@metamask/snaps-controllers 2.0.0 → 2.0.1

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.
@@ -11,7 +11,6 @@ Object.defineProperty(exports, "SnapEndowments", {
11
11
  var SnapEndowments;
12
12
  (function(SnapEndowments) {
13
13
  SnapEndowments["NetworkAccess"] = 'endowment:network-access';
14
- SnapEndowments["LongRunning"] = 'endowment:long-running';
15
14
  SnapEndowments["TransactionInsight"] = 'endowment:transaction-insight';
16
15
  SnapEndowments["Cronjob"] = 'endowment:cronjob';
17
16
  SnapEndowments["EthereumProvider"] = 'endowment:ethereum-provider';
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/snaps/endowments/enum.ts"],"sourcesContent":["export enum SnapEndowments {\n NetworkAccess = 'endowment:network-access',\n LongRunning = 'endowment:long-running',\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","LongRunning","TransactionInsight","Cronjob","EthereumProvider","Rpc","WebAssemblyAccess","NameLookup","LifecycleHooks"],"mappings":";;;;;;;;;;IAAO;UAAKA,cAAc;IAAdA,eACVC,mBAAgB;IADND,eAEVE,iBAAc;IAFJF,eAGVG,wBAAqB;IAHXH,eAIVI,aAAU;IAJAJ,eAKVK,sBAAmB;IALTL,eAMVM,SAAM;IANIN,eAOVO,uBAAoB;IAPVP,eAQVQ,gBAAa;IARHR,eASVS,oBAAiB;GATPT,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}\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"}
@@ -35,7 +35,6 @@ const _snapsutils = require("@metamask/snaps-utils");
35
35
  const _cronjob = require("./cronjob");
36
36
  const _ethereumprovider = require("./ethereum-provider");
37
37
  const _lifecyclehooks = require("./lifecycle-hooks");
38
- const _longrunning = require("./long-running");
39
38
  const _namelookup = require("./name-lookup");
40
39
  const _networkaccess = require("./network-access");
41
40
  const _rpc = require("./rpc");
@@ -57,7 +56,6 @@ function _export_star(from, to) {
57
56
  }
58
57
  const endowmentPermissionBuilders = {
59
58
  [_networkaccess.networkAccessEndowmentBuilder.targetName]: _networkaccess.networkAccessEndowmentBuilder,
60
- [_longrunning.longRunningEndowmentBuilder.targetName]: _longrunning.longRunningEndowmentBuilder,
61
59
  [_transactioninsight.transactionInsightEndowmentBuilder.targetName]: _transactioninsight.transactionInsightEndowmentBuilder,
62
60
  [_cronjob.cronjobEndowmentBuilder.targetName]: _cronjob.cronjobEndowmentBuilder,
63
61
  [_ethereumprovider.ethereumProviderEndowmentBuilder.targetName]: _ethereumprovider.ethereumProviderEndowmentBuilder,
@@ -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 { longRunningEndowmentBuilder } from './long-running';\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 [longRunningEndowmentBuilder.targetName]: longRunningEndowmentBuilder,\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","longRunningEndowmentBuilder","transactionInsightEndowmentBuilder","cronjobEndowmentBuilder","ethereumProviderEndowmentBuilder","rpcEndowmentBuilder","webAssemblyEndowmentBuilder","nameLookupEndowmentBuilder","lifecycleHooksEndowmentBuilder","cronjobCaveatSpecifications","transactionInsightCaveatSpecifications","rpcCaveatSpecifications","nameLookupCaveatSpecifications","getCronjobCaveatMapper","getTransactionInsightCaveatMapper","getRpcCaveatMapper","getNameLookupCaveatMapper","HandlerType","OnRpcRequest","OnTransaction","OnCronjob","OnNameLookup","OnInstall","OnUpdate"],"mappings":";;;;;;;;;;;IA8BaA,2BAA2B;eAA3BA;;IAcAC,6BAA6B;eAA7BA;;IAOAC,sBAAsB;eAAtBA;;IAWAC,iBAAiB;eAAjBA;;IAUJC,mBAAmB;eAAnBA,wBAAmB;;IACnBC,0BAA0B;eAA1BA,8CAA0B;;IAC1BC,iBAAiB;eAAjBA,6BAAiB;;;4BAzEE;yBAOrB;kCAC0C;gCACF;6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sCAA0B,CAACP,UAAU;IACjE,CAACiB,uBAAW,CAACK,SAAS,CAAC,EAAEd,8CAA8B,CAACR,UAAU;IAClE,CAACiB,uBAAW,CAACM,QAAQ,CAAC,EAAEf,8CAA8B,CAACR,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 { 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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,EAAEjB,sDAAkC,CAACD,UAAU;IAC1E,CAACgB,uBAAW,CAACG,SAAS,CAAC,EAAEjB,gCAAuB,CAACF,UAAU;IAC3D,CAACgB,uBAAW,CAACI,YAAY,CAAC,EAAEd,sCAA0B,CAACN,UAAU;IACjE,CAACgB,uBAAW,CAACK,SAAS,CAAC,EAAEd,8CAA8B,CAACP,UAAU;IAClE,CAACgB,uBAAW,CAACM,QAAQ,CAAC,EAAEf,8CAA8B,CAACP,UAAU;AACnE"}
@@ -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, logWarning, normalizeRelative, resolveVersionRange, SnapCaveatType, SnapStatus, SnapStatusEvents, validateFetchedSnap } from '@metamask/snaps-utils';
67
+ import { assertIsSnapManifest, assertIsValidSnapId, DEFAULT_ENDOWMENTS, DEFAULT_REQUESTED_SNAP_VERSION, getErrorMessage, HandlerType, 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';
@@ -1001,7 +1001,6 @@ _initializeStateMachine = /*#__PURE__*/ new WeakSet(), /**
1001
1001
  * Awaits the specified promise and rejects if the promise doesn't resolve
1002
1002
  * before the timeout.
1003
1003
  *
1004
- * @param snapId - The snap id.
1005
1004
  * @param promise - The promise to await.
1006
1005
  * @param timer - An optional timer object to control the timeout.
1007
1006
  * @returns The result of the promise or rejects if the promise times out.
@@ -1359,7 +1358,7 @@ async function startSnap(snapData) {
1359
1358
  throw new Error(`Snap "${snapId}" is already started.`);
1360
1359
  }
1361
1360
  try {
1362
- const result = await _class_private_method_get(this, _executeWithTimeout, executeWithTimeout).call(this, snapId, this.messagingSystem.call('ExecutionService:executeSnap', {
1361
+ const result = await _class_private_method_get(this, _executeWithTimeout, executeWithTimeout).call(this, this.messagingSystem.call('ExecutionService:executeSnap', {
1363
1362
  ...snapData,
1364
1363
  endowments: await _class_private_method_get(this, _getEndowments, getEndowments).call(this, snapId)
1365
1364
  }));
@@ -1537,7 +1536,7 @@ function getRpcRequestHandler(snapId) {
1537
1536
  });
1538
1537
  // This will either get the result or reject due to the timeout.
1539
1538
  try {
1540
- const result = await _class_private_method_get(this, _executeWithTimeout, executeWithTimeout).call(this, snapId, handleRpcRequestPromise, timer);
1539
+ const result = await _class_private_method_get(this, _executeWithTimeout, executeWithTimeout).call(this, handleRpcRequestPromise, timer);
1541
1540
  _class_private_method_get(this, _recordSnapRpcRequestFinish, recordSnapRpcRequestFinish).call(this, snapId, request.id);
1542
1541
  return result;
1543
1542
  } catch (error) {
@@ -1548,13 +1547,7 @@ function getRpcRequestHandler(snapId) {
1548
1547
  runtime.rpcHandler = rpcHandler;
1549
1548
  return rpcHandler;
1550
1549
  }
1551
- async function executeWithTimeout(snapId, promise, timer) {
1552
- const isLongRunning = this.messagingSystem.call('PermissionController:hasPermission', snapId, SnapEndowments.LongRunning);
1553
- // Long running snaps have timeouts disabled
1554
- if (isLongRunning) {
1555
- logWarning(`${SnapEndowments.LongRunning} will soon be deprecated. For more information please see https://github.com/MetaMask/snaps-monorepo/issues/945.`);
1556
- return promise;
1557
- }
1550
+ async function executeWithTimeout(promise, timer) {
1558
1551
  const result = await withTimeout(promise, timer ?? this.maxRequestTime);
1559
1552
  if (result === hasTimedOut) {
1560
1553
  throw new Error('The request timed out.');