Documentation ¶
Overview ¶
Package state defines the data structures which are signed by channel participants.
Index ¶
- Variables
- type FixedPart
- type Signature
- type SignedState
- func (ss SignedState) AddSignature(sig Signature) error
- func (ss SignedState) ChannelId() types.Destination
- func (ss SignedState) Clone() SignedState
- func (ss SignedState) GetParticipantSignature(participantIndex uint) (crypto.Signature, error)
- func (ss SignedState) HasAllSignatures() bool
- func (ss SignedState) HasSignatureForParticipant(participantIndex uint) bool
- func (ss SignedState) MarshalJSON() ([]byte, error)
- func (ss SignedState) Merge(ss2 SignedState) error
- func (ss SignedState) Signatures() []Signature
- func (ss SignedState) SortInfo() (types.Destination, uint64)
- func (ss SignedState) State() State
- func (ss *SignedState) UnmarshalJSON(j []byte) error
- type State
- func (s State) ChannelId() types.Destination
- func (s State) Clone() State
- func (s State) Equal(r State) bool
- func (s State) FixedPart() FixedPart
- func (s State) Hash() (types.Bytes32, error)
- func (s State) RecoverSigner(sig Signature) (types.Address, error)
- func (s State) Sign(secretKey []byte) (Signature, error)
- func (s State) Validate() error
- func (s State) VariablePart() VariablePart
- type VariablePart
Constants ¶
This section is empty.
Variables ¶
var TestOutcome = outcome.Exit{ outcome.SingleAssetExit{ Asset: types.Address{}, AssetMetadata: outcome.AssetMetadata{ AssetType: 0, Metadata: make(types.Bytes, 0), }, Allocations: outcome.Allocations{ outcome.Allocation{ Destination: types.AddressToDestination(common.HexToAddress(`0xF5A1BB5607C9D079E46d1B3Dc33f257d937b43BD`)), Amount: big.NewInt(5), }, outcome.Allocation{ Destination: types.AddressToDestination(common.HexToAddress(`0xEe18fF1575055691009aa246aE608132C57a422c`)), Amount: big.NewInt(5), }, }, }, }
var TestState = State{ Participants: []types.Address{ common.HexToAddress(`0xF5A1BB5607C9D079E46d1B3Dc33f257d937b43BD`), common.HexToAddress(`0x760bf27cd45036a6C486802D30B5D90CfFBE31FE`), }, ChannelNonce: 37140676580, AppDefinition: common.HexToAddress(`0x5e29E5Ab8EF33F050c7cc10B5a0456D975C5F88d`), ChallengeDuration: 60, AppData: []byte{}, Outcome: TestOutcome, TurnNum: 5, IsFinal: false, }
Functions ¶
This section is empty.
Types ¶
type FixedPart ¶
type FixedPart struct { Participants []types.Address ChannelNonce uint64 AppDefinition types.Address ChallengeDuration uint32 }
FixedPart contains the subset of State data which does not change during a state update.
func (FixedPart) ChannelId ¶
func (fp FixedPart) ChannelId() types.Destination
type Signature ¶
func CloneSignature ¶
CloneSignature creates a deep copy of the provided signature.
type SignedState ¶
type SignedState struct {
// contains filtered or unexported fields
}
func NewSignedState ¶
func NewSignedState(s State) SignedState
NewSignedState initializes a SignedState struct for the given The signedState returned will have no signatures.
func (SignedState) AddSignature ¶
func (ss SignedState) AddSignature(sig Signature) error
AddSignature adds a participant's signature to the SignedState.
An error is returned if
- the signer is not a participant, or
- OR the signature was already stored
func (SignedState) ChannelId ¶
func (ss SignedState) ChannelId() types.Destination
ChannelId returns the channel id of the state.
func (SignedState) Clone ¶
func (ss SignedState) Clone() SignedState
Clone returns a deep copy of the receiver.
func (SignedState) GetParticipantSignature ¶
func (ss SignedState) GetParticipantSignature(participantIndex uint) (crypto.Signature, error)
GetParticipantSignature returns the signature for the participant specified by participantIndex
func (SignedState) HasAllSignatures ¶
func (ss SignedState) HasAllSignatures() bool
HasAllSignatures returns true if every participant has a valid signature.
func (SignedState) HasSignatureForParticipant ¶
func (ss SignedState) HasSignatureForParticipant(participantIndex uint) bool
HasSignatureForParticipant returns true if the participant (at participantIndex) has a valid signature.
func (SignedState) MarshalJSON ¶
func (ss SignedState) MarshalJSON() ([]byte, error)
MarshalJSON marshals the SignedState into JSON, implementing the Marshaler interface.
func (SignedState) Merge ¶
func (ss SignedState) Merge(ss2 SignedState) error
Merge checks the passed SignedState's state and the receiver's state for equality, and adds each signature from the former to the latter.
func (SignedState) Signatures ¶
func (ss SignedState) Signatures() []Signature
Signatures returns a slice of the signatures stored in the SignedState. There will be one signature per participant, in order of channel's Participants. Returned signatures are expected either to be valid or zero-valued.
func (SignedState) SortInfo ¶
func (ss SignedState) SortInfo() (types.Destination, uint64)
SortInfo returns the channel id and turn number of the state, so the state can be easily sorted.
func (SignedState) State ¶
func (ss SignedState) State() State
State returns the State part of the SignedState.
func (*SignedState) UnmarshalJSON ¶
func (ss *SignedState) UnmarshalJSON(j []byte) error
UnmarshalJSON unmarshals the passed JSON into a SignedState, implementing the Unmarshaler interface.
type State ¶
type State struct { Participants []types.Address ChannelNonce uint64 AppDefinition types.Address ChallengeDuration uint32 AppData types.Bytes Outcome outcome.Exit TurnNum uint64 IsFinal bool }
State holds all of the data describing the state of a channel
func StateFromFixedAndVariablePart ¶
func StateFromFixedAndVariablePart(f FixedPart, v VariablePart) State
StateFromFixedAndVariablePart constructs a State from a FixedPart and a VariablePart
func (State) ChannelId ¶
func (s State) ChannelId() types.Destination
ChannelId computes and returns the channel id corresponding to the State, and an error if the id is an external destination.
Up to hash collisions, ChannelId distinguishes channels that have different FixedPart values
func (State) RecoverSigner ¶
RecoverSigner computes the Ethereum address which generated Signature sig on State state
func (State) Sign ¶
Sign generates an ECDSA signature on the state using the supplied private key The state hash is prepended with \x19Ethereum Signed Message:\n32 and then rehashed to create a digest to sign
func (State) Validate ¶
Validate checks whether the state is malformed and returns an error if it is.
func (State) VariablePart ¶
func (s State) VariablePart() VariablePart
VariablePart returns the VariablePart of the State