Class SignerKey
This class supports four types of signers as defined in the Stellar protocol:
- ED25519 - Standard Ed25519 public key signer
- PRE_AUTH_TX - Pre-authorized transaction hash signer
- HASH_X - SHA-256 hash preimage signer
- ED25519_SIGNED_PAYLOAD - Ed25519 signed payload signer (CAP-40)
The Ed25519 Signed Payload Signer (introduced in CAP-40) is particularly useful for multi-party contracts like payment channels, as it allows all parties to share a set of transactions for signing and guarantees that if one transaction is signed and submitted, information is revealed that allows all other transactions in the set to be authorized.
Example usage:
// Create an Ed25519 signer
SignerKey ed25519Signer = SignerKey.fromEd25519PublicKey("GCEZWKCA5VLDNRLN3RPRJMRZOX3Z6G5CHCGSNFHEYVXM3XOJMDS674JZ");
// Create a signed payload signer
byte[] payload = "transaction_hash".getBytes();
Ed25519SignedPayload signedPayload = new Ed25519SignedPayload(publicKeyBytes, payload);
SignerKey payloadSigner = SignerKey.fromEd25519SignedPayload(signedPayload);
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classRepresents an Ed25519 signed payload as defined in CAP-40. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intMaximum payload length for Ed25519 signed payload signers. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanstatic SignerKeyfromEd25519PublicKey(byte[] key) Creates a SignerKey from an Ed25519 public key.static SignerKeyCreates a SignerKey from an encoded Ed25519 public key string.static SignerKeyfromEd25519SignedPayload(byte[] key) Creates a SignerKey from an Ed25519 signed payload.static SignerKeyCreates a SignerKey from an encoded Ed25519 signed payload string.static SignerKeyfromEd25519SignedPayload(String ed25519PublicKey, byte[] payload) Creates a SignerKey from an Ed25519 public key and payload.static SignerKeyfromEd25519SignedPayload(SignerKey.Ed25519SignedPayload ed25519SignedPayload) Creates a SignerKey from an Ed25519SignedPayload object.static SignerKeyfromEncodedSignerKey(String encodedSignerKey) Creates a SignerKey from an encoded signer key string.static SignerKeyfromPreAuthTx(byte[] key) Creates a SignerKey from a pre-authorized transaction hash.static SignerKeyfromPreAuthTx(String key) Creates a SignerKey from an encoded pre-authorized transaction hash string.static SignerKeyfromPreAuthTx(Transaction key) Creates a SignerKey from a pre-authorized transaction.static SignerKeyfromSha256Hash(byte[] key) Creates a SignerKey from a SHA-256 hash.static SignerKeyfromSha256Hash(String key) Creates a SignerKey from an encoded SHA-256 hash string.static SignerKeyCreates a SignerKey from its XDR representation.Gets the encoded string representation of this signer key.byte[]getKey()The raw key bytes for this signer.getType()The type of this signer key.inthashCode()Converts this SignerKey to an Ed25519SignedPayload object.toString()toXdr()Converts this SignerKey to its XDR representation.
-
Field Details
-
SIGNED_PAYLOAD_MAX_PAYLOAD_LENGTH
public static final int SIGNED_PAYLOAD_MAX_PAYLOAD_LENGTHMaximum payload length for Ed25519 signed payload signers. As defined in CAP-40, the payload has a maximum size of 64 bytes.- See Also:
-
-
Constructor Details
-
SignerKey
Creates a newSignerKeyinstance.- Parameters:
key- The raw key bytes for this signer. The format depends on the signer type:- ED25519: 32-byte public key
- PRE_AUTH_TX: 32-byte transaction hash
- HASH_X: 32-byte SHA-256 hash
- ED25519_SIGNED_PAYLOAD: Variable length encoded payload with public key
type- The type of this signer key.
-
-
Method Details
-
getEncodedSignerKey
Gets the encoded string representation of this signer key.- Returns:
- The StrKey-encoded representation of this signer key
- Throws:
IllegalArgumentException- if the signer key type is unknown
-
fromEncodedSignerKey
Creates a SignerKey from an encoded signer key string.This method automatically detects the signer key type based on the encoded string format and creates the appropriate SignerKey instance.
- Parameters:
encodedSignerKey- The StrKey-encoded signer key string- Returns:
- A new SignerKey instance
- Throws:
IllegalArgumentException- if the encoded signer key is invalid
-
fromEd25519PublicKey
Creates a SignerKey from an Ed25519 public key.- Parameters:
key- The 32-byte Ed25519 public key- Returns:
- A new SignerKey instance of type ED25519
-
fromEd25519PublicKey
Creates a SignerKey from an encoded Ed25519 public key string.- Parameters:
key- The StrKey-encoded Ed25519 public key (starts with 'G')- Returns:
- A new SignerKey instance of type ED25519
- Throws:
IllegalArgumentException- if the key is not a valid Ed25519 public key
-
fromPreAuthTx
Creates a SignerKey from a pre-authorized transaction hash.Pre-authorized transaction signers allow a transaction to be authorized by including the hash of a specific transaction as a signer. This is useful for creating transactions that can only be executed if a specific other transaction is also executed.
- Parameters:
key- The 32-byte transaction hash- Returns:
- A new SignerKey instance of type PRE_AUTH_TX
-
fromPreAuthTx
Creates a SignerKey from an encoded pre-authorized transaction hash string.- Parameters:
key- The StrKey-encoded pre-authorized transaction hash (starts with 'T')- Returns:
- A new SignerKey instance of type PRE_AUTH_TX
- Throws:
IllegalArgumentException- if the key is not a valid pre-authorized transaction hash
-
fromPreAuthTx
Creates a SignerKey from a pre-authorized transaction.- Parameters:
key- The pre-authorized transaction- Returns:
- A new SignerKey instance of type PRE_AUTH_TX
-
fromSha256Hash
Creates a SignerKey from a SHA-256 hash.Hash-X signers allow a transaction to be authorized by revealing the preimage of a specific SHA-256 hash. This is useful for creating hashlocks and other cryptographic puzzles.
- Parameters:
key- The 32-byte SHA-256 hash- Returns:
- A new SignerKey instance of type HASH_X
-
fromSha256Hash
Creates a SignerKey from an encoded SHA-256 hash string.- Parameters:
key- The StrKey-encoded SHA-256 hash (starts with 'X')- Returns:
- A new SignerKey instance of type HASH_X
- Throws:
IllegalArgumentException- if the key is not a valid SHA-256 hash
-
fromEd25519SignedPayload
Creates a SignerKey from an Ed25519 signed payload.Ed25519 signed payload signers (CAP-40) allow a transaction to be authorized by providing a signature of a specific payload using an Ed25519 key. This is particularly useful for multi-party contracts where signing one transaction reveals information that allows other transactions to be authorized.
- Parameters:
key- The encoded payload containing the Ed25519 public key and payload- Returns:
- A new SignerKey instance of type ED25519_SIGNED_PAYLOAD
-
fromEd25519SignedPayload
Creates a SignerKey from an Ed25519 public key and payload.This method encodes the Ed25519 public key and payload into the binary format required by the Stellar protocol, including proper padding for the payload.
- Parameters:
ed25519PublicKey- The StrKey-encoded Ed25519 public key (starts with 'G')payload- The payload to be signed (up to 64 bytes)- Returns:
- A new SignerKey instance of type ED25519_SIGNED_PAYLOAD
- Throws:
IllegalArgumentException- if the payload length exceeds the maximum allowed
-
fromEd25519SignedPayload
public static SignerKey fromEd25519SignedPayload(SignerKey.Ed25519SignedPayload ed25519SignedPayload) Creates a SignerKey from an Ed25519SignedPayload object.This method encodes the Ed25519 public key and payload into the binary format required by the Stellar protocol, including proper padding for the payload.
- Parameters:
ed25519SignedPayload- The Ed25519SignedPayload containing the public key and payload- Returns:
- A new SignerKey instance of type ED25519_SIGNED_PAYLOAD
- Throws:
UnexpectedException- if an I/O error occurs during encoding
-
fromEd25519SignedPayload
Creates a SignerKey from an encoded Ed25519 signed payload string.- Parameters:
key- The StrKey-encoded Ed25519 signed payload (starts with 'P')- Returns:
- A new SignerKey instance of type ED25519_SIGNED_PAYLOAD
- Throws:
IllegalArgumentException- if the key is not a valid Ed25519 signed payload
-
toEd25519SignedPayload
Converts this SignerKey to an Ed25519SignedPayload object.This method extracts the Ed25519 public key and payload from the encoded binary format used by Ed25519 signed payload signers.
- Returns:
- An Ed25519SignedPayload object containing the public key and payload
- Throws:
IllegalArgumentException- if this SignerKey is not of type ED25519_SIGNED_PAYLOAD
-
toXdr
Converts this SignerKey to its XDR representation.- Returns:
- The XDR representation of this signer key
- Throws:
IllegalArgumentException- if the signer key type is unknown
-
fromXdr
Creates a SignerKey from its XDR representation.- Parameters:
signerKey- The XDR representation of a signer key- Returns:
- A new SignerKey instance
- Throws:
IllegalArgumentException- if the XDR signer key type is unknown
-
getKey
public byte[] getKey()The raw key bytes for this signer. The format depends on the signer type:- ED25519: 32-byte public key
- PRE_AUTH_TX: 32-byte transaction hash
- HASH_X: 32-byte SHA-256 hash
- ED25519_SIGNED_PAYLOAD: Variable length encoded payload with public key
- Returns:
- the raw key bytes
-
getType
The type of this signer key.- Returns:
- the signer key type
-
equals
-
hashCode
public int hashCode() -
toString
-