@rabby-wallet/eth-hd-keyring 4.3.2 → 4.3.3-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/index.d.ts CHANGED
@@ -15,6 +15,7 @@ interface DeserializeOption {
15
15
  mnemonic: string;
16
16
  activeIndexes?: number[];
17
17
  byImport?: boolean;
18
+ hasBackup?: boolean;
18
19
  index?: number;
19
20
  passphrase?: string;
20
21
  needPassphrase?: boolean;
@@ -41,6 +42,7 @@ declare class HdKeyring extends SimpleKeyring {
41
42
  page: number;
42
43
  perPage: number;
43
44
  byImport: boolean;
45
+ hasBackup?: boolean;
44
46
  publicKey: string;
45
47
  needPassphrase: boolean;
46
48
  accounts: string[];
@@ -56,6 +58,7 @@ declare class HdKeyring extends SimpleKeyring {
56
58
  activeIndexes: number[];
57
59
  hdPath: string;
58
60
  byImport: boolean;
61
+ hasBackup: boolean;
59
62
  index: number;
60
63
  needPassphrase: boolean;
61
64
  accounts: string[];
package/dist/index.js CHANGED
@@ -45,7 +45,6 @@ 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);
49
48
  var __async = (__this, __arguments, generator) => {
50
49
  return new Promise((resolve, reject) => {
51
50
  var fulfilled = (value) => {
@@ -100,20 +99,38 @@ var require_slip39_helper = __commonJS({
100
99
  var ROUND_COUNT = 4;
101
100
  var DIGEST_INDEX = 254;
102
101
  var SECRET_INDEX = 255;
103
- var slip39EncodeHex = function(str) {
102
+ String.prototype.slip39EncodeHex = function() {
104
103
  let bytes = [];
105
- for (let i = 0; i < str.length; ++i) {
106
- bytes.push(str.charCodeAt(i));
104
+ for (let i = 0; i < this.length; ++i) {
105
+ bytes.push(this.charCodeAt(i));
107
106
  }
108
107
  return bytes;
109
108
  };
110
- var slip39Generate = function(m, v = (_) => _) {
111
- let n = m;
112
- const arr = [];
109
+ Array.prototype.slip39DecodeHex = function() {
110
+ let str = [];
111
+ const hex = this.toString().split(",");
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;
113
119
  for (let i = 0; i < n; i++) {
114
- arr[i] = v(i);
120
+ this[i] = v(i);
121
+ }
122
+ return this;
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));
115
132
  }
116
- return arr;
133
+ return this;
117
134
  };
118
135
  var BIGINT_WORD_BITS = BigInt(8);
119
136
  function decodeBigInt(bytes) {
@@ -179,9 +196,9 @@ var require_slip39_helper = __commonJS({
179
196
  }
180
197
  let IL = masterSecret.slice().slice(0, masterSecret.length / 2);
181
198
  let IR = masterSecret.slice().slice(masterSecret.length / 2);
182
- const pwd = slip39EncodeHex(passphrase);
199
+ const pwd = passphrase.slip39EncodeHex();
183
200
  const salt = getSalt(identifier, extendableBackupFlag);
184
- let range = slip39Generate(ROUND_COUNT);
201
+ let range = Array().slip39Generate(ROUND_COUNT);
185
202
  range = encrypt ? range : range.reverse();
186
203
  range.forEach((round) => {
187
204
  const f = roundFunction(round, pwd, iterationExponent, salt, IR);
@@ -215,7 +232,7 @@ var require_slip39_helper = __commonJS({
215
232
  );
216
233
  }
217
234
  if (threshold === 1) {
218
- return slip39Generate(shareCount, () => sharedSecret);
235
+ return Array().slip39Generate(shareCount, () => sharedSecret);
219
236
  }
220
237
  const randomShareCount = threshold - 2;
221
238
  const randomPart = randomBytes(sharedSecret.length - DIGEST_LENGTH);
@@ -223,7 +240,7 @@ var require_slip39_helper = __commonJS({
223
240
  let baseShares = /* @__PURE__ */ new Map();
224
241
  let shares = [];
225
242
  if (randomShareCount) {
226
- shares = slip39Generate(
243
+ shares = Array().slip39Generate(
227
244
  randomShareCount,
228
245
  () => randomBytes(sharedSecret.length)
229
246
  );
@@ -252,13 +269,13 @@ var require_slip39_helper = __commonJS({
252
269
  `Invalid padding in mnemonic or insufficient length of mnemonics (${a.length} or ${b.length})`
253
270
  );
254
271
  }
255
- return slip39Generate(a.length, (i) => a[i] ^ b[i]);
272
+ return Array().slip39Generate(a.length, (i) => a[i] ^ b[i]);
256
273
  }
257
274
  function getSalt(identifier, extendableBackupFlag) {
258
275
  if (extendableBackupFlag) {
259
276
  return [];
260
277
  } else {
261
- const salt = slip39EncodeHex(CUSTOMIZATION_STRING_NON_EXTENDABLE);
278
+ const salt = CUSTOMIZATION_STRING_NON_EXTENDABLE.slip39EncodeHex();
262
279
  return salt.concat(identifier);
263
280
  }
264
281
  }
@@ -282,7 +299,7 @@ var require_slip39_helper = __commonJS({
282
299
  shares.forEach((v, k) => {
283
300
  logProd = logProd + LOG_TABLE[k ^ x];
284
301
  });
285
- let results = slip39Generate(
302
+ let results = Array().slip39Generate(
286
303
  sharesValueLengths.values().next().value,
287
304
  () => 0
288
305
  );
@@ -331,14 +348,14 @@ var require_slip39_helper = __commonJS({
331
348
  return extendableBackupFlag ? CUSTOMIZATION_STRING_EXTENDABLE : CUSTOMIZATION_STRING_NON_EXTENDABLE;
332
349
  }
333
350
  function rs1024CreateChecksum(data, extendableBackupFlag) {
334
- const values = slip39EncodeHex(get_customization_string(extendableBackupFlag)).concat(data).concat(slip39Generate(CHECKSUM_WORDS_LENGTH, () => 0));
351
+ const values = get_customization_string(extendableBackupFlag).slip39EncodeHex().concat(data).concat(Array().slip39Generate(CHECKSUM_WORDS_LENGTH, () => 0));
335
352
  const polymod = rs1024Polymod(values) ^ 1;
336
- const result = slip39Generate(CHECKSUM_WORDS_LENGTH, (i) => polymod >> 10 * i & 1023).reverse();
353
+ const result = Array().slip39Generate(CHECKSUM_WORDS_LENGTH, (i) => polymod >> 10 * i & 1023).reverse();
337
354
  return result;
338
355
  }
339
356
  function rs1024VerifyChecksum(data, extendableBackupFlag) {
340
357
  return rs1024Polymod(
341
- slip39EncodeHex(get_customization_string(extendableBackupFlag)).concat(data)
358
+ get_customization_string(extendableBackupFlag).slip39EncodeHex().concat(data)
342
359
  ) === 1;
343
360
  }
344
361
  function intFromIndices(indices) {
@@ -351,7 +368,7 @@ var require_slip39_helper = __commonJS({
351
368
  }
352
369
  function intToIndices(value, length, bits) {
353
370
  const mask = BigInt((1 << bits) - 1);
354
- const result = slip39Generate(
371
+ const result = Array().slip39Generate(
355
372
  length,
356
373
  (i) => parseInt(value >> BigInt(i) * BigInt(bits) & mask, 10)
357
374
  );
@@ -2163,9 +2180,7 @@ var require_slip39_helper = __commonJS({
2163
2180
  combineMnemonics,
2164
2181
  crypt,
2165
2182
  bitsToBytes,
2166
- WORD_LIST,
2167
- decodeMnemonics,
2168
- decodeMnemonic
2183
+ WORD_LIST
2169
2184
  };
2170
2185
  }
2171
2186
  });
@@ -2192,7 +2207,7 @@ var require_slip39 = __commonJS({
2192
2207
  return result;
2193
2208
  }
2194
2209
  };
2195
- var _Slip39 = class _Slip39 {
2210
+ var Slip39 = class _Slip39 {
2196
2211
  constructor({
2197
2212
  iterationExponent = 0,
2198
2213
  extendableBackupFlag = 0,
@@ -2349,10 +2364,6 @@ var require_slip39 = __commonJS({
2349
2364
  return result;
2350
2365
  }
2351
2366
  };
2352
- __publicField(_Slip39, "decodeMnemonics", slipHelper.decodeMnemonics);
2353
- __publicField(_Slip39, "decodeMnemonic", slipHelper.decodeMnemonic);
2354
- __publicField(_Slip39, "combineMnemonics", slipHelper.combineMnemonics);
2355
- var Slip39 = _Slip39;
2356
2367
  exports2 = module2.exports = Slip39;
2357
2368
  }
2358
2369
  });
@@ -2426,6 +2437,7 @@ var _HdKeyring = class _HdKeyring extends import_eth_simple_keyring.default {
2426
2437
  activeIndexes: this.activeIndexes,
2427
2438
  hdPath: this.hdPath,
2428
2439
  byImport: this.byImport,
2440
+ hasBackup: this.hasBackup,
2429
2441
  index: this.index,
2430
2442
  needPassphrase: this.needPassphrase,
2431
2443
  accounts: this.accounts,
@@ -2439,6 +2451,8 @@ var _HdKeyring = class _HdKeyring extends import_eth_simple_keyring.default {
2439
2451
  this.mnemonic = null;
2440
2452
  this.hdPath = opts.hdPath || HD_PATH_BASE["BIP44" /* BIP44 */];
2441
2453
  this.byImport = !!opts.byImport;
2454
+ this.hasBackup = opts.hasBackup;
2455
+ console.log("opts.index", opts);
2442
2456
  this.index = opts.index || 0;
2443
2457
  this.needPassphrase = opts.needPassphrase || !!opts.passphrase;
2444
2458
  this.passphrase = opts.passphrase;
package/index.ts CHANGED
@@ -43,6 +43,7 @@ interface DeserializeOption {
43
43
  mnemonic: string;
44
44
  activeIndexes?: number[];
45
45
  byImport?: boolean;
46
+ hasBackup?: boolean;
46
47
  index?: number;
47
48
  passphrase?: string;
48
49
  needPassphrase?: boolean;
@@ -72,6 +73,7 @@ class HdKeyring extends SimpleKeyring {
72
73
  page = 0;
73
74
  perPage = 5;
74
75
  byImport = false;
76
+ hasBackup?: boolean;
75
77
  publicKey: string = '';
76
78
  needPassphrase = false;
77
79
  accounts: string[] = [];
@@ -94,6 +96,7 @@ class HdKeyring extends SimpleKeyring {
94
96
  activeIndexes: this.activeIndexes,
95
97
  hdPath: this.hdPath,
96
98
  byImport: this.byImport,
99
+ hasBackup: this.hasBackup,
97
100
  index: this.index,
98
101
  needPassphrase: this.needPassphrase,
99
102
  accounts: this.accounts,
@@ -108,6 +111,8 @@ class HdKeyring extends SimpleKeyring {
108
111
  this.mnemonic = null;
109
112
  this.hdPath = opts.hdPath || HD_PATH_BASE[HDPathType.BIP44];
110
113
  this.byImport = !!opts.byImport;
114
+ this.hasBackup = opts.hasBackup;
115
+ console.log('opts.index', opts);
111
116
  this.index = opts.index || 0;
112
117
  this.needPassphrase = opts.needPassphrase || !!opts.passphrase;
113
118
  this.passphrase = opts.passphrase;
@@ -115,7 +120,6 @@ class HdKeyring extends SimpleKeyring {
115
120
  this.accountDetails = opts.accountDetails || {};
116
121
  this.publicKey = opts.publicKey || '';
117
122
  this.isSlip39 = opts.isSlip39 || false;
118
-
119
123
  if (opts.mnemonic) {
120
124
  this.mnemonic = opts.mnemonic;
121
125
  this.setPassphrase(opts.passphrase || '');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rabby-wallet/eth-hd-keyring",
3
- "version": "4.3.2",
3
+ "version": "4.3.3-1",
4
4
  "description": "A simple standard interface for a seed phrase generated set of Ethereum accounts.",
5
5
  "keywords": [
6
6
  "ethereum",