common

package
v0.0.0-...-5cda5f8 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2023 License: MIT Imports: 27 Imported by: 2

Documentation

Index

Constants

View Source
const (
	AskStateBatch  Method = "askStateBatch"
	SignStateBatch Method = "signStateBatch"
	AskSlash       Method = "askSlash"
	SignSlash      Method = "signSlash"
	SignRollBack   Method = "signRollBack"
	AskRollBack    Method = "askRollBack"

	SlashTypeLiveness byte = 0
	SlashTypeCulprit  byte = 1

	CulpritErrorCode = 100
)
View Source
const (
	JwtSecretLength = 32
)

Variables

This section is empty.

Functions

func EnsureConnection

func EnsureConnection(client *ethclient.Client) error

Ensure we can actually connect l1

func EstimateGas

func EstimateGas(client *ethclient.Client, prikey *ecdsa.PrivateKey, chainId *big.Int, ctx context.Context, tx *types.Transaction, rawContract *bind.BoundContract, to common.Address) (*types.Transaction, error)

func GetMerkleRoot

func GetMerkleRoot(elements [][32]byte) ([32]byte, error)

GetMerkleRoot Calculates a merkle root for a list of 32-byte leaf hashes. WARNING: If the number of leaves passed in is not a power of two, it pads out the tree with zero hashes. If you do not know the original length of elements for the tree you are verifying, then this may allow empty leaves past elements.length to pass a verification check down the line. Note that the _elements argument is modified, therefore it must not be used again afterwards @param elements Array of hashes from which to generate a merkle root. @return Merkle root of the leaves, with zero hashes for non-powers-of-two (see above).

func IsAddrExist

func IsAddrExist(set []common.Address, find common.Address) bool

func NewJwtHandler

func NewJwtHandler(handle http.Handler, jetSecretKey string) (http.Handler, error)

func NodeToAddress

func NodeToAddress(publicKey string) (common.Address, error)

func RollBackHash

func RollBackHash(startBlock *big.Int) ([]byte, error)

func SetCmdConfig

func SetCmdConfig(cmd *cobra.Command, config Configuration) error

func SetGroupPubKeyBytes

func SetGroupPubKeyBytes(localKey, poolPubKey []byte) ([]byte, error)

func SlashBytes

func SlashBytes(msg, sig []byte) ([]byte, error)

func SlashMsgBytes

func SlashMsgBytes(batchIndex uint64, jailNode common.Address, tssNodes []common.Address, slashType byte) ([]byte, error)

func SlashMsgHash

func SlashMsgHash(batchIndex uint64, jailNode common.Address, tssNodes []common.Address, slashType byte) ([]byte, error)

func StateBatchHash

func StateBatchHash(stateRoots [][32]byte, offsetStartsAtIndex *big.Int) ([]byte, error)

Types

type AKSKConfig

type AKSKConfig struct {
	Id     string `json:"id" mapstructure:"id"`
	Secret string `json:"secret" mapstructure:"secret"`
}

type AskResponse

type AskResponse struct {
	Result bool `json:"result"`
}

type BatchSubmitterResponse

type BatchSubmitterResponse struct {
	Signature []byte `json:"signature"`
	RollBack  bool   `json:"roll_back"`
}

type Configuration

type Configuration struct {
	Manager                        ManagerConfig `json:"manager"`
	Node                           NodeConfig    `json:"node"`
	L1Url                          string        `json:"l1_url" mapstructure:"l1_url"`
	SccContractAddress             string        `json:"scc_contract_address" mapstructure:"scc_contract_address"`
	TssGroupContractAddress        string        `json:"tss_group_contract_address" mapstructure:"tss_group_contract_address"`
	TssStakingSlashContractAddress string        `json:"tss_staking_slash_contract_address" mapstructure:"tss_staking_slash_contract_address"`
	TimedTaskInterval              string        `json:"timed_task_interval" mapstructure:"timed_task_interval"`
	L1ReceiptConfirmTimeout        string        `json:"l1_receipt_confirm_timeout" mapstructure:"l1_receipt_confirm_timeout"`
	L1ConfirmBlocks                int           `json:"l1_confirm_blocks" mapstructure:"l1_confirm_blocks"`
	L1StartBlockNumber             string        `json:"l1_start_block_number" mapstructure:"l1_start_block_number"`
	MissSignedNumber               int           `json:"miss_signed_number" mapstructure:"miss_signed_number"`
}

func DefaultConfiguration

func DefaultConfiguration() Configuration

func GetConfigFromCmd

func GetConfigFromCmd(cmd *cobra.Command) Configuration

func LoadConfig

func LoadConfig(file string) (Configuration, error)

type JwtHandler

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

func (*JwtHandler) ServeHTTP

func (handler *JwtHandler) ServeHTTP(out http.ResponseWriter, r *http.Request)

ServeHTTP implements http.Handler

type KeygenRequest

type KeygenRequest struct {
	Nodes      []string `json:"nodes"`
	ElectionId uint64   `json:"election_id"`
	Threshold  int      `json:"threshold"`
	Timestamp  int64    `json:"timestamp"`
}

type KeygenResponse

type KeygenResponse struct {
	ClusterPublicKey string `json:"cluster_public_key"`
}

type KmsConfig

type KmsConfig struct {
	KeyId  string     `json:"key_id" mapstructure:"key_id"`
	Region string     `json:"region" mapstructure:"region"`
	Aksk   AKSKConfig `json:"aksk" mapstructure:"aksk"`
}

type ManagerConfig

