import { utils } from 'ethers' ; import { Address , Bytes32 , Uint256 , Uint48 } from './types' ; /**
 * Holds the parameters that define a channel (in particular, its id)
 */ export interface Channel { channelNonce : Uint48 ; participants : Address [ ] ; chainId : Uint256 ; } param bytes32 returns export function isExternalDestination ( bytes32 ) { return /^0x(0{24})([a-fA-F0-9]{40})$/ . test ( bytes32 ) ; } param channel returns export function getChannelId ( channel ) { const { chainId , participants , channelNonce } = channel ; const channelId = utils . keccak256 ( utils . defaultAbiCoder . encode ( [ 'uint256' , 'address[]' , 'uint256' ] , [ chainId , participants , channelNonce ] ) ) ; if ( isExternalDestination ( channelId ) ) throw Error ( 'This channel would have an external destination as an id' ) ; return channelId ; }