@interncom/diplomatic 0.1.2 → 0.2.0-rc1
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 +69 -42
- package/dist/cli/bin/host.js +6 -0
- package/dist/cli/bun/src/codec.d.ts +3 -0
- package/dist/cli/bun/src/crypto.d.ts +3 -0
- package/dist/cli/bun/src/host.d.ts +1 -0
- package/dist/cli/bun/src/storage/sqlite.d.ts +3 -0
- package/dist/cli/index.js +6020 -0
- package/dist/cli/index.mjs +6020 -0
- package/dist/{shared/crypto/libsodium.d.ts → cli/shared/crypto/noble.d.ts} +1 -6
- package/dist/{shared → cli/shared}/types.d.ts +1 -2
- package/dist/cli/src/index.d.ts +44 -0
- package/dist/{client.d.ts → web/client.d.ts} +1 -1
- package/dist/web/crypto.d.ts +3 -0
- package/dist/{index.d.ts → web/index.d.ts} +3 -3
- package/dist/web/index.js +6800 -0
- package/dist/web/index.mjs +7645 -0
- package/dist/web/shared/api/peek.d.ts +3 -0
- package/dist/web/shared/api/pull.d.ts +3 -0
- package/dist/web/shared/api/push.d.ts +4 -0
- package/dist/web/shared/api/user.d.ts +2 -0
- package/dist/web/shared/auth.d.ts +8 -0
- package/dist/web/shared/bag.d.ts +15 -0
- package/dist/web/shared/binary.d.ts +8 -0
- package/dist/web/shared/client.d.ts +22 -0
- package/dist/web/shared/clock.d.ts +13 -0
- package/dist/web/shared/codec.d.ts +43 -0
- package/dist/web/shared/codecs/authTimestamp.d.ts +8 -0
- package/dist/web/shared/codecs/bag.d.ts +3 -0
- package/dist/web/shared/codecs/eid.d.ts +10 -0
- package/dist/web/shared/codecs/messageHead.d.ts +16 -0
- package/dist/web/shared/codecs/notifItem.d.ts +7 -0
- package/dist/web/shared/codecs/peekItem.d.ts +6 -0
- package/dist/web/shared/codecs/peekItemHead.d.ts +7 -0
- package/dist/web/shared/codecs/pullItem.d.ts +6 -0
- package/dist/web/shared/codecs/pushItem.d.ts +11 -0
- package/dist/web/shared/codecs/respHead.d.ts +10 -0
- package/dist/web/shared/codecs/usageQuota.d.ts +6 -0
- package/dist/web/shared/consts.d.ts +50 -0
- package/dist/web/shared/crypto/noble.d.ts +11 -0
- package/dist/web/shared/enclave.d.ts +8 -0
- package/dist/web/shared/endpoint.d.ts +23 -0
- package/dist/web/shared/events.d.ts +8 -0
- package/dist/web/shared/http/listener.d.ts +11 -0
- package/dist/web/shared/http/server.d.ts +14 -0
- package/dist/web/shared/http.d.ts +82 -0
- package/dist/web/shared/message.d.ts +22 -0
- package/dist/web/shared/singleton.d.ts +15 -0
- package/dist/web/shared/sync.d.ts +9 -0
- package/dist/web/shared/types.d.ts +163 -0
- package/dist/web/shared/valstat.d.ts +6 -0
- package/package.json +27 -11
- package/dist/crypto.d.ts +0 -3
- package/dist/exim.d.ts +0 -0
- package/dist/index.mjs +0 -11295
- package/dist/lib.d.ts +0 -2
- /package/dist/{shared → cli/shared}/api/peek.d.ts +0 -0
- /package/dist/{shared → cli/shared}/api/pull.d.ts +0 -0
- /package/dist/{shared → cli/shared}/api/push.d.ts +0 -0
- /package/dist/{shared → cli/shared}/api/user.d.ts +0 -0
- /package/dist/{shared → cli/shared}/auth.d.ts +0 -0
- /package/dist/{shared → cli/shared}/bag.d.ts +0 -0
- /package/dist/{shared → cli/shared}/binary.d.ts +0 -0
- /package/dist/{shared → cli/shared}/client.d.ts +0 -0
- /package/dist/{shared → cli/shared}/clock.d.ts +0 -0
- /package/dist/{shared → cli/shared}/codec.d.ts +0 -0
- /package/dist/{shared → cli/shared}/codecs/authTimestamp.d.ts +0 -0
- /package/dist/{shared → cli/shared}/codecs/bag.d.ts +0 -0
- /package/dist/{shared → cli/shared}/codecs/eid.d.ts +0 -0
- /package/dist/{shared → cli/shared}/codecs/messageHead.d.ts +0 -0
- /package/dist/{shared → cli/shared}/codecs/notifItem.d.ts +0 -0
- /package/dist/{shared → cli/shared}/codecs/peekItem.d.ts +0 -0
- /package/dist/{shared → cli/shared}/codecs/peekItemHead.d.ts +0 -0
- /package/dist/{shared → cli/shared}/codecs/pullItem.d.ts +0 -0
- /package/dist/{shared → cli/shared}/codecs/pushItem.d.ts +0 -0
- /package/dist/{shared → cli/shared}/codecs/respHead.d.ts +0 -0
- /package/dist/{shared → cli/shared}/codecs/usageQuota.d.ts +0 -0
- /package/dist/{shared → cli/shared}/consts.d.ts +0 -0
- /package/dist/{shared → cli/shared}/enclave.d.ts +0 -0
- /package/dist/{shared → cli/shared}/endpoint.d.ts +0 -0
- /package/dist/{shared → cli/shared}/events.d.ts +0 -0
- /package/dist/{shared → cli/shared}/http/listener.d.ts +0 -0
- /package/dist/{shared → cli/shared}/http/server.d.ts +0 -0
- /package/dist/{shared → cli/shared}/http.d.ts +0 -0
- /package/dist/{shared → cli/shared}/message.d.ts +0 -0
- /package/dist/{shared → cli/shared}/singleton.d.ts +0 -0
- /package/dist/{shared → cli/shared}/sync.d.ts +0 -0
- /package/dist/{shared → cli/shared}/valstat.d.ts +0 -0
- /package/dist/{entdb → web/entdb}/entdb.d.ts +0 -0
- /package/dist/{entdb → web/entdb}/idb.d.ts +0 -0
- /package/dist/{entdb → web/entdb}/memory.d.ts +0 -0
- /package/dist/{events.d.ts → web/events.d.ts} +0 -0
- /package/dist/{react → web/react}/useClient.d.ts +0 -0
- /package/dist/{react → web/react}/useEntities.d.ts +0 -0
- /package/dist/{react → web/react}/useStateWatcher.d.ts +0 -0
- /package/dist/{shared → web/shared}/codecs/file.d.ts +0 -0
- /package/dist/{shared → web/shared}/codecs/fileHead.d.ts +0 -0
- /package/dist/{shared → web/shared}/codecs/fileIndexItem.d.ts +0 -0
- /package/dist/{shared → web/shared}/exim.d.ts +0 -0
- /package/dist/{shared → web/shared}/lpc/listener.d.ts +0 -0
- /package/dist/{shared → web/shared}/lpc/pusher.d.ts +0 -0
- /package/dist/{shared → web/shared}/lpc/server.d.ts +0 -0
- /package/dist/{shared → web/shared}/storage/memory.d.ts +0 -0
- /package/dist/{state.d.ts → web/state.d.ts} +0 -0
- /package/dist/{stores → web/stores}/idb/dnlds.d.ts +0 -0
- /package/dist/{stores → web/stores}/idb/hosts.d.ts +0 -0
- /package/dist/{stores → web/stores}/idb/msgs.d.ts +0 -0
- /package/dist/{stores → web/stores}/idb/seed.d.ts +0 -0
- /package/dist/{stores → web/stores}/idb/store.d.ts +0 -0
- /package/dist/{stores → web/stores}/idb/uplds.d.ts +0 -0
- /package/dist/{stores → web/stores}/memory/dnlds.d.ts +0 -0
- /package/dist/{stores → web/stores}/memory/hosts.d.ts +0 -0
- /package/dist/{stores → web/stores}/memory/msgs.d.ts +0 -0
- /package/dist/{stores → web/stores}/memory/seed.d.ts +0 -0
- /package/dist/{stores → web/stores}/memory/store.d.ts +0 -0
- /package/dist/{stores → web/stores}/memory/uplds.d.ts +0 -0
- /package/dist/{sync.d.ts → web/sync.d.ts} +0 -0
- /package/dist/{types.d.ts → web/types.d.ts} +0 -0
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { IClock } from "./clock.ts";
|
|
2
|
+
import { Decoder, Encoder } from "./codec.ts";
|
|
3
|
+
import { IAuthTimestamp } from "./codecs/authTimestamp.ts";
|
|
4
|
+
import type { IBagPeekItem } from "./codecs/peekItem.ts";
|
|
5
|
+
import { IUsageQuota } from "./codecs/usageQuota.ts";
|
|
6
|
+
import { APICallName, Status } from "./consts.ts";
|
|
7
|
+
import { ValStat } from "./valstat.ts";
|
|
8
|
+
export type GroupID = string;
|
|
9
|
+
declare const entityIDSymbol: unique symbol;
|
|
10
|
+
export type EntityID = Uint8Array & {
|
|
11
|
+
readonly [entityIDSymbol]: true;
|
|
12
|
+
};
|
|
13
|
+
export type SerializedContent = Uint8Array;
|
|
14
|
+
export interface IMsgEntBody<T = unknown> {
|
|
15
|
+
gid?: GroupID;
|
|
16
|
+
pid?: EntityID;
|
|
17
|
+
type: string;
|
|
18
|
+
body?: T;
|
|
19
|
+
}
|
|
20
|
+
export interface IMessageHead {
|
|
21
|
+
eid: EntityID;
|
|
22
|
+
off: number;
|
|
23
|
+
ctr: number;
|
|
24
|
+
len: number;
|
|
25
|
+
hsh?: Uint8Array;
|
|
26
|
+
}
|
|
27
|
+
export interface IMessage extends IMessageHead {
|
|
28
|
+
bod?: SerializedContent;
|
|
29
|
+
}
|
|
30
|
+
export interface IMessageWithHash extends IMessage {
|
|
31
|
+
headHash: Hash;
|
|
32
|
+
}
|
|
33
|
+
export interface IDeleteOp extends Omit<IMessageHead, "len" | "hsh" | "bod"> {
|
|
34
|
+
}
|
|
35
|
+
export interface IMutateOp<T = unknown> extends IDeleteOp, Omit<IMsgEntBody<T>, "body"> {
|
|
36
|
+
body: T;
|
|
37
|
+
}
|
|
38
|
+
export type IOp = IDeleteOp | IMutateOp;
|
|
39
|
+
export declare function isDeleteOp(op: IOp): op is IDeleteOp;
|
|
40
|
+
export declare function isMutateOp(op: IOp): op is IMutateOp;
|
|
41
|
+
export interface IInsertParams<T> extends IMsgEntBody<T> {
|
|
42
|
+
id?: Uint8Array;
|
|
43
|
+
}
|
|
44
|
+
export interface IUpsertParams<T> extends IMsgEntBody<T> {
|
|
45
|
+
eid?: EntityID;
|
|
46
|
+
}
|
|
47
|
+
export interface IStorage {
|
|
48
|
+
addUser: (pubKey: PublicKey) => Promise<ValStat<void>>;
|
|
49
|
+
hasUser: (pubKey: PublicKey) => Promise<ValStat<boolean>>;
|
|
50
|
+
subMeta: (pubKey: PublicKey) => Promise<ValStat<ISubscriptionMetadata>>;
|
|
51
|
+
setBag: (pubKey: PublicKey, bag: IBag) => Promise<ValStat<number>>;
|
|
52
|
+
getBody: (pubKey: PublicKey, seq: number) => Promise<ValStat<Uint8Array | undefined>>;
|
|
53
|
+
listHeads: (pubKey: PublicKey, minSeq: number) => Promise<ValStat<IBagPeekItem[]>>;
|
|
54
|
+
}
|
|
55
|
+
export interface KeyPair {
|
|
56
|
+
keyType: "ed25519";
|
|
57
|
+
privateKey: PrivateKey;
|
|
58
|
+
publicKey: PublicKey;
|
|
59
|
+
}
|
|
60
|
+
declare const masterSeedSymbol: unique symbol;
|
|
61
|
+
declare const derivationSeedSymbol: unique symbol;
|
|
62
|
+
declare const publicKeySymbol: unique symbol;
|
|
63
|
+
declare const privateKeySymbol: unique symbol;
|
|
64
|
+
declare const hostSpecificKeyPairSymbol: unique symbol;
|
|
65
|
+
declare const hashSymbol: unique symbol;
|
|
66
|
+
export type MasterSeed = Uint8Array & {
|
|
67
|
+
readonly [masterSeedSymbol]: true;
|
|
68
|
+
};
|
|
69
|
+
export type DerivationSeed = Uint8Array & {
|
|
70
|
+
readonly [derivationSeedSymbol]: true;
|
|
71
|
+
};
|
|
72
|
+
export type PublicKey = Uint8Array & {
|
|
73
|
+
readonly [publicKeySymbol]: true;
|
|
74
|
+
};
|
|
75
|
+
export type PrivateKey = Uint8Array & {
|
|
76
|
+
readonly [privateKeySymbol]: true;
|
|
77
|
+
};
|
|
78
|
+
export type HostSpecificKeyPair = KeyPair & {
|
|
79
|
+
readonly [hostSpecificKeyPairSymbol]: true;
|
|
80
|
+
};
|
|
81
|
+
export type Hash = Uint8Array & {
|
|
82
|
+
readonly [hashSymbol]: true;
|
|
83
|
+
};
|
|
84
|
+
export interface IHostCrypto {
|
|
85
|
+
checkSigEd25519: (sig: Uint8Array, message: Uint8Array | string, pubKey: PublicKey) => Promise<boolean>;
|
|
86
|
+
}
|
|
87
|
+
export interface ICrypto extends IHostCrypto {
|
|
88
|
+
genRandomBytes: (bytes: number) => Promise<Uint8Array>;
|
|
89
|
+
gen256BitSecureRandomSeed: () => Promise<Uint8Array>;
|
|
90
|
+
encryptXSalsa20Poly1305Combined: (plaintext: Uint8Array, key: Uint8Array) => Promise<Uint8Array>;
|
|
91
|
+
decryptXSalsa20Poly1305Combined: (headerAndCipher: Uint8Array, key: Uint8Array) => Promise<Uint8Array>;
|
|
92
|
+
deriveEd25519KeyPair: (derivationSeed: DerivationSeed) => Promise<KeyPair>;
|
|
93
|
+
signEd25519: (message: Uint8Array | string, secKey: PrivateKey) => Promise<Uint8Array>;
|
|
94
|
+
blake3: (data: Uint8Array) => Promise<Hash>;
|
|
95
|
+
}
|
|
96
|
+
export interface IMsgpackCodec {
|
|
97
|
+
encode: (source: unknown) => Uint8Array;
|
|
98
|
+
decode: (packed: ArrayBuffer | Uint8Array) => unknown;
|
|
99
|
+
decodeAsync: (stream: ReadableStream<Uint8Array>) => Promise<unknown>;
|
|
100
|
+
}
|
|
101
|
+
export interface IProtoHost {
|
|
102
|
+
storage: IStorage;
|
|
103
|
+
crypto: IHostCrypto;
|
|
104
|
+
notifier: IPushNotifier;
|
|
105
|
+
clock: IClock;
|
|
106
|
+
}
|
|
107
|
+
export type PushReceiver = (data: Uint8Array) => void;
|
|
108
|
+
export interface IPushOpenResponse {
|
|
109
|
+
send: (data: Uint8Array) => Status;
|
|
110
|
+
shut: () => Status;
|
|
111
|
+
status: Status;
|
|
112
|
+
}
|
|
113
|
+
export interface IPushNotifier {
|
|
114
|
+
open(authTS: IAuthTimestamp, recv: PushReceiver, crypto: IHostCrypto, clock: IClock): Promise<IPushOpenResponse>;
|
|
115
|
+
push(pubKey: PublicKey, data: Uint8Array): void;
|
|
116
|
+
}
|
|
117
|
+
export interface IPushListener {
|
|
118
|
+
connect(authTS: IAuthTimestamp, recv: PushReceiver, onDisconnect: () => void): Promise<Status>;
|
|
119
|
+
connected(): boolean;
|
|
120
|
+
disconnect(): void;
|
|
121
|
+
}
|
|
122
|
+
export interface IBagHeader {
|
|
123
|
+
sig: Uint8Array;
|
|
124
|
+
kdm: Uint8Array;
|
|
125
|
+
}
|
|
126
|
+
export interface IBag extends IBagHeader {
|
|
127
|
+
headCph: Uint8Array;
|
|
128
|
+
bodyCph: Uint8Array;
|
|
129
|
+
}
|
|
130
|
+
export type EncodedBag = Uint8Array;
|
|
131
|
+
export type HostHandle = URL | IProtoHost;
|
|
132
|
+
export interface IHostConnectionInfo<Handle extends HostHandle> {
|
|
133
|
+
handle: Handle;
|
|
134
|
+
label: string;
|
|
135
|
+
idx?: number;
|
|
136
|
+
}
|
|
137
|
+
export interface ISubscriptionMetadata {
|
|
138
|
+
term: number;
|
|
139
|
+
elapsed: number;
|
|
140
|
+
stat: IUsageQuota;
|
|
141
|
+
dyn: IUsageQuota;
|
|
142
|
+
}
|
|
143
|
+
export declare const nullSubMeta: ISubscriptionMetadata;
|
|
144
|
+
export interface IHostMetadata {
|
|
145
|
+
subscription: ISubscriptionMetadata;
|
|
146
|
+
clockOffset: number;
|
|
147
|
+
}
|
|
148
|
+
export interface ITransport {
|
|
149
|
+
call: (name: APICallName, enc: Encoder) => Promise<ValStat<Decoder>>;
|
|
150
|
+
listener: IPushListener;
|
|
151
|
+
}
|
|
152
|
+
export interface IStateManager {
|
|
153
|
+
apply: (msgs: IMessage[]) => Promise<Status[]>;
|
|
154
|
+
on: (type: string, listener: () => void) => void;
|
|
155
|
+
off: (type: string, listener: () => void) => void;
|
|
156
|
+
}
|
|
157
|
+
export interface IUpsertMessage extends IMessage {
|
|
158
|
+
bod: SerializedContent;
|
|
159
|
+
}
|
|
160
|
+
export interface IDeleteMessage extends Omit<IMessage, "bod"> {
|
|
161
|
+
len: 0;
|
|
162
|
+
}
|
|
163
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Status } from "./consts.ts";
|
|
2
|
+
export type StatusOK = Status.Success;
|
|
3
|
+
export type StatusNOK = Exclude<Status, Status.Success>;
|
|
4
|
+
export type ValStat<T> = [T, StatusOK] | [undefined, StatusNOK];
|
|
5
|
+
export declare function ok<T>(val: T): ValStat<T>;
|
|
6
|
+
export declare function err<T>(stat: StatusNOK): ValStat<T>;
|
package/package.json
CHANGED
|
@@ -1,19 +1,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@interncom/diplomatic",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0-rc1",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"description": "Secure sync layer",
|
|
6
|
-
"main": "dist/index.mjs",
|
|
7
|
-
"types": "dist/index.d.ts",
|
|
5
|
+
"description": "Secure sync layer and CLI utilities for DIPLOMATIC",
|
|
8
6
|
"files": [
|
|
9
7
|
"dist"
|
|
10
8
|
],
|
|
9
|
+
"bin": {
|
|
10
|
+
"diplomatic-host": "dist/cli/bin/host.js"
|
|
11
|
+
},
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"browser": "./dist/web/index.mjs",
|
|
15
|
+
"node": "./dist/cli/index.mjs",
|
|
16
|
+
"types": "./dist/web/index.d.ts"
|
|
17
|
+
},
|
|
18
|
+
"./web": {
|
|
19
|
+
"import": "./dist/web/index.mjs",
|
|
20
|
+
"types": "./dist/web/index.d.ts"
|
|
21
|
+
},
|
|
22
|
+
"./cli": {
|
|
23
|
+
"import": "./dist/cli/index.mjs",
|
|
24
|
+
"types": "./dist/cli/index.d.ts"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
11
27
|
"scripts": {
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"
|
|
28
|
+
"build": "bun run build-web.mjs && bun run build-cli.mjs",
|
|
29
|
+
"check": "node check.mjs",
|
|
30
|
+
"clean": "rm -rf dist",
|
|
31
|
+
"tsc": "tsc --project ../web/tsconfig.json",
|
|
32
|
+
"test": "npm test --workspace=web && deno test --allow-net --allow-ffi --allow-env ../deno/"
|
|
17
33
|
},
|
|
18
34
|
"author": "The Internet Committee",
|
|
19
35
|
"license": "ISC",
|
|
@@ -21,6 +37,7 @@
|
|
|
21
37
|
"access": "public"
|
|
22
38
|
},
|
|
23
39
|
"devDependencies": {
|
|
40
|
+
"@types/bun": "latest",
|
|
24
41
|
"@types/file-saver": "^2.0.7",
|
|
25
42
|
"@types/node": "^20.14.11",
|
|
26
43
|
"@types/react": "^19.1.0",
|
|
@@ -36,7 +53,6 @@
|
|
|
36
53
|
"dependencies": {
|
|
37
54
|
"@msgpack/msgpack": "3.1.3",
|
|
38
55
|
"@noble/hashes": "1.8.0",
|
|
39
|
-
"file-saver": "2.0.5"
|
|
40
|
-
"libsodium.js": "git+ssh://github.com/interncom/libsodium.js#e4e7647"
|
|
56
|
+
"file-saver": "2.0.5"
|
|
41
57
|
}
|
|
42
58
|
}
|
package/dist/crypto.d.ts
DELETED
package/dist/exim.d.ts
DELETED
|
File without changes
|