Class KeyPair


  • public class KeyPair
    extends java.lang.Object
    Holds a Stellar keypair.
    • Constructor Summary

      Constructors 
      Constructor Description
      KeyPair​(net.i2p.crypto.eddsa.EdDSAPublicKey publicKey)
      Creates a new KeyPair without a private key.
      KeyPair​(net.i2p.crypto.eddsa.EdDSAPublicKey publicKey, net.i2p.crypto.eddsa.EdDSAPrivateKey privateKey)
      Creates a new KeyPair from the given public and private keys.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method 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​(org.stellar.sdk.xdr.PublicKey key)  
      static KeyPair fromXdrSignerKey​(org.stellar.sdk.xdr.SignerKey key)  
      java.lang.String getAccountId()
      Returns the human readable account ID encoded in strkey.
      byte[] getPublicKey()  
      char[] getSecretSeed()
      Returns the human readable secret seed encoded in strkey.
      org.stellar.sdk.xdr.SignatureHint getSignatureHint()  
      org.stellar.sdk.xdr.AccountID getXdrAccountId()  
      org.stellar.sdk.xdr.PublicKey getXdrPublicKey()  
      org.stellar.sdk.xdr.SignerKey getXdrSignerKey()  
      int hashCode()  
      static KeyPair random()
      Generates a random Stellar keypair.
      byte[] sign​(byte[] data)
      Sign the provided data with the keypair's private key.
      org.stellar.sdk.xdr.DecoratedSignature signDecorated​(byte[] data)
      Sign the provided data with the keypair's private key and returns DecoratedSignature.
      org.stellar.sdk.xdr.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.
      • Methods inherited from class java.lang.Object

        getClass, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • KeyPair

        public KeyPair​(net.i2p.crypto.eddsa.EdDSAPublicKey publicKey)
        Creates a new KeyPair without a private key. Useful to simply verify a signature from a given public address.
        Parameters:
        publicKey -
      • KeyPair

        public KeyPair​(net.i2p.crypto.eddsa.EdDSAPublicKey publicKey,
                       net.i2p.crypto.eddsa.EdDSAPrivateKey privateKey)
        Creates a new KeyPair from the given public and private keys.
        Parameters:
        publicKey -
        privateKey -
    • Method Detail

      • canSign

        public boolean canSign()
        Returns true if this Keypair is capable of signing
      • fromSecretSeed

        public static KeyPair fromSecretSeed​(char[] seed)
        Creates a new Stellar KeyPair from a strkey encoded Stellar secret seed.
        Parameters:
        seed - Char array containing strkey encoded Stellar secret seed.
        Returns:
        KeyPair
      • fromSecretSeed

        public static KeyPair fromSecretSeed​(java.lang.String seed)
        Insecure Creates a new Stellar KeyPair from a strkey encoded Stellar secret seed. This method is insecure. Use only if you are aware of security implications.
        Parameters:
        seed - The strkey encoded Stellar secret seed.
        Returns:
        KeyPair
        See Also:
        Using Password-Based Encryption
      • fromSecretSeed

        public static KeyPair fromSecretSeed​(byte[] seed)
        Creates a new Stellar keypair from a raw 32 byte secret seed.
        Parameters:
        seed - The 32 byte secret seed.
        Returns:
        KeyPair
      • fromAccountId

        public static KeyPair fromAccountId​(java.lang.String accountId)
        Creates a new Stellar KeyPair from a strkey encoded Stellar account ID.
        Parameters:
        accountId - The strkey encoded Stellar account ID.
        Returns:
        KeyPair
      • fromPublicKey

        public static KeyPair fromPublicKey​(byte[] publicKey)
        Creates a new Stellar keypair from a 32 byte address.
        Parameters:
        publicKey - The 32 byte public key.
        Returns:
        KeyPair
      • fromBip39Seed

        public static KeyPair fromBip39Seed​(byte[] bip39Seed,
                                            int accountNumber)
        Finds the KeyPair for the path m/44'/148'/accountNumber' using the method described in SEP-0005.
        Parameters:
        bip39Seed - The output of BIP0039
        accountNumber - The number of the account
        Returns:
        KeyPair with secret
      • random

        public static KeyPair random()
        Generates a random Stellar keypair.
        Returns:
        a random Stellar keypair.
      • getAccountId

        public java.lang.String getAccountId()
        Returns the human readable account ID encoded in strkey.
      • getSecretSeed

        public char[] getSecretSeed()
        Returns the human readable secret seed encoded in strkey.
      • getPublicKey

        public byte[] getPublicKey()
      • getSignatureHint

        public org.stellar.sdk.xdr.SignatureHint getSignatureHint()
      • getXdrPublicKey

        public org.stellar.sdk.xdr.PublicKey getXdrPublicKey()
      • getXdrAccountId

        public org.stellar.sdk.xdr.AccountID getXdrAccountId()
      • getXdrSignerKey

        public org.stellar.sdk.xdr.SignerKey getXdrSignerKey()
      • fromXdrPublicKey

        public static KeyPair fromXdrPublicKey​(org.stellar.sdk.xdr.PublicKey key)
      • fromXdrSignerKey

        public static KeyPair fromXdrSignerKey​(org.stellar.sdk.xdr.SignerKey key)
      • sign

        public byte[] sign​(byte[] data)
        Sign the provided data with the keypair's private key.
        Parameters:
        data - The data to sign.
        Returns:
        signed bytes, null if the private key for this keypair is null.
      • signDecorated

        public org.stellar.sdk.xdr.DecoratedSignature signDecorated​(byte[] data)
        Sign the provided data with the keypair's private key and returns DecoratedSignature.
        Parameters:
        data - the data to sign
        Returns:
        DecoratedSignature
      • signPayloadDecorated

        public org.stellar.sdk.xdr.DecoratedSignature signPayloadDecorated​(byte[] signerPayload)
        Sign the provided payload data for payload signer where the input is the data being signed. Per the CAP-40 Signature spec DecoratedSignature.
        Parameters:
        signerPayload - the payload signers raw data to sign
        Returns:
        DecoratedSignature
      • verify

        public boolean verify​(byte[] data,
                              byte[] signature)
        Verify the provided data and signature match this keypair's public key.
        Parameters:
        data - The data that was signed.
        signature - The signature.
        Returns:
        True if they match, false otherwise.
        Throws:
        java.lang.RuntimeException
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object object)
        Overrides:
        equals in class java.lang.Object