universal_sigver

package
v0.0.46 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2024 License: GPL-3.0 Imports: 10 Imported by: 0

README

Universal Signer Verifier package

Overview

Universal Signer Verifier is a golang library that provides helper functions to verify signatures.

Verify

You can use Verify(ctx, signer, messageHash, signature) (bool, error) to verify an ECDSA, ERC-1271 or ERC-6492 signature.

ERC6492

You can use IsERC6492Sig(sig) bool to check if a signature is an ERC-6492 signature (by checking ERC-6492 suffix).

You can use PackERC6492Sig(ctx, ownerAddress, index, sig) ([]byte, error) to pack a smart wallet signature into an ERC-6492 signature.

You can use UnpackERC6492Sig(sig) (common.Address, []byte, []byte, error) to unpack an ERC-6492 signature into smart wallet factory address, factory calldata and signature.

Usage

To use the Universal Signer Verifier package, you need to create a client, providing an ethclient, smart wallet config and an address of an EntryPoint contract. If you don't provide an address of the latter one, the default (v0.6) address will be used.

import (
  "github.com/layer-3/clearsync/pkg/universal_sigver"
  "github.com/ethereum/go-ethereum/common"
  "github.com/ethereum/go-ethereum/ethclient"
)

func main() {
  providerURL := "wss://your-infura-url"
  config := universal_sigver.Config{/* build your config here */}
  entryPointAddress := common.Address{/* address of a pre-deployed EntryPoint contract */}

  sigver, err := universal_sigver.NewUniversalSigVer(providerURL, config, entryPointAddress)
  if err != nil {
    panic(err)
  }

  // Use verifier to verify signatures
  sigver.Verify(...)
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotERC6492Sig       = errors.New("not an ERC-6492 signature")
	ErrCorruptedERC6492Sig = errors.New("corrupted ERC-6492 signature")
)

Functions

func IsERC6492Sig

func IsERC6492Sig(sig []byte) bool

IsERC6492Sig checks if the signature contains the ERC-6492 suffix, meaning it is an ERC-6492 signature.

Parameters: - sig: the signature

Returns: - true if the signature is an ERC-6492 signature, false otherwise

func PackERC6492Sig

func PackERC6492Sig(factoryAddress common.Address, factoryCalldata, sig []byte) []byte

PackERC6492Sig packs an ERC-6492 signature by adding smart wallet factory address, calldata and ERC-6492 suffix.

Parameters: - factoryAddress: the address of the smart wallet factory - factoryCalldata: the calldata for the smart wallet factory - sig: the signature

Returns: - the packed signature

func UnpackERC6492Sig

func UnpackERC6492Sig(sig []byte) (factoryAddress common.Address, factoryCalldata, signature []byte, err error)

UnpackERC6492Sig unpacks an ERC-6492 signature into a smart wallet factory address, calldata and signature.

Parameters: - sig: the signature

Returns: - the smart wallet factory address - the calldata for the smart wallet factory - the signature - an error if the signature is not an ERC-6492 signature or it is corrupted

Types

type Client

type Client interface {
	// Verify checks if the signature was signed by the signer.
	// This function supports ECDSA, ERC-1271 and ERC-6492 signatures.
	//
	// Parameters:
	// - ctx: the context
	// - signer: the address of the signer. EOA address if ECDSA signature is supplied, smart wallet address if ERC-1271 or ERC-6492 signature is supplied.
	// - messageHash: the hash of the message that was signed
	// - signature: the signature
	//
	// Returns:
	// - true if the signature is valid, false otherwise
	// - an error if an error occurred during the verification
	Verify(ctx context.Context, signer common.Address, messageHash common.Hash, signature []byte) (bool, error)

	// PackERC6492Sig packs an ERC-6492 signature by adding smart wallet factory address, calldata and ERC-6492 suffix.
	//
	// Parameters:
	// - ctx: the context
	// - ownerAddress: the address of the owner of the smart wallet
	// - index: the index of the smart wallet
	// - sig: the signature
	//
	// Returns:
	// - the packed signature
	// - an error if an error occurred during the packing
	PackERC6492Sig(ctx context.Context, ownerAddress common.Address, index decimal.Decimal, sig []byte) ([]byte, error)
}

func NewUniversalSigVer

func NewUniversalSigVer(providerURL string, smartWalletConfig *smart_wallet.Config, entryPointAddress *common.Address) Client

Jump to

Keyboard shortcuts

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