@metamask/snaps-utils 5.0.0 → 5.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -1
- package/dist/cjs/auxiliary-files.js +3 -3
- package/dist/cjs/auxiliary-files.js.map +1 -1
- package/dist/cjs/base64.js +44 -0
- package/dist/cjs/base64.js.map +1 -0
- package/dist/cjs/bytes.js +23 -0
- package/dist/cjs/bytes.js.map +1 -0
- package/dist/cjs/checksum.js +2 -14
- package/dist/cjs/checksum.js.map +1 -1
- package/dist/cjs/derivation-paths.js +300 -0
- package/dist/cjs/derivation-paths.js.map +1 -0
- package/dist/cjs/index.browser.js +3 -0
- package/dist/cjs/index.browser.js.map +1 -1
- package/dist/cjs/index.js +3 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/virtual-file/VirtualFile.js +1 -0
- package/dist/cjs/virtual-file/VirtualFile.js.map +1 -1
- package/dist/esm/auxiliary-files.js +3 -3
- package/dist/esm/auxiliary-files.js.map +1 -1
- package/dist/esm/base64.js +36 -0
- package/dist/esm/base64.js.map +1 -0
- package/dist/esm/bytes.js +18 -0
- package/dist/esm/bytes.js.map +1 -0
- package/dist/esm/checksum.js +3 -17
- package/dist/esm/checksum.js.map +1 -1
- package/dist/esm/derivation-paths.js +287 -0
- package/dist/esm/derivation-paths.js.map +1 -0
- package/dist/esm/index.browser.js +3 -0
- package/dist/esm/index.browser.js.map +1 -1
- package/dist/esm/index.js +3 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/virtual-file/VirtualFile.js +1 -0
- package/dist/esm/virtual-file/VirtualFile.js.map +1 -1
- package/dist/types/auxiliary-files.d.ts +1 -1
- package/dist/types/base64.d.ts +15 -0
- package/dist/types/bytes.d.ts +8 -0
- package/dist/types/checksum.d.ts +1 -8
- package/dist/types/derivation-paths.d.ts +24 -0
- package/dist/types/index.browser.d.ts +3 -0
- package/dist/types/index.d.ts +3 -0
- package/package.json +6 -5
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [5.1.0]
|
|
10
|
+
### Added
|
|
11
|
+
- Add `getSnapDerivationPathName` and `getSlip44ProtocolName` to be shared across clients ([#2033](https://github.com/MetaMask/snaps/pull/2033))
|
|
12
|
+
|
|
13
|
+
### Changed
|
|
14
|
+
- Bump `snaps-registry` ([#2020](https://hub.com/MetaMask/snaps/pull/2020))
|
|
15
|
+
|
|
16
|
+
## [5.0.1]
|
|
17
|
+
### Changed
|
|
18
|
+
- Improve base64 encoding/decoding speeds ([#1985](https://github.com/MetaMask/snaps/pull/1985))
|
|
19
|
+
- Bump several MetaMask dependencies ([#1989](https://github.com/MetaMask/snaps/pull/1989), [#1993](https://github.com/MetaMask/snaps/pull/1993))
|
|
20
|
+
|
|
9
21
|
## [5.0.0]
|
|
10
22
|
### Changed
|
|
11
23
|
- Bump several MetaMask dependencies ([#1964](https://github.com/MetaMask/snaps/pull/1964))
|
|
@@ -117,7 +129,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
117
129
|
- The version of the package no longer needs to match the version of all other
|
|
118
130
|
MetaMask Snaps packages.
|
|
119
131
|
|
|
120
|
-
[Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-utils@5.
|
|
132
|
+
[Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-utils@5.1.0...HEAD
|
|
133
|
+
[5.1.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-utils@5.0.1...@metamask/snaps-utils@5.1.0
|
|
134
|
+
[5.0.1]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-utils@5.0.0...@metamask/snaps-utils@5.0.1
|
|
121
135
|
[5.0.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-utils@4.0.1...@metamask/snaps-utils@5.0.0
|
|
122
136
|
[4.0.1]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-utils@4.0.0...@metamask/snaps-utils@4.0.1
|
|
123
137
|
[4.0.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-utils@3.3.0...@metamask/snaps-utils@4.0.0
|
|
@@ -10,14 +10,14 @@ Object.defineProperty(exports, "encodeAuxiliaryFile", {
|
|
|
10
10
|
});
|
|
11
11
|
const _snapssdk = require("@metamask/snaps-sdk");
|
|
12
12
|
const _utils = require("@metamask/utils");
|
|
13
|
-
const
|
|
14
|
-
function encodeAuxiliaryFile(value, encoding) {
|
|
13
|
+
const _base64 = require("./base64");
|
|
14
|
+
async function encodeAuxiliaryFile(value, encoding) {
|
|
15
15
|
// Input is assumed to be the stored file in base64.
|
|
16
16
|
if (encoding === _snapssdk.AuxiliaryFileEncoding.Base64) {
|
|
17
17
|
return value;
|
|
18
18
|
}
|
|
19
19
|
// TODO: Use @metamask/utils for this
|
|
20
|
-
const decoded =
|
|
20
|
+
const decoded = await (0, _base64.decodeBase64)(value);
|
|
21
21
|
if (encoding === _snapssdk.AuxiliaryFileEncoding.Utf8) {
|
|
22
22
|
return (0, _utils.bytesToString)(decoded);
|
|
23
23
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/auxiliary-files.ts"],"sourcesContent":["import { AuxiliaryFileEncoding } from '@metamask/snaps-sdk';\nimport { bytesToHex, bytesToString } from '@metamask/utils';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../src/auxiliary-files.ts"],"sourcesContent":["import { AuxiliaryFileEncoding } from '@metamask/snaps-sdk';\nimport { bytesToHex, bytesToString } from '@metamask/utils';\n\nimport { decodeBase64 } from './base64';\n\n/**\n * Re-encodes an auxiliary file if needed depending on the requested file encoding.\n *\n * @param value - The base64 value stored for the auxiliary file.\n * @param encoding - The chosen encoding.\n * @returns The file encoded in the requested encoding.\n */\nexport async function encodeAuxiliaryFile(\n value: string,\n encoding: AuxiliaryFileEncoding,\n) {\n // Input is assumed to be the stored file in base64.\n if (encoding === AuxiliaryFileEncoding.Base64) {\n return value;\n }\n\n // TODO: Use @metamask/utils for this\n const decoded = await decodeBase64(value);\n if (encoding === AuxiliaryFileEncoding.Utf8) {\n return bytesToString(decoded);\n }\n\n return bytesToHex(decoded);\n}\n"],"names":["encodeAuxiliaryFile","value","encoding","AuxiliaryFileEncoding","Base64","decoded","decodeBase64","Utf8","bytesToString","bytesToHex"],"mappings":";;;;+BAYsBA;;;eAAAA;;;0BAZgB;uBACI;wBAEb;AAStB,eAAeA,oBACpBC,KAAa,EACbC,QAA+B;IAE/B,oDAAoD;IACpD,IAAIA,aAAaC,+BAAqB,CAACC,MAAM,EAAE;QAC7C,OAAOH;IACT;IAEA,qCAAqC;IACrC,MAAMI,UAAU,MAAMC,IAAAA,oBAAY,EAACL;IACnC,IAAIC,aAAaC,+BAAqB,CAACI,IAAI,EAAE;QAC3C,OAAOC,IAAAA,oBAAa,EAACH;IACvB;IAEA,OAAOI,IAAAA,iBAAU,EAACJ;AACpB"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
encodeBase64: function() {
|
|
13
|
+
return encodeBase64;
|
|
14
|
+
},
|
|
15
|
+
decodeBase64: function() {
|
|
16
|
+
return decodeBase64;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
const _utils = require("@metamask/utils");
|
|
20
|
+
const _bytes = require("./bytes");
|
|
21
|
+
async function encodeBase64(input) {
|
|
22
|
+
const bytes = (0, _bytes.getBytes)(input);
|
|
23
|
+
// In the browser, FileReader is much faster than bytesToBase64.
|
|
24
|
+
if ('FileReader' in globalThis) {
|
|
25
|
+
return await new Promise((resolve, reject)=>{
|
|
26
|
+
const reader = Object.assign(new FileReader(), {
|
|
27
|
+
onload: ()=>resolve(reader.result.replace('data:application/octet-stream;base64,', '')),
|
|
28
|
+
onerror: ()=>reject(reader.error)
|
|
29
|
+
});
|
|
30
|
+
reader.readAsDataURL(new File([
|
|
31
|
+
bytes
|
|
32
|
+
], '', {
|
|
33
|
+
type: 'application/octet-stream'
|
|
34
|
+
}));
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
return (0, _utils.bytesToBase64)(bytes);
|
|
38
|
+
}
|
|
39
|
+
async function decodeBase64(base64) {
|
|
40
|
+
const response = await fetch(`data:application/octet-stream;base64,${base64}`);
|
|
41
|
+
return new Uint8Array(await response.arrayBuffer());
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
//# sourceMappingURL=base64.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/base64.ts"],"sourcesContent":["import { bytesToBase64 } from '@metamask/utils';\n\nimport { getBytes } from './bytes';\nimport type { VirtualFile } from './virtual-file';\n\n/**\n * Provides fast, asynchronous base64 encoding.\n *\n * @param input - The input value, assumed to be coercable to bytes.\n * @returns A base64 string.\n */\nexport async function encodeBase64(input: Uint8Array | VirtualFile | string) {\n const bytes = getBytes(input);\n // In the browser, FileReader is much faster than bytesToBase64.\n if ('FileReader' in globalThis) {\n return await new Promise((resolve, reject) => {\n const reader = Object.assign(new FileReader(), {\n onload: () =>\n resolve(\n (reader.result as string).replace(\n 'data:application/octet-stream;base64,',\n '',\n ),\n ),\n onerror: () => reject(reader.error),\n });\n reader.readAsDataURL(\n new File([bytes], '', { type: 'application/octet-stream' }),\n );\n });\n }\n return bytesToBase64(bytes);\n}\n\n/**\n * Provides fast, asynchronous base64 decoding.\n *\n * @param base64 - A base64 string.\n * @returns A Uint8Array of bytes.\n */\nexport async function decodeBase64(base64: string) {\n const response = await fetch(\n `data:application/octet-stream;base64,${base64}`,\n );\n return new Uint8Array(await response.arrayBuffer());\n}\n"],"names":["encodeBase64","decodeBase64","input","bytes","getBytes","globalThis","Promise","resolve","reject","reader","Object","assign","FileReader","onload","result","replace","onerror","error","readAsDataURL","File","type","bytesToBase64","base64","response","fetch","Uint8Array","arrayBuffer"],"mappings":";;;;;;;;;;;IAWsBA,YAAY;eAAZA;;IA6BAC,YAAY;eAAZA;;;uBAxCQ;uBAEL;AASlB,eAAeD,aAAaE,KAAwC;IACzE,MAAMC,QAAQC,IAAAA,eAAQ,EAACF;IACvB,gEAAgE;IAChE,IAAI,gBAAgBG,YAAY;QAC9B,OAAO,MAAM,IAAIC,QAAQ,CAACC,SAASC;YACjC,MAAMC,SAASC,OAAOC,MAAM,CAAC,IAAIC,cAAc;gBAC7CC,QAAQ,IACNN,QACE,AAACE,OAAOK,MAAM,CAAYC,OAAO,CAC/B,yCACA;gBAGNC,SAAS,IAAMR,OAAOC,OAAOQ,KAAK;YACpC;YACAR,OAAOS,aAAa,CAClB,IAAIC,KAAK;gBAAChB;aAAM,EAAE,IAAI;gBAAEiB,MAAM;YAA2B;QAE7D;IACF;IACA,OAAOC,IAAAA,oBAAa,EAAClB;AACvB;AAQO,eAAeF,aAAaqB,MAAc;IAC/C,MAAMC,WAAW,MAAMC,MACrB,CAAC,qCAAqC,EAAEF,OAAO,CAAC;IAElD,OAAO,IAAIG,WAAW,MAAMF,SAASG,WAAW;AAClD"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "getBytes", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return getBytes;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _utils = require("@metamask/utils");
|
|
12
|
+
const _virtualfile = require("./virtual-file");
|
|
13
|
+
function getBytes(bytes) {
|
|
14
|
+
// Unwrap VirtualFiles to extract the content
|
|
15
|
+
// The content is then either a string or Uint8Array
|
|
16
|
+
const unwrapped = bytes instanceof _virtualfile.VirtualFile ? bytes.value : bytes;
|
|
17
|
+
if (typeof unwrapped === 'string') {
|
|
18
|
+
return (0, _utils.stringToBytes)(unwrapped);
|
|
19
|
+
}
|
|
20
|
+
return unwrapped;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
//# sourceMappingURL=bytes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/bytes.ts"],"sourcesContent":["import { stringToBytes } from '@metamask/utils';\n\nimport { VirtualFile } from './virtual-file';\n\n/**\n * Convert a bytes-like input value to a Uint8Array.\n *\n * @param bytes - A bytes-like value.\n * @returns The input value converted to a Uint8Array if necessary.\n */\nexport function getBytes(bytes: VirtualFile | Uint8Array | string): Uint8Array {\n // Unwrap VirtualFiles to extract the content\n // The content is then either a string or Uint8Array\n const unwrapped = bytes instanceof VirtualFile ? bytes.value : bytes;\n\n if (typeof unwrapped === 'string') {\n return stringToBytes(unwrapped);\n }\n\n return unwrapped;\n}\n"],"names":["getBytes","bytes","unwrapped","VirtualFile","value","stringToBytes"],"mappings":";;;;+BAUgBA;;;eAAAA;;;uBAVc;6BAEF;AAQrB,SAASA,SAASC,KAAwC;IAC/D,6CAA6C;IAC7C,oDAAoD;IACpD,MAAMC,YAAYD,iBAAiBE,wBAAW,GAAGF,MAAMG,KAAK,GAAGH;IAE/D,IAAI,OAAOC,cAAc,UAAU;QACjC,OAAOG,IAAAA,oBAAa,EAACH;IACvB;IAEA,OAAOA;AACT"}
|
package/dist/cjs/checksum.js
CHANGED
|
@@ -9,9 +9,6 @@ function _export(target, all) {
|
|
|
9
9
|
});
|
|
10
10
|
}
|
|
11
11
|
_export(exports, {
|
|
12
|
-
getChecksumBytes: function() {
|
|
13
|
-
return getChecksumBytes;
|
|
14
|
-
},
|
|
15
12
|
checksum: function() {
|
|
16
13
|
return checksum;
|
|
17
14
|
},
|
|
@@ -21,18 +18,9 @@ _export(exports, {
|
|
|
21
18
|
});
|
|
22
19
|
const _utils = require("@metamask/utils");
|
|
23
20
|
const _sha256 = require("@noble/hashes/sha256");
|
|
24
|
-
const
|
|
25
|
-
function getChecksumBytes(bytes) {
|
|
26
|
-
// Unwrap VirtualFiles to extract the content
|
|
27
|
-
// The content is then either a string or Uint8Array
|
|
28
|
-
const unwrapped = bytes instanceof _VirtualFile.VirtualFile ? bytes.value : bytes;
|
|
29
|
-
if (typeof unwrapped === 'string') {
|
|
30
|
-
return (0, _utils.stringToBytes)(unwrapped);
|
|
31
|
-
}
|
|
32
|
-
return unwrapped;
|
|
33
|
-
}
|
|
21
|
+
const _bytes = require("./bytes");
|
|
34
22
|
async function checksum(bytes) {
|
|
35
|
-
const value =
|
|
23
|
+
const value = (0, _bytes.getBytes)(bytes);
|
|
36
24
|
// Use crypto.subtle.digest whenever possible as it is faster.
|
|
37
25
|
if ('crypto' in globalThis && typeof globalThis.crypto === 'object' && crypto.subtle?.digest) {
|
|
38
26
|
return new Uint8Array(await crypto.subtle.digest('SHA-256', value));
|
package/dist/cjs/checksum.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/checksum.ts"],"sourcesContent":["import { assert, concatBytes
|
|
1
|
+
{"version":3,"sources":["../../src/checksum.ts"],"sourcesContent":["import { assert, concatBytes } from '@metamask/utils';\nimport { sha256 } from '@noble/hashes/sha256';\n\nimport { getBytes } from './bytes';\nimport type { 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 async function checksum(\n bytes: VirtualFile | Uint8Array | string,\n): Promise<Uint8Array> {\n const value = getBytes(bytes);\n // Use crypto.subtle.digest whenever possible as it is faster.\n if (\n 'crypto' in globalThis &&\n typeof globalThis.crypto === 'object' &&\n crypto.subtle?.digest\n ) {\n return new Uint8Array(await crypto.subtle.digest('SHA-256', value));\n }\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 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"],"names":["checksum","checksumFiles","bytes","value","getBytes","globalThis","crypto","subtle","digest","Uint8Array","sha256","files","checksums","Promise","all","sort","a","b","assert","path","map","file","concatBytes"],"mappings":";;;;;;;;;;;IAYsBA,QAAQ;eAARA;;IA2BAC,aAAa;eAAbA;;;uBAvCc;wBACb;uBAEE;AASlB,eAAeD,SACpBE,KAAwC;IAExC,MAAMC,QAAQC,IAAAA,eAAQ,EAACF;IACvB,8DAA8D;IAC9D,IACE,YAAYG,cACZ,OAAOA,WAAWC,MAAM,KAAK,YAC7BA,OAAOC,MAAM,EAAEC,QACf;QACA,OAAO,IAAIC,WAAW,MAAMH,OAAOC,MAAM,CAACC,MAAM,CAAC,WAAWL;IAC9D;IACA,OAAOO,IAAAA,cAAM,EAACP;AAChB;AAcO,eAAeF,cAAcU,KAAoB;IACtD,MAAMC,YAAY,MAAMC,QAAQC,GAAG,CACjC;WAAIH;KAAM,CACPI,IAAI,CAAC,CAACC,GAAGC;QACRC,IAAAA,aAAM,EAACF,EAAEG,IAAI,KAAKF,EAAEE,IAAI,EAAE;QAC1B,IAAIH,EAAEG,IAAI,GAAGF,EAAEE,IAAI,EAAE;YACnB,OAAO,CAAC;QACV;QACA,OAAO;IACT,GACCC,GAAG,CAAC,OAAOC,OAASrB,SAASqB;IAGlC,OAAOrB,SAASsB,IAAAA,kBAAW,EAACV;AAC9B"}
|
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
SNAPS_DERIVATION_PATHS: function() {
|
|
13
|
+
return SNAPS_DERIVATION_PATHS;
|
|
14
|
+
},
|
|
15
|
+
getSnapDerivationPathName: function() {
|
|
16
|
+
return getSnapDerivationPathName;
|
|
17
|
+
},
|
|
18
|
+
getSlip44ProtocolName: function() {
|
|
19
|
+
return getSlip44ProtocolName;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
const _slip44 = /*#__PURE__*/ _interop_require_default(require("@metamask/slip44"));
|
|
23
|
+
const _array = require("./array");
|
|
24
|
+
function _interop_require_default(obj) {
|
|
25
|
+
return obj && obj.__esModule ? obj : {
|
|
26
|
+
default: obj
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
const SNAPS_DERIVATION_PATHS = [
|
|
30
|
+
{
|
|
31
|
+
path: [
|
|
32
|
+
'm',
|
|
33
|
+
`44'`,
|
|
34
|
+
`0'`
|
|
35
|
+
],
|
|
36
|
+
curve: 'ed25519',
|
|
37
|
+
name: 'Test BIP-32 Path (ed25519)'
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
path: [
|
|
41
|
+
'm',
|
|
42
|
+
`44'`,
|
|
43
|
+
`1'`
|
|
44
|
+
],
|
|
45
|
+
curve: 'secp256k1',
|
|
46
|
+
name: 'Testnet'
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
path: [
|
|
50
|
+
'm',
|
|
51
|
+
`44'`,
|
|
52
|
+
`0'`
|
|
53
|
+
],
|
|
54
|
+
curve: 'secp256k1',
|
|
55
|
+
name: 'Bitcoin Legacy'
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
path: [
|
|
59
|
+
'm',
|
|
60
|
+
`49'`,
|
|
61
|
+
`0'`
|
|
62
|
+
],
|
|
63
|
+
curve: 'secp256k1',
|
|
64
|
+
name: 'Bitcoin Nested SegWit'
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
path: [
|
|
68
|
+
'm',
|
|
69
|
+
`49'`,
|
|
70
|
+
`1'`
|
|
71
|
+
],
|
|
72
|
+
curve: 'secp256k1',
|
|
73
|
+
name: 'Bitcoin Testnet Nested SegWit'
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
path: [
|
|
77
|
+
'm',
|
|
78
|
+
`84'`,
|
|
79
|
+
`0'`
|
|
80
|
+
],
|
|
81
|
+
curve: 'secp256k1',
|
|
82
|
+
name: 'Bitcoin Native SegWit'
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
path: [
|
|
86
|
+
'm',
|
|
87
|
+
`84'`,
|
|
88
|
+
`1'`
|
|
89
|
+
],
|
|
90
|
+
curve: 'secp256k1',
|
|
91
|
+
name: 'Bitcoin Testnet Native SegWit'
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
path: [
|
|
95
|
+
'm',
|
|
96
|
+
`44'`,
|
|
97
|
+
`501'`
|
|
98
|
+
],
|
|
99
|
+
curve: 'ed25519',
|
|
100
|
+
name: 'Solana'
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
path: [
|
|
104
|
+
'm',
|
|
105
|
+
`44'`,
|
|
106
|
+
`501'`,
|
|
107
|
+
"0'",
|
|
108
|
+
"0'"
|
|
109
|
+
],
|
|
110
|
+
curve: 'ed25519',
|
|
111
|
+
name: 'Solana'
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
path: [
|
|
115
|
+
'm',
|
|
116
|
+
`44'`,
|
|
117
|
+
`2'`
|
|
118
|
+
],
|
|
119
|
+
curve: 'secp256k1',
|
|
120
|
+
name: 'Litecoin'
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
path: [
|
|
124
|
+
'm',
|
|
125
|
+
`44'`,
|
|
126
|
+
`3'`
|
|
127
|
+
],
|
|
128
|
+
curve: 'secp256k1',
|
|
129
|
+
name: 'Dogecoin'
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
path: [
|
|
133
|
+
'm',
|
|
134
|
+
`44'`,
|
|
135
|
+
`60'`
|
|
136
|
+
],
|
|
137
|
+
curve: 'secp256k1',
|
|
138
|
+
name: 'Ethereum'
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
path: [
|
|
142
|
+
'm',
|
|
143
|
+
`44'`,
|
|
144
|
+
`118'`
|
|
145
|
+
],
|
|
146
|
+
curve: 'secp256k1',
|
|
147
|
+
name: 'Atom'
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
path: [
|
|
151
|
+
'm',
|
|
152
|
+
`44'`,
|
|
153
|
+
`145'`
|
|
154
|
+
],
|
|
155
|
+
curve: 'secp256k1',
|
|
156
|
+
name: 'Bitcoin Cash'
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
path: [
|
|
160
|
+
'm',
|
|
161
|
+
`44'`,
|
|
162
|
+
`637'`
|
|
163
|
+
],
|
|
164
|
+
curve: 'ed25519',
|
|
165
|
+
name: 'Aptos'
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
path: [
|
|
169
|
+
'm',
|
|
170
|
+
`44'`,
|
|
171
|
+
`714'`
|
|
172
|
+
],
|
|
173
|
+
curve: 'secp256k1',
|
|
174
|
+
name: 'Binance (BNB)'
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
path: [
|
|
178
|
+
'm',
|
|
179
|
+
`44'`,
|
|
180
|
+
`784'`
|
|
181
|
+
],
|
|
182
|
+
curve: 'ed25519',
|
|
183
|
+
name: 'Sui'
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
path: [
|
|
187
|
+
'm',
|
|
188
|
+
`44'`,
|
|
189
|
+
`931'`
|
|
190
|
+
],
|
|
191
|
+
curve: 'secp256k1',
|
|
192
|
+
name: 'THORChain (RUNE)'
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
path: [
|
|
196
|
+
'm',
|
|
197
|
+
`44'`,
|
|
198
|
+
`330'`
|
|
199
|
+
],
|
|
200
|
+
curve: 'secp256k1',
|
|
201
|
+
name: 'Terra (LUNA)'
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
path: [
|
|
205
|
+
'm',
|
|
206
|
+
`44'`,
|
|
207
|
+
`459'`
|
|
208
|
+
],
|
|
209
|
+
curve: 'secp256k1',
|
|
210
|
+
name: 'Kava'
|
|
211
|
+
},
|
|
212
|
+
{
|
|
213
|
+
path: [
|
|
214
|
+
'm',
|
|
215
|
+
`44'`,
|
|
216
|
+
`529'`
|
|
217
|
+
],
|
|
218
|
+
curve: 'secp256k1',
|
|
219
|
+
name: 'Secret Network'
|
|
220
|
+
},
|
|
221
|
+
{
|
|
222
|
+
path: [
|
|
223
|
+
'm',
|
|
224
|
+
`44'`,
|
|
225
|
+
`397'`,
|
|
226
|
+
`0'`
|
|
227
|
+
],
|
|
228
|
+
curve: 'ed25519',
|
|
229
|
+
name: 'NEAR Protocol'
|
|
230
|
+
},
|
|
231
|
+
{
|
|
232
|
+
path: [
|
|
233
|
+
'm',
|
|
234
|
+
`44'`,
|
|
235
|
+
`1'`,
|
|
236
|
+
`0'`
|
|
237
|
+
],
|
|
238
|
+
curve: 'ed25519',
|
|
239
|
+
name: 'Testnet'
|
|
240
|
+
},
|
|
241
|
+
{
|
|
242
|
+
path: [
|
|
243
|
+
'm',
|
|
244
|
+
`44'`,
|
|
245
|
+
`472'`
|
|
246
|
+
],
|
|
247
|
+
curve: 'ed25519',
|
|
248
|
+
name: 'Arweave'
|
|
249
|
+
},
|
|
250
|
+
{
|
|
251
|
+
path: [
|
|
252
|
+
'm',
|
|
253
|
+
`44'`,
|
|
254
|
+
`12586'`
|
|
255
|
+
],
|
|
256
|
+
curve: 'secp256k1',
|
|
257
|
+
name: 'Mina'
|
|
258
|
+
},
|
|
259
|
+
{
|
|
260
|
+
path: [
|
|
261
|
+
'm',
|
|
262
|
+
`44'`,
|
|
263
|
+
`1729'`,
|
|
264
|
+
`0'`,
|
|
265
|
+
`0'`
|
|
266
|
+
],
|
|
267
|
+
curve: 'ed25519',
|
|
268
|
+
name: 'Tezos'
|
|
269
|
+
},
|
|
270
|
+
{
|
|
271
|
+
path: [
|
|
272
|
+
'm',
|
|
273
|
+
`1789'`,
|
|
274
|
+
`0'`
|
|
275
|
+
],
|
|
276
|
+
curve: 'ed25519',
|
|
277
|
+
name: 'Vega'
|
|
278
|
+
}
|
|
279
|
+
];
|
|
280
|
+
function getSnapDerivationPathName(path, curve) {
|
|
281
|
+
const pathMetadata = SNAPS_DERIVATION_PATHS.find((derivationPath)=>derivationPath.curve === curve && (0, _array.isEqual)(derivationPath.path, path));
|
|
282
|
+
if (pathMetadata) {
|
|
283
|
+
return pathMetadata.name;
|
|
284
|
+
}
|
|
285
|
+
// If the curve is secp256k1 and the path is a valid BIP44 path
|
|
286
|
+
// we try looking for the network/protocol name in SLIP44
|
|
287
|
+
if (curve === 'secp256k1' && path[0] === 'm' && path[1] === `44'` && path[2].endsWith(`'`)) {
|
|
288
|
+
const coinType = path[2].slice(0, -1);
|
|
289
|
+
return getSlip44ProtocolName(coinType) ?? null;
|
|
290
|
+
}
|
|
291
|
+
return null;
|
|
292
|
+
}
|
|
293
|
+
function getSlip44ProtocolName(coinType) {
|
|
294
|
+
if (String(coinType) === '1') {
|
|
295
|
+
return 'Test Networks';
|
|
296
|
+
}
|
|
297
|
+
return _slip44.default[coinType]?.name ?? null;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
//# sourceMappingURL=derivation-paths.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/derivation-paths.ts"],"sourcesContent":["import type { SupportedCurve } from '@metamask/key-tree';\nimport slip44 from '@metamask/slip44';\n\nimport { isEqual } from './array';\n\nexport type SnapsDerivationPath = {\n path: ['m', ...string[]];\n curve: SupportedCurve;\n name: string;\n};\n\nexport const SNAPS_DERIVATION_PATHS: SnapsDerivationPath[] = [\n {\n path: ['m', `44'`, `0'`],\n curve: 'ed25519',\n name: 'Test BIP-32 Path (ed25519)',\n },\n {\n path: ['m', `44'`, `1'`],\n curve: 'secp256k1',\n name: 'Testnet',\n },\n {\n path: ['m', `44'`, `0'`],\n curve: 'secp256k1',\n name: 'Bitcoin Legacy',\n },\n {\n path: ['m', `49'`, `0'`],\n curve: 'secp256k1',\n name: 'Bitcoin Nested SegWit',\n },\n {\n path: ['m', `49'`, `1'`],\n curve: 'secp256k1',\n name: 'Bitcoin Testnet Nested SegWit',\n },\n {\n path: ['m', `84'`, `0'`],\n curve: 'secp256k1',\n name: 'Bitcoin Native SegWit',\n },\n {\n path: ['m', `84'`, `1'`],\n curve: 'secp256k1',\n name: 'Bitcoin Testnet Native SegWit',\n },\n {\n path: ['m', `44'`, `501'`],\n curve: 'ed25519',\n name: 'Solana',\n },\n {\n path: ['m', `44'`, `501'`, \"0'\", \"0'\"],\n curve: 'ed25519',\n name: 'Solana',\n },\n {\n path: ['m', `44'`, `2'`],\n curve: 'secp256k1',\n name: 'Litecoin',\n },\n {\n path: ['m', `44'`, `3'`],\n curve: 'secp256k1',\n name: 'Dogecoin',\n },\n {\n path: ['m', `44'`, `60'`],\n curve: 'secp256k1',\n name: 'Ethereum',\n },\n {\n path: ['m', `44'`, `118'`],\n curve: 'secp256k1',\n name: 'Atom',\n },\n {\n path: ['m', `44'`, `145'`],\n curve: 'secp256k1',\n name: 'Bitcoin Cash',\n },\n {\n path: ['m', `44'`, `637'`],\n curve: 'ed25519',\n name: 'Aptos',\n },\n {\n path: ['m', `44'`, `714'`],\n curve: 'secp256k1',\n name: 'Binance (BNB)',\n },\n {\n path: ['m', `44'`, `784'`],\n curve: 'ed25519',\n name: 'Sui',\n },\n {\n path: ['m', `44'`, `931'`],\n curve: 'secp256k1',\n name: 'THORChain (RUNE)',\n },\n {\n path: ['m', `44'`, `330'`],\n curve: 'secp256k1',\n name: 'Terra (LUNA)',\n },\n {\n path: ['m', `44'`, `459'`],\n curve: 'secp256k1',\n name: 'Kava',\n },\n {\n path: ['m', `44'`, `529'`],\n curve: 'secp256k1',\n name: 'Secret Network',\n },\n {\n path: ['m', `44'`, `397'`, `0'`],\n curve: 'ed25519',\n name: 'NEAR Protocol',\n },\n {\n path: ['m', `44'`, `1'`, `0'`],\n curve: 'ed25519',\n name: 'Testnet',\n },\n {\n path: ['m', `44'`, `472'`],\n curve: 'ed25519',\n name: 'Arweave',\n },\n {\n path: ['m', `44'`, `12586'`],\n curve: 'secp256k1',\n name: 'Mina',\n },\n {\n path: ['m', `44'`, `1729'`, `0'`, `0'`],\n curve: 'ed25519',\n name: 'Tezos',\n },\n {\n path: ['m', `1789'`, `0'`],\n curve: 'ed25519',\n name: 'Vega',\n },\n];\n\n/**\n * Gets the name of a derivation path supported by snaps.\n *\n * @param path - The derivation path.\n * @param curve - The curve used to derive the keys.\n * @returns The name of the derivation path, otherwise null.\n */\nexport function getSnapDerivationPathName(\n path: SnapsDerivationPath['path'],\n curve: SupportedCurve,\n): string | null {\n const pathMetadata = SNAPS_DERIVATION_PATHS.find(\n (derivationPath) =>\n derivationPath.curve === curve && isEqual(derivationPath.path, path),\n );\n\n if (pathMetadata) {\n return pathMetadata.name;\n }\n\n // If the curve is secp256k1 and the path is a valid BIP44 path\n // we try looking for the network/protocol name in SLIP44\n if (\n curve === 'secp256k1' &&\n path[0] === 'm' &&\n path[1] === `44'` &&\n path[2].endsWith(`'`)\n ) {\n const coinType = path[2].slice(0, -1);\n return getSlip44ProtocolName(coinType) ?? null;\n }\n\n return null;\n}\n\n/**\n * Gets the name of the SLIP-44 protocol corresponding to the specified\n * `coin_type`.\n *\n * @param coinType - The SLIP-44 `coin_type` value whose name\n * to retrieve.\n * @returns The name of the protocol, otherwise null.\n */\nexport function getSlip44ProtocolName(coinType: number | string) {\n if (String(coinType) === '1') {\n return 'Test Networks';\n }\n\n return slip44[coinType as keyof typeof slip44]?.name ?? null;\n}\n"],"names":["SNAPS_DERIVATION_PATHS","getSnapDerivationPathName","getSlip44ProtocolName","path","curve","name","pathMetadata","find","derivationPath","isEqual","endsWith","coinType","slice","String","slip44"],"mappings":";;;;;;;;;;;IAWaA,sBAAsB;eAAtBA;;IAiJGC,yBAAyB;eAAzBA;;IAoCAC,qBAAqB;eAArBA;;;+DA/LG;uBAEK;;;;;;AAQjB,MAAMF,yBAAgD;IAC3D;QACEG,MAAM;YAAC;YAAK,CAAC,GAAG,CAAC;YAAE,CAAC,EAAE,CAAC;SAAC;QACxBC,OAAO;QACPC,MAAM;IACR;IACA;QACEF,MAAM;YAAC;YAAK,CAAC,GAAG,CAAC;YAAE,CAAC,EAAE,CAAC;SAAC;QACxBC,OAAO;QACPC,MAAM;IACR;IACA;QACEF,MAAM;YAAC;YAAK,CAAC,GAAG,CAAC;YAAE,CAAC,EAAE,CAAC;SAAC;QACxBC,OAAO;QACPC,MAAM;IACR;IACA;QACEF,MAAM;YAAC;YAAK,CAAC,GAAG,CAAC;YAAE,CAAC,EAAE,CAAC;SAAC;QACxBC,OAAO;QACPC,MAAM;IACR;IACA;QACEF,MAAM;YAAC;YAAK,CAAC,GAAG,CAAC;YAAE,CAAC,EAAE,CAAC;SAAC;QACxBC,OAAO;QACPC,MAAM;IACR;IACA;QACEF,MAAM;YAAC;YAAK,CAAC,GAAG,CAAC;YAAE,CAAC,EAAE,CAAC;SAAC;QACxBC,OAAO;QACPC,MAAM;IACR;IACA;QACEF,MAAM;YAAC;YAAK,CAAC,GAAG,CAAC;YAAE,CAA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,eAAeL,IAAI,EAAEA;IAGnE,IAAIG,cAAc;QAChB,OAAOA,aAAaD,IAAI;IAC1B;IAEA,+DAA+D;IAC/D,yDAAyD;IACzD,IACED,UAAU,eACVD,IAAI,CAAC,EAAE,KAAK,OACZA,IAAI,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,IACjBA,IAAI,CAAC,EAAE,CAACO,QAAQ,CAAC,CAAC,CAAC,CAAC,GACpB;QACA,MAAMC,WAAWR,IAAI,CAAC,EAAE,CAACS,KAAK,CAAC,GAAG,CAAC;QACnC,OAAOV,sBAAsBS,aAAa;IAC5C;IAEA,OAAO;AACT;AAUO,SAAST,sBAAsBS,QAAyB;IAC7D,IAAIE,OAAOF,cAAc,KAAK;QAC5B,OAAO;IACT;IAEA,OAAOG,eAAM,CAACH,SAAgC,EAAEN,QAAQ;AAC1D"}
|
|
@@ -4,11 +4,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
});
|
|
5
5
|
_export_star(require("./array"), exports);
|
|
6
6
|
_export_star(require("./auxiliary-files"), exports);
|
|
7
|
+
_export_star(require("./base64"), exports);
|
|
8
|
+
_export_star(require("./bytes"), exports);
|
|
7
9
|
_export_star(require("./caveats"), exports);
|
|
8
10
|
_export_star(require("./checksum"), exports);
|
|
9
11
|
_export_star(require("./cronjob"), exports);
|
|
10
12
|
_export_star(require("./deep-clone"), exports);
|
|
11
13
|
_export_star(require("./default-endowments"), exports);
|
|
14
|
+
_export_star(require("./derivation-paths"), exports);
|
|
12
15
|
_export_star(require("./entropy"), exports);
|
|
13
16
|
_export_star(require("./errors"), exports);
|
|
14
17
|
_export_star(require("./handlers"), exports);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.browser.ts"],"sourcesContent":["export * from './array';\nexport * from './auxiliary-files';\nexport * from './caveats';\nexport * from './checksum';\nexport * from './cronjob';\nexport * from './deep-clone';\nexport * from './default-endowments';\nexport * from './entropy';\nexport * from './errors';\nexport * from './handlers';\nexport * from './handler-types';\nexport * from './iframe';\nexport * from './json';\nexport * from './json-rpc';\nexport * from './localization';\nexport * from './logging';\nexport * from './manifest/index.browser';\nexport * from './namespace';\nexport * from './path';\nexport * from './snaps';\nexport * from './strings';\nexport * from './structs';\nexport * from './types';\nexport * from './ui';\nexport * from './validation';\nexport * from './versions';\nexport * from './virtual-file/index.browser';\n"],"names":[],"mappings":";;;;qBAAc;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA"}
|
|
1
|
+
{"version":3,"sources":["../../src/index.browser.ts"],"sourcesContent":["export * from './array';\nexport * from './auxiliary-files';\nexport * from './base64';\nexport * from './bytes';\nexport * from './caveats';\nexport * from './checksum';\nexport * from './cronjob';\nexport * from './deep-clone';\nexport * from './default-endowments';\nexport * from './derivation-paths';\nexport * from './entropy';\nexport * from './errors';\nexport * from './handlers';\nexport * from './handler-types';\nexport * from './iframe';\nexport * from './json';\nexport * from './json-rpc';\nexport * from './localization';\nexport * from './logging';\nexport * from './manifest/index.browser';\nexport * from './namespace';\nexport * from './path';\nexport * from './snaps';\nexport * from './strings';\nexport * from './structs';\nexport * from './types';\nexport * from './ui';\nexport * from './validation';\nexport * from './versions';\nexport * from './virtual-file/index.browser';\n"],"names":[],"mappings":";;;;qBAAc;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA"}
|
package/dist/cjs/index.js
CHANGED
|
@@ -4,11 +4,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
});
|
|
5
5
|
_export_star(require("./array"), exports);
|
|
6
6
|
_export_star(require("./auxiliary-files"), exports);
|
|
7
|
+
_export_star(require("./base64"), exports);
|
|
8
|
+
_export_star(require("./bytes"), exports);
|
|
7
9
|
_export_star(require("./caveats"), exports);
|
|
8
10
|
_export_star(require("./cronjob"), exports);
|
|
9
11
|
_export_star(require("./checksum"), exports);
|
|
10
12
|
_export_star(require("./deep-clone"), exports);
|
|
11
13
|
_export_star(require("./default-endowments"), exports);
|
|
14
|
+
_export_star(require("./derivation-paths"), exports);
|
|
12
15
|
_export_star(require("./entropy"), exports);
|
|
13
16
|
_export_star(require("./eval"), exports);
|
|
14
17
|
_export_star(require("./errors"), exports);
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export * from './array';\nexport * from './auxiliary-files';\nexport * from './caveats';\nexport * from './cronjob';\nexport * from './checksum';\nexport * from './deep-clone';\nexport * from './default-endowments';\nexport * from './entropy';\nexport * from './eval';\nexport * from './errors';\nexport * from './fs';\nexport * from './handlers';\nexport * from './handler-types';\nexport * from './iframe';\nexport * from './json';\nexport * from './json-rpc';\nexport * from './localization';\nexport * from './logging';\nexport * from './manifest';\nexport * from './mock';\nexport * from './namespace';\nexport * from './npm';\nexport * from './path';\nexport * from './post-process';\nexport * from './snaps';\nexport * from './strings';\nexport * from './structs';\nexport * from './types';\nexport * from './ui';\nexport * from './validation';\nexport * from './versions';\nexport * from './virtual-file';\n"],"names":[],"mappings":";;;;qBAAc;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA"}
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export * from './array';\nexport * from './auxiliary-files';\nexport * from './base64';\nexport * from './bytes';\nexport * from './caveats';\nexport * from './cronjob';\nexport * from './checksum';\nexport * from './deep-clone';\nexport * from './default-endowments';\nexport * from './derivation-paths';\nexport * from './entropy';\nexport * from './eval';\nexport * from './errors';\nexport * from './fs';\nexport * from './handlers';\nexport * from './handler-types';\nexport * from './iframe';\nexport * from './json';\nexport * from './json-rpc';\nexport * from './localization';\nexport * from './logging';\nexport * from './manifest';\nexport * from './mock';\nexport * from './namespace';\nexport * from './npm';\nexport * from './path';\nexport * from './post-process';\nexport * from './snaps';\nexport * from './strings';\nexport * from './structs';\nexport * from './types';\nexport * from './ui';\nexport * from './validation';\nexport * from './versions';\nexport * from './virtual-file';\n"],"names":[],"mappings":";;;;qBAAc;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA"}
|
|
@@ -40,6 +40,7 @@ class VirtualFile {
|
|
|
40
40
|
} else if (this.value instanceof Uint8Array && encoding === 'hex') {
|
|
41
41
|
return (0, _utils.bytesToHex)(this.value);
|
|
42
42
|
} else if (this.value instanceof Uint8Array && encoding === 'base64') {
|
|
43
|
+
// For large files, this is quite slow, instead use `encodeBase64()`
|
|
43
44
|
// TODO: Use @metamask/utils for this
|
|
44
45
|
return _base.base64.encode(this.value);
|
|
45
46
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/virtual-file/VirtualFile.ts"],"sourcesContent":["// TODO(ritave): Move into separate package @metamask/vfile / @metamask/utils + @metamask/to-vfile when passes code review\n// TODO(ritave): Streaming vfile contents similar to vinyl maybe?\n// TODO(ritave): Move fixing manifest in cli and bundler plugins to write messages to vfile\n// similar to unified instead of throwing \"ProgrammaticallyFixableErrors\".\n//\n// Using https://github.com/vfile/vfile would be helpful, but they only support ESM and we need to support CommonJS.\n// https://github.com/gulpjs/vinyl is also good, but they normalize paths, which we can't do, because\n// we're calculating checksums based on original path.\nimport { assert, bytesToHex } from '@metamask/utils';\nimport { base64 } from '@scure/base';\n\nimport { deepClone } from '../deep-clone';\n\n/**\n * This map registers the type of the {@link VirtualFile.data} key of a {@link VirtualFile}.\n *\n * This type can be augmented to register custom `data` types.\n *\n * @example\n * declare module '@metamask/snaps-utils' {\n * interface DataMap {\n * // `file.data.name` is typed as `string`\n * name: string\n * }\n * }\n */\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions, @typescript-eslint/no-empty-interface\nexport interface DataMap {}\n\nexport type Value = string | Uint8Array;\nexport type Compatible<Result = unknown> =\n | string\n | Uint8Array\n | Options<Result>;\nexport type Data = Record<string, unknown> & Partial<DataMap>;\nexport type Options<Result = unknown> = {\n value: Value;\n path?: string;\n data?: Data;\n result?: Result;\n};\n\nexport class VirtualFile<Result = unknown> {\n constructor(value?: Compatible<Result>) {\n let options: Options | undefined;\n if (typeof value === 'string' || value instanceof Uint8Array) {\n options = { value };\n } else {\n options = value;\n }\n\n this.value = options?.value ?? '';\n // This situations happens when there's no .result used,\n // we expect the file to have default generic in that situation:\n // VirtualFile<unknown> which will handle undefined properly\n //\n // While not 100% type safe, it'll be way less frustrating to work with.\n // The alternative would be to have VirtualFile.result be Result | undefined\n // and that would result in needing to branch out and check in all situations.\n //\n // In short, optimizing for most common use case.\n this.result = options?.result ?? (undefined as any);\n this.data = options?.data ?? {};\n this.path = options?.path ?? '/';\n }\n\n value: Value;\n\n result: Result;\n\n data: Data;\n\n path: string;\n\n toString(encoding?: string) {\n if (typeof this.value === 'string') {\n assert(encoding === undefined, 'Tried to encode string.');\n return this.value;\n } else if (this.value instanceof Uint8Array && encoding === 'hex') {\n return bytesToHex(this.value);\n } else if (this.value instanceof Uint8Array && encoding === 'base64') {\n // TODO: Use @metamask/utils for this\n return base64.encode(this.value);\n }\n const decoder = new TextDecoder(encoding);\n return decoder.decode(this.value);\n }\n\n clone() {\n const vfile = new VirtualFile<Result>();\n if (typeof this.value === 'string') {\n vfile.value = this.value;\n } else {\n // deep-clone doesn't clone Buffer properly, even if it's a sub-class of Uint8Array\n vfile.value = this.value.slice(0);\n }\n vfile.result = deepClone(this.result);\n vfile.data = deepClone(this.data);\n vfile.path = this.path;\n return vfile;\n }\n}\n"],"names":["VirtualFile","toString","encoding","value","assert","undefined","Uint8Array","bytesToHex","base64","encode","decoder","TextDecoder","decode","clone","vfile","slice","result","deepClone","data","path","constructor","options"],"mappings":"AAAA,0HAA0H;AAC1H,iEAAiE;AACjE,2FAA2F;AAC3F,wFAAwF;AACxF,EAAE;AACF,oHAAoH;AACpH,qGAAqG;AACrG,sDAAsD;;;;;+BAmCzCA;;;eAAAA;;;uBAlCsB;sBACZ;2BAEG;;;;;;;;;;;;;;AA+BnB,MAAMA;IAgCXC,SAASC,QAAiB,EAAE;QAC1B,IAAI,OAAO,IAAI,CAACC,KAAK,KAAK,UAAU;YAClCC,IAAAA,aAAM,EAACF,aAAaG,WAAW;YAC/B,OAAO,IAAI,CAACF,KAAK;QACnB,OAAO,IAAI,IAAI,CAACA,KAAK,YAAYG,cAAcJ,aAAa,OAAO;YACjE,OAAOK,IAAAA,iBAAU,EAAC,IAAI,CAACJ,KAAK;QAC9B,OAAO,IAAI,IAAI,CAACA,KAAK,YAAYG,cAAcJ,aAAa,UAAU;YACpE,qCAAqC;YACrC,OAAOM,YAAM,CAACC,MAAM,CAAC,IAAI,CAACN,KAAK;QACjC;QACA,MAAMO,UAAU,IAAIC,YAAYT;QAChC,OAAOQ,QAAQE,MAAM,CAAC,IAAI,CAACT,KAAK;IAClC;IAEAU,QAAQ;QACN,MAAMC,QAAQ,IAAId;QAClB,IAAI,OAAO,IAAI,CAACG,KAAK,KAAK,UAAU;YAClCW,MAAMX,KAAK,GAAG,IAAI,CAACA,KAAK;QAC1B,OAAO;YACL,mFAAmF;YACnFW,MAAMX,KAAK,GAAG,IAAI,CAACA,KAAK,CAACY,KAAK,CAAC;QACjC;QACAD,MAAME,MAAM,GAAGC,IAAAA,oBAAS,EAAC,IAAI,CAACD,MAAM;QACpCF,MAAMI,IAAI,GAAGD,IAAAA,oBAAS,EAAC,IAAI,CAACC,IAAI;QAChCJ,MAAMK,IAAI,GAAG,IAAI,CAACA,IAAI;QACtB,OAAOL;IACT;
|
|
1
|
+
{"version":3,"sources":["../../../src/virtual-file/VirtualFile.ts"],"sourcesContent":["// TODO(ritave): Move into separate package @metamask/vfile / @metamask/utils + @metamask/to-vfile when passes code review\n// TODO(ritave): Streaming vfile contents similar to vinyl maybe?\n// TODO(ritave): Move fixing manifest in cli and bundler plugins to write messages to vfile\n// similar to unified instead of throwing \"ProgrammaticallyFixableErrors\".\n//\n// Using https://github.com/vfile/vfile would be helpful, but they only support ESM and we need to support CommonJS.\n// https://github.com/gulpjs/vinyl is also good, but they normalize paths, which we can't do, because\n// we're calculating checksums based on original path.\nimport { assert, bytesToHex } from '@metamask/utils';\nimport { base64 } from '@scure/base';\n\nimport { deepClone } from '../deep-clone';\n\n/**\n * This map registers the type of the {@link VirtualFile.data} key of a {@link VirtualFile}.\n *\n * This type can be augmented to register custom `data` types.\n *\n * @example\n * declare module '@metamask/snaps-utils' {\n * interface DataMap {\n * // `file.data.name` is typed as `string`\n * name: string\n * }\n * }\n */\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions, @typescript-eslint/no-empty-interface\nexport interface DataMap {}\n\nexport type Value = string | Uint8Array;\nexport type Compatible<Result = unknown> =\n | string\n | Uint8Array\n | Options<Result>;\nexport type Data = Record<string, unknown> & Partial<DataMap>;\nexport type Options<Result = unknown> = {\n value: Value;\n path?: string;\n data?: Data;\n result?: Result;\n};\n\nexport class VirtualFile<Result = unknown> {\n constructor(value?: Compatible<Result>) {\n let options: Options | undefined;\n if (typeof value === 'string' || value instanceof Uint8Array) {\n options = { value };\n } else {\n options = value;\n }\n\n this.value = options?.value ?? '';\n // This situations happens when there's no .result used,\n // we expect the file to have default generic in that situation:\n // VirtualFile<unknown> which will handle undefined properly\n //\n // While not 100% type safe, it'll be way less frustrating to work with.\n // The alternative would be to have VirtualFile.result be Result | undefined\n // and that would result in needing to branch out and check in all situations.\n //\n // In short, optimizing for most common use case.\n this.result = options?.result ?? (undefined as any);\n this.data = options?.data ?? {};\n this.path = options?.path ?? '/';\n }\n\n value: Value;\n\n result: Result;\n\n data: Data;\n\n path: string;\n\n toString(encoding?: string) {\n if (typeof this.value === 'string') {\n assert(encoding === undefined, 'Tried to encode string.');\n return this.value;\n } else if (this.value instanceof Uint8Array && encoding === 'hex') {\n return bytesToHex(this.value);\n } else if (this.value instanceof Uint8Array && encoding === 'base64') {\n // For large files, this is quite slow, instead use `encodeBase64()`\n // TODO: Use @metamask/utils for this\n return base64.encode(this.value);\n }\n const decoder = new TextDecoder(encoding);\n return decoder.decode(this.value);\n }\n\n clone() {\n const vfile = new VirtualFile<Result>();\n if (typeof this.value === 'string') {\n vfile.value = this.value;\n } else {\n // deep-clone doesn't clone Buffer properly, even if it's a sub-class of Uint8Array\n vfile.value = this.value.slice(0);\n }\n vfile.result = deepClone(this.result);\n vfile.data = deepClone(this.data);\n vfile.path = this.path;\n return vfile;\n }\n}\n"],"names":["VirtualFile","toString","encoding","value","assert","undefined","Uint8Array","bytesToHex","base64","encode","decoder","TextDecoder","decode","clone","vfile","slice","result","deepClone","data","path","constructor","options"],"mappings":"AAAA,0HAA0H;AAC1H,iEAAiE;AACjE,2FAA2F;AAC3F,wFAAwF;AACxF,EAAE;AACF,oHAAoH;AACpH,qGAAqG;AACrG,sDAAsD;;;;;+BAmCzCA;;;eAAAA;;;uBAlCsB;sBACZ;2BAEG;;;;;;;;;;;;;;AA+BnB,MAAMA;IAgCXC,SAASC,QAAiB,EAAE;QAC1B,IAAI,OAAO,IAAI,CAACC,KAAK,KAAK,UAAU;YAClCC,IAAAA,aAAM,EAACF,aAAaG,WAAW;YAC/B,OAAO,IAAI,CAACF,KAAK;QACnB,OAAO,IAAI,IAAI,CAACA,KAAK,YAAYG,cAAcJ,aAAa,OA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AACa,IAAI,GAAGG,SAASH,QAAQ,CAAC;QAC9B,IAAI,CAACC,IAAI,GAAGE,SAASF,QAAQ;IAC/B;AAsCF"}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { AuxiliaryFileEncoding } from '@metamask/snaps-sdk';
|
|
2
2
|
import { bytesToHex, bytesToString } from '@metamask/utils';
|
|
3
|
-
import {
|
|
3
|
+
import { decodeBase64 } from './base64';
|
|
4
4
|
/**
|
|
5
5
|
* Re-encodes an auxiliary file if needed depending on the requested file encoding.
|
|
6
6
|
*
|
|
7
7
|
* @param value - The base64 value stored for the auxiliary file.
|
|
8
8
|
* @param encoding - The chosen encoding.
|
|
9
9
|
* @returns The file encoded in the requested encoding.
|
|
10
|
-
*/ export function encodeAuxiliaryFile(value, encoding) {
|
|
10
|
+
*/ export async function encodeAuxiliaryFile(value, encoding) {
|
|
11
11
|
// Input is assumed to be the stored file in base64.
|
|
12
12
|
if (encoding === AuxiliaryFileEncoding.Base64) {
|
|
13
13
|
return value;
|
|
14
14
|
}
|
|
15
15
|
// TODO: Use @metamask/utils for this
|
|
16
|
-
const decoded =
|
|
16
|
+
const decoded = await decodeBase64(value);
|
|
17
17
|
if (encoding === AuxiliaryFileEncoding.Utf8) {
|
|
18
18
|
return bytesToString(decoded);
|
|
19
19
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/auxiliary-files.ts"],"sourcesContent":["import { AuxiliaryFileEncoding } from '@metamask/snaps-sdk';\nimport { bytesToHex, bytesToString } from '@metamask/utils';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../src/auxiliary-files.ts"],"sourcesContent":["import { AuxiliaryFileEncoding } from '@metamask/snaps-sdk';\nimport { bytesToHex, bytesToString } from '@metamask/utils';\n\nimport { decodeBase64 } from './base64';\n\n/**\n * Re-encodes an auxiliary file if needed depending on the requested file encoding.\n *\n * @param value - The base64 value stored for the auxiliary file.\n * @param encoding - The chosen encoding.\n * @returns The file encoded in the requested encoding.\n */\nexport async function encodeAuxiliaryFile(\n value: string,\n encoding: AuxiliaryFileEncoding,\n) {\n // Input is assumed to be the stored file in base64.\n if (encoding === AuxiliaryFileEncoding.Base64) {\n return value;\n }\n\n // TODO: Use @metamask/utils for this\n const decoded = await decodeBase64(value);\n if (encoding === AuxiliaryFileEncoding.Utf8) {\n return bytesToString(decoded);\n }\n\n return bytesToHex(decoded);\n}\n"],"names":["AuxiliaryFileEncoding","bytesToHex","bytesToString","decodeBase64","encodeAuxiliaryFile","value","encoding","Base64","decoded","Utf8"],"mappings":"AAAA,SAASA,qBAAqB,QAAQ,sBAAsB;AAC5D,SAASC,UAAU,EAAEC,aAAa,QAAQ,kBAAkB;AAE5D,SAASC,YAAY,QAAQ,WAAW;AAExC;;;;;;CAMC,GACD,OAAO,eAAeC,oBACpBC,KAAa,EACbC,QAA+B;IAE/B,oDAAoD;IACpD,IAAIA,aAAaN,sBAAsBO,MAAM,EAAE;QAC7C,OAAOF;IACT;IAEA,qCAAqC;IACrC,MAAMG,UAAU,MAAML,aAAaE;IACnC,IAAIC,aAAaN,sBAAsBS,IAAI,EAAE;QAC3C,OAAOP,cAAcM;IACvB;IAEA,OAAOP,WAAWO;AACpB"}
|