@metamask/snaps-rpc-methods 11.13.1 → 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 (50) hide show
  1. package/CHANGELOG.md +10 -1
  2. package/dist/restricted/getBip32Entropy.cjs +16 -3
  3. package/dist/restricted/getBip32Entropy.cjs.map +1 -1
  4. package/dist/restricted/getBip32Entropy.d.cts +11 -1
  5. package/dist/restricted/getBip32Entropy.d.cts.map +1 -1
  6. package/dist/restricted/getBip32Entropy.d.mts +11 -1
  7. package/dist/restricted/getBip32Entropy.d.mts.map +1 -1
  8. package/dist/restricted/getBip32Entropy.mjs +17 -4
  9. package/dist/restricted/getBip32Entropy.mjs.map +1 -1
  10. package/dist/restricted/getBip32PublicKey.cjs +19 -3
  11. package/dist/restricted/getBip32PublicKey.cjs.map +1 -1
  12. package/dist/restricted/getBip32PublicKey.d.cts +11 -1
  13. package/dist/restricted/getBip32PublicKey.d.cts.map +1 -1
  14. package/dist/restricted/getBip32PublicKey.d.mts +11 -1
  15. package/dist/restricted/getBip32PublicKey.d.mts.map +1 -1
  16. package/dist/restricted/getBip32PublicKey.mjs +20 -4
  17. package/dist/restricted/getBip32PublicKey.mjs.map +1 -1
  18. package/dist/restricted/getBip44Entropy.cjs +8 -5
  19. package/dist/restricted/getBip44Entropy.cjs.map +1 -1
  20. package/dist/restricted/getBip44Entropy.d.cts +6 -6
  21. package/dist/restricted/getBip44Entropy.d.cts.map +1 -1
  22. package/dist/restricted/getBip44Entropy.d.mts +6 -6
  23. package/dist/restricted/getBip44Entropy.d.mts.map +1 -1
  24. package/dist/restricted/getBip44Entropy.mjs +9 -6
  25. package/dist/restricted/getBip44Entropy.mjs.map +1 -1
  26. package/dist/restricted/getEntropy.cjs +7 -7
  27. package/dist/restricted/getEntropy.cjs.map +1 -1
  28. package/dist/restricted/getEntropy.d.cts +7 -7
  29. package/dist/restricted/getEntropy.d.cts.map +1 -1
  30. package/dist/restricted/getEntropy.d.mts +7 -7
  31. package/dist/restricted/getEntropy.d.mts.map +1 -1
  32. package/dist/restricted/getEntropy.mjs +8 -8
  33. package/dist/restricted/getEntropy.mjs.map +1 -1
  34. package/dist/restricted/manageState.cjs +4 -4
  35. package/dist/restricted/manageState.cjs.map +1 -1
  36. package/dist/restricted/manageState.d.cts +3 -3
  37. package/dist/restricted/manageState.d.cts.map +1 -1
  38. package/dist/restricted/manageState.d.mts +3 -3
  39. package/dist/restricted/manageState.d.mts.map +1 -1
  40. package/dist/restricted/manageState.mjs +5 -5
  41. package/dist/restricted/manageState.mjs.map +1 -1
  42. package/dist/utils.cjs +68 -23
  43. package/dist/utils.cjs.map +1 -1
  44. package/dist/utils.d.cts +40 -16
  45. package/dist/utils.d.cts.map +1 -1
  46. package/dist/utils.d.mts +40 -16
  47. package/dist/utils.d.mts.map +1 -1
  48. package/dist/utils.mjs +63 -19
  49. package/dist/utils.mjs.map +1 -1
  50. package/package.json +3 -3
