|
| 1 | +import { describe, test, expect } from "@jest/globals"; |
| 2 | +import { PrivateKey } from "../../src/generated"; |
| 3 | +import * as CSL from "@emurgo/cardano-serialization-lib-nodejs-gc"; |
| 4 | + |
| 5 | +describe("Our PrivateKey", () => { |
| 6 | + const key = PrivateKey.generate_ed25519(); |
| 7 | + const cslKey = CSL.PrivateKey.from_hex(key.to_hex()); |
| 8 | + |
| 9 | + test("Must serialize same as CSL", () => { |
| 10 | + expect(key.to_hex()).toEqual(cslKey.to_hex()); |
| 11 | + expect(key.as_bytes()).toEqual(cslKey.as_bytes()); |
| 12 | + expect(key.to_bech32()).toEqual(cslKey.to_bech32()); |
| 13 | + }); |
| 14 | + |
| 15 | + test("Must have the same pubkey as CSL", () => { |
| 16 | + const pubkey = key.to_public(); |
| 17 | + const cslPubkey = cslKey.to_public(); |
| 18 | + expect(pubkey.to_hex()).toEqual(cslPubkey.to_hex()); |
| 19 | + expect(pubkey.to_bech32()).toEqual(cslPubkey.to_bech32()); |
| 20 | + expect(pubkey.as_bytes()).toEqual(cslPubkey.as_bytes()); |
| 21 | + }); |
| 22 | +}); |
| 23 | + |
| 24 | +describe("Our PrivateKey (extended)", () => { |
| 25 | + const key = PrivateKey.generate_ed25519extended(); |
| 26 | + const cslKey = CSL.PrivateKey.from_hex(key.to_hex()); |
| 27 | + |
| 28 | + test("Must serialize same as CSL", () => { |
| 29 | + expect(key.to_hex()).toEqual(cslKey.to_hex()); |
| 30 | + expect(key.as_bytes()).toEqual(cslKey.as_bytes()); |
| 31 | + expect(key.to_bech32()).toEqual(cslKey.to_bech32()); |
| 32 | + }); |
| 33 | + |
| 34 | + test("Must have the same pubkey as CSL", () => { |
| 35 | + const pubkey = key.to_public(); |
| 36 | + const cslPubkey = cslKey.to_public(); |
| 37 | + expect(pubkey.to_hex()).toEqual(cslPubkey.to_hex()); |
| 38 | + expect(pubkey.to_bech32()).toEqual(cslPubkey.to_bech32()); |
| 39 | + expect(pubkey.as_bytes()).toEqual(cslPubkey.as_bytes()); |
| 40 | + }); |
| 41 | +}); |
0 commit comments