@interncom/diplomatic 0.0.75 → 0.1.1

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.
Files changed (83) hide show
  1. package/README.md +12 -6
  2. package/dist/client.d.ts +44 -56
  3. package/dist/entdb/entdb.d.ts +42 -0
  4. package/dist/entdb/idb.d.ts +28 -0
  5. package/dist/entdb/memory.d.ts +30 -0
  6. package/dist/events.d.ts +18 -0
  7. package/dist/exim.d.ts +0 -0
  8. package/dist/index.d.ts +21 -13
  9. package/dist/index.mjs +6359 -7052
  10. package/dist/lib.d.ts +2 -0
  11. package/dist/react/useClient.d.ts +17 -5
  12. package/dist/react/useEntities.d.ts +0 -0
  13. package/dist/react/useStateWatcher.d.ts +3 -3
  14. package/dist/shared/api/peek.d.ts +3 -0
  15. package/dist/shared/api/pull.d.ts +3 -0
  16. package/dist/shared/api/push.d.ts +4 -0
  17. package/dist/shared/api/user.d.ts +2 -0
  18. package/dist/shared/auth.d.ts +8 -0
  19. package/dist/shared/bag.d.ts +15 -0
  20. package/dist/shared/binary.d.ts +8 -0
  21. package/dist/shared/client.d.ts +20 -9
  22. package/dist/shared/clock.d.ts +13 -0
  23. package/dist/shared/codec.d.ts +43 -0
  24. package/dist/shared/codecs/authTimestamp.d.ts +8 -0
  25. package/dist/shared/codecs/bag.d.ts +3 -0
  26. package/dist/shared/codecs/eid.d.ts +10 -0
  27. package/dist/shared/codecs/file.d.ts +8 -0
  28. package/dist/shared/codecs/fileHead.d.ts +10 -0
  29. package/dist/shared/codecs/fileIndexItem.d.ts +8 -0
  30. package/dist/shared/codecs/messageHead.d.ts +16 -0
  31. package/dist/shared/codecs/notifItem.d.ts +7 -0
  32. package/dist/shared/codecs/peekItem.d.ts +6 -0
  33. package/dist/shared/codecs/peekItemHead.d.ts +7 -0
  34. package/dist/shared/codecs/pullItem.d.ts +6 -0
  35. package/dist/shared/codecs/pushItem.d.ts +11 -0
  36. package/dist/shared/codecs/respHead.d.ts +10 -0
  37. package/dist/shared/codecs/usageQuota.d.ts +6 -0
  38. package/dist/shared/consts.d.ts +50 -0
  39. package/dist/shared/crypto/libsodium.d.ts +5 -5
  40. package/dist/shared/enclave.d.ts +8 -0
  41. package/dist/shared/endpoint.d.ts +23 -0
  42. package/dist/shared/exim.d.ts +12 -0
  43. package/dist/shared/http/listener.d.ts +11 -0
  44. package/dist/shared/http/server.d.ts +11 -0
  45. package/dist/shared/http.d.ts +82 -0
  46. package/dist/shared/lpc/listener.d.ts +16 -0
  47. package/dist/shared/lpc/pusher.d.ts +9 -0
  48. package/dist/shared/lpc/server.d.ts +19 -0
  49. package/dist/shared/message.d.ts +30 -0
  50. package/dist/shared/storage/memory.d.ts +10 -0
  51. package/dist/shared/sync.d.ts +9 -0
  52. package/dist/shared/types.d.ts +127 -49
  53. package/dist/shared/valstat.d.ts +6 -0
  54. package/dist/state.d.ts +12 -17
  55. package/dist/stores/idb/dnlds.d.ts +10 -0
  56. package/dist/stores/idb/hosts.d.ts +15 -0
  57. package/dist/stores/idb/msgs.d.ts +19 -0
  58. package/dist/stores/idb/seed.d.ts +11 -0
  59. package/dist/stores/idb/store.d.ts +24 -0
  60. package/dist/stores/idb/uplds.d.ts +11 -0
  61. package/dist/stores/memory/dnlds.d.ts +9 -0
  62. package/dist/stores/memory/hosts.d.ts +13 -0
  63. package/dist/stores/memory/msgs.d.ts +19 -0
  64. package/dist/stores/memory/seed.d.ts +9 -0
  65. package/dist/stores/memory/store.d.ts +16 -0
  66. package/dist/stores/memory/uplds.d.ts +10 -0
  67. package/dist/sync.d.ts +25 -2
  68. package/dist/types.d.ts +113 -29
  69. package/package.json +10 -7
  70. package/dist/api.d.ts +0 -3
  71. package/dist/entityDB.d.ts +0 -34
  72. package/dist/eventEmitter.d.ts +0 -8
  73. package/dist/idbStore.d.ts +0 -38
  74. package/dist/localStorageStore.d.ts +0 -36
  75. package/dist/memoryStore.d.ts +0 -40
  76. package/dist/queue.d.ts +0 -10
  77. package/dist/react/initSeedView.d.ts +0 -7
  78. package/dist/react/statusBar.d.ts +0 -7
  79. package/dist/shared/lib.d.ts +0 -2
  80. package/dist/shared/ops.d.ts +0 -4
  81. package/dist/shared/server.d.ts +0 -12
  82. package/dist/typedEventEmitter.d.ts +0 -8
  83. package/dist/useClient.d.ts +0 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@interncom/diplomatic",
