Class AKeyPair

java.lang.Object
convex.core.crypto.AKeyPair
Direct Known Subclasses:
BCKeyPair

public abstract class AKeyPair extends Object
Abstract base class for key pairs in Convex. Intended as a lightweight container for underlying crypto primitives.
  • Field Details

  • Constructor Details

    • AKeyPair

      public AKeyPair()
  • Method Details

    • getPublicKeyBytes

      public final byte[] getPublicKeyBytes()
      Gets a new byte array representation of the public key
      Returns:
      Bytes of public key
    • getAccountKey

      public abstract AccountKey getAccountKey()
      Gets the Account Public Key of this KeyPair
      Returns:
      AccountKey for this KeyPair
    • signData

      public abstract <R extends ACell> SignedData<R> signData(R value)
      Signs a value with this key pair
      Type Parameters:
      R - Type of Value
      Parameters:
      value - Value to sign. Can be any valid CVM value.
      Returns:
      Signed Data Object
    • equals

      public final boolean equals(Object a)
      Overrides:
      equals in class Object
    • equals

      public abstract boolean equals(AKeyPair kp)
      Tests if this keypair is equal to another key pair. Generally, a key pair should be considered equal if it has the same public key and produces identical signatures in all cases.
      Parameters:
      kp - Other key pair to compare with
      Returns:
      True if key pairs are equal
    • sign

      public abstract ASignature sign(AArrayBlob hash)
      Signs a hash value with this key pair, producing a signature of the appropriate type.
      Parameters:
      hash - Hash of value to sign
      Returns:
      A Signature compatible with the key pair.
    • createSeeded

      public static AKeyPair createSeeded(long seed)
      Create a deterministic key pair with the given seed. SECURITY: Never use this for valuable keys or real assets: intended for deterministic testing only.
      Parameters:
      seed - Any long value. The same seed will produce the same key pair.
      Returns:
      New key pair
    • generate

      public static AKeyPair generate()
      Generates a new, secure random key pair. Uses a Java SecureRandom instance.
      Returns:
      New Key Pair instance.
    • create

      public static AKeyPair create(byte[] keyMaterial)
      Creates a key pair using specific key material.
      Parameters:
      keyMaterial - Bytes to use as key
      Returns:
      New key pair
    • create

      public static AKeyPair create(Blob seed)
      Create a key pair with the given seed. Public key is generated automatically from the private key
      Parameters:
      seed - 32 bytes of seed material
      Returns:
      A new key pair using the given seed
    • getPrivate

      public PrivateKey getPrivate()
      Gets the JCA PrivateKey
      Returns:
      Private Key
    • getPublic

      public PublicKey getPublic()
      Gets the JCA PublicKey
      Returns:
      Public Key
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getJCAKeyPair

      public KeyPair getJCAKeyPair()
      Gets the JCA representation of this Key Pair
      Returns:
      JCA KepPair
    • extractSeed

      protected static Blob extractSeed(PrivateKey priv)
      Gets the seed from a JCA Private Key. Should always be last 32 bytes of the encoding
      Parameters:
      priv - Private Key in JCA format
      Returns:
    • getSeed

      public abstract Blob getSeed()
      Gets the Ed25519 seed for this key pair
      Returns:
      Seed blob of 32 bytes
    • create

      public static AKeyPair create(PrivateKey privateKey)
      Create a KeyPair from given private key. Public key is generated automatically from the private key
      Parameters:
      privateKey - An PrivateKey item for private key
      Returns:
      A new key pair using the given private key
    • create

      public static AKeyPair create(PublicKey publicKey, PrivateKey privateKey)
      Creates an Ed25519 Key Pair with the specified keys
      Parameters:
      publicKey - Public key
      privateKey - Private key
      Returns:
      Key Pair instance
    • create

      public static AKeyPair create(KeyPair keyPair)
      Create a KeyPair from a JCA KeyPair
      Parameters:
      keyPair - JCA KeyPair
      Returns:
      AKeyPair instance
    • privateKeyFromBytes

      public static PrivateKey privateKeyFromBytes(byte[] key)
      Creates a private key using the given raw bytes.
      Parameters:
      key - 32 bytes private key data
      Returns:
      Ed25519 Private Key instance
    • extractAccountKey

      public static AccountKey extractAccountKey(PublicKey publicKey)
      Extracts an AccountKey from an Ed25519 public key
      Parameters:
      publicKey - Public key
      Returns:
      AccountKey instance
    • privateKeyFromBlob

      public static PrivateKey privateKeyFromBlob(Blob encodedKey)
    • privateFromBytes

      public static PrivateKey privateFromBytes(byte[] privKey)
      Gets a Ed25519 Private Key from a 32-byte array.
      Parameters:
      privKey - Bytes to use as a private key seed
      Returns:
      PrivateKey instance
    • publicKeyFromBytes

      public static PublicKey publicKeyFromBytes(byte[] key)