@xyo-network/bip39 3.14.0 → 3.14.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/neutral/index.mjs +2 -79
- package/dist/neutral/index.mjs.map +1 -1
- package/dist/types/index.d.ts +2 -55
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +1 -6
- package/src/index.ts +1 -124
- package/dist/types/wordlists/index.d.ts +0 -13
- package/dist/types/wordlists/index.d.ts.map +0 -1
- package/src/wordlists/index.ts +0 -22
package/dist/neutral/index.mjs
CHANGED
|
@@ -1,83 +1,6 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
-
|
|
3
|
-
import { pbkdf2, pbkdf2Async } from "@noble/hashes/pbkdf2";
|
|
4
|
-
import { sha256 } from "@noble/hashes/sha256";
|
|
5
|
-
import { sha512 } from "@noble/hashes/sha512";
|
|
6
|
-
import { utils as baseUtils } from "@scure/base";
|
|
7
|
-
|
|
8
|
-
// src/wordlists/index.ts
|
|
9
|
-
import { wordlist as czech } from "@scure/bip39/wordlists/czech";
|
|
10
|
-
import { wordlist as english } from "@scure/bip39/wordlists/english";
|
|
11
|
-
import { wordlist as french } from "@scure/bip39/wordlists/french";
|
|
12
|
-
import { wordlist as italian } from "@scure/bip39/wordlists/italian";
|
|
13
|
-
import { wordlist as japanese } from "@scure/bip39/wordlists/japanese";
|
|
14
|
-
import { wordlist as korean } from "@scure/bip39/wordlists/korean";
|
|
15
|
-
import { wordlist as simplifiedChinese } from "@scure/bip39/wordlists/simplified-chinese";
|
|
16
|
-
import { wordlist as spanish } from "@scure/bip39/wordlists/spanish";
|
|
17
|
-
import { wordlist as traditionalChinese } from "@scure/bip39/wordlists/traditional-chinese";
|
|
18
|
-
var wordlists = {
|
|
19
|
-
czech,
|
|
20
|
-
english,
|
|
21
|
-
french,
|
|
22
|
-
italian,
|
|
23
|
-
japanese,
|
|
24
|
-
korean,
|
|
25
|
-
simplifiedChinese,
|
|
26
|
-
spanish,
|
|
27
|
-
traditionalChinese
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
// src/index.ts
|
|
31
|
-
var isJapanese = (wordlist) => wordlist[0] === "\u3042\u3044\u3053\u304F\u3057\u3093";
|
|
32
|
-
function nfkd(str) {
|
|
33
|
-
if (typeof str !== "string") throw new TypeError(`Invalid mnemonic type: ${typeof str}`);
|
|
34
|
-
return str.normalize("NFKD");
|
|
35
|
-
}
|
|
36
|
-
function normalize(str) {
|
|
37
|
-
const norm = nfkd(str);
|
|
38
|
-
const words = norm.split(" ");
|
|
39
|
-
if (![12, 15, 18, 21, 24].includes(words.length)) throw new Error("Invalid mnemonic");
|
|
40
|
-
return { nfkd: norm, words };
|
|
41
|
-
}
|
|
42
|
-
function assertEntropy(entropy) {
|
|
43
|
-
abytes(entropy, 16, 20, 24, 28, 32);
|
|
44
|
-
}
|
|
45
|
-
var calcChecksum = (entropy) => {
|
|
46
|
-
const bitsLeft = 8 - entropy.length / 4;
|
|
47
|
-
return new Uint8Array([sha256(entropy)[0] >> bitsLeft << bitsLeft]);
|
|
48
|
-
};
|
|
49
|
-
function getCoder(wordlist) {
|
|
50
|
-
if (!Array.isArray(wordlist) || wordlist.length !== 2048 || typeof wordlist[0] !== "string")
|
|
51
|
-
throw new Error("Wordlist: expected array of 2048 strings");
|
|
52
|
-
for (const i of wordlist) {
|
|
53
|
-
if (typeof i !== "string") throw new Error(`Wordlist: non-string element: ${i}`);
|
|
54
|
-
}
|
|
55
|
-
return baseUtils.chain(baseUtils.checksum(1, calcChecksum), baseUtils.radix2(11, true), baseUtils.alphabet(wordlist));
|
|
56
|
-
}
|
|
57
|
-
function mnemonicToEntropy(mnemonic, wordlist) {
|
|
58
|
-
const { words } = normalize(mnemonic);
|
|
59
|
-
const entropy = getCoder(wordlist).decode(words);
|
|
60
|
-
assertEntropy(entropy);
|
|
61
|
-
return entropy;
|
|
62
|
-
}
|
|
63
|
-
function entropyToMnemonic(entropy, wordlist) {
|
|
64
|
-
assertEntropy(entropy);
|
|
65
|
-
const words = getCoder(wordlist).encode(entropy);
|
|
66
|
-
return words.join(isJapanese(wordlist) ? "\u3000" : " ");
|
|
67
|
-
}
|
|
68
|
-
var salt = (passphrase) => nfkd(`mnemonic${passphrase}`);
|
|
69
|
-
function mnemonicToSeed(mnemonic, passphrase = "") {
|
|
70
|
-
return pbkdf2Async(sha512, normalize(mnemonic).nfkd, salt(passphrase), { c: 2048, dkLen: 64 });
|
|
71
|
-
}
|
|
72
|
-
function mnemonicToSeedSync(mnemonic, passphrase = "") {
|
|
73
|
-
return pbkdf2(sha512, normalize(mnemonic).nfkd, salt(passphrase), { c: 2048, dkLen: 64 });
|
|
74
|
-
}
|
|
2
|
+
var index_default = {};
|
|
75
3
|
export {
|
|
76
|
-
|
|
77
|
-
mnemonicToEntropy,
|
|
78
|
-
mnemonicToSeed,
|
|
79
|
-
mnemonicToSeedSync,
|
|
80
|
-
wordlists
|
|
4
|
+
index_default as default
|
|
81
5
|
};
|
|
82
|
-
/*! scure-bip39 - MIT License (c) 2022 Patricio Palladino, Paul Miller (paulmillr.com) */
|
|
83
6
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export default {}\n"],"mappings":";AAAA,IAAO,gBAAQ,CAAC;","names":[]}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,56 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* Reversible: Converts mnemonic string to raw entropy in form of byte array.
|
|
4
|
-
* @param mnemonic 12-24 words
|
|
5
|
-
* @param wordlist imported wordlist for specific language
|
|
6
|
-
* @example
|
|
7
|
-
* const mnem = 'legal winner thank year wave sausage worth useful legal winner thank yellow';
|
|
8
|
-
* mnemonicToEntropy(mnem, wordlist)
|
|
9
|
-
* // Produces
|
|
10
|
-
* new Uint8Array([
|
|
11
|
-
* 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f,
|
|
12
|
-
* 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f
|
|
13
|
-
* ])
|
|
14
|
-
*/
|
|
15
|
-
/** @deprecated use @scure/bip39 instead */
|
|
16
|
-
export declare function mnemonicToEntropy(mnemonic: string, wordlist: string[]): Uint8Array;
|
|
17
|
-
/**
|
|
18
|
-
* Reversible: Converts raw entropy in form of byte array to mnemonic string.
|
|
19
|
-
* @param entropy byte array
|
|
20
|
-
* @param wordlist imported wordlist for specific language
|
|
21
|
-
* @returns 12-24 words
|
|
22
|
-
* @example
|
|
23
|
-
* const ent = new Uint8Array([
|
|
24
|
-
* 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f,
|
|
25
|
-
* 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f
|
|
26
|
-
* ]);
|
|
27
|
-
* entropyToMnemonic(ent, wordlist);
|
|
28
|
-
* // 'legal winner thank year wave sausage worth useful legal winner thank yellow'
|
|
29
|
-
*/
|
|
30
|
-
/** @deprecated use @scure/bip39 instead */
|
|
31
|
-
export declare function entropyToMnemonic(entropy: Uint8Array, wordlist: string[]): string;
|
|
32
|
-
/**
|
|
33
|
-
* Irreversible: Uses KDF to derive 64 bytes of key data from mnemonic + optional password.
|
|
34
|
-
* @param mnemonic 12-24 words
|
|
35
|
-
* @param passphrase string that will additionally protect the key
|
|
36
|
-
* @returns 64 bytes of key data
|
|
37
|
-
* @example
|
|
38
|
-
* const mnem = 'legal winner thank year wave sausage worth useful legal winner thank yellow';
|
|
39
|
-
* await mnemonicToSeed(mnem, 'password');
|
|
40
|
-
* // new Uint8Array([...64 bytes])
|
|
41
|
-
*/
|
|
42
|
-
/** @deprecated use @scure/bip39 instead */
|
|
43
|
-
export declare function mnemonicToSeed(mnemonic: string, passphrase?: string): Promise<Uint8Array<ArrayBufferLike>>;
|
|
44
|
-
/**
|
|
45
|
-
* Irreversible: Uses KDF to derive 64 bytes of key data from mnemonic + optional password.
|
|
46
|
-
* @param mnemonic 12-24 words
|
|
47
|
-
* @param passphrase string that will additionally protect the key
|
|
48
|
-
* @returns 64 bytes of key data
|
|
49
|
-
* @example
|
|
50
|
-
* const mnem = 'legal winner thank year wave sausage worth useful legal winner thank yellow';
|
|
51
|
-
* mnemonicToSeedSync(mnem, 'password');
|
|
52
|
-
* // new Uint8Array([...64 bytes])
|
|
53
|
-
*/
|
|
54
|
-
/** @deprecated use @scure/bip39 instead */
|
|
55
|
-
export declare function mnemonicToSeedSync(mnemonic: string, passphrase?: string): Uint8Array<ArrayBufferLike>;
|
|
1
|
+
declare const _default: {};
|
|
2
|
+
export default _default;
|
|
56
3
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA,wBAAiB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xyo-network/bip39",
|
|
3
|
-
"version": "3.14.
|
|
3
|
+
"version": "3.14.1",
|
|
4
4
|
"description": "Primary SDK for using XYO Protocol 2.0",
|
|
5
5
|
"homepage": "https://xyo.network",
|
|
6
6
|
"bugs": {
|
|
@@ -28,11 +28,6 @@
|
|
|
28
28
|
},
|
|
29
29
|
"module": "dist/neutral/index.mjs",
|
|
30
30
|
"types": "dist/types/index.d.ts",
|
|
31
|
-
"dependencies": {
|
|
32
|
-
"@noble/hashes": "^1.8.0",
|
|
33
|
-
"@scure/base": "^1.2.5",
|
|
34
|
-
"@scure/bip39": "^1.6.0"
|
|
35
|
-
},
|
|
36
31
|
"devDependencies": {
|
|
37
32
|
"@xylabs/ts-scripts-yarn3": "^6.3.5",
|
|
38
33
|
"@xylabs/tsconfig": "^6.3.5",
|
package/src/index.ts
CHANGED
|
@@ -1,124 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { abytes } from '@noble/hashes/_assert'
|
|
3
|
-
import { pbkdf2, pbkdf2Async } from '@noble/hashes/pbkdf2'
|
|
4
|
-
import { sha256 } from '@noble/hashes/sha256'
|
|
5
|
-
import { sha512 } from '@noble/hashes/sha512'
|
|
6
|
-
import { utils as baseUtils } from '@scure/base'
|
|
7
|
-
|
|
8
|
-
export * from './wordlists/index.ts'
|
|
9
|
-
|
|
10
|
-
// Japanese wordlist
|
|
11
|
-
const isJapanese = (wordlist: string[]) => wordlist[0] === '\u3042\u3044\u3053\u304F\u3057\u3093'
|
|
12
|
-
|
|
13
|
-
// Normalization replaces equivalent sequences of characters
|
|
14
|
-
// so that any two texts that are equivalent will be reduced
|
|
15
|
-
// to the same sequence of code points, called the normal form of the original text.
|
|
16
|
-
function nfkd(str: string) {
|
|
17
|
-
if (typeof str !== 'string') throw new TypeError(`Invalid mnemonic type: ${typeof str}`)
|
|
18
|
-
return str.normalize('NFKD')
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function normalize(str: string) {
|
|
22
|
-
const norm = nfkd(str)
|
|
23
|
-
const words = norm.split(' ')
|
|
24
|
-
if (![12, 15, 18, 21, 24].includes(words.length)) throw new Error('Invalid mnemonic')
|
|
25
|
-
return { nfkd: norm, words }
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function assertEntropy(entropy: Uint8Array) {
|
|
29
|
-
abytes(entropy, 16, 20, 24, 28, 32)
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const calcChecksum = (entropy: Uint8Array) => {
|
|
33
|
-
// Checksum is ent.length/4 bits long
|
|
34
|
-
const bitsLeft = 8 - entropy.length / 4
|
|
35
|
-
// Zero rightmost "bitsLeft" bits in byte
|
|
36
|
-
// For example: bitsLeft=4 val=10111101 -> 10110000
|
|
37
|
-
return new Uint8Array([(sha256(entropy)[0] >> bitsLeft) << bitsLeft])
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function getCoder(wordlist: string[]) {
|
|
41
|
-
if (!Array.isArray(wordlist) || wordlist.length !== 2048 || typeof wordlist[0] !== 'string')
|
|
42
|
-
throw new Error('Wordlist: expected array of 2048 strings')
|
|
43
|
-
for (const i of wordlist) {
|
|
44
|
-
if (typeof i !== 'string') throw new Error(`Wordlist: non-string element: ${i}`)
|
|
45
|
-
}
|
|
46
|
-
return baseUtils.chain(baseUtils.checksum(1, calcChecksum), baseUtils.radix2(11, true), baseUtils.alphabet(wordlist))
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Reversible: Converts mnemonic string to raw entropy in form of byte array.
|
|
51
|
-
* @param mnemonic 12-24 words
|
|
52
|
-
* @param wordlist imported wordlist for specific language
|
|
53
|
-
* @example
|
|
54
|
-
* const mnem = 'legal winner thank year wave sausage worth useful legal winner thank yellow';
|
|
55
|
-
* mnemonicToEntropy(mnem, wordlist)
|
|
56
|
-
* // Produces
|
|
57
|
-
* new Uint8Array([
|
|
58
|
-
* 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f,
|
|
59
|
-
* 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f
|
|
60
|
-
* ])
|
|
61
|
-
*/
|
|
62
|
-
|
|
63
|
-
/** @deprecated use @scure/bip39 instead */
|
|
64
|
-
export function mnemonicToEntropy(mnemonic: string, wordlist: string[]): Uint8Array {
|
|
65
|
-
const { words } = normalize(mnemonic)
|
|
66
|
-
const entropy = getCoder(wordlist).decode(words)
|
|
67
|
-
assertEntropy(entropy)
|
|
68
|
-
return entropy
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Reversible: Converts raw entropy in form of byte array to mnemonic string.
|
|
73
|
-
* @param entropy byte array
|
|
74
|
-
* @param wordlist imported wordlist for specific language
|
|
75
|
-
* @returns 12-24 words
|
|
76
|
-
* @example
|
|
77
|
-
* const ent = new Uint8Array([
|
|
78
|
-
* 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f,
|
|
79
|
-
* 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f
|
|
80
|
-
* ]);
|
|
81
|
-
* entropyToMnemonic(ent, wordlist);
|
|
82
|
-
* // 'legal winner thank year wave sausage worth useful legal winner thank yellow'
|
|
83
|
-
*/
|
|
84
|
-
|
|
85
|
-
/** @deprecated use @scure/bip39 instead */
|
|
86
|
-
export function entropyToMnemonic(entropy: Uint8Array, wordlist: string[]): string {
|
|
87
|
-
assertEntropy(entropy)
|
|
88
|
-
const words = getCoder(wordlist).encode(entropy)
|
|
89
|
-
return words.join(isJapanese(wordlist) ? '\u3000' : ' ')
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
const salt = (passphrase: string) => nfkd(`mnemonic${passphrase}`)
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Irreversible: Uses KDF to derive 64 bytes of key data from mnemonic + optional password.
|
|
96
|
-
* @param mnemonic 12-24 words
|
|
97
|
-
* @param passphrase string that will additionally protect the key
|
|
98
|
-
* @returns 64 bytes of key data
|
|
99
|
-
* @example
|
|
100
|
-
* const mnem = 'legal winner thank year wave sausage worth useful legal winner thank yellow';
|
|
101
|
-
* await mnemonicToSeed(mnem, 'password');
|
|
102
|
-
* // new Uint8Array([...64 bytes])
|
|
103
|
-
*/
|
|
104
|
-
|
|
105
|
-
/** @deprecated use @scure/bip39 instead */
|
|
106
|
-
export function mnemonicToSeed(mnemonic: string, passphrase = '') {
|
|
107
|
-
return pbkdf2Async(sha512, normalize(mnemonic).nfkd, salt(passphrase), { c: 2048, dkLen: 64 })
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* Irreversible: Uses KDF to derive 64 bytes of key data from mnemonic + optional password.
|
|
112
|
-
* @param mnemonic 12-24 words
|
|
113
|
-
* @param passphrase string that will additionally protect the key
|
|
114
|
-
* @returns 64 bytes of key data
|
|
115
|
-
* @example
|
|
116
|
-
* const mnem = 'legal winner thank year wave sausage worth useful legal winner thank yellow';
|
|
117
|
-
* mnemonicToSeedSync(mnem, 'password');
|
|
118
|
-
* // new Uint8Array([...64 bytes])
|
|
119
|
-
*/
|
|
120
|
-
|
|
121
|
-
/** @deprecated use @scure/bip39 instead */
|
|
122
|
-
export function mnemonicToSeedSync(mnemonic: string, passphrase = '') {
|
|
123
|
-
return pbkdf2(sha512, normalize(mnemonic).nfkd, salt(passphrase), { c: 2048, dkLen: 64 })
|
|
124
|
-
}
|
|
1
|
+
export default {}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/** @deprecated use @scure/bip39 instead */
|
|
2
|
-
export declare const wordlists: {
|
|
3
|
-
czech: string[];
|
|
4
|
-
english: string[];
|
|
5
|
-
french: string[];
|
|
6
|
-
italian: string[];
|
|
7
|
-
japanese: string[];
|
|
8
|
-
korean: string[];
|
|
9
|
-
simplifiedChinese: string[];
|
|
10
|
-
spanish: string[];
|
|
11
|
-
traditionalChinese: string[];
|
|
12
|
-
};
|
|
13
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/wordlists/index.ts"],"names":[],"mappings":"AAUA,2CAA2C;AAC3C,eAAO,MAAM,SAAS;;;;;;;;;;CAUrB,CAAA"}
|
package/src/wordlists/index.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { wordlist as czech } from '@scure/bip39/wordlists/czech'
|
|
2
|
-
import { wordlist as english } from '@scure/bip39/wordlists/english'
|
|
3
|
-
import { wordlist as french } from '@scure/bip39/wordlists/french'
|
|
4
|
-
import { wordlist as italian } from '@scure/bip39/wordlists/italian'
|
|
5
|
-
import { wordlist as japanese } from '@scure/bip39/wordlists/japanese'
|
|
6
|
-
import { wordlist as korean } from '@scure/bip39/wordlists/korean'
|
|
7
|
-
import { wordlist as simplifiedChinese } from '@scure/bip39/wordlists/simplified-chinese'
|
|
8
|
-
import { wordlist as spanish } from '@scure/bip39/wordlists/spanish'
|
|
9
|
-
import { wordlist as traditionalChinese } from '@scure/bip39/wordlists/traditional-chinese'
|
|
10
|
-
|
|
11
|
-
/** @deprecated use @scure/bip39 instead */
|
|
12
|
-
export const wordlists = {
|
|
13
|
-
czech,
|
|
14
|
-
english,
|
|
15
|
-
french,
|
|
16
|
-
italian,
|
|
17
|
-
japanese,
|
|
18
|
-
korean,
|
|
19
|
-
simplifiedChinese,
|
|
20
|
-
spanish,
|
|
21
|
-
traditionalChinese,
|
|
22
|
-
}
|