Class SecpFieldElementImpl

java.lang.Object
org.bitcoinj.secp.internal.SecpFieldElementImpl
All Implemented Interfaces:
SecpFieldElement

public class SecpFieldElementImpl extends Object implements SecpFieldElement
Implementation of SecpFieldElement as an array of bytes.
  • Constructor Details

    • SecpFieldElementImpl

      public SecpFieldElementImpl(BigInteger i)
    • SecpFieldElementImpl

      public SecpFieldElementImpl(byte[] bytes)
      Caller is responsible for defensively copying byte[]. This is to avoid a redundant copy. Exclusive ownership must be passed to this instance.
      Parameters:
      bytes - (will not be defensively copied)
  • Method Details

    • toBigInteger

      public BigInteger toBigInteger()
      Description copied from interface: SecpFieldElement
      Get the field element as a BigInteger
      Specified by:
      toBigInteger in interface SecpFieldElement
      Returns:
      field element value
    • serialize

      public byte[] serialize()
      Description copied from interface: SecpFieldElement
      Get serialized (big-endian) field element (32 bytes unsigned)
      Specified by:
      serialize in interface SecpFieldElement
      Returns:
      serialized field element
    • isOdd

      public boolean isOdd()
      Description copied from interface: SecpFieldElement
      Get the parity of the field value
      Specified by:
      isOdd in interface SecpFieldElement
      Returns:
      true if odd, false if even
    • equals

      public boolean equals(@Nullable 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
    • integerTo32Bytes

      public static byte[] integerTo32Bytes(BigInteger i)
      Convert a BigInteger to a fixed-length byte array verifying it's a valid P256k1 field element.
      Parameters:
      i - an unsigned BigInteger containing a valid Secp256k1 field value
      Returns:
      a 32-byte, big-endian unsigned integer value
    • isInRange

      public static boolean isInRange(byte[] e)
    • checkInRange

      public static byte[] checkInRange(byte[] e)
      Throw IllegalArgumentException if the byte array is not the length.

      NOTE: We are not currently validating for value less than P

      Parameters:
      e - unvalidated integer (byte[] format)
      Returns:
      a validated integer (byte[] format)