From fa3d790c6c3bacccc0c4fb088e76b5ae2867619a Mon Sep 17 00:00:00 2001 From: sairajzero Date: Sun, 24 Jul 2022 02:29:04 +0530 Subject: [PATCH] floDapps v2.3.2: lock privkey by default - Removed the options for launchStartUp - private-key is on lock mode by default - Added utility functions that uses private-key without entering password in .user .sign(message): signs message .decrypt(data): decrypts ciphertext in asymmetric .encipher(message): encrypts message in symmetric .decipher(data): decrypts ciphertext in symmetric --- floDapps.js | 25 +++++++++++++++++-------- index.html | 2 +- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/floDapps.js b/floDapps.js index e25ecf0..e5e2d6d 100644 --- a/floDapps.js +++ b/floDapps.js @@ -1,4 +1,4 @@ -(function(EXPORTS) { //floDapps v2.3.1a +(function(EXPORTS) { //floDapps v2.3.2 /* General functions for FLO Dapps*/ 'use strict'; const floDapps = EXPORTS; @@ -40,6 +40,18 @@ else return Crypto.AES.decrypt(user_private, aes_key); }, + sign(message) { + return floCrypto.signData(message, raw_user.private); + }, + decrypt(data) { + return floCrypto.decryptData(data, raw_user.private); + }, + encipher(message) { + return Crypto.AES.encrypt(message, raw_user.private); + }, + decipher(data) { + return Crypto.AES.decrypt(data, raw_user.private); + }, get db_name() { return "floDapps#" + user.id; }, @@ -240,7 +252,7 @@ resolve(inputVal) }); - function getCredentials(lock_key) { + function getCredentials() { const readSharesFromIDB = indexArr => new Promise((resolve, reject) => { var promises = [] @@ -336,10 +348,7 @@ let n = floCrypto.randInt(12, 20); aes_key = floCrypto.randString(n); user_priv_raw = Crypto.AES.encrypt(privKey, aes_key); - if (!lock_key) - user_private = user_priv_raw; - else - user_private = user_priv_wrap; + user_private = user_priv_wrap; resolve('Login Credentials loaded successful') } catch (error) { console.log(error) @@ -384,7 +393,7 @@ }) }); - floDapps.launchStartUp = function(options = {}) { + floDapps.launchStartUp = function() { return new Promise((resolve, reject) => { initIndexedDB().then(log => { console.log(log) @@ -399,7 +408,7 @@ }) }); let p2 = new Promise((res, rej) => { - callAndLog(getCredentials(options.lock_key)).then(r => { + callAndLog(getCredentials()).then(r => { callAndLog(initUserDB()).then(r => { callAndLog(loadUserDB()) .then(r => res(true)) diff --git a/index.html b/index.html index cef876c..2b60d9d 100644 --- a/index.html +++ b/index.html @@ -24,7 +24,7 @@ //floDapps.addStartUpFunction('Sample', Promised Function) //floDapps.setAppObjectStores({sampleObs1:{}, sampleObs2:{options{autoIncrement:true, keyPath:'SampleKey'}, Indexes:{sampleIndex:{}}}}) //floDapps.setCustomPrivKeyInput( () => { FUNCTION BODY *must resolve private key* } ) - floDapps.launchStartUp( /*{lock_key: true}*/ ).then(result => { + floDapps.launchStartUp().then(result => { console.log(result) alert(`Welcome FLO_ID: ${myFloID}`) //App functions....