@metamask/snaps-controllers 8.3.1 → 9.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 +19 -1
- package/dist/{chunk-YIQM6ZKA.mjs → chunk-4M2FX2AT.mjs} +9 -2
- package/dist/{chunk-YIQM6ZKA.mjs.map → chunk-4M2FX2AT.mjs.map} +1 -1
- package/dist/chunk-6ERB63FH.js +58 -0
- package/dist/chunk-6ERB63FH.js.map +1 -0
- package/dist/{chunk-PIQFC66N.js → chunk-6VGMRXGY.js} +7 -7
- package/dist/{chunk-UJJCRV7W.mjs → chunk-7CZDBXIY.mjs} +10 -3
- package/dist/chunk-7CZDBXIY.mjs.map +1 -0
- package/dist/chunk-CIFVYFJW.mjs +58 -0
- package/dist/chunk-CIFVYFJW.mjs.map +1 -0
- package/dist/{chunk-5YBORD3A.js → chunk-JQ54YYLU.js} +9 -2
- package/dist/chunk-JQ54YYLU.js.map +1 -0
- package/dist/{chunk-JCQR3I2Q.mjs → chunk-RVWBSSZM.mjs} +18 -6
- package/dist/chunk-RVWBSSZM.mjs.map +1 -0
- package/dist/{chunk-7TYZZFHZ.js → chunk-WCDDYBFW.js} +10 -3
- package/dist/chunk-WCDDYBFW.js.map +1 -0
- package/dist/{chunk-QLWR3M4Q.mjs → chunk-YAZ55WUL.mjs} +2 -2
- package/dist/{chunk-NRZEYYBQ.js → chunk-ZBSBCWWM.js} +18 -6
- package/dist/chunk-ZBSBCWWM.js.map +1 -0
- package/dist/cronjob/CronjobController.js +5 -5
- package/dist/cronjob/CronjobController.mjs +5 -5
- package/dist/cronjob/index.js +5 -5
- package/dist/cronjob/index.mjs +5 -5
- package/dist/index.js +6 -6
- package/dist/index.mjs +5 -5
- package/dist/interface/SnapInterfaceController.js +3 -3
- package/dist/interface/SnapInterfaceController.mjs +2 -2
- package/dist/interface/index.js +3 -3
- package/dist/interface/index.mjs +2 -2
- package/dist/interface/utils.js +2 -2
- package/dist/interface/utils.mjs +1 -1
- package/dist/node.js +6 -6
- package/dist/node.mjs +5 -5
- package/dist/react-native.js +6 -6
- package/dist/react-native.mjs +5 -5
- package/dist/services/browser.js +2 -2
- package/dist/services/browser.mjs +1 -1
- package/dist/services/index.js +2 -2
- package/dist/services/index.mjs +1 -1
- package/dist/services/node-js/NodeProcessExecutionService.js +1 -1
- package/dist/services/node-js/NodeProcessExecutionService.mjs +1 -1
- package/dist/services/node-js/NodeThreadExecutionService.js +1 -1
- package/dist/services/node-js/NodeThreadExecutionService.mjs +1 -1
- package/dist/services/node-js/index.js +1 -1
- package/dist/services/node-js/index.mjs +1 -1
- package/dist/services/node.js +2 -2
- package/dist/services/node.mjs +1 -1
- package/dist/services/offscreen/OffscreenExecutionService.js +2 -2
- package/dist/services/offscreen/OffscreenExecutionService.mjs +1 -1
- package/dist/services/offscreen/index.js +2 -2
- package/dist/services/offscreen/index.mjs +1 -1
- package/dist/services/react-native.js +2 -2
- package/dist/services/react-native.mjs +1 -1
- package/dist/snaps/SnapController.js +3 -3
- package/dist/snaps/SnapController.mjs +2 -2
- package/dist/snaps/constants.js +4 -2
- package/dist/snaps/constants.mjs +5 -3
- package/dist/snaps/index.js +3 -3
- package/dist/snaps/index.mjs +2 -2
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/services/offscreen/OffscreenExecutionService.d.ts +8 -9
- package/dist/types/snaps/SnapController.d.ts +1 -0
- package/dist/types/snaps/constants.d.ts +6 -0
- package/package.json +11 -11
- package/dist/chunk-3OJFF5CK.mjs +0 -72
- package/dist/chunk-3OJFF5CK.mjs.map +0 -1
- package/dist/chunk-5YBORD3A.js.map +0 -1
- package/dist/chunk-7TYZZFHZ.js.map +0 -1
- package/dist/chunk-HK4OAMJT.js +0 -72
- package/dist/chunk-HK4OAMJT.js.map +0 -1
- package/dist/chunk-JCQR3I2Q.mjs.map +0 -1
- package/dist/chunk-NRZEYYBQ.js.map +0 -1
- package/dist/chunk-UJJCRV7W.mjs.map +0 -1
- /package/dist/{chunk-PIQFC66N.js.map → chunk-6VGMRXGY.js.map} +0 -0
- /package/dist/{chunk-QLWR3M4Q.mjs.map → chunk-YAZ55WUL.mjs.map} +0 -0
|
@@ -1,29 +1,28 @@
|
|
|
1
1
|
import type { ExecutionServiceArgs } from '../AbstractExecutionService';
|
|
2
2
|
import { ProxyExecutionService } from '../proxy/ProxyExecutionService';
|
|
3
3
|
declare type OffscreenExecutionEnvironmentServiceArgs = {
|
|
4
|
-
|
|
4
|
+
offscreenPromise: Promise<unknown>;
|
|
5
5
|
} & ExecutionServiceArgs;
|
|
6
6
|
export declare class OffscreenExecutionService extends ProxyExecutionService {
|
|
7
7
|
#private;
|
|
8
|
-
readonly documentUrl: URL;
|
|
9
8
|
/**
|
|
10
9
|
* Create a new offscreen execution service.
|
|
11
10
|
*
|
|
12
11
|
* @param args - The constructor arguments.
|
|
13
|
-
* @param args.documentUrl - The URL of the offscreen document to use as the
|
|
14
|
-
* execution environment. This must be a URL relative to the location where
|
|
15
|
-
* this is called. This cannot be a public (http(s)) URL.
|
|
16
12
|
* @param args.messenger - The messenger to use for communication with the
|
|
17
13
|
* `SnapController`.
|
|
18
14
|
* @param args.setupSnapProvider - The function to use to set up the snap
|
|
19
15
|
* provider.
|
|
16
|
+
* @param args.offscreenPromise - A promise that resolves when the offscreen
|
|
17
|
+
* environment is ready.
|
|
20
18
|
*/
|
|
21
|
-
constructor({
|
|
19
|
+
constructor({ messenger, setupSnapProvider, offscreenPromise, }: OffscreenExecutionEnvironmentServiceArgs);
|
|
22
20
|
/**
|
|
23
|
-
* Create a new stream for the
|
|
24
|
-
*
|
|
21
|
+
* Create a new stream for the given job ID. This will wait for the offscreen
|
|
22
|
+
* environment to be ready before creating the stream.
|
|
25
23
|
*
|
|
26
|
-
* @param jobId - The job ID.
|
|
24
|
+
* @param jobId - The job ID to create a stream for.
|
|
25
|
+
* @returns The stream for the given job ID.
|
|
27
26
|
*/
|
|
28
27
|
protected initEnvStream(jobId: string): Promise<{
|
|
29
28
|
worker: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask/snaps-controllers",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "9.0.0",
|
|
4
4
|
"description": "Controllers for MetaMask Snaps.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -53,19 +53,19 @@
|
|
|
53
53
|
"build:ci": "tsup --clean"
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@metamask/approval-controller": "^
|
|
57
|
-
"@metamask/base-controller": "^
|
|
58
|
-
"@metamask/json-rpc-engine": "^
|
|
59
|
-
"@metamask/json-rpc-middleware-stream": "^
|
|
56
|
+
"@metamask/approval-controller": "^7.0.0",
|
|
57
|
+
"@metamask/base-controller": "^6.0.0",
|
|
58
|
+
"@metamask/json-rpc-engine": "^9.0.0",
|
|
59
|
+
"@metamask/json-rpc-middleware-stream": "^8.0.0",
|
|
60
60
|
"@metamask/object-multiplex": "^2.0.0",
|
|
61
|
-
"@metamask/permission-controller": "^
|
|
62
|
-
"@metamask/phishing-controller": "^
|
|
61
|
+
"@metamask/permission-controller": "^10.0.0",
|
|
62
|
+
"@metamask/phishing-controller": "^10.0.0",
|
|
63
63
|
"@metamask/post-message-stream": "^8.1.0",
|
|
64
64
|
"@metamask/rpc-errors": "^6.2.1",
|
|
65
65
|
"@metamask/snaps-registry": "^3.1.0",
|
|
66
|
-
"@metamask/snaps-rpc-methods": "^9.1.
|
|
67
|
-
"@metamask/snaps-sdk": "^
|
|
68
|
-
"@metamask/snaps-utils": "^7.
|
|
66
|
+
"@metamask/snaps-rpc-methods": "^9.1.3",
|
|
67
|
+
"@metamask/snaps-sdk": "^5.0.0",
|
|
68
|
+
"@metamask/snaps-utils": "^7.6.0",
|
|
69
69
|
"@metamask/utils": "^8.3.0",
|
|
70
70
|
"@xstate/fsm": "^2.0.0",
|
|
71
71
|
"browserify-zlib": "^0.2.0",
|
|
@@ -138,7 +138,7 @@
|
|
|
138
138
|
"webdriverio": "^8.19.0"
|
|
139
139
|
},
|
|
140
140
|
"peerDependencies": {
|
|
141
|
-
"@metamask/snaps-execution-environments": "^6.
|
|
141
|
+
"@metamask/snaps-execution-environments": "^6.4.0"
|
|
142
142
|
},
|
|
143
143
|
"peerDependenciesMeta": {
|
|
144
144
|
"@metamask/snaps-execution-environments": {
|
package/dist/chunk-3OJFF5CK.mjs
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ProxyExecutionService
|
|
3
|
-
} from "./chunk-3A72M4GC.mjs";
|
|
4
|
-
import {
|
|
5
|
-
__privateAdd,
|
|
6
|
-
__privateMethod
|
|
7
|
-
} from "./chunk-YRZVIDCF.mjs";
|
|
8
|
-
|
|
9
|
-
// src/services/offscreen/OffscreenExecutionService.ts
|
|
10
|
-
import { BrowserRuntimePostMessageStream } from "@metamask/post-message-stream";
|
|
11
|
-
var _createDocument, createDocument_fn;
|
|
12
|
-
var OffscreenExecutionService = class extends ProxyExecutionService {
|
|
13
|
-
/**
|
|
14
|
-
* Create a new offscreen execution service.
|
|
15
|
-
*
|
|
16
|
-
* @param args - The constructor arguments.
|
|
17
|
-
* @param args.documentUrl - The URL of the offscreen document to use as the
|
|
18
|
-
* execution environment. This must be a URL relative to the location where
|
|
19
|
-
* this is called. This cannot be a public (http(s)) URL.
|
|
20
|
-
* @param args.messenger - The messenger to use for communication with the
|
|
21
|
-
* `SnapController`.
|
|
22
|
-
* @param args.setupSnapProvider - The function to use to set up the snap
|
|
23
|
-
* provider.
|
|
24
|
-
*/
|
|
25
|
-
constructor({
|
|
26
|
-
documentUrl,
|
|
27
|
-
messenger,
|
|
28
|
-
setupSnapProvider
|
|
29
|
-
}) {
|
|
30
|
-
super({
|
|
31
|
-
messenger,
|
|
32
|
-
setupSnapProvider,
|
|
33
|
-
stream: new BrowserRuntimePostMessageStream({
|
|
34
|
-
name: "parent",
|
|
35
|
-
target: "child"
|
|
36
|
-
})
|
|
37
|
-
});
|
|
38
|
-
/**
|
|
39
|
-
* Creates the offscreen document to be used as the execution environment.
|
|
40
|
-
*
|
|
41
|
-
* If the document already exists, this does nothing.
|
|
42
|
-
*/
|
|
43
|
-
__privateAdd(this, _createDocument);
|
|
44
|
-
this.documentUrl = documentUrl;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Create a new stream for the specified job. This wraps the runtime stream
|
|
48
|
-
* in a stream specific to the job.
|
|
49
|
-
*
|
|
50
|
-
* @param jobId - The job ID.
|
|
51
|
-
*/
|
|
52
|
-
async initEnvStream(jobId) {
|
|
53
|
-
await __privateMethod(this, _createDocument, createDocument_fn).call(this);
|
|
54
|
-
return super.initEnvStream(jobId);
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
_createDocument = new WeakSet();
|
|
58
|
-
createDocument_fn = async function() {
|
|
59
|
-
if (await chrome.offscreen.hasDocument()) {
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
await chrome.offscreen.createDocument({
|
|
63
|
-
justification: "MetaMask Snaps Execution Environment",
|
|
64
|
-
reasons: ["IFRAME_SCRIPTING"],
|
|
65
|
-
url: this.documentUrl.toString()
|
|
66
|
-
});
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
export {
|
|
70
|
-
OffscreenExecutionService
|
|
71
|
-
};
|
|
72
|
-
//# sourceMappingURL=chunk-3OJFF5CK.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/services/offscreen/OffscreenExecutionService.ts"],"sourcesContent":["import { BrowserRuntimePostMessageStream } from '@metamask/post-message-stream';\n\nimport type { ExecutionServiceArgs } from '../AbstractExecutionService';\nimport { ProxyExecutionService } from '../proxy/ProxyExecutionService';\n\ntype OffscreenExecutionEnvironmentServiceArgs = {\n documentUrl: URL;\n} & ExecutionServiceArgs;\n\nexport class OffscreenExecutionService extends ProxyExecutionService {\n public readonly documentUrl: URL;\n\n /**\n * Create a new offscreen execution service.\n *\n * @param args - The constructor arguments.\n * @param args.documentUrl - The URL of the offscreen document to use as the\n * execution environment. This must be a URL relative to the location where\n * this is called. This cannot be a public (http(s)) URL.\n * @param args.messenger - The messenger to use for communication with the\n * `SnapController`.\n * @param args.setupSnapProvider - The function to use to set up the snap\n * provider.\n */\n constructor({\n documentUrl,\n messenger,\n setupSnapProvider,\n }: OffscreenExecutionEnvironmentServiceArgs) {\n super({\n messenger,\n setupSnapProvider,\n stream: new BrowserRuntimePostMessageStream({\n name: 'parent',\n target: 'child',\n }),\n });\n\n this.documentUrl = documentUrl;\n }\n\n /**\n * Create a new stream for the specified job. This wraps the runtime stream\n * in a stream specific to the job.\n *\n * @param jobId - The job ID.\n */\n protected async initEnvStream(jobId: string) {\n // Lazily create the offscreen document.\n await this.#createDocument();\n\n return super.initEnvStream(jobId);\n }\n\n /**\n * Creates the offscreen document to be used as the execution environment.\n *\n * If the document already exists, this does nothing.\n */\n async #createDocument() {\n // Extensions can only have a single offscreen document.\n if (await chrome.offscreen.hasDocument()) {\n return;\n }\n\n await chrome.offscreen.createDocument({\n justification: 'MetaMask Snaps Execution Environment',\n reasons: ['IFRAME_SCRIPTING' as chrome.offscreen.Reason],\n url: this.documentUrl.toString(),\n });\n }\n}\n"],"mappings":";;;;;;;;;AAAA,SAAS,uCAAuC;AAAhD;AASO,IAAM,4BAAN,cAAwC,sBAAsB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAenE,YAAY;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,EACF,GAA6C;AAC3C,UAAM;AAAA,MACJ;AAAA,MACA;AAAA,MACA,QAAQ,IAAI,gCAAgC;AAAA,QAC1C,MAAM;AAAA,QACN,QAAQ;AAAA,MACV,CAAC;AAAA,IACH,CAAC;AAuBH;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAM;AArBJ,SAAK,cAAc;AAAA,EACrB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAgB,cAAc,OAAe;AAE3C,UAAM,sBAAK,oCAAL;AAEN,WAAO,MAAM,cAAc,KAAK;AAAA,EAClC;AAmBF;AAZQ;AAAA,oBAAe,iBAAG;AAEtB,MAAI,MAAM,OAAO,UAAU,YAAY,GAAG;AACxC;AAAA,EACF;AAEA,QAAM,OAAO,UAAU,eAAe;AAAA,IACpC,eAAe;AAAA,IACf,SAAS,CAAC,kBAA6C;AAAA,IACvD,KAAK,KAAK,YAAY,SAAS;AAAA,EACjC,CAAC;AACH;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/snaps/constants.ts"],"names":[],"mappings":";AAAA,SAAS,sBAAsB;AAGxB,IAAM,sBAAsB,OAAO,OAAO;AAAA,EAC/C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,eAAe;AAAA,EACf,eAAe;AAAA,EACf,eAAe;AAAA,EACf,eAAe;AAAA,EACf,eAAe;AAAA,EACf,eAAe;AACjB,CAAC","sourcesContent":["import { SnapEndowments } from '@metamask/snaps-rpc-methods';\n\n// These permissions are allowed without being on the allowlist.\nexport const ALLOWED_PERMISSIONS = Object.freeze([\n 'snap_dialog',\n 'snap_manageState',\n 'snap_notify',\n 'snap_getLocale',\n SnapEndowments.Cronjob,\n SnapEndowments.HomePage,\n SnapEndowments.LifecycleHooks,\n SnapEndowments.EthereumProvider,\n SnapEndowments.TransactionInsight,\n SnapEndowments.SignatureInsight,\n]);\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/interface/utils.ts"],"names":[],"mappings":";AAAA,SAAS,cAAc;AAcvB,SAAS,0BAA0B;AACnC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAUA,SAAS,gBAAgB,WAA2C;AACzE,MAAI,mBAAmB,SAAS,GAAG;AACjC,WAAO;AAAA,EACT;AAEA,SAAO,2BAA2B,SAAS;AAC7C;AAQO,SAAS,mBAAmB,OAAuB,MAAc;AACtE;AAAA,IACE,MAAM,IAAI,MAAM;AAAA,IAChB,4EAA4E,IAAI;AAAA,EAClF;AACF;AASA,SAAS,oBACP,UACA,SACA;AACA,SAAO,QAAQ,MAAM,SAAS,SAAS,QAAQ,MAAM,IAAI,KAAK;AAChE;AAUA,SAAS,wBACP,UACA,WACA,MACA;AACA,QAAM,eAAe,SAAS,IAAI;AAClC,QAAM,gBAAgB,eAAe,UAAU,MAAM,IAAI;AACzD,SAAO,UAAU,MAAM,SAAS,iBAAiB;AACnD;AAQA,SAAS,cAAc,SAAuB;AAC5C,MAAI,MAAM,QAAQ,QAAQ,MAAM,QAAQ,GAAG;AACzC,WAAO,QAAQ,MAAM,SAAS,CAAC;AAAA,EACjC;AAEA,SAAO,QAAQ,MAAM;AACvB;AAWA,SAAS,mBACP,UACA,WACA,MACA,UACW;AACX,MAAI,UAAU,SAAS,UAAU;AAC/B,WAAO;AAAA,EACT;AAEA,QAAM,QAAQ,cAAc,SAAS;AACrC,qBAAmB,UAAU,MAAM,MAAM,IAAI;AAE7C,WAAS,MAAM,MAAM,IAAI,IAAI,wBAAwB,UAAU,OAAO,IAAI;AAE1E,SAAO;AACT;AAUO,SAAS,eACd,UACA,WACA,WAA2B,CAAC,GACZ;AAChB,MAAI,UAAU,SAAS,OAAO;AAC5B,UAAM,WAAW,eAAe,SAAS;AACzC,WAAO,SAAS;AAAA,MACd,CAAC,aAAa,SACZ,eAAe,UAAU,MAAoB,WAAW;AAAA,MAC1D;AAAA,IACF;AAAA,EACF;AAEA,MAAI,UAAU,SAAS,QAAQ;AAC7B,uBAAmB,UAAU,UAAU,MAAM,IAAI;AAEjD,UAAM,WAAW,eAAe,SAAS;AACzC,aAAS,UAAU,MAAM,IAAI,IAAI,SAAS;AAAA,MACxC,CAAC,aAAa,SAAS;AACrB,eAAO;AAAA,UACL;AAAA;AAAA,UAEA;AAAA,UACA,UAAU,MAAM;AAAA,UAChB;AAAA,QACF;AAAA,MACF;AAAA,MACA,CAAC;AAAA,IACH;AAEA,WAAO;AAAA,EACT;AAEA,MAAI,UAAU,SAAS,WAAW,UAAU,SAAS,YAAY;AAC/D,uBAAmB,UAAU,UAAU,MAAM,IAAI;AACjD,aAAS,UAAU,MAAM,IAAI,IAAI,oBAAoB,UAAU,SAAS;AAAA,EAC1E;AAEA,SAAO;AACT;AAEA,IAAM,mBAAmB;AAQlB,SAAS,yBAAyB,SAA4B;AACnE,MAAI,CAAC,SAAS;AACZ;AAAA,EACF;AAIA,QAAM,OAAO,kBAAkB,OAAO;AACtC;AAAA,IACE,QAAQ;AAAA,IACR,mDACE,mBAAmB,GACrB;AAAA,EACF;AACF","sourcesContent":["import { assert } from '@metamask/snaps-sdk';\nimport type {\n FormState,\n InterfaceState,\n ComponentOrElement,\n InterfaceContext,\n} from '@metamask/snaps-sdk';\nimport type {\n ButtonElement,\n DropdownElement,\n FieldElement,\n InputElement,\n JSXElement,\n} from '@metamask/snaps-sdk/jsx';\nimport { isJSXElementUnsafe } from '@metamask/snaps-sdk/jsx';\nimport {\n getJsonSizeUnsafe,\n getJsxChildren,\n getJsxElementFromComponent,\n} from '@metamask/snaps-utils';\n\n/**\n * Get a JSX element from a component or JSX element. If the component is a\n * JSX element, it is returned as is. Otherwise, the component is converted to\n * a JSX element.\n *\n * @param component - The component to convert.\n * @returns The JSX element.\n */\nexport function getJsxInterface(component: ComponentOrElement): JSXElement {\n if (isJSXElementUnsafe(component)) {\n return component;\n }\n\n return getJsxElementFromComponent(component);\n}\n\n/**\n * Assert that the component name is unique in state.\n *\n * @param state - The interface state to verify against.\n * @param name - The component name to verify.\n */\nexport function assertNameIsUnique(state: InterfaceState, name: string) {\n assert(\n state[name] === undefined,\n `Duplicate component names are not allowed, found multiple instances of: \"${name}\".`,\n );\n}\n\n/**\n * Construct the state for an input field.\n *\n * @param oldState - The previous state.\n * @param element - The input element.\n * @returns The input state.\n */\nfunction constructInputState(\n oldState: InterfaceState,\n element: InputElement | DropdownElement,\n) {\n return element.props.value ?? oldState[element.props.name] ?? null;\n}\n\n/**\n * Construct the state for a form input.\n *\n * @param oldState - The previous state.\n * @param component - The input element.\n * @param form - The parent form name of the input.\n * @returns The input state.\n */\nfunction constructFormInputState(\n oldState: InterfaceState,\n component: InputElement | DropdownElement,\n form: string,\n) {\n const oldFormState = oldState[form] as FormState;\n const oldInputState = oldFormState?.[component.props.name];\n return component.props.value ?? oldInputState ?? null;\n}\n\n/**\n * Get the input field from a field element.\n *\n * @param element - The field element.\n * @returns The input element.\n */\nfunction getFieldInput(element: FieldElement) {\n if (Array.isArray(element.props.children)) {\n return element.props.children[0];\n }\n\n return element.props.children;\n}\n\n/**\n * Construct the state for a form input.\n *\n * @param oldState - The previous state.\n * @param component - The field element.\n * @param form - The parent form name of the input.\n * @param newState - The new state.\n * @returns The input state.\n */\nfunction constructFormState(\n oldState: InterfaceState,\n component: FieldElement | ButtonElement,\n form: string,\n newState: FormState,\n): FormState {\n if (component.type === 'Button') {\n return newState;\n }\n\n const input = getFieldInput(component);\n assertNameIsUnique(newState, input.props.name);\n\n newState[input.props.name] = constructFormInputState(oldState, input, form);\n\n return newState;\n}\n\n/**\n * Construct the interface state for a given component tree.\n *\n * @param oldState - The previous state.\n * @param component - The UI component to construct state from.\n * @param newState - The state that is being constructed.\n * @returns The interface state of the passed component.\n */\nexport function constructState(\n oldState: InterfaceState,\n component: JSXElement,\n newState: InterfaceState = {},\n): InterfaceState {\n if (component.type === 'Box') {\n const children = getJsxChildren(component);\n return children.reduce(\n (accumulator, node) =>\n constructState(oldState, node as JSXElement, accumulator),\n newState,\n );\n }\n\n if (component.type === 'Form') {\n assertNameIsUnique(newState, component.props.name);\n\n const children = getJsxChildren(component);\n newState[component.props.name] = children.reduce<FormState>(\n (accumulator, node) => {\n return constructFormState(\n oldState,\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n node as FieldElement | ButtonElement,\n component.props.name,\n accumulator,\n );\n },\n {},\n );\n\n return newState;\n }\n\n if (component.type === 'Input' || component.type === 'Dropdown') {\n assertNameIsUnique(newState, component.props.name);\n newState[component.props.name] = constructInputState(oldState, component);\n }\n\n return newState;\n}\n\nconst MAX_CONTEXT_SIZE = 1_000_000; // 1 mb\n\n/**\n * Validate a JSON blob to be used as the interface context.\n *\n * @param context - The JSON blob.\n * @throws If the JSON blob is too large.\n */\nexport function validateInterfaceContext(context?: InterfaceContext) {\n if (!context) {\n return;\n }\n\n // We assume the validity of this JSON to be validated by the caller.\n // E.g., in the RPC method implementation.\n const size = getJsonSizeUnsafe(context);\n assert(\n size <= MAX_CONTEXT_SIZE,\n `A Snap interface context may not be larger than ${\n MAX_CONTEXT_SIZE / 1000000\n } MB.`,\n );\n}\n"]}
|
package/dist/chunk-HK4OAMJT.js
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
-
|
|
3
|
-
var _chunkKH72WRHRjs = require('./chunk-KH72WRHR.js');
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var _chunkEXN2TFDJjs = require('./chunk-EXN2TFDJ.js');
|
|
8
|
-
|
|
9
|
-
// src/services/offscreen/OffscreenExecutionService.ts
|
|
10
|
-
var _postmessagestream = require('@metamask/post-message-stream');
|
|
11
|
-
var _createDocument, createDocument_fn;
|
|
12
|
-
var OffscreenExecutionService = class extends _chunkKH72WRHRjs.ProxyExecutionService {
|
|
13
|
-
/**
|
|
14
|
-
* Create a new offscreen execution service.
|
|
15
|
-
*
|
|
16
|
-
* @param args - The constructor arguments.
|
|
17
|
-
* @param args.documentUrl - The URL of the offscreen document to use as the
|
|
18
|
-
* execution environment. This must be a URL relative to the location where
|
|
19
|
-
* this is called. This cannot be a public (http(s)) URL.
|
|
20
|
-
* @param args.messenger - The messenger to use for communication with the
|
|
21
|
-
* `SnapController`.
|
|
22
|
-
* @param args.setupSnapProvider - The function to use to set up the snap
|
|
23
|
-
* provider.
|
|
24
|
-
*/
|
|
25
|
-
constructor({
|
|
26
|
-
documentUrl,
|
|
27
|
-
messenger,
|
|
28
|
-
setupSnapProvider
|
|
29
|
-
}) {
|
|
30
|
-
super({
|
|
31
|
-
messenger,
|
|
32
|
-
setupSnapProvider,
|
|
33
|
-
stream: new (0, _postmessagestream.BrowserRuntimePostMessageStream)({
|
|
34
|
-
name: "parent",
|
|
35
|
-
target: "child"
|
|
36
|
-
})
|
|
37
|
-
});
|
|
38
|
-
/**
|
|
39
|
-
* Creates the offscreen document to be used as the execution environment.
|
|
40
|
-
*
|
|
41
|
-
* If the document already exists, this does nothing.
|
|
42
|
-
*/
|
|
43
|
-
_chunkEXN2TFDJjs.__privateAdd.call(void 0, this, _createDocument);
|
|
44
|
-
this.documentUrl = documentUrl;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Create a new stream for the specified job. This wraps the runtime stream
|
|
48
|
-
* in a stream specific to the job.
|
|
49
|
-
*
|
|
50
|
-
* @param jobId - The job ID.
|
|
51
|
-
*/
|
|
52
|
-
async initEnvStream(jobId) {
|
|
53
|
-
await _chunkEXN2TFDJjs.__privateMethod.call(void 0, this, _createDocument, createDocument_fn).call(this);
|
|
54
|
-
return super.initEnvStream(jobId);
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
_createDocument = new WeakSet();
|
|
58
|
-
createDocument_fn = async function() {
|
|
59
|
-
if (await chrome.offscreen.hasDocument()) {
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
await chrome.offscreen.createDocument({
|
|
63
|
-
justification: "MetaMask Snaps Execution Environment",
|
|
64
|
-
reasons: ["IFRAME_SCRIPTING"],
|
|
65
|
-
url: this.documentUrl.toString()
|
|
66
|
-
});
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
exports.OffscreenExecutionService = OffscreenExecutionService;
|
|
72
|
-
//# sourceMappingURL=chunk-HK4OAMJT.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/services/offscreen/OffscreenExecutionService.ts"],"names":[],"mappings":";;;;;;;;;AAAA,SAAS,uCAAuC;AAAhD;AASO,IAAM,4BAAN,cAAwC,sBAAsB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAenE,YAAY;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,EACF,GAA6C;AAC3C,UAAM;AAAA,MACJ;AAAA,MACA;AAAA,MACA,QAAQ,IAAI,gCAAgC;AAAA,QAC1C,MAAM;AAAA,QACN,QAAQ;AAAA,MACV,CAAC;AAAA,IACH,CAAC;AAuBH;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAM;AArBJ,SAAK,cAAc;AAAA,EACrB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAgB,cAAc,OAAe;AAE3C,UAAM,sBAAK,oCAAL;AAEN,WAAO,MAAM,cAAc,KAAK;AAAA,EAClC;AAmBF;AAZQ;AAAA,oBAAe,iBAAG;AAEtB,MAAI,MAAM,OAAO,UAAU,YAAY,GAAG;AACxC;AAAA,EACF;AAEA,QAAM,OAAO,UAAU,eAAe;AAAA,IACpC,eAAe;AAAA,IACf,SAAS,CAAC,kBAA6C;AAAA,IACvD,KAAK,KAAK,YAAY,SAAS;AAAA,EACjC,CAAC;AACH","sourcesContent":["import { BrowserRuntimePostMessageStream } from '@metamask/post-message-stream';\n\nimport type { ExecutionServiceArgs } from '../AbstractExecutionService';\nimport { ProxyExecutionService } from '../proxy/ProxyExecutionService';\n\ntype OffscreenExecutionEnvironmentServiceArgs = {\n documentUrl: URL;\n} & ExecutionServiceArgs;\n\nexport class OffscreenExecutionService extends ProxyExecutionService {\n public readonly documentUrl: URL;\n\n /**\n * Create a new offscreen execution service.\n *\n * @param args - The constructor arguments.\n * @param args.documentUrl - The URL of the offscreen document to use as the\n * execution environment. This must be a URL relative to the location where\n * this is called. This cannot be a public (http(s)) URL.\n * @param args.messenger - The messenger to use for communication with the\n * `SnapController`.\n * @param args.setupSnapProvider - The function to use to set up the snap\n * provider.\n */\n constructor({\n documentUrl,\n messenger,\n setupSnapProvider,\n }: OffscreenExecutionEnvironmentServiceArgs) {\n super({\n messenger,\n setupSnapProvider,\n stream: new BrowserRuntimePostMessageStream({\n name: 'parent',\n target: 'child',\n }),\n });\n\n this.documentUrl = documentUrl;\n }\n\n /**\n * Create a new stream for the specified job. This wraps the runtime stream\n * in a stream specific to the job.\n *\n * @param jobId - The job ID.\n */\n protected async initEnvStream(jobId: string) {\n // Lazily create the offscreen document.\n await this.#createDocument();\n\n return super.initEnvStream(jobId);\n }\n\n /**\n * Creates the offscreen document to be used as the execution environment.\n *\n * If the document already exists, this does nothing.\n */\n async #createDocument() {\n // Extensions can only have a single offscreen document.\n if (await chrome.offscreen.hasDocument()) {\n return;\n }\n\n await chrome.offscreen.createDocument({\n justification: 'MetaMask Snaps Execution Environment',\n reasons: ['IFRAME_SCRIPTING' as chrome.offscreen.Reason],\n url: this.documentUrl.toString(),\n });\n }\n}\n"]}
|