diff options
| author | Adam Soltys <[email protected]> | 2026-03-01 18:51:16 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2026-03-01 18:51:16 -0800 |
| commit | c7e2383736d3ef99f069226bbafad9fbddfeb030 (patch) | |
| tree | e71947a1e627cd1a4802808661ed88866a234f81 /test/unified-seed.test.ts | |
| parent | e3b7208ae23d7b56126b0b32b66dfa48140dc1f2 (diff) | |
| download | coinos-ui-c7e2383736d3ef99f069226bbafad9fbddfeb030.tar.gz coinos-ui-c7e2383736d3ef99f069226bbafad9fbddfeb030.zip | |
messages ui
Diffstat (limited to 'test/unified-seed.test.ts')
| -rw-r--r-- | test/unified-seed.test.ts | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/test/unified-seed.test.ts b/test/unified-seed.test.ts index 4410dbea..1bdf35d3 100644 --- a/test/unified-seed.test.ts +++ b/test/unified-seed.test.ts @@ -10,6 +10,8 @@ import { import { wordlist } from "@scure/bip39/wordlists/english.js"; import { bytesToHex, hexToBytes } from "@noble/hashes/utils.js"; import { encrypt, decrypt } from "nostr-tools/nip49"; +import { privateKeyFromSeedWords } from "nostr-tools/nip06"; +import { getPublicKey } from "nostr-tools"; const versions = { private: 0x04358394, @@ -217,3 +219,42 @@ describe("backward compatibility", () => { expect(() => decrypt(encrypted, "wrongpassword")).toThrow(); }); }); + +describe("NIP-06 nostr key derivation", () => { + const mnemonic = generateMnemonic(wordlist); + + it("derives a deterministic nostr key from mnemonic via NIP-06 path", () => { + const sk = privateKeyFromSeedWords(mnemonic); + const pubkey = getPublicKey(sk); + + expect(sk).toBeInstanceOf(Uint8Array); + expect(sk.length).toBe(32); + expect(pubkey).toMatch(/^[0-9a-f]{64}$/); + + // Same mnemonic produces same key + const sk2 = privateKeyFromSeedWords(mnemonic); + expect(bytesToHex(sk2)).toBe(bytesToHex(sk)); + }); + + it("derives nostr key from entropy round-trip", () => { + const entropy = mnemonicToEntropy(mnemonic, wordlist); + const recovered = entropyToMnemonic(entropy, wordlist); + expect(recovered).toBe(mnemonic); + + const sk = privateKeyFromSeedWords(mnemonic); + const skRecovered = privateKeyFromSeedWords(recovered); + expect(bytesToHex(skRecovered)).toBe(bytesToHex(sk)); + }); + + it("nostr NIP-06 key differs from Bitcoin and Ark keys", async () => { + const seed = await mnemonicToSeed(mnemonic, password); + const master = HDKey.fromMasterSeed(seed, versions); + + const btcKey = bytesToHex(master.derive("m/84'/0'/0'").privateKey!); + const arkKey = bytesToHex(master.derive("m/86'/0'/0'/0/0").privateKey!); + const nostrKey = bytesToHex(privateKeyFromSeedWords(mnemonic)); + + expect(nostrKey).not.toBe(btcKey); + expect(nostrKey).not.toBe(arkKey); + }); +}); |
