Skip to content

Commit

Permalink
Merge pull request #1046 from BlueWallet/fixElectrumBug
Browse files Browse the repository at this point in the history
Fix Electrum recovery bug
  • Loading branch information
Overtorment committed May 4, 2020
2 parents 13572c8 + a13acaa commit 6100a9a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
18 changes: 9 additions & 9 deletions class/hd-legacy-electrum-seed-p2pkh-wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ const bitcoin = require('bitcoinjs-lib');
const mn = require('electrum-mnemonic');
const HDNode = require('bip32');

const PREFIX = mn.PREFIXES.standard;
const MNEMONIC_TO_SEED_OPTS = {
prefix: PREFIX,
};

/**
* ElectrumSeed means that instead of BIP39 seed format it works with the format invented by Electrum wallet. Otherwise
* its a regular HD wallet that has all the properties of parent class.
Expand All @@ -15,12 +20,7 @@ export class HDLegacyElectrumSeedP2PKHWallet extends HDLegacyP2PKHWallet {
static typeReadable = 'HD Legacy Electrum (BIP32 P2PKH)';

validateMnemonic() {
try {
mn.mnemonicToSeedSync(this.secret);
return true;
} catch (_) {
return false;
}
return mn.validateMnemonic(this.secret, PREFIX);
}

async generate() {
Expand All @@ -31,8 +31,8 @@ export class HDLegacyElectrumSeedP2PKHWallet extends HDLegacyP2PKHWallet {
if (this._xpub) {
return this._xpub; // cache hit
}
const root = bitcoin.bip32.fromSeed(mn.mnemonicToSeedSync(this.secret));
this._xpub = root.toBase58();
const root = bitcoin.bip32.fromSeed(mn.mnemonicToSeedSync(this.secret, MNEMONIC_TO_SEED_OPTS));
this._xpub = root.neutered().toBase58();
return this._xpub;
}

Expand Down Expand Up @@ -61,7 +61,7 @@ export class HDLegacyElectrumSeedP2PKHWallet extends HDLegacyP2PKHWallet {
}

_getWIFByIndex(internal, index) {
const root = bitcoin.bip32.fromSeed(mn.mnemonicToSeedSync(this.secret));
const root = bitcoin.bip32.fromSeed(mn.mnemonicToSeedSync(this.secret, MNEMONIC_TO_SEED_OPTS));
const path = `m/${internal ? 1 : 0}/${index}`;
const child = root.derivePath(path);

Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
"dayjs": "1.8.23",
"ecurve": "1.0.6",
"electrum-client": "git+https://github.com/BlueWallet/rn-electrum-client.git#2a5bb11dd9a8d89f328049d9ed59bce49d88a15d",
"electrum-mnemonic": "1.0.7",
"electrum-mnemonic": "2.0.0",
"eslint-config-prettier": "6.10.0",
"eslint-config-standard": "12.0.0",
"eslint-config-standard-react": "7.0.2",
Expand Down

0 comments on commit 6100a9a

Please sign in to comment.