Skip to content

floCrypto

Sai Raj edited this page May 26, 2023 · 1 revision

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 are all functions. They have not been promisified

Note: for nodejs use require and assign floCrypto to global

global.floCrypto = require('/path/to/floCrypto');

Key generation

Generate New FLO ID pair

floCrypto.generateNewID()

Generates and returns private-key, public-key and floID

  • Returns : Object { privKey , pubKey, floID }

Generate new FLO ID

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;

Generate a hash FLO ID for the given string

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

  1. str - string to be hashed (String)
  • Returns : hashFloID (String)

Generate a dummy floID

floCrypto.tmpID

Generates a random floID without private-key or public-key

  • Returns : dummyFloID (String)

Key manipulations

Calculate Public Key Hex

floCrypto.getPubKeyHex(privateKey)

Calculates the public-key for the given private-key

  1. privateKey - private key in WIF format (Hex)
  • Returns : pubicKey (string)

Calculate FLO ID

floCrypto.getFloID(publickey_or_privateKey)

Calculates flo-ID from given public-key (or) private-key

  1. publickey_or_privateKey - public key or private key
  • Returns : floID (string)

Verify Private Key

floCrypto.verifyPrivKey(privateKey, pubKey_floID, isfloID)

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 (optional) - boolean
    • true: (DEFAULT) given pubKey_floID parameter is floID
    • false: given pubKey_floID parameter is public key
  • Returns : boolean (true or false)

Validate FLO ID

floCrypto.validateFloID(floID)

Check if the given floID is valid or not

  1. floID - flo ID to validate
  2. regularOnly (optional) - boolean
    • true: only validates regular flo-id
    • false: (DEFAULT) also validates multisig flo-id
  • Returns : boolean (true or false)

Verify Public Key (Any Blockchain)

floCrypto.verifyPubKey(publicKey, address)

Verify the public key (or redeem-script) for the given address (any blockchain)

  1. publicKey - public key (or redeem-script of multisig address)
  2. address - address to verify
  • Returns : boolean (true or false)

Multisig for FLO blockchain

Create a multisig address for FLO

floCrypto.getMultisigAddress(publicKeyList, requiredSignatures)

Creates a multisig floID from the given public-key list

  1. publicKeyList: Array of public-keys (shared owners)
  2. 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

Decode redeem script

floCrypto.decodeRedeemScript(redeemScript)

Decodes the given redeemScript

  1. redeemScript: redeem-script of the multisig id
  • Returns : Object {address, pubkeys, required }

NOTE: floCrypto.decodeRedeemScript inverse function of floCrypto.getMultisigAddress.

Cross Blockchain operations

Calculate Address

floCrypto.getAddress(privateKey, strict)

Returns respective address from given private-key

NOTE: supported blockchains FLO, BTC.

  1. privateKey - private key in WIF format
  2. 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)

Validate Address

floCrypto.validateAddr(address, *std, *bech)

Check if the given Address (any blockchain) is valid or not

  1. address - address to validate
  2. std - checks for legacy version (optional, default=true) (true: allow any, array: list of versions, value: one version only, false: allow none)
  3. 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)

Convert to floID

floCrypto.toFloID(address, options)

Converts any blockchain address to floID

  1. address - address (Any blockchain)
  2. 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
  • Returns : floID (string)

NOTE: if options parameter is not passed, converts any address into respective flo-id

Convert raw bytes to floID

floCrypto.rawToFloID(raw_bytes)

Calculates the floID from given raw bytes

  1. raw_bytes - raw bytes to convert into floID (hex or byte array)
  • Returns : floID (string)

Convert to multisig floID

floCrypto.toMultisigFloID(address, options)

Converts any blockchain multisig address to multisig floID

  1. address - address (Any blockchain)
  2. 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
  • Returns : multisigFloID (string)

Check if same address

floCrypto.isSameAddr(addr1, addr2)

Checks if both given address are equivalent w.r.t keys

  1. addr1 - address to compare
  2. addr1 - address to compare
  • Returns : boolean (true or false)

Decode address

floCrypto.decodeAddr(address)
  1. address - address to decode
  • Returns : decoded values (Object)

Encryption and decryption

Data Encryption

floCrypto.encryptData(data, publicKey)

Encrypts the given data using public-key

  1. data - data to encrypt (String)
  2. publicKey - public key of the recipient
  • Returns : Encrypted data (Object)

Data Decryption

floCrypto.decryptData(data, privateKey)

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)

Signing and verification

Sign Data

floCrypto.signData(data, privateKey)

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)

Verifies signatue of the data using public-key

  1. data - data of the given signature
  2. signature - signature of the data
  3. publicKey - public key of the signer
  • Returns : boolean (true or false)

Share Spliting

Create Shamir's Secret shares

floCrypto.createShamirsSecretShares(str, total_shares, threshold_limit)

Splits the data 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)

Reconstructs the secret from the shares.

  1. sharesArray - Array of shares
  • Returns : retrivedData (String)

Verify Shamir's Secret

floCrypto.verifyShamirsSecret(sharesArray, str)

Verfies the validity of the created shares.

  1. sharesArray - Array of shares
  2. str - originalData (string).
  • Returns : boolean (true or false)

Utility functions

Generate Random Interger

floCrypto.randInt(min, max)

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)

Returns a randomly generated string of given length.

  1. length - length of the string to be generated
  2. alphaNumeric (optional) - boolean
    • true: (DEFAULT) generated string will only contain alphabets and digits
    • false: generated string will also have symbols
  • Returns : randomString (String)

Validate ASCII characters

floCrypto.validateASCII(string, bool)

Validates the string if it contains only ASCII characters

  1. string - string to validate
  2. bool (optional) - boolean
    • true: (DEFAULT) returns false when check fails
    • false: returns array of invalid characters when check fails
  • Returns : result (true if check passes)

Convert to ASCII characters

floCrypto.convertToASCII(string, mode)

Converts the given string into valid ASCII characters

  1. string - string to convert into valid ASCII string
  2. 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)

Revert Unicode values to characters

floCrypto.revertUnicode(string)

Converts the unicode values in string into respective characters

  1. 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