@metamask/snaps-utils 8.0.0 → 8.1.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 +21 -1
- package/dist/array.cjs +17 -0
- package/dist/array.cjs.map +1 -0
- package/dist/array.d.cts +11 -0
- package/dist/array.d.cts.map +1 -0
- package/dist/array.d.mts +11 -0
- package/dist/array.d.mts.map +1 -0
- package/dist/array.mjs +12 -7
- package/dist/array.mjs.map +1 -1
- package/dist/auxiliary-files.cjs +39 -0
- package/dist/auxiliary-files.cjs.map +1 -0
- package/dist/auxiliary-files.d.cts +17 -0
- package/dist/auxiliary-files.d.cts.map +1 -0
- package/dist/auxiliary-files.d.mts +17 -0
- package/dist/auxiliary-files.d.mts.map +1 -0
- package/dist/auxiliary-files.mjs +33 -14
- package/dist/auxiliary-files.mjs.map +1 -1
- package/dist/base64.cjs +38 -0
- package/dist/base64.cjs.map +1 -0
- package/dist/base64.d.cts +16 -0
- package/dist/base64.d.cts.map +1 -0
- package/dist/base64.d.mts +16 -0
- package/dist/base64.d.mts.map +1 -0
- package/dist/base64.mjs +32 -12
- package/dist/base64.mjs.map +1 -1
- package/dist/bytes.cjs +22 -0
- package/dist/bytes.cjs.map +1 -0
- package/dist/bytes.d.cts +9 -0
- package/dist/bytes.d.cts.map +1 -0
- package/dist/bytes.d.mts +9 -0
- package/dist/bytes.d.mts.map +1 -0
- package/dist/bytes.mjs +17 -9
- package/dist/bytes.mjs.map +1 -1
- package/dist/caveats.cjs +51 -0
- package/dist/caveats.cjs.map +1 -0
- package/dist/caveats.d.cts +47 -0
- package/dist/caveats.d.cts.map +1 -0
- package/dist/caveats.d.mts +47 -0
- package/dist/caveats.d.mts.map +1 -0
- package/dist/caveats.mjs +47 -7
- package/dist/caveats.mjs.map +1 -1
- package/dist/checksum.cjs +49 -0
- package/dist/checksum.cjs.map +1 -0
- package/dist/checksum.d.cts +22 -0
- package/dist/checksum.d.cts.map +1 -0
- package/dist/checksum.d.mts +22 -0
- package/dist/checksum.d.mts.map +1 -0
- package/dist/checksum.mjs +43 -12
- package/dist/checksum.mjs.map +1 -1
- package/dist/constants.cjs +8 -0
- package/dist/constants.cjs.map +1 -0
- package/dist/constants.d.cts +2 -0
- package/dist/constants.d.cts.map +1 -0
- package/dist/constants.d.mts +2 -0
- package/dist/constants.d.mts.map +1 -0
- package/dist/constants.mjs +4 -7
- package/dist/constants.mjs.map +1 -1
- package/dist/cronjob.cjs +70 -0
- package/dist/cronjob.cjs.map +1 -0
- package/dist/cronjob.d.cts +90 -0
- package/dist/cronjob.d.cts.map +1 -0
- package/dist/cronjob.d.mts +90 -0
- package/dist/cronjob.d.mts.map +1 -0
- package/dist/cronjob.mjs +64 -19
- package/dist/cronjob.mjs.map +1 -1
- package/dist/deep-clone.cjs +9 -0
- package/dist/deep-clone.cjs.map +1 -0
- package/dist/deep-clone.d.cts +2 -0
- package/dist/deep-clone.d.cts.map +1 -0
- package/dist/deep-clone.d.mts +2 -0
- package/dist/deep-clone.d.mts.map +1 -0
- package/dist/deep-clone.mjs +9 -7
- package/dist/deep-clone.mjs.map +1 -1
- package/dist/default-endowments.cjs +42 -0
- package/dist/default-endowments.cjs.map +1 -0
- package/dist/default-endowments.d.cts +5 -0
- package/dist/default-endowments.d.cts.map +1 -0
- package/dist/default-endowments.d.mts +5 -0
- package/dist/default-endowments.d.mts.map +1 -0
- package/dist/default-endowments.mjs +38 -7
- package/dist/default-endowments.mjs.map +1 -1
- package/dist/derivation-paths.cjs +215 -0
- package/dist/derivation-paths.cjs.map +1 -0
- package/dist/derivation-paths.d.cts +25 -0
- package/dist/derivation-paths.d.cts.map +1 -0
- package/dist/derivation-paths.d.mts +25 -0
- package/dist/derivation-paths.d.mts.map +1 -0
- package/dist/derivation-paths.mjs +206 -12
- package/dist/derivation-paths.mjs.map +1 -1
- package/dist/entropy.cjs +8 -0
- package/dist/entropy.cjs.map +1 -0
- package/dist/entropy.d.cts +4 -0
- package/dist/entropy.d.cts.map +1 -0
- package/dist/entropy.d.mts +4 -0
- package/dist/entropy.d.mts.map +1 -0
- package/dist/entropy.mjs +4 -9
- package/dist/entropy.mjs.map +1 -1
- package/dist/errors.cjs +189 -0
- package/dist/errors.cjs.map +1 -0
- package/dist/errors.d.cts +85 -0
- package/dist/errors.d.cts.map +1 -0
- package/dist/errors.d.mts +85 -0
- package/dist/errors.d.mts.map +1 -0
- package/dist/errors.mjs +179 -18
- package/dist/errors.mjs.map +1 -1
- package/dist/eval-worker.cjs +42 -0
- package/dist/eval-worker.cjs.map +1 -0
- package/dist/eval-worker.d.cts +2 -0
- package/dist/eval-worker.d.cts.map +1 -0
- package/dist/eval-worker.d.mts +2 -0
- package/dist/eval-worker.d.mts.map +1 -0
- package/dist/eval-worker.mjs +28 -31
- package/dist/eval-worker.mjs.map +1 -1
- package/dist/eval.cjs +54 -0
- package/dist/eval.cjs.map +1 -0
- package/dist/eval.d.cts +17 -0
- package/dist/eval.d.cts.map +1 -0
- package/dist/eval.d.mts +17 -0
- package/dist/eval.d.mts.map +1 -0
- package/dist/eval.mjs +48 -16
- package/dist/eval.mjs.map +1 -1
- package/dist/fs.cjs +159 -0
- package/dist/fs.cjs.map +1 -0
- package/dist/fs.d.cts +70 -0
- package/dist/fs.d.cts.map +1 -0
- package/dist/fs.d.mts +70 -0
- package/dist/fs.d.mts.map +1 -0
- package/dist/fs.mjs +144 -27
- package/dist/fs.mjs.map +1 -1
- package/dist/handler-types.cjs +18 -0
- package/dist/handler-types.cjs.map +1 -0
- package/dist/handler-types.d.cts +35 -0
- package/dist/handler-types.d.cts.map +1 -0
- package/dist/handler-types.d.mts +35 -0
- package/dist/handler-types.d.mts.map +1 -0
- package/dist/handler-types.mjs +14 -9
- package/dist/handler-types.mjs.map +1 -1
- package/dist/handlers.cjs +119 -0
- package/dist/handlers.cjs.map +1 -0
- package/dist/handlers.d.cts +750 -0
- package/dist/handlers.d.cts.map +1 -0
- package/dist/handlers.d.mts +750 -0
- package/dist/handlers.d.mts.map +1 -0
- package/dist/handlers.mjs +114 -33
- package/dist/handlers.mjs.map +1 -1
- package/dist/icon.cjs +58 -0
- package/dist/icon.cjs.map +1 -0
- package/dist/icon.d.cts +20 -0
- package/dist/icon.d.cts.map +1 -0
- package/dist/icon.d.mts +20 -0
- package/dist/icon.d.mts.map +1 -0
- package/dist/icon.mjs +52 -14
- package/dist/icon.mjs.map +1 -1
- package/dist/iframe.cjs +54 -0
- package/dist/iframe.cjs.map +1 -0
- package/dist/iframe.d.cts +12 -0
- package/dist/iframe.d.cts.map +1 -0
- package/dist/iframe.d.mts +12 -0
- package/dist/iframe.d.mts.map +1 -0
- package/dist/iframe.mjs +49 -7
- package/dist/iframe.mjs.map +1 -1
- package/dist/iframe.test.browser.cjs +15 -0
- package/dist/iframe.test.browser.cjs.map +1 -0
- package/dist/iframe.test.browser.d.cts +2 -0
- package/dist/iframe.test.browser.d.cts.map +1 -0
- package/dist/iframe.test.browser.d.mts +2 -0
- package/dist/iframe.test.browser.d.mts.map +1 -0
- package/dist/iframe.test.browser.mjs +13 -0
- package/dist/iframe.test.browser.mjs.map +1 -0
- package/dist/index.cjs +49 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +33 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +33 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.executionenv.cjs +25 -0
- package/dist/index.executionenv.cjs.map +1 -0
- package/dist/index.executionenv.d.cts +8 -0
- package/dist/index.executionenv.d.cts.map +1 -0
- package/dist/index.executionenv.d.mts +8 -0
- package/dist/index.executionenv.d.mts.map +1 -0
- package/dist/index.executionenv.mjs +8 -127
- package/dist/index.executionenv.mjs.map +1 -1
- package/dist/index.mjs +32 -397
- package/dist/index.mjs.map +1 -1
- package/dist/json-rpc.cjs +135 -0
- package/dist/json-rpc.cjs.map +1 -0
- package/dist/json-rpc.d.cts +56 -0
- package/dist/json-rpc.d.cts.map +1 -0
- package/dist/json-rpc.d.mts +56 -0
- package/dist/json-rpc.d.mts.map +1 -0
- package/dist/json-rpc.mjs +127 -17
- package/dist/json-rpc.mjs.map +1 -1
- package/dist/json.cjs +34 -0
- package/dist/json.cjs.map +1 -0
- package/dist/json.d.cts +23 -0
- package/dist/json.d.cts.map +1 -0
- package/dist/json.d.mts +23 -0
- package/dist/json.d.mts.map +1 -0
- package/dist/json.mjs +28 -9
- package/dist/json.mjs.map +1 -1
- package/dist/localization.cjs +128 -0
- package/dist/localization.cjs.map +1 -0
- package/dist/localization.d.cts +146 -0
- package/dist/localization.d.cts.map +1 -0
- package/dist/localization.d.mts +146 -0
- package/dist/localization.d.mts.map +1 -0
- package/dist/localization.mjs +119 -22
- package/dist/localization.mjs.map +1 -1
- package/dist/logging.cjs +67 -0
- package/dist/logging.cjs.map +1 -0
- package/dist/logging.d.cts +50 -0
- package/dist/logging.d.cts.map +1 -0
- package/dist/logging.d.mts +50 -0
- package/dist/logging.d.mts.map +1 -0
- package/dist/logging.mjs +60 -13
- package/dist/logging.mjs.map +1 -1
- package/dist/manifest/index.cjs +18 -0
- package/dist/manifest/index.cjs.map +1 -0
- package/dist/manifest/index.d.cts +2 -0
- package/dist/manifest/index.d.cts.map +1 -0
- package/dist/manifest/index.d.mts +2 -0
- package/dist/manifest/index.d.mts.map +1 -0
- package/dist/manifest/index.mjs +1 -64
- package/dist/manifest/index.mjs.map +1 -1
- package/dist/manifest/manifest.cjs +267 -0
- package/dist/manifest/manifest.cjs.map +1 -0
- package/dist/manifest/manifest.d.cts +100 -0
- package/dist/manifest/manifest.d.cts.map +1 -0
- package/dist/manifest/manifest.d.mts +100 -0
- package/dist/manifest/manifest.d.mts.map +1 -0
- package/dist/manifest/manifest.mjs +252 -57
- package/dist/manifest/manifest.mjs.map +1 -1
- package/dist/manifest/node.cjs +19 -0
- package/dist/manifest/node.cjs.map +1 -0
- package/dist/manifest/node.d.cts +3 -0
- package/dist/manifest/node.d.cts.map +1 -0
- package/dist/manifest/node.d.mts +3 -0
- package/dist/manifest/node.d.mts.map +1 -0
- package/dist/manifest/node.mjs +2 -105
- package/dist/manifest/node.mjs.map +1 -1
- package/dist/manifest/validation.cjs +194 -0
- package/dist/manifest/validation.cjs.map +1 -0
- package/dist/manifest/validation.d.cts +254 -0
- package/dist/manifest/validation.d.cts.map +1 -0
- package/dist/manifest/validation.d.mts +254 -0
- package/dist/manifest/validation.d.mts.map +1 -0
- package/dist/manifest/validation.mjs +186 -63
- package/dist/manifest/validation.mjs.map +1 -1
- package/dist/manifest/validator-types.cjs +3 -0
- package/dist/manifest/validator-types.cjs.map +1 -0
- package/dist/manifest/validator-types.d.cts +35 -0
- package/dist/manifest/validator-types.d.cts.map +1 -0
- package/dist/manifest/validator-types.d.mts +35 -0
- package/dist/manifest/validator-types.d.mts.map +1 -0
- package/dist/manifest/validator-types.mjs +1 -0
- package/dist/manifest/validator-types.mjs.map +1 -1
- package/dist/manifest/validator.cjs +109 -0
- package/dist/manifest/validator.cjs.map +1 -0
- package/dist/manifest/validator.d.cts +24 -0
- package/dist/manifest/validator.d.cts.map +1 -0
- package/dist/manifest/validator.d.mts +24 -0
- package/dist/manifest/validator.d.mts.map +1 -0
- package/dist/manifest/validator.mjs +79 -42
- package/dist/manifest/validator.mjs.map +1 -1
- package/dist/manifest/validators/checksum.cjs +23 -0
- package/dist/manifest/validators/checksum.cjs.map +1 -0
- package/dist/manifest/validators/checksum.d.cts +6 -0
- package/dist/manifest/validators/checksum.d.cts.map +1 -0
- package/dist/manifest/validators/checksum.d.mts +6 -0
- package/dist/manifest/validators/checksum.d.mts.map +1 -0
- package/dist/manifest/validators/checksum.mjs +18 -13
- package/dist/manifest/validators/checksum.mjs.map +1 -1
- package/dist/manifest/validators/expected-files.cjs +24 -0
- package/dist/manifest/validators/expected-files.cjs.map +1 -0
- package/dist/manifest/validators/expected-files.d.cts +6 -0
- package/dist/manifest/validators/expected-files.d.cts.map +1 -0
- package/dist/manifest/validators/expected-files.d.mts +6 -0
- package/dist/manifest/validators/expected-files.d.mts.map +1 -0
- package/dist/manifest/validators/expected-files.mjs +19 -7
- package/dist/manifest/validators/expected-files.mjs.map +1 -1
- package/dist/manifest/validators/icon-declared.cjs +15 -0
- package/dist/manifest/validators/icon-declared.cjs.map +1 -0
- package/dist/manifest/validators/icon-declared.d.cts +6 -0
- package/dist/manifest/validators/icon-declared.d.cts.map +1 -0
- package/dist/manifest/validators/icon-declared.d.mts +6 -0
- package/dist/manifest/validators/icon-declared.d.mts.map +1 -0
- package/dist/manifest/validators/icon-declared.mjs +10 -6
- package/dist/manifest/validators/icon-declared.mjs.map +1 -1
- package/dist/manifest/validators/icon-dimensions.cjs +20 -0
- package/dist/manifest/validators/icon-dimensions.cjs.map +1 -0
- package/dist/manifest/validators/icon-dimensions.d.cts +6 -0
- package/dist/manifest/validators/icon-dimensions.d.cts.map +1 -0
- package/dist/manifest/validators/icon-dimensions.d.mts +6 -0
- package/dist/manifest/validators/icon-dimensions.d.mts.map +1 -0
- package/dist/manifest/validators/icon-dimensions.mjs +15 -8
- package/dist/manifest/validators/icon-dimensions.mjs.map +1 -1
- package/dist/manifest/validators/icon-missing.cjs +16 -0
- package/dist/manifest/validators/icon-missing.cjs.map +1 -0
- package/dist/manifest/validators/icon-missing.d.cts +6 -0
- package/dist/manifest/validators/icon-missing.d.cts.map +1 -0
- package/dist/manifest/validators/icon-missing.d.mts +6 -0
- package/dist/manifest/validators/icon-missing.d.mts.map +1 -0
- package/dist/manifest/validators/icon-missing.mjs +11 -6
- package/dist/manifest/validators/icon-missing.mjs.map +1 -1
- package/dist/manifest/validators/index.cjs +31 -0
- package/dist/manifest/validators/index.cjs.map +1 -0
- package/dist/manifest/validators/index.d.cts +15 -0
- package/dist/manifest/validators/index.d.cts.map +1 -0
- package/dist/manifest/validators/index.d.mts +15 -0
- package/dist/manifest/validators/index.d.mts.map +1 -0
- package/dist/manifest/validators/index.mjs +14 -79
- package/dist/manifest/validators/index.mjs.map +1 -1
- package/dist/manifest/validators/is-localization-file.cjs +23 -0
- package/dist/manifest/validators/is-localization-file.cjs.map +1 -0
- package/dist/manifest/validators/is-localization-file.d.cts +6 -0
- package/dist/manifest/validators/is-localization-file.d.cts.map +1 -0
- package/dist/manifest/validators/is-localization-file.d.mts +6 -0
- package/dist/manifest/validators/is-localization-file.d.mts.map +1 -0
- package/dist/manifest/validators/is-localization-file.mjs +18 -10
- package/dist/manifest/validators/is-localization-file.mjs.map +1 -1
- package/dist/manifest/validators/is-package-json.cjs +24 -0
- package/dist/manifest/validators/is-package-json.cjs.map +1 -0
- package/dist/manifest/validators/is-package-json.d.cts +6 -0
- package/dist/manifest/validators/is-package-json.d.cts.map +1 -0
- package/dist/manifest/validators/is-package-json.d.mts +6 -0
- package/dist/manifest/validators/is-package-json.d.mts.map +1 -0
- package/dist/manifest/validators/is-package-json.mjs +19 -9
- package/dist/manifest/validators/is-package-json.mjs.map +1 -1
- package/dist/manifest/validators/is-snap-icon.cjs +24 -0
- package/dist/manifest/validators/is-snap-icon.cjs.map +1 -0
- package/dist/manifest/validators/is-snap-icon.d.cts +6 -0
- package/dist/manifest/validators/is-snap-icon.d.cts.map +1 -0
- package/dist/manifest/validators/is-snap-icon.d.mts +6 -0
- package/dist/manifest/validators/is-snap-icon.d.mts.map +1 -0
- package/dist/manifest/validators/is-snap-icon.mjs +19 -8
- package/dist/manifest/validators/is-snap-icon.mjs.map +1 -1
- package/dist/manifest/validators/is-snap-manifest.cjs +25 -0
- package/dist/manifest/validators/is-snap-manifest.cjs.map +1 -0
- package/dist/manifest/validators/is-snap-manifest.d.cts +6 -0
- package/dist/manifest/validators/is-snap-manifest.d.cts.map +1 -0
- package/dist/manifest/validators/is-snap-manifest.d.mts +6 -0
- package/dist/manifest/validators/is-snap-manifest.d.mts.map +1 -0
- package/dist/manifest/validators/is-snap-manifest.mjs +20 -21
- package/dist/manifest/validators/is-snap-manifest.mjs.map +1 -1
- package/dist/manifest/validators/manifest-localization.cjs +30 -0
- package/dist/manifest/validators/manifest-localization.cjs.map +1 -0
- package/dist/manifest/validators/manifest-localization.d.cts +6 -0
- package/dist/manifest/validators/manifest-localization.d.cts.map +1 -0
- package/dist/manifest/validators/manifest-localization.d.mts +6 -0
- package/dist/manifest/validators/manifest-localization.d.mts.map +1 -0
- package/dist/manifest/validators/manifest-localization.mjs +25 -8
- package/dist/manifest/validators/manifest-localization.mjs.map +1 -1
- package/dist/manifest/validators/package-json-recommended-fields.cjs +18 -0
- package/dist/manifest/validators/package-json-recommended-fields.cjs.map +1 -0
- package/dist/manifest/validators/package-json-recommended-fields.d.cts +6 -0
- package/dist/manifest/validators/package-json-recommended-fields.d.cts.map +1 -0
- package/dist/manifest/validators/package-json-recommended-fields.d.mts +6 -0
- package/dist/manifest/validators/package-json-recommended-fields.d.mts.map +1 -0
- package/dist/manifest/validators/package-json-recommended-fields.mjs +13 -6
- package/dist/manifest/validators/package-json-recommended-fields.mjs.map +1 -1
- package/dist/manifest/validators/package-name-match.cjs +21 -0
- package/dist/manifest/validators/package-name-match.cjs.map +1 -0
- package/dist/manifest/validators/package-name-match.d.cts +6 -0
- package/dist/manifest/validators/package-name-match.d.cts.map +1 -0
- package/dist/manifest/validators/package-name-match.d.mts +6 -0
- package/dist/manifest/validators/package-name-match.d.mts.map +1 -0
- package/dist/manifest/validators/package-name-match.mjs +16 -7
- package/dist/manifest/validators/package-name-match.mjs.map +1 -1
- package/dist/manifest/validators/repository-match.cjs +29 -0
- package/dist/manifest/validators/repository-match.cjs.map +1 -0
- package/dist/manifest/validators/repository-match.d.cts +6 -0
- package/dist/manifest/validators/repository-match.d.cts.map +1 -0
- package/dist/manifest/validators/repository-match.d.mts +6 -0
- package/dist/manifest/validators/repository-match.d.mts.map +1 -0
- package/dist/manifest/validators/repository-match.mjs +28 -8
- package/dist/manifest/validators/repository-match.mjs.map +1 -1
- package/dist/manifest/validators/version-match.cjs +21 -0
- package/dist/manifest/validators/version-match.cjs.map +1 -0
- package/dist/manifest/validators/version-match.d.cts +6 -0
- package/dist/manifest/validators/version-match.d.cts.map +1 -0
- package/dist/manifest/validators/version-match.d.mts +6 -0
- package/dist/manifest/validators/version-match.d.mts.map +1 -0
- package/dist/manifest/validators/version-match.mjs +16 -7
- package/dist/manifest/validators/version-match.mjs.map +1 -1
- package/dist/mock.cjs +113 -0
- package/dist/mock.cjs.map +1 -0
- package/dist/mock.d.cts +15 -0
- package/dist/mock.d.cts.map +1 -0
- package/dist/mock.d.mts +15 -0
- package/dist/mock.d.mts.map +1 -0
- package/dist/mock.mjs +103 -11
- package/dist/mock.mjs.map +1 -1
- package/dist/namespace.cjs +136 -0
- package/dist/namespace.cjs.map +1 -0
- package/dist/namespace.d.cts +130 -0
- package/dist/namespace.d.cts.map +1 -0
- package/dist/namespace.d.mts +130 -0
- package/dist/namespace.d.mts.map +1 -0
- package/dist/namespace.mjs +125 -43
- package/dist/namespace.mjs.map +1 -1
- package/dist/node.cjs +25 -0
- package/dist/node.cjs.map +1 -0
- package/dist/node.d.cts +8 -0
- package/dist/node.d.cts.map +1 -0
- package/dist/node.d.mts +8 -0
- package/dist/node.d.mts.map +1 -0
- package/dist/node.mjs +8 -475
- package/dist/node.mjs.map +1 -1
- package/dist/path.cjs +21 -0
- package/dist/path.cjs.map +1 -0
- package/dist/path.d.cts +8 -0
- package/dist/path.d.cts.map +1 -0
- package/dist/path.d.mts +8 -0
- package/dist/path.d.mts.map +1 -0
- package/dist/path.mjs +16 -7
- package/dist/path.mjs.map +1 -1
- package/dist/post-process.cjs +339 -0
- package/dist/post-process.cjs.map +1 -0
- package/dist/post-process.d.cts +72 -0
- package/dist/post-process.d.cts.map +1 -0
- package/dist/post-process.d.mts +72 -0
- package/dist/post-process.d.mts.map +1 -0
- package/dist/post-process.mjs +335 -9
- package/dist/post-process.mjs.map +1 -1
- package/dist/promise.cjs +3 -0
- package/dist/promise.cjs.map +1 -0
- package/dist/promise.d.cts +2 -0
- package/dist/promise.d.cts.map +1 -0
- package/dist/promise.d.mts +2 -0
- package/dist/promise.d.mts.map +1 -0
- package/dist/promise.mjs +1 -1
- package/dist/promise.mjs.map +1 -1
- package/dist/snaps.cjs +207 -0
- package/dist/snaps.cjs.map +1 -0
- package/dist/snaps.d.cts +170 -0
- package/dist/snaps.d.cts.map +1 -0
- package/dist/snaps.d.mts +170 -0
- package/dist/snaps.d.mts.map +1 -0
- package/dist/snaps.mjs +200 -45
- package/dist/snaps.mjs.map +1 -1
- package/dist/strings.cjs +15 -0
- package/dist/strings.cjs.map +1 -0
- package/dist/strings.d.cts +9 -0
- package/dist/strings.d.cts.map +1 -0
- package/dist/strings.d.mts +9 -0
- package/dist/strings.d.mts.map +1 -0
- package/dist/strings.mjs +10 -7
- package/dist/strings.mjs.map +1 -1
- package/dist/structs.cjs +316 -0
- package/dist/structs.cjs.map +1 -0
- package/dist/structs.d.cts +181 -0
- package/dist/structs.d.cts.map +1 -0
- package/dist/structs.d.mts +181 -0
- package/dist/structs.d.mts.map +1 -0
- package/dist/structs.mjs +300 -32
- package/dist/structs.mjs.map +1 -1
- package/dist/svg.cjs +49 -0
- package/dist/svg.cjs.map +1 -0
- package/dist/svg.d.cts +15 -0
- package/dist/svg.d.cts.map +1 -0
- package/dist/svg.d.mts +15 -0
- package/dist/svg.d.mts.map +1 -0
- package/dist/svg.mjs +43 -9
- package/dist/svg.mjs.map +1 -1
- package/dist/types.cjs +64 -0
- package/dist/types.cjs.map +1 -0
- package/dist/types.d.cts +104 -0
- package/dist/types.d.cts.map +1 -0
- package/dist/types.d.mts +104 -0
- package/dist/types.d.mts.map +1 -0
- package/dist/types.mjs +58 -21
- package/dist/types.mjs.map +1 -1
- package/dist/ui.cjs +405 -0
- package/dist/ui.cjs.map +1 -0
- package/dist/ui.d.cts +93 -0
- package/dist/ui.d.cts.map +1 -0
- package/dist/ui.d.mts +93 -0
- package/dist/ui.d.mts.map +1 -0
- package/dist/ui.mjs +391 -23
- package/dist/ui.mjs.map +1 -1
- package/dist/validation.cjs +23 -0
- package/dist/validation.cjs.map +1 -0
- package/dist/validation.d.cts +9 -0
- package/dist/validation.d.cts.map +1 -0
- package/dist/validation.d.mts +9 -0
- package/dist/validation.d.mts.map +1 -0
- package/dist/validation.mjs +18 -26
- package/dist/validation.mjs.map +1 -1
- package/dist/versions.cjs +44 -0
- package/dist/versions.cjs.map +1 -0
- package/dist/versions.d.cts +22 -0
- package/dist/versions.d.cts.map +1 -0
- package/dist/versions.d.mts +22 -0
- package/dist/versions.d.mts.map +1 -0
- package/dist/versions.mjs +38 -11
- package/dist/versions.mjs.map +1 -1
- package/dist/virtual-file/VirtualFile.cjs +75 -0
- package/dist/virtual-file/VirtualFile.cjs.map +1 -0
- package/dist/virtual-file/VirtualFile.d.cts +35 -0
- package/dist/virtual-file/VirtualFile.d.cts.map +1 -0
- package/dist/virtual-file/VirtualFile.d.mts +35 -0
- package/dist/virtual-file/VirtualFile.d.mts.map +1 -0
- package/dist/virtual-file/VirtualFile.mjs +70 -8
- package/dist/virtual-file/VirtualFile.mjs.map +1 -1
- package/dist/virtual-file/index.cjs +18 -0
- package/dist/virtual-file/index.cjs.map +1 -0
- package/dist/virtual-file/index.d.cts +2 -0
- package/dist/virtual-file/index.d.cts.map +1 -0
- package/dist/virtual-file/index.d.mts +2 -0
- package/dist/virtual-file/index.d.mts.map +1 -0
- package/dist/virtual-file/index.mjs +1 -9
- package/dist/virtual-file/index.mjs.map +1 -1
- package/dist/virtual-file/node.cjs +19 -0
- package/dist/virtual-file/node.cjs.map +1 -0
- package/dist/virtual-file/node.d.cts +3 -0
- package/dist/virtual-file/node.d.cts.map +1 -0
- package/dist/virtual-file/node.d.mts +3 -0
- package/dist/virtual-file/node.d.mts.map +1 -0
- package/dist/virtual-file/node.mjs +2 -16
- package/dist/virtual-file/node.mjs.map +1 -1
- package/dist/virtual-file/toVirtualFile.cjs +31 -0
- package/dist/virtual-file/toVirtualFile.cjs.map +1 -0
- package/dist/virtual-file/toVirtualFile.d.cts +24 -0
- package/dist/virtual-file/toVirtualFile.d.cts.map +1 -0
- package/dist/virtual-file/toVirtualFile.d.mts +24 -0
- package/dist/virtual-file/toVirtualFile.d.mts.map +1 -0
- package/dist/virtual-file/toVirtualFile.mjs +25 -11
- package/dist/virtual-file/toVirtualFile.mjs.map +1 -1
- package/package.json +37 -25
- package/dist/array.js +0 -8
- package/dist/array.js.map +0 -1
- package/dist/auxiliary-files.js +0 -15
- package/dist/auxiliary-files.js.map +0 -1
- package/dist/base64.js +0 -13
- package/dist/base64.js.map +0 -1
- package/dist/bytes.js +0 -10
- package/dist/bytes.js.map +0 -1
- package/dist/caveats.js +0 -8
- package/dist/caveats.js.map +0 -1
- package/dist/checksum.js +0 -13
- package/dist/checksum.js.map +0 -1
- package/dist/chunk-37EUH3KZ.js +0 -293
- package/dist/chunk-37EUH3KZ.js.map +0 -1
- package/dist/chunk-3N27GIUS.mjs +0 -229
- package/dist/chunk-3N27GIUS.mjs.map +0 -1
- package/dist/chunk-3OXW5H4F.js +0 -30
- package/dist/chunk-3OXW5H4F.js.map +0 -1
- package/dist/chunk-3RFGTBEP.js +0 -151
- package/dist/chunk-3RFGTBEP.js.map +0 -1
- package/dist/chunk-3RUWAMJT.mjs +0 -31
- package/dist/chunk-3RUWAMJT.mjs.map +0 -1
- package/dist/chunk-3S4INAGA.mjs +0 -18
- package/dist/chunk-3S4INAGA.mjs.map +0 -1
- package/dist/chunk-44VFHYJO.js +0 -249
- package/dist/chunk-44VFHYJO.js.map +0 -1
- package/dist/chunk-4AA3TKRJ.mjs +0 -153
- package/dist/chunk-4AA3TKRJ.mjs.map +0 -1
- package/dist/chunk-4BGZ2CHC.mjs +0 -22
- package/dist/chunk-4BGZ2CHC.mjs.map +0 -1
- package/dist/chunk-4CMD46B2.js +0 -1
- package/dist/chunk-4CMD46B2.js.map +0 -1
- package/dist/chunk-4RYTYEUQ.mjs +0 -33
- package/dist/chunk-4RYTYEUQ.mjs.map +0 -1
- package/dist/chunk-4ZJOU3LR.js +0 -71
- package/dist/chunk-4ZJOU3LR.js.map +0 -1
- package/dist/chunk-53QXTM77.js +0 -229
- package/dist/chunk-53QXTM77.js.map +0 -1
- package/dist/chunk-5FTBWYCW.mjs +0 -27
- package/dist/chunk-5FTBWYCW.mjs.map +0 -1
- package/dist/chunk-5MABKEV7.mjs +0 -66
- package/dist/chunk-5MABKEV7.mjs.map +0 -1
- package/dist/chunk-5R7UF7KM.mjs +0 -21
- package/dist/chunk-5R7UF7KM.mjs.map +0 -1
- package/dist/chunk-5UAPBOKO.js +0 -37
- package/dist/chunk-5UAPBOKO.js.map +0 -1
- package/dist/chunk-5WKQI22S.js +0 -7
- package/dist/chunk-5WKQI22S.js.map +0 -1
- package/dist/chunk-63OXILAY.mjs +0 -69
- package/dist/chunk-63OXILAY.mjs.map +0 -1
- package/dist/chunk-6ATNGN44.js +0 -300
- package/dist/chunk-6ATNGN44.js.map +0 -1
- package/dist/chunk-6HXIPMBN.js +0 -103
- package/dist/chunk-6HXIPMBN.js.map +0 -1
- package/dist/chunk-6YJWU77L.js +0 -19
- package/dist/chunk-6YJWU77L.js.map +0 -1
- package/dist/chunk-7HLSXEHK.mjs +0 -300
- package/dist/chunk-7HLSXEHK.mjs.map +0 -1
- package/dist/chunk-7LG4D4XA.mjs +0 -20
- package/dist/chunk-7LG4D4XA.mjs.map +0 -1
- package/dist/chunk-7P62OIGX.js +0 -69
- package/dist/chunk-7P62OIGX.js.map +0 -1
- package/dist/chunk-7T7FYH77.mjs +0 -37
- package/dist/chunk-7T7FYH77.mjs.map +0 -1
- package/dist/chunk-7VJ2BOVU.js +0 -15
- package/dist/chunk-7VJ2BOVU.js.map +0 -1
- package/dist/chunk-A3RRMELT.mjs +0 -1
- package/dist/chunk-A3RRMELT.mjs.map +0 -1
- package/dist/chunk-AMW2VJ3N.js +0 -32
- package/dist/chunk-AMW2VJ3N.js.map +0 -1
- package/dist/chunk-ANYNWSCA.mjs +0 -104
- package/dist/chunk-ANYNWSCA.mjs.map +0 -1
- package/dist/chunk-AOGVLPQZ.js +0 -18
- package/dist/chunk-AOGVLPQZ.js.map +0 -1
- package/dist/chunk-AS5P6JRP.mjs +0 -9
- package/dist/chunk-AS5P6JRP.mjs.map +0 -1
- package/dist/chunk-ASZWZ7JT.js +0 -20
- package/dist/chunk-ASZWZ7JT.js.map +0 -1
- package/dist/chunk-B5GNTDE2.js +0 -109
- package/dist/chunk-B5GNTDE2.js.map +0 -1
- package/dist/chunk-BGSO2GQC.mjs +0 -41
- package/dist/chunk-BGSO2GQC.mjs.map +0 -1
- package/dist/chunk-BPK5BH7K.js +0 -27
- package/dist/chunk-BPK5BH7K.js.map +0 -1
- package/dist/chunk-CJK7DDV2.mjs +0 -109
- package/dist/chunk-CJK7DDV2.mjs.map +0 -1
- package/dist/chunk-CPG2UGAA.js +0 -25
- package/dist/chunk-CPG2UGAA.js.map +0 -1
- package/dist/chunk-DE22V5AO.mjs +0 -53
- package/dist/chunk-DE22V5AO.mjs.map +0 -1
- package/dist/chunk-DEQUNIME.js +0 -53
- package/dist/chunk-DEQUNIME.js.map +0 -1
- package/dist/chunk-DKO64Y4H.mjs +0 -27
- package/dist/chunk-DKO64Y4H.mjs.map +0 -1
- package/dist/chunk-E3BDBG6T.js +0 -20
- package/dist/chunk-E3BDBG6T.js.map +0 -1
- package/dist/chunk-EFRPCO3C.js +0 -1
- package/dist/chunk-EFRPCO3C.js.map +0 -1
- package/dist/chunk-EVHDXNOC.mjs +0 -35
- package/dist/chunk-EVHDXNOC.mjs.map +0 -1
- package/dist/chunk-EYWMVDCD.mjs +0 -25
- package/dist/chunk-EYWMVDCD.mjs.map +0 -1
- package/dist/chunk-FA4QIZH6.js +0 -1
- package/dist/chunk-FA4QIZH6.js.map +0 -1
- package/dist/chunk-FBZ5SU7X.js +0 -189
- package/dist/chunk-FBZ5SU7X.js.map +0 -1
- package/dist/chunk-GIVJAZ2Q.mjs +0 -248
- package/dist/chunk-GIVJAZ2Q.mjs.map +0 -1
- package/dist/chunk-GJAVOB7B.js +0 -24
- package/dist/chunk-GJAVOB7B.js.map +0 -1
- package/dist/chunk-GXSTPU7D.mjs +0 -293
- package/dist/chunk-GXSTPU7D.mjs.map +0 -1
- package/dist/chunk-HY4W6BUH.mjs +0 -24
- package/dist/chunk-HY4W6BUH.mjs.map +0 -1
- package/dist/chunk-HYF7Q6VY.mjs +0 -1
- package/dist/chunk-HYF7Q6VY.mjs.map +0 -1
- package/dist/chunk-I2SWLZ34.js +0 -30
- package/dist/chunk-I2SWLZ34.js.map +0 -1
- package/dist/chunk-IELPPZJP.mjs +0 -189
- package/dist/chunk-IELPPZJP.mjs.map +0 -1
- package/dist/chunk-IJX3CXOY.js +0 -9
- package/dist/chunk-IJX3CXOY.js.map +0 -1
- package/dist/chunk-IPUL74MZ.mjs +0 -30
- package/dist/chunk-IPUL74MZ.mjs.map +0 -1
- package/dist/chunk-IV3FSWZ7.mjs +0 -9
- package/dist/chunk-IV3FSWZ7.mjs.map +0 -1
- package/dist/chunk-IVDERT5W.js +0 -22
- package/dist/chunk-IVDERT5W.js.map +0 -1
- package/dist/chunk-JETPRED3.js +0 -248
- package/dist/chunk-JETPRED3.js.map +0 -1
- package/dist/chunk-JI5NQ2C3.mjs +0 -1
- package/dist/chunk-JI5NQ2C3.mjs.map +0 -1
- package/dist/chunk-JJTIVHFX.mjs +0 -38
- package/dist/chunk-JJTIVHFX.mjs.map +0 -1
- package/dist/chunk-L2DHOOBX.js +0 -33
- package/dist/chunk-L2DHOOBX.js.map +0 -1
- package/dist/chunk-LEKZPKS2.js +0 -21
- package/dist/chunk-LEKZPKS2.js.map +0 -1
- package/dist/chunk-LHQP7CUJ.mjs +0 -107
- package/dist/chunk-LHQP7CUJ.mjs.map +0 -1
- package/dist/chunk-LOJA2ZS4.js +0 -107
- package/dist/chunk-LOJA2ZS4.js.map +0 -1
- package/dist/chunk-LQSEBGOX.js +0 -34
- package/dist/chunk-LQSEBGOX.js.map +0 -1
- package/dist/chunk-MDOG3S4V.mjs +0 -34
- package/dist/chunk-MDOG3S4V.mjs.map +0 -1
- package/dist/chunk-MFGLB75H.mjs +0 -22
- package/dist/chunk-MFGLB75H.mjs.map +0 -1
- package/dist/chunk-MKFQAXRF.js +0 -21
- package/dist/chunk-MKFQAXRF.js.map +0 -1
- package/dist/chunk-MQURBEO4.mjs +0 -16
- package/dist/chunk-MQURBEO4.mjs.map +0 -1
- package/dist/chunk-MWAZGSRO.js +0 -75
- package/dist/chunk-MWAZGSRO.js.map +0 -1
- package/dist/chunk-N2JAYIUP.mjs +0 -75
- package/dist/chunk-N2JAYIUP.mjs.map +0 -1
- package/dist/chunk-N4MA537G.js +0 -22
- package/dist/chunk-N4MA537G.js.map +0 -1
- package/dist/chunk-N5HVDE3P.mjs +0 -30
- package/dist/chunk-N5HVDE3P.mjs.map +0 -1
- package/dist/chunk-N722KRZW.js +0 -41
- package/dist/chunk-N722KRZW.js.map +0 -1
- package/dist/chunk-NNYGTNHP.mjs +0 -1
- package/dist/chunk-NNYGTNHP.mjs.map +0 -1
- package/dist/chunk-NSVVZNSD.mjs +0 -183
- package/dist/chunk-NSVVZNSD.mjs.map +0 -1
- package/dist/chunk-NUCLSR2G.js +0 -8
- package/dist/chunk-NUCLSR2G.js.map +0 -1
- package/dist/chunk-OBN2WDFU.js +0 -38
- package/dist/chunk-OBN2WDFU.js.map +0 -1
- package/dist/chunk-P252LKUT.mjs +0 -9
- package/dist/chunk-P252LKUT.mjs.map +0 -1
- package/dist/chunk-PAOTMYIM.mjs +0 -69
- package/dist/chunk-PAOTMYIM.mjs.map +0 -1
- package/dist/chunk-PJMEJVOB.mjs +0 -29
- package/dist/chunk-PJMEJVOB.mjs.map +0 -1
- package/dist/chunk-PLBSSUVY.js +0 -29
- package/dist/chunk-PLBSSUVY.js.map +0 -1
- package/dist/chunk-PLNIERDY.js +0 -34
- package/dist/chunk-PLNIERDY.js.map +0 -1
- package/dist/chunk-PO5BBHHX.mjs +0 -22
- package/dist/chunk-PO5BBHHX.mjs.map +0 -1
- package/dist/chunk-PTOH2SVI.mjs +0 -55
- package/dist/chunk-PTOH2SVI.mjs.map +0 -1
- package/dist/chunk-PZF4KWU2.mjs +0 -151
- package/dist/chunk-PZF4KWU2.mjs.map +0 -1
- package/dist/chunk-QD3LTING.js +0 -34
- package/dist/chunk-QD3LTING.js.map +0 -1
- package/dist/chunk-QGCNQRIQ.js +0 -35
- package/dist/chunk-QGCNQRIQ.js.map +0 -1
- package/dist/chunk-QYPLUMB7.mjs +0 -249
- package/dist/chunk-QYPLUMB7.mjs.map +0 -1
- package/dist/chunk-RAZ7XG4Z.mjs +0 -1
- package/dist/chunk-RAZ7XG4Z.mjs.map +0 -1
- package/dist/chunk-RNMJQSVQ.js +0 -69
- package/dist/chunk-RNMJQSVQ.js.map +0 -1
- package/dist/chunk-RRFKK45V.mjs +0 -15
- package/dist/chunk-RRFKK45V.mjs.map +0 -1
- package/dist/chunk-S3BWTUTZ.js +0 -31
- package/dist/chunk-S3BWTUTZ.js.map +0 -1
- package/dist/chunk-SKKANJ45.mjs +0 -19
- package/dist/chunk-SKKANJ45.mjs.map +0 -1
- package/dist/chunk-SPCIIRSB.mjs +0 -7
- package/dist/chunk-SPCIIRSB.mjs.map +0 -1
- package/dist/chunk-SRMDDOVO.mjs +0 -20
- package/dist/chunk-SRMDDOVO.mjs.map +0 -1
- package/dist/chunk-SYYDKPK3.js +0 -15
- package/dist/chunk-SYYDKPK3.js.map +0 -1
- package/dist/chunk-T2VA4YJE.js +0 -104
- package/dist/chunk-T2VA4YJE.js.map +0 -1
- package/dist/chunk-T3VM5YXY.js +0 -1
- package/dist/chunk-T3VM5YXY.js.map +0 -1
- package/dist/chunk-T3YY4JIJ.js +0 -9
- package/dist/chunk-T3YY4JIJ.js.map +0 -1
- package/dist/chunk-T5ZOOZ46.js +0 -22
- package/dist/chunk-T5ZOOZ46.js.map +0 -1
- package/dist/chunk-TAMKWZ4E.js +0 -183
- package/dist/chunk-TAMKWZ4E.js.map +0 -1
- package/dist/chunk-TFP64TMV.js +0 -1
- package/dist/chunk-TFP64TMV.js.map +0 -1
- package/dist/chunk-TYWGZIOF.mjs +0 -34
- package/dist/chunk-TYWGZIOF.mjs.map +0 -1
- package/dist/chunk-UAINMOUU.js +0 -18
- package/dist/chunk-UAINMOUU.js.map +0 -1
- package/dist/chunk-UNNEBOL4.mjs +0 -15
- package/dist/chunk-UNNEBOL4.mjs.map +0 -1
- package/dist/chunk-UW74NLTC.mjs +0 -18
- package/dist/chunk-UW74NLTC.mjs.map +0 -1
- package/dist/chunk-VBYSWMSU.js +0 -66
- package/dist/chunk-VBYSWMSU.js.map +0 -1
- package/dist/chunk-VEPYH26P.js +0 -27
- package/dist/chunk-VEPYH26P.js.map +0 -1
- package/dist/chunk-VIAHMNTA.mjs +0 -34
- package/dist/chunk-VIAHMNTA.mjs.map +0 -1
- package/dist/chunk-VWLBM7XM.js +0 -1
- package/dist/chunk-VWLBM7XM.js.map +0 -1
- package/dist/chunk-W7A3BYUP.mjs +0 -1
- package/dist/chunk-W7A3BYUP.mjs.map +0 -1
- package/dist/chunk-W7KRIAIX.js +0 -55
- package/dist/chunk-W7KRIAIX.js.map +0 -1
- package/dist/chunk-X2GGUOMY.js +0 -153
- package/dist/chunk-X2GGUOMY.js.map +0 -1
- package/dist/chunk-X3UZCGO5.mjs +0 -103
- package/dist/chunk-X3UZCGO5.mjs.map +0 -1
- package/dist/chunk-XF2AZMWG.mjs +0 -32
- package/dist/chunk-XF2AZMWG.mjs.map +0 -1
- package/dist/chunk-XWYJQWHG.js +0 -56
- package/dist/chunk-XWYJQWHG.js.map +0 -1
- package/dist/chunk-XZ7362GQ.mjs +0 -63
- package/dist/chunk-XZ7362GQ.mjs.map +0 -1
- package/dist/chunk-XZNJFDBF.mjs +0 -21
- package/dist/chunk-XZNJFDBF.mjs.map +0 -1
- package/dist/chunk-YJHQZFR4.mjs +0 -71
- package/dist/chunk-YJHQZFR4.mjs.map +0 -1
- package/dist/chunk-YL2EHYAA.js +0 -16
- package/dist/chunk-YL2EHYAA.js.map +0 -1
- package/dist/chunk-Z2JQNSVL.mjs +0 -8
- package/dist/chunk-Z2JQNSVL.mjs.map +0 -1
- package/dist/chunk-ZT3KKTS2.js +0 -9
- package/dist/chunk-ZT3KKTS2.js.map +0 -1
- package/dist/constants.js +0 -8
- package/dist/constants.js.map +0 -1
- package/dist/cronjob.js +0 -20
- package/dist/cronjob.js.map +0 -1
- package/dist/deep-clone.js +0 -8
- package/dist/deep-clone.js.map +0 -1
- package/dist/default-endowments.js +0 -8
- package/dist/default-endowments.js.map +0 -1
- package/dist/derivation-paths.js +0 -13
- package/dist/derivation-paths.js.map +0 -1
- package/dist/entropy.js +0 -10
- package/dist/entropy.js.map +0 -1
- package/dist/errors.js +0 -20
- package/dist/errors.js.map +0 -1
- package/dist/eval-worker.js +0 -43
- package/dist/eval-worker.js.map +0 -1
- package/dist/eval.js +0 -17
- package/dist/eval.js.map +0 -1
- package/dist/fs.js +0 -28
- package/dist/fs.js.map +0 -1
- package/dist/handler-types.js +0 -10
- package/dist/handler-types.js.map +0 -1
- package/dist/handlers.js +0 -35
- package/dist/handlers.js.map +0 -1
- package/dist/icon.js +0 -15
- package/dist/icon.js.map +0 -1
- package/dist/iframe.js +0 -8
- package/dist/iframe.js.map +0 -1
- package/dist/index.executionenv.js +0 -128
- package/dist/index.executionenv.js.map +0 -1
- package/dist/index.js +0 -398
- package/dist/index.js.map +0 -1
- package/dist/json-rpc.js +0 -18
- package/dist/json-rpc.js.map +0 -1
- package/dist/json.js +0 -10
- package/dist/json.js.map +0 -1
- package/dist/localization.js +0 -23
- package/dist/localization.js.map +0 -1
- package/dist/logging.js +0 -14
- package/dist/logging.js.map +0 -1
- package/dist/manifest/index.js +0 -65
- package/dist/manifest/index.js.map +0 -1
- package/dist/manifest/manifest.js +0 -59
- package/dist/manifest/manifest.js.map +0 -1
- package/dist/manifest/node.js +0 -106
- package/dist/manifest/node.js.map +0 -1
- package/dist/manifest/validation.js +0 -64
- package/dist/manifest/validation.js.map +0 -1
- package/dist/manifest/validator-types.js +0 -1
- package/dist/manifest/validator-types.js.map +0 -1
- package/dist/manifest/validator.js +0 -44
- package/dist/manifest/validator.js.map +0 -1
- package/dist/manifest/validators/checksum.js +0 -15
- package/dist/manifest/validators/checksum.js.map +0 -1
- package/dist/manifest/validators/expected-files.js +0 -9
- package/dist/manifest/validators/expected-files.js.map +0 -1
- package/dist/manifest/validators/icon-declared.js +0 -8
- package/dist/manifest/validators/icon-declared.js.map +0 -1
- package/dist/manifest/validators/icon-dimensions.js +0 -10
- package/dist/manifest/validators/icon-dimensions.js.map +0 -1
- package/dist/manifest/validators/icon-missing.js +0 -8
- package/dist/manifest/validators/icon-missing.js.map +0 -1
- package/dist/manifest/validators/index.js +0 -80
- package/dist/manifest/validators/index.js.map +0 -1
- package/dist/manifest/validators/is-localization-file.js +0 -12
- package/dist/manifest/validators/is-localization-file.js.map +0 -1
- package/dist/manifest/validators/is-package-json.js +0 -11
- package/dist/manifest/validators/is-package-json.js.map +0 -1
- package/dist/manifest/validators/is-snap-icon.js +0 -10
- package/dist/manifest/validators/is-snap-icon.js.map +0 -1
- package/dist/manifest/validators/is-snap-manifest.js +0 -23
- package/dist/manifest/validators/is-snap-manifest.js.map +0 -1
- package/dist/manifest/validators/manifest-localization.js +0 -10
- package/dist/manifest/validators/manifest-localization.js.map +0 -1
- package/dist/manifest/validators/package-json-recommended-fields.js +0 -8
- package/dist/manifest/validators/package-json-recommended-fields.js.map +0 -1
- package/dist/manifest/validators/package-name-match.js +0 -9
- package/dist/manifest/validators/package-name-match.js.map +0 -1
- package/dist/manifest/validators/repository-match.js +0 -10
- package/dist/manifest/validators/repository-match.js.map +0 -1
- package/dist/manifest/validators/version-match.js +0 -9
- package/dist/manifest/validators/version-match.js.map +0 -1
- package/dist/mock.js +0 -13
- package/dist/mock.js.map +0 -1
- package/dist/namespace.js +0 -44
- package/dist/namespace.js.map +0 -1
- package/dist/node.js +0 -476
- package/dist/node.js.map +0 -1
- package/dist/path.js +0 -8
- package/dist/path.js.map +0 -1
- package/dist/post-process.js +0 -10
- package/dist/post-process.js.map +0 -1
- package/dist/promise.js +0 -2
- package/dist/promise.js.map +0 -1
- package/dist/snaps.js +0 -46
- package/dist/snaps.js.map +0 -1
- package/dist/strings.js +0 -8
- package/dist/strings.js.map +0 -1
- package/dist/structs.js +0 -33
- package/dist/structs.js.map +0 -1
- package/dist/svg.js +0 -10
- package/dist/svg.js.map +0 -1
- package/dist/tsconfig.build.tsbuildinfo +0 -1
- package/dist/types/array.d.ts +0 -10
- package/dist/types/auxiliary-files.d.ts +0 -16
- package/dist/types/base64.d.ts +0 -15
- package/dist/types/bytes.d.ts +0 -8
- package/dist/types/caveats.d.ts +0 -46
- package/dist/types/checksum.d.ts +0 -21
- package/dist/types/constants.d.ts +0 -1
- package/dist/types/cronjob.d.ts +0 -89
- package/dist/types/deep-clone.d.ts +0 -1
- package/dist/types/default-endowments.d.ts +0 -4
- package/dist/types/derivation-paths.d.ts +0 -24
- package/dist/types/entropy.d.ts +0 -3
- package/dist/types/errors.d.ts +0 -84
- package/dist/types/eval-worker.d.ts +0 -1
- package/dist/types/eval.d.ts +0 -16
- package/dist/types/fs.d.ts +0 -69
- package/dist/types/handler-types.d.ts +0 -34
- package/dist/types/handlers.d.ts +0 -749
- package/dist/types/icon.d.ts +0 -19
- package/dist/types/iframe.d.ts +0 -11
- package/dist/types/iframe.test.browser.d.ts +0 -1
- package/dist/types/index.d.ts +0 -32
- package/dist/types/index.executionenv.d.ts +0 -7
- package/dist/types/json-rpc.d.ts +0 -55
- package/dist/types/json.d.ts +0 -22
- package/dist/types/localization.d.ts +0 -145
- package/dist/types/logging.d.ts +0 -49
- package/dist/types/manifest/index.d.ts +0 -1
- package/dist/types/manifest/manifest.d.ts +0 -98
- package/dist/types/manifest/node.d.ts +0 -2
- package/dist/types/manifest/validation.d.ts +0 -253
- package/dist/types/manifest/validator-types.d.ts +0 -34
- package/dist/types/manifest/validator.d.ts +0 -22
- package/dist/types/manifest/validators/checksum.d.ts +0 -5
- package/dist/types/manifest/validators/expected-files.d.ts +0 -5
- package/dist/types/manifest/validators/icon-declared.d.ts +0 -5
- package/dist/types/manifest/validators/icon-dimensions.d.ts +0 -5
- package/dist/types/manifest/validators/icon-missing.d.ts +0 -5
- package/dist/types/manifest/validators/index.d.ts +0 -14
- package/dist/types/manifest/validators/is-localization-file.d.ts +0 -5
- package/dist/types/manifest/validators/is-package-json.d.ts +0 -5
- package/dist/types/manifest/validators/is-snap-icon.d.ts +0 -5
- package/dist/types/manifest/validators/is-snap-manifest.d.ts +0 -5
- package/dist/types/manifest/validators/manifest-localization.d.ts +0 -5
- package/dist/types/manifest/validators/package-json-recommended-fields.d.ts +0 -5
- package/dist/types/manifest/validators/package-name-match.d.ts +0 -5
- package/dist/types/manifest/validators/repository-match.d.ts +0 -5
- package/dist/types/manifest/validators/version-match.d.ts +0 -5
- package/dist/types/mock.d.ts +0 -14
- package/dist/types/namespace.d.ts +0 -129
- package/dist/types/node.d.ts +0 -7
- package/dist/types/path.d.ts +0 -7
- package/dist/types/post-process.d.ts +0 -71
- package/dist/types/promise.d.ts +0 -1
- package/dist/types/snaps.d.ts +0 -169
- package/dist/types/strings.d.ts +0 -8
- package/dist/types/structs.d.ts +0 -180
- package/dist/types/svg.d.ts +0 -14
- package/dist/types/types.d.ts +0 -103
- package/dist/types/ui.d.ts +0 -84
- package/dist/types/validation.d.ts +0 -8
- package/dist/types/versions.d.ts +0 -21
- package/dist/types/virtual-file/VirtualFile.d.ts +0 -34
- package/dist/types/virtual-file/index.d.ts +0 -1
- package/dist/types/virtual-file/node.d.ts +0 -2
- package/dist/types/virtual-file/toVirtualFile.d.ts +0 -21
- package/dist/types.js +0 -22
- package/dist/types.js.map +0 -1
- package/dist/ui.js +0 -24
- package/dist/ui.js.map +0 -1
- package/dist/validation.js +0 -27
- package/dist/validation.js.map +0 -1
- package/dist/versions.js +0 -12
- package/dist/versions.js.map +0 -1
- package/dist/virtual-file/VirtualFile.js +0 -9
- package/dist/virtual-file/VirtualFile.js.map +0 -1
- package/dist/virtual-file/index.js +0 -10
- package/dist/virtual-file/index.js.map +0 -1
- package/dist/virtual-file/node.js +0 -17
- package/dist/virtual-file/node.js.map +0 -1
- package/dist/virtual-file/toVirtualFile.js +0 -12
- package/dist/virtual-file/toVirtualFile.js.map +0 -1
package/dist/structs.mjs
CHANGED
|
@@ -1,33 +1,301 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
1
|
+
import { union } from "@metamask/snaps-sdk";
|
|
2
|
+
import { assign, is, validate, type as superstructType, Struct, StructError, create } from "@metamask/superstruct";
|
|
3
|
+
import { assert, isObject } from "@metamask/utils";
|
|
4
|
+
import $chalk from "chalk";
|
|
5
|
+
const { bold, green, red } = $chalk;
|
|
6
|
+
import { indent } from "./strings.mjs";
|
|
7
|
+
/**
|
|
8
|
+
* Colorize a value with a color function. This is useful for colorizing values
|
|
9
|
+
* in error messages. If colorization is disabled, the original value is
|
|
10
|
+
* returned.
|
|
11
|
+
*
|
|
12
|
+
* @param value - The value to colorize.
|
|
13
|
+
* @param colorFunction - The color function to use.
|
|
14
|
+
* @param enabled - Whether to colorize the value.
|
|
15
|
+
* @returns The colorized value, or the original value if colorization is
|
|
16
|
+
* disabled.
|
|
17
|
+
*/
|
|
18
|
+
function color(value, colorFunction, enabled) {
|
|
19
|
+
if (enabled) {
|
|
20
|
+
return colorFunction(value);
|
|
21
|
+
}
|
|
22
|
+
return value;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Define a struct, and also define the name of the struct as the given name.
|
|
26
|
+
*
|
|
27
|
+
* This is useful for improving the error messages returned by `superstruct`.
|
|
28
|
+
*
|
|
29
|
+
* @param name - The name of the struct.
|
|
30
|
+
* @param struct - The struct.
|
|
31
|
+
* @returns The struct.
|
|
32
|
+
*/
|
|
33
|
+
export function named(name, struct) {
|
|
34
|
+
return new Struct({
|
|
35
|
+
...struct,
|
|
36
|
+
type: name,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
export class SnapsStructError extends StructError {
|
|
40
|
+
constructor(struct, prefix, suffix, failure, failures, colorize = true) {
|
|
41
|
+
super(failure, failures);
|
|
42
|
+
this.name = 'SnapsStructError';
|
|
43
|
+
this.message = `${prefix}.\n\n${getStructErrorMessage(struct, [...failures()], colorize)}${suffix ? `\n\n${suffix}` : ''}`;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Converts an array to a generator function that yields the items in the
|
|
48
|
+
* array.
|
|
49
|
+
*
|
|
50
|
+
* @param array - The array.
|
|
51
|
+
* @returns A generator function.
|
|
52
|
+
* @yields The items in the array.
|
|
53
|
+
*/
|
|
54
|
+
export function* arrayToGenerator(array) {
|
|
55
|
+
for (const item of array) {
|
|
56
|
+
yield item;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Returns a `SnapsStructError` with the given prefix and suffix.
|
|
61
|
+
*
|
|
62
|
+
* @param options - The options.
|
|
63
|
+
* @param options.struct - The struct that caused the error.
|
|
64
|
+
* @param options.prefix - The prefix to add to the error message.
|
|
65
|
+
* @param options.suffix - The suffix to add to the error message. Defaults to
|
|
66
|
+
* an empty string.
|
|
67
|
+
* @param options.error - The `superstruct` error to wrap.
|
|
68
|
+
* @param options.colorize - Whether to colorize the value. Defaults to `true`.
|
|
69
|
+
* @returns The `SnapsStructError`.
|
|
70
|
+
*/
|
|
71
|
+
export function getError({ struct, prefix, suffix = '', error, colorize, }) {
|
|
72
|
+
return new SnapsStructError(struct, prefix, suffix, error, () => arrayToGenerator(error.failures()), colorize);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* A wrapper of `superstruct`'s `create` function that throws a
|
|
76
|
+
* `SnapsStructError` instead of a `StructError`. This is useful for improving
|
|
77
|
+
* the error messages returned by `superstruct`.
|
|
78
|
+
*
|
|
79
|
+
* @param value - The value to validate.
|
|
80
|
+
* @param struct - The `superstruct` struct to validate the value against.
|
|
81
|
+
* @param prefix - The prefix to add to the error message.
|
|
82
|
+
* @param suffix - The suffix to add to the error message. Defaults to an empty
|
|
83
|
+
* string.
|
|
84
|
+
* @returns The validated value.
|
|
85
|
+
*/
|
|
86
|
+
export function createFromStruct(value, struct, prefix, suffix = '') {
|
|
87
|
+
try {
|
|
88
|
+
return create(value, struct);
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
if (error instanceof StructError) {
|
|
92
|
+
throw getError({ struct, prefix, suffix, error });
|
|
93
|
+
}
|
|
94
|
+
throw error;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Get a struct from a failure path.
|
|
99
|
+
*
|
|
100
|
+
* @param struct - The struct.
|
|
101
|
+
* @param path - The failure path.
|
|
102
|
+
* @returns The struct at the failure path.
|
|
103
|
+
*/
|
|
104
|
+
export function getStructFromPath(struct, path) {
|
|
105
|
+
return path.reduce((result, key) => {
|
|
106
|
+
if (isObject(struct.schema) && struct.schema[key]) {
|
|
107
|
+
return struct.schema[key];
|
|
108
|
+
}
|
|
109
|
+
return result;
|
|
110
|
+
}, struct);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Get the union struct names from a struct.
|
|
114
|
+
*
|
|
115
|
+
* @param struct - The struct.
|
|
116
|
+
* @param colorize - Whether to colorize the value. Defaults to `true`.
|
|
117
|
+
* @returns The union struct names, or `null` if the struct is not a union
|
|
118
|
+
* struct.
|
|
119
|
+
*/
|
|
120
|
+
export function getUnionStructNames(struct, colorize = true) {
|
|
121
|
+
if (Array.isArray(struct.schema)) {
|
|
122
|
+
return struct.schema.map(({ type }) => color(type, green, colorize));
|
|
123
|
+
}
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Get an error prefix from a `superstruct` failure. This is useful for
|
|
128
|
+
* formatting the error message returned by `superstruct`.
|
|
129
|
+
*
|
|
130
|
+
* @param failure - The `superstruct` failure.
|
|
131
|
+
* @param colorize - Whether to colorize the value. Defaults to `true`.
|
|
132
|
+
* @returns The error prefix.
|
|
133
|
+
*/
|
|
134
|
+
export function getStructErrorPrefix(failure, colorize = true) {
|
|
135
|
+
if (failure.type === 'never' || failure.path.length === 0) {
|
|
136
|
+
return '';
|
|
137
|
+
}
|
|
138
|
+
return `At path: ${color(failure.path.join('.'), bold, colorize)} — `;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Get a string describing the failure. This is similar to the `message`
|
|
142
|
+
* property of `superstruct`'s `Failure` type, but formats the value in a more
|
|
143
|
+
* readable way.
|
|
144
|
+
*
|
|
145
|
+
* @param struct - The struct that caused the failure.
|
|
146
|
+
* @param failure - The `superstruct` failure.
|
|
147
|
+
* @param colorize - Whether to colorize the value. Defaults to `true`.
|
|
148
|
+
* @returns A string describing the failure.
|
|
149
|
+
*/
|
|
150
|
+
export function getStructFailureMessage(struct, failure, colorize = true) {
|
|
151
|
+
const received = color(JSON.stringify(failure.value), red, colorize);
|
|
152
|
+
const prefix = getStructErrorPrefix(failure, colorize);
|
|
153
|
+
if (failure.type === 'union') {
|
|
154
|
+
const childStruct = getStructFromPath(struct, failure.path);
|
|
155
|
+
const unionNames = getUnionStructNames(childStruct, colorize);
|
|
156
|
+
if (unionNames) {
|
|
157
|
+
return `${prefix}Expected the value to be one of: ${unionNames.join(', ')}, but received: ${received}.`;
|
|
158
|
+
}
|
|
159
|
+
return `${prefix}${failure.message}.`;
|
|
160
|
+
}
|
|
161
|
+
if (failure.type === 'literal') {
|
|
162
|
+
// Superstruct's failure does not provide information about which literal
|
|
163
|
+
// value was expected, so we need to parse the message to get the literal.
|
|
164
|
+
const message = failure.message
|
|
165
|
+
.replace(/the literal `(.+)`,/u, `the value to be \`${color('$1', green, colorize)}\`,`)
|
|
166
|
+
.replace(/, but received: (.+)/u, `, but received: ${color('$1', red, colorize)}`);
|
|
167
|
+
return `${prefix}${message}.`;
|
|
168
|
+
}
|
|
169
|
+
if (failure.type === 'never') {
|
|
170
|
+
return `Unknown key: ${color(failure.path.join('.'), bold, colorize)}, received: ${received}.`;
|
|
171
|
+
}
|
|
172
|
+
if (failure.refinement === 'size') {
|
|
173
|
+
const message = failure.message
|
|
174
|
+
.replace(/length between `(\d+)` and `(\d+)`/u, `length between ${color('$1', green, colorize)} and ${color('$2', green, colorize)},`)
|
|
175
|
+
.replace(/length of `(\d+)`/u, `length of ${color('$1', red, colorize)}`)
|
|
176
|
+
.replace(/a array/u, 'an array');
|
|
177
|
+
return `${prefix}${message}.`;
|
|
178
|
+
}
|
|
179
|
+
// Refinements we built ourselves have nice error messages
|
|
180
|
+
if (failure.refinement !== undefined) {
|
|
181
|
+
return `${prefix}${failure.message}.`;
|
|
182
|
+
}
|
|
183
|
+
return `${prefix}Expected a value of type ${color(failure.type, green, colorize)}, but received: ${received}.`;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Get a string describing the errors. This formats all the errors in a
|
|
187
|
+
* human-readable way.
|
|
188
|
+
*
|
|
189
|
+
* @param struct - The struct that caused the failures.
|
|
190
|
+
* @param failures - The `superstruct` failures.
|
|
191
|
+
* @param colorize - Whether to colorize the value. Defaults to `true`.
|
|
192
|
+
* @returns A string describing the errors.
|
|
193
|
+
*/
|
|
194
|
+
export function getStructErrorMessage(struct, failures, colorize = true) {
|
|
195
|
+
const formattedFailures = failures.map((failure) => indent(`• ${getStructFailureMessage(struct, failure, colorize)}`));
|
|
196
|
+
return formattedFailures.join('\n');
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Validate a union struct, and throw readable errors if the value does not
|
|
200
|
+
* satisfy the struct. This is useful for improving the error messages returned
|
|
201
|
+
* by `superstruct`.
|
|
202
|
+
*
|
|
203
|
+
* @param value - The value to validate.
|
|
204
|
+
* @param struct - The `superstruct` union struct to validate the value against.
|
|
205
|
+
* This struct must be a union of object structs, and must have at least one
|
|
206
|
+
* shared key to validate against.
|
|
207
|
+
* @param structKey - The key to validate against. This key must be present in
|
|
208
|
+
* all the object structs in the union struct, and is expected to be a literal
|
|
209
|
+
* value.
|
|
210
|
+
* @param coerce - Whether to coerce the value to satisfy the struct. Defaults
|
|
211
|
+
* to `false`.
|
|
212
|
+
* @returns The validated value.
|
|
213
|
+
* @throws If the value does not satisfy the struct.
|
|
214
|
+
* @example
|
|
215
|
+
* const struct = union([
|
|
216
|
+
* object({ type: literal('a'), value: string() }),
|
|
217
|
+
* object({ type: literal('b'), value: number() }),
|
|
218
|
+
* object({ type: literal('c'), value: boolean() }),
|
|
219
|
+
* // ...
|
|
220
|
+
* ]);
|
|
221
|
+
*
|
|
222
|
+
* // At path: type — Expected the value to be one of: "a", "b", "c", but received: "d".
|
|
223
|
+
* validateUnion({ type: 'd', value: 'foo' }, struct, 'type');
|
|
224
|
+
*
|
|
225
|
+
* // At path: value — Expected a value of type string, but received: 42.
|
|
226
|
+
* validateUnion({ type: 'a', value: 42 }, struct, 'value');
|
|
227
|
+
*/
|
|
228
|
+
export function validateUnion(value, struct, structKey, coerce = false) {
|
|
229
|
+
assert(struct.schema, 'Expected a struct with a schema. Make sure to use `union` from `@metamask/snaps-sdk`.');
|
|
230
|
+
assert(struct.schema.length > 0, 'Expected a non-empty array of structs.');
|
|
231
|
+
const keyUnion = struct.schema.map((innerStruct) => innerStruct.schema[structKey]);
|
|
232
|
+
const key = superstructType({
|
|
233
|
+
[structKey]: union(keyUnion),
|
|
234
|
+
});
|
|
235
|
+
const [keyError] = validate(value, key, { coerce });
|
|
236
|
+
if (keyError) {
|
|
237
|
+
throw new Error(getStructFailureMessage(key, keyError.failures()[0], false));
|
|
238
|
+
}
|
|
239
|
+
// At this point it's guaranteed that the value is an object, so we can safely
|
|
240
|
+
// cast it to a Record.
|
|
241
|
+
const objectValue = value;
|
|
242
|
+
const objectStructs = struct.schema.filter((innerStruct) => is(objectValue[structKey], innerStruct.schema[structKey]));
|
|
243
|
+
assert(objectStructs.length > 0, 'Expected a struct to match the value.');
|
|
244
|
+
// We need to validate the value against all the object structs that match the
|
|
245
|
+
// struct key, and return the first validated value.
|
|
246
|
+
const validationResults = objectStructs.map((objectStruct) => validate(objectValue, objectStruct, { coerce }));
|
|
247
|
+
const validatedValue = validationResults.find(([error]) => !error);
|
|
248
|
+
if (validatedValue) {
|
|
249
|
+
return validatedValue[1];
|
|
250
|
+
}
|
|
251
|
+
assert(validationResults[0][0], 'Expected at least one error.');
|
|
252
|
+
// If there is no validated value, we need to find the error with the least
|
|
253
|
+
// number of failures (with the assumption that it's the most specific error).
|
|
254
|
+
const validationError = validationResults.reduce((error, [innerError]) => {
|
|
255
|
+
assert(innerError, 'Expected an error.');
|
|
256
|
+
if (innerError.failures().length < error.failures().length) {
|
|
257
|
+
return innerError;
|
|
258
|
+
}
|
|
259
|
+
return error;
|
|
260
|
+
}, validationResults[0][0]);
|
|
261
|
+
throw new Error(getStructFailureMessage(struct, validationError.failures()[0], false));
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Create a value with the coercion logic of a union struct, and throw readable
|
|
265
|
+
* errors if the value does not satisfy the struct. This is useful for improving
|
|
266
|
+
* the error messages returned by `superstruct`.
|
|
267
|
+
*
|
|
268
|
+
* @param value - The value to validate.
|
|
269
|
+
* @param struct - The `superstruct` union struct to validate the value against.
|
|
270
|
+
* This struct must be a union of object structs, and must have at least one
|
|
271
|
+
* shared key to validate against.
|
|
272
|
+
* @param structKey - The key to validate against. This key must be present in
|
|
273
|
+
* all the object structs in the union struct, and is expected to be a literal
|
|
274
|
+
* value.
|
|
275
|
+
* @returns The validated value.
|
|
276
|
+
* @throws If the value does not satisfy the struct.
|
|
277
|
+
* @see validateUnion
|
|
278
|
+
*/
|
|
279
|
+
export function createUnion(value, struct, structKey) {
|
|
280
|
+
return validateUnion(value, struct, structKey, true);
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Merge multiple structs into one, using superstruct `assign`.
|
|
284
|
+
*
|
|
285
|
+
* Differently from plain `assign`, this function also copies over refinements from each struct.
|
|
286
|
+
*
|
|
287
|
+
* @param structs - The `superstruct` structs to merge.
|
|
288
|
+
* @returns The merged struct.
|
|
289
|
+
*/
|
|
290
|
+
export function mergeStructs(...structs) {
|
|
291
|
+
const mergedStruct = assign(...structs);
|
|
292
|
+
return new Struct({
|
|
293
|
+
...mergedStruct,
|
|
294
|
+
*refiner(value, ctx) {
|
|
295
|
+
for (const struct of structs) {
|
|
296
|
+
yield* struct.refiner(value, ctx);
|
|
297
|
+
}
|
|
298
|
+
},
|
|
299
|
+
});
|
|
300
|
+
}
|
|
33
301
|
//# sourceMappingURL=structs.mjs.map
|
package/dist/structs.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
1
|
+
{"version":3,"file":"structs.mjs","sourceRoot":"","sources":["../src/structs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,4BAA4B;AAQ5C,OAAO,EACL,MAAM,EACN,EAAE,EACF,QAAQ,EACR,IAAI,IAAI,eAAe,EACvB,MAAM,EACN,WAAW,EACX,MAAM,EACP,8BAA8B;AAE/B,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,wBAAwB;;;AAGnD,OAAO,EAAE,MAAM,EAAE,sBAAkB;AA6BnC;;;;;;;;;;GAUG;AACH,SAAS,KAAK,CACZ,KAAa,EACb,aAAwC,EACxC,OAAgB;IAEhB,IAAI,OAAO,EAAE,CAAC;QACZ,OAAO,aAAa,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AAC;AAuDD;;;;;;;GAOG;AACH,MAAM,UAAU,YAAY,CAAC,GAAG,OAAsB;IACpD,MAAM,YAAY,GAAI,MAAgD,CACpE,GAAG,OAAO,CACX,CAAC;IACF,OAAO,IAAI,MAAM,CAAC;QAChB,GAAG,YAAY;QACf,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG;YACjB,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;gBAC7B,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;YACpC,CAAC;QACH,CAAC;KACF,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { union } from '@metamask/snaps-sdk';\nimport type {\n AnyStruct,\n Assign,\n Failure,\n ObjectSchema,\n ObjectType,\n} from '@metamask/superstruct';\nimport {\n assign,\n is,\n validate,\n type as superstructType,\n Struct,\n StructError,\n create,\n} from '@metamask/superstruct';\nimport type { NonEmptyArray } from '@metamask/utils';\nimport { assert, isObject } from '@metamask/utils';\nimport { bold, green, red } from 'chalk';\n\nimport { indent } from './strings';\n\n/**\n * Infer a struct type, only if it matches the specified type. This is useful\n * for defining types and structs that are related to each other in separate\n * files.\n *\n * @example\n * ```typescript\n * // In file A\n * export type GetFileArgs = {\n * path: string;\n * encoding?: EnumToUnion<AuxiliaryFileEncoding>;\n * };\n *\n * // In file B\n * export const GetFileArgsStruct = object(...);\n *\n * // If the type and struct are in the same file, this will return the type.\n * // Otherwise, it will return `never`.\n * export type GetFileArgs =\n * InferMatching<typeof GetFileArgsStruct, GetFileArgs>;\n * ```\n */\nexport type InferMatching<\n StructType extends Struct<any, any>,\n Type,\n> = StructType['TYPE'] extends Type ? Type : never;\n\n/**\n * Colorize a value with a color function. This is useful for colorizing values\n * in error messages. If colorization is disabled, the original value is\n * returned.\n *\n * @param value - The value to colorize.\n * @param colorFunction - The color function to use.\n * @param enabled - Whether to colorize the value.\n * @returns The colorized value, or the original value if colorization is\n * disabled.\n */\nfunction color(\n value: string,\n colorFunction: (value: string) => string,\n enabled: boolean,\n) {\n if (enabled) {\n return colorFunction(value);\n }\n\n return value;\n}\n\n/**\n * Define a struct, and also define the name of the struct as the given name.\n *\n * This is useful for improving the error messages returned by `superstruct`.\n *\n * @param name - The name of the struct.\n * @param struct - The struct.\n * @returns The struct.\n */\nexport function named<Type, Schema>(\n name: string,\n struct: Struct<Type, Schema>,\n) {\n return new Struct({\n ...struct,\n type: name,\n });\n}\n\nexport class SnapsStructError<Type, Schema> extends StructError {\n constructor(\n struct: Struct<Type, Schema>,\n prefix: string,\n suffix: string,\n failure: StructError,\n failures: () => Generator<Failure>,\n colorize = true,\n ) {\n super(failure, failures);\n\n this.name = 'SnapsStructError';\n this.message = `${prefix}.\\n\\n${getStructErrorMessage(\n struct,\n [...failures()],\n colorize,\n )}${suffix ? `\\n\\n${suffix}` : ''}`;\n }\n}\n\ntype GetErrorOptions<Type, Schema> = {\n struct: Struct<Type, Schema>;\n prefix: string;\n suffix?: string;\n error: StructError;\n colorize?: boolean;\n};\n\n/**\n * Converts an array to a generator function that yields the items in the\n * array.\n *\n * @param array - The array.\n * @returns A generator function.\n * @yields The items in the array.\n */\nexport function* arrayToGenerator<Type>(\n array: Type[],\n): Generator<Type, void, undefined> {\n for (const item of array) {\n yield item;\n }\n}\n\n/**\n * Returns a `SnapsStructError` with the given prefix and suffix.\n *\n * @param options - The options.\n * @param options.struct - The struct that caused the error.\n * @param options.prefix - The prefix to add to the error message.\n * @param options.suffix - The suffix to add to the error message. Defaults to\n * an empty string.\n * @param options.error - The `superstruct` error to wrap.\n * @param options.colorize - Whether to colorize the value. Defaults to `true`.\n * @returns The `SnapsStructError`.\n */\nexport function getError<Type, Schema>({\n struct,\n prefix,\n suffix = '',\n error,\n colorize,\n}: GetErrorOptions<Type, Schema>) {\n return new SnapsStructError(\n struct,\n prefix,\n suffix,\n error,\n () => arrayToGenerator(error.failures()),\n colorize,\n );\n}\n\n/**\n * A wrapper of `superstruct`'s `create` function that throws a\n * `SnapsStructError` instead of a `StructError`. This is useful for improving\n * the error messages returned by `superstruct`.\n *\n * @param value - The value to validate.\n * @param struct - The `superstruct` struct to validate the value against.\n * @param prefix - The prefix to add to the error message.\n * @param suffix - The suffix to add to the error message. Defaults to an empty\n * string.\n * @returns The validated value.\n */\nexport function createFromStruct<Type, Schema>(\n value: unknown,\n struct: Struct<Type, Schema>,\n prefix: string,\n suffix = '',\n) {\n try {\n return create(value, struct);\n } catch (error) {\n if (error instanceof StructError) {\n throw getError({ struct, prefix, suffix, error });\n }\n\n throw error;\n }\n}\n\n/**\n * Get a struct from a failure path.\n *\n * @param struct - The struct.\n * @param path - The failure path.\n * @returns The struct at the failure path.\n */\nexport function getStructFromPath<Type, Schema>(\n struct: Struct<Type, Schema>,\n path: string[],\n) {\n return path.reduce<AnyStruct>((result, key) => {\n if (isObject(struct.schema) && struct.schema[key]) {\n return struct.schema[key] as AnyStruct;\n }\n\n return result;\n }, struct);\n}\n\n/**\n * Get the union struct names from a struct.\n *\n * @param struct - The struct.\n * @param colorize - Whether to colorize the value. Defaults to `true`.\n * @returns The union struct names, or `null` if the struct is not a union\n * struct.\n */\nexport function getUnionStructNames<Type, Schema>(\n struct: Struct<Type, Schema>,\n colorize = true,\n) {\n if (Array.isArray(struct.schema)) {\n return struct.schema.map(({ type }) => color(type, green, colorize));\n }\n\n return null;\n}\n\n/**\n * Get an error prefix from a `superstruct` failure. This is useful for\n * formatting the error message returned by `superstruct`.\n *\n * @param failure - The `superstruct` failure.\n * @param colorize - Whether to colorize the value. Defaults to `true`.\n * @returns The error prefix.\n */\nexport function getStructErrorPrefix(failure: Failure, colorize = true) {\n if (failure.type === 'never' || failure.path.length === 0) {\n return '';\n }\n\n return `At path: ${color(failure.path.join('.'), bold, colorize)} — `;\n}\n\n/**\n * Get a string describing the failure. This is similar to the `message`\n * property of `superstruct`'s `Failure` type, but formats the value in a more\n * readable way.\n *\n * @param struct - The struct that caused the failure.\n * @param failure - The `superstruct` failure.\n * @param colorize - Whether to colorize the value. Defaults to `true`.\n * @returns A string describing the failure.\n */\nexport function getStructFailureMessage<Type, Schema>(\n struct: Struct<Type, Schema>,\n failure: Failure,\n colorize = true,\n) {\n const received = color(JSON.stringify(failure.value), red, colorize);\n const prefix = getStructErrorPrefix(failure, colorize);\n\n if (failure.type === 'union') {\n const childStruct = getStructFromPath(struct, failure.path);\n const unionNames = getUnionStructNames(childStruct, colorize);\n\n if (unionNames) {\n return `${prefix}Expected the value to be one of: ${unionNames.join(\n ', ',\n )}, but received: ${received}.`;\n }\n\n return `${prefix}${failure.message}.`;\n }\n\n if (failure.type === 'literal') {\n // Superstruct's failure does not provide information about which literal\n // value was expected, so we need to parse the message to get the literal.\n const message = failure.message\n .replace(\n /the literal `(.+)`,/u,\n `the value to be \\`${color('$1', green, colorize)}\\`,`,\n )\n .replace(\n /, but received: (.+)/u,\n `, but received: ${color('$1', red, colorize)}`,\n );\n\n return `${prefix}${message}.`;\n }\n\n if (failure.type === 'never') {\n return `Unknown key: ${color(\n failure.path.join('.'),\n bold,\n colorize,\n )}, received: ${received}.`;\n }\n\n if (failure.refinement === 'size') {\n const message = failure.message\n .replace(\n /length between `(\\d+)` and `(\\d+)`/u,\n `length between ${color('$1', green, colorize)} and ${color(\n '$2',\n green,\n colorize,\n )},`,\n )\n .replace(/length of `(\\d+)`/u, `length of ${color('$1', red, colorize)}`)\n .replace(/a array/u, 'an array');\n\n return `${prefix}${message}.`;\n }\n\n // Refinements we built ourselves have nice error messages\n if (failure.refinement !== undefined) {\n return `${prefix}${failure.message}.`;\n }\n\n return `${prefix}Expected a value of type ${color(\n failure.type,\n green,\n colorize,\n )}, but received: ${received}.`;\n}\n\n/**\n * Get a string describing the errors. This formats all the errors in a\n * human-readable way.\n *\n * @param struct - The struct that caused the failures.\n * @param failures - The `superstruct` failures.\n * @param colorize - Whether to colorize the value. Defaults to `true`.\n * @returns A string describing the errors.\n */\nexport function getStructErrorMessage<Type, Schema>(\n struct: Struct<Type, Schema>,\n failures: Failure[],\n colorize = true,\n) {\n const formattedFailures = failures.map((failure) =>\n indent(`• ${getStructFailureMessage(struct, failure, colorize)}`),\n );\n\n return formattedFailures.join('\\n');\n}\n\n/**\n * Validate a union struct, and throw readable errors if the value does not\n * satisfy the struct. This is useful for improving the error messages returned\n * by `superstruct`.\n *\n * @param value - The value to validate.\n * @param struct - The `superstruct` union struct to validate the value against.\n * This struct must be a union of object structs, and must have at least one\n * shared key to validate against.\n * @param structKey - The key to validate against. This key must be present in\n * all the object structs in the union struct, and is expected to be a literal\n * value.\n * @param coerce - Whether to coerce the value to satisfy the struct. Defaults\n * to `false`.\n * @returns The validated value.\n * @throws If the value does not satisfy the struct.\n * @example\n * const struct = union([\n * object({ type: literal('a'), value: string() }),\n * object({ type: literal('b'), value: number() }),\n * object({ type: literal('c'), value: boolean() }),\n * // ...\n * ]);\n *\n * // At path: type — Expected the value to be one of: \"a\", \"b\", \"c\", but received: \"d\".\n * validateUnion({ type: 'd', value: 'foo' }, struct, 'type');\n *\n * // At path: value — Expected a value of type string, but received: 42.\n * validateUnion({ type: 'a', value: 42 }, struct, 'value');\n */\nexport function validateUnion<Type, Schema extends readonly Struct<any, any>[]>(\n value: unknown,\n struct: Struct<Type, Schema>,\n structKey: keyof Type,\n coerce = false,\n) {\n assert(\n struct.schema,\n 'Expected a struct with a schema. Make sure to use `union` from `@metamask/snaps-sdk`.',\n );\n assert(struct.schema.length > 0, 'Expected a non-empty array of structs.');\n\n const keyUnion = struct.schema.map(\n (innerStruct) => innerStruct.schema[structKey],\n // This is guaranteed to be a non-empty array by the assertion above. We\n // need to cast it since `superstruct` requires a non-empty array of structs\n // for the `union` struct.\n ) as NonEmptyArray<Struct>;\n\n const key = superstructType({\n [structKey]: union(keyUnion),\n });\n\n const [keyError] = validate(value, key, { coerce });\n if (keyError) {\n throw new Error(\n getStructFailureMessage(key, keyError.failures()[0], false),\n );\n }\n\n // At this point it's guaranteed that the value is an object, so we can safely\n // cast it to a Record.\n const objectValue = value as Record<PropertyKey, unknown>;\n const objectStructs = struct.schema.filter((innerStruct) =>\n is(objectValue[structKey], innerStruct.schema[structKey]),\n );\n\n assert(objectStructs.length > 0, 'Expected a struct to match the value.');\n\n // We need to validate the value against all the object structs that match the\n // struct key, and return the first validated value.\n const validationResults = objectStructs.map((objectStruct) =>\n validate(objectValue, objectStruct, { coerce }),\n );\n\n const validatedValue = validationResults.find(([error]) => !error);\n if (validatedValue) {\n return validatedValue[1];\n }\n\n assert(validationResults[0][0], 'Expected at least one error.');\n\n // If there is no validated value, we need to find the error with the least\n // number of failures (with the assumption that it's the most specific error).\n const validationError = validationResults.reduce((error, [innerError]) => {\n assert(innerError, 'Expected an error.');\n if (innerError.failures().length < error.failures().length) {\n return innerError;\n }\n\n return error;\n }, validationResults[0][0]);\n\n throw new Error(\n getStructFailureMessage(struct, validationError.failures()[0], false),\n );\n}\n\n/**\n * Create a value with the coercion logic of a union struct, and throw readable\n * errors if the value does not satisfy the struct. This is useful for improving\n * the error messages returned by `superstruct`.\n *\n * @param value - The value to validate.\n * @param struct - The `superstruct` union struct to validate the value against.\n * This struct must be a union of object structs, and must have at least one\n * shared key to validate against.\n * @param structKey - The key to validate against. This key must be present in\n * all the object structs in the union struct, and is expected to be a literal\n * value.\n * @returns The validated value.\n * @throws If the value does not satisfy the struct.\n * @see validateUnion\n */\nexport function createUnion<Type, Schema extends readonly Struct<any, any>[]>(\n value: unknown,\n struct: Struct<Type, Schema>,\n structKey: keyof Type,\n) {\n return validateUnion(value, struct, structKey, true);\n}\n\n// These types are copied from Superstruct, to mirror `assign`.\nexport function mergeStructs<\n ObjectA extends ObjectSchema,\n ObjectB extends ObjectSchema,\n>(\n A: Struct<ObjectType<ObjectA>, ObjectA>,\n B: Struct<ObjectType<ObjectB>, ObjectB>,\n): Struct<ObjectType<Assign<ObjectA, ObjectB>>, Assign<ObjectA, ObjectB>>;\nexport function mergeStructs<\n ObjectA extends ObjectSchema,\n ObjectB extends ObjectSchema,\n ObjectC extends ObjectSchema,\n>(\n A: Struct<ObjectType<ObjectA>, ObjectA>,\n B: Struct<ObjectType<ObjectB>, ObjectB>,\n C: Struct<ObjectType<ObjectC>, ObjectC>,\n): Struct<\n ObjectType<Assign<Assign<ObjectA, ObjectB>, ObjectC>>,\n Assign<Assign<ObjectA, ObjectB>, ObjectC>\n>;\nexport function mergeStructs<\n ObjectA extends ObjectSchema,\n ObjectB extends ObjectSchema,\n ObjectC extends ObjectSchema,\n ObjectD extends ObjectSchema,\n>(\n A: Struct<ObjectType<ObjectA>, ObjectA>,\n B: Struct<ObjectType<ObjectB>, ObjectB>,\n C: Struct<ObjectType<ObjectC>, ObjectC>,\n D: Struct<ObjectType<ObjectD>, ObjectD>,\n): Struct<\n ObjectType<Assign<Assign<Assign<ObjectA, ObjectB>, ObjectC>, ObjectD>>,\n Assign<Assign<Assign<ObjectA, ObjectB>, ObjectC>, ObjectD>\n>;\nexport function mergeStructs<\n ObjectA extends ObjectSchema,\n ObjectB extends ObjectSchema,\n ObjectC extends ObjectSchema,\n ObjectD extends ObjectSchema,\n ObjectE extends ObjectSchema,\n>(\n A: Struct<ObjectType<ObjectA>, ObjectA>,\n B: Struct<ObjectType<ObjectB>, ObjectB>,\n C: Struct<ObjectType<ObjectC>, ObjectC>,\n D: Struct<ObjectType<ObjectD>, ObjectD>,\n E: Struct<ObjectType<ObjectE>, ObjectE>,\n): Struct<\n ObjectType<\n Assign<Assign<Assign<Assign<ObjectA, ObjectB>, ObjectC>, ObjectD>, ObjectE>\n >,\n Assign<Assign<Assign<Assign<ObjectA, ObjectB>, ObjectC>, ObjectD>, ObjectE>\n>;\n\n/**\n * Merge multiple structs into one, using superstruct `assign`.\n *\n * Differently from plain `assign`, this function also copies over refinements from each struct.\n *\n * @param structs - The `superstruct` structs to merge.\n * @returns The merged struct.\n */\nexport function mergeStructs(...structs: Struct<any>[]): Struct<any> {\n const mergedStruct = (assign as (...structs: Struct<any>[]) => Struct)(\n ...structs,\n );\n return new Struct({\n ...mergedStruct,\n *refiner(value, ctx) {\n for (const struct of structs) {\n yield* struct.refiner(value, ctx);\n }\n },\n });\n}\n"]}
|
package/dist/svg.cjs
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isSvg = exports.parseSvg = void 0;
|
|
4
|
+
const utils_1 = require("@metamask/utils");
|
|
5
|
+
const fast_xml_parser_1 = require("fast-xml-parser");
|
|
6
|
+
/**
|
|
7
|
+
* Parse and validate a string as an SVG.
|
|
8
|
+
*
|
|
9
|
+
* @param svg - An SVG string.
|
|
10
|
+
* @returns The SVG, its attributes and children in an object format.
|
|
11
|
+
*/
|
|
12
|
+
function parseSvg(svg) {
|
|
13
|
+
try {
|
|
14
|
+
const trimmed = svg.trim();
|
|
15
|
+
(0, utils_1.assert)(trimmed.length > 0);
|
|
16
|
+
const parser = new fast_xml_parser_1.XMLParser({
|
|
17
|
+
ignoreAttributes: false,
|
|
18
|
+
parseAttributeValue: true,
|
|
19
|
+
});
|
|
20
|
+
const parsed = parser.parse(trimmed, true);
|
|
21
|
+
(0, utils_1.assert)((0, utils_1.hasProperty)(parsed, 'svg'));
|
|
22
|
+
// Empty SVGs are not returned as objects
|
|
23
|
+
if (!(0, utils_1.isObject)(parsed.svg)) {
|
|
24
|
+
return {};
|
|
25
|
+
}
|
|
26
|
+
return parsed.svg;
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
throw new Error('Snap icon must be a valid SVG.');
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.parseSvg = parseSvg;
|
|
33
|
+
/**
|
|
34
|
+
* Validate that a string is a valid SVG.
|
|
35
|
+
*
|
|
36
|
+
* @param svg - An SVG string.
|
|
37
|
+
* @returns True if the SVG is valid otherwise false.
|
|
38
|
+
*/
|
|
39
|
+
function isSvg(svg) {
|
|
40
|
+
try {
|
|
41
|
+
parseSvg(svg);
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.isSvg = isSvg;
|
|
49
|
+
//# sourceMappingURL=svg.cjs.map
|
package/dist/svg.cjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"svg.cjs","sourceRoot":"","sources":["../src/svg.ts"],"names":[],"mappings":";;;AAAA,2CAAgE;AAChE,qDAA4C;AAE5C;;;;;GAKG;AACH,SAAgB,QAAQ,CAAC,GAAW;IAClC,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,GAAG,CAAC,IAAI,EAAE,CAAC;QAE3B,IAAA,cAAM,EAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QAE3B,MAAM,MAAM,GAAG,IAAI,2BAAS,CAAC;YAC3B,gBAAgB,EAAE,KAAK;YACvB,mBAAmB,EAAE,IAAI;SAC1B,CAAC,CAAC;QACH,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QAE3C,IAAA,cAAM,EAAC,IAAA,mBAAW,EAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;QAEnC,yCAAyC;QACzC,IAAI,CAAC,IAAA,gBAAQ,EAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC;YAC1B,OAAO,EAAE,CAAC;QACZ,CAAC;QAED,OAAO,MAAM,CAAC,GAAG,CAAC;IACpB,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;IACpD,CAAC;AACH,CAAC;AAvBD,4BAuBC;AAED;;;;;GAKG;AACH,SAAgB,KAAK,CAAC,GAAW;IAC/B,IAAI,CAAC;QACH,QAAQ,CAAC,GAAG,CAAC,CAAC;QACd,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAPD,sBAOC","sourcesContent":["import { assert, hasProperty, isObject } from '@metamask/utils';\nimport { XMLParser } from 'fast-xml-parser';\n\n/**\n * Parse and validate a string as an SVG.\n *\n * @param svg - An SVG string.\n * @returns The SVG, its attributes and children in an object format.\n */\nexport function parseSvg(svg: string) {\n try {\n const trimmed = svg.trim();\n\n assert(trimmed.length > 0);\n\n const parser = new XMLParser({\n ignoreAttributes: false,\n parseAttributeValue: true,\n });\n const parsed = parser.parse(trimmed, true);\n\n assert(hasProperty(parsed, 'svg'));\n\n // Empty SVGs are not returned as objects\n if (!isObject(parsed.svg)) {\n return {};\n }\n\n return parsed.svg;\n } catch {\n throw new Error('Snap icon must be a valid SVG.');\n }\n}\n\n/**\n * Validate that a string is a valid SVG.\n *\n * @param svg - An SVG string.\n * @returns True if the SVG is valid otherwise false.\n */\nexport function isSvg(svg: string) {\n try {\n parseSvg(svg);\n return true;\n } catch {\n return false;\n }\n}\n"]}
|
package/dist/svg.d.cts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parse and validate a string as an SVG.
|
|
3
|
+
*
|
|
4
|
+
* @param svg - An SVG string.
|
|
5
|
+
* @returns The SVG, its attributes and children in an object format.
|
|
6
|
+
*/
|
|
7
|
+
export declare function parseSvg(svg: string): any;
|
|
8
|
+
/**
|
|
9
|
+
* Validate that a string is a valid SVG.
|
|
10
|
+
*
|
|
11
|
+
* @param svg - An SVG string.
|
|
12
|
+
* @returns True if the SVG is valid otherwise false.
|
|
13
|
+
*/
|
|
14
|
+
export declare function isSvg(svg: string): boolean;
|
|
15
|
+
//# sourceMappingURL=svg.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"svg.d.cts","sourceRoot":"","sources":["../src/svg.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,OAuBnC;AAED;;;;;GAKG;AACH,wBAAgB,KAAK,CAAC,GAAG,EAAE,MAAM,WAOhC"}
|
package/dist/svg.d.mts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parse and validate a string as an SVG.
|
|
3
|
+
*
|
|
4
|
+
* @param svg - An SVG string.
|
|
5
|
+
* @returns The SVG, its attributes and children in an object format.
|
|
6
|
+
*/
|
|
7
|
+
export declare function parseSvg(svg: string): any;
|
|
8
|
+
/**
|
|
9
|
+
* Validate that a string is a valid SVG.
|
|
10
|
+
*
|
|
11
|
+
* @param svg - An SVG string.
|
|
12
|
+
* @returns True if the SVG is valid otherwise false.
|
|
13
|
+
*/
|
|
14
|
+
export declare function isSvg(svg: string): boolean;
|
|
15
|
+
//# sourceMappingURL=svg.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"svg.d.mts","sourceRoot":"","sources":["../src/svg.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,OAuBnC;AAED;;;;;GAKG;AACH,wBAAgB,KAAK,CAAC,GAAG,EAAE,MAAM,WAOhC"}
|
package/dist/svg.mjs
CHANGED
|
@@ -1,10 +1,44 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import { assert, hasProperty, isObject } from "@metamask/utils";
|
|
2
|
+
import { XMLParser } from "fast-xml-parser";
|
|
3
|
+
/**
|
|
4
|
+
* Parse and validate a string as an SVG.
|
|
5
|
+
*
|
|
6
|
+
* @param svg - An SVG string.
|
|
7
|
+
* @returns The SVG, its attributes and children in an object format.
|
|
8
|
+
*/
|
|
9
|
+
export function parseSvg(svg) {
|
|
10
|
+
try {
|
|
11
|
+
const trimmed = svg.trim();
|
|
12
|
+
assert(trimmed.length > 0);
|
|
13
|
+
const parser = new XMLParser({
|
|
14
|
+
ignoreAttributes: false,
|
|
15
|
+
parseAttributeValue: true,
|
|
16
|
+
});
|
|
17
|
+
const parsed = parser.parse(trimmed, true);
|
|
18
|
+
assert(hasProperty(parsed, 'svg'));
|
|
19
|
+
// Empty SVGs are not returned as objects
|
|
20
|
+
if (!isObject(parsed.svg)) {
|
|
21
|
+
return {};
|
|
22
|
+
}
|
|
23
|
+
return parsed.svg;
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
throw new Error('Snap icon must be a valid SVG.');
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Validate that a string is a valid SVG.
|
|
31
|
+
*
|
|
32
|
+
* @param svg - An SVG string.
|
|
33
|
+
* @returns True if the SVG is valid otherwise false.
|
|
34
|
+
*/
|
|
35
|
+
export function isSvg(svg) {
|
|
36
|
+
try {
|
|
37
|
+
parseSvg(svg);
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
10
44
|
//# sourceMappingURL=svg.mjs.map
|
package/dist/svg.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"
|
|
1
|
+
{"version":3,"file":"svg.mjs","sourceRoot":"","sources":["../src/svg.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,wBAAwB;AAChE,OAAO,EAAE,SAAS,EAAE,wBAAwB;AAE5C;;;;;GAKG;AACH,MAAM,UAAU,QAAQ,CAAC,GAAW;IAClC,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,GAAG,CAAC,IAAI,EAAE,CAAC;QAE3B,MAAM,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QAE3B,MAAM,MAAM,GAAG,IAAI,SAAS,CAAC;YAC3B,gBAAgB,EAAE,KAAK;YACvB,mBAAmB,EAAE,IAAI;SAC1B,CAAC,CAAC;QACH,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QAE3C,MAAM,CAAC,WAAW,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;QAEnC,yCAAyC;QACzC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC;YAC1B,OAAO,EAAE,CAAC;QACZ,CAAC;QAED,OAAO,MAAM,CAAC,GAAG,CAAC;IACpB,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;IACpD,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,KAAK,CAAC,GAAW;IAC/B,IAAI,CAAC;QACH,QAAQ,CAAC,GAAG,CAAC,CAAC;QACd,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC","sourcesContent":["import { assert, hasProperty, isObject } from '@metamask/utils';\nimport { XMLParser } from 'fast-xml-parser';\n\n/**\n * Parse and validate a string as an SVG.\n *\n * @param svg - An SVG string.\n * @returns The SVG, its attributes and children in an object format.\n */\nexport function parseSvg(svg: string) {\n try {\n const trimmed = svg.trim();\n\n assert(trimmed.length > 0);\n\n const parser = new XMLParser({\n ignoreAttributes: false,\n parseAttributeValue: true,\n });\n const parsed = parser.parse(trimmed, true);\n\n assert(hasProperty(parsed, 'svg'));\n\n // Empty SVGs are not returned as objects\n if (!isObject(parsed.svg)) {\n return {};\n }\n\n return parsed.svg;\n } catch {\n throw new Error('Snap icon must be a valid SVG.');\n }\n}\n\n/**\n * Validate that a string is a valid SVG.\n *\n * @param svg - An SVG string.\n * @returns True if the SVG is valid otherwise false.\n */\nexport function isSvg(svg: string) {\n try {\n parseSvg(svg);\n return true;\n } catch {\n return false;\n }\n}\n"]}
|
package/dist/types.cjs
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WALLET_SNAP_PERMISSION_KEY = exports.isValidUrl = exports.uri = exports.SNAP_STREAM_NAMES = exports.SnapIdPrefixes = exports.NpmSnapPackageJsonStruct = exports.NameStruct = exports.NpmSnapFileNames = void 0;
|
|
4
|
+
const superstruct_1 = require("@metamask/superstruct");
|
|
5
|
+
const utils_1 = require("@metamask/utils");
|
|
6
|
+
var NpmSnapFileNames;
|
|
7
|
+
(function (NpmSnapFileNames) {
|
|
8
|
+
NpmSnapFileNames["PackageJson"] = "package.json";
|
|
9
|
+
NpmSnapFileNames["Manifest"] = "snap.manifest.json";
|
|
10
|
+
})(NpmSnapFileNames || (exports.NpmSnapFileNames = NpmSnapFileNames = {}));
|
|
11
|
+
exports.NameStruct = (0, superstruct_1.size)((0, superstruct_1.pattern)((0, superstruct_1.string)(), /^(?:@[a-z0-9-*~][a-z0-9-*._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/u), 1, 214);
|
|
12
|
+
// Note we use `type` instead of `object` here, because the latter does not
|
|
13
|
+
// allow unknown keys.
|
|
14
|
+
exports.NpmSnapPackageJsonStruct = (0, superstruct_1.type)({
|
|
15
|
+
version: utils_1.VersionStruct,
|
|
16
|
+
name: exports.NameStruct,
|
|
17
|
+
main: (0, superstruct_1.optional)((0, superstruct_1.size)((0, superstruct_1.string)(), 1, Infinity)),
|
|
18
|
+
repository: (0, superstruct_1.optional)((0, superstruct_1.object)({
|
|
19
|
+
type: (0, superstruct_1.size)((0, superstruct_1.string)(), 1, Infinity),
|
|
20
|
+
url: (0, superstruct_1.size)((0, superstruct_1.string)(), 1, Infinity),
|
|
21
|
+
})),
|
|
22
|
+
});
|
|
23
|
+
/**
|
|
24
|
+
* The possible prefixes for snap ids.
|
|
25
|
+
*/
|
|
26
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
|
27
|
+
var SnapIdPrefixes;
|
|
28
|
+
(function (SnapIdPrefixes) {
|
|
29
|
+
SnapIdPrefixes["npm"] = "npm:";
|
|
30
|
+
SnapIdPrefixes["local"] = "local:";
|
|
31
|
+
})(SnapIdPrefixes || (exports.SnapIdPrefixes = SnapIdPrefixes = {}));
|
|
32
|
+
/* eslint-enable @typescript-eslint/naming-convention */
|
|
33
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
|
34
|
+
var SNAP_STREAM_NAMES;
|
|
35
|
+
(function (SNAP_STREAM_NAMES) {
|
|
36
|
+
SNAP_STREAM_NAMES["JSON_RPC"] = "jsonRpc";
|
|
37
|
+
SNAP_STREAM_NAMES["COMMAND"] = "command";
|
|
38
|
+
})(SNAP_STREAM_NAMES || (exports.SNAP_STREAM_NAMES = SNAP_STREAM_NAMES = {}));
|
|
39
|
+
const uri = (opts = {}) => (0, superstruct_1.refine)((0, superstruct_1.union)([(0, superstruct_1.string)(), (0, superstruct_1.instance)(URL)]), 'uri', (value) => {
|
|
40
|
+
try {
|
|
41
|
+
const url = new URL(value);
|
|
42
|
+
const UrlStruct = (0, superstruct_1.type)(opts);
|
|
43
|
+
(0, superstruct_1.assert)(url, UrlStruct);
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
return `Expected URL, got "${value.toString()}".`;
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
exports.uri = uri;
|
|
51
|
+
/**
|
|
52
|
+
* Returns whether a given value is a valid URL.
|
|
53
|
+
*
|
|
54
|
+
* @param url - The value to check.
|
|
55
|
+
* @param opts - Optional constraints for url checking.
|
|
56
|
+
* @returns Whether `url` is valid URL or not.
|
|
57
|
+
*/
|
|
58
|
+
function isValidUrl(url, opts = {}) {
|
|
59
|
+
return (0, superstruct_1.is)(url, (0, exports.uri)(opts));
|
|
60
|
+
}
|
|
61
|
+
exports.isValidUrl = isValidUrl;
|
|
62
|
+
// redefining here to avoid circular dependency
|
|
63
|
+
exports.WALLET_SNAP_PERMISSION_KEY = 'wallet_snap';
|
|
64
|
+
//# sourceMappingUR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,MAAM,GAAG,GAAG,CAAC,OAAwB,EAAE,EAAE,EAAE,CAChD,IAAA,oBAAM,EAAC,IAAA,mBAAK,EAAC,CAAC,IAAA,oBAAM,GAAE,EAAE,IAAA,sBAAQ,EAAC,GAAG,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE;IACxD,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC;QAE3B,MAAM,SAAS,GAAG,IAAA,kBAAI,EAAC,IAAI,CAAC,CAAC;QAC7B,IAAA,oBAAiB,EAAC,GAAG,EAAE,SAAS,CAAC,CAAC;QAClC,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,sBAAsB,KAAK,CAAC,QAAQ,EAAE,IAAI,CAAC;IACpD,CAAC;AACH,CAAC,CAAC,CAAC;AAXQ,QAAA,GAAG,OAWX;AAEL;;;;;;GAMG;AACH,SAAgB,UAAU,CACxB,GAAY,EACZ,OAAwB,EAAE;IAE1B,OAAO,IAAA,gBAAE,EAAC,GAAG,EAAE,IAAA,WAAG,EAAC,IAAI,CAAC,CAAC,CAAC;AAC5B,CAAC;AALD,gCAKC;AAED,+CAA+C;AAClC,QAAA,0BAA0B,GAAG,aAAa,CAAC","sourcesContent":["import {\n instance,\n is,\n object,\n optional,\n pattern,\n refine,\n size,\n string,\n type,\n union,\n assert as assertSuperstruct,\n} from '@metamask/superstruct';\nimport type { Infer, Struct } from '@metamask/superstruct';\nimport type { Json } from '@metamask/utils';\nimport { VersionStruct } from '@metamask/utils';\n\nimport type { SnapCaveatType } from './caveats';\nimport type { SnapFunctionExports, SnapRpcHookArgs } from './handlers';\nimport type { LocalizationFile } from './localization';\nimport type { SnapManifest } from './manifest';\nimport type { VirtualFile } from './virtual-file';\n\nexport enum NpmSnapFileNames {\n PackageJson = 'package.json',\n Manifest = 'snap.manifest.json',\n}\n\nexport const NameStruct = size(\n pattern(\n string(),\n /^(?:@[a-z0-9-*~][a-z0-9-*._~]*\\/)?[a-z0-9-~][a-z0-9-._~]*$/u,\n ),\n 1,\n 214,\n);\n\n// Note we use `type` instead of `object` here, because the latter does not\n// allow unknown keys.\nexport const NpmSnapPackageJsonStruct = type({\n version: VersionStruct,\n name: NameStruct,\n main: optional(size(string(), 1, Infinity)),\n repository: optional(\n object({\n type: size(string(), 1, Infinity),\n url: size(string(), 1, Infinity),\n }),\n ),\n});\n\nexport type NpmSnapPackageJson = Infer<typeof NpmSnapPackageJsonStruct> &\n Record<string, any>;\n\n/**\n * An object for storing parsed but unvalidated Snap file contents.\n */\nexport type UnvalidatedSnapFiles = {\n manifest?: VirtualFile<Json>;\n packageJson?: VirtualFile<Json>;\n sourceCode?: VirtualFile;\n svgIcon?: VirtualFile;\n auxiliaryFiles: VirtualFile[];\n localizationFiles: VirtualFile[];\n};\n\n/**\n * An object for storing the contents of Snap files that have passed JSON\n * Schema validation, or are non-empty if they are strings.\n */\nexport type SnapFiles = {\n manifest: VirtualFile<SnapManifest>;\n packageJson: VirtualFile<NpmSnapPackageJson>;\n sourceCode: VirtualFile;\n svgIcon?: VirtualFile;\n auxiliaryFiles: VirtualFile[];\n localizationFiles: VirtualFile<LocalizationFile>[];\n};\n\n/**\n * A subset of snap files extracted from a fetched snap.\n */\nexport type FetchedSnapFiles = Pick<\n SnapFiles,\n 'manifest' | 'sourceCode' | 'svgIcon' | 'auxiliaryFiles' | 'localizationFiles'\n>;\n\n/**\n * The possible prefixes for snap ids.\n */\n/* eslint-disable @typescript-eslint/naming-convention */\nexport enum SnapIdPrefixes {\n npm = 'npm:',\n local = 'local:',\n}\n/* eslint-enable @typescript-eslint/naming-convention */\n\n/* eslint-disable @typescript-eslint/naming-convention */\nexport enum SNAP_STREAM_NAMES {\n JSON_RPC = 'jsonRpc',\n COMMAND = 'command',\n}\n/* eslint-enable @typescript-eslint/naming-convention */\n\n// The snap is the callee\nexport type SnapRpcHook = (options: SnapRpcHookArgs) => Promise<unknown>;\n\ntype ObjectParameters<\n Type extends Record<string, (...args: any[]) => unknown>,\n> = Parameters<Type[keyof Type]>;\n\nexport type SnapExportsParameters = ObjectParameters<SnapFunctionExports>;\n\ntype UriOptions<Type extends string> = {\n protocol?: Struct<Type>;\n hash?: Struct<Type>;\n port?: Struct<Type>;\n hostname?: Struct<Type>;\n pathname?: Struct<Type>;\n search?: Struct<Type>;\n};\n\nexport const uri = (opts: UriOptions<any> = {}) =>\n refine(union([string(), instance(URL)]), 'uri', (value) => {\n try {\n const url = new URL(value);\n\n const UrlStruct = type(opts);\n assertSuperstruct(url, UrlStruct);\n return true;\n } catch {\n return `Expected URL, got \"${value.toString()}\".`;\n }\n });\n\n/**\n * Returns whether a given value is a valid URL.\n *\n * @param url - The value to check.\n * @param opts - Optional constraints for url checking.\n * @returns Whether `url` is valid URL or not.\n */\nexport function isValidUrl(\n url: unknown,\n opts: UriOptions<any> = {},\n): url is string | URL {\n return is(url, uri(opts));\n}\n\n// redefining here to avoid circular dependency\nexport const WALLET_SNAP_PERMISSION_KEY = 'wallet_snap';\n\nexport type SnapsPermissionRequest = {\n [WALLET_SNAP_PERMISSION_KEY]: {\n caveats: [\n {\n type: SnapCaveatType.SnapIds;\n value: Record<string, Json>;\n },\n ];\n };\n};\n"]}
|