mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2025-01-19 05:45:15 +01:00
ADD: import path for supported watch only formats
This commit is contained in:
parent
43f2117ad0
commit
30062e9795
@ -174,10 +174,12 @@ export class AbstractWallet {
|
||||
const re = /\[([^\]]+)\](.*)/;
|
||||
const m = this.secret.match(re);
|
||||
if (m && m.length === 3) {
|
||||
let hexFingerprint = m[1].split('/')[0];
|
||||
let [hexFingerprint, ...derivationPathArray] = m[1].split('/');
|
||||
const derivationPath = `m/${derivationPathArray.join('/').replace(/h/g, "'")}`;
|
||||
if (hexFingerprint.length === 8) {
|
||||
hexFingerprint = Buffer.from(hexFingerprint, 'hex').reverse().toString('hex');
|
||||
this.masterFingerprint = parseInt(hexFingerprint, 16);
|
||||
this._derivationPath = derivationPath;
|
||||
}
|
||||
this.secret = m[2];
|
||||
}
|
||||
@ -205,16 +207,20 @@ export class AbstractWallet {
|
||||
if (parsedSecret.keystore.label) {
|
||||
this.setLabel(parsedSecret.keystore.label);
|
||||
}
|
||||
if (parsedSecret.keystore.derivation) {
|
||||
this._derivationPath = parsedSecret.keystore.derivation;
|
||||
}
|
||||
this.secret = parsedSecret.keystore.xpub;
|
||||
this.masterFingerprint = masterFingerprint;
|
||||
|
||||
if (parsedSecret.keystore.type === 'hardware') this.use_with_hardware_wallet = true;
|
||||
}
|
||||
// It is a Cobo Vault Hardware Wallet
|
||||
if (parsedSecret && parsedSecret.ExtPubKey && parsedSecret.MasterFingerprint) {
|
||||
if (parsedSecret && parsedSecret.ExtPubKey && parsedSecret.MasterFingerprint && parsedSecret.AccountKeyPath) {
|
||||
this.secret = parsedSecret.ExtPubKey;
|
||||
const mfp = Buffer.from(parsedSecret.MasterFingerprint, 'hex').reverse().toString('hex');
|
||||
this.masterFingerprint = parseInt(mfp, 16);
|
||||
this._derivationPath = `m/${parsedSecret.AccountKeyPath}`;
|
||||
if (parsedSecret.CoboVaultFirmwareVersion) this.use_with_hardware_wallet = true;
|
||||
}
|
||||
} catch (_) {}
|
||||
|
@ -1 +1 @@
|
||||
{"ExtPubKey":"zpub6rcabYFcdr41zyUNRWRyHYs2Sm86E5XV8RjjRzTFYsiCngteeZnkwaF2xuhjmM6kpHjuNpFW42BMhzPmFwXt48e1FhddMB7xidZzN4SF24K","MasterFingerprint":"5271c071","CoboVaultFirmwareVersion":"1.2.4(BTC-Only)"}
|
||||
{"ExtPubKey":"zpub6rcabYFcdr41zyUNRWRyHYs2Sm86E5XV8RjjRzTFYsiCngteeZnkwaF2xuhjmM6kpHjuNpFW42BMhzPmFwXt48e1FhddMB7xidZzN4SF24K","MasterFingerprint":"5271c071","AccountKeyPath":"84'\/0'\/0'","CoboVaultFirmwareVersion":"1.2.4(BTC-Only)"}
|
||||
|
@ -156,6 +156,7 @@ describe('Watch only wallet', () => {
|
||||
);
|
||||
assert.strictEqual(w.getMasterFingerprint(), 64392470);
|
||||
assert.strictEqual(w.getMasterFingerprintHex(), '168dd603');
|
||||
assert.strictEqual(w.getDerivationPath(), "m/84'/0'/0'");
|
||||
assert.ok(w.useWithHardwareWalletEnabled());
|
||||
|
||||
const utxos = [
|
||||
@ -195,6 +196,7 @@ describe('Watch only wallet', () => {
|
||||
);
|
||||
assert.strictEqual(w.getMasterFingerprint(), 64392470);
|
||||
assert.strictEqual(w.getMasterFingerprintHex(), '168dd603');
|
||||
assert.strictEqual(w.getDerivationPath(), "m/84'/0'/1'");
|
||||
assert.ok(w.useWithHardwareWalletEnabled());
|
||||
|
||||
const utxos = [
|
||||
@ -235,10 +237,11 @@ describe('Watch only wallet', () => {
|
||||
assert.strictEqual(w.getMasterFingerprint(), 1908437330);
|
||||
assert.strictEqual(w.getMasterFingerprintHex(), '5271c071');
|
||||
assert.strictEqual(w.getLabel(), 'Wallet');
|
||||
assert.strictEqual(w.getDerivationPath(), "m/84'/0'/0'");
|
||||
assert.ok(w.useWithHardwareWalletEnabled());
|
||||
});
|
||||
|
||||
it('can import zpub with master fingerprint', async () => {
|
||||
it('can import zpub with master fingerprint and derivation path', async () => {
|
||||
const w = new WatchOnlyWallet();
|
||||
w.setSecret(require('fs').readFileSync('./tests/unit/fixtures/skeleton-walletdescriptor.txt', 'ascii'));
|
||||
w.init();
|
||||
@ -249,6 +252,7 @@ describe('Watch only wallet', () => {
|
||||
);
|
||||
assert.strictEqual(w.getMasterFingerprint(), 4167290508);
|
||||
assert.strictEqual(w.getMasterFingerprintHex(), '8cce63f8');
|
||||
assert.strictEqual(w.getDerivationPath(), "m/84'/0'/0'");
|
||||
assert.ok(!w.useWithHardwareWalletEnabled());
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user