@metamask/snaps-controllers 19.0.0 → 20.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.
Files changed (94) hide show
  1. package/CHANGELOG.md +23 -1
  2. package/dist/cronjob/CronjobController-method-action-types.cjs +1 -1
  3. package/dist/cronjob/CronjobController-method-action-types.cjs.map +1 -1
  4. package/dist/cronjob/CronjobController-method-action-types.d.cts +1 -1
  5. package/dist/cronjob/CronjobController-method-action-types.d.mts +1 -1
  6. package/dist/cronjob/CronjobController-method-action-types.mjs +1 -1
  7. package/dist/cronjob/CronjobController-method-action-types.mjs.map +1 -1
  8. package/dist/cronjob/CronjobController.cjs.map +1 -1
  9. package/dist/cronjob/CronjobController.d.cts +2 -2
  10. package/dist/cronjob/CronjobController.d.cts.map +1 -1
  11. package/dist/cronjob/CronjobController.d.mts +2 -2
  12. package/dist/cronjob/CronjobController.d.mts.map +1 -1
  13. package/dist/cronjob/CronjobController.mjs.map +1 -1
  14. package/dist/insights/SnapInsightsController.cjs.map +1 -1
  15. package/dist/insights/SnapInsightsController.d.cts +2 -2
  16. package/dist/insights/SnapInsightsController.d.cts.map +1 -1
  17. package/dist/insights/SnapInsightsController.d.mts +2 -2
  18. package/dist/insights/SnapInsightsController.d.mts.map +1 -1
  19. package/dist/insights/SnapInsightsController.mjs.map +1 -1
  20. package/dist/interface/SnapInterfaceController-method-action-types.cjs +1 -1
  21. package/dist/interface/SnapInterfaceController-method-action-types.cjs.map +1 -1
  22. package/dist/interface/SnapInterfaceController-method-action-types.d.cts +1 -1
  23. package/dist/interface/SnapInterfaceController-method-action-types.d.mts +1 -1
  24. package/dist/interface/SnapInterfaceController-method-action-types.mjs +1 -1
  25. package/dist/interface/SnapInterfaceController-method-action-types.mjs.map +1 -1
  26. package/dist/interface/SnapInterfaceController.cjs.map +1 -1
  27. package/dist/interface/SnapInterfaceController.d.cts +2 -2
  28. package/dist/interface/SnapInterfaceController.d.cts.map +1 -1
  29. package/dist/interface/SnapInterfaceController.d.mts +2 -2
  30. package/dist/interface/SnapInterfaceController.d.mts.map +1 -1
  31. package/dist/interface/SnapInterfaceController.mjs.map +1 -1
  32. package/dist/multichain/MultichainRoutingService-method-action-types.cjs +1 -1
  33. package/dist/multichain/MultichainRoutingService-method-action-types.cjs.map +1 -1
  34. package/dist/multichain/MultichainRoutingService-method-action-types.d.cts +1 -1
  35. package/dist/multichain/MultichainRoutingService-method-action-types.d.mts +1 -1
  36. package/dist/multichain/MultichainRoutingService-method-action-types.mjs +1 -1
  37. package/dist/multichain/MultichainRoutingService-method-action-types.mjs.map +1 -1
  38. package/dist/multichain/MultichainRoutingService.cjs.map +1 -1
  39. package/dist/multichain/MultichainRoutingService.d.cts +2 -2
  40. package/dist/multichain/MultichainRoutingService.d.cts.map +1 -1
  41. package/dist/multichain/MultichainRoutingService.d.mts +2 -2
  42. package/dist/multichain/MultichainRoutingService.d.mts.map +1 -1
  43. package/dist/multichain/MultichainRoutingService.mjs.map +1 -1
  44. package/dist/services/ExecutionService-method-action-types.cjs +1 -1
  45. package/dist/services/ExecutionService-method-action-types.cjs.map +1 -1
  46. package/dist/services/ExecutionService-method-action-types.d.cts +1 -1
  47. package/dist/services/ExecutionService-method-action-types.d.mts +1 -1
  48. package/dist/services/ExecutionService-method-action-types.mjs +1 -1
  49. package/dist/services/ExecutionService-method-action-types.mjs.map +1 -1
  50. package/dist/snaps/SnapController-method-action-types.cjs +1 -1
  51. package/dist/snaps/SnapController-method-action-types.cjs.map +1 -1
  52. package/dist/snaps/SnapController-method-action-types.d.cts +2 -2
  53. package/dist/snaps/SnapController-method-action-types.d.mts +2 -2
  54. package/dist/snaps/SnapController-method-action-types.mjs +1 -1
  55. package/dist/snaps/SnapController-method-action-types.mjs.map +1 -1
  56. package/dist/snaps/SnapController.cjs +3 -3
  57. package/dist/snaps/SnapController.cjs.map +1 -1
  58. package/dist/snaps/SnapController.d.cts +5 -5
  59. package/dist/snaps/SnapController.d.cts.map +1 -1
  60. package/dist/snaps/SnapController.d.mts +5 -5
  61. package/dist/snaps/SnapController.d.mts.map +1 -1
  62. package/dist/snaps/SnapController.mjs +3 -3
  63. package/dist/snaps/SnapController.mjs.map +1 -1
  64. package/dist/snaps/registry/SnapRegistryController-method-action-types.cjs +1 -1
  65. package/dist/snaps/registry/SnapRegistryController-method-action-types.cjs.map +1 -1
  66. package/dist/snaps/registry/SnapRegistryController-method-action-types.d.cts +1 -1
  67. package/dist/snaps/registry/SnapRegistryController-method-action-types.d.mts +1 -1
  68. package/dist/snaps/registry/SnapRegistryController-method-action-types.mjs +1 -1
  69. package/dist/snaps/registry/SnapRegistryController-method-action-types.mjs.map +1 -1
  70. package/dist/snaps/registry/SnapRegistryController.cjs +3 -0
  71. package/dist/snaps/registry/SnapRegistryController.cjs.map +1 -1
  72. package/dist/snaps/registry/SnapRegistryController.d.cts +5 -1
  73. package/dist/snaps/registry/SnapRegistryController.d.cts.map +1 -1
  74. package/dist/snaps/registry/SnapRegistryController.d.mts +5 -1
  75. package/dist/snaps/registry/SnapRegistryController.d.mts.map +1 -1
  76. package/dist/snaps/registry/SnapRegistryController.mjs +3 -0
  77. package/dist/snaps/registry/SnapRegistryController.mjs.map +1 -1
  78. package/dist/snaps/registry/index.cjs.map +1 -1
  79. package/dist/snaps/registry/index.d.cts +1 -1
  80. package/dist/snaps/registry/index.d.cts.map +1 -1
  81. package/dist/snaps/registry/index.d.mts +1 -1
  82. package/dist/snaps/registry/index.d.mts.map +1 -1
  83. package/dist/snaps/registry/index.mjs.map +1 -1
  84. package/dist/utils.d.cts +31 -1
  85. package/dist/utils.d.cts.map +1 -1
  86. package/dist/utils.d.mts +31 -1
  87. package/dist/utils.d.mts.map +1 -1
  88. package/dist/websocket/WebSocketService-method-action-types.cjs +1 -1
  89. package/dist/websocket/WebSocketService-method-action-types.cjs.map +1 -1
  90. package/dist/websocket/WebSocketService-method-action-types.d.cts +1 -1
  91. package/dist/websocket/WebSocketService-method-action-types.d.mts +1 -1
  92. package/dist/websocket/WebSocketService-method-action-types.mjs +1 -1
  93. package/dist/websocket/WebSocketService-method-action-types.mjs.map +1 -1
  94. package/package.json +14 -12
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /**
3
- * This file is auto generated by `scripts/generate-method-action-types.ts`.
3
+ * This file is auto generated.
4
4
  * Do not edit manually.
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -1 +1 @@
1
- {"version":3,"file":"SnapRegistryController-method-action-types.cjs","sourceRoot":"","sources":["../../../src/snaps/registry/SnapRegistryController-method-action-types.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated by `scripts/generate-method-action-types.ts`.\n * Do not edit manually.\n */\n\nimport type { SnapRegistryController } from './SnapRegistryController';\n\n/**\n * Triggers an update of the registry database.\n *\n * If an existing update is in progress this function will await that update.\n */\nexport type SnapRegistryControllerRequestUpdateAction = {\n type: `SnapRegistryController:requestUpdate`;\n handler: SnapRegistryController['requestUpdate'];\n};\n\nexport type SnapRegistryControllerGetAction = {\n type: `SnapRegistryController:get`;\n handler: SnapRegistryController['get'];\n};\n\n/**\n * Find an allowlisted version within a specified version range. Otherwise return the version range itself.\n *\n * @param snapId - The ID of the snap we are trying to resolve a version for.\n * @param versionRange - The version range.\n * @param refetch - An optional flag used to determine if we are refetching the registry.\n * @returns An allowlisted version within the specified version range if available otherwise returns the input version range.\n */\nexport type SnapRegistryControllerResolveVersionAction = {\n type: `SnapRegistryController:resolveVersion`;\n handler: SnapRegistryController['resolveVersion'];\n};\n\n/**\n * Get metadata for the given snap ID, if available, without updating registry.\n *\n * @param snapId - The ID of the snap to get metadata for.\n * @returns The metadata for the given snap ID, or `null` if the snap is not\n * verified.\n */\nexport type SnapRegistryControllerGetMetadataAction = {\n type: `SnapRegistryController:getMetadata`;\n handler: SnapRegistryController['getMetadata'];\n};\n\n/**\n * Union of all SnapRegistryController action types.\n */\nexport type SnapRegistryControllerMethodActions =\n | SnapRegistryControllerRequestUpdateAction\n | SnapRegistryControllerGetAction\n | SnapRegistryControllerResolveVersionAction\n | SnapRegistryControllerGetMetadataAction;\n"]}
1
+ {"version":3,"file":"SnapRegistryController-method-action-types.cjs","sourceRoot":"","sources":["../../../src/snaps/registry/SnapRegistryController-method-action-types.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { SnapRegistryController } from './SnapRegistryController';\n\n/**\n * Triggers an update of the registry database.\n *\n * If an existing update is in progress this function will await that update.\n */\nexport type SnapRegistryControllerRequestUpdateAction = {\n type: `SnapRegistryController:requestUpdate`;\n handler: SnapRegistryController['requestUpdate'];\n};\n\nexport type SnapRegistryControllerGetAction = {\n type: `SnapRegistryController:get`;\n handler: SnapRegistryController['get'];\n};\n\n/**\n * Find an allowlisted version within a specified version range. Otherwise return the version range itself.\n *\n * @param snapId - The ID of the snap we are trying to resolve a version for.\n * @param versionRange - The version range.\n * @param refetch - An optional flag used to determine if we are refetching the registry.\n * @returns An allowlisted version within the specified version range if available otherwise returns the input version range.\n */\nexport type SnapRegistryControllerResolveVersionAction = {\n type: `SnapRegistryController:resolveVersion`;\n handler: SnapRegistryController['resolveVersion'];\n};\n\n/**\n * Get metadata for the given snap ID, if available, without updating registry.\n *\n * @param snapId - The ID of the snap to get metadata for.\n * @returns The metadata for the given snap ID, or `null` if the snap is not\n * verified.\n */\nexport type SnapRegistryControllerGetMetadataAction = {\n type: `SnapRegistryController:getMetadata`;\n handler: SnapRegistryController['getMetadata'];\n};\n\n/**\n * Union of all SnapRegistryController action types.\n */\nexport type SnapRegistryControllerMethodActions =\n | SnapRegistryControllerRequestUpdateAction\n | SnapRegistryControllerGetAction\n | SnapRegistryControllerResolveVersionAction\n | SnapRegistryControllerGetMetadataAction;\n"]}
@@ -1,5 +1,5 @@
1
1
  /**
2
- * This file is auto generated by `scripts/generate-method-action-types.ts`.
2
+ * This file is auto generated.
3
3
  * Do not edit manually.
4
4
  */
5
5
  import type { SnapRegistryController } from "./SnapRegistryController.cjs";
@@ -1,5 +1,5 @@
1
1
  /**
2
- * This file is auto generated by `scripts/generate-method-action-types.ts`.
2
+ * This file is auto generated.
3
3
  * Do not edit manually.
4
4
  */
5
5
  import type { SnapRegistryController } from "./SnapRegistryController.mjs";
@@ -1,5 +1,5 @@
1
1
  /**
2
- * This file is auto generated by `scripts/generate-method-action-types.ts`.
2
+ * This file is auto generated.
3
3
  * Do not edit manually.
4
4
  */
