@metamask/snaps-rpc-methods 11.5.1 → 11.7.0

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 (88) hide show
  1. package/CHANGELOG.md +17 -1
  2. package/dist/permitted/createInterface.cjs.map +1 -1
  3. package/dist/permitted/createInterface.d.cts +6 -18
  4. package/dist/permitted/createInterface.d.cts.map +1 -1
  5. package/dist/permitted/createInterface.d.mts +6 -18
  6. package/dist/permitted/createInterface.d.mts.map +1 -1
  7. package/dist/permitted/createInterface.mjs.map +1 -1
  8. package/dist/permitted/getInterfaceContext.cjs +62 -0
  9. package/dist/permitted/getInterfaceContext.cjs.map +1 -0
  10. package/dist/permitted/getInterfaceContext.d.cts +19 -0
  11. package/dist/permitted/getInterfaceContext.d.cts.map +1 -0
  12. package/dist/permitted/getInterfaceContext.d.mts +19 -0
  13. package/dist/permitted/getInterfaceContext.d.mts.map +1 -0
  14. package/dist/permitted/getInterfaceContext.mjs +59 -0
  15. package/dist/permitted/getInterfaceContext.mjs.map +1 -0
  16. package/dist/permitted/handlers.cjs +2 -0
  17. package/dist/permitted/handlers.cjs.map +1 -1
  18. package/dist/permitted/handlers.d.cts +2 -1
  19. package/dist/permitted/handlers.d.cts.map +1 -1
  20. package/dist/permitted/handlers.d.mts +2 -1
  21. package/dist/permitted/handlers.d.mts.map +1 -1
  22. package/dist/permitted/handlers.mjs +2 -0
  23. package/dist/permitted/handlers.mjs.map +1 -1
  24. package/dist/permitted/updateInterface.d.cts +2 -2
  25. package/dist/permitted/updateInterface.d.mts +2 -2
  26. package/dist/restricted/dialog.cjs.map +1 -1
  27. package/dist/restricted/dialog.d.cts +62 -62
  28. package/dist/restricted/dialog.d.cts.map +1 -1
  29. package/dist/restricted/dialog.d.mts +62 -62
  30. package/dist/restricted/dialog.d.mts.map +1 -1
  31. package/dist/restricted/dialog.mjs.map +1 -1
  32. package/dist/restricted/getBip32Entropy.cjs +5 -1
  33. package/dist/restricted/getBip32Entropy.cjs.map +1 -1
  34. package/dist/restricted/getBip32Entropy.d.cts +12 -1
  35. package/dist/restricted/getBip32Entropy.d.cts.map +1 -1
  36. package/dist/restricted/getBip32Entropy.d.mts +12 -1
  37. package/dist/restricted/getBip32Entropy.d.mts.map +1 -1
  38. package/dist/restricted/getBip32Entropy.mjs +5 -1
  39. package/dist/restricted/getBip32Entropy.mjs.map +1 -1
  40. package/dist/restricted/getBip32PublicKey.cjs +5 -1
  41. package/dist/restricted/getBip32PublicKey.cjs.map +1 -1
  42. package/dist/restricted/getBip32PublicKey.d.cts +12 -1
  43. package/dist/restricted/getBip32PublicKey.d.cts.map +1 -1
  44. package/dist/restricted/getBip32PublicKey.d.mts +12 -1
  45. package/dist/restricted/getBip32PublicKey.d.mts.map +1 -1
  46. package/dist/restricted/getBip32PublicKey.mjs +5 -1
  47. package/dist/restricted/getBip32PublicKey.mjs.map +1 -1
  48. package/dist/restricted/getBip44Entropy.cjs +5 -6
  49. package/dist/restricted/getBip44Entropy.cjs.map +1 -1
  50. package/dist/restricted/getBip44Entropy.d.cts +12 -1
  51. package/dist/restricted/getBip44Entropy.d.cts.map +1 -1
  52. package/dist/restricted/getBip44Entropy.d.mts +12 -1
  53. package/dist/restricted/getBip44Entropy.d.mts.map +1 -1
  54. package/dist/restricted/getBip44Entropy.mjs +5 -6
  55. package/dist/restricted/getBip44Entropy.mjs.map +1 -1
  56. package/dist/restricted/getEntropy.cjs +5 -1
  57. package/dist/restricted/getEntropy.cjs.map +1 -1
  58. package/dist/restricted/getEntropy.d.cts +12 -1
  59. package/dist/restricted/getEntropy.d.cts.map +1 -1
  60. package/dist/restricted/getEntropy.d.mts +12 -1
  61. package/dist/restricted/getEntropy.d.mts.map +1 -1
  62. package/dist/restricted/getEntropy.mjs +5 -1
  63. package/dist/restricted/getEntropy.mjs.map +1 -1
  64. package/dist/restricted/manageState.cjs +4 -1
  65. package/dist/restricted/manageState.cjs.map +1 -1
  66. package/dist/restricted/manageState.d.cts +5 -1
  67. package/dist/restricted/manageState.d.cts.map +1 -1
  68. package/dist/restricted/manageState.d.mts +5 -1
  69. package/dist/restricted/manageState.d.mts.map +1 -1
  70. package/dist/restricted/manageState.mjs +4 -1
  71. package/dist/restricted/manageState.mjs.map +1 -1
  72. package/dist/restricted/notify.cjs +49 -5
  73. package/dist/restricted/notify.cjs.map +1 -1
  74. package/dist/restricted/notify.d.cts +311 -13
  75. package/dist/restricted/notify.d.cts.map +1 -1
  76. package/dist/restricted/notify.d.mts +311 -13
  77. package/dist/restricted/notify.d.mts.map +1 -1
  78. package/dist/restricted/notify.mjs +52 -8
  79. package/dist/restricted/notify.mjs.map +1 -1
  80. package/dist/utils.cjs +8 -4
  81. package/dist/utils.cjs.map +1 -1
  82. package/dist/utils.d.cts +12 -3
  83. package/dist/utils.d.cts.map +1 -1
  84. package/dist/utils.d.mts +12 -3
  85. package/dist/utils.d.mts.map +1 -1
  86. package/dist/utils.mjs +8 -4
  87. package/dist/utils.mjs.map +1 -1
  88. package/package.json +5 -5