type ManagerConfig struct {
	WsAddr     string `json:"ws_addr" mapstructure:"ws_addr"`
	HttpAddr   string `json:"http_addr" mapstructure:"http_addr"`
	JwtSecret  string `json:"jwt_secret" mapstructure:"jwt_secret"`
	DBDir      string `json:"db_dir" mapstructure:"db_dir"`
	PrivateKey string `json:"private_key" mapstructure:"private_key"`

	KeygenTimeout     string `json:"keygen_timeout" mapstructure:"keygen_timeout"`
	CPKConfirmTimeout string `json:"cpk_confirm_timeout" mapstructure:"cpk_confirm_timeout"`
	AskTimeout        string `json:"ask_timeout" mapstructure:"ask_timeout"`
	SignTimeout       string `json:"sign_timeout" mapstructure:"sign_timeout"`
}

type Method

type Method string

func (Method) String

func (m Method) String() string

type NodeConfig

type NodeConfig struct {
	BaseDir      string `json:"base_dir" mapstructure:"base_dir"`
	DBDir        string `json:"db_dir" mapstructure:"db_dir"`
	WsAddr       string `json:"ws_addr" mapstructure:"ws_addr"`
	HttpAddr     string `json:"http_addr" mapstructure:"http_addr"`
	JwtSecret    string `json:"jwt_secret" mapstructure:"jwt_secret"`
	L2EthRpc     string `json:"l2_eth_rpc" mapstructure:"l2_eth_rpc"`
	DisableHTTP2 bool   `json:"disable_http2" mapstructure:"disable_http2"`
	PrivateKey   string `json:"private_key" mapstructure:"private_key"`

	PreParamFile    string        `json:"pre_param_file" mapstructure:"pre_param_file"`
	P2PPort         string        `json:"p2p_port" mapstructure:"p2p_port"`
	BootstrapPeers  string        `json:"bootstrap_peers" mapstructure:"bootstrap_peers"`
	ExternalIP      string        `json:"external_ip" mapstructure:"external_ip"`
	KeyGenTimeout   time.Duration `json:"key_gen_timeout" mapstructure:"key_gen_timeout"`
	KeySignTimeout  time.Duration `json:"key_sign_timeout" mapstructure:"key_sign_timeout"`
	PreParamTimeout time.Duration `json:"pre_param_timeout" mapstructure:"pre_param_timeout"`
	GasLimitScaler  int           `json:"gas_limit_scaler" mapstructure:"gas_limit_scaler"`

	Secrets SecretsManagerConfig `json:"secrets" mapstructure:"secrets"`
	Shamir  ShamirConfig         `json:"shamir" mapstructure:"shamir"`
}

type NodeSignRequest

type NodeSignRequest struct {
	ClusterPublicKey string      `json:"cluster_public_key"`
	Timestamp        int64       `json:"timestamp"`
	Nodes            []string    `json:"nodes"`
	RequestBody      interface{} `json:"request_body"`
}

type RollBackRequest

type RollBackRequest struct {
	StartBlock *big.Int `json:"start_block"`
}

type S3Config

type S3Config struct {
	Region  string     `json:"region" mapstructure:"region"`
	Buckets string     `json:"buckets" mapstructure:"buckets"`
	Aksk    AKSKConfig `json:"aksk" mapstructure:"aksk"`
}

type SMConfig

type SMConfig struct {
	Region    string     `json:"region" mapstructure:"region"`
	SecretIds string     `json:"secretIds" mapstructure:"secretIds"`
	Aksk      AKSKConfig `json:"aksk" mapstructure:"aksk"`
}

type SecretsManagerConfig

type SecretsManagerConfig struct {
	Enable   bool   `json:"enable" mapstructure:"enable"`
	SecretId string `json:"secret_id" mapstructure:"secret_id"`
}

type ShamirConfig

type ShamirConfig struct {
	Enable bool      `json:"enable" mapstructure:"enable"`
	Kms    KmsConfig `json:"kms" mapstructure:"kms"`
	S3     S3Config  `json:"s3" mapstructure:"s3"`
	Sm     SMConfig  `json:"sm" mapstructure:"sm"`
	Xor    string    `json:"xor" mapstructure:"xor"`
}

type SignResponse

type SignResponse struct {
	Signature []byte `json:"signature"`
}

type SignStateRequest

type SignStateRequest struct {
	Type                uint64     `json:"type"`
	StartBlock          *big.Int   `json:"start_block"`
	OffsetStartsAtIndex *big.Int   `json:"offset_starts_at_index"`
	Challenge           string     `json:"challenge"`
	StateRoots          [][32]byte `json:"state_roots"`
	ElectionId          uint64     `json:"election_id"`
}

func (SignStateRequest) String

func (ssr SignStateRequest) String() string

type SignatureData

type SignatureData struct {
	// Ethereum-style recovery byte; only the first byte is relevant
	SignatureRecovery []byte `json:"signature_recovery,omitempty"`
	// Signature components R, S
	R []byte `json:"r,omitempty"`
	S []byte `json:"s,omitempty"`
	// M represents the original message digest that was signed M
	M []byte `json:"m,omitempty"`
}

type SlashMsg

type SlashMsg struct {
	BatchIndex *big.Int
	JailNode   common.Address
	TssNodes   []common.Address
	SlashType  *big.Int
}

type SlashRequest

type SlashRequest struct {
	Address    common.Address `json:"address"`
	BatchIndex uint64         `json:"batch_index"`
	SignType   byte           `json:"sign_type"`
}

Jump to

Keyboard shortcuts

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