core

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2021 License: MIT, Apache-2.0, MIT Imports: 41 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MethodSend        = builtin.MethodSend
	MethodConstructor = builtin.MethodConstructor
)
View Source
const (
	MTUnknown = MsgType("unknown")

	// Signing message CID. MsgMeta.Extra contains raw cbor message bytes
	MTChainMsg = MsgType("message")

	// Signing a blockheader. signing raw cbor block bytes (MsgMeta.Extra is empty)
	MTBlock = MsgType("block")

	// Signing a deal proposal. signing raw cbor proposal bytes (MsgMeta.Extra is empty)
	MTDealProposal = MsgType("dealproposal")
	// extra is nil, 'toSign' is cbor raw bytes of 'DrawRandomParams'
	//  following types follow above rule
	MTDrawRandomParam = MsgType("drawrandomparam")
	MTSignedVoucher   = MsgType("signedvoucher")
	MTStorageAsk      = MsgType("storageask")
	MTAskResponse     = MsgType("askresponse")
	MTNetWorkResponse = MsgType("networkresposne")

	// reference : storagemarket/impl/remotecli.go:330
	// sign storagemarket.ClientDeal.ProposalCid,
	// MsgMeta.Extra is nil, 'toSign' is market.ClientDealProposal
	// storagemarket.ClientDeal.ProposalCid equals cborutil.AsIpld(market.ClientDealProposal).Cid()
	MTClientDeal = MsgType("clientdeal")

	MTProviderDealState = MsgType("providerdealstate")
)
View Source
const (
	SigTypeUnknown = SigType(math.MaxUint8)

	SigTypeSecp256k1 = SigType(iota)
	SigTypeBLS
)
View Source
const BLAKE2B_MIN = 0xb201
View Source
const DefaultHashFunction = uint64(BLAKE2B_MIN + 31)

The multihash function identifier to use for content addresses.

View Source
const MessageVersion = 0
View Source
const StringEmpty = ""

Variables

View Source
var DefaultCidBuilder = cid.V1Builder{Codec: cid.DagCBOR, MhType: DefaultHashFunction}

A builder for all blockchain CIDs. Note that sector commitments use a different scheme.

