erc1271

package module
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2023 License: Apache-2.0 Imports: 15 Imported by: 0

README

erc1271 Go Reference

A simple utility library to validate ERC1271 signatures

Use cases

  • CA-based (not EOA) wallets signature validation
  • Contract-based validations for off-chain operations

Example

  • see cmd/erc1271validate/main.go

Installation

  • go get github.com/holyheld/erc1271

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ContractABI = ContractMetaData.ABI

ContractABI is the input ABI used to generate the binding from. Deprecated: Use ContractMetaData.ABI instead.

View Source
var ContractMetaData = &bind.MetaData{
	ABI: "[{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"_hash\",\"type\":\"bytes32\"},{\"internalType\":\"bytes\",\"name\":\"_signature\",\"type\":\"bytes\"}],\"name\":\"isValidSignature\",\"outputs\":[{\"internalType\":\"bytes4\",\"name\":\"magicValue\",\"type\":\"bytes4\"}],\"stateMutability\":\"view\",\"type\":\"function\"}]",
}

ContractMetaData contains all meta data concerning the Contract contract.

View Source
var ValidSignature = crypto.Keccak256([]byte("isValidSignature(bytes32,bytes)"))[:4]

ValidSignature is a magic value to compare validate result against

Functions

func IsZeroAddress added in v1.0.5

func IsZeroAddress(iaddress interface{}) bool

IsZeroAddress validates if it's a 0 address

https://github.com/miguelmota/ethereum-development-with-go-book/blob/3b24cad5d54aff1496fe4c3590c27f0fad648ddf/code/util/util.go#L42

Types

type Contract

type Contract struct {
	ContractCaller     // Read-only binding to the contract
	ContractTransactor // Write-only binding to the contract
	ContractFilterer   // Log filterer for contract events
}

Contract is an auto generated Go binding around an Ethereum contract.

func NewContract

func NewContract(address common.Address, backend bind.ContractBackend) (*Contract, error)

NewContract creates a new instance of Contract, bound to a specific deployed contract.

type ContractCaller

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

ContractCaller is an auto generated read-only Go binding around an Ethereum contract.

func NewContractCaller

func NewContractCaller(address common.Address, caller bind.ContractCaller) (*ContractCaller, error)

NewContractCaller creates a new read-only instance of Contract, bound to a specific deployed contract.

func (*ContractCaller) IsValidSignature

func (_Contract *ContractCaller) IsValidSignature(opts *bind.CallOpts, _hash [32]byte, _signature []byte) ([4]byte, error)

IsValidSignature is a free data retrieval call binding the contract method 0x1626ba7e.

Solidity: function isValidSignature(bytes32 _hash, bytes _signature) view returns(bytes4 magicValue)

type ContractCallerRaw

type ContractCallerRaw struct {
	Contract *ContractCaller // Generic read-only contract binding to access the raw methods on
}

ContractCallerRaw is an auto generated low-level read-only Go binding around an Ethereum contract.

func (*ContractCallerRaw) Call

func (_Contract *ContractCallerRaw) Call(opts *bind.CallOpts, result *[]interface{}, method string, params ...interface{}) error

Call invokes the (constant) contract method with params as input values and sets the output to result. The result type might be a single field for simple returns, a slice of interfaces for anonymous returns and a struct for named returns.

type ContractCallerSession

type ContractCallerSession struct {
	Contract *ContractCaller // Generic contract caller binding to set the session for
	CallOpts bind.CallOpts   // Call options to use throughout this session
}

ContractCallerSession is an auto generated read-only Go binding around an Ethereum contract, with pre-set call options.

func (*ContractCallerSession) IsValidSignature

func (_Contract *ContractCallerSession) IsValidSignature(_hash [32]byte, _signature []byte) ([4]byte, error)

IsValidSignature is a free data retrieval call binding the contract method 0x1626ba7e.

Solidity: function isValidSignature(bytes32 _hash, bytes _signature) view returns(bytes4 magicValue)

type ContractFilterer

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

ContractFilterer is an auto generated log filtering Go binding around an Ethereum contract events.

func NewContractFilterer

func NewContractFilterer(address common.Address, filterer bind.ContractFilterer) (*ContractFilterer, error)

NewContractFilterer creates a new log filterer instance of Contract, bound to a specific deployed contract.

type ContractRaw

type ContractRaw struct {
	Contract *Contract // Generic contract binding to access the raw methods on
}

ContractRaw is an auto generated low-level Go binding around an Ethereum contract.

func (*ContractRaw) Call

