@rabby-wallet/eth-hd-keyring 4.3.3-1 → 4.3.3-3
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/index.js +32 -42
- package/index.ts +2 -3
- package/package.json +6 -3
package/dist/index.js
CHANGED
|
@@ -45,6 +45,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
45
45
|
mod
|
|
46
46
|
));
|
|
47
47
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
48
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
48
49
|
var __async = (__this, __arguments, generator) => {
|
|
49
50
|
return new Promise((resolve, reject) => {
|
|
50
51
|
var fulfilled = (value) => {
|
|
@@ -99,38 +100,20 @@ var require_slip39_helper = __commonJS({
|
|
|
99
100
|
var ROUND_COUNT = 4;
|
|
100
101
|
var DIGEST_INDEX = 254;
|
|
101
102
|
var SECRET_INDEX = 255;
|
|
102
|
-
|
|
103
|
+
var slip39EncodeHex = function(str) {
|
|
103
104
|
let bytes = [];
|
|
104
|
-
for (let i = 0; i <
|
|
105
|
-
bytes.push(
|
|
105
|
+
for (let i = 0; i < str.length; ++i) {
|
|
106
|
+
bytes.push(str.charCodeAt(i));
|
|
106
107
|
}
|
|
107
108
|
return bytes;
|
|
108
109
|
};
|
|
109
|
-
|
|
110
|
-
let
|
|
111
|
-
const
|
|
112
|
-
for (let i = 0; i < hex.length; i++) {
|
|
113
|
-
str.push(String.fromCharCode(hex[i]));
|
|
114
|
-
}
|
|
115
|
-
return str.toString().replace(/,/g, "");
|
|
116
|
-
};
|
|
117
|
-
Array.prototype.slip39Generate = function(m, v = (_) => _) {
|
|
118
|
-
let n = m || this.length;
|
|
110
|
+
var slip39Generate = function(m, v = (_) => _) {
|
|
111
|
+
let n = m;
|
|
112
|
+
const arr = [];
|
|
119
113
|
for (let i = 0; i < n; i++) {
|
|
120
|
-
|
|
114
|
+
arr[i] = v(i);
|
|
121
115
|
}
|
|
122
|
-
return
|
|
123
|
-
};
|
|
124
|
-
Array.prototype.toHexString = function() {
|
|
125
|
-
return Array.prototype.map.call(this, function(byte) {
|
|
126
|
-
return ("0" + (byte & 255).toString(16)).slice(-2);
|
|
127
|
-
}).join("");
|
|
128
|
-
};
|
|
129
|
-
Array.prototype.toByteArray = function(hexString) {
|
|
130
|
-
for (let i = 0; i < hexString.length; i = i + 2) {
|
|
131
|
-
this.push(parseInt(hexString.substr(i, 2), 16));
|
|
132
|
-
}
|
|
133
|
-
return this;
|
|
116
|
+
return arr;
|
|
134
117
|
};
|
|
135
118
|
var BIGINT_WORD_BITS = BigInt(8);
|
|
136
119
|
function decodeBigInt(bytes) {
|
|
@@ -196,9 +179,9 @@ var require_slip39_helper = __commonJS({
|
|
|
196
179
|
}
|
|
197
180
|
let IL = masterSecret.slice().slice(0, masterSecret.length / 2);
|
|
198
181
|
let IR = masterSecret.slice().slice(masterSecret.length / 2);
|
|
199
|
-
const pwd =
|
|
182
|
+
const pwd = slip39EncodeHex(passphrase);
|
|
200
183
|
const salt = getSalt(identifier, extendableBackupFlag);
|
|
201
|
-
let range =
|
|
184
|
+
let range = slip39Generate(ROUND_COUNT);
|
|
202
185
|
range = encrypt ? range : range.reverse();
|
|
203
186
|
range.forEach((round) => {
|
|
204
187
|
const f = roundFunction(round, pwd, iterationExponent, salt, IR);
|
|
@@ -232,7 +215,7 @@ var require_slip39_helper = __commonJS({
|
|
|
232
215
|
);
|
|
233
216
|
}
|
|
234
217
|
if (threshold === 1) {
|
|
235
|
-
return
|
|
218
|
+
return slip39Generate(shareCount, () => sharedSecret);
|
|
236
219
|
}
|
|
237
220
|
const randomShareCount = threshold - 2;
|
|
238
221
|
const randomPart = randomBytes(sharedSecret.length - DIGEST_LENGTH);
|
|
@@ -240,7 +223,7 @@ var require_slip39_helper = __commonJS({
|
|
|
240
223
|
let baseShares = /* @__PURE__ */ new Map();
|
|
241
224
|
let shares = [];
|
|
242
225
|
if (randomShareCount) {
|
|
243
|
-
shares =
|
|
226
|
+
shares = slip39Generate(
|
|
244
227
|
randomShareCount,
|
|
245
228
|
() => randomBytes(sharedSecret.length)
|
|
246
229
|
);
|
|
@@ -269,13 +252,13 @@ var require_slip39_helper = __commonJS({
|
|
|
269
252
|
`Invalid padding in mnemonic or insufficient length of mnemonics (${a.length} or ${b.length})`
|
|
270
253
|
);
|
|
271
254
|
}
|
|
272
|
-
return
|
|
255
|
+
return slip39Generate(a.length, (i) => a[i] ^ b[i]);
|
|
273
256
|
}
|
|
274
257
|
function getSalt(identifier, extendableBackupFlag) {
|
|
275
258
|
if (extendableBackupFlag) {
|
|
276
259
|
return [];
|
|
277
260
|
} else {
|
|
278
|
-
const salt =
|
|
261
|
+
const salt = slip39EncodeHex(CUSTOMIZATION_STRING_NON_EXTENDABLE);
|
|
279
262
|
return salt.concat(identifier);
|
|
280
263
|
}
|
|
281
264
|
}
|
|
@@ -299,7 +282,7 @@ var require_slip39_helper = __commonJS({
|
|
|
299
282
|
shares.forEach((v, k) => {
|
|
300
283
|
logProd = logProd + LOG_TABLE[k ^ x];
|
|
301
284
|
});
|
|
302
|
-
let results =
|
|
285
|
+
let results = slip39Generate(
|
|
303
286
|
sharesValueLengths.values().next().value,
|
|
304
287
|
() => 0
|
|
305
288
|
);
|
|
@@ -348,14 +331,14 @@ var require_slip39_helper = __commonJS({
|
|
|
348
331
|
return extendableBackupFlag ? CUSTOMIZATION_STRING_EXTENDABLE : CUSTOMIZATION_STRING_NON_EXTENDABLE;
|
|
349
332
|
}
|
|
350
333
|
function rs1024CreateChecksum(data, extendableBackupFlag) {
|
|
351
|
-
const values = get_customization_string(extendableBackupFlag)
|
|
334
|
+
const values = slip39EncodeHex(get_customization_string(extendableBackupFlag)).concat(data).concat(slip39Generate(CHECKSUM_WORDS_LENGTH, () => 0));
|
|
352
335
|
const polymod = rs1024Polymod(values) ^ 1;
|
|
353
|
-
const result =
|
|
336
|
+
const result = slip39Generate(CHECKSUM_WORDS_LENGTH, (i) => polymod >> 10 * i & 1023).reverse();
|
|
354
337
|
return result;
|
|
355
338
|
}
|
|
356
339
|
function rs1024VerifyChecksum(data, extendableBackupFlag) {
|
|
357
340
|
return rs1024Polymod(
|
|
358
|
-
get_customization_string(extendableBackupFlag)
|
|
341
|
+
slip39EncodeHex(get_customization_string(extendableBackupFlag)).concat(data)
|
|
359
342
|
) === 1;
|
|
360
343
|
}
|
|
361
344
|
function intFromIndices(indices) {
|
|
@@ -368,7 +351,7 @@ var require_slip39_helper = __commonJS({
|
|
|
368
351
|
}
|
|
369
352
|
function intToIndices(value, length, bits) {
|
|
370
353
|
const mask = BigInt((1 << bits) - 1);
|
|
371
|
-
const result =
|
|
354
|
+
const result = slip39Generate(
|
|
372
355
|
length,
|
|
373
356
|
(i) => parseInt(value >> BigInt(i) * BigInt(bits) & mask, 10)
|
|
374
357
|
);
|
|
@@ -2180,7 +2163,9 @@ var require_slip39_helper = __commonJS({
|
|
|
2180
2163
|
combineMnemonics,
|
|
2181
2164
|
crypt,
|
|
2182
2165
|
bitsToBytes,
|
|
2183
|
-
WORD_LIST
|
|
2166
|
+
WORD_LIST,
|
|
2167
|
+
decodeMnemonics,
|
|
2168
|
+
decodeMnemonic
|
|
2184
2169
|
};
|
|
2185
2170
|
}
|
|
2186
2171
|
});
|
|
@@ -2207,7 +2192,7 @@ var require_slip39 = __commonJS({
|
|
|
2207
2192
|
return result;
|
|
2208
2193
|
}
|
|
2209
2194
|
};
|
|
2210
|
-
var
|
|
2195
|
+
var _Slip39 = class _Slip39 {
|
|
2211
2196
|
constructor({
|
|
2212
2197
|
iterationExponent = 0,
|
|
2213
2198
|
extendableBackupFlag = 0,
|
|
@@ -2364,6 +2349,10 @@ var require_slip39 = __commonJS({
|
|
|
2364
2349
|
return result;
|
|
2365
2350
|
}
|
|
2366
2351
|
};
|
|
2352
|
+
__publicField(_Slip39, "decodeMnemonics", slipHelper.decodeMnemonics);
|
|
2353
|
+
__publicField(_Slip39, "decodeMnemonic", slipHelper.decodeMnemonic);
|
|
2354
|
+
__publicField(_Slip39, "combineMnemonics", slipHelper.combineMnemonics);
|
|
2355
|
+
var Slip39 = _Slip39;
|
|
2367
2356
|
exports2 = module2.exports = Slip39;
|
|
2368
2357
|
}
|
|
2369
2358
|
});
|
|
@@ -2429,6 +2418,7 @@ var _HdKeyring = class _HdKeyring extends import_eth_simple_keyring.default {
|
|
|
2429
2418
|
this.deserialize(opts);
|
|
2430
2419
|
}
|
|
2431
2420
|
serialize() {
|
|
2421
|
+
var _a;
|
|
2432
2422
|
return Promise.resolve({
|
|
2433
2423
|
mnemonic: this.mnemonic,
|
|
2434
2424
|
/**
|
|
@@ -2437,7 +2427,7 @@ var _HdKeyring = class _HdKeyring extends import_eth_simple_keyring.default {
|
|
|
2437
2427
|
activeIndexes: this.activeIndexes,
|
|
2438
2428
|
hdPath: this.hdPath,
|
|
2439
2429
|
byImport: this.byImport,
|
|
2440
|
-
hasBackup: this.hasBackup,
|
|
2430
|
+
hasBackup: (_a = this.hasBackup) != null ? _a : true,
|
|
2441
2431
|
index: this.index,
|
|
2442
2432
|
needPassphrase: this.needPassphrase,
|
|
2443
2433
|
accounts: this.accounts,
|
|
@@ -2447,12 +2437,12 @@ var _HdKeyring = class _HdKeyring extends import_eth_simple_keyring.default {
|
|
|
2447
2437
|
});
|
|
2448
2438
|
}
|
|
2449
2439
|
deserialize(opts = {}) {
|
|
2440
|
+
var _a;
|
|
2450
2441
|
this.wallets = [];
|
|
2451
2442
|
this.mnemonic = null;
|
|
2452
2443
|
this.hdPath = opts.hdPath || HD_PATH_BASE["BIP44" /* BIP44 */];
|
|
2453
2444
|
this.byImport = !!opts.byImport;
|
|
2454
|
-
this.hasBackup = opts.hasBackup;
|
|
2455
|
-
console.log("opts.index", opts);
|
|
2445
|
+
this.hasBackup = (_a = opts.hasBackup) != null ? _a : true;
|
|
2456
2446
|
this.index = opts.index || 0;
|
|
2457
2447
|
this.needPassphrase = opts.needPassphrase || !!opts.passphrase;
|
|
2458
2448
|
this.passphrase = opts.passphrase;
|
package/index.ts
CHANGED
|
@@ -96,7 +96,7 @@ class HdKeyring extends SimpleKeyring {
|
|
|
96
96
|
activeIndexes: this.activeIndexes,
|
|
97
97
|
hdPath: this.hdPath,
|
|
98
98
|
byImport: this.byImport,
|
|
99
|
-
hasBackup: this.hasBackup,
|
|
99
|
+
hasBackup: this.hasBackup ?? true,
|
|
100
100
|
index: this.index,
|
|
101
101
|
needPassphrase: this.needPassphrase,
|
|
102
102
|
accounts: this.accounts,
|
|
@@ -111,8 +111,7 @@ class HdKeyring extends SimpleKeyring {
|
|
|
111
111
|
this.mnemonic = null;
|
|
112
112
|
this.hdPath = opts.hdPath || HD_PATH_BASE[HDPathType.BIP44];
|
|
113
113
|
this.byImport = !!opts.byImport;
|
|
114
|
-
this.hasBackup = opts.hasBackup;
|
|
115
|
-
console.log('opts.index', opts);
|
|
114
|
+
this.hasBackup = opts.hasBackup ?? true;
|
|
116
115
|
this.index = opts.index || 0;
|
|
117
116
|
this.needPassphrase = opts.needPassphrase || !!opts.passphrase;
|
|
118
117
|
this.passphrase = opts.passphrase;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rabby-wallet/eth-hd-keyring",
|
|
3
|
-
"version": "4.3.3-
|
|
3
|
+
"version": "4.3.3-3",
|
|
4
4
|
"description": "A simple standard interface for a seed phrase generated set of Ethereum accounts.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ethereum",
|
|
@@ -24,7 +24,8 @@
|
|
|
24
24
|
"lint:misc": "prettier '**/*.json' '**/*.md' '!CHANGELOG.md' '**/*.yml' --ignore-path .gitignore",
|
|
25
25
|
"lint": "yarn lint:eslint && yarn lint:misc --check",
|
|
26
26
|
"lint:fix": "yarn lint:eslint --fix && yarn lint:misc --write",
|
|
27
|
-
"test": "yarn build && mocha"
|
|
27
|
+
"test": "yarn build && mocha",
|
|
28
|
+
"postinstall": "patch-package"
|
|
28
29
|
},
|
|
29
30
|
"dependencies": {
|
|
30
31
|
"@ethereumjs/util": "^9.0.0",
|
|
@@ -64,8 +65,10 @@
|
|
|
64
65
|
"lavamoat": {
|
|
65
66
|
"allowScripts": {
|
|
66
67
|
"@lavamoat/preinstall-always-fail": false,
|
|
68
|
+
"@rabby-wallet/eth-hd-keyring": true,
|
|
67
69
|
"keccak": false,
|
|
68
|
-
"secp256k1": false
|
|
70
|
+
"secp256k1": false,
|
|
71
|
+
"esbuild": false
|
|
69
72
|
}
|
|
70
73
|
},
|
|
71
74
|
"tsup": {
|