pattern export type Address = string ; pattern export type Bytes32 = string ; export type Uint48 = number ; pattern export type Uint256 = string ; pattern export type Bytes = string ; export interface Participant { participantId : string ; signingAddress : Address ; destination : Address ; } export interface AllocationItem { destination : Bytes32 ; amount : Uint256 ; } export interface Allocation { asset : Address ; allocationItems : AllocationItem [ ] ; } export type Allocations = Allocation [ ] ; export interface Guarantee { asset : Address ; targetChannelId : Bytes32 ; destinations : Bytes32 [ ] ; } export type Guarantees = Guarantee [ ] ; export type Outcome = Guarantees | Allocations ; export function isAllocations ( outcome ) { if ( outcome . length === 0 ) { return true ; } else { const first = outcome [ 0 ] ; return 'allocationItems' in first ; } } export interface SignedState { chainId : string ; participants : Participant [ ] ; channelNonce : Uint48 ; appDefinition : Address ; challengeDuration : Uint48 ; outcome : Outcome ; turnNum : Uint48 ; appData : Bytes ; isFinal : boolean ; channelId : Bytes32 ; signatures : string [ ] ; } type _Objective < Name , Data > = { participants : Participant [ ] ; type : Name ; data : Data ; } ; type FundingStrategy = 'Direct' | 'Ledger' | 'Virtual' | 'Fake' | 'Unknown' ; export type OpenChannel = _Objective < 'OpenChannel' , { targetChannelId : Bytes32 ; fundingStrategy : FundingStrategy ; role ? : 'app' | 'ledger' ; fundingLedgerChannelId ? : Address ; } > ; export type CloseChannel = _Objective < 'CloseChannel' , { targetChannelId : Bytes32 ; fundingStrategy : FundingStrategy ; txSubmitterOrder : number [ ] ; } > ; export type VirtuallyFund = _Objective < 'VirtuallyFund' , { targetChannelId : Bytes32 ; jointChannelId : Bytes32 ; } > ; export type FundGuarantor = _Objective < 'FundGuarantor' , { jointChannelId : Bytes32 ; ledgerId : Bytes32 ; guarantorId : Bytes32 ; } > ; export type FundLedger = _Objective < 'FundLedger' , { ledgerId : Bytes32 ; } > ; export type CloseLedger = _Objective < 'CloseLedger' , { ledgerId : Bytes32 ; } > ; export type Objective = OpenChannel | CloseChannel | VirtuallyFund | FundGuarantor | FundLedger | CloseLedger ; const guard = < T extends Objective > ( name ) => ( o ) : o is T => o . type === name ; export const isOpenChannel = guard < OpenChannel > ( 'OpenChannel' ) ; export const isVirtuallyFund = guard < VirtuallyFund > ( 'VirtuallyFund' ) ; export const isFundGuarantor = guard < FundGuarantor > ( 'FundGuarantor' ) ; type GetChannel = { type : 'GetChannel' ; channelId : string ; } ; export type ChannelRequest = GetChannel ; export interface Payload { walletVersion : string ; signedStates ? : SignedState [ ] ; objectives ? : Objective [ ] ; requests ? : ChannelRequest [ ] ; } export interface Message { recipient : string ; sender ? : string ; data : Payload ; }