Update lib.js
This commit is contained in:
parent
46e386c9ee
commit
ce4bdcd83c
143
scripts/lib.js
143
scripts/lib.js
@ -1,4 +1,4 @@
|
|||||||
(function (GLOBAL) { //lib v1.4.1a
|
(function (GLOBAL) { //lib v1.4.2b
|
||||||
'use strict';
|
'use strict';
|
||||||
/* Utility Libraries required for Standard operations
|
/* Utility Libraries required for Standard operations
|
||||||
* All credits for these codes belong to their respective creators, moderators and owners.
|
* All credits for these codes belong to their respective creators, moderators and owners.
|
||||||
@ -4355,6 +4355,12 @@
|
|||||||
bitjs.multisig = 0x5e; //flochange - prefix for FLO Mainnet Multisig 0x5e
|
bitjs.multisig = 0x5e; //flochange - prefix for FLO Mainnet Multisig 0x5e
|
||||||
bitjs.compressed = false;
|
bitjs.compressed = false;
|
||||||
|
|
||||||
|
if (GLOBAL.cryptocoin == 'FLO_TEST') {
|
||||||
|
bitjs.pub = 0x73; // flochange - changed the prefix to FLO TestNet PublicKey Prefix 0x73
|
||||||
|
bitjs.priv = 0xa3; //flochange - changed the prefix to FLO TestNet Private key prefix 0xa3
|
||||||
|
bitjs.multisig = 0xc6; //flochange - prefix for FLO TestNet Multisig 0xc6
|
||||||
|
}
|
||||||
|
|
||||||
/* provide a privkey and return an WIF */
|
/* provide a privkey and return an WIF */
|
||||||
bitjs.privkey2wif = function (h) {
|
bitjs.privkey2wif = function (h) {
|
||||||
var r = Crypto.util.hexToBytes(h);
|
var r = Crypto.util.hexToBytes(h);
|
||||||
@ -4492,7 +4498,7 @@
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
bitjs.transaction = function () {
|
bitjs.transaction = function (tx_data = undefined) {
|
||||||
var btrx = {};
|
var btrx = {};
|
||||||
btrx.version = 2; //flochange look at this version
|
btrx.version = 2; //flochange look at this version
|
||||||
btrx.inputs = [];
|
btrx.inputs = [];
|
||||||
@ -4521,14 +4527,12 @@
|
|||||||
if (addr.version === bitjs.pub) { // regular address
|
if (addr.version === bitjs.pub) { // regular address
|
||||||
buf.push(118); //OP_DUP
|
buf.push(118); //OP_DUP
|
||||||
buf.push(169); //OP_HASH160
|
buf.push(169); //OP_HASH160
|
||||||
buf.push(addr.bytes.length);
|
buf = this.writeBytesToScriptBuffer(buf, addr.bytes);// address in bytes
|
||||||
buf = buf.concat(addr.bytes); // address in bytes
|
|
||||||
buf.push(136); //OP_EQUALVERIFY
|
buf.push(136); //OP_EQUALVERIFY
|
||||||
buf.push(172); //OP_CHECKSIG
|
buf.push(172); //OP_CHECKSIG
|
||||||
} else if (addr.version === bitjs.multisig) { // multisig address
|
} else if (addr.version === bitjs.multisig) { // multisig address
|
||||||
buf.push(169); //OP_HASH160
|
buf.push(169); //OP_HASH160
|
||||||
buf.push(addr.bytes.length);
|
buf = this.writeBytesToScriptBuffer(buf, addr.bytes);// address in bytes
|
||||||
buf = buf.concat(addr.bytes); // address in bytes
|
|
||||||
buf.push(135); //OP_EQUAL
|
buf.push(135); //OP_EQUAL
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4790,6 +4794,27 @@
|
|||||||
return KBigInt;
|
return KBigInt;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
btrx.writeBytesToScriptBuffer = function (buf, bytes) {
|
||||||
|
if (bytes.length < 76) { //OP_PUSHDATA1
|
||||||
|
buf.push(bytes.length);
|
||||||
|
} else if (bytes.length <= 0xff) {
|
||||||
|
buf.push(76); //OP_PUSHDATA1
|
||||||
|
buf.push(bytes.length);
|
||||||
|
} else if (bytes.length <= 0xffff) {
|
||||||
|
buf.push(77); //OP_PUSHDATA2
|
||||||
|
buf.push(bytes.length & 0xff);
|
||||||
|
buf.push((bytes.length >>> 8) & 0xff);
|
||||||
|
} else {
|
||||||
|
buf.push(78); //OP_PUSHDATA4
|
||||||
|
buf.push(bytes.length & 0xff);
|
||||||
|
buf.push((bytes.length >>> 8) & 0xff);
|
||||||
|
buf.push((bytes.length >>> 16) & 0xff);
|
||||||
|
buf.push((bytes.length >>> 24) & 0xff);
|
||||||
|
}
|
||||||
|
buf = buf.concat(bytes);
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
btrx.parseScript = function (script) {
|
btrx.parseScript = function (script) {
|
||||||
|
|
||||||
var chunks = [];
|
var chunks = [];
|
||||||
@ -4853,8 +4878,7 @@
|
|||||||
var signature = this.transactionSig(index, wif, shType);
|
var signature = this.transactionSig(index, wif, shType);
|
||||||
var buf = [];
|
var buf = [];
|
||||||
var sigBytes = Crypto.util.hexToBytes(signature);
|
var sigBytes = Crypto.util.hexToBytes(signature);
|
||||||
buf.push(sigBytes.length);
|
buf = this.writeBytesToScriptBuffer(buf, sigBytes);
|
||||||
buf = buf.concat(sigBytes);
|
|
||||||
var pubKeyBytes = Crypto.util.hexToBytes(key['pubkey']);
|
var pubKeyBytes = Crypto.util.hexToBytes(key['pubkey']);
|
||||||
buf.push(pubKeyBytes.length);
|
buf.push(pubKeyBytes.length);
|
||||||
buf = buf.concat(pubKeyBytes);
|
buf = buf.concat(pubKeyBytes);
|
||||||
@ -4902,16 +4926,14 @@
|
|||||||
for (let y in sigsList) {
|
for (let y in sigsList) {
|
||||||
var sighash = Crypto.util.hexToBytes(this.transactionHash(index, sigsList[y].slice(-1)[0] * 1));
|
var sighash = Crypto.util.hexToBytes(this.transactionHash(index, sigsList[y].slice(-1)[0] * 1));
|
||||||
if (bitjs.verifySignature(sighash, sigsList[y], pubkeyList[x])) {
|
if (bitjs.verifySignature(sighash, sigsList[y], pubkeyList[x])) {
|
||||||
buf.push(sigsList[y].length);
|
buf = this.writeBytesToScriptBuffer(buf, sigsList[y]);
|
||||||
buf = buf.concat(sigsList[y]);
|
|
||||||
break; //ensures duplicate sigs from same pubkey are not added
|
break; //ensures duplicate sigs from same pubkey are not added
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//append redeemscript
|
//append redeemscript
|
||||||
buf.push(redeemScript.length);
|
buf = this.writeBytesToScriptBuffer(buf, redeemScript);
|
||||||
buf = buf.concat(redeemScript);
|
|
||||||
|
|
||||||
this.inputs[index].script = buf;
|
this.inputs[index].script = buf;
|
||||||
return true;
|
return true;
|
||||||
@ -4992,6 +5014,78 @@
|
|||||||
return Crypto.util.bytesToHex(buffer);
|
return Crypto.util.bytesToHex(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* deserialize a transaction */
|
||||||
|
function deserialize(buffer) {
|
||||||
|
if (typeof buffer == "string") {
|
||||||
|
buffer = Crypto.util.hexToBytes(buffer)
|
||||||
|
}
|
||||||
|
|
||||||
|
var pos = 0;
|
||||||
|
|
||||||
|
var readAsInt = function (bytes) {
|
||||||
|
if (bytes == 0) return 0;
|
||||||
|
pos++;
|
||||||
|
return buffer[pos - 1] + readAsInt(bytes - 1) * 256;
|
||||||
|
}
|
||||||
|
|
||||||
|
var readVarInt = function () {
|
||||||
|
pos++;
|
||||||
|
if (buffer[pos - 1] < 253) {
|
||||||
|
return buffer[pos - 1];
|
||||||
|
}
|
||||||
|
return readAsInt(buffer[pos - 1] - 251);
|
||||||
|
}
|
||||||
|
|
||||||
|
var readBytes = function (bytes) {
|
||||||
|
pos += bytes;
|
||||||
|
return buffer.slice(pos - bytes, pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
var readVarString = function () {
|
||||||
|
var size = readVarInt();
|
||||||
|
return readBytes(size);
|
||||||
|
}
|
||||||
|
|
||||||
|
var bytesToStr = function (bytes) {
|
||||||
|
return bytes.map(b => String.fromCharCode(b)).join('');
|
||||||
|
}
|
||||||
|
|
||||||
|
const self = btrx;
|
||||||
|
|
||||||
|
self.version = readAsInt(4);
|
||||||
|
|
||||||
|
var ins = readVarInt();
|
||||||
|
for (var i = 0; i < ins; i++) {
|
||||||
|
self.inputs.push({
|
||||||
|
outpoint: {
|
||||||
|
hash: Crypto.util.bytesToHex(readBytes(32).reverse()),
|
||||||
|
index: readAsInt(4)
|
||||||
|
},
|
||||||
|
script: readVarString(),
|
||||||
|
sequence: readAsInt(4)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
var outs = readVarInt();
|
||||||
|
for (var i = 0; i < outs; i++) {
|
||||||
|
self.outputs.push({
|
||||||
|
value: bitjs.bytesToNum(readBytes(8)),
|
||||||
|
script: readVarString()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
self.lock_time = readAsInt(4);
|
||||||
|
|
||||||
|
//flochange - floData field
|
||||||
|
self.floData = bytesToStr(readVarString());
|
||||||
|
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
//deserialize the data if passed
|
||||||
|
if (tx_data)
|
||||||
|
deserialize(tx_data);
|
||||||
|
|
||||||
return btrx;
|
return btrx;
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -5229,23 +5323,22 @@
|
|||||||
if ("string" == typeof bytes) {
|
if ("string" == typeof bytes) {
|
||||||
var d = Bitcoin.Address.decodeString(bytes);
|
var d = Bitcoin.Address.decodeString(bytes);
|
||||||
bytes = d.hash;
|
bytes = d.hash;
|
||||||
if (GLOBAL.cryptocoin == "FLO" && (d.version == Bitcoin.Address.standardVersion || d.version == Bitcoin.Address.multisigVersion))
|
if (d.version == Bitcoin.Address.standardVersion || d.version == Bitcoin.Address.multisigVersion)
|
||||||
this.version = d.version;
|
|
||||||
else if (GLOBAL.cryptocoin == "FLO_TEST" && d.version == Bitcoin.Address.testnetVersion)
|
|
||||||
this.version = d.version;
|
this.version = d.version;
|
||||||
else throw "Version (prefix) " + d.version + " not supported!";
|
else throw "Version (prefix) " + d.version + " not supported!";
|
||||||
} else {
|
} else {
|
||||||
if (GLOBAL.cryptocoin == "FLO")
|
this.version = Bitcoin.Address.standardVersion;
|
||||||
this.version = Bitcoin.Address.standardVersion;
|
|
||||||
else if (GLOBAL.cryptocoin == "FLO_TEST")
|
|
||||||
this.version = Bitcoin.Address.testnetVersion; // FLO testnet public address
|
|
||||||
}
|
}
|
||||||
this.hash = bytes;
|
this.hash = bytes;
|
||||||
};
|
};
|
||||||
|
|
||||||
Bitcoin.Address.standardVersion = 0x23; // (FLO mainnet 0x23, 35D), (Bitcoin Mainnet, 0x00, 0D)
|
Bitcoin.Address.standardVersion = 0x23; // (FLO mainnet 0x23, 35D), (Bitcoin Mainnet, 0x00, 0D)
|
||||||
Bitcoin.Address.multisigVersion = 0x5e; // (FLO multisig 0x5e, 94D)
|
Bitcoin.Address.multisigVersion = 0x5e; // (FLO multisig 0x5e, 94D)
|
||||||
Bitcoin.Address.testnetVersion = 0x73; // (FLO testnet 0x73, 115D)
|
|
||||||
|
if (GLOBAL.cryptocoin == "FLO_TEST") {
|
||||||
|
Bitcoin.Address.standardVersion = 0x73; // (FLO testnet 0x73, 115D), (Bitcoin Mainnet, 0x00, 0D)
|
||||||
|
Bitcoin.Address.multisigVersion = 0xc6; // (FLO testnet multisig 0xc6, 198D)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Serialize this object as a standard Bitcoin address.
|
* Serialize this object as a standard Bitcoin address.
|
||||||
@ -6704,6 +6797,7 @@
|
|||||||
return {
|
return {
|
||||||
'address': address,
|
'address': address,
|
||||||
'redeemScript': r.redeemScript,
|
'redeemScript': r.redeemScript,
|
||||||
|
'scripthash': Crypto.util.bytesToHex(program),
|
||||||
'size': r.size
|
'size': r.size
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -6797,15 +6891,16 @@
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
coinjs.multisigBech32Address = function (raw_redeemscript) {
|
coinjs.multisigBech32Address = function (redeemscript) {
|
||||||
var program = Crypto.SHA256(Crypto.util.hexToBytes(raw_redeemscript), {
|
var program = Crypto.SHA256(Crypto.util.hexToBytes(redeemscript), {
|
||||||
asBytes: true
|
asBytes: true
|
||||||
});
|
});
|
||||||
var address = coinjs.bech32_encode(coinjs.bech32.hrp, [coinjs.bech32.version].concat(coinjs.bech32_convert(program, 8, 5, true)));
|
var address = coinjs.bech32_encode(coinjs.bech32.hrp, [coinjs.bech32.version].concat(coinjs.bech32_convert(program, 8, 5, true)));
|
||||||
return {
|
return {
|
||||||
'address': address,
|
'address': address,
|
||||||
'type': 'multisigBech32',
|
'type': 'multisigBech32',
|
||||||
'redeemscript': Crypto.util.bytesToHex(program)
|
'redeemScript': redeemscript,
|
||||||
|
'scripthash': Crypto.util.bytesToHex(program)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -7803,7 +7898,7 @@
|
|||||||
var n = u.getElementsByTagName("tx_output_n")[0].childNodes[0].nodeValue;
|
var n = u.getElementsByTagName("tx_output_n")[0].childNodes[0].nodeValue;
|
||||||
var scr = script || u.getElementsByTagName("script")[0].childNodes[0].nodeValue;
|
var scr = script || u.getElementsByTagName("script")[0].childNodes[0].nodeValue;
|
||||||
|
|
||||||
if (segwit) { //also for MULTISIG_BECH32 (p2wsh-multisig)(script = raw_redeemscript; for p2wsh-multisig)
|
if (segwit) { //also for MULTISIG_BECH32 (p2wsh-multisig)(script = redeemscript; for p2wsh-multisig)
|
||||||
/* this is a small hack to include the value with the redeemscript to make the signing procedure smoother.
|
/* 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. */
|
It is not standard and removed during the signing procedure. */
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user