@@ -3,7 +3,7 @@ import * as encryptorUtils from '@metamask/browser-passworder';
33import HDKeyring from '@metamask/eth-hd-keyring' ;
44import { normalize as normalizeToHex } from '@metamask/eth-sig-util' ;
55import SimpleKeyring from '@metamask/eth-simple-keyring' ;
6- import { remove0x , isValidJson } from '@metamask/utils' ;
6+ import { remove0x } from '@metamask/utils' ;
77import type {
88 Hex ,
99 Json ,
@@ -87,7 +87,7 @@ class KeyringController extends EventEmitter {
8787 *
8888 * @returns The controller state.
8989 */
90- # fullUpdate( ) {
90+ fullUpdate ( ) {
9191 this . emit ( 'update' , this . memStore . getState ( ) ) ;
9292 return this . memStore . getState ( ) ;
9393 }
@@ -117,7 +117,7 @@ class KeyringController extends EventEmitter {
117117
118118 await this . #createFirstKeyTree( ) ;
119119 this . #setUnlocked( ) ;
120- return this . # fullUpdate( ) ;
120+ return this . fullUpdate ( ) ;
121121 }
122122
123123 /**
@@ -154,7 +154,7 @@ class KeyringController extends EventEmitter {
154154 throw new Error ( KeyringControllerError . NoFirstAccount ) ;
155155 }
156156 this . #setUnlocked( ) ;
157- return this . # fullUpdate( ) ;
157+ return this . fullUpdate ( ) ;
158158 }
159159
160160 /**
@@ -178,7 +178,7 @@ class KeyringController extends EventEmitter {
178178 this . keyrings = [ ] ;
179179 await this . updateMemStoreKeyrings ( ) ;
180180 this . emit ( 'lock' ) ;
181- return this . # fullUpdate( ) ;
181+ return this . fullUpdate ( ) ;
182182 }
183183
184184 /**
@@ -198,7 +198,7 @@ class KeyringController extends EventEmitter {
198198 this . keyrings = await this . unlockKeyrings ( password ) ;
199199
200200 this . #setUnlocked( ) ;
201- return this . # fullUpdate( ) ;
201+ return this . fullUpdate ( ) ;
202202 }
203203
204204 /**
@@ -222,7 +222,7 @@ class KeyringController extends EventEmitter {
222222 encryptionSalt ,
223223 ) ;
224224 this . #setUnlocked( ) ;
225- return this . # fullUpdate( ) ;
225+ return this . fullUpdate ( ) ;
226226 }
227227
228228 /**
@@ -265,7 +265,7 @@ class KeyringController extends EventEmitter {
265265 } ) ;
266266
267267 await this . persistAllKeyrings ( ) ;
268- return this . # fullUpdate( ) ;
268+ return this . fullUpdate ( ) ;
269269 }
270270
271271 /**
@@ -285,7 +285,7 @@ class KeyringController extends EventEmitter {
285285 throw new Error ( KeyringControllerError . UnsupportedExportAccount ) ;
286286 }
287287
288- return await keyring . exportAccount ( normalizeToHex ( address ) ) ;
288+ return await keyring . exportAccount ( normalizeToHex ( address ) as Hex ) ;
289289 }
290290
291291 /**
@@ -314,7 +314,7 @@ class KeyringController extends EventEmitter {
314314 }
315315
316316 await this . persistAllKeyrings ( ) ;
317- return this . # fullUpdate( ) ;
317+ return this . fullUpdate ( ) ;
318318 }
319319
320320 /**
@@ -388,7 +388,7 @@ class KeyringController extends EventEmitter {
388388 rawAddress : string ,
389389 opts : Record < string , unknown > = { } ,
390390 ) : Promise < TxData > {
391- const address = normalizeToHex ( rawAddress ) ;
391+ const address = normalizeToHex ( rawAddress ) as Hex ;
392392 const keyring = await this . getKeyringForAccount ( address ) ;
393393 if ( ! keyring . signTransaction ) {
394394 throw new Error ( KeyringControllerError . UnsupportedSignTransaction ) ;
@@ -415,7 +415,7 @@ class KeyringController extends EventEmitter {
415415 } ,
416416 opts : Record < string , unknown > = { } ,
417417 ) : Promise < string > {
418- const address = normalizeToHex ( msgParams . from ) ;
418+ const address = normalizeToHex ( msgParams . from ) as Hex ;
419419 const keyring = await this . getKeyringForAccount ( address ) ;
420420 if ( ! keyring . signMessage ) {
421421 throw new Error ( KeyringControllerError . UnsupportedSignMessage ) ;
@@ -443,13 +443,13 @@ class KeyringController extends EventEmitter {
443443 } ,
444444 opts : Record < string , unknown > = { } ,
445445 ) : Promise < string > {
446- const address = normalizeToHex ( msgParams . from ) ;
446+ const address = normalizeToHex ( msgParams . from ) as Hex ;
447447 const keyring = await this . getKeyringForAccount ( address ) ;
448448 if ( ! keyring . signPersonalMessage ) {
449449 throw new Error ( KeyringControllerError . UnsupportedSignPersonalMessage ) ;
450450 }
451451
452- const normalizedData = normalizeToHex ( msgParams . data ) ;
452+ const normalizedData = normalizeToHex ( msgParams . data ) as Hex ;
453453
454454 return await keyring . signPersonalMessage ( address , normalizedData , opts ) ;
455455 }
@@ -467,7 +467,7 @@ class KeyringController extends EventEmitter {
467467 address : string ,
468468 opts : Record < string , unknown > = { } ,
469469 ) : Promise < Bytes > {
470- const normalizedAddress = normalizeToHex ( address ) ;
470+ const normalizedAddress = normalizeToHex ( address ) as Hex ;
471471 const keyring = await this . getKeyringForAccount ( address ) ;
472472 if ( ! keyring . getEncryptionPublicKey ) {
473473 throw new Error ( KeyringControllerError . UnsupportedGetEncryptionPublicKey ) ;
@@ -490,7 +490,7 @@ class KeyringController extends EventEmitter {
490490 from : string ;
491491 data : Eip1024EncryptedData ;
492492 } ) : Promise < Bytes > {
493- const address = normalizeToHex ( msgParams . from ) ;
493+ const address = normalizeToHex ( msgParams . from ) as Hex ;
494494 const keyring = await this . getKeyringForAccount ( address ) ;
495495 if ( ! keyring . decryptMessage ) {
496496 throw new Error ( KeyringControllerError . UnsupportedDecryptMessage ) ;
@@ -536,7 +536,7 @@ class KeyringController extends EventEmitter {
536536 * @returns The app key address.
537537 */
538538 async getAppKeyAddress ( rawAddress : string , origin : string ) : Promise < string > {
539- const address = normalizeToHex ( rawAddress ) ;
539+ const address = normalizeToHex ( rawAddress ) as Hex ;
540540 const keyring = await this . getKeyringForAccount ( address ) ;
541541 if ( ! keyring . getAppKeyAddress ) {
542542 throw new Error ( KeyringControllerError . UnsupportedGetAppKeyAddress ) ;
@@ -556,7 +556,7 @@ class KeyringController extends EventEmitter {
556556 rawAddress : string ,
557557 origin : string ,
558558 ) : Promise < string > {
559- const address = normalizeToHex ( rawAddress ) ;
559+ const address = normalizeToHex ( rawAddress ) as Hex ;
560560 const keyring = await this . getKeyringForAccount ( address ) ;
561561 if ( ! keyring . exportAccount ) {
562562 throw new Error ( KeyringControllerError . UnsupportedExportAppKeyForAddress ) ;
@@ -618,7 +618,7 @@ class KeyringController extends EventEmitter {
618618 this . keyrings . push ( keyring ) ;
619619 await this . persistAllKeyrings ( ) ;
620620
621- this . # fullUpdate( ) ;
621+ this . fullUpdate ( ) ;
622622
623623 return keyring ;
624624 }
@@ -756,11 +756,7 @@ class KeyringController extends EventEmitter {
756756 * @returns Keyrings matching the specified type.
757757 */
758758 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 ) ;
764760 }
765761
766762 /**
@@ -1030,10 +1026,7 @@ class KeyringController extends EventEmitter {
10301026
10311027 const keyring = keyringBuilder ( ) ;
10321028
1033- if ( ! isValidJson ( data ) ) {
1034- throw new Error ( KeyringControllerError . DataType ) ;
1035- }
1036-
1029+ // @ts -expect-error Enforce data type after updating clients
10371030 await keyring . deserialize ( data ) ;
10381031
10391032 if ( keyring . init ) {
0 commit comments