@metamask/snaps-execution-environments 11.0.2 → 11.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/CHANGELOG.md +14 -1
  2. package/dist/common/BaseSnapExecutor.cjs.map +1 -1
  3. package/dist/common/BaseSnapExecutor.d.cts +2 -2
  4. package/dist/common/BaseSnapExecutor.d.cts.map +1 -1
  5. package/dist/common/BaseSnapExecutor.d.mts +2 -2
  6. package/dist/common/BaseSnapExecutor.d.mts.map +1 -1
  7. package/dist/common/BaseSnapExecutor.mjs.map +1 -1
  8. package/dist/common/endowments/commonEndowmentFactory.cjs.map +1 -1
  9. package/dist/common/endowments/commonEndowmentFactory.d.cts +44 -5
  10. package/dist/common/endowments/commonEndowmentFactory.d.cts.map +1 -1
  11. package/dist/common/endowments/commonEndowmentFactory.d.mts +44 -5
  12. package/dist/common/endowments/commonEndowmentFactory.d.mts.map +1 -1
  13. package/dist/common/endowments/commonEndowmentFactory.mjs.map +1 -1
  14. package/dist/common/endowments/console.cjs +13 -12
  15. package/dist/common/endowments/console.cjs.map +1 -1
  16. package/dist/common/endowments/console.d.cts +8 -7
  17. package/dist/common/endowments/console.d.cts.map +1 -1
  18. package/dist/common/endowments/console.d.mts +8 -7
  19. package/dist/common/endowments/console.d.mts.map +1 -1
  20. package/dist/common/endowments/console.mjs +13 -12
  21. package/dist/common/endowments/console.mjs.map +1 -1
  22. package/dist/common/endowments/index.cjs +1 -1
  23. package/dist/common/endowments/index.cjs.map +1 -1
  24. package/dist/common/endowments/index.d.cts +1 -1
  25. package/dist/common/endowments/index.d.cts.map +1 -1
  26. package/dist/common/endowments/index.d.mts +1 -1
  27. package/dist/common/endowments/index.d.mts.map +1 -1
  28. package/dist/common/endowments/index.mjs +1 -1
  29. package/dist/common/endowments/index.mjs.map +1 -1
  30. package/dist/common/endowments/network.cjs +5 -4
  31. package/dist/common/endowments/network.cjs.map +1 -1
  32. package/dist/common/endowments/network.d.cts.map +1 -1
  33. package/dist/common/endowments/network.d.mts.map +1 -1
  34. package/dist/common/endowments/network.mjs +5 -4
  35. package/dist/common/endowments/network.mjs.map +1 -1
  36. package/dist/common/validation.d.cts +17 -17
  37. package/dist/common/validation.d.mts +17 -17
  38. package/dist/endowments.cjs +61 -0
  39. package/dist/endowments.cjs.map +1 -0
  40. package/dist/endowments.d.cts +59 -0
  41. package/dist/endowments.d.cts.map +1 -0
  42. package/dist/endowments.d.mts +59 -0
  43. package/dist/endowments.d.mts.map +1 -0
  44. package/dist/endowments.mjs +47 -0
  45. package/dist/endowments.mjs.map +1 -0
  46. package/dist/webpack/iframe/bundle.js +1 -1
  47. package/dist/webpack/node-process/bundle.js +1 -1
  48. package/dist/webpack/node-thread/bundle.js +1 -1
  49. package/dist/webpack/webview/index.html +1 -1
  50. package/package.json +16 -6
