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 and the serviceoffer-controller (sub-agent wallets) so there is exactly one implementation of the wallet crypto path.
Index ¶
- Constants
- func AddressFromPublicKey(pubKey []byte) string
- func DecryptV3(keystoreJSON []byte, password string) ([]byte, error)
- func EncryptV3(privKey, pubKey []byte, password string) ([]byte, string, error)
- func GenerateKeypair() (privKeyBytes, pubKeyUncompressed []byte, err error)
- func RandomPassword(length int) (string, error)
- func ToChecksumAddress(addr string) string
- func Zero(b []byte)
- type CipherParams
- type KDFParams
- type Material
- type V3
- type V3Crypto
Constants ¶
const ( ScryptN = 262144 ScryptR = 8 ScryptP = 1 ScryptDKLen = 32 )
scrypt parameters matching go-ethereum's "standard" defaults.
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 ¶
AddressFromPublicKey computes the EIP-55 checksummed, 0x-prefixed Ethereum address of a 64-byte uncompressed public key (no 0x04 prefix).
func DecryptV3 ¶
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 ¶
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 ¶
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 ¶
RandomPassword returns a cryptographically random alphanumeric (a-z, A-Z, 0-9) password of the given length.
func ToChecksumAddress ¶
ToChecksumAddress applies EIP-55 mixed-case checksum encoding to a hex address (with or without 0x prefix) and returns it 0x-prefixed.
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 ¶
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.