package/dist/utils.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import type { SupportedCurve } from "@metamask/key-tree";
1
+ import type { SupportedCurve, CryptographicFunctions } from "@metamask/key-tree";
2
2
  import { SLIP10Node } from "@metamask/key-tree";
3
3
  import type { MagicValue } from "@metamask/snaps-utils";
4
4
  import type { Hex } from "@metamask/utils";
@@ -41,6 +41,10 @@ type DeriveEntropyOptions = {
41
41
  * mnemonic phrase.
42
42
  */
43
43
  magic: MagicValue;
44
+ /**
45
+ * The cryptographic functions to use for the derivation.
46
+ */
47
+ cryptographicFunctions: CryptographicFunctions | undefined;
44
48
  };
45
49
  /**
46
50
  * Derive entropy from the given mnemonic phrase and salt.
@@ -55,9 +59,11 @@ type DeriveEntropyOptions = {
55
59
  * derivation.
56
60
  * @param options.magic - A hardened BIP-32 index, which is used to derive the
57
61
  * root key from the mnemonic phrase.
62
+ * @param options.cryptographicFunctions - The cryptographic functions to use
63
+ * for the derivation.
58
64
  * @returns The derived entropy.
59
65
  */
60
- export declare function deriveEntropy({ input, salt, mnemonicPhrase, magic, }: DeriveEntropyOptions): Promise<Hex>;
66
+ export declare function deriveEntropy({ input, salt, mnemonicPhrase, magic, cryptographicFunctions, }: DeriveEntropyOptions): Promise<Hex>;
61
67
  /**
62
68
  * Get the path prefix to use for key derivation in `key-tree`. This assumes the
63
69
  * following:
@@ -78,6 +84,7 @@ type GetNodeArgs = {
78
84
  curve: SupportedCurve;
79
85
  secretRecoveryPhrase: Uint8Array;
80
86
  path: string[];
87
+ cryptographicFunctions: CryptographicFunctions | undefined;
81
88
  };
82
89
  /**
83
90
  * Get a `key-tree`-compatible node.
@@ -91,8 +98,10 @@ type GetNodeArgs = {
91
98
  * derivation.
92
99
  * @param options.path - The derivation path to use as array, starting with an
93
100
  * "m" as the first item.
101
+ * @param options.cryptographicFunctions - The cryptographic functions to use
102
+ * for the node.
94
103
  * @returns The `key-tree` SLIP-10 node.
95
104
  */
96
- export declare function getNode({ curve, secretRecoveryPhrase, path, }: GetNodeArgs): Promise<SLIP10Node>;
105
+ export declare function getNode({ curve, secretRecoveryPhrase, path, cryptographicFunctions, }: GetNodeArgs): Promise<SLIP10Node>;
97
106
  export {};
98
107
  //# sourceMappingURL=utils.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.cts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAIV,cAAc,EACf,2BAA2B;AAC5B,OAAO,EAAE,UAAU,EAAE,2BAA2B;AAChD,OAAO,KAAK,EAAE,UAAU,EAAE,8BAA8B;AACxD,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAa3C;;;;GAIG;AACH,MAAM,MAAM,iBAAiB,CAAC,SAAS,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI;KACxE,GAAG,IAAI,MAAM,SAAS,GAAG,IAAI;CAC/B,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,wBAAgB,W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AAC,EAC5B,KAAK,EACL,oBAAoB,EACpB,IAAI,EACJ,sBAAsB,GACvB,EAAE,WAAW,uBAeb"}
