Class PersonalSign

java.lang.Object
com.codename1.crypto.evm.PersonalSign

public final class PersonalSign extends Object

EIP-191 personal_sign messages, the "Sign in with Ethereum" and wallet-ownership proof, and the 65-byte r || s || v signatures EVM wallets exchange.

v is written as 27 or 28, the form personal_sign and eth_sign return; the recovering methods also accept 0 and 1.

  • Method Summary

    Modifier and Type
    Method
    Description
    static byte[]
    hash(byte[] message)
    keccak256("\x19Ethereum Signed Message:\n" + len(message) + message).
    static byte[]
    hash(String message)
    hash(byte[]) of a text message, UTF-8 encoded.
    static EvmAddress
    recover(byte[] message, byte[] signature65)
    The address that signed a message.
    static EvmAddress
    recoverHash(byte[] hash32, byte[] signature65)
    The address whose key produced signature65 over a 32-byte digest.
    static byte[]
    sign(byte[] message, byte[] privateKey)
    Signs a message as personal_sign does.
    static byte[]
    sign(String message, byte[] privateKey)
    Signs a text message as personal_sign does.
    static byte[]
    signHash(byte[] hash32, byte[] privateKey)
    Signs a 32-byte digest, answering r || s || v with v 27 or 28.
    static boolean
    verify(String message, byte[] signature65, EvmAddress address)
    Tells whether address signed the text message.

    Methods inherited from class Object

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

    • hash

      public static byte[] hash(byte[] message)
      keccak256("\x19Ethereum Signed Message:\n" + len(message) + message).
    • hash

      public static byte[] hash(String message)
      hash(byte[]) of a text message, UTF-8 encoded.
    • sign

      public static byte[] sign(byte[] message, byte[] privateKey)
      Signs a message as personal_sign does.
    • sign

      public static byte[] sign(String message, byte[] privateKey)
      Signs a text message as personal_sign does.
    • recover

      public static EvmAddress recover(byte[] message, byte[] signature65)

      The address that signed a message.

      Throws
      • IllegalArgumentException: for a malformed signature

      • com.codename1.security.CryptoException: when the signature recovers no key

    • verify

      public static boolean verify(String message, byte[] signature65, EvmAddress address)
      Tells whether address signed the text message.
    • signHash

      public static byte[] signHash(byte[] hash32, byte[] privateKey)
      Signs a 32-byte digest, answering r || s || v with v 27 or 28.
    • recoverHash

      public static EvmAddress recoverHash(byte[] hash32, byte[] signature65)
      The address whose key produced signature65 over a 32-byte digest.