Class EncodingUtils

java.lang.Object
com.kryptokrauts.aeternity.sdk.util.EncodingUtils

public final class EncodingUtils
extends java.lang.Object
This util class provides all encoding related methods
  • Constructor Summary

    Constructors
    Constructor Description
    EncodingUtils()  
  • Method Summary

    Modifier and Type Method Description
    static java.lang.String addressToHex​(java.lang.String base58CheckAddress)  
    static byte[] decodeCheck​(java.lang.String input, EncodingType encodingType)
    decode input with given encodingType
    static byte[] decodeCheck​(java.lang.String input, java.lang.String identifier)
    decode input with encoding determined from given identifier String
    static byte[] decodeCheckAndTag​(java.lang.String input)  
    static byte[] decodeCheckAndTag​(java.lang.String input, java.util.List<java.lang.String> allowedIdentifiers)  
    static byte[] decodeCheckWithIdentifier​(java.lang.String input)
    decode input which is combined of the identifier and the encoded string (e.g.
    static java.lang.String encodeCheck​(byte[] input, EncodingType encodingType)
    encode input with given encodingType
    static java.lang.String encodeCheck​(byte[] input, java.lang.String identifier)
    encode input with encoding determined from given identifier String
    static java.lang.String generateAuthFunHash​(java.lang.String authFun)
    generate authentication function name hash for generalized accounts
    static java.lang.String generateCommitmentHash​(java.lang.String name, java.math.BigInteger salt)
    generate commitment hash needed to pre-claim a name
    static byte[] hash​(byte[] input)
    hash the given input using Blake2b
    static java.lang.String hashEncode​(byte[] input, java.lang.String identifier)
    hash and encode the given input, also see encodeCheck(byte[], String)
    static boolean hasValidType​(java.lang.String value, java.lang.String type)
    check if given value is correct according to type
    static boolean isAddressValid​(java.lang.String address)
    check if the given address has the correct length
    static java.lang.String queryId​(java.lang.String senderId, java.math.BigInteger nonce, java.lang.String oracleId)  

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • EncodingUtils

      public EncodingUtils()
  • Method Details

    • encodeCheck

      public static final java.lang.String encodeCheck​(byte[] input, java.lang.String identifier) throws java.lang.IllegalArgumentException, EncodingNotSupportedException
      encode input with encoding determined from given identifier String
      Parameters:
      input - the input to encode
      identifier - see ApiIdentifiers
      Returns:
      base58 or base64 encoded string
      Throws:
      EncodingNotSupportedException - if the encoding type cannot be determined for some reason
      java.lang.IllegalArgumentException - if the identifier is unknown
    • encodeCheck

      public static final java.lang.String encodeCheck​(byte[] input, EncodingType encodingType) throws EncodingNotSupportedException
      encode input with given encodingType
      Parameters:
      input - the input to encode
      encodingType - see EncodingType
      Returns:
      base58 or base64 encoded string
      Throws:
      EncodingNotSupportedException - if the encodingType is not supported
      java.lang.IllegalArgumentException - if the encodingType is null
    • decodeCheckWithIdentifier

      public static final byte[] decodeCheckWithIdentifier​(java.lang.String input) throws java.lang.IllegalArgumentException
      decode input which is combined of the identifier and the encoded string (e.g. ak_[encoded])
      Parameters:
      input - the encoded string to decode
      Returns:
      the decoded bytearray
      Throws:
      java.lang.IllegalArgumentException - if the input has a wrong/unexpected format
    • decodeCheck

      public static final byte[] decodeCheck​(java.lang.String input, java.lang.String identifier) throws EncodingNotSupportedException
      decode input with encoding determined from given identifier String
      Parameters:
      input - the encoded string to decode
      identifier - see @ApiIdentifiers
      Returns:
      the decoded bytearray
      Throws:
      EncodingNotSupportedException - if the encoding type cannot be determined for some reason
    • decodeCheck

      public static final byte[] decodeCheck​(java.lang.String input, EncodingType encodingType) throws EncodingNotSupportedException
      decode input with given encodingType
      Parameters:
      input - the input to decode
      encodingType - see EncodingType
      Returns:
      the decoded bytearray
      Throws:
      EncodingNotSupportedException - if the encodingType is not supported
      java.lang.IllegalArgumentException - if the encodingType is null
    • decodeCheckAndTag

      public static final byte[] decodeCheckAndTag​(java.lang.String input, java.util.List<java.lang.String> allowedIdentifiers)
      Parameters:
      input - the input to decode
      allowedIdentifiers - the apiIdentifiers allowed (if null or empty all known identifiers are allowed)
      Returns:
      the decoded bytearray
    • decodeCheckAndTag

      public static final byte[] decodeCheckAndTag​(java.lang.String input)
      Parameters:
      input - the input to decode
      Returns:
      the decoded bytearray
    • isAddressValid

      public static final boolean isAddressValid​(java.lang.String address)
      check if the given address has the correct length
      Parameters:
      address - base58 encoded aeternity address (ak_...)
      Returns:
      true if the address is valid
      false if the address is invalid
    • hasValidType

      public static final boolean hasValidType​(java.lang.String value, java.lang.String type)
      check if given value is correct according to type
      Parameters:
      value -
      type -
      Returns:
    • addressToHex

      public static final java.lang.String addressToHex​(java.lang.String base58CheckAddress)
      Parameters:
      base58CheckAddress - base58 encoded aeternity address (ak_...)
      Returns:
      the readable public key as hex
    • hashEncode

      public static java.lang.String hashEncode​(byte[] input, java.lang.String identifier)
      hash and encode the given input, also see encodeCheck(byte[], String)
      Parameters:
      input - to hash
      identifier - encoding identifier
      Returns:
      hashed and encoded input
    • hash

      public static byte[] hash​(byte[] input)
      hash the given input using Blake2b
      Parameters:
      input - to hash
      Returns:
      Blake2b hashed input
    • generateCommitmentHash

      public static java.lang.String generateCommitmentHash​(java.lang.String name, java.math.BigInteger salt)
      generate commitment hash needed to pre-claim a name
      Parameters:
      name - to generate commitment hash from
      salt - to generate commitment hash from
      Returns:
      generated commitment hash
    • generateAuthFunHash

      public static java.lang.String generateAuthFunHash​(java.lang.String authFun)
      generate authentication function name hash for generalized accounts
      Parameters:
      authFun - function name to hash
      Returns:
      hex encoded and hashed function name
    • queryId

      public static java.lang.String queryId​(java.lang.String senderId, java.math.BigInteger nonce, java.lang.String oracleId)
      Parameters:
      senderId - senders public key
      nonce - senders nonce
      oracleId - oracleId
      Returns:
      queryId