@xyo-network/bip39 2.107.3 → 2.107.5
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/browser/index.cjs +155 -19
- package/dist/browser/index.cjs.map +1 -1
- package/dist/browser/index.js +124 -19
- package/dist/browser/index.js.map +1 -1
- package/dist/neutral/index.cjs +155 -19
- package/dist/neutral/index.cjs.map +1 -1
- package/dist/neutral/index.js +124 -19
- package/dist/neutral/index.js.map +1 -1
- package/dist/node/index.cjs +165 -19
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.js +124 -19
- package/dist/node/index.js.map +1 -1
- package/package.json +3 -3
package/dist/browser/index.js
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import assert 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 { randomBytes } from "@noble/hashes/utils";
|
|
7
|
+
import { utils as baseUtils } from "@scure/base";
|
|
8
|
+
|
|
9
|
+
// src/wordlists/czech.ts
|
|
10
|
+
var wordlist = `abdikace
|
|
2
11
|
abeceda
|
|
3
12
|
adresa
|
|
4
13
|
agrese
|
|
@@ -2045,8 +2054,10 @@ zvesela
|
|
|
2045
2054
|
zvon
|
|
2046
2055
|
zvrat
|
|
2047
2056
|
zvukovod
|
|
2048
|
-
zvyk`.split(
|
|
2049
|
-
|
|
2057
|
+
zvyk`.split("\n");
|
|
2058
|
+
|
|
2059
|
+
// src/wordlists/english.ts
|
|
2060
|
+
var wordlist2 = `abandon
|
|
2050
2061
|
ability
|
|
2051
2062
|
able
|
|
2052
2063
|
about
|
|
@@ -4093,8 +4104,10 @@ youth
|
|
|
4093
4104
|
zebra
|
|
4094
4105
|
zero
|
|
4095
4106
|
zone
|
|
4096
|
-
zoo`.split(
|
|
4097
|
-
|
|
4107
|
+
zoo`.split("\n");
|
|
4108
|
+
|
|
4109
|
+
// src/wordlists/french.ts
|
|
4110
|
+
var wordlist3 = `abaisser
|
|
4098
4111
|
abandon
|
|
4099
4112
|
abdiquer
|
|
4100
4113
|
abeille
|
|
@@ -6141,8 +6154,10 @@ yacht
|
|
|
6141
6154
|
ze\u0300bre
|
|
6142
6155
|
ze\u0301nith
|
|
6143
6156
|
zeste
|
|
6144
|
-
zoologie`.split(
|
|
6145
|
-
|
|
6157
|
+
zoologie`.split("\n");
|
|
6158
|
+
|
|
6159
|
+
// src/wordlists/italian.ts
|
|
6160
|
+
var wordlist4 = `abaco
|
|
6146
6161
|
abbaglio
|
|
6147
6162
|
abbinato
|
|
6148
6163
|
abete
|
|
@@ -8189,8 +8204,10 @@ zotico
|
|
|
8189
8204
|
zucchero
|
|
8190
8205
|
zufolo
|
|
8191
8206
|
zulu
|
|
8192
|
-
zuppa`.split(
|
|
8193
|
-
|
|
8207
|
+
zuppa`.split("\n");
|
|
8208
|
+
|
|
8209
|
+
// src/wordlists/japanese.ts
|
|
8210
|
+
var wordlist5 = `\u3042\u3044\u3053\u304F\u3057\u3093
|
|
8194
8211
|
\u3042\u3044\u3055\u3064
|
|
8195
8212
|
\u3042\u3044\u305F\u3099
|
|
8196
8213
|
\u3042\u304A\u305D\u3099\u3089
|
|
@@ -10237,8 +10254,10 @@ zuppa`.split(`
|
|
|
10237
10254
|
\u308F\u3057\u3099\u307E\u3057
|
|
10238
10255
|
\u308F\u3059\u308C\u3082\u306E
|
|
10239
10256
|
\u308F\u3089\u3046
|
|
10240
|
-
\u308F\u308C\u308B`.split(
|
|
10241
|
-
|
|
10257
|
+
\u308F\u308C\u308B`.split("\n");
|
|
10258
|
+
|
|
10259
|
+
// src/wordlists/korean.ts
|
|
10260
|
+
var wordlist6 = `\u1100\u1161\u1100\u1167\u11A8
|
|
10242
10261
|
\u1100\u1161\u1101\u1173\u11B7
|
|
10243
10262
|
\u1100\u1161\u1102\u1161\u11AB
|
|
10244
10263
|
\u1100\u1161\u1102\u1173\u11BC
|
|
@@ -12285,8 +12304,10 @@ zuppa`.split(`
|
|
|
12285
12304
|
\u1112\u1174\u1106\u1161\u11BC
|
|
12286
12305
|
\u1112\u1174\u1109\u1162\u11BC
|
|
12287
12306
|
\u1112\u1174\u11AB\u1109\u1162\u11A8
|
|
12288
|
-
\u1112\u1175\u11B7\u1101\u1165\u11BA`.split(
|
|
12289
|
-
|
|
12307
|
+
\u1112\u1175\u11B7\u1101\u1165\u11BA`.split("\n");
|
|
12308
|
+
|
|
12309
|
+
// src/wordlists/simplified-chinese.ts
|
|
12310
|
+
var wordlist7 = `\u7684
|
|
12290
12311
|
\u4E00
|
|
12291
12312
|
\u662F
|
|
12292
12313
|
\u5728
|
|
@@ -14333,8 +14354,10 @@ zuppa`.split(`
|
|
|
14333
14354
|
\u97E6
|
|
14334
14355
|
\u6028
|
|
14335
14356
|
\u77EE
|
|
14336
|
-
\u6B47`.split(
|
|
14337
|
-
|
|
14357
|
+
\u6B47`.split("\n");
|
|
14358
|
+
|
|
14359
|
+
// src/wordlists/spanish.ts
|
|
14360
|
+
var wordlist8 = `a\u0301baco
|
|
14338
14361
|
abdomen
|
|
14339
14362
|
abeja
|
|
14340
14363
|
abierto
|
|
@@ -16381,8 +16404,10 @@ zarza
|
|
|
16381
16404
|
zona
|
|
16382
16405
|
zorro
|
|
16383
16406
|
zumo
|
|
16384
|
-
zurdo`.split(
|
|
16385
|
-
|
|
16407
|
+
zurdo`.split("\n");
|
|
16408
|
+
|
|
16409
|
+
// src/wordlists/traditional-chinese.ts
|
|
16410
|
+
var wordlist9 = `\u7684
|
|
16386
16411
|
\u4E00
|
|
16387
16412
|
\u662F
|
|
16388
16413
|
\u5728
|
|
@@ -18429,7 +18454,87 @@ zurdo`.split(`
|
|
|
18429
18454
|
\u97CB
|
|
18430
18455
|
\u6028
|
|
18431
18456
|
\u77EE
|
|
18432
|
-
\u6B47`.split(
|
|
18433
|
-
|
|
18457
|
+
\u6B47`.split("\n");
|
|
18458
|
+
|
|
18459
|
+
// src/wordlists/index.ts
|
|
18460
|
+
var wordlists = {
|
|
18461
|
+
czech: wordlist,
|
|
18462
|
+
english: wordlist2,
|
|
18463
|
+
french: wordlist3,
|
|
18464
|
+
italian: wordlist4,
|
|
18465
|
+
japanese: wordlist5,
|
|
18466
|
+
korean: wordlist6,
|
|
18467
|
+
simplifiedChinese: wordlist7,
|
|
18468
|
+
spanish: wordlist8,
|
|
18469
|
+
traditionalChinese: wordlist9
|
|
18470
|
+
};
|
|
18471
|
+
|
|
18472
|
+
// src/index.ts
|
|
18473
|
+
var isJapanese = (wordlist10) => wordlist10[0] === "\u3042\u3044\u3053\u304F\u3057\u3093";
|
|
18474
|
+
function nfkd(str) {
|
|
18475
|
+
if (typeof str !== "string") throw new TypeError(`Invalid mnemonic type: ${typeof str}`);
|
|
18476
|
+
return str.normalize("NFKD");
|
|
18477
|
+
}
|
|
18478
|
+
function normalize(str) {
|
|
18479
|
+
const norm = nfkd(str);
|
|
18480
|
+
const words = norm.split(" ");
|
|
18481
|
+
if (![12, 15, 18, 21, 24].includes(words.length)) throw new Error("Invalid mnemonic");
|
|
18482
|
+
return { nfkd: norm, words };
|
|
18483
|
+
}
|
|
18484
|
+
function assertEntropy(entropy) {
|
|
18485
|
+
assert.bytes(entropy, 16, 20, 24, 28, 32);
|
|
18486
|
+
}
|
|
18487
|
+
function generateMnemonic(wordlist10, strength = 128) {
|
|
18488
|
+
assert.number(strength);
|
|
18489
|
+
if (strength % 32 !== 0 || strength > 256) throw new TypeError("Invalid entropy");
|
|
18490
|
+
return entropyToMnemonic(randomBytes(strength / 8), wordlist10);
|
|
18491
|
+
}
|
|
18492
|
+
var calcChecksum = (entropy) => {
|
|
18493
|
+
const bitsLeft = 8 - entropy.length / 4;
|
|
18494
|
+
return new Uint8Array([sha256(entropy)[0] >> bitsLeft << bitsLeft]);
|
|
18495
|
+
};
|
|
18496
|
+
function getCoder(wordlist10) {
|
|
18497
|
+
if (!Array.isArray(wordlist10) || wordlist10.length !== 2048 || typeof wordlist10[0] !== "string")
|
|
18498
|
+
throw new Error("Worlist: expected array of 2048 strings");
|
|
18499
|
+
for (const i of wordlist10) {
|
|
18500
|
+
if (typeof i !== "string") throw new Error(`Wordlist: non-string element: ${i}`);
|
|
18501
|
+
}
|
|
18502
|
+
return baseUtils.chain(baseUtils.checksum(1, calcChecksum), baseUtils.radix2(11, true), baseUtils.alphabet(wordlist10));
|
|
18503
|
+
}
|
|
18504
|
+
function mnemonicToEntropy(mnemonic, wordlist10) {
|
|
18505
|
+
const { words } = normalize(mnemonic);
|
|
18506
|
+
const entropy = getCoder(wordlist10).decode(words);
|
|
18507
|
+
assertEntropy(entropy);
|
|
18508
|
+
return entropy;
|
|
18509
|
+
}
|
|
18510
|
+
function entropyToMnemonic(entropy, wordlist10) {
|
|
18511
|
+
assertEntropy(entropy);
|
|
18512
|
+
const words = getCoder(wordlist10).encode(entropy);
|
|
18513
|
+
return words.join(isJapanese(wordlist10) ? "\u3000" : " ");
|
|
18514
|
+
}
|
|
18515
|
+
function validateMnemonic(mnemonic, wordlist10) {
|
|
18516
|
+
try {
|
|
18517
|
+
mnemonicToEntropy(mnemonic, wordlist10);
|
|
18518
|
+
} catch {
|
|
18519
|
+
return false;
|
|
18520
|
+
}
|
|
18521
|
+
return true;
|
|
18522
|
+
}
|
|
18523
|
+
var salt = (passphrase) => nfkd(`mnemonic${passphrase}`);
|
|
18524
|
+
function mnemonicToSeed(mnemonic, passphrase = "") {
|
|
18525
|
+
return pbkdf2Async(sha512, normalize(mnemonic).nfkd, salt(passphrase), { c: 2048, dkLen: 64 });
|
|
18526
|
+
}
|
|
18527
|
+
function mnemonicToSeedSync(mnemonic, passphrase = "") {
|
|
18528
|
+
return pbkdf2(sha512, normalize(mnemonic).nfkd, salt(passphrase), { c: 2048, dkLen: 64 });
|
|
18529
|
+
}
|
|
18530
|
+
export {
|
|
18531
|
+
entropyToMnemonic,
|
|
18532
|
+
generateMnemonic,
|
|
18533
|
+
mnemonicToEntropy,
|
|
18534
|
+
mnemonicToSeed,
|
|
18535
|
+
mnemonicToSeedSync,
|
|
18536
|
+
validateMnemonic,
|
|
18537
|
+
wordlists
|
|
18538
|
+
};
|
|
18434
18539
|
/*! scure-bip39 - MIT License (c) 2022 Patricio Palladino, Paul Miller (paulmillr.com) */
|
|
18435
18540
|
//# sourceMappingURL=index.js.map
|