sequence

package module
v0.50.4 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2025 License: Apache-2.0 Imports: 37 Imported by: 3

README

go-sequence

Sequence Wallet client written in Go.

Usage

For documentation on sequence, please see our docs page.

Developing the go-sequence library

  1. make bootstrap -- will install node modules of ./testutil/chain
  2. make start-testchain -- starts the test ethereum chain (id 1337)
  3. (in a separate terminal) make test -- runs test suite

Testing

Testing is super important, to run the tests just call make test. As well, you can run the testchain separately with make start-testchain then in another terminal run make test.

NOTE: Go by default will execute tests in parallel if you run go test -v ./..., so ensure to pass -p 1 to set parallelization to just 1 (so it runs serially). The make test command is already set to do this.

A. If you'd like to use a local version of a dependency/module, you can use the replace directive in go.mod, for example, lets say you want to use a local version of "ethkit" that hasn't been released with go-sequence, you can add replace github.com/0xsequence/ethkit => /home/peter/Dev/0xsequence/ethkit to your go.mod

LICENSE

Apache 2.0

Documentation

Index

Constants

View Source
const WalletContractBytecode = "0x603a600e3d39601a805130553df3363d3d373d3d3d363d30545af43d82803e903d91601857fd5bf3"

https://github.com/0xsequence/wallet-contracts/blob/master/src/contracts/Wallet.sol#L57-L59

Variables

View Source
var (
	// NonceChangeEventSig is the signature event emitted as the first event on the batch execution
	// 0x1f180c27086c7a39ea2a7b25239d1ab92348f07ca7bb59d1438fcf527568f881
	NonceChangeEventSig = MustEncodeSig("NonceChange(uint256,uint256)")

	// TxFailedEventSig is the signature event emitted in a failed smart-wallet meta-transaction batch
	// 0x3dbd1590ea96dd3253a91f24e64e3a502e1225d602a5731357bc12643070ccd7
	V1TxFailedEventSig = MustEncodeSig("TxFailed(bytes32,bytes)")

	// TxExecutedEventSig is the signature event emitted in a successful smart-wallet meta-transaction batch (for v2)
	// 0x5c4eeb02dabf8976016ab414d617f9a162936dcace3cdef8c69ef6e262ad5ae7
	// TxExecuted(bytes32 indexed _tx, uint256 _index)
	V2TxExecutedEventSig = common.HexToHash("0x5c4eeb02dabf8976016ab414d617f9a162936dcace3cdef8c69ef6e262ad5ae7")

	// TxFailedEventSig is the signature event emitted in a failed smart-wallet meta-transaction batch (for v2)
	// 0xab46c69f7f32e1bf09b0725853da82a211e5402a0600296ab499a2fb5ea3b419
	// TxFailed(bytes32 indexed _tx, uint256 _index, bytes _reason)
	V2TxFailedEventSig = common.HexToHash("0xab46c69f7f32e1bf09b0725853da82a211e5402a0600296ab499a2fb5ea3b419")
)

Transaction events as defined in wallet-contracts IModuleCalls.sol

View Source
var (
	ErrUnknownChainID = fmt.Errorf("chainID is unknown")
	ErrProviderNotSet = fmt.Errorf("provider is not set")
	ErrRelayerNotSet  = fmt.Errorf("relayer is not set")
)
View Source
var (
	// ImageHashUpdatedEventSig is emitted anytime wallet config is updated.
	ImageHashUpdatedEventSig = MustEncodeSig("ImageHashUpdated(bytes32)")

	// ImplementationUpdatedEventSig is emitted anytime a wallet's mainModule is changed,
	// this is a rare occurence.
	ImplementationUpdatedEventSig = MustEncodeSig("ImplementationUpdated(address)")
)

Functions

func AddressFromImageHash

func AddressFromImageHash(imageHash string, context WalletContext) (common.Address, error)

func AddressFromWalletConfig

func AddressFromWalletConfig(walletConfig core.WalletConfig, context WalletContext) (common.Address, error)

func BuildProxy added in v0.4.4

func BuildProxy(addr common.Address) string

BuildProxy for address based on https://eips.ethereum.org/EIPS/eip-1167 the bytecode contains an aditional SLOAD to mimic the Sequence proxies bytecode:

