Skip to content

Commit 5e7b8cc

Browse files
committed
tests: Add bip32-ed25519 related tests
1 parent 8c3ebd6 commit 5e7b8cc

File tree

3 files changed

+46
-5
lines changed

3 files changed

+46
-5
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"test-serialization": "NODE_OPTIONS=--experimental-vm-modules jest tests/serialization/serialization.test.ts",
1313
"test-serialization-dev": "NODE_OPTIONS=--experimental-vm-modules jest tests/serialization/serialization_dev.test.ts",
1414
"test-api": "npm run generate-cdl-definitions ; NODE_OPTIONS=--experimental-vm-modules jest tests/api/api.test.ts",
15-
"test-implementation": "NODE_OPTIONS=--experimental-vm-modules jest fees hash min_output_ada",
15+
"test-implementation": "NODE_OPTIONS=--experimental-vm-modules jest fees hash min_output_ada private_key bip32-ed25519",
1616
"codegen": "tsx conway-cddl/codegen/main.ts",
1717
"generate-grammar-bundle": "npx ohm generateBundles -e -t tests/api/grammar.ohm",
1818
"generate-cdl-definitions": "make typedefs",

src/lib/bip32-ed25519/test.ts tests/bip32-ed25519/bip32-ed25519.test.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { describe, test, expect } from "@jest/globals";
2-
import * as thisLib from "./index";
3-
import * as naclExt from "./nacl-extended";
4-
import nacl from "tweetnacl";
52
import * as CSL from "@emurgo/cardano-serialization-lib-nodejs-gc";
6-
import * as derive from "./derive";
3+
import * as thisLib from "../../src/lib/bip32-ed25519/index";
4+
import * as naclExt from "../../src/lib/bip32-ed25519/nacl-extended";
5+
import nacl from "tweetnacl";
6+
import * as derive from "../../src/lib/bip32-ed25519/derive";
77

88
describe("extendedToPubkey", () => {
99
for (let i = 0; i < 10; i++) {
+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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

Comments
 (0)