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: 458e87006af46832702fee8c0581ee159db3643287aea91f077df17b9d0cdc64
Index ¶
- Constants
- Variables
- 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 DepositData
- func (d *DepositData) HashTreeRoot() ([32]byte, error)
- func (d *DepositData) HashTreeRootWith(hh *ssz.Hasher) (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) HashTreeRoot() ([32]byte, error)
- func (d *DepositMessage) HashTreeRootWith(hh *ssz.Hasher) (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) HashTreeRoot() ([32]byte, error)
- func (f *ForkData) HashTreeRootWith(hh *ssz.Hasher) (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) HashTreeRoot() ([32]byte, error)
- func (s *SigningData) HashTreeRootWith(hh *ssz.Hasher) (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
- Bugs
Constants ¶
const ( K = 32 L = K * 255 )
const ( MAINNET = "mainnet" PYRMONT = "pyrmont" PRATER = "prater" )
const (
SeedLength = 32
)
Variables ¶
var (
IV, _ = hex.DecodeString("5a31313230aeB16524a01FF5597A5529")
)
var (
R, _ = new(big.Int).SetString("52435875175126190479447740508185965837690552500527637822603658699938581184513", 10)
)
Functions ¶
This section is empty.
Types ¶
type BaseChainSetting ¶
var ( MainnetSetting BaseChainSetting PyrmontSetting BaseChainSetting PraterSetting 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:"eth2_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 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) HashTreeRoot ¶
func (d *DepositData) HashTreeRoot() ([32]byte, error)
HashTreeRoot ssz hashes the DepositData object
func (*DepositData) HashTreeRootWith ¶
func (d *DepositData) HashTreeRootWith(hh *ssz.Hasher) (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) HashTreeRoot ¶
func (d *DepositMessage) HashTreeRoot() ([32]byte, error)
HashTreeRoot ssz hashes the DepositMessage object
func (*DepositMessage) HashTreeRootWith ¶
func (d *DepositMessage) HashTreeRootWith(hh *ssz.Hasher) (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 ¶
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 ¶
type MasterKey struct {
// 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:
keyString := rockx.com/eth/key_id/%v(string)-> h := Hash(keyString) -> secret := encrypt(parentKey,h) 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) HashTreeRoot ¶
func (s *SigningData) HashTreeRoot() ([32]byte, error)
HashTreeRoot ssz hashes the SigningData object
func (*SigningData) HashTreeRootWith ¶
func (s *SigningData) HashTreeRootWith(hh *ssz.Hasher) (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
Notes ¶
Bugs ¶
the parent key in cipher.Block should be erased someway