Class EthereumHelper


  • public abstract class EthereumHelper
    extends Object
    • Constructor Detail

      • EthereumHelper

        public EthereumHelper()
    • Method Detail

      • getEthereumMessageHash

        public static byte[] getEthereumMessageHash​(String messageString)
        Given a String message, return the prefixed message hashed
        Parameters:
        messageString - message to hash
        Returns:
        byte[]
      • signMessage

        public static org.web3j.crypto.Sign.SignatureData signMessage​(String message,
                                                                      org.web3j.crypto.ECKeyPair keyPair)
        Given a string and a ECKeyPair sign the ethereum prefixed message
        Parameters:
        message - message to sign
        keyPair - keypair
        Returns:
        signature data
      • signMessage

        public static org.web3j.crypto.Sign.SignatureData signMessage​(String message,
                                                                      org.web3j.crypto.Credentials credentials)
        Given a string and a ECKeyPair sign the ethereum prefixed message
        Parameters:
        message - message to sign
        credentials - user credentials
        Returns:
        signature data
      • recoverAddressFromSignature

        public static List<String> recoverAddressFromSignature​(org.web3j.crypto.Sign.SignatureData signatureData,
                                                               byte[] hashMessage)
        Given a signature data and the hashed message, recover and return the public key that generated the signature
        Parameters:
        signatureData - signature data
        hashMessage - hashed message
        Returns:
        address
      • wasSignedByAddress

        public static boolean wasSignedByAddress​(String address,
                                                 org.web3j.crypto.Sign.SignatureData signatureData,
                                                 byte[] hashMessage)
        Given an address, signature data and the hashed message return true or false if the address is the one used to sign the message
        Parameters:
        address - address
        signatureData - the signature
        hashMessage - the hashed message
        Returns:
        boolean
      • ethSignMessage

        public static String ethSignMessage​(org.web3j.protocol.Web3j web3,
                                            String message,
                                            String address,
                                            String password)
                                     throws IOException
        Execute a web3 eth-sign message in the keeper
        Parameters:
        web3 - web3j
        message - message to sign
        address - address to use for signing
        password - password to use for signing
        Returns:
        signed message
        Throws:
        IOException - IOException
      • ethEncodeAndSignMessage

        public static String ethEncodeAndSignMessage​(org.web3j.protocol.Web3j web3,
                                                     String message,
                                                     String address,
                                                     String password)
                                              throws IOException
        Hashing a message and signing using web3 eth-sign
        Parameters:
        web3 - web3j
        message - message to hash and sign
        address - address to use for signing
        password - password to use for signing
        Returns:
        signed message
        Throws:
        IOException - IOException
      • remove0x

        public static String remove0x​(String input)
        Removes all the "0x"
        Parameters:
        input - string
        Returns:
        string
      • add0x

        public static String add0x​(String input)
        If a string doesn't start by 0x, prepend 0x to it
        Parameters:
        input - string
        Returns:
        string
      • isValidAddress

        public static boolean isValidAddress​(String input)
        Given an input string validates if it's a valid ethereum address
        Parameters:
        input - the input string
        Returns:
        boolean
      • getFunctionSelector

        public static String getFunctionSelector​(String functionDefinition)
        Given a function defition return the ethereum function selector
        Parameters:
        functionDefinition - the definition of a function
        Returns:
        a String with the ethereum function selector