Class Signature

java.lang.Object
com.norswap.nanoeth.signature.Signature

public final class Signature
extends Object
An ECDSA signature using the SECP-256k1 curve.
  • Field Summary

    Fields
    Modifier and Type Field Description
    Natural r  
    Natural s  
    byte yParity
    The y Parity that specifies which key generated this signature (as there are two possible keys).
  • Constructor Summary

    Constructors
    Constructor Description
    Signature​(int yParity, Natural r, Natural s)
    Creates a new signature with the given yParity, r and s values.
  • Method Summary

    Modifier and Type Method Description
    boolean equals​(Object o)  
    int hashCode()  
    ECPoint recoverPublicKey​(byte[] message)
    Recover the public key from the signature of the hash of the given message, as specified in SEC1 §4.1.6.
    ECPoint recoverPublicKeyWithoutHashing​(byte[] message)
    Recover the public key from the signature of the given message, as specified in SEC1 §4.1.6.
    String toString()  
    boolean verify​(byte[] message)
    Returns true only if this is a valid signature for Keccak hash of the given message.
    boolean verify​(ECPoint publicKey, byte[] message)
    Returns true only if this is a valid signature for Keccak hash of the given message.
    boolean verifyWithoutHashing​(ECPoint publicKey, byte[] message)
    Returns true only if this is a valid signature for the given message.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • yParity

      public final byte yParity
      The y Parity that specifies which key generated this signature (as there are two possible keys). This is also sometimes called "recovery ID" as it allows recovering the public key from the signature. See the signature package README for more information.

      Will be 1 if y is odd, 0 if even.

    • r

      public final Natural r
    • s

      public final Natural s
  • Constructor Details

  • Method Details

    • verify

      public boolean verify​(byte[] message)
      Returns true only if this is a valid signature for Keccak hash of the given message.

      The public key is automatically recovered from the signature and the message.

    • verify

      public boolean verify​(ECPoint publicKey, byte[] message)
      Returns true only if this is a valid signature for Keccak hash of the given message.
    • verifyWithoutHashing

      public boolean verifyWithoutHashing​(ECPoint publicKey, byte[] message)
      Returns true only if this is a valid signature for the given message.

      In Ethereum, the message will always be a hash.

    • recoverPublicKey

      public ECPoint recoverPublicKey​(byte[] message)
      Recover the public key from the signature of the hash of the given message, as specified in SEC1 §4.1.6.
    • recoverPublicKeyWithoutHashing

      public ECPoint recoverPublicKeyWithoutHashing​(byte[] message)
      Recover the public key from the signature of the given message, as specified in SEC1 §4.1.6.

      In Ethereum, the message will always be a hash.

    • equals

      public boolean equals​(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object