raiden-ts
Version:
Raiden Light Client Typescript/Javascript SDK
93 lines (92 loc) • 4.35 kB
TypeScript
import type { Signer } from '@ethersproject/abstract-signer';
import type { Observable } from 'rxjs';
import { matrixPresence } from '../transport/actions';
import type { RaidenEpicDeps } from '../types';
import { LruCache } from '../utils/lru';
import type { Last, Signed } from '../utils/types';
import { Address } from '../utils/types';
import type { pathFind } from './actions';
import type { IOU, PFS } from './types';
import { AddressMetadata } from './types';
/**
* Fetch PFS info & validate for a given server address or URL
*
* This is a memoized function which caches by url or address, network and registry used.
*
* @param pfsAddrOrUrl - PFS account/address or URL
* @param deps - RaidenEpicDeps needed for various parameters
* @param deps.log - Logger instance
* @param deps.serviceRegistryContract - ServiceRegistry contract instance
* @param deps.network - Current Network
* @param deps.contractsInfo - ContractsInfo mapping
* @param deps.provider - Eth provider
* @param deps.config$ - Config observable
* @param deps.latest$ - Latest observable
* @returns Promise containing PFS server info
*/
export declare function pfsInfo(pfsAddrOrUrl: Address | string, { log, serviceRegistryContract, network, contractsInfo, provider, config$, latest$, }: Pick<RaidenEpicDeps, 'log' | 'serviceRegistryContract' | 'network' | 'contractsInfo' | 'provider' | 'config$' | 'latest$'>): Promise<PFS>;
/**
* Returns the address for the PFS/service with the given URL.
* Result is cached and this cache is shared with [[pfsInfo]] calls.
*
* @param url - Url of the PFS to retrieve address for
* @param deps - Epics dependencies (for pfsInfo)
* @returns Promise to Address of PFS on given URL
*/
export declare const pfsInfoAddress: ((url: string, deps: Pick<RaidenEpicDeps, 'log' | 'serviceRegistryContract' | 'network' | 'contractsInfo' | 'provider' | 'config$' | 'latest$'>) => Promise<Address>) & {
cache: LruCache<string, Promise<Address>>;
};
/**
* Retrieve pfsInfo for these servers & return sorted PFS info
*
* Sort order is price then response time (rtt).
* Throws if no server can be validated, meaning either there's none in the current network or
* we're out-of-sync (outdated or ahead of PFS's deployment network version).
*
* @param pfsList - Array of PFS addresses or URLs
* @param deps - RaidenEpicDeps array
* @returns Observable of online, validated & sorted PFS info array
*/
export declare function pfsListInfo(pfsList: readonly (string | Address)[], deps: Pick<RaidenEpicDeps, 'log'> & Last<Parameters<typeof pfsInfo>>): Observable<PFS[]>;
/**
* Validates metadata was signed by address
*
* @param metadata - Peer's metadata
* @param address - Peer's address
* @param opts - Options
* @param opts.log - Logger instance
* @returns presence iff metadata is valid and was signed by address
*/
export declare function validateAddressMetadata(metadata: AddressMetadata | undefined, address: Address, { log }?: Partial<Pick<RaidenEpicDeps, 'log'>>): matrixPresence.success | undefined;
/**
* @param address - Peer address to fetch presence for
* @param pfsAddrOrUrl - PFS/service address to fetch presence from
* @param deps - Epics dependencies subset
* @param deps.serviceRegistryContract - Contract instance
* @returns Observable to peer's presence or error
*/
export declare function getPresenceFromService$(address: Address, pfsAddrOrUrl: string, deps: Pick<RaidenEpicDeps, 'serviceRegistryContract' | 'log'>): Observable<matrixPresence.success>;
/**
* Pack an IOU for signing or verification
*
* @param iou - IOU to be packed
* @returns Packed IOU as a UInt8Array
*/
export declare function packIOU(iou: IOU): Uint8Array;
/**
* Sign an IOU with signer
*
* @param signer - Signer instance
* @param iou - IOU to be signed
* @returns Signed IOU
*/
export declare function signIOU(signer: Signer, iou: IOU): Promise<Signed<IOU>>;
/**
* Choose best PFS and fetch info from it
*
* @param pfsByAction - Override config for this call: explicit PFS, disabled or undefined
* @param deps - Epics dependencies
* @param sortByRtt - Whether to sort PFSs by rtt, instead of price (default)
* @returns Observable to choosen PFS
*/
export declare function choosePfs$(pfsByAction: pathFind.request['payload']['pfs'], deps: RaidenEpicDeps, sortByRtt?: boolean): Observable<PFS>;