core

package
v0.0.0-...-7325b6b Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Author: https://github.com/zksync-sdk/zksync-go *

Package common contains various helper functions.

Author: https://github.com/zksync-sdk/zksync-go *

Author: https://github.com/zksync-sdk/zksync-go *

Author: https://github.com/zksync-sdk/zksync-go *

Author: https://github.com/zksync-sdk/zksync-go *

Package hexutil implements hex encoding with 0x prefix. This encoding is used by the Ethereum RPC API to transport binary data in JSON payloads.

Encoding Rules

All hex data must have prefix "0x".

For byte slices, the hex data must be of even length. An empty byte slice encodes as "0x".

Integers are encoded using the least amount of digits (no leading zero digits). Their encoding may be of uneven length. The number zero encodes as "0x0".

Author: https://github.com/zksync-sdk/zksync-go *

Author: https://github.com/zksync-sdk/zksync-go *

Author: https://github.com/zksync-sdk/zksync-go *

Author: https://github.com/zksync-sdk/zksync-go *

Author: https://github.com/zksync-sdk/zksync-go *

Author: https://github.com/zksync-sdk/zksync-go *

Author: https://github.com/zksync-sdk/zksync-go *

Author: https://github.com/zksync-sdk/zksync-go *

Author: https://github.com/zksync-sdk/zksync-go *

Author: https://github.com/zksync-sdk/zksync-go *

Index

Constants

View Source
const (
	TransactionTypeMintNFT     = "MintNFT"
	TransactionTypeWithdrawNFT = "WithdrawNFT"
)
View Source
const (
	AmountExponentBitWidth int64 = 5
	AmountMantissaBitWidth int64 = 35
	FeeExponentBitWidth    int64 = 5
	FeeMantissaBitWidth    int64 = 11
)
View Source
const (
	// HashLength is the expected length of the hash
	HashLength = 32
	// AddressLength is the expected length of the address
	AddressLength = 20
)

Lengths of hashes and addresses in bytes.

View Source
const (
	TransactionTypeWithdraw   = "Withdraw"
	TransactionTypeForcedExit = "ForcedExit"
)
View Source
const (
	Message                 = "Access zkSync account.\n\nOnly sign this message for a trusted client!"
	TransactionVersion byte = 0x01
	PUBLICK_KEY_PREFIX      = "sync:"
	HEX_PREFIX              = "0x"
)
View Source
const (
	TransactionTypeSwap = "Swap"
)
View Source
const (
	TransactionTypeTransfer = "Transfer"
)

Variables

View Source
var (
	ErrUnknownTxTYPE = errors.New("unknown tx type")
	ErrConvertBigInt = errors.New("failed to convert string fee to big.Int")
)
View Source
var (
	ErrEmptyString   = &decError{"empty hex string"}
	ErrSyntax        = &decError{"invalid hex string"}
	ErrMissingPrefix = &decError{"hex string without 0x prefix"}
	ErrOddLength     = &decError{"hex string of odd length"}
	ErrEmptyNumber   = &decError{"hex string \"0x\""}
	ErrLeadingZero   = &decError{"hex number with leading zero digits"}
	ErrUint64Range   = &decError{"hex number > 64 bits"}
	ErrUintRange     = &decError{fmt.Sprintf("hex number > %d bits", uintBits)}
	ErrBig256Range   = &decError{"hex number > 256 bits"}
)

Errors

Functions

func BigIntToBytesBE

func BigIntToBytesBE(v *big.Int, numBytes int) []byte

func Bytes2Hex

func Bytes2Hex(d []byte) string

Bytes2Hex returns the hexadecimal encoding of d.

func CopyBytes

func CopyBytes(b []byte) (copiedBytes []byte)

CopyBytes returns an exact copy of the provided bytes.

func Decode

func Decode(input string) ([]byte, error)

Decode decodes a hex string with 0x prefix.

func DecodeBig

func DecodeBig(input string) (*big.Int, error)

DecodeBig decodes a hex string with 0x prefix as a quantity. Numbers larger than 256 bits are not accepted.

func DecodeUint64

func DecodeUint64(input string) (uint64, error)

