Error in serialization for nLockTime values
if nLockTime is 1234(decimal) -> thats 4D2(hex) -> The current code splits it beginning from the end into bytes -> [4d, 02], but it should be [4, d2]. Error only occurs if one of the bytes is <16
This commit is contained in:
parent
cad1f6e98b
commit
3ba79f0e3d
1 changed files with 10 additions and 2 deletions
12
js/coin.js
12
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 @@
|
|||
// ^ <unlocktime> OP_CHECKLOCKTIMEVERIFY OP_DROP <pubkey> 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];
|
||||
|
|
Loading…
Reference in a new issue