3
- "version": "0.0.75",
3
+ "version": "0.1.1",
4
4
  "type": "module",
5
5
  "description": "Secure sync layer",
6
6
  "main": "dist/index.mjs",
@@ -11,7 +11,9 @@
11
11
  "scripts": {
12
12
  "tsc": "tsc",
13
13
  "build": "node esbuild.mjs",
14
- "test": "vitest"
14
+ "test": "vitest",
15
+ "coverage": "vitest run --coverage",
16
+ "fmt": "deno fmt"
15
17
  },
16
18
  "author": "The Internet Committee",
17
19
  "license": "ISC",
@@ -22,18 +24,19 @@
22
24
  "@types/file-saver": "^2.0.7",
23
25
  "@types/node": "^20.14.11",
24
26
  "@types/react": "^19.1.0",
27
+ "@vitest/coverage-v8": "^4.0.17",
25
28
  "esbuild": "0.21.5",
26
29
  "react": "^19.1.0",
27
30
  "typescript": "^5.8.3",
28
- "vitest": "^3.1.2"
31
+ "vitest": "^4.0.17"
29
32
  },
30
33
  "peerDependencies": {
31
34
  "react": "^19.0.0"
32
35
  },
33
36
  "dependencies": {
34
- "@msgpack/msgpack": "^3.0.0-beta2",
35
- "file-saver": "^2.0.5",
36
- "idb": "^8.0.0",
37
- "jszip": "^3.10.1"
37
+ "@msgpack/msgpack": "3.1.3",
38
+ "@noble/hashes": "1.8.0",
39
+ "file-saver": "2.0.5",
40
+ "libsodium.js": "git+ssh://github.com/interncom/libsodium.js#e4e7647"
38
41
  }
39
42
  }
