Skip to content

Commit f722b23

Browse files
authored
Merge pull request #17 from SpringRole/develop
fix wallet generation issue
2 parents 45363cc + 1a77d89 commit f722b23

File tree

5 files changed

+927
-1023
lines changed

5 files changed

+927
-1023
lines changed

.babelrc

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
11
{
2-
"presets": ["@babel/env", "minify"]
2+
"presets": ["@babel/env", "minify"],
3+
"plugins": [
4+
[
5+
"@babel/plugin-transform-runtime",
6+
{
7+
"helpers": true,
8+
"regenerator": true
9+
}
10+
]
11+
]
312
}

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@springrole/springwallet",
3-
"version": "0.2.0",
3+
"version": "0.2.2",
44
"description": "Wallet for SpringRole users",
55
"main": "dist/index.js",
66
"scripts": {
@@ -44,6 +44,7 @@
4444
"devDependencies": {
4545
"@babel/cli": "^7.12.10",
4646
"@babel/core": "^7.12.10",
47+
"@babel/plugin-transform-runtime": "^7.12.10",
4748
"@babel/preset-env": "^7.12.11",
4849
"babel-preset-minify": "^0.5.1",
4950
"eslint": "^7.18.0",

src/index.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -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 };

src/utils/encryption.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export async function decryptMnemonic(encryptedMnemonic, password) {
6060
const decipher = createDecipheriv('aes-128-cbc', encKey, iv);
6161
const plaintextBuffer = Buffer.concat([decipher.update(cipherText), decipher.final()]);
6262

63-
const hmac = crypto.createHmac('sha256', macKey);
63+
const hmac = createHmac('sha256', macKey);
6464
hmac.write(hmacPayload);
6565

6666
const hmacDigest = hmac.digest();

0 commit comments

Comments
 (0)