2022-09-09 07:20:52 +00:00
|
|
|
/// <reference types="node" />
|
|
|
|
import tls from "tls";
|
|
|
|
import type { Logger } from "loglevel";
|
|
|
|
import type { Ed25519Keypair, Err } from "libskynet";
|
|
|
|
import type express from "express";
|
2022-08-29 02:02:11 +00:00
|
|
|
export interface RPCRequest {
|
2022-08-29 02:11:57 +00:00
|
|
|
bypassCache?: boolean;
|
|
|
|
module: string;
|
|
|
|
method: string;
|
|
|
|
data: any;
|
2022-08-29 02:02:11 +00:00
|
|
|
}
|
|
|
|
export interface RPCResponse {
|
2022-08-29 02:11:57 +00:00
|
|
|
updated?: number;
|
|
|
|
data?: any;
|
|
|
|
error?: string;
|
2022-08-29 02:02:11 +00:00
|
|
|
}
|
|
|
|
export interface RPCMethod {
|
2022-08-29 02:11:57 +00:00
|
|
|
cacheable: boolean;
|
|
|
|
handler: (
|
|
|
|
request: RPCRequest,
|
|
|
|
sendStream: (stream: AsyncIterable<Uint8Array>) => void
|
|
|
|
) => Promise<RPCResponse | null>;
|
2022-08-29 02:02:11 +00:00
|
|
|
}
|
|
|
|
export interface StreamFileResponse {
|
2022-08-29 02:11:57 +00:00
|
|
|
data?: Uint8Array;
|
|
|
|
done: boolean;
|
2022-08-29 02:02:11 +00:00
|
|
|
}
|
|
|
|
export interface PluginAPI {
|
2022-08-29 02:11:57 +00:00
|
|
|
config: any;
|
|
|
|
registerMethod: (methodName: string, method: RPCMethod) => void;
|
|
|
|
loadPlugin: (moduleName: string) => Promise<Plugin>;
|
|
|
|
getMethods: () => string[];
|
2022-09-09 07:20:52 +00:00
|
|
|
ssl: {
|
|
|
|
setContext: (context: tls.SecureContext) => void;
|
|
|
|
getContext: () => tls.SecureContext;
|
|
|
|
getSaved: (retry: boolean) => Promise<boolean | SslData>;
|
2022-09-09 07:57:07 +00:00
|
|
|
set: (
|
|
|
|
cert: IndependentFileSmall | Uint8Array,
|
|
|
|
key: IndependentFileSmall | Uint8Array
|
|
|
|
) => void;
|
2022-09-09 07:20:52 +00:00
|
|
|
get: () => SslData;
|
|
|
|
save: () => Promise<void>;
|
|
|
|
};
|
|
|
|
appRouter: {
|
|
|
|
get: () => express.Router;
|
|
|
|
set: (newRouter: express.Router) => void;
|
|
|
|
reset: () => void;
|
|
|
|
};
|
2022-09-09 07:42:21 +00:00
|
|
|
files: {
|
|
|
|
createIndependentFileSmall(
|
|
|
|
seed: Uint8Array,
|
|
|
|
userInode: string,
|
|
|
|
fileData: Uint8Array
|
|
|
|
): Promise<[IndependentFileSmall, Err]>;
|
|
|
|
openIndependentFileSmall(
|
|
|
|
seed: Uint8Array,
|
|
|
|
userInode: string
|
|
|
|
): Promise<[IndependentFileSmall, Err]>;
|
|
|
|
overwriteIndependentFileSmall(
|
|
|
|
file: IndependentFileSmall,
|
|
|
|
newData: Uint8Array
|
|
|
|
): Promise<Err>;
|
|
|
|
};
|
2022-09-09 07:20:52 +00:00
|
|
|
logger: Logger;
|
2022-09-09 07:42:21 +00:00
|
|
|
getSeed: () => Uint8Array;
|
2022-08-29 02:02:11 +00:00
|
|
|
}
|
|
|
|
export declare type PluginFunction = (api: PluginAPI) => Promise<void>;
|
|
|
|
export interface Plugin {
|
2022-08-29 02:11:57 +00:00
|
|
|
name: string;
|
|
|
|
plugin: PluginFunction;
|
|
|
|
exports?: any;
|
|
|
|
default?: Plugin;
|
2022-08-29 02:02:11 +00:00
|
|
|
}
|
2022-08-29 02:11:57 +00:00
|
|
|
export declare type RPCStreamHandler = (
|
|
|
|
stream: AsyncIterable<Uint8Array>
|
|
|
|
) => Promise<RPCResponse>;
|
2022-09-09 07:20:52 +00:00
|
|
|
export declare type OverwriteDataFn = (newData: Uint8Array) => Promise<Err>;
|
|
|
|
export declare type ReadDataFn = () => Promise<[Uint8Array, Err]>;
|
|
|
|
export interface IndependentFileSmallMetadata {
|
|
|
|
largestHistoricSize: bigint;
|
|
|
|
}
|
|
|
|
export interface IndependentFileSmall {
|
|
|
|
dataKey: Uint8Array;
|
|
|
|
fileData: Uint8Array;
|
|
|
|
inode: string;
|
|
|
|
keypair: Ed25519Keypair;
|
|
|
|
metadata: IndependentFileSmallMetadata;
|
|
|
|
revision: bigint;
|
|
|
|
seed: Uint8Array;
|
|
|
|
skylink: string;
|
|
|
|
viewKey: string;
|
|
|
|
overwriteData: OverwriteDataFn;
|
|
|
|
readData: ReadDataFn;
|
|
|
|
}
|
|
|
|
export interface SslData {
|
2022-09-09 07:57:07 +00:00
|
|
|
cert?: IndependentFileSmall | Uint8Array;
|
|
|
|
key?: IndependentFileSmall | Uint8Array;
|
2022-09-09 07:20:52 +00:00
|
|
|
}
|
2022-08-29 02:11:57 +00:00
|
|
|
//# sourceMappingURL=index.d.ts.map
|