-
Notifications
You must be signed in to change notification settings - Fork 9
floCrypto
floCrypto
operations can be used to perform blockchain-cryptography methods. floCrypto
operations are synchronized and return a value. Contains the following Operations.
floCrypto operations are all functions. They have not been promisified
Note: for nodejs use require and assign floCrypto to global
global.floCrypto = require('/path/to/floCrypto');
floCrypto.generateNewID()
Generates and returns private-key, public-key and floID
- Returns : Object { privKey , pubKey, floID }
floCrypto.newID
Generates and returns private-key, public-key and floID
- Returns : Object { privKey , pubKey, floID }
NOTE: same as floCrypto.generateNewID()
example:
var { privKey , pubKey, floID } = floCrypto.newID;
floCrypto.hashID(str)
Calculates the hash of the given string and returns the floID for it.
NOTE: ID will not have a private-key or public-key
- str - string to be hashed (String)
- Returns : hashFloID (String)
floCrypto.tmpID
Generates a random floID without private-key or public-key
- Returns : dummyFloID (String)
floCrypto.getPubKeyHex(privateKey)
Calculates the public-key for the given private-key
- privateKey - private key in WIF format (Hex)
- Returns : pubicKey (string)
floCrypto.getFloID(publickey_or_privateKey)
Calculates flo-ID from given public-key (or) private-key
- publickey_or_privateKey - public key or private key
- Returns : floID (string)
floCrypto.verifyPrivKey(privateKey, pubKey_floID, isfloID)
Verify the private-key for the given public-key or flo-ID
- privateKey - private key in WIF format (Hex)
- pubKey_floID - public Key or flo ID
- isfloID (optional) - boolean
- true: (DEFAULT) given
pubKey_floID
parameter is floID - false: given
pubKey_floID
parameter is public key
- true: (DEFAULT) given
- Returns : boolean (true or false)
floCrypto.validateFloID(floID)
Check if the given floID is valid or not
- floID - flo ID to validate
- regularOnly (optional) - boolean
- true: only validates regular flo-id
- false: (DEFAULT) also validates multisig flo-id
- Returns : boolean (true or false)
floCrypto.verifyPubKey(publicKey, address)
Verify the public key (or redeem-script) for the given address (any blockchain)
- publicKey - public key (or redeem-script of multisig address)
- address - address to verify
- Returns : boolean (true or false)
floCrypto.getMultisigAddress(publicKeyList, requiredSignatures)
Creates a multisig floID from the given public-key list
- publicKeyList: Array of public-keys (shared owners)
- requiredSignatures: minimum signatures required (
1 <= requiredSignatures <= publicKeyList.length
)
- Returns : Object {address, redeemScript, size}
NOTE: Changing order of public-keys in the array and/or value of requiredSignatures
will form a different multisig-floID
floCrypto.decodeRedeemScript(redeemScript)
Decodes the given redeemScript
- redeemScript: redeem-script of the multisig id
- Returns : Object {address, pubkeys, required }
NOTE: floCrypto.decodeRedeemScript
inverse function of floCrypto.getMultisigAddress
.
floCrypto.getAddress(privateKey, strict)
Returns respective address from given private-key
NOTE: supported blockchains FLO
, BTC
.
- privateKey - private key in WIF format
- strict (optional) - boolean
- false: (DEFAULT) return flo-id if private key doesnot belong to supported blockchains
- true: returns
false
if no prefix match is found
- Returns : address (string)
floCrypto.validateAddr(address, *std, *bech)
Check if the given Address (any blockchain) is valid or not
- address - address to validate
- std - checks for legacy version (optional, default=true) (true: allow any, array: list of versions, value: one version only, false: allow none)
- bech - checks for bech version (optional, default=true) (true: allow any, array: list of versions, value: one version only, false: allow none)
- Returns : boolean (true or false)
floCrypto.toFloID(address, options)
Converts any blockchain address to floID
- address - address (Any blockchain)
- options (optional) - if passed, converts address only from given blockchain version (prefix)
- accepts Object with following properties
- std: version (or array of version) of standard address encoding
- bech: version (or array of version) of bech32 address encoding
- accepts Object with following properties
- Returns : floID (string)
NOTE: if options
parameter is not passed, converts any address into respective flo-id
floCrypto.rawToFloID(raw_bytes)
Calculates the floID from given raw bytes
- raw_bytes - raw bytes to convert into floID (hex or byte array)
- Returns : floID (string)
floCrypto.toMultisigFloID(address, options)
Converts any blockchain multisig address to multisig floID
- address - address (Any blockchain)
- options (optional) - if passed, converts address only from given blockchain version (prefix)
- accepts Object with following properties
- std: version (or array of version) of standard address encoding
- bech: version (or array of version) of bech32 address encoding
- accepts Object with following properties
- Returns : multisigFloID (string)
floCrypto.isSameAddr(addr1, addr2)
Checks if both given address are equivalent w.r.t keys
- addr1 - address to compare
- addr1 - address to compare
- Returns : boolean (true or false)
floCrypto.decodeAddr(address)
- address - address to decode
- Returns : decoded values (Object)
floCrypto.encryptData(data, publicKey)
Encrypts the given data using public-key
- data - data to encrypt (String)
- publicKey - public key of the recipient
- Returns : Encrypted data (Object)
floCrypto.decryptData(data, privateKey)
Decrypts the given data using private-key
- data - encrypted data to decrypt (Object that was returned from encryptData)
- privateKey - private key of the recipient
- Returns : Decrypted data (String)
floCrypto.signData(data, privateKey)
Signs the data using the private key
- data - data to sign
- privateKey - private key of the signer
- Returns : signature (String)
floCrypto.verifySign(data, signature, publicKey)
Verifies signatue of the data using public-key
- data - data of the given signature
- signature - signature of the data
- publicKey - public key of the signer
- Returns : boolean (true or false)
floCrypto.createShamirsSecretShares(str, total_shares, threshold_limit)
Splits the data into shares using shamir's secret.
- str - string to be split
- total_shares - total number of shares to be split into
- threshold_limit - minimum number of shares required to reconstruct the secret str
- Returns : Shares (Array of string)
floCrypto.retrieveShamirSecret(sharesArray)
Reconstructs the secret from the shares.
- sharesArray - Array of shares
- Returns : retrivedData (String)
floCrypto.verifyShamirsSecret(sharesArray, str)
Verfies the validity of the created shares.
- sharesArray - Array of shares
- str - originalData (string).
- Returns : boolean (true or false)
floCrypto.randInt(min, max)
Returns a randomly generated interger in a given range.
- min - minimum value of the range
- max - maximum value of the range
- Returns : randomNum (Interger)
floCrypto.randString(length, alphaNumeric)
Returns a randomly generated string of given length.
- length - length of the string to be generated
- alphaNumeric (optional) - boolean
- true: (DEFAULT) generated string will only contain alphabets and digits
- false: generated string will also have symbols
- Returns : randomString (String)
floCrypto.validateASCII(string, bool)
Validates the string if it contains only ASCII characters
- string - string to validate
- bool (optional) - boolean
- true: (DEFAULT) returns
false
when check fails - false: returns array of invalid characters when check fails
- true: (DEFAULT) returns
- Returns : result (
true
if check passes)
floCrypto.convertToASCII(string, mode)
Converts the given string into valid ASCII characters
- string - string to convert into valid ASCII string
- mode (optional) - mode of conversion
-
'soft-remove'
: (DEFAULT) converts non-ASCII characters into ASCII characters if possible or remove it -
'hard-remove'
: removes all non-ASCII characters -
'soft-unicode'
: converts non-ASCII characters into ASCII characters if possible or convert them into Unicode values -
'hard-unicode'
: converts all non-ASCII characters into Unicode values
-
- Returns : valid_ASCII_string (String)
floCrypto.revertUnicode(string)
Converts the unicode values in string into respective characters
- string - string to revert (string obtained from
floCrypto.convertToASCII
while using'soft-unicode'
or'hard-unicode'
modes)
- Returns : reverted_string (String)
Caution: characters obtained from 'soft-unicode'
mode wont be reverted if non-ASCII characters are directly converted to ASCII instead of unicode