Help us shape the future of Go! Take the 2026 Go Developer Survey

keystore

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package keystore mints secp256k1 wallets and encrypts/decrypts them as Web3 Secret Storage v3 keystores (scrypt + AES-128-CTR), the format the remote-signer loads. It is shared by the Hermes runtime, the serviceoffer-controller (sub-agent wallets) and the deprecated OpenClaw runtime so there is exactly one implementation of the wallet crypto path.

Index

Constants

View Source
const (
	ScryptN     = 262144
	ScryptR     = 8
	ScryptP     = 1
	ScryptDKLen = 32
)

scrypt parameters matching go-ethereum's "standard" defaults.

View Source
const PasswordLength = 32

PasswordLength is the length of passwords minted by GenerateInMemory and the runtime wallet provisioners.

Variables

This section is empty.

Functions

func AddressFromPublicKey

func AddressFromPublicKey(pubKey []byte) string

AddressFromPublicKey computes the EIP-55 checksummed, 0x-prefixed Ethereum address of a 64-byte uncompressed public key (no 0x04 prefix).

func DecryptV3

func DecryptV3(keystoreJSON []byte, password string) ([]byte, error)

DecryptV3 decrypts a scrypt/AES-128-CTR V3 keystore and returns the raw private key bytes. It returns an error on a MAC mismatch (wrong password or corrupted keystore).

func EncryptV3

func EncryptV3(privKey, pubKey []byte, password string) ([]byte, string, error)

EncryptV3 encrypts a private key using the Web3 Secret Storage v3 format: scrypt KDF (N=262144, r=8, p=1) + AES-128-CTR. Returns the JSON-encoded keystore and its UUID.

func GenerateKeypair

func GenerateKeypair() (privKeyBytes, pubKeyUncompressed []byte, err error)

GenerateKeypair creates a random secp256k1 private key using crypto/rand. Returns the 32-byte private key and the 64-byte uncompressed public key (X || Y, without the 0x04 prefix).

func RandomPassword

func RandomPassword(length int) (string, error)

RandomPassword returns a cryptographically random alphanumeric (a-z, A-Z, 0-9) password of the given length.

func ToChecksumAddress

func ToChecksumAddress(addr string) string

ToChecksumAddress applies EIP-55 mixed-case checksum encoding to a hex address (with or without 0x prefix) and returns it 0x-prefixed.

func Zero

func Zero(b []byte)

Zero overwrites b with zeros (best-effort scrubbing of key material).

Types

type CipherParams

type CipherParams struct {
	IV string `json:"iv"`
}

CipherParams holds the AES-CTR IV.

type KDFParams

type KDFParams struct {
	DKLen int    `json:"dklen"`
	N     int    `json:"n"`
	R     int    `json:"r"`
	P     int    `json:"p"`
	Salt  string `json:"salt"`
}

KDFParams holds the scrypt parameters.

type Material

type Material struct {
	Address      string // EIP-55 checksummed
	PublicKey    string // 0x04 || X || Y (130 hex chars)
	KeystoreUUID string // V3 keystore "id" field
	KeystoreJSON []byte // Encrypted V3 keystore document
	Password     string // Random 32-char password
}

Material bundles the in-memory output of GenerateInMemory: a freshly minted secp256k1 wallet encrypted as a Web3 V3 keystore plus the password needed to decrypt it. Used by callers that persist the keystore via mechanisms other than a host-side PVC (e.g. a K8s Secret created by an in-cluster controller).

func GenerateInMemory

func GenerateInMemory() (*Material, error)

GenerateInMemory mints a fresh wallet keypair, V3-encrypts it in memory with a random password, and returns everything the caller needs to persist the keystore wherever it wants.

type V3

type V3 struct {
	Address string   `json:"address"` // hex address without 0x prefix
	Crypto  V3Crypto `json:"crypto"`
	ID      string   `json:"id"`
	Version int      `json:"version"`
}

V3 is a keystore document matching the Web3 Secret Storage Definition v3.

type V3Crypto

type V3Crypto struct {
	Cipher       string       `json:"cipher"`
	CipherText   string       `json:"ciphertext"`
	CipherParams CipherParams `json:"cipherparams"`
	KDF          string       `json:"kdf"`
	KDFParams    KDFParams    `json:"kdfparams"`
	MAC          string       `json:"mac"`
}

V3Crypto is the "crypto" section of a V3 keystore.

Jump to

Keyboard shortcuts

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