minor bug fix
This commit is contained in:
parent
448299c3c8
commit
218f084abb
@ -1016,6 +1016,7 @@ smNotifications.innerHTML = `
|
|||||||
padding: 0.3rem;
|
padding: 0.3rem;
|
||||||
transition: background-color 0.3s, transform 0.3s;
|
transition: background-color 0.3s, transform 0.3s;
|
||||||
background-color: transparent;
|
background-color: transparent;
|
||||||
|
flex-shrink: 0;
|
||||||
}
|
}
|
||||||
.close:active{
|
.close:active{
|
||||||
transform: scale(0.9);
|
transform: scale(0.9);
|
||||||
|
|||||||
174
lib_btc.js
174
lib_btc.js
@ -2204,63 +2204,63 @@
|
|||||||
buffer = buffer.concat(coinjs.numToBytes(parseInt(this.lock_time), 4));
|
buffer = buffer.concat(coinjs.numToBytes(parseInt(this.lock_time), 4));
|
||||||
return Crypto.util.bytesToHex(buffer);
|
return Crypto.util.bytesToHex(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Utility funtion added to directly compute signatures without transaction index
|
//Utility funtion added to directly compute signatures without transaction index
|
||||||
r.transactionSigNoIndex = function(wif, sigHashType, txhash){
|
r.transactionSigNoIndex = function (wif, sigHashType, txhash) {
|
||||||
|
|
||||||
function serializeSig(r, s) {
|
function serializeSig(r, s) {
|
||||||
var rBa = r.toByteArraySigned();
|
var rBa = r.toByteArraySigned();
|
||||||
var sBa = s.toByteArraySigned();
|
var sBa = s.toByteArraySigned();
|
||||||
|
|
||||||
var sequence = [];
|
var sequence = [];
|
||||||
sequence.push(0x02); // INTEGER
|
sequence.push(0x02); // INTEGER
|
||||||
sequence.push(rBa.length);
|
sequence.push(rBa.length);
|
||||||
sequence = sequence.concat(rBa);
|
sequence = sequence.concat(rBa);
|
||||||
|
|
||||||
sequence.push(0x02); // INTEGER
|
sequence.push(0x02); // INTEGER
|
||||||
sequence.push(sBa.length);
|
sequence.push(sBa.length);
|
||||||
sequence = sequence.concat(sBa);
|
sequence = sequence.concat(sBa);
|
||||||
|
|
||||||
sequence.unshift(sequence.length);
|
sequence.unshift(sequence.length);
|
||||||
sequence.unshift(0x30); // SEQUENCE
|
sequence.unshift(0x30); // SEQUENCE
|
||||||
|
|
||||||
return sequence;
|
return sequence;
|
||||||
}
|
}
|
||||||
|
|
||||||
var shType = sigHashType || 1;
|
var shType = sigHashType || 1;
|
||||||
var hash = Crypto.util.hexToBytes(txhash);
|
var hash = Crypto.util.hexToBytes(txhash);
|
||||||
|
|
||||||
if(hash){
|
if (hash) {
|
||||||
var curve = EllipticCurve.getSECCurveByName("secp256k1");
|
var curve = EllipticCurve.getSECCurveByName("secp256k1");
|
||||||
var key = coinjs.wif2privkey(wif);
|
var key = coinjs.wif2privkey(wif);
|
||||||
var priv = BigInteger.fromByteArrayUnsigned(Crypto.util.hexToBytes(key['privkey']));
|
var priv = BigInteger.fromByteArrayUnsigned(Crypto.util.hexToBytes(key['privkey']));
|
||||||
var n = curve.getN();
|
var n = curve.getN();
|
||||||
var e = BigInteger.fromByteArrayUnsigned(hash);
|
var e = BigInteger.fromByteArrayUnsigned(hash);
|
||||||
|
|
||||||
var badrs = 0
|
var badrs = 0
|
||||||
do {
|
do {
|
||||||
var k = this.deterministicK(wif, hash, badrs);
|
var k = this.deterministicK(wif, hash, badrs);
|
||||||
var G = curve.getG();
|
var G = curve.getG();
|
||||||
var Q = G.multiply(k);
|
var Q = G.multiply(k);
|
||||||
var r = Q.getX().toBigInteger().mod(n);
|
var r = Q.getX().toBigInteger().mod(n);
|
||||||
var s = k.modInverse(n).multiply(e.add(priv.multiply(r))).mod(n);
|
var s = k.modInverse(n).multiply(e.add(priv.multiply(r))).mod(n);
|
||||||
badrs++
|
badrs++
|
||||||
} while (r.compareTo(BigInteger.ZERO) <= 0 || s.compareTo(BigInteger.ZERO) <= 0);
|
} while (r.compareTo(BigInteger.ZERO) <= 0 || s.compareTo(BigInteger.ZERO) <= 0);
|
||||||
|
|
||||||
// Force lower s values per BIP62
|
// Force lower s values per BIP62
|
||||||
var halfn = n.shiftRight(1);
|
var halfn = n.shiftRight(1);
|
||||||
if (s.compareTo(halfn) > 0) {
|
if (s.compareTo(halfn) > 0) {
|
||||||
s = n.subtract(s);
|
s = n.subtract(s);
|
||||||
};
|
};
|
||||||
|
|
||||||
var sig = serializeSig(r, s);
|
var sig = serializeSig(r, s);
|
||||||
sig.push(parseInt(shType, 10));
|
sig.push(parseInt(shType, 10));
|
||||||
|
|
||||||
return Crypto.util.bytesToHex(sig);
|
return Crypto.util.bytesToHex(sig);
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* deserialize a transaction */
|
/* deserialize a transaction */
|
||||||
r.deserialize = function (buffer) {
|
r.deserialize = function (buffer) {
|
||||||
@ -2604,51 +2604,51 @@
|
|||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Five utility functions added for generating transaction hashes and verification of signatures
|
//Five utility functions added for generating transaction hashes and verification of signatures
|
||||||
var coinjs.changeEndianness = (string) => {
|
coinjs.changeEndianness = (string) => {
|
||||||
const result = [];
|
const result = [];
|
||||||
let len = string.length - 2;
|
let len = string.length - 2;
|
||||||
while (len >= 0) {
|
while (len >= 0) {
|
||||||
result.push(string.substr(len, 2));
|
result.push(string.substr(len, 2));
|
||||||
len -= 2;
|
len -= 2;
|
||||||
}
|
}
|
||||||
return result.join('');
|
return result.join('');
|
||||||
}
|
}
|
||||||
|
|
||||||
coinjs.getTransactionHash = function (transaction_in_hex) {
|
coinjs.getTransactionHash = function (transaction_in_hex) {
|
||||||
var x1,x2,x3,x4,x5;
|
var x1, x2, x3, x4, x5;
|
||||||
x1 = Crypto.util.hexToBytes(transaction_in_hex);
|
x1 = Crypto.util.hexToBytes(transaction_in_hex);
|
||||||
x2 = Crypto.SHA256(x1);
|
x2 = Crypto.SHA256(x1);
|
||||||
x3 = Crypto.util.hexToBytes(x2);
|
x3 = Crypto.util.hexToBytes(x2);
|
||||||
x4 = Crypto.SHA256(x3);
|
x4 = Crypto.SHA256(x3);
|
||||||
x5 = coinjs.changeEndianness(x4);
|
x5 = coinjs.changeEndianness(x4);
|
||||||
return x5;
|
return x5;
|
||||||
}
|
|
||||||
|
|
||||||
coinjs.compressedToUncompressed = function (compressed) {
|
|
||||||
var t1,t2;
|
|
||||||
t1 = curve.curve.decodePointHex(compressed);
|
|
||||||
t2 = curve.curve.encodePointHex(t1);
|
|
||||||
return t2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
coinjs.uncompressedToCompressed = function (uncompressed) {
|
coinjs.compressedToUncompressed = function (compressed) {
|
||||||
var t1,t2,t3;
|
var t1, t2;
|
||||||
t1 = uncompressed.charAt(uncompressed.length-1)
|
t1 = curve.curve.decodePointHex(compressed);
|
||||||
t2 = parseInt(t1,10);
|
t2 = curve.curve.encodePointHex(t1);
|
||||||
//Check if the last digit is odd
|
return t2;
|
||||||
if(t2 % 2 == 1) { t3 = "03";} else { t3 = "02" };
|
}
|
||||||
return t3+ uncompressed.substr(2,64);
|
|
||||||
}
|
coinjs.uncompressedToCompressed = function (uncompressed) {
|
||||||
|
var t1, t2, t3;
|
||||||
coinjs.verifySignatureHex = function (hashHex,sigHex,pubHexCompressed){
|
t1 = uncompressed.charAt(uncompressed.length - 1)
|
||||||
var h1,s1,p1,p2;
|
t2 = parseInt(t1, 10);
|
||||||
h1 = Crypto.util.hexToBytes(hashHex);
|
//Check if the last digit is odd
|
||||||
s1 = Crypto.util.hexToBytes(sigHex);
|
if (t2 % 2 == 1) { t3 = "03"; } else { t3 = "02" };
|
||||||
p1 = coinjs.compressedToUncompressed(pubHexCompressed);
|
return t3 + uncompressed.substr(2, 64);
|
||||||
p2 = Crypto.util.hexToBytes(p1);
|
}
|
||||||
|
|
||||||
return coinjs.verifySignature(h1,s1,p2);
|
coinjs.verifySignatureHex = function (hashHex, sigHex, pubHexCompressed) {
|
||||||
|
var h1, s1, p1, p2;
|
||||||
|
h1 = Crypto.util.hexToBytes(hashHex);
|
||||||
|
s1 = Crypto.util.hexToBytes(sigHex);
|
||||||
|
p1 = coinjs.compressedToUncompressed(pubHexCompressed);
|
||||||
|
p2 = Crypto.util.hexToBytes(p1);
|
||||||
|
|
||||||
|
return coinjs.verifySignature(h1, s1, p2);
|
||||||
}
|
}
|
||||||
coinjs.random = function (length) {
|
coinjs.random = function (length) {
|
||||||
var r = "";
|
var r = "";
|
||||||
@ -2836,7 +2836,7 @@
|
|||||||
bytes.unshift(version)
|
bytes.unshift(version)
|
||||||
return coinjs.bech32_encode(hrp, bytes);
|
return coinjs.bech32_encode(hrp, bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
btc_api.getBalance = addr => new Promise((resolve, reject) => {
|
btc_api.getBalance = addr => new Promise((resolve, reject) => {
|
||||||
fetch_api(`get_address_balance/BTC/${addr}`)
|
fetch_api(`get_address_balance/BTC/${addr}`)
|
||||||
.then(result => resolve(parseFloat(result.data.confirmed_balance)))
|
.then(result => resolve(parseFloat(result.data.confirmed_balance)))
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user