@metamask/snaps-execution-environments 0.24.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +3 -0
  3. package/dist/common/BaseSnapExecutor.d.ts +68 -0
  4. package/dist/common/BaseSnapExecutor.js +324 -0
  5. package/dist/common/BaseSnapExecutor.js.map +1 -0
  6. package/dist/common/commands.d.ts +30 -0
  7. package/dist/common/commands.js +68 -0
  8. package/dist/common/commands.js.map +1 -0
  9. package/dist/common/endowments/crypto.d.ts +8 -0
  10. package/dist/common/endowments/crypto.js +25 -0
  11. package/dist/common/endowments/crypto.js.map +1 -0
  12. package/dist/common/endowments/index.d.ts +25 -0
  13. package/dist/common/endowments/index.js +122 -0
  14. package/dist/common/endowments/index.js.map +1 -0
  15. package/dist/common/endowments/interval.d.ts +9 -0
  16. package/dist/common/endowments/interval.js +47 -0
  17. package/dist/common/endowments/interval.js.map +1 -0
  18. package/dist/common/endowments/math.d.ts +60 -0
  19. package/dist/common/endowments/math.js +48 -0
  20. package/dist/common/endowments/math.js.map +1 -0
  21. package/dist/common/endowments/network.d.ts +48 -0
  22. package/dist/common/endowments/network.js +362 -0
  23. package/dist/common/endowments/network.js.map +1 -0
  24. package/dist/common/endowments/timeout.d.ts +9 -0
  25. package/dist/common/endowments/timeout.js +50 -0
  26. package/dist/common/endowments/timeout.js.map +1 -0
  27. package/dist/common/globalEvents.d.ts +19 -0
  28. package/dist/common/globalEvents.js +47 -0
  29. package/dist/common/globalEvents.js.map +1 -0
  30. package/dist/common/globalObject.d.ts +9 -0
  31. package/dist/common/globalObject.js +48 -0
  32. package/dist/common/globalObject.js.map +1 -0
  33. package/dist/common/keyring.d.ts +12 -0
  34. package/dist/common/keyring.js +42 -0
  35. package/dist/common/keyring.js.map +1 -0
  36. package/dist/common/lockdown/lockdown-more.d.ts +22 -0
  37. package/dist/common/lockdown/lockdown-more.js +88 -0
  38. package/dist/common/lockdown/lockdown-more.js.map +1 -0
  39. package/dist/common/lockdown/lockdown.d.ts +7 -0
  40. package/dist/common/lockdown/lockdown.js +28 -0
  41. package/dist/common/lockdown/lockdown.js.map +1 -0
  42. package/dist/common/sortParams.d.ts +16 -0
  43. package/dist/common/sortParams.js +32 -0
  44. package/dist/common/sortParams.js.map +1 -0
  45. package/dist/common/utils.d.ts +38 -0
  46. package/dist/common/utils.js +98 -0
  47. package/dist/common/utils.js.map +1 -0
  48. package/dist/common/validation.d.ts +100 -0
  49. package/dist/common/validation.js +110 -0
  50. package/dist/common/validation.js.map +1 -0
  51. package/dist/iframe/IFrameSnapExecutor.d.ts +11 -0
  52. package/dist/iframe/IFrameSnapExecutor.js +41 -0
  53. package/dist/iframe/IFrameSnapExecutor.js.map +1 -0
  54. package/dist/iframe/index.d.ts +1 -0
  55. package/dist/iframe/index.js +9 -0
  56. package/dist/iframe/index.js.map +1 -0
  57. package/dist/iframe-test/index.d.ts +1 -0
  58. package/dist/iframe-test/index.js +8 -0
  59. package/dist/iframe-test/index.js.map +1 -0
  60. package/dist/node-process/ChildProcessSnapExecutor.d.ts +4 -0
  61. package/dist/node-process/ChildProcessSnapExecutor.js +29 -0
  62. package/dist/node-process/ChildProcessSnapExecutor.js.map +1 -0
  63. package/dist/node-process/index.d.ts +1 -0
  64. package/dist/node-process/index.js +9 -0
  65. package/dist/node-process/index.js.map +1 -0
  66. package/dist/node-thread/ThreadSnapExecutor.d.ts +4 -0
  67. package/dist/node-thread/ThreadSnapExecutor.js +29 -0
  68. package/dist/node-thread/ThreadSnapExecutor.js.map +1 -0
  69. package/dist/node-thread/index.d.ts +1 -0
  70. package/dist/node-thread/index.js +9 -0
  71. package/dist/node-thread/index.js.map +1 -0
  72. package/dist/openrpc.json +210 -0
  73. package/dist/webpack/iframe/bundle.js +2 -0
  74. package/dist/webpack/iframe/bundle.js.LICENSE.txt +21 -0
  75. package/dist/webpack/iframe/index.html +10 -0
  76. package/dist/webpack/iframe/lockdown.umd.min.js +1 -0
  77. package/dist/webpack/node-process/bundle.js +1784 -0
  78. package/dist/webpack/node-process/bundle.js.LICENSE.txt +3 -0
  79. package/dist/webpack/node-process/lockdown.umd.min.js +1 -0
  80. package/dist/webpack/node-thread/bundle.js +1784 -0
  81. package/dist/webpack/node-thread/bundle.js.LICENSE.txt +3 -0
  82. package/dist/webpack/node-thread/lockdown.umd.min.js +1 -0
  83. package/package.json +88 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validation.js","sourceRoot":"","sources":["../../src/common/validation.ts"],"names":[],"mappings":"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","sourcesContent":["import { ChainIdStruct, HandlerType } from '@metamask/snaps-utils';\nimport { SnapKeyring } from '@metamask/snaps-types';\nimport {\n assertStruct,\n Json,\n JsonRpcIdStruct,\n JsonRpcRequestStruct,\n JsonRpcSuccess,\n JsonRpcSuccessStruct,\n JsonStruct,\n} from '@metamask/utils';\nimport {\n array,\n assign,\n enums,\n Infer,\n is,\n literal,\n nullable,\n object,\n omit,\n optional,\n record,\n string,\n tuple,\n union,\n} from 'superstruct';\n\nconst VALIDATION_FUNCTIONS = {\n [HandlerType.OnRpcRequest]: validateFunctionExport,\n [HandlerType.OnTransaction]: validateFunctionExport,\n [HandlerType.SnapKeyring]: validateKeyringExport,\n [HandlerType.OnCronjob]: validateFunctionExport,\n};\n\n/**\n * Validates a function export.\n *\n * @param snapExport - The export itself.\n * @returns True if the export matches the expected shape, false otherwise.\n */\nfunction validateFunctionExport(\n snapExport: unknown,\n): snapExport is (...args: unknown[]) => unknown {\n return typeof snapExport === 'function';\n}\n\n/**\n * Validates a keyring export.\n *\n * @param snapExport - The export itself.\n * @returns True if the export matches the expected shape, false otherwise.\n */\nfunction validateKeyringExport(snapExport: unknown): snapExport is SnapKeyring {\n // TODO Decide whether we want more validation\n return typeof snapExport === 'object';\n}\n\n/**\n * Validates a given snap export.\n *\n * @param type - The type of export expected.\n * @param snapExport - The export itself.\n * @returns True if the export matches the expected shape, false otherwise.\n */\nexport function validateExport(type: HandlerType, snapExport: unknown) {\n const validationFunction = VALIDATION_FUNCTIONS[type];\n return validationFunction?.(snapExport) ?? false;\n}\n\nexport const JsonRpcRequestWithoutIdStruct = assign(\n omit(JsonRpcRequestStruct, ['id']),\n object({\n id: optional(JsonRpcIdStruct),\n }),\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 optional(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 );\n}\n\nconst OkResponseStruct = assign(\n JsonRpcSuccessStruct,\n object({\n result: OkStruct,\n }),\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"]}
@@ -0,0 +1,11 @@
1
+ import { BaseSnapExecutor } from '../common/BaseSnapExecutor';
2
+ export declare class IFrameSnapExecutor extends BaseSnapExecutor {
3
+ /**
4
+ * Initialize the IFrameSnapExecutor. This creates a post message stream from
5
+ * and to the parent window, for two-way communication with the iframe.
6
+ *
7
+ * @returns An instance of `IFrameSnapExecutor`, with the initialized post
8
+ * message streams.
9
+ */
10
+ static initialize(): IFrameSnapExecutor;
11
+ }
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.IFrameSnapExecutor = void 0;
7
+ const object_multiplex_1 = __importDefault(require("@metamask/object-multiplex"));
8
+ const post_message_stream_1 = require("@metamask/post-message-stream");
9
+ const pump_1 = __importDefault(require("pump"));
10
+ const snaps_utils_1 = require("@metamask/snaps-utils");
11
+ const BaseSnapExecutor_1 = require("../common/BaseSnapExecutor");
12
+ class IFrameSnapExecutor extends BaseSnapExecutor_1.BaseSnapExecutor {
13
+ /**
14
+ * Initialize the IFrameSnapExecutor. This creates a post message stream from
15
+ * and to the parent window, for two-way communication with the iframe.
16
+ *
17
+ * @returns An instance of `IFrameSnapExecutor`, with the initialized post
18
+ * message streams.
19
+ */
20
+ static initialize() {
21
+ console.log('Worker: Connecting to parent.');
22
+ const parentStream = new post_message_stream_1.WindowPostMessageStream({
23
+ name: 'child',
24
+ target: 'parent',
25
+ targetWindow: self.parent,
26
+ targetOrigin: '*',
27
+ });
28
+ const mux = new object_multiplex_1.default();
29
+ (0, pump_1.default)(parentStream, mux, parentStream, (err) => {
30
+ if (err) {
31
+ console.error(`Parent stream failure, closing worker.`, err);
32
+ }
33
+ self.close();
34
+ });
35
+ const commandStream = mux.createStream(snaps_utils_1.SNAP_STREAM_NAMES.COMMAND);
36
+ const rpcStream = mux.createStream(snaps_utils_1.SNAP_STREAM_NAMES.JSON_RPC);
37
+ return new IFrameSnapExecutor(commandStream, rpcStream);
38
+ }
39
+ }
40
+ exports.IFrameSnapExecutor = IFrameSnapExecutor;
41
+ //# sourceMappingURL=IFrameSnapExecutor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IFrameSnapExecutor.js","sourceRoot":"","sources":["../../src/iframe/IFrameSnapExecutor.ts"],"names":[],"mappings":";;;;;;AAAA,kFAAyD;AACzD,uEAAwE;AACxE,gDAAwB;AACxB,uDAA0D;AAC1D,iEAA8D;AAE9D,MAAa,kBAAmB,SAAQ,mCAAgB;IACtD;;;;;;OAMG;IACH,MAAM,CAAC,UAAU;QACf,OAAO,CAAC,GAAG,CAAC,+BAA+B,CAAC,CAAC;QAE7C,MAAM,YAAY,GAAG,IAAI,6CAAuB,CAAC;YAC/C,IAAI,EAAE,OAAO;YACb,MAAM,EAAE,QAAQ;YAChB,YAAY,EAAE,IAAI,CAAC,MAAM;YACzB,YAAY,EAAE,GAAG;SAClB,CAAC,CAAC;QAEH,MAAM,GAAG,GAAG,IAAI,0BAAe,EAAE,CAAC;QAClC,IAAA,cAAI,EAAC,YAAY,EAAE,GAAG,EAAE,YAAY,EAAE,CAAC,GAAG,EAAE,EAAE;YAC5C,IAAI,GAAG,EAAE;gBACP,OAAO,CAAC,KAAK,CAAC,wCAAwC,EAAE,GAAG,CAAC,CAAC;aAC9D;YACD,IAAI,CAAC,KAAK,EAAE,CAAC;QACf,CAAC,CAAC,CAAC;QAEH,MAAM,aAAa,GAAG,GAAG,CAAC,YAAY,CAAC,+BAAiB,CAAC,OAAO,CAAC,CAAC;QAClE,MAAM,SAAS,GAAG,GAAG,CAAC,YAAY,CAAC,+BAAiB,CAAC,QAAQ,CAAC,CAAC;QAE/D,OAAO,IAAI,kBAAkB,CAAC,aAAa,EAAE,SAAS,CAAC,CAAC;IAC1D,CAAC;CACF;AA/BD,gDA+BC","sourcesContent":["import ObjectMultiplex from '@metamask/object-multiplex';\nimport { WindowPostMessageStream } from '@metamask/post-message-stream';\nimport pump from 'pump';\nimport { SNAP_STREAM_NAMES } from '@metamask/snaps-utils';\nimport { BaseSnapExecutor } from '../common/BaseSnapExecutor';\n\nexport class IFrameSnapExecutor extends BaseSnapExecutor {\n /**\n * Initialize the IFrameSnapExecutor. This creates a post message stream from\n * and to the parent window, for two-way communication with the iframe.\n *\n * @returns An instance of `IFrameSnapExecutor`, with the initialized post\n * message streams.\n */\n static initialize() {\n console.log('Worker: Connecting to parent.');\n\n const parentStream = new WindowPostMessageStream({\n name: 'child',\n target: 'parent',\n targetWindow: self.parent,\n targetOrigin: '*',\n });\n\n const mux = new ObjectMultiplex();\n pump(parentStream, mux, parentStream, (err) => {\n if (err) {\n console.error(`Parent stream failure, closing worker.`, err);\n }\n self.close();\n });\n\n const commandStream = mux.createStream(SNAP_STREAM_NAMES.COMMAND);\n const rpcStream = mux.createStream(SNAP_STREAM_NAMES.JSON_RPC);\n\n return new IFrameSnapExecutor(commandStream, rpcStream);\n }\n}\n"]}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const lockdown_1 = require("../common/lockdown/lockdown");
4
+ const lockdown_more_1 = require("../common/lockdown/lockdown-more");
5
+ const IFrameSnapExecutor_1 = require("./IFrameSnapExecutor");
6
+ (0, lockdown_1.executeLockdown)();
7
+ (0, lockdown_more_1.executeLockdownMore)();
8
+ IFrameSnapExecutor_1.IFrameSnapExecutor.initialize();
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/iframe/index.ts"],"names":[],"mappings":";;AAAA,0DAA8D;AAC9D,oEAAuE;AACvE,6DAA0D;AAE1D,IAAA,0BAAe,GAAE,CAAC;AAClB,IAAA,mCAAmB,GAAE,CAAC;AAEtB,uCAAkB,CAAC,UAAU,EAAE,CAAC","sourcesContent":["import { executeLockdown } from '../common/lockdown/lockdown';\nimport { executeLockdownMore } from '../common/lockdown/lockdown-more';\nimport { IFrameSnapExecutor } from './IFrameSnapExecutor';\n\nexecuteLockdown();\nexecuteLockdownMore();\n\nIFrameSnapExecutor.initialize();\n"]}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const lockdown_1 = require("../common/lockdown/lockdown");
4
+ const IFrameSnapExecutor_1 = require("../iframe/IFrameSnapExecutor");
5
+ // The testing iframe is run without lockdown-more due to JSDOM incompatibilities
6
+ (0, lockdown_1.executeLockdown)();
7
+ IFrameSnapExecutor_1.IFrameSnapExecutor.initialize();
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/iframe-test/index.ts"],"names":[],"mappings":";;AAAA,0DAA8D;AAC9D,qEAAkE;AAElE,iFAAiF;AACjF,IAAA,0BAAe,GAAE,CAAC;AAElB,uCAAkB,CAAC,UAAU,EAAE,CAAC","sourcesContent":["import { executeLockdown } from '../common/lockdown/lockdown';\nimport { IFrameSnapExecutor } from '../iframe/IFrameSnapExecutor';\n\n// The testing iframe is run without lockdown-more due to JSDOM incompatibilities\nexecuteLockdown();\n\nIFrameSnapExecutor.initialize();\n"]}
@@ -0,0 +1,4 @@
1
+ import { BaseSnapExecutor } from '../common/BaseSnapExecutor';
2
+ export declare class ChildProcessSnapExecutor extends BaseSnapExecutor {
3
+ static initialize(): ChildProcessSnapExecutor;
4
+ }
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.ChildProcessSnapExecutor = void 0;
7
+ const object_multiplex_1 = __importDefault(require("@metamask/object-multiplex"));
8
+ const pump_1 = __importDefault(require("pump"));
9
+ const post_message_stream_1 = require("@metamask/post-message-stream");
10
+ const snaps_utils_1 = require("@metamask/snaps-utils");
11
+ const BaseSnapExecutor_1 = require("../common/BaseSnapExecutor");
12
+ class ChildProcessSnapExecutor extends BaseSnapExecutor_1.BaseSnapExecutor {
13
+ static initialize() {
14
+ console.log('Worker: Connecting to parent.');
15
+ const parentStream = new post_message_stream_1.ProcessMessageStream();
16
+ const mux = new object_multiplex_1.default();
17
+ (0, pump_1.default)(parentStream, mux, parentStream, (err) => {
18
+ if (err) {
19
+ console.error(`Parent stream failure, closing worker.`, err);
20
+ }
21
+ self.close();
22
+ });
23
+ const commandStream = mux.createStream(snaps_utils_1.SNAP_STREAM_NAMES.COMMAND);
24
+ const rpcStream = mux.createStream(snaps_utils_1.SNAP_STREAM_NAMES.JSON_RPC);
25
+ return new ChildProcessSnapExecutor(commandStream, rpcStream);
26
+ }
27
+ }
28
+ exports.ChildProcessSnapExecutor = ChildProcessSnapExecutor;
29
+ //# sourceMappingURL=ChildProcessSnapExecutor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ChildProcessSnapExecutor.js","sourceRoot":"","sources":["../../src/node-process/ChildProcessSnapExecutor.ts"],"names":[],"mappings":";;;;;;AAAA,kFAAyD;AACzD,gDAAwB;AACxB,uEAAqE;AACrE,uDAA0D;AAC1D,iEAA8D;AAE9D,MAAa,wBAAyB,SAAQ,mCAAgB;IAC5D,MAAM,CAAC,UAAU;QACf,OAAO,CAAC,GAAG,CAAC,+BAA+B,CAAC,CAAC;QAE7C,MAAM,YAAY,GAAG,IAAI,0CAAoB,EAAE,CAAC;QAChD,MAAM,GAAG,GAAG,IAAI,0BAAe,EAAE,CAAC;QAClC,IAAA,cAAI,EAAC,YAAY,EAAE,GAAU,EAAE,YAAY,EAAE,CAAC,GAAG,EAAE,EAAE;YACnD,IAAI,GAAG,EAAE;gBACP,OAAO,CAAC,KAAK,CAAC,wCAAwC,EAAE,GAAG,CAAC,CAAC;aAC9D;YACD,IAAI,CAAC,KAAK,EAAE,CAAC;QACf,CAAC,CAAC,CAAC;QAEH,MAAM,aAAa,GAAG,GAAG,CAAC,YAAY,CAAC,+BAAiB,CAAC,OAAO,CAAC,CAAC;QAClE,MAAM,SAAS,GAAG,GAAG,CAAC,YAAY,CAAC,+BAAiB,CAAC,QAAQ,CAAQ,CAAC;QACtE,OAAO,IAAI,wBAAwB,CAAC,aAAa,EAAE,SAAS,CAAC,CAAC;IAChE,CAAC;CACF;AAjBD,4DAiBC","sourcesContent":["import ObjectMultiplex from '@metamask/object-multiplex';\nimport pump from 'pump';\nimport { ProcessMessageStream } from '@metamask/post-message-stream';\nimport { SNAP_STREAM_NAMES } from '@metamask/snaps-utils';\nimport { BaseSnapExecutor } from '../common/BaseSnapExecutor';\n\nexport class ChildProcessSnapExecutor extends BaseSnapExecutor {\n static initialize() {\n console.log('Worker: Connecting to parent.');\n\n const parentStream = new ProcessMessageStream();\n const mux = new ObjectMultiplex();\n pump(parentStream, mux as any, parentStream, (err) => {\n if (err) {\n console.error(`Parent stream failure, closing worker.`, err);\n }\n self.close();\n });\n\n const commandStream = mux.createStream(SNAP_STREAM_NAMES.COMMAND);\n const rpcStream = mux.createStream(SNAP_STREAM_NAMES.JSON_RPC) as any;\n return new ChildProcessSnapExecutor(commandStream, rpcStream);\n }\n}\n"]}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const lockdown_1 = require("../common/lockdown/lockdown");
4
+ const lockdown_more_1 = require("../common/lockdown/lockdown-more");
5
+ const ChildProcessSnapExecutor_1 = require("./ChildProcessSnapExecutor");
6
+ (0, lockdown_1.executeLockdown)();
7
+ (0, lockdown_more_1.executeLockdownMore)();
8
+ ChildProcessSnapExecutor_1.ChildProcessSnapExecutor.initialize();
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/node-process/index.ts"],"names":[],"mappings":";;AAAA,0DAA8D;AAC9D,oEAAuE;AACvE,yEAAsE;AAEtE,IAAA,0BAAe,GAAE,CAAC;AAClB,IAAA,mCAAmB,GAAE,CAAC;AAEtB,mDAAwB,CAAC,UAAU,EAAE,CAAC","sourcesContent":["import { executeLockdown } from '../common/lockdown/lockdown';\nimport { executeLockdownMore } from '../common/lockdown/lockdown-more';\nimport { ChildProcessSnapExecutor } from './ChildProcessSnapExecutor';\n\nexecuteLockdown();\nexecuteLockdownMore();\n\nChildProcessSnapExecutor.initialize();\n"]}
@@ -0,0 +1,4 @@
1
+ import { BaseSnapExecutor } from '../common/BaseSnapExecutor';
2
+ export declare class ThreadSnapExecutor extends BaseSnapExecutor {
3
+ static initialize(): ThreadSnapExecutor;
4
+ }
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.ThreadSnapExecutor = void 0;
7
+ const object_multiplex_1 = __importDefault(require("@metamask/object-multiplex"));
8
+ const pump_1 = __importDefault(require("pump"));
9
+ const post_message_stream_1 = require("@metamask/post-message-stream");
10
+ const snaps_utils_1 = require("@metamask/snaps-utils");
11
+ const BaseSnapExecutor_1 = require("../common/BaseSnapExecutor");
12
+ class ThreadSnapExecutor extends BaseSnapExecutor_1.BaseSnapExecutor {
13
+ static initialize() {
14
+ console.log('Worker: Connecting to parent.');
15
+ const parentStream = new post_message_stream_1.ThreadMessageStream();
16
+ const mux = new object_multiplex_1.default();
17
+ (0, pump_1.default)(parentStream, mux, parentStream, (err) => {
18
+ if (err) {
19
+ console.error(`Parent stream failure, closing worker.`, err);
20
+ }
21
+ self.close();
22
+ });
23
+ const commandStream = mux.createStream(snaps_utils_1.SNAP_STREAM_NAMES.COMMAND);
24
+ const rpcStream = mux.createStream(snaps_utils_1.SNAP_STREAM_NAMES.JSON_RPC);
25
+ return new ThreadSnapExecutor(commandStream, rpcStream);
26
+ }
27
+ }
28
+ exports.ThreadSnapExecutor = ThreadSnapExecutor;
29
+ //# sourceMappingURL=ThreadSnapExecutor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ThreadSnapExecutor.js","sourceRoot":"","sources":["../../src/node-thread/ThreadSnapExecutor.ts"],"names":[],"mappings":";;;;;;AAAA,kFAAyD;AACzD,gDAAwB;AACxB,uEAAoE;AACpE,uDAA0D;AAC1D,iEAA8D;AAE9D,MAAa,kBAAmB,SAAQ,mCAAgB;IACtD,MAAM,CAAC,UAAU;QACf,OAAO,CAAC,GAAG,CAAC,+BAA+B,CAAC,CAAC;QAE7C,MAAM,YAAY,GAAG,IAAI,yCAAmB,EAAE,CAAC;QAC/C,MAAM,GAAG,GAAG,IAAI,0BAAe,EAAE,CAAC;QAClC,IAAA,cAAI,EAAC,YAAY,EAAE,GAAU,EAAE,YAAY,EAAE,CAAC,GAAG,EAAE,EAAE;YACnD,IAAI,GAAG,EAAE;gBACP,OAAO,CAAC,KAAK,CAAC,wCAAwC,EAAE,GAAG,CAAC,CAAC;aAC9D;YACD,IAAI,CAAC,KAAK,EAAE,CAAC;QACf,CAAC,CAAC,CAAC;QAEH,MAAM,aAAa,GAAG,GAAG,CAAC,YAAY,CAAC,+BAAiB,CAAC,OAAO,CAAC,CAAC;QAClE,MAAM,SAAS,GAAG,GAAG,CAAC,YAAY,CAAC,+BAAiB,CAAC,QAAQ,CAAQ,CAAC;QACtE,OAAO,IAAI,kBAAkB,CAAC,aAAa,EAAE,SAAS,CAAC,CAAC;IAC1D,CAAC;CACF;AAjBD,gDAiBC","sourcesContent":["import ObjectMultiplex from '@metamask/object-multiplex';\nimport pump from 'pump';\nimport { ThreadMessageStream } from '@metamask/post-message-stream';\nimport { SNAP_STREAM_NAMES } from '@metamask/snaps-utils';\nimport { BaseSnapExecutor } from '../common/BaseSnapExecutor';\n\nexport class ThreadSnapExecutor extends BaseSnapExecutor {\n static initialize() {\n console.log('Worker: Connecting to parent.');\n\n const parentStream = new ThreadMessageStream();\n const mux = new ObjectMultiplex();\n pump(parentStream, mux as any, parentStream, (err) => {\n if (err) {\n console.error(`Parent stream failure, closing worker.`, err);\n }\n self.close();\n });\n\n const commandStream = mux.createStream(SNAP_STREAM_NAMES.COMMAND);\n const rpcStream = mux.createStream(SNAP_STREAM_NAMES.JSON_RPC) as any;\n return new ThreadSnapExecutor(commandStream, rpcStream);\n }\n}\n"]}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const lockdown_1 = require("../common/lockdown/lockdown");
4
+ const lockdown_more_1 = require("../common/lockdown/lockdown-more");
5
+ const ThreadSnapExecutor_1 = require("./ThreadSnapExecutor");
6
+ (0, lockdown_1.executeLockdown)();
7
+ (0, lockdown_more_1.executeLockdownMore)();
8
+ ThreadSnapExecutor_1.ThreadSnapExecutor.initialize();
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/node-thread/index.ts"],"names":[],"mappings":";;AAAA,0DAA8D;AAC9D,oEAAuE;AACvE,6DAA0D;AAE1D,IAAA,0BAAe,GAAE,CAAC;AAClB,IAAA,mCAAmB,GAAE,CAAC;AAEtB,uCAAkB,CAAC,UAAU,EAAE,CAAC","sourcesContent":["import { executeLockdown } from '../common/lockdown/lockdown';\nimport { executeLockdownMore } from '../common/lockdown/lockdown-more';\nimport { ThreadSnapExecutor } from './ThreadSnapExecutor';\n\nexecuteLockdown();\nexecuteLockdownMore();\n\nThreadSnapExecutor.initialize();\n"]}
@@ -0,0 +1,210 @@
1
+ {
2
+ "openrpc": "1.2.4",
3
+ "info": {
4
+ "title": "MetaMask Snaps Execution Environment API",
5
+ "version": "0.0.0-development"
6
+ },
7
+ "methods": [
8
+ {
9
+ "name": "ping",
10
+ "description": "confirms that a connection has been established with the execution environment",
11
+ "params": [],
12
+ "result": {
13
+ "name": "PingResult",
14
+ "schema": {
15
+ "$ref": "#/components/schemas/OK"
16
+ }
17
+ }
18
+ },
19
+ {
20
+ "name": "terminate",
21
+ "description": "tells the execution environment that it is being shut down",
22
+ "params": [],
23
+ "result": {
24
+ "name": "TerminateResult",
25
+ "schema": {
26
+ "$ref": "#/components/schemas/OK"
27
+ }
28
+ }
29
+ },
30
+ {
31
+ "name": "executeSnap",
32
+ "description": "executes a snap in the environment. The snap can then be interacted with via `snapRpc`",
33
+ "params": [
34
+ {
35
+ "name": "snapName",
36
+ "required": true,
37
+ "description": "the name of the snap",
38
+ "schema": {
39
+ "title": "SnapName",
40
+ "type": "string"
41
+ }
42
+ },
43
+ {
44
+ "name": "sourceCode",
45
+ "description": "a snaps source code that gets executed in the environment",
46
+ "required": true,
47
+ "schema": {
48
+ "title": "SourceCode",
49
+ "type": "string"
50
+ }
51
+ },
52
+ {
53
+ "name": "endowments",
54
+ "description": "A list of endowments to provide to SES",
55
+ "required": false,
56
+ "schema": {
57
+ "title": "Endowments",
58
+ "description": "An array of the names of the endowments",
59
+ "type": "array",
60
+ "items": {
61
+ "title": "Endowment",
62
+ "type": "string"
63
+ }
64
+ }
65
+ }
66
+ ],
67
+ "result": {
68
+ "name": "executeSnapResult",
69
+ "schema": {
70
+ "$ref": "#/components/schemas/OK"
71
+ }
72
+ },
73
+ "examples": [
74
+ {
75
+ "name": "BasicTestSnapExecuteExample",
76
+ "params": [
77
+ {
78
+ "name": "snapName",
79
+ "value": "TestSnap"
80
+ },
81
+ {
82
+ "name": "sourceCode",
83
+ "value": "module.exports.onRpcRequest = async ({ request }) => { return request.method + request.id }"
84
+ }
85
+ ],
86
+ "result": {
87
+ "name": "BasicTestSnapExampleResult",
88
+ "value": "OK"
89
+ }
90
+ }
91
+ ]
92
+ },
93
+ {
94
+ "name": "snapRpc",
95
+ "params": [
96
+ {
97
+ "name": "target",
98
+ "required": true,
99
+ "description": "the name of the snap",
100
+ "schema": {
101
+ "title": "Target",
102
+ "type": "string"
103
+ }
104
+ },
105
+ {
106
+ "name": "handler",
107
+ "required": true,
108
+ "description": "the handler to trigger on the snap",
109
+ "schema": {
110
+ "title": "Handler",
111
+ "type": "string",
112
+ "enum": ["onRpcRequest", "onTransaction", "keyring"]
113
+ }
114
+ },
115
+ {
116
+ "name": "origin",
117
+ "required": true,
118
+ "description": "Origin of the snap JSON-RPC request",
119
+ "schema": {
120
+ "title": "Origin",
121
+ "type": "string"
122
+ }
123
+ },
124
+ {
125
+ "name": "request",
126
+ "required": true,
127
+ "description": "JSON-RPC request",
128
+ "schema": {
129
+ "$ref": "#/components/schemas/JsonRpcRequest"
130
+ }
131
+ }
132
+ ],
133
+ "result": {
134
+ "name": "HandleSnapRpcResult",
135
+ "schema": {
136
+ "title": "SnapRpcResult"
137
+ }
138
+ },
139
+ "examples": [
140
+ {
141
+ "name": "TestSnapExample",
142
+ "params": [
143
+ {
144
+ "name": "target",
145
+ "value": "TestSnap"
146
+ },
147
+ {
148
+ "name": "origin",
149
+ "value": "foo.com"
150
+ },
151
+ {
152
+ "name": "request",
153
+ "value": {
154
+ "jsonrpc": "2.0",
155
+ "method": "hello",
156
+ "params": [],
157
+ "id": 1
158
+ }
159
+ }
160
+ ],
161
+ "result": {
162
+ "name": "TestSnapResultExample",
163
+ "value": "hello1"
164
+ }
165
+ }
166
+ ]
167
+ }
168
+ ],
169
+ "components": {
170
+ "schemas": {
171
+ "OK": {
172
+ "title": "OK",
173
+ "type": "string",
174
+ "const": "OK"
175
+ },
176
+ "JsonRpcRequest": {
177
+ "title": "JsonRpcRequest",
178
+ "type": "object",
179
+ "required": ["jsonrpc", "method"],
180
+ "properties": {
181
+ "jsonrpc": {
182
+ "title": "JSONRPCString",
183
+ "type": "string",
184
+ "const": "2.0"
185
+ },
186
+ "id": {
187
+ "title": "JSONRPCID",
188
+ "oneOf": [
189
+ {
190
+ "type": "string"
191
+ },
192
+ {
193
+ "type": "number"
194
+ }
195
+ ]
196
+ },
197
+ "method": {
198
+ "title": "JSONRPCMethod",
199
+ "description": "the name of the method",
200
+ "type": "string"
201
+ },
202
+ "params": {
203
+ "title": "JSONRPCParams",
204
+ "type": ["array", "object"]
205
+ }
206
+ }
207
+ }
208
+ }
209
+ }
210
+ }