Skip to content

Waves Crypto

Vladimir edited this page Jul 23, 2019 · 5 revisions

This is a collection of functions used for cooperating with Waves basic types and crypto primitives. For a better understanding of this functionality please take into account the basic definitions.

Methods list:

  • blake2b()
    /**
     BLAKE2 are cryptographic hash function
     
     - Parameter: input byte array of input data
     - Returns: byte array of hash values
     */
    func blake2b256(input: Bytes) -> Bytes
  • keccak()
   /**
     Keccak are secure hash algorithm
     
     - Parameter: input byte array of input data
     - Returns: byte array of hash values
     */ 
    func keccak256(input: Bytes) -> Bytes
  • sha256()
    /**
     SHA-256 are cryptographic hash function
     
     - Parameter: input byte array of input data
     - Returns: byte array of hash values
     */
    func sha256(input: Bytes) -> Bytes
  • base58encode()
    /**
     Base58 binary-to-text encoding function used to represent large integers as alphanumeric text.
     Compared to Base64 like in base64encode(), the following similar-looking letters are omitted:
     0 (zero), O (capital o), I (capital i) and l (lower case L) as well
     as the non-alphanumeric characters + (plus) and / (slash)
     
     - Parameter: input byte array containing binary data to encode
     - Returns: encoded string containing Base58 characters
     */
    func base58encode(input: Bytes) -> String?
  • base58decode()
    /**
     Base58 text-to-binary function used to restore data encoded by Base58,
     reverse of base58encode()
     
     - Parameter: input encoded Base58 string
     - Returns: decoded byte array
     */
    func base58decode(input: String) -> Bytes?
  • base64encode()
    /**
      Base64 binary-to-text encoding function used to represent binary data in an ASCII
      string format by translating it into a radix-64 representation.
      The implementation uses A–Z, a–z, and 0–9 for the first 62 values and '+', '/'
     
      - Parameter: input byte array containing binary data to encode.
      - Returns: String containing Base64 characters
     */
    func base64encode(input: Bytes) -> String
  • base64decode()
    /**
     Base64 text-to-binary function used to restore data encoded by Base64,
     reverse of base64encode()
     
     - Parameter: input encoded Base64 string
     - Returns: decoded byte array
     */
    func base64decode(input: String) -> Bytes?
  • keyPair()
    /**
     - Returns: a public and private key-pair by seed-phrase
     */
    func keyPair(seed: Seed) -> KeyPair?
  • publicKey()
    /**
     - Returns: a public key as String by seed-phrase
     */
    func publicKey(seed: Seed) -> PublicKey?
  • privateKey()
    /**
     - Returns: a private key as String by seed-phrase
     */
    func privateKey(seed: Seed) -> PrivateKey?
  • address(publicKey: PublicKey)
    /**
     - Returns: a new generated Waves address as String from the publicKey and chainId
     */
    func address(publicKey: PublicKey, chainId: String?) -> Address?
  • address(seed: Seed)
    /**
     - Returns: a new generated Waves address as String from the seed-phrase
     */
    func address(seed: Seed, chainId: String?) -> Address?
  • randomSeed()
    /**
     Random Seed-phrase generator from 2048 prepared words.
     It is a list of words which store all the information needed to recover a private key
     - Returns: a new randomly generated BIP39 seed-phrase
     */
    func randomSeed() -> Seed
  • signBytes(bytes: Bytes, privateKey: PrivateKey)
    /**
     - Parameter: privateKey is a key to an address that gives access
     to the management of the tokens on that address as String.
     It is string encoded by Base58 from byte array.
     - Returns: signature for the bytes by privateKey as byte array
     */
    func signBytes(bytes: Bytes, privateKey: PrivateKey) -> Bytes?
  • signBytes(bytes: Bytes, seed: Seed)
    /**
     - Returns: signature for the bytes by seed-phrase as byte array
     */
    func signBytes(bytes: Bytes, seed: Seed) -> Bytes?
  • verifySignature()
    /**
     - Returns: true if signature is a valid signature of bytes by publicKey
     */
    func verifySignature(publicKey: PublicKey, bytes: Bytes, signature: Bytes) -> Bool
  • verifyPublicKey()
    /**
     - Returns: true if publicKey is a valid public key
     */
    func verifyPublicKey(publicKey: PublicKey) -> Bool
  • verifyAddress()
    /**
     Checks address for a valid by optional chainId and publicKey params
     If params non null it iss will be checked.
     - Parameter: address a unique identifier of an account on the Waves blockchain
     - Parameter: chainId it is id of blockchain network 'W' for production and 'T' for test net
     - Parameter: publicKey
     - Returns: true if address is a valid Waves address for optional chainId and publicKey
     */
    func verifyAddress(address: Address, chainId: String?, publicKey: PublicKey?) -> Bool