sequence

package module
v0.4.25 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2021 License: Apache-2.0 Imports: 32 Imported by: 3

README

go-sequence

Sequence Wallet client written in Go.

Usage

TODO: add docs.. etc. examples, etc.

Developing the go-sequence library

  1. make boostrap -- will install node modules of ./testutil/chain
  2. make start-test-chain -- 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 test-chain separately with make start-test-chain 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
	TxFailedEventSig = MustEncodeSig("TxFailed(bytes32,bytes)")

	// TxExecutedEventSig is the signature of the event emitted in a successful transaction
	// ........
	TxExecutedEventSig = MustEncodeSig("TxExecuted(bytes32)")
)

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 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 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 DecodeTxFailedEvent added in v0.3.1

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

func DeploySequenceWallet

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

func EncodeNonce

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

EncodeNonce with space

func EncodeTransactionsForRelaying

func EncodeTransactionsForRelaying(relayer Relayer, walletConfig 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 WalletConfig, walletContext WalletContext) (common.Address, common.Address, []byte, error)

func GenerateRandomNonce

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

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

func GetWalletNonce

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

func ImageHashOfWalletConfig

func ImageHashOfWalletConfig(walletConfig WalletConfig) (string, error)

func ImageHashOfWalletConfigBytes

func ImageHashOfWalletConfigBytes(walletConfig WalletConfig) ([]byte, error)

func IsTxExecutedEvent added in v0.3.1

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

func IsValidSignature

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

func IsWalletConfigEqual

func IsWalletConfigEqual(walletConfigA, walletConfigB WalletConfig) bool

func IsWalletConfigUsable

func IsWalletConfigUsable(walletConfig WalletConfig) (bool, error)

func IsWalletDeployed

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

func MessageDigest

func MessageDigest(message []byte) common.Hash

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 SortWalletConfig

func SortWalletConfig(walletConfig WalletConfig) error

func SubDigest

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

func ValidateSequenceAccountProof

func ValidateSequenceAccountProof() ethauth.ValidatorFunc

func ValidateSequenceAccountProofWith

func ValidateSequenceAccountProofWith(factory, mainModule common.Address) ethauth.ValidatorFunc

Types

type BlockOfReceipts added in v0.4.17

type BlockOfReceipts []*ReceiptResult

type CallOverride added in v0.4.0

type CallOverride struct {
	Code      string
	Balance   *big.Int
	Nonce     *big.Int
	StateDiff []*StateOverride
	State     []*StateOverride
}

type EstimateTransaction added in v0.4.0

type EstimateTransaction struct {
	From common.Address
	To   common.Address
	Data []byte
}

type Estimator added in v0.4.0

type Estimator struct {
	BaseCost     uint64
	DataOneCost  uint64
	DataZeroCost uint64
	// contains filtered or unexported fields
}

func NewEstimator added in v0.4.0

func NewEstimator() *Estimator

func (*Estimator) AreEOAs added in v0.4.0

func (e *Estimator) AreEOAs(ctx context.Context, provider *ethrpc.Provider, walletConfig WalletConfig) ([]bool, error)

func (*Estimator) BuildStubSignature added in v0.4.0

func (e *Estimator) BuildStubSignature(walletConfig WalletConfig, willSign []bool, isEoa []bool) []byte

func (*Estimator) CalldataCost added in v0.4.0

func (e *Estimator) CalldataCost(data []byte) uint64

func (*Estimator) Estimate added in v0.4.0

func (e *Estimator) Estimate(ctx context.Context, provider *ethrpc.