signer

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package signer provides signing abstractions for Filecoin and Ethereum transactions.

This is a leaf package. It defines separate capabilities for native Filecoin messages, Ethereum transactions, and Storage EIP-712 authorizations:

  • Signer signs native Filecoin messages.
  • EVMSigner adds Ethereum transaction signing.
  • HashSigner signs pre-computed 32-byte digests.
  • StorageSigner combines an EVM address with HashSigner without requiring native message or transaction signing.

The package provides concrete implementations:

  • Secp256k1Signer: dual-protocol signer using a single secp256k1 key for both Filecoin (blake2b) and Ethereum (keccak256) signing.
  • BLSSigner: Filecoin-only BLS signature support.

Consumers should accept the interface types; this package returns concrete types per Go convention.

External transaction signers

Standalone contract services accept custom EVMSigner implementations. EVMSigner.Transactor must return non-nil transaction options on success; returning an error aborts the write before nonce acquisition or broadcast.

Raw hash signing

HashSigner and StorageSigner are extension points for KMS/HSM-backed keys, remote signers, and decorators. A HashSigner receives only a digest, so it cannot reconstruct or validate the original EIP-712 domain and message. Implementations should use a dedicated authorization key and restrict access to trusted callers. Do not expose HashSigner as a general-purpose signing oracle.

Index

Constants

This section is empty.

Variables

View Source
var ErrUnsupportedSigner = errors.New("signer: raw hash signing not supported by this signer")

ErrUnsupportedSigner is returned when an EVMSigner does not implement HashSigner.

Functions

func SignHash

func SignHash(s EVMSigner, hash []byte) ([]byte, error)

SignHash signs a pre-computed 32-byte hash using the underlying secp256k1 key, returning a 65-byte R‖S‖V signature. User code should prefer one of the higher-level APIs that constructs and domain-separates the message.

SignHash returns ErrUnsupportedSigner when s does not implement HashSigner. Wrappers and external signers are supported when they expose that capability.

Types

type BLSSigner

type BLSSigner struct {
	// contains filtered or unexported fields
}

BLSSigner implements Signer backed by a BLS12-381 private key. BLS keys can only sign Filecoin messages; EVM operations are not supported.

func NewBLSSigner

func NewBLSSigner(raw []byte) (*BLSSigner, error)

NewBLSSigner creates a Filecoin-only signer from raw BLS secret key bytes in big-endian order (the native blst serialization format, as produced by blst.SecretKey.Serialize). For Lotus-exported keys (little-endian), use FromLotusExport which handles the byte-order conversion automatically.

func (*BLSSigner) FilecoinAddress

func (s *BLSSigner) FilecoinAddress() address.Address

FilecoinAddress returns the Filecoin BLS protocol address.

func (*BLSSigner) Sign

func (s *BLSSigner) Sign(msg []byte) (*crypto.Signature, error)

Sign produces a BLS signature over the raw message bytes. Unlike secp256k1, BLS signing does not pre-hash the message.

type EVMSigner

type EVMSigner interface {
	Signer

	// EVMAddress returns the Ethereum address derived from this key.
	EVMAddress() common.Address

	// Transactor returns go-ethereum TransactOpts bound to the given chain ID.
	// On success, the returned options must be non-nil.
	Transactor(chainID *big.Int) (*bind.TransactOpts, error)
}

EVMSigner extends Signer with Ethereum/FEVM transaction signing. External transaction signers can implement it for standalone services. The built-in implementation supports secp256k1 keys.

func AsEVM

func AsEVM(s Signer) (EVMSigner, bool)

AsEVM checks whether a Signer can also sign EVM transactions. Returns nil, false for key types that don't support EVM (e.g., BLS).

type HashSigner added in v0.5.1

type HashSigner interface {
	SignHash(hash []byte) ([]byte, error)
}

HashSigner signs a pre-computed 32-byte digest and returns a 65-byte Ethereum R‖S‖V signature. External signers can implement it. V may be encoded as 0/1 or 27/28. Implementations must return an error for any other digest length.