View Source
var (
	ErrCodeOverflow = errors.New("code over flow")
)
View Source
var MaxMsgEnumCode = len(MsgEnumPool) - 1
View Source
var MethodNameList []MethodName
View Source
var MethodNamesMap = make(map[string]struct{})
View Source
var MethodsMap = map[Cid]map[MethodNum]MethodMeta{}
View Source
var MsgEnumPool = []struct {
	Code int
	Name string
}{
	{Code: MsgEnumCode(MEUnknown), Name: "unknown"},
	{Code: MsgEnumCode(MEChainMsg), Name: "chainMsg"},
	{Code: MsgEnumCode(MEBlock), Name: "block"},
	{Code: MsgEnumCode(MEDealProposal), Name: "dealProposal"},
	{Code: MsgEnumCode(MEDrawRandomParam), Name: "drawRandomParam"},
	{Code: MsgEnumCode(MESignedVoucher), Name: "signedVoucher"},
	{Code: MsgEnumCode(MEStorageAsk), Name: "storageAsk"},
	{Code: MsgEnumCode(MEAskResponse), Name: "askResponse"},
	{Code: MsgEnumCode(MENetWorkResponse), Name: "netWorkResponse"},
	{Code: MsgEnumCode(MEProviderDealState), Name: "providerDealState"},
	{Code: MsgEnumCode(MEClientDeal), Name: "clientDeal"},
}
View Source
var (
	NilAddress = Address{}
)
View Source
var SupportedMsgTypes = map[MsgType]*Types{
	MTDealProposal: {reflect.TypeOf(market.DealProposal{}), func(i interface{}) ([]byte, error) {
		return cborutil.Dump(i)
	}, nil},
	MTClientDeal: {reflect.TypeOf(market.ClientDealProposal{}), func(in interface{}) ([]byte, error) {
		ni, err := cborutil.AsIpld(in)
		if err != nil {
			return nil, err
		}
		return ni.Cid().Bytes(), nil
	}, nil},
	MTDrawRandomParam: {reflect.TypeOf(DrawRandomParams{}), func(in interface{}) ([]byte, error) {
		param := in.(*DrawRandomParams)
		return param.SignBytes()
	}, nil},
	MTSignedVoucher: {reflect.TypeOf(paych.SignedVoucher{}), func(in interface{}) ([]byte, error) {
		return (in.(*paych.SignedVoucher)).SigningBytes()
	}, nil},
	MTStorageAsk: {reflect.TypeOf(storagemarket.StorageAsk{}), func(in interface{}) ([]byte, error) {
		return cborutil.Dump(in)
	}, nil},
	MTAskResponse: {Type: reflect.TypeOf(network.AskResponse{}), /* contains filtered or unexported fields */},
	MTNetWorkResponse: {reflect.TypeOf(network.Response{}), func(in interface{}) ([]byte, error) {
		return cborutil.Dump(in)
	}, nil},

	MTBlock: {reflect.TypeOf(Block{}), func(in interface{}) ([]byte, error) {
		return in.(*Block).SignatureData(), nil
	}, nil},
	MTChainMsg: {reflect.TypeOf(Message{}), func(in interface{}) ([]byte, error) {
		msg := in.(*Message)
		return msg.Cid().Bytes(), nil
	}, nil},
	MTProviderDealState: {reflect.TypeOf(storagemarket.ProviderDealState{}), func(in interface{}) ([]byte, error) {
		return cborutil.Dump(in)
	}, nil,
	},

	MTUnknown: {reflect.TypeOf([]byte{}), func(in interface{}) ([]byte, error) {
		msg, isok := in.([]byte)
		if !isok {
			return nil, fmt.Errorf("MTUnkown must be []byte")
		}
		return msg, nil
	}, func(in []byte, meta MsgMeta) (interface{}, error) {
		if meta.Type == MTUnknown {
			return in, nil
		}
		return nil, fmt.Errorf("un-expected MsgType:%s", meta.Type)
	}},
}

signature type factory

Functions

func CheckMsgEnum

func CheckMsgEnum(me MsgEnum) error

func ContainMsgType

func ContainMsgType(multiME MsgEnum, mt MsgType) bool

func ContextStrategyToken

func ContextStrategyToken(ctx context.Context) string

func FindCode

func FindCode(enum MsgEnum) []int

func GetMethodName

func GetMethodName(actCode Cid, method MethodNum) (string, error)

func GetSignBytes

func GetSignBytes(toSign []byte, meta MsgMeta) (interface{}, []byte, error)

Matches the type and returns the data that needs to be signed

func MsgEnumCode

func MsgEnumCode(me MsgEnum) int

func RegistSupportedMsgTypes

func RegistSupportedMsgTypes(msgType MsgType, p reflect.Type,
	fGetSignBytes FGetSignBytes, fParseObj FParseObj) (replaced bool)

Types

type Address

type Address = address.Address

type AddressScope

type AddressScope struct {
	Root      bool      // is root auth,  true : can get all addresses in the wallet
	Addresses []Address // when root==false, should fill a scope of wallet addresses
}

type BeaconEntry

type BeaconEntry struct {
	Round uint64
	Data  []byte
}

func (*BeaconEntry) MarshalCBOR

func (t *BeaconEntry) MarshalCBOR(w io.Writer) error

func (*BeaconEntry) UnmarshalCBOR

func (t *BeaconEntry) UnmarshalCBOR(r io.Reader) error

type Block