5
5
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"SnapRegistryController-method-action-types.mjs","sourceRoot":"","sources":["../../../src/snaps/registry/SnapRegistryController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated by `scripts/generate-method-action-types.ts`.\n * Do not edit manually.\n */\n\nimport type { SnapRegistryController } from './SnapRegistryController';\n\n/**\n * Triggers an update of the registry database.\n *\n * If an existing update is in progress this function will await that update.\n */\nexport type SnapRegistryControllerRequestUpdateAction = {\n type: `SnapRegistryController:requestUpdate`;\n handler: SnapRegistryController['requestUpdate'];\n};\n\nexport type SnapRegistryControllerGetAction = {\n type: `SnapRegistryController:get`;\n handler: SnapRegistryController['get'];\n};\n\n/**\n * Find an allowlisted version within a specified version range. Otherwise return the version range itself.\n *\n * @param snapId - The ID of the snap we are trying to resolve a version for.\n * @param versionRange - The version range.\n * @param refetch - An optional flag used to determine if we are refetching the registry.\n * @returns An allowlisted version within the specified version range if available otherwise returns the input version range.\n */\nexport type SnapRegistryControllerResolveVersionAction = {\n type: `SnapRegistryController:resolveVersion`;\n handler: SnapRegistryController['resolveVersion'];\n};\n\n/**\n * Get metadata for the given snap ID, if available, without updating registry.\n *\n * @param snapId - The ID of the snap to get metadata for.\n * @returns The metadata for the given snap ID, or `null` if the snap is not\n * verified.\n */\nexport type SnapRegistryControllerGetMetadataAction = {\n type: `SnapRegistryController:getMetadata`;\n handler: SnapRegistryController['getMetadata'];\n};\n\n/**\n * Union of all SnapRegistryController action types.\n */\nexport type SnapRegistryControllerMethodActions =\n | SnapRegistryControllerRequestUpdateAction\n | SnapRegistryControllerGetAction\n | SnapRegistryControllerResolveVersionAction\n | SnapRegistryControllerGetMetadataAction;\n"]}
1
+ {"version":3,"file":"SnapRegistryController-method-action-types.mjs","sourceRoot":"","sources":["../../../src/snaps/registry/SnapRegistryController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { SnapRegistryController } from './SnapRegistryController';\n\n/**\n * Triggers an update of the registry database.\n *\n * If an existing update is in progress this function will await that update.\n */\nexport type SnapRegistryControllerRequestUpdateAction = {\n type: `SnapRegistryController:requestUpdate`;\n handler: SnapRegistryController['requestUpdate'];\n};\n\nexport type SnapRegistryControllerGetAction = {\n type: `SnapRegistryController:get`;\n handler: SnapRegistryController['get'];\n};\n\n/**\n * Find an allowlisted version within a specified version range. Otherwise return the version range itself.\n *\n * @param snapId - The ID of the snap we are trying to resolve a version for.\n * @param versionRange - The version range.\n * @param refetch - An optional flag used to determine if we are refetching the registry.\n * @returns An allowlisted version within the specified version range if available otherwise returns the input version range.\n */\nexport type SnapRegistryControllerResolveVersionAction = {\n type: `SnapRegistryController:resolveVersion`;\n handler: SnapRegistryController['resolveVersion'];\n};\n\n/**\n * Get metadata for the given snap ID, if available, without updating registry.\n *\n * @param snapId - The ID of the snap to get metadata for.\n * @returns The metadata for the given snap ID, or `null` if the snap is not\n * verified.\n */\nexport type SnapRegistryControllerGetMetadataAction = {\n type: `SnapRegistryController:getMetadata`;\n handler: SnapRegistryController['getMetadata'];\n};\n\n/**\n * Union of all SnapRegistryController action types.\n */\nexport type SnapRegistryControllerMethodActions =\n | SnapRegistryControllerRequestUpdateAction\n | SnapRegistryControllerGetAction\n | SnapRegistryControllerResolveVersionAction\n | SnapRegistryControllerGetMetadataAction;\n"]}
@@ -107,6 +107,7 @@ class SnapRegistryController extends base_controller_1.BaseController {
107
107
  async #update() {
108
108
  // No-op if we recently fetched the registry.
109
109
  if (this.#wasRecentlyFetched()) {
110
+ this.messenger.publish('SnapRegistryController:registryUpdated', false);
110
111
  return;
111
112
  }
112
113
  try {
@@ -121,6 +122,7 @@ class SnapRegistryController extends base_controller_1.BaseController {
121
122
  state.lastUpdated = Date.now();
122
123
  state.databaseUnavailable = false;
123
124
  });
125
+ this.messenger.publish('SnapRegistryController:registryUpdated', false);
124
126
  return;
125
127
  }
126
128
  await this.#verifySignature(database, signatureJson);
@@ -130,6 +132,7 @@ class SnapRegistryController extends base_controller_1.BaseController {
130
132
  state.databaseUnavailable = false;
131
133
  state.signature = signatureJson.signature;
132
134
  });
135
+ this.messenger.publish('SnapRegistryController:registryUpdated', true);
133
136
  }
