@metamask/keyring-sdk 2.3.0 → 3.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 +23 -2
- package/dist/entropy.cjs +45 -0
- package/dist/entropy.cjs.map +1 -0
- package/dist/entropy.d.cts +39 -0
- package/dist/entropy.d.cts.map +1 -0
- package/dist/entropy.d.mts +39 -0
- package/dist/entropy.d.mts.map +1 -0
- package/dist/entropy.mjs +40 -0
- package/dist/entropy.mjs.map +1 -0
- package/dist/index.cjs +1 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +1 -0
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -0
- package/dist/index.mjs.map +1 -1
- package/dist/mnemonic.cjs +50 -6
- package/dist/mnemonic.cjs.map +1 -1
- package/dist/mnemonic.d.cts +26 -0
- package/dist/mnemonic.d.cts.map +1 -1
- package/dist/mnemonic.d.mts +26 -0
- package/dist/mnemonic.d.mts.map +1 -1
- package/dist/mnemonic.mjs +46 -5
- package/dist/mnemonic.mjs.map +1 -1
- package/package.json +5 -4
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,25 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [3.1.0]
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- Add `decodeMnemonic` and `decodeMnemonicWords` ([#612](https://github.com/MetaMask/accounts/pull/612))
|
|
15
|
+
|
|
16
|
+
## [3.0.0]
|
|
17
|
+
|
|
18
|
+
### Added
|
|
19
|
+
|
|
20
|
+
- Add new entropy support ([#603](https://github.com/MetaMask/accounts/pull/603))
|
|
21
|
+
- Add `encodeMnemonicWords` ([#606](https://github.com/MetaMask/accounts/pull/606))
|
|
22
|
+
|
|
23
|
+
### Changed
|
|
24
|
+
|
|
25
|
+
- **BREAKING:** Drop support for Node.js v18 and v20; minimum version is now v22 ([#593](https://github.com/MetaMask/accounts/pull/593))
|
|
26
|
+
- Bump `@metamask/keyring-api` from `^23.6.0` to `^24.0.0` ([#604](https://github.com/MetaMask/accounts/pull/604), [#611](https://github.com/MetaMask/accounts/pull/611))
|
|
27
|
+
- Bump `@metamask/keyring-utils` from `^4.0.0` to `^5.0.0` ([#611](https://github.com/MetaMask/accounts/pull/611))
|
|
28
|
+
|
|
10
29
|
## [2.3.0]
|
|
11
30
|
|
|
12
31
|
### Added
|
|
@@ -17,7 +36,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
17
36
|
### Changed
|
|
18
37
|
|
|
19
38
|
- Bump `@metamask/keyring-api` from `^23.2.0` to `^23.6.0` ([#569](https://github.com/MetaMask/accounts/pull/569), [#583](https://github.com/MetaMask/accounts/pull/583), [#587](https://github.com/MetaMask/accounts/pull/587), [#600](https://github.com/MetaMask/accounts/pull/600))
|
|
20
|
-
- Bump `@metamask/superstruct` from `^3.1.0` to `^3.4.1` ([#580](https://github.com/MetaMask/accounts/pull/580)
|
|
39
|
+
- Bump `@metamask/superstruct` from `^3.1.0` to `^3.4.1` ([#580](https://github.com/MetaMask/accounts/pull/580), [#577](https://github.com/MetaMask/accounts/pull/577))
|
|
21
40
|
- Bump `@metamask/keyring-utils` from `^3.3.1` to `^4.0.0` ([#600](https://github.com/MetaMask/accounts/pull/600))
|
|
22
41
|
|
|
23
42
|
## [2.2.0]
|
|
@@ -101,7 +120,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
101
120
|
|
|
102
121
|
- Initial release, extracted from `@metamask/keyring-api` ([#478](https://github.com/MetaMask/accounts/pull/478), [#482](https://github.com/MetaMask/accounts/pull/482))
|
|
103
122
|
|
|
104
|
-
[Unreleased]: https://github.com/MetaMask/accounts/compare/@metamask/keyring-sdk@
|
|
123
|
+
[Unreleased]: https://github.com/MetaMask/accounts/compare/@metamask/keyring-sdk@3.1.0...HEAD
|
|
124
|
+
[3.1.0]: https://github.com/MetaMask/accounts/compare/@metamask/keyring-sdk@3.0.0...@metamask/keyring-sdk@3.1.0
|
|
125
|
+
[3.0.0]: https://github.com/MetaMask/accounts/compare/@metamask/keyring-sdk@2.3.0...@metamask/keyring-sdk@3.0.0
|
|
105
126
|
[2.3.0]: https://github.com/MetaMask/accounts/compare/@metamask/keyring-sdk@2.2.0...@metamask/keyring-sdk@2.3.0
|
|
106
127
|
[2.2.0]: https://github.com/MetaMask/accounts/compare/@metamask/keyring-sdk@2.1.1...@metamask/keyring-sdk@2.2.0
|
|
107
128
|
[2.1.1]: https://github.com/MetaMask/accounts/compare/@metamask/keyring-sdk@2.1.0...@metamask/keyring-sdk@2.1.1
|
package/dist/entropy.cjs
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toEntropySourceId = exports.fingerprint = void 0;
|
|
4
|
+
const hmac_1 = require("@noble/hashes/hmac");
|
|
5
|
+
const sha2_1 = require("@noble/hashes/sha2");
|
|
6
|
+
const uuid_1 = require("uuid");
|
|
7
|
+
/**
|
|
8
|
+
* Computes a deterministic, non-reversible fingerprint for a piece of entropy.
|
|
9
|
+
*
|
|
10
|
+
* The fingerprint is a UUID v4 seeded from the first 16 bytes of
|
|
11
|
+
* `HMAC-SHA256(key=material, msg='metamask:fingerprint')`.
|
|
12
|
+
*
|
|
13
|
+
* @param material - The raw entropy bytes (e.g. BIP-39 mnemonic bytes).
|
|
14
|
+
* @returns A deterministic UUID v4 string that uniquely identifies the entropy
|
|
15
|
+
* without exposing it.
|
|
16
|
+
*/
|
|
17
|
+
async function fingerprint(material) {
|
|
18
|
+
const message = new TextEncoder().encode('metamask:fingerprint');
|
|
19
|
+
// `@noble/hashes` is synchronous today, but the async signature is kept as a
|
|
20
|
+
// forward-compatible seam: a future migration to the Web Crypto API (or any
|
|
21
|
+
// other async primitive) won't require changes at every call site.
|
|
22
|
+
const digest = (0, hmac_1.hmac)(sha2_1.sha256, material, message);
|
|
23
|
+
return (0, uuid_1.v4)({ random: digest.slice(0, 16) });
|
|
24
|
+
}
|
|
25
|
+
exports.fingerprint = fingerprint;
|
|
26
|
+
/**
|
|
27
|
+
* Computes a stable {@link EntropySourceId} for an entropy source.
|
|
28
|
+
*
|
|
29
|
+
* The ID is formatted as `entropy:{type}:{uuid}`, where
|
|
30
|
+
* the UUID segment is the {@link fingerprint} of `material` when provided, or
|
|
31
|
+
* `'_'` for entropy sources whose secret never leaves the device (e.g. hardware
|
|
32
|
+
* wallets).
|
|
33
|
+
*
|
|
34
|
+
* @param type - The entropy source type (e.g. `'mnemonic'`,
|
|
35
|
+
* `'ledger'`, `'private-key'`).
|
|
36
|
+
* @param material - The raw entropy bytes. Omit for hardware wallets or any
|
|
37
|
+
* entropy source where the secret is not directly accessible.
|
|
38
|
+
* @returns A stable {@link EntropySourceId} string.
|
|
39
|
+
*/
|
|
40
|
+
async function toEntropySourceId(type, material) {
|
|
41
|
+
const entropyFingerprint = material ? await fingerprint(material) : '_';
|
|
42
|
+
return `entropy:${type}:${entropyFingerprint}`;
|
|
43
|
+
}
|
|
44
|
+
exports.toEntropySourceId = toEntropySourceId;
|
|
45
|
+
//# sourceMappingURL=entropy.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entropy.cjs","sourceRoot":"","sources":["../src/entropy.ts"],"names":[],"mappings":";;;AAAA,6CAA0C;AAC1C,6CAA4C;AAC5C,+BAAkC;AAsBlC;;;;;;;;;GASG;AACI,KAAK,UAAU,WAAW,CAAC,QAAoB;IACpD,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,sBAAsB,CAAC,CAAC;IACjE,6EAA6E;IAC7E,4EAA4E;IAC5E,mEAAmE;IACnE,MAAM,MAAM,GAAG,IAAA,WAAI,EAAC,aAAM,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;IAC/C,OAAO,IAAA,SAAI,EAAC,EAAE,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC;AAC/C,CAAC;AAPD,kCAOC;AAED;;;;;;;;;;;;;GAaG;AACI,KAAK,UAAU,iBAAiB,CACrC,IAAuB,EACvB,QAAqB;IAErB,MAAM,kBAAkB,GAAG,QAAQ,CAAC,CAAC,CAAC,MAAM,WAAW,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;IACxE,OAAO,WAAW,IAAI,IAAI,kBAAkB,EAAE,CAAC;AACjD,CAAC;AAND,8CAMC","sourcesContent":["import { hmac } from '@noble/hashes/hmac';\nimport { sha256 } from '@noble/hashes/sha2';\nimport { v4 as uuid } from 'uuid';\n\n/**\n * The type of an entropy source.\n */\nexport type EntropySourceType =\n | 'mnemonic'\n | 'ledger'\n | 'trezor'\n | 'qr'\n | 'private-key'\n | 'mpc';\n\n/**\n * Unique identifier for an entropy source.\n *\n * Format: `entropy:{type}:{uuid}` where the UUID is a\n * deterministic fingerprint of the underlying secret, or `'_'` for entropies\n * that cannot be uniquely identified.\n */\nexport type EntropySourceId = `entropy:${EntropySourceType}:${string}`;\n\n/**\n * Computes a deterministic, non-reversible fingerprint for a piece of entropy.\n *\n * The fingerprint is a UUID v4 seeded from the first 16 bytes of\n * `HMAC-SHA256(key=material, msg='metamask:fingerprint')`.\n *\n * @param material - The raw entropy bytes (e.g. BIP-39 mnemonic bytes).\n * @returns A deterministic UUID v4 string that uniquely identifies the entropy\n * without exposing it.\n */\nexport async function fingerprint(material: Uint8Array): Promise<string> {\n const message = new TextEncoder().encode('metamask:fingerprint');\n // `@noble/hashes` is synchronous today, but the async signature is kept as a\n // forward-compatible seam: a future migration to the Web Crypto API (or any\n // other async primitive) won't require changes at every call site.\n const digest = hmac(sha256, material, message);\n return uuid({ random: digest.slice(0, 16) });\n}\n\n/**\n * Computes a stable {@link EntropySourceId} for an entropy source.\n *\n * The ID is formatted as `entropy:{type}:{uuid}`, where\n * the UUID segment is the {@link fingerprint} of `material` when provided, or\n * `'_'` for entropy sources whose secret never leaves the device (e.g. hardware\n * wallets).\n *\n * @param type - The entropy source type (e.g. `'mnemonic'`,\n * `'ledger'`, `'private-key'`).\n * @param material - The raw entropy bytes. Omit for hardware wallets or any\n * entropy source where the secret is not directly accessible.\n * @returns A stable {@link EntropySourceId} string.\n */\nexport async function toEntropySourceId(\n type: EntropySourceType,\n material?: Uint8Array,\n): Promise<EntropySourceId> {\n const entropyFingerprint = material ? await fingerprint(material) : '_';\n return `entropy:${type}:${entropyFingerprint}`;\n}\n"]}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The type of an entropy source.
|
|
3
|
+
*/
|
|
4
|
+
export type EntropySourceType = 'mnemonic' | 'ledger' | 'trezor' | 'qr' | 'private-key' | 'mpc';
|
|
5
|
+
/**
|
|
6
|
+
* Unique identifier for an entropy source.
|
|
7
|
+
*
|
|
8
|
+
* Format: `entropy:{type}:{uuid}` where the UUID is a
|
|
9
|
+
* deterministic fingerprint of the underlying secret, or `'_'` for entropies
|
|
10
|
+
* that cannot be uniquely identified.
|
|
11
|
+
*/
|
|
12
|
+
export type EntropySourceId = `entropy:${EntropySourceType}:${string}`;
|
|
13
|
+
/**
|
|
14
|
+
* Computes a deterministic, non-reversible fingerprint for a piece of entropy.
|
|
15
|
+
*
|
|
16
|
+
* The fingerprint is a UUID v4 seeded from the first 16 bytes of
|
|
17
|
+
* `HMAC-SHA256(key=material, msg='metamask:fingerprint')`.
|
|
18
|
+
*
|
|
19
|
+
* @param material - The raw entropy bytes (e.g. BIP-39 mnemonic bytes).
|
|
20
|
+
* @returns A deterministic UUID v4 string that uniquely identifies the entropy
|
|
21
|
+
* without exposing it.
|
|
22
|
+
*/
|
|
23
|
+
export declare function fingerprint(material: Uint8Array): Promise<string>;
|
|
24
|
+
/**
|
|
25
|
+
* Computes a stable {@link EntropySourceId} for an entropy source.
|
|
26
|
+
*
|
|
27
|
+
* The ID is formatted as `entropy:{type}:{uuid}`, where
|
|
28
|
+
* the UUID segment is the {@link fingerprint} of `material` when provided, or
|
|
29
|
+
* `'_'` for entropy sources whose secret never leaves the device (e.g. hardware
|
|
30
|
+
* wallets).
|
|
31
|
+
*
|
|
32
|
+
* @param type - The entropy source type (e.g. `'mnemonic'`,
|
|
33
|
+
* `'ledger'`, `'private-key'`).
|
|
34
|
+
* @param material - The raw entropy bytes. Omit for hardware wallets or any
|
|
35
|
+
* entropy source where the secret is not directly accessible.
|
|
36
|
+
* @returns A stable {@link EntropySourceId} string.
|
|
37
|
+
*/
|
|
38
|
+
export declare function toEntropySourceId(type: EntropySourceType, material?: Uint8Array): Promise<EntropySourceId>;
|
|
39
|
+
//# sourceMappingURL=entropy.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entropy.d.cts","sourceRoot":"","sources":["../src/entropy.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,MAAM,MAAM,iBAAiB,GACzB,UAAU,GACV,QAAQ,GACR,QAAQ,GACR,IAAI,GACJ,aAAa,GACb,KAAK,CAAC;AAEV;;;;;;GAMG;AACH,MAAM,MAAM,eAAe,GAAG,WAAW,iBAAiB,IAAI,MAAM,EAAE,CAAC;AAEvE;;;;;;;;;GASG;AACH,wBAAsB,WAAW,CAAC,QAAQ,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,CAOvE;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAsB,iBAAiB,CACrC,IAAI,EAAE,iBAAiB,EACvB,QAAQ,CAAC,EAAE,UAAU,GACpB,OAAO,CAAC,eAAe,CAAC,CAG1B"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The type of an entropy source.
|
|
3
|
+
*/
|
|
4
|
+
export type EntropySourceType = 'mnemonic' | 'ledger' | 'trezor' | 'qr' | 'private-key' | 'mpc';
|
|
5
|
+
/**
|
|
6
|
+
* Unique identifier for an entropy source.
|
|
7
|
+
*
|
|
8
|
+
* Format: `entropy:{type}:{uuid}` where the UUID is a
|
|
9
|
+
* deterministic fingerprint of the underlying secret, or `'_'` for entropies
|
|
10
|
+
* that cannot be uniquely identified.
|
|
11
|
+
*/
|
|
12
|
+
export type EntropySourceId = `entropy:${EntropySourceType}:${string}`;
|
|
13
|
+
/**
|
|
14
|
+
* Computes a deterministic, non-reversible fingerprint for a piece of entropy.
|
|
15
|
+
*
|
|
16
|
+
* The fingerprint is a UUID v4 seeded from the first 16 bytes of
|
|
17
|
+
* `HMAC-SHA256(key=material, msg='metamask:fingerprint')`.
|
|
18
|
+
*
|
|
19
|
+
* @param material - The raw entropy bytes (e.g. BIP-39 mnemonic bytes).
|
|
20
|
+
* @returns A deterministic UUID v4 string that uniquely identifies the entropy
|
|
21
|
+
* without exposing it.
|
|
22
|
+
*/
|
|
23
|
+
export declare function fingerprint(material: Uint8Array): Promise<string>;
|
|
24
|
+
/**
|
|
25
|
+
* Computes a stable {@link EntropySourceId} for an entropy source.
|
|
26
|
+
*
|
|
27
|
+
* The ID is formatted as `entropy:{type}:{uuid}`, where
|
|
28
|
+
* the UUID segment is the {@link fingerprint} of `material` when provided, or
|
|
29
|
+
* `'_'` for entropy sources whose secret never leaves the device (e.g. hardware
|
|
30
|
+
* wallets).
|
|
31
|
+
*
|
|
32
|
+
* @param type - The entropy source type (e.g. `'mnemonic'`,
|
|
33
|
+
* `'ledger'`, `'private-key'`).
|
|
34
|
+
* @param material - The raw entropy bytes. Omit for hardware wallets or any
|
|
35
|
+
* entropy source where the secret is not directly accessible.
|
|
36
|
+
* @returns A stable {@link EntropySourceId} string.
|
|
37
|
+
*/
|
|
38
|
+
export declare function toEntropySourceId(type: EntropySourceType, material?: Uint8Array): Promise<EntropySourceId>;
|
|
39
|
+
//# sourceMappingURL=entropy.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entropy.d.mts","sourceRoot":"","sources":["../src/entropy.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,MAAM,MAAM,iBAAiB,GACzB,UAAU,GACV,QAAQ,GACR,QAAQ,GACR,IAAI,GACJ,aAAa,GACb,KAAK,CAAC;AAEV;;;;;;GAMG;AACH,MAAM,MAAM,eAAe,GAAG,WAAW,iBAAiB,IAAI,MAAM,EAAE,CAAC;AAEvE;;;;;;;;;GASG;AACH,wBAAsB,WAAW,CAAC,QAAQ,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,CAOvE;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAsB,iBAAiB,CACrC,IAAI,EAAE,iBAAiB,EACvB,QAAQ,CAAC,EAAE,UAAU,GACpB,OAAO,CAAC,eAAe,CAAC,CAG1B"}
|
package/dist/entropy.mjs
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { hmac } from "@noble/hashes/hmac";
|
|
2
|
+
import { sha256 } from "@noble/hashes/sha2";
|
|
3
|
+
import { v4 as uuid } from "uuid";
|
|
4
|
+
/**
|
|
5
|
+
* Computes a deterministic, non-reversible fingerprint for a piece of entropy.
|
|
6
|
+
*
|
|
7
|
+
* The fingerprint is a UUID v4 seeded from the first 16 bytes of
|
|
8
|
+
* `HMAC-SHA256(key=material, msg='metamask:fingerprint')`.
|
|
9
|
+
*
|
|
10
|
+
* @param material - The raw entropy bytes (e.g. BIP-39 mnemonic bytes).
|
|
11
|
+
* @returns A deterministic UUID v4 string that uniquely identifies the entropy
|
|
12
|
+
* without exposing it.
|
|
13
|
+
*/
|
|
14
|
+
export async function fingerprint(material) {
|
|
15
|
+
const message = new TextEncoder().encode('metamask:fingerprint');
|
|
16
|
+
// `@noble/hashes` is synchronous today, but the async signature is kept as a
|
|
17
|
+
// forward-compatible seam: a future migration to the Web Crypto API (or any
|
|
18
|
+
// other async primitive) won't require changes at every call site.
|
|
19
|
+
const digest = hmac(sha256, material, message);
|
|
20
|
+
return uuid({ random: digest.slice(0, 16) });
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Computes a stable {@link EntropySourceId} for an entropy source.
|
|
24
|
+
*
|
|
25
|
+
* The ID is formatted as `entropy:{type}:{uuid}`, where
|
|
26
|
+
* the UUID segment is the {@link fingerprint} of `material` when provided, or
|
|
27
|
+
* `'_'` for entropy sources whose secret never leaves the device (e.g. hardware
|
|
28
|
+
* wallets).
|
|
29
|
+
*
|
|
30
|
+
* @param type - The entropy source type (e.g. `'mnemonic'`,
|
|
31
|
+
* `'ledger'`, `'private-key'`).
|
|
32
|
+
* @param material - The raw entropy bytes. Omit for hardware wallets or any
|
|
33
|
+
* entropy source where the secret is not directly accessible.
|
|
34
|
+
* @returns A stable {@link EntropySourceId} string.
|
|
35
|
+
*/
|
|
36
|
+
export async function toEntropySourceId(type, material) {
|
|
37
|
+
const entropyFingerprint = material ? await fingerprint(material) : '_';
|
|
38
|
+
return `entropy:${type}:${entropyFingerprint}`;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=entropy.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entropy.mjs","sourceRoot":"","sources":["../src/entropy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,2BAA2B;AAC1C,OAAO,EAAE,MAAM,EAAE,2BAA2B;AAC5C,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,aAAa;AAsBlC;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,QAAoB;IACpD,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,sBAAsB,CAAC,CAAC;IACjE,6EAA6E;IAC7E,4EAA4E;IAC5E,mEAAmE;IACnE,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;IAC/C,OAAO,IAAI,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC;AAC/C,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,IAAuB,EACvB,QAAqB;IAErB,MAAM,kBAAkB,GAAG,QAAQ,CAAC,CAAC,CAAC,MAAM,WAAW,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;IACxE,OAAO,WAAW,IAAI,IAAI,kBAAkB,EAAE,CAAC;AACjD,CAAC","sourcesContent":["import { hmac } from '@noble/hashes/hmac';\nimport { sha256 } from '@noble/hashes/sha2';\nimport { v4 as uuid } from 'uuid';\n\n/**\n * The type of an entropy source.\n */\nexport type EntropySourceType =\n | 'mnemonic'\n | 'ledger'\n | 'trezor'\n | 'qr'\n | 'private-key'\n | 'mpc';\n\n/**\n * Unique identifier for an entropy source.\n *\n * Format: `entropy:{type}:{uuid}` where the UUID is a\n * deterministic fingerprint of the underlying secret, or `'_'` for entropies\n * that cannot be uniquely identified.\n */\nexport type EntropySourceId = `entropy:${EntropySourceType}:${string}`;\n\n/**\n * Computes a deterministic, non-reversible fingerprint for a piece of entropy.\n *\n * The fingerprint is a UUID v4 seeded from the first 16 bytes of\n * `HMAC-SHA256(key=material, msg='metamask:fingerprint')`.\n *\n * @param material - The raw entropy bytes (e.g. BIP-39 mnemonic bytes).\n * @returns A deterministic UUID v4 string that uniquely identifies the entropy\n * without exposing it.\n */\nexport async function fingerprint(material: Uint8Array): Promise<string> {\n const message = new TextEncoder().encode('metamask:fingerprint');\n // `@noble/hashes` is synchronous today, but the async signature is kept as a\n // forward-compatible seam: a future migration to the Web Crypto API (or any\n // other async primitive) won't require changes at every call site.\n const digest = hmac(sha256, material, message);\n return uuid({ random: digest.slice(0, 16) });\n}\n\n/**\n * Computes a stable {@link EntropySourceId} for an entropy source.\n *\n * The ID is formatted as `entropy:{type}:{uuid}`, where\n * the UUID segment is the {@link fingerprint} of `material` when provided, or\n * `'_'` for entropy sources whose secret never leaves the device (e.g. hardware\n * wallets).\n *\n * @param type - The entropy source type (e.g. `'mnemonic'`,\n * `'ledger'`, `'private-key'`).\n * @param material - The raw entropy bytes. Omit for hardware wallets or any\n * entropy source where the secret is not directly accessible.\n * @returns A stable {@link EntropySourceId} string.\n */\nexport async function toEntropySourceId(\n type: EntropySourceType,\n material?: Uint8Array,\n): Promise<EntropySourceId> {\n const entropyFingerprint = material ? await fingerprint(material) : '_';\n return `entropy:${type}:${entropyFingerprint}`;\n}\n"]}
|
package/dist/index.cjs
CHANGED
|
@@ -17,5 +17,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./keyring-account-registry.cjs"), exports);
|
|
18
18
|
__exportStar(require("./migration.cjs"), exports);
|
|
19
19
|
__exportStar(require("./mnemonic.cjs"), exports);
|
|
20
|
+
__exportStar(require("./entropy.cjs"), exports);
|
|
20
21
|
__exportStar(require("./eth/index.cjs"), exports);
|
|
21
22
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iEAA2C;AAC3C,kDAA4B;AAC5B,iDAA2B;AAC3B,kDAAsB","sourcesContent":["export * from './keyring-account-registry';\nexport * from './migration';\nexport * from './mnemonic';\nexport * from './eth';\n"]}
|
|
1
|
+
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iEAA2C;AAC3C,kDAA4B;AAC5B,iDAA2B;AAC3B,gDAA0B;AAC1B,kDAAsB","sourcesContent":["export * from './keyring-account-registry';\nexport * from './migration';\nexport * from './mnemonic';\nexport * from './entropy';\nexport * from './eth';\n"]}
|
package/dist/index.d.cts
CHANGED
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,+CAA2C;AAC3C,gCAA4B;AAC5B,+BAA2B;AAC3B,gCAAsB"}
|
|
1
|
+
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,+CAA2C;AAC3C,gCAA4B;AAC5B,+BAA2B;AAC3B,8BAA0B;AAC1B,gCAAsB"}
|
package/dist/index.d.mts
CHANGED
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,+CAA2C;AAC3C,gCAA4B;AAC5B,+BAA2B;AAC3B,gCAAsB"}
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,+CAA2C;AAC3C,gCAA4B;AAC5B,+BAA2B;AAC3B,8BAA0B;AAC1B,gCAAsB"}
|
package/dist/index.mjs
CHANGED
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,+CAA2C;AAC3C,gCAA4B;AAC5B,+BAA2B;AAC3B,gCAAsB","sourcesContent":["export * from './keyring-account-registry';\nexport * from './migration';\nexport * from './mnemonic';\nexport * from './eth';\n"]}
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,+CAA2C;AAC3C,gCAA4B;AAC5B,+BAA2B;AAC3B,8BAA0B;AAC1B,gCAAsB","sourcesContent":["export * from './keyring-account-registry';\nexport * from './migration';\nexport * from './mnemonic';\nexport * from './entropy';\nexport * from './eth';\n"]}
|
package/dist/mnemonic.cjs
CHANGED
|
@@ -1,21 +1,65 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.encodeMnemonic = void 0;
|
|
3
|
+
exports.decodeMnemonic = exports.decodeMnemonicWords = exports.encodeMnemonic = exports.encodeMnemonicWords = void 0;
|
|
4
4
|
const english_1 = require("@metamask/scure-bip39/dist/wordlists/english.js");
|
|
5
5
|
/**
|
|
6
|
-
* Encodes a mnemonic as
|
|
6
|
+
* Encodes a mnemonic as a string of words.
|
|
7
7
|
*
|
|
8
8
|
* @param mnemonicIndicesBytes - An array of bytes (16-bit unsigned integers) representing the indices of the words in the mnemonic.
|
|
9
|
-
* @returns
|
|
9
|
+
* @returns A string representing the mnemonic.
|
|
10
10
|
*/
|
|
11
|
-
function
|
|
11
|
+
function encodeMnemonicWords(mnemonicIndicesBytes) {
|
|
12
12
|
const mnemonicIndices = Array.from(
|
|
13
13
|
// Create a new `Uint8Array` to ensure we have a proper view on the buffer
|
|
14
14
|
// without having to worry about `byteOffset` and `byteLength` of
|
|
15
15
|
// the inner buffer.
|
|
16
16
|
new Uint16Array(new Uint8Array(mnemonicIndicesBytes).buffer));
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
return mnemonicIndices.map((i) => english_1.wordlist[i]).join(' ');
|
|
18
|
+
}
|
|
19
|
+
exports.encodeMnemonicWords = encodeMnemonicWords;
|
|
20
|
+
/**
|
|
21
|
+
* Encodes a mnemonic as an array of bytes (UTF-8).
|
|
22
|
+
*
|
|
23
|
+
* @param mnemonicIndicesBytes - An array of bytes (16-bit unsigned integers) representing the indices of the words in the mnemonic.
|
|
24
|
+
* @returns An array of bytes (UTF-8) representing the mnemonic.
|
|
25
|
+
*/
|
|
26
|
+
function encodeMnemonic(mnemonicIndicesBytes) {
|
|
27
|
+
return Array.from(new TextEncoder().encode(encodeMnemonicWords(mnemonicIndicesBytes)));
|
|
19
28
|
}
|
|
20
29
|
exports.encodeMnemonic = encodeMnemonic;
|
|
30
|
+
/**
|
|
31
|
+
* Decodes a string of mnemonic words as an array of bytes (16-bit unsigned
|
|
32
|
+
* integers) representing the indices of the words in the mnemonic.
|
|
33
|
+
*
|
|
34
|
+
* @param mnemonic - A string representing the mnemonic.
|
|
35
|
+
* @returns An array of bytes representing the indices of the words in the mnemonic.
|
|
36
|
+
* @throws If the mnemonic contains a word that is not in the English BIP-39 wordlist.
|
|
37
|
+
*/
|
|
38
|
+
function decodeMnemonicWords(mnemonic) {
|
|
39
|
+
if (mnemonic === '') {
|
|
40
|
+
return new Uint8Array();
|
|
41
|
+
}
|
|
42
|
+
const mnemonicIndices = mnemonic.split(' ').map((word) => {
|
|
43
|
+
const index = english_1.wordlist.indexOf(word);
|
|
44
|
+
if (index === -1) {
|
|
45
|
+
throw new Error(`Invalid mnemonic word: "${word}"`);
|
|
46
|
+
}
|
|
47
|
+
return index;
|
|
48
|
+
});
|
|
49
|
+
return new Uint8Array(new Uint16Array(mnemonicIndices).buffer);
|
|
50
|
+
}
|
|
51
|
+
exports.decodeMnemonicWords = decodeMnemonicWords;
|
|
52
|
+
/**
|
|
53
|
+
* Decodes an array of bytes (UTF-8) representing a mnemonic as an array of
|
|
54
|
+
* bytes (16-bit unsigned integers) representing the indices of the words in
|
|
55
|
+
* the mnemonic.
|
|
56
|
+
*
|
|
57
|
+
* @param mnemonicBytes - An array of bytes (UTF-8) representing the mnemonic.
|
|
58
|
+
* @returns An array of bytes representing the indices of the words in the mnemonic.
|
|
59
|
+
* @throws If the mnemonic contains a word that is not in the English BIP-39 wordlist.
|
|
60
|
+
*/
|
|
61
|
+
function decodeMnemonic(mnemonicBytes) {
|
|
62
|
+
return decodeMnemonicWords(new TextDecoder().decode(mnemonicBytes));
|
|
63
|
+
}
|
|
64
|
+
exports.decodeMnemonic = decodeMnemonic;
|
|
21
65
|
//# sourceMappingURL=mnemonic.cjs.map
|
package/dist/mnemonic.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mnemonic.cjs","sourceRoot":"","sources":["../src/mnemonic.ts"],"names":[],"mappings":";;;AAAA,6EAAwE;AAExE;;;;;GAKG;AACH,SAAgB,
|
|
1
|
+
{"version":3,"file":"mnemonic.cjs","sourceRoot":"","sources":["../src/mnemonic.ts"],"names":[],"mappings":";;;AAAA,6EAAwE;AAExE;;;;;GAKG;AACH,SAAgB,mBAAmB,CAAC,oBAAgC;IAClE,MAAM,eAAe,GAAG,KAAK,CAAC,IAAI;IAChC,0EAA0E;IAC1E,iEAAiE;IACjE,oBAAoB;IACpB,IAAI,WAAW,CAAC,IAAI,UAAU,CAAC,oBAAoB,CAAC,CAAC,MAAM,CAAC,CAC7D,CAAC;IACF,OAAO,eAAe,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,kBAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC3D,CAAC;AARD,kDAQC;AAED;;;;;GAKG;AACH,SAAgB,cAAc,CAAC,oBAAgC;IAC7D,OAAO,KAAK,CAAC,IAAI,CACf,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,mBAAmB,CAAC,oBAAoB,CAAC,CAAC,CACpE,CAAC;AACJ,CAAC;AAJD,wCAIC;AAED;;;;;;;GAOG;AACH,SAAgB,mBAAmB,CAAC,QAAgB;IAClD,IAAI,QAAQ,KAAK,EAAE,EAAE,CAAC;QACpB,OAAO,IAAI,UAAU,EAAE,CAAC;IAC1B,CAAC;IAED,MAAM,eAAe,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;QACvD,MAAM,KAAK,GAAG,kBAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACrC,IAAI,KAAK,KAAK,CAAC,CAAC,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CAAC,2BAA2B,IAAI,GAAG,CAAC,CAAC;QACtD,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC,CAAC,CAAC;IAEH,OAAO,IAAI,UAAU,CAAC,IAAI,WAAW,CAAC,eAAe,CAAC,CAAC,MAAM,CAAC,CAAC;AACjE,CAAC;AAdD,kDAcC;AAED;;;;;;;;GAQG;AACH,SAAgB,cAAc,CAAC,aAAyB;IACtD,OAAO,mBAAmB,CAAC,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC;AACtE,CAAC;AAFD,wCAEC","sourcesContent":["import { wordlist } from '@metamask/scure-bip39/dist/wordlists/english';\n\n/**\n * Encodes a mnemonic as a string of words.\n *\n * @param mnemonicIndicesBytes - An array of bytes (16-bit unsigned integers) representing the indices of the words in the mnemonic.\n * @returns A string representing the mnemonic.\n */\nexport function encodeMnemonicWords(mnemonicIndicesBytes: Uint8Array): string {\n const mnemonicIndices = Array.from(\n // Create a new `Uint8Array` to ensure we have a proper view on the buffer\n // without having to worry about `byteOffset` and `byteLength` of\n // the inner buffer.\n new Uint16Array(new Uint8Array(mnemonicIndicesBytes).buffer),\n );\n return mnemonicIndices.map((i) => wordlist[i]).join(' ');\n}\n\n/**\n * Encodes a mnemonic as an array of bytes (UTF-8).\n *\n * @param mnemonicIndicesBytes - An array of bytes (16-bit unsigned integers) representing the indices of the words in the mnemonic.\n * @returns An array of bytes (UTF-8) representing the mnemonic.\n */\nexport function encodeMnemonic(mnemonicIndicesBytes: Uint8Array): number[] {\n return Array.from(\n new TextEncoder().encode(encodeMnemonicWords(mnemonicIndicesBytes)),\n );\n}\n\n/**\n * Decodes a string of mnemonic words as an array of bytes (16-bit unsigned\n * integers) representing the indices of the words in the mnemonic.\n *\n * @param mnemonic - A string representing the mnemonic.\n * @returns An array of bytes representing the indices of the words in the mnemonic.\n * @throws If the mnemonic contains a word that is not in the English BIP-39 wordlist.\n */\nexport function decodeMnemonicWords(mnemonic: string): Uint8Array {\n if (mnemonic === '') {\n return new Uint8Array();\n }\n\n const mnemonicIndices = mnemonic.split(' ').map((word) => {\n const index = wordlist.indexOf(word);\n if (index === -1) {\n throw new Error(`Invalid mnemonic word: \"${word}\"`);\n }\n return index;\n });\n\n return new Uint8Array(new Uint16Array(mnemonicIndices).buffer);\n}\n\n/**\n * Decodes an array of bytes (UTF-8) representing a mnemonic as an array of\n * bytes (16-bit unsigned integers) representing the indices of the words in\n * the mnemonic.\n *\n * @param mnemonicBytes - An array of bytes (UTF-8) representing the mnemonic.\n * @returns An array of bytes representing the indices of the words in the mnemonic.\n * @throws If the mnemonic contains a word that is not in the English BIP-39 wordlist.\n */\nexport function decodeMnemonic(mnemonicBytes: Uint8Array): Uint8Array {\n return decodeMnemonicWords(new TextDecoder().decode(mnemonicBytes));\n}\n"]}
|
package/dist/mnemonic.d.cts
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Encodes a mnemonic as a string of words.
|
|
3
|
+
*
|
|
4
|
+
* @param mnemonicIndicesBytes - An array of bytes (16-bit unsigned integers) representing the indices of the words in the mnemonic.
|
|
5
|
+
* @returns A string representing the mnemonic.
|
|
6
|
+
*/
|
|
7
|
+
export declare function encodeMnemonicWords(mnemonicIndicesBytes: Uint8Array): string;
|
|
1
8
|
/**
|
|
2
9
|
* Encodes a mnemonic as an array of bytes (UTF-8).
|
|
3
10
|
*
|
|
@@ -5,4 +12,23 @@
|
|
|
5
12
|
* @returns An array of bytes (UTF-8) representing the mnemonic.
|
|
6
13
|
*/
|
|
7
14
|
export declare function encodeMnemonic(mnemonicIndicesBytes: Uint8Array): number[];
|
|
15
|
+
/**
|
|
16
|
+
* Decodes a string of mnemonic words as an array of bytes (16-bit unsigned
|
|
17
|
+
* integers) representing the indices of the words in the mnemonic.
|
|
18
|
+
*
|
|
19
|
+
* @param mnemonic - A string representing the mnemonic.
|
|
20
|
+
* @returns An array of bytes representing the indices of the words in the mnemonic.
|
|
21
|
+
* @throws If the mnemonic contains a word that is not in the English BIP-39 wordlist.
|
|
22
|
+
*/
|
|
23
|
+
export declare function decodeMnemonicWords(mnemonic: string): Uint8Array;
|
|
24
|
+
/**
|
|
25
|
+
* Decodes an array of bytes (UTF-8) representing a mnemonic as an array of
|
|
26
|
+
* bytes (16-bit unsigned integers) representing the indices of the words in
|
|
27
|
+
* the mnemonic.
|
|
28
|
+
*
|
|
29
|
+
* @param mnemonicBytes - An array of bytes (UTF-8) representing the mnemonic.
|
|
30
|
+
* @returns An array of bytes representing the indices of the words in the mnemonic.
|
|
31
|
+
* @throws If the mnemonic contains a word that is not in the English BIP-39 wordlist.
|
|
32
|
+
*/
|
|
33
|
+
export declare function decodeMnemonic(mnemonicBytes: Uint8Array): Uint8Array;
|
|
8
34
|
//# sourceMappingURL=mnemonic.d.cts.map
|
package/dist/mnemonic.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mnemonic.d.cts","sourceRoot":"","sources":["../src/mnemonic.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,oBAAoB,EAAE,UAAU,GAAG,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"mnemonic.d.cts","sourceRoot":"","sources":["../src/mnemonic.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,oBAAoB,EAAE,UAAU,GAAG,MAAM,CAQ5E;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,oBAAoB,EAAE,UAAU,GAAG,MAAM,EAAE,CAIzE;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,UAAU,CAchE;AAED;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,aAAa,EAAE,UAAU,GAAG,UAAU,CAEpE"}
|
package/dist/mnemonic.d.mts
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Encodes a mnemonic as a string of words.
|
|
3
|
+
*
|
|
4
|
+
* @param mnemonicIndicesBytes - An array of bytes (16-bit unsigned integers) representing the indices of the words in the mnemonic.
|
|
5
|
+
* @returns A string representing the mnemonic.
|
|
6
|
+
*/
|
|
7
|
+
export declare function encodeMnemonicWords(mnemonicIndicesBytes: Uint8Array): string;
|
|
1
8
|
/**
|
|
2
9
|
* Encodes a mnemonic as an array of bytes (UTF-8).
|
|
3
10
|
*
|
|
@@ -5,4 +12,23 @@
|
|
|
5
12
|
* @returns An array of bytes (UTF-8) representing the mnemonic.
|
|
6
13
|
*/
|
|
7
14
|
export declare function encodeMnemonic(mnemonicIndicesBytes: Uint8Array): number[];
|
|
15
|
+
/**
|
|
16
|
+
* Decodes a string of mnemonic words as an array of bytes (16-bit unsigned
|
|
17
|
+
* integers) representing the indices of the words in the mnemonic.
|
|
18
|
+
*
|
|
19
|
+
* @param mnemonic - A string representing the mnemonic.
|
|
20
|
+
* @returns An array of bytes representing the indices of the words in the mnemonic.
|
|
21
|
+
* @throws If the mnemonic contains a word that is not in the English BIP-39 wordlist.
|
|
22
|
+
*/
|
|
23
|
+
export declare function decodeMnemonicWords(mnemonic: string): Uint8Array;
|
|
24
|
+
/**
|
|
25
|
+
* Decodes an array of bytes (UTF-8) representing a mnemonic as an array of
|
|
26
|
+
* bytes (16-bit unsigned integers) representing the indices of the words in
|
|
27
|
+
* the mnemonic.
|
|
28
|
+
*
|
|
29
|
+
* @param mnemonicBytes - An array of bytes (UTF-8) representing the mnemonic.
|
|
30
|
+
* @returns An array of bytes representing the indices of the words in the mnemonic.
|
|
31
|
+
* @throws If the mnemonic contains a word that is not in the English BIP-39 wordlist.
|
|
32
|
+
*/
|
|
33
|
+
export declare function decodeMnemonic(mnemonicBytes: Uint8Array): Uint8Array;
|
|
8
34
|
//# sourceMappingURL=mnemonic.d.mts.map
|
package/dist/mnemonic.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mnemonic.d.mts","sourceRoot":"","sources":["../src/mnemonic.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,oBAAoB,EAAE,UAAU,GAAG,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"mnemonic.d.mts","sourceRoot":"","sources":["../src/mnemonic.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,oBAAoB,EAAE,UAAU,GAAG,MAAM,CAQ5E;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,oBAAoB,EAAE,UAAU,GAAG,MAAM,EAAE,CAIzE;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,UAAU,CAchE;AAED;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,aAAa,EAAE,UAAU,GAAG,UAAU,CAEpE"}
|
package/dist/mnemonic.mjs
CHANGED
|
@@ -1,17 +1,58 @@
|
|
|
1
1
|
import { wordlist } from "@metamask/scure-bip39/dist/wordlists/english.js";
|
|
2
2
|
/**
|
|
3
|
-
* Encodes a mnemonic as
|
|
3
|
+
* Encodes a mnemonic as a string of words.
|
|
4
4
|
*
|
|
5
5
|
* @param mnemonicIndicesBytes - An array of bytes (16-bit unsigned integers) representing the indices of the words in the mnemonic.
|
|
6
|
-
* @returns
|
|
6
|
+
* @returns A string representing the mnemonic.
|
|
7
7
|
*/
|
|
8
|
-
export function
|
|
8
|
+
export function encodeMnemonicWords(mnemonicIndicesBytes) {
|
|
9
9
|
const mnemonicIndices = Array.from(
|
|
10
10
|
// Create a new `Uint8Array` to ensure we have a proper view on the buffer
|
|
11
11
|
// without having to worry about `byteOffset` and `byteLength` of
|
|
12
12
|
// the inner buffer.
|
|
13
13
|
new Uint16Array(new Uint8Array(mnemonicIndicesBytes).buffer));
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
return mnemonicIndices.map((i) => wordlist[i]).join(' ');
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Encodes a mnemonic as an array of bytes (UTF-8).
|
|
18
|
+
*
|
|
19
|
+
* @param mnemonicIndicesBytes - An array of bytes (16-bit unsigned integers) representing the indices of the words in the mnemonic.
|
|
20
|
+
* @returns An array of bytes (UTF-8) representing the mnemonic.
|
|
21
|
+
*/
|
|
22
|
+
export function encodeMnemonic(mnemonicIndicesBytes) {
|
|
23
|
+
return Array.from(new TextEncoder().encode(encodeMnemonicWords(mnemonicIndicesBytes)));
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Decodes a string of mnemonic words as an array of bytes (16-bit unsigned
|
|
27
|
+
* integers) representing the indices of the words in the mnemonic.
|
|
28
|
+
*
|
|
29
|
+
* @param mnemonic - A string representing the mnemonic.
|
|
30
|
+
* @returns An array of bytes representing the indices of the words in the mnemonic.
|
|
31
|
+
* @throws If the mnemonic contains a word that is not in the English BIP-39 wordlist.
|
|
32
|
+
*/
|
|
33
|
+
export function decodeMnemonicWords(mnemonic) {
|
|
34
|
+
if (mnemonic === '') {
|
|
35
|
+
return new Uint8Array();
|
|
36
|
+
}
|
|
37
|
+
const mnemonicIndices = mnemonic.split(' ').map((word) => {
|
|
38
|
+
const index = wordlist.indexOf(word);
|
|
39
|
+
if (index === -1) {
|
|
40
|
+
throw new Error(`Invalid mnemonic word: "${word}"`);
|
|
41
|
+
}
|
|
42
|
+
return index;
|
|
43
|
+
});
|
|
44
|
+
return new Uint8Array(new Uint16Array(mnemonicIndices).buffer);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Decodes an array of bytes (UTF-8) representing a mnemonic as an array of
|
|
48
|
+
* bytes (16-bit unsigned integers) representing the indices of the words in
|
|
49
|
+
* the mnemonic.
|
|
50
|
+
*
|
|
51
|
+
* @param mnemonicBytes - An array of bytes (UTF-8) representing the mnemonic.
|
|
52
|
+
* @returns An array of bytes representing the indices of the words in the mnemonic.
|
|
53
|
+
* @throws If the mnemonic contains a word that is not in the English BIP-39 wordlist.
|
|
54
|
+
*/
|
|
55
|
+
export function decodeMnemonic(mnemonicBytes) {
|
|
56
|
+
return decodeMnemonicWords(new TextDecoder().decode(mnemonicBytes));
|
|
16
57
|
}
|
|
17
58
|
//# sourceMappingURL=mnemonic.mjs.map
|
package/dist/mnemonic.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mnemonic.mjs","sourceRoot":"","sources":["../src/mnemonic.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,wDAAqD;AAExE;;;;;GAKG;AACH,MAAM,UAAU,
|
|
1
|
+
{"version":3,"file":"mnemonic.mjs","sourceRoot":"","sources":["../src/mnemonic.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,wDAAqD;AAExE;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB,CAAC,oBAAgC;IAClE,MAAM,eAAe,GAAG,KAAK,CAAC,IAAI;IAChC,0EAA0E;IAC1E,iEAAiE;IACjE,oBAAoB;IACpB,IAAI,WAAW,CAAC,IAAI,UAAU,CAAC,oBAAoB,CAAC,CAAC,MAAM,CAAC,CAC7D,CAAC;IACF,OAAO,eAAe,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC3D,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,oBAAgC;IAC7D,OAAO,KAAK,CAAC,IAAI,CACf,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,mBAAmB,CAAC,oBAAoB,CAAC,CAAC,CACpE,CAAC;AACJ,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,mBAAmB,CAAC,QAAgB;IAClD,IAAI,QAAQ,KAAK,EAAE,EAAE,CAAC;QACpB,OAAO,IAAI,UAAU,EAAE,CAAC;IAC1B,CAAC;IAED,MAAM,eAAe,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;QACvD,MAAM,KAAK,GAAG,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACrC,IAAI,KAAK,KAAK,CAAC,CAAC,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CAAC,2BAA2B,IAAI,GAAG,CAAC,CAAC;QACtD,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC,CAAC,CAAC;IAEH,OAAO,IAAI,UAAU,CAAC,IAAI,WAAW,CAAC,eAAe,CAAC,CAAC,MAAM,CAAC,CAAC;AACjE,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,cAAc,CAAC,aAAyB;IACtD,OAAO,mBAAmB,CAAC,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC;AACtE,CAAC","sourcesContent":["import { wordlist } from '@metamask/scure-bip39/dist/wordlists/english';\n\n/**\n * Encodes a mnemonic as a string of words.\n *\n * @param mnemonicIndicesBytes - An array of bytes (16-bit unsigned integers) representing the indices of the words in the mnemonic.\n * @returns A string representing the mnemonic.\n */\nexport function encodeMnemonicWords(mnemonicIndicesBytes: Uint8Array): string {\n const mnemonicIndices = Array.from(\n // Create a new `Uint8Array` to ensure we have a proper view on the buffer\n // without having to worry about `byteOffset` and `byteLength` of\n // the inner buffer.\n new Uint16Array(new Uint8Array(mnemonicIndicesBytes).buffer),\n );\n return mnemonicIndices.map((i) => wordlist[i]).join(' ');\n}\n\n/**\n * Encodes a mnemonic as an array of bytes (UTF-8).\n *\n * @param mnemonicIndicesBytes - An array of bytes (16-bit unsigned integers) representing the indices of the words in the mnemonic.\n * @returns An array of bytes (UTF-8) representing the mnemonic.\n */\nexport function encodeMnemonic(mnemonicIndicesBytes: Uint8Array): number[] {\n return Array.from(\n new TextEncoder().encode(encodeMnemonicWords(mnemonicIndicesBytes)),\n );\n}\n\n/**\n * Decodes a string of mnemonic words as an array of bytes (16-bit unsigned\n * integers) representing the indices of the words in the mnemonic.\n *\n * @param mnemonic - A string representing the mnemonic.\n * @returns An array of bytes representing the indices of the words in the mnemonic.\n * @throws If the mnemonic contains a word that is not in the English BIP-39 wordlist.\n */\nexport function decodeMnemonicWords(mnemonic: string): Uint8Array {\n if (mnemonic === '') {\n return new Uint8Array();\n }\n\n const mnemonicIndices = mnemonic.split(' ').map((word) => {\n const index = wordlist.indexOf(word);\n if (index === -1) {\n throw new Error(`Invalid mnemonic word: \"${word}\"`);\n }\n return index;\n });\n\n return new Uint8Array(new Uint16Array(mnemonicIndices).buffer);\n}\n\n/**\n * Decodes an array of bytes (UTF-8) representing a mnemonic as an array of\n * bytes (16-bit unsigned integers) representing the indices of the words in\n * the mnemonic.\n *\n * @param mnemonicBytes - An array of bytes (UTF-8) representing the mnemonic.\n * @returns An array of bytes representing the indices of the words in the mnemonic.\n * @throws If the mnemonic contains a word that is not in the English BIP-39 wordlist.\n */\nexport function decodeMnemonic(mnemonicBytes: Uint8Array): Uint8Array {\n return decodeMnemonicWords(new TextDecoder().decode(mnemonicBytes));\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask/keyring-sdk",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"description": "MetaMask Keyring SDK",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"keyring",
|
|
@@ -68,11 +68,12 @@
|
|
|
68
68
|
"dependencies": {
|
|
69
69
|
"@ethereumjs/tx": "^5.4.0",
|
|
70
70
|
"@metamask/eth-sig-util": "^8.2.0",
|
|
71
|
-
"@metamask/keyring-api": "^
|
|
72
|
-
"@metamask/keyring-utils": "^
|
|
71
|
+
"@metamask/keyring-api": "^24.0.0",
|
|
72
|
+
"@metamask/keyring-utils": "^5.0.0",
|
|
73
73
|
"@metamask/scure-bip39": "^2.1.1",
|
|
74
74
|
"@metamask/superstruct": "^3.4.1",
|
|
75
75
|
"@metamask/utils": "^11.11.0",
|
|
76
|
+
"@noble/hashes": "^1.8.0",
|
|
76
77
|
"async-mutex": "^0.5.0",
|
|
77
78
|
"ethereum-cryptography": "^2.2.1",
|
|
78
79
|
"uuid": "^9.0.1"
|
|
@@ -103,7 +104,7 @@
|
|
|
103
104
|
"directory": "src"
|
|
104
105
|
},
|
|
105
106
|
"engines": {
|
|
106
|
-
"node": "
|
|
107
|
+
"node": ">=22"
|
|
107
108
|
},
|
|
108
109
|
"lavamoat": {
|
|
109
110
|
"allowScripts": {
|