Documentation
¶
Overview ¶
Package sign abstracts signing identities behind a pluggable, algorithm-aware interface — raw in-memory keys for clients/CLI/tests, KMS backends in production (custody's AWS/GCP signers satisfy this interface unchanged). The blockchain adapters take a Signer at construction and apply the chain-specific framing (EVM keccak + recovery id, BTC DER + sighash byte, XRPL encode-for-multisigning) themselves.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrUnsupportedAlgorithm = errors.New("sign: unsupported algorithm")
ErrUnsupportedAlgorithm is returned for an algorithm a backend can't handle.
Functions ¶
func EthAddress ¶
EthAddress derives the Ethereum address from a secp256k1 Signer.
func SignEthDigest ¶
func SignEthDigest(ctx context.Context, s Signer, digest []byte, expectedAddr common.Address) ([]byte, error)
SignEthDigest signs a 32-byte digest with a secp256k1 Signer and returns the 65-byte Ethereum form R || S || V with V ∈ {0,1} (what crypto.Sign produces and crypto.SigToPub expects). Callers that need Solidity's V ∈ {27,28} shift at the contract boundary. expectedAddr disambiguates the recovery id.
Types ¶
type Algorithm ¶
type Algorithm string
Algorithm names the curve/scheme. The Sign output format is algorithm-specific:
- AlgSecp256k1: DER ECDSA, low-S normalized; caller passes a 32-byte digest.
- AlgEd25519: raw 64-byte signature; caller passes the message.
type KeySigner ¶
type KeySigner struct {
// contains filtered or unexported fields
}
KeySigner is a Signer backed by a raw private key held in memory — for clients, the CLI, and tests. Production prefers a KMS-backed Signer.
func NewKeySignerFromECDSA ¶
func NewKeySignerFromECDSA(key *ecdsa.PrivateKey) *KeySigner
NewKeySignerFromECDSA wraps a secp256k1 private key.
func NewKeySignerFromEd25519 ¶
func NewKeySignerFromEd25519(key ed25519.PrivateKey) (*KeySigner, error)
NewKeySignerFromEd25519 wraps an ed25519 private key.
type Signer ¶
type Signer interface {
Algorithm() Algorithm
// PublicKey returns the raw public key bytes:
// - secp256k1: 33-byte compressed SEC1 (0x02/0x03 || X)
// - ed25519: 32-byte raw
PublicKey() []byte
Sign(ctx context.Context, message []byte) ([]byte, error)
Close() error
}
Signer is implemented by every signing backend. Implementations are safe for concurrent Sign calls; construct once, share, Close at shutdown.