@metamask/snaps-rpc-methods 11.11.0 → 11.13.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 +23 -1
- package/dist/endowments/caveats/requestTime.cjs +1 -2
- package/dist/endowments/caveats/requestTime.cjs.map +1 -1
- package/dist/endowments/caveats/requestTime.mjs +1 -2
- package/dist/endowments/caveats/requestTime.mjs.map +1 -1
- package/dist/endowments/rpc.cjs.map +1 -1
- package/dist/endowments/rpc.d.cts.map +1 -1
- package/dist/endowments/rpc.d.mts.map +1 -1
- package/dist/endowments/rpc.mjs.map +1 -1
- package/dist/permitted/getState.cjs.map +1 -1
- package/dist/permitted/getState.d.cts +1 -1
- package/dist/permitted/getState.d.cts.map +1 -1
- package/dist/permitted/getState.d.mts +1 -1
- package/dist/permitted/getState.d.mts.map +1 -1
- package/dist/permitted/getState.mjs.map +1 -1
- package/dist/permitted/handlers.cjs +2 -0
- package/dist/permitted/handlers.cjs.map +1 -1
- package/dist/permitted/handlers.d.cts +2 -1
- package/dist/permitted/handlers.d.cts.map +1 -1
- package/dist/permitted/handlers.d.mts +2 -1
- package/dist/permitted/handlers.d.mts.map +1 -1
- package/dist/permitted/handlers.mjs +2 -0
- package/dist/permitted/handlers.mjs.map +1 -1
- package/dist/permitted/index.cjs.map +1 -1
- package/dist/permitted/index.d.cts +2 -1
- package/dist/permitted/index.d.cts.map +1 -1
- package/dist/permitted/index.d.mts +2 -1
- package/dist/permitted/index.d.mts.map +1 -1
- package/dist/permitted/index.mjs.map +1 -1
- package/dist/permitted/invokeKeyring.cjs.map +1 -1
- package/dist/permitted/invokeKeyring.d.cts.map +1 -1
- package/dist/permitted/invokeKeyring.d.mts.map +1 -1
- package/dist/permitted/invokeKeyring.mjs.map +1 -1
- package/dist/permitted/listEntropySources.cjs +50 -0
- package/dist/permitted/listEntropySources.cjs.map +1 -0
- package/dist/permitted/listEntropySources.d.cts +19 -0
- package/dist/permitted/listEntropySources.d.cts.map +1 -0
- package/dist/permitted/listEntropySources.d.mts +19 -0
- package/dist/permitted/listEntropySources.d.mts.map +1 -0
- package/dist/permitted/listEntropySources.mjs +47 -0
- package/dist/permitted/listEntropySources.mjs.map +1 -0
- package/dist/permitted/middleware.cjs +1 -1
- package/dist/permitted/middleware.cjs.map +1 -1
- package/dist/permitted/middleware.mjs +1 -1
- package/dist/permitted/middleware.mjs.map +1 -1
- package/dist/permitted/resolveInterface.cjs.map +1 -1
- package/dist/permitted/resolveInterface.d.cts +1 -1
- package/dist/permitted/resolveInterface.d.cts.map +1 -1
- package/dist/permitted/resolveInterface.d.mts +1 -1
- package/dist/permitted/resolveInterface.d.mts.map +1 -1
- package/dist/permitted/resolveInterface.mjs.map +1 -1
- package/dist/permitted/scheduleBackgroundEvent.cjs.map +1 -1
- package/dist/permitted/scheduleBackgroundEvent.d.cts +1 -2
- package/dist/permitted/scheduleBackgroundEvent.d.cts.map +1 -1
- package/dist/permitted/scheduleBackgroundEvent.d.mts +1 -2
- package/dist/permitted/scheduleBackgroundEvent.d.mts.map +1 -1
- package/dist/permitted/scheduleBackgroundEvent.mjs.map +1 -1
- package/dist/permitted/setState.cjs +1 -3
- package/dist/permitted/setState.cjs.map +1 -1
- package/dist/permitted/setState.d.cts +1 -1
- package/dist/permitted/setState.d.cts.map +1 -1
- package/dist/permitted/setState.d.mts +1 -1
- package/dist/permitted/setState.d.mts.map +1 -1
- package/dist/permitted/setState.mjs +1 -3
- package/dist/permitted/setState.mjs.map +1 -1
- package/dist/restricted/caveats/index.cjs +3 -3
- package/dist/restricted/caveats/index.cjs.map +1 -1
- package/dist/restricted/caveats/index.mjs +3 -3
- package/dist/restricted/caveats/index.mjs.map +1 -1
- package/dist/restricted/caveats/permittedCoinTypes.cjs +7 -0
- package/dist/restricted/caveats/permittedCoinTypes.cjs.map +1 -1
- package/dist/restricted/caveats/permittedCoinTypes.d.cts.map +1 -1
- package/dist/restricted/caveats/permittedCoinTypes.d.mts.map +1 -1
- package/dist/restricted/caveats/permittedCoinTypes.mjs +7 -0
- package/dist/restricted/caveats/permittedCoinTypes.mjs.map +1 -1
- package/dist/restricted/getBip32Entropy.cjs +2 -1
- package/dist/restricted/getBip32Entropy.cjs.map +1 -1
- package/dist/restricted/getBip32Entropy.d.cts +7 -2
- package/dist/restricted/getBip32Entropy.d.cts.map +1 -1
- package/dist/restricted/getBip32Entropy.d.mts +7 -2
- package/dist/restricted/getBip32Entropy.d.mts.map +1 -1
- package/dist/restricted/getBip32Entropy.mjs +3 -2
- package/dist/restricted/getBip32Entropy.mjs.map +1 -1
- package/dist/restricted/getBip32PublicKey.cjs +3 -1
- package/dist/restricted/getBip32PublicKey.cjs.map +1 -1
- package/dist/restricted/getBip32PublicKey.d.cts +9 -2
- package/dist/restricted/getBip32PublicKey.d.cts.map +1 -1
- package/dist/restricted/getBip32PublicKey.d.mts +9 -2
- package/dist/restricted/getBip32PublicKey.d.mts.map +1 -1
- package/dist/restricted/getBip32PublicKey.mjs +5 -3
- package/dist/restricted/getBip32PublicKey.mjs.map +1 -1
- package/dist/restricted/getBip44Entropy.cjs +3 -1
- package/dist/restricted/getBip44Entropy.cjs.map +1 -1
- package/dist/restricted/getBip44Entropy.d.cts +7 -2
- package/dist/restricted/getBip44Entropy.d.cts.map +1 -1
- package/dist/restricted/getBip44Entropy.d.mts +7 -2
- package/dist/restricted/getBip44Entropy.d.mts.map +1 -1
- package/dist/restricted/getBip44Entropy.mjs +3 -1
- package/dist/restricted/getBip44Entropy.mjs.map +1 -1
- package/dist/restricted/getEntropy.cjs +2 -1
- package/dist/restricted/getEntropy.cjs.map +1 -1
- package/dist/restricted/getEntropy.d.cts +9 -2
- package/dist/restricted/getEntropy.d.cts.map +1 -1
- package/dist/restricted/getEntropy.d.mts +9 -2
- package/dist/restricted/getEntropy.d.mts.map +1 -1
- package/dist/restricted/getEntropy.mjs +3 -2
- package/dist/restricted/getEntropy.mjs.map +1 -1
- package/dist/restricted/index.d.cts +2 -2
- package/dist/restricted/index.d.mts +2 -2
- package/dist/restricted/notify.cjs.map +1 -1
- package/dist/restricted/notify.d.cts +4 -14
- package/dist/restricted/notify.d.cts.map +1 -1
- package/dist/restricted/notify.d.mts +4 -14
- package/dist/restricted/notify.d.mts.map +1 -1
- package/dist/restricted/notify.mjs.map +1 -1
- package/dist/utils.cjs +29 -1
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +9 -0
- package/dist/utils.d.cts.map +1 -1
- package/dist/utils.d.mts +9 -0
- package/dist/utils.d.mts.map +1 -1
- package/dist/utils.mjs +27 -0
- package/dist/utils.mjs.map +1 -1
- package/package.json +10 -24
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { PermissionType, SubjectType } from "@metamask/permission-controller";
|
|
2
2
|
import { rpcErrors } from "@metamask/rpc-errors";
|
|
3
3
|
import { bip32entropy, Bip32PathStruct, CurveStruct, SnapCaveatType } from "@metamask/snaps-utils";
|
|
4
|
-
import { boolean, object, optional } from "@metamask/superstruct";
|
|
4
|
+
import { boolean, object, optional, string } from "@metamask/superstruct";
|
|
5
5
|
import { assertStruct } from "@metamask/utils";
|
|
6
|
-
import { getNode } from "../utils.mjs";
|
|
6
|
+
import { getSecretRecoveryPhrase, getNode } from "../utils.mjs";
|
|
7
7
|
const targetName = 'snap_getBip32PublicKey';
|
|
8
8
|
export const Bip32PublicKeyArgsStruct = bip32entropy(object({
|
|
9
9
|
path: Bip32PathStruct,
|
|
10
10
|
curve: CurveStruct,
|
|
11
11
|
compressed: optional(boolean()),
|
|
12
|
+
source: optional(string()),
|
|
12
13
|
}));
|
|
13
14
|
/**
|
|
14
15
|
* The specification builder for the `snap_getBip32PublicKey` permission.
|
|
@@ -63,10 +64,11 @@ export function getBip32PublicKeyImplementation({ getMnemonic, getUnlockPromise,
|
|
|
63
64
|
await getUnlockPromise(true);
|
|
64
65
|
assertStruct(args.params, Bip32PublicKeyArgsStruct, 'Invalid BIP-32 public key params', rpcErrors.invalidParams);
|
|
65
66
|
const { params } = args;
|
|
67
|
+
const secretRecoveryPhrase = await getSecretRecoveryPhrase(getMnemonic, params.source);
|
|
66
68
|
const node = await getNode({
|
|
67
69
|
curve: params.curve,
|
|
68
70
|
path: params.path,
|
|
69
|
-
secretRecoveryPhrase
|
|
71
|
+
secretRecoveryPhrase,
|
|
70
72
|
cryptographicFunctions: getClientCryptography(),
|
|
71
73
|
});
|
|
72
74
|
if (params.compressed) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getBip32PublicKey.mjs","sourceRoot":"","sources":["../../src/restricted/getBip32PublicKey.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,wCAAwC;AAC9E,OAAO,EAAE,SAAS,EAAE,6BAA6B;AAKjD,OAAO,EACL,YAAY,EACZ,eAAe,EACf,WAAW,EACX,cAAc,EACf,8BAA8B;AAC/B,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,8BAA8B;
|
|
1
|
+
{"version":3,"file":"getBip32PublicKey.mjs","sourceRoot":"","sources":["../../src/restricted/getBip32PublicKey.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,wCAAwC;AAC9E,OAAO,EAAE,SAAS,EAAE,6BAA6B;AAKjD,OAAO,EACL,YAAY,EACZ,eAAe,EACf,WAAW,EACX,cAAc,EACf,8BAA8B;AAC/B,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,8BAA8B;AAE1E,OAAO,EAAE,YAAY,EAAE,wBAAwB;AAG/C,OAAO,EAAE,uBAAuB,EAAE,OAAO,EAAE,qBAAiB;AAE5D,MAAM,UAAU,GAAG,wBAAwB,CAAC;AA0C5C,MAAM,CAAC,MAAM,wBAAwB,GAAG,YAAY,CAClD,MAAM,CAAC;IACL,IAAI,EAAE,eAAe;IACrB,KAAK,EAAE,WAAW;IAClB,UAAU,EAAE,QAAQ,CAAC,OAAO,EAA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B,CAAC;QAEF,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;QACxB,MAAM,oBAAoB,GAAG,MAAM,uBAAuB,CACxD,WAAW,EACX,MAAM,CAAC,MAAM,CACd,CAAC;QAEF,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC;YACzB,KAAK,EAAE,MAAM,CAAC,KAAK;YACnB,IAAI,EAAE,MAAM,CAAC,IAAI;YACjB,oBAAoB;YACpB,sBAAsB,EAAE,qBAAqB,EAAE;SAChD,CAAC,CAAC;QAEH,IAAI,MAAM,CAAC,UAAU,EAAE,CAAC;YACtB,OAAO,IAAI,CAAC,mBAAmB,CAAC;QAClC,CAAC;QAED,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import type { CryptographicFunctions } from '@metamask/key-tree';\nimport type {\n PermissionSpecificationBuilder,\n PermissionValidatorConstraint,\n RestrictedMethodOptions,\n ValidPermissionSpecification,\n} from '@metamask/permission-controller';\nimport { PermissionType, SubjectType } from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type {\n GetBip32PublicKeyParams,\n GetBip32PublicKeyResult,\n} from '@metamask/snaps-sdk';\nimport {\n bip32entropy,\n Bip32PathStruct,\n CurveStruct,\n SnapCaveatType,\n} from '@metamask/snaps-utils';\nimport { boolean, object, optional, string } from '@metamask/superstruct';\nimport type { NonEmptyArray } from '@metamask/utils';\nimport { assertStruct } from '@metamask/utils';\n\nimport type { MethodHooksObject } from '../utils';\nimport { getSecretRecoveryPhrase, getNode } from '../utils';\n\nconst targetName = 'snap_getBip32PublicKey';\n\nexport type GetBip32PublicKeyMethodHooks = {\n /**\n * Get the mnemonic of the provided source. If no source is provided, the\n * mnemonic of the primary keyring will be returned.\n *\n * @param source - The optional ID of the source to get the mnemonic of.\n * @returns The mnemonic of the provided source, or the default source if no\n * source is provided.\n */\n getMnemonic: (source?: string | undefined) => Promise<Uint8Array>;\n\n /**\n * Waits for the extension to be unlocked.\n *\n * @returns A promise that resolves once the extension is unlocked.\n */\n getUnlockPromise: (shouldShowUnlockRequest: boolean) => Promise<void>;\n\n /**\n * Get the cryptographic functions to use for the client. This may return an\n * empty object or `undefined` to fall back to the default cryptographic\n * functions.\n *\n * @returns The cryptographic functions to use for the client.\n */\n getClientCryptography: () => CryptographicFunctions | undefined;\n};\n\ntype GetBip32PublicKeySpecificationBuilderOptions = {\n methodHooks: GetBip32PublicKeyMethodHooks;\n};\n\ntype GetBip32PublicKeySpecification = ValidPermissionSpecification<{\n permissionType: PermissionType.RestrictedMethod;\n targetName: typeof targetName;\n methodImplementation: ReturnType<typeof getBip32PublicKeyImplementation>;\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n validator: PermissionValidatorConstraint;\n}>;\n\nexport const Bip32PublicKeyArgsStruct = bip32entropy(\n object({\n path: Bip32PathStruct,\n curve: CurveStruct,\n compressed: optional(boolean()),\n source: optional(string()),\n }),\n);\n\n/**\n * The specification builder for the `snap_getBip32PublicKey` permission.\n * `snap_getBip32PublicKey` lets the Snap retrieve public keys for a particular\n * BIP-32 node.\n *\n * @param options - The specification builder options.\n * @param options.methodHooks - The RPC method hooks needed by the method implementation.\n * @returns The specification for the `snap_getBip32PublicKey` permission.\n */\nconst specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.RestrictedMethod,\n GetBip32PublicKeySpecificationBuilderOptions,\n GetBip32PublicKeySpecification\n> = ({ methodHooks }: GetBip32PublicKeySpecificationBuilderOptions) => {\n return {\n permissionType: PermissionType.RestrictedMethod,\n targetName,\n allowedCaveats: [SnapCaveatType.PermittedDerivationPaths],\n methodImplementation: getBip32PublicKeyImplementation(methodHooks),\n validator: ({ caveats }) => {\n if (\n caveats?.length !== 1 ||\n caveats[0].type !== SnapCaveatType.PermittedDerivationPaths\n ) {\n throw rpcErrors.invalidParams({\n message: `Expected a single \"${SnapCaveatType.PermittedDerivationPaths}\" caveat.`,\n });\n }\n },\n subjectTypes: [SubjectType.Snap],\n };\n};\n\nconst methodHooks: MethodHooksObject<GetBip32PublicKeyMethodHooks> = {\n getMnemonic: true,\n getUnlockPromise: true,\n getClientCryptography: true,\n};\n\nexport const getBip32PublicKeyBuilder = Object.freeze({\n targetName,\n specificationBuilder,\n methodHooks,\n} as const);\n\n/**\n * Builds the method implementation for `snap_getBip32PublicKey`.\n *\n * @param hooks - The RPC method hooks.\n * @param hooks.getMnemonic - A function to retrieve the Secret Recovery Phrase of the user.\n * @param hooks.getUnlockPromise - A function that resolves once the MetaMask extension is unlocked\n * and prompts the user to unlock their MetaMask if it is locked.\n * @param hooks.getClientCryptography - A function to retrieve the cryptographic\n * functions to use for the client.\n * @returns The method implementation which returns a public key.\n * @throws If the params are invalid.\n */\nexport function getBip32PublicKeyImplementation({\n getMnemonic,\n getUnlockPromise,\n getClientCryptography,\n}: GetBip32PublicKeyMethodHooks) {\n return async function getBip32PublicKey(\n args: RestrictedMethodOptions<GetBip32PublicKeyParams>,\n ): Promise<GetBip32PublicKeyResult> {\n await getUnlockPromise(true);\n\n assertStruct(\n args.params,\n Bip32PublicKeyArgsStruct,\n 'Invalid BIP-32 public key params',\n rpcErrors.invalidParams,\n );\n\n const { params } = args;\n const secretRecoveryPhrase = await getSecretRecoveryPhrase(\n getMnemonic,\n params.source,\n );\n\n const node = await getNode({\n curve: params.curve,\n path: params.path,\n secretRecoveryPhrase,\n cryptographicFunctions: getClientCryptography(),\n });\n\n if (params.compressed) {\n return node.compressedPublicKey;\n }\n\n return node.publicKey;\n };\n}\n"]}
|
|
@@ -5,6 +5,7 @@ const key_tree_1 = require("@metamask/key-tree");
|
|
|
5
5
|
const permission_controller_1 = require("@metamask/permission-controller");
|
|
6
6
|
const rpc_errors_1 = require("@metamask/rpc-errors");
|
|
7
7
|
const snaps_utils_1 = require("@metamask/snaps-utils");
|
|
8
|
+
const utils_1 = require("../utils.cjs");
|
|
8
9
|
const targetName = 'snap_getBip44Entropy';
|
|
9
10
|
/**
|
|
10
11
|
* The specification builder for the `snap_getBip44Entropy` permission.
|
|
@@ -62,7 +63,8 @@ function getBip44EntropyImplementation({ getMnemonic, getUnlockPromise, getClien
|
|
|
62
63
|
await getUnlockPromise(true);
|
|
63
64
|
// `args.params` is validated by the decorator, so it's safe to assert here.
|
|
64
65
|
const params = args.params;
|
|
65
|
-
const
|
|
66
|
+
const secretRecoveryPhrase = await (0, utils_1.getSecretRecoveryPhrase)(getMnemonic, params.source);
|
|
67
|
+
const node = await key_tree_1.BIP44CoinTypeNode.fromDerivationPath([secretRecoveryPhrase, `bip32:44'`, `bip32:${params.coinType}'`], 'mainnet', getClientCryptography());
|
|
66
68
|
return node.toJSON();
|
|
67
69
|
};
|
|
68
70
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getBip44Entropy.cjs","sourceRoot":"","sources":["../../src/restricted/getBip44Entropy.ts"],"names":[],"mappings":";;;AACA,iDAAuD;AAOvD,2EAA8E;AAC9E,qDAAiD;AAKjD,uDAAuD;
|
|
1
|
+
{"version":3,"file":"getBip44Entropy.cjs","sourceRoot":"","sources":["../../src/restricted/getBip44Entropy.ts"],"names":[],"mappings":";;;AACA,iDAAuD;AAOvD,2EAA8E;AAC9E,qDAAiD;AAKjD,uDAAuD;AAIvD,wCAAmD;AAEnD,MAAM,UAAU,GAAG,sBAAsB,CAAC;AA0C1C;;;;;;;;;GASG;AACH,MAAM,oBAAoB,GAItB,CAAC,EAAE,WAAW,EAA8C,EAAE,EAAE;IAClE,OAAO;QACL,cAAc,EAAE,sCAAc,CAAC,gBAAgB;QAC/C,UAAU;QACV,cAAc,EAAE,CAAC,4BAAc,CAAC,kBAAkB,CAAC;QACnD,oBAAoB,EAAE,6BAA6B,CAAC,WAAW,CAAC;QAChE,SAAS,EAAE,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE;YACzB,IACE,OAAO,EAAE,MAAM,KAAK,CAAC;gBACrB,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,4BAAc,CAAC,kBAAkB,EACrD,CAAC;gBACD,MAAM,sBAAS,CAAC,aAAa,CAAC;oBAC5B,OAAO,EAAE,sBAAsB,4BAAc,CAAC,kBAAkB,WAAW;iBAC5E,CAAC,CAAC;YACL,CAAC;QACH,CAAC;QACD,YAAY,EAAE,CAAC,mCAAW,CAAC,IAAI,CAAC;KACjC,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,WAAW,GAAkD;IACjE,WAAW,EAAE,IAAI;IACjB,gBAAgB,EAAE,IAAI;IACtB,qBAAqB,EAAE,IAAI;CAC5B,CAAC;AAEW,QAAA,sBAAsB,GAAG,MAAM,CAAC,MAAM,CAAC;IAClD,UAAU;IACV,oBAAoB;IACpB,WAAW;CACH,CAAC,CAAC;AAEZ;;;;;;;;;;;;;GAaG;AACH,SAAgB,6BAA6B,CAAC,EAC5C,WAAW,EACX,gBAAgB,EAChB,qBAAqB,GACM;IAC3B,OAAO,KAAK,UAAU,eAAe,CACnC,IAAoD;QAEpD,MAAM,gBAAgB,CAAC,IAAI,CAAC,CAAC;QAE7B,4EAA4E;QAC5E,MAAM,MAAM,GAAG,IAAI,CAAC,MAA+B,CAAC;QACpD,MAAM,oBAAoB,GAAG,MAAM,IAAA,+BAAuB,EACxD,WAAW,EACX,MAAM,CAAC,MAAM,CACd,CAAC;QAEF,MAAM,IAAI,GAAG,MAAM,4BAAiB,CAAC,kBAAkB,CACrD,CAAC,oBAAoB,EAAE,WAAW,EAAE,SAAS,MAAM,CAAC,QAAQ,GAAG,CAAC,EAChE,SAAS,EACT,qBAAqB,EAAE,CACxB,CAAC;QAEF,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC;IACvB,CAAC,CAAC;AACJ,CAAC;AAzBD,sEAyBC","sourcesContent":["import type { CryptographicFunctions } from '@metamask/key-tree';\nimport { BIP44CoinTypeNode } from '@metamask/key-tree';\nimport type {\n PermissionSpecificationBuilder,\n PermissionValidatorConstraint,\n RestrictedMethodOptions,\n ValidPermissionSpecification,\n} from '@metamask/permission-controller';\nimport { PermissionType, SubjectType } from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type {\n GetBip44EntropyParams,\n GetBip44EntropyResult,\n} from '@metamask/snaps-sdk';\nimport { SnapCaveatType } from '@metamask/snaps-utils';\nimport type { NonEmptyArray } from '@metamask/utils';\n\nimport type { MethodHooksObject } from '../utils';\nimport { getSecretRecoveryPhrase } from '../utils';\n\nconst targetName = 'snap_getBip44Entropy';\n\nexport type GetBip44EntropyMethodHooks = {\n /**\n * Get the mnemonic of the provided source. If no source is provided, the\n * mnemonic of the primary keyring will be returned.\n *\n * @param source - The optional ID of the source to get the mnemonic of.\n * @returns The mnemonic of the provided source, or the default source if no\n * source is provided.\n */\n getMnemonic: (source?: string | undefined) => Promise<Uint8Array>;\n\n /**\n * Waits for the extension to be unlocked.\n *\n * @returns A promise that resolves once the extension is unlocked.\n */\n getUnlockPromise: (shouldShowUnlockRequest: boolean) => Promise<void>;\n\n /**\n * Get the cryptographic functions to use for the client. This may return an\n * empty object or `undefined` to fall back to the default cryptographic\n * functions.\n *\n * @returns The cryptographic functions to use for the client.\n */\n getClientCryptography: () => CryptographicFunctions | undefined;\n};\n\ntype GetBip44EntropySpecificationBuilderOptions = {\n methodHooks: GetBip44EntropyMethodHooks;\n};\n\ntype GetBip44EntropySpecification = ValidPermissionSpecification<{\n permissionType: PermissionType.RestrictedMethod;\n targetName: typeof targetName;\n methodImplementation: ReturnType<typeof getBip44EntropyImplementation>;\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n validator: PermissionValidatorConstraint;\n}>;\n\n/**\n * The specification builder for the `snap_getBip44Entropy` permission.\n * `snap_getBip44Entropy_*` lets the Snap control private keys for a particular\n * BIP-32 coin type.\n *\n * @param options - The specification builder options.\n * @param options.methodHooks - The RPC method hooks needed by the method\n * implementation.\n * @returns The specification for the `snap_getBip44Entropy` permission.\n */\nconst specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.RestrictedMethod,\n GetBip44EntropySpecificationBuilderOptions,\n GetBip44EntropySpecification\n> = ({ methodHooks }: GetBip44EntropySpecificationBuilderOptions) => {\n return {\n permissionType: PermissionType.RestrictedMethod,\n targetName,\n allowedCaveats: [SnapCaveatType.PermittedCoinTypes],\n methodImplementation: getBip44EntropyImplementation(methodHooks),\n validator: ({ caveats }) => {\n if (\n caveats?.length !== 1 ||\n caveats[0].type !== SnapCaveatType.PermittedCoinTypes\n ) {\n throw rpcErrors.invalidParams({\n message: `Expected a single \"${SnapCaveatType.PermittedCoinTypes}\" caveat.`,\n });\n }\n },\n subjectTypes: [SubjectType.Snap],\n };\n};\n\nconst methodHooks: MethodHooksObject<GetBip44EntropyMethodHooks> = {\n getMnemonic: true,\n getUnlockPromise: true,\n getClientCryptography: true,\n};\n\nexport const getBip44EntropyBuilder = Object.freeze({\n targetName,\n specificationBuilder,\n methodHooks,\n} as const);\n\n/**\n * Builds the method implementation for `snap_getBip44Entropy`.\n *\n * @param hooks - The RPC method hooks.\n * @param hooks.getMnemonic - A function to retrieve the Secret Recovery Phrase\n * of the user.\n * @param hooks.getUnlockPromise - A function that resolves once the MetaMask\n * extension is unlocked and prompts the user to unlock their MetaMask if it is\n * locked.\n * @param hooks.getClientCryptography - A function to retrieve the cryptographic\n * functions to use for the client.\n * @returns The method implementation which returns a `BIP44CoinTypeNode`.\n * @throws If the params are invalid.\n */\nexport function getBip44EntropyImplementation({\n getMnemonic,\n getUnlockPromise,\n getClientCryptography,\n}: GetBip44EntropyMethodHooks) {\n return async function getBip44Entropy(\n args: RestrictedMethodOptions<GetBip44EntropyParams>,\n ): Promise<GetBip44EntropyResult> {\n await getUnlockPromise(true);\n\n // `args.params` is validated by the decorator, so it's safe to assert here.\n const params = args.params as GetBip44EntropyParams;\n const secretRecoveryPhrase = await getSecretRecoveryPhrase(\n getMnemonic,\n params.source,\n );\n\n const node = await BIP44CoinTypeNode.fromDerivationPath(\n [secretRecoveryPhrase, `bip32:44'`, `bip32:${params.coinType}'`],\n 'mainnet',\n getClientCryptography(),\n );\n\n return node.toJSON();\n };\n}\n"]}
|
|
@@ -7,9 +7,14 @@ import type { MethodHooksObject } from "../utils.cjs";
|
|
|
7
7
|
declare const targetName = "snap_getBip44Entropy";
|
|
8
8
|
export type GetBip44EntropyMethodHooks = {
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
10
|
+
* Get the mnemonic of the provided source. If no source is provided, the
|
|
11
|
+
* mnemonic of the primary keyring will be returned.
|
|
12
|
+
*
|
|
13
|
+
* @param source - The optional ID of the source to get the mnemonic of.
|
|
14
|
+
* @returns The mnemonic of the provided source, or the default source if no
|
|
15
|
+
* source is provided.
|
|
11
16
|
*/
|
|
12
|
-
getMnemonic: () => Promise<Uint8Array>;
|
|
17
|
+
getMnemonic: (source?: string | undefined) => Promise<Uint8Array>;
|
|
13
18
|
/**
|
|
14
19
|
* Waits for the extension to be unlocked.
|
|
15
20
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getBip44Entropy.d.cts","sourceRoot":"","sources":["../../src/restricted/getBip44Entropy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,2BAA2B;AAEjE,OAAO,KAAK,EACV,8BAA8B,EAC9B,6BAA6B,EAC7B,uBAAuB,EAExB,wCAAwC;AACzC,OAAO,EAAE,cAAc,EAAe,wCAAwC;AAE9E,OAAO,KAAK,EACV,qBAAqB,EACrB,qBAAqB,EACtB,4BAA4B;AAE7B,OAAO,KAAK,EAAE,aAAa,EAAE,wBAAwB;AAErD,OAAO,KAAK,EAAE,iBAAiB,EAAE,qBAAiB;
|
|
1
|
+
{"version":3,"file":"getBip44Entropy.d.cts","sourceRoot":"","sources":["../../src/restricted/getBip44Entropy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,2BAA2B;AAEjE,OAAO,KAAK,EACV,8BAA8B,EAC9B,6BAA6B,EAC7B,uBAAuB,EAExB,wCAAwC;AACzC,OAAO,EAAE,cAAc,EAAe,wCAAwC;AAE9E,OAAO,KAAK,EACV,qBAAqB,EACrB,qBAAqB,EACtB,4BAA4B;AAE7B,OAAO,KAAK,EAAE,aAAa,EAAE,wBAAwB;AAErD,OAAO,KAAK,EAAE,iBAAiB,EAAE,qBAAiB;AAGlD,QAAA,MAAM,UAAU,yBAAyB,CAAC;AAE1C,MAAM,MAAM,0BAA0B,GAAG;IACvC;;;;;;;OAOG;IACH,WAAW,EAAE,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,KAAK,OAAO,CAAC,UAAU,CAAC,CAAC;IAElE;;;;OAIG;IACH,gBAAgB,EAAE,CAAC,uBAAuB,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAEtE;;;;;;OAMG;IACH,qBAAqB,EAAE,MAAM,sBAAsB,GAAG,SAAS,CAAC;CACjE,CAAC;AAEF,KAAK,0CAA0C,GAAG;IAChD,WAAW,EAAE,0BAA0B,CAAC;CACzC,CAAC;AAkDF,eAAO,MAAM,sBAAsB;;;wBA/CjB,eAAe,gBAAgB;oBACnC,iBAAiB;8BACP,WAAW,oCAAoC,CAAC;wBACtD,SAAS,cAAc,MAAM,CAAC,CAAC,GAAG,IAAI;mBAC3C,6BAA6B;;;EA+C/B,CAAC;AAEZ;;;;;;;;;;;;;GAaG;AACH,wBAAgB,6BAA6B,CAAC,EAC5C,WAAW,EACX,gBAAgB,EAChB,qBAAqB,GACtB,EAAE,0BAA0B,UAEnB,wBAAwB,qBAAqB,CAAC,KACnD,QAAQ,qBAAqB,CAAC,CAkBlC"}
|
|
@@ -7,9 +7,14 @@ import type { MethodHooksObject } from "../utils.mjs";
|
|
|
7
7
|
declare const targetName = "snap_getBip44Entropy";
|
|
8
8
|
export type GetBip44EntropyMethodHooks = {
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
10
|
+
* Get the mnemonic of the provided source. If no source is provided, the
|
|
11
|
+
* mnemonic of the primary keyring will be returned.
|
|
12
|
+
*
|
|
13
|
+
* @param source - The optional ID of the source to get the mnemonic of.
|
|
14
|
+
* @returns The mnemonic of the provided source, or the default source if no
|
|
15
|
+
* source is provided.
|
|
11
16
|
*/
|
|
12
|
-
getMnemonic: () => Promise<Uint8Array>;
|
|
17
|
+
getMnemonic: (source?: string | undefined) => Promise<Uint8Array>;
|
|
13
18
|
/**
|
|
14
19
|
* Waits for the extension to be unlocked.
|
|
15
20
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getBip44Entropy.d.mts","sourceRoot":"","sources":["../../src/restricted/getBip44Entropy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,2BAA2B;AAEjE,OAAO,KAAK,EACV,8BAA8B,EAC9B,6BAA6B,EAC7B,uBAAuB,EAExB,wCAAwC;AACzC,OAAO,EAAE,cAAc,EAAe,wCAAwC;AAE9E,OAAO,KAAK,EACV,qBAAqB,EACrB,qBAAqB,EACtB,4BAA4B;AAE7B,OAAO,KAAK,EAAE,aAAa,EAAE,wBAAwB;AAErD,OAAO,KAAK,EAAE,iBAAiB,EAAE,qBAAiB;
|
|
1
|
+
{"version":3,"file":"getBip44Entropy.d.mts","sourceRoot":"","sources":["../../src/restricted/getBip44Entropy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,2BAA2B;AAEjE,OAAO,KAAK,EACV,8BAA8B,EAC9B,6BAA6B,EAC7B,uBAAuB,EAExB,wCAAwC;AACzC,OAAO,EAAE,cAAc,EAAe,wCAAwC;AAE9E,OAAO,KAAK,EACV,qBAAqB,EACrB,qBAAqB,EACtB,4BAA4B;AAE7B,OAAO,KAAK,EAAE,aAAa,EAAE,wBAAwB;AAErD,OAAO,KAAK,EAAE,iBAAiB,EAAE,qBAAiB;AAGlD,QAAA,MAAM,UAAU,yBAAyB,CAAC;AAE1C,MAAM,MAAM,0BAA0B,GAAG;IACvC;;;;;;;OAOG;IACH,WAAW,EAAE,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,KAAK,OAAO,CAAC,UAAU,CAAC,CAAC;IAElE;;;;OAIG;IACH,gBAAgB,EAAE,CAAC,uBAAuB,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAEtE;;;;;;OAMG;IACH,qBAAqB,EAAE,MAAM,sBAAsB,GAAG,SAAS,CAAC;CACjE,CAAC;AAEF,KAAK,0CAA0C,GAAG;IAChD,WAAW,EAAE,0BAA0B,CAAC;CACzC,CAAC;AAkDF,eAAO,MAAM,sBAAsB;;;wBA/CjB,eAAe,gBAAgB;oBACnC,iBAAiB;8BACP,WAAW,oCAAoC,CAAC;wBACtD,SAAS,cAAc,MAAM,CAAC,CAAC,GAAG,IAAI;mBAC3C,6BAA6B;;;EA+C/B,CAAC;AAEZ;;;;;;;;;;;;;GAaG;AACH,wBAAgB,6BAA6B,CAAC,EAC5C,WAAW,EACX,gBAAgB,EAChB,qBAAqB,GACtB,EAAE,0BAA0B,UAEnB,wBAAwB,qBAAqB,CAAC,KACnD,QAAQ,qBAAqB,CAAC,CAkBlC"}
|
|
@@ -2,6 +2,7 @@ import { BIP44CoinTypeNode } from "@metamask/key-tree";
|
|
|
2
2
|
import { PermissionType, SubjectType } from "@metamask/permission-controller";
|
|
3
3
|
import { rpcErrors } from "@metamask/rpc-errors";
|
|
4
4
|
import { SnapCaveatType } from "@metamask/snaps-utils";
|
|
5
|
+
import { getSecretRecoveryPhrase } from "../utils.mjs";
|
|
5
6
|
const targetName = 'snap_getBip44Entropy';
|
|
6
7
|
/**
|
|
7
8
|
* The specification builder for the `snap_getBip44Entropy` permission.
|
|
@@ -59,7 +60,8 @@ export function getBip44EntropyImplementation({ getMnemonic, getUnlockPromise, g
|
|
|
59
60
|
await getUnlockPromise(true);
|
|
60
61
|
// `args.params` is validated by the decorator, so it's safe to assert here.
|
|
61
62
|
const params = args.params;
|
|
62
|
-
const
|
|
63
|
+
const secretRecoveryPhrase = await getSecretRecoveryPhrase(getMnemonic, params.source);
|
|
64
|
+
const node = await BIP44CoinTypeNode.fromDerivationPath([secretRecoveryPhrase, `bip32:44'`, `bip32:${params.coinType}'`], 'mainnet', getClientCryptography());
|
|
63
65
|
return node.toJSON();
|
|
64
66
|
};
|
|
65
67
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getBip44Entropy.mjs","sourceRoot":"","sources":["../../src/restricted/getBip44Entropy.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,2BAA2B;AAOvD,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,wCAAwC;AAC9E,OAAO,EAAE,SAAS,EAAE,6BAA6B;AAKjD,OAAO,EAAE,cAAc,EAAE,8BAA8B;
|
|
1
|
+
{"version":3,"file":"getBip44Entropy.mjs","sourceRoot":"","sources":["../../src/restricted/getBip44Entropy.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,2BAA2B;AAOvD,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,wCAAwC;AAC9E,OAAO,EAAE,SAAS,EAAE,6BAA6B;AAKjD,OAAO,EAAE,cAAc,EAAE,8BAA8B;AAIvD,OAAO,EAAE,uBAAuB,EAAE,qBAAiB;AAEnD,MAAM,UAAU,GAAG,sBAAsB,CAAC;AA0C1C;;;;;;;;;GASG;AACH,MAAM,oBAAoB,GAItB,CAAC,EAAE,WAAW,EAA8C,EAAE,EAAE;IAClE,OAAO;QACL,cAAc,EAAE,cAAc,CAAC,gBAAgB;QAC/C,UAAU;QACV,cAAc,EAAE,CAAC,cAAc,CAAC,kBAAkB,CAAC;QACnD,oBAAoB,EAAE,6BAA6B,CAAC,WAAW,CAAC;QAChE,SAAS,EAAE,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE;YACzB,IACE,OAAO,EAAE,MAAM,KAAK,CAAC;gBACrB,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,cAAc,CAAC,kBAAkB,EACrD,CAAC;gBACD,MAAM,SAAS,CAAC,aAAa,CAAC;oBAC5B,OAAO,EAAE,sBAAsB,cAAc,CAAC,kBAAkB,WAAW;iBAC5E,CAAC,CAAC;YACL,CAAC;QACH,CAAC;QACD,YAAY,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC;KACjC,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,WAAW,GAAkD;IACjE,WAAW,EAAE,IAAI;IACjB,gBAAgB,EAAE,IAAI;IACtB,qBAAqB,EAAE,IAAI;CAC5B,CAAC;AAEF,MAAM,CAAC,MAAM,sBAAsB,GAAG,MAAM,CAAC,MAAM,CAAC;IAClD,UAAU;IACV,oBAAoB;IACpB,WAAW;CACH,CAAC,CAAC;AAEZ;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,6BAA6B,CAAC,EAC5C,WAAW,EACX,gBAAgB,EAChB,qBAAqB,GACM;IAC3B,OAAO,KAAK,UAAU,eAAe,CACnC,IAAoD;QAEpD,MAAM,gBAAgB,CAAC,IAAI,CAAC,CAAC;QAE7B,4EAA4E;QAC5E,MAAM,MAAM,GAAG,IAAI,CAAC,MAA+B,CAAC;QACpD,MAAM,oBAAoB,GAAG,MAAM,uBAAuB,CACxD,WAAW,EACX,MAAM,CAAC,MAAM,CACd,CAAC;QAEF,MAAM,IAAI,GAAG,MAAM,iBAAiB,CAAC,kBAAkB,CACrD,CAAC,oBAAoB,EAAE,WAAW,EAAE,SAAS,MAAM,CAAC,QAAQ,GAAG,CAAC,EAChE,SAAS,EACT,qBAAqB,EAAE,CACxB,CAAC;QAEF,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC;IACvB,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import type { CryptographicFunctions } from '@metamask/key-tree';\nimport { BIP44CoinTypeNode } from '@metamask/key-tree';\nimport type {\n PermissionSpecificationBuilder,\n PermissionValidatorConstraint,\n RestrictedMethodOptions,\n ValidPermissionSpecification,\n} from '@metamask/permission-controller';\nimport { PermissionType, SubjectType } from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type {\n GetBip44EntropyParams,\n GetBip44EntropyResult,\n} from '@metamask/snaps-sdk';\nimport { SnapCaveatType } from '@metamask/snaps-utils';\nimport type { NonEmptyArray } from '@metamask/utils';\n\nimport type { MethodHooksObject } from '../utils';\nimport { getSecretRecoveryPhrase } from '../utils';\n\nconst targetName = 'snap_getBip44Entropy';\n\nexport type GetBip44EntropyMethodHooks = {\n /**\n * Get the mnemonic of the provided source. If no source is provided, the\n * mnemonic of the primary keyring will be returned.\n *\n * @param source - The optional ID of the source to get the mnemonic of.\n * @returns The mnemonic of the provided source, or the default source if no\n * source is provided.\n */\n getMnemonic: (source?: string | undefined) => Promise<Uint8Array>;\n\n /**\n * Waits for the extension to be unlocked.\n *\n * @returns A promise that resolves once the extension is unlocked.\n */\n getUnlockPromise: (shouldShowUnlockRequest: boolean) => Promise<void>;\n\n /**\n * Get the cryptographic functions to use for the client. This may return an\n * empty object or `undefined` to fall back to the default cryptographic\n * functions.\n *\n * @returns The cryptographic functions to use for the client.\n */\n getClientCryptography: () => CryptographicFunctions | undefined;\n};\n\ntype GetBip44EntropySpecificationBuilderOptions = {\n methodHooks: GetBip44EntropyMethodHooks;\n};\n\ntype GetBip44EntropySpecification = ValidPermissionSpecification<{\n permissionType: PermissionType.RestrictedMethod;\n targetName: typeof targetName;\n methodImplementation: ReturnType<typeof getBip44EntropyImplementation>;\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n validator: PermissionValidatorConstraint;\n}>;\n\n/**\n * The specification builder for the `snap_getBip44Entropy` permission.\n * `snap_getBip44Entropy_*` lets the Snap control private keys for a particular\n * BIP-32 coin type.\n *\n * @param options - The specification builder options.\n * @param options.methodHooks - The RPC method hooks needed by the method\n * implementation.\n * @returns The specification for the `snap_getBip44Entropy` permission.\n */\nconst specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.RestrictedMethod,\n GetBip44EntropySpecificationBuilderOptions,\n GetBip44EntropySpecification\n> = ({ methodHooks }: GetBip44EntropySpecificationBuilderOptions) => {\n return {\n permissionType: PermissionType.RestrictedMethod,\n targetName,\n allowedCaveats: [SnapCaveatType.PermittedCoinTypes],\n methodImplementation: getBip44EntropyImplementation(methodHooks),\n validator: ({ caveats }) => {\n if (\n caveats?.length !== 1 ||\n caveats[0].type !== SnapCaveatType.PermittedCoinTypes\n ) {\n throw rpcErrors.invalidParams({\n message: `Expected a single \"${SnapCaveatType.PermittedCoinTypes}\" caveat.`,\n });\n }\n },\n subjectTypes: [SubjectType.Snap],\n };\n};\n\nconst methodHooks: MethodHooksObject<GetBip44EntropyMethodHooks> = {\n getMnemonic: true,\n getUnlockPromise: true,\n getClientCryptography: true,\n};\n\nexport const getBip44EntropyBuilder = Object.freeze({\n targetName,\n specificationBuilder,\n methodHooks,\n} as const);\n\n/**\n * Builds the method implementation for `snap_getBip44Entropy`.\n *\n * @param hooks - The RPC method hooks.\n * @param hooks.getMnemonic - A function to retrieve the Secret Recovery Phrase\n * of the user.\n * @param hooks.getUnlockPromise - A function that resolves once the MetaMask\n * extension is unlocked and prompts the user to unlock their MetaMask if it is\n * locked.\n * @param hooks.getClientCryptography - A function to retrieve the cryptographic\n * functions to use for the client.\n * @returns The method implementation which returns a `BIP44CoinTypeNode`.\n * @throws If the params are invalid.\n */\nexport function getBip44EntropyImplementation({\n getMnemonic,\n getUnlockPromise,\n getClientCryptography,\n}: GetBip44EntropyMethodHooks) {\n return async function getBip44Entropy(\n args: RestrictedMethodOptions<GetBip44EntropyParams>,\n ): Promise<GetBip44EntropyResult> {\n await getUnlockPromise(true);\n\n // `args.params` is validated by the decorator, so it's safe to assert here.\n const params = args.params as GetBip44EntropyParams;\n const secretRecoveryPhrase = await getSecretRecoveryPhrase(\n getMnemonic,\n params.source,\n );\n\n const node = await BIP44CoinTypeNode.fromDerivationPath(\n [secretRecoveryPhrase, `bip32:44'`, `bip32:${params.coinType}'`],\n 'mainnet',\n getClientCryptography(),\n );\n\n return node.toJSON();\n };\n}\n"]}
|
|
@@ -11,6 +11,7 @@ const targetName = 'snap_getEntropy';
|
|
|
11
11
|
exports.GetEntropyArgsStruct = (0, superstruct_1.object)({
|
|
12
12
|
version: (0, superstruct_1.literal)(1),
|
|
13
13
|
salt: (0, superstruct_1.optional)((0, superstruct_1.string)()),
|
|
14
|
+
source: (0, superstruct_1.optional)((0, superstruct_1.string)()),
|
|
14
15
|
});
|
|
15
16
|
const specificationBuilder = ({ allowedCaveats = null, methodHooks, }) => {
|
|
16
17
|
return {
|
|
@@ -50,7 +51,7 @@ function getEntropyImplementation({ getMnemonic, getUnlockPromise, getClientCryp
|
|
|
50
51
|
const { params, context: { origin }, } = options;
|
|
51
52
|
(0, utils_1.assertStruct)(params, exports.GetEntropyArgsStruct, 'Invalid "snap_getEntropy" parameters', rpc_errors_1.rpcErrors.invalidParams);
|
|
52
53
|
await getUnlockPromise(true);
|
|
53
|
-
const mnemonicPhrase = await
|
|
54
|
+
const mnemonicPhrase = await (0, utils_2.getSecretRecoveryPhrase)(getMnemonic, params.source);
|
|
54
55
|
return (0, utils_2.deriveEntropy)({
|
|
55
56
|
input: origin,
|
|
56
57
|
salt: params.salt,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getEntropy.cjs","sourceRoot":"","sources":["../../src/restricted/getEntropy.ts"],"names":[],"mappings":";;;AAMA,2EAA8E;AAC9E,qDAAiD;AAEjD,uDAA0D;AAE1D,uDAA0E;AAE1E,2CAA+C;AAG/C,
|
|
1
|
+
{"version":3,"file":"getEntropy.cjs","sourceRoot":"","sources":["../../src/restricted/getEntropy.ts"],"names":[],"mappings":";;;AAMA,2EAA8E;AAC9E,qDAAiD;AAEjD,uDAA0D;AAE1D,uDAA0E;AAE1E,2CAA+C;AAG/C,wCAAkE;AAElE,MAAM,UAAU,GAAG,iBAAiB,CAAC;AAcxB,QAAA,oBAAoB,GAAG,IAAA,oBAAM,EAAC;IACzC,OAAO,EAAE,IAAA,qBAAO,EAAC,CAAC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AK,EAAE,+BAAiB;YACxB,sBAAsB,EAAE,qBAAqB,EAAE;SAChD,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import type { CryptographicFunctions } from '@metamask/key-tree';\nimport type {\n PermissionSpecificationBuilder,\n RestrictedMethodOptions,\n ValidPermissionSpecification,\n} from '@metamask/permission-controller';\nimport { PermissionType, SubjectType } from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type { GetEntropyParams, GetEntropyResult } from '@metamask/snaps-sdk';\nimport { SIP_6_MAGIC_VALUE } from '@metamask/snaps-utils';\nimport type { Infer } from '@metamask/superstruct';\nimport { literal, object, optional, string } from '@metamask/superstruct';\nimport type { NonEmptyArray } from '@metamask/utils';\nimport { assertStruct } from '@metamask/utils';\n\nimport type { MethodHooksObject } from '../utils';\nimport { getSecretRecoveryPhrase, deriveEntropy } from '../utils';\n\nconst targetName = 'snap_getEntropy';\n\ntype GetEntropySpecificationBuilderOptions = {\n allowedCaveats?: Readonly<NonEmptyArray<string>> | null;\n methodHooks: GetEntropyHooks;\n};\n\ntype GetEntropySpecification = ValidPermissionSpecification<{\n permissionType: PermissionType.RestrictedMethod;\n targetName: typeof targetName;\n methodImplementation: ReturnType<typeof getEntropyImplementation>;\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n}>;\n\nexport const GetEntropyArgsStruct = object({\n version: literal(1),\n salt: optional(string()),\n source: optional(string()),\n});\n\n/**\n * @property version - The version of the `snap_getEntropy` method. This must be\n * the numeric literal `1`.\n * @property salt - A string to use as the salt when deriving the entropy. If\n * omitted, the salt will be an empty string.\n */\nexport type GetEntropyArgs = Infer<typeof GetEntropyArgsStruct>;\n\nconst specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.RestrictedMethod,\n GetEntropySpecificationBuilderOptions,\n GetEntropySpecification\n> = ({\n allowedCaveats = null,\n methodHooks,\n}: GetEntropySpecificationBuilderOptions) => {\n return {\n permissionType: PermissionType.RestrictedMethod,\n targetName,\n allowedCaveats,\n methodImplementation: getEntropyImplementation(methodHooks),\n subjectTypes: [SubjectType.Snap],\n };\n};\n\nconst methodHooks: MethodHooksObject<GetEntropyHooks> = {\n getMnemonic: true,\n getUnlockPromise: true,\n getClientCryptography: true,\n};\n\nexport const getEntropyBuilder = Object.freeze({\n targetName,\n specificationBuilder,\n methodHooks,\n} as const);\n\nexport type GetEntropyHooks = {\n /**\n * Get the mnemonic of the provided source. If no source is provided, the\n * mnemonic of the primary keyring will be returned.\n *\n * @param source - The optional ID of the source to get the mnemonic of.\n * @returns The mnemonic of the provided source, or the default source if no\n * source is provided.\n */\n getMnemonic: (source?: string | undefined) => Promise<Uint8Array>;\n\n /**\n * Waits for the extension to be unlocked.\n *\n * @returns A promise that resolves once the extension is unlocked.\n */\n getUnlockPromise: (shouldShowUnlockRequest: boolean) => Promise<void>;\n\n /**\n * Get the cryptographic functions to use for the client. This may return an\n * empty object or `undefined` to fall back to the default cryptographic\n * functions.\n *\n * @returns The cryptographic functions to use for the client.\n */\n getClientCryptography: () => CryptographicFunctions | undefined;\n};\n\n/**\n * Builds the method implementation for `snap_getEntropy`. The implementation\n * is based on the reference implementation of\n * [SIP-6](https://metamask.github.io/SIPs/SIPS/sip-6).\n *\n * @param hooks - The RPC method hooks.\n * @param hooks.getMnemonic - The method to get the mnemonic of the user's\n * primary keyring.\n * @param hooks.getUnlockPromise - The method to get a promise that resolves\n * once the extension is unlocked.\n * @param hooks.getClientCryptography - A function to retrieve the cryptographic\n * functions to use for the client.\n * @returns The method implementation.\n */\nfunction getEntropyImplementation({\n getMnemonic,\n getUnlockPromise,\n getClientCryptography,\n}: GetEntropyHooks) {\n return async function getEntropy(\n options: RestrictedMethodOptions<GetEntropyParams>,\n ): Promise<GetEntropyResult> {\n const {\n params,\n context: { origin },\n } = options;\n\n assertStruct(\n params,\n GetEntropyArgsStruct,\n 'Invalid \"snap_getEntropy\" parameters',\n rpcErrors.invalidParams,\n );\n\n await getUnlockPromise(true);\n const mnemonicPhrase = await getSecretRecoveryPhrase(\n getMnemonic,\n params.source,\n );\n\n return deriveEntropy({\n input: origin,\n salt: params.salt,\n mnemonicPhrase,\n magic: SIP_6_MAGIC_VALUE,\n cryptographicFunctions: getClientCryptography(),\n });\n };\n}\n"]}
|
|
@@ -12,10 +12,12 @@ type GetEntropySpecificationBuilderOptions = {
|
|
|
12
12
|
};
|
|
13
13
|
export declare const GetEntropyArgsStruct: import("@metamask/superstruct").Struct<{
|
|
14
14
|
version: 1;
|
|
15
|
+
source?: string | undefined;
|
|
15
16
|
salt?: string | undefined;
|
|
16
17
|
}, {
|
|
17
18
|
version: import("@metamask/superstruct").Struct<1, 1>;
|
|
18
19
|
salt: import("@metamask/superstruct").Struct<string | undefined, null>;
|
|
20
|
+
source: import("@metamask/superstruct").Struct<string | undefined, null>;
|
|
19
21
|
}>;
|
|
20
22
|
/**
|
|
21
23
|
* @property version - The version of the `snap_getEntropy` method. This must be
|
|
@@ -36,9 +38,14 @@ export declare const getEntropyBuilder: Readonly<{
|
|
|
36
38
|
}>;
|
|
37
39
|
export type GetEntropyHooks = {
|
|
38
40
|
/**
|
|
39
|
-
*
|
|
41
|
+
* Get the mnemonic of the provided source. If no source is provided, the
|
|
42
|
+
* mnemonic of the primary keyring will be returned.
|
|
43
|
+
*
|
|
44
|
+
* @param source - The optional ID of the source to get the mnemonic of.
|
|
45
|
+
* @returns The mnemonic of the provided source, or the default source if no
|
|
46
|
+
* source is provided.
|
|
40
47
|
*/
|
|
41
|
-
getMnemonic: () => Promise<Uint8Array>;
|
|
48
|
+
getMnemonic: (source?: string | undefined) => Promise<Uint8Array>;
|
|
42
49
|
/**
|
|
43
50
|
* Waits for the extension to be unlocked.
|
|
44
51
|
*
|
|
@@ -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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cAAc,GAAG,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAyBhE,eAAO,MAAM,iBAAiB;;;wBA3CZ,eAAe,gBAAgB;oBACnC,iBAAiB;8BACP,WAAW,+BAA+B,CAAC;wBACjD,SAAS,cAAc,MAAM,CAAC,CAAC,GAAG,IAAI;;;EA4C7C,CAAC;AAEZ,MAAM,MAAM,eAAe,GAAG;IAC5B;;;;;;;OAOG;IACH,WAAW,EAAE,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,KAAK,OAAO,CAAC,UAAU,CAAC,CAAC;IAElE;;;;OAIG;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,EACX,gBAAgB,EAChB,qBAAqB,GACtB,EAAE,eAAe,aAEL,wBAAwB,gBAAgB,CAAC,KACjD,QAAQ,gBAAgB,CAAC,CA2B7B"}
|
|
@@ -12,10 +12,12 @@ type GetEntropySpecificationBuilderOptions = {
|
|
|
12
12
|
};
|
|
13
13
|
export declare const GetEntropyArgsStruct: import("@metamask/superstruct").Struct<{
|
|
14
14
|
version: 1;
|
|
15
|
+
source?: string | undefined;
|
|
15
16
|
salt?: string | undefined;
|
|
16
17
|
}, {
|
|
17
18
|
version: import("@metamask/superstruct").Struct<1, 1>;
|
|
18
19
|
salt: import("@metamask/superstruct").Struct<string | undefined, null>;
|
|
20
|
+
source: import("@metamask/superstruct").Struct<string | undefined, null>;
|
|
19
21
|
}>;
|
|
20
22
|
/**
|
|
21
23
|
* @property version - The version of the `snap_getEntropy` method. This must be
|
|
@@ -36,9 +38,14 @@ export declare const getEntropyBuilder: Readonly<{
|
|
|
36
38
|
}>;
|
|
37
39
|
export type GetEntropyHooks = {
|
|
38
40
|
/**
|
|
39
|
-
*
|
|
41
|
+
* Get the mnemonic of the provided source. If no source is provided, the
|
|
42
|
+
* mnemonic of the primary keyring will be returned.
|
|
43
|
+
*
|
|
44
|
+
* @param source - The optional ID of the source to get the mnemonic of.
|
|
45
|
+
* @returns The mnemonic of the provided source, or the default source if no
|
|
46
|
+
* source is provided.
|
|
40
47
|
*/
|
|
41
|
-
getMnemonic: () => Promise<Uint8Array>;
|
|
48
|
+
getMnemonic: (source?: string | undefined) => Promise<Uint8Array>;
|
|
42
49
|
/**
|
|
43
50
|
* Waits for the extension to be unlocked.
|
|
44
51
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getEntropy.d.mts","sourceRoot":"","sources":["../../src/restricted/getEntropy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,2BAA2B;AACjE,OAAO,KAAK,EACV,8BAA8B,EAC9B,uBAAuB,EAExB,wCAAwC;AACzC,OAAO,EAAE,cAAc,EAAe,wCAAwC;AAE9E,OAAO,KAAK,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,4BAA4B;AAE9E,OAAO,KAAK,EAAE,KAAK,EAAE,8BAA8B;AAEnD,OAAO,KAAK,EAAE,aAAa,EAAE,wBAAwB;AAGrD,OAAO,KAAK,EAAE,iBAAiB,EAAE,qBAAiB;AAGlD,QAAA,MAAM,UAAU,oBAAoB,CAAC;AAErC,KAAK,qCAAqC,GAAG;IAC3C,cAAc,CAAC,EAAE,QAAQ,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,GAAG,IAAI,CAAC;IACxD,WAAW,EAAE,eAAe,CAAC;CAC9B,CAAC;AASF,eAAO,MAAM,oBAAoB
|
|
1
|
+
{"version":3,"file":"getEntropy.d.mts","sourceRoot":"","sources":["../../src/restricted/getEntropy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,2BAA2B;AACjE,OAAO,KAAK,EACV,8BAA8B,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D,QAAQ,gBAAgB,CAAC,CA2B7B"}
|
|
@@ -3,11 +3,12 @@ import { rpcErrors } from "@metamask/rpc-errors";
|
|
|
3
3
|
import { SIP_6_MAGIC_VALUE } from "@metamask/snaps-utils";
|
|
4
4
|
import { literal, object, optional, string } from "@metamask/superstruct";
|
|
5
5
|
import { assertStruct } from "@metamask/utils";
|
|
6
|
-
import { deriveEntropy } from "../utils.mjs";
|
|
6
|
+
import { getSecretRecoveryPhrase, deriveEntropy } from "../utils.mjs";
|
|
7
7
|
const targetName = 'snap_getEntropy';
|
|
8
8
|
export const GetEntropyArgsStruct = object({
|
|
9
9
|
version: literal(1),
|
|
10
10
|
salt: optional(string()),
|
|
11
|
+
source: optional(string()),
|
|
11
12
|
});
|
|
12
13
|
const specificationBuilder = ({ allowedCaveats = null, methodHooks, }) => {
|
|
13
14
|
return {
|
|
@@ -47,7 +48,7 @@ function getEntropyImplementation({ getMnemonic, getUnlockPromise, getClientCryp
|
|
|
47
48
|
const { params, context: { origin }, } = options;
|
|
48
49
|
assertStruct(params, GetEntropyArgsStruct, 'Invalid "snap_getEntropy" parameters', rpcErrors.invalidParams);
|
|
49
50
|
await getUnlockPromise(true);
|
|
50
|
-
const mnemonicPhrase = await getMnemonic
|
|
51
|
+
const mnemonicPhrase = await getSecretRecoveryPhrase(getMnemonic, params.source);
|
|
51
52
|
return deriveEntropy({
|
|
52
53
|
input: origin,
|
|
53
54
|
salt: params.salt,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getEntropy.mjs","sourceRoot":"","sources":["../../src/restricted/getEntropy.ts"],"names":[],"mappings":"AAMA,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,YA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;;;;;;;;GAaG;AACH,SAAS,wBAAwB,CAAC,EAChC,WAAW,EACX,gBAAgB,EAChB,qBAAqB,GACL;IAChB,OAAO,KAAK,UAAU,UAAU,CAC9B,OAAkD;QAElD,MAAM,EACJ,MAAM,EACN,OAAO,EAAE,EAAE,MAAM,EAAE,GACpB,GAAG,OAAO,CAAC;QAEZ,YAAY,CACV,MAAM,EACN,oBAAoB,EACpB,sCAAsC,EACtC,SAAS,CAAC,aAAa,CACxB,CAAC;QAEF,MAAM,gBAAgB,CAAC,IAAI,CAAC,CAAC;QAC7B,MAAM,cAAc,GAAG,MAAM,uBAAuB,CAClD,WAAW,EACX,MAAM,CAAC,MAAM,CACd,CAAC;QAEF,OAAO,aAAa,CAAC;YACnB,KAAK,EAAE,MAAM;YACb,IAAI,EAAE,MAAM,CAAC,IAAI;YACjB,cAAc;YACd,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 {\n PermissionSpecificationBuilder,\n RestrictedMethodOptions,\n ValidPermissionSpecification,\n} from '@metamask/permission-controller';\nimport { PermissionType, SubjectType } from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type { GetEntropyParams, GetEntropyResult } from '@metamask/snaps-sdk';\nimport { SIP_6_MAGIC_VALUE } from '@metamask/snaps-utils';\nimport type { Infer } from '@metamask/superstruct';\nimport { literal, object, optional, string } from '@metamask/superstruct';\nimport type { NonEmptyArray } from '@metamask/utils';\nimport { assertStruct } from '@metamask/utils';\n\nimport type { MethodHooksObject } from '../utils';\nimport { getSecretRecoveryPhrase, deriveEntropy } from '../utils';\n\nconst targetName = 'snap_getEntropy';\n\ntype GetEntropySpecificationBuilderOptions = {\n allowedCaveats?: Readonly<NonEmptyArray<string>> | null;\n methodHooks: GetEntropyHooks;\n};\n\ntype GetEntropySpecification = ValidPermissionSpecification<{\n permissionType: PermissionType.RestrictedMethod;\n targetName: typeof targetName;\n methodImplementation: ReturnType<typeof getEntropyImplementation>;\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n}>;\n\nexport const GetEntropyArgsStruct = object({\n version: literal(1),\n salt: optional(string()),\n source: optional(string()),\n});\n\n/**\n * @property version - The version of the `snap_getEntropy` method. This must be\n * the numeric literal `1`.\n * @property salt - A string to use as the salt when deriving the entropy. If\n * omitted, the salt will be an empty string.\n */\nexport type GetEntropyArgs = Infer<typeof GetEntropyArgsStruct>;\n\nconst specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.RestrictedMethod,\n GetEntropySpecificationBuilderOptions,\n GetEntropySpecification\n> = ({\n allowedCaveats = null,\n methodHooks,\n}: GetEntropySpecificationBuilderOptions) => {\n return {\n permissionType: PermissionType.RestrictedMethod,\n targetName,\n allowedCaveats,\n methodImplementation: getEntropyImplementation(methodHooks),\n subjectTypes: [SubjectType.Snap],\n };\n};\n\nconst methodHooks: MethodHooksObject<GetEntropyHooks> = {\n getMnemonic: true,\n getUnlockPromise: true,\n getClientCryptography: true,\n};\n\nexport const getEntropyBuilder = Object.freeze({\n targetName,\n specificationBuilder,\n methodHooks,\n} as const);\n\nexport type GetEntropyHooks = {\n /**\n * Get the mnemonic of the provided source. If no source is provided, the\n * mnemonic of the primary keyring will be returned.\n *\n * @param source - The optional ID of the source to get the mnemonic of.\n * @returns The mnemonic of the provided source, or the default source if no\n * source is provided.\n */\n getMnemonic: (source?: string | undefined) => Promise<Uint8Array>;\n\n /**\n * Waits for the extension to be unlocked.\n *\n * @returns A promise that resolves once the extension is unlocked.\n */\n getUnlockPromise: (shouldShowUnlockRequest: boolean) => Promise<void>;\n\n /**\n * Get the cryptographic functions to use for the client. This may return an\n * empty object or `undefined` to fall back to the default cryptographic\n * functions.\n *\n * @returns The cryptographic functions to use for the client.\n */\n getClientCryptography: () => CryptographicFunctions | undefined;\n};\n\n/**\n * Builds the method implementation for `snap_getEntropy`. The implementation\n * is based on the reference implementation of\n * [SIP-6](https://metamask.github.io/SIPs/SIPS/sip-6).\n *\n * @param hooks - The RPC method hooks.\n * @param hooks.getMnemonic - The method to get the mnemonic of the user's\n * primary keyring.\n * @param hooks.getUnlockPromise - The method to get a promise that resolves\n * once the extension is unlocked.\n * @param hooks.getClientCryptography - A function to retrieve the cryptographic\n * functions to use for the client.\n * @returns The method implementation.\n */\nfunction getEntropyImplementation({\n getMnemonic,\n getUnlockPromise,\n getClientCryptography,\n}: GetEntropyHooks) {\n return async function getEntropy(\n options: RestrictedMethodOptions<GetEntropyParams>,\n ): Promise<GetEntropyResult> {\n const {\n params,\n context: { origin },\n } = options;\n\n assertStruct(\n params,\n GetEntropyArgsStruct,\n 'Invalid \"snap_getEntropy\" parameters',\n rpcErrors.invalidParams,\n );\n\n await getUnlockPromise(true);\n const mnemonicPhrase = await getSecretRecoveryPhrase(\n getMnemonic,\n params.source,\n );\n\n return deriveEntropy({\n input: origin,\n salt: params.salt,\n mnemonicPhrase,\n magic: SIP_6_MAGIC_VALUE,\n cryptographicFunctions: getClientCryptography(),\n });\n };\n}\n"]}
|
|
@@ -33,7 +33,7 @@ export declare const restrictedMethodPermissionBuilders: {
|
|
|
33
33
|
}, {
|
|
34
34
|
permissionType: import("@metamask/permission-controller").PermissionType.RestrictedMethod;
|
|
35
35
|
targetName: "snap_getBip32Entropy";
|
|
36
|
-
methodImplementation: (args: import("@metamask/permission-controller").RestrictedMethodOptions<import("@metamask/snaps-sdk").
|
|
36
|
+
methodImplementation: (args: import("@metamask/permission-controller").RestrictedMethodOptions<import("@metamask/snaps-sdk").GetBip32EntropyParams>) => Promise<import("@metamask/key-tree").JsonSLIP10Node>;
|
|
37
37
|
allowedCaveats: readonly [string, ...string[]] | null;
|
|
38
38
|
validator: import("@metamask/permission-controller").PermissionValidatorConstraint;
|
|
39
39
|
}>;
|
|
@@ -59,7 +59,7 @@ export declare const restrictedMethodPermissionBuilders: {
|
|
|
59
59
|
}, {
|
|
60
60
|
permissionType: import("@metamask/permission-controller").PermissionType.RestrictedMethod;
|
|
61
61
|
targetName: "snap_getBip44Entropy";
|
|
62
|
-
methodImplementation: (args: import("@metamask/permission-controller").RestrictedMethodOptions<import("@metamask/snaps-sdk").
|
|
62
|
+
methodImplementation: (args: import("@metamask/permission-controller").RestrictedMethodOptions<import("@metamask/snaps-sdk").GetBip44EntropyParams>) => Promise<import("@metamask/key-tree").JsonBIP44CoinTypeNode>;
|
|
63
63
|
allowedCaveats: readonly [string, ...string[]] | null;
|
|
64
64
|
validator: import("@metamask/permission-controller").PermissionValidatorConstraint;
|
|
65
65
|
}>;
|
|
@@ -33,7 +33,7 @@ export declare const restrictedMethodPermissionBuilders: {
|
|
|
33
33
|
}, {
|
|
34
34
|
permissionType: import("@metamask/permission-controller").PermissionType.RestrictedMethod;
|
|
35
35
|
targetName: "snap_getBip32Entropy";
|
|
36
|
-
methodImplementation: (args: import("@metamask/permission-controller").RestrictedMethodOptions<import("@metamask/snaps-sdk").
|
|
36
|
+
methodImplementation: (args: import("@metamask/permission-controller").RestrictedMethodOptions<import("@metamask/snaps-sdk").GetBip32EntropyParams>) => Promise<import("@metamask/key-tree").JsonSLIP10Node>;
|
|
37
37
|
allowedCaveats: readonly [string, ...string[]] | null;
|
|
38
38
|
validator: import("@metamask/permission-controller").PermissionValidatorConstraint;
|
|
39
39
|
}>;
|
|
@@ -59,7 +59,7 @@ export declare const restrictedMethodPermissionBuilders: {
|
|
|
59
59
|
}, {
|
|
60
60
|
permissionType: import("@metamask/permission-controller").PermissionType.RestrictedMethod;
|
|
61
61
|
targetName: "snap_getBip44Entropy";
|
|
62
|
-
methodImplementation: (args: import("@metamask/permission-controller").RestrictedMethodOptions<import("@metamask/snaps-sdk").
|
|
62
|
+
methodImplementation: (args: import("@metamask/permission-controller").RestrictedMethodOptions<import("@metamask/snaps-sdk").GetBip44EntropyParams>) => Promise<import("@metamask/key-tree").JsonBIP44CoinTypeNode>;
|
|
63
63
|
allowedCaveats: readonly [string, ...string[]] | null;
|
|
64
64
|
validator: import("@metamask/permission-controller").PermissionValidatorConstraint;
|
|
65
65
|
}>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notify.cjs","sourceRoot":"","sources":["../../src/restricted/notify.ts"],"names":[],"mappings":";;;AAKA,2EAA8E;AAC9E,qDAAiD;AAOjD,mDAO6B;AAC7B,uDAK+B;AAE/B,uDAAiE;AAEjE,2CAAwD;AAIxD,MAAM,UAAU,GAAG,aAAa,CAAC;AAEjC,MAAM,wBAAwB,GAAG,IAAA,oBAAM,EAAC;IACtC,IAAI,EAAE,IAAA,qBAAS,EAAC,4BAAgB,CAAC,MAAM,CAAC;IACxC,OAAO,EAAE,IAAA,oBAAM,GAAE;CAClB,CAAC,CAAC;AAEH,MAAM,uBAAuB,GAAG,IAAA,oBAAM,EAAC;IACrC,IAAI,EAAE,IAAA,qBAAS,EAAC,4BAAgB,CAAC,KAAK,CAAC;IACvC,OAAO,EAAE,IAAA,oBAAM,GAAE;CAClB,CAAC,CAAC;AAEH,MAAM,kCAAkC,GAAG,IAAA,oBAAM,EAAC;IAChD,IAAI,EAAE,IAAA,qBAAS,EAAC,4BAAgB,CAAC,KAAK,CAAC;IACvC,OAAO,EAAE,IAAA,oBAAM,GAAE;IACjB,OAAO,EAAE,oCAAwB;IACjC,KAAK,EAAE,IAAA,oBAAM,GAAE;IACf,UAAU,EAAE,IAAA,sBAAQ,EAClB,IAAA,oBAAM,EAAC;QACL,IAAI,EAAE,IAAA,oBAAM,GAAE;QACd,IAAI,EAAE,IAAA,oBAAM,GAAE;KACf,CAAC,CACH;CACF,CAAC,CAAC;AAEH,MAAM,4BAA4B,GAAG,IAAA,iBAAK,EAAC;IACzC,uBAAuB;IACvB,kCAAkC;IAClC,wBAAwB;CACzB,CAAC,CAAC;AAmDH;;;;;;;;GAQG;AACI,MAAM,oBAAoB,GAI7B,CAAC,EAAE,cAAc,GAAG,IAAI,EAAE,WAAW,EAA+B,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QAC/B,CAAC,WAAW,IAAI,OAAO,CAAC,MAAM,IAAI,GAAG,CAAC,EACtC,CAAC;QACD,MAAM,sBAAS,CAAC,aAAa,CAAC;YAC5B,OAAO,EACL,0EAA0E;SAC7E,CAAC,CAAC;IACL,CAAC;IAED,IAAI,CAAC;QACH,MAAM,eAAe,GAAG,IAAA,yBAAW,EACjC,MAAM,EACN,4BAA4B,EAC5B,MAAM,CACP,CAAC;QAEF,IAAA,+BAAiB,EAAC,eAAe,CAAC,OAAO,EAAE,gBAAgB,EAAE,OAAO,CAAC,CAAC;QAEtE,IAAI,IAAA,mBAAW,EAAC,eAAe,EAAE,YAAY,CAAC,EAAE,CAAC;YAC/C,IAAA,0BAAY,EAAC,eAAe,CAAC,UAAU,CAAC,IAAI,EAAE,gBAAgB,EAAE,OAAO,CAAC,CAAC;QAC3E,CAAC;QAED,OAAO,eAAe,CAAC;IACzB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,sBAAS,CAAC,aAAa,CAAC;YAC5B,OAAO,EAAE,mBAAmB,IAAA,2BAAe,EAAC,KAAK,CAAC,EAAE;SACrD,CAAC,CAAC;IACL,CAAC;AACH,CAAC;AAhED,gDAgEC","sourcesContent":["import 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 {\n NotifyParams,\n NotifyResult,\n InterfaceContext,\n ComponentOrElement,\n} from '@metamask/snaps-sdk';\nimport {\n enumValue,\n NotificationType,\n union,\n ContentType,\n getErrorMessage,\n ComponentOrElementStruct,\n} from '@metamask/snaps-sdk';\nimport {\n createUnion,\n validateLink,\n validateTextLinks,\n type Snap,\n} from '@metamask/snaps-utils';\nimport type { InferMatching } from '@metamask/snaps-utils';\nimport { object, string, optional } from '@metamask/superstruct';\nimport type { NonEmptyArray } from '@metamask/utils';\nimport { hasProperty, isObject } from '@metamask/utils';\n\nimport { type MethodHooksObject } from '../utils';\n\nconst methodName = 'snap_notify';\n\nconst NativeNotificationStruct = object({\n type: enumValue(NotificationType.Native),\n message: string(),\n});\n\nconst InAppNotificationStruct = object({\n type: enumValue(NotificationType.InApp),\n message: string(),\n});\n\nconst InAppNotificationWithDetailsStruct = object({\n type: enumValue(NotificationType.InApp),\n message: string(),\n content: ComponentOrElementStruct,\n title: string(),\n footerLink: optional(\n object({\n href: string(),\n text: string(),\n }),\n ),\n});\n\nconst NotificationParametersStruct = union([\n InAppNotificationStruct,\n InAppNotificationWithDetailsStruct,\n NativeNotificationStruct,\n]);\n\nexport type NotificationArgs = InferMatching<\n typeof NotificationParametersStruct,\n NotifyParams\n>;\n\nexport type NotifyMethodHooks = {\n /**\n * @param snapId - The ID of the Snap that created the notification.\n * @param args - The notification arguments.\n */\n showNativeNotification: (\n snapId: string,\n args: NotificationArgs,\n ) => Promise<null>;\n\n /**\n * @param snapId - The ID of the Snap that created the notification.\n * @param args - The notification arguments.\n */\n showInAppNotification: (\n snapId: string,\n args: NotificationArgs,\n ) => Promise<null>;\n\n isOnPhishingList: (url: string) => boolean;\n\n maybeUpdatePhishingList: () => Promise<void>;\n\n createInterface: (\n origin: string,\n content: ComponentOrElement,\n context?: InterfaceContext,\n contentType?: ContentType,\n ) => Promise<string>;\n getSnap: (snapId: string) => Snap | undefined;\n};\n\ntype SpecificationBuilderOptions = {\n allowedCaveats?: Readonly<NonEmptyArray<string>> | null;\n methodHooks: NotifyMethodHooks;\n};\n\ntype Specification = ValidPermissionSpecification<{\n permissionType: PermissionType.RestrictedMethod;\n targetName: typeof methodName;\n methodImplementation: ReturnType<typeof getImplementation>;\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n}>;\n\n/**\n * The specification builder for the `snap_notify` permission.\n * `snap_notify` allows snaps to send multiple types of notifications to its users.\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_notify` permission.\n */\nexport const specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.RestrictedMethod,\n SpecificationBuilderOptions,\n Specification\n> = ({ allowedCaveats = null, methodHooks }: SpecificationBuilderOptions) => {\n return {\n permissionType: PermissionType.RestrictedMethod,\n targetName: methodName,\n allowedCaveats,\n methodImplementation: getImplementation(methodHooks),\n subjectTypes: [SubjectType.Snap],\n };\n};\n\nconst methodHooks: MethodHooksObject<NotifyMethodHooks> = {\n showNativeNotification: true,\n showInAppNotification: true,\n isOnPhishingList: true,\n maybeUpdatePhishingList: true,\n createInterface: true,\n getSnap: true,\n};\n\nexport const notifyBuilder = Object.freeze({\n targetName: methodName,\n specificationBuilder,\n methodHooks,\n} as const);\n\n/**\n * Builds the method implementation for `snap_notify`.\n *\n * @param hooks - The RPC method hooks.\n * @param hooks.showNativeNotification - A function that shows a native browser notification.\n * @param hooks.showInAppNotification - A function that shows a notification in the MetaMask UI.\n * @param hooks.isOnPhishingList - A function that checks for links against the phishing list.\n * @param hooks.maybeUpdatePhishingList - A function that updates the phishing list if needed.\n * @param hooks.createInterface - A function that creates the interface in SnapInterfaceController.\n * @param hooks.getSnap - A function that checks if a snap is installed.\n * @returns The method implementation which returns `null` on success.\n * @throws If the params are invalid.\n */\nexport function getImplementation({\n showNativeNotification,\n showInAppNotification,\n isOnPhishingList,\n maybeUpdatePhishingList,\n createInterface,\n getSnap,\n}: NotifyMethodHooks) {\n return async function implementation(\n args: RestrictedMethodOptions<NotifyParams>,\n ): Promise<NotifyResult> {\n const {\n params,\n context: { origin },\n } = args;\n\n await maybeUpdatePhishingList();\n\n const validatedParams = getValidatedParams(\n params,\n isOnPhishingList,\n getSnap,\n );\n\n if (hasProperty(validatedParams, 'content')) {\n const id = await createInterface(\n origin,\n validatedParams.content as ComponentOrElement,\n undefined,\n ContentType.Notification,\n );\n validatedParams.content = id;\n }\n\n switch (validatedParams.type) {\n case NotificationType.Native:\n return await showNativeNotification(origin, validatedParams);\n case NotificationType.InApp:\n return await showInAppNotification(origin, validatedParams);\n default:\n throw rpcErrors.invalidParams({\n message: 'Must specify a valid notification \"type\".',\n });\n }\n };\n}\n\n/**\n * Validates the notify 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 isOnPhishingList - The function that checks for links against the phishing list.\n * @param getSnap - A function that checks if a snap is installed.\n * @returns The validated method parameter object.\n * @throws If the params are invalid.\n */\nexport function getValidatedParams(\n params: unknown,\n isOnPhishingList: NotifyMethodHooks['isOnPhishingList'],\n getSnap: NotifyMethodHooks['getSnap'],\n): NotifyParams {\n if (!isObject(params)) {\n throw rpcErrors.invalidParams({\n message: 'Expected params to be a single object.',\n });\n }\n\n const { type, message } = params;\n\n if (\n !type ||\n typeof type !== 'string' ||\n !Object.values(NotificationType).includes(type as NotificationType)\n ) {\n throw rpcErrors.invalidParams({\n message: 'Must specify a valid notification \"type\".',\n });\n }\n\n const isNotString = !message || typeof message !== 'string';\n // Set to the max message length on a Mac notification for now.\n if (\n type === NotificationType.Native &&\n (isNotString || message.length >= 50)\n ) {\n throw rpcErrors.invalidParams({\n message:\n 'Must specify a non-empty string \"message\" less than 50 characters long.',\n });\n }\n\n if (\n type === NotificationType.InApp &&\n (isNotString || message.length >= 500)\n ) {\n throw rpcErrors.invalidParams({\n message:\n 'Must specify a non-empty string \"message\" less than 500 characters long.',\n });\n }\n\n try {\n const validatedParams = createUnion(\n params,\n NotificationParametersStruct,\n 'type',\n );\n\n validateTextLinks(validatedParams.message, isOnPhishingList, getSnap);\n\n if (hasProperty(validatedParams, 'footerLink')) {\n validateLink(validatedParams.footerLink.href, isOnPhishingList, getSnap);\n }\n\n return validatedParams;\n } catch (error) {\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${getErrorMessage(error)}`,\n });\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"notify.cjs","sourceRoot":"","sources":["../../src/restricted/notify.ts"],"names":[],"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,MAAM,eAAe,GAAG,IAAA,yBAAW,EACjC,MAAM,EACN,4BAA4B,EAC5B,MAAM,CACP,CAAC;QAEF,IAAA,+BAAiB,EAAC,eAAe,CAAC,OAAO,EAAE,gBAAgB,EAAE,OAAO,CAAC,CAAC;QAEtE,IAAI,IAAA,mBAAW,EAAC,eAAe,EAAE,YAAY,CAAC,EAAE,CAAC;YAC/C,IAAA,0BAAY,EAAC,eAAe,CAAC,UAAU,CAAC,IAAI,EAAE,gBAAgB,EAAE,OAAO,CAAC,CAAC;QAC3E,CAAC;QAED,OAAO,eAAe,CAAC;IACzB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,sBAAS,CAAC,aAAa,CAAC;YAC5B,OAAO,EAAE,mBAAmB,IAAA,2BAAe,EAAC,KAAK,CAAC,EAAE;SACrD,CAAC,CAAC;IACL,CAAC;AACH,CAAC;AAhED,gDAgEC","sourcesContent":["import 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 {\n NotifyParams,\n NotifyResult,\n InterfaceContext,\n ComponentOrElement,\n} from '@metamask/snaps-sdk';\nimport {\n enumValue,\n NotificationType,\n union,\n ContentType,\n getErrorMessage,\n ComponentOrElementStruct,\n} from '@metamask/snaps-sdk';\nimport {\n createUnion,\n validateLink,\n validateTextLinks,\n} from '@metamask/snaps-utils';\nimport type { InferMatching, Snap } from '@metamask/snaps-utils';\nimport { object, string, optional } from '@metamask/superstruct';\nimport type { NonEmptyArray } from '@metamask/utils';\nimport { hasProperty, isObject } from '@metamask/utils';\n\nimport { type MethodHooksObject } from '../utils';\n\nconst methodName = 'snap_notify';\n\nconst NativeNotificationStruct = object({\n type: enumValue(NotificationType.Native),\n message: string(),\n});\n\nconst InAppNotificationStruct = object({\n type: enumValue(NotificationType.InApp),\n message: string(),\n});\n\nconst InAppNotificationWithDetailsStruct = object({\n type: enumValue(NotificationType.InApp),\n message: string(),\n content: ComponentOrElementStruct,\n title: string(),\n footerLink: optional(\n object({\n href: string(),\n text: string(),\n }),\n ),\n});\n\nconst NotificationParametersStruct = union([\n InAppNotificationStruct,\n InAppNotificationWithDetailsStruct,\n NativeNotificationStruct,\n]);\n\nexport type NotificationArgs = InferMatching<\n typeof NotificationParametersStruct,\n NotifyParams\n>;\n\nexport type NotifyMethodHooks = {\n /**\n * @param snapId - The ID of the Snap that created the notification.\n * @param args - The notification arguments.\n */\n showNativeNotification: (\n snapId: string,\n args: NotificationArgs,\n ) => Promise<null>;\n\n /**\n * @param snapId - The ID of the Snap that created the notification.\n * @param args - The notification arguments.\n */\n showInAppNotification: (\n snapId: string,\n args: NotificationArgs,\n ) => Promise<null>;\n\n isOnPhishingList: (url: string) => boolean;\n\n maybeUpdatePhishingList: () => Promise<void>;\n\n createInterface: (\n origin: string,\n content: ComponentOrElement,\n context?: InterfaceContext,\n contentType?: ContentType,\n ) => Promise<string>;\n getSnap: (snapId: string) => Snap | undefined;\n};\n\ntype SpecificationBuilderOptions = {\n allowedCaveats?: Readonly<NonEmptyArray<string>> | null;\n methodHooks: NotifyMethodHooks;\n};\n\ntype Specification = ValidPermissionSpecification<{\n permissionType: PermissionType.RestrictedMethod;\n targetName: typeof methodName;\n methodImplementation: ReturnType<typeof getImplementation>;\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n}>;\n\n/**\n * The specification builder for the `snap_notify` permission.\n * `snap_notify` allows snaps to send multiple types of notifications to its users.\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_notify` permission.\n */\nexport const specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.RestrictedMethod,\n SpecificationBuilderOptions,\n Specification\n> = ({ allowedCaveats = null, methodHooks }: SpecificationBuilderOptions) => {\n return {\n permissionType: PermissionType.RestrictedMethod,\n targetName: methodName,\n allowedCaveats,\n methodImplementation: getImplementation(methodHooks),\n subjectTypes: [SubjectType.Snap],\n };\n};\n\nconst methodHooks: MethodHooksObject<NotifyMethodHooks> = {\n showNativeNotification: true,\n showInAppNotification: true,\n isOnPhishingList: true,\n maybeUpdatePhishingList: true,\n createInterface: true,\n getSnap: true,\n};\n\nexport const notifyBuilder = Object.freeze({\n targetName: methodName,\n specificationBuilder,\n methodHooks,\n} as const);\n\n/**\n * Builds the method implementation for `snap_notify`.\n *\n * @param hooks - The RPC method hooks.\n * @param hooks.showNativeNotification - A function that shows a native browser notification.\n * @param hooks.showInAppNotification - A function that shows a notification in the MetaMask UI.\n * @param hooks.isOnPhishingList - A function that checks for links against the phishing list.\n * @param hooks.maybeUpdatePhishingList - A function that updates the phishing list if needed.\n * @param hooks.createInterface - A function that creates the interface in SnapInterfaceController.\n * @param hooks.getSnap - A function that checks if a snap is installed.\n * @returns The method implementation which returns `null` on success.\n * @throws If the params are invalid.\n */\nexport function getImplementation({\n showNativeNotification,\n showInAppNotification,\n isOnPhishingList,\n maybeUpdatePhishingList,\n createInterface,\n getSnap,\n}: NotifyMethodHooks) {\n return async function implementation(\n args: RestrictedMethodOptions<NotifyParams>,\n ): Promise<NotifyResult> {\n const {\n params,\n context: { origin },\n } = args;\n\n await maybeUpdatePhishingList();\n\n const validatedParams = getValidatedParams(\n params,\n isOnPhishingList,\n getSnap,\n );\n\n if (hasProperty(validatedParams, 'content')) {\n const id = await createInterface(\n origin,\n validatedParams.content as ComponentOrElement,\n undefined,\n ContentType.Notification,\n );\n validatedParams.content = id;\n }\n\n switch (validatedParams.type) {\n case NotificationType.Native:\n return await showNativeNotification(origin, validatedParams);\n case NotificationType.InApp:\n return await showInAppNotification(origin, validatedParams);\n default:\n throw rpcErrors.invalidParams({\n message: 'Must specify a valid notification \"type\".',\n });\n }\n };\n}\n\n/**\n * Validates the notify 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 isOnPhishingList - The function that checks for links against the phishing list.\n * @param getSnap - A function that checks if a snap is installed.\n * @returns The validated method parameter object.\n * @throws If the params are invalid.\n */\nexport function getValidatedParams(\n params: unknown,\n isOnPhishingList: NotifyMethodHooks['isOnPhishingList'],\n getSnap: NotifyMethodHooks['getSnap'],\n): NotifyParams {\n if (!isObject(params)) {\n throw rpcErrors.invalidParams({\n message: 'Expected params to be a single object.',\n });\n }\n\n const { type, message } = params;\n\n if (\n !type ||\n typeof type !== 'string' ||\n !Object.values(NotificationType).includes(type as NotificationType)\n ) {\n throw rpcErrors.invalidParams({\n message: 'Must specify a valid notification \"type\".',\n });\n }\n\n const isNotString = !message || typeof message !== 'string';\n // Set to the max message length on a Mac notification for now.\n if (\n type === NotificationType.Native &&\n (isNotString || message.length >= 50)\n ) {\n throw rpcErrors.invalidParams({\n message:\n 'Must specify a non-empty string \"message\" less than 50 characters long.',\n });\n }\n\n if (\n type === NotificationType.InApp &&\n (isNotString || message.length >= 500)\n ) {\n throw rpcErrors.invalidParams({\n message:\n 'Must specify a non-empty string \"message\" less than 500 characters long.',\n });\n }\n\n try {\n const validatedParams = createUnion(\n params,\n NotificationParametersStruct,\n 'type',\n );\n\n validateTextLinks(validatedParams.message, isOnPhishingList, getSnap);\n\n if (hasProperty(validatedParams, 'footerLink')) {\n validateLink(validatedParams.footerLink.href, isOnPhishingList, getSnap);\n }\n\n return validatedParams;\n } catch (error) {\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${getErrorMessage(error)}`,\n });\n }\n}\n"]}
|
|
@@ -2,8 +2,7 @@ import type { PermissionSpecificationBuilder, RestrictedMethodOptions, ValidPerm
|
|
|
2
2
|
import { PermissionType } from "@metamask/permission-controller";
|
|
3
3
|
import type { NotifyParams, NotifyResult, InterfaceContext, ComponentOrElement } from "@metamask/snaps-sdk";
|
|
4
4
|
import { ContentType } from "@metamask/snaps-sdk";
|
|
5
|
-
import {
|
|
6
|
-
import type { InferMatching } from "@metamask/snaps-utils";
|
|
5
|
+
import type { InferMatching, Snap } from "@metamask/snaps-utils";
|
|
7
6
|
import type { NonEmptyArray } from "@metamask/utils";
|
|
8
7
|
import { type MethodHooksObject } from "../utils.cjs";
|
|
9
8
|
declare const methodName = "snap_notify";
|
|
@@ -23,10 +22,7 @@ declare const NotificationParametersStruct: import("@metamask/superstruct").Stru
|
|
|
23
22
|
} | {
|
|
24
23
|
type: import("@metamask/snaps-sdk").NodeType.Divider;
|
|
25
24
|
} | {
|
|
26
|
-
type: import("@metamask/snaps-sdk").NodeType.Heading;
|
|
27
|
-
* @param snapId - The ID of the Snap that created the notification.
|
|
28
|
-
* @param args - The notification arguments.
|
|
29
|
-
*/
|
|
25
|
+
type: import("@metamask/snaps-sdk").NodeType.Heading;
|
|
30
26
|
value: string;
|
|
31
27
|
} | {
|
|
32
28
|
type: import("@metamask/snaps-sdk").NodeType.Image;
|
|
@@ -125,10 +121,7 @@ declare const NotificationParametersStruct: import("@metamask/superstruct").Stru
|
|
|
125
121
|
} | {
|
|
126
122
|
type: import("@metamask/snaps-sdk").NodeType.Divider;
|
|
127
123
|
} | {
|
|
128
|
-
type: import("@metamask/snaps-sdk").NodeType.Heading;
|
|
129
|
-
* @param snapId - The ID of the Snap that created the notification.
|
|
130
|
-
* @param args - The notification arguments.
|
|
131
|
-
*/
|
|
124
|
+
type: import("@metamask/snaps-sdk").NodeType.Heading;
|
|
132
125
|
value: string;
|
|
133
126
|
} | {
|
|
134
127
|
type: import("@metamask/snaps-sdk").NodeType.Image;
|
|
@@ -221,10 +214,7 @@ declare const NotificationParametersStruct: import("@metamask/superstruct").Stru
|
|
|
221
214
|
} | {
|
|
222
215
|
type: import("@metamask/snaps-sdk").NodeType.Divider;
|
|
223
216
|
} | {
|
|
224
|
-
type: import("@metamask/snaps-sdk").NodeType.Heading;
|
|
225
|
-
* @param snapId - The ID of the Snap that created the notification.
|
|
226
|
-
* @param args - The notification arguments.
|
|
227
|
-
*/
|
|
217
|
+
type: import("@metamask/snaps-sdk").NodeType.Heading;
|
|
228
218
|
value: string;
|
|
229
219
|
} | {
|
|
230
220
|
type: import("@metamask/snaps-sdk").NodeType.Image;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notify.d.cts","sourceRoot":"","sources":["../../src/restricted/notify.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,8BAA8B,EAC9B,uBAAuB,EACvB,4BAA4B,EAC7B,wCAAwC;AACzC,OAAO,EAAE,cAAc,EAAe,wCAAwC;AAE9E,OAAO,KAAK,EACV,YAAY,EACZ,YAAY,EACZ,gBAAgB,EAChB,kBAAkB,EACnB,4BAA4B;AAC7B,OAAO,EAIL,WAAW,EAGZ,4BAA4B;
|
|
1
|
+
{"version":3,"file":"notify.d.cts","sourceRoot":"","sources":["../../src/restricted/notify.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,8BAA8B,EAC9B,uBAAuB,EACvB,4BAA4B,EAC7B,wCAAwC;AACzC,OAAO,EAAE,cAAc,EAAe,wCAAwC;AAE9E,OAAO,KAAK,EACV,YAAY,EACZ,YAAY,EACZ,gBAAgB,EAChB,kBAAkB,EACnB,4BAA4B;AAC7B,OAAO,EAIL,WAAW,EAGZ,4BAA4B;AAM7B,OAAO,KAAK,EAAE,aAAa,EAAE,IAAI,EAAE,8BAA8B;AAEjE,OAAO,KAAK,EAAE,aAAa,EAAE,wBAAwB;AAGrD,OAAO,EAAE,KAAK,iBAAiB,EAAE,qBAAiB;AAElD,QAAA,MAAM,UAAU,gBAAgB,CAAC;AAyBjC,QAAA,MAAM,4BAA4B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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