The simplest way to create a new keypair is to generate one randomly:
import software.sava.core.accounts.Signer;import software.sava.core.accounts.PublicKey;// Generate a random private keybyte[] privateKey = Signer.generatePrivateKeyBytes();// Create a signer from the private keySigner signer = Signer.createFromPrivateKey(privateKey);// Access the public keyPublicKey publicKey = signer.publicKey();System.out.println("Public Key: " + publicKey.toBase58());
If you already have a private key (for example, from a wallet file), you can load it:
import software.sava.core.encoding.Base58;// From Base58-encoded private keyString base58PrivateKey = "your-private-key-here";byte[] privateKey = Base58.decode(base58PrivateKey);Signer signer = Signer.createFromPrivateKey(privateKey);// From a 64-byte keypair arraybyte[] fullKeyPair = new byte[64]; // Load from file or other sourceSigner signerFromKeyPair = Signer.createFromKeyPair(fullKeyPair);
The SDK automatically validates keypairs when creating signers:
try { // This will throw an exception if the keypair is invalid Signer.validateKeyPair(privateKey, publicKey); System.out.println("Keypair is valid");} catch (IllegalStateException e) { System.err.println("Invalid keypair: " + e.getMessage());}