@@ -100,6 +100,14 @@ export class SimpleKeyringV2
100100 return account ;
101101 }
102102
103+ async #getPrivateKeys( ) : Promise < string [ ] > {
104+ return await this . inner . serialize ( ) ;
105+ }
106+
107+ async #setPrivateKeys( privateKeys : string [ ] ) : Promise < void > {
108+ await this . inner . deserialize ( privateKeys ) ;
109+ }
110+
103111 async getAccounts ( ) : Promise < KeyringAccount [ ] > {
104112 const addresses = await this . inner . getAccounts ( ) ;
105113
@@ -161,10 +169,10 @@ export class SimpleKeyringV2
161169 const addressesBefore = new Set ( await this . inner . getAccounts ( ) ) ;
162170
163171 // Get current accounts to preserve them (also used for rollback)
164- const currentAccounts = await this . inner . serialize ( ) ;
172+ const currentAccounts = await this . #getPrivateKeys ( ) ;
165173
166174 // Import the new private key by deserializing with all accounts
167- await this . inner . deserialize ( [ ...currentAccounts , privateKey ] ) ;
175+ await this . #setPrivateKeys ( [ ...currentAccounts , privateKey ] ) ;
168176
169177 // Get addresses after import and find the newly added one
170178 const addressesAfter = await this . inner . getAccounts ( ) ;
@@ -176,7 +184,7 @@ export class SimpleKeyringV2
176184
177185 if ( newAddresses . length !== 1 || ! newAddresses [ 0 ] ) {
178186 // Rollback the inner keyring state to prevent corruption
179- await this . inner . deserialize ( currentAccounts ) ;
187+ await this . #setPrivateKeys ( currentAccounts ) ;
180188 throw new Error ( 'Failed to import private key' ) ;
181189 }
182190
0 commit comments