package/dist/utils.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import type { SupportedCurve } from "@metamask/key-tree";
1
+ import type { SupportedCurve, CryptographicFunctions } from "@metamask/key-tree";
2
2
  import { SLIP10Node } from "@metamask/key-tree";
3
3
  import type { MagicValue } from "@metamask/snaps-utils";
4
4
  import type { Hex } from "@metamask/utils";
@@ -41,6 +41,10 @@ type DeriveEntropyOptions = {
41
41
  * mnemonic phrase.
42
42
  */
43
43
  magic: MagicValue;
44
+ /**
45
+ * The cryptographic functions to use for the derivation.
46
+ */
47
+ cryptographicFunctions: CryptographicFunctions | undefined;
44
48
  };
45
49
  /**
46
50
  * Derive entropy from the given mnemonic phrase and salt.
@@ -55,9 +59,11 @@ type DeriveEntropyOptions = {
55
59
  * derivation.
56
60
  * @param options.magic - A hardened BIP-32 index, which is used to derive the
57
61
  * root key from the mnemonic phrase.
62
+ * @param options.cryptographicFunctions - The cryptographic functions to use
63
+ * for the derivation.
58
64
  * @returns The derived entropy.
59
65
  */
60
- export declare function deriveEntropy({ input, salt, mnemonicPhrase, magic, }: DeriveEntropyOptions): Promise<Hex>;
66
+ export declare function deriveEntropy({ input, salt, mnemonicPhrase, magic, cryptographicFunctions, }: DeriveEntropyOptions): Promise<Hex>;
61
67
  /**
62
68
  * Get the path prefix to use for key derivation in `key-tree`. This assumes the
63
69
  * following:
@@ -78,6 +84,7 @@ type GetNodeArgs = {
78
84
  curve: SupportedCurve;
79
85
  secretRecoveryPhrase: Uint8Array;
80
86
  path: string[];
87
+ cryptographicFunctions: CryptographicFunctions | undefined;
81
88
  };
82
89
  /**
83
90
  * Get a `key-tree`-compatible node.
@@ -91,8 +98,10 @@ type GetNodeArgs = {
91
98
  * derivation.
92
99
  * @param options.path - The derivation path to use as array, starting with an
93
100
  * "m" as the first item.
101
+ * @param options.cryptographicFunctions - The cryptographic functions to use
102
+ * for the node.
94
103
  * @returns The `key-tree` SLIP-10 node.
95
104
  */
96
- export declare function getNode({ curve, secretRecoveryPhrase, path, }: GetNodeArgs): Promise<SLIP10Node>;
105
+ export declare function getNode({ curve, secretRecoveryPhrase, path, cryptographicFunctions, }: GetNodeArgs): Promise<SLIP10Node>;
97
106
  export {};
98
107
  //# sourceMappingURL=utils.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.mts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAIV,cAAc,EACf,2BAA2B;AAC5B,OAAO,EAAE,UAAU,EAAE,2BAA2B;AAChD,OAAO,KAAK,EAAE,UAAU,EAAE,8BAA8B;AACxD,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAa3C;;;;GAIG;AACH,MAAM,MAAM,iBAAiB,CAAC,SAAS,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI;KACxE,GAAG,IAAI,MAAM,SAAS,GAAG,IAAI;CAC/B,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,wBAAgB,WAAW,CACzB,KAAK,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACrC,QAAQ,SAAS,MAAM,KAAK,EAE5B,KAAK,EAAE,KAAK,EACZ,SAAS,CAAC,EAAE,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,GACpC,IAAI,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,SAAS,CAYnC;AA2BD,KAAK,oBAAoB,GAAG;IAC1B;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,cAAc,EAAE,UAAU,CAAC;IAE3B;;;OAGG;IACH,KAAK,EAAE,UAAU,CAAC;CACnB,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,aAAa,CAAC,EAClC,KAAK,EACL,IAAS,EACT,cAAc,EACd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,CAAC;IAEd;;OAEG;IACH,cAAc,EAAE,UAAU,CAAC;IAE3B;;;OAGG;IACH,KAAK,EAAE,UAAU,CAAC;IAElB;;OAEG;IACH,sBAAsB,EAAE,sBAAsB,GAAG,SAAS,CAAC;CAC5D,CAAC;AAEF;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,aAAa,CAAC,EAClC,KAAK,EACL,IAAS,EACT,cAAc,EACd,KAAK,EACL,sBAAsB,GACvB,EAAE,oBAAoB,GAAG,OAAO,CAAC,GAAG,CAAC,CAyBrC;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,aAAa,CAC3B,KAAK,EAAE,cAAc,GACpB,OAAO,GAAG,QAAQ,GAAG,MAAM,CAW7B;AAED,KAAK,WAAW,GAAG;IACjB,KAAK,EAAE,cAAc,CAAC;IACtB,oBAAoB,EAAE,UAAU,CAAC;IACjC,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,sBAAsB,EAAE,sBAAsB,GAAG,SAAS,CAAC;CAC5D,CAAC;AAEF;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,OAAO,CAAC,EAC5B,KAAK,EACL,oBAAoB,EACpB,IAAI,EACJ,sBAAsB,GACvB,EAAE,WAAW,uBAeb"}
