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 encodingTypestatic byte[]
decodeCheck(java.lang.String input, java.lang.String identifier)
decode input with encoding determined from given identifier Stringstatic 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 encodingTypestatic java.lang.String
encodeCheck(byte[] input, java.lang.String identifier)
encode input with encoding determined from given identifier Stringstatic java.lang.String
generateAuthFunHash(java.lang.String authFun)
generate authentication function name hash for generalized accountsstatic java.lang.String
generateCommitmentHash(java.lang.String name, java.math.BigInteger salt)
generate commitment hash needed to pre-claim a namestatic byte[]
hash(byte[] input)
hash the given input using Blake2bstatic java.lang.String
hashEncode(byte[] input, java.lang.String identifier)
hash and encode the given input, also seeencodeCheck(byte[], String)
static boolean
hasValidType(java.lang.String value, java.lang.String type)
check if given value is correct according to typestatic boolean
isAddressValid(java.lang.String address)
check if the given address has the correct lengthstatic 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, EncodingNotSupportedExceptionencode input with encoding determined from given identifier String- Parameters:
input
- the input to encodeidentifier
- seeApiIdentifiers
- Returns:
- base58 or base64 encoded string
- Throws:
EncodingNotSupportedException
- if the encoding type cannot be determined for some reasonjava.lang.IllegalArgumentException
- if the identifier is unknown
-
encodeCheck
public static final java.lang.String encodeCheck(byte[] input, EncodingType encodingType) throws EncodingNotSupportedExceptionencode input with given encodingType- Parameters:
input
- the input to encodeencodingType
- seeEncodingType
- Returns:
- base58 or base64 encoded string
- Throws:
EncodingNotSupportedException
- if the encodingType is not supportedjava.lang.IllegalArgumentException
- if the encodingType is null
-
decodeCheckWithIdentifier
public static final byte[] decodeCheckWithIdentifier(java.lang.String input) throws java.lang.IllegalArgumentExceptiondecode 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 EncodingNotSupportedExceptiondecode input with encoding determined from given identifier String- Parameters:
input
- the encoded string to decodeidentifier
- 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 EncodingNotSupportedExceptiondecode input with given encodingType- Parameters:
input
- the input to decodeencodingType
- seeEncodingType
- Returns:
- the decoded bytearray
- Throws:
EncodingNotSupportedException
- if the encodingType is not supportedjava.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 decodeallowedIdentifiers
- 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 seeencodeCheck(byte[], String)
- Parameters:
input
- to hashidentifier
- 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 fromsalt
- 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 keynonce
- senders nonceoracleId
- oracleId- Returns:
- queryId
-