From cedc6dddafebdd2b1ec86c770c7c122da258ce8e Mon Sep 17 00:00:00 2001 From: "Denilson M. Amorim" Date: Tue, 29 Dec 2015 00:00:11 -0300 Subject: [PATCH] Fix endianess of checklocktimeverify --- js/coin.js | 14 +++++++------- js/coinbin.js | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/js/coin.js b/js/coin.js index 550d789..06d5781 100644 --- a/js/coin.js +++ b/js/coin.js @@ -141,14 +141,14 @@ may throw a string on failure! */ - coinjs.simpleHodlAddress = function(pubkey, locktime) { + coinjs.simpleHodlAddress = function(pubkey, checklocktimeverify) { - if(locktime < 0) { - throw "Locktime is negative."; + if(checklocktimeverify < 0) { + throw "Parameter for OP_CHECKLOCKTIMEVERIFY is negative."; } var s = coinjs.script(); - s.writeBytes(Crypto.util.hexToBytes(locktime.toString(16))); + s.writeBytes(Crypto.util.hexToBytes(checklocktimeverify.toString(16)).reverse()); s.writeOp(177);//OP_CHECKLOCKTIMEVERIFY s.writeOp(117);//OP_DROP s.writeBytes(Crypto.util.hexToBytes(pubkey)); @@ -681,11 +681,11 @@ r.address = multi['address']; r.type = 'multisig__'; // using __ for now to differentiat from the other object .type == "multisig" } else if(s.chunks.length == 5 && s.chunks[1] == 177 && s.chunks[2] == 117 && s.chunks[4] == 172){ - // ^ OP_CHECKLOCKTIMEVERIFY OP_DROP OP_CHECKSIG ^ + // ^ OP_CHECKLOCKTIMEVERIFY OP_DROP OP_CHECKSIG ^ r = {} r.pubkey = Crypto.util.bytesToHex(s.chunks[3]); - r.locktime = parseInt(Crypto.util.bytesToHex(s.chunks[0]), 16); // TODO is this endian safe? - r.address = coinjs.simpleHodlAddress(r.pubkey, r.locktime).address; + r.checklocktimeverify = parseInt(Crypto.util.bytesToHex(s.chunks[0].slice().reverse()), 16); + r.address = coinjs.simpleHodlAddress(r.pubkey, r.checklocktimeverify).address; r.type = "hodl__"; } } catch(e) { diff --git a/js/coinbin.js b/js/coinbin.js index 7b8ef2c..c6a1bbc 100644 --- a/js/coinbin.js +++ b/js/coinbin.js @@ -635,7 +635,7 @@ $(document).ready(function() { if($("#redeemFromStatus").hasClass("hidden")) { // An ethical dilemma: Should we automatically set nLockTime? if(redeem.from == 'redeemScript' && redeem.decodedRs.type == "hodl__") { - $("#nLockTime").val(redeem.decodedRs.locktime); + $("#nLockTime").val(redeem.decodedRs.checklocktimeverify); } else { $("#nLockTime").val(0); } @@ -1007,7 +1007,7 @@ $(document).ready(function() { var d = $("#verifyRsDataHodl .date").data("DateTimePicker"); $("#verifyRsDataHodl .address").val(decode['address']); $("#verifyRsDataHodl .pubkey").val(coinjs.pubkey2address(decode['pubkey'])); - $("#verifyRsDataHodl .date").val(decode['locktime'] >= 500000000? moment.unix(decode['locktime']).format("MM/DD/YYYY HH:mm") : decode['locktime']); + $("#verifyRsDataHodl .date").val(decode['checklocktimeverify'] >= 500000000? moment.unix(decode['checklocktimeverify']).format("MM/DD/YYYY HH:mm") : decode['checklocktimeverify']); $("#verifyRsData").removeClass("hidden"); $("#verifyRsDataHodl").removeClass('hidden'); $(".verifyLink").attr('href','?verify='+$("#verifyScript").val());