@metamask/snaps-controllers 3.1.1 → 3.3.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 +16 -1
- package/dist/cjs/snaps/SnapController.js +69 -17
- package/dist/cjs/snaps/SnapController.js.map +1 -1
- package/dist/cjs/snaps/endowments/enum.js +1 -0
- package/dist/cjs/snaps/endowments/enum.js.map +1 -1
- package/dist/cjs/snaps/endowments/home-page.js +37 -0
- package/dist/cjs/snaps/endowments/home-page.js.map +1 -0
- package/dist/cjs/snaps/endowments/index.js +5 -2
- package/dist/cjs/snaps/endowments/index.js.map +1 -1
- package/dist/cjs/utils.js +9 -0
- package/dist/cjs/utils.js.map +1 -1
- package/dist/esm/snaps/SnapController.js +72 -20
- package/dist/esm/snaps/SnapController.js.map +1 -1
- package/dist/esm/snaps/endowments/enum.js +1 -0
- package/dist/esm/snaps/endowments/enum.js.map +1 -1
- package/dist/esm/snaps/endowments/home-page.js +27 -0
- package/dist/esm/snaps/endowments/home-page.js.map +1 -0
- package/dist/esm/snaps/endowments/index.js +5 -2
- package/dist/esm/snaps/endowments/index.js.map +1 -1
- package/dist/esm/utils.js +12 -0
- package/dist/esm/utils.js.map +1 -1
- package/dist/types/snaps/SnapController.d.ts +10 -6
- package/dist/types/snaps/endowments/enum.d.ts +2 -1
- package/dist/types/snaps/endowments/home-page.d.ts +15 -0
- package/dist/types/snaps/endowments/index.d.ts +9 -0
- package/dist/types/utils.d.ts +9 -0
- package/package.json +6 -4
|
@@ -19,6 +19,7 @@ var SnapEndowments;
|
|
|
19
19
|
SnapEndowments["NameLookup"] = 'endowment:name-lookup';
|
|
20
20
|
SnapEndowments["LifecycleHooks"] = 'endowment:lifecycle-hooks';
|
|
21
21
|
SnapEndowments["Keyring"] = 'endowment:keyring';
|
|
22
|
+
SnapEndowments["HomePage"] = 'endowment:page-home';
|
|
22
23
|
})(SnapEndowments || (SnapEndowments = {}));
|
|
23
24
|
|
|
24
25
|
//# sourceMappingURL=enum.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/snaps/endowments/enum.ts"],"sourcesContent":["export enum SnapEndowments {\n NetworkAccess = 'endowment:network-access',\n TransactionInsight = 'endowment:transaction-insight',\n Cronjob = 'endowment:cronjob',\n EthereumProvider = 'endowment:ethereum-provider',\n Rpc = 'endowment:rpc',\n WebAssemblyAccess = 'endowment:webassembly',\n NameLookup = 'endowment:name-lookup',\n LifecycleHooks = 'endowment:lifecycle-hooks',\n Keyring = 'endowment:keyring',\n}\n"],"names":["SnapEndowments","NetworkAccess","TransactionInsight","Cronjob","EthereumProvider","Rpc","WebAssemblyAccess","NameLookup","LifecycleHooks","Keyring"],"mappings":";;;;;;;;;;IAAO;UAAKA,cAAc;IAAdA,eACVC,mBAAgB;IADND,eAEVE,wBAAqB;IAFXF,eAGVG,aAAU;IAHAH,eAIVI,sBAAmB;IAJTJ,eAKVK,SAAM;IALIL,eAMVM,uBAAoB;IANVN,eAOVO,gBAAa;IAPHP,eAQVQ,oBAAiB;IARPR,eASVS,aAAU;
|
|
1
|
+
{"version":3,"sources":["../../../../src/snaps/endowments/enum.ts"],"sourcesContent":["export enum SnapEndowments {\n NetworkAccess = 'endowment:network-access',\n TransactionInsight = 'endowment:transaction-insight',\n Cronjob = 'endowment:cronjob',\n EthereumProvider = 'endowment:ethereum-provider',\n Rpc = 'endowment:rpc',\n WebAssemblyAccess = 'endowment:webassembly',\n NameLookup = 'endowment:name-lookup',\n LifecycleHooks = 'endowment:lifecycle-hooks',\n Keyring = 'endowment:keyring',\n HomePage = 'endowment:page-home',\n}\n"],"names":["SnapEndowments","NetworkAccess","TransactionInsight","Cronjob","EthereumProvider","Rpc","WebAssemblyAccess","NameLookup","LifecycleHooks","Keyring","HomePage"],"mappings":";;;;;;;;;;IAAO;UAAKA,cAAc;IAAdA,eACVC,mBAAgB;IADND,eAEVE,wBAAqB;IAFXF,eAGVG,aAAU;IAHAH,eAIVI,sBAAmB;IAJTJ,eAKVK,SAAM;IALIL,eAMVM,uBAAoB;IANVN,eAOVO,gBAAa;IAPHP,eAQVQ,oBAAiB;IARPR,eASVS,aAAU;IATAT,eAUVU,cAAW;GAVDV,mBAAAA"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "homePageEndowmentBuilder", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return homePageEndowmentBuilder;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _permissioncontroller = require("@metamask/permission-controller");
|
|
12
|
+
const _enum = require("./enum");
|
|
13
|
+
const permissionName = _enum.SnapEndowments.HomePage;
|
|
14
|
+
/**
|
|
15
|
+
* `endowment:page-home` returns nothing; it is intended to be used as a
|
|
16
|
+
* flag by the snap controller to detect whether the snap has the capability to
|
|
17
|
+
* use the snap home page feature.
|
|
18
|
+
*
|
|
19
|
+
* @param _builderOptions - Optional specification builder options.
|
|
20
|
+
* @returns The specification for the `snap-pages` endowment.
|
|
21
|
+
*/ const specificationBuilder = (_builderOptions)=>{
|
|
22
|
+
return {
|
|
23
|
+
permissionType: _permissioncontroller.PermissionType.Endowment,
|
|
24
|
+
targetName: permissionName,
|
|
25
|
+
allowedCaveats: null,
|
|
26
|
+
endowmentGetter: (_getterOptions)=>undefined,
|
|
27
|
+
subjectTypes: [
|
|
28
|
+
_permissioncontroller.SubjectType.Snap
|
|
29
|
+
]
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
const homePageEndowmentBuilder = Object.freeze({
|
|
33
|
+
targetName: permissionName,
|
|
34
|
+
specificationBuilder
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
//# sourceMappingURL=home-page.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/snaps/endowments/home-page.ts"],"sourcesContent":["import type {\n PermissionSpecificationBuilder,\n EndowmentGetterParams,\n ValidPermissionSpecification,\n} from '@metamask/permission-controller';\nimport { PermissionType, SubjectType } from '@metamask/permission-controller';\nimport type { NonEmptyArray } from '@metamask/utils';\n\nimport { SnapEndowments } from './enum';\n\nconst permissionName = SnapEndowments.HomePage;\n\ntype HomePageEndowmentSpecification = ValidPermissionSpecification<{\n permissionType: PermissionType.Endowment;\n targetName: typeof permissionName;\n endowmentGetter: (_options?: EndowmentGetterParams) => undefined;\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n}>;\n\n/**\n * `endowment:page-home` returns nothing; it is intended to be used as a\n * flag by the snap controller to detect whether the snap has the capability to\n * use the snap home page feature.\n *\n * @param _builderOptions - Optional specification builder options.\n * @returns The specification for the `snap-pages` endowment.\n */\nconst specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.Endowment,\n any,\n HomePageEndowmentSpecification\n> = (_builderOptions?: unknown) => {\n return {\n permissionType: PermissionType.Endowment,\n targetName: permissionName,\n allowedCaveats: null,\n endowmentGetter: (_getterOptions?: EndowmentGetterParams) => undefined,\n subjectTypes: [SubjectType.Snap],\n };\n};\n\nexport const homePageEndowmentBuilder = Object.freeze({\n targetName: permissionName,\n specificationBuilder,\n} as const);\n"],"names":["homePageEndowmentBuilder","permissionName","SnapEndowments","HomePage","specificationBuilder","_builderOptions","permissionType","PermissionType","Endowment","targetName","allowedCaveats","endowmentGetter","_getterOptions","undefined","subjectTypes","SubjectType","Snap","Object","freeze"],"mappings":";;;;+BAyCaA;;;eAAAA;;;sCApC+B;sBAGb;AAE/B,MAAMC,iBAAiBC,oBAAc,CAACC,QAAQ;AAS9C;;;;;;;CAOC,GACD,MAAMC,uBAIF,CAACC;IACH,OAAO;QACLC,gBAAgBC,oCAAc,CAACC,SAAS;QACxCC,YAAYR;QACZS,gBAAgB;QAChBC,iBAAiB,CAACC,iBAA2CC;QAC7DC,cAAc;YAACC,iCAAW,CAACC,IAAI;SAAC;IAClC;AACF;AAEO,MAAMhB,2BAA2BiB,OAAOC,MAAM,CAAC;IACpDT,YAAYR;IACZG;AACF"}
|
|
@@ -37,6 +37,7 @@ _export(exports, {
|
|
|
37
37
|
const _snapsutils = require("@metamask/snaps-utils");
|
|
38
38
|
const _cronjob = require("./cronjob");
|
|
39
39
|
const _ethereumprovider = require("./ethereum-provider");
|
|
40
|
+
const _homepage = require("./home-page");
|
|
40
41
|
const _keyring = require("./keyring");
|
|
41
42
|
const _lifecyclehooks = require("./lifecycle-hooks");
|
|
42
43
|
const _namelookup = require("./name-lookup");
|
|
@@ -67,7 +68,8 @@ const endowmentPermissionBuilders = {
|
|
|
67
68
|
[_webassembly.webAssemblyEndowmentBuilder.targetName]: _webassembly.webAssemblyEndowmentBuilder,
|
|
68
69
|
[_namelookup.nameLookupEndowmentBuilder.targetName]: _namelookup.nameLookupEndowmentBuilder,
|
|
69
70
|
[_lifecyclehooks.lifecycleHooksEndowmentBuilder.targetName]: _lifecyclehooks.lifecycleHooksEndowmentBuilder,
|
|
70
|
-
[_keyring.keyringEndowmentBuilder.targetName]: _keyring.keyringEndowmentBuilder
|
|
71
|
+
[_keyring.keyringEndowmentBuilder.targetName]: _keyring.keyringEndowmentBuilder,
|
|
72
|
+
[_homepage.homePageEndowmentBuilder.targetName]: _homepage.homePageEndowmentBuilder
|
|
71
73
|
};
|
|
72
74
|
const endowmentCaveatSpecifications = {
|
|
73
75
|
..._cronjob.cronjobCaveatSpecifications,
|
|
@@ -90,7 +92,8 @@ const handlerEndowments = {
|
|
|
90
92
|
[_snapsutils.HandlerType.OnNameLookup]: _namelookup.nameLookupEndowmentBuilder.targetName,
|
|
91
93
|
[_snapsutils.HandlerType.OnInstall]: _lifecyclehooks.lifecycleHooksEndowmentBuilder.targetName,
|
|
92
94
|
[_snapsutils.HandlerType.OnUpdate]: _lifecyclehooks.lifecycleHooksEndowmentBuilder.targetName,
|
|
93
|
-
[_snapsutils.HandlerType.OnKeyringRequest]: _keyring.keyringEndowmentBuilder.targetName
|
|
95
|
+
[_snapsutils.HandlerType.OnKeyringRequest]: _keyring.keyringEndowmentBuilder.targetName,
|
|
96
|
+
[_snapsutils.HandlerType.OnHomePage]: _homepage.homePageEndowmentBuilder.targetName
|
|
94
97
|
};
|
|
95
98
|
|
|
96
99
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/snaps/endowments/index.ts"],"sourcesContent":["import type { PermissionConstraint } from '@metamask/permission-controller';\nimport { HandlerType } from '@metamask/snaps-utils';\nimport type { Json } from '@metamask/utils';\n\nimport {\n cronjobCaveatSpecifications,\n cronjobEndowmentBuilder,\n getCronjobCaveatMapper,\n} from './cronjob';\nimport { ethereumProviderEndowmentBuilder } from './ethereum-provider';\nimport {\n getKeyringCaveatMapper,\n keyringCaveatSpecifications,\n keyringEndowmentBuilder,\n} from './keyring';\nimport { lifecycleHooksEndowmentBuilder } from './lifecycle-hooks';\nimport {\n getNameLookupCaveatMapper,\n nameLookupCaveatSpecifications,\n nameLookupEndowmentBuilder,\n} from './name-lookup';\nimport { networkAccessEndowmentBuilder } from './network-access';\nimport {\n getRpcCaveatMapper,\n rpcCaveatSpecifications,\n rpcEndowmentBuilder,\n} from './rpc';\nimport {\n getTransactionInsightCaveatMapper,\n transactionInsightCaveatSpecifications,\n transactionInsightEndowmentBuilder,\n} from './transaction-insight';\nimport { webAssemblyEndowmentBuilder } from './web-assembly';\n\nexport const endowmentPermissionBuilders = {\n [networkAccessEndowmentBuilder.targetName]: networkAccessEndowmentBuilder,\n [transactionInsightEndowmentBuilder.targetName]:\n transactionInsightEndowmentBuilder,\n [cronjobEndowmentBuilder.targetName]: cronjobEndowmentBuilder,\n [ethereumProviderEndowmentBuilder.targetName]:\n ethereumProviderEndowmentBuilder,\n [rpcEndowmentBuilder.targetName]: rpcEndowmentBuilder,\n [webAssemblyEndowmentBuilder.targetName]: webAssemblyEndowmentBuilder,\n [nameLookupEndowmentBuilder.targetName]: nameLookupEndowmentBuilder,\n [lifecycleHooksEndowmentBuilder.targetName]: lifecycleHooksEndowmentBuilder,\n [keyringEndowmentBuilder.targetName]: keyringEndowmentBuilder,\n} as const;\n\nexport const endowmentCaveatSpecifications = {\n ...cronjobCaveatSpecifications,\n ...transactionInsightCaveatSpecifications,\n ...rpcCaveatSpecifications,\n ...nameLookupCaveatSpecifications,\n ...keyringCaveatSpecifications,\n};\n\nexport const endowmentCaveatMappers: Record<\n string,\n (value: Json) => Pick<PermissionConstraint, 'caveats'>\n> = {\n [cronjobEndowmentBuilder.targetName]: getCronjobCaveatMapper,\n [transactionInsightEndowmentBuilder.targetName]:\n getTransactionInsightCaveatMapper,\n [rpcEndowmentBuilder.targetName]: getRpcCaveatMapper,\n [nameLookupEndowmentBuilder.targetName]: getNameLookupCaveatMapper,\n [keyringEndowmentBuilder.targetName]: getKeyringCaveatMapper,\n};\n\nexport const handlerEndowments: Record<HandlerType, string> = {\n [HandlerType.OnRpcRequest]: rpcEndowmentBuilder.targetName,\n [HandlerType.OnTransaction]: transactionInsightEndowmentBuilder.targetName,\n [HandlerType.OnCronjob]: cronjobEndowmentBuilder.targetName,\n [HandlerType.OnNameLookup]: nameLookupEndowmentBuilder.targetName,\n [HandlerType.OnInstall]: lifecycleHooksEndowmentBuilder.targetName,\n [HandlerType.OnUpdate]: lifecycleHooksEndowmentBuilder.targetName,\n [HandlerType.OnKeyringRequest]: keyringEndowmentBuilder.targetName,\n};\n\nexport * from './enum';\nexport { getRpcCaveatOrigins } from './rpc';\nexport { getTransactionOriginCaveat } from './transaction-insight';\nexport { getChainIdsCaveat } from './name-lookup';\nexport { getKeyringCaveatOrigins } from './keyring';\n"],"names":["endowmentPermissionBuilders","endowmentCaveatSpecifications","endowmentCaveatMappers","handlerEndowments","getRpcCaveatOrigins","getTransactionOriginCaveat","getChainIdsCaveat","getKeyringCaveatOrigins","networkAccessEndowmentBuilder","targetName","transactionInsightEndowmentBuilder","cronjobEndowmentBuilder","ethereumProviderEndowmentBuilder","rpcEndowmentBuilder","webAssemblyEndowmentBuilder","nameLookupEndowmentBuilder","lifecycleHooksEndowmentBuilder","keyringEndowmentBuilder","cronjobCaveatSpecifications","transactionInsightCaveatSpecifications","rpcCaveatSpecifications","nameLookupCaveatSpecifications","keyringCaveatSpecifications","getCronjobCaveatMapper","getTransactionInsightCaveatMapper","getRpcCaveatMapper","getNameLookupCaveatMapper","getKeyringCaveatMapper","HandlerType","OnRpcRequest","OnTransaction","OnCronjob","OnNameLookup","OnInstall","OnUpdate","OnKeyringRequest"],"mappings":";;;;;;;;;;;
|
|
1
|
+
{"version":3,"sources":["../../../../src/snaps/endowments/index.ts"],"sourcesContent":["import type { PermissionConstraint } from '@metamask/permission-controller';\nimport { HandlerType } from '@metamask/snaps-utils';\nimport type { Json } from '@metamask/utils';\n\nimport {\n cronjobCaveatSpecifications,\n cronjobEndowmentBuilder,\n getCronjobCaveatMapper,\n} from './cronjob';\nimport { ethereumProviderEndowmentBuilder } from './ethereum-provider';\nimport { homePageEndowmentBuilder } from './home-page';\nimport {\n getKeyringCaveatMapper,\n keyringCaveatSpecifications,\n keyringEndowmentBuilder,\n} from './keyring';\nimport { lifecycleHooksEndowmentBuilder } from './lifecycle-hooks';\nimport {\n getNameLookupCaveatMapper,\n nameLookupCaveatSpecifications,\n nameLookupEndowmentBuilder,\n} from './name-lookup';\nimport { networkAccessEndowmentBuilder } from './network-access';\nimport {\n getRpcCaveatMapper,\n rpcCaveatSpecifications,\n rpcEndowmentBuilder,\n} from './rpc';\nimport {\n getTransactionInsightCaveatMapper,\n transactionInsightCaveatSpecifications,\n transactionInsightEndowmentBuilder,\n} from './transaction-insight';\nimport { webAssemblyEndowmentBuilder } from './web-assembly';\n\nexport const endowmentPermissionBuilders = {\n [networkAccessEndowmentBuilder.targetName]: networkAccessEndowmentBuilder,\n [transactionInsightEndowmentBuilder.targetName]:\n transactionInsightEndowmentBuilder,\n [cronjobEndowmentBuilder.targetName]: cronjobEndowmentBuilder,\n [ethereumProviderEndowmentBuilder.targetName]:\n ethereumProviderEndowmentBuilder,\n [rpcEndowmentBuilder.targetName]: rpcEndowmentBuilder,\n [webAssemblyEndowmentBuilder.targetName]: webAssemblyEndowmentBuilder,\n [nameLookupEndowmentBuilder.targetName]: nameLookupEndowmentBuilder,\n [lifecycleHooksEndowmentBuilder.targetName]: lifecycleHooksEndowmentBuilder,\n [keyringEndowmentBuilder.targetName]: keyringEndowmentBuilder,\n [homePageEndowmentBuilder.targetName]: homePageEndowmentBuilder,\n} as const;\n\nexport const endowmentCaveatSpecifications = {\n ...cronjobCaveatSpecifications,\n ...transactionInsightCaveatSpecifications,\n ...rpcCaveatSpecifications,\n ...nameLookupCaveatSpecifications,\n ...keyringCaveatSpecifications,\n};\n\nexport const endowmentCaveatMappers: Record<\n string,\n (value: Json) => Pick<PermissionConstraint, 'caveats'>\n> = {\n [cronjobEndowmentBuilder.targetName]: getCronjobCaveatMapper,\n [transactionInsightEndowmentBuilder.targetName]:\n getTransactionInsightCaveatMapper,\n [rpcEndowmentBuilder.targetName]: getRpcCaveatMapper,\n [nameLookupEndowmentBuilder.targetName]: getNameLookupCaveatMapper,\n [keyringEndowmentBuilder.targetName]: getKeyringCaveatMapper,\n};\n\nexport const handlerEndowments: Record<HandlerType, string> = {\n [HandlerType.OnRpcRequest]: rpcEndowmentBuilder.targetName,\n [HandlerType.OnTransaction]: transactionInsightEndowmentBuilder.targetName,\n [HandlerType.OnCronjob]: cronjobEndowmentBuilder.targetName,\n [HandlerType.OnNameLookup]: nameLookupEndowmentBuilder.targetName,\n [HandlerType.OnInstall]: lifecycleHooksEndowmentBuilder.targetName,\n [HandlerType.OnUpdate]: lifecycleHooksEndowmentBuilder.targetName,\n [HandlerType.OnKeyringRequest]: keyringEndowmentBuilder.targetName,\n [HandlerType.OnHomePage]: homePageEndowmentBuilder.targetName,\n};\n\nexport * from './enum';\nexport { getRpcCaveatOrigins } from './rpc';\nexport { getTransactionOriginCaveat } from './transaction-insight';\nexport { getChainIdsCaveat } from './name-lookup';\nexport { getKeyringCaveatOrigins } from './keyring';\n"],"names":["endowmentPermissionBuilders","endowmentCaveatSpecifications","endowmentCaveatMappers","handlerEndowments","getRpcCaveatOrigins","getTransactionOriginCaveat","getChainIdsCaveat","getKeyringCaveatOrigins","networkAccessEndowmentBuilder","targetName","transactionInsightEndowmentBuilder","cronjobEndowmentBuilder","ethereumProviderEndowmentBuilder","rpcEndowmentBuilder","webAssemblyEndowmentBuilder","nameLookupEndowmentBuilder","lifecycleHooksEndowmentBuilder","keyringEndowmentBuilder","homePageEndowmentBuilder","cronjobCaveatSpecifications","transactionInsightCaveatSpecifications","rpcCaveatSpecifications","nameLookupCaveatSpecifications","keyringCaveatSpecifications","getCronjobCaveatMapper","getTransactionInsightCaveatMapper","getRpcCaveatMapper","getNameLookupCaveatMapper","getKeyringCaveatMapper","HandlerType","OnRpcRequest","OnTransaction","OnCronjob","OnNameLookup","OnInstall","OnUpdate","OnKeyringRequest","OnHomePage"],"mappings":";;;;;;;;;;;IAmCaA,2BAA2B;eAA3BA;;IAeAC,6BAA6B;eAA7BA;;IAQAC,sBAAsB;eAAtBA;;IAYAC,iBAAiB;eAAjBA;;IAYJC,mBAAmB;eAAnBA,wBAAmB;;IACnBC,0BAA0B;eAA1BA,8CAA0B;;IAC1BC,iBAAiB;eAAjBA,6BAAiB;;IACjBC,uBAAuB;eAAvBA,gCAAuB;;;4BApFJ;yBAOrB;kCAC0C;0BACR;yBAKlC;gCACwC;4BAKxC;+BACuC;qBAKvC;oCAKA;6BACqC;qBAgD9B;;;;;;;;;;;;;;AA9CP,MAAMP,8BAA8B;IACzC,CAACQ,4CAA6B,CAACC,UAAU,CAAC,EAAED,4CAA6B;IACzE,CAACE,sDAAkC,CAACD,UAAU,CAAC,EAC7CC,sDAAkC;IACpC,CAACC,gCAAuB,CAACF,UAAU,CAAC,EAAEE,gCAAuB;IAC7D,CAACC,kDAAgC,CAACH,UAAU,CAAC,EAC3CG,kDAAgC;IAClC,CAACC,wBAAmB,CAACJ,UAAU,CAAC,EAAEI,wBAAmB;IACrD,CAACC,wCAA2B,CAACL,UAAU,CAAC,EAAEK,wCAA2B;IACrE,CAACC,sCAA0B,CAACN,UAAU,CAAC,EAAEM,sCAA0B;IACnE,CAACC,8CAA8B,CAACP,UAAU,CAAC,EAAEO,8CAA8B;IAC3E,CAACC,gCAAuB,CAACR,UAAU,CAAC,EAAEQ,gCAAuB;IAC7D,CAACC,kCAAwB,CAACT,UAAU,CAAC,EAAES,kCAAwB;AACjE;AAEO,MAAMjB,gCAAgC;IAC3C,GAAGkB,oCAA2B;IAC9B,GAAGC,0DAAsC;IACzC,GAAGC,4BAAuB;IAC1B,GAAGC,0CAA8B;IACjC,GAAGC,oCAA2B;AAChC;AAEO,MAAMrB,yBAGT;IACF,CAACS,gCAAuB,CAACF,UAAU,CAAC,EAAEe,+BAAsB;IAC5D,CAACd,sDAAkC,CAACD,UAAU,CAAC,EAC7CgB,qDAAiC;IACnC,CAACZ,wBAAmB,CAACJ,UAAU,CAAC,EAAEiB,uBAAkB;IACpD,CAACX,sCAA0B,CAACN,UAAU,CAAC,EAAEkB,qCAAyB;IAClE,CAACV,gCAAuB,CAACR,UAAU,CAAC,EAAEmB,+BAAsB;AAC9D;AAEO,MAAMzB,oBAAiD;IAC5D,CAAC0B,uBAAW,CAACC,YAAY,CAAC,EAAEjB,wBAAmB,CAACJ,UAAU;IAC1D,CAACoB,uBAAW,CAACE,aAAa,CAAC,EAAErB,sDAAkC,CAACD,UAAU;IAC1E,CAACoB,uBAAW,CAACG,SAAS,CAAC,EAAErB,gCAAuB,CAACF,UAAU;IAC3D,CAACoB,uBAAW,CAACI,YAAY,CAAC,EAAElB,sCAA0B,CAACN,UAAU;IACjE,CAACoB,uBAAW,CAACK,SAAS,CAAC,EAAElB,8CAA8B,CAACP,UAAU;IAClE,CAACoB,uBAAW,CAACM,QAAQ,CAAC,EAAEnB,8CAA8B,CAACP,UAAU;IACjE,CAACoB,uBAAW,CAACO,gBAAgB,CAAC,EAAEnB,gCAAuB,CAACR,UAAU;IAClE,CAACoB,uBAAW,CAACQ,UAAU,CAAC,EAAEnB,kCAAwB,CAACT,UAAU;AAC/D"}
|
package/dist/cjs/utils.js
CHANGED
|
@@ -23,6 +23,9 @@ _export(exports, {
|
|
|
23
23
|
},
|
|
24
24
|
withTimeout: function() {
|
|
25
25
|
return withTimeout;
|
|
26
|
+
},
|
|
27
|
+
getSnapFiles: function() {
|
|
28
|
+
return getSnapFiles;
|
|
26
29
|
}
|
|
27
30
|
});
|
|
28
31
|
const _Timer = require("./snaps/Timer");
|
|
@@ -66,5 +69,11 @@ async function withTimeout(promise, timerOrMs) {
|
|
|
66
69
|
delayPromise.cancel();
|
|
67
70
|
}
|
|
68
71
|
}
|
|
72
|
+
async function getSnapFiles(location, files) {
|
|
73
|
+
if (!files || files.length === 0) {
|
|
74
|
+
return [];
|
|
75
|
+
}
|
|
76
|
+
return await Promise.all(files.map(async (filePath)=>location.fetch(filePath)));
|
|
77
|
+
}
|
|
69
78
|
|
|
70
79
|
//# sourceMappingURL=utils.js.map
|
package/dist/cjs/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils.ts"],"sourcesContent":["import { Timer } from './snaps/Timer';\n\n/**\n * Takes two objects and does a Set Difference of them.\n * Set Difference is generally defined as follows:\n * ```\n * 𝑥 ∈ A ∖ B ⟺ 𝑥 ∈ A ∧ 𝑥 ∉ B\n * ```\n * Meaning that the returned object contains all properties of A expect those that also\n * appear in B. Notice that properties that appear in B, but not in A, have no effect.\n *\n * @see [Set Difference]{@link https://proofwiki.org/wiki/Definition:Set_Difference}\n * @param objectA - The object on which the difference is being calculated.\n * @param objectB - The object whose properties will be removed from objectA.\n * @returns The objectA without properties from objectB.\n */\nexport function setDiff<\n ObjectA extends Record<any, unknown>,\n ObjectB extends Record<any, unknown>,\n>(objectA: ObjectA, objectB: ObjectB): Diff<ObjectA, ObjectB> {\n return Object.entries(objectA).reduce<Record<any, unknown>>(\n (acc, [key, value]) => {\n if (!(key in objectB)) {\n acc[key] = value;\n }\n return acc;\n },\n {},\n ) as Diff<ObjectA, ObjectB>;\n}\n\n/**\n * A Promise that delays its return for a given amount of milliseconds.\n *\n * @param ms - Milliseconds to delay the execution for.\n * @param result - The result to return from the Promise after delay.\n * @returns A promise that is void if no result provided, result otherwise.\n * @template Result - The `result`.\n */\nexport function delay<Result = void>(\n ms: number,\n result?: Result,\n): Promise<Result> & { cancel: () => void } {\n return delayWithTimer(new Timer(ms), result);\n}\n\n/**\n * A Promise that delays it's return by using a pausable Timer.\n *\n * @param timer - Timer used to control the delay.\n * @param result - The result to return from the Promise after delay.\n * @returns A promise that is void if no result provided, result otherwise.\n * @template Result - The `result`.\n */\nexport function delayWithTimer<Result = void>(\n timer: Timer,\n result?: Result,\n): Promise<Result> & { cancel: () => void } {\n let rejectFunc: (reason: Error) => void;\n const promise: any = new Promise<Result>((resolve: any, reject) => {\n timer.start(() => {\n result === undefined ? resolve() : resolve(result);\n });\n rejectFunc = reject;\n });\n\n promise.cancel = () => {\n if (timer.status !== 'finished') {\n timer.cancel();\n rejectFunc(new Error('The delay has been canceled.'));\n }\n };\n return promise;\n}\n\n/*\n * We use a Symbol instead of rejecting the promise so that Errors thrown\n * by the main promise will propagate.\n */\nexport const hasTimedOut = Symbol(\n 'Used to check if the requested promise has timeout (see withTimeout)',\n);\n\n/**\n * Executes the given Promise, if the Timer expires before the Promise settles, we return earlier.\n *\n * NOTE:** The given Promise is not cancelled or interrupted, and will continue to execute uninterrupted. We will just discard its result if it does not complete before the timeout.\n *\n * @param promise - The promise that you want to execute.\n * @param timerOrMs - The timer controlling the timeout or a ms value.\n * @returns The resolved `PromiseValue`, or the hasTimedOut symbol if\n * returning early.\n * @template PromiseValue - The value of the Promise.\n */\nexport async function withTimeout<PromiseValue = void>(\n promise: Promise<PromiseValue>,\n timerOrMs: Timer | number,\n): Promise<PromiseValue | typeof hasTimedOut> {\n const timer =\n typeof timerOrMs === 'number' ? new Timer(timerOrMs) : timerOrMs;\n const delayPromise = delayWithTimer(timer, hasTimedOut);\n try {\n return await Promise.race([promise, delayPromise]);\n } finally {\n delayPromise.cancel();\n }\n}\n\n/**\n * Checks whether the type is composed of literal types\n *\n * @returns @type {true} if whole type is composed of literals, @type {false} if whole type is not literals, @type {boolean} if mixed\n * @example\n * ```\n * type t1 = IsLiteral<1 | 2 | \"asd\" | true>;\n * // t1 = true\n *\n * type t2 = IsLiteral<number | string>;\n * // t2 = false\n *\n * type t3 = IsLiteral<1 | string>;\n * // t3 = boolean\n *\n * const s = Symbol();\n * type t4 = IsLiteral<typeof s>;\n * // t4 = true\n *\n * type t5 = IsLiteral<symbol>\n * // t5 = false;\n * ```\n */\ntype IsLiteral<Type> = Type extends string | number | boolean | symbol\n ? Extract<string | number | boolean | symbol, Type> extends never\n ? true\n : false\n : false;\n\n/**\n * Returns all keys of an object, that are literal, as an union\n *\n * @example\n * ```\n * type t1 = _LiteralKeys<{a: number, b: 0, c: 'foo', d: string}>\n * // t1 = 'b' | 'c'\n * ```\n * @see [Literal types]{@link https://www.typescriptlang.org/docs/handbook/literal-types.html}\n */\ntype LiteralKeys<Type> = NonNullable<\n {\n [Key in keyof Type]: IsLiteral<Key> extends true ? Key : never;\n }[keyof Type]\n>;\n\n/**\n * Returns all keys of an object, that are not literal, as an union\n *\n * @example\n * ```\n * type t1 = _NonLiteralKeys<{a: number, b: 0, c: 'foo', d: string}>\n * // t1 = 'a' | 'd'\n * ```\n * @see [Literal types]{@link https://www.typescriptlang.org/docs/handbook/literal-types.html}\n */\ntype NonLiteralKeys<Type> = NonNullable<\n {\n [Key in keyof Type]: IsLiteral<Key> extends false ? Key : never;\n }[keyof Type]\n>;\n\n/**\n * A set difference of two objects based on their keys\n *\n * @example\n * ```\n * type t1 = Diff<{a: string, b: string}, {a: number}>\n * // t1 = {b: string};\n * type t2 = Diff<{a: string, 0: string}, Record<string, unknown>>;\n * // t2 = { a?: string, 0: string};\n * type t3 = Diff<{a: string, 0: string, 1: string}, Record<1 | string, unknown>>;\n * // t3 = {a?: string, 0: string}\n * ```\n * @see {@link setDiff} for the main use-case\n */\nexport type Diff<First, Second> = Omit<First, LiteralKeys<Second>> &\n Partial<Pick<First, Extract<keyof First, NonLiteralKeys<Second>>>>;\n\n/**\n * Makes every specified property of the specified object type mutable.\n *\n * @template Type - The object whose readonly properties to make mutable.\n * @template TargetKey - The property key(s) to make mutable.\n */\nexport type Mutable<\n Type extends Record<string, unknown>,\n TargetKey extends string,\n> = {\n -readonly [Key in keyof Pick<Type, TargetKey>]: Type[Key];\n} & {\n [Key in keyof Omit<Type, TargetKey>]: Type[Key];\n};\n"],"names":["setDiff","delay","delayWithTimer","hasTimedOut","withTimeout","objectA","objectB","Object","entries","reduce","acc","key","value","ms","result","Timer","timer","rejectFunc","promise","Promise","resolve","reject","start","undefined","cancel","status","Error","Symbol","timerOrMs","delayPromise","race"],"mappings":";;;;;;;;;;;
|
|
1
|
+
{"version":3,"sources":["../../src/utils.ts"],"sourcesContent":["import type { SnapLocation } from './snaps';\nimport { Timer } from './snaps/Timer';\n\n/**\n * Takes two objects and does a Set Difference of them.\n * Set Difference is generally defined as follows:\n * ```\n * 𝑥 ∈ A ∖ B ⟺ 𝑥 ∈ A ∧ 𝑥 ∉ B\n * ```\n * Meaning that the returned object contains all properties of A expect those that also\n * appear in B. Notice that properties that appear in B, but not in A, have no effect.\n *\n * @see [Set Difference]{@link https://proofwiki.org/wiki/Definition:Set_Difference}\n * @param objectA - The object on which the difference is being calculated.\n * @param objectB - The object whose properties will be removed from objectA.\n * @returns The objectA without properties from objectB.\n */\nexport function setDiff<\n ObjectA extends Record<any, unknown>,\n ObjectB extends Record<any, unknown>,\n>(objectA: ObjectA, objectB: ObjectB): Diff<ObjectA, ObjectB> {\n return Object.entries(objectA).reduce<Record<any, unknown>>(\n (acc, [key, value]) => {\n if (!(key in objectB)) {\n acc[key] = value;\n }\n return acc;\n },\n {},\n ) as Diff<ObjectA, ObjectB>;\n}\n\n/**\n * A Promise that delays its return for a given amount of milliseconds.\n *\n * @param ms - Milliseconds to delay the execution for.\n * @param result - The result to return from the Promise after delay.\n * @returns A promise that is void if no result provided, result otherwise.\n * @template Result - The `result`.\n */\nexport function delay<Result = void>(\n ms: number,\n result?: Result,\n): Promise<Result> & { cancel: () => void } {\n return delayWithTimer(new Timer(ms), result);\n}\n\n/**\n * A Promise that delays it's return by using a pausable Timer.\n *\n * @param timer - Timer used to control the delay.\n * @param result - The result to return from the Promise after delay.\n * @returns A promise that is void if no result provided, result otherwise.\n * @template Result - The `result`.\n */\nexport function delayWithTimer<Result = void>(\n timer: Timer,\n result?: Result,\n): Promise<Result> & { cancel: () => void } {\n let rejectFunc: (reason: Error) => void;\n const promise: any = new Promise<Result>((resolve: any, reject) => {\n timer.start(() => {\n result === undefined ? resolve() : resolve(result);\n });\n rejectFunc = reject;\n });\n\n promise.cancel = () => {\n if (timer.status !== 'finished') {\n timer.cancel();\n rejectFunc(new Error('The delay has been canceled.'));\n }\n };\n return promise;\n}\n\n/*\n * We use a Symbol instead of rejecting the promise so that Errors thrown\n * by the main promise will propagate.\n */\nexport const hasTimedOut = Symbol(\n 'Used to check if the requested promise has timeout (see withTimeout)',\n);\n\n/**\n * Executes the given Promise, if the Timer expires before the Promise settles, we return earlier.\n *\n * NOTE:** The given Promise is not cancelled or interrupted, and will continue to execute uninterrupted. We will just discard its result if it does not complete before the timeout.\n *\n * @param promise - The promise that you want to execute.\n * @param timerOrMs - The timer controlling the timeout or a ms value.\n * @returns The resolved `PromiseValue`, or the hasTimedOut symbol if\n * returning early.\n * @template PromiseValue - The value of the Promise.\n */\nexport async function withTimeout<PromiseValue = void>(\n promise: Promise<PromiseValue>,\n timerOrMs: Timer | number,\n): Promise<PromiseValue | typeof hasTimedOut> {\n const timer =\n typeof timerOrMs === 'number' ? new Timer(timerOrMs) : timerOrMs;\n const delayPromise = delayWithTimer(timer, hasTimedOut);\n try {\n return await Promise.race([promise, delayPromise]);\n } finally {\n delayPromise.cancel();\n }\n}\n\n/**\n * Checks whether the type is composed of literal types\n *\n * @returns @type {true} if whole type is composed of literals, @type {false} if whole type is not literals, @type {boolean} if mixed\n * @example\n * ```\n * type t1 = IsLiteral<1 | 2 | \"asd\" | true>;\n * // t1 = true\n *\n * type t2 = IsLiteral<number | string>;\n * // t2 = false\n *\n * type t3 = IsLiteral<1 | string>;\n * // t3 = boolean\n *\n * const s = Symbol();\n * type t4 = IsLiteral<typeof s>;\n * // t4 = true\n *\n * type t5 = IsLiteral<symbol>\n * // t5 = false;\n * ```\n */\ntype IsLiteral<Type> = Type extends string | number | boolean | symbol\n ? Extract<string | number | boolean | symbol, Type> extends never\n ? true\n : false\n : false;\n\n/**\n * Returns all keys of an object, that are literal, as an union\n *\n * @example\n * ```\n * type t1 = _LiteralKeys<{a: number, b: 0, c: 'foo', d: string}>\n * // t1 = 'b' | 'c'\n * ```\n * @see [Literal types]{@link https://www.typescriptlang.org/docs/handbook/literal-types.html}\n */\ntype LiteralKeys<Type> = NonNullable<\n {\n [Key in keyof Type]: IsLiteral<Key> extends true ? Key : never;\n }[keyof Type]\n>;\n\n/**\n * Returns all keys of an object, that are not literal, as an union\n *\n * @example\n * ```\n * type t1 = _NonLiteralKeys<{a: number, b: 0, c: 'foo', d: string}>\n * // t1 = 'a' | 'd'\n * ```\n * @see [Literal types]{@link https://www.typescriptlang.org/docs/handbook/literal-types.html}\n */\ntype NonLiteralKeys<Type> = NonNullable<\n {\n [Key in keyof Type]: IsLiteral<Key> extends false ? Key : never;\n }[keyof Type]\n>;\n\n/**\n * A set difference of two objects based on their keys\n *\n * @example\n * ```\n * type t1 = Diff<{a: string, b: string}, {a: number}>\n * // t1 = {b: string};\n * type t2 = Diff<{a: string, 0: string}, Record<string, unknown>>;\n * // t2 = { a?: string, 0: string};\n * type t3 = Diff<{a: string, 0: string, 1: string}, Record<1 | string, unknown>>;\n * // t3 = {a?: string, 0: string}\n * ```\n * @see {@link setDiff} for the main use-case\n */\nexport type Diff<First, Second> = Omit<First, LiteralKeys<Second>> &\n Partial<Pick<First, Extract<keyof First, NonLiteralKeys<Second>>>>;\n\n/**\n * Makes every specified property of the specified object type mutable.\n *\n * @template Type - The object whose readonly properties to make mutable.\n * @template TargetKey - The property key(s) to make mutable.\n */\nexport type Mutable<\n Type extends Record<string, unknown>,\n TargetKey extends string,\n> = {\n -readonly [Key in keyof Pick<Type, TargetKey>]: Type[Key];\n} & {\n [Key in keyof Omit<Type, TargetKey>]: Type[Key];\n};\n\n/**\n * Get all files in a Snap from an array of file paths.\n *\n * @param location - The location of the Snap.\n * @param files - The array of file paths.\n * @returns The array of files as {@link VirtualFile}s.\n */\nexport async function getSnapFiles(\n location: SnapLocation,\n files?: string[] | undefined,\n) {\n if (!files || files.length === 0) {\n return [];\n }\n\n return await Promise.all(\n files.map(async (filePath) => location.fetch(filePath)),\n );\n}\n"],"names":["setDiff","delay","delayWithTimer","hasTimedOut","withTimeout","getSnapFiles","objectA","objectB","Object","entries","reduce","acc","key","value","ms","result","Timer","timer","rejectFunc","promise","Promise","resolve","reject","start","undefined","cancel","status","Error","Symbol","timerOrMs","delayPromise","race","location","files","length","all","map","filePath","fetch"],"mappings":";;;;;;;;;;;IAiBgBA,OAAO;eAAPA;;IAuBAC,KAAK;eAALA;;IAeAC,cAAc;eAAdA;;IAyBHC,WAAW;eAAXA;;IAeSC,WAAW;eAAXA;;IAkHAC,YAAY;eAAZA;;;uBAhNA;AAgBf,SAASL,QAGdM,OAAgB,EAAEC,OAAgB;IAClC,OAAOC,OAAOC,OAAO,CAACH,SAASI,MAAM,CACnC,CAACC,KAAK,CAACC,KAAKC,MAAM;QAChB,IAAI,CAAED,CAAAA,OAAOL,OAAM,GAAI;YACrBI,GAAG,CAACC,IAAI,GAAGC;QACb;QACA,OAAOF;IACT,GACA,CAAC;AAEL;AAUO,SAASV,MACda,EAAU,EACVC,MAAe;IAEf,OAAOb,eAAe,IAAIc,YAAK,CAACF,KAAKC;AACvC;AAUO,SAASb,eACde,KAAY,EACZF,MAAe;IAEf,IAAIG;IACJ,MAAMC,UAAe,IAAIC,QAAgB,CAACC,SAAcC;QACtDL,MAAMM,KAAK,CAAC;YACVR,WAAWS,YAAYH,YAAYA,QAAQN;QAC7C;QACAG,aAAaI;IACf;IAEAH,QAAQM,MAAM,GAAG;QACf,IAAIR,MAAMS,MAAM,KAAK,YAAY;YAC/BT,MAAMQ,MAAM;YACZP,WAAW,IAAIS,MAAM;QACvB;IACF;IACA,OAAOR;AACT;AAMO,MAAMhB,cAAcyB,OACzB;AAcK,eAAexB,YACpBe,OAA8B,EAC9BU,SAAyB;IAEzB,MAAMZ,QACJ,OAAOY,cAAc,WAAW,IAAIb,YAAK,CAACa,aAAaA;IACzD,MAAMC,eAAe5B,eAAee,OAAOd;IAC3C,IAAI;QACF,OAAO,MAAMiB,QAAQW,IAAI,CAAC;YAACZ;YAASW;SAAa;IACnD,SAAU;QACRA,aAAaL,MAAM;IACrB;AACF;AAsGO,eAAepB,aACpB2B,QAAsB,EACtBC,KAA4B;IAE5B,IAAI,CAACA,SAASA,MAAMC,MAAM,KAAK,GAAG;QAChC,OAAO,EAAE;IACX;IAEA,OAAO,MAAMd,QAAQe,GAAG,CACtBF,MAAMG,GAAG,CAAC,OAAOC,WAAaL,SAASM,KAAK,CAACD;AAEjD"}
|
|
@@ -65,13 +65,14 @@ import { BaseControllerV2 as BaseController } from '@metamask/base-controller';
|
|
|
65
65
|
import { SubjectType } from '@metamask/permission-controller';
|
|
66
66
|
import { rpcErrors } from '@metamask/rpc-errors';
|
|
67
67
|
import { WALLET_SNAP_PERMISSION_KEY } from '@metamask/snaps-rpc-methods';
|
|
68
|
-
import {
|
|
69
|
-
import {
|
|
68
|
+
import { assertUILinksAreSafe } from '@metamask/snaps-ui';
|
|
69
|
+
import { assertIsSnapManifest, assertIsValidSnapId, AuxiliaryFileEncoding, DEFAULT_ENDOWMENTS, DEFAULT_REQUESTED_SNAP_VERSION, encodeAuxiliaryFile, getErrorMessage, HandlerType, isOriginAllowed, logError, normalizeRelative, OnTransactionResponseStruct, resolveVersionRange, SnapCaveatType, SnapStatus, SnapStatusEvents, validateFetchedSnap, unwrapError, OnHomePageResponseStruct, getValidatedLocalizationFiles } from '@metamask/snaps-utils';
|
|
70
|
+
import { assert, assertIsJsonRpcRequest, assertStruct, Duration, gtRange, gtVersion, hasProperty, inMilliseconds, isNonEmptyArray, isValidSemVerRange, satisfiesVersionRange, timeSince } from '@metamask/utils';
|
|
70
71
|
import { createMachine, interpret } from '@xstate/fsm';
|
|
71
72
|
import { nanoid } from 'nanoid';
|
|
72
73
|
import { forceStrict, validateMachine } from '../fsm';
|
|
73
74
|
import { log } from '../logging';
|
|
74
|
-
import { hasTimedOut, setDiff, withTimeout } from '../utils';
|
|
75
|
+
import { getSnapFiles, hasTimedOut, setDiff, withTimeout } from '../utils';
|
|
75
76
|
import { handlerEndowments, SnapEndowments } from './endowments';
|
|
76
77
|
import { getKeyringCaveatOrigins } from './endowments/keyring';
|
|
77
78
|
import { getRpcCaveatOrigins } from './endowments/rpc';
|
|
@@ -94,7 +95,8 @@ const TRUNCATED_SNAP_PROPERTIES = new Set([
|
|
|
94
95
|
]);
|
|
95
96
|
const defaultState = {
|
|
96
97
|
snaps: {},
|
|
97
|
-
snapStates: {}
|
|
98
|
+
snapStates: {},
|
|
99
|
+
unencryptedSnapStates: {}
|
|
98
100
|
};
|
|
99
101
|
/**
|
|
100
102
|
* Truncates the properties of a snap to only ones that are easily serializable.
|
|
@@ -166,7 +168,7 @@ _initializeStateMachine = /*#__PURE__*/ new WeakSet(), /**
|
|
|
166
168
|
*
|
|
167
169
|
* @param snapId - The id of the Snap whose message handler to get.
|
|
168
170
|
* @returns The RPC handler for the given snap.
|
|
169
|
-
*/ _getRpcRequestHandler = /*#__PURE__*/ new WeakSet(), _executeWithTimeout = /*#__PURE__*/ new WeakSet(), _recordSnapRpcRequestStart = /*#__PURE__*/ new WeakSet(), _recordSnapRpcRequestFinish = /*#__PURE__*/ new WeakSet(), /**
|
|
171
|
+
*/ _getRpcRequestHandler = /*#__PURE__*/ new WeakSet(), _triggerPhishingListUpdate = /*#__PURE__*/ new WeakSet(), _checkPhishingList = /*#__PURE__*/ new WeakSet(), _assertSnapRpcRequestResult = /*#__PURE__*/ new WeakSet(), _executeWithTimeout = /*#__PURE__*/ new WeakSet(), _recordSnapRpcRequestStart = /*#__PURE__*/ new WeakSet(), _recordSnapRpcRequestFinish = /*#__PURE__*/ new WeakSet(), /**
|
|
170
172
|
* Retrieves the rollback snapshot of a snap.
|
|
171
173
|
*
|
|
172
174
|
* @param snapId - The snap id.
|
|
@@ -380,9 +382,14 @@ _initializeStateMachine = /*#__PURE__*/ new WeakSet(), /**
|
|
|
380
382
|
*
|
|
381
383
|
* @param snapId - The id of the Snap whose state should be updated.
|
|
382
384
|
* @param newSnapState - The new state of the snap.
|
|
383
|
-
|
|
385
|
+
* @param encrypted - A flag to indicate whether to use encrypted storage or not.
|
|
386
|
+
*/ updateSnapState(snapId, newSnapState, encrypted) {
|
|
384
387
|
this.update((state)=>{
|
|
385
|
-
|
|
388
|
+
if (encrypted) {
|
|
389
|
+
state.snapStates[snapId] = newSnapState;
|
|
390
|
+
} else {
|
|
391
|
+
state.unencryptedSnapStates[snapId] = newSnapState;
|
|
392
|
+
}
|
|
386
393
|
});
|
|
387
394
|
}
|
|
388
395
|
/**
|
|
@@ -390,9 +397,14 @@ _initializeStateMachine = /*#__PURE__*/ new WeakSet(), /**
|
|
|
390
397
|
* This is distinct from the state MetaMask uses to manage snaps.
|
|
391
398
|
*
|
|
392
399
|
* @param snapId - The id of the Snap whose state should be cleared.
|
|
393
|
-
|
|
400
|
+
* @param encrypted - A flag to indicate whether to use encrypted storage or not.
|
|
401
|
+
*/ clearSnapState(snapId, encrypted) {
|
|
394
402
|
this.update((state)=>{
|
|
395
|
-
|
|
403
|
+
if (encrypted) {
|
|
404
|
+
state.snapStates[snapId] = null;
|
|
405
|
+
} else {
|
|
406
|
+
state.unencryptedSnapStates[snapId] = null;
|
|
407
|
+
}
|
|
396
408
|
});
|
|
397
409
|
}
|
|
398
410
|
/**
|
|
@@ -400,10 +412,10 @@ _initializeStateMachine = /*#__PURE__*/ new WeakSet(), /**
|
|
|
400
412
|
* This is distinct from the state MetaMask uses to manage snaps.
|
|
401
413
|
*
|
|
402
414
|
* @param snapId - The id of the Snap whose state to get.
|
|
403
|
-
* @
|
|
404
|
-
* @
|
|
405
|
-
*/
|
|
406
|
-
const state = this.state.snapStates[snapId];
|
|
415
|
+
* @param encrypted - A flag to indicate whether to use encrypted storage or not.
|
|
416
|
+
* @returns The requested snap state or null if no state exists.
|
|
417
|
+
*/ getSnapState(snapId, encrypted) {
|
|
418
|
+
const state = encrypted ? this.state.snapStates[snapId] : this.state.unencryptedSnapStates[snapId];
|
|
407
419
|
return state ?? null;
|
|
408
420
|
}
|
|
409
421
|
/**
|
|
@@ -920,6 +932,10 @@ _initializeStateMachine = /*#__PURE__*/ new WeakSet(), /**
|
|
|
920
932
|
persist: true,
|
|
921
933
|
anonymous: false
|
|
922
934
|
},
|
|
935
|
+
unencryptedSnapStates: {
|
|
936
|
+
persist: true,
|
|
937
|
+
anonymous: false
|
|
938
|
+
},
|
|
923
939
|
snaps: {
|
|
924
940
|
persist: (snaps)=>{
|
|
925
941
|
return Object.values(snaps)// We should not persist snaps that are in the installing state,
|
|
@@ -999,6 +1015,14 @@ _initializeStateMachine = /*#__PURE__*/ new WeakSet(), /**
|
|
|
999
1015
|
*/ _class_private_method_init(this, _fetchSnap);
|
|
1000
1016
|
_class_private_method_init(this, _validateSnapPermissions);
|
|
1001
1017
|
_class_private_method_init(this, _getRpcRequestHandler);
|
|
1018
|
+
_class_private_method_init(this, _triggerPhishingListUpdate);
|
|
1019
|
+
_class_private_method_init(this, _checkPhishingList);
|
|
1020
|
+
/**
|
|
1021
|
+
* Asserts that the returned result of a Snap RPC call is the expected shape.
|
|
1022
|
+
*
|
|
1023
|
+
* @param handlerType - The handler type of the RPC Request.
|
|
1024
|
+
* @param result - The result of the RPC request.
|
|
1025
|
+
*/ _class_private_method_init(this, _assertSnapRpcRequestResult);
|
|
1002
1026
|
/**
|
|
1003
1027
|
* Awaits the specified promise and rejects if the promise doesn't resolve
|
|
1004
1028
|
* before the timeout.
|
|
@@ -1191,11 +1215,11 @@ function initializeStateMachine() {
|
|
|
1191
1215
|
function registerMessageHandlers() {
|
|
1192
1216
|
this.messagingSystem.registerActionHandler(`${controllerName}:clearSnapState`, (...args)=>this.clearSnapState(...args));
|
|
1193
1217
|
this.messagingSystem.registerActionHandler(`${controllerName}:get`, (...args)=>this.get(...args));
|
|
1194
|
-
this.messagingSystem.registerActionHandler(`${controllerName}:getSnapState`,
|
|
1218
|
+
this.messagingSystem.registerActionHandler(`${controllerName}:getSnapState`, (...args)=>this.getSnapState(...args));
|
|
1195
1219
|
this.messagingSystem.registerActionHandler(`${controllerName}:handleRequest`, async (...args)=>this.handleRequest(...args));
|
|
1196
1220
|
this.messagingSystem.registerActionHandler(`${controllerName}:has`, (...args)=>this.has(...args));
|
|
1197
1221
|
this.messagingSystem.registerActionHandler(`${controllerName}:updateBlockedSnaps`, async ()=>this.updateBlockedSnaps());
|
|
1198
|
-
this.messagingSystem.registerActionHandler(`${controllerName}:updateSnapState`,
|
|
1222
|
+
this.messagingSystem.registerActionHandler(`${controllerName}:updateSnapState`, (...args)=>this.updateSnapState(...args));
|
|
1199
1223
|
this.messagingSystem.registerActionHandler(`${controllerName}:enable`, (...args)=>this.enableSnap(...args));
|
|
1200
1224
|
this.messagingSystem.registerActionHandler(`${controllerName}:disable`, async (...args)=>this.disableSnap(...args));
|
|
1201
1225
|
this.messagingSystem.registerActionHandler(`${controllerName}:remove`, async (...args)=>this.removeSnap(...args));
|
|
@@ -1404,7 +1428,7 @@ async function getEndowments(snapId) {
|
|
|
1404
1428
|
}
|
|
1405
1429
|
function set(args) {
|
|
1406
1430
|
const { id: snapId, origin, files, isUpdate = false } = args;
|
|
1407
|
-
const { manifest, sourceCode: sourceCodeFile, svgIcon, auxiliaryFiles: rawAuxiliaryFiles } = files;
|
|
1431
|
+
const { manifest, sourceCode: sourceCodeFile, svgIcon, auxiliaryFiles: rawAuxiliaryFiles, localizationFiles } = files;
|
|
1408
1432
|
assertIsSnapManifest(manifest.result);
|
|
1409
1433
|
const { version } = manifest.result;
|
|
1410
1434
|
const sourceCode = sourceCodeFile.toString();
|
|
@@ -1438,7 +1462,8 @@ function set(args) {
|
|
|
1438
1462
|
sourceCode,
|
|
1439
1463
|
version,
|
|
1440
1464
|
versionHistory,
|
|
1441
|
-
auxiliaryFiles
|
|
1465
|
+
auxiliaryFiles,
|
|
1466
|
+
localizationFiles: localizationFiles.map((file)=>file.result)
|
|
1442
1467
|
};
|
|
1443
1468
|
// If the snap was blocked, it isn't any longer
|
|
1444
1469
|
delete snap.blockInformation;
|
|
@@ -1466,12 +1491,15 @@ async function fetchSnap(snapId, location) {
|
|
|
1466
1491
|
const sourceCode = await location.fetch(manifest.result.source.location.npm.filePath);
|
|
1467
1492
|
const { iconPath } = manifest.result.source.location.npm;
|
|
1468
1493
|
const svgIcon = iconPath ? await location.fetch(iconPath) : undefined;
|
|
1469
|
-
const auxiliaryFiles =
|
|
1494
|
+
const auxiliaryFiles = await getSnapFiles(location, manifest.result.source.files);
|
|
1495
|
+
const localizationFiles = await getSnapFiles(location, manifest.result.source.locales);
|
|
1496
|
+
const validatedLocalizationFiles = getValidatedLocalizationFiles(localizationFiles);
|
|
1470
1497
|
const files = {
|
|
1471
1498
|
manifest,
|
|
1472
1499
|
sourceCode,
|
|
1473
1500
|
svgIcon,
|
|
1474
|
-
auxiliaryFiles
|
|
1501
|
+
auxiliaryFiles,
|
|
1502
|
+
localizationFiles: validatedLocalizationFiles
|
|
1475
1503
|
};
|
|
1476
1504
|
validateFetchedSnap(files);
|
|
1477
1505
|
return {
|
|
@@ -1540,7 +1568,7 @@ function getRpcRequestHandler(snapId) {
|
|
|
1540
1568
|
// This will either get the result or reject due to the timeout.
|
|
1541
1569
|
try {
|
|
1542
1570
|
const result = await _class_private_method_get(this, _executeWithTimeout, executeWithTimeout).call(this, handleRpcRequestPromise, timer);
|
|
1543
|
-
_class_private_method_get(this,
|
|
1571
|
+
await _class_private_method_get(this, _assertSnapRpcRequestResult, assertSnapRpcRequestResult).call(this, handlerType, result);
|
|
1544
1572
|
return result;
|
|
1545
1573
|
} catch (error) {
|
|
1546
1574
|
const [jsonRpcError, handled] = unwrapError(error);
|
|
@@ -1548,11 +1576,35 @@ function getRpcRequestHandler(snapId) {
|
|
|
1548
1576
|
await this.stopSnap(snapId, SnapStatusEvents.Crash);
|
|
1549
1577
|
}
|
|
1550
1578
|
throw jsonRpcError;
|
|
1579
|
+
} finally{
|
|
1580
|
+
_class_private_method_get(this, _recordSnapRpcRequestFinish, recordSnapRpcRequestFinish).call(this, snapId, request.id);
|
|
1551
1581
|
}
|
|
1552
1582
|
};
|
|
1553
1583
|
runtime.rpcHandler = rpcHandler;
|
|
1554
1584
|
return rpcHandler;
|
|
1555
1585
|
}
|
|
1586
|
+
async function triggerPhishingListUpdate() {
|
|
1587
|
+
return this.messagingSystem.call('PhishingController:maybeUpdateState');
|
|
1588
|
+
}
|
|
1589
|
+
function checkPhishingList(origin) {
|
|
1590
|
+
return this.messagingSystem.call('PhishingController:testOrigin', origin).result;
|
|
1591
|
+
}
|
|
1592
|
+
async function assertSnapRpcRequestResult(handlerType, result) {
|
|
1593
|
+
switch(handlerType){
|
|
1594
|
+
case HandlerType.OnTransaction:
|
|
1595
|
+
assertStruct(result, OnTransactionResponseStruct);
|
|
1596
|
+
await _class_private_method_get(this, _triggerPhishingListUpdate, triggerPhishingListUpdate).call(this);
|
|
1597
|
+
assertUILinksAreSafe(result.content, _class_private_method_get(this, _checkPhishingList, checkPhishingList).bind(this));
|
|
1598
|
+
break;
|
|
1599
|
+
case HandlerType.OnHomePage:
|
|
1600
|
+
assertStruct(result, OnHomePageResponseStruct);
|
|
1601
|
+
await _class_private_method_get(this, _triggerPhishingListUpdate, triggerPhishingListUpdate).call(this);
|
|
1602
|
+
assertUILinksAreSafe(result.content, _class_private_method_get(this, _checkPhishingList, checkPhishingList).bind(this));
|
|
1603
|
+
break;
|
|
1604
|
+
default:
|
|
1605
|
+
break;
|
|
1606
|
+
}
|
|
1607
|
+
}
|
|
1556
1608
|
async function executeWithTimeout(promise, timer) {
|
|
1557
1609
|
const result = await withTimeout(promise, timer ?? this.maxRequestTime);
|
|
1558
1610
|
if (result === hasTimedOut) {
|