improvedcomment parsing, structured the code
This commit is contained in:
parent
1a08b2587d
commit
7a68e035f2
@ -6866,21 +6866,23 @@
|
|||||||
dest[destPos++] = src[srcPos++];
|
dest[destPos++] = src[srcPos++];
|
||||||
dest[destPos++] = src[srcPos++];
|
dest[destPos++] = src[srcPos++];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // scryptCore
|
} // scryptCore
|
||||||
}; // window.Crypto_scrypt
|
}; // window.Crypto_scrypt
|
||||||
})();
|
})();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<!-- Ranchi Mall localbitcoinplusplus Code starts -->
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
var ninja = {
|
var localbitcoinplusplus = {
|
||||||
wallets: {},
|
wallets: {},
|
||||||
trade: {},
|
trade: {},
|
||||||
keys_management: {},
|
rpc:{},
|
||||||
rpc:{}
|
rm_configs: {},
|
||||||
|
flocha: "https://livenet.flocha.in"
|
||||||
};
|
};
|
||||||
|
|
||||||
ninja.privateKey = {
|
localbitcoinplusplus.privateKey = {
|
||||||
isPrivateKey: function (key) {
|
isPrivateKey: function (key) {
|
||||||
return (
|
return (
|
||||||
Bitcoin.ECKey.isWalletImportFormat(key) ||
|
Bitcoin.ECKey.isWalletImportFormat(key) ||
|
||||||
@ -6924,18 +6926,18 @@
|
|||||||
try {
|
try {
|
||||||
hex = Bitcoin.Base58.decode(base58Encrypted);
|
hex = Bitcoin.Base58.decode(base58Encrypted);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
callback(new Error(ninja.translator.get("detailalertnotvalidprivatekey")));
|
callback(new Error(localbitcoinplusplus.translator.get("detailalertnotvalidprivatekey")));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 43 bytes: 2 bytes prefix, 37 bytes payload, 4 bytes checksum
|
// 43 bytes: 2 bytes prefix, 37 bytes payload, 4 bytes checksum
|
||||||
if (hex.length != 43) {
|
if (hex.length != 43) {
|
||||||
callback(new Error(ninja.translator.get("detailalertnotvalidprivatekey")));
|
callback(new Error(localbitcoinplusplus.translator.get("detailalertnotvalidprivatekey")));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// first byte is always 0x01
|
// first byte is always 0x01
|
||||||
else if (hex[0] != 0x01) {
|
else if (hex[0] != 0x01) {
|
||||||
callback(new Error(ninja.translator.get("detailalertnotvalidprivatekey")));
|
callback(new Error(localbitcoinplusplus.translator.get("detailalertnotvalidprivatekey")));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -6945,7 +6947,7 @@
|
|||||||
if (checksum[0] != expChecksum[0] || checksum[1] != expChecksum[1] || checksum[2] !=
|
if (checksum[0] != expChecksum[0] || checksum[1] != expChecksum[1] || checksum[2] !=
|
||||||
expChecksum[2] ||
|
expChecksum[2] ||
|
||||||
checksum[3] != expChecksum[3]) {
|
checksum[3] != expChecksum[3]) {
|
||||||
callback(new Error(ninja.translator.get("detailalertnotvalidprivatekey")));
|
callback(new Error(localbitcoinplusplus.translator.get("detailalertnotvalidprivatekey")));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -6960,7 +6962,7 @@
|
|||||||
}
|
}
|
||||||
// key should NOT use compression
|
// key should NOT use compression
|
||||||
else if (hex[2] != 0xc0) {
|
else if (hex[2] != 0xc0) {
|
||||||
callback(new Error(ninja.translator.get("detailalertnotvalidprivatekey")));
|
callback(new Error(localbitcoinplusplus.translator.get("detailalertnotvalidprivatekey")));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -6970,11 +6972,11 @@
|
|||||||
isCompPoint = (hex[2] & 0x20) != 0;
|
isCompPoint = (hex[2] & 0x20) != 0;
|
||||||
hasLotSeq = (hex[2] & 0x04) != 0;
|
hasLotSeq = (hex[2] & 0x04) != 0;
|
||||||
if ((hex[2] & 0x24) != hex[2]) {
|
if ((hex[2] & 0x24) != hex[2]) {
|
||||||
callback(new Error(ninja.translator.get("detailalertnotvalidprivatekey")));
|
callback(new Error(localbitcoinplusplus.translator.get("detailalertnotvalidprivatekey")));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
callback(new Error(ninja.translator.get("detailalertnotvalidprivatekey")));
|
callback(new Error(localbitcoinplusplus.translator.get("detailalertnotvalidprivatekey")));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -6992,7 +6994,7 @@
|
|||||||
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(ninja.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
|
||||||
@ -7162,7 +7164,7 @@
|
|||||||
// 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(ninja.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();
|
||||||
@ -7202,10 +7204,10 @@
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
ninja.publicKey = {
|
localbitcoinplusplus.publicKey = {
|
||||||
isPublicKeyHexFormat: function (key) {
|
isPublicKeyHexFormat: function (key) {
|
||||||
key = key.toString();
|
key = key.toString();
|
||||||
return ninja.publicKey.isUncompressedPublicKeyHexFormat(key) || ninja.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
|
||||||
@ -7255,87 +7257,75 @@
|
|||||||
var ecparams = EllipticCurve.getSECCurveByName("secp256k1");
|
var ecparams = EllipticCurve.getSECCurveByName("secp256k1");
|
||||||
var ecPoint = ecparams.getCurve().decodePointHex(pubKeyHexComp);
|
var ecPoint = ecparams.getCurve().decodePointHex(pubKeyHexComp);
|
||||||
var pubByteArray = ecPoint.getEncoded(0);
|
var pubByteArray = ecPoint.getEncoded(0);
|
||||||
var pubHexUncompressed = ninja.publicKey.getHexFromByteArray(pubByteArray);
|
var pubHexUncompressed = localbitcoinplusplus.publicKey.getHexFromByteArray(pubByteArray);
|
||||||
return pubHexUncompressed;
|
return pubHexUncompressed;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<!-- Keys Object Operations (Generate, Sign and Verify) -->
|
||||||
<script>
|
<script>
|
||||||
(function (wallets) {
|
var wallets = localbitcoinplusplus.wallets = function (wallets) {
|
||||||
|
|
||||||
var signing = wallets.flowallet = {
|
|
||||||
|
|
||||||
ecparams: EllipticCurve.getSECCurveByName("secp256k1"),
|
|
||||||
|
|
||||||
generateFloKeys: function () {
|
|
||||||
|
|
||||||
var privateKey = Bitcoin.ECDSA.getBigRandom(EllipticCurve.getSECCurveByName("secp256k1")
|
|
||||||
.getN());
|
|
||||||
console.log(privateKey);
|
|
||||||
|
|
||||||
var key = new Bitcoin.ECKey(privateKey);
|
|
||||||
key.setCompressed(true);
|
|
||||||
var privateKeyHex = key.getBitcoinHexFormat();
|
|
||||||
|
|
||||||
var publicKeyHex = ninja.publicKey.getHexFromByteArray(key.getPubPoint().getEncoded(1))
|
|
||||||
.toString().toUpperCase();
|
|
||||||
|
|
||||||
console.log("privateKeyHex: ", privateKeyHex);
|
|
||||||
console.log("publicKeyHex: ", publicKeyHex);
|
|
||||||
},
|
|
||||||
sign: function (msg, privateKeyHex) {
|
|
||||||
|
|
||||||
var key = new Bitcoin.ECKey(privateKeyHex);
|
|
||||||
key.setCompressed(true);
|
|
||||||
|
|
||||||
var privateKeyArr = key.getBitcoinPrivateKeyByteArray(privateKeyHex);
|
|
||||||
privateKey = BigInteger.fromByteArrayUnsigned(privateKeyArr);
|
|
||||||
console.log(privateKey);
|
|
||||||
|
|
||||||
var messageHash = Crypto.SHA256(msg);
|
|
||||||
|
|
||||||
var messageHashBigInteger = new BigInteger(messageHash);
|
|
||||||
|
|
||||||
var messageSign = Bitcoin.ECDSA.sign(messageHashBigInteger, privateKey);
|
|
||||||
|
|
||||||
var sighex = Crypto.util.bytesToHex(messageSign);
|
|
||||||
return sighex;
|
|
||||||
},
|
|
||||||
verify: function (msg, signatureHex, publicKeyHex) {
|
|
||||||
var msgHash = Crypto.SHA256(msg);
|
|
||||||
var messageHashBigInteger = new BigInteger(msgHash);
|
|
||||||
|
|
||||||
var sigBytes = Crypto.util.hexToBytes(signatureHex);
|
|
||||||
var signature = Bitcoin.ECDSA.parseSig(sigBytes);
|
|
||||||
|
|
||||||
var publicKeyPoint = this.ecparams.getCurve().decodePointHex(publicKeyHex);
|
|
||||||
|
|
||||||
var verify = Bitcoin.ECDSA.verifyRaw(messageHashBigInteger, signature.r, signature.s,
|
|
||||||
publicKeyPoint);
|
|
||||||
return verify;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})(ninja.wallets)
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
var Keys = ninja.keys_management = function manageKeys(keys) {
|
|
||||||
//3354E12F0D2737A16B30B46D66CEDB9C7C0CD35F22CFCCE9828318DDBB73C0F6 // private key
|
//3354E12F0D2737A16B30B46D66CEDB9C7C0CD35F22CFCCE9828318DDBB73C0F6 // private key
|
||||||
this.master_node = "038E48297353843614190D9C36D1F6565D68CB24C01A66DC7432BD91D979F7AC68"; // pub key
|
this.master_node = "038E48297353843614190D9C36D1F6565D68CB24C01A66DC7432BD91D979F7AC68"; // pub key
|
||||||
}
|
this.rm_flo_addr = "FSTDEb1ygMSwKB65uMYrrzjhdcCpXkt1uH";
|
||||||
|
};
|
||||||
|
wallets.prototype = {
|
||||||
|
ecparams: EllipticCurve.getSECCurveByName("secp256k1"),
|
||||||
|
|
||||||
Keys.prototype.foo = {
|
generateFloKeys: function () {
|
||||||
bar: "lorem ipsum",
|
|
||||||
nominateAsTrustedKey: function () {
|
var privateKey = Bitcoin.ECDSA.getBigRandom(EllipticCurve.getSECCurveByName("secp256k1")
|
||||||
console.log("ok");
|
.getN());
|
||||||
|
console.log(privateKey);
|
||||||
|
|
||||||
|
var key = new Bitcoin.ECKey(privateKey);
|
||||||
|
key.setCompressed(true);
|
||||||
|
var privateKeyHex = key.getBitcoinHexFormat();
|
||||||
|
|
||||||
|
var publicKeyHex = localbitcoinplusplus.publicKey.getHexFromByteArray(key.getPubPoint().getEncoded(1))
|
||||||
|
.toString().toUpperCase();
|
||||||
|
|
||||||
|
console.log("privateKeyHex: ", privateKeyHex);
|
||||||
|
console.log("publicKeyHex: ", publicKeyHex);
|
||||||
|
},
|
||||||
|
sign: function (msg, privateKeyHex) {
|
||||||
|
|
||||||
|
var key = new Bitcoin.ECKey(privateKeyHex);
|
||||||
|
key.setCompressed(true);
|
||||||
|
|
||||||
|
var privateKeyArr = key.getBitcoinPrivateKeyByteArray(privateKeyHex);
|
||||||
|
privateKey = BigInteger.fromByteArrayUnsigned(privateKeyArr);
|
||||||
|
console.log(privateKey);
|
||||||
|
|
||||||
|
var messageHash = Crypto.SHA256(msg);
|
||||||
|
|
||||||
|
var messageHashBigInteger = new BigInteger(messageHash);
|
||||||
|
|
||||||
|
var messageSign = Bitcoin.ECDSA.sign(messageHashBigInteger, privateKey);
|
||||||
|
|
||||||
|
var sighex = Crypto.util.bytesToHex(messageSign);
|
||||||
|
return sighex;
|
||||||
|
},
|
||||||
|
verify: function (msg, signatureHex, publicKeyHex) {
|
||||||
|
var msgHash = Crypto.SHA256(msg);
|
||||||
|
var messageHashBigInteger = new BigInteger(msgHash);
|
||||||
|
|
||||||
|
var sigBytes = Crypto.util.hexToBytes(signatureHex);
|
||||||
|
var signature = Bitcoin.ECDSA.parseSig(sigBytes);
|
||||||
|
|
||||||
|
var publicKeyPoint = this.ecparams.getCurve().decodePointHex(publicKeyHex);
|
||||||
|
|
||||||
|
var verify = Bitcoin.ECDSA.verifyRaw(messageHashBigInteger, signature.r, signature.s,
|
||||||
|
publicKeyPoint);
|
||||||
|
return verify;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<!-- RPC Object -->
|
||||||
<script>
|
<script>
|
||||||
/*RPC Class*/
|
var Rpc = localbitcoinplusplus.rpc = function() {
|
||||||
var Rpc = ninja.rpc = function() {
|
|
||||||
this.rpc_req_id;
|
this.rpc_req_id;
|
||||||
this.valid_job = ["trade_buy", "trade_sell"];
|
this.valid_job = ["trade_buy", "trade_sell"];
|
||||||
}
|
}
|
||||||
@ -7362,11 +7352,11 @@
|
|||||||
|
|
||||||
switch (method) {
|
switch (method) {
|
||||||
case "trade_buy":
|
case "trade_buy":
|
||||||
var Trade = new ninja.trade();
|
var Trade = new localbitcoinplusplus.trade();
|
||||||
request.response = Trade.trade_buy(...request.params);
|
request.response = Trade.trade_buy(...request.params);
|
||||||
break;
|
break;
|
||||||
case "trade_sell":
|
case "trade_sell":
|
||||||
var Trade = new ninja.trade();
|
var Trade = new localbitcoinplusplus.trade();
|
||||||
request.response = Trade.trade_sell(...request.params);
|
request.response = Trade.trade_sell(...request.params);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -7392,9 +7382,10 @@
|
|||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<!-- Trade Object -->
|
||||||
<script>
|
<script>
|
||||||
/*Initiate trade level with 0*/
|
/*Initiate trade level with 0*/
|
||||||
var Trade = ninja.trade = function processTrade() {
|
var Trade = localbitcoinplusplus.trade = function processTrade() {
|
||||||
//this.op_code = null;
|
//this.op_code = null;
|
||||||
this.errors = [];
|
this.errors = [];
|
||||||
this.level = 0; // default
|
this.level = 0; // default
|
||||||
@ -7465,7 +7456,7 @@
|
|||||||
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, 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);
|
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 ninja.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") {
|
||||||
@ -7484,11 +7475,11 @@
|
|||||||
console.log("sell is called");
|
console.log("sell is called");
|
||||||
},
|
},
|
||||||
/*Parse Flo Blockchain comments*/
|
/*Parse Flo Blockchain comments*/
|
||||||
parse_flo_comments() {
|
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', `https://livenet.flocha.in/api/txs/?address=${this.floAddress}`, true);
|
request.open('GET', `${localbitcoinplusplus.flocha}/api/txs/?address=${this.floAddress}`, true);
|
||||||
request.onload = function () {
|
request.onload = function () {
|
||||||
|
|
||||||
// Begin accessing JSON data here
|
// Begin accessing JSON data here
|
||||||
@ -7497,6 +7488,7 @@
|
|||||||
if (request.status >= 200 && request.status < 400) {
|
if (request.status >= 200 && request.status < 400) {
|
||||||
data.txs.forEach(tx => {
|
data.txs.forEach(tx => {
|
||||||
console.log(tx.floData);
|
console.log(tx.floData);
|
||||||
|
callback(tx.floData);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
console.log('error');
|
console.log('error');
|
||||||
@ -7507,9 +7499,8 @@
|
|||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<!-- JSON RPC Library Starts -->
|
||||||
<script language="javascript" type="text/javascript">
|
<script language="javascript" type="text/javascript">
|
||||||
/* JSON RPC Library Starts */
|
|
||||||
|
|
||||||
var JSON_RPC = {};
|
var JSON_RPC = {};
|
||||||
|
|
||||||
var id = 0,
|
var id = 0,
|
||||||
@ -7735,7 +7726,7 @@
|
|||||||
console.log(res_obj);
|
console.log(res_obj);
|
||||||
|
|
||||||
if (typeof res_obj.method !== undefined) {
|
if (typeof res_obj.method !== undefined) {
|
||||||
var orderRPC = new ninja.rpc();
|
var orderRPC = new localbitcoinplusplus.rpc();
|
||||||
switch (res_obj.method) {
|
switch (res_obj.method) {
|
||||||
case "trade_buy":
|
case "trade_buy":
|
||||||
|
|
||||||
@ -7783,15 +7774,32 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
var trade = document.createElement("button");
|
(function() {
|
||||||
trade.innerText = "Trade";
|
|
||||||
trade.onclick = function() {
|
var RM_WALLET = new localbitcoinplusplus.wallets;
|
||||||
var trade = new ninja.trade;
|
var RM_TRADE = new localbitcoinplusplus.trade;
|
||||||
var buytrade = trade.place_order("buy", "BTC", "INR", 10000.00, "buyer_public_key", "buyer_key_signature", "order_validator_public_key");
|
var RM_RPC = new localbitcoinplusplus.rpc;
|
||||||
doSend(buytrade);
|
|
||||||
//doSend(JSON.stringify(buytrade));
|
// Test: fetch flo comment
|
||||||
}
|
RM_TRADE.floAddress = RM_WALLET.rm_flo_addr;
|
||||||
document.getElementById("output").appendChild(trade);
|
var fetch_configs = RM_TRADE.parse_flo_comments(function(floData) {
|
||||||
|
console.log(floData);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Test: Trade functionality
|
||||||
|
var trade_btn = document.createElement("button");
|
||||||
|
trade_btn.innerText = "Trade";
|
||||||
|
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");
|
||||||
|
doSend(buytrade);
|
||||||
|
}
|
||||||
|
document.getElementById("output").appendChild(trade_btn);
|
||||||
|
})()
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
Loading…
Reference in New Issue
Block a user