@@ -3,7 +3,7 @@ import * as encryptorUtils from '@metamask/browser-passworder';
3
3
import HDKeyring from '@metamask/eth-hd-keyring' ;
4
4
import { normalize as normalizeToHex } from '@metamask/eth-sig-util' ;
5
5
import SimpleKeyring from '@metamask/eth-simple-keyring' ;
6
- import { remove0x , isValidJson } from '@metamask/utils' ;
6
+ import { remove0x } from '@metamask/utils' ;
7
7
import type {
8
8
Hex ,
9
9
Json ,
@@ -87,7 +87,7 @@ class KeyringController extends EventEmitter {
87
87
*
88
88
* @returns The controller state.
89
89
*/
90
- # fullUpdate( ) {
90
+ fullUpdate ( ) {
91
91
this . emit ( 'update' , this . memStore . getState ( ) ) ;
92
92
return this . memStore . getState ( ) ;
93
93
}
@@ -117,7 +117,7 @@ class KeyringController extends EventEmitter {
117
117
118
118
await this . #createFirstKeyTree( ) ;
119
119
this . #setUnlocked( ) ;
120
- return this . # fullUpdate( ) ;
120
+ return this . fullUpdate ( ) ;
121
121
}
122
122
123
123
/**
@@ -154,7 +154,7 @@ class KeyringController extends EventEmitter {
154
154
throw new Error ( KeyringControllerError . NoFirstAccount ) ;
155
155
}
156
156
this . #setUnlocked( ) ;
157
- return this . # fullUpdate( ) ;
157
+ return this . fullUpdate ( ) ;
158
158
}
159
159
160
160
/**
@@ -178,7 +178,7 @@ class KeyringController extends EventEmitter {
178
178
this . keyrings = [ ] ;
179
179
await this . updateMemStoreKeyrings ( ) ;
180
180
this . emit ( 'lock' ) ;
181
- return this . # fullUpdate( ) ;
181
+ return this . fullUpdate ( ) ;
182
182
}
183
183
184
184
/**
@@ -198,7 +198,7 @@ class KeyringController extends EventEmitter {
198
198
this . keyrings = await this . unlockKeyrings ( password ) ;
199
199
200
200
this . #setUnlocked( ) ;
201
- return this . # fullUpdate( ) ;
201
+ return this . fullUpdate ( ) ;
202
202
}
203
203
204
204
/**
@@ -222,7 +222,7 @@ class KeyringController extends EventEmitter {
222
222
encryptionSalt ,
223
223
) ;
224
224
this . #setUnlocked( ) ;
225
- return this . # fullUpdate( ) ;
225
+ return this . fullUpdate ( ) ;
226
226
}
227
227
228
228
/**
@@ -265,7 +265,7 @@ class KeyringController extends EventEmitter {
265
265
} ) ;
266
266
267
267
await this . persistAllKeyrings ( ) ;
268
- return this . # fullUpdate( ) ;
268
+ return this . fullUpdate ( ) ;
269
269
}
270
270
271
271
/**
@@ -285,7 +285,7 @@ class KeyringController extends EventEmitter {
285
285
throw new Error ( KeyringControllerError . UnsupportedExportAccount ) ;
286
286
}
287
287
288
- return await keyring . exportAccount ( normalizeToHex ( address ) ) ;
288
+ return await keyring . exportAccount ( normalizeToHex ( address ) as Hex ) ;
289
289
}
290
290
291
291
/**
@@ -314,7 +314,7 @@ class KeyringController extends EventEmitter {
314
314
}
315
315
316
316
await this . persistAllKeyrings ( ) ;
317
- return this . # fullUpdate( ) ;
317
+ return this . fullUpdate ( ) ;
318
318
}
319
319
320
320
/**
@@ -388,7 +388,7 @@ class KeyringController extends EventEmitter {
388
388
rawAddress : string ,
389
389
opts : Record < string , unknown > = { } ,
390
390
) : Promise < TxData > {
391
- const address = normalizeToHex ( rawAddress ) ;
391
+ const address = normalizeToHex ( rawAddress ) as Hex ;
392
392
const keyring = await this . getKeyringForAccount ( address ) ;
393
393
if ( ! keyring . signTransaction ) {
394
394
throw new Error ( KeyringControllerError . UnsupportedSignTransaction ) ;
@@ -415,7 +415,7 @@ class KeyringController extends EventEmitter {
415
415
} ,
416
416
opts : Record < string , unknown > = { } ,
417
417
) : Promise < string > {
418
- const address = normalizeToHex ( msgParams . from ) ;
418
+ const address = normalizeToHex ( msgParams . from ) as Hex ;
419
419
const keyring = await this . getKeyringForAccount ( address ) ;
420
420
if ( ! keyring . signMessage ) {
421
421
throw new Error ( KeyringControllerError . UnsupportedSignMessage ) ;
@@ -443,13 +443,13 @@ class KeyringController extends EventEmitter {
443
443
} ,
444
444
opts : Record < string , unknown > = { } ,
445
445
) : Promise < string > {
446
- const address = normalizeToHex ( msgParams . from ) ;
446
+ const address = normalizeToHex ( msgParams . from ) as Hex ;
447
447
const keyring = await this . getKeyringForAccount ( address ) ;
448
448
if ( ! keyring . signPersonalMessage ) {
449
449
throw new Error ( KeyringControllerError . UnsupportedSignPersonalMessage ) ;
450
450
}
451
451
452
- const normalizedData = normalizeToHex ( msgParams . data ) ;
452
+ const normalizedData = normalizeToHex ( msgParams . data ) as Hex ;
453
453
454
454
return await keyring . signPersonalMessage ( address , normalizedData , opts ) ;
455
455
}
@@ -467,7 +467,7 @@ class KeyringController extends EventEmitter {
467
467
address : string ,
468
468
opts : Record < string , unknown > = { } ,
469
469
) : Promise < Bytes > {
470
- const normalizedAddress = normalizeToHex ( address ) ;
470
+ const normalizedAddress = normalizeToHex ( address ) as Hex ;
471
471
const keyring = await this . getKeyringForAccount ( address ) ;
472
472
if ( ! keyring . getEncryptionPublicKey ) {
473
473
throw new Error ( KeyringControllerError . UnsupportedGetEncryptionPublicKey ) ;
@@ -490,7 +490,7 @@ class KeyringController extends EventEmitter {
490
490
from : string ;
491
491
data : Eip1024EncryptedData ;
492
492
} ) : Promise < Bytes > {
493
- const address = normalizeToHex ( msgParams . from ) ;
493
+ const address = normalizeToHex ( msgParams . from ) as Hex ;
494
494
const keyring = await this . getKeyringForAccount ( address ) ;
495
495
if ( ! keyring . decryptMessage ) {
496
496
throw new Error ( KeyringControllerError . UnsupportedDecryptMessage ) ;
@@ -536,7 +536,7 @@ class KeyringController extends EventEmitter {
536
536
* @returns The app key address.
537
537
*/
538
538
async getAppKeyAddress ( rawAddress : string , origin : string ) : Promise < string > {
539
- const address = normalizeToHex ( rawAddress ) ;
539
+ const address = normalizeToHex ( rawAddress ) as Hex ;
540
540
const keyring = await this . getKeyringForAccount ( address ) ;
541
541
if ( ! keyring . getAppKeyAddress ) {
542
542
throw new Error ( KeyringControllerError . UnsupportedGetAppKeyAddress ) ;
@@ -556,7 +556,7 @@ class KeyringController extends EventEmitter {
556
556
rawAddress : string ,
557
557
origin : string ,
558
558
) : Promise < string > {
559
- const address = normalizeToHex ( rawAddress ) ;
559
+ const address = normalizeToHex ( rawAddress ) as Hex ;
560
560
const keyring = await this . getKeyringForAccount ( address ) ;
561
561
if ( ! keyring . exportAccount ) {
562
562
throw new Error ( KeyringControllerError . UnsupportedExportAppKeyForAddress ) ;
@@ -618,7 +618,7 @@ class KeyringController extends EventEmitter {
618
618
this . keyrings . push ( keyring ) ;
619
619
await this . persistAllKeyrings ( ) ;
620
620
621
- this . # fullUpdate( ) ;
621
+ this . fullUpdate ( ) ;
622
622
623
623
return keyring ;
624
624
}
@@ -756,11 +756,7 @@ class KeyringController extends EventEmitter {
756
756
* @returns Keyrings matching the specified type.
757
757
*/
758
758
getKeyringsByType ( type : string ) : Keyring < Json > [ ] {
759
- const keyrings = this . keyrings . filter ( ( keyring ) => keyring . type === type ) ;
760
- if ( ! keyrings . length ) {
761
- throw new Error ( KeyringControllerError . NoKeyring ) ;
762
- }
763
- return keyrings ;
759
+ return this . keyrings . filter ( ( keyring ) => keyring . type === type ) ;
764
760
}
765
761
766
762
/**
@@ -1030,10 +1026,7 @@ class KeyringController extends EventEmitter {
1030
1026
1031
1027
const keyring = keyringBuilder ( ) ;
1032
1028
1033
- if ( ! isValidJson ( data ) ) {
1034
- throw new Error ( KeyringControllerError . DataType ) ;
1035
- }
1036
-
1029
+ // @ts -expect-error Enforce data type after updating clients
1037
1030
await keyring . deserialize ( data ) ;
1038
1031
1039
1032
if ( keyring . init ) {
0 commit comments