mirror of
https://github.com/ok2/coinbin.git
synced 2026-05-09 18:15:23 +02:00
Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| cea94af32f | |||
| 3b1e44e4b4 | |||
| 06054a7000 | |||
| 6a6c2c6beb | |||
| 04609947e8 | |||
| 40a235eb04 | |||
| 20bf365d29 | |||
| 632572fc66 | |||
| 00519cb2ab | |||
| f408c9b251 | |||
| bd82cfd76f | |||
| 27a2d4efb1 | |||
| 704f2c96a3 | |||
| 29baeff8c8 |
+26
-4
@@ -1206,16 +1206,16 @@
|
||||
<p>The path of key derivation</p>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-8">
|
||||
<div class="col-md-6">
|
||||
<b>Path</b><br>
|
||||
<select class="form-control" id="hdpathtype"">
|
||||
<select class="form-control" id="hdpathtype">
|
||||
<option value="simple">Simple: m/i</option>
|
||||
<option value="custom">Custom</option>
|
||||
</select>
|
||||
|
||||
<div id="hdpath" class="hidden" style="margin-top:4px">
|
||||
<span class="input-group">
|
||||
<input type="text" class="form-control" value="m/0/1"> <br>
|
||||
<input type="text" class="form-control" value="m/0/1" title="WARNING: see #settings page when using hardened paths!"> <br>
|
||||
<span class="input-group-addon"> / </span>
|
||||
</span>
|
||||
</div>
|
||||
@@ -1231,6 +1231,15 @@
|
||||
<input type="text" class="form-control derivation_index_end" value="1">
|
||||
</div>
|
||||
|
||||
<div class="col-md-2">
|
||||
<b>Address format</b><br>
|
||||
<select class="form-control derivation_addr_format">
|
||||
<option value="bech32">Bech32</option>
|
||||
<option value="segwit">SegWit</option>
|
||||
<option value="legacy">Legacy</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<hr>
|
||||
@@ -1241,7 +1250,7 @@
|
||||
<div class="derived_data">
|
||||
<table class="table table-striped table-hover">
|
||||
<thead>
|
||||
<tr><td><b>Index</b></td><td><b>Address</b><td><b>Private Key (WIF)</b></td></td><td><b>Extended xPub</b></td><td><b>Extended xPrv</b></td></tr>
|
||||
<tr><td><b>Index</b></td><td><b>Address</b></td><td><b>Redeem script</b></td><td><b>Private Key (WIF)</b></td><td><b>Extended xPub</b></td><td><b>Extended xPrv</b></td></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
</tbody>
|
||||
@@ -1471,6 +1480,19 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<hr>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<b>HD wallet hardened path derivation</b>: <br>
|
||||
<p class="text-muted">The path derivation for hardened paths was calculated wrong in earlier versions of coinb.in. Please select the old path derivation to recover HD wallet keys generated with older version of coinb.in.</p>
|
||||
<select class="form-control" id="coinjs_derivation">
|
||||
<option value="bip32_derivation">BIP32 compliant derivation</option>
|
||||
<option value="coinbin_broken">Old (broken) coinb.in path derivation</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<br>
|
||||
|
||||
<div id="statusSettings" class="hidden alert">
|
||||
|
||||
+35
-6
@@ -18,6 +18,8 @@
|
||||
|
||||
coinjs.compressed = false;
|
||||
|
||||
coinjs.hd_derivation = "bip32_derivation";
|
||||
|
||||
/* other vars */
|
||||
coinjs.developer = '33tht1bKDgZVxb39MnZsWa8oxHXHvUYE4G'; //bitcoin
|
||||
|
||||
@@ -619,10 +621,20 @@
|
||||
var privkey = (r.key_bytes).slice(1, 33);
|
||||
var privkeyHex = Crypto.util.bytesToHex(privkey);
|
||||
var pubkey = coinjs.newPubkey(privkeyHex);
|
||||
var addr_format = $("#verifyHDaddress .derivation_addr_format").val();
|
||||
if (addr_format == "bech32") {
|
||||
var address = coinjs.bech32Address(pubkey);
|
||||
} else if (addr_format == "segwit") {
|
||||
var address = coinjs.segwitAddress(pubkey);
|
||||
} else {
|
||||
var address = {'address': coinjs.pubkey2address(pubkey),
|
||||
'redeemscript': ''};
|
||||
}
|
||||
|
||||
r.keys = {'privkey':privkeyHex,
|
||||
'pubkey':pubkey,
|
||||
'address':coinjs.pubkey2address(pubkey),
|
||||
'address':address.address,
|
||||
'script':address.redeemscript,
|
||||
'wif':coinjs.privkey2wif(privkeyHex)};
|
||||
|
||||
} else if(r.key_bytes[0] == 0x02 || r.key_bytes[0] == 0x03) {
|
||||
@@ -686,7 +698,11 @@
|
||||
r.derive = function(i){
|
||||
|
||||
i = (i)?i:0;
|
||||
var blob = (Crypto.util.hexToBytes(this.keys.pubkey)).concat(coinjs.numToBytes(i,4).reverse());
|
||||
if ((i >= 0x80000000) && (coinjs.hd_derivation == "bip32_derivation")) {
|
||||
var blob = (Crypto.util.hexToBytes("00").concat(Crypto.util.hexToBytes(this.keys.privkey)).concat(coinjs.numToBytes(i,4).reverse()));
|
||||
} else {
|
||||
var blob = (Crypto.util.hexToBytes(this.keys.pubkey)).concat(coinjs.numToBytes(i,4).reverse());
|
||||
}
|
||||
|
||||
var j = new jsSHA(Crypto.util.bytesToHex(blob), 'HEX');
|
||||
var hash = j.getHMAC(Crypto.util.bytesToHex(r.chain_code), "HEX", "SHA-512", "HEX");
|
||||
@@ -697,23 +713,34 @@
|
||||
var ecparams = EllipticCurve.getSECCurveByName("secp256k1");
|
||||
var curve = ecparams.getCurve();
|
||||
|
||||
var k, key, pubkey, o;
|
||||
var k, key, pubkey, o, addr_format, address_fun, address;
|
||||
|
||||
o = coinjs.clone(this);
|
||||
o.chain_code = ir;
|
||||
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(pk), 'redeemscript': ''};
|
||||
};
|
||||
}
|
||||
if(this.type=='private'){
|
||||
// derive key pair from from a xprv key
|
||||
k = il.add(new BigInteger([0].concat(Crypto.util.hexToBytes(this.keys.privkey)))).mod(ecparams.getN());
|
||||
key = Crypto.util.bytesToHex(k.toByteArrayUnsigned());
|
||||
|
||||
pubkey = coinjs.newPubkey(key);
|
||||
|
||||
address = address_fun(pubkey);
|
||||
o.keys = {'privkey':key,
|
||||
'pubkey':pubkey,
|
||||
'wif':coinjs.privkey2wif(key),
|
||||
'address':coinjs.pubkey2address(pubkey)};
|
||||
'address':address.address,
|
||||
'script':address.redeemscript};
|
||||
|
||||
} else if (this.type=='public'){
|
||||
// derive xpub key from an xpub key
|
||||
@@ -730,9 +757,11 @@
|
||||
publicKeyBytesCompressed.unshift(0x03)
|
||||
}
|
||||
pubkey = Crypto.util.bytesToHex(publicKeyBytesCompressed);
|
||||
address = address_fun(pubkey);
|
||||
|
||||
o.keys = {'pubkey':pubkey,
|
||||
'address':coinjs.pubkey2address(pubkey)}
|
||||
'address':address.address,
|
||||
'script':address.redeemscript}
|
||||
} else {
|
||||
// fail
|
||||
}
|
||||
|
||||
+16
-3
@@ -1704,19 +1704,29 @@ $(document).ready(function() {
|
||||
|
||||
function deriveHDaddress() {
|
||||
var hd = coinjs.hd($("#verifyHDaddress .hdKey").html());
|
||||
var index_start = $("#verifyHDaddress .derivation_index_start").val()*1;
|
||||
var index_end = $("#verifyHDaddress .derivation_index_end").val()*1;
|
||||
var index_start = $("#verifyHDaddress .derivation_index_start").val();
|
||||
if ((index_start.length > 1) && (index_start[index_start.length - 1] == '\'')) {
|
||||
var use_private_index = '\'';
|
||||
index_start = index_start.replace(/[']/, "") * 1;
|
||||
} else {
|
||||
var use_private_index = '';
|
||||
index_start = index_start.replace(/[']/, "") * 1;
|
||||
}
|
||||
var index_end = $("#verifyHDaddress .derivation_index_end").val().replace(/[']/, "") * 1;
|
||||
$("#verifyHDaddress .derivation_index_end").val(index_end + use_private_index);
|
||||
var html = '';
|
||||
$("#verifyHDaddress .derived_data table tbody").html("");
|
||||
for(var i=index_start;i<=index_end;i++){
|
||||
if($("#hdpathtype option:selected").val()=='simple'){
|
||||
var derived = hd.derive(i);
|
||||
} else {
|
||||
var derived = hd.derive_path(($("#hdpath input").val().replace(/\/+$/, ""))+'/'+i);
|
||||
var derived = hd.derive_path(($("#hdpath input").val().replace(/\/+$/, ""))+'/'+i+use_private_index);
|
||||
$("#hdpath").removeClass(); // make it visible
|
||||
}
|
||||
html += '<tr>';
|
||||
html += '<td>'+i+'</td>';
|
||||
html += '<td><input type="text" class="form-control" value="'+derived.keys.address+'" readonly></td>';
|
||||
html += '<td><input type="text" class="form-control" value="'+derived.keys.script+'" readonly></td>';
|
||||
html += '<td><input type="text" class="form-control" value="'+((derived.keys.wif)?derived.keys.wif:'')+'" readonly></td>';
|
||||
html += '<td><input type="text" class="form-control" value="'+derived.keys_extended.pubkey+'" readonly></td>';
|
||||
html += '<td><input type="text" class="form-control" value="'+((derived.keys_extended.privkey)?derived.keys_extended.privkey:'')+'" readonly></td>';
|
||||
@@ -1917,6 +1927,8 @@ $(document).ready(function() {
|
||||
coinjs.hdkey.pub = $("#coinjs_hdpub").val()*1;
|
||||
coinjs.hdkey.prv = $("#coinjs_hdprv").val()*1;
|
||||
|
||||
coinjs.hd_derivation = $("#coinjs_derivation").val();
|
||||
|
||||
configureBroadcast();
|
||||
configureGetUnspentTx();
|
||||
|
||||
@@ -1962,6 +1974,7 @@ $(document).ready(function() {
|
||||
$("#coinjs_multisig").val(o[2]);
|
||||
$("#coinjs_hdpub").val(o[3]);
|
||||
$("#coinjs_hdprv").val(o[4]);
|
||||
$("#coinjs_derivation").val(o[7]);
|
||||
|
||||
// hide/show custom screen
|
||||
if($("option:selected",this).val()=="custom"){
|
||||
|
||||
Reference in New Issue
Block a user