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
- Variables
- func ComputeDepositDomain(fork_version [4]byte) ([]byte, error)
- func ComputeDepositForkDataRoot(current_version [4]byte) ([]byte, error)
- func ComputeSigningRoot(ssz_object ssz.HashRoot, domain []byte) ([]byte, error)
- type BaseChainSetting
- type CompactDepositData
- type Credential
- func (cred *Credential) DepositMessage() (*DepositMessage, error)
- func (cred *Credential) MarshalText() ([]byte, error)
- func (cred *Credential) SignedDeposit() (*DepositData, error)
- func (cred *Credential) SigningPK() (pub []byte, err error)
- func (cred *Credential) SigningSK() (*memguard.LockedBuffer, error)
- func (cred *Credential) WithdrawCredentials() ([]byte, error)
- func (cred *Credential) WithdrawalPK() (pub []byte, err error)
- func (cred *Credential) WithdrawalSK() (*memguard.LockedBuffer, error)
- type CredentialV2
- func (cred *CredentialV2) DepositMessage() (*DepositMessage, error)
- func (cred *CredentialV2) MarshalText() ([]byte, error)
- func (cred *CredentialV2) SignedDeposit() (*DepositData, error)
- func (cred *CredentialV2) SigningPK() (pub []byte, err error)
- func (cred *CredentialV2) SigningSK() (*memguard.LockedBuffer, error)
- func (cred *CredentialV2) WithdrawCredentials() ([]byte, error)
- func (cred *CredentialV2) WithdrawalPK() (pub []byte, err error)
- func (cred *CredentialV2) WithdrawalSK() (*memguard.LockedBuffer, error)
- type DepositData
- func (d *DepositData) GetTree() (*ssz.Node, error)
- func (d *DepositData) HashTreeRoot() ([32]byte, error)
- func (d *DepositData) HashTreeRootWith(hh ssz.HashWalker) (err error)
- func (d *DepositData) MarshalSSZ() ([]byte, error)
- func (d *DepositData) MarshalSSZTo(buf []byte) (dst []byte, err error)
- func (d *DepositData) SizeSSZ() (size int)
- func (d *DepositData) UnmarshalSSZ(buf []byte) error
- type DepositMessage
- func (d *DepositMessage) GetTree() (*ssz.Node, error)
- func (d *DepositMessage) HashTreeRoot() ([32]byte, error)
- func (d *DepositMessage) HashTreeRootWith(hh ssz.HashWalker) (err error)
- func (d *DepositMessage) MarshalSSZ() ([]byte, error)
- func (d *DepositMessage) MarshalSSZTo(buf []byte) (dst []byte, err error)
- func (d *DepositMessage) SizeSSZ() (size int)
- func (d *DepositMessage) UnmarshalSSZ(buf []byte) error
- type ForkData
- func (f *ForkData) GetTree() (*ssz.Node, error)
- func (f *ForkData) HashTreeRoot() ([32]byte, error)
- func (f *ForkData) HashTreeRootWith(hh ssz.HashWalker) (err error)
- func (f *ForkData) MarshalSSZ() ([]byte, error)
- func (f *ForkData) MarshalSSZTo(buf []byte) (dst []byte, err error)
- func (f *ForkData) SizeSSZ() (size int)
- func (f *ForkData) UnmarshalSSZ(buf []byte) error
- type MasterKey
- type SigningData
- func (s *SigningData) GetTree() (*ssz.Node, error)
- func (s *SigningData) HashTreeRoot() ([32]byte, error)
- func (s *SigningData) HashTreeRootWith(hh ssz.HashWalker) (err error)
- func (s *SigningData) MarshalSSZ() ([]byte, error)
- func (s *SigningData) MarshalSSZTo(buf []byte) (dst []byte, err error)
- func (s *SigningData) SizeSSZ() (size int)
- func (s *SigningData) UnmarshalSSZ(buf []byte) error
- type WithdrawType
Constants ¶
const ( K = 32 L = K * 255 )
const ( MAINNET = "mainnet" PYRMONT = "pyrmont" PRATER = "prater" HOLESKY = "holesky" HOODI = "hoodi" )
const DEPOSIT_CLI_VERSION = "2.8.0"
const (
SeedLength = 32
)
Variables ¶
var (
R, _ = new(big.Int).SetString("52435875175126190479447740508185965837690552500527637822603658699938581184513", 10)
)
Functions ¶
func ComputeDepositDomain ¶ added in v1.0.8
func ComputeDepositForkDataRoot ¶ added in v1.0.8
Types ¶
type BaseChainSetting ¶
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) HashTreeRoot ¶
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 ¶
MarshalSSZ ssz marshals the ForkData object
func (*ForkData) MarshalSSZTo ¶
MarshalSSZTo ssz marshals the ForkData object to a target array
func (*ForkData) UnmarshalSSZ ¶
UnmarshalSSZ ssz unmarshals the ForkData object
type MasterKey ¶
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