type Block struct {
	// Miner is the address of the miner actor that mined this block.
	Miner Address `json:"miner"`

	// Ticket is the ticket submitted with this block.
	Ticket Ticket `json:"ticket"`

	// ElectionProof is the vrf proof giving this block's miner authoring rights
	ElectionProof *ElectionProof `json:"electionProof"`

	// BeaconEntries contain the verifiable oracle randomness used to elect
	// this block's author leader
	BeaconEntries []*BeaconEntry `json:"beaconEntries"`

	// WinPoStProof are the winning post proofs
	WinPoStProof []proof2.PoStProof `json:"winPoStProof"`

	// Parents is the set of parents this block was based on. Typically one,
	// but can be several in the case where there were multiple winning ticket-
	// holders for an epoch.
	Parents TipSetKey `json:"parents"`

	// ParentWeight is the aggregate chain weight of the parent set.
	ParentWeight fbig.Int `json:"parentWeight"`

	// Height is the chain height of this block.
	Height abi.ChainEpoch `json:"height"`

	// ParentStateRoot is the CID of the root of the state tree after application of the messages in the parent tipset
	// to the parent tipset's state root.
	ParentStateRoot Cid `json:"parentStateRoot,omitempty"`

	// ParentMessageReceipts is a list of receipts corresponding to the application of the messages in the parent tipset
	// to the parent tipset's state root (corresponding to this block's ParentStateRoot).
	ParentMessageReceipts Cid `json:"parentMessageReceipts,omitempty"`

	// Messages is the set of messages included in this block
	Messages Cid `json:"messages,omitempty"`

	// The aggregate signature of all BLS signed messages in the block
	BLSAggregate *Signature `json:"BLSAggregate"`

	// The timestamp, in seconds since the Unix epoch, at which this block was created.
	Timestamp uint64 `json:"timestamp"`

	// The signature of the miner's worker key over the block
	BlockSig *Signature `json:"blocksig"`

	// ForkSignaling is extra data used by miners to communicate
	ForkSignaling uint64 `json:"forkSignaling"`

	ParentBaseFee TokenAmount `json:"parentBaseFee"`
}

Block is a block in the blockchain.

func (*Block) MarshalCBOR

func (bk *Block) MarshalCBOR(w io.Writer) error

func (*Block) SignatureData

func (bk *Block) SignatureData() []byte

func (*Block) UnmarshalCBOR

func (bk *Block) UnmarshalCBOR(r io.Reader) error

type Cid

type Cid = cid.Cid

type ContextKey

type ContextKey string
const CtxKeyStrategy ContextKey = "strategy"

ctx key of strategy token

type DrawRandomParams

type DrawRandomParams struct {
	Rbase   []byte
	Pers    crypto.DomainSeparationTag
	Round   abi.ChainEpoch
	Entropy []byte
}

func (*DrawRandomParams) MarshalCBOR

func (dr *DrawRandomParams) MarshalCBOR(w io.Writer) error

func (*DrawRandomParams) SignBytes

func (dr *DrawRandomParams) SignBytes() ([]byte, error)

return store.DrawRandomness(dr.Rbase, dr.Pers, dr.Round, dr.Entropy)

func (*DrawRandomParams) UnmarshalCBOR

func (dr *DrawRandomParams) UnmarshalCBOR(r io.Reader) error

type ElectionProof

type ElectionProof struct {
	WinCount int64

	// A proof output by running a VRF on the VRFProof of the parent ticket
	VRFProof VRFPi
}

func (*ElectionProof) MarshalCBOR

func (t *ElectionProof) MarshalCBOR(w io.Writer) error

func (*ElectionProof) UnmarshalCBOR

func (t *ElectionProof) UnmarshalCBOR(r io.Reader) error

type EmptyValue

type EmptyValue struct{}

type FGetSignBytes

type FGetSignBytes func(in interface{}) ([]byte, error)

type FParseObj

type FParseObj func([]byte, MsgMeta) (interface{}, error)

type KeyInfo

type KeyInfo struct {
	Type       KeyType
	PrivateKey []byte
}

type KeyType

type KeyType string

KeyType defines a type of a key

const (
	KTUnknown   KeyType = "unknown"
	KTBLS       KeyType = "bls"
	KTSecp256k1 KeyType = "secp256k1"
)

func SignType2Key

func SignType2Key(kt SigType) KeyType

func (*KeyType) UnmarshalJSON

