diff --git a/js/coin.js b/js/coin.js index c7b2efb..1971de9 100644 --- a/js/coin.js +++ b/js/coin.js @@ -148,7 +148,7 @@ } var s = coinjs.script(); - s.writeBytes(Crypto.util.hexToBytes(checklocktimeverify.toString(16)).reverse()); + s.writeBytes(coinjs.numToByteArray(checklocktimeverify).reverse()); s.writeOp(177);//OP_CHECKLOCKTIMEVERIFY s.writeOp(117);//OP_DROP s.writeBytes(Crypto.util.hexToBytes(pubkey)); @@ -687,7 +687,7 @@ // ^ OP_CHECKLOCKTIMEVERIFY OP_DROP OP_CHECKSIG ^ r = {} r.pubkey = Crypto.util.bytesToHex(s.chunks[3]); - r.checklocktimeverify = parseInt(Crypto.util.bytesToHex(s.chunks[0].slice().reverse()), 16); + r.checklocktimeverify = coinjs.bytesToNum(s.chunks[0].slice().reverse()); r.address = coinjs.simpleHodlAddress(r.pubkey, r.checklocktimeverify).address; r.type = "hodl__"; } @@ -1454,6 +1454,14 @@ } } + coinjs.numToByteArray = function(num) { + if (num <= 256) { + return [num]; + } else { + return [num % 256].concat(coinjs.numToByteArray(Math.floor(num / 256))); + } + } + coinjs.numToVarInt = function(num) { if (num < 253) { return [num];