public final class SignerKey
extends java.lang.Object
This class supports four types of signers as defined in the Stellar protocol:
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);
Modifier and Type | Class and Description |
---|---|
static class |
SignerKey.Ed25519SignedPayload
Represents an Ed25519 signed payload as defined in CAP-40.
|
Modifier and Type | Field and Description |
---|---|
static int |
SIGNED_PAYLOAD_MAX_PAYLOAD_LENGTH
Maximum payload length for Ed25519 signed payload signers.
|
Constructor and Description |
---|
SignerKey(byte[] key,
SignerKeyType type)
Creates a new
SignerKey instance. |
Modifier and Type | Method and Description |
---|---|
boolean |
equals(java.lang.Object o) |
static SignerKey |
fromEd25519PublicKey(byte[] key)
Creates a SignerKey from an Ed25519 public key.
|
static SignerKey |
fromEd25519PublicKey(java.lang.String key)
Creates a SignerKey from an encoded Ed25519 public key string.
|
static SignerKey |
fromEd25519SignedPayload(byte[] key)
Creates a SignerKey from an Ed25519 signed payload.
|
static SignerKey |
fromEd25519SignedPayload(SignerKey.Ed25519SignedPayload ed25519SignedPayload)
Creates a SignerKey from an Ed25519SignedPayload object.
|
static SignerKey |
fromEd25519SignedPayload(java.lang.String key)
Creates a SignerKey from an encoded Ed25519 signed payload string.
|
static SignerKey |
fromEd25519SignedPayload(java.lang.String ed25519PublicKey,
byte[] payload)
Creates a SignerKey from an Ed25519 public key and payload.
|
static SignerKey |
fromEncodedSignerKey(java.lang.String encodedSignerKey)
Creates a SignerKey from an encoded signer key string.
|
static SignerKey |
fromPreAuthTx(byte[] key)
Creates a SignerKey from a pre-authorized transaction hash.
|
static SignerKey |
fromPreAuthTx(java.lang.String key)
Creates a SignerKey from an encoded pre-authorized transaction hash string.
|
static SignerKey |
fromPreAuthTx(Transaction key)
Creates a SignerKey from a pre-authorized transaction.
|
static SignerKey |
fromSha256Hash(byte[] key)
Creates a SignerKey from a SHA-256 hash.
|
static SignerKey |
fromSha256Hash(java.lang.String key)
Creates a SignerKey from an encoded SHA-256 hash string.
|
static SignerKey |
fromXdr(SignerKey signerKey)
Creates a SignerKey from its XDR representation.
|
java.lang.String |
getEncodedSignerKey()
Gets the encoded string representation of this signer key.
|
byte[] |
getKey()
The raw key bytes for this signer.
|
SignerKeyType |
getType()
The type of this signer key.
|
int |
hashCode() |
SignerKey.Ed25519SignedPayload |
toEd25519SignedPayload()
Converts this SignerKey to an Ed25519SignedPayload object.
|
java.lang.String |
toString() |
SignerKey |
toXdr()
Converts this SignerKey to its XDR representation.
|
public static final int SIGNED_PAYLOAD_MAX_PAYLOAD_LENGTH
public SignerKey(byte[] key, SignerKeyType type)
SignerKey
instance.key
- The raw key bytes for this signer. The format depends on the signer type:
type
- The type of this signer key.public java.lang.String getEncodedSignerKey()
java.lang.IllegalArgumentException
- if the signer key type is unknownpublic static SignerKey fromEncodedSignerKey(java.lang.String encodedSignerKey)
This method automatically detects the signer key type based on the encoded string format and creates the appropriate SignerKey instance.
encodedSignerKey
- The StrKey-encoded signer key stringjava.lang.IllegalArgumentException
- if the encoded signer key is invalidpublic static SignerKey fromEd25519PublicKey(byte[] key)
key
- The 32-byte Ed25519 public keypublic static SignerKey fromEd25519PublicKey(java.lang.String key)
key
- The StrKey-encoded Ed25519 public key (starts with 'G')java.lang.IllegalArgumentException
- if the key is not a valid Ed25519 public keypublic static SignerKey fromPreAuthTx(byte[] key)
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.
key
- The 32-byte transaction hashpublic static SignerKey fromPreAuthTx(java.lang.String key)
key
- The StrKey-encoded pre-authorized transaction hash (starts with 'T')java.lang.IllegalArgumentException
- if the key is not a valid pre-authorized transaction hashpublic static SignerKey fromPreAuthTx(Transaction key)
key
- The pre-authorized transactionpublic static SignerKey fromSha256Hash(byte[] key)
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.
key
- The 32-byte SHA-256 hashpublic static SignerKey fromSha256Hash(java.lang.String key)
key
- The StrKey-encoded SHA-256 hash (starts with 'X')java.lang.IllegalArgumentException
- if the key is not a valid SHA-256 hashpublic static SignerKey fromEd25519SignedPayload(byte[] key)
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.
key
- The encoded payload containing the Ed25519 public key and payloadpublic static SignerKey fromEd25519SignedPayload(java.lang.String ed25519PublicKey, byte[] 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.
ed25519PublicKey
- The StrKey-encoded Ed25519 public key (starts with 'G')payload
- The payload to be signed (up to 64 bytes)java.lang.IllegalArgumentException
- if the payload length exceeds the maximum allowedpublic static SignerKey fromEd25519SignedPayload(SignerKey.Ed25519SignedPayload ed25519SignedPayload)
This method encodes the Ed25519 public key and payload into the binary format required by the Stellar protocol, including proper padding for the payload.
ed25519SignedPayload
- The Ed25519SignedPayload containing the public key and payloadUnexpectedException
- if an I/O error occurs during encodingpublic static SignerKey fromEd25519SignedPayload(java.lang.String key)
key
- The StrKey-encoded Ed25519 signed payload (starts with 'P')java.lang.IllegalArgumentException
- if the key is not a valid Ed25519 signed payloadpublic SignerKey.Ed25519SignedPayload toEd25519SignedPayload()
This method extracts the Ed25519 public key and payload from the encoded binary format used by Ed25519 signed payload signers.
java.lang.IllegalArgumentException
- if this SignerKey is not of type ED25519_SIGNED_PAYLOADpublic SignerKey toXdr()
java.lang.IllegalArgumentException
- if the signer key type is unknownpublic static SignerKey fromXdr(SignerKey signerKey)
signerKey
- The XDR representation of a signer keyjava.lang.IllegalArgumentException
- if the XDR signer key type is unknownpublic byte[] getKey()
public SignerKeyType getType()
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object