import { Key } from "../../../lib/common-libs/crypto/keyring"; import { WS2PMessageHandler } from "./impl/WS2PMessageHandler"; import { BlockDTO } from "../../../lib/dto/BlockDTO"; import { IdentityDTO } from "../../../lib/dto/IdentityDTO"; import { CertificationDTO } from "../../../lib/dto/CertificationDTO"; import { MembershipDTO } from "../../../lib/dto/MembershipDTO"; import { TransactionDTO } from "../../../lib/dto/TransactionDTO"; import { PeerDTO } from "../../../lib/dto/PeerDTO"; import { ManualPromise } from "../../../lib/common-libs/manual-promise"; export declare enum WS2P_PUSH { PEER = 0, TRANSACTION = 1, MEMBERSHIP = 2, CERTIFICATION = 3, IDENTITY = 4, BLOCK = 5, HEAD = 6 } export interface WS2PAuth { authenticationIsDone(): Promise; } export interface WS2PRemoteAuth extends WS2PAuth { givenCurrency: Promise; registerCONNECT(type: "CONNECT" | "SYNC", ws2pVersion: number, challenge: string, sig: string, pub: string, currency: string, ws2pId: string): Promise; sendACK(ws: any): Promise; registerOK(sig: string): Promise; isAuthenticatedByRemote(): boolean; getPubkey(): string; getVersion(): number; isSync(): boolean; } export interface WS2PLocalAuth extends WS2PAuth { sendCONNECT(ws: any, ws2pVersion: number): Promise; registerACK(sig: string, pub: string): Promise; sendOK(ws: any): Promise; isRemoteAuthenticated(): boolean; currency: string; } /** * A passive authenticator based on our keyring. */ export declare class WS2PPubkeyRemoteAuth implements WS2PRemoteAuth { protected currency: string; protected pair: Key; protected tellIsAuthorizedPubkey: (pub: string, isSync: boolean) => Promise; protected challenge: string; protected authenticatedByRemote: boolean; protected remotePub: string; protected remoteWs2pId: string; protected remoteVersion: number; protected serverAuth: Promise; protected serverAuthResolve: () => void; protected serverAuthReject: (err: any) => void; protected isSyncConnection: boolean; givenCurrency: ManualPromise; constructor(currency: string, pair: Key, tellIsAuthorizedPubkey?: (pub: string, isSync: boolean) => Promise); getVersion(): number; getPubkey(): string; isSync(): boolean; sendACK(ws: any): Promise; registerCONNECT(type: "CONNECT" | "SYNC", ws2pVersion: number, challenge: string, sig: string, pub: string, currency: string, ws2pId?: string): Promise; registerOK(sig: string): Promise; isAuthenticatedByRemote(): boolean; authenticationIsDone(): Promise; } /** * An connecting authenticator based on our keyring. */ export declare class WS2PPubkeyLocalAuth implements WS2PLocalAuth { currency: string; protected pair: Key; protected ws2pId: string; protected tellIsAuthorizedPubkey: (pub: string) => Promise; protected challenge: string; protected authenticated: boolean; protected serverAuth: Promise; protected serverAuthResolve: () => void; protected serverAuthReject: (err: any) => void; protected isSync: boolean; constructor(currency: string, pair: Key, ws2pId: string, tellIsAuthorizedPubkey?: (pub: string) => Promise); sendCONNECT(ws: any, ws2pVersion: number): Promise; registerACK(sig: string, pub: string): Promise; sendOK(ws: any): Promise; isRemoteAuthenticated(): boolean; authenticationIsDone(): Promise; } export declare class WS2PPubkeySyncLocalAuth extends WS2PPubkeyLocalAuth { protected pair: Key; protected ws2pId: string; protected tellIsAuthorizedPubkey: (pub: string) => Promise; constructor(currency: string, // Only here for function signature purpose pair: Key, ws2pId: string, tellIsAuthorizedPubkey?: (pub: string) => Promise); } export interface WS2PRequest { name: string; params?: any; } export declare class WS2PMessageExchange { promise: Promise; extras: { resolve: (data: any) => void; reject: (err: any) => void; }; constructor(extras: { resolve: () => void; reject: () => void; }, race: any); } /** * The handler of a WS2P connection. * * Goal: operating an authenticated bidirectionnal communication over a WebSocket connection. * Requires an established WebSocket connection in order to work. */ export declare class WS2PConnection { private ws2pVersion; private ws; private onWsOpened; private onWsClosed; private messageHandler; private localAuth; private remoteAuth; private options; private expectedPub; private expectedWS2PUID; private connectp; private connectedp; private connectedResolve; private connectedReject; private nbErrors; private nbRequestsCount; private nbResponsesCount; private nbPushsToRemoteCount; private nbPushsByRemoteCount; private exchanges; constructor(ws2pVersion: number, ws: any, onWsOpened: Promise, onWsClosed: Promise, messageHandler: WS2PMessageHandler, localAuth: WS2PLocalAuth, remoteAuth: WS2PRemoteAuth, options?: { connectionTimeout: number; requestTimeout: number; }, expectedPub?: string, expectedWS2PUID?: string); static newConnectionToAddress(ws2pVersion: number, address: string, messageHandler: WS2PMessageHandler, localAuth: WS2PLocalAuth, remoteAuth: WS2PRemoteAuth, proxySocksAddress?: string | undefined, options?: { connectionTimeout: number; requestTimeout: number; }, expectedPub?: string, expectedWS2PUID?: string): WS2PConnection; static newConnectionFromWebSocketServer(websocket: any, messageHandler: WS2PMessageHandler, localAuth: WS2PLocalAuth, remoteAuth: WS2PRemoteAuth, options?: { connectionTimeout: number; requestTimeout: number; }, expectedPub?: string): WS2PConnection; get version(): number; get pubkey(): string; get uuid(): string; get isSync(): boolean; get nbRequests(): number; get nbResponses(): number; get nbPushsToRemote(): number; get nbPushsByRemote(): number; get connected(): Promise; get closed(): Promise; close(): any; connectAsInitiator(): Promise; connect(initiator?: boolean): Promise; request(body: WS2PRequest): Promise; pushBlock(block: BlockDTO): Promise; pushIdentity(idty: IdentityDTO): Promise; pushCertification(cert: CertificationDTO): Promise; pushMembership(ms: MembershipDTO): Promise; pushTransaction(tx: TransactionDTO): Promise; pushPeer(peer: PeerDTO): Promise; pushHeads(heads: { message: string; sig: string; messageV2?: string; sigV2?: string; step?: number; }[]): Promise; pushData(type: WS2P_PUSH, key: string, data: any): Promise; private errorDetected; get hostName(): string; }