@metamask/snaps-rpc-methods 9.1.4 → 10.0.1
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 +25 -1
- package/dist/{chunk-KIXPIIY5.mjs → chunk-2RDYC42U.mjs} +2 -2
- package/dist/chunk-2RDYC42U.mjs.map +1 -0
- package/dist/{chunk-4BPNRCZJ.js → chunk-4PWFZPJC.js} +2 -2
- package/dist/chunk-4PWFZPJC.js.map +1 -0
- package/dist/{chunk-B53MDMPL.js → chunk-4TUORIA6.js} +6 -6
- package/dist/{chunk-IC5BIIRG.js → chunk-6VJVURH5.js} +11 -11
- package/dist/{chunk-QKZO7EUA.js → chunk-756OQVOC.js} +2 -2
- package/dist/chunk-756OQVOC.js.map +1 -0
- package/dist/{chunk-4W7U4OH6.js → chunk-7CV677MM.js} +2 -2
- package/dist/chunk-7CV677MM.js.map +1 -0
- package/dist/{chunk-3XL562LA.mjs → chunk-7P6TF6CE.mjs} +10 -6
- package/dist/chunk-7P6TF6CE.mjs.map +1 -0
- package/dist/{chunk-P74WXDY4.js → chunk-A6H6I4VH.js} +9 -2
- package/dist/{chunk-P74WXDY4.js.map → chunk-A6H6I4VH.js.map} +1 -1
- package/dist/{chunk-QSVAU6X4.js → chunk-ATBKAX2S.js} +3 -3
- package/dist/{chunk-43UTAOW7.mjs → chunk-BSAXPL2T.mjs} +3 -3
- package/dist/{chunk-I7DR6BFO.js → chunk-ELCOEVKA.js} +65 -20
- package/dist/chunk-ELCOEVKA.js.map +1 -0
- package/dist/{chunk-NP3KGMVC.js → chunk-EOXTZF5U.js} +2 -2
- package/dist/chunk-EOXTZF5U.js.map +1 -0
- package/dist/{chunk-R4PZNFIL.mjs → chunk-FJ7COFRJ.mjs} +2 -2
- package/dist/chunk-FJ7COFRJ.mjs.map +1 -0
- package/dist/{chunk-PCIEMFOB.mjs → chunk-FNUO7MQ4.mjs} +6 -6
- package/dist/{chunk-I6FU5MGE.mjs → chunk-GPV4ETUH.mjs} +2 -2
- package/dist/chunk-GPV4ETUH.mjs.map +1 -0
- package/dist/{chunk-NE55M45Y.js → chunk-H6X3CWWQ.js} +2 -2
- package/dist/chunk-H6X3CWWQ.js.map +1 -0
- package/dist/{chunk-O2VSIMDY.js → chunk-HZQ34FQT.js} +14 -14
- package/dist/{chunk-O2VSIMDY.js.map → chunk-HZQ34FQT.js.map} +1 -1
- package/dist/{chunk-OHEJDJNV.mjs → chunk-I2P65KBQ.mjs} +2 -2
- package/dist/chunk-I2P65KBQ.mjs.map +1 -0
- package/dist/chunk-MC2Z4NF6.mjs +45 -0
- package/dist/chunk-MC2Z4NF6.mjs.map +1 -0
- package/dist/{chunk-PPR53SPJ.js → chunk-OI33OL7K.js} +2 -2
- package/dist/chunk-OI33OL7K.js.map +1 -0
- package/dist/{chunk-I3QG3QZL.mjs → chunk-SYB5TG5O.mjs} +10 -10
- package/dist/{chunk-I3QG3QZL.mjs.map → chunk-SYB5TG5O.mjs.map} +1 -1
- package/dist/{chunk-X247BMMW.mjs → chunk-TQCUJQHY.mjs} +64 -19
- package/dist/chunk-TQCUJQHY.mjs.map +1 -0
- package/dist/{chunk-TJYMYQAB.mjs → chunk-TVC3E5LI.mjs} +2 -2
- package/dist/chunk-TVC3E5LI.mjs.map +1 -0
- package/dist/{chunk-D5WQBUZB.js → chunk-U6TJQLNV.js} +2 -2
- package/dist/chunk-U6TJQLNV.js.map +1 -0
- package/dist/chunk-UCWANXBZ.js +45 -0
- package/dist/chunk-UCWANXBZ.js.map +1 -0
- package/dist/{chunk-F3VP6B2X.js → chunk-UF3UJTY3.js} +13 -9
- package/dist/chunk-UF3UJTY3.js.map +1 -0
- package/dist/{chunk-GVJLWGSI.mjs → chunk-UY4DUF53.mjs} +2 -2
- package/dist/chunk-UY4DUF53.mjs.map +1 -0
- package/dist/{chunk-R3DRYUNH.mjs → chunk-VYII7C3J.mjs} +2 -2
- package/dist/chunk-VYII7C3J.mjs.map +1 -0
- package/dist/{chunk-WEUKWKAQ.mjs → chunk-XGMYBPQR.mjs} +2 -2
- package/dist/chunk-XGMYBPQR.mjs.map +1 -0
- package/dist/{chunk-E6WUMFQT.mjs → chunk-Z6YFGWHN.mjs} +9 -2
- package/dist/chunk-Z6YFGWHN.mjs.map +1 -0
- package/dist/{chunk-IVD2ORDS.js → chunk-ZKISN6YP.js} +2 -2
- package/dist/chunk-ZKISN6YP.js.map +1 -0
- package/dist/{chunk-T3O2PFSR.mjs → chunk-ZXDCQWMJ.mjs} +2 -2
- package/dist/index.js +21 -17
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +20 -16
- package/dist/index.mjs.map +1 -1
- package/dist/permissions.js +11 -11
- package/dist/permissions.mjs +10 -10
- package/dist/permitted/createInterface.js +2 -2
- package/dist/permitted/createInterface.mjs +1 -1
- package/dist/permitted/getFile.js +2 -2
- package/dist/permitted/getFile.mjs +1 -1
- package/dist/permitted/getInterfaceState.js +2 -2
- package/dist/permitted/getInterfaceState.mjs +1 -1
- package/dist/permitted/handlers.js +7 -6
- package/dist/permitted/handlers.mjs +6 -5
- package/dist/permitted/index.js +8 -7
- package/dist/permitted/index.mjs +7 -6
- package/dist/permitted/middleware.js +8 -7
- package/dist/permitted/middleware.mjs +7 -6
- package/dist/permitted/resolveInterface.js +7 -0
- package/dist/permitted/resolveInterface.js.map +1 -0
- package/dist/permitted/resolveInterface.mjs +7 -0
- package/dist/permitted/resolveInterface.mjs.map +1 -0
- package/dist/permitted/updateInterface.js +2 -2
- package/dist/permitted/updateInterface.mjs +1 -1
- package/dist/restricted/caveats/index.js +5 -5
- package/dist/restricted/caveats/index.mjs +4 -4
- package/dist/restricted/caveats/permittedDerivationPaths.js +2 -2
- package/dist/restricted/caveats/permittedDerivationPaths.mjs +1 -1
- package/dist/restricted/caveats/snapIds.js +2 -2
- package/dist/restricted/caveats/snapIds.mjs +1 -1
- package/dist/restricted/dialog.js +4 -2
- package/dist/restricted/dialog.mjs +3 -1
- package/dist/restricted/getBip32PublicKey.js +2 -2
- package/dist/restricted/getBip32PublicKey.mjs +1 -1
- package/dist/restricted/getEntropy.js +2 -2
- package/dist/restricted/getEntropy.mjs +1 -1
- package/dist/restricted/index.js +13 -10
- package/dist/restricted/index.mjs +12 -9
- package/dist/restricted/manageAccounts.js +2 -2
- package/dist/restricted/manageAccounts.mjs +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/permitted/createInterface.d.ts +4 -4
- package/dist/types/permitted/getFile.d.ts +3 -3
- package/dist/types/permitted/getInterfaceState.d.ts +2 -2
- package/dist/types/permitted/handlers.d.ts +2 -1
- package/dist/types/permitted/index.d.ts +2 -1
- package/dist/types/permitted/resolveInterface.d.ts +21 -0
- package/dist/types/permitted/updateInterface.d.ts +4 -4
- package/dist/types/restricted/dialog.d.ts +353 -24
- package/dist/types/restricted/getBip32PublicKey.d.ts +4 -4
- package/dist/types/restricted/getEntropy.d.ts +4 -4
- package/dist/types/restricted/index.d.ts +3 -1
- package/dist/types/restricted/manageAccounts.d.ts +1 -1
- package/package.json +10 -10
- package/dist/chunk-3XL562LA.mjs.map +0 -1
- package/dist/chunk-4BPNRCZJ.js.map +0 -1
- package/dist/chunk-4W7U4OH6.js.map +0 -1
- package/dist/chunk-D5WQBUZB.js.map +0 -1
- package/dist/chunk-E6WUMFQT.mjs.map +0 -1
- package/dist/chunk-F3VP6B2X.js.map +0 -1
- package/dist/chunk-GVJLWGSI.mjs.map +0 -1
- package/dist/chunk-I6FU5MGE.mjs.map +0 -1
- package/dist/chunk-I7DR6BFO.js.map +0 -1
- package/dist/chunk-IVD2ORDS.js.map +0 -1
- package/dist/chunk-KIXPIIY5.mjs.map +0 -1
- package/dist/chunk-NE55M45Y.js.map +0 -1
- package/dist/chunk-NP3KGMVC.js.map +0 -1
- package/dist/chunk-OHEJDJNV.mjs.map +0 -1
- package/dist/chunk-PPR53SPJ.js.map +0 -1
- package/dist/chunk-QKZO7EUA.js.map +0 -1
- package/dist/chunk-R3DRYUNH.mjs.map +0 -1
- package/dist/chunk-R4PZNFIL.mjs.map +0 -1
- package/dist/chunk-TJYMYQAB.mjs.map +0 -1
- package/dist/chunk-WEUKWKAQ.mjs.map +0 -1
- package/dist/chunk-X247BMMW.mjs.map +0 -1
- /package/dist/{chunk-B53MDMPL.js.map → chunk-4TUORIA6.js.map} +0 -0
- /package/dist/{chunk-IC5BIIRG.js.map → chunk-6VJVURH5.js.map} +0 -0
- /package/dist/{chunk-QSVAU6X4.js.map → chunk-ATBKAX2S.js.map} +0 -0
- /package/dist/{chunk-43UTAOW7.mjs.map → chunk-BSAXPL2T.mjs.map} +0 -0
- /package/dist/{chunk-PCIEMFOB.mjs.map → chunk-FNUO7MQ4.mjs.map} +0 -0
- /package/dist/{chunk-T3O2PFSR.mjs.map → chunk-ZXDCQWMJ.mjs.map} +0 -0
|
@@ -19,14 +19,14 @@ export declare type GetBip32PublicKeyMethodHooks = {
|
|
|
19
19
|
declare type GetBip32PublicKeySpecificationBuilderOptions = {
|
|
20
20
|
methodHooks: GetBip32PublicKeyMethodHooks;
|
|
21
21
|
};
|
|
22
|
-
export declare const Bip32PublicKeyArgsStruct: import("superstruct").Struct<{
|
|
22
|
+
export declare const Bip32PublicKeyArgsStruct: import("@metamask/superstruct").Struct<{
|
|
23
23
|
path: string[];
|
|
24
24
|
curve: "ed25519" | "ed25519Bip32" | "secp256k1";
|
|
25
25
|
compressed?: boolean | undefined;
|
|
26
26
|
}, {
|
|
27
|
-
path: import("superstruct").Struct<string[], import("superstruct").Struct<string, null>>;
|
|
28
|
-
curve: import("superstruct").Describe<"ed25519" | "ed25519Bip32" | "secp256k1">;
|
|
29
|
-
compressed: import("superstruct").Struct<boolean | undefined, null>;
|
|
27
|
+
path: import("@metamask/superstruct").Struct<string[], import("@metamask/superstruct").Struct<string, null>>;
|
|
28
|
+
curve: import("@metamask/superstruct").Describe<"ed25519" | "ed25519Bip32" | "secp256k1">;
|
|
29
|
+
compressed: import("@metamask/superstruct").Struct<boolean | undefined, null>;
|
|
30
30
|
}>;
|
|
31
31
|
export declare const getBip32PublicKeyBuilder: Readonly<{
|
|
32
32
|
readonly targetName: "snap_getBip32PublicKey";
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import type { PermissionSpecificationBuilder, RestrictedMethodOptions } from '@metamask/permission-controller';
|
|
2
2
|
import { PermissionType } from '@metamask/permission-controller';
|
|
3
3
|
import type { GetEntropyParams, GetEntropyResult } from '@metamask/snaps-sdk';
|
|
4
|
+
import type { Infer } from '@metamask/superstruct';
|
|
4
5
|
import type { NonEmptyArray } from '@metamask/utils';
|
|
5
|
-
import type { Infer } from 'superstruct';
|
|
6
6
|
import type { MethodHooksObject } from '../utils';
|
|
7
7
|
declare const targetName = "snap_getEntropy";
|
|
8
8
|
declare type GetEntropySpecificationBuilderOptions = {
|
|
9
9
|
allowedCaveats?: Readonly<NonEmptyArray<string>> | null;
|
|
10
10
|
methodHooks: GetEntropyHooks;
|
|
11
11
|
};
|
|
12
|
-
export declare const GetEntropyArgsStruct: import("superstruct").Struct<{
|
|
12
|
+
export declare const GetEntropyArgsStruct: import("@metamask/superstruct").Struct<{
|
|
13
13
|
version: 1;
|
|
14
14
|
salt?: string | undefined;
|
|
15
15
|
}, {
|
|
16
|
-
version: import("superstruct").Struct<1, 1>;
|
|
17
|
-
salt: import("superstruct").Struct<string | undefined, null>;
|
|
16
|
+
version: import("@metamask/superstruct").Struct<1, 1>;
|
|
17
|
+
salt: import("@metamask/superstruct").Struct<string | undefined, null>;
|
|
18
18
|
}>;
|
|
19
19
|
/**
|
|
20
20
|
* @property version - The version of the `snap_getEntropy` method. This must be
|
|
@@ -20,7 +20,7 @@ export declare const restrictedMethodPermissionBuilders: {
|
|
|
20
20
|
}, {
|
|
21
21
|
permissionType: import("@metamask/permission-controller").PermissionType.RestrictedMethod;
|
|
22
22
|
targetName: "snap_dialog";
|
|
23
|
-
methodImplementation: (args: import("@metamask/permission-controller").RestrictedMethodOptions<import("@metamask/snaps-sdk").DialogParams>) => Promise<
|
|
23
|
+
methodImplementation: (args: import("@metamask/permission-controller").RestrictedMethodOptions<import("@metamask/snaps-sdk").DialogParams>) => Promise<import("@metamask/utils").Json>;
|
|
24
24
|
allowedCaveats: readonly [string, ...string[]] | null;
|
|
25
25
|
}>;
|
|
26
26
|
readonly methodHooks: import("../utils").MethodHooksObject<DialogMethodHooks>;
|
|
@@ -150,3 +150,5 @@ export declare const restrictedMethodPermissionBuilders: {
|
|
|
150
150
|
}>;
|
|
151
151
|
};
|
|
152
152
|
export * from './caveats';
|
|
153
|
+
export type { DialogApprovalTypes } from './dialog';
|
|
154
|
+
export { DIALOG_APPROVAL_TYPES } from './dialog';
|
|
@@ -3,7 +3,7 @@ import { PermissionType } from '@metamask/permission-controller';
|
|
|
3
3
|
import type { ManageAccountsParams, ManageAccountsResult } from '@metamask/snaps-sdk';
|
|
4
4
|
import type { InferMatching } from '@metamask/snaps-utils';
|
|
5
5
|
import type { Json, NonEmptyArray } from '@metamask/utils';
|
|
6
|
-
declare const SnapMessageStruct: import("superstruct").Struct<{
|
|
6
|
+
declare const SnapMessageStruct: import("@metamask/superstruct").Struct<{
|
|
7
7
|
method: string;
|
|
8
8
|
} | {
|
|
9
9
|
method: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask/snaps-rpc-methods",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "10.0.1",
|
|
4
4
|
"description": "MetaMask Snaps JSON-RPC method implementations.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -39,14 +39,14 @@
|
|
|
39
39
|
"build:ci": "tsup --clean"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@metamask/key-tree": "^9.1.
|
|
43
|
-
"@metamask/permission-controller": "^
|
|
44
|
-
"@metamask/rpc-errors": "^6.
|
|
45
|
-
"@metamask/snaps-sdk": "^6.
|
|
46
|
-
"@metamask/snaps-utils": "^7.
|
|
47
|
-
"@metamask/
|
|
48
|
-
"@
|
|
49
|
-
"
|
|
42
|
+
"@metamask/key-tree": "^9.1.2",
|
|
43
|
+
"@metamask/permission-controller": "^11.0.0",
|
|
44
|
+
"@metamask/rpc-errors": "^6.3.1",
|
|
45
|
+
"@metamask/snaps-sdk": "^6.1.0",
|
|
46
|
+
"@metamask/snaps-utils": "^7.8.1",
|
|
47
|
+
"@metamask/superstruct": "^3.1.0",
|
|
48
|
+
"@metamask/utils": "^9.1.0",
|
|
49
|
+
"@noble/hashes": "^1.3.1"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@lavamoat/allow-scripts": "^3.0.4",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"@metamask/eslint-config-jest": "^12.1.0",
|
|
56
56
|
"@metamask/eslint-config-nodejs": "^12.1.0",
|
|
57
57
|
"@metamask/eslint-config-typescript": "^12.1.0",
|
|
58
|
-
"@metamask/json-rpc-engine": "^9.0.
|
|
58
|
+
"@metamask/json-rpc-engine": "^9.0.2",
|
|
59
59
|
"@swc/core": "1.3.78",
|
|
60
60
|
"@swc/jest": "^0.2.26",
|
|
61
61
|
"@types/node": "18.14.2",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/permitted/handlers.ts"],"sourcesContent":["import { createInterfaceHandler } from './createInterface';\nimport { getAllSnapsHandler } from './getAllSnaps';\nimport { getClientStatusHandler } from './getClientStatus';\nimport { getFileHandler } from './getFile';\nimport { getInterfaceStateHandler } from './getInterfaceState';\nimport { getSnapsHandler } from './getSnaps';\nimport { invokeKeyringHandler } from './invokeKeyring';\nimport { invokeSnapSugarHandler } from './invokeSnapSugar';\nimport { requestSnapsHandler } from './requestSnaps';\nimport { updateInterfaceHandler } from './updateInterface';\n\n/* eslint-disable @typescript-eslint/naming-convention */\nexport const methodHandlers = {\n wallet_getAllSnaps: getAllSnapsHandler,\n wallet_getSnaps: getSnapsHandler,\n wallet_requestSnaps: requestSnapsHandler,\n wallet_invokeSnap: invokeSnapSugarHandler,\n wallet_invokeKeyring: invokeKeyringHandler,\n snap_getClientStatus: getClientStatusHandler,\n snap_getFile: getFileHandler,\n snap_createInterface: createInterfaceHandler,\n snap_updateInterface: updateInterfaceHandler,\n snap_getInterfaceState: getInterfaceStateHandler,\n};\n/* eslint-enable @typescript-eslint/naming-convention */\n\nexport const handlers = Object.values(methodHandlers);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAYO,IAAM,iBAAiB;AAAA,EAC5B,oBAAoB;AAAA,EACpB,iBAAiB;AAAA,EACjB,qBAAqB;AAAA,EACrB,mBAAmB;AAAA,EACnB,sBAAsB;AAAA,EACtB,sBAAsB;AAAA,EACtB,cAAc;AAAA,EACd,sBAAsB;AAAA,EACtB,sBAAsB;AAAA,EACtB,wBAAwB;AAC1B;AAGO,IAAM,WAAW,OAAO,OAAO,cAAc;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/restricted/getBip32PublicKey.ts"],"names":["methodHooks"],"mappings":";;;;;AAMA,SAAS,gBAAgB,mBAAmB;AAC5C,SAAS,iBAAiB;AAK1B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,oBAAoB;AAC7B,SAAS,SAAS,QAAQ,gBAAgB;AAK1C,IAAM,aAAa;AA4BZ,IAAM,2BAA2B;AAAA,EACtC,OAAO;AAAA,IACL,MAAM;AAAA,IACN,OAAO;AAAA,IACP,YAAY,SAAS,QAAQ,CAAC;AAAA,EAChC,CAAC;AACH;AAWA,IAAM,uBAIF,CAAC,EAAE,aAAAA,aAAY,MAAoD;AACrE,SAAO;AAAA,IACL,gBAAgB,eAAe;AAAA,IAC/B;AAAA,IACA,gBAAgB,CAAC,eAAe,wBAAwB;AAAA,IACxD,sBAAsB,gCAAgCA,YAAW;AAAA,IACjE,WAAW,CAAC,EAAE,QAAQ,MAAM;AAC1B,UACE,SAAS,WAAW,KACpB,QAAQ,CAAC,EAAE,SAAS,eAAe,0BACnC;AACA,cAAM,UAAU,cAAc;AAAA,UAC5B,SAAS,sBAAsB,eAAe,wBAAwB;AAAA,QACxE,CAAC;AAAA,MACH;AAAA,IACF;AAAA,IACA,cAAc,CAAC,YAAY,IAAI;AAAA,EACjC;AACF;AAEA,IAAM,cAA+D;AAAA,EACnE,aAAa;AAAA,EACb,kBAAkB;AACpB;AAEO,IAAM,2BAA2B,OAAO,OAAO;AAAA,EACpD;AAAA,EACA;AAAA,EACA;AACF,CAAU;AAYH,SAAS,gCAAgC;AAAA,EAC9C;AAAA,EACA;AACF,GAAiC;AAC/B,SAAO,eAAe,kBACpB,MACkC;AAClC,UAAM,iBAAiB,IAAI;AAE3B;AAAA,MACE,KAAK;AAAA,MACL;AAAA,MACA;AAAA,MACA,UAAU;AAAA,IACZ;AAEA,UAAM,EAAE,OAAO,IAAI;AACnB,UAAM,OAAO,MAAM,QAAQ;AAAA,MACzB,OAAO,OAAO;AAAA,MACd,MAAM,OAAO;AAAA,MACb,sBAAsB,MAAM,YAAY;AAAA,IAC1C,CAAC;AAED,QAAI,OAAO,YAAY;AACrB,aAAO,KAAK;AAAA,IACd;AAEA,WAAO,KAAK;AAAA,EACd;AACF","sourcesContent":["import 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 type { NonEmptyArray } from '@metamask/utils';\nimport { assertStruct } from '@metamask/utils';\nimport { boolean, object, optional } from 'superstruct';\n\nimport type { MethodHooksObject } from '../utils';\nimport { getNode } from '../utils';\n\nconst targetName = 'snap_getBip32PublicKey';\n\nexport type GetBip32PublicKeyMethodHooks = {\n /**\n * @returns The mnemonic of the user's primary keyring.\n */\n getMnemonic: () => 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\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 }),\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};\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 * @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}: 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 node = await getNode({\n curve: params.curve,\n path: params.path,\n secretRecoveryPhrase: await getMnemonic(),\n });\n\n if (params.compressed) {\n return node.compressedPublicKey;\n }\n\n return node.publicKey;\n };\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/permitted/getInterfaceState.ts"],"names":[],"mappings":";AAEA,SAAS,iBAAiB;AAS1B,SAAS,aAAa,QAAQ,QAAQ,cAAc;AAIpD,IAAM,YAA6D;AAAA,EACjE,mBAAmB;AACrB;AAUO,IAAM,2BAIT;AAAA,EACF,aAAa,CAAC,wBAAwB;AAAA,EACtC,gBAAgB;AAAA,EAChB;AACF;AAEA,IAAM,oCAAoC,OAAO;AAAA,EAC/C,IAAI,OAAO;AACb,CAAC;AAmBD,SAAS,mCACP,KACA,KACA,OACA,KACA,EAAE,kBAAkB,GACd;AACN,QAAM,EAAE,OAAO,IAAI;AAEnB,MAAI;AACF,UAAM,kBAAkB,mBAAmB,MAAM;AAEjD,UAAM,EAAE,GAAG,IAAI;AAEf,QAAI,SAAS,kBAAkB,EAAE;AAAA,EACnC,SAAS,OAAO;AACd,WAAO,IAAI,KAAK;AAAA,EAClB;AAEA,SAAO,IAAI;AACb;AASA,SAAS,mBAAmB,QAA8C;AACxE,MAAI;AACF,WAAO,OAAO,QAAQ,iCAAiC;AAAA,EACzD,SAAS,OAAO;AACd,QAAI,iBAAiB,aAAa;AAChC,YAAM,UAAU,cAAc;AAAA,QAC5B,SAAS,mBAAmB,MAAM,OAAO;AAAA,MAC3C,CAAC;AAAA,IACH;AAEA,UAAM,UAAU,SAAS;AAAA,EAC3B;AACF","sourcesContent":["import type { JsonRpcEngineEndCallback } from '@metamask/json-rpc-engine';\nimport type { PermittedHandlerExport } from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type {\n GetInterfaceStateParams,\n GetInterfaceStateResult,\n InterfaceState,\n JsonRpcRequest,\n} from '@metamask/snaps-sdk';\nimport { type InferMatching } from '@metamask/snaps-utils';\nimport type { PendingJsonRpcResponse } from '@metamask/utils';\nimport { StructError, create, object, string } from 'superstruct';\n\nimport type { MethodHooksObject } from '../utils';\n\nconst hookNames: MethodHooksObject<GetInterfaceStateMethodHooks> = {\n getInterfaceState: true,\n};\n\nexport type GetInterfaceStateMethodHooks = {\n /**\n * @param id - The interface ID.\n * @returns The interface state.\n */\n getInterfaceState: (id: string) => InterfaceState;\n};\n\nexport const getInterfaceStateHandler: PermittedHandlerExport<\n GetInterfaceStateMethodHooks,\n GetInterfaceStateParameters,\n GetInterfaceStateResult\n> = {\n methodNames: ['snap_getInterfaceState'],\n implementation: getGetInterfaceStateImplementation,\n hookNames,\n};\n\nconst GetInterfaceStateParametersStruct = object({\n id: string(),\n});\n\nexport type GetInterfaceStateParameters = InferMatching<\n typeof GetInterfaceStateParametersStruct,\n GetInterfaceStateParams\n>;\n\n/**\n * The `snap_getInterfaceState` method implementation.\n *\n * @param req - The JSON-RPC request object.\n * @param res - The JSON-RPC response object.\n * @param _next - The `json-rpc-engine` \"next\" callback. Not used by this\n * function.\n * @param end - The `json-rpc-engine` \"end\" callback.\n * @param hooks - The RPC method hooks.\n * @param hooks.getInterfaceState - The function to get the interface state.\n * @returns Noting.\n */\nfunction getGetInterfaceStateImplementation(\n req: JsonRpcRequest<GetInterfaceStateParameters>,\n res: PendingJsonRpcResponse<GetInterfaceStateResult>,\n _next: unknown,\n end: JsonRpcEngineEndCallback,\n { getInterfaceState }: GetInterfaceStateMethodHooks,\n): void {\n const { params } = req;\n\n try {\n const validatedParams = getValidatedParams(params);\n\n const { id } = validatedParams;\n\n res.result = getInterfaceState(id);\n } catch (error) {\n return end(error);\n }\n\n return end();\n}\n\n/**\n * Validate the getInterfaceState 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 * @returns The validated getInterfaceState method parameter object.\n */\nfunction getValidatedParams(params: unknown): GetInterfaceStateParameters {\n try {\n return create(params, GetInterfaceStateParametersStruct);\n } catch (error) {\n if (error instanceof StructError) {\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${error.message}.`,\n });\n }\n /* istanbul ignore next */\n throw rpcErrors.internal();\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/permitted/updateInterface.ts"],"names":[],"mappings":";AAEA,SAAS,iBAAiB;AAO1B,SAAS,gCAAgC;AAGzC,SAAS,aAAa,QAAQ,QAAQ,cAAc;AAIpD,IAAM,YAA2D;AAAA,EAC/D,iBAAiB;AACnB;AAUO,IAAM,yBAIT;AAAA,EACF,aAAa,CAAC,sBAAsB;AAAA,EACpC,gBAAgB;AAAA,EAChB;AACF;AAEA,IAAM,kCAAkC,OAAO;AAAA,EAC7C,IAAI,OAAO;AAAA,EACX,IAAI;AACN,CAAC;AAmBD,eAAe,iCACb,KACA,KACA,OACA,KACA,EAAE,gBAAgB,GACH;AACf,QAAM,EAAE,OAAO,IAAI;AAEnB,MAAI;AACF,UAAM,kBAAkB,mBAAmB,MAAM;AAEjD,UAAM,EAAE,IAAI,GAAG,IAAI;AAEnB,UAAM,gBAAgB,IAAI,EAAE;AAC5B,QAAI,SAAS;AAAA,EACf,SAAS,OAAO;AACd,WAAO,IAAI,KAAK;AAAA,EAClB;AAEA,SAAO,IAAI;AACb;AASA,SAAS,mBAAmB,QAA4C;AACtE,MAAI;AACF,WAAO,OAAO,QAAQ,+BAA+B;AAAA,EACvD,SAAS,OAAO;AACd,QAAI,iBAAiB,aAAa;AAChC,YAAM,UAAU,cAAc;AAAA,QAC5B,SAAS,mBAAmB,MAAM,OAAO;AAAA,MAC3C,CAAC;AAAA,IACH;AAEA,UAAM,UAAU,SAAS;AAAA,EAC3B;AACF","sourcesContent":["import type { JsonRpcEngineEndCallback } from '@metamask/json-rpc-engine';\nimport type { PermittedHandlerExport } from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type {\n UpdateInterfaceParams,\n UpdateInterfaceResult,\n JsonRpcRequest,\n ComponentOrElement,\n} from '@metamask/snaps-sdk';\nimport { ComponentOrElementStruct } from '@metamask/snaps-sdk';\nimport { type InferMatching } from '@metamask/snaps-utils';\nimport type { PendingJsonRpcResponse } from '@metamask/utils';\nimport { StructError, create, object, string } from 'superstruct';\n\nimport type { MethodHooksObject } from '../utils';\n\nconst hookNames: MethodHooksObject<UpdateInterfaceMethodHooks> = {\n updateInterface: true,\n};\n\nexport type UpdateInterfaceMethodHooks = {\n /**\n * @param id - The interface ID.\n * @param ui - The UI components.\n */\n updateInterface: (id: string, ui: ComponentOrElement) => Promise<void>;\n};\n\nexport const updateInterfaceHandler: PermittedHandlerExport<\n UpdateInterfaceMethodHooks,\n UpdateInterfaceParameters,\n UpdateInterfaceResult\n> = {\n methodNames: ['snap_updateInterface'],\n implementation: getUpdateInterfaceImplementation,\n hookNames,\n};\n\nconst UpdateInterfaceParametersStruct = object({\n id: string(),\n ui: ComponentOrElementStruct,\n});\n\nexport type UpdateInterfaceParameters = InferMatching<\n typeof UpdateInterfaceParametersStruct,\n UpdateInterfaceParams\n>;\n\n/**\n * The `snap_updateInterface` method implementation.\n *\n * @param req - The JSON-RPC request object.\n * @param res - The JSON-RPC response object.\n * @param _next - The `json-rpc-engine` \"next\" callback. Not used by this\n * function.\n * @param end - The `json-rpc-engine` \"end\" callback.\n * @param hooks - The RPC method hooks.\n * @param hooks.updateInterface - The function to update the interface.\n * @returns Nothing.\n */\nasync function getUpdateInterfaceImplementation(\n req: JsonRpcRequest<UpdateInterfaceParameters>,\n res: PendingJsonRpcResponse<UpdateInterfaceResult>,\n _next: unknown,\n end: JsonRpcEngineEndCallback,\n { updateInterface }: UpdateInterfaceMethodHooks,\n): Promise<void> {\n const { params } = req;\n\n try {\n const validatedParams = getValidatedParams(params);\n\n const { id, ui } = validatedParams;\n\n await updateInterface(id, ui);\n res.result = null;\n } catch (error) {\n return end(error);\n }\n\n return end();\n}\n\n/**\n * Validate the updateInterface 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 * @returns The validated updateInterface method parameter object.\n */\nfunction getValidatedParams(params: unknown): UpdateInterfaceParameters {\n try {\n return create(params, UpdateInterfaceParametersStruct);\n } catch (error) {\n if (error instanceof StructError) {\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${error.message}.`,\n });\n }\n /* istanbul ignore next */\n throw rpcErrors.internal();\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/restricted/manageAccounts.ts"],"sourcesContent":["import type {\n RestrictedMethodOptions,\n ValidPermissionSpecification,\n PermissionSpecificationBuilder,\n} from '@metamask/permission-controller';\nimport { SubjectType, PermissionType } from '@metamask/permission-controller';\nimport type {\n ManageAccountsParams,\n ManageAccountsResult,\n} from '@metamask/snaps-sdk';\nimport type { InferMatching } from '@metamask/snaps-utils';\nimport type { Json, NonEmptyArray } from '@metamask/utils';\nimport { JsonStruct } from '@metamask/utils';\nimport { assert, string, object, union, array, record } from 'superstruct';\n\nconst SnapMessageStruct = union([\n object({\n method: string(),\n }),\n object({\n method: string(),\n params: union([array(JsonStruct), record(string(), JsonStruct)]),\n }),\n]);\n\ntype Message = InferMatching<typeof SnapMessageStruct, ManageAccountsParams>;\n\nexport const methodName = 'snap_manageAccounts';\n\nexport type ManageAccountsMethodHooks = {\n /**\n * Gets the snap keyring implementation.\n */\n getSnapKeyring: (snapOrigin: string) => Promise<{\n handleKeyringSnapMessage: (\n snapId: string,\n message: Message,\n ) => Promise<Json>;\n }>;\n};\n\ntype ManageAccountsSpecificationBuilderOptions = {\n allowedCaveats?: Readonly<NonEmptyArray<string>> | null;\n methodHooks: ManageAccountsMethodHooks;\n};\n\ntype ManageAccountsSpecification = ValidPermissionSpecification<{\n permissionType: PermissionType.RestrictedMethod;\n targetName: typeof methodName;\n methodImplementation: ReturnType<typeof manageAccountsImplementation>;\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n}>;\n\n/**\n * The specification builder for the `snap_manageAccounts` permission.\n * `snap_manageAccounts` lets the Snap manage a set of accounts via a custom keyring.\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_manageAccounts` permission.\n */\nexport const specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.RestrictedMethod,\n ManageAccountsSpecificationBuilderOptions,\n ManageAccountsSpecification\n> = ({\n allowedCaveats = null,\n methodHooks,\n}: ManageAccountsSpecificationBuilderOptions) => {\n return {\n permissionType: PermissionType.RestrictedMethod,\n targetName: methodName,\n allowedCaveats,\n methodImplementation: manageAccountsImplementation(methodHooks),\n subjectTypes: [SubjectType.Snap],\n };\n};\n\n/**\n * Builds the method implementation for `snap_manageAccounts`.\n *\n * @param hooks - The RPC method hooks.\n * @param hooks.getSnapKeyring - A function to get the snap keyring.\n * @returns The method implementation which either returns `null` for a\n * successful state update/deletion or returns the decrypted state.\n * @throws If the params are invalid.\n */\nexport function manageAccountsImplementation({\n getSnapKeyring,\n}: ManageAccountsMethodHooks) {\n return async function manageAccounts(\n options: RestrictedMethodOptions<ManageAccountsParams>,\n ): Promise<ManageAccountsResult> {\n const {\n context: { origin },\n params,\n } = options;\n\n assert(params, SnapMessageStruct);\n const keyring = await getSnapKeyring(origin);\n return await keyring.handleKeyringSnapMessage(origin, params);\n };\n}\n\nexport const manageAccountsBuilder = Object.freeze({\n targetName: methodName,\n specificationBuilder,\n methodHooks: {\n getSnapKeyring: true,\n },\n} as const);\n"],"mappings":";AAKA,SAAS,aAAa,sBAAsB;AAO5C,SAAS,kBAAkB;AAC3B,SAAS,QAAQ,QAAQ,QAAQ,OAAO,OAAO,cAAc;AAE7D,IAAM,oBAAoB,MAAM;AAAA,EAC9B,OAAO;AAAA,IACL,QAAQ,OAAO;AAAA,EACjB,CAAC;AAAA,EACD,OAAO;AAAA,IACL,QAAQ,OAAO;AAAA,IACf,QAAQ,MAAM,CAAC,MAAM,UAAU,GAAG,OAAO,OAAO,GAAG,UAAU,CAAC,CAAC;AAAA,EACjE,CAAC;AACH,CAAC;AAIM,IAAM,aAAa;AAmCnB,IAAM,uBAIT,CAAC;AAAA,EACH,iBAAiB;AAAA,EACjB;AACF,MAAiD;AAC/C,SAAO;AAAA,IACL,gBAAgB,eAAe;AAAA,IAC/B,YAAY;AAAA,IACZ;AAAA,IACA,sBAAsB,6BAA6B,WAAW;AAAA,IAC9D,cAAc,CAAC,YAAY,IAAI;AAAA,EACjC;AACF;AAWO,SAAS,6BAA6B;AAAA,EAC3C;AACF,GAA8B;AAC5B,SAAO,eAAe,eACpB,SAC+B;AAC/B,UAAM;AAAA,MACJ,SAAS,EAAE,OAAO;AAAA,MAClB;AAAA,IACF,IAAI;AAEJ,WAAO,QAAQ,iBAAiB;AAChC,UAAM,UAAU,MAAM,eAAe,MAAM;AAC3C,WAAO,MAAM,QAAQ,yBAAyB,QAAQ,MAAM;AAAA,EAC9D;AACF;AAEO,IAAM,wBAAwB,OAAO,OAAO;AAAA,EACjD,YAAY;AAAA,EACZ;AAAA,EACA,aAAa;AAAA,IACX,gBAAgB;AAAA,EAClB;AACF,CAAU;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/permitted/handlers.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAYO,IAAM,iBAAiB;AAAA,EAC5B,oBAAoB;AAAA,EACpB,iBAAiB;AAAA,EACjB,qBAAqB;AAAA,EACrB,mBAAmB;AAAA,EACnB,sBAAsB;AAAA,EACtB,sBAAsB;AAAA,EACtB,cAAc;AAAA,EACd,sBAAsB;AAAA,EACtB,sBAAsB;AAAA,EACtB,wBAAwB;AAC1B;AAGO,IAAM,WAAW,OAAO,OAAO,cAAc","sourcesContent":["import { createInterfaceHandler } from './createInterface';\nimport { getAllSnapsHandler } from './getAllSnaps';\nimport { getClientStatusHandler } from './getClientStatus';\nimport { getFileHandler } from './getFile';\nimport { getInterfaceStateHandler } from './getInterfaceState';\nimport { getSnapsHandler } from './getSnaps';\nimport { invokeKeyringHandler } from './invokeKeyring';\nimport { invokeSnapSugarHandler } from './invokeSnapSugar';\nimport { requestSnapsHandler } from './requestSnaps';\nimport { updateInterfaceHandler } from './updateInterface';\n\n/* eslint-disable @typescript-eslint/naming-convention */\nexport const methodHandlers = {\n wallet_getAllSnaps: getAllSnapsHandler,\n wallet_getSnaps: getSnapsHandler,\n wallet_requestSnaps: requestSnapsHandler,\n wallet_invokeSnap: invokeSnapSugarHandler,\n wallet_invokeKeyring: invokeKeyringHandler,\n snap_getClientStatus: getClientStatusHandler,\n snap_getFile: getFileHandler,\n snap_createInterface: createInterfaceHandler,\n snap_updateInterface: updateInterfaceHandler,\n snap_getInterfaceState: getInterfaceStateHandler,\n};\n/* eslint-enable @typescript-eslint/naming-convention */\n\nexport const handlers = Object.values(methodHandlers);\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/permitted/updateInterface.ts"],"sourcesContent":["import type { JsonRpcEngineEndCallback } from '@metamask/json-rpc-engine';\nimport type { PermittedHandlerExport } from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type {\n UpdateInterfaceParams,\n UpdateInterfaceResult,\n JsonRpcRequest,\n ComponentOrElement,\n} from '@metamask/snaps-sdk';\nimport { ComponentOrElementStruct } from '@metamask/snaps-sdk';\nimport { type InferMatching } from '@metamask/snaps-utils';\nimport type { PendingJsonRpcResponse } from '@metamask/utils';\nimport { StructError, create, object, string } from 'superstruct';\n\nimport type { MethodHooksObject } from '../utils';\n\nconst hookNames: MethodHooksObject<UpdateInterfaceMethodHooks> = {\n updateInterface: true,\n};\n\nexport type UpdateInterfaceMethodHooks = {\n /**\n * @param id - The interface ID.\n * @param ui - The UI components.\n */\n updateInterface: (id: string, ui: ComponentOrElement) => Promise<void>;\n};\n\nexport const updateInterfaceHandler: PermittedHandlerExport<\n UpdateInterfaceMethodHooks,\n UpdateInterfaceParameters,\n UpdateInterfaceResult\n> = {\n methodNames: ['snap_updateInterface'],\n implementation: getUpdateInterfaceImplementation,\n hookNames,\n};\n\nconst UpdateInterfaceParametersStruct = object({\n id: string(),\n ui: ComponentOrElementStruct,\n});\n\nexport type UpdateInterfaceParameters = InferMatching<\n typeof UpdateInterfaceParametersStruct,\n UpdateInterfaceParams\n>;\n\n/**\n * The `snap_updateInterface` method implementation.\n *\n * @param req - The JSON-RPC request object.\n * @param res - The JSON-RPC response object.\n * @param _next - The `json-rpc-engine` \"next\" callback. Not used by this\n * function.\n * @param end - The `json-rpc-engine` \"end\" callback.\n * @param hooks - The RPC method hooks.\n * @param hooks.updateInterface - The function to update the interface.\n * @returns Nothing.\n */\nasync function getUpdateInterfaceImplementation(\n req: JsonRpcRequest<UpdateInterfaceParameters>,\n res: PendingJsonRpcResponse<UpdateInterfaceResult>,\n _next: unknown,\n end: JsonRpcEngineEndCallback,\n { updateInterface }: UpdateInterfaceMethodHooks,\n): Promise<void> {\n const { params } = req;\n\n try {\n const validatedParams = getValidatedParams(params);\n\n const { id, ui } = validatedParams;\n\n await updateInterface(id, ui);\n res.result = null;\n } catch (error) {\n return end(error);\n }\n\n return end();\n}\n\n/**\n * Validate the updateInterface 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 * @returns The validated updateInterface method parameter object.\n */\nfunction getValidatedParams(params: unknown): UpdateInterfaceParameters {\n try {\n return create(params, UpdateInterfaceParametersStruct);\n } catch (error) {\n if (error instanceof StructError) {\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${error.message}.`,\n });\n }\n /* istanbul ignore next */\n throw rpcErrors.internal();\n }\n}\n"],"mappings":";AAEA,SAAS,iBAAiB;AAO1B,SAAS,gCAAgC;AAGzC,SAAS,aAAa,QAAQ,QAAQ,cAAc;AAIpD,IAAM,YAA2D;AAAA,EAC/D,iBAAiB;AACnB;AAUO,IAAM,yBAIT;AAAA,EACF,aAAa,CAAC,sBAAsB;AAAA,EACpC,gBAAgB;AAAA,EAChB;AACF;AAEA,IAAM,kCAAkC,OAAO;AAAA,EAC7C,IAAI,OAAO;AAAA,EACX,IAAI;AACN,CAAC;AAmBD,eAAe,iCACb,KACA,KACA,OACA,KACA,EAAE,gBAAgB,GACH;AACf,QAAM,EAAE,OAAO,IAAI;AAEnB,MAAI;AACF,UAAM,kBAAkB,mBAAmB,MAAM;AAEjD,UAAM,EAAE,IAAI,GAAG,IAAI;AAEnB,UAAM,gBAAgB,IAAI,EAAE;AAC5B,QAAI,SAAS;AAAA,EACf,SAAS,OAAO;AACd,WAAO,IAAI,KAAK;AAAA,EAClB;AAEA,SAAO,IAAI;AACb;AASA,SAAS,mBAAmB,QAA4C;AACtE,MAAI;AACF,WAAO,OAAO,QAAQ,+BAA+B;AAAA,EACvD,SAAS,OAAO;AACd,QAAI,iBAAiB,aAAa;AAChC,YAAM,UAAU,cAAc;AAAA,QAC5B,SAAS,mBAAmB,MAAM,OAAO;AAAA,MAC3C,CAAC;AAAA,IACH;AAEA,UAAM,UAAU,SAAS;AAAA,EAC3B;AACF;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/permitted/getFile.ts"],"sourcesContent":["import type { JsonRpcEngineEndCallback } from '@metamask/json-rpc-engine';\nimport type { PermittedHandlerExport } from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type { GetFileParams, GetFileResult } from '@metamask/snaps-sdk';\nimport { AuxiliaryFileEncoding, enumValue } from '@metamask/snaps-sdk';\nimport type { InferMatching } from '@metamask/snaps-utils';\nimport type { PendingJsonRpcResponse, JsonRpcRequest } from '@metamask/utils';\nimport { assertStruct } from '@metamask/utils';\nimport { object, optional, string, union } from 'superstruct';\n\nimport type { MethodHooksObject } from '../utils';\n\nexport const GetFileArgsStruct = object({\n path: string(),\n encoding: optional(\n union([\n enumValue(AuxiliaryFileEncoding.Base64),\n enumValue(AuxiliaryFileEncoding.Hex),\n enumValue(AuxiliaryFileEncoding.Utf8),\n ]),\n ),\n});\n\nexport type InferredGetFileParams = InferMatching<\n typeof GetFileArgsStruct,\n GetFileParams\n>;\n\nconst hookNames: MethodHooksObject<GetFileHooks> = {\n getSnapFile: true,\n};\n\nexport const getFileHandler: PermittedHandlerExport<\n GetFileHooks,\n InferredGetFileParams,\n string\n> = {\n methodNames: ['snap_getFile'],\n implementation,\n hookNames,\n};\n\nexport type GetFileHooks = {\n getSnapFile: (\n path: InferredGetFileParams['path'],\n encoding: InferredGetFileParams['encoding'],\n ) => Promise<string>;\n};\n\n/**\n * The `snap_getFile` method implementation.\n *\n * @param req - The JSON-RPC request object.\n * @param res - The JSON-RPC response object.\n * @param _next - The `json-rpc-engine` \"next\" callback. Not used by this\n * function.\n * @param end - The `json-rpc-engine` \"end\" callback.\n * @param hooks - The RPC method hooks.\n * @param hooks.getSnapFile - The function to load a static snap file.\n * @returns Nothing.\n */\nasync function implementation(\n req: JsonRpcRequest<InferredGetFileParams>,\n res: PendingJsonRpcResponse<GetFileResult>,\n _next: unknown,\n end: JsonRpcEngineEndCallback,\n { getSnapFile }: GetFileHooks,\n): Promise<void> {\n const { params } = req;\n\n assertStruct(\n params,\n GetFileArgsStruct,\n 'Invalid \"snap_getFile\" parameters',\n rpcErrors.invalidParams,\n );\n\n try {\n res.result = await getSnapFile(\n params.path,\n params.encoding ?? AuxiliaryFileEncoding.Base64,\n );\n } catch (error) {\n return end(error);\n }\n\n return end();\n}\n"],"mappings":";AAEA,SAAS,iBAAiB;AAE1B,SAAS,uBAAuB,iBAAiB;AAGjD,SAAS,oBAAoB;AAC7B,SAAS,QAAQ,UAAU,QAAQ,aAAa;AAIzC,IAAM,oBAAoB,OAAO;AAAA,EACtC,MAAM,OAAO;AAAA,EACb,UAAU;AAAA,IACR,MAAM;AAAA,MACJ,UAAU,sBAAsB,MAAM;AAAA,MACtC,UAAU,sBAAsB,GAAG;AAAA,MACnC,UAAU,sBAAsB,IAAI;AAAA,IACtC,CAAC;AAAA,EACH;AACF,CAAC;AAOD,IAAM,YAA6C;AAAA,EACjD,aAAa;AACf;AAEO,IAAM,iBAIT;AAAA,EACF,aAAa,CAAC,cAAc;AAAA,EAC5B;AAAA,EACA;AACF;AAqBA,eAAe,eACb,KACA,KACA,OACA,KACA,EAAE,YAAY,GACC;AACf,QAAM,EAAE,OAAO,IAAI;AAEnB;AAAA,IACE;AAAA,IACA;AAAA,IACA;AAAA,IACA,UAAU;AAAA,EACZ;AAEA,MAAI;AACF,QAAI,SAAS,MAAM;AAAA,MACjB,OAAO;AAAA,MACP,OAAO,YAAY,sBAAsB;AAAA,IAC3C;AAAA,EACF,SAAS,OAAO;AACd,WAAO,IAAI,KAAK;AAAA,EAClB;AAEA,SAAO,IAAI;AACb;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/restricted/dialog.ts"],"names":["methodHooks"],"mappings":"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","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 {\n DialogType,\n enumValue,\n union,\n ComponentOrElementStruct,\n} from '@metamask/snaps-sdk';\nimport type {\n DialogParams,\n EnumToUnion,\n Component,\n InterfaceState,\n SnapId,\n ComponentOrElement,\n} from '@metamask/snaps-sdk';\nimport { createUnion } from '@metamask/snaps-utils';\nimport type { InferMatching } from '@metamask/snaps-utils';\nimport { hasProperty, type NonEmptyArray } from '@metamask/utils';\nimport type { Infer, Struct } from 'superstruct';\nimport {\n create,\n enums,\n object,\n optional,\n size,\n string,\n type,\n} from 'superstruct';\n\nimport { type MethodHooksObject } from '../utils';\n\nconst methodName = 'snap_dialog';\n\nconst PlaceholderStruct = optional(size(string(), 1, 40));\n\nexport type Placeholder = Infer<typeof PlaceholderStruct>;\n\ntype ShowDialog = (\n snapId: string,\n type: EnumToUnion<DialogType>,\n id: string,\n placeholder?: Placeholder,\n) => Promise<null | boolean | string>;\n\ntype CreateInterface = (\n snapId: string,\n content: ComponentOrElement,\n) => Promise<string>;\n\ntype GetInterface = (\n snapId: string,\n id: string,\n) => { content: ComponentOrElement; snapId: SnapId; state: InterfaceState };\n\nexport type DialogMethodHooks = {\n /**\n * @param snapId - The ID of the Snap that created the alert.\n * @param type - The dialog type.\n * @param id - The interface ID.\n * @param placeholder - The placeholder for the Prompt dialog input.\n */\n showDialog: ShowDialog;\n\n /**\n * @param snapId - The Snap ID creating the interface.\n * @param content - The content of the interface.\n */\n createInterface: CreateInterface;\n /**\n * @param snapId - The SnapId requesting the interface.\n * @param id - The interface ID.\n */\n getInterface: GetInterface;\n};\n\ntype DialogSpecificationBuilderOptions = {\n allowedCaveats?: Readonly<NonEmptyArray<string>> | null;\n methodHooks: DialogMethodHooks;\n};\n\ntype DialogSpecification = ValidPermissionSpecification<{\n permissionType: PermissionType.RestrictedMethod;\n targetName: typeof methodName;\n methodImplementation: ReturnType<typeof getDialogImplementation>;\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n}>;\n\n/**\n * The specification builder for the `snap_dialog` permission. `snap_dialog`\n * lets the Snap display one of the following dialogs to the user:\n * - An alert, for displaying information.\n * - A confirmation, for accepting or rejecting some action.\n * - A prompt, for inputting some information.\n *\n * @param options - The specification builder options.\n * @param options.allowedCaveats - The optional allowed caveats for the\n * permission.\n * @param options.methodHooks - The RPC method hooks needed by the method\n * implementation.\n * @returns The specification for the `snap_dialog` permission.\n */\nconst specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.RestrictedMethod,\n DialogSpecificationBuilderOptions,\n DialogSpecification\n> = ({\n allowedCaveats = null,\n methodHooks,\n}: DialogSpecificationBuilderOptions) => {\n return {\n permissionType: PermissionType.RestrictedMethod,\n targetName: methodName,\n allowedCaveats,\n methodImplementation: getDialogImplementation(methodHooks),\n subjectTypes: [SubjectType.Snap],\n };\n};\n\nconst methodHooks: MethodHooksObject<DialogMethodHooks> = {\n showDialog: true,\n createInterface: true,\n getInterface: true,\n};\n\nexport const dialogBuilder = Object.freeze({\n targetName: methodName,\n specificationBuilder,\n methodHooks,\n} as const);\n\n// Note: We use `type` here instead of `object` because `type` does not validate\n// the keys of the object, which is what we want.\nconst BaseParamsStruct = type({\n type: enums([DialogType.Alert, DialogType.Confirmation, DialogType.Prompt]),\n});\n\nconst AlertParametersWithContentStruct = object({\n type: enumValue(DialogType.Alert),\n content: ComponentOrElementStruct,\n});\nconst AlertParametersWithIdStruct = object({\n type: enumValue(DialogType.Alert),\n id: string(),\n});\n\nconst AlertParametersStruct = union([\n AlertParametersWithContentStruct,\n AlertParametersWithIdStruct,\n]);\n\nconst ConfirmationParametersWithContentStruct = object({\n type: enumValue(DialogType.Confirmation),\n content: ComponentOrElementStruct,\n});\n\nconst ConfirmationParametersWithIdStruct = object({\n type: enumValue(DialogType.Confirmation),\n id: string(),\n});\n\nconst ConfirmationParametersStruct = union([\n ConfirmationParametersWithContentStruct,\n ConfirmationParametersWithIdStruct,\n]);\n\nconst PromptParametersWithContentStruct = object({\n type: enumValue(DialogType.Prompt),\n content: ComponentOrElementStruct,\n placeholder: PlaceholderStruct,\n});\n\nconst PromptParametersWithIdStruct = object({\n type: enumValue(DialogType.Prompt),\n id: string(),\n placeholder: PlaceholderStruct,\n});\n\nconst PromptParametersStruct = union([\n PromptParametersWithContentStruct,\n PromptParametersWithIdStruct,\n]);\n\nconst DialogParametersStruct = union([\n AlertParametersStruct,\n ConfirmationParametersStruct,\n PromptParametersStruct,\n]);\n\nexport type DialogParameters = InferMatching<\n typeof DialogParametersStruct,\n DialogParams\n>;\n\nconst structs = {\n [DialogType.Alert]: AlertParametersStruct,\n [DialogType.Confirmation]: ConfirmationParametersStruct,\n [DialogType.Prompt]: PromptParametersStruct,\n};\n\n/**\n * Builds the method implementation for `snap_dialog`.\n *\n * @param hooks - The RPC method hooks.\n * @param hooks.showDialog - A function that shows the specified dialog in the\n * MetaMask UI and returns the appropriate value for the dialog type.\n * @param hooks.createInterface - A function that creates the interface in SnapInterfaceController.\n * @param hooks.getInterface - A function that gets an interface from SnapInterfaceController.\n * @returns The method implementation which return value depends on the dialog\n * type, valid return types are: string, boolean, null.\n */\nexport function getDialogImplementation({\n showDialog,\n createInterface,\n getInterface,\n}: DialogMethodHooks) {\n return async function dialogImplementation(\n args: RestrictedMethodOptions<DialogParameters>,\n ): Promise<boolean | null | string> {\n const {\n params,\n context: { origin },\n } = args;\n\n const validatedType = getValidatedType(params);\n const validatedParams = getValidatedParams(params, structs[validatedType]);\n\n const placeholder =\n validatedParams.type === DialogType.Prompt\n ? validatedParams.placeholder\n : undefined;\n\n if (hasProperty(validatedParams, 'content')) {\n const id = await createInterface(\n origin,\n validatedParams.content as Component,\n );\n return showDialog(origin, validatedType, id, placeholder);\n }\n\n // Verify that the passed interface ID is valid.\n // This will throw if the interface ID is invalid (not created by the snap or doesn't exist)\n try {\n getInterface(origin, validatedParams.id);\n } catch (error) {\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${error.message}`,\n });\n }\n\n return showDialog(origin, validatedType, validatedParams.id, placeholder);\n };\n}\n\n/**\n * Get the validated type of the dialog parameters. Throws an error if the type\n * is invalid.\n *\n * @param params - The parameters to validate.\n * @returns The validated type of the dialog parameters.\n */\nfunction getValidatedType(params: unknown): DialogType {\n try {\n return create(params, BaseParamsStruct).type;\n } catch (error) {\n throw rpcErrors.invalidParams({\n message: `The \"type\" property must be one of: ${Object.values(\n DialogType,\n ).join(', ')}.`,\n });\n }\n}\n\n/**\n * Validates the confirm 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 struct - The struct to validate the params against.\n * @returns The validated confirm method parameter object.\n */\nfunction getValidatedParams(\n params: unknown,\n struct: Struct<any, any>,\n): DialogParameters {\n try {\n return createUnion(params, struct, 'type');\n } catch (error) {\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${error.message}`,\n });\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/restricted/getEntropy.ts"],"names":["methodHooks"],"mappings":";;;;;AAKA,SAAS,gBAAgB,mBAAmB;AAC5C,SAAS,iBAAiB;AAE1B,SAAS,yBAAyB;AAElC,SAAS,oBAAoB;AAE7B,SAAS,SAAS,QAAQ,UAAU,cAAc;AAKlD,IAAM,aAAa;AAcZ,IAAM,uBAAuB,OAAO;AAAA,EACzC,SAAS,QAAQ,CAAC;AAAA,EAClB,MAAM,SAAS,OAAO,CAAC;AACzB,CAAC;AAUD,IAAM,uBAIF,CAAC;AAAA,EACH,iBAAiB;AAAA,EACjB,aAAAA;AACF,MAA6C;AAC3C,SAAO;AAAA,IACL,gBAAgB,eAAe;AAAA,IAC/B;AAAA,IACA;AAAA,IACA,sBAAsB,yBAAyBA,YAAW;AAAA,IAC1D,cAAc,CAAC,YAAY,IAAI;AAAA,EACjC;AACF;AAEA,IAAM,cAAkD;AAAA,EACtD,aAAa;AAAA,EACb,kBAAkB;AACpB;AAEO,IAAM,oBAAoB,OAAO,OAAO;AAAA,EAC7C;AAAA,EACA;AAAA,EACA;AACF,CAAU;AA4BV,SAAS,yBAAyB;AAAA,EAChC;AAAA,EACA;AACF,GAAoB;AAClB,SAAO,eAAe,WACpB,SAC2B;AAC3B,UAAM;AAAA,MACJ;AAAA,MACA,SAAS,EAAE,OAAO;AAAA,IACpB,IAAI;AAEJ;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA,UAAU;AAAA,IACZ;AAEA,UAAM,iBAAiB,IAAI;AAC3B,UAAM,iBAAiB,MAAM,YAAY;AAEzC,WAAO,cAAc;AAAA,MACnB,OAAO;AAAA,MACP,MAAM,OAAO;AAAA,MACb;AAAA,MACA,OAAO;AAAA,IACT,CAAC;AAAA,EACH;AACF","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 { GetEntropyParams, GetEntropyResult } from '@metamask/snaps-sdk';\nimport { SIP_6_MAGIC_VALUE } from '@metamask/snaps-utils';\nimport type { NonEmptyArray } from '@metamask/utils';\nimport { assertStruct } from '@metamask/utils';\nimport type { Infer } from 'superstruct';\nimport { literal, object, optional, string } from 'superstruct';\n\nimport type { MethodHooksObject } from '../utils';\nimport { 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});\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};\n\nexport const getEntropyBuilder = Object.freeze({\n targetName,\n specificationBuilder,\n methodHooks,\n} as const);\n\nexport type GetEntropyHooks = {\n /**\n * @returns The mnemonic of the user's primary keyring.\n */\n getMnemonic: () => 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/**\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 * @returns The method implementation.\n */\nfunction getEntropyImplementation({\n getMnemonic,\n getUnlockPromise,\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 getMnemonic();\n\n return deriveEntropy({\n input: origin,\n salt: params.salt,\n mnemonicPhrase,\n magic: SIP_6_MAGIC_VALUE,\n });\n };\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/restricted/getEntropy.ts"],"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 { GetEntropyParams, GetEntropyResult } from '@metamask/snaps-sdk';\nimport { SIP_6_MAGIC_VALUE } from '@metamask/snaps-utils';\nimport type { NonEmptyArray } from '@metamask/utils';\nimport { assertStruct } from '@metamask/utils';\nimport type { Infer } from 'superstruct';\nimport { literal, object, optional, string } from 'superstruct';\n\nimport type { MethodHooksObject } from '../utils';\nimport { 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});\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};\n\nexport const getEntropyBuilder = Object.freeze({\n targetName,\n specificationBuilder,\n methodHooks,\n} as const);\n\nexport type GetEntropyHooks = {\n /**\n * @returns The mnemonic of the user's primary keyring.\n */\n getMnemonic: () => 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/**\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 * @returns The method implementation.\n */\nfunction getEntropyImplementation({\n getMnemonic,\n getUnlockPromise,\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 getMnemonic();\n\n return deriveEntropy({\n input: origin,\n salt: params.salt,\n mnemonicPhrase,\n magic: SIP_6_MAGIC_VALUE,\n });\n };\n}\n"],"mappings":";;;;;AAKA,SAAS,gBAAgB,mBAAmB;AAC5C,SAAS,iBAAiB;AAE1B,SAAS,yBAAyB;AAElC,SAAS,oBAAoB;AAE7B,SAAS,SAAS,QAAQ,UAAU,cAAc;AAKlD,IAAM,aAAa;AAcZ,IAAM,uBAAuB,OAAO;AAAA,EACzC,SAAS,QAAQ,CAAC;AAAA,EAClB,MAAM,SAAS,OAAO,CAAC;AACzB,CAAC;AAUD,IAAM,uBAIF,CAAC;AAAA,EACH,iBAAiB;AAAA,EACjB,aAAAA;AACF,MAA6C;AAC3C,SAAO;AAAA,IACL,gBAAgB,eAAe;AAAA,IAC/B;AAAA,IACA;AAAA,IACA,sBAAsB,yBAAyBA,YAAW;AAAA,IAC1D,cAAc,CAAC,YAAY,IAAI;AAAA,EACjC;AACF;AAEA,IAAM,cAAkD;AAAA,EACtD,aAAa;AAAA,EACb,kBAAkB;AACpB;AAEO,IAAM,oBAAoB,OAAO,OAAO;AAAA,EAC7C;AAAA,EACA;AAAA,EACA;AACF,CAAU;AA4BV,SAAS,yBAAyB;AAAA,EAChC;AAAA,EACA;AACF,GAAoB;AAClB,SAAO,eAAe,WACpB,SAC2B;AAC3B,UAAM;AAAA,MACJ;AAAA,MACA,SAAS,EAAE,OAAO;AAAA,IACpB,IAAI;AAEJ;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA,UAAU;AAAA,IACZ;AAEA,UAAM,iBAAiB,IAAI;AAC3B,UAAM,iBAAiB,MAAM,YAAY;AAEzC,WAAO,cAAc;AAAA,MACnB,OAAO;AAAA,MACP,MAAM,OAAO;AAAA,MACb;AAAA,MACA,OAAO;AAAA,IACT,CAAC;AAAA,EACH;AACF;","names":["methodHooks"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/restricted/caveats/snapIds.ts"],"names":[],"mappings":";AAOA,SAAS,iBAAiB;AAE1B,SAAS,gBAAgB,qBAAqB;AAE9C,SAAS,aAAa,oBAAoB;AAC1C,SAAS,YAAY;AAYd,SAAS,oBACd,OACuC;AACvC,SAAO;AAAA,IACL,SAAS;AAAA,MACP;AAAA,QACE,MAAM,eAAe;AAAA,QACrB;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;AAQO,SAAS,sBACd,QAC2C;AAC3C;AAAA,IACE;AAAA,IACA,KAAK;AAAA,MACH,OAAO;AAAA,IACT,CAAC;AAAA,IACD;AAAA,IACA,UAAU;AAAA,EACZ;AACF;AAEO,IAAM,6BAGT;AAAA,EACF,CAAC,eAAe,OAAO,GAAG,OAAO,OAAO;AAAA,IACtC,MAAM,eAAe;AAAA,IACrB,WAAW,CAAC,WAAW,sBAAsB,MAAM;AAAA,IACnD,WAAW,CAAC,QAAQ,WAAW;AAC7B,aAAO,OAAO,SAAS;AACrB,cAAM;AAAA,UACJ;AAAA,UACA,SAAS,EAAE,OAAO;AAAA,QACpB,IAAyD;AACzD,cAAM,UAAU,OAAO;AACvB,cAAM,EAAE,OAAO,IAAI;AACnB,YAAI,CAAC,YAAY,SAAS,MAAM,GAAG;AACjC,gBAAM,IAAI;AAAA,YACR,GAAG,MAAM,uCAAuC,MAAM;AAAA,UACxD;AAAA,QACF;AACA,eAAO,MAAM,OAAO,IAAI;AAAA,MAC1B;AAAA,IACF;AAAA,EACF,CAAC;AACH","sourcesContent":["import type {\n Caveat,\n RestrictedMethodOptions,\n RestrictedMethodParameters,\n RestrictedMethodCaveatSpecificationConstraint,\n PermissionConstraint,\n} from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type { SnapIds } from '@metamask/snaps-utils';\nimport { SnapCaveatType, SnapIdsStruct } from '@metamask/snaps-utils';\nimport type { Json } from '@metamask/utils';\nimport { hasProperty, assertStruct } from '@metamask/utils';\nimport { type } from 'superstruct';\n\nimport type { InvokeSnapParams } from '../invokeSnap';\n\n/**\n * Map a raw value from the `initialPermissions` to a caveat specification.\n * Note that this function does not do any validation, that's handled by the\n * PermissionsController when the permission is requested.\n *\n * @param value - The raw value from the `initialPermissions`.\n * @returns The caveat specification.\n */\nexport function snapIdsCaveatMapper(\n value: Json,\n): Pick<PermissionConstraint, 'caveats'> {\n return {\n caveats: [\n {\n type: SnapCaveatType.SnapIds,\n value,\n },\n ],\n };\n}\n\n/**\n * Validates that the caveat value exists and is a non-empty object.\n *\n * @param caveat - The caveat to validate.\n * @throws If the caveat is invalid.\n */\nexport function validateSnapIdsCaveat(\n caveat: Caveat<string, any>,\n): asserts caveat is Caveat<string, SnapIds> {\n assertStruct(\n caveat,\n type({\n value: SnapIdsStruct,\n }),\n 'Expected caveat to have a value property of a non-empty object of snap IDs.',\n rpcErrors.invalidParams,\n );\n}\n\nexport const SnapIdsCaveatSpecification: Record<\n SnapCaveatType.SnapIds,\n RestrictedMethodCaveatSpecificationConstraint\n> = {\n [SnapCaveatType.SnapIds]: Object.freeze({\n type: SnapCaveatType.SnapIds,\n validator: (caveat) => validateSnapIdsCaveat(caveat),\n decorator: (method, caveat) => {\n return async (args) => {\n const {\n params,\n context: { origin },\n }: RestrictedMethodOptions<RestrictedMethodParameters> = args;\n const snapIds = caveat.value as SnapIds;\n const { snapId } = params as InvokeSnapParams;\n if (!hasProperty(snapIds, snapId)) {\n throw new Error(\n `${origin} does not have permission to invoke ${snapId} snap.`,\n );\n }\n return await method(args);\n };\n },\n }),\n};\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/permitted/getFile.ts"],"names":[],"mappings":";AAEA,SAAS,iBAAiB;AAE1B,SAAS,uBAAuB,iBAAiB;AAGjD,SAAS,oBAAoB;AAC7B,SAAS,QAAQ,UAAU,QAAQ,aAAa;AAIzC,IAAM,oBAAoB,OAAO;AAAA,EACtC,MAAM,OAAO;AAAA,EACb,UAAU;AAAA,IACR,MAAM;AAAA,MACJ,UAAU,sBAAsB,MAAM;AAAA,MACtC,UAAU,sBAAsB,GAAG;AAAA,MACnC,UAAU,sBAAsB,IAAI;AAAA,IACtC,CAAC;AAAA,EACH;AACF,CAAC;AAOD,IAAM,YAA6C;AAAA,EACjD,aAAa;AACf;AAEO,IAAM,iBAIT;AAAA,EACF,aAAa,CAAC,cAAc;AAAA,EAC5B;AAAA,EACA;AACF;AAqBA,eAAe,eACb,KACA,KACA,OACA,KACA,EAAE,YAAY,GACC;AACf,QAAM,EAAE,OAAO,IAAI;AAEnB;AAAA,IACE;AAAA,IACA;AAAA,IACA;AAAA,IACA,UAAU;AAAA,EACZ;AAEA,MAAI;AACF,QAAI,SAAS,MAAM;AAAA,MACjB,OAAO;AAAA,MACP,OAAO,YAAY,sBAAsB;AAAA,IAC3C;AAAA,EACF,SAAS,OAAO;AACd,WAAO,IAAI,KAAK;AAAA,EAClB;AAEA,SAAO,IAAI;AACb","sourcesContent":["import type { JsonRpcEngineEndCallback } from '@metamask/json-rpc-engine';\nimport type { PermittedHandlerExport } from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type { GetFileParams, GetFileResult } from '@metamask/snaps-sdk';\nimport { AuxiliaryFileEncoding, enumValue } from '@metamask/snaps-sdk';\nimport type { InferMatching } from '@metamask/snaps-utils';\nimport type { PendingJsonRpcResponse, JsonRpcRequest } from '@metamask/utils';\nimport { assertStruct } from '@metamask/utils';\nimport { object, optional, string, union } from 'superstruct';\n\nimport type { MethodHooksObject } from '../utils';\n\nexport const GetFileArgsStruct = object({\n path: string(),\n encoding: optional(\n union([\n enumValue(AuxiliaryFileEncoding.Base64),\n enumValue(AuxiliaryFileEncoding.Hex),\n enumValue(AuxiliaryFileEncoding.Utf8),\n ]),\n ),\n});\n\nexport type InferredGetFileParams = InferMatching<\n typeof GetFileArgsStruct,\n GetFileParams\n>;\n\nconst hookNames: MethodHooksObject<GetFileHooks> = {\n getSnapFile: true,\n};\n\nexport const getFileHandler: PermittedHandlerExport<\n GetFileHooks,\n InferredGetFileParams,\n string\n> = {\n methodNames: ['snap_getFile'],\n implementation,\n hookNames,\n};\n\nexport type GetFileHooks = {\n getSnapFile: (\n path: InferredGetFileParams['path'],\n encoding: InferredGetFileParams['encoding'],\n ) => Promise<string>;\n};\n\n/**\n * The `snap_getFile` method implementation.\n *\n * @param req - The JSON-RPC request object.\n * @param res - The JSON-RPC response object.\n * @param _next - The `json-rpc-engine` \"next\" callback. Not used by this\n * function.\n * @param end - The `json-rpc-engine` \"end\" callback.\n * @param hooks - The RPC method hooks.\n * @param hooks.getSnapFile - The function to load a static snap file.\n * @returns Nothing.\n */\nasync function implementation(\n req: JsonRpcRequest<InferredGetFileParams>,\n res: PendingJsonRpcResponse<GetFileResult>,\n _next: unknown,\n end: JsonRpcEngineEndCallback,\n { getSnapFile }: GetFileHooks,\n): Promise<void> {\n const { params } = req;\n\n assertStruct(\n params,\n GetFileArgsStruct,\n 'Invalid \"snap_getFile\" parameters',\n rpcErrors.invalidParams,\n );\n\n try {\n res.result = await getSnapFile(\n params.path,\n params.encoding ?? AuxiliaryFileEncoding.Base64,\n );\n } catch (error) {\n return end(error);\n }\n\n return end();\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/restricted/caveats/permittedDerivationPaths.ts"],"sourcesContent":["import type {\n Caveat,\n PermissionConstraint,\n RestrictedMethodCaveatSpecificationConstraint,\n} from '@metamask/permission-controller';\nimport { providerErrors, rpcErrors } from '@metamask/rpc-errors';\nimport type { Bip32Entropy } from '@metamask/snaps-utils';\nimport {\n SnapCaveatType,\n Bip32EntropyStruct,\n isEqual,\n} from '@metamask/snaps-utils';\nimport type { Json } from '@metamask/utils';\nimport { assertStruct } from '@metamask/utils';\nimport { array, size, type } from 'superstruct';\n\n/**\n * Map a raw value from the `initialPermissions` to a caveat specification.\n * Note that this function does not do any validation, that's handled by the\n * PermissionsController when the permission is requested.\n *\n * @param value - The raw value from the `initialPermissions`.\n * @returns The caveat specification.\n */\nexport function permittedDerivationPathsCaveatMapper(\n value: Json,\n): Pick<PermissionConstraint, 'caveats'> {\n return {\n caveats: [\n {\n type: SnapCaveatType.PermittedDerivationPaths,\n value,\n },\n ],\n };\n}\n\n/**\n * Validate a caveat path object. The object must consist of a `path` array and\n * a `curve` string. Paths must start with `m`, and must contain at\n * least two indices. If `ed25519` is used, this checks if all the path indices\n * are hardened.\n *\n * @param value - The value to validate.\n * @throws If the value is invalid.\n */\nexport function validateBIP32Path(\n value: unknown,\n): asserts value is Bip32Entropy {\n assertStruct(\n value,\n Bip32EntropyStruct,\n 'Invalid BIP-32 entropy path definition',\n rpcErrors.invalidParams,\n );\n}\n\n/**\n * Validate the path values associated with a caveat. This validates that the\n * value is a non-empty array with valid derivation paths and curves.\n *\n * @param caveat - The caveat to validate.\n * @throws If the value is invalid.\n */\nexport function validateBIP32CaveatPaths(\n caveat: Caveat<string, any>,\n): asserts caveat is Caveat<string, Bip32Entropy[]> {\n assertStruct(\n caveat,\n type({ value: size(array(Bip32EntropyStruct), 1, Infinity) }),\n 'Invalid BIP-32 entropy caveat',\n rpcErrors.internal,\n );\n}\n\nexport const PermittedDerivationPathsCaveatSpecification: Record<\n SnapCaveatType.PermittedDerivationPaths,\n RestrictedMethodCaveatSpecificationConstraint\n> = {\n [SnapCaveatType.PermittedDerivationPaths]: Object.freeze({\n type: SnapCaveatType.PermittedDerivationPaths,\n decorator: (method, caveat) => {\n return async (args) => {\n const { params } = args;\n validateBIP32Path(params);\n\n const path = (caveat.value as Bip32Entropy[]).find(\n (caveatPath) =>\n isEqual(\n params.path.slice(0, caveatPath.path.length),\n caveatPath.path,\n ) && caveatPath.curve === params.curve,\n );\n\n if (!path) {\n throw providerErrors.unauthorized({\n message:\n 'The requested path is not permitted. Allowed paths must be specified in the snap manifest.',\n });\n }\n\n return await method(args);\n };\n },\n validator: (caveat) => validateBIP32CaveatPaths(caveat),\n }),\n};\n"],"mappings":";AAKA,SAAS,gBAAgB,iBAAiB;AAE1C;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,oBAAoB;AAC7B,SAAS,OAAO,MAAM,YAAY;AAU3B,SAAS,qCACd,OACuC;AACvC,SAAO;AAAA,IACL,SAAS;AAAA,MACP;AAAA,QACE,MAAM,eAAe;AAAA,QACrB;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;AAWO,SAAS,kBACd,OAC+B;AAC/B;AAAA,IACE;AAAA,IACA;AAAA,IACA;AAAA,IACA,UAAU;AAAA,EACZ;AACF;AASO,SAAS,yBACd,QACkD;AAClD;AAAA,IACE;AAAA,IACA,KAAK,EAAE,OAAO,KAAK,MAAM,kBAAkB,GAAG,GAAG,QAAQ,EAAE,CAAC;AAAA,IAC5D;AAAA,IACA,UAAU;AAAA,EACZ;AACF;AAEO,IAAM,8CAGT;AAAA,EACF,CAAC,eAAe,wBAAwB,GAAG,OAAO,OAAO;AAAA,IACvD,MAAM,eAAe;AAAA,IACrB,WAAW,CAAC,QAAQ,WAAW;AAC7B,aAAO,OAAO,SAAS;AACrB,cAAM,EAAE,OAAO,IAAI;AACnB,0BAAkB,MAAM;AAExB,cAAM,OAAQ,OAAO,MAAyB;AAAA,UAC5C,CAAC,eACC;AAAA,YACE,OAAO,KAAK,MAAM,GAAG,WAAW,KAAK,MAAM;AAAA,YAC3C,WAAW;AAAA,UACb,KAAK,WAAW,UAAU,OAAO;AAAA,QACrC;AAEA,YAAI,CAAC,MAAM;AACT,gBAAM,eAAe,aAAa;AAAA,YAChC,SACE;AAAA,UACJ,CAAC;AAAA,QACH;AAEA,eAAO,MAAM,OAAO,IAAI;AAAA,MAC1B;AAAA,IACF;AAAA,IACA,WAAW,CAAC,WAAW,yBAAyB,MAAM;AAAA,EACxD,CAAC;AACH;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/permitted/createInterface.ts"],"names":[],"mappings":";AAEA,SAAS,iBAAiB;AAQ1B;AAAA,EACE;AAAA,EACA;AAAA,OACK;AAGP,SAAS,aAAa,QAAQ,QAAQ,gBAAgB;AAItD,IAAM,YAA2D;AAAA,EAC/D,iBAAiB;AACnB;AAaO,IAAM,yBAIT;AAAA,EACF,aAAa,CAAC,sBAAsB;AAAA,EACpC,gBAAgB;AAAA,EAChB;AACF;AAEA,IAAM,kCAAkC,OAAO;AAAA,EAC7C,IAAI;AAAA,EACJ,SAAS,SAAS,sBAAsB;AAC1C,CAAC;AAmBD,eAAe,iCACb,KACA,KACA,OACA,KACA,EAAE,gBAAgB,GACH;AACf,QAAM,EAAE,OAAO,IAAI;AAEnB,MAAI;AACF,UAAM,kBAAkB,mBAAmB,MAAM;AAEjD,UAAM,EAAE,IAAI,QAAQ,IAAI;AAExB,QAAI,SAAS,MAAM,gBAAgB,IAAI,OAAO;AAAA,EAChD,SAAS,OAAO;AACd,WAAO,IAAI,KAAK;AAAA,EAClB;AAEA,SAAO,IAAI;AACb;AASA,SAAS,mBAAmB,QAA4C;AACtE,MAAI;AACF,WAAO,OAAO,QAAQ,+BAA+B;AAAA,EACvD,SAAS,OAAO;AACd,QAAI,iBAAiB,aAAa;AAChC,YAAM,UAAU,cAAc;AAAA,QAC5B,SAAS,mBAAmB,MAAM,OAAO;AAAA,MAC3C,CAAC;AAAA,IACH;AAEA,UAAM,UAAU,SAAS;AAAA,EAC3B;AACF","sourcesContent":["import type { JsonRpcEngineEndCallback } from '@metamask/json-rpc-engine';\nimport type { PermittedHandlerExport } from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type {\n CreateInterfaceParams,\n CreateInterfaceResult,\n JsonRpcRequest,\n ComponentOrElement,\n InterfaceContext,\n} from '@metamask/snaps-sdk';\nimport {\n ComponentOrElementStruct,\n InterfaceContextStruct,\n} from '@metamask/snaps-sdk';\nimport { type InferMatching } from '@metamask/snaps-utils';\nimport type { PendingJsonRpcResponse } from '@metamask/utils';\nimport { StructError, create, object, optional } from 'superstruct';\n\nimport type { MethodHooksObject } from '../utils';\n\nconst hookNames: MethodHooksObject<CreateInterfaceMethodHooks> = {\n createInterface: true,\n};\n\nexport type CreateInterfaceMethodHooks = {\n /**\n * @param ui - The UI components.\n * @returns The unique identifier of the interface.\n */\n createInterface: (\n ui: ComponentOrElement,\n context?: InterfaceContext,\n ) => Promise<string>;\n};\n\nexport const createInterfaceHandler: PermittedHandlerExport<\n CreateInterfaceMethodHooks,\n CreateInterfaceParameters,\n CreateInterfaceResult\n> = {\n methodNames: ['snap_createInterface'],\n implementation: getCreateInterfaceImplementation,\n hookNames,\n};\n\nconst CreateInterfaceParametersStruct = object({\n ui: ComponentOrElementStruct,\n context: optional(InterfaceContextStruct),\n});\n\nexport type CreateInterfaceParameters = InferMatching<\n typeof CreateInterfaceParametersStruct,\n CreateInterfaceParams\n>;\n\n/**\n * The `snap_createInterface` method implementation.\n *\n * @param req - The JSON-RPC request object.\n * @param res - The JSON-RPC response object.\n * @param _next - The `json-rpc-engine` \"next\" callback. Not used by this\n * function.\n * @param end - The `json-rpc-engine` \"end\" callback.\n * @param hooks - The RPC method hooks.\n * @param hooks.createInterface - The function to create the interface.\n * @returns Nothing.\n */\nasync function getCreateInterfaceImplementation(\n req: JsonRpcRequest<CreateInterfaceParameters>,\n res: PendingJsonRpcResponse<CreateInterfaceResult>,\n _next: unknown,\n end: JsonRpcEngineEndCallback,\n { createInterface }: CreateInterfaceMethodHooks,\n): Promise<void> {\n const { params } = req;\n\n try {\n const validatedParams = getValidatedParams(params);\n\n const { ui, context } = validatedParams;\n\n res.result = await createInterface(ui, context);\n } catch (error) {\n return end(error);\n }\n\n return end();\n}\n\n/**\n * Validate the createInterface 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 * @returns The validated createInterface method parameter object.\n */\nfunction getValidatedParams(params: unknown): CreateInterfaceParameters {\n try {\n return create(params, CreateInterfaceParametersStruct);\n } catch (error) {\n if (error instanceof StructError) {\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${error.message}.`,\n });\n }\n /* istanbul ignore next */\n throw rpcErrors.internal();\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/restricted/caveats/permittedDerivationPaths.ts"],"names":[],"mappings":";AAKA,SAAS,gBAAgB,iBAAiB;AAE1C;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,oBAAoB;AAC7B,SAAS,OAAO,MAAM,YAAY;AAU3B,SAAS,qCACd,OACuC;AACvC,SAAO;AAAA,IACL,SAAS;AAAA,MACP;AAAA,QACE,MAAM,eAAe;AAAA,QACrB;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;AAWO,SAAS,kBACd,OAC+B;AAC/B;AAAA,IACE;AAAA,IACA;AAAA,IACA;AAAA,IACA,UAAU;AAAA,EACZ;AACF;AASO,SAAS,yBACd,QACkD;AAClD;AAAA,IACE;AAAA,IACA,KAAK,EAAE,OAAO,KAAK,MAAM,kBAAkB,GAAG,GAAG,QAAQ,EAAE,CAAC;AAAA,IAC5D;AAAA,IACA,UAAU;AAAA,EACZ;AACF;AAEO,IAAM,8CAGT;AAAA,EACF,CAAC,eAAe,wBAAwB,GAAG,OAAO,OAAO;AAAA,IACvD,MAAM,eAAe;AAAA,IACrB,WAAW,CAAC,QAAQ,WAAW;AAC7B,aAAO,OAAO,SAAS;AACrB,cAAM,EAAE,OAAO,IAAI;AACnB,0BAAkB,MAAM;AAExB,cAAM,OAAQ,OAAO,MAAyB;AAAA,UAC5C,CAAC,eACC;AAAA,YACE,OAAO,KAAK,MAAM,GAAG,WAAW,KAAK,MAAM;AAAA,YAC3C,WAAW;AAAA,UACb,KAAK,WAAW,UAAU,OAAO;AAAA,QACrC;AAEA,YAAI,CAAC,MAAM;AACT,gBAAM,eAAe,aAAa;AAAA,YAChC,SACE;AAAA,UACJ,CAAC;AAAA,QACH;AAEA,eAAO,MAAM,OAAO,IAAI;AAAA,MAC1B;AAAA,IACF;AAAA,IACA,WAAW,CAAC,WAAW,yBAAyB,MAAM;AAAA,EACxD,CAAC;AACH","sourcesContent":["import type {\n Caveat,\n PermissionConstraint,\n RestrictedMethodCaveatSpecificationConstraint,\n} from '@metamask/permission-controller';\nimport { providerErrors, rpcErrors } from '@metamask/rpc-errors';\nimport type { Bip32Entropy } from '@metamask/snaps-utils';\nimport {\n SnapCaveatType,\n Bip32EntropyStruct,\n isEqual,\n} from '@metamask/snaps-utils';\nimport type { Json } from '@metamask/utils';\nimport { assertStruct } from '@metamask/utils';\nimport { array, size, type } from 'superstruct';\n\n/**\n * Map a raw value from the `initialPermissions` to a caveat specification.\n * Note that this function does not do any validation, that's handled by the\n * PermissionsController when the permission is requested.\n *\n * @param value - The raw value from the `initialPermissions`.\n * @returns The caveat specification.\n */\nexport function permittedDerivationPathsCaveatMapper(\n value: Json,\n): Pick<PermissionConstraint, 'caveats'> {\n return {\n caveats: [\n {\n type: SnapCaveatType.PermittedDerivationPaths,\n value,\n },\n ],\n };\n}\n\n/**\n * Validate a caveat path object. The object must consist of a `path` array and\n * a `curve` string. Paths must start with `m`, and must contain at\n * least two indices. If `ed25519` is used, this checks if all the path indices\n * are hardened.\n *\n * @param value - The value to validate.\n * @throws If the value is invalid.\n */\nexport function validateBIP32Path(\n value: unknown,\n): asserts value is Bip32Entropy {\n assertStruct(\n value,\n Bip32EntropyStruct,\n 'Invalid BIP-32 entropy path definition',\n rpcErrors.invalidParams,\n );\n}\n\n/**\n * Validate the path values associated with a caveat. This validates that the\n * value is a non-empty array with valid derivation paths and curves.\n *\n * @param caveat - The caveat to validate.\n * @throws If the value is invalid.\n */\nexport function validateBIP32CaveatPaths(\n caveat: Caveat<string, any>,\n): asserts caveat is Caveat<string, Bip32Entropy[]> {\n assertStruct(\n caveat,\n type({ value: size(array(Bip32EntropyStruct), 1, Infinity) }),\n 'Invalid BIP-32 entropy caveat',\n rpcErrors.internal,\n );\n}\n\nexport const PermittedDerivationPathsCaveatSpecification: Record<\n SnapCaveatType.PermittedDerivationPaths,\n RestrictedMethodCaveatSpecificationConstraint\n> = {\n [SnapCaveatType.PermittedDerivationPaths]: Object.freeze({\n type: SnapCaveatType.PermittedDerivationPaths,\n decorator: (method, caveat) => {\n return async (args) => {\n const { params } = args;\n validateBIP32Path(params);\n\n const path = (caveat.value as Bip32Entropy[]).find(\n (caveatPath) =>\n isEqual(\n params.path.slice(0, caveatPath.path.length),\n caveatPath.path,\n ) && caveatPath.curve === params.curve,\n );\n\n if (!path) {\n throw providerErrors.unauthorized({\n message:\n 'The requested path is not permitted. Allowed paths must be specified in the snap manifest.',\n });\n }\n\n return await method(args);\n };\n },\n validator: (caveat) => validateBIP32CaveatPaths(caveat),\n }),\n};\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/restricted/getBip32PublicKey.ts"],"sourcesContent":["import 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 type { NonEmptyArray } from '@metamask/utils';\nimport { assertStruct } from '@metamask/utils';\nimport { boolean, object, optional } from 'superstruct';\n\nimport type { MethodHooksObject } from '../utils';\nimport { getNode } from '../utils';\n\nconst targetName = 'snap_getBip32PublicKey';\n\nexport type GetBip32PublicKeyMethodHooks = {\n /**\n * @returns The mnemonic of the user's primary keyring.\n */\n getMnemonic: () => 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\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 }),\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};\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 * @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}: 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 node = await getNode({\n curve: params.curve,\n path: params.path,\n secretRecoveryPhrase: await getMnemonic(),\n });\n\n if (params.compressed) {\n return node.compressedPublicKey;\n }\n\n return node.publicKey;\n };\n}\n"],"mappings":";;;;;AAMA,SAAS,gBAAgB,mBAAmB;AAC5C,SAAS,iBAAiB;AAK1B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,oBAAoB;AAC7B,SAAS,SAAS,QAAQ,gBAAgB;AAK1C,IAAM,aAAa;AA4BZ,IAAM,2BAA2B;AAAA,EACtC,OAAO;AAAA,IACL,MAAM;AAAA,IACN,OAAO;AAAA,IACP,YAAY,SAAS,QAAQ,CAAC;AAAA,EAChC,CAAC;AACH;AAWA,IAAM,uBAIF,CAAC,EAAE,aAAAA,aAAY,MAAoD;AACrE,SAAO;AAAA,IACL,gBAAgB,eAAe;AAAA,IAC/B;AAAA,IACA,gBAAgB,CAAC,eAAe,wBAAwB;AAAA,IACxD,sBAAsB,gCAAgCA,YAAW;AAAA,IACjE,WAAW,CAAC,EAAE,QAAQ,MAAM;AAC1B,UACE,SAAS,WAAW,KACpB,QAAQ,CAAC,EAAE,SAAS,eAAe,0BACnC;AACA,cAAM,UAAU,cAAc;AAAA,UAC5B,SAAS,sBAAsB,eAAe,wBAAwB;AAAA,QACxE,CAAC;AAAA,MACH;AAAA,IACF;AAAA,IACA,cAAc,CAAC,YAAY,IAAI;AAAA,EACjC;AACF;AAEA,IAAM,cAA+D;AAAA,EACnE,aAAa;AAAA,EACb,kBAAkB;AACpB;AAEO,IAAM,2BAA2B,OAAO,OAAO;AAAA,EACpD;AAAA,EACA;AAAA,EACA;AACF,CAAU;AAYH,SAAS,gCAAgC;AAAA,EAC9C;AAAA,EACA;AACF,GAAiC;AAC/B,SAAO,eAAe,kBACpB,MACkC;AAClC,UAAM,iBAAiB,IAAI;AAE3B;AAAA,MACE,KAAK;AAAA,MACL;AAAA,MACA;AAAA,MACA,UAAU;AAAA,IACZ;AAEA,UAAM,EAAE,OAAO,IAAI;AACnB,UAAM,OAAO,MAAM,QAAQ;AAAA,MACzB,OAAO,OAAO;AAAA,MACd,MAAM,OAAO;AAAA,MACb,sBAAsB,MAAM,YAAY;AAAA,IAC1C,CAAC;AAED,QAAI,OAAO,YAAY;AACrB,aAAO,KAAK;AAAA,IACd;AAEA,WAAO,KAAK;AAAA,EACd;AACF;","names":["methodHooks"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/restricted/caveats/snapIds.ts"],"sourcesContent":["import type {\n Caveat,\n RestrictedMethodOptions,\n RestrictedMethodParameters,\n RestrictedMethodCaveatSpecificationConstraint,\n PermissionConstraint,\n} from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type { SnapIds } from '@metamask/snaps-utils';\nimport { SnapCaveatType, SnapIdsStruct } from '@metamask/snaps-utils';\nimport type { Json } from '@metamask/utils';\nimport { hasProperty, assertStruct } from '@metamask/utils';\nimport { type } from 'superstruct';\n\nimport type { InvokeSnapParams } from '../invokeSnap';\n\n/**\n * Map a raw value from the `initialPermissions` to a caveat specification.\n * Note that this function does not do any validation, that's handled by the\n * PermissionsController when the permission is requested.\n *\n * @param value - The raw value from the `initialPermissions`.\n * @returns The caveat specification.\n */\nexport function snapIdsCaveatMapper(\n value: Json,\n): Pick<PermissionConstraint, 'caveats'> {\n return {\n caveats: [\n {\n type: SnapCaveatType.SnapIds,\n value,\n },\n ],\n };\n}\n\n/**\n * Validates that the caveat value exists and is a non-empty object.\n *\n * @param caveat - The caveat to validate.\n * @throws If the caveat is invalid.\n */\nexport function validateSnapIdsCaveat(\n caveat: Caveat<string, any>,\n): asserts caveat is Caveat<string, SnapIds> {\n assertStruct(\n caveat,\n type({\n value: SnapIdsStruct,\n }),\n 'Expected caveat to have a value property of a non-empty object of snap IDs.',\n rpcErrors.invalidParams,\n );\n}\n\nexport const SnapIdsCaveatSpecification: Record<\n SnapCaveatType.SnapIds,\n RestrictedMethodCaveatSpecificationConstraint\n> = {\n [SnapCaveatType.SnapIds]: Object.freeze({\n type: SnapCaveatType.SnapIds,\n validator: (caveat) => validateSnapIdsCaveat(caveat),\n decorator: (method, caveat) => {\n return async (args) => {\n const {\n params,\n context: { origin },\n }: RestrictedMethodOptions<RestrictedMethodParameters> = args;\n const snapIds = caveat.value as SnapIds;\n const { snapId } = params as InvokeSnapParams;\n if (!hasProperty(snapIds, snapId)) {\n throw new Error(\n `${origin} does not have permission to invoke ${snapId} snap.`,\n );\n }\n return await method(args);\n };\n },\n }),\n};\n"],"mappings":";AAOA,SAAS,iBAAiB;AAE1B,SAAS,gBAAgB,qBAAqB;AAE9C,SAAS,aAAa,oBAAoB;AAC1C,SAAS,YAAY;AAYd,SAAS,oBACd,OACuC;AACvC,SAAO;AAAA,IACL,SAAS;AAAA,MACP;AAAA,QACE,MAAM,eAAe;AAAA,QACrB;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;AAQO,SAAS,sBACd,QAC2C;AAC3C;AAAA,IACE;AAAA,IACA,KAAK;AAAA,MACH,OAAO;AAAA,IACT,CAAC;AAAA,IACD;AAAA,IACA,UAAU;AAAA,EACZ;AACF;AAEO,IAAM,6BAGT;AAAA,EACF,CAAC,eAAe,OAAO,GAAG,OAAO,OAAO;AAAA,IACtC,MAAM,eAAe;AAAA,IACrB,WAAW,CAAC,WAAW,sBAAsB,MAAM;AAAA,IACnD,WAAW,CAAC,QAAQ,WAAW;AAC7B,aAAO,OAAO,SAAS;AACrB,cAAM;AAAA,UACJ;AAAA,UACA,SAAS,EAAE,OAAO;AAAA,QACpB,IAAyD;AACzD,cAAM,UAAU,OAAO;AACvB,cAAM,EAAE,OAAO,IAAI;AACnB,YAAI,CAAC,YAAY,SAAS,MAAM,GAAG;AACjC,gBAAM,IAAI;AAAA,YACR,GAAG,MAAM,uCAAuC,MAAM;AAAA,UACxD;AAAA,QACF;AACA,eAAO,MAAM,OAAO,IAAI;AAAA,MAC1B;AAAA,IACF;AAAA,EACF,CAAC;AACH;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/permitted/getInterfaceState.ts"],"sourcesContent":["import type { JsonRpcEngineEndCallback } from '@metamask/json-rpc-engine';\nimport type { PermittedHandlerExport } from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type {\n GetInterfaceStateParams,\n GetInterfaceStateResult,\n InterfaceState,\n JsonRpcRequest,\n} from '@metamask/snaps-sdk';\nimport { type InferMatching } from '@metamask/snaps-utils';\nimport type { PendingJsonRpcResponse } from '@metamask/utils';\nimport { StructError, create, object, string } from 'superstruct';\n\nimport type { MethodHooksObject } from '../utils';\n\nconst hookNames: MethodHooksObject<GetInterfaceStateMethodHooks> = {\n getInterfaceState: true,\n};\n\nexport type GetInterfaceStateMethodHooks = {\n /**\n * @param id - The interface ID.\n * @returns The interface state.\n */\n getInterfaceState: (id: string) => InterfaceState;\n};\n\nexport const getInterfaceStateHandler: PermittedHandlerExport<\n GetInterfaceStateMethodHooks,\n GetInterfaceStateParameters,\n GetInterfaceStateResult\n> = {\n methodNames: ['snap_getInterfaceState'],\n implementation: getGetInterfaceStateImplementation,\n hookNames,\n};\n\nconst GetInterfaceStateParametersStruct = object({\n id: string(),\n});\n\nexport type GetInterfaceStateParameters = InferMatching<\n typeof GetInterfaceStateParametersStruct,\n GetInterfaceStateParams\n>;\n\n/**\n * The `snap_getInterfaceState` method implementation.\n *\n * @param req - The JSON-RPC request object.\n * @param res - The JSON-RPC response object.\n * @param _next - The `json-rpc-engine` \"next\" callback. Not used by this\n * function.\n * @param end - The `json-rpc-engine` \"end\" callback.\n * @param hooks - The RPC method hooks.\n * @param hooks.getInterfaceState - The function to get the interface state.\n * @returns Noting.\n */\nfunction getGetInterfaceStateImplementation(\n req: JsonRpcRequest<GetInterfaceStateParameters>,\n res: PendingJsonRpcResponse<GetInterfaceStateResult>,\n _next: unknown,\n end: JsonRpcEngineEndCallback,\n { getInterfaceState }: GetInterfaceStateMethodHooks,\n): void {\n const { params } = req;\n\n try {\n const validatedParams = getValidatedParams(params);\n\n const { id } = validatedParams;\n\n res.result = getInterfaceState(id);\n } catch (error) {\n return end(error);\n }\n\n return end();\n}\n\n/**\n * Validate the getInterfaceState 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 * @returns The validated getInterfaceState method parameter object.\n */\nfunction getValidatedParams(params: unknown): GetInterfaceStateParameters {\n try {\n return create(params, GetInterfaceStateParametersStruct);\n } catch (error) {\n if (error instanceof StructError) {\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${error.message}.`,\n });\n }\n /* istanbul ignore next */\n throw rpcErrors.internal();\n }\n}\n"],"mappings":";AAEA,SAAS,iBAAiB;AAS1B,SAAS,aAAa,QAAQ,QAAQ,cAAc;AAIpD,IAAM,YAA6D;AAAA,EACjE,mBAAmB;AACrB;AAUO,IAAM,2BAIT;AAAA,EACF,aAAa,CAAC,wBAAwB;AAAA,EACtC,gBAAgB;AAAA,EAChB;AACF;AAEA,IAAM,oCAAoC,OAAO;AAAA,EAC/C,IAAI,OAAO;AACb,CAAC;AAmBD,SAAS,mCACP,KACA,KACA,OACA,KACA,EAAE,kBAAkB,GACd;AACN,QAAM,EAAE,OAAO,IAAI;AAEnB,MAAI;AACF,UAAM,kBAAkB,mBAAmB,MAAM;AAEjD,UAAM,EAAE,GAAG,IAAI;AAEf,QAAI,SAAS,kBAAkB,EAAE;AAAA,EACnC,SAAS,OAAO;AACd,WAAO,IAAI,KAAK;AAAA,EAClB;AAEA,SAAO,IAAI;AACb;AASA,SAAS,mBAAmB,QAA8C;AACxE,MAAI;AACF,WAAO,OAAO,QAAQ,iCAAiC;AAAA,EACzD,SAAS,OAAO;AACd,QAAI,iBAAiB,aAAa;AAChC,YAAM,UAAU,cAAc;AAAA,QAC5B,SAAS,mBAAmB,MAAM,OAAO;AAAA,MAC3C,CAAC;AAAA,IACH;AAEA,UAAM,UAAU,SAAS;AAAA,EAC3B;AACF;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/permitted/createInterface.ts"],"sourcesContent":["import type { JsonRpcEngineEndCallback } from '@metamask/json-rpc-engine';\nimport type { PermittedHandlerExport } from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type {\n CreateInterfaceParams,\n CreateInterfaceResult,\n JsonRpcRequest,\n ComponentOrElement,\n InterfaceContext,\n} from '@metamask/snaps-sdk';\nimport {\n ComponentOrElementStruct,\n InterfaceContextStruct,\n} from '@metamask/snaps-sdk';\nimport { type InferMatching } from '@metamask/snaps-utils';\nimport type { PendingJsonRpcResponse } from '@metamask/utils';\nimport { StructError, create, object, optional } from 'superstruct';\n\nimport type { MethodHooksObject } from '../utils';\n\nconst hookNames: MethodHooksObject<CreateInterfaceMethodHooks> = {\n createInterface: true,\n};\n\nexport type CreateInterfaceMethodHooks = {\n /**\n * @param ui - The UI components.\n * @returns The unique identifier of the interface.\n */\n createInterface: (\n ui: ComponentOrElement,\n context?: InterfaceContext,\n ) => Promise<string>;\n};\n\nexport const createInterfaceHandler: PermittedHandlerExport<\n CreateInterfaceMethodHooks,\n CreateInterfaceParameters,\n CreateInterfaceResult\n> = {\n methodNames: ['snap_createInterface'],\n implementation: getCreateInterfaceImplementation,\n hookNames,\n};\n\nconst CreateInterfaceParametersStruct = object({\n ui: ComponentOrElementStruct,\n context: optional(InterfaceContextStruct),\n});\n\nexport type CreateInterfaceParameters = InferMatching<\n typeof CreateInterfaceParametersStruct,\n CreateInterfaceParams\n>;\n\n/**\n * The `snap_createInterface` method implementation.\n *\n * @param req - The JSON-RPC request object.\n * @param res - The JSON-RPC response object.\n * @param _next - The `json-rpc-engine` \"next\" callback. Not used by this\n * function.\n * @param end - The `json-rpc-engine` \"end\" callback.\n * @param hooks - The RPC method hooks.\n * @param hooks.createInterface - The function to create the interface.\n * @returns Nothing.\n */\nasync function getCreateInterfaceImplementation(\n req: JsonRpcRequest<CreateInterfaceParameters>,\n res: PendingJsonRpcResponse<CreateInterfaceResult>,\n _next: unknown,\n end: JsonRpcEngineEndCallback,\n { createInterface }: CreateInterfaceMethodHooks,\n): Promise<void> {\n const { params } = req;\n\n try {\n const validatedParams = getValidatedParams(params);\n\n const { ui, context } = validatedParams;\n\n res.result = await createInterface(ui, context);\n } catch (error) {\n return end(error);\n }\n\n return end();\n}\n\n/**\n * Validate the createInterface 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 * @returns The validated createInterface method parameter object.\n */\nfunction getValidatedParams(params: unknown): CreateInterfaceParameters {\n try {\n return create(params, CreateInterfaceParametersStruct);\n } catch (error) {\n if (error instanceof StructError) {\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${error.message}.`,\n });\n }\n /* istanbul ignore next */\n throw rpcErrors.internal();\n }\n}\n"],"mappings":";AAEA,SAAS,iBAAiB;AAQ1B;AAAA,EACE;AAAA,EACA;AAAA,OACK;AAGP,SAAS,aAAa,QAAQ,QAAQ,gBAAgB;AAItD,IAAM,YAA2D;AAAA,EAC/D,iBAAiB;AACnB;AAaO,IAAM,yBAIT;AAAA,EACF,aAAa,CAAC,sBAAsB;AAAA,EACpC,gBAAgB;AAAA,EAChB;AACF;AAEA,IAAM,kCAAkC,OAAO;AAAA,EAC7C,IAAI;AAAA,EACJ,SAAS,SAAS,sBAAsB;AAC1C,CAAC;AAmBD,eAAe,iCACb,KACA,KACA,OACA,KACA,EAAE,gBAAgB,GACH;AACf,QAAM,EAAE,OAAO,IAAI;AAEnB,MAAI;AACF,UAAM,kBAAkB,mBAAmB,MAAM;AAEjD,UAAM,EAAE,IAAI,QAAQ,IAAI;AAExB,QAAI,SAAS,MAAM,gBAAgB,IAAI,OAAO;AAAA,EAChD,SAAS,OAAO;AACd,WAAO,IAAI,KAAK;AAAA,EAClB;AAEA,SAAO,IAAI;AACb;AASA,SAAS,mBAAmB,QAA4C;AACtE,MAAI;AACF,WAAO,OAAO,QAAQ,+BAA+B;AAAA,EACvD,SAAS,OAAO;AACd,QAAI,iBAAiB,aAAa;AAChC,YAAM,UAAU,cAAc;AAAA,QAC5B,SAAS,mBAAmB,MAAM,OAAO;AAAA,MAC3C,CAAC;AAAA,IACH;AAEA,UAAM,UAAU,SAAS;AAAA,EAC3B;AACF;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/restricted/dialog.ts"],"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 {\n DialogType,\n enumValue,\n union,\n ComponentOrElementStruct,\n} from '@metamask/snaps-sdk';\nimport type {\n DialogParams,\n EnumToUnion,\n Component,\n InterfaceState,\n SnapId,\n ComponentOrElement,\n} from '@metamask/snaps-sdk';\nimport { createUnion } from '@metamask/snaps-utils';\nimport type { InferMatching } from '@metamask/snaps-utils';\nimport { hasProperty, type NonEmptyArray } from '@metamask/utils';\nimport type { Infer, Struct } from 'superstruct';\nimport {\n create,\n enums,\n object,\n optional,\n size,\n string,\n type,\n} from 'superstruct';\n\nimport { type MethodHooksObject } from '../utils';\n\nconst methodName = 'snap_dialog';\n\nconst PlaceholderStruct = optional(size(string(), 1, 40));\n\nexport type Placeholder = Infer<typeof PlaceholderStruct>;\n\ntype ShowDialog = (\n snapId: string,\n type: EnumToUnion<DialogType>,\n id: string,\n placeholder?: Placeholder,\n) => Promise<null | boolean | string>;\n\ntype CreateInterface = (\n snapId: string,\n content: ComponentOrElement,\n) => Promise<string>;\n\ntype GetInterface = (\n snapId: string,\n id: string,\n) => { content: ComponentOrElement; snapId: SnapId; state: InterfaceState };\n\nexport type DialogMethodHooks = {\n /**\n * @param snapId - The ID of the Snap that created the alert.\n * @param type - The dialog type.\n * @param id - The interface ID.\n * @param placeholder - The placeholder for the Prompt dialog input.\n */\n showDialog: ShowDialog;\n\n /**\n * @param snapId - The Snap ID creating the interface.\n * @param content - The content of the interface.\n */\n createInterface: CreateInterface;\n /**\n * @param snapId - The SnapId requesting the interface.\n * @param id - The interface ID.\n */\n getInterface: GetInterface;\n};\n\ntype DialogSpecificationBuilderOptions = {\n allowedCaveats?: Readonly<NonEmptyArray<string>> | null;\n methodHooks: DialogMethodHooks;\n};\n\ntype DialogSpecification = ValidPermissionSpecification<{\n permissionType: PermissionType.RestrictedMethod;\n targetName: typeof methodName;\n methodImplementation: ReturnType<typeof getDialogImplementation>;\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n}>;\n\n/**\n * The specification builder for the `snap_dialog` permission. `snap_dialog`\n * lets the Snap display one of the following dialogs to the user:\n * - An alert, for displaying information.\n * - A confirmation, for accepting or rejecting some action.\n * - A prompt, for inputting some information.\n *\n * @param options - The specification builder options.\n * @param options.allowedCaveats - The optional allowed caveats for the\n * permission.\n * @param options.methodHooks - The RPC method hooks needed by the method\n * implementation.\n * @returns The specification for the `snap_dialog` permission.\n */\nconst specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.RestrictedMethod,\n DialogSpecificationBuilderOptions,\n DialogSpecification\n> = ({\n allowedCaveats = null,\n methodHooks,\n}: DialogSpecificationBuilderOptions) => {\n return {\n permissionType: PermissionType.RestrictedMethod,\n targetName: methodName,\n allowedCaveats,\n methodImplementation: getDialogImplementation(methodHooks),\n subjectTypes: [SubjectType.Snap],\n };\n};\n\nconst methodHooks: MethodHooksObject<DialogMethodHooks> = {\n showDialog: true,\n createInterface: true,\n getInterface: true,\n};\n\nexport const dialogBuilder = Object.freeze({\n targetName: methodName,\n specificationBuilder,\n methodHooks,\n} as const);\n\n// Note: We use `type` here instead of `object` because `type` does not validate\n// the keys of the object, which is what we want.\nconst BaseParamsStruct = type({\n type: enums([DialogType.Alert, DialogType.Confirmation, DialogType.Prompt]),\n});\n\nconst AlertParametersWithContentStruct = object({\n type: enumValue(DialogType.Alert),\n content: ComponentOrElementStruct,\n});\nconst AlertParametersWithIdStruct = object({\n type: enumValue(DialogType.Alert),\n id: string(),\n});\n\nconst AlertParametersStruct = union([\n AlertParametersWithContentStruct,\n AlertParametersWithIdStruct,\n]);\n\nconst ConfirmationParametersWithContentStruct = object({\n type: enumValue(DialogType.Confirmation),\n content: ComponentOrElementStruct,\n});\n\nconst ConfirmationParametersWithIdStruct = object({\n type: enumValue(DialogType.Confirmation),\n id: string(),\n});\n\nconst ConfirmationParametersStruct = union([\n ConfirmationParametersWithContentStruct,\n ConfirmationParametersWithIdStruct,\n]);\n\nconst PromptParametersWithContentStruct = object({\n type: enumValue(DialogType.Prompt),\n content: ComponentOrElementStruct,\n placeholder: PlaceholderStruct,\n});\n\nconst PromptParametersWithIdStruct = object({\n type: enumValue(DialogType.Prompt),\n id: string(),\n placeholder: PlaceholderStruct,\n});\n\nconst PromptParametersStruct = union([\n PromptParametersWithContentStruct,\n PromptParametersWithIdStruct,\n]);\n\nconst DialogParametersStruct = union([\n AlertParametersStruct,\n ConfirmationParametersStruct,\n PromptParametersStruct,\n]);\n\nexport type DialogParameters = InferMatching<\n typeof DialogParametersStruct,\n DialogParams\n>;\n\nconst structs = {\n [DialogType.Alert]: AlertParametersStruct,\n [DialogType.Confirmation]: ConfirmationParametersStruct,\n [DialogType.Prompt]: PromptParametersStruct,\n};\n\n/**\n * Builds the method implementation for `snap_dialog`.\n *\n * @param hooks - The RPC method hooks.\n * @param hooks.showDialog - A function that shows the specified dialog in the\n * MetaMask UI and returns the appropriate value for the dialog type.\n * @param hooks.createInterface - A function that creates the interface in SnapInterfaceController.\n * @param hooks.getInterface - A function that gets an interface from SnapInterfaceController.\n * @returns The method implementation which return value depends on the dialog\n * type, valid return types are: string, boolean, null.\n */\nexport function getDialogImplementation({\n showDialog,\n createInterface,\n getInterface,\n}: DialogMethodHooks) {\n return async function dialogImplementation(\n args: RestrictedMethodOptions<DialogParameters>,\n ): Promise<boolean | null | string> {\n const {\n params,\n context: { origin },\n } = args;\n\n const validatedType = getValidatedType(params);\n const validatedParams = getValidatedParams(params, structs[validatedType]);\n\n const placeholder =\n validatedParams.type === DialogType.Prompt\n ? validatedParams.placeholder\n : undefined;\n\n if (hasProperty(validatedParams, 'content')) {\n const id = await createInterface(\n origin,\n validatedParams.content as Component,\n );\n return showDialog(origin, validatedType, id, placeholder);\n }\n\n // Verify that the passed interface ID is valid.\n // This will throw if the interface ID is invalid (not created by the snap or doesn't exist)\n try {\n getInterface(origin, validatedParams.id);\n } catch (error) {\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${error.message}`,\n });\n }\n\n return showDialog(origin, validatedType, validatedParams.id, placeholder);\n };\n}\n\n/**\n * Get the validated type of the dialog parameters. Throws an error if the type\n * is invalid.\n *\n * @param params - The parameters to validate.\n * @returns The validated type of the dialog parameters.\n */\nfunction getValidatedType(params: unknown): DialogType {\n try {\n return create(params, BaseParamsStruct).type;\n } catch (error) {\n throw rpcErrors.invalidParams({\n message: `The \"type\" property must be one of: ${Object.values(\n DialogType,\n ).join(', ')}.`,\n });\n }\n}\n\n/**\n * Validates the confirm 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 struct - The struct to validate the params against.\n * @returns The validated confirm method parameter object.\n */\nfunction getValidatedParams(\n params: unknown,\n struct: Struct<any, any>,\n): DialogParameters {\n try {\n return createUnion(params, struct, 'type');\n } catch (error) {\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${error.message}`,\n });\n }\n}\n"],"mappings":"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","names":["methodHooks"]}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|