@metamask-previews/key-tree 10.1.1-preview-c3ccf7def → 10.1.1-preview-270326558

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.
Files changed (73) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/dist/BIP44CoinTypeNode.d.ts +10 -21
  3. package/dist/BIP44CoinTypeNode.d.ts.map +1 -1
  4. package/dist/BIP44CoinTypeNode.js +15 -28
  5. package/dist/BIP44CoinTypeNode.js.map +1 -1
  6. package/dist/BIP44Node.d.ts +11 -20
  7. package/dist/BIP44Node.d.ts.map +1 -1
  8. package/dist/BIP44Node.js +10 -18
  9. package/dist/BIP44Node.js.map +1 -1
  10. package/dist/SLIP10Node.d.ts +18 -31
  11. package/dist/SLIP10Node.d.ts.map +1 -1
  12. package/dist/SLIP10Node.js +17 -29
  13. package/dist/SLIP10Node.js.map +1 -1
  14. package/dist/constants.d.ts +2 -2
  15. package/dist/constants.d.ts.map +1 -1
  16. package/dist/constants.js.map +1 -1
  17. package/dist/cryptography.d.ts +0 -58
  18. package/dist/cryptography.d.ts.map +1 -1
  19. package/dist/cryptography.js +1 -84
  20. package/dist/cryptography.js.map +1 -1
  21. package/dist/curves/curve.d.ts +6 -6
  22. package/dist/curves/curve.d.ts.map +1 -1
  23. package/dist/curves/curve.js.map +1 -1
  24. package/dist/curves/ed25519.d.ts +5 -5
  25. package/dist/curves/ed25519.d.ts.map +1 -1
  26. package/dist/curves/ed25519.js +4 -4
  27. package/dist/curves/ed25519.js.map +1 -1
  28. package/dist/curves/ed25519Bip32.d.ts +16 -8
  29. package/dist/curves/ed25519Bip32.d.ts.map +1 -1
  30. package/dist/curves/ed25519Bip32.js +5 -5
  31. package/dist/curves/ed25519Bip32.js.map +1 -1
  32. package/dist/curves/secp256k1.d.ts +14 -6
  33. package/dist/curves/secp256k1.d.ts.map +1 -1
  34. package/dist/curves/secp256k1.js +13 -13
  35. package/dist/curves/secp256k1.js.map +1 -1
  36. package/dist/derivation.d.ts +1 -4
  37. package/dist/derivation.d.ts.map +1 -1
  38. package/dist/derivation.js +3 -5
  39. package/dist/derivation.js.map +1 -1
  40. package/dist/derivers/bip32.d.ts +3 -6
  41. package/dist/derivers/bip32.d.ts.map +1 -1
  42. package/dist/derivers/bip32.js +4 -8
  43. package/dist/derivers/bip32.js.map +1 -1
  44. package/dist/derivers/bip39.d.ts +8 -13
  45. package/dist/derivers/bip39.d.ts.map +1 -1
  46. package/dist/derivers/bip39.js +24 -18
  47. package/dist/derivers/bip39.js.map +1 -1
  48. package/dist/derivers/cip3.d.ts +17 -24
  49. package/dist/derivers/cip3.d.ts.map +1 -1
  50. package/dist/derivers/cip3.js +34 -36
  51. package/dist/derivers/cip3.js.map +1 -1
  52. package/dist/derivers/index.d.ts +5 -6
  53. package/dist/derivers/index.d.ts.map +1 -1
  54. package/dist/derivers/index.js.map +1 -1
  55. package/dist/derivers/shared.d.ts +19 -26
  56. package/dist/derivers/shared.d.ts.map +1 -1
  57. package/dist/derivers/shared.js +19 -26
  58. package/dist/derivers/shared.js.map +1 -1
  59. package/dist/derivers/slip10.d.ts +1 -4
  60. package/dist/derivers/slip10.d.ts.map +1 -1
  61. package/dist/derivers/slip10.js +4 -8
  62. package/dist/derivers/slip10.js.map +1 -1
  63. package/dist/extended-keys.d.ts +3 -3
  64. package/dist/extended-keys.d.ts.map +1 -1
  65. package/dist/extended-keys.js.map +1 -1
  66. package/dist/index.d.ts +0 -1
  67. package/dist/index.d.ts.map +1 -1
  68. package/dist/index.js.map +1 -1
  69. package/dist/utils.d.ts +9 -16
  70. package/dist/utils.d.ts.map +1 -1
  71. package/dist/utils.js +17 -15
  72. package/dist/utils.js.map +1 -1
  73. package/package.json +2 -1
