@metamask/snaps-utils 11.7.0 → 12.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +28 -1
- package/dist/checksum.cjs +1 -9
- package/dist/checksum.cjs.map +1 -1
- package/dist/checksum.d.cts.map +1 -1
- package/dist/checksum.d.mts.map +1 -1
- package/dist/checksum.mjs +2 -10
- package/dist/checksum.mjs.map +1 -1
- package/dist/handlers/assets-market-data.cjs +2 -2
- package/dist/handlers/assets-market-data.cjs.map +1 -1
- package/dist/handlers/assets-market-data.d.cts +2 -2
- package/dist/handlers/assets-market-data.d.mts +2 -2
- package/dist/handlers/assets-market-data.mjs +2 -2
- package/dist/handlers/assets-market-data.mjs.map +1 -1
- package/dist/iframe.cjs +1 -1
- package/dist/iframe.cjs.map +1 -1
- package/dist/iframe.d.cts.map +1 -1
- package/dist/iframe.d.mts.map +1 -1
- package/dist/iframe.mjs +1 -1
- package/dist/iframe.mjs.map +1 -1
- package/dist/localization.d.cts +1 -0
- package/dist/localization.d.cts.map +1 -1
- package/dist/localization.d.mts +1 -0
- package/dist/localization.d.mts.map +1 -1
- package/dist/manifest/manifest.cjs +99 -27
- package/dist/manifest/manifest.cjs.map +1 -1
- package/dist/manifest/manifest.d.cts +18 -5
- package/dist/manifest/manifest.d.cts.map +1 -1
- package/dist/manifest/manifest.d.mts +18 -5
- package/dist/manifest/manifest.d.mts.map +1 -1
- package/dist/manifest/manifest.mjs +106 -28
- package/dist/manifest/manifest.mjs.map +1 -1
- package/dist/manifest/validation.cjs +1 -0
- package/dist/manifest/validation.cjs.map +1 -1
- package/dist/manifest/validation.d.cts +2 -0
- package/dist/manifest/validation.d.cts.map +1 -1
- package/dist/manifest/validation.d.mts +2 -0
- package/dist/manifest/validation.d.mts.map +1 -1
- package/dist/manifest/validation.mjs +1 -0
- package/dist/manifest/validation.mjs.map +1 -1
- package/dist/manifest/validator-types.cjs.map +1 -1
- package/dist/manifest/validator-types.d.cts +4 -5
- package/dist/manifest/validator-types.d.cts.map +1 -1
- package/dist/manifest/validator-types.d.mts +4 -5
- package/dist/manifest/validator-types.d.mts.map +1 -1
- package/dist/manifest/validator-types.mjs.map +1 -1
- package/dist/manifest/validator.cjs +1 -1
- package/dist/manifest/validator.cjs.map +1 -1
- package/dist/manifest/validator.d.cts +3 -3
- package/dist/manifest/validator.d.cts.map +1 -1
- package/dist/manifest/validator.d.mts +3 -3
- package/dist/manifest/validator.d.mts.map +1 -1
- package/dist/manifest/validator.mjs +1 -1
- package/dist/manifest/validator.mjs.map +1 -1
- package/dist/manifest/validators/checksum.cjs +11 -3
- package/dist/manifest/validators/checksum.cjs.map +1 -1
- package/dist/manifest/validators/checksum.d.cts.map +1 -1
- package/dist/manifest/validators/checksum.d.mts.map +1 -1
- package/dist/manifest/validators/checksum.mjs +11 -3
- package/dist/manifest/validators/checksum.mjs.map +1 -1
- package/dist/manifest/validators/icon-declared.cjs +1 -1
- package/dist/manifest/validators/icon-declared.cjs.map +1 -1
- package/dist/manifest/validators/icon-declared.mjs +1 -1
- package/dist/manifest/validators/icon-declared.mjs.map +1 -1
- package/dist/manifest/validators/icon-missing.cjs +1 -1
- package/dist/manifest/validators/icon-missing.cjs.map +1 -1
- package/dist/manifest/validators/icon-missing.d.cts.map +1 -1
- package/dist/manifest/validators/icon-missing.d.mts.map +1 -1
- package/dist/manifest/validators/icon-missing.mjs +1 -1
- package/dist/manifest/validators/icon-missing.mjs.map +1 -1
- package/dist/manifest/validators/is-snap-manifest.cjs +1 -1
- package/dist/manifest/validators/is-snap-manifest.cjs.map +1 -1
- package/dist/manifest/validators/is-snap-manifest.mjs +1 -1
- package/dist/manifest/validators/is-snap-manifest.mjs.map +1 -1
- package/dist/manifest/validators/manifest-localization.cjs +1 -1
- package/dist/manifest/validators/manifest-localization.cjs.map +1 -1
- package/dist/manifest/validators/manifest-localization.mjs +1 -1
- package/dist/manifest/validators/manifest-localization.mjs.map +1 -1
- package/dist/manifest/validators/package-name-match.cjs +6 -2
- package/dist/manifest/validators/package-name-match.cjs.map +1 -1
- package/dist/manifest/validators/package-name-match.d.cts.map +1 -1
- package/dist/manifest/validators/package-name-match.d.mts.map +1 -1
- package/dist/manifest/validators/package-name-match.mjs +6 -2
- package/dist/manifest/validators/package-name-match.mjs.map +1 -1
- package/dist/manifest/validators/platform-version.cjs +4 -4
- package/dist/manifest/validators/platform-version.cjs.map +1 -1
- package/dist/manifest/validators/platform-version.d.cts.map +1 -1
- package/dist/manifest/validators/platform-version.d.mts.map +1 -1
- package/dist/manifest/validators/platform-version.mjs +4 -4
- package/dist/manifest/validators/platform-version.mjs.map +1 -1
- package/dist/manifest/validators/production-platform-version.cjs +1 -1
- package/dist/manifest/validators/production-platform-version.cjs.map +1 -1
- package/dist/manifest/validators/production-platform-version.d.cts.map +1 -1
- package/dist/manifest/validators/production-platform-version.d.mts.map +1 -1
- package/dist/manifest/validators/production-platform-version.mjs +1 -1
- package/dist/manifest/validators/production-platform-version.mjs.map +1 -1
- package/dist/manifest/validators/repository-match.cjs +2 -2
- package/dist/manifest/validators/repository-match.cjs.map +1 -1
- package/dist/manifest/validators/repository-match.d.cts.map +1 -1
- package/dist/manifest/validators/repository-match.d.mts.map +1 -1
- package/dist/manifest/validators/repository-match.mjs +2 -2
- package/dist/manifest/validators/repository-match.mjs.map +1 -1
- package/dist/manifest/validators/unused-exports.cjs +3 -3
- package/dist/manifest/validators/unused-exports.cjs.map +1 -1
- package/dist/manifest/validators/unused-exports.mjs +3 -3
- package/dist/manifest/validators/unused-exports.mjs.map +1 -1
- package/dist/manifest/validators/version-match.cjs +2 -2
- package/dist/manifest/validators/version-match.cjs.map +1 -1
- package/dist/manifest/validators/version-match.mjs +2 -2
- package/dist/manifest/validators/version-match.mjs.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +66 -1
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +66 -1
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/package.json +5 -6
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,31 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [12.0.0]
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- Add `loadManifest` function to load extendable manifests ([#3793](https://github.com/MetaMask/snaps/pull/3793))
|
|
15
|
+
|
|
16
|
+
### Changed
|
|
17
|
+
|
|
18
|
+
- **BREAKING:** Allow manifest to extend another manifest ([#3802](https://github.com/MetaMask/snaps/pull/3802))
|
|
19
|
+
- `checkManifest` now returns `ExtendableSnapFiles`, containing a manifest
|
|
20
|
+
that may extend another manifest.
|
|
21
|
+
- **BREAKING:** Require path to manifest instead of directory in `checkManifest` function ([#3793](https://github.com/MetaMask/snaps/pull/3793))
|
|
22
|
+
|
|
23
|
+
## [11.7.1]
|
|
24
|
+
|
|
25
|
+
### Changed
|
|
26
|
+
|
|
27
|
+
- Use `sha256` utility from `@metamask/utils` ([#3781](https://github.com/MetaMask/snaps/pull/3781))
|
|
28
|
+
- Bump MetaMask dependencies ([#3783](https://github.com/MetaMask/snaps/pull/3783), [#3748](https://github.com/MetaMask/snaps/pull/3748), [#3791](https://github.com/MetaMask/snaps/pull/3791))
|
|
29
|
+
- Fix some typos in the documentation ([#3739](https://github.com/MetaMask/snaps/pull/3739))
|
|
30
|
+
|
|
31
|
+
### Fixed
|
|
32
|
+
|
|
33
|
+
- Ensure iframe load listener is removed ([#3797](https://github.com/MetaMask/snaps/pull/3797))
|
|
34
|
+
|
|
10
35
|
## [11.7.0]
|
|
11
36
|
|
|
12
37
|
### Added
|
|
@@ -742,7 +767,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
742
767
|
- The version of the package no longer needs to match the version of all other
|
|
743
768
|
MetaMask Snaps packages.
|
|
744
769
|
|
|
745
|
-
[Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-utils@
|
|
770
|
+
[Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-utils@12.0.0...HEAD
|
|
771
|
+
[12.0.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-utils@11.7.1...@metamask/snaps-utils@12.0.0
|
|
772
|
+
[11.7.1]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-utils@11.7.0...@metamask/snaps-utils@11.7.1
|
|
746
773
|
[11.7.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-utils@11.6.3...@metamask/snaps-utils@11.7.0
|
|
747
774
|
[11.6.3]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-utils@11.6.2...@metamask/snaps-utils@11.6.3
|
|
748
775
|
[11.6.2]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-utils@11.6.1...@metamask/snaps-utils@11.6.2
|
package/dist/checksum.cjs
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.checksumFiles = exports.checksum = void 0;
|
|
4
4
|
const utils_1 = require("@metamask/utils");
|
|
5
|
-
const sha256_1 = require("@noble/hashes/sha256");
|
|
6
5
|
const bytes_1 = require("./bytes.cjs");
|
|
7
6
|
/**
|
|
8
7
|
* Calculates checksum for a single byte array.
|
|
@@ -11,14 +10,7 @@ const bytes_1 = require("./bytes.cjs");
|
|
|
11
10
|
* @returns A single sha-256 checksum.
|
|
12
11
|
*/
|
|
13
12
|
async function checksum(bytes) {
|
|
14
|
-
|
|
15
|
-
// Use crypto.subtle.digest whenever possible as it is faster.
|
|
16
|
-
if ('crypto' in globalThis &&
|
|
17
|
-
typeof globalThis.crypto === 'object' &&
|
|
18
|
-
crypto.subtle?.digest) {
|
|
19
|
-
return new Uint8Array(await crypto.subtle.digest('SHA-256', value));
|
|
20
|
-
}
|
|
21
|
-
return (0, sha256_1.sha256)(value);
|
|
13
|
+
return await (0, utils_1.sha256)((0, bytes_1.getBytes)(bytes));
|
|
22
14
|
}
|
|
23
15
|
exports.checksum = checksum;
|
|
24
16
|
/**
|
package/dist/checksum.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checksum.cjs","sourceRoot":"","sources":["../src/checksum.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"checksum.cjs","sourceRoot":"","sources":["../src/checksum.ts"],"names":[],"mappings":";;;AAAA,2CAA8D;AAE9D,uCAAmC;AAGnC;;;;;GAKG;AACI,KAAK,UAAU,QAAQ,CAC5B,KAAwC;IAExC,OAAO,MAAM,IAAA,cAAM,EAAC,IAAA,gBAAQ,EAAC,KAAK,CAAC,CAAC,CAAC;AACvC,CAAC;AAJD,4BAIC;AAED;;;;;;;;;;;GAWG;AACI,KAAK,UAAU,aAAa,CAAC,KAAoB;IACtD,MAAM,SAAS,GAAG,MAAM,OAAO,CAAC,GAAG,CACjC,CAAC,GAAG,KAAK,CAAC;SACP,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;QACb,IAAA,cAAM,EAAC,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,IAAI,EAAE,4CAA4C,CAAC,CAAC;QACxE,IAAI,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;YACpB,OAAO,CAAC,CAAC,CAAC;QACZ,CAAC;QACD,OAAO,CAAC,CAAC;IACX,CAAC,CAAC;SACD,GAAG,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CACvC,CAAC;IAEF,OAAO,QAAQ,CAAC,IAAA,mBAAW,EAAC,SAAS,CAAC,CAAC,CAAC;AAC1C,CAAC;AAdD,sCAcC","sourcesContent":["import { assert, concatBytes, sha256 } from '@metamask/utils';\n\nimport { getBytes } from './bytes';\nimport type { VirtualFile } from './virtual-file';\n\n/**\n * Calculates checksum for a single byte array.\n *\n * @param bytes - The byte array to calculate the checksum for.\n * @returns A single sha-256 checksum.\n */\nexport async function checksum(\n bytes: VirtualFile | Uint8Array | string,\n): Promise<Uint8Array> {\n return await sha256(getBytes(bytes));\n}\n\n/**\n * Calculates checksum over multiple files in a reproducible way.\n *\n * 1. Sort all the files by their paths.\n * 2. Calculate sha-256 checksum of each file separately.\n * 3. Concatenate all the checksums into one buffer and sha-256 that buffer.\n *\n * The sorting of paths is done using {@link https://tc39.es/ecma262/#sec-islessthan UTF-16 Code Units}.\n *\n * @param files - The files over which to calculate the checksum.\n * @returns A single sha-256 checksum.\n */\nexport async function checksumFiles(files: VirtualFile[]) {\n const checksums = await Promise.all(\n [...files]\n .sort((a, b) => {\n assert(a.path !== b.path, 'Tried to sort files with non-unique paths.');\n if (a.path < b.path) {\n return -1;\n }\n return 1;\n })\n .map(async (file) => checksum(file)),\n );\n\n return checksum(concatBytes(checksums));\n}\n"]}
|
package/dist/checksum.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checksum.d.cts","sourceRoot":"","sources":["../src/checksum.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"checksum.d.cts","sourceRoot":"","sources":["../src/checksum.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,iCAAuB;AAElD;;;;;GAKG;AACH,wBAAsB,QAAQ,CAC5B,KAAK,EAAE,WAAW,GAAG,UAAU,GAAG,MAAM,GACvC,OAAO,CAAC,UAAU,CAAC,CAErB;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,aAAa,CAAC,KAAK,EAAE,WAAW,EAAE,uBAcvD"}
|
package/dist/checksum.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checksum.d.mts","sourceRoot":"","sources":["../src/checksum.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"checksum.d.mts","sourceRoot":"","sources":["../src/checksum.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,iCAAuB;AAElD;;;;;GAKG;AACH,wBAAsB,QAAQ,CAC5B,KAAK,EAAE,WAAW,GAAG,UAAU,GAAG,MAAM,GACvC,OAAO,CAAC,UAAU,CAAC,CAErB;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,aAAa,CAAC,KAAK,EAAE,WAAW,EAAE,uBAcvD"}
|
package/dist/checksum.mjs
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { assert, concatBytes } from "@metamask/utils";
|
|
2
|
-
import { sha256 } from "@noble/hashes/sha256";
|
|
1
|
+
import { assert, concatBytes, sha256 } from "@metamask/utils";
|
|
3
2
|
import { getBytes } from "./bytes.mjs";
|
|
4
3
|
/**
|
|
5
4
|
* Calculates checksum for a single byte array.
|
|
@@ -8,14 +7,7 @@ import { getBytes } from "./bytes.mjs";
|
|
|
8
7
|
* @returns A single sha-256 checksum.
|
|
9
8
|
*/
|
|
10
9
|
export async function checksum(bytes) {
|
|
11
|
-
|
|
12
|
-
// Use crypto.subtle.digest whenever possible as it is faster.
|
|
13
|
-
if ('crypto' in globalThis &&
|
|
14
|
-
typeof globalThis.crypto === 'object' &&
|
|
15
|
-
crypto.subtle?.digest) {
|
|
16
|
-
return new Uint8Array(await crypto.subtle.digest('SHA-256', value));
|
|
17
|
-
}
|
|
18
|
-
return sha256(value);
|
|
10
|
+
return await sha256(getBytes(bytes));
|
|
19
11
|
}
|
|
20
12
|
/**
|
|
21
13
|
* Calculates checksum over multiple files in a reproducible way.
|
package/dist/checksum.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checksum.mjs","sourceRoot":"","sources":["../src/checksum.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,
|
|
1
|
+
{"version":3,"file":"checksum.mjs","sourceRoot":"","sources":["../src/checksum.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,wBAAwB;AAE9D,OAAO,EAAE,QAAQ,EAAE,oBAAgB;AAGnC;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,QAAQ,CAC5B,KAAwC;IAExC,OAAO,MAAM,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;AACvC,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,KAAoB;IACtD,MAAM,SAAS,GAAG,MAAM,OAAO,CAAC,GAAG,CACjC,CAAC,GAAG,KAAK,CAAC;SACP,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;QACb,MAAM,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,IAAI,EAAE,4CAA4C,CAAC,CAAC;QACxE,IAAI,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;YACpB,OAAO,CAAC,CAAC,CAAC;QACZ,CAAC;QACD,OAAO,CAAC,CAAC;IACX,CAAC,CAAC;SACD,GAAG,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CACvC,CAAC;IAEF,OAAO,QAAQ,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC,CAAC;AAC1C,CAAC","sourcesContent":["import { assert, concatBytes, sha256 } from '@metamask/utils';\n\nimport { getBytes } from './bytes';\nimport type { VirtualFile } from './virtual-file';\n\n/**\n * Calculates checksum for a single byte array.\n *\n * @param bytes - The byte array to calculate the checksum for.\n * @returns A single sha-256 checksum.\n */\nexport async function checksum(\n bytes: VirtualFile | Uint8Array | string,\n): Promise<Uint8Array> {\n return await sha256(getBytes(bytes));\n}\n\n/**\n * Calculates checksum over multiple files in a reproducible way.\n *\n * 1. Sort all the files by their paths.\n * 2. Calculate sha-256 checksum of each file separately.\n * 3. Concatenate all the checksums into one buffer and sha-256 that buffer.\n *\n * The sorting of paths is done using {@link https://tc39.es/ecma262/#sec-islessthan UTF-16 Code Units}.\n *\n * @param files - The files over which to calculate the checksum.\n * @returns A single sha-256 checksum.\n */\nexport async function checksumFiles(files: VirtualFile[]) {\n const checksums = await Promise.all(\n [...files]\n .sort((a, b) => {\n assert(a.path !== b.path, 'Tried to sort files with non-unique paths.');\n if (a.path < b.path) {\n return -1;\n }\n return 1;\n })\n .map(async (file) => checksum(file)),\n );\n\n return checksum(concatBytes(checksums));\n}\n"]}
|
|
@@ -36,7 +36,7 @@ exports.FungibleAssetMarketDataStruct = (0, superstruct_1.object)({
|
|
|
36
36
|
* A struct representing an asset value, which includes the asset type and the amount.
|
|
37
37
|
*
|
|
38
38
|
* @property asset - The CAIP-19 asset type or ID of the asset.
|
|
39
|
-
* @property amount - The
|
|
39
|
+
* @property amount - The price represented as a number in string format.
|
|
40
40
|
*/
|
|
41
41
|
exports.AssetValueStruct = (0, superstruct_1.object)({
|
|
42
42
|
asset: utils_1.CaipAssetTypeOrIdStruct,
|
|
@@ -46,7 +46,7 @@ exports.AssetValueStruct = (0, superstruct_1.object)({
|
|
|
46
46
|
* A struct representing the market data for a non-fungible asset.
|
|
47
47
|
*
|
|
48
48
|
* @property asset - The CAIP-19 asset type or ID of the asset.
|
|
49
|
-
* @property amount - The
|
|
49
|
+
* @property amount - The price represented as a number in string format.
|
|
50
50
|
* @property fungible - Indicates that this is a non-fungible asset.
|
|
51
51
|
* This is always `false` for non-fungible assets.
|
|
52
52
|
* @property lastSale - The last sale price of the asset, if available. See {@link AssetValueStruct}.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assets-market-data.cjs","sourceRoot":"","sources":["../../src/handlers/assets-market-data.ts"],"names":[],"mappings":";;;AAAA,mDAAqE;AACrE,uDAS+B;AAC/B,2CAIyB;AAEzB,sCAAgD;AAEhD;;GAEG;AACU,QAAA,wBAAwB,GAAG,IAAA,0BAAc,EACpD,IAAA,mBAAK,EAAC,CAAC,IAAA,qBAAO,EAAC,KAAK,CAA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AAE,IAAA,sBAAQ,EAAC,IAAA,oBAAM,EAAC,IAAA,oBAAM,GAAE,EAAE,IAAA,oBAAM,GAAE,CAAC,CAAC;KAC/C,CAAC,CACH;CACF,CAAC,CAAC;AAEH;;GAEG;AACU,QAAA,qBAAqB,GAAG,IAAA,0BAAc,EAAC,CAAC,UAAU,EAAE,EAAE;IACjE,IAAI,IAAA,gBAAQ,EAAC,UAAU,CAAC,IAAI,UAAU,CAAC,QAAQ,EAAE,CAAC;QAChD,OAAO,qCAA6B,CAAC;IACvC,CAAC;IAED,OAAO,wCAAgC,CAAC;AAC1C,CAAC,CAAC,CAAC;AAEH;;;;GAIG;AACU,QAAA,gCAAgC,GAAG,IAAA,oBAAM,EAAC;IACrD,UAAU,EAAE,IAAA,oBAAM,EAChB,+BAAuB,EACvB,IAAA,oBAAM,EAAC,2BAAmB,EAAE,IAAA,sBAAQ,EAAC,6BAAqB,CAAC,CAAC,CAC7D;CACF,CAAC,CAAC","sourcesContent":["import { nonEmptyRecord, selectiveUnion } from '@metamask/snaps-sdk';\nimport {\n literal,\n nullable,\n number,\n object,\n optional,\n record,\n string,\n union,\n} from '@metamask/superstruct';\nimport {\n CaipAssetTypeOrIdStruct,\n CaipAssetTypeStruct,\n isObject,\n} from '@metamask/utils';\n\nimport { ISO8601DurationStruct } from '../time';\n\n/**\n * A struct representing the market data for an asset.\n */\nexport const PricePercentChangeStruct = nonEmptyRecord(\n union([literal('all'), ISO8601DurationStruct]),\n number(),\n);\n\n/**\n * A struct representing the market data for a fungible asset.\n *\n * @property fungible - Indicates that this is a fungible asset.\n * This is always `true` for fungible assets.\n * @property marketCap - The market capitalization of the asset.\n * @property totalVolume - The total volume of the asset.\n * @property circulatingSupply - The circulating supply of the asset.\n * @property allTimeHigh - The all-time high price of the asset.\n * @property allTimeLow - The all-time low price of the asset.\n * @property pricePercentChange - The percentage change in price over different intervals.\n * @property pricePercentChange.interval - The time interval for the price change as a ISO 8601 duration\n * or the string \"all\" to represent the all-time change.\n */\nexport const FungibleAssetMarketDataStruct = object({\n fungible: literal(true),\n marketCap: optional(string()),\n totalVolume: optional(string()),\n circulatingSupply: optional(string()),\n allTimeHigh: optional(string()),\n allTimeLow: optional(string()),\n pricePercentChange: optional(PricePercentChangeStruct),\n});\n\n/**\n * A struct representing an asset value, which includes the asset type and the amount.\n *\n * @property asset - The CAIP-19 asset type or ID of the asset.\n * @property amount - The
|
|
1
|
+
{"version":3,"file":"assets-market-data.cjs","sourceRoot":"","sources":["../../src/handlers/assets-market-data.ts"],"names":[],"mappings":";;;AAAA,mDAAqE;AACrE,uDAS+B;AAC/B,2CAIyB;AAEzB,sCAAgD;AAEhD;;GAEG;AACU,QAAA,wBAAwB,GAAG,IAAA,0BAAc,EACpD,IAAA,mBAAK,EAAC,CAAC,IAAA,qBAAO,EAAC,KAAK,CAAC,EAAE,4BAAqB,CAAC,CAAC,EAC9C,IAAA,oBAAM,GAAE,CACT,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACU,QAAA,6BAA6B,GAAG,IAAA,oBAAM,EAAC;IAClD,QAAQ,EAAE,IAAA,qBAAO,EAAC,IAAI,CAAC;IACvB,SAAS,EAAE,IAAA,sBAAQ,EAAC,IAAA,oBAAM,GAAE,CAAC;IAC7B,WAAW,EAAE,IAAA,sBAAQ,EAAC,IAAA,oBAAM,GAAE,CAAC;IAC/B,iBAAiB,EAAE,IAAA,sBAAQ,EAAC,IAAA,oBAAM,GAAE,CAAC;IACrC,WAAW,EAAE,IAAA,sBAAQ,EAAC,IAAA,oBAAM,GAAE,CAAC;IAC/B,UAAU,EAAE,IAAA,sBAAQ,EAAC,IAAA,oBAAM,GAAE,CAAC;IAC9B,kBAAkB,EAAE,IAAA,sBAAQ,EAAC,gCAAwB,CAAC;CACvD,CAAC,CAAC;AAEH;;;;;GAKG;AACU,QAAA,gBAAgB,GAAG,IAAA,oBAAM,EAAC;IACrC,KAAK,EAAE,+BAAuB;IAC9B,MAAM,EAAE,IAAA,oBAAM,GAAE;CACjB,CAAC,CAAC;AAEH;;;;;;;;;;;;;;;;GAgBG;AACU,QAAA,gCAAgC,GAAG,IAAA,oBAAM,EAAC;IACrD,QAAQ,EAAE,IAAA,qBAAO,EAAC,KAAK,CAAC;IACxB,QAAQ,EAAE,IAAA,sBAAQ,EAAC,wBAAgB,CAAC;IACpC,MAAM,EAAE,IAAA,sBAAQ,EAAC,wBAAgB,CAAC;IAClC,UAAU,EAAE,IAAA,sBAAQ,EAAC,wBAAgB,CAAC;IACtC,MAAM,EAAE,IAAA,sBAAQ,EACd,IAAA,oBAAM,EAAC;QACL,OAAO,EAAE,IAAA,sBAAQ,EACf,IAAA,oBAAM,EAAC;YACL,MAAM,EAAE,IAAA,oBAAM,GAAE;YAChB,IAAI,EAAE,IAAA,oBAAM,GAAE;SACf,CAAC,CACH;QACD,QAAQ,EAAE,IAAA,sBAAQ,EAAC,IAAA,oBAAM,EAAC,IAAA,oBAAM,GAAE,EAAE,IAAA,oBAAM,GAAE,CAAC,CAAC;KAC/C,CAAC,CACH;CACF,CAAC,CAAC;AAEH;;GAEG;AACU,QAAA,qBAAqB,GAAG,IAAA,0BAAc,EAAC,CAAC,UAAU,EAAE,EAAE;IACjE,IAAI,IAAA,gBAAQ,EAAC,UAAU,CAAC,IAAI,UAAU,CAAC,QAAQ,EAAE,CAAC;QAChD,OAAO,qCAA6B,CAAC;IACvC,CAAC;IAED,OAAO,wCAAgC,CAAC;AAC1C,CAAC,CAAC,CAAC;AAEH;;;;GAIG;AACU,QAAA,gCAAgC,GAAG,IAAA,oBAAM,EAAC;IACrD,UAAU,EAAE,IAAA,oBAAM,EAChB,+BAAuB,EACvB,IAAA,oBAAM,EAAC,2BAAmB,EAAE,IAAA,sBAAQ,EAAC,6BAAqB,CAAC,CAAC,CAC7D;CACF,CAAC,CAAC","sourcesContent":["import { nonEmptyRecord, selectiveUnion } from '@metamask/snaps-sdk';\nimport {\n literal,\n nullable,\n number,\n object,\n optional,\n record,\n string,\n union,\n} from '@metamask/superstruct';\nimport {\n CaipAssetTypeOrIdStruct,\n CaipAssetTypeStruct,\n isObject,\n} from '@metamask/utils';\n\nimport { ISO8601DurationStruct } from '../time';\n\n/**\n * A struct representing the market data for an asset.\n */\nexport const PricePercentChangeStruct = nonEmptyRecord(\n union([literal('all'), ISO8601DurationStruct]),\n number(),\n);\n\n/**\n * A struct representing the market data for a fungible asset.\n *\n * @property fungible - Indicates that this is a fungible asset.\n * This is always `true` for fungible assets.\n * @property marketCap - The market capitalization of the asset.\n * @property totalVolume - The total volume of the asset.\n * @property circulatingSupply - The circulating supply of the asset.\n * @property allTimeHigh - The all-time high price of the asset.\n * @property allTimeLow - The all-time low price of the asset.\n * @property pricePercentChange - The percentage change in price over different intervals.\n * @property pricePercentChange.interval - The time interval for the price change as a ISO 8601 duration\n * or the string \"all\" to represent the all-time change.\n */\nexport const FungibleAssetMarketDataStruct = object({\n fungible: literal(true),\n marketCap: optional(string()),\n totalVolume: optional(string()),\n circulatingSupply: optional(string()),\n allTimeHigh: optional(string()),\n allTimeLow: optional(string()),\n pricePercentChange: optional(PricePercentChangeStruct),\n});\n\n/**\n * A struct representing an asset value, which includes the asset type and the amount.\n *\n * @property asset - The CAIP-19 asset type or ID of the asset.\n * @property amount - The price represented as a number in string format.\n */\nexport const AssetValueStruct = object({\n asset: CaipAssetTypeOrIdStruct,\n amount: string(),\n});\n\n/**\n * A struct representing the market data for a non-fungible asset.\n *\n * @property asset - The CAIP-19 asset type or ID of the asset.\n * @property amount - The price represented as a number in string format.\n * @property fungible - Indicates that this is a non-fungible asset.\n * This is always `false` for non-fungible assets.\n * @property lastSale - The last sale price of the asset, if available. See {@link AssetValueStruct}.\n * @property topBid - The top bid price for the asset, if available. See {@link AssetValueStruct}.\n * @property floorPrice - The floor price of the asset, if available. See {@link AssetValueStruct}.\n * @property rarity - The rarity information for the asset, if available.\n * @property rarity.ranking - The ranking of the asset's rarity, if available.\n * @property rarity.ranking.source - The source of the rarity ranking.\n * @property rarity.ranking.rank - The rank of the asset in the rarity ranking.\n * @property rarity.metadata - Additional metadata about the asset's rarity, if available.\n * This is a record of string keys and number values.\n */\nexport const NonFungibleAssetMarketDataStruct = object({\n fungible: literal(false),\n lastSale: optional(AssetValueStruct),\n topBid: optional(AssetValueStruct),\n floorPrice: optional(AssetValueStruct),\n rarity: optional(\n object({\n ranking: optional(\n object({\n source: string(),\n rank: number(),\n }),\n ),\n metadata: optional(record(string(), number())),\n }),\n ),\n});\n\n/**\n * A struct representing the market data for an asset, which can be either {@link FungibleAssetMarketDataStruct} or {@link NonFungibleAssetMarketDataStruct}.\n */\nexport const AssetMarketDataStruct = selectiveUnion((marketData) => {\n if (isObject(marketData) && marketData.fungible) {\n return FungibleAssetMarketDataStruct;\n }\n\n return NonFungibleAssetMarketDataStruct;\n});\n\n/**\n * A struct representing the response of the `onAssetsMarketData` method.\n *\n * @property marketData - A nested object with two CAIP-19 keys that contains a {@link AssetMarketData} object or null.\n */\nexport const OnAssetsMarketDataResponseStruct = object({\n marketData: record(\n CaipAssetTypeOrIdStruct,\n record(CaipAssetTypeStruct, nullable(AssetMarketDataStruct)),\n ),\n});\n"]}
|
|
@@ -37,7 +37,7 @@ export declare const FungibleAssetMarketDataStruct: import("@metamask/superstruc
|
|
|
37
37
|
* A struct representing an asset value, which includes the asset type and the amount.
|
|
38
38
|
*
|
|
39
39
|
* @property asset - The CAIP-19 asset type or ID of the asset.
|
|
40
|
-
* @property amount - The
|
|
40
|
+
* @property amount - The price represented as a number in string format.
|
|
41
41
|
*/
|
|
42
42
|
export declare const AssetValueStruct: import("@metamask/superstruct").Struct<{
|
|
43
43
|
asset: `${string}:${string}/${string}:${string}` | `${string}:${string}/${string}:${string}/${string}`;
|
|
@@ -50,7 +50,7 @@ export declare const AssetValueStruct: import("@metamask/superstruct").Struct<{
|
|
|
50
50
|
* A struct representing the market data for a non-fungible asset.
|
|
51
51
|
*
|
|
52
52
|
* @property asset - The CAIP-19 asset type or ID of the asset.
|
|
53
|
-
* @property amount - The
|
|
53
|
+
* @property amount - The price represented as a number in string format.
|
|
54
54
|
* @property fungible - Indicates that this is a non-fungible asset.
|
|
55
55
|
* This is always `false` for non-fungible assets.
|
|
56
56
|
* @property lastSale - The last sale price of the asset, if available. See {@link AssetValueStruct}.
|
|
@@ -37,7 +37,7 @@ export declare const FungibleAssetMarketDataStruct: import("@metamask/superstruc
|
|
|
37
37
|
* A struct representing an asset value, which includes the asset type and the amount.
|
|
38
38
|
*
|
|
39
39
|
* @property asset - The CAIP-19 asset type or ID of the asset.
|
|
40
|
-
* @property amount - The
|
|
40
|
+
* @property amount - The price represented as a number in string format.
|
|
41
41
|
*/
|
|
42
42
|
export declare const AssetValueStruct: import("@metamask/superstruct").Struct<{
|
|
43
43
|
asset: `${string}:${string}/${string}:${string}` | `${string}:${string}/${string}:${string}/${string}`;
|
|
@@ -50,7 +50,7 @@ export declare const AssetValueStruct: import("@metamask/superstruct").Struct<{
|
|
|
50
50
|
* A struct representing the market data for a non-fungible asset.
|
|
51
51
|
*
|
|
52
52
|
* @property asset - The CAIP-19 asset type or ID of the asset.
|
|
53
|
-
* @property amount - The
|
|
53
|
+
* @property amount - The price represented as a number in string format.
|
|
54
54
|
* @property fungible - Indicates that this is a non-fungible asset.
|
|
55
55
|
* This is always `false` for non-fungible assets.
|
|
56
56
|
* @property lastSale - The last sale price of the asset, if available. See {@link AssetValueStruct}.
|
|
@@ -33,7 +33,7 @@ export const FungibleAssetMarketDataStruct = object({
|
|
|
33
33
|
* A struct representing an asset value, which includes the asset type and the amount.
|
|
34
34
|
*
|
|
35
35
|
* @property asset - The CAIP-19 asset type or ID of the asset.
|
|
36
|
-
* @property amount - The
|
|
36
|
+
* @property amount - The price represented as a number in string format.
|
|
37
37
|
*/
|
|
38
38
|
export const AssetValueStruct = object({
|
|
39
39
|
asset: CaipAssetTypeOrIdStruct,
|
|
@@ -43,7 +43,7 @@ export const AssetValueStruct = object({
|
|
|
43
43
|
* A struct representing the market data for a non-fungible asset.
|
|
44
44
|
*
|
|
45
45
|
* @property asset - The CAIP-19 asset type or ID of the asset.
|
|
46
|
-
* @property amount - The
|
|
46
|
+
* @property amount - The price represented as a number in string format.
|
|
47
47
|
* @property fungible - Indicates that this is a non-fungible asset.
|
|
48
48
|
* This is always `false` for non-fungible assets.
|
|
49
49
|
* @property lastSale - The last sale price of the asset, if available. See {@link AssetValueStruct}.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assets-market-data.mjs","sourceRoot":"","sources":["../../src/handlers/assets-market-data.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,4BAA4B;AACrE,OAAO,EACL,OAAO,EACP,QAAQ,EACR,MAAM,EACN,MAAM,EACN,QAAQ,EACR,MAAM,EACN,MAAM,EACN,KAAK,EACN,8BAA8B;AAC/B,OAAO,EACL,uBAAuB,EACvB,mBAAmB,EACnB,QAAQ,EACT,wBAAwB;AAEzB,OAAO,EAAE,qBAAqB,EAAE,oBAAgB;AAEhD;;GAEG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,cAAc,CACpD,KAAK,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,qBAAqB,CAAC,CAAC,EAC9C,MAAM,EAAE,CACT,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,6BAA6B,GAAG,MAAM,CAAC;IAClD,QAAQ,EAAE,OAAO,CAAC,IAAI,CAAC;IACvB,SAAS,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAC;IAC7B,WAAW,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAC;IAC/B,iBAAiB,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAC;IACrC,WAAW,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAC;IAC/B,UAAU,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAC;IAC9B,kBAAkB,EAAE,QAAQ,CAAC,wBAAwB,CAAC;CACvD,CAAC,CAAC;AAEH;;;;;GAKG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,MAAM,CAAC;IACrC,KAAK,EAAE,uBAAuB;IAC9B,MAAM,EAAE,MAAM,EAAE;CACjB,CAAC,CAAC;AAEH;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,MAAM,gCAAgC,GAAG,MAAM,CAAC;IACrD,QAAQ,EAAE,OAAO,CAAC,KAAK,CAAC;IACxB,QAAQ,EAAE,QAAQ,CAAC,gBAAgB,CAAC;IACpC,MAAM,EAAE,QAAQ,CAAC,gBAAgB,CAAC;IAClC,UAAU,EAAE,QAAQ,CAAC,gBAAgB,CAAC;IACtC,MAAM,EAAE,QAAQ,CACd,MAAM,CAAC;QACL,OAAO,EAAE,QAAQ,CACf,MAAM,CAAC;YACL,MAAM,EAAE,MAAM,EAAE;YAChB,IAAI,EAAE,MAAM,EAAE;SACf,CAAC,CACH;QACD,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;KAC/C,CAAC,CACH;CACF,CAAC,CAAC;AAEH;;GAEG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,cAAc,CAAC,CAAC,UAAU,EAAE,EAAE;IACjE,IAAI,QAAQ,CAAC,UAAU,CAAC,IAAI,UAAU,CAAC,QAAQ,EAAE,CAAC;QAChD,OAAO,6BAA6B,CAAC;IACvC,CAAC;IAED,OAAO,gCAAgC,CAAC;AAC1C,CAAC,CAAC,CAAC;AAEH;;;;GAIG;AACH,MAAM,CAAC,MAAM,gCAAgC,GAAG,MAAM,CAAC;IACrD,UAAU,EAAE,MAAM,CAChB,uBAAuB,EACvB,MAAM,CAAC,mBAAmB,EAAE,QAAQ,CAAC,qBAAqB,CAAC,CAAC,CAC7D;CACF,CAAC,CAAC","sourcesContent":["import { nonEmptyRecord, selectiveUnion } from '@metamask/snaps-sdk';\nimport {\n literal,\n nullable,\n number,\n object,\n optional,\n record,\n string,\n union,\n} from '@metamask/superstruct';\nimport {\n CaipAssetTypeOrIdStruct,\n CaipAssetTypeStruct,\n isObject,\n} from '@metamask/utils';\n\nimport { ISO8601DurationStruct } from '../time';\n\n/**\n * A struct representing the market data for an asset.\n */\nexport const PricePercentChangeStruct = nonEmptyRecord(\n union([literal('all'), ISO8601DurationStruct]),\n number(),\n);\n\n/**\n * A struct representing the market data for a fungible asset.\n *\n * @property fungible - Indicates that this is a fungible asset.\n * This is always `true` for fungible assets.\n * @property marketCap - The market capitalization of the asset.\n * @property totalVolume - The total volume of the asset.\n * @property circulatingSupply - The circulating supply of the asset.\n * @property allTimeHigh - The all-time high price of the asset.\n * @property allTimeLow - The all-time low price of the asset.\n * @property pricePercentChange - The percentage change in price over different intervals.\n * @property pricePercentChange.interval - The time interval for the price change as a ISO 8601 duration\n * or the string \"all\" to represent the all-time change.\n */\nexport const FungibleAssetMarketDataStruct = object({\n fungible: literal(true),\n marketCap: optional(string()),\n totalVolume: optional(string()),\n circulatingSupply: optional(string()),\n allTimeHigh: optional(string()),\n allTimeLow: optional(string()),\n pricePercentChange: optional(PricePercentChangeStruct),\n});\n\n/**\n * A struct representing an asset value, which includes the asset type and the amount.\n *\n * @property asset - The CAIP-19 asset type or ID of the asset.\n * @property amount - The
|
|
1
|
+
{"version":3,"file":"assets-market-data.mjs","sourceRoot":"","sources":["../../src/handlers/assets-market-data.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,4BAA4B;AACrE,OAAO,EACL,OAAO,EACP,QAAQ,EACR,MAAM,EACN,MAAM,EACN,QAAQ,EACR,MAAM,EACN,MAAM,EACN,KAAK,EACN,8BAA8B;AAC/B,OAAO,EACL,uBAAuB,EACvB,mBAAmB,EACnB,QAAQ,EACT,wBAAwB;AAEzB,OAAO,EAAE,qBAAqB,EAAE,oBAAgB;AAEhD;;GAEG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,cAAc,CACpD,KAAK,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,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C,CAAC,UAAU,EAAE,EAAE;IACjE,IAAI,QAAQ,CAAC,UAAU,CAAC,IAAI,UAAU,CAAC,QAAQ,EAAE,CAAC;QAChD,OAAO,6BAA6B,CAAC;IACvC,CAAC;IAED,OAAO,gCAAgC,CAAC;AAC1C,CAAC,CAAC,CAAC;AAEH;;;;GAIG;AACH,MAAM,CAAC,MAAM,gCAAgC,GAAG,MAAM,CAAC;IACrD,UAAU,EAAE,MAAM,CAChB,uBAAuB,EACvB,MAAM,CAAC,mBAAmB,EAAE,QAAQ,CAAC,qBAAqB,CAAC,CAAC,CAC7D;CACF,CAAC,CAAC","sourcesContent":["import { nonEmptyRecord, selectiveUnion } from '@metamask/snaps-sdk';\nimport {\n literal,\n nullable,\n number,\n object,\n optional,\n record,\n string,\n union,\n} from '@metamask/superstruct';\nimport {\n CaipAssetTypeOrIdStruct,\n CaipAssetTypeStruct,\n isObject,\n} from '@metamask/utils';\n\nimport { ISO8601DurationStruct } from '../time';\n\n/**\n * A struct representing the market data for an asset.\n */\nexport const PricePercentChangeStruct = nonEmptyRecord(\n union([literal('all'), ISO8601DurationStruct]),\n number(),\n);\n\n/**\n * A struct representing the market data for a fungible asset.\n *\n * @property fungible - Indicates that this is a fungible asset.\n * This is always `true` for fungible assets.\n * @property marketCap - The market capitalization of the asset.\n * @property totalVolume - The total volume of the asset.\n * @property circulatingSupply - The circulating supply of the asset.\n * @property allTimeHigh - The all-time high price of the asset.\n * @property allTimeLow - The all-time low price of the asset.\n * @property pricePercentChange - The percentage change in price over different intervals.\n * @property pricePercentChange.interval - The time interval for the price change as a ISO 8601 duration\n * or the string \"all\" to represent the all-time change.\n */\nexport const FungibleAssetMarketDataStruct = object({\n fungible: literal(true),\n marketCap: optional(string()),\n totalVolume: optional(string()),\n circulatingSupply: optional(string()),\n allTimeHigh: optional(string()),\n allTimeLow: optional(string()),\n pricePercentChange: optional(PricePercentChangeStruct),\n});\n\n/**\n * A struct representing an asset value, which includes the asset type and the amount.\n *\n * @property asset - The CAIP-19 asset type or ID of the asset.\n * @property amount - The price represented as a number in string format.\n */\nexport const AssetValueStruct = object({\n asset: CaipAssetTypeOrIdStruct,\n amount: string(),\n});\n\n/**\n * A struct representing the market data for a non-fungible asset.\n *\n * @property asset - The CAIP-19 asset type or ID of the asset.\n * @property amount - The price represented as a number in string format.\n * @property fungible - Indicates that this is a non-fungible asset.\n * This is always `false` for non-fungible assets.\n * @property lastSale - The last sale price of the asset, if available. See {@link AssetValueStruct}.\n * @property topBid - The top bid price for the asset, if available. See {@link AssetValueStruct}.\n * @property floorPrice - The floor price of the asset, if available. See {@link AssetValueStruct}.\n * @property rarity - The rarity information for the asset, if available.\n * @property rarity.ranking - The ranking of the asset's rarity, if available.\n * @property rarity.ranking.source - The source of the rarity ranking.\n * @property rarity.ranking.rank - The rank of the asset in the rarity ranking.\n * @property rarity.metadata - Additional metadata about the asset's rarity, if available.\n * This is a record of string keys and number values.\n */\nexport const NonFungibleAssetMarketDataStruct = object({\n fungible: literal(false),\n lastSale: optional(AssetValueStruct),\n topBid: optional(AssetValueStruct),\n floorPrice: optional(AssetValueStruct),\n rarity: optional(\n object({\n ranking: optional(\n object({\n source: string(),\n rank: number(),\n }),\n ),\n metadata: optional(record(string(), number())),\n }),\n ),\n});\n\n/**\n * A struct representing the market data for an asset, which can be either {@link FungibleAssetMarketDataStruct} or {@link NonFungibleAssetMarketDataStruct}.\n */\nexport const AssetMarketDataStruct = selectiveUnion((marketData) => {\n if (isObject(marketData) && marketData.fungible) {\n return FungibleAssetMarketDataStruct;\n }\n\n return NonFungibleAssetMarketDataStruct;\n});\n\n/**\n * A struct representing the response of the `onAssetsMarketData` method.\n *\n * @property marketData - A nested object with two CAIP-19 keys that contains a {@link AssetMarketData} object or null.\n */\nexport const OnAssetsMarketDataResponseStruct = object({\n marketData: record(\n CaipAssetTypeOrIdStruct,\n record(CaipAssetTypeStruct, nullable(AssetMarketDataStruct)),\n ),\n});\n"]}
|
package/dist/iframe.cjs
CHANGED
|
@@ -49,7 +49,7 @@ async function createWindow({ uri, id, sandbox = true, testId = 'snaps-iframe',
|
|
|
49
49
|
// fast if it does.
|
|
50
50
|
reject(new Error(`iframe.contentWindow not present on load for job "${id}".`));
|
|
51
51
|
}
|
|
52
|
-
});
|
|
52
|
+
}, { once: true });
|
|
53
53
|
});
|
|
54
54
|
}
|
|
55
55
|
exports.createWindow = createWindow;
|
package/dist/iframe.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"iframe.cjs","sourceRoot":"","sources":["../src/iframe.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;GAWG;AACI,KAAK,UAAU,YAAY,CAAC,EACjC,GAAG,EACH,EAAE,EACF,OAAO,GAAG,IAAI,EACd,MAAM,GAAG,cAAc,GAMxB;IACC,OAAO,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAC3C,MAAM,MAAM,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;QAChD,uEAAuE;QACvE,yCAAyC;QACzC,MAAM,CAAC,YAAY,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QAC9B,MAAM,CAAC,YAAY,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC;QAE3C,IAAI,OAAO,EAAE,CAAC;YACZ,gGAAgG;YAChG,kEAAkE;YAClE,WAAW;YACX,qFAAqF;YACrF,MAAM,CAAC,YAAY,CAAC,SAAS,EAAE,eAAe,CAAC,CAAC;QAClD,CAAC;QAED,uEAAuE;QACvE,yEAAyE;QACzE,uEAAuE;QACvE,wEAAwE;QACxE,uBAAuB;QACvB,EAAE;QACF,mEAAmE;QACnE,kCAAkC;QAClC,EAAE;QACF,mGAAmG;QACnG,iJAAiJ;QACjJ,MAAM,CAAC,YAAY,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QAChC,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;QAElC,MAAM,CAAC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,CAAC,EACD,EAAE,IAAI,EAAE,IAAI,EAAE,CACf,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC;AA1DD,oCA0DC","sourcesContent":["/**\n * Creates the iframe to be used as the execution environment. This may run\n * forever if the iframe never loads, but the promise should be wrapped in\n * an initialization timeout in the SnapController.\n *\n * @param options - The options for createWindow.\n * @param options.uri - The iframe URI.\n * @param options.id - The ID to assign to the iframe.\n * @param options.sandbox - Whether to enable the sandbox attribute.\n * @param options.testId - The data-testid attribute to assign to the iframe.\n * @returns A promise that resolves to the contentWindow of the iframe.\n */\nexport async function createWindow({\n uri,\n id,\n sandbox = true,\n testId = 'snaps-iframe',\n}: {\n uri: string;\n id: string;\n sandbox?: boolean;\n testId?: string;\n}): Promise<Window> {\n return await new Promise((resolve, reject) => {\n const iframe = document.createElement('iframe');\n // The order of operations appears to matter for everything except this\n // attribute. We may as well set it here.\n iframe.setAttribute('id', id);\n iframe.setAttribute('data-testid', testId);\n\n if (sandbox) {\n // For the sandbox property to have any effect it needs to be set before the iframe is appended.\n // We apply this property as a principle of least authority (POLA)\n // measure.\n // Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe#attr-sandbox\n iframe.setAttribute('sandbox', 'allow-scripts');\n }\n\n // In the past, we've had problems that appear to be symptomatic of the\n // iframe firing the `load` event before its scripts are actually loaded,\n // which has prevented snaps from executing properly. Therefore, we set\n // the `src` attribute and append the iframe to the DOM before attaching\n // the `load` listener.\n //\n // `load` should only fire when \"all dependent resources\" have been\n // loaded, which includes scripts.\n //\n // MDN article for `load` event: https://developer.mozilla.org/en-US/docs/Web/API/Window/load_event\n // Re: `load` firing twice: https://stackoverflow.com/questions/10781880/dynamically-created-iframe-triggers-onload-event-twice/15880489#15880489\n iframe.setAttribute('src', uri);\n document.body.appendChild(iframe);\n\n iframe.addEventListener(\n 'load',\n () => {\n if (iframe.contentWindow) {\n resolve(iframe.contentWindow);\n } else {\n // We don't know of a case when this would happen, but better to fail\n // fast if it does.\n reject(\n new Error(\n `iframe.contentWindow not present on load for job \"${id}\".`,\n ),\n );\n }\n },\n { once: true },\n );\n });\n}\n"]}
|
package/dist/iframe.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"iframe.d.cts","sourceRoot":"","sources":["../src/iframe.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,wBAAsB,YAAY,CAAC,EACjC,GAAG,EACH,EAAE,EACF,OAAc,EACd,MAAuB,GACxB,EAAE;IACD,GAAG,EAAE,MAAM,CAAC;IACZ,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,GAAG,OAAO,CAAC,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"iframe.d.cts","sourceRoot":"","sources":["../src/iframe.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,wBAAsB,YAAY,CAAC,EACjC,GAAG,EACH,EAAE,EACF,OAAc,EACd,MAAuB,GACxB,EAAE;IACD,GAAG,EAAE,MAAM,CAAC;IACZ,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,GAAG,OAAO,CAAC,MAAM,CAAC,CAgDlB"}
|
package/dist/iframe.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"iframe.d.mts","sourceRoot":"","sources":["../src/iframe.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,wBAAsB,YAAY,CAAC,EACjC,GAAG,EACH,EAAE,EACF,OAAc,EACd,MAAuB,GACxB,EAAE;IACD,GAAG,EAAE,MAAM,CAAC;IACZ,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,GAAG,OAAO,CAAC,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"iframe.d.mts","sourceRoot":"","sources":["../src/iframe.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,wBAAsB,YAAY,CAAC,EACjC,GAAG,EACH,EAAE,EACF,OAAc,EACd,MAAuB,GACxB,EAAE;IACD,GAAG,EAAE,MAAM,CAAC;IACZ,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,GAAG,OAAO,CAAC,MAAM,CAAC,CAgDlB"}
|
package/dist/iframe.mjs
CHANGED
|
@@ -46,7 +46,7 @@ export async function createWindow({ uri, id, sandbox = true, testId = 'snaps-if
|
|
|
46
46
|
// fast if it does.
|
|
47
47
|
reject(new Error(`iframe.contentWindow not present on load for job "${id}".`));
|
|
48
48
|
}
|
|
49
|
-
});
|
|
49
|
+
}, { once: true });
|
|
50
50
|
});
|
|
51
51
|
}
|
|
52
52
|
//# sourceMappingURL=iframe.mjs.map
|
package/dist/iframe.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"iframe.mjs","sourceRoot":"","sources":["../src/iframe.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,EACjC,GAAG,EACH,EAAE,EACF,OAAO,GAAG,IAAI,EACd,MAAM,GAAG,cAAc,GAMxB;IACC,OAAO,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAC3C,MAAM,MAAM,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;QAChD,uEAAuE;QACvE,yCAAyC;QACzC,MAAM,CAAC,YAAY,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QAC9B,MAAM,CAAC,YAAY,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC;QAE3C,IAAI,OAAO,EAAE,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mG;QACnG,iJAAiJ;QACjJ,MAAM,CAAC,YAAY,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QAChC,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;QAElC,MAAM,CAAC,gBAAgB,CACrB,MAAM,EACN,GAAG,EAAE;YACH,IAAI,MAAM,CAAC,aAAa,EAAE,CAAC;gBACzB,OAAO,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;YAChC,CAAC;iBAAM,CAAC;gBACN,qEAAqE;gBACrE,mBAAmB;gBACnB,MAAM,CACJ,IAAI,KAAK,CACP,qDAAqD,EAAE,IAAI,CAC5D,CACF,CAAC;YACJ,CAAC;QACH,CAAC,EACD,EAAE,IAAI,EAAE,IAAI,EAAE,CACf,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["/**\n * Creates the iframe to be used as the execution environment. This may run\n * forever if the iframe never loads, but the promise should be wrapped in\n * an initialization timeout in the SnapController.\n *\n * @param options - The options for createWindow.\n * @param options.uri - The iframe URI.\n * @param options.id - The ID to assign to the iframe.\n * @param options.sandbox - Whether to enable the sandbox attribute.\n * @param options.testId - The data-testid attribute to assign to the iframe.\n * @returns A promise that resolves to the contentWindow of the iframe.\n */\nexport async function createWindow({\n uri,\n id,\n sandbox = true,\n testId = 'snaps-iframe',\n}: {\n uri: string;\n id: string;\n sandbox?: boolean;\n testId?: string;\n}): Promise<Window> {\n return await new Promise((resolve, reject) => {\n const iframe = document.createElement('iframe');\n // The order of operations appears to matter for everything except this\n // attribute. We may as well set it here.\n iframe.setAttribute('id', id);\n iframe.setAttribute('data-testid', testId);\n\n if (sandbox) {\n // For the sandbox property to have any effect it needs to be set before the iframe is appended.\n // We apply this property as a principle of least authority (POLA)\n // measure.\n // Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe#attr-sandbox\n iframe.setAttribute('sandbox', 'allow-scripts');\n }\n\n // In the past, we've had problems that appear to be symptomatic of the\n // iframe firing the `load` event before its scripts are actually loaded,\n // which has prevented snaps from executing properly. Therefore, we set\n // the `src` attribute and append the iframe to the DOM before attaching\n // the `load` listener.\n //\n // `load` should only fire when \"all dependent resources\" have been\n // loaded, which includes scripts.\n //\n // MDN article for `load` event: https://developer.mozilla.org/en-US/docs/Web/API/Window/load_event\n // Re: `load` firing twice: https://stackoverflow.com/questions/10781880/dynamically-created-iframe-triggers-onload-event-twice/15880489#15880489\n iframe.setAttribute('src', uri);\n document.body.appendChild(iframe);\n\n iframe.addEventListener(\n 'load',\n () => {\n if (iframe.contentWindow) {\n resolve(iframe.contentWindow);\n } else {\n // We don't know of a case when this would happen, but better to fail\n // fast if it does.\n reject(\n new Error(\n `iframe.contentWindow not present on load for job \"${id}\".`,\n ),\n );\n }\n },\n { once: true },\n );\n });\n}\n"]}
|
package/dist/localization.d.cts
CHANGED
|
@@ -131,6 +131,7 @@ export declare function getLocalizedSnapManifest(snapManifest: SnapManifest, loc
|
|
|
131
131
|
wallet_snap: Record<string, import("@metamask/snaps-sdk").RequestedSnap>;
|
|
132
132
|
}>;
|
|
133
133
|
manifestVersion: "0.1";
|
|
134
|
+
extends?: string | undefined;
|
|
134
135
|
repository?: {
|
|
135
136
|
type: string;
|
|
136
137
|
url: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"localization.d.cts","sourceRoot":"","sources":["../src/localization.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,8BAA8B;AAWnD,OAAO,KAAK,EAAE,YAAY,EAAE,6BAAmB;AAC/C,OAAO,KAAK,EAAE,WAAW,EAAE,iCAAuB;AAElD,eAAO,MAAM,kBAAkB,0CAA2C,CAAC;AAE3E,eAAO,MAAM,sBAAsB;;;;;;;;;;;;EASjC,CAAC;AAEH,MAAM,MAAM,gBAAgB,GAAG,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAEpE;;;;;;GAMG;AACH,wBAAgB,6BAA6B,CAC3C,iBAAiB,EAA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H,wBAAgB,wBAAwB,CACtC,YAAY,EAAE,YAAY,EAC1B,MAAM,EAAE,MAAM,EACd,iBAAiB,EAAE,gBAAgB,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAWtC;AAED;;;;;;GAMG;AACH,wBAAgB,iCAAiC,CAC/C,YAAY,EAAE,YAAY,EAC1B,iBAAiB,EAAE,gBAAgB,EAAE,QAkBtC"}
|
package/dist/localization.d.mts
CHANGED
|
@@ -131,6 +131,7 @@ export declare function getLocalizedSnapManifest(snapManifest: SnapManifest, loc
|
|
|
131
131
|
wallet_snap: Record<string, import("@metamask/snaps-sdk").RequestedSnap>;
|
|
132
132
|
}>;
|
|
133
133
|
manifestVersion: "0.1";
|
|
134
|
+
extends?: string | undefined;
|
|
134
135
|
repository?: {
|
|
135
136
|
type: string;
|
|
136
137
|
url: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"localization.d.mts","sourceRoot":"","sources":["../src/localization.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,8BAA8B;AAWnD,OAAO,KAAK,EAAE,YAAY,EAAE,6BAAmB;AAC/C,OAAO,KAAK,EAAE,WAAW,EAAE,iCAAuB;AAElD,eAAO,MAAM,kBAAkB,0CAA2C,CAAC;AAE3E,eAAO,MAAM,sBAAsB;;;;;;;;;;;;EASjC,CAAC;AAEH,MAAM,MAAM,gBAAgB,GAAG,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAEpE;;;;;;GAMG;AACH,wBAAgB,6BAA6B,CAC3C,iBAAiB,EAAE,WAAW,EAAE,GAC/B,WAAW,CAAC,gBAAgB,CAAC,EAAE,CAsBjC;AAED;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,MAAM,EACd,iBAAiB,EAAE,gBAAgB,EAAE;;;;;;cAatC;AAED,eAAO,MAAM,iBA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EAWtC;AAED;;;;;;GAMG;AACH,wBAAgB,iCAAiC,CAC/C,YAAY,EAAE,YAAY,EAC1B,iBAAiB,EAAE,gBAAgB,EAAE,QAkBtC"}
|
|
@@ -26,11 +26,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.getWritableManifest = exports.getSnapFiles = exports.getSnapFilePaths = exports.getSnapIcon = exports.getSnapSourceCode = exports.runFixes = exports.checkManifest = void 0;
|
|
29
|
+
exports.getWritableManifest = exports.getSnapFiles = exports.getSnapFilePaths = exports.getSnapIcon = exports.getSnapSourceCode = exports.runFixes = exports.checkManifest = exports.loadManifest = void 0;
|
|
30
30
|
const snaps_sdk_1 = require("@metamask/snaps-sdk");
|
|
31
31
|
const utils_1 = require("@metamask/utils");
|
|
32
|
+
const deepmerge_1 = __importDefault(require("deepmerge"));
|
|
32
33
|
const fs_1 = require("fs");
|
|
33
|
-
const path_1 =
|
|
34
|
+
const path_1 = __importStar(require("path"));
|
|
34
35
|
const validator_1 = require("./validator.cjs");
|
|
35
36
|
const defaultValidators = __importStar(require("./validators/index.cjs"));
|
|
36
37
|
const deep_clone_1 = require("../deep-clone.cjs");
|
|
@@ -40,22 +41,85 @@ const types_1 = require("../types.cjs");
|
|
|
40
41
|
const node_1 = require("../virtual-file/node.cjs");
|
|
41
42
|
const MANIFEST_SORT_ORDER = {
|
|
42
43
|
$schema: 1,
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
44
|
+
extends: 2,
|
|
45
|
+
version: 3,
|
|
46
|
+
description: 4,
|
|
47
|
+
proposedName: 5,
|
|
48
|
+
repository: 6,
|
|
49
|
+
source: 7,
|
|
50
|
+
initialConnections: 8,
|
|
51
|
+
initialPermissions: 9,
|
|
52
|
+
platformVersion: 10,
|
|
53
|
+
manifestVersion: 11,
|
|
52
54
|
};
|
|
55
|
+
/**
|
|
56
|
+
* Merge two Snap manifests, with the extended manifest taking precedence
|
|
57
|
+
* over the base manifest.
|
|
58
|
+
*
|
|
59
|
+
* @param mainManifest - The main manifest.
|
|
60
|
+
* @param extendedManifest - The extended manifest.
|
|
61
|
+
* @returns The merged manifest.
|
|
62
|
+
*/
|
|
63
|
+
function mergeManifests(mainManifest, extendedManifest) {
|
|
64
|
+
if (!extendedManifest) {
|
|
65
|
+
return mainManifest;
|
|
66
|
+
}
|
|
67
|
+
(0, utils_1.assert)((0, utils_1.isObject)(mainManifest));
|
|
68
|
+
(0, utils_1.assert)((0, utils_1.isObject)(extendedManifest));
|
|
69
|
+
const mergedManifest = (0, deepmerge_1.default)(extendedManifest, mainManifest);
|
|
70
|
+
delete mergedManifest.extends;
|
|
71
|
+
return getWritableManifest(mergedManifest);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Load a manifest and its extended manifest if it has one.
|
|
75
|
+
*
|
|
76
|
+
* Note: This function does not validate the manifests.
|
|
77
|
+
*
|
|
78
|
+
* @param manifestPath - The path to the manifest file.
|
|
79
|
+
* @param files - A set of already loaded manifest file paths to prevent
|
|
80
|
+
* circular dependencies.
|
|
81
|
+
* @param root - Whether this is the root manifest being loaded. Used for
|
|
82
|
+
* recursive calls, and should not be set by callers.
|
|
83
|
+
* @returns The base and extended manifests.
|
|
84
|
+
*/
|
|
85
|
+
async function loadManifest(manifestPath, files = new Set(), root = true) {
|
|
86
|
+
(0, utils_1.assert)(path_1.default.isAbsolute(manifestPath), 'The `loadManifest` function must be called with an absolute path.');
|
|
87
|
+
if (files.has(manifestPath)) {
|
|
88
|
+
throw new Error(`Failed to load Snap manifest: Circular dependency detected when loading "${manifestPath}".`);
|
|
89
|
+
}
|
|
90
|
+
const mainManifest = await (0, fs_2.readJsonFile)(manifestPath);
|
|
91
|
+
files.add(manifestPath);
|
|
92
|
+
if (!(0, utils_1.isObject)(mainManifest.result)) {
|
|
93
|
+
throw new Error(`Failed to load Snap manifest: The Snap manifest file at "${manifestPath}" must contain a JSON object.`);
|
|
94
|
+
}
|
|
95
|
+
if (mainManifest.result.extends &&
|
|
96
|
+
typeof mainManifest.result.extends === 'string') {
|
|
97
|
+
const fileName = path_1.default.basename(manifestPath);
|
|
98
|
+
if (root && fileName === 'snap.manifest.json') {
|
|
99
|
+
throw new Error(`Failed to load Snap manifest: The Snap manifest file at "snap.manifest.json" cannot extend another manifest.`);
|
|
100
|
+
}
|
|
101
|
+
const extendedManifestPath = path_1.default.resolve(path_1.default.dirname(manifestPath), mainManifest.result.extends);
|
|
102
|
+
const extendedManifest = await loadManifest(extendedManifestPath, files, false);
|
|
103
|
+
return {
|
|
104
|
+
mainManifest,
|
|
105
|
+
extendedManifest: extendedManifest.mergedManifest,
|
|
106
|
+
mergedManifest: mergeManifests(mainManifest.result, extendedManifest.mergedManifest),
|
|
107
|
+
files,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
return {
|
|
111
|
+
mainManifest,
|
|
112
|
+
mergedManifest: mainManifest.result,
|
|
113
|
+
files,
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
exports.loadManifest = loadManifest;
|
|
53
117
|
/**
|
|
54
118
|
* Validates a snap.manifest.json file. Attempts to fix the manifest and write
|
|
55
119
|
* the fixed version to disk if `writeManifest` is true. Throws if validation
|
|
56
120
|
* fails.
|
|
57
121
|
*
|
|
58
|
-
* @param
|
|
122
|
+
* @param manifestPath - The path to the manifest file.
|
|
59
123
|
* @param options - Additional options for the function.
|
|
60
124
|
* @param options.sourceCode - The source code of the Snap.
|
|
61
125
|
* @param options.writeFileFn - The function to use to write the manifest to
|
|
@@ -73,10 +137,10 @@ const MANIFEST_SORT_ORDER = {
|
|
|
73
137
|
* @returns Whether the manifest was updated, and an array of warnings that
|
|
74
138
|
* were encountered during processing of the manifest files.
|
|
75
139
|
*/
|
|
76
|
-
async function checkManifest(
|
|
77
|
-
const
|
|
78
|
-
const
|
|
79
|
-
const unvalidatedManifest =
|
|
140
|
+
async function checkManifest(manifestPath, { updateAndWriteManifest = true, sourceCode, writeFileFn = fs_1.promises.writeFile, exports, handlerEndowments, watchMode = false, } = {}) {
|
|
141
|
+
const basePath = (0, path_1.dirname)(manifestPath);
|
|
142
|
+
const extendableManifest = await loadManifest(manifestPath);
|
|
143
|
+
const unvalidatedManifest = extendableManifest.mergedManifest;
|
|
80
144
|
const packageFile = await (0, fs_2.readJsonFile)(path_1.default.join(basePath, types_1.NpmSnapFileNames.PackageJson));
|
|
81
145
|
const auxiliaryFilePaths = getSnapFilePaths(unvalidatedManifest, (manifest) => manifest?.source?.files);
|
|
82
146
|
const localizationFilePaths = getSnapFilePaths(unvalidatedManifest, (manifest) => manifest?.source?.locales);
|
|
@@ -91,7 +155,7 @@ async function checkManifest(basePath, { updateAndWriteManifest = true, sourceCo
|
|
|
91
155
|
}
|
|
92
156
|
}
|
|
93
157
|
const snapFiles = {
|
|
94
|
-
manifest:
|
|
158
|
+
manifest: extendableManifest,
|
|
95
159
|
packageJson: packageFile,
|
|
96
160
|
sourceCode: await getSnapSourceCode(basePath, unvalidatedManifest, sourceCode),
|
|
97
161
|
svgIcon: await getSnapIcon(basePath, unvalidatedManifest),
|
|
@@ -111,7 +175,7 @@ async function checkManifest(basePath, { updateAndWriteManifest = true, sourceCo
|
|
|
111
175
|
manifestResults = fixedResults;
|
|
112
176
|
(0, utils_1.assert)(manifestResults.files);
|
|
113
177
|
try {
|
|
114
|
-
await writeFileFn(
|
|
178
|
+
await writeFileFn(manifestPath, manifestResults.files.manifest.mainManifest.toString());
|
|
115
179
|
}
|
|
116
180
|
catch (error) {
|
|
117
181
|
// Note: This error isn't pushed to the errors array, because it's not an
|
|
@@ -143,18 +207,27 @@ async function runFixes(results, rules, errorsOnly = false) {
|
|
|
143
207
|
(0, utils_1.assert)(results.files);
|
|
144
208
|
let fixResults = results;
|
|
145
209
|
(0, utils_1.assert)(fixResults.files);
|
|
146
|
-
fixResults.files.manifest =
|
|
210
|
+
fixResults.files.manifest.mainManifest =
|
|
211
|
+
fixResults.files.manifest.mainManifest.clone();
|
|
147
212
|
const mergedReports = (0, deep_clone_1.deepClone)(fixResults.reports);
|
|
148
213
|
for (let attempts = 1; shouldRunFixes && attempts <= MAX_ATTEMPTS; attempts++) {
|
|
149
214
|
(0, utils_1.assert)(fixResults.files);
|
|
150
|
-
let manifest = fixResults.files.manifest.result;
|
|
151
215
|
const fixable = fixResults.reports.filter((report) => (0, validator_1.isReportFixable)(report, errorsOnly));
|
|
216
|
+
let { manifest } = fixResults.files;
|
|
152
217
|
for (const report of fixable) {
|
|
153
218
|
(0, utils_1.assert)(report.fix);
|
|
154
219
|
({ manifest } = await report.fix({ manifest }));
|
|
220
|
+
manifest.mergedManifest = mergeManifests(manifest.mainManifest.result, manifest.extendedManifest);
|
|
155
221
|
}
|
|
156
|
-
|
|
157
|
-
|
|
222
|
+
// The `mainManifest` is always the first manifest loaded, and is the one
|
|
223
|
+
// that should be updated with fixes. Any manifests that the main manifest
|
|
224
|
+
// extends will not be updated.
|
|
225
|
+
// We can revisit this in the future if we want to support fixing extended
|
|
226
|
+
// manifests as well, but it adds complexity, as we'd need to track which
|
|
227
|
+
// fixes apply to which manifest.
|
|
228
|
+
fixResults.files.manifest.mainManifest.value = `${JSON.stringify(getWritableManifest(manifest.mainManifest.result), null, 2)}\n`;
|
|
229
|
+
fixResults.files.manifest = manifest;
|
|
230
|
+
fixResults.files.manifest.mergedManifest = mergeManifests(fixResults.files.manifest.mainManifest.result, fixResults.files.manifest.extendedManifest);
|
|
158
231
|
fixResults = await (0, validator_1.runValidators)(fixResults.files, rules);
|
|
159
232
|
shouldRunFixes = (0, validator_1.hasFixes)(fixResults, errorsOnly);
|
|
160
233
|
fixResults.reports
|
|
@@ -196,7 +269,7 @@ exports.runFixes = runFixes;
|
|
|
196
269
|
* @returns The contents of the bundle file, if any.
|
|
197
270
|
*/
|
|
198
271
|
async function getSnapSourceCode(basePath, manifest, sourceCode) {
|
|
199
|
-
if (!(0, utils_1.
|
|
272
|
+
if (!(0, utils_1.isObject)(manifest)) {
|
|
200
273
|
return undefined;
|
|
201
274
|
}
|
|
202
275
|
const sourceFilePath = manifest.source?.location
|
|
@@ -228,7 +301,7 @@ exports.getSnapSourceCode = getSnapSourceCode;
|
|
|
228
301
|
* @returns The contents of the icon, if any.
|
|
229
302
|
*/
|
|
230
303
|
async function getSnapIcon(basePath, manifest) {
|
|
231
|
-
if (!(0, utils_1.
|
|
304
|
+
if (!(0, utils_1.isObject)(manifest)) {
|
|
232
305
|
return undefined;
|
|
233
306
|
}
|
|
234
307
|
const iconPath = manifest.source?.location?.npm
|
|
@@ -253,7 +326,7 @@ exports.getSnapIcon = getSnapIcon;
|
|
|
253
326
|
* @returns The paths to the files, if any.
|
|
254
327
|
*/
|
|
255
328
|
function getSnapFilePaths(manifest, selector) {
|
|
256
|
-
if (!(0, utils_1.
|
|
329
|
+
if (!(0, utils_1.isObject)(manifest)) {
|
|
257
330
|
return undefined;
|
|
258
331
|
}
|
|
259
332
|
const snapManifest = manifest;
|
|
@@ -295,13 +368,12 @@ exports.getSnapFiles = getSnapFiles;
|
|
|
295
368
|
function getWritableManifest(manifest) {
|
|
296
369
|
const { repository, ...remaining } = manifest;
|
|
297
370
|
const keys = Object.keys(repository ? { ...remaining, repository } : remaining);
|
|
298
|
-
|
|
371
|
+
return keys
|
|
299
372
|
.sort((a, b) => MANIFEST_SORT_ORDER[a] - MANIFEST_SORT_ORDER[b])
|
|
300
373
|
.reduce((result, key) => ({
|
|
301
374
|
...result,
|
|
302
375
|
[key]: manifest[key],
|
|
303
376
|
}), {});
|
|
304
|
-
return writableManifest;
|
|
305
377
|
}
|
|
306
378
|
exports.getWritableManifest = getWritableManifest;
|
|
307
379
|
//# sourceMappingURL=manifest.cjs.map
|