mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2025-03-04 04:13:49 +01:00
ADD: Refactor Aezeed wallet to use this.passphrase
This commit is contained in:
parent
5938a8f8c1
commit
a70781180c
2 changed files with 15 additions and 8 deletions
|
@ -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';
|
||||
|
|
|
@ -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()));
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue