@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.
@@ -18,6 +18,7 @@ var SnapEndowments;
18
18
  SnapEndowments["WebAssemblyAccess"] = 'endowment:webassembly';
19
19
  SnapEndowments["NameLookup"] = 'endowment:name-lookup';
20
20
  SnapEndowments["LifecycleHooks"] = 'endowment:lifecycle-hooks';
21
+ SnapEndowments["Keyring"] = 'endowment:keyring';
21
22
  })(SnapEndowments || (SnapEndowments = {}));
22
23
 
23
24
  //# 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":";;;;;;;;;;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;GARPR,mBAAAA"}
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;GATAT,mBAAAA"}
@@ -29,11 +29,15 @@ _export(exports, {
29
29
  },
30
30
  getChainIdsCaveat: function() {
31
31
  return _namelookup.getChainIdsCaveat;
32
+ },
33
+ getKeyringCaveatOrigins: function() {
34
+ return _keyring.getKeyringCaveatOrigins;
32
35
  }
33
36
  });
34
37
  const _snapsutils = require("@metamask/snaps-utils");
35
38
  const _cronjob = require("./cronjob");
36
39
  const _ethereumprovider = require("./ethereum-provider");
40
+ const _keyring = require("./keyring");
37
41
  const _lifecyclehooks = require("./lifecycle-hooks");
38
42
  const _namelookup = require("./name-lookup");
39
43
  const _networkaccess = require("./network-access");
@@ -62,19 +66,22 @@ const endowmentPermissionBuilders = {
62
66
  [_rpc.rpcEndowmentBuilder.targetName]: _rpc.rpcEndowmentBuilder,
63
67
  [_webassembly.webAssemblyEndowmentBuilder.targetName]: _webassembly.webAssemblyEndowmentBuilder,
64
68
  [_namelookup.nameLookupEndowmentBuilder.targetName]: _namelookup.nameLookupEndowmentBuilder,
65
- [_lifecyclehooks.lifecycleHooksEndowmentBuilder.targetName]: _lifecyclehooks.lifecycleHooksEndowmentBuilder
69
+ [_lifecyclehooks.lifecycleHooksEndowmentBuilder.targetName]: _lifecyclehooks.lifecycleHooksEndowmentBuilder,
70
+ [_keyring.keyringEndowmentBuilder.targetName]: _keyring.keyringEndowmentBuilder
66
71
  };
67
72
  const endowmentCaveatSpecifications = {
68
73
  ..._cronjob.cronjobCaveatSpecifications,
69
74
  ..._transactioninsight.transactionInsightCaveatSpecifications,
70
75
  ..._rpc.rpcCaveatSpecifications,
71
- ..._namelookup.nameLookupCaveatSpecifications
76
+ ..._namelookup.nameLookupCaveatSpecifications,
77
+ ..._keyring.keyringCaveatSpecifications
72
78
  };
73
79
  const endowmentCaveatMappers = {
74
80
  [_cronjob.cronjobEndowmentBuilder.targetName]: _cronjob.getCronjobCaveatMapper,
75
81
  [_transactioninsight.transactionInsightEndowmentBuilder.targetName]: _transactioninsight.getTransactionInsightCaveatMapper,
76
82
  [_rpc.rpcEndowmentBuilder.targetName]: _rpc.getRpcCaveatMapper,
77
- [_namelookup.nameLookupEndowmentBuilder.targetName]: _namelookup.getNameLookupCaveatMapper
83
+ [_namelookup.nameLookupEndowmentBuilder.targetName]: _namelookup.getNameLookupCaveatMapper,
84
+ [_keyring.keyringEndowmentBuilder.targetName]: _keyring.getKeyringCaveatMapper
78
85
  };
