From ecb18acb0fd5ad03e60a81a9d843079a60be24ff Mon Sep 17 00:00:00 2001 From: btc Date: Wed, 20 Sep 2017 09:56:20 +0000 Subject: [PATCH] code was missing for the segwit feature from the #wallet section --- index.html | 4 ++-- js/coin.js | 14 ++++++++++++-- js/coinbin.js | 7 +++---- sha1sum | 8 ++++---- 4 files changed, 21 insertions(+), 12 deletions(-) diff --git a/index.html b/index.html index df9422f..81f64c8 100644 --- a/index.html +++ b/index.html @@ -5,8 +5,8 @@ Bitcoin Wallet by Coinb.in - - + + diff --git a/js/coin.js b/js/coin.js index 20294f5..054f3ab 100644 --- a/js/coin.js +++ b/js/coin.js @@ -876,7 +876,7 @@ } /* add unspent to transaction */ - r.addUnspent = function(address, callback, script){ + r.addUnspent = function(address, callback, script, segwit){ var self = this; this.listUnspent(address, function(data){ var s = coinjs.script(); @@ -902,8 +902,18 @@ var n = u.getElementsByTagName("tx_output_n")[0].childNodes[0].nodeValue; var scr = script || u.getElementsByTagName("script")[0].childNodes[0].nodeValue; - self.addinput(txhash, n, scr); + if(segwit){ + /* this is a small hack to include the value with the redeemscript to make the signing procedure smoother. + It is not standard and removed during the signing procedure. */ + s = coinjs.script(); + s.writeBytes(Crypto.util.hexToBytes(script)); + s.writeOp(0); + s.writeBytes(coinjs.numToBytes(u.getElementsByTagName("value")[0].childNodes[0].nodeValue*1, 8)); + scr = Crypto.util.bytesToHex(s.buffer); + } + + self.addinput(txhash, n, scr); value += u.getElementsByTagName("value")[0].childNodes[0].nodeValue*1; total++; } diff --git a/js/coinbin.js b/js/coinbin.js index 597fe41..5238998 100644 --- a/js/coinbin.js +++ b/js/coinbin.js @@ -124,7 +124,7 @@ $(document).ready(function() { var script = false; if($("#walletSegwit").is(":checked")){ var sw = coinjs.segwitAddress($("#walletKeys .pubkey").val()); - scrip = sw.redeemscript; + script = sw.redeemscript; } tx.addUnspent($("#walletAddress").html(), function(data){ @@ -148,7 +148,7 @@ $(document).ready(function() { // 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()); + $("#walletSendConfirmStatus").removeClass('hidden').addClass('alert-success').html('txid: '+$(data).find("txid").text()+''); } else { $("#walletSendConfirmStatus").removeClass('hidden').addClass('alert-danger').html(unescape($(data).find("response").text()).replace(/\+/g,' ')); $("#walletSendFailTransaction").removeClass('hidden'); @@ -167,7 +167,7 @@ $(document).ready(function() { $("#walletLoader").addClass("hidden"); - }, script); + }, script, script); }); $("#walletSendBtn").click(function(){ @@ -1262,7 +1262,6 @@ $(document).ready(function() { var tx = coinjs.transaction(); try { var decode = tx.deserialize($("#verifyScript").val()); - // console.log(decode); $("#verifyTransactionData .transactionVersion").html(decode['version']); $("#verifyTransactionData .transactionSize").html(decode.size()+' bytes'); $("#verifyTransactionData .transactionLockTime").html(decode['lock_time']); diff --git a/sha1sum b/sha1sum index a45746c..62a5f36 100644 --- a/sha1sum +++ b/sha1sum @@ -1,9 +1,9 @@ ----- Version 1.3 2017.09.16 ---- +---- Version 1.3 2017.09.20 ---- 77e4519962e2f6a9fc93342137dbb31c33b76b04 ./js/aes.js 3a09a8fc0cfe828b57fc798d668234d0490ee1a6 ./js/bootstrap-datetimepicker.min.js 253711c6d825de55a8360552573be950da180614 ./js/bootstrap.min.js -618db47822494e730a8fa93cfab985332872b93e ./js/coinbin.js -b2b1b00455dd2d1f168dc68b6efdbb1de817b5d0 ./js/coin.js +3ac0e33ea28610e6f784658efcd88802bdd18119 ./js/coinbin.js +466bd554f3466c477cd13bb355a4df343749b8b9 ./js/coin.js 988565bc2cb402d63ed5c5fd7ff47c4278efc2c5 ./js/collapse.js 9ba5ede3d7f9d4c8fd623395f196adfdcf7e970f ./js/crypto-min.js f7c09f2f5a721371e7d478050119f7e2d58e3ef9 ./js/crypto-sha256-hmac.js @@ -30,4 +30,4 @@ de51a8494180a6db074af2dee2383f0a363c5b08 ./fonts/glyphicons-halflings-regular.s 278e49a86e634da6f2a02f3b47dd9d2a8f26210f ./fonts/glyphicons-halflings-regular.woff 44bc1850f570972267b169ae18f1cb06b611ffa2 ./fonts/glyphicons-halflings-regular.ttf d8a324a13501cd5705dc26b945fc8088f00907ae ./README.md -cc101e4b9718116bb767f7cbd04cab816ca32b66 ./index.html +45bb7cbfe003039b3e527ecc38a18786de55a843 ./index.html