Files
zeekay 1943f1c093 Hanzo Commerce
Multi-tenant commerce and billing: orders, subscriptions, invoices, plans,
usage metering and a credit ledger. One Go binary. MIT OR Apache-2.0.

Claude-Session: https://claude.ai/code/session_01SAtaDFm8VDiWrhYHNNtxMw
2026-09-23 21:52:16 -07:00

36 lines
1.1 KiB
Go

package wallet
import (
"crypto/ecdsa"
"crypto/rand"
"encoding/hex"
"strings"
luxcrypto "github.com/luxfi/crypto"
"github.com/hanzoai/commerce/models/blockchains"
)
// Ethereum key generation lives here (not in luxfi/cevm) because the
// primitives rely only on luxfi/crypto (secp256k1 + keccak256 address
// derivation). The luxfi/cevm sub-module pulls the heavier luxfi/geth
// JSON-RPC client; it is not needed for generating accounts.
func init() {
for _, typ := range []blockchains.Type{blockchains.EthereumType, blockchains.EthereumRopstenType} {
RegisterKeyGen(typ, ethereumKeyGen)
}
}
func ethereumKeyGen(_ blockchains.Type) (priv, pub, address string, err error) {
sk, err := ecdsa.GenerateKey(luxcrypto.S256(), rand.Reader)
if err != nil {
return "", "", "", err
}
// Drop the leading 0x04 uncompressed-marker byte on the public key, matching
// the format previously produced by luxfi/cevm.GenerateKeyPair.
priv = hex.EncodeToString(luxcrypto.FromECDSA(sk))
pub = hex.EncodeToString(luxcrypto.FromECDSAPub(&sk.PublicKey)[1:])
address = strings.ToLower(luxcrypto.PubkeyToAddress(sk.PublicKey).Hex())
return priv, pub, address, nil
}