@leather.io/crypto 1.0.3 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -10,9 +10,25 @@ declare enum DerivationPathDepth {
10
10
  }
11
11
  declare const extractAccountIndexFromPath: (path: string) => number;
12
12
  declare const extractAddressIndexFromPath: (path: string) => number;
13
+ /**
14
+ * @description
15
+ * A key origin path refers to the identifier commonly used as part of the key
16
+ * information provided as part of a Output Descriptor described in BIP-380. It
17
+ * replaces the `m/` part of a derivation path with the master key fingerprint to which the
18
+ * key it describes belongs.
19
+ * @example `0a3fd8ef/84'/0'/0'`
20
+ */
21
+ declare function createKeyOriginPath(fingerprint: string, path: string): string;
13
22
 
14
23
  declare function generateMnemonic(): string;
15
- declare function deriveBip39MnemonicFromSeed(mnemonic: string): Promise<Uint8Array>;
24
+ declare function deriveBip39SeedFromMnemonic(mnemonic: string): Promise<Uint8Array>;
25
+ /** @deprecated Inaccurately named fn, use `deriveBip39SeedFromMnemonic` */
26
+ declare const deriveBip39MnemonicFromSeed: typeof deriveBip39SeedFromMnemonic;
16
27
  declare function deriveRootBip32Keychain(seed: Uint8Array): HDKey;
28
+ /**
29
+ * Gets keychain fingerprint directly from mnemonic. This is useful for
30
+ * referencing a mnemonic safely by an identifier.
31
+ */
32
+ declare function getMnemonicRootKeyFingerprint(mnemonic: string): Promise<string>;
17
33
 
