added flosend.html

This commit is contained in:
Abhishek Sinha 2018-10-21 23:00:33 +05:30
parent d7326aad3e
commit dfb0297929
2 changed files with 3803 additions and 68 deletions

3565
supernode/flosend.html Normal file

File diff suppressed because it is too large Load Diff

View File

@ -165,6 +165,157 @@
})(); })();
} }
</script> </script>
<!-- SHA1 -->
<script type="text/javascript">
//Adding SHA1 to fix basic PKBDF2
/*
* Crypto-JS v2.5.4
* http://code.google.com/p/crypto-js/
* (c) 2009-2012 by Jeff Mott. All rights reserved.
* http://code.google.com/p/crypto-js/wiki/License
*/
(function () {
// Shortcuts
var C = Crypto,
util = C.util,
charenc = C.charenc,
UTF8 = charenc.UTF8,
Binary = charenc.Binary;
// Public API
var SHA1 = C.SHA1 = function (message, options) {
var digestbytes = util.wordsToBytes(SHA1._sha1(message));
return options && options.asBytes ? digestbytes :
options && options.asString ? Binary.bytesToString(digestbytes) :
util.bytesToHex(digestbytes);
};
// The core
SHA1._sha1 = function (message) {
// Convert to byte array
if (message.constructor == String) message = UTF8.stringToBytes(message);
/* else, assume byte array already */
var m = util.bytesToWords(message),
l = message.length * 8,
w = [],
H0 = 1732584193,
H1 = -271733879,
H2 = -1732584194,
H3 = 271733878,
H4 = -1009589776;
// Padding
m[l >> 5] |= 0x80 << (24 - l % 32);
m[((l + 64 >>> 9) << 4) + 15] = l;
for (var i = 0; i < m.length; i += 16) {
var a = H0,
b = H1,
c = H2,
d = H3,
e = H4;
for (var j = 0; j < 80; j++) {
if (j < 16) w[j] = m[i + j];
else {
var n = w[j - 3] ^ w[j - 8] ^ w[j - 14] ^ w[j - 16];
w[j] = (n << 1) | (n >>> 31);
}
var t = ((H0 << 5) | (H0 >>> 27)) + H4 + (w[j] >>> 0) + (
j < 20 ? (H1 & H2 | ~H1 & H3) + 1518500249 :
j < 40 ? (H1 ^ H2 ^ H3) + 1859775393 :
j < 60 ? (H1 & H2 | H1 & H3 | H2 & H3) - 1894007588 :
(H1 ^ H2 ^ H3) - 899497514);
H4 = H3;
H3 = H2;
H2 = (H1 << 30) | (H1 >>> 2);
H1 = H0;
H0 = t;
}
H0 += a;
H1 += b;
H2 += c;
H3 += d;
H4 += e;
}
return [H0, H1, H2, H3, H4];
};
// Package private blocksize
SHA1._blocksize = 16;
SHA1._digestsize = 20;
})();
</script>
<!-- HMAC -->
<script type="text/javascript">
//Added to make PKBDF2 work
/*
* Crypto-JS v2.5.4
* http://code.google.com/p/crypto-js/
* (c) 2009-2012 by Jeff Mott. All rights reserved.
* http://code.google.com/p/crypto-js/wiki/License
*/
(function () {
// Shortcuts
var C = Crypto,
util = C.util,
charenc = C.charenc,
UTF8 = charenc.UTF8,
Binary = charenc.Binary;
C.HMAC = function (hasher, message, key, options) {
// Convert to byte arrays
if (message.constructor == String) message = UTF8.stringToBytes(message);
if (key.constructor == String) key = UTF8.stringToBytes(key);
/* else, assume byte arrays already */
// Allow arbitrary length keys
if (key.length > hasher._blocksize * 4)
key = hasher(key, {
asBytes: true
});
// XOR keys with pad constants
var okey = key.slice(0),
ikey = key.slice(0);
for (var i = 0; i < hasher._blocksize * 4; i++) {
okey[i] ^= 0x5C;
ikey[i] ^= 0x36;
}
var hmacbytes = hasher(okey.concat(hasher(ikey.concat(message), {
asBytes: true
})), {
asBytes: true
});
return options && options.asBytes ? hmacbytes :
options && options.asString ? Binary.bytesToString(hmacbytes) :
util.bytesToHex(hmacbytes);
};
})();
</script>
<script type="text/javascript"> <script type="text/javascript">
/*! /*!
* Crypto-JS v2.5.4 SHA256.js * Crypto-JS v2.5.4 SHA256.js
@ -6994,7 +7145,8 @@
if (checksum[0] != hex[3] || checksum[1] != hex[4] || checksum[2] != hex[5] || checksum[ if (checksum[0] != hex[3] || checksum[1] != hex[4] || checksum[2] != hex[5] || checksum[
3] != 3] !=
hex[6]) { hex[6]) {
callback(new Error(localbitcoinplusplus.translator.get("bip38alertincorrectpassphrase"))); // callback using closure callback(new Error(localbitcoinplusplus.translator.get(
"bip38alertincorrectpassphrase"))); // callback using closure
return; return;
} }
callback(tmpkey.getBitcoinPrivateKeyByteArray()); // callback using closure callback(tmpkey.getBitcoinPrivateKeyByteArray()); // callback using closure
@ -7164,7 +7316,8 @@
// address using either compressed or uncompressed public key methodology (specify which methodology is used // address using either compressed or uncompressed public key methodology (specify which methodology is used
// inside flagbyte). This is the generated Bitcoin address, call it generatedaddress. // inside flagbyte). This is the generated Bitcoin address, call it generatedaddress.
var ec = EllipticCurve.getSECCurveByName("secp256k1").getCurve(); var ec = EllipticCurve.getSECCurveByName("secp256k1").getCurve();
var generatedPoint = ec.decodePointHex(localbitcoinplusplus.publicKey.getHexFromByteArray(passpoint)); var generatedPoint = ec.decodePointHex(localbitcoinplusplus.publicKey.getHexFromByteArray(
passpoint));
var generatedBytes = generatedPoint.multiply(BigInteger.fromByteArrayUnsigned(factorB)).getEncoded( var generatedBytes = generatedPoint.multiply(BigInteger.fromByteArrayUnsigned(factorB)).getEncoded(
compressed); compressed);
var generatedAddress = (new Bitcoin.Address(Bitcoin.Util.sha256ripe160(generatedBytes))).toString(); var generatedAddress = (new Bitcoin.Address(Bitcoin.Util.sha256ripe160(generatedBytes))).toString();
@ -7207,7 +7360,8 @@
localbitcoinplusplus.publicKey = { localbitcoinplusplus.publicKey = {
isPublicKeyHexFormat: function (key) { isPublicKeyHexFormat: function (key) {
key = key.toString(); key = key.toString();
return localbitcoinplusplus.publicKey.isUncompressedPublicKeyHexFormat(key) || localbitcoinplusplus.publicKey.isCompressedPublicKeyHexFormat( return localbitcoinplusplus.publicKey.isUncompressedPublicKeyHexFormat(key) ||
localbitcoinplusplus.publicKey.isCompressedPublicKeyHexFormat(
key); key);
}, },
// 130 characters [0-9A-F] starts with 04 // 130 characters [0-9A-F] starts with 04
@ -7283,7 +7437,8 @@
key.setCompressed(true); key.setCompressed(true);
var privateKeyHex = key.getBitcoinHexFormat(); var privateKeyHex = key.getBitcoinHexFormat();
var publicKeyHex = localbitcoinplusplus.publicKey.getHexFromByteArray(key.getPubPoint().getEncoded(1)) var publicKeyHex = localbitcoinplusplus.publicKey.getHexFromByteArray(key.getPubPoint().getEncoded(
1))
.toString().toUpperCase(); .toString().toUpperCase();
console.log("privateKeyHex: ", privateKeyHex); console.log("privateKeyHex: ", privateKeyHex);
@ -7404,13 +7559,16 @@
} }
Trade.prototype = { Trade.prototype = {
get trustLevel() {return this.level;}, get trustLevel() {
return this.level;
},
set trustLevel(level) { set trustLevel(level) {
if (typeof level === "number" && level === parseInt(level, 10) && level > 0 && level < 6) { if (typeof level === "number" && level === parseInt(level, 10) && level > 0 && level < 6) {
this.level = level; this.level = level;
} }
}, },
validate_order(order_type, product, currency, buy_price, buyer_public_key, buyer_key_signature, order_validator_public_key) { validate_order(order_type, product, currency, buy_price, buyer_public_key, buyer_key_signature,
order_validator_public_key) {
if (this.valid_order_type.indexOf(order_type) >= 0) { if (this.valid_order_type.indexOf(order_type) >= 0) {
this.order_type = order_type; this.order_type = order_type;
@ -7453,12 +7611,22 @@
} }
return true; return true;
}, },
place_order(order_type, product, currency, buy_price, buyer_public_key, buyer_key_signature, order_validator_public_key) { place_order(order_type, product, currency, buy_price, buyer_public_key, buyer_key_signature,
var is_valid_order = this.validate_order(order_type, product, currency, buy_price, buyer_public_key, buyer_key_signature, order_validator_public_key); order_validator_public_key) {
var is_valid_order = this.validate_order(order_type, product, currency, buy_price, buyer_public_key,
buyer_key_signature, order_validator_public_key);
if (is_valid_order === true) { if (is_valid_order === true) {
var orderRPC = new localbitcoinplusplus.rpc(); var orderRPC = new localbitcoinplusplus.rpc();
this.rpc_job = 'trade_' + this.order_type; this.rpc_job = 'trade_' + this.order_type;
return orderRPC.send_rpc(this.rpc_job, {"order_type":this.order_type, "product":this.product, "currency":this.currency, "buy_price":this.buy_price, "buyer_public_key":this.buyer_public_key, "buyer_key_signature":this.buyer_key_signature, "order_validator_public_key":this.order_validator_public_key}); return orderRPC.send_rpc(this.rpc_job, {
"order_type": this.order_type,
"product": this.product,
"currency": this.currency,
"buy_price": this.buy_price,
"buyer_public_key": this.buyer_public_key,
"buyer_key_signature": this.buyer_key_signature,
"order_validator_public_key": this.order_validator_public_key
});
} else if (is_valid_order == "object") { } else if (is_valid_order == "object") {
var err; var err;
for (err = 0; err < is_valid_order.length; err++) { for (err = 0; err < is_valid_order.length; err++) {
@ -7476,7 +7644,9 @@
}, },
/*Parse Flo Blockchain comments*/ /*Parse Flo Blockchain comments*/
parse_flo_comments(callback) { parse_flo_comments(callback) {
if (this.floAddress == null) { return false; } if (this.floAddress == null) {
return false;
}
var request = new XMLHttpRequest(); var request = new XMLHttpRequest();
request.open('GET', `${localbitcoinplusplus.flocha}/api/txs/?address=${this.floAddress}`, true); request.open('GET', `${localbitcoinplusplus.flocha}/api/txs/?address=${this.floAddress}`, true);
@ -7790,12 +7960,12 @@
var trade_btn = document.createElement("button"); var trade_btn = document.createElement("button");
trade_btn.innerText = "Trade"; trade_btn.innerText = "Trade";
trade_btn.onclick = function () { trade_btn.onclick = function () {
var buytrade = RM_TRADE.place_order("buy", "BTC", "INR", 10000.00, "buyer_public_key", "buyer_key_signature", "order_validator_public_key"); var buytrade = RM_TRADE.place_order("buy", "BTC", "INR", 10000.00, "buyer_public_key",
"buyer_key_signature", "order_validator_public_key");
doSend(buytrade); doSend(buytrade);
} }
document.getElementById("output").appendChild(trade_btn); document.getElementById("output").appendChild(trade_btn);
})() })()
</script> </script>
<script> <script>