| 0x00000000 36 calldatasize cds | 0x00000001 3d returndatasize 0 cds | 0x00000002 3d returndatasize 0 0 cds | 0x00000003 37 calldatacopy | 0x00000004 30 address addr | 0x00000005 54 sload stub | 0x00000006 50 pop | 0x00000007 3d returndatasize 0 | 0x00000008 3d returndatasize 0 0 | 0x00000009 3d returndatasize 0 0 0 | 0x0000000a 36 calldatasize cds 0 0 0 | 0x0000000b 3d returndatasize 0 cds 0 0 0 | 0x0000000c 73bebebebebe. push20 0xbebebebe 0xbebe 0 cds 0 0 0 | 0x00000020 5a gas gas 0xbebe 0 cds 0 0 0 | 0x00000021 f4 delegatecall suc 0 | 0x00000022 3d returndatasize rds suc 0 | 0x00000023 82 dup3 0 rds suc 0 | 0x00000024 80 dup1 0 0 rds suc 0 | 0x00000025 3e returndatacopy suc 0 | 0x00000026 90 swap1 0 suc | 0x00000027 3d returndatasize rds 0 suc | 0x00000028 91 swap2 suc 0 rds | 0x00000029 602d push1 0x2e 0x2e suc 0 rds | ,=< 0x0000002b 57 jumpi 0 rds | | 0x0000002c fd revert | `-> 0x0000002d 5b jumpdest 0 rds \ 0x0000002e f3 return

func ComputeGuestExecDigest added in v0.3.3

func ComputeGuestExecDigest(txns Transactions) (common.Hash, error)

func ComputeSelfExecDigest added in v0.3.3

func ComputeSelfExecDigest(txns Transactions) (common.Hash, error)

func ComputeWalletExecDigest added in v0.3.3

func ComputeWalletExecDigest(nonce *big.Int, txns Transactions) (common.Hash, error)

func ContextWithAuxData added in v0.22.0

func ContextWithAuxData(ctx context.Context, auxData *AuxData) context.Context

func DecodeNonce

func DecodeNonce(raw *big.Int) (*big.Int, *big.Int)

DecodeNonce raw nonce, returns (space, nonce)

func DecodeNonceChangeEvent added in v0.3.1

func DecodeNonceChangeEvent(log *types.Log) (*big.Int, *big.Int, error)

func DecodeRevertReason added in v0.3.3

func DecodeRevertReason(logs []*types.Log) []string

func DecodeSignature

func DecodeSignature(sequenceSignature []byte) (core.Signature[*v2.WalletConfig], error)

func DecodeTxFailedEvent added in v0.3.1

func DecodeTxFailedEvent(log *types.Log) (common.Hash, string, uint, error)

func DecompressCalldata added in v0.26.0

func DecompressCalldata(ctx context.Context, provider *ethrpc.Provider, transaction *types.Transaction) (common.Address, []byte, error)

This method is duplicated code from: `compressor/contract.go` can't be used directly, because it would create a circular dependency

func DeploySequenceWallet

func DeploySequenceWallet(sender *ethwallet.Wallet, walletConfig core.WalletConfig, walletContext WalletContext) (common.Address, *types.Transaction, ethtxn.WaitReceipt, error)

func EIP6492Signature added in v0.22.1

func EIP6492Signature(signature []byte, config core.WalletConfig) ([]byte, error)

func EIP6492SignatureWithMultipleDeployments added in v0.37.1

func EIP6492SignatureWithMultipleDeployments(signature []byte, configs []core.WalletConfig) ([]byte, error)

func EIP6492ValidateSignature added in v0.22.0

func EIP6492ValidateSignature() ethauth.ValidatorFunc

func EncodeNonce

func EncodeNonce(space *big.Int, nonce *big.Int) (*big.Int, error)

EncodeNonce with space

func EncodeTransactionsForRelaying

func EncodeTransactionsForRelaying(relayer Relayer, walletAddress common.Address, walletConfig core.WalletConfig, walletContext WalletContext, txns Transactions, nonce *big.Int, seqSig []byte) (common.Address, []byte, error)

returns `to` address (either guest or wallet) and `data` of signed-metatx-calldata, aka execdata

func EncodeWalletDeployment added in v0.3.3

func EncodeWalletDeployment(walletConfig core.WalletConfig, walletContext WalletContext) (common.Address, common.Address, []byte, error)

func FilterMetaTransactionAny added in v0.17.0

func FilterMetaTransactionAny() ethreceipts.FilterQuery

Find any Sequence meta txns

func FilterMetaTransactionID added in v0.17.0

func FilterMetaTransactionID(metaTxnID ethkit.Hash) ethreceipts.FilterQuery

func GeneralIsValidSignature added in v0.22.0

func GeneralIsValidSignature(walletAddress common.Address, digest common.Hash, seqSig []byte, walletContexts WalletContexts, chainID *big.Int, provider *ethrpc.Provider) (bool, error)

func GeneralValidateSequenceAccountProof added in v0.22.0

func GeneralValidateSequenceAccountProof() ethauth.ValidatorFunc

func GeneralValidateSequenceAccountProofWith added in v0.22.0

func GeneralValidateSequenceAccountProofWith(walletContexts WalletContexts) ethauth.ValidatorFunc

func GenerateRandomNonce

func GenerateRandomNonce() (*big.Int, error)

GenerateRandomNonce returns a random space for a nonce to ensure transactions can be executed in parallel.

func GenericDecodeSignature added in v0.22.0

func GenericDecodeSignature[C core.WalletConfig](sequenceSignature []byte) (core.Signature[C], error)

GenericDecodeSignature sequence into individual parts

func GenericIsValidSignature added in v0.22.0

func GenericIsValidSignature[C core.WalletConfig](walletAddress common.Address, digest common.Hash, seqSig []byte, walletContext WalletContext, chainID *big.Int, provider *ethrpc.Provider) (bool, error)

func GenericIsValidUndeployedSignature added in v0.22.0

func GenericIsValidUndeployedSignature[C core.WalletConfig](walletAddress common.Address, digest common.Hash, seqSig []byte, walletContext WalletContext, chainID *big.Int, provider *ethrpc.Provider) (bool, error)

func GenericRecoverWalletConfigFromDigest added in v0.22.0

func GenericRecoverWalletConfigFromDigest[C core.WalletConfig](digest, seqSig []byte, walletAddress common.Address, walletContext WalletContext, chainID *big.Int, provider *ethrpc.Provider) (C, *big.Int, error)

func GenericValidateSequenceAccountProof added in v0.22.0

func GenericValidateSequenceAccountProof[C core.WalletConfig]() ethauth.ValidatorFunc

func GenericValidateSequenceAccountProofWith added in v0.22.0

func GenericValidateSequenceAccountProofWith[C core.WalletConfig](walletContexts WalletContext) ethauth.ValidatorFunc

func GetWalletNonce

func GetWalletNonce(provider *ethrpc.Provider, walletConfig core.WalletConfig, walletContext WalletContext, space *big.Int, blockNum *big.Int) (*big.Int, error)

func IsEIP191Message added in v0.29.0

func IsEIP191Message(msg []byte) bool

func IsTxExecutedEvent added in v0.3.1

func IsTxExecutedEvent(log *types.Log, hash common.Hash) bool

func IsTxFailedEvent added in v0.17.0

func IsTxFailedEvent(log *types.Log, hash common.Hash) bool

func IsValidMessageSignature added in v0.28.3

func IsValidMessageSignature(address common.Address, message []byte, signature []byte, chainID *big.Int, provider *ethrpc.Provider, optLogger *logger.Logger) (bool, error)

func IsValidSignature

func IsValidSignature(log logger.Logger, walletAddress common.Address, digest common.Hash, seqSig []byte, walletContexts WalletContexts, chainID *big.Int, provider *ethrpc.Provider) (bool, error)

func IsValidTypedDataSignature added in v0.44.2

func IsValidTypedDataSignature(address common.Address, encodedTypedData []byte, signature []byte, chainID *big.Int, provider *ethrpc.Provider, optLogger *logger.Logger) (bool, error)

func IsValidUndeployedSignature added in v0.22.0

func IsValidUndeployedSignature(walletAddress common.Address, digest common.Hash, seqSig []byte, walletContext WalletContext, chainID *big.Int, provider *ethrpc.Provider) (bool, error)

func IsWalletConfigEqual

func IsWalletConfigEqual(walletConfigA, walletConfigB core.WalletConfig) bool

func IsWalletDeployed

func IsWalletDeployed(provider *ethrpc.Provider, walletAddress common.Address) (bool, error)

func MessageDigest

func MessageDigest(message []byte) common.Hash

func MessageToEIP191 added in v0.29.0

func MessageToEIP191(msg []byte) []byte

func MustEncodeSig

func MustEncodeSig(str string) common.Hash

func PackMessageData

func PackMessageData(chainID *big.Int, address common.Address, digest common.Hash) ([]byte, error)

PackMessageData encodes a Sequence contract "message"

func ParseHexOrDec added in v0.29.0

func ParseHexOrDec(s string) (*big.Int, bool)

func RecoverWalletConfigFromDigest

func RecoverWalletConfigFromDigest(digest, seqSig []byte, walletAddress common.Address, walletContext WalletContext, chainID *big.Int, provider *ethrpc.Provider) (*v2.WalletConfig, *big.Int, error)

func ReduceExecdataSignatures added in v0.6.6

func ReduceExecdataSignatures(chainID *big.Int, data []byte) ([]byte, error)

func Sign

func Sign[C core.WalletConfig](wallet *Wallet[C], input common.Hash) ([]byte, error)

func SubDigest

func SubDigest(chainID *big.Int, address common.Address, digest common.Hash) ([]byte, error)

func UnwrapEIP6492Signature added in v0.33.0

func UnwrapEIP6492Signature(signature []byte) ([]byte, error)

func V1DecodeSignature added in v0.22.0

func V1DecodeSignature(sequenceSignature []byte) (core.Signature[*v1.WalletConfig], error)

func V1DecodeTxFailedEvent added in v0.22.0

func V1DecodeTxFailedEvent(log *types.Log) (common.Hash, string, error)

func V1IsTxExecutedEvent added in v0.22.0

func V1IsTxExecutedEvent(log *types.Log, hash common.Hash) bool

func V1IsTxFailedEvent added in v0.22.0

func V1IsTxFailedEvent(log *types.Log, hash common.Hash) bool

func V1IsValidSignature added in v0.22.0

func V1IsValidSignature(walletAddress common.Address, digest common.Hash, seqSig []byte, walletContext WalletContext, chainID *big.Int, provider *ethrpc.Provider) (bool, error)

func V1IsValidUndeployedSignature added in v0.22.0

func V1IsValidUndeployedSignature(walletAddress common.Address, digest common.Hash, seqSig []byte, walletContext WalletContext, chainID *big.Int, provider *ethrpc.Provider) (bool, error)

func V1RecoverWalletConfigFromDigest added in v0.22.0

func V1RecoverWalletConfigFromDigest(digest, seqSig []byte, walletAddress common.Address, walletContext WalletContext, chainID *big.Int, provider *ethrpc.Provider) (*v1.WalletConfig, *big.Int, error)

func V1SortWalletConfig added in v0.22.0

func V1SortWalletConfig(walletConfig *v1.WalletConfig) error

func V1ValidateSequenceAccountProof added in v0.22.0

func V1ValidateSequenceAccountProof() ethauth.ValidatorFunc

func V1ValidateSequenceAccountProofWith added in v0.22.0

func V1ValidateSequenceAccountProofWith(walletContext WalletContext) ethauth.ValidatorFunc

func V2DecodeSignature added in v0.22.0

func V2DecodeSignature(sequenceSignature []byte) (core.Signature[*v2.WalletConfig], error)

func V2DecodeTxFailedEvent added in v0.22.0

func V2DecodeTxFailedEvent(log *types.Log) (common.Hash, string, uint, error)

func V2IsTxExecutedEvent added in v0.22.0

func V2IsTxExecutedEvent(log *types.Log, hash common.Hash) bool

func V2IsTxFailedEvent added in v0.22.0

func V2IsTxFailedEvent(log *types.Log, hash common.Hash) bool

func V2IsValidSignature added in v0.22.0

func V2IsValidSignature(walletAddress common.Address, digest common.Hash, seqSig []byte, walletContext WalletContext, chainID *big.Int, provider *ethrpc.Provider) (bool, error)

func V2IsValidUndeployedSignature added in v0.22.0

func V2IsValidUndeployedSignature(walletAddress common.Address, digest common.Hash, seqSig []byte, walletContext WalletContext, chainID *big.Int, provider *ethrpc.Provider) (bool, error)

func V2RecoverWalletConfigFromDigest added in v0.22.0

func V2RecoverWalletConfigFromDigest(digest, seqSig []byte, walletAddress