wallet

package
v1.15.2 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: Apache-2.0, MIT Imports: 23 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrCodeOverflow = errors.New("code over flow")
View Source
var MaxMsgEnumCode = len(MsgEnumPool) - 1
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 SupportedMsgTypes = map[types.MsgType]*Types{
	types.MTDealProposal: {
		Type: reflect.TypeOf(market.DealProposal{}),
		SignBytes: func(i interface{}) ([]byte, error) {
			return cborutil.Dump(i)
		},
		ParseObj: defaultPaseObjFunc(reflect.TypeOf(market.DealProposal{})),
	},
	types.MTClientDeal: {
		Type: reflect.TypeOf(market.ClientDealProposal{}),
		SignBytes: func(in interface{}) ([]byte, error) {
			ni, err := cborutil.AsIpld(in)
			if err != nil {
				return nil, err
			}
			return ni.Cid().Bytes(), nil
		},
		ParseObj: defaultPaseObjFunc(reflect.TypeOf(market.ClientDealProposal{})),
	},
	types.MTDrawRandomParam: {
		Type: reflect.TypeOf(DrawRandomParams{}),
		SignBytes: func(in interface{}) ([]byte, error) {
			param := in.(*DrawRandomParams)
			return param.SignBytes()
		},
		ParseObj: defaultPaseObjFunc(reflect.TypeOf(DrawRandomParams{})),
	},
	types.MTSignedVoucher: {
		Type: reflect.TypeOf(paych.SignedVoucher{}),
		SignBytes: func(in interface{}) ([]byte, error) {
			return (in.(*paych.SignedVoucher)).SigningBytes()
		},
		ParseObj: defaultPaseObjFunc(reflect.TypeOf(paych.SignedVoucher{})),
	},
	types.MTStorageAsk: {
		Type: reflect.TypeOf(storagemarket.StorageAsk{}),
		SignBytes: func(in interface{}) ([]byte, error) {
			return cborutil.Dump(in)
		},
		ParseObj: defaultPaseObjFunc(reflect.TypeOf(storagemarket.StorageAsk{})),
	},
	types.MTAskResponse: {
		Type: reflect.TypeOf(network.AskResponse{}),
		SignBytes: func(in interface{}) ([]byte, error) {
			newAsk := in.(*network.AskResponse).Ask.Ask
			oldAsk := &migrations.StorageAsk0{
				Price: newAsk.Price, VerifiedPrice: newAsk.VerifiedPrice, MinPieceSize: newAsk.MinPieceSize,
				MaxPieceSize: newAsk.MaxPieceSize, Miner: newAsk.Miner, Timestamp: newAsk.Timestamp, Expiry: newAsk.Expiry, SeqNo: newAsk.SeqNo,
			}
			return cborutil.Dump(oldAsk)
		},
		ParseObj: defaultPaseObjFunc(reflect.TypeOf(network.AskResponse{})),
	},
	types.MTNetWorkResponse: {
		Type: reflect.TypeOf(network.Response{}),
		SignBytes: func(in interface{}) ([]byte, error) {
			return cborutil.Dump(in)
		},
		ParseObj: defaultPaseObjFunc(reflect.TypeOf(network.Response{})),
	},

	types.MTBlock: {
		Type: reflect.TypeOf(types.BlockHeader{}),
		SignBytes: func(in interface{}) ([]byte, error) {
			return in.(*types.BlockHeader).SignatureData()
		},
		ParseObj: defaultPaseObjFunc(reflect.TypeOf(types.BlockHeader{})),
	},
	types.MTChainMsg: {
		Type: reflect.TypeOf(types.Message{}),
		SignBytes: func(in interface{}) ([]byte, error) {
			msg := in.(*types.Message)
			return msg.Cid().Bytes(), nil
		},
		ParseObj: func(in []byte, meta types.MsgMeta) (interface{}, error) {
			if len(meta.Extra) == 0 {
				return nil, errors.New("msg type must contain extra data")
			}
			msg, err := types.DecodeMessage(meta.Extra)
			if err != nil {
				return nil, err
			}

			return msg, nil
		},
	},
	types.MTProviderDealState: {
		Type: reflect.TypeOf(storagemarket.ProviderDealState{}),
		SignBytes: func(in interface{}) ([]byte, error) {
			return cborutil.Dump(in)
		},
		ParseObj: defaultPaseObjFunc(reflect.TypeOf(storagemarket.ProviderDealState{})),
	},

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

	types.MTVerifyAddress: {
		Type: reflect.TypeOf([]byte{}),
		SignBytes: func(in interface{}) ([]byte, error) {
			return in.([]byte), nil
		},
		ParseObj: func(in []byte, meta types.MsgMeta) (interface{}, error) {
			expected := GetSignData(meta.Extra, gateway.RandomBytes)
			if !bytes.Equal(in, expected) {
				return nil, fmt.Errorf("sign data not match, actual %v, expected %v", in, expected)
			}
			return in, nil
		},
	},
}

