Package com.oceanprotocol.squid.helpers
Class EthereumHelper
- java.lang.Object
-
- com.oceanprotocol.squid.helpers.EthereumHelper
-
public abstract class EthereumHelper extends Object
-
-
Field Summary
Fields Modifier and Type Field Description private static String
MESSAGE_PREFIX
-
Constructor Summary
Constructors Constructor Description EthereumHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static String
add0x(String input)
If a string doesn't start by 0x, prepend 0x to itstatic String
encodeParameterValue(String type, Object value)
static String
ethEncodeAndSignMessage(org.web3j.protocol.Web3j web3, String message, String address, String password)
Hashing a message and signing using web3 eth-signstatic String
ethSignMessage(org.web3j.protocol.Web3j web3, String message, String address, String password)
Execute a web3 eth-sign message in the keeperstatic byte[]
getEthereumMessageHash(String messageString)
Given a String message, return the prefixed message hashedstatic String
getFunctionSelector(String functionDefinition)
Given a function defition return the ethereum function selectorstatic boolean
isValidAddress(String input)
Given an input string validates if it's a valid ethereum addressstatic 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 signaturestatic String
remove0x(String input)
Removes all the "0x"static org.web3j.crypto.Sign.SignatureData
signMessage(String message, org.web3j.crypto.Credentials credentials)
Given a string and a ECKeyPair sign the ethereum prefixed messagestatic org.web3j.crypto.Sign.SignatureData
signMessage(String message, org.web3j.crypto.ECKeyPair keyPair)
Given a string and a ECKeyPair sign the ethereum prefixed messagestatic 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
-
-
-
Field Detail
-
MESSAGE_PREFIX
private static final String MESSAGE_PREFIX
- See Also:
- Constant Field Values
-
-
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 signkeyPair
- 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 signcredentials
- 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 datahashMessage
- 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
- addresssignatureData
- the signaturehashMessage
- 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
- web3jmessage
- message to signaddress
- address to use for signingpassword
- 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
- web3jmessage
- message to hash and signaddress
- address to use for signingpassword
- 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
-
encodeParameterValue
public static String encodeParameterValue(String type, Object value) throws UnsupportedEncodingException
- Throws:
UnsupportedEncodingException
-
-