@metamask/snaps-rpc-methods 11.13.0 → 12.0.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 (58) hide show
  1. package/CHANGELOG.md +17 -1
  2. package/dist/permitted/listEntropySources.cjs +5 -2
  3. package/dist/permitted/listEntropySources.cjs.map +1 -1
  4. package/dist/permitted/listEntropySources.d.cts +6 -0
  5. package/dist/permitted/listEntropySources.d.cts.map +1 -1
  6. package/dist/permitted/listEntropySources.d.mts +6 -0
  7. package/dist/permitted/listEntropySources.d.mts.map +1 -1
  8. package/dist/permitted/listEntropySources.mjs +5 -2
  9. package/dist/permitted/listEntropySources.mjs.map +1 -1
  10. package/dist/restricted/getBip32Entropy.cjs +16 -3
  11. package/dist/restricted/getBip32Entropy.cjs.map +1 -1
  12. package/dist/restricted/getBip32Entropy.d.cts +11 -1
  13. package/dist/restricted/getBip32Entropy.d.cts.map +1 -1
  14. package/dist/restricted/getBip32Entropy.d.mts +11 -1
  15. package/dist/restricted/getBip32Entropy.d.mts.map +1 -1
  16. package/dist/restricted/getBip32Entropy.mjs +17 -4
  17. package/dist/restricted/getBip32Entropy.mjs.map +1 -1
  18. package/dist/restricted/getBip32PublicKey.cjs +19 -3
  19. package/dist/restricted/getBip32PublicKey.cjs.map +1 -1
  20. package/dist/restricted/getBip32PublicKey.d.cts +11 -1
  21. package/dist/restricted/getBip32PublicKey.d.cts.map +1 -1
  22. package/dist/restricted/getBip32PublicKey.d.mts +11 -1
  23. package/dist/restricted/getBip32PublicKey.d.mts.map +1 -1
  24. package/dist/restricted/getBip32PublicKey.mjs +20 -4
  25. package/dist/restricted/getBip32PublicKey.mjs.map +1 -1
  26. package/dist/restricted/getBip44Entropy.cjs +8 -5
  27. package/dist/restricted/getBip44Entropy.cjs.map +1 -1
  28. package/dist/restricted/getBip44Entropy.d.cts +6 -6
  29. package/dist/restricted/getBip44Entropy.d.cts.map +1 -1
  30. package/dist/restricted/getBip44Entropy.d.mts +6 -6
  31. package/dist/restricted/getBip44Entropy.d.mts.map +1 -1
  32. package/dist/restricted/getBip44Entropy.mjs +9 -6
  33. package/dist/restricted/getBip44Entropy.mjs.map +1 -1
  34. package/dist/restricted/getEntropy.cjs +7 -7
  35. package/dist/restricted/getEntropy.cjs.map +1 -1
  36. package/dist/restricted/getEntropy.d.cts +7 -7
  37. package/dist/restricted/getEntropy.d.cts.map +1 -1
  38. package/dist/restricted/getEntropy.d.mts +7 -7
  39. package/dist/restricted/getEntropy.d.mts.map +1 -1
  40. package/dist/restricted/getEntropy.mjs +8 -8
  41. package/dist/restricted/getEntropy.mjs.map +1 -1
  42. package/dist/restricted/manageState.cjs +4 -4
  43. package/dist/restricted/manageState.cjs.map +1 -1
  44. package/dist/restricted/manageState.d.cts +3 -3
  45. package/dist/restricted/manageState.d.cts.map +1 -1
  46. package/dist/restricted/manageState.d.mts +3 -3
  47. package/dist/restricted/manageState.d.mts.map +1 -1
  48. package/dist/restricted/manageState.mjs +5 -5
  49. package/dist/restricted/manageState.mjs.map +1 -1
  50. package/dist/utils.cjs +68 -23
  51. package/dist/utils.cjs.map +1 -1
  52. package/dist/utils.d.cts +40 -16
  53. package/dist/utils.d.cts.map +1 -1
  54. package/dist/utils.d.mts +40 -16
  55. package/dist/utils.d.mts.map +1 -1
  56. package/dist/utils.mjs +63 -19
  57. package/dist/utils.mjs.map +1 -1
  58. package/package.json +3 -3
