From 648c366b6de1a55fa791ea3ac0e37f63c1601164 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Fri, 9 Sep 2022 03:20:31 -0400 Subject: [PATCH] *Add plugin api for ssl, approuter, and logger *Move IndependentFile types to types repo as it will be used by plugins --- package.json | 7 ++++++- src/index.ts | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index cdfb8f3..4f7fd7c 100644 --- a/package.json +++ b/package.json @@ -2,5 +2,10 @@ "name": "@lumeweb/relay-types", "version": "0.1.0", "main": "dist", - "type": "module" + "type": "module", + "devDependencies": { + "@types/node": "^18.7.16", + "express": "^4.18.1", + "loglevel": "^1.8.0" + } } diff --git a/src/index.ts b/src/index.ts index 3e6d31c..56bbe3c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,3 +1,8 @@ +import tls from "tls"; +import type { Logger } from "loglevel"; +import type { Ed25519Keypair, Err } from "libskynet"; +import type express from "express"; + export interface RPCRequest { bypassCache?: boolean; module: string; @@ -29,6 +34,20 @@ export interface PluginAPI { registerMethod: (methodName: string, method: RPCMethod) => void; loadPlugin: (moduleName: string) => Promise; getMethods: () => string[]; + ssl: { + setContext: (context: tls.SecureContext) => void; + getContext: () => tls.SecureContext; + getSaved: (retry: boolean) => Promise; + set: (cert: IndependentFileSmall, key: IndependentFileSmall) => void; + get: () => SslData; + save: () => Promise; + }; + appRouter: { + get: () => express.Router; + set: (newRouter: express.Router) => void; + reset: () => void; + }; + logger: Logger; } export type PluginFunction = (api: PluginAPI) => Promise; @@ -43,3 +62,33 @@ export interface Plugin { export type RPCStreamHandler = ( stream: AsyncIterable ) => Promise; + +export type OverwriteDataFn = (newData: Uint8Array) => Promise; + +export 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 { + cert?: IndependentFileSmall; + key?: IndependentFileSmall; +}