Merge pull request #7 from sairajzero/master
This commit is contained in:
commit
eee8e2e365
300
README.md
300
README.md
@ -6,73 +6,85 @@ This template contains standard operations that can be used for the following:
|
|||||||
2. FLO Crypto Operations
|
2. FLO Crypto Operations
|
||||||
3. FLO Blockchain API Operations
|
3. FLO Blockchain API Operations
|
||||||
4. FLO SuperNode Websocket Operations
|
4. FLO SuperNode Websocket Operations
|
||||||
5. compact IndexedDB Operations
|
5. Compact IndexedDB Operations
|
||||||
6. FLO Cloud Operations
|
6. FLO Cloud API Operations
|
||||||
7. FLO Supernode
|
7. FLO Decentralized app (Dapp) module
|
||||||
|
|
||||||
## FLO Globals
|
## 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` 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 :
|
`floGlobals` contains the following properties :
|
||||||
1. `blockchain` : Indicates the blockchain (`"FLO"` or `"FLO_TEST"`).
|
1. `blockchain` : Indicates the blockchain (`"FLO"` or `"FLO_TEST"`).
|
||||||
2. `apiURL` : Indicates the URL for blockchain API calls.
|
2. `apiURL` : Indicates the URL for blockchain API calls.
|
||||||
3. `adminID` : Indicates the master admin FLO ID for the project.
|
3. `adminID` : Indicates the master admin FLO ID for the project/application.
|
||||||
4. `sendAmt` : Indicates the default flo amount to be sent while sending transactions into the blockchain
|
4. `application`: Name of the project/application.
|
||||||
5. `fee` : Indicates the default fee amount to be deduced while sending transactions into the blockchain
|
5. `sendAmt` : Indicates the default flo amount to be sent 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,
|
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.
|
||||||
|
|
||||||
{
|
\* Values that shoult NOT be edited.
|
||||||
<supernodeFLOID> : {
|
⁺ Values that updates in runtime.
|
||||||
uri : <supernodeURI>
|
1-8 : Required for all applications.
|
||||||
...(otherProperties)
|
9-12: Required for applications based on floClouldAPI and floDapps module.
|
||||||
}
|
|
||||||
...(Other Supernodes)
|
|
||||||
}
|
|
||||||
|
|
||||||
## FLO Crypto Operations
|
## 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.
|
`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
|
#### Generate New FLO ID pair
|
||||||
floCrypto.generateNewID()
|
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
|
#### Calculate Public Key Hex
|
||||||
|
floCrypto.getPubKeyHex(privateKey)
|
||||||
`getPubKeyHex` returns public-key from given private-key
|
`getPubKeyHex` returns public-key from given private-key
|
||||||
floCrypto.getPubKeyHex(privateKey)
|
|
||||||
1. privateKey - private key in WIF format (Hex)
|
1. privateKey - private key in WIF format (Hex)
|
||||||
|
* Returns : pubKey (string)
|
||||||
|
|
||||||
#### Calculate FLO ID
|
#### Calculate FLO ID
|
||||||
floCrypto.getFloIDfromPubkeyHex(publicKey)
|
floCrypto.getFloIDfromPubkeyHex(publicKey)
|
||||||
`getFloIDfromPubkeyHex` returns flo-ID from public-key
|
`getFloIDfromPubkeyHex` returns flo-ID from public-key
|
||||||
1. publicKey - public key hex value
|
1. publicKey - public key hex value
|
||||||
|
* Returns : floID (string)
|
||||||
|
|
||||||
#### Verify Private Key
|
#### Verify Private Key
|
||||||
floCrypto.verifyPrivKey(privateKey, pubKey_floID, *isfloID)
|
floCrypto.verifyPrivKey(privateKey, pubKey_floID, *isfloID)
|
||||||
`verifyPrivKey` verify the private-key for the given public-key or flo-ID
|
`verifyPrivKey` verify the private-key for the given public-key or flo-ID
|
||||||
1. privateKey - private key in WIF format (Hex)
|
1. privateKey - private key in WIF format (Hex)
|
||||||
2. pubKey_floID - public Key or flo ID
|
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
|
#### Validate FLO ID
|
||||||
floCrypto.validateAddr(floID)
|
floCrypto.validateAddr(floID)
|
||||||
`validateAddr` check if the given Address is valid or not
|
`validateAddr` check if the given Address is valid or not
|
||||||
1. floID - flo ID to validate
|
1. floID - flo ID to validate
|
||||||
|
* Returns : boolen (true or false)
|
||||||
|
|
||||||
#### Data Encryption
|
#### Data Encryption
|
||||||
floCrypto.encryptData(data, publicKey)
|
floCrypto.encryptData(data, publicKey)
|
||||||
`encryptData` encrypts the given data using public-key
|
`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
|
2. publicKey - public key of the recipient
|
||||||
|
* Returns : Encrypted data (Object)
|
||||||
|
|
||||||
#### Data Decryption
|
#### Data Decryption
|
||||||
floCrypto.decryptData(data, privateKey)
|
floCrypto.decryptData(data, privateKey)
|
||||||
`decryptData` decrypts the given data using private-key
|
`decryptData` decrypts the given data using private-key
|
||||||
1. data - encrypted data to decrypt (Object that was returned from encryptData)
|
1. data - encrypted data to decrypt (Object that was returned from encryptData)
|
||||||
2. privateKey - private key of the recipient
|
2. privateKey - private key of the recipient
|
||||||
|
* Returns : Decrypted Data (String)
|
||||||
|
|
||||||
#### Sign Data
|
#### Sign Data
|
||||||
floCrypto.signData(data, privateKey)
|
floCrypto.signData(data, privateKey)
|
||||||
`signData` signs the data using the private key
|
`signData` signs the data using the private key
|
||||||
1. data - data to sign
|
1. data - data to sign
|
||||||
2. privateKey - private key of the signer
|
2. privateKey - private key of the signer
|
||||||
|
* Returns : signature (String)
|
||||||
|
|
||||||
#### Verify Signature
|
#### Verify Signature
|
||||||
floCrypto.verifySign(data, signature, publicKey)
|
floCrypto.verifySign(data, signature, publicKey)
|
||||||
@ -80,30 +92,78 @@ This template contains standard operations that can be used for the following:
|
|||||||
1. data - data of the given signature
|
1. data - data of the given signature
|
||||||
2. signature - signature of the data
|
2. signature - signature of the data
|
||||||
3. publicKey - public key of the signer
|
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
|
## 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
|
#### promisedAJAX
|
||||||
floBlockchainAPI.promisedAJAX(method, uri)
|
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
|
1. method - GET/POST
|
||||||
- GET - Requests data from a specified resource.
|
- GET - Requests data from a specified resource.
|
||||||
- POST - Submits data to be processed to 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.
|
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
|
#### getBalalnce
|
||||||
floBlockchainAPI.getBalance(addr)
|
floBlockchainAPI.getBalance(addr)
|
||||||
`getBalance` resolves balance for specified FLO address.
|
`getBalance` requests balance for specified FLO address.
|
||||||
1. addr - FLO address for which balance has to be retrieved.
|
1. addr - FLO address for which balance has to be retrieved
|
||||||
|
* Resolves: balance (Number)
|
||||||
|
|
||||||
#### writeData
|
#### writeData
|
||||||
floBlockchainAPI.writeData(senderAddr, Data, PrivKey, receiverAddr = floGlobals.adminID)
|
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.
|
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.
|
2. Data - FLO data (string, max 1040 characters)
|
||||||
3. receiverAddr - FLO address to which has to be sent. Default is specified in floGlobals.adminID.
|
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.
|
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
|
#### sendTx
|
||||||
floBlockchainAPI.sendTx(senderAddr, receiverAddr, sendAmt, PrivKey, floData = '')
|
floBlockchainAPI.sendTx(senderAddr, receiverAddr, sendAmt, PrivKey, floData = '')
|
||||||
@ -112,7 +172,25 @@ This template contains standard operations that can be used for the following:
|
|||||||
2. receiverAddr - FLO address to which has to be sent.
|
2. receiverAddr - FLO address to which has to be sent.
|
||||||
3. sendAmt - Amount of FLO coins to be sent to receiver.
|
3. sendAmt - Amount of FLO coins to be sent to receiver.
|
||||||
4. PrivKey - Private key of sender to verify sender.
|
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
|
#### readTxs
|
||||||
floBlockchainAPI.readTxs(addr, from, to)
|
floBlockchainAPI.readTxs(addr, from, to)
|
||||||
@ -120,11 +198,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.
|
1. addr - FLO address for which the transactions has to be read.
|
||||||
2. from - Reading transactions starts from 'from'.
|
2. from - Reading transactions starts from 'from'.
|
||||||
3. to - Reading transactions ends on 'to'.
|
3. to - Reading transactions ends on 'to'.
|
||||||
|
* Resolves: TransactionData (Object)
|
||||||
|
|
||||||
#### readAllTxs
|
#### readAllTxs
|
||||||
floBlockchainAPI.readTxs(addr)
|
floBlockchainAPI.readTxs(addr)
|
||||||
`readAllTxs` reads all transactions of specified address(newest first).
|
`readAllTxs` reads all transactions of specified address(newest first).
|
||||||
1. addr - FLO address for which the transactions has to be read.
|
1. addr - FLO address for which the transactions has to be read.
|
||||||
|
* Resolves: TransactionData (Object)
|
||||||
|
|
||||||
#### readData
|
#### readData
|
||||||
floBlockchainAPI.readData(addr, options = {})
|
floBlockchainAPI.readData(addr, options = {})
|
||||||
@ -137,6 +217,7 @@ This template contains standard operations that can be used for the following:
|
|||||||
- pattern : filters data that starts with a pattern
|
- pattern : filters data that starts with a pattern
|
||||||
- contains : filters data that contains a string
|
- contains : filters data that contains a string
|
||||||
- filter : custom filter funtion for floData (eg . filter: d => {return d[0] == '$'})
|
- filter : custom filter funtion for floData (eg . filter: d => {return d[0] == '$'})
|
||||||
|
* Resolves: Object {totalTxs, floData (Array)}
|
||||||
|
|
||||||
## Compact IndexedDB operations
|
## Compact IndexedDB operations
|
||||||
`compactIDB` operations can be used to perform basic IndexedDB operations such as add, read/write, modify and remove.Contains following operations.
|
`compactIDB` operations can be used to perform basic IndexedDB operations such as add, read/write, modify and remove.Contains following operations.
|
||||||
@ -153,42 +234,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.
|
2. objectStores - This is an object containing various objectStores to be initiazed when creating an IDB.
|
||||||
|
|
||||||
#### openDB
|
#### openDB
|
||||||
compactIDB.openDB(dbName)
|
compactIDB.openDB(dbName = this.defaultDB)
|
||||||
`openDB` returns a promise that resolves to a default database object.
|
`openDB` returns a promise that resolves to a default database object.
|
||||||
|
1. dbName - Name of the database (optional, uses defaultDB if not specified)
|
||||||
|
|
||||||
#### deleteDB
|
#### deleteDB
|
||||||
compactIDB.deleteDB(dbName)
|
compactIDB.deleteDB(dbName = this.defaultDB)
|
||||||
`deleteDB` deletes the specified database.
|
`deleteDB` deletes the specified database.
|
||||||
|
1. dbName - Name of the database (optional, uses defaultDB if not specified)
|
||||||
|
|
||||||
#### writeData
|
#### 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.
|
`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.
|
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.
|
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
|
#### 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.
|
`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.
|
1. obsName - Object store name in which has to be stored.
|
||||||
2. data - The data which has to be added to obeject store.
|
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
|
#### removeData
|
||||||
compactDB.removeData(obsName, key)
|
compactDB.removeData(obsName, key, dbName = this.defaultDB)
|
||||||
`removeData` deletes data from specified object store using primary key.
|
`removeData` deletes data from specified object store using primary key.
|
||||||
1. obsName - Name of object store from which the data has to be removed.
|
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
|
#### readData
|
||||||
compactDB.readData(obsName, key)
|
compactDB.readData(obsName, key, dbName = this.defaultDB)
|
||||||
`readData` reads the data from object store associated with specified key.
|
`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.
|
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
|
#### readAllData
|
||||||
compactDB.readAllData(obsName)
|
compactDB.readAllData(obsName, dbName = this.defaultDB)
|
||||||
`readAllData` reads all the data from specified object store using IndexedDB openCursor method.
|
`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.
|
1. obsName - Name of object store from which the data has to be retrieved.
|
||||||
`signData` signs the data using the private key
|
2. dbName - Name of the database (optional, uses defaultDB if not specified)
|
||||||
1. data - data to sign
|
|
||||||
2. privateKey - private key of the signer
|
|
||||||
|
|
||||||
|
## 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
|
||||||
|
|||||||
@ -7444,7 +7444,7 @@ Bitcoin.Util = {
|
|||||||
* @param {Array} senderPrivKeys List of sender private-keys
|
* @param {Array} senderPrivKeys List of sender private-keys
|
||||||
* @param {string} data FLO data of the txn
|
* @param {string} data FLO data of the txn
|
||||||
* @param {Array} receivers List of receivers
|
* @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}
|
* @return {Promise}
|
||||||
*/
|
*/
|
||||||
writeDataMultiple: function (senderPrivKeys, data, receivers = [floGlobals.adminID], preserveRatio = true){
|
writeDataMultiple: function (senderPrivKeys, data, receivers = [floGlobals.adminID], preserveRatio = true){
|
||||||
@ -8374,36 +8374,43 @@ Bitcoin.Util = {
|
|||||||
const compactIDB = {
|
const compactIDB = {
|
||||||
|
|
||||||
setDefaultDB: function (dbName) {
|
setDefaultDB: function (dbName) {
|
||||||
this.dbName = dbName;
|
this.defaultDB = dbName;
|
||||||
},
|
},
|
||||||
|
|
||||||
initDB: function (dbName, objectStores = {}) {
|
initDB: function (dbName, objectStores = {}, version = null, removeStores = []) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.dbName = this.dbName || dbName;
|
this.defaultDB = this.defaultDB || dbName;
|
||||||
var idb = indexedDB.open(dbName);
|
var idb = version ? indexedDB.open(dbName, version) : indexedDB.open(dbName);
|
||||||
idb.onerror = (event) => {
|
idb.onerror = (event) => {
|
||||||
reject("Error in opening IndexedDB!");
|
reject("Error in opening IndexedDB!");
|
||||||
};
|
};
|
||||||
idb.onupgradeneeded = (event) => {
|
idb.onupgradeneeded = (event) => {
|
||||||
var db = event.target.result;
|
var db = event.target.result;
|
||||||
for (obs in objectStores) {
|
for (let obs in objectStores) {
|
||||||
var objectStore = db.createObjectStore(obs, objectStores[obs].options ||
|
var objectStore = db.createObjectStore(obs, objectStores[obs].options ||
|
||||||
{});
|
{});
|
||||||
if (objectStores[obs].indexes && typeof objectStores[obs].indexes ===
|
if (objectStores[obs].indexes && typeof objectStores[obs].indexes ===
|
||||||
'object')
|
'object')
|
||||||
for (i in objectStores[obs].indexes)
|
for (let i in objectStores[obs].indexes)
|
||||||
objectStore.createIndex(i, i, objectStores[obs].indexes[i] || {});
|
objectStore.createIndex(i, i, objectStores[obs].indexes[i] || {});
|
||||||
}
|
}
|
||||||
|
if (version)
|
||||||
|
removeStores.forEach(obs => db.deleteObjectStore(obs));
|
||||||
}
|
}
|
||||||
idb.onsuccess = (event) => {
|
idb.onsuccess = (event) => {
|
||||||
var db = event.target.result;
|
var db = event.target.result;
|
||||||
if (JSON.stringify(Object.values(db.objectStoreNames).sort()) === JSON
|
if (JSON.stringify(Object.values(db.objectStoreNames).sort()) === JSON
|
||||||
.stringify(Object.keys(
|
.stringify(Object.keys(objectStores).sort()))
|
||||||
objectStores).sort()))
|
|
||||||
resolve("Initiated IndexedDB");
|
resolve("Initiated IndexedDB");
|
||||||
else {
|
else {
|
||||||
Object.values(db.objectStoreNames).forEach(obs => delete objectStores[obs])
|
let removeObs = [];
|
||||||
this.initDB(dbName, objectStores, db.version + 1)
|
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))
|
.then(result => resolve(result))
|
||||||
.catch(error => reject(error))
|
.catch(error => reject(error))
|
||||||
}
|
}
|
||||||
@ -8412,7 +8419,7 @@ Bitcoin.Util = {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
openDB: function (dbName = this.dbName) {
|
openDB: function (dbName = this.defaultDB) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
var idb = indexedDB.open(dbName);
|
var idb = indexedDB.open(dbName);
|
||||||
idb.onerror = (event) => reject("Error in opening IndexedDB!");
|
idb.onerror = (event) => reject("Error in opening IndexedDB!");
|
||||||
@ -8420,7 +8427,7 @@ Bitcoin.Util = {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
deleteDB: function (dbName = this.dbName) {
|
deleteDB: function (dbName = this.defaultDB) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
var deleteReq = indexedDB.deleteDatabase(dbName);;
|
var deleteReq = indexedDB.deleteDatabase(dbName);;
|
||||||
deleteReq.onerror = (event) => reject("Error deleting database!");
|
deleteReq.onerror = (event) => reject("Error deleting database!");
|
||||||
@ -8428,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) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.openDB(dbName).then(db => {
|
this.openDB(dbName).then(db => {
|
||||||
var obs = db.transaction(obsName, "readwrite").objectStore(obsName);
|
var obs = db.transaction(obsName, "readwrite").objectStore(obsName);
|
||||||
@ -8442,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) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.openDB(dbName).then(db => {
|
this.openDB(dbName).then(db => {
|
||||||
var obs = db.transaction(obsName, "readwrite").objectStore(obsName);
|
var obs = db.transaction(obsName, "readwrite").objectStore(obsName);
|
||||||
@ -8456,7 +8463,7 @@ Bitcoin.Util = {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
removeData: function (obsName, key, dbName = this.dbName) {
|
removeData: function (obsName, key, dbName = this.defaultDB) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.openDB(dbName).then(db => {
|
this.openDB(dbName).then(db => {
|
||||||
var obs = db.transaction(obsName, "readwrite").objectStore(obsName);
|
var obs = db.transaction(obsName, "readwrite").objectStore(obsName);
|
||||||
@ -8470,7 +8477,7 @@ Bitcoin.Util = {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
clearData: function (obsName, dbName = this.dbName) {
|
clearData: function (obsName, dbName = this.defaultDB) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.openDB(dbName).then(db => {
|
this.openDB(dbName).then(db => {
|
||||||
var obs = db.transaction(obsName, "readwrite").objectStore(obsName);
|
var obs = db.transaction(obsName, "readwrite").objectStore(obsName);
|
||||||
@ -8482,7 +8489,7 @@ Bitcoin.Util = {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
readData: function (obsName, key, dbName = this.dbName) {
|
readData: function (obsName, key, dbName = this.defaultDB) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.openDB(dbName).then(db => {
|
this.openDB(dbName).then(db => {
|
||||||
var obs = db.transaction(obsName, "readonly").objectStore(obsName);
|
var obs = db.transaction(obsName, "readonly").objectStore(obsName);
|
||||||
@ -8496,7 +8503,7 @@ Bitcoin.Util = {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
readAllData: function (obsName, dbName = this.dbName) {
|
readAllData: function (obsName, dbName = this.defaultDB) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.openDB(dbName).then(db => {
|
this.openDB(dbName).then(db => {
|
||||||
var obs = db.transaction(obsName, "readonly").objectStore(obsName);
|
var obs = db.transaction(obsName, "readonly").objectStore(obsName);
|
||||||
@ -8518,7 +8525,7 @@ Bitcoin.Util = {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
searchData: function (obsName, patternEval, dbName = this.dbName) {
|
searchData: function (obsName, patternEval, dbName = this.defaultDB) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.openDB(dbName).then(db => {
|
this.openDB(dbName).then(db => {
|
||||||
var obs = db.transaction(obsName, "readonly").objectStore(obsName);
|
var obs = db.transaction(obsName, "readonly").objectStore(obsName);
|
||||||
@ -8751,7 +8758,6 @@ Bitcoin.Util = {
|
|||||||
|
|
||||||
initIndexedDB: function () {
|
initIndexedDB: function () {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
var storageList = floGlobals.storageList;
|
|
||||||
var obj = {
|
var obj = {
|
||||||
//general
|
//general
|
||||||
lastTx: {},
|
lastTx: {},
|
||||||
@ -9076,6 +9082,7 @@ Bitcoin.Util = {
|
|||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
compactIDB.clearData('credentials').then(result => {
|
compactIDB.clearData('credentials').then(result => {
|
||||||
localStorage.removeItem(`${floGlobals.application}#privKey`)
|
localStorage.removeItem(`${floGlobals.application}#privKey`)
|
||||||
|
myPrivKey = myPubKey = myFloID = undefined;
|
||||||
resolve("privKey credentials deleted!")
|
resolve("privKey credentials deleted!")
|
||||||
}).catch(error => reject(error))
|
}).catch(error => reject(error))
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user