@metamask/snaps-jest 3.0.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -6,6 +6,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [4.0.0]
10
+ ### Changed
11
+ - Use `@metamask/snaps-sdk` package ([#1930](https://github.com/MetaMask/snaps/pull/1930),
12
+ [#1950](https://github.com/MetaMask/snaps/pull/1950), [#1954](https://github.com/MetaMask/snaps/pull/1954))
13
+ - This package replaces the `@metamask/snaps-types` and
14
+ - `@metamask/snaps-ui` packages.
15
+
16
+ ### Removed
17
+ - **BREAKING**: `DialogType`, `ManageStateOperation`, `NotificationType` are no
18
+ longer re-exported from `@metamask/snaps-jest` ([#1930](https://github.com/MetaMask/snaps/pull/1930))
19
+ - These enums can now be imported from `@metamask/snaps-sdk` instead.
20
+
21
+ ## [3.1.0]
22
+ ### Added
23
+ - Add support for links in custom UI and notifications ([#1814](https://github.com/MetaMask/snaps/pull/1814))
24
+
9
25
  ## [3.0.0]
10
26
  ### Changed
11
27
  - **BREAKING:** Improve error handling ([#1841](https://github.com/MetaMask/snaps/pull/1841))
@@ -61,7 +77,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
61
77
  - The version of the package no longer needs to match the version of all other
62
78
  MetaMask Snaps packages.
63
79
 
64
- [Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-jest@3.0.0...HEAD
80
+ [Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-jest@4.0.0...HEAD
81
+ [4.0.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-jest@3.1.0...@metamask/snaps-jest@4.0.0
82
+ [3.1.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-jest@3.0.0...@metamask/snaps-jest@3.1.0
65
83
  [3.0.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-jest@2.0.0...@metamask/snaps-jest@3.0.0
66
84
  [2.0.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-jest@1.0.0...@metamask/snaps-jest@2.0.0
67
85
  [1.0.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-jest@0.37.5-flask.1...@metamask/snaps-jest@1.0.0
package/README.md CHANGED
@@ -200,7 +200,7 @@ function.
200
200
 
201
201
  ```js
202
202
  import { installSnap } from '@metamask/snaps-jest';
203
- import { panel, text } from '@metamask/snaps-ui';
203
+ import { panel, text } from '@metamask/snaps-sdk';
204
204
 
205
205
  describe('MySnap', () => {
206
206
  it('should do something', async () => {
@@ -316,7 +316,7 @@ functions that can be used to interact with the user interface.
316
316
 
317
317
  ```js
318
318
  import { installSnap } from '@metamask/snaps-jest';
319
- import { text } from '@metamask/snaps-ui';
319
+ import { text } from '@metamask/snaps-sdk';
320
320
  import { assert } from '@metamask/utils';
321
321
 
322
322
  describe('MySnap', () => {
@@ -16,7 +16,7 @@ _export(exports, {
16
16
  return getNotifications;
17
17
  }
18
18
  });
19
- const _snapsrpcmethods = require("@metamask/snaps-rpc-methods");
19
+ const _snapssdk = require("@metamask/snaps-sdk");
20
20
  const _utils = require("@metamask/utils");
21
21
  const _superstruct = require("superstruct");
22
22
  const _structs = require("./structs");
@@ -35,7 +35,7 @@ async function getInterface(page, options = {}) {
35
35
  message: 'Timed out waiting for snap interface to be shown.'
36
36
  });
37
37
  switch(type){
38
- case _snapsrpcmethods.DialogType.Alert:
38
+ case _snapssdk.DialogType.Alert:
39
39
  return {
40
40
  type: 'alert',
41
41
  content,
@@ -48,7 +48,7 @@ async function getInterface(page, options = {}) {
48
48
  });
49
49
  }
50
50
  };
51
- case _snapsrpcmethods.DialogType.Confirmation:
51
+ case _snapssdk.DialogType.Confirmation:
52
52
  return {
53
53
  type: 'confirmation',
54
54
  content,
@@ -69,7 +69,7 @@ async function getInterface(page, options = {}) {
69
69
  });
70
70
  }
71
71
  };
72
- case _snapsrpcmethods.DialogType.Prompt:
72
+ case _snapssdk.DialogType.Prompt:
73
73
  return {
74
74
  type: 'prompt',
75
75
  content,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/internals/interface.ts"],"sourcesContent":["import { DialogType } from '@metamask/snaps-rpc-methods';\nimport { assert } from '@metamask/utils';\nimport type { Page } from 'puppeteer';\nimport { create } from 'superstruct';\n\nimport type { SnapInterface, SnapOptions } from '../types';\nimport { SnapOptionsStruct } from './structs';\nimport { waitFor } from './wait-for';\n\n/**\n * Get the current snap user interface (i.e., dialog). This will throw an error\n * if the snap does not show a user interface within the timeout.\n *\n * @param page - The page to get the interface from.\n * @param options - The options to use.\n * @param options.timeout - The timeout in milliseconds to use. Defaults to\n * `1000`.\n * @returns The user interface object.\n */\nexport async function getInterface(\n page: Page,\n options: SnapOptions = {},\n): Promise<SnapInterface> {\n const { timeout } = create(options, SnapOptionsStruct);\n\n const { type, node: content } = await waitFor(\n async () => {\n const ui = await page.evaluate(() => {\n const state = window.__SIMULATOR_API__.getState();\n return state.simulation.ui;\n });\n\n assert(ui);\n return ui;\n },\n {\n timeout,\n message: 'Timed out waiting for snap interface to be shown.',\n },\n );\n\n switch (type) {\n case DialogType.Alert:\n return {\n type: 'alert',\n content,\n\n ok: async () => {\n await page.evaluate(() => {\n window.__SIMULATOR_API__.dispatch({\n type: 'simulation/resolveUserInterface',\n payload: null,\n });\n });\n },\n };\n\n case DialogType.Confirmation:\n return {\n type: 'confirmation',\n content,\n\n ok: async () => {\n await page.evaluate(() => {\n window.__SIMULATOR_API__.dispatch({\n type: 'simulation/resolveUserInterface',\n payload: true,\n });\n });\n },\n\n cancel: async () => {\n await page.evaluate(() => {\n window.__SIMULATOR_API__.dispatch({\n type: 'simulation/resolveUserInterface',\n payload: false,\n });\n });\n },\n };\n\n case DialogType.Prompt:\n return {\n type: 'prompt',\n content,\n\n ok: async (value) => {\n await page.evaluate((payload) => {\n window.__SIMULATOR_API__.dispatch({\n type: 'simulation/resolveUserInterface',\n payload,\n });\n }, value);\n },\n\n cancel: async () => {\n await page.evaluate(() => {\n window.__SIMULATOR_API__.dispatch({\n type: 'simulation/resolveUserInterface',\n payload: null,\n });\n });\n },\n };\n\n default:\n throw new Error(`Unknown or unsupported dialog type: ${String(type)}.`);\n }\n}\n\n/**\n * Get the text of the notifications.\n *\n * @param page - The page to get the notifications from.\n * @param requestId - The ID of the request to get the notifications for.\n * @returns The text of the notifications, in order of appearance.\n */\nexport async function getNotifications(page: Page, requestId: string) {\n return await page.evaluate((id) => {\n return window.__SIMULATOR_API__.getNotifications(id);\n }, requestId);\n}\n"],"names":["getInterface","getNotifications","page","options","timeout","create","SnapOptionsStruct","type","node","content","waitFor","ui","evaluate","state","window","__SIMULATOR_API__","getState","simulation","assert","message","DialogType","Alert","ok","dispatch","payload","Confirmation","cancel","Prompt","value","Error","String","requestId","id"],"mappings":";;;;;;;;;;;IAmBsBA,YAAY;eAAZA;;IAkGAC,gBAAgB;eAAhBA;;;iCArHK;uBACJ;6BAEA;yBAGW;yBACV;AAYjB,eAAeD,aACpBE,IAAU,EACVC,UAAuB,CAAC,CAAC;IAEzB,MAAM,EAAEC,OAAO,EAAE,GAAGC,IAAAA,mBAAM,EAACF,SAASG,0BAAiB;IAErD,MAAM,EAAEC,IAAI,EAAEC,MAAMC,OAAO,EAAE,GAAG,MAAMC,IAAAA,gBAAO,EAC3C;QACE,MAAMC,KAAK,MAAMT,KAAKU,QAAQ,CAAC;YAC7B,MAAMC,QAAQC,OAAOC,iBAAiB,CAACC,QAAQ;YAC/C,OAAOH,MAAMI,UAAU,CAACN,EAAE;QAC5B;QAEAO,IAAAA,aAAM,EAACP;QACP,OAAOA;IACT,GACA;QACEP;QACAe,SAAS;IACX;IAGF,OAAQZ;QACN,KAAKa,2BAAU,CAACC,KAAK;YACnB,OAAO;gBACLd,MAAM;gBACNE;gBAEAa,IAAI;oBACF,MAAMpB,KAAKU,QAAQ,CAAC;wBAClBE,OAAOC,iBAAiB,CAACQ,QAAQ,CAAC;4BAChChB,MAAM;4BACNiB,SAAS;wBACX;oBACF;gBACF;YACF;QAEF,KAAKJ,2BAAU,CAACK,YAAY;YAC1B,OAAO;gBACLlB,MAAM;gBACNE;gBAEAa,IAAI;oBACF,MAAMpB,KAAKU,QAAQ,CAAC;wBAClBE,OAAOC,iBAAiB,CAACQ,QAAQ,CAAC;4BAChChB,MAAM;4BACNiB,SAAS;wBACX;oBACF;gBACF;gBAEAE,QAAQ;oBACN,MAAMxB,KAAKU,QAAQ,CAAC;wBAClBE,OAAOC,iBAAiB,CAACQ,QAAQ,CAAC;4BAChChB,MAAM;4BACNiB,SAAS;wBACX;oBACF;gBACF;YACF;QAEF,KAAKJ,2BAAU,CAACO,MAAM;YACpB,OAAO;gBACLpB,MAAM;gBACNE;gBAEAa,IAAI,OAAOM;oBACT,MAAM1B,KAAKU,QAAQ,CAAC,CAACY;wBACnBV,OAAOC,iBAAiB,CAACQ,QAAQ,CAAC;4BAChChB,MAAM;4BACNiB;wBACF;oBACF,GAAGI;gBACL;gBAEAF,QAAQ;oBACN,MAAMxB,KAAKU,QAAQ,CAAC;wBAClBE,OAAOC,iBAAiB,CAACQ,QAAQ,CAAC;4BAChChB,MAAM;4BACNiB,SAAS;wBACX;oBACF;gBACF;YACF;QAEF;YACE,MAAM,IAAIK,MAAM,CAAC,oCAAoC,EAAEC,OAAOvB,MAAM,CAAC,CAAC;IAC1E;AACF;AASO,eAAeN,iBAAiBC,IAAU,EAAE6B,SAAiB;IAClE,OAAO,MAAM7B,KAAKU,QAAQ,CAAC,CAACoB;QAC1B,OAAOlB,OAAOC,iBAAiB,CAACd,gBAAgB,CAAC+B;IACnD,GAAGD;AACL"}
1
+ {"version":3,"sources":["../../../src/internals/interface.ts"],"sourcesContent":["import { DialogType } from '@metamask/snaps-sdk';\nimport { assert } from '@metamask/utils';\nimport type { Page } from 'puppeteer';\nimport { create } from 'superstruct';\n\nimport type { SnapInterface, SnapOptions } from '../types';\nimport { SnapOptionsStruct } from './structs';\nimport { waitFor } from './wait-for';\n\n/**\n * Get the current snap user interface (i.e., dialog). This will throw an error\n * if the snap does not show a user interface within the timeout.\n *\n * @param page - The page to get the interface from.\n * @param options - The options to use.\n * @param options.timeout - The timeout in milliseconds to use. Defaults to\n * `1000`.\n * @returns The user interface object.\n */\nexport async function getInterface(\n page: Page,\n options: SnapOptions = {},\n): Promise<SnapInterface> {\n const { timeout } = create(options, SnapOptionsStruct);\n\n const { type, node: content } = await waitFor(\n async () => {\n const ui = await page.evaluate(() => {\n const state = window.__SIMULATOR_API__.getState();\n return state.simulation.ui;\n });\n\n assert(ui);\n return ui;\n },\n {\n timeout,\n message: 'Timed out waiting for snap interface to be shown.',\n },\n );\n\n switch (type) {\n case DialogType.Alert:\n return {\n type: 'alert',\n content,\n\n ok: async () => {\n await page.evaluate(() => {\n window.__SIMULATOR_API__.dispatch({\n type: 'simulation/resolveUserInterface',\n payload: null,\n });\n });\n },\n };\n\n case DialogType.Confirmation:\n return {\n type: 'confirmation',\n content,\n\n ok: async () => {\n await page.evaluate(() => {\n window.__SIMULATOR_API__.dispatch({\n type: 'simulation/resolveUserInterface',\n payload: true,\n });\n });\n },\n\n cancel: async () => {\n await page.evaluate(() => {\n window.__SIMULATOR_API__.dispatch({\n type: 'simulation/resolveUserInterface',\n payload: false,\n });\n });\n },\n };\n\n case DialogType.Prompt:\n return {\n type: 'prompt',\n content,\n\n ok: async (value) => {\n await page.evaluate((payload) => {\n window.__SIMULATOR_API__.dispatch({\n type: 'simulation/resolveUserInterface',\n payload,\n });\n }, value);\n },\n\n cancel: async () => {\n await page.evaluate(() => {\n window.__SIMULATOR_API__.dispatch({\n type: 'simulation/resolveUserInterface',\n payload: null,\n });\n });\n },\n };\n\n default:\n throw new Error(`Unknown or unsupported dialog type: ${String(type)}.`);\n }\n}\n\n/**\n * Get the text of the notifications.\n *\n * @param page - The page to get the notifications from.\n * @param requestId - The ID of the request to get the notifications for.\n * @returns The text of the notifications, in order of appearance.\n */\nexport async function getNotifications(page: Page, requestId: string) {\n return await page.evaluate((id) => {\n return window.__SIMULATOR_API__.getNotifications(id);\n }, requestId);\n}\n"],"names":["getInterface","getNotifications","page","options","timeout","create","SnapOptionsStruct","type","node","content","waitFor","ui","evaluate","state","window","__SIMULATOR_API__","getState","simulation","assert","message","DialogType","Alert","ok","dispatch","payload","Confirmation","cancel","Prompt","value","Error","String","requestId","id"],"mappings":";;;;;;;;;;;IAmBsBA,YAAY;eAAZA;;IAkGAC,gBAAgB;eAAhBA;;;0BArHK;uBACJ;6BAEA;yBAGW;yBACV;AAYjB,eAAeD,aACpBE,IAAU,EACVC,UAAuB,CAAC,CAAC;IAEzB,MAAM,EAAEC,OAAO,EAAE,GAAGC,IAAAA,mBAAM,EAACF,SAASG,0BAAiB;IAErD,MAAM,EAAEC,IAAI,EAAEC,MAAMC,OAAO,EAAE,GAAG,MAAMC,IAAAA,gBAAO,EAC3C;QACE,MAAMC,KAAK,MAAMT,KAAKU,QAAQ,CAAC;YAC7B,MAAMC,QAAQC,OAAOC,iBAAiB,CAACC,QAAQ;YAC/C,OAAOH,MAAMI,UAAU,CAACN,EAAE;QAC5B;QAEAO,IAAAA,aAAM,EAACP;QACP,OAAOA;IACT,GACA;QACEP;QACAe,SAAS;IACX;IAGF,OAAQZ;QACN,KAAKa,oBAAU,CAACC,KAAK;YACnB,OAAO;gBACLd,MAAM;gBACNE;gBAEAa,IAAI;oBACF,MAAMpB,KAAKU,QAAQ,CAAC;wBAClBE,OAAOC,iBAAiB,CAACQ,QAAQ,CAAC;4BAChChB,MAAM;4BACNiB,SAAS;wBACX;oBACF;gBACF;YACF;QAEF,KAAKJ,oBAAU,CAACK,YAAY;YAC1B,OAAO;gBACLlB,MAAM;gBACNE;gBAEAa,IAAI;oBACF,MAAMpB,KAAKU,QAAQ,CAAC;wBAClBE,OAAOC,iBAAiB,CAACQ,QAAQ,CAAC;4BAChChB,MAAM;4BACNiB,SAAS;wBACX;oBACF;gBACF;gBAEAE,QAAQ;oBACN,MAAMxB,KAAKU,QAAQ,CAAC;wBAClBE,OAAOC,iBAAiB,CAACQ,QAAQ,CAAC;4BAChChB,MAAM;4BACNiB,SAAS;wBACX;oBACF;gBACF;YACF;QAEF,KAAKJ,oBAAU,CAACO,MAAM;YACpB,OAAO;gBACLpB,MAAM;gBACNE;gBAEAa,IAAI,OAAOM;oBACT,MAAM1B,KAAKU,QAAQ,CAAC,CAACY;wBACnBV,OAAOC,iBAAiB,CAACQ,QAAQ,CAAC;4BAChChB,MAAM;4BACNiB;wBACF;oBACF,GAAGI;gBACL;gBAEAF,QAAQ;oBACN,MAAMxB,KAAKU,QAAQ,CAAC;wBAClBE,OAAOC,iBAAiB,CAACQ,QAAQ,CAAC;4BAChChB,MAAM;4BACNiB,SAAS;wBACX;oBACF;gBACF;YACF;QAEF;YACE,MAAM,IAAIK,MAAM,CAAC,oCAAoC,EAAEC,OAAOvB,MAAM,CAAC,CAAC;IAC1E;AACF;AASO,eAAeN,iBAAiBC,IAAU,EAAE6B,SAAiB;IAClE,OAAO,MAAM7B,KAAKU,QAAQ,CAAC,CAACoB;QAC1B,OAAOlB,OAAOC,iBAAiB,CAACd,gBAAgB,CAAC+B;IACnD,GAAGD;AACL"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/internals/request.ts"],"sourcesContent":["import type { Component } from '@metamask/snaps-ui';\nimport type { SnapRpcHookArgs } from '@metamask/snaps-utils';\nimport { HandlerType } from '@metamask/snaps-utils';\nimport {\n assert,\n createModuleLogger,\n hasProperty,\n isPlainObject,\n} from '@metamask/utils';\nimport { getDocument, queries } from 'pptr-testing-library';\nimport type { Page } from 'puppeteer';\nimport { create } from 'superstruct';\n\nimport type {\n CronjobOptions,\n RequestOptions,\n SnapRequest,\n SnapResponse,\n TransactionOptions,\n} from '../types';\nimport { getInterface, getNotifications } from './interface';\nimport { rootLogger } from './logger';\nimport { TransactionOptionsStruct } from './structs';\nimport { waitForResponse } from './wait-for';\n\nconst log = createModuleLogger(rootLogger, 'request');\n\n/**\n * Send a request to the snap.\n *\n * @param page - The page to send the request from.\n * @param args - The request arguments.\n * @returns The request ID.\n */\nasync function sendRequest(page: Page, args: SnapRpcHookArgs) {\n const document = await getDocument(page);\n const button = await queries.getByTestId(\n document,\n `navigation-${args.handler}`,\n );\n\n // Navigate to the request handler page.\n await button.click();\n\n return await page.evaluate((payload) => {\n window.__SIMULATOR_API__.dispatch({\n type: 'simulation/sendRequest',\n payload,\n });\n\n return window.__SIMULATOR_API__.getRequestId();\n }, args);\n}\n\n/**\n * Send a request to the snap.\n *\n * @param page - The page to send the request from.\n * @param options - The request options.\n * @param options.origin - The origin of the request. Defaults to `metamask.io`.\n * @param handler - The handler to use. Defaults to `onRpcRequest`.\n * @returns The response.\n */\nexport function request(\n page: Page,\n { origin = 'metamask.io', ...options }: RequestOptions,\n handler:\n | HandlerType.OnRpcRequest\n | HandlerType.OnCronjob = HandlerType.OnRpcRequest,\n) {\n const doRequest = async (): Promise<SnapResponse> => {\n const args: SnapRpcHookArgs = {\n origin,\n handler,\n request: {\n jsonrpc: '2.0',\n id: 1,\n ...options,\n },\n };\n\n log('Sending request %o', args);\n\n const promise = waitForResponse(page, handler);\n const id = await sendRequest(page, args);\n const response = await promise;\n\n log('Received response %o', response);\n\n const notifications = await getNotifications(page, id);\n\n return { id, response, notifications };\n };\n\n // This is a bit hacky, but it allows us to add the `getInterface` method\n // to the response promise.\n const response = doRequest() as SnapRequest;\n\n response.getInterface = async (getInterfaceOptions) => {\n return await getInterface(page, getInterfaceOptions);\n };\n\n return response;\n}\n\n/**\n * Send a transaction to the snap.\n *\n * @param page - The page to send the transaction from.\n * @param options - The transaction options.\n * @returns The response.\n */\nexport async function sendTransaction(\n page: Page,\n options: Partial<TransactionOptions>,\n) {\n const {\n origin: transactionOrigin,\n chainId,\n ...transaction\n } = create(options, TransactionOptionsStruct);\n\n const args: SnapRpcHookArgs = {\n origin: '',\n handler: HandlerType.OnTransaction,\n request: {\n jsonrpc: '2.0',\n method: '',\n params: {\n chainId,\n transaction,\n transactionOrigin,\n },\n },\n };\n\n log('Sending transaction %o', args);\n\n const promise = waitForResponse(page, HandlerType.OnTransaction);\n const id = await sendRequest(page, args);\n const response = await promise;\n\n log('Received response %o', response);\n\n if (hasProperty(response, 'error')) {\n return { id, response, notifications: [] };\n }\n\n assert(isPlainObject(response.result));\n assert(hasProperty(response.result, 'content'));\n\n return {\n id,\n response,\n notifications: [],\n content: response.result.content as Component,\n };\n}\n\n/**\n * Run a cronjob.\n *\n * @param page - The page to run the cronjob from.\n * @param options - The request options.\n * @returns The response.\n */\nexport function runCronjob(page: Page, options: CronjobOptions) {\n return request(page, options, HandlerType.OnCronjob);\n}\n"],"names":["request","sendTransaction","runCronjob","log","createModuleLogger","rootLogger","sendRequest","page","args","document","getDocument","button","queries","getByTestId","handler","click","evaluate","payload","window","__SIMULATOR_API__","dispatch","type","getRequestId","origin","options","HandlerType","OnRpcRequest","doRequest","jsonrpc","id","promise","waitForResponse","response","notifications","getNotifications","getInterface","getInterfaceOptions","transactionOrigin","chainId","transaction","create","TransactionOptionsStruct","OnTransaction","method","params","hasProperty","assert","isPlainObject","result","content","OnCronjob"],"mappings":";;;;;;;;;;;IA+DgBA,OAAO;eAAPA;;IAiDMC,eAAe;eAAfA;;IAsDNC,UAAU;eAAVA;;;4BApKY;uBAMrB;oCAC8B;6BAEd;2BASwB;wBACpB;yBACc;yBACT;AAEhC,MAAMC,MAAMC,IAAAA,yBAAkB,EAACC,kBAAU,EAAE;AAE3C;;;;;;CAMC,GACD,eAAeC,YAAYC,IAAU,EAAEC,IAAqB;IAC1D,MAAMC,WAAW,MAAMC,IAAAA,+BAAW,EAACH;IACnC,MAAMI,SAAS,MAAMC,2BAAO,CAACC,WAAW,CACtCJ,UACA,CAAC,WAAW,EAAED,KAAKM,OAAO,CAAC,CAAC;IAG9B,wCAAwC;IACxC,MAAMH,OAAOI,KAAK;IAElB,OAAO,MAAMR,KAAKS,QAAQ,CAAC,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,KAAK,MAAMvB,YAAYC,MAAMC;IACnC,MAAMwB,WAAW,MAAMF;IAEvB3B,IAAI,wBAAwB6B;IAE5B,IAAIa,IAAAA,kBAAW,EAACb,UAAU,UAAU;QAClC,OAAO;YAAEH;YAAIG;YAAUC,eAAe,EAAE;QAAC;IAC3C;IAEAa,IAAAA,aAAM,EAACC,IAAAA,oBAAa,EAACf,SAASgB,MAAM;IACpCF,IAAAA,aAAM,EAACD,IAAAA,kBAAW,EAACb,SAASgB,MAAM,EAAE;IAEpC,OAAO;QACLnB;QACAG;QACAC,eAAe,EAAE;QACjBgB,SAASjB,SAASgB,MAAM,CAACC,OAAO;IAClC;AACF;AASO,SAAS/C,WAAWK,IAAU,EAAEiB,OAAuB;IAC5D,OAAOxB,QAAQO,MAAMiB,SAASC,uBAAW,CAACyB,SAAS;AACrD"}
1
+ {"version":3,"sources":["../../../src/internals/request.ts"],"sourcesContent":["import type { Component } from '@metamask/snaps-sdk';\nimport type { SnapRpcHookArgs } from '@metamask/snaps-utils';\nimport { HandlerType } from '@metamask/snaps-utils';\nimport {\n assert,\n createModuleLogger,\n hasProperty,\n isPlainObject,\n} from '@metamask/utils';\nimport { getDocument, queries } from 'pptr-testing-library';\nimport type { Page } from 'puppeteer';\nimport { create } from 'superstruct';\n\nimport type {\n CronjobOptions,\n RequestOptions,\n SnapRequest,\n SnapResponse,\n TransactionOptions,\n} from '../types';\nimport { getInterface, getNotifications } from './interface';\nimport { rootLogger } from './logger';\nimport { TransactionOptionsStruct } from './structs';\nimport { waitForResponse } from './wait-for';\n\nconst log = createModuleLogger(rootLogger, 'request');\n\n/**\n * Send a request to the snap.\n *\n * @param page - The page to send the request from.\n * @param args - The request arguments.\n * @returns The request ID.\n */\nasync function sendRequest(page: Page, args: SnapRpcHookArgs) {\n const document = await getDocument(page);\n const button = await queries.getByTestId(\n document,\n `navigation-${args.handler}`,\n );\n\n // Navigate to the request handler page.\n await button.click();\n\n return await page.evaluate((payload) => {\n window.__SIMULATOR_API__.dispatch({\n type: 'simulation/sendRequest',\n payload,\n });\n\n return window.__SIMULATOR_API__.getRequestId();\n }, args);\n}\n\n/**\n * Send a request to the snap.\n *\n * @param page - The page to send the request from.\n * @param options - The request options.\n * @param options.origin - The origin of the request. Defaults to `metamask.io`.\n * @param handler - The handler to use. Defaults to `onRpcRequest`.\n * @returns The response.\n */\nexport function request(\n page: Page,\n { origin = 'metamask.io', ...options }: RequestOptions,\n handler:\n | HandlerType.OnRpcRequest\n | HandlerType.OnCronjob = HandlerType.OnRpcRequest,\n) {\n const doRequest = async (): Promise<SnapResponse> => {\n const args: SnapRpcHookArgs = {\n origin,\n handler,\n request: {\n jsonrpc: '2.0',\n id: 1,\n ...options,\n },\n };\n\n log('Sending request %o', args);\n\n const promise = waitForResponse(page, handler);\n const id = await sendRequest(page, args);\n const response = await promise;\n\n log('Received response %o', response);\n\n const notifications = await getNotifications(page, id);\n\n return { id, response, notifications };\n };\n\n // This is a bit hacky, but it allows us to add the `getInterface` method\n // to the response promise.\n const response = doRequest() as SnapRequest;\n\n response.getInterface = async (getInterfaceOptions) => {\n return await getInterface(page, getInterfaceOptions);\n };\n\n return response;\n}\n\n/**\n * Send a transaction to the snap.\n *\n * @param page - The page to send the transaction from.\n * @param options - The transaction options.\n * @returns The response.\n */\nexport async function sendTransaction(\n page: Page,\n options: Partial<TransactionOptions>,\n) {\n const {\n origin: transactionOrigin,\n chainId,\n ...transaction\n } = create(options, TransactionOptionsStruct);\n\n const args: SnapRpcHookArgs = {\n origin: '',\n handler: HandlerType.OnTransaction,\n request: {\n jsonrpc: '2.0',\n method: '',\n params: {\n chainId,\n transaction,\n transactionOrigin,\n },\n },\n };\n\n log('Sending transaction %o', args);\n\n const promise = waitForResponse(page, HandlerType.OnTransaction);\n const id = await sendRequest(page, args);\n const response = await promise;\n\n log('Received response %o', response);\n\n if (hasProperty(response, 'error')) {\n return { id, response, notifications: [] };\n }\n\n assert(isPlainObject(response.result));\n assert(hasProperty(response.result, 'content'));\n\n return {\n id,\n response,\n notifications: [],\n content: response.result.content as Component,\n };\n}\n\n/**\n * Run a cronjob.\n *\n * @param page - The page to run the cronjob from.\n * @param options - The request options.\n * @returns The response.\n */\nexport function runCronjob(page: Page, options: CronjobOptions) {\n return request(page, options, HandlerType.OnCronjob);\n}\n"],"names":["request","sendTransaction","runCronjob","log","createModuleLogger","rootLogger","sendRequest","page","args","document","getDocument","button","queries","getByTestId","handler","click","evaluate","payload","window","__SIMULATOR_API__","dispatch","type","getRequestId","origin","options","HandlerType","OnRpcRequest","doRequest","jsonrpc","id","promise","waitForResponse","response","notifications","getNotifications","getInterface","getInterfaceOptions","transactionOrigin","chainId","transaction","create","TransactionOptionsStruct","OnTransaction","method","params","hasProperty","assert","isPlainObject","result","content","OnCronjob"],"mappings":";;;;;;;;;;;IA+DgBA,OAAO;eAAPA;;IAiDMC,eAAe;eAAfA;;IAsDNC,UAAU;eAAVA;;;4BApKY;uBAMrB;oCAC8B;6BAEd;2BASwB;wBACpB;yBACc;yBACT;AAEhC,MAAMC,MAAMC,IAAAA,yBAAkB,EAACC,kBAAU,EAAE;AAE3C;;;;;;CAMC,GACD,eAAeC,YAAYC,IAAU,EAAEC,IAAqB;IAC1D,MAAMC,WAAW,MAAMC,IAAAA,+BAAW,EAACH;IACnC,MAAMI,SAAS,MAAMC,2BAAO,CAACC,WAAW,CACtCJ,UACA,CAAC,WAAW,EAAED,KAAKM,OAAO,CAAC,CAAC;IAG9B,wCAAwC;IACxC,MAAMH,OAAOI,KAAK;IAElB,OAAO,MAAMR,KAAKS,QAAQ,CAAC,CAACC;QAC1BC,OAAOC,iBAAiB,CAACC,QAAQ,CAAC;YAChCC,MAAM;YACNJ;QACF;QAEA,OAAOC,OAAOC,iBAAiB,CAACG,YAAY;IAC9C,GAAGd;AACL;AAWO,SAASR,QACdO,IAAU,EACV,EAAEgB,SAAS,aAAa,EAAE,GAAGC,SAAyB,EACtDV,UAE4BW,uBAAW,CAACC,YAAY;IAEpD,MAAMC,YAAY;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AAA,aAAM,EAACD,IAAAA,kBAAW,EAACb,SAASgB,MAAM,EAAE;IAEpC,OAAO;QACLnB;QACAG;QACAC,eAAe,EAAE;QACjBgB,SAASjB,SAASgB,MAAM,CAACC,OAAO;IAClC;AACF;AASO,SAAS/C,WAAWK,IAAU,EAAEiB,OAAuB;IAC5D,OAAOxB,QAAQO,MAAMiB,SAASC,uBAAW,CAACyB,SAAS;AACrD"}
@@ -22,8 +22,7 @@ _export(exports, {
22
22
  return SnapResponseStruct;
23
23
  }
24
24
  });
25
- const _snapsrpcmethods = require("@metamask/snaps-rpc-methods");
26
- const _snapsui = require("@metamask/snaps-ui");
25
+ const _snapssdk = require("@metamask/snaps-sdk");
27
26
  const _snapsutils = require("@metamask/snaps-utils");
28
27
  const _utils = require("@metamask/utils");
29
28
  const _crypto = require("crypto");
@@ -99,7 +98,7 @@ const SnapOptionsStruct = (0, _superstruct.object)({
99
98
  */ timeout: (0, _superstruct.defaulted)((0, _superstruct.optional)((0, _superstruct.number)()), 1000)
100
99
  });
101
100
  const InterfaceStruct = (0, _superstruct.type)({
102
- content: (0, _superstruct.optional)(_snapsui.ComponentStruct)
101
+ content: (0, _superstruct.optional)(_snapssdk.ComponentStruct)
103
102
  });
104
103
  const SnapResponseStruct = (0, _superstruct.assign)(InterfaceStruct, (0, _superstruct.object)({
105
104
  id: (0, _superstruct.string)(),
@@ -115,8 +114,8 @@ const SnapResponseStruct = (0, _superstruct.assign)(InterfaceStruct, (0, _supers
115
114
  id: (0, _superstruct.string)(),
116
115
  message: (0, _superstruct.string)(),
117
116
  type: (0, _superstruct.union)([
118
- (0, _snapsutils.enumValue)(_snapsrpcmethods.NotificationType.InApp),
119
- (0, _snapsutils.enumValue)(_snapsrpcmethods.NotificationType.Native)
117
+ (0, _snapsutils.enumValue)(_snapssdk.NotificationType.InApp),
118
+ (0, _snapsutils.enumValue)(_snapssdk.NotificationType.Native)
120
119
  ])
121
120
  }))
122
121
  }));
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/internals/structs.ts"],"sourcesContent":["import { NotificationType } from '@metamask/snaps-rpc-methods';\nimport { ComponentStruct } from '@metamask/snaps-ui';\nimport { enumValue } from '@metamask/snaps-utils';\nimport {\n bytesToHex,\n JsonStruct,\n StrictHexStruct,\n valueToBytes,\n} from '@metamask/utils';\nimport { randomBytes } from 'crypto';\nimport {\n array,\n assign,\n bigint,\n coerce,\n defaulted,\n instance,\n literal,\n number,\n object,\n optional,\n string,\n type,\n union,\n} from 'superstruct';\n\n// TODO: Export this from `@metamask/utils` instead.\nconst BytesLikeStruct = union([\n bigint(),\n number(),\n string(),\n instance(Uint8Array),\n]);\n\nexport const TransactionOptionsStruct = object({\n /**\n * The CAIP-2 chain ID to send the transaction on. Defaults to `eip155:1`.\n */\n chainId: defaulted(string(), 'eip155:1'),\n\n /**\n * The origin to send the transaction from. Defaults to `metamask.io`.\n */\n origin: defaulted(string(), 'metamask.io'),\n\n /**\n * The address to send the transaction from. Defaults to a randomly generated\n * address.\n */\n // TODO: Move this coercer to `@metamask/utils`.\n from: coerce(StrictHexStruct, optional(BytesLikeStruct), (value) => {\n if (value) {\n return valueToBytes(value);\n }\n\n return bytesToHex(randomBytes(20));\n }),\n\n /**\n * The address to send the transaction to. Defaults to a randomly generated\n * address.\n */\n // TODO: Move this coercer to `@metamask/utils`.\n to: coerce(StrictHexStruct, optional(BytesLikeStruct), (value) => {\n if (value) {\n return valueToBytes(value);\n }\n\n return bytesToHex(randomBytes(20));\n }),\n\n /**\n * The value to send with the transaction. The value may be specified as a\n * `number`, `bigint`, `string`, or `Uint8Array`. Defaults to `0`.\n */\n value: defaulted(\n coerce(StrictHexStruct, BytesLikeStruct, (value) =>\n bytesToHex(valueToBytes(value)),\n ),\n '0x0',\n ),\n\n /**\n * The gas limit to use for the transaction. The gas limit may be specified\n * as a `number`, `bigint`, `string`, or `Uint8Array`. Defaults to `21_000`.\n */\n gasLimit: defaulted(\n coerce(StrictHexStruct, BytesLikeStruct, (value) =>\n bytesToHex(valueToBytes(value)),\n ),\n valueToBytes(21_000),\n ),\n\n /**\n * The max fee per gas (in Wei) to use for the transaction. The max fee per\n * gas may be specified as a `number`, `bigint`, `string`, or `Uint8Array`.\n * Defaults to `1`.\n */\n maxFeePerGas: defaulted(\n coerce(StrictHexStruct, BytesLikeStruct, (value) =>\n bytesToHex(valueToBytes(value)),\n ),\n valueToBytes(1),\n ),\n\n /**\n * The max priority fee per gas (in Wei) to use for the transaction. The max\n * priority fee per gas may be specified as a `number`, `bigint`, `string`,\n * or `Uint8Array`. Defaults to `1`.\n */\n maxPriorityFeePerGas: defaulted(\n coerce(StrictHexStruct, BytesLikeStruct, (value) =>\n bytesToHex(valueToBytes(value)),\n ),\n valueToBytes(1),\n ),\n\n /**\n * The nonce to use for the transaction. The nonce may be specified as a\n * `number`, `bigint`, `string`, or `Uint8Array`. Defaults to `0`.\n */\n nonce: defaulted(\n coerce(StrictHexStruct, BytesLikeStruct, (value) =>\n bytesToHex(valueToBytes(value)),\n ),\n valueToBytes(0),\n ),\n\n /**\n * The data to send with the transaction. The data may be specified as a\n * `number`, `bigint`, `string`, or `Uint8Array`. Defaults to `0x`.\n */\n data: defaulted(\n coerce(union([StrictHexStruct, literal('0x')]), BytesLikeStruct, (value) =>\n bytesToHex(valueToBytes(value)),\n ),\n '0x',\n ),\n});\n\nexport const SnapOptionsStruct = object({\n /**\n * The timeout in milliseconds to use for requests to the snap. Defaults to\n * `1000`.\n */\n timeout: defaulted(optional(number()), 1000),\n});\n\nexport const InterfaceStruct = type({\n content: optional(ComponentStruct),\n});\n\nexport const SnapResponseStruct = assign(\n InterfaceStruct,\n object({\n id: string(),\n\n response: union([\n object({\n result: JsonStruct,\n }),\n object({\n error: JsonStruct,\n }),\n ]),\n\n notifications: array(\n object({\n id: string(),\n message: string(),\n type: union([\n enumValue(NotificationType.InApp),\n enumValue(NotificationType.Native),\n ]),\n }),\n ),\n }),\n);\n"],"names":["TransactionOptionsStruct","SnapOptionsStruct","InterfaceStruct","SnapResponseStruct","BytesLikeStruct","union","bigint","number","string","instance","Uint8Array","object","chainId","defaulted","origin","from","coerce","StrictHexStruct","optional","value","valueToBytes","bytesToHex","randomBytes","to","gasLimit","maxFeePerGas","maxPriorityFeePerGas","nonce","data","literal","timeout","type","content","ComponentStruct","assign","id","response","result","JsonStruct","error","notifications","array","message","enumValue","NotificationType","InApp","Native"],"mappings":";;;;;;;;;;;IAkCaA,wBAAwB;eAAxBA;;IA0GAC,iBAAiB;eAAjBA;;IAQAC,eAAe;eAAfA;;IAIAC,kBAAkB;eAAlBA;;;iCAxJoB;yBACD;4BACN;uBAMnB;wBACqB;6BAerB;AAEP,oDAAoD;AACpD,MAAMC,kBAAkBC,IAAAA,kBAAK,EAAC;IAC5BC,IAAAA,mBAAM;IACNC,IAAAA,mBAAM;IACNC,IAAAA,mBAAM;IACNC,IAAAA,qBAAQ,EAACC;CACV;AAEM,MAAMV,2BAA2BW,IAAAA,mBAAM,EAAC;IAC7C;;GAEC,GACDC,SAASC,IAAAA,sBAAS,EAACL,IAAAA,mBAAM,KAAI;IAE7B;;GAEC,GACDM,QAAQD,IAAAA,sBAAS,EAACL,IAAAA,mBAAM,KAAI;IAE5B;;;GAGC,GACD,gDAAgD;IAChDO,MAAMC,IAAAA,mBAAM,EAACC,sBAAe,EAAEC,IAAAA,qBAAQ,EAACd,kBAAkB,CAACe;QACxD,IAAIA,OAAO;YACT,OAAOC,IAAAA,mBAAY,EAACD;QACtB;QAEA,OAAOE,IAAAA,iBAAU,EAACC,IAAAA,mBAAW,EAAC;IAChC;IAEA;;;GAGC,GACD,gDAAgD;IAChDC,IAAIP,IAAAA,mBAAM,EAACC,sBAAe,EAAEC,IAAAA,qBAAQ,EAACd,kBAAkB,CAACe;QACtD,IAAIA,OAAO;YACT,OAAOC,IAAAA,mBAAY,EAACD;QACtB;QAEA,OAAOE,IAAAA,iBAAU,EAACC,IAAAA,mBAAW,EAAC;IAChC;IAEA;;;GAGC,GACDH,OAAON,IAAAA,sB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IAClCC,SAASd,IAAAA,qBAAQ,EAACe,wBAAe;AACnC;AAEO,MAAM9B,qBAAqB+B,IAAAA,mBAAM,EACtChC,iBACAS,IAAAA,mBAAM,EAAC;IACLwB,IAAI3B,IAAAA,mBAAM;IAEV4B,UAAU/B,IAAAA,kBAAK,EAAC;QACdM,IAAAA,mBAAM,EAAC;YACL0B,QAAQC,iBAAU;QACpB;QACA3B,IAAAA,mBAAM,EAAC;YACL4B,OAAOD,iBAAU;QACnB;KACD;IAEDE,eAAeC,IAAAA,kBAAK,EAClB9B,IAAAA,mBAAM,EAAC;QACLwB,IAAI3B,IAAAA,mBAAM;QACVkC,SAASlC,IAAAA,mBAAM;QACfuB,MAAM1B,IAAAA,kBAAK,EAAC;YACVsC,IAAAA,qBAAS,EAACC,iCAAgB,CAACC,KAAK;YAChCF,IAAAA,qBAAS,EAACC,iCAAgB,CAACE,MAAM;SAClC;IACH;AAEJ"}
1
+ {"version":3,"sources":["../../../src/internals/structs.ts"],"sourcesContent":["import { NotificationType, ComponentStruct } from '@metamask/snaps-sdk';\nimport { enumValue } from '@metamask/snaps-utils';\nimport {\n bytesToHex,\n JsonStruct,\n StrictHexStruct,\n valueToBytes,\n} from '@metamask/utils';\nimport { randomBytes } from 'crypto';\nimport {\n array,\n assign,\n bigint,\n coerce,\n defaulted,\n instance,\n literal,\n number,\n object,\n optional,\n string,\n type,\n union,\n} from 'superstruct';\n\n// TODO: Export this from `@metamask/utils` instead.\nconst BytesLikeStruct = union([\n bigint(),\n number(),\n string(),\n instance(Uint8Array),\n]);\n\nexport const TransactionOptionsStruct = object({\n /**\n * The CAIP-2 chain ID to send the transaction on. Defaults to `eip155:1`.\n */\n chainId: defaulted(string(), 'eip155:1'),\n\n /**\n * The origin to send the transaction from. Defaults to `metamask.io`.\n */\n origin: defaulted(string(), 'metamask.io'),\n\n /**\n * The address to send the transaction from. Defaults to a randomly generated\n * address.\n */\n // TODO: Move this coercer to `@metamask/utils`.\n from: coerce(StrictHexStruct, optional(BytesLikeStruct), (value) => {\n if (value) {\n return valueToBytes(value);\n }\n\n return bytesToHex(randomBytes(20));\n }),\n\n /**\n * The address to send the transaction to. Defaults to a randomly generated\n * address.\n */\n // TODO: Move this coercer to `@metamask/utils`.\n to: coerce(StrictHexStruct, optional(BytesLikeStruct), (value) => {\n if (value) {\n return valueToBytes(value);\n }\n\n return bytesToHex(randomBytes(20));\n }),\n\n /**\n * The value to send with the transaction. The value may be specified as a\n * `number`, `bigint`, `string`, or `Uint8Array`. Defaults to `0`.\n */\n value: defaulted(\n coerce(StrictHexStruct, BytesLikeStruct, (value) =>\n bytesToHex(valueToBytes(value)),\n ),\n '0x0',\n ),\n\n /**\n * The gas limit to use for the transaction. The gas limit may be specified\n * as a `number`, `bigint`, `string`, or `Uint8Array`. Defaults to `21_000`.\n */\n gasLimit: defaulted(\n coerce(StrictHexStruct, BytesLikeStruct, (value) =>\n bytesToHex(valueToBytes(value)),\n ),\n valueToBytes(21_000),\n ),\n\n /**\n * The max fee per gas (in Wei) to use for the transaction. The max fee per\n * gas may be specified as a `number`, `bigint`, `string`, or `Uint8Array`.\n * Defaults to `1`.\n */\n maxFeePerGas: defaulted(\n coerce(StrictHexStruct, BytesLikeStruct, (value) =>\n bytesToHex(valueToBytes(value)),\n ),\n valueToBytes(1),\n ),\n\n /**\n * The max priority fee per gas (in Wei) to use for the transaction. The max\n * priority fee per gas may be specified as a `number`, `bigint`, `string`,\n * or `Uint8Array`. Defaults to `1`.\n */\n maxPriorityFeePerGas: defaulted(\n coerce(StrictHexStruct, BytesLikeStruct, (value) =>\n bytesToHex(valueToBytes(value)),\n ),\n valueToBytes(1),\n ),\n\n /**\n * The nonce to use for the transaction. The nonce may be specified as a\n * `number`, `bigint`, `string`, or `Uint8Array`. Defaults to `0`.\n */\n nonce: defaulted(\n coerce(StrictHexStruct, BytesLikeStruct, (value) =>\n bytesToHex(valueToBytes(value)),\n ),\n valueToBytes(0),\n ),\n\n /**\n * The data to send with the transaction. The data may be specified as a\n * `number`, `bigint`, `string`, or `Uint8Array`. Defaults to `0x`.\n */\n data: defaulted(\n coerce(union([StrictHexStruct, literal('0x')]), BytesLikeStruct, (value) =>\n bytesToHex(valueToBytes(value)),\n ),\n '0x',\n ),\n});\n\nexport const SnapOptionsStruct = object({\n /**\n * The timeout in milliseconds to use for requests to the snap. Defaults to\n * `1000`.\n */\n timeout: defaulted(optional(number()), 1000),\n});\n\nexport const InterfaceStruct = type({\n content: optional(ComponentStruct),\n});\n\nexport const SnapResponseStruct = assign(\n InterfaceStruct,\n object({\n id: string(),\n\n response: union([\n object({\n result: JsonStruct,\n }),\n object({\n error: JsonStruct,\n }),\n ]),\n\n notifications: array(\n object({\n id: string(),\n message: string(),\n type: union([\n enumValue(NotificationType.InApp),\n enumValue(NotificationType.Native),\n ]),\n }),\n ),\n }),\n);\n"],"names":["TransactionOptionsStruct","SnapOptionsStruct","InterfaceStruct","SnapResponseStruct","BytesLikeStruct","union","bigint","number","string","instance","Uint8Array","object","chainId","defaulted","origin","from","coerce","StrictHexStruct","optional","value","valueToBytes","bytesToHex","randomBytes","to","gasLimit","maxFeePerGas","maxPriorityFeePerGas","nonce","data","literal","timeout","type","content","ComponentStruct","assign","id","response","result","JsonStruct","error","notifications","array","message","enumValue","NotificationType","InApp","Native"],"mappings":";;;;;;;;;;;IAiCaA,wBAAwB;eAAxBA;;IA0GAC,iBAAiB;eAAjBA;;IAQAC,eAAe;eAAfA;;IAIAC,kBAAkB;eAAlBA;;;0BAvJqC;4BACxB;uBAMnB;wBACqB;6BAerB;AAEP,oDAAoD;AACpD,MAAMC,kBAAkBC,IAAAA,kBAAK,EAAC;IAC5BC,IAAAA,mBAAM;IACNC,IAAAA,mBAAM;IACNC,IAAAA,mBAAM;IACNC,IAAAA,qBAAQ,EAACC;CACV;AAEM,MAAMV,2BAA2BW,IAAAA,mBAAM,EAAC;IAC7C;;GAEC,GACDC,SAASC,IAAAA,sBAAS,EAACL,IAAAA,mBAAM,KAAI;IAE7B;;GAE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,IAAAA,sBAAS,EACdG,IAAAA,mBAAM,EAACC,sBAAe,EAAEb,iBAAiB,CAACe,QACxCE,IAAAA,iBAAU,EAACD,IAAAA,mBAAY,EAACD,UAE1BC,IAAAA,mBAAY,EAAC;IAGf;;;GAGC,GACDQ,MAAMf,IAAAA,sBAAS,EACbG,IAAAA,mBAAM,EAACX,IAAAA,kBAAK,EAAC;QAACY,sBAAe;QAAEY,IAAAA,oBAAO,EAAC;KAAM,GAAGzB,iBAAiB,CAACe,QAChEE,IAAAA,iBAAU,EAACD,IAAAA,mBAAY,EAACD,UAE1B;AAEJ;AAEO,MAAMlB,oBAAoBU,IAAAA,mBAAM,EAAC;IACtC;;;GAGC,GACDmB,SAASjB,IAAAA,sBAAS,EAACK,IAAAA,qBAAQ,EAACX,IAAAA,mBAAM,MAAK;AACzC;AAEO,MAAML,kBAAkB6B,IAAAA,iBAAI,EAAC;IAClCC,SAASd,IAAAA,qBAAQ,EAACe,yBAAe;AACnC;AAEO,MAAM9B,qBAAqB+B,IAAAA,mBAAM,EACtChC,iBACAS,IAAAA,mBAAM,EAAC;IACLwB,IAAI3B,IAAAA,mBAAM;IAEV4B,UAAU/B,IAAAA,kBAAK,EAAC;QACdM,IAAAA,mBAAM,EAAC;YACL0B,QAAQC,iBAAU;QACpB;QACA3B,IAAAA,mBAAM,EAAC;YACL4B,OAAOD,iBAAU;QACnB;KACD;IAEDE,eAAeC,IAAAA,kBAAK,EAClB9B,IAAAA,mBAAM,EAAC;QACLwB,IAAI3B,IAAAA,mBAAM;QACVkC,SAASlC,IAAAA,mBAAM;QACfuB,MAAM1B,IAAAA,kBAAK,EAAC;YACVsC,IAAAA,qBAAS,EAACC,0BAAgB,CAACC,KAAK;YAChCF,IAAAA,qBAAS,EAACC,0BAAgB,CAACE,MAAM;SAClC;IACH;AAEJ"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/matchers.ts"],"sourcesContent":["/* eslint-disable no-invalid-this */\n\n// Note: Because this file imports from `@jest/globals`, it can only be used in\n// a Jest environment. This is why it's not exported from the index file.\n\nimport type { MatcherFunction } from '@jest/expect';\nimport { expect } from '@jest/globals';\nimport type { NotificationType } from '@metamask/snaps-rpc-methods';\nimport type { Component } from '@metamask/snaps-ui';\nimport type { EnumToUnion } from '@metamask/snaps-utils';\nimport type { Json } from '@metamask/utils';\nimport { hasProperty } from '@metamask/utils';\nimport type { MatcherHintOptions } from 'jest-matcher-utils';\nimport {\n diff,\n matcherErrorMessage,\n matcherHint,\n printReceived,\n printWithType,\n RECEIVED_COLOR,\n} from 'jest-matcher-utils';\nimport { is } from 'superstruct';\n\nimport { InterfaceStruct, SnapResponseStruct } from './internals';\nimport type { SnapResponse } from './types';\n\n/**\n * Ensure that the actual value is a response from the `request` function.\n *\n * @param actual - The actual value.\n * @param matcherName - The name of the matcher.\n * @param options - The matcher options.\n */\nfunction assertActualIsSnapResponse(\n actual: unknown,\n matcherName: string,\n options?: MatcherHintOptions,\n): asserts actual is SnapResponse {\n if (!is(actual, SnapResponseStruct)) {\n throw new Error(\n matcherErrorMessage(\n matcherHint(matcherName, undefined, undefined, options),\n `${RECEIVED_COLOR(\n 'received',\n )} value must be a response from the \\`request\\` function`,\n printWithType('Received', actual, printReceived),\n ),\n );\n }\n}\n\n/**\n * Ensure that the actual value is a response from the `request` function, and\n * that it has a `ui` property.\n *\n * @param actual - The actual value.\n * @param matcherName - The name of the matcher.\n * @param options - The matcher options.\n */\nfunction assertHasInterface(\n actual: unknown,\n matcherName: string,\n options?: MatcherHintOptions,\n): asserts actual is { content: Component } {\n if (!is(actual, InterfaceStruct) || !actual.content) {\n throw new Error(\n matcherErrorMessage(\n matcherHint(matcherName, undefined, undefined, options),\n `${RECEIVED_COLOR('received')} value must have a \\`content\\` property`,\n printWithType('Received', actual, printReceived),\n ),\n );\n }\n}\n\n/**\n * Check if a JSON-RPC response matches the expected value. This matcher is\n * intended to be used with the `expect` global.\n *\n * @param actual - The actual response.\n * @param expected - The expected response.\n * @returns The status and message.\n */\nexport const toRespondWith: MatcherFunction<[expected: Json]> = function (\n actual,\n expected,\n) {\n assertActualIsSnapResponse(actual, 'toRespondWith');\n\n const { response } = actual;\n if (hasProperty(response, 'error')) {\n const message = () =>\n `${this.utils.matcherHint('.toRespondWith')}\\n\\n` +\n `Expected response: ${this.utils.printExpected(expected)}\\n` +\n `Received error: ${this.utils.printReceived(response.error)}`;\n\n return { message, pass: false };\n }\n\n const pass = this.equals(response.result, expected);\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRespondWith')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.result)}`\n : () =>\n `${this.utils.matcherHint('.toRespondWith')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.result)}`;\n\n return { message, pass };\n};\n\nexport const toRespondWithError: MatcherFunction<[expected: Json]> = function (\n actual,\n expected,\n) {\n assertActualIsSnapResponse(actual, 'toRespondWithError');\n\n const { response } = actual;\n if (hasProperty(response, 'result')) {\n const message = () =>\n `${this.utils.matcherHint('.toRespondWithError')}\\n\\n` +\n `Expected error: ${this.utils.printExpected(expected)}\\n` +\n `Received result: ${this.utils.printReceived(response.result)}`;\n\n return { message, pass: false };\n }\n\n const pass = this.equals(response.error, expected);\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRespondWithError')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.error)}`\n : () =>\n `${this.utils.matcherHint('.toRespondWithError')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.error)}`;\n\n return { message, pass };\n};\n\n/**\n * Check if the snap sent a notification with the expected message. This matcher\n * is intended to be used with the `expect` global.\n *\n * @param actual - The actual response.\n * @param expected - The expected notification message.\n * @param type - The expected notification type.\n * @returns The status and message.\n */\nexport const toSendNotification: MatcherFunction<\n [expected: string, type?: EnumToUnion<NotificationType> | undefined]\n> = async function (actual, expected, type) {\n assertActualIsSnapResponse(actual, 'toSendNotification');\n\n const { notifications } = actual;\n const pass = notifications.some(\n (notification) =>\n this.equals(notification.message, expected) &&\n (type === undefined || notification.type === type),\n );\n\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toSendNotification')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Expected type: ${this.utils.printExpected(type)}\\n` +\n `Received: ${this.utils.printReceived(notifications)}`\n : () =>\n `${this.utils.matcherHint('.toSendNotification')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Expected type: ${this.utils.printExpected(type)}\\n` +\n `Received: ${this.utils.printReceived(notifications)}`;\n\n return { message, pass };\n};\n\nexport const toRender: MatcherFunction<[expected: Component]> = function (\n actual,\n expected,\n) {\n assertHasInterface(actual, 'toRender');\n\n const { content } = actual;\n const pass = this.equals(content, expected);\n\n const difference = diff(expected, content);\n\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toShowInterface')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(content)}` +\n `${difference ? `\\n\\nDifference:\\n\\n${difference}` : ''}`\n : () =>\n `${this.utils.matcherHint('.toShowInterface')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(content)}` +\n `${difference ? `\\n\\nDifference:\\n\\n${difference}` : ''}`;\n\n return { message, pass };\n};\n\nexpect.extend({\n toRespondWith,\n toRespondWithError,\n toSendNotification,\n toRender,\n});\n"],"names":["toRespondWith","toRespondWithError","toSendNotification","toRender","assertActualIsSnapResponse","actual","matcherName","options","is","SnapResponseStruct","Error","matcherErrorMessage","matcherHint","undefined","RECEIVED_COLOR","printWithType","printReceived","assertHasInterface","InterfaceStruct","content","expected","response","hasProperty","message","utils","printExpected","error","pass","equals","result","type","notifications","some","notification","difference","diff","expect","extend"],"mappings":"AAAA,kCAA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,MAAM,CAAC;IACZrC;IACAC;IACAC;IACAC;AACF"}
1
+ {"version":3,"sources":["../../src/matchers.ts"],"sourcesContent":["/* eslint-disable no-invalid-this */\n\n// Note: Because this file imports from `@jest/globals`, it can only be used in\n// a Jest environment. This is why it's not exported from the index file.\n\nimport type { MatcherFunction } from '@jest/expect';\nimport { expect } from '@jest/globals';\nimport type {\n NotificationType,\n EnumToUnion,\n Component,\n} from '@metamask/snaps-sdk';\nimport type { Json } from '@metamask/utils';\nimport { hasProperty } from '@metamask/utils';\nimport type { MatcherHintOptions } from 'jest-matcher-utils';\nimport {\n diff,\n matcherErrorMessage,\n matcherHint,\n printReceived,\n printWithType,\n RECEIVED_COLOR,\n} from 'jest-matcher-utils';\nimport { is } from 'superstruct';\n\nimport { InterfaceStruct, SnapResponseStruct } from './internals';\nimport type { SnapResponse } from './types';\n\n/**\n * Ensure that the actual value is a response from the `request` function.\n *\n * @param actual - The actual value.\n * @param matcherName - The name of the matcher.\n * @param options - The matcher options.\n */\nfunction assertActualIsSnapResponse(\n actual: unknown,\n matcherName: string,\n options?: MatcherHintOptions,\n): asserts actual is SnapResponse {\n if (!is(actual, SnapResponseStruct)) {\n throw new Error(\n matcherErrorMessage(\n matcherHint(matcherName, undefined, undefined, options),\n `${RECEIVED_COLOR(\n 'received',\n )} value must be a response from the \\`request\\` function`,\n printWithType('Received', actual, printReceived),\n ),\n );\n }\n}\n\n/**\n * Ensure that the actual value is a response from the `request` function, and\n * that it has a `ui` property.\n *\n * @param actual - The actual value.\n * @param matcherName - The name of the matcher.\n * @param options - The matcher options.\n */\nfunction assertHasInterface(\n actual: unknown,\n matcherName: string,\n options?: MatcherHintOptions,\n): asserts actual is { content: Component } {\n if (!is(actual, InterfaceStruct) || !actual.content) {\n throw new Error(\n matcherErrorMessage(\n matcherHint(matcherName, undefined, undefined, options),\n `${RECEIVED_COLOR('received')} value must have a \\`content\\` property`,\n printWithType('Received', actual, printReceived),\n ),\n );\n }\n}\n\n/**\n * Check if a JSON-RPC response matches the expected value. This matcher is\n * intended to be used with the `expect` global.\n *\n * @param actual - The actual response.\n * @param expected - The expected response.\n * @returns The status and message.\n */\nexport const toRespondWith: MatcherFunction<[expected: Json]> = function (\n actual,\n expected,\n) {\n assertActualIsSnapResponse(actual, 'toRespondWith');\n\n const { response } = actual;\n if (hasProperty(response, 'error')) {\n const message = () =>\n `${this.utils.matcherHint('.toRespondWith')}\\n\\n` +\n `Expected response: ${this.utils.printExpected(expected)}\\n` +\n `Received error: ${this.utils.printReceived(response.error)}`;\n\n return { message, pass: false };\n }\n\n const pass = this.equals(response.result, expected);\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRespondWith')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.result)}`\n : () =>\n `${this.utils.matcherHint('.toRespondWith')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.result)}`;\n\n return { message, pass };\n};\n\nexport const toRespondWithError: MatcherFunction<[expected: Json]> = function (\n actual,\n expected,\n) {\n assertActualIsSnapResponse(actual, 'toRespondWithError');\n\n const { response } = actual;\n if (hasProperty(response, 'result')) {\n const message = () =>\n `${this.utils.matcherHint('.toRespondWithError')}\\n\\n` +\n `Expected error: ${this.utils.printExpected(expected)}\\n` +\n `Received result: ${this.utils.printReceived(response.result)}`;\n\n return { message, pass: false };\n }\n\n const pass = this.equals(response.error, expected);\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRespondWithError')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.error)}`\n : () =>\n `${this.utils.matcherHint('.toRespondWithError')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.error)}`;\n\n return { message, pass };\n};\n\n/**\n * Check if the snap sent a notification with the expected message. This matcher\n * is intended to be used with the `expect` global.\n *\n * @param actual - The actual response.\n * @param expected - The expected notification message.\n * @param type - The expected notification type.\n * @returns The status and message.\n */\nexport const toSendNotification: MatcherFunction<\n [expected: string, type?: EnumToUnion<NotificationType> | undefined]\n> = async function (actual, expected, type) {\n assertActualIsSnapResponse(actual, 'toSendNotification');\n\n const { notifications } = actual;\n const pass = notifications.some(\n (notification) =>\n this.equals(notification.message, expected) &&\n (type === undefined || notification.type === type),\n );\n\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toSendNotification')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Expected type: ${this.utils.printExpected(type)}\\n` +\n `Received: ${this.utils.printReceived(notifications)}`\n : () =>\n `${this.utils.matcherHint('.toSendNotification')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Expected type: ${this.utils.printExpected(type)}\\n` +\n `Received: ${this.utils.printReceived(notifications)}`;\n\n return { message, pass };\n};\n\nexport const toRender: MatcherFunction<[expected: Component]> = function (\n actual,\n expected,\n) {\n assertHasInterface(actual, 'toRender');\n\n const { content } = actual;\n const pass = this.equals(content, expected);\n\n const difference = diff(expected, content);\n\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toShowInterface')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(content)}` +\n `${difference ? `\\n\\nDifference:\\n\\n${difference}` : ''}`\n : () =>\n `${this.utils.matcherHint('.toShowInterface')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(content)}` +\n `${difference ? `\\n\\nDifference:\\n\\n${difference}` : ''}`;\n\n return { message, pass };\n};\n\nexpect.extend({\n toRespondWith,\n toRespondWithError,\n toSendNotification,\n toRender,\n});\n"],"names":["toRespondWith","toRespondWithError","toSendNotification","toRender","assertActualIsSnapResponse","actual","matcherName","options","is","SnapResponseStruct","Error","matcherErrorMessage","matcherHint","undefined","RECEIVED_COLOR","printWithType","printReceived","assertHasInterface","InterfaceStruct","content","expected","response","hasProperty","message","utils","printExpected","error","pass","equals","result","type","notifications","some","notification","difference","diff","expect","extend"],"mappings":"AAAA,kCAAkC,GAElC,+EAA+E;AAC/E,yEAAyE;;;;;;;;;;;;IAkF5DA,aAAa;eAAbA;;IA8BAC,kBAAkB;eAAlBA;;IAuCAC,kBAAkB;eAAlBA;;IA2BAC,QAAQ;eAARA;;;yBA/KU;uBAOK;kCASrB;6BACY;2BAEiC;AAGpD;;;;;;CAMC,GACD,SAASC,2BACPC,MAAe,EACfC,WAAmB,EACnBC,OAA4B;IAE5B,IAAI,CAACC,IAAAA,eAAE,EAACH,QAAQI,6BAAkB,GAAG;QACnC,MAAM,IAAIC,MACRC,IAAAA,qCAAmB,EACjBC,IAAAA,6BAAW,EAACN,aAAaO,WAAWA,WAAWN,UAC/C,CAAC,EAAEO,IAAAA,gCAAc,EACf,YACA,uDAAuD,CAAC,EAC1DC,IAAAA,+BAAa,EAAC,YAAYV,QAAQW,+BAAa;IAGrD;AACF;AAEA;;;;;;;CAOC,GACD,SAASC,mBACPZ,MAAe,EACfC,WAAmB,EACnBC,OAA4B;IAE5B,IAAI,CAACC,IAAAA,eAAE,EAACH,QAAQa,0BAAe,KAAK,CAACb,OAAOc,OAAO,EAAE;QACnD,MAAM,IAAIT,MACRC,IAAAA,qCAAmB,EACjBC,IAAAA,6BAAW,EAACN,aAAaO,WAAWA,WAAWN,UAC/C,CAAC,EAAEO,IAAAA,gCAAc,EAAC,YAAY,uCAAuC,CAAC,EACtEC,IAAAA,+BAAa,EAAC,YAAYV,QAAQW,+BAAa;IAGrD;AACF;AAUO,MAAMhB,gBAAmD,SAC9DK,MAAM,EACNe,QAAQ;IAERhB,2BAA2BC,QAAQ;IAEnC,MAAM,EAAEgB,QAAQ,EAAE,GAAGhB;IACrB,IAAIiB,IAAAA,kBAAW,EAACD,UAAU,UAAU;QAClC,MAAME,UAAU,IACd,CAAC,EAAE,IAAI,CAACC,KAAK,CAACZ,WAAW,CAAC,kBA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EAAEA,WAAW,CAAC,GAAG,GAAG,CAAC;IAE/D,OAAO;QAAEX;QAASI;IAAK;AACzB;AAEAS,eAAM,CAACC,MAAM,CAAC;IACZrC;IACAC;IACAC;IACAC;AACF"}
package/dist/cjs/types.js CHANGED
@@ -2,12 +2,5 @@
2
2
  Object.defineProperty(exports, "__esModule", {
3
3
  value: true
4
4
  });
5
- Object.defineProperty(exports, "NotificationType", {
6
- enumerable: true,
7
- get: function() {
8
- return _snapsrpcmethods.NotificationType;
9
- }
10
- });
11
- const _snapsrpcmethods = require("@metamask/snaps-rpc-methods");
12
5
 
13
6
  //# sourceMappingURL=types.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/types.ts"],"sourcesContent":["import type { NotificationType } from '@metamask/snaps-rpc-methods';\nimport type { Component } from '@metamask/snaps-ui';\nimport type { EnumToUnion } from '@metamask/snaps-utils';\nimport type { JsonRpcId, JsonRpcParams } from '@metamask/utils';\nimport type { Infer } from 'superstruct';\n\nimport type {\n Mock,\n MockJsonRpcOptions,\n MockOptions,\n SnapOptionsStruct,\n SnapResponseStruct,\n TransactionOptionsStruct,\n} from './internals';\n\n/* eslint-disable @typescript-eslint/consistent-type-definitions */\ndeclare module 'expect' {\n interface AsymmetricMatchers {\n toRespondWith(response: unknown): void;\n toRespondWithError(error: unknown): void;\n toSendNotification(\n message: string,\n type?: EnumToUnion<NotificationType>,\n ): void;\n toRender(component: Component): void;\n }\n\n // Ideally we would use `Matchers<Result>` instead of `Matchers<R>`, but\n // TypeScript doesn't allow this:\n // TS2428: All declarations of 'Matchers' must have identical type parameters.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n interface Matchers<R> {\n toRespondWith(response: unknown): R;\n toRespondWithError(error: unknown): R;\n toSendNotification(\n message: string,\n type?: EnumToUnion<NotificationType>,\n ): R;\n toRender(component: Component): R;\n }\n}\n/* eslint-enable @typescript-eslint/consistent-type-definitions */\n\n/**\n * Deeply partialize a type.\n *\n * @template Type - The type to partialize.\n * @returns The deeply partialized type.\n * @example\n * ```ts\n * type Foo = {\n * bar: {\n * baz: string;\n * };\n * qux: number;\n * };\n *\n * type PartialFoo = DeepPartial<Foo>;\n * // { bar?: { baz?: string; }; qux?: number; }\n * ```\n */\nexport type DeepPartial<Type> = {\n [Key in keyof Type]?: Type[Key] extends Record<string, unknown>\n ? DeepPartial<Type[Key]>\n : Type[Key];\n};\n\nexport type RequestOptions = {\n /**\n * The JSON-RPC request ID.\n */\n id?: JsonRpcId;\n\n /**\n * The JSON-RPC method.\n */\n method: string;\n\n /**\n * The JSON-RPC params.\n */\n params?: JsonRpcParams;\n\n /**\n * The origin to send the request from.\n */\n origin?: string;\n};\n\n/**\n * The `runCronjob` options. This is the same as {@link RequestOptions}, except\n * that it does not have an `origin` property.\n */\nexport type CronjobOptions = Omit<RequestOptions, 'origin'>;\n\n/**\n * The options to use for transaction requests.\n *\n * @property chainId - The CAIP-2 chain ID to send the transaction on. Defaults\n * to `eip155:1`.\n * @property origin - The origin to send the transaction from. Defaults to\n * `metamask.io`.\n * @property from - The address to send the transaction from. Defaults to a\n * randomly generated address.\n * @property to - The address to send the transaction to. Defaults to a randomly\n * generated address.\n * @property value - The value to send with the transaction. Defaults to `0`.\n * @property data - The data to send with the transaction. Defaults to `0x`.\n * @property gasLimit - The gas limit to use for the transaction. Defaults to\n * `21_000`.\n * @property maxFeePerGas - The maximum fee per gas to use for the transaction.\n * Defaults to `1`.\n * @property maxPriorityFeePerGas - The maximum priority fee per gas to use for\n * the transaction. Defaults to `1`.\n * @property nonce - The nonce to use for the transaction. Defaults to `0`.\n */\nexport type TransactionOptions = Infer<typeof TransactionOptionsStruct>;\n\n/**\n * The options to use for requests to the snap.\n *\n * @property timeout - The timeout in milliseconds to use. Defaults to `1000`.\n */\nexport type SnapOptions = Infer<typeof SnapOptionsStruct>;\n\n/**\n * A `snap_dialog` alert interface.\n */\nexport type SnapAlertInterface = {\n /**\n * The type of the interface. This is always `alert`.\n */\n type: 'alert';\n\n /**\n * The content to show in the alert.\n */\n content: Component;\n\n /**\n * Close the alert.\n */\n ok(): Promise<void>;\n};\n\n/**\n * A `snap_dialog` confirmation interface.\n */\nexport type SnapConfirmationInterface = {\n /**\n * The type of the interface. This is always `confirmation`.\n */\n type: 'confirmation';\n\n /**\n * The content to show in the confirmation.\n */\n content: Component;\n\n /**\n * Close the confirmation.\n */\n ok(): Promise<void>;\n\n /**\n * Cancel the confirmation.\n */\n cancel(): Promise<void>;\n};\n\n/**\n * A `snap_dialog` prompt interface.\n */\nexport type SnapPromptInterface = {\n /**\n * The type of the interface. This is always `prompt`.\n */\n type: 'prompt';\n\n /**\n * The content to show in the prompt.\n */\n content: Component;\n\n /**\n * Close the prompt.\n *\n * @param value - The value to close the prompt with.\n */\n ok(value?: string): Promise<void>;\n\n /**\n * Cancel the prompt.\n */\n cancel(): Promise<void>;\n};\n\nexport type SnapInterface =\n | SnapAlertInterface\n | SnapConfirmationInterface\n | SnapPromptInterface;\n\nexport type SnapRequestObject = {\n /**\n * Get a user interface object from a snap. This will throw an error if the\n * snap does not show a user interface within the timeout.\n *\n * @param options - The options to use.\n * @param options.timeout - The timeout in milliseconds to use. Defaults to\n * `1000`.\n * @returns The user interface object.\n */\n getInterface(options?: SnapOptions): Promise<SnapInterface>;\n};\n\n/**\n * A pending request object. This is a promise with extra\n * {@link SnapRequestObject} fields.\n */\nexport type SnapRequest = Promise<SnapResponse> & SnapRequestObject;\n\n/**\n * This is the main entry point to interact with the snap. It is returned by\n * {@link installSnap}, and has methods to send requests to the snap.\n *\n * @example\n * ```ts\n * import { installSnap } from '@metamask/snaps-jest';\n *\n * const snap = await installSnap();\n * const response = await snap.request({ method: 'hello' });\n *\n * expect(response).toRespondWith('Hello, world!');\n * ```\n */\nexport type Snap = {\n /**\n * Send a JSON-RPC request to the snap.\n *\n * @param request - The request. This is similar to a JSON-RPC request, but\n * has an extra `origin` field.\n * @returns The response promise, with extra {@link SnapRequestObject} fields.\n */\n request(request: RequestOptions): SnapRequest;\n\n /**\n * Send a transaction to the snap.\n *\n * @param transaction - The transaction. This is similar to an Ethereum\n * transaction object, but has an extra `origin` field. Any missing fields\n * will be filled in with default values.\n * @returns The response.\n */\n sendTransaction(\n transaction?: Partial<TransactionOptions>,\n ): Promise<SnapResponse>;\n\n /**\n * Run a cronjob in the snap. This is similar to {@link request}, but the\n * request will be sent to the `onCronjob` method of the snap.\n *\n * @param cronjob - The cronjob request. This is similar to a JSON-RPC\n * request, and is normally specified in the snap manifest, under the\n * `endowment:cronjob` permission.\n * @returns The response promise, with extra {@link SnapRequestObject} fields.\n */\n runCronjob(cronjob: CronjobOptions): SnapRequest;\n\n /**\n * Close the page running the snap. This is mainly useful for cleaning up\n * the test environment, and calling it is not strictly necessary.\n *\n * @returns A promise that resolves when the page is closed.\n */\n // TODO: Find a way to do this automatically.\n close(): Promise<void>;\n\n /**\n * Enable network mocking for the snap.\n *\n * @param options - The options for the network mocking.\n * @returns A {@link Mock} object, with an `unmock` function.\n */\n mock(options: DeepPartial<MockOptions>): Promise<Mock>;\n\n /**\n * Enable JSON-RPC provider mocking for the snap. This will mock any requests\n * sent through the `ethereum` global, with the specified `method`.\n *\n * @param options - The options for the JSON-RPC mocking.\n * @param options.method - The JSON-RPC method to mock, e.g.,\n * `eth_blockNumber`.\n * @param options.result - The JSON value to return.\n * @returns A {@link Mock} object, with an `unmock` function.\n */\n mockJsonRpc(options: MockJsonRpcOptions): Promise<Mock>;\n};\n\nexport type SnapResponse = Infer<typeof SnapResponseStruct>;\n\nexport { NotificationType } from '@metamask/snaps-rpc-methods';\n"],"names":["NotificationType"],"mappings":";;;;+BA4SSA;;;eAAAA,iCAAgB;;;iCAAQ"}
1
+ {"version":3,"sources":["../../src/types.ts"],"names":[],"mappings":""}
@@ -1,4 +1,4 @@
1
- import { DialogType } from '@metamask/snaps-rpc-methods';
1
+ import { DialogType } from '@metamask/snaps-sdk';
2
2
  import { assert } from '@metamask/utils';
3
3
  import { create } from 'superstruct';
4
4
  import { SnapOptionsStruct } from './structs';
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/internals/interface.ts"],"sourcesContent":["import { DialogType } from '@metamask/snaps-rpc-methods';\nimport { assert } from '@metamask/utils';\nimport type { Page } from 'puppeteer';\nimport { create } from 'superstruct';\n\nimport type { SnapInterface, SnapOptions } from '../types';\nimport { SnapOptionsStruct } from './structs';\nimport { waitFor } from './wait-for';\n\n/**\n * Get the current snap user interface (i.e., dialog). This will throw an error\n * if the snap does not show a user interface within the timeout.\n *\n * @param page - The page to get the interface from.\n * @param options - The options to use.\n * @param options.timeout - The timeout in milliseconds to use. Defaults to\n * `1000`.\n * @returns The user interface object.\n */\nexport async function getInterface(\n page: Page,\n options: SnapOptions = {},\n): Promise<SnapInterface> {\n const { timeout } = create(options, SnapOptionsStruct);\n\n const { type, node: content } = await waitFor(\n async () => {\n const ui = await page.evaluate(() => {\n const state = window.__SIMULATOR_API__.getState();\n return state.simulation.ui;\n });\n\n assert(ui);\n return ui;\n },\n {\n timeout,\n message: 'Timed out waiting for snap interface to be shown.',\n },\n );\n\n switch (type) {\n case DialogType.Alert:\n return {\n type: 'alert',\n content,\n\n ok: async () => {\n await page.evaluate(() => {\n window.__SIMULATOR_API__.dispatch({\n type: 'simulation/resolveUserInterface',\n payload: null,\n });\n });\n },\n };\n\n case DialogType.Confirmation:\n return {\n type: 'confirmation',\n content,\n\n ok: async () => {\n await page.evaluate(() => {\n window.__SIMULATOR_API__.dispatch({\n type: 'simulation/resolveUserInterface',\n payload: true,\n });\n });\n },\n\n cancel: async () => {\n await page.evaluate(() => {\n window.__SIMULATOR_API__.dispatch({\n type: 'simulation/resolveUserInterface',\n payload: false,\n });\n });\n },\n };\n\n case DialogType.Prompt:\n return {\n type: 'prompt',\n content,\n\n ok: async (value) => {\n await page.evaluate((payload) => {\n window.__SIMULATOR_API__.dispatch({\n type: 'simulation/resolveUserInterface',\n payload,\n });\n }, value);\n },\n\n cancel: async () => {\n await page.evaluate(() => {\n window.__SIMULATOR_API__.dispatch({\n type: 'simulation/resolveUserInterface',\n payload: null,\n });\n });\n },\n };\n\n default:\n throw new Error(`Unknown or unsupported dialog type: ${String(type)}.`);\n }\n}\n\n/**\n * Get the text of the notifications.\n *\n * @param page - The page to get the notifications from.\n * @param requestId - The ID of the request to get the notifications for.\n * @returns The text of the notifications, in order of appearance.\n */\nexport async function getNotifications(page: Page, requestId: string) {\n return await page.evaluate((id) => {\n return window.__SIMULATOR_API__.getNotifications(id);\n }, requestId);\n}\n"],"names":["DialogType","assert","create","SnapOptionsStruct","waitFor","getInterface","page","options","timeout","type","node","content","ui","evaluate","state","window","__SIMULATOR_API__","getState","simulation","message","Alert","ok","dispatch","payload","Confirmation","cancel","Prompt","value","Error","String","getNotifications","requestId","id"],"mappings":"AAAA,SAASA,UAAU,QAAQ,8BAA8B;AACzD,SAASC,MAAM,QAAQ,kBAAkB;AAEzC,SAASC,MAAM,QAAQ,cAAc;AAGrC,SAASC,iBAAiB,QAAQ,YAAY;AAC9C,SAASC,OAAO,QAAQ,aAAa;AAErC;;;;;;;;;CASC,GACD,OAAO,eAAeC,aACpBC,IAAU,EACVC,UAAuB,CAAC,CAAC;IAEzB,MAAM,EAAEC,OAAO,EAAE,GAAGN,OAAOK,SAASJ;IAEpC,MAAM,EAAEM,IAAI,EAAEC,MAAMC,OAAO,EAAE,GAAG,MAAMP,QACpC;QACE,MAAMQ,KAAK,MAAMN,KAAKO,QAAQ,CAAC;YAC7B,MAAMC,QAAQC,OAAOC,iBAAiB,CAACC,QAAQ;YAC/C,OAAOH,MAAMI,UAAU,CAACN,EAAE;QAC5B;QAEAX,OAAOW;QACP,OAAOA;IACT,GACA;QACEJ;QACAW,SAAS;IACX;IAGF,OAAQV;QACN,KAAKT,WAAWoB,KAAK;YACnB,OAAO;gBACLX,MAAM;gBACNE;gBAEAU,IAAI;oBACF,MAAMf,KAAKO,QAAQ,CAAC;wBAClBE,OAAOC,iBAAiB,CAACM,QAAQ,CAAC;4BAChCb,MAAM;4BACNc,SAAS;wBACX;oBACF;gBACF;YACF;QAEF,KAAKvB,WAAWwB,YAAY;YAC1B,OAAO;gBACLf,MAAM;gBACNE;gBAEAU,IAAI;oBACF,MAAMf,KAAKO,QAAQ,CAAC;wBAClBE,OAAOC,iBAAiB,CAACM,QAAQ,CAAC;4BAChCb,MAAM;4BACNc,SAAS;wBACX;oBACF;gBACF;gBAEAE,QAAQ;oBACN,MAAMnB,KAAKO,QAAQ,CAAC;wBAClBE,OAAOC,iBAAiB,CAACM,QAAQ,CAAC;4BAChCb,MAAM;4BACNc,SAAS;wBACX;oBACF;gBACF;YACF;QAEF,KAAKvB,WAAW0B,MAAM;YACpB,OAAO;gBACLjB,MAAM;gBACNE;gBAEAU,IAAI,OAAOM;oBACT,MAAMrB,KAAKO,QAAQ,CAAC,CAACU;wBACnBR,OAAOC,iBAAiB,CAACM,QAAQ,CAAC;4BAChCb,MAAM;4BACNc;wBACF;oBACF,GAAGI;gBACL;gBAEAF,QAAQ;oBACN,MAAMnB,KAAKO,QAAQ,CAAC;wBAClBE,OAAOC,iBAAiB,CAACM,QAAQ,CAAC;4BAChCb,MAAM;4BACNc,SAAS;wBACX;oBACF;gBACF;YACF;QAEF;YACE,MAAM,IAAIK,MAAM,CAAC,oCAAoC,EAAEC,OAAOpB,MAAM,CAAC,CAAC;IAC1E;AACF;AAEA;;;;;;CAMC,GACD,OAAO,eAAeqB,iBAAiBxB,IAAU,EAAEyB,SAAiB;IAClE,OAAO,MAAMzB,KAAKO,QAAQ,CAAC,CAACmB;QAC1B,OAAOjB,OAAOC,iBAAiB,CAACc,gBAAgB,CAACE;IACnD,GAAGD;AACL"}
1
+ {"version":3,"sources":["../../../src/internals/interface.ts"],"sourcesContent":["import { DialogType } from '@metamask/snaps-sdk';\nimport { assert } from '@metamask/utils';\nimport type { Page } from 'puppeteer';\nimport { create } from 'superstruct';\n\nimport type { SnapInterface, SnapOptions } from '../types';\nimport { SnapOptionsStruct } from './structs';\nimport { waitFor } from './wait-for';\n\n/**\n * Get the current snap user interface (i.e., dialog). This will throw an error\n * if the snap does not show a user interface within the timeout.\n *\n * @param page - The page to get the interface from.\n * @param options - The options to use.\n * @param options.timeout - The timeout in milliseconds to use. Defaults to\n * `1000`.\n * @returns The user interface object.\n */\nexport async function getInterface(\n page: Page,\n options: SnapOptions = {},\n): Promise<SnapInterface> {\n const { timeout } = create(options, SnapOptionsStruct);\n\n const { type, node: content } = await waitFor(\n async () => {\n const ui = await page.evaluate(() => {\n const state = window.__SIMULATOR_API__.getState();\n return state.simulation.ui;\n });\n\n assert(ui);\n return ui;\n },\n {\n timeout,\n message: 'Timed out waiting for snap interface to be shown.',\n },\n );\n\n switch (type) {\n case DialogType.Alert:\n return {\n type: 'alert',\n content,\n\n ok: async () => {\n await page.evaluate(() => {\n window.__SIMULATOR_API__.dispatch({\n type: 'simulation/resolveUserInterface',\n payload: null,\n });\n });\n },\n };\n\n case DialogType.Confirmation:\n return {\n type: 'confirmation',\n content,\n\n ok: async () => {\n await page.evaluate(() => {\n window.__SIMULATOR_API__.dispatch({\n type: 'simulation/resolveUserInterface',\n payload: true,\n });\n });\n },\n\n cancel: async () => {\n await page.evaluate(() => {\n window.__SIMULATOR_API__.dispatch({\n type: 'simulation/resolveUserInterface',\n payload: false,\n });\n });\n },\n };\n\n case DialogType.Prompt:\n return {\n type: 'prompt',\n content,\n\n ok: async (value) => {\n await page.evaluate((payload) => {\n window.__SIMULATOR_API__.dispatch({\n type: 'simulation/resolveUserInterface',\n payload,\n });\n }, value);\n },\n\n cancel: async () => {\n await page.evaluate(() => {\n window.__SIMULATOR_API__.dispatch({\n type: 'simulation/resolveUserInterface',\n payload: null,\n });\n });\n },\n };\n\n default:\n throw new Error(`Unknown or unsupported dialog type: ${String(type)}.`);\n }\n}\n\n/**\n * Get the text of the notifications.\n *\n * @param page - The page to get the notifications from.\n * @param requestId - The ID of the request to get the notifications for.\n * @returns The text of the notifications, in order of appearance.\n */\nexport async function getNotifications(page: Page, requestId: string) {\n return await page.evaluate((id) => {\n return window.__SIMULATOR_API__.getNotifications(id);\n }, requestId);\n}\n"],"names":["DialogType","assert","create","SnapOptionsStruct","waitFor","getInterface","page","options","timeout","type","node","content","ui","evaluate","state","window","__SIMULATOR_API__","getState","simulation","message","Alert","ok","dispatch","payload","Confirmation","cancel","Prompt","value","Error","String","getNotifications","requestId","id"],"mappings":"AAAA,SAASA,UAAU,QAAQ,sBAAsB;AACjD,SAASC,MAAM,QAAQ,kBAAkB;AAEzC,SAASC,MAAM,QAAQ,cAAc;AAGrC,SAASC,iBAAiB,QAAQ,YAAY;AAC9C,SAASC,OAAO,QAAQ,aAAa;AAErC;;;;;;;;;CASC,GACD,OAAO,eAAeC,aACpBC,IAAU,EACVC,UAAuB,CAAC,CAAC;IAEzB,MAAM,EAAEC,OAAO,EAAE,GAAGN,OAAOK,SAASJ;IAEpC,MAAM,EAAEM,IAAI,EAAEC,MAAMC,OAAO,EAAE,GAAG,MAAMP,QACpC;QACE,MAAMQ,KAAK,MAAMN,KAAKO,QAAQ,CAAC;YAC7B,MAAMC,QAAQC,OAAOC,iBAAiB,CAACC,QAAQ;YAC/C,OAAOH,MAAMI,UAAU,CAACN,EAAE;QAC5B;QAEAX,OAAOW;QACP,OAAOA;IACT,GACA;QACEJ;QACAW,SAAS;IACX;IAGF,OAAQV;QACN,KAAKT,WAAWoB,KAAK;YACnB,OAAO;gBACLX,MAAM;gBACNE;gBAEAU,IAAI;oBACF,MAAMf,KAAKO,QAAQ,CAAC;wBAClBE,OAAOC,iBAAiB,CAACM,QAAQ,CAAC;4BAChCb,MAAM;4BACNc,SAAS;wBACX;oBACF;gBACF;YACF;QAEF,KAAKvB,WAAWwB,YAAY;YAC1B,OAAO;gBACLf,MAAM;gBACNE;gBAEAU,IAAI;oBACF,MAAMf,KAAKO,QAAQ,CAAC;wBAClBE,OAAOC,iBAAiB,CAACM,QAAQ,CAAC;4BAChCb,MAAM;4BACNc,SAAS;wBACX;oBACF;gBACF;gBAEAE,QAAQ;oBACN,MAAMnB,KAAKO,QAAQ,CAAC;wBAClBE,OAAOC,iBAAiB,CAACM,QAAQ,CAAC;4BAChCb,MAAM;4BACNc,SAAS;wBACX;oBACF;gBACF;YACF;QAEF,KAAKvB,WAAW0B,MAAM;YACpB,OAAO;gBACLjB,MAAM;gBACNE;gBAEAU,IAAI,OAAOM;oBACT,MAAMrB,KAAKO,QAAQ,CAAC,CAACU;wBACnBR,OAAOC,iBAAiB,CAACM,QAAQ,CAAC;4BAChCb,MAAM;4BACNc;wBACF;oBACF,GAAGI;gBACL;gBAEAF,QAAQ;oBACN,MAAMnB,KAAKO,QAAQ,CAAC;wBAClBE,OAAOC,iBAAiB,CAACM,QAAQ,CAAC;4BAChCb,MAAM;4BACNc,SAAS;wBACX;oBACF;gBACF;YACF;QAEF;YACE,MAAM,IAAIK,MAAM,CAAC,oCAAoC,EAAEC,OAAOpB,MAAM,CAAC,CAAC;IAC1E;AACF;AAEA;;;;;;CAMC,GACD,OAAO,eAAeqB,iBAAiBxB,IAAU,EAAEyB,SAAiB;IAClE,OAAO,MAAMzB,KAAKO,QAAQ,CAAC,CAACmB;QAC1B,OAAOjB,OAAOC,iBAAiB,CAACc,gBAAgB,CAACE;IACnD,GAAGD;AACL"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/internals/request.ts"],"sourcesContent":["import type { Component } from '@metamask/snaps-ui';\nimport type { SnapRpcHookArgs } from '@metamask/snaps-utils';\nimport { HandlerType } from '@metamask/snaps-utils';\nimport {\n assert,\n createModuleLogger,\n hasProperty,\n isPlainObject,\n} from '@metamask/utils';\nimport { getDocument, queries } from 'pptr-testing-library';\nimport type { Page } from 'puppeteer';\nimport { create } from 'superstruct';\n\nimport type {\n CronjobOptions,\n RequestOptions,\n SnapRequest,\n SnapResponse,\n TransactionOptions,\n} from '../types';\nimport { getInterface, getNotifications } from './interface';\nimport { rootLogger } from './logger';\nimport { TransactionOptionsStruct } from './structs';\nimport { waitForResponse } from './wait-for';\n\nconst log = createModuleLogger(rootLogger, 'request');\n\n/**\n * Send a request to the snap.\n *\n * @param page - The page to send the request from.\n * @param args - The request arguments.\n * @returns The request ID.\n */\nasync function sendRequest(page: Page, args: SnapRpcHookArgs) {\n const document = await getDocument(page);\n const button = await queries.getByTestId(\n document,\n `navigation-${args.handler}`,\n );\n\n // Navigate to the request handler page.\n await button.click();\n\n return await page.evaluate((payload) => {\n window.__SIMULATOR_API__.dispatch({\n type: 'simulation/sendRequest',\n payload,\n });\n\n return window.__SIMULATOR_API__.getRequestId();\n }, args);\n}\n\n/**\n * Send a request to the snap.\n *\n * @param page - The page to send the request from.\n * @param options - The request options.\n * @param options.origin - The origin of the request. Defaults to `metamask.io`.\n * @param handler - The handler to use. Defaults to `onRpcRequest`.\n * @returns The response.\n */\nexport function request(\n page: Page,\n { origin = 'metamask.io', ...options }: RequestOptions,\n handler:\n | HandlerType.OnRpcRequest\n | HandlerType.OnCronjob = HandlerType.OnRpcRequest,\n) {\n const doRequest = async (): Promise<SnapResponse> => {\n const args: SnapRpcHookArgs = {\n origin,\n handler,\n request: {\n jsonrpc: '2.0',\n id: 1,\n ...options,\n },\n };\n\n log('Sending request %o', args);\n\n const promise = waitForResponse(page, handler);\n const id = await sendRequest(page, args);\n const response = await promise;\n\n log('Received response %o', response);\n\n const notifications = await getNotifications(page, id);\n\n return { id, response, notifications };\n };\n\n // This is a bit hacky, but it allows us to add the `getInterface` method\n // to the response promise.\n const response = doRequest() as SnapRequest;\n\n response.getInterface = async (getInterfaceOptions) => {\n return await getInterface(page, getInterfaceOptions);\n };\n\n return response;\n}\n\n/**\n * Send a transaction to the snap.\n *\n * @param page - The page to send the transaction from.\n * @param options - The transaction options.\n * @returns The response.\n */\nexport async function sendTransaction(\n page: Page,\n options: Partial<TransactionOptions>,\n) {\n const {\n origin: transactionOrigin,\n chainId,\n ...transaction\n } = create(options, TransactionOptionsStruct);\n\n const args: SnapRpcHookArgs = {\n origin: '',\n handler: HandlerType.OnTransaction,\n request: {\n jsonrpc: '2.0',\n method: '',\n params: {\n chainId,\n transaction,\n transactionOrigin,\n },\n },\n };\n\n log('Sending transaction %o', args);\n\n const promise = waitForResponse(page, HandlerType.OnTransaction);\n const id = await sendRequest(page, args);\n const response = await promise;\n\n log('Received response %o', response);\n\n if (hasProperty(response, 'error')) {\n return { id, response, notifications: [] };\n }\n\n assert(isPlainObject(response.result));\n assert(hasProperty(response.result, 'content'));\n\n return {\n id,\n response,\n notifications: [],\n content: response.result.content as Component,\n };\n}\n\n/**\n * Run a cronjob.\n *\n * @param page - The page to run the cronjob from.\n * @param options - The request options.\n * @returns The response.\n */\nexport function runCronjob(page: Page, options: CronjobOptions) {\n return request(page, options, HandlerType.OnCronjob);\n}\n"],"names":["HandlerType","assert","createModuleLogger","hasProperty","isPlainObject","getDocument","queries","create","getInterface","getNotifications","rootLogger","TransactionOptionsStruct","waitForResponse","log","sendRequest","page","args","document","button","getByTestId","handler","click","evaluate","payload","window","__SIMULATOR_API__","dispatch","type","getRequestId","request","origin","options","OnRpcRequest","doRequest","jsonrpc","id","promise","response","notifications","getInterfaceOptions","sendTransaction","transactionOrigin","chainId","transaction","OnTransaction","method","params","result","content","runCronjob","OnCronjob"],"mappings":"AAEA,SAASA,WAAW,QAAQ,wBAAwB;AACpD,SACEC,MAAM,EACNC,kBAAkB,EAClBC,WAAW,EACXC,aAAa,QACR,kBAAkB;AACzB,SAASC,WAAW,EAAEC,OAAO,QAAQ,uBAAuB;AAE5D,SAASC,MAAM,QAAQ,cAAc;AASrC,SAASC,YAAY,EAAEC,gBAAgB,QAAQ,cAAc;AAC7D,SAASC,UAAU,QAAQ,WAAW;AACtC,SAASC,wBAAwB,QAAQ,YAAY;AACrD,SAASC,eAAe,QAAQ,aAAa;AAE7C,MAAMC,MAAMX,mBAAmBQ,YAAY;AAE3C;;;;;;CAMC,GACD,eAAeI,YAAYC,IAAU,EAAEC,IAAqB;IAC1D,MAAMC,WAAW,MAAMZ,YAAYU;IACnC,MAAMG,SAAS,MAAMZ,QAAQa,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BACAF;YACF;QACF;IACF;IAEA5B,IAAI,0BAA0BG;IAE9B,MAAMoB,UAAUxB,gBAAgBG,MAAMf,YAAY4C,aAAa;IAC/D,MAAMT,KAAK,MAAMrB,YAAYC,MAAMC;IACnC,MAAMqB,WAAW,MAAMD;IAEvBvB,IAAI,wBAAwBwB;IAE5B,IAAIlC,YAAYkC,UAAU,UAAU;QAClC,OAAO;YAAEF;YAAIE;YAAUC,eAAe,EAAE;QAAC;IAC3C;IAEArC,OAAOG,cAAciC,SAASU,MAAM;IACpC9C,OAAOE,YAAYkC,SAASU,MAAM,EAAE;IAEpC,OAAO;QACLZ;QACAE;QACAC,eAAe,EAAE;QACjBU,SAASX,SAASU,MAAM,CAACC,OAAO;IAClC;AACF;AAEA;;;;;;CAMC,GACD,OAAO,SAASC,WAAWlC,IAAU,EAAEgB,OAAuB;IAC5D,OAAOF,QAAQd,MAAMgB,SAAS/B,YAAYkD,SAAS;AACrD"}
1
+ {"version":3,"sources":["../../../src/internals/request.ts"],"sourcesContent":["import type { Component } from '@metamask/snaps-sdk';\nimport type { SnapRpcHookArgs } from '@metamask/snaps-utils';\nimport { HandlerType } from '@metamask/snaps-utils';\nimport {\n assert,\n createModuleLogger,\n hasProperty,\n isPlainObject,\n} from '@metamask/utils';\nimport { getDocument, queries } from 'pptr-testing-library';\nimport type { Page } from 'puppeteer';\nimport { create } from 'superstruct';\n\nimport type {\n CronjobOptions,\n RequestOptions,\n SnapRequest,\n SnapResponse,\n TransactionOptions,\n} from '../types';\nimport { getInterface, getNotifications } from './interface';\nimport { rootLogger } from './logger';\nimport { TransactionOptionsStruct } from './structs';\nimport { waitForResponse } from './wait-for';\n\nconst log = createModuleLogger(rootLogger, 'request');\n\n/**\n * Send a request to the snap.\n *\n * @param page - The page to send the request from.\n * @param args - The request arguments.\n * @returns The request ID.\n */\nasync function sendRequest(page: Page, args: SnapRpcHookArgs) {\n const document = await getDocument(page);\n const button = await queries.getByTestId(\n document,\n `navigation-${args.handler}`,\n );\n\n // Navigate to the request handler page.\n await button.click();\n\n return await page.evaluate((payload) => {\n window.__SIMULATOR_API__.dispatch({\n type: 'simulation/sendRequest',\n payload,\n });\n\n return window.__SIMULATOR_API__.getRequestId();\n }, args);\n}\n\n/**\n * Send a request to the snap.\n *\n * @param page - The page to send the request from.\n * @param options - The request options.\n * @param options.origin - The origin of the request. Defaults to `metamask.io`.\n * @param handler - The handler to use. Defaults to `onRpcRequest`.\n * @returns The response.\n */\nexport function request(\n page: Page,\n { origin = 'metamask.io', ...options }: RequestOptions,\n handler:\n | HandlerType.OnRpcRequest\n | HandlerType.OnCronjob = HandlerType.OnRpcRequest,\n) {\n const doRequest = async (): Promise<SnapResponse> => {\n const args: SnapRpcHookArgs = {\n origin,\n handler,\n request: {\n jsonrpc: '2.0',\n id: 1,\n ...options,\n },\n };\n\n log('Sending request %o', args);\n\n const promise = waitForResponse(page, handler);\n const id = await sendRequest(page, args);\n const response = await promise;\n\n log('Received response %o', response);\n\n const notifications = await getNotifications(page, id);\n\n return { id, response, notifications };\n };\n\n // This is a bit hacky, but it allows us to add the `getInterface` method\n // to the response promise.\n const response = doRequest() as SnapRequest;\n\n response.getInterface = async (getInterfaceOptions) => {\n return await getInterface(page, getInterfaceOptions);\n };\n\n return response;\n}\n\n/**\n * Send a transaction to the snap.\n *\n * @param page - The page to send the transaction from.\n * @param options - The transaction options.\n * @returns The response.\n */\nexport async function sendTransaction(\n page: Page,\n options: Partial<TransactionOptions>,\n) {\n const {\n origin: transactionOrigin,\n chainId,\n ...transaction\n } = create(options, TransactionOptionsStruct);\n\n const args: SnapRpcHookArgs = {\n origin: '',\n handler: HandlerType.OnTransaction,\n request: {\n jsonrpc: '2.0',\n method: '',\n params: {\n chainId,\n transaction,\n transactionOrigin,\n },\n },\n };\n\n log('Sending transaction %o', args);\n\n const promise = waitForResponse(page, HandlerType.OnTransaction);\n const id = await sendRequest(page, args);\n const response = await promise;\n\n log('Received response %o', response);\n\n if (hasProperty(response, 'error')) {\n return { id, response, notifications: [] };\n }\n\n assert(isPlainObject(response.result));\n assert(hasProperty(response.result, 'content'));\n\n return {\n id,\n response,\n notifications: [],\n content: response.result.content as Component,\n };\n}\n\n/**\n * Run a cronjob.\n *\n * @param page - The page to run the cronjob from.\n * @param options - The request options.\n * @returns The response.\n */\nexport function runCronjob(page: Page, options: CronjobOptions) {\n return request(page, options, HandlerType.OnCronjob);\n}\n"],"names":["HandlerType","assert","createModuleLogger","hasProperty","isPlainObject","getDocument","queries","create","getInterface","getNotifications","rootLogger","TransactionOptionsStruct","waitForResponse","log","sendRequest","page","args","document","button","getByTestId","handler","click","evaluate","payload","window","__SIMULATOR_API__","dispatch","type","getRequestId","request","origin","options","OnRpcRequest","doRequest","jsonrpc","id","promise","response","notifications","getInterfaceOptions","sendTransaction","transactionOrigin","chainId","transaction","OnTransaction","method","params","result","content","runCronjob","OnCronjob"],"mappings":"AAEA,SAASA,WAAW,QAAQ,wBAAwB;AACpD,SACEC,MAAM,EACNC,kBAAkB,EAClBC,WAAW,EACXC,aAAa,QACR,kBAAkB;AACzB,SAASC,WAAW,EAAEC,OAAO,QAAQ,uBAAuB;AAE5D,SAASC,MAAM,QAAQ,cAAc;AASrC,SAASC,YAAY,EAAEC,gBAAgB,QAAQ,cAAc;AAC7D,SAASC,UAAU,QAAQ,WAAW;AACtC,SAASC,wBAAwB,QAAQ,YAAY;AACrD,SAASC,eAAe,QAAQ,aAAa;AAE7C,MAAMC,MAAMX,mBAAmBQ,YAAY;AAE3C;;;;;;CAMC,GACD,eAAeI,YAAYC,IAAU,EAAEC,IAAqB;IAC1D,MAAMC,WAAW,MAAMZ,YAAYU;IACnC,MAAMG,SAAS,MAAMZ,QAAQa,WAAW,CACtCF,UACA,CAAC,WAAW,EAAED,KAAKI,OAAO,CAAC,CAAC;IAG9B,wCAAwC;IACxC,MAAMF,OAAOG,KAAK;IAElB,OAAO,MAAMN,KAAKO,QAAQ,CAAC,CAACC;QAC1BC,OAAOC,iBAAiB,CAACC,QAAQ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,wBAAwBwB;IAE5B,IAAIlC,YAAYkC,UAAU,UAAU;QAClC,OAAO;YAAEF;YAAIE;YAAUC,eAAe,EAAE;QAAC;IAC3C;IAEArC,OAAOG,cAAciC,SAASU,MAAM;IACpC9C,OAAOE,YAAYkC,SAASU,MAAM,EAAE;IAEpC,OAAO;QACLZ;QACAE;QACAC,eAAe,EAAE;QACjBU,SAASX,SAASU,MAAM,CAACC,OAAO;IAClC;AACF;AAEA;;;;;;CAMC,GACD,OAAO,SAASC,WAAWlC,IAAU,EAAEgB,OAAuB;IAC5D,OAAOF,QAAQd,MAAMgB,SAAS/B,YAAYkD,SAAS;AACrD"}
@@ -1,5 +1,4 @@
1
- import { NotificationType } from '@metamask/snaps-rpc-methods';
2
- import { ComponentStruct } from '@metamask/snaps-ui';
1
+ import { NotificationType, ComponentStruct } from '@metamask/snaps-sdk';
3
2
  import { enumValue } from '@metamask/snaps-utils';
4
3
  import { bytesToHex, JsonStruct, StrictHexStruct, valueToBytes } from '@metamask/utils';
5
4
  import { randomBytes } from 'crypto';
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/internals/structs.ts"],"sourcesContent":["import { NotificationType } from '@metamask/snaps-rpc-methods';\nimport { ComponentStruct } from '@metamask/snaps-ui';\nimport { enumValue } from '@metamask/snaps-utils';\nimport {\n bytesToHex,\n JsonStruct,\n StrictHexStruct,\n valueToBytes,\n} from '@metamask/utils';\nimport { randomBytes } from 'crypto';\nimport {\n array,\n assign,\n bigint,\n coerce,\n defaulted,\n instance,\n literal,\n number,\n object,\n optional,\n string,\n type,\n union,\n} from 'superstruct';\n\n// TODO: Export this from `@metamask/utils` instead.\nconst BytesLikeStruct = union([\n bigint(),\n number(),\n string(),\n instance(Uint8Array),\n]);\n\nexport const TransactionOptionsStruct = object({\n /**\n * The CAIP-2 chain ID to send the transaction on. Defaults to `eip155:1`.\n */\n chainId: defaulted(string(), 'eip155:1'),\n\n /**\n * The origin to send the transaction from. Defaults to `metamask.io`.\n */\n origin: defaulted(string(), 'metamask.io'),\n\n /**\n * The address to send the transaction from. Defaults to a randomly generated\n * address.\n */\n // TODO: Move this coercer to `@metamask/utils`.\n from: coerce(StrictHexStruct, optional(BytesLikeStruct), (value) => {\n if (value) {\n return valueToBytes(value);\n }\n\n return bytesToHex(randomBytes(20));\n }),\n\n /**\n * The address to send the transaction to. Defaults to a randomly generated\n * address.\n */\n // TODO: Move this coercer to `@metamask/utils`.\n to: coerce(StrictHexStruct, optional(BytesLikeStruct), (value) => {\n if (value) {\n return valueToBytes(value);\n }\n\n return bytesToHex(randomBytes(20));\n }),\n\n /**\n * The value to send with the transaction. The value may be specified as a\n * `number`, `bigint`, `string`, or `Uint8Array`. Defaults to `0`.\n */\n value: defaulted(\n coerce(StrictHexStruct, BytesLikeStruct, (value) =>\n bytesToHex(valueToBytes(value)),\n ),\n '0x0',\n ),\n\n /**\n * The gas limit to use for the transaction. The gas limit may be specified\n * as a `number`, `bigint`, `string`, or `Uint8Array`. Defaults to `21_000`.\n */\n gasLimit: defaulted(\n coerce(StrictHexStruct, BytesLikeStruct, (value) =>\n bytesToHex(valueToBytes(value)),\n ),\n valueToBytes(21_000),\n ),\n\n /**\n * The max fee per gas (in Wei) to use for the transaction. The max fee per\n * gas may be specified as a `number`, `bigint`, `string`, or `Uint8Array`.\n * Defaults to `1`.\n */\n maxFeePerGas: defaulted(\n coerce(StrictHexStruct, BytesLikeStruct, (value) =>\n bytesToHex(valueToBytes(value)),\n ),\n valueToBytes(1),\n ),\n\n /**\n * The max priority fee per gas (in Wei) to use for the transaction. The max\n * priority fee per gas may be specified as a `number`, `bigint`, `string`,\n * or `Uint8Array`. Defaults to `1`.\n */\n maxPriorityFeePerGas: defaulted(\n coerce(StrictHexStruct, BytesLikeStruct, (value) =>\n bytesToHex(valueToBytes(value)),\n ),\n valueToBytes(1),\n ),\n\n /**\n * The nonce to use for the transaction. The nonce may be specified as a\n * `number`, `bigint`, `string`, or `Uint8Array`. Defaults to `0`.\n */\n nonce: defaulted(\n coerce(StrictHexStruct, BytesLikeStruct, (value) =>\n bytesToHex(valueToBytes(value)),\n ),\n valueToBytes(0),\n ),\n\n /**\n * The data to send with the transaction. The data may be specified as a\n * `number`, `bigint`, `string`, or `Uint8Array`. Defaults to `0x`.\n */\n data: defaulted(\n coerce(union([StrictHexStruct, literal('0x')]), BytesLikeStruct, (value) =>\n bytesToHex(valueToBytes(value)),\n ),\n '0x',\n ),\n});\n\nexport const SnapOptionsStruct = object({\n /**\n * The timeout in milliseconds to use for requests to the snap. Defaults to\n * `1000`.\n */\n timeout: defaulted(optional(number()), 1000),\n});\n\nexport const InterfaceStruct = type({\n content: optional(ComponentStruct),\n});\n\nexport const SnapResponseStruct = assign(\n InterfaceStruct,\n object({\n id: string(),\n\n response: union([\n object({\n result: JsonStruct,\n }),\n object({\n error: JsonStruct,\n }),\n ]),\n\n notifications: array(\n object({\n id: string(),\n message: string(),\n type: union([\n enumValue(NotificationType.InApp),\n enumValue(NotificationType.Native),\n ]),\n }),\n ),\n }),\n);\n"],"names":["NotificationType","ComponentStruct","enumValue","bytesToHex","JsonStruct","StrictHexStruct","valueToBytes","randomBytes","array","assign","bigint","coerce","defaulted","instance","literal","number","object","optional","string","type","union","BytesLikeStruct","Uint8Array","TransactionOptionsStruct","chainId","origin","from","value","to","gasLimit","maxFeePerGas","maxPriorityFeePerGas","nonce","data","SnapOptionsStruct","timeout","InterfaceStruct","content","SnapResponseStruct","id","response","result","error","notifications","message","InApp","Native"],"mappings":"AAAA,SAASA,gBAAgB,QAAQ,8BAA8B;AAC/D,SAASC,eAAe,QAAQ,qBAAqB;AACrD,SAASC,SAAS,QAAQ,wBAAwB;AAClD,SACEC,UAAU,EACVC,UAAU,EACVC,eAAe,EACfC,YAAY,QACP,kBAAkB;AACzB,SAASC,WAAW,QAAQ,SAAS;AACrC,SACEC,KAAK,EACLC,MAAM,EACNC,MAAM,EACNC,MAAM,EACNC,SAAS,EACTC,QAAQ,EACRC,OAAO,EACPC,MAAM,EACNC,M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qB,UAE1B;AAEJ,GAAG;AAEH,OAAO,MAAMO,oBAAoBlB,OAAO;IACtC;;;GAGC,GACDmB,SAASvB,UAAUK,SAASF,WAAW;AACzC,GAAG;AAEH,OAAO,MAAMqB,kBAAkBjB,KAAK;IAClCkB,SAASpB,SAAShB;AACpB,GAAG;AAEH,OAAO,MAAMqC,qBAAqB7B,OAChC2B,iBACApB,OAAO;IACLuB,IAAIrB;IAEJsB,UAAUpB,MAAM;QACdJ,OAAO;YACLyB,QAAQrC;QACV;QACAY,OAAO;YACL0B,OAAOtC;QACT;KACD;IAEDuC,eAAenC,MACbQ,OAAO;QACLuB,IAAIrB;QACJ0B,SAAS1B;QACTC,MAAMC,MAAM;YACVlB,UAAUF,iBAAiB6C,KAAK;YAChC3C,UAAUF,iBAAiB8C,MAAM;SAClC;IACH;AAEJ,IACA"}
1
+ {"version":3,"sources":["../../../src/internals/structs.ts"],"sourcesContent":["import { NotificationType, ComponentStruct } from '@metamask/snaps-sdk';\nimport { enumValue } from '@metamask/snaps-utils';\nimport {\n bytesToHex,\n JsonStruct,\n StrictHexStruct,\n valueToBytes,\n} from '@metamask/utils';\nimport { randomBytes } from 'crypto';\nimport {\n array,\n assign,\n bigint,\n coerce,\n defaulted,\n instance,\n literal,\n number,\n object,\n optional,\n string,\n type,\n union,\n} from 'superstruct';\n\n// TODO: Export this from `@metamask/utils` instead.\nconst BytesLikeStruct = union([\n bigint(),\n number(),\n string(),\n instance(Uint8Array),\n]);\n\nexport const TransactionOptionsStruct = object({\n /**\n * The CAIP-2 chain ID to send the transaction on. Defaults to `eip155:1`.\n */\n chainId: defaulted(string(), 'eip155:1'),\n\n /**\n * The origin to send the transaction from. Defaults to `metamask.io`.\n */\n origin: defaulted(string(), 'metamask.io'),\n\n /**\n * The address to send the transaction from. Defaults to a randomly generated\n * address.\n */\n // TODO: Move this coercer to `@metamask/utils`.\n from: coerce(StrictHexStruct, optional(BytesLikeStruct), (value) => {\n if (value) {\n return valueToBytes(value);\n }\n\n return bytesToHex(randomBytes(20));\n }),\n\n /**\n * The address to send the transaction to. Defaults to a randomly generated\n * address.\n */\n // TODO: Move this coercer to `@metamask/utils`.\n to: coerce(StrictHexStruct, optional(BytesLikeStruct), (value) => {\n if (value) {\n return valueToBytes(value);\n }\n\n return bytesToHex(randomBytes(20));\n }),\n\n /**\n * The value to send with the transaction. The value may be specified as a\n * `number`, `bigint`, `string`, or `Uint8Array`. Defaults to `0`.\n */\n value: defaulted(\n coerce(StrictHexStruct, BytesLikeStruct, (value) =>\n bytesToHex(valueToBytes(value)),\n ),\n '0x0',\n ),\n\n /**\n * The gas limit to use for the transaction. The gas limit may be specified\n * as a `number`, `bigint`, `string`, or `Uint8Array`. Defaults to `21_000`.\n */\n gasLimit: defaulted(\n coerce(StrictHexStruct, BytesLikeStruct, (value) =>\n bytesToHex(valueToBytes(value)),\n ),\n valueToBytes(21_000),\n ),\n\n /**\n * The max fee per gas (in Wei) to use for the transaction. The max fee per\n * gas may be specified as a `number`, `bigint`, `string`, or `Uint8Array`.\n * Defaults to `1`.\n */\n maxFeePerGas: defaulted(\n coerce(StrictHexStruct, BytesLikeStruct, (value) =>\n bytesToHex(valueToBytes(value)),\n ),\n valueToBytes(1),\n ),\n\n /**\n * The max priority fee per gas (in Wei) to use for the transaction. The max\n * priority fee per gas may be specified as a `number`, `bigint`, `string`,\n * or `Uint8Array`. Defaults to `1`.\n */\n maxPriorityFeePerGas: defaulted(\n coerce(StrictHexStruct, BytesLikeStruct, (value) =>\n bytesToHex(valueToBytes(value)),\n ),\n valueToBytes(1),\n ),\n\n /**\n * The nonce to use for the transaction. The nonce may be specified as a\n * `number`, `bigint`, `string`, or `Uint8Array`. Defaults to `0`.\n */\n nonce: defaulted(\n coerce(StrictHexStruct, BytesLikeStruct, (value) =>\n bytesToHex(valueToBytes(value)),\n ),\n valueToBytes(0),\n ),\n\n /**\n * The data to send with the transaction. The data may be specified as a\n * `number`, `bigint`, `string`, or `Uint8Array`. Defaults to `0x`.\n */\n data: defaulted(\n coerce(union([StrictHexStruct, literal('0x')]), BytesLikeStruct, (value) =>\n bytesToHex(valueToBytes(value)),\n ),\n '0x',\n ),\n});\n\nexport const SnapOptionsStruct = object({\n /**\n * The timeout in milliseconds to use for requests to the snap. Defaults to\n * `1000`.\n */\n timeout: defaulted(optional(number()), 1000),\n});\n\nexport const InterfaceStruct = type({\n content: optional(ComponentStruct),\n});\n\nexport const SnapResponseStruct = assign(\n InterfaceStruct,\n object({\n id: string(),\n\n response: union([\n object({\n result: JsonStruct,\n }),\n object({\n error: JsonStruct,\n }),\n ]),\n\n notifications: array(\n object({\n id: string(),\n message: string(),\n type: union([\n enumValue(NotificationType.InApp),\n enumValue(NotificationType.Native),\n ]),\n }),\n ),\n }),\n);\n"],"names":["NotificationType","ComponentStruct","enumValue","bytesToHex","JsonStruct","StrictHexStruct","valueToBytes","randomBytes","array","assign","bigint","coerce","defaulted","instance","literal","number","object","optional","string","type","union","BytesLikeStruct","Uint8Array","TransactionOptionsStruct","chainId","origin","from","value","to","gasLimit","maxFeePerGas","maxPriorityFeePerGas","nonce","data","SnapOptionsStruct","timeout","InterfaceStruct","content","SnapResponseStruct","id","response","result","error","notifications","message","InApp","Native"],"mappings":"AAAA,SAASA,gBAAgB,EAAEC,eAAe,QAAQ,sBAAsB;AACxE,SAASC,SAAS,QAAQ,wBAAwB;AAClD,SACEC,UAAU,EACVC,UAAU,EACVC,eAAe,EACfC,YAAY,QACP,kBAAkB;AACzB,SAASC,WAAW,QAAQ,SAAS;AACrC,SACEC,KAAK,EACLC,MAAM,EACNC,MAAM,EACNC,MAAM,EACNC,SAAS,EACTC,QAAQ,EACRC,OAAO,EACPC,MAAM,EACNC,MAAM,EACNC,QAAQ,EACRC,MAAM,EACNC,IAAI,EACJC,KAAK,QACA,cAAc;AAErB,oDAAoD;AACpD,MAAMC,kBAAkBD,MAAM;IAC5BV;IACAK;IACAG;IACAL,SAASS;CACV;AAED,OAAO,MAAMC,2BAA2BP,OAAO;IAC7C;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GAAG;AAEH,OAAO,MAAMqC,qBAAqB7B,OAChC2B,iBACApB,OAAO;IACLuB,IAAIrB;IAEJsB,UAAUpB,MAAM;QACdJ,OAAO;YACLyB,QAAQrC;QACV;QACAY,OAAO;YACL0B,OAAOtC;QACT;KACD;IAEDuC,eAAenC,MACbQ,OAAO;QACLuB,IAAIrB;QACJ0B,SAAS1B;QACTC,MAAMC,MAAM;YACVlB,UAAUF,iBAAiB6C,KAAK;YAChC3C,UAAUF,iBAAiB8C,MAAM;SAClC;IACH;AAEJ,IACA"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/internals/types.ts"],"sourcesContent":["import type { NotificationType } from '@metamask/snaps-rpc-methods';\nimport type { ApplicationState, Dispatch } from '@metamask/snaps-simulator';\nimport type { EnumToUnion } from '@metamask/snaps-utils';\n\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/consistent-type-definitions\n interface Window {\n // This API is injected into the page by the simulator. It allows us to\n // dispatch actions to the simulator, and read the state directly from the\n // Redux store.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n __SIMULATOR_API__: {\n dispatch: Dispatch;\n subscribe: (listener: () => void) => () => void;\n getState: () => ApplicationState;\n getRequestId: () => string;\n getNotifications: (requestId: string) => {\n id: string;\n message: string;\n type: EnumToUnion<NotificationType>;\n }[];\n };\n }\n}\n\nexport {};\n"],"names":[],"mappings":"AAAA,WAyBU"}
1
+ {"version":3,"sources":["../../../src/internals/types.ts"],"sourcesContent":["import type { NotificationType, EnumToUnion } from '@metamask/snaps-sdk';\nimport type { ApplicationState, Dispatch } from '@metamask/snaps-simulator';\n\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/consistent-type-definitions\n interface Window {\n // This API is injected into the page by the simulator. It allows us to\n // dispatch actions to the simulator, and read the state directly from the\n // Redux store.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n __SIMULATOR_API__: {\n dispatch: Dispatch;\n subscribe: (listener: () => void) => () => void;\n getState: () => ApplicationState;\n getRequestId: () => string;\n getNotifications: (requestId: string) => {\n id: string;\n message: string;\n type: EnumToUnion<NotificationType>;\n }[];\n };\n }\n}\n\nexport {};\n"],"names":[],"mappings":"AAAA,WAwBU"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/matchers.ts"],"sourcesContent":["/* eslint-disable no-invalid-this */\n\n// Note: Because this file imports from `@jest/globals`, it can only be used in\n// a Jest environment. This is why it's not exported from the index file.\n\nimport type { MatcherFunction } from '@jest/expect';\nimport { expect } from '@jest/globals';\nimport type { NotificationType } from '@metamask/snaps-rpc-methods';\nimport type { Component } from '@metamask/snaps-ui';\nimport type { EnumToUnion } from '@metamask/snaps-utils';\nimport type { Json } from '@metamask/utils';\nimport { hasProperty } from '@metamask/utils';\nimport type { MatcherHintOptions } from 'jest-matcher-utils';\nimport {\n diff,\n matcherErrorMessage,\n matcherHint,\n printReceived,\n printWithType,\n RECEIVED_COLOR,\n} from 'jest-matcher-utils';\nimport { is } from 'superstruct';\n\nimport { InterfaceStruct, SnapResponseStruct } from './internals';\nimport type { SnapResponse } from './types';\n\n/**\n * Ensure that the actual value is a response from the `request` function.\n *\n * @param actual - The actual value.\n * @param matcherName - The name of the matcher.\n * @param options - The matcher options.\n */\nfunction assertActualIsSnapResponse(\n actual: unknown,\n matcherName: string,\n options?: MatcherHintOptions,\n): asserts actual is SnapResponse {\n if (!is(actual, SnapResponseStruct)) {\n throw new Error(\n matcherErrorMessage(\n matcherHint(matcherName, undefined, undefined, options),\n `${RECEIVED_COLOR(\n 'received',\n )} value must be a response from the \\`request\\` function`,\n printWithType('Received', actual, printReceived),\n ),\n );\n }\n}\n\n/**\n * Ensure that the actual value is a response from the `request` function, and\n * that it has a `ui` property.\n *\n * @param actual - The actual value.\n * @param matcherName - The name of the matcher.\n * @param options - The matcher options.\n */\nfunction assertHasInterface(\n actual: unknown,\n matcherName: string,\n options?: MatcherHintOptions,\n): asserts actual is { content: Component } {\n if (!is(actual, InterfaceStruct) || !actual.content) {\n throw new Error(\n matcherErrorMessage(\n matcherHint(matcherName, undefined, undefined, options),\n `${RECEIVED_COLOR('received')} value must have a \\`content\\` property`,\n printWithType('Received', actual, printReceived),\n ),\n );\n }\n}\n\n/**\n * Check if a JSON-RPC response matches the expected value. This matcher is\n * intended to be used with the `expect` global.\n *\n * @param actual - The actual response.\n * @param expected - The expected response.\n * @returns The status and message.\n */\nexport const toRespondWith: MatcherFunction<[expected: Json]> = function (\n actual,\n expected,\n) {\n assertActualIsSnapResponse(actual, 'toRespondWith');\n\n const { response } = actual;\n if (hasProperty(response, 'error')) {\n const message = () =>\n `${this.utils.matcherHint('.toRespondWith')}\\n\\n` +\n `Expected response: ${this.utils.printExpected(expected)}\\n` +\n `Received error: ${this.utils.printReceived(response.error)}`;\n\n return { message, pass: false };\n }\n\n const pass = this.equals(response.result, expected);\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRespondWith')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.result)}`\n : () =>\n `${this.utils.matcherHint('.toRespondWith')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.result)}`;\n\n return { message, pass };\n};\n\nexport const toRespondWithError: MatcherFunction<[expected: Json]> = function (\n actual,\n expected,\n) {\n assertActualIsSnapResponse(actual, 'toRespondWithError');\n\n const { response } = actual;\n if (hasProperty(response, 'result')) {\n const message = () =>\n `${this.utils.matcherHint('.toRespondWithError')}\\n\\n` +\n `Expected error: ${this.utils.printExpected(expected)}\\n` +\n `Received result: ${this.utils.printReceived(response.result)}`;\n\n return { message, pass: false };\n }\n\n const pass = this.equals(response.error, expected);\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRespondWithError')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.error)}`\n : () =>\n `${this.utils.matcherHint('.toRespondWithError')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.error)}`;\n\n return { message, pass };\n};\n\n/**\n * Check if the snap sent a notification with the expected message. This matcher\n * is intended to be used with the `expect` global.\n *\n * @param actual - The actual response.\n * @param expected - The expected notification message.\n * @param type - The expected notification type.\n * @returns The status and message.\n */\nexport const toSendNotification: MatcherFunction<\n [expected: string, type?: EnumToUnion<NotificationType> | undefined]\n> = async function (actual, expected, type) {\n assertActualIsSnapResponse(actual, 'toSendNotification');\n\n const { notifications } = actual;\n const pass = notifications.some(\n (notification) =>\n this.equals(notification.message, expected) &&\n (type === undefined || notification.type === type),\n );\n\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toSendNotification')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Expected type: ${this.utils.printExpected(type)}\\n` +\n `Received: ${this.utils.printReceived(notifications)}`\n : () =>\n `${this.utils.matcherHint('.toSendNotification')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Expected type: ${this.utils.printExpected(type)}\\n` +\n `Received: ${this.utils.printReceived(notifications)}`;\n\n return { message, pass };\n};\n\nexport const toRender: MatcherFunction<[expected: Component]> = function (\n actual,\n expected,\n) {\n assertHasInterface(actual, 'toRender');\n\n const { content } = actual;\n const pass = this.equals(content, expected);\n\n const difference = diff(expected, content);\n\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toShowInterface')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(content)}` +\n `${difference ? `\\n\\nDifference:\\n\\n${difference}` : ''}`\n : () =>\n `${this.utils.matcherHint('.toShowInterface')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(content)}` +\n `${difference ? `\\n\\nDifference:\\n\\n${difference}` : ''}`;\n\n return { message, pass };\n};\n\nexpect.extend({\n toRespondWith,\n toRespondWithError,\n toSendNotification,\n toRender,\n});\n"],"names":["expect","hasProperty","diff","matcherErrorMessage","matcherHint","printReceived","printWithType","RECEIVED_COLOR","is","InterfaceStruct","SnapResponseStruct","assertActualIsSnapResponse","actual","matcherName","options","Error","undefined","assertHasInterface","content","toRespondWith","expected","response","message","utils","printExpected","error","pass","equals","result","toRespondWithError","toSendNotification","type","notifications","some","notification","toRender","difference","extend"],"mappings":"AAAA,kCAAkC,GAElC,+EAA+E;AAC/E,yEAAyE;AAGzE,SAASA,MAAM,QAAQ,gBAAgB;AAKvC,SAASC,WAAW,QAAQ,kBAAkB;AAE9C,SACEC,IAAI,EACJC,mBAAmB,EACnBC,WAAW,EACXC,aAAa,EACbC,aAAa,EACbC,cAAc,QACT,qBAAqB;AAC5B,SAASC,EAAE,QAAQ,cAAc;AAEjC,SAASC,eAAe,EAAEC,kBAAkB,QAAQ,cAAc;AAGlE;;;;;;CAMC,GACD,SAASC,2BACPC,MAAe,EACfC,WAAmB,EACnBC,OAA4B;IAE5B,IAAI,CAACN,GAAGI,QAAQF,qBAAqB;QACnC,MAAM,IAAIK,MACRZ,oBACEC,YAAYS,aAAaG,WAAWA,WAAWF,UAC/C,CAAC,EAAEP,eACD,YACA,uDAAuD,CAAC,EAC1DD,cAAc,YAAYM,QAAQP;IAGxC;AACF;AAEA;;;;;;;CAOC,GACD,SAASY,mBACPL,MAAe,EACfC,WAAmB,EACnBC,OAA4B;IAE5B,IAAI,CAACN,GAAGI,QAAQH,oBAAoB,CAACG,OAAOM,OAAO,EAAE;QACnD,MAAM,IAAIH,MACRZ,oBACEC,YAAYS,aAAaG,WAAWA,WAAWF,UAC/C,CAAC,EAAEP,eAAe,YAAY,uCAAuC,CAAC,EACtED,cAAc,YAAYM,QAAQP;IAGxC;AACF;AAEA;;;;;;;CAOC,GACD,OAAO,MAAMc,gBAAmD,SAC9DP,MAAM,EACNQ,QAAQ;IAERT,2BAA2BC,QAAQ;IAEnC,MAAM,EAAES,QAAQ,EAAE,GAAGT;IACrB,IAAIX,YAAYoB,UAAU,UAAU;QAClC,MAAMC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J,UAAU,EAAE,CAAC,GACnD,CAAC,UAAU,EAAE,IAAI,CAACG,KAAK,CAAClB,aAAa,CAACa,SAAS,CAAC,GAChD,CAAC,EAAEkB,aAAa,CAAC,mBAAmB,EAAEA,WAAW,CAAC,GAAG,GAAG,CAAC;IAE/D,OAAO;QAAEd;QAASI;IAAK;AACzB,EAAE;AAEF1B,OAAOqC,MAAM,CAAC;IACZlB;IACAU;IACAC;IACAK;AACF"}
1
+ {"version":3,"sources":["../../src/matchers.ts"],"sourcesContent":["/* eslint-disable no-invalid-this */\n\n// Note: Because this file imports from `@jest/globals`, it can only be used in\n// a Jest environment. This is why it's not exported from the index file.\n\nimport type { MatcherFunction } from '@jest/expect';\nimport { expect } from '@jest/globals';\nimport type {\n NotificationType,\n EnumToUnion,\n Component,\n} from '@metamask/snaps-sdk';\nimport type { Json } from '@metamask/utils';\nimport { hasProperty } from '@metamask/utils';\nimport type { MatcherHintOptions } from 'jest-matcher-utils';\nimport {\n diff,\n matcherErrorMessage,\n matcherHint,\n printReceived,\n printWithType,\n RECEIVED_COLOR,\n} from 'jest-matcher-utils';\nimport { is } from 'superstruct';\n\nimport { InterfaceStruct, SnapResponseStruct } from './internals';\nimport type { SnapResponse } from './types';\n\n/**\n * Ensure that the actual value is a response from the `request` function.\n *\n * @param actual - The actual value.\n * @param matcherName - The name of the matcher.\n * @param options - The matcher options.\n */\nfunction assertActualIsSnapResponse(\n actual: unknown,\n matcherName: string,\n options?: MatcherHintOptions,\n): asserts actual is SnapResponse {\n if (!is(actual, SnapResponseStruct)) {\n throw new Error(\n matcherErrorMessage(\n matcherHint(matcherName, undefined, undefined, options),\n `${RECEIVED_COLOR(\n 'received',\n )} value must be a response from the \\`request\\` function`,\n printWithType('Received', actual, printReceived),\n ),\n );\n }\n}\n\n/**\n * Ensure that the actual value is a response from the `request` function, and\n * that it has a `ui` property.\n *\n * @param actual - The actual value.\n * @param matcherName - The name of the matcher.\n * @param options - The matcher options.\n */\nfunction assertHasInterface(\n actual: unknown,\n matcherName: string,\n options?: MatcherHintOptions,\n): asserts actual is { content: Component } {\n if (!is(actual, InterfaceStruct) || !actual.content) {\n throw new Error(\n matcherErrorMessage(\n matcherHint(matcherName, undefined, undefined, options),\n `${RECEIVED_COLOR('received')} value must have a \\`content\\` property`,\n printWithType('Received', actual, printReceived),\n ),\n );\n }\n}\n\n/**\n * Check if a JSON-RPC response matches the expected value. This matcher is\n * intended to be used with the `expect` global.\n *\n * @param actual - The actual response.\n * @param expected - The expected response.\n * @returns The status and message.\n */\nexport const toRespondWith: MatcherFunction<[expected: Json]> = function (\n actual,\n expected,\n) {\n assertActualIsSnapResponse(actual, 'toRespondWith');\n\n const { response } = actual;\n if (hasProperty(response, 'error')) {\n const message = () =>\n `${this.utils.matcherHint('.toRespondWith')}\\n\\n` +\n `Expected response: ${this.utils.printExpected(expected)}\\n` +\n `Received error: ${this.utils.printReceived(response.error)}`;\n\n return { message, pass: false };\n }\n\n const pass = this.equals(response.result, expected);\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRespondWith')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.result)}`\n : () =>\n `${this.utils.matcherHint('.toRespondWith')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.result)}`;\n\n return { message, pass };\n};\n\nexport const toRespondWithError: MatcherFunction<[expected: Json]> = function (\n actual,\n expected,\n) {\n assertActualIsSnapResponse(actual, 'toRespondWithError');\n\n const { response } = actual;\n if (hasProperty(response, 'result')) {\n const message = () =>\n `${this.utils.matcherHint('.toRespondWithError')}\\n\\n` +\n `Expected error: ${this.utils.printExpected(expected)}\\n` +\n `Received result: ${this.utils.printReceived(response.result)}`;\n\n return { message, pass: false };\n }\n\n const pass = this.equals(response.error, expected);\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRespondWithError')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.error)}`\n : () =>\n `${this.utils.matcherHint('.toRespondWithError')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.error)}`;\n\n return { message, pass };\n};\n\n/**\n * Check if the snap sent a notification with the expected message. This matcher\n * is intended to be used with the `expect` global.\n *\n * @param actual - The actual response.\n * @param expected - The expected notification message.\n * @param type - The expected notification type.\n * @returns The status and message.\n */\nexport const toSendNotification: MatcherFunction<\n [expected: string, type?: EnumToUnion<NotificationType> | undefined]\n> = async function (actual, expected, type) {\n assertActualIsSnapResponse(actual, 'toSendNotification');\n\n const { notifications } = actual;\n const pass = notifications.some(\n (notification) =>\n this.equals(notification.message, expected) &&\n (type === undefined || notification.type === type),\n );\n\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toSendNotification')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Expected type: ${this.utils.printExpected(type)}\\n` +\n `Received: ${this.utils.printReceived(notifications)}`\n : () =>\n `${this.utils.matcherHint('.toSendNotification')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Expected type: ${this.utils.printExpected(type)}\\n` +\n `Received: ${this.utils.printReceived(notifications)}`;\n\n return { message, pass };\n};\n\nexport const toRender: MatcherFunction<[expected: Component]> = function (\n actual,\n expected,\n) {\n assertHasInterface(actual, 'toRender');\n\n const { content } = actual;\n const pass = this.equals(content, expected);\n\n const difference = diff(expected, content);\n\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toShowInterface')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(content)}` +\n `${difference ? `\\n\\nDifference:\\n\\n${difference}` : ''}`\n : () =>\n `${this.utils.matcherHint('.toShowInterface')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(content)}` +\n `${difference ? `\\n\\nDifference:\\n\\n${difference}` : ''}`;\n\n return { message, pass };\n};\n\nexpect.extend({\n toRespondWith,\n toRespondWithError,\n toSendNotification,\n toRender,\n});\n"],"names":["expect","hasProperty","diff","matcherErrorMessage","matcherHint","printReceived","printWithType","RECEIVED_COLOR","is","InterfaceStruct","SnapResponseStruct","assertActualIsSnapResponse","actual","matcherName","options","Error","undefined","assertHasInterface","content","toRespondWith","expected","response","message","utils","printExpected","error","pass","equals","result","toRespondWithError","toSendNotification","type","notifications","some","notification","toRender","difference","extend"],"mappings":"AAAA,kCAAkC,GAElC,+EAA+E;AAC/E,yEAAyE;AAGzE,SAASA,MAAM,QAAQ,gBAAgB;AAOvC,SAASC,WAAW,QAAQ,kBAAkB;AAE9C,SACEC,IAAI,EACJC,mBAAmB,EACnBC,WAAW,EACXC,aAAa,EACbC,aAAa,EACbC,cAAc,QACT,qBAAqB;AAC5B,SAASC,EAAE,QAAQ,cAAc;AAEjC,SAASC,eAAe,EAAEC,kBAAkB,QAAQ,cAAc;AAGlE;;;;;;CAMC,GACD,SAASC,2BACPC,MAAe,EACfC,WAAmB,EACnBC,OAA4B;IAE5B,IAAI,CAACN,GAAGI,QAAQF,qBAAqB;QACnC,MAAM,IAAIK,MACRZ,oBACEC,YAAYS,aAAaG,WAAWA,WAAWF,UAC/C,CAAC,EAAEP,eACD,YACA,uDAAuD,CAAC,EAC1DD,cAAc,YAAYM,QAAQP;IAGxC;AACF;AAEA;;;;;;;CAOC,GACD,SAASY,mBACPL,MAAe,EACfC,WAAmB,EACnBC,OAA4B;IAE5B,IAAI,CAACN,GAAGI,QAAQH,oBAAoB,CAACG,OAAOM,OAAO,EAAE;QACnD,MAAM,IAAIH,MACRZ,oBACEC,YAAYS,aAAaG,WAAWA,WAAWF,UAC/C,CAAC,EAAEP,eAAe,YAAY,uCAAuC,CAAC,EACtED,cAAc,YAAYM,QAAQP;IAGxC;AACF;AAEA;;;;;;;CAOC,GACD,OAAO,MAAMc,gBAAmD,SAC9DP,MAAM,EACNQ,QAAQ;IA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,KAAK,CAACnB,WAAW,CAAC,oBAAoB,IAAI,CAAC,GACnD,CAAC,UAAU,EAAE,IAAI,CAACmB,KAAK,CAACC,aAAa,CAACJ,UAAU,EAAE,CAAC,GACnD,CAAC,UAAU,EAAE,IAAI,CAACG,KAAK,CAAClB,aAAa,CAACa,SAAS,CAAC,GAChD,CAAC,EAAEkB,aAAa,CAAC,mBAAmB,EAAEA,WAAW,CAAC,GAAG,GAAG,CAAC;IAE/D,OAAO;QAAEd;QAASI;IAAK;AACzB,EAAE;AAEF1B,OAAOqC,MAAM,CAAC;IACZlB;IACAU;IACAC;IACAK;AACF"}
package/dist/esm/types.js CHANGED
@@ -1,3 +1,3 @@
1
- export { NotificationType } from '@metamask/snaps-rpc-methods';
1
+ export { };
2
2
 
3
3
  //# sourceMappingURL=types.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/types.ts"],"sourcesContent":["import type { NotificationType } from '@metamask/snaps-rpc-methods';\nimport type { Component } from '@metamask/snaps-ui';\nimport type { EnumToUnion } from '@metamask/snaps-utils';\nimport type { JsonRpcId, JsonRpcParams } from '@metamask/utils';\nimport type { Infer } from 'superstruct';\n\nimport type {\n Mock,\n MockJsonRpcOptions,\n MockOptions,\n SnapOptionsStruct,\n SnapResponseStruct,\n TransactionOptionsStruct,\n} from './internals';\n\n/* eslint-disable @typescript-eslint/consistent-type-definitions */\ndeclare module 'expect' {\n interface AsymmetricMatchers {\n toRespondWith(response: unknown): void;\n toRespondWithError(error: unknown): void;\n toSendNotification(\n message: string,\n type?: EnumToUnion<NotificationType>,\n ): void;\n toRender(component: Component): void;\n }\n\n // Ideally we would use `Matchers<Result>` instead of `Matchers<R>`, but\n // TypeScript doesn't allow this:\n // TS2428: All declarations of 'Matchers' must have identical type parameters.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n interface Matchers<R> {\n toRespondWith(response: unknown): R;\n toRespondWithError(error: unknown): R;\n toSendNotification(\n message: string,\n type?: EnumToUnion<NotificationType>,\n ): R;\n toRender(component: Component): R;\n }\n}\n/* eslint-enable @typescript-eslint/consistent-type-definitions */\n\n/**\n * Deeply partialize a type.\n *\n * @template Type - The type to partialize.\n * @returns The deeply partialized type.\n * @example\n * ```ts\n * type Foo = {\n * bar: {\n * baz: string;\n * };\n * qux: number;\n * };\n *\n * type PartialFoo = DeepPartial<Foo>;\n * // { bar?: { baz?: string; }; qux?: number; }\n * ```\n */\nexport type DeepPartial<Type> = {\n [Key in keyof Type]?: Type[Key] extends Record<string, unknown>\n ? DeepPartial<Type[Key]>\n : Type[Key];\n};\n\nexport type RequestOptions = {\n /**\n * The JSON-RPC request ID.\n */\n id?: JsonRpcId;\n\n /**\n * The JSON-RPC method.\n */\n method: string;\n\n /**\n * The JSON-RPC params.\n */\n params?: JsonRpcParams;\n\n /**\n * The origin to send the request from.\n */\n origin?: string;\n};\n\n/**\n * The `runCronjob` options. This is the same as {@link RequestOptions}, except\n * that it does not have an `origin` property.\n */\nexport type CronjobOptions = Omit<RequestOptions, 'origin'>;\n\n/**\n * The options to use for transaction requests.\n *\n * @property chainId - The CAIP-2 chain ID to send the transaction on. Defaults\n * to `eip155:1`.\n * @property origin - The origin to send the transaction from. Defaults to\n * `metamask.io`.\n * @property from - The address to send the transaction from. Defaults to a\n * randomly generated address.\n * @property to - The address to send the transaction to. Defaults to a randomly\n * generated address.\n * @property value - The value to send with the transaction. Defaults to `0`.\n * @property data - The data to send with the transaction. Defaults to `0x`.\n * @property gasLimit - The gas limit to use for the transaction. Defaults to\n * `21_000`.\n * @property maxFeePerGas - The maximum fee per gas to use for the transaction.\n * Defaults to `1`.\n * @property maxPriorityFeePerGas - The maximum priority fee per gas to use for\n * the transaction. Defaults to `1`.\n * @property nonce - The nonce to use for the transaction. Defaults to `0`.\n */\nexport type TransactionOptions = Infer<typeof TransactionOptionsStruct>;\n\n/**\n * The options to use for requests to the snap.\n *\n * @property timeout - The timeout in milliseconds to use. Defaults to `1000`.\n */\nexport type SnapOptions = Infer<typeof SnapOptionsStruct>;\n\n/**\n * A `snap_dialog` alert interface.\n */\nexport type SnapAlertInterface = {\n /**\n * The type of the interface. This is always `alert`.\n */\n type: 'alert';\n\n /**\n * The content to show in the alert.\n */\n content: Component;\n\n /**\n * Close the alert.\n */\n ok(): Promise<void>;\n};\n\n/**\n * A `snap_dialog` confirmation interface.\n */\nexport type SnapConfirmationInterface = {\n /**\n * The type of the interface. This is always `confirmation`.\n */\n type: 'confirmation';\n\n /**\n * The content to show in the confirmation.\n */\n content: Component;\n\n /**\n * Close the confirmation.\n */\n ok(): Promise<void>;\n\n /**\n * Cancel the confirmation.\n */\n cancel(): Promise<void>;\n};\n\n/**\n * A `snap_dialog` prompt interface.\n */\nexport type SnapPromptInterface = {\n /**\n * The type of the interface. This is always `prompt`.\n */\n type: 'prompt';\n\n /**\n * The content to show in the prompt.\n */\n content: Component;\n\n /**\n * Close the prompt.\n *\n * @param value - The value to close the prompt with.\n */\n ok(value?: string): Promise<void>;\n\n /**\n * Cancel the prompt.\n */\n cancel(): Promise<void>;\n};\n\nexport type SnapInterface =\n | SnapAlertInterface\n | SnapConfirmationInterface\n | SnapPromptInterface;\n\nexport type SnapRequestObject = {\n /**\n * Get a user interface object from a snap. This will throw an error if the\n * snap does not show a user interface within the timeout.\n *\n * @param options - The options to use.\n * @param options.timeout - The timeout in milliseconds to use. Defaults to\n * `1000`.\n * @returns The user interface object.\n */\n getInterface(options?: SnapOptions): Promise<SnapInterface>;\n};\n\n/**\n * A pending request object. This is a promise with extra\n * {@link SnapRequestObject} fields.\n */\nexport type SnapRequest = Promise<SnapResponse> & SnapRequestObject;\n\n/**\n * This is the main entry point to interact with the snap. It is returned by\n * {@link installSnap}, and has methods to send requests to the snap.\n *\n * @example\n * ```ts\n * import { installSnap } from '@metamask/snaps-jest';\n *\n * const snap = await installSnap();\n * const response = await snap.request({ method: 'hello' });\n *\n * expect(response).toRespondWith('Hello, world!');\n * ```\n */\nexport type Snap = {\n /**\n * Send a JSON-RPC request to the snap.\n *\n * @param request - The request. This is similar to a JSON-RPC request, but\n * has an extra `origin` field.\n * @returns The response promise, with extra {@link SnapRequestObject} fields.\n */\n request(request: RequestOptions): SnapRequest;\n\n /**\n * Send a transaction to the snap.\n *\n * @param transaction - The transaction. This is similar to an Ethereum\n * transaction object, but has an extra `origin` field. Any missing fields\n * will be filled in with default values.\n * @returns The response.\n */\n sendTransaction(\n transaction?: Partial<TransactionOptions>,\n ): Promise<SnapResponse>;\n\n /**\n * Run a cronjob in the snap. This is similar to {@link request}, but the\n * request will be sent to the `onCronjob` method of the snap.\n *\n * @param cronjob - The cronjob request. This is similar to a JSON-RPC\n * request, and is normally specified in the snap manifest, under the\n * `endowment:cronjob` permission.\n * @returns The response promise, with extra {@link SnapRequestObject} fields.\n */\n runCronjob(cronjob: CronjobOptions): SnapRequest;\n\n /**\n * Close the page running the snap. This is mainly useful for cleaning up\n * the test environment, and calling it is not strictly necessary.\n *\n * @returns A promise that resolves when the page is closed.\n */\n // TODO: Find a way to do this automatically.\n close(): Promise<void>;\n\n /**\n * Enable network mocking for the snap.\n *\n * @param options - The options for the network mocking.\n * @returns A {@link Mock} object, with an `unmock` function.\n */\n mock(options: DeepPartial<MockOptions>): Promise<Mock>;\n\n /**\n * Enable JSON-RPC provider mocking for the snap. This will mock any requests\n * sent through the `ethereum` global, with the specified `method`.\n *\n * @param options - The options for the JSON-RPC mocking.\n * @param options.method - The JSON-RPC method to mock, e.g.,\n * `eth_blockNumber`.\n * @param options.result - The JSON value to return.\n * @returns A {@link Mock} object, with an `unmock` function.\n */\n mockJsonRpc(options: MockJsonRpcOptions): Promise<Mock>;\n};\n\nexport type SnapResponse = Infer<typeof SnapResponseStruct>;\n\nexport { NotificationType } from '@metamask/snaps-rpc-methods';\n"],"names":["NotificationType"],"mappings":"AA4SA,SAASA,gBAAgB,QAAQ,8BAA8B"}
1
+ {"version":3,"sources":["../../src/types.ts"],"sourcesContent":["import type {\n NotificationType,\n EnumToUnion,\n Component,\n} from '@metamask/snaps-sdk';\nimport type { JsonRpcId, JsonRpcParams } from '@metamask/utils';\nimport type { Infer } from 'superstruct';\n\nimport type {\n Mock,\n MockJsonRpcOptions,\n MockOptions,\n SnapOptionsStruct,\n SnapResponseStruct,\n TransactionOptionsStruct,\n} from './internals';\n\n/* eslint-disable @typescript-eslint/consistent-type-definitions */\ndeclare module 'expect' {\n interface AsymmetricMatchers {\n toRespondWith(response: unknown): void;\n toRespondWithError(error: unknown): void;\n toSendNotification(\n message: string,\n type?: EnumToUnion<NotificationType>,\n ): void;\n toRender(component: Component): void;\n }\n\n // Ideally we would use `Matchers<Result>` instead of `Matchers<R>`, but\n // TypeScript doesn't allow this:\n // TS2428: All declarations of 'Matchers' must have identical type parameters.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n interface Matchers<R> {\n toRespondWith(response: unknown): R;\n toRespondWithError(error: unknown): R;\n toSendNotification(\n message: string,\n type?: EnumToUnion<NotificationType>,\n ): R;\n toRender(component: Component): R;\n }\n}\n/* eslint-enable @typescript-eslint/consistent-type-definitions */\n\n/**\n * Deeply partialize a type.\n *\n * @template Type - The type to partialize.\n * @returns The deeply partialized type.\n * @example\n * ```ts\n * type Foo = {\n * bar: {\n * baz: string;\n * };\n * qux: number;\n * };\n *\n * type PartialFoo = DeepPartial<Foo>;\n * // { bar?: { baz?: string; }; qux?: number; }\n * ```\n */\nexport type DeepPartial<Type> = {\n [Key in keyof Type]?: Type[Key] extends Record<string, unknown>\n ? DeepPartial<Type[Key]>\n : Type[Key];\n};\n\nexport type RequestOptions = {\n /**\n * The JSON-RPC request ID.\n */\n id?: JsonRpcId;\n\n /**\n * The JSON-RPC method.\n */\n method: string;\n\n /**\n * The JSON-RPC params.\n */\n params?: JsonRpcParams;\n\n /**\n * The origin to send the request from.\n */\n origin?: string;\n};\n\n/**\n * The `runCronjob` options. This is the same as {@link RequestOptions}, except\n * that it does not have an `origin` property.\n */\nexport type CronjobOptions = Omit<RequestOptions, 'origin'>;\n\n/**\n * The options to use for transaction requests.\n *\n * @property chainId - The CAIP-2 chain ID to send the transaction on. Defaults\n * to `eip155:1`.\n * @property origin - The origin to send the transaction from. Defaults to\n * `metamask.io`.\n * @property from - The address to send the transaction from. Defaults to a\n * randomly generated address.\n * @property to - The address to send the transaction to. Defaults to a randomly\n * generated address.\n * @property value - The value to send with the transaction. Defaults to `0`.\n * @property data - The data to send with the transaction. Defaults to `0x`.\n * @property gasLimit - The gas limit to use for the transaction. Defaults to\n * `21_000`.\n * @property maxFeePerGas - The maximum fee per gas to use for the transaction.\n * Defaults to `1`.\n * @property maxPriorityFeePerGas - The maximum priority fee per gas to use for\n * the transaction. Defaults to `1`.\n * @property nonce - The nonce to use for the transaction. Defaults to `0`.\n */\nexport type TransactionOptions = Infer<typeof TransactionOptionsStruct>;\n\n/**\n * The options to use for requests to the snap.\n *\n * @property timeout - The timeout in milliseconds to use. Defaults to `1000`.\n */\nexport type SnapOptions = Infer<typeof SnapOptionsStruct>;\n\n/**\n * A `snap_dialog` alert interface.\n */\nexport type SnapAlertInterface = {\n /**\n * The type of the interface. This is always `alert`.\n */\n type: 'alert';\n\n /**\n * The content to show in the alert.\n */\n content: Component;\n\n /**\n * Close the alert.\n */\n ok(): Promise<void>;\n};\n\n/**\n * A `snap_dialog` confirmation interface.\n */\nexport type SnapConfirmationInterface = {\n /**\n * The type of the interface. This is always `confirmation`.\n */\n type: 'confirmation';\n\n /**\n * The content to show in the confirmation.\n */\n content: Component;\n\n /**\n * Close the confirmation.\n */\n ok(): Promise<void>;\n\n /**\n * Cancel the confirmation.\n */\n cancel(): Promise<void>;\n};\n\n/**\n * A `snap_dialog` prompt interface.\n */\nexport type SnapPromptInterface = {\n /**\n * The type of the interface. This is always `prompt`.\n */\n type: 'prompt';\n\n /**\n * The content to show in the prompt.\n */\n content: Component;\n\n /**\n * Close the prompt.\n *\n * @param value - The value to close the prompt with.\n */\n ok(value?: string): Promise<void>;\n\n /**\n * Cancel the prompt.\n */\n cancel(): Promise<void>;\n};\n\nexport type SnapInterface =\n | SnapAlertInterface\n | SnapConfirmationInterface\n | SnapPromptInterface;\n\nexport type SnapRequestObject = {\n /**\n * Get a user interface object from a snap. This will throw an error if the\n * snap does not show a user interface within the timeout.\n *\n * @param options - The options to use.\n * @param options.timeout - The timeout in milliseconds to use. Defaults to\n * `1000`.\n * @returns The user interface object.\n */\n getInterface(options?: SnapOptions): Promise<SnapInterface>;\n};\n\n/**\n * A pending request object. This is a promise with extra\n * {@link SnapRequestObject} fields.\n */\nexport type SnapRequest = Promise<SnapResponse> & SnapRequestObject;\n\n/**\n * This is the main entry point to interact with the snap. It is returned by\n * {@link installSnap}, and has methods to send requests to the snap.\n *\n * @example\n * ```ts\n * import { installSnap } from '@metamask/snaps-jest';\n *\n * const snap = await installSnap();\n * const response = await snap.request({ method: 'hello' });\n *\n * expect(response).toRespondWith('Hello, world!');\n * ```\n */\nexport type Snap = {\n /**\n * Send a JSON-RPC request to the snap.\n *\n * @param request - The request. This is similar to a JSON-RPC request, but\n * has an extra `origin` field.\n * @returns The response promise, with extra {@link SnapRequestObject} fields.\n */\n request(request: RequestOptions): SnapRequest;\n\n /**\n * Send a transaction to the snap.\n *\n * @param transaction - The transaction. This is similar to an Ethereum\n * transaction object, but has an extra `origin` field. Any missing fields\n * will be filled in with default values.\n * @returns The response.\n */\n sendTransaction(\n transaction?: Partial<TransactionOptions>,\n ): Promise<SnapResponse>;\n\n /**\n * Run a cronjob in the snap. This is similar to {@link request}, but the\n * request will be sent to the `onCronjob` method of the snap.\n *\n * @param cronjob - The cronjob request. This is similar to a JSON-RPC\n * request, and is normally specified in the snap manifest, under the\n * `endowment:cronjob` permission.\n * @returns The response promise, with extra {@link SnapRequestObject} fields.\n */\n runCronjob(cronjob: CronjobOptions): SnapRequest;\n\n /**\n * Close the page running the snap. This is mainly useful for cleaning up\n * the test environment, and calling it is not strictly necessary.\n *\n * @returns A promise that resolves when the page is closed.\n */\n // TODO: Find a way to do this automatically.\n close(): Promise<void>;\n\n /**\n * Enable network mocking for the snap.\n *\n * @param options - The options for the network mocking.\n * @returns A {@link Mock} object, with an `unmock` function.\n */\n mock(options: DeepPartial<MockOptions>): Promise<Mock>;\n\n /**\n * Enable JSON-RPC provider mocking for the snap. This will mock any requests\n * sent through the `ethereum` global, with the specified `method`.\n *\n * @param options - The options for the JSON-RPC mocking.\n * @param options.method - The JSON-RPC method to mock, e.g.,\n * `eth_blockNumber`.\n * @param options.result - The JSON value to return.\n * @returns A {@link Mock} object, with an `unmock` function.\n */\n mockJsonRpc(options: MockJsonRpcOptions): Promise<Mock>;\n};\n\nexport type SnapResponse = Infer<typeof SnapResponseStruct>;\n"],"names":[],"mappings":"AAAA,WA4S4D"}
@@ -21,35 +21,36 @@ export declare function request(page: Page, { origin, ...options }: RequestOptio
21
21
  export declare function sendTransaction(page: Page, options: Partial<TransactionOptions>): Promise<{
22
22
  id: string;
23
23
  response: ({
24
- result: import("@metamask/utils").Json;
24
+ result: import("@metamask/snaps-sdk").Json;
25
25
  } | {
26
- error: import("@metamask/utils").Json;
26
+ error: import("@metamask/snaps-sdk").Json;
27
27
  }) & Record<"error", unknown>;
28
28
  notifications: never[];
29
29
  content?: undefined;
30
30
  } | {
31
31
  id: string;
32
32
  response: {
33
- result: import("@metamask/utils").Json;
33
+ result: import("@metamask/snaps-sdk").Json;
34
34
  };
35
35
  notifications: never[];
36
- content: import("@metamask/snaps-ui").Panel | {
36
+ content: import("@metamask/snaps-sdk").Panel | {
37
37
  value: string;
38
- type: import("@metamask/snaps-ui").NodeType.Copyable;
38
+ type: import("@metamask/snaps-sdk").NodeType.Copyable;
39
+ sensitive?: boolean | undefined;
39
40
  } | {
40
- type: import("@metamask/snaps-ui").NodeType.Divider;
41
+ type: import("@metamask/snaps-sdk").NodeType.Divider;
41
42
  } | {
42
43
  value: string;
43
- type: import("@metamask/snaps-ui").NodeType.Heading;
44
- } | {
45
- type: import("@metamask/snaps-ui").NodeType.Spinner;
44
+ type: import("@metamask/snaps-sdk").NodeType.Heading;
46
45
  } | {
47
46
  value: string;
48
- type: import("@metamask/snaps-ui").NodeType.Text;
49
- markdown?: boolean | undefined;
47
+ type: import("@metamask/snaps-sdk").NodeType.Image;
48
+ } | {
49
+ type: import("@metamask/snaps-sdk").NodeType.Spinner;
50
50
  } | {
51
51
  value: string;
52
- type: import("@metamask/snaps-ui").NodeType.Image;
52
+ type: import("@metamask/snaps-sdk").NodeType.Text;
53
+ markdown?: boolean | undefined;
53
54
  };
54
55
  }>;
55
56
  /**
@@ -4,11 +4,11 @@ export declare const TransactionOptionsStruct: import("superstruct").Struct<{
4
4
  origin: string;
5
5
  value: `0x${string}`;
6
6
  chainId: string;
7
- nonce: `0x${string}`;
8
- maxPriorityFeePerGas: `0x${string}`;
9
- maxFeePerGas: `0x${string}`;
10
7
  to: `0x${string}`;
11
8
  gasLimit: `0x${string}`;
9
+ maxFeePerGas: `0x${string}`;
10
+ maxPriorityFeePerGas: `0x${string}`;
11
+ nonce: `0x${string}`;
12
12
  }, {
13
13
  /**
14
14
  * The CAIP-2 chain ID to send the transaction on. Defaults to `eip155:1`.
@@ -71,49 +71,57 @@ export declare const SnapOptionsStruct: import("superstruct").Struct<{
71
71
  timeout: import("superstruct").Struct<number | undefined, null>;
72
72
  }>;
73
73
  export declare const InterfaceStruct: import("superstruct").Struct<{
74
- content?: import("@metamask/snaps-ui").Panel | {
74
+ content?: import("@metamask/snaps-sdk").Panel | {
75
75
  value: string;
76
- type: import("@metamask/snaps-ui").NodeType.Copyable;
76
+ type: import("@metamask/snaps-sdk").NodeType.Copyable;
77
+ sensitive?: boolean | undefined;
77
78
  } | {
78
- type: import("@metamask/snaps-ui").NodeType.Divider;
79
+ type: import("@metamask/snaps-sdk").NodeType.Divider;
79
80
  } | {
80
81
  value: string;
81
- type: import("@metamask/snaps-ui").NodeType.Heading;
82
- } | {
83
- type: import("@metamask/snaps-ui").NodeType.Spinner;
82
+ type: import("@metamask/snaps-sdk").NodeType.Heading;
84
83
  } | {
85
84
  value: string;
86
- type: import("@metamask/snaps-ui").NodeType.Text;
87
- markdown?: boolean | undefined;
85
+ type: import("@metamask/snaps-sdk").NodeType.Image;
86
+ } | {
87
+ type: import("@metamask/snaps-sdk").NodeType.Spinner;
88
88
  } | {
89
89
  value: string;
90
- type: import("@metamask/snaps-ui").NodeType.Image;
90
+ type: import("@metamask/snaps-sdk").NodeType.Text; /**
91
+ * The timeout in milliseconds to use for requests to the snap. Defaults to
92
+ * `1000`.
93
+ */
94
+ markdown?: boolean | undefined;
91
95
  } | undefined;
92
96
  }, {
93
- content: import("superstruct").Struct<import("@metamask/snaps-ui").Panel | {
97
+ content: import("superstruct").Struct<import("@metamask/snaps-sdk").Panel | {
94
98
  value: string;
95
- type: import("@metamask/snaps-ui").NodeType.Copyable;
99
+ type: import("@metamask/snaps-sdk").NodeType.Copyable;
100
+ sensitive?: boolean | undefined;
96
101
  } | {
97
- type: import("@metamask/snaps-ui").NodeType.Divider;
102
+ type: import("@metamask/snaps-sdk").NodeType.Divider;
98
103
  } | {
99
104
  value: string;
100
- type: import("@metamask/snaps-ui").NodeType.Heading;
101
- } | {
102
- type: import("@metamask/snaps-ui").NodeType.Spinner;
105
+ type: import("@metamask/snaps-sdk").NodeType.Heading;
103
106
  } | {
104
107
  value: string;
105
- type: import("@metamask/snaps-ui").NodeType.Text;
106
- markdown?: boolean | undefined;
108
+ type: import("@metamask/snaps-sdk").NodeType.Image;
109
+ } | {
110
+ type: import("@metamask/snaps-sdk").NodeType.Spinner;
107
111
  } | {
108
112
  value: string;
109
- type: import("@metamask/snaps-ui").NodeType.Image;
113
+ type: import("@metamask/snaps-sdk").NodeType.Text; /**
114
+ * The timeout in milliseconds to use for requests to the snap. Defaults to
115
+ * `1000`.
116
+ */
117
+ markdown?: boolean | undefined;
110
118
  } | undefined, null>;
111
119
  }>;
112
120
  export declare const SnapResponseStruct: import("superstruct").Struct<{
113
121
  response: {
114
- result: import("@metamask/utils").Json;
122
+ result: import("@metamask/snaps-sdk").Json;
115
123
  } | {
116
- error: import("@metamask/utils").Json;
124
+ error: import("@metamask/snaps-sdk").Json;
117
125
  };
118
126
  id: string;
119
127
  notifications: {
@@ -121,30 +129,34 @@ export declare const SnapResponseStruct: import("superstruct").Struct<{
121
129
  type: "native" | "inApp";
122
130
  id: string;
123
131
  }[];
124
- content?: import("@metamask/snaps-ui").Panel | {
132
+ content?: import("@metamask/snaps-sdk").Panel | {
125
133
  value: string;
126
- type: import("@metamask/snaps-ui").NodeType.Copyable;
134
+ type: import("@metamask/snaps-sdk").NodeType.Copyable;
135
+ sensitive?: boolean | undefined;
127
136
  } | {
128
- type: import("@metamask/snaps-ui").NodeType.Divider;
137
+ type: import("@metamask/snaps-sdk").NodeType.Divider;
129
138
  } | {
130
139
  value: string;
131
- type: import("@metamask/snaps-ui").NodeType.Heading;
132
- } | {
133
- type: import("@metamask/snaps-ui").NodeType.Spinner;
140
+ type: import("@metamask/snaps-sdk").NodeType.Heading;
134
141
  } | {
135
142
  value: string;
136
- type: import("@metamask/snaps-ui").NodeType.Text;
137
- markdown?: boolean | undefined;
143
+ type: import("@metamask/snaps-sdk").NodeType.Image;
144
+ } | {
145
+ type: import("@metamask/snaps-sdk").NodeType.Spinner;
138
146
  } | {
139
147
  value: string;
140
- type: import("@metamask/snaps-ui").NodeType.Image;
148
+ type: import("@metamask/snaps-sdk").NodeType.Text; /**
149
+ * The timeout in milliseconds to use for requests to the snap. Defaults to
150
+ * `1000`.
151
+ */
152
+ markdown?: boolean | undefined;
141
153
  } | undefined;
142
154
  }, {
143
155
  id: import("superstruct").Struct<string, null>;
144
156
  response: import("superstruct").Struct<{
145
- result: import("@metamask/utils").Json;
157
+ result: import("@metamask/snaps-sdk").Json;
146
158
  } | {
147
- error: import("@metamask/utils").Json;
159
+ error: import("@metamask/snaps-sdk").Json;
148
160
  }, null>;
149
161
  notifications: import("superstruct").Struct<{
150
162
  message: string;
@@ -159,22 +171,26 @@ export declare const SnapResponseStruct: import("superstruct").Struct<{
159
171
  message: import("superstruct").Struct<string, null>;
160
172
  type: import("superstruct").Struct<"native" | "inApp", null>;
161
173
  }>>;
162
- content: import("superstruct").Struct<import("@metamask/snaps-ui").Panel | {
174
+ content: import("superstruct").Struct<import("@metamask/snaps-sdk").Panel | {
163
175
  value: string;
164
- type: import("@metamask/snaps-ui").NodeType.Copyable;
176
+ type: import("@metamask/snaps-sdk").NodeType.Copyable;
177
+ sensitive?: boolean | undefined;
165
178
  } | {
166
- type: import("@metamask/snaps-ui").NodeType.Divider;
179
+ type: import("@metamask/snaps-sdk").NodeType.Divider;
167
180
  } | {
168
181
  value: string;
169
- type: import("@metamask/snaps-ui").NodeType.Heading;
170
- } | {
171
- type: import("@metamask/snaps-ui").NodeType.Spinner;
182
+ type: import("@metamask/snaps-sdk").NodeType.Heading;
172
183
  } | {
173
184
  value: string;
174
- type: import("@metamask/snaps-ui").NodeType.Text;
175
- markdown?: boolean | undefined;
185
+ type: import("@metamask/snaps-sdk").NodeType.Image;
186
+ } | {
187
+ type: import("@metamask/snaps-sdk").NodeType.Spinner;
176
188
  } | {
177
189
  value: string;
178
- type: import("@metamask/snaps-ui").NodeType.Image;
190
+ type: import("@metamask/snaps-sdk").NodeType.Text; /**
191
+ * The timeout in milliseconds to use for requests to the snap. Defaults to
192
+ * `1000`.
193
+ */
194
+ markdown?: boolean | undefined;
179
195
  } | undefined, null>;
180
196
  }>;
@@ -1,6 +1,5 @@
1
- import type { NotificationType } from '@metamask/snaps-rpc-methods';
1
+ import type { NotificationType, EnumToUnion } from '@metamask/snaps-sdk';
2
2
  import type { ApplicationState, Dispatch } from '@metamask/snaps-simulator';
3
- import type { EnumToUnion } from '@metamask/snaps-utils';
4
3
  declare global {
5
4
  interface Window {
6
5
  __SIMULATOR_API__: {
@@ -1,7 +1,5 @@
1
1
  import type { MatcherFunction } from '@jest/expect';
2
- import type { NotificationType } from '@metamask/snaps-rpc-methods';
3
- import type { Component } from '@metamask/snaps-ui';
4
- import type { EnumToUnion } from '@metamask/snaps-utils';
2
+ import type { NotificationType, EnumToUnion, Component } from '@metamask/snaps-sdk';
5
3
  import type { Json } from '@metamask/utils';
6
4
  /**
7
5
  * Check if a JSON-RPC response matches the expected value. This matcher is
@@ -1,6 +1,4 @@
1
- import type { NotificationType } from '@metamask/snaps-rpc-methods';
2
- import type { Component } from '@metamask/snaps-ui';
3
- import type { EnumToUnion } from '@metamask/snaps-utils';
1
+ import type { NotificationType, EnumToUnion, Component } from '@metamask/snaps-sdk';
4
2
  import type { JsonRpcId, JsonRpcParams } from '@metamask/utils';
5
3
  import type { Infer } from 'superstruct';
6
4
  import type { Mock, MockJsonRpcOptions, MockOptions, SnapOptionsStruct, SnapResponseStruct, TransactionOptionsStruct } from './internals';
@@ -238,4 +236,3 @@ export declare type Snap = {
238
236
  mockJsonRpc(options: MockJsonRpcOptions): Promise<Mock>;
239
237
  };
240
238
  export declare type SnapResponse = Infer<typeof SnapResponseStruct>;
241
- export { NotificationType } from '@metamask/snaps-rpc-methods';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask/snaps-jest",
3
- "version": "3.0.0",
3
+ "version": "4.0.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
  "sideEffects": false,
6
6
  "main": "./dist/cjs/index.js",
@@ -36,11 +36,10 @@
36
36
  "@jest/environment": "^29.5.0",
37
37
  "@jest/expect": "^29.5.0",
38
38
  "@jest/globals": "^29.5.0",
39
- "@metamask/snaps-execution-environments": "^3.1.0",
40
- "@metamask/snaps-rpc-methods": "^3.1.0",
41
- "@metamask/snaps-simulator": "^2.1.0",
42
- "@metamask/snaps-ui": "^3.0.1",
43
- "@metamask/snaps-utils": "^3.1.0",
39
+ "@metamask/snaps-execution-environments": "^3.3.0",
40
+ "@metamask/snaps-sdk": "^1.0.0",
41
+ "@metamask/snaps-simulator": "^2.4.0",
42
+ "@metamask/snaps-utils": "^4.0.0",
44
43
  "@metamask/utils": "^8.1.0",
45
44
  "express": "^4.18.2",
46
45
  "jest-environment-node": "^29.5.0",
@@ -52,7 +51,7 @@
52
51
  },
53
52
  "devDependencies": {
54
53
  "@lavamoat/allow-scripts": "^2.5.1",
55
- "@metamask/auto-changelog": "^3.3.0",
54
+ "@metamask/auto-changelog": "^3.4.3",
56
55
  "@metamask/eslint-config": "^12.1.0",
57
56
  "@metamask/eslint-config-jest": "^12.1.0",
58
57
  "@metamask/eslint-config-nodejs": "^12.1.0",