@metamask/eth-hd-keyring 7.0.0 → 7.0.2

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.
@@ -1,4 +1,4 @@
1
- import {
1
+ const {
2
2
  normalize,
3
3
  personalSign,
4
4
  recoverPersonalSignature,
@@ -6,27 +6,24 @@ import {
6
6
  signTypedData,
7
7
  SignTypedDataVersion,
8
8
  encrypt,
9
- EthEncryptedData,
10
- } from '@metamask/eth-sig-util';
11
- import { wordlist } from '@metamask/scure-bip39/dist/wordlists/english';
12
- import { generateMnemonic as oldMMForkBIP39GenerateMnemonic } from '@metamask/bip39';
13
- import {
9
+ } = require('@metamask/eth-sig-util');
10
+ const { wordlist } = require('@metamask/scure-bip39/dist/wordlists/english');
11
+ const oldMMForkBIP39 = require('@metamask/bip39');
12
+ const {
14
13
  isValidAddress,
15
14
  bufferToHex,
16
15
  toBuffer,
17
16
  ecrecover,
18
17
  pubToAddress,
19
- } from '@ethereumjs/util';
20
- import { TransactionFactory, Transaction as EthereumTx } from '@ethereumjs/tx';
21
- import { keccak256 } from 'ethereum-cryptography/keccak';
22
- import { Eip1024EncryptedData, Hex, add0x, assert } from '@metamask/utils';
23
-
24
- // we do not want to add this to dependency
25
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
26
- // @ts-ignore - TS7016: Could not find a declaration file for module
27
- // eslint-disable-next-line node/no-unpublished-import
28
- import OldHDKeyring from '@metamask/eth-hd-keyring';
29
- import { HDKeyring } from './HDKeyring';
18
+ } = require('@ethereumjs/util');
19
+ const {
20
+ TransactionFactory,
21
+ Transaction: EthereumTx,
22
+ } = require('@ethereumjs/tx');
23
+
24
+ const OldHdKeyring = require('@metamask/eth-hd-keyring');
25
+ const { keccak256 } = require('ethereum-cryptography/keccak');
26
+ const HdKeyring = require('..');
30
27
 
31
28
  // Sample account:
32
29
  const privKeyHex =
@@ -42,23 +39,25 @@ const notKeyringAddress = '0xbD20F6F5F1616947a39E11926E78ec94817B3931';
42
39
  describe('hd-keyring', () => {
43
40
  describe('compare old bip39 implementation with new', () => {
44
41
  it('should derive the same accounts from the same mnemonics', async () => {
45
- const mnemonics: Buffer[] = [];
42
+ const mnemonics = [];
46
43
  for (let i = 0; i < 99; i++) {
47
- mnemonics.push(oldMMForkBIP39GenerateMnemonic());
44
+ mnemonics.push(oldMMForkBIP39.generateMnemonic());
48
45
  }
49
46
 
50
47
  await Promise.all(
51
48
  mnemonics.map(async (mnemonic) => {
52
- const newHDKeyring = new HDKeyring({ mnemonic, numberOfAccounts: 3 });
53
- const oldHDKeyring = new OldHDKeyring({
49
+ const newHDKeyring = new HdKeyring({ mnemonic, numberOfAccounts: 3 });
50
+ const oldHDKeyring = new OldHdKeyring({
54
51
  mnemonic,
55
52
  numberOfAccounts: 3,
56
53
  });
57
54
  const newAccounts = await newHDKeyring.getAccounts();
58
55
  const oldAccounts = await oldHDKeyring.getAccounts();
59
- expect(newAccounts[0]).toStrictEqual(oldAccounts[0]);
60
- expect(newAccounts[1]).toStrictEqual(oldAccounts[1]);
61
- expect(newAccounts[2]).toStrictEqual(oldAccounts[2]);
56
+ await expect(newAccounts[0]).toStrictEqual(oldAccounts[0]);
57
+
58
+ await expect(newAccounts[1]).toStrictEqual(oldAccounts[1]);
59
+
60
+ await expect(newAccounts[2]).toStrictEqual(oldAccounts[2]);
62
61
  }),
63
62
  );
64
63
  });
@@ -66,7 +65,7 @@ describe('hd-keyring', () => {
66
65
 
67
66
  describe('constructor', () => {
68
67
  it('constructs with a typeof string mnemonic', async () => {
69
- const keyring = new HDKeyring({
68
+ const keyring = new HdKeyring({
70
69
  mnemonic: sampleMnemonic,
71
70
  numberOfAccounts: 2,
72
71
  });
@@ -77,7 +76,7 @@ describe('hd-keyring', () => {
77
76
  });
78
77
 
79
78
  it('constructs with a typeof buffer mnemonic', async () => {
80
- const keyring = new HDKeyring({
79
+ const keyring = new HdKeyring({
81
80
  mnemonic: Buffer.from(sampleMnemonic, 'utf8'),
82
81
  numberOfAccounts: 2,
83
82
  });
@@ -94,7 +93,7 @@ describe('hd-keyring', () => {
94
93
  const uInt8ArrayOfMnemonic = new Uint8Array(
95
94
  new Uint16Array(indices).buffer,
96
95
  );
97
- const keyring = new HDKeyring({
96
+ const keyring = new HdKeyring({
98
97
  mnemonic: uInt8ArrayOfMnemonic,
99
98
  numberOfAccounts: 2,
100
99
  });
@@ -104,35 +103,23 @@ describe('hd-keyring', () => {
104
103
  expect(accounts[1]).toStrictEqual(secondAcct);
105
104
  });
106
105
 
107
- it('constructs with jscasted buffer', async () => {
108
- const jscastedBuffer = Buffer.from(sampleMnemonic).toJSON();
109
- const keyring = new HDKeyring({
110
- mnemonic: jscastedBuffer,
111
- numberOfAccounts: 2,
112
- });
113
-
114
- const accounts = await keyring.getAccounts();
115
- expect(accounts[0]).toStrictEqual(firstAcct);
116
- expect(accounts[1]).toStrictEqual(secondAcct);
117
- });
118
-
119
106
  it('throws on invalid mnemonic', () => {
120
107
  expect(
121
108
  () =>
122
- new HDKeyring({
109
+ new HdKeyring({
123
110
  mnemonic: 'abc xyz',
124
111
  numberOfAccounts: 2,
125
112
  }),
126
113
  ).toThrow('Eth-Hd-Keyring: Invalid secret recovery phrase provided');
127
114
  });
128
115
 
129
- it('throws when numberOfAccounts is passed with no mnemonic', async () => {
130
- expect(() => {
131
- // eslint-disable-next-line no-new
132
- new HDKeyring({
133
- numberOfAccounts: 1,
134
- });
135
- }).toThrow(
116
+ it('throws when numberOfAccounts is passed with no mnemonic', () => {
117
+ expect(
118
+ () =>
119
+ new HdKeyring({
120
+ numberOfAccounts: 2,
121
+ }),
122
+ ).toThrow(
136
123
  'Eth-Hd-Keyring: Deserialize method cannot be called with an opts value for numberOfAccounts and no menmonic',
137
124
  );
138
125
  });
@@ -142,7 +129,7 @@ describe('hd-keyring', () => {
142
129
  const alreadyProvidedError =
143
130
  'Eth-Hd-Keyring: Secret recovery phrase already provided';
144
131
  it('double generateRandomMnemonic', () => {
145
- const keyring = new HDKeyring();
132
+ const keyring = new HdKeyring();
146
133
  keyring.generateRandomMnemonic();
147
134
  expect(() => {
148
135
  keyring.generateRandomMnemonic();
@@ -150,7 +137,7 @@ describe('hd-keyring', () => {
150
137
  });
151
138
 
152
139
  it('constructor + generateRandomMnemonic', () => {
153
- const keyring = new HDKeyring({
140
+ const keyring = new HdKeyring({
154
141
  mnemonic: sampleMnemonic,
155
142
  numberOfAccounts: 2,
156
143
  });
@@ -161,13 +148,12 @@ describe('hd-keyring', () => {
161
148
  });
162
149
 
163
150
  it('constructor + deserialize', () => {
164
- const keyring = new HDKeyring({
151
+ const keyring = new HdKeyring({
165
152
  mnemonic: sampleMnemonic,
166
153
  numberOfAccounts: 2,
167
154
  });
168
155
 
169
156
  expect(() => {
170
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
171
157
  keyring.deserialize({
172
158
  mnemonic: sampleMnemonic,
173
159
  numberOfAccounts: 1,
@@ -178,28 +164,28 @@ describe('hd-keyring', () => {
178
164
 
179
165
  describe('Keyring.type', () => {
180
166
  it('is a class property that returns the type string.', () => {
181
- const { type } = HDKeyring;
167
+ const { type } = HdKeyring;
182
168
  expect(typeof type).toBe('string');
183
169
  });
184
170
  });
185
171
 
186
172
  describe('#type', () => {
187
173
  it('returns the correct value', () => {
188
- const keyring = new HDKeyring();
174
+ const keyring = new HdKeyring();
189
175
 
190
176
  const { type } = keyring;
191
- const correct = HDKeyring.type;
177
+ const correct = HdKeyring.type;
192
178
  expect(type).toStrictEqual(correct);
193
179
  });
194
180
  });
195
181
 
196
182
  describe('#serialize mnemonic.', () => {
197
183
  it('serializes the mnemonic in the same format as previous version (an array of utf8 encoded bytes)', async () => {
198
- const keyring = new HDKeyring({
184
+ const keyring = new HdKeyring({
199
185
  mnemonic: sampleMnemonic,
200
186
  });
201
187
  // uses previous version of eth-hd-keyring to ensure backwards compatibility
202
- const oldHDKeyring = new OldHDKeyring({ mnemonic: sampleMnemonic });
188
+ const oldHDKeyring = new OldHdKeyring({ mnemonic: sampleMnemonic });
203
189
  const { mnemonic: oldKeyringSerializedMnemonic } =
204
190
  await oldHDKeyring.serialize();
205
191
 
@@ -208,7 +194,7 @@ describe('hd-keyring', () => {
208
194
  });
209
195
 
210
196
  it('serializes mnemonic passed in as a string to an array of utf8 encoded bytes', async () => {
211
- const keyring = new HDKeyring({
197
+ const keyring = new HdKeyring({
212
198
  mnemonic: sampleMnemonic,
213
199
  });
214
200
  const output = await keyring.serialize();
@@ -218,9 +204,9 @@ describe('hd-keyring', () => {
218
204
  });
219
205
 
220
206
  it('serializes mnemonic passed in as a an array of utf8 encoded bytes in the same format', async () => {
221
- const uint8Array = new TextEncoder().encode(sampleMnemonic);
207
+ const uint8Array = new TextEncoder('utf-8').encode(sampleMnemonic);
222
208
  const mnemonicAsArrayOfUtf8EncodedBytes = Array.from(uint8Array);
223
- const keyring = new HDKeyring({
209
+ const keyring = new HdKeyring({
224
210
  mnemonic: mnemonicAsArrayOfUtf8EncodedBytes,
225
211
  });
226
212
 
@@ -229,18 +215,11 @@ describe('hd-keyring', () => {
229
215
  const mnemonicAsString = Buffer.from(output.mnemonic).toString();
230
216
  expect(mnemonicAsString).toStrictEqual(sampleMnemonic);
231
217
  });
232
-
233
- it('throws if mnemnoic is not set', async () => {
234
- const keyring = new HDKeyring({});
235
- await expect(keyring.serialize()).rejects.toThrow(
236
- 'Eth-Hd-Keyring: Missing mnemonic when serializing',
237
- );
238
- });
239
218
  });
240
219
 
241
220
  describe('#deserialize a private key', () => {
242
221
  it('serializes what it deserializes', async () => {
243
- const keyring = new HDKeyring();
222
+ const keyring = new HdKeyring();
244
223
  await keyring.deserialize({
245
224
  mnemonic: sampleMnemonic,
246
225
  numberOfAccounts: 1,
@@ -263,7 +242,7 @@ describe('hd-keyring', () => {
263
242
  describe('#addAccounts', () => {
264
243
  describe('with no arguments', () => {
265
244
  it('creates a single wallet', async () => {
266
- const keyring = new HDKeyring();
245
+ const keyring = new HdKeyring();
267
246
  keyring.generateRandomMnemonic();
268
247
  await keyring.addAccounts();
269
248
  const accounts = await keyring.getAccounts();
@@ -271,8 +250,8 @@ describe('hd-keyring', () => {
271
250
  });
272
251
 
273
252
  it('throws an error when no SRP has been generated yet', async () => {
274
- const keyring = new HDKeyring();
275
- await expect(keyring.addAccounts()).rejects.toThrow(
253
+ const keyring = new HdKeyring();
254
+ expect(() => keyring.addAccounts()).toThrow(
276
255
  'Eth-Hd-Keyring: No secret recovery phrase provided',
277
256
  );
278
257
  });
@@ -280,7 +259,7 @@ describe('hd-keyring', () => {
280
259
 
281
260
  describe('with a numeric argument', () => {
282
261
  it('creates that number of wallets', async () => {
283
- const keyring = new HDKeyring();
262
+ const keyring = new HdKeyring();
284
263
  keyring.generateRandomMnemonic();
285
264
  await keyring.addAccounts(3);
286
265
  const accounts = await keyring.getAccounts();
@@ -291,7 +270,7 @@ describe('hd-keyring', () => {
291
270
 
292
271
  describe('#signPersonalMessage', () => {
293
272
  it('returns the expected value', async () => {
294
- const keyring = new HDKeyring();
273
+ const keyring = new HdKeyring();
295
274
 
296
275
  const address = firstAcct;
297
276
  const message = '0x68656c6c6f20776f726c64';
@@ -314,7 +293,7 @@ describe('hd-keyring', () => {
314
293
 
315
294
  describe('#signTypedData', () => {
316
295
  it('can recover a basic signature', async () => {
317
- const keyring = new HDKeyring();
296
+ const keyring = new HdKeyring();
318
297
  Buffer.from(privKeyHex, 'hex');
319
298
  const typedData = [
320
299
  {
@@ -325,9 +304,8 @@ describe('hd-keyring', () => {
325
304
  ];
326
305
  keyring.generateRandomMnemonic();
327
306
  await keyring.addAccounts(1);
328
- const [rawAddress] = await keyring.getAccounts();
329
- assert(rawAddress, 'addresses is empty');
330
- const address = add0x(rawAddress);
307
+ const addresses = await keyring.getAccounts();
308
+ const address = addresses[0];
331
309
  const signature = await keyring.signTypedData(address, typedData);
332
310
  const restored = recoverTypedSignature({
333
311
  data: typedData,
@@ -348,12 +326,11 @@ describe('hd-keyring', () => {
348
326
  ];
349
327
 
350
328
  it('signs in a compliant and recoverable way', async () => {
351
- const keyring = new HDKeyring();
329
+ const keyring = new HdKeyring();
352
330
  keyring.generateRandomMnemonic();
353
331
  await keyring.addAccounts(1);
354
- const [rawAddress] = await keyring.getAccounts();
355
- assert(rawAddress, 'addresses is empty');
356
- const address = add0x(rawAddress);
332
+ const addresses = await keyring.getAccounts();
333
+ const address = addresses[0];
357
334
  const signature = await keyring.signTypedData(address, typedData, {
358
335
  version: SignTypedDataVersion.V1,
359
336
  });
@@ -368,13 +345,13 @@ describe('hd-keyring', () => {
368
345
 
369
346
  describe('#signTypedData_v3', () => {
370
347
  it('signs in a compliant and recoverable way', async () => {
371
- const keyring = new HDKeyring();
348
+ const keyring = new HdKeyring();
372
349
  const typedData = {
373
350
  types: {
374
351
  EIP712Domain: [],
375
352
  },
376
353
  domain: {},
377
- primaryType: 'EIP712Domain' as const,
354
+ primaryType: 'EIP712Domain',
378
355
  message: {},
379
356
  };
380
357
 
@@ -382,9 +359,8 @@ describe('hd-keyring', () => {
382
359
  mnemonic: sampleMnemonic,
383
360
  numberOfAccounts: 1,
384
361
  });
385
- const [rawAddress] = await keyring.getAccounts();
386
- assert(rawAddress, 'addresses is empty');
387
- const address = add0x(rawAddress);
362
+ const addresses = await keyring.getAccounts();
363
+ const address = addresses[0];
388
364
  const signature = await keyring.signTypedData(address, typedData, {
389
365
  version: SignTypedDataVersion.V3,
390
366
  });
@@ -399,7 +375,7 @@ describe('hd-keyring', () => {
399
375
 
400
376
  describe('#signTypedData_v3 signature verification', () => {
401
377
  it('signs in a recoverable way.', async () => {
402
- const keyring = new HDKeyring();
378
+ const keyring = new HdKeyring();
403
379
  const typedData = {
404
380
  types: {
405
381
  EIP712Domain: [
@@ -418,7 +394,7 @@ describe('hd-keyring', () => {
418
394
  { name: 'contents', type: 'string' },
419
395
  ],
420
396
  },
421
- primaryType: 'Mail' as const,
397
+ primaryType: 'Mail',
422
398
  domain: {
423
399
  name: 'Ether Mail',
424
400
  version: '1',
@@ -440,9 +416,8 @@ describe('hd-keyring', () => {
440
416
 
441
417
  keyring.generateRandomMnemonic();
442
418
  await keyring.addAccounts(1);
443
- const [rawAddress] = await keyring.getAccounts();
444
- assert(rawAddress, 'addresses is empty');
445
- const address = add0x(rawAddress);
419
+ const addresses = await keyring.getAccounts();
420
+ const address = addresses[0];
446
421
  const signature = await keyring.signTypedData(address, typedData, {
447
422
  version: SignTypedDataVersion.V3,
448
423
  });
@@ -457,9 +432,9 @@ describe('hd-keyring', () => {
457
432
 
458
433
  describe('custom hd paths', () => {
459
434
  it('can deserialize with an hdPath param and generate the same accounts.', async () => {
460
- const keyring = new HDKeyring();
435
+ const keyring = new HdKeyring();
461
436
  const hdPathString = `m/44'/60'/0'/0`;
462
- await keyring.deserialize({
437
+ keyring.deserialize({
463
438
  mnemonic: sampleMnemonic,
464
439
  numberOfAccounts: 1,
465
440
  hdPath: hdPathString,
@@ -471,9 +446,9 @@ describe('hd-keyring', () => {
471
446
  });
472
447
 
473
448
  it('can deserialize with an hdPath param and generate different accounts.', async () => {
474
- const keyring = new HDKeyring();
449
+ const keyring = new HdKeyring();
475
450
  const hdPathString = `m/44'/60'/0'/1`;
476
- await keyring.deserialize({
451
+ keyring.deserialize({
477
452
  mnemonic: sampleMnemonic,
478
453
  numberOfAccounts: 1,
479
454
  hdPath: hdPathString,
@@ -493,14 +468,14 @@ describe('hd-keyring', () => {
493
468
 
494
469
  for (let i = 0; i < 1e3; i++) {
495
470
 
496
- const keyring = new HDKeyring({
471
+ const keyring = new HdKeyring({
497
472
  numberOfAccounts: 1,
498
473
  })
499
474
  const originalAccounts = await keyring.getAccounts()
500
475
  const serialized = await keyring.serialize()
501
476
  const mnemonic = serialized.mnemonic
502
477
 
503
- const keyring = new HDKeyring({
478
+ const keyring = new HdKeyring({
504
479
  numberOfAccounts: 1,
505
480
  mnemonic,
506
481
  })
@@ -520,7 +495,7 @@ describe('hd-keyring', () => {
520
495
 
521
496
  describe('signing methods withAppKeyOrigin option', () => {
522
497
  it('should signPersonalMessage with the expected key when passed a withAppKeyOrigin', async () => {
523
- const keyring = new HDKeyring();
498
+ const keyring = new HdKeyring();
524
499
  const address = firstAcct;
525
500
  const message = '0x68656c6c6f20776f726c64';
526
501
 
@@ -542,14 +517,14 @@ describe('hd-keyring', () => {
542
517
  });
543
518
 
544
519
  it('should signTypedData with the expected key when passed a withAppKeyOrigin', async () => {
545
- const keyring = new HDKeyring();
520
+ const keyring = new HdKeyring();
546
521
  const address = firstAcct;
547
522
  const typedData = {
548
523
  types: {
549
524
  EIP712Domain: [],
550
525
  },
551
526
  domain: {},
552
- primaryType: 'EIP712Domain' as const,
527
+ primaryType: 'EIP712Domain',
553
528
  message: {},
554
529
  };
555
530
 
@@ -587,7 +562,7 @@ describe('hd-keyring', () => {
587
562
  '0xb21867b2221db0172e970b7370825b71c57823ff8714168ce9748f32f450e2c43d0fe396eb5b5f59284b7fd108c8cf61a6180a6756bdd3d4b7b9ccc4ac6d51611b';
588
563
 
589
564
  it('passes the dennis test', async function () {
590
- const keyring = new HDKeyring();
565
+ const keyring = new HdKeyring();
591
566
  await keyring.deserialize({
592
567
  mnemonic: sampleMnemonic,
593
568
  numberOfAccounts: 1,
@@ -597,7 +572,7 @@ describe('hd-keyring', () => {
597
572
  });
598
573
 
599
574
  it('reliably can decode messages it signs', async function () {
600
- const keyring = new HDKeyring();
575
+ const keyring = new HdKeyring();
601
576
  await keyring.deserialize({
602
577
  mnemonic: sampleMnemonic,
603
578
  numberOfAccounts: 1,
@@ -605,11 +580,11 @@ describe('hd-keyring', () => {
605
580
  const localMessage = 'hello there!';
606
581
  const msgHashHex = bufferToHex(
607
582
  Buffer.from(keccak256(Buffer.from(localMessage))),
608
- ) as Hex;
583
+ );
609
584
  await keyring.addAccounts(9);
610
585
  const addresses = await keyring.getAccounts();
611
586
  const signatures = await Promise.all(
612
- addresses.map(async (accountAddress: Hex) => {
587
+ addresses.map(async (accountAddress) => {
613
588
  return await keyring.signMessage(accountAddress, msgHashHex);
614
589
  }),
615
590
  );
@@ -628,7 +603,7 @@ describe('hd-keyring', () => {
628
603
  });
629
604
 
630
605
  it('throw error for invalid message', async function () {
631
- const keyring = new HDKeyring();
606
+ const keyring = new HdKeyring();
632
607
  await keyring.deserialize({
633
608
  mnemonic: sampleMnemonic,
634
609
  numberOfAccounts: 1,
@@ -640,20 +615,19 @@ describe('hd-keyring', () => {
640
615
  });
641
616
 
642
617
  it('throw error if empty address is passed', async function () {
643
- const keyring = new HDKeyring();
618
+ const keyring = new HdKeyring();
644
619
  await keyring.deserialize({
645
620
  mnemonic: sampleMnemonic,
646
621
  numberOfAccounts: 1,
647
622
  });
648
623
 
649
- // @ts-expect-error we inputting an invalid address
650
624
  await expect(keyring.signMessage('', message)).rejects.toThrow(
651
625
  'Must specify address.',
652
626
  );
653
627
  });
654
628
 
655
629
  it('throw error if address not associated with the current keyring is passed', async function () {
656
- const keyring = new HDKeyring();
630
+ const keyring = new HdKeyring();
657
631
  await keyring.deserialize({
658
632
  mnemonic: sampleMnemonic,
659
633
  numberOfAccounts: 1,
@@ -661,14 +635,14 @@ describe('hd-keyring', () => {
661
635
 
662
636
  await expect(
663
637
  keyring.signMessage(notKeyringAddress, message),
664
- ).rejects.toThrow('Eth-Hd-Keyring: Unable to find matching address.');
638
+ ).rejects.toThrow('HD Keyring - Unable to find matching address.');
665
639
  });
666
640
  });
667
641
 
668
642
  describe('#removeAccount', function () {
669
- let keyring: HDKeyring;
643
+ let keyring;
670
644
  beforeEach(() => {
671
- keyring = new HDKeyring({
645
+ keyring = new HdKeyring({
672
646
  mnemonic: sampleMnemonic,
673
647
  numberOfAccounts: 1,
674
648
  });
@@ -676,12 +650,9 @@ describe('hd-keyring', () => {
676
650
 
677
651
  describe('if the account exists', function () {
678
652
  it('should remove that account', async function () {
679
- const rawAddresses = await keyring.getAccounts();
680
- const [rawAddress] = rawAddresses;
681
- expect(rawAddresses).toHaveLength(1);
682
- assert(rawAddress, 'rawAddress should be empty');
683
- const address = add0x(rawAddress);
684
- keyring.removeAccount(address);
653
+ const addresses = await keyring.getAccounts();
654
+ expect(addresses).toHaveLength(1);
655
+ keyring.removeAccount(addresses[0]);
685
656
  const addressesAfterRemoval = await keyring.getAccounts();
686
657
  expect(addressesAfterRemoval).toHaveLength(0);
687
658
  });
@@ -698,9 +669,9 @@ describe('hd-keyring', () => {
698
669
  });
699
670
 
700
671
  describe('getAppKeyAddress', function () {
701
- let keyring: HDKeyring;
672
+ let keyring;
702
673
  beforeEach(() => {
703
- keyring = new HDKeyring({
674
+ keyring = new HdKeyring({
704
675
  mnemonic: sampleMnemonic,
705
676
  numberOfAccounts: 1,
706
677
  });
@@ -751,7 +722,6 @@ describe('hd-keyring', () => {
751
722
  });
752
723
 
753
724
  it('should throw error if the provided origin is not a string', async function () {
754
- // @ts-expect-error we are providing an incorrect origin key
755
725
  await expect(keyring.getAppKeyAddress(firstAcct, [])).rejects.toThrow(
756
726
  `'origin' must be a non-empty string`,
757
727
  );
@@ -765,9 +735,9 @@ describe('hd-keyring', () => {
765
735
  });
766
736
 
767
737
  describe('exportAccount', function () {
768
- let keyring: HDKeyring;
738
+ let keyring;
769
739
  beforeEach(() => {
770
- keyring = new HDKeyring({
740
+ keyring = new HdKeyring({
771
741
  mnemonic: sampleMnemonic,
772
742
  numberOfAccounts: 1,
773
743
  });
@@ -783,16 +753,16 @@ describe('hd-keyring', () => {
783
753
 
784
754
  it('throw error if account is not present', async function () {
785
755
  await expect(keyring.exportAccount(notKeyringAddress)).rejects.toThrow(
786
- 'Eth-Hd-Keyring: Unable to find matching address.',
756
+ 'HD Keyring - Unable to find matching address.',
787
757
  );
788
758
  });
789
759
  });
790
760
 
791
761
  describe('#encryptionPublicKey', function () {
792
762
  const publicKey = 'LV7lWhd0mUDcvxkMU2o6uKXftu25zq4bMYdmMqppXic=';
793
- let keyring: HDKeyring;
763
+ let keyring;
794
764
  beforeEach(() => {
795
- keyring = new HDKeyring({
765
+ keyring = new HdKeyring({
796
766
  mnemonic: sampleMnemonic,
797
767
  numberOfAccounts: 1,
798
768
  });
@@ -806,7 +776,6 @@ describe('hd-keyring', () => {
806
776
  });
807
777
 
808
778
  it('throw error if address is blank', async function () {
809
- // @ts-expect-error provide an invalid key
810
779
  await expect(keyring.getEncryptionPublicKey('')).rejects.toThrow(
811
780
  'Must specify address.',
812
781
  );
@@ -815,14 +784,14 @@ describe('hd-keyring', () => {
815
784
  it('throw error if address is not present in the keyring', async function () {
816
785
  await expect(
817
786
  keyring.getEncryptionPublicKey(notKeyringAddress),
818
- ).rejects.toThrow('Eth-Hd-Keyring: Unable to find matching address.');
787
+ ).rejects.toThrow('HD Keyring - Unable to find matching address.');
819
788
  });
820
789
  });
821
790
 
822
791
  describe('#signTypedData V4 signature verification', function () {
823
- let keyring: HDKeyring;
792
+ let keyring;
824
793
  beforeEach(() => {
825
- keyring = new HDKeyring({
794
+ keyring = new HdKeyring({
826
795
  mnemonic: sampleMnemonic,
827
796
  numberOfAccounts: 1,
828
797
  });
@@ -860,7 +829,7 @@ describe('hd-keyring', () => {
860
829
  chainId: 1,
861
830
  verifyingContract: '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC',
862
831
  },
863
- primaryType: 'Mail' as const,
832
+ primaryType: 'Mail',
864
833
  message: {
865
834
  from: {
866
835
  name: 'Cow',
@@ -886,8 +855,8 @@ describe('hd-keyring', () => {
886
855
  const addresses = await keyring.getAccounts();
887
856
  const [address] = addresses;
888
857
 
889
- const signature = await keyring.signTypedData(address as Hex, typedData, {
890
- version: SignTypedDataVersion.V4,
858
+ const signature = await keyring.signTypedData(address, typedData, {
859
+ version: 'V4',
891
860
  });
892
861
  expect(signature).toBe(expectedSignature);
893
862
  const restored = recoverTypedSignature({
@@ -901,10 +870,10 @@ describe('hd-keyring', () => {
901
870
 
902
871
  describe('#decryptMessage', function () {
903
872
  const message = 'Hello world!';
904
- let encryptedMessage: EthEncryptedData, keyring: HDKeyring;
873
+ let encryptedMessage, keyring;
905
874
 
906
875
  beforeEach(async () => {
907
- keyring = new HDKeyring({
876
+ keyring = new HdKeyring({
908
877
  mnemonic: sampleMnemonic,
909
878
  numberOfAccounts: 1,
910
879
  });
@@ -930,20 +899,20 @@ describe('hd-keyring', () => {
930
899
  it('throw error if address passed is not present in the keyring', async function () {
931
900
  await expect(
932
901
  keyring.decryptMessage(notKeyringAddress, encryptedMessage),
933
- ).rejects.toThrow('Eth-Hd-Keyring: Unable to find matching address.');
902
+ ).rejects.toThrow('HD Keyring - Unable to find matching address.');
934
903
  });
935
904
 
936
905
  it('throw error if wrong encrypted data object is passed', async function () {
937
- await expect(
938
- keyring.decryptMessage(firstAcct, {} as Eip1024EncryptedData),
939
- ).rejects.toThrow('Encryption type/version not supported.');
906
+ await expect(keyring.decryptMessage(firstAcct, {})).rejects.toThrow(
907
+ 'Encryption type/version not supported.',
908
+ );
940
909
  });
941
910
  });
942
911
 
943
912
  describe('#signTransaction', function () {
944
- let keyring: HDKeyring;
913
+ let keyring;
945
914
  beforeEach(() => {
946
- keyring = new HDKeyring({
915
+ keyring = new HdKeyring({
947
916
  mnemonic: sampleMnemonic,
948
917
  numberOfAccounts: 1,
949
918
  });
@@ -963,8 +932,7 @@ describe('hd-keyring', () => {
963
932
  expect(tx.isSigned()).toBe(false);
964
933
 
965
934
  const signed = await keyring.signTransaction(firstAcct, tx);
966
- const signedTx = TransactionFactory.fromTxData(signed);
967
- expect(signedTx.isSigned()).toBe(true);
935
+ expect(signed.isSigned()).toBe(true);
968
936
  });
969
937
 
970
938
  it('returns a signed tx object', async function () {
@@ -972,13 +940,11 @@ describe('hd-keyring', () => {
972
940
  expect(tx.isSigned()).toBe(false);
973
941
 
974
942
  const signed = await keyring.signTransaction(firstAcct, tx);
975
- const signedTx = TransactionFactory.fromTxData(signed);
976
- expect(signedTx.isSigned()).toBe(true);
943
+ expect(signed.isSigned()).toBe(true);
977
944
  });
978
945
 
979
946
  it('returns rejected promise if empty address is passed', async function () {
980
947
  const tx = TransactionFactory.fromTxData(txParams);
981
- // @ts-expect-error provide invalid address
982
948
  await expect(keyring.signTransaction('', tx)).rejects.toThrow(
983
949
  'Must specify address.',
984
950
  );
@@ -988,7 +954,7 @@ describe('hd-keyring', () => {
988
954
  const tx = TransactionFactory.fromTxData(txParams);
989
955
  await expect(
990
956
  keyring.signTransaction(notKeyringAddress, tx),
991
- ).rejects.toThrow('Eth-Hd-Keyring: Unable to find matching address.');
957
+ ).rejects.toThrow('HD Keyring - Unable to find matching address.');
992
958
  });
993
959
  });
994
960
  });