keystore

package
v1.9.2 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2026 License: Apache-2.0, MIT Imports: 13 Imported by: 0

Documentation

Overview

Package keystore provides a disk-backed, passphrase-encrypted key store.

On-disk layout: one JSON file per key, name is the key's identifier (`wallet-<address>`), contents are AES-GCM-wrapped CBOR-encoded crypto.PrivateKey from go-state-types/crypto plus the SigType.

The format is intentionally close to Lotus' lib/keystore: a JSON object `{Type: "bls"|"secp256k1"|"delegated", PrivateKey: <base64>}` is AES-GCM-encrypted under a key derived from the user's passphrase via scrypt. The wrapping envelope is itself JSON:

{"v":1,"salt":<base64>,"nonce":<base64>,"ct":<base64>}

This means Lantern keystores cannot be opened by raw Lotus, but the underlying KeyInfo shape is identical and a one-line export tool can produce Lotus-compatible KeyInfo blobs (see Wallet.Export).

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrKeyNotFound   = errors.New("keystore: key not found")
	ErrBadPassphrase = errors.New("keystore: bad passphrase")
)

Errors.

Functions

func EnsureKeystoreDir

func EnsureKeystoreDir(dir string) (string, error)

EnsureKeystoreDir creates dir with 0700 perms if missing. Returns the absolute path.

Types

type KeyInfo

type KeyInfo struct {
	Type       string `json:"Type"`
	PrivateKey []byte `json:"PrivateKey"`
}

KeyInfo is the in-memory representation of a stored key. The PrivateKey bytes are raw scalar (secp/delegated: 32-byte d, BLS: 32-byte scalar). Type matches go-state-types/crypto.SigType values.

JSON shape matches Lotus' KeyInfo (lib/keystore) so Export/Import is directly compatible.

func (KeyInfo) MarshalJSON

func (k KeyInfo) MarshalJSON() ([]byte, error)

MarshalJSON renders PrivateKey as base64, matching Lotus.

func (*KeyInfo) UnmarshalJSON

func (k *KeyInfo) UnmarshalJSON(b []byte) error

UnmarshalJSON accepts either a base64 string (Lotus shape) or a raw byte-array (Go default).

type Store

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

Store is a passphrase-protected, disk-backed key store. Concurrent callers can safely share a *Store.

func Open

func Open(dir, passphrase string) (*Store, error)

Open opens an existing keystore at dir, creating the directory if it doesn't exist. Passphrase is required for every operation.

func (*Store) Default

func (s *Store) Default() (string, error)

Default returns the current default key name, or "" if unset.

func (*Store) Delete

func (s *Store) Delete(name string) error

Delete removes name.

func (*Store) Dir

func (s *Store) Dir() string

Dir returns the on-disk path.

func (*Store) Get

func (s *Store) Get(name string) (*KeyInfo, error)

Get returns the KeyInfo stored under name.

func (*Store) Has

func (s *Store) Has(name string) bool

Has returns true if name exists in the store.

func (*Store) List

func (s *Store) List() ([]string, error)

List enumerates all key names in the store.

func (*Store) Put

func (s *Store) Put(name string, ki *KeyInfo) error

Put writes ki under name. Overwrites any existing entry.

func (*Store) ReadRaw

func (s *Store) ReadRaw(name string) ([]byte, error)

ReadRaw returns the raw envelope file for `name`, mostly for tests asserting on-disk encryption.

func (*Store) SetDefault

func (s *Store) SetDefault(name string) error

SetDefault marks a key as the default by writing a symlink-style pointer file `default`.

Jump to

Keyboard shortcuts

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