package/CHANGELOG.md CHANGED
@@ -15,6 +15,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
15
15
  - **BREAKING:** Bump minimum supported Node.js version to `^22.14.0 || ^24 || ^26` ([#11361](https://github.com/MetaMask/core/pull/11361))
16
16
  - **BREAKING:** Compile to `ES2022` instead of `ES2020` ([#11360](https://github.com/MetaMask/core/pull/11360))
17
17
  - Consumers that bundle this package for environments that do not support `ES2022` must transpile it.
18
+ - **BREAKING:** Replace cryptography implementations with `@metamask/cryptography` ([#11395](https://github.com/MetaMask/core/pull/11395))
19
+ - The custom `cryptographicFunctions` option was removed. Consumers that passed it must stop doing so, as the package now always uses `@metamask/cryptography`.
20
+ - **BREAKING:** Replace curve objects with simple objects containing only the curve parameters ([#11395](https://github.com/MetaMask/core/pull/11395))
21
+ - All functions now use `Uint8Array<ArrayBuffer>` instead of `Uint8Array` ([#11395](https://github.com/MetaMask/core/pull/11395))
22
+ - `Uint8Array`s backed by a `SharedArrayBuffer` were never properly supported, so this only makes the types reflect the existing runtime behaviour.
18
23
  - Replace the `@metamask/utils` dependency with `@metamask/byte-utils` and `@metamask/type-utils` ([#11361](https://github.com/MetaMask/core/pull/11361))
19
24
  - Bump `@noble/curves` from `^1.8.1` to `^1.9.7`, `@noble/hashes` from `^1.3.2` to `^1.8.0`, and `@scure/base` from `^1.0.0` to `^1.2.6` ([#11361](https://github.com/MetaMask/core/pull/11361))
20
25
  - This package was migrated from `MetaMask/key-tree` to the `MetaMask/core` monorepo ([#11354](https://github.com/MetaMask/core/pull/11354))
@@ -1,7 +1,6 @@
1
1
  import type { BIP44NodeInterface, JsonBIP44Node } from './BIP44Node.js';
2
2
  import { BIP44Node } from './BIP44Node.js';
3
3
  import type { BIP39Node, BIP44Depth, BIP44PurposeNodeToken, CoinTypeHDPathString, HardenedBIP32Node, Network } from './constants.js';
4
- import type { CryptographicFunctions } from './cryptography.js';
5
4
  import type { SupportedCurve } from './curves/index.js';
6
5
  import type { CoinTypeToAddressIndices } from './utils.js';
7
6
  import { getBIP44ChangePathString } from './utils.js';
@@ -11,7 +10,7 @@ export type CoinTypeHDPathTuple = [
11
10
  HardenedBIP32Node
12
11
  ];
13
12
  export type CoinTypeSeedPathTuple = [
14
- Uint8Array,
13
+ Uint8Array<ArrayBuffer>,
15
14
  typeof BIP44PurposeNodeToken,
16
15
  HardenedBIP32Node
17
16
  ];
@@ -62,11 +61,9 @@ export declare class BIP44CoinTypeNode implements BIP44CoinTypeNodeInterface {
62
61
  * @param json - The {@link JsonBIP44Node} for the key of this node.
63
62
  * @param coin_type - The coin_type index of this node. Must be a non-negative
64
63
  * integer.
65
- * @param cryptographicFunctions - The cryptographic functions to use. If
66
- * provided, these will be used instead of the built-in implementations.
67
64
  * @returns A BIP44CoinType node.
68
65
  */
69
- static fromJSON(json: JsonBIP44Node, coin_type: number, cryptographicFunctions?: CryptographicFunctions): Promise<BIP44CoinTypeNode>;
66
+ static fromJSON(json: JsonBIP44Node, coin_type: number): Promise<BIP44CoinTypeNode>;
70
67
  /**
71
68
  * Construct a BIP-44 `coin_type` node. `coin_type` is the index
72
69
  * specifying the protocol for which deeper keys are intended. For the
@@ -84,11 +81,9 @@ export declare class BIP44CoinTypeNode implements BIP44CoinTypeNodeInterface {
84
81
  * @param derivationPath - The derivation path for the key of this node.
85
82
  * @param network - The network for the node. This is only used for extended
86
83
  * keys, and defaults to `mainnet`.
87
- * @param cryptographicFunctions - The cryptographic functions to use. If
88
- * provided, these will be used instead of the built-in implementations.
89
84
  * @returns A BIP44CoinType node.
90
85
  */
91
- static fromDerivationPath(derivationPath: CoinTypeHDPathTuple, network?: Network | undefined, cryptographicFunctions?: CryptographicFunctions): Promise<BIP44CoinTypeNode>;
86
+ static fromDerivationPath(derivationPath: CoinTypeHDPathTuple, network?: Network | undefined): Promise<BIP44CoinTypeNode>;
92
87
  /**
93
88
  * Create a new BIP-44 coin type node from a BIP-39 seed. The derivation path
94
89
  * must be rooted, i.e. it must begin with a BIP-39 node, given as a
@@ -102,11 +97,9 @@ export declare class BIP44CoinTypeNode implements BIP44CoinTypeNodeInterface {
102
97
  * to derive the key of this node.
103
98
  * @param options.network - The network for the node. This is only used for
104
99
  * extended keys, and defaults to `mainnet`.
105
- * @param cryptographicFunctions - The cryptographic functions to use. If
106
- * provided, these will be used instead of the built-in implementations.
107
100
  * @returns A new BIP-44 node.
108
101
  */
109
- static fromSeed({ derivationPath, network }: BIP44CoinTypeSeedOptions, cryptographicFunctions?: CryptographicFunctions): Promise<BIP44CoinTypeNode>;
102
+ static fromSeed({ derivationPath, network, }: BIP44CoinTypeSeedOptions): Promise<BIP44CoinTypeNode>;
110
103
  /**
111
104
  * Constructs a BIP-44 `coin_type` node. `coin_type` is the index
112
105
  * specifying the protocol for which deeper keys are intended. For the
@@ -131,13 +124,13 @@ export declare class BIP44CoinTypeNode implements BIP44CoinTypeNodeInterface {
131
124
  readonly coin_type: number;
132
125
  private constructor();
133
126
  get depth(): BIP44Depth;
134
- get privateKeyBytes(): Uint8Array | undefined;
135
- get publicKeyBytes(): Uint8Array;
136
- get chainCodeBytes(): Uint8Array;
127
+ get privateKeyBytes(): Uint8Array<ArrayBuffer> | undefined;
128
+ get publicKeyBytes(): Uint8Array<ArrayBuffer>;
129
+ get chainCodeBytes(): Uint8Array<ArrayBuffer>;
137
130
  get privateKey(): string | undefined;
138
131
  get publicKey(): string;
139
132
  get compressedPublicKey(): string;
140
- get compressedPublicKeyBytes(): Uint8Array;
133
+ get compressedPublicKeyBytes(): Uint8Array<ArrayBuffer>;
141
134
  get chainCode(): string;
142
135
  get address(): string;
143
136
  get masterFingerprint(): number | undefined;
@@ -187,11 +180,9 @@ export declare class BIP44CoinTypeNode implements BIP44CoinTypeNodeInterface {
187
180
  * @param indices.account - The `account` index. Default: `0`.
188
181
  * @param indices.change - The `change` index. Default: `0`.
189
182
  * @param indices.address_index - The `address_index` index.
190
- * @param cryptographicFunctions - The cryptographic functions to use. If
191
- * provided, these will be used instead of the built-in implementations.
192
183
  * @returns The derived `address_index` key for the specified derivation path.
193
184
  */
194
- export declare function deriveBIP44AddressKey(parentKeyOrNode: BIP44CoinTypeNode | JsonBIP44CoinTypeNode | string, { account, change, address_index }: CoinTypeToAddressIndices, cryptographicFunctions?: CryptographicFunctions): Promise<BIP44Node>;
185
+ export declare function deriveBIP44AddressKey(parentKeyOrNode: BIP44CoinTypeNode | JsonBIP44CoinTypeNode | string, { account, change, address_index }: CoinTypeToAddressIndices): Promise<BIP44Node>;
195
186
  export type BIP44AddressKeyDeriver = {
196
187
  /**
197
188
  * @param address_index - The `address_index` value.
@@ -235,10 +226,8 @@ export type BIP44AddressKeyDeriver = {
235
226
  * This node contains a BIP-44 key of depth 2, `coin_type`.
236
227
  * @param accountAndChangeIndices - The `account` and `change` indices that
237
228
  * will be used to derive addresses.
238
- * @param cryptographicFunctions - The cryptographic functions to use. If
239
- * provided, these will be used instead of the built-in implementations.
240
229
  * @returns The deriver function for the derivation path specified by the
241
230
  * `coin_type` node, `account`, and `change` indices.
242
231
  */
243
- export declare function getBIP44AddressKeyDeriver(node: BIP44CoinTypeNode | JsonBIP44CoinTypeNode | string, accountAndChangeIndices?: Omit<CoinTypeToAddressIndices, 'address_index'>, cryptographicFunctions?: CryptographicFunctions): Promise<BIP44AddressKeyDeriver>;
232
+ export declare function getBIP44AddressKeyDeriver(node: BIP44CoinTypeNode | JsonBIP44CoinTypeNode | string, accountAndChangeIndices?: Omit<CoinTypeToAddressIndices, 'address_index'>): Promise<BIP44AddressKeyDeriver>;
244
233
  //# sourceMappingURL=BIP44CoinTypeNode.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"BIP44CoinTypeNode.d.ts","sourceRoot":"","sources":["../src/BIP44CoinTypeNode.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AACxE,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,KAAK,EACV,SAAS,EACT,UAAU,EACV,qBAAqB,EACrB,oBAAoB,EACpB,iBAAiB,EACjB,OAAO,EACR,MAAM,gBAAgB,CAAC;AAExB,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAChE,OA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;;;;;;GAkBG;AACH,wBAAsB,qBAAqB,CACzC,eAAe,EAAE,iBAAiB,GAAG,qBAAqB,GAAG,MAAM,EACnE,EAAE,OAAW,EAAE,MAAU,EAAE,aAAa,EAAE,EAAE,wBAAwB,GACnE,OAAO,CAAC,SAAS,CAAC,CAcpB;AAED,MAAM,MAAM,sBAAsB,GAAG;IACnC;;;;;OAKG;IACH,CAAC,aAAa,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;IAElE;;;;;;;;;;;OAWG;IACH,IAAI,EAAE,UAAU,CAAC,OAAO,wBAAwB,CAAC,CAAC;IAElD;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAsB,yBAAyB,CAC7C,IAAI,EAAE,iBAAiB,GAAG,qBAAqB,GAAG,MAAM,EACxD,uBAAuB,CAAC,EAAE,IAAI,CAAC,wBAAwB,EAAE,eAAe,CAAC,GACxE,OAAO,CAAC,sBAAsB,CAAC,CAmCjC"}
@@ -36,11 +36,9 @@ export class BIP44CoinTypeNode {
36
36
  * @param json - The {@link JsonBIP44Node} for the key of this node.
37
37
  * @param coin_type - The coin_type index of this node. Must be a non-negative
38
38
  * integer.
39
- * @param cryptographicFunctions - The cryptographic functions to use. If
40
- * provided, these will be used instead of the built-in implementations.
41
39
  * @returns A BIP44CoinType node.
42
40
  */
43
- static async fromJSON(json, coin_type, cryptographicFunctions) {
41
+ static async fromJSON(json, coin_type) {
44
42
  validateCoinType(coin_type);
45
43
  validateCoinTypeNodeDepth(json.depth);
46
44
  const node = await BIP44Node.fromExtendedKey({
@@ -51,7 +49,7 @@ export class BIP44CoinTypeNode {
51
49
  chainCode: hexStringToBytes(json.chainCode),
52
50
  privateKey: nullableHexStringToBytes(json.privateKey),
53
51
  publicKey: hexStringToBytes(json.publicKey),
54
- }, cryptographicFunctions);
52
+ });
55
53
  return new BIP44CoinTypeNode(node, coin_type);
56
54
  }
57
55
  /**
@@ -71,16 +69,14 @@ export class BIP44CoinTypeNode {
71
69
  * @param derivationPath - The derivation path for the key of this node.
72
70
  * @param network - The network for the node. This is only used for extended
73
71
  * keys, and defaults to `mainnet`.
74
- * @param cryptographicFunctions - The cryptographic functions to use. If
75
- * provided, these will be used instead of the built-in implementations.
76
72
  * @returns A BIP44CoinType node.
77
73
  */
78
- static async fromDerivationPath(derivationPath, network, cryptographicFunctions) {
74
+ static async fromDerivationPath(derivationPath, network) {
79
75
  validateCoinTypeNodeDepth(derivationPath.length - 1);
80
76
  const node = await BIP44Node.fromDerivationPath({
81
77
  derivationPath,
82
78
  network,
83
- }, cryptographicFunctions);
79
+ });
84
80
  const coinType = getBIP44CoinType(derivationPath);
85
81
  return new BIP44CoinTypeNode(node, coinType);
86
82
  }
@@ -97,16 +93,14 @@ export class BIP44CoinTypeNode {
97
93
  * to derive the key of this node.
98
94
  * @param options.network - The network for the node. This is only used for
99
95
  * extended keys, and defaults to `mainnet`.
100
- * @param cryptographicFunctions - The cryptographic functions to use. If
101
- * provided, these will be used instead of the built-in implementations.
102
96
  * @returns A new BIP-44 node.
103
97
  */
104
- static async fromSeed({ derivationPath, network }, cryptographicFunctions) {
98
+ static async fromSeed({ derivationPath, network, }) {
105
99
  validateCoinTypeNodeDepth(derivationPath.length - 1);
106
100
  const node = await BIP44Node.fromSeed({
107
101
  derivationPath,
108
102
  network,
109
- }, cryptographicFunctions);
103
+ });
110
104
  const coinType = getBIP44CoinType(derivationPath);
111
105
  return new BIP44CoinTypeNode(node, coinType);
112
106
  }
@@ -272,21 +266,19 @@ function validateCoinType(coin_type) {
272
266
  * @param indices.account - The `account` index. Default: `0`.
273
267
  * @param indices.change - The `change` index. Default: `0`.
274
268
  * @param indices.address_index - The `address_index` index.
275
- * @param cryptographicFunctions - The cryptographic functions to use. If
276
- * provided, these will be used instead of the built-in implementations.
277
269
  * @returns The derived `address_index` key for the specified derivation path.
278
270
  */
279
- export async function deriveBIP44AddressKey(parentKeyOrNode, { account = 0, change = 0, address_index }, cryptographicFunctions) {
271
+ export async function deriveBIP44AddressKey(parentKeyOrNode, { account = 0, change = 0, address_index }) {
280
272
  const path = getBIP44CoinTypeToAddressPathTuple({
281
273
  account,
282
274
  change,
283
275
  address_index,
284
276
  });
285
- const node = await getNode(parentKeyOrNode, cryptographicFunctions);
277
+ const node = await getNode(parentKeyOrNode);
286
278
  const childNode = await deriveChildNode({
287
279
  path,
288
280
  node,
289
- }, cryptographicFunctions);
281
+ });
290
282
  return new BIP44Node(childNode);
291
283
  }
292
284
  /**
@@ -306,14 +298,12 @@ export async function deriveBIP44AddressKey(parentKeyOrNode, { account = 0, chan
306
298
  * This node contains a BIP-44 key of depth 2, `coin_type`.
307
299
  * @param accountAndChangeIndices - The `account` and `change` indices that
308
300
  * will be used to derive addresses.
309
- * @param cryptographicFunctions - The cryptographic functions to use. If
310
- * provided, these will be used instead of the built-in implementations.
311
301
  * @returns The deriver function for the derivation path specified by the
312
302
  * `coin_type` node, `account`, and `change` indices.
313
303
  */
314
- export async function getBIP44AddressKeyDeriver(node, accountAndChangeIndices, cryptographicFunctions) {
304
+ export async function getBIP44AddressKeyDeriver(node, accountAndChangeIndices) {
315
305
  const { account = 0, change = 0 } = accountAndChangeIndices ?? {};
316
- const actualNode = await getNode(node, cryptographicFunctions);
306
+ const actualNode = await getNode(node);
317
307
  const accountNode = getHardenedBIP32NodeToken(account);
318
308
  const changeNode = getBIP32NodeToken(change);
319
309
  const bip44AddressKeyDeriver = async (address_index, isHardened = false) => {
@@ -326,7 +316,7 @@ export async function getBIP44AddressKeyDeriver(node, accountAndChangeIndices, c
326
316
  : getUnhardenedBIP32NodeToken(address_index),
327
317
  ],
328
318
  node: actualNode,
329
- }, cryptographicFunctions);
319
+ });
330
320
  return new BIP44Node(slip10Node);
331
321
  };
332
322
  bip44AddressKeyDeriver.coin_type = actualNode.coin_type;
@@ -344,22 +334,19 @@ export async function getBIP44AddressKeyDeriver(node, accountAndChangeIndices, c
344
334
  * The depth of the node is validated to be a valid coin type node.
345
335
  *
346
336
  * @param node - A BIP-44 coin type node, JSON node or extended key.
347
- * @param cryptographicFunctions - The cryptographic functions to use. If
348
- * provided, these will be used instead of the built-in implementations. This is
349
- * only used if the node is an extended key string or JSON object.
350
337
  * @returns A BIP44CoinType node.
351
338
  */
352
- async function getNode(node, cryptographicFunctions) {
339
+ async function getNode(node) {
353
340
  if (node instanceof BIP44CoinTypeNode) {
354
341
  validateCoinTypeNodeDepth(node.depth);
355
342
  return node;
356
343
  }
357
344
  if (typeof node === 'string') {
358
- const bip44Node = await BIP44Node.fromExtendedKey(node, cryptographicFunctions);
345
+ const bip44Node = await BIP44Node.fromExtendedKey(node);
359
346
  const coinTypeNode = await BIP44CoinTypeNode.fromNode(bip44Node, bip44Node.index - BIP_32_HARDENED_OFFSET);
360
347
  validateCoinTypeNodeDepth(coinTypeNode.depth);
361
348
  return coinTypeNode;
362
349
  }
363
- return BIP44CoinTypeNode.fromJSON(node, node.coin_type, cryptographicFunctions);
350
+ return BIP44CoinTypeNode.fromJSON(node, node.coin_type);
364
351
  }
365
352
  //# sourceMappingURL=BIP44CoinTypeNode.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"BIP44CoinTypeNode.js","sourceRoot":"","sources":["../src/BIP44CoinTypeNode.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAS3C,OAAO,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAGxD,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAElD,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,wBAAwB,EACxB,0BAA0B,EAC1B,kCAAkC,EAClC,yBAAyB,EACzB,2BAA2B,EAC3B,gBAAgB,EAChB,wBAAwB,GACzB,MAAM,YAAY,CAAC;AAcpB,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,CAAC;AAiBxC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ACpB,IAAwD,EACxD,sBAA+C;IAE/C,IAAI,IAAI,YAAY,iBAAiB,EAAE,CAAC;QACtC,yBAAyB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAEtC,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC7B,MAAM,SAAS,GAAG,MAAM,SAAS,CAAC,eAAe,CAC/C,IAAI,EACJ,sBAAsB,CACvB,CAAC;QACF,MAAM,YAAY,GAAG,MAAM,iBAAiB,CAAC,QAAQ,CACnD,SAAS,EACT,SAAS,CAAC,KAAK,GAAG,sBAAsB,CACzC,CAAC;QAEF,yBAAyB,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;QAE9C,OAAO,YAAY,CAAC;IACtB,CAAC;IAED,OAAO,iBAAiB,CAAC,QAAQ,CAC/B,IAAI,EACJ,IAAI,CAAC,SAAS,EACd,sBAAsB,CACvB,CAAC;AACJ,CAAC","sourcesContent":["import type { BIP44NodeInterface, JsonBIP44Node } from './BIP44Node.js';\nimport { BIP44Node } from './BIP44Node.js';\nimport type {\n BIP39Node,\n BIP44Depth,\n BIP44PurposeNodeToken,\n CoinTypeHDPathString,\n HardenedBIP32Node,\n Network,\n} from './constants.js';\nimport { BIP_32_HARDENED_OFFSET } from './constants.js';\nimport type { CryptographicFunctions } from './cryptography.js';\nimport type { SupportedCurve } from './curves/index.js';\nimport { deriveChildNode } from './SLIP10Node.js';\nimport type { CoinTypeToAddressIndices } from './utils.js';\nimport {\n getBIP44CoinType,\n getBIP32NodeToken,\n getBIP44ChangePathString,\n getBIP44CoinTypePathString,\n getBIP44CoinTypeToAddressPathTuple,\n getHardenedBIP32NodeToken,\n getUnhardenedBIP32NodeToken,\n hexStringToBytes,\n nullableHexStringToBytes,\n} from './utils.js';\n\nexport type CoinTypeHDPathTuple = [\n BIP39Node,\n typeof BIP44PurposeNodeToken,\n HardenedBIP32Node,\n];\n\nexport type CoinTypeSeedPathTuple = [\n Uint8Array,\n typeof BIP44PurposeNodeToken,\n HardenedBIP32Node,\n];\n\nexport const BIP_44_COIN_TYPE_DEPTH = 2;\n\nexport type JsonBIP44CoinTypeNode = JsonBIP44Node & {\n readonly coin_type: number;\n readonly path: CoinTypeHDPathString;\n};\n\nexport type BIP44CoinTypeNodeInterface = BIP44NodeInterface & {\n readonly coin_type: number;\n readonly path: CoinTypeHDPathString;\n};\n\nexport type BIP44CoinTypeSeedOptions = {\n readonly derivationPath: CoinTypeSeedPathTuple;\n readonly network?: Network | undefined;\n};\n\n/**\n * A wrapper object for BIP-44 `coin_type` keys. `coin_type` is the index\n * specifying the protocol for which deeper keys are intended. For the\n * authoritative list of coin types, please see\n * [SLIP-44](https://github.com/satoshilabs/slips/blob/master/slip-0044.md).\n *\n * Recall that a BIP-44 HD tree path consists of the following nodes:\n *\n * `m / 44' / coin_type' / account' / change / address_index`\n *\n * With the following depths:\n *\n * `0 / 1 / 2 / 3 / 4 / 5`\n *\n */\nexport class BIP44CoinTypeNode implements BIP44CoinTypeNodeInterface {\n /**\n * Constructs a BIP-44 `coin_type` node. `coin_type` is the index\n * specifying the protocol for which deeper keys are intended. For the\n * authoritative list of coin types, please see\n * [SLIP-44](https://github.com/satoshilabs/slips/blob/master/slip-0044.md).\n *\n * Recall that a BIP-44 HD tree path consists of the following nodes:\n *\n * `m / 44' / coin_type' / account' / change / address_index`\n *\n * With the following depths:\n *\n * `0 / 1 / 2 / 3 / 4 / 5`\n *\n * @param json - The {@link JsonBIP44Node} for the key of this node.\n * @param coin_type - The coin_type index of this node. Must be a non-negative\n * integer.\n * @param cryptographicFunctions - The cryptographic functions to use. If\n * provided, these will be used instead of the built-in implementations.\n * @returns A BIP44CoinType node.\n */\n static async fromJSON(\n json: JsonBIP44Node,\n coin_type: number,\n cryptographicFunctions?: CryptographicFunctions,\n ): Promise<BIP44CoinTypeNode> {\n validateCoinType(coin_type);\n validateCoinTypeNodeDepth(json.depth);\n\n const node = await BIP44Node.fromExtendedKey(\n {\n depth: json.depth,\n index: json.index,\n network: json.network,\n parentFingerprint: json.parentFingerprint,\n chainCode: hexStringToBytes(json.chainCode),\n privateKey: nullableHexStringToBytes(json.privateKey),\n publicKey: hexStringToBytes(json.publicKey),\n },\n cryptographicFunctions,\n );\n\n return new BIP44CoinTypeNode(node, coin_type);\n }\n\n /**\n * Construct a BIP-44 `coin_type` node. `coin_type` is the index\n * specifying the protocol for which deeper keys are intended. For the\n * authoritative list of coin types, please see\n * [SLIP-44](https://github.com/satoshilabs/slips/blob/master/slip-0044.md).\n *\n * Recall that a BIP-44 HD tree path consists of the following nodes:\n *\n * `m / 44' / coin_type' / account' / change / address_index`\n *\n * With the following depths:\n *\n * `0 / 1 / 2 / 3 / 4 / 5`\n *\n * @param derivationPath - The derivation path for the key of this node.\n * @param network - The network for the node. This is only used for extended\n * keys, and defaults to `mainnet`.\n * @param cryptographicFunctions - The cryptographic functions to use. If\n * provided, these will be used instead of the built-in implementations.\n * @returns A BIP44CoinType node.\n */\n static async fromDerivationPath(\n derivationPath: CoinTypeHDPathTuple,\n network?: Network | undefined,\n cryptographicFunctions?: CryptographicFunctions,\n ): Promise<BIP44CoinTypeNode> {\n validateCoinTypeNodeDepth(derivationPath.length - 1);\n\n const node = await BIP44Node.fromDerivationPath(\n {\n derivationPath,\n network,\n },\n cryptographicFunctions,\n );\n\n const coinType = getBIP44CoinType(derivationPath);\n return new BIP44CoinTypeNode(node, coinType);\n }\n\n /**\n * Create a new BIP-44 coin type node from a BIP-39 seed. The derivation path\n * must be rooted, i.e. it must begin with a BIP-39 node, given as a\n * `Uint8Array` of the seed bytes.\n *\n * All parameters are stringently validated, and an error is thrown if\n * validation fails.\n *\n * @param options - The options for the new node.\n * @param options.derivationPath - The rooted HD tree path that will be used\n * to derive the key of this node.\n * @param options.network - The network for the node. This is only used for\n * extended keys, and defaults to `mainnet`.\n * @param cryptographicFunctions - The cryptographic functions to use. If\n * provided, these will be used instead of the built-in implementations.\n * @returns A new BIP-44 node.\n */\n static async fromSeed(\n { derivationPath, network }: BIP44CoinTypeSeedOptions,\n cryptographicFunctions?: CryptographicFunctions,\n ): Promise<BIP44CoinTypeNode> {\n validateCoinTypeNodeDepth(derivationPath.length - 1);\n\n const node = await BIP44Node.fromSeed(\n {\n derivationPath,\n network,\n },\n cryptographicFunctions,\n );\n\n const coinType = getBIP44CoinType(derivationPath);\n return new BIP44CoinTypeNode(node, coinType);\n }\n\n /**\n * Constructs a BIP-44 `coin_type` node. `coin_type` is the index\n * specifying the protocol for which deeper keys are intended. For the\n * authoritative list of coin types, please see\n * [SLIP-44](https://github.com/satoshilabs/slips/blob/master/slip-0044.md).\n *\n * Recall that a BIP-44 HD tree path consists of the following nodes:\n *\n * `m / 44' / coin_type' / account' / change / address_index`\n *\n * With the following depths:\n *\n * `0 / 1 / 2 / 3 / 4 / 5`\n *\n * @param node - The {@link BIP44Node} for the key of this node.\n * @param coin_type - The coin_type index of this node. Must be a non-negative\n * integer.\n * @returns A BIP44CoinType node.\n */\n static async fromNode(\n node: BIP44Node,\n coin_type: number,\n ): Promise<BIP44CoinTypeNode> {\n if (!(node instanceof BIP44Node)) {\n throw new Error('Invalid node: Expected an instance of BIP44Node.');\n }\n\n validateCoinType(coin_type);\n validateCoinTypeNodeDepth(node.depth);\n\n // TODO: Make this function not async in a future version.\n return Promise.resolve(new BIP44CoinTypeNode(node, coin_type));\n }\n\n readonly #node: BIP44Node;\n\n public readonly path: CoinTypeHDPathString;\n\n public readonly coin_type: number;\n\n // Constructors cannot use hash names.\n // eslint-disable-next-line no-restricted-syntax\n private constructor(node: BIP44Node, coin_type: number) {\n this.#node = node;\n this.coin_type = coin_type;\n this.path = getBIP44CoinTypePathString(coin_type);\n\n Object.freeze(this);\n }\n\n public get depth(): BIP44Depth {\n return this.#node.depth;\n }\n\n public get privateKeyBytes(): Uint8Array | undefined {\n return this.#node.privateKeyBytes;\n }\n\n public get publicKeyBytes(): Uint8Array {\n return this.#node.publicKeyBytes;\n }\n\n public get chainCodeBytes(): Uint8Array {\n return this.#node.chainCodeBytes;\n }\n\n public get privateKey(): string | undefined {\n return this.#node.privateKey;\n }\n\n public get publicKey(): string {\n return this.#node.publicKey;\n }\n\n public get compressedPublicKey(): string {\n return this.#node.compressedPublicKey;\n }\n\n public get compressedPublicKeyBytes(): Uint8Array {\n return this.#node.compressedPublicKeyBytes;\n }\n\n public get chainCode(): string {\n return this.#node.chainCode;\n }\n\n public get address(): string {\n return this.#node.address;\n }\n\n public get masterFingerprint(): number | undefined {\n return this.#node.masterFingerprint;\n }\n\n public get parentFingerprint(): number {\n return this.#node.parentFingerprint;\n }\n\n public get fingerprint(): number {\n return this.#node.fingerprint;\n }\n\n public get index(): number {\n return this.#node.index;\n }\n\n public get network(): Network {\n return this.#node.network;\n }\n\n public get curve(): SupportedCurve {\n return this.#node.curve;\n }\n\n public get extendedKey(): string {\n return this.#node.extendedKey;\n }\n\n /**\n * Derives a BIP-44 `address_index` key corresponding to the path of this\n * node and the specified `account`, `change`, and `address_index` values.\n * `address_index` keys are normally the keys used to generate user account\n * addresses.\n *\n * Recall that a BIP-44 HD tree path consists of the following nodes:\n *\n * `m / 44' / coin_type' / account' / change / address_index`\n *\n * With the following depths:\n *\n * `0 / 1 / 2 / 3 / 4 / 5`\n *\n * @param indices - The BIP-44 index values to use in key derivation.\n * @param indices.account - The `account` index. Default: `0`\n * @param indices.change - The `change` index. Default: `0`\n * @param indices.address_index - The `address_index` index.\n * @returns The derived BIP-44 `address_index` node.\n */\n async deriveBIP44AddressKey({\n account = 0,\n change = 0,\n address_index,\n }: CoinTypeToAddressIndices): Promise<BIP44Node> {\n return await this.#node.derive(\n getBIP44CoinTypeToAddressPathTuple({ account, change, address_index }),\n );\n }\n\n toJSON(): JsonBIP44CoinTypeNode {\n return {\n ...this.#node.toJSON(),\n coin_type: this.coin_type,\n path: this.path,\n };\n }\n}\n\n/**\n * Validates the depth of a `coin_type` node. Simply, ensures that it is the\n * number `2`. An error is thrown if validation fails.\n *\n * @param depth - The depth to validate.\n */\nfunction validateCoinTypeNodeDepth(depth: number): void {\n if (depth !== BIP_44_COIN_TYPE_DEPTH) {\n throw new Error(\n `Invalid depth: Coin type nodes must be of depth ${BIP_44_COIN_TYPE_DEPTH}. Received: \"${depth}\"`,\n );\n }\n}\n\n/**\n * Validates that the coin type is a non-negative integer number. An error is\n * thrown if validation fails.\n *\n * @param coin_type - The coin type to validate.\n */\nfunction validateCoinType(coin_type: unknown): asserts coin_type is number {\n if (\n typeof coin_type !== 'number' ||\n !Number.isInteger(coin_type) ||\n coin_type < 0\n ) {\n throw new Error(\n 'Invalid coin type: The specified coin type must be a non-negative integer number.',\n );\n }\n}\n\n/**\n * Derives a BIP-44 address key corresponding to the specified derivation path,\n * given either by a {@link BIP44CoinTypeNode} or derivation path tuple.\n *\n * Recall that a BIP-44 HD tree path consists of the following nodes:\n *\n * `m / 44' / coin_type' / account' / change / address_index`\n *\n * With the following depths:\n *\n * `0 / 1 / 2 / 3 / 4 / 5`\n *\n * @param parentKeyOrNode - The `coin_type` parent key to derive from.\n * @param indices - The BIP-44 index values to use in key derivation.\n * @param indices.account - The `account` index. Default: `0`.\n * @param indices.change - The `change` index. Default: `0`.\n * @param indices.address_index - The `address_index` index.\n * @param cryptographicFunctions - The cryptographic functions to use. If\n * provided, these will be used instead of the built-in implementations.\n * @returns The derived `address_index` key for the specified derivation path.\n */\nexport async function deriveBIP44AddressKey(\n parentKeyOrNode: BIP44CoinTypeNode | JsonBIP44CoinTypeNode | string,\n { account = 0, change = 0, address_index }: CoinTypeToAddressIndices,\n cryptographicFunctions?: CryptographicFunctions,\n): Promise<BIP44Node> {\n const path = getBIP44CoinTypeToAddressPathTuple({\n account,\n change,\n address_index,\n });\n\n const node = await getNode(parentKeyOrNode, cryptographicFunctions);\n const childNode = await deriveChildNode(\n {\n path,\n node,\n },\n cryptographicFunctions,\n );\n\n return new BIP44Node(childNode);\n}\n\nexport type BIP44AddressKeyDeriver = {\n /**\n * @param address_index - The `address_index` value.\n * @param isHardened - Whether the derived index is hardened.\n * @returns The key corresponding to the path of this deriver and the\n * specified `address_index` value.\n */\n (address_index: number, isHardened?: boolean): Promise<BIP44Node>;\n\n /**\n * A human-readable representation of the derivation path of this deriver\n * function, excluding the `address_index`, which is parameterized.\n *\n * Recall that a BIP-44 HD tree path consists of the following nodes:\n *\n * `m / 44' / coin_type' / account' / change / address_index`\n *\n * With the following depths:\n *\n * `0 / 1 / 2 / 3 / 4 / 5`\n */\n path: ReturnType<typeof getBIP44ChangePathString>;\n\n /**\n * The `coin_type` index of addresses derived by this deriver function.\n */\n coin_type: number;\n};\n\n/**\n * Creates a function that derives BIP-44 address keys corresponding to the\n * specified derivation path, given either by a {@link BIP44CoinTypeNode} or\n * derivation path tuple.\n *\n * Recall that a BIP-44 HD tree path consists of the following nodes:\n *\n * `m / 44' / coin_type' / account' / change / address_index`\n *\n * With the following depths:\n *\n * `0 / 1 / 2 / 3 / 4 / 5`\n *\n * @param node - The {@link BIP44CoinTypeNode} to derive address keys from.\n * This node contains a BIP-44 key of depth 2, `coin_type`.\n * @param accountAndChangeIndices - The `account` and `change` indices that\n * will be used to derive addresses.\n * @param cryptographicFunctions - The cryptographic functions to use. If\n * provided, these will be used instead of the built-in implementations.\n * @returns The deriver function for the derivation path specified by the\n * `coin_type` node, `account`, and `change` indices.\n */\nexport async function getBIP44AddressKeyDeriver(\n node: BIP44CoinTypeNode | JsonBIP44CoinTypeNode | string,\n accountAndChangeIndices?: Omit<CoinTypeToAddressIndices, 'address_index'>,\n cryptographicFunctions?: CryptographicFunctions,\n): Promise<BIP44AddressKeyDeriver> {\n const { account = 0, change = 0 } = accountAndChangeIndices ?? {};\n\n const actualNode = await getNode(node, cryptographicFunctions);\n\n const accountNode = getHardenedBIP32NodeToken(account);\n const changeNode = getBIP32NodeToken(change);\n\n const bip44AddressKeyDeriver: BIP44AddressKeyDeriver = async (\n address_index: number,\n isHardened = false,\n ): Promise<BIP44Node> => {\n const slip10Node = await deriveChildNode(\n {\n path: [\n accountNode,\n changeNode,\n isHardened\n ? getHardenedBIP32NodeToken(address_index)\n : getUnhardenedBIP32NodeToken(address_index),\n ],\n node: actualNode,\n },\n cryptographicFunctions,\n );\n\n return new BIP44Node(slip10Node);\n };\n\n bip44AddressKeyDeriver.coin_type = actualNode.coin_type;\n bip44AddressKeyDeriver.path = getBIP44ChangePathString(actualNode.path, {\n account,\n change,\n });\n\n Object.freeze(bip44AddressKeyDeriver);\n\n return bip44AddressKeyDeriver;\n}\n\n/**\n * Get a BIP-44 coin type node from a JSON node or extended key string. If an existing coin type\n * node is provided, the same node is returned.\n *\n * The depth of the node is validated to be a valid coin type node.\n *\n * @param node - A BIP-44 coin type node, JSON node or extended key.\n * @param cryptographicFunctions - The cryptographic functions to use. If\n * provided, these will be used instead of the built-in implementations. This is\n * only used if the node is an extended key string or JSON object.\n * @returns A BIP44CoinType node.\n */\nasync function getNode(\n node: BIP44CoinTypeNode | JsonBIP44CoinTypeNode | string,\n cryptographicFunctions?: CryptographicFunctions,\n): Promise<BIP44CoinTypeNode> {\n if (node instanceof BIP44CoinTypeNode) {\n validateCoinTypeNodeDepth(node.depth);\n\n return node;\n }\n\n if (typeof node === 'string') {\n const bip44Node = await BIP44Node.fromExtendedKey(\n node,\n cryptographicFunctions,\n );\n const coinTypeNode = await BIP44CoinTypeNode.fromNode(\n bip44Node,\n bip44Node.index - BIP_32_HARDENED_OFFSET,\n );\n\n validateCoinTypeNodeDepth(coinTypeNode.depth);\n\n return coinTypeNode;\n }\n\n return BIP44CoinTypeNode.fromJSON(\n node,\n node.coin_type,\n cryptographicFunctions,\n );\n}\n"]}
1
+ {"version":3,"file":"BIP44CoinTypeNode.js","sourceRoot":"","sources":["../src/BIP44CoinTypeNode.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAS3C,OAAO,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAExD,OAAO,EAAE,eAAe,EAAE,MAAM,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AC;AAChC,CAAC;AAED;;;;;;;;GAQG;AACH,KAAK,UAAU,OAAO,CACpB,IAAwD;IAExD,IAAI,IAAI,YAAY,iBAAiB,EAAE,CAAC;QACtC,yBAAyB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAEtC,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC7B,MAAM,SAAS,GAAG,MAAM,SAAS,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;QACxD,MAAM,YAAY,GAAG,MAAM,iBAAiB,CAAC,QAAQ,CACnD,SAAS,EACT,SAAS,CAAC,KAAK,GAAG,sBAAsB,CACzC,CAAC;QAEF,yBAAyB,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;QAE9C,OAAO,YAAY,CAAC;IACtB,CAAC;IAED,OAAO,iBAAiB,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;AAC1D,CAAC","sourcesContent":["import type { BIP44NodeInterface, JsonBIP44Node } from './BIP44Node.js';\nimport { BIP44Node } from './BIP44Node.js';\nimport type {\n BIP39Node,\n BIP44Depth,\n BIP44PurposeNodeToken,\n CoinTypeHDPathString,\n HardenedBIP32Node,\n Network,\n} from './constants.js';\nimport { BIP_32_HARDENED_OFFSET } from './constants.js';\nimport type { SupportedCurve } from './curves/index.js';\nimport { deriveChildNode } from './SLIP10Node.js';\nimport type { CoinTypeToAddressIndices } from './utils.js';\nimport {\n getBIP44CoinType,\n getBIP32NodeToken,\n getBIP44ChangePathString,\n getBIP44CoinTypePathString,\n getBIP44CoinTypeToAddressPathTuple,\n getHardenedBIP32NodeToken,\n getUnhardenedBIP32NodeToken,\n hexStringToBytes,\n nullableHexStringToBytes,\n} from './utils.js';\n\nexport type CoinTypeHDPathTuple = [\n BIP39Node,\n typeof BIP44PurposeNodeToken,\n HardenedBIP32Node,\n];\n\nexport type CoinTypeSeedPathTuple = [\n Uint8Array<ArrayBuffer>,\n typeof BIP44PurposeNodeToken,\n HardenedBIP32Node,\n];\n\nexport const BIP_44_COIN_TYPE_DEPTH = 2;\n\nexport type JsonBIP44CoinTypeNode = JsonBIP44Node & {\n readonly coin_type: number;\n readonly path: CoinTypeHDPathString;\n};\n\nexport type BIP44CoinTypeNodeInterface = BIP44NodeInterface & {\n readonly coin_type: number;\n readonly path: CoinTypeHDPathString;\n};\n\nexport type BIP44CoinTypeSeedOptions = {\n readonly derivationPath: CoinTypeSeedPathTuple;\n readonly network?: Network | undefined;\n};\n\n/**\n * A wrapper object for BIP-44 `coin_type` keys. `coin_type` is the index\n * specifying the protocol for which deeper keys are intended. For the\n * authoritative list of coin types, please see\n * [SLIP-44](https://github.com/satoshilabs/slips/blob/master/slip-0044.md).\n *\n * Recall that a BIP-44 HD tree path consists of the following nodes:\n *\n * `m / 44' / coin_type' / account' / change / address_index`\n *\n * With the following depths:\n *\n * `0 / 1 / 2 / 3 / 4 / 5`\n *\n */\nexport class BIP44CoinTypeNode implements BIP44CoinTypeNodeInterface {\n /**\n * Constructs a BIP-44 `coin_type` node. `coin_type` is the index\n * specifying the protocol for which deeper keys are intended. For the\n * authoritative list of coin types, please see\n * [SLIP-44](https://github.com/satoshilabs/slips/blob/master/slip-0044.md).\n *\n * Recall that a BIP-44 HD tree path consists of the following nodes:\n *\n * `m / 44' / coin_type' / account' / change / address_index`\n *\n * With the following depths:\n *\n * `0 / 1 / 2 / 3 / 4 / 5`\n *\n * @param json - The {@link JsonBIP44Node} for the key of this node.\n * @param coin_type - The coin_type index of this node. Must be a non-negative\n * integer.\n * @returns A BIP44CoinType node.\n */\n static async fromJSON(\n json: JsonBIP44Node,\n coin_type: number,\n ): Promise<BIP44CoinTypeNode> {\n validateCoinType(coin_type);\n validateCoinTypeNodeDepth(json.depth);\n\n const node = await BIP44Node.fromExtendedKey({\n depth: json.depth,\n index: json.index,\n network: json.network,\n parentFingerprint: json.parentFingerprint,\n chainCode: hexStringToBytes(json.chainCode),\n privateKey: nullableHexStringToBytes(json.privateKey),\n publicKey: hexStringToBytes(json.publicKey),\n });\n\n return new BIP44CoinTypeNode(node, coin_type);\n }\n\n /**\n * Construct a BIP-44 `coin_type` node. `coin_type` is the index\n * specifying the protocol for which deeper keys are intended. For the\n * authoritative list of coin types, please see\n * [SLIP-44](https://github.com/satoshilabs/slips/blob/master/slip-0044.md).\n *\n * Recall that a BIP-44 HD tree path consists of the following nodes:\n *\n * `m / 44' / coin_type' / account' / change / address_index`\n *\n * With the following depths:\n *\n * `0 / 1 / 2 / 3 / 4 / 5`\n *\n * @param derivationPath - The derivation path for the key of this node.\n * @param network - The network for the node. This is only used for extended\n * keys, and defaults to `mainnet`.\n * @returns A BIP44CoinType node.\n */\n static async fromDerivationPath(\n derivationPath: CoinTypeHDPathTuple,\n network?: Network | undefined,\n ): Promise<BIP44CoinTypeNode> {\n validateCoinTypeNodeDepth(derivationPath.length - 1);\n\n const node = await BIP44Node.fromDerivationPath({\n derivationPath,\n network,\n });\n\n const coinType = getBIP44CoinType(derivationPath);\n return new BIP44CoinTypeNode(node, coinType);\n }\n\n /**\n * Create a new BIP-44 coin type node from a BIP-39 seed. The derivation path\n * must be rooted, i.e. it must begin with a BIP-39 node, given as a\n * `Uint8Array` of the seed bytes.\n *\n * All parameters are stringently validated, and an error is thrown if\n * validation fails.\n *\n * @param options - The options for the new node.\n * @param options.derivationPath - The rooted HD tree path that will be used\n * to derive the key of this node.\n * @param options.network - The network for the node. This is only used for\n * extended keys, and defaults to `mainnet`.\n * @returns A new BIP-44 node.\n */\n static async fromSeed({\n derivationPath,\n network,\n }: BIP44CoinTypeSeedOptions): Promise<BIP44CoinTypeNode> {\n validateCoinTypeNodeDepth(derivationPath.length - 1);\n\n const node = await BIP44Node.fromSeed({\n derivationPath,\n network,\n });\n\n const coinType = getBIP44CoinType(derivationPath);\n return new BIP44CoinTypeNode(node, coinType);\n }\n\n /**\n * Constructs a BIP-44 `coin_type` node. `coin_type` is the index\n * specifying the protocol for which deeper keys are intended. For the\n * authoritative list of coin types, please see\n * [SLIP-44](https://github.com/satoshilabs/slips/blob/master/slip-0044.md).\n *\n * Recall that a BIP-44 HD tree path consists of the following nodes:\n *\n * `m / 44' / coin_type' / account' / change / address_index`\n *\n * With the following depths:\n *\n * `0 / 1 / 2 / 3 / 4 / 5`\n *\n * @param node - The {@link BIP44Node} for the key of this node.\n * @param coin_type - The coin_type index of this node. Must be a non-negative\n * integer.\n * @returns A BIP44CoinType node.\n */\n static async fromNode(\n node: BIP44Node,\n coin_type: number,\n ): Promise<BIP44CoinTypeNode> {\n if (!(node instanceof BIP44Node)) {\n throw new Error('Invalid node: Expected an instance of BIP44Node.');\n }\n\n validateCoinType(coin_type);\n validateCoinTypeNodeDepth(node.depth);\n\n // TODO: Make this function not async in a future version.\n return Promise.resolve(new BIP44CoinTypeNode(node, coin_type));\n }\n\n readonly #node: BIP44Node;\n\n public readonly path: CoinTypeHDPathString;\n\n public readonly coin_type: number;\n\n // Constructors cannot use hash names.\n // eslint-disable-next-line no-restricted-syntax\n private constructor(node: BIP44Node, coin_type: number) {\n this.#node = node;\n this.coin_type = coin_type;\n this.path = getBIP44CoinTypePathString(coin_type);\n\n Object.freeze(this);\n }\n\n public get depth(): BIP44Depth {\n return this.#node.depth;\n }\n\n public get privateKeyBytes(): Uint8Array<ArrayBuffer> | undefined {\n return this.#node.privateKeyBytes;\n }\n\n public get publicKeyBytes(): Uint8Array<ArrayBuffer> {\n return this.#node.publicKeyBytes;\n }\n\n public get chainCodeBytes(): Uint8Array<ArrayBuffer> {\n return this.#node.chainCodeBytes;\n }\n\n public get privateKey(): string | undefined {\n return this.#node.privateKey;\n }\n\n public get publicKey(): string {\n return this.#node.publicKey;\n }\n\n public get compressedPublicKey(): string {\n return this.#node.compressedPublicKey;\n }\n\n public get compressedPublicKeyBytes(): Uint8Array<ArrayBuffer> {\n return this.#node.compressedPublicKeyBytes;\n }\n\n public get chainCode(): string {\n return this.#node.chainCode;\n }\n\n public get address(): string {\n return this.#node.address;\n }\n\n public get masterFingerprint(): number | undefined {\n return this.#node.masterFingerprint;\n }\n\n public get parentFingerprint(): number {\n return this.#node.parentFingerprint;\n }\n\n public get fingerprint(): number {\n return this.#node.fingerprint;\n }\n\n public get index(): number {\n return this.#node.index;\n }\n\n public get network(): Network {\n return this.#node.network;\n }\n\n public get curve(): SupportedCurve {\n return this.#node.curve;\n }\n\n public get extendedKey(): string {\n return this.#node.extendedKey;\n }\n\n /**\n * Derives a BIP-44 `address_index` key corresponding to the path of this\n * node and the specified `account`, `change`, and `address_index` values.\n * `address_index` keys are normally the keys used to generate user account\n * addresses.\n *\n * Recall that a BIP-44 HD tree path consists of the following nodes:\n *\n * `m / 44' / coin_type' / account' / change / address_index`\n *\n * With the following depths:\n *\n * `0 / 1 / 2 / 3 / 4 / 5`\n *\n * @param indices - The BIP-44 index values to use in key derivation.\n * @param indices.account - The `account` index. Default: `0`\n * @param indices.change - The `change` index. Default: `0`\n * @param indices.address_index - The `address_index` index.\n * @returns The derived BIP-44 `address_index` node.\n */\n async deriveBIP44AddressKey({\n account = 0,\n change = 0,\n address_index,\n }: CoinTypeToAddressIndices): Promise<BIP44Node> {\n return await this.#node.derive(\n getBIP44CoinTypeToAddressPathTuple({ account, change, address_index }),\n );\n }\n\n toJSON(): JsonBIP44CoinTypeNode {\n return {\n ...this.#node.toJSON(),\n coin_type: this.coin_type,\n path: this.path,\n };\n }\n}\n\n/**\n * Validates the depth of a `coin_type` node. Simply, ensures that it is the\n * number `2`. An error is thrown if validation fails.\n *\n * @param depth - The depth to validate.\n */\nfunction validateCoinTypeNodeDepth(depth: number): void {\n if (depth !== BIP_44_COIN_TYPE_DEPTH) {\n throw new Error(\n `Invalid depth: Coin type nodes must be of depth ${BIP_44_COIN_TYPE_DEPTH}. Received: \"${depth}\"`,\n );\n }\n}\n\n/**\n * Validates that the coin type is a non-negative integer number. An error is\n * thrown if validation fails.\n *\n * @param coin_type - The coin type to validate.\n */\nfunction validateCoinType(coin_type: unknown): asserts coin_type is number {\n if (\n typeof coin_type !== 'number' ||\n !Number.isInteger(coin_type) ||\n coin_type < 0\n ) {\n throw new Error(\n 'Invalid coin type: The specified coin type must be a non-negative integer number.',\n );\n }\n}\n\n/**\n * Derives a BIP-44 address key corresponding to the specified derivation path,\n * given either by a {@link BIP44CoinTypeNode} or derivation path tuple.\n *\n * Recall that a BIP-44 HD tree path consists of the following nodes:\n *\n * `m / 44' / coin_type' / account' / change / address_index`\n *\n * With the following depths:\n *\n * `0 / 1 / 2 / 3 / 4 / 5`\n *\n * @param parentKeyOrNode - The `coin_type` parent key to derive from.\n * @param indices - The BIP-44 index values to use in key derivation.\n * @param indices.account - The `account` index. Default: `0`.\n * @param indices.change - The `change` index. Default: `0`.\n * @param indices.address_index - The `address_index` index.\n * @returns The derived `address_index` key for the specified derivation path.\n */\nexport async function deriveBIP44AddressKey(\n parentKeyOrNode: BIP44CoinTypeNode | JsonBIP44CoinTypeNode | string,\n { account = 0, change = 0, address_index }: CoinTypeToAddressIndices,\n): Promise<BIP44Node> {\n const path = getBIP44CoinTypeToAddressPathTuple({\n account,\n change,\n address_index,\n });\n\n const node = await getNode(parentKeyOrNode);\n const childNode = await deriveChildNode({\n path,\n node,\n });\n\n return new BIP44Node(childNode);\n}\n\nexport type BIP44AddressKeyDeriver = {\n /**\n * @param address_index - The `address_index` value.\n * @param isHardened - Whether the derived index is hardened.\n * @returns The key corresponding to the path of this deriver and the\n * specified `address_index` value.\n */\n (address_index: number, isHardened?: boolean): Promise<BIP44Node>;\n\n /**\n * A human-readable representation of the derivation path of this deriver\n * function, excluding the `address_index`, which is parameterized.\n *\n * Recall that a BIP-44 HD tree path consists of the following nodes:\n *\n * `m / 44' / coin_type' / account' / change / address_index`\n *\n * With the following depths:\n *\n * `0 / 1 / 2 / 3 / 4 / 5`\n */\n path: ReturnType<typeof getBIP44ChangePathString>;\n\n /**\n * The `coin_type` index of addresses derived by this deriver function.\n */\n coin_type: number;\n};\n\n/**\n * Creates a function that derives BIP-44 address keys corresponding to the\n * specified derivation path, given either by a {@link BIP44CoinTypeNode} or\n * derivation path tuple.\n *\n * Recall that a BIP-44 HD tree path consists of the following nodes:\n *\n * `m / 44' / coin_type' / account' / change / address_index`\n *\n * With the following depths:\n *\n * `0 / 1 / 2 / 3 / 4 / 5`\n *\n * @param node - The {@link BIP44CoinTypeNode} to derive address keys from.\n * This node contains a BIP-44 key of depth 2, `coin_type`.\n * @param accountAndChangeIndices - The `account` and `change` indices that\n * will be used to derive addresses.\n * @returns The deriver function for the derivation path specified by the\n * `coin_type` node, `account`, and `change` indices.\n */\nexport async function getBIP44AddressKeyDeriver(\n node: BIP44CoinTypeNode | JsonBIP44CoinTypeNode | string,\n accountAndChangeIndices?: Omit<CoinTypeToAddressIndices, 'address_index'>,\n): Promise<BIP44AddressKeyDeriver> {\n const { account = 0, change = 0 } = accountAndChangeIndices ?? {};\n\n const actualNode = await getNode(node);\n\n const accountNode = getHardenedBIP32NodeToken(account);\n const changeNode = getBIP32NodeToken(change);\n\n const bip44AddressKeyDeriver: BIP44AddressKeyDeriver = async (\n address_index: number,\n isHardened = false,\n ): Promise<BIP44Node> => {\n const slip10Node = await deriveChildNode({\n path: [\n accountNode,\n changeNode,\n isHardened\n ? getHardenedBIP32NodeToken(address_index)\n : getUnhardenedBIP32NodeToken(address_index),\n ],\n node: actualNode,\n });\n\n return new BIP44Node(slip10Node);\n };\n\n bip44AddressKeyDeriver.coin_type = actualNode.coin_type;\n bip44AddressKeyDeriver.path = getBIP44ChangePathString(actualNode.path, {\n account,\n change,\n });\n\n Object.freeze(bip44AddressKeyDeriver);\n\n return bip44AddressKeyDeriver;\n}\n\n/**\n * Get a BIP-44 coin type node from a JSON node or extended key string. If an existing coin type\n * node is provided, the same node is returned.\n *\n * The depth of the node is validated to be a valid coin type node.\n *\n * @param node - A BIP-44 coin type node, JSON node or extended key.\n * @returns A BIP44CoinType node.\n */\nasync function getNode(\n node: BIP44CoinTypeNode | JsonBIP44CoinTypeNode | string,\n): Promise<BIP44CoinTypeNode> {\n if (node instanceof BIP44CoinTypeNode) {\n validateCoinTypeNodeDepth(node.depth);\n\n return node;\n }\n\n if (typeof node === 'string') {\n const bip44Node = await BIP44Node.fromExtendedKey(node);\n const coinTypeNode = await BIP44CoinTypeNode.fromNode(\n bip44Node,\n bip44Node.index - BIP_32_HARDENED_OFFSET,\n );\n\n validateCoinTypeNodeDepth(coinTypeNode.depth);\n\n return coinTypeNode;\n }\n\n return BIP44CoinTypeNode.fromJSON(node, node.coin_type);\n}\n"]}
@@ -1,5 +1,4 @@
1
1
  import type { BIP44Depth, Network, PartialHDPathTuple, RootedSLIP10PathTuple, RootedSLIP10SeedPathTuple } from './constants.js';
2
- import type { CryptographicFunctions } from './cryptography.js';
3
2
  import type { SupportedCurve } from './curves/index.js';
4
3
  import { SLIP10Node } from './SLIP10Node.js';
5
4
  export type BIP44ExtendedKeyOptions = {
@@ -7,9 +6,9 @@ export type BIP44ExtendedKeyOptions = {
7
6
  readonly parentFingerprint: number;
8
7
  readonly index: number;
9
8
  readonly network?: Network | undefined;
10
- readonly chainCode: Uint8Array | string;
11
- readonly privateKey?: Uint8Array | string | undefined;
12
- readonly publicKey?: Uint8Array | string | undefined;
9
+ readonly chainCode: Uint8Array<ArrayBuffer> | string;
10
+ readonly privateKey?: Uint8Array<ArrayBuffer> | string | undefined;
11
+ readonly publicKey?: Uint8Array<ArrayBuffer> | string | undefined;
13
12
  };
14
13
  export type BIP44DerivationPathOptions = {
15
14
  readonly derivationPath: RootedSLIP10PathTuple;
@@ -90,11 +89,9 @@ export declare class BIP44Node implements BIP44NodeInterface {
90
89
  * for documentation.
91
90
  *
92
91
  * @param json - The JSON representation of a SLIP-10 node.
93
- * @param cryptographicFunctions - The cryptographic functions to use. If
94
- * provided, these will be used instead of the built-in implementations.
95
92
  * @returns A BIP44 node.
96
93
  */
97
- static fromJSON(json: JsonBIP44Node, cryptographicFunctions?: CryptographicFunctions): Promise<BIP44Node>;
94
+ static fromJSON(json: JsonBIP44Node): Promise<BIP44Node>;
98
95
  /**
99
96
  * Create a new BIP-44 node from a key and chain code. You must specify
100
97
  * either a private key or a public key. When specifying a private key,
@@ -112,11 +109,9 @@ export declare class BIP44Node implements BIP44NodeInterface {
112
109
  * @param options.publicKey - The public key for the node. If a private key is
113
110
  * specified, this parameter is ignored.
114
111
  * @param options.chainCode - The chain code for the node.
115
- * @param cryptographicFunctions - The cryptographic functions to use. If
116
- * provided, these will be used instead of the built-in implementations.
117
112
  * @returns A BIP44 node.
118
113
  */
119
- static fromExtendedKey(options: BIP44ExtendedKeyOptions | string, cryptographicFunctions?: CryptographicFunctions): Promise<BIP44Node>;
114
+ static fromExtendedKey(options: BIP44ExtendedKeyOptions | string): Promise<BIP44Node>;
120
115
  /**
121
116
  * Create a new BIP-44 node from a derivation path. The derivation path
122
117
  * must be rooted, i.e. it must begin with a BIP-39 node, given as a string of
@@ -139,11 +134,9 @@ export declare class BIP44Node implements BIP44NodeInterface {
139
134
  * to derive the key of this node.
140
135
  * @param options.network - The network for the node. This is only used for
141
136
  * extended keys, and defaults to `mainnet`.
142
- * @param cryptographicFunctions - The cryptographic functions to use. If
143
- * provided, these will be used instead of the built-in implementations.
144
137
  * @returns A BIP44 node.
145
138
  */
146
- static fromDerivationPath({ derivationPath, network }: BIP44DerivationPathOptions, cryptographicFunctions?: CryptographicFunctions): Promise<BIP44Node>;
139
+ static fromDerivationPath({ derivationPath, network, }: BIP44DerivationPathOptions): Promise<BIP44Node>;
147
140
  /**
148
141
  * Create a new BIP-44 node from a BIP-39 seed. The derivation path must be
149
142
  * rooted, i.e. it must begin with a BIP-39 node, given as a `Uint8Array` of
@@ -157,19 +150,17 @@ export declare class BIP44Node implements BIP44NodeInterface {
157
150
  * to derive the key of this node.
158
151
  * @param options.network - The network for the node. This is only used for
159
152
  * extended keys, and defaults to `mainnet`.
160
- * @param cryptographicFunctions - The cryptographic functions to use. If
161
- * provided, these will be used instead of the built-in implementations.
162
153
  * @returns A new BIP-44 node.
163
154
  */
164
- static fromSeed({ derivationPath, network }: BIP44SeedOptions, cryptographicFunctions?: CryptographicFunctions): Promise<BIP44Node>;
155
+ static fromSeed({ derivationPath, network, }: BIP44SeedOptions): Promise<BIP44Node>;
165
156
  get depth(): BIP44Depth;
166
- get privateKeyBytes(): Uint8Array | undefined;
167
- get publicKeyBytes(): Uint8Array;
168
- get chainCodeBytes(): Uint8Array;
157
+ get privateKeyBytes(): Uint8Array<ArrayBuffer> | undefined;
158
+ get publicKeyBytes(): Uint8Array<ArrayBuffer>;
159
+ get chainCodeBytes(): Uint8Array<ArrayBuffer>;
169
160
  get privateKey(): string | undefined;
170
161
  get publicKey(): string;
171
162
  get compressedPublicKey(): string;
172
- get compressedPublicKeyBytes(): Uint8Array;
163
+ get compressedPublicKeyBytes(): Uint8Array<ArrayBuffer>;
173
164
  get chainCode(): string;
174
165
  get address(): string;
175
166
  get masterFingerprint(): number | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"BIP44Node.d.ts","sourceRoot":"","sources":["../src/BIP44Node.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,UAAU,EACV,OAAO,EACP,kBAAkB,EAClB,qBAAqB,EACrB,yBAAyB,EAE1B,MAAM,gBAAgB,CAAC;AAQxB,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAChE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAExD,OAAO,EAAE,UAAU,EAAsB,MAAM,iBAAiB,CAAC;AAGjE,MAAM,MAAM,uBAAuB,GAAG;IACpC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;IACnC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IACvC,QAAQ,CAAC,SAAS,EAAE,UAAU,GAAG,MAAM,CAAC;IACx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B,kBAAkB,CAChC,KAAK,EAAE,OAAO,GACb,OAAO,CAAC,KAAK,IAAI,UAAU,CAQ7B"}
package/dist/BIP44Node.js CHANGED
@@ -17,12 +17,10 @@ export class BIP44Node {
17
17
  * for documentation.
18
18
  *
19
19
  * @param json - The JSON representation of a SLIP-10 node.
20
- * @param cryptographicFunctions - The cryptographic functions to use. If
21
- * provided, these will be used instead of the built-in implementations.
22
20
  * @returns A BIP44 node.
23
21
  */
24
- static async fromJSON(json, cryptographicFunctions) {
25
- return BIP44Node.fromExtendedKey(json, cryptographicFunctions);
22
+ static async fromJSON(json) {
23
+ return BIP44Node.fromExtendedKey(json);
26
24
  }
27
25
  /**
28
26
  * Create a new BIP-44 node from a key and chain code. You must specify
@@ -41,11 +39,9 @@ export class BIP44Node {
41
39
  * @param options.publicKey - The public key for the node. If a private key is
42
40
  * specified, this parameter is ignored.
43
41
  * @param options.chainCode - The chain code for the node.
44
- * @param cryptographicFunctions - The cryptographic functions to use. If
45
- * provided, these will be used instead of the built-in implementations.
46
42
  * @returns A BIP44 node.
47
43
  */
48
- static async fromExtendedKey(options, cryptographicFunctions) {
44
+ static async fromExtendedKey(options) {
49
45
  if (typeof options === 'string') {
50
46
  const extendedKey = decodeExtendedKey(options);
51
47
  const { type, chainCode, depth, parentFingerprint, index, network } = extendedKey;
@@ -58,7 +54,7 @@ export class BIP44Node {
58
54
  network,
59
55
  privateKey,
60
56
  chainCode,
61
- }, cryptographicFunctions);
57
+ });
62
58
  }
63
59
  const { publicKey } = extendedKey;
64
60
  return BIP44Node.fromExtendedKey({
@@ -68,7 +64,7 @@ export class BIP44Node {
68
64
  network,
69
65
  publicKey,
70
66
  chainCode,
71
- }, cryptographicFunctions);
67
+ });
72
68
  }
73
69
  const { privateKey, publicKey, chainCode, depth, parentFingerprint, index, network, } = options;
74
70
  validateBIP44Depth(depth);
@@ -81,7 +77,7 @@ export class BIP44Node {
81
77
  index,
82
78
  network,
83
79
  curve: 'secp256k1',
84
- }, cryptographicFunctions);
80
+ });
85
81
  return new BIP44Node(node);
86
82
  }
87
83
  /**
@@ -106,18 +102,16 @@ export class BIP44Node {
106
102
  * to derive the key of this node.
107
103
  * @param options.network - The network for the node. This is only used for
108
104
  * extended keys, and defaults to `mainnet`.
109
- * @param cryptographicFunctions - The cryptographic functions to use. If
110
- * provided, these will be used instead of the built-in implementations.
111
105
  * @returns A BIP44 node.
112
106
  */
113
- static async fromDerivationPath({ derivationPath, network }, cryptographicFunctions) {
107
+ static async fromDerivationPath({ derivationPath, network, }) {
114
108
  validateBIP44Depth(derivationPath.length - 1);
115
109
  validateBIP44DerivationPath(derivationPath, MIN_BIP_44_DEPTH);
116
110
  const node = await SLIP10Node.fromDerivationPath({
117
111
  derivationPath,
118
112
  network,
119
113
  curve: 'secp256k1',
120
- }, cryptographicFunctions);
114
+ });
121
115
  return new BIP44Node(node);
122
116
  }
123
117
  /**
@@ -133,18 +127,16 @@ export class BIP44Node {
133
127
  * to derive the key of this node.
134
128
  * @param options.network - The network for the node. This is only used for
135
129
  * extended keys, and defaults to `mainnet`.
136
- * @param cryptographicFunctions - The cryptographic functions to use. If
137
- * provided, these will be used instead of the built-in implementations.
138
130
  * @returns A new BIP-44 node.
139
131
  */
140
- static async fromSeed({ derivationPath, network }, cryptographicFunctions) {
132
+ static async fromSeed({ derivationPath, network, }) {
141
133
  validateBIP44Depth(derivationPath.length - 1);
142
134
  validateBIP44DerivationPath(derivationPath, MIN_BIP_44_DEPTH);
143
135
  const node = await SLIP10Node.fromSeed({
144
136
  derivationPath,
145
137
  network,
146
138
  curve: 'secp256k1',
147
- }, cryptographicFunctions);
139
+ });
148
140
  return new BIP44Node(node);
149
141
  }
150
142
  #node;