Private Keys
The Kotlin SDK supports vanilla account schemes such as ED25519
, SECP256K1
and SECP256R1
.
In this chapter, we’ll explore account creation, restoration and usage for these schemes
Creating new Accounts
All account types in the Kotlin SDK extend from a common Account
abstract class.
This class provides a create
static method that allows you to create a new account of a specified type and defaults to SignatureScheme.ED25519
if no type is specified.
You can also specify the signature scheme as follows:
You can also create accounts of a specific type directly by invoking the generate
method on the respective classes:
Importing an existing Account
In case you already have existing account credentials like a Bech32 encoded private key or passphrase that you'd like to import and use, there's an overloaded import
static method on the Accounts
class. Pass in either the private key string or the passphrase.
For a private key:
For a passphrase:
Signing Messages
You can sign messages using the sign
method on the Account
class. This returns a Result<ByteArray, Exception>
, so you can handle success and failure cases appropriately. Here's an example of signing a message:
Signature Verification
You can verify signatures using the verify
method on the Account
class. This returns a Result<Boolean, Exception>
, so you can handle success and failure cases appropriately. Here's an example of verifying a signature:
The SDK extensively uses the Result
type to model success and failure cases. This ensures you handle both outcomes explicitly, making your code more predictable and safer by default. For more details on response handling, check out the response handling chapter.