@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,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
transactionInsightEndowmentBuilder: function() {
|
|
13
|
+
return transactionInsightEndowmentBuilder;
|
|
14
|
+
},
|
|
15
|
+
getTransactionInsightCaveatMapper: function() {
|
|
16
|
+
return getTransactionInsightCaveatMapper;
|
|
17
|
+
},
|
|
18
|
+
getTransactionOriginCaveat: function() {
|
|
19
|
+
return getTransactionOriginCaveat;
|
|
20
|
+
},
|
|
21
|
+
transactionInsightCaveatSpecifications: function() {
|
|
22
|
+
return transactionInsightCaveatSpecifications;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
const _permissioncontroller = require("@metamask/permission-controller");
|
|
26
|
+
const _rpcerrors = require("@metamask/rpc-errors");
|
|
27
|
+
const _snapsutils = require("@metamask/snaps-utils");
|
|
28
|
+
const _utils = require("@metamask/utils");
|
|
29
|
+
const _caveats = require("./caveats");
|
|
30
|
+
const _enum = require("./enum");
|
|
31
|
+
const permissionName = _enum.SnapEndowments.TransactionInsight;
|
|
32
|
+
/**
|
|
33
|
+
* `endowment:transaction-insight` returns nothing; it is intended to be used as a flag
|
|
34
|
+
* by the extension to detect whether the snap has the capability to show information on the transaction confirmation screen.
|
|
35
|
+
*
|
|
36
|
+
* @param _builderOptions - Optional specification builder options.
|
|
37
|
+
* @returns The specification for the transaction-insight endowment.
|
|
38
|
+
*/ const specificationBuilder = (_builderOptions)=>{
|
|
39
|
+
return {
|
|
40
|
+
permissionType: _permissioncontroller.PermissionType.Endowment,
|
|
41
|
+
targetName: permissionName,
|
|
42
|
+
allowedCaveats: [
|
|
43
|
+
_snapsutils.SnapCaveatType.TransactionOrigin,
|
|
44
|
+
_snapsutils.SnapCaveatType.MaxRequestTime
|
|
45
|
+
],
|
|
46
|
+
endowmentGetter: (_getterOptions)=>undefined,
|
|
47
|
+
validator: (0, _caveats.createGenericPermissionValidator)([
|
|
48
|
+
{
|
|
49
|
+
type: _snapsutils.SnapCaveatType.TransactionOrigin,
|
|
50
|
+
optional: true
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
type: _snapsutils.SnapCaveatType.MaxRequestTime,
|
|
54
|
+
optional: true
|
|
55
|
+
}
|
|
56
|
+
]),
|
|
57
|
+
subjectTypes: [
|
|
58
|
+
_permissioncontroller.SubjectType.Snap
|
|
59
|
+
]
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
const transactionInsightEndowmentBuilder = Object.freeze({
|
|
63
|
+
targetName: permissionName,
|
|
64
|
+
specificationBuilder
|
|
65
|
+
});
|
|
66
|
+
/**
|
|
67
|
+
* Validates the type of the caveat value.
|
|
68
|
+
*
|
|
69
|
+
* @param caveat - The caveat to validate.
|
|
70
|
+
* @throws If the caveat value is invalid.
|
|
71
|
+
*/ function validateCaveat(caveat) {
|
|
72
|
+
if (!(0, _utils.hasProperty)(caveat, 'value') || !(0, _utils.isPlainObject)(caveat)) {
|
|
73
|
+
throw _rpcerrors.rpcErrors.invalidParams({
|
|
74
|
+
message: 'Expected a plain object.'
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
const { value } = caveat;
|
|
78
|
+
(0, _utils.assert)(typeof value === 'boolean', 'Expected caveat value to have type "boolean"');
|
|
79
|
+
}
|
|
80
|
+
function getTransactionInsightCaveatMapper(value) {
|
|
81
|
+
if (!value || !(0, _utils.isObject)(value) || (0, _utils.isObject)(value) && Object.keys(value).length === 0) {
|
|
82
|
+
return {
|
|
83
|
+
caveats: null
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
return {
|
|
87
|
+
caveats: [
|
|
88
|
+
{
|
|
89
|
+
type: _snapsutils.SnapCaveatType.TransactionOrigin,
|
|
90
|
+
value: (0, _utils.hasProperty)(value, 'allowTransactionOrigin') && value.allowTransactionOrigin
|
|
91
|
+
}
|
|
92
|
+
]
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
function getTransactionOriginCaveat(permission) {
|
|
96
|
+
if (!permission?.caveats) {
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
(0, _utils.assert)(permission.caveats.length === 1);
|
|
100
|
+
(0, _utils.assert)(permission.caveats[0].type === _snapsutils.SnapCaveatType.TransactionOrigin);
|
|
101
|
+
const caveat = permission.caveats[0];
|
|
102
|
+
return caveat.value ?? null;
|
|
103
|
+
}
|
|
104
|
+
const transactionInsightCaveatSpecifications = {
|
|
105
|
+
[_snapsutils.SnapCaveatType.TransactionOrigin]: Object.freeze({
|
|
106
|
+
type: _snapsutils.SnapCaveatType.TransactionOrigin,
|
|
107
|
+
validator: (caveat)=>validateCaveat(caveat)
|
|
108
|
+
})
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
//# sourceMappingURL=transaction-insight.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/endowments/transaction-insight.ts"],"sourcesContent":["import type {\n PermissionSpecificationBuilder,\n EndowmentGetterParams,\n ValidPermissionSpecification,\n PermissionValidatorConstraint,\n PermissionConstraint,\n CaveatSpecificationConstraint,\n Caveat,\n} from '@metamask/permission-controller';\nimport { PermissionType, SubjectType } from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport { SnapCaveatType } from '@metamask/snaps-utils';\nimport type { Json, NonEmptyArray } from '@metamask/utils';\nimport { assert, hasProperty, isObject, isPlainObject } from '@metamask/utils';\n\nimport { createGenericPermissionValidator } from './caveats';\nimport { SnapEndowments } from './enum';\n\nconst permissionName = SnapEndowments.TransactionInsight;\n\ntype TransactionInsightEndowmentSpecification = ValidPermissionSpecification<{\n permissionType: PermissionType.Endowment;\n targetName: typeof permissionName;\n endowmentGetter: (_options?: EndowmentGetterParams) => undefined;\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n validator: PermissionValidatorConstraint;\n}>;\n\n/**\n * `endowment:transaction-insight` returns nothing; it is intended to be used as a flag\n * by the extension to detect whether the snap has the capability to show information on the transaction confirmation screen.\n *\n * @param _builderOptions - Optional specification builder options.\n * @returns The specification for the transaction-insight endowment.\n */\nconst specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.Endowment,\n any,\n TransactionInsightEndowmentSpecification\n> = (_builderOptions?: unknown) => {\n return {\n permissionType: PermissionType.Endowment,\n targetName: permissionName,\n allowedCaveats: [\n SnapCaveatType.TransactionOrigin,\n SnapCaveatType.MaxRequestTime,\n ],\n endowmentGetter: (_getterOptions?: EndowmentGetterParams) => undefined,\n validator: createGenericPermissionValidator([\n { type: SnapCaveatType.TransactionOrigin, optional: true },\n { type: SnapCaveatType.MaxRequestTime, optional: true },\n ]),\n subjectTypes: [SubjectType.Snap],\n };\n};\n\nexport const transactionInsightEndowmentBuilder = Object.freeze({\n targetName: permissionName,\n specificationBuilder,\n} as const);\n\n/**\n * Validates the type of the caveat value.\n *\n * @param caveat - The caveat to validate.\n * @throws If the caveat value is invalid.\n */\nfunction validateCaveat(caveat: Caveat<string, any>): void {\n if (!hasProperty(caveat, 'value') || !isPlainObject(caveat)) {\n throw rpcErrors.invalidParams({\n message: 'Expected a plain object.',\n });\n }\n\n const { value } = caveat;\n\n assert(\n typeof value === 'boolean',\n 'Expected caveat value to have type \"boolean\"',\n );\n}\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 getTransactionInsightCaveatMapper(\n value: Json,\n): Pick<PermissionConstraint, 'caveats'> {\n if (\n !value ||\n !isObject(value) ||\n (isObject(value) && Object.keys(value).length === 0)\n ) {\n return { caveats: null };\n }\n return {\n caveats: [\n {\n type: SnapCaveatType.TransactionOrigin,\n value:\n hasProperty(value, 'allowTransactionOrigin') &&\n (value.allowTransactionOrigin as boolean),\n },\n ],\n };\n}\n\n/**\n * Getter function to get the transaction origin caveat from a permission.\n *\n * This does basic validation of the caveat, but does not validate the type or\n * value of the namespaces object itself, as this is handled by the\n * `PermissionsController` when the permission is requested.\n *\n * @param permission - The permission to get the transaction origin caveat from.\n * @returns The transaction origin, or `null` if the permission does not have a\n * transaction origin caveat.\n */\nexport function getTransactionOriginCaveat(\n permission?: PermissionConstraint,\n): boolean | null {\n if (!permission?.caveats) {\n return null;\n }\n\n assert(permission.caveats.length === 1);\n assert(permission.caveats[0].type === SnapCaveatType.TransactionOrigin);\n\n const caveat = permission.caveats[0] as Caveat<string, boolean>;\n\n return caveat.value ?? null;\n}\n\nexport const transactionInsightCaveatSpecifications: Record<\n SnapCaveatType.TransactionOrigin,\n CaveatSpecificationConstraint\n> = {\n [SnapCaveatType.TransactionOrigin]: Object.freeze({\n type: SnapCaveatType.TransactionOrigin,\n validator: (caveat: Caveat<string, any>) => validateCaveat(caveat),\n }),\n};\n"],"names":["transactionInsightEndowmentBuilder","getTransactionInsightCaveatMapper","getTransactionOriginCaveat","transactionInsightCaveatSpecifications","permissionName","SnapEndowments","TransactionInsight","specificationBuilder","_builderOptions","permissionType","PermissionType","Endowment","targetName","allowedCaveats","SnapCaveatType","TransactionOrigin","MaxRequestTime","endowmentGetter","_getterOptions","undefined","validator","createGenericPermissionValidator","type","optional","subjectTypes","SubjectType","Snap","Object","freeze","validateCaveat","caveat","hasProperty","isPlainObject","rpcErrors","invalidParams","message","value","assert","isObject","keys","length","caveats","allowTransactionOrigin","permission"],"mappings":";;;;;;;;;;;IAwDaA,kCAAkC;eAAlCA;;IAkCGC,iCAAiC;eAAjCA;;IAiCAC,0BAA0B;eAA1BA;;IAeHC,sCAAsC;eAAtCA;;;sCAjI+B;2BAClB;4BACK;uBAE8B;yBAEZ;sBAClB;AAE/B,MAAMC,iBAAiBC,oBAAc,CAACC,kBAAkB;AAUxD;;;;;;CAMC,GACD,MAAMC,uBAIF,CAACC;IACH,OAAO;QACLC,gBAAgBC,oCAAc,CAACC,SAAS;QACxCC,YAAYR;QACZS,gBAAgB;YACdC,0BAAc,CAACC,iBAAiB;YAChCD,0BAAc,CAACE,cAAc;SAC9B;QACDC,iBAAiB,CAACC,iBAA2CC;QAC7DC,WAAWC,IAAAA,yCAAgC,EAAC;YAC1C;gBAAEC,MAAMR,0BAAc,CAACC,iBAAiB;gBAAEQ,UAAU;YAAK;YACzD;gBAAED,MAAMR,0BAAc,CAACE,cAAc;gBAAEO,UAAU;YAAK;SACvD;QACDC,cAAc;YAACC,iCAAW,CAACC,IAAI;SAAC;IAClC;AACF;AAEO,MAAM1B,qCAAqC2B,OAAOC,MAAM,CAAC;IAC9DhB,YAAYR;IACZG;AACF;AAEA;;;;;CAKC,GACD,SAASsB,eAAeC,MAA2B;IACjD,IAAI,CAACC,IAAAA,kBAAW,EAACD,QAAQ,YAAY,CAACE,IAAAA,oBAAa,EAACF,SAAS;QAC3D,MAAMG,oBAAS,CAACC,aAAa,CAAC;YAC5BC,SAAS;QACX;IACF;IAEA,MAAM,EAAEC,KAAK,EAAE,GAAGN;IAElBO,IAAAA,aAAM,EACJ,OAAOD,UAAU,WACjB;AAEJ;AAUO,SAASnC,kCACdmC,KAAW;IAEX,IACE,CAACA,SACD,CAACE,IAAAA,eAAQ,EAACF,UACTE,IAAAA,eAAQ,EAACF,UAAUT,OAAOY,IAAI,CAACH,OAAOI,MAAM,KAAK,GAClD;QACA,OAAO;YAAEC,SAAS;QAAK;IACzB;IACA,OAAO;QACLA,SAAS;YACP;gBACEnB,MAAMR,0BAAc,CAACC,iBAAiB;gBACtCqB,OACEL,IAAAA,kBAAW,EAACK,OAAO,6BAClBA,MAAMM,sBAAsB;YACjC;SACD;IACH;AACF;AAaO,SAASxC,2BACdyC,UAAiC;IAEjC,IAAI,CAACA,YAAYF,SAAS;QACxB,OAAO;IACT;IAEAJ,IAAAA,aAAM,EAACM,WAAWF,OAAO,CAACD,MAAM,KAAK;IACrCH,IAAAA,aAAM,EAACM,WAAWF,OAAO,CAAC,EAAE,CAACnB,IAAI,KAAKR,0BAAc,CAACC,iBAAiB;IAEtE,MAAMe,SAASa,WAAWF,OAAO,CAAC,EAAE;IAEpC,OAAOX,OAAOM,KAAK,IAAI;AACzB;AAEO,MAAMjC,yCAGT;IACF,CAACW,0BAAc,CAACC,iBAAiB,CAAC,EAAEY,OAAOC,MAAM,CAAC;QAChDN,MAAMR,0BAAc,CAACC,iBAAiB;QACtCK,WAAW,CAACU,SAAgCD,eAAeC;IAC7D;AACF"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "webAssemblyEndowmentBuilder", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return webAssemblyEndowmentBuilder;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _permissioncontroller = require("@metamask/permission-controller");
|
|
12
|
+
const _enum = require("./enum");
|
|
13
|
+
const permissionName = _enum.SnapEndowments.WebAssemblyAccess;
|
|
14
|
+
/**
|
|
15
|
+
* `endowment:webassembly` returns the name of global browser API(s) that
|
|
16
|
+
* enable access to the WebAssembly API.
|
|
17
|
+
* This is intended to populate the endowments of the SES Compartment
|
|
18
|
+
* in which a Snap executes.
|
|
19
|
+
*
|
|
20
|
+
* @param _builderOptions - Optional specification builder options.
|
|
21
|
+
* @returns The specification for the WebAssembly endowment.
|
|
22
|
+
*/ const specificationBuilder = (_builderOptions)=>{
|
|
23
|
+
return {
|
|
24
|
+
permissionType: _permissioncontroller.PermissionType.Endowment,
|
|
25
|
+
targetName: permissionName,
|
|
26
|
+
allowedCaveats: null,
|
|
27
|
+
endowmentGetter: (_getterOptions)=>{
|
|
28
|
+
return [
|
|
29
|
+
'WebAssembly'
|
|
30
|
+
];
|
|
31
|
+
},
|
|
32
|
+
subjectTypes: [
|
|
33
|
+
_permissioncontroller.SubjectType.Snap
|
|
34
|
+
]
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
const webAssemblyEndowmentBuilder = Object.freeze({
|
|
38
|
+
targetName: permissionName,
|
|
39
|
+
specificationBuilder
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
//# sourceMappingURL=web-assembly.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/endowments/web-assembly.ts"],"sourcesContent":["import type {\n EndowmentGetterParams,\n PermissionSpecificationBuilder,\n ValidPermissionSpecification,\n} from '@metamask/permission-controller';\nimport { PermissionType, SubjectType } from '@metamask/permission-controller';\n\nimport { SnapEndowments } from './enum';\n\nconst permissionName = SnapEndowments.WebAssemblyAccess;\n\ntype WebAssemblyEndowmentSpecification = ValidPermissionSpecification<{\n permissionType: PermissionType.Endowment;\n targetName: typeof permissionName;\n endowmentGetter: (_options?: any) => ['WebAssembly'];\n allowedCaveats: null;\n}>;\n\n/**\n * `endowment:webassembly` returns the name of global browser API(s) that\n * enable access to the WebAssembly API.\n * This is intended to populate the endowments of the SES Compartment\n * in which a Snap executes.\n *\n * @param _builderOptions - Optional specification builder options.\n * @returns The specification for the WebAssembly endowment.\n */\nconst specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.Endowment,\n any,\n WebAssemblyEndowmentSpecification\n> = (_builderOptions?: any) => {\n return {\n permissionType: PermissionType.Endowment,\n targetName: permissionName,\n allowedCaveats: null,\n endowmentGetter: (_getterOptions?: EndowmentGetterParams) => {\n return ['WebAssembly'];\n },\n subjectTypes: [SubjectType.Snap],\n };\n};\n\nexport const webAssemblyEndowmentBuilder = Object.freeze({\n targetName: permissionName,\n specificationBuilder,\n} as const);\n"],"names":["webAssemblyEndowmentBuilder","permissionName","SnapEndowments","WebAssemblyAccess","specificationBuilder","_builderOptions","permissionType","PermissionType","Endowment","targetName","allowedCaveats","endowmentGetter","_getterOptions","subjectTypes","SubjectType","Snap","Object","freeze"],"mappings":";;;;+BA2CaA;;;eAAAA;;;sCAtC+B;sBAEb;AAE/B,MAAMC,iBAAiBC,oBAAc,CAACC,iBAAiB;AASvD;;;;;;;;CAQC,GACD,MAAMC,uBAIF,CAACC;IACH,OAAO;QACLC,gBAAgBC,oCAAc,CAACC,SAAS;QACxCC,YAAYR;QACZS,gBAAgB;QAChBC,iBAAiB,CAACC;YAChB,OAAO;gBAAC;aAAc;QACxB;QACAC,cAAc;YAACC,iCAAW,CAACC,IAAI;SAAC;IAClC;AACF;AAEO,MAAMf,8BAA8BgB,OAAOC,MAAM,CAAC;IACvDR,YAAYR;IACZG;AACF"}
|
package/dist/cjs/index.js
CHANGED
|
@@ -23,9 +23,11 @@ _export(exports, {
|
|
|
23
23
|
}
|
|
24
24
|
});
|
|
25
25
|
const _permitted = require("./permitted");
|
|
26
|
-
_export_star(require("./restricted"), exports);
|
|
27
26
|
const _snapsutils = require("@metamask/snaps-utils");
|
|
28
27
|
const _utils = require("./utils");
|
|
28
|
+
_export_star(require("./endowments"), exports);
|
|
29
|
+
_export_star(require("./permissions"), exports);
|
|
30
|
+
_export_star(require("./restricted"), exports);
|
|
29
31
|
function _export_star(from, to) {
|
|
30
32
|
Object.keys(from).forEach(function(k) {
|
|
31
33
|
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export {\n handlers as permittedMethods,\n createSnapsMethodMiddleware,\n} from './permitted';\nexport type { PermittedRpcMethodHooks } from './permitted';\nexport { SnapCaveatType } from '@metamask/snaps-utils';\nexport { selectHooks } from './utils';\nexport * from './endowments';\nexport * from './permissions';\nexport * from './restricted';\n"],"names":["permittedMethods","handlers","createSnapsMethodMiddleware","SnapCaveatType","selectHooks"],"mappings":";;;;;;;;;;;IACcA,gBAAgB;eAA5BC,mBAAQ;;IACRC,2BAA2B;eAA3BA,sCAA2B;;IAGpBC,cAAc;eAAdA,0BAAc;;IACdC,WAAW;eAAXA,kBAAW;;;2BAHb;4BAEwB;uBACH;qBACd;qBACA;qBACA"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
processSnapPermissions: function() {
|
|
13
|
+
return processSnapPermissions;
|
|
14
|
+
},
|
|
15
|
+
buildSnapEndowmentSpecifications: function() {
|
|
16
|
+
return buildSnapEndowmentSpecifications;
|
|
17
|
+
},
|
|
18
|
+
buildSnapRestrictedMethodSpecifications: function() {
|
|
19
|
+
return buildSnapRestrictedMethodSpecifications;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
const _utils = require("@metamask/utils");
|
|
23
|
+
const _endowments = require("./endowments");
|
|
24
|
+
const _restricted = require("./restricted");
|
|
25
|
+
const _utils1 = require("./utils");
|
|
26
|
+
function processSnapPermissions(initialPermissions) {
|
|
27
|
+
return Object.fromEntries(Object.entries(initialPermissions).map(([initialPermission, value])=>{
|
|
28
|
+
if ((0, _utils.hasProperty)(_restricted.caveatMappers, initialPermission)) {
|
|
29
|
+
return [
|
|
30
|
+
initialPermission,
|
|
31
|
+
_restricted.caveatMappers[initialPermission](value)
|
|
32
|
+
];
|
|
33
|
+
} else if ((0, _utils.hasProperty)(_endowments.endowmentCaveatMappers, initialPermission)) {
|
|
34
|
+
return [
|
|
35
|
+
initialPermission,
|
|
36
|
+
_endowments.endowmentCaveatMappers[initialPermission](value)
|
|
37
|
+
];
|
|
38
|
+
}
|
|
39
|
+
// If we have no mapping, this may be a non-snap permission, return as-is
|
|
40
|
+
return [
|
|
41
|
+
initialPermission,
|
|
42
|
+
value
|
|
43
|
+
];
|
|
44
|
+
}));
|
|
45
|
+
}
|
|
46
|
+
const buildSnapEndowmentSpecifications = (excludedEndowments)=>Object.values(_endowments.endowmentPermissionBuilders).reduce((allSpecifications, { targetName, specificationBuilder })=>{
|
|
47
|
+
if (!excludedEndowments.includes(targetName)) {
|
|
48
|
+
allSpecifications[targetName] = specificationBuilder({});
|
|
49
|
+
}
|
|
50
|
+
return allSpecifications;
|
|
51
|
+
}, {});
|
|
52
|
+
const buildSnapRestrictedMethodSpecifications = (excludedPermissions, hooks)=>Object.values(_restricted.restrictedMethodPermissionBuilders).reduce((specifications, { targetName, specificationBuilder, methodHooks })=>{
|
|
53
|
+
if (!excludedPermissions.includes(targetName)) {
|
|
54
|
+
specifications[targetName] = specificationBuilder({
|
|
55
|
+
// @ts-expect-error The selectHooks type is wonky
|
|
56
|
+
methodHooks: (0, _utils1.selectHooks)(hooks, methodHooks)
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
return specifications;
|
|
60
|
+
}, {});
|
|
61
|
+
|
|
62
|
+
//# sourceMappingURL=permissions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/permissions.ts"],"sourcesContent":["import type {\n PermissionConstraint,\n PermissionSpecificationConstraint,\n} from '@metamask/permission-controller';\nimport type { SnapPermissions } from '@metamask/snaps-utils';\nimport { hasProperty } from '@metamask/utils';\n\nimport {\n endowmentCaveatMappers,\n endowmentPermissionBuilders,\n} from './endowments';\nimport {\n caveatMappers,\n restrictedMethodPermissionBuilders,\n} from './restricted';\nimport { selectHooks } from './utils';\n\n/**\n * Map initial permissions as defined in a Snap manifest to something that can\n * be processed by the PermissionsController. Each caveat mapping function\n * should return a valid permission caveat value.\n *\n * This function does not validate the caveat values, since that is done by\n * the PermissionsController itself, upon requesting the permissions.\n *\n * @param initialPermissions - The initial permissions to process.\n * @returns The processed permissions.\n */\nexport function processSnapPermissions(\n initialPermissions: SnapPermissions,\n): Record<string, Pick<PermissionConstraint, 'caveats'>> {\n return Object.fromEntries(\n Object.entries(initialPermissions).map(([initialPermission, value]) => {\n if (hasProperty(caveatMappers, initialPermission)) {\n return [initialPermission, caveatMappers[initialPermission](value)];\n } else if (hasProperty(endowmentCaveatMappers, initialPermission)) {\n return [\n initialPermission,\n endowmentCaveatMappers[initialPermission](value),\n ];\n }\n\n // If we have no mapping, this may be a non-snap permission, return as-is\n return [\n initialPermission,\n value as Pick<PermissionConstraint, 'caveats'>,\n ];\n }),\n );\n}\n\nexport const buildSnapEndowmentSpecifications = (\n excludedEndowments: string[],\n) =>\n Object.values(endowmentPermissionBuilders).reduce<\n Record<string, PermissionSpecificationConstraint>\n >((allSpecifications, { targetName, specificationBuilder }) => {\n if (!excludedEndowments.includes(targetName)) {\n allSpecifications[targetName] = specificationBuilder({});\n }\n return allSpecifications;\n }, {});\n\nexport const buildSnapRestrictedMethodSpecifications = (\n excludedPermissions: string[],\n hooks: Record<string, unknown>,\n) =>\n Object.values(restrictedMethodPermissionBuilders).reduce<\n Record<string, PermissionSpecificationConstraint>\n >((specifications, { targetName, specificationBuilder, methodHooks }) => {\n if (!excludedPermissions.includes(targetName)) {\n specifications[targetName] = specificationBuilder({\n // @ts-expect-error The selectHooks type is wonky\n methodHooks: selectHooks<typeof hooks, keyof typeof methodHooks>(\n hooks,\n methodHooks,\n ) as Pick<typeof hooks, keyof typeof methodHooks>,\n });\n }\n return specifications;\n }, {});\n"],"names":["processSnapPermissions","buildSnapEndowmentSpecifications","buildSnapRestrictedMethodSpecifications","initialPermissions","Object","fromEntries","entries","map","initialPermission","value","hasProperty","caveatMappers","endowmentCaveatMappers","excludedEndowments","values","endowmentPermissionBuilders","reduce","allSpecifications","targetName","specificationBuilder","includes","excludedPermissions","hooks","restrictedMethodPermissionBuilders","specifications","methodHooks","selectHooks"],"mappings":";;;;;;;;;;;IA4BgBA,sBAAsB;eAAtBA;;IAuBHC,gCAAgC;eAAhCA;;IAYAC,uCAAuC;eAAvCA;;;uBA1De;4BAKrB;4BAIA;wBACqB;AAarB,SAASF,uBACdG,kBAAmC;IAEnC,OAAOC,OAAOC,WAAW,CACvBD,OAAOE,OAAO,CAACH,oBAAoBI,GAAG,CAAC,CAAC,CAACC,mBAAmBC,MAAM;QAChE,IAAIC,IAAAA,kBAAW,EAACC,yBAAa,EAAEH,oBAAoB;YACjD,OAAO;gBAACA;gBAAmBG,yBAAa,CAACH,kBAAkB,CAACC;aAAO;QACrE,OAAO,IAAIC,IAAAA,kBAAW,EAACE,kCAAsB,EAAEJ,oBAAoB;YACjE,OAAO;gBACLA;gBACAI,kCAAsB,CAACJ,kBAAkB,CAACC;aAC3C;QACH;QAEA,yEAAyE;QACzE,OAAO;YACLD;YACAC;SACD;IACH;AAEJ;AAEO,MAAMR,mCAAmC,CAC9CY,qBAEAT,OAAOU,MAAM,CAACC,uCAA2B,EAAEC,MAAM,CAE/C,CAACC,mBAAmB,EAAEC,UAAU,EAAEC,oBAAoB,EAAE;QACxD,IAAI,CAACN,mBAAmBO,QAAQ,CAACF,aAAa;YAC5CD,iBAAiB,CAACC,WAAW,GAAGC,qBAAqB,CAAC;QACxD;QACA,OAAOF;IACT,GAAG,CAAC;AAEC,MAAMf,0CAA0C,CACrDmB,qBACAC,QAEAlB,OAAOU,MAAM,CAACS,8CAAkC,EAAEP,MAAM,CAEtD,CAACQ,gBAAgB,EAAEN,UAAU,EAAEC,oBAAoB,EAAEM,WAAW,EAAE;QAClE,IAAI,CAACJ,oBAAoBD,QAAQ,CAACF,aAAa;YAC7CM,cAAc,CAACN,WAAW,GAAGC,qBAAqB;gBAChD,iDAAiD;gBACjDM,aAAaC,IAAAA,mBAAW,EACtBJ,OACAG;YAEJ;QACF;QACA,OAAOD;IACT,GAAG,CAAC"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "createInterfaceHandler", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return createInterfaceHandler;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _rpcerrors = require("@metamask/rpc-errors");
|
|
12
|
+
const _snapssdk = require("@metamask/snaps-sdk");
|
|
13
|
+
const _superstruct = require("superstruct");
|
|
14
|
+
const hookNames = {
|
|
15
|
+
createInterface: true
|
|
16
|
+
};
|
|
17
|
+
const createInterfaceHandler = {
|
|
18
|
+
methodNames: [
|
|
19
|
+
'snap_createInterface'
|
|
20
|
+
],
|
|
21
|
+
implementation: getCreateInterfaceImplementation,
|
|
22
|
+
hookNames
|
|
23
|
+
};
|
|
24
|
+
const CreateInterfaceParametersStruct = (0, _superstruct.object)({
|
|
25
|
+
ui: _snapssdk.ComponentStruct
|
|
26
|
+
});
|
|
27
|
+
/**
|
|
28
|
+
* The `snap_createInterface` method implementation.
|
|
29
|
+
*
|
|
30
|
+
* @param req - The JSON-RPC request object.
|
|
31
|
+
* @param res - The JSON-RPC response object.
|
|
32
|
+
* @param _next - The `json-rpc-engine` "next" callback. Not used by this
|
|
33
|
+
* function.
|
|
34
|
+
* @param end - The `json-rpc-engine` "end" callback.
|
|
35
|
+
* @param hooks - The RPC method hooks.
|
|
36
|
+
* @param hooks.createInterface - The function to create the interface.
|
|
37
|
+
* @returns Nothing.
|
|
38
|
+
*/ async function getCreateInterfaceImplementation(req, res, _next, end, { createInterface }) {
|
|
39
|
+
const { params } = req;
|
|
40
|
+
try {
|
|
41
|
+
const validatedParams = getValidatedParams(params);
|
|
42
|
+
const { ui } = validatedParams;
|
|
43
|
+
res.result = await createInterface(ui);
|
|
44
|
+
} catch (error) {
|
|
45
|
+
return end(error);
|
|
46
|
+
}
|
|
47
|
+
return end();
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Validate the createInterface method `params` and returns them cast to the correct
|
|
51
|
+
* type. Throws if validation fails.
|
|
52
|
+
*
|
|
53
|
+
* @param params - The unvalidated params object from the method request.
|
|
54
|
+
* @returns The validated createInterface method parameter object.
|
|
55
|
+
*/ function getValidatedParams(params) {
|
|
56
|
+
try {
|
|
57
|
+
return (0, _superstruct.create)(params, CreateInterfaceParametersStruct);
|
|
58
|
+
} catch (error) {
|
|
59
|
+
if (error instanceof _superstruct.StructError) {
|
|
60
|
+
throw _rpcerrors.rpcErrors.invalidParams({
|
|
61
|
+
message: `Invalid params: ${error.message}.`
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
/* istanbul ignore next */ throw _rpcerrors.rpcErrors.internal();
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
//# sourceMappingURL=createInterface.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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 Component,\n CreateInterfaceParams,\n CreateInterfaceResult,\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 } 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: (ui: Component) => 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: ComponentStruct,\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 } = validatedParams;\n\n res.result = await createInterface(ui);\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"],"names":["createInterfaceHandler","hookNames","createInterface","methodNames","implementation","getCreateInterfaceImplementation","CreateInterfaceParametersStruct","object","ui","ComponentStruct","req","res","_next","end","params","validatedParams","getValidatedParams","result","error","create","StructError","rpcErrors","invalidParams","message","internal"],"mappings":";;;;+BA4BaA;;;eAAAA;;;2BA1Ba;0BAOM;6BAGY;AAI5C,MAAMC,YAA2D;IAC/DC,iBAAiB;AACnB;AAUO,MAAMF,yBAIT;IACFG,aAAa;QAAC;KAAuB;IACrCC,gBAAgBC;IAChBJ;AACF;AAEA,MAAMK,kCAAkCC,IAAAA,mBAAM,EAAC;IAC7CC,IAAIC,yBAAe;AACrB;AAOA;;;;;;;;;;;CAWC,GACD,eAAeJ,iCACbK,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,EAAE,GAAGO;QAEfJ,IAAIM,MAAM,GAAG,MAAMf,gBAAgBM;IACrC,EAAE,OAAOU,OAAO;QACd,OAAOL,IAAIK;IACb;IAEA,OAAOL;AACT;AAEA;;;;;;CAMC,GACD,SAASG,mBAAmBF,MAAe;IACzC,IAAI;QACF,OAAOK,IAAAA,mBAAM,EAACL,QAAQR;IACxB,EAAE,OAAOY,OAAO;QACd,IAAIA,iBAAiBE,wBAAW,EAAE;YAChC,MAAMC,oBAAS,CAACC,aAAa,CAAC;gBAC5BC,SAAS,CAAC,gBAAgB,EAAEL,MAAMK,OAAO,CAAC,CAAC,CAAC;YAC9C;QACF;QACA,wBAAwB,GACxB,MAAMF,oBAAS,CAACG,QAAQ;IAC1B;AACF"}
|
|
@@ -47,7 +47,7 @@ const getFileHandler = {
|
|
|
47
47
|
* function.
|
|
48
48
|
* @param end - The `json-rpc-engine` "end" callback.
|
|
49
49
|
* @param hooks - The RPC method hooks.
|
|
50
|
-
* @param hooks.getSnapFile - The
|
|
50
|
+
* @param hooks.getSnapFile - The function to load a static snap file.
|
|
51
51
|
* @returns Nothing.
|
|
52
52
|
*/ async function implementation(req, res, _next, end, { getSnapFile }) {
|
|
53
53
|
const { params } = req;
|
|
@@ -1 +1 @@
|
|
|
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
|
|
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"],"names":["GetFileArgsStruct","getFileHandler","object","path","string","encoding","optional","union","enumValue","AuxiliaryFileEncoding","Base64","Hex","Utf8","hookNames","getSnapFile","methodNames","implementation","req","res","_next","end","params","assertStruct","rpcErrors","invalidParams","result","error"],"mappings":";;;;;;;;;;;IAYaA,iBAAiB;eAAjBA;;IAoBAC,cAAc;eAAdA;;;2BA9Ba;0BAEuB;uBAGpB;6BACmB;AAIzC,MAAMD,oBAAoBE,IAAAA,mBAAM,EAAC;IACtCC,MAAMC,IAAAA,mBAAM;IACZC,UAAUC,IAAAA,qBAAQ,EAChBC,IAAAA,kBAAK,EAAC;QACJC,IAAAA,mBAAS,EAACC,+BAAqB,CAACC,MAAM;QACtCF,IAAAA,mBAAS,EAACC,+BAAqB,CAACE,GAAG;QACnCH,IAAAA,mBAAS,EAACC,+BAAqB,CAACG,IAAI;KACrC;AAEL;AAOA,MAAMC,YAA6C;IACjDC,aAAa;AACf;AAEO,MAAMb,iBAIT;IACFc,aAAa;QAAC;KAAe;IAC7BC;IACAH;AACF;AASA;;;;;;;;;;;CAWC,GACD,eAAeG,eACbC,GAA0C,EAC1CC,GAA0C,EAC1CC,KAAc,EACdC,GAA6B,EAC7B,EAAEN,WAAW,EAAgB;IAE7B,MAAM,EAAEO,MAAM,EAAE,GAAGJ;IAEnBK,IAAAA,mBAAY,EACVD,QACArB,mBACA,qCACAuB,oBAAS,CAACC,aAAa;IAGzB,IAAI;QACFN,IAAIO,MAAM,GAAG,MAAMX,YACjBO,OAAOlB,IAAI,EACXkB,OAAOhB,QAAQ,IAAII,+BAAqB,CAACC,MAAM;IAEnD,EAAE,OAAOgB,OAAO;QACd,OAAON,IAAIM;IACb;IAEA,OAAON;AACT"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "getInterfaceStateHandler", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return getInterfaceStateHandler;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _rpcerrors = require("@metamask/rpc-errors");
|
|
12
|
+
const _superstruct = require("superstruct");
|
|
13
|
+
const hookNames = {
|
|
14
|
+
getInterfaceState: true
|
|
15
|
+
};
|
|
16
|
+
const getInterfaceStateHandler = {
|
|
17
|
+
methodNames: [
|
|
18
|
+
'snap_getInterfaceState'
|
|
19
|
+
],
|
|
20
|
+
implementation: getGetInterfaceStateImplementation,
|
|
21
|
+
hookNames
|
|
22
|
+
};
|
|
23
|
+
const GetInterfaceStateParametersStruct = (0, _superstruct.object)({
|
|
24
|
+
id: (0, _superstruct.string)()
|
|
25
|
+
});
|
|
26
|
+
/**
|
|
27
|
+
* The `snap_getInterfaceState` method implementation.
|
|
28
|
+
*
|
|
29
|
+
* @param req - The JSON-RPC request object.
|
|
30
|
+
* @param res - The JSON-RPC response object.
|
|
31
|
+
* @param _next - The `json-rpc-engine` "next" callback. Not used by this
|
|
32
|
+
* function.
|
|
33
|
+
* @param end - The `json-rpc-engine` "end" callback.
|
|
34
|
+
* @param hooks - The RPC method hooks.
|
|
35
|
+
* @param hooks.getInterfaceState - The function to get the interface state.
|
|
36
|
+
* @returns Noting.
|
|
37
|
+
*/ function getGetInterfaceStateImplementation(req, res, _next, end, { getInterfaceState }) {
|
|
38
|
+
const { params } = req;
|
|
39
|
+
try {
|
|
40
|
+
const validatedParams = getValidatedParams(params);
|
|
41
|
+
const { id } = validatedParams;
|
|
42
|
+
res.result = getInterfaceState(id);
|
|
43
|
+
} catch (error) {
|
|
44
|
+
return end(error);
|
|
45
|
+
}
|
|
46
|
+
return end();
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Validate the getInterfaceState method `params` and returns them cast to the correct
|
|
50
|
+
* type. Throws if validation fails.
|
|
51
|
+
*
|
|
52
|
+
* @param params - The unvalidated params object from the method request.
|
|
53
|
+
* @returns The validated getInterfaceState method parameter object.
|
|
54
|
+
*/ function getValidatedParams(params) {
|
|
55
|
+
try {
|
|
56
|
+
return (0, _superstruct.create)(params, GetInterfaceStateParametersStruct);
|
|
57
|
+
} catch (error) {
|
|
58
|
+
if (error instanceof _superstruct.StructError) {
|
|
59
|
+
throw _rpcerrors.rpcErrors.invalidParams({
|
|
60
|
+
message: `Invalid params: ${error.message}.`
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
/* istanbul ignore next */ throw _rpcerrors.rpcErrors.internal();
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
//# sourceMappingURL=getInterfaceState.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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"],"names":["getInterfaceStateHandler","hookNames","getInterfaceState","methodNames","implementation","getGetInterfaceStateImplementation","GetInterfaceStateParametersStruct","object","id","string","req","res","_next","end","params","validatedParams","getValidatedParams","result","error","create","StructError","rpcErrors","invalidParams","message","internal"],"mappings":";;;;+BA2BaA;;;eAAAA;;;2BAzBa;6BAS0B;AAIpD,MAAMC,YAA6D;IACjEC,mBAAmB;AACrB;AAUO,MAAMF,2BAIT;IACFG,aAAa;QAAC;KAAyB;IACvCC,gBAAgBC;IAChBJ;AACF;AAEA,MAAMK,oCAAoCC,IAAAA,mBAAM,EAAC;IAC/CC,IAAIC,IAAAA,mBAAM;AACZ;AAOA;;;;;;;;;;;CAWC,GACD,SAASJ,mCACPK,GAAgD,EAChDC,GAAoD,EACpDC,KAAc,EACdC,GAA6B,EAC7B,EAAEX,iBAAiB,EAAgC;IAEnD,MAAM,EAAEY,MAAM,EAAE,GAAGJ;IAEnB,IAAI;QACF,MAAMK,kBAAkBC,mBAAmBF;QAE3C,MAAM,EAAEN,EAAE,EAAE,GAAGO;QAEfJ,IAAIM,MAAM,GAAGf,kBAAkBM;IACjC,EAAE,OAAOU,OAAO;QACd,OAAOL,IAAIK;IACb;IAEA,OAAOL;AACT;AAEA;;;;;;CAMC,GACD,SAASG,mBAAmBF,MAAe;IACzC,IAAI;QACF,OAAOK,IAAAA,mBAAM,EAACL,QAAQR;IACxB,EAAE,OAAOY,OAAO;QACd,IAAIA,iBAAiBE,wBAAW,EAAE;YAChC,MAAMC,oBAAS,CAACC,aAAa,CAAC;gBAC5BC,SAAS,CAAC,gBAAgB,EAAEL,MAAMK,OAAO,CAAC,CAAC,CAAC;YAC9C;QACF;QACA,wBAAwB,GACxB,MAAMF,oBAAS,CAACG,QAAQ;IAC1B;AACF"}
|
|
@@ -16,13 +16,16 @@ _export(exports, {
|
|
|
16
16
|
return handlers;
|
|
17
17
|
}
|
|
18
18
|
});
|
|
19
|
+
const _createInterface = require("./createInterface");
|
|
19
20
|
const _getAllSnaps = require("./getAllSnaps");
|
|
20
21
|
const _getClientStatus = require("./getClientStatus");
|
|
21
22
|
const _getFile = require("./getFile");
|
|
23
|
+
const _getInterfaceState = require("./getInterfaceState");
|
|
22
24
|
const _getSnaps = require("./getSnaps");
|
|
23
25
|
const _invokeKeyring = require("./invokeKeyring");
|
|
24
26
|
const _invokeSnapSugar = require("./invokeSnapSugar");
|
|
25
27
|
const _requestSnaps = require("./requestSnaps");
|
|
28
|
+
const _updateInterface = require("./updateInterface");
|
|
26
29
|
const methodHandlers = {
|
|
27
30
|
wallet_getAllSnaps: _getAllSnaps.getAllSnapsHandler,
|
|
28
31
|
wallet_getSnaps: _getSnaps.getSnapsHandler,
|
|
@@ -30,7 +33,10 @@ const methodHandlers = {
|
|
|
30
33
|
wallet_invokeSnap: _invokeSnapSugar.invokeSnapSugarHandler,
|
|
31
34
|
wallet_invokeKeyring: _invokeKeyring.invokeKeyringHandler,
|
|
32
35
|
snap_getClientStatus: _getClientStatus.getClientStatusHandler,
|
|
33
|
-
snap_getFile: _getFile.getFileHandler
|
|
36
|
+
snap_getFile: _getFile.getFileHandler,
|
|
37
|
+
snap_createInterface: _createInterface.createInterfaceHandler,
|
|
38
|
+
snap_updateInterface: _updateInterface.updateInterfaceHandler,
|
|
39
|
+
snap_getInterfaceState: _getInterfaceState.getInterfaceStateHandler
|
|
34
40
|
};
|
|
35
41
|
const handlers = Object.values(methodHandlers);
|
|
36
42
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/permitted/handlers.ts"],"sourcesContent":["import { getAllSnapsHandler } from './getAllSnaps';\nimport { getClientStatusHandler } from './getClientStatus';\nimport { getFileHandler } from './getFile';\nimport { getSnapsHandler } from './getSnaps';\nimport { invokeKeyringHandler } from './invokeKeyring';\nimport { invokeSnapSugarHandler } from './invokeSnapSugar';\nimport { requestSnapsHandler } from './requestSnaps';\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};\n/* eslint-enable @typescript-eslint/naming-convention */\n\nexport const handlers = Object.values(methodHandlers);\n"],"names":["methodHandlers","handlers","wallet_getAllSnaps","getAllSnapsHandler","wallet_getSnaps","getSnapsHandler","wallet_requestSnaps","requestSnapsHandler","wallet_invokeSnap","invokeSnapSugarHandler","wallet_invokeKeyring","invokeKeyringHandler","snap_getClientStatus","getClientStatusHandler","snap_getFile","getFileHandler","Object","values"],"mappings":";;;;;;;;;;;
|
|
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"],"names":["methodHandlers","handlers","wallet_getAllSnaps","getAllSnapsHandler","wallet_getSnaps","getSnapsHandler","wallet_requestSnaps","requestSnapsHandler","wallet_invokeSnap","invokeSnapSugarHandler","wallet_invokeKeyring","invokeKeyringHandler","snap_getClientStatus","getClientStatusHandler","snap_getFile","getFileHandler","snap_createInterface","createInterfaceHandler","snap_updateInterface","updateInterfaceHandler","snap_getInterfaceState","getInterfaceStateHandler","Object","values"],"mappings":";;;;;;;;;;;IAYaA,cAAc;eAAdA;;IAcAC,QAAQ;eAARA;;;iCA1B0B;6BACJ;iCACI;yBACR;mCACU;0BACT;+BACK;iCACE;8BACH;iCACG;AAGhC,MAAMD,iBAAiB;IAC5BE,oBAAoBC,+BAAkB;IACtCC,iBAAiBC,yBAAe;IAChCC,qBAAqBC,iCAAmB;IACxCC,mBAAmBC,uCAAsB;IACzCC,sBAAsBC,mCAAoB;IAC1CC,sBAAsBC,uCAAsB;IAC5CC,cAAcC,uBAAc;IAC5BC,sBAAsBC,uCAAsB;IAC5CC,sBAAsBC,uCAAsB;IAC5CC,wBAAwBC,2CAAwB;AAClD;AAGO,MAAMpB,WAAWqB,OAAOC,MAAM,CAACvB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/permitted/index.ts"],"sourcesContent":["import type { GetAllSnapsHooks } from './getAllSnaps';\nimport type { GetClientStatusHooks } from './getClientStatus';\nimport type { GetSnapsHooks } from './getSnaps';\nimport type { RequestSnapsHooks } from './requestSnaps';\n\nexport type PermittedRpcMethodHooks = GetAllSnapsHooks &\n GetClientStatusHooks &\n GetSnapsHooks &\n RequestSnapsHooks;\n\nexport * from './handlers';\nexport * from './middleware';\n"],"names":[],"mappings":";;;;
|
|
1
|
+
{"version":3,"sources":["../../../src/permitted/index.ts"],"sourcesContent":["import type { CreateInterfaceMethodHooks } from './createInterface';\nimport type { GetAllSnapsHooks } from './getAllSnaps';\nimport type { GetClientStatusHooks } from './getClientStatus';\nimport type { GetInterfaceStateMethodHooks } from './getInterfaceState';\nimport type { GetSnapsHooks } from './getSnaps';\nimport type { RequestSnapsHooks } from './requestSnaps';\nimport type { UpdateInterfaceMethodHooks } from './updateInterface';\n\nexport type PermittedRpcMethodHooks = GetAllSnapsHooks &\n GetClientStatusHooks &\n GetSnapsHooks &\n RequestSnapsHooks &\n CreateInterfaceMethodHooks &\n UpdateInterfaceMethodHooks &\n GetInterfaceStateMethodHooks;\n\nexport * from './handlers';\nexport * from './middleware';\n"],"names":[],"mappings":";;;;qBAgBc;qBACA"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "updateInterfaceHandler", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return updateInterfaceHandler;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _rpcerrors = require("@metamask/rpc-errors");
|
|
12
|
+
const _snapssdk = require("@metamask/snaps-sdk");
|
|
13
|
+
const _superstruct = require("superstruct");
|
|
14
|
+
const hookNames = {
|
|
15
|
+
updateInterface: true
|
|
16
|
+
};
|
|
17
|
+
const updateInterfaceHandler = {
|
|
18
|
+
methodNames: [
|
|
19
|
+
'snap_updateInterface'
|
|
20
|
+
],
|
|
21
|
+
implementation: getUpdateInterfaceImplementation,
|
|
22
|
+
hookNames
|
|
23
|
+
};
|
|
24
|
+
const UpdateInterfaceParametersStruct = (0, _superstruct.object)({
|
|
25
|
+
id: (0, _superstruct.string)(),
|
|
26
|
+
ui: _snapssdk.ComponentStruct
|
|
27
|
+
});
|
|
28
|
+
/**
|
|
29
|
+
* The `snap_updateInterface` method implementation.
|
|
30
|
+
*
|
|
31
|
+
* @param req - The JSON-RPC request object.
|
|
32
|
+
* @param res - The JSON-RPC response object.
|
|
33
|
+
* @param _next - The `json-rpc-engine` "next" callback. Not used by this
|
|
34
|
+
* function.
|
|
35
|
+
* @param end - The `json-rpc-engine` "end" callback.
|
|
36
|
+
* @param hooks - The RPC method hooks.
|
|
37
|
+
* @param hooks.updateInterface - The function to update the interface.
|
|
38
|
+
* @returns Nothing.
|
|
39
|
+
*/ async function getUpdateInterfaceImplementation(req, res, _next, end, { updateInterface }) {
|
|
40
|
+
const { params } = req;
|
|
41
|
+
try {
|
|
42
|
+
const validatedParams = getValidatedParams(params);
|
|
43
|
+
const { id, ui } = validatedParams;
|
|
44
|
+
await updateInterface(id, ui);
|
|
45
|
+
res.result = null;
|
|
46
|
+
} catch (error) {
|
|
47
|
+
return end(error);
|
|
48
|
+
}
|
|
49
|
+
return end();
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Validate the updateInterface method `params` and returns them cast to the correct
|
|
53
|
+
* type. Throws if validation fails.
|
|
54
|
+
*
|
|
55
|
+
* @param params - The unvalidated params object from the method request.
|
|
56
|
+
* @returns The validated updateInterface method parameter object.
|
|
57
|
+
*/ function getValidatedParams(params) {
|
|
58
|
+
try {
|
|
59
|
+
return (0, _superstruct.create)(params, UpdateInterfaceParametersStruct);
|
|
60
|
+
} catch (error) {
|
|
61
|
+
if (error instanceof _superstruct.StructError) {
|
|
62
|
+
throw _rpcerrors.rpcErrors.invalidParams({
|
|
63
|
+
message: `Invalid params: ${error.message}.`
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
/* istanbul ignore next */ throw _rpcerrors.rpcErrors.internal();
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
//# 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":["updateInterfaceHandler","hookNames","updateInterface","methodNames","implementation","getUpdateInterfaceImplementation","UpdateInterfaceParametersStruct","object","id","string","ui","ComponentStruct","req","res","_next","end","params","validatedParams","getValidatedParams","result","error","create","StructError","rpcErrors","invalidParams","message","internal"],"mappings":";;;;+BA4BaA;;;eAAAA;;;2BA1Ba;0BAOM;6BAGoB;AAIpD,MAAMC,YAA2D;IAC/DC,iBAAiB;AACnB;AAUO,MAAMF,yBAIT;IACFG,aAAa;QAAC;KAAuB;IACrCC,gBAAgBC;IAChBJ;AACF;AAEA,MAAMK,kCAAkCC,IAAAA,mBAAM,EAAC;IAC7CC,IAAIC,IAAAA,mBAAM;IACVC,IAAIC,yBAAe;AACrB;AAOA;;;;;;;;;;;CAWC,GACD,eAAeN,iCACbO,GAA8C,EAC9CC,GAAkD,EAClDC,KAAc,EACdC,GAA6B,EAC7B,EAAEb,eAAe,EAA8B;IAE/C,MAAM,EAAEc,MAAM,EAAE,GAAGJ;IAEnB,IAAI;QACF,MAAMK,kBAAkBC,mBAAmBF;QAE3C,MAAM,EAAER,EAAE,EAAEE,EAAE,EAAE,GAAGO;QAEnB,MAAMf,gBAAgBM,IAAIE;QAC1BG,IAAIM,MAAM,GAAG;IACf,EAAE,OAAOC,OAAO;QACd,OAAOL,IAAIK;IACb;IAEA,OAAOL;AACT;AAEA;;;;;;CAMC,GACD,SAASG,mBAAmBF,MAAe;IACzC,IAAI;QACF,OAAOK,IAAAA,mBAAM,EAACL,QAAQV;IACxB,EAAE,OAAOc,OAAO;QACd,IAAIA,iBAAiBE,wBAAW,EAAE;YAChC,MAAMC,oBAAS,CAACC,aAAa,CAAC;gBAC5BC,SAAS,CAAC,gBAAgB,EAAEL,MAAMK,OAAO,CAAC,CAAC,CAAC;YAC9C;QACF;QACA,wBAAwB,GACxB,MAAMF,oBAAS,CAACG,QAAQ;IAC1B;AACF"}
|