Class PublicKey

java.lang.Object
com.hedera.hashgraph.sdk.Key
com.hedera.hashgraph.sdk.PublicKey
Direct Known Subclasses:
PublicKeyECDSA, PublicKeyED25519

public abstract class PublicKey extends Key
A public key on the Hedera™ network.
  • Constructor Details

    • PublicKey

      public PublicKey()
  • Method Details

    • fromBytes

      public static PublicKey fromBytes(byte[] publicKey)
      Create a public key from a byte array.
      Parameters:
      publicKey - the byte array
      Returns:
      the new public key
    • fromBytesDER

      public static PublicKey fromBytesDER(byte[] publicKey)
      Create a public key from a DER encoded byte array.
      Parameters:
      publicKey - the DER encoded byte array
      Returns:
      the new key
    • fromBytesED25519

      public static PublicKey fromBytesED25519(byte[] publicKey)
      Create a public key from a byte array.
      Parameters:
      publicKey - the byte array
      Returns:
      the new key
    • fromBytesECDSA

      public static PublicKey fromBytesECDSA(byte[] publicKey)
      Create a public key from a byte array.
      Parameters:
      publicKey - the byte array
      Returns:
      the new key
    • fromString

      public static PublicKey fromString(String publicKey)
      Create a public key from a string.
      Parameters:
      publicKey - the string
      Returns:
      the new key
    • fromStringED25519

      public static PublicKey fromStringED25519(String publicKey)
      Create a public key from a string.
      Parameters:
      publicKey - the string
      Returns:
      the new key
    • fromStringECDSA

      public static PublicKey fromStringECDSA(String publicKey)
      Create a public key from a string.
      Parameters:
      publicKey - the string
      Returns:
      the new key
    • fromStringDER

      public static PublicKey fromStringDER(String publicKey)
      Create a public key from a string.
      Parameters:
      publicKey - the string
      Returns:
      the new key
    • fromAliasBytes

      @Nullable static PublicKey fromAliasBytes(com.google.protobuf.ByteString aliasBytes)
      The public key from an immutable byte string.
      Parameters:
      aliasBytes - the immutable byte string
      Returns:
      the key
    • verify

      public abstract boolean verify(byte[] message, byte[] signature)
      Verify a signature on a message with this public key.
      Parameters:
      message - The array of bytes representing the message
      signature - The array of bytes representing the signature
      Returns:
      boolean
    • extractSignatureFromProtobuf

      abstract com.google.protobuf.ByteString extractSignatureFromProtobuf(SignaturePair pair)
      Get the signature from a signature pair protobuf.
      Parameters:
      pair - the protobuf
      Returns:
      the signature
    • verifyTransaction

      public boolean verifyTransaction(Transaction<?> transaction)
      Is the given transaction valid?
      Parameters:
      transaction - the transaction
      Returns:
      is it valid
    • toSignaturePairProtobuf

      abstract SignaturePair toSignaturePairProtobuf(byte[] signature)
      Serialize this key as a SignaturePair protobuf object
    • toBytes

      public abstract byte[] toBytes()
      Description copied from class: Key
      Create the byte array.
      Overrides:
      toBytes in class Key
      Returns:
      the byte array representation
    • toBytesDER

      public abstract byte[] toBytesDER()
      Extract the DER represented as a byte array.
      Returns:
      the DER represented as a byte array
    • toBytesRaw

      public abstract byte[] toBytesRaw()
      Extract the raw byte representation.
      Returns:
      the raw byte representation
    • toString

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

      public String toStringDER()
      Extract the DER encoded string.
      Returns:
      the DER encoded string
    • toStringRaw

      public String toStringRaw()
      Extract the raw string.
      Returns:
      the raw string
    • toAccountId

      public AccountId toAccountId(@Nonnegative long shard, @Nonnegative long realm)
      Create a new account id.
      Parameters:
      shard - the shard part
      realm - the realm part
      Returns:
      the new account id
    • isED25519

      public abstract boolean isED25519()
      Is this an ED25519 key?
      Returns:
      is this an ED25519 key
    • isECDSA

      public abstract boolean isECDSA()
      Is this an ECDSA key?
      Returns:
      is this an ECDSA key
    • toEvmAddress

      public abstract EvmAddress toEvmAddress()
      Converts the key to EVM address
      Returns:
      the EVM address
    • unusableKey

      public static PublicKey unusableKey()
      Returns an "unusable" public key. “Unusable” refers to a key such as an Ed25519 0x00000... public key, since it is (presumably) impossible to find the 32-byte string whose SHA-512 hash begins with 32 bytes of zeros.
      Returns:
      The "unusable" key