This commit is contained in:
sairaj mote 2022-08-18 13:41:09 +05:30
parent 6c8ca451ae
commit 3c19efd073
4 changed files with 66 additions and 14 deletions

View File

@ -1,4 +1,4 @@
(function(EXPORTS) { //floCloudAPI v2.4.2b
(function(EXPORTS) { //floCloudAPI v2.4.2c
/* FLO Cloud operations to send/request application data*/
'use strict';
const floCloudAPI = EXPORTS;
@ -384,7 +384,7 @@
if (!address)
return;
var bytes;
if (address.length == 34) { //legacy encoding
if (address.length == 33 || address.length == 34) { //legacy encoding
let decode = bitjs.Base58.decode(address);
bytes = decode.slice(0, decode.length - 4);
let checksum = decode.slice(decode.length - 4),

View File

@ -1,4 +1,4 @@
(function(EXPORTS) { //floCrypto v2.3.3a
(function(EXPORTS) { //floCrypto v2.3.3b
/* FLO Crypto Operators */
'use strict';
const floCrypto = EXPORTS;
@ -148,8 +148,23 @@
}
}
Object.defineProperty(floCrypto, 'newID', {
get: () => generateNewID()
Object.defineProperties(floCrypto, {
newID: {
get: () => generateNewID()
},
tmpID: {
get: () => {
let bytes = Crypto.util.randomBytes(20);
bytes.unshift(bitjs.pub);
var hash = Crypto.SHA256(Crypto.SHA256(bytes, {
asBytes: true
}), {
asBytes: true
});
var checksum = hash.slice(0, 4);
return bitjs.Base58.encode(bytes.concat(checksum));
}
}
});
//Returns public-key from private-key
@ -230,7 +245,7 @@
//Check if the given address (any blockchain) is valid or not
floCrypto.validateAddr = function(address, std = true, bech = true) {
if (address.length == 34) { //legacy or segwit encoding
if (address.length == 33 || address.length == 34) { //legacy or segwit encoding
if (std === false)
return false;
let decode = bitjs.Base58.decode(address);
@ -262,11 +277,12 @@
return false;
}
//Check the public-key for the address (any blockchain)
floCrypto.verifyPubKey = function(pubKeyHex, address) {
let pub_hash = Crypto.util.bytesToHex(ripemd160(Crypto.SHA256(Crypto.util.hexToBytes(pubKeyHex), {
asBytes: true
})));
if (address.length == 34) { //legacy encoding
if (address.length == 33 || address.length == 34) { //legacy encoding
let decode = bitjs.Base58.decode(address);
var raw = decode.slice(0, decode.length - 4),
checksum = decode.slice(decode.length - 4);
@ -291,6 +307,41 @@
return false;
}
//Convert the given address (any blockchain) to equivalent floID
floCrypto.toFloID = function(address) {
if (!address)
return;
var bytes;
if (address.length == 33 || address.length == 34) { //legacy encoding
let decode = bitjs.Base58.decode(address);
bytes = decode.slice(0, decode.length - 4);
let checksum = decode.slice(decode.length - 4),
hash = Crypto.SHA256(Crypto.SHA256(bytes, {
asBytes: true
}), {
asBytes: true
});
hash[0] != checksum[0] || hash[1] != checksum[1] || hash[2] != checksum[2] || hash[3] != checksum[3] ?
bytes = undefined : bytes.shift();
} else if (address.length == 42) { //bech encoding
let decode = coinjs.bech32_decode(address);
if (decode) {
bytes = decode.data;
bytes.shift();
bytes = coinjs.bech32_convert(bytes, 5, 8, false);
}
}
if (!bytes)
return;
bytes.unshift(bitjs.pub);
let hash = Crypto.SHA256(Crypto.SHA256(bytes, {
asBytes: true
}), {
asBytes: true
});
return bitjs.Base58.encode(bytes.concat(hash.slice(0, 4)));
}
//Split the str using shamir's Secret and Returns the shares
floCrypto.createShamirsSecretShares = function(str, total_shares, threshold_limit) {
try {

View File

@ -494,10 +494,11 @@ function declineTopUp() {
async function completeTokenToCashRequest(request) {
const { vectorClock, senderID, message: { token_txid, amount, upi_id } } = request;
var upiID;
let upiID;
if (upi_id instanceof Object && "secret" in upi_id) {
try {
const privateKey = await floGlobals.user.private
const privateKey = await floDapps.user.private
console.log(upiID)
upiID = floCrypto.decryptData(upi_id, privateKey);
} catch (error) {
console.error("UPI ID is not encrypted with a proper key", error);
@ -1419,7 +1420,7 @@ getRef('fees_selector').addEventListener('change', e => {
getRef('send_transaction').onclick = evt => {
buttonLoader('send_transaction', true)
floGlobals.user.private.then(privateKey => {
floDapps.user.private.then(privateKey => {
const privKeys = btc_api.convert.wif(privateKey);
const senders = btc_api.convert.legacy2bech(floDapps.user.id);
const receivers = [...getRef('receiver_container').querySelectorAll('.receiver-input')].map(input => input.value.trim());

View File

@ -1,4 +1,4 @@
(function(GLOBAL) { //lib v1.3.0b
(function(GLOBAL) { //lib v1.3.0c
'use strict';
/* Utility Libraries required for Standard operations
* All credits for these codes belong to their respective creators, moderators and owners.
@ -7814,7 +7814,7 @@
} else if (this.ins[index].script.chunks[0] == 0 && this.ins[index].script.chunks[this.ins[index].script.chunks.length - 1][this.ins[index].script.chunks[this.ins[index].script.chunks.length - 1].length - 1] == 174) { // OP_CHECKMULTISIG
// multisig script, with signature(s) included
var sigcount = 0;
for (i = 1; i < this.ins[index].script.chunks.length - 1; i++) {
for (let i = 1; i < this.ins[index].script.chunks.length - 1; i++) {
if (this.ins[index].script.chunks[i] != 0) {
sigcount++;
}
@ -8057,8 +8057,8 @@
s.writeOp(0);
for (x in pubkeyList) {
for (y in sigsList) {
for (let x in pubkeyList) {
for (let y in sigsList) {
this.ins[index].script.buffer = redeemScript;
sighash = Crypto.util.hexToBytes(this.transactionHash(index, sigsList[y].slice(-1)[0] * 1));
if (coinjs.verifySignature(sighash, sigsList[y], pubkeyList[x])) {