From a70781180c08b375e9fa1d890170a992b2eaab59 Mon Sep 17 00:00:00 2001 From: Ivan Vershigora Date: Wed, 7 Jul 2021 10:52:42 +0300 Subject: [PATCH] ADD: Refactor Aezeed wallet to use this.passphrase --- class/wallets/hd-aezeed-wallet.js | 10 +++++----- tests/unit/hd-aezeed.test.js | 13 ++++++++++--- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/class/wallets/hd-aezeed-wallet.js b/class/wallets/hd-aezeed-wallet.js index 423b7b431..36aae589b 100644 --- a/class/wallets/hd-aezeed-wallet.js +++ b/class/wallets/hd-aezeed-wallet.js @@ -21,7 +21,7 @@ export class HDAezeedWallet extends AbstractHDElectrumWallet { setSecret(newSecret) { this.secret = newSecret.trim(); - this.secret = this.secret.replace(/[^a-zA-Z0-9:]/g, ' ').replace(/\s+/g, ' '); + this.secret = this.secret.replace(/[^a-zA-Z0-9]/g, ' ').replace(/\s+/g, ' '); return this; } @@ -56,9 +56,9 @@ export class HDAezeedWallet extends AbstractHDElectrumWallet { } async validateMnemonicAsync() { - const [mnemonic3, password] = this.secret.split(':'); + const passphrase = this.getPassphrase() || 'aezeed'; try { - const cipherSeed1 = await CipherSeed.fromMnemonic(mnemonic3, password || 'aezeed'); + const cipherSeed1 = await CipherSeed.fromMnemonic(this.secret, passphrase); this._entropyHex = cipherSeed1.entropy.toString('hex'); // save cache return !!cipherSeed1.entropy; } catch (_) { @@ -67,9 +67,9 @@ export class HDAezeedWallet extends AbstractHDElectrumWallet { } async mnemonicInvalidPassword() { - const [mnemonic3, password] = this.secret.split(':'); + const passphrase = this.getPassphrase() || 'aezeed'; try { - const cipherSeed1 = await CipherSeed.fromMnemonic(mnemonic3, password || 'aezeed'); + const cipherSeed1 = await CipherSeed.fromMnemonic(this.secret, passphrase); this._entropyHex = cipherSeed1.entropy.toString('hex'); // save cache } catch (error) { return error.message === 'Invalid Password'; diff --git a/tests/unit/hd-aezeed.test.js b/tests/unit/hd-aezeed.test.js index d30b879de..30d436a6d 100644 --- a/tests/unit/hd-aezeed.test.js +++ b/tests/unit/hd-aezeed.test.js @@ -11,8 +11,9 @@ describe('HDAezeedWallet', () => { // correct pass: aezeed.setSecret( - 'able mix price funny host express lawsuit congress antique float pig exchange vapor drip wide cup style apple tumble verb fix blush tongue market:strongPassword', + 'able mix price funny host express lawsuit congress antique float pig exchange vapor drip wide cup style apple tumble verb fix blush tongue market', ); + aezeed.setPassphrase('strongPassword'); assert.ok(await aezeed.validateMnemonicAsync()); assert.ok(!(await aezeed.mnemonicInvalidPassword())); @@ -20,31 +21,37 @@ describe('HDAezeedWallet', () => { aezeed.setSecret( 'able mix price funny host express lawsuit congress antique float pig exchange vapor drip wide cup style apple tumble verb fix blush tongue market', ); + aezeed.setPassphrase(); assert.ok(!(await aezeed.validateMnemonicAsync())); assert.ok(await aezeed.mnemonicInvalidPassword()); // wrong pass: aezeed.setSecret( - 'able mix price funny host express lawsuit congress antique float pig exchange vapor drip wide cup style apple tumble verb fix blush tongue market:badpassword', + 'able mix price funny host express lawsuit congress antique float pig exchange vapor drip wide cup style apple tumble verb fix blush tongue market', ); + aezeed.setPassphrase('badpassword'); assert.ok(!(await aezeed.validateMnemonicAsync())); assert.ok(await aezeed.mnemonicInvalidPassword()); aezeed.setSecret( 'able concert slush lend olive cost wagon dawn board robot park snap dignity churn fiction quote shrimp hammer wing jump immune skill sunset west', ); + aezeed.setPassphrase(); assert.ok(await aezeed.validateMnemonicAsync()); assert.ok(!(await aezeed.mnemonicInvalidPassword())); aezeed.setSecret( - 'able concert slush lend olive cost wagon dawn board robot park snap dignity churn fiction quote shrimp hammer wing jump immune skill sunset west:aezeed', + 'able concert slush lend olive cost wagon dawn board robot park snap dignity churn fiction quote shrimp hammer wing jump immune skill sunset west', ); + aezeed.setPassphrase(); + aezeed.setPassphrase('aezeed'); assert.ok(await aezeed.validateMnemonicAsync()); assert.ok(!(await aezeed.mnemonicInvalidPassword())); aezeed.setSecret( 'abstract rhythm weird food attract treat mosquito sight royal actor surround ride strike remove guilt catch filter summer mushroom protect poverty cruel chaos pattern', ); + aezeed.setPassphrase(); assert.ok(await aezeed.validateMnemonicAsync()); assert.ok(!(await aezeed.mnemonicInvalidPassword()));