DecodeUint64 decodes a hex string with 0x prefix as a quantity.

func Encode

func Encode(b []byte) string

Encode encodes b as a hex string with 0x prefix.

func EncodeBig

func EncodeBig(bigint *big.Int) string

EncodeBig encodes bigint as a hex string with 0x prefix. The sign of the integer is ignored.

func EncodeUint64

func EncodeUint64(i uint64) string

EncodeUint64 encodes i as a hex string with 0x prefix.

func FromHex

func FromHex(s string) []byte

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

func Hex2Bytes

func Hex2Bytes(str string) []byte

Hex2Bytes returns the bytes represented by the hexadecimal string str.

func Hex2BytesFixed

func Hex2BytesFixed(str string, flen int) []byte

Hex2BytesFixed returns bytes of a specified fixed length flen.

func IsHexAddress

func IsHexAddress(s string) bool

IsHexAddress verifies whether a string can represent a valid hex-encoded Ethereum address or not.

func LeftPadBytes

func LeftPadBytes(slice []byte, l int) []byte

LeftPadBytes zero-pads slice to the left up to length l.

func MustDecode

func MustDecode(input string) []byte

MustDecode decodes a hex string with 0x prefix. It panics for invalid input.

func MustDecodeBig

func MustDecodeBig(input string) *big.Int

MustDecodeBig decodes a hex string with 0x prefix as a quantity. It panics for invalid input.

func MustDecodeUint64

func MustDecodeUint64(input string) uint64

MustDecodeUint64 decodes a hex string with 0x prefix as a quantity. It panics for invalid input.

func PackAmount

func PackAmount(fee *big.Int) ([]byte, error)

func PackFee

func PackFee(fee *big.Int) ([]byte, error)

func ParseAddress

func ParseAddress(address string) []byte

func RightPadBytes

func RightPadBytes(slice []byte, l int) []byte

RightPadBytes zero-pads slice to the right up to length l.

func TrimLeftZeroes

func TrimLeftZeroes(s []byte) []byte

TrimLeftZeroes returns a subslice of s without leading zeroes

func TrimRightZeroes

func TrimRightZeroes(s []byte) []byte

TrimRightZeroes returns a subslice of s without trailing zeroes

func Uint16ToBytes

func Uint16ToBytes(v uint16) []byte

func Uint32ToBytes

func Uint32ToBytes(v uint32) []byte

func Uint64ToBytes

func Uint64ToBytes(v uint64) []byte

func UnmarshalFixedJSON

func UnmarshalFixedJSON(typ reflect.Type, input, out []byte) error

UnmarshalFixedJSON decodes the input as a string with 0x prefix. The length of out determines the required input length. This function is commonly used to implement the UnmarshalJSON method for fixed-size types.

func UnmarshalFixedText

func UnmarshalFixedText(typname string, input, out []byte) error

UnmarshalFixedText decodes the input as a string with 0x prefix. The length of out determines the required input length. This function is commonly used to implement the UnmarshalText method for fixed-size types.

func UnmarshalFixedUnprefixedText

func UnmarshalFixedUnprefixedText(typname string, input, out []byte) error

UnmarshalFixedUnprefixedText decodes the input as a string with optional 0x prefix. The length of out determines the required input length. This function is commonly used to implement the UnmarshalText method for fixed-size types.

Types

type AccountState

type AccountState struct {
	Address    string           `json:"address"`
	Id         uint32           `json:"id"`
	Depositing *DepositingState `json:"depositing"`
	Committed  *State           `json:"committed"`
	Verified   *State           `json:"verified"`
}

type Address

type Address [AddressLength]byte

Address represents the 20 byte address of an Ethereum account.

func BigToAddress

func BigToAddress(b *big.Int) Address

BigToAddress returns Address with byte values of b. If b is larger than len(h), b will be cropped from the left.

func BytesToAddress

func BytesToAddress(b []byte) Address

BytesToAddress returns Address with value b. If b is larger than len(h), b will be cropped from the left.

func HexToAddress

func HexToAddress(s string) Address

HexToAddress returns Address with byte values of s. If s is larger than len(h), s will be cropped from the left.

func (Address) Bytes

func (a Address) Bytes() []byte

