sigverify

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2022 License: Apache-2.0 Imports: 11 Imported by: 15

README

SigVerify

This project is used to verify signatures under various specifications of ethereum. In addition to the standard elliptic curve signature, it also supports the signature of wallets such as ledger and argent.

It supports:

  1. Standard elliptic curve signature verification. (eth_sign).
  2. EIP712 typed data verification. (eth_signTypedData_v*).
  3. ERC1271 Smart contract wallet signature verification (isValidSignature).
  4. Additional support for signature verification of ledger wallet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CopyBytes

func CopyBytes(data []byte) []byte

CopyBytes is used to copy slice

func EcRecover

func EcRecover(data []byte, sig []byte) (ethcommon.Address, error)

EcRecover returns the address for the account that was used to create the signature, Note, this function is compatible with eth_sign and personal_sign. As such it recovers the address of: hash = keccak256("\x19Ethereum Signed Message:\n"${message length}${message}) addr = ecrecover(hash, signature)

Note, the signature must conform to the secp256k1 curve R, S and V values, where the V value must be 27 or 28 for legacy reasons.

https://github.com/ethereum/go-ethereum/wiki/Management-APIs#personal_ecRecover

func EcRecoverEx

func EcRecoverEx(data []byte, sig []byte) (ethcommon.Address, error)

EcRecoverEx is an extension to EcRecover that supports more signature formats, such as ledger signatures.

func GetERC1271Magic

func GetERC1271Magic() [4]byte

GetERC1271Magic is used to get the magic value defined by ERC1271

func Has0xPrefix

func Has0xPrefix(str string) bool

Has0xPrefix validates str begins with '0x' or '0X'.

func HashTypedData

func HashTypedData(data apitypes.TypedData) ([]byte, []byte, error)

HashTypedData is used to calculate the hash of EIP-712 conformant typed data hash = keccak256("\x19${byteVersion}${domainSeparator}${hashStruct(message)}")

func HexDecode

func HexDecode(s string) ([]byte, error)

HexDecode returns the bytes represented by the hexadecimal string s. s may be prefixed with "0x".

func IsErrExecutionReverted

func IsErrExecutionReverted(err error) bool

IsErrExecutionReverted is used to determine whether err is an ExecutionReverted error

func IsErrNoContractCode

func IsErrNoContractCode(err error) bool

IsErrNoContractCode is used to determine whether err is an NoContractCode error

func RecoveryAddress

func RecoveryAddress(data []byte, sig []byte) (ethcommon.Address, error)

RecoveryAddress returns the address for the account that was used to create the signature, this function is almost a fork of EcRecover However, EcRecover in go-ethereum will automatically perform accounts.TextHash for data in EcRecover, which makes EIP712 unable to reuse this function This design makes the function lose versatility, so this behavior is changed here

func RecoveryAddressEx

func RecoveryAddressEx(data []byte, sig []byte) (ethcommon.Address, error)

RecoveryAddressEx is an extension to RecoveryAddress that supports more signature formats, such as ledger signatures.

func RecoveryTypedDataAddressEx

func RecoveryTypedDataAddressEx(data apitypes.TypedData, signature []byte) (ethcommon.Address, error)

RecoveryTypedDataAddressEx is used to recover the signer address of the TypedData signature

func VerifyERC1271HexSignature

func VerifyERC1271HexSignature(ctx context.Context, client *ethclient.Client, address ethcommon.Address, data []byte, signature string) (bool, error)

VerifyERC1271HexSignature is a helper function. look up VerifyERC1271 for more comments.

func VerifyERC1271Signature

func VerifyERC1271Signature(ctx context.Context, client *ethclient.Client, address ethcommon.Address, data []byte, signature []byte) (bool, error)

VerifyERC1271Signature verifies signatures based on the ERC1271 standard 1. When the given address is EOA, "no contract code at given address" will be thrown: 2. When the given address is a contract but does not conform to the erc1271 specification, "execution reverted" will be thrown

func VerifyEllipticCurveSignature

func VerifyEllipticCurveSignature(address ethcommon.Address, data []byte, signature []byte) (bool, error)

VerifyEllipticCurveSignature is used to verify the elliptic curve signature It calls the native ecrecover function to verify the signature

func VerifyEllipticCurveSignatureEx

func VerifyEllipticCurveSignatureEx(address ethcommon.Address, data []byte, signature []byte) (bool, error)

VerifyEllipticCurveSignatureEx is used to verify elliptic curve signatures It calls the EcRecoverEx function to verify the signature.

func VerifyHexSignatureEx

func VerifyHexSignatureEx(ctx context.Context, client *ethclient.Client, address ethcommon.Address, msg []byte, signature string) (bool, error)

VerifyHexSignatureEx is used to verify text signature

func VerifySignatureEx

func VerifySignatureEx(ctx context.Context, client *ethclient.Client, address ethcommon.Address, msg []byte, signature []byte) (bool, error)

VerifySignatureEx is used to verify text signature

func VerifyTypedDataHexSignatureEx

func VerifyTypedDataHexSignatureEx(address ethcommon.Address, data apitypes.TypedData, signature string) (bool, error)

VerifyTypedDataHexSignatureEx is used to verify the signer address of the TypedData signature

func VerifyTypedDataSignatureEx

func VerifyTypedDataSignatureEx(address ethcommon.Address, data apitypes.TypedData, signature []byte) (bool, error)

VerifyTypedDataSignatureEx is used to verify the signer address of the TypedData signature

Types

This section is empty.

Directories

Path Synopsis
contracts

Jump to

Keyboard shortcuts

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