Documentation
¶
Index ¶
- Variables
- func AddressFromPublicKey(pub ed25519.PublicKey) (a2al.Address, error)
- func CompactSignedMessageHash(message string) []byte
- func EIP191Hash(message string) []byte
- func EthPubKeyToAddress20(pub *secp256k1.PublicKey) ([20]byte, error)
- func GenerateEd25519() (ed25519.PrivateKey, ed25519.PublicKey, error)
- func GenerateSecp256k1PrivateKey() (*secp256k1.PrivateKey, error)
- func Hash160(b []byte) [20]byte
- func Keccak256(b []byte) []byte
- func RecoverEthereumPubKey(message string, sig65 []byte) (*secp256k1.PublicKey, error)
- func Secp256k1PubKeyToHash160(pub *secp256k1.PublicKey, compressed bool) ([20]byte, error)
- func SignCompactMessage(priv *secp256k1.PrivateKey, message string, compressedPubKey bool) ([]byte, error)
- func SignDetached(priv ed25519.PrivateKey, message []byte) []byte
- func SignEIP191(priv *secp256k1.PrivateKey, message string) ([]byte, error)
- func VerifyCompactMessageSignature(addr20 [20]byte, message string, sig65 []byte) error
- func VerifyDetached(pub ed25519.PublicKey, message, sig []byte) bool
- func VerifyEIP191Signature(addr20 [20]byte, message string, sig65 []byte) error
- func Wipe(b []byte)
- type EncryptedKeyStore
- func (e *EncryptedKeyStore) Ed25519PrivateKey(address a2al.Address) (ed25519.PrivateKey, error)
- func (e *EncryptedKeyStore) Generate(keyType KeyType) (PrivateKey, error)
- func (e *EncryptedKeyStore) List() ([]a2al.Address, error)
- func (e *EncryptedKeyStore) Load() error
- func (e *EncryptedKeyStore) PublicKey(address a2al.Address) ([]byte, error)
- func (e *EncryptedKeyStore) Sign(address a2al.Address, data []byte) ([]byte, error)
- type KeyStore
- type KeyType
- type PrivateKey
Constants ¶
This section is empty.
Variables ¶
var ( // ErrIdentityExists is returned when Generate is called but a key is already loaded. ErrIdentityExists = errors.New("a2al/crypto: identity already exists") // ErrNoIdentity is returned when signing is requested before Load or Generate. ErrNoIdentity = errors.New("a2al/crypto: no identity loaded") // ErrWrongPassphrase is returned when the ciphertext cannot be authenticated. ErrWrongPassphrase = errors.New("a2al/crypto: wrong passphrase or corrupted blob") )
Functions ¶
func AddressFromPublicKey ¶
AddressFromPublicKey derives the A2AL Address for an Ed25519 public key (spec §6.1).
func CompactSignedMessageHash ¶
CompactSignedMessageHash returns double-SHA256 of the varint-prefixed magic + message, matching the Bitcoin Core / Paralism signmessage format.
func EIP191Hash ¶
EIP191Hash is Keccak256("\x19Ethereum Signed Message:\n" + len + message) per EIP-191.
func EthPubKeyToAddress20 ¶
EthPubKeyToAddress20 derives the 20-byte Ethereum address from an uncompressed secp256k1 public key.
func GenerateEd25519 ¶
func GenerateEd25519() (ed25519.PrivateKey, ed25519.PublicKey, error)
GenerateEd25519 returns a new Ed25519 key pair (private, public).
func GenerateSecp256k1PrivateKey ¶
func GenerateSecp256k1PrivateKey() (*secp256k1.PrivateKey, error)
GenerateSecp256k1PrivateKey creates a random secp256k1 private key.
func RecoverEthereumPubKey ¶
RecoverEthereumPubKey recovers the signer public key from an EIP-191 signature (r||s||v, v=27|28).
func Secp256k1PubKeyToHash160 ¶
Secp256k1PubKeyToHash160 returns HASH160 of the compressed or uncompressed secp256k1 pubkey serialization.
func SignCompactMessage ¶
func SignCompactMessage(priv *secp256k1.PrivateKey, message string, compressedPubKey bool) ([]byte, error)
SignCompactMessage signs message using the Bitcoin/Paralism compact signmessage format. Returns a 65-byte compact signature (recovery||r||s).
func SignDetached ¶
func SignDetached(priv ed25519.PrivateKey, message []byte) []byte
SignDetached signs message with the private key (Ed25519).
func SignEIP191 ¶
func SignEIP191(priv *secp256k1.PrivateKey, message string) ([]byte, error)
SignEIP191 signs message with Ethereum personal_sign semantics. Returns 65-byte r||s||v (v ∈ {27,28}).
func VerifyCompactMessageSignature ¶
VerifyCompactMessageSignature verifies a compact signature against CompactSignedMessageHash(message) and checks that the recovered address matches addr20 (HASH160 of pubkey).
func VerifyDetached ¶
VerifyDetached verifies an Ed25519 signature.
func VerifyEIP191Signature ¶
VerifyEIP191Signature checks that sig is a valid personal_sign for message from addr20.
func Wipe ¶
func Wipe(b []byte)
Wipe overwrites b with zeros. Use in defer to clear sensitive key material. In practice the Go compiler does not eliminate these stores because callers pass slices that remain reachable via defer. If a future Go version proves more aggressive, replace with a runtime.KeepAlive(b) tail call or use golang.org/x/sys/unix.Mlock / crypto/subtle equivalents. TODO: revisit when Go provides an official "secure zero" intrinsic.
Types ¶
type EncryptedKeyStore ¶
type EncryptedKeyStore struct {
// contains filtered or unexported fields
}
EncryptedKeyStore stores a single Ed25519 identity in a2al.Storage as an Argon2id + XChaCha20-Poly1305 encrypted blob. Passphrase is required to encrypt/decrypt.
func NewEncryptedKeyStore ¶
func NewEncryptedKeyStore(stg a2al.Storage, blobKey string, passphrase []byte) *EncryptedKeyStore
NewEncryptedKeyStore creates a keystore. blobKey is the Storage key (e.g. "identity.ed25519"); if empty, defaultIdentityStore is used.
func (*EncryptedKeyStore) Ed25519PrivateKey ¶
func (e *EncryptedKeyStore) Ed25519PrivateKey(address a2al.Address) (ed25519.PrivateKey, error)
Ed25519PrivateKey returns a copy of the decrypted identity for QUIC/TLS (Phase 2). Requires Load or Generate first.
func (*EncryptedKeyStore) Generate ¶
func (e *EncryptedKeyStore) Generate(keyType KeyType) (PrivateKey, error)
Generate creates a new Ed25519 identity and encrypts it to Storage. Fails with ErrIdentityExists if a key is already in memory.
func (*EncryptedKeyStore) List ¶
func (e *EncryptedKeyStore) List() ([]a2al.Address, error)
List implements KeyStore.
func (*EncryptedKeyStore) Load ¶
func (e *EncryptedKeyStore) Load() error
Load reads and decrypts the identity from Storage. Missing blob leaves the store empty (no error).
type KeyStore ¶
type KeyStore interface {
Generate(keyType KeyType) (PrivateKey, error)
Sign(address a2al.Address, data []byte) ([]byte, error)
PublicKey(address a2al.Address) ([]byte, error)
List() ([]a2al.Address, error)
}
KeyStore persists signing keys and performs signatures (spec §1.6).
type KeyType ¶
type KeyType byte
KeyType identifies the asymmetric algorithm used for an Agent identity.
const ( // KeyTypeEd25519 is the Phase 1 default (spec §6.1). KeyTypeEd25519 KeyType = 0x01 )
type PrivateKey ¶
type PrivateKey []byte
PrivateKey is Ed25519 private key material (64 bytes, per crypto/ed25519).