Bytes gets the string representation of the underlying address.

func (Address) Format

func (a Address) Format(s fmt.State, c rune)

Format implements fmt.Formatter. Address supports the %v, %s, %v, %x, %X and %d format verbs.

func (Address) Hash

func (a Address) Hash() Hash

Hash converts an address to a hash by left-padding it with zeros.

func (Address) Hex

func (a Address) Hex() string

Hex returns an EIP55-compliant hex string representation of the address.

func (Address) ImplementsGraphQLType

func (a Address) ImplementsGraphQLType(name string) bool

ImplementsGraphQLType returns true if Hash implements the specified GraphQL type.

func (Address) MarshalText

func (a Address) MarshalText() ([]byte, error)

MarshalText returns the hex representation of a.

func (*Address) Scan

func (a *Address) Scan(src interface{}) error

Scan implements Scanner for database/sql.

func (*Address) SetBytes

func (a *Address) SetBytes(b []byte)

SetBytes sets the address to the value of b. If b is larger than len(a), b will be cropped from the left.

func (Address) String

func (a Address) String() string

String implements fmt.Stringer.

func (*Address) UnmarshalGraphQL

func (a *Address) UnmarshalGraphQL(input interface{}) error

UnmarshalGraphQL unmarshals the provided GraphQL query data.

func (*Address) UnmarshalJSON

func (a *Address) UnmarshalJSON(input []byte) error

UnmarshalJSON parses a hash in hex syntax.

func (*Address) UnmarshalText

func (a *Address) UnmarshalText(input []byte) error

UnmarshalText parses a hash in hex syntax.

func (Address) Value

func (a Address) Value() (driver.Value, error)

Value implements valuer for database/sql.

type Big

type Big big.Int

Big marshals/unmarshals as a JSON string with 0x prefix. The zero value marshals as "0x0".

Negative integers are not supported at this time. Attempting to marshal them will return an error. Values larger than 256bits are rejected by Unmarshal but will be marshaled without error.

func (Big) ImplementsGraphQLType

func (b Big) ImplementsGraphQLType(name string) bool

ImplementsGraphQLType returns true if Big implements the provided GraphQL type.

func (Big) MarshalText

func (b Big) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler

func (*Big) String

func (b *Big) String() string

String returns the hex encoding of b.

func (*Big) ToInt

func (b *Big) ToInt() *big.Int

ToInt converts b to a big.Int.

func (*Big) UnmarshalGraphQL

func (b *Big) UnmarshalGraphQL(input interface{}) error

UnmarshalGraphQL unmarshals the provided GraphQL query data.

func (*Big) UnmarshalJSON

func (b *Big) UnmarshalJSON(input []byte) error

UnmarshalJSON implements json.Unmarshaler.

func (*Big) UnmarshalText

func (b *Big) UnmarshalText(input []byte) error

UnmarshalText implements encoding.TextUnmarshaler

type Bits

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

func NewBits

func NewBits(len uint) *Bits

func (*Bits) Append

func (b *Bits) Append(a *Bits) *Bits

func (*Bits) Clone

func (b *Bits) Clone() *Bits

func (*Bits) FromBytesBE

func (b *Bits) FromBytesBE(bytes []byte) *Bits

func (*Bits) GetBit

func (b *Bits) GetBit(i uint) bool

func (*Bits) Len

func (b *Bits) Len() uint

func (*Bits) Reverse

func (b *Bits) Reverse() *Bits

func (*Bits) SetBit

func (b *Bits) SetBit(i uint, v bool)

func (*Bits) String

func (b *Bits) String() (s string)

func (*Bits) ToBytesBE

func (b *Bits) ToBytesBE() ([]byte, error)

type BlockInfo

type BlockInfo struct {
	BlockNumber uint64 `json:"blockNumber"`
	Committed   bool   `json:"committed"`
	Verified    bool   `json:"verified"`
}

type Bytes

type Bytes []byte

Bytes marshals/unmarshals as a JSON string with 0x prefix. The empty slice marshals as "0x".

func (Bytes) ImplementsGraphQLType

func (b Bytes) ImplementsGraphQLType(name string) bool

