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*/ /* FLO Cloud operations to send/request application data*/
'use strict'; 'use strict';
const floCloudAPI = EXPORTS; const floCloudAPI = EXPORTS;
@ -12,27 +12,48 @@
}; };
var user_id, user_public, user_private, aes_key; var user_id, user_public, user_private, aes_key;
const user = {
get id() { function user(id, priv) {
if (!user_id) if (!priv || !id)
throw "User not set"; return user.clear();
return user_id; let pub = floCrypto.getPubKeyHex(priv);
}, if (!pub || !floCrypto.verifyPubKey(pub, id))
get public() { return user.clear();
if (!user_public) let n = floCrypto.randInt(12, 20);
throw "User not set"; aes_key = floCrypto.randString(n);
return user_public; user_private = Crypto.AES.encrypt(priv, aes_key);
}, user_public = pub;
sign(msg) { user_id = id;
if (!user_private) return user_id;
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;
}
} }
Object.defineProperties(user, {
id: {
get: () => {
if (!user_id)
throw "User not set";
return user_id;
}
},
public: {
get: () => {
if (!user_public)
throw "User not set";
return user_public;
}
},
sign: {
value: msg => {
if (!user_private)
throw "User not set";
return floCrypto.signData(msg, Crypto.AES.decrypt(user_private, aes_key));
}
},
clear: {
value: () => user_id = user_public = user_private = aes_key = undefined
}
})
Object.defineProperties(floCloudAPI, { Object.defineProperties(floCloudAPI, {
SNStorageID: { SNStorageID: {
get: () => DEFAULT.SNStorageID get: () => DEFAULT.SNStorageID
@ -44,21 +65,6 @@
get: () => DEFAULT.application get: () => DEFAULT.application
}, },
user: { 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 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*/ /* General functions for FLO Dapps*/
'use strict'; 'use strict';
const floDapps = EXPORTS; const floDapps = EXPORTS;
@ -75,6 +75,9 @@
myFloID: { myFloID: {
get: () => user.id get: () => user.id
}, },
myUserID: {
get: () => user.id
},
myPubKey: { myPubKey: {
get: () => user.public get: () => user.public
}, },
@ -179,14 +182,14 @@
}).then(result => { }).then(result => {
for (var i = result.data.length - 1; i >= 0; i--) { for (var i = result.data.length - 1; i >= 0; i--) {
var content = JSON.parse(result.data[i]).SuperNodeStorage; 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); 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("supernodes", content.newNodes[sn], sn, DEFAULT.root);
} }
compactIDB.writeData("lastTx", result.totalTxs, floCloudAPI.SNStorageID, DEFAULT.root); compactIDB.writeData("lastTx", result.totalTxs, floCloudAPI.SNStorageID, DEFAULT.root);
compactIDB.readAllData("supernodes", DEFAULT.root).then(result => { compactIDB.readAllData("supernodes", DEFAULT.root).then(nodes => {
floCloudAPI.init(result) floCloudAPI.init(nodes)
.then(result => resolve("Loaded Supernode list\n" + result)) .then(result => resolve("Loaded Supernode list\n" + result))
.catch(error => reject(error)) .catch(error => reject(error))
}) })
@ -342,8 +345,8 @@
checkIfPinRequired(key).then(privKey => { checkIfPinRequired(key).then(privKey => {
try { try {
user_public = floCrypto.getPubKeyHex(privKey); user_public = floCrypto.getPubKeyHex(privKey);
user_id = floCrypto.getFloID(privKey); user_id = floCrypto.getAddress(privKey);
floCloudAPI.user = privKey; //Set user for floCloudAPI floCloudAPI.user(user_id, privKey); //Set user for floCloudAPI
user_priv_wrap = () => checkIfPinRequired(key); user_priv_wrap = () => checkIfPinRequired(key);
let n = floCrypto.randInt(12, 20); let n = floCrypto.randInt(12, 20);
aes_key = floCrypto.randString(n); 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'; 'use strict';
/* Utility Libraries required for Standard operations /* Utility Libraries required for Standard operations
* All credits for these codes belong to their respective creators, moderators and owners. * 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 += (document.getElementById("entropybucket")) ? document.getElementById("entropybucket").innerHTML : '';
x += x + '' + x; x += x + '' + x;
var r = 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)); r = Crypto.SHA256(r.concat(x));
} }
var checkrBigInt = new BigInteger(r); var checkrBigInt = new BigInteger(r);
@ -8565,7 +8565,7 @@
var r = ""; var r = "";
var l = length || 25; var l = length || 25;
var chars = "!$%^&*()_+{}:@~?><|\./;'#][=-abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"; var chars = "!$%^&*()_+{}:@~?><|\./;'#][=-abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
for (x = 0; x < l; x++) { for (let x = 0; x < l; x++) {
r += chars.charAt(Math.floor(Math.random() * 62)); r += chars.charAt(Math.floor(Math.random() * 62));
} }
return r; return r;