SupportedMsgTypes signature type factory

Functions

func CborDecodeInto added in v1.13.0

func CborDecodeInto(r []byte, v interface{}) error

func CheckMsgEnum

func CheckMsgEnum(me MsgEnum) error

func ContainMsgType

func ContainMsgType(multiME MsgEnum, mt types.MsgType) bool

func FindCode

func FindCode(enum MsgEnum) []int

func GetSignBytesAndObj added in v1.13.0

func GetSignBytesAndObj(toSign []byte, meta types.MsgMeta) (interface{}, []byte, error)

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

func GetSignData added in v1.13.0

func GetSignData(datas ...[]byte) []byte

func MsgEnumCode

func MsgEnumCode(me MsgEnum) int

func RegisterSupportedMsgTypes added in v1.13.0

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

Types

type AddressScope

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

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 FGetSignBytes added in v1.13.0

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

type FParseObj added in v1.13.0

type FParseObj func(toSign []byte, meta types.MsgMeta) (interface{}, error)

type Group

type Group struct {
	GroupID uint
	Name    string
	// NOTE: not fill data when query groups
	KeyBinds []*KeyBind
}

Group multi KeyBind

type GroupAuth

type GroupAuth struct {
	Token    string
	GroupID  uint
	Name     string
	KeyBinds []*KeyBind
}

GroupAuth relation with Group and generate a token for external invocation

type KeyBind

type KeyBind struct {
	BindID  uint
	Name    string
	Address string
	// source from MsgTypeTemplate or temporary create
	MetaTypes MsgEnum
	// source from MethodTemplate
	Methods []MethodName
}

KeyBind bind wallet usage strategy allow designated rule to pass

func (*KeyBind) ContainMethod

func (kb *KeyBind) ContainMethod(m string) bool

func (*KeyBind) ContainMsgType

func (kb *KeyBind) ContainMsgType(m types.MsgType) bool

type KeyStrategy

type KeyStrategy struct {
	Address   address.Address // wallet address
	MetaTypes MsgEnum         // sum MsgEnum
	Methods   []MethodName    // msg method array
}

KeyStrategy a uint of wallet strategy

type MethodName

type MethodName = string

type MethodTemplate

type MethodTemplate struct {
	MTId uint
	Name string
	// method name join with ','
	Methods []MethodName
}

MethodTemplate to quickly create a private key usage strategy msg actor and methodNum agg to method name NOTE: routeType 4

type MsgEnum

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

func AggregateMsgEnumCode

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

func MsgEnumFromInt

func MsgEnumFromInt(code int) (MsgEnum, error)

type MsgTypeTemplate

type MsgTypeTemplate struct {
	MTTId     uint
	Name      string
	MetaTypes MsgEnum
}

MsgTypeTemplate to quickly create a private key usage strategy

type Types added in v1.13.0

type Types struct {
	Type      reflect.Type
	SignBytes FGetSignBytes
	ParseObj  FParseObj
}

Types Abstract data types to be signed

Jump to

Keyboard shortcuts

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