@rabby-wallet/eth-hd-keyring 4.3.1 → 4.3.2-beta

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
@@ -107,7 +107,7 @@ declare class HdKeyring extends SimpleKeyring {
107
107
  getSeed(mnemonic: string, passphrase?: string): Uint8Array;
108
108
  slip39MnemonicToSeedSync(mnemonic: string, passphrase?: string): Uint8Array;
109
109
  static checkMnemonicIsSlip39(mnemonic: string): boolean;
110
- static slip39DecodeMnemonics(shares: string[]): any;
110
+ static slip39GetThreshold(shares: string[]): number;
111
111
  static slip39DecodeMnemonic(share: string): any;
112
112
  static validateMnemonic(mnemonic: string): boolean;
113
113
  }
package/dist/index.js CHANGED
@@ -333,7 +333,7 @@ var require_slip39_helper = __commonJS({
333
333
  function rs1024CreateChecksum(data, extendableBackupFlag) {
334
334
  const values = slip39EncodeHex(get_customization_string(extendableBackupFlag)).concat(data).concat(slip39Generate(CHECKSUM_WORDS_LENGTH, () => 0));
335
335
  const polymod = rs1024Polymod(values) ^ 1;
336
- const result = Array().slip39Generate(CHECKSUM_WORDS_LENGTH, (i) => polymod >> 10 * i & 1023).reverse();
336
+ const result = slip39Generate(CHECKSUM_WORDS_LENGTH, (i) => polymod >> 10 * i & 1023).reverse();
337
337
  return result;
338
338
  }
339
339
  function rs1024VerifyChecksum(data, extendableBackupFlag) {
@@ -2351,6 +2351,7 @@ var require_slip39 = __commonJS({
2351
2351
  };
2352
2352
  __publicField(_Slip39, "decodeMnemonics", slipHelper.decodeMnemonics);
2353
2353
  __publicField(_Slip39, "decodeMnemonic", slipHelper.decodeMnemonic);
2354
+ __publicField(_Slip39, "combineMnemonics", slipHelper.combineMnemonics);
2354
2355
  var Slip39 = _Slip39;
2355
2356
  exports2 = module2.exports = Slip39;
2356
2357
  }
@@ -2674,14 +2675,29 @@ var _HdKeyring = class _HdKeyring extends import_eth_simple_keyring.default {
2674
2675
  static checkMnemonicIsSlip39(mnemonic) {
2675
2676
  const arr = mnemonic.split("\n");
2676
2677
  try {
2677
- _HdKeyring.slip39DecodeMnemonics(arr);
2678
+ _HdKeyring.slip39GetThreshold(arr);
2678
2679
  return true;
2679
2680
  } catch (e) {
2680
2681
  return false;
2681
2682
  }
2682
2683
  }
2683
- static slip39DecodeMnemonics(shares) {
2684
- return import_slip39.default.decodeMnemonics(shares);
2684
+ static slip39GetThreshold(shares) {
2685
+ try {
2686
+ import_slip39.default.combineMnemonics(shares);
2687
+ } catch (e) {
2688
+ const m1 = e.message.match(/The required number of groups is (\d+)/);
2689
+ const m2 = e.message.match(/Expected (\d+) groups/);
2690
+ const m3 = e.message.match(/Expected (\d+) mnemonics/);
2691
+ if (m1) {
2692
+ return parseInt(m1[1]);
2693
+ } else if (m2) {
2694
+ return parseInt(m2[1]);
2695
+ } else if (m3) {
2696
+ return parseInt(m3[1]);
2697
+ }
2698
+ throw new Error("Can't get threshold from error message");
2699
+ }
2700
+ return shares.length;
2685
2701
  }
2686
2702
  static slip39DecodeMnemonic(share) {
2687
2703
  return import_slip39.default.decodeMnemonic(share);
package/index.ts CHANGED
@@ -413,15 +413,33 @@ class HdKeyring extends SimpleKeyring {
413
413
  static checkMnemonicIsSlip39(mnemonic: string) {
414
414
  const arr = mnemonic.split('\n');
415
415
  try {
416
- HdKeyring.slip39DecodeMnemonics(arr);
416
+ HdKeyring.slip39GetThreshold(arr);
417
417
  return true;
418
418
  } catch (e) {
419
419
  return false;
420
420
  }
421
421
  }
422
422
 
423
- static slip39DecodeMnemonics(shares: string[]) {
424
- return slip39.decodeMnemonics(shares);
423
+ static slip39GetThreshold(shares: string[]) {
424
+ try {
425
+ slip39.combineMnemonics(shares);
426
+ } catch (e) {
427
+ const m1 = e.message.match(/The required number of groups is (\d+)/);
428
+ const m2 = e.message.match(/Expected (\d+) groups/);
429
+ const m3 = e.message.match(/Expected (\d+) mnemonics/);
430
+
431
+ if (m1) {
432
+ return parseInt(m1[1]);
433
+ } else if (m2) {
434
+ return parseInt(m2[1]);
435
+ } else if (m3) {
436
+ return parseInt(m3[1]);
437
+ }
438
+
439
+ throw new Error("Can't get threshold from error message");
440
+ }
441
+
442
+ return shares.length;
425
443
  }
426
444
 
427
445
  static slip39DecodeMnemonic(share: string) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rabby-wallet/eth-hd-keyring",
3
- "version": "4.3.1",
3
+ "version": "4.3.2-beta",
4
4
  "description": "A simple standard interface for a seed phrase generated set of Ethereum accounts.",
5
5
  "keywords": [
6
6
  "ethereum",
@@ -1,20 +1,22 @@
1
1
  diff --git a/node_modules/slip39/src/slip39.js b/node_modules/slip39/src/slip39.js
2
- index aff1c16..bd3ba54 100644
2
+ index aff1c16..62fe490 100644
3
3
  --- a/node_modules/slip39/src/slip39.js
4
4
  +++ b/node_modules/slip39/src/slip39.js
5
- @@ -180,6 +180,10 @@ class Slip39 {
5
+ @@ -180,6 +180,12 @@ class Slip39 {
6
6
  return slipHelper.validateMnemonic(mnemonic);
7
7
  }
8
8
 
9
9
  + static decodeMnemonics = slipHelper.decodeMnemonics;
10
10
  +
11
11
  + static decodeMnemonic = slipHelper.decodeMnemonic;
12
+ +
13
+ + static combineMnemonics = slipHelper.combineMnemonics;
12
14
  +
13
15
  fromPath(path) {
14
16
  this.validatePath(path);
15
17
 
16
18
  diff --git a/node_modules/slip39/src/slip39_helper.js b/node_modules/slip39/src/slip39_helper.js
17
- index 8bcb956..e9b86e4 100644
19
+ index 8bcb956..4b77568 100644
18
20
  --- a/node_modules/slip39/src/slip39_helper.js
19
21
  +++ b/node_modules/slip39/src/slip39_helper.js
20
22
  @@ -75,44 +75,21 @@ const SECRET_INDEX = 255;
@@ -128,7 +130,7 @@ index 8bcb956..e9b86e4 100644
128
130
  sharesValueLengths.values().next().value,
129
131
  () => 0,
130
132
  );
131
- @@ -400,10 +377,9 @@ function get_customization_string(extendableBackupFlag) {
133
+ @@ -400,13 +377,11 @@ function get_customization_string(extendableBackupFlag) {
132
134
  }
133
135
 
134
136
  function rs1024CreateChecksum(data, extendableBackupFlag) {
@@ -139,9 +141,13 @@ index 8bcb956..e9b86e4 100644
139
141
  - .concat(Array().slip39Generate(CHECKSUM_WORDS_LENGTH, () => 0));
140
142
  + .concat(slip39Generate(CHECKSUM_WORDS_LENGTH, () => 0));
141
143
  const polymod = rs1024Polymod(values) ^ 1;
142
- const result = Array()
143
- .slip39Generate(CHECKSUM_WORDS_LENGTH, (i) => (polymod >> (10 * i)) & 1023)
144
- @@ -414,9 +390,7 @@ function rs1024CreateChecksum(data, extendableBackupFlag) {
144
+ - const result = Array()
145
+ - .slip39Generate(CHECKSUM_WORDS_LENGTH, (i) => (polymod >> (10 * i)) & 1023)
146
+ + const result = slip39Generate(CHECKSUM_WORDS_LENGTH, (i) => (polymod >> (10 * i)) & 1023)
147
+ .reverse();
148
+
149
+ return result;
150
+ @@ -414,9 +389,7 @@ function rs1024CreateChecksum(data, extendableBackupFlag) {
145
151
 
146
152
  function rs1024VerifyChecksum(data, extendableBackupFlag) {
147
153
  return (
@@ -152,7 +158,7 @@ index 8bcb956..e9b86e4 100644
152
158
  .concat(data),
153
159
  ) === 1
154
160
  );
155
- @@ -440,7 +414,7 @@ function intFromIndices(indices) {
161
+ @@ -440,7 +413,7 @@ function intFromIndices(indices) {
156
162
  //
157
163
  function intToIndices(value, length, bits) {
158
164
  const mask = BigInt((1 << bits) - 1);
@@ -161,7 +167,7 @@ index 8bcb956..e9b86e4 100644
161
167
  parseInt((value >> (BigInt(i) * BigInt(bits))) & mask, 10),
162
168
  );
163
169
  return result.reverse();
164
- @@ -1886,4 +1860,6 @@ exports = module.exports = {
170
+ @@ -1886,4 +1859,6 @@ exports = module.exports = {
165
171
  crypt,
166
172
  bitsToBytes,
167
173
  WORD_LIST,