@@ -24,6 +24,7 @@ export class SpringWallet {
2424 constructor ( network ) {
2525 if ( ! network ) throw new Error ( "'network' not defined" ) ;
2626 this . network = networkConfig ( network ) ;
27+ this . wallet = undefined ;
2728 this . walletAddress = this . initWalletAddress ( ) ;
2829 this . privateKey = this . initPrivateKey ( ) ;
2930 this . provider = this . initProvider ( this . network ) ;
@@ -120,7 +121,7 @@ export class SpringWallet {
120121 * @method encryptMnemonic
121122 * @param {String } mnemonic phrase
122123 * @param {String } password
123- * @returns {String } encryptMnemonic
124+ * @returns {Promise< String> } encryptMnemonic
124125 */
125126 static encryptMnemonic ( phrase , password ) {
126127 return encryptMnemonic ( phrase , password ) ;
@@ -150,14 +151,11 @@ export class SpringWallet {
150151 /**
151152 * Fetch encrypted mnemonic from browser's local storage
152153 * @method getEncryptedMnemonic
153- * @returns {String } encryptedMnemonic
154+ * @returns {Object } encryptedMnemonic
154155 */
155156 static getWalletSession ( ) {
156157 const data = localStorage . getItem ( STORAGE_SESSION_KEY ) ;
157- if ( ! data ) {
158- return null ;
159- }
160-
158+ if ( ! data ) return null ;
161159 const { address, encryptedMnemonic } = JSON . parse ( data ) ;
162160 return { address, encryptedMnemonic } ;
163161 }
@@ -169,13 +167,13 @@ export class SpringWallet {
169167 * @returns wallet instance
170168 */
171169 static async initializeWalletFromMnemonic ( mnemonic ) {
172- const seed = mnemonicToSeed ( mnemonic ) ;
170+ const seed = await mnemonicToSeed ( mnemonic ) ;
173171 const hdKey = await hdkey . fromMasterSeed ( seed ) ;
174172 const wallet = await hdKey . derivePath ( MNEMONIC_PATH ) . deriveChild ( 0 ) . getWallet ( ) ;
175173 return wallet ;
176174 }
177175
178- async unlockWallet ( mnemonic ) {
176+ static async unlockWallet ( mnemonic ) {
179177 const wallet = await SpringWallet . initializeWalletFromMnemonic ( mnemonic ) ;
180178 this . wallet = wallet ;
181179 this . walletAddress = wallet . getChecksumAddressString ( ) ;
@@ -185,3 +183,5 @@ export class SpringWallet {
185183 return this . walletAddress ;
186184 }
187185}
186+
187+ export { encryptMnemonic , decryptMnemonic } ;
0 commit comments