@metamask/snaps-utils 0.35.1-flask.1 → 1.0.0-prerelease.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.
- package/CHANGELOG.md +5 -46
- package/dist/{esm/array.js → array.js} +7 -3
- package/dist/array.js.map +1 -0
- package/dist/{types/caveats.d.ts → caveats.d.ts} +4 -0
- package/dist/caveats.js +35 -0
- package/dist/caveats.js.map +1 -0
- package/dist/checksum.js +42 -0
- package/dist/checksum.js.map +1 -0
- package/dist/cronjob.js +71 -0
- package/dist/cronjob.js.map +1 -0
- package/dist/deep-clone.js +9 -0
- package/dist/deep-clone.js.map +1 -0
- package/dist/{esm/default-endowments.js → default-endowments.js} +6 -3
- package/dist/default-endowments.js.map +1 -0
- package/dist/entropy.js +8 -0
- package/dist/entropy.js.map +1 -0
- package/dist/{cjs/eval-worker.js → eval-worker.js} +21 -22
- package/dist/eval-worker.js.map +1 -0
- package/dist/eval.js +27 -0
- package/dist/eval.js.map +1 -0
- package/dist/{esm/fs.js → fs.js} +56 -33
- package/dist/fs.js.map +1 -0
- package/dist/{types/handlers.d.ts → handlers.d.ts} +42 -5
- package/dist/handlers.js +3 -0
- package/dist/handlers.js.map +1 -0
- package/dist/{types/iframe.d.ts → iframe.d.ts} +2 -3
- package/dist/{esm/iframe.js → iframe.js} +18 -16
- package/dist/iframe.js.map +1 -0
- package/dist/iframe.test.browser.js +15 -0
- package/dist/iframe.test.browser.js.map +1 -0
- package/dist/{types/index.browser.d.ts → index.browser.d.ts} +1 -2
- package/dist/index.browser.js +37 -0
- package/dist/index.browser.js.map +1 -0
- package/dist/{types/index.d.ts → index.d.ts} +1 -2
- package/dist/index.executionenv.js +22 -0
- package/dist/index.executionenv.js.map +1 -0
- package/dist/index.js +42 -0
- package/dist/index.js.map +1 -0
- package/dist/json-rpc.js +46 -0
- package/dist/json-rpc.js.map +1 -0
- package/dist/json.d.ts +9 -0
- package/dist/json.js +18 -0
- package/dist/json.js.map +1 -0
- package/dist/{esm/logging.js → logging.js} +14 -6
- package/dist/logging.js.map +1 -0
- package/dist/manifest/index.browser.js +18 -0
- package/dist/manifest/index.browser.js.map +1 -0
- package/dist/manifest/index.js +19 -0
- package/dist/manifest/index.js.map +1 -0
- package/dist/{esm/manifest → manifest}/manifest.js +113 -98
- package/dist/manifest/manifest.js.map +1 -0
- package/dist/{types/manifest → manifest}/validation.d.ts +73 -31
- package/dist/manifest/validation.js +141 -0
- package/dist/manifest/validation.js.map +1 -0
- package/dist/{esm/mock.js → mock.js} +40 -42
- package/dist/mock.js.map +1 -0
- package/dist/namespace.d.ts +275 -0
- package/dist/namespace.js +225 -0
- package/dist/namespace.js.map +1 -0
- package/dist/notification.d.ts +66 -0
- package/dist/notification.js +58 -0
- package/dist/notification.js.map +1 -0
- package/dist/{types/npm.d.ts → npm.d.ts} +2 -0
- package/dist/npm.js +74 -0
- package/dist/npm.js.map +1 -0
- package/dist/path.js +21 -0
- package/dist/path.js.map +1 -0
- package/dist/{esm/post-process.js → post-process.js} +99 -110
- package/dist/post-process.js.map +1 -0
- package/dist/{types/snaps.d.ts → snaps.d.ts} +2 -9
- package/dist/snaps.js +202 -0
- package/dist/snaps.js.map +1 -0
- package/dist/{types/types.d.ts → types.d.ts} +5 -2
- package/dist/types.js +103 -0
- package/dist/types.js.map +1 -0
- package/dist/{esm/versions.js → versions.js} +18 -15
- package/dist/versions.js.map +1 -0
- package/dist/{esm/virtual-file → virtual-file}/VirtualFile.js +33 -47
- package/dist/virtual-file/VirtualFile.js.map +1 -0
- package/dist/virtual-file/index.browser.js +18 -0
- package/dist/virtual-file/index.browser.js.map +1 -0
- package/dist/virtual-file/index.js +19 -0
- package/dist/virtual-file/index.js.map +1 -0
- package/dist/virtual-file/toVirtualFile.js +30 -0
- package/dist/virtual-file/toVirtualFile.js.map +1 -0
- package/package.json +32 -61
- package/dist/cjs/array.js +0 -23
- package/dist/cjs/array.js.map +0 -1
- package/dist/cjs/caveats.js +0 -33
- package/dist/cjs/caveats.js.map +0 -1
- package/dist/cjs/checksum.js +0 -38
- package/dist/cjs/checksum.js.map +0 -1
- package/dist/cjs/cronjob.js +0 -84
- package/dist/cjs/cronjob.js.map +0 -1
- package/dist/cjs/deep-clone.js +0 -22
- package/dist/cjs/deep-clone.js.map +0 -1
- package/dist/cjs/default-endowments.js +0 -49
- package/dist/cjs/default-endowments.js.map +0 -1
- package/dist/cjs/entropy.js +0 -23
- package/dist/cjs/entropy.js.map +0 -1
- package/dist/cjs/enum.js +0 -16
- package/dist/cjs/enum.js.map +0 -1
- package/dist/cjs/eval-worker.js.map +0 -1
- package/dist/cjs/eval.js +0 -29
- package/dist/cjs/eval.js.map +0 -1
- package/dist/cjs/fs.js +0 -126
- package/dist/cjs/fs.js.map +0 -1
- package/dist/cjs/handlers.js +0 -6
- package/dist/cjs/handlers.js.map +0 -1
- package/dist/cjs/icon.js +0 -37
- package/dist/cjs/icon.js.map +0 -1
- package/dist/cjs/iframe.js +0 -59
- package/dist/cjs/iframe.js.map +0 -1
- package/dist/cjs/index.browser.js +0 -40
- package/dist/cjs/index.browser.js.map +0 -1
- package/dist/cjs/index.executionenv.js +0 -24
- package/dist/cjs/index.executionenv.js.map +0 -1
- package/dist/cjs/index.js +0 -45
- package/dist/cjs/index.js.map +0 -1
- package/dist/cjs/json-rpc.js +0 -46
- package/dist/cjs/json-rpc.js.map +0 -1
- package/dist/cjs/json.js +0 -16
- package/dist/cjs/json.js.map +0 -1
- package/dist/cjs/logging.js +0 -40
- package/dist/cjs/logging.js.map +0 -1
- package/dist/cjs/manifest/index.browser.js +0 -20
- package/dist/cjs/manifest/index.browser.js.map +0 -1
- package/dist/cjs/manifest/index.js +0 -21
- package/dist/cjs/manifest/index.js.map +0 -1
- package/dist/cjs/manifest/manifest.js +0 -239
- package/dist/cjs/manifest/manifest.js.map +0 -1
- package/dist/cjs/manifest/validation.js +0 -183
- package/dist/cjs/manifest/validation.js.map +0 -1
- package/dist/cjs/mock.js +0 -128
- package/dist/cjs/mock.js.map +0 -1
- package/dist/cjs/namespace.js +0 -124
- package/dist/cjs/namespace.js.map +0 -1
- package/dist/cjs/npm.js +0 -81
- package/dist/cjs/npm.js.map +0 -1
- package/dist/cjs/path.js +0 -21
- package/dist/cjs/path.js.map +0 -1
- package/dist/cjs/post-process.js +0 -328
- package/dist/cjs/post-process.js.map +0 -1
- package/dist/cjs/snaps.js +0 -230
- package/dist/cjs/snaps.js.map +0 -1
- package/dist/cjs/types.js +0 -117
- package/dist/cjs/types.js.map +0 -1
- package/dist/cjs/validation.js +0 -22
- package/dist/cjs/validation.js.map +0 -1
- package/dist/cjs/versions.js +0 -47
- package/dist/cjs/versions.js.map +0 -1
- package/dist/cjs/virtual-file/VirtualFile.js +0 -85
- package/dist/cjs/virtual-file/VirtualFile.js.map +0 -1
- package/dist/cjs/virtual-file/index.browser.js +0 -20
- package/dist/cjs/virtual-file/index.browser.js.map +0 -1
- package/dist/cjs/virtual-file/index.js +0 -21
- package/dist/cjs/virtual-file/index.js.map +0 -1
- package/dist/cjs/virtual-file/toVirtualFile.js +0 -33
- package/dist/cjs/virtual-file/toVirtualFile.js.map +0 -1
- package/dist/esm/array.js.map +0 -1
- package/dist/esm/caveats.js +0 -23
- package/dist/esm/caveats.js.map +0 -1
- package/dist/esm/checksum.js +0 -36
- package/dist/esm/checksum.js.map +0 -1
- package/dist/esm/cronjob.js +0 -66
- package/dist/esm/cronjob.js.map +0 -1
- package/dist/esm/deep-clone.js +0 -7
- package/dist/esm/deep-clone.js.map +0 -1
- package/dist/esm/default-endowments.js.map +0 -1
- package/dist/esm/entropy.js +0 -6
- package/dist/esm/entropy.js.map +0 -1
- package/dist/esm/enum.js +0 -12
- package/dist/esm/enum.js.map +0 -1
- package/dist/esm/eval-worker.js +0 -47
- package/dist/esm/eval-worker.js.map +0 -1
- package/dist/esm/eval.js +0 -25
- package/dist/esm/eval.js.map +0 -1
- package/dist/esm/fs.js.map +0 -1
- package/dist/esm/handlers.js +0 -3
- package/dist/esm/handlers.js.map +0 -1
- package/dist/esm/icon.js +0 -11
- package/dist/esm/icon.js.map +0 -1
- package/dist/esm/iframe.js.map +0 -1
- package/dist/esm/index.browser.js +0 -23
- package/dist/esm/index.browser.js.map +0 -1
- package/dist/esm/index.executionenv.js +0 -7
- package/dist/esm/index.executionenv.js.map +0 -1
- package/dist/esm/index.js +0 -28
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/json-rpc.js +0 -39
- package/dist/esm/json-rpc.js.map +0 -1
- package/dist/esm/json.js +0 -17
- package/dist/esm/json.js.map +0 -1
- package/dist/esm/logging.js.map +0 -1
- package/dist/esm/manifest/index.browser.js +0 -3
- package/dist/esm/manifest/index.browser.js.map +0 -1
- package/dist/esm/manifest/index.js +0 -4
- package/dist/esm/manifest/index.js.map +0 -1
- package/dist/esm/manifest/manifest.js.map +0 -1
- package/dist/esm/manifest/validation.js +0 -152
- package/dist/esm/manifest/validation.js.map +0 -1
- package/dist/esm/mock.js.map +0 -1
- package/dist/esm/namespace.js +0 -110
- package/dist/esm/namespace.js.map +0 -1
- package/dist/esm/npm.js +0 -70
- package/dist/esm/npm.js.map +0 -1
- package/dist/esm/path.js +0 -17
- package/dist/esm/path.js.map +0 -1
- package/dist/esm/post-process.js.map +0 -1
- package/dist/esm/snaps.js +0 -215
- package/dist/esm/snaps.js.map +0 -1
- package/dist/esm/types.js +0 -85
- package/dist/esm/types.js.map +0 -1
- package/dist/esm/validation.js +0 -17
- package/dist/esm/validation.js.map +0 -1
- package/dist/esm/versions.js.map +0 -1
- package/dist/esm/virtual-file/VirtualFile.js.map +0 -1
- package/dist/esm/virtual-file/index.browser.js +0 -3
- package/dist/esm/virtual-file/index.browser.js.map +0 -1
- package/dist/esm/virtual-file/index.js +0 -4
- package/dist/esm/virtual-file/index.js.map +0 -1
- package/dist/esm/virtual-file/toVirtualFile.js +0 -26
- package/dist/esm/virtual-file/toVirtualFile.js.map +0 -1
- package/dist/types/enum.d.ts +0 -30
- package/dist/types/icon.d.ts +0 -4
- package/dist/types/json.d.ts +0 -13
- package/dist/types/namespace.d.ts +0 -124
- package/dist/types/validation.d.ts +0 -8
- /package/dist/{types/array.d.ts → array.d.ts} +0 -0
- /package/dist/{types/checksum.d.ts → checksum.d.ts} +0 -0
- /package/dist/{types/cronjob.d.ts → cronjob.d.ts} +0 -0
- /package/dist/{types/deep-clone.d.ts → deep-clone.d.ts} +0 -0
- /package/dist/{types/default-endowments.d.ts → default-endowments.d.ts} +0 -0
- /package/dist/{types/entropy.d.ts → entropy.d.ts} +0 -0
- /package/dist/{types/eval-worker.d.ts → eval-worker.d.ts} +0 -0
- /package/dist/{types/eval.d.ts → eval.d.ts} +0 -0
- /package/dist/{types/fs.d.ts → fs.d.ts} +0 -0
- /package/dist/{types/iframe.test.browser.d.ts → iframe.test.browser.d.ts} +0 -0
- /package/dist/{types/index.executionenv.d.ts → index.executionenv.d.ts} +0 -0
- /package/dist/{types/json-rpc.d.ts → json-rpc.d.ts} +0 -0
- /package/dist/{types/logging.d.ts → logging.d.ts} +0 -0
- /package/dist/{types/manifest → manifest}/index.browser.d.ts +0 -0
- /package/dist/{types/manifest → manifest}/index.d.ts +0 -0
- /package/dist/{types/manifest → manifest}/manifest.d.ts +0 -0
- /package/dist/{types/mock.d.ts → mock.d.ts} +0 -0
- /package/dist/{types/path.d.ts → path.d.ts} +0 -0
- /package/dist/{types/post-process.d.ts → post-process.d.ts} +0 -0
- /package/dist/{types/versions.d.ts → versions.d.ts} +0 -0
- /package/dist/{types/virtual-file → virtual-file}/VirtualFile.d.ts +0 -0
- /package/dist/{types/virtual-file → virtual-file}/index.browser.d.ts +0 -0
- /package/dist/{types/virtual-file → virtual-file}/index.d.ts +0 -0
- /package/dist/{types/virtual-file → virtual-file}/toVirtualFile.d.ts +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -6,52 +6,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
-
## [0.
|
|
10
|
-
### Changed
|
|
11
|
-
- No changes this release.
|
|
12
|
-
|
|
13
|
-
## [0.35.0-flask.1]
|
|
9
|
+
## [1.0.0-prerelease.1]
|
|
14
10
|
### Added
|
|
15
|
-
- Add
|
|
11
|
+
- Add subject type restrictions to snap-specific permissions ([#1366](https://github.com/MetaMask/snaps/pull/1366))
|
|
16
12
|
|
|
17
13
|
### Changed
|
|
18
|
-
- **BREAKING:** Build packages as both CJS and ESM ([#1519](https://github.com/MetaMask/snaps/pull/1519), ([#1532](https://github.com/MetaMask/snaps/pull/1532)))
|
|
19
|
-
- This is breaking in the sense that imports to `dist/` will now require you to import either `dist/cjs` or `dist/esm`.
|
|
20
14
|
- **BREAKING:** Disallow deriving Ethereum keys ([#1217](https://github.com/MetaMask/snaps/pull/1217))
|
|
21
|
-
- Coin type `60` is now blocked for derivation.
|
|
22
|
-
- Add `sideEffects: false` ([#1486](https://github.com/MetaMask/snaps/pull/1486))
|
|
23
|
-
|
|
24
|
-
### Removed
|
|
25
|
-
- **BREAKING:** Remove utility functions used for multichain/keyring effort ([#1527](https://github.com/MetaMask/snaps/pull/1527))
|
|
15
|
+
- Coin type `60` is now blocked for derivation.
|
|
26
16
|
|
|
27
17
|
### Fixed
|
|
28
18
|
- Improve JSON parsing safety ([#1499](https://github.com/MetaMask/snaps/pull/1499))
|
|
29
|
-
- Fix false positives when post processing code with HTML comment tokens ([#1522](https://github.com/MetaMask/snaps/pull/1522))
|
|
30
|
-
- Fix BIP-32 path validation ([#1506](https://github.com/MetaMask/snaps/pull/1506))
|
|
31
|
-
|
|
32
|
-
## [0.34.1-flask.1]
|
|
33
|
-
### Changed
|
|
34
|
-
- No changes this release.
|
|
35
|
-
|
|
36
|
-
## [0.34.0-flask.1]
|
|
37
|
-
### Changed
|
|
38
|
-
- Add SVG validation ([#1401](https://github.com/MetaMask/snaps/pull/1401))
|
|
39
|
-
- Make handler types generic, allowing them to be changed ([#1409](https://github.com/MetaMask/snaps/pull/1409))
|
|
40
|
-
- Allow use of `$schema` in manifest files ([#1389](https://github.com/MetaMask/snaps/pull/1389))
|
|
41
|
-
|
|
42
|
-
## [0.33.1-flask.1]
|
|
43
|
-
### Changed
|
|
44
|
-
- No changes this release.
|
|
45
|
-
|
|
46
|
-
## [0.33.0-flask.1]
|
|
47
|
-
### Changed
|
|
48
|
-
- **BREAKING:** Added `snapIds` caveat mapper ([#1360](https://github.com/MetaMask/snaps-monorepo/pull/1360))
|
|
49
|
-
- Snap dependencies must be specified in a simplified manner. See the PR for an example.
|
|
50
|
-
- Add subject type restrictions to snap-specific permissions ([#1366](https://github.com/MetaMask/snaps-monorepo/pull/1366))
|
|
51
|
-
- Add Web Worker support for snap execution ([#1320](https://github.com/MetaMask/snaps-monorepo/pull/1320))
|
|
52
|
-
|
|
53
|
-
### Fixed
|
|
54
|
-
- Add `WebAssembly` to eval mock ([#1359](https://github.com/MetaMask/snaps-monorepo/pull/1359))
|
|
55
19
|
|
|
56
20
|
## [0.32.2]
|
|
57
21
|
### Changed
|
|
@@ -230,13 +194,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
230
194
|
### Added
|
|
231
195
|
- Initial release ([#410](https://github.com/MetaMask/snaps-monorepo/pull/410), [#421](https://github.com/MetaMask/snaps-monorepo/pull/421))
|
|
232
196
|
|
|
233
|
-
[Unreleased]: https://github.com/MetaMask/snaps/compare/
|
|
234
|
-
[0.
|
|
235
|
-
[0.35.0-flask.1]: https://github.com/MetaMask/snaps/compare/v0.34.1-flask.1...v0.35.0-flask.1
|
|
236
|
-
[0.34.1-flask.1]: https://github.com/MetaMask/snaps/compare/v0.34.0-flask.1...v0.34.1-flask.1
|
|
237
|
-
[0.34.0-flask.1]: https://github.com/MetaMask/snaps/compare/v0.33.1-flask.1...v0.34.0-flask.1
|
|
238
|
-
[0.33.1-flask.1]: https://github.com/MetaMask/snaps/compare/v0.33.0-flask.1...v0.33.1-flask.1
|
|
239
|
-
[0.33.0-flask.1]: https://github.com/MetaMask/snaps/compare/v0.32.2...v0.33.0-flask.1
|
|
197
|
+
[Unreleased]: https://github.com/MetaMask/snaps/compare/v1.0.0-prerelease.1...HEAD
|
|
198
|
+
[1.0.0-prerelease.1]: https://github.com/MetaMask/snaps/compare/v0.32.2...v1.0.0-prerelease.1
|
|
240
199
|
[0.32.2]: https://github.com/MetaMask/snaps/compare/v0.32.1...v0.32.2
|
|
241
200
|
[0.32.1]: https://github.com/MetaMask/snaps/compare/v0.32.0...v0.32.1
|
|
242
201
|
[0.32.0]: https://github.com/MetaMask/snaps/compare/v0.31.0...v0.32.0
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isEqual = void 0;
|
|
1
4
|
/**
|
|
2
5
|
* Checks if array `a` is equal to array `b`. Note that this does not do a deep
|
|
3
6
|
* equality check. It only checks if the arrays are the same length and if each
|
|
@@ -6,8 +9,9 @@
|
|
|
6
9
|
* @param a - The first array to compare.
|
|
7
10
|
* @param b - The second array to compare.
|
|
8
11
|
* @returns `true` if the arrays are equal, `false` otherwise.
|
|
9
|
-
*/
|
|
10
|
-
|
|
12
|
+
*/
|
|
13
|
+
function isEqual(a, b) {
|
|
14
|
+
return a.length === b.length && a.every((value, index) => value === b[index]);
|
|
11
15
|
}
|
|
12
|
-
|
|
16
|
+
exports.isEqual = isEqual;
|
|
13
17
|
//# sourceMappingURL=array.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"array.js","sourceRoot":"","sources":["../src/array.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;GAQG;AACH,SAAgB,OAAO,CAAC,CAAY,EAAE,CAAY;IAChD,OAAO,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;AAChF,CAAC;AAFD,0BAEC","sourcesContent":["/**\n * Checks if array `a` is equal to array `b`. Note that this does not do a deep\n * equality check. It only checks if the arrays are the same length and if each\n * element in `a` is equal to (`===`) the corresponding element in `b`.\n *\n * @param a - The first array to compare.\n * @param b - The second array to compare.\n * @returns `true` if the arrays are equal, `false` otherwise.\n */\nexport function isEqual(a: unknown[], b: unknown[]): boolean {\n return a.length === b.length && a.every((value, index) => value === b[index]);\n}\n"]}
|
|
@@ -7,6 +7,10 @@ export declare enum SnapCaveatType {
|
|
|
7
7
|
* Permitted coin types, used by `snap_getBip44Entropy`.
|
|
8
8
|
*/
|
|
9
9
|
PermittedCoinTypes = "permittedCoinTypes",
|
|
10
|
+
/**
|
|
11
|
+
* Permission to use the Snap keyring API.
|
|
12
|
+
*/
|
|
13
|
+
SnapKeyring = "snapKeyring",
|
|
10
14
|
/**
|
|
11
15
|
* Caveat specifying a snap cronjob.
|
|
12
16
|
*/
|
package/dist/caveats.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SnapCaveatType = void 0;
|
|
4
|
+
var SnapCaveatType;
|
|
5
|
+
(function (SnapCaveatType) {
|
|
6
|
+
/**
|
|
7
|
+
* Permitted derivation paths, used by `snap_getBip32Entropy`.
|
|
8
|
+
*/
|
|
9
|
+
SnapCaveatType["PermittedDerivationPaths"] = "permittedDerivationPaths";
|
|
10
|
+
/**
|
|
11
|
+
* Permitted coin types, used by `snap_getBip44Entropy`.
|
|
12
|
+
*/
|
|
13
|
+
SnapCaveatType["PermittedCoinTypes"] = "permittedCoinTypes";
|
|
14
|
+
/**
|
|
15
|
+
* Permission to use the Snap keyring API.
|
|
16
|
+
*/
|
|
17
|
+
SnapCaveatType["SnapKeyring"] = "snapKeyring";
|
|
18
|
+
/**
|
|
19
|
+
* Caveat specifying a snap cronjob.
|
|
20
|
+
*/
|
|
21
|
+
SnapCaveatType["SnapCronjob"] = "snapCronjob";
|
|
22
|
+
/**
|
|
23
|
+
* Caveat specifying access to the transaction origin, used by `endowment:transaction-insight`.
|
|
24
|
+
*/
|
|
25
|
+
SnapCaveatType["TransactionOrigin"] = "transactionOrigin";
|
|
26
|
+
/**
|
|
27
|
+
* The origins that a Snap can receive JSON-RPC messages from.
|
|
28
|
+
*/
|
|
29
|
+
SnapCaveatType["RpcOrigin"] = "rpcOrigin";
|
|
30
|
+
/**
|
|
31
|
+
* Caveat specifying the snap IDs that can be interacted with.
|
|
32
|
+
*/
|
|
33
|
+
SnapCaveatType["SnapIds"] = "snapIds";
|
|
34
|
+
})(SnapCaveatType = exports.SnapCaveatType || (exports.SnapCaveatType = {}));
|
|
35
|
+
//# sourceMappingURL=caveats.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"caveats.js","sourceRoot":"","sources":["../src/caveats.ts"],"names":[],"mappings":";;;AAAA,IAAY,cAmCX;AAnCD,WAAY,cAAc;IACxB;;OAEG;IACH,uEAAqD,CAAA;IAErD;;OAEG;IACH,2DAAyC,CAAA;IAEzC;;OAEG;IACH,6CAA2B,CAAA;IAE3B;;OAEG;IACH,6CAA2B,CAAA;IAE3B;;OAEG;IACH,yDAAuC,CAAA;IAEvC;;OAEG;IACH,yCAAuB,CAAA;IAEvB;;OAEG;IACH,qCAAmB,CAAA;AACrB,CAAC,EAnCW,cAAc,GAAd,sBAAc,KAAd,sBAAc,QAmCzB","sourcesContent":["export enum SnapCaveatType {\n /**\n * Permitted derivation paths, used by `snap_getBip32Entropy`.\n */\n PermittedDerivationPaths = 'permittedDerivationPaths',\n\n /**\n * Permitted coin types, used by `snap_getBip44Entropy`.\n */\n PermittedCoinTypes = 'permittedCoinTypes',\n\n /**\n * Permission to use the Snap keyring API.\n */\n SnapKeyring = 'snapKeyring',\n\n /**\n * Caveat specifying a snap cronjob.\n */\n SnapCronjob = 'snapCronjob',\n\n /**\n * Caveat specifying access to the transaction origin, used by `endowment:transaction-insight`.\n */\n TransactionOrigin = 'transactionOrigin',\n\n /**\n * The origins that a Snap can receive JSON-RPC messages from.\n */\n RpcOrigin = 'rpcOrigin',\n\n /**\n * Caveat specifying the snap IDs that can be interacted with.\n */\n SnapIds = 'snapIds',\n}\n"]}
|
package/dist/checksum.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.checksumFiles = exports.checksum = void 0;
|
|
4
|
+
const utils_1 = require("@metamask/utils");
|
|
5
|
+
const sha256_1 = require("@noble/hashes/sha256");
|
|
6
|
+
const VirtualFile_1 = require("./virtual-file/VirtualFile");
|
|
7
|
+
/**
|
|
8
|
+
* Calculates checksum for a single byte array.
|
|
9
|
+
*
|
|
10
|
+
* @param bytes - The byte array to calculate the checksum for.
|
|
11
|
+
* @returns A single sha-256 checksum.
|
|
12
|
+
*/
|
|
13
|
+
function checksum(bytes) {
|
|
14
|
+
const value = bytes instanceof VirtualFile_1.VirtualFile ? bytes.value : bytes;
|
|
15
|
+
return (0, sha256_1.sha256)(value);
|
|
16
|
+
}
|
|
17
|
+
exports.checksum = checksum;
|
|
18
|
+
/**
|
|
19
|
+
* Calculates checksum over multiple files in a reproducible way.
|
|
20
|
+
*
|
|
21
|
+
* 1. Sort all the files by their paths.
|
|
22
|
+
* 2. Calculate sha-256 checksum of each file separately.
|
|
23
|
+
* 3. Concatenate all the checksums into one buffer and sha-256 that buffer.
|
|
24
|
+
*
|
|
25
|
+
* The sorting of paths is done using {@link https://tc39.es/ecma262/#sec-islessthan UTF-16 Code Units}.
|
|
26
|
+
*
|
|
27
|
+
* @param files - The files over which to calculate the checksum.
|
|
28
|
+
* @returns A single sha-256 checksum.
|
|
29
|
+
*/
|
|
30
|
+
function checksumFiles(files) {
|
|
31
|
+
return checksum((0, utils_1.concatBytes)([...files]
|
|
32
|
+
.sort((a, b) => {
|
|
33
|
+
(0, utils_1.assert)(a.path !== b.path, 'Tried to sort files with non-unique paths.');
|
|
34
|
+
if (a.path < b.path) {
|
|
35
|
+
return -1;
|
|
36
|
+
}
|
|
37
|
+
return 1;
|
|
38
|
+
})
|
|
39
|
+
.map((file) => checksum(file))));
|
|
40
|
+
}
|
|
41
|
+
exports.checksumFiles = checksumFiles;
|
|
42
|
+
//# sourceMappingURL=checksum.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checksum.js","sourceRoot":"","sources":["../src/checksum.ts"],"names":[],"mappings":";;;AAAA,2CAAsD;AACtD,iDAA8C;AAE9C,4DAAyD;AAEzD;;;;;GAKG;AACH,SAAgB,QAAQ,CAAC,KAAwC;IAC/D,MAAM,KAAK,GAAG,KAAK,YAAY,yBAAW,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC;IACjE,OAAO,IAAA,eAAM,EAAC,KAAK,CAAC,CAAC;AACvB,CAAC;AAHD,4BAGC;AAED;;;;;;;;;;;GAWG;AACH,SAAgB,aAAa,CAAC,KAAoB;IAChD,OAAO,QAAQ,CACb,IAAA,mBAAW,EACT,CAAC,GAAG,KAAK,CAAC;SACP,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;QACb,IAAA,cAAM,EACJ,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,IAAI,EACjB,4CAA4C,CAC7C,CAAC;QACF,IAAI,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,EAAE;YACnB,OAAO,CAAC,CAAC,CAAC;SACX;QACD,OAAO,CAAC,CAAC;IACX,CAAC,CAAC;SACD,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CACjC,CACF,CAAC;AACJ,CAAC;AAjBD,sCAiBC","sourcesContent":["import { assert, concatBytes } from '@metamask/utils';\nimport { sha256 } from '@noble/hashes/sha256';\n\nimport { VirtualFile } from './virtual-file/VirtualFile';\n\n/**\n * Calculates checksum for a single byte array.\n *\n * @param bytes - The byte array to calculate the checksum for.\n * @returns A single sha-256 checksum.\n */\nexport function checksum(bytes: VirtualFile | Uint8Array | string): Uint8Array {\n const value = bytes instanceof VirtualFile ? bytes.value : bytes;\n return sha256(value);\n}\n\n/**\n * Calculates checksum over multiple files in a reproducible way.\n *\n * 1. Sort all the files by their paths.\n * 2. Calculate sha-256 checksum of each file separately.\n * 3. Concatenate all the checksums into one buffer and sha-256 that buffer.\n *\n * The sorting of paths is done using {@link https://tc39.es/ecma262/#sec-islessthan UTF-16 Code Units}.\n *\n * @param files - The files over which to calculate the checksum.\n * @returns A single sha-256 checksum.\n */\nexport function checksumFiles(files: VirtualFile[]) {\n return checksum(\n concatBytes(\n [...files]\n .sort((a, b) => {\n assert(\n a.path !== b.path,\n 'Tried to sort files with non-unique paths.',\n );\n if (a.path < b.path) {\n return -1;\n }\n return 1;\n })\n .map((file) => checksum(file)),\n ),\n );\n}\n"]}
|
package/dist/cronjob.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isCronjobSpecificationArray = exports.CronjobSpecificationArrayStruct = exports.isCronjobSpecification = exports.CronjobSpecificationStruct = exports.parseCronExpression = exports.CronExpressionStruct = exports.CronjobRpcRequestStruct = void 0;
|
|
4
|
+
const utils_1 = require("@metamask/utils");
|
|
5
|
+
const cron_parser_1 = require("cron-parser");
|
|
6
|
+
const superstruct_1 = require("superstruct");
|
|
7
|
+
exports.CronjobRpcRequestStruct = (0, superstruct_1.assign)((0, superstruct_1.partial)((0, superstruct_1.pick)(utils_1.JsonRpcRequestStruct, ['id', 'jsonrpc'])), (0, superstruct_1.omit)(utils_1.JsonRpcRequestStruct, ['id', 'jsonrpc']));
|
|
8
|
+
exports.CronExpressionStruct = (0, superstruct_1.refine)((0, superstruct_1.coerce)((0, superstruct_1.string)(), (0, superstruct_1.object)({
|
|
9
|
+
minute: (0, superstruct_1.optional)((0, superstruct_1.string)()),
|
|
10
|
+
hour: (0, superstruct_1.optional)((0, superstruct_1.string)()),
|
|
11
|
+
dayOfMonth: (0, superstruct_1.optional)((0, superstruct_1.string)()),
|
|
12
|
+
month: (0, superstruct_1.optional)((0, superstruct_1.string)()),
|
|
13
|
+
dayOfWeek: (0, superstruct_1.optional)((0, superstruct_1.string)()),
|
|
14
|
+
}), (value) => `${value.minute ?? '*'} ${value.hour ?? '*'} ${value.dayOfMonth ?? '*'} ${value.month ?? '*'} ${value.dayOfWeek ?? '*'}`), 'CronExpression', (value) => {
|
|
15
|
+
try {
|
|
16
|
+
(0, cron_parser_1.parseExpression)(value);
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
/**
|
|
24
|
+
* Parses a cron expression.
|
|
25
|
+
*
|
|
26
|
+
* @param expression - Expression to parse.
|
|
27
|
+
* @returns A CronExpression class instance.
|
|
28
|
+
*/
|
|
29
|
+
function parseCronExpression(expression) {
|
|
30
|
+
const ensureStringExpression = (0, superstruct_1.create)(expression, exports.CronExpressionStruct);
|
|
31
|
+
return (0, cron_parser_1.parseExpression)(ensureStringExpression);
|
|
32
|
+
}
|
|
33
|
+
exports.parseCronExpression = parseCronExpression;
|
|
34
|
+
exports.CronjobSpecificationStruct = (0, superstruct_1.object)({
|
|
35
|
+
expression: exports.CronExpressionStruct,
|
|
36
|
+
request: exports.CronjobRpcRequestStruct,
|
|
37
|
+
});
|
|
38
|
+
/**
|
|
39
|
+
* Check if the given value is a {@link CronjobSpecification} object.
|
|
40
|
+
*
|
|
41
|
+
* @param value - The value to check.
|
|
42
|
+
* @returns Whether the value is a valid {@link CronjobSpecification} object.
|
|
43
|
+
*/
|
|
44
|
+
function isCronjobSpecification(value) {
|
|
45
|
+
try {
|
|
46
|
+
(0, superstruct_1.create)(value, exports.CronjobSpecificationStruct);
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
exports.isCronjobSpecification = isCronjobSpecification;
|
|
54
|
+
exports.CronjobSpecificationArrayStruct = (0, superstruct_1.array)(exports.CronjobSpecificationStruct);
|
|
55
|
+
/**
|
|
56
|
+
* Check if the given value is an array of {@link CronjobSpecification} objects.
|
|
57
|
+
*
|
|
58
|
+
* @param value - The value to check.
|
|
59
|
+
* @returns Whether the value is a valid array of {@link CronjobSpecification} objects.
|
|
60
|
+
*/
|
|
61
|
+
function isCronjobSpecificationArray(value) {
|
|
62
|
+
try {
|
|
63
|
+
(0, superstruct_1.create)(value, exports.CronjobSpecificationArrayStruct);
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
exports.isCronjobSpecificationArray = isCronjobSpecificationArray;
|
|
71
|
+
//# sourceMappingURL=cronjob.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cronjob.js","sourceRoot":"","sources":["../src/cronjob.ts"],"names":[],"mappings":";;;AAAA,2CAAuD;AACvD,6CAA8C;AAC9C,6CAaqB;AAER,QAAA,uBAAuB,GAAG,IAAA,oBAAM,EAC3C,IAAA,qBAAO,EAAC,IAAA,kBAAI,EAAC,4BAAoB,EAAE,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC,EACtD,IAAA,kBAAI,EAAC,4BAAoB,EAAE,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,CAC9C,CAAC;AAGW,QAAA,oBAAoB,GAAG,IAAA,oBAAM,EACxC,IAAA,oBAAM,EACJ,IAAA,oBAAM,GAAE,EACR,IAAA,oBAAM,EAAC;IACL,MAAM,EAAE,IAAA,sBAAQ,EAAC,IAAA,oBAAM,GAAE,CAAC;IAC1B,IAAI,EAAE,IAAA,sBAAQ,EAAC,IAAA,oBAAM,GAAE,CAAC;IACxB,UAAU,EAAE,IAAA,sBAAQ,EAAC,IAAA,oBAAM,GAAE,CAAC;IAC9B,KAAK,EAAE,IAAA,sBAAQ,EAAC,IAAA,oBAAM,GAAE,CAAC;IACzB,SAAS,EAAE,IAAA,sBAAQ,EAAC,IAAA,oBAAM,GAAE,CAAC;CAC9B,CAAC,EACF,CAAC,KAAK,EAAE,EAAE,CACR,GAAG,KAAK,CAAC,MAAM,IAAI,GAAG,IAAI,KAAK,CAAC,IAAI,IAAI,GAAG,IAAI,KAAK,CAAC,UAAU,IAAI,GAAG,IACpE,KAAK,CAAC,KAAK,IAAI,GACjB,IAAI,KAAK,CAAC,SAAS,IAAI,GAAG,EAAE,CAC/B,EACD,gBAAgB,EAChB,CAAC,KAAK,EAAE,EAAE;IACR,IAAI;QACF,IAAA,6BAAe,EAAC,KAAK,CAAC,CAAC;QACvB,OAAO,IAAI,CAAC;KACb;IAAC,MAAM;QACN,OAAO,KAAK,CAAC;KACd;AACH,CAAC,CACF,CAAC;AAIF;;;;;GAKG;AACH,SAAgB,mBAAmB,CAAC,UAA2B;IAC7D,MAAM,sBAAsB,GAAG,IAAA,oBAAM,EAAC,UAAU,EAAE,4BAAoB,CAAC,CAAC;IACxE,OAAO,IAAA,6BAAe,EAAC,sBAAsB,CAAC,CAAC;AACjD,CAAC;AAHD,kDAGC;AAEY,QAAA,0BAA0B,GAAG,IAAA,oBAAM,EAAC;IAC/C,UAAU,EAAE,4BAAoB;IAChC,OAAO,EAAE,+BAAuB;CACjC,CAAC,CAAC;AAGH;;;;;GAKG;AACH,SAAgB,sBAAsB,CAAC,KAAc;IACnD,IAAI;QACF,IAAA,oBAAM,EAAC,KAAK,EAAE,kCAA0B,CAAC,CAAC;QAC1C,OAAO,IAAI,CAAC;KACb;IAAC,MAAM;QACN,OAAO,KAAK,CAAC;KACd;AACH,CAAC;AAPD,wDAOC;AAEY,QAAA,+BAA+B,GAAG,IAAA,mBAAK,EAClD,kCAA0B,CAC3B,CAAC;AAEF;;;;;GAKG;AACH,SAAgB,2BAA2B,CAAC,KAAc;IACxD,IAAI;QACF,IAAA,oBAAM,EAAC,KAAK,EAAE,uCAA+B,CAAC,CAAC;QAC/C,OAAO,IAAI,CAAC;KACb;IAAC,MAAM;QACN,OAAO,KAAK,CAAC;KACd;AACH,CAAC;AAPD,kEAOC","sourcesContent":["import { JsonRpcRequestStruct } from '@metamask/utils';\nimport { parseExpression } from 'cron-parser';\nimport {\n array,\n assign,\n coerce,\n create,\n Infer,\n object,\n omit,\n optional,\n partial,\n pick,\n refine,\n string,\n} from 'superstruct';\n\nexport const CronjobRpcRequestStruct = assign(\n partial(pick(JsonRpcRequestStruct, ['id', 'jsonrpc'])),\n omit(JsonRpcRequestStruct, ['id', 'jsonrpc']),\n);\nexport type CronjobRpcRequest = Infer<typeof CronjobRpcRequestStruct>;\n\nexport const CronExpressionStruct = refine(\n coerce(\n string(),\n object({\n minute: optional(string()),\n hour: optional(string()),\n dayOfMonth: optional(string()),\n month: optional(string()),\n dayOfWeek: optional(string()),\n }),\n (value) =>\n `${value.minute ?? '*'} ${value.hour ?? '*'} ${value.dayOfMonth ?? '*'} ${\n value.month ?? '*'\n } ${value.dayOfWeek ?? '*'}`,\n ),\n 'CronExpression',\n (value) => {\n try {\n parseExpression(value);\n return true;\n } catch {\n return false;\n }\n },\n);\n\nexport type CronExpression = Infer<typeof CronExpressionStruct>;\n\n/**\n * Parses a cron expression.\n *\n * @param expression - Expression to parse.\n * @returns A CronExpression class instance.\n */\nexport function parseCronExpression(expression: string | object) {\n const ensureStringExpression = create(expression, CronExpressionStruct);\n return parseExpression(ensureStringExpression);\n}\n\nexport const CronjobSpecificationStruct = object({\n expression: CronExpressionStruct,\n request: CronjobRpcRequestStruct,\n});\nexport type CronjobSpecification = Infer<typeof CronjobSpecificationStruct>;\n\n/**\n * Check if the given value is a {@link CronjobSpecification} object.\n *\n * @param value - The value to check.\n * @returns Whether the value is a valid {@link CronjobSpecification} object.\n */\nexport function isCronjobSpecification(value: unknown): boolean {\n try {\n create(value, CronjobSpecificationStruct);\n return true;\n } catch {\n return false;\n }\n}\n\nexport const CronjobSpecificationArrayStruct = array(\n CronjobSpecificationStruct,\n);\n\n/**\n * Check if the given value is an array of {@link CronjobSpecification} objects.\n *\n * @param value - The value to check.\n * @returns Whether the value is a valid array of {@link CronjobSpecification} objects.\n */\nexport function isCronjobSpecificationArray(value: unknown): boolean {\n try {\n create(value, CronjobSpecificationArrayStruct);\n return true;\n } catch {\n return false;\n }\n}\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
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.deepClone = void 0;
|
|
7
|
+
const rfdc_1 = __importDefault(require("rfdc"));
|
|
8
|
+
exports.deepClone = (0, rfdc_1.default)({ proto: false, circles: false });
|
|
9
|
+
//# sourceMappingURL=deep-clone.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deep-clone.js","sourceRoot":"","sources":["../src/deep-clone.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;AAEX,QAAA,SAAS,GAAG,IAAA,cAAI,EAAC,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC","sourcesContent":["import rfdc from 'rfdc';\n\nexport const deepClone = rfdc({ proto: false, circles: false });\n"]}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_ENDOWMENTS = void 0;
|
|
1
4
|
/**
|
|
2
5
|
* Global JavaScript APIs exposed by default to all snaps.
|
|
3
|
-
*/
|
|
6
|
+
*/
|
|
7
|
+
exports.DEFAULT_ENDOWMENTS = Object.freeze([
|
|
4
8
|
'atob',
|
|
5
9
|
'btoa',
|
|
6
10
|
'BigInt',
|
|
@@ -33,7 +37,6 @@
|
|
|
33
37
|
// https://github.com/MetaMask/snaps-monorepo/issues/662
|
|
34
38
|
// https://github.com/MetaMask/snaps-monorepo/discussions/678
|
|
35
39
|
'AbortController',
|
|
36
|
-
'AbortSignal'
|
|
40
|
+
'AbortSignal',
|
|
37
41
|
]);
|
|
38
|
-
|
|
39
42
|
//# sourceMappingURL=default-endowments.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"default-endowments.js","sourceRoot":"","sources":["../src/default-endowments.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACU,QAAA,kBAAkB,GAAsB,MAAM,CAAC,MAAM,CAAC;IACjE,MAAM;IACN,MAAM;IACN,QAAQ;IACR,SAAS;IACT,QAAQ;IACR,MAAM;IACN,MAAM;IACN,YAAY;IACZ,cAAc;IACd,cAAc;IACd,aAAa;IACb,aAAa;IACb,KAAK;IACL,aAAa;IACb,eAAe;IACf,WAAW;IACX,YAAY;IACZ,mBAAmB;IACnB,YAAY;IACZ,aAAa;IACb,YAAY;IACZ,aAAa;IACb,cAAc;IACd,cAAc;IACd,eAAe;IACf,gBAAgB;IAChB,UAAU;IACV,aAAa;IACb,qFAAqF;IACrF,wDAAwD;IACxD,6DAA6D;IAC7D,iBAAiB;IACjB,aAAa;CACd,CAAC,CAAC","sourcesContent":["/**\n * Global JavaScript APIs exposed by default to all snaps.\n */\nexport const DEFAULT_ENDOWMENTS: readonly string[] = Object.freeze([\n 'atob',\n 'btoa',\n 'BigInt',\n 'console',\n 'crypto',\n 'Date',\n 'Math',\n 'setTimeout',\n 'clearTimeout',\n 'SubtleCrypto',\n 'TextDecoder',\n 'TextEncoder',\n 'URL',\n 'setInterval',\n 'clearInterval',\n 'Int8Array',\n 'Uint8Array',\n 'Uint8ClampedArray',\n 'Int16Array',\n 'Uint16Array',\n 'Int32Array',\n 'Uint32Array',\n 'Float32Array',\n 'Float64Array',\n 'BigInt64Array',\n 'BigUint64Array',\n 'DataView',\n 'ArrayBuffer',\n // Used by fetch, but also as API for some packages that don't do network connections\n // https://github.com/MetaMask/snaps-monorepo/issues/662\n // https://github.com/MetaMask/snaps-monorepo/discussions/678\n 'AbortController',\n 'AbortSignal',\n]);\n"]}
|
package/dist/entropy.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.STATE_ENCRYPTION_MAGIC_VALUE = exports.SIP_6_MAGIC_VALUE = void 0;
|
|
4
|
+
// 0xd36e6170 - 0x80000000
|
|
5
|
+
exports.SIP_6_MAGIC_VALUE = `1399742832'`;
|
|
6
|
+
// `${bytesToNumber(keccak256('Snaps state encryption').slice(0, 4))}'`
|
|
7
|
+
exports.STATE_ENCRYPTION_MAGIC_VALUE = `572232532'`;
|
|
8
|
+
//# sourceMappingURL=entropy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entropy.js","sourceRoot":"","sources":["../src/entropy.ts"],"names":[],"mappings":";;;AAAA,0BAA0B;AACb,QAAA,iBAAiB,GAAG,aAA6B,CAAC;AAE/D,uEAAuE;AAC1D,QAAA,4BAA4B,GAAG,YAA4B,CAAC","sourcesContent":["// 0xd36e6170 - 0x80000000\nexport const SIP_6_MAGIC_VALUE = `1399742832'` as `${number}'`;\n\n// `${bytesToNumber(keccak256('Snaps state encryption').slice(0, 4))}'`\nexport const STATE_ENCRYPTION_MAGIC_VALUE = `572232532'` as `${number}'`;\n\nexport type MagicValue =\n | typeof SIP_6_MAGIC_VALUE\n | typeof STATE_ENCRYPTION_MAGIC_VALUE;\n"]}
|
|
@@ -1,22 +1,23 @@
|
|
|
1
|
-
// eslint-disable-next-line import/no-unassigned-import
|
|
2
1
|
"use strict";
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
|
|
5
|
-
});
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
// eslint-disable-next-line import/no-unassigned-import
|
|
6
4
|
require("ses/lockdown");
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
5
|
+
const fs_1 = require("fs");
|
|
6
|
+
const mock_1 = require("./mock");
|
|
7
|
+
const types_1 = require("./types");
|
|
10
8
|
lockdown({
|
|
11
9
|
consoleTaming: 'unsafe',
|
|
12
10
|
errorTaming: 'unsafe',
|
|
13
11
|
mathTaming: 'unsafe',
|
|
14
12
|
dateTaming: 'unsafe',
|
|
15
13
|
overrideTaming: 'severe',
|
|
16
|
-
//
|
|
17
|
-
//
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
// TODO: See if there's an easier way to do this. This file is ran in a
|
|
15
|
+
// separate process, so we can't mock SES with Jest.
|
|
16
|
+
...(process.env.NODE_ENV === 'test'
|
|
17
|
+
? {
|
|
18
|
+
domainTaming: 'unsafe',
|
|
19
|
+
}
|
|
20
|
+
: {}),
|
|
20
21
|
});
|
|
21
22
|
/**
|
|
22
23
|
* Get mock endowments that don't do anything. This is useful for running the
|
|
@@ -24,28 +25,26 @@ lockdown({
|
|
|
24
25
|
* for example.
|
|
25
26
|
*
|
|
26
27
|
* @returns The mock endowments.
|
|
27
|
-
*/
|
|
28
|
-
|
|
28
|
+
*/
|
|
29
|
+
function getMockEndowments() {
|
|
30
|
+
const endowments = (0, mock_1.generateMockEndowments)();
|
|
29
31
|
return {
|
|
30
32
|
...endowments,
|
|
31
33
|
window: endowments,
|
|
32
|
-
self: endowments
|
|
34
|
+
self: endowments,
|
|
33
35
|
};
|
|
34
36
|
}
|
|
35
37
|
const snapFilePath = process.argv[2];
|
|
36
|
-
const snapModule = {
|
|
37
|
-
exports: {}
|
|
38
|
-
};
|
|
38
|
+
const snapModule = { exports: {} };
|
|
39
39
|
new Compartment({
|
|
40
40
|
...getMockEndowments(),
|
|
41
41
|
module: snapModule,
|
|
42
|
-
exports: snapModule.exports
|
|
43
|
-
}).evaluate((0,
|
|
44
|
-
const invalidExports = Object.keys(snapModule.exports).filter((snapExport)
|
|
42
|
+
exports: snapModule.exports,
|
|
43
|
+
}).evaluate((0, fs_1.readFileSync)(snapFilePath, 'utf8'));
|
|
44
|
+
const invalidExports = Object.keys(snapModule.exports).filter((snapExport) => !types_1.SNAP_EXPORT_NAMES.includes(snapExport));
|
|
45
45
|
if (invalidExports.length > 0) {
|
|
46
46
|
// eslint-disable-next-line no-console
|
|
47
47
|
console.warn(`Invalid snap exports detected:\n${invalidExports.join('\n')}`);
|
|
48
48
|
}
|
|
49
|
-
setTimeout(()=>process.exit(0), 1000); // Hack to ensure worker exits
|
|
50
|
-
|
|
49
|
+
setTimeout(() => process.exit(0), 1000); // Hack to ensure worker exits
|
|
51
50
|
//# sourceMappingURL=eval-worker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eval-worker.js","sourceRoot":"","sources":["../src/eval-worker.ts"],"names":[],"mappings":";;AAAA,uDAAuD;AACvD,wBAAsB;AAEtB,2BAAkC;AAElC,iCAAgD;AAChD,mCAAyD;AAIzD,QAAQ,CAAC;IACP,aAAa,EAAE,QAAQ;IACvB,WAAW,EAAE,QAAQ;IACrB,UAAU,EAAE,QAAQ;IACpB,UAAU,EAAE,QAAQ;IACpB,cAAc,EAAE,QAAQ;IAExB,uEAAuE;IACvE,oDAAoD;IACpD,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,MAAM;QACjC,CAAC,CAAC;YACE,YAAY,EAAE,QAAQ;SACvB;QACH,CAAC,CAAC,EAAE,CAAC;CACR,CAAC,CAAC;AAEH;;;;;;GAMG;AACH,SAAS,iBAAiB;IACxB,MAAM,UAAU,GAAG,IAAA,6BAAsB,GAAE,CAAC;IAC5C,OAAO;QACL,GAAG,UAAU;QACb,MAAM,EAAE,UAAU;QAClB,IAAI,EAAE,UAAU;KACjB,CAAC;AACJ,CAAC;AAED,MAAM,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAErC,MAAM,UAAU,GAAsB,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;AAEtD,IAAI,WAAW,CAAC;IACd,GAAG,iBAAiB,EAAE;IACtB,MAAM,EAAE,UAAU;IAClB,OAAO,EAAE,UAAU,CAAC,OAAO;CAC5B,CAAC,CAAC,QAAQ,CAAC,IAAA,iBAAY,EAAC,YAAY,EAAE,MAAM,CAAC,CAAC,CAAC;AAEhD,MAAM,cAAc,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,MAAM,CAC3D,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC,yBAAiB,CAAC,QAAQ,CAAC,UAAyB,CAAC,CACvE,CAAC;AAEF,IAAI,cAAc,CAAC,MAAM,GAAG,CAAC,EAAE;IAC7B,sCAAsC;IACtC,OAAO,CAAC,IAAI,CAAC,mCAAmC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;CAC9E;AAED,UAAU,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,8BAA8B","sourcesContent":["// eslint-disable-next-line import/no-unassigned-import\nimport 'ses/lockdown';\n\nimport { readFileSync } from 'fs';\n\nimport { generateMockEndowments } from './mock';\nimport { HandlerType, SNAP_EXPORT_NAMES } from './types';\n\ndeclare let lockdown: any, Compartment: any;\n\nlockdown({\n consoleTaming: 'unsafe',\n errorTaming: 'unsafe',\n mathTaming: 'unsafe',\n dateTaming: 'unsafe',\n overrideTaming: 'severe',\n\n // TODO: See if there's an easier way to do this. This file is ran in a\n // separate process, so we can't mock SES with Jest.\n ...(process.env.NODE_ENV === 'test'\n ? {\n domainTaming: 'unsafe',\n }\n : {}),\n});\n\n/**\n * Get mock endowments that don't do anything. This is useful for running the\n * eval, for snaps that try to communicate with the extension on initialisation,\n * for example.\n *\n * @returns The mock endowments.\n */\nfunction getMockEndowments() {\n const endowments = generateMockEndowments();\n return {\n ...endowments,\n window: endowments,\n self: endowments,\n };\n}\n\nconst snapFilePath = process.argv[2];\n\nconst snapModule: { exports?: any } = { exports: {} };\n\nnew Compartment({\n ...getMockEndowments(),\n module: snapModule,\n exports: snapModule.exports,\n}).evaluate(readFileSync(snapFilePath, 'utf8'));\n\nconst invalidExports = Object.keys(snapModule.exports).filter(\n (snapExport) => !SNAP_EXPORT_NAMES.includes(snapExport as HandlerType),\n);\n\nif (invalidExports.length > 0) {\n // eslint-disable-next-line no-console\n console.warn(`Invalid snap exports detected:\\n${invalidExports.join('\\n')}`);\n}\n\nsetTimeout(() => process.exit(0), 1000); // Hack to ensure worker exits\n"]}
|
package/dist/eval.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.evalBundle = void 0;
|
|
4
|
+
const child_process_1 = require("child_process");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
const fs_1 = require("./fs");
|
|
7
|
+
/**
|
|
8
|
+
* Spawn a new process to run the provided bundle in.
|
|
9
|
+
*
|
|
10
|
+
* @param bundlePath - The path to the bundle to run.
|
|
11
|
+
* @returns `null` if the worker ran successfully.
|
|
12
|
+
* @throws If the worker failed to run successfully.
|
|
13
|
+
*/
|
|
14
|
+
async function evalBundle(bundlePath) {
|
|
15
|
+
await (0, fs_1.validateFilePath)(bundlePath);
|
|
16
|
+
return new Promise((resolve, reject) => {
|
|
17
|
+
const worker = (0, child_process_1.fork)((0, path_1.join)(__dirname, 'eval-worker.js'), [bundlePath]);
|
|
18
|
+
worker.on('exit', (exitCode) => {
|
|
19
|
+
if (exitCode === 0) {
|
|
20
|
+
return resolve(null);
|
|
21
|
+
}
|
|
22
|
+
return reject(new Error(`Process exited with non-zero exit code: ${exitCode}`));
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
exports.evalBundle = evalBundle;
|
|
27
|
+
//# sourceMappingURL=eval.js.map
|
package/dist/eval.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eval.js","sourceRoot":"","sources":["../src/eval.ts"],"names":[],"mappings":";;;AAAA,iDAAqC;AACrC,+BAA4B;AAE5B,6BAAwC;AAExC;;;;;;GAMG;AACI,KAAK,UAAU,UAAU,CAAC,UAAkB;IACjD,MAAM,IAAA,qBAAgB,EAAC,UAAU,CAAC,CAAC;IAEnC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,MAAM,MAAM,GAAG,IAAA,oBAAI,EAAC,IAAA,WAAI,EAAC,SAAS,EAAE,gBAAgB,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC;QAErE,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,QAAgB,EAAE,EAAE;YACrC,IAAI,QAAQ,KAAK,CAAC,EAAE;gBAClB,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC;aACtB;YAED,OAAO,MAAM,CACX,IAAI,KAAK,CAAC,2CAA2C,QAAQ,EAAE,CAAC,CACjE,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AAhBD,gCAgBC","sourcesContent":["import { fork } from 'child_process';\nimport { join } from 'path';\n\nimport { validateFilePath } from './fs';\n\n/**\n * Spawn a new process to run the provided bundle in.\n *\n * @param bundlePath - The path to the bundle to run.\n * @returns `null` if the worker ran successfully.\n * @throws If the worker failed to run successfully.\n */\nexport async function evalBundle(bundlePath: string): Promise<null> {\n await validateFilePath(bundlePath);\n\n return new Promise((resolve, reject) => {\n const worker = fork(join(__dirname, 'eval-worker.js'), [bundlePath]);\n\n worker.on('exit', (exitCode: number) => {\n if (exitCode === 0) {\n return resolve(null);\n }\n\n return reject(\n new Error(`Process exited with non-zero exit code: ${exitCode}`),\n );\n });\n });\n}\n"]}
|