interface-relay/dist/rpc.d.ts

64 lines
1.6 KiB
TypeScript
Raw Normal View History

2022-11-26 07:54:14 +00:00
/// <reference types="node" />
/// <reference types="node" />
import type EventEmitter from "events";
2022-11-28 07:22:12 +00:00
import type NodeCache from "node-cache";
2022-12-19 20:19:47 +00:00
import type DHTCache from "@lumeweb/dht-cache";
2022-11-26 07:54:14 +00:00
export interface RPCRequest {
module: string;
method: string;
data: any;
}
export interface ClientRPCRequest extends RPCRequest {
bypassCache?: boolean;
}
export interface RPCResponse {
updated?: number;
data?: any | RPCResponse;
error?: string;
signature?: string;
signedField?: string;
}
export interface RPCMethod {
cacheable: boolean;
handler: (req: any) => Promise<any>;
}
export interface RPCCacheData {
[query: string]: RPCCacheItem | null;
}
export interface RPCCacheItem extends RPCResponse {
value: RPCResponse;
signature: string;
}
export interface RPCBroadcastRequest {
request: RPCRequest;
relays: string[];
2022-12-15 09:47:36 +00:00
timeout: number;
2022-11-26 07:54:14 +00:00
}
export interface RPCBroadcastResponse extends RPCResponse {
relays: {
[relay: string]: RPCResponse;
};
}
export declare class RPCServer extends EventEmitter {
get cache(): RPCCache;
registerMethod(
moduleName: string,
methodName: string,
options: RPCMethod
): void;
getMethods(): string[];
setup(stream: any): any;
signData(data: any): string;
static hashQuery(query: RPCRequest): string;
}
export declare class RPCCache extends EventEmitter {
2022-11-28 07:22:12 +00:00
get data(): NodeCache;
2022-12-19 20:19:47 +00:00
get dhtCache(): DHTCache;
2022-11-26 07:54:14 +00:00
constructor(server: RPCServer);
signResponse(item: RPCCacheItem): any;
verifyResponse(pubkey: Buffer, item: RPCCacheItem): boolean | Buffer;
addItem(query: RPCRequest, response: RPCResponse): void;
deleteItem(queryHash: string): boolean;
}
//# sourceMappingURL=rpc.d.ts.map