mirror of
https://github.com/ok2/coinbin.git
synced 2026-04-24 11:44:02 +02:00
Fix address generation for HD wallet with different types on simple path scheme.
This commit is contained in:
parent
00519cb2ab
commit
40a235eb04
21
js/coin.js
21
js/coin.js
@ -706,23 +706,34 @@
|
|||||||
var ecparams = EllipticCurve.getSECCurveByName("secp256k1");
|
var ecparams = EllipticCurve.getSECCurveByName("secp256k1");
|
||||||
var curve = ecparams.getCurve();
|
var curve = ecparams.getCurve();
|
||||||
|
|
||||||
var k, key, pubkey, o;
|
var k, key, pubkey, o, addr_format, address_fun, address;
|
||||||
|
|
||||||
o = coinjs.clone(this);
|
o = coinjs.clone(this);
|
||||||
o.chain_code = ir;
|
o.chain_code = ir;
|
||||||
o.child_index = i;
|
o.child_index = i;
|
||||||
|
|
||||||
|
addr_format = $("#verifyHDaddress .derivation_addr_format").val();
|
||||||
|
if (addr_format == "bech32") {
|
||||||
|
address_fun = function(pk) { return coinjs.bech32Address(pk); };
|
||||||
|
} else if (addr_format == "segwit") {
|
||||||
|
address_fun = function(pk) { return coinjs.segwitAddress(pk); };
|
||||||
|
} else {
|
||||||
|
address_fun = function(pk) {
|
||||||
|
return {'address': coinjs.pubkey2address(pubkey), 'redeemscript': ''};
|
||||||
|
};
|
||||||
|
}
|
||||||
if(this.type=='private'){
|
if(this.type=='private'){
|
||||||
// derive key pair from from a xprv key
|
// derive key pair from from a xprv key
|
||||||
k = il.add(new BigInteger([0].concat(Crypto.util.hexToBytes(this.keys.privkey)))).mod(ecparams.getN());
|
k = il.add(new BigInteger([0].concat(Crypto.util.hexToBytes(this.keys.privkey)))).mod(ecparams.getN());
|
||||||
key = Crypto.util.bytesToHex(k.toByteArrayUnsigned());
|
key = Crypto.util.bytesToHex(k.toByteArrayUnsigned());
|
||||||
|
|
||||||
pubkey = coinjs.newPubkey(key);
|
pubkey = coinjs.newPubkey(key);
|
||||||
|
address = address_fun(pubkey);
|
||||||
o.keys = {'privkey':key,
|
o.keys = {'privkey':key,
|
||||||
'pubkey':pubkey,
|
'pubkey':pubkey,
|
||||||
'wif':coinjs.privkey2wif(key),
|
'wif':coinjs.privkey2wif(key),
|
||||||
'address':coinjs.pubkey2address(pubkey)};
|
'address':address.address,
|
||||||
|
'script':address.redeemscript};
|
||||||
|
|
||||||
} else if (this.type=='public'){
|
} else if (this.type=='public'){
|
||||||
// derive xpub key from an xpub key
|
// derive xpub key from an xpub key
|
||||||
@ -739,9 +750,11 @@
|
|||||||
publicKeyBytesCompressed.unshift(0x03)
|
publicKeyBytesCompressed.unshift(0x03)
|
||||||
}
|
}
|
||||||
pubkey = Crypto.util.bytesToHex(publicKeyBytesCompressed);
|
pubkey = Crypto.util.bytesToHex(publicKeyBytesCompressed);
|
||||||
|
address = address_fun(pubkey);
|
||||||
|
|
||||||
o.keys = {'pubkey':pubkey,
|
o.keys = {'pubkey':pubkey,
|
||||||
'address':coinjs.pubkey2address(pubkey)}
|
'address':address.address,
|
||||||
|
'script':address.redeemscript}
|
||||||
} else {
|
} else {
|
||||||
// fail
|
// fail
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user