Documentation
¶
Index ¶
- Variables
- func ComputeDomainSeparator(domain EIP712Domain) [32]byte
- func ComputeEIP712Hash(domainSeparator, messageHash [32]byte) [32]byte
- func ComputeMessageHash(msg NonceMessage) [32]byte
- func DeployAndFundERC20(ctx context.Context, be LocalBackend, name, symbol string, decimal uint8, ...) (common.Address, *test_erc20.TestERC20, error)
- func DeployERC20(ctx context.Context, be LocalBackend, name, symbol string, decimals uint8, ...) (common.Address, *test_erc20.TestERC20, error)
- func FundERC20(ctx context.Context, be LocalBackend, tokenContract *test_erc20.TestERC20, ...) error
- func GenerateKeyPair() (*ecdsa.PrivateKey, *ecdsa.PublicKey, error)
- func Nonce(length int) ([]byte, error)
- func RegisterES256Signer()
- func SignEIP712Hash(privKey *ecdsa.PrivateKey, domain EIP712Domain, msg NonceMessage) ([]byte, error)
- func VerifySignature(domain EIP712Domain, msg NonceMessage, sig []byte, ...) (bool, error)
- type Address
- type AssetConfig
- type Backend
- type Deployer
- type DeploymentResult
- type EIP712Domain
- type EIP712SignatureData
- type ES256Signer
- type Hash
- type LocalBackend
- type LocalSigner
- type NodeBackend
- type NonceMessage
- type Signature
- func (s1 Signature) Equal(s2 Signature) bool
- func (s Signature) MarshalJSON() ([]byte, error)
- func (sig Signature) Raw() (concatenatedSignature []byte)
- func (sig Signature) RecoverPublicKey(msg []byte) (*ecdsa.PublicKey, error)
- func (sig Signature) String() string
- func (s *Signature) UnmarshalJSON(b []byte) error
- type Signer
- type SimulatedAccount
- type SimulatedAsset
- type SimulatedBackend
- func (sb *SimulatedBackend) Account(id int) (*SimulatedAccount, error)
- func (sb *SimulatedBackend) ChainID(ctx context.Context) (*big.Int, error)
- func (sb *SimulatedBackend) Deployer() *SimulatedAccount
- func (sb *SimulatedBackend) PrepareTx(t *testing.T, callTx *ethereum.CallMsg, account *SimulatedAccount) (*types.Transaction, error)
- func (sb *SimulatedBackend) WaitMined(ctx context.Context, tx *types.Transaction) (*types.Receipt, error)
- func (sb *SimulatedBackend) WaitMinedPeriod() time.Duration
- type SimulatedBackendConfig
- type SimulatedEnvironment
- type SimulatedEnvironmentConfig
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidSignerType is returned when the key is not a valid eth.Signer ErrInvalidSignerType = errors.New("key is not of type eth.Signer") // ErrInvalidKeyType is returned when the key is not of the expected type ErrInvalidKeyType = errors.New("key is not of valid type") // ErrInvalidSigningString is returned when the signing string is invalid ErrInvalidSigningString = errors.New("invalid signing string") )
var ( DEFAULT_INTERVAL = 10 * time.Millisecond DEFAULT_START_BLOCK = uint64(1) DEFAULT_EXISTING_BLOCKS = DEFAULT_START_BLOCK + 1 )
var DEFAULT_FUNDING_AMOUNT = big.NewInt(0).SetUint64(1000000000000000000) // 1 ETH
DEFAULT_FUNDING_AMOUNT is the default amount of Ether assigned to each test account (1 ETH).
var SimulatedChainID = big.NewInt(1337)
SimulatedChainID is the chain ID used by the simulated environment, default is 1337.
Functions ¶
func ComputeDomainSeparator ¶
func ComputeDomainSeparator(domain EIP712Domain) [32]byte
ComputeDomainSeparator hashes the domain fields into a 32-byte domain separator.
func ComputeEIP712Hash ¶
ComputeEIP712Hash creates the final EIP-191–style message hash: keccak256(0x19, 0x01, domainSeparator, messageHash).
func ComputeMessageHash ¶
func ComputeMessageHash(msg NonceMessage) [32]byte
ComputeMessageHash builds a 32-byte hash of the NonceMessage struct using EIP-712 encoding.
func DeployAndFundERC20 ¶
func DeployERC20 ¶
func FundERC20 ¶
func FundERC20( ctx context.Context, be LocalBackend, tokenContract *test_erc20.TestERC20, funding map[common.Address]*big.Int, ) error
func GenerateKeyPair ¶
func GenerateKeyPair() (*ecdsa.PrivateKey, *ecdsa.PublicKey, error)
GenerateKeyPair creates a new private/public keypair for demonstration or testing.
func Nonce ¶
RandomNonce returns a secure random byte slice of the specified length. The output includes only characters A-Z, a-z, and 0-9.
func RegisterES256Signer ¶
func RegisterES256Signer()
RegisterES256Signer registers the ES256Signer as a JWT signing method
func SignEIP712Hash ¶
func SignEIP712Hash(privKey *ecdsa.PrivateKey, domain EIP712Domain, msg NonceMessage) ([]byte, error)
SignEIP712Hash produces an EIP-712 signature using the provided private key, domain, and message.
func VerifySignature ¶
func VerifySignature(domain EIP712Domain, msg NonceMessage, sig []byte, signerPubKey *ecdsa.PublicKey) (bool, error)
VerifySignature checks whether the provided signature corresponds to the given public key and message data.
Types ¶
type Address ¶
Address represents a common.Address stored as a hexadecimal string with a 0x prefix.
func NewAddressFromPubkey ¶
type AssetConfig ¶
type Backend ¶
type Backend interface {
ethereum.ChainReader
ethereum.ChainStateReader
ethereum.TransactionReader
ethereum.TransactionSender
ethereum.ContractCaller
ChainID(ctx context.Context) (*big.Int, error)
WaitMinedPeriod() time.Duration
bind.ContractBackend
}
type Deployer ¶
type Deployer interface {
Deploy(ctx context.Context, backend LocalBackend) (common.Address, *types.Transaction, error)
}
Deployer is a shortcut for deploying new contracts. The contract is assumed to be configured by the implementor.
type DeploymentResult ¶
type DeploymentResult struct {
Address common.Address
Transaction *types.Transaction
}
type EIP712Domain ¶
type EIP712Domain struct {
Name string // e.g. "My DApp"
Version string // e.g. "1"
ChainID *big.Int // e.g. big.NewInt(1) for mainnet
VerifyingContract common.Address
}
EIP712Domain represents a minimal EIP-712 domain struct.
type EIP712SignatureData ¶
type EIP712SignatureData struct {
Domain EIP712Domain
Message NonceMessage
}
EIP712SignatureData encapsulates the domain and message for typed hashing and signature.
type ES256Signer ¶
type ES256Signer struct{}
ES256Signer implements jwt.SigningMethod for ES256 using an eth.Signer
type Hash ¶
Hash represents a common.Hash stored as a hexadecimal string with a 0x prefix.
type LocalBackend ¶
type LocalBackend interface {
Backend
Deployer() *SimulatedAccount
}
type LocalSigner ¶
type LocalSigner struct {
// contains filtered or unexported fields
}
func NewLocalSigner ¶
func NewLocalSigner(privateKey *ecdsa.PrivateKey) LocalSigner
func (LocalSigner) Address ¶
func (s LocalSigner) Address() Address
func (LocalSigner) PublicKey ¶
func (s LocalSigner) PublicKey() *ecdsa.PublicKey
type NodeBackend ¶
func NewNodeBackend ¶
func NewNodeBackend(rpcUrl url.URL) (*NodeBackend, error)
func (*NodeBackend) WaitMined ¶
func (b *NodeBackend) WaitMined(ctx context.Context, tx *types.Transaction) (*types.Receipt, error)
WaitMined waits for tx to be mined on the blockchain. It stops waiting when the context is canceled.
func (*NodeBackend) WaitMinedPeriod ¶
func (n *NodeBackend) WaitMinedPeriod() time.Duration
type NonceMessage ¶
type NonceMessage []byte
NonceMessage stores the data you want to sign, in this case a simple nonce as either a string or byte array.
type Signature ¶
func NewSignature ¶
func NewSignatureFromBytes ¶
func (Signature) MarshalJSON ¶
func (Signature) RecoverPublicKey ¶
func (*Signature) UnmarshalJSON ¶
type SimulatedAccount ¶
type SimulatedAccount struct {
PrivateKey *ecdsa.PrivateKey
CommonAddress common.Address
TransactOpts *bind.TransactOpts
Signer signer.LocalSigner
}
func NewSimulatedAccount ¶
func NewSimulatedAccount(chainID *big.Int) (SimulatedAccount, error)
func NewSimulatedAccountWithPrivateKey ¶
func NewSimulatedAccountWithPrivateKey(privateKey *ecdsa.PrivateKey, chainID *big.Int) (SimulatedAccount, error)
type SimulatedAsset ¶
func NewSimulatedAsset ¶
type SimulatedBackend ¶
type SimulatedBackend struct {
*simulated.Backend
simulated.Client
// contains filtered or unexported fields
}
SimulatedBackend wraps the simulated backend, client, accounts, and deployer.
func NewSimulatedBackend ¶
func NewSimulatedBackend(config SimulatedBackendConfig) (*SimulatedBackend, error)
NewSimulatedBackend creates a new SimulatedBackend instance with 10 accounts funded by the default allocation. If supplied interval is not `nil`, then starts a goroutine that commits new blocks with the interval.
func (*SimulatedBackend) Account ¶
func (sb *SimulatedBackend) Account(id int) (*SimulatedAccount, error)
Account returns a pointer to the SimulatedAccount at the given id or an error if the id is out of range.
func (*SimulatedBackend) Deployer ¶
func (sb *SimulatedBackend) Deployer() *SimulatedAccount
Deployer returns a pointer to the deployer account used by the SimulatedBackend.
func (*SimulatedBackend) PrepareTx ¶
func (sb *SimulatedBackend) PrepareTx(t *testing.T, callTx *ethereum.CallMsg, account *SimulatedAccount) (*types.Transaction, error)
PrepareTx prepares a transaction using a provided testing object, call message, and the given SimulatedAccount.
func (*SimulatedBackend) WaitMined ¶
func (sb *SimulatedBackend) WaitMined(ctx context.Context, tx *types.Transaction) (*types.Receipt, error)
WaitMined waits for the specified transaction to be mined or until the context is canceled.
func (*SimulatedBackend) WaitMinedPeriod ¶
func (sb *SimulatedBackend) WaitMinedPeriod() time.Duration
WaitMinedPeriod is the time interval to wait between block commits when simulating transactions.
type SimulatedBackendConfig ¶
type SimulatedEnvironment ¶
type SimulatedEnvironment struct {
Backend LocalBackend
// contains filtered or unexported fields
}
func NewSimulatedEnvironment ¶
func NewSimulatedEnvironment(ctx context.Context, config SimulatedEnvironmentConfig) (sim SimulatedEnvironment, err error)
func (*SimulatedEnvironment) Accounts ¶
func (env *SimulatedEnvironment) Accounts() []SimulatedAccount
func (*SimulatedEnvironment) DeployContract ¶
func (env *SimulatedEnvironment) DeployContract(deployer Deployer) (DeploymentResult, error)
func (*SimulatedEnvironment) DeployToken ¶
func (env *SimulatedEnvironment) DeployToken(ctx context.Context, asset AssetConfig) (SimulatedAsset, error)