Skip to main content

Signer

Signer is an interface that provides functionality for signing transactions. The signer can be created from a local keybase, or from a bip39 mnemonic phrase.

Useful types and functions when using the Signer can be found below.

type Signer

Signer provides an interface for signing transactions.

type Signer interface {
Sign(SignCfg) (*std.Tx, error) // Signs a transaction and returns a signed tx ready for broadcasting.
Info() keys.Info // Returns key information, including the address.
Validate() error // Checks whether the signer is properly configured.
}

type SignCfg

SignCfg provides the signing configuration, containing the unsigned transaction data, account number, and account sequence.

type SignCfg struct {
UnsignedTX std.Tx
SequenceNumber uint64
AccountNumber uint64
}

type SignerFromKeybase

SignerFromKeybase represents a signer created from a Keybase.

type SignerFromKeybase struct {
Keybase keys.Keybase // Stores keys in memory or on disk
Account string // Account name or bech32 format
Password string // Password for encryption
ChainID string // Chain ID for transaction signing
}

func (SignerFromKeybase) Info

func (s SignerFromKeybase) Info() keys.Info

Info gets keypair information.

func (SignerFromKeybase) Sign

func (s SignerFromKeybase) Sign(cfg SignCfg) (*std.Tx, error)

Sign implements the Signer interface for SignerFromKeybase.

func (SignerFromKeybase) Validate

func (s SignerFromKeybase) Validate() error

Validate checks if the signer is properly configured.

func SignerFromBip39

func SignerFromBip39(mnemonic string, chainID string, passphrase string, account uint32, index uint32) (Signer, error)

SignerFromBip39 creates a Signer from an in-memory keybase with a single default account, derived from the given mnemonic. This can be useful in scenarios where storing private keys in the filesystem isn't feasible, or for generating a signer for testing.

Using keys.NewKeyBaseFromDir() to get a keypair from local storage is recommended where possible, as it is more secure.