79
86
  const handlerEndowments = {
80
87
  [_snapsutils.HandlerType.OnRpcRequest]: _rpc.rpcEndowmentBuilder.targetName,
@@ -82,7 +89,8 @@ const handlerEndowments = {
82
89
  [_snapsutils.HandlerType.OnCronjob]: _cronjob.cronjobEndowmentBuilder.targetName,
83
90
  [_snapsutils.HandlerType.OnNameLookup]: _namelookup.nameLookupEndowmentBuilder.targetName,
84
91
  [_snapsutils.HandlerType.OnInstall]: _lifecyclehooks.lifecycleHooksEndowmentBuilder.targetName,
85
- [_snapsutils.HandlerType.OnUpdate]: _lifecyclehooks.lifecycleHooksEndowmentBuilder.targetName
92
+ [_snapsutils.HandlerType.OnUpdate]: _lifecyclehooks.lifecycleHooksEndowmentBuilder.targetName,
93
+ [_snapsutils.HandlerType.OnKeyringRequest]: _keyring.keyringEndowmentBuilder.targetName
86
94
  };
87
95
 
88
96
  //# 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":["endowmentPermissionBuilders","endowmentCaveatSpecifications","endowmentCaveatMappers","handlerEndowments","getRpcCaveatOrigins","getTransactionOriginCaveat","getChainIdsCaveat","networkAccessEndowmentBuilder","targetName","transactionInsightEndowmentBuilder","cronjobEndowmentBuilder","ethereumProviderEndowmentBuilder","rpcEndowmentBuilder","webAssemblyEndowmentBuilder","nameLookupEndowmentBuilder","lifecycleHooksEndowmentBuilder","cronjobCaveatSpecifications","transactionInsightCaveatSpecifications","rpcCaveatSpecifications","nameLookupCaveatSpecifications","getCronjobCaveatMapper","getTransactionInsightCaveatMapper","getRpcCaveatMapper","getNameLookupCaveatMapper","HandlerType","OnRpcRequest","OnTransaction","OnCronjob","OnNameLookup","OnInstall","OnUpdate"],"mappings":";;;;;;;;;;;IA6BaA,2BAA2B;eAA3BA;;IAaAC,6BAA6B;eAA7BA;;IAOAC,sBAAsB;eAAtBA;;IAWAC,iBAAiB;eAAjBA;;IAUJC,mBAAmB;eAAnBA,wBAAmB;;IACnBC,0BAA0B;eAA1BA,8CAA0B;;IAC1BC,iBAAiB;eAAjBA,6BAAiB;;;4BAvEE;yBA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,CAACK,SAAS,CAAC,EAAEd,8CAA8B,CAACP,UAAU;IAClE,CAACgB,uBAAW,CAACM,QAAQ,CAAC,EAAEf,8CAA8B,CAACP,UAAU;AACnE"}
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":";;;;;;;;;;;IAkCaA,2BAA2B;eAA3BA;;IAcAC,6BAA6B;eAA7BA;;IAQAC,sBAAsB;eAAtBA;;IAYAC,iBAAiB;eAAjBA;;IAWJC,mBAAmB;eAAnBA,wBAAmB;;IACnBC,0BAA0B;eAA1BA,8CAA0B;;IAC1BC,iBAAiB;eAAjBA,6BAAiB;;IACjBC,uBAAuB;eAAvBA,gCAAuB;;;4BAjFJ;yBAOrB;kCAC0C;yBAK1C;gCACwC;4BAKxC;+BACuC;qBAKvC;oCAKA;6BACqC;qBA8C9B;;;;;;;;;;;;;;AA5CP,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;AAC/D;AAEO,MAAMhB,gCAAgC;IAC3C,GAAGiB,oCAA2B;IAC9B,GAAGC,0DAAsC;IACzC,GAAGC,4BAAuB;IAC1B,GAAGC,0CAA8B;IACjC,GAAGC,oCAA2B;AAChC;AAEO,MAAMpB,yBAGT;IACF,CAACS,gCAAuB,CAACF,UAAU,CAAC,EAAEc,+BAAsB;IAC5D,CAACb,sDAAkC,CAACD,UAAU,CAAC,EAC7Ce,qDAAiC;IACnC,CAACX,wBAAmB,CAACJ,UAAU,CAAC,EAAEgB,uBAAkB;IACpD,CAACV,sCAA0B,CAACN,UAAU,CAAC,EAAEiB,qCAAyB;IAClE,CAACT,gCAAuB,CAACR,UAAU,CAAC,EAAEkB,+BAAsB;AAC9D;AAEO,MAAMxB,oBAAiD;IAC5D,CAACyB,uBAAW,CAACC,YAAY,CAAC,EAAEhB,wBAAmB,CAACJ,UAAU;IAC1D,CAACmB,uBAAW,CAACE,aAAa,CAAC,EAAEpB,sDAAkC,CAACD,UAAU;IAC1E,CAACmB,uBAAW,CAACG,SAAS,CAAC,EAAEpB,gCAAuB,CAACF,UAAU;IAC3D,CAACmB,uBAAW,CAACI,YAAY,CAAC,EAAEjB,sCAA0B,CAACN,UAAU;IACjE,CAACmB,uBAAW,CAACK,SAAS,CAAC,EAAEjB,8CAA8B,CAACP,UAAU;IAClE,CAACmB,uBAAW,CAACM,QAAQ,CAAC,EAAElB,8CAA8B,CAACP,UAAU;IACjE,CAACmB,uBAAW,CAACO,gBAAgB,CAAC,EAAElB,gCAAuB,CAACR,UAAU;AACpE"}
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: all[name]
9
+ });
10
+ }
11
+ _export(exports, {
12
+ keyringEndowmentBuilder: function() {
13
+ return keyringEndowmentBuilder;
14
+ },
15
+ getKeyringCaveatMapper: function() {
16
+ return getKeyringCaveatMapper;
17
+ },
18
+ getKeyringCaveatOrigins: function() {
19
+ return getKeyringCaveatOrigins;
20
+ },
21
+ keyringCaveatSpecifications: function() {
22
+ return keyringCaveatSpecifications;
23
+ }
24
+ });
25
+ const _permissioncontroller = require("@metamask/permission-controller");
26
+ const _snapsutils = require("@metamask/snaps-utils");
27
+ const _utils = require("@metamask/utils");
28
+ const _ethrpcerrors = require("eth-rpc-errors");
29
+ const _enum = require("./enum");
30
+ const permissionName = _enum.SnapEndowments.Keyring;
31
+ /**
32
+ * `endowment:keyring` returns nothing; it is intended to be used as a flag
33
+ * by the client to detect whether the snap has keyring capabilities.
34
+ *
35
+ * @param _builderOptions - Optional specification builder options.
36
+ * @returns The specification for the keyring endowment.
37
+ */ const specificationBuilder = (_builderOptions)=>{
38
+ return {
39
+ permissionType: _permissioncontroller.PermissionType.Endowment,
40
+ targetName: permissionName,
41
+ allowedCaveats: [
42
+ _snapsutils.SnapCaveatType.KeyringOrigin
43
+ ],
44
+ endowmentGetter: (_getterOptions)=>undefined,
45
+ validator: ({ caveats })=>{
46
+ if (caveats?.length !== 1 || caveats[0].type !== _snapsutils.SnapCaveatType.KeyringOrigin) {
47
+ throw _ethrpcerrors.ethErrors.rpc.invalidParams({
48
+ message: `Expected a single "${_snapsutils.SnapCaveatType.KeyringOrigin}" caveat.`
49
+ });
50
+ }
51
+ },
52
+ subjectTypes: [
53
+ _permissioncontroller.SubjectType.Snap
54
+ ]
55
+ };
56
+ };
57
+ const keyringEndowmentBuilder = Object.freeze({
58
+ targetName: permissionName,
59
+ specificationBuilder
60
+ });
61
+ /**
62
+ * Validate the value of a caveat. This does not validate the type of the
63
+ * caveat itself, only the value of the caveat.
64
+ *
65
+ * @param caveat - The caveat to validate.
66
+ * @throws If the caveat value is invalid.
67
+ */ function validateCaveatOrigins(caveat) {
68
+ if (!(0, _utils.hasProperty)(caveat, 'value') || !(0, _utils.isPlainObject)(caveat.value)) {
69
+ throw _ethrpcerrors.ethErrors.rpc.invalidParams({
70
+ message: 'Invalid keyring origins: Expected a plain object.'
71
+ });
72
+ }
73
+ const { value } = caveat;
74
+ (0, _snapsutils.assertIsKeyringOrigins)(value, _ethrpcerrors.ethErrors.rpc.invalidParams);
75
+ }
76
+ function getKeyringCaveatMapper(value) {
77
+ return {
78
+ caveats: [
79
+ {
80
+ type: _snapsutils.SnapCaveatType.KeyringOrigin,
81
+ value
82
+ }
83
+ ]
84
+ };
85
+ }
86
+ function getKeyringCaveatOrigins(permission) {
87
+ (0, _utils.assert)(permission?.caveats);
88
+ (0, _utils.assert)(permission.caveats.length === 1);
89
+ (0, _utils.assert)(permission.caveats[0].type === _snapsutils.SnapCaveatType.KeyringOrigin);
90
+ const caveat = permission.caveats[0];
91
+ return caveat.value;
92
+ }
93
+ const keyringCaveatSpecifications = {
94
+ [_snapsutils.SnapCaveatType.KeyringOrigin]: Object.freeze({
95
+ type: _snapsutils.SnapCaveatType.KeyringOrigin,
96
+ validator: (caveat)=>validateCaveatOrigins(caveat)
97
+ })
98
+ };
99
+
100
+ //# 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":["keyringEndowmentBuilder","getKeyringCaveatMapper","getKeyringCaveatOrigins","keyringCaveatSpecifications","permissionName","SnapEndowments","Keyring","specificationBuilder","_builderOptions","permissionType","PermissionType","Endowment","targetName","allowedCaveats","SnapCaveatType","KeyringOrigin","endowmentGetter","_getterOptions","undefined","validator","caveats","length","type","ethErrors","rpc","invalidParams","message","subjectTypes","SubjectType","Snap","Object","freeze","validateCaveatOrigins","caveat","hasProperty","isPlainObject","value","assertIsKeyringOrigins","permission","assert"],"mappings":";;;;;;;;;;;IA4DaA,uBAAuB;eAAvBA;;IA+BGC,sBAAsB;eAAtBA;;IAsBAC,uBAAuB;eAAvBA;;IAWHC,2BAA2B;eAA3BA;;;sCAnH+B;4BAEW;uBAEJ;8BACzB;sBAEK;AAE/B,MAAMC,iBAAiBC,oBAAc,CAACC,OAAO;AAW7C;;;;;;CAMC,GACD,MAAMC,uBAIF,CAACC;IACH,OAAO;QACLC,gBAAgBC,oCAAc,CAACC,SAAS;QACxCC,YAAYR;QACZS,gBAAgB;YAACC,0BAAc,CAACC,aAAa;SAAC;QAC9CC,iBAAiB,CAACC,iBAA2CC;QAC7DC,WAAW,CAAC,EAAEC,OAAO,EAAE;YACrB,IACEA,SAASC,WAAW,KACpBD,OAAO,CAA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AACF"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/fsm.ts"],"sourcesContent":["import { assert } from '@metamask/utils';\nimport type { EventObject, StateMachine, Typestate } from '@xstate/fsm';\nimport { InterpreterStatus } from '@xstate/fsm';\n\n/**\n * Validates the set-up of a @xstate/fsm machine.\n *\n * 1. Ensures that all named actions in the config have a provided implementation.\n *\n * @param machine - The machine to validate.\n * @throws {@link AssertionError}. If the validation fails.\n */\nexport function validateMachine<\n TContext extends object,\n TEvent extends EventObject,\n TState extends Typestate<TContext>,\n>(machine: StateMachine.Machine<TContext, TEvent, TState>) {\n assert('_options' in machine, 'The machine is not an @xstate/fsm machine');\n const typed = machine as StateMachine.Machine<TContext, TEvent, TState> & {\n _options: { actions?: StateMachine.ActionMap<TContext, TEvent> };\n };\n\n // 1.\n const toArray = <Type>(obj: Type | Type[]): Type[] => {\n if (Array.isArray(obj)) {\n return obj;\n } else if (obj === undefined || obj === null) {\n return [];\n }\n return [obj];\n };\n\n const allActions = new Set<string>();\n const addActions = (actions: any) =>\n toArray(actions)\n .flatMap((action) => {\n if (typeof action === 'string') {\n return [action];\n }\n assert(typeof action === 'function');\n return [];\n })\n .forEach(allActions.add.bind(allActions));\n\n for (const state of Object.values<typeof typed.config.states[string]>(\n typed.config.states,\n )) {\n addActions(state.entry);\n addActions(state.exit);\n for (const transition of Object.values<any>(state.on ?? {})) {\n addActions(transition.actions);\n }\n }\n\n allActions.forEach((action) =>\n assert(\n typed._options.actions !== undefined && action in typed._options.actions,\n `Action \"${action}\" doesn't have an implementation`,\n ),\n );\n}\n\n/**\n * Ensure that the interpreter is strict.\n * Strict means that the transition must occur.\n * The event must exist in .on {} state config and it's guard must succeed.\n *\n * The error will be thrown when an invalid `interpreter.send()` is called\n * and will be bubbled there.\n *\n * TODO(ritave): Doesn't support self transitions.\n *\n * @param interpreter - The interpreter that will be force into strict mode.\n * @throws {@link Error} Thrown when the transition is invalid.\n */\nexport function forceStrict(interpreter: StateMachine.Service<any, any, any>) {\n // As soon as a listener subscribes, it is called. It might be called in\n // an initial state which doesn't have the .changed property\n let onInitialCalled = false;\n interpreter.subscribe((state) => {\n assert(!onInitialCalled || state.changed, 'Invalid state transition');\n onInitialCalled = true;\n });\n\n const ogSend = interpreter.send.bind(interpreter);\n interpreter.send = (...args) => {\n assert(\n interpreter.status === InterpreterStatus.Running,\n 'Interpreter is stopped',\n );\n return ogSend(...args);\n };\n}\n"],"names":["assert","InterpreterStatus","validateMachine","machine","typed","toArray","obj","Array","isArray","undefined","allActions","Set","addActions","actions","flatMap","action","forEach","add","bind","state","Object","values","config","states","entry","exit","transition","on","_options","forceStrict","interpreter","onInitialCalled","subscribe","changed","ogSend","send","args","status","Running"],"mappings":"AAAA,SAASA,MAAM,QAAQ,kBAAkB;AAEzC,SAASC,iBAAiB,QAAQ,cAAc;AAEhD;;;;;;;CAOC,GACD,OAAO,SAASC,gBAIdC,OAAuD;IACvDH,OAAO,cAAcG,SAAS;IAC9B,MAAMC,QAAQD;IAId,KAAK;IACL,MAAME,UAAU,CAAOC;QACrB,IAAIC,MAAMC,OAAO,CAACF,MAAM;YACtB,OAAOA;QACT,OAAO,IAAIA,QAAQG,aAAaH,QAAQ,MAAM;YAC5C,OAAO,EAAE;QACX;QACA,OAAO;YAACA;SAAI;IACd;IAEA,MAAMI,aAAa,IAAIC;IACvB,MAAMC,aAAa,CAACC,UAClBR,QAAQQ,SACLC,OAAO,CAAC,CAACC;YACR,IAAI,OAAOA,WAAW,UAAU;gBAC9B,OAAO;oBAACA;iBAAO;YACjB;YACAf,OAAO,OAAOe,WAAW;YACzB,OAAO,EAAE;QACX,GACCC,OAAO,CAACN,WAAWO,GAAG,CAACC,IAAI,CAACR;IAEjC,KAAK,MAAMS,SAASC,OAAOC,MAAM,CAC/BjB,MAAMkB,MAAM,CAACC,MAAM,EAClB;QACDX,WAAWO,MAAMK,KAAK;QACtBZ,WAAWO,MAAMM,IAAI;QACrB,KAAK,MAAMC,cAAcN,OAAOC,MAAM,CAAMF,MAAMQ,EAAE,IAAI,CAAC,GAAI;YAC3Df,WAAWc,WAAWb,OAAO;QAC/B;IACF;IAEAH,WAAWM,OAAO,CAAC,CAACD,SAClBf,OACEI,MAAMwB,QAAQ,CAACf,OAAO,KAAKJ,aAAaM,UAAUX,MAAMwB,QAAQ,CAACf,OAAO,EACxE,CAAC,QAAQ,EAAEE,OAAO,gCAAgC,CAAC;AAGzD;AAEA;;;;;;;;;;;;CAYC,GACD,OAAO,SAASc,YAAYC,WAAgD;IAC1E,wEAAwE;IACxE,4DAA4D;IAC5D,IAAIC,kBAAkB;IACtBD,YAAYE,SAAS,CAAC,CAACb;QACrBnB,OAAO,CAAC+B,mBAAmBZ,MAAMc,OAAO,EAAE;QAC1CF,kBAAkB;IACpB;IAEA,MAAMG,SAASJ,YAAYK,IAAI,CAACjB,IAAI,CAACY;IACrCA,YAAYK,IAAI,GAAG,CAAC,GAAGC;QACrBpC,OACE8B,YAAYO,MAAM,KAAKpC,kBAAkBqC,OAAO,EAChD;QAEF,OAAOJ,UAAUE;IACnB;AACF"}
1
+ {"version":3,"sources":["../../src/fsm.ts"],"sourcesContent":["import { assert } from '@metamask/utils';\nimport type { EventObject, StateMachine, Typestate } from '@xstate/fsm';\nimport { InterpreterStatus } from '@xstate/fsm';\n\n/**\n * Validates the set-up of a @xstate/fsm machine.\n *\n * 1. Ensures that all named actions in the config have a provided implementation.\n *\n * @param machine - The machine to validate.\n * @throws {@link AssertionError}. If the validation fails.\n */\nexport function validateMachine<\n TContext extends object,\n TEvent extends EventObject,\n TState extends Typestate<TContext>,\n>(machine: StateMachine.Machine<TContext, TEvent, TState>) {\n assert('_options' in machine, 'The machine is not an @xstate/fsm machine');\n const typed = machine as StateMachine.Machine<TContext, TEvent, TState> & {\n _options: { actions?: StateMachine.ActionMap<TContext, TEvent> };\n };\n\n // 1.\n const toArray = <Type>(obj: Type | Type[]): Type[] => {\n if (Array.isArray(obj)) {\n return obj;\n } else if (obj === undefined || obj === null) {\n return [];\n }\n return [obj];\n };\n\n const allActions = new Set<string>();\n const addActions = (actions: any) =>\n toArray(actions)\n .flatMap((action) => {\n if (typeof action === 'string') {\n return [action];\n }\n assert(typeof action === 'function');\n return [];\n })\n .forEach(allActions.add.bind(allActions));\n\n for (const state of Object.values<(typeof typed.config.states)[string]>(\n typed.config.states,\n )) {\n addActions(state.entry);\n addActions(state.exit);\n for (const transition of Object.values<any>(state.on ?? {})) {\n addActions(transition.actions);\n }\n }\n\n allActions.forEach((action) =>\n assert(\n typed._options.actions !== undefined && action in typed._options.actions,\n `Action \"${action}\" doesn't have an implementation`,\n ),\n );\n}\n\n/**\n * Ensure that the interpreter is strict.\n * Strict means that the transition must occur.\n * The event must exist in .on {} state config and it's guard must succeed.\n *\n * The error will be thrown when an invalid `interpreter.send()` is called\n * and will be bubbled there.\n *\n * TODO(ritave): Doesn't support self transitions.\n *\n * @param interpreter - The interpreter that will be force into strict mode.\n * @throws {@link Error} Thrown when the transition is invalid.\n */\nexport function forceStrict(interpreter: StateMachine.Service<any, any, any>) {\n // As soon as a listener subscribes, it is called. It might be called in\n // an initial state which doesn't have the .changed property\n let onInitialCalled = false;\n interpreter.subscribe((state) => {\n assert(!onInitialCalled || state.changed, 'Invalid state transition');\n onInitialCalled = true;\n });\n\n const ogSend = interpreter.send.bind(interpreter);\n interpreter.send = (...args) => {\n assert(\n interpreter.status === InterpreterStatus.Running,\n 'Interpreter is stopped',\n );\n return ogSend(...args);\n };\n}\n"],"names":["assert","InterpreterStatus","validateMachine","machine","typed","toArray","obj","Array","isArray","undefined","allActions","Set","addActions","actions","flatMap","action","forEach","add","bind","state","Object","values","config","states","entry","exit","transition","on","_options","forceStrict","interpreter","onInitialCalled","subscribe","changed","ogSend","send","args","status","Running"],"mappings":"AAAA,SAASA,MAAM,QAAQ,kBAAkB;AAEzC,SAASC,iBAAiB,QAAQ,cAAc;AAEhD;;;;;;;CAOC,GACD,OAAO,SAASC,gBAIdC,OAAuD;IACvDH,OAAO,cAAcG,SAA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AAM,KAAKpC,kBAAkBqC,OAAO,EAChD;QAEF,OAAOJ,UAAUE;IACnB;AACF"}
@@ -64,7 +64,7 @@ function _define_property(obj, key, value) {
64
64
  import { BaseControllerV2 as BaseController } from '@metamask/base-controller';
65
65
  import { SubjectType } from '@metamask/permission-controller';
66
66
  import { WALLET_SNAP_PERMISSION_KEY } from '@metamask/rpc-methods';
67
- import { assertIsSnapManifest, assertIsValidSnapId, DEFAULT_ENDOWMENTS, DEFAULT_REQUESTED_SNAP_VERSION, getErrorMessage, HandlerType, logError, normalizeRelative, resolveVersionRange, SnapCaveatType, SnapStatus, SnapStatusEvents, validateFetchedSnap } from '@metamask/snaps-utils';
67
+ import { assertIsSnapManifest, assertIsValidSnapId, DEFAULT_ENDOWMENTS, DEFAULT_REQUESTED_SNAP_VERSION, getErrorMessage, HandlerType, isOriginAllowed, logError, normalizeRelative, resolveVersionRange, SnapCaveatType, SnapStatus, SnapStatusEvents, validateFetchedSnap } from '@metamask/snaps-utils';
68
68
  import { assert, assertIsJsonRpcRequest, Duration, gtRange, gtVersion, hasProperty, inMilliseconds, isNonEmptyArray, isValidSemVerRange, satisfiesVersionRange, timeSince } from '@metamask/utils';
69
69
  import { createMachine, interpret } from '@xstate/fsm';
70
70
  import { ethErrors } from 'eth-rpc-errors';
@@ -73,6 +73,7 @@ import { forceStrict, validateMachine } from '../fsm';
73
73
  import { log } from '../logging';
74
74
  import { hasTimedOut, setDiff, withTimeout } from '../utils';
75
75
  import { handlerEndowments, SnapEndowments } from './endowments';
76
+ import { getKeyringCaveatOrigins } from './endowments/keyring';
76
77
  import { getRpcCaveatOrigins } from './endowments/rpc';
77
78
  import { detectSnapLocation } from './location';
78
79
  import { processSnapPermissions } from './permissions';
@@ -899,16 +900,15 @@ _initializeStateMachine = /*#__PURE__*/ new WeakSet(), /**
899
900
  if (!hasPermission) {
900
901
  throw new Error(`Snap "${snapId}" is not permitted to use "${permissionName}".`);
901
902
  }
902
- if (permissionName === SnapEndowments.Rpc) {
903
+ if (permissionName === SnapEndowments.Rpc || permissionName === SnapEndowments.Keyring) {
903
904
  const subject = this.messagingSystem.call('SubjectMetadataController:getSubjectMetadata', origin);
904
- const isSnap = subject?.subjectType === SubjectType.Snap;
905
905
  const permissions = this.messagingSystem.call('PermissionController:getPermissions', snapId);
906
- const rpcPermission = permissions?.[SnapEndowments.Rpc];
907
- assert(rpcPermission);
908
- const origins = getRpcCaveatOrigins(rpcPermission);
906
+ const handlerPermissions = permissions?.[permissionName];
907
+ assert(handlerPermissions);
908
+ const origins = permissionName === SnapEndowments.Rpc ? getRpcCaveatOrigins(handlerPermissions) : getKeyringCaveatOrigins(handlerPermissions);
909
909
  assert(origins);
910
- if (isSnap && !origins.snaps || !isSnap && !origins.dapps) {
911
- throw new Error(`Snap "${snapId}" is not permitted to handle JSON-RPC requests from "${origin}".`);
910
+ if (!isOriginAllowed(origins, subject?.subjectType ?? SubjectType.Website, origin)) {
911
+ throw new Error(`Snap "${snapId}" is not permitted to handle requests from "${origin}".`);
912
912
  }
913
913
  }
914
914
  const handler = await _class_private_method_get(this, _getRpcRequestHandler, getRpcRequestHandler).call(this, snapId);