@metamask/snaps-execution-environments 3.5.0 → 4.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/CHANGELOG.md +20 -1
  2. package/dist/browserify/iframe/bundle.js +5 -5
  3. package/dist/browserify/iframe/index.html +202 -111
  4. package/dist/browserify/node-process/bundle.js +205 -114
  5. package/dist/browserify/node-thread/bundle.js +205 -114
  6. package/dist/browserify/webview/bundle.js +9 -0
  7. package/dist/browserify/{offscreen → webview}/index.html +202 -111
  8. package/dist/browserify/worker-executor/bundle.js +207 -116
  9. package/dist/browserify/worker-pool/bundle.js +5 -5
  10. package/dist/browserify/worker-pool/index.html +202 -111
  11. package/dist/cjs/common/BaseSnapExecutor.js +2 -2
  12. package/dist/cjs/common/BaseSnapExecutor.js.map +1 -1
  13. package/dist/cjs/common/commands.js +9 -0
  14. package/dist/cjs/common/commands.js.map +1 -1
  15. package/dist/cjs/common/validation.js +14 -0
  16. package/dist/cjs/common/validation.js.map +1 -1
  17. package/dist/cjs/index.js +20 -0
  18. package/dist/cjs/index.js.map +1 -0
  19. package/dist/cjs/proxy/ProxySnapExecutor.js +2 -2
  20. package/dist/cjs/proxy/ProxySnapExecutor.js.map +1 -1
  21. package/dist/cjs/proxy/index.js +20 -0
  22. package/dist/cjs/proxy/index.js.map +1 -0
  23. package/dist/cjs/webview/WebViewExecutorStream.js +121 -0
  24. package/dist/cjs/webview/WebViewExecutorStream.js.map +1 -0
  25. package/dist/cjs/{offscreen → webview}/index.js +4 -4
  26. package/dist/cjs/webview/index.js.map +1 -0
  27. package/dist/esm/common/BaseSnapExecutor.js +1 -1
  28. package/dist/esm/common/BaseSnapExecutor.js.map +1 -1
  29. package/dist/esm/common/commands.js +10 -1
  30. package/dist/esm/common/commands.js.map +1 -1
  31. package/dist/esm/common/validation.js +15 -0
  32. package/dist/esm/common/validation.js.map +1 -1
  33. package/dist/esm/index.js +3 -0
  34. package/dist/esm/index.js.map +1 -0
  35. package/dist/esm/proxy/ProxySnapExecutor.js +2 -2
  36. package/dist/esm/proxy/ProxySnapExecutor.js.map +1 -1
  37. package/dist/esm/proxy/index.js +3 -0
  38. package/dist/esm/proxy/index.js.map +1 -0
  39. package/dist/esm/webview/WebViewExecutorStream.js +111 -0
  40. package/dist/esm/webview/WebViewExecutorStream.js.map +1 -0
  41. package/dist/esm/{offscreen → webview}/index.js +4 -4
  42. package/dist/esm/webview/index.js.map +1 -0
  43. package/dist/types/common/validation.d.ts +31 -0
  44. package/dist/types/index.d.ts +1 -0
  45. package/dist/types/proxy/index.d.ts +1 -0
  46. package/dist/types/webview/WebViewExecutorStream.d.ts +32 -0
  47. package/package.json +9 -9
  48. package/dist/browserify/offscreen/bundle.js +0 -9
  49. package/dist/cjs/offscreen/index.js.map +0 -1
  50. package/dist/esm/offscreen/index.js.map +0 -1
  51. /package/dist/types/{offscreen → webview}/index.d.ts +0 -0
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/common/validation.ts"],"sourcesContent":["import { rpcErrors } from '@metamask/rpc-errors';\nimport { ChainIdStruct, HandlerType } from '@metamask/snaps-utils';\nimport type { Json, JsonRpcSuccess } from '@metamask/utils';\nimport {\n assertStruct,\n JsonRpcIdStruct,\n JsonRpcParamsStruct,\n JsonRpcSuccessStruct,\n JsonRpcVersionStruct,\n JsonStruct,\n} from '@metamask/utils';\nimport type { Infer } from 'superstruct';\nimport {\n array,\n assign,\n enums,\n is,\n literal,\n nullable,\n object,\n optional,\n record,\n string,\n tuple,\n union,\n} from 'superstruct';\n\nexport const JsonRpcRequestWithoutIdStruct = object({\n jsonrpc: optional(JsonRpcVersionStruct),\n id: optional(JsonRpcIdStruct),\n method: string(),\n params: optional(JsonRpcParamsStruct),\n});\n\nexport type JsonRpcRequestWithoutId = Infer<\n typeof JsonRpcRequestWithoutIdStruct\n>;\n\nexport const EndowmentStruct = string();\nexport type Endowment = Infer<typeof EndowmentStruct>;\n\n/**\n * Check if the given value is an endowment.\n *\n * @param value - The value to check.\n * @returns Whether the value is an endowment.\n */\nexport function isEndowment(value: unknown): value is Endowment {\n return is(value, EndowmentStruct);\n}\n\n/**\n * Check if the given value is an array of endowments.\n *\n * @param value - The value to check.\n * @returns Whether the value is an array of endowments.\n */\nexport function isEndowmentsArray(value: unknown): value is Endowment[] {\n return Array.isArray(value) && value.every(isEndowment);\n}\n\nconst OkStruct = literal('OK');\n\nexport const PingRequestArgumentsStruct = optional(\n union([literal(undefined), array()]),\n);\n\nexport const TerminateRequestArgumentsStruct = union([\n literal(undefined),\n array(),\n]);\n\nexport const ExecuteSnapRequestArgumentsStruct = tuple([\n string(),\n string(),\n array(EndowmentStruct),\n]);\n\nexport const SnapRpcRequestArgumentsStruct = tuple([\n string(),\n enums(Object.values(HandlerType)),\n string(),\n assign(\n JsonRpcRequestWithoutIdStruct,\n object({\n params: optional(record(string(), JsonStruct)),\n }),\n ),\n]);\n\nexport type PingRequestArguments = Infer<typeof PingRequestArgumentsStruct>;\nexport type TerminateRequestArguments = Infer<\n typeof TerminateRequestArgumentsStruct\n>;\n\nexport type ExecuteSnapRequestArguments = Infer<\n typeof ExecuteSnapRequestArgumentsStruct\n>;\n\nexport type SnapRpcRequestArguments = Infer<\n typeof SnapRpcRequestArgumentsStruct\n>;\n\nexport type RequestArguments =\n | PingRequestArguments\n | TerminateRequestArguments\n | ExecuteSnapRequestArguments\n | SnapRpcRequestArguments;\n\nexport const OnTransactionRequestArgumentsStruct = object({\n // TODO: Improve `transaction` type.\n transaction: record(string(), JsonStruct),\n chainId: ChainIdStruct,\n transactionOrigin: nullable(string()),\n});\n\nexport type OnTransactionRequestArguments = Infer<\n typeof OnTransactionRequestArgumentsStruct\n>;\n\n/**\n * Asserts that the given value is a valid {@link OnTransactionRequestArguments}\n * object.\n *\n * @param value - The value to validate.\n * @throws If the value is not a valid {@link OnTransactionRequestArguments}\n * object.\n */\nexport function assertIsOnTransactionRequestArguments(\n value: unknown,\n): asserts value is OnTransactionRequestArguments {\n assertStruct(\n value,\n OnTransactionRequestArgumentsStruct,\n 'Invalid request params',\n rpcErrors.invalidParams,\n );\n}\n\nexport const OnSignatureRequestArgumentsStruct = object({\n signature: record(string(), JsonStruct),\n signatureOrigin: nullable(string()),\n});\n\nexport type OnSignatureRequestArguments = Infer<\n typeof OnSignatureRequestArgumentsStruct\n>;\n\n/**\n * Asserts that the given value is a valid {@link OnSignatureRequestArguments}\n * object.\n *\n * @param value - The value to validate.\n * @throws If the value is not a valid {@link OnSignatureRequestArguments}\n * object.\n */\nexport function assertIsOnSignatureRequestArguments(\n value: unknown,\n): asserts value is OnSignatureRequestArguments {\n assertStruct(\n value,\n OnSignatureRequestArgumentsStruct,\n 'Invalid request params',\n rpcErrors.invalidParams,\n );\n}\n\nconst baseNameLookupArgs = { chainId: ChainIdStruct };\nconst domainRequestStruct = object({\n ...baseNameLookupArgs,\n address: string(),\n});\nconst addressRequestStruct = object({\n ...baseNameLookupArgs,\n domain: string(),\n});\n\nexport const OnNameLookupRequestArgumentsStruct = union([\n domainRequestStruct,\n addressRequestStruct,\n]);\n\nexport type OnNameLookupRequestArguments = Infer<\n typeof OnNameLookupRequestArgumentsStruct\n>;\n\nexport type PossibleLookupRequestArgs = typeof baseNameLookupArgs & {\n address?: string;\n domain?: string;\n};\n\n/**\n * Asserts that the given value is a valid {@link OnNameLookupRequestArguments}\n * object.\n *\n * @param value - The value to validate.\n * @throws If the value is not a valid {@link OnNameLookupRequestArguments}\n * object.\n */\nexport function assertIsOnNameLookupRequestArguments(\n value: unknown,\n): asserts value is OnNameLookupRequestArguments {\n assertStruct(\n value,\n OnNameLookupRequestArgumentsStruct,\n 'Invalid request params',\n rpcErrors.invalidParams,\n );\n}\n\nconst OkResponseStruct = object({\n id: JsonRpcIdStruct,\n jsonrpc: JsonRpcVersionStruct,\n result: OkStruct,\n});\n\nconst SnapRpcResponse = JsonRpcSuccessStruct;\n\nexport type OkResponse = Infer<typeof OkResponseStruct>;\nexport type SnapRpcResponse = Infer<typeof SnapRpcResponse>;\n\nexport type Response = OkResponse | SnapRpcResponse;\n\ntype RequestParams<Params extends unknown[] | undefined> =\n Params extends undefined ? [] : Params;\n\ntype RequestFunction<\n Args extends RequestArguments,\n ResponseType extends JsonRpcSuccess<Json>,\n> = (...args: RequestParams<Args>) => Promise<ResponseType['result']>;\n\nexport type Ping = RequestFunction<PingRequestArguments, OkResponse>;\nexport type Terminate = RequestFunction<TerminateRequestArguments, OkResponse>;\nexport type ExecuteSnap = RequestFunction<\n ExecuteSnapRequestArguments,\n OkResponse\n>;\nexport type SnapRpc = RequestFunction<SnapRpcRequestArguments, SnapRpcResponse>;\n"],"names":["rpcErrors","ChainIdStruct","HandlerType","assertStruct","JsonRpcIdStruct","JsonRpcParamsStruct","JsonRpcSuccessStruct","JsonRpcVersionStruct","JsonStruct","array","assign","enums","is","literal","nullable","object","optional","record","string","tuple","union","JsonRpcRequestWithoutIdStruct","jsonrpc","id","method","params","EndowmentStruct","isEndowment","value","isEndowmentsArray","Array","isArray","every","OkStruct","PingRequestArgumentsStruct","undefined","TerminateRequestArgumentsStruct","ExecuteSnapRequestArgumentsStruct","SnapRpcRequestArgumentsStruct","Object","values","OnTransactionRequestArgumentsStruct","transaction","chainId","transactionOrigin","assertIsOnTransactionRequestArguments","invalidParams","OnSignatureRequestArgumentsStruct","signature","signatureOrigin","assertIsOnSignatureRequestArguments","baseNameLookupArgs","domainRequestStruct","address","addressRequestStruct","domain","OnNameLookupRequestArgumentsStruct","assertIsOnNameLookupRequestArguments","OkResponseStruct","result","SnapRpcResponse"],"mappings":"AAAA,SAASA,SAAS,QAAQ,uBAAuB;AACjD,SAASC,aAAa,EAAEC,WAAW,QAAQ,wBAAwB;AAEnE,SACEC,YAAY,EACZC,eAAe,EACfC,mBAAmB,EACnBC,oBAAoB,EACpBC,oBAAoB,EACpBC,UAAU,QACL,kBAAkB;AAEzB,SACEC,KAAK,EACLC,MAAM,EACNC,KAAK,EACLC,EAAE,EACFC,OAAO,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MH;;;;;;;CAOC,GACD,OAAO,SAASgC,oCACdtB,KAAc;IAEdzB,aACEyB,OACAmB,mCACA,0BACA/C,UAAU8C,aAAa;AAE3B;AAEA,MAAMK,qBAAqB;IAAER,SAAS1C;AAAc;AACpD,MAAMmD,sBAAsBrC,OAAO;IACjC,GAAGoC,kBAAkB;IACrBE,SAASnC;AACX;AACA,MAAMoC,uBAAuBvC,OAAO;IAClC,GAAGoC,kBAAkB;IACrBI,QAAQrC;AACV;AAEA,OAAO,MAAMsC,qCAAqCpC,MAAM;IACtDgC;IACAE;CACD,EAAE;AAWH;;;;;;;CAOC,GACD,OAAO,SAASG,qCACd7B,KAAc;IAEdzB,aACEyB,OACA4B,oCACA,0BACAxD,UAAU8C,aAAa;AAE3B;AAEA,MAAMY,mBAAmB3C,OAAO;IAC9BQ,IAAInB;IACJkB,SAASf;IACToD,QAAQ1B;AACV;AAEA,MAAM2B,kBAAkBtD"}
1
+ {"version":3,"sources":["../../../src/common/validation.ts"],"sourcesContent":["import { rpcErrors } from '@metamask/rpc-errors';\nimport { UserInputEventStruct } from '@metamask/snaps-sdk';\nimport { ChainIdStruct, HandlerType } from '@metamask/snaps-utils';\nimport type { Json, JsonRpcSuccess } from '@metamask/utils';\nimport {\n assertStruct,\n JsonRpcIdStruct,\n JsonRpcParamsStruct,\n JsonRpcSuccessStruct,\n JsonRpcVersionStruct,\n JsonStruct,\n} from '@metamask/utils';\nimport type { Infer } from 'superstruct';\nimport {\n array,\n assign,\n enums,\n is,\n literal,\n nullable,\n object,\n optional,\n record,\n string,\n tuple,\n union,\n} from 'superstruct';\n\nexport const JsonRpcRequestWithoutIdStruct = object({\n jsonrpc: optional(JsonRpcVersionStruct),\n id: optional(JsonRpcIdStruct),\n method: string(),\n params: optional(JsonRpcParamsStruct),\n});\n\nexport type JsonRpcRequestWithoutId = Infer<\n typeof JsonRpcRequestWithoutIdStruct\n>;\n\nexport const EndowmentStruct = string();\nexport type Endowment = Infer<typeof EndowmentStruct>;\n\n/**\n * Check if the given value is an endowment.\n *\n * @param value - The value to check.\n * @returns Whether the value is an endowment.\n */\nexport function isEndowment(value: unknown): value is Endowment {\n return is(value, EndowmentStruct);\n}\n\n/**\n * Check if the given value is an array of endowments.\n *\n * @param value - The value to check.\n * @returns Whether the value is an array of endowments.\n */\nexport function isEndowmentsArray(value: unknown): value is Endowment[] {\n return Array.isArray(value) && value.every(isEndowment);\n}\n\nconst OkStruct = literal('OK');\n\nexport const PingRequestArgumentsStruct = optional(\n union([literal(undefined), array()]),\n);\n\nexport const TerminateRequestArgumentsStruct = union([\n literal(undefined),\n array(),\n]);\n\nexport const ExecuteSnapRequestArgumentsStruct = tuple([\n string(),\n string(),\n array(EndowmentStruct),\n]);\n\nexport const SnapRpcRequestArgumentsStruct = tuple([\n string(),\n enums(Object.values(HandlerType)),\n string(),\n assign(\n JsonRpcRequestWithoutIdStruct,\n object({\n params: optional(record(string(), JsonStruct)),\n }),\n ),\n]);\n\nexport type PingRequestArguments = Infer<typeof PingRequestArgumentsStruct>;\nexport type TerminateRequestArguments = Infer<\n typeof TerminateRequestArgumentsStruct\n>;\n\nexport type ExecuteSnapRequestArguments = Infer<\n typeof ExecuteSnapRequestArgumentsStruct\n>;\n\nexport type SnapRpcRequestArguments = Infer<\n typeof SnapRpcRequestArgumentsStruct\n>;\n\nexport type RequestArguments =\n | PingRequestArguments\n | TerminateRequestArguments\n | ExecuteSnapRequestArguments\n | SnapRpcRequestArguments;\n\nexport const OnTransactionRequestArgumentsStruct = object({\n // TODO: Improve `transaction` type.\n transaction: record(string(), JsonStruct),\n chainId: ChainIdStruct,\n transactionOrigin: nullable(string()),\n});\n\nexport type OnTransactionRequestArguments = Infer<\n typeof OnTransactionRequestArgumentsStruct\n>;\n\n/**\n * Asserts that the given value is a valid {@link OnTransactionRequestArguments}\n * object.\n *\n * @param value - The value to validate.\n * @throws If the value is not a valid {@link OnTransactionRequestArguments}\n * object.\n */\nexport function assertIsOnTransactionRequestArguments(\n value: unknown,\n): asserts value is OnTransactionRequestArguments {\n assertStruct(\n value,\n OnTransactionRequestArgumentsStruct,\n 'Invalid request params',\n rpcErrors.invalidParams,\n );\n}\n\nexport const OnSignatureRequestArgumentsStruct = object({\n signature: record(string(), JsonStruct),\n signatureOrigin: nullable(string()),\n});\n\nexport type OnSignatureRequestArguments = Infer<\n typeof OnSignatureRequestArgumentsStruct\n>;\n\n/**\n * Asserts that the given value is a valid {@link OnSignatureRequestArguments}\n * object.\n *\n * @param value - The value to validate.\n * @throws If the value is not a valid {@link OnSignatureRequestArguments}\n * object.\n */\nexport function assertIsOnSignatureRequestArguments(\n value: unknown,\n): asserts value is OnSignatureRequestArguments {\n assertStruct(\n value,\n OnSignatureRequestArgumentsStruct,\n 'Invalid request params',\n rpcErrors.invalidParams,\n );\n}\n\nconst baseNameLookupArgs = { chainId: ChainIdStruct };\nconst domainRequestStruct = object({\n ...baseNameLookupArgs,\n address: string(),\n});\nconst addressRequestStruct = object({\n ...baseNameLookupArgs,\n domain: string(),\n});\n\nexport const OnNameLookupRequestArgumentsStruct = union([\n domainRequestStruct,\n addressRequestStruct,\n]);\n\nexport type OnNameLookupRequestArguments = Infer<\n typeof OnNameLookupRequestArgumentsStruct\n>;\n\nexport type PossibleLookupRequestArgs = typeof baseNameLookupArgs & {\n address?: string;\n domain?: string;\n};\n\n/**\n * Asserts that the given value is a valid {@link OnNameLookupRequestArguments}\n * object.\n *\n * @param value - The value to validate.\n * @throws If the value is not a valid {@link OnNameLookupRequestArguments}\n * object.\n */\nexport function assertIsOnNameLookupRequestArguments(\n value: unknown,\n): asserts value is OnNameLookupRequestArguments {\n assertStruct(\n value,\n OnNameLookupRequestArgumentsStruct,\n 'Invalid request params',\n rpcErrors.invalidParams,\n );\n}\n\nexport const OnUserInputArgumentsStruct = object({\n id: string(),\n event: UserInputEventStruct,\n});\n\nexport type OnUserInputArguments = Infer<typeof OnUserInputArgumentsStruct>;\n\n/**\n * Asserts that the given value is a valid {@link OnUserInputArguments}\n * object.\n *\n * @param value - The value to validate.\n * @throws If the value is not a valid {@link OnUserInputArguments}\n * object.\n */\nexport function assertIsOnUserInputRequestArguments(\n value: unknown,\n): asserts value is OnUserInputArguments {\n assertStruct(\n value,\n OnUserInputArgumentsStruct,\n 'Invalid request params',\n rpcErrors.invalidParams,\n );\n}\n\nconst OkResponseStruct = object({\n id: JsonRpcIdStruct,\n jsonrpc: JsonRpcVersionStruct,\n result: OkStruct,\n});\n\nconst SnapRpcResponse = JsonRpcSuccessStruct;\n\nexport type OkResponse = Infer<typeof OkResponseStruct>;\nexport type SnapRpcResponse = Infer<typeof SnapRpcResponse>;\n\nexport type Response = OkResponse | SnapRpcResponse;\n\ntype RequestParams<Params extends unknown[] | undefined> =\n Params extends undefined ? [] : Params;\n\ntype RequestFunction<\n Args extends RequestArguments,\n ResponseType extends JsonRpcSuccess<Json>,\n> = (...args: RequestParams<Args>) => Promise<ResponseType['result']>;\n\nexport type Ping = RequestFunction<PingRequestArguments, OkResponse>;\nexport type Terminate = RequestFunction<TerminateRequestArguments, OkResponse>;\nexport type ExecuteSnap = RequestFunction<\n ExecuteSnapRequestArguments,\n OkResponse\n>;\nexport type SnapRpc = RequestFunction<SnapRpcRequestArguments, SnapRpcResponse>;\n"],"names":["rpcErrors","UserInputEventStruct","ChainIdStruct","HandlerType","assertStruct","JsonRpcIdStruct","JsonRpcParamsStruct","JsonRpcSuccessStruct","JsonRpcVersionStruct","JsonStruct","array","assign","enums","is","literal","nullable","object","optional","record","string","tuple","union","JsonRpcRequestWithoutIdStruct","jsonrpc","id","method","params","EndowmentStruct","isEndowment","value","isEndowmentsArray","Array","isArray","every","OkStruct","PingRequestArgumentsStruct","undefined","TerminateRequestArgumentsStruct","ExecuteSnapRequestArgumentsStruct","SnapRpcRequestArgumentsStruct","Object","values","OnTransactionRequestArgumentsStruct","transaction","chainId","transactionOrigin","assertIsOnTransactionRequestArguments","invalidParams","OnSignatureRequestArgumentsStruct","signature","signatureOrigin","assertIsOnSignatureRequestArguments","baseNameLookupArgs","domainRequestStruct","address","addressRequestStruct","domain","OnNameLookupRequestArgumentsStruct","assertIsOnNameLookupRequestArguments","OnUserInputArgumentsStruct","event","assertIsOnUserInputRequestArguments","OkResponseStruct","result","SnapRpcResponse"],"mappings":"AAAA,SAASA,SAAS,QAAQ,uBAAuB;AACjD,SAASC,oBAAoB,QAAQ,sBAAsB;AAC3D,SAASC,aAAa,EAAEC,WAAW,QAAQ,wBAAwB;AAEnE,SACEC,YAAY,EACZC,eAAe,EACfC,mBAAmB,EACnBC,oBAAoB,EACpBC,oBAAoB,EACpBC,UAAU,QACL,kBAAkB;AAEzB,SACEC,KAAK,EACLC,MAAM,EACNC,KAAK,EACLC,EAAE,EACFC,OAAO,EACPC,QAAQ,EACRC,MAAM,EACNC,QAAQ,EACRC,MAAM,EACNC,MAAM,EACNC,KAAK,EACLC,KAAK,QACA,cAAc;AAErB,OAAO,MAAMC,gCAAgCN,OAAO;IAClDO,SAASN,SAAST;IAClBgB,IAAIP,SAASZ;IACboB,QAAQN;IACRO,QAAQT,SAASX;AACnB,GAAG;AAMH,OAAO,MAAMqB,kBAAkBR,SAAS;AAGxC;;;;;CAKC,GACD,OAAO,SAASS,YAAYC,KAAc;IACxC,OAAOhB,GAAGgB,OAAOF;AACnB;AAEA;;;;;CAKC,GACD,OAAO,SAASG,kBAAkBD,KAAc;IAC9C,OAAOE,MAAMC,OAAO,CAACH,UAAUA,MAAMI,KAAK,CAACL;AAC7C;AAEA,MAAMM,WAAWpB,QAAQ;AAEzB,OAAO,MAAMqB,6BAA6BlB,SACxCI,MAAM;IAACP,QAAQsB;IAAY1B;CAAQ,GACnC;AAEF,OAAO,MAAM2B,kCAAkChB,MAAM;IACnDP,QAAQsB;IACR1B;CACD,EAAE;AAEH,OAAO,MAAM4B,oCAAoClB,MAAM;IACrDD;IACAA;IACAT,MAAMiB;CACP,EAAE;AAEH,OAAO,MAAMY,gCAAgCnB,MAAM;IACjDD;IACAP,MAAM4B,OAAOC,MAAM,CA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 @@
1
+ export * from './proxy';
2
+
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export * from './proxy';\n"],"names":[],"mappings":"AAAA,cAAc,UAAU"}
@@ -66,9 +66,9 @@ import { WindowPostMessageStream } from '@metamask/post-message-stream';
66
66
  import packageJson from '@metamask/snaps-execution-environments/package.json';
67
67
  import { createWindow, logError } from '@metamask/snaps-utils';
68
68
  import { assert } from '@metamask/utils';
69
- const IFRAME_URL = `https://execution.metamask.io/${packageJson.version}/index.html`;
69
+ const IFRAME_URL = `https://execution.metamask.io/iframe/${packageJson.version}/index.html`;
70
70
  var _stream = /*#__PURE__*/ new WeakMap(), _frameUrl = /*#__PURE__*/ new WeakMap(), /**
71
- * Handle an incoming message from the `OffscreenExecutionService`. This
71
+ * Handle an incoming message from a `ProxyExecutionService`. This
72
72
  * assumes that the message contains a `jobId` property, and a JSON-RPC
73
73
  * request in the `data` property.
74
74
  *
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/proxy/ProxySnapExecutor.ts"],"sourcesContent":["import type { BasePostMessageStream } from '@metamask/post-message-stream';\nimport { WindowPostMessageStream } from '@metamask/post-message-stream';\n// eslint-disable-next-line import/no-extraneous-dependencies\nimport packageJson from '@metamask/snaps-execution-environments/package.json';\nimport { createWindow, logError } from '@metamask/snaps-utils';\nimport type { JsonRpcRequest } from '@metamask/utils';\nimport { assert } from '@metamask/utils';\n\ntype ExecutorJob = {\n id: string;\n window: Window;\n stream: WindowPostMessageStream;\n};\n\nconst IFRAME_URL = `https://execution.metamask.io/${packageJson.version}/index.html`;\n\n/**\n * A \"proxy\" snap executor that uses a level of indirection to execute snaps.\n *\n * Useful for multiple execution environments.\n *\n * This is not a traditional snap executor, as it does not execute snaps itself.\n * Instead, it creates an iframe window for each snap execution, and sends the\n * snap execution request to the iframe window. The iframe window is responsible\n * for executing the snap.\n *\n * This executor is persisted between snap executions. The executor essentially\n * acts as a proxy between the client and the iframe execution environment.\n */\nexport class ProxySnapExecutor {\n readonly #stream: BasePostMessageStream;\n\n readonly #frameUrl: string;\n\n readonly jobs: Record<string, ExecutorJob> = {};\n\n /**\n * Initialize the executor with the given stream. This is a wrapper around the\n * constructor.\n *\n * @param stream - The stream to use for communication.\n * @param frameUrl - An optional URL for the iframe to use.\n * @returns The initialized executor.\n */\n static initialize(stream: BasePostMessageStream, frameUrl = IFRAME_URL) {\n return new ProxySnapExecutor(stream, frameUrl);\n }\n\n constructor(stream: BasePostMessageStream, frameUrl: string) {\n this.#stream = stream;\n this.#stream.on('data', this.#onData.bind(this));\n this.#frameUrl = frameUrl;\n }\n\n /**\n * Handle an incoming message from the `OffscreenExecutionService`. This\n * assumes that the message contains a `jobId` property, and a JSON-RPC\n * request in the `data` property.\n *\n * @param data - The message data.\n * @param data.data - The JSON-RPC request.\n * @param data.jobId - The job ID.\n */\n #onData(data: { data: JsonRpcRequest; jobId: string }) {\n const { jobId, data: request } = data;\n\n if (!this.jobs[jobId]) {\n // This ensures that a job is initialized before it is used. To avoid\n // code duplication, we call the `#onData` method again, which will\n // run the rest of the logic after initialization.\n this.#initializeJob(jobId)\n .then(() => {\n this.#onData(data);\n })\n .catch((error) => {\n logError('[Worker] Error initializing job:', error);\n });\n\n return;\n }\n\n // This is a method specific to the `OffscreenSnapExecutor`, as the service\n // itself does not have access to the iframes directly.\n if (request.method === 'terminateJob') {\n this.#terminateJob(jobId);\n return;\n }\n\n this.jobs[jobId].stream.write(request);\n }\n\n /**\n * Create a new iframe and set up a stream to communicate with it.\n *\n * @param jobId - The job ID.\n */\n async #initializeJob(jobId: string): Promise<ExecutorJob> {\n const window = await createWindow(this.#frameUrl, jobId);\n const jobStream = new WindowPostMessageStream({\n name: 'parent',\n target: 'child',\n targetWindow: window,\n targetOrigin: '*',\n });\n\n // Write messages from the iframe to the parent, wrapped with the job ID.\n jobStream.on('data', (data) => {\n this.#stream.write({ data, jobId });\n });\n\n this.jobs[jobId] = { id: jobId, window, stream: jobStream };\n return this.jobs[jobId];\n }\n\n /**\n * Terminate the job with the given ID. This will close the iframe and delete\n * the job from the internal job map.\n *\n * @param jobId - The job ID.\n */\n #terminateJob(jobId: string) {\n assert(this.jobs[jobId], `Job \"${jobId}\" not found.`);\n\n const iframe = document.getElementById(jobId);\n assert(iframe, `Iframe with ID \"${jobId}\" not found.`);\n\n iframe.remove();\n this.jobs[jobId].stream.destroy();\n delete this.jobs[jobId];\n }\n}\n"],"names":["WindowPostMessageStream","packageJson","createWindow","logError","assert","IFRAME_URL","version","ProxySnapExecutor","initialize","stream","frameUrl","constructor","jobs","on","onData","bind","data","jobId","request","initializeJob","then","catch","error","method","terminateJob","write","window","jobStream","name","target","targetWindow","targetOrigin","id","iframe","document","getElementById","remove","destroy"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,SAASA,uBAAuB,QAAQ,gCAAgC;AACxE,6DAA6D;AAC7D,OAAOC,iBAAiB,sDAAsD;AAC9E,SAASC,YAAY,EAAEC,QAAQ,QAAQ,wBAAwB;AAE/D,SAASC,MAAM,QAAQ,kBAAkB;AAQzC,MAAMC,aAAa,CAAC,8BAA8B,EAAEJ,YAAYK,OAAO,CAAC,WAAW,CAAC;IAgBzE,uCAEA,yCAsBT;;;;;;;;GAQC,GACD,uCAiCM,8CAkBN;;;;;GAKC,GACD;AAxGF;;;;;;;;;;;;CAYC,GACD,OAAO,MAAMC;IAOX;;;;;;;GAOC,GACD,OAAOC,WAAWC,MAA6B,EAAEC,WAAWL,UAAU,EAAE;QACtE,OAAO,IAAIE,kBAAkBE,QAAQC;IACvC;IAEAC,YAAYF,MAA6B,EAAEC,QAAgB,CAAE;QAe7D,iCAAA;QA4BA;;;;GAIC,GACD,iCAAM;QAwBN,iCAAA;QA1FA,gCAAS;;mBAAT,KAAA;;QAEA,gCAAS;;mBAAT,KAAA;;QAEA,uBAASE,QAAoC,CAAC;uCAetCH,S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,CAACK,MAAM,EAAE,CAAC,KAAK,EAAEA,MAAM,YAAY,CAAC;IAEpD,MAAMgB,SAASC,SAASC,cAAc,CAAClB;IACvCb,OAAO6B,QAAQ,CAAC,gBAAgB,EAAEhB,MAAM,YAAY,CAAC;IAErDgB,OAAOG,MAAM;IACb,IAAI,CAACxB,IAAI,CAACK,MAAM,CAACR,MAAM,CAAC4B,OAAO;IAC/B,OAAO,IAAI,CAACzB,IAAI,CAACK,MAAM;AACzB"}
1
+ {"version":3,"sources":["../../../src/proxy/ProxySnapExecutor.ts"],"sourcesContent":["import type { BasePostMessageStream } from '@metamask/post-message-stream';\nimport { WindowPostMessageStream } from '@metamask/post-message-stream';\n// eslint-disable-next-line import/no-extraneous-dependencies\nimport packageJson from '@metamask/snaps-execution-environments/package.json';\nimport { createWindow, logError } from '@metamask/snaps-utils';\nimport type { JsonRpcRequest } from '@metamask/utils';\nimport { assert } from '@metamask/utils';\n\ntype ExecutorJob = {\n id: string;\n window: Window;\n stream: WindowPostMessageStream;\n};\n\nconst IFRAME_URL = `https://execution.metamask.io/iframe/${packageJson.version}/index.html`;\n\n/**\n * A \"proxy\" snap executor that uses a level of indirection to execute snaps.\n *\n * Useful for multiple execution environments.\n *\n * This is not a traditional snap executor, as it does not execute snaps itself.\n * Instead, it creates an iframe window for each snap execution, and sends the\n * snap execution request to the iframe window. The iframe window is responsible\n * for executing the snap.\n *\n * This executor is persisted between snap executions. The executor essentially\n * acts as a proxy between the client and the iframe execution environment.\n */\nexport class ProxySnapExecutor {\n readonly #stream: BasePostMessageStream;\n\n readonly #frameUrl: string;\n\n readonly jobs: Record<string, ExecutorJob> = {};\n\n /**\n * Initialize the executor with the given stream. This is a wrapper around the\n * constructor.\n *\n * @param stream - The stream to use for communication.\n * @param frameUrl - An optional URL for the iframe to use.\n * @returns The initialized executor.\n */\n static initialize(stream: BasePostMessageStream, frameUrl = IFRAME_URL) {\n return new ProxySnapExecutor(stream, frameUrl);\n }\n\n constructor(stream: BasePostMessageStream, frameUrl: string) {\n this.#stream = stream;\n this.#stream.on('data', this.#onData.bind(this));\n this.#frameUrl = frameUrl;\n }\n\n /**\n * Handle an incoming message from a `ProxyExecutionService`. This\n * assumes that the message contains a `jobId` property, and a JSON-RPC\n * request in the `data` property.\n *\n * @param data - The message data.\n * @param data.data - The JSON-RPC request.\n * @param data.jobId - The job ID.\n */\n #onData(data: { data: JsonRpcRequest; jobId: string }) {\n const { jobId, data: request } = data;\n\n if (!this.jobs[jobId]) {\n // This ensures that a job is initialized before it is used. To avoid\n // code duplication, we call the `#onData` method again, which will\n // run the rest of the logic after initialization.\n this.#initializeJob(jobId)\n .then(() => {\n this.#onData(data);\n })\n .catch((error) => {\n logError('[Worker] Error initializing job:', error);\n });\n\n return;\n }\n\n // This is a method specific to the `OffscreenSnapExecutor`, as the service\n // itself does not have access to the iframes directly.\n if (request.method === 'terminateJob') {\n this.#terminateJob(jobId);\n return;\n }\n\n this.jobs[jobId].stream.write(request);\n }\n\n /**\n * Create a new iframe and set up a stream to communicate with it.\n *\n * @param jobId - The job ID.\n */\n async #initializeJob(jobId: string): Promise<ExecutorJob> {\n const window = await createWindow(this.#frameUrl, jobId);\n const jobStream = new WindowPostMessageStream({\n name: 'parent',\n target: 'child',\n targetWindow: window, // iframe's internal window\n targetOrigin: '*',\n });\n\n // Write messages from the iframe to the parent, wrapped with the job ID.\n jobStream.on('data', (data) => {\n this.#stream.write({ data, jobId });\n });\n\n this.jobs[jobId] = { id: jobId, window, stream: jobStream };\n return this.jobs[jobId];\n }\n\n /**\n * Terminate the job with the given ID. This will close the iframe and delete\n * the job from the internal job map.\n *\n * @param jobId - The job ID.\n */\n #terminateJob(jobId: string) {\n assert(this.jobs[jobId], `Job \"${jobId}\" not found.`);\n\n const iframe = document.getElementById(jobId);\n assert(iframe, `Iframe with ID \"${jobId}\" not found.`);\n\n iframe.remove();\n this.jobs[jobId].stream.destroy();\n delete this.jobs[jobId];\n }\n}\n"],"names":["WindowPostMessageStream","packageJson","createWindow","logError","assert","IFRAME_URL","version","ProxySnapExecutor","initialize","stream","frameUrl","constructor","jobs","on","onData","bind","data","jobId","request","initializeJob","then","catch","error","method","terminateJob","write","window","jobStream","name","target","targetWindow","targetOrigin","id","iframe","document","getElementById","remove","destroy"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,SAASA,uBAAuB,QAAQ,gCAAgC;AACxE,6DAA6D;AAC7D,OAAOC,iBAAiB,sDAAsD;AAC9E,SAASC,YAAY,EAAEC,QAAQ,QAAQ,wBAAwB;AAE/D,SAASC,MAAM,QAAQ,kBAAkB;AAQzC,MAAMC,aAAa,CAAC,qCAAqC,EAAEJ,YAAYK,OAAO,CAAC,WAAW,CAAC;IAgBhF,uCAEA,yCAsBT;;;;;;;;GAQC,GACD,uCAiCM,8CAkBN;;;;;GAKC,GACD;AAxGF;;;;;;;;;;;;CAYC,GACD,OAAO,MAAMC;IAOX;;;;;;;GAOC,GACD,OAAOC,WAAWC,MAA6B,EAAEC,WAAWL,UAAU,EAAE;QACtE,OAAO,IAAIE,kBAAkBE,QAAQC;IACvC;IAEAC,YAAYF,MAA6B,EAAEC,QAAgB,CAAE;QAe7D,iCAAA;QA4BA;;;;GAIC,GACD,iCAAM;QAwBN,iCAAA;QA1FA,gCAAS;;mBAAT,KAAA;;QAEA,gCAAS;;mBAAT,KAAA;;QAEA,uBAASE,QAAoC,CAAC;uCAetCH,SAASA;QACf,yBAAA,IAAI,EAAEA,SAAOI,EAAE,CAAC,QAAQ,0BAAA,IAAI,EAAEC,SAAAA,QAAOC,IAAI,CAAC,IAAI;uCACxCL,WAAWA;IACnB;AA8EF;AAnEE,SAAA,OAAQM,IAA6C;IACnD,MAAM,EAAEC,KAAK,EAAED,MAAME,OAAO,EAAE,GAAGF;IAEjC,IAAI,CAAC,IAAI,CAACJ,IAAI,CAACK,MAAM,EAAE;QACrB,qEAAqE;QACrE,mEAAmE;QACnE,kDA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1
+ export * from './ProxySnapExecutor';
2
+
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/proxy/index.ts"],"sourcesContent":["export * from './ProxySnapExecutor';\n"],"names":[],"mappings":"AAAA,cAAc,sBAAsB"}
@@ -0,0 +1,111 @@
1
+ function _check_private_redeclaration(obj, privateCollection) {
2
+ if (privateCollection.has(obj)) {
3
+ throw new TypeError("Cannot initialize the same private elements twice on an object");
4
+ }
5
+ }
6
+ function _class_apply_descriptor_get(receiver, descriptor) {
7
+ if (descriptor.get) {
8
+ return descriptor.get.call(receiver);
9
+ }
10
+ return descriptor.value;
11
+ }
12
+ function _class_apply_descriptor_set(receiver, descriptor, value) {
13
+ if (descriptor.set) {
14
+ descriptor.set.call(receiver, value);
15
+ } else {
16
+ if (!descriptor.writable) {
17
+ throw new TypeError("attempted to set read only private field");
18
+ }
19
+ descriptor.value = value;
20
+ }
21
+ }
22
+ function _class_extract_field_descriptor(receiver, privateMap, action) {
23
+ if (!privateMap.has(receiver)) {
24
+ throw new TypeError("attempted to " + action + " private field on non-instance");
25
+ }
26
+ return privateMap.get(receiver);
27
+ }
28
+ function _class_private_field_get(receiver, privateMap) {
29
+ var descriptor = _class_extract_field_descriptor(receiver, privateMap, "get");
30
+ return _class_apply_descriptor_get(receiver, descriptor);
31
+ }
32
+ function _class_private_field_init(obj, privateMap, value) {
33
+ _check_private_redeclaration(obj, privateMap);
34
+ privateMap.set(obj, value);
35
+ }
36
+ function _class_private_field_set(receiver, privateMap, value) {
37
+ var descriptor = _class_extract_field_descriptor(receiver, privateMap, "set");
38
+ _class_apply_descriptor_set(receiver, descriptor, value);
39
+ return value;
40
+ }
41
+ import { BasePostMessageStream } from '@metamask/post-message-stream';
42
+ import { isValidStreamMessage } from '@metamask/post-message-stream/dist/utils';
43
+ import { base64ToBytes, bytesToString } from '@metamask/utils';
44
+ var _name = /*#__PURE__*/ new WeakMap(), _target = /*#__PURE__*/ new WeakMap(), _targetWindow = /*#__PURE__*/ new WeakMap();
45
+ export class WebViewExecutorStream extends BasePostMessageStream {
46
+ /**
47
+ * Webview needs to receive strings only on postMessage. That's the main difference between this and the original window post message stream.
48
+ * Reference: https://github.com/react-native-webview/react-native-webview/blob/master/docs/Guide.md?plain=1#L471
49
+ */ _postMessage(data) {
50
+ _class_private_field_get(this, _targetWindow).postMessage(JSON.stringify({
51
+ target: _class_private_field_get(this, _target),
52
+ data
53
+ }));
54
+ }
55
+ _onMessage(event) {
56
+ if (typeof event.data !== 'string') {
57
+ return;
58
+ }
59
+ const bytes = base64ToBytes(event.data);
60
+ const message = JSON.parse(bytesToString(bytes));
61
+ // Notice that we don't check targetWindow or targetOrigin here.
62
+ // This doesn't seem possible to do in RN.
63
+ if (!isValidStreamMessage(message) || message.target !== _class_private_field_get(this, _name)) {
64
+ return;
65
+ }
66
+ this._onData(message.data);
67
+ }
68
+ _destroy() {
69
+ // This method is already bound.
70
+ // eslint-disable-next-line @typescript-eslint/unbound-method
71
+ window.removeEventListener('message', this._onMessage, false);
72
+ }
73
+ /**
74
+ * A special post-message-stream to be used by the WebView executor.
75
+ *
76
+ * This stream is different in a few ways:
77
+ * - It expects data to be base64 encoded
78
+ * - It stringifies the data it posts
79
+ * - It does less validation of origins
80
+ *
81
+ * @param args - Options bag.
82
+ * @param args.name - The name of the stream. Used to differentiate between
83
+ * multiple streams sharing the same window object. child:WebView
84
+ * @param args.target - The name of the stream to exchange messages with. parent:rnside
85
+ * @param args.targetWindow - The window object of the target stream.
86
+ */ constructor({ name, target, targetWindow }){
87
+ super();
88
+ _class_private_field_init(this, _name, {
89
+ writable: true,
90
+ value: void 0
91
+ });
92
+ _class_private_field_init(this, _target, {
93
+ writable: true,
94
+ value: void 0
95
+ });
96
+ _class_private_field_init(this, _targetWindow, {
97
+ writable: true,
98
+ value: void 0
99
+ });
100
+ _class_private_field_set(this, _name, name);
101
+ _class_private_field_set(this, _target, target);
102
+ _class_private_field_set(this, _targetWindow, targetWindow);
103
+ this._onMessage = this._onMessage.bind(this);
104
+ // This method is already bound.
105
+ // eslint-disable-next-line @typescript-eslint/unbound-method
106
+ window.addEventListener('message', this._onMessage, false);
107
+ this._handshake();
108
+ }
109
+ }
110
+
111
+ //# sourceMappingURL=WebViewExecutorStream.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/webview/WebViewExecutorStream.ts"],"sourcesContent":["import type { PostMessageEvent } from '@metamask/post-message-stream';\nimport { BasePostMessageStream } from '@metamask/post-message-stream';\nimport { isValidStreamMessage } from '@metamask/post-message-stream/dist/utils';\nimport { base64ToBytes, bytesToString } from '@metamask/utils';\n\ntype WebViewExecutorStreamArgs = {\n name: string;\n target: string;\n targetWindow: Window['ReactNativeWebView'];\n};\n\nexport class WebViewExecutorStream extends BasePostMessageStream {\n #name;\n\n #target;\n\n #targetWindow;\n\n /**\n * A special post-message-stream to be used by the WebView executor.\n *\n * This stream is different in a few ways:\n * - It expects data to be base64 encoded\n * - It stringifies the data it posts\n * - It does less validation of origins\n *\n * @param args - Options bag.\n * @param args.name - The name of the stream. Used to differentiate between\n * multiple streams sharing the same window object. child:WebView\n * @param args.target - The name of the stream to exchange messages with. parent:rnside\n * @param args.targetWindow - The window object of the target stream.\n */\n\n constructor({ name, target, targetWindow }: WebViewExecutorStreamArgs) {\n super();\n\n this.#name = name;\n this.#target = target;\n this.#targetWindow = targetWindow;\n\n this._onMessage = this._onMessage.bind(this);\n\n // This method is already bound.\n // eslint-disable-next-line @typescript-eslint/unbound-method\n window.addEventListener('message', this._onMessage as any, false);\n\n this._handshake();\n }\n\n /**\n * Webview needs to receive strings only on postMessage. That's the main difference between this and the original window post message stream.\n * Reference: https://github.com/react-native-webview/react-native-webview/blob/master/docs/Guide.md?plain=1#L471\n */\n\n protected _postMessage(data: unknown): void {\n this.#targetWindow.postMessage(\n JSON.stringify({\n target: this.#target,\n data,\n }),\n );\n }\n\n private _onMessage(event: PostMessageEvent): void {\n if (typeof event.data !== 'string') {\n return;\n }\n\n const bytes = base64ToBytes(event.data);\n const message = JSON.parse(bytesToString(bytes));\n\n // Notice that we don't check targetWindow or targetOrigin here.\n // This doesn't seem possible to do in RN.\n if (!isValidStreamMessage(message) || message.target !== this.#name) {\n return;\n }\n\n this._onData(message.data);\n }\n\n _destroy() {\n // This method is already bound.\n // eslint-disable-next-line @typescript-eslint/unbound-method\n window.removeEventListener('message', this._onMessage as any, false);\n }\n}\n"],"names":["BasePostMessageStream","isValidStreamMessage","base64ToBytes","bytesToString","WebViewExecutorStream","_postMessage","data","targetWindow","postMessage","JSON","stringify","target","_onMessage","event","bytes","message","parse","name","_onData","_destroy","window","removeEventListener","constructor","bind","addEventListener","_handshake"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,SAASA,qBAAqB,QAAQ,gCAAgC;AACtE,SAASC,oBAAoB,QAAQ,2CAA2C;AAChF,SAASC,aAAa,EAAEC,aAAa,QAAQ,kBAAkB;IAS7D,qCAEA,uCAEA;AALF,OAAO,MAAMC,8BAA8BJ;IAsCzC;;;GAGC,GAED,AAAUK,aAAaC,IAAa,EAAQ;QAC1C,yBAAA,IAAI,EAAEC,eAAaC,WAAW,CAC5BC,KAAKC,SAAS,CAAC;YACbC,MAAM,2BAAE,IAAI,EAAEA;YACdL;QACF;IAEJ;IAEQM,WAAWC,KAAuB,EAAQ;QAChD,IAAI,OAAOA,MAAMP,IAAI,KAAK,UAAU;YAClC;QACF;QAEA,MAAMQ,QAAQZ,cAAcW,MAAMP,IAAI;QACtC,MAAMS,UAAUN,KAAKO,KAAK,CAACb,cAAcW;QAEzC,gEAAgE;QAChE,0CAA0C;QAC1C,IAAI,CAACb,qBAAqBc,YAAYA,QAAQJ,MAAM,8BAAK,IAAI,EAAEM,QAAM;YACnE;QACF;QAEA,IAAI,CAACC,OAAO,CAACH,QAAQT,IAAI;IAC3B;IAEAa,WAAW;QACT,gCAAgC;QAChC,6DAA6D;QAC7DC,OAAOC,mBAAmB,CAAC,WAAW,IAAI,CAACT,UAAU,EAAS;IAChE;IAlEA;;;;;;;;;;;;;GAaC,GAEDU,YAAY,EAAEL,IAAI,EAAEN,MAAM,EAAEJ,YAAY,EAA6B,CAAE;QACrE,KAAK;QAtBP,gCAAA;;mBAAA,KAAA;;QAEA,gCAAA;;mBAAA,KAAA;;QAEA,gCAAA;;mBAAA,KAAA;;uCAoBQU,OAAOA;uCACPN,SAASA;uCACTJ,eAAeA;QAErB,IAAI,CAACK,UAAU,GAAG,IAAI,CAACA,UAAU,CAACW,IAAI,CAAC,IAAI;QAE3C,gCAAgC;QAChC,6DAA6D;QAC7DH,OAAOI,gBAAgB,CAAC,WAAW,IAAI,CAACZ,UAAU,EAAS;QAE3D,IAAI,CAACa,UAAU;IACjB;AAsCF"}
@@ -1,14 +1,14 @@
1
- import { BrowserRuntimePostMessageStream } from '@metamask/post-message-stream';
2
1
  import { executeLockdownEvents } from '../common/lockdown/lockdown-events';
3
2
  import { executeLockdownMore } from '../common/lockdown/lockdown-more';
4
3
  import { ProxySnapExecutor } from '../proxy/ProxySnapExecutor';
4
+ import { WebViewExecutorStream } from './WebViewExecutorStream';
5
5
  // Lockdown is already applied in LavaMoat
6
6
  executeLockdownMore();
7
7
  executeLockdownEvents();
8
- // The stream from the offscreen document to the execution service.
9
- const parentStream = new BrowserRuntimePostMessageStream({
8
+ const parentStream = new WebViewExecutorStream({
10
9
  name: 'child',
11
- target: 'parent'
10
+ target: 'parent',
11
+ targetWindow: window.ReactNativeWebView
12
12
  });
13
13
  ProxySnapExecutor.initialize(parentStream);
14
14
 
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/webview/index.ts"],"sourcesContent":["import { executeLockdownEvents } from '../common/lockdown/lockdown-events';\nimport { executeLockdownMore } from '../common/lockdown/lockdown-more';\nimport { ProxySnapExecutor } from '../proxy/ProxySnapExecutor';\nimport { WebViewExecutorStream } from './WebViewExecutorStream';\n\n// Lockdown is already applied in LavaMoat\nexecuteLockdownMore();\nexecuteLockdownEvents();\n\nconst parentStream = new WebViewExecutorStream({\n name: 'child', // webview\n target: 'parent', // rnside\n targetWindow: window.ReactNativeWebView,\n});\n\nProxySnapExecutor.initialize(parentStream);\n"],"names":["executeLockdownEvents","executeLockdownMore","ProxySnapExecutor","WebViewExecutorStream","parentStream","name","target","targetWindow","window","ReactNativeWebView","initialize"],"mappings":"AAAA,SAASA,qBAAqB,QAAQ,qCAAqC;AAC3E,SAASC,mBAAmB,QAAQ,mCAAmC;AACvE,SAASC,iBAAiB,QAAQ,6BAA6B;AAC/D,SAASC,qBAAqB,QAAQ,0BAA0B;AAEhE,0CAA0C;AAC1CF;AACAD;AAEA,MAAMI,eAAe,IAAID,sBAAsB;IAC7CE,MAAM;IACNC,QAAQ;IACRC,cAAcC,OAAOC,kBAAkB;AACzC;AAEAP,kBAAkBQ,UAAU,CAACN"}
@@ -103,6 +103,37 @@ export declare type PossibleLookupRequestArgs = typeof baseNameLookupArgs & {
103
103
  * object.
104
104
  */
105
105
  export declare function assertIsOnNameLookupRequestArguments(value: unknown): asserts value is OnNameLookupRequestArguments;
106
+ export declare const OnUserInputArgumentsStruct: import("superstruct").Struct<{
107
+ id: string;
108
+ event: {
109
+ type: import("@metamask/snaps-sdk").UserInputEventType.ButtonClickEvent;
110
+ name?: string | undefined;
111
+ } | {
112
+ value: Record<string, string>;
113
+ type: import("@metamask/snaps-sdk").UserInputEventType.FormSubmitEvent;
114
+ name: string;
115
+ };
116
+ }, {
117
+ id: import("superstruct").Struct<string, null>;
118
+ event: import("superstruct").Struct<{
119
+ type: import("@metamask/snaps-sdk").UserInputEventType.ButtonClickEvent;
120
+ name?: string | undefined;
121
+ } | {
122
+ value: Record<string, string>;
123
+ type: import("@metamask/snaps-sdk").UserInputEventType.FormSubmitEvent;
124
+ name: string;
125
+ }, null>;
126
+ }>;
127
+ export declare type OnUserInputArguments = Infer<typeof OnUserInputArgumentsStruct>;
128
+ /**
129
+ * Asserts that the given value is a valid {@link OnUserInputArguments}
130
+ * object.
131
+ *
132
+ * @param value - The value to validate.
133
+ * @throws If the value is not a valid {@link OnUserInputArguments}
134
+ * object.
135
+ */
136
+ export declare function assertIsOnUserInputRequestArguments(value: unknown): asserts value is OnUserInputArguments;
106
137
  declare const OkResponseStruct: import("superstruct").Struct<{
107
138
  result: "OK";
108
139
  id: string | number | null;
@@ -0,0 +1 @@
1
+ export * from './proxy';
@@ -0,0 +1 @@
1
+ export * from './ProxySnapExecutor';
@@ -0,0 +1,32 @@
1
+ import { BasePostMessageStream } from '@metamask/post-message-stream';
2
+ declare type WebViewExecutorStreamArgs = {
3
+ name: string;
4
+ target: string;
5
+ targetWindow: Window['ReactNativeWebView'];
6
+ };
7
+ export declare class WebViewExecutorStream extends BasePostMessageStream {
8
+ #private;
9
+ /**
10
+ * A special post-message-stream to be used by the WebView executor.
11
+ *
12
+ * This stream is different in a few ways:
13
+ * - It expects data to be base64 encoded
14
+ * - It stringifies the data it posts
15
+ * - It does less validation of origins
16
+ *
17
+ * @param args - Options bag.
18
+ * @param args.name - The name of the stream. Used to differentiate between
19
+ * multiple streams sharing the same window object. child:WebView
20
+ * @param args.target - The name of the stream to exchange messages with. parent:rnside
21
+ * @param args.targetWindow - The window object of the target stream.
22
+ */
23
+ constructor({ name, target, targetWindow }: WebViewExecutorStreamArgs);
24
+ /**
25
+ * Webview needs to receive strings only on postMessage. That's the main difference between this and the original window post message stream.
26
+ * Reference: https://github.com/react-native-webview/react-native-webview/blob/master/docs/Guide.md?plain=1#L471
27
+ */
28
+ protected _postMessage(data: unknown): void;
29
+ private _onMessage;
30
+ _destroy(): void;
31
+ }
32
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask/snaps-execution-environments",
3
- "version": "3.5.0",
3
+ "version": "4.0.1",
4
4
  "description": "Snap sandbox environments for executing SES javascript",
5
5
  "repository": {
6
6
  "type": "git",
@@ -44,13 +44,13 @@
44
44
  "lint:dependencies": "depcheck"
45
45
  },
46
46
  "dependencies": {
47
- "@metamask/json-rpc-engine": "^7.3.1",
47
+ "@metamask/json-rpc-engine": "^7.3.2",
48
48
  "@metamask/object-multiplex": "^2.0.0",
49
- "@metamask/post-message-stream": "^7.0.0",
49
+ "@metamask/post-message-stream": "^8.0.0",
50
50
  "@metamask/providers": "^14.0.2",
51
51
  "@metamask/rpc-errors": "^6.1.0",
52
- "@metamask/snaps-sdk": "^1.4.0",
53
- "@metamask/snaps-utils": "^5.2.0",
52
+ "@metamask/snaps-sdk": "^2.1.0",
53
+ "@metamask/snaps-utils": "^6.1.0",
54
54
  "@metamask/utils": "^8.3.0",
55
55
  "nanoid": "^3.1.31",
56
56
  "readable-stream": "^3.6.2",
@@ -62,8 +62,8 @@
62
62
  "@babel/preset-typescript": "^7.23.2",
63
63
  "@esbuild-plugins/node-globals-polyfill": "^0.2.3",
64
64
  "@esbuild-plugins/node-modules-polyfill": "^0.2.2",
65
- "@lavamoat/allow-scripts": "^3.0.0",
66
- "@lavamoat/lavapack": "^6.0.2",
65
+ "@lavamoat/allow-scripts": "^3.0.2",
66
+ "@lavamoat/lavapack": "^6.1.0",
67
67
  "@lavamoat/lavatube": "^1.0.0",
68
68
  "@metamask/auto-changelog": "^3.4.4",
69
69
  "@metamask/eslint-config": "^12.1.0",
@@ -105,8 +105,8 @@
105
105
  "jest": "^29.0.2",
106
106
  "jest-environment-node": "^29.5.0",
107
107
  "jest-fetch-mock": "^3.0.3",
108
- "lavamoat": "^8.0.2",
109
- "lavamoat-browserify": "^17.0.2",
108
+ "lavamoat": "^8.0.3",
109
+ "lavamoat-browserify": "^17.0.4",
110
110
  "prettier": "^2.7.1",
111
111
  "prettier-plugin-packagejson": "^2.2.11",
112
112
  "rimraf": "^4.1.2",