This is a high-trust capability because the signer receives only a digest and cannot verify the original message or its domain separation. External implementations should dedicate the key to the intended SDK authorization flows and restrict access instead of exposing a general-purpose signing oracle.

type Secp256k1Signer

type Secp256k1Signer struct {
	// contains filtered or unexported fields
}

Secp256k1Signer implements EVMSigner backed by a secp256k1 private key. It can sign both Filecoin messages (blake2b hash) and Ethereum/FEVM transactions (keccak256 hash) from a single key.

Private-key lifecycle is the caller's responsibility: the SDK does not provide an in-place wipe primitive. To bound the in-memory exposure of the key, hold the signer for as short a lifetime as the workload allows and let it be garbage-collected.

func NewSecp256k1Signer

func NewSecp256k1Signer(key *ecdsa.PrivateKey) (*Secp256k1Signer, error)

NewSecp256k1Signer creates a dual-protocol signer from a go-ethereum ECDSA private key. The key is deep-copied so the signer owns an independent copy; the caller may safely zero or mutate the original.

func NewSecp256k1SignerFromBytes

func NewSecp256k1SignerFromBytes(raw []byte) (*Secp256k1Signer, error)

NewSecp256k1SignerFromBytes creates a dual-protocol signer from a raw 32-byte private key scalar. Shorter inputs are left-padded to 32 bytes to handle big.Int.Bytes() output that may drop leading zeros.

func (*Secp256k1Signer) EVMAddress

func (s *Secp256k1Signer) EVMAddress() common.Address

EVMAddress returns the Ethereum address derived from the public key.

func (*Secp256k1Signer) FilecoinAddress

func (s *Secp256k1Signer) FilecoinAddress() address.Address

FilecoinAddress returns the Filecoin secp256k1 protocol address.

func (*Secp256k1Signer) Sign

func (s *Secp256k1Signer) Sign(msg []byte) (*crypto.Signature, error)

Sign produces a Filecoin-native secp256k1 signature. The message is hashed with blake2b-256 before signing, and the result is in R|S|V format (65 bytes).

func (*Secp256k1Signer) SignHash

func (s *Secp256k1Signer) SignHash(hash []byte) ([]byte, error)

SignHash signs a pre-computed 32-byte hash using the secp256k1 key. Returns 65-byte R‖S‖V signature.

SignHash implements HashSigner. Raw hash signing bypasses domain separation, so callers should prefer a higher-level API that constructs the message and use a dedicated key or access policy for this capability.

func (*Secp256k1Signer) Transactor

func (s *Secp256k1Signer) Transactor(chainID *big.Int) (*bind.TransactOpts, error)

Transactor returns bind.TransactOpts for signing Ethereum/FEVM transactions on the given chain. The returned opts embed their own key copy so they remain valid for the lifetime of the opts independent of the signer.

type Signer

type Signer interface {
	// FilecoinAddress returns the Filecoin protocol address for this key.
	FilecoinAddress() address.Address

	// Sign produces a Filecoin-native signature over msg.
	Sign(msg []byte) (*crypto.Signature, error)
}

Signer signs native Filecoin messages. External key stores, remote signers, and decorators can implement it.

func FromLotusExport

func FromLotusExport(exported string) (Signer, error)

FromLotusExport creates a Signer from a Lotus wallet export string. The export format is a hex-encoded JSON object with Type and PrivateKey fields, as produced by `lotus wallet export`.

BLS private keys from Lotus are little-endian (filecoin-ffi convention), while blst expects big-endian. This function handles the byte-order conversion automatically.

type StorageSigner added in v0.5.1

type StorageSigner interface {
	EVMAddress() common.Address
	HashSigner
}

StorageSigner signs Storage EIP-712 authorizations without requiring native Filecoin signing or Ethereum transaction submission. External signers can implement it. EVMAddress must return the address derived from the key used by HashSigner. Storage operations may call SignHash concurrently; implementations must be safe for concurrent use or serialize calls internally.

Jump to

Keyboard shortcuts

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