@metamask/snaps-rpc-methods 16.0.0 → 17.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.
- package/CHANGELOG.md +10 -2
- package/dist/restricted/getBip32Entropy.cjs +1 -1
- package/dist/restricted/getBip32Entropy.cjs.map +1 -1
- package/dist/restricted/getBip32Entropy.d.cts +3 -3
- package/dist/restricted/getBip32Entropy.d.cts.map +1 -1
- package/dist/restricted/getBip32Entropy.d.mts +3 -3
- package/dist/restricted/getBip32Entropy.d.mts.map +1 -1
- package/dist/restricted/getBip32Entropy.mjs +1 -1
- package/dist/restricted/getBip32Entropy.mjs.map +1 -1
- package/dist/restricted/getBip32PublicKey.cjs +1 -1
- package/dist/restricted/getBip32PublicKey.cjs.map +1 -1
- package/dist/restricted/getBip32PublicKey.d.cts +3 -3
- package/dist/restricted/getBip32PublicKey.d.cts.map +1 -1
- package/dist/restricted/getBip32PublicKey.d.mts +3 -3
- package/dist/restricted/getBip32PublicKey.d.mts.map +1 -1
- package/dist/restricted/getBip32PublicKey.mjs +1 -1
- package/dist/restricted/getBip32PublicKey.mjs.map +1 -1
- package/dist/restricted/getBip44Entropy.cjs +1 -1
- package/dist/restricted/getBip44Entropy.cjs.map +1 -1
- package/dist/restricted/getBip44Entropy.d.cts +3 -3
- package/dist/restricted/getBip44Entropy.d.cts.map +1 -1
- package/dist/restricted/getBip44Entropy.d.mts +3 -3
- package/dist/restricted/getBip44Entropy.d.mts.map +1 -1
- package/dist/restricted/getBip44Entropy.mjs +1 -1
- package/dist/restricted/getBip44Entropy.mjs.map +1 -1
- package/dist/restricted/getEntropy.cjs +1 -1
- package/dist/restricted/getEntropy.cjs.map +1 -1
- package/dist/restricted/getEntropy.d.cts +3 -3
- package/dist/restricted/getEntropy.d.cts.map +1 -1
- package/dist/restricted/getEntropy.d.mts +3 -3
- package/dist/restricted/getEntropy.d.mts.map +1 -1
- package/dist/restricted/getEntropy.mjs +1 -1
- package/dist/restricted/getEntropy.mjs.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +3 -3
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +3 -3
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/dist/utils.cjs +5 -5
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +4 -4
- package/dist/utils.d.cts.map +1 -1
- package/dist/utils.d.mts +4 -4
- package/dist/utils.d.mts.map +1 -1
- package/dist/utils.mjs +5 -5
- package/dist/utils.mjs.map +1 -1
- package/package.json +4 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getBip44Entropy.mjs","sourceRoot":"","sources":["../../src/restricted/getBip44Entropy.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,2BAA2B;AAQvD,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,wCAAwC;AAC9E,OAAO,EAAE,SAAS,EAAE,6BAA6B;AAKjD,OAAO,EAAE,cAAc,EAAE,8BAA8B;AAKvD,OAAO,EAAE,eAAe,EAAE,yBAAyB,EAAE,qBAAiB;AAEtE,MAAM,UAAU,GAAG,sBAAsB,CAAC;AAoC1C;;;;;;;;;;GAUG;AACH,MAAM,oBAAoB,GAItB,CAAC,EACH,WAAW,EACX,SAAS,GACkC,EAAE,EAAE;IAC/C,OAAO;QACL,cAAc,EAAE,cAAc,CAAC,gBAAgB;QAC/C,UAAU;QACV,cAAc,EAAE,CAAC,cAAc,CAAC,kBAAkB,CAAC;QACnD,oBAAoB,EAAE,6BAA6B,CAAC;YAClD,WAAW;YACX,SAAS;SACV,CAAC;QACF,SAAS,EAAE,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE;YACzB,IACE,OAAO,EAAE,MAAM,KAAK,CAAC;gBACrB,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,cAAc,CAAC,kBAAkB,EACrD,CAAC;gBACD,MAAM,SAAS,CAAC,aAAa,CAAC;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AAC;IACvB,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import type { CryptographicFunctions } from '@metamask/key-tree';\nimport { BIP44CoinTypeNode } from '@metamask/key-tree';\nimport type { Messenger } from '@metamask/messenger';\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 { KeyringControllerWithKeyringV2UnsafeAction } from '../types';\nimport type { MethodHooksObject } from '../utils';\nimport { getMnemonicSeed, getValueFromEntropySource } from '../utils';\n\nconst targetName = 'snap_getBip44Entropy';\n\nexport type GetBip44EntropyMethodHooks = {\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\nexport type GetBip44EntropyMessengerActions =\n KeyringControllerWithKeyringV2UnsafeAction;\n\ntype GetBip44EntropySpecificationBuilderOptions = {\n methodHooks: GetBip44EntropyMethodHooks;\n messenger: Messenger<string, GetBip44EntropyMessengerActions>;\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.messenger - The messenger.\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> = ({\n methodHooks,\n messenger,\n}: GetBip44EntropySpecificationBuilderOptions) => {\n return {\n permissionType: PermissionType.RestrictedMethod,\n targetName,\n allowedCaveats: [SnapCaveatType.PermittedCoinTypes],\n methodImplementation: getBip44EntropyImplementation({\n methodHooks,\n messenger,\n }),\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 getUnlockPromise: true,\n getClientCryptography: true,\n};\n\n/**\n * Enables you to [manage users' non-EVM accounts](https://docs.metamask.io/snaps/features/non-evm-networks/)\n * by deriving the [BIP-44](https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki)\n * keys specified by the `coinType` parameter. The keys are derived using the\n * entropy from the user's Secret Recovery Phrase.\n *\n * If the keys you want to derive don't conform to the BIP-44 structure, use\n * [`snap_getBip32Entropy`](https://docs.metamask.io/snaps/reference/snaps-api/snap_getbip32entropy)\n * instead.\n *\n * This method is designed to be used with the [`@metamask/key-tree`](https://npmjs.com/package/@metamask/key-tree)\n * module. `@metamask/key-tree` can help you get the [extended private keys](https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#extended-keys)\n * for user addresses, but it's your responsibility to know how to use those\n * keys to, for example, derive an address for the relevant protocol or sign a\n * transaction for the user.\n *\n * @example\n * ```json name=\"Manifest\"\n * {\n * \"initialPermissions\": {\n * \"snap_getBip44Entropy\": [\n * {\n * \"coinType\": 3\n * }\n * ]\n * }\n * }\n * ```\n * ```ts name=\"Usage\"\n * import { getBIP44AddressKeyDeriver } from '@metamask/key-tree'\n *\n * // This example uses Dogecoin, which has coin_type 3.\n * const dogecoinNode = await snap.request({\n * method: 'snap_getBip44Entropy',\n * params: {\n * coinType: 3,\n * },\n * })\n *\n * // Next, create an address key deriver function for the Dogecoin coin_type\n * // node. In this case, its path is: m/44'/3'/0'/0/address_index\n * const deriveDogecoinAddress = await getBIP44AddressKeyDeriver(dogecoinNode)\n *\n * // These are BIP-44 nodes containing the extended private keys for the\n * // respective derivation paths.\n *\n * // m/44'/3'/0'/0/0\n * const addressKey0 = await deriveDogecoinAddress(0)\n *\n * // m/44'/3'/0'/0/1\n * const addressKey1 = await deriveDogecoinAddress(1)\n * ```\n */\nexport const getBip44EntropyBuilder = Object.freeze({\n targetName,\n specificationBuilder,\n methodHooks,\n actionNames: ['KeyringController:withKeyringV2Unsafe'],\n} as const);\n\n/**\n * Builds the method implementation for `snap_getBip44Entropy`.\n *\n * @param options - The options.\n * @param options.messenger - The messenger.\n * @param options.methodHooks - The RPC method hooks.\n * @param options.methodHooks.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 options.methodHooks.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 methodHooks: { getUnlockPromise, getClientCryptography },\n messenger,\n}: GetBip44EntropySpecificationBuilderOptions) {\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.bind(null, messenger),\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"]}
|
|
@@ -65,7 +65,7 @@ exports.getEntropyBuilder = Object.freeze({
|
|
|
65
65
|
targetName,
|
|
66
66
|
specificationBuilder,
|
|
67
67
|
methodHooks,
|
|
68
|
-
actionNames: ['KeyringController:
|
|
68
|
+
actionNames: ['KeyringController:withKeyringV2Unsafe'],
|
|
69
69
|
});
|
|
70
70
|
/**
|
|
71
71
|
* Builds the method implementation for `snap_getEntropy`. The implementation
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getEntropy.cjs","sourceRoot":"","sources":["../../src/restricted/getEntropy.ts"],"names":[],"mappings":";;;AAOA,2EAA8E;AAC9E,qDAAiD;AAEjD,uDAA0D;AAE1D,uDAA0E;AAE1E,2CAA+C;AAI/C,wCAIkB;AAElB,MAAM,UAAU,GAAG,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"getEntropy.cjs","sourceRoot":"","sources":["../../src/restricted/getEntropy.ts"],"names":[],"mappings":";;;AAOA,2EAA8E;AAC9E,qDAAiD;AAEjD,uDAA0D;AAE1D,uDAA0E;AAE1E,2CAA+C;AAI/C,wCAIkB;AAElB,MAAM,UAAU,GAAG,iBAAiB,CAAC;AAkBxB,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,EACX,SAAS,GAC6B,EAAE,EAAE;IAC1C,O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,CAAC;AACJ,CAAC","sourcesContent":["import type { CryptographicFunctions } from '@metamask/key-tree';\nimport type { Messenger } from '@metamask/messenger';\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 { KeyringControllerWithKeyringV2UnsafeAction } from '../types';\nimport type { MethodHooksObject } from '../utils';\nimport {\n deriveEntropyFromSeed,\n getMnemonicSeed,\n getValueFromEntropySource,\n} from '../utils';\n\nconst targetName = 'snap_getEntropy';\n\nexport type GetEntropyMessengerActions =\n KeyringControllerWithKeyringV2UnsafeAction;\n\ntype GetEntropySpecificationBuilderOptions = {\n allowedCaveats?: Readonly<NonEmptyArray<string>> | null;\n methodHooks: GetEntropyHooks;\n messenger: Messenger<string, GetEntropyMessengerActions>;\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 messenger,\n}: GetEntropySpecificationBuilderOptions) => {\n return {\n permissionType: PermissionType.RestrictedMethod,\n targetName,\n allowedCaveats,\n methodImplementation: getEntropyImplementation({ methodHooks, messenger }),\n subjectTypes: [SubjectType.Snap],\n };\n};\n\nconst methodHooks: MethodHooksObject<GetEntropyHooks> = {\n getUnlockPromise: true,\n getClientCryptography: true,\n};\n\n/**\n * Get a deterministic 256-bit entropy value, specific to the Snap and the\n * user's account. You can use this entropy to generate a private key, or any\n * other value that requires a high level of randomness. Other Snaps can't\n * access this entropy, and it changes if the user's secret recovery phrase\n * changes.\n *\n * You can optionally specify a salt to generate different entropy for different\n * purposes. Using a salt results in entropy unrelated to the entropy generated\n * without a salt.\n *\n * This value is deterministic: it's always the same for the same Snap, user\n * account, and salt.\n *\n * @example\n * ```json name=\"Manifest\"\n * {\n * \"initialPermissions\": {\n * \"snap_getEntropy\": {}\n * }\n * }\n * ```\n * ```ts name=\"Usage\"\n * const entropy = await snap.request({\n * method: 'snap_getEntropy',\n * params: {\n * version: 1,\n * salt: 'foo', // Optional.\n * },\n * })\n *\n * // '0x...'\n * console.log(entropy)\n * ```\n */\nexport const getEntropyBuilder = Object.freeze({\n targetName,\n specificationBuilder,\n methodHooks,\n actionNames: ['KeyringController:withKeyringV2Unsafe'],\n} as const);\n\nexport type GetEntropyHooks = {\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 options - The options.\n * @param options.messenger - The messenger.\n * @param options.methodHooks - The RPC method hooks.\n * @param options.methodHooks.getUnlockPromise - The method to get a promise that resolves\n * once the extension is unlocked.\n * @param options.methodHooks.getClientCryptography - A function to retrieve the cryptographic\n * functions to use for the client.\n * @returns The method implementation.\n */\nfunction getEntropyImplementation({\n methodHooks: { getUnlockPromise, getClientCryptography },\n messenger,\n}: GetEntropySpecificationBuilderOptions) {\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\n const seed = await getValueFromEntropySource(\n getMnemonicSeed.bind(null, messenger),\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"]}
|
|
@@ -5,10 +5,10 @@ import { PermissionType } from "@metamask/permission-controller";
|
|
|
5
5
|
import type { GetEntropyParams, GetEntropyResult } from "@metamask/snaps-sdk";
|
|
6
6
|
import type { Infer } from "@metamask/superstruct";
|
|
7
7
|
import type { NonEmptyArray } from "@metamask/utils";
|
|
8
|
-
import type {
|
|
8
|
+
import type { KeyringControllerWithKeyringV2UnsafeAction } from "../types.cjs";
|
|
9
9
|
import type { MethodHooksObject } from "../utils.cjs";
|
|
10
10
|
declare const targetName = "snap_getEntropy";
|
|
11
|
-
export type GetEntropyMessengerActions =
|
|
11
|
+
export type GetEntropyMessengerActions = KeyringControllerWithKeyringV2UnsafeAction;
|
|
12
12
|
type GetEntropySpecificationBuilderOptions = {
|
|
13
13
|
allowedCaveats?: Readonly<NonEmptyArray<string>> | null;
|
|
14
14
|
methodHooks: GetEntropyHooks;
|
|
@@ -74,7 +74,7 @@ export declare const getEntropyBuilder: Readonly<{
|
|
|
74
74
|
allowedCaveats: Readonly<NonEmptyArray<string>> | null;
|
|
75
75
|
}>;
|
|
76
76
|
readonly methodHooks: MethodHooksObject<GetEntropyHooks>;
|
|
77
|
-
readonly actionNames: readonly ["KeyringController:
|
|
77
|
+
readonly actionNames: readonly ["KeyringController:withKeyringV2Unsafe"];
|
|
78
78
|
}>;
|
|
79
79
|
export type GetEntropyHooks = {
|
|
80
80
|
/**
|
|
@@ -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,EAAE,SAAS,EAAE,4BAA4B;AACrD,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,
|
|
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,EAAE,SAAS,EAAE,4BAA4B;AACrD,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,0CAA0C,EAAE,qBAAiB;AAC3E,OAAO,KAAK,EAAE,iBAAiB,EAAE,qBAAiB;AAOlD,QAAA,MAAM,UAAU,oBAAoB,CAAC;AAErC,MAAM,MAAM,0BAA0B,GACpC,0CAA0C,CAAC;AAE7C,KAAK,qCAAqC,GAAG;IAC3C,cAAc,CAAC,EAAE,QAAQ,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,GAAG,IAAI,CAAC;IACxD,WAAW,EAAE,eAAe,CAAC;IAC7B,SAAS,EAAE,SAAS,CAAC,MAAM,EAAE,0BAA0B,CAAC,CAAC;CAC1D,CAAC;AASF,eAAO,MAAM,oBAAoB;;;;;;;;EAI/B,CAAC;AAEH;;;;;GAKG;AACH,MAAM,MAAM,cAAc,GAAG,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAyBhE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,eAAO,MAAM,iBAAiB;;;wBA9EZ,eAAe,gBAAgB;oBACnC,iBAAiB;8BACP,WAAW,+BAA+B,CAAC;wBACjD,SAAS,cAAc,MAAM,CAAC,CAAC,GAAG,IAAI;;;;EAgF7C,CAAC;AAEZ,MAAM,MAAM,eAAe,GAAG;IAC5B;;;;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,WAAW,EAAE,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,EACxD,SAAS,GACV,EAAE,qCAAqC,aAE3B,wBAAwB,gBAAgB,CAAC,KACjD,QAAQ,gBAAgB,CAAC,CA4B7B"}
|
|
@@ -5,10 +5,10 @@ import { PermissionType } from "@metamask/permission-controller";
|
|
|
5
5
|
import type { GetEntropyParams, GetEntropyResult } from "@metamask/snaps-sdk";
|
|
6
6
|
import type { Infer } from "@metamask/superstruct";
|
|
7
7
|
import type { NonEmptyArray } from "@metamask/utils";
|
|
8
|
-
import type {
|
|
8
|
+
import type { KeyringControllerWithKeyringV2UnsafeAction } from "../types.mjs";
|
|
9
9
|
import type { MethodHooksObject } from "../utils.mjs";
|
|
10
10
|
declare const targetName = "snap_getEntropy";
|
|
11
|
-
export type GetEntropyMessengerActions =
|
|
11
|
+
export type GetEntropyMessengerActions = KeyringControllerWithKeyringV2UnsafeAction;
|
|
12
12
|
type GetEntropySpecificationBuilderOptions = {
|
|
13
13
|
allowedCaveats?: Readonly<NonEmptyArray<string>> | null;
|
|
14
14
|
methodHooks: GetEntropyHooks;
|
|
@@ -74,7 +74,7 @@ export declare const getEntropyBuilder: Readonly<{
|
|
|
74
74
|
allowedCaveats: Readonly<NonEmptyArray<string>> | null;
|
|
75
75
|
}>;
|
|
76
76
|
readonly methodHooks: MethodHooksObject<GetEntropyHooks>;
|
|
77
|
-
readonly actionNames: readonly ["KeyringController:
|
|
77
|
+
readonly actionNames: readonly ["KeyringController:withKeyringV2Unsafe"];
|
|
78
78
|
}>;
|
|
79
79
|
export type GetEntropyHooks = {
|
|
80
80
|
/**
|
|
@@ -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,EAAE,SAAS,EAAE,4BAA4B;AACrD,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,
|
|
1
|
+
{"version":3,"file":"getEntropy.d.mts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AAE,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,WAAW,EAAE,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,EACxD,SAAS,GACV,EAAE,qCAAqC,aAE3B,wBAAwB,gBAAgB,CAAC,KACjD,QAAQ,gBAAgB,CAAC,CA4B7B"}
|
|
@@ -62,7 +62,7 @@ export const getEntropyBuilder = Object.freeze({
|
|
|
62
62
|
targetName,
|
|
63
63
|
specificationBuilder,
|
|
64
64
|
methodHooks,
|
|
65
|
-
actionNames: ['KeyringController:
|
|
65
|
+
actionNames: ['KeyringController:withKeyringV2Unsafe'],
|
|
66
66
|
});
|
|
67
67
|
/**
|
|
68
68
|
* Builds the method implementation for `snap_getEntropy`. The implementation
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getEntropy.mjs","sourceRoot":"","sources":["../../src/restricted/getEntropy.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,wCAAwC;AAC9E,OAAO,EAAE,SAAS,EAAE,6BAA6B;AAEjD,OAAO,EAAE,iBAAiB,EAAE,8BAA8B;AAE1D,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,8BAA8B;AAE1E,OAAO,EAAE,YAAY,EAAE,wBAAwB;AAI/C,OAAO,EACL,qBAAqB,EACrB,eAAe,EACf,yBAAyB,EAC1B,qBAAiB;AAElB,MAAM,UAAU,GAAG,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"getEntropy.mjs","sourceRoot":"","sources":["../../src/restricted/getEntropy.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,wCAAwC;AAC9E,OAAO,EAAE,SAAS,EAAE,6BA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ACtC,OAAO,KAAK,UAAU,UAAU,CAC9B,OAAkD;QAElD,MAAM,EACJ,MAAM,EACN,OAAO,EAAE,EAAE,MAAM,EAAE,GACpB,GAAG,OAAO,CAAC;QAEZ,YAAY,CACV,MAAM,EACN,oBAAoB,EACpB,sCAAsC,EACtC,SAAS,CAAC,aAAa,CACxB,CAAC;QAEF,MAAM,gBAAgB,CAAC,IAAI,CAAC,CAAC;QAE7B,MAAM,IAAI,GAAG,MAAM,yBAAyB,CAC1C,eAAe,CAAC,IAAI,CAAC,IAAI,EAAE,SAAS,CAAC,EACrC,MAAM,CAAC,MAAM,CACd,CAAC;QAEF,OAAO,qBAAqB,CAAC;YAC3B,KAAK,EAAE,MAAM;YACb,IAAI,EAAE,MAAM,CAAC,IAAI;YACjB,IAAI;YACJ,KAAK,EAAE,iBAAiB;YACxB,sBAAsB,EAAE,qBAAqB,EAAE;SAChD,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import type { CryptographicFunctions } from '@metamask/key-tree';\nimport type { Messenger } from '@metamask/messenger';\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 { KeyringControllerWithKeyringV2UnsafeAction } from '../types';\nimport type { MethodHooksObject } from '../utils';\nimport {\n deriveEntropyFromSeed,\n getMnemonicSeed,\n getValueFromEntropySource,\n} from '../utils';\n\nconst targetName = 'snap_getEntropy';\n\nexport type GetEntropyMessengerActions =\n KeyringControllerWithKeyringV2UnsafeAction;\n\ntype GetEntropySpecificationBuilderOptions = {\n allowedCaveats?: Readonly<NonEmptyArray<string>> | null;\n methodHooks: GetEntropyHooks;\n messenger: Messenger<string, GetEntropyMessengerActions>;\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 messenger,\n}: GetEntropySpecificationBuilderOptions) => {\n return {\n permissionType: PermissionType.RestrictedMethod,\n targetName,\n allowedCaveats,\n methodImplementation: getEntropyImplementation({ methodHooks, messenger }),\n subjectTypes: [SubjectType.Snap],\n };\n};\n\nconst methodHooks: MethodHooksObject<GetEntropyHooks> = {\n getUnlockPromise: true,\n getClientCryptography: true,\n};\n\n/**\n * Get a deterministic 256-bit entropy value, specific to the Snap and the\n * user's account. You can use this entropy to generate a private key, or any\n * other value that requires a high level of randomness. Other Snaps can't\n * access this entropy, and it changes if the user's secret recovery phrase\n * changes.\n *\n * You can optionally specify a salt to generate different entropy for different\n * purposes. Using a salt results in entropy unrelated to the entropy generated\n * without a salt.\n *\n * This value is deterministic: it's always the same for the same Snap, user\n * account, and salt.\n *\n * @example\n * ```json name=\"Manifest\"\n * {\n * \"initialPermissions\": {\n * \"snap_getEntropy\": {}\n * }\n * }\n * ```\n * ```ts name=\"Usage\"\n * const entropy = await snap.request({\n * method: 'snap_getEntropy',\n * params: {\n * version: 1,\n * salt: 'foo', // Optional.\n * },\n * })\n *\n * // '0x...'\n * console.log(entropy)\n * ```\n */\nexport const getEntropyBuilder = Object.freeze({\n targetName,\n specificationBuilder,\n methodHooks,\n actionNames: ['KeyringController:withKeyringV2Unsafe'],\n} as const);\n\nexport type GetEntropyHooks = {\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 options - The options.\n * @param options.messenger - The messenger.\n * @param options.methodHooks - The RPC method hooks.\n * @param options.methodHooks.getUnlockPromise - The method to get a promise that resolves\n * once the extension is unlocked.\n * @param options.methodHooks.getClientCryptography - A function to retrieve the cryptographic\n * functions to use for the client.\n * @returns The method implementation.\n */\nfunction getEntropyImplementation({\n methodHooks: { getUnlockPromise, getClientCryptography },\n messenger,\n}: GetEntropySpecificationBuilderOptions) {\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\n const seed = await getValueFromEntropySource(\n getMnemonicSeed.bind(null, messenger),\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"]}
|
package/dist/types.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n AuxiliaryFileEncoding,\n BackgroundEvent,\n ComponentOrElement,\n GetSnapsResult,\n GetWebSocketsResult,\n InterfaceContext,\n InterfaceState,\n RequestSnapsResult,\n ContentType,\n RequestSnapsParams,\n SnapId,\n} from '@metamask/snaps-sdk';\nimport type {\n Snap,\n SnapRpcHookArgs,\n TruncatedSnap,\n} from '@metamask/snaps-utils';\nimport type { Json, JsonRpcParams, JsonRpcRequest } from '@metamask/utils';\n\nexport type JsonRpcRequestWithOrigin<\n Params extends JsonRpcParams = JsonRpcParams,\n> = JsonRpcRequest<Params> & { origin: string };\n\nexport type HdKeyring = {\n type: '
|
|
1
|
+
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n AuxiliaryFileEncoding,\n BackgroundEvent,\n ComponentOrElement,\n GetSnapsResult,\n GetWebSocketsResult,\n InterfaceContext,\n InterfaceState,\n RequestSnapsResult,\n ContentType,\n RequestSnapsParams,\n SnapId,\n} from '@metamask/snaps-sdk';\nimport type {\n Snap,\n SnapRpcHookArgs,\n TruncatedSnap,\n} from '@metamask/snaps-utils';\nimport type { Json, JsonRpcParams, JsonRpcRequest } from '@metamask/utils';\n\nexport type JsonRpcRequestWithOrigin<\n Params extends JsonRpcParams = JsonRpcParams,\n> = JsonRpcRequest<Params> & { origin: string };\n\nexport type HdKeyring = {\n type: 'hd';\n seed?: Uint8Array;\n mnemonic?: Uint8Array;\n};\n\nexport type KeyringControllerWithKeyringV2UnsafeAction = {\n type: 'KeyringController:withKeyringV2Unsafe';\n handler: (\n selector:\n | {\n type: string;\n index?: number;\n }\n | { id: string },\n operation: (args: { keyring: HdKeyring }) => Promise<unknown>,\n ) => Promise<unknown>;\n};\n\nexport type KeyringControllerGetStateAction = {\n type: `KeyringController:getState`;\n handler: () => {\n isUnlocked: boolean;\n keyrings: {\n type: string;\n metadata: { id: string; name: string };\n }[];\n };\n};\n\nexport type ApprovalControllerAddRequestAction = {\n type: 'ApprovalController:addRequest';\n handler: (\n opts: {\n id?: string;\n origin: string;\n type: string;\n requestData?: Record<string, unknown>;\n requestState?: Record<string, Json>;\n },\n shouldShowRequest: boolean,\n ) => Promise<Json>;\n};\n\nexport type SnapInterfaceControllerCreateInterfaceAction = {\n type: 'SnapInterfaceController:createInterface';\n handler: (\n snapId: string,\n content: ComponentOrElement,\n context?: InterfaceContext,\n contentType?: ContentType,\n ) => string;\n};\n\nexport type SnapInterfaceControllerGetInterfaceAction = {\n type: 'SnapInterfaceController:getInterface';\n handler: (\n snapId: string,\n id: string,\n ) => {\n content: ComponentOrElement;\n snapId: SnapId;\n state: InterfaceState;\n context: InterfaceContext | null;\n };\n};\n\nexport type SnapInterfaceControllerSetInterfaceDisplayedAction = {\n type: 'SnapInterfaceController:setInterfaceDisplayed';\n handler: (snapId: string, id: string) => void;\n};\n\nexport type SnapInterfaceControllerGetInterfaceStateAction = {\n type: `SnapInterfaceController:getInterfaceState`;\n handler: (snapId: string, id: string) => InterfaceState;\n};\n\nexport type SnapInterfaceControllerUpdateInterfaceAction = {\n type: `SnapInterfaceController:updateInterface`;\n handler: (\n snapId: string,\n id: string,\n content: ComponentOrElement,\n context?: InterfaceContext,\n ) => void;\n};\n\nexport type SnapInterfaceControllerResolveInterfaceAction = {\n type: `SnapInterfaceController:resolveInterface`;\n handler: (snapId: string, id: string, value: Json) => Promise<void>;\n};\n\nexport type SnapControllerHandleRequestAction = {\n type: 'SnapController:handleRequest';\n handler: (args: SnapRpcHookArgs & { snapId: string }) => Promise<unknown>;\n};\n\nexport type SnapControllerGetSnapAction = {\n type: 'SnapController:getSnap';\n handler: (snapId: string) => Snap | null;\n};\n\nexport type SnapControllerClearSnapStateAction = {\n type: 'SnapController:clearSnapState';\n handler: (snapId: string, encrypted: boolean) => void;\n};\n\nexport type SnapControllerGetSnapStateAction = {\n type: 'SnapController:getSnapState';\n handler: (\n snapId: string,\n encrypted: boolean,\n ) => Promise<Record<string, Json> | null>;\n};\n\nexport type SnapControllerUpdateSnapStateAction = {\n type: 'SnapController:updateSnapState';\n handler: (\n snapId: string,\n newState: Record<string, Json>,\n encrypted: boolean,\n ) => Promise<void>;\n};\n\nexport type SnapControllerGetAllSnapsAction = {\n type: `SnapController:getAllSnaps`;\n handler: () => TruncatedSnap[];\n};\n\nexport type SnapControllerGetPermittedSnapsAction = {\n type: `SnapController:getPermittedSnaps`;\n handler: (origin: string) => GetSnapsResult;\n};\n\nexport type SnapControllerInstallSnapsAction = {\n type: `SnapController:installSnaps`;\n handler: (\n origin: string,\n requestedSnaps: RequestSnapsParams,\n ) => Promise<RequestSnapsResult>;\n};\n\nexport type SnapControllerGetSnapFileAction = {\n type: `SnapController:getSnapFile`;\n handler: (\n snapId: string,\n path: string,\n encoding?: AuxiliaryFileEncoding,\n ) => Promise<string | null>;\n};\n\nexport type RateLimitControllerCallAction = {\n type: 'RateLimitController:call';\n handler: (\n origin: string,\n type: string,\n ...args: unknown[]\n ) => Promise<unknown>;\n};\n\nexport type CronjobControllerCancelAction = {\n type: `CronjobController:cancel`;\n handler: (origin: string, id: string) => void;\n};\n\nexport type CronjobControllerScheduleAction = {\n type: `CronjobController:schedule`;\n handler: (event: {\n snapId: string;\n request: {\n method: string;\n jsonrpc?: '2.0';\n id?: string | number | null;\n params?: Json[] | Record<string, Json>;\n };\n schedule: string;\n id?: string;\n }) => string;\n};\n\nexport type CronjobControllerGetAction = {\n type: `CronjobController:get`;\n handler: (snapId: string) => BackgroundEvent[];\n};\n\nexport type WebSocketServiceOpenAction = {\n type: `WebSocketService:open`;\n handler: (\n snapId: string,\n url: string,\n protocols?: string[],\n ) => Promise<string>;\n};\n\nexport type WebSocketServiceCloseAction = {\n type: `WebSocketService:close`;\n handler: (snapId: string, id: string) => void;\n};\n\nexport type WebSocketServiceSendMessageAction = {\n type: `WebSocketService:sendMessage`;\n handler: (\n snapId: string,\n id: string,\n data: string | number[],\n ) => Promise<void>;\n};\n\nexport type WebSocketServiceGetAllAction = {\n type: `WebSocketService:getAll`;\n handler: (snapId: string) => GetWebSocketsResult;\n};\n"]}
|
package/dist/types.d.cts
CHANGED
|
@@ -5,12 +5,12 @@ export type JsonRpcRequestWithOrigin<Params extends JsonRpcParams = JsonRpcParam
|
|
|
5
5
|
origin: string;
|
|
6
6
|
};
|
|
7
7
|
export type HdKeyring = {
|
|
8
|
-
type: '
|
|
8
|
+
type: 'hd';
|
|
9
9
|
seed?: Uint8Array;
|
|
10
10
|
mnemonic?: Uint8Array;
|
|
11
11
|
};
|
|
12
|
-
export type
|
|
13
|
-
type: 'KeyringController:
|
|
12
|
+
export type KeyringControllerWithKeyringV2UnsafeAction = {
|
|
13
|
+
type: 'KeyringController:withKeyringV2Unsafe';
|
|
14
14
|
handler: (selector: {
|
|
15
15
|
type: string;
|
|
16
16
|
index?: number;
|
package/dist/types.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,qBAAqB,EACrB,eAAe,EACf,kBAAkB,EAClB,cAAc,EACd,mBAAmB,EACnB,gBAAgB,EAChB,cAAc,EACd,kBAAkB,EAClB,WAAW,EACX,kBAAkB,EAClB,MAAM,EACP,4BAA4B;AAC7B,OAAO,KAAK,EACV,IAAI,EACJ,eAAe,EACf,aAAa,EACd,8BAA8B;AAC/B,OAAO,KAAK,EAAE,IAAI,EAAE,aAAa,EAAE,cAAc,EAAE,wBAAwB;AAE3E,MAAM,MAAM,wBAAwB,CAClC,MAAM,SAAS,aAAa,GAAG,aAAa,IAC1C,cAAc,CAAC,MAAM,CAAC,GAAG;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAEhD,MAAM,MAAM,SAAS,GAAG;IACtB,IAAI,EAAE,
|
|
1
|
+
{"version":3,"file":"types.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AO,CAAC,IAAI,CAAC,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,4BAA4B,GAAG;IACzC,IAAI,EAAE,yBAAyB,CAAC;IAChC,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,mBAAmB,CAAC;CAClD,CAAC"}
|
package/dist/types.d.mts
CHANGED
|
@@ -5,12 +5,12 @@ export type JsonRpcRequestWithOrigin<Params extends JsonRpcParams = JsonRpcParam
|
|
|
5
5
|
origin: string;
|
|
6
6
|
};
|
|
7
7
|
export type HdKeyring = {
|
|
8
|
-
type: '
|
|
8
|
+
type: 'hd';
|
|
9
9
|
seed?: Uint8Array;
|
|
10
10
|
mnemonic?: Uint8Array;
|
|
11
11
|
};
|
|
12
|
-
export type
|
|
13
|
-
type: 'KeyringController:
|
|
12
|
+
export type KeyringControllerWithKeyringV2UnsafeAction = {
|
|
13
|
+
type: 'KeyringController:withKeyringV2Unsafe';
|
|
14
14
|
handler: (selector: {
|
|
15
15
|
type: string;
|
|
16
16
|
index?: number;
|
package/dist/types.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,qBAAqB,EACrB,eAAe,EACf,kBAAkB,EAClB,cAAc,EACd,mBAAmB,EACnB,gBAAgB,EAChB,cAAc,EACd,kBAAkB,EAClB,WAAW,EACX,kBAAkB,EAClB,MAAM,EACP,4BAA4B;AAC7B,OAAO,KAAK,EACV,IAAI,EACJ,eAAe,EACf,aAAa,EACd,8BAA8B;AAC/B,OAAO,KAAK,EAAE,IAAI,EAAE,aAAa,EAAE,cAAc,EAAE,wBAAwB;AAE3E,MAAM,MAAM,wBAAwB,CAClC,MAAM,SAAS,aAAa,GAAG,aAAa,IAC1C,cAAc,CAAC,MAAM,CAAC,GAAG;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAEhD,MAAM,MAAM,SAAS,GAAG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V,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,KACpB,OAAO,CAAC,IAAI,CAAC,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,4BAA4B,GAAG;IACzC,IAAI,EAAE,yBAAyB,CAAC;IAChC,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,mBAAmB,CAAC;CAClD,CAAC"}
|
package/dist/types.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n AuxiliaryFileEncoding,\n BackgroundEvent,\n ComponentOrElement,\n GetSnapsResult,\n GetWebSocketsResult,\n InterfaceContext,\n InterfaceState,\n RequestSnapsResult,\n ContentType,\n RequestSnapsParams,\n SnapId,\n} from '@metamask/snaps-sdk';\nimport type {\n Snap,\n SnapRpcHookArgs,\n TruncatedSnap,\n} from '@metamask/snaps-utils';\nimport type { Json, JsonRpcParams, JsonRpcRequest } from '@metamask/utils';\n\nexport type JsonRpcRequestWithOrigin<\n Params extends JsonRpcParams = JsonRpcParams,\n> = JsonRpcRequest<Params> & { origin: string };\n\nexport type HdKeyring = {\n type: '
|
|
1
|
+
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n AuxiliaryFileEncoding,\n BackgroundEvent,\n ComponentOrElement,\n GetSnapsResult,\n GetWebSocketsResult,\n InterfaceContext,\n InterfaceState,\n RequestSnapsResult,\n ContentType,\n RequestSnapsParams,\n SnapId,\n} from '@metamask/snaps-sdk';\nimport type {\n Snap,\n SnapRpcHookArgs,\n TruncatedSnap,\n} from '@metamask/snaps-utils';\nimport type { Json, JsonRpcParams, JsonRpcRequest } from '@metamask/utils';\n\nexport type JsonRpcRequestWithOrigin<\n Params extends JsonRpcParams = JsonRpcParams,\n> = JsonRpcRequest<Params> & { origin: string };\n\nexport type HdKeyring = {\n type: 'hd';\n seed?: Uint8Array;\n mnemonic?: Uint8Array;\n};\n\nexport type KeyringControllerWithKeyringV2UnsafeAction = {\n type: 'KeyringController:withKeyringV2Unsafe';\n handler: (\n selector:\n | {\n type: string;\n index?: number;\n }\n | { id: string },\n operation: (args: { keyring: HdKeyring }) => Promise<unknown>,\n ) => Promise<unknown>;\n};\n\nexport type KeyringControllerGetStateAction = {\n type: `KeyringController:getState`;\n handler: () => {\n isUnlocked: boolean;\n keyrings: {\n type: string;\n metadata: { id: string; name: string };\n }[];\n };\n};\n\nexport type ApprovalControllerAddRequestAction = {\n type: 'ApprovalController:addRequest';\n handler: (\n opts: {\n id?: string;\n origin: string;\n type: string;\n requestData?: Record<string, unknown>;\n requestState?: Record<string, Json>;\n },\n shouldShowRequest: boolean,\n ) => Promise<Json>;\n};\n\nexport type SnapInterfaceControllerCreateInterfaceAction = {\n type: 'SnapInterfaceController:createInterface';\n handler: (\n snapId: string,\n content: ComponentOrElement,\n context?: InterfaceContext,\n contentType?: ContentType,\n ) => string;\n};\n\nexport type SnapInterfaceControllerGetInterfaceAction = {\n type: 'SnapInterfaceController:getInterface';\n handler: (\n snapId: string,\n id: string,\n ) => {\n content: ComponentOrElement;\n snapId: SnapId;\n state: InterfaceState;\n context: InterfaceContext | null;\n };\n};\n\nexport type SnapInterfaceControllerSetInterfaceDisplayedAction = {\n type: 'SnapInterfaceController:setInterfaceDisplayed';\n handler: (snapId: string, id: string) => void;\n};\n\nexport type SnapInterfaceControllerGetInterfaceStateAction = {\n type: `SnapInterfaceController:getInterfaceState`;\n handler: (snapId: string, id: string) => InterfaceState;\n};\n\nexport type SnapInterfaceControllerUpdateInterfaceAction = {\n type: `SnapInterfaceController:updateInterface`;\n handler: (\n snapId: string,\n id: string,\n content: ComponentOrElement,\n context?: InterfaceContext,\n ) => void;\n};\n\nexport type SnapInterfaceControllerResolveInterfaceAction = {\n type: `SnapInterfaceController:resolveInterface`;\n handler: (snapId: string, id: string, value: Json) => Promise<void>;\n};\n\nexport type SnapControllerHandleRequestAction = {\n type: 'SnapController:handleRequest';\n handler: (args: SnapRpcHookArgs & { snapId: string }) => Promise<unknown>;\n};\n\nexport type SnapControllerGetSnapAction = {\n type: 'SnapController:getSnap';\n handler: (snapId: string) => Snap | null;\n};\n\nexport type SnapControllerClearSnapStateAction = {\n type: 'SnapController:clearSnapState';\n handler: (snapId: string, encrypted: boolean) => void;\n};\n\nexport type SnapControllerGetSnapStateAction = {\n type: 'SnapController:getSnapState';\n handler: (\n snapId: string,\n encrypted: boolean,\n ) => Promise<Record<string, Json> | null>;\n};\n\nexport type SnapControllerUpdateSnapStateAction = {\n type: 'SnapController:updateSnapState';\n handler: (\n snapId: string,\n newState: Record<string, Json>,\n encrypted: boolean,\n ) => Promise<void>;\n};\n\nexport type SnapControllerGetAllSnapsAction = {\n type: `SnapController:getAllSnaps`;\n handler: () => TruncatedSnap[];\n};\n\nexport type SnapControllerGetPermittedSnapsAction = {\n type: `SnapController:getPermittedSnaps`;\n handler: (origin: string) => GetSnapsResult;\n};\n\nexport type SnapControllerInstallSnapsAction = {\n type: `SnapController:installSnaps`;\n handler: (\n origin: string,\n requestedSnaps: RequestSnapsParams,\n ) => Promise<RequestSnapsResult>;\n};\n\nexport type SnapControllerGetSnapFileAction = {\n type: `SnapController:getSnapFile`;\n handler: (\n snapId: string,\n path: string,\n encoding?: AuxiliaryFileEncoding,\n ) => Promise<string | null>;\n};\n\nexport type RateLimitControllerCallAction = {\n type: 'RateLimitController:call';\n handler: (\n origin: string,\n type: string,\n ...args: unknown[]\n ) => Promise<unknown>;\n};\n\nexport type CronjobControllerCancelAction = {\n type: `CronjobController:cancel`;\n handler: (origin: string, id: string) => void;\n};\n\nexport type CronjobControllerScheduleAction = {\n type: `CronjobController:schedule`;\n handler: (event: {\n snapId: string;\n request: {\n method: string;\n jsonrpc?: '2.0';\n id?: string | number | null;\n params?: Json[] | Record<string, Json>;\n };\n schedule: string;\n id?: string;\n }) => string;\n};\n\nexport type CronjobControllerGetAction = {\n type: `CronjobController:get`;\n handler: (snapId: string) => BackgroundEvent[];\n};\n\nexport type WebSocketServiceOpenAction = {\n type: `WebSocketService:open`;\n handler: (\n snapId: string,\n url: string,\n protocols?: string[],\n ) => Promise<string>;\n};\n\nexport type WebSocketServiceCloseAction = {\n type: `WebSocketService:close`;\n handler: (snapId: string, id: string) => void;\n};\n\nexport type WebSocketServiceSendMessageAction = {\n type: `WebSocketService:sendMessage`;\n handler: (\n snapId: string,\n id: string,\n data: string | number[],\n ) => Promise<void>;\n};\n\nexport type WebSocketServiceGetAllAction = {\n type: `WebSocketService:getAll`;\n handler: (snapId: string) => GetWebSocketsResult;\n};\n"]}
|
package/dist/utils.cjs
CHANGED
|
@@ -225,7 +225,7 @@ exports.UI_PERMISSIONS = [
|
|
|
225
225
|
endowments_1.SnapEndowments.TransactionInsight,
|
|
226
226
|
endowments_1.SnapEndowments.SignatureInsight,
|
|
227
227
|
];
|
|
228
|
-
exports.HD_KEYRING = '
|
|
228
|
+
exports.HD_KEYRING = 'hd';
|
|
229
229
|
/**
|
|
230
230
|
* Get the mnemonic for a given entropy source. If no source is
|
|
231
231
|
* provided, the primary HD keyring's mnemonic will be returned.
|
|
@@ -236,7 +236,7 @@ exports.HD_KEYRING = 'HD Key Tree';
|
|
|
236
236
|
*/
|
|
237
237
|
async function getMnemonic(messenger, source) {
|
|
238
238
|
if (!source) {
|
|
239
|
-
const mnemonic = (await messenger.call('KeyringController:
|
|
239
|
+
const mnemonic = (await messenger.call('KeyringController:withKeyringV2Unsafe', {
|
|
240
240
|
type: exports.HD_KEYRING,
|
|
241
241
|
index: 0,
|
|
242
242
|
}, async ({ keyring }) => keyring.mnemonic));
|
|
@@ -246,7 +246,7 @@ async function getMnemonic(messenger, source) {
|
|
|
246
246
|
return mnemonic;
|
|
247
247
|
}
|
|
248
248
|
try {
|
|
249
|
-
const keyringData = await messenger.call('KeyringController:
|
|
249
|
+
const keyringData = await messenger.call('KeyringController:withKeyringV2Unsafe', {
|
|
250
250
|
id: source,
|
|
251
251
|
}, async ({ keyring }) => ({
|
|
252
252
|
type: keyring.type,
|
|
@@ -274,7 +274,7 @@ exports.getMnemonic = getMnemonic;
|
|
|
274
274
|
*/
|
|
275
275
|
async function getMnemonicSeed(messenger, source) {
|
|
276
276
|
if (!source) {
|
|
277
|
-
const seed = (await messenger.call('KeyringController:
|
|
277
|
+
const seed = (await messenger.call('KeyringController:withKeyringV2Unsafe', {
|
|
278
278
|
type: exports.HD_KEYRING,
|
|
279
279
|
index: 0,
|
|
280
280
|
}, async ({ keyring }) => keyring.seed));
|
|
@@ -284,7 +284,7 @@ async function getMnemonicSeed(messenger, source) {
|
|
|
284
284
|
return seed;
|
|
285
285
|
}
|
|
286
286
|
try {
|
|
287
|
-
const keyringData = await messenger.call('KeyringController:
|
|
287
|
+
const keyringData = await messenger.call('KeyringController:withKeyringV2Unsafe', {
|
|
288
288
|
id: source,
|
|
289
289
|
}, async ({ keyring }) => ({
|
|
290
290
|
type: keyring.type,
|
package/dist/utils.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.cjs","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AAOA,iDAAgD;AAEhD,qDAAiD;AAEjD,uDAAuD;AACvD,2CAOyB;AACzB,6CAA6D;AAE7D,uDAA8C;AAG9C,MAAM,cAAc,GAAG,UAAU,CAAC;AAErB,QAAA,cAAc,GAAG,CAAC,aAAa,EAAE,WAAW,EAAE,WAAW,CAAC,CAAC;AAWxE;;;;;;GAMG;AACH,SAAS,sBAAsB,CAAC,IAAgB;IAC9C,MAAM,KAAK,GAAwB,EAAE,CAAC;IACtC,MAAM,IAAI,GAAG,IAAA,sBAAc,EAAC,IAAI,CAAC,CAAC;IAElC,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC;QACvC,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,GAAG,CAAC,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,CACnC,SAAgE,EAChE,MAA2B;IAE3B,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,GAAG,CAAC,MAAM,SAAS,CAAC,IAAI,CAChC,+BAA+B,EAC/B;YACE,IAAI,EAAE,kBAAU;YAChB,KAAK,EAAE,CAAC;SACT,EACD,KAAK,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CACpC,CAAsB,CAAC;QAExB,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;QAC3D,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI,CAAC;QACH,MAAM,WAAW,GAAG,MAAM,SAAS,CAAC,IAAI,CACtC,+BAA+B,EAC/B;YACE,EAAE,EAAE,MAAM;SACX,EACD,KAAK,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,CAAC;YACtB,IAAI,EAAE,OAAO,CAAC,IAAI;YAClB,IAAI,EAAE,OAAO,CAAC,IAAI;SACnB,CAAC,CACH,CAAC;QAEF,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,WAAkD,CAAC;QAE1E,yDAAyD;QACzD,6DAA6D;QAC7D,sCAAsC;QACtC,IAAA,cAAM,EAAC,IAAI,KAAK,kBAAU,IAAI,IAAI,CAAC,CAAC;QAEpC,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,KAAK,CAAC,2BAA2B,MAAM,cAAc,CAAC,CAAC;IACnE,CAAC;AACH,CAAC;AA5CD,0CA4CC","sourcesContent":["import type {\n HardenedBIP32Node,\n BIP32Node,\n SLIP10PathNode,\n SupportedCurve,\n CryptographicFunctions,\n} from '@metamask/key-tree';\nimport { SLIP10Node } from '@metamask/key-tree';\nimport type { Messenger } from '@metamask/messenger';\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\nimport { SnapEndowments } from './endowments';\nimport type { KeyringControllerWithKeyringAction } from './types';\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 * 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\n/**\n * The permissions that allow a Snap to show UI. Snaps must have at least one\n * of these permissions to use the interface management RPC methods.\n */\nexport const UI_PERMISSIONS = [\n 'snap_dialog',\n 'snap_notify',\n SnapEndowments.HomePage,\n SnapEndowments.SettingsPage,\n SnapEndowments.TransactionInsight,\n SnapEndowments.SignatureInsight,\n] as const;\n\nexport const HD_KEYRING = 'HD Key Tree';\n\n/**\n * Get the mnemonic for a given entropy source. If no source is\n * provided, the primary HD keyring's mnemonic will be returned.\n *\n * @param messenger - The messenger.\n * @param source - The ID of the entropy source keyring.\n * @returns The mnemonic.\n */\nexport async function getMnemonic(\n messenger: Messenger<string, KeyringControllerWithKeyringAction>,\n source?: string | undefined,\n): Promise<Uint8Array> {\n if (!source) {\n const mnemonic = (await messenger.call(\n 'KeyringController:withKeyring',\n {\n type: HD_KEYRING,\n index: 0,\n },\n async ({ keyring }) => keyring.mnemonic,\n )) as Uint8Array | null;\n\n if (!mnemonic) {\n throw new Error('Primary keyring mnemonic unavailable.');\n }\n\n return mnemonic;\n }\n\n try {\n const keyringData = await messenger.call(\n 'KeyringController:withKeyring',\n {\n id: source,\n },\n async ({ keyring }) => ({\n type: keyring.type,\n mnemonic: keyring.mnemonic,\n }),\n );\n\n const { type, mnemonic } = keyringData as {\n type: string;\n mnemonic?: Uint8Array;\n };\n\n // The keyring isn't guaranteed to have a mnemonic (e.g.,\n // hardware wallets, which can't be used as entropy sources),\n // so we throw an error if it doesn't.\n assert(type === HD_KEYRING && mnemonic);\n\n return mnemonic;\n } catch {\n throw new Error(`Entropy source with ID \"${source}\" not found.`);\n }\n}\n\n/**\n * Get the mnemonic seed for a given entropy source. If no source is\n * provided, the primary HD keyring's mnemonic seed will be returned.\n *\n * @param messenger - The messenger.\n * @param source - The ID of the entropy source keyring.\n * @returns The mnemonic seed.\n */\nexport async function getMnemonicSeed(\n messenger: Messenger<string, KeyringControllerWithKeyringAction>,\n source?: string | undefined,\n): Promise<Uint8Array> {\n if (!source) {\n const seed = (await messenger.call(\n 'KeyringController:withKeyring',\n {\n type: HD_KEYRING,\n index: 0,\n },\n async ({ keyring }) => keyring.seed,\n )) as Uint8Array | null;\n\n if (!seed) {\n throw new Error('Primary keyring mnemonic unavailable.');\n }\n\n return seed;\n }\n\n try {\n const keyringData = await messenger.call(\n 'KeyringController:withKeyring',\n {\n id: source,\n },\n async ({ keyring }) => ({\n type: keyring.type,\n seed: keyring.seed,\n }),\n );\n\n const { type, seed } = keyringData as { type: string; seed?: Uint8Array };\n\n // The keyring isn't guaranteed to have a mnemonic (e.g.,\n // hardware wallets, which can't be used as entropy sources),\n // so we throw an error if it doesn't.\n assert(type === HD_KEYRING && seed);\n\n return seed;\n } catch {\n throw new Error(`Entropy source with ID \"${source}\" not found.`);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"utils.cjs","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AAOA,iDAAgD;AAEhD,qDAAiD;AAEjD,uDAAuD;AACvD,2CAOyB;AACzB,6CAA6D;AAE7D,uDAA8C;AAG9C,MAAM,cAAc,GAAG,UAAU,CAAC;AAErB,QAAA,cAAc,GAAG,CAAC,aAAa,EAAE,WAAW,EAAE,WAAW,CAAC,CAAC;AAWxE;;;;;;GAMG;AACH,SAAS,sBAAsB,CAAC,IAAgB;IAC9C,MAAM,KAAK,GAAwB,EAAE,CAAC;IACtC,MAAM,IAAI,GAAG,IAAA,sBAAc,EAAC,IAAI,CAAC,CAAC;IAElC,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC;QACvC,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;QAEzC,2EAA2E;QAC3E,0EAA0E;QAC1E,mCAAmC;QACnC,sCAAsC;QACtC,MAAM,SAAS,GAAG,CAAC,MAAM,GAAG,cAAc,CAAC,KAAK,CAAC,CAAC;QAClD,KAAK,CAAC,IAAI,CAAC,SAAS,SAAS,GAAG,cAAc,GAAY,CAAC,CAAC;IAC9D,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAgCD;;;;;;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AC;QAExB,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;QAC3D,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI,CAAC;QACH,MAAM,WAAW,GAAG,MAAM,SAAS,CAAC,IAAI,CACtC,uCAAuC,EACvC;YACE,EAAE,EAAE,MAAM;SACX,EACD,KAAK,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,CAAC;YACtB,IAAI,EAAE,OAAO,CAAC,IAAI;YAClB,IAAI,EAAE,OAAO,CAAC,IAAI;SACnB,CAAC,CACH,CAAC;QAEF,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,WAAkD,CAAC;QAE1E,yDAAyD;QACzD,6DAA6D;QAC7D,sCAAsC;QACtC,IAAA,cAAM,EAAC,IAAI,KAAK,kBAAU,IAAI,IAAI,CAAC,CAAC;QAEpC,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,KAAK,CAAC,2BAA2B,MAAM,cAAc,CAAC,CAAC;IACnE,CAAC;AACH,CAAC;AA5CD,0CA4CC","sourcesContent":["import type {\n HardenedBIP32Node,\n BIP32Node,\n SLIP10PathNode,\n SupportedCurve,\n CryptographicFunctions,\n} from '@metamask/key-tree';\nimport { SLIP10Node } from '@metamask/key-tree';\nimport type { Messenger } from '@metamask/messenger';\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\nimport { SnapEndowments } from './endowments';\nimport type { KeyringControllerWithKeyringV2UnsafeAction } from './types';\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 * 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\n/**\n * The permissions that allow a Snap to show UI. Snaps must have at least one\n * of these permissions to use the interface management RPC methods.\n */\nexport const UI_PERMISSIONS = [\n 'snap_dialog',\n 'snap_notify',\n SnapEndowments.HomePage,\n SnapEndowments.SettingsPage,\n SnapEndowments.TransactionInsight,\n SnapEndowments.SignatureInsight,\n] as const;\n\nexport const HD_KEYRING = 'hd';\n\n/**\n * Get the mnemonic for a given entropy source. If no source is\n * provided, the primary HD keyring's mnemonic will be returned.\n *\n * @param messenger - The messenger.\n * @param source - The ID of the entropy source keyring.\n * @returns The mnemonic.\n */\nexport async function getMnemonic(\n messenger: Messenger<string, KeyringControllerWithKeyringV2UnsafeAction>,\n source?: string | undefined,\n): Promise<Uint8Array> {\n if (!source) {\n const mnemonic = (await messenger.call(\n 'KeyringController:withKeyringV2Unsafe',\n {\n type: HD_KEYRING,\n index: 0,\n },\n async ({ keyring }) => keyring.mnemonic,\n )) as Uint8Array | null;\n\n if (!mnemonic) {\n throw new Error('Primary keyring mnemonic unavailable.');\n }\n\n return mnemonic;\n }\n\n try {\n const keyringData = await messenger.call(\n 'KeyringController:withKeyringV2Unsafe',\n {\n id: source,\n },\n async ({ keyring }) => ({\n type: keyring.type,\n mnemonic: keyring.mnemonic,\n }),\n );\n\n const { type, mnemonic } = keyringData as {\n type: string;\n mnemonic?: Uint8Array;\n };\n\n // The keyring isn't guaranteed to have a mnemonic (e.g.,\n // hardware wallets, which can't be used as entropy sources),\n // so we throw an error if it doesn't.\n assert(type === HD_KEYRING && mnemonic);\n\n return mnemonic;\n } catch {\n throw new Error(`Entropy source with ID \"${source}\" not found.`);\n }\n}\n\n/**\n * Get the mnemonic seed for a given entropy source. If no source is\n * provided, the primary HD keyring's mnemonic seed will be returned.\n *\n * @param messenger - The messenger.\n * @param source - The ID of the entropy source keyring.\n * @returns The mnemonic seed.\n */\nexport async function getMnemonicSeed(\n messenger: Messenger<string, KeyringControllerWithKeyringV2UnsafeAction>,\n source?: string | undefined,\n): Promise<Uint8Array> {\n if (!source) {\n const seed = (await messenger.call(\n 'KeyringController:withKeyringV2Unsafe',\n {\n type: HD_KEYRING,\n index: 0,\n },\n async ({ keyring }) => keyring.seed,\n )) as Uint8Array | null;\n\n if (!seed) {\n throw new Error('Primary keyring mnemonic unavailable.');\n }\n\n return seed;\n }\n\n try {\n const keyringData = await messenger.call(\n 'KeyringController:withKeyringV2Unsafe',\n {\n id: source,\n },\n async ({ keyring }) => ({\n type: keyring.type,\n seed: keyring.seed,\n }),\n );\n\n const { type, seed } = keyringData as { type: string; seed?: Uint8Array };\n\n // The keyring isn't guaranteed to have a mnemonic (e.g.,\n // hardware wallets, which can't be used as entropy sources),\n // so we throw an error if it doesn't.\n assert(type === HD_KEYRING && seed);\n\n return seed;\n } catch {\n throw new Error(`Entropy source with ID \"${source}\" not found.`);\n }\n}\n"]}
|
package/dist/utils.d.cts
CHANGED
|
@@ -3,7 +3,7 @@ import { SLIP10Node } from "@metamask/key-tree";
|
|
|
3
3
|
import type { Messenger } from "@metamask/messenger";
|
|
4
4
|
import type { MagicValue } from "@metamask/snaps-utils";
|
|
5
5
|
import { SnapEndowments } from "./endowments/index.cjs";
|
|
6
|
-
import type {
|
|
6
|
+
import type { KeyringControllerWithKeyringV2UnsafeAction } from "./types.cjs";
|
|
7
7
|
export declare const FORBIDDEN_KEYS: string[];
|
|
8
8
|
/**
|
|
9
9
|
* Maps an interface with method hooks to an object, using the keys of the
|
|
@@ -140,7 +140,7 @@ export declare function getValueFromEntropySource(hook: (source?: string | undef
|
|
|
140
140
|
* of these permissions to use the interface management RPC methods.
|
|
141
141
|
*/
|
|
142
142
|
export declare const UI_PERMISSIONS: readonly ["snap_dialog", "snap_notify", SnapEndowments.HomePage, SnapEndowments.SettingsPage, SnapEndowments.TransactionInsight, SnapEndowments.SignatureInsight];
|
|
143
|
-
export declare const HD_KEYRING = "
|
|
143
|
+
export declare const HD_KEYRING = "hd";
|
|
144
144
|
/**
|
|
145
145
|
* Get the mnemonic for a given entropy source. If no source is
|
|
146
146
|
* provided, the primary HD keyring's mnemonic will be returned.
|
|
@@ -149,7 +149,7 @@ export declare const HD_KEYRING = "HD Key Tree";
|
|
|
149
149
|
* @param source - The ID of the entropy source keyring.
|
|
150
150
|
* @returns The mnemonic.
|
|
151
151
|
*/
|
|
152
|
-
export declare function getMnemonic(messenger: Messenger<string,
|
|
152
|
+
export declare function getMnemonic(messenger: Messenger<string, KeyringControllerWithKeyringV2UnsafeAction>, source?: string | undefined): Promise<Uint8Array>;
|
|
153
153
|
/**
|
|
154
154
|
* Get the mnemonic seed for a given entropy source. If no source is
|
|
155
155
|
* provided, the primary HD keyring's mnemonic seed will be returned.
|
|
@@ -158,6 +158,6 @@ export declare function getMnemonic(messenger: Messenger<string, KeyringControll
|
|
|
158
158
|
* @param source - The ID of the entropy source keyring.
|
|
159
159
|
* @returns The mnemonic seed.
|
|
160
160
|
*/
|
|
161
|
-
export declare function getMnemonicSeed(messenger: Messenger<string,
|
|
161
|
+
export declare function getMnemonicSeed(messenger: Messenger<string, KeyringControllerWithKeyringV2UnsafeAction>, source?: string | undefined): Promise<Uint8Array>;
|
|
162
162
|
export {};
|
|
163
163
|
//# sourceMappingURL=utils.d.cts.map
|
package/dist/utils.d.cts.map
CHANGED
|
@@ -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;AAChD,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AAErD,OAAO,KAAK,EAAE,UAAU,EAAE,8BAA8B;AAYxD,OAAO,EAAE,cAAc,EAAE,+BAAqB;AAC9C,OAAO,KAAK,EAAE,
|
|
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;AAChD,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AAErD,OAAO,KAAK,EAAE,UAAU,EAAE,8BAA8B;AAYxD,OAAO,EAAE,cAAc,EAAE,+BAAqB;AAC9C,OAAO,KAAK,EAAE,0CAA0C,EAAE,oBAAgB;AAI1E,eAAO,MAAM,cAAc,UAA4C,CAAC;AAExE;;;;GAIG;AACH,MAAM,MAAM,iBAAiB,CAAC,SAAS,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI;KAC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