@metamask/snaps-controllers 2.0.2 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -1
- package/dist/cjs/fsm.js.map +1 -1
- package/dist/cjs/snaps/SnapController.js +7 -7
- 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/index.js +12 -4
- package/dist/cjs/snaps/endowments/index.js.map +1 -1
- package/dist/cjs/snaps/endowments/keyring.js +100 -0
- package/dist/cjs/snaps/endowments/keyring.js.map +1 -0
- package/dist/esm/fsm.js.map +1 -1
- package/dist/esm/snaps/SnapController.js +8 -8
- 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/index.js +10 -4
- package/dist/esm/snaps/endowments/index.js.map +1 -1
- package/dist/esm/snaps/endowments/keyring.js +91 -0
- package/dist/esm/snaps/endowments/keyring.js.map +1 -0
- package/dist/types/snaps/endowments/enum.d.ts +2 -1
- package/dist/types/snaps/endowments/index.d.ts +13 -0
- package/dist/types/snaps/endowments/keyring.d.ts +39 -0
- package/package.json +8 -8
|
@@ -8,6 +8,7 @@ export var SnapEndowments;
|
|
|
8
8
|
SnapEndowments["WebAssemblyAccess"] = 'endowment:webassembly';
|
|
9
9
|
SnapEndowments["NameLookup"] = 'endowment:name-lookup';
|
|
10
10
|
SnapEndowments["LifecycleHooks"] = 'endowment:lifecycle-hooks';
|
|
11
|
+
SnapEndowments["Keyring"] = 'endowment:keyring';
|
|
11
12
|
})(SnapEndowments || (SnapEndowments = {}));
|
|
12
13
|
|
|
13
14
|
//# 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}\n"],"names":["SnapEndowments","NetworkAccess","TransactionInsight","Cronjob","EthereumProvider","Rpc","WebAssemblyAccess","NameLookup","LifecycleHooks"],"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;
|
|
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;GATAT,mBAAAA"}
|
|
@@ -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 { getKeyringCaveatMapper, keyringCaveatSpecifications, keyringEndowmentBuilder } from './keyring';
|
|
4
5
|
import { lifecycleHooksEndowmentBuilder } from './lifecycle-hooks';
|
|
5
6
|
import { getNameLookupCaveatMapper, nameLookupCaveatSpecifications, nameLookupEndowmentBuilder } from './name-lookup';
|
|
6
7
|
import { networkAccessEndowmentBuilder } from './network-access';
|
|
@@ -15,19 +16,22 @@ export const endowmentPermissionBuilders = {
|
|
|
15
16
|
[rpcEndowmentBuilder.targetName]: rpcEndowmentBuilder,
|
|
16
17
|
[webAssemblyEndowmentBuilder.targetName]: webAssemblyEndowmentBuilder,
|
|
17
18
|
[nameLookupEndowmentBuilder.targetName]: nameLookupEndowmentBuilder,
|
|
18
|
-
[lifecycleHooksEndowmentBuilder.targetName]: lifecycleHooksEndowmentBuilder
|
|
19
|
+
[lifecycleHooksEndowmentBuilder.targetName]: lifecycleHooksEndowmentBuilder,
|
|
20
|
+
[keyringEndowmentBuilder.targetName]: keyringEndowmentBuilder
|
|
19
21
|
};
|
|
20
22
|
export const endowmentCaveatSpecifications = {
|
|
21
23
|
...cronjobCaveatSpecifications,
|
|
22
24
|
...transactionInsightCaveatSpecifications,
|
|
23
25
|
...rpcCaveatSpecifications,
|
|
24
|
-
...nameLookupCaveatSpecifications
|
|
26
|
+
...nameLookupCaveatSpecifications,
|
|
27
|
+
...keyringCaveatSpecifications
|
|
25
28
|
};
|
|
26
29
|
export const endowmentCaveatMappers = {
|
|
27
30
|
[cronjobEndowmentBuilder.targetName]: getCronjobCaveatMapper,
|
|
28
31
|
[transactionInsightEndowmentBuilder.targetName]: getTransactionInsightCaveatMapper,
|
|
29
32
|
[rpcEndowmentBuilder.targetName]: getRpcCaveatMapper,
|
|
30
|
-
[nameLookupEndowmentBuilder.targetName]: getNameLookupCaveatMapper
|
|
33
|
+
[nameLookupEndowmentBuilder.targetName]: getNameLookupCaveatMapper,
|
|
34
|
+
[keyringEndowmentBuilder.targetName]: getKeyringCaveatMapper
|
|
31
35
|
};
|
|
32
36
|
export const handlerEndowments = {
|
|
33
37
|
[HandlerType.OnRpcRequest]: rpcEndowmentBuilder.targetName,
|
|
@@ -35,11 +39,13 @@ export const handlerEndowments = {
|
|
|
35
39
|
[HandlerType.OnCronjob]: cronjobEndowmentBuilder.targetName,
|
|
36
40
|
[HandlerType.OnNameLookup]: nameLookupEndowmentBuilder.targetName,
|
|
37
41
|
[HandlerType.OnInstall]: lifecycleHooksEndowmentBuilder.targetName,
|
|
38
|
-
[HandlerType.OnUpdate]: lifecycleHooksEndowmentBuilder.targetName
|
|
42
|
+
[HandlerType.OnUpdate]: lifecycleHooksEndowmentBuilder.targetName,
|
|
43
|
+
[HandlerType.OnKeyringRequest]: keyringEndowmentBuilder.targetName
|
|
39
44
|
};
|
|
40
45
|
export * from './enum';
|
|
41
46
|
export { getRpcCaveatOrigins } from './rpc';
|
|
42
47
|
export { getTransactionOriginCaveat } from './transaction-insight';
|
|
43
48
|
export { getChainIdsCaveat } from './name-lookup';
|
|
49
|
+
export { getKeyringCaveatOrigins } from './keyring';
|
|
44
50
|
|
|
45
51
|
//# 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 { 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} as const;\n\nexport const endowmentCaveatSpecifications = {\n ...cronjobCaveatSpecifications,\n ...transactionInsightCaveatSpecifications,\n ...rpcCaveatSpecifications,\n ...nameLookupCaveatSpecifications,\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};\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};\n\nexport * from './enum';\nexport { getRpcCaveatOrigins } from './rpc';\nexport { getTransactionOriginCaveat } from './transaction-insight';\nexport { getChainIdsCaveat } from './name-lookup';\n"],"names":["HandlerType","cronjobCaveatSpecifications","cronjobEndowmentBuilder","getCronjobCaveatMapper","ethereumProviderEndowmentBuilder","lifecycleHooksEndowmentBuilder","getNameLookupCaveatMapper","nameLookupCaveatSpecifications","nameLookupEndowmentBuilder","networkAccessEndowmentBuilder","getRpcCaveatMapper","rpcCaveatSpecifications","rpcEndowmentBuilder","getTransactionInsightCaveatMapper","transactionInsightCaveatSpecifications","transactionInsightEndowmentBuilder","webAssemblyEndowmentBuilder","endowmentPermissionBuilders","targetName","endowmentCaveatSpecifications","endowmentCaveatMappers","handlerEndowments","OnRpcRequest","OnTransaction","OnCronjob","OnNameLookup","OnInstall","OnUpdate","getRpcCaveatOrigins","getTransactionOriginCaveat","getChainIdsCaveat"],"mappings":"AACA,SAASA,WAAW,QAAQ,wBAAwB;AAGpD,SACEC,2BAA2B,EAC3BC,uBAAuB,EACvBC,sBAAsB,QACjB,YAAY;AACnB,SAASC,gCAAgC,QAAQ,sBAAsB;AACvE,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 {\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,CAAChB,wBAAwBmB,UAAU,CAAC,EAAEnB;IACtC,CAACE,iCAAiCiB,UAAU,CAAC,EAC3CjB;IACF,CAACW,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;AACxC,EAAW;AAEX,OAAO,MAAMe,gCAAgC;IAC3C,GAAGrB,2BAA2B;IAC9B,GAAGgB,sCAAsC;IACzC,GAAGH,uBAAuB;IAC1B,GAAGJ,8BAA8B;IACjC,GAAGJ,2BAA2B;AAChC,EAAE;AAEF,OAAO,MAAMiB,yBAGT;IACF,CAACrB,wBAAwBmB,UAAU,CAAC,EAAElB;IACtC,CAACe,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,CAACxB,YAAYyB,YAAY,CAAC,EAAEV,oBAAoBM,UAAU;IAC1D,CAACrB,YAAY0B,aAAa,CAAC,EAAER,mCAAmCG,UAAU;IAC1E,CAACrB,YAAY2B,SAAS,CAAC,EAAEzB,wBAAwBmB,UAAU;IAC3D,CAACrB,YAAY4B,YAAY,CAAC,EAAEjB,2BAA2BU,UAAU;IACjE,CAACrB,YAAY6B,SAAS,CAAC,EAAErB,+BAA+Ba,UAAU;IAClE,CAACrB,YAAY8B,QAAQ,CAAC,EAAEtB,+BAA+Ba,UAAU;IACjE,CAACrB,YAAY+B,gBAAgB,CAAC,EAAExB,wBAAwBc,UAAU;AACpE,EAAE;AAEF,cAAc,SAAS;AACvB,SAASW,mBAAmB,QAAQ,QAAQ;AAC5C,SAASC,0BAA0B,QAAQ,wBAAwB;AACnE,SAASC,iBAAiB,QAAQ,gBAAgB;AAClD,SAASC,uBAAuB,QAAQ,YAAY"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { PermissionType, SubjectType } from '@metamask/permission-controller';
|
|
2
|
+
import { assertIsKeyringOrigins, SnapCaveatType } from '@metamask/snaps-utils';
|
|
3
|
+
import { assert, hasProperty, isPlainObject } from '@metamask/utils';
|
|
4
|
+
import { ethErrors } from 'eth-rpc-errors';
|
|
5
|
+
import { SnapEndowments } from './enum';
|
|
6
|
+
const permissionName = SnapEndowments.Keyring;
|
|
7
|
+
/**
|
|
8
|
+
* `endowment:keyring` returns nothing; it is intended to be used as a flag
|
|
9
|
+
* by the client to detect whether the snap has keyring capabilities.
|
|
10
|
+
*
|
|
11
|
+
* @param _builderOptions - Optional specification builder options.
|
|
12
|
+
* @returns The specification for the keyring endowment.
|
|
13
|
+
*/ const specificationBuilder = (_builderOptions)=>{
|
|
14
|
+
return {
|
|
15
|
+
permissionType: PermissionType.Endowment,
|
|
16
|
+
targetName: permissionName,
|
|
17
|
+
allowedCaveats: [
|
|
18
|
+
SnapCaveatType.KeyringOrigin
|
|
19
|
+
],
|
|
20
|
+
endowmentGetter: (_getterOptions)=>undefined,
|
|
21
|
+
validator: ({ caveats })=>{
|
|
22
|
+
if (caveats?.length !== 1 || caveats[0].type !== SnapCaveatType.KeyringOrigin) {
|
|
23
|
+
throw ethErrors.rpc.invalidParams({
|
|
24
|
+
message: `Expected a single "${SnapCaveatType.KeyringOrigin}" caveat.`
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
subjectTypes: [
|
|
29
|
+
SubjectType.Snap
|
|
30
|
+
]
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
export const keyringEndowmentBuilder = Object.freeze({
|
|
34
|
+
targetName: permissionName,
|
|
35
|
+
specificationBuilder
|
|
36
|
+
});
|
|
37
|
+
/**
|
|
38
|
+
* Validate the value of a caveat. This does not validate the type of the
|
|
39
|
+
* caveat itself, only the value of the caveat.
|
|
40
|
+
*
|
|
41
|
+
* @param caveat - The caveat to validate.
|
|
42
|
+
* @throws If the caveat value is invalid.
|
|
43
|
+
*/ function validateCaveatOrigins(caveat) {
|
|
44
|
+
if (!hasProperty(caveat, 'value') || !isPlainObject(caveat.value)) {
|
|
45
|
+
throw ethErrors.rpc.invalidParams({
|
|
46
|
+
message: 'Invalid keyring origins: Expected a plain object.'
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
const { value } = caveat;
|
|
50
|
+
assertIsKeyringOrigins(value, ethErrors.rpc.invalidParams);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Map a raw value from the `initialPermissions` to a caveat specification.
|
|
54
|
+
* Note that this function does not do any validation, that's handled by the
|
|
55
|
+
* PermissionsController when the permission is requested.
|
|
56
|
+
*
|
|
57
|
+
* @param value - The raw value from the `initialPermissions`.
|
|
58
|
+
* @returns The caveat specification.
|
|
59
|
+
*/ export function getKeyringCaveatMapper(value) {
|
|
60
|
+
return {
|
|
61
|
+
caveats: [
|
|
62
|
+
{
|
|
63
|
+
type: SnapCaveatType.KeyringOrigin,
|
|
64
|
+
value
|
|
65
|
+
}
|
|
66
|
+
]
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Getter function to get the {@link KeyringOrigins} caveat value from a
|
|
71
|
+
* permission.
|
|
72
|
+
*
|
|
73
|
+
* @param permission - The permission to get the caveat value from.
|
|
74
|
+
* @returns The caveat value.
|
|
75
|
+
* @throws If the permission does not have a valid {@link KeyringOrigins}
|
|
76
|
+
* caveat.
|
|
77
|
+
*/ export function getKeyringCaveatOrigins(permission) {
|
|
78
|
+
assert(permission?.caveats);
|
|
79
|
+
assert(permission.caveats.length === 1);
|
|
80
|
+
assert(permission.caveats[0].type === SnapCaveatType.KeyringOrigin);
|
|
81
|
+
const caveat = permission.caveats[0];
|
|
82
|
+
return caveat.value;
|
|
83
|
+
}
|
|
84
|
+
export const keyringCaveatSpecifications = {
|
|
85
|
+
[SnapCaveatType.KeyringOrigin]: Object.freeze({
|
|
86
|
+
type: SnapCaveatType.KeyringOrigin,
|
|
87
|
+
validator: (caveat)=>validateCaveatOrigins(caveat)
|
|
88
|
+
})
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
//# sourceMappingURL=keyring.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/snaps/endowments/keyring.ts"],"sourcesContent":["import type {\n Caveat,\n CaveatSpecificationConstraint,\n EndowmentGetterParams,\n PermissionConstraint,\n PermissionSpecificationBuilder,\n PermissionValidatorConstraint,\n ValidPermissionSpecification,\n} from '@metamask/permission-controller';\nimport { PermissionType, SubjectType } from '@metamask/permission-controller';\nimport type { KeyringOrigins } from '@metamask/snaps-utils';\nimport { assertIsKeyringOrigins, SnapCaveatType } from '@metamask/snaps-utils';\nimport type { Json, NonEmptyArray } from '@metamask/utils';\nimport { assert, hasProperty, isPlainObject } from '@metamask/utils';\nimport { ethErrors } from 'eth-rpc-errors';\n\nimport { SnapEndowments } from './enum';\n\nconst permissionName = SnapEndowments.Keyring;\n\ntype KeyringEndowmentSpecification = ValidPermissionSpecification<{\n permissionType: PermissionType.Endowment;\n targetName: typeof permissionName;\n endowmentGetter: (_options?: EndowmentGetterParams) => undefined;\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n validator: PermissionValidatorConstraint;\n subjectTypes: readonly SubjectType[];\n}>;\n\n/**\n * `endowment:keyring` returns nothing; it is intended to be used as a flag\n * by the client to detect whether the snap has keyring capabilities.\n *\n * @param _builderOptions - Optional specification builder options.\n * @returns The specification for the keyring endowment.\n */\nconst specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.Endowment,\n any,\n KeyringEndowmentSpecification\n> = (_builderOptions?: unknown) => {\n return {\n permissionType: PermissionType.Endowment,\n targetName: permissionName,\n allowedCaveats: [SnapCaveatType.KeyringOrigin],\n endowmentGetter: (_getterOptions?: EndowmentGetterParams) => undefined,\n validator: ({ caveats }) => {\n if (\n caveats?.length !== 1 ||\n caveats[0].type !== SnapCaveatType.KeyringOrigin\n ) {\n throw ethErrors.rpc.invalidParams({\n message: `Expected a single \"${SnapCaveatType.KeyringOrigin}\" caveat.`,\n });\n }\n },\n subjectTypes: [SubjectType.Snap],\n };\n};\n\nexport const keyringEndowmentBuilder = Object.freeze({\n targetName: permissionName,\n specificationBuilder,\n} as const);\n\n/**\n * Validate the value of a caveat. This does not validate the type of the\n * caveat itself, only the value of the caveat.\n *\n * @param caveat - The caveat to validate.\n * @throws If the caveat value is invalid.\n */\nfunction validateCaveatOrigins(caveat: Caveat<string, any>) {\n if (!hasProperty(caveat, 'value') || !isPlainObject(caveat.value)) {\n throw ethErrors.rpc.invalidParams({\n message: 'Invalid keyring origins: Expected a plain object.',\n });\n }\n\n const { value } = caveat;\n assertIsKeyringOrigins(value, ethErrors.rpc.invalidParams);\n}\n\n/**\n * Map a raw value from the `initialPermissions` to a caveat specification.\n * Note that this function does not do any validation, that's handled by the\n * PermissionsController when the permission is requested.\n *\n * @param value - The raw value from the `initialPermissions`.\n * @returns The caveat specification.\n */\nexport function getKeyringCaveatMapper(\n value: Json,\n): Pick<PermissionConstraint, 'caveats'> {\n return {\n caveats: [\n {\n type: SnapCaveatType.KeyringOrigin,\n value,\n },\n ],\n };\n}\n\n/**\n * Getter function to get the {@link KeyringOrigins} caveat value from a\n * permission.\n *\n * @param permission - The permission to get the caveat value from.\n * @returns The caveat value.\n * @throws If the permission does not have a valid {@link KeyringOrigins}\n * caveat.\n */\nexport function getKeyringCaveatOrigins(\n permission?: PermissionConstraint,\n): KeyringOrigins | null {\n assert(permission?.caveats);\n assert(permission.caveats.length === 1);\n assert(permission.caveats[0].type === SnapCaveatType.KeyringOrigin);\n\n const caveat = permission.caveats[0] as Caveat<string, KeyringOrigins>;\n return caveat.value;\n}\n\nexport const keyringCaveatSpecifications: Record<\n SnapCaveatType.KeyringOrigin,\n CaveatSpecificationConstraint\n> = {\n [SnapCaveatType.KeyringOrigin]: Object.freeze({\n type: SnapCaveatType.KeyringOrigin,\n validator: (caveat: Caveat<string, any>) => validateCaveatOrigins(caveat),\n }),\n};\n"],"names":["PermissionType","SubjectType","assertIsKeyringOrigins","SnapCaveatType","assert","hasProperty","isPlainObject","ethErrors","SnapEndowments","permissionName","Keyring","specificationBuilder","_builderOptions","permissionType","Endowment","targetName","allowedCaveats","KeyringOrigin","endowmentGetter","_getterOptions","undefined","validator","caveats","length","type","rpc","invalidParams","message","subjectTypes","Snap","keyringEndowmentBuilder","Object","freeze","validateCaveatOrigins","caveat","value","getKeyringCaveatMapper","getKeyringCaveatOrigins","permission","keyringCaveatSpecifications"],"mappings":"AASA,SAASA,cAAc,EAAEC,WAAW,QAAQ,kCAAkC;AAE9E,SAASC,sBAAsB,EAAEC,cAAc,QAAQ,wBAAwB;AAE/E,SAASC,MAAM,EAAEC,WAAW,EAAEC,aAAa,QAAQ,kBAAkB;AACrE,SAASC,SAAS,QAAQ,iBAAiB;AAE3C,SAASC,cAAc,QAAQ,SAAS;AAExC,MAAMC,iBAAiBD,eAAeE,OAAO;AAW7C;;;;;;CAMC,GACD,MAAMC,uBAIF,CAACC;IACH,OAAO;QACLC,gBAAgBb,eAAec,SAAS;QACxCC,YAAYN;QACZO,gBAAgB;YAACb,eAAec,aAAa;SAAC;QAC9CC,iBAAiB,CAACC,iBAA2CC;QAC7DC,WAAW,CAAC,EAAEC,OAAO,EAAE;YACrB,IACEA,SAASC,WAAW,KACpBD,OAAO,CAAC,EAAE,CAACE,IAAI,KAAKrB,eAAec,aAAa,EAChD;gBACA,MAAMV,UAAUkB,GAAG,CAACC,aAAa,CAAC;oBAChCC,SAAS,CAAC,mBAAmB,EAAExB,eAAec,aAAa,CAAC,SAAS,CAAC;gBACxE;YACF;QACF;QACAW,cAAc;YAAC3B,YAAY4B,IAAI;SAAC;IAClC;AACF;AAEA,OAAO,MAAMC,0BAA0BC,OAAOC,MAAM,CAAC;IACnDjB,YAAYN;IACZE;AACF,GAAY;AAEZ;;;;;;CAMC,GACD,SAASsB,sBAAsBC,MAA2B;IACxD,IAAI,CAAC7B,YAAY6B,QAAQ,YAAY,CAAC5B,cAAc4B,OAAOC,KAAK,GAAG;QACjE,MAAM5B,UAAUkB,GAAG,CAACC,aAAa,CAAC;YAChCC,SAAS;QACX;IACF;IAEA,MAAM,EAAEQ,KAAK,EAAE,GAAGD;IAClBhC,uBAAuBiC,OAAO5B,UAAUkB,GAAG,CAACC,aAAa;AAC3D;AAEA;;;;;;;CAOC,GACD,OAAO,SAASU,uBACdD,KAAW;IAEX,OAAO;QACLb,SAAS;YACP;gBACEE,MAAMrB,eAAec,aAAa;gBAClCkB;YACF;SACD;IACH;AACF;AAEA;;;;;;;;CAQC,GACD,OAAO,SAASE,wBACdC,UAAiC;IAEjClC,OAAOkC,YAAYhB;IACnBlB,OAAOkC,WAAWhB,OAAO,CAACC,MAAM,KAAK;IACrCnB,OAAOkC,WAAWhB,OAAO,CAAC,EAAE,CAACE,IAAI,KAAKrB,eAAec,aAAa;IAElE,MAAMiB,SAASI,WAAWhB,OAAO,CAAC,EAAE;IACpC,OAAOY,OAAOC,KAAK;AACrB;AAEA,OAAO,MAAMI,8BAGT;IACF,CAACpC,eAAec,aAAa,CAAC,EAAEc,OAAOC,MAAM,CAAC;QAC5CR,MAAMrB,eAAec,aAAa;QAClCI,WAAW,CAACa,SAAgCD,sBAAsBC;IACpE;AACF,EAAE"}
|
|
@@ -6,5 +6,6 @@ export declare enum SnapEndowments {
|
|
|
6
6
|
Rpc = "endowment:rpc",
|
|
7
7
|
WebAssemblyAccess = "endowment:webassembly",
|
|
8
8
|
NameLookup = "endowment:name-lookup",
|
|
9
|
-
LifecycleHooks = "endowment:lifecycle-hooks"
|
|
9
|
+
LifecycleHooks = "endowment:lifecycle-hooks",
|
|
10
|
+
Keyring = "endowment:keyring"
|
|
10
11
|
}
|
|
@@ -78,8 +78,20 @@ export declare const endowmentPermissionBuilders: {
|
|
|
78
78
|
allowedCaveats: readonly [string, ...string[]] | null;
|
|
79
79
|
}>;
|
|
80
80
|
}>;
|
|
81
|
+
readonly "endowment:keyring": Readonly<{
|
|
82
|
+
readonly targetName: import("./enum").SnapEndowments.Keyring;
|
|
83
|
+
readonly specificationBuilder: import("@metamask/permission-controller").PermissionSpecificationBuilder<import("@metamask/permission-controller").PermissionType.Endowment, any, {
|
|
84
|
+
permissionType: import("@metamask/permission-controller").PermissionType.Endowment;
|
|
85
|
+
targetName: import("./enum").SnapEndowments.Keyring;
|
|
86
|
+
endowmentGetter: (_options?: import("@metamask/permission-controller").EndowmentGetterParams | undefined) => undefined;
|
|
87
|
+
allowedCaveats: readonly [string, ...string[]] | null;
|
|
88
|
+
validator: import("@metamask/permission-controller").PermissionValidatorConstraint;
|
|
89
|
+
subjectTypes: readonly import("@metamask/permission-controller").SubjectType[];
|
|
90
|
+
}>;
|
|
91
|
+
}>;
|
|
81
92
|
};
|
|
82
93
|
export declare const endowmentCaveatSpecifications: {
|
|
94
|
+
keyringOrigin: import("@metamask/permission-controller").CaveatSpecificationConstraint;
|
|
83
95
|
chainIds: import("@metamask/permission-controller").CaveatSpecificationConstraint;
|
|
84
96
|
rpcOrigin: import("@metamask/permission-controller").CaveatSpecificationConstraint;
|
|
85
97
|
transactionOrigin: import("@metamask/permission-controller").CaveatSpecificationConstraint;
|
|
@@ -91,3 +103,4 @@ export * from './enum';
|
|
|
91
103
|
export { getRpcCaveatOrigins } from './rpc';
|
|
92
104
|
export { getTransactionOriginCaveat } from './transaction-insight';
|
|
93
105
|
export { getChainIdsCaveat } from './name-lookup';
|
|
106
|
+
export { getKeyringCaveatOrigins } from './keyring';
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { CaveatSpecificationConstraint, EndowmentGetterParams, PermissionConstraint, PermissionSpecificationBuilder, PermissionValidatorConstraint } from '@metamask/permission-controller';
|
|
2
|
+
import { PermissionType, SubjectType } from '@metamask/permission-controller';
|
|
3
|
+
import type { KeyringOrigins } from '@metamask/snaps-utils';
|
|
4
|
+
import { SnapCaveatType } from '@metamask/snaps-utils';
|
|
5
|
+
import type { Json, NonEmptyArray } from '@metamask/utils';
|
|
6
|
+
import { SnapEndowments } from './enum';
|
|
7
|
+
declare const permissionName = SnapEndowments.Keyring;
|
|
8
|
+
export declare const keyringEndowmentBuilder: Readonly<{
|
|
9
|
+
readonly targetName: SnapEndowments.Keyring;
|
|
10
|
+
readonly specificationBuilder: PermissionSpecificationBuilder<PermissionType.Endowment, any, {
|
|
11
|
+
permissionType: PermissionType.Endowment;
|
|
12
|
+
targetName: typeof permissionName;
|
|
13
|
+
endowmentGetter: (_options?: EndowmentGetterParams) => undefined;
|
|
14
|
+
allowedCaveats: Readonly<NonEmptyArray<string>> | null;
|
|
15
|
+
validator: PermissionValidatorConstraint;
|
|
16
|
+
subjectTypes: readonly SubjectType[];
|
|
17
|
+
}>;
|
|
18
|
+
}>;
|
|
19
|
+
/**
|
|
20
|
+
* Map a raw value from the `initialPermissions` to a caveat specification.
|
|
21
|
+
* Note that this function does not do any validation, that's handled by the
|
|
22
|
+
* PermissionsController when the permission is requested.
|
|
23
|
+
*
|
|
24
|
+
* @param value - The raw value from the `initialPermissions`.
|
|
25
|
+
* @returns The caveat specification.
|
|
26
|
+
*/
|
|
27
|
+
export declare function getKeyringCaveatMapper(value: Json): Pick<PermissionConstraint, 'caveats'>;
|
|
28
|
+
/**
|
|
29
|
+
* Getter function to get the {@link KeyringOrigins} caveat value from a
|
|
30
|
+
* permission.
|
|
31
|
+
*
|
|
32
|
+
* @param permission - The permission to get the caveat value from.
|
|
33
|
+
* @returns The caveat value.
|
|
34
|
+
* @throws If the permission does not have a valid {@link KeyringOrigins}
|
|
35
|
+
* caveat.
|
|
36
|
+
*/
|
|
37
|
+
export declare function getKeyringCaveatOrigins(permission?: PermissionConstraint): KeyringOrigins | null;
|
|
38
|
+
export declare const keyringCaveatSpecifications: Record<SnapCaveatType.KeyringOrigin, CaveatSpecificationConstraint>;
|
|
39
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask/snaps-controllers",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Controllers for MetaMask Snaps.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"test:prepare": "yarn mkdirp test/fixtures && ./scripts/generate-fixtures.sh",
|
|
24
24
|
"test": "rimraf coverage && yarn test:prepare && jest && yarn test:browser && yarn posttest",
|
|
25
25
|
"posttest": "ts-node scripts/coverage.ts && rimraf coverage/jest coverage/wdio",
|
|
26
|
-
"test:browser": "wdio run wdio.config.
|
|
26
|
+
"test:browser": "wdio run wdio.config.js",
|
|
27
27
|
"test:ci": "yarn test",
|
|
28
28
|
"build": "yarn build:source && yarn build:types",
|
|
29
29
|
"build:source": "yarn build:esm && yarn build:cjs",
|
|
@@ -46,12 +46,12 @@
|
|
|
46
46
|
"@metamask/approval-controller": "^3.5.0",
|
|
47
47
|
"@metamask/base-controller": "^3.2.0",
|
|
48
48
|
"@metamask/object-multiplex": "^1.2.0",
|
|
49
|
-
"@metamask/permission-controller": "^4.1.
|
|
49
|
+
"@metamask/permission-controller": "^4.1.2",
|
|
50
50
|
"@metamask/post-message-stream": "^7.0.0",
|
|
51
|
-
"@metamask/rpc-methods": "^
|
|
52
|
-
"@metamask/snaps-execution-environments": "^
|
|
51
|
+
"@metamask/rpc-methods": "^3.0.0",
|
|
52
|
+
"@metamask/snaps-execution-environments": "^3.0.0",
|
|
53
53
|
"@metamask/snaps-registry": "^2.0.0",
|
|
54
|
-
"@metamask/snaps-utils": "^
|
|
54
|
+
"@metamask/snaps-utils": "^3.0.0",
|
|
55
55
|
"@metamask/utils": "^8.1.0",
|
|
56
56
|
"@xstate/fsm": "^2.0.0",
|
|
57
57
|
"concat-stream": "^2.0.0",
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
"@esbuild-plugins/node-globals-polyfill": "^0.2.3",
|
|
69
69
|
"@esbuild-plugins/node-modules-polyfill": "^0.2.2",
|
|
70
70
|
"@lavamoat/allow-scripts": "^2.5.1",
|
|
71
|
-
"@metamask/auto-changelog": "^3.
|
|
71
|
+
"@metamask/auto-changelog": "^3.3.0",
|
|
72
72
|
"@metamask/eslint-config": "^12.1.0",
|
|
73
73
|
"@metamask/eslint-config-jest": "^12.1.0",
|
|
74
74
|
"@metamask/eslint-config-nodejs": "^12.1.0",
|
|
@@ -123,7 +123,7 @@
|
|
|
123
123
|
"webdriverio": "^8.15.9"
|
|
124
124
|
},
|
|
125
125
|
"engines": {
|
|
126
|
-
"node": ">=
|
|
126
|
+
"node": "^18.16 || >=20"
|
|
127
127
|
},
|
|
128
128
|
"publishConfig": {
|
|
129
129
|
"access": "public",
|