@interncom/diplomatic 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +34 -0
- package/dist/api.d.ts +3 -0
- package/dist/client.d.ts +34 -0
- package/dist/crypto.d.ts +3 -0
- package/dist/eventEmitter.d.ts +8 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +8600 -0
- package/dist/localStorageStore.d.ts +19 -0
- package/dist/ops.d.ts +2 -0
- package/dist/shared/client.d.ts +11 -0
- package/dist/shared/crypto/libsodium.d.ts +15 -0
- package/dist/shared/lib.d.ts +2 -0
- package/dist/shared/server.d.ts +11 -0
- package/dist/shared/types.d.ts +58 -0
- package/dist/state.d.ts +12 -0
- package/dist/sync.d.ts +2 -0
- package/dist/types.d.ts +18 -0
- package/dist/useClient.d.ts +8 -0
- package/package.json +32 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { IClientStateStore } from "./types";
|
|
2
|
+
declare class LocalStorageStore implements IClientStateStore {
|
|
3
|
+
getSeed(): Promise<Uint8Array | undefined>;
|
|
4
|
+
setSeed(seed: Uint8Array): Promise<void>;
|
|
5
|
+
getHostURL(): Promise<string | undefined>;
|
|
6
|
+
setHostURL(url: string): Promise<void>;
|
|
7
|
+
getHostID(): Promise<string | undefined>;
|
|
8
|
+
setHostID(id: string): Promise<void>;
|
|
9
|
+
uploadQueue: Map<string, Uint8Array>;
|
|
10
|
+
enqueueUpload: (sha256: Uint8Array, cipherOp: Uint8Array) => Promise<void>;
|
|
11
|
+
dequeueUpload: (sha256: Uint8Array) => Promise<void>;
|
|
12
|
+
peekUpload: (sha256: Uint8Array) => Promise<Uint8Array | undefined>;
|
|
13
|
+
listUploadQueue(): Promise<string[]>;
|
|
14
|
+
downloadQueue: Set<string>;
|
|
15
|
+
enqueueDownload: (path: string) => Promise<void>;
|
|
16
|
+
dequeueDownload: (path: string) => Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
export declare const localStorageStore: LocalStorageStore;
|
|
19
|
+
export {};
|
package/dist/ops.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ICrypto, IGetDeltaPathsResponse, IMsgpackCodec, KeyPair } from "./types.ts";
|
|
2
|
+
export default class DiplomaticClientAPI {
|
|
3
|
+
codec: IMsgpackCodec;
|
|
4
|
+
crypto: ICrypto;
|
|
5
|
+
constructor(codec: IMsgpackCodec, crypto: ICrypto);
|
|
6
|
+
getHostID(hostURL: URL): Promise<string>;
|
|
7
|
+
register(hostURL: URL, pubKey: Uint8Array, token: string): Promise<void>;
|
|
8
|
+
putDelta(hostURL: URL, cipherOp: Uint8Array, keyPair: KeyPair): Promise<string>;
|
|
9
|
+
getDelta(hostURL: URL, opPath: string, keyPair: KeyPair): Promise<Uint8Array>;
|
|
10
|
+
getDeltaPaths(hostURL: URL, begin: Date, keyPair: KeyPair): Promise<IGetDeltaPathsResponse>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ICrypto, KeyPair } from "../types.ts";
|
|
2
|
+
type Libsodium = any;
|
|
3
|
+
export declare class LibsodiumCrypto implements ICrypto {
|
|
4
|
+
sodium: Libsodium;
|
|
5
|
+
constructor(sodium: Libsodium);
|
|
6
|
+
gen256BitSecureRandomSeed(): Promise<Uint8Array>;
|
|
7
|
+
deriveXSalsa20Poly1305Key(seed: Uint8Array): Promise<Uint8Array>;
|
|
8
|
+
encryptXSalsa20Poly1305Combined(data: Uint8Array, key: Uint8Array): Promise<Uint8Array>;
|
|
9
|
+
decryptXSalsa20Poly1305Combined(data: Uint8Array, key: Uint8Array): Promise<Uint8Array>;
|
|
10
|
+
deriveEd25519KeyPair(seed: Uint8Array, hostID: string, derivationIndex?: number): Promise<KeyPair>;
|
|
11
|
+
signEd25519(message: Uint8Array | string, secKey: Uint8Array): Promise<Uint8Array>;
|
|
12
|
+
checkSigEd25519(sig: Uint8Array, message: Uint8Array | string, pubKey: Uint8Array): Promise<boolean>;
|
|
13
|
+
sha256Hash(data: Uint8Array): Promise<Uint8Array>;
|
|
14
|
+
}
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { IHostCrypto, IMsgpackCodec, IStorage } from "./types.ts";
|
|
2
|
+
export declare class DiplomaticServer {
|
|
3
|
+
hostID: string;
|
|
4
|
+
regToken: string;
|
|
5
|
+
storage: IStorage;
|
|
6
|
+
codec: IMsgpackCodec;
|
|
7
|
+
crypto: IHostCrypto;
|
|
8
|
+
constructor(hostID: string, regToken: string, storage: IStorage, codec: IMsgpackCodec, crypto: IHostCrypto);
|
|
9
|
+
corsHandler: (request: Request) => Promise<Response>;
|
|
10
|
+
handler: (request: Request) => Promise<Response>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
export declare enum Verb {
|
|
2
|
+
DELETE = 0,
|
|
3
|
+
UPSERT = 1
|
|
4
|
+
}
|
|
5
|
+
type Timestamp = string;
|
|
6
|
+
export interface IOp {
|
|
7
|
+
ts: Timestamp;
|
|
8
|
+
type: string;
|
|
9
|
+
verb: Verb;
|
|
10
|
+
ver: number;
|
|
11
|
+
body: unknown;
|
|
12
|
+
}
|
|
13
|
+
export type CipherOp = Uint8Array;
|
|
14
|
+
export interface ISyncRequest {
|
|
15
|
+
ops: CipherOp[];
|
|
16
|
+
begin: Timestamp;
|
|
17
|
+
}
|
|
18
|
+
export interface IRegistrationRequest {
|
|
19
|
+
token: string;
|
|
20
|
+
pubKey: Uint8Array;
|
|
21
|
+
}
|
|
22
|
+
export interface IOperationRequest {
|
|
23
|
+
cipher: Uint8Array;
|
|
24
|
+
}
|
|
25
|
+
export interface IGetDeltaPathsResponse {
|
|
26
|
+
paths: string[];
|
|
27
|
+
fetchedAt: string;
|
|
28
|
+
}
|
|
29
|
+
export interface IStorage {
|
|
30
|
+
addUser: (pubKeyHex: string) => Promise<void>;
|
|
31
|
+
hasUser: (pubKeyHex: string) => Promise<boolean>;
|
|
32
|
+
setOp: (pubKeyHex: string, path: string, op: Uint8Array) => Promise<void>;
|
|
33
|
+
getOp: (pubKeyHex: string, path: string) => Promise<Uint8Array | undefined>;
|
|
34
|
+
listOps: (pubKeyHex: string, begin: string, end: string) => Promise<string[]>;
|
|
35
|
+
}
|
|
36
|
+
export interface KeyPair {
|
|
37
|
+
keyType: "public" | "private" | "secret";
|
|
38
|
+
privateKey: Uint8Array;
|
|
39
|
+
publicKey: Uint8Array;
|
|
40
|
+
}
|
|
41
|
+
export interface IHostCrypto {
|
|
42
|
+
checkSigEd25519: (sig: Uint8Array, message: Uint8Array | string, pubKey: Uint8Array) => Promise<boolean>;
|
|
43
|
+
sha256Hash: (data: Uint8Array) => Promise<Uint8Array>;
|
|
44
|
+
}
|
|
45
|
+
export interface ICrypto extends IHostCrypto {
|
|
46
|
+
gen256BitSecureRandomSeed: () => Promise<Uint8Array>;
|
|
47
|
+
deriveXSalsa20Poly1305Key: (seed: Uint8Array, derivationIndex: number) => Promise<Uint8Array>;
|
|
48
|
+
encryptXSalsa20Poly1305Combined: (plaintext: Uint8Array, key: Uint8Array) => Promise<Uint8Array>;
|
|
49
|
+
decryptXSalsa20Poly1305Combined: (headerAndCipher: Uint8Array, key: Uint8Array) => Promise<Uint8Array>;
|
|
50
|
+
deriveEd25519KeyPair: (seed: Uint8Array, hostID: string, derivationIndex: number) => Promise<KeyPair>;
|
|
51
|
+
signEd25519: (message: Uint8Array | string, secKey: Uint8Array) => Promise<Uint8Array>;
|
|
52
|
+
}
|
|
53
|
+
export interface IMsgpackCodec {
|
|
54
|
+
encode: (source: unknown) => Uint8Array;
|
|
55
|
+
decode: (packed: ArrayBuffer | Uint8Array) => unknown;
|
|
56
|
+
decodeAsync: (stream: ReadableStream<Uint8Array>) => Promise<unknown>;
|
|
57
|
+
}
|
|
58
|
+
export {};
|
package/dist/state.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { EventEmitter } from "./eventEmitter";
|
|
2
|
+
import type { Applier } from "./types";
|
|
3
|
+
import type { IOp } from "./shared/types";
|
|
4
|
+
export declare class StateManager {
|
|
5
|
+
emitter: EventEmitter;
|
|
6
|
+
applier: Applier;
|
|
7
|
+
constructor(applier: Applier);
|
|
8
|
+
apply: (op: IOp) => Promise<void>;
|
|
9
|
+
on: (opType: string, listener: () => void) => void;
|
|
10
|
+
off: (opType: string, listener: () => void) => void;
|
|
11
|
+
}
|
|
12
|
+
export declare function useStateWatcher<T>(mgr: StateManager, opType: string, callback: () => T): T;
|
package/dist/sync.d.ts
ADDED
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { IOp } from "./shared/types";
|
|
2
|
+
export interface IClientStateStore {
|
|
3
|
+
init?: () => Promise<void>;
|
|
4
|
+
getSeed: () => Promise<Uint8Array | undefined>;
|
|
5
|
+
setSeed: (seed: Uint8Array) => Promise<void>;
|
|
6
|
+
getHostURL: () => Promise<string | undefined>;
|
|
7
|
+
setHostURL: (url: string) => Promise<void>;
|
|
8
|
+
getHostID: () => Promise<string | undefined>;
|
|
9
|
+
setHostID: (id: string) => Promise<void>;
|
|
10
|
+
enqueueUpload: (sha256: Uint8Array, cipherOp: Uint8Array) => Promise<void>;
|
|
11
|
+
dequeueUpload: (sha256: Uint8Array) => Promise<void>;
|
|
12
|
+
peekUpload: (sha256: Uint8Array) => Promise<Uint8Array | undefined>;
|
|
13
|
+
listUploadQueue: () => Promise<string[]>;
|
|
14
|
+
enqueueDownload: (path: string) => Promise<void>;
|
|
15
|
+
dequeueDownload: (path: string) => Promise<void>;
|
|
16
|
+
}
|
|
17
|
+
export type DiplomaticClientState = "loading" | "seedless" | "hostless" | "ready";
|
|
18
|
+
export type Applier = (op: IOp) => Promise<void>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import DiplomaticClient, { type IDiplomaticClientParams } from "./client";
|
|
2
|
+
import type { DiplomaticClientState, IClientStateStore } from "./types";
|
|
3
|
+
interface IClientHookParams extends Omit<IDiplomaticClientParams, "store"> {
|
|
4
|
+
refreshInterval?: number;
|
|
5
|
+
store?: IClientStateStore;
|
|
6
|
+
}
|
|
7
|
+
export default function useClient(params: IClientHookParams): [DiplomaticClient, DiplomaticClientState, () => void];
|
|
8
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@interncom/diplomatic",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Secure sync layer",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"scripts": {
|
|
12
|
+
"tsc": "tsc",
|
|
13
|
+
"build": "node esbuild.mjs"
|
|
14
|
+
},
|
|
15
|
+
"author": "The Internet Committee",
|
|
16
|
+
"license": "ISC",
|
|
17
|
+
"publishConfig": {
|
|
18
|
+
"access": "public"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@types/react": "^18.3.3",
|
|
22
|
+
"react": "^18.3.1",
|
|
23
|
+
"esbuild": "0.21.5",
|
|
24
|
+
"typescript": "^5.5.2"
|
|
25
|
+
},
|
|
26
|
+
"peerDependencies": {
|
|
27
|
+
"react": "^18.3.1"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@msgpack/msgpack": "^3.0.0-beta2"
|
|
31
|
+
}
|
|
32
|
+
}
|