eth2deposit

package module
v1.0.12 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2025 License: GPL-3.0 Imports: 19 Imported by: 2 modules, 2 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

GoDoc MIT licensed

eth2deposit

A Golang library for runtime ETH2 staking

Features

Installation

$ go get github.com/RockX-SG/eth2deposit

API is experimental and may have unstable changes. You should pin a version.

Status

Beta

Documentation

Overview

This package aims to enhance online staking service procedure with safe usage of master key to derive child keys

package main

import (
	"crypto/rand"
	"fmt"
	"io"

	"github.com/RockX-SG/eth2deposit"
	"github.com/awnumar/memguard"
)

func main() {
	// Safely terminate in case of an interrupt signal
	memguard.CatchInterrupt()
	// Purge the session when we return
	defer memguard.Purge()

	var seed [32]byte
	io.ReadFull(rand.Reader, seed[:])

	// create master key and dervie 100th child key
	masterKey := eth2deposit.NewMasterKey(seed)
	lockedBuffer, err := masterKey.DeriveChild(100)
	if err != nil {
		panic(err)
	}

	// create a deposit credential
	cred, err := eth2deposit.NewCredential(lockedBuffer, 0, nil, eth2deposit.MainnetSetting)
	if err != nil {
		panic(err)
	}

	bts, err := cred.MarshalText()
	if err != nil {
		panic(err)
	}

	fmt.Println(string(bts))
}

Code generated by fastssz. DO NOT EDIT. Hash: 3e913cb74b7db9eb4049edc1b26de7a2274819ea5f34346389b2c3f2555658ed Version: 0.1.3-dev

Index

Constants

View Source
const (
	K = 32
	L = K * 255
)
View Source
const (
	MAINNET = "mainnet"
	PYRMONT = "pyrmont"
	PRATER  = "prater"
	HOLESKY = "holesky"
	HOODI   = "hoodi"
)
View Source
const DEPOSIT_CLI_VERSION = "2.8.0"
View Source
const (
	SeedLength = 32
)

Variables

View Source
var (
	R, _ = new(big.Int).SetString("52435875175126190479447740508185965837690552500527637822603658699938581184513", 10)
)

Functions

func ComputeDepositDomain added in v1.0.8

func ComputeDepositDomain(fork_version [4]byte) ([]byte, error)

func ComputeDepositForkDataRoot added in v1.0.8

func ComputeDepositForkDataRoot(current_version [4]byte) ([]byte, error)

func ComputeSigningRoot added in v1.0.8

func ComputeSigningRoot(ssz_object ssz.HashRoot, domain []byte) ([]byte, error)

Types

type BaseChainSetting

type BaseChainSetting struct {
	ETH2_NETWORK_NAME    string
	GENESIS_FORK_VERSION [4]byte
}
var (
	MainnetSetting BaseChainSetting
	PyrmontSetting BaseChainSetting
	PraterSetting  BaseChainSetting
	HoleskySetting BaseChainSetting
	HoodiSetting   BaseChainSetting
)

type CompactDepositData

type CompactDepositData struct {
	PubKey             string `json:"pubkey"`
	WithdrawCredential string `json:"withdrawal_credentials"`
	Amount             int    `json:"amount"`
	Signature          string `json:"signature"`
	DepositMessageRoot string `json:"deposit_message_root"`
	DepositDataRoot    string `json:"deposit_data_root"`
	ForkVersion        string `json:"fork_version"`
	Eth2NetworkName    string `json:"network_name"`
	DepositCliVersion  string `json:"deposit_cli_version"`
}

type Credential

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

Credential defines a ETH2 bls signing credential

func NewCredential

func NewCredential(buf *memguard.LockedBuffer, account uint32, hex_eth1_withdrawal_address []byte, chain BaseChainSetting) (*Credential, error)

NewCredential creates an ETH2 BLS signing credential

func (*Credential) DepositMessage

func (cred *Credential) DepositMessage() (*DepositMessage, error)

DepositMessage retrieves deposit message

func (*Credential) MarshalText

func (cred *Credential) MarshalText() ([]byte, error)

String returns json string compatible with eth2deposit

func (*Credential) SignedDeposit

func (cred *Credential) SignedDeposit() (*DepositData, error)

SignedDeposit returns the deposit data

func (*Credential) SigningPK

func (cred *Credential) SigningPK() (pub []byte, err error)

SigningPK returns public key of BLS signing account

func (*Credential) SigningSK

func (cred *Credential) SigningSK() (*memguard.LockedBuffer, error)

SigningSK returns locked signing secret key in 10-based string

func (*Credential) WithdrawCredentials