@@ -64,7 +64,7 @@ export declare const manageStateBuilder: Readonly<{
64
64
  export declare const STORAGE_SIZE_LIMIT = 64000000;
65
65
  type GetEncryptionKeyArgs = {
66
66
  snapId: string;
67
- mnemonicPhrase: Uint8Array;
67
+ seed: Uint8Array;
68
68
  cryptographicFunctions?: CryptographicFunctions | undefined;
69
69
  };
70
70
  /**
@@ -76,13 +76,13 @@ type GetEncryptionKeyArgs = {
76
76
  *
77
77
  * @param args - The encryption key args.
78
78
  * @param args.snapId - The ID of the snap to get the encryption key for.
79
- * @param args.mnemonicPhrase - The mnemonic phrase to derive the encryption key
79
+ * @param args.seed - The mnemonic seed to derive the encryption key
80
80
  * from.
81
81
  * @param args.cryptographicFunctions - The cryptographic functions to use for
82
82
  * the client.
83
83
  * @returns The state encryption key.
84
84
  */
85
- export declare function getEncryptionEntropy({ mnemonicPhrase, snapId, cryptographicFunctions, }: GetEncryptionKeyArgs): Promise<`0x${string}`>;
85
+ export declare function getEncryptionEntropy({ seed, snapId, cryptographicFunctions, }: GetEncryptionKeyArgs): Promise<`0x${string}`>;
86
86
  /**
87
87
  * Builds the method implementation for `snap_manageState`.
88
88
  *
@@ -1 +1 @@
1
- {"version":3,"file":"manageState.d.mts","sourceRoot":"","sources":["../../src/restricted/manageState.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,2BAA2B;AACjE,OAAO,KAAK,EACV,8BAA8B,EAC9B,uBAAuB,EACvB,4BAA4B,EAC7B,wCAAwC;AACzC,OAAO,EAAE,cAAc,EAAe,wCAAwC;AAE9E,OAAO,KAAK,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,4BAA4B;AAGhF,OAAO,KAAK,EAAE,IAAI,EAAE,aAAa,EAAE,wBAAwB;AAG3D,OAAO,KAAK,EAAE,iBAAiB,EAAE,qBAAiB;AAIlD,eAAO,MAAM,qBAAqB,gCAAgC,CAAC;AAEnE,QAAA,MAAM,UAAU,qBAAqB,CAAC;AAEtC,MAAM,MAAM,sBAAsB,GAAG;IACnC;;;;OAIG;IACH,gBAAgB,EAAE,CAAC,uBAAuB,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAEtE;;OAEG;IACH,cAAc,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,KAAK,IAAI,CAAC;IAE7D;;;;OAIG;IACH,YAAY,EAAE,CACZ,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,OAAO,KACf,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC;IAEnC;;;;OAIG;IACH,eAAe,EAAE,CACf,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,EAC9B,SAAS,EAAE,OAAO,KACf,OAAO,CAAC,IAAI,CAAC,CAAC;CACpB,CAAC;AAEF,KAAK,sCAAsC,GAAG;IAC5C,cAAc,CAAC,EAAE,QAAQ,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,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 -3,7 +3,7 @@ import { rpcErrors } from "@metamask/rpc-errors";
3
3
  import { ManageStateOperation } from "@metamask/snaps-sdk";
4
4
  import { STATE_ENCRYPTION_MAGIC_VALUE } from "@metamask/snaps-utils";
5
5
  import { isObject, getJsonSize } from "@metamask/utils";
6
- import { deriveEntropy } from "../utils.mjs";
6
+ import { deriveEntropyFromSeed } from "../utils.mjs";
7
7
  // The salt used for SIP-6-based entropy derivation.
8
8
  export const STATE_ENCRYPTION_SALT = 'snap_manageState encryption';
9
9
  const methodName = 'snap_manageState';
@@ -47,15 +47,15 @@ export const STORAGE_SIZE_LIMIT = 64000000; // In bytes (64 MB)
47
47
  *
48
48
  * @param args - The encryption key args.
49
49
  * @param args.snapId - The ID of the snap to get the encryption key for.
50
- * @param args.mnemonicPhrase - The mnemonic phrase to derive the encryption key
50
+ * @param args.seed - The mnemonic seed to derive the encryption key
51
51
  * from.
52
52
  * @param args.cryptographicFunctions - The cryptographic functions to use for
53
53
  * the client.
54
54
  * @returns The state encryption key.
55
55
  */
56
- export async function getEncryptionEntropy({ mnemonicPhrase, snapId, cryptographicFunctions, }) {
57
- return await deriveEntropy({
58
- mnemonicPhrase,
56
+ export async function getEncryptionEntropy({ seed, snapId, cryptographicFunctions, }) {
57
+ return await deriveEntropyFromSeed({
58
+ seed,
59
59
  input: snapId,
60
60
  salt: STATE_ENCRYPTION_SALT,
61
61
  magic: STATE_ENCRYPTION_MAGIC_VALUE,
@@ -1 +1 @@
1
- {"version":3,"file":"manageState.mjs","sourceRoot":"","sources":["../../src/restricted/manageState.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,wCAAwC;AAC9E,OAAO,EAAE,SAAS,EAAE,6BAA6B;AAEjD,OAAO,EAAE,oBAAoB,EAAE,4BAA4B;AAC3D,OAAO,EAAE,4BAA4B,EAAE,8BAA8B;AAErE,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,wBAAwB;AAGxD,OAAO,EAAE,aAAa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C;IAED,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,MAAM,CAAC;IAElD,IACE,CAAC,SAAS;QACV,OAAO,SAAS,KAAK,QAAQ;QAC7B,CAAC,MAAM,CAAC,MAAM,CAAC,oBAAoB,CAAC,CAAC,QAAQ,CAC3C,SAAiC,CAClC,EACD,CAAC;QACD,MAAM,SAAS,CAAC,aAAa,CAAC;YAC5B,OAAO,EAAE,gDAAgD;SAC1D,CAAC,CAAC;IACL,CAAC;IAED,IAAI,SAAS,KAAK,SAAS,IAAI,OAAO,SAAS,KAAK,SAAS,EAAE,CAAC;QAC9D,MAAM,SAAS,CAAC,aAAa,CAAC;YAC5B,OAAO,EAAE,uDAAuD;SACjE,CAAC,CAAC;IACL,CAAC;IAED,IAAI,SAAS,KAAK,oBAAoB,CAAC,WAAW,EAAE,CAAC;QACnD,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;YACxB,MAAM,SAAS,CAAC,aAAa,CAAC;gBAC5B,OAAO,EAAE,WAAW,MAAM,8DAA8D;aACzF,CAAC,CAAC;QACL,CAAC;QAED,IAAI,IAAI,CAAC;QACT,IAAI,CAAC;YACH,kEAAkE;YAClE,IAAI,GAAG,WAAW,CAAC,QAAQ,CAAC,CAAC;QAC/B,CAAC;QAAC,MAAM,CAAC;YACP,MAAM,SAAS,CAAC,aAAa,CAAC;gBAC5B,OAAO,EAAE,WAAW,MAAM,iEAAiE;aAC5F,CAAC,CAAC;QACL,CAAC;QAED,IAAI,IAAI,GAAG,gBAAgB,EAAE,CAAC;YAC5B,MAAM,SAAS,CAAC,aAAa,CAAC;gBAC5B,OAAO,EAAE,WAAW,MAAM,wDACxB,gBAAgB,GAAG,OACrB,cAAc;aACf,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED,OAAO,MAA2B,CAAC;AACrC,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 { ManageStateParams, ManageStateResult } from '@metamask/snaps-sdk';\nimport { ManageStateOperation } from '@metamask/snaps-sdk';\nimport { STATE_ENCRYPTION_MAGIC_VALUE } from '@metamask/snaps-utils';\nimport type { Json, NonEmptyArray } from '@metamask/utils';\nimport { isObject, getJsonSize } from '@metamask/utils';\n\nimport type { MethodHooksObject } from '../utils';\nimport { deriveEntropy } from '../utils';\n\n// The salt used for SIP-6-based entropy derivation.\nexport const STATE_ENCRYPTION_SALT = 'snap_manageState encryption';\n\nconst methodName = 'snap_manageState';\n\nexport type ManageStateMethodHooks = {\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 * A function that clears the state of the requesting Snap.\n */\n clearSnapState: (snapId: string, encrypted: boolean) => void;\n\n /**\n * A function that gets the encrypted state of the requesting Snap.\n *\n * @returns The current state of the Snap.\n */\n getSnapState: (\n snapId: string,\n encrypted: boolean,\n ) => Promise<Record<string, Json>>;\n\n /**\n * A function that updates the state of the requesting Snap.\n *\n * @param newState - The new state of the Snap.\n */\n updateSnapState: (\n snapId: string,\n newState: Record<string, Json>,\n encrypted: boolean,\n ) => Promise<void>;\n};\n\ntype ManageStateSpecificationBuilderOptions = {\n allowedCaveats?: Readonly<NonEmptyArray<string>> | null;\n methodHooks: ManageStateMethodHooks;\n};\n\ntype ManageStateSpecification = ValidPermissionSpecification<{\n permissionType: PermissionType.RestrictedMethod;\n targetName: typeof methodName;\n methodImplementation: ReturnType<typeof getManageStateImplementation>;\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n}>;\n\n/**\n * The specification builder for the `snap_manageState` permission.\n * `snap_manageState` lets the Snap store and manage some of its state on\n * your device.\n *\n * @param options - The specification builder options.\n * @param options.allowedCaveats - The optional allowed caveats for the permission.\n * @param options.methodHooks - The RPC method hooks needed by the method implementation.\n * @returns The specification for the `snap_manageState` permission.\n */\nexport const specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.RestrictedMethod,\n ManageStateSpecificationBuilderOptions,\n ManageStateSpecification\n> = ({\n allowedCaveats = null,\n methodHooks,\n}: ManageStateSpecificationBuilderOptions) => {\n return {\n permissionType: PermissionType.RestrictedMethod,\n targetName: methodName,\n allowedCaveats,\n methodImplementation: getManageStateImplementation(methodHooks),\n subjectTypes: [SubjectType.Snap],\n };\n};\n\nconst methodHooks: MethodHooksObject<ManageStateMethodHooks> = {\n getUnlockPromise: true,\n clearSnapState: true,\n getSnapState: true,\n updateSnapState: true,\n};\n\nexport const manageStateBuilder = Object.freeze({\n targetName: methodName,\n specificationBuilder,\n methodHooks,\n} as const);\n\nexport const STORAGE_SIZE_LIMIT = 64_000_000; // In bytes (64 MB)\n\ntype GetEncryptionKeyArgs = {\n snapId: string;\n mnemonicPhrase: Uint8Array;\n cryptographicFunctions?: CryptographicFunctions | undefined;\n};\n\n/**\n * Get a deterministic encryption key to use for encrypting and decrypting the\n * state.\n *\n * This key should only be used for state encryption using `snap_manageState`.\n * To get other encryption keys, a different salt can be used.\n *\n * @param args - The encryption key args.\n * @param args.snapId - The ID of the snap to get the encryption key for.\n * @param args.mnemonicPhrase - The mnemonic phrase to derive the encryption key\n * from.\n * @param args.cryptographicFunctions - The cryptographic functions to use for\n * the client.\n * @returns The state encryption key.\n */\nexport async function getEncryptionEntropy({\n mnemonicPhrase,\n snapId,\n cryptographicFunctions,\n}: GetEncryptionKeyArgs) {\n return await deriveEntropy({\n mnemonicPhrase,\n input: snapId,\n salt: STATE_ENCRYPTION_SALT,\n magic: STATE_ENCRYPTION_MAGIC_VALUE,\n cryptographicFunctions,\n });\n}\n\n/**\n * Builds the method implementation for `snap_manageState`.\n *\n * @param hooks - The RPC method hooks.\n * @param hooks.clearSnapState - A function that clears the state stored for a\n * snap.\n * @param hooks.getSnapState - A function that fetches the persisted decrypted\n * state for a snap.\n * @param hooks.updateSnapState - A function that updates the state stored for a\n * snap.\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 * @returns The method implementation which either returns `null` for a\n * successful state update/deletion or returns the decrypted state.\n * @throws If the params are invalid.\n */\nexport function getManageStateImplementation({\n getUnlockPromise,\n clearSnapState,\n getSnapState,\n updateSnapState,\n}: ManageStateMethodHooks) {\n return async function manageState(\n options: RestrictedMethodOptions<ManageStateParams>,\n ): Promise<ManageStateResult> {\n const {\n params = {},\n method,\n context: { origin },\n } = options;\n const validatedParams = getValidatedParams(params, method);\n\n // If the encrypted param is undefined or null we default to true.\n const shouldEncrypt = validatedParams.encrypted ?? true;\n\n // We only need to prompt the user when the mnemonic is needed\n // which it isn't for the clear operation or unencrypted storage.\n if (\n shouldEncrypt &&\n validatedParams.operation !== ManageStateOperation.ClearState\n ) {\n await getUnlockPromise(true);\n }\n\n switch (validatedParams.operation) {\n case ManageStateOperation.ClearState:\n clearSnapState(origin, shouldEncrypt);\n return null;\n\n case ManageStateOperation.GetState: {\n return await getSnapState(origin, shouldEncrypt);\n }\n\n case ManageStateOperation.UpdateState: {\n await updateSnapState(origin, validatedParams.newState, shouldEncrypt);\n return null;\n }\n\n default:\n throw rpcErrors.invalidParams(\n `Invalid ${method} operation: \"${\n validatedParams.operation as string\n }\"`,\n );\n }\n };\n}\n\n/**\n * Validates the manageState method `params` and returns them cast to the correct\n * type. Throws if validation fails.\n *\n * @param params - The unvalidated params object from the method request.\n * @param method - RPC method name used for debugging errors.\n * @param storageSizeLimit - Maximum allowed size (in bytes) of a new state object.\n * @returns The validated method parameter object.\n */\nexport function getValidatedParams(\n params: unknown,\n method: string,\n storageSizeLimit = STORAGE_SIZE_LIMIT,\n): ManageStateParams {\n if (!isObject(params)) {\n throw rpcErrors.invalidParams({\n message: 'Expected params to be a single object.',\n });\n }\n\n const { operation, newState, encrypted } = params;\n\n if (\n !operation ||\n typeof operation !== 'string' ||\n !Object.values(ManageStateOperation).includes(\n operation as ManageStateOperation,\n )\n ) {\n throw rpcErrors.invalidParams({\n message: 'Must specify a valid manage state \"operation\".',\n });\n }\n\n if (encrypted !== undefined && typeof encrypted !== 'boolean') {\n throw rpcErrors.invalidParams({\n message: '\"encrypted\" parameter must be a boolean if specified.',\n });\n }\n\n if (operation === ManageStateOperation.UpdateState) {\n if (!isObject(newState)) {\n throw rpcErrors.invalidParams({\n message: `Invalid ${method} \"newState\" parameter: The new state must be a plain object.`,\n });\n }\n\n let size;\n try {\n // `getJsonSize` will throw if the state is not JSON serializable.\n size = getJsonSize(newState);\n } catch {\n throw rpcErrors.invalidParams({\n message: `Invalid ${method} \"newState\" parameter: The new state must be JSON serializable.`,\n });\n }\n\n if (size > storageSizeLimit) {\n throw rpcErrors.invalidParams({\n message: `Invalid ${method} \"newState\" parameter: The new state must not exceed ${\n storageSizeLimit / 1_000_000\n } MB in size.`,\n });\n }\n }\n\n return params as ManageStateParams;\n}\n"]}
1
+ {"version":3,"file":"manageState.mjs","sourceRoot":"","sources":["../../src/restricted/manageState.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,wCAAwC;AAC9E,OAAO,EAAE,SAAS,EAAE,6BAA6B;AAEjD,OAAO,EAAE,oBAAoB,EAAE,4BAA4B;AAC3D,OAAO,EAAE,4BAA4B,EAAE,8BAA8B;AAErE,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,wBAAwB;AAGxD,OAAO,EAAE,qBAAqB,EAAE,qBAAiB;AAEjD,oDAAoD;AACpD,MAAM,CAAC,MAAM,qBAAqB,GAAG,6BAA6B,CAAC;AAEnE,MAAM,UAAU,GAAG,kBAAkB,CAAC;AAiDtC;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAI7B,CAAC,EACH,cAAc,GAAG,IAAI,EACrB,WAAW,G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;QACD,MAAM,SAAS,CAAC,aAAa,CAAC;YAC5B,OAAO,EAAE,gDAAgD;SAC1D,CAAC,CAAC;IACL,CAAC;IAED,IAAI,SAAS,KAAK,SAAS,IAAI,OAAO,SAAS,KAAK,SAAS,EAAE,CAAC;QAC9D,MAAM,SAAS,CAAC,aAAa,CAAC;YAC5B,OAAO,EAAE,uDAAuD;SACjE,CAAC,CAAC;IACL,CAAC;IAED,IAAI,SAAS,KAAK,oBAAoB,CAAC,WAAW,EAAE,CAAC;QACnD,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;YACxB,MAAM,SAAS,CAAC,aAAa,CAAC;gBAC5B,OAAO,EAAE,WAAW,MAAM,8DAA8D;aACzF,CAAC,CAAC;QACL,CAAC;QAED,IAAI,IAAI,CAAC;QACT,IAAI,CAAC;YACH,kEAAkE;YAClE,IAAI,GAAG,WAAW,CAAC,QAAQ,CAAC,CAAC;QAC/B,CAAC;QAAC,MAAM,CAAC;YACP,MAAM,SAAS,CAAC,aAAa,CAAC;gBAC5B,OAAO,EAAE,WAAW,MAAM,iEAAiE;aAC5F,CAAC,CAAC;QACL,CAAC;QAED,IAAI,IAAI,GAAG,gBAAgB,EAAE,CAAC;YAC5B,MAAM,SAAS,CAAC,aAAa,CAAC;gBAC5B,OAAO,EAAE,WAAW,MAAM,wDACxB,gBAAgB,GAAG,OACrB,cAAc;aACf,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED,OAAO,MAA2B,CAAC;AACrC,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 { ManageStateParams, ManageStateResult } from '@metamask/snaps-sdk';\nimport { ManageStateOperation } from '@metamask/snaps-sdk';\nimport { STATE_ENCRYPTION_MAGIC_VALUE } from '@metamask/snaps-utils';\nimport type { Json, NonEmptyArray } from '@metamask/utils';\nimport { isObject, getJsonSize } from '@metamask/utils';\n\nimport type { MethodHooksObject } from '../utils';\nimport { deriveEntropyFromSeed } from '../utils';\n\n// The salt used for SIP-6-based entropy derivation.\nexport const STATE_ENCRYPTION_SALT = 'snap_manageState encryption';\n\nconst methodName = 'snap_manageState';\n\nexport type ManageStateMethodHooks = {\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 * A function that clears the state of the requesting Snap.\n */\n clearSnapState: (snapId: string, encrypted: boolean) => void;\n\n /**\n * A function that gets the encrypted state of the requesting Snap.\n *\n * @returns The current state of the Snap.\n */\n getSnapState: (\n snapId: string,\n encrypted: boolean,\n ) => Promise<Record<string, Json>>;\n\n /**\n * A function that updates the state of the requesting Snap.\n *\n * @param newState - The new state of the Snap.\n */\n updateSnapState: (\n snapId: string,\n newState: Record<string, Json>,\n encrypted: boolean,\n ) => Promise<void>;\n};\n\ntype ManageStateSpecificationBuilderOptions = {\n allowedCaveats?: Readonly<NonEmptyArray<string>> | null;\n methodHooks: ManageStateMethodHooks;\n};\n\ntype ManageStateSpecification = ValidPermissionSpecification<{\n permissionType: PermissionType.RestrictedMethod;\n targetName: typeof methodName;\n methodImplementation: ReturnType<typeof getManageStateImplementation>;\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n}>;\n\n/**\n * The specification builder for the `snap_manageState` permission.\n * `snap_manageState` lets the Snap store and manage some of its state on\n * your device.\n *\n * @param options - The specification builder options.\n * @param options.allowedCaveats - The optional allowed caveats for the permission.\n * @param options.methodHooks - The RPC method hooks needed by the method implementation.\n * @returns The specification for the `snap_manageState` permission.\n */\nexport const specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.RestrictedMethod,\n ManageStateSpecificationBuilderOptions,\n ManageStateSpecification\n> = ({\n allowedCaveats = null,\n methodHooks,\n}: ManageStateSpecificationBuilderOptions) => {\n return {\n permissionType: PermissionType.RestrictedMethod,\n targetName: methodName,\n allowedCaveats,\n methodImplementation: getManageStateImplementation(methodHooks),\n subjectTypes: [SubjectType.Snap],\n };\n};\n\nconst methodHooks: MethodHooksObject<ManageStateMethodHooks> = {\n getUnlockPromise: true,\n clearSnapState: true,\n getSnapState: true,\n updateSnapState: true,\n};\n\nexport const manageStateBuilder = Object.freeze({\n targetName: methodName,\n specificationBuilder,\n methodHooks,\n} as const);\n\nexport const STORAGE_SIZE_LIMIT = 64_000_000; // In bytes (64 MB)\n\ntype GetEncryptionKeyArgs = {\n snapId: string;\n seed: Uint8Array;\n cryptographicFunctions?: CryptographicFunctions | undefined;\n};\n\n/**\n * Get a deterministic encryption key to use for encrypting and decrypting the\n * state.\n *\n * This key should only be used for state encryption using `snap_manageState`.\n * To get other encryption keys, a different salt can be used.\n *\n * @param args - The encryption key args.\n * @param args.snapId - The ID of the snap to get the encryption key for.\n * @param args.seed - The mnemonic seed to derive the encryption key\n * from.\n * @param args.cryptographicFunctions - The cryptographic functions to use for\n * the client.\n * @returns The state encryption key.\n */\nexport async function getEncryptionEntropy({\n seed,\n snapId,\n cryptographicFunctions,\n}: GetEncryptionKeyArgs) {\n return await deriveEntropyFromSeed({\n seed,\n input: snapId,\n salt: STATE_ENCRYPTION_SALT,\n magic: STATE_ENCRYPTION_MAGIC_VALUE,\n cryptographicFunctions,\n });\n}\n\n/**\n * Builds the method implementation for `snap_manageState`.\n *\n * @param hooks - The RPC method hooks.\n * @param hooks.clearSnapState - A function that clears the state stored for a\n * snap.\n * @param hooks.getSnapState - A function that fetches the persisted decrypted\n * state for a snap.\n * @param hooks.updateSnapState - A function that updates the state stored for a\n * snap.\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 * @returns The method implementation which either returns `null` for a\n * successful state update/deletion or returns the decrypted state.\n * @throws If the params are invalid.\n */\nexport function getManageStateImplementation({\n getUnlockPromise,\n clearSnapState,\n getSnapState,\n updateSnapState,\n}: ManageStateMethodHooks) {\n return async function manageState(\n options: RestrictedMethodOptions<ManageStateParams>,\n ): Promise<ManageStateResult> {\n const {\n params = {},\n method,\n context: { origin },\n } = options;\n const validatedParams = getValidatedParams(params, method);\n\n // If the encrypted param is undefined or null we default to true.\n const shouldEncrypt = validatedParams.encrypted ?? true;\n\n // We only need to prompt the user when the mnemonic is needed\n // which it isn't for the clear operation or unencrypted storage.\n if (\n shouldEncrypt &&\n validatedParams.operation !== ManageStateOperation.ClearState\n ) {\n await getUnlockPromise(true);\n }\n\n switch (validatedParams.operation) {\n case ManageStateOperation.ClearState:\n clearSnapState(origin, shouldEncrypt);\n return null;\n\n case ManageStateOperation.GetState: {\n return await getSnapState(origin, shouldEncrypt);\n }\n\n case ManageStateOperation.UpdateState: {\n await updateSnapState(origin, validatedParams.newState, shouldEncrypt);\n return null;\n }\n\n default:\n throw rpcErrors.invalidParams(\n `Invalid ${method} operation: \"${\n validatedParams.operation as string\n }\"`,\n );\n }\n };\n}\n\n/**\n * Validates the manageState method `params` and returns them cast to the correct\n * type. Throws if validation fails.\n *\n * @param params - The unvalidated params object from the method request.\n * @param method - RPC method name used for debugging errors.\n * @param storageSizeLimit - Maximum allowed size (in bytes) of a new state object.\n * @returns The validated method parameter object.\n */\nexport function getValidatedParams(\n params: unknown,\n method: string,\n storageSizeLimit = STORAGE_SIZE_LIMIT,\n): ManageStateParams {\n if (!isObject(params)) {\n throw rpcErrors.invalidParams({\n message: 'Expected params to be a single object.',\n });\n }\n\n const { operation, newState, encrypted } = params;\n\n if (\n !operation ||\n typeof operation !== 'string' ||\n !Object.values(ManageStateOperation).includes(\n operation as ManageStateOperation,\n )\n ) {\n throw rpcErrors.invalidParams({\n message: 'Must specify a valid manage state \"operation\".',\n });\n }\n\n if (encrypted !== undefined && typeof encrypted !== 'boolean') {\n throw rpcErrors.invalidParams({\n message: '\"encrypted\" parameter must be a boolean if specified.',\n });\n }\n\n if (operation === ManageStateOperation.UpdateState) {\n if (!isObject(newState)) {\n throw rpcErrors.invalidParams({\n message: `Invalid ${method} \"newState\" parameter: The new state must be a plain object.`,\n });\n }\n\n let size;\n try {\n // `getJsonSize` will throw if the state is not JSON serializable.\n size = getJsonSize(newState);\n } catch {\n throw rpcErrors.invalidParams({\n message: `Invalid ${method} \"newState\" parameter: The new state must be JSON serializable.`,\n });\n }\n\n if (size > storageSizeLimit) {\n throw rpcErrors.invalidParams({\n message: `Invalid ${method} \"newState\" parameter: The new state must not exceed ${\n storageSizeLimit / 1_000_000\n } MB in size.`,\n });\n }\n }\n\n return params as ManageStateParams;\n}\n"]}
package/dist/utils.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getSecretRecoveryPhrase = exports.StateKeyStruct = exports.isValidStateKey = exports.getNode = exports.getPathPrefix = exports.deriveEntropy = exports.selectHooks = exports.FORBIDDEN_KEYS = void 0;
3
+ exports.getValueFromEntropySource = exports.StateKeyStruct = exports.isValidStateKey = exports.getNodeFromSeed = exports.getNodeFromMnemonic = exports.getPathPrefix = exports.deriveEntropyFromSeed = exports.selectHooks = exports.FORBIDDEN_KEYS = void 0;
4
4
  const key_tree_1 = require("@metamask/key-tree");
5
5
  const rpc_errors_1 = require("@metamask/rpc-errors");
6
6
  const superstruct_1 = require("@metamask/superstruct");
@@ -53,7 +53,7 @@ function getDerivationPathArray(hash) {
53
53
  return array;
54
54
  }
55
55
  /**
56
- * Derive entropy from the given mnemonic phrase and salt.
56
+ * Get the derivation path to use for entropy derivation.
57
57
  *
58
58
  * This is based on the reference implementation of
59
59
  * [SIP-6](https://metamask.github.io/SIPs/SIPS/sip-6).
@@ -61,34 +61,51 @@ function getDerivationPathArray(hash) {
61
61
  * @param options - The options for entropy derivation.
62
62
  * @param options.input - The input value to derive entropy from.
63
63
  * @param options.salt - An optional salt to use when deriving entropy.
64
- * @param options.mnemonicPhrase - The mnemonic phrase to use for entropy
65
- * derivation.
66
64
  * @param options.magic - A hardened BIP-32 index, which is used to derive the
67
65
  * root key from the mnemonic phrase.
68
- * @param options.cryptographicFunctions - The cryptographic functions to use
69
- * for the derivation.
70
- * @returns The derived entropy.
66
+ * @returns The derivation path to be used for entropy key derivation.
71
67
  */
72
- async function deriveEntropy({ input, salt = '', mnemonicPhrase, magic, cryptographicFunctions, }) {
68
+ function getEntropyDerivationPath({ input, salt, magic, }) {
73
69
  const inputBytes = (0, utils_1.stringToBytes)(input);
74
70
  const saltBytes = (0, utils_1.stringToBytes)(salt);
75
71
  // Get the derivation path from the snap ID.
76
72
  const hash = (0, sha3_1.keccak_256)((0, utils_1.concatBytes)([inputBytes, (0, sha3_1.keccak_256)(saltBytes)]));
77
73
  const computedDerivationPath = getDerivationPathArray(hash);
74
+ return [`bip32:${magic}`, ...computedDerivationPath];
75
+ }
76
+ /**
77
+ * Derive entropy from the given mnemonic seed and salt.
78
+ *
79
+ * This is based on the reference implementation of
80
+ * [SIP-6](https://metamask.github.io/SIPs/SIPS/sip-6).
81
+ *
82
+ * @param options - The options for entropy derivation.
83
+ * @param options.input - The input value to derive entropy from.
84
+ * @param options.salt - An optional salt to use when deriving entropy.
85
+ * @param options.seed - The mnemonic seed to use for entropy
86
+ * derivation.
87
+ * @param options.magic - A hardened BIP-32 index, which is used to derive the
88
+ * root key from the mnemonic phrase.
89
+ * @param options.cryptographicFunctions - The cryptographic functions to use
90
+ * for the derivation.
91
+ * @returns The derived entropy.
92
+ */
93
+ async function deriveEntropyFromSeed({ input, salt = '', seed, magic, cryptographicFunctions, }) {
94
+ const computedDerivationPath = getEntropyDerivationPath({
95
+ input,
96
+ salt,
97
+ magic,
98
+ });
78
99
  // Derive the private key using BIP-32.
79
- const { privateKey } = await key_tree_1.SLIP10Node.fromDerivationPath({
80
- derivationPath: [
81
- mnemonicPhrase,
82
- `bip32:${magic}`,
83
- ...computedDerivationPath,
84
- ],
100
+ const { privateKey } = await key_tree_1.SLIP10Node.fromSeed({
101
+ derivationPath: [seed, ...computedDerivationPath],
85
102
  curve: 'secp256k1',
86
103
  }, cryptographicFunctions);
87
104
  // This should never happen, but this keeps TypeScript happy.
88
105
  (0, utils_1.assert)(privateKey, 'Failed to derive the entropy.');
89
106
  return (0, utils_1.add0x)(privateKey);
90
107
  }
91
- exports.deriveEntropy = deriveEntropy;
108
+ exports.deriveEntropyFromSeed = deriveEntropyFromSeed;
92
109
  /**
93
110
  * Get the path prefix to use for key derivation in `key-tree`. This assumes the
94
111
  * following:
@@ -133,7 +150,7 @@ exports.getPathPrefix = getPathPrefix;
133
150
  * for the node.
134
151
  * @returns The `key-tree` SLIP-10 node.
135
152
  */
136
- async function getNode({ curve, secretRecoveryPhrase, path, cryptographicFunctions, }) {
153
+ async function getNodeFromMnemonic({ curve, secretRecoveryPhrase, path, cryptographicFunctions, }) {
137
154
  const prefix = getPathPrefix(curve);
138
155
  return await key_tree_1.SLIP10Node.fromDerivationPath({
139
156
  curve,
@@ -143,7 +160,34 @@ async function getNode({ curve, secretRecoveryPhrase, path, cryptographicFunctio
143
160
  ],
144
161
  }, cryptographicFunctions);
145
162
  }
146
- exports.getNode = getNode;
163
+ exports.getNodeFromMnemonic = getNodeFromMnemonic;
164
+ /**
165
+ * Get a `key-tree`-compatible node.
166
+ *
167
+ * Note: This function assumes that all the parameters have been validated
168
+ * beforehand.
169
+ *
170
+ * @param options - The derivation options.
171
+ * @param options.curve - The curve to use for derivation.
172
+ * @param options.seed - The BIP-39 to use for
173
+ * derivation.
174
+ * @param options.path - The derivation path to use as array, starting with an
175
+ * "m" as the first item.
176
+ * @param options.cryptographicFunctions - The cryptographic functions to use
177
+ * for the node.
178
+ * @returns The `key-tree` SLIP-10 node.
179
+ */
180
+ async function getNodeFromSeed({ curve, seed, path, cryptographicFunctions, }) {
181
+ const prefix = getPathPrefix(curve);
182
+ return await key_tree_1.SLIP10Node.fromSeed({
183
+ curve,
184
+ derivationPath: [
185
+ seed,
186
+ ...path.slice(1).map((index) => `${prefix}:${index}`),
187
+ ],
188
+ }, cryptographicFunctions);
189
+ }
190
+ exports.getNodeFromSeed = getNodeFromSeed;
147
191
  /**
148
192
  * Validate the key of a state object.
149
193
  *
@@ -164,16 +208,17 @@ exports.StateKeyStruct = (0, superstruct_1.refine)((0, superstruct_1.string)(),
164
208
  return true;
165
209
  });
166
210
  /**
167
- * Get the secret recovery phrase of the user. This calls the `getMnemonic` hook
168
- * and handles any errors that occur, throwing formatted JSON-RPC errors.
211
+ * Get a value using the entropy source hooks: getMnemonic or getMnemonicSeed.
212
+ * This function calls the passed hook and handles any errors that occur,
213
+ * throwing formatted JSON-RPC errors.
169
214
  *
170
- * @param getMnemonic - The `getMnemonic` hook.
215
+ * @param hook - The hook.
171
216
  * @param source - The entropy source to use.
172
217
  * @returns The secret recovery phrase.
173
218
  */
174
- async function getSecretRecoveryPhrase(getMnemonic, source) {
219
+ async function getValueFromEntropySource(hook, source) {
175
220
  try {
176
- return await getMnemonic(source);
221
+ return await hook(source);
177
222
  }
178
223
  catch (error) {
179
224
  if (error instanceof Error) {
@@ -189,5 +234,5 @@ async function getSecretRecoveryPhrase(getMnemonic, source) {
189
234
  });
190
235
  }
191
236
  }
192
- exports.getSecretRecoveryPhrase = getSecretRecoveryPhrase;
237
+ exports.getValueFromEntropySource = getValueFromEntropySource;
193
238
  //# sourceMappingURL=utils.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.cjs","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AAOA,iDAAgD;AAChD,qDAAiD;AAEjD,uDAAuD;AAEvD,2CAOyB;AACzB,6CAA6D;AAE7D,MAAM,cAAc,GAAG,UAAU,CAAC;AAErB,QAAA,cAAc,GAAG,CAAC,aAAa,EAAE,WAAW,EAAE,WAAW,CAAC,CAAC;AAWxE;;;;;;;;;;;GAWG;AACH,SAAgB,WAAW,CAIzB,KAAY,EACZ,SAAqC;IAErC,IAAI,S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EACD,sBAAsB,CACvB,CAAC;AACJ,CAAC;AApBD,0BAoBC;AAED;;;;;GAKG;AACH,SAAgB,eAAe,CAAC,GAAuB;IACrD,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;QACtB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AACzD,CAAC;AAND,0CAMC;AAEY,QAAA,cAAc,GAAG,IAAA,oBAAM,EAAC,IAAA,oBAAM,GAAE,EAAE,WAAW,EAAE,CAAC,KAAK,EAAE,EAAE;IACpE,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,EAAE,CAAC;QAC5B,OAAO,4DAA4D,CAAC;IACtE,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC,CAAC,CAAC;AAEH;;;;;;;GAOG;AACI,KAAK,UAAU,uBAAuB,CAC3C,WAAiE,EACjE,MAA2B;IAE3B,IAAI,CAAC;QACH,OAAO,MAAM,WAAW,CAAC,MAAM,CAAC,CAAC;IACnC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;YAC3B,MAAM,sBAAS,CAAC,aAAa,CAAC;gBAC5B,OAAO,EAAE,KAAK,CAAC,OAAO;aACvB,CAAC,CAAC;QACL,CAAC;QAED,MAAM,sBAAS,CAAC,QAAQ,CAAC;YACvB,OAAO,EAAE,4BAA4B;YACrC,IAAI,EAAE;gBACJ,KAAK,EAAE,KAAK,CAAC,QAAQ,EAAE;aACxB;SACF,CAAC,CAAC;IACL,CAAC;AACH,CAAC;AApBD,0DAoBC","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 { rpcErrors } from '@metamask/rpc-errors';\nimport type { MagicValue } from '@metamask/snaps-utils';\nimport { refine, string } from '@metamask/superstruct';\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\nexport const FORBIDDEN_KEYS = ['constructor', '__proto__', 'prototype'];\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\n/**\n * Validate the key of a state object.\n *\n * @param key - The key to validate.\n * @returns `true` if the key is valid, `false` otherwise.\n */\nexport function isValidStateKey(key: string | undefined) {\n if (key === undefined) {\n return true;\n }\n\n return key.split('.').every((part) => part.length > 0);\n}\n\nexport const StateKeyStruct = refine(string(), 'state key', (value) => {\n if (!isValidStateKey(value)) {\n return 'Invalid state key. Each part of the key must be non-empty.';\n }\n\n return true;\n});\n\n/**\n * Get the secret recovery phrase of the user. This calls the `getMnemonic` hook\n * and handles any errors that occur, throwing formatted JSON-RPC errors.\n *\n * @param getMnemonic - The `getMnemonic` hook.\n * @param source - The entropy source to use.\n * @returns The secret recovery phrase.\n */\nexport async function getSecretRecoveryPhrase(\n getMnemonic: (source?: string | undefined) => Promise<Uint8Array>,\n source?: string | undefined,\n): Promise<Uint8Array> {\n try {\n return await getMnemonic(source);\n } catch (error) {\n if (error instanceof Error) {\n throw rpcErrors.invalidParams({\n message: error.message,\n });\n }\n\n throw rpcErrors.internal({\n message: 'An unknown error occurred.',\n data: {\n error: error.toString(),\n },\n });\n }\n}\n"]}
1
+ {"version":3,"file":"utils.cjs","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AAOA,iDAAgD;AAChD,qDAAiD;AAEjD,uDAAuD;AACvD,2CAOyB;AACzB,6CAA6D;AAE7D,MAAM,cAAc,GAAG,UAAU,CAAC;AAErB,QAAA,cAAc,GAAG,CAAC,aAAa,EAAE,WAAW,EAAE,WAAW,CAAC,CAAC;AAWxE;;;;;;;;;;;GAWG;AACH,SAAgB,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,SAAqB,CAAC;YACvC,UAAU,CAAC,QAAQ,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAC;YACvC,OAAO,UAAU,CAAC;QACpB,CAA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K,EAAE,CAAC;YAC3B,MAAM,sBAAS,CAAC,aAAa,CAAC;gBAC5B,OAAO,EAAE,KAAK,CAAC,OAAO;aACvB,CAAC,CAAC;QACL,CAAC;QAED,MAAM,sBAAS,CAAC,QAAQ,CAAC;YACvB,OAAO,EAAE,4BAA4B;YACrC,IAAI,EAAE;gBACJ,KAAK,EAAE,KAAK,CAAC,QAAQ,EAAE;aACxB;SACF,CAAC,CAAC;IACL,CAAC;AACH,CAAC;AApBD,8DAoBC","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 { rpcErrors } from '@metamask/rpc-errors';\nimport type { MagicValue } from '@metamask/snaps-utils';\nimport { refine, string } from '@metamask/superstruct';\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\nexport const FORBIDDEN_KEYS = ['constructor', '__proto__', 'prototype'];\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 BaseDeriveEntropyOptions = {\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 * 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\ntype SeedDeriveEntropyOptions = BaseDeriveEntropyOptions & {\n /**\n * The mnemonic seed to use for entropy derivation.\n */\n seed: Uint8Array;\n};\n\n/**\n * Get the derivation path to use for entropy derivation.\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.magic - A hardened BIP-32 index, which is used to derive the\n * root key from the mnemonic phrase.\n * @returns The derivation path to be used for entropy key derivation.\n */\nfunction getEntropyDerivationPath({\n input,\n salt,\n magic,\n}: Required<Omit<BaseDeriveEntropyOptions, 'cryptographicFunctions'>>):\n | BIP32Node[]\n | SLIP10PathNode[] {\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 return [`bip32:${magic}`, ...computedDerivationPath];\n}\n\n/**\n * Derive entropy from the given mnemonic seed 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.seed - The mnemonic seed 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 deriveEntropyFromSeed({\n input,\n salt = '',\n seed,\n magic,\n cryptographicFunctions,\n}: SeedDeriveEntropyOptions) {\n const computedDerivationPath = getEntropyDerivationPath({\n input,\n salt,\n magic,\n });\n\n // Derive the private key using BIP-32.\n const { privateKey } = await SLIP10Node.fromSeed(\n {\n derivationPath: [seed, ...computedDerivationPath],\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 BaseGetNodeArgs = {\n curve: SupportedCurve;\n path: string[];\n cryptographicFunctions: CryptographicFunctions | undefined;\n};\n\ntype GetNodeArgsMnemonic = BaseGetNodeArgs & {\n secretRecoveryPhrase: Uint8Array;\n};\n\ntype GetNodeArgsSeed = BaseGetNodeArgs & {\n seed: Uint8Array;\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 getNodeFromMnemonic({\n curve,\n secretRecoveryPhrase,\n path,\n cryptographicFunctions,\n}: GetNodeArgsMnemonic) {\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\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.seed - The BIP-39 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 getNodeFromSeed({\n curve,\n seed,\n path,\n cryptographicFunctions,\n}: GetNodeArgsSeed) {\n const prefix = getPathPrefix(curve);\n\n return await SLIP10Node.fromSeed(\n {\n curve,\n derivationPath: [\n seed,\n ...(path.slice(1).map((index) => `${prefix}:${index}`) as\n | BIP32Node[]\n | SLIP10PathNode[]),\n ],\n },\n cryptographicFunctions,\n );\n}\n\n/**\n * Validate the key of a state object.\n *\n * @param key - The key to validate.\n * @returns `true` if the key is valid, `false` otherwise.\n */\nexport function isValidStateKey(key: string | undefined) {\n if (key === undefined) {\n return true;\n }\n\n return key.split('.').every((part) => part.length > 0);\n}\n\nexport const StateKeyStruct = refine(string(), 'state key', (value) => {\n if (!isValidStateKey(value)) {\n return 'Invalid state key. Each part of the key must be non-empty.';\n }\n\n return true;\n});\n\n/**\n * Get a value using the entropy source hooks: getMnemonic or getMnemonicSeed.\n * This function calls the passed hook and handles any errors that occur,\n * throwing formatted JSON-RPC errors.\n *\n * @param hook - The hook.\n * @param source - The entropy source to use.\n * @returns The secret recovery phrase.\n */\nexport async function getValueFromEntropySource(\n hook: (source?: string | undefined) => Promise<Uint8Array>,\n source?: string | undefined,\n): Promise<Uint8Array> {\n try {\n return await hook(source);\n } catch (error) {\n if (error instanceof Error) {\n throw rpcErrors.invalidParams({\n message: error.message,\n });\n }\n\n throw rpcErrors.internal({\n message: 'An unknown error occurred.',\n data: {\n error: error.toString(),\n },\n });\n }\n}\n"]}
package/dist/utils.d.cts CHANGED
@@ -1,7 +1,6 @@
1
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
- import type { Hex } from "@metamask/utils";
5
4
  export declare const FORBIDDEN_KEYS: string[];
6
5
  /**
7
6
  * Maps an interface with method hooks to an object, using the keys of the
@@ -24,7 +23,7 @@ export type MethodHooksObject<HooksType extends Record<string, unknown>> = {
24
23
  * @template HookName - The names of the hooks to select.
25
24
  */
26
25
  export declare function selectHooks<Hooks extends Record<string, unknown>, HookName extends keyof Hooks>(hooks: Hooks, hookNames?: Record<HookName, boolean>): Pick<Hooks, HookName> | undefined;
27
- type DeriveEntropyOptions = {
26
+ type BaseDeriveEntropyOptions = {
28
27
  /**
29
28
  * The input value to derive entropy from.
30
29
  */
@@ -33,10 +32,6 @@ type DeriveEntropyOptions = {
33
32
  * An optional salt to use when deriving entropy.
34
33
  */
35
34
  salt?: string;
36
- /**
37
- * The mnemonic phrase to use for entropy derivation.
38
- */
39
- mnemonicPhrase: Uint8Array;
40
35
  /**
41
36
  * A hardened BIP-32 index, which is used to derive the root key from the
42
37
  * mnemonic phrase.
@@ -47,8 +42,14 @@ type DeriveEntropyOptions = {
47
42
  */
48
43
  cryptographicFunctions: CryptographicFunctions | undefined;
49
44
  };
45
+ type SeedDeriveEntropyOptions = BaseDeriveEntropyOptions & {
46
+ /**
47
+ * The mnemonic seed to use for entropy derivation.
48
+ */
49
+ seed: Uint8Array;
50
+ };
50
51
  /**
51
- * Derive entropy from the given mnemonic phrase and salt.
52
+ * Derive entropy from the given mnemonic seed and salt.
52
53
  *
53
54
  * This is based on the reference implementation of
54
55
  * [SIP-6](https://metamask.github.io/SIPs/SIPS/sip-6).
@@ -56,7 +57,7 @@ type DeriveEntropyOptions = {
56
57
  * @param options - The options for entropy derivation.
57
58
  * @param options.input - The input value to derive entropy from.
58
59
  * @param options.salt - An optional salt to use when deriving entropy.
59
- * @param options.mnemonicPhrase - The mnemonic phrase to use for entropy
60
+ * @param options.seed - The mnemonic seed to use for entropy
60
61
  * derivation.
61
62
  * @param options.magic - A hardened BIP-32 index, which is used to derive the
62
63
  * root key from the mnemonic phrase.
@@ -64,7 +65,7 @@ type DeriveEntropyOptions = {
64
65
  * for the derivation.
65
66
  * @returns The derived entropy.
66
67
  */
67
- export declare function deriveEntropy({ input, salt, mnemonicPhrase, magic, cryptographicFunctions, }: DeriveEntropyOptions): Promise<Hex>;
68
+ export declare function deriveEntropyFromSeed({ input, salt, seed, magic, cryptographicFunctions, }: SeedDeriveEntropyOptions): Promise<`0x${string}`>;
68
69
  /**
69
70
  * Get the path prefix to use for key derivation in `key-tree`. This assumes the
70
71
  * following:
@@ -81,12 +82,17 @@ export declare function deriveEntropy({ input, salt, mnemonicPhrase, magic, cryp
81
82
  * @returns The path prefix, i.e., `bip32` or `slip10`.
82
83
  */
83
84
  export declare function getPathPrefix(curve: SupportedCurve): 'bip32' | 'slip10' | 'cip3';
84
- type GetNodeArgs = {
85
+ type BaseGetNodeArgs = {
85
86
  curve: SupportedCurve;
86
- secretRecoveryPhrase: Uint8Array;
87
87
  path: string[];
88
88
  cryptographicFunctions: CryptographicFunctions | undefined;
89
89
  };
90
+ type GetNodeArgsMnemonic = BaseGetNodeArgs & {
91
+ secretRecoveryPhrase: Uint8Array;
92
+ };
93
+ type GetNodeArgsSeed = BaseGetNodeArgs & {
94
+ seed: Uint8Array;
95
+ };
90
96
  /**
91
97
  * Get a `key-tree`-compatible node.
92
98
  *
@@ -103,7 +109,24 @@ type GetNodeArgs = {
103
109
  * for the node.
104
110
  * @returns The `key-tree` SLIP-10 node.
105
111
  */
106
- export declare function getNode({ curve, secretRecoveryPhrase, path, cryptographicFunctions, }: GetNodeArgs): Promise<SLIP10Node>;
112
+ export declare function getNodeFromMnemonic({ curve, secretRecoveryPhrase, path, cryptographicFunctions, }: GetNodeArgsMnemonic): Promise<SLIP10Node>;
113
+ /**
114
+ * Get a `key-tree`-compatible node.
115
+ *
116
+ * Note: This function assumes that all the parameters have been validated
117
+ * beforehand.
118
+ *
119
+ * @param options - The derivation options.
120
+ * @param options.curve - The curve to use for derivation.
121
+ * @param options.seed - The BIP-39 to use for
122
+ * derivation.
123
+ * @param options.path - The derivation path to use as array, starting with an
124
+ * "m" as the first item.
125
+ * @param options.cryptographicFunctions - The cryptographic functions to use
126
+ * for the node.
127
+ * @returns The `key-tree` SLIP-10 node.
128
+ */
129
+ export declare function getNodeFromSeed({ curve, seed, path, cryptographicFunctions, }: GetNodeArgsSeed): Promise<SLIP10Node>;
107
130
  /**
108
131
  * Validate the key of a state object.
109
132
  *
@@ -113,13 +136,14 @@ export declare function getNode({ curve, secretRecoveryPhrase, path, cryptograph
113
136
  export declare function isValidStateKey(key: string | undefined): boolean;
114
137
  export declare const StateKeyStruct: import("@metamask/superstruct").Struct<string, null>;
115
138
  /**
116
- * Get the secret recovery phrase of the user. This calls the `getMnemonic` hook
117
- * and handles any errors that occur, throwing formatted JSON-RPC errors.
139
+ * Get a value using the entropy source hooks: getMnemonic or getMnemonicSeed.
140
+ * This function calls the passed hook and handles any errors that occur,
141
+ * throwing formatted JSON-RPC errors.
118
142
  *
119
- * @param getMnemonic - The `getMnemonic` hook.
143
+ * @param hook - The hook.
120
144
  * @param source - The entropy source to use.
121
145
  * @returns The secret recovery phrase.
122
146
  */
123
- export declare function getSecretRecoveryPhrase(getMnemonic: (source?: string | undefined) => Promise<Uint8Array>, source?: string | undefined): Promise<Uint8Array>;
147
+ export declare function getValueFromEntropySource(hook: (source?: string | undefined) => Promise<Uint8Array>, source?: string | undefined): Promise<Uint8Array>;
124
148
  export {};
125
149
  //# 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,EACd,sBAAsB,EACvB,2BAA2B;AAC5B,OAAO,EAAE,UAAU,EAAE,2BAA2B;AAEhD,OAAO,KAAK,EAAE,UAAU,EAAE,8BAA8B;AAExD,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAa3C,eAAO,MAAM,cAAc,UAA4C,CAAC;AAExE;;;;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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ryptographicFunctions } from "@metamask/key-tree";
2
2
  import { SLIP10Node } from "@metamask/key-tree";
3
3
  import type { MagicValue } from "@metamask/snaps-utils";
4
- import type { Hex } from "@metamask/utils";
5
4
  export declare const FORBIDDEN_KEYS: string[];
6
5
  /**
7
6
  * Maps an interface with method hooks to an object, using the keys of the
@@ -24,7 +23,7 @@ export type MethodHooksObject<HooksType extends Record<string, unknown>> = {
24
23
  * @template HookName - The names of the hooks to select.
25
24
  */
26
25
  export declare function selectHooks<Hooks extends Record<string, unknown>, HookName extends keyof Hooks>(hooks: Hooks, hookNames?: Record<HookName, boolean>): Pick<Hooks, HookName> | undefined;
27
- type DeriveEntropyOptions = {
26
+ type BaseDeriveEntropyOptions = {
28
27
  /**
29
28
  * The input value to derive entropy from.
30
29
  */
@@ -33,10 +32,6 @@ type DeriveEntropyOptions = {
33
32
  * An optional salt to use when deriving entropy.
34
33
  */
35
34
  salt?: string;
36
- /**
37
- * The mnemonic phrase to use for entropy derivation.
38
- */
39
- mnemonicPhrase: Uint8Array;
40
35
  /**
41
36
  * A hardened BIP-32 index, which is used to derive the root key from the
42
37
  * mnemonic phrase.
@@ -47,8 +42,14 @@ type DeriveEntropyOptions = {
47
42
  */
48
43
  cryptographicFunctions: CryptographicFunctions | undefined;
49
44
  };
45
+ type SeedDeriveEntropyOptions = BaseDeriveEntropyOptions & {
46
+ /**
47
+ * The mnemonic seed to use for entropy derivation.
48
+ */
49
+ seed: Uint8Array;
50
+ };
50
51
  /**
51
- * Derive entropy from the given mnemonic phrase and salt.
52
+ * Derive entropy from the given mnemonic seed and salt.
52
53
  *
53
54
  * This is based on the reference implementation of
54
55
  * [SIP-6](https://metamask.github.io/SIPs/SIPS/sip-6).
@@ -56,7 +57,7 @@ type DeriveEntropyOptions = {
56
57
  * @param options - The options for entropy derivation.
57
58
  * @param options.input - The input value to derive entropy from.
58
59
  * @param options.salt - An optional salt to use when deriving entropy.
59
- * @param options.mnemonicPhrase - The mnemonic phrase to use for entropy
60
+ * @param options.seed - The mnemonic seed to use for entropy
60
61
  * derivation.
61
62
  * @param options.magic - A hardened BIP-32 index, which is used to derive the
62
63
  * root key from the mnemonic phrase.
@@ -64,7 +65,7 @@ type DeriveEntropyOptions = {
64
65
  * for the derivation.
65
66
  * @returns The derived entropy.
66
67
  */
67
- export declare function deriveEntropy({ input, salt, mnemonicPhrase, magic, cryptographicFunctions, }: DeriveEntropyOptions): Promise<Hex>;
68
+ export declare function deriveEntropyFromSeed({ input, salt, seed, magic, cryptographicFunctions, }: SeedDeriveEntropyOptions): Promise<`0x${string}`>;
68
69
  /**
69
70
  * Get the path prefix to use for key derivation in `key-tree`. This assumes the
70
71
  * following:
@@ -81,12 +82,17 @@ export declare function deriveEntropy({ input, salt, mnemonicPhrase, magic, cryp
81
82
  * @returns The path prefix, i.e., `bip32` or `slip10`.
82
83
  */
83
84
  export declare function getPathPrefix(curve: SupportedCurve): 'bip32' | 'slip10' | 'cip3';
84
- type GetNodeArgs = {
85
+ type BaseGetNodeArgs = {
85
86
  curve: SupportedCurve;
86
- secretRecoveryPhrase: Uint8Array;
87
87
  path: string[];
88
88
  cryptographicFunctions: CryptographicFunctions | undefined;
89
89
  };
90
+ type GetNodeArgsMnemonic = BaseGetNodeArgs & {
91
+ secretRecoveryPhrase: Uint8Array;
92
+ };
93
+ type GetNodeArgsSeed = BaseGetNodeArgs & {
94
+ seed: Uint8Array;
95
+ };
90
96
  /**
91
97
  * Get a `key-tree`-compatible node.
92
98
  *
@@ -103,7 +109,24 @@ type GetNodeArgs = {
103
109
  * for the node.
104
110
  * @returns The `key-tree` SLIP-10 node.
105
111
  */
106
- export declare function getNode({ curve, secretRecoveryPhrase, path, cryptographicFunctions, }: GetNodeArgs): Promise<SLIP10Node>;
112
+ export declare function getNodeFromMnemonic({ curve, secretRecoveryPhrase, path, cryptographicFunctions, }: GetNodeArgsMnemonic): Promise<SLIP10Node>;
113
+ /**
114
+ * Get a `key-tree`-compatible node.
115
+ *
116
+ * Note: This function assumes that all the parameters have been validated
117
+ * beforehand.
118
+ *
119
+ * @param options - The derivation options.
120
+ * @param options.curve - The curve to use for derivation.
121
+ * @param options.seed - The BIP-39 to use for
122
+ * derivation.
123
+ * @param options.path - The derivation path to use as array, starting with an
124
+ * "m" as the first item.
125
+ * @param options.cryptographicFunctions - The cryptographic functions to use
126
+ * for the node.
127
+ * @returns The `key-tree` SLIP-10 node.
128
+ */
129
+ export declare function getNodeFromSeed({ curve, seed, path, cryptographicFunctions, }: GetNodeArgsSeed): Promise<SLIP10Node>;
107
130
  /**
108
131
  * Validate the key of a state object.
109
132
  *
@@ -113,13 +136,14 @@ export declare function getNode({ curve, secretRecoveryPhrase, path, cryptograph
113
136
  export declare function isValidStateKey(key: string | undefined): boolean;
114
137
  export declare const StateKeyStruct: import("@metamask/superstruct").Struct<string, null>;
115
138
  /**
116
- * Get the secret recovery phrase of the user. This calls the `getMnemonic` hook
117
- * and handles any errors that occur, throwing formatted JSON-RPC errors.
139
+ * Get a value using the entropy source hooks: getMnemonic or getMnemonicSeed.
140
+ * This function calls the passed hook and handles any errors that occur,
141
+ * throwing formatted JSON-RPC errors.
118
142
  *
119
- * @param getMnemonic - The `getMnemonic` hook.
143
+ * @param hook - The hook.
120
144
  * @param source - The entropy source to use.
121
145
  * @returns The secret recovery phrase.
122
146
  */
123
- export declare function getSecretRecoveryPhrase(getMnemonic: (source?: string | undefined) => Promise<Uint8Array>, source?: string | undefined): Promise<Uint8Array>;
147
+ export declare function getValueFromEntropySource(hook: (source?: string | undefined) => Promise<Uint8Array>, source?: string | undefined): Promise<Uint8Array>;
124
148
  export {};
125
149
  //# 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,EACd,sBAAsB,EACvB,2BAA2B;AAC5B,OAAO,EAAE,UAAU,EAAE,2BAA2B;AAEhD,OAAO,KAAK,EAAE,UAAU,EA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