18
- export { DerivationPathDepth, deriveBip39MnemonicFromSeed, deriveRootBip32Keychain, extractAccountIndexFromPath, extractAddressIndexFromPath, generateMnemonic };
34
+ export { DerivationPathDepth, createKeyOriginPath, deriveBip39MnemonicFromSeed, deriveBip39SeedFromMnemonic, deriveRootBip32Keychain, extractAccountIndexFromPath, extractAddressIndexFromPath, generateMnemonic, getMnemonicRootKeyFingerprint };
package/dist/index.mjs CHANGED
@@ -27,23 +27,34 @@ var extractAccountIndexFromPath = extractSectionFromDerivationPath(
27
27
  var extractAddressIndexFromPath = extractSectionFromDerivationPath(
28
28
  5 /* AddressIndex */
29
29
  );
30
+ function createKeyOriginPath(fingerprint, path) {
31
+ return `${fingerprint}/${path.replace("m/", "")}`;
32
+ }
30
33
 
31
34
  // src/index.ts
32
35
  function generateMnemonic() {
33
36
  return scureGenerateMnemonic(wordlist, 256);
34
37
  }
35
- async function deriveBip39MnemonicFromSeed(mnemonic) {
38
+ async function deriveBip39SeedFromMnemonic(mnemonic) {
36
39
  return mnemonicToSeed(mnemonic);
37
40
  }
41
+ var deriveBip39MnemonicFromSeed = deriveBip39SeedFromMnemonic;
38
42
  function deriveRootBip32Keychain(seed) {
39
43
  return HDKey.fromMasterSeed(seed);
40
44
  }
45
+ async function getMnemonicRootKeyFingerprint(mnemonic) {
46
+ const keychain = deriveRootBip32Keychain(await deriveBip39SeedFromMnemonic(mnemonic));
47
+ return keychain.fingerprint.toString(16);
48
+ }
41
49
  export {
42
50
  DerivationPathDepth,
51
+ createKeyOriginPath,
43
52
  deriveBip39MnemonicFromSeed,
53
+ deriveBip39SeedFromMnemonic,
44
54
  deriveRootBip32Keychain,
45
55
  extractAccountIndexFromPath,
46
56
  extractAddressIndexFromPath,
47
- generateMnemonic
57
+ generateMnemonic,
58
+ getMnemonicRootKeyFingerprint
48
59
  };
49
60
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/derivation-path-utils.ts"],"sourcesContent":["import { HDKey } from '@scure/bip32';\nimport { mnemonicToSeed, generateMnemonic as scureGenerateMnemonic } from '@scure/bip39';\nimport { wordlist } from '@scure/bip39/wordlists/english';\n\nexport * from './derivation-path-utils';\n\nexport function generateMnemonic() {\n return scureGenerateMnemonic(wordlist, 256);\n}\n\nexport async function deriveBip39MnemonicFromSeed(mnemonic: string) {\n return mnemonicToSeed(mnemonic);\n}\n\nexport function deriveRootBip32Keychain(seed: Uint8Array) {\n return HDKey.fromMasterSeed(seed);\n}\n","export enum DerivationPathDepth {\n Root = 0,\n Purpose = 1,\n CoinType = 2,\n Account = 3,\n ChangeReceive = 4,\n AddressIndex = 5,\n}\n\nfunction extractSectionFromDerivationPath(depth: DerivationPathDepth) {\n return (path: string) => {\n const segments = path.split('/');\n const accountNum = parseInt(segments[depth].replaceAll(\"'\", ''), 10);\n if (isNaN(accountNum)) throw new Error(`Cannot parse ${DerivationPathDepth[depth]} from path`);\n return accountNum;\n };\n}\n\nexport const extractAccountIndexFromPath = extractSectionFromDerivationPath(\n DerivationPathDepth.Account\n);\n\nexport const extractAddressIndexFromPath = extractSectionFromDerivationPath(\n DerivationPathDepth.AddressIndex\n);\n"],"mappings":";AAAA,SAAS,aAAa;AACtB,SAAS,gBAAgB,oBAAoB,6BAA6B;AAC1E,SAAS,gBAAgB;;;ACFlB,IAAK,sBAAL,kBAAKA,yBAAL;AACL,EAAAA,0CAAA,UAAO,KAAP;AACA,EAAAA,0CAAA,aAAU,KAAV;AACA,EAAAA,0CAAA,cAAW,KAAX;AACA,EAAAA,0CAAA,aAAU,KAAV;AACA,EAAAA,0CAAA,mBAAgB,KAAhB;AACA,EAAAA,0CAAA,kBAAe,KAAf;AANU,SAAAA;AAAA,GAAA;AASZ,SAAS,iCAAiC,OAA4B;AACpE,SAAO,CAAC,SAAiB;AACvB,UAAM,WAAW,KAAK,MAAM,GAAG;AAC/B,UAAM,aAAa,SAAS,SAAS,KAAK,EAAE,WAAW,KAAK,EAAE,GAAG,EAAE;AACnE,QAAI,MAAM,UAAU,EAAG,OAAM,IAAI,MAAM,gBAAgB,oBAAoB,KAAK,CAAC,YAAY;AAC7F,WAAO;AAAA,EACT;AACF;AAEO,IAAM,8BAA8B;AAAA,EACzC;AACF;AAEO,IAAM,8BAA8B;AAAA,EACzC;AACF;;;ADlBO,SAAS,mBAAmB;AACjC,SAAO,sBAAsB,UAAU,GAAG;AAC5C;AAEA,eAAsB,4BAA4B,UAAkB;AAClE,SAAO,eAAe,QAAQ;AAChC;AAEO,SAAS,wBAAwB,MAAkB;AACxD,SAAO,MAAM,eAAe,IAAI;AAClC;","names":["DerivationPathDepth"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/derivation-path-utils.ts"],"sourcesContent":["import { HDKey } from '@scure/bip32';\nimport { mnemonicToSeed, generateMnemonic as scureGenerateMnemonic } from '@scure/bip39';\nimport { wordlist } from '@scure/bip39/wordlists/english';\n\nexport * from './derivation-path-utils';\n\nexport function generateMnemonic() {\n return scureGenerateMnemonic(wordlist, 256);\n}\n\nexport async function deriveBip39SeedFromMnemonic(mnemonic: string) {\n return mnemonicToSeed(mnemonic);\n}\n/** @deprecated Inaccurately named fn, use `deriveBip39SeedFromMnemonic` */\nexport const deriveBip39MnemonicFromSeed = deriveBip39SeedFromMnemonic;\n\nexport function deriveRootBip32Keychain(seed: Uint8Array) {\n return HDKey.fromMasterSeed(seed);\n}\n\n/**\n * Gets keychain fingerprint directly from mnemonic. This is useful for\n * referencing a mnemonic safely by an identifier.\n */\nexport async function getMnemonicRootKeyFingerprint(mnemonic: string) {\n const keychain = deriveRootBip32Keychain(await deriveBip39SeedFromMnemonic(mnemonic));\n return keychain.fingerprint.toString(16);\n}\n","export enum DerivationPathDepth {\n Root = 0,\n Purpose = 1,\n CoinType = 2,\n Account = 3,\n ChangeReceive = 4,\n AddressIndex = 5,\n}\n\nfunction extractSectionFromDerivationPath(depth: DerivationPathDepth) {\n return (path: string) => {\n const segments = path.split('/');\n const accountNum = parseInt(segments[depth].replaceAll(\"'\", ''), 10);\n if (isNaN(accountNum)) throw new Error(`Cannot parse ${DerivationPathDepth[depth]} from path`);\n return accountNum;\n };\n}\n\nexport const extractAccountIndexFromPath = extractSectionFromDerivationPath(\n DerivationPathDepth.Account\n);\n\nexport const extractAddressIndexFromPath = extractSectionFromDerivationPath(\n DerivationPathDepth.AddressIndex\n);\n\n/**\n * @description\n * A key origin path refers to the identifier commonly used as part of the key\n * information provided as part of a Output Descriptor described in BIP-380. It\n * replaces the `m/` part of a derivation path with the master key fingerprint to which the\n * key it describes belongs.\n * @example `0a3fd8ef/84'/0'/0'`\n */\nexport function createKeyOriginPath(fingerprint: string, path: string) {\n return `${fingerprint}/${path.replace('m/', '')}`;\n}\n"],"mappings":";AAAA,SAAS,aAAa;AACtB,SAAS,gBAAgB,oBAAoB,6BAA6B;AAC1E,SAAS,gBAAgB;;;ACFlB,IAAK,sBAAL,kBAAKA,yBAAL;AACL,EAAAA,0CAAA,UAAO,KAAP;AACA,EAAAA,0CAAA,aAAU,KAAV;AACA,EAAAA,0CAAA,cAAW,KAAX;AACA,EAAAA,0CAAA,aAAU,KAAV;AACA,EAAAA,0CAAA,mBAAgB,KAAhB;AACA,EAAAA,0CAAA,kBAAe,KAAf;AANU,SAAAA;AAAA,GAAA;AASZ,SAAS,iCAAiC,OAA4B;AACpE,SAAO,CAAC,SAAiB;AACvB,UAAM,WAAW,KAAK,MAAM,GAAG;AAC/B,UAAM,aAAa,SAAS,SAAS,KAAK,EAAE,WAAW,KAAK,EAAE,GAAG,EAAE;AACnE,QAAI,MAAM,UAAU,EAAG,OAAM,IAAI,MAAM,gBAAgB,oBAAoB,KAAK,CAAC,YAAY;AAC7F,WAAO;AAAA,EACT;AACF;AAEO,IAAM,8BAA8B;AAAA,EACzC;AACF;AAEO,IAAM,8BAA8B;AAAA,EACzC;AACF;AAUO,SAAS,oBAAoB,aAAqB,MAAc;AACrE,SAAO,GAAG,WAAW,IAAI,KAAK,QAAQ,MAAM,EAAE,CAAC;AACjD;;;AD9BO,SAAS,mBAAmB;AACjC,SAAO,sBAAsB,UAAU,GAAG;AAC5C;AAEA,eAAsB,4BAA4B,UAAkB;AAClE,SAAO,eAAe,QAAQ;AAChC;AAEO,IAAM,8BAA8B;AAEpC,SAAS,wBAAwB,MAAkB;AACxD,SAAO,MAAM,eAAe,IAAI;AAClC;AAMA,eAAsB,8BAA8B,UAAkB;AACpE,QAAM,WAAW,wBAAwB,MAAM,4BAA4B,QAAQ,CAAC;AACpF,SAAO,SAAS,YAAY,SAAS,EAAE;AACzC;","names":["DerivationPathDepth"]}
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@leather.io/crypto",
3
3
  "author": "leather.io",
4
4
  "description": "Generic crypto utils package for Leather",
5
- "version": "1.0.3",
5
+ "version": "1.0.4",
6
6
  "license": "MIT",
7
7
  "exports": {
8
8
  ".": "./dist/index.mjs"
@@ -14,7 +14,7 @@
14
14
  "devDependencies": {
15
15
  "@vitest/coverage-istanbul": "0.34.6",
16
16
  "tsup": "8.1.0",
17
- "vitest": "0.34.6"
17
+ "vitest": "2.0.3"
18
18
  },
19
19
  "files": [
20
20
  "dist"
@@ -26,7 +26,7 @@
26
26
  "build": "tsup",
27
27
  "build:watch": "tsup --watch",
28
28
  "prepublish": "pnpm build",
29
- "test:unit": "vitest",
29
+ "test:unit": "vitest run",
30
30
  "typecheck": "tsc --noEmit"
31
31
  }
32
32
  }