func (cred *Credential) WithdrawCredentials() ([]byte, error)

WithdrawCredentials returns credential bytes

func (*Credential) WithdrawalPK

func (cred *Credential) WithdrawalPK() (pub []byte, err error)

WithdrawalPK returns public key of BLS withdrawal account

func (*Credential) WithdrawalSK

func (cred *Credential) WithdrawalSK() (*memguard.LockedBuffer, error)

WithdrawalSK returns locked withdraw secret key in 10-based string

type CredentialV2 added in v1.0.12

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

Credential defines a ETH2 bls signing credential

func NewCredentialV2 added in v1.0.12

func NewCredentialV2(buf *memguard.LockedBuffer, account uint32, hex_eth1_withdrawal_address []byte, chain BaseChainSetting, amount uint64) (*CredentialV2, error)

NewCredential creates an ETH2 BLS signing credential

func (*CredentialV2) DepositMessage added in v1.0.12

func (cred *CredentialV2) DepositMessage() (*DepositMessage, error)

DepositMessage retrieves deposit message

func (*CredentialV2) MarshalText added in v1.0.12

func (cred *CredentialV2) MarshalText() ([]byte, error)

String returns json string compatible with eth2deposit

func (*CredentialV2) SignedDeposit added in v1.0.12

func (cred *CredentialV2) SignedDeposit() (*DepositData, error)

SignedDeposit returns the deposit data

func (*CredentialV2) SigningPK added in v1.0.12

func (cred *CredentialV2) SigningPK() (pub []byte, err error)

SigningPK returns public key of BLS signing account

func (*CredentialV2) SigningSK added in v1.0.12

func (cred *CredentialV2) SigningSK() (*memguard.LockedBuffer, error)

SigningSK returns locked signing secret key in 10-based string

func (*CredentialV2) WithdrawCredentials added in v1.0.12

func (cred *CredentialV2) WithdrawCredentials() ([]byte, error)

WithdrawCredentials returns credential bytes

func (*CredentialV2) WithdrawalPK added in v1.0.12

func (cred *CredentialV2) WithdrawalPK() (pub []byte, err error)

WithdrawalPK returns public key of BLS withdrawal account

func (*CredentialV2) WithdrawalSK added in v1.0.12

func (cred *CredentialV2) WithdrawalSK() (*memguard.LockedBuffer, error)

WithdrawalSK returns locked withdraw secret key in 10-based string

type DepositData

type DepositData struct {
	Pubkey                [48]byte `json:"pubkey" ssz-size:"48"`
	WithdrawalCredentials [32]byte `json:"withdrawal_credentials" ssz-size:"32"`
	Amount                uint64   `json:"amount"`
	Signature             [96]byte `json:"signature" ssz-size:"96"`
	Root                  [32]byte `ssz:"-"`
}

func (*DepositData) GetTree added in v1.0.10

func (d *DepositData) GetTree() (*ssz.Node, error)

GetTree ssz hashes the DepositData object

func (*DepositData) HashTreeRoot

func (d *DepositData) HashTreeRoot() ([32]byte, error)

HashTreeRoot ssz hashes the DepositData object

func (*DepositData) HashTreeRootWith

func (d *DepositData) HashTreeRootWith(hh ssz.HashWalker) (err error)

HashTreeRootWith ssz hashes the DepositData object with a hasher

func (*DepositData) MarshalSSZ

func (d *DepositData) MarshalSSZ() ([]byte, error)

MarshalSSZ ssz marshals the DepositData object

func (*DepositData) MarshalSSZTo

func (d *DepositData) MarshalSSZTo(buf []byte) (dst []byte, err error)

MarshalSSZTo ssz marshals the DepositData object to a target array

func (*DepositData) SizeSSZ

func (d *DepositData) SizeSSZ() (size int)

SizeSSZ returns the ssz encoded size in bytes for the DepositData object

func (*DepositData) UnmarshalSSZ

func (d *DepositData) UnmarshalSSZ(buf []byte) error

UnmarshalSSZ ssz unmarshals the DepositData object

type DepositMessage

type DepositMessage struct {
	Pubkey                [48]byte `json:"pubkey" ssz-size:"48"`
	WithdrawalCredentials [32]byte `json:"withdrawal_credentials" ssz-size:"32"`
	Amount                uint64   `json:"amount"`
}

func (*DepositMessage) GetTree added in v1.0.10

func (d *DepositMessage) GetTree() (*ssz.Node, error)

GetTree ssz hashes the DepositMessage object

func (*DepositMessage) HashTreeRoot

func (d *DepositMessage) HashTreeRoot() ([32]byte, error)

HashTreeRoot ssz hashes the DepositMessage object

