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 ¶
- Variables
- func EnsureKeystoreDir(dir string) (string, error)
- type KeyInfo
- type Store
- func (s *Store) Default() (string, error)
- func (s *Store) Delete(name string) error
- func (s *Store) Dir() string
- func (s *Store) Get(name string) (*KeyInfo, error)
- func (s *Store) Has(name string) bool
- func (s *Store) List() ([]string, error)
- func (s *Store) Put(name string, ki *KeyInfo) error
- func (s *Store) ReadRaw(name string) ([]byte, error)
- func (s *Store) SetDefault(name string) error
Constants ¶
This section is empty.
Variables ¶
var ( ErrKeyNotFound = errors.New("keystore: key not found") ErrBadPassphrase = errors.New("keystore: bad passphrase") )
Errors.
Functions ¶
func EnsureKeystoreDir ¶
EnsureKeystoreDir creates dir with 0700 perms if missing. Returns the absolute path.
Types ¶
type KeyInfo ¶
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 ¶
MarshalJSON renders PrivateKey as base64, matching Lotus.
func (*KeyInfo) UnmarshalJSON ¶
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 ¶
Open opens an existing keystore at dir, creating the directory if it doesn't exist. Passphrase is required for every operation.
func (*Store) ReadRaw ¶
ReadRaw returns the raw envelope file for `name`, mostly for tests asserting on-disk encryption.
func (*Store) SetDefault ¶
SetDefault marks a key as the default by writing a symlink-style pointer file `default`.