sign

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2026 License: MIT Imports: 9 Imported by: 0

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

View Source
var ErrUnsupportedAlgorithm = errors.New("sign: unsupported algorithm")

ErrUnsupportedAlgorithm is returned for an algorithm a backend can't handle.

Functions

func EthAddress

func EthAddress(s Signer) (common.Address, error)

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.
const (
	AlgSecp256k1 Algorithm = "secp256k1"
	AlgEd25519   Algorithm = "ed25519"
)

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.

func (*KeySigner) Algorithm

func (s *KeySigner) Algorithm() Algorithm

func (*KeySigner) Close

func (s *KeySigner) Close() error

func (*KeySigner) PublicKey

func (s *KeySigner) PublicKey() []byte

func (*KeySigner) Sign

func (s *KeySigner) Sign(_ context.Context, message []byte) ([]byte, error)

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.

Jump to

Keyboard shortcuts

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