Package org.xrpl.xrpl4j.crypto.keys
Class PrivateKey
java.lang.Object
org.xrpl.xrpl4j.crypto.keys.PrivateKey
- All Implemented Interfaces:
Destroyable,PrivateKeyable
A typed instance of an XRPL private-key.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final UnsignedBytePrivate keys (whether from the ed25519 or secp256k1 curves) have 32 bytes naturally.static final UnsignedByteDeprecated.This value will be removed in a future version.static final UnsignedBytePrivate keys (whether from the ed25519 or secp256k1 curves) have 32 bytes naturally. -
Method Summary
Modifier and TypeMethodDescriptionfinal voiddestroy()booleanstatic PrivateKeyfromNaturalBytes(UnsignedByteArray value, KeyType keyType) Instantiates a new instance ofPrivateKeyusing the supplied 32 bytes and specified key type.static PrivateKeyInstantiates a new instance ofPrivateKeyusing the supplied bytes by inspecting the first byte out of 33 to see whichKeyTypeto assign.inthashCode()final booleanfinal KeyTypekeyType()The type of this key (eitherKeyType.ED25519orKeyType.SECP256K1).Accessor for the byte value invalue()but in a more natural form (i.e., the size of the returned value will be 32 bytes).static PrivateKeyof(UnsignedByteArray value) Deprecated.This method will be removed in a future version.Accessor for the bytes of this private key in a prefixed.toString()value()Deprecated.PreferprefixedBytes()ornaturalBytes()instead.
-
Field Details
-
PREFIX
Deprecated.This value will be removed in a future version. PreferED2559_PREFIXorSECP256K1_PREFIXinstead.A one-byte prefix for ed25519 keys. -
ED2559_PREFIX
Private keys (whether from the ed25519 or secp256k1 curves) have 32 bytes naturally. At the same time, secp256k1 public keys have 33 bytes naturally, whereas ed25519 public keys have 32 bytes naturally. Because of this, in XRPL, ed25519 public keys are prefixed with a one-byte prefix (i.e., 0xED). For consistency, this library (and other XRPL tooling) also prepends all private keys with artificial prefixes (0xED for ed25519 or 0x00 for secp256k1). This value is the one-byte prefix for ed25519 keys. -
SECP256K1_PREFIX
Private keys (whether from the ed25519 or secp256k1 curves) have 32 bytes naturally. At the same time, secp256k1 public keys have 33 bytes naturally, whereas ed25519 public keys have 32 bytes naturally. Because of this, in XRPL, ed25519 public keys are prefixed with a one-byte prefix (i.e., 0xED). For consistency, this library (and other XRPL tooling) also prepends all private keys with artificial prefixes (0xED for ed25519 or 0x00 for secp256k1). This value is the one-byte prefix for secp256k1 keys.
-
-
Method Details
-
fromNaturalBytes
Instantiates a new instance ofPrivateKeyusing the supplied 32 bytes and specified key type.- Parameters:
value- AnUnsignedByteArraycontaining a private key's natural bytes (i.e., 32 bytes).keyType- AKeyTypefor this private key.- Returns:
- A
PrivateKey.
-
fromPrefixedBytes
Instantiates a new instance ofPrivateKeyusing the supplied bytes by inspecting the first byte out of 33 to see whichKeyTypeto assign.- Parameters:
value- AnUnsignedByteArraycontaining a private key's natural bytes (i.e., 32 bytes).- Returns:
- A
PrivateKey.
-
of
Deprecated.This method will be removed in a future version. PreferfromPrefixedBytes(UnsignedByteArray)instead.Instantiates a new instance ofPrivateKeyusing the supplied bytes by inspecting the first byte out of 33 to see whichKeyTypeto assign.- Parameters:
value- AnUnsignedByteArraycontaining this key's binary value.- Returns:
- A
PrivateKey.
-
value
Deprecated.PreferprefixedBytes()ornaturalBytes()instead.Accessor for the key value, in binary (Note: will be 33 bytes).- Returns:
- An instance of
UnsignedByteArray.
-
naturalBytes
Accessor for the byte value invalue()but in a more natural form (i.e., the size of the returned value will be 32 bytes). Natural ed25519 or secp256k1 private keys will ordinarily contain only 32 bytes. However, in XRPL, private keys are represented with a single-byte prefix (i.e., `0xED` for ed25519 and `0x00` for secp256k1 keys).- Returns:
- An instance of
UnsignedByteArray.
-
prefixedBytes
Accessor for the bytes of this private key in a prefixed. Natural ed25519 or secp256k1 private keys will ordinarily contain only 32 bytes. However, in XRPL, private keys are typically represented with a single-byte prefix (i.e., `0xED` for ed25519 and `0x00` for secp256k1 keys), which this method provides.- Returns:
- An instance of
UnsignedByteArray.
-
keyType
The type of this key (eitherKeyType.ED25519orKeyType.SECP256K1).- Specified by:
keyTypein interfacePrivateKeyable- Returns:
- A
KeyType.
-
destroy
public final void destroy()- Specified by:
destroyin interfaceDestroyable
-
isDestroyed
public final boolean isDestroyed()- Specified by:
isDestroyedin interfaceDestroyable
-
equals
-
hashCode
public int hashCode() -
toString
-