@@ -24,6 +24,7 @@ export class SpringWallet {
24
24
constructor ( network ) {
25
25
if ( ! network ) throw new Error ( "'network' not defined" ) ;
26
26
this . network = networkConfig ( network ) ;
27
+ this . wallet = undefined ;
27
28
this . walletAddress = this . initWalletAddress ( ) ;
28
29
this . privateKey = this . initPrivateKey ( ) ;
29
30
this . provider = this . initProvider ( this . network ) ;
@@ -120,7 +121,7 @@ export class SpringWallet {
120
121
* @method encryptMnemonic
121
122
* @param {String } mnemonic phrase
122
123
* @param {String } password
123
- * @returns {String } encryptMnemonic
124
+ * @returns {Promise< String> } encryptMnemonic
124
125
*/
125
126
static encryptMnemonic ( phrase , password ) {
126
127
return encryptMnemonic ( phrase , password ) ;
@@ -150,14 +151,11 @@ export class SpringWallet {
150
151
/**
151
152
* Fetch encrypted mnemonic from browser's local storage
152
153
* @method getEncryptedMnemonic
153
- * @returns {String } encryptedMnemonic
154
+ * @returns {Object } encryptedMnemonic
154
155
*/
155
156
static getWalletSession ( ) {
156
157
const data = localStorage . getItem ( STORAGE_SESSION_KEY ) ;
157
- if ( ! data ) {
158
- return null ;
159
- }
160
-
158
+ if ( ! data ) return null ;
161
159
const { address, encryptedMnemonic } = JSON . parse ( data ) ;
162
160
return { address, encryptedMnemonic } ;
163
161
}
@@ -169,13 +167,13 @@ export class SpringWallet {
169
167
* @returns wallet instance
170
168
*/
171
169
static async initializeWalletFromMnemonic ( mnemonic ) {
172
- const seed = mnemonicToSeed ( mnemonic ) ;
170
+ const seed = await mnemonicToSeed ( mnemonic ) ;
173
171
const hdKey = await hdkey . fromMasterSeed ( seed ) ;
174
172
const wallet = await hdKey . derivePath ( MNEMONIC_PATH ) . deriveChild ( 0 ) . getWallet ( ) ;
175
173
return wallet ;
176
174
}
177
175
178
- async unlockWallet ( mnemonic ) {
176
+ static async unlockWallet ( mnemonic ) {
179
177
const wallet = await SpringWallet . initializeWalletFromMnemonic ( mnemonic ) ;
180
178
this . wallet = wallet ;
181
179
this . walletAddress = wallet . getChecksumAddressString ( ) ;
@@ -185,3 +183,5 @@ export class SpringWallet {
185
183
return this . walletAddress ;
186
184
}
187
185
}
186
+
187
+ export { encryptMnemonic , decryptMnemonic } ;
0 commit comments