import { Connection , PublicKey } from '@solana/web3.js' ; import { didToPublicKey , ExtendedCluster , PrivateKey } from '../lib/util' ; import { SolariumTransaction } from '../lib/solana/transaction' ; import { Channel } from '../lib/Channel' ; import { from , Observable } from 'rxjs' ; import { ChannelData } from '../lib/solana/models/ChannelData' ; import { switchMap } from 'rxjs/operators' ; import { CEKAccountData } from '../lib/solana/models/CEKAccountData' ; param channel param connection param memberDID param memberKey param cluster export const get = async ( channel , connection , memberDID , memberKey ? , cluster ? ) : Promise < Channel > => { const didKey = didToPublicKey ( memberDID ) ; const channelData = await SolariumTransaction . getChannelData ( connection , channel ) ; if ( ! channelData ) throw new Error ( `Channel not found` ) ; const cekAccountData = await SolariumTransaction . getCEKAccountData ( connection , didKey , channel ) ; if ( ! cekAccountData ) throw new Error ( `No CEK account found for DID ${ memberDID }. Are they a member of the channel?` ) ; return Channel . fromChainData ( channel , channelData , cekAccountData , memberDID , memberKey , cluster ) ; } ; param channel param connection param memberDID param memberKey param cluster export const getStream = ( channel , connection , memberDID , memberKey ? , cluster ? ) : Observable < Channel > => { const didKey = didToPublicKey ( memberDID ) ; const cekAccountData$ = from ( SolariumTransaction . getCEKAccountData ( connection , didKey , channel ) ) ; return cekAccountData$ . pipe ( switchMap ( ( cekAccountData ) => { if ( ! cekAccountData ) throw new Error ( `No CEK account found for DID ${ memberDID }. Are they a member of the channel?` ) ; return new Observable < Channel > ( subscriber => { const id = connection . onAccountChange ( channel , async ( accountInfo ) => { const channelData = await ChannelData . fromAccount ( accountInfo . data ) ; const channelObject = await Channel . fromChainData ( channel , channelData , cekAccountData , memberDID , memberKey , cluster ) ; subscriber . next ( channelObject ) ; } ) ; return ( ) : void => { connection . removeAccountChangeListener ( id ) ; } ; } ) ; } ) ) ; } ;