floDapps, floCloudAPI: retain blkchain id on login

floDapps login:
- login to btc address when btc private key is entered
- login to flo id when flo (or any other) private key is entered

floCloudAPI user:
- accept userID and private key for user set

Others:
- Fixed: minor bugs
This commit is contained in:
sairajzero 2022-07-28 02:24:26 +05:30
parent f673d3f37a
commit 4bced4352d
3 changed files with 54 additions and 45 deletions

View File

@ -1,4 +1,4 @@
(function(EXPORTS) { //floCloudAPI v2.4.2a
(function(EXPORTS) { //floCloudAPI v2.4.2b
/* FLO Cloud operations to send/request application data*/
'use strict';
const floCloudAPI = EXPORTS;
@ -12,26 +12,47 @@
};
var user_id, user_public, user_private, aes_key;
const user = {
get id() {
function user(id, priv) {
if (!priv || !id)
return user.clear();
let pub = floCrypto.getPubKeyHex(priv);
if (!pub || !floCrypto.verifyPubKey(pub, id))
return user.clear();
let n = floCrypto.randInt(12, 20);
aes_key = floCrypto.randString(n);
user_private = Crypto.AES.encrypt(priv, aes_key);
user_public = pub;
user_id = id;
return user_id;
}
Object.defineProperties(user, {
id: {
get: () => {
if (!user_id)
throw "User not set";
return user_id;
}
},
get public() {
public: {
get: () => {
if (!user_public)
throw "User not set";
return user_public;
}
},
sign(msg) {
sign: {
value: msg => {
if (!user_private)
throw "User not set";
return floCrypto.signData(msg, Crypto.AES.decrypt(user_private, aes_key));
}
},
clear() {
user_id = user_public = user_private = aes_key = undefined;
}
clear: {
value: () => user_id = user_public = user_private = aes_key = undefined
}
})
Object.defineProperties(floCloudAPI, {
SNStorageID: {
@ -44,21 +65,6 @@
get: () => DEFAULT.application
},
user: {
set: priv => {
if (!priv)
user_id = user_public = user_private = aes_key = undefined;
else {
user_public = floCrypto.getPubKeyHex(priv);
user_id = floCrypto.getFloID(user_public);
if (!user_public || !user_id || !floCrypto.verifyPrivKey(priv, user_id))
user_id = user_public = user_private = aes_key = undefined;
else {
let n = floCrypto.randInt(12, 20);
aes_key = floCrypto.randString(n);
user_private = Crypto.AES.encrypt(priv, aes_key);
}
}
},
get: () => user
}
});

View File

@ -1,4 +1,4 @@
(function(EXPORTS) { //floDapps v2.3.2
(function(EXPORTS) { //floDapps v2.3.2a
/* General functions for FLO Dapps*/
'use strict';
const floDapps = EXPORTS;
@ -75,6 +75,9 @@
myFloID: {
get: () => user.id
},
myUserID: {
get: () => user.id
},
myPubKey: {
get: () => user.public
},
@ -179,14 +182,14 @@
}).then(result => {
for (var i = result.data.length - 1; i >= 0; i--) {
var content = JSON.parse(result.data[i]).SuperNodeStorage;
for (sn in content.removeNodes)
for (let sn in content.removeNodes)
compactIDB.removeData("supernodes", sn, DEFAULT.root);
for (sn in content.newNodes)
for (let sn in content.newNodes)
compactIDB.writeData("supernodes", content.newNodes[sn], sn, DEFAULT.root);
}
compactIDB.writeData("lastTx", result.totalTxs, floCloudAPI.SNStorageID, DEFAULT.root);
compactIDB.readAllData("supernodes", DEFAULT.root).then(result => {
floCloudAPI.init(result)
compactIDB.readAllData("supernodes", DEFAULT.root).then(nodes => {
floCloudAPI.init(nodes)
.then(result => resolve("Loaded Supernode list\n" + result))
.catch(error => reject(error))
})
@ -342,8 +345,8 @@
checkIfPinRequired(key).then(privKey => {
try {
user_public = floCrypto.getPubKeyHex(privKey);
user_id = floCrypto.getFloID(privKey);
floCloudAPI.user = privKey; //Set user for floCloudAPI
user_id = floCrypto.getAddress(privKey);
floCloudAPI.user(user_id, privKey); //Set user for floCloudAPI
user_priv_wrap = () => checkIfPinRequired(key);
let n = floCrypto.randInt(12, 20);
aes_key = floCrypto.randString(n);

6
lib.js
View File

@ -1,4 +1,4 @@
(function(GLOBAL) { //lib v1.3.0a
(function(GLOBAL) { //lib v1.3.0b
'use strict';
/* Utility Libraries required for Standard operations
* All credits for these codes belong to their respective creators, moderators and owners.
@ -6353,7 +6353,7 @@
x += (document.getElementById("entropybucket")) ? document.getElementById("entropybucket").innerHTML : '';
x += x + '' + x;
var r = x;
for (i = 0; i < (x).length / 25; i++) {
for (let i = 0; i < (x).length / 25; i++) {
r = Crypto.SHA256(r.concat(x));
}
var checkrBigInt = new BigInteger(r);
@ -8565,7 +8565,7 @@
var r = "";
var l = length || 25;
var chars = "!$%^&*()_+{}:@~?><|\./;'#][=-abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
for (x = 0; x < l; x++) {
for (let x = 0; x < l; x++) {
r += chars.charAt(Math.floor(Math.random() * 62));
}
return r;