rohit sir sign verify version
This commit is contained in:
parent
9481074f0c
commit
054eef05b2
2
.gitignore
vendored
2
.gitignore
vendored
@ -3,4 +3,4 @@ json-rpc/
|
|||||||
supernode/websocket_chat
|
supernode/websocket_chat
|
||||||
supernode/floaddress.org.html
|
supernode/floaddress.org.html
|
||||||
supernode/Makefile
|
supernode/Makefile
|
||||||
list.txt
|
playground
|
||||||
@ -1,44 +1,23 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<meta charset="utf-8" />
|
<html lang="en">
|
||||||
<title>LocalBitcoin++ Prototype</title>
|
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||||
|
<title>Document</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
|
||||||
<div id="wallets">
|
|
||||||
<div id="singlearea" class="walletarea">
|
|
||||||
<div class="commands">
|
|
||||||
<div id="singlecommands" class="row">
|
|
||||||
<span><input type="button" id="newaddress" value="Generate New Address" onclick="ninja.wallets.singlewallet.generateNewAddressAndKey();" /></span>
|
|
||||||
<span class="print"><input type="button" name="print" value="Print" id="singleprint" onclick="window.print();" /></span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="body">
|
|
||||||
<div id="keyarea" class="keyarea">
|
|
||||||
<div class="public">
|
|
||||||
<div class="pubaddress">
|
|
||||||
<span class="label" id="singlelabelbitcoinaddress">Bitcoin Address</span>
|
|
||||||
</div>
|
|
||||||
<div id="qrcode_public" class="qrcode_public"></div>
|
|
||||||
<div class="pubaddress">
|
|
||||||
<span class="output" id="btcaddress"></span>
|
|
||||||
</div>
|
|
||||||
<div id="singleshare">SHARE</div>
|
|
||||||
</div>
|
|
||||||
<div class="private">
|
|
||||||
<div class="privwif">
|
|
||||||
<span class="label" id="singlelabelprivatekey">Private Key</span>
|
|
||||||
</div>
|
|
||||||
<div id="qrcode_private" class="qrcode_private"></div>
|
|
||||||
<div class="privwif">
|
|
||||||
<span class="output" id="btcprivwif"></span>
|
|
||||||
</div>
|
|
||||||
<div id="singlesecret">SECRET</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
/*!
|
||||||
|
* Crypto-JS v2.5.4 Crypto.js
|
||||||
|
* http://code.google.com/p/crypto-js/
|
||||||
|
* Copyright (c) 2009-2013, Jeff Mott. All rights reserved.
|
||||||
|
* http://code.google.com/p/crypto-js/wiki/License
|
||||||
|
*/
|
||||||
if (typeof Crypto == "undefined" || !Crypto.util) {
|
if (typeof Crypto == "undefined" || !Crypto.util) {
|
||||||
(function () {
|
(function () {
|
||||||
|
|
||||||
@ -134,7 +113,8 @@
|
|||||||
|
|
||||||
for (var bytes = [], i = 0, imod4 = 0; i < base64.length; imod4 = ++i % 4) {
|
for (var bytes = [], i = 0, imod4 = 0; i < base64.length; imod4 = ++i % 4) {
|
||||||
if (imod4 == 0) continue;
|
if (imod4 == 0) continue;
|
||||||
bytes.push(((base64map.indexOf(base64.charAt(i - 1)) & (Math.pow(2, -2 * imod4 + 8) -
|
bytes.push(((base64map.indexOf(base64.charAt(i - 1)) & (Math.pow(2, -2 * imod4 +
|
||||||
|
8) -
|
||||||
1)) << (imod4 * 2)) |
|
1)) << (imod4 * 2)) |
|
||||||
(base64map.indexOf(base64.charAt(i)) >>> (6 - imod4 * 2)));
|
(base64map.indexOf(base64.charAt(i)) >>> (6 - imod4 * 2)));
|
||||||
}
|
}
|
||||||
@ -1617,7 +1597,8 @@
|
|||||||
// browser plugin details: ~16.2 to ~21.8 bits
|
// browser plugin details: ~16.2 to ~21.8 bits
|
||||||
var pluginsStr = "";
|
var pluginsStr = "";
|
||||||
for (var i = 0; i < navigator.plugins.length; i++) {
|
for (var i = 0; i < navigator.plugins.length; i++) {
|
||||||
pluginsStr += navigator.plugins[i].name + " " + navigator.plugins[i].filename + " " + navigator.plugins[
|
pluginsStr += navigator.plugins[i].name + " " + navigator.plugins[i].filename + " " + navigator
|
||||||
|
.plugins[
|
||||||
i].description + " " + navigator.plugins[i].version + ", ";
|
i].description + " " + navigator.plugins[i].version + ", ";
|
||||||
}
|
}
|
||||||
var mimeTypesStr = "";
|
var mimeTypesStr = "";
|
||||||
@ -1700,7 +1681,8 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
ec.FieldElementFp.prototype.divide = function (b) {
|
ec.FieldElementFp.prototype.divide = function (b) {
|
||||||
return new ec.FieldElementFp(this.q, this.x.multiply(b.toBigInteger().modInverse(this.q)).mod(this.q));
|
return new ec.FieldElementFp(this.q, this.x.multiply(b.toBigInteger().modInverse(this.q)).mod(
|
||||||
|
this.q));
|
||||||
};
|
};
|
||||||
|
|
||||||
ec.FieldElementFp.prototype.getByteLength = function () {
|
ec.FieldElementFp.prototype.getByteLength = function () {
|
||||||
@ -1873,10 +1855,12 @@
|
|||||||
if (b.isInfinity()) return this;
|
if (b.isInfinity()) return this;
|
||||||
|
|
||||||
// u = Y2 * Z1 - Y1 * Z2
|
// u = Y2 * Z1 - Y1 * Z2
|
||||||
var u = b.y.toBigInteger().multiply(this.z).subtract(this.y.toBigInteger().multiply(b.z)).mod(this.curve
|
var u = b.y.toBigInteger().multiply(this.z).subtract(this.y.toBigInteger().multiply(b.z)).mod(
|
||||||
|
this.curve
|
||||||
.q);
|
.q);
|
||||||
// v = X2 * Z1 - X1 * Z2
|
// v = X2 * Z1 - X1 * Z2
|
||||||
var v = b.x.toBigInteger().multiply(this.z).subtract(this.x.toBigInteger().multiply(b.z)).mod(this.curve
|
var v = b.x.toBigInteger().multiply(this.z).subtract(this.x.toBigInteger().multiply(b.z)).mod(
|
||||||
|
this.curve
|
||||||
.q);
|
.q);
|
||||||
|
|
||||||
|
|
||||||
@ -1906,7 +1890,8 @@
|
|||||||
// z3 = v^3 * z1 * z2
|
// z3 = v^3 * z1 * z2
|
||||||
var z3 = v3.multiply(this.z).multiply(b.z).mod(this.curve.q);
|
var z3 = v3.multiply(this.z).multiply(b.z).mod(this.curve.q);
|
||||||
|
|
||||||
return new ec.PointFp(this.curve, this.curve.fromBigInteger(x3), this.curve.fromBigInteger(y3), z3);
|
return new ec.PointFp(this.curve, this.curve.fromBigInteger(x3), this.curve.fromBigInteger(y3),
|
||||||
|
z3);
|
||||||
};
|
};
|
||||||
|
|
||||||
ec.PointFp.prototype.twice = function () {
|
ec.PointFp.prototype.twice = function () {
|
||||||
@ -1930,15 +1915,18 @@
|
|||||||
w = w.mod(this.curve.q);
|
w = w.mod(this.curve.q);
|
||||||
//this.curve.reduce(w);
|
//this.curve.reduce(w);
|
||||||
// x3 = 2 * y1 * z1 * (w^2 - 8 * x1 * y1^2 * z1)
|
// x3 = 2 * y1 * z1 * (w^2 - 8 * x1 * y1^2 * z1)
|
||||||
var x3 = w.square().subtract(x1.shiftLeft(3).multiply(y1sqz1)).shiftLeft(1).multiply(y1z1).mod(this
|
var x3 = w.square().subtract(x1.shiftLeft(3).multiply(y1sqz1)).shiftLeft(1).multiply(y1z1).mod(
|
||||||
|
this
|
||||||
.curve.q);
|
.curve.q);
|
||||||
// y3 = 4 * y1^2 * z1 * (3 * w * x1 - 2 * y1^2 * z1) - w^3
|
// y3 = 4 * y1^2 * z1 * (3 * w * x1 - 2 * y1^2 * z1) - w^3
|
||||||
var y3 = w.multiply(THREE).multiply(x1).subtract(y1sqz1.shiftLeft(1)).shiftLeft(2).multiply(y1sqz1)
|
var y3 = w.multiply(THREE).multiply(x1).subtract(y1sqz1.shiftLeft(1)).shiftLeft(2).multiply(
|
||||||
|
y1sqz1)
|
||||||
.subtract(w.square().multiply(w)).mod(this.curve.q);
|
.subtract(w.square().multiply(w)).mod(this.curve.q);
|
||||||
// z3 = 8 * (y1 * z1)^3
|
// z3 = 8 * (y1 * z1)^3
|
||||||
var z3 = y1z1.square().multiply(y1z1).shiftLeft(3).mod(this.curve.q);
|
var z3 = y1z1.square().multiply(y1z1).shiftLeft(3).mod(this.curve.q);
|
||||||
|
|
||||||
return new ec.PointFp(this.curve, this.curve.fromBigInteger(x3), this.curve.fromBigInteger(y3), z3);
|
return new ec.PointFp(this.curve, this.curve.fromBigInteger(x3), this.curve.fromBigInteger(y3),
|
||||||
|
z3);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Simple NAF (Non-Adjacent Form) multiplication algorithm
|
// Simple NAF (Non-Adjacent Form) multiplication algorithm
|
||||||
@ -2345,7 +2333,8 @@
|
|||||||
// Primitive polynomials (in decimal form) for Galois Fields GF(2^n), for 2 <= n <= 30
|
// Primitive polynomials (in decimal form) for Galois Fields GF(2^n), for 2 <= n <= 30
|
||||||
// The index of each term in the array corresponds to the n for that polynomial
|
// The index of each term in the array corresponds to the n for that polynomial
|
||||||
// i.e. to get the polynomial for n=16, use primitivePolynomials[16]
|
// i.e. to get the polynomial for n=16, use primitivePolynomials[16]
|
||||||
primitivePolynomials: [null, null, 1, 3, 3, 5, 3, 3, 29, 17, 9, 5, 83, 27, 43, 3, 45, 9, 39, 39, 9,
|
primitivePolynomials: [null, null, 1, 3, 3, 5, 3, 3, 29, 17, 9, 5, 83, 27, 43, 3, 45, 9, 39, 39,
|
||||||
|
9,
|
||||||
5, 3, 33, 27, 9, 71, 39, 9, 5, 83
|
5, 3, 33, 27, 9, 71, 39, 9, 5, 83
|
||||||
],
|
],
|
||||||
|
|
||||||
@ -2365,7 +2354,8 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
function init(bits) {
|
function init(bits) {
|
||||||
if (bits && (typeof bits !== 'number' || bits % 1 !== 0 || bits < defaults.minBits || bits > defaults.maxBits)) {
|
if (bits && (typeof bits !== 'number' || bits % 1 !== 0 || bits < defaults.minBits || bits >
|
||||||
|
defaults.maxBits)) {
|
||||||
throw new Error('Number of bits must be an integer between ' + defaults.minBits + ' and ' +
|
throw new Error('Number of bits must be an integer between ' + defaults.minBits + ' and ' +
|
||||||
defaults.maxBits + ', inclusive.')
|
defaults.maxBits + ', inclusive.')
|
||||||
}
|
}
|
||||||
@ -2427,7 +2417,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
// node.js crypto.randomBytes()
|
// node.js crypto.randomBytes()
|
||||||
if (typeof require === 'function' && (crypto = require('crypto')) && (randomBits = crypto['randomBytes'])) {
|
if (typeof require === 'function' && (crypto = require('crypto')) && (randomBits = crypto[
|
||||||
|
'randomBytes'])) {
|
||||||
return function (bits) {
|
return function (bits) {
|
||||||
var bytes = Math.ceil(bits / 8),
|
var bytes = Math.ceil(bits / 8),
|
||||||
str = null;
|
str = null;
|
||||||
@ -2566,7 +2557,8 @@
|
|||||||
if (threshold > config.max) {
|
if (threshold > config.max) {
|
||||||
var neededBits = Math.ceil(Math.log(threshold + 1) / Math.LN2);
|
var neededBits = Math.ceil(Math.log(threshold + 1) / Math.LN2);
|
||||||
throw new Error('Threshold number of shares must be an integer between 2 and 2^bits-1 (' +
|
throw new Error('Threshold number of shares must be an integer between 2 and 2^bits-1 (' +
|
||||||
config.max + '), inclusive. To use a threshold of ' + threshold + ', use at least ' +
|
config.max + '), inclusive. To use a threshold of ' + threshold +
|
||||||
|
', use at least ' +
|
||||||
neededBits + ' bits.');
|
neededBits + ' bits.');
|
||||||
}
|
}
|
||||||
if (typeof padLength !== 'number' || padLength % 1 !== 0) {
|
if (typeof padLength !== 'number' || padLength % 1 !== 0) {
|
||||||
@ -2653,7 +2645,8 @@
|
|||||||
function processShare(share) {
|
function processShare(share) {
|
||||||
|
|
||||||
var bits = parseInt(share[0], 36);
|
var bits = parseInt(share[0], 36);
|
||||||
if (bits && (typeof bits !== 'number' || bits % 1 !== 0 || bits < defaults.minBits || bits > defaults.maxBits)) {
|
if (bits && (typeof bits !== 'number' || bits % 1 !== 0 || bits < defaults.minBits || bits >
|
||||||
|
defaults.maxBits)) {
|
||||||
throw new Error('Number of bits must be an integer between ' + defaults.minBits + ' and ' +
|
throw new Error('Number of bits must be an integer between ' + defaults.minBits + ' and ' +
|
||||||
defaults.maxBits + ', inclusive.')
|
defaults.maxBits + ', inclusive.')
|
||||||
}
|
}
|
||||||
@ -2847,7 +2840,8 @@
|
|||||||
}
|
}
|
||||||
bytesPerChar = bytesPerChar || defaults.bytesPerChar;
|
bytesPerChar = bytesPerChar || defaults.bytesPerChar;
|
||||||
|
|
||||||
if (typeof bytesPerChar !== 'number' || bytesPerChar % 1 !== 0 || bytesPerChar < 1 || bytesPerChar >
|
if (typeof bytesPerChar !== 'number' || bytesPerChar % 1 !== 0 || bytesPerChar < 1 ||
|
||||||
|
bytesPerChar >
|
||||||
defaults.maxBytesPerChar) {
|
defaults.maxBytesPerChar) {
|
||||||
throw new Error('Bytes per character must be an integer between 1 and ' + defaults.maxBytesPerChar +
|
throw new Error('Bytes per character must be an integer between 1 and ' + defaults.maxBytesPerChar +
|
||||||
', inclusive.')
|
', inclusive.')
|
||||||
@ -2863,7 +2857,8 @@
|
|||||||
throw new Error('Invalid character: ' + str[i]);
|
throw new Error('Invalid character: ' + str[i]);
|
||||||
} else if (num > max) {
|
} else if (num > max) {
|
||||||
var neededBytes = Math.ceil(Math.log(num + 1) / Math.log(256));
|
var neededBytes = Math.ceil(Math.log(num + 1) / Math.log(256));
|
||||||
throw new Error('Invalid character code (' + num + '). Maximum allowable is 256^bytes-1 (' +
|
throw new Error('Invalid character code (' + num +
|
||||||
|
'). Maximum allowable is 256^bytes-1 (' +
|
||||||
max + '). To convert this character, use at least ' + neededBytes + ' bytes.')
|
max + '). To convert this character, use at least ' + neededBytes + ' bytes.')
|
||||||
} else {
|
} else {
|
||||||
out = padLeft(num.toString(16), hexChars) + out;
|
out = padLeft(num.toString(16), hexChars) + out;
|
||||||
@ -2880,7 +2875,8 @@
|
|||||||
}
|
}
|
||||||
bytesPerChar = bytesPerChar || defaults.bytesPerChar;
|
bytesPerChar = bytesPerChar || defaults.bytesPerChar;
|
||||||
|
|
||||||
if (typeof bytesPerChar !== 'number' || bytesPerChar % 1 !== 0 || bytesPerChar < 1 || bytesPerChar >
|
if (typeof bytesPerChar !== 'number' || bytesPerChar % 1 !== 0 || bytesPerChar < 1 ||
|
||||||
|
bytesPerChar >
|
||||||
defaults.maxBytesPerChar) {
|
defaults.maxBytesPerChar) {
|
||||||
throw new Error('Bytes per character must be an integer between 1 and ' + defaults.maxBytesPerChar +
|
throw new Error('Bytes per character must be an integer between 1 and ' + defaults.maxBytesPerChar +
|
||||||
', inclusive.')
|
', inclusive.')
|
||||||
@ -3518,14 +3514,22 @@
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
var lowprimes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89,
|
var lowprimes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83,
|
||||||
97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193,
|
89,
|
||||||
197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311,
|
97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191,
|
||||||
313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433,
|
193,
|
||||||
439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569,
|
197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307,
|
||||||
571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683,
|
311,
|
||||||
691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827,
|
313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431,
|
||||||
829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971,
|
433,
|
||||||
|
439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563,
|
||||||
|
569,
|
||||||
|
571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677,
|
||||||
|
683,
|
||||||
|
691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823,
|
||||||
|
827,
|
||||||
|
829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967,
|
||||||
|
971,
|
||||||
977, 983, 991, 997
|
977, 983, 991, 997
|
||||||
];
|
];
|
||||||
var lplim = (1 << 26) / lowprimes[lowprimes.length - 1];
|
var lplim = (1 << 26) / lowprimes[lowprimes.length - 1];
|
||||||
@ -4997,7 +5001,8 @@
|
|||||||
getBCHTypeInfo: function (data) {
|
getBCHTypeInfo: function (data) {
|
||||||
var d = data << 10;
|
var d = data << 10;
|
||||||
while (QRCode.Util.getBCHDigit(d) - QRCode.Util.getBCHDigit(QRCode.Util.G15) >= 0) {
|
while (QRCode.Util.getBCHDigit(d) - QRCode.Util.getBCHDigit(QRCode.Util.G15) >= 0) {
|
||||||
d ^= (QRCode.Util.G15 << (QRCode.Util.getBCHDigit(d) - QRCode.Util.getBCHDigit(QRCode.Util
|
d ^= (QRCode.Util.G15 << (QRCode.Util.getBCHDigit(d) - QRCode.Util.getBCHDigit(
|
||||||
|
QRCode.Util
|
||||||
.G15)));
|
.G15)));
|
||||||
}
|
}
|
||||||
return ((data << 10) | d) ^ QRCode.Util.G15_MASK;
|
return ((data << 10) | d) ^ QRCode.Util.G15_MASK;
|
||||||
@ -5006,7 +5011,8 @@
|
|||||||
getBCHTypeNumber: function (data) {
|
getBCHTypeNumber: function (data) {
|
||||||
var d = data << 12;
|
var d = data << 12;
|
||||||
while (QRCode.Util.getBCHDigit(d) - QRCode.Util.getBCHDigit(QRCode.Util.G18) >= 0) {
|
while (QRCode.Util.getBCHDigit(d) - QRCode.Util.getBCHDigit(QRCode.Util.G18) >= 0) {
|
||||||
d ^= (QRCode.Util.G18 << (QRCode.Util.getBCHDigit(d) - QRCode.Util.getBCHDigit(QRCode.Util
|
d ^= (QRCode.Util.G18 << (QRCode.Util.getBCHDigit(d) - QRCode.Util.getBCHDigit(
|
||||||
|
QRCode.Util
|
||||||
.G18)));
|
.G18)));
|
||||||
}
|
}
|
||||||
return (data << 12) | d;
|
return (data << 12) | d;
|
||||||
@ -5317,7 +5323,8 @@
|
|||||||
|
|
||||||
for (var i = 0; i < this.getLength(); i++) {
|
for (var i = 0; i < this.getLength(); i++) {
|
||||||
for (var j = 0; j < e.getLength(); j++) {
|
for (var j = 0; j < e.getLength(); j++) {
|
||||||
num[i + j] ^= QRCode.Math.gexp(QRCode.Math.glog(this.get(i)) + QRCode.Math.glog(e.get(
|
num[i + j] ^= QRCode.Math.gexp(QRCode.Math.glog(this.get(i)) + QRCode.Math.glog(
|
||||||
|
e.get(
|
||||||
j)));
|
j)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -5669,7 +5676,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
|||||||
</script>
|
</script>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
//https://raw.github.com/bitcoinjs/bitcoinjs-lib/e90780d3d3b8fc0d027d2bcb38b80479902f223e/src/ecdsa.js
|
//https://raw.github.com/bitcoinjs/bitcoinjs-lib/e90780d3d3b8fc0d027d2bcb38b80479902f223e/src/ecdsa.js
|
||||||
Bitcoin.ECDSA = (function (ec) {
|
Bitcoin.ECDSA = (function () {
|
||||||
var ecparams = EllipticCurve.getSECCurveByName("secp256k1");
|
var ecparams = EllipticCurve.getSECCurveByName("secp256k1");
|
||||||
var rng = new SecureRandom();
|
var rng = new SecureRandom();
|
||||||
|
|
||||||
@ -5717,7 +5724,6 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
|||||||
var G = ecparams.getG();
|
var G = ecparams.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);
|
||||||
|
|
||||||
} while (r.compareTo(BigInteger.ZERO) <= 0);
|
} while (r.compareTo(BigInteger.ZERO) <= 0);
|
||||||
|
|
||||||
var s = k.modInverse(n).multiply(e.add(d.multiply(r))).mod(n);
|
var s = k.modInverse(n).multiply(e.add(d.multiply(r))).mod(n);
|
||||||
@ -5737,16 +5743,11 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
|||||||
} else {
|
} else {
|
||||||
throw "Invalid value for signature";
|
throw "Invalid value for signature";
|
||||||
}
|
}
|
||||||
console.log(hash);
|
|
||||||
console.log(sig);
|
|
||||||
console.log("pubkey instanceof ec.PointFp: ", pubkey instanceof ec.PointFp);
|
|
||||||
console.log("Bitcoin.Util.isArray(pubkey): ", Bitcoin.Util.isArray(pubkey));
|
|
||||||
|
|
||||||
var Q;
|
var Q;
|
||||||
if (pubkey instanceof ec.PointFp) {
|
if (pubkey instanceof ec.PointFp) {
|
||||||
Q = pubkey;
|
Q = pubkey;
|
||||||
} else
|
} else if (Bitcoin.Util.isArray(pubkey)) {
|
||||||
if (Bitcoin.Util.isArray(pubkey)) {
|
|
||||||
Q = EllipticCurve.PointFp.decodeFrom(ecparams.getCurve(), pubkey);
|
Q = EllipticCurve.PointFp.decodeFrom(ecparams.getCurve(), pubkey);
|
||||||
} else {
|
} else {
|
||||||
throw "Invalid format for pubkey value, must be byte array or ec.PointFp";
|
throw "Invalid format for pubkey value, must be byte array or ec.PointFp";
|
||||||
@ -5781,9 +5782,6 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
|||||||
|
|
||||||
var v = point.getX().toBigInteger().mod(n);
|
var v = point.getX().toBigInteger().mod(n);
|
||||||
|
|
||||||
console.log(v);
|
|
||||||
console.log(r);
|
|
||||||
|
|
||||||
return v.equals(r);
|
return v.equals(r);
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -5966,7 +5964,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
|||||||
};
|
};
|
||||||
|
|
||||||
return ECDSA;
|
return ECDSA;
|
||||||
})(window.EllipticCurve);
|
})();
|
||||||
</script>
|
</script>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
Bitcoin.KeyPool = (function () {
|
Bitcoin.KeyPool = (function () {
|
||||||
@ -6012,7 +6010,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
|||||||
var item = pool[index];
|
var item = pool[index];
|
||||||
if (Bitcoin.Util.hasMethods(item, 'getBitcoinAddress', 'toString')) {
|
if (Bitcoin.Util.hasMethods(item, 'getBitcoinAddress', 'toString')) {
|
||||||
if (item != null) {
|
if (item != null) {
|
||||||
keyPoolString += "\"" + item.getBitcoinAddress() + "\"" + ", \"" + item.toString(
|
keyPoolString += "\"" + item.getBitcoinAddress() + "\"" + ", \"" + item
|
||||||
|
.toString(
|
||||||
"wif") + "\"\n";
|
"wif") + "\"\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -6098,7 +6097,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
|||||||
if (this.priv != null && BigInteger.ZERO.compareTo(this.priv) == 0) this.setError(
|
if (this.priv != null && BigInteger.ZERO.compareTo(this.priv) == 0) this.setError(
|
||||||
"Error: BigInteger equal to zero.");
|
"Error: BigInteger equal to zero.");
|
||||||
// valid range [0x1, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364140])
|
// valid range [0x1, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364140])
|
||||||
var hexKeyRangeLimit = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364140";
|
var hexKeyRangeLimit =
|
||||||
|
"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364140";
|
||||||
var rangeLimitBytes = Crypto.util.hexToBytes(hexKeyRangeLimit);
|
var rangeLimitBytes = Crypto.util.hexToBytes(hexKeyRangeLimit);
|
||||||
var limitBigInt = BigInteger.fromByteArrayUnsigned(rangeLimitBytes);
|
var limitBigInt = BigInteger.fromByteArrayUnsigned(rangeLimitBytes);
|
||||||
if (this.priv != null && limitBigInt.compareTo(this.priv) < 0) this.setError(
|
if (this.priv != null && limitBigInt.compareTo(this.priv) < 0) this.setError(
|
||||||
@ -6337,7 +6337,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
|||||||
// 44 characters
|
// 44 characters
|
||||||
ECKey.isBase64Format = function (key) {
|
ECKey.isBase64Format = function (key) {
|
||||||
key = key.toString();
|
key = key.toString();
|
||||||
return (/^[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789=+\/]{44}$/.test(key));
|
return (/^[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789=+\/]{44}$/.test(
|
||||||
|
key));
|
||||||
};
|
};
|
||||||
|
|
||||||
// 99 characters, 1=1, if using dice convert 6 to 0
|
// 99 characters, 1=1, if using dice convert 6 to 0
|
||||||
@ -6553,7 +6554,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
|||||||
type: "text/javascript"
|
type: "text/javascript"
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
window.BlobBuilder = window.BlobBuilder || window.WebKitBlobBuilder || window.MozBlobBuilder ||
|
window.BlobBuilder = window.BlobBuilder || window.WebKitBlobBuilder ||
|
||||||
|
window.MozBlobBuilder ||
|
||||||
window.MSBlobBuilder;
|
window.MSBlobBuilder;
|
||||||
blob = new BlobBuilder();
|
blob = new BlobBuilder();
|
||||||
blob.append(code);
|
blob.append(code);
|
||||||
@ -6869,284 +6871,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
|||||||
})();
|
})();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<script type="text/javascript">
|
||||||
|
|
||||||
|
|
||||||
<!-- JSON RPC Calls -->
|
|
||||||
<script language="javascript" type="text/javascript">
|
|
||||||
var JSON_RPC = {};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var id = 0,
|
|
||||||
callbacks = {};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs a new JSON-RPC Request
|
|
||||||
* @param method A String containing the name of the method to be invoked.
|
|
||||||
* @param params (optional) A Structured value that holds the parameter values to be used during the invocation of the method.
|
|
||||||
*/
|
|
||||||
JSON_RPC.Request = function (method, params) {
|
|
||||||
this.jsonrpc = "2.0";
|
|
||||||
this.method = method;
|
|
||||||
if (typeof params !== "undefined") {
|
|
||||||
this.params = params;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.id = id++;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Implements getters and setters for the result of a JSON-RPC Request.
|
|
||||||
// The result may be an any Object or primitive
|
|
||||||
Object.defineProperty(JSON_RPC.Request.prototype, "result", {
|
|
||||||
get: function () {
|
|
||||||
return this._result;
|
|
||||||
},
|
|
||||||
set: function (result) {
|
|
||||||
delete this.method; // remove the method name
|
|
||||||
delete this.params; // remove the params
|
|
||||||
delete this.error; // remove error state if it exists
|
|
||||||
this._result = result;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Implements getters and setters for the error state of a JSON-RPC Request.
|
|
||||||
// Error should be a JSON_RPC.Error object
|
|
||||||
Object.defineProperty(JSON_RPC.Request.prototype, "error", {
|
|
||||||
get: function () {
|
|
||||||
return this._error;
|
|
||||||
},
|
|
||||||
set: function (error) {
|
|
||||||
delete this.method; // remove the method name
|
|
||||||
delete this.params; // remove the params
|
|
||||||
delete this.result; // remove result state if it exists
|
|
||||||
this._error = error;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a String representation of a JSON-RPC Request
|
|
||||||
* @returns A JSON String
|
|
||||||
*/
|
|
||||||
JSON_RPC.Request.prototype.toString = function () {
|
|
||||||
var rpc = {
|
|
||||||
jsonrpc: this.jsonrpc,
|
|
||||||
id: this.id
|
|
||||||
};
|
|
||||||
|
|
||||||
if (this.method !== undefined) rpc.method = this.method;
|
|
||||||
if (this.params !== undefined) rpc.params = this.params;
|
|
||||||
if (this.result !== undefined) rpc.result = this.result;
|
|
||||||
if (this.error !== undefined) rpc.error = this.error;
|
|
||||||
|
|
||||||
return JSON.stringify(rpc);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs a new JSON-RPC Notification
|
|
||||||
* @param method A String containing the name of the method to be invoked.
|
|
||||||
* @param params (optional) A Structured value that holds the parameter values to be used during the invocation of the method.
|
|
||||||
*/
|
|
||||||
JSON_RPC.Notification = function (method, params) {
|
|
||||||
this.jsonrpc = "2.0";
|
|
||||||
this.method = method;
|
|
||||||
if (typeof params !== "undefined") {
|
|
||||||
this.params = params;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a String representation of a JSON-RPC Notification
|
|
||||||
* @returns A JSON String
|
|
||||||
*/
|
|
||||||
JSON_RPC.Notification.prototype.toString = function () {
|
|
||||||
var rpc = {
|
|
||||||
jsonrpc: this.jsonrpc,
|
|
||||||
method: this.method,
|
|
||||||
params: this.params
|
|
||||||
};
|
|
||||||
|
|
||||||
return JSON.stringify(rpc);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs a new JSON-RPC Errror object
|
|
||||||
* @params code A Number that indicates the error type that occurred. -32768 to -32000 are reserved.
|
|
||||||
* @param message (optional) A String providing a short description of the error.
|
|
||||||
* @param data (optional) A Primitive or Structured value that contains additional information about the error.
|
|
||||||
*/
|
|
||||||
JSON_RPC.Error = function (code, message, data) {
|
|
||||||
this.code = code;
|
|
||||||
if (typeof message == "string") this.message = message;
|
|
||||||
if (data !== undefined) this.data = data;
|
|
||||||
};
|
|
||||||
|
|
||||||
// stock errors
|
|
||||||
JSON_RPC.PARSE_ERROR = new JSON_RPC.Error(-32700, "An error occurred on the server while parsing the JSON text.");
|
|
||||||
JSON_RPC.INVALID_REQUEST = new JSON_RPC.Error(-32600, "The JSON sent is not a valid Request object.");
|
|
||||||
JSON_RPC.METHOD_NOT_FOUND = new JSON_RPC.Error(-32601, "The method does not exist / is not available.");
|
|
||||||
JSON_RPC.INVALID_PARAMS = new JSON_RPC.Error(-32602, "Invalid method parameter(s).");
|
|
||||||
JSON_RPC.INTERNAL_ERROR = new JSON_RPC.Error(-32603, "Internal JSON-RPC error.");
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parses a JSON-RPC string and converts to a JSON-RPC object or an Array of such strings.
|
|
||||||
* @params rpc A String or Array to parse to a JSON-RPC object.
|
|
||||||
*/
|
|
||||||
JSON_RPC.parse = function (rpc) {
|
|
||||||
// batch?
|
|
||||||
if (rpc.constructor === Array) {
|
|
||||||
var arr = [];
|
|
||||||
rpc.forEach(function (el) {
|
|
||||||
arr.push(JSON_RPC.parse(el));
|
|
||||||
});
|
|
||||||
return arr;
|
|
||||||
}
|
|
||||||
|
|
||||||
// parsable?
|
|
||||||
var rpc;
|
|
||||||
try {
|
|
||||||
rpc = JSON.parse(rpc);
|
|
||||||
} catch (err) {
|
|
||||||
var obj = new JSON_RPC.Request();
|
|
||||||
obj.result = JSON_RPC.PARSE_ERROR;
|
|
||||||
obj.id = null;
|
|
||||||
return obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 2.0?
|
|
||||||
if (rpc.jsonrpc !== "2.0") {
|
|
||||||
var obj = new JSON_RPC.Request();
|
|
||||||
obj.result = JSON_RPC.INVALID_REQUEST;
|
|
||||||
obj.id = null;
|
|
||||||
return obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
// request or notification?
|
|
||||||
var obj = (rpc.id === undefined) ?
|
|
||||||
new JSON_RPC.Notification(rpc.method, rpc.params) :
|
|
||||||
new JSON_RPC.Request(rpc.method, rpc.params);
|
|
||||||
// have an ID?
|
|
||||||
if (rpc.id !== undefined) obj.id = rpc.id;
|
|
||||||
// is it a result?
|
|
||||||
if (rpc.result !== undefined) obj.result = rpc.result;
|
|
||||||
// is it a error?
|
|
||||||
if (rpc.error !== undefined) {
|
|
||||||
obj.error = new JSON_RPC.Error(
|
|
||||||
rpc.error.code,
|
|
||||||
rpc.error.message,
|
|
||||||
rpc.error.data
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// parsed :-)
|
|
||||||
return obj;
|
|
||||||
};
|
|
||||||
|
|
||||||
/* JSON RPC Library Ends */
|
|
||||||
|
|
||||||
|
|
||||||
/* Custom Localbitcoin++ JSON-RPC code starts here */
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// var request = new JSON_RPC.Request("SignMessage", "[1,2]");
|
|
||||||
// var id = request.id;
|
|
||||||
// var initialJSONSend = request.toString();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var request = new JSON_RPC.parse('{"jsonrpc":"2.0","id":0,"method":"SignMessage","params":"[3,4]"}'); //Request is Websocket data received -- websocket.onmessage
|
|
||||||
var methodToExecute = request.method; // if successful
|
|
||||||
executeJSONRequest(methodToExecute);
|
|
||||||
var initialJSONSend = request.toString(); // return to client
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function executeJSONRequest(methodToExecute) {
|
|
||||||
if (methodToExecute == "SignMessage") {
|
|
||||||
console.log("SignMessage Executed")
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// Start building all functions here
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Custom JSON-RPC code ends */
|
|
||||||
|
|
||||||
|
|
||||||
/* Websocket Code Starts here */
|
|
||||||
|
|
||||||
var wsUri = "ws://localhost:9000/";
|
|
||||||
var output;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function init() {
|
|
||||||
output = document.getElementById("output");
|
|
||||||
testWebSocket();
|
|
||||||
}
|
|
||||||
|
|
||||||
function testWebSocket() {
|
|
||||||
websocket = new WebSocket(wsUri);
|
|
||||||
websocket.onopen = function (evt) {
|
|
||||||
onOpen(evt)
|
|
||||||
};
|
|
||||||
websocket.onclose = function (evt) {
|
|
||||||
onClose(evt)
|
|
||||||
};
|
|
||||||
websocket.onmessage = function (evt) {
|
|
||||||
onMessage(evt)
|
|
||||||
};
|
|
||||||
websocket.onerror = function (evt) {
|
|
||||||
onError(evt)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function onOpen(evt) {
|
|
||||||
writeToScreen("CONNECTED");
|
|
||||||
doSend("Intial Hello Message: WebSocket rocks");
|
|
||||||
}
|
|
||||||
|
|
||||||
function onClose(evt) {
|
|
||||||
writeToScreen("DISCONNECTED");
|
|
||||||
}
|
|
||||||
|
|
||||||
function onMessage(evt) {
|
|
||||||
writeToScreen('<span style="color: blue;">RESPONSE: ' + evt.data + '</span>');
|
|
||||||
//websocket.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
function onError(evt) {
|
|
||||||
writeToScreen('<span style="color: red;">ERROR:</span> ' + evt.data);
|
|
||||||
}
|
|
||||||
|
|
||||||
function doSend(message) {
|
|
||||||
writeToScreen("SENT: " + message);
|
|
||||||
websocket.send(message);
|
|
||||||
websocket.send(initialJSONSend);
|
|
||||||
}
|
|
||||||
|
|
||||||
function writeToScreen(message) {
|
|
||||||
var pre = document.createElement("p");
|
|
||||||
pre.style.wordWrap = "break-word";
|
|
||||||
pre.innerHTML = message;
|
|
||||||
output.appendChild(pre);
|
|
||||||
}
|
|
||||||
|
|
||||||
window.addEventListener("load", init, false);
|
|
||||||
|
|
||||||
/* Websocket Code Ends Here*/
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<h2>Localbitcoin++ Prototype</h2>
|
|
||||||
|
|
||||||
<div id="output"></div>
|
|
||||||
|
|
||||||
<!-- Private/Public Key functions -->
|
|
||||||
<script>
|
|
||||||
var ninja = {
|
var ninja = {
|
||||||
wallets: {}
|
wallets: {}
|
||||||
};
|
};
|
||||||
@ -7213,7 +6938,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
|||||||
var expChecksum = hex.slice(-4);
|
var expChecksum = hex.slice(-4);
|
||||||
hex = hex.slice(0, -4);
|
hex = hex.slice(0, -4);
|
||||||
var checksum = Bitcoin.Util.dsha256(hex);
|
var checksum = Bitcoin.Util.dsha256(hex);
|
||||||
if (checksum[0] != expChecksum[0] || checksum[1] != expChecksum[1] || checksum[2] != expChecksum[2] ||
|
if (checksum[0] != expChecksum[0] || checksum[1] != expChecksum[1] || checksum[2] !=
|
||||||
|
expChecksum[2] ||
|
||||||
checksum[3] != expChecksum[3]) {
|
checksum[3] != expChecksum[3]) {
|
||||||
callback(new Error(ninja.translator.get("detailalertnotvalidprivatekey")));
|
callback(new Error(ninja.translator.get("detailalertnotvalidprivatekey")));
|
||||||
return;
|
return;
|
||||||
@ -7259,7 +6985,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
|||||||
var base58AddrText = tmpkey.setCompressed(isCompPoint).getBitcoinAddress(); // isCompPoint using closure
|
var base58AddrText = tmpkey.setCompressed(isCompPoint).getBitcoinAddress(); // isCompPoint using closure
|
||||||
checksum = Bitcoin.Util.dsha256(base58AddrText); // checksum using closure
|
checksum = Bitcoin.Util.dsha256(base58AddrText); // checksum using closure
|
||||||
|
|
||||||
if (checksum[0] != hex[3] || checksum[1] != hex[4] || checksum[2] != hex[5] || checksum[3] !=
|
if (checksum[0] != hex[3] || checksum[1] != hex[4] || checksum[2] != hex[5] || checksum[
|
||||||
|
3] !=
|
||||||
hex[6]) {
|
hex[6]) {
|
||||||
callback(new Error(ninja.translator.get("bip38alertincorrectpassphrase"))); // callback using closure
|
callback(new Error(ninja.translator.get("bip38alertincorrectpassphrase"))); // callback using closure
|
||||||
return;
|
return;
|
||||||
@ -7298,19 +7025,22 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
|||||||
derived) {
|
derived) {
|
||||||
var k = derived.slice(32);
|
var k = derived.slice(32);
|
||||||
|
|
||||||
var unencryptedpart2 = Crypto.AES.decrypt(encryptedpart2, k, AES_opts);
|
var unencryptedpart2 = Crypto.AES.decrypt(encryptedpart2, k,
|
||||||
|
AES_opts);
|
||||||
for (var i = 0; i < 16; i++) {
|
for (var i = 0; i < 16; i++) {
|
||||||
unencryptedpart2[i] ^= derived[i + 16];
|
unencryptedpart2[i] ^= derived[i + 16];
|
||||||
}
|
}
|
||||||
|
|
||||||
var encryptedpart1 = hex.slice(15, 15 + 8).concat(unencryptedpart2.slice(
|
var encryptedpart1 = hex.slice(15, 15 + 8).concat(unencryptedpart2.slice(
|
||||||
0, 0 + 8));
|
0, 0 + 8));
|
||||||
var unencryptedpart1 = Crypto.AES.decrypt(encryptedpart1, k, AES_opts);
|
var unencryptedpart1 = Crypto.AES.decrypt(encryptedpart1, k,
|
||||||
|
AES_opts);
|
||||||
for (var i = 0; i < 16; i++) {
|
for (var i = 0; i < 16; i++) {
|
||||||
unencryptedpart1[i] ^= derived[i];
|
unencryptedpart1[i] ^= derived[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
var seedb = unencryptedpart1.slice(0, 0 + 16).concat(unencryptedpart2.slice(
|
var seedb = unencryptedpart1.slice(0, 0 + 16).concat(
|
||||||
|
unencryptedpart2.slice(
|
||||||
8, 8 + 8));
|
8, 8 + 8));
|
||||||
|
|
||||||
var factorb = Bitcoin.Util.dsha256(seedb);
|
var factorb = Bitcoin.Util.dsha256(seedb);
|
||||||
@ -7437,7 +7167,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
|||||||
var addressHash = Bitcoin.Util.dsha256(generatedAddress).slice(0, 4);
|
var addressHash = Bitcoin.Util.dsha256(generatedAddress).slice(0, 4);
|
||||||
|
|
||||||
// 5) Now we will encrypt seedb. Derive a second key from passpoint using scrypt
|
// 5) Now we will encrypt seedb. Derive a second key from passpoint using scrypt
|
||||||
Crypto_scrypt(passpoint, addressHash.concat(ownerEntropy), 1024, 1, 1, 64, function (derivedBytes) {
|
Crypto_scrypt(passpoint, addressHash.concat(ownerEntropy), 1024, 1, 1, 64, function (
|
||||||
|
derivedBytes) {
|
||||||
// 6) Do AES256Encrypt(seedb[0...15]] xor derivedhalf1[0...15], derivedhalf2), call the 16-byte result encryptedpart1
|
// 6) Do AES256Encrypt(seedb[0...15]] xor derivedhalf1[0...15], derivedhalf2), call the 16-byte result encryptedpart1
|
||||||
for (var i = 0; i < 16; ++i) {
|
for (var i = 0; i < 16; ++i) {
|
||||||
seedB[i] ^= derivedBytes[i];
|
seedB[i] ^= derivedBytes[i];
|
||||||
@ -7465,7 +7196,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
|||||||
callback(generatedAddress, Bitcoin.Base58.encode(encryptedKey));
|
callback(generatedAddress, Bitcoin.Base58.encode(encryptedKey));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
ninja.publicKey = {
|
ninja.publicKey = {
|
||||||
isPublicKeyHexFormat: function (key) {
|
isPublicKeyHexFormat: function (key) {
|
||||||
@ -7526,187 +7257,82 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
|||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<!-- QR Code -->
|
|
||||||
<script type="text/javascript">
|
|
||||||
(function (ninja) {
|
|
||||||
var qrC = ninja.qrCode = {
|
|
||||||
// determine which type number is big enough for the input text length
|
|
||||||
getTypeNumber: function (text) {
|
|
||||||
var lengthCalculation = text.length * 8 + 12; // length as calculated by the QRCode
|
|
||||||
if (lengthCalculation < 72) {
|
|
||||||
return 1;
|
|
||||||
} else if (lengthCalculation < 128) {
|
|
||||||
return 2;
|
|
||||||
} else if (lengthCalculation < 208) {
|
|
||||||
return 3;
|
|
||||||
} else if (lengthCalculation < 288) {
|
|
||||||
return 4;
|
|
||||||
} else if (lengthCalculation < 368) {
|
|
||||||
return 5;
|
|
||||||
} else if (lengthCalculation < 480) {
|
|
||||||
return 6;
|
|
||||||
} else if (lengthCalculation < 528) {
|
|
||||||
return 7;
|
|
||||||
} else if (lengthCalculation < 688) {
|
|
||||||
return 8;
|
|
||||||
} else if (lengthCalculation < 800) {
|
|
||||||
return 9;
|
|
||||||
} else if (lengthCalculation < 976) {
|
|
||||||
return 10;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
},
|
|
||||||
|
|
||||||
createCanvas: function (text, sizeMultiplier) {
|
|
||||||
sizeMultiplier = (sizeMultiplier == undefined) ? 2 : sizeMultiplier; // default 2
|
|
||||||
// create the qrcode itself
|
|
||||||
var typeNumber = qrC.getTypeNumber(text);
|
|
||||||
var qrcode = new QRCode(typeNumber, QRCode.ErrorCorrectLevel.H);
|
|
||||||
qrcode.addData(text);
|
|
||||||
qrcode.make();
|
|
||||||
var width = qrcode.getModuleCount() * sizeMultiplier;
|
|
||||||
var height = qrcode.getModuleCount() * sizeMultiplier;
|
|
||||||
// create canvas element
|
|
||||||
var canvas = document.createElement('canvas');
|
|
||||||
var scale = 10.0;
|
|
||||||
canvas.width = width * scale;
|
|
||||||
canvas.height = height * scale;
|
|
||||||
canvas.style.width = width + 'px';
|
|
||||||
canvas.style.height = height + 'px';
|
|
||||||
var ctx = canvas.getContext('2d');
|
|
||||||
ctx.scale(scale, scale);
|
|
||||||
// compute tileW/tileH based on width/height
|
|
||||||
var tileW = width / qrcode.getModuleCount();
|
|
||||||
var tileH = height / qrcode.getModuleCount();
|
|
||||||
// draw in the canvas
|
|
||||||
for (var row = 0; row < qrcode.getModuleCount(); row++) {
|
|
||||||
for (var col = 0; col < qrcode.getModuleCount(); col++) {
|
|
||||||
ctx.fillStyle = qrcode.isDark(row, col) ? "#000000" : "#ffffff";
|
|
||||||
ctx.fillRect(col * tileW, row * tileH, tileW, tileH);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// return just built canvas
|
|
||||||
return canvas;
|
|
||||||
},
|
|
||||||
|
|
||||||
// show QRCodes with canvas
|
|
||||||
// parameter: keyValuePair
|
|
||||||
// example: { "id1": "string1", "id2": "string2"}
|
|
||||||
// "id1" is the id of a div element where you want a QRCode inserted.
|
|
||||||
// "string1" is the string you want encoded into the QRCode.
|
|
||||||
showQrCode: function (keyValuePair, sizeMultiplier) {
|
|
||||||
for (var key in keyValuePair) {
|
|
||||||
var value = keyValuePair[key];
|
|
||||||
try {
|
|
||||||
if (document.getElementById(key)) {
|
|
||||||
document.getElementById(key).innerHTML = "";
|
|
||||||
document.getElementById(key).appendChild(qrC.createCanvas(value, sizeMultiplier));
|
|
||||||
}
|
|
||||||
} catch (e) {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
})(ninja);
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<!-- My functions -->
|
|
||||||
<script type="text/javascript">
|
|
||||||
(function (wallets, qrCode) {
|
|
||||||
var single = wallets.singlewallet = {
|
|
||||||
isOpen: function () {
|
|
||||||
return (document.getElementById("singlewallet").className.indexOf("selected") != -1);
|
|
||||||
},
|
|
||||||
|
|
||||||
open: function () {
|
|
||||||
if (document.getElementById("btcaddress").innerHTML == "") {
|
|
||||||
single.generateNewAddressAndKey();
|
|
||||||
}
|
|
||||||
document.getElementById("singlearea").style.display = "block";
|
|
||||||
},
|
|
||||||
|
|
||||||
close: function () {
|
|
||||||
document.getElementById("singlearea").style.display = "none";
|
|
||||||
},
|
|
||||||
|
|
||||||
// generate bitcoin address and private key and update information in the HTML
|
|
||||||
generateNewAddressAndKey: function () {
|
|
||||||
try {
|
|
||||||
var key = new Bitcoin.ECKey(false);
|
|
||||||
key.setCompressed(true);
|
|
||||||
var bitcoinAddress = key.getBitcoinAddress();
|
|
||||||
var privateKeyWif = key.getBitcoinWalletImportFormat();
|
|
||||||
document.getElementById("btcaddress").innerHTML = bitcoinAddress;
|
|
||||||
document.getElementById("btcprivwif").innerHTML = privateKeyWif;
|
|
||||||
var keyValuePair = {
|
|
||||||
"qrcode_public": bitcoinAddress,
|
|
||||||
"qrcode_private": privateKeyWif
|
|
||||||
};
|
|
||||||
qrCode.showQrCode(keyValuePair, 4);
|
|
||||||
} catch (e) {
|
|
||||||
// browser does not have sufficient JavaScript support to generate a bitcoin address
|
|
||||||
alert(e);
|
|
||||||
document.getElementById("btcaddress").innerHTML = "error";
|
|
||||||
document.getElementById("btcprivwif").innerHTML = "error";
|
|
||||||
document.getElementById("qrcode_public").innerHTML = "";
|
|
||||||
document.getElementById("qrcode_private").innerHTML = "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
})(ninja.wallets, ninja.qrCode);
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
(function (wallets) {
|
(function (wallets) {
|
||||||
|
|
||||||
var signing = wallets.flowallet = {
|
var signing = wallets.flowallet = {
|
||||||
bigInt: function (data) {
|
|
||||||
var BI = new BigInteger(data);
|
|
||||||
return BI;
|
|
||||||
},
|
|
||||||
generateFloKeys: function () {
|
generateFloKeys: function () {
|
||||||
var key = new Bitcoin.ECKey(false);
|
|
||||||
key.setCompressed(true);
|
// var key = new Bitcoin.ECKey(false);
|
||||||
var bitcoinAddress = key.getBitcoinAddress();
|
// key.setCompressed(true);
|
||||||
var privateKeyWif = key.getBitcoinWalletImportFormat();
|
// var bitcoinAddress = key.getBitcoinAddress();
|
||||||
var privateKey = key.getBitcoinHexFormat();
|
// var privateKeyWif = key.getBitcoinWalletImportFormat();
|
||||||
var publicKey = key.getPubKeyHex();
|
// var privateKey = key.getBitcoinHexFormat();
|
||||||
var publicKeyECPoint = key.getPubPoint(); // Return public point as ECPoint object.
|
// var publicKey = key.getPubKeyHex();
|
||||||
console.log("bitcoinAddress", bitcoinAddress);
|
// var publicKeyECPoint = key.getPubPoint(); // Return public point as ECPoint object.
|
||||||
console.log("privateKeyWif", privateKeyWif);
|
// console.log("bitcoinAddress", bitcoinAddress);
|
||||||
console.log("publicKey", publicKey);
|
// console.log("privateKeyWif", privateKeyWif);
|
||||||
|
// console.log("publicKey", publicKey);
|
||||||
|
// console.log("publicKeyECPoint", publicKeyECPoint);
|
||||||
|
|
||||||
|
// var ms = "hello";
|
||||||
|
// var signn = this.sign(ms, privateKeyWif);
|
||||||
|
|
||||||
|
// var veri = this.verify(ms, signn, publicKeyECPoint);
|
||||||
|
// console.log(veri);
|
||||||
|
|
||||||
|
var privateKey = Bitcoin.ECDSA.getBigRandom(EllipticCurve.getSECCurveByName("secp256k1").getN());
|
||||||
|
var publicKey = EllipticCurve.getSECCurveByName("secp256k1").getG().multiply(privateKey);
|
||||||
|
|
||||||
|
console.log(privateKey);
|
||||||
|
console.log(publicKey);
|
||||||
|
|
||||||
var ms = "hello";
|
var ms = "hello";
|
||||||
var signn = this.sign(ms, privateKeyWif);
|
var sign = this.sign(ms, privateKey);
|
||||||
|
console.log(sign);
|
||||||
var veri = this.verify(ms, signn, publicKey);
|
var verify = this.verify(ms, sign, publicKey);
|
||||||
console.log(veri);
|
console.log(verify);
|
||||||
|
|
||||||
},
|
},
|
||||||
sign: function (msg, privateKey) {
|
sign: function (msg, privateKey) {
|
||||||
var msgHash = Crypto.SHA256(msg);
|
// var msgHash = Crypto.SHA256(msg);
|
||||||
var msgHashBI = this.bigInt(msgHash);
|
// var msgHashBI = this.bigInt(msgHash);
|
||||||
var privateKeyHashBI = this.bigInt(privateKey);
|
// var privateKeyHashBI = this.bigInt(privateKey);
|
||||||
var signature = new Bitcoin.ECDSA.sign(msgHashBI, privateKeyHashBI);
|
// var signature = new Bitcoin.ECDSA.sign(msgHashBI, privateKeyHashBI);
|
||||||
|
|
||||||
//return signature;
|
// //return signature;
|
||||||
console.log(Crypto.util.bytesToHex(signature));
|
// console.log(Crypto.util.bytesToHex(signature));
|
||||||
|
|
||||||
|
// return Crypto.util.bytesToHex(signature);
|
||||||
|
|
||||||
|
var messageHash = Crypto.SHA256(msg);
|
||||||
|
|
||||||
|
var messageHashBigInteger = new BigInteger(messageHash);
|
||||||
|
|
||||||
|
var messageSign = Bitcoin.ECDSA.sign(messageHashBigInteger, privateKey);
|
||||||
|
|
||||||
|
var messageSignParse = Bitcoin.ECDSA.parseSig(messageSign);
|
||||||
|
|
||||||
|
return messageSignParse;
|
||||||
|
|
||||||
return Crypto.util.bytesToHex(signature);
|
|
||||||
},
|
},
|
||||||
verify: function (msg, signature, publicKey) {
|
verify: function (msg, signature, publicKey) {
|
||||||
var msgHash = Crypto.SHA256(msg);
|
var msgHash = Crypto.SHA256(msg);
|
||||||
var msgHashBI = this.bigInt(msgHash);
|
var messageHashBigInteger = new BigInteger(msgHash);
|
||||||
//var msgHashBI = Crypto.util.hexToBytes(msgHash);
|
// //var msgHashBI = Crypto.util.hexToBytes(msgHash);
|
||||||
|
|
||||||
var signatureBI = Crypto.util.hexToBytes(signature);
|
// var signatureBI = Crypto.util.hexToBytes(signature);
|
||||||
//var signatureBI = this.bigInt(signature);
|
|
||||||
//console.log(signatureBI);
|
|
||||||
|
|
||||||
//var publicKeyBI = this.bigInt(publicKey);
|
// //var signatureBI = this.bigInt(signature);
|
||||||
var publicKeyBI = Crypto.util.hexToBytes(publicKey);
|
// //console.log(signatureBI);
|
||||||
|
|
||||||
var verification = new Bitcoin.ECDSA.verify(msgHashBI, signatureBI, publicKeyBI);
|
// //var publicKeyBI = this.bigInt(publicKey);
|
||||||
return verification;
|
// //var publicKeyBI = Crypto.util.hexToBytes(publicKey);
|
||||||
|
// var publicKeyBI = publicKey;
|
||||||
|
|
||||||
|
// var verification = new Bitcoin.ECDSA.verify(msgHash, signatureBI, publicKeyBI);
|
||||||
|
// return verification;
|
||||||
|
var verify = Bitcoin.ECDSA.verifyRaw(messageHashBigInteger,signature.r, signature.s, publicKey);
|
||||||
|
return verify;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})(ninja.wallets)
|
})(ninja.wallets)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user