ImplementsGraphQLType returns true if Bytes implements the specified GraphQL type.

func (Bytes) MarshalText

func (b Bytes) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler

func (Bytes) String

func (b Bytes) String() string

String returns the hex encoding of b.

func (*Bytes) UnmarshalGraphQL

func (b *Bytes) UnmarshalGraphQL(input interface{}) error

UnmarshalGraphQL unmarshals the provided GraphQL query data.

func (*Bytes) UnmarshalJSON

func (b *Bytes) UnmarshalJSON(input []byte) error

UnmarshalJSON implements json.Unmarshaler.

func (*Bytes) UnmarshalText

func (b *Bytes) UnmarshalText(input []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

type ChainId

type ChainId int
const (
	ChainIdMainnet   ChainId = 1
	ChainIdRinkeby   ChainId = 4
	ChainIdRopsten   ChainId = 3
	ChainIdLocalhost ChainId = 9
)

type ChangePubKey

type ChangePubKey struct {
	Type        string              `json:"type"`
	AccountId   uint32              `json:"accountId"`
	Account     string              `json:"account"`
	NewPkHash   string              `json:"newPkHash"`
	FeeToken    uint32              `json:"feeToken"`
	Fee         string              `json:"fee"`
	Nonce       uint32              `json:"nonce"`
	Signature   *Signature          `json:"signature"`
	EthAuthData ChangePubKeyVariant `json:"ethAuthData"`
	*TimeRange
}

func (*ChangePubKey) GetTxHash

func (t *ChangePubKey) GetTxHash() (string, error)

type ChangePubKeyAuthType

type ChangePubKeyAuthType string
const (
	ChangePubKeyAuthTypeOnchain ChangePubKeyAuthType = `Onchain`
	ChangePubKeyAuthTypeECDSA   ChangePubKeyAuthType = `ECDSA`
	ChangePubKeyAuthTypeCREATE2 ChangePubKeyAuthType = `CREATE2`
)

type ChangePubKeyCREATE2

type ChangePubKeyCREATE2 struct {
	Type           ChangePubKeyAuthType `json:"type"`
	CreatorAddress string               `json:"creatorAddress"`
	SaltArg        string               `json:"saltArg"`
	CodeHash       string               `json:"codeHash"`
}

type ChangePubKeyECDSA

type ChangePubKeyECDSA struct {
	Type         ChangePubKeyAuthType `json:"type"`
	EthSignature string               `json:"ethSignature"`
	BatchHash    string               `json:"batchHash"`
}

type ChangePubKeyOnchain

type ChangePubKeyOnchain struct {
	Type ChangePubKeyAuthType `json:"type"`
}

type ChangePubKeyVariant

type ChangePubKeyVariant interface {
	// contains filtered or unexported methods
}

type DepositingBalance

type DepositingBalance struct {
	Amount              string `json:"amount"`
	ExpectedBlockNumber string `json:"expectedBlockNumber"` // to *big.Int
}

type DepositingState

type DepositingState struct {
	Balances map[string]*DepositingBalance `json:"balances"`
}

type EthOpInfo

type EthOpInfo struct {
	Executed bool       `json:"executed"`
	Block    *BlockInfo `json:"block"`
}

type EthSignature

type EthSignature struct {
	Type      EthSignatureType `json:"type"`
	Signature string           `json:"signature"`
}

type EthSignatureType

type EthSignatureType string
const (
	EthSignatureTypeEth     EthSignatureType = "EthereumSignature"
	EthSignatureTypeEIP1271 EthSignatureType = "EIP1271Signature"
)

type EthSigner

type EthSigner interface {
	GetAddress() string
	SignMessage([]byte) ([]byte, error)
	SignHash(msg []byte) ([]byte, error)
	SignAuth(txData *ChangePubKey) (*ChangePubKeyECDSA, error)
	SignTransaction(tx ZksTransaction, nonce uint32, token *Token, fee *big.Int) (*EthSignature, error)
	SignBatch(txs []ZksTransaction, nonce uint32, token *Token, fee *big.Int) (*EthSignature, error)
	SignOrder(order *Order, sell, buy *Token) (*EthSignature, error)
}

type ForcedExit

type ForcedExit struct {
	Type      string     `json:"type"`
	AccountId uint32     `json:"initiatorAccountId"`
	Target    string     `json:"target"`
	TokenId   uint32     `json:"token"`
	Amount    *big.Int   `json:"amount"`
	Fee       string     `json:"fee"`
	Nonce     uint32     `json:"nonce"`
	Signature *Signature `json:"signature"`
	*TimeRange
}

type Hash

type Hash [HashLength]byte

Hash represents the 32 byte Keccak256 hash of arbitrary data.

func BigToHash

func BigToHash(b *big.Int) Hash

BigToHash sets byte representation of b to hash. If b is larger than len(h), b will be cropped from the left.

func BytesToHash

func BytesToHash(b []byte) Hash

BytesToHash sets b to hash. If b is larger than len(h), b will be cropped from the left.

func HexToHash

func HexToHash(s string) Hash

HexToHash sets byte representation of s to hash. If b is larger than len(h), b will be cropped from the left.

func (Hash) Big

func (h Hash) Big() *big.Int

Big converts a hash to a big integer.

func (Hash) Bytes

func (h Hash) Bytes() []byte

Bytes gets the byte representation of the underlying hash.

func (Hash) Format

func (h Hash) Format(s fmt.State, c rune)

Format implements fmt.Formatter. Hash supports the %v, %s, %v, %x, %X and %d format verbs.

func (Hash) Generate

func (h Hash) Generate(rand *rand.Rand, size int) reflect.Value

Generate implements testing/quick.Generator.

func (Hash) Hex

func (h Hash) Hex() string

Hex converts a hash to a hex string.

func (Hash) ImplementsGraphQLType

func (Hash) ImplementsGraphQLType(name string) bool

ImplementsGraphQLType returns true if Hash implements the specified GraphQL type.

func (Hash) MarshalText

func (h Hash) MarshalText() ([]byte, error)

MarshalText returns the hex representation of h.

func (*Hash) Scan

func (h *Hash) Scan(src interface{}) error

Scan implements Scanner for database/sql.

func (*Hash) SetBytes

func (h *Hash) SetBytes(b []byte)

SetBytes sets the hash to the value of b. If b is larger than len(h), b will be cropped from the left.

func (Hash) String

func (h Hash) String() string

String implements the stringer interface and is used also by the logger when doing full logging into a file.

func (Hash) TerminalString

func (h Hash) TerminalString() string

TerminalString implements log.TerminalStringer, formatting a string for console output during logging.

func (*Hash) UnmarshalGraphQL

func (h *Hash) UnmarshalGraphQL(input interface{}) error

UnmarshalGraphQL unmarshals the provided GraphQL query data.

func (*Hash) UnmarshalJSON

func (h *Hash) UnmarshalJSON(input []byte) error

UnmarshalJSON parses a hash in hex syntax.

func (*Hash) UnmarshalText

func (h *Hash) UnmarshalText(input []byte) error

UnmarshalText parses a hash in hex syntax.

func (Hash) Value

func (h Hash) Value() (driver.Value, error)

Value implements valuer for database/sql.

type MintNFT

type MintNFT struct {
	Type           string     `json:"type"`
	CreatorId      uint32     `json:"creatorId"`
	CreatorAddress string     `json:"creatorAddress"`
	ContentHash    Hash       `json:"contentHash"`
	Recipient      string     `json:"recipient"`
	Fee            string     `json:"fee"`
	FeeToken       uint32     `json:"feeToken"`
	Nonce          uint32     `json:"nonce"`
	Signature      *Signature `json:"signature"`
}

type MixedcaseAddress

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

MixedcaseAddress retains the original string, which may or may not be correctly checksummed

func NewMixedcaseAddress

func NewMixedcaseAddress(addr Address) MixedcaseAddress

NewMixedcaseAddress constructor (mainly for testing)

func NewMixedcaseAddressFromString

func NewMixedcaseAddressFromString(hexaddr string) (*MixedcaseAddress, error)

NewMixedcaseAddressFromString is mainly meant for unit-testing

func (*MixedcaseAddress) Address

func (ma *MixedcaseAddress) Address() Address

Address returns the address

func (*MixedcaseAddress) MarshalJSON

func (ma *MixedcaseAddress) MarshalJSON() ([]byte, error)

MarshalJSON marshals the original value

func (*MixedcaseAddress) Original

func (ma *MixedcaseAddress) Original() string

Original returns the mixed-case input string

func (*MixedcaseAddress) String

func (ma *MixedcaseAddress) String() string

String implements fmt.Stringer

func (*MixedcaseAddress) UnmarshalJSON

func (ma *MixedcaseAddress) UnmarshalJSON(input []byte) error

UnmarshalJSON parses MixedcaseAddress

func (*MixedcaseAddress) ValidChecksum

func (ma *MixedcaseAddress) ValidChecksum() bool

ValidChecksum returns true if the address has valid checksum

type NFT

type NFT struct {
	Id             uint32 `json:"id"`
	Symbol         string `json:"symbol"`
	CreatorId      uint32 `json:"creatorId"`
	ContentHash    Hash   `json:"contentHash"`
	CreatorAddress string `json:"creatorAddress"`
	SerialId       uint32 `json:"serialId"`
	Address        string `json:"address"`
}

func (*NFT) ToToken

func (t *NFT) ToToken() *Token

type OkEthSigner

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

func NewOkEthSignerFromPrivBytes

func NewOkEthSignerFromPrivBytes(privKeyBytes []byte) (*OkEthSigner, error)

func (*OkEthSigner) GetAddress

func (s *OkEthSigner) GetAddress() string

func (*OkEthSigner) SignAuth

func (s *OkEthSigner) SignAuth(txData *ChangePubKey) (*ChangePubKeyECDSA, error)

func (*OkEthSigner) SignBatch

func (s *OkEthSigner) SignBatch(txs []ZksTransaction, nonce uint32, token *Token, fee *big.Int) (*EthSignature, error)

func (*OkEthSigner) SignHash

func (s *OkEthSigner) SignHash(msg []byte) ([]byte, error)

func (*OkEthSigner) SignMessage

func (s *OkEthSigner) SignMessage(msg []byte) ([]byte, error)

func (*OkEthSigner) SignOrder

func (s *OkEthSigner) SignOrder(order *Order, sell, buy *Token) (*EthSignature, error)

func (*OkEthSigner) SignTransaction

func (s *OkEthSigner) SignTransaction(tx ZksTransaction, nonce uint32, token *Token, fee *big.Int) (*EthSignature, error)

type Order

type Order struct {
	AccountId         uint32        `json:"accountId"`
	RecipientAddress  string        `json:"recipient"`
	Nonce             uint32        `json:"nonce"`
	TokenBuy          uint32        `json:"tokenBuy"`
	TokenSell         uint32        `json:"tokenSell"`
	Ratio             []*big.Int    `json:"ratio"`
	Amount            *big.Int      `json:"amount"`
	Signature         *Signature    `json:"signature"`
	EthereumSignature *EthSignature `json:"ethereumSignature"`
	*TimeRange
}

type Signature

type Signature struct {
	PubKey    string `json:"pubKey"`
	Signature string `json:"signature"`
}

type SignedTransaction

type SignedTransaction struct {
	Transaction       ZksTransaction `json:"tx"`
	EthereumSignature *EthSignature  `json:"signature"`
}

type State

type State struct {
	Balances   map[string]string `json:"balances"`
	Nonce      uint32            `json:"nonce"`
	PubKeyHash string            `json:"pubKeyHash"`
	Nfts       map[string]*NFT   `json:"nfts"`
	MintedNfts map[string]*NFT   `json:"mintedNfts"`
}

func (*State) GetBalanceOf

func (s *State) GetBalanceOf(token string) (*big.Int, bool)

type Swap

type Swap struct {
	Type             string     `json:"type"`
	SubmitterId      uint32     `json:"submitterId"`
	SubmitterAddress string     `json:"submitterAddress"`
	Nonce            uint32     `json:"nonce"`
	Orders           []*Order   `json:"orders"`
	Amounts          []*big.Int `json:"amounts"`
	Fee              string     `json:"fee"`
	FeeToken         uint32     `json:"feeToken"`
	Signature        *Signature `json:"signature"`
	*TimeRange
}

type TimeRange

type TimeRange struct {
	ValidFrom  uint64 `json:"validFrom"`
	ValidUntil uint64 `json:"validUntil"`
}

func DefaultTimeRange

func DefaultTimeRange() *TimeRange

type Token

type Token struct {
	Id       uint32 `json:"id"`
	Address  string `json:"address"`
	Symbol   string `json:"symbol"`
	Decimals uint   `json:"decimals"`
	IsNft    bool   `json:"is_nft"`
}

func CreateETH

func CreateETH() *Token

func (Token) GetAddress

func (t Token) GetAddress() string

func (Token) IsETH

func (t Token) IsETH() bool

func (Token) ToDecimalString

func (t Token) ToDecimalString(amount *big.Int) string

type Tokens

type Tokens struct {
	Tokens map[string]*Token
}

func (*Tokens) GetToken

func (ts *Tokens) GetToken(id string) (*Token, error)

type TransactionDetails

type TransactionDetails struct {
	Executed   bool       `json:"executed"`
	Success    bool       `json:"success"`
	FailReason string     `json:"failReason"`
	Block      *BlockInfo `json:"block"`
}

type TransactionFee

type TransactionFee struct {
	FeeToken string   `json:"feeToken"`
	Fee      *big.Int `json:"fee"`
}

type TransactionFeeDetails

type TransactionFeeDetails struct {
	GasTxAmount string `json:"gasTxAmount"`
	GasPriceWei string `json:"gasPriceWei"`
	GasFee      string `json:"gasFee"`
	ZkpFee      string `json:"zkpFee"`
	TotalFee    string `json:"totalFee"`
}

func (*TransactionFeeDetails) GetTotalFee

func (d *TransactionFeeDetails) GetTotalFee() *big.Int

func (*TransactionFeeDetails) GetTxFee

func (d *TransactionFeeDetails) GetTxFee(feeToken *Token) *TransactionFee

type TransactionStatus

type TransactionStatus int
const (
	TransactionStatusSent TransactionStatus = iota
	TransactionStatusCommitted
	TransactionStatusVerified
)

type TransactionType

type TransactionType string
const (
	TransactionTypeChangePubKey_                       = "ChangePubKey"
	TransactionTypeChangePubKeyOnchain TransactionType = "Onchain"
	TransactionTypeChangePubKeyECDSA   TransactionType = "ECDSA"
	TransactionTypeChangePubKeyCREATE2 TransactionType = "CREATE2"
)

type TransactionTypeChangePubKey

type TransactionTypeChangePubKey struct {
	ChangePubKey string `json:"ChangePubKey"`
}

type Transfer

type Transfer struct {
	Type      string     `json:"type"`
	AccountId uint32     `json:"accountId"`
	From      string     `json:"from"`
	To        string     `json:"to"`
	Token     *Token     `json:"-"`
	TokenId   uint32     `json:"token"`
	Amount    *big.Int   `json:"amount"`
	Fee       string     `json:"fee"`
	Nonce     uint32     `json:"nonce"`
	Signature *Signature `json:"signature"`
	*TimeRange
}

func (*Transfer) GetTxHash

func (t *Transfer) GetTxHash() (string, error)

type Uint

type Uint uint

Uint marshals/unmarshals as a JSON string with 0x prefix. The zero value marshals as "0x0".

func (Uint) MarshalText

func (b Uint) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.

func (Uint) String

func (b Uint) String() string

String returns the hex encoding of b.

func (*Uint) UnmarshalJSON

func (b *Uint) UnmarshalJSON(input []byte) error

UnmarshalJSON implements json.Unmarshaler.

func (*Uint) UnmarshalText

func (b *Uint) UnmarshalText(input []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

type Uint64

type Uint64 uint64

Uint64 marshals/unmarshals as a JSON string with 0x prefix. The zero value marshals as "0x0".

func (Uint64) ImplementsGraphQLType

func (b Uint64) ImplementsGraphQLType(name string) bool

ImplementsGraphQLType returns true if Uint64 implements the provided GraphQL type.

func (Uint64) MarshalText

func (b Uint64) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.

func (Uint64) String

func (b Uint64) String() string

String returns the hex encoding of b.

func (*Uint64) UnmarshalGraphQL

func (b *Uint64) UnmarshalGraphQL(input interface{}) error

UnmarshalGraphQL unmarshals the provided GraphQL query data.

func (*Uint64) UnmarshalJSON

func (b *Uint64) UnmarshalJSON(input []byte) error

UnmarshalJSON implements json.Unmarshaler.

func (*Uint64) UnmarshalText

func (b *Uint64) UnmarshalText(input []byte) error

UnmarshalText implements encoding.TextUnmarshaler

type UnprefixedAddress

type UnprefixedAddress Address

UnprefixedAddress allows marshaling an Address without 0x prefix.

func (UnprefixedAddress) MarshalText

func (a UnprefixedAddress) MarshalText() ([]byte, error)

MarshalText encodes the address as hex.

func (*UnprefixedAddress) UnmarshalText

func (a *UnprefixedAddress) UnmarshalText(input []byte) error

UnmarshalText decodes the address from hex. The 0x prefix is optional.

type UnprefixedHash

type UnprefixedHash Hash

UnprefixedHash allows marshaling a Hash without 0x prefix.

func (UnprefixedHash) MarshalText

func (h UnprefixedHash) MarshalText() ([]byte, error)

MarshalText encodes the hash as hex.

func (*UnprefixedHash) UnmarshalText

func (h *UnprefixedHash) UnmarshalText(input []byte) error

UnmarshalText decodes the hash from hex. The 0x prefix is optional.

type Withdraw

type Withdraw struct {
	Type      string     `json:"type"`
	AccountId uint32     `json:"accountId"`
	From      string     `json:"from"`
	To        string     `json:"to"`
	TokenId   uint32     `json:"token"`
	Amount    *big.Int   `json:"amount"`
	Fee       string     `json:"fee"`
	Nonce     uint32     `json:"nonce"`
	Signature *Signature `json:"signature"`
	*TimeRange
}

type WithdrawNFT

type WithdrawNFT struct {
	Type      string     `json:"type"`
	AccountId uint32     `json:"accountId"`
	From      string     `json:"from"`
	To        string     `json:"to"`
	Token     uint32     `json:"token"`
	FeeToken  uint32     `json:"feeToken"`
	Fee       string     `json:"fee"`
	Nonce     uint32     `json:"nonce"`
	Signature *Signature `json:"signature"`
	*TimeRange
}

type ZkSigner

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

func NewZkSignerFromEthSigner

func NewZkSignerFromEthSigner(es EthSigner, cid ChainId) (*ZkSigner, error)

func NewZkSignerFromSeed

func NewZkSignerFromSeed(seed []byte) (*ZkSigner, error)

func (*ZkSigner) GetPublicKey

func (s *ZkSigner) GetPublicKey() string

func (*ZkSigner) GetPublicKeyHash

func (s *ZkSigner) GetPublicKeyHash() string

func (*ZkSigner) Sign

func (s *ZkSigner) Sign(message []byte) (*zkscrypto.Signature, error)

func (*ZkSigner) SignChangePubKey

func (s *ZkSigner) SignChangePubKey(txData *ChangePubKey) (*Signature, error)

func (*ZkSigner) SignForcedExit

func (s *ZkSigner) SignForcedExit(txData *ForcedExit) (*Signature, error)

func (*ZkSigner) SignMintNFT

func (s *ZkSigner) SignMintNFT(txData *MintNFT) (*Signature, error)

func (*ZkSigner) SignTransfer

func (s *ZkSigner) SignTransfer(txData *Transfer) (*Signature, error)

func (*ZkSigner) SignWithdraw

func (s *ZkSigner) SignWithdraw(txData *Withdraw) (*Signature, error)

func (*ZkSigner) SignWithdrawNFT

func (s *ZkSigner) SignWithdrawNFT(txData *WithdrawNFT) (*Signature, error)

type ZksTransaction

type ZksTransaction interface {
	// contains filtered or unexported methods
}

Jump to

Keyboard shortcuts

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