package/dist/api.d.ts DELETED
@@ -1,3 +0,0 @@
1
- import DiplomaticClientAPI from "./shared/client";
2
- declare const webClientAPI: DiplomaticClientAPI;
3
- export default webClientAPI;
@@ -1,34 +0,0 @@
1
- import { type DBSchema } from "idb";
2
- import type { Applier } from "./types";
3
- import { type EntityID, type GroupID } from "./shared/types";
4
- import { StateManager } from "./state";
5
- export declare const entityTableName = "entities";
6
- export declare const typeIndexName = "entity_type_created_at";
7
- export declare const typeUpdatedAtIndexName = "entity_type_updated_at";
8
- export declare const typeGroupIndexName = "entity_type_group_id";
9
- export declare const typeParentIndexName = "entity_type_parent_id";
10
- export interface IEntity<T> {
11
- eid: EntityID;
12
- gid?: GroupID;
13
- pid?: EntityID;
14
- type: string;
15
- updatedAt: Date;
16
- createdAt: Date;
17
- body: T;
18
- }
19
- interface IEntityDB extends DBSchema {
20
- entities: {
21
- key: Uint8Array;
22
- value: IEntity<unknown>;
23
- indexes: {
24
- [typeIndexName]: [string, Date];
25
- [typeUpdatedAtIndexName]: [string, Date];
26
- [typeGroupIndexName]: [string, GroupID];
27
- [typeParentIndexName]: [string, EntityID];
28
- };
29
- };
30
- }
31
- export declare const db: import("idb").IDBPDatabase<IEntityDB>;
32
- export declare const applier: Applier;
33
- export declare const stateManager: StateManager;
34
- export {};
@@ -1,8 +0,0 @@
1
- type Listener = () => void;
2
- export declare class EventEmitter {
3
- private events;
4
- on(event: string, listener: Listener): void;
5
- off(event: string, listener: Listener): void;
6
- emit(event: string): void;
7
- }
8
- export {};
@@ -1,38 +0,0 @@
1
- import type { IClientStateStore } from "./types";
2
- declare class IDBStore implements IClientStateStore {
3
- seed?: Uint8Array;
4
- hostURL?: string;
5
- hostID?: string;
6
- lastFetchedAt?: Date;
7
- wipe(): Promise<void>;
8
- getSeed(): Promise<Uint8Array<ArrayBufferLike> | undefined>;
9
- setSeed(seed: Uint8Array): Promise<void>;
10
- getHostURL(): Promise<string | undefined>;
11
- setHostURL(url: string): Promise<void>;
12
- getHostID(): Promise<string | undefined>;
13
- setHostID(id: string): Promise<void>;
14
- getLastFetchedAt(): Promise<Date | undefined>;
15
- setLastFetchedAt(ts: Date): Promise<void>;
16
- enqueueUpload: (sha256: Uint8Array, cipherOp: Uint8Array) => Promise<void>;
17
- dequeueUpload: (sha256: Uint8Array) => Promise<void>;
18
- peekUpload: (sha256: Uint8Array) => Promise<Uint8Array<ArrayBufferLike> | undefined>;
19
- listUploads: () => Promise<Uint8Array<ArrayBufferLike>[]>;
20
- numUploads: () => Promise<number>;
21
- downloadQueue: Set<string>;
22
- enqueueDownload: (sha256: Uint8Array, recordedAt: Date) => Promise<void>;
23
- dequeueDownload: (sha256: Uint8Array) => Promise<void>;
24
- listDownloads: () => Promise<{
25
- sha256: Uint8Array<ArrayBufferLike>;
26
- recordedAt: Date;
27
- }[]>;
28
- numDownloads: () => Promise<number>;
29
- storeOp: (sha256: Uint8Array, cipherOp: Uint8Array) => Promise<void>;
30
- clearOp: (sha256: Uint8Array) => Promise<void>;
31
- listOps: () => Promise<{
32
- sha256: string;
33
- cipherOp: Uint8Array<ArrayBufferLike>;
34
- }[]>;
35
- hasOp: (sha256: Uint8Array) => Promise<boolean>;
36
- }
37
- export declare const idbStore: IDBStore;
38
- export {};
@@ -1,36 +0,0 @@
1
- import type { IClientStateStore } from "./types";
2
- declare class LocalStorageStore implements IClientStateStore {
3
- wipe(): Promise<void>;
4
- getSeed(): Promise<Uint8Array<ArrayBufferLike> | 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
- getLastFetchedAt(): Promise<Date | undefined>;
11
- setLastFetchedAt(ts: Date): Promise<void>;
12
- uploadQueue: Map<string, Uint8Array<ArrayBufferLike>>;
13
- enqueueUpload: (sha256: Uint8Array, cipherOp: Uint8Array) => Promise<void>;
14
- dequeueUpload: (sha256: Uint8Array) => Promise<void>;
15
- peekUpload: (sha256: Uint8Array) => Promise<Uint8Array<ArrayBufferLike> | undefined>;
16
- listUploads: () => Promise<Uint8Array<ArrayBufferLike>[]>;
17
- numUploads: () => Promise<number>;
18
- downloadQueue: Map<string, Date>;
19
- enqueueDownload: (sha256: Uint8Array, recordedAt: Date) => Promise<void>;
20
- dequeueDownload: (sha256: Uint8Array) => Promise<void>;
21
- listDownloads: () => Promise<{
22
- sha256: Uint8Array<ArrayBufferLike>;
23
- recordedAt: Date;
24
- }[]>;
25
- numDownloads: () => Promise<number>;
26
- ops: Map<string, Uint8Array<ArrayBufferLike>>;
27
- storeOp: (sha256: Uint8Array, cipherOp: Uint8Array) => Promise<void>;
28
- clearOp: (sha256: Uint8Array) => Promise<void>;
29
- listOps: () => Promise<{
30
- sha256: string;
31
- cipherOp: Uint8Array<ArrayBufferLike>;
32
- }[]>;
33
- hasOp: (sha256: Uint8Array) => Promise<boolean>;
34
- }
35
- export declare const localStorageStore: LocalStorageStore;
36
- export {};
@@ -1,40 +0,0 @@
1
- import type { IClientStateStore } from "./types";
2
- declare class MemoryStore implements IClientStateStore {
3
- seed?: Uint8Array;
4
- hostURL?: string;
5
- hostID?: string;
6
- lastFetchedAt?: Date;
7
- wipe(): Promise<void>;
8
- getSeed(): Promise<Uint8Array<ArrayBufferLike> | undefined>;
9
- setSeed(seed: Uint8Array): Promise<void>;
10
- getHostURL(): Promise<string | undefined>;
11
- setHostURL(url: string): Promise<void>;
12
- getHostID(): Promise<string | undefined>;
13
- setHostID(id: string): Promise<void>;
14
- getLastFetchedAt(): Promise<Date | undefined>;
15
- setLastFetchedAt(ts: Date): Promise<void>;
16
- uploadQueue: Map<string, Uint8Array<ArrayBufferLike>>;
17
- enqueueUpload: (sha256: Uint8Array, cipherOp: Uint8Array) => Promise<void>;
18
- dequeueUpload: (sha256: Uint8Array) => Promise<void>;
19
- peekUpload: (sha256: Uint8Array) => Promise<Uint8Array<ArrayBufferLike> | undefined>;
20
- listUploads: () => Promise<Uint8Array<ArrayBufferLike>[]>;
21
- numUploads: () => Promise<number>;
22
- downloadQueue: Map<string, Date>;
23
- enqueueDownload: (sha256: Uint8Array, recordedAt: Date) => Promise<void>;
24
- dequeueDownload: (sha256: Uint8Array) => Promise<void>;
25
- listDownloads: () => Promise<{
26
- sha256: Uint8Array<ArrayBufferLike>;
27
- recordedAt: Date;
28
- }[]>;
29
- numDownloads: () => Promise<number>;
30
- ops: Map<string, Uint8Array<ArrayBufferLike>>;
31
- storeOp: (sha256: Uint8Array, cipherOp: Uint8Array) => Promise<void>;
32
- clearOp: (sha256: Uint8Array) => Promise<void>;
33
- listOps: () => Promise<{
34
- sha256: string;
35
- cipherOp: Uint8Array<ArrayBufferLike>;
36
- }[]>;
37
- hasOp: (sha256: Uint8Array) => Promise<boolean>;
38
- }
39
- export declare const memoryStore: MemoryStore;
40
- export {};
package/dist/queue.d.ts DELETED
@@ -1,10 +0,0 @@
1
- import type { IQueue } from "./types";
2
- export declare class Queue<K, V> implements IQueue<K, V> {
3
- private map;
4
- constructor();
5
- enqueue(key: K, value: V): Promise<void>;
6
- peek(key: K): Promise<V | undefined>;
7
- entries(): Promise<Array<[K, V]>>;
8
- dequeue(key: K): Promise<V | undefined>;
9
- size(): Promise<number>;
10
- }
@@ -1,7 +0,0 @@
1
- import type DiplomaticClient from "../client";
2
- interface IProps {
3
- client: DiplomaticClient;
4
- path: string;
5
- }
6
- export default function InitSeedView({ client, path }: IProps): import("react/jsx-runtime").JSX.Element;
7
- export {};
@@ -1,7 +0,0 @@
1
- import type { IDiplomaticClientState, IDiplomaticClientXferState } from "../types";
2
- interface IProps {
3
- state: IDiplomaticClientState;
4
- xferState: IDiplomaticClientXferState;
5
- }
6
- export default function ClientStatusBar({ state, xferState }: IProps): import("react/jsx-runtime").JSX.Element;
7
- export {};
@@ -1,2 +0,0 @@
1
- export declare function btoh(bytes: Uint8Array): string;
2
- export declare function htob(hex: string): Uint8Array;
@@ -1,4 +0,0 @@
1
- import { type EntityID, type GroupID, type IDeleteOp, type IOp, type IUpsertOp } from "./types.ts";
2
- export declare function genUpsertOp<T>(eid: EntityID, type: string, body: T, version?: number, gid?: GroupID, pid?: EntityID): IUpsertOp;
3
- export declare function genDeleteOp<T>(eid: Uint8Array, type: string, version?: number): IDeleteOp;
4
- export declare function isOp(op: any): op is IOp;
@@ -1,12 +0,0 @@
1
- import type { IHostCrypto, IMsgpackCodec, IStorage, IWebsocketNotifier } from "./types.ts";
2
- export declare class DiplomaticServer {
3
- hostID: string;
4
- regToken: string;
5
- storage: IStorage;
6
- codec: IMsgpackCodec;
7
- crypto: IHostCrypto;
8
- notifier: IWebsocketNotifier;
9
- constructor(hostID: string, regToken: string, storage: IStorage, codec: IMsgpackCodec, crypto: IHostCrypto, notifier: IWebsocketNotifier);
10
- corsHandler: (request: Request) => Promise<Response>;
11
- handler: (request: Request) => Promise<Response>;
12
- }
@@ -1,8 +0,0 @@
1
- type Listener<T> = (data: T) => void;
2
- export default class TypedEventEmitter<T> {
3
- private listeners;
4
- addEventListener(eventType: string, listener: Listener<T>): () => void;
5
- removeEventListener(eventType: string, listener: Listener<T>): void;
6
- emit(eventType: string, data: T): void;
7
- }
8
- export {};
@@ -1,4 +0,0 @@
1
- import type { IDiplomaticClientState } from "./types";
2
- import type DiplomaticClient from "./client";
3
- export declare function useClientState(client: DiplomaticClient): IDiplomaticClientState | undefined;
4
- export declare function useSyncOnResume(client: DiplomaticClient): void;