134
137
  catch {
135
138
  // Ignore
@@ -1 +1 @@
1
- {"version":3,"file":"SnapRegistryController.cjs","sourceRoot":"","sources":["../../../src/snaps/registry/SnapRegistryController.ts"],"names":[],"mappings":";;;AAIA,+DAA2D;AAM3D,6DAAkD;AAClD,uDAAyD;AAGzD,2CAMyB;AASzB,uCAA6C;AAE7C,MAAM,iBAAiB,GACrB,wDAAwD,CAAC;AAE3D,MAAM,2BAA2B,GAC/B,yDAAyD,CAAC;AAE5D,MAAM,kBAAkB,GACtB,sEAAsE,CAAC;AAqDzE,MAAM,cAAc,GAAG,wBAAwB,CAAC;AAEhD,MAAM,yBAAyB,GAAG;IAChC,KAAK;IACL,aAAa;IACb,gBAAgB;IAChB,eAAe;CACP,CAAC;AAEX,MAAM,YAAY,GAAG;IACnB,QAAQ,EAAE,IAAI;IACd,SAAS,EAAE,IAAI;IACf,WAAW,EAAE,IAAI;IACjB,mBAAmB,EAAE,KAAK;CAC3B,CAAC;AAEF,MAAa,sBAAuB,SAAQ,gCAI3C;IACU,IAAI,CAAuB;IAE3B,UAAU,CAAM;IAEhB,aAAa,CAAe;IAE5B,cAAc,CAAe;IAE7B,qBAAqB,CAAS;IAE9B,uBAAuB,CAAU;IAE1C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YACT,SAAS,EAAE,IAAI,CAAC,UAAU;SAC3B,CAAC,CAAC;QAEH,IAAA,cAAM,EAAC,KAAK,EAAE,6BAA6B,CAAC,CAAC;IAC/C,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,UAAU,CAAC,GAAW;QAC1B,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC,CAAC;QACvE,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CAAC,mBAAmB,GAAG,GAAG,CAAC,CAAC;QAC7C,CAAC;QAED,OAAO,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;IAC/B,CAAC;CACF;AAnUD,wDAmUC","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type { Messenger } from '@metamask/messenger';\nimport type {\n SnapsRegistryDatabase,\n SignatureStruct,\n} from '@metamask/snaps-registry';\nimport { verify } from '@metamask/snaps-registry';\nimport { getTargetVersion } from '@metamask/snaps-utils';\nimport type { Infer } from '@metamask/superstruct';\nimport type { Hex, SemVerRange, SemVerVersion } from '@metamask/utils';\nimport {\n assert,\n assertIsSemVerRange,\n Duration,\n inMilliseconds,\n satisfiesVersionRange,\n} from '@metamask/utils';\n\nimport type { SnapRegistryControllerMethodActions } from './SnapRegistryController-method-action-types';\nimport type {\n SnapRegistryInfo,\n SnapRegistryMetadata,\n SnapRegistryRequest,\n SnapRegistryResult,\n} from './types';\nimport { SnapRegistryStatus } from './types';\n\nconst SNAP_REGISTRY_URL =\n 'https://acl.execution.metamask.io/latest/registry.json';\n\nconst SNAP_REGISTRY_SIGNATURE_URL =\n 'https://acl.execution.metamask.io/latest/signature.json';\n\nconst DEFAULT_PUBLIC_KEY =\n '0x025b65308f0f0fb8bc7f7ff87bfc296e0330eee5d3c1d1ee4a048b2fd6a86fa0a6';\n\ntype JsonSnapsRegistryUrl = {\n registry: string;\n signature: string;\n};\n\nexport type ClientConfig = {\n type: 'extension' | 'mobile';\n version: SemVerVersion;\n};\n\nexport type SnapRegistryControllerArgs = {\n messenger: SnapRegistryControllerMessenger;\n state?: SnapRegistryControllerState;\n fetchFunction?: typeof fetch;\n url?: JsonSnapsRegistryUrl;\n recentFetchThreshold?: number;\n refetchOnAllowlistMiss?: boolean;\n publicKey?: Hex;\n clientConfig: ClientConfig;\n};\n\nexport type SnapRegistryControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n SnapRegistryControllerState\n>;\n\nexport type SnapRegistryControllerActions =\n | SnapRegistryControllerGetStateAction\n | SnapRegistryControllerMethodActions;\n\nexport type SnapRegistryControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof controllerName,\n SnapRegistryControllerState\n>;\n\nexport type SnapRegistryControllerEvents =\n SnapRegistryControllerStateChangeEvent;\n\nexport type SnapRegistryControllerMessenger = Messenger<\n typeof controllerName,\n SnapRegistryControllerActions,\n SnapRegistryControllerEvents\n>;\n\nexport type SnapRegistryControllerState = {\n database: SnapsRegistryDatabase | null;\n signature: string | null;\n lastUpdated: number | null;\n databaseUnavailable: boolean;\n};\n\nconst controllerName = 'SnapRegistryController';\n\nconst MESSENGER_EXPOSED_METHODS = [\n 'get',\n 'getMetadata',\n 'resolveVersion',\n 'requestUpdate',\n] as const;\n\nconst defaultState = {\n database: null,\n signature: null,\n lastUpdated: null,\n databaseUnavailable: false,\n};\n\nexport class SnapRegistryController extends BaseController<\n typeof controllerName,\n SnapRegistryControllerState,\n SnapRegistryControllerMessenger\n> {\n readonly #url: JsonSnapsRegistryUrl;\n\n readonly #publicKey: Hex;\n\n readonly #clientConfig: ClientConfig;\n\n readonly #fetchFunction: typeof fetch;\n\n readonly #recentFetchThreshold: number;\n\n readonly #refetchOnAllowlistMiss: boolean;\n\n #currentUpdate: Promise<void> | null;\n\n constructor({\n messenger,\n state,\n url = {\n registry: SNAP_REGISTRY_URL,\n signature: SNAP_REGISTRY_SIGNATURE_URL,\n },\n publicKey = DEFAULT_PUBLIC_KEY,\n clientConfig,\n fetchFunction = globalThis.fetch.bind(undefined),\n recentFetchThreshold = inMilliseconds(5, Duration.Minute),\n refetchOnAllowlistMiss = true,\n }: SnapRegistryControllerArgs) {\n super({\n messenger,\n metadata: {\n database: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n signature: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: true,\n usedInUi: false,\n },\n lastUpdated: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: true,\n usedInUi: false,\n },\n databaseUnavailable: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: true,\n usedInUi: false,\n },\n },\n name: controllerName,\n state: {\n ...defaultState,\n ...state,\n },\n });\n this.#url = url;\n this.#publicKey = publicKey;\n this.#clientConfig = clientConfig;\n this.#fetchFunction = fetchFunction;\n this.#recentFetchThreshold = recentFetchThreshold;\n this.#refetchOnAllowlistMiss = refetchOnAllowlistMiss;\n this.#currentUpdate = null;\n\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n }\n\n #wasRecentlyFetched() {\n return (\n this.state.lastUpdated &&\n Date.now() - this.state.lastUpdated < this.#recentFetchThreshold\n );\n }\n\n /**\n * Triggers an update of the registry database.\n *\n * If an existing update is in progress this function will await that update.\n */\n async requestUpdate() {\n // If an update is ongoing, wait for that.\n if (this.#currentUpdate) {\n await this.#currentUpdate;\n return;\n }\n // If no update exists, create promise and store globally.\n if (this.#currentUpdate === null) {\n this.#currentUpdate = this.#update();\n }\n await this.#currentUpdate;\n this.#currentUpdate = null;\n }\n\n /**\n * Updates the registry database if the registry hasn't been updated recently.\n *\n * NOTE: SHOULD NOT be called directly, instead `triggerUpdate` should be used.\n */\n async #update() {\n // No-op if we recently fetched the registry.\n if (this.#wasRecentlyFetched()) {\n return;\n }\n\n try {\n const [database, signature] = await Promise.all([\n this.#safeFetch(this.#url.registry),\n this.#safeFetch(this.#url.signature),\n ]);\n\n const signatureJson = JSON.parse(signature);\n\n // If the signature matches the existing state, we can skip verification and don't need to update the database.\n if (signatureJson.signature === this.state.signature) {\n this.update((state) => {\n state.lastUpdated = Date.now();\n state.databaseUnavailable = false;\n });\n return;\n }\n\n await this.#verifySignature(database, signatureJson);\n\n this.update((state) => {\n state.database = JSON.parse(database);\n state.lastUpdated = Date.now();\n state.databaseUnavailable = false;\n state.signature = signatureJson.signature;\n });\n } catch {\n // Ignore\n this.update((state) => {\n state.databaseUnavailable = true;\n });\n }\n }\n\n async #getDatabase(): Promise<SnapsRegistryDatabase | null> {\n if (this.state.database === null) {\n await this.requestUpdate();\n }\n\n return this.state.database;\n }\n\n async #getSingle(\n snapId: string,\n snapInfo: SnapRegistryInfo,\n refetch = false,\n ): Promise<SnapRegistryResult> {\n const database = await this.#getDatabase();\n\n const blockedEntry = database?.blockedSnaps.find((blocked) => {\n if ('id' in blocked) {\n return (\n blocked.id === snapId &&\n satisfiesVersionRange(snapInfo.version, blocked.versionRange)\n );\n }\n\n return blocked.checksum === snapInfo.checksum;\n });\n\n if (blockedEntry) {\n return {\n status: SnapRegistryStatus.Blocked,\n reason: blockedEntry.reason,\n };\n }\n\n const verified = database?.verifiedSnaps[snapId];\n const version = verified?.versions?.[snapInfo.version];\n const clientRange = version?.clientVersions?.[this.#clientConfig.type];\n const isCompatible =\n !clientRange ||\n satisfiesVersionRange(this.#clientConfig.version, clientRange);\n if (version && version.checksum === snapInfo.checksum && isCompatible) {\n return { status: SnapRegistryStatus.Verified };\n }\n // For now, if we have an allowlist miss, we can refetch once and try again.\n if (this.#refetchOnAllowlistMiss && !refetch) {\n await this.requestUpdate();\n return this.#getSingle(snapId, snapInfo, true);\n }\n return {\n status: this.state.databaseUnavailable\n ? SnapRegistryStatus.Unavailable\n : SnapRegistryStatus.Unverified,\n };\n }\n\n async get(\n snaps: SnapRegistryRequest,\n ): Promise<Record<string, SnapRegistryResult>> {\n return Object.entries(snaps).reduce<\n Promise<Record<string, SnapRegistryResult>>\n >(async (previousPromise, [snapId, snapInfo]) => {\n const result = await this.#getSingle(snapId, snapInfo);\n const acc = await previousPromise;\n acc[snapId] = result;\n return acc;\n }, Promise.resolve({}));\n }\n\n /**\n * Find an allowlisted version within a specified version range. Otherwise return the version range itself.\n *\n * @param snapId - The ID of the snap we are trying to resolve a version for.\n * @param versionRange - The version range.\n * @param refetch - An optional flag used to determine if we are refetching the registry.\n * @returns An allowlisted version within the specified version range if available otherwise returns the input version range.\n */\n async resolveVersion(\n snapId: string,\n versionRange: SemVerRange,\n refetch = false,\n ): Promise<SemVerRange> {\n const database = await this.#getDatabase();\n const versions = database?.verifiedSnaps[snapId]?.versions ?? null;\n\n if (!versions && this.#refetchOnAllowlistMiss && !refetch) {\n await this.requestUpdate();\n return this.resolveVersion(snapId, versionRange, true);\n }\n\n // If we cannot narrow down the version range we return the unaltered version range.\n if (!versions) {\n return versionRange;\n }\n\n const compatibleVersions = Object.entries(versions).reduce<SemVerVersion[]>(\n (accumulator, [version, metadata]) => {\n const clientRange = metadata.clientVersions?.[this.#clientConfig.type];\n if (\n !clientRange ||\n satisfiesVersionRange(this.#clientConfig.version, clientRange)\n ) {\n accumulator.push(version as SemVerVersion);\n }\n\n return accumulator;\n },\n [],\n );\n\n const targetVersion = getTargetVersion(compatibleVersions, versionRange);\n\n if (!targetVersion && this.#refetchOnAllowlistMiss && !refetch) {\n await this.requestUpdate();\n return this.resolveVersion(snapId, versionRange, true);\n }\n\n // If we cannot narrow down the version range we return the unaltered version range.\n if (!targetVersion) {\n return versionRange;\n }\n\n // A semver version is technically also a valid semver range.\n assertIsSemVerRange(targetVersion);\n return targetVersion;\n }\n\n /**\n * Get metadata for the given snap ID, if available, without updating registry.\n *\n * @param snapId - The ID of the snap to get metadata for.\n * @returns The metadata for the given snap ID, or `null` if the snap is not\n * verified.\n */\n getMetadata(snapId: string): SnapRegistryMetadata | null {\n return this.state?.database?.verifiedSnaps[snapId]?.metadata ?? null;\n }\n\n /**\n * Verify the signature of the registry.\n *\n * @param database - The registry database.\n * @param signature - The signature of the registry.\n * @throws If the signature is invalid.\n */\n async #verifySignature(\n database: string,\n signature: Infer<typeof SignatureStruct>,\n ) {\n assert(this.#publicKey, 'No public key provided.');\n\n const valid = await verify({\n registry: database,\n signature,\n publicKey: this.#publicKey,\n });\n\n assert(valid, 'Invalid registry signature.');\n }\n\n /**\n * Fetch the given URL, throwing if the response is not OK.\n *\n * @param url - The URL to fetch.\n * @returns The response body.\n * @private\n */\n async #safeFetch(url: string) {\n const response = await this.#fetchFunction(url, { cache: 'no-cache' });\n if (!response.ok) {\n throw new Error(`Failed to fetch ${url}.`);\n }\n\n return await response.text();\n }\n}\n"]}
1
+ {"version":3,"file":"SnapRegistryController.cjs","sourceRoot":"","sources":["../../../src/snaps/registry/SnapRegistryController.ts"],"names":[],"mappings":";;;AAIA,+DAA2D;AAM3D,6DAAkD;AAClD,uDAAyD;AAGzD,2CAMyB;AASzB,uCAA6C;AAE7C,MAAM,iBAAiB,GACrB,wDAAwD,CAAC;AAE3D,MAAM,2BAA2B,GAC/B,yDAAyD,CAAC;AAE5D,MAAM,kBAAkB,GACtB,sEAAsE,CAAC;AA2DzE,MAAM,cAAc,GAAG,wBAAwB,CAAC;AAEhD,MAAM,yBAAyB,GAAG;IAChC,KAAK;IACL,aAAa;IACb,gBAAgB;IAChB,eAAe;CACP,CAAC;AAEX,MAAM,YAAY,GAAG;IACnB,QAAQ,EAAE,IAAI;IACd,SAAS,EAAE,IAAI;IACf,WAAW,EAAE,IAAI;IACjB,mBAAmB,EAAE,KAAK;CAC3B,CAAC;AAEF,MAAa,sBAAuB,SAAQ,gCAI3C;IACU,IAAI,CAAuB;IAE3B,UAAU,CAAM;IAEhB,aAAa,CAAe;IAE5B,cAAc,CAAe;IAE7B,qBAAqB,CAAS;IAE9B,uBAAuB,CAAU;IAE1C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IAED;;;;;;OAMG;IACH,KAAK,CAAC,gBAAgB,CACpB,QAAgB,EAChB,SAAwC;QAExC,IAAA,cAAM,EAAC,IAAI,CAAC,UAAU,EAAE,yBAAyB,CAAC,CAAC;QAEnD,MAAM,KAAK,GAAG,MAAM,IAAA,uBAAM,EAAC;YACzB,QAAQ,EAAE,QAAQ;YAClB,SAAS;YACT,SAAS,EAAE,IAAI,CAAC,UAAU;SAC3B,CAAC,CAAC;QAEH,IAAA,cAAM,EAAC,KAAK,EAAE,6BAA6B,CAAC,CAAC;IAC/C,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,UAAU,CAAC,GAAW;QAC1B,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC,CAAC;QACvE,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CAAC,mBAAmB,GAAG,GAAG,CAAC,CAAC;QAC7C,CAAC;QAED,OAAO,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;IAC/B,CAAC;CACF;AAvUD,wDAuUC","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type { Messenger } from '@metamask/messenger';\nimport type {\n SnapsRegistryDatabase,\n SignatureStruct,\n} from '@metamask/snaps-registry';\nimport { verify } from '@metamask/snaps-registry';\nimport { getTargetVersion } from '@metamask/snaps-utils';\nimport type { Infer } from '@metamask/superstruct';\nimport type { Hex, SemVerRange, SemVerVersion } from '@metamask/utils';\nimport {\n assert,\n assertIsSemVerRange,\n Duration,\n inMilliseconds,\n satisfiesVersionRange,\n} from '@metamask/utils';\n\nimport type { SnapRegistryControllerMethodActions } from './SnapRegistryController-method-action-types';\nimport type {\n SnapRegistryInfo,\n SnapRegistryMetadata,\n SnapRegistryRequest,\n SnapRegistryResult,\n} from './types';\nimport { SnapRegistryStatus } from './types';\n\nconst SNAP_REGISTRY_URL =\n 'https://acl.execution.metamask.io/latest/registry.json';\n\nconst SNAP_REGISTRY_SIGNATURE_URL =\n 'https://acl.execution.metamask.io/latest/signature.json';\n\nconst DEFAULT_PUBLIC_KEY =\n '0x025b65308f0f0fb8bc7f7ff87bfc296e0330eee5d3c1d1ee4a048b2fd6a86fa0a6';\n\ntype JsonSnapsRegistryUrl = {\n registry: string;\n signature: string;\n};\n\nexport type ClientConfig = {\n type: 'extension' | 'mobile';\n version: SemVerVersion;\n};\n\nexport type SnapRegistryControllerArgs = {\n messenger: SnapRegistryControllerMessenger;\n state?: SnapRegistryControllerState;\n fetchFunction?: typeof fetch;\n url?: JsonSnapsRegistryUrl;\n recentFetchThreshold?: number;\n refetchOnAllowlistMiss?: boolean;\n publicKey?: Hex;\n clientConfig: ClientConfig;\n};\n\nexport type SnapRegistryControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n SnapRegistryControllerState\n>;\n\nexport type SnapRegistryControllerActions =\n | SnapRegistryControllerGetStateAction\n | SnapRegistryControllerMethodActions;\n\nexport type SnapRegistryControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof controllerName,\n SnapRegistryControllerState\n>;\n\nexport type SnapRegistryControllerRegistryUpdatedEvent = {\n type: `${typeof controllerName}:registryUpdated`;\n payload: [databaseUpdated: boolean];\n};\n\nexport type SnapRegistryControllerEvents =\n | SnapRegistryControllerStateChangeEvent\n | SnapRegistryControllerRegistryUpdatedEvent;\n\nexport type SnapRegistryControllerMessenger = Messenger<\n typeof controllerName,\n SnapRegistryControllerActions,\n SnapRegistryControllerEvents\n>;\n\nexport type SnapRegistryControllerState = {\n database: SnapsRegistryDatabase | null;\n signature: string | null;\n lastUpdated: number | null;\n databaseUnavailable: boolean;\n};\n\nconst controllerName = 'SnapRegistryController';\n\nconst MESSENGER_EXPOSED_METHODS = [\n 'get',\n 'getMetadata',\n 'resolveVersion',\n 'requestUpdate',\n] as const;\n\nconst defaultState = {\n database: null,\n signature: null,\n lastUpdated: null,\n databaseUnavailable: false,\n};\n\nexport class SnapRegistryController extends BaseController<\n typeof controllerName,\n SnapRegistryControllerState,\n SnapRegistryControllerMessenger\n> {\n readonly #url: JsonSnapsRegistryUrl;\n\n readonly #publicKey: Hex;\n\n readonly #clientConfig: ClientConfig;\n\n readonly #fetchFunction: typeof fetch;\n\n readonly #recentFetchThreshold: number;\n\n readonly #refetchOnAllowlistMiss: boolean;\n\n #currentUpdate: Promise<void> | null;\n\n constructor({\n messenger,\n state,\n url = {\n registry: SNAP_REGISTRY_URL,\n signature: SNAP_REGISTRY_SIGNATURE_URL,\n },\n publicKey = DEFAULT_PUBLIC_KEY,\n clientConfig,\n fetchFunction = globalThis.fetch.bind(undefined),\n recentFetchThreshold = inMilliseconds(5, Duration.Minute),\n refetchOnAllowlistMiss = true,\n }: SnapRegistryControllerArgs) {\n super({\n messenger,\n metadata: {\n database: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n signature: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: true,\n usedInUi: false,\n },\n lastUpdated: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: true,\n usedInUi: false,\n },\n databaseUnavailable: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: true,\n usedInUi: false,\n },\n },\n name: controllerName,\n state: {\n ...defaultState,\n ...state,\n },\n });\n this.#url = url;\n this.#publicKey = publicKey;\n this.#clientConfig = clientConfig;\n this.#fetchFunction = fetchFunction;\n this.#recentFetchThreshold = recentFetchThreshold;\n this.#refetchOnAllowlistMiss = refetchOnAllowlistMiss;\n this.#currentUpdate = null;\n\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n }\n\n #wasRecentlyFetched() {\n return (\n this.state.lastUpdated &&\n Date.now() - this.state.lastUpdated < this.#recentFetchThreshold\n );\n }\n\n /**\n * Triggers an update of the registry database.\n *\n * If an existing update is in progress this function will await that update.\n */\n async requestUpdate() {\n // If an update is ongoing, wait for that.\n if (this.#currentUpdate) {\n await this.#currentUpdate;\n return;\n }\n // If no update exists, create promise and store globally.\n if (this.#currentUpdate === null) {\n this.#currentUpdate = this.#update();\n }\n await this.#currentUpdate;\n this.#currentUpdate = null;\n }\n\n /**\n * Updates the registry database if the registry hasn't been updated recently.\n *\n * NOTE: SHOULD NOT be called directly, instead `triggerUpdate` should be used.\n */\n async #update() {\n // No-op if we recently fetched the registry.\n if (this.#wasRecentlyFetched()) {\n this.messenger.publish('SnapRegistryController:registryUpdated', false);\n return;\n }\n\n try {\n const [database, signature] = await Promise.all([\n this.#safeFetch(this.#url.registry),\n this.#safeFetch(this.#url.signature),\n ]);\n\n const signatureJson = JSON.parse(signature);\n\n // If the signature matches the existing state, we can skip verification and don't need to update the database.\n if (signatureJson.signature === this.state.signature) {\n this.update((state) => {\n state.lastUpdated = Date.now();\n state.databaseUnavailable = false;\n });\n this.messenger.publish('SnapRegistryController:registryUpdated', false);\n return;\n }\n\n await this.#verifySignature(database, signatureJson);\n\n this.update((state) => {\n state.database = JSON.parse(database);\n state.lastUpdated = Date.now();\n state.databaseUnavailable = false;\n state.signature = signatureJson.signature;\n });\n\n this.messenger.publish('SnapRegistryController:registryUpdated', true);\n } catch {\n // Ignore\n this.update((state) => {\n state.databaseUnavailable = true;\n });\n }\n }\n\n async #getDatabase(): Promise<SnapsRegistryDatabase | null> {\n if (this.state.database === null) {\n await this.requestUpdate();\n }\n\n return this.state.database;\n }\n\n async #getSingle(\n snapId: string,\n snapInfo: SnapRegistryInfo,\n refetch = false,\n ): Promise<SnapRegistryResult> {\n const database = await this.#getDatabase();\n\n const blockedEntry = database?.blockedSnaps.find((blocked) => {\n if ('id' in blocked) {\n return (\n blocked.id === snapId &&\n satisfiesVersionRange(snapInfo.version, blocked.versionRange)\n );\n }\n\n return blocked.checksum === snapInfo.checksum;\n });\n\n if (blockedEntry) {\n return {\n status: SnapRegistryStatus.Blocked,\n reason: blockedEntry.reason,\n };\n }\n\n const verified = database?.verifiedSnaps[snapId];\n const version = verified?.versions?.[snapInfo.version];\n const clientRange = version?.clientVersions?.[this.#clientConfig.type];\n const isCompatible =\n !clientRange ||\n satisfiesVersionRange(this.#clientConfig.version, clientRange);\n if (version && version.checksum === snapInfo.checksum && isCompatible) {\n return { status: SnapRegistryStatus.Verified };\n }\n // For now, if we have an allowlist miss, we can refetch once and try again.\n if (this.#refetchOnAllowlistMiss && !refetch) {\n await this.requestUpdate();\n return this.#getSingle(snapId, snapInfo, true);\n }\n return {\n status: this.state.databaseUnavailable\n ? SnapRegistryStatus.Unavailable\n : SnapRegistryStatus.Unverified,\n };\n }\n\n async get(\n snaps: SnapRegistryRequest,\n ): Promise<Record<string, SnapRegistryResult>> {\n return Object.entries(snaps).reduce<\n Promise<Record<string, SnapRegistryResult>>\n >(async (previousPromise, [snapId, snapInfo]) => {\n const result = await this.#getSingle(snapId, snapInfo);\n const acc = await previousPromise;\n acc[snapId] = result;\n return acc;\n }, Promise.resolve({}));\n }\n\n /**\n * Find an allowlisted version within a specified version range. Otherwise return the version range itself.\n *\n * @param snapId - The ID of the snap we are trying to resolve a version for.\n * @param versionRange - The version range.\n * @param refetch - An optional flag used to determine if we are refetching the registry.\n * @returns An allowlisted version within the specified version range if available otherwise returns the input version range.\n */\n async resolveVersion(\n snapId: string,\n versionRange: SemVerRange,\n refetch = false,\n ): Promise<SemVerRange> {\n const database = await this.#getDatabase();\n const versions = database?.verifiedSnaps[snapId]?.versions ?? null;\n\n if (!versions && this.#refetchOnAllowlistMiss && !refetch) {\n await this.requestUpdate();\n return this.resolveVersion(snapId, versionRange, true);\n }\n\n // If we cannot narrow down the version range we return the unaltered version range.\n if (!versions) {\n return versionRange;\n }\n\n const compatibleVersions = Object.entries(versions).reduce<SemVerVersion[]>(\n (accumulator, [version, metadata]) => {\n const clientRange = metadata.clientVersions?.[this.#clientConfig.type];\n if (\n !clientRange ||\n satisfiesVersionRange(this.#clientConfig.version, clientRange)\n ) {\n accumulator.push(version as SemVerVersion);\n }\n\n return accumulator;\n },\n [],\n );\n\n const targetVersion = getTargetVersion(compatibleVersions, versionRange);\n\n if (!targetVersion && this.#refetchOnAllowlistMiss && !refetch) {\n await this.requestUpdate();\n return this.resolveVersion(snapId, versionRange, true);\n }\n\n // If we cannot narrow down the version range we return the unaltered version range.\n if (!targetVersion) {\n return versionRange;\n }\n\n // A semver version is technically also a valid semver range.\n assertIsSemVerRange(targetVersion);\n return targetVersion;\n }\n\n /**\n * Get metadata for the given snap ID, if available, without updating registry.\n *\n * @param snapId - The ID of the snap to get metadata for.\n * @returns The metadata for the given snap ID, or `null` if the snap is not\n * verified.\n */\n getMetadata(snapId: string): SnapRegistryMetadata | null {\n return this.state?.database?.verifiedSnaps[snapId]?.metadata ?? null;\n }\n\n /**\n * Verify the signature of the registry.\n *\n * @param database - The registry database.\n * @param signature - The signature of the registry.\n * @throws If the signature is invalid.\n */\n async #verifySignature(\n database: string,\n signature: Infer<typeof SignatureStruct>,\n ) {\n assert(this.#publicKey, 'No public key provided.');\n\n const valid = await verify({\n registry: database,\n signature,\n publicKey: this.#publicKey,\n });\n\n assert(valid, 'Invalid registry signature.');\n }\n\n /**\n * Fetch the given URL, throwing if the response is not OK.\n *\n * @param url - The URL to fetch.\n * @returns The response body.\n * @private\n */\n async #safeFetch(url: string) {\n const response = await this.#fetchFunction(url, { cache: 'no-cache' });\n if (!response.ok) {\n throw new Error(`Failed to fetch ${url}.`);\n }\n\n return await response.text();\n }\n}\n"]}
@@ -26,7 +26,11 @@ export type SnapRegistryControllerArgs = {
26
26
  export type SnapRegistryControllerGetStateAction = ControllerGetStateAction<typeof controllerName, SnapRegistryControllerState>;
27
27
  export type SnapRegistryControllerActions = SnapRegistryControllerGetStateAction | SnapRegistryControllerMethodActions;
28
28
  export type SnapRegistryControllerStateChangeEvent = ControllerStateChangeEvent<typeof controllerName, SnapRegistryControllerState>;
29
- export type SnapRegistryControllerEvents = SnapRegistryControllerStateChangeEvent;
29
+ export type SnapRegistryControllerRegistryUpdatedEvent = {
30
+ type: `${typeof controllerName}:registryUpdated`;
31
+ payload: [databaseUpdated: boolean];
32
+ };
33
+ export type SnapRegistryControllerEvents = SnapRegistryControllerStateChangeEvent | SnapRegistryControllerRegistryUpdatedEvent;
30
34
  export type SnapRegistryControllerMessenger = Messenger<typeof controllerName, SnapRegistryControllerActions, SnapRegistryControllerEvents>;
31
35
  export type SnapRegistryControllerState = {
32
36
  database: SnapsRegistryDatabase | null;
@@ -1 +1 @@
1
- {"version":3,"file":"SnapRegistryController.d.cts","sourceRoot":"","sources":["../../../src/snaps/registry/SnapRegistryController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC3B,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,EACV,qBAAqB,EAEtB,iCAAiC;AAIlC,OAAO,KAAK,EAAE,GAAG,EAAE,WAAW,EAAE,aAAa,EAAE,wBAAwB;AASvE,OAAO,KAAK,EAAE,mCAAmC,EAAE,yDAAqD;AACxG,OAAO,KAAK,EAEV,oBAAoB,EACpB,mBAAmB,EACnB,kBAAkB,EACnB,oBAAgB;AAYjB,KAAK,oBAAoB,GAAG;IAC1B,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,EAAE,WAAW,GAAG,QAAQ,CAAC;IAC7B,OAAO,EAAE,aAAa,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,0BAA0B,GAAG;IACvC,SAAS,EAAE,+BAA+B,CAAC;IAC3C,KAAK,CAAC,EAAE,2BAA2B,CAAC;IACpC,aAAa,CAAC,EAAE,OAAO,KAAK,CAAC;IAC7B,GAAG,CAAC,EAAE,oBAAoB,CAAC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UAAQ,GACd,OAAO,CAAC,WAAW,CAAC;IA8CvB;;;;;;OAMG;IACH,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,oBAAoB,GAAG,IAAI;CAyCzD"}
1
+ {"version":3,"file":"SnapRegistryController.d.cts","sourceRoot":"","sources":["../../../src/snaps/registry/SnapRegistryController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC3B,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,EACV,qBAAqB,EAEtB,iCAAiC;AAIlC,OAAO,KAAK,EAAE,GAAG,EAAE,WAAW,EAAE,aAAa,EAAE,wBAAwB;AASvE,OAAO,KAAK,EAAE,mCAAmC,EAAE,yDAAqD;AACxG,OAAO,KAAK,EAEV,oBAAoB,EACpB,mBAAmB,EACnB,kBAAkB,EACnB,oBAAgB;AAYjB,KAAK,oBAAoB,GAAG;IAC1B,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,EAAE,WAAW,GAAG,QAAQ,CAAC;IAC7B,OAAO,EAAE,aAAa,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,0BAA0B,GAAG;IACvC,SAAS,EAAE,+BAA+B,CAAC;IAC3C,KAAK,CAAC,EAAE,2BAA2B,CAAC;IACpC,aAAa,CAAC,EAAE,OAAO,KAAK,CAAC;IAC7B,GAAG,CAAC,EAAE,oBAAoB,CAAC;IAC3B,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,sBAAsB,CAAC,EAAE,OAAO,CAAC;IACjC,SAAS,CAAC,EAAE,GAAG,CAAC;IAChB,YAAY,EAAE,YAAY,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,oCAAoC,GAAG,wBAAwB,CACzE,OAAO,cAAc,EAC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ACH,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,oBAAoB,GAAG,IAAI;CAyCzD"}
@@ -26,7 +26,11 @@ export type SnapRegistryControllerArgs = {
26
26
  export type SnapRegistryControllerGetStateAction = ControllerGetStateAction<typeof controllerName, SnapRegistryControllerState>;
27
27
  export type SnapRegistryControllerActions = SnapRegistryControllerGetStateAction | SnapRegistryControllerMethodActions;
28
28
  export type SnapRegistryControllerStateChangeEvent = ControllerStateChangeEvent<typeof controllerName, SnapRegistryControllerState>;
29
- export type SnapRegistryControllerEvents = SnapRegistryControllerStateChangeEvent;
29
+ export type SnapRegistryControllerRegistryUpdatedEvent = {
30
+ type: `${typeof controllerName}:registryUpdated`;
31
+ payload: [databaseUpdated: boolean];
32
+ };
33
+ export type SnapRegistryControllerEvents = SnapRegistryControllerStateChangeEvent | SnapRegistryControllerRegistryUpdatedEvent;
30
34
  export type SnapRegistryControllerMessenger = Messenger<typeof controllerName, SnapRegistryControllerActions, SnapRegistryControllerEvents>;
31
35
  export type SnapRegistryControllerState = {
32
36
  database: SnapsRegistryDatabase | null;
@@ -1 +1 @@
1
- {"version":3,"file":"SnapRegistryController.d.mts","sourceRoot":"","sources":["../../../src/snaps/registry/SnapRegistryController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC3B,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,EACV,qBAAqB,EAEtB,iCAAiC;AAIlC,OAAO,KAAK,EAAE,GAAG,EAAE,WAAW,EAAE,aAAa,EAAE,wBAAwB;AASvE,OAAO,KAAK,EAAE,mCAAmC,EAAE,yDAAqD;AACxG,OAAO,KAAK,EAEV,oBAAoB,EACpB,mBAAmB,EACnB,kBAAkB,EACnB,oBAAgB;AAYjB,KAAK,oBAAoB,GAAG;IAC1B,QAAQ,EAAE,MAAM,CAAC;IACjB,SA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AAS,EACT,KAAK,EACL,GAGC,EACD,SAA8B,EAC9B,YAAY,EACZ,aAAgD,EAChD,oBAAyD,EACzD,sBAA6B,GAC9B,EAAE,0BAA0B;IAwD7B;;;;OAIG;IACG,aAAa;IAgHb,GAAG,CACP,KAAK,EAAE,mBAAmB,GACzB,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;IAW9C;;;;;;;OAOG;IACG,cAAc,CAClB,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,WAAW,EACzB,OAAO,UAAQ,GACd,OAAO,CAAC,WAAW,CAAC;IA8CvB;;;;;;OAMG;IACH,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,oBAAoB,GAAG,IAAI;CAyCzD"}
1
+ {"version":3,"file":"SnapRegistryController.d.mts","sourceRoot":"","sources":["../../../src/snaps/registry/SnapRegistryController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC3B,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,EACV,qBAAqB,EAEtB,iCAAiC;AAIlC,OAAO,KAAK,EAAE,GAAG,EAAE,WAAW,EAAE,aAAa,EAAE,wBAAwB;AASvE,OAAO,KAAK,EAAE,mCAAmC,EAAE,yDAAqD;AACxG,OAAO,KAAK,EAEV,oBAAoB,EACpB,mBAAmB,EACnB,kBAAkB,EACnB,oBAAgB;AAYjB,KAAK,oBAAoB,GAAG;IAC1B,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,EAAE,WAAW,GAAG,QAAQ,CAAC;IAC7B,OAAO,EAAE,aAAa,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,0BAA0B,GAAG;IACvC,SAAS,EAAE,+BAA+B,CAAC;IAC3C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aAAgD,EAChD,oBAAyD,EACzD,sBAA6B,GAC9B,EAAE,0BAA0B;IAwD7B;;;;OAIG;IACG,aAAa;IAoHb,GAAG,CACP,KAAK,EAAE,mBAAmB,GACzB,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;IAW9C;;;;;;;OAOG;IACG,cAAc,CAClB,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,WAAW,EACzB,OAAO,UAAQ,GACd,OAAO,CAAC,WAAW,CAAC;IA8CvB;;;;;;OAMG;IACH,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,oBAAoB,GAAG,IAAI;CAyCzD"}
@@ -104,6 +104,7 @@ export class SnapRegistryController extends BaseController {
104
104
  async #update() {
105
105
  // No-op if we recently fetched the registry.
106
106
  if (this.#wasRecentlyFetched()) {
107
+ this.messenger.publish('SnapRegistryController:registryUpdated', false);
107
108
  return;
108
109
  }
109
110
  try {
@@ -118,6 +119,7 @@ export class SnapRegistryController extends BaseController {
118
119
  state.lastUpdated = Date.now();
119
120
  state.databaseUnavailable = false;
120
121
  });
122
+ this.messenger.publish('SnapRegistryController:registryUpdated', false);
121
123
  return;
122
124
  }
123
125
  await this.#verifySignature(database, signatureJson);
@@ -127,6 +129,7 @@ export class SnapRegistryController extends BaseController {
127
129
  state.databaseUnavailable = false;
128
130
  state.signature = signatureJson.signature;
129
131
  });
132
+ this.messenger.publish('SnapRegistryController:registryUpdated', true);
130
133
  }
131
134
  catch {
132
135
  // Ignore
@@ -1 +1 @@
1
- {"version":3,"file":"SnapRegistryController.mjs","sourceRoot":"","sources":["../../../src/snaps/registry/SnapRegistryController.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAM3D,OAAO,EAAE,MAAM,EAAE,iCAAiC;AAClD,OAAO,EAAE,gBAAgB,EAAE,8BAA8B;AAGzD,OAAO,EACL,MAAM,EACN,mBAAmB,EACnB,QAAQ,EACR,cAAc,EACd,qBAAqB,EACt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QACzD,CAAC;QAED,oFAAoF;QACpF,IAAI,CAAC,aAAa,EAAE,CAAC;YACnB,OAAO,YAAY,CAAC;QACtB,CAAC;QAED,6DAA6D;QAC7D,mBAAmB,CAAC,aAAa,CAAC,CAAC;QACnC,OAAO,aAAa,CAAC;IACvB,CAAC;IAED;;;;;;OAMG;IACH,WAAW,CAAC,MAAc;QACxB,OAAO,IAAI,CAAC,KAAK,EAAE,QAAQ,EAAE,aAAa,CAAC,MAAM,CAAC,EAAE,QAAQ,IAAI,IAAI,CAAC;IACvE,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,gBAAgB,CACpB,QAAgB,EAChB,SAAwC;QAExC,MAAM,CAAC,IAAI,CAAC,UAAU,EAAE,yBAAyB,CAAC,CAAC;QAEnD,MAAM,KAAK,GAAG,MAAM,MAAM,CAAC;YACzB,QAAQ,EAAE,QAAQ;YAClB,SAAS;YACT,SAAS,EAAE,IAAI,CAAC,UAAU;SAC3B,CAAC,CAAC;QAEH,MAAM,CAAC,KAAK,EAAE,6BAA6B,CAAC,CAAC;IAC/C,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,UAAU,CAAC,GAAW;QAC1B,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC,CAAC;QACvE,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CAAC,mBAAmB,GAAG,GAAG,CAAC,CAAC;QAC7C,CAAC;QAED,OAAO,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;IAC/B,CAAC;CACF","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type { Messenger } from '@metamask/messenger';\nimport type {\n SnapsRegistryDatabase,\n SignatureStruct,\n} from '@metamask/snaps-registry';\nimport { verify } from '@metamask/snaps-registry';\nimport { getTargetVersion } from '@metamask/snaps-utils';\nimport type { Infer } from '@metamask/superstruct';\nimport type { Hex, SemVerRange, SemVerVersion } from '@metamask/utils';\nimport {\n assert,\n assertIsSemVerRange,\n Duration,\n inMilliseconds,\n satisfiesVersionRange,\n} from '@metamask/utils';\n\nimport type { SnapRegistryControllerMethodActions } from './SnapRegistryController-method-action-types';\nimport type {\n SnapRegistryInfo,\n SnapRegistryMetadata,\n SnapRegistryRequest,\n SnapRegistryResult,\n} from './types';\nimport { SnapRegistryStatus } from './types';\n\nconst SNAP_REGISTRY_URL =\n 'https://acl.execution.metamask.io/latest/registry.json';\n\nconst SNAP_REGISTRY_SIGNATURE_URL =\n 'https://acl.execution.metamask.io/latest/signature.json';\n\nconst DEFAULT_PUBLIC_KEY =\n '0x025b65308f0f0fb8bc7f7ff87bfc296e0330eee5d3c1d1ee4a048b2fd6a86fa0a6';\n\ntype JsonSnapsRegistryUrl = {\n registry: string;\n signature: string;\n};\n\nexport type ClientConfig = {\n type: 'extension' | 'mobile';\n version: SemVerVersion;\n};\n\nexport type SnapRegistryControllerArgs = {\n messenger: SnapRegistryControllerMessenger;\n state?: SnapRegistryControllerState;\n fetchFunction?: typeof fetch;\n url?: JsonSnapsRegistryUrl;\n recentFetchThreshold?: number;\n refetchOnAllowlistMiss?: boolean;\n publicKey?: Hex;\n clientConfig: ClientConfig;\n};\n\nexport type SnapRegistryControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n SnapRegistryControllerState\n>;\n\nexport type SnapRegistryControllerActions =\n | SnapRegistryControllerGetStateAction\n | SnapRegistryControllerMethodActions;\n\nexport type SnapRegistryControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof controllerName,\n SnapRegistryControllerState\n>;\n\nexport type SnapRegistryControllerEvents =\n SnapRegistryControllerStateChangeEvent;\n\nexport type SnapRegistryControllerMessenger = Messenger<\n typeof controllerName,\n SnapRegistryControllerActions,\n SnapRegistryControllerEvents\n>;\n\nexport type SnapRegistryControllerState = {\n database: SnapsRegistryDatabase | null;\n signature: string | null;\n lastUpdated: number | null;\n databaseUnavailable: boolean;\n};\n\nconst controllerName = 'SnapRegistryController';\n\nconst MESSENGER_EXPOSED_METHODS = [\n 'get',\n 'getMetadata',\n 'resolveVersion',\n 'requestUpdate',\n] as const;\n\nconst defaultState = {\n database: null,\n signature: null,\n lastUpdated: null,\n databaseUnavailable: false,\n};\n\nexport class SnapRegistryController extends BaseController<\n typeof controllerName,\n SnapRegistryControllerState,\n SnapRegistryControllerMessenger\n> {\n readonly #url: JsonSnapsRegistryUrl;\n\n readonly #publicKey: Hex;\n\n readonly #clientConfig: ClientConfig;\n\n readonly #fetchFunction: typeof fetch;\n\n readonly #recentFetchThreshold: number;\n\n readonly #refetchOnAllowlistMiss: boolean;\n\n #currentUpdate: Promise<void> | null;\n\n constructor({\n messenger,\n state,\n url = {\n registry: SNAP_REGISTRY_URL,\n signature: SNAP_REGISTRY_SIGNATURE_URL,\n },\n publicKey = DEFAULT_PUBLIC_KEY,\n clientConfig,\n fetchFunction = globalThis.fetch.bind(undefined),\n recentFetchThreshold = inMilliseconds(5, Duration.Minute),\n refetchOnAllowlistMiss = true,\n }: SnapRegistryControllerArgs) {\n super({\n messenger,\n metadata: {\n database: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n signature: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: true,\n usedInUi: false,\n },\n lastUpdated: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: true,\n usedInUi: false,\n },\n databaseUnavailable: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: true,\n usedInUi: false,\n },\n },\n name: controllerName,\n state: {\n ...defaultState,\n ...state,\n },\n });\n this.#url = url;\n this.#publicKey = publicKey;\n this.#clientConfig = clientConfig;\n this.#fetchFunction = fetchFunction;\n this.#recentFetchThreshold = recentFetchThreshold;\n this.#refetchOnAllowlistMiss = refetchOnAllowlistMiss;\n this.#currentUpdate = null;\n\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n }\n\n #wasRecentlyFetched() {\n return (\n this.state.lastUpdated &&\n Date.now() - this.state.lastUpdated < this.#recentFetchThreshold\n );\n }\n\n /**\n * Triggers an update of the registry database.\n *\n * If an existing update is in progress this function will await that update.\n */\n async requestUpdate() {\n // If an update is ongoing, wait for that.\n if (this.#currentUpdate) {\n await this.#currentUpdate;\n return;\n }\n // If no update exists, create promise and store globally.\n if (this.#currentUpdate === null) {\n this.#currentUpdate = this.#update();\n }\n await this.#currentUpdate;\n this.#currentUpdate = null;\n }\n\n /**\n * Updates the registry database if the registry hasn't been updated recently.\n *\n * NOTE: SHOULD NOT be called directly, instead `triggerUpdate` should be used.\n */\n async #update() {\n // No-op if we recently fetched the registry.\n if (this.#wasRecentlyFetched()) {\n return;\n }\n\n try {\n const [database, signature] = await Promise.all([\n this.#safeFetch(this.#url.registry),\n this.#safeFetch(this.#url.signature),\n ]);\n\n const signatureJson = JSON.parse(signature);\n\n // If the signature matches the existing state, we can skip verification and don't need to update the database.\n if (signatureJson.signature === this.state.signature) {\n this.update((state) => {\n state.lastUpdated = Date.now();\n state.databaseUnavailable = false;\n });\n return;\n }\n\n await this.#verifySignature(database, signatureJson);\n\n this.update((state) => {\n state.database = JSON.parse(database);\n state.lastUpdated = Date.now();\n state.databaseUnavailable = false;\n state.signature = signatureJson.signature;\n });\n } catch {\n // Ignore\n this.update((state) => {\n state.databaseUnavailable = true;\n });\n }\n }\n\n async #getDatabase(): Promise<SnapsRegistryDatabase | null> {\n if (this.state.database === null) {\n await this.requestUpdate();\n }\n\n return this.state.database;\n }\n\n async #getSingle(\n snapId: string,\n snapInfo: SnapRegistryInfo,\n refetch = false,\n ): Promise<SnapRegistryResult> {\n const database = await this.#getDatabase();\n\n const blockedEntry = database?.blockedSnaps.find((blocked) => {\n if ('id' in blocked) {\n return (\n blocked.id === snapId &&\n satisfiesVersionRange(snapInfo.version, blocked.versionRange)\n );\n }\n\n return blocked.checksum === snapInfo.checksum;\n });\n\n if (blockedEntry) {\n return {\n status: SnapRegistryStatus.Blocked,\n reason: blockedEntry.reason,\n };\n }\n\n const verified = database?.verifiedSnaps[snapId];\n const version = verified?.versions?.[snapInfo.version];\n const clientRange = version?.clientVersions?.[this.#clientConfig.type];\n const isCompatible =\n !clientRange ||\n satisfiesVersionRange(this.#clientConfig.version, clientRange);\n if (version && version.checksum === snapInfo.checksum && isCompatible) {\n return { status: SnapRegistryStatus.Verified };\n }\n // For now, if we have an allowlist miss, we can refetch once and try again.\n if (this.#refetchOnAllowlistMiss && !refetch) {\n await this.requestUpdate();\n return this.#getSingle(snapId, snapInfo, true);\n }\n return {\n status: this.state.databaseUnavailable\n ? SnapRegistryStatus.Unavailable\n : SnapRegistryStatus.Unverified,\n };\n }\n\n async get(\n snaps: SnapRegistryRequest,\n ): Promise<Record<string, SnapRegistryResult>> {\n return Object.entries(snaps).reduce<\n Promise<Record<string, SnapRegistryResult>>\n >(async (previousPromise, [snapId, snapInfo]) => {\n const result = await this.#getSingle(snapId, snapInfo);\n const acc = await previousPromise;\n acc[snapId] = result;\n return acc;\n }, Promise.resolve({}));\n }\n\n /**\n * Find an allowlisted version within a specified version range. Otherwise return the version range itself.\n *\n * @param snapId - The ID of the snap we are trying to resolve a version for.\n * @param versionRange - The version range.\n * @param refetch - An optional flag used to determine if we are refetching the registry.\n * @returns An allowlisted version within the specified version range if available otherwise returns the input version range.\n */\n async resolveVersion(\n snapId: string,\n versionRange: SemVerRange,\n refetch = false,\n ): Promise<SemVerRange> {\n const database = await this.#getDatabase();\n const versions = database?.verifiedSnaps[snapId]?.versions ?? null;\n\n if (!versions && this.#refetchOnAllowlistMiss && !refetch) {\n await this.requestUpdate();\n return this.resolveVersion(snapId, versionRange, true);\n }\n\n // If we cannot narrow down the version range we return the unaltered version range.\n if (!versions) {\n return versionRange;\n }\n\n const compatibleVersions = Object.entries(versions).reduce<SemVerVersion[]>(\n (accumulator, [version, metadata]) => {\n const clientRange = metadata.clientVersions?.[this.#clientConfig.type];\n if (\n !clientRange ||\n satisfiesVersionRange(this.#clientConfig.version, clientRange)\n ) {\n accumulator.push(version as SemVerVersion);\n }\n\n return accumulator;\n },\n [],\n );\n\n const targetVersion = getTargetVersion(compatibleVersions, versionRange);\n\n if (!targetVersion && this.#refetchOnAllowlistMiss && !refetch) {\n await this.requestUpdate();\n return this.resolveVersion(snapId, versionRange, true);\n }\n\n // If we cannot narrow down the version range we return the unaltered version range.\n if (!targetVersion) {\n return versionRange;\n }\n\n // A semver version is technically also a valid semver range.\n assertIsSemVerRange(targetVersion);\n return targetVersion;\n }\n\n /**\n * Get metadata for the given snap ID, if available, without updating registry.\n *\n * @param snapId - The ID of the snap to get metadata for.\n * @returns The metadata for the given snap ID, or `null` if the snap is not\n * verified.\n */\n getMetadata(snapId: string): SnapRegistryMetadata | null {\n return this.state?.database?.verifiedSnaps[snapId]?.metadata ?? null;\n }\n\n /**\n * Verify the signature of the registry.\n *\n * @param database - The registry database.\n * @param signature - The signature of the registry.\n * @throws If the signature is invalid.\n */\n async #verifySignature(\n database: string,\n signature: Infer<typeof SignatureStruct>,\n ) {\n assert(this.#publicKey, 'No public key provided.');\n\n const valid = await verify({\n registry: database,\n signature,\n publicKey: this.#publicKey,\n });\n\n assert(valid, 'Invalid registry signature.');\n }\n\n /**\n * Fetch the given URL, throwing if the response is not OK.\n *\n * @param url - The URL to fetch.\n * @returns The response body.\n * @private\n */\n async #safeFetch(url: string) {\n const response = await this.#fetchFunction(url, { cache: 'no-cache' });\n if (!response.ok) {\n throw new Error(`Failed to fetch ${url}.`);\n }\n\n return await response.text();\n }\n}\n"]}
1
+ {"version":3,"file":"SnapRegistryController.mjs","sourceRoot":"","sources":["../../../src/snaps/registry/SnapRegistryController.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAM3D,OAAO,EAAE,MAAM,EAAE,iCAAiC;AAClD,OAAO,EAA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,KAAK,CAAC,mBAAmB,GAAG,GAAG,CAAC,CAAC;QAC7C,CAAC;QAED,OAAO,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;IAC/B,CAAC;CACF","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type { Messenger } from '@metamask/messenger';\nimport type {\n SnapsRegistryDatabase,\n SignatureStruct,\n} from '@metamask/snaps-registry';\nimport { verify } from '@metamask/snaps-registry';\nimport { getTargetVersion } from '@metamask/snaps-utils';\nimport type { Infer } from '@metamask/superstruct';\nimport type { Hex, SemVerRange, SemVerVersion } from '@metamask/utils';\nimport {\n assert,\n assertIsSemVerRange,\n Duration,\n inMilliseconds,\n satisfiesVersionRange,\n} from '@metamask/utils';\n\nimport type { SnapRegistryControllerMethodActions } from './SnapRegistryController-method-action-types';\nimport type {\n SnapRegistryInfo,\n SnapRegistryMetadata,\n SnapRegistryRequest,\n SnapRegistryResult,\n} from './types';\nimport { SnapRegistryStatus } from './types';\n\nconst SNAP_REGISTRY_URL =\n 'https://acl.execution.metamask.io/latest/registry.json';\n\nconst SNAP_REGISTRY_SIGNATURE_URL =\n 'https://acl.execution.metamask.io/latest/signature.json';\n\nconst DEFAULT_PUBLIC_KEY =\n '0x025b65308f0f0fb8bc7f7ff87bfc296e0330eee5d3c1d1ee4a048b2fd6a86fa0a6';\n\ntype JsonSnapsRegistryUrl = {\n registry: string;\n signature: string;\n};\n\nexport type ClientConfig = {\n type: 'extension' | 'mobile';\n version: SemVerVersion;\n};\n\nexport type SnapRegistryControllerArgs = {\n messenger: SnapRegistryControllerMessenger;\n state?: SnapRegistryControllerState;\n fetchFunction?: typeof fetch;\n url?: JsonSnapsRegistryUrl;\n recentFetchThreshold?: number;\n refetchOnAllowlistMiss?: boolean;\n publicKey?: Hex;\n clientConfig: ClientConfig;\n};\n\nexport type SnapRegistryControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n SnapRegistryControllerState\n>;\n\nexport type SnapRegistryControllerActions =\n | SnapRegistryControllerGetStateAction\n | SnapRegistryControllerMethodActions;\n\nexport type SnapRegistryControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof controllerName,\n SnapRegistryControllerState\n>;\n\nexport type SnapRegistryControllerRegistryUpdatedEvent = {\n type: `${typeof controllerName}:registryUpdated`;\n payload: [databaseUpdated: boolean];\n};\n\nexport type SnapRegistryControllerEvents =\n | SnapRegistryControllerStateChangeEvent\n | SnapRegistryControllerRegistryUpdatedEvent;\n\nexport type SnapRegistryControllerMessenger = Messenger<\n typeof controllerName,\n SnapRegistryControllerActions,\n SnapRegistryControllerEvents\n>;\n\nexport type SnapRegistryControllerState = {\n database: SnapsRegistryDatabase | null;\n signature: string | null;\n lastUpdated: number | null;\n databaseUnavailable: boolean;\n};\n\nconst controllerName = 'SnapRegistryController';\n\nconst MESSENGER_EXPOSED_METHODS = [\n 'get',\n 'getMetadata',\n 'resolveVersion',\n 'requestUpdate',\n] as const;\n\nconst defaultState = {\n database: null,\n signature: null,\n lastUpdated: null,\n databaseUnavailable: false,\n};\n\nexport class SnapRegistryController extends BaseController<\n typeof controllerName,\n SnapRegistryControllerState,\n SnapRegistryControllerMessenger\n> {\n readonly #url: JsonSnapsRegistryUrl;\n\n readonly #publicKey: Hex;\n\n readonly #clientConfig: ClientConfig;\n\n readonly #fetchFunction: typeof fetch;\n\n readonly #recentFetchThreshold: number;\n\n readonly #refetchOnAllowlistMiss: boolean;\n\n #currentUpdate: Promise<void> | null;\n\n constructor({\n messenger,\n state,\n url = {\n registry: SNAP_REGISTRY_URL,\n signature: SNAP_REGISTRY_SIGNATURE_URL,\n },\n publicKey = DEFAULT_PUBLIC_KEY,\n clientConfig,\n fetchFunction = globalThis.fetch.bind(undefined),\n recentFetchThreshold = inMilliseconds(5, Duration.Minute),\n refetchOnAllowlistMiss = true,\n }: SnapRegistryControllerArgs) {\n super({\n messenger,\n metadata: {\n database: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n signature: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: true,\n usedInUi: false,\n },\n lastUpdated: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: true,\n usedInUi: false,\n },\n databaseUnavailable: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: true,\n usedInUi: false,\n },\n },\n name: controllerName,\n state: {\n ...defaultState,\n ...state,\n },\n });\n this.#url = url;\n this.#publicKey = publicKey;\n this.#clientConfig = clientConfig;\n this.#fetchFunction = fetchFunction;\n this.#recentFetchThreshold = recentFetchThreshold;\n this.#refetchOnAllowlistMiss = refetchOnAllowlistMiss;\n this.#currentUpdate = null;\n\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n }\n\n #wasRecentlyFetched() {\n return (\n this.state.lastUpdated &&\n Date.now() - this.state.lastUpdated < this.#recentFetchThreshold\n );\n }\n\n /**\n * Triggers an update of the registry database.\n *\n * If an existing update is in progress this function will await that update.\n */\n async requestUpdate() {\n // If an update is ongoing, wait for that.\n if (this.#currentUpdate) {\n await this.#currentUpdate;\n return;\n }\n // If no update exists, create promise and store globally.\n if (this.#currentUpdate === null) {\n this.#currentUpdate = this.#update();\n }\n await this.#currentUpdate;\n this.#currentUpdate = null;\n }\n\n /**\n * Updates the registry database if the registry hasn't been updated recently.\n *\n * NOTE: SHOULD NOT be called directly, instead `triggerUpdate` should be used.\n */\n async #update() {\n // No-op if we recently fetched the registry.\n if (this.#wasRecentlyFetched()) {\n this.messenger.publish('SnapRegistryController:registryUpdated', false);\n return;\n }\n\n try {\n const [database, signature] = await Promise.all([\n this.#safeFetch(this.#url.registry),\n this.#safeFetch(this.#url.signature),\n ]);\n\n const signatureJson = JSON.parse(signature);\n\n // If the signature matches the existing state, we can skip verification and don't need to update the database.\n if (signatureJson.signature === this.state.signature) {\n this.update((state) => {\n state.lastUpdated = Date.now();\n state.databaseUnavailable = false;\n });\n this.messenger.publish('SnapRegistryController:registryUpdated', false);\n return;\n }\n\n await this.#verifySignature(database, signatureJson);\n\n this.update((state) => {\n state.database = JSON.parse(database);\n state.lastUpdated = Date.now();\n state.databaseUnavailable = false;\n state.signature = signatureJson.signature;\n });\n\n this.messenger.publish('SnapRegistryController:registryUpdated', true);\n } catch {\n // Ignore\n this.update((state) => {\n state.databaseUnavailable = true;\n });\n }\n }\n\n async #getDatabase(): Promise<SnapsRegistryDatabase | null> {\n if (this.state.database === null) {\n await this.requestUpdate();\n }\n\n return this.state.database;\n }\n\n async #getSingle(\n snapId: string,\n snapInfo: SnapRegistryInfo,\n refetch = false,\n ): Promise<SnapRegistryResult> {\n const database = await this.#getDatabase();\n\n const blockedEntry = database?.blockedSnaps.find((blocked) => {\n if ('id' in blocked) {\n return (\n blocked.id === snapId &&\n satisfiesVersionRange(snapInfo.version, blocked.versionRange)\n );\n }\n\n return blocked.checksum === snapInfo.checksum;\n });\n\n if (blockedEntry) {\n return {\n status: SnapRegistryStatus.Blocked,\n reason: blockedEntry.reason,\n };\n }\n\n const verified = database?.verifiedSnaps[snapId];\n const version = verified?.versions?.[snapInfo.version];\n const clientRange = version?.clientVersions?.[this.#clientConfig.type];\n const isCompatible =\n !clientRange ||\n satisfiesVersionRange(this.#clientConfig.version, clientRange);\n if (version && version.checksum === snapInfo.checksum && isCompatible) {\n return { status: SnapRegistryStatus.Verified };\n }\n // For now, if we have an allowlist miss, we can refetch once and try again.\n if (this.#refetchOnAllowlistMiss && !refetch) {\n await this.requestUpdate();\n return this.#getSingle(snapId, snapInfo, true);\n }\n return {\n status: this.state.databaseUnavailable\n ? SnapRegistryStatus.Unavailable\n : SnapRegistryStatus.Unverified,\n };\n }\n\n async get(\n snaps: SnapRegistryRequest,\n ): Promise<Record<string, SnapRegistryResult>> {\n return Object.entries(snaps).reduce<\n Promise<Record<string, SnapRegistryResult>>\n >(async (previousPromise, [snapId, snapInfo]) => {\n const result = await this.#getSingle(snapId, snapInfo);\n const acc = await previousPromise;\n acc[snapId] = result;\n return acc;\n }, Promise.resolve({}));\n }\n\n /**\n * Find an allowlisted version within a specified version range. Otherwise return the version range itself.\n *\n * @param snapId - The ID of the snap we are trying to resolve a version for.\n * @param versionRange - The version range.\n * @param refetch - An optional flag used to determine if we are refetching the registry.\n * @returns An allowlisted version within the specified version range if available otherwise returns the input version range.\n */\n async resolveVersion(\n snapId: string,\n versionRange: SemVerRange,\n refetch = false,\n ): Promise<SemVerRange> {\n const database = await this.#getDatabase();\n const versions = database?.verifiedSnaps[snapId]?.versions ?? null;\n\n if (!versions && this.#refetchOnAllowlistMiss && !refetch) {\n await this.requestUpdate();\n return this.resolveVersion(snapId, versionRange, true);\n }\n\n // If we cannot narrow down the version range we return the unaltered version range.\n if (!versions) {\n return versionRange;\n }\n\n const compatibleVersions = Object.entries(versions).reduce<SemVerVersion[]>(\n (accumulator, [version, metadata]) => {\n const clientRange = metadata.clientVersions?.[this.#clientConfig.type];\n if (\n !clientRange ||\n satisfiesVersionRange(this.#clientConfig.version, clientRange)\n ) {\n accumulator.push(version as SemVerVersion);\n }\n\n return accumulator;\n },\n [],\n );\n\n const targetVersion = getTargetVersion(compatibleVersions, versionRange);\n\n if (!targetVersion && this.#refetchOnAllowlistMiss && !refetch) {\n await this.requestUpdate();\n return this.resolveVersion(snapId, versionRange, true);\n }\n\n // If we cannot narrow down the version range we return the unaltered version range.\n if (!targetVersion) {\n return versionRange;\n }\n\n // A semver version is technically also a valid semver range.\n assertIsSemVerRange(targetVersion);\n return targetVersion;\n }\n\n /**\n * Get metadata for the given snap ID, if available, without updating registry.\n *\n * @param snapId - The ID of the snap to get metadata for.\n * @returns The metadata for the given snap ID, or `null` if the snap is not\n * verified.\n */\n getMetadata(snapId: string): SnapRegistryMetadata | null {\n return this.state?.database?.verifiedSnaps[snapId]?.metadata ?? null;\n }\n\n /**\n * Verify the signature of the registry.\n *\n * @param database - The registry database.\n * @param signature - The signature of the registry.\n * @throws If the signature is invalid.\n */\n async #verifySignature(\n database: string,\n signature: Infer<typeof SignatureStruct>,\n ) {\n assert(this.#publicKey, 'No public key provided.');\n\n const valid = await verify({\n registry: database,\n signature,\n publicKey: this.#publicKey,\n });\n\n assert(valid, 'Invalid registry signature.');\n }\n\n /**\n * Fetch the given URL, throwing if the response is not OK.\n *\n * @param url - The URL to fetch.\n * @returns The response body.\n * @private\n */\n async #safeFetch(url: string) {\n const response = await this.#fetchFunction(url, { cache: 'no-cache' });\n if (!response.ok) {\n throw new Error(`Failed to fetch ${url}.`);\n }\n\n return await response.text();\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../../src/snaps/registry/index.ts"],"names":[],"mappings":";;;AASA,uEAAkE;AAAzD,gIAAA,sBAAsB,OAAA;AAa/B,qCAA6C;AAApC,2GAAA,kBAAkB,OAAA","sourcesContent":["export type {\n SnapRegistryControllerActions,\n SnapRegistryControllerEvents,\n SnapRegistryControllerArgs,\n SnapRegistryControllerGetStateAction,\n SnapRegistryControllerMessenger,\n SnapRegistryControllerState,\n SnapRegistryControllerStateChangeEvent,\n} from './SnapRegistryController';\nexport { SnapRegistryController } from './SnapRegistryController';\nexport type {\n SnapRegistryControllerGetAction,\n SnapRegistryControllerGetMetadataAction,\n SnapRegistryControllerRequestUpdateAction,\n SnapRegistryControllerResolveVersionAction,\n} from './SnapRegistryController-method-action-types';\nexport type {\n SnapRegistryInfo,\n SnapRegistryMetadata,\n SnapRegistryRequest,\n SnapRegistryResult,\n} from './types';\nexport { SnapRegistryStatus } from './types';\n"]}
1
+ {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../../src/snaps/registry/index.ts"],"names":[],"mappings":";;;AAUA,uEAAkE;AAAzD,gIAAA,sBAAsB,OAAA;AAa/B,qCAA6C;AAApC,2GAAA,kBAAkB,OAAA","sourcesContent":["export type {\n SnapRegistryControllerActions,\n SnapRegistryControllerEvents,\n SnapRegistryControllerArgs,\n SnapRegistryControllerGetStateAction,\n SnapRegistryControllerMessenger,\n SnapRegistryControllerState,\n SnapRegistryControllerStateChangeEvent,\n SnapRegistryControllerRegistryUpdatedEvent,\n} from './SnapRegistryController';\nexport { SnapRegistryController } from './SnapRegistryController';\nexport type {\n SnapRegistryControllerGetAction,\n SnapRegistryControllerGetMetadataAction,\n SnapRegistryControllerRequestUpdateAction,\n SnapRegistryControllerResolveVersionAction,\n} from './SnapRegistryController-method-action-types';\nexport type {\n SnapRegistryInfo,\n SnapRegistryMetadata,\n SnapRegistryRequest,\n SnapRegistryResult,\n} from './types';\nexport { SnapRegistryStatus } from './types';\n"]}
@@ -1,4 +1,4 @@
1
- export type { SnapRegistryControllerActions, SnapRegistryControllerEvents, SnapRegistryControllerArgs, SnapRegistryControllerGetStateAction, SnapRegistryControllerMessenger, SnapRegistryControllerState, SnapRegistryControllerStateChangeEvent, } from "./SnapRegistryController.cjs";
1
+ export type { SnapRegistryControllerActions, SnapRegistryControllerEvents, SnapRegistryControllerArgs, SnapRegistryControllerGetStateAction, SnapRegistryControllerMessenger, SnapRegistryControllerState, SnapRegistryControllerStateChangeEvent, SnapRegistryControllerRegistryUpdatedEvent, } from "./SnapRegistryController.cjs";
2
2
  export { SnapRegistryController } from "./SnapRegistryController.cjs";
3
3
  export type { SnapRegistryControllerGetAction, SnapRegistryControllerGetMetadataAction, SnapRegistryControllerRequestUpdateAction, SnapRegistryControllerResolveVersionAction, } from "./SnapRegistryController-method-action-types.cjs";
4
4
  export type { SnapRegistryInfo, SnapRegistryMetadata, SnapRegistryRequest, SnapRegistryResult, } from "./types.cjs";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../../src/snaps/registry/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,6BAA6B,EAC7B,4BAA4B,EAC5B,0BAA0B,EAC1B,oCAAoC,EACpC,+BAA+B,EAC/B,2BAA2B,EAC3B,sCAAsC,GACvC,qCAAiC;AAClC,OAAO,EAAE,sBAAsB,EAAE,qCAAiC;AAClE,YAAY,EACV,+BAA+B,EAC/B,uCAAuC,EACvC,yCAAyC,EACzC,0CAA0C,GAC3C,yDAAqD;AACtD,YAAY,EACV,gBAAgB,EAChB,oBAAoB,EACpB,mBAAmB,EACnB,kBAAkB,GACnB,oBAAgB;AACjB,OAAO,EAAE,kBAAkB,EAAE,oBAAgB"}
1
+ {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../../src/snaps/registry/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,6BAA6B,EAC7B,4BAA4B,EAC5B,0BAA0B,EAC1B,oCAAoC,EACpC,+BAA+B,EAC/B,2BAA2B,EAC3B,sCAAsC,EACtC,0CAA0C,GAC3C,qCAAiC;AAClC,OAAO,EAAE,sBAAsB,EAAE,qCAAiC;AAClE,YAAY,EACV,+BAA+B,EAC/B,uCAAuC,EACvC,yCAAyC,EACzC,0CAA0C,GAC3C,yDAAqD;AACtD,YAAY,EACV,gBAAgB,EAChB,oBAAoB,EACpB,mBAAmB,EACnB,kBAAkB,GACnB,oBAAgB;AACjB,OAAO,EAAE,kBAAkB,EAAE,oBAAgB"}
@@ -1,4 +1,4 @@
1
- export type { SnapRegistryControllerActions, SnapRegistryControllerEvents, SnapRegistryControllerArgs, SnapRegistryControllerGetStateAction, SnapRegistryControllerMessenger, SnapRegistryControllerState, SnapRegistryControllerStateChangeEvent, } from "./SnapRegistryController.mjs";
1
+ export type { SnapRegistryControllerActions, SnapRegistryControllerEvents, SnapRegistryControllerArgs, SnapRegistryControllerGetStateAction, SnapRegistryControllerMessenger, SnapRegistryControllerState, SnapRegistryControllerStateChangeEvent, SnapRegistryControllerRegistryUpdatedEvent, } from "./SnapRegistryController.mjs";
2
2
  export { SnapRegistryController } from "./SnapRegistryController.mjs";
3
3
  export type { SnapRegistryControllerGetAction, SnapRegistryControllerGetMetadataAction, SnapRegistryControllerRequestUpdateAction, SnapRegistryControllerResolveVersionAction, } from "./SnapRegistryController-method-action-types.mjs";
4
4
  export type { SnapRegistryInfo, SnapRegistryMetadata, SnapRegistryRequest, SnapRegistryResult, } from "./types.mjs";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../../src/snaps/registry/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,6BAA6B,EAC7B,4BAA4B,EAC5B,0BAA0B,EAC1B,oCAAoC,EACpC,+BAA+B,EAC/B,2BAA2B,EAC3B,sCAAsC,GACvC,qCAAiC;AAClC,OAAO,EAAE,sBAAsB,EAAE,qCAAiC;AAClE,YAAY,EACV,+BAA+B,EAC/B,uCAAuC,EACvC,yCAAyC,EACzC,0CAA0C,GAC3C,yDAAqD;AACtD,YAAY,EACV,gBAAgB,EAChB,oBAAoB,EACpB,mBAAmB,EACnB,kBAAkB,GACnB,oBAAgB;AACjB,OAAO,EAAE,kBAAkB,EAAE,oBAAgB"}
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../../src/snaps/registry/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,6BAA6B,EAC7B,4BAA4B,EAC5B,0BAA0B,EAC1B,oCAAoC,EACpC,+BAA+B,EAC/B,2BAA2B,EAC3B,sCAAsC,EACtC,0CAA0C,GAC3C,qCAAiC;AAClC,OAAO,EAAE,sBAAsB,EAAE,qCAAiC;AAClE,YAAY,EACV,+BAA+B,EAC/B,uCAAuC,EACvC,yCAAyC,EACzC,0CAA0C,GAC3C,yDAAqD;AACtD,YAAY,EACV,gBAAgB,EAChB,oBAAoB,EACpB,mBAAmB,EACnB,kBAAkB,GACnB,oBAAgB;AACjB,OAAO,EAAE,kBAAkB,EAAE,oBAAgB"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../../src/snaps/registry/index.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,sBAAsB,EAAE,qCAAiC;AAalE,OAAO,EAAE,kBAAkB,EAAE,oBAAgB","sourcesContent":["export type {\n SnapRegistryControllerActions,\n SnapRegistryControllerEvents,\n SnapRegistryControllerArgs,\n SnapRegistryControllerGetStateAction,\n SnapRegistryControllerMessenger,\n SnapRegistryControllerState,\n SnapRegistryControllerStateChangeEvent,\n} from './SnapRegistryController';\nexport { SnapRegistryController } from './SnapRegistryController';\nexport type {\n SnapRegistryControllerGetAction,\n SnapRegistryControllerGetMetadataAction,\n SnapRegistryControllerRequestUpdateAction,\n SnapRegistryControllerResolveVersionAction,\n} from './SnapRegistryController-method-action-types';\nexport type {\n SnapRegistryInfo,\n SnapRegistryMetadata,\n SnapRegistryRequest,\n SnapRegistryResult,\n} from './types';\nexport { SnapRegistryStatus } from './types';\n"]}
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../../src/snaps/registry/index.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,sBAAsB,EAAE,qCAAiC;AAalE,OAAO,EAAE,kBAAkB,EAAE,oBAAgB","sourcesContent":["export type {\n SnapRegistryControllerActions,\n SnapRegistryControllerEvents,\n SnapRegistryControllerArgs,\n SnapRegistryControllerGetStateAction,\n SnapRegistryControllerMessenger,\n SnapRegistryControllerState,\n SnapRegistryControllerStateChangeEvent,\n SnapRegistryControllerRegistryUpdatedEvent,\n} from './SnapRegistryController';\nexport { SnapRegistryController } from './SnapRegistryController';\nexport type {\n SnapRegistryControllerGetAction,\n SnapRegistryControllerGetMetadataAction,\n SnapRegistryControllerRequestUpdateAction,\n SnapRegistryControllerResolveVersionAction,\n} from './SnapRegistryController-method-action-types';\nexport type {\n SnapRegistryInfo,\n SnapRegistryMetadata,\n SnapRegistryRequest,\n SnapRegistryResult,\n} from './types';\nexport { SnapRegistryStatus } from './types';\n"]}
package/dist/utils.d.cts CHANGED
@@ -184,6 +184,27 @@ export declare function fetchSnap(snapId: SnapId, location: SnapLocation): Promi
184
184
  'endowment:ethereum-provider': import("@metamask/snaps-sdk").EmptyObject;
185
185
  'endowment:keyring': {
186
186
  allowedOrigins?: string[] | undefined;
187
+ capabilities?: {
188
+ scopes: `${string}:${string}`[];
189
+ bip44?: {
190
+ derivePath?: boolean | undefined;
191
+ deriveIndex?: boolean | undefined;
192
+ deriveIndexRange?: boolean | undefined;
193
+ discover?: boolean | undefined;
194
+ } | undefined;
195
+ privateKey?: {
196
+ importFormats?: {
197
+ encoding: "hexadecimal" | "base58";
198
+ type?: "eip155:eoa" | "eip155:erc4337" | "bip122:p2pkh" | "bip122:p2sh" | "bip122:p2wpkh" | "bip122:p2tr" | "solana:data-account" | "tron:eoa" | "entropy:account" | undefined;
199
+ }[] | undefined;
200
+ exportFormats?: {
201
+ encoding: "hexadecimal" | "base58";
202
+ }[] | undefined;
203
+ } | undefined;
204
+ custom?: {
205
+ createAccounts?: boolean | undefined;
206
+ } | undefined;
207
+ } | undefined;
187
208
  maxRequestTime?: number | undefined;
188
209
  };
189
210
  'endowment:lifecycle-hooks'?: {
@@ -221,7 +242,16 @@ export declare function fetchSnap(snapId: SnapId, location: SnapLocation): Promi
221
242
  snap_getBip32PublicKey: import("@metamask/snaps-sdk").Bip32Entropy[];
222
243
  snap_getBip44Entropy: import("@metamask/snaps-sdk").Bip44Entropy[];
223
244
  snap_getEntropy: import("@metamask/snaps-sdk").EmptyObject;
224
- snap_getLocale: import("@metamask/snaps-sdk").EmptyObject;
245
+ snap_getLocale: import("@metamask/snaps-sdk").EmptyObject; /**
246
+ * Returns all keys of an object, that are not literal, as an union
247
+ *
248
+ * @example
249
+ * ```
250
+ * type t1 = _NonLiteralKeys<{a: number, b: 0, c: 'foo', d: string}>
251
+ * // t1 = 'a' | 'd'
252
+ * ```
253
+ * @see [Literal types]{@link https://www.typescriptlang.org/docs/handbook/literal-types.html}
254
+ */
225
255
  snap_manageAccounts: import("@metamask/snaps-sdk").EmptyObject;
226
256
  snap_manageState: import("@metamask/snaps-sdk").EmptyObject;
227
257
  snap_notify: import("@metamask/snaps-sdk").EmptyObject;
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.cts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings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ACH,eAAO,MAAM,kBAAkB,wLAQpB,CAAC;AAEZ;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,CAAC,OAAO,kBAAkB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEnE;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC9B,EAAE,EAAE,CACF,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,gBAAgB,EACzB,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,MAAM,KACX,IAAI,EACT,OAAO,SAAQ,YAYL,MAAM,WACL,gBAAgB,WAChB,OAAO,UACR,MAAM,KACb,IAAI,CAgCR;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,WAAW,GACnB,OAAO,IAAI,gBAAgB,CAE7B;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAErD"}
package/dist/utils.d.mts CHANGED
@@ -184,6 +184,27 @@ export declare function fetchSnap(snapId: SnapId, location: SnapLocation): Promi
184
184
  'endowment:ethereum-provider': import("@metamask/snaps-sdk").EmptyObject;
185
185
  'endowment:keyring': {
186
186
  allowedOrigins?: string[] | undefined;
187
+ capabilities?: {
188
+ scopes: `${string}:${string}`[];
189
+ bip44?: {
190
+ derivePath?: boolean | undefined;
191
+ deriveIndex?: boolean | undefined;
192
+ deriveIndexRange?: boolean | undefined;
193
+ discover?: boolean | undefined;
194
+ } | undefined;
195
+ privateKey?: {
196
+ importFormats?: {
197
+ encoding: "hexadecimal" | "base58";
198
+ type?: "eip155:eoa" | "eip155:erc4337" | "bip122:p2pkh" | "bip122:p2sh" | "bip122:p2wpkh" | "bip122:p2tr" | "solana:data-account" | "tron:eoa" | "entropy:account" | undefined;
199
+ }[] | undefined;
200
+ exportFormats?: {
201
+ encoding: "hexadecimal" | "base58";
202
+ }[] | undefined;
203
+ } | undefined;
204
+ custom?: {
205
+ createAccounts?: boolean | undefined;
206
+ } | undefined;
207
+ } | undefined;
187
208
  maxRequestTime?: number | undefined;
188
209
  };
189
210
  'endowment:lifecycle-hooks'?: {
@@ -221,7 +242,16 @@ export declare function fetchSnap(snapId: SnapId, location: SnapLocation): Promi
221
242
  snap_getBip32PublicKey: import("@metamask/snaps-sdk").Bip32Entropy[];
222
243
  snap_getBip44Entropy: import("@metamask/snaps-sdk").Bip44Entropy[];
223
244
  snap_getEntropy: import("@metamask/snaps-sdk").EmptyObject;
224
- snap_getLocale: import("@metamask/snaps-sdk").EmptyObject;
245
+ snap_getLocale: import("@metamask/snaps-sdk").EmptyObject; /**
246
+ * Returns all keys of an object, that are not literal, as an union
247
+ *
248
+ * @example
249
+ * ```
250
+ * type t1 = _NonLiteralKeys<{a: number, b: 0, c: 'foo', d: string}>
251
+ * // t1 = 'a' | 'd'
252
+ * ```
253
+ * @see [Literal types]{@link https://www.typescriptlang.org/docs/handbook/literal-types.html}
254
+ */
225
255
  snap_manageAccounts: import("@metamask/snaps-sdk").EmptyObject;
226
256
  snap_manageState: import("@metamask/snaps-sdk").EmptyObject;
227
257
  snap_notify: import("@metamask/snaps-sdk").EmptyObject;
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.mts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,wCAAwC;AAC5E,OAAO,KAAK,EAAE,MAAM,EAAE,4BAA4B;AAElD,OAAO,EAML,WAAW,EACZ,8BAA8B;AAC/B,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAG5C,OAAO,KAAK,EAAE,YAAY,EAAE,0BAAgB;AAC5C,OAAO,EAAE,KAAK,EAAE,0BAAsB;AAEtC;;;;;;;;;;;;;GAaG;AACH,wBAAgB,OAAO,CACrB,OAAO,SAAS,MAAM,CAAC,GAAG,EAAE,OAAO,CAAC,EACpC,OAAO,SAAS,MAAM,CAAC,GAAG,EAAE,OAAO,CAAC,EACpC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO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gBAAgB,CAE7B;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAErD"}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /**
3
- * This file is auto generated by `scripts/generate-method-action-types.ts`.
3
+ * This file is auto generated.
4
4
  * Do not edit manually.
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -1 +1 @@
1
- {"version":3,"file":"WebSocketService-method-action-types.cjs","sourceRoot":"","sources":["../../src/websocket/WebSocketService-method-action-types.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated by `scripts/generate-method-action-types.ts`.\n * Do not edit manually.\n */\n\nimport type { WebSocketService } from './WebSocketService';\n\n/**\n * Open a WebSocket connection.\n *\n * @param snapId - The Snap ID.\n * @param url - The URL for the WebSocket connection.\n * @param protocols - An optional parameter for protocols.\n * @returns The identifier for the opened connection.\n * @throws If the connection fails.\n */\nexport type WebSocketServiceOpenAction = {\n type: `WebSocketService:open`;\n handler: WebSocketService['open'];\n};\n\n/**\n * Close a given WebSocket connection.\n *\n * @param snapId - The Snap ID.\n * @param id - The identifier for the WebSocket connection.\n */\nexport type WebSocketServiceCloseAction = {\n type: `WebSocketService:close`;\n handler: WebSocketService['close'];\n};\n\n/**\n * Send a message from a given Snap ID to a WebSocket connection.\n *\n * @param snapId - The Snap ID.\n * @param id - The identifier for the WebSocket connection.\n * @param data - The message to send.\n */\nexport type WebSocketServiceSendMessageAction = {\n type: `WebSocketService:sendMessage`;\n handler: WebSocketService['sendMessage'];\n};\n\n/**\n * Get a list of all open WebSocket connections for a Snap ID.\n *\n * @param snapId - The Snap ID.\n * @returns A list of WebSocket connections.\n */\nexport type WebSocketServiceGetAllAction = {\n type: `WebSocketService:getAll`;\n handler: WebSocketService['getAll'];\n};\n\n/**\n * Union of all WebSocketService action types.\n */\nexport type WebSocketServiceMethodActions =\n | WebSocketServiceOpenAction\n | WebSocketServiceCloseAction\n | WebSocketServiceSendMessageAction\n | WebSocketServiceGetAllAction;\n"]}
1
+ {"version":3,"file":"WebSocketService-method-action-types.cjs","sourceRoot":"","sources":["../../src/websocket/WebSocketService-method-action-types.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { WebSocketService } from './WebSocketService';\n\n/**\n * Open a WebSocket connection.\n *\n * @param snapId - The Snap ID.\n * @param url - The URL for the WebSocket connection.\n * @param protocols - An optional parameter for protocols.\n * @returns The identifier for the opened connection.\n * @throws If the connection fails.\n */\nexport type WebSocketServiceOpenAction = {\n type: `WebSocketService:open`;\n handler: WebSocketService['open'];\n};\n\n/**\n * Close a given WebSocket connection.\n *\n * @param snapId - The Snap ID.\n * @param id - The identifier for the WebSocket connection.\n */\nexport type WebSocketServiceCloseAction = {\n type: `WebSocketService:close`;\n handler: WebSocketService['close'];\n};\n\n/**\n * Send a message from a given Snap ID to a WebSocket connection.\n *\n * @param snapId - The Snap ID.\n * @param id - The identifier for the WebSocket connection.\n * @param data - The message to send.\n */\nexport type WebSocketServiceSendMessageAction = {\n type: `WebSocketService:sendMessage`;\n handler: WebSocketService['sendMessage'];\n};\n\n/**\n * Get a list of all open WebSocket connections for a Snap ID.\n *\n * @param snapId - The Snap ID.\n * @returns A list of WebSocket connections.\n */\nexport type WebSocketServiceGetAllAction = {\n type: `WebSocketService:getAll`;\n handler: WebSocketService['getAll'];\n};\n\n/**\n * Union of all WebSocketService action types.\n */\nexport type WebSocketServiceMethodActions =\n | WebSocketServiceOpenAction\n | WebSocketServiceCloseAction\n | WebSocketServiceSendMessageAction\n | WebSocketServiceGetAllAction;\n"]}
@@ -1,5 +1,5 @@
1
1
  /**
2
- * This file is auto generated by `scripts/generate-method-action-types.ts`.
2
+ * This file is auto generated.
3
3
  * Do not edit manually.
4
4
  */
5
5
  import type { WebSocketService } from "./WebSocketService.cjs";
@@ -1,5 +1,5 @@
1
1
  /**
2
- * This file is auto generated by `scripts/generate-method-action-types.ts`.
2
+ * This file is auto generated.
3
3
  * Do not edit manually.
4
4
  */
5
5
  import type { WebSocketService } from "./WebSocketService.mjs";
@@ -1,5 +1,5 @@
1
1
  /**
2
- * This file is auto generated by `scripts/generate-method-action-types.ts`.
2
+ * This file is auto generated.
3
3
  * Do not edit manually.
4
4
  */
5
5
  export {};