wallet

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2026 License: MIT Imports: 25 Imported by: 0

Documentation

Overview

Package wallet handles private key loading and management.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetAddress

func GetAddress(privateKey *ecdsa.PrivateKey) string

GetAddress returns the Ethereum address for a private key.

func GetSolanaAddress added in v0.2.3

func GetSolanaAddress(privateKey solana.PrivateKey) string

GetSolanaAddress returns the base58-encoded public key for a Solana private key.

func LoadFromHex

func LoadFromHex(hexKey string) (*ecdsa.PrivateKey, error)

LoadFromHex loads a private key from a hex string. Accepts with or without 0x prefix.

func LoadFromKeystore

func LoadFromKeystore(path string) (*ecdsa.PrivateKey, error)

LoadFromKeystore loads a private key from a Web3 Secret Storage keystore file. Prompts for password interactively.

func LoadFromStdin

func LoadFromStdin() (*ecdsa.PrivateKey, error)

LoadFromStdin reads a private key from stdin. Expects hex-encoded key on a single line.

func LoadPrivateKey

func LoadPrivateKey(keystorePath, hexKey string, fromStdin bool) (*ecdsa.PrivateKey, error)

LoadPrivateKey loads a private key from various sources. Priority: keystore file → hex key (flag/env) → stdin

Parameters:

  • keystorePath: Path to Web3 Secret Storage keystore file
  • hexKey: Hex-encoded private key (with or without 0x prefix)
  • fromStdin: If true and no other source, read from stdin

func LoadSolanaKeypair added in v0.2.3

func LoadSolanaKeypair(path string) (solana.PrivateKey, error)

LoadSolanaKeypair loads a Solana keypair from a file. Supports JSON array format (Solana CLI) and base58 encoded private keys.

func LoadSolanaKeypairFromBase58 added in v0.2.3

func LoadSolanaKeypairFromBase58(base58Key string) (solana.PrivateKey, error)

LoadSolanaKeypairFromBase58 loads a Solana keypair from a base58 string.

func PromptPassword

func PromptPassword(prompt string) (string, error)

PromptPassword prompts for a password without echoing to terminal.

Types

type EVMSigner added in v0.2.3

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

EVMSigner implements the Signer interface for EVM-compatible chains. It uses EIP-712 typed data signing for EIP-3009 TransferWithAuthorization.

func NewEVMSigner added in v0.2.3

func NewEVMSigner(key *ecdsa.PrivateKey) *EVMSigner

NewEVMSigner creates a new EVM signer from an ECDSA private key. Panics if key is nil (programming error).

func (*EVMSigner) Address added in v0.2.3

func (s *EVMSigner) Address() string

Address returns the Ethereum address for this signer.

func (*EVMSigner) Sign added in v0.2.3

func (s *EVMSigner) Sign(params SignParams) (*SignResult, error)

Sign creates an EIP-712 signature for EIP-3009 TransferWithAuthorization. This enables gasless token transfers: the signer authorizes a transfer off-chain, and a third party (the facilitator) executes it on-chain, paying the gas.

type SignParams

type SignParams struct {
	// Common fields (all chains)
	TokenAddress   string // Token contract/mint address
	From           string // Payer address (signer)
	To             string // Recipient address
	Value          string // Amount in atomic units
	TimeoutSeconds int    // Timeout for payment validity

	// EVM-specific fields
	ChainID      int64  // EVM chain ID (e.g., 84532 for Base Sepolia)
	TokenName    string // Token name for EIP-712 domain (e.g., "USDC")
	TokenVersion string // Token version for EIP-712 domain (e.g., "2")
	ValidAfter   int64  // Unix timestamp, usually 0
	ValidBefore  int64  // Unix timestamp for expiration

	// Solana-specific fields
	FeePayer string // Fee payer public key (facilitator)
}

SignParams contains parameters for signing a payment authorization. Supports both EVM (EIP-3009) and Solana payment parameters. Different signers use different subsets of these fields.

func PrepareSignParams

func PrepareSignParams(option *x402.PaymentRequirement, fromAddress string, chainID int64) SignParams

PrepareSignParams builds SignParams from payment requirement and signer address.

func PrepareSolanaSignParams added in v0.2.3

func PrepareSolanaSignParams(option *x402.PaymentRequirement, fromAddress string) SignParams

PrepareSolanaSignParams builds SignParams from a Solana payment requirement.

type SignResult

type SignResult struct {
	// Signature is the signed authorization.
	// Format varies by chain:
	//   - EVM: Hex-encoded signature with 0x prefix
	//   - Solana: Base64-encoded partially-signed transaction
	Signature     string
	Authorization x402.Authorization // Authorization struct for payload
	// Nonce is the transaction nonce.
	// Format varies by chain:
	//   - EVM: Hex-encoded nonce with 0x prefix
	//   - Solana: Base58-encoded recent blockhash
	Nonce string
}

SignResult contains the signature and authorization details.

func SignTransferAuthorization

func SignTransferAuthorization(key *ecdsa.PrivateKey, params SignParams) (*SignResult, error)

SignTransferAuthorization creates an EIP-712 signature for EIP-3009 TransferWithAuthorization. This is a convenience function that creates an EVMSigner and signs the authorization. It maintains backward compatibility with existing code.

type Signer added in v0.2.3

type Signer interface {
	// Sign creates a signature for the given payment parameters.
	// Returns the signature and authorization details needed for the payment payload.
	Sign(params SignParams) (*SignResult, error)

	// Address returns the signer's address in the appropriate format for the chain.
	Address() string
}

Signer is the interface for signing payment authorizations. Implementations exist for different blockchain networks (EVM, Solana, etc.).

type SolanaSigner added in v0.2.3

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

SolanaSigner implements the Signer interface for Solana payments. It creates partially-signed SPL token transfer transactions.

func NewSolanaSigner added in v0.2.3

func NewSolanaSigner(privateKey solana.PrivateKey, rpcURL string) *SolanaSigner

NewSolanaSigner creates a new Solana signer from a private key. The rpcURL is used to fetch the recent blockhash for transaction construction.

func (*SolanaSigner) Address added in v0.2.3

func (s *SolanaSigner) Address() string

Address returns the base58-encoded public key for this signer.

func (*SolanaSigner) Sign added in v0.2.3

func (s *SolanaSigner) Sign(params SignParams) (*SignResult, error)

Sign creates a partially-signed Solana transaction for SPL token transfer. The transaction follows the x402 SVM spec with exactly 3 core instructions:

  1. ComputeBudget::SetComputeUnitLimit
  2. ComputeBudget::SetComputeUnitPrice
  3. Token::TransferChecked

If the destination ATA doesn't exist, a CreateAssociatedTokenAccount instruction is prepended (making 4 instructions total).

The transaction is signed by the token owner but requires the fee payer's signature to be fully valid (facilitator adds this).

Jump to

Keyboard shortcuts

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