@metamask/snaps-rpc-methods 5.0.0 → 6.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -3
- package/dist/cjs/endowments/caveats/generic.js +40 -0
- package/dist/cjs/endowments/caveats/generic.js.map +1 -0
- package/dist/cjs/endowments/caveats/index.js +21 -0
- package/dist/cjs/endowments/caveats/index.js.map +1 -0
- package/dist/cjs/endowments/caveats/requestTime.js +99 -0
- package/dist/cjs/endowments/caveats/requestTime.js.map +1 -0
- package/dist/cjs/endowments/cronjob.js +100 -0
- package/dist/cjs/endowments/cronjob.js.map +1 -0
- package/dist/cjs/endowments/enum.js +26 -0
- package/dist/cjs/endowments/enum.js.map +1 -0
- package/dist/cjs/endowments/ethereum-provider.js +43 -0
- package/dist/cjs/endowments/ethereum-provider.js.map +1 -0
- package/dist/cjs/endowments/home-page.js +37 -0
- package/dist/cjs/endowments/home-page.js.map +1 -0
- package/dist/cjs/endowments/index.js +121 -0
- package/dist/cjs/endowments/index.js.map +1 -0
- package/dist/cjs/endowments/keyring.js +104 -0
- package/dist/cjs/endowments/keyring.js.map +1 -0
- package/dist/cjs/endowments/lifecycle-hooks.js +37 -0
- package/dist/cjs/endowments/lifecycle-hooks.js.map +1 -0
- package/dist/cjs/endowments/name-lookup.js +148 -0
- package/dist/cjs/endowments/name-lookup.js.map +1 -0
- package/dist/cjs/endowments/network-access.js +44 -0
- package/dist/cjs/endowments/network-access.js.map +1 -0
- package/dist/cjs/endowments/rpc.js +103 -0
- package/dist/cjs/endowments/rpc.js.map +1 -0
- package/dist/cjs/endowments/signature-insight.js +110 -0
- package/dist/cjs/endowments/signature-insight.js.map +1 -0
- package/dist/cjs/endowments/transaction-insight.js +111 -0
- package/dist/cjs/endowments/transaction-insight.js.map +1 -0
- package/dist/cjs/endowments/web-assembly.js +42 -0
- package/dist/cjs/endowments/web-assembly.js.map +1 -0
- package/dist/cjs/index.js +3 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/permissions.js +62 -0
- package/dist/cjs/permissions.js.map +1 -0
- package/dist/cjs/permitted/createInterface.js +68 -0
- package/dist/cjs/permitted/createInterface.js.map +1 -0
- package/dist/cjs/permitted/getFile.js +1 -1
- package/dist/cjs/permitted/getFile.js.map +1 -1
- package/dist/cjs/permitted/getInterfaceState.js +67 -0
- package/dist/cjs/permitted/getInterfaceState.js.map +1 -0
- package/dist/cjs/permitted/handlers.js +7 -1
- package/dist/cjs/permitted/handlers.js.map +1 -1
- package/dist/cjs/permitted/index.js.map +1 -1
- package/dist/cjs/permitted/updateInterface.js +70 -0
- package/dist/cjs/permitted/updateInterface.js.map +1 -0
- package/dist/cjs/restricted/dialog.js +51 -24
- package/dist/cjs/restricted/dialog.js.map +1 -1
- package/dist/esm/endowments/caveats/generic.js +40 -0
- package/dist/esm/endowments/caveats/generic.js.map +1 -0
- package/dist/esm/endowments/caveats/index.js +4 -0
- package/dist/esm/endowments/caveats/index.js.map +1 -0
- package/dist/esm/endowments/caveats/requestTime.js +93 -0
- package/dist/esm/endowments/caveats/requestTime.js.map +1 -0
- package/dist/esm/endowments/cronjob.js +99 -0
- package/dist/esm/endowments/cronjob.js.map +1 -0
- package/dist/esm/endowments/enum.js +16 -0
- package/dist/esm/endowments/enum.js.map +1 -0
- package/dist/esm/endowments/ethereum-provider.js +33 -0
- package/dist/esm/endowments/ethereum-provider.js.map +1 -0
- package/dist/esm/endowments/home-page.js +27 -0
- package/dist/esm/endowments/home-page.js.map +1 -0
- package/dist/esm/endowments/index.js +68 -0
- package/dist/esm/endowments/index.js.map +1 -0
- package/dist/esm/endowments/keyring.js +95 -0
- package/dist/esm/endowments/keyring.js.map +1 -0
- package/dist/esm/endowments/lifecycle-hooks.js +27 -0
- package/dist/esm/endowments/lifecycle-hooks.js.map +1 -0
- package/dist/esm/endowments/name-lookup.js +146 -0
- package/dist/esm/endowments/name-lookup.js.map +1 -0
- package/dist/esm/endowments/network-access.js +34 -0
- package/dist/esm/endowments/network-access.js.map +1 -0
- package/dist/esm/endowments/rpc.js +92 -0
- package/dist/esm/endowments/rpc.js.map +1 -0
- package/dist/esm/endowments/signature-insight.js +103 -0
- package/dist/esm/endowments/signature-insight.js.map +1 -0
- package/dist/esm/endowments/transaction-insight.js +104 -0
- package/dist/esm/endowments/transaction-insight.js.map +1 -0
- package/dist/esm/endowments/web-assembly.js +32 -0
- package/dist/esm/endowments/web-assembly.js.map +1 -0
- package/dist/esm/index.js +3 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/permissions.js +51 -0
- package/dist/esm/permissions.js.map +1 -0
- package/dist/esm/permitted/createInterface.js +58 -0
- package/dist/esm/permitted/createInterface.js.map +1 -0
- package/dist/esm/permitted/getFile.js +1 -1
- package/dist/esm/permitted/getFile.js.map +1 -1
- package/dist/esm/permitted/getInterfaceState.js +57 -0
- package/dist/esm/permitted/getInterfaceState.js.map +1 -0
- package/dist/esm/permitted/handlers.js +7 -1
- package/dist/esm/permitted/handlers.js.map +1 -1
- package/dist/esm/permitted/index.js.map +1 -1
- package/dist/esm/permitted/updateInterface.js +60 -0
- package/dist/esm/permitted/updateInterface.js.map +1 -0
- package/dist/esm/restricted/dialog.js +55 -29
- package/dist/esm/restricted/dialog.js.map +1 -1
- package/dist/types/endowments/caveats/generic.d.ts +19 -0
- package/dist/types/endowments/caveats/index.d.ts +2 -0
- package/dist/types/endowments/caveats/requestTime.d.ts +29 -0
- package/dist/types/endowments/cronjob.d.ts +51 -0
- package/dist/types/endowments/enum.d.ts +13 -0
- package/dist/types/endowments/ethereum-provider.d.ts +14 -0
- package/dist/types/endowments/home-page.d.ts +15 -0
- package/dist/types/endowments/index.d.ts +131 -0
- package/dist/types/endowments/keyring.d.ts +39 -0
- package/dist/types/endowments/lifecycle-hooks.d.ts +15 -0
- package/dist/types/endowments/name-lookup.d.ts +49 -0
- package/dist/types/endowments/network-access.d.ts +14 -0
- package/dist/types/endowments/rpc.d.ts +38 -0
- package/dist/types/endowments/signature-insight.d.ts +39 -0
- package/dist/types/endowments/transaction-insight.d.ts +39 -0
- package/dist/types/endowments/web-assembly.d.ts +14 -0
- package/dist/types/index.d.ts +4 -2
- package/dist/types/permissions.d.ts +16 -0
- package/dist/types/permitted/createInterface.d.ts +150 -0
- package/dist/types/permitted/getInterfaceState.d.ts +18 -0
- package/dist/types/permitted/handlers.d.ts +4 -1
- package/dist/types/permitted/index.d.ts +4 -1
- package/dist/types/permitted/updateInterface.d.ts +152 -0
- package/dist/types/restricted/dialog.d.ts +776 -14
- package/package.json +5 -5
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { rpcErrors } from '@metamask/rpc-errors';
|
|
2
|
+
import { ComponentStruct } from '@metamask/snaps-sdk';
|
|
3
|
+
import { StructError, create, object, string } from 'superstruct';
|
|
4
|
+
const hookNames = {
|
|
5
|
+
updateInterface: true
|
|
6
|
+
};
|
|
7
|
+
export const updateInterfaceHandler = {
|
|
8
|
+
methodNames: [
|
|
9
|
+
'snap_updateInterface'
|
|
10
|
+
],
|
|
11
|
+
implementation: getUpdateInterfaceImplementation,
|
|
12
|
+
hookNames
|
|
13
|
+
};
|
|
14
|
+
const UpdateInterfaceParametersStruct = object({
|
|
15
|
+
id: string(),
|
|
16
|
+
ui: ComponentStruct
|
|
17
|
+
});
|
|
18
|
+
/**
|
|
19
|
+
* The `snap_updateInterface` method implementation.
|
|
20
|
+
*
|
|
21
|
+
* @param req - The JSON-RPC request object.
|
|
22
|
+
* @param res - The JSON-RPC response object.
|
|
23
|
+
* @param _next - The `json-rpc-engine` "next" callback. Not used by this
|
|
24
|
+
* function.
|
|
25
|
+
* @param end - The `json-rpc-engine` "end" callback.
|
|
26
|
+
* @param hooks - The RPC method hooks.
|
|
27
|
+
* @param hooks.updateInterface - The function to update the interface.
|
|
28
|
+
* @returns Nothing.
|
|
29
|
+
*/ async function getUpdateInterfaceImplementation(req, res, _next, end, { updateInterface }) {
|
|
30
|
+
const { params } = req;
|
|
31
|
+
try {
|
|
32
|
+
const validatedParams = getValidatedParams(params);
|
|
33
|
+
const { id, ui } = validatedParams;
|
|
34
|
+
await updateInterface(id, ui);
|
|
35
|
+
res.result = null;
|
|
36
|
+
} catch (error) {
|
|
37
|
+
return end(error);
|
|
38
|
+
}
|
|
39
|
+
return end();
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Validate the updateInterface method `params` and returns them cast to the correct
|
|
43
|
+
* type. Throws if validation fails.
|
|
44
|
+
*
|
|
45
|
+
* @param params - The unvalidated params object from the method request.
|
|
46
|
+
* @returns The validated updateInterface method parameter object.
|
|
47
|
+
*/ function getValidatedParams(params) {
|
|
48
|
+
try {
|
|
49
|
+
return create(params, UpdateInterfaceParametersStruct);
|
|
50
|
+
} catch (error) {
|
|
51
|
+
if (error instanceof StructError) {
|
|
52
|
+
throw rpcErrors.invalidParams({
|
|
53
|
+
message: `Invalid params: ${error.message}.`
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
/* istanbul ignore next */ throw rpcErrors.internal();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
//# sourceMappingURL=updateInterface.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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 Component,\n UpdateInterfaceParams,\n UpdateInterfaceResult,\n JsonRpcRequest,\n} from '@metamask/snaps-sdk';\nimport { ComponentStruct } 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: Component) => 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: ComponentStruct,\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"],"names":["rpcErrors","ComponentStruct","StructError","create","object","string","hookNames","updateInterface","updateInterfaceHandler","methodNames","implementation","getUpdateInterfaceImplementation","UpdateInterfaceParametersStruct","id","ui","req","res","_next","end","params","validatedParams","getValidatedParams","result","error","invalidParams","message","internal"],"mappings":"AAEA,SAASA,SAAS,QAAQ,uBAAuB;AAOjD,SAASC,eAAe,QAAQ,sBAAsB;AAGtD,SAASC,WAAW,EAAEC,MAAM,EAAEC,MAAM,EAAEC,MAAM,QAAQ,cAAc;AAIlE,MAAMC,YAA2D;IAC/DC,iBAAiB;AACnB;AAUA,OAAO,MAAMC,yBAIT;IACFC,aAAa;QAAC;KAAuB;IACrCC,gBAAgBC;IAChBL;AACF,EAAE;AAEF,MAAMM,kCAAkCR,OAAO;IAC7CS,IAAIR;IACJS,IAAIb;AACN;AAOA;;;;;;;;;;;CAWC,GACD,eAAeU,iCACbI,GAA8C,EAC9CC,GAAkD,EAClDC,KAAc,EACdC,GAA6B,EAC7B,EAAEX,eAAe,EAA8B;IAE/C,MAAM,EAAEY,MAAM,EAAE,GAAGJ;IAEnB,IAAI;QACF,MAAMK,kBAAkBC,mBAAmBF;QAE3C,MAAM,EAAEN,EAAE,EAAEC,EAAE,EAAE,GAAGM;QAEnB,MAAMb,gBAAgBM,IAAIC;QAC1BE,IAAIM,MAAM,GAAG;IACf,EAAE,OAAOC,OAAO;QACd,OAAOL,IAAIK;IACb;IAEA,OAAOL;AACT;AAEA;;;;;;CAMC,GACD,SAASG,mBAAmBF,MAAe;IACzC,IAAI;QACF,OAAOhB,OAAOgB,QAAQP;IACxB,EAAE,OAAOW,OAAO;QACd,IAAIA,iBAAiBrB,aAAa;YAChC,MAAMF,UAAUwB,aAAa,CAAC;gBAC5BC,SAAS,CAAC,gBAAgB,EAAEF,MAAME,OAAO,CAAC,CAAC,CAAC;YAC9C;QACF;QACA,wBAAwB,GACxB,MAAMzB,UAAU0B,QAAQ;IAC1B;AACF"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { PermissionType, SubjectType } from '@metamask/permission-controller';
|
|
2
2
|
import { rpcErrors } from '@metamask/rpc-errors';
|
|
3
|
-
import { DialogType, ComponentStruct, enumValue } from '@metamask/snaps-sdk';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
3
|
+
import { DialogType, ComponentStruct, enumValue, union } from '@metamask/snaps-sdk';
|
|
4
|
+
import { createUnion } from '@metamask/snaps-utils';
|
|
5
|
+
import { hasProperty } from '@metamask/utils';
|
|
6
|
+
import { create, enums, object, optional, size, string, type } from 'superstruct';
|
|
6
7
|
const methodName = 'snap_dialog';
|
|
7
8
|
const PlaceholderStruct = optional(size(string(), 1, 40));
|
|
8
9
|
/**
|
|
@@ -31,8 +32,8 @@ const PlaceholderStruct = optional(size(string(), 1, 40));
|
|
|
31
32
|
};
|
|
32
33
|
const methodHooks = {
|
|
33
34
|
showDialog: true,
|
|
34
|
-
|
|
35
|
-
|
|
35
|
+
createInterface: true,
|
|
36
|
+
getInterface: true
|
|
36
37
|
};
|
|
37
38
|
export const dialogBuilder = Object.freeze({
|
|
38
39
|
targetName: methodName,
|
|
@@ -48,19 +49,44 @@ const BaseParamsStruct = type({
|
|
|
48
49
|
DialogType.Prompt
|
|
49
50
|
])
|
|
50
51
|
});
|
|
51
|
-
const
|
|
52
|
+
const AlertParametersWithContentStruct = object({
|
|
52
53
|
type: enumValue(DialogType.Alert),
|
|
53
54
|
content: ComponentStruct
|
|
54
55
|
});
|
|
55
|
-
const
|
|
56
|
+
const AlertParametersWithIdStruct = object({
|
|
57
|
+
type: enumValue(DialogType.Alert),
|
|
58
|
+
id: string()
|
|
59
|
+
});
|
|
60
|
+
const AlertParametersStruct = union([
|
|
61
|
+
AlertParametersWithContentStruct,
|
|
62
|
+
AlertParametersWithIdStruct
|
|
63
|
+
]);
|
|
64
|
+
const ConfirmationParametersWithContentStruct = object({
|
|
56
65
|
type: enumValue(DialogType.Confirmation),
|
|
57
66
|
content: ComponentStruct
|
|
58
67
|
});
|
|
59
|
-
const
|
|
68
|
+
const ConfirmationParametersWithIdStruct = object({
|
|
69
|
+
type: enumValue(DialogType.Confirmation),
|
|
70
|
+
id: string()
|
|
71
|
+
});
|
|
72
|
+
const ConfirmationParametersStruct = union([
|
|
73
|
+
ConfirmationParametersWithContentStruct,
|
|
74
|
+
ConfirmationParametersWithIdStruct
|
|
75
|
+
]);
|
|
76
|
+
const PromptParametersWithContentStruct = object({
|
|
60
77
|
type: enumValue(DialogType.Prompt),
|
|
61
78
|
content: ComponentStruct,
|
|
62
79
|
placeholder: PlaceholderStruct
|
|
63
80
|
});
|
|
81
|
+
const PromptParametersWithIdStruct = object({
|
|
82
|
+
type: enumValue(DialogType.Prompt),
|
|
83
|
+
id: string(),
|
|
84
|
+
placeholder: PlaceholderStruct
|
|
85
|
+
});
|
|
86
|
+
const PromptParametersStruct = union([
|
|
87
|
+
PromptParametersWithContentStruct,
|
|
88
|
+
PromptParametersWithIdStruct
|
|
89
|
+
]);
|
|
64
90
|
const DialogParametersStruct = union([
|
|
65
91
|
AlertParametersStruct,
|
|
66
92
|
ConfirmationParametersStruct,
|
|
@@ -77,21 +103,30 @@ const structs = {
|
|
|
77
103
|
* @param hooks - The RPC method hooks.
|
|
78
104
|
* @param hooks.showDialog - A function that shows the specified dialog in the
|
|
79
105
|
* MetaMask UI and returns the appropriate value for the dialog type.
|
|
80
|
-
* @param hooks.
|
|
81
|
-
*
|
|
82
|
-
* @param hooks.maybeUpdatePhishingList - A function that updates the phishing list if needed.
|
|
106
|
+
* @param hooks.createInterface - A function that creates the interface in SnapInterfaceController.
|
|
107
|
+
* @param hooks.getInterface - A function that gets an interface from SnapInterfaceController.
|
|
83
108
|
* @returns The method implementation which return value depends on the dialog
|
|
84
109
|
* type, valid return types are: string, boolean, null.
|
|
85
|
-
*/ export function getDialogImplementation({ showDialog,
|
|
110
|
+
*/ export function getDialogImplementation({ showDialog, createInterface, getInterface }) {
|
|
86
111
|
return async function dialogImplementation(args) {
|
|
87
112
|
const { params, context: { origin } } = args;
|
|
88
113
|
const validatedType = getValidatedType(params);
|
|
89
114
|
const validatedParams = getValidatedParams(params, structs[validatedType]);
|
|
90
|
-
const { content } = validatedParams;
|
|
91
|
-
await maybeUpdatePhishingList();
|
|
92
|
-
validateComponentLinks(content, isOnPhishingList);
|
|
93
115
|
const placeholder = validatedParams.type === DialogType.Prompt ? validatedParams.placeholder : undefined;
|
|
94
|
-
|
|
116
|
+
if (hasProperty(validatedParams, 'content')) {
|
|
117
|
+
const id = await createInterface(origin, validatedParams.content);
|
|
118
|
+
return showDialog(origin, validatedType, id, placeholder);
|
|
119
|
+
}
|
|
120
|
+
// Verify that the passed interface ID is valid.
|
|
121
|
+
// This will throw if the interface ID is invalid (not created by the snap or doesn't exist)
|
|
122
|
+
try {
|
|
123
|
+
getInterface(origin, validatedParams.id);
|
|
124
|
+
} catch (error) {
|
|
125
|
+
throw rpcErrors.invalidParams({
|
|
126
|
+
message: `Invalid params: ${error.message}`
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
return showDialog(origin, validatedType, validatedParams.id, placeholder);
|
|
95
130
|
};
|
|
96
131
|
}
|
|
97
132
|
/**
|
|
@@ -118,20 +153,11 @@ const structs = {
|
|
|
118
153
|
* @returns The validated confirm method parameter object.
|
|
119
154
|
*/ function getValidatedParams(params, struct) {
|
|
120
155
|
try {
|
|
121
|
-
return
|
|
156
|
+
return createUnion(params, struct, 'type');
|
|
122
157
|
} catch (error) {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
throw rpcErrors.invalidParams({
|
|
127
|
-
message: 'Invalid params: Alerts or confirmations may not specify a "placeholder" field.'
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
throw rpcErrors.invalidParams({
|
|
131
|
-
message: `Invalid params: ${error.message}.`
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
/* istanbul ignore next */ throw rpcErrors.internal();
|
|
158
|
+
throw rpcErrors.invalidParams({
|
|
159
|
+
message: `Invalid params: ${error.message}`
|
|
160
|
+
});
|
|
135
161
|
}
|
|
136
162
|
}
|
|
137
163
|
|
|
@@ -1 +1 @@
|
|
|
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 { DialogType, ComponentStruct, enumValue } from '@metamask/snaps-sdk';\nimport type { DialogParams, EnumToUnion, Component } from '@metamask/snaps-sdk';\nimport { validateComponentLinks } from '@metamask/snaps-utils';\nimport type { InferMatching } from '@metamask/snaps-utils';\nimport 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 StructError,\n type,\n union,\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 content: Component,\n placeholder?: Placeholder,\n) => Promise<null | boolean | string>;\n\ntype MaybeUpdatePhisingList = () => Promise<void>;\ntype IsOnPhishingList = (url: string) => boolean;\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 content - The dialog custom UI.\n * @param placeholder - The placeholder for the Prompt dialog input.\n */\n showDialog: ShowDialog;\n\n maybeUpdatePhishingList: MaybeUpdatePhisingList;\n\n /**\n * @param url - The URL to check against the phishing list.\n */\n isOnPhishingList: IsOnPhishingList;\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 isOnPhishingList: true,\n maybeUpdatePhishingList: 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 AlertParametersStruct = object({\n type: enumValue(DialogType.Alert),\n content: ComponentStruct,\n});\n\nconst ConfirmationParametersStruct = object({\n type: enumValue(DialogType.Confirmation),\n content: ComponentStruct,\n});\n\nconst PromptParametersStruct = object({\n type: enumValue(DialogType.Prompt),\n content: ComponentStruct,\n placeholder: PlaceholderStruct,\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.isOnPhishingList - A function that checks a link against the\n * phishing list and return true if it's in, otherwise false.\n * @param hooks.maybeUpdatePhishingList - A function that updates the phishing list if needed.\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 isOnPhishingList,\n maybeUpdatePhishingList,\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 { content } = validatedParams;\n\n await maybeUpdatePhishingList();\n\n validateComponentLinks(content, isOnPhishingList);\n\n const placeholder =\n validatedParams.type === DialogType.Prompt\n ? validatedParams.placeholder\n : undefined;\n\n return showDialog(origin, validatedType, content, 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>,\n): DialogParameters {\n try {\n return create(params, struct);\n } catch (error) {\n if (error instanceof StructError) {\n const { key, type: errorType } = error;\n\n if (key === 'placeholder' && errorType === 'never') {\n throw rpcErrors.invalidParams({\n message:\n 'Invalid params: Alerts or confirmations may not specify a \"placeholder\" field.',\n });\n }\n\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${error.message}.`,\n });\n }\n\n /* istanbul ignore next */\n throw rpcErrors.internal();\n }\n}\n"],"names":["PermissionType","SubjectType","rpcErrors","DialogType","ComponentStruct","enumValue","validateComponentLinks","create","enums","object","optional","size","string","StructError","type","union","methodName","PlaceholderStruct","specificationBuilder","allowedCaveats","methodHooks","permissionType","RestrictedMethod","targetName","methodImplementation","getDialogImplementation","subjectTypes","Snap","showDialog","isOnPhishingList","maybeUpdatePhishingList","dialogBuilder","Object","freeze","BaseParamsStruct","Alert","Confirmation","Prompt","AlertParametersStruct","content","ConfirmationParametersStruct","PromptParametersStruct","placeholder","DialogParametersStruct","structs","dialogImplementation","args","params","context","origin","validatedType","getValidatedType","validatedParams","getValidatedParams","undefined","error","invalidParams","message","values","join","struct","key","errorType","internal"],"mappings":"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"}
|
|
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 ComponentStruct,\n enumValue,\n union,\n} from '@metamask/snaps-sdk';\nimport type {\n DialogParams,\n EnumToUnion,\n Component,\n InterfaceState,\n SnapId,\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 = (snapId: string, content: Component) => Promise<string>;\ntype GetInterface = (\n snapId: string,\n id: string,\n) => { content: Component; 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: ComponentStruct,\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: ComponentStruct,\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: ComponentStruct,\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"],"names":["PermissionType","SubjectType","rpcErrors","DialogType","ComponentStruct","enumValue","union","createUnion","hasProperty","create","enums","object","optional","size","string","type","methodName","PlaceholderStruct","specificationBuilder","allowedCaveats","methodHooks","permissionType","RestrictedMethod","targetName","methodImplementation","getDialogImplementation","subjectTypes","Snap","showDialog","createInterface","getInterface","dialogBuilder","Object","freeze","BaseParamsStruct","Alert","Confirmation","Prompt","AlertParametersWithContentStruct","content","AlertParametersWithIdStruct","id","AlertParametersStruct","ConfirmationParametersWithContentStruct","ConfirmationParametersWithIdStruct","ConfirmationParametersStruct","PromptParametersWithContentStruct","placeholder","PromptParametersWithIdStruct","PromptParametersStruct","DialogParametersStruct","structs","dialogImplementation","args","params","context","origin","validatedType","getValidatedType","validatedParams","getValidatedParams","undefined","error","invalidParams","message","values","join","struct"],"mappings":"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"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { PermissionConstraint, PermissionValidatorConstraint } from '@metamask/permission-controller';
|
|
2
|
+
import type { Json } from '@metamask/utils';
|
|
3
|
+
export declare type CaveatMapperReturnValue = Pick<PermissionConstraint, 'caveats'>;
|
|
4
|
+
export declare type CaveatMapperFunction = (value: Json) => CaveatMapperReturnValue;
|
|
5
|
+
/**
|
|
6
|
+
* Create a generic permission validator that validates the presence of certain caveats.
|
|
7
|
+
*
|
|
8
|
+
* This validator only validates the types of the caveats, not the values.
|
|
9
|
+
*
|
|
10
|
+
* @param caveatsToValidate - A list of objects that represent caveats.
|
|
11
|
+
* @param caveatsToValidate.type - The string defining the caveat type.
|
|
12
|
+
* @param caveatsToValidate.optional - An optional boolean flag that defines
|
|
13
|
+
* whether the caveat is optional or not.
|
|
14
|
+
* @returns A function that validates a permission.
|
|
15
|
+
*/
|
|
16
|
+
export declare function createGenericPermissionValidator(caveatsToValidate: {
|
|
17
|
+
type: string;
|
|
18
|
+
optional?: boolean;
|
|
19
|
+
}[]): PermissionValidatorConstraint;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { CaveatSpecificationConstraint, PermissionConstraint } from '@metamask/permission-controller';
|
|
2
|
+
import { SnapCaveatType } from '@metamask/snaps-utils';
|
|
3
|
+
import type { Json } from '@metamask/utils';
|
|
4
|
+
import type { CaveatMapperFunction, CaveatMapperReturnValue } from './generic';
|
|
5
|
+
/**
|
|
6
|
+
* Map a raw value from the `initialPermissions` to a caveat specification.
|
|
7
|
+
* Note that this function does not do any validation, that's handled by the
|
|
8
|
+
* PermissionsController when the permission is requested.
|
|
9
|
+
*
|
|
10
|
+
* @param value - The raw value from the `initialPermissions`.
|
|
11
|
+
* @returns The caveat specification.
|
|
12
|
+
*/
|
|
13
|
+
export declare function getMaxRequestTimeCaveatMapper(value: Json): CaveatMapperReturnValue;
|
|
14
|
+
/**
|
|
15
|
+
* Creates a wrapping caveat mapper that creates the `maxRequestTime` caveat
|
|
16
|
+
* and merges it with any other caveats created by the mapper function.
|
|
17
|
+
*
|
|
18
|
+
* @param mapper - Another caveat mapper function.
|
|
19
|
+
* @returns The caveat specification.
|
|
20
|
+
*/
|
|
21
|
+
export declare function createMaxRequestTimeMapper(mapper: CaveatMapperFunction): CaveatMapperFunction;
|
|
22
|
+
/**
|
|
23
|
+
* Getter function to get the {@link MaxRequestTime} caveat value from a permission if specified.
|
|
24
|
+
*
|
|
25
|
+
* @param permission - The permission to get the caveat value from.
|
|
26
|
+
* @returns The caveat value if present, otherwise null.
|
|
27
|
+
*/
|
|
28
|
+
export declare function getMaxRequestTimeCaveat(permission?: PermissionConstraint): number | null;
|
|
29
|
+
export declare const maxRequestTimeCaveatSpecifications: Record<SnapCaveatType.MaxRequestTime, CaveatSpecificationConstraint>;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { PermissionSpecificationBuilder, PermissionConstraint, Caveat, CaveatSpecificationConstraint } from '@metamask/permission-controller';
|
|
2
|
+
import { PermissionType } from '@metamask/permission-controller';
|
|
3
|
+
import type { CronjobSpecification } from '@metamask/snaps-utils';
|
|
4
|
+
import { SnapCaveatType } from '@metamask/snaps-utils';
|
|
5
|
+
import type { Json, NonEmptyArray } from '@metamask/utils';
|
|
6
|
+
import { SnapEndowments } from './enum';
|
|
7
|
+
declare const permissionName = SnapEndowments.Cronjob;
|
|
8
|
+
export declare const cronjobEndowmentBuilder: Readonly<{
|
|
9
|
+
readonly targetName: SnapEndowments.Cronjob;
|
|
10
|
+
readonly specificationBuilder: PermissionSpecificationBuilder<PermissionType.Endowment, any, {
|
|
11
|
+
permissionType: PermissionType.Endowment;
|
|
12
|
+
targetName: typeof permissionName;
|
|
13
|
+
endowmentGetter: (_options?: any) => undefined;
|
|
14
|
+
allowedCaveats: Readonly<NonEmptyArray<string>> | null;
|
|
15
|
+
}>;
|
|
16
|
+
}>;
|
|
17
|
+
/**
|
|
18
|
+
* Map a raw value from the `initialPermissions` to a caveat specification.
|
|
19
|
+
* Note that this function does not do any validation, that's handled by the
|
|
20
|
+
* PermissionsController when the permission is requested.
|
|
21
|
+
*
|
|
22
|
+
* @param value - The raw value from the `initialPermissions`.
|
|
23
|
+
* @returns The caveat specification.
|
|
24
|
+
*/
|
|
25
|
+
export declare function getCronjobCaveatMapper(value: Json): Pick<PermissionConstraint, 'caveats'>;
|
|
26
|
+
/**
|
|
27
|
+
* Getter function to get the cronjobs from a permission.
|
|
28
|
+
*
|
|
29
|
+
* This does basic validation of the caveat, but does not validate the type or
|
|
30
|
+
* value of the namespaces object itself, as this is handled by the
|
|
31
|
+
* `PermissionsController` when the permission is requested.
|
|
32
|
+
*
|
|
33
|
+
* @param permission - The permission to get the keyring namespaces from.
|
|
34
|
+
* @returns The cronjobs, or `null` if the permission does not have a
|
|
35
|
+
* cronjob caveat.
|
|
36
|
+
*/
|
|
37
|
+
export declare function getCronjobCaveatJobs(permission?: PermissionConstraint): CronjobSpecification[] | null;
|
|
38
|
+
/**
|
|
39
|
+
* Validate the cronjob specification values associated with a caveat.
|
|
40
|
+
* This validates that the value is a non-empty array with valid
|
|
41
|
+
* cronjob expression and request object.
|
|
42
|
+
*
|
|
43
|
+
* @param caveat - The caveat to validate.
|
|
44
|
+
* @throws If the value is invalid.
|
|
45
|
+
*/
|
|
46
|
+
export declare function validateCronjobCaveat(caveat: Caveat<string, any>): void;
|
|
47
|
+
/**
|
|
48
|
+
* Caveat specification for the Cronjob.
|
|
49
|
+
*/
|
|
50
|
+
export declare const cronjobCaveatSpecifications: Record<SnapCaveatType.SnapCronjob, CaveatSpecificationConstraint>;
|
|
51
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare enum SnapEndowments {
|
|
2
|
+
NetworkAccess = "endowment:network-access",
|
|
3
|
+
SignatureInsight = "endowment:signature-insight",
|
|
4
|
+
TransactionInsight = "endowment:transaction-insight",
|
|
5
|
+
Cronjob = "endowment:cronjob",
|
|
6
|
+
EthereumProvider = "endowment:ethereum-provider",
|
|
7
|
+
Rpc = "endowment:rpc",
|
|
8
|
+
WebAssemblyAccess = "endowment:webassembly",
|
|
9
|
+
NameLookup = "endowment:name-lookup",
|
|
10
|
+
LifecycleHooks = "endowment:lifecycle-hooks",
|
|
11
|
+
Keyring = "endowment:keyring",
|
|
12
|
+
HomePage = "endowment:page-home"
|
|
13
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { PermissionSpecificationBuilder } from '@metamask/permission-controller';
|
|
2
|
+
import { PermissionType } from '@metamask/permission-controller';
|
|
3
|
+
import { SnapEndowments } from './enum';
|
|
4
|
+
declare const permissionName = SnapEndowments.EthereumProvider;
|
|
5
|
+
export declare const ethereumProviderEndowmentBuilder: Readonly<{
|
|
6
|
+
readonly targetName: SnapEndowments.EthereumProvider;
|
|
7
|
+
readonly specificationBuilder: PermissionSpecificationBuilder<PermissionType.Endowment, any, {
|
|
8
|
+
permissionType: PermissionType.Endowment;
|
|
9
|
+
targetName: typeof permissionName;
|
|
10
|
+
endowmentGetter: (_options?: any) => ['ethereum'];
|
|
11
|
+
allowedCaveats: null;
|
|
12
|
+
}>;
|
|
13
|
+
}>;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { PermissionSpecificationBuilder, EndowmentGetterParams } from '@metamask/permission-controller';
|
|
2
|
+
import { PermissionType } from '@metamask/permission-controller';
|
|
3
|
+
import type { NonEmptyArray } from '@metamask/utils';
|
|
4
|
+
import { SnapEndowments } from './enum';
|
|
5
|
+
declare const permissionName = SnapEndowments.HomePage;
|
|
6
|
+
export declare const homePageEndowmentBuilder: Readonly<{
|
|
7
|
+
readonly targetName: SnapEndowments.HomePage;
|
|
8
|
+
readonly specificationBuilder: PermissionSpecificationBuilder<PermissionType.Endowment, any, {
|
|
9
|
+
permissionType: PermissionType.Endowment;
|
|
10
|
+
targetName: typeof permissionName;
|
|
11
|
+
endowmentGetter: (_options?: EndowmentGetterParams) => undefined;
|
|
12
|
+
allowedCaveats: Readonly<NonEmptyArray<string>> | null;
|
|
13
|
+
}>;
|
|
14
|
+
}>;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import type { PermissionConstraint } from '@metamask/permission-controller';
|
|
2
|
+
import { HandlerType } from '@metamask/snaps-utils';
|
|
3
|
+
import type { Json } from '@metamask/utils';
|
|
4
|
+
export declare const endowmentPermissionBuilders: {
|
|
5
|
+
readonly "endowment:network-access": Readonly<{
|
|
6
|
+
readonly targetName: import("./enum").SnapEndowments.NetworkAccess;
|
|
7
|
+
readonly specificationBuilder: import("@metamask/permission-controller").PermissionSpecificationBuilder<import("@metamask/permission-controller").PermissionType.Endowment, any, {
|
|
8
|
+
permissionType: import("@metamask/permission-controller").PermissionType.Endowment;
|
|
9
|
+
targetName: import("./enum").SnapEndowments.NetworkAccess;
|
|
10
|
+
endowmentGetter: (_options?: any) => ["fetch", "Request", "Headers", "Response"];
|
|
11
|
+
allowedCaveats: null;
|
|
12
|
+
}>;
|
|
13
|
+
}>;
|
|
14
|
+
readonly "endowment:transaction-insight": Readonly<{
|
|
15
|
+
readonly targetName: import("./enum").SnapEndowments.TransactionInsight;
|
|
16
|
+
readonly specificationBuilder: import("@metamask/permission-controller").PermissionSpecificationBuilder<import("@metamask/permission-controller").PermissionType.Endowment, any, {
|
|
17
|
+
permissionType: import("@metamask/permission-controller").PermissionType.Endowment;
|
|
18
|
+
targetName: import("./enum").SnapEndowments.TransactionInsight;
|
|
19
|
+
endowmentGetter: (_options?: import("@metamask/permission-controller").EndowmentGetterParams | undefined) => undefined;
|
|
20
|
+
allowedCaveats: readonly [string, ...string[]] | null;
|
|
21
|
+
validator: import("@metamask/permission-controller").PermissionValidatorConstraint;
|
|
22
|
+
}>;
|
|
23
|
+
}>;
|
|
24
|
+
readonly "endowment:cronjob": Readonly<{
|
|
25
|
+
readonly targetName: import("./enum").SnapEndowments.Cronjob;
|
|
26
|
+
readonly specificationBuilder: import("@metamask/permission-controller").PermissionSpecificationBuilder<import("@metamask/permission-controller").PermissionType.Endowment, any, {
|
|
27
|
+
permissionType: import("@metamask/permission-controller").PermissionType.Endowment;
|
|
28
|
+
targetName: import("./enum").SnapEndowments.Cronjob;
|
|
29
|
+
endowmentGetter: (_options?: any) => undefined;
|
|
30
|
+
allowedCaveats: readonly [string, ...string[]] | null;
|
|
31
|
+
}>;
|
|
32
|
+
}>;
|
|
33
|
+
readonly "endowment:ethereum-provider": Readonly<{
|
|
34
|
+
readonly targetName: import("./enum").SnapEndowments.EthereumProvider;
|
|
35
|
+
readonly specificationBuilder: import("@metamask/permission-controller").PermissionSpecificationBuilder<import("@metamask/permission-controller").PermissionType.Endowment, any, {
|
|
36
|
+
permissionType: import("@metamask/permission-controller").PermissionType.Endowment;
|
|
37
|
+
targetName: import("./enum").SnapEndowments.EthereumProvider;
|
|
38
|
+
endowmentGetter: (_options?: any) => ["ethereum"];
|
|
39
|
+
allowedCaveats: null;
|
|
40
|
+
}>;
|
|
41
|
+
}>;
|
|
42
|
+
readonly "endowment:rpc": Readonly<{
|
|
43
|
+
readonly targetName: import("./enum").SnapEndowments.Rpc;
|
|
44
|
+
readonly specificationBuilder: import("@metamask/permission-controller").PermissionSpecificationBuilder<import("@metamask/permission-controller").PermissionType.Endowment, {}, {
|
|
45
|
+
permissionType: import("@metamask/permission-controller").PermissionType.Endowment;
|
|
46
|
+
targetName: import("./enum").SnapEndowments.Rpc;
|
|
47
|
+
endowmentGetter: (_options?: any) => undefined;
|
|
48
|
+
allowedCaveats: readonly [string, ...string[]] | null;
|
|
49
|
+
validator: import("@metamask/permission-controller").PermissionValidatorConstraint;
|
|
50
|
+
subjectTypes: readonly import("@metamask/permission-controller").SubjectType[];
|
|
51
|
+
}>;
|
|
52
|
+
}>;
|
|
53
|
+
readonly "endowment:webassembly": Readonly<{
|
|
54
|
+
readonly targetName: import("./enum").SnapEndowments.WebAssemblyAccess;
|
|
55
|
+
readonly specificationBuilder: import("@metamask/permission-controller").PermissionSpecificationBuilder<import("@metamask/permission-controller").PermissionType.Endowment, any, {
|
|
56
|
+
permissionType: import("@metamask/permission-controller").PermissionType.Endowment;
|
|
57
|
+
targetName: import("./enum").SnapEndowments.WebAssemblyAccess;
|
|
58
|
+
endowmentGetter: (_options?: any) => ["WebAssembly"];
|
|
59
|
+
allowedCaveats: null;
|
|
60
|
+
}>;
|
|
61
|
+
}>;
|
|
62
|
+
readonly "endowment:name-lookup": Readonly<{
|
|
63
|
+
readonly targetName: import("./enum").SnapEndowments.NameLookup;
|
|
64
|
+
readonly specificationBuilder: import("@metamask/permission-controller").PermissionSpecificationBuilder<import("@metamask/permission-controller").PermissionType.Endowment, any, {
|
|
65
|
+
permissionType: import("@metamask/permission-controller").PermissionType.Endowment;
|
|
66
|
+
targetName: import("./enum").SnapEndowments.NameLookup;
|
|
67
|
+
endowmentGetter: (_options?: import("@metamask/permission-controller").EndowmentGetterParams | undefined) => undefined;
|
|
68
|
+
allowedCaveats: readonly [string, ...string[]] | null;
|
|
69
|
+
validator: import("@metamask/permission-controller").PermissionValidatorConstraint;
|
|
70
|
+
}>;
|
|
71
|
+
}>;
|
|
72
|
+
readonly "endowment:lifecycle-hooks": Readonly<{
|
|
73
|
+
readonly targetName: import("./enum").SnapEndowments.LifecycleHooks;
|
|
74
|
+
readonly specificationBuilder: import("@metamask/permission-controller").PermissionSpecificationBuilder<import("@metamask/permission-controller").PermissionType.Endowment, any, {
|
|
75
|
+
permissionType: import("@metamask/permission-controller").PermissionType.Endowment;
|
|
76
|
+
targetName: import("./enum").SnapEndowments.LifecycleHooks;
|
|
77
|
+
endowmentGetter: (_options?: import("@metamask/permission-controller").EndowmentGetterParams | undefined) => undefined;
|
|
78
|
+
allowedCaveats: readonly [string, ...string[]] | null;
|
|
79
|
+
}>;
|
|
80
|
+
}>;
|
|
81
|
+
readonly "endowment:keyring": Readonly<{
|
|
82
|
+
readonly targetName: import("./enum").SnapEndowments.Keyring;
|
|
83
|
+
readonly specificationBuilder: import("@metamask/permission-controller").PermissionSpecificationBuilder<import("@metamask/permission-controller").PermissionType.Endowment, any, {
|
|
84
|
+
permissionType: import("@metamask/permission-controller").PermissionType.Endowment;
|
|
85
|
+
targetName: import("./enum").SnapEndowments.Keyring;
|
|
86
|
+
endowmentGetter: (_options?: import("@metamask/permission-controller").EndowmentGetterParams | undefined) => undefined;
|
|
87
|
+
allowedCaveats: readonly [string, ...string[]] | null;
|
|
88
|
+
validator: import("@metamask/permission-controller").PermissionValidatorConstraint;
|
|
89
|
+
subjectTypes: readonly import("@metamask/permission-controller").SubjectType[];
|
|
90
|
+
}>;
|
|
91
|
+
}>;
|
|
92
|
+
readonly "endowment:page-home": Readonly<{
|
|
93
|
+
readonly targetName: import("./enum").SnapEndowments.HomePage;
|
|
94
|
+
readonly specificationBuilder: import("@metamask/permission-controller").PermissionSpecificationBuilder<import("@metamask/permission-controller").PermissionType.Endowment, any, {
|
|
95
|
+
permissionType: import("@metamask/permission-controller").PermissionType.Endowment;
|
|
96
|
+
targetName: import("./enum").SnapEndowments.HomePage;
|
|
97
|
+
endowmentGetter: (_options?: import("@metamask/permission-controller").EndowmentGetterParams | undefined) => undefined;
|
|
98
|
+
allowedCaveats: readonly [string, ...string[]] | null;
|
|
99
|
+
}>;
|
|
100
|
+
}>;
|
|
101
|
+
readonly "endowment:signature-insight": Readonly<{
|
|
102
|
+
readonly targetName: import("./enum").SnapEndowments.SignatureInsight;
|
|
103
|
+
readonly specificationBuilder: import("@metamask/permission-controller").PermissionSpecificationBuilder<import("@metamask/permission-controller").PermissionType.Endowment, any, {
|
|
104
|
+
permissionType: import("@metamask/permission-controller").PermissionType.Endowment;
|
|
105
|
+
targetName: import("./enum").SnapEndowments.SignatureInsight;
|
|
106
|
+
endowmentGetter: (_options?: import("@metamask/permission-controller").EndowmentGetterParams | undefined) => undefined;
|
|
107
|
+
allowedCaveats: readonly [string, ...string[]] | null;
|
|
108
|
+
validator: import("@metamask/permission-controller").PermissionValidatorConstraint;
|
|
109
|
+
}>;
|
|
110
|
+
}>;
|
|
111
|
+
};
|
|
112
|
+
export declare const endowmentCaveatSpecifications: {
|
|
113
|
+
maxRequestTime: import("@metamask/permission-controller").CaveatSpecificationConstraint;
|
|
114
|
+
signatureOrigin: import("@metamask/permission-controller").CaveatSpecificationConstraint;
|
|
115
|
+
keyringOrigin: import("@metamask/permission-controller").CaveatSpecificationConstraint;
|
|
116
|
+
chainIds: import("@metamask/permission-controller").CaveatSpecificationConstraint;
|
|
117
|
+
lookupMatchers: import("@metamask/permission-controller").CaveatSpecificationConstraint;
|
|
118
|
+
rpcOrigin: import("@metamask/permission-controller").CaveatSpecificationConstraint;
|
|
119
|
+
transactionOrigin: import("@metamask/permission-controller").CaveatSpecificationConstraint;
|
|
120
|
+
snapCronjob: import("@metamask/permission-controller").CaveatSpecificationConstraint;
|
|
121
|
+
};
|
|
122
|
+
export declare const endowmentCaveatMappers: Record<string, (value: Json) => Pick<PermissionConstraint, 'caveats'>>;
|
|
123
|
+
export declare const handlerEndowments: Record<HandlerType, string | null>;
|
|
124
|
+
export * from './enum';
|
|
125
|
+
export { getRpcCaveatOrigins } from './rpc';
|
|
126
|
+
export { getSignatureOriginCaveat } from './signature-insight';
|
|
127
|
+
export { getTransactionOriginCaveat } from './transaction-insight';
|
|
128
|
+
export { getChainIdsCaveat, getLookupMatchersCaveat } from './name-lookup';
|
|
129
|
+
export { getKeyringCaveatOrigins } from './keyring';
|
|
130
|
+
export { getMaxRequestTimeCaveat } from './caveats';
|
|
131
|
+
export { getCronjobCaveatJobs } from './cronjob';
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { CaveatSpecificationConstraint, EndowmentGetterParams, PermissionConstraint, PermissionSpecificationBuilder, PermissionValidatorConstraint } from '@metamask/permission-controller';
|
|
2
|
+
import { PermissionType, SubjectType } from '@metamask/permission-controller';
|
|
3
|
+
import type { KeyringOrigins } from '@metamask/snaps-utils';
|
|
4
|
+
import { SnapCaveatType } from '@metamask/snaps-utils';
|
|
5
|
+
import type { Json, NonEmptyArray } from '@metamask/utils';
|
|
6
|
+
import { SnapEndowments } from './enum';
|
|
7
|
+
declare const permissionName = SnapEndowments.Keyring;
|
|
8
|
+
export declare const keyringEndowmentBuilder: Readonly<{
|
|
9
|
+
readonly targetName: SnapEndowments.Keyring;
|
|
10
|
+
readonly specificationBuilder: PermissionSpecificationBuilder<PermissionType.Endowment, any, {
|
|
11
|
+
permissionType: PermissionType.Endowment;
|
|
12
|
+
targetName: typeof permissionName;
|
|
13
|
+
endowmentGetter: (_options?: EndowmentGetterParams) => undefined;
|
|
14
|
+
allowedCaveats: Readonly<NonEmptyArray<string>> | null;
|
|
15
|
+
validator: PermissionValidatorConstraint;
|
|
16
|
+
subjectTypes: readonly SubjectType[];
|
|
17
|
+
}>;
|
|
18
|
+
}>;
|
|
19
|
+
/**
|
|
20
|
+
* Map a raw value from the `initialPermissions` to a caveat specification.
|
|
21
|
+
* Note that this function does not do any validation, that's handled by the
|
|
22
|
+
* PermissionsController when the permission is requested.
|
|
23
|
+
*
|
|
24
|
+
* @param value - The raw value from the `initialPermissions`.
|
|
25
|
+
* @returns The caveat specification.
|
|
26
|
+
*/
|
|
27
|
+
export declare function getKeyringCaveatMapper(value: Json): Pick<PermissionConstraint, 'caveats'>;
|
|
28
|
+
/**
|
|
29
|
+
* Getter function to get the {@link KeyringOrigins} caveat value from a
|
|
30
|
+
* permission.
|
|
31
|
+
*
|
|
32
|
+
* @param permission - The permission to get the caveat value from.
|
|
33
|
+
* @returns The caveat value.
|
|
34
|
+
* @throws If the permission does not have a valid {@link KeyringOrigins}
|
|
35
|
+
* caveat.
|
|
36
|
+
*/
|
|
37
|
+
export declare function getKeyringCaveatOrigins(permission?: PermissionConstraint): KeyringOrigins | null;
|
|
38
|
+
export declare const keyringCaveatSpecifications: Record<SnapCaveatType.KeyringOrigin, CaveatSpecificationConstraint>;
|
|
39
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { PermissionSpecificationBuilder, EndowmentGetterParams } from '@metamask/permission-controller';
|
|
2
|
+
import { PermissionType } from '@metamask/permission-controller';
|
|
3
|
+
import type { NonEmptyArray } from '@metamask/utils';
|
|
4
|
+
import { SnapEndowments } from './enum';
|
|
5
|
+
declare const permissionName = SnapEndowments.LifecycleHooks;
|
|
6
|
+
export declare const lifecycleHooksEndowmentBuilder: Readonly<{
|
|
7
|
+
readonly targetName: SnapEndowments.LifecycleHooks;
|
|
8
|
+
readonly specificationBuilder: PermissionSpecificationBuilder<PermissionType.Endowment, any, {
|
|
9
|
+
permissionType: PermissionType.Endowment;
|
|
10
|
+
targetName: typeof permissionName;
|
|
11
|
+
endowmentGetter: (_options?: EndowmentGetterParams) => undefined;
|
|
12
|
+
allowedCaveats: Readonly<NonEmptyArray<string>> | null;
|
|
13
|
+
}>;
|
|
14
|
+
}>;
|
|
15
|
+
export {};
|