@@ -1 +1 @@
1
- {"version":3,"file":"getBip32PublicKey.d.mts","sourceRoot":"","sources":["../../src/restricted/getBip32PublicKey.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,2BAA2B;AACjE,OAAO,KAAK,EACV,8BAA8B,EAC9B,6BAA6B,EAC7B,uBAAuB,EAExB,wCAAwC;AACzC,OAAO,EAAE,cAAc,EAAe,wCAAwC;AAE9E,OAAO,KAAK,EACV,uBAAuB,EACvB,uBAAuB,EACxB,4BAA4B;AAQ7B,OAAO,KAAK,EAA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A4B;AAQ7B,OAAO,KAAK,EAAE,aAAa,EAAE,wBAAwB;AAGrD,OAAO,KAAK,EAAE,iBAAiB,EAAE,qBAAiB;AAOlD,QAAA,MAAM,UAAU,2BAA2B,CAAC;AAE5C,MAAM,MAAM,4BAA4B,GAAG;IACzC;;;;;;;OAOG;IACH,WAAW,EAAE,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,KAAK,OAAO,CAAC,UAAU,CAAC,CAAC;IAElE;;;;;;;OAOG;IACH,eAAe,EAAE,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,KAAK,OAAO,CAAC,UAAU,CAAC,CAAC;IAEtE;;;;OAIG;IACH,gBAAgB,EAAE,CAAC,uBAAuB,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAEtE;;;;;;OAMG;IACH,qBAAqB,EAAE,MAAM,sBAAsB,GAAG,SAAS,CAAC;CACjE,CAAC;AAEF,KAAK,4CAA4C,GAAG;IAClD,WAAW,EAAE,4BAA4B,CAAC;CAC3C,CAAC;AAUF,eAAO,MAAM,wBAAwB;;;;;;;;;;EAOpC,CAAC;AA0CF,eAAO,MAAM,wBAAwB;;;wBAxDnB,eAAe,gBAAgB;oBACnC,iBAAiB;8BACP,WAAW,sCAAsC,CAAC;wBACxD,SAAS,cAAc,MAAM,CAAC,CAAC,GAAG,IAAI;mBAC3C,6BAA6B;;;EAwD/B,CAAC;AAEZ;;;;;;;;;;;;GAYG;AACH,wBAAgB,+BAA+B,CAAC,EAC9C,WAAW,EACX,eAAe,EACf,gBAAgB,EAChB,qBAAqB,GACtB,EAAE,4BAA4B,UAErB,wBAAwB,uBAAuB,CAAC,KACrD,QAAQ,uBAAuB,CAAC,CAmDpC"}
@@ -3,7 +3,7 @@ import { rpcErrors } from "@metamask/rpc-errors";
3
3
  import { bip32entropy, Bip32PathStruct, CurveStruct, SnapCaveatType } from "@metamask/snaps-utils";
4
4
  import { boolean, object, optional, string } from "@metamask/superstruct";
5
5
  import { assertStruct } from "@metamask/utils";
6
- import { getSecretRecoveryPhrase, getNode } from "../utils.mjs";
6
+ import { getValueFromEntropySource, getNodeFromMnemonic, getNodeFromSeed } from "../utils.mjs";
7
7
  const targetName = 'snap_getBip32PublicKey';
8
8
  export const Bip32PublicKeyArgsStruct = bip32entropy(object({
9
9
  path: Bip32PathStruct,
@@ -39,6 +39,7 @@ const specificationBuilder = ({ methodHooks }) => {
39
39
  };
40
40
  const methodHooks = {
41
41
  getMnemonic: true,
42
+ getMnemonicSeed: true,
42
43
  getUnlockPromise: true,
43
44
  getClientCryptography: true,
44
45
  };
@@ -52,6 +53,7 @@ export const getBip32PublicKeyBuilder = Object.freeze({
52
53
  *
53
54
  * @param hooks - The RPC method hooks.
54
55
  * @param hooks.getMnemonic - A function to retrieve the Secret Recovery Phrase of the user.
56
+ * @param hooks.getMnemonicSeed - A function to retrieve the BIP-39 seed of the user.
55
57
  * @param hooks.getUnlockPromise - A function that resolves once the MetaMask extension is unlocked
56
58
  * and prompts the user to unlock their MetaMask if it is locked.
57
59
  * @param hooks.getClientCryptography - A function to retrieve the cryptographic
@@ -59,13 +61,27 @@ export const getBip32PublicKeyBuilder = Object.freeze({
59
61
  * @returns The method implementation which returns a public key.
60
62
  * @throws If the params are invalid.
61
63
  */
62
- export function getBip32PublicKeyImplementation({ getMnemonic, getUnlockPromise, getClientCryptography, }) {
64
+ export function getBip32PublicKeyImplementation({ getMnemonic, getMnemonicSeed, getUnlockPromise, getClientCryptography, }) {
63
65
  return async function getBip32PublicKey(args) {
64
66
  await getUnlockPromise(true);
65
67
  assertStruct(args.params, Bip32PublicKeyArgsStruct, 'Invalid BIP-32 public key params', rpcErrors.invalidParams);
66
68
  const { params } = args;
67
- const secretRecoveryPhrase = await getSecretRecoveryPhrase(getMnemonic, params.source);
68
- const node = await getNode({
69
+ // Using the seed is much faster, but we can only do it for these specific curves.
70
+ if (params.curve === 'secp256k1' || params.curve === 'ed25519') {
71
+ const seed = await getValueFromEntropySource(getMnemonicSeed, params.source);
72
+ const node = await getNodeFromSeed({
73
+ curve: params.curve,
74
+ path: params.path,
75
+ seed,
76
+ cryptographicFunctions: getClientCryptography(),
77
+ });
78
+ if (params.compressed) {
79
+ return node.compressedPublicKey;
80
+ }
81
+ return node.publicKey;
82
+ }
83
+ const secretRecoveryPhrase = await getValueFromEntropySource(getMnemonic, params.source);
84
+ const node = await getNodeFromMnemonic({
69
85
  curve: params.curve,
70
86
  path: params.path,
71
87
  secretRecoveryPhrase,
@@ -1 +1 @@
1
- {"version":3,"file":"getBip32PublicKey.mjs","sourceRoot":"","sources":["../../src/restricted/getBip32PublicKey.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,wCAAwC;AAC9E,OAAO,EAAE,SAAS,EAAE,6BAA6B;AAKjD,OAAO,EACL,YAAY,EACZ,eAAe,EACf,WAAW,EACX,cAAc,EACf,8BAA8B;AAC/B,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,8BAA8B;AAE1E,OAAO,EAAE,YAAY,EAAE,wBAAwB;AAG/C,OAAO,EAAE,uBAAuB,EAAE,OAAO,EAAE,qBAAiB;AAE5D,MAAM,UAAU,GAAG,wBAAwB,CAAC;AA0C5C,MAAM,CAAC,MAAM,wBAAwB,GAAG,YAAY,CAClD,MAAM,CAAC;IACL,IAAI,EAAE,eAAe;IACrB,KAAK,EAAE,WAAW;IAClB,UAAU,EAAE,QAAQ,CAAC,OAAO,EAAE,CAAC;IAC/B,MAAM,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAC;CAC3B,CAAC,CACH,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,oBAAoB,GAItB,CAAC,EAAE,WAAW,EAAgD,EAAE,EAAE;IACpE,OAAO;QACL,cAAc,EAAE,cAAc,CAAC,gBAAgB;QAC/C,UAAU;QACV,cAAc,EAAE,CAAC,cAAc,CAAC,wBAAwB,CAAC;QACzD,oBAAoB,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qBAAqB,EAAE;SAChD,CAAC,CAAC;QAEH,IAAI,MAAM,CAAC,UAAU,EAAE,CAAC;YACtB,OAAO,IAAI,CAAC,mBAAmB,CAAC;QAClC,CAAC;QAED,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import type { CryptographicFunctions } from '@metamask/key-tree';\nimport type {\n PermissionSpecificationBuilder,\n PermissionValidatorConstraint,\n RestrictedMethodOptions,\n ValidPermissionSpecification,\n} from '@metamask/permission-controller';\nimport { PermissionType, SubjectType } from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type {\n GetBip32PublicKeyParams,\n GetBip32PublicKeyResult,\n} from '@metamask/snaps-sdk';\nimport {\n bip32entropy,\n Bip32PathStruct,\n CurveStruct,\n SnapCaveatType,\n} from '@metamask/snaps-utils';\nimport { boolean, object, optional, string } from '@metamask/superstruct';\nimport type { NonEmptyArray } from '@metamask/utils';\nimport { assertStruct } from '@metamask/utils';\n\nimport type { MethodHooksObject } from '../utils';\nimport { getSecretRecoveryPhrase, getNode } from '../utils';\n\nconst targetName = 'snap_getBip32PublicKey';\n\nexport type GetBip32PublicKeyMethodHooks = {\n /**\n * Get the mnemonic of the provided source. If no source is provided, the\n * mnemonic of the primary keyring will be returned.\n *\n * @param source - The optional ID of the source to get the mnemonic of.\n * @returns The mnemonic of the provided source, or the default source if no\n * source is provided.\n */\n getMnemonic: (source?: string | undefined) => Promise<Uint8Array>;\n\n /**\n * Waits for the extension to be unlocked.\n *\n * @returns A promise that resolves once the extension is unlocked.\n */\n getUnlockPromise: (shouldShowUnlockRequest: boolean) => Promise<void>;\n\n /**\n * Get the cryptographic functions to use for the client. This may return an\n * empty object or `undefined` to fall back to the default cryptographic\n * functions.\n *\n * @returns The cryptographic functions to use for the client.\n */\n getClientCryptography: () => CryptographicFunctions | undefined;\n};\n\ntype GetBip32PublicKeySpecificationBuilderOptions = {\n methodHooks: GetBip32PublicKeyMethodHooks;\n};\n\ntype GetBip32PublicKeySpecification = ValidPermissionSpecification<{\n permissionType: PermissionType.RestrictedMethod;\n targetName: typeof targetName;\n methodImplementation: ReturnType<typeof getBip32PublicKeyImplementation>;\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n validator: PermissionValidatorConstraint;\n}>;\n\nexport const Bip32PublicKeyArgsStruct = bip32entropy(\n object({\n path: Bip32PathStruct,\n curve: CurveStruct,\n compressed: optional(boolean()),\n source: optional(string()),\n }),\n);\n\n/**\n * The specification builder for the `snap_getBip32PublicKey` permission.\n * `snap_getBip32PublicKey` lets the Snap retrieve public keys for a particular\n * BIP-32 node.\n *\n * @param options - The specification builder options.\n * @param options.methodHooks - The RPC method hooks needed by the method implementation.\n * @returns The specification for the `snap_getBip32PublicKey` permission.\n */\nconst specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.RestrictedMethod,\n GetBip32PublicKeySpecificationBuilderOptions,\n GetBip32PublicKeySpecification\n> = ({ methodHooks }: GetBip32PublicKeySpecificationBuilderOptions) => {\n return {\n permissionType: PermissionType.RestrictedMethod,\n targetName,\n allowedCaveats: [SnapCaveatType.PermittedDerivationPaths],\n methodImplementation: getBip32PublicKeyImplementation(methodHooks),\n validator: ({ caveats }) => {\n if (\n caveats?.length !== 1 ||\n caveats[0].type !== SnapCaveatType.PermittedDerivationPaths\n ) {\n throw rpcErrors.invalidParams({\n message: `Expected a single \"${SnapCaveatType.PermittedDerivationPaths}\" caveat.`,\n });\n }\n },\n subjectTypes: [SubjectType.Snap],\n };\n};\n\nconst methodHooks: MethodHooksObject<GetBip32PublicKeyMethodHooks> = {\n getMnemonic: true,\n getUnlockPromise: true,\n getClientCryptography: true,\n};\n\nexport const getBip32PublicKeyBuilder = Object.freeze({\n targetName,\n specificationBuilder,\n methodHooks,\n} as const);\n\n/**\n * Builds the method implementation for `snap_getBip32PublicKey`.\n *\n * @param hooks - The RPC method hooks.\n * @param hooks.getMnemonic - A function to retrieve the Secret Recovery Phrase of the user.\n * @param hooks.getUnlockPromise - A function that resolves once the MetaMask extension is unlocked\n * and prompts the user to unlock their MetaMask if it is locked.\n * @param hooks.getClientCryptography - A function to retrieve the cryptographic\n * functions to use for the client.\n * @returns The method implementation which returns a public key.\n * @throws If the params are invalid.\n */\nexport function getBip32PublicKeyImplementation({\n getMnemonic,\n getUnlockPromise,\n getClientCryptography,\n}: GetBip32PublicKeyMethodHooks) {\n return async function getBip32PublicKey(\n args: RestrictedMethodOptions<GetBip32PublicKeyParams>,\n ): Promise<GetBip32PublicKeyResult> {\n await getUnlockPromise(true);\n\n assertStruct(\n args.params,\n Bip32PublicKeyArgsStruct,\n 'Invalid BIP-32 public key params',\n rpcErrors.invalidParams,\n );\n\n const { params } = args;\n const secretRecoveryPhrase = await getSecretRecoveryPhrase(\n getMnemonic,\n params.source,\n );\n\n const node = await getNode({\n curve: params.curve,\n path: params.path,\n secretRecoveryPhrase,\n cryptographicFunctions: getClientCryptography(),\n });\n\n if (params.compressed) {\n return node.compressedPublicKey;\n }\n\n return node.publicKey;\n };\n}\n"]}
1
+ {"version":3,"file":"getBip32PublicKey.mjs","sourceRoot":"","sources":["../../src/restricted/getBip32PublicKey.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,wCAAwC;AAC9E,OAAO,EAAE,SAAS,EAAE,6BAA6B;AAKjD,OAAO,EACL,YAAY,EACZ,eAAe,EACf,WAAW,EACX,cAAc,EACf,8BAA8B;AAC/B,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,8BAA8B;AAE1E,OAAO,EAAE,YAAY,EAAE,wBAAwB;AAG/C,OAAO,EACL,yBAAyB,EACzB,mBAAmB,EACnB,eAAe,EAChB,qBAAiB;AAElB,MAAM,UAAU,GAAG,wBAAwB,CAAC;AAoD5C,MAAM,CAAC,MAAM,wBAAwB,GAAG,YAAY,CAClD,MAAM,CAAC;IACL,IAAI,EAAE,eAAe;IACrB,KAAK,EA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B,YAAY,CACV,IAAI,CAAC,MAAM,EACX,wBAAwB,EACxB,kCAAkC,EAClC,SAAS,CAAC,aAAa,CACxB,CAAC;QAEF,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;QAExB,kFAAkF;QAClF,IAAI,MAAM,CAAC,KAAK,KAAK,WAAW,IAAI,MAAM,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;YAC/D,MAAM,IAAI,GAAG,MAAM,yBAAyB,CAC1C,eAAe,EACf,MAAM,CAAC,MAAM,CACd,CAAC;YAEF,MAAM,IAAI,GAAG,MAAM,eAAe,CAAC;gBACjC,KAAK,EAAE,MAAM,CAAC,KAAK;gBACnB,IAAI,EAAE,MAAM,CAAC,IAAI;gBACjB,IAAI;gBACJ,sBAAsB,EAAE,qBAAqB,EAAE;aAChD,CAAC,CAAC;YAEH,IAAI,MAAM,CAAC,UAAU,EAAE,CAAC;gBACtB,OAAO,IAAI,CAAC,mBAAmB,CAAC;YAClC,CAAC;YAED,OAAO,IAAI,CAAC,SAAS,CAAC;QACxB,CAAC;QAED,MAAM,oBAAoB,GAAG,MAAM,yBAAyB,CAC1D,WAAW,EACX,MAAM,CAAC,MAAM,CACd,CAAC;QAEF,MAAM,IAAI,GAAG,MAAM,mBAAmB,CAAC;YACrC,KAAK,EAAE,MAAM,CAAC,KAAK;YACnB,IAAI,EAAE,MAAM,CAAC,IAAI;YACjB,oBAAoB;YACpB,sBAAsB,EAAE,qBAAqB,EAAE;SAChD,CAAC,CAAC;QAEH,IAAI,MAAM,CAAC,UAAU,EAAE,CAAC;YACtB,OAAO,IAAI,CAAC,mBAAmB,CAAC;QAClC,CAAC;QAED,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import type { CryptographicFunctions } from '@metamask/key-tree';\nimport type {\n PermissionSpecificationBuilder,\n PermissionValidatorConstraint,\n RestrictedMethodOptions,\n ValidPermissionSpecification,\n} from '@metamask/permission-controller';\nimport { PermissionType, SubjectType } from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type {\n GetBip32PublicKeyParams,\n GetBip32PublicKeyResult,\n} from '@metamask/snaps-sdk';\nimport {\n bip32entropy,\n Bip32PathStruct,\n CurveStruct,\n SnapCaveatType,\n} from '@metamask/snaps-utils';\nimport { boolean, object, optional, string } from '@metamask/superstruct';\nimport type { NonEmptyArray } from '@metamask/utils';\nimport { assertStruct } from '@metamask/utils';\n\nimport type { MethodHooksObject } from '../utils';\nimport {\n getValueFromEntropySource,\n getNodeFromMnemonic,\n getNodeFromSeed,\n} from '../utils';\n\nconst targetName = 'snap_getBip32PublicKey';\n\nexport type GetBip32PublicKeyMethodHooks = {\n /**\n * Get the mnemonic of the provided source. If no source is provided, the\n * mnemonic of the primary keyring will be returned.\n *\n * @param source - The optional ID of the source to get the mnemonic of.\n * @returns The mnemonic of the provided source, or the default source if no\n * source is provided.\n */\n getMnemonic: (source?: string | undefined) => Promise<Uint8Array>;\n\n /**\n * Get the mnemonic seed of the provided source. If no source is provided, the\n * mnemonic seed of the primary keyring will be returned.\n *\n * @param source - The optional ID of the source to get the mnemonic of.\n * @returns The mnemonic seed of the provided source, or the default source if no\n * source is provided.\n */\n getMnemonicSeed: (source?: string | undefined) => Promise<Uint8Array>;\n\n /**\n * Waits for the extension to be unlocked.\n *\n * @returns A promise that resolves once the extension is unlocked.\n */\n getUnlockPromise: (shouldShowUnlockRequest: boolean) => Promise<void>;\n\n /**\n * Get the cryptographic functions to use for the client. This may return an\n * empty object or `undefined` to fall back to the default cryptographic\n * functions.\n *\n * @returns The cryptographic functions to use for the client.\n */\n getClientCryptography: () => CryptographicFunctions | undefined;\n};\n\ntype GetBip32PublicKeySpecificationBuilderOptions = {\n methodHooks: GetBip32PublicKeyMethodHooks;\n};\n\ntype GetBip32PublicKeySpecification = ValidPermissionSpecification<{\n permissionType: PermissionType.RestrictedMethod;\n targetName: typeof targetName;\n methodImplementation: ReturnType<typeof getBip32PublicKeyImplementation>;\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n validator: PermissionValidatorConstraint;\n}>;\n\nexport const Bip32PublicKeyArgsStruct = bip32entropy(\n object({\n path: Bip32PathStruct,\n curve: CurveStruct,\n compressed: optional(boolean()),\n source: optional(string()),\n }),\n);\n\n/**\n * The specification builder for the `snap_getBip32PublicKey` permission.\n * `snap_getBip32PublicKey` lets the Snap retrieve public keys for a particular\n * BIP-32 node.\n *\n * @param options - The specification builder options.\n * @param options.methodHooks - The RPC method hooks needed by the method implementation.\n * @returns The specification for the `snap_getBip32PublicKey` permission.\n */\nconst specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.RestrictedMethod,\n GetBip32PublicKeySpecificationBuilderOptions,\n GetBip32PublicKeySpecification\n> = ({ methodHooks }: GetBip32PublicKeySpecificationBuilderOptions) => {\n return {\n permissionType: PermissionType.RestrictedMethod,\n targetName,\n allowedCaveats: [SnapCaveatType.PermittedDerivationPaths],\n methodImplementation: getBip32PublicKeyImplementation(methodHooks),\n validator: ({ caveats }) => {\n if (\n caveats?.length !== 1 ||\n caveats[0].type !== SnapCaveatType.PermittedDerivationPaths\n ) {\n throw rpcErrors.invalidParams({\n message: `Expected a single \"${SnapCaveatType.PermittedDerivationPaths}\" caveat.`,\n });\n }\n },\n subjectTypes: [SubjectType.Snap],\n };\n};\n\nconst methodHooks: MethodHooksObject<GetBip32PublicKeyMethodHooks> = {\n getMnemonic: true,\n getMnemonicSeed: true,\n getUnlockPromise: true,\n getClientCryptography: true,\n};\n\nexport const getBip32PublicKeyBuilder = Object.freeze({\n targetName,\n specificationBuilder,\n methodHooks,\n} as const);\n\n/**\n * Builds the method implementation for `snap_getBip32PublicKey`.\n *\n * @param hooks - The RPC method hooks.\n * @param hooks.getMnemonic - A function to retrieve the Secret Recovery Phrase of the user.\n * @param hooks.getMnemonicSeed - A function to retrieve the BIP-39 seed of the user.\n * @param hooks.getUnlockPromise - A function that resolves once the MetaMask extension is unlocked\n * and prompts the user to unlock their MetaMask if it is locked.\n * @param hooks.getClientCryptography - A function to retrieve the cryptographic\n * functions to use for the client.\n * @returns The method implementation which returns a public key.\n * @throws If the params are invalid.\n */\nexport function getBip32PublicKeyImplementation({\n getMnemonic,\n getMnemonicSeed,\n getUnlockPromise,\n getClientCryptography,\n}: GetBip32PublicKeyMethodHooks) {\n return async function getBip32PublicKey(\n args: RestrictedMethodOptions<GetBip32PublicKeyParams>,\n ): Promise<GetBip32PublicKeyResult> {\n await getUnlockPromise(true);\n\n assertStruct(\n args.params,\n Bip32PublicKeyArgsStruct,\n 'Invalid BIP-32 public key params',\n rpcErrors.invalidParams,\n );\n\n const { params } = args;\n\n // Using the seed is much faster, but we can only do it for these specific curves.\n if (params.curve === 'secp256k1' || params.curve === 'ed25519') {\n const seed = await getValueFromEntropySource(\n getMnemonicSeed,\n params.source,\n );\n\n const node = await getNodeFromSeed({\n curve: params.curve,\n path: params.path,\n seed,\n cryptographicFunctions: getClientCryptography(),\n });\n\n if (params.compressed) {\n return node.compressedPublicKey;\n }\n\n return node.publicKey;\n }\n\n const secretRecoveryPhrase = await getValueFromEntropySource(\n getMnemonic,\n params.source,\n );\n\n const node = await getNodeFromMnemonic({\n curve: params.curve,\n path: params.path,\n secretRecoveryPhrase,\n cryptographicFunctions: getClientCryptography(),\n });\n\n if (params.compressed) {\n return node.compressedPublicKey;\n }\n\n return node.publicKey;\n };\n}\n"]}
@@ -35,7 +35,7 @@ const specificationBuilder = ({ methodHooks }) => {
35
35
  };
36
36
  };
37
37
  const methodHooks = {
38
- getMnemonic: true,
38
+ getMnemonicSeed: true,
39
39
  getUnlockPromise: true,
40
40
  getClientCryptography: true,
41
41
  };
@@ -48,7 +48,7 @@ exports.getBip44EntropyBuilder = Object.freeze({
48
48
  * Builds the method implementation for `snap_getBip44Entropy`.
49
49
  *
50
50
  * @param hooks - The RPC method hooks.
51
- * @param hooks.getMnemonic - A function to retrieve the Secret Recovery Phrase
51
+ * @param hooks.getMnemonicSeed - A function to retrieve the BIP-39 seed
52
52
  * of the user.
53
53
  * @param hooks.getUnlockPromise - A function that resolves once the MetaMask
54
54
  * extension is unlocked and prompts the user to unlock their MetaMask if it is
@@ -58,13 +58,16 @@ exports.getBip44EntropyBuilder = Object.freeze({
58
58
  * @returns The method implementation which returns a `BIP44CoinTypeNode`.
59
59
  * @throws If the params are invalid.
60
60
  */
61
- function getBip44EntropyImplementation({ getMnemonic, getUnlockPromise, getClientCryptography, }) {
61
+ function getBip44EntropyImplementation({ getMnemonicSeed, getUnlockPromise, getClientCryptography, }) {
62
62
  return async function getBip44Entropy(args) {
63
63
  await getUnlockPromise(true);
64
64
  // `args.params` is validated by the decorator, so it's safe to assert here.
65
65
  const params = args.params;
66
- const secretRecoveryPhrase = await (0, utils_1.getSecretRecoveryPhrase)(getMnemonic, params.source);
67
- const node = await key_tree_1.BIP44CoinTypeNode.fromDerivationPath([secretRecoveryPhrase, `bip32:44'`, `bip32:${params.coinType}'`], 'mainnet', getClientCryptography());
66
+ const seed = await (0, utils_1.getValueFromEntropySource)(getMnemonicSeed, params.source);
67
+ const node = await key_tree_1.BIP44CoinTypeNode.fromSeed({
68
+ derivationPath: [seed, `bip32:44'`, `bip32:${params.coinType}'`],
69
+ network: 'mainnet',
70
+ }, getClientCryptography());
68
71
  return node.toJSON();
69
72
  };
70
73
  }
@@ -1 +1 @@
1
- {"version":3,"file":"getBip44Entropy.cjs","sourceRoot":"","sources":["../../src/restricted/getBip44Entropy.ts"],"names":[],"mappings":";;;AACA,iDAAuD;AAOvD,2EAA8E;AAC9E,qDAAiD;AAKjD,uDAAuD;AAIvD,wCAAmD;AAEnD,MAAM,UAAU,GAAG,sBAAsB,CAAC;AA0C1C;;;;;;;;;GASG;AACH,MAAM,oBAAoB,GAItB,CAAC,EAAE,WAAW,EAA8C,EAAE,EAAE;IAClE,OAAO;QACL,cAAc,EAAE,sCAAc,CAAC,gBAAgB;QAC/C,UAAU;QACV,cAAc,EAAE,CAAC,4BAAc,CAAC,kBAA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IACvB,CAAC,CAAC;AACJ,CAAC;AAzBD,sEAyBC","sourcesContent":["import type { CryptographicFunctions } from '@metamask/key-tree';\nimport { BIP44CoinTypeNode } from '@metamask/key-tree';\nimport type {\n PermissionSpecificationBuilder,\n PermissionValidatorConstraint,\n RestrictedMethodOptions,\n ValidPermissionSpecification,\n} from '@metamask/permission-controller';\nimport { PermissionType, SubjectType } from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type {\n GetBip44EntropyParams,\n GetBip44EntropyResult,\n} from '@metamask/snaps-sdk';\nimport { SnapCaveatType } from '@metamask/snaps-utils';\nimport type { NonEmptyArray } from '@metamask/utils';\n\nimport type { MethodHooksObject } from '../utils';\nimport { getSecretRecoveryPhrase } from '../utils';\n\nconst targetName = 'snap_getBip44Entropy';\n\nexport type GetBip44EntropyMethodHooks = {\n /**\n * Get the mnemonic of the provided source. If no source is provided, the\n * mnemonic of the primary keyring will be returned.\n *\n * @param source - The optional ID of the source to get the mnemonic of.\n * @returns The mnemonic of the provided source, or the default source if no\n * source is provided.\n */\n getMnemonic: (source?: string | undefined) => Promise<Uint8Array>;\n\n /**\n * Waits for the extension to be unlocked.\n *\n * @returns A promise that resolves once the extension is unlocked.\n */\n getUnlockPromise: (shouldShowUnlockRequest: boolean) => Promise<void>;\n\n /**\n * Get the cryptographic functions to use for the client. This may return an\n * empty object or `undefined` to fall back to the default cryptographic\n * functions.\n *\n * @returns The cryptographic functions to use for the client.\n */\n getClientCryptography: () => CryptographicFunctions | undefined;\n};\n\ntype GetBip44EntropySpecificationBuilderOptions = {\n methodHooks: GetBip44EntropyMethodHooks;\n};\n\ntype GetBip44EntropySpecification = ValidPermissionSpecification<{\n permissionType: PermissionType.RestrictedMethod;\n targetName: typeof targetName;\n methodImplementation: ReturnType<typeof getBip44EntropyImplementation>;\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n validator: PermissionValidatorConstraint;\n}>;\n\n/**\n * The specification builder for the `snap_getBip44Entropy` permission.\n * `snap_getBip44Entropy_*` lets the Snap control private keys for a particular\n * BIP-32 coin type.\n *\n * @param options - The specification builder options.\n * @param options.methodHooks - The RPC method hooks needed by the method\n * implementation.\n * @returns The specification for the `snap_getBip44Entropy` permission.\n */\nconst specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.RestrictedMethod,\n GetBip44EntropySpecificationBuilderOptions,\n GetBip44EntropySpecification\n> = ({ methodHooks }: GetBip44EntropySpecificationBuilderOptions) => {\n return {\n permissionType: PermissionType.RestrictedMethod,\n targetName,\n allowedCaveats: [SnapCaveatType.PermittedCoinTypes],\n methodImplementation: getBip44EntropyImplementation(methodHooks),\n validator: ({ caveats }) => {\n if (\n caveats?.length !== 1 ||\n caveats[0].type !== SnapCaveatType.PermittedCoinTypes\n ) {\n throw rpcErrors.invalidParams({\n message: `Expected a single \"${SnapCaveatType.PermittedCoinTypes}\" caveat.`,\n });\n }\n },\n subjectTypes: [SubjectType.Snap],\n };\n};\n\nconst methodHooks: MethodHooksObject<GetBip44EntropyMethodHooks> = {\n getMnemonic: true,\n getUnlockPromise: true,\n getClientCryptography: true,\n};\n\nexport const getBip44EntropyBuilder = Object.freeze({\n targetName,\n specificationBuilder,\n methodHooks,\n} as const);\n\n/**\n * Builds the method implementation for `snap_getBip44Entropy`.\n *\n * @param hooks - The RPC method hooks.\n * @param hooks.getMnemonic - A function to retrieve the Secret Recovery Phrase\n * of the user.\n * @param hooks.getUnlockPromise - A function that resolves once the MetaMask\n * extension is unlocked and prompts the user to unlock their MetaMask if it is\n * locked.\n * @param hooks.getClientCryptography - A function to retrieve the cryptographic\n * functions to use for the client.\n * @returns The method implementation which returns a `BIP44CoinTypeNode`.\n * @throws If the params are invalid.\n */\nexport function getBip44EntropyImplementation({\n getMnemonic,\n getUnlockPromise,\n getClientCryptography,\n}: GetBip44EntropyMethodHooks) {\n return async function getBip44Entropy(\n args: RestrictedMethodOptions<GetBip44EntropyParams>,\n ): Promise<GetBip44EntropyResult> {\n await getUnlockPromise(true);\n\n // `args.params` is validated by the decorator, so it's safe to assert here.\n const params = args.params as GetBip44EntropyParams;\n const secretRecoveryPhrase = await getSecretRecoveryPhrase(\n getMnemonic,\n params.source,\n );\n\n const node = await BIP44CoinTypeNode.fromDerivationPath(\n [secretRecoveryPhrase, `bip32:44'`, `bip32:${params.coinType}'`],\n 'mainnet',\n getClientCryptography(),\n );\n\n return node.toJSON();\n };\n}\n"]}
1
+ {"version":3,"file":"getBip44Entropy.cjs","sourceRoot":"","sources":["../../src/restricted/getBip44Entropy.ts"],"names":[],"mappings":";;;AACA,iDAAuD;AAOvD,2EAA8E;AAC9E,qDAAiD;AAKjD,uDAAuD;AAIvD,wCAAqD;AAErD,MAAM,UAAU,GAAG,sBAAsB,CAAC;AA0C1C;;;;;;;;;GASG;AACH,MAAM,oBAAoB,GAItB,CAAC,EAAE,WAAW,EAA8C,EAAE,EAAE;IAClE,OAAO;QACL,cAAc,EAAE,sCAAc,CAAC,gBAAgB;QAC/C,UAAU;QACV,cAAc,EAAE,CAAC,4BAAc,CAAC,kBAAkB,CAAC;QACnD,oBAAoB,EAAE,6BAA6B,CAAC,WAAW,CAAC;QAChE,SAAS,EAAE,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE;YACzB,IACE,OAAO,EAAE,MAAM,KAAK,CAAC;gBACrB,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,4BAAc,CAAC,kBAAkB,EACrD,CAAC;gBACD,MAAM,sBAAS,CAAC,aAAa,CAAC;oBAC5B,OAAO,EAAE,sBAAsB,4BAAc,CAAC,kBAAkB,WAAW;iBAC5E,CAAC,CAAC;YACL,CAAC;QACH,CAAC;QACD,YAAY,EAAE,CAAC,mCAAW,CAAC,IAAI,CAAC;KACjC,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,WAAW,GAAkD;IACjE,eAAe,EAAE,IAAI;IACrB,gBAAgB,EAAE,IAAI;IACtB,qBAAqB,EAAE,IAAI;CAC5B,CAAC;AAEW,QAAA,sBAAsB,GAAG,MAAM,CAAC,MAAM,CAAC;IAClD,UAAU;IACV,oBAAoB;IACpB,WAAW;CACH,CAAC,CAAC;AAEZ;;;;;;;;;;;;;GAaG;AACH,SAAgB,6BAA6B,CAAC,EAC5C,eAAe,EACf,gBAAgB,EAChB,qBAAqB,GACM;IAC3B,OAAO,KAAK,UAAU,eAAe,CACnC,IAAoD;QAEpD,MAAM,gBAAgB,CAAC,IAAI,CAAC,CAAC;QAE7B,4EAA4E;QAC5E,MAAM,MAAM,GAAG,IAAI,CAAC,MAA+B,CAAC;QACpD,MAAM,IAAI,GAAG,MAAM,IAAA,iCAAyB,EAC1C,eAAe,EACf,MAAM,CAAC,MAAM,CACd,CAAC;QAEF,MAAM,IAAI,GAAG,MAAM,4BAAiB,CAAC,QAAQ,CAC3C;YACE,cAAc,EAAE,CAAC,IAAI,EAAE,WAAW,EAAE,SAAS,MAAM,CAAC,QAAQ,GAAG,CAAC;YAChE,OAAO,EAAE,SAAS;SACnB,EACD,qBAAqB,EAAE,CACxB,CAAC;QAEF,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC;IACvB,CAAC,CAAC;AACJ,CAAC;AA3BD,sEA2BC","sourcesContent":["import type { CryptographicFunctions } from '@metamask/key-tree';\nimport { BIP44CoinTypeNode } from '@metamask/key-tree';\nimport type {\n PermissionSpecificationBuilder,\n PermissionValidatorConstraint,\n RestrictedMethodOptions,\n ValidPermissionSpecification,\n} from '@metamask/permission-controller';\nimport { PermissionType, SubjectType } from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type {\n GetBip44EntropyParams,\n GetBip44EntropyResult,\n} from '@metamask/snaps-sdk';\nimport { SnapCaveatType } from '@metamask/snaps-utils';\nimport type { NonEmptyArray } from '@metamask/utils';\n\nimport type { MethodHooksObject } from '../utils';\nimport { getValueFromEntropySource } from '../utils';\n\nconst targetName = 'snap_getBip44Entropy';\n\nexport type GetBip44EntropyMethodHooks = {\n /**\n * Get the mnemonic seed of the provided source. If no source is provided, the\n * mnemonic seed of the primary keyring will be returned.\n *\n * @param source - The optional ID of the source to get the mnemonic of.\n * @returns The mnemonic seed of the provided source, or the default source if no\n * source is provided.\n */\n getMnemonicSeed: (source?: string | undefined) => Promise<Uint8Array>;\n\n /**\n * Waits for the extension to be unlocked.\n *\n * @returns A promise that resolves once the extension is unlocked.\n */\n getUnlockPromise: (shouldShowUnlockRequest: boolean) => Promise<void>;\n\n /**\n * Get the cryptographic functions to use for the client. This may return an\n * empty object or `undefined` to fall back to the default cryptographic\n * functions.\n *\n * @returns The cryptographic functions to use for the client.\n */\n getClientCryptography: () => CryptographicFunctions | undefined;\n};\n\ntype GetBip44EntropySpecificationBuilderOptions = {\n methodHooks: GetBip44EntropyMethodHooks;\n};\n\ntype GetBip44EntropySpecification = ValidPermissionSpecification<{\n permissionType: PermissionType.RestrictedMethod;\n targetName: typeof targetName;\n methodImplementation: ReturnType<typeof getBip44EntropyImplementation>;\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n validator: PermissionValidatorConstraint;\n}>;\n\n/**\n * The specification builder for the `snap_getBip44Entropy` permission.\n * `snap_getBip44Entropy_*` lets the Snap control private keys for a particular\n * BIP-32 coin type.\n *\n * @param options - The specification builder options.\n * @param options.methodHooks - The RPC method hooks needed by the method\n * implementation.\n * @returns The specification for the `snap_getBip44Entropy` permission.\n */\nconst specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.RestrictedMethod,\n GetBip44EntropySpecificationBuilderOptions,\n GetBip44EntropySpecification\n> = ({ methodHooks }: GetBip44EntropySpecificationBuilderOptions) => {\n return {\n permissionType: PermissionType.RestrictedMethod,\n targetName,\n allowedCaveats: [SnapCaveatType.PermittedCoinTypes],\n methodImplementation: getBip44EntropyImplementation(methodHooks),\n validator: ({ caveats }) => {\n if (\n caveats?.length !== 1 ||\n caveats[0].type !== SnapCaveatType.PermittedCoinTypes\n ) {\n throw rpcErrors.invalidParams({\n message: `Expected a single \"${SnapCaveatType.PermittedCoinTypes}\" caveat.`,\n });\n }\n },\n subjectTypes: [SubjectType.Snap],\n };\n};\n\nconst methodHooks: MethodHooksObject<GetBip44EntropyMethodHooks> = {\n getMnemonicSeed: true,\n getUnlockPromise: true,\n getClientCryptography: true,\n};\n\nexport const getBip44EntropyBuilder = Object.freeze({\n targetName,\n specificationBuilder,\n methodHooks,\n} as const);\n\n/**\n * Builds the method implementation for `snap_getBip44Entropy`.\n *\n * @param hooks - The RPC method hooks.\n * @param hooks.getMnemonicSeed - A function to retrieve the BIP-39 seed\n * of the user.\n * @param hooks.getUnlockPromise - A function that resolves once the MetaMask\n * extension is unlocked and prompts the user to unlock their MetaMask if it is\n * locked.\n * @param hooks.getClientCryptography - A function to retrieve the cryptographic\n * functions to use for the client.\n * @returns The method implementation which returns a `BIP44CoinTypeNode`.\n * @throws If the params are invalid.\n */\nexport function getBip44EntropyImplementation({\n getMnemonicSeed,\n getUnlockPromise,\n getClientCryptography,\n}: GetBip44EntropyMethodHooks) {\n return async function getBip44Entropy(\n args: RestrictedMethodOptions<GetBip44EntropyParams>,\n ): Promise<GetBip44EntropyResult> {\n await getUnlockPromise(true);\n\n // `args.params` is validated by the decorator, so it's safe to assert here.\n const params = args.params as GetBip44EntropyParams;\n const seed = await getValueFromEntropySource(\n getMnemonicSeed,\n params.source,\n );\n\n const node = await BIP44CoinTypeNode.fromSeed(\n {\n derivationPath: [seed, `bip32:44'`, `bip32:${params.coinType}'`],\n network: 'mainnet',\n },\n getClientCryptography(),\n );\n\n return node.toJSON();\n };\n}\n"]}
@@ -7,14 +7,14 @@ import type { MethodHooksObject } from "../utils.cjs";
7
7
  declare const targetName = "snap_getBip44Entropy";
8
8
  export type GetBip44EntropyMethodHooks = {
9
9
  /**
10
- * Get the mnemonic of the provided source. If no source is provided, the
11
- * mnemonic of the primary keyring will be returned.
10
+ * Get the mnemonic seed of the provided source. If no source is provided, the
11
+ * mnemonic seed of the primary keyring will be returned.
12
12
  *
13
13
  * @param source - The optional ID of the source to get the mnemonic of.
14
- * @returns The mnemonic of the provided source, or the default source if no
14
+ * @returns The mnemonic seed of the provided source, or the default source if no
15
15
  * source is provided.
16
16
  */
17
- getMnemonic: (source?: string | undefined) => Promise<Uint8Array>;
17
+ getMnemonicSeed: (source?: string | undefined) => Promise<Uint8Array>;
18
18
  /**
19
19
  * Waits for the extension to be unlocked.
20
20
  *
@@ -48,7 +48,7 @@ export declare const getBip44EntropyBuilder: Readonly<{
48
48
  * Builds the method implementation for `snap_getBip44Entropy`.
49
49
  *
50
50
  * @param hooks - The RPC method hooks.
51
- * @param hooks.getMnemonic - A function to retrieve the Secret Recovery Phrase
51
+ * @param hooks.getMnemonicSeed - A function to retrieve the BIP-39 seed
52
52
  * of the user.
53
53
  * @param hooks.getUnlockPromise - A function that resolves once the MetaMask
54
54
  * extension is unlocked and prompts the user to unlock their MetaMask if it is
@@ -58,6 +58,6 @@ export declare const getBip44EntropyBuilder: Readonly<{
58
58
  * @returns The method implementation which returns a `BIP44CoinTypeNode`.
59
59
  * @throws If the params are invalid.
60
60
  */
61
- export declare function getBip44EntropyImplementation({ getMnemonic, getUnlockPromise, getClientCryptography, }: GetBip44EntropyMethodHooks): (args: RestrictedMethodOptions<GetBip44EntropyParams>) => Promise<GetBip44EntropyResult>;
61
+ export declare function getBip44EntropyImplementation({ getMnemonicSeed, getUnlockPromise, getClientCryptography, }: GetBip44EntropyMethodHooks): (args: RestrictedMethodOptions<GetBip44EntropyParams>) => Promise<GetBip44EntropyResult>;
62
62
  export {};
63
63
  //# sourceMappingURL=getBip44Entropy.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"getBip44Entropy.d.cts","sourceRoot":"","sources":["../../src/restricted/getBip44Entropy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,2BAA2B;AAEjE,OAAO,KAAK,EACV,8BAA8B,EAC9B,6BAA6B,EAC7B,uBAAuB,EAExB,wCAAwC;AACzC,OAAO,EAAE,cAAc,EAAe,wCAAwC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V,qBAAqB,EACrB,qBAAqB,EACtB,4BAA4B;AAE7B,OAAO,KAAK,EAAE,aAAa,EAAE,wBAAwB;AAErD,OAAO,KAAK,EAAE,iBAAiB,EAAE,qBAAiB;AAGlD,QAAA,MAAM,UAAU,yBAAyB,CAAC;AAE1C,MAAM,MAAM,0BAA0B,GAAG;IACvC;;;;;;;OAOG;IACH,eAAe,EAAE,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,KAAK,OAAO,CAAC,UAAU,CAAC,CAAC;IAEtE;;;;OAIG;IACH,gBAAgB,EAAE,CAAC,uBAAuB,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAEtE;;;;;;OAMG;IACH,qBAAqB,EAAE,MAAM,sBAAsB,GAAG,SAAS,CAAC;CACjE,CAAC;AAEF,KAAK,0CAA0C,GAAG;IAChD,WAAW,EAAE,0BAA0B,CAAC;CACzC,CAAC;AAkDF,eAAO,MAAM,sBAAsB;;;wBA/CjB,eAAe,gBAAgB;oBACnC,iBAAiB;8BACP,WAAW,oCAAoC,CAAC;wBACtD,SAAS,cAAc,MAAM,CAAC,CAAC,GAAG,IAAI;mBAC3C,6BAA6B;;;EA+C/B,CAAC;AAEZ;;;;;;;;;;;;;GAaG;AACH,wBAAgB,6BAA6B,CAAC,EAC5C,eAAe,EACf,gBAAgB,EAChB,qBAAqB,GACtB,EAAE,0BAA0B,UAEnB,wBAAwB,qBAAqB,CAAC,KACnD,QAAQ,qBAAqB,CAAC,CAoBlC"}
@@ -7,14 +7,14 @@ import type { MethodHooksObject } from "../utils.mjs";
7
7
  declare const targetName = "snap_getBip44Entropy";
8
8
  export type GetBip44EntropyMethodHooks = {
9
9
  /**
10
- * Get the mnemonic of the provided source. If no source is provided, the
11
- * mnemonic of the primary keyring will be returned.
10
+ * Get the mnemonic seed of the provided source. If no source is provided, the
11
+ * mnemonic seed of the primary keyring will be returned.
12
12
  *
13
13
  * @param source - The optional ID of the source to get the mnemonic of.
14
- * @returns The mnemonic of the provided source, or the default source if no
14
+ * @returns The mnemonic seed of the provided source, or the default source if no
15
15
  * source is provided.
16
16
  */
17
- getMnemonic: (source?: string | undefined) => Promise<Uint8Array>;
17
+ getMnemonicSeed: (source?: string | undefined) => Promise<Uint8Array>;
18
18
  /**
19
19
  * Waits for the extension to be unlocked.
20
20
  *
@@ -48,7 +48,7 @@ export declare const getBip44EntropyBuilder: Readonly<{
48
48
  * Builds the method implementation for `snap_getBip44Entropy`.
49
49
  *
50
50
  * @param hooks - The RPC method hooks.
51
- * @param hooks.getMnemonic - A function to retrieve the Secret Recovery Phrase
51
+ * @param hooks.getMnemonicSeed - A function to retrieve the BIP-39 seed
52
52
  * of the user.
53
53
  * @param hooks.getUnlockPromise - A function that resolves once the MetaMask
54
54
  * extension is unlocked and prompts the user to unlock their MetaMask if it is
@@ -58,6 +58,6 @@ export declare const getBip44EntropyBuilder: Readonly<{
58
58
  * @returns The method implementation which returns a `BIP44CoinTypeNode`.
59
59
  * @throws If the params are invalid.
60
60
  */
61
- export declare function getBip44EntropyImplementation({ getMnemonic, getUnlockPromise, getClientCryptography, }: GetBip44EntropyMethodHooks): (args: RestrictedMethodOptions<GetBip44EntropyParams>) => Promise<GetBip44EntropyResult>;
61
+ export declare function getBip44EntropyImplementation({ getMnemonicSeed, getUnlockPromise, getClientCryptography, }: GetBip44EntropyMethodHooks): (args: RestrictedMethodOptions<GetBip44EntropyParams>) => Promise<GetBip44EntropyResult>;
62
62
  export {};
63
63
  //# sourceMappingURL=getBip44Entropy.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"getBip44Entropy.d.mts","sourceRoot":"","sources":["../../src/restricted/getBip44Entropy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,2BAA2B;AAEjE,OAAO,KAAK,EACV,8BAA8B,EAC9B,6BAA6B,EAC7B,uBAAuB,EAExB,wCAAwC;AACzC,OAAO,EAAE,cAAc,EAAe,wCAAwC;AAE9E,OAAO,K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,qBAAqB,EACtB,4BAA4B;AAE7B,OAAO,KAAK,EAAE,aAAa,EAAE,wBAAwB;AAErD,OAAO,KAAK,EAAE,iBAAiB,EAAE,qBAAiB;AAGlD,QAAA,MAAM,UAAU,yBAAyB,CAAC;AAE1C,MAAM,MAAM,0BAA0B,GAAG;IACvC;;;;;;;OAOG;IACH,eAAe,EAAE,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,KAAK,OAAO,CAAC,UAAU,CAAC,CAAC;IAEtE;;;;OAIG;IACH,gBAAgB,EAAE,CAAC,uBAAuB,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAEtE;;;;;;OAMG;IACH,qBAAqB,EAAE,MAAM,sBAAsB,GAAG,SAAS,CAAC;CACjE,CAAC;AAEF,KAAK,0CAA0C,GAAG;IAChD,WAAW,EAAE,0BAA0B,CAAC;CACzC,CAAC;AAkDF,eAAO,MAAM,sBAAsB;;;wBA/CjB,eAAe,gBAAgB;oBACnC,iBAAiB;8BACP,WAAW,oCAAoC,CAAC;wBACtD,SAAS,cAAc,MAAM,CAAC,CAAC,GAAG,IAAI;mBAC3C,6BAA6B;;;EA+C/B,CAAC;AAEZ;;;;;;;;;;;;;GAaG;AACH,wBAAgB,6BAA6B,CAAC,EAC5C,eAAe,EACf,gBAAgB,EAChB,qBAAqB,GACtB,EAAE,0BAA0B,UAEnB,wBAAwB,qBAAqB,CAAC,KACnD,QAAQ,qBAAqB,CAAC,CAoBlC"}
@@ -2,7 +2,7 @@ import { BIP44CoinTypeNode } from "@metamask/key-tree";
2
2
  import { PermissionType, SubjectType } from "@metamask/permission-controller";
3
3
  import { rpcErrors } from "@metamask/rpc-errors";
4
4
  import { SnapCaveatType } from "@metamask/snaps-utils";
5
- import { getSecretRecoveryPhrase } from "../utils.mjs";
5
+ import { getValueFromEntropySource } from "../utils.mjs";
6
6
  const targetName = 'snap_getBip44Entropy';
7
7
  /**
8
8
  * The specification builder for the `snap_getBip44Entropy` permission.
@@ -32,7 +32,7 @@ const specificationBuilder = ({ methodHooks }) => {
32
32
  };
33
33
  };
34
34
  const methodHooks = {
35
- getMnemonic: true,
35
+ getMnemonicSeed: true,
36
36
  getUnlockPromise: true,
37
37
  getClientCryptography: true,
38
38
  };
@@ -45,7 +45,7 @@ export const getBip44EntropyBuilder = Object.freeze({
45
45
  * Builds the method implementation for `snap_getBip44Entropy`.
46
46
  *
47
47
  * @param hooks - The RPC method hooks.
48
- * @param hooks.getMnemonic - A function to retrieve the Secret Recovery Phrase
48
+ * @param hooks.getMnemonicSeed - A function to retrieve the BIP-39 seed
49
49
  * of the user.
50
50
  * @param hooks.getUnlockPromise - A function that resolves once the MetaMask
51
51
  * extension is unlocked and prompts the user to unlock their MetaMask if it is
@@ -55,13 +55,16 @@ export const getBip44EntropyBuilder = Object.freeze({
55
55
  * @returns The method implementation which returns a `BIP44CoinTypeNode`.
56
56
  * @throws If the params are invalid.
57
57
  */
58
- export function getBip44EntropyImplementation({ getMnemonic, getUnlockPromise, getClientCryptography, }) {
58
+ export function getBip44EntropyImplementation({ getMnemonicSeed, getUnlockPromise, getClientCryptography, }) {
59
59
  return async function getBip44Entropy(args) {
60
60
  await getUnlockPromise(true);
61
61
  // `args.params` is validated by the decorator, so it's safe to assert here.
62
62
  const params = args.params;
63
- const secretRecoveryPhrase = await getSecretRecoveryPhrase(getMnemonic, params.source);
64
- const node = await BIP44CoinTypeNode.fromDerivationPath([secretRecoveryPhrase, `bip32:44'`, `bip32:${params.coinType}'`], 'mainnet', getClientCryptography());
63
+ const seed = await getValueFromEntropySource(getMnemonicSeed, params.source);
64
+ const node = await BIP44CoinTypeNode.fromSeed({
65
+ derivationPath: [seed, `bip32:44'`, `bip32:${params.coinType}'`],
66
+ network: 'mainnet',
67
+ }, getClientCryptography());
65
68
  return node.toJSON();
66
69
  };
67
70
  }
@@ -1 +1 @@
1
- {"version":3,"file":"getBip44Entropy.mjs","sourceRoot":"","sources":["../../src/restricted/getBip44Entropy.ts"],"names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IAC3B,OAAO,KAAK,UAAU,eAAe,CACnC,IAAoD;QAEpD,MAAM,gBAAgB,CAAC,IAAI,CAAC,CAAC;QAE7B,4EAA4E;QAC5E,MAAM,MAAM,GAAG,IAAI,CAAC,MAA+B,CAAC;QACpD,MAAM,oBAAoB,GAAG,MAAM,uBAAuB,CACxD,WAAW,EACX,MAAM,CAAC,MAAM,CACd,CAAC;QAEF,MAAM,IAAI,GAAG,MAAM,iBAAiB,CAAC,kBAAkB,CACrD,CAAC,oBAAoB,EAAE,WAAW,EAAE,SAAS,MAAM,CAAC,QAAQ,GAAG,CAAC,EAChE,SAAS,EACT,qBAAqB,EAAE,CACxB,CAAC;QAEF,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC;IACvB,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import type { CryptographicFunctions } from '@metamask/key-tree';\nimport { BIP44CoinTypeNode } from '@metamask/key-tree';\nimport type {\n PermissionSpecificationBuilder,\n PermissionValidatorConstraint,\n RestrictedMethodOptions,\n ValidPermissionSpecification,\n} from '@metamask/permission-controller';\nimport { PermissionType, SubjectType } from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type {\n GetBip44EntropyParams,\n GetBip44EntropyResult,\n} from '@metamask/snaps-sdk';\nimport { SnapCaveatType } from '@metamask/snaps-utils';\nimport type { NonEmptyArray } from '@metamask/utils';\n\nimport type { MethodHooksObject } from '../utils';\nimport { getSecretRecoveryPhrase } from '../utils';\n\nconst targetName = 'snap_getBip44Entropy';\n\nexport type GetBip44EntropyMethodHooks = {\n /**\n * Get the mnemonic of the provided source. If no source is provided, the\n * mnemonic of the primary keyring will be returned.\n *\n * @param source - The optional ID of the source to get the mnemonic of.\n * @returns The mnemonic of the provided source, or the default source if no\n * source is provided.\n */\n getMnemonic: (source?: string | undefined) => Promise<Uint8Array>;\n\n /**\n * Waits for the extension to be unlocked.\n *\n * @returns A promise that resolves once the extension is unlocked.\n */\n getUnlockPromise: (shouldShowUnlockRequest: boolean) => Promise<void>;\n\n /**\n * Get the cryptographic functions to use for the client. This may return an\n * empty object or `undefined` to fall back to the default cryptographic\n * functions.\n *\n * @returns The cryptographic functions to use for the client.\n */\n getClientCryptography: () => CryptographicFunctions | undefined;\n};\n\ntype GetBip44EntropySpecificationBuilderOptions = {\n methodHooks: GetBip44EntropyMethodHooks;\n};\n\ntype GetBip44EntropySpecification = ValidPermissionSpecification<{\n permissionType: PermissionType.RestrictedMethod;\n targetName: typeof targetName;\n methodImplementation: ReturnType<typeof getBip44EntropyImplementation>;\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n validator: PermissionValidatorConstraint;\n}>;\n\n/**\n * The specification builder for the `snap_getBip44Entropy` permission.\n * `snap_getBip44Entropy_*` lets the Snap control private keys for a particular\n * BIP-32 coin type.\n *\n * @param options - The specification builder options.\n * @param options.methodHooks - The RPC method hooks needed by the method\n * implementation.\n * @returns The specification for the `snap_getBip44Entropy` permission.\n */\nconst specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.RestrictedMethod,\n GetBip44EntropySpecificationBuilderOptions,\n GetBip44EntropySpecification\n> = ({ methodHooks }: GetBip44EntropySpecificationBuilderOptions) => {\n return {\n permissionType: PermissionType.RestrictedMethod,\n targetName,\n allowedCaveats: [SnapCaveatType.PermittedCoinTypes],\n methodImplementation: getBip44EntropyImplementation(methodHooks),\n validator: ({ caveats }) => {\n if (\n caveats?.length !== 1 ||\n caveats[0].type !== SnapCaveatType.PermittedCoinTypes\n ) {\n throw rpcErrors.invalidParams({\n message: `Expected a single \"${SnapCaveatType.PermittedCoinTypes}\" caveat.`,\n });\n }\n },\n subjectTypes: [SubjectType.Snap],\n };\n};\n\nconst methodHooks: MethodHooksObject<GetBip44EntropyMethodHooks> = {\n getMnemonic: true,\n getUnlockPromise: true,\n getClientCryptography: true,\n};\n\nexport const getBip44EntropyBuilder = Object.freeze({\n targetName,\n specificationBuilder,\n methodHooks,\n} as const);\n\n/**\n * Builds the method implementation for `snap_getBip44Entropy`.\n *\n * @param hooks - The RPC method hooks.\n * @param hooks.getMnemonic - A function to retrieve the Secret Recovery Phrase\n * of the user.\n * @param hooks.getUnlockPromise - A function that resolves once the MetaMask\n * extension is unlocked and prompts the user to unlock their MetaMask if it is\n * locked.\n * @param hooks.getClientCryptography - A function to retrieve the cryptographic\n * functions to use for the client.\n * @returns The method implementation which returns a `BIP44CoinTypeNode`.\n * @throws If the params are invalid.\n */\nexport function getBip44EntropyImplementation({\n getMnemonic,\n getUnlockPromise,\n getClientCryptography,\n}: GetBip44EntropyMethodHooks) {\n return async function getBip44Entropy(\n args: RestrictedMethodOptions<GetBip44EntropyParams>,\n ): Promise<GetBip44EntropyResult> {\n await getUnlockPromise(true);\n\n // `args.params` is validated by the decorator, so it's safe to assert here.\n const params = args.params as GetBip44EntropyParams;\n const secretRecoveryPhrase = await getSecretRecoveryPhrase(\n getMnemonic,\n params.source,\n );\n\n const node = await BIP44CoinTypeNode.fromDerivationPath(\n [secretRecoveryPhrase, `bip32:44'`, `bip32:${params.coinType}'`],\n 'mainnet',\n getClientCryptography(),\n );\n\n return node.toJSON();\n };\n}\n"]}
1
+ {"version":3,"file":"getBip44Entropy.mjs","sourceRoot":"","sources":["../../src/restricted/getBip44Entropy.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,2BAA2B;AAOvD,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,wCAAwC;AAC9E,OAAO,EAAE,SAAS,EAAE,6BAA6B;AAKjD,OAAO,EAAE,cAAc,EAAE,8BAA8B;AAIvD,OAAO,EAAE,yBAAyB,EAAE,qBAAiB;AAErD,MAAM,UAAU,GAAG,sBAAsB,CAAC;AA0C1C;;;;;;;;;GASG;AACH,MAAM,oBAAoB,GAItB,CAAC,EAAE,WAAW,EAA8C,EAAE,EAAE;IAClE,OAAO;QACL,cAAc,EAAE,cAAc,CAAC,gBAAgB;QAC/C,UAAU;QACV,cAAc,EAAE,CAAC,cAAc,CAAC,kBAAkB,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AO,IAAI,CAAC,MAAM,EAAE,CAAC;IACvB,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import type { CryptographicFunctions } from '@metamask/key-tree';\nimport { BIP44CoinTypeNode } from '@metamask/key-tree';\nimport type {\n PermissionSpecificationBuilder,\n PermissionValidatorConstraint,\n RestrictedMethodOptions,\n ValidPermissionSpecification,\n} from '@metamask/permission-controller';\nimport { PermissionType, SubjectType } from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type {\n GetBip44EntropyParams,\n GetBip44EntropyResult,\n} from '@metamask/snaps-sdk';\nimport { SnapCaveatType } from '@metamask/snaps-utils';\nimport type { NonEmptyArray } from '@metamask/utils';\n\nimport type { MethodHooksObject } from '../utils';\nimport { getValueFromEntropySource } from '../utils';\n\nconst targetName = 'snap_getBip44Entropy';\n\nexport type GetBip44EntropyMethodHooks = {\n /**\n * Get the mnemonic seed of the provided source. If no source is provided, the\n * mnemonic seed of the primary keyring will be returned.\n *\n * @param source - The optional ID of the source to get the mnemonic of.\n * @returns The mnemonic seed of the provided source, or the default source if no\n * source is provided.\n */\n getMnemonicSeed: (source?: string | undefined) => Promise<Uint8Array>;\n\n /**\n * Waits for the extension to be unlocked.\n *\n * @returns A promise that resolves once the extension is unlocked.\n */\n getUnlockPromise: (shouldShowUnlockRequest: boolean) => Promise<void>;\n\n /**\n * Get the cryptographic functions to use for the client. This may return an\n * empty object or `undefined` to fall back to the default cryptographic\n * functions.\n *\n * @returns The cryptographic functions to use for the client.\n */\n getClientCryptography: () => CryptographicFunctions | undefined;\n};\n\ntype GetBip44EntropySpecificationBuilderOptions = {\n methodHooks: GetBip44EntropyMethodHooks;\n};\n\ntype GetBip44EntropySpecification = ValidPermissionSpecification<{\n permissionType: PermissionType.RestrictedMethod;\n targetName: typeof targetName;\n methodImplementation: ReturnType<typeof getBip44EntropyImplementation>;\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n validator: PermissionValidatorConstraint;\n}>;\n\n/**\n * The specification builder for the `snap_getBip44Entropy` permission.\n * `snap_getBip44Entropy_*` lets the Snap control private keys for a particular\n * BIP-32 coin type.\n *\n * @param options - The specification builder options.\n * @param options.methodHooks - The RPC method hooks needed by the method\n * implementation.\n * @returns The specification for the `snap_getBip44Entropy` permission.\n */\nconst specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.RestrictedMethod,\n GetBip44EntropySpecificationBuilderOptions,\n GetBip44EntropySpecification\n> = ({ methodHooks }: GetBip44EntropySpecificationBuilderOptions) => {\n return {\n permissionType: PermissionType.RestrictedMethod,\n targetName,\n allowedCaveats: [SnapCaveatType.PermittedCoinTypes],\n methodImplementation: getBip44EntropyImplementation(methodHooks),\n validator: ({ caveats }) => {\n if (\n caveats?.length !== 1 ||\n caveats[0].type !== SnapCaveatType.PermittedCoinTypes\n ) {\n throw rpcErrors.invalidParams({\n message: `Expected a single \"${SnapCaveatType.PermittedCoinTypes}\" caveat.`,\n });\n }\n },\n subjectTypes: [SubjectType.Snap],\n };\n};\n\nconst methodHooks: MethodHooksObject<GetBip44EntropyMethodHooks> = {\n getMnemonicSeed: true,\n getUnlockPromise: true,\n getClientCryptography: true,\n};\n\nexport const getBip44EntropyBuilder = Object.freeze({\n targetName,\n specificationBuilder,\n methodHooks,\n} as const);\n\n/**\n * Builds the method implementation for `snap_getBip44Entropy`.\n *\n * @param hooks - The RPC method hooks.\n * @param hooks.getMnemonicSeed - A function to retrieve the BIP-39 seed\n * of the user.\n * @param hooks.getUnlockPromise - A function that resolves once the MetaMask\n * extension is unlocked and prompts the user to unlock their MetaMask if it is\n * locked.\n * @param hooks.getClientCryptography - A function to retrieve the cryptographic\n * functions to use for the client.\n * @returns The method implementation which returns a `BIP44CoinTypeNode`.\n * @throws If the params are invalid.\n */\nexport function getBip44EntropyImplementation({\n getMnemonicSeed,\n getUnlockPromise,\n getClientCryptography,\n}: GetBip44EntropyMethodHooks) {\n return async function getBip44Entropy(\n args: RestrictedMethodOptions<GetBip44EntropyParams>,\n ): Promise<GetBip44EntropyResult> {\n await getUnlockPromise(true);\n\n // `args.params` is validated by the decorator, so it's safe to assert here.\n const params = args.params as GetBip44EntropyParams;\n const seed = await getValueFromEntropySource(\n getMnemonicSeed,\n params.source,\n );\n\n const node = await BIP44CoinTypeNode.fromSeed(\n {\n derivationPath: [seed, `bip32:44'`, `bip32:${params.coinType}'`],\n network: 'mainnet',\n },\n getClientCryptography(),\n );\n\n return node.toJSON();\n };\n}\n"]}
@@ -23,7 +23,7 @@ const specificationBuilder = ({ allowedCaveats = null, methodHooks, }) => {
23
23
  };
24
24
  };
25
25
  const methodHooks = {
26
- getMnemonic: true,
26
+ getMnemonicSeed: true,
27
27
  getUnlockPromise: true,
28
28
  getClientCryptography: true,
29
29
  };
@@ -38,24 +38,24 @@ exports.getEntropyBuilder = Object.freeze({
38
38
  * [SIP-6](https://metamask.github.io/SIPs/SIPS/sip-6).
39
39
  *
40
40
  * @param hooks - The RPC method hooks.
41
- * @param hooks.getMnemonic - The method to get the mnemonic of the user's
42
- * primary keyring.
41
+ * @param hooks.getMnemonicSeed - A function to retrieve the BIP-39 seed
42
+ * of the user.
43
43
  * @param hooks.getUnlockPromise - The method to get a promise that resolves
44
44
  * once the extension is unlocked.
45
45
  * @param hooks.getClientCryptography - A function to retrieve the cryptographic
46
46
  * functions to use for the client.
47
47
  * @returns The method implementation.
48
48
  */
49
- function getEntropyImplementation({ getMnemonic, getUnlockPromise, getClientCryptography, }) {
49
+ function getEntropyImplementation({ getMnemonicSeed, getUnlockPromise, getClientCryptography, }) {
50
50
  return async function getEntropy(options) {
51
51
  const { params, context: { origin }, } = options;
52
52
  (0, utils_1.assertStruct)(params, exports.GetEntropyArgsStruct, 'Invalid "snap_getEntropy" parameters', rpc_errors_1.rpcErrors.invalidParams);
53
53
  await getUnlockPromise(true);
54
- const mnemonicPhrase = await (0, utils_2.getSecretRecoveryPhrase)(getMnemonic, params.source);
55
- return (0, utils_2.deriveEntropy)({
54
+ const seed = await (0, utils_2.getValueFromEntropySource)(getMnemonicSeed, params.source);
55
+ return (0, utils_2.deriveEntropyFromSeed)({
56
56
  input: origin,
57
57
  salt: params.salt,
58
- mnemonicPhrase,
58
+ seed,
59
59
  magic: snaps_utils_1.SIP_6_MAGIC_VALUE,
60
60
  cryptographicFunctions: getClientCryptography(),
61
61
  });
@@ -1 +1 @@
1
- {"version":3,"file":"getEntropy.cjs","sourceRoot":"","sources":["../../src/restricted/getEntropy.ts"],"names":[],"mappings":";;;AAMA,2EAA8E;AAC9E,qDAAiD;AAEjD,uDAA0D;AAE1D,uDAA0E;AAE1E,2CAA+C;AAG/C,wCAAkE;AAElE,MAAM,UAAU,GAAG,iBAAiB,CAAC;AAcxB,QAAA,oBAAoB,GAAG,IAAA,oBAAM,EAAC;IACzC,OAAO,EAAE,IAAA,qBAAO,EAAC,CAAC,CAAC;IACnB,IAAI,EAAE,IAAA,sBAAQ,EAAC,IAAA,oBAAM,GAAE,CAAC;IACxB,MAAM,EAAE,IAAA,sBAAQ,EAAC,IAAA,oBAAM,GAAE,CAAC;CAC3B,CAAC,CAAC;AAUH,MAAM,oBAAoB,GAItB,CAAC,EACH,cAAc,GAAG,IAAI,EACrB,WAAW,GAC2B,EAAE,EAAE;IAC1C,OAAO;QACL,cAAc,EAAE,sCAAc,CAAC,gBAAgB;QAC/C,UAAU;QACV,cAAc;QACd,oBAAoB,EAAE,wBAAwB,CAAC,WAAW,CAAC;QAC3D,YAAY,EAAE,CAAC,mCAAW,CAAC,IAAI,CAAC;KACjC,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,WAAW,GAAuC;IACtD,WAAW,EAAE,IAAI;IACjB,gBAAgB,EAAE,IAAI;IACtB,qBAAqB,EAAE,IAAI;CAC5B,CAAC;AAEW,QAAA,iBAAiB,GAAG,MAAM,CAAC,MAAM,CAAC;IAC7C,UAAU;IACV,oBAAoB;IACpB,WAAW;CACH,CAAC,CAAC;AA8BZ;;;;;;;;;;;;;GAaG;AACH,SAAS,wBAAwB,CAAC,EAChC,WAAW,EACX,gBAAgB,EAChB,qBAAqB,GACL;IAChB,OAAO,KAAK,UAAU,UAAU,CAC9B,OAAkD;QAElD,MAAM,EACJ,MAAM,EACN,OAAO,EAAE,EAAE,MAAM,EAAE,GACpB,GAAG,OAAO,CAAC;QAEZ,IAAA,oBAAY,EACV,MAAM,EACN,4BAAoB,EACpB,sCAAsC,EACtC,sBAAS,CAAC,aAAa,CACxB,CAAC;QAEF,MAAM,gBAAgB,CAAC,IAAI,CAAC,CAAC;QAC7B,MAAM,cAAc,GAAG,MAAM,IAAA,+BAAuB,EAClD,WAAW,EACX,MAAM,CAAC,MAAM,CACd,CAAC;QAEF,OAAO,IAAA,qBAAa,EAAC;YACnB,KAAK,EAAE,MAAM;YACb,IAAI,EAAE,MAAM,CAAC,IAAI;YACjB,cAAc;YACd,KAAK,EAAE,+BAAiB;YACxB,sBAAsB,EAAE,qBAAqB,EAAE;SAChD,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import type { CryptographicFunctions } from '@metamask/key-tree';\nimport type {\n PermissionSpecificationBuilder,\n RestrictedMethodOptions,\n ValidPermissionSpecification,\n} from '@metamask/permission-controller';\nimport { PermissionType, SubjectType } from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type { GetEntropyParams, GetEntropyResult } from '@metamask/snaps-sdk';\nimport { SIP_6_MAGIC_VALUE } from '@metamask/snaps-utils';\nimport type { Infer } from '@metamask/superstruct';\nimport { literal, object, optional, string } from '@metamask/superstruct';\nimport type { NonEmptyArray } from '@metamask/utils';\nimport { assertStruct } from '@metamask/utils';\n\nimport type { MethodHooksObject } from '../utils';\nimport { getSecretRecoveryPhrase, deriveEntropy } from '../utils';\n\nconst targetName = 'snap_getEntropy';\n\ntype GetEntropySpecificationBuilderOptions = {\n allowedCaveats?: Readonly<NonEmptyArray<string>> | null;\n methodHooks: GetEntropyHooks;\n};\n\ntype GetEntropySpecification = ValidPermissionSpecification<{\n permissionType: PermissionType.RestrictedMethod;\n targetName: typeof targetName;\n methodImplementation: ReturnType<typeof getEntropyImplementation>;\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n}>;\n\nexport const GetEntropyArgsStruct = object({\n version: literal(1),\n salt: optional(string()),\n source: optional(string()),\n});\n\n/**\n * @property version - The version of the `snap_getEntropy` method. This must be\n * the numeric literal `1`.\n * @property salt - A string to use as the salt when deriving the entropy. If\n * omitted, the salt will be an empty string.\n */\nexport type GetEntropyArgs = Infer<typeof GetEntropyArgsStruct>;\n\nconst specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.RestrictedMethod,\n GetEntropySpecificationBuilderOptions,\n GetEntropySpecification\n> = ({\n allowedCaveats = null,\n methodHooks,\n}: GetEntropySpecificationBuilderOptions) => {\n return {\n permissionType: PermissionType.RestrictedMethod,\n targetName,\n allowedCaveats,\n methodImplementation: getEntropyImplementation(methodHooks),\n subjectTypes: [SubjectType.Snap],\n };\n};\n\nconst methodHooks: MethodHooksObject<GetEntropyHooks> = {\n getMnemonic: true,\n getUnlockPromise: true,\n getClientCryptography: true,\n};\n\nexport const getEntropyBuilder = Object.freeze({\n targetName,\n specificationBuilder,\n methodHooks,\n} as const);\n\nexport type GetEntropyHooks = {\n /**\n * Get the mnemonic of the provided source. If no source is provided, the\n * mnemonic of the primary keyring will be returned.\n *\n * @param source - The optional ID of the source to get the mnemonic of.\n * @returns The mnemonic of the provided source, or the default source if no\n * source is provided.\n */\n getMnemonic: (source?: string | undefined) => Promise<Uint8Array>;\n\n /**\n * Waits for the extension to be unlocked.\n *\n * @returns A promise that resolves once the extension is unlocked.\n */\n getUnlockPromise: (shouldShowUnlockRequest: boolean) => Promise<void>;\n\n /**\n * Get the cryptographic functions to use for the client. This may return an\n * empty object or `undefined` to fall back to the default cryptographic\n * functions.\n *\n * @returns The cryptographic functions to use for the client.\n */\n getClientCryptography: () => CryptographicFunctions | undefined;\n};\n\n/**\n * Builds the method implementation for `snap_getEntropy`. The implementation\n * is based on the reference implementation of\n * [SIP-6](https://metamask.github.io/SIPs/SIPS/sip-6).\n *\n * @param hooks - The RPC method hooks.\n * @param hooks.getMnemonic - The method to get the mnemonic of the user's\n * primary keyring.\n * @param hooks.getUnlockPromise - The method to get a promise that resolves\n * once the extension is unlocked.\n * @param hooks.getClientCryptography - A function to retrieve the cryptographic\n * functions to use for the client.\n * @returns The method implementation.\n */\nfunction getEntropyImplementation({\n getMnemonic,\n getUnlockPromise,\n getClientCryptography,\n}: GetEntropyHooks) {\n return async function getEntropy(\n options: RestrictedMethodOptions<GetEntropyParams>,\n ): Promise<GetEntropyResult> {\n const {\n params,\n context: { origin },\n } = options;\n\n assertStruct(\n params,\n GetEntropyArgsStruct,\n 'Invalid \"snap_getEntropy\" parameters',\n rpcErrors.invalidParams,\n );\n\n await getUnlockPromise(true);\n const mnemonicPhrase = await getSecretRecoveryPhrase(\n getMnemonic,\n params.source,\n );\n\n return deriveEntropy({\n input: origin,\n salt: params.salt,\n mnemonicPhrase,\n magic: SIP_6_MAGIC_VALUE,\n cryptographicFunctions: getClientCryptography(),\n });\n };\n}\n"]}
1
+ {"version":3,"file":"getEntropy.cjs","sourceRoot":"","sources":["../../src/restricted/getEntropy.ts"],"names":[],"mappings":";;;AAMA,2EAA8E;AAC9E,qDAAiD;AAEjD,uDAA0D;AAE1D,uDAA0E;AAE1E,2CAA+C;AAG/C,wCAA4E;AAE5E,MAAM,UAAU,GAAG,iBAAiB,CAAC;AAcxB,QAAA,oBAAoB,GAAG,IAAA,oBAAM,EAAC;IACzC,OAAO,EAAE,IAAA,qBAAO,EAAC,CAAC,CAAC;IACnB,IAAI,EAAE,IAAA,sBAAQ,EAAC,IAAA,oBAAM,GAAE,CAAC;IACxB,MAAM,EAAE,IAAA,sBAAQ,EAAC,IAAA,oBAAM,GAAE,CAAC;CAC3B,CAAC,CAAC;AAUH,MAAM,oBAAoB,GAItB,CAAC,EACH,cAAc,GAAG,IAAI,EACrB,WAAW,GAC2B,EAAE,EAAE;IAC1C,OAAO;QACL,cAAc,EAAE,sCAAc,CAAC,gBAAgB;QAC/C,UAAU;QACV,cAAc;QACd,oBAAoB,EAAE,wBAAwB,CAAC,WAAW,CAAC;QAC3D,YAAY,EAAE,CAAC,mCAAW,CAAC,IAAI,CAAC;KACjC,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,WAAW,GAAuC;IACtD,eAAe,EAAE,IAAI;IACrB,gBAAgB,EAAE,IAAI;IACtB,qBAAqB,EAAE,IAAI;CAC5B,CAAC;AAEW,QAAA,iBAAiB,GAAG,MAAM,CAAC,MAAM,CAAC;IAC7C,UAAU;IACV,oBAAoB;IACpB,WAAW;CACH,CAAC,CAAC;AA8BZ;;;;;;;;;;;;;GAaG;AACH,SAAS,wBAAwB,CAAC,EAChC,eAAe,EACf,gBAAgB,EAChB,qBAAqB,GACL;IAChB,OAAO,KAAK,UAAU,UAAU,CAC9B,OAAkD;QAElD,MAAM,EACJ,MAAM,EACN,OAAO,EAAE,EAAE,MAAM,EAAE,GACpB,GAAG,OAAO,CAAC;QAEZ,IAAA,oBAAY,EACV,MAAM,EACN,4BAAoB,EACpB,sCAAsC,EACtC,sBAAS,CAAC,aAAa,CACxB,CAAC;QAEF,MAAM,gBAAgB,CAAC,IAAI,CAAC,CAAC;QAC7B,MAAM,IAAI,GAAG,MAAM,IAAA,iCAAyB,EAC1C,eAAe,EACf,MAAM,CAAC,MAAM,CACd,CAAC;QAEF,OAAO,IAAA,6BAAqB,EAAC;YAC3B,KAAK,EAAE,MAAM;YACb,IAAI,EAAE,MAAM,CAAC,IAAI;YACjB,IAAI;YACJ,KAAK,EAAE,+BAAiB;YACxB,sBAAsB,EAAE,qBAAqB,EAAE;SAChD,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import type { CryptographicFunctions } from '@metamask/key-tree';\nimport type {\n PermissionSpecificationBuilder,\n RestrictedMethodOptions,\n ValidPermissionSpecification,\n} from '@metamask/permission-controller';\nimport { PermissionType, SubjectType } from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type { GetEntropyParams, GetEntropyResult } from '@metamask/snaps-sdk';\nimport { SIP_6_MAGIC_VALUE } from '@metamask/snaps-utils';\nimport type { Infer } from '@metamask/superstruct';\nimport { literal, object, optional, string } from '@metamask/superstruct';\nimport type { NonEmptyArray } from '@metamask/utils';\nimport { assertStruct } from '@metamask/utils';\n\nimport type { MethodHooksObject } from '../utils';\nimport { getValueFromEntropySource, deriveEntropyFromSeed } from '../utils';\n\nconst targetName = 'snap_getEntropy';\n\ntype GetEntropySpecificationBuilderOptions = {\n allowedCaveats?: Readonly<NonEmptyArray<string>> | null;\n methodHooks: GetEntropyHooks;\n};\n\ntype GetEntropySpecification = ValidPermissionSpecification<{\n permissionType: PermissionType.RestrictedMethod;\n targetName: typeof targetName;\n methodImplementation: ReturnType<typeof getEntropyImplementation>;\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n}>;\n\nexport const GetEntropyArgsStruct = object({\n version: literal(1),\n salt: optional(string()),\n source: optional(string()),\n});\n\n/**\n * @property version - The version of the `snap_getEntropy` method. This must be\n * the numeric literal `1`.\n * @property salt - A string to use as the salt when deriving the entropy. If\n * omitted, the salt will be an empty string.\n */\nexport type GetEntropyArgs = Infer<typeof GetEntropyArgsStruct>;\n\nconst specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.RestrictedMethod,\n GetEntropySpecificationBuilderOptions,\n GetEntropySpecification\n> = ({\n allowedCaveats = null,\n methodHooks,\n}: GetEntropySpecificationBuilderOptions) => {\n return {\n permissionType: PermissionType.RestrictedMethod,\n targetName,\n allowedCaveats,\n methodImplementation: getEntropyImplementation(methodHooks),\n subjectTypes: [SubjectType.Snap],\n };\n};\n\nconst methodHooks: MethodHooksObject<GetEntropyHooks> = {\n getMnemonicSeed: true,\n getUnlockPromise: true,\n getClientCryptography: true,\n};\n\nexport const getEntropyBuilder = Object.freeze({\n targetName,\n specificationBuilder,\n methodHooks,\n} as const);\n\nexport type GetEntropyHooks = {\n /**\n * Get the mnemonic seed of the provided source. If no source is provided, the\n * mnemonic seed of the primary keyring will be returned.\n *\n * @param source - The optional ID of the source to get the mnemonic of.\n * @returns The mnemonic seed of the provided source, or the default source if no\n * source is provided.\n */\n getMnemonicSeed: (source?: string | undefined) => Promise<Uint8Array>;\n\n /**\n * Waits for the extension to be unlocked.\n *\n * @returns A promise that resolves once the extension is unlocked.\n */\n getUnlockPromise: (shouldShowUnlockRequest: boolean) => Promise<void>;\n\n /**\n * Get the cryptographic functions to use for the client. This may return an\n * empty object or `undefined` to fall back to the default cryptographic\n * functions.\n *\n * @returns The cryptographic functions to use for the client.\n */\n getClientCryptography: () => CryptographicFunctions | undefined;\n};\n\n/**\n * Builds the method implementation for `snap_getEntropy`. The implementation\n * is based on the reference implementation of\n * [SIP-6](https://metamask.github.io/SIPs/SIPS/sip-6).\n *\n * @param hooks - The RPC method hooks.\n * @param hooks.getMnemonicSeed - A function to retrieve the BIP-39 seed\n * of the user.\n * @param hooks.getUnlockPromise - The method to get a promise that resolves\n * once the extension is unlocked.\n * @param hooks.getClientCryptography - A function to retrieve the cryptographic\n * functions to use for the client.\n * @returns The method implementation.\n */\nfunction getEntropyImplementation({\n getMnemonicSeed,\n getUnlockPromise,\n getClientCryptography,\n}: GetEntropyHooks) {\n return async function getEntropy(\n options: RestrictedMethodOptions<GetEntropyParams>,\n ): Promise<GetEntropyResult> {\n const {\n params,\n context: { origin },\n } = options;\n\n assertStruct(\n params,\n GetEntropyArgsStruct,\n 'Invalid \"snap_getEntropy\" parameters',\n rpcErrors.invalidParams,\n );\n\n await getUnlockPromise(true);\n const seed = await getValueFromEntropySource(\n getMnemonicSeed,\n params.source,\n );\n\n return deriveEntropyFromSeed({\n input: origin,\n salt: params.salt,\n seed,\n magic: SIP_6_MAGIC_VALUE,\n cryptographicFunctions: getClientCryptography(),\n });\n };\n}\n"]}
@@ -38,14 +38,14 @@ export declare const getEntropyBuilder: Readonly<{
38
38
  }>;
39
39
  export type GetEntropyHooks = {
40
40
  /**
41
- * Get the mnemonic of the provided source. If no source is provided, the
42
- * mnemonic of the primary keyring will be returned.
41
+ * Get the mnemonic seed of the provided source. If no source is provided, the
42
+ * mnemonic seed of the primary keyring will be returned.
43
43
  *
44
44
  * @param source - The optional ID of the source to get the mnemonic of.
45
- * @returns The mnemonic of the provided source, or the default source if no
45
+ * @returns The mnemonic seed of the provided source, or the default source if no
46
46
  * source is provided.
47
47
  */
48
- getMnemonic: (source?: string | undefined) => Promise<Uint8Array>;
48
+ getMnemonicSeed: (source?: string | undefined) => Promise<Uint8Array>;
49
49
  /**
50
50
  * Waits for the extension to be unlocked.
51
51
  *
@@ -67,14 +67,14 @@ export type GetEntropyHooks = {
67
67
  * [SIP-6](https://metamask.github.io/SIPs/SIPS/sip-6).
68
68
  *
69
69
  * @param hooks - The RPC method hooks.
70
- * @param hooks.getMnemonic - The method to get the mnemonic of the user's
71
- * primary keyring.
70
+ * @param hooks.getMnemonicSeed - A function to retrieve the BIP-39 seed
71
+ * of the user.
72
72
  * @param hooks.getUnlockPromise - The method to get a promise that resolves
73
73
  * once the extension is unlocked.
74
74
  * @param hooks.getClientCryptography - A function to retrieve the cryptographic
75
75
  * functions to use for the client.
76
76
  * @returns The method implementation.
77
77
  */
78
- declare function getEntropyImplementation({ getMnemonic, getUnlockPromise, getClientCryptography, }: GetEntropyHooks): (options: RestrictedMethodOptions<GetEntropyParams>) => Promise<GetEntropyResult>;
78
+ declare function getEntropyImplementation({ getMnemonicSeed, getUnlockPromise, getClientCryptography, }: GetEntropyHooks): (options: RestrictedMethodOptions<GetEntropyParams>) => Promise<GetEntropyResult>;
79
79
  export {};
80
80
  //# sourceMappingURL=getEntropy.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"getEntropy.d.cts","sourceRoot":"","sources":["../../src/restricted/getEntropy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,2BAA2B;AACjE,OAAO,KAAK,E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IACH,qBAAqB,EAAE,MAAM,sBAAsB,GAAG,SAAS,CAAC;CACjE,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,iBAAS,wBAAwB,CAAC,EAChC,eAAe,EACf,gBAAgB,EAChB,qBAAqB,GACtB,EAAE,eAAe,aAEL,wBAAwB,gBAAgB,CAAC,KACjD,QAAQ,gBAAgB,CAAC,CA2B7B"}
@@ -38,14 +38,14 @@ export declare const getEntropyBuilder: Readonly<{
38
38
  }>;
39
39
  export type GetEntropyHooks = {
40
40
  /**
41
- * Get the mnemonic of the provided source. If no source is provided, the
42
- * mnemonic of the primary keyring will be returned.
41
+ * Get the mnemonic seed of the provided source. If no source is provided, the
42
+ * mnemonic seed of the primary keyring will be returned.
43
43
  *
44
44
  * @param source - The optional ID of the source to get the mnemonic of.
45
- * @returns The mnemonic of the provided source, or the default source if no
45
+ * @returns The mnemonic seed of the provided source, or the default source if no
46
46
  * source is provided.
47
47
  */
48
- getMnemonic: (source?: string | undefined) => Promise<Uint8Array>;
48
+ getMnemonicSeed: (source?: string | undefined) => Promise<Uint8Array>;
49
49
  /**
50
50
  * Waits for the extension to be unlocked.
51
51
  *
@@ -67,14 +67,14 @@ export type GetEntropyHooks = {
67
67
  * [SIP-6](https://metamask.github.io/SIPs/SIPS/sip-6).
68
68
  *
69
69
  * @param hooks - The RPC method hooks.
70
- * @param hooks.getMnemonic - The method to get the mnemonic of the user's
71
- * primary keyring.
70
+ * @param hooks.getMnemonicSeed - A function to retrieve the BIP-39 seed
71
+ * of the user.
72
72
  * @param hooks.getUnlockPromise - The method to get a promise that resolves
73
73
  * once the extension is unlocked.
74
74
  * @param hooks.getClientCryptography - A function to retrieve the cryptographic
75
75
  * functions to use for the client.
76
76
  * @returns The method implementation.
77
77
  */
78
- declare function getEntropyImplementation({ getMnemonic, getUnlockPromise, getClientCryptography, }: GetEntropyHooks): (options: RestrictedMethodOptions<GetEntropyParams>) => Promise<GetEntropyResult>;
78
+ declare function getEntropyImplementation({ getMnemonicSeed, getUnlockPromise, getClientCryptography, }: GetEntropyHooks): (options: RestrictedMethodOptions<GetEntropyParams>) => Promise<GetEntropyResult>;
79
79
  export {};
80
80
  //# sourceMappingURL=getEntropy.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"getEntropy.d.mts","sourceRoot":"","sources":["../../src/restricted/getEntropy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,2BAA2B;AACjE,OAAO,KAAK,EACV,8BAA8B,EAC9B,uBAAuB,EAExB,wCAAwC;AACzC,OAAO,EAAE,cAAc,EAAe,wCAAwC;AAE9E,OAAO,KAAK,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,4BAA4B;AAE9E,OAAO,KAAK,EAAE,KAAK,EAAE,8BAA8B;AAEnD,OAAO,KAAK,EAAE,aAAa,EAAE,wBAAwB;AAGrD,OAAO,KAAK,EAAE,iBAAiB,EAAE,qBAAiB;AAGlD,QAAA,MAAM,UAAU,oBAAoB,CAAC;AAErC,KAAK,qCAAqC,GAAG;IAC3C,cAAc,CAAC,EAAE,QAAQ,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,GAAG,IAAI,CAAC;IACxD,WAAW,EAAE,eAAe,CAAC;CAC9B,CAAC;AASF,eAAO,MAAM,oBAAoB;;;;;;;;EAI/B,CAAC;AAEH;;;;;GAKG;AACH,MAAM,MAAM,cAAc,GAAG,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAyBhE,eAAO,MAAM,iBAAiB;;;wBA3CZ,eAAe,gBAAgB;oBACnC,iBAAiB;8BACP,WAAW,+BAA+B,CAAC;wBACjD,SAAS,cAAc,MAAM,CAAC,CAAC,GAAG,IAAI;;;EA4C7C,CAAC;AAEZ,MAAM,MAAM,eAAe,GAAG;IAC5B;;;;;;;OAOG;IACH,WAAW,EAAE,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,KAAK,OAAO,CAAC,UAAU,CAAC,CAAC;IAElE;;;;OAIG;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C,GAAG,IAAI;;;EA4C7C,CAAC;AAEZ,MAAM,MAAM,eAAe,GAAG;IAC5B;;;;;;;OAOG;IACH,eAAe,EAAE,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,KAAK,OAAO,CAAC,UAAU,CAAC,CAAC;IAEtE;;;;OAIG;IACH,gBAAgB,EAAE,CAAC,uBAAuB,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAEtE;;;;;;OAMG;IACH,qBAAqB,EAAE,MAAM,sBAAsB,GAAG,SAAS,CAAC;CACjE,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,iBAAS,wBAAwB,CAAC,EAChC,eAAe,EACf,gBAAgB,EAChB,qBAAqB,GACtB,EAAE,eAAe,aAEL,wBAAwB,gBAAgB,CAAC,KACjD,QAAQ,gBAAgB,CAAC,CA2B7B"}
@@ -3,7 +3,7 @@ import { rpcErrors } from "@metamask/rpc-errors";
3
3
  import { SIP_6_MAGIC_VALUE } from "@metamask/snaps-utils";
4
4
  import { literal, object, optional, string } from "@metamask/superstruct";
5
5
  import { assertStruct } from "@metamask/utils";
6
- import { getSecretRecoveryPhrase, deriveEntropy } from "../utils.mjs";
6
+ import { getValueFromEntropySource, deriveEntropyFromSeed } from "../utils.mjs";
7
7
  const targetName = 'snap_getEntropy';
8
8
  export const GetEntropyArgsStruct = object({
9
9
  version: literal(1),
@@ -20,7 +20,7 @@ const specificationBuilder = ({ allowedCaveats = null, methodHooks, }) => {
20
20
  };
21
21
  };
22
22
  const methodHooks = {
23
- getMnemonic: true,
23
+ getMnemonicSeed: true,
24
24
  getUnlockPromise: true,
25
25
  getClientCryptography: true,
26
26
  };
@@ -35,24 +35,24 @@ export const getEntropyBuilder = Object.freeze({
35
35
  * [SIP-6](https://metamask.github.io/SIPs/SIPS/sip-6).
36
36
  *
37
37
  * @param hooks - The RPC method hooks.
38
- * @param hooks.getMnemonic - The method to get the mnemonic of the user's
39
- * primary keyring.
38
+ * @param hooks.getMnemonicSeed - A function to retrieve the BIP-39 seed
39
+ * of the user.
40
40
  * @param hooks.getUnlockPromise - The method to get a promise that resolves
41
41
  * once the extension is unlocked.
42
42
  * @param hooks.getClientCryptography - A function to retrieve the cryptographic
43
43
  * functions to use for the client.
44
44
  * @returns The method implementation.
45
45
  */
46
- function getEntropyImplementation({ getMnemonic, getUnlockPromise, getClientCryptography, }) {
46
+ function getEntropyImplementation({ getMnemonicSeed, getUnlockPromise, getClientCryptography, }) {
47
47
  return async function getEntropy(options) {
48
48
  const { params, context: { origin }, } = options;
49
49
  assertStruct(params, GetEntropyArgsStruct, 'Invalid "snap_getEntropy" parameters', rpcErrors.invalidParams);
50
50
  await getUnlockPromise(true);
51
- const mnemonicPhrase = await getSecretRecoveryPhrase(getMnemonic, params.source);
52
- return deriveEntropy({
51
+ const seed = await getValueFromEntropySource(getMnemonicSeed, params.source);
52
+ return deriveEntropyFromSeed({
53
53
  input: origin,
54
54
  salt: params.salt,
55
- mnemonicPhrase,
55
+ seed,
56
56
  magic: SIP_6_MAGIC_VALUE,
57
57
  cryptographicFunctions: getClientCryptography(),
58
58
  });