package/dist/utils.mjs CHANGED
@@ -58,9 +58,11 @@ function getDerivationPathArray(hash) {
58
58
  * derivation.
59
59
  * @param options.magic - A hardened BIP-32 index, which is used to derive the
60
60
  * root key from the mnemonic phrase.
61
+ * @param options.cryptographicFunctions - The cryptographic functions to use
62
+ * for the derivation.
61
63
  * @returns The derived entropy.
62
64
  */
63
- export async function deriveEntropy({ input, salt = '', mnemonicPhrase, magic, }) {
65
+ export async function deriveEntropy({ input, salt = '', mnemonicPhrase, magic, cryptographicFunctions, }) {
64
66
  const inputBytes = stringToBytes(input);
65
67
  const saltBytes = stringToBytes(salt);
66
68
  // Get the derivation path from the snap ID.
@@ -74,7 +76,7 @@ export async function deriveEntropy({ input, salt = '', mnemonicPhrase, magic, }
74
76
  ...computedDerivationPath,
75
77
  ],
76
78
  curve: 'secp256k1',
77
- });
79
+ }, cryptographicFunctions);
78
80
  // This should never happen, but this keeps TypeScript happy.
79
81
  assert(privateKey, 'Failed to derive the entropy.');
80
82
  return add0x(privateKey);
@@ -118,9 +120,11 @@ export function getPathPrefix(curve) {
118
120
  * derivation.
119
121
  * @param options.path - The derivation path to use as array, starting with an
120
122
  * "m" as the first item.
123
+ * @param options.cryptographicFunctions - The cryptographic functions to use
124
+ * for the node.
121
125
  * @returns The `key-tree` SLIP-10 node.
122
126
  */
123
- export async function getNode({ curve, secretRecoveryPhrase, path, }) {
127
+ export async function getNode({ curve, secretRecoveryPhrase, path, cryptographicFunctions, }) {
124
128
  const prefix = getPathPrefix(curve);
125
129
  return await SLIP10Node.fromDerivationPath({
126
130
  curve,
@@ -128,6 +132,6 @@ export async function getNode({ curve, secretRecoveryPhrase, path, }) {
128
132
  secretRecoveryPhrase,
129
133
  ...path.slice(1).map((index) => `${prefix}:${index}`),
130
134
  ],
131
- });
135
+ }, cryptographicFunctions);
132
136
  }
