@metamask/snaps-jest 9.0.0 → 9.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [9.2.0]
11
+
12
+ ### Added
13
+
14
+ - Add support for `AssetSelector` and `AccountSelector` ([#3462](https://github.com/MetaMask/snaps/pull/3462))
15
+
16
+ ## [9.1.0]
17
+
18
+ ### Added
19
+
20
+ - Add support for `onStart` ([#3455](https://github.com/MetaMask/snaps/pull/3455))
21
+
10
22
  ## [9.0.0]
11
23
 
12
24
  ### Added
@@ -385,7 +397,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
385
397
  - The version of the package no longer needs to match the version of all other
386
398
  MetaMask Snaps packages.
387
399
 
388
- [Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-jest@9.0.0...HEAD
400
+ [Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-jest@9.2.0...HEAD
401
+ [9.2.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-jest@9.1.0...@metamask/snaps-jest@9.2.0
402
+ [9.1.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-jest@9.0.0...@metamask/snaps-jest@9.1.0
389
403
  [9.0.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-jest@8.16.0...@metamask/snaps-jest@9.0.0
390
404
  [8.16.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-jest@8.15.0...@metamask/snaps-jest@8.16.0
391
405
  [8.15.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-jest@8.14.1...@metamask/snaps-jest@8.15.0
package/dist/helpers.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.installSnap = void 0;
3
+ exports.getMockAccount = exports.getStateFromAsset = exports.getStateFromAccount = exports.installSnap = void 0;
4
4
  const snaps_utils_1 = require("@metamask/snaps-utils");
5
5
  const utils_1 = require("@metamask/utils");
6
6
  const internals_1 = require("./internals/index.cjs");
@@ -55,7 +55,7 @@ async function installSnap(snapId, options = {}) {
55
55
  // TODO: Either fix this lint violation or explain why it's necessary to
56
56
  // ignore.
57
57
  /* eslint-disable @typescript-eslint/unbound-method */
58
- const { request, onTransaction, sendTransaction, onSignature, onCronjob, runCronjob, onBackgroundEvent, onHomePage, onSettingsPage, onKeyringRequest, onInstall, onUpdate, onNameLookup, onProtocolRequest, onClientRequest, mockJsonRpc, close, } = await (0, internals_1.getEnvironment)().installSnap(...resolvedOptions);
58
+ const { request, onTransaction, sendTransaction, onSignature, onCronjob, runCronjob, onBackgroundEvent, onHomePage, onSettingsPage, onKeyringRequest, onInstall, onUpdate, onStart, onNameLookup, onProtocolRequest, onClientRequest, mockJsonRpc, close, } = await (0, internals_1.getEnvironment)().installSnap(...resolvedOptions);
59
59
  /* eslint-enable @typescript-eslint/unbound-method */
60
60
  return {
61
61
  request,
@@ -70,6 +70,7 @@ async function installSnap(snapId, options = {}) {
70
70
  onKeyringRequest,
71
71
  onInstall,
72
72
  onUpdate,
73
+ onStart,
73
74
  onNameLookup,
74
75
  onProtocolRequest,
75
76
  onClientRequest,
@@ -82,4 +83,66 @@ async function installSnap(snapId, options = {}) {
82
83
  };
83
84
  }
84
85
  exports.installSnap = installSnap;
86
+ /**
87
+ * Get the state of an AccountSelector based on a {@link SimulationAccount}.
88
+ *
89
+ * @param account - The {@link SimulationAccount} to get the state from.
90
+ * @returns The state of the AccountSelector.
91
+ */
92
+ function getStateFromAccount(account) {
93
+ const { address, scopes } = account;
94
+ return {
95
+ addresses: scopes.map((scope) => `${scope}:${address}`),
96
+ accountId: account.id,
97
+ };
98
+ }
99
+ exports.getStateFromAccount = getStateFromAccount;
100
+ /**
101
+ * Get the state of an AssetSelector based on a {@link SimulationAsset}.
102
+ *
103
+ * @param id - The Asset id as a CAIP-19 asset type.
104
+ * @param assets - The {@link SimulationAsset} to get the state from.
105
+ * @returns The state of the AssetSelector.
106
+ */
107
+ function getStateFromAsset(id, assets) {
108
+ const asset = assets[id];
109
+ (0, utils_1.assert)(asset, `Asset with ID "${id}" not found in simulation assets.`);
110
+ const { symbol, name } = asset;
111
+ return {
112
+ asset: id,
113
+ symbol,
114
+ name,
115
+ };
116
+ }
117
+ exports.getStateFromAsset = getStateFromAsset;
118
+ /**
119
+ * Generate a pseudo-random UUID.
120
+ *
121
+ * @returns A pseudo-random UUID string.
122
+ */
123
+ const getPseudoRandomUuid = (0, internals_1.getPseudoRandomUuidGenerator)();
124
+ /**
125
+ * Get a mock account object for testing purposes.
126
+ *
127
+ * @param options - The options for creating the mock account.
128
+ * @param options.address - The address of the account.
129
+ * @param options.scopes - The scopes associated with the account, in CAIP
130
+ * format. If not provided, they will be derived from the `assets`.
131
+ * @param options.assets - The assets associated with the account, in CAIP
132
+ * format. If not provided, it will default to an empty array.
133
+ * @param options.selected - Whether the account is selected by default.
134
+ * @param options.id - The ID of the account. If not provided, a pseudo-random
135
+ * UUID will be generated.
136
+ * @returns A mock account object with the specified properties.
137
+ */
138
+ function getMockAccount({ address, assets = [], selected = false, id = getPseudoRandomUuid(), scopes = (0, internals_1.getScopesFromAssets)(assets), }) {
139
+ return {
140
+ address,
141
+ id,
142
+ scopes,
143
+ selected,
144
+ assets,
145
+ };
146
+ }
147
+ exports.getMockAccount = getMockAccount;
85
148
  //# sourceMappingURL=helpers.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.cjs","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":";;;AAGA,uDAAgD;AAChD,2CAAqD;AAErD,qDAAyD;AAEzD,MAAM,GAAG,GAAG,IAAA,0BAAkB,EAAC,sBAAU,EAAE,SAAS,CAAC,CAAC;AAEtD;;;;;;GAMG;AACH,SAAS,UAAU,CAKjB,MAAiE,EACjE,OAA6C;IAE7C,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;QAC/B,OAAO,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;IAC7B,CAAC;IAED,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAC3B,CAAC;AAqGD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACI,KAAK,UAAU,WAAW,CAK/B,MAAsD,EACtD,UAAgD,EAAE;IAElD,MAAM,eAAe,GAAG,UAAU,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAEpD,wEAAwE;IACxE,WAAW;IACX,sDAAsD;IACtD,MAAM,EACJ,OAAO,EACP,aAAa,EACb,eAAe,EACf,WAAW,EACX,SAAS,EACT,UAAU,EACV,iBAAiB,EACjB,UAAU,EACV,cAAc,EACd,gBAAgB,EAChB,SAAS,EACT,QAAQ,EACR,YAAY,EACZ,iBAAiB,EACjB,eAAe,EACf,WAAW,EACX,KAAK,GACN,GAAG,MAAM,IAAA,0BAAc,GAAE,CAAC,WAAW,CAAC,GAAG,eAAe,CAAC,CAAC;IAC3D,qDAAqD;IAErD,OAAO;QACL,OAAO;QACP,aAAa;QACb,eAAe;QACf,WAAW;QACX,SAAS;QACT,UAAU;QACV,iBAAiB;QACjB,UAAU;QACV,cAAc;QACd,gBAAgB;QAChB,SAAS;QACT,QAAQ;QACR,YAAY;QACZ,iBAAiB;QACjB,eAAe;QACf,WAAW;QACX,KAAK,EAAE,KAAK,IAAI,EAAE;YAChB,GAAG,CAAC,4BAA4B,CAAC,CAAC;YAClC,IAAA,qBAAO,EACL,uIAAuI,CACxI,CAAC;YAEF,MAAM,KAAK,EAAE,CAAC;QAChB,CAAC;KACF,CAAC;AACJ,CAAC;AA5DD,kCA4DC","sourcesContent":["import type { AbstractExecutionService } from '@metamask/snaps-controllers';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport type { InstallSnapOptions, Snap } from '@metamask/snaps-simulation';\nimport { logInfo } from '@metamask/snaps-utils';\nimport { createModuleLogger } from '@metamask/utils';\n\nimport { rootLogger, getEnvironment } from './internals';\n\nconst log = createModuleLogger(rootLogger, 'helpers');\n\n/**\n * Get the options for {@link installSnap}.\n *\n * @param snapId - The ID of the Snap, or the options.\n * @param options - The options, if any.\n * @returns The options.\n */\nfunction getOptions<\n Service extends new (\n ...args: any[]\n ) => InstanceType<typeof AbstractExecutionService>,\n>(\n snapId: SnapId | Partial<InstallSnapOptions<Service>> | undefined,\n options: Partial<InstallSnapOptions<Service>>,\n): [SnapId | undefined, Partial<InstallSnapOptions<Service>>] {\n if (typeof snapId === 'object') {\n return [undefined, snapId];\n }\n\n return [snapId, options];\n}\n\n/**\n * Load a snap into the environment. This is the main entry point for testing\n * snaps: It returns a {@link Snap} object that can be used to interact with the\n * snap.\n *\n * @example\n * import { installSnap } from '@metamask/snaps-jest';\n *\n * describe('My Snap', () => {\n * it('should do something', async () => {\n * const { request } = await installSnap('local:my-snap');\n * const response = await request({\n * method: 'foo',\n * params: ['bar'],\n * });\n * expect(response).toRespondWith('bar');\n * });\n * });\n * @returns The snap.\n * @throws If the built-in server is not running, and no snap ID is provided.\n */\nexport async function installSnap(): Promise<Snap>;\n\n/**\n * Load a snap into the environment. This is the main entry point for testing\n * snaps: It returns a {@link Snap} object that can be used to interact with the\n * snap.\n *\n * @example\n * import { installSnap } from '@metamask/snaps-jest';\n *\n * describe('My Snap', () => {\n * it('should do something', async () => {\n * const { request } = await installSnap('local:my-snap');\n * const response = await request({\n * method: 'foo',\n * params: ['bar'],\n * });\n * expect(response).toRespondWith('bar');\n * });\n * });\n * @param options - The options to use.\n * @param options.executionService - The execution service to use. Defaults to\n * {@link NodeThreadExecutionService}. You do not need to provide this unless\n * you are testing a custom execution service.\n * @param options.executionServiceOptions - The options to use when creating the\n * execution service, if any. This should only include options specific to the\n * provided execution service.\n * @param options.options - The simulation options.\n * @returns The snap.\n * @throws If the built-in server is not running, and no snap ID is provided.\n */\nexport async function installSnap<\n Service extends new (\n ...args: any[]\n ) => InstanceType<typeof AbstractExecutionService>,\n>(options: Partial<InstallSnapOptions<Service>>): Promise<Snap>;\n\n/**\n * Load a snap into the environment. This is the main entry point for testing\n * snaps: It returns a {@link Snap} object that can be used to interact with the\n * snap.\n *\n * @example\n * import { installSnap } from '@metamask/snaps-jest';\n *\n * describe('My Snap', () => {\n * it('should do something', async () => {\n * const { request } = await installSnap('local:my-snap');\n * const response = await request({\n * method: 'foo',\n * params: ['bar'],\n * });\n * expect(response).toRespondWith('bar');\n * });\n * });\n * @param snapId - The ID of the snap, including the prefix (`local:`). Defaults\n * to the URL of the built-in server, if it is running. This supports both\n * local snap IDs and NPM snap IDs.\n * @param options - The options to use.\n * @param options.executionService - The execution service to use. Defaults to\n * {@link NodeThreadExecutionService}. You do not need to provide this unless\n * you are testing a custom execution service.\n * @param options.executionServiceOptions - The options to use when creating the\n * execution service, if any. This should only include options specific to the\n * provided execution service.\n * @param options.options - The simulation options.\n * @returns The snap.\n * @throws If the built-in server is not running, and no snap ID is provided.\n */\nexport async function installSnap<\n Service extends new (\n ...args: any[]\n ) => InstanceType<typeof AbstractExecutionService>,\n>(\n snapId: SnapId,\n options?: Partial<InstallSnapOptions<Service>>,\n): Promise<Snap>;\n\n/**\n * Load a snap into the environment. This is the main entry point for testing\n * snaps: It returns a {@link Snap} object that can be used to interact with the\n * snap.\n *\n * @example\n * import { installSnap } from '@metamask/snaps-jest';\n *\n * describe('My Snap', () => {\n * it('should do something', async () => {\n * const { request } = await installSnap('local:my-snap');\n * const response = await request({\n * method: 'foo',\n * params: ['bar'],\n * });\n * expect(response).toRespondWith('bar');\n * });\n * });\n * @param snapId - The ID of the snap, including the prefix (`local:`). Defaults\n * to the URL of the built-in server, if it is running. This supports both\n * local snap IDs and NPM snap IDs.\n * @param options - The options to use.\n * @param options.executionService - The execution service to use. Defaults to\n * {@link NodeThreadExecutionService}. You do not need to provide this unless\n * you are testing a custom execution service.\n * @param options.executionServiceOptions - The options to use when creating the\n * execution service, if any. This should only include options specific to the\n * provided execution service.\n * @param options.options - The simulation options.\n * @returns The snap.\n * @throws If the built-in server is not running, and no snap ID is provided.\n */\nexport async function installSnap<\n Service extends new (\n ...args: any[]\n ) => InstanceType<typeof AbstractExecutionService>,\n>(\n snapId?: SnapId | Partial<InstallSnapOptions<Service>>,\n options: Partial<InstallSnapOptions<Service>> = {},\n): Promise<Snap> {\n const resolvedOptions = getOptions(snapId, options);\n\n // TODO: Either fix this lint violation or explain why it's necessary to\n // ignore.\n /* eslint-disable @typescript-eslint/unbound-method */\n const {\n request,\n onTransaction,\n sendTransaction,\n onSignature,\n onCronjob,\n runCronjob,\n onBackgroundEvent,\n onHomePage,\n onSettingsPage,\n onKeyringRequest,\n onInstall,\n onUpdate,\n onNameLookup,\n onProtocolRequest,\n onClientRequest,\n mockJsonRpc,\n close,\n } = await getEnvironment().installSnap(...resolvedOptions);\n /* eslint-enable @typescript-eslint/unbound-method */\n\n return {\n request,\n onTransaction,\n sendTransaction,\n onSignature,\n onCronjob,\n runCronjob,\n onBackgroundEvent,\n onHomePage,\n onSettingsPage,\n onKeyringRequest,\n onInstall,\n onUpdate,\n onNameLookup,\n onProtocolRequest,\n onClientRequest,\n mockJsonRpc,\n close: async () => {\n log('Closing execution service.');\n logInfo(\n 'Calling `snap.close()` is deprecated, and will be removed in a future release. Snaps are now automatically closed when the test ends.',\n );\n\n await close();\n },\n };\n}\n"]}
1
+ {"version":3,"file":"helpers.cjs","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":";;;AAYA,uDAAgD;AAChD,2CAA6D;AAO7D,qDAKqB;AAErB,MAAM,GAAG,GAAG,IAAA,0BAAkB,EAAC,sBAAU,EAAE,SAAS,CAAC,CAAC;AAEtD;;;;;;GAMG;AACH,SAAS,UAAU,CAKjB,MAAiE,EACjE,OAA6C;IAE7C,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;QAC/B,OAAO,CAAC,SAAS,EAAE,MAAM,CAAC,CAA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AAE,CAAoB;QAC1E,SAAS,EAAE,OAAO,CAAC,EAAE;KACtB,CAAC;AACJ,CAAC;AARD,kDAQC;AAED;;;;;;GAMG;AACH,SAAgB,iBAAiB,CAC/B,EAAiB,EACjB,MAA8C;IAE9C,MAAM,KAAK,GAAG,MAAM,CAAC,EAAE,CAAC,CAAC;IAEzB,IAAA,cAAM,EAAC,KAAK,EAAE,kBAAkB,EAAE,mCAAmC,CAAC,CAAC;IAEvE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,KAAK,CAAC;IAE/B,OAAO;QACL,KAAK,EAAE,EAAE;QACT,MAAM;QACN,IAAI;KACL,CAAC;AACJ,CAAC;AAfD,8CAeC;AAED;;;;GAIG;AACH,MAAM,mBAAmB,GAAG,IAAA,wCAA4B,GAAE,CAAC;AAgE3D;;;;;;;;;;;;;GAaG;AACH,SAAgB,cAAc,CAAC,EAC7B,OAAO,EACP,MAAM,GAAG,EAAE,EACX,QAAQ,GAAG,KAAK,EAChB,EAAE,GAAG,mBAAmB,EAAE,EAC1B,MAAM,GAAG,IAAA,+BAAmB,EAAC,MAAM,CAAC,GACd;IACtB,OAAO;QACL,OAAO;QACP,EAAE;QACF,MAAM;QACN,QAAQ;QACR,MAAM;KACP,CAAC;AACJ,CAAC;AAdD,wCAcC","sourcesContent":["import type { AbstractExecutionService } from '@metamask/snaps-controllers';\nimport type {\n AccountSelectorState,\n AssetSelectorState,\n SnapId,\n} from '@metamask/snaps-sdk';\nimport type {\n InstallSnapOptions,\n SimulationAccount,\n SimulationAsset,\n Snap,\n} from '@metamask/snaps-simulation';\nimport { logInfo } from '@metamask/snaps-utils';\nimport { assert, createModuleLogger } from '@metamask/utils';\nimport type {\n CaipAccountId,\n CaipAssetType,\n CaipChainId,\n} from '@metamask/utils';\n\nimport {\n rootLogger,\n getEnvironment,\n getPseudoRandomUuidGenerator,\n getScopesFromAssets,\n} from './internals';\n\nconst log = createModuleLogger(rootLogger, 'helpers');\n\n/**\n * Get the options for {@link installSnap}.\n *\n * @param snapId - The ID of the Snap, or the options.\n * @param options - The options, if any.\n * @returns The options.\n */\nfunction getOptions<\n Service extends new (\n ...args: any[]\n ) => InstanceType<typeof AbstractExecutionService>,\n>(\n snapId: SnapId | Partial<InstallSnapOptions<Service>> | undefined,\n options: Partial<InstallSnapOptions<Service>>,\n): [SnapId | undefined, Partial<InstallSnapOptions<Service>>] {\n if (typeof snapId === 'object') {\n return [undefined, snapId];\n }\n\n return [snapId, options];\n}\n\n/**\n * Load a snap into the environment. This is the main entry point for testing\n * snaps: It returns a {@link Snap} object that can be used to interact with the\n * snap.\n *\n * @example\n * import { installSnap } from '@metamask/snaps-jest';\n *\n * describe('My Snap', () => {\n * it('should do something', async () => {\n * const { request } = await installSnap('local:my-snap');\n * const response = await request({\n * method: 'foo',\n * params: ['bar'],\n * });\n * expect(response).toRespondWith('bar');\n * });\n * });\n * @returns The snap.\n * @throws If the built-in server is not running, and no snap ID is provided.\n */\nexport async function installSnap(): Promise<Snap>;\n\n/**\n * Load a snap into the environment. This is the main entry point for testing\n * snaps: It returns a {@link Snap} object that can be used to interact with the\n * snap.\n *\n * @example\n * import { installSnap } from '@metamask/snaps-jest';\n *\n * describe('My Snap', () => {\n * it('should do something', async () => {\n * const { request } = await installSnap('local:my-snap');\n * const response = await request({\n * method: 'foo',\n * params: ['bar'],\n * });\n * expect(response).toRespondWith('bar');\n * });\n * });\n * @param options - The options to use.\n * @param options.executionService - The execution service to use. Defaults to\n * {@link NodeThreadExecutionService}. You do not need to provide this unless\n * you are testing a custom execution service.\n * @param options.executionServiceOptions - The options to use when creating the\n * execution service, if any. This should only include options specific to the\n * provided execution service.\n * @param options.options - The simulation options.\n * @returns The snap.\n * @throws If the built-in server is not running, and no snap ID is provided.\n */\nexport async function installSnap<\n Service extends new (\n ...args: any[]\n ) => InstanceType<typeof AbstractExecutionService>,\n>(options: Partial<InstallSnapOptions<Service>>): Promise<Snap>;\n\n/**\n * Load a snap into the environment. This is the main entry point for testing\n * snaps: It returns a {@link Snap} object that can be used to interact with the\n * snap.\n *\n * @example\n * import { installSnap } from '@metamask/snaps-jest';\n *\n * describe('My Snap', () => {\n * it('should do something', async () => {\n * const { request } = await installSnap('local:my-snap');\n * const response = await request({\n * method: 'foo',\n * params: ['bar'],\n * });\n * expect(response).toRespondWith('bar');\n * });\n * });\n * @param snapId - The ID of the snap, including the prefix (`local:`). Defaults\n * to the URL of the built-in server, if it is running. This supports both\n * local snap IDs and NPM snap IDs.\n * @param options - The options to use.\n * @param options.executionService - The execution service to use. Defaults to\n * {@link NodeThreadExecutionService}. You do not need to provide this unless\n * you are testing a custom execution service.\n * @param options.executionServiceOptions - The options to use when creating the\n * execution service, if any. This should only include options specific to the\n * provided execution service.\n * @param options.options - The simulation options.\n * @returns The snap.\n * @throws If the built-in server is not running, and no snap ID is provided.\n */\nexport async function installSnap<\n Service extends new (\n ...args: any[]\n ) => InstanceType<typeof AbstractExecutionService>,\n>(\n snapId: SnapId,\n options?: Partial<InstallSnapOptions<Service>>,\n): Promise<Snap>;\n\n/**\n * Load a snap into the environment. This is the main entry point for testing\n * snaps: It returns a {@link Snap} object that can be used to interact with the\n * snap.\n *\n * @example\n * import { installSnap } from '@metamask/snaps-jest';\n *\n * describe('My Snap', () => {\n * it('should do something', async () => {\n * const { request } = await installSnap('local:my-snap');\n * const response = await request({\n * method: 'foo',\n * params: ['bar'],\n * });\n * expect(response).toRespondWith('bar');\n * });\n * });\n * @param snapId - The ID of the snap, including the prefix (`local:`). Defaults\n * to the URL of the built-in server, if it is running. This supports both\n * local snap IDs and NPM snap IDs.\n * @param options - The options to use.\n * @param options.executionService - The execution service to use. Defaults to\n * {@link NodeThreadExecutionService}. You do not need to provide this unless\n * you are testing a custom execution service.\n * @param options.executionServiceOptions - The options to use when creating the\n * execution service, if any. This should only include options specific to the\n * provided execution service.\n * @param options.options - The simulation options.\n * @returns The snap.\n * @throws If the built-in server is not running, and no snap ID is provided.\n */\nexport async function installSnap<\n Service extends new (\n ...args: any[]\n ) => InstanceType<typeof AbstractExecutionService>,\n>(\n snapId?: SnapId | Partial<InstallSnapOptions<Service>>,\n options: Partial<InstallSnapOptions<Service>> = {},\n): Promise<Snap> {\n const resolvedOptions = getOptions(snapId, options);\n\n // TODO: Either fix this lint violation or explain why it's necessary to\n // ignore.\n /* eslint-disable @typescript-eslint/unbound-method */\n const {\n request,\n onTransaction,\n sendTransaction,\n onSignature,\n onCronjob,\n runCronjob,\n onBackgroundEvent,\n onHomePage,\n onSettingsPage,\n onKeyringRequest,\n onInstall,\n onUpdate,\n onStart,\n onNameLookup,\n onProtocolRequest,\n onClientRequest,\n mockJsonRpc,\n close,\n } = await getEnvironment().installSnap(...resolvedOptions);\n /* eslint-enable @typescript-eslint/unbound-method */\n\n return {\n request,\n onTransaction,\n sendTransaction,\n onSignature,\n onCronjob,\n runCronjob,\n onBackgroundEvent,\n onHomePage,\n onSettingsPage,\n onKeyringRequest,\n onInstall,\n onUpdate,\n onStart,\n onNameLookup,\n onProtocolRequest,\n onClientRequest,\n mockJsonRpc,\n close: async () => {\n log('Closing execution service.');\n logInfo(\n 'Calling `snap.close()` is deprecated, and will be removed in a future release. Snaps are now automatically closed when the test ends.',\n );\n\n await close();\n },\n };\n}\n\n/**\n * Get the state of an AccountSelector based on a {@link SimulationAccount}.\n *\n * @param account - The {@link SimulationAccount} to get the state from.\n * @returns The state of the AccountSelector.\n */\nexport function getStateFromAccount(\n account: SimulationAccount,\n): AccountSelectorState {\n const { address, scopes } = account;\n return {\n addresses: scopes.map((scope) => `${scope}:${address}`) as CaipAccountId[],\n accountId: account.id,\n };\n}\n\n/**\n * Get the state of an AssetSelector based on a {@link SimulationAsset}.\n *\n * @param id - The Asset id as a CAIP-19 asset type.\n * @param assets - The {@link SimulationAsset} to get the state from.\n * @returns The state of the AssetSelector.\n */\nexport function getStateFromAsset(\n id: CaipAssetType,\n assets: Record<CaipAssetType, SimulationAsset>,\n): AssetSelectorState {\n const asset = assets[id];\n\n assert(asset, `Asset with ID \"${id}\" not found in simulation assets.`);\n\n const { symbol, name } = asset;\n\n return {\n asset: id,\n symbol,\n name,\n };\n}\n\n/**\n * Generate a pseudo-random UUID.\n *\n * @returns A pseudo-random UUID string.\n */\nconst getPseudoRandomUuid = getPseudoRandomUuidGenerator();\n\n/**\n * The base options for the {@link getMockAccount} function.\n */\nexport type BaseMockAccountOptions = {\n /**\n * The address of the account.\n */\n address: string;\n\n /**\n * The ID of the account. If not provided, a pseudo-random UUID will be\n * generated.\n */\n id?: string;\n\n /**\n * Whether the account is selected by default.\n */\n selected?: boolean;\n};\n\n/**\n * Options for creating a mock account with assets or scopes. If `scopes` are\n * not provided, they will be derived from the `assets`.\n *\n * @see BaseMockAccountOptions\n */\nexport type MockAccountOptionsWithAssets = BaseMockAccountOptions & {\n /**\n * The assets associated with the account. These should be in CAIP format.\n */\n assets: CaipAssetType[];\n\n /**\n * The scopes associated with the account. If not provided, they will be\n * derived from the `assets`.\n */\n scopes?: CaipChainId[];\n};\n\n/**\n * Options for creating a mock account with scopes, and optionally assets.\n *\n * @see BaseMockAccountOptions\n */\nexport type MockAccountOptionsWithScopes = BaseMockAccountOptions & {\n /**\n * The scopes associated with the account. These should be in CAIP format.\n */\n scopes: CaipChainId[];\n\n /**\n * The assets associated with the account. If not provided, it will default\n * to an empty array.\n */\n assets?: CaipAssetType[];\n};\n\nexport type GetMockAccountOptions =\n | MockAccountOptionsWithAssets\n | MockAccountOptionsWithScopes;\n\n/**\n * Get a mock account object for testing purposes.\n *\n * @param options - The options for creating the mock account.\n * @param options.address - The address of the account.\n * @param options.scopes - The scopes associated with the account, in CAIP\n * format. If not provided, they will be derived from the `assets`.\n * @param options.assets - The assets associated with the account, in CAIP\n * format. If not provided, it will default to an empty array.\n * @param options.selected - Whether the account is selected by default.\n * @param options.id - The ID of the account. If not provided, a pseudo-random\n * UUID will be generated.\n * @returns A mock account object with the specified properties.\n */\nexport function getMockAccount({\n address,\n assets = [],\n selected = false,\n id = getPseudoRandomUuid(),\n scopes = getScopesFromAssets(assets),\n}: GetMockAccountOptions): SimulationAccount {\n return {\n address,\n id,\n scopes,\n selected,\n assets,\n };\n}\n"]}
@@ -1,6 +1,7 @@
1
1
  import type { AbstractExecutionService } from "@metamask/snaps-controllers";
2
- import type { SnapId } from "@metamask/snaps-sdk";
3
- import type { InstallSnapOptions, Snap } from "@metamask/snaps-simulation";
2
+ import type { AccountSelectorState, AssetSelectorState, SnapId } from "@metamask/snaps-sdk";
3
+ import type { InstallSnapOptions, SimulationAccount, SimulationAsset, Snap } from "@metamask/snaps-simulation";
4
+ import type { CaipAssetType, CaipChainId } from "@metamask/utils";
4
5
  /**
5
6
  * Load a snap into the environment. This is the main entry point for testing
6
7
  * snaps: It returns a {@link Snap} object that can be used to interact with the
@@ -86,4 +87,86 @@ export declare function installSnap<Service extends new (...args: any[]) => Inst
86
87
  * @throws If the built-in server is not running, and no snap ID is provided.
87
88
  */
88
89
  export declare function installSnap<Service extends new (...args: any[]) => InstanceType<typeof AbstractExecutionService>>(snapId: SnapId, options?: Partial<InstallSnapOptions<Service>>): Promise<Snap>;
90
+ /**
91
+ * Get the state of an AccountSelector based on a {@link SimulationAccount}.
92
+ *
93
+ * @param account - The {@link SimulationAccount} to get the state from.
94
+ * @returns The state of the AccountSelector.
95
+ */
96
+ export declare function getStateFromAccount(account: SimulationAccount): AccountSelectorState;
97
+ /**
98
+ * Get the state of an AssetSelector based on a {@link SimulationAsset}.
99
+ *
100
+ * @param id - The Asset id as a CAIP-19 asset type.
101
+ * @param assets - The {@link SimulationAsset} to get the state from.
102
+ * @returns The state of the AssetSelector.
103
+ */
104
+ export declare function getStateFromAsset(id: CaipAssetType, assets: Record<CaipAssetType, SimulationAsset>): AssetSelectorState;
105
+ /**
106
+ * The base options for the {@link getMockAccount} function.
107
+ */
108
+ export type BaseMockAccountOptions = {
109
+ /**
110
+ * The address of the account.
111
+ */
112
+ address: string;
113
+ /**
114
+ * The ID of the account. If not provided, a pseudo-random UUID will be
115
+ * generated.
116
+ */
117
+ id?: string;
118
+ /**
119
+ * Whether the account is selected by default.
120
+ */
121
+ selected?: boolean;
122
+ };
123
+ /**
124
+ * Options for creating a mock account with assets or scopes. If `scopes` are
125
+ * not provided, they will be derived from the `assets`.
126
+ *
127
+ * @see BaseMockAccountOptions
128
+ */
129
+ export type MockAccountOptionsWithAssets = BaseMockAccountOptions & {
130
+ /**
131
+ * The assets associated with the account. These should be in CAIP format.
132
+ */
133
+ assets: CaipAssetType[];
134
+ /**
135
+ * The scopes associated with the account. If not provided, they will be
136
+ * derived from the `assets`.
137
+ */
138
+ scopes?: CaipChainId[];
139
+ };
140
+ /**
141
+ * Options for creating a mock account with scopes, and optionally assets.
142
+ *
143
+ * @see BaseMockAccountOptions
144
+ */
145
+ export type MockAccountOptionsWithScopes = BaseMockAccountOptions & {
146
+ /**
147
+ * The scopes associated with the account. These should be in CAIP format.
148
+ */
149
+ scopes: CaipChainId[];
150
+ /**
151
+ * The assets associated with the account. If not provided, it will default
152
+ * to an empty array.
153
+ */
154
+ assets?: CaipAssetType[];
155
+ };
156
+ export type GetMockAccountOptions = MockAccountOptionsWithAssets | MockAccountOptionsWithScopes;
157
+ /**
158
+ * Get a mock account object for testing purposes.
159
+ *
160
+ * @param options - The options for creating the mock account.
161
+ * @param options.address - The address of the account.
162
+ * @param options.scopes - The scopes associated with the account, in CAIP
163
+ * format. If not provided, they will be derived from the `assets`.
164
+ * @param options.assets - The assets associated with the account, in CAIP
165
+ * format. If not provided, it will default to an empty array.
166
+ * @param options.selected - Whether the account is selected by default.
167
+ * @param options.id - The ID of the account. If not provided, a pseudo-random
168
+ * UUID will be generated.
169
+ * @returns A mock account object with the specified properties.
170
+ */
171
+ export declare function getMockAccount({ address, assets, selected, id, scopes, }: GetMockAccountOptions): SimulationAccount;
89
172
  //# sourceMappingURL=helpers.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.d.cts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAAA,OA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CAAC;IAEtB;;;OAGG;IACH,MAAM,CAAC,EAAE,aAAa,EAAE,CAAC;CAC1B,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAC7B,4BAA4B,GAC5B,4BAA4B,CAAC;AAEjC;;;;;;;;;;;;;GAaG;AACH,wBAAgB,cAAc,CAAC,EAC7B,OAAO,EACP,MAAW,EACX,QAAgB,EAChB,EAA0B,EAC1B,MAAoC,GACrC,EAAE,qBAAqB,GAAG,iBAAiB,CAQ3C"}
@@ -1,6 +1,7 @@
1
1
  import type { AbstractExecutionService } from "@metamask/snaps-controllers";
2
- import type { SnapId } from "@metamask/snaps-sdk";
3
- import type { InstallSnapOptions, Snap } from "@metamask/snaps-simulation";
2
+ import type { AccountSelectorState, AssetSelectorState, SnapId } from "@metamask/snaps-sdk";
3
+ import type { InstallSnapOptions, SimulationAccount, SimulationAsset, Snap } from "@metamask/snaps-simulation";
4
+ import type { CaipAssetType, CaipChainId } from "@metamask/utils";
4
5
  /**
5
6
  * Load a snap into the environment. This is the main entry point for testing
6
7
  * snaps: It returns a {@link Snap} object that can be used to interact with the
@@ -86,4 +87,86 @@ export declare function installSnap<Service extends new (...args: any[]) => Inst
86
87
  * @throws If the built-in server is not running, and no snap ID is provided.
87
88
  */
88
89
  export declare function installSnap<Service extends new (...args: any[]) => InstanceType<typeof AbstractExecutionService>>(snapId: SnapId, options?: Partial<InstallSnapOptions<Service>>): Promise<Snap>;
90
+ /**
91
+ * Get the state of an AccountSelector based on a {@link SimulationAccount}.
92
+ *
93
+ * @param account - The {@link SimulationAccount} to get the state from.
94
+ * @returns The state of the AccountSelector.
95
+ */
96
+ export declare function getStateFromAccount(account: SimulationAccount): AccountSelectorState;
97
+ /**
98
+ * Get the state of an AssetSelector based on a {@link SimulationAsset}.
99
+ *
100
+ * @param id - The Asset id as a CAIP-19 asset type.
101
+ * @param assets - The {@link SimulationAsset} to get the state from.
102
+ * @returns The state of the AssetSelector.
103
+ */
104
+ export declare function getStateFromAsset(id: CaipAssetType, assets: Record<CaipAssetType, SimulationAsset>): AssetSelectorState;
105
+ /**
106
+ * The base options for the {@link getMockAccount} function.
107
+ */
108
+ export type BaseMockAccountOptions = {
109
+ /**
110
+ * The address of the account.
111
+ */
112
+ address: string;
113
+ /**
114
+ * The ID of the account. If not provided, a pseudo-random UUID will be
115
+ * generated.
116
+ */
117
+ id?: string;
118
+ /**
119
+ * Whether the account is selected by default.
120
+ */
121
+ selected?: boolean;
122
+ };
123
+ /**
124
+ * Options for creating a mock account with assets or scopes. If `scopes` are
125
+ * not provided, they will be derived from the `assets`.
126
+ *
127
+ * @see BaseMockAccountOptions
128
+ */
129
+ export type MockAccountOptionsWithAssets = BaseMockAccountOptions & {
130
+ /**
131
+ * The assets associated with the account. These should be in CAIP format.
132
+ */
133
+ assets: CaipAssetType[];
134
+ /**
135
+ * The scopes associated with the account. If not provided, they will be
136
+ * derived from the `assets`.
137
+ */
138
+ scopes?: CaipChainId[];
139
+ };
140
+ /**
141
+ * Options for creating a mock account with scopes, and optionally assets.
142
+ *
143
+ * @see BaseMockAccountOptions
144
+ */
145
+ export type MockAccountOptionsWithScopes = BaseMockAccountOptions & {
146
+ /**
147
+ * The scopes associated with the account. These should be in CAIP format.
148
+ */
149
+ scopes: CaipChainId[];
150
+ /**
151
+ * The assets associated with the account. If not provided, it will default
152
+ * to an empty array.
153
+ */
154
+ assets?: CaipAssetType[];
155
+ };
156
+ export type GetMockAccountOptions = MockAccountOptionsWithAssets | MockAccountOptionsWithScopes;
157
+ /**
158
+ * Get a mock account object for testing purposes.
159
+ *
160
+ * @param options - The options for creating the mock account.
161
+ * @param options.address - The address of the account.
162
+ * @param options.scopes - The scopes associated with the account, in CAIP
163
+ * format. If not provided, they will be derived from the `assets`.
164
+ * @param options.assets - The assets associated with the account, in CAIP
165
+ * format. If not provided, it will default to an empty array.
166
+ * @param options.selected - Whether the account is selected by default.
167
+ * @param options.id - The ID of the account. If not provided, a pseudo-random
168
+ * UUID will be generated.
169
+ * @returns A mock account object with the specified properties.
170
+ */
171
+ export declare function getMockAccount({ address, assets, selected, id, scopes, }: GetMockAccountOptions): SimulationAccount;
89
172
  //# sourceMappingURL=helpers.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.d.mts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,oCAAoC;AAC5E,OAAO,KAAK,EAAE,MAAM,EAAE,4BAA4B;AAClD,OAAO,KAAK,EAAE,kBAAkB,EAAE,IAAI,EAAE,mCAAmC;AA8B3E;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAsB,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;AAEnD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAsB,WAAW,CAC/B,OAAO,SAAS,KACd,GAAG,IAAI,EAAE,GAAG,EAAE,KACX,YAAY,CAAC,OAAO,wBAAwB,CAAC,EAClD,OAAO,EAAE,OAAO,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAEhE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAsB,WAAW,CAC/B,OAAO,SAAS,KACd,GAAG,IAAI,EAAE,GAAG,EAAE,KACX,YAAY,CAAC,OAAO,wBAAwB,CAAC,EAElD,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,OAAO,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC,GAC7C,OAAO,CAAC,IAAI,CAAC,CAAC"}
1
+ {"version":3,"file":"helpers.d.mts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,oCAAoC;AAC5E,OAAO,KAAK,EACV,oBAAoB,EACpB,kBAAkB,EAClB,MAAM,EACP,4BAA4B;AAC7B,OAAO,KAAK,EACV,kBAAkB,EAClB,iBAAiB,EACjB,e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H,MAAM,EAAE,aAAa,EAAE,CAAC;IAExB;;;OAGG;IACH,MAAM,CAAC,EAAE,WAAW,EAAE,CAAC;CACxB,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,4BAA4B,GAAG,sBAAsB,GAAG;IAClE;;OAEG;IACH,MAAM,EAAE,WAAW,EAAE,CAAC;IAEtB;;;OAGG;IACH,MAAM,CAAC,EAAE,aAAa,EAAE,CAAC;CAC1B,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAC7B,4BAA4B,GAC5B,4BAA4B,CAAC;AAEjC;;;;;;;;;;;;;GAaG;AACH,wBAAgB,cAAc,CAAC,EAC7B,OAAO,EACP,MAAW,EACX,QAAgB,EAChB,EAA0B,EAC1B,MAAoC,GACrC,EAAE,qBAAqB,GAAG,iBAAiB,CAQ3C"}
package/dist/helpers.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { logInfo } from "@metamask/snaps-utils";
2
- import { createModuleLogger } from "@metamask/utils";
3
- import { rootLogger, getEnvironment } from "./internals/index.mjs";
2
+ import { assert, createModuleLogger } from "@metamask/utils";
3
+ import { rootLogger, getEnvironment, getPseudoRandomUuidGenerator, getScopesFromAssets } from "./internals/index.mjs";
4
4
  const log = createModuleLogger(rootLogger, 'helpers');
5
5
  /**
6
6
  * Get the options for {@link installSnap}.
@@ -52,7 +52,7 @@ export async function installSnap(snapId, options = {}) {
52
52
  // TODO: Either fix this lint violation or explain why it's necessary to
53
53
  // ignore.
54
54
  /* eslint-disable @typescript-eslint/unbound-method */
55
- const { request, onTransaction, sendTransaction, onSignature, onCronjob, runCronjob, onBackgroundEvent, onHomePage, onSettingsPage, onKeyringRequest, onInstall, onUpdate, onNameLookup, onProtocolRequest, onClientRequest, mockJsonRpc, close, } = await getEnvironment().installSnap(...resolvedOptions);
55
+ const { request, onTransaction, sendTransaction, onSignature, onCronjob, runCronjob, onBackgroundEvent, onHomePage, onSettingsPage, onKeyringRequest, onInstall, onUpdate, onStart, onNameLookup, onProtocolRequest, onClientRequest, mockJsonRpc, close, } = await getEnvironment().installSnap(...resolvedOptions);
56
56
  /* eslint-enable @typescript-eslint/unbound-method */
57
57
  return {
58
58
  request,
@@ -67,6 +67,7 @@ export async function installSnap(snapId, options = {}) {
67
67
  onKeyringRequest,
68
68
  onInstall,
69
69
  onUpdate,
70
+ onStart,
70
71
  onNameLookup,
71
72
  onProtocolRequest,
72
73
  onClientRequest,
@@ -78,4 +79,63 @@ export async function installSnap(snapId, options = {}) {
78
79
  },
79
80
  };
80
81
  }
82
+ /**
83
+ * Get the state of an AccountSelector based on a {@link SimulationAccount}.
84
+ *
85
+ * @param account - The {@link SimulationAccount} to get the state from.
86
+ * @returns The state of the AccountSelector.
87
+ */
88
+ export function getStateFromAccount(account) {
89
+ const { address, scopes } = account;
90
+ return {
91
+ addresses: scopes.map((scope) => `${scope}:${address}`),
92
+ accountId: account.id,
93
+ };
94
+ }
95
+ /**
96
+ * Get the state of an AssetSelector based on a {@link SimulationAsset}.
97
+ *
98
+ * @param id - The Asset id as a CAIP-19 asset type.
99
+ * @param assets - The {@link SimulationAsset} to get the state from.
100
+ * @returns The state of the AssetSelector.
101
+ */
102
+ export function getStateFromAsset(id, assets) {
103
+ const asset = assets[id];
104
+ assert(asset, `Asset with ID "${id}" not found in simulation assets.`);
105
+ const { symbol, name } = asset;
106
+ return {
107
+ asset: id,
108
+ symbol,
109
+ name,
110
+ };
111
+ }
112
+ /**
113
+ * Generate a pseudo-random UUID.
114
+ *
115
+ * @returns A pseudo-random UUID string.
116
+ */
117
+ const getPseudoRandomUuid = getPseudoRandomUuidGenerator();
118
+ /**
119
+ * Get a mock account object for testing purposes.
120
+ *
121
+ * @param options - The options for creating the mock account.
122
+ * @param options.address - The address of the account.
123
+ * @param options.scopes - The scopes associated with the account, in CAIP
124
+ * format. If not provided, they will be derived from the `assets`.
125
+ * @param options.assets - The assets associated with the account, in CAIP
126
+ * format. If not provided, it will default to an empty array.
127
+ * @param options.selected - Whether the account is selected by default.
128
+ * @param options.id - The ID of the account. If not provided, a pseudo-random
129
+ * UUID will be generated.
130
+ * @returns A mock account object with the specified properties.
131
+ */
132
+ export function getMockAccount({ address, assets = [], selected = false, id = getPseudoRandomUuid(), scopes = getScopesFromAssets(assets), }) {
133
+ return {
134
+ address,
135
+ id,
136
+ scopes,
137
+ selected,
138
+ assets,
139
+ };
140
+ }
81
141
  //# sourceMappingURL=helpers.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.mjs","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,8BAA8B;AAChD,OAAO,EAAE,kBAAkB,EAAE,wBAAwB;AAErD,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,8BAAoB;AAEzD,MAAM,GAAG,GAAG,kBAAkB,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC;AAEtD;;;;;;GAMG;AACH,SAAS,UAAU,CAKjB,MAAiE,EACjE,OAA6C;IAE7C,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;QAC/B,OAAO,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;IAC7B,CAAC;IAED,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAC3B,CAAC;AAqGD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAK/B,MAAsD,EACtD,UAAgD,EAAE;IAElD,MAAM,eAAe,GAAG,UAAU,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAEpD,wEAAwE;IACxE,WAAW;IACX,sDAAsD;IACtD,MAAM,EACJ,OAAO,EACP,aAAa,EACb,eAAe,EACf,WAAW,EACX,SAAS,EACT,UAAU,EACV,iBAAiB,EACjB,UAAU,EACV,cAAc,EACd,gBAAgB,EAChB,SAAS,EACT,QAAQ,EACR,YAAY,EACZ,iBAAiB,EACjB,eAAe,EACf,WAAW,EACX,KAAK,GACN,GAAG,MAAM,cAAc,EAAE,CAAC,WAAW,CAAC,GAAG,eAAe,CAAC,CAAC;IAC3D,qDAAqD;IAErD,OAAO;QACL,OAAO;QACP,aAAa;QACb,eAAe;QACf,WAAW;QACX,SAAS;QACT,UAAU;QACV,iBAAiB;QACjB,UAAU;QACV,cAAc;QACd,gBAAgB;QAChB,SAAS;QACT,QAAQ;QACR,YAAY;QACZ,iBAAiB;QACjB,eAAe;QACf,WAAW;QACX,KAAK,EAAE,KAAK,IAAI,EAAE;YAChB,GAAG,CAAC,4BAA4B,CAAC,CAAC;YAClC,OAAO,CACL,uIAAuI,CACxI,CAAC;YAEF,MAAM,KAAK,EAAE,CAAC;QAChB,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import type { AbstractExecutionService } from '@metamask/snaps-controllers';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport type { InstallSnapOptions, Snap } from '@metamask/snaps-simulation';\nimport { logInfo } from '@metamask/snaps-utils';\nimport { createModuleLogger } from '@metamask/utils';\n\nimport { rootLogger, getEnvironment } from './internals';\n\nconst log = createModuleLogger(rootLogger, 'helpers');\n\n/**\n * Get the options for {@link installSnap}.\n *\n * @param snapId - The ID of the Snap, or the options.\n * @param options - The options, if any.\n * @returns The options.\n */\nfunction getOptions<\n Service extends new (\n ...args: any[]\n ) => InstanceType<typeof AbstractExecutionService>,\n>(\n snapId: SnapId | Partial<InstallSnapOptions<Service>> | undefined,\n options: Partial<InstallSnapOptions<Service>>,\n): [SnapId | undefined, Partial<InstallSnapOptions<Service>>] {\n if (typeof snapId === 'object') {\n return [undefined, snapId];\n }\n\n return [snapId, options];\n}\n\n/**\n * Load a snap into the environment. This is the main entry point for testing\n * snaps: It returns a {@link Snap} object that can be used to interact with the\n * snap.\n *\n * @example\n * import { installSnap } from '@metamask/snaps-jest';\n *\n * describe('My Snap', () => {\n * it('should do something', async () => {\n * const { request } = await installSnap('local:my-snap');\n * const response = await request({\n * method: 'foo',\n * params: ['bar'],\n * });\n * expect(response).toRespondWith('bar');\n * });\n * });\n * @returns The snap.\n * @throws If the built-in server is not running, and no snap ID is provided.\n */\nexport async function installSnap(): Promise<Snap>;\n\n/**\n * Load a snap into the environment. This is the main entry point for testing\n * snaps: It returns a {@link Snap} object that can be used to interact with the\n * snap.\n *\n * @example\n * import { installSnap } from '@metamask/snaps-jest';\n *\n * describe('My Snap', () => {\n * it('should do something', async () => {\n * const { request } = await installSnap('local:my-snap');\n * const response = await request({\n * method: 'foo',\n * params: ['bar'],\n * });\n * expect(response).toRespondWith('bar');\n * });\n * });\n * @param options - The options to use.\n * @param options.executionService - The execution service to use. Defaults to\n * {@link NodeThreadExecutionService}. You do not need to provide this unless\n * you are testing a custom execution service.\n * @param options.executionServiceOptions - The options to use when creating the\n * execution service, if any. This should only include options specific to the\n * provided execution service.\n * @param options.options - The simulation options.\n * @returns The snap.\n * @throws If the built-in server is not running, and no snap ID is provided.\n */\nexport async function installSnap<\n Service extends new (\n ...args: any[]\n ) => InstanceType<typeof AbstractExecutionService>,\n>(options: Partial<InstallSnapOptions<Service>>): Promise<Snap>;\n\n/**\n * Load a snap into the environment. This is the main entry point for testing\n * snaps: It returns a {@link Snap} object that can be used to interact with the\n * snap.\n *\n * @example\n * import { installSnap } from '@metamask/snaps-jest';\n *\n * describe('My Snap', () => {\n * it('should do something', async () => {\n * const { request } = await installSnap('local:my-snap');\n * const response = await request({\n * method: 'foo',\n * params: ['bar'],\n * });\n * expect(response).toRespondWith('bar');\n * });\n * });\n * @param snapId - The ID of the snap, including the prefix (`local:`). Defaults\n * to the URL of the built-in server, if it is running. This supports both\n * local snap IDs and NPM snap IDs.\n * @param options - The options to use.\n * @param options.executionService - The execution service to use. Defaults to\n * {@link NodeThreadExecutionService}. You do not need to provide this unless\n * you are testing a custom execution service.\n * @param options.executionServiceOptions - The options to use when creating the\n * execution service, if any. This should only include options specific to the\n * provided execution service.\n * @param options.options - The simulation options.\n * @returns The snap.\n * @throws If the built-in server is not running, and no snap ID is provided.\n */\nexport async function installSnap<\n Service extends new (\n ...args: any[]\n ) => InstanceType<typeof AbstractExecutionService>,\n>(\n snapId: SnapId,\n options?: Partial<InstallSnapOptions<Service>>,\n): Promise<Snap>;\n\n/**\n * Load a snap into the environment. This is the main entry point for testing\n * snaps: It returns a {@link Snap} object that can be used to interact with the\n * snap.\n *\n * @example\n * import { installSnap } from '@metamask/snaps-jest';\n *\n * describe('My Snap', () => {\n * it('should do something', async () => {\n * const { request } = await installSnap('local:my-snap');\n * const response = await request({\n * method: 'foo',\n * params: ['bar'],\n * });\n * expect(response).toRespondWith('bar');\n * });\n * });\n * @param snapId - The ID of the snap, including the prefix (`local:`). Defaults\n * to the URL of the built-in server, if it is running. This supports both\n * local snap IDs and NPM snap IDs.\n * @param options - The options to use.\n * @param options.executionService - The execution service to use. Defaults to\n * {@link NodeThreadExecutionService}. You do not need to provide this unless\n * you are testing a custom execution service.\n * @param options.executionServiceOptions - The options to use when creating the\n * execution service, if any. This should only include options specific to the\n * provided execution service.\n * @param options.options - The simulation options.\n * @returns The snap.\n * @throws If the built-in server is not running, and no snap ID is provided.\n */\nexport async function installSnap<\n Service extends new (\n ...args: any[]\n ) => InstanceType<typeof AbstractExecutionService>,\n>(\n snapId?: SnapId | Partial<InstallSnapOptions<Service>>,\n options: Partial<InstallSnapOptions<Service>> = {},\n): Promise<Snap> {\n const resolvedOptions = getOptions(snapId, options);\n\n // TODO: Either fix this lint violation or explain why it's necessary to\n // ignore.\n /* eslint-disable @typescript-eslint/unbound-method */\n const {\n request,\n onTransaction,\n sendTransaction,\n onSignature,\n onCronjob,\n runCronjob,\n onBackgroundEvent,\n onHomePage,\n onSettingsPage,\n onKeyringRequest,\n onInstall,\n onUpdate,\n onNameLookup,\n onProtocolRequest,\n onClientRequest,\n mockJsonRpc,\n close,\n } = await getEnvironment().installSnap(...resolvedOptions);\n /* eslint-enable @typescript-eslint/unbound-method */\n\n return {\n request,\n onTransaction,\n sendTransaction,\n onSignature,\n onCronjob,\n runCronjob,\n onBackgroundEvent,\n onHomePage,\n onSettingsPage,\n onKeyringRequest,\n onInstall,\n onUpdate,\n onNameLookup,\n onProtocolRequest,\n onClientRequest,\n mockJsonRpc,\n close: async () => {\n log('Closing execution service.');\n logInfo(\n 'Calling `snap.close()` is deprecated, and will be removed in a future release. Snaps are now automatically closed when the test ends.',\n );\n\n await close();\n },\n };\n}\n"]}
1
+ {"version":3,"file":"helpers.mjs","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,OAAO,EAAE,8BAA8B;AAChD,OAAO,EAAE,MAAM,EAAE,kBAAkB,EAAE,wBAAwB;AAO7D,OAAO,EACL,UAAU,EACV,cAAc,EACd,4BAA4B,EAC5B,mBAAmB,EACpB,8BAAoB;AAErB,MAAM,GAAG,GAAG,kBAAkB,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC;AAEtD;;;;;;GAMG;AACH,SAAS,UAAU,CAKjB,MAAiE,EACjE,OAA6C;IAE7C,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;QAC/B,OAAO,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;IAC7B,CAAC;IAED,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAC3B,CAAC;AAqGD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAK/B,MAAsD,EACtD,UAAgD,EAAE;IAElD,MAAM,eAAe,GAAG,UAAU,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAEpD,wEAAwE;IACxE,WAAW;IACX,sDAAsD;IACtD,MAAM,EACJ,OAAO,EACP,aAAa,EACb,eAAe,EACf,WAAW,EACX,SAAS,EACT,UAAU,EACV,iBAAiB,EACjB,UAAU,EACV,cAAc,EACd,gBAAgB,EAChB,SAAS,EACT,QAAQ,EACR,OAAO,EACP,YAAY,EACZ,iBAAiB,EACjB,eAAe,EACf,WAAW,EACX,KAAK,GACN,GAAG,MAAM,cA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AAE,EACX,QAAQ,GAAG,KAAK,EAChB,EAAE,GAAG,mBAAmB,EAAE,EAC1B,MAAM,GAAG,mBAAmB,CAAC,MAAM,CAAC,GACd;IACtB,OAAO;QACL,OAAO;QACP,EAAE;QACF,MAAM;QACN,QAAQ;QACR,MAAM;KACP,CAAC;AACJ,CAAC","sourcesContent":["import type { AbstractExecutionService } from '@metamask/snaps-controllers';\nimport type {\n AccountSelectorState,\n AssetSelectorState,\n SnapId,\n} from '@metamask/snaps-sdk';\nimport type {\n InstallSnapOptions,\n SimulationAccount,\n SimulationAsset,\n Snap,\n} from '@metamask/snaps-simulation';\nimport { logInfo } from '@metamask/snaps-utils';\nimport { assert, createModuleLogger } from '@metamask/utils';\nimport type {\n CaipAccountId,\n CaipAssetType,\n CaipChainId,\n} from '@metamask/utils';\n\nimport {\n rootLogger,\n getEnvironment,\n getPseudoRandomUuidGenerator,\n getScopesFromAssets,\n} from './internals';\n\nconst log = createModuleLogger(rootLogger, 'helpers');\n\n/**\n * Get the options for {@link installSnap}.\n *\n * @param snapId - The ID of the Snap, or the options.\n * @param options - The options, if any.\n * @returns The options.\n */\nfunction getOptions<\n Service extends new (\n ...args: any[]\n ) => InstanceType<typeof AbstractExecutionService>,\n>(\n snapId: SnapId | Partial<InstallSnapOptions<Service>> | undefined,\n options: Partial<InstallSnapOptions<Service>>,\n): [SnapId | undefined, Partial<InstallSnapOptions<Service>>] {\n if (typeof snapId === 'object') {\n return [undefined, snapId];\n }\n\n return [snapId, options];\n}\n\n/**\n * Load a snap into the environment. This is the main entry point for testing\n * snaps: It returns a {@link Snap} object that can be used to interact with the\n * snap.\n *\n * @example\n * import { installSnap } from '@metamask/snaps-jest';\n *\n * describe('My Snap', () => {\n * it('should do something', async () => {\n * const { request } = await installSnap('local:my-snap');\n * const response = await request({\n * method: 'foo',\n * params: ['bar'],\n * });\n * expect(response).toRespondWith('bar');\n * });\n * });\n * @returns The snap.\n * @throws If the built-in server is not running, and no snap ID is provided.\n */\nexport async function installSnap(): Promise<Snap>;\n\n/**\n * Load a snap into the environment. This is the main entry point for testing\n * snaps: It returns a {@link Snap} object that can be used to interact with the\n * snap.\n *\n * @example\n * import { installSnap } from '@metamask/snaps-jest';\n *\n * describe('My Snap', () => {\n * it('should do something', async () => {\n * const { request } = await installSnap('local:my-snap');\n * const response = await request({\n * method: 'foo',\n * params: ['bar'],\n * });\n * expect(response).toRespondWith('bar');\n * });\n * });\n * @param options - The options to use.\n * @param options.executionService - The execution service to use. Defaults to\n * {@link NodeThreadExecutionService}. You do not need to provide this unless\n * you are testing a custom execution service.\n * @param options.executionServiceOptions - The options to use when creating the\n * execution service, if any. This should only include options specific to the\n * provided execution service.\n * @param options.options - The simulation options.\n * @returns The snap.\n * @throws If the built-in server is not running, and no snap ID is provided.\n */\nexport async function installSnap<\n Service extends new (\n ...args: any[]\n ) => InstanceType<typeof AbstractExecutionService>,\n>(options: Partial<InstallSnapOptions<Service>>): Promise<Snap>;\n\n/**\n * Load a snap into the environment. This is the main entry point for testing\n * snaps: It returns a {@link Snap} object that can be used to interact with the\n * snap.\n *\n * @example\n * import { installSnap } from '@metamask/snaps-jest';\n *\n * describe('My Snap', () => {\n * it('should do something', async () => {\n * const { request } = await installSnap('local:my-snap');\n * const response = await request({\n * method: 'foo',\n * params: ['bar'],\n * });\n * expect(response).toRespondWith('bar');\n * });\n * });\n * @param snapId - The ID of the snap, including the prefix (`local:`). Defaults\n * to the URL of the built-in server, if it is running. This supports both\n * local snap IDs and NPM snap IDs.\n * @param options - The options to use.\n * @param options.executionService - The execution service to use. Defaults to\n * {@link NodeThreadExecutionService}. You do not need to provide this unless\n * you are testing a custom execution service.\n * @param options.executionServiceOptions - The options to use when creating the\n * execution service, if any. This should only include options specific to the\n * provided execution service.\n * @param options.options - The simulation options.\n * @returns The snap.\n * @throws If the built-in server is not running, and no snap ID is provided.\n */\nexport async function installSnap<\n Service extends new (\n ...args: any[]\n ) => InstanceType<typeof AbstractExecutionService>,\n>(\n snapId: SnapId,\n options?: Partial<InstallSnapOptions<Service>>,\n): Promise<Snap>;\n\n/**\n * Load a snap into the environment. This is the main entry point for testing\n * snaps: It returns a {@link Snap} object that can be used to interact with the\n * snap.\n *\n * @example\n * import { installSnap } from '@metamask/snaps-jest';\n *\n * describe('My Snap', () => {\n * it('should do something', async () => {\n * const { request } = await installSnap('local:my-snap');\n * const response = await request({\n * method: 'foo',\n * params: ['bar'],\n * });\n * expect(response).toRespondWith('bar');\n * });\n * });\n * @param snapId - The ID of the snap, including the prefix (`local:`). Defaults\n * to the URL of the built-in server, if it is running. This supports both\n * local snap IDs and NPM snap IDs.\n * @param options - The options to use.\n * @param options.executionService - The execution service to use. Defaults to\n * {@link NodeThreadExecutionService}. You do not need to provide this unless\n * you are testing a custom execution service.\n * @param options.executionServiceOptions - The options to use when creating the\n * execution service, if any. This should only include options specific to the\n * provided execution service.\n * @param options.options - The simulation options.\n * @returns The snap.\n * @throws If the built-in server is not running, and no snap ID is provided.\n */\nexport async function installSnap<\n Service extends new (\n ...args: any[]\n ) => InstanceType<typeof AbstractExecutionService>,\n>(\n snapId?: SnapId | Partial<InstallSnapOptions<Service>>,\n options: Partial<InstallSnapOptions<Service>> = {},\n): Promise<Snap> {\n const resolvedOptions = getOptions(snapId, options);\n\n // TODO: Either fix this lint violation or explain why it's necessary to\n // ignore.\n /* eslint-disable @typescript-eslint/unbound-method */\n const {\n request,\n onTransaction,\n sendTransaction,\n onSignature,\n onCronjob,\n runCronjob,\n onBackgroundEvent,\n onHomePage,\n onSettingsPage,\n onKeyringRequest,\n onInstall,\n onUpdate,\n onStart,\n onNameLookup,\n onProtocolRequest,\n onClientRequest,\n mockJsonRpc,\n close,\n } = await getEnvironment().installSnap(...resolvedOptions);\n /* eslint-enable @typescript-eslint/unbound-method */\n\n return {\n request,\n onTransaction,\n sendTransaction,\n onSignature,\n onCronjob,\n runCronjob,\n onBackgroundEvent,\n onHomePage,\n onSettingsPage,\n onKeyringRequest,\n onInstall,\n onUpdate,\n onStart,\n onNameLookup,\n onProtocolRequest,\n onClientRequest,\n mockJsonRpc,\n close: async () => {\n log('Closing execution service.');\n logInfo(\n 'Calling `snap.close()` is deprecated, and will be removed in a future release. Snaps are now automatically closed when the test ends.',\n );\n\n await close();\n },\n };\n}\n\n/**\n * Get the state of an AccountSelector based on a {@link SimulationAccount}.\n *\n * @param account - The {@link SimulationAccount} to get the state from.\n * @returns The state of the AccountSelector.\n */\nexport function getStateFromAccount(\n account: SimulationAccount,\n): AccountSelectorState {\n const { address, scopes } = account;\n return {\n addresses: scopes.map((scope) => `${scope}:${address}`) as CaipAccountId[],\n accountId: account.id,\n };\n}\n\n/**\n * Get the state of an AssetSelector based on a {@link SimulationAsset}.\n *\n * @param id - The Asset id as a CAIP-19 asset type.\n * @param assets - The {@link SimulationAsset} to get the state from.\n * @returns The state of the AssetSelector.\n */\nexport function getStateFromAsset(\n id: CaipAssetType,\n assets: Record<CaipAssetType, SimulationAsset>,\n): AssetSelectorState {\n const asset = assets[id];\n\n assert(asset, `Asset with ID \"${id}\" not found in simulation assets.`);\n\n const { symbol, name } = asset;\n\n return {\n asset: id,\n symbol,\n name,\n };\n}\n\n/**\n * Generate a pseudo-random UUID.\n *\n * @returns A pseudo-random UUID string.\n */\nconst getPseudoRandomUuid = getPseudoRandomUuidGenerator();\n\n/**\n * The base options for the {@link getMockAccount} function.\n */\nexport type BaseMockAccountOptions = {\n /**\n * The address of the account.\n */\n address: string;\n\n /**\n * The ID of the account. If not provided, a pseudo-random UUID will be\n * generated.\n */\n id?: string;\n\n /**\n * Whether the account is selected by default.\n */\n selected?: boolean;\n};\n\n/**\n * Options for creating a mock account with assets or scopes. If `scopes` are\n * not provided, they will be derived from the `assets`.\n *\n * @see BaseMockAccountOptions\n */\nexport type MockAccountOptionsWithAssets = BaseMockAccountOptions & {\n /**\n * The assets associated with the account. These should be in CAIP format.\n */\n assets: CaipAssetType[];\n\n /**\n * The scopes associated with the account. If not provided, they will be\n * derived from the `assets`.\n */\n scopes?: CaipChainId[];\n};\n\n/**\n * Options for creating a mock account with scopes, and optionally assets.\n *\n * @see BaseMockAccountOptions\n */\nexport type MockAccountOptionsWithScopes = BaseMockAccountOptions & {\n /**\n * The scopes associated with the account. These should be in CAIP format.\n */\n scopes: CaipChainId[];\n\n /**\n * The assets associated with the account. If not provided, it will default\n * to an empty array.\n */\n assets?: CaipAssetType[];\n};\n\nexport type GetMockAccountOptions =\n | MockAccountOptionsWithAssets\n | MockAccountOptionsWithScopes;\n\n/**\n * Get a mock account object for testing purposes.\n *\n * @param options - The options for creating the mock account.\n * @param options.address - The address of the account.\n * @param options.scopes - The scopes associated with the account, in CAIP\n * format. If not provided, they will be derived from the `assets`.\n * @param options.assets - The assets associated with the account, in CAIP\n * format. If not provided, it will default to an empty array.\n * @param options.selected - Whether the account is selected by default.\n * @param options.id - The ID of the account. If not provided, a pseudo-random\n * UUID will be generated.\n * @returns A mock account object with the specified properties.\n */\nexport function getMockAccount({\n address,\n assets = [],\n selected = false,\n id = getPseudoRandomUuid(),\n scopes = getScopesFromAssets(assets),\n}: GetMockAccountOptions): SimulationAccount {\n return {\n address,\n id,\n scopes,\n selected,\n assets,\n };\n}\n"]}
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getScopesFromAssets = exports.getPseudoRandomUuidGenerator = void 0;
4
+ const utils_1 = require("@metamask/utils");
5
+ const crypto_1 = require("crypto");
6
+ /**
7
+ * Get a function that generates pseudo-random UUIDs. This function uses a
8
+ * counter to generate a unique UUID each time it is called.
9
+ *
10
+ * This is likely not suitable for production use, as it does not guarantee
11
+ * true randomness and is not cryptographically secure. It is intended for
12
+ * testing and mock purposes only.
13
+ *
14
+ * @returns A function that generates a pseudo-random UUID.
15
+ */
16
+ function getPseudoRandomUuidGenerator() {
17
+ let counter = 0;
18
+ return () => {
19
+ const bytes = (0, crypto_1.createHash)('sha256')
20
+ .update(`${counter}`)
21
+ .digest()
22
+ .subarray(0, 16);
23
+ /* eslint-disable no-bitwise */
24
+ bytes[6] = (bytes[6] & 0x0f) | 0x40;
25
+ bytes[8] = (bytes[8] & 0x3f) | 0x80;
26
+ /* eslint-enable no-bitwise */
27
+ counter += 1;
28
+ return (bytes
29
+ .toString('hex')
30
+ .match(/.{1,8}/gu)
31
+ ?.join('-') ?? '');
32
+ };
33
+ }
34
+ exports.getPseudoRandomUuidGenerator = getPseudoRandomUuidGenerator;
35
+ /**
36
+ * Get unique scopes from a list of assets. This assumes the assets are in
37
+ * CAIP format, where the chain ID is the first part of the asset type.
38
+ *
39
+ * @param assets - An array of CAIP asset types.
40
+ * @returns An array of unique CAIP chain IDs derived from the assets.
41
+ */
42
+ function getScopesFromAssets(assets = []) {
43
+ const scopes = assets.map((asset) => {
44
+ const { chainId } = (0, utils_1.parseCaipAssetType)(asset);
45
+ return chainId;
46
+ });
47
+ return Array.from(new Set(scopes));
48
+ }
49
+ exports.getScopesFromAssets = getScopesFromAssets;
50
+ //# sourceMappingURL=accounts.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"accounts.cjs","sourceRoot":"","sources":["../../src/internals/accounts.ts"],"names":[],"mappings":";;;AACA,2CAAqD;AACrD,mCAAoC;AAEpC;;;;;;;;;GASG;AACH,SAAgB,4BAA4B;IAC1C,IAAI,OAAO,GAAG,CAAC,CAAC;IAEhB,OAAO,GAAG,EAAE;QACV,MAAM,KAAK,GAAG,IAAA,mBAAU,EAAC,QAAQ,CAAC;aAC/B,MAAM,CAAC,GAAG,OAAO,EAAE,CAAC;aACpB,MAAM,EAAE;aACR,QAAQ,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QAEnB,+BAA+B;QAC/B,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC;QACpC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC;QACpC,8BAA8B;QAE9B,OAAO,IAAI,CAAC,CAAC;QAEb,OAAO,CACL,KAAK;aACF,QAAQ,CAAC,KAAK,CAAC;aACf,KAAK,CAAC,UAAU,CAAC;YAClB,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CACpB,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AAvBD,oEAuBC;AAED;;;;;;GAMG;AACH,SAAgB,mBAAmB,CACjC,SAA0B,EAAE;IAE5B,MAAM,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;QAClC,MAAM,EAAE,OAAO,EAAE,GAAG,IAAA,0BAAkB,EAAC,KAAK,CAAC,CAAC;QAC9C,OAAO,OAAO,CAAC;IACjB,CAAC,CAAC,CAAC;IAEH,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;AACrC,CAAC;AATD,kDASC","sourcesContent":["import type { CaipAssetType, CaipChainId } from '@metamask/utils';\nimport { parseCaipAssetType } from '@metamask/utils';\nimport { createHash } from 'crypto';\n\n/**\n * Get a function that generates pseudo-random UUIDs. This function uses a\n * counter to generate a unique UUID each time it is called.\n *\n * This is likely not suitable for production use, as it does not guarantee\n * true randomness and is not cryptographically secure. It is intended for\n * testing and mock purposes only.\n *\n * @returns A function that generates a pseudo-random UUID.\n */\nexport function getPseudoRandomUuidGenerator() {\n let counter = 0;\n\n return () => {\n const bytes = createHash('sha256')\n .update(`${counter}`)\n .digest()\n .subarray(0, 16);\n\n /* eslint-disable no-bitwise */\n bytes[6] = (bytes[6] & 0x0f) | 0x40;\n bytes[8] = (bytes[8] & 0x3f) | 0x80;\n /* eslint-enable no-bitwise */\n\n counter += 1;\n\n return (\n bytes\n .toString('hex')\n .match(/.{1,8}/gu)\n ?.join('-') ?? ''\n );\n };\n}\n\n/**\n * Get unique scopes from a list of assets. This assumes the assets are in\n * CAIP format, where the chain ID is the first part of the asset type.\n *\n * @param assets - An array of CAIP asset types.\n * @returns An array of unique CAIP chain IDs derived from the assets.\n */\nexport function getScopesFromAssets(\n assets: CaipAssetType[] = [],\n): CaipChainId[] {\n const scopes = assets.map((asset) => {\n const { chainId } = parseCaipAssetType(asset);\n return chainId;\n });\n\n return Array.from(new Set(scopes));\n}\n"]}
@@ -0,0 +1,21 @@
1
+ import type { CaipAssetType, CaipChainId } from "@metamask/utils";
2
+ /**
3
+ * Get a function that generates pseudo-random UUIDs. This function uses a
4
+ * counter to generate a unique UUID each time it is called.
5
+ *
6
+ * This is likely not suitable for production use, as it does not guarantee
7
+ * true randomness and is not cryptographically secure. It is intended for
8
+ * testing and mock purposes only.
9
+ *
10
+ * @returns A function that generates a pseudo-random UUID.
11
+ */
12
+ export declare function getPseudoRandomUuidGenerator(): () => string;
13
+ /**
14
+ * Get unique scopes from a list of assets. This assumes the assets are in
15
+ * CAIP format, where the chain ID is the first part of the asset type.
16
+ *
17
+ * @param assets - An array of CAIP asset types.
18
+ * @returns An array of unique CAIP chain IDs derived from the assets.
19
+ */
20
+ export declare function getScopesFromAssets(assets?: CaipAssetType[]): CaipChainId[];
21
+ //# sourceMappingURL=accounts.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"accounts.d.cts","sourceRoot":"","sources":["../../src/internals/accounts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,wBAAwB;AAIlE;;;;;;;;;GASG;AACH,wBAAgB,4BAA4B,iBAuB3C;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,GAAE,aAAa,EAAO,GAC3B,WAAW,EAAE,CAOf"}
@@ -0,0 +1,21 @@
1
+ import type { CaipAssetType, CaipChainId } from "@metamask/utils";
2
+ /**
3
+ * Get a function that generates pseudo-random UUIDs. This function uses a
4
+ * counter to generate a unique UUID each time it is called.
5
+ *
6
+ * This is likely not suitable for production use, as it does not guarantee
7
+ * true randomness and is not cryptographically secure. It is intended for
8
+ * testing and mock purposes only.
9
+ *
10
+ * @returns A function that generates a pseudo-random UUID.
11
+ */
12
+ export declare function getPseudoRandomUuidGenerator(): () => string;
13
+ /**
14
+ * Get unique scopes from a list of assets. This assumes the assets are in
15
+ * CAIP format, where the chain ID is the first part of the asset type.
16
+ *
17
+ * @param assets - An array of CAIP asset types.
18
+ * @returns An array of unique CAIP chain IDs derived from the assets.
19
+ */
20
+ export declare function getScopesFromAssets(assets?: CaipAssetType[]): CaipChainId[];
21
+ //# sourceMappingURL=accounts.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"accounts.d.mts","sourceRoot":"","sources":["../../src/internals/accounts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,wBAAwB;AAIlE;;;;;;;;;GASG;AACH,wBAAgB,4BAA4B,iBAuB3C;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,GAAE,aAAa,EAAO,GAC3B,WAAW,EAAE,CAOf"}
@@ -0,0 +1,45 @@
1
+ import { parseCaipAssetType } from "@metamask/utils";
2
+ import { createHash } from "crypto";
3
+ /**
4
+ * Get a function that generates pseudo-random UUIDs. This function uses a
5
+ * counter to generate a unique UUID each time it is called.
6
+ *
7
+ * This is likely not suitable for production use, as it does not guarantee
8
+ * true randomness and is not cryptographically secure. It is intended for
9
+ * testing and mock purposes only.
10
+ *
11
+ * @returns A function that generates a pseudo-random UUID.
12
+ */
13
+ export function getPseudoRandomUuidGenerator() {
14
+ let counter = 0;
15
+ return () => {
16
+ const bytes = createHash('sha256')
17
+ .update(`${counter}`)
18
+ .digest()
19
+ .subarray(0, 16);
20
+ /* eslint-disable no-bitwise */
21
+ bytes[6] = (bytes[6] & 0x0f) | 0x40;
22
+ bytes[8] = (bytes[8] & 0x3f) | 0x80;
23
+ /* eslint-enable no-bitwise */
24
+ counter += 1;
25
+ return (bytes
26
+ .toString('hex')
27
+ .match(/.{1,8}/gu)
28
+ ?.join('-') ?? '');
29
+ };
30
+ }
31
+ /**
32
+ * Get unique scopes from a list of assets. This assumes the assets are in
33
+ * CAIP format, where the chain ID is the first part of the asset type.
34
+ *
35
+ * @param assets - An array of CAIP asset types.
36
+ * @returns An array of unique CAIP chain IDs derived from the assets.
37
+ */
38
+ export function getScopesFromAssets(assets = []) {
39
+ const scopes = assets.map((asset) => {
40
+ const { chainId } = parseCaipAssetType(asset);
41
+ return chainId;
42
+ });
43
+ return Array.from(new Set(scopes));
44
+ }
45
+ //# sourceMappingURL=accounts.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"accounts.mjs","sourceRoot":"","sources":["../../src/internals/accounts.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,wBAAwB;AACrD,OAAO,EAAE,UAAU,EAAE,eAAe;AAEpC;;;;;;;;;GASG;AACH,MAAM,UAAU,4BAA4B;IAC1C,IAAI,OAAO,GAAG,CAAC,CAAC;IAEhB,OAAO,GAAG,EAAE;QACV,MAAM,KAAK,GAAG,UAAU,CAAC,QAAQ,CAAC;aAC/B,MAAM,CAAC,GAAG,OAAO,EAAE,CAAC;aACpB,MAAM,EAAE;aACR,QAAQ,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QAEnB,+BAA+B;QAC/B,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC;QACpC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC;QACpC,8BAA8B;QAE9B,OAAO,IAAI,CAAC,CAAC;QAEb,OAAO,CACL,KAAK;aACF,QAAQ,CAAC,KAAK,CAAC;aACf,KAAK,CAAC,UAAU,CAAC;YAClB,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CACpB,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,mBAAmB,CACjC,SAA0B,EAAE;IAE5B,MAAM,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;QAClC,MAAM,EAAE,OAAO,EAAE,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAAC;QAC9C,OAAO,OAAO,CAAC;IACjB,CAAC,CAAC,CAAC;IAEH,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;AACrC,CAAC","sourcesContent":["import type { CaipAssetType, CaipChainId } from '@metamask/utils';\nimport { parseCaipAssetType } from '@metamask/utils';\nimport { createHash } from 'crypto';\n\n/**\n * Get a function that generates pseudo-random UUIDs. This function uses a\n * counter to generate a unique UUID each time it is called.\n *\n * This is likely not suitable for production use, as it does not guarantee\n * true randomness and is not cryptographically secure. It is intended for\n * testing and mock purposes only.\n *\n * @returns A function that generates a pseudo-random UUID.\n */\nexport function getPseudoRandomUuidGenerator() {\n let counter = 0;\n\n return () => {\n const bytes = createHash('sha256')\n .update(`${counter}`)\n .digest()\n .subarray(0, 16);\n\n /* eslint-disable no-bitwise */\n bytes[6] = (bytes[6] & 0x0f) | 0x40;\n bytes[8] = (bytes[8] & 0x3f) | 0x80;\n /* eslint-enable no-bitwise */\n\n counter += 1;\n\n return (\n bytes\n .toString('hex')\n .match(/.{1,8}/gu)\n ?.join('-') ?? ''\n );\n };\n}\n\n/**\n * Get unique scopes from a list of assets. This assumes the assets are in\n * CAIP format, where the chain ID is the first part of the asset type.\n *\n * @param assets - An array of CAIP asset types.\n * @returns An array of unique CAIP chain IDs derived from the assets.\n */\nexport function getScopesFromAssets(\n assets: CaipAssetType[] = [],\n): CaipChainId[] {\n const scopes = assets.map((asset) => {\n const { chainId } = parseCaipAssetType(asset);\n return chainId;\n });\n\n return Array.from(new Set(scopes));\n}\n"]}
@@ -17,4 +17,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./environment.cjs"), exports);
18
18
  __exportStar(require("./logger.cjs"), exports);
19
19
  __exportStar(require("./server.cjs"), exports);
20
+ __exportStar(require("./accounts.cjs"), exports);
20
21
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../src/internals/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAA8B;AAC9B,+CAAyB;AACzB,+CAAyB","sourcesContent":["export * from './environment';\nexport * from './logger';\nexport * from './server';\n"]}
1
+ {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../src/internals/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAA8B;AAC9B,+CAAyB;AACzB,+CAAyB;AACzB,iDAA2B","sourcesContent":["export * from './environment';\nexport * from './logger';\nexport * from './server';\nexport * from './accounts';\n"]}
@@ -1,4 +1,5 @@
1
1
  export * from "./environment.cjs";
2
2
  export * from "./logger.cjs";
3
3
  export * from "./server.cjs";
4
+ export * from "./accounts.cjs";
4
5
  //# sourceMappingURL=index.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../src/internals/index.ts"],"names":[],"mappings":"AAAA,kCAA8B;AAC9B,6BAAyB;AACzB,6BAAyB"}
1
+ {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../src/internals/index.ts"],"names":[],"mappings":"AAAA,kCAA8B;AAC9B,6BAAyB;AACzB,6BAAyB;AACzB,+BAA2B"}
@@ -1,4 +1,5 @@
1
1
  export * from "./environment.mjs";
2
2
  export * from "./logger.mjs";
3
3
  export * from "./server.mjs";
4
+ export * from "./accounts.mjs";
4
5
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/internals/index.ts"],"names":[],"mappings":"AAAA,kCAA8B;AAC9B,6BAAyB;AACzB,6BAAyB"}
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/internals/index.ts"],"names":[],"mappings":"AAAA,kCAA8B;AAC9B,6BAAyB;AACzB,6BAAyB;AACzB,+BAA2B"}
@@ -1,4 +1,5 @@
1
1
  export * from "./environment.mjs";
2
2
  export * from "./logger.mjs";
3
3
  export * from "./server.mjs";
4
+ export * from "./accounts.mjs";
4
5
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../src/internals/index.ts"],"names":[],"mappings":"AAAA,kCAA8B;AAC9B,6BAAyB;AACzB,6BAAyB","sourcesContent":["export * from './environment';\nexport * from './logger';\nexport * from './server';\n"]}
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../src/internals/index.ts"],"names":[],"mappings":"AAAA,kCAA8B;AAC9B,6BAAyB;AACzB,6BAAyB;AACzB,+BAA2B","sourcesContent":["export * from './environment';\nexport * from './logger';\nexport * from './server';\nexport * from './accounts';\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"options.cjs","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":";;;AACA,uDAQ+B;AAE/B,MAAM,6BAA6B,GAAG,IAAA,kBAAI,EAAC;IACzC,MAAM,EAAE,IAAA,uBAAS,EACf,IAAA,oBAAM,EAAC;QACL,OAAO,EAAE,IAAA,uBAAS,EAAC,IAAA,qBAAO,GAAE,EAAE,IAAI,CAAC;QACnC,IAAI,EAAE,IAAA,uBAAS,EAAC,IAAA,oBAAM,GAAE,EAAE,CAAC,CAAC;QAC5B,IAAI,EAAE,IAAA,uBAAS,EAAC,IAAA,oBAAM,GAAE,EAAE,OAAO,CAAC,GAAG,EAAE,CAAC;KACzC,CAAC,EACF,EAAE,CACH;CACF,CAAC,CAAC;AA+BH;;;;;;;GAOG;AACH,SAAgB,UAAU,CAAC,sBAA+C;IACxE,OAAO,IAAA,oBAAM,EAAC,sBAAsB,EAAE,6BAA6B,CAAC,CAAC;AACvE,CAAC;AAFD,gCAEC","sourcesContent":["import type { Infer } from '@metamask/superstruct';\nimport {\n boolean,\n create,\n defaulted,\n number,\n object,\n string,\n type,\n} from '@metamask/superstruct';\n\nconst SnapsEnvironmentOptionsStruct = type({\n server: defaulted(\n object({\n enabled: defaulted(boolean(), true),\n port: defaulted(number(), 0),\n root: defaulted(string(), process.cwd()),\n }),\n {},\n ),\n});\n\n/**\n * The options for the environment. These can be specified in the Jest\n * configuration under `testEnvironmentOptions`.\n *\n * @example\n * {\n * \"testEnvironment\": \"@metamask/snaps-jest\",\n * \"testEnvironmentOptions\": {\n * \"executionEnvironmentUrl\": \"http://localhost:8080\",\n * \"server\": {\n * \"port\": 8080,\n * /* ... *\\/\n * }\n * }\n * }\n * @property server - The options for the built-in HTTP server.\n * @property server.enabled - Whether to run the built-in HTTP server. Defaults\n * to `true`.\n * @property server.port - The port to use for the built-in HTTP server. If this\n * is not provided, a random available port will be used.\n * @property server.root - The root directory to serve from the built-in HTTP\n * server. Defaults to the current working directory. This is assumed to be the\n * directory containing the snap manifest and `dist` files. If this is a\n * relative path, it will be resolved relative to the current working directory.\n */\nexport type SnapsEnvironmentOptions = Infer<\n typeof SnapsEnvironmentOptionsStruct\n>;\n\n/**\n * Get the environment options. This validates the options, and returns the\n * default options if none are provided.\n *\n * @param testEnvironmentOptions - The test environment options as defined in\n * the Jest configuration.\n * @returns The environment options.\n */\nexport function getOptions(testEnvironmentOptions: Record<string, unknown>) {\n return create(testEnvironmentOptions, SnapsEnvironmentOptionsStruct);\n}\n"]}
1
+ {"version":3,"file":"options.cjs","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":";;;AACA,uDAQ+B;AAE/B,MAAM,6BAA6B,GAAG,IAAA,kBAAI,EAAC;IACzC,MAAM,EAAE,IAAA,uBAAS,EACf,IAAA,oBAAM,EAAC;QACL,OAAO,EAAE,IAAA,uBAAS,EAAC,IAAA,qBAAO,GAAE,EAAE,IAAI,CAAC;QACnC,IAAI,EAAE,IAAA,uBAAS,EAAC,IAAA,oBAAM,GAAE,EAAE,CAAC,CAAC;QAC5B,IAAI,EAAE,IAAA,uBAAS,EAAC,IAAA,oBAAM,GAAE,EAAE,OAAO,CAAC,GAAG,EAAE,CAAC;KACzC,CAAC,EACF,EAAE,CACH;CACF,CAAC,CAAC;AA+BH;;;;;;;GAOG;AACH,SAAgB,UAAU,CAAC,sBAA+C;IACxE,OAAO,IAAA,oBAAM,EAAC,sBAAsB,EAAE,6BAA6B,CAAC,CAAC;AACvE,CAAC;AAFD,gCAEC","sourcesContent":["import type { Infer } from '@metamask/superstruct';\nimport {\n boolean,\n create,\n defaulted,\n number,\n object,\n string,\n type,\n} from '@metamask/superstruct';\n\nconst SnapsEnvironmentOptionsStruct = type({\n server: defaulted(\n object({\n enabled: defaulted(boolean(), true),\n port: defaulted(number(), 0),\n root: defaulted(string(), process.cwd()),\n }),\n {},\n ),\n});\n\n/**\n * The options for the environment. These can be specified in the Jest\n * configuration under `testEnvironmentOptions`.\n *\n * @example\n * {\n * \"testEnvironment\": \"@metamask/snaps-jest\",\n * \"testEnvironmentOptions\": {\n * \"executionEnvironmentUrl\": \"http://localhost:8080\",\n * \"server\": {\n * \"port\": 8080,\n * /* ... *\\/\n * }\n * }\n * }\n * @property server - The options for the built-in HTTP server.\n * @property server.enabled - Whether to run the built-in HTTP server. Defaults\n * to `true`.\n * @property server.port - The port to use for the built-in HTTP server. If this\n * is not provided, a random available port will be used.\n * @property server.root - The root directory to serve from the built-in HTTP\n * server. Defaults to the current working directory. This is assumed to be the\n * directory containing the snap manifest and `dist` files. If this is a\n * relative path, it will be resolved relative to the current working directory.\n */\nexport type SnapsEnvironmentOptions = Infer<\n typeof SnapsEnvironmentOptionsStruct\n>;\n\n/**\n * Get the environment options. This validates the options, and returns the\n * default options if none are provided.\n *\n * @param testEnvironmentOptions - The test environment options as defined in\n * the Jest configuration.\n * @returns The environment options.\n */\nexport function getOptions(testEnvironmentOptions: Record<string, unknown>) {\n return create(testEnvironmentOptions, SnapsEnvironmentOptionsStruct);\n}\n\nexport type {\n SimulationAccount,\n SimulationAsset,\n} from '@metamask/snaps-simulation';\n"]}
@@ -57,5 +57,5 @@ export declare function getOptions(testEnvironmentOptions: Record<string, unknow
57
57
  root: string;
58
58
  };
59
59
  };
60
- export {};
60
+ export type { SimulationAccount, SimulationAsset, } from "@metamask/snaps-simulation";
61
61
  //# sourceMappingURL=options.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"options.d.cts","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,8BAA8B;AAWnD,QAAA,MAAM,6BAA6B;;;;;;;;;;;;;;;;EASjC,CAAC;AAEH;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,MAAM,uBAAuB,GAAG,KAAK,CACzC,OAAO,6BAA6B,CACrC,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,sBAAsB,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;;;;;;EAEzE"}
1
+ {"version":3,"file":"options.d.cts","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,8BAA8B;AAWnD,QAAA,MAAM,6BAA6B;;;;;;;;;;;;;;;;EASjC,CAAC;AAEH;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,MAAM,uBAAuB,GAAG,KAAK,CACzC,OAAO,6BAA6B,CACrC,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,sBAAsB,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;;;;;;EAEzE;AAED,YAAY,EACV,iBAAiB,EACjB,eAAe,GAChB,mCAAmC"}
@@ -57,5 +57,5 @@ export declare function getOptions(testEnvironmentOptions: Record<string, unknow
57
57
  root: string;
58
58
  };
59
59
  };
60
- export {};
60
+ export type { SimulationAccount, SimulationAsset, } from "@metamask/snaps-simulation";
61
61
  //# sourceMappingURL=options.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"options.d.mts","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,8BAA8B;AAWnD,QAAA,MAAM,6BAA6B;;;;;;;;;;;;;;;;EASjC,CAAC;AAEH;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,MAAM,uBAAuB,GAAG,KAAK,CACzC,OAAO,6BAA6B,CACrC,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,sBAAsB,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;;;;;;EAEzE"}
1
+ {"version":3,"file":"options.d.mts","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,8BAA8B;AAWnD,QAAA,MAAM,6BAA6B;;;;;;;;;;;;;;;;EASjC,CAAC;AAEH;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,MAAM,uBAAuB,GAAG,KAAK,CACzC,OAAO,6BAA6B,CACrC,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,sBAAsB,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;;;;;;EAEzE;AAED,YAAY,EACV,iBAAiB,EACjB,eAAe,GAChB,mCAAmC"}
@@ -1 +1 @@
1
- {"version":3,"file":"options.mjs","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AACA,OAAO,EACL,OAAO,EACP,MAAM,EACN,SAAS,EACT,MAAM,EACN,MAAM,EACN,MAAM,EACN,IAAI,EACL,8BAA8B;AAE/B,MAAM,6BAA6B,GAAG,IAAI,CAAC;IACzC,MAAM,EAAE,SAAS,CACf,MAAM,CAAC;QACL,OAAO,EAAE,SAAS,CAAC,OAAO,EAAE,EAAE,IAAI,CAAC;QACnC,IAAI,EAAE,SAAS,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QAC5B,IAAI,EAAE,SAAS,CAAC,MAAM,EAAE,EAAE,OAAO,CAAC,GAAG,EAAE,CAAC;KACzC,CAAC,EACF,EAAE,CACH;CACF,CAAC,CAAC;AA+BH;;;;;;;GAOG;AACH,MAAM,UAAU,UAAU,CAAC,sBAA+C;IACxE,OAAO,MAAM,CAAC,sBAAsB,EAAE,6BAA6B,CAAC,CAAC;AACvE,CAAC","sourcesContent":["import type { Infer } from '@metamask/superstruct';\nimport {\n boolean,\n create,\n defaulted,\n number,\n object,\n string,\n type,\n} from '@metamask/superstruct';\n\nconst SnapsEnvironmentOptionsStruct = type({\n server: defaulted(\n object({\n enabled: defaulted(boolean(), true),\n port: defaulted(number(), 0),\n root: defaulted(string(), process.cwd()),\n }),\n {},\n ),\n});\n\n/**\n * The options for the environment. These can be specified in the Jest\n * configuration under `testEnvironmentOptions`.\n *\n * @example\n * {\n * \"testEnvironment\": \"@metamask/snaps-jest\",\n * \"testEnvironmentOptions\": {\n * \"executionEnvironmentUrl\": \"http://localhost:8080\",\n * \"server\": {\n * \"port\": 8080,\n * /* ... *\\/\n * }\n * }\n * }\n * @property server - The options for the built-in HTTP server.\n * @property server.enabled - Whether to run the built-in HTTP server. Defaults\n * to `true`.\n * @property server.port - The port to use for the built-in HTTP server. If this\n * is not provided, a random available port will be used.\n * @property server.root - The root directory to serve from the built-in HTTP\n * server. Defaults to the current working directory. This is assumed to be the\n * directory containing the snap manifest and `dist` files. If this is a\n * relative path, it will be resolved relative to the current working directory.\n */\nexport type SnapsEnvironmentOptions = Infer<\n typeof SnapsEnvironmentOptionsStruct\n>;\n\n/**\n * Get the environment options. This validates the options, and returns the\n * default options if none are provided.\n *\n * @param testEnvironmentOptions - The test environment options as defined in\n * the Jest configuration.\n * @returns The environment options.\n */\nexport function getOptions(testEnvironmentOptions: Record<string, unknown>) {\n return create(testEnvironmentOptions, SnapsEnvironmentOptionsStruct);\n}\n"]}
1
+ {"version":3,"file":"options.mjs","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AACA,OAAO,EACL,OAAO,EACP,MAAM,EACN,SAAS,EACT,MAAM,EACN,MAAM,EACN,MAAM,EACN,IAAI,EACL,8BAA8B;AAE/B,MAAM,6BAA6B,GAAG,IAAI,CAAC;IACzC,MAAM,EAAE,SAAS,CACf,MAAM,CAAC;QACL,OAAO,EAAE,SAAS,CAAC,OAAO,EAAE,EAAE,IAAI,CAAC;QACnC,IAAI,EAAE,SAAS,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QAC5B,IAAI,EAAE,SAAS,CAAC,MAAM,EAAE,EAAE,OAAO,CAAC,GAAG,EAAE,CAAC;KACzC,CAAC,EACF,EAAE,CACH;CACF,CAAC,CAAC;AA+BH;;;;;;;GAOG;AACH,MAAM,UAAU,UAAU,CAAC,sBAA+C;IACxE,OAAO,MAAM,CAAC,sBAAsB,EAAE,6BAA6B,CAAC,CAAC;AACvE,CAAC","sourcesContent":["import type { Infer } from '@metamask/superstruct';\nimport {\n boolean,\n create,\n defaulted,\n number,\n object,\n string,\n type,\n} from '@metamask/superstruct';\n\nconst SnapsEnvironmentOptionsStruct = type({\n server: defaulted(\n object({\n enabled: defaulted(boolean(), true),\n port: defaulted(number(), 0),\n root: defaulted(string(), process.cwd()),\n }),\n {},\n ),\n});\n\n/**\n * The options for the environment. These can be specified in the Jest\n * configuration under `testEnvironmentOptions`.\n *\n * @example\n * {\n * \"testEnvironment\": \"@metamask/snaps-jest\",\n * \"testEnvironmentOptions\": {\n * \"executionEnvironmentUrl\": \"http://localhost:8080\",\n * \"server\": {\n * \"port\": 8080,\n * /* ... *\\/\n * }\n * }\n * }\n * @property server - The options for the built-in HTTP server.\n * @property server.enabled - Whether to run the built-in HTTP server. Defaults\n * to `true`.\n * @property server.port - The port to use for the built-in HTTP server. If this\n * is not provided, a random available port will be used.\n * @property server.root - The root directory to serve from the built-in HTTP\n * server. Defaults to the current working directory. This is assumed to be the\n * directory containing the snap manifest and `dist` files. If this is a\n * relative path, it will be resolved relative to the current working directory.\n */\nexport type SnapsEnvironmentOptions = Infer<\n typeof SnapsEnvironmentOptionsStruct\n>;\n\n/**\n * Get the environment options. This validates the options, and returns the\n * default options if none are provided.\n *\n * @param testEnvironmentOptions - The test environment options as defined in\n * the Jest configuration.\n * @returns The environment options.\n */\nexport function getOptions(testEnvironmentOptions: Record<string, unknown>) {\n return create(testEnvironmentOptions, SnapsEnvironmentOptionsStruct);\n}\n\nexport type {\n SimulationAccount,\n SimulationAsset,\n} from '@metamask/snaps-simulation';\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask/snaps-jest",
3
- "version": "9.0.0",
3
+ "version": "9.2.0",
4
4
  "description": "A Jest preset for end-to-end testing MetaMask Snaps, including a Jest environment, and a set of Jest matchers",
5
5
  "keywords": [
6
6
  "MetaMask",
@@ -60,9 +60,9 @@
60
60
  "@jest/environment": "^29.5.0",
61
61
  "@jest/expect": "^29.5.0",
62
62
  "@jest/globals": "^29.5.0",
63
- "@metamask/snaps-controllers": "^13.0.0",
64
- "@metamask/snaps-sdk": "^8.0.0",
65
- "@metamask/snaps-simulation": "^3.0.0",
63
+ "@metamask/snaps-controllers": "^14.0.0",
64
+ "@metamask/snaps-sdk": "^9.0.0",
65
+ "@metamask/snaps-simulation": "^3.2.0",
66
66
  "@metamask/superstruct": "^3.2.1",
67
67
  "@metamask/utils": "^11.4.0",
68
68
  "express": "^5.1.0",
@@ -72,9 +72,9 @@
72
72
  },
73
73
  "devDependencies": {
74
74
  "@jest/types": "^29.6.3",
75
- "@lavamoat/allow-scripts": "^3.3.3",
75
+ "@lavamoat/allow-scripts": "^3.3.4",
76
76
  "@metamask/auto-changelog": "^5.0.2",
77
- "@metamask/snaps-utils": "^10.0.0",
77
+ "@metamask/snaps-utils": "^11.0.0",
78
78
  "@swc/core": "1.11.31",
79
79
  "@swc/jest": "^0.2.38",
80
80
  "@ts-bridge/cli": "^0.6.1",