Documentation ¶
Overview ¶
Package primitives defines the data types required for offchain communication.
It defines structure of a state, session id and functions to generate them. It also defines message packets, its marshallers and unmarshallers.
Index ¶
- Constants
- Variables
- func ContainsStatus(list []MessageStatus, requiredValue MessageStatus) bool
- func GenerateRandomNumber(sizeInBytes int) ([]byte, error)
- type ChMsgPkt
- type JSONMsgContractAddr
- type JSONMsgIdentity
- type JSONMsgMSCBaseState
- type JSONMsgNewChannel
- type JSONMsgSessionID
- type JSONMsgVPCState
- type MSCBaseState
- type MSCBaseStateSigned
- func (state *MSCBaseStateSigned) AddSign(idWithCreds identity.OffChainID, role Role) (err error)
- func (state *MSCBaseStateSigned) Equal(b MSCBaseStateSigned) (result bool)
- func (state MSCBaseStateSigned) String() string
- func (state *MSCBaseStateSigned) VerifySign(id identity.OffChainID, role Role) (isValid bool, err error)
- type MessageID
- type MessageStatus
- type Role
- type SessionID
- func (sid *SessionID) Equal(b SessionID) bool
- func (sid *SessionID) EqualReceiver(b SessionID) bool
- func (sid *SessionID) EqualSender(b SessionID) bool
- func (sid *SessionID) GenerateCompleteSid() (err error)
- func (sid *SessionID) GenerateReceiverPart(AddrReceiver types.Address) (err error)
- func (sid *SessionID) GenerateSenderPart(AddrSender types.Address) (err error)
- func (sid *SessionID) SoliditySHA3() []byte
- func (sid *SessionID) Validate() (valid bool, err error)
- type VPCState
- type VPCStateID
- type VPCStateSigned
- func (state *VPCStateSigned) AddSign(idWithCreds identity.OffChainID, role Role) (err error)
- func (state *VPCStateSigned) Equal(b VPCStateSigned) (result bool)
- func (state VPCStateSigned) String() string
- func (state *VPCStateSigned) VerifySign(id identity.OffChainID, role Role) (isValid bool, err error)
Constants ¶
const Version = "0.1"
Version defines the version of offchain messaging protocol.
Variables ¶
var ( MessageStatusRequire = MessageStatus("require") MessageStatusAccept = MessageStatus("accept") MessageStatusDecline = MessageStatus("decline") MessageStatusUnknown = MessageStatus("unknown") RequestStatusList = []MessageStatus{MessageStatusRequire} ResponseStatusList = []MessageStatus{MessageStatusAccept, MessageStatusDecline} )
Enumeration of allowed values for message status
Functions ¶
func ContainsStatus ¶
func ContainsStatus(list []MessageStatus, requiredValue MessageStatus) bool
ContainsStatus checks of the required value of staus is present in the list.
func GenerateRandomNumber ¶
GenerateRandomNumber generates a random byte array of given size.
Types ¶
type ChMsgPkt ¶
type ChMsgPkt struct { Version string `json:"version"` MessageID MessageID `json:"message_id"` Message interface{} `json:"message"` Timestamp time.Time `json:"timestamp"` }
ChMsgPkt is packet definition for offchain communications.
func (*ChMsgPkt) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaller interface.
The json message is first unmarshalled retaining the message as raw json. Then the message is unmarshalled to appropriate format depending upon the message id.
type JSONMsgContractAddr ¶
type JSONMsgContractAddr struct { Addr types.Address `json:"addr"` ContractType contract.Handler `json:"contract_type"` Status MessageStatus `json:"status"` }
JSONMsgContractAddr is the packet definition for "contract address request|response" message
type JSONMsgIdentity ¶
type JSONMsgIdentity struct {
ID identity.OffChainID `json:"id"`
}
JSONMsgIdentity is the packet definition for "identity request|response" message
type JSONMsgMSCBaseState ¶
type JSONMsgMSCBaseState struct { SignedStateVal MSCBaseStateSigned `json:"signed_state_val"` Status MessageStatus `json:"status"` }
JSONMsgMSCBaseState is the packet definition for "MSC base state request|response" message
type JSONMsgNewChannel ¶
type JSONMsgNewChannel struct { //TODO : Check if contract lock in amount also need to be added ContractStoreVersion []byte `json:"contract_store_version"` MsgProtocolVersion string `json:"msg_protocol_version"` Status MessageStatus `json:"status"` Reason string `json:"reason"` }
JSONMsgNewChannel is the packet definition for "new channel request|response" message
type JSONMsgSessionID ¶
type JSONMsgSessionID struct { Sid SessionID `json:"sid"` Status MessageStatus `json:"status"` }
JSONMsgSessionID is the packet definition for "session id request|response" message
type JSONMsgVPCState ¶
type JSONMsgVPCState struct { SignedStateVal VPCStateSigned `json:"signed_state_val"` Status MessageStatus `json:"status"` }
JSONMsgVPCState is the packet definition for "VPC state request|response" message
type MSCBaseState ¶
type MSCBaseState struct { VpcAddress types.Address `json:"vpc_address"` Sid *big.Int `json:"sid"` BlockedSender *big.Int `json:"blocked_sender"` BlockedReceiver *big.Int `json:"blocked_receiver"` Version *big.Int `json:"version"` }
MSCBaseState is the structure of base state in mscontract. Data types of state members should match with those defined in solidity code.
func (MSCBaseState) Equal ¶
func (state MSCBaseState) Equal(b MSCBaseState) (result bool)
Equal returns true if two MSContractBaseStates are equal.
func (MSCBaseState) SoliditySHA3 ¶
func (state MSCBaseState) SoliditySHA3() []byte
SoliditySHA3 generates solidity compatible sha3 hash over MSContractBaseState.
func (MSCBaseState) String ¶
func (state MSCBaseState) String() string
String implements fmt.Stringer interface. It prints msc base state struct with vpc address in hexadecimal form.
type MSCBaseStateSigned ¶
type MSCBaseStateSigned struct { MSContractBaseState MSCBaseState `json:"ms_contract_state"` SignSender []byte `json:"sign_sender"` SignReceiver []byte `json:"sign_receiver"` }
MSCBaseStateSigned is MSContractBaseState with signatures.
func (*MSCBaseStateSigned) AddSign ¶
func (state *MSCBaseStateSigned) AddSign(idWithCreds identity.OffChainID, role Role) (err error)
AddSign adds signature over MSContractBaseState for the defined role using idWithCreds as signer.
func (*MSCBaseStateSigned) Equal ¶
func (state *MSCBaseStateSigned) Equal(b MSCBaseStateSigned) (result bool)
Equal returns true if the two MSContractBaseStateSigned are equal.
func (MSCBaseStateSigned) String ¶
func (state MSCBaseStateSigned) String() string
String implements fmt.Stringer interface. It prints msc base state signed struct with signatures in hexadecimal form.
func (*MSCBaseStateSigned) VerifySign ¶
func (state *MSCBaseStateSigned) VerifySign(id identity.OffChainID, role Role) (isValid bool, err error)
VerifySign verifies the signature of user corresponding to defined role over MSContractBaseState.
type MessageID ¶
type MessageID string
MessageID is the unique id for the channel message format.
const ( // MsgIdentityRequest is the id for "identity request" message. MsgIdentityRequest MessageID = "MsgIdentityRequest" // MsgIdentityResponse is the id for "identity response" message. MsgIdentityResponse MessageID = "MsgIdentityResponse" // MsgNewChannelRequest is the id for "new channel request" message. MsgNewChannelRequest MessageID = "MsgNewChannelRequest" // MsgNewChannelResponse is the id for "new channel response" message. MsgNewChannelResponse MessageID = "MsgNewChannelResponse" // MsgSessionIDRequest is the id for "session id request" message. MsgSessionIDRequest MessageID = "MsgSessionIdRequest" // MsgSessionIDResponse is the id for "session id response" message. MsgSessionIDResponse MessageID = "MsgSessionIdResponse" // MsgContractAddrRequest is the id for "contract address request" message. MsgContractAddrRequest MessageID = "MsgContractAddrRequest" // MsgContractAddrResponse is the id for "contract address response" message. MsgContractAddrResponse MessageID = "MsgContractAddrResponse" // MsgMSCBaseStateRequest is the id for "MSC base state request" message. MsgMSCBaseStateRequest MessageID = "MsgMSCBaseStateRequest" // MsgMSCBaseStateResponse is the id for "MSC base state response" message. MsgMSCBaseStateResponse MessageID = "MsgMSCBaseStateResponse" // MsgVPCStateRequest is the id for "VPC state request" message. MsgVPCStateRequest MessageID = "MsgVPCStateRequest" // MsgVPCStateResponse is the id for "VPC state response" message. MsgVPCStateResponse MessageID = "MsgVPCStateResponse" )
Enumeration of allowed values for message id.
type MessageStatus ¶
type MessageStatus string
MessageStatus represents the status in a request-response message.
type Role ¶
type Role string
Role is the role of the user in an activity (such as opening, closing) on channel.
const ( // Sender is the one who initializes the activity on the channel. // The activity can be Opening or Closing the channel. Sender Role = Role("Sender") // Receiver is the user other than the one who initializes the activity on the channel. // The activity can be Opening or Closing the channel. Receiver Role = Role("Receiver") )
Enumeration of allowed values for role in activity on channel.
type SessionID ¶
type SessionID struct { //SidComplete is *big.Int is to create compatible solidiySHA3 hash SidComplete *big.Int `json:"sid_complete"` SidSenderPart []byte `json:"sid_sender_part"` SidReceiverPart []byte `json:"sid_receiver_part"` AddrSender types.Address `json:"addr_sender"` AddrReceiver types.Address `json:"addr_receiver"` NonceSender []byte `json:"nonce_sender"` NonceReceiver []byte `json:"nonce_receiver"` //SessionId is locked for further changes Locked bool `json:"locked"` }
SessionID represents the unique identification of offchain channel.
func NewSessionID ¶
NewSessionID returns a initialized session id.
func (*SessionID) EqualReceiver ¶
EqualReceiver returns true true if the receiver parts of two session ids are equal.
func (*SessionID) EqualSender ¶
EqualSender returns true true if the sender parts of two session ids are equal.
func (*SessionID) GenerateCompleteSid ¶
GenerateCompleteSid generates sid = hash(sender part + receiver part).
func (*SessionID) GenerateReceiverPart ¶
GenerateReceiverPart generates sid receiver part = hash(nonce + addrReceiver).
func (*SessionID) GenerateSenderPart ¶
GenerateSenderPart generates sid sender part = hash(nonce + addrSender).
func (*SessionID) SoliditySHA3 ¶
SoliditySHA3 provides hash of sid as will be returned in VPCClosing and VPCClosed events.
type VPCState ¶
type VPCState struct { ID []byte `json:"id"` Version *big.Int `json:"version"` BlockedSender *big.Int `json:"blocked_alice"` BlockedReceiver *big.Int `json:"blocked_bob"` }
VPCState is the structure of state in vpc and hence in off-chain channel. Data types of state members should match with those defined in solidity code.
func (VPCState) SoliditySHA3 ¶
SoliditySHA3 generates solidity compatible sha3 hash over VPCState.
type VPCStateID ¶
VPCStateID is the structure of id vpc state.
func (*VPCStateID) SoliditySHA3 ¶
func (stateID *VPCStateID) SoliditySHA3() []byte
SoliditySHA3 generates solidity compatible sha3 hash over VPCStateId.
type VPCStateSigned ¶
type VPCStateSigned struct { VPCState VPCState `json:"vpc_state"` SignSender []byte `json:"sign_sender"` SignReceiver []byte `json:"sign_receiver"` }
VPCStateSigned is VPCState with signatures.
func (*VPCStateSigned) AddSign ¶
func (state *VPCStateSigned) AddSign(idWithCreds identity.OffChainID, role Role) (err error)
AddSign adds signature over VPCState for the defined role using idWithCreds as signer.
func (*VPCStateSigned) Equal ¶
func (state *VPCStateSigned) Equal(b VPCStateSigned) (result bool)
Equal returns true if the two VPCStateSigned are equal.
func (VPCStateSigned) String ¶
func (state VPCStateSigned) String() string
String implements fmt.Stringer interface. It prints vpc state signed struct with signatures in hexadecimal form.
func (*VPCStateSigned) VerifySign ¶
func (state *VPCStateSigned) VerifySign(id identity.OffChainID, role Role) (isValid bool, err error)
VerifySign verifies the signature of user corresponding to defined role over VPCState.