133
137
  //# sourceMappingURL=utils.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.mjs","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,UAAU,EAAE,2BAA2B;AAGhD,OAAO,EACL,gBAAgB,EAChB,KAAK,EACL,MAAM,EACN,WAAW,EACX,cAAc,EACd,aAAa,EACd,wBAAwB;AACzB,OAAO,EAAE,UAAU,IAAI,SAAS,EAAE,2BAA2B;AAE7D,MAAM,cAAc,GAAG,UAAU,CAAC;AAWlC;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,WAAW,CAIzB,KAAY,EACZ,SAAqC;IAErC,IAAI,SAAS,EAAE,CAAC;QACd,OAAO,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,MAAM,CAClC,CAAC,UAAU,EAAE,SAAS,EAAE,EAAE;YACxB,MAAM,QAAQ,GAAG,SAA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AAM,UAAU,CAAC,kBAAkB,CAAC;QACzD,cAAc,EAAE;YACd,cAAc;YACd,SAAS,KAAK,EAAE;YAChB,GAAG,sBAAsB;SAC1B;QACD,KAAK,EAAE,WAAW;KACnB,CAAC,CAAC;IAEH,6DAA6D;IAC7D,MAAM,CAAC,UAAU,EAAE,+BAA+B,CAAC,CAAC;IAEpD,OAAO,KAAK,CAAC,UAAU,CAAC,CAAC;AAC3B,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,aAAa,CAC3B,KAAqB;IAErB,QAAQ,KAAK,EAAE,CAAC;QACd,KAAK,WAAW;YACd,OAAO,OAAO,CAAC;QACjB,KAAK,SAAS;YACZ,OAAO,QAAQ,CAAC;QAClB,KAAK,cAAc;YACjB,OAAO,MAAM,CAAC;QAChB;YACE,OAAO,gBAAgB,CAAC,KAAK,CAAC,CAAC;IACnC,CAAC;AACH,CAAC;AAQD;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,KAAK,UAAU,OAAO,CAAC,EAC5B,KAAK,EACL,oBAAoB,EACpB,IAAI,GACQ;IACZ,MAAM,MAAM,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC;IAEpC,OAAO,MAAM,UAAU,CAAC,kBAAkB,CAAC;QACzC,KAAK;QACL,cAAc,EAAE;YACd,oBAAoB;YACpB,GAAI,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,GAAG,MAAM,IAAI,KAAK,EAAE,CAEhC;SACtB;KACF,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type {\n HardenedBIP32Node,\n BIP32Node,\n SLIP10PathNode,\n SupportedCurve,\n} from '@metamask/key-tree';\nimport { SLIP10Node } from '@metamask/key-tree';\nimport type { MagicValue } from '@metamask/snaps-utils';\nimport type { Hex } from '@metamask/utils';\nimport {\n assertExhaustive,\n add0x,\n assert,\n concatBytes,\n createDataView,\n stringToBytes,\n} from '@metamask/utils';\nimport { keccak_256 as keccak256 } from '@noble/hashes/sha3';\n\nconst HARDENED_VALUE = 0x80000000;\n\n/**\n * Maps an interface with method hooks to an object, using the keys of the\n * interface, and `true` as value. This ensures that the `methodHooks` object\n * has the same values as the interface.\n */\nexport type MethodHooksObject<HooksType extends Record<string, unknown>> = {\n [Key in keyof HooksType]: true;\n};\n\n/**\n * Returns the subset of the specified `hooks` that are included in the\n * `hookNames` object. This is a Principle of Least Authority (POLA) measure\n * to ensure that each RPC method implementation only has access to the\n * API \"hooks\" it needs to do its job.\n *\n * @param hooks - The hooks to select from.\n * @param hookNames - The names of the hooks to select.\n * @returns The selected hooks.\n * @template Hooks - The hooks to select from.\n * @template HookName - The names of the hooks to select.\n */\nexport function selectHooks<\n Hooks extends Record<string, unknown>,\n HookName extends keyof Hooks,\n>(\n hooks: Hooks,\n hookNames?: Record<HookName, boolean>,\n): Pick<Hooks, HookName> | undefined {\n if (hookNames) {\n return Object.keys(hookNames).reduce<Partial<Pick<Hooks, HookName>>>(\n (hookSubset, _hookName) => {\n const hookName = _hookName as HookName;\n hookSubset[hookName] = hooks[hookName];\n return hookSubset;\n },\n {},\n ) as Pick<Hooks, HookName>;\n }\n return undefined;\n}\n\n/**\n * Get a BIP-32 derivation path array from a hash, which is compatible with\n * `@metamask/key-tree`. The hash is assumed to be 32 bytes long.\n *\n * @param hash - The hash to derive indices from.\n * @returns The derived indices as a {@link HardenedBIP32Node} array.\n */\nfunction getDerivationPathArray(hash: Uint8Array): HardenedBIP32Node[] {\n const array: HardenedBIP32Node[] = [];\n const view = createDataView(hash);\n\n for (let index = 0; index < 8; index++) {\n const uint32 = view.getUint32(index * 4);\n\n // This is essentially `index | 0x80000000`. Because JavaScript numbers are\n // signed, we use the bitwise unsigned right shift operator to ensure that\n // the result is a positive number.\n // eslint-disable-next-line no-bitwise\n const pathIndex = (uint32 | HARDENED_VALUE) >>> 0;\n array.push(`bip32:${pathIndex - HARDENED_VALUE}'` as const);\n }\n\n return array;\n}\n\ntype DeriveEntropyOptions = {\n /**\n * The input value to derive entropy from.\n */\n input: string;\n\n /**\n * An optional salt to use when deriving entropy.\n */\n salt?: string;\n\n /**\n * The mnemonic phrase to use for entropy derivation.\n */\n mnemonicPhrase: Uint8Array;\n\n /**\n * A hardened BIP-32 index, which is used to derive the root key from the\n * mnemonic phrase.\n */\n magic: MagicValue;\n};\n\n/**\n * Derive entropy from the given mnemonic phrase and salt.\n *\n * This is based on the reference implementation of\n * [SIP-6](https://metamask.github.io/SIPs/SIPS/sip-6).\n *\n * @param options - The options for entropy derivation.\n * @param options.input - The input value to derive entropy from.\n * @param options.salt - An optional salt to use when deriving entropy.\n * @param options.mnemonicPhrase - The mnemonic phrase to use for entropy\n * derivation.\n * @param options.magic - A hardened BIP-32 index, which is used to derive the\n * root key from the mnemonic phrase.\n * @returns The derived entropy.\n */\nexport async function deriveEntropy({\n input,\n salt = '',\n mnemonicPhrase,\n magic,\n}: DeriveEntropyOptions): Promise<Hex> {\n const inputBytes = stringToBytes(input);\n const saltBytes = stringToBytes(salt);\n\n // Get the derivation path from the snap ID.\n const hash = keccak256(concatBytes([inputBytes, keccak256(saltBytes)]));\n const computedDerivationPath = getDerivationPathArray(hash);\n\n // Derive the private key using BIP-32.\n const { privateKey } = await SLIP10Node.fromDerivationPath({\n derivationPath: [\n mnemonicPhrase,\n `bip32:${magic}`,\n ...computedDerivationPath,\n ],\n curve: 'secp256k1',\n });\n\n // This should never happen, but this keeps TypeScript happy.\n assert(privateKey, 'Failed to derive the entropy.');\n\n return add0x(privateKey);\n}\n\n/**\n * Get the path prefix to use for key derivation in `key-tree`. This assumes the\n * following:\n *\n * - The Secp256k1 curve always uses the BIP-32 specification.\n * - The Ed25519 curve always uses the SLIP-10 specification.\n * - The BIP-32-Ed25519 curve always uses the CIP-3 specification.\n *\n * While this does not matter in most situations (no known case at the time of\n * writing), `key-tree` requires a specific specification to be used.\n *\n * @param curve - The curve to get the path prefix for. The curve is NOT\n * validated by this function.\n * @returns The path prefix, i.e., `bip32` or `slip10`.\n */\nexport function getPathPrefix(\n curve: SupportedCurve,\n): 'bip32' | 'slip10' | 'cip3' {\n switch (curve) {\n case 'secp256k1':\n return 'bip32';\n case 'ed25519':\n return 'slip10';\n case 'ed25519Bip32':\n return 'cip3';\n default:\n return assertExhaustive(curve);\n }\n}\n\ntype GetNodeArgs = {\n curve: SupportedCurve;\n secretRecoveryPhrase: Uint8Array;\n path: string[];\n};\n\n/**\n * Get a `key-tree`-compatible node.\n *\n * Note: This function assumes that all the parameters have been validated\n * beforehand.\n *\n * @param options - The derivation options.\n * @param options.curve - The curve to use for derivation.\n * @param options.secretRecoveryPhrase - The secret recovery phrase to use for\n * derivation.\n * @param options.path - The derivation path to use as array, starting with an\n * \"m\" as the first item.\n * @returns The `key-tree` SLIP-10 node.\n */\nexport async function getNode({\n curve,\n secretRecoveryPhrase,\n path,\n}: GetNodeArgs) {\n const prefix = getPathPrefix(curve);\n\n return await SLIP10Node.fromDerivationPath({\n curve,\n derivationPath: [\n secretRecoveryPhrase,\n ...(path.slice(1).map((index) => `${prefix}:${index}`) as\n | BIP32Node[]\n | SLIP10PathNode[]),\n ],\n });\n}\n"]}
