@metamask/snaps-utils 0.28.0 → 0.29.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/dist/caveats.d.ts +5 -1
- package/dist/caveats.js +4 -0
- package/dist/caveats.js.map +1 -1
- package/dist/checksum.d.ts +21 -0
- package/dist/checksum.js +42 -0
- package/dist/checksum.js.map +1 -0
- package/dist/eval-worker.js +1 -0
- package/dist/eval-worker.js.map +1 -1
- package/dist/fs.d.ts +2 -11
- package/dist/fs.js +8 -17
- package/dist/fs.js.map +1 -1
- package/dist/handlers.d.ts +0 -7
- package/dist/handlers.js.map +1 -1
- package/dist/index.browser.d.ts +2 -0
- package/dist/index.browser.js +2 -0
- package/dist/index.browser.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/logging.d.ts +49 -0
- package/dist/logging.js +67 -0
- package/dist/logging.js.map +1 -0
- package/dist/manifest/manifest.d.ts +16 -6
- package/dist/manifest/manifest.js +85 -48
- package/dist/manifest/manifest.js.map +1 -1
- package/dist/manifest/validation.d.ts +4 -4
- package/dist/manifest/validation.js +2 -5
- package/dist/manifest/validation.js.map +1 -1
- package/dist/namespace.d.ts +3 -3
- package/dist/npm.js +5 -4
- package/dist/npm.js.map +1 -1
- package/dist/post-process.js +2 -1
- package/dist/post-process.js.map +1 -1
- package/dist/snaps.d.ts +25 -22
- package/dist/snaps.js +60 -24
- package/dist/snaps.js.map +1 -1
- package/dist/types.d.ts +21 -8
- package/dist/types.js +3 -1
- package/dist/types.js.map +1 -1
- package/dist/virtual-file/toVirtualFile.d.ts +1 -1
- package/dist/virtual-file/toVirtualFile.js +3 -6
- package/dist/virtual-file/toVirtualFile.js.map +1 -1
- package/package.json +5 -3
package/dist/caveats.d.ts
CHANGED
|
@@ -22,5 +22,9 @@ export declare enum SnapCaveatType {
|
|
|
22
22
|
/**
|
|
23
23
|
* The origins that a Snap can receive JSON-RPC messages from.
|
|
24
24
|
*/
|
|
25
|
-
RpcOrigin = "rpcOrigin"
|
|
25
|
+
RpcOrigin = "rpcOrigin",
|
|
26
|
+
/**
|
|
27
|
+
* Caveat specifying the snap IDs that can be interacted with.
|
|
28
|
+
*/
|
|
29
|
+
SnapIds = "snapIds"
|
|
26
30
|
}
|
package/dist/caveats.js
CHANGED
|
@@ -27,5 +27,9 @@ var SnapCaveatType;
|
|
|
27
27
|
* The origins that a Snap can receive JSON-RPC messages from.
|
|
28
28
|
*/
|
|
29
29
|
SnapCaveatType["RpcOrigin"] = "rpcOrigin";
|
|
30
|
+
/**
|
|
31
|
+
* Caveat specifying the snap IDs that can be interacted with.
|
|
32
|
+
*/
|
|
33
|
+
SnapCaveatType["SnapIds"] = "snapIds";
|
|
30
34
|
})(SnapCaveatType = exports.SnapCaveatType || (exports.SnapCaveatType = {}));
|
|
31
35
|
//# sourceMappingURL=caveats.js.map
|
package/dist/caveats.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"caveats.js","sourceRoot":"","sources":["../src/caveats.ts"],"names":[],"mappings":";;;AAAA,IAAY,
|
|
1
|
+
{"version":3,"file":"caveats.js","sourceRoot":"","sources":["../src/caveats.ts"],"names":[],"mappings":";;;AAAA,IAAY,cAmCX;AAnCD,WAAY,cAAc;IACxB;;OAEG;IACH,uEAAqD,CAAA;IAErD;;OAEG;IACH,2DAAyC,CAAA;IAEzC;;OAEG;IACH,6CAA2B,CAAA;IAE3B;;OAEG;IACH,6CAA2B,CAAA;IAE3B;;OAEG;IACH,yDAAuC,CAAA;IAEvC;;OAEG;IACH,yCAAuB,CAAA;IAEvB;;OAEG;IACH,qCAAmB,CAAA;AACrB,CAAC,EAnCW,cAAc,GAAd,sBAAc,KAAd,sBAAc,QAmCzB","sourcesContent":["export enum SnapCaveatType {\n /**\n * Permitted derivation paths, used by `snap_getBip32Entropy`.\n */\n PermittedDerivationPaths = 'permittedDerivationPaths',\n\n /**\n * Permitted coin types, used by `snap_getBip44Entropy`.\n */\n PermittedCoinTypes = 'permittedCoinTypes',\n\n /**\n * Permission to use the Snap keyring API.\n */\n SnapKeyring = 'snapKeyring',\n\n /**\n * Caveat specifying a snap cronjob.\n */\n SnapCronjob = 'snapCronjob',\n\n /**\n * Caveat specifying access to the transaction origin, used by `endowment:transaction-insight`.\n */\n TransactionOrigin = 'transactionOrigin',\n\n /**\n * The origins that a Snap can receive JSON-RPC messages from.\n */\n RpcOrigin = 'rpcOrigin',\n\n /**\n * Caveat specifying the snap IDs that can be interacted with.\n */\n SnapIds = 'snapIds',\n}\n"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { VirtualFile } from './virtual-file/VirtualFile';
|
|
2
|
+
/**
|
|
3
|
+
* Calculates checksum for a single byte array.
|
|
4
|
+
*
|
|
5
|
+
* @param bytes - The byte array to calculate the checksum for.
|
|
6
|
+
* @returns A single sha-256 checksum.
|
|
7
|
+
*/
|
|
8
|
+
export declare function checksum(bytes: VirtualFile | Uint8Array | string): Uint8Array;
|
|
9
|
+
/**
|
|
10
|
+
* Calculates checksum over multiple files in a reproducible way.
|
|
11
|
+
*
|
|
12
|
+
* 1. Sort all the files by their paths.
|
|
13
|
+
* 2. Calculate sha-256 checksum of each file separately.
|
|
14
|
+
* 3. Concatenate all the checksums into one buffer and sha-256 that buffer.
|
|
15
|
+
*
|
|
16
|
+
* The sorting of paths is done using {@link https://tc39.es/ecma262/#sec-islessthan UTF-16 Code Units}.
|
|
17
|
+
*
|
|
18
|
+
* @param files - The files over which to calculate the checksum.
|
|
19
|
+
* @returns A single sha-256 checksum.
|
|
20
|
+
*/
|
|
21
|
+
export declare function checksumFiles(files: VirtualFile[]): Uint8Array;
|
package/dist/checksum.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.checksumFiles = exports.checksum = void 0;
|
|
4
|
+
const utils_1 = require("@metamask/utils");
|
|
5
|
+
const sha256_1 = require("@noble/hashes/sha256");
|
|
6
|
+
const VirtualFile_1 = require("./virtual-file/VirtualFile");
|
|
7
|
+
/**
|
|
8
|
+
* Calculates checksum for a single byte array.
|
|
9
|
+
*
|
|
10
|
+
* @param bytes - The byte array to calculate the checksum for.
|
|
11
|
+
* @returns A single sha-256 checksum.
|
|
12
|
+
*/
|
|
13
|
+
function checksum(bytes) {
|
|
14
|
+
const value = bytes instanceof VirtualFile_1.VirtualFile ? bytes.value : bytes;
|
|
15
|
+
return (0, sha256_1.sha256)(value);
|
|
16
|
+
}
|
|
17
|
+
exports.checksum = checksum;
|
|
18
|
+
/**
|
|
19
|
+
* Calculates checksum over multiple files in a reproducible way.
|
|
20
|
+
*
|
|
21
|
+
* 1. Sort all the files by their paths.
|
|
22
|
+
* 2. Calculate sha-256 checksum of each file separately.
|
|
23
|
+
* 3. Concatenate all the checksums into one buffer and sha-256 that buffer.
|
|
24
|
+
*
|
|
25
|
+
* The sorting of paths is done using {@link https://tc39.es/ecma262/#sec-islessthan UTF-16 Code Units}.
|
|
26
|
+
*
|
|
27
|
+
* @param files - The files over which to calculate the checksum.
|
|
28
|
+
* @returns A single sha-256 checksum.
|
|
29
|
+
*/
|
|
30
|
+
function checksumFiles(files) {
|
|
31
|
+
return checksum((0, utils_1.concatBytes)([...files]
|
|
32
|
+
.sort((a, b) => {
|
|
33
|
+
(0, utils_1.assert)(a.path !== b.path, 'Tried to sort files with non-unique paths.');
|
|
34
|
+
if (a.path < b.path) {
|
|
35
|
+
return -1;
|
|
36
|
+
}
|
|
37
|
+
return 1;
|
|
38
|
+
})
|
|
39
|
+
.map((file) => checksum(file))));
|
|
40
|
+
}
|
|
41
|
+
exports.checksumFiles = checksumFiles;
|
|
42
|
+
//# sourceMappingURL=checksum.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checksum.js","sourceRoot":"","sources":["../src/checksum.ts"],"names":[],"mappings":";;;AAAA,2CAAsD;AACtD,iDAA8C;AAE9C,4DAAyD;AAEzD;;;;;GAKG;AACH,SAAgB,QAAQ,CAAC,KAAwC;IAC/D,MAAM,KAAK,GAAG,KAAK,YAAY,yBAAW,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC;IACjE,OAAO,IAAA,eAAM,EAAC,KAAK,CAAC,CAAC;AACvB,CAAC;AAHD,4BAGC;AAED;;;;;;;;;;;GAWG;AACH,SAAgB,aAAa,CAAC,KAAoB;IAChD,OAAO,QAAQ,CACb,IAAA,mBAAW,EACT,CAAC,GAAG,KAAK,CAAC;SACP,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;QACb,IAAA,cAAM,EACJ,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,IAAI,EACjB,4CAA4C,CAC7C,CAAC;QACF,IAAI,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,EAAE;YACnB,OAAO,CAAC,CAAC,CAAC;SACX;QACD,OAAO,CAAC,CAAC;IACX,CAAC,CAAC;SACD,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CACjC,CACF,CAAC;AACJ,CAAC;AAjBD,sCAiBC","sourcesContent":["import { assert, concatBytes } from '@metamask/utils';\nimport { sha256 } from '@noble/hashes/sha256';\n\nimport { VirtualFile } from './virtual-file/VirtualFile';\n\n/**\n * Calculates checksum for a single byte array.\n *\n * @param bytes - The byte array to calculate the checksum for.\n * @returns A single sha-256 checksum.\n */\nexport function checksum(bytes: VirtualFile | Uint8Array | string): Uint8Array {\n const value = bytes instanceof VirtualFile ? bytes.value : bytes;\n return sha256(value);\n}\n\n/**\n * Calculates checksum over multiple files in a reproducible way.\n *\n * 1. Sort all the files by their paths.\n * 2. Calculate sha-256 checksum of each file separately.\n * 3. Concatenate all the checksums into one buffer and sha-256 that buffer.\n *\n * The sorting of paths is done using {@link https://tc39.es/ecma262/#sec-islessthan UTF-16 Code Units}.\n *\n * @param files - The files over which to calculate the checksum.\n * @returns A single sha-256 checksum.\n */\nexport function checksumFiles(files: VirtualFile[]) {\n return checksum(\n concatBytes(\n [...files]\n .sort((a, b) => {\n assert(\n a.path !== b.path,\n 'Tried to sort files with non-unique paths.',\n );\n if (a.path < b.path) {\n return -1;\n }\n return 1;\n })\n .map((file) => checksum(file)),\n ),\n );\n}\n"]}
|
package/dist/eval-worker.js
CHANGED
|
@@ -26,6 +26,7 @@ const snapModule = { exports: {} };
|
|
|
26
26
|
new Compartment(Object.assign(Object.assign({}, getMockEndowments()), { module: snapModule, exports: snapModule.exports })).evaluate((0, fs_1.readFileSync)(snapFilePath, 'utf8'));
|
|
27
27
|
const invalidExports = Object.keys(snapModule.exports).filter((snapExport) => !types_1.SNAP_EXPORT_NAMES.includes(snapExport));
|
|
28
28
|
if (invalidExports.length > 0) {
|
|
29
|
+
// eslint-disable-next-line no-console
|
|
29
30
|
console.warn(`Invalid snap exports detected:\n${invalidExports.join('\n')}`);
|
|
30
31
|
}
|
|
31
32
|
setTimeout(() => process.exit(0), 1000); // Hack to ensure worker exits
|
package/dist/eval-worker.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"eval-worker.js","sourceRoot":"","sources":["../src/eval-worker.ts"],"names":[],"mappings":";;AAAA,uDAAuD;AACvD,wBAAsB;AAEtB,2BAAkC;AAElC,iCAAgD;AAChD,mCAAyD;AAIzD,QAAQ,iBACN,aAAa,EAAE,QAAQ,EACvB,WAAW,EAAE,QAAQ,EACrB,UAAU,EAAE,QAAQ,EACpB,UAAU,EAAE,QAAQ,EACpB,cAAc,EAAE,QAAQ,IAIrB,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,MAAM;IACjC,CAAC,CAAC;QACE,YAAY,EAAE,QAAQ;KACvB;IACH,CAAC,CAAC,EAAE,CAAC,EACP,CAAC;AAEH;;;;;;GAMG;AACH,SAAS,iBAAiB;IACxB,MAAM,UAAU,GAAG,IAAA,6BAAsB,GAAE,CAAC;IAC5C,uCACK,UAAU,KACb,MAAM,EAAE,UAAU,EAClB,IAAI,EAAE,UAAU,IAChB;AACJ,CAAC;AAED,MAAM,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAErC,MAAM,UAAU,GAAsB,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;AAEtD,IAAI,WAAW,iCACV,iBAAiB,EAAE,KACtB,MAAM,EAAE,UAAU,EAClB,OAAO,EAAE,UAAU,CAAC,OAAO,IAC3B,CAAC,QAAQ,CAAC,IAAA,iBAAY,EAAC,YAAY,EAAE,MAAM,CAAC,CAAC,CAAC;AAEhD,MAAM,cAAc,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,MAAM,CAC3D,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC,yBAAiB,CAAC,QAAQ,CAAC,UAAyB,CAAC,CACvE,CAAC;AAEF,IAAI,cAAc,CAAC,MAAM,GAAG,CAAC,EAAE;IAC7B,OAAO,CAAC,IAAI,CAAC,mCAAmC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;CAC9E;AAED,UAAU,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,8BAA8B","sourcesContent":["// eslint-disable-next-line import/no-unassigned-import\nimport 'ses/lockdown';\n\nimport { readFileSync } from 'fs';\n\nimport { generateMockEndowments } from './mock';\nimport { HandlerType, SNAP_EXPORT_NAMES } from './types';\n\ndeclare let lockdown: any, Compartment: any;\n\nlockdown({\n consoleTaming: 'unsafe',\n errorTaming: 'unsafe',\n mathTaming: 'unsafe',\n dateTaming: 'unsafe',\n overrideTaming: 'severe',\n\n // TODO: See if there's an easier way to do this. This file is ran in a\n // separate process, so we can't mock SES with Jest.\n ...(process.env.NODE_ENV === 'test'\n ? {\n domainTaming: 'unsafe',\n }\n : {}),\n});\n\n/**\n * Get mock endowments that don't do anything. This is useful for running the\n * eval, for snaps that try to communicate with the extension on initialisation,\n * for example.\n *\n * @returns The mock endowments.\n */\nfunction getMockEndowments() {\n const endowments = generateMockEndowments();\n return {\n ...endowments,\n window: endowments,\n self: endowments,\n };\n}\n\nconst snapFilePath = process.argv[2];\n\nconst snapModule: { exports?: any } = { exports: {} };\n\nnew Compartment({\n ...getMockEndowments(),\n module: snapModule,\n exports: snapModule.exports,\n}).evaluate(readFileSync(snapFilePath, 'utf8'));\n\nconst invalidExports = Object.keys(snapModule.exports).filter(\n (snapExport) => !SNAP_EXPORT_NAMES.includes(snapExport as HandlerType),\n);\n\nif (invalidExports.length > 0) {\n console.warn(`Invalid snap exports detected:\\n${invalidExports.join('\\n')}`);\n}\n\nsetTimeout(() => process.exit(0), 1000); // Hack to ensure worker exits\n"]}
|
|
1
|
+
{"version":3,"file":"eval-worker.js","sourceRoot":"","sources":["../src/eval-worker.ts"],"names":[],"mappings":";;AAAA,uDAAuD;AACvD,wBAAsB;AAEtB,2BAAkC;AAElC,iCAAgD;AAChD,mCAAyD;AAIzD,QAAQ,iBACN,aAAa,EAAE,QAAQ,EACvB,WAAW,EAAE,QAAQ,EACrB,UAAU,EAAE,QAAQ,EACpB,UAAU,EAAE,QAAQ,EACpB,cAAc,EAAE,QAAQ,IAIrB,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,MAAM;IACjC,CAAC,CAAC;QACE,YAAY,EAAE,QAAQ;KACvB;IACH,CAAC,CAAC,EAAE,CAAC,EACP,CAAC;AAEH;;;;;;GAMG;AACH,SAAS,iBAAiB;IACxB,MAAM,UAAU,GAAG,IAAA,6BAAsB,GAAE,CAAC;IAC5C,uCACK,UAAU,KACb,MAAM,EAAE,UAAU,EAClB,IAAI,EAAE,UAAU,IAChB;AACJ,CAAC;AAED,MAAM,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAErC,MAAM,UAAU,GAAsB,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;AAEtD,IAAI,WAAW,iCACV,iBAAiB,EAAE,KACtB,MAAM,EAAE,UAAU,EAClB,OAAO,EAAE,UAAU,CAAC,OAAO,IAC3B,CAAC,QAAQ,CAAC,IAAA,iBAAY,EAAC,YAAY,EAAE,MAAM,CAAC,CAAC,CAAC;AAEhD,MAAM,cAAc,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,MAAM,CAC3D,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC,yBAAiB,CAAC,QAAQ,CAAC,UAAyB,CAAC,CACvE,CAAC;AAEF,IAAI,cAAc,CAAC,MAAM,GAAG,CAAC,EAAE;IAC7B,sCAAsC;IACtC,OAAO,CAAC,IAAI,CAAC,mCAAmC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;CAC9E;AAED,UAAU,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,8BAA8B","sourcesContent":["// eslint-disable-next-line import/no-unassigned-import\nimport 'ses/lockdown';\n\nimport { readFileSync } from 'fs';\n\nimport { generateMockEndowments } from './mock';\nimport { HandlerType, SNAP_EXPORT_NAMES } from './types';\n\ndeclare let lockdown: any, Compartment: any;\n\nlockdown({\n consoleTaming: 'unsafe',\n errorTaming: 'unsafe',\n mathTaming: 'unsafe',\n dateTaming: 'unsafe',\n overrideTaming: 'severe',\n\n // TODO: See if there's an easier way to do this. This file is ran in a\n // separate process, so we can't mock SES with Jest.\n ...(process.env.NODE_ENV === 'test'\n ? {\n domainTaming: 'unsafe',\n }\n : {}),\n});\n\n/**\n * Get mock endowments that don't do anything. This is useful for running the\n * eval, for snaps that try to communicate with the extension on initialisation,\n * for example.\n *\n * @returns The mock endowments.\n */\nfunction getMockEndowments() {\n const endowments = generateMockEndowments();\n return {\n ...endowments,\n window: endowments,\n self: endowments,\n };\n}\n\nconst snapFilePath = process.argv[2];\n\nconst snapModule: { exports?: any } = { exports: {} };\n\nnew Compartment({\n ...getMockEndowments(),\n module: snapModule,\n exports: snapModule.exports,\n}).evaluate(readFileSync(snapFilePath, 'utf8'));\n\nconst invalidExports = Object.keys(snapModule.exports).filter(\n (snapExport) => !SNAP_EXPORT_NAMES.includes(snapExport as HandlerType),\n);\n\nif (invalidExports.length > 0) {\n // eslint-disable-next-line no-console\n console.warn(`Invalid snap exports detected:\\n${invalidExports.join('\\n')}`);\n}\n\nsetTimeout(() => process.exit(0), 1000); // Hack to ensure worker exits\n"]}
|
package/dist/fs.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Json } from '@metamask/utils';
|
|
2
|
-
import {
|
|
2
|
+
import { VirtualFile } from './virtual-file';
|
|
3
3
|
/**
|
|
4
4
|
* Checks whether the given path string resolves to an existing directory, and
|
|
5
5
|
* optionally creates the directory if it doesn't exist.
|
|
@@ -22,16 +22,7 @@ export declare function isFile(pathString: string): Promise<boolean>;
|
|
|
22
22
|
* @param pathString - The path to the JSON file.
|
|
23
23
|
* @returns The parsed contents of the JSON file.
|
|
24
24
|
*/
|
|
25
|
-
export declare function readJsonFile<Type = Json>(pathString: string): Promise<Type
|
|
26
|
-
/**
|
|
27
|
-
* Utility function for reading `package.json` or the Snap manifest file.
|
|
28
|
-
* These are assumed to be in the current working directory.
|
|
29
|
-
*
|
|
30
|
-
* @param pathString - The base path of the file to read.
|
|
31
|
-
* @param snapJsonFileName - The name of the file to read.
|
|
32
|
-
* @returns The parsed JSON file.
|
|
33
|
-
*/
|
|
34
|
-
export declare function readSnapJsonFile(pathString: string, snapJsonFileName: NpmSnapFileNames): Promise<Json>;
|
|
25
|
+
export declare function readJsonFile<Type extends Json = Json>(pathString: string): Promise<VirtualFile<Type>>;
|
|
35
26
|
/**
|
|
36
27
|
* Gets the complete out file path from an output file name and parent
|
|
37
28
|
* directory path.
|
package/dist/fs.js
CHANGED
|
@@ -3,9 +3,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.validateDirPath = exports.validateFilePath = exports.validateOutfileName = exports.getOutfilePath = exports.
|
|
6
|
+
exports.validateDirPath = exports.validateFilePath = exports.validateOutfileName = exports.getOutfilePath = exports.readJsonFile = exports.isFile = exports.isDirectory = void 0;
|
|
7
7
|
const fs_1 = require("fs");
|
|
8
8
|
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const virtual_file_1 = require("./virtual-file");
|
|
9
10
|
/**
|
|
10
11
|
* Checks whether the given path string resolves to an existing directory, and
|
|
11
12
|
* optionally creates the directory if it doesn't exist.
|
|
@@ -57,30 +58,20 @@ async function readJsonFile(pathString) {
|
|
|
57
58
|
if (!pathString.endsWith('.json')) {
|
|
58
59
|
throw new Error('The specified file must be a ".json" file.');
|
|
59
60
|
}
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
exports.readJsonFile = readJsonFile;
|
|
63
|
-
/**
|
|
64
|
-
* Utility function for reading `package.json` or the Snap manifest file.
|
|
65
|
-
* These are assumed to be in the current working directory.
|
|
66
|
-
*
|
|
67
|
-
* @param pathString - The base path of the file to read.
|
|
68
|
-
* @param snapJsonFileName - The name of the file to read.
|
|
69
|
-
* @returns The parsed JSON file.
|
|
70
|
-
*/
|
|
71
|
-
async function readSnapJsonFile(pathString, snapJsonFileName) {
|
|
72
|
-
const path = path_1.default.join(pathString, snapJsonFileName);
|
|
61
|
+
let file;
|
|
73
62
|
try {
|
|
74
|
-
|
|
63
|
+
file = await (0, virtual_file_1.readVirtualFile)(pathString, 'utf8');
|
|
75
64
|
}
|
|
76
65
|
catch (error) {
|
|
77
66
|
if (error.code === 'ENOENT') {
|
|
78
|
-
throw new Error(`Could not find '${
|
|
67
|
+
throw new Error(`Could not find '${pathString}'. Please ensure that the file exists.`);
|
|
79
68
|
}
|
|
80
69
|
throw error;
|
|
81
70
|
}
|
|
71
|
+
file.result = JSON.parse(file.toString());
|
|
72
|
+
return file;
|
|
82
73
|
}
|
|
83
|
-
exports.
|
|
74
|
+
exports.readJsonFile = readJsonFile;
|
|
84
75
|
/**
|
|
85
76
|
* Gets the complete out file path from an output file name and parent
|
|
86
77
|
* directory path.
|
package/dist/fs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fs.js","sourceRoot":"","sources":["../src/fs.ts"],"names":[],"mappings":";;;;;;AACA,2BAAoC;AACpC,gDAA6B;
|
|
1
|
+
{"version":3,"file":"fs.js","sourceRoot":"","sources":["../src/fs.ts"],"names":[],"mappings":"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","sourcesContent":["import { Json } from '@metamask/utils';\nimport { promises as fs } from 'fs';\nimport pathUtils from 'path';\n\nimport { readVirtualFile, VirtualFile } from './virtual-file';\n\n/**\n * Checks whether the given path string resolves to an existing directory, and\n * optionally creates the directory if it doesn't exist.\n *\n * @param pathString - The path string to check.\n * @param createDir - Whether to create the directory if it doesn't exist.\n * @returns Whether the given path is an existing directory.\n */\nexport async function isDirectory(\n pathString: string,\n createDir: boolean,\n): Promise<boolean> {\n try {\n const stats = await fs.stat(pathString);\n return stats.isDirectory();\n } catch (error) {\n if (error.code === 'ENOENT') {\n if (!createDir) {\n return false;\n }\n\n await fs.mkdir(pathString, { recursive: true });\n return true;\n }\n\n return false;\n }\n}\n\n/**\n * Checks whether the given path string resolves to an existing file.\n *\n * @param pathString - The path string to check.\n * @returns Whether the given path is an existing file.\n */\nexport async function isFile(pathString: string): Promise<boolean> {\n try {\n const stats = await fs.stat(pathString);\n return stats.isFile();\n } catch (error) {\n return false;\n }\n}\n\n/**\n * Reads a `.json` file, parses its contents, and returns them.\n *\n * @param pathString - The path to the JSON file.\n * @returns The parsed contents of the JSON file.\n */\nexport async function readJsonFile<Type extends Json = Json>(\n pathString: string,\n): Promise<VirtualFile<Type>> {\n if (!pathString.endsWith('.json')) {\n throw new Error('The specified file must be a \".json\" file.');\n }\n\n let file;\n try {\n file = await readVirtualFile(pathString, 'utf8');\n } catch (error) {\n if (error.code === 'ENOENT') {\n throw new Error(\n `Could not find '${pathString}'. Please ensure that the file exists.`,\n );\n }\n\n throw error;\n }\n file.result = JSON.parse(file.toString());\n return file as VirtualFile<Type>;\n}\n\n/**\n * Gets the complete out file path from an output file name and parent\n * directory path.\n *\n * @param outDir - The path to the out file's parent directory.\n * @param outFileName - The out file's name.\n * @returns The complete path to the out file.\n */\nexport function getOutfilePath(outDir: string, outFileName: string): string {\n return pathUtils.join(outDir, outFileName || 'bundle.js');\n}\n\n/**\n * Ensures that the outfile name is just a `.js` file name.\n * Throws on validation failure.\n *\n * @param filename - The file name to validate.\n * @returns `true` if validation succeeded.\n * @throws If the file name is invalid.\n */\nexport function validateOutfileName(filename: string): boolean {\n if (\n !filename.endsWith('.js') ||\n filename === '.js' ||\n pathUtils.basename(filename) !== filename\n ) {\n throw new Error(`Invalid outfile name: ${filename}. Must be a .js file`);\n }\n return true;\n}\n\n/**\n * Validates a file path. Throws on validation failure.\n *\n * @param filePath - The file path to validate.\n * @returns `true` if validation succeeded.\n * @throws If the path does not resolve to a file.\n */\nexport async function validateFilePath(filePath: string): Promise<boolean> {\n const exists = await isFile(filePath);\n if (!exists) {\n throw new Error(\n `Invalid params: '${filePath}' is not a file or does not exist.`,\n );\n }\n return true;\n}\n\n/**\n * Validates a directory path. Throws on validation failure.\n *\n * @param dirPath - The directory path to validate.\n * @param createDir - Whether to create the directory if it doesn't exist.\n * @returns `true` if validation succeeded or the directory was created.\n * @throws If the directory does not exist or could not be created.\n */\nexport async function validateDirPath(\n dirPath: string,\n createDir: boolean,\n): Promise<boolean> {\n const exists = await isDirectory(dirPath, createDir);\n if (!exists) {\n throw new Error(\n `Invalid params: '${dirPath}' is not a directory or could not be created.`,\n );\n }\n return true;\n}\n"]}
|
package/dist/handlers.d.ts
CHANGED
|
@@ -1,13 +1,6 @@
|
|
|
1
|
-
import type { StreamProvider } from '@metamask/providers';
|
|
2
1
|
import { Component } from '@metamask/snaps-ui';
|
|
3
2
|
import { Json, JsonRpcRequest } from '@metamask/utils';
|
|
4
3
|
import { AccountId, ChainId, RequestArguments } from './namespace';
|
|
5
|
-
/**
|
|
6
|
-
* The global `snap` object. This is injected into the global scope of a snap.
|
|
7
|
-
*/
|
|
8
|
-
export declare type SnapsGlobalObject = {
|
|
9
|
-
request: StreamProvider['request'];
|
|
10
|
-
};
|
|
11
4
|
/**
|
|
12
5
|
* The `onRpcRequest` handler. This is called whenever a JSON-RPC request is
|
|
13
6
|
* made to the snap.
|
package/dist/handlers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handlers.js","sourceRoot":"","sources":["../src/handlers.ts"],"names":[],"mappings":"","sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"handlers.js","sourceRoot":"","sources":["../src/handlers.ts"],"names":[],"mappings":"","sourcesContent":["import { Component } from '@metamask/snaps-ui';\nimport { Json, JsonRpcRequest } from '@metamask/utils';\n\nimport { AccountId, ChainId, RequestArguments } from './namespace';\n\n/**\n * The `onRpcRequest` handler. This is called whenever a JSON-RPC request is\n * made to the snap.\n *\n * @param args - The request arguments.\n * @param args.origin - The origin of the request. This can be the ID of another\n * snap, or the URL of a dapp.\n * @param args.request - The JSON-RPC request sent to the snap.\n * @returns The JSON-RPC response. This must be a JSON-serializable value.\n */\nexport type OnRpcRequestHandler = (args: {\n origin: string;\n request: JsonRpcRequest<Json[] | Record<string, Json>>;\n}) => Promise<unknown>;\n\n/**\n * The response from a snap's `onTransaction` handler.\n *\n * @property insights - The insights object. This is a key-value map of the\n * insights that the snap has about the transaction. The keys are the insight\n * names, and the values are the insight values. The insight values must be\n * JSON-serializable.\n *\n * If the snap has no insights about the transaction, this should be `null`.\n */\nexport type OnTransactionResponse = {\n content: Component;\n};\n\n/**\n * The `onTransaction` handler. This is called whenever a transaction is\n * submitted to the snap. It can return insights about the transaction, which\n * will be displayed to the user.\n *\n * @param args - The request arguments.\n * @param args.transaction - The transaction object.\n * @param args.chainId - The CAIP-2 chain ID of the network the transaction is\n * being submitted to.\n * @param args.transactionOrigin - The origin of the transaction. This is the\n * URL of the dapp that submitted the transaction.\n * @returns Insights about the transaction. See {@link OnTransactionResponse}.\n */\n// TODO: Improve type.\nexport type OnTransactionHandler = (args: {\n transaction: { [key: string]: Json };\n chainId: string;\n transactionOrigin?: string;\n}) => Promise<OnTransactionResponse>;\n\n/**\n * The `onCronjob` handler. This is called on a regular interval, as defined by\n * the snap's manifest.\n *\n * @param args - The request arguments.\n * @param args.request - The JSON-RPC request sent to the snap.\n */\nexport type OnCronjobHandler = (args: {\n request: JsonRpcRequest<Json[] | Record<string, Json>>;\n}) => Promise<unknown>;\n\n/**\n * A request sent to the `handleRequest` handler of a snap keyring.\n *\n * @property chainId - The CAIP-2 chain ID of the network the request is being\n * made to.\n * @property origin - The origin of the request. This can be the ID of another\n * snap, or the URL of a dapp.\n */\nexport type KeyringRequest = {\n chainId: ChainId;\n origin: string;\n};\n\n/**\n * A keyring event, which consists of a {@link KeyringRequest}, combined with\n * the name of the event.\n */\nexport type KeyringEvent = KeyringRequest & { eventName: string };\n\n/**\n * A snap keyring object, which can be exported as `keyring` in a snap.\n */\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\nexport interface SnapKeyring {\n getAccounts(): Promise<AccountId[]>;\n handleRequest(\n data: KeyringRequest & {\n request: RequestArguments;\n },\n ): Promise<Json>;\n on(data: KeyringEvent, listener: (...args: Json[]) => void): void;\n off(data: KeyringEvent): void;\n\n addAccount?(chainId: ChainId): Promise<AccountId>;\n removeAccount?(accountId: AccountId): Promise<void>;\n\n importAccount?(chainId: ChainId, data: Json): Promise<AccountId>;\n exportAccount?(accountId: AccountId): Promise<Json>;\n}\n\n/**\n * All the function-based handlers that a snap can implement.\n */\nexport type SnapFunctionExports = {\n onRpcRequest?: OnRpcRequestHandler;\n onTransaction?: OnTransactionHandler;\n onCronjob?: OnCronjobHandler;\n};\n\n/**\n * All handlers that a snap can implement.\n */\nexport type SnapExports = SnapFunctionExports & {\n keyring?: SnapKeyring;\n};\n"]}
|
package/dist/index.browser.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export * from './caveats';
|
|
2
|
+
export * from './checksum';
|
|
2
3
|
export * from './cronjob';
|
|
3
4
|
export * from './deep-clone';
|
|
4
5
|
export * from './default-endowments';
|
|
@@ -7,6 +8,7 @@ export * from './flatMap';
|
|
|
7
8
|
export * from './handlers';
|
|
8
9
|
export * from './iframe';
|
|
9
10
|
export * from './json-rpc';
|
|
11
|
+
export * from './logging';
|
|
10
12
|
export * from './manifest/index.browser';
|
|
11
13
|
export * from './namespace';
|
|
12
14
|
export * from './notification';
|
package/dist/index.browser.js
CHANGED
|
@@ -15,6 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./caveats"), exports);
|
|
18
|
+
__exportStar(require("./checksum"), exports);
|
|
18
19
|
__exportStar(require("./cronjob"), exports);
|
|
19
20
|
__exportStar(require("./deep-clone"), exports);
|
|
20
21
|
__exportStar(require("./default-endowments"), exports);
|
|
@@ -23,6 +24,7 @@ __exportStar(require("./flatMap"), exports);
|
|
|
23
24
|
__exportStar(require("./handlers"), exports);
|
|
24
25
|
__exportStar(require("./iframe"), exports);
|
|
25
26
|
__exportStar(require("./json-rpc"), exports);
|
|
27
|
+
__exportStar(require("./logging"), exports);
|
|
26
28
|
__exportStar(require("./manifest/index.browser"), exports);
|
|
27
29
|
__exportStar(require("./namespace"), exports);
|
|
28
30
|
__exportStar(require("./notification"), exports);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.browser.js","sourceRoot":"","sources":["../src/index.browser.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAA0B;AAC1B,4CAA0B;AAC1B,+CAA6B;AAC7B,uDAAqC;AACrC,4CAA0B;AAC1B,4CAA0B;AAC1B,6CAA2B;AAC3B,2CAAyB;AACzB,6CAA2B;AAC3B,2DAAyC;AACzC,8CAA4B;AAC5B,iDAA+B;AAC/B,2CAAyB;AACzB,yCAAuB;AACvB,0CAAwB;AACxB,0CAAwB;AACxB,6CAA2B;AAC3B,+DAA6C","sourcesContent":["export * from './caveats';\nexport * from './cronjob';\nexport * from './deep-clone';\nexport * from './default-endowments';\nexport * from './entropy';\nexport * from './flatMap';\nexport * from './handlers';\nexport * from './iframe';\nexport * from './json-rpc';\nexport * from './manifest/index.browser';\nexport * from './namespace';\nexport * from './notification';\nexport * from './object';\nexport * from './path';\nexport * from './snaps';\nexport * from './types';\nexport * from './versions';\nexport * from './virtual-file/index.browser';\n"]}
|
|
1
|
+
{"version":3,"file":"index.browser.js","sourceRoot":"","sources":["../src/index.browser.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAA0B;AAC1B,6CAA2B;AAC3B,4CAA0B;AAC1B,+CAA6B;AAC7B,uDAAqC;AACrC,4CAA0B;AAC1B,4CAA0B;AAC1B,6CAA2B;AAC3B,2CAAyB;AACzB,6CAA2B;AAC3B,4CAA0B;AAC1B,2DAAyC;AACzC,8CAA4B;AAC5B,iDAA+B;AAC/B,2CAAyB;AACzB,yCAAuB;AACvB,0CAAwB;AACxB,0CAAwB;AACxB,6CAA2B;AAC3B,+DAA6C","sourcesContent":["export * from './caveats';\nexport * from './checksum';\nexport * from './cronjob';\nexport * from './deep-clone';\nexport * from './default-endowments';\nexport * from './entropy';\nexport * from './flatMap';\nexport * from './handlers';\nexport * from './iframe';\nexport * from './json-rpc';\nexport * from './logging';\nexport * from './manifest/index.browser';\nexport * from './namespace';\nexport * from './notification';\nexport * from './object';\nexport * from './path';\nexport * from './snaps';\nexport * from './types';\nexport * from './versions';\nexport * from './virtual-file/index.browser';\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export * from './caveats';
|
|
2
2
|
export * from './cronjob';
|
|
3
|
+
export * from './checksum';
|
|
3
4
|
export * from './deep-clone';
|
|
4
5
|
export * from './default-endowments';
|
|
5
6
|
export * from './entropy';
|
|
@@ -9,6 +10,7 @@ export * from './fs';
|
|
|
9
10
|
export * from './handlers';
|
|
10
11
|
export * from './iframe';
|
|
11
12
|
export * from './json-rpc';
|
|
13
|
+
export * from './logging';
|
|
12
14
|
export * from './manifest';
|
|
13
15
|
export * from './mock';
|
|
14
16
|
export * from './namespace';
|
package/dist/index.js
CHANGED
|
@@ -16,6 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./caveats"), exports);
|
|
18
18
|
__exportStar(require("./cronjob"), exports);
|
|
19
|
+
__exportStar(require("./checksum"), exports);
|
|
19
20
|
__exportStar(require("./deep-clone"), exports);
|
|
20
21
|
__exportStar(require("./default-endowments"), exports);
|
|
21
22
|
__exportStar(require("./entropy"), exports);
|
|
@@ -25,6 +26,7 @@ __exportStar(require("./fs"), exports);
|
|
|
25
26
|
__exportStar(require("./handlers"), exports);
|
|
26
27
|
__exportStar(require("./iframe"), exports);
|
|
27
28
|
__exportStar(require("./json-rpc"), exports);
|
|
29
|
+
__exportStar(require("./logging"), exports);
|
|
28
30
|
__exportStar(require("./manifest"), exports);
|
|
29
31
|
__exportStar(require("./mock"), exports);
|
|
30
32
|
__exportStar(require("./namespace"), exports);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAA0B;AAC1B,4CAA0B;AAC1B,+CAA6B;AAC7B,uDAAqC;AACrC,4CAA0B;AAC1B,yCAAuB;AACvB,4CAA0B;AAC1B,uCAAqB;AACrB,6CAA2B;AAC3B,2CAAyB;AACzB,6CAA2B;AAC3B,6CAA2B;AAC3B,yCAAuB;AACvB,8CAA4B;AAC5B,iDAA+B;AAC/B,wCAAsB;AACtB,2CAAyB;AACzB,yCAAuB;AACvB,iDAA+B;AAC/B,0CAAwB;AACxB,0CAAwB;AACxB,6CAA2B;AAC3B,iDAA+B","sourcesContent":["export * from './caveats';\nexport * from './cronjob';\nexport * from './deep-clone';\nexport * from './default-endowments';\nexport * from './entropy';\nexport * from './eval';\nexport * from './flatMap';\nexport * from './fs';\nexport * from './handlers';\nexport * from './iframe';\nexport * from './json-rpc';\nexport * from './manifest';\nexport * from './mock';\nexport * from './namespace';\nexport * from './notification';\nexport * from './npm';\nexport * from './object';\nexport * from './path';\nexport * from './post-process';\nexport * from './snaps';\nexport * from './types';\nexport * from './versions';\nexport * from './virtual-file';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAA0B;AAC1B,4CAA0B;AAC1B,6CAA2B;AAC3B,+CAA6B;AAC7B,uDAAqC;AACrC,4CAA0B;AAC1B,yCAAuB;AACvB,4CAA0B;AAC1B,uCAAqB;AACrB,6CAA2B;AAC3B,2CAAyB;AACzB,6CAA2B;AAC3B,4CAA0B;AAC1B,6CAA2B;AAC3B,yCAAuB;AACvB,8CAA4B;AAC5B,iDAA+B;AAC/B,wCAAsB;AACtB,2CAAyB;AACzB,yCAAuB;AACvB,iDAA+B;AAC/B,0CAAwB;AACxB,0CAAwB;AACxB,6CAA2B;AAC3B,iDAA+B","sourcesContent":["export * from './caveats';\nexport * from './cronjob';\nexport * from './checksum';\nexport * from './deep-clone';\nexport * from './default-endowments';\nexport * from './entropy';\nexport * from './eval';\nexport * from './flatMap';\nexport * from './fs';\nexport * from './handlers';\nexport * from './iframe';\nexport * from './json-rpc';\nexport * from './logging';\nexport * from './manifest';\nexport * from './mock';\nexport * from './namespace';\nexport * from './notification';\nexport * from './npm';\nexport * from './object';\nexport * from './path';\nexport * from './post-process';\nexport * from './snaps';\nexport * from './types';\nexport * from './versions';\nexport * from './virtual-file';\n"]}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/// <reference types="debug" />
|
|
2
|
+
export declare const snapsLogger: import("debug").Debugger;
|
|
3
|
+
/**
|
|
4
|
+
* Log a message. Currently, this is just a wrapper around `console.log`, but
|
|
5
|
+
* the implementation may change in the future. These logs will be included in
|
|
6
|
+
* production builds, so they should be used sparingly, and not contain any
|
|
7
|
+
* sensitive information.
|
|
8
|
+
*
|
|
9
|
+
* This function makes it easy to swap out the logging implementation in all
|
|
10
|
+
* files at once.
|
|
11
|
+
*
|
|
12
|
+
* @param message - The message to log.
|
|
13
|
+
* @param optionalParams - Additional parameters to pass to the logging.
|
|
14
|
+
*/
|
|
15
|
+
export declare function logInfo(message: string, ...optionalParams: unknown[]): void;
|
|
16
|
+
/**
|
|
17
|
+
* Log an error. Currently, this is just a wrapper around `console.error`, but
|
|
18
|
+
* the implementation may change in the future. These logs will be included in
|
|
19
|
+
* production builds, so they should be used sparingly, and not contain any
|
|
20
|
+
* sensitive information.
|
|
21
|
+
*
|
|
22
|
+
* These logs should always be visible, without requiring the user to enable
|
|
23
|
+
* verbose logging (like setting a `DEBUG` environment variable), as they are
|
|
24
|
+
* important for debugging snaps.
|
|
25
|
+
*
|
|
26
|
+
* This function makes it easy to swap out the logging implementation in all
|
|
27
|
+
* files at once.
|
|
28
|
+
*
|
|
29
|
+
* @param error - The error to log.
|
|
30
|
+
* @param optionalParams - Additional parameters to pass to the logging.
|
|
31
|
+
*/
|
|
32
|
+
export declare function logError(error: unknown, ...optionalParams: unknown[]): void;
|
|
33
|
+
/**
|
|
34
|
+
* Log a warning. Currently, this is just a wrapper around `console.warn`, but
|
|
35
|
+
* the implementation may change in the future. These logs will be included in
|
|
36
|
+
* production builds, so they should be used sparingly, and not contain any
|
|
37
|
+
* sensitive information.
|
|
38
|
+
*
|
|
39
|
+
* These logs should always be visible, without requiring the user to enable
|
|
40
|
+
* verbose logging (like setting a `DEBUG` environment variable), as they are
|
|
41
|
+
* important for debugging snaps.
|
|
42
|
+
*
|
|
43
|
+
* This function makes it easy to swap out the logging implementation in all
|
|
44
|
+
* files at once.
|
|
45
|
+
*
|
|
46
|
+
* @param message - The message to log.
|
|
47
|
+
* @param optionalParams - Additional parameters to pass to the logging.
|
|
48
|
+
*/
|
|
49
|
+
export declare function logWarning(message: string, ...optionalParams: unknown[]): void;
|
package/dist/logging.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.logWarning = exports.logError = exports.logInfo = exports.snapsLogger = void 0;
|
|
4
|
+
const utils_1 = require("@metamask/utils");
|
|
5
|
+
// The global logger used across the monorepo. Other projects should use this
|
|
6
|
+
// to create a module logger.
|
|
7
|
+
exports.snapsLogger = (0, utils_1.createProjectLogger)('snaps');
|
|
8
|
+
/**
|
|
9
|
+
* Log a message. Currently, this is just a wrapper around `console.log`, but
|
|
10
|
+
* the implementation may change in the future. These logs will be included in
|
|
11
|
+
* production builds, so they should be used sparingly, and not contain any
|
|
12
|
+
* sensitive information.
|
|
13
|
+
*
|
|
14
|
+
* This function makes it easy to swap out the logging implementation in all
|
|
15
|
+
* files at once.
|
|
16
|
+
*
|
|
17
|
+
* @param message - The message to log.
|
|
18
|
+
* @param optionalParams - Additional parameters to pass to the logging.
|
|
19
|
+
*/
|
|
20
|
+
function logInfo(message, ...optionalParams) {
|
|
21
|
+
// eslint-disable-next-line no-console
|
|
22
|
+
console.log(message, ...optionalParams);
|
|
23
|
+
}
|
|
24
|
+
exports.logInfo = logInfo;
|
|
25
|
+
/**
|
|
26
|
+
* Log an error. Currently, this is just a wrapper around `console.error`, but
|
|
27
|
+
* the implementation may change in the future. These logs will be included in
|
|
28
|
+
* production builds, so they should be used sparingly, and not contain any
|
|
29
|
+
* sensitive information.
|
|
30
|
+
*
|
|
31
|
+
* These logs should always be visible, without requiring the user to enable
|
|
32
|
+
* verbose logging (like setting a `DEBUG` environment variable), as they are
|
|
33
|
+
* important for debugging snaps.
|
|
34
|
+
*
|
|
35
|
+
* This function makes it easy to swap out the logging implementation in all
|
|
36
|
+
* files at once.
|
|
37
|
+
*
|
|
38
|
+
* @param error - The error to log.
|
|
39
|
+
* @param optionalParams - Additional parameters to pass to the logging.
|
|
40
|
+
*/
|
|
41
|
+
function logError(error, ...optionalParams) {
|
|
42
|
+
// eslint-disable-next-line no-console
|
|
43
|
+
console.error(error, ...optionalParams);
|
|
44
|
+
}
|
|
45
|
+
exports.logError = logError;
|
|
46
|
+
/**
|
|
47
|
+
* Log a warning. Currently, this is just a wrapper around `console.warn`, but
|
|
48
|
+
* the implementation may change in the future. These logs will be included in
|
|
49
|
+
* production builds, so they should be used sparingly, and not contain any
|
|
50
|
+
* sensitive information.
|
|
51
|
+
*
|
|
52
|
+
* These logs should always be visible, without requiring the user to enable
|
|
53
|
+
* verbose logging (like setting a `DEBUG` environment variable), as they are
|
|
54
|
+
* important for debugging snaps.
|
|
55
|
+
*
|
|
56
|
+
* This function makes it easy to swap out the logging implementation in all
|
|
57
|
+
* files at once.
|
|
58
|
+
*
|
|
59
|
+
* @param message - The message to log.
|
|
60
|
+
* @param optionalParams - Additional parameters to pass to the logging.
|
|
61
|
+
*/
|
|
62
|
+
function logWarning(message, ...optionalParams) {
|
|
63
|
+
// eslint-disable-next-line no-console
|
|
64
|
+
console.warn(message, ...optionalParams);
|
|
65
|
+
}
|
|
66
|
+
exports.logWarning = logWarning;
|
|
67
|
+
//# sourceMappingURL=logging.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logging.js","sourceRoot":"","sources":["../src/logging.ts"],"names":[],"mappings":";;;AAAA,2CAAsD;AAEtD,6EAA6E;AAC7E,6BAA6B;AAChB,QAAA,WAAW,GAAG,IAAA,2BAAmB,EAAC,OAAO,CAAC,CAAC;AAExD;;;;;;;;;;;GAWG;AACH,SAAgB,OAAO,CAAC,OAAe,EAAE,GAAG,cAAyB;IACnE,sCAAsC;IACtC,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,cAAc,CAAC,CAAC;AAC1C,CAAC;AAHD,0BAGC;AAED;;;;;;;;;;;;;;;GAeG;AACH,SAAgB,QAAQ,CAAC,KAAc,EAAE,GAAG,cAAyB;IACnE,sCAAsC;IACtC,OAAO,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,cAAc,CAAC,CAAC;AAC1C,CAAC;AAHD,4BAGC;AAED;;;;;;;;;;;;;;;GAeG;AACH,SAAgB,UAAU,CACxB,OAAe,EACf,GAAG,cAAyB;IAE5B,sCAAsC;IACtC,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,cAAc,CAAC,CAAC;AAC3C,CAAC;AAND,gCAMC","sourcesContent":["import { createProjectLogger } from '@metamask/utils';\n\n// The global logger used across the monorepo. Other projects should use this\n// to create a module logger.\nexport const snapsLogger = createProjectLogger('snaps');\n\n/**\n * Log a message. Currently, this is just a wrapper around `console.log`, but\n * the implementation may change in the future. These logs will be included in\n * production builds, so they should be used sparingly, and not contain any\n * sensitive information.\n *\n * This function makes it easy to swap out the logging implementation in all\n * files at once.\n *\n * @param message - The message to log.\n * @param optionalParams - Additional parameters to pass to the logging.\n */\nexport function logInfo(message: string, ...optionalParams: unknown[]): void {\n // eslint-disable-next-line no-console\n console.log(message, ...optionalParams);\n}\n\n/**\n * Log an error. Currently, this is just a wrapper around `console.error`, but\n * the implementation may change in the future. These logs will be included in\n * production builds, so they should be used sparingly, and not contain any\n * sensitive information.\n *\n * These logs should always be visible, without requiring the user to enable\n * verbose logging (like setting a `DEBUG` environment variable), as they are\n * important for debugging snaps.\n *\n * This function makes it easy to swap out the logging implementation in all\n * files at once.\n *\n * @param error - The error to log.\n * @param optionalParams - Additional parameters to pass to the logging.\n */\nexport function logError(error: unknown, ...optionalParams: unknown[]): void {\n // eslint-disable-next-line no-console\n console.error(error, ...optionalParams);\n}\n\n/**\n * Log a warning. Currently, this is just a wrapper around `console.warn`, but\n * the implementation may change in the future. These logs will be included in\n * production builds, so they should be used sparingly, and not contain any\n * sensitive information.\n *\n * These logs should always be visible, without requiring the user to enable\n * verbose logging (like setting a `DEBUG` environment variable), as they are\n * important for debugging snaps.\n *\n * This function makes it easy to swap out the logging implementation in all\n * files at once.\n *\n * @param message - The message to log.\n * @param optionalParams - Additional parameters to pass to the logging.\n */\nexport function logWarning(\n message: string,\n ...optionalParams: unknown[]\n): void {\n // eslint-disable-next-line no-console\n console.warn(message, ...optionalParams);\n}\n"]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Json } from '@metamask/utils';
|
|
2
2
|
import { ProgrammaticallyFixableSnapError } from '../snaps';
|
|
3
|
-
import {
|
|
3
|
+
import { SnapFiles } from '../types';
|
|
4
|
+
import { VirtualFile } from '../virtual-file';
|
|
4
5
|
import { SnapManifest } from './validation';
|
|
5
6
|
/**
|
|
6
7
|
* The result from the `checkManifest` function.
|
|
@@ -43,16 +44,26 @@ export declare function checkManifest(basePath: string, writeManifest?: boolean,
|
|
|
43
44
|
* @param error - The {@link ProgrammaticallyFixableSnapError} that was thrown.
|
|
44
45
|
* @returns A copy of the manifest file where the cause of the error is fixed.
|
|
45
46
|
*/
|
|
46
|
-
export declare function fixManifest(snapFiles: SnapFiles, error: ProgrammaticallyFixableSnapError): SnapManifest
|
|
47
|
+
export declare function fixManifest(snapFiles: SnapFiles, error: ProgrammaticallyFixableSnapError): VirtualFile<SnapManifest>;
|
|
47
48
|
/**
|
|
48
49
|
* Given an unvalidated Snap manifest, attempts to extract the location of the
|
|
49
50
|
* bundle source file location and read the file.
|
|
50
51
|
*
|
|
51
52
|
* @param basePath - The path to the folder with the manifest files.
|
|
52
53
|
* @param manifest - The unvalidated Snap manifest file contents.
|
|
54
|
+
* @param sourceCode - Override source code for plugins.
|
|
53
55
|
* @returns The contents of the bundle file, if any.
|
|
54
56
|
*/
|
|
55
|
-
export declare function getSnapSourceCode(basePath: string, manifest: Json): Promise<
|
|
57
|
+
export declare function getSnapSourceCode(basePath: string, manifest: Json, sourceCode?: string): Promise<VirtualFile | undefined>;
|
|
58
|
+
/**
|
|
59
|
+
* Given an unvalidated Snap manifest, attempts to extract the location of the
|
|
60
|
+
* icon and read the file.
|
|
61
|
+
*
|
|
62
|
+
* @param basePath - The path to the folder with the manifest files.
|
|
63
|
+
* @param manifest - The unvalidated Snap manifest file contents.
|
|
64
|
+
* @returns The contents of the icon, if any.
|
|
65
|
+
*/
|
|
66
|
+
export declare function getSnapIcon(basePath: string, manifest: Json): Promise<VirtualFile | undefined>;
|
|
56
67
|
/**
|
|
57
68
|
* Sorts the given manifest in our preferred sort order and removes the
|
|
58
69
|
* `repository` field if it is falsy (it may be `null`).
|
|
@@ -69,7 +80,6 @@ export declare function getWritableManifest(manifest: SnapManifest): SnapManifes
|
|
|
69
80
|
* @param snapFiles.manifest - The npm Snap manifest to validate.
|
|
70
81
|
* @param snapFiles.packageJson - The npm Snap's `package.json`.
|
|
71
82
|
* @param snapFiles.sourceCode - The Snap's source code.
|
|
72
|
-
* @
|
|
73
|
-
* and `package.json`.
|
|
83
|
+
* @param snapFiles.svgIcon - The Snap's optional icon.
|
|
74
84
|
*/
|
|
75
|
-
export declare function validateNpmSnapManifest({ manifest, packageJson, sourceCode, }: SnapFiles):
|
|
85
|
+
export declare function validateNpmSnapManifest({ manifest, packageJson, sourceCode, svgIcon, }: SnapFiles): void;
|