@@ -1448,7 +1201,7 @@
Settings making coinb.in even better!
diff --git a/js/coin.js b/js/coin.js
index 87a94a68..84362e51 100644
--- a/js/coin.js
+++ b/js/coin.js
@@ -14,12 +14,11 @@
coinjs.priv = 0x80;
coinjs.multisig = 0x05;
coinjs.hdkey = {'prv':0x0488ade4, 'pub':0x0488b21e};
- coinjs.bech32 = {'charset':'qpzry9x8gf2tvdw0s3jn54khce6mua7l', 'version':0, 'hrp':'bc'};
coinjs.compressed = false;
/* other vars */
- coinjs.developer = '3K1oFZMks41C7qDYBsr72SYjapLqDuSYuN'; //bitcoin
+ coinjs.developer = '1CWHWkTWaq1K5hevimJia3cyinQsrgXUvg'; // bitcoin
/* bit(coinb.in) api vars */
coinjs.host = ('https:'==document.location.protocol?'https://':'http://')+'coinb.in/api/';
@@ -185,24 +184,6 @@
return {'address':address, 'type':'segwit', 'redeemscript':Crypto.util.bytesToHex(keyhash)};
}
- /* create a new segwit bech32 encoded address */
- coinjs.bech32Address = function(pubkey){
- var program = ripemd160(Crypto.SHA256(Crypto.util.hexToBytes(pubkey), {asBytes: true}), {asBytes: true});
- var address = coinjs.bech32_encode(coinjs.bech32.hrp, [coinjs.bech32.version].concat(coinjs.bech32_convert(program, 8, 5, true)));
- return {'address':address, 'type':'bech32', 'redeemscript':Crypto.util.bytesToHex(program)};
- }
-
- /* extract the redeemscript from a bech32 address */
- coinjs.bech32redeemscript = function(address){
- var r = false;
- var decode = coinjs.bech32_decode(address);
- if(decode){
- decode.data.shift();
- return Crypto.util.bytesToHex(coinjs.bech32_convert(decode.data, 5, 8, true));
- }
- return r;
- }
-
/* provide a privkey and return an WIF */
coinjs.privkey2wif = function(h){
var r = Crypto.util.hexToBytes(h);
@@ -305,12 +286,7 @@
return false;
}
} catch(e) {
- bech32rs = coinjs.bech32redeemscript(addr);
- if(bech32rs){
- return {'type':'bech32', 'redeemscript':bech32rs};
- } else {
- return false;
- }
+ return false;
}
}
@@ -340,126 +316,6 @@
return false;
}
- coinjs.bech32_polymod = function(values) {
- var chk = 1;
- var BECH32_GENERATOR = [0x3b6a57b2, 0x26508e6d, 0x1ea119fa, 0x3d4233dd, 0x2a1462b3];
- for (var p = 0; p < values.length; ++p) {
- var top = chk >> 25;
- chk = (chk & 0x1ffffff) << 5 ^ values[p];
- for (var i = 0; i < 5; ++i) {
- if ((top >> i) & 1) {
- chk ^= BECH32_GENERATOR[i];
- }
- }
- }
- return chk;
- }
-
- coinjs.bech32_hrpExpand = function(hrp) {
- var ret = [];
- var p;
- for (p = 0; p < hrp.length; ++p) {
- ret.push(hrp.charCodeAt(p) >> 5);
- }
- ret.push(0);
- for (p = 0; p < hrp.length; ++p) {
- ret.push(hrp.charCodeAt(p) & 31);
- }
- return ret;
- }
-
- coinjs. bech32_verifyChecksum = function(hrp, data) {
- return coinjs.bech32_polymod(coinjs.bech32_hrpExpand(hrp).concat(data)) === 1;
- }
-
- coinjs.bech32_createChecksum = function(hrp, data) {
- var values = coinjs.bech32_hrpExpand(hrp).concat(data).concat([0, 0, 0, 0, 0, 0]);
- var mod = coinjs.bech32_polymod(values) ^ 1;
- var ret = [];
- for (var p = 0; p < 6; ++p) {
- ret.push((mod >> 5 * (5 - p)) & 31);
- }
- return ret;
- }
-
- coinjs.bech32_encode = function(hrp, data) {
- var combined = data.concat(coinjs.bech32_createChecksum(hrp, data));
- var ret = hrp + '1';
- for (var p = 0; p < combined.length; ++p) {
- ret += coinjs.bech32.charset.charAt(combined[p]);
- }
- return ret;
- }
-
- coinjs.bech32_decode = function(bechString) {
- var p;
- var has_lower = false;
- var has_upper = false;
- for (p = 0; p < bechString.length; ++p) {
- if (bechString.charCodeAt(p) < 33 || bechString.charCodeAt(p) > 126) {
- return null;
- }
- if (bechString.charCodeAt(p) >= 97 && bechString.charCodeAt(p) <= 122) {
- has_lower = true;
- }
- if (bechString.charCodeAt(p) >= 65 && bechString.charCodeAt(p) <= 90) {
- has_upper = true;
- }
- }
- if (has_lower && has_upper) {
- return null;
- }
- bechString = bechString.toLowerCase();
- var pos = bechString.lastIndexOf('1');
- if (pos < 1 || pos + 7 > bechString.length || bechString.length > 90) {
- return null;
- }
- var hrp = bechString.substring(0, pos);
- var data = [];
- for (p = pos + 1; p < bechString.length; ++p) {
- var d = coinjs.bech32.charset.indexOf(bechString.charAt(p));
- if (d === -1) {
- return null;
- }
- data.push(d);
- }
- if (!coinjs.bech32_verifyChecksum(hrp, data)) {
- return null;
- }
- return {
- hrp: hrp,
- data: data.slice(0, data.length - 6)
- };
- }
-
- coinjs.bech32_convert = function(data, inBits, outBits, pad) {
- var value = 0;
- var bits = 0;
- var maxV = (1 << outBits) - 1;
-
- var result = [];
- for (var i = 0; i < data.length; ++i) {
- value = (value << inBits) | data[i];
- bits += inBits;
-
- while (bits >= outBits) {
- bits -= outBits;
- result.push((value >> bits) & maxV);
- }
- }
-
- if (pad) {
- if (bits > 0) {
- result.push((value << (outBits - bits)) & maxV);
- }
- } else {
- if (bits >= inBits) throw new Error('Excess padding');
- if ((value << (outBits - bits)) & maxV) throw new Error('Non-zero padding');
- }
-
- return result;
- }
-
coinjs.testdeterministicK = function() {
// https://github.com/bitpay/bitcore/blob/9a5193d8e94b0bd5b8e7f00038e7c0b935405a03/test/crypto/ecdsa.js
// Line 21 and 22 specify digest hash and privkey for the first 2 test vectors.
@@ -846,9 +702,6 @@
var multi = coinjs.pubkeys2MultisigAddress(pubkeys, r.signaturesRequired);
r.address = multi['address'];
r.type = 'multisig__'; // using __ for now to differentiat from the other object .type == "multisig"
- var rs = Crypto.util.bytesToHex(s.buffer);
- r.redeemscript = rs;
-
} else if((s.chunks.length==2) && (s.buffer[0] == 0 && s.buffer[1] == 20)){ // SEGWIT
r = {};
r.type = "segwit__";
@@ -862,8 +715,6 @@
r.pubkey = Crypto.util.bytesToHex(s.chunks[3]);
r.checklocktimeverify = coinjs.bytesToNum(s.chunks[0].slice());
r.address = coinjs.simpleHodlAddress(r.pubkey, r.checklocktimeverify).address;
- var rs = Crypto.util.bytesToHex(s.buffer);
- r.redeemscript = rs;
r.type = "hodl__";
}
} catch(e) {
@@ -877,10 +728,7 @@
r.spendToScript = function(address){
var addr = coinjs.addressDecode(address);
var s = coinjs.script();
- if(addr.type == "bech32"){
- s.writeOp(0);
- s.writeBytes(Crypto.util.hexToBytes(addr.redeemscript));
- } else if(addr.version==coinjs.multisig){ // multisig address
+ if(addr.version==coinjs.multisig){ // multisig address
s.writeOp(169); //OP_HASH160
s.writeBytes(addr.bytes);
s.writeOp(135); //OP_EQUAL
@@ -1034,10 +882,11 @@
}
/* add unspent to transaction */
- r.addUnspent = function(address, callback, script, segwit, sequence){
+ r.addUnspent = function(address, callback, script, segwit){
var self = this;
this.listUnspent(address, function(data){
var s = coinjs.script();
+ var pubkeyScript = s.pubkeyHash(address);
var value = 0;
var total = 0;
var x = {};
@@ -1070,8 +919,7 @@
scr = Crypto.util.bytesToHex(s.buffer);
}
- var seq = sequence || false;
- self.addinput(txhash, n, scr, seq);
+ self.addinput(txhash, n, scr);
value += u.getElementsByTagName("value")[0].childNodes[0].nodeValue*1;
total++;
}
@@ -1194,24 +1042,20 @@
return {'result':0, 'fail':'redeemscript', 'response':'redeemscript missing or not valid for segwit'};
}
+ var scriptcode = Crypto.util.hexToBytes(extract['script']);
+ if(scriptcode[0] != 0){
+ return {'result':0, 'fail':'scriptcode', 'response':'redeemscript is not valid'};
+ }
+
if(extract['value'] == -1){
return {'result':0, 'fail':'value', 'response':'unable to generate a valid segwit hash without a value'};
}
- var scriptcode = Crypto.util.hexToBytes(extract['script']);
-
// end of redeem script check
- /* P2WPKH */
- if(scriptcode.length == 20){
- scriptcode = [0x00,0x14].concat(scriptcode);
- }
-
- if(scriptcode.length == 22){
- scriptcode = scriptcode.slice(1);
- scriptcode.unshift(25, 118, 169);
- scriptcode.push(136, 172);
- }
+ scriptcode = scriptcode.slice(1);
+ scriptcode.unshift(25, 118, 169);
+ scriptcode.push(136, 172);
var value = coinjs.numToBytes(extract['value'], 8);
@@ -1292,7 +1136,8 @@
} else if(this.ins[index].script.chunks.length == 5 && this.ins[index].script.chunks[1] == 177){//OP_CHECKLOCKTIMEVERIFY
// hodl script (not signed)
return {'type':'hodl', 'signed':'false', 'signatures': 0, 'script': Crypto.util.bytesToHex(this.ins[index].script.buffer)};
- } else if((this.ins[index].script.chunks.length <= 3 && this.ins[index].script.chunks.length > 0) && ((this.ins[index].script.chunks[0].length == 22 && this.ins[index].script.chunks[0][0] == 0) || (this.ins[index].script.chunks[0].length == 20 && this.ins[index].script.chunks[1] == 0))){
+ } else if((this.ins[index].script.chunks.length <= 3 && this.ins[index].script.chunks.length > 0) && this.ins[index].script.chunks[0].length == 22 && this.ins[index].script.chunks[0][0] == 0){
+ // segwit script
var signed = ((this.witness[index]) && this.witness[index].length==2) ? 'true' : 'false';
var sigs = (signed == 'true') ? 1 : 0;
var value = -1; // no value found
@@ -1521,16 +1366,13 @@
var wif2 = coinjs.wif2pubkey(wif);
var segwit = coinjs.segwitAddress(wif2['pubkey']);
- var bech32 = coinjs.bech32Address(wif2['pubkey']);
- if((segwit['redeemscript'] == Crypto.util.bytesToHex(this.ins[index].script.chunks[0])) || (bech32['redeemscript'] == Crypto.util.bytesToHex(this.ins[index].script.chunks[0]))){
+ if(segwit['redeemscript'] == Crypto.util.bytesToHex(this.ins[index].script.chunks[0])){
var txhash = this.transactionHashSegWitV0(index, shType);
-
if(txhash.result == 1){
-
var segwitHash = Crypto.util.hexToBytes(txhash.hash);
var signature = this.transactionSig(index, wif, shType, segwitHash);
-
+
// remove any non standard data we store, i.e. input value
var script = coinjs.script();
script.writeBytes(this.ins[index].script.chunks[0]);
@@ -1553,29 +1395,14 @@
for(var y = 0; y < this.witness.length; y++){
if(!witness_used.includes(y)){
var sw = coinjs.segwitAddress(this.witness[y][1]);
- var b32 = coinjs.bech32Address(this.witness[y][1]);
- var rs = '';
-
- if(this.ins[i].script.chunks.length>=1){
- rs = Crypto.util.bytesToHex(this.ins[i].script.chunks[0]);
- } else if (this.ins[i].script.chunks.length==0){
- rs = b32['redeemscript'];
- }
-
- if((sw['redeemscript'] == rs) || (b32['redeemscript'] == rs)){
+ if(sw['redeemscript'] == Crypto.util.bytesToHex(this.ins[i].script.chunks[0])){
witness_order.push(this.witness[y]);
witness_used.push(y);
-
- // bech32, empty redeemscript
- if(b32['redeemscript'] == rs){
- this.ins[index].script = coinjs.script();
- }
break;
}
}
}
}
-
this.witness = witness_order;
}
}
diff --git a/js/coinbin.js b/js/coinbin.js
index db39b1f2..8d737fe8 100644
--- a/js/coinbin.js
+++ b/js/coinbin.js
@@ -37,17 +37,11 @@ $(document).ready(function() {
$("#walletKeys .walletSegWitRS").addClass("hidden");
if($("#walletSegwit").is(":checked")){
- if($("#walletSegwitBech32").is(":checked")){
- var sw = coinjs.bech32Address(pubkey);
- address = sw.address;
- } else {
-
- var sw = coinjs.segwitAddress(pubkey);
- address = sw.address;
- }
+ var sw = coinjs.segwitAddress(pubkey);
+ address = sw.address;
$("#walletKeys .walletSegWitRS").removeClass("hidden");
- $("#walletKeys .walletSegWitRS input:text").val(sw.redeemscript);
+ $("#walletKeys .walletSegWitRS input:text").val(sw.redeemscript);
}
$("#walletAddress").html(address);
@@ -100,25 +94,9 @@ $(document).ready(function() {
$("#openLoginStatus").html("").hide();
});
- $("#walletSegwit").click(function(){
- if($(this).is(":checked")){
- $(".walletSegwitType").attr('disabled',false);
- } else {
- $(".walletSegwitType").attr('disabled',true);
- }
- });
-
$("#walletToSegWit").click(function(){
$("#walletToBtn").html('SegWit
');
$("#walletSegwit")[0].checked = true;
- $("#walletSegwitp2sh")[0].checked = true;
- $("#openBtn").click();
- });
-
- $("#walletToSegWitBech32").click(function(){
- $("#walletToBtn").html('Bech32
');
- $("#walletSegwit")[0].checked = true;
- $("#walletSegwitBech32")[0].checked = true;
$("#openBtn").click();
});
@@ -128,6 +106,7 @@ $(document).ready(function() {
$("#openBtn").click();
});
+
$("#walletShowKeys").click(function(){
$("#walletKeys").removeClass("hidden");
$("#walletSpend").removeClass("hidden").addClass("hidden");
@@ -163,19 +142,10 @@ $(document).ready(function() {
var script = false;
if($("#walletSegwit").is(":checked")){
- if($("#walletSegwitBech32").is(":checked")){
- var sw = coinjs.bech32Address($("#walletKeys .pubkey").val());
- } else {
- var sw = coinjs.segwitAddress($("#walletKeys .pubkey").val());
- }
+ var sw = coinjs.segwitAddress($("#walletKeys .pubkey").val());
script = sw.redeemscript;
}
- var sequence = false;
- if($("#walletRBF").is(":checked")){
- sequence = 0xffffffff-2;
- }
-
tx.addUnspent($("#walletAddress").html(), function(data){
var dvalue = (data.value/100000000).toFixed(8) * 1;
@@ -195,7 +165,6 @@ $(document).ready(function() {
var signed = txunspent.sign($("#walletKeys .privkey").val());
// and finally broadcast!
-
tx2.broadcast(function(data){
if($(data).find("result").text()=="1"){
$("#walletSendConfirmStatus").removeClass('hidden').addClass('alert-success').html('txid:
'+$(data).find("txid").text()+'');
@@ -217,7 +186,7 @@ $(document).ready(function() {
$("#walletLoader").addClass("hidden");
- }, script, script, sequence);
+ }, script, script);
});
$("#walletSendBtn").click(function(){
@@ -375,16 +344,9 @@ $(document).ready(function() {
$("#newSegWitKeysBtn").click(function(){
var compressed = coinjs.compressed;
coinjs.compressed = true;
-
var s = ($("#newSegWitBrainwallet").is(":checked")) ? $("#brainwalletSegWit").val() : null;
var coin = coinjs.newKeys(s);
-
- if($("#newSegWitBech32addr").is(":checked")){
- var sw = coinjs.bech32Address(coin.pubkey);
- } else {
- var sw = coinjs.segwitAddress(coin.pubkey);
- }
-
+ var sw = coinjs.segwitAddress(coin.pubkey);
$("#newSegWitAddress").val(sw.address);
$("#newSegWitRedeemScript").val(sw.redeemscript);
$("#newSegWitPubKey").val(coin.pubkey);
@@ -654,7 +616,7 @@ $(document).ready(function() {
$.each($("#recipients .row"), function(i,o){
var a = ($(".address",o).val());
var ad = coinjs.addressDecode(a);
- if(((a!="") && (ad.version == coinjs.pub || ad.version == coinjs.multisig || ad.type=="bech32")) && $(".amount",o).val()!=""){ // address
+ if(((a!="") && (ad.version == coinjs.pub || ad.version == coinjs.multisig)) && $(".amount",o).val()!=""){ // address
// P2SH output is 32, P2PKH is 34
estimatedTxSize += (ad.version == coinjs.pub ? 34 : 32)
tx.addoutput(a, $(".amount",o).val());
@@ -673,84 +635,21 @@ $(document).ready(function() {
if(!$("#recipients .row, #inputs .row").hasClass('has-error')){
-
$("#transactionCreate textarea").val(tx.serialize());
$("#transactionCreate .txSize").html(tx.size());
- if($("#feesestnewtx").attr('est')=='y'){
- $("#fees .txhex").val($("#transactionCreate textarea").val());
- $("#feesAnalyseBtn").click();
- $("#fees .txhex").val("");
- window.location = "#fees";
- } else {
-
- $("#transactionCreate").removeClass("hidden");
+ $("#transactionCreate").removeClass("hidden");
- // Check fee against hard 0.01 as well as fluid 200 satoshis per byte calculation.
- if($("#transactionFee").val()>=0.01 || $("#transactionFee").val()>= estimatedTxSize * 200 * 1e-8){
- $("#modalWarningFeeAmount").html($("#transactionFee").val());
- $("#modalWarningFee").modal("show");
- }
+ // Check fee against hard 0.01 as well as fluid 200 satoshis per byte calculation.
+ if($("#transactionFee").val()>=0.01 || $("#transactionFee").val()>= estimatedTxSize * 200 * 1e-8){
+ $("#modalWarningFeeAmount").html($("#transactionFee").val());
+ $("#modalWarningFee").modal("show");
}
- $("#feesestnewtx").attr('est','');
} else {
$("#transactionCreateStatus").removeClass("hidden").html("One or more input or output is invalid").fadeOut().fadeIn();
}
});
- $("#feesestnewtx").click(function(){
- $(this).attr('est','y');
- $("#transactionBtn").click();
- });
-
- $("#feesestwallet").click(function(){
- $(this).attr('est','y');
- var outputs = $("#walletSpendTo .output").length;
-
- $("#fees .inputno, #fees .outputno, #fees .bytes").html(0);
- $("#fees .slider").val(0);
-
- var tx = coinjs.transaction();
- tx.listUnspent($("#walletAddress").html(), function(data){
- var inputs = $(data).find("unspent").children().length;
- if($("#walletSegwit").is(":checked")){
- $("#fees .txi_segwit").val(inputs);
- $("#fees .txi_segwit").trigger('input');
- } else {
- $("#fees .txi_regular").val(inputs);
- $("#fees .txi_regular").trigger('input');
- }
-
- $.each($("#walletSpendTo .output"), function(i,o){
- var addr = $('.addressTo',o);
- var ad = coinjs.addressDecode(addr.val());
- if (ad.version == coinjs.pub){ // p2pkh
- $("#fees .txo_p2pkh").val(($("#fees .txo_p2pkh").val()*1)+1);
- $("#fees .txo_p2pkh").trigger('input');
- } else { // p2psh
- $("#fees .txo_p2sh").val(($("#fees .txo_p2sh").val()*1)+1);
- $("#fees .txo_p2sh").trigger('input');
- }
- });
-
- if(($("#developerDonation").val()*1)>0){
- var addr = coinjs.developer;
- var ad = coinjs.addressDecode(addr);
- if (ad.version == coinjs.pub){ // p2pkh
- $("#fees .txo_p2pkh").val(($("#fees .txo_p2pkh").val()*1)+1);
- $("#fees .txo_p2pkh").trigger('input');
- } else { // p2psh
- $("#fees .txo_p2sh").val(($("#fees .txo_p2sh").val()*1)+1);
- $("#fees .txo_p2sh").trigger('input');
- }
- }
-
- });
-
- //feeStats();
- window.location = "#fees";
- });
-
$(".txidClear").click(function(){
$("#inputs .row:first input").attr('disabled',false);
$("#inputs .row:first input").val("");
@@ -854,7 +753,7 @@ $(document).ready(function() {
/* redeem from button code */
$("#redeemFromBtn").click(function(){
- var redeem = redeemingFrom($("#redeemFrom").val());
+ var redeem = redeemingFrom($("#redeemFrom").val());
document.getElementById("returnoutputaddress").value = redeem.addr;
$("#redeemFromStatus, #redeemFromAddress").addClass('hidden');
@@ -864,7 +763,7 @@ $(document).ready(function() {
}
if(redeem.from=='other'){
- $("#redeemFromStatus").removeClass('hidden').html('
The address or redeem script you have entered is invalid');
+ $("#redeemFromStatus").removeClass('hidden').html('
The address or multisig redeem script you have entered is invalid');
return false;
}
@@ -876,6 +775,7 @@ $(document).ready(function() {
var host = $(this).attr('rel');
+
if(host=='chain.so_litecoin'){
listUnspentChainso_Litecoin(redeem);
} else if(host=='chain.so_dogecoin'){
@@ -890,8 +790,8 @@ $(document).ready(function() {
if($("#redeemFromStatus").hasClass("hidden")) {
// An ethical dilemma: Should we automatically set nLockTime?
- if(redeem.from == 'redeemScript' && redeem.type == "hodl__") {
- $("#nLockTime").val(redeem.decodescript.checklocktimeverify);
+ if(redeem.from == 'redeemScript' && redeem.decodedRs.type == "hodl__") {
+ $("#nLockTime").val(redeem.decodedRs.checklocktimeverify);
} else {
$("#nLockTime").val(0);
}
@@ -905,35 +805,28 @@ $(document).ready(function() {
if(decode.version == coinjs.pub){ // regular address
r.addr = string;
r.from = 'address';
- r.redeemscript = false;
+ r.isMultisig = false;
} else if (decode.version == coinjs.priv){ // wif key
var a = coinjs.wif2address(string);
r.addr = a['address'];
r.from = 'wif';
- r.redeemscript = false;
+ r.isMultisig = false;
} else if (decode.version == coinjs.multisig){ // mulisig address
r.addr = '';
r.from = 'multisigAddress';
- r.redeemscript = false;
- } else if(decode.type == 'bech32'){
- r.addr = string;
- r.from = 'bech32';
- r.decodedRs = decode.redeemscript;
- r.redeemscript = true;
+ r.isMultisig = false;
} else {
var script = coinjs.script();
var decodeRs = script.decodeRedeemScript(string);
if(decodeRs){ // redeem script
r.addr = decodeRs['address'];
r.from = 'redeemScript';
- r.decodedRs = decodeRs.redeemscript;
- r.type = decodeRs['type'];
- r.redeemscript = true;
- r.decodescript = decodeRs;
+ r.decodedRs = decodeRs;
+ r.isMultisig = true; // not quite, may be hodl
} else { // something else
r.addr = '';
r.from = 'other';
- r.redeemscript = false;
+ r.isMultisig = false;
}
}
return r;
@@ -988,7 +881,7 @@ $(document).ready(function() {
$("#inputs .txIdN:last").val(n);
$("#inputs .txIdAmount:last").val(amount);
- if(((script.match(/^00/) && script.length==44)) || (script.length==40 && script.match(/^[a-f0-9]+$/gi))){
+ if(script.match(/^00/) && script.length==44){
s = coinjs.script();
s.writeBytes(Crypto.util.hexToBytes(script));
s.writeOp(0);
@@ -1010,7 +903,7 @@ $(document).ready(function() {
$.each($(data).find("unspent").children(), function(i,o){
var tx = $(o).find("tx_hash").text();
var n = $(o).find("tx_output_n").text();
- var script = (redeem.redeemscript==true) ? redeem.decodedRs : $(o).find("script").text();
+ var script = (redeem.isMultisig==true) ? $("#redeemFrom").val() : $(o).find("script").text();
var amount = (($(o).find("value").text()*1)/100000000).toFixed(8);
addOutput(tx, n, script, amount);
@@ -1041,7 +934,7 @@ $(document).ready(function() {
var o = data.data.txs[i];
var tx = ((o.txid).match(/.{1,2}/g).reverse()).join("")+'';
var n = o.output_no;
- var script = (redeem.redeemscript==true) ? redeem.decodedRs : o.script_hex;
+ var script = (redeem.isMultisig==true) ? $("#redeemFrom").val() : o.script_hex;
var amount = o.value;
addOutput(tx, n, script, amount);
}
@@ -1074,7 +967,7 @@ $(document).ready(function() {
$.each($(data).find("unspent").children(), function(i,o){
var tx = $(o).find("tx_hash").text();
var n = $(o).find("tx_output_n").text();
- var script = (redeem.redeemscript==true) ? redeem.decodedRs : o.script_hex;
+ var script = (redeem.isMultisig==true) ? $("#redeemFrom").val() : o.script_hex;
var amount = (($(o).find("value").text()*1)/100000000).toFixed(8);
addOutput(tx, n, script, amount);
});
@@ -1108,7 +1001,7 @@ $(document).ready(function() {
var tx = ((""+o.txid).match(/.{1,2}/g).reverse()).join("")+'';
if(tx.match(/^[a-f0-9]+$/)){
var n = o.output_no;
- var script = (redeem.redeemscript==true) ? redeem.decodedRs : o.script_hex;
+ var script = (redeem.isMultisig==true) ? $("#redeemFrom").val() : o.script_hex;
var amount = o.value;
addOutput(tx, n, script, amount);
}
@@ -1519,8 +1412,6 @@ $(document).ready(function() {
var addr = '';
if(o.script.chunks.length==5){
addr = coinjs.scripthash2address(Crypto.util.bytesToHex(o.script.chunks[2]));
- } else if((o.script.chunks.length==2) && o.script.chunks[0]==0){
- addr = coinjs.bech32_encode(coinjs.bech32.hrp, [coinjs.bech32.version].concat(coinjs.bech32_convert(o.script.chunks[1], 8, 5, true)));
} else {
var pub = coinjs.pub;
coinjs.pub = coinjs.multisig;
@@ -1578,19 +1469,7 @@ $(document).ready(function() {
var pubkey = $("#verifyScript").val();
if(pubkey.length==66 || pubkey.length==130){
try {
- $("#verifyPubKey .verifyDataSw").addClass('hidden');
$("#verifyPubKey .address").val(coinjs.pubkey2address(pubkey));
- if(pubkey.length == 66){
- var sw = coinjs.segwitAddress(pubkey);
- $("#verifyPubKey .addressSegWit").val(sw.address);
- $("#verifyPubKey .addressSegWitRedeemScript").val(sw.redeemscript);
-
- var b32 = coinjs.bech32Address(pubkey);
- $("#verifyPubKey .addressBech32").val(b32.address);
- $("#verifyPubKey .addressBech32RedeemScript").val(b32.redeemscript);
-
- $("#verifyPubKey .verifyDataSw").removeClass('hidden');
- }
$("#verifyPubKey").removeClass("hidden");
$(".verifyLink").attr('href','?verify='+$("#verifyScript").val());
return true;
@@ -1732,12 +1611,6 @@ $(document).ready(function() {
window.location.hash = "#verify";
}
- $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
- if(e.target.hash == "#fees"){
- feeStats();
- }
- })
-
$(".qrcodeBtn").click(function(){
$("#qrcode").html("");
var thisbtn = $(this).parent().parent();
@@ -1912,231 +1785,6 @@ $(document).ready(function() {
$("#redeemFromBtn").attr('rel',$("#coinjs_utxo option:selected").val());
}
-
- /* fees page code */
-
- $("#fees .slider").on('input', function(){
- $('.'+$(this).attr('rel')+' .inputno, .'+$(this).attr('rel')+' .outputno',$("#fees")).html($(this).val());
- $('.'+$(this).attr('rel')+' .estimate',$("#fees")).removeClass('hidden');
- });
-
- $("#fees .txo_p2pkh").on('input', function(){
- var outputno = $('.'+$(this).attr('rel')+' .outputno',$("#fees .txoutputs")).html();
- $('.'+$(this).attr('rel')+' .bytes',$("#fees .txoutputs")).html((outputno*$("#est_txo_p2pkh").val())+(outputno*9));
- mathFees();
- });
-
- $("#fees .txo_p2sh").on('input', function(){
- var outputno = $('.'+$(this).attr('rel')+' .outputno',$("#fees .txoutputs")).html();
- $('.'+$(this).attr('rel')+' .bytes',$("#fees .txoutputs")).html((outputno*$("#est_txo_p2sh").val())+(outputno*9));
- mathFees();
- });
-
- $("#fees .txi_regular").on('input', function(){
- var inputno = $('.'+$(this).attr('rel')+' .inputno',$("#fees .txinputs")).html();
- $('.'+$(this).attr('rel')+' .bytes',$("#fees .txinputs")).html((inputno*$("#est_txi_regular").val())+(inputno*41));
- mathFees();
- });
-
- $("#fees .txi_segwit").on('input', function(){
- var inputno = $('.'+$(this).attr('rel')+' .inputno',$("#fees .txinputs")).html();
- var bytes = 0;
- if(inputno >= 1){
- bytes = 2;
- bytes += (inputno*32);
- bytes += (inputno*$("#est_txi_segwit").val());
- bytes += (inputno*(41))
- }
-
- bytes = bytes.toFixed(0);
- $('.'+$(this).attr('rel')+' .bytes',$("#fees .txinputs")).html(bytes);
- mathFees();
- });
-
- $("#fees .txi_multisig").on('input', function(){
- var inputno = $('.'+$(this).attr('rel')+' .inputno',$("#fees .txinputs")).html();
- $('.'+$(this).attr('rel')+' .bytes',$("#fees .txinputs")).html((inputno*$("#est_txi_multisig").val())+(inputno*41));
- mathFees();
- });
-
- $("#fees .txi_hodl").on('input', function(){
- var inputno = $('.'+$(this).attr('rel')+' .inputno',$("#fees .txinputs")).html();
- $('.'+$(this).attr('rel')+' .bytes',$("#fees .txinputs")).html((inputno*$("#est_txi_hodl").val())+(inputno*41));
- mathFees();
- });
-
- $("#fees .txi_unknown").on('input', function(){
- var inputno = $('.'+$(this).attr('rel')+' .inputno',$("#fees .txinputs")).html();
- $('.'+$(this).attr('rel')+' .bytes',$("#fees .txinputs")).html((inputno*$("#est_txi_unknown").val())+(inputno*41));
- mathFees();
- });
-
- $("#fees .sliderbtn.down").click(function(){
- var val = $(".slider",$(this).parent().parent()).val()*1;
- if(val>($(".slider",$(this).parent().parent()).attr('min')*1)){
- $(".slider",$(this).parent().parent()).val(val-1);
- $(".slider",$(this).parent().parent()).trigger('input');
- }
- });
-
- $("#fees .sliderbtn.up").click(function(){
- var val = $(".slider",$(this).parent().parent()).val()*1;
- if(val<($(".slider",$(this).parent().parent()).attr('max')*1)){
- $(".slider",$(this).parent().parent()).val(val+1);
- $(".slider",$(this).parent().parent()).trigger('input');
- }
- });
-
- $("#advancedFeesCollapse").click(function(){
- if($("#advancedFees").hasClass('hidden')){
- $("span",this).removeClass('glyphicon-collapse-down').addClass('glyphicon-collapse-up');
- $("#advancedFees").removeClass("hidden");
- } else {
- $("span",this).removeClass('glyphicon-collapse-up').addClass('glyphicon-collapse-down');
- $("#advancedFees").addClass("hidden");
- }
- });
-
- $("#feesAnalyseBtn").click(function(){
- if(!$("#fees .txhex").val().match(/^[a-f0-9]+$/ig)){
- alert('You must provide a hex encoded transaction');
- return;
- }
-
- var tx = coinjs.transaction();
- var deserialized = tx.deserialize($("#fees .txhex").val());
-
- $("#fees .txoutputs .outputno, #fees .txinputs .inputno").html("0");
- $("#fees .txoutputs .bytes, #fees .txinputs .bytes").html("0");
- $("#fees .slider").val(0);
-
- for(var i = 0; i < deserialized.ins.length; i++){
- var script = deserialized.extractScriptKey(i);
- var size = 41;
- if(script.type == 'segwit'){
- if(deserialized.witness[i]){
- size += deserialized.ins[i].script.buffer.length / 2;
- for(w in deserialized.witness[i]){
- size += (deserialized.witness[i][w].length / 2) /4;
- }
- } else {
- size += $("#est_txi_segwit").val()*1;
- }
- $("#fees .segwit .inputno").html(($("#fees .segwit .inputno").html()*1)+1);
- $("#fees .txi_segwit").val(($("#fees .txi_segwit").val()*1)+1);
- $("#fees .segwit .bytes").html(($("#fees .segwit .bytes").html()*1)+size);
-
- } else if(script.type == 'multisig'){
- var s = coinjs.script();
- var rs = s.decodeRedeemScript(script.script);
- size += 4 + ((script.script.length / 2) + (73 * rs.signaturesRequired));
- $("#fees .multisig .inputno").html(($("#fees .multisig .inputno").html()*1)+1);
- $("#fees .txi_multisig").val(($("#fees .txi_multisig").val()*1)+1);
- $("#fees .multisig .bytes").html(($("#fees .multisig .bytes").html()*1)+size);
-
- } else if(script.type == 'hodl'){
- size += 78;
- $("#fees .hodl .inputno").html(($("#fees .hodl .inputno").html()*1)+1);
- $("#fees .txi_hodl").val(($("#fees .txi_hodl").val()*1)+1);
- $("#fees .hodl .bytes").html(($("#fees .hodl .bytes").html()*1)+size);
-
- } else if(script.type == 'empty' || script.type == 'scriptpubkey'){
- if(script.signatures == 1){
- size += script.script.length / 2;
- } else {
- size += $("#est_txi_regular").val()*1;
- }
-
- $("#fees .regular .inputno").html(($("#fees .regular .inputno").html()*1)+1);
- $("#fees .txi_regular").val(($("#fees .txi_regular").val()*1)+1);
- $("#fees .regular .bytes").html(($("#fees .regular .bytes").html()*1)+size);
-
- } else if(script.type == 'unknown'){
- size += script.script.length / 2;
- $("#fees .unknown .inputno").html(($("#fees .unknown .inputno").html()*1)+1);
- $("#fees .txi_unknown").val(($("#fees .txi_unknown").val()*1)+1);
- $("#fees .unknown .bytes").html(($("#fees .unknown .bytes").html()*1)+size);
- }
- }
-
- for(var i = 0; i < deserialized.outs.length; i++){
- if(deserialized.outs[i].script.buffer[0]==118){
- $("#fees .txoutputs .p2pkh .outputno").html(($("#fees .txoutputs .p2pkh .outputno").html()*1)+1);
- $("#fees .txoutputs .p2pkh .bytes").html(($("#fees .txoutputs .p2pkh .bytes").html()*1)+34);
- $("#fees .txo_p2pkh").val(($("#fees .txo_p2pkh").val()*1)+1);
- } else if (deserialized.outs[i].script.buffer[0]==169){
- $("#fees .txoutputs .p2sh .outputno").html(($("#fees .txoutputs .p2sh .outputno").html()*1)+1);
- $("#fees .txoutputs .p2sh .bytes").html(($("#fees .txoutputs .p2sh .bytes").html()*1)+32);
- $("#fees .txo_p2sh").val(($("#fees .txo_p2sh").val()*1)+1);
- }
- }
-
- feeStats();
- });
-
- $("#feeStatsReload").click(function(){
- feeStats();
- });
-
- function mathFees(){
-
- var inputsTotal = 0;
- var inputsBytes = 0;
- $.each($(".inputno"), function(i,o){
- inputsTotal += ($(o).html()*1);
- inputsBytes += ($(".bytes",$(o).parent()).html()*1);
- });
-
- $("#fees .txinputs .txsize").html(inputsBytes.toFixed(0));
- $("#fees .txinputs .txtotal").html(inputsTotal.toFixed(0));
-
- var outputsTotal = 0;
- var outputsBytes = 0;
- $.each($(".outputno"), function(i,o){
- outputsTotal += ($(o).html()*1);
- outputsBytes += ($(".bytes",$(o).parent()).html()*1);
- });
-
- $("#fees .txoutputs .txsize").html(outputsBytes.toFixed(0));
- $("#fees .txoutputs .txtotal").html(outputsTotal.toFixed(0));
-
- var totalBytes = 10 + outputsBytes + inputsBytes;
- if((!isNaN($("#fees .feeSatByte:first").html())) && totalBytes > 10){
- var recommendedFee = ((totalBytes * $(".feeSatByte").html())/100000000).toFixed(8);
- $(".recommendedFee").html(recommendedFee);
- $(".feeTxSize").html(totalBytes);
- } else {
- $(".recommendedFee").html((0).toFixed(8));
- $(".feeTxSize").html(0);
- }
- };
-
- function feeStats(){
- $("#feeStatsReload").attr('disabled',true);
- $.ajax ({
- type: "GET",
- url: "https://coinb.in/api/?uid=1&key=12345678901234567890123456789012&setmodule=fees&request=stats",
- dataType: "xml",
- error: function(data) {
- },
- success: function(data) {
- $("#fees .recommended .blockHeight").html('
'+$(data).find("height").text()+'');
- $("#fees .recommended .blockHash").html($(data).find("block").text());
- $("#fees .recommended .blockTime").html($(data).find("timestamp").text());
- $("#fees .recommended .blockDateTime").html(unescape($(data).find("datetime").text()).replace(/\+/g,' '));
- $("#fees .recommended .txId").html('
'+$(data).find("txid").text()+'');
- $("#fees .recommended .txSize").html($(data).find("txsize").text());
- $("#fees .recommended .txFee").html($(data).find("txfee").text());
- $("#fees .feeSatByte").html($(data).find("satbyte").text());
-
- mathFees();
- },
- complete: function(data, status){
- $("#feeStatsReload").attr('disabled', false);
- }
- });
- }
-
/* capture mouse movement to add entropy */
var IE = document.all?true:false // Boolean, is browser IE?
if (!IE) document.captureEvents(Event.MOUSEMOVE)
@@ -2168,5 +1816,4 @@ $(document).ready(function() {
return true;
};
-
});
diff --git a/sha1sum b/sha1sum
index 52fa46cb..e31f3f5e 100644
--- a/sha1sum
+++ b/sha1sum
@@ -1,9 +1,9 @@
----- Version 1.4 2018.12.28 ---
+---- Version 1.3 2017.12.09 ---
77e4519962e2f6a9fc93342137dbb31c33b76b04 ./js/aes.js
3a09a8fc0cfe828b57fc798d668234d0490ee1a6 ./js/bootstrap-datetimepicker.min.js
253711c6d825de55a8360552573be950da180614 ./js/bootstrap.min.js
-e9be49c8cdc51931749a8750361eaea2e5de4e61 ./js/coinbin.js
-d7e828cea4e9af4934cc500d022cb1b6ce12cbb0 ./js/coin.js
+934f5330156c159378c370f14b46862d54ff5b35 ./js/coinbin.js
+31fbebf65d9cae8f26761cb057c4fb1b97339d08 ./js/coin.js
988565bc2cb402d63ed5c5fd7ff47c4278efc2c5 ./js/collapse.js
9ba5ede3d7f9d4c8fd623395f196adfdcf7e970f ./js/crypto-min.js
f7c09f2f5a721371e7d478050119f7e2d58e3ef9 ./js/crypto-sha256-hmac.js
@@ -21,8 +21,7 @@ ad038e1f39646b68ae666324ed4c2882a8c42474 ./js/qrcode.js
255c58c17e63eb54adb3cd02b5c06224c67fc364 ./css/bootstrap-datetimepicker.min.css
ed29315e0ffb3f14382431f2724235bf67f44eb3 ./css/bootstrap.min.css
fc6b4268fbd57ad95d2b41a1d4d6866f222fbdb2 ./css/bootstrap-theme.min.css
-eb54f374256b75a17f274847b4ca9985fd046f9f ./css/style.css
-2e3217a3f3b7c2fb30562ab9a4ef9a407ae81897 ./images/btc32x.png
+4198ed869836ea5727ad6b80bf2df0a9c1a83244 ./css/style.css
8ac24915d59cef71c542e7cb7d7e153f560cba1f ./images/coinbin.gif
f2af060f1cadbc9065c8c465c648dc01be67cc12 ./images/loader.gif
86b6f62b7853e67d3e635f6512a5a5efc58ea3c3 ./fonts/glyphicons-halflings-regular.eot
@@ -30,5 +29,8 @@ ca35b697d99cae4d1b60f2d60fcd37771987eb07 ./fonts/glyphicons-halflings-regular.w
de51a8494180a6db074af2dee2383f0a363c5b08 ./fonts/glyphicons-halflings-regular.svg
278e49a86e634da6f2a02f3b47dd9d2a8f26210f ./fonts/glyphicons-halflings-regular.woff
44bc1850f570972267b169ae18f1cb06b611ffa2 ./fonts/glyphicons-halflings-regular.ttf
-c024021c71cba503979a859d23cbf7a88b570d82 ./README.md
-88c2d9787969c3ecbcfe0865cfcffbd8c04d0693 ./index.html
+d8a324a13501cd5705dc26b945fc8088f00907ae ./README.md
+4b0ef8c0520f45540f142b562e9fbf00145f219c ./index.html
+
+
+