func (kt *KeyType) UnmarshalJSON(bb []byte) error

type Message

type Message struct {
	Version uint64

	To   Address
	From Address

	Nonce uint64

	Value TokenAmount

	GasLimit   int64
	GasFeeCap  TokenAmount
	GasPremium TokenAmount

	Method MethodNum
	Params []byte
}

filecoin message

func DecodeMessage

func DecodeMessage(b []byte) (*Message, error)

func (*Message) Cid

func (msg *Message) Cid() cid.Cid

func (*Message) MarshalCBOR

func (msg *Message) MarshalCBOR(w io.Writer) error

func (*Message) Serialize

func (msg *Message) Serialize() ([]byte, error)

func (*Message) ToStorageBlock

func (msg *Message) ToStorageBlock() (block.Block, error)

func (*Message) UnmarshalCBOR

func (msg *Message) UnmarshalCBOR(r io.Reader) error

type MethodMeta

type MethodMeta struct {
	Name string

	Params reflect.Type
	Ret    reflect.Type
}

type MethodName

type MethodName = string

func AggregateMethodNames

func AggregateMethodNames(methods []MethodName) ([]MethodName, error)

type MethodNum

type MethodNum = abi.MethodNum

type MsgEnum

type MsgEnum = uint32
const (
	MEUnknown MsgEnum = 1 << iota
	MEChainMsg
	MEBlock
	MEDealProposal
	MEDrawRandomParam
	MESignedVoucher
	MEStorageAsk
	MEAskResponse
	MENetWorkResponse
	MEProviderDealState
	MEClientDeal
)

func AggregateMsgEnumCode

func AggregateMsgEnumCode(codes []int) (MsgEnum, error)

func MsgEnumFromInt

func MsgEnumFromInt(code int) (MsgEnum, error)

type MsgMeta

type MsgMeta struct {
	Type MsgType
	// Additional data related to what is signed. Should be verifiable with the
	// signed bytes (e.g. CID(Extra).Bytes() == toSign)
	Extra []byte
}

type MsgType

type MsgType string

type SigType

type SigType = crypto.SigType

func KeyType2Sign

func KeyType2Sign(kt KeyType) SigType

type Signature

type Signature = crypto.Signature

type SignedMessage

type SignedMessage struct {
	Message   Message
	Signature Signature
}

func (*SignedMessage) MarshalCBOR

func (t *SignedMessage) MarshalCBOR(w io.Writer) error

func (*SignedMessage) UnmarshalCBOR

func (t *SignedMessage) UnmarshalCBOR(r io.Reader) error

type StrategyLevel

type StrategyLevel = uint8
const (
	// default level, no strategy
	SLDisable StrategyLevel = iota
	// level 1, check struct type
	SLMetaType
	// level 2, check struct type and method in msg
	SLMethod
)
var WalletStrategyLevel StrategyLevel

wallet strategy level, it will be initialized from config at startup

type Ticket

type Ticket struct {
	// A proof output by running a VRF on the VRFProof of the parent ticket
	VRFProof VRFPi
}

func (*Ticket) MarshalCBOR

func (t *Ticket) MarshalCBOR(w io.Writer) error

func (*Ticket) UnmarshalCBOR

func (t *Ticket) UnmarshalCBOR(r io.Reader) error

type TipSetKey

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

func (TipSetKey) Cids

func (tipsetKey TipSetKey) Cids() []Cid

Cids returns a slice of the CIDs comprising this key.

func (TipSetKey) MarshalCBOR

func (tipsetKey TipSetKey) MarshalCBOR(w io.Writer) error

func (*TipSetKey) UnmarshalCBOR

func (tipsetKey *TipSetKey) UnmarshalCBOR(r io.Reader) error

type TokenAmount

type TokenAmount = abi.TokenAmount

type Types

type Types struct {
	Type reflect.Type
	// contains filtered or unexported fields
}

Abstract data types to be signed

type VRFPi

type VRFPi []byte

Jump to

Keyboard shortcuts

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