Skip to content

Keypair

The Keypair class represents an Ed25519 keypair for signing SOMA transactions.

from soma_sdk import Keypair

Generate a new random Ed25519 keypair.

kp = Keypair.generate()

Returns: Keypair

kp = Keypair.generate()
print(kp.address()) # 0x...

Import a keypair from a secret key.

kp = Keypair.from_secret_key(secret)
ParameterTypeRequiredDefaultDescription
secretbytes | strYes32-byte secret key (bytes or hex string)

Returns: Keypair

Derive a keypair from a BIP-39 mnemonic phrase.

kp = Keypair.from_mnemonic("word1 word2 ... word12")
ParameterTypeRequiredDefaultDescription
mnemonicstrYesBIP-39 mnemonic phrase (12, 15, 18, 21, or 24 words)

Returns: Keypair

Get the SOMA address derived from this keypair’s public key.

addr = kp.address() # "0x..."

Returns: str — hex-encoded SOMA address

Sign transaction data bytes.

signature = kp.sign(tx_data_bytes)
ParameterTypeRequiredDefaultDescription
tx_data_bytesbytesYesBCS-serialized transaction data

Returns: bytes — Ed25519 signature

Export the secret key as a hex string.

secret = kp.to_secret_key() # hex string

Returns: str — hex-encoded 32-byte secret key