@@ -1 +1 @@
1
- {"version":3,"file":"network.mjs","sourceRoot":"","sources":["../../../src/common/endowments/network.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,wBAAwB;AAGzC,OAAO,EAAE,YAAY,EAAE,qBAAiB;AAExC;;;GAGG;AACH,MAAM,OAAO,eAAe;IACjB,YAAY,CAA2B;IAEvC,WAAW,CAAW;IAEtB,QAAQ,CAAsB;IAE9B,SAAS,CAAsB;IAExC,YACE,UAAoB,EACpB,WAAqC,EACrC,OAA4B,EAC5B,QAA6B;QAE7B,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;QAC9B,IAAI,CAAC,YAAY,GAAG,WAAW,CAAC;QAChC,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;QACxB,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;IAC5B,CAAC;IAED,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;IAC/B,CAAC;IAED,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC;IACnC,CAAC;IAED,IAAI,OAAO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CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC9B,CAAC,CAAC;IAEF,OAAO;QACL,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC;QACrB,4EAA4E;QAC5E,gEAAgE;QAChE,yFAAyF;QACzF,uEAAuE;QACvE,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC;QACxB,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC;QACxB,QAAQ,EAAE,MAAM,CAAC,eAAe,CAAC;QACjC,gBAAgB;KACjB,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,eAAe,GAAG;IACtB,KAAK,EAAE,CAAC,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,CAAU;IAC3D,OAAO,EAAE,aAAa;CACvB,CAAC;AACF,eAAe,eAAe,CAAC","sourcesContent":["import { assert } from '@metamask/utils';\n\nimport type { EndowmentFactoryOptions } from './commonEndowmentFactory';\nimport { withTeardown } from '../utils';\n\n/**\n * This class wraps a Response object.\n * That way, a teardown process can stop any processes left.\n */\nexport class ResponseWrapper implements Response {\n readonly #teardownRef: { lastTeardown: number };\n\n readonly #ogResponse: Response;\n\n readonly #onStart: () => Promise<void>;\n\n readonly #onFinish: () => Promise<void>;\n\n constructor(\n ogResponse: Response,\n teardownRef: { lastTeardown: number },\n onStart: () => Promise<void>,\n onFinish: () => Promise<void>,\n ) {\n this.#ogResponse = ogResponse;\n this.#teardownRef = teardownRef;\n this.#onStart = onStart;\n this.#onFinish = onFinish;\n }\n\n get body(): ReadableStream<Uint8Array> | null {\n return this.#ogResponse.body;\n }\n\n get bodyUsed() {\n return this.#ogResponse.bodyUsed;\n }\n\n get headers() {\n return this.#ogResponse.headers;\n }\n\n get ok() {\n return this.#ogResponse.ok;\n }\n\n get redirected() {\n return this.#ogResponse.redirected;\n }\n\n get status() {\n return this.#ogResponse.status;\n }\n\n get statusText() {\n return this.#ogResponse.statusText;\n }\n\n get type() {\n return this.#ogResponse.type;\n }\n\n get url() {\n return this.#ogResponse.url;\n }\n\n async text() {\n return await withTeardown<string>(\n (async () => {\n await this.#onStart();\n try {\n return await this.#ogResponse.text();\n } finally {\n await this.#onFinish();\n }\n })(),\n this.#teardownRef,\n );\n }\n\n async arrayBuffer(): Promise<ArrayBuffer> {\n return await withTeardown<ArrayBuffer>(\n (async () => {\n await this.#onStart();\n try {\n return await this.#ogResponse.arrayBuffer();\n } finally {\n await this.#onFinish();\n }\n })(),\n this.#teardownRef,\n );\n }\n\n async blob(): Promise<Blob> {\n return await withTeardown<Blob>(\n (async () => {\n await this.#onStart();\n try {\n return await this.#ogResponse.blob();\n } finally {\n await this.#onFinish();\n }\n })(),\n this.#teardownRef,\n );\n }\n\n clone(): Response {\n const newResponse = this.#ogResponse.clone();\n return new ResponseWrapper(\n newResponse,\n this.#teardownRef,\n this.#onStart,\n this.#onFinish,\n );\n }\n\n async formData(): Promise<FormData> {\n return await withTeardown<FormData>(\n (async () => {\n await this.#onStart();\n try {\n return await this.#ogResponse.formData();\n } finally {\n await this.#onFinish();\n }\n })(),\n this.#teardownRef,\n );\n }\n\n async json(): Promise<any> {\n return await withTeardown(\n (async () => {\n await this.#onStart();\n try {\n return await this.#ogResponse.json();\n } finally {\n await this.#onFinish();\n }\n })(),\n this.#teardownRef,\n );\n }\n}\n\n// We redefine the global Response class to overwrite [Symbol.hasInstance].\n// This fixes problems where the response from `fetch` would not pass\n// instance of checks, leading to failures in WASM bindgen.\nclass AlteredResponse extends Response {\n static [Symbol.hasInstance](instance: unknown) {\n return instance instanceof Response || instance instanceof ResponseWrapper;\n }\n}\n\n/**\n * Create a network endowment, consisting of a `fetch` function.\n * This allows us to provide a teardown function, so that we can cancel\n * any pending requests, connections, streams, etc. that may be open when a snap\n * is terminated.\n *\n * This wraps the original implementation of `fetch`,\n * to ensure that a bad actor cannot get access to the original function, thus\n * potentially preventing the network requests from being torn down.\n *\n * @param options - An options bag.\n * @param options.notify - A reference to the notify function of the snap executor.\n * @returns An object containing a wrapped `fetch`\n * function, as well as a teardown function.\n */\nconst createNetwork = ({ notify }: EndowmentFactoryOptions = {}) => {\n assert(notify, 'Notify must be passed to network endowment factory');\n // Open fetch calls or open body streams\n const openConnections = new Set<{ cancel: () => Promise<void> }>();\n // Track last teardown count\n const teardownRef = { lastTeardown: 0 };\n\n // Remove items from openConnections after they were garbage collected\n const cleanup = new FinalizationRegistry<() => void>(\n /* istanbul ignore next: can't test garbage collection without modifying node parameters */\n (callback) => callback(),\n );\n\n const _fetch: typeof fetch = async (\n input: RequestInfo | URL,\n init?: RequestInit,\n ): Promise<Response> => {\n const abortController = new AbortController();\n if (init?.signal !== null && init?.signal !== undefined) {\n const originalSignal = init.signal;\n // Merge abort controllers\n originalSignal.addEventListener(\n 'abort',\n () => {\n abortController.abort((originalSignal as any).reason);\n },\n { once: true },\n );\n }\n\n let started = false;\n const onStart = async () => {\n if (!started) {\n started = true;\n await notify({\n method: 'OutboundRequest',\n params: { source: 'fetch' },\n });\n }\n };\n\n let finished = false;\n const onFinish = async () => {\n if (!finished) {\n finished = true;\n await notify({\n method: 'OutboundResponse',\n params: { source: 'fetch' },\n });\n }\n };\n\n let res: Response;\n let openFetchConnection: { cancel: () => Promise<void> } | undefined;\n return await withTeardown(\n (async () => {\n try {\n const fetchPromise = fetch(input, {\n ...init,\n signal: abortController.signal,\n });\n\n await notify({\n method: 'OutboundRequest',\n params: { source: 'fetch' },\n });\n\n openFetchConnection = {\n cancel: async () => {\n abortController.abort();\n try {\n await fetchPromise;\n } catch {\n /* do nothing */\n }\n },\n };\n openConnections.add(openFetchConnection);\n\n res = new ResponseWrapper(\n await fetchPromise,\n teardownRef,\n onStart,\n onFinish,\n );\n } finally {\n if (openFetchConnection !== undefined) {\n openConnections.delete(openFetchConnection);\n }\n await notify({\n method: 'OutboundResponse',\n params: { source: 'fetch' },\n });\n }\n\n if (res.body !== null) {\n const body = new WeakRef<ReadableStream>(res.body);\n\n const openBodyConnection = {\n cancel:\n /* istanbul ignore next: see it.todo('can be torn down during body read') test */\n async () => {\n try {\n await body.deref()?.cancel();\n } catch {\n /* do nothing */\n }\n },\n };\n openConnections.add(openBodyConnection);\n cleanup.register(\n res.body,\n /* istanbul ignore next: can't test garbage collection without modifying node parameters */\n () => openConnections.delete(openBodyConnection),\n );\n }\n return harden(res);\n })(),\n teardownRef,\n );\n };\n\n const teardownFunction = async () => {\n teardownRef.lastTeardown += 1;\n const promises: Promise<void>[] = [];\n openConnections.forEach(({ cancel }) => promises.push(cancel()));\n openConnections.clear();\n await Promise.all(promises);\n };\n\n return {\n fetch: harden(_fetch),\n // Request, Headers and Response are the endowments injected alongside fetch\n // only when 'endowment:network-access' permission is requested,\n // therefore these are hardened as part of fetch dependency injection within its factory.\n // These endowments are not (and should never be) available by default.\n Request: harden(Request),\n Headers: harden(Headers),\n Response: harden(AlteredResponse),\n teardownFunction,\n };\n};\n\nconst endowmentModule = {\n names: ['fetch', 'Request', 'Headers', 'Response'] as const,\n factory: createNetwork,\n};\nexport default endowmentModule;\n"]}
1
+ {"version":3,"file":"network.mjs","sourceRoot":"","sources":["../../../src/common/endowments/network.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,wBAAwB;AAGzC,OAAO,EAAE,YAAY,EAAE,qBAAiB;AAExC;;;GAGG;AACH,MAAM,OAAO,eAAe;IACjB,YAAY,CAA2B;IAEvC,WAAW,CAAW;IAEtB,QAAQ,CAAsB;IAE9B,SAAS,CAAsB;IAExC,YACE,UAAoB,EACpB,WAAqC,EACrC,OAA4B,EAC5B,QAA6B;QAE7B,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;QAC9B,IAAI,CAAC,YAAY,GAAG,WAAW,CAAC;QAChC,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;QACxB,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;IAC5B,CAAC;IAED,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;IAC/B,CAAC;IAED,IAAI,QAAQ;QACV,OAAO,I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C,CAAC;QACjE,eAAe,CAAC,KAAK,EAAE,CAAC;QACxB,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC9B,CAAC,CAAC;IAEF,OAAO;QACL,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC;QACrB,4EAA4E;QAC5E,gEAAgE;QAChE,yFAAyF;QACzF,uEAAuE;QACvE,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC;QACxB,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC;QACxB,QAAQ,EAAE,MAAM,CAAC,eAAe,CAAC;QACjC,gBAAgB;KACjB,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,eAAe,GAAG;IACtB,KAAK,EAAE,CAAC,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,CAAU;IAC3D,OAAO,EAAE,aAAa;CACvB,CAAC;AACF,eAAe,eAAe,CAAC","sourcesContent":["import { assert } from '@metamask/utils';\n\nimport type { EndowmentFactoryOptions } from './commonEndowmentFactory';\nimport { withTeardown } from '../utils';\n\n/**\n * This class wraps a Response object.\n * That way, a teardown process can stop any processes left.\n */\nexport class ResponseWrapper implements Response {\n readonly #teardownRef: { lastTeardown: number };\n\n readonly #ogResponse: Response;\n\n readonly #onStart: () => Promise<void>;\n\n readonly #onFinish: () => Promise<void>;\n\n constructor(\n ogResponse: Response,\n teardownRef: { lastTeardown: number },\n onStart: () => Promise<void>,\n onFinish: () => Promise<void>,\n ) {\n this.#ogResponse = ogResponse;\n this.#teardownRef = teardownRef;\n this.#onStart = onStart;\n this.#onFinish = onFinish;\n }\n\n get body(): ReadableStream<Uint8Array> | null {\n return this.#ogResponse.body;\n }\n\n get bodyUsed() {\n return this.#ogResponse.bodyUsed;\n }\n\n get headers() {\n return this.#ogResponse.headers;\n }\n\n get ok() {\n return this.#ogResponse.ok;\n }\n\n get redirected() {\n return this.#ogResponse.redirected;\n }\n\n get status() {\n return this.#ogResponse.status;\n }\n\n get statusText() {\n return this.#ogResponse.statusText;\n }\n\n get type() {\n return this.#ogResponse.type;\n }\n\n get url() {\n return this.#ogResponse.url;\n }\n\n async text() {\n return await withTeardown<string>(\n (async () => {\n await this.#onStart();\n try {\n return await this.#ogResponse.text();\n } finally {\n await this.#onFinish();\n }\n })(),\n this.#teardownRef,\n );\n }\n\n async arrayBuffer(): Promise<ArrayBuffer> {\n return await withTeardown<ArrayBuffer>(\n (async () => {\n await this.#onStart();\n try {\n return await this.#ogResponse.arrayBuffer();\n } finally {\n await this.#onFinish();\n }\n })(),\n this.#teardownRef,\n );\n }\n\n async blob(): Promise<Blob> {\n return await withTeardown<Blob>(\n (async () => {\n await this.#onStart();\n try {\n return await this.#ogResponse.blob();\n } finally {\n await this.#onFinish();\n }\n })(),\n this.#teardownRef,\n );\n }\n\n clone(): Response {\n const newResponse = this.#ogResponse.clone();\n return new ResponseWrapper(\n newResponse,\n this.#teardownRef,\n this.#onStart,\n this.#onFinish,\n );\n }\n\n async formData(): Promise<FormData> {\n return await withTeardown<FormData>(\n (async () => {\n await this.#onStart();\n try {\n return await this.#ogResponse.formData();\n } finally {\n await this.#onFinish();\n }\n })(),\n this.#teardownRef,\n );\n }\n\n async json(): Promise<any> {\n return await withTeardown(\n (async () => {\n await this.#onStart();\n try {\n return await this.#ogResponse.json();\n } finally {\n await this.#onFinish();\n }\n })(),\n this.#teardownRef,\n );\n }\n}\n\n// We redefine the global Response class to overwrite [Symbol.hasInstance].\n// This fixes problems where the response from `fetch` would not pass\n// instance of checks, leading to failures in WASM bindgen.\nclass AlteredResponse extends Response {\n static [Symbol.hasInstance](instance: unknown) {\n return instance instanceof Response || instance instanceof ResponseWrapper;\n }\n}\n\n/**\n * Create a network endowment, consisting of a `fetch` function.\n * This allows us to provide a teardown function, so that we can cancel\n * any pending requests, connections, streams, etc. that may be open when the\n * execution context is torn down.\n *\n * This wraps the original implementation of `fetch`,\n * to ensure that a bad actor cannot get access to the original function, thus\n * potentially preventing the network requests from being torn down.\n *\n * @param options - An options bag.\n * @param options.notify - A notification callback for outbound request\n * lifecycle events.\n * @returns An object containing a wrapped `fetch`\n * function, as well as a teardown function.\n */\nconst createNetwork = ({ notify }: EndowmentFactoryOptions = {}) => {\n assert(\n notify,\n 'The \"notify\" callback is required by the network endowment factory.',\n );\n // Open fetch calls or open body streams\n const openConnections = new Set<{ cancel: () => Promise<void> }>();\n // Track last teardown count\n const teardownRef = { lastTeardown: 0 };\n\n // Remove items from openConnections after they were garbage collected\n const cleanup = new FinalizationRegistry<() => void>(\n /* istanbul ignore next: can't test garbage collection without modifying node parameters */\n (callback) => callback(),\n );\n\n const _fetch: typeof fetch = async (\n input: RequestInfo | URL,\n init?: RequestInit,\n ): Promise<Response> => {\n const abortController = new AbortController();\n if (init?.signal !== null && init?.signal !== undefined) {\n const originalSignal = init.signal;\n // Merge abort controllers\n originalSignal.addEventListener(\n 'abort',\n () => {\n abortController.abort((originalSignal as any).reason);\n },\n { once: true },\n );\n }\n\n let started = false;\n const onStart = async () => {\n if (!started) {\n started = true;\n await notify({\n method: 'OutboundRequest',\n params: { source: 'fetch' },\n });\n }\n };\n\n let finished = false;\n const onFinish = async () => {\n if (!finished) {\n finished = true;\n await notify({\n method: 'OutboundResponse',\n params: { source: 'fetch' },\n });\n }\n };\n\n let res: Response;\n let openFetchConnection: { cancel: () => Promise<void> } | undefined;\n return await withTeardown(\n (async () => {\n try {\n const fetchPromise = fetch(input, {\n ...init,\n signal: abortController.signal,\n });\n\n await notify({\n method: 'OutboundRequest',\n params: { source: 'fetch' },\n });\n\n openFetchConnection = {\n cancel: async () => {\n abortController.abort();\n try {\n await fetchPromise;\n } catch {\n /* do nothing */\n }\n },\n };\n openConnections.add(openFetchConnection);\n\n res = new ResponseWrapper(\n await fetchPromise,\n teardownRef,\n onStart,\n onFinish,\n );\n } finally {\n if (openFetchConnection !== undefined) {\n openConnections.delete(openFetchConnection);\n }\n await notify({\n method: 'OutboundResponse',\n params: { source: 'fetch' },\n });\n }\n\n if (res.body !== null) {\n const body = new WeakRef<ReadableStream>(res.body);\n\n const openBodyConnection = {\n cancel:\n /* istanbul ignore next: see it.todo('can be torn down during body read') test */\n async () => {\n try {\n await body.deref()?.cancel();\n } catch {\n /* do nothing */\n }\n },\n };\n openConnections.add(openBodyConnection);\n cleanup.register(\n res.body,\n /* istanbul ignore next: can't test garbage collection without modifying node parameters */\n () => openConnections.delete(openBodyConnection),\n );\n }\n return harden(res);\n })(),\n teardownRef,\n );\n };\n\n const teardownFunction = async () => {\n teardownRef.lastTeardown += 1;\n const promises: Promise<void>[] = [];\n openConnections.forEach(({ cancel }) => promises.push(cancel()));\n openConnections.clear();\n await Promise.all(promises);\n };\n\n return {\n fetch: harden(_fetch),\n // Request, Headers and Response are the endowments injected alongside fetch\n // only when 'endowment:network-access' permission is requested,\n // therefore these are hardened as part of fetch dependency injection within its factory.\n // These endowments are not (and should never be) available by default.\n Request: harden(Request),\n Headers: harden(Headers),\n Response: harden(AlteredResponse),\n teardownFunction,\n };\n};\n\nconst endowmentModule = {\n names: ['fetch', 'Request', 'Headers', 'Response'] as const,\n factory: createNetwork,\n};\nexport default endowmentModule;\n"]}
@@ -3,14 +3,14 @@ import type { Infer, Struct } from "@metamask/superstruct";
3
3
  import type { CaipChainId, JsonRpcRequest } from "@metamask/utils";
4
4
  export declare const JsonRpcRequestWithoutIdStruct: Struct<{
5
5
  method: string;
6
+ params?: import("@metamask/snaps-sdk").Json[] | Record<string, import("@metamask/snaps-sdk").Json> | undefined;
6
7
  jsonrpc?: "2.0" | undefined;
7
8
  id?: string | number | null | undefined;
8
- params?: Record<string, import("@metamask/snaps-sdk").Json> | import("@metamask/snaps-sdk").Json[] | undefined;
9
9
  }, {
10
10
  jsonrpc: Struct<"2.0" | undefined, "2.0">;
11
11
  id: Struct<string | number | null | undefined, null>;
12
12
  method: Struct<string, null>;
13
- params: Struct<Record<string, import("@metamask/snaps-sdk").Json> | import("@metamask/snaps-sdk").Json[] | undefined, null>;
13
+ params: Struct<import("@metamask/snaps-sdk").Json[] | Record<string, import("@metamask/snaps-sdk").Json> | undefined, null>;
14
14
  }>;
15
15
  export type JsonRpcRequestWithoutId = Infer<typeof JsonRpcRequestWithoutIdStruct>;
16
16
  export declare const EndowmentStruct: Struct<string, null>;
@@ -41,15 +41,15 @@ export declare const ExecuteSnapRequestArgumentsStruct: Struct<{
41
41
  endowments: Struct<string[], Struct<string, null>>;
42
42
  }>;
43
43
  export declare const SnapRpcRequestArgumentsStruct: Struct<{
44
- snapId: string;
45
- handler: HandlerType;
46
- origin: string;
47
44
  request: {
48
45
  method: string;
46
+ params?: Record<string, any> | undefined;
49
47
  jsonrpc?: "2.0" | undefined;
50
48
  id?: string | number | null | undefined;
51
- params?: Record<string, any> | undefined;
52
49
  };
50
+ origin: string;
51
+ snapId: string;
52
+ handler: HandlerType;
53
53
  }, {
54
54
  snapId: Struct<string, null>;
55
55
  handler: Struct<HandlerType, {
@@ -78,14 +78,14 @@ export declare const SnapRpcRequestArgumentsStruct: Struct<{
78
78
  origin: Struct<string, null>;
79
79
  request: Struct<{
80
80
  method: string;
81
+ params?: Record<string, any> | undefined;
81
82
  jsonrpc?: "2.0" | undefined;
82
83
  id?: string | number | null | undefined;
83
- params?: Record<string, any> | undefined;
84
84
  }, {
85
85
  params: Struct<Record<string, any> | undefined, null>;
86
+ method: Struct<string, null>;
86
87
  jsonrpc: Struct<"2.0" | undefined, "2.0">;
87
88
  id: Struct<string | number | null | undefined, null>;
88
- method: Struct<string, null>;
89
89
  }>;
90
90
  }>;
91
91
  export type PingRequestArguments = Infer<typeof PingRequestArgumentsStruct>;
@@ -351,12 +351,12 @@ export type OnProtocolRequestArguments = Infer<typeof OnProtocolRequestArguments
351
351
  */
352
352
  export declare function assertIsOnProtocolRequestArguments(value: unknown): asserts value is OnProtocolRequestArguments;
353
353
  export declare const WebSocketEventStruct: Struct<{
354
- id: string;
355
354
  origin: string;
355
+ id: string;
356
356
  type: "open";
357
357
  } | {
358
- id: string;
359
358
  origin: string;
359
+ id: string;
360
360
  type: "close";
361
361
  code: number;
362
362
  reason: string | null;
@@ -369,18 +369,18 @@ export declare const WebSocketEventStruct: Struct<{
369
369
  type: "binary";
370
370
  message: number[];
371
371
  };
372
- id: string;
373
372
  origin: string;
373
+ id: string;
374
374
  type: "message";
375
375
  }, null>;
376
376
  export declare const OnWebSocketEventArgumentsStruct: Struct<{
377
377
  event: {
378
- id: string;
379
378
  origin: string;
379
+ id: string;
380
380
  type: "open";
381
381
  } | {
382
- id: string;
383
382
  origin: string;
383
+ id: string;
384
384
  type: "close";
385
385
  code: number;
386
386
  reason: string | null;
@@ -393,18 +393,18 @@ export declare const OnWebSocketEventArgumentsStruct: Struct<{
393
393
  type: "binary";
394
394
  message: number[];
395
395
  };
396
- id: string;
397
396
  origin: string;
397
+ id: string;
398
398
  type: "message";
399
399
  };
400
400
  }, {
401
401
  event: Struct<{
402
- id: string;
403
402
  origin: string;
403
+ id: string;
404
404
  type: "open";
405
405
  } | {
406
- id: string;
407
406
  origin: string;
407
+ id: string;
408
408
  type: "close";
409
409
  code: number;
410
410
  reason: string | null;
@@ -417,8 +417,8 @@ export declare const OnWebSocketEventArgumentsStruct: Struct<{
417
417
  type: "binary";
418
418
  message: number[];
419
419
  };
420
- id: string;
421
420
  origin: string;
421
+ id: string;
422
422
  type: "message";
423
423
  }, null>;
424
424
  }>;
@@ -3,14 +3,14 @@ import type { Infer, Struct } from "@metamask/superstruct";
3
3
  import type { CaipChainId, JsonRpcRequest } from "@metamask/utils";
4
4
  export declare const JsonRpcRequestWithoutIdStruct: Struct<{
5
5
  method: string;
6
+ params?: import("@metamask/snaps-sdk").Json[] | Record<string, import("@metamask/snaps-sdk").Json> | undefined;
6
7
  jsonrpc?: "2.0" | undefined;
7
8
  id?: string | number | null | undefined;
8
- params?: Record<string, import("@metamask/snaps-sdk").Json> | import("@metamask/snaps-sdk").Json[] | undefined;
9
9
  }, {
10
10
  jsonrpc: Struct<"2.0" | undefined, "2.0">;
11
11
  id: Struct<string | number | null | undefined, null>;
12
12
  method: Struct<string, null>;
13
- params: Struct<Record<string, import("@metamask/snaps-sdk").Json> | import("@metamask/snaps-sdk").Json[] | undefined, null>;
13
+ params: Struct<import("@metamask/snaps-sdk").Json[] | Record<string, import("@metamask/snaps-sdk").Json> | undefined, null>;
14
14
  }>;
15
15
  export type JsonRpcRequestWithoutId = Infer<typeof JsonRpcRequestWithoutIdStruct>;
16
16
  export declare const EndowmentStruct: Struct<string, null>;
@@ -41,15 +41,15 @@ export declare const ExecuteSnapRequestArgumentsStruct: Struct<{
41
41
  endowments: Struct<string[], Struct<string, null>>;
42
42
  }>;
43
43
  export declare const SnapRpcRequestArgumentsStruct: Struct<{
44
- snapId: string;
45
- handler: HandlerType;
46
- origin: string;
47
44
  request: {
48
45
  method: string;
46
+ params?: Record<string, any> | undefined;
49
47
  jsonrpc?: "2.0" | undefined;
50
48
  id?: string | number | null | undefined;
51
- params?: Record<string, any> | undefined;
52
49
  };
50
+ origin: string;
51
+ snapId: string;
52
+ handler: HandlerType;
53
53
  }, {
54
54
  snapId: Struct<string, null>;
55
55
  handler: Struct<HandlerType, {
@@ -78,14 +78,14 @@ export declare const SnapRpcRequestArgumentsStruct: Struct<{
78
78
  origin: Struct<string, null>;
79
79
  request: Struct<{
80
80
  method: string;
81
+ params?: Record<string, any> | undefined;
81
82
  jsonrpc?: "2.0" | undefined;
82
83
  id?: string | number | null | undefined;
83
- params?: Record<string, any> | undefined;
84
84
  }, {
85
85
  params: Struct<Record<string, any> | undefined, null>;
86
+ method: Struct<string, null>;
86
87
  jsonrpc: Struct<"2.0" | undefined, "2.0">;
87
88
  id: Struct<string | number | null | undefined, null>;
88
- method: Struct<string, null>;
89
89
  }>;
90
90
  }>;
91
91
  export type PingRequestArguments = Infer<typeof PingRequestArgumentsStruct>;
@@ -351,12 +351,12 @@ export type OnProtocolRequestArguments = Infer<typeof OnProtocolRequestArguments
351
351
  */
352
352
  export declare function assertIsOnProtocolRequestArguments(value: unknown): asserts value is OnProtocolRequestArguments;
353
353
  export declare const WebSocketEventStruct: Struct<{
354
- id: string;
355
354
  origin: string;
355
+ id: string;
356
356
  type: "open";
357
357
  } | {
358
- id: string;
359
358
  origin: string;
359
+ id: string;
360
360
  type: "close";
361
361
  code: number;
362
362
  reason: string | null;
@@ -369,18 +369,18 @@ export declare const WebSocketEventStruct: Struct<{
369
369
  type: "binary";
370
370
  message: number[];
371
371
  };
372
- id: string;
373
372
  origin: string;
373
+ id: string;
374
374
  type: "message";
375
375
  }, null>;
376
376
  export declare const OnWebSocketEventArgumentsStruct: Struct<{
377
377
  event: {
378
- id: string;
379
378
  origin: string;
379
+ id: string;
380
380
  type: "open";
381
381
  } | {
382
- id: string;
383
382
  origin: string;
383
+ id: string;
384
384
  type: "close";
385
385
  code: number;
386
386
  reason: string | null;
@@ -393,18 +393,18 @@ export declare const OnWebSocketEventArgumentsStruct: Struct<{
393
393
  type: "binary";
394
394
  message: number[];
395
395
  };
396
- id: string;
397
396
  origin: string;
397
+ id: string;
398
398
  type: "message";
399
399
  };
400
400
  }, {
401
401
  event: Struct<{
402
- id: string;
403
402
  origin: string;
403
+ id: string;
404
404
  type: "open";
405
405
  } | {
406
- id: string;
407
406
  origin: string;
407
+ id: string;
408
408
  type: "close";
409
409
  code: number;
410
410
  reason: string | null;
@@ -417,8 +417,8 @@ export declare const OnWebSocketEventArgumentsStruct: Struct<{
417
417
  type: "binary";
418
418
  message: number[];
419
419
  };
420
- id: string;
421
420
  origin: string;
421
+ id: string;
422
422
  type: "message";
423
423
  }, null>;
424
424
  }>;
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ /**
3
+ * Public endowment factory exports for use outside the Snaps ecosystem.
4
+ *
5
+ * **Prerequisite**: These factories call the SES `harden()` global internally.
6
+ * The consuming environment must have loaded SES and called `lockdown()` before
7
+ * invoking any factory function.
8
+ *
9
+ * Each module provides a `names` array and a `factory` function. Call
10
+ * `factory()` to obtain hardened endowment values (and an optional
11
+ * `teardownFunction` for stateful endowments that manage resources).
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * import { timeout, date } from '@metamask/snaps-execution-environments/endowments';
16
+ *
17
+ * const timers = timeout.factory();
18
+ * // { setTimeout, clearTimeout, teardownFunction }
19
+ *
20
+ * const dateEndowment = date.factory();
21
+ * // { Date } (with attenuated Date.now)
22
+ * ```
23
+ *
24
+ * @module endowments
25
+ */
26
+ var __importDefault = (this && this.__importDefault) || function (mod) {
27
+ return (mod && mod.__esModule) ? mod : { "default": mod };
28
+ };
29
+ Object.defineProperty(exports, "__esModule", { value: true });
30
+ exports.buildCommonEndowments = exports.network = exports.consoleEndowment = exports.math = exports.crypto = exports.textDecoder = exports.textEncoder = exports.date = exports.interval = exports.timeout = void 0;
31
+ const console_1 = __importDefault(require("./common/endowments/console.cjs"));
32
+ const network_1 = __importDefault(require("./common/endowments/network.cjs"));
33
+ // Individual endowment factory modules with no required options
34
+ var timeout_1 = require("./common/endowments/timeout.cjs");
35
+ Object.defineProperty(exports, "timeout", { enumerable: true, get: function () { return __importDefault(timeout_1).default; } });
36
+ var interval_1 = require("./common/endowments/interval.cjs");
37
+ Object.defineProperty(exports, "interval", { enumerable: true, get: function () { return __importDefault(interval_1).default; } });
38
+ var date_1 = require("./common/endowments/date.cjs");
39
+ Object.defineProperty(exports, "date", { enumerable: true, get: function () { return __importDefault(date_1).default; } });
40
+ var textEncoder_1 = require("./common/endowments/textEncoder.cjs");
41
+ Object.defineProperty(exports, "textEncoder", { enumerable: true, get: function () { return __importDefault(textEncoder_1).default; } });
42
+ var textDecoder_1 = require("./common/endowments/textDecoder.cjs");
43
+ Object.defineProperty(exports, "textDecoder", { enumerable: true, get: function () { return __importDefault(textDecoder_1).default; } });
44
+ var crypto_1 = require("./common/endowments/crypto.cjs");
45
+ Object.defineProperty(exports, "crypto", { enumerable: true, get: function () { return __importDefault(crypto_1).default; } });
46
+ var math_1 = require("./common/endowments/math.cjs");
47
+ Object.defineProperty(exports, "math", { enumerable: true, get: function () { return __importDefault(math_1).default; } });
48
+ /**
49
+ * The console endowment factory. Produces an attenuated `console` object that
50
+ * prefixes output with the provided source label.
51
+ */
52
+ exports.consoleEndowment = console_1.default;
53
+ /**
54
+ * The network endowment factory. Produces a wrapped `fetch` function and
55
+ * related types with teardown support.
56
+ */
57
+ exports.network = network_1.default;
58
+ // Consolidated factory builder and types
59
+ var commonEndowmentFactory_1 = require("./common/endowments/commonEndowmentFactory.cjs");
60
+ Object.defineProperty(exports, "buildCommonEndowments", { enumerable: true, get: function () { return __importDefault(commonEndowmentFactory_1).default; } });
61
+ //# sourceMappingURL=endowments.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"endowments.cjs","sourceRoot":"","sources":["../src/endowments.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;;;;;;AAMH,8EAAiE;AACjE,8EAAwD;AAExD,gEAAgE;AAChE,2DAAiE;AAAxD,mHAAA,OAAO,OAAW;AAC3B,6DAAmE;AAA1D,qHAAA,OAAO,OAAY;AAC5B,qDAA2D;AAAlD,6GAAA,OAAO,OAAQ;AACxB,mEAAyE;AAAhE,2HAAA,OAAO,OAAe;AAC/B,mEAAyE;AAAhE,2HAAA,OAAO,OAAe;AAC/B,yDAA+D;AAAtD,iHAAA,OAAO,OAAU;AAC1B,qDAA2D;AAAlD,6GAAA,OAAO,OAAQ;AAgBxB;;;GAGG;AACU,QAAA,gBAAgB,GAGzB,iBAAsB,CAAC;AAE3B;;;GAGG;AACU,QAAA,OAAO,GAGhB,iBAAa,CAAC;AAElB,yCAAyC;AACzC,yFAA8F;AAArF,gJAAA,OAAO,OAAyB","sourcesContent":["/**\n * Public endowment factory exports for use outside the Snaps ecosystem.\n *\n * **Prerequisite**: These factories call the SES `harden()` global internally.\n * The consuming environment must have loaded SES and called `lockdown()` before\n * invoking any factory function.\n *\n * Each module provides a `names` array and a `factory` function. Call\n * `factory()` to obtain hardened endowment values (and an optional\n * `teardownFunction` for stateful endowments that manage resources).\n *\n * @example\n * ```ts\n * import { timeout, date } from '@metamask/snaps-execution-environments/endowments';\n *\n * const timers = timeout.factory();\n * // { setTimeout, clearTimeout, teardownFunction }\n *\n * const dateEndowment = date.factory();\n * // { Date } (with attenuated Date.now)\n * ```\n *\n * @module endowments\n */\n\nimport type {\n EndowmentFactoryOptions,\n EndowmentFactoryResult,\n} from './common/endowments/commonEndowmentFactory';\nimport consoleEndowmentModule from './common/endowments/console';\nimport networkModule from './common/endowments/network';\n\n// Individual endowment factory modules with no required options\nexport { default as timeout } from './common/endowments/timeout';\nexport { default as interval } from './common/endowments/interval';\nexport { default as date } from './common/endowments/date';\nexport { default as textEncoder } from './common/endowments/textEncoder';\nexport { default as textDecoder } from './common/endowments/textDecoder';\nexport { default as crypto } from './common/endowments/crypto';\nexport { default as math } from './common/endowments/math';\n\n/**\n * Options required by the console endowment factory.\n */\nexport type ConsoleEndowmentOptions = Required<\n Pick<EndowmentFactoryOptions, 'sourceLabel'>\n>;\n\n/**\n * Options required by the network endowment factory.\n */\nexport type NetworkEndowmentOptions = Required<\n Pick<EndowmentFactoryOptions, 'notify'>\n>;\n\n/**\n * The console endowment factory. Produces an attenuated `console` object that\n * prefixes output with the provided source label.\n */\nexport const consoleEndowment: {\n readonly names: readonly ['console'];\n factory: (options: ConsoleEndowmentOptions) => EndowmentFactoryResult;\n} = consoleEndowmentModule;\n\n/**\n * The network endowment factory. Produces a wrapped `fetch` function and\n * related types with teardown support.\n */\nexport const network: {\n readonly names: readonly ['fetch', 'Request', 'Headers', 'Response'];\n factory: (options: NetworkEndowmentOptions) => EndowmentFactoryResult;\n} = networkModule;\n\n// Consolidated factory builder and types\nexport { default as buildCommonEndowments } from './common/endowments/commonEndowmentFactory';\nexport type {\n NotifyFunction,\n EndowmentFactoryOptions,\n EndowmentFactoryResult,\n EndowmentFactory,\n} from './common/endowments/commonEndowmentFactory';\n"]}
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Public endowment factory exports for use outside the Snaps ecosystem.
3
+ *
4
+ * **Prerequisite**: These factories call the SES `harden()` global internally.
5
+ * The consuming environment must have loaded SES and called `lockdown()` before
6
+ * invoking any factory function.
7
+ *
8
+ * Each module provides a `names` array and a `factory` function. Call
9
+ * `factory()` to obtain hardened endowment values (and an optional
10
+ * `teardownFunction` for stateful endowments that manage resources).
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * import { timeout, date } from '@metamask/snaps-execution-environments/endowments';
15
+ *
16
+ * const timers = timeout.factory();
17
+ * // { setTimeout, clearTimeout, teardownFunction }
18
+ *
19
+ * const dateEndowment = date.factory();
20
+ * // { Date } (with attenuated Date.now)
21
+ * ```
22
+ *
23
+ * @module endowments
24
+ */
25
+ import type { EndowmentFactoryOptions, EndowmentFactoryResult } from "./common/endowments/commonEndowmentFactory.cjs";
26
+ export { default as timeout } from "./common/endowments/timeout.cjs";
27
+ export { default as interval } from "./common/endowments/interval.cjs";
28
+ export { default as date } from "./common/endowments/date.cjs";
29
+ export { default as textEncoder } from "./common/endowments/textEncoder.cjs";
30
+ export { default as textDecoder } from "./common/endowments/textDecoder.cjs";
31
+ export { default as crypto } from "./common/endowments/crypto.cjs";
32
+ export { default as math } from "./common/endowments/math.cjs";
33
+ /**
34
+ * Options required by the console endowment factory.
35
+ */
36
+ export type ConsoleEndowmentOptions = Required<Pick<EndowmentFactoryOptions, 'sourceLabel'>>;
37
+ /**
38
+ * Options required by the network endowment factory.
39
+ */
40
+ export type NetworkEndowmentOptions = Required<Pick<EndowmentFactoryOptions, 'notify'>>;
41
+ /**
42
+ * The console endowment factory. Produces an attenuated `console` object that
43
+ * prefixes output with the provided source label.
44
+ */
45
+ export declare const consoleEndowment: {
46
+ readonly names: readonly ['console'];
47
+ factory: (options: ConsoleEndowmentOptions) => EndowmentFactoryResult;
48
+ };
49
+ /**
50
+ * The network endowment factory. Produces a wrapped `fetch` function and
51
+ * related types with teardown support.
52
+ */
53
+ export declare const network: {
54
+ readonly names: readonly ['fetch', 'Request', 'Headers', 'Response'];
55
+ factory: (options: NetworkEndowmentOptions) => EndowmentFactoryResult;
56
+ };
57
+ export { default as buildCommonEndowments } from "./common/endowments/commonEndowmentFactory.cjs";
58
+ export type { NotifyFunction, EndowmentFactoryOptions, EndowmentFactoryResult, EndowmentFactory, } from "./common/endowments/commonEndowmentFactory.cjs";
59
+ //# sourceMappingURL=endowments.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"endowments.d.cts","sourceRoot":"","sources":["../src/endowments.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,KAAK,EACV,uBAAuB,EACvB,sBAAsB,EACvB,uDAAmD;AAKpD,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,wCAAoC;AACjE,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,yCAAqC;AACnE,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,qCAAiC;AAC3D,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,4CAAwC;AACzE,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,4CAAwC;AACzE,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,uCAAmC;AAC/D,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,qCAAiC;AAE3D;;GAEG;AACH,MAAM,MAAM,uBAAuB,GAAG,QAAQ,CAC5C,IAAI,CAAC,uBAAuB,EAAE,aAAa,CAAC,CAC7C,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,uBAAuB,GAAG,QAAQ,CAC5C,IAAI,CAAC,uBAAuB,EAAE,QAAQ,CAAC,CACxC,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,gBAAgB,EAAE;IAC7B,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IACrC,OAAO,EAAE,CAAC,OAAO,EAAE,uBAAuB,KAAK,sBAAsB,CAAC;CAC9C,CAAC;AAE3B;;;GAGG;AACH,eAAO,MAAM,OAAO,EAAE;IACpB,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC;IACrE,OAAO,EAAE,CAAC,OAAO,EAAE,uBAAuB,KAAK,sBAAsB,CAAC;CACvD,CAAC;AAGlB,OAAO,EAAE,OAAO,IAAI,qBAAqB,EAAE,uDAAmD;AAC9F,YAAY,EACV,cAAc,EACd,uBAAuB,EACvB,sBAAsB,EACtB,gBAAgB,GACjB,uDAAmD"}
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Public endowment factory exports for use outside the Snaps ecosystem.
3
+ *
4
+ * **Prerequisite**: These factories call the SES `harden()` global internally.
5
+ * The consuming environment must have loaded SES and called `lockdown()` before
6
+ * invoking any factory function.
7
+ *
8
+ * Each module provides a `names` array and a `factory` function. Call
9
+ * `factory()` to obtain hardened endowment values (and an optional
10
+ * `teardownFunction` for stateful endowments that manage resources).
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * import { timeout, date } from '@metamask/snaps-execution-environments/endowments';
15
+ *
16
+ * const timers = timeout.factory();
17
+ * // { setTimeout, clearTimeout, teardownFunction }
18
+ *
19
+ * const dateEndowment = date.factory();
20
+ * // { Date } (with attenuated Date.now)
21
+ * ```
22
+ *
23
+ * @module endowments
24
+ */
25
+ import type { EndowmentFactoryOptions, EndowmentFactoryResult } from "./common/endowments/commonEndowmentFactory.mjs";
26
+ export { default as timeout } from "./common/endowments/timeout.mjs";
27
+ export { default as interval } from "./common/endowments/interval.mjs";
28
+ export { default as date } from "./common/endowments/date.mjs";
29
+ export { default as textEncoder } from "./common/endowments/textEncoder.mjs";
30
+ export { default as textDecoder } from "./common/endowments/textDecoder.mjs";
31
+ export { default as crypto } from "./common/endowments/crypto.mjs";
32
+ export { default as math } from "./common/endowments/math.mjs";
33
+ /**
34
+ * Options required by the console endowment factory.
35
+ */
36
+ export type ConsoleEndowmentOptions = Required<Pick<EndowmentFactoryOptions, 'sourceLabel'>>;
37
+ /**
38
+ * Options required by the network endowment factory.
39
+ */
40
+ export type NetworkEndowmentOptions = Required<Pick<EndowmentFactoryOptions, 'notify'>>;
41
+ /**
42
+ * The console endowment factory. Produces an attenuated `console` object that
43
+ * prefixes output with the provided source label.
44
+ */
45
+ export declare const consoleEndowment: {
46
+ readonly names: readonly ['console'];
47
+ factory: (options: ConsoleEndowmentOptions) => EndowmentFactoryResult;
48
+ };
49
+ /**
50
+ * The network endowment factory. Produces a wrapped `fetch` function and
51
+ * related types with teardown support.
52
+ */
53
+ export declare const network: {
54
+ readonly names: readonly ['fetch', 'Request', 'Headers', 'Response'];
55
+ factory: (options: NetworkEndowmentOptions) => EndowmentFactoryResult;
56
+ };
57
+ export { default as buildCommonEndowments } from "./common/endowments/commonEndowmentFactory.mjs";
58
+ export type { NotifyFunction, EndowmentFactoryOptions, EndowmentFactoryResult, EndowmentFactory, } from "./common/endowments/commonEndowmentFactory.mjs";
59
+ //# sourceMappingURL=endowments.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"endowments.d.mts","sourceRoot":"","sources":["../src/endowments.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,KAAK,EACV,uBAAuB,EACvB,sBAAsB,EACvB,uDAAmD;AAKpD,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,wCAAoC;AACjE,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,yCAAqC;AACnE,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,qCAAiC;AAC3D,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,4CAAwC;AACzE,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,4CAAwC;AACzE,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,uCAAmC;AAC/D,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,qCAAiC;AAE3D;;GAEG;AACH,MAAM,MAAM,uBAAuB,GAAG,QAAQ,CAC5C,IAAI,CAAC,uBAAuB,EAAE,aAAa,CAAC,CAC7C,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,uBAAuB,GAAG,QAAQ,CAC5C,IAAI,CAAC,uBAAuB,EAAE,QAAQ,CAAC,CACxC,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,gBAAgB,EAAE;IAC7B,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IACrC,OAAO,EAAE,CAAC,OAAO,EAAE,uBAAuB,KAAK,sBAAsB,CAAC;CAC9C,CAAC;AAE3B;;;GAGG;AACH,eAAO,MAAM,OAAO,EAAE;IACpB,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC;IACrE,OAAO,EAAE,CAAC,OAAO,EAAE,uBAAuB,KAAK,sBAAsB,CAAC;CACvD,CAAC;AAGlB,OAAO,EAAE,OAAO,IAAI,qBAAqB,EAAE,uDAAmD;AAC9F,YAAY,EACV,cAAc,EACd,uBAAuB,EACvB,sBAAsB,EACtB,gBAAgB,GACjB,uDAAmD"}
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Public endowment factory exports for use outside the Snaps ecosystem.
3
+ *
4
+ * **Prerequisite**: These factories call the SES `harden()` global internally.
5
+ * The consuming environment must have loaded SES and called `lockdown()` before
6
+ * invoking any factory function.
7
+ *
8
+ * Each module provides a `names` array and a `factory` function. Call
9
+ * `factory()` to obtain hardened endowment values (and an optional
10
+ * `teardownFunction` for stateful endowments that manage resources).
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * import { timeout, date } from '@metamask/snaps-execution-environments/endowments';
15
+ *
16
+ * const timers = timeout.factory();
17
+ * // { setTimeout, clearTimeout, teardownFunction }
18
+ *
19
+ * const dateEndowment = date.factory();
20
+ * // { Date } (with attenuated Date.now)
21
+ * ```
22
+ *
23
+ * @module endowments
24
+ */
25
+ import consoleEndowmentModule from "./common/endowments/console.mjs";
26
+ import networkModule from "./common/endowments/network.mjs";
27
+ // Individual endowment factory modules with no required options
28
+ export { default as timeout } from "./common/endowments/timeout.mjs";
29
+ export { default as interval } from "./common/endowments/interval.mjs";
30
+ export { default as date } from "./common/endowments/date.mjs";
31
+ export { default as textEncoder } from "./common/endowments/textEncoder.mjs";
32
+ export { default as textDecoder } from "./common/endowments/textDecoder.mjs";
33
+ export { default as crypto } from "./common/endowments/crypto.mjs";
34
+ export { default as math } from "./common/endowments/math.mjs";
35
+ /**
36
+ * The console endowment factory. Produces an attenuated `console` object that
37
+ * prefixes output with the provided source label.
38
+ */
39
+ export const consoleEndowment = consoleEndowmentModule;
40
+ /**
41
+ * The network endowment factory. Produces a wrapped `fetch` function and
42
+ * related types with teardown support.
43
+ */
44
+ export const network = networkModule;
45
+ // Consolidated factory builder and types
46
+ export { default as buildCommonEndowments } from "./common/endowments/commonEndowmentFactory.mjs";
47
+ //# sourceMappingURL=endowments.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"endowments.mjs","sourceRoot":"","sources":["../src/endowments.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAMH,OAAO,sBAAsB,wCAAoC;AACjE,OAAO,aAAa,wCAAoC;AAExD,gEAAgE;AAChE,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,wCAAoC;AACjE,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,yCAAqC;AACnE,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,qCAAiC;AAC3D,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,4CAAwC;AACzE,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,4CAAwC;AACzE,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,uCAAmC;AAC/D,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,qCAAiC;AAgB3D;;;GAGG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAGzB,sBAAsB,CAAC;AAE3B;;;GAGG;AACH,MAAM,CAAC,MAAM,OAAO,GAGhB,aAAa,CAAC;AAElB,yCAAyC;AACzC,OAAO,EAAE,OAAO,IAAI,qBAAqB,EAAE,uDAAmD","sourcesContent":["/**\n * Public endowment factory exports for use outside the Snaps ecosystem.\n *\n * **Prerequisite**: These factories call the SES `harden()` global internally.\n * The consuming environment must have loaded SES and called `lockdown()` before\n * invoking any factory function.\n *\n * Each module provides a `names` array and a `factory` function. Call\n * `factory()` to obtain hardened endowment values (and an optional\n * `teardownFunction` for stateful endowments that manage resources).\n *\n * @example\n * ```ts\n * import { timeout, date } from '@metamask/snaps-execution-environments/endowments';\n *\n * const timers = timeout.factory();\n * // { setTimeout, clearTimeout, teardownFunction }\n *\n * const dateEndowment = date.factory();\n * // { Date } (with attenuated Date.now)\n * ```\n *\n * @module endowments\n */\n\nimport type {\n EndowmentFactoryOptions,\n EndowmentFactoryResult,\n} from './common/endowments/commonEndowmentFactory';\nimport consoleEndowmentModule from './common/endowments/console';\nimport networkModule from './common/endowments/network';\n\n// Individual endowment factory modules with no required options\nexport { default as timeout } from './common/endowments/timeout';\nexport { default as interval } from './common/endowments/interval';\nexport { default as date } from './common/endowments/date';\nexport { default as textEncoder } from './common/endowments/textEncoder';\nexport { default as textDecoder } from './common/endowments/textDecoder';\nexport { default as crypto } from './common/endowments/crypto';\nexport { default as math } from './common/endowments/math';\n\n/**\n * Options required by the console endowment factory.\n */\nexport type ConsoleEndowmentOptions = Required<\n Pick<EndowmentFactoryOptions, 'sourceLabel'>\n>;\n\n/**\n * Options required by the network endowment factory.\n */\nexport type NetworkEndowmentOptions = Required<\n Pick<EndowmentFactoryOptions, 'notify'>\n>;\n\n/**\n * The console endowment factory. Produces an attenuated `console` object that\n * prefixes output with the provided source label.\n */\nexport const consoleEndowment: {\n readonly names: readonly ['console'];\n factory: (options: ConsoleEndowmentOptions) => EndowmentFactoryResult;\n} = consoleEndowmentModule;\n\n/**\n * The network endowment factory. Produces a wrapped `fetch` function and\n * related types with teardown support.\n */\nexport const network: {\n readonly names: readonly ['fetch', 'Request', 'Headers', 'Response'];\n factory: (options: NetworkEndowmentOptions) => EndowmentFactoryResult;\n} = networkModule;\n\n// Consolidated factory builder and types\nexport { default as buildCommonEndowments } from './common/endowments/commonEndowmentFactory';\nexport type {\n NotifyFunction,\n EndowmentFactoryOptions,\n EndowmentFactoryResult,\n EndowmentFactory,\n} from './common/endowments/commonEndowmentFactory';\n"]}