@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
|
@@ -9,6 +9,7 @@ export var SnapEndowments;
|
|
|
9
9
|
SnapEndowments["NameLookup"] = 'endowment:name-lookup';
|
|
10
10
|
SnapEndowments["LifecycleHooks"] = 'endowment:lifecycle-hooks';
|
|
11
11
|
SnapEndowments["Keyring"] = 'endowment:keyring';
|
|
12
|
+
SnapEndowments["HomePage"] = 'endowment:page-home';
|
|
12
13
|
})(SnapEndowments || (SnapEndowments = {}));
|
|
13
14
|
|
|
14
15
|
//# 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":"WAAO;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":"WAAO;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,27 @@
|
|
|
1
|
+
import { PermissionType, SubjectType } from '@metamask/permission-controller';
|
|
2
|
+
import { SnapEndowments } from './enum';
|
|
3
|
+
const permissionName = SnapEndowments.HomePage;
|
|
4
|
+
/**
|
|
5
|
+
* `endowment:page-home` returns nothing; it is intended to be used as a
|
|
6
|
+
* flag by the snap controller to detect whether the snap has the capability to
|
|
7
|
+
* use the snap home page feature.
|
|
8
|
+
*
|
|
9
|
+
* @param _builderOptions - Optional specification builder options.
|
|
10
|
+
* @returns The specification for the `snap-pages` endowment.
|
|
11
|
+
*/ const specificationBuilder = (_builderOptions)=>{
|
|
12
|
+
return {
|
|
13
|
+
permissionType: PermissionType.Endowment,
|
|
14
|
+
targetName: permissionName,
|
|
15
|
+
allowedCaveats: null,
|
|
16
|
+
endowmentGetter: (_getterOptions)=>undefined,
|
|
17
|
+
subjectTypes: [
|
|
18
|
+
SubjectType.Snap
|
|
19
|
+
]
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
export const homePageEndowmentBuilder = Object.freeze({
|
|
23
|
+
targetName: permissionName,
|
|
24
|
+
specificationBuilder
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
//# 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":["PermissionType","SubjectType","SnapEndowments","permissionName","HomePage","specificationBuilder","_builderOptions","permissionType","Endowment","targetName","allowedCaveats","endowmentGetter","_getterOptions","undefined","subjectTypes","Snap","homePageEndowmentBuilder","Object","freeze"],"mappings":"AAKA,SAASA,cAAc,EAAEC,WAAW,QAAQ,kCAAkC;AAG9E,SAASC,cAAc,QAAQ,SAAS;AAExC,MAAMC,iBAAiBD,eAAeE,QAAQ;AAS9C;;;;;;;CAOC,GACD,MAAMC,uBAIF,CAACC;IACH,OAAO;QACLC,gBAAgBP,eAAeQ,SAAS;QACxCC,YAAYN;QACZO,gBAAgB;QAChBC,iBAAiB,CAACC,iBAA2CC;QAC7DC,cAAc;YAACb,YAAYc,IAAI;SAAC;IAClC;AACF;AAEA,OAAO,MAAMC,2BAA2BC,OAAOC,MAAM,CAAC;IACpDT,YAAYN;IACZE;AACF,GAAY"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { HandlerType } from '@metamask/snaps-utils';
|
|
2
2
|
import { cronjobCaveatSpecifications, cronjobEndowmentBuilder, getCronjobCaveatMapper } from './cronjob';
|
|
3
3
|
import { ethereumProviderEndowmentBuilder } from './ethereum-provider';
|
|
4
|
+
import { homePageEndowmentBuilder } from './home-page';
|
|
4
5
|
import { getKeyringCaveatMapper, keyringCaveatSpecifications, keyringEndowmentBuilder } from './keyring';
|
|
5
6
|
import { lifecycleHooksEndowmentBuilder } from './lifecycle-hooks';
|
|
6
7
|
import { getNameLookupCaveatMapper, nameLookupCaveatSpecifications, nameLookupEndowmentBuilder } from './name-lookup';
|
|
@@ -17,7 +18,8 @@ export const endowmentPermissionBuilders = {
|
|
|
17
18
|
[webAssemblyEndowmentBuilder.targetName]: webAssemblyEndowmentBuilder,
|
|
18
19
|
[nameLookupEndowmentBuilder.targetName]: nameLookupEndowmentBuilder,
|
|
19
20
|
[lifecycleHooksEndowmentBuilder.targetName]: lifecycleHooksEndowmentBuilder,
|
|
20
|
-
[keyringEndowmentBuilder.targetName]: keyringEndowmentBuilder
|
|
21
|
+
[keyringEndowmentBuilder.targetName]: keyringEndowmentBuilder,
|
|
22
|
+
[homePageEndowmentBuilder.targetName]: homePageEndowmentBuilder
|
|
21
23
|
};
|
|
22
24
|
export const endowmentCaveatSpecifications = {
|
|
23
25
|
...cronjobCaveatSpecifications,
|
|
@@ -40,7 +42,8 @@ export const handlerEndowments = {
|
|
|
40
42
|
[HandlerType.OnNameLookup]: nameLookupEndowmentBuilder.targetName,
|
|
41
43
|
[HandlerType.OnInstall]: lifecycleHooksEndowmentBuilder.targetName,
|
|
42
44
|
[HandlerType.OnUpdate]: lifecycleHooksEndowmentBuilder.targetName,
|
|
43
|
-
[HandlerType.OnKeyringRequest]: keyringEndowmentBuilder.targetName
|
|
45
|
+
[HandlerType.OnKeyringRequest]: keyringEndowmentBuilder.targetName,
|
|
46
|
+
[HandlerType.OnHomePage]: homePageEndowmentBuilder.targetName
|
|
44
47
|
};
|
|
45
48
|
export * from './enum';
|
|
46
49
|
export { getRpcCaveatOrigins } from './rpc';
|
|
@@ -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":["HandlerType","cronjobCaveatSpecifications","cronjobEndowmentBuilder","getCronjobCaveatMapper","ethereumProviderEndowmentBuilder","getKeyringCaveatMapper","keyringCaveatSpecifications","keyringEndowmentBuilder","lifecycleHooksEndowmentBuilder","getNameLookupCaveatMapper","nameLookupCaveatSpecifications","nameLookupEndowmentBuilder","networkAccessEndowmentBuilder","getRpcCaveatMapper","rpcCaveatSpecifications","rpcEndowmentBuilder","getTransactionInsightCaveatMapper","transactionInsightCaveatSpecifications","transactionInsightEndowmentBuilder","webAssemblyEndowmentBuilder","endowmentPermissionBuilders","targetName","endowmentCaveatSpecifications","endowmentCaveatMappers","handlerEndowments","OnRpcRequest","OnTransaction","OnCronjob","OnNameLookup","OnInstall","OnUpdate","OnKeyringRequest","getRpcCaveatOrigins","getTransactionOriginCaveat","getChainIdsCaveat","getKeyringCaveatOrigins"],"mappings":"AACA,SAASA,WAAW,QAAQ,wBAAwB;AAGpD,SACEC,2BAA2B,EAC3BC,uBAAuB,EACvBC,sBAAsB,QACjB,YAAY;AACnB,SAASC,gCAAgC,QAAQ,sBAAsB;AACvE,SACEC,sBAAsB,EACtBC,2BAA2B,EAC3BC,uBAAuB,QAClB,YAAY;AACnB,SAASC,8BAA8B,QAAQ,oBAAoB;AACnE,SACEC,yBAAyB,EACzBC,8BAA8B,EAC9BC,0BAA0B,QACrB,gBAAgB;AACvB,SAASC,6BAA6B,QAAQ,mBAAmB;AACjE,SACEC,kBAAkB,EAClBC,uBAAuB,EACvBC,mBAAmB,QACd,QAAQ;AACf,SACEC,iCAAiC,EACjCC,sCAAsC,EACtCC,kCAAkC,QAC7B,wBAAwB;AAC/B,SAASC,2BAA2B,QAAQ,iBAAiB;AAE7D,OAAO,MAAMC,8BAA8B;IACzC,CAACR,8BAA8BS,UAAU,CAAC,EAAET;IAC5C,CAACM,mCAAmCG,UAAU,CAAC,EAC7CH;IACF,
|
|
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":["HandlerType","cronjobCaveatSpecifications","cronjobEndowmentBuilder","getCronjobCaveatMapper","ethereumProviderEndowmentBuilder","homePageEndowmentBuilder","getKeyringCaveatMapper","keyringCaveatSpecifications","keyringEndowmentBuilder","lifecycleHooksEndowmentBuilder","getNameLookupCaveatMapper","nameLookupCaveatSpecifications","nameLookupEndowmentBuilder","networkAccessEndowmentBuilder","getRpcCaveatMapper","rpcCaveatSpecifications","rpcEndowmentBuilder","getTransactionInsightCaveatMapper","transactionInsightCaveatSpecifications","transactionInsightEndowmentBuilder","webAssemblyEndowmentBuilder","endowmentPermissionBuilders","targetName","endowmentCaveatSpecifications","endowmentCaveatMappers","handlerEndowments","OnRpcRequest","OnTransaction","OnCronjob","OnNameLookup","OnInstall","OnUpdate","OnKeyringRequest","OnHomePage","getRpcCaveatOrigins","getTransactionOriginCaveat","getChainIdsCaveat","getKeyringCaveatOrigins"],"mappings":"AACA,SAASA,WAAW,QAAQ,wBAAwB;AAGpD,SACEC,2BAA2B,EAC3BC,uBAAuB,EACvBC,sBAAsB,QACjB,YAAY;AACnB,SAASC,gCAAgC,QAAQ,sBAAsB;AACvE,SAASC,wBAAwB,QAAQ,cAAc;AACvD,SACEC,sBAAsB,EACtBC,2BAA2B,EAC3BC,uBAAuB,QAClB,YAAY;AACnB,SAASC,8BAA8B,QAAQ,oBAAoB;AACnE,SACEC,yBAAyB,EACzBC,8BAA8B,EAC9BC,0BAA0B,QACrB,gBAAgB;AACvB,SAASC,6BAA6B,QAAQ,mBAAmB;AACjE,SACEC,kBAAkB,EAClBC,uBAAuB,EACvBC,mBAAmB,QACd,QAAQ;AACf,SACEC,iCAAiC,EACjCC,sCAAsC,EACtCC,kCAAkC,QAC7B,wBAAwB;AAC/B,SAASC,2BAA2B,QAAQ,iBAAiB;AAE7D,OAAO,MAAMC,8BAA8B;IACzC,CAACR,8BAA8BS,UAAU,CAAC,EAAET;IAC5C,CAACM,mCAAmCG,UAAU,CAAC,EAC7CH;IACF,CAACjB,wBAAwBoB,UAAU,CAAC,EAAEpB;IACtC,CAACE,iCAAiCkB,UAAU,CAAC,EAC3ClB;IACF,CAACY,oBAAoBM,UAAU,CAAC,EAAEN;IAClC,CAACI,4BAA4BE,UAAU,CAAC,EAAEF;IAC1C,CAACR,2BAA2BU,UAAU,CAAC,EAAEV;IACzC,CAACH,+BAA+Ba,UAAU,CAAC,EAAEb;IAC7C,CAACD,wBAAwBc,UAAU,CAAC,EAAEd;IACtC,CAACH,yBAAyBiB,UAAU,CAAC,EAAEjB;AACzC,EAAW;AAEX,OAAO,MAAMkB,gCAAgC;IAC3C,GAAGtB,2BAA2B;IAC9B,GAAGiB,sCAAsC;IACzC,GAAGH,uBAAuB;IAC1B,GAAGJ,8BAA8B;IACjC,GAAGJ,2BAA2B;AAChC,EAAE;AAEF,OAAO,MAAMiB,yBAGT;IACF,CAACtB,wBAAwBoB,UAAU,CAAC,EAAEnB;IACtC,CAACgB,mCAAmCG,UAAU,CAAC,EAC7CL;IACF,CAACD,oBAAoBM,UAAU,CAAC,EAAER;IAClC,CAACF,2BAA2BU,UAAU,CAAC,EAAEZ;IACzC,CAACF,wBAAwBc,UAAU,CAAC,EAAEhB;AACxC,EAAE;AAEF,OAAO,MAAMmB,oBAAiD;IAC5D,CAACzB,YAAY0B,YAAY,CAAC,EAAEV,oBAAoBM,UAAU;IAC1D,CAACtB,YAAY2B,aAAa,CAAC,EAAER,mCAAmCG,UAAU;IAC1E,CAACtB,YAAY4B,SAAS,CAAC,EAAE1B,wBAAwBoB,UAAU;IAC3D,CAACtB,YAAY6B,YAAY,CAAC,EAAEjB,2BAA2BU,UAAU;IACjE,CAACtB,YAAY8B,SAAS,CAAC,EAAErB,+BAA+Ba,UAAU;IAClE,CAACtB,YAAY+B,QAAQ,CAAC,EAAEtB,+BAA+Ba,UAAU;IACjE,CAACtB,YAAYgC,gBAAgB,CAAC,EAAExB,wBAAwBc,UAAU;IAClE,CAACtB,YAAYiC,UAAU,CAAC,EAAE5B,yBAAyBiB,UAAU;AAC/D,EAAE;AAEF,cAAc,SAAS;AACvB,SAASY,mBAAmB,QAAQ,QAAQ;AAC5C,SAASC,0BAA0B,QAAQ,wBAAwB;AACnE,SAASC,iBAAiB,QAAQ,gBAAgB;AAClD,SAASC,uBAAuB,QAAQ,YAAY"}
|
package/dist/esm/utils.js
CHANGED
|
@@ -79,5 +79,17 @@ import { Timer } from './snaps/Timer';
|
|
|
79
79
|
delayPromise.cancel();
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
|
+
/**
|
|
83
|
+
* Get all files in a Snap from an array of file paths.
|
|
84
|
+
*
|
|
85
|
+
* @param location - The location of the Snap.
|
|
86
|
+
* @param files - The array of file paths.
|
|
87
|
+
* @returns The array of files as {@link VirtualFile}s.
|
|
88
|
+
*/ export async function getSnapFiles(location, files) {
|
|
89
|
+
if (!files || files.length === 0) {
|
|
90
|
+
return [];
|
|
91
|
+
}
|
|
92
|
+
return await Promise.all(files.map(async (filePath)=>location.fetch(filePath)));
|
|
93
|
+
}
|
|
82
94
|
|
|
83
95
|
//# sourceMappingURL=utils.js.map
|
package/dist/esm/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":["Timer","setDiff","objectA","objectB","Object","entries","reduce","acc","key","value","delay","ms","result","delayWithTimer","timer","rejectFunc","promise","Promise","resolve","reject","start","undefined","cancel","status","Error","hasTimedOut","Symbol","withTimeout","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":["Timer","setDiff","objectA","objectB","Object","entries","reduce","acc","key","value","delay","ms","result","delayWithTimer","timer","rejectFunc","promise","Promise","resolve","reject","start","undefined","cancel","status","Error","hasTimedOut","Symbol","withTimeout","timerOrMs","delayPromise","race","getSnapFiles","location","files","length","all","map","filePath","fetch"],"mappings":"AACA,SAASA,KAAK,QAAQ,gBAAgB;AAEtC;;;;;;;;;;;;;CAaC,GACD,OAAO,SAASC,QAGdC,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;AAEA;;;;;;;CAOC,GACD,OAAO,SAASG,MACdC,EAAU,EACVC,MAAe;IAEf,OAAOC,eAAe,IAAIb,MAAMW,KAAKC;AACvC;AAEA;;;;;;;CAOC,GACD,OAAO,SAASC,eACdC,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;AAEA;;;CAGC,GACD,OAAO,MAAMS,cAAcC,OACzB,wEACA;AAEF;;;;;;;;;;CAUC,GACD,OAAO,eAAeC,YACpBX,OAA8B,EAC9BY,SAAyB;IAEzB,MAAMd,QACJ,OAAOc,cAAc,WAAW,IAAI5B,MAAM4B,aAAaA;IACzD,MAAMC,eAAehB,eAAeC,OAAOW;IAC3C,IAAI;QACF,OAAO,MAAMR,QAAQa,IAAI,CAAC;YAACd;YAASa;SAAa;IACnD,SAAU;QACRA,aAAaP,MAAM;IACrB;AACF;AA+FA;;;;;;CAMC,GACD,OAAO,eAAeS,aACpBC,QAAsB,EACtBC,KAA4B;IAE5B,IAAI,CAACA,SAASA,MAAMC,MAAM,KAAK,GAAG;QAChC,OAAO,EAAE;IACX;IAEA,OAAO,MAAMjB,QAAQkB,GAAG,CACtBF,MAAMG,GAAG,CAAC,OAAOC,WAAaL,SAASM,KAAK,CAACD;AAEjD"}
|
|
@@ -2,6 +2,7 @@ import type { AddApprovalRequest, UpdateRequestState } from '@metamask/approval-
|
|
|
2
2
|
import type { RestrictedControllerMessenger } from '@metamask/base-controller';
|
|
3
3
|
import { BaseControllerV2 as BaseController } from '@metamask/base-controller';
|
|
4
4
|
import type { GetEndowments, GetPermissions, GetSubjectMetadata, GetSubjects, GrantPermissions, HasPermission, HasPermissions, RevokeAllPermissions, RevokePermissionForAllSubjects, RevokePermissions, UpdateCaveat } from '@metamask/permission-controller';
|
|
5
|
+
import type { MaybeUpdateState, TestOrigin } from '@metamask/phishing-controller';
|
|
5
6
|
import type { BlockReason } from '@metamask/snaps-registry';
|
|
6
7
|
import type { InstallSnapsResult, PersistedSnap, RequestedSnapPermissions, Snap, SnapId, SnapRpcHook, SnapRpcHookArgs, StatusContext, StatusEvents, StatusStates, TruncatedSnap, ValidatedSnapId } from '@metamask/snaps-utils';
|
|
7
8
|
import { AuxiliaryFileEncoding, SnapStatusEvents } from '@metamask/snaps-utils';
|
|
@@ -70,6 +71,7 @@ declare type StoredSnaps = Record<ValidatedSnapId, Snap>;
|
|
|
70
71
|
export declare type SnapControllerState = {
|
|
71
72
|
snaps: StoredSnaps;
|
|
72
73
|
snapStates: Record<ValidatedSnapId, string | null>;
|
|
74
|
+
unencryptedSnapStates: Record<ValidatedSnapId, string | null>;
|
|
73
75
|
};
|
|
74
76
|
export declare type PersistedSnapControllerState = SnapControllerState & {
|
|
75
77
|
snaps: Record<ValidatedSnapId, PersistedSnap>;
|
|
@@ -259,7 +261,7 @@ export declare type SnapDisabled = {
|
|
|
259
261
|
payload: [snap: TruncatedSnap];
|
|
260
262
|
};
|
|
261
263
|
export declare type SnapControllerEvents = SnapAdded | SnapBlocked | SnapInstalled | SnapUninstalled | SnapRemoved | SnapStateChange | SnapUnblocked | SnapUpdated | SnapRolledback | SnapTerminated | SnapEnabled | SnapDisabled;
|
|
262
|
-
export declare type AllowedActions = GetEndowments | GetPermissions | GetSubjects | GetSubjectMetadata | HasPermission | HasPermissions | RevokePermissions | RevokeAllPermissions | RevokePermissionForAllSubjects | GrantPermissions | AddApprovalRequest | HandleRpcRequestAction | ExecuteSnapAction | TerminateAllSnapsAction | TerminateSnapAction | UpdateCaveat | UpdateRequestState | GetResult | GetMetadata | Update | ResolveVersion;
|
|
264
|
+
export declare type AllowedActions = GetEndowments | GetPermissions | GetSubjects | GetSubjectMetadata | HasPermission | HasPermissions | RevokePermissions | RevokeAllPermissions | RevokePermissionForAllSubjects | GrantPermissions | AddApprovalRequest | HandleRpcRequestAction | ExecuteSnapAction | TerminateAllSnapsAction | TerminateSnapAction | UpdateCaveat | UpdateRequestState | GetResult | GetMetadata | Update | ResolveVersion | TestOrigin | MaybeUpdateState;
|
|
263
265
|
export declare type AllowedEvents = ExecutionServiceEvents | SnapInstalled | SnapUpdated;
|
|
264
266
|
declare type SnapControllerMessenger = RestrictedControllerMessenger<typeof controllerName, SnapControllerActions | AllowedActions, SnapControllerEvents | AllowedEvents, AllowedActions['type'], AllowedEvents['type']>;
|
|
265
267
|
declare type FeatureFlags = {
|
|
@@ -427,24 +429,26 @@ export declare class SnapController extends BaseController<string, SnapControlle
|
|
|
427
429
|
*
|
|
428
430
|
* @param snapId - The id of the Snap whose state should be updated.
|
|
429
431
|
* @param newSnapState - The new state of the snap.
|
|
432
|
+
* @param encrypted - A flag to indicate whether to use encrypted storage or not.
|
|
430
433
|
*/
|
|
431
|
-
updateSnapState(snapId: ValidatedSnapId, newSnapState: string):
|
|
434
|
+
updateSnapState(snapId: ValidatedSnapId, newSnapState: string, encrypted: boolean): void;
|
|
432
435
|
/**
|
|
433
436
|
* Clears the state of the snap with the given id.
|
|
434
437
|
* This is distinct from the state MetaMask uses to manage snaps.
|
|
435
438
|
*
|
|
436
439
|
* @param snapId - The id of the Snap whose state should be cleared.
|
|
440
|
+
* @param encrypted - A flag to indicate whether to use encrypted storage or not.
|
|
437
441
|
*/
|
|
438
|
-
clearSnapState(snapId: ValidatedSnapId): void;
|
|
442
|
+
clearSnapState(snapId: ValidatedSnapId, encrypted: boolean): void;
|
|
439
443
|
/**
|
|
440
444
|
* Gets the own state of the snap with the given id.
|
|
441
445
|
* This is distinct from the state MetaMask uses to manage snaps.
|
|
442
446
|
*
|
|
443
447
|
* @param snapId - The id of the Snap whose state to get.
|
|
444
|
-
* @
|
|
445
|
-
* @
|
|
448
|
+
* @param encrypted - A flag to indicate whether to use encrypted storage or not.
|
|
449
|
+
* @returns The requested snap state or null if no state exists.
|
|
446
450
|
*/
|
|
447
|
-
getSnapState(snapId: ValidatedSnapId):
|
|
451
|
+
getSnapState(snapId: ValidatedSnapId, encrypted: boolean): Json;
|
|
448
452
|
/**
|
|
449
453
|
* Gets a static auxiliary snap file in a chosen file encoding.
|
|
450
454
|
*
|
|
@@ -7,5 +7,6 @@ export declare enum SnapEndowments {
|
|
|
7
7
|
WebAssemblyAccess = "endowment:webassembly",
|
|
8
8
|
NameLookup = "endowment:name-lookup",
|
|
9
9
|
LifecycleHooks = "endowment:lifecycle-hooks",
|
|
10
|
-
Keyring = "endowment:keyring"
|
|
10
|
+
Keyring = "endowment:keyring",
|
|
11
|
+
HomePage = "endowment:page-home"
|
|
11
12
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { PermissionSpecificationBuilder, EndowmentGetterParams } from '@metamask/permission-controller';
|
|
2
|
+
import { PermissionType } from '@metamask/permission-controller';
|
|
3
|
+
import type { NonEmptyArray } from '@metamask/utils';
|
|
4
|
+
import { SnapEndowments } from './enum';
|
|
5
|
+
declare const permissionName = SnapEndowments.HomePage;
|
|
6
|
+
export declare const homePageEndowmentBuilder: Readonly<{
|
|
7
|
+
readonly targetName: SnapEndowments.HomePage;
|
|
8
|
+
readonly specificationBuilder: PermissionSpecificationBuilder<PermissionType.Endowment, any, {
|
|
9
|
+
permissionType: PermissionType.Endowment;
|
|
10
|
+
targetName: typeof permissionName;
|
|
11
|
+
endowmentGetter: (_options?: EndowmentGetterParams) => undefined;
|
|
12
|
+
allowedCaveats: Readonly<NonEmptyArray<string>> | null;
|
|
13
|
+
}>;
|
|
14
|
+
}>;
|
|
15
|
+
export {};
|
|
@@ -89,6 +89,15 @@ export declare const endowmentPermissionBuilders: {
|
|
|
89
89
|
subjectTypes: readonly import("@metamask/permission-controller").SubjectType[];
|
|
90
90
|
}>;
|
|
91
91
|
}>;
|
|
92
|
+
readonly "endowment:page-home": Readonly<{
|
|
93
|
+
readonly targetName: import("./enum").SnapEndowments.HomePage;
|
|
94
|
+
readonly specificationBuilder: import("@metamask/permission-controller").PermissionSpecificationBuilder<import("@metamask/permission-controller").PermissionType.Endowment, any, {
|
|
95
|
+
permissionType: import("@metamask/permission-controller").PermissionType.Endowment;
|
|
96
|
+
targetName: import("./enum").SnapEndowments.HomePage;
|
|
97
|
+
endowmentGetter: (_options?: import("@metamask/permission-controller").EndowmentGetterParams | undefined) => undefined;
|
|
98
|
+
allowedCaveats: readonly [string, ...string[]] | null;
|
|
99
|
+
}>;
|
|
100
|
+
}>;
|
|
92
101
|
};
|
|
93
102
|
export declare const endowmentCaveatSpecifications: {
|
|
94
103
|
keyringOrigin: import("@metamask/permission-controller").CaveatSpecificationConstraint;
|
package/dist/types/utils.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { SnapLocation } from './snaps';
|
|
1
2
|
import { Timer } from './snaps/Timer';
|
|
2
3
|
/**
|
|
3
4
|
* Takes two objects and does a Set Difference of them.
|
|
@@ -125,4 +126,12 @@ export declare type Mutable<Type extends Record<string, unknown>, TargetKey exte
|
|
|
125
126
|
} & {
|
|
126
127
|
[Key in keyof Omit<Type, TargetKey>]: Type[Key];
|
|
127
128
|
};
|
|
129
|
+
/**
|
|
130
|
+
* Get all files in a Snap from an array of file paths.
|
|
131
|
+
*
|
|
132
|
+
* @param location - The location of the Snap.
|
|
133
|
+
* @param files - The array of file paths.
|
|
134
|
+
* @returns The array of files as {@link VirtualFile}s.
|
|
135
|
+
*/
|
|
136
|
+
export declare function getSnapFiles(location: SnapLocation, files?: string[] | undefined): Promise<import("@metamask/snaps-utils").VirtualFile<unknown>[]>;
|
|
128
137
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask/snaps-controllers",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.0",
|
|
4
4
|
"description": "Controllers for MetaMask Snaps.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -47,11 +47,13 @@
|
|
|
47
47
|
"@metamask/json-rpc-engine": "^7.1.1",
|
|
48
48
|
"@metamask/object-multiplex": "^1.2.0",
|
|
49
49
|
"@metamask/permission-controller": "^5.0.0",
|
|
50
|
+
"@metamask/phishing-controller": "^7.0.0",
|
|
50
51
|
"@metamask/post-message-stream": "^7.0.0",
|
|
51
52
|
"@metamask/rpc-errors": "^6.1.0",
|
|
52
53
|
"@metamask/snaps-registry": "^2.1.0",
|
|
53
|
-
"@metamask/snaps-rpc-methods": "^3.
|
|
54
|
-
"@metamask/snaps-
|
|
54
|
+
"@metamask/snaps-rpc-methods": "^3.3.0",
|
|
55
|
+
"@metamask/snaps-ui": "^3.1.0",
|
|
56
|
+
"@metamask/snaps-utils": "^3.3.0",
|
|
55
57
|
"@metamask/utils": "^8.1.0",
|
|
56
58
|
"@xstate/fsm": "^2.0.0",
|
|
57
59
|
"concat-stream": "^2.0.0",
|
|
@@ -122,7 +124,7 @@
|
|
|
122
124
|
"webdriverio": "^8.19.0"
|
|
123
125
|
},
|
|
124
126
|
"peerDependencies": {
|
|
125
|
-
"@metamask/snaps-execution-environments": "^3.
|
|
127
|
+
"@metamask/snaps-execution-environments": "^3.2.0"
|
|
126
128
|
},
|
|
127
129
|
"peerDependenciesMeta": {
|
|
128
130
|
"@metamask/snaps-execution-environments": {
|