func (*DepositMessage) HashTreeRootWith

func (d *DepositMessage) HashTreeRootWith(hh ssz.HashWalker) (err error)

HashTreeRootWith ssz hashes the DepositMessage object with a hasher

func (*DepositMessage) MarshalSSZ

func (d *DepositMessage) MarshalSSZ() ([]byte, error)

MarshalSSZ ssz marshals the DepositMessage object

func (*DepositMessage) MarshalSSZTo

func (d *DepositMessage) MarshalSSZTo(buf []byte) (dst []byte, err error)

MarshalSSZTo ssz marshals the DepositMessage object to a target array

func (*DepositMessage) SizeSSZ

func (d *DepositMessage) SizeSSZ() (size int)

SizeSSZ returns the ssz encoded size in bytes for the DepositMessage object

func (*DepositMessage) UnmarshalSSZ

func (d *DepositMessage) UnmarshalSSZ(buf []byte) error

UnmarshalSSZ ssz unmarshals the DepositMessage object

type ForkData

type ForkData struct {
	CurrentVersion       [4]byte  `json:"current_version" ssz-size:"4"`
	GenesisValidatorRoot [32]byte `json:"genesis_validators_root" ssz-size:"32"`
}

func (*ForkData) GetTree added in v1.0.10

func (f *ForkData) GetTree() (*ssz.Node, error)

GetTree ssz hashes the ForkData object

func (*ForkData) HashTreeRoot

func (f *ForkData) HashTreeRoot() ([32]byte, error)

HashTreeRoot ssz hashes the ForkData object

func (*ForkData) HashTreeRootWith

func (f *ForkData) HashTreeRootWith(hh ssz.HashWalker) (err error)

HashTreeRootWith ssz hashes the ForkData object with a hasher

func (*ForkData) MarshalSSZ

func (f *ForkData) MarshalSSZ() ([]byte, error)

MarshalSSZ ssz marshals the ForkData object

func (*ForkData) MarshalSSZTo

func (f *ForkData) MarshalSSZTo(buf []byte) (dst []byte, err error)

MarshalSSZTo ssz marshals the ForkData object to a target array

func (*ForkData) SizeSSZ

func (f *ForkData) SizeSSZ() (size int)

SizeSSZ returns the ssz encoded size in bytes for the ForkData object

func (*ForkData) UnmarshalSSZ

func (f *ForkData) UnmarshalSSZ(buf []byte) error

UnmarshalSSZ ssz unmarshals the ForkData object

type MasterKey

type MasterKey struct {
	N *big.Int
	// contains filtered or unexported fields
}

MasterKey defines an enclaved master key for offering online service

func NewMasterKey

func NewMasterKey(seed [SeedLength]byte) *MasterKey

NewMasterKey creates an encalved key

func (*MasterKey) DeriveChild

func (mkey *MasterKey) DeriveChild(path string) (*memguard.LockedBuffer, error)

DeriveChild derives crypto-strong child key

Approach:

For Each Level of Subkey Generation:

secret := hmac(rockx.com/eth/key_id/%v(string), parentKey)
pubkey := p256.ScalaBaseMult(secret)
childKey := hash(pubkey)

type SigningData

type SigningData struct {
	ObjectRoot [32]byte `json:"current_version" ssz-size:"32"`
	Domain     [32]byte `json:"domain" ssz-size:"32"`
}

func (*SigningData) GetTree added in v1.0.10

func (s *SigningData) GetTree() (*ssz.Node, error)

GetTree ssz hashes the SigningData object

func (*SigningData) HashTreeRoot

func (s *SigningData) HashTreeRoot() ([32]byte, error)

HashTreeRoot ssz hashes the SigningData object

func (*SigningData) HashTreeRootWith

func (s *SigningData) HashTreeRootWith(hh ssz.HashWalker) (err error)

HashTreeRootWith ssz hashes the SigningData object with a hasher

func (*SigningData) MarshalSSZ

func (s *SigningData) MarshalSSZ() ([]byte, error)

MarshalSSZ ssz marshals the SigningData object

func (*SigningData) MarshalSSZTo

func (s *SigningData) MarshalSSZTo(buf []byte) (dst []byte, err error)

MarshalSSZTo ssz marshals the SigningData object to a target array

func (*SigningData) SizeSSZ

func (s *SigningData) SizeSSZ() (size int)

SizeSSZ returns the ssz encoded size in bytes for the SigningData object

func (*SigningData) UnmarshalSSZ

func (s *SigningData) UnmarshalSSZ(buf []byte) error

UnmarshalSSZ ssz unmarshals the SigningData object

type WithdrawType

type WithdrawType int

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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