From 489996c1b8c47d5f69959c046f2fd1c6062aa243 Mon Sep 17 00:00:00 2001 From: sairajzero Date: Wed, 6 May 2020 19:56:31 +0530 Subject: [PATCH 1/5] Improve clearCredentials Clearing the private key, public key and floID from memory on clearCredentials --- standard_Operations.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/standard_Operations.html b/standard_Operations.html index 3754c60..572aded 100644 --- a/standard_Operations.html +++ b/standard_Operations.html @@ -8751,7 +8751,6 @@ Bitcoin.Util = { initIndexedDB: function () { return new Promise((resolve, reject) => { - var storageList = floGlobals.storageList; var obj = { //general lastTx: {}, @@ -9076,6 +9075,7 @@ Bitcoin.Util = { return new Promise((resolve, reject) => { compactIDB.clearData('credentials').then(result => { localStorage.removeItem(`${floGlobals.application}#privKey`) + myPrivKey = myPubKey = myFloID = undefined; resolve("privKey credentials deleted!") }).catch(error => reject(error)) }) From 32da4e28af04d8c5f2a84402fc71d988d513aa1a Mon Sep 17 00:00:00 2001 From: sairajzero Date: Thu, 7 May 2020 15:46:58 +0530 Subject: [PATCH 2/5] Improved initDB initDB also deletes objectstores on upgrade needed (version change) --- standard_Operations.html | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/standard_Operations.html b/standard_Operations.html index 572aded..8462f27 100644 --- a/standard_Operations.html +++ b/standard_Operations.html @@ -8377,33 +8377,40 @@ Bitcoin.Util = { this.dbName = dbName; }, - initDB: function (dbName, objectStores = {}) { + initDB: function (dbName, objectStores = {}, version = null, removeStores = []) { return new Promise((resolve, reject) => { this.dbName = this.dbName || dbName; - var idb = indexedDB.open(dbName); + var idb = version ? indexedDB.open(dbName, version) : indexedDB.open(dbName); idb.onerror = (event) => { reject("Error in opening IndexedDB!"); }; idb.onupgradeneeded = (event) => { var db = event.target.result; - for (obs in objectStores) { + for (let obs in objectStores) { var objectStore = db.createObjectStore(obs, objectStores[obs].options || {}); if (objectStores[obs].indexes && typeof objectStores[obs].indexes === 'object') - for (i in objectStores[obs].indexes) + for (let i in objectStores[obs].indexes) objectStore.createIndex(i, i, objectStores[obs].indexes[i] || {}); } + if (version) + removeStores.forEach(obs => db.deleteObjectStore(obs)); } idb.onsuccess = (event) => { var db = event.target.result; if (JSON.stringify(Object.values(db.objectStoreNames).sort()) === JSON - .stringify(Object.keys( - objectStores).sort())) + .stringify(Object.keys(objectStores).sort())) resolve("Initiated IndexedDB"); else { - Object.values(db.objectStoreNames).forEach(obs => delete objectStores[obs]) - this.initDB(dbName, objectStores, db.version + 1) + let removeObs = []; + Object.values(db.objectStoreNames).forEach(obs => { + if (obs in objectStores) + delete objectStores[obs] + else + removeObs.push(obs) + }) + this.initDB(dbName, objectStores, db.version + 1, removeObs) .then(result => resolve(result)) .catch(error => reject(error)) } From a66c2d91c25488fc3492d955f4ffeb28dbadca0f Mon Sep 17 00:00:00 2001 From: sairajzero Date: Thu, 14 May 2020 03:52:39 +0530 Subject: [PATCH 3/5] minor changes -Renamed defaultDB propertyName in compactIDB -Fixed error in writeDataMultiple comment --- standard_Operations.html | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/standard_Operations.html b/standard_Operations.html index 8462f27..46a72cf 100644 --- a/standard_Operations.html +++ b/standard_Operations.html @@ -7444,7 +7444,7 @@ Bitcoin.Util = { * @param {Array} senderPrivKeys List of sender private-keys * @param {string} data FLO data of the txn * @param {Array} receivers List of receivers - * @param {float} sendAmt (optional) amount to be sent to receivers (default value: floGlobals.sendAmt) + * @param {boolean} preserveRatio (optional) preserve ratio or equal contribution * @return {Promise} */ writeDataMultiple: function (senderPrivKeys, data, receivers = [floGlobals.adminID], preserveRatio = true){ @@ -8374,12 +8374,12 @@ Bitcoin.Util = { const compactIDB = { setDefaultDB: function (dbName) { - this.dbName = dbName; + this.defaultDB = dbName; }, initDB: function (dbName, objectStores = {}, version = null, removeStores = []) { return new Promise((resolve, reject) => { - this.dbName = this.dbName || dbName; + this.defaultDB = this.defaultDB || dbName; var idb = version ? indexedDB.open(dbName, version) : indexedDB.open(dbName); idb.onerror = (event) => { reject("Error in opening IndexedDB!"); @@ -8419,7 +8419,7 @@ Bitcoin.Util = { }); }, - openDB: function (dbName = this.dbName) { + openDB: function (dbName = this.defaultDB) { return new Promise((resolve, reject) => { var idb = indexedDB.open(dbName); idb.onerror = (event) => reject("Error in opening IndexedDB!"); @@ -8427,7 +8427,7 @@ Bitcoin.Util = { }); }, - deleteDB: function (dbName = this.dbName) { + deleteDB: function (dbName = this.defaultDB) { return new Promise((resolve, reject) => { var deleteReq = indexedDB.deleteDatabase(dbName);; deleteReq.onerror = (event) => reject("Error deleting database!"); @@ -8435,7 +8435,7 @@ Bitcoin.Util = { }); }, - writeData: function (obsName, data, key = false, dbName = this.dbName) { + writeData: function (obsName, data, key = false, dbName = this.defaultDB) { return new Promise((resolve, reject) => { this.openDB(dbName).then(db => { var obs = db.transaction(obsName, "readwrite").objectStore(obsName); @@ -8449,7 +8449,7 @@ Bitcoin.Util = { }); }, - addData: function (obsName, data, key = false, dbName = this.dbName) { + addData: function (obsName, data, key = false, dbName = this.defaultDB) { return new Promise((resolve, reject) => { this.openDB(dbName).then(db => { var obs = db.transaction(obsName, "readwrite").objectStore(obsName); @@ -8463,7 +8463,7 @@ Bitcoin.Util = { }); }, - removeData: function (obsName, key, dbName = this.dbName) { + removeData: function (obsName, key, dbName = this.defaultDB) { return new Promise((resolve, reject) => { this.openDB(dbName).then(db => { var obs = db.transaction(obsName, "readwrite").objectStore(obsName); @@ -8477,7 +8477,7 @@ Bitcoin.Util = { }); }, - clearData: function (obsName, dbName = this.dbName) { + clearData: function (obsName, dbName = this.defaultDB) { return new Promise((resolve, reject) => { this.openDB(dbName).then(db => { var obs = db.transaction(obsName, "readwrite").objectStore(obsName); @@ -8489,7 +8489,7 @@ Bitcoin.Util = { }); }, - readData: function (obsName, key, dbName = this.dbName) { + readData: function (obsName, key, dbName = this.defaultDB) { return new Promise((resolve, reject) => { this.openDB(dbName).then(db => { var obs = db.transaction(obsName, "readonly").objectStore(obsName); @@ -8503,7 +8503,7 @@ Bitcoin.Util = { }); }, - readAllData: function (obsName, dbName = this.dbName) { + readAllData: function (obsName, dbName = this.defaultDB) { return new Promise((resolve, reject) => { this.openDB(dbName).then(db => { var obs = db.transaction(obsName, "readonly").objectStore(obsName); @@ -8525,7 +8525,7 @@ Bitcoin.Util = { }); }, - searchData: function (obsName, patternEval, dbName = this.dbName) { + searchData: function (obsName, patternEval, dbName = this.defaultDB) { return new Promise((resolve, reject) => { this.openDB(dbName).then(db => { var obs = db.transaction(obsName, "readonly").objectStore(obsName); From fccf2fdebdb4a8a9a1e3a1054f33af350116c383 Mon Sep 17 00:00:00 2001 From: sairajzero Date: Thu, 14 May 2020 03:52:45 +0530 Subject: [PATCH 4/5] Update README.md --- README.md | 296 +++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 259 insertions(+), 37 deletions(-) diff --git a/README.md b/README.md index 04a52f2..482a26d 100644 --- a/README.md +++ b/README.md @@ -6,71 +6,83 @@ This template contains standard operations that can be used for the following: 2. FLO Crypto Operations 3. FLO Blockchain API Operations 4. FLO SuperNode Websocket Operations -5. compact IndexedDB Operations +5. Compact IndexedDB Operations ## FLO Globals `floGlobals` object contains the global variables and constants required for the operations. Make sure to add this object before any other scripts. `floGlobals` contains the following properties : 1. `blockchain` : Indicates the blockchain (`"FLO"` or `"FLO_TEST"`). 2. `apiURL` : Indicates the URL for blockchain API calls. -3. `adminID` : Indicates the master admin FLO ID for the project. -4. `sendAmt` : Indicates the default flo amount to be sent while sending transactions into the blockchain -5. `fee` : Indicates the default fee amount to be deduced while sending transactions into the blockchain -6. `supernodes` : Holder for the supernode list. Can be updated in runtime while retriving data from blockchain using API. Stored in the Object format, +3. `adminID` : Indicates the master admin FLO ID for the project/application. +4. `application`: Name of the project/application. +5. `sendAmt` : Indicates the default flo amount to be sent while sending transactions into the blockchain. +6. `fee` : Indicates the default fee amount to be deduced while sending transactions into the blockchain. +7. `SNStorageID`* : SuperNode Storage adminID. +8. `supernodes`⁺ : List of supernodes. +9. `subAdmins`⁺ : subAdmins of the application. +10. `appData`⁺ : Application data for the app (data sent by subAdmins). +11. `generalData`⁺: General Data for the app (data sent by any user). +12. `vectorClock`⁺ and `generalVC`⁺ : vectorclocks for application data and general data respectively. - { - : { - uri : - ...(otherProperties) - } - ...(Other Supernodes) - } +\* Values that shoult NOT be edited. +⁺ Values that updates in runtime. +1-8 : Required for all applications. +9-12: Required for applications based on floClouldAPI and floDapps module. ## FLO Crypto Operations `floCrypto` operations can be used to perform blockchain-cryptography methods. `floCrypto` operations are synchronized and return a value. Contains the following Operations. + #### Generate New FLO ID pair floCrypto.generateNewID() - `generateNewID` generates a new flo ID and returns private-key, public-key and floID + `generateNewID` generates a new flo ID and returns private-key, public-key and floID + * Returns : Object { privKey , pubKey, floID } #### Calculate Public Key Hex + floCrypto.getPubKeyHex(privateKey) `getPubKeyHex` returns public-key from given private-key - floCrypto.getPubKeyHex(privateKey) 1. privateKey - private key in WIF format (Hex) + * Returns : pubKey (string) #### Calculate FLO ID floCrypto.getFloIDfromPubkeyHex(publicKey) `getFloIDfromPubkeyHex` returns flo-ID from public-key 1. publicKey - public key hex value +* Returns : floID (string) #### Verify Private Key floCrypto.verifyPrivKey(privateKey, pubKey_floID, *isfloID) `verifyPrivKey` verify the private-key for the given public-key or flo-ID 1. privateKey - private key in WIF format (Hex) 2. pubKey_floID - public Key or flo ID -3. isfloID - boolean value (true - compare as flo ID, false - compare as public key) (optional, default is true) +3. isfloID - boolean value (true: compare as flo ID, false: compare as public key) (optional, default is true) +* Returns : boolen (true or false) #### Validate FLO ID floCrypto.validateAddr(floID) `validateAddr` check if the given Address is valid or not 1. floID - flo ID to validate +* Returns : boolen (true or false) #### Data Encryption floCrypto.encryptData(data, publicKey) `encryptData` encrypts the given data using public-key -1. data - data to encrypt +1. data - data to encrypt (String) 2. publicKey - public key of the recipient +* Returns : Encrypted data (Object) #### Data Decryption floCrypto.decryptData(data, privateKey) `decryptData` decrypts the given data using private-key 1. data - encrypted data to decrypt (Object that was returned from encryptData) 2. privateKey - private key of the recipient +* Returns : Decrypted Data (String) #### Sign Data floCrypto.signData(data, privateKey) `signData` signs the data using the private key 1. data - data to sign 2. privateKey - private key of the signer +* Returns : signature (String) #### Verify Signature floCrypto.verifySign(data, signature, publicKey) @@ -78,30 +90,78 @@ This template contains standard operations that can be used for the following: 1. data - data of the given signature 2. signature - signature of the data 3. publicKey - public key of the signer +* Returns : boolen (true or false) + +#### Generate Random Interger + floCrypto.randInt(min, max) +`randInt` returns a randomly generated interger in a given range. +1. min - minimum value of the range +2. max - maximum value of the range +* Returns : randomNum (Interger) + +#### Generate Random String + floCrypto.randString(length, alphaNumeric) +`randString` returns a randomly generated string of given length. +1. length - length of the string to be generated +2. alphaNumeric - boolean (true: generated string will only contain alphabets and digits, false: generated string will also have symbols) (optional, default value is false) +* Returns : randomString (String) + +#### Create Shamir's Secret shares + floCrypto.createShamirsSecretShares(str, total_shares, threshold_limit) +`createShamirsSecretShares` splits the str into shares using shamir's secret. +1. str - string to be split +2. total_shares - total number of shares to be split into +3. threshold_limit - minimum number of shares required to reconstruct the secret str +* Returns : Shares (Array of string) + +#### Retrieve Shamir's Secret + floCrypto.retrieveShamirSecret(sharesArray) +`retrieveShamirSecret` reconstructs the secret from the shares. +1. sharesArray - Array of shares +* Returns : retrivedData (String) + +#### Verify Shamir's Secret + floCrypto.verifyShamirsSecret(sharesArray, str) +`verifyShamirsSecret` verfies the validity of the created shares. +1. sharesArray - Array of shares +2. str - originalData (string). +* Returns : boolen (true or false) ## FLO Blockchain API Operations -`floBlockchainAPI` object method can be used to send/recieve data to/from blockchain.These functions are asynchronous and return a promise. Contains the following functions. +`floBlockchainAPI` object method can be used to send/recieve data to/from blockchain. These functions are asynchronous and return a promise. Contains the following functions. #### promisedAJAX floBlockchainAPI.promisedAJAX(method, uri) -`promisedAJAX` resolves a responce from server on success or rejects the responce on failure. +`promisedAJAX` requests data using API 1. method - GET/POST - GET - Requests data from a specified resource. - POST - Submits data to be processed to a specified resource. 2. uri(Uniform Resource Identifier) - identifier for AJAX resource. It is used to create URL(Uniform Resource Locator) for further operations. +* Resolves: responseData from the API #### getBalalnce floBlockchainAPI.getBalance(addr) -`getBalance` resolves balance for specified FLO address. -1. addr - FLO address for which balance has to be retrieved. +`getBalance` requests balance for specified FLO address. +1. addr - FLO address for which balance has to be retrieved +* Resolves: balance (Number) #### writeData floBlockchainAPI.writeData(senderAddr, Data, PrivKey, receiverAddr = floGlobals.adminID) -`writeData` writes data into blockchain. +`writeData` writes data into blockchain, resolves transaction id if the transacation was succsessful. 1. senderAddr - FLO address from which the data and amount has to be sent. -2. Data - Actual FLO data that will be sent as string of 1040 characters. -3. receiverAddr - FLO address to which has to be sent. Default is specified in floGlobals.adminID. -4. PrivKey - Private key of sender to verify sender. +2. Data - FLO data (string, max 1040 characters) +3. receiverAddr - FLO address to which has to be sent. (Default is specified in floGlobals.adminID) +4. PrivKey - Private key of sender +* Resolves: TransactionID (String) + +#### writeDataMultiple + floBlockchainAPI.writeDataMultiple(senderPrivKeys, data, receivers = [floGlobals.adminID], preserveRatio = true) +`writeDataMultiple` writes data into blockchain from multiple floIDs to multiple floIDs, resolves transaction id if the transacation was succsessful. +1. senderPrivKeys - Array of Private keys of the senders. +2. Data - FLO data (string, max 1040 characters) +3. receivers - Array of receiver FLO Addresses. (Default is specified in floGlobals.adminID) +4. preserveRatio - boolean (true: preserves the ratio of the balance of senders, false: all senders contribute equal amount to the transaction) (optional, default is true) +* Resolves: TransactionID (String) #### sendTx floBlockchainAPI.sendTx(senderAddr, receiverAddr, sendAmt, PrivKey, floData = '') @@ -110,7 +170,25 @@ This template contains standard operations that can be used for the following: 2. receiverAddr - FLO address to which has to be sent. 3. sendAmt - Amount of FLO coins to be sent to receiver. 4. PrivKey - Private key of sender to verify sender. -5. floData - Actual FLO data that will be sent as string of 1040 characters. +5. floData - FLO data (string, max 1040 characters) (optional, default value is empty string) +* Resolves: TransactionID (String) + +#### sendTxMultiple + floBlockchainAPI.sendTxMultiple(senderPrivKeys, receivers, floData = '') +`sendTxMultiple` sends a transaction to blockchain from multiple floIDs to multiple floIDs, resolves transaction id if the transacation was succsessful. +1. senderPrivKeys - Array of Private keys of the senders (or) Object of private keys with sendAmount for each floID (eg: { privateKey1: sendAmt1, privateKey2: sendAmt2...}) . +Note: If passed as Array, then ratio of the balance of the senders are preserved. If passed as Object uses the amount given. +3. receivers - Object of receiver floIDs with receive amount (eg: {receiverID1: receiveAmt1, receiver2: receiveAmt2...}) +4. floData - FLO data (string, max 1040 characters) (optional, default value is empty string) +* Resolves: TransactionID (String) + +#### mergeUTXOs + floBlockchainAPI.mergeUTXOs(floID, privKey, floData = '') +`mergeUTXOs` sends a transaction to blockchain that merges all utxos of the given floID. +1. floID - FLO address of which the utxos should be merged. +2. privKey - private key of the floID. +3. floData - FLO data (string, max 1040 characters) (optional, default value is empty string) +* Resolves: TransactionID (String) #### readTxs floBlockchainAPI.readTxs(addr, from, to) @@ -118,11 +196,13 @@ This template contains standard operations that can be used for the following: 1. addr - FLO address for which the transactions has to be read. 2. from - Reading transactions starts from 'from'. 3. to - Reading transactions ends on 'to'. +* Resolves: TransactionData (Object) #### readAllTxs floBlockchainAPI.readTxs(addr) `readAllTxs` reads all transactions of specified address(newest first). 1. addr - FLO address for which the transactions has to be read. +* Resolves: TransactionData (Object) #### readData floBlockchainAPI.readData(addr, options = {}) @@ -135,6 +215,7 @@ This template contains standard operations that can be used for the following: - pattern : filters data that starts with a pattern - contains : filters data that contains a string - filter : custom filter funtion for floData (eg . filter: d => {return d[0] == '$'}) +* Resolves: Object {totalTxs, floData (Array)} ## Compact IndexedDB operations `compactIDB` operations can be used to perform basic IndexedDB operations such as add, read/write, modify and remove.Contains following operations. @@ -151,42 +232,183 @@ This template contains standard operations that can be used for the following: 2. objectStores - This is an object containing various objectStores to be initiazed when creating an IDB. #### openDB - compactIDB.openDB(dbName) + compactIDB.openDB(dbName = this.defaultDB) `openDB` returns a promise that resolves to a default database object. +1. dbName - Name of the database (optional, uses defaultDB if not specified) #### deleteDB - compactIDB.deleteDB(dbName) + compactIDB.deleteDB(dbName = this.defaultDB) `deleteDB` deletes the specified database. +1. dbName - Name of the database (optional, uses defaultDB if not specified) #### writeData - compactIDB.writeData(obsName, data) + compactIDB.writeData(obsName, data, key = false, dbName = this.defaultDB) `writeData` writes specified data into the database if data doesn't exists or replaces it when data is already present. 1. obsName - object store name in which the data is to be written. 2. data - data that has to be written in specified object store. +3. key - Primary key of the data (optional, false indicates key is autoincremented or passed in data) +4. dbName - Name of the database (optional, uses defaultDB if not specified) #### addData - compactIDB.addData(obsName, data) + compactIDB.addData(obsName, data, key = false, dbName = this.defaultDB) `addData` writes new data into object store. If data already exists, it will return an error. 1. obsName - Object store name in which has to be stored. 2. data - The data which has to be added to obeject store. +3. key - Primary key of the data (optional, false indicates key is autoincremented or passed in data) +4. dbName - Name of the database (optional, uses defaultDB if not specified) #### removeData - compactDB.removeData(obsName, key) + compactDB.removeData(obsName, key, dbName = this.defaultDB) `removeData` deletes data from specified object store using primary key. 1. obsName - Name of object store from which the data has to be removed. -2. key - Primary key of the specified object store. +2. key - Primary key of the data. +3. dbName - Name of the database (optional, uses defaultDB if not specified) + +#### clearData + compactDB.clearData(obsName, dbName = this.defaultDB) +`clearData` clears all data in the objectStore. +1. obsName - Name of object store from which the data has to be removed. +2. dbName - Name of the database (optional, uses defaultDB if not specified) #### readData - compactDB.readData(obsName, key) + compactDB.readData(obsName, key, dbName = this.defaultDB) `readData` reads the data from object store associated with specified key. 1. obsName - Name of object store from which the data has to be retrieved. -2. key - 2.key - Primary key of the specified object store. +2. key - Primary key of the data to read. +3. dbName - Name of the database (optional, uses defaultDB if not specified) #### readAllData - compactDB.readAllData(obsName) + compactDB.readAllData(obsName, dbName = this.defaultDB) `readAllData` reads all the data from specified object store using IndexedDB openCursor method. 1. obsName - Name of object store from which the data has to be retrieved. -`signData` signs the data using the private key -1. data - data to sign -2. privateKey - private key of the signer +2. dbName - Name of the database (optional, uses defaultDB if not specified) +## FLO Supernode module +This module contains functions that interact with the supernode to send and retrive data in the backend. Use floClouldAPI operations to send and receive data for application. + +## FLO Cloud API operations +`floCloudAPI` operations can interact with floSupernode cloud to send and retrive data for applications. floCloudAPI uses floSupernode module for backend interactions. + +#### sendApplicationData + floCloudAPI.sendApplicationData(message, type, options = {}) +`sendApplicationData` sends application data to the cloud. +1. message - data to be sent +2. type - type of the data +3. options - (optional, options detailed at end of module) + +#### requestApplicationData + floCloudAPI.requestApplicationData(options = {}) +`requestApplicationData` requests application data from the cloud. +1. options - (optional, options detailed at end of module) + +#### sendGeneralData + floCloudAPI.sendGeneralData(message, type, options = {}) +`sendGeneralData` sends general data to the cloud. +1. message - data to be sent +2. type - type of the data +3. options - (optional, options detailed at end of module) + +#### requestGeneralData + floCloudAPI.requestGeneralData(type, options = {}) +`requestGeneralData` requests application data from the cloud. +1. type - type of the data +2. options - (optional, options detailed at end of module) + +#### resetObjectData + floCloudAPI.resetObjectData(objectName, options = {}) +`resetObjectData` resets the objectData to cloud. +1. objectName - Name of the objectData to be reset +2. options - (optional, options detailed at end of module) +Note: value of objectData is taken from floGlobals + +#### updateObjectData + floCloudAPI.updateObjectData(objectName, options = {}) +`updateObjectData` updates the objectData to cloud. +1. objectName - Name of the objectData to be updated +2. options - (optional, options detailed at end of module) +Note: value of objectData is taken from floGlobals + +#### requestObjectData + floCloudAPI.requestObjectData(objectName, options = {}) +`requestObjectData` requests application data from the cloud. +1. objectName - Name of the objectData to be requested +2. options - (optional, options detailed at end of module) + +#### options: +* send options: + * receiverID - received of the data + * application - application of the data + * comment - comment of the data + +* request options + * receiverID - received of the data + * senderIDs - array of senderIDs + * application - application of the data + * type - type of the data + * comment - comment of the data + * lowerVectorClock - VC from which the data is to be requested + * upperVectorClock - VC till which the data is to be requested + * atVectorClock - VC at which the data is to requested + * mostRecent - boolean (true: request only the recent data matching the pattern) + +## FLO Decentralised Applications (Dapps) +`floDapps` module contains methods for basic Dapp. floDapps uses all of the above modules. + +#### addStartUpFunction + floDapps.addStartUpFunction(fname, fn) +`addStartUpFunction` adds a startup funtion to the Dapp +1. fname - Name of the startup function +2. fn - body of the function +Note: startup funtions are called in parallel. Therefore only add custom startup funtion only if it can run in parallel with other startup functions. (default startup funtions are read supernode list and subAdmin list from blockchain API, load data from indexedDB, get login credentials) + +#### setCustomPrivKeyInput + floDapps.setCustomPrivKeyInput(customFn) +`setCustomPrivKeyInput` adds a startup funtion to the Dapp +1. customFn - custom function to get login credentials (privateKey) + +#### setAppObjectStores + floDapps.setAppObjectStores(appObs) +`setAppObjectStores` adds additionals objectstores for the app +1. appObs - additionals objects for the app + +#### manageSubAdmins + floDapps.manageSubAdmins(adminPrivKey, addList, rmList) +`manageSubAdmins` adds and/or removes subAdmins by sending transaction to blockchain. +1. adminPrivKey - private key of the adminID +2. addList - Array of subAdmins to add +3. rmList - Array of subAdmins to remove + +#### clearCredentials + floDapps.clearCredentials() +`clearCredentials` removes the login credentials stored in IDB. + +#### securePrivKey + floDapps.securePrivKey(pwd) +`securePrivKey` replaces the stored private key with an encrypted variant +1. pwd - password for the encryption +Note: if securePrivKey is used, then password must be requested during customPrivKeyInput (in setCustomPrivKeyInput). + +#### objectDataMapper + floDapps.objectDataMapper(object, path, data) +`objectDataMapper` maps the object and data via path +1. object - object to be mapped +2. path - end path for the data holder +3. data - data to be pushed in map + +#### getNextGeneralData + floDapps.getNextGeneralData(type, vectorClock, options = {}) +`getNextGeneralData` return the next generaldata +1. type - type of the general data +2. vectorClock - current known VC, from which next data to be retrived +3. options - (optional, {comment, application} of the data) + +#### launchStartUp + floDapps.launchStartUp() +`launchStartUp` launchs the Dapp startup functions + +##### reactorEvents +* startUpSuccessLog - called when a startup funtion is successfully completed +* startUpErrorLog - called when a startup funtion encounters an error + +##### onLoadStartUp +Sample startup is defined in onLoadStartUp function From 7d65c4da8eb1d563d9b9bb629dc1a71887d0a089 Mon Sep 17 00:00:00 2001 From: Sai Raj <39055732+sairajzero@users.noreply.github.com> Date: Thu, 14 May 2020 03:57:23 +0530 Subject: [PATCH 5/5] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 482a26d..8b942a3 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,8 @@ This template contains standard operations that can be used for the following: 3. FLO Blockchain API Operations 4. FLO SuperNode Websocket Operations 5. Compact IndexedDB Operations +6. FLO Cloud API +7. FLO Decentralized app (Dapp) ## FLO Globals `floGlobals` object contains the global variables and constants required for the operations. Make sure to add this object before any other scripts.