@metamask/snaps-execution-environments 3.4.3 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +24 -1
- package/dist/browserify/iframe/bundle.js +5 -5
- package/dist/browserify/iframe/index.html +1132 -389
- package/dist/browserify/node-process/bundle.js +1135 -392
- package/dist/browserify/node-thread/bundle.js +1135 -392
- package/dist/browserify/webview/bundle.js +9 -0
- package/dist/browserify/{offscreen → webview}/index.html +1132 -389
- package/dist/browserify/worker-executor/bundle.js +1137 -394
- package/dist/browserify/worker-pool/bundle.js +5 -5
- package/dist/browserify/worker-pool/index.html +1132 -389
- package/dist/cjs/common/BaseSnapExecutor.js +2 -2
- package/dist/cjs/common/BaseSnapExecutor.js.map +1 -1
- package/dist/cjs/common/commands.js +18 -0
- package/dist/cjs/common/commands.js.map +1 -1
- package/dist/cjs/common/validation.js +27 -0
- package/dist/cjs/common/validation.js.map +1 -1
- package/dist/cjs/index.js +20 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/{offscreen/OffscreenSnapExecutor.js → proxy/ProxySnapExecutor.js} +26 -16
- package/dist/cjs/proxy/ProxySnapExecutor.js.map +1 -0
- package/dist/cjs/proxy/index.js +20 -0
- package/dist/cjs/proxy/index.js.map +1 -0
- package/dist/cjs/webview/WebViewExecutorStream.js +121 -0
- package/dist/cjs/webview/WebViewExecutorStream.js.map +1 -0
- package/dist/cjs/webview/index.js +19 -0
- package/dist/cjs/webview/index.js.map +1 -0
- package/dist/esm/common/BaseSnapExecutor.js +1 -1
- package/dist/esm/common/BaseSnapExecutor.js.map +1 -1
- package/dist/esm/common/commands.js +19 -1
- package/dist/esm/common/commands.js.map +1 -1
- package/dist/esm/common/validation.js +29 -0
- package/dist/esm/common/validation.js.map +1 -1
- package/dist/esm/index.js +3 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/{offscreen/OffscreenSnapExecutor.js → proxy/ProxySnapExecutor.js} +25 -20
- package/dist/esm/proxy/ProxySnapExecutor.js.map +1 -0
- package/dist/esm/proxy/index.js +3 -0
- package/dist/esm/proxy/index.js.map +1 -0
- package/dist/esm/webview/WebViewExecutorStream.js +111 -0
- package/dist/esm/webview/WebViewExecutorStream.js.map +1 -0
- package/dist/esm/webview/index.js +15 -0
- package/dist/esm/webview/index.js.map +1 -0
- package/dist/types/common/validation.d.ts +48 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/{offscreen/OffscreenSnapExecutor.d.ts → proxy/ProxySnapExecutor.d.ts} +9 -9
- package/dist/types/proxy/index.d.ts +1 -0
- package/dist/types/webview/WebViewExecutorStream.d.ts +32 -0
- package/package.json +13 -13
- package/dist/browserify/offscreen/bundle.js +0 -9
- package/dist/cjs/offscreen/OffscreenSnapExecutor.js.map +0 -1
- package/dist/cjs/offscreen/index.js +0 -19
- package/dist/cjs/offscreen/index.js.map +0 -1
- package/dist/esm/offscreen/OffscreenSnapExecutor.js.map +0 -1
- package/dist/esm/offscreen/index.js +0 -15
- package/dist/esm/offscreen/index.js.map +0 -1
- /package/dist/types/{offscreen → webview}/index.d.ts +0 -0
|
@@ -0,0 +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/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,kDAAkD;QAClD,0BAAA,IAAI,EAAEE,gBAAAA,oBAAN,IAAI,EAAgBF,OACjBG,IAAI,CAAC;YACJ,0BAAA,IAAI,EAAEN,SAAAA,aAAN,IAAI,EAASE;QACf,GACCK,KAAK,CAAC,CAACC;YACNnB,SAAS,oCAAoCmB;QAC/C;QAEF;IACF;IAEA,2EAA2E;IAC3E,uDAAuD;IACvD,IAAIJ,QAAQK,MAAM,KAAK,gBAAgB;QACrC,0BAAA,IAAI,EAAEC,eAAAA,mBAAN,IAAI,EAAeP;QACnB;IACF;IAEA,IAAI,CAACL,IAAI,CAACK,MAAM,CAACR,MAAM,CAACgB,KAAK,CAACP;AAChC;AAOA,eAAA,cAAqBD,KAAa;IAChC,MAAMS,SAAS,MAAMxB,sCAAa,IAAI,EAAEQ,YAAUO;IAClD,MAAMU,YAAY,IAAI3B,wBAAwB;QAC5C4B,MAAM;QACNC,QAAQ;QACRC,cAAcJ;QACdK,cAAc;IAChB;IAEA,yEAAyE;IACzEJ,UAAUd,EAAE,CAAC,QAAQ,CAACG;QACpB,yBAAA,IAAI,EAAEP,SAAOgB,KAAK,CAAC;YAAET;YAAMC;QAAM;IACnC;IAEA,IAAI,CAACL,IAAI,CAACK,MAAM,GAAG;QAAEe,IAAIf;QAAOS;QAAQjB,QAAQkB;IAAU;IAC1D,OAAO,IAAI,CAACf,IAAI,CAACK,MAAM;AACzB;AAQA,SAAA,aAAcA,KAAa;IACzBb,OAAO,IAAI,CAACQ,IAAI,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"}
|
|
@@ -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"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { executeLockdownEvents } from '../common/lockdown/lockdown-events';
|
|
2
|
+
import { executeLockdownMore } from '../common/lockdown/lockdown-more';
|
|
3
|
+
import { ProxySnapExecutor } from '../proxy/ProxySnapExecutor';
|
|
4
|
+
import { WebViewExecutorStream } from './WebViewExecutorStream';
|
|
5
|
+
// Lockdown is already applied in LavaMoat
|
|
6
|
+
executeLockdownMore();
|
|
7
|
+
executeLockdownEvents();
|
|
8
|
+
const parentStream = new WebViewExecutorStream({
|
|
9
|
+
name: 'child',
|
|
10
|
+
target: 'parent',
|
|
11
|
+
targetWindow: window.ReactNativeWebView
|
|
12
|
+
});
|
|
13
|
+
ProxySnapExecutor.initialize(parentStream);
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -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"}
|
|
@@ -62,6 +62,23 @@ export declare type OnTransactionRequestArguments = Infer<typeof OnTransactionRe
|
|
|
62
62
|
* object.
|
|
63
63
|
*/
|
|
64
64
|
export declare function assertIsOnTransactionRequestArguments(value: unknown): asserts value is OnTransactionRequestArguments;
|
|
65
|
+
export declare const OnSignatureRequestArgumentsStruct: import("superstruct").Struct<{
|
|
66
|
+
signature: Record<string, Json>;
|
|
67
|
+
signatureOrigin: string | null;
|
|
68
|
+
}, {
|
|
69
|
+
signature: import("superstruct").Struct<Record<string, Json>, null>;
|
|
70
|
+
signatureOrigin: import("superstruct").Struct<string | null, null>;
|
|
71
|
+
}>;
|
|
72
|
+
export declare type OnSignatureRequestArguments = Infer<typeof OnSignatureRequestArgumentsStruct>;
|
|
73
|
+
/**
|
|
74
|
+
* Asserts that the given value is a valid {@link OnSignatureRequestArguments}
|
|
75
|
+
* object.
|
|
76
|
+
*
|
|
77
|
+
* @param value - The value to validate.
|
|
78
|
+
* @throws If the value is not a valid {@link OnSignatureRequestArguments}
|
|
79
|
+
* object.
|
|
80
|
+
*/
|
|
81
|
+
export declare function assertIsOnSignatureRequestArguments(value: unknown): asserts value is OnSignatureRequestArguments;
|
|
65
82
|
declare const baseNameLookupArgs: {
|
|
66
83
|
chainId: import("superstruct").Struct<`${string}:${string}`, null>;
|
|
67
84
|
};
|
|
@@ -86,6 +103,37 @@ export declare type PossibleLookupRequestArgs = typeof baseNameLookupArgs & {
|
|
|
86
103
|
* object.
|
|
87
104
|
*/
|
|
88
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;
|
|
89
137
|
declare const OkResponseStruct: import("superstruct").Struct<{
|
|
90
138
|
result: "OK";
|
|
91
139
|
id: string | number | null;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './proxy';
|
|
@@ -6,20 +6,19 @@ declare type ExecutorJob = {
|
|
|
6
6
|
stream: WindowPostMessageStream;
|
|
7
7
|
};
|
|
8
8
|
/**
|
|
9
|
-
* A snap executor
|
|
9
|
+
* A "proxy" snap executor that uses a level of indirection to execute snaps.
|
|
10
|
+
*
|
|
11
|
+
* Useful for multiple execution environments.
|
|
10
12
|
*
|
|
11
13
|
* This is not a traditional snap executor, as it does not execute snaps itself.
|
|
12
14
|
* Instead, it creates an iframe window for each snap execution, and sends the
|
|
13
15
|
* snap execution request to the iframe window. The iframe window is responsible
|
|
14
16
|
* for executing the snap.
|
|
15
17
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* acts as a proxy between the extension and the iframe execution environment.
|
|
19
|
-
*
|
|
20
|
-
* @see https://developer.chrome.com/docs/extensions/reference/offscreen/
|
|
18
|
+
* This executor is persisted between snap executions. The executor essentially
|
|
19
|
+
* acts as a proxy between the client and the iframe execution environment.
|
|
21
20
|
*/
|
|
22
|
-
export declare class
|
|
21
|
+
export declare class ProxySnapExecutor {
|
|
23
22
|
#private;
|
|
24
23
|
readonly jobs: Record<string, ExecutorJob>;
|
|
25
24
|
/**
|
|
@@ -27,9 +26,10 @@ export declare class OffscreenSnapExecutor {
|
|
|
27
26
|
* constructor.
|
|
28
27
|
*
|
|
29
28
|
* @param stream - The stream to use for communication.
|
|
29
|
+
* @param frameUrl - An optional URL for the iframe to use.
|
|
30
30
|
* @returns The initialized executor.
|
|
31
31
|
*/
|
|
32
|
-
static initialize(stream: BasePostMessageStream):
|
|
33
|
-
constructor(stream: BasePostMessageStream);
|
|
32
|
+
static initialize(stream: BasePostMessageStream, frameUrl?: string): ProxySnapExecutor;
|
|
33
|
+
constructor(stream: BasePostMessageStream, frameUrl: string);
|
|
34
34
|
}
|
|
35
35
|
export {};
|
|
@@ -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
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "Snap sandbox environments for executing SES javascript",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -44,14 +44,14 @@
|
|
|
44
44
|
"lint:dependencies": "depcheck"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@metamask/json-rpc-engine": "^7.3.
|
|
47
|
+
"@metamask/json-rpc-engine": "^7.3.2",
|
|
48
48
|
"@metamask/object-multiplex": "^2.0.0",
|
|
49
|
-
"@metamask/post-message-stream": "^
|
|
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": "^
|
|
53
|
-
"@metamask/snaps-utils": "^
|
|
54
|
-
"@metamask/utils": "^8.
|
|
52
|
+
"@metamask/snaps-sdk": "^2.0.0",
|
|
53
|
+
"@metamask/snaps-utils": "^6.0.0",
|
|
54
|
+
"@metamask/utils": "^8.3.0",
|
|
55
55
|
"nanoid": "^3.1.31",
|
|
56
56
|
"readable-stream": "^3.6.2",
|
|
57
57
|
"superstruct": "^1.0.3"
|
|
@@ -62,10 +62,10 @@
|
|
|
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": "^
|
|
66
|
-
"@lavamoat/lavapack": "^
|
|
67
|
-
"@lavamoat/lavatube": "^0.
|
|
68
|
-
"@metamask/auto-changelog": "^3.4.
|
|
65
|
+
"@lavamoat/allow-scripts": "^3.0.0",
|
|
66
|
+
"@lavamoat/lavapack": "^6.0.2",
|
|
67
|
+
"@lavamoat/lavatube": "^1.0.0",
|
|
68
|
+
"@metamask/auto-changelog": "^3.4.4",
|
|
69
69
|
"@metamask/eslint-config": "^12.1.0",
|
|
70
70
|
"@metamask/eslint-config-jest": "^12.1.0",
|
|
71
71
|
"@metamask/eslint-config-nodejs": "^12.1.0",
|
|
@@ -105,13 +105,13 @@
|
|
|
105
105
|
"jest": "^29.0.2",
|
|
106
106
|
"jest-environment-node": "^29.5.0",
|
|
107
107
|
"jest-fetch-mock": "^3.0.3",
|
|
108
|
-
"lavamoat": "^
|
|
109
|
-
"lavamoat-browserify": "^
|
|
108
|
+
"lavamoat": "^8.0.2",
|
|
109
|
+
"lavamoat-browserify": "^17.0.2",
|
|
110
110
|
"prettier": "^2.7.1",
|
|
111
111
|
"prettier-plugin-packagejson": "^2.2.11",
|
|
112
112
|
"rimraf": "^4.1.2",
|
|
113
113
|
"serve-handler": "^6.1.5",
|
|
114
|
-
"ses": "^
|
|
114
|
+
"ses": "^1.1.0",
|
|
115
115
|
"terser": "^5.17.7",
|
|
116
116
|
"ts-node": "^10.9.1",
|
|
117
117
|
"typescript": "~4.8.4",
|