1
+ {"version":3,"file":"utils.mjs","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,UAAU,EAAE,2BAA2B;AAGhD,OAAO,EACL,gBAAgB,EAChB,KAAK,EACL,MAAM,EACN,WAAW,EACX,cAAc,EACd,aAAa,EACd,wBAAwB;AACzB,OAAO,EAAE,UAAU,IAAI,SAAS,EAAE,2BAA2B;AAE7D,MAAM,cAAc,GAAG,UAAU,CAAC;AAWlC;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,WAAW,CAIzB,KAAY,EACZ,SAAqC;IAErC,IAAI,SAAS,EAAE,CAAC;QACd,OAAO,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,MAAM,CAClC,CAAC,UAAU,EAAE,SAAS,EAAE,EAAE;YACxB,MAAM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C,MAAM,EAAE,UAAU,EAAE,GAAG,MAAM,UAAU,CAAC,kBAAkB,CACxD;QACE,cAAc,EAAE;YACd,cAAc;YACd,SAAS,KAAK,EAAE;YAChB,GAAG,sBAAsB;SAC1B;QACD,KAAK,EAAE,WAAW;KACnB,EACD,sBAAsB,CACvB,CAAC;IAEF,6DAA6D;IAC7D,MAAM,CAAC,UAAU,EAAE,+BAA+B,CAAC,CAAC;IAEpD,OAAO,KAAK,CAAC,UAAU,CAAC,CAAC;AAC3B,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,aAAa,CAC3B,KAAqB;IAErB,QAAQ,KAAK,EAAE,CAAC;QACd,KAAK,WAAW;YACd,OAAO,OAAO,CAAC;QACjB,KAAK,SAAS;YACZ,OAAO,QAAQ,CAAC;QAClB,KAAK,cAAc;YACjB,OAAO,MAAM,CAAC;QAChB;YACE,OAAO,gBAAgB,CAAC,KAAK,CAAC,CAAC;IACnC,CAAC;AACH,CAAC;AASD;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,KAAK,UAAU,OAAO,CAAC,EAC5B,KAAK,EACL,oBAAoB,EACpB,IAAI,EACJ,sBAAsB,GACV;IACZ,MAAM,MAAM,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC;IAEpC,OAAO,MAAM,UAAU,CAAC,kBAAkB,CACxC;QACE,KAAK;QACL,cAAc,EAAE;YACd,oBAAoB;YACpB,GAAI,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,GAAG,MAAM,IAAI,KAAK,EAAE,CAEhC;SACtB;KACF,EACD,sBAAsB,CACvB,CAAC;AACJ,CAAC","sourcesContent":["import type {\n HardenedBIP32Node,\n BIP32Node,\n SLIP10PathNode,\n SupportedCurve,\n CryptographicFunctions,\n} from '@metamask/key-tree';\nimport { SLIP10Node } from '@metamask/key-tree';\nimport type { MagicValue } from '@metamask/snaps-utils';\nimport type { Hex } from '@metamask/utils';\nimport {\n assertExhaustive,\n add0x,\n assert,\n concatBytes,\n createDataView,\n stringToBytes,\n} from '@metamask/utils';\nimport { keccak_256 as keccak256 } from '@noble/hashes/sha3';\n\nconst HARDENED_VALUE = 0x80000000;\n\n/**\n * Maps an interface with method hooks to an object, using the keys of the\n * interface, and `true` as value. This ensures that the `methodHooks` object\n * has the same values as the interface.\n */\nexport type MethodHooksObject<HooksType extends Record<string, unknown>> = {\n [Key in keyof HooksType]: true;\n};\n\n/**\n * Returns the subset of the specified `hooks` that are included in the\n * `hookNames` object. This is a Principle of Least Authority (POLA) measure\n * to ensure that each RPC method implementation only has access to the\n * API \"hooks\" it needs to do its job.\n *\n * @param hooks - The hooks to select from.\n * @param hookNames - The names of the hooks to select.\n * @returns The selected hooks.\n * @template Hooks - The hooks to select from.\n * @template HookName - The names of the hooks to select.\n */\nexport function selectHooks<\n Hooks extends Record<string, unknown>,\n HookName extends keyof Hooks,\n>(\n hooks: Hooks,\n hookNames?: Record<HookName, boolean>,\n): Pick<Hooks, HookName> | undefined {\n if (hookNames) {\n return Object.keys(hookNames).reduce<Partial<Pick<Hooks, HookName>>>(\n (hookSubset, _hookName) => {\n const hookName = _hookName as HookName;\n hookSubset[hookName] = hooks[hookName];\n return hookSubset;\n },\n {},\n ) as Pick<Hooks, HookName>;\n }\n return undefined;\n}\n\n/**\n * Get a BIP-32 derivation path array from a hash, which is compatible with\n * `@metamask/key-tree`. The hash is assumed to be 32 bytes long.\n *\n * @param hash - The hash to derive indices from.\n * @returns The derived indices as a {@link HardenedBIP32Node} array.\n */\nfunction getDerivationPathArray(hash: Uint8Array): HardenedBIP32Node[] {\n const array: HardenedBIP32Node[] = [];\n const view = createDataView(hash);\n\n for (let index = 0; index < 8; index++) {\n const uint32 = view.getUint32(index * 4);\n\n // This is essentially `index | 0x80000000`. Because JavaScript numbers are\n // signed, we use the bitwise unsigned right shift operator to ensure that\n // the result is a positive number.\n // eslint-disable-next-line no-bitwise\n const pathIndex = (uint32 | HARDENED_VALUE) >>> 0;\n array.push(`bip32:${pathIndex - HARDENED_VALUE}'` as const);\n }\n\n return array;\n}\n\ntype DeriveEntropyOptions = {\n /**\n * The input value to derive entropy from.\n */\n input: string;\n\n /**\n * An optional salt to use when deriving entropy.\n */\n salt?: string;\n\n /**\n * The mnemonic phrase to use for entropy derivation.\n */\n mnemonicPhrase: Uint8Array;\n\n /**\n * A hardened BIP-32 index, which is used to derive the root key from the\n * mnemonic phrase.\n */\n magic: MagicValue;\n\n /**\n * The cryptographic functions to use for the derivation.\n */\n cryptographicFunctions: CryptographicFunctions | undefined;\n};\n\n/**\n * Derive entropy from the given mnemonic phrase and salt.\n *\n * This is based on the reference implementation of\n * [SIP-6](https://metamask.github.io/SIPs/SIPS/sip-6).\n *\n * @param options - The options for entropy derivation.\n * @param options.input - The input value to derive entropy from.\n * @param options.salt - An optional salt to use when deriving entropy.\n * @param options.mnemonicPhrase - The mnemonic phrase to use for entropy\n * derivation.\n * @param options.magic - A hardened BIP-32 index, which is used to derive the\n * root key from the mnemonic phrase.\n * @param options.cryptographicFunctions - The cryptographic functions to use\n * for the derivation.\n * @returns The derived entropy.\n */\nexport async function deriveEntropy({\n input,\n salt = '',\n mnemonicPhrase,\n magic,\n cryptographicFunctions,\n}: DeriveEntropyOptions): Promise<Hex> {\n const inputBytes = stringToBytes(input);\n const saltBytes = stringToBytes(salt);\n\n // Get the derivation path from the snap ID.\n const hash = keccak256(concatBytes([inputBytes, keccak256(saltBytes)]));\n const computedDerivationPath = getDerivationPathArray(hash);\n\n // Derive the private key using BIP-32.\n const { privateKey } = await SLIP10Node.fromDerivationPath(\n {\n derivationPath: [\n mnemonicPhrase,\n `bip32:${magic}`,\n ...computedDerivationPath,\n ],\n curve: 'secp256k1',\n },\n cryptographicFunctions,\n );\n\n // This should never happen, but this keeps TypeScript happy.\n assert(privateKey, 'Failed to derive the entropy.');\n\n return add0x(privateKey);\n}\n\n/**\n * Get the path prefix to use for key derivation in `key-tree`. This assumes the\n * following:\n *\n * - The Secp256k1 curve always uses the BIP-32 specification.\n * - The Ed25519 curve always uses the SLIP-10 specification.\n * - The BIP-32-Ed25519 curve always uses the CIP-3 specification.\n *\n * While this does not matter in most situations (no known case at the time of\n * writing), `key-tree` requires a specific specification to be used.\n *\n * @param curve - The curve to get the path prefix for. The curve is NOT\n * validated by this function.\n * @returns The path prefix, i.e., `bip32` or `slip10`.\n */\nexport function getPathPrefix(\n curve: SupportedCurve,\n): 'bip32' | 'slip10' | 'cip3' {\n switch (curve) {\n case 'secp256k1':\n return 'bip32';\n case 'ed25519':\n return 'slip10';\n case 'ed25519Bip32':\n return 'cip3';\n default:\n return assertExhaustive(curve);\n }\n}\n\ntype GetNodeArgs = {\n curve: SupportedCurve;\n secretRecoveryPhrase: Uint8Array;\n path: string[];\n cryptographicFunctions: CryptographicFunctions | undefined;\n};\n\n/**\n * Get a `key-tree`-compatible node.\n *\n * Note: This function assumes that all the parameters have been validated\n * beforehand.\n *\n * @param options - The derivation options.\n * @param options.curve - The curve to use for derivation.\n * @param options.secretRecoveryPhrase - The secret recovery phrase to use for\n * derivation.\n * @param options.path - The derivation path to use as array, starting with an\n * \"m\" as the first item.\n * @param options.cryptographicFunctions - The cryptographic functions to use\n * for the node.\n * @returns The `key-tree` SLIP-10 node.\n */\nexport async function getNode({\n curve,\n secretRecoveryPhrase,\n path,\n cryptographicFunctions,\n}: GetNodeArgs) {\n const prefix = getPathPrefix(curve);\n\n return await SLIP10Node.fromDerivationPath(\n {\n curve,\n derivationPath: [\n secretRecoveryPhrase,\n ...(path.slice(1).map((index) => `${prefix}:${index}`) as\n | BIP32Node[]\n | SLIP10PathNode[]),\n ],\n },\n cryptographicFunctions,\n );\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask/snaps-rpc-methods",
3
- "version": "11.5.1",
3
+ "version": "11.7.0",
4
4
  "description": "MetaMask Snaps JSON-RPC method implementations",
5
5
  "keywords": [
6
6
  "MetaMask",
@@ -55,11 +55,11 @@
55
55
  "test:watch": "jest --watch"
56
56
  },
57
57
  "dependencies": {
58
- "@metamask/key-tree": "^9.1.2",
58
+ "@metamask/key-tree": "^10.0.1",
59
59
  "@metamask/permission-controller": "^11.0.3",
60
60
  "@metamask/rpc-errors": "^7.0.1",
61
- "@metamask/snaps-sdk": "^6.10.0",
62
- "@metamask/snaps-utils": "^8.5.0",
61
+ "@metamask/snaps-sdk": "^6.13.0",
62
+ "@metamask/snaps-utils": "^8.6.1",
63
63
  "@metamask/superstruct": "^3.1.0",
64
64
  "@metamask/utils": "^10.0.0",
65
65
  "@noble/hashes": "^1.3.1"
@@ -74,7 +74,7 @@
74
74
  "@metamask/json-rpc-engine": "^10.0.1",
75
75
  "@swc/core": "1.3.78",
76
76
  "@swc/jest": "^0.2.26",
77
- "@ts-bridge/cli": "^0.5.1",
77
+ "@ts-bridge/cli": "^0.6.1",
78
78
  "@types/node": "18.14.2",
79
79
  "@typescript-eslint/eslint-plugin": "^5.42.1",
80
80
  "@typescript-eslint/parser": "^6.21.0",