key

package
v1.16.37 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 29, 2025 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeriveKey

func DeriveKey(mnemonic []string, index uint32) (crypto.PrivateKey, error)

DeriveKey derives a key from a mnemonic at the given index

func ExportKey

func ExportKey(key *Key, format string, writer io.Writer) error

ExportKey exports a key in various formats

func GenerateMnemonic

func GenerateMnemonic(bitSize int) ([]string, error)

GenerateMnemonic generates a mnemonic phrase

Types

type Key

type Key struct {
	ID         ids.ID            `json:"id"`
	Type       string            `json:"type"` // "ed25519", "bls", "secp256k1"
	PrivateKey crypto.PrivateKey `json:"-"`
	PublicKey  crypto.PublicKey  `json:"publicKey"`
	Address    ids.ShortID       `json:"address"`
	Metadata   map[string]string `json:"metadata,omitempty"`
}

Key represents a cryptographic key with metadata

func LoadSoft added in v0.2.1

func LoadSoft(networkID uint32, keyPath string) (*Key, error)

LoadSoft loads a soft key from a file path

func (*Key) C added in v0.2.1

func (k *Key) C() string

C returns the Ethereum-style address (0x prefixed hex string)

func (*Key) PrivKeyHex added in v0.2.1

func (k *Key) PrivKeyHex() string

PrivKeyHex returns the private key as a hex string

type Keychain

type Keychain struct {
	// contains filtered or unexported fields
}

Keychain manages a collection of private keys for signing

func NewKeychain

func NewKeychain() *Keychain

NewKeychain creates a new keychain

func (*Keychain) Add

func (kc *Keychain) Add(privateKey crypto.PrivateKey) error

Add adds a private key to the keychain

func (*Keychain) Addresses

func (kc *Keychain) Addresses() []ids.ShortID

Addresses returns all addresses in the keychain

func (*Keychain) Get

func (kc *Keychain) Get(address ids.ShortID) (crypto.PrivateKey, error)

Get retrieves a private key by address

func (*Keychain) Sign

func (kc *Keychain) Sign(message []byte, address ids.ShortID) (crypto.Signature, error)

Sign signs a message with the key for the given address

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager handles key generation, storage, and retrieval

func NewManager

func NewManager(keyDir string) (*Manager, error)

NewManager creates a new key manager

func (*Manager) Delete

func (m *Manager) Delete(keyID ids.ID) error

Delete removes a key

func (*Manager) DeleteKey

func (m *Manager) DeleteKey(keyID ids.ID) error

DeleteKey removes a key from the manager

func (*Manager) ExportKey

func (m *Manager) ExportKey(keyID ids.ID) (string, error)

ExportKey exports a key's private key as hex string

func (*Manager) GenerateBLS

func (m *Manager) GenerateBLS() (*Key, *bls.SecretKey, error)

GenerateBLS generates a new BLS key

func (*Manager) GenerateEd25519

func (m *Manager) GenerateEd25519() (*Key, error)

GenerateEd25519 generates a new Ed25519 key

func (*Manager) GenerateKey

func (m *Manager) GenerateKey(keyType string) (*Key, error)

GenerateKey generates a new key of the specified type

func (*Manager) Get

func (m *Manager) Get(keyID ids.ID) (*Key, error)

Get retrieves a key by ID

func (*Manager) GetByAddress

func (m *Manager) GetByAddress(address ids.ShortID) (*Key, error)

GetByAddress retrieves a key by address

func (*Manager) GetKey

func (m *Manager) GetKey(keyID ids.ID) (*Key, error)

GetKey retrieves a key by ID

func (*Manager) ImportKey

func (m *Manager) ImportKey(privateKey crypto.PrivateKey, keyType string) (*Key, error)

ImportKey imports a key with the given private key and type

func (*Manager) ImportPrivateKey

func (m *Manager) ImportPrivateKey(privateKey crypto.PrivateKey) (*Key, error)

ImportPrivateKey imports an existing private key

func (*Manager) List

func (m *Manager) List() []*Key

List returns all keys

func (*Manager) ListKeys

func (m *Manager) ListKeys() []*Key

ListKeys returns all keys

func (*Manager) Save

func (m *Manager) Save(keyID ids.ID) error

Save persists a key to disk

func (*Manager) SaveAll

func (m *Manager) SaveAll() error

SaveAll persists all keys to disk

func (*Manager) SaveKey

func (m *Manager) SaveKey(key *Key) error

SaveKey saves a key to disk

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL