public class KeyPair
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
boolean |
canSign()
Returns true if this Keypair is capable of signing
|
boolean |
equals(java.lang.Object object) |
static KeyPair |
fromAccountId(java.lang.String accountId)
Creates a new Stellar KeyPair from a strkey encoded Stellar account ID.
|
static KeyPair |
fromBip39Seed(byte[] bip39Seed,
int accountNumber)
Finds the KeyPair for the path m/44'/148'/accountNumber' using the method described in SEP-0005.
|
static KeyPair |
fromPublicKey(byte[] publicKey)
Creates a new Stellar keypair from a 32 byte address.
|
static KeyPair |
fromSecretSeed(byte[] seed)
Creates a new Stellar keypair from a raw 32 byte secret seed.
|
static KeyPair |
fromSecretSeed(char[] seed)
Creates a new Stellar KeyPair from a strkey encoded Stellar secret seed.
|
static KeyPair |
fromSecretSeed(java.lang.String seed)
Insecure Creates a new Stellar KeyPair from a strkey encoded Stellar secret
seed.
|
static KeyPair |
fromXdrPublicKey(PublicKey key)
Creates a new KeyPair from an XDR
PublicKey . |
java.lang.String |
getAccountId()
Returns the human-readable account ID encoded in strkey.
|
byte[] |
getPublicKey()
Returns the raw 32 byte public key.
|
char[] |
getSecretSeed()
Returns the human-readable secret seed encoded in strkey.
|
SignatureHint |
getSignatureHint()
Returns the signature hint for this keypair.
|
AccountID |
getXdrAccountId()
Returns the XDR
AccountID for this keypair. |
PublicKey |
getXdrPublicKey()
Returns the XDR
PublicKey for this keypair. |
int |
hashCode() |
static KeyPair |
random()
Generates a random Stellar keypair.
|
byte[] |
sign(byte[] data)
Sign the provided data with the keypair's private key.
|
DecoratedSignature |
signDecorated(byte[] data)
Sign the provided data with the keypair's private key and returns
DecoratedSignature . |
byte[] |
signMessage(byte[] message)
Sign a message according to SEP-53.
|
byte[] |
signMessage(java.lang.String message)
Sign a message according to SEP-53.
|
DecoratedSignature |
signPayloadDecorated(byte[] signerPayload)
Sign the provided payload data for payload signer where the input is the data being signed.
|
boolean |
verify(byte[] data,
byte[] signature)
Verify the provided data and signature match this keypair's public key.
|
boolean |
verifyMessage(byte[] message,
byte[] signature)
Verify a SEP-53 signed message.
|
boolean |
verifyMessage(java.lang.String message,
byte[] signature)
Verify a SEP-53 signed message.
|
public boolean canSign()
public static KeyPair fromSecretSeed(char[] seed)
seed
- Char array containing strkey encoded Stellar secret seed.KeyPair
java.lang.IllegalArgumentException
- if the provided seed is invalidpublic static KeyPair fromSecretSeed(java.lang.String seed)
seed
- The strkey encoded Stellar secret seed.KeyPair
java.lang.IllegalArgumentException
- if the provided seed is invalidpublic static KeyPair fromSecretSeed(byte[] seed)
seed
- The 32 byte secret seed.KeyPair
java.lang.IllegalArgumentException
- if the provided seed is invalidpublic static KeyPair fromAccountId(java.lang.String accountId)
accountId
- The strkey encoded Stellar account ID.KeyPair
java.lang.IllegalArgumentException
- if the provided account ID is invalidpublic static KeyPair fromPublicKey(byte[] publicKey)
publicKey
- The 32 byte public key.KeyPair
java.lang.IllegalArgumentException
- if the provided public key is invalidpublic static KeyPair fromBip39Seed(byte[] bip39Seed, int accountNumber)
You can generate a BIP39 seed using a library like mnemonic4j.
bip39Seed
- The output of BIP0039accountNumber
- The number of the accountjava.lang.IllegalArgumentException
- if the provided bip39Seed is invalidpublic static KeyPair random()
public java.lang.String getAccountId()
public char[] getSecretSeed()
WARNING: This method returns the secret seed of the keypair. The secret seed should be handled with care and not be exposed to anyone else. Exposing the secret seed can lead to the theft of the account.
public byte[] getPublicKey()
public SignatureHint getSignatureHint()
public static KeyPair fromXdrPublicKey(PublicKey key)
PublicKey
.key
- The XDR PublicKey
object.public byte[] sign(byte[] data)
data
- The data to sign.java.lang.IllegalStateException
- if the private key for this keypair is null.public DecoratedSignature signDecorated(byte[] data)
DecoratedSignature
.data
- the data to signpublic DecoratedSignature signPayloadDecorated(byte[] signerPayload)
DecoratedSignature
.signerPayload
- the payload signers raw data to signpublic boolean verify(byte[] data, byte[] signature)
data
- The data that was signed.signature
- The signature.public boolean equals(java.lang.Object object)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public byte[] signMessage(java.lang.String message)
message
- The message to sign.public byte[] signMessage(byte[] message)
message
- The message to sign.public boolean verifyMessage(byte[] message, byte[] signature)
message
- The original message.signature
- The signature to verify.public boolean verifyMessage(java.lang.String message, byte[] signature)
message
- The original message.signature
- The signature to verify.