func (_Contract *ContractRaw) Call(opts *bind.CallOpts, result *[]interface{}, method string, params ...interface{}) error

Call invokes the (constant) contract method with params as input values and sets the output to result. The result type might be a single field for simple returns, a slice of interfaces for anonymous returns and a struct for named returns.

func (*ContractRaw) Transact

func (_Contract *ContractRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error)

Transact invokes the (paid) contract method with params as input values.

func (*ContractRaw) Transfer

func (_Contract *ContractRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error)

Transfer initiates a plain transaction to move funds to the contract, calling its default method if one is available.

type ContractSession

type ContractSession struct {
	Contract     *Contract         // Generic contract binding to set the session for
	CallOpts     bind.CallOpts     // Call options to use throughout this session
	TransactOpts bind.TransactOpts // Transaction auth options to use throughout this session
}

ContractSession is an auto generated Go binding around an Ethereum contract, with pre-set call and transact options.

func (*ContractSession) IsValidSignature

func (_Contract *ContractSession) IsValidSignature(_hash [32]byte, _signature []byte) ([4]byte, error)

IsValidSignature is a free data retrieval call binding the contract method 0x1626ba7e.

Solidity: function isValidSignature(bytes32 _hash, bytes _signature) view returns(bytes4 magicValue)

type ContractTransactor

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

ContractTransactor is an auto generated write-only Go binding around an Ethereum contract.

func NewContractTransactor

func NewContractTransactor(address common.Address, transactor bind.ContractTransactor) (*ContractTransactor, error)

NewContractTransactor creates a new write-only instance of Contract, bound to a specific deployed contract.

type ContractTransactorRaw

type ContractTransactorRaw struct {
	Contract *ContractTransactor // Generic write-only contract binding to access the raw methods on
}

ContractTransactorRaw is an auto generated low-level write-only Go binding around an Ethereum contract.

func (*ContractTransactorRaw) Transact

func (_Contract *ContractTransactorRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error)

Transact invokes the (paid) contract method with params as input values.

func (*ContractTransactorRaw) Transfer

func (_Contract *ContractTransactorRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error)

Transfer initiates a plain transaction to move funds to the contract, calling its default method if one is available.

type ContractTransactorSession

type ContractTransactorSession struct {
	Contract     *ContractTransactor // Generic contract transactor binding to set the session for
	TransactOpts bind.TransactOpts   // Transaction auth options to use throughout this session
}

ContractTransactorSession is an auto generated write-only Go binding around an Ethereum contract, with pre-set transact options.

type Validator

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

Validator is a helper struct that provides with convenience method and ERC1271-compliant validate function

func NewValidator added in v1.0.4

func NewValidator(client bind.ContractCaller) *Validator

NewValidator creates a new Validator instance

func (*Validator) IsContract added in v1.0.5

func (v *Validator) IsContract(ctx context.Context, validatorAddress common.Address) (bool, error)

IsContract checks if validator address is smart contract using common.Address value

func (*Validator) IsContractHex added in v1.0.5

func (v *Validator) IsContractHex(ctx context.Context, validatorAddress string) (bool, error)

IsContractHex checks if validatorAddress is smart contract using hex (string) value

func (*Validator) Validate

func (v *Validator) Validate(ctx context.Context, message []byte, signer string, signature string) (bool, error)

Validate performs all the necessary checks to tell if the signature is valid from ERC1271 standpoint

Handles obvious contract (response) related errors internally, error value should be used to check if the RPC connection is established properly

func (*Validator) WithCustomValidSignature

func (v *Validator) WithCustomValidSignature(signature []byte) *Validator

WithCustomValidSignature sets custom valid signature (magic value to compare the results against) using byte slice value

func (*Validator) WithCustomValidSignatureHex

func (v *Validator) WithCustomValidSignatureHex(signature string) *Validator

WithCustomValidSignatureHex sets custom valid signature (magic value to compare the results against) using hex (string) value

func (*Validator) WithSkipIsContractCheck added in v1.0.5

func (v *Validator) WithSkipIsContractCheck(skip bool) *Validator

WithSkipIsContractCheck sets internal skip flag to not perform CodeAt(validatorAddress) check

func (*Validator) WithValidatorAddress

func (v *Validator) WithValidatorAddress(address common.Address) *Validator

WithValidatorAddress sets validator address (target contract validator address) using common.Address value

func (*Validator) WithValidatorAddressHex

func (v *Validator) WithValidatorAddressHex(address string) *Validator

WithValidatorAddressHex sets validator address (target contract validator address) using hex (string) value

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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