@interncom/diplomatic 0.0.74 → 0.1.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 +12 -6
- package/dist/client.d.ts +43 -56
- package/dist/entdb/entdb.d.ts +36 -0
- package/dist/entdb/idb.d.ts +27 -0
- package/dist/entdb/memory.d.ts +30 -0
- package/dist/events.d.ts +18 -0
- package/dist/exim.d.ts +0 -0
- package/dist/index.d.ts +23 -14
- package/dist/index.mjs +6210 -6767
- package/dist/lib.d.ts +2 -0
- package/dist/react/useClient.d.ts +5 -4
- package/dist/react/useEntities.d.ts +0 -0
- package/dist/react/useStateWatcher.d.ts +3 -3
- package/dist/shared/api/peek.d.ts +3 -0
- package/dist/shared/api/pull.d.ts +3 -0
- package/dist/shared/api/push.d.ts +4 -0
- package/dist/shared/api/user.d.ts +2 -0
- package/dist/shared/auth.d.ts +8 -0
- package/dist/shared/bag.d.ts +16 -0
- package/dist/shared/binary.d.ts +8 -0
- package/dist/shared/client.d.ts +20 -9
- package/dist/shared/clock.d.ts +13 -0
- package/dist/shared/codec.d.ts +43 -0
- package/dist/shared/codecs/authTimestamp.d.ts +8 -0
- package/dist/shared/codecs/bag.d.ts +3 -0
- package/dist/shared/codecs/eid.d.ts +10 -0
- package/dist/shared/codecs/file.d.ts +8 -0
- package/dist/shared/codecs/fileHead.d.ts +10 -0
- package/dist/shared/codecs/fileIndexItem.d.ts +8 -0
- package/dist/shared/codecs/messageHead.d.ts +16 -0
- package/dist/shared/codecs/notifItem.d.ts +7 -0
- package/dist/shared/codecs/peekItem.d.ts +6 -0
- package/dist/shared/codecs/peekItemHead.d.ts +7 -0
- package/dist/shared/codecs/pullItem.d.ts +6 -0
- package/dist/shared/codecs/pushItem.d.ts +11 -0
- package/dist/shared/codecs/respHead.d.ts +10 -0
- package/dist/shared/codecs/usageQuota.d.ts +6 -0
- package/dist/shared/consts.d.ts +50 -0
- package/dist/shared/crypto/libsodium.d.ts +5 -5
- package/dist/shared/enclave.d.ts +8 -0
- package/dist/shared/endpoint.d.ts +23 -0
- package/dist/shared/exim.d.ts +12 -0
- package/dist/shared/http/listener.d.ts +11 -0
- package/dist/shared/http/server.d.ts +11 -0
- package/dist/shared/http.d.ts +81 -0
- package/dist/shared/lpc/listener.d.ts +16 -0
- package/dist/shared/lpc/pusher.d.ts +9 -0
- package/dist/shared/lpc/server.d.ts +19 -0
- package/dist/shared/message.d.ts +30 -0
- package/dist/shared/storage/memory.d.ts +10 -0
- package/dist/shared/types.d.ts +127 -49
- package/dist/shared/valstat.d.ts +6 -0
- package/dist/state.d.ts +12 -17
- package/dist/stores/idb/dnlds.d.ts +10 -0
- package/dist/stores/idb/hosts.d.ts +15 -0
- package/dist/stores/idb/msgs.d.ts +19 -0
- package/dist/stores/idb/seed.d.ts +11 -0
- package/dist/stores/idb/store.d.ts +23 -0
- package/dist/stores/idb/uplds.d.ts +11 -0
- package/dist/stores/memory/dnlds.d.ts +9 -0
- package/dist/stores/memory/hosts.d.ts +13 -0
- package/dist/stores/memory/msgs.d.ts +19 -0
- package/dist/stores/memory/seed.d.ts +9 -0
- package/dist/stores/memory/store.d.ts +16 -0
- package/dist/stores/memory/uplds.d.ts +10 -0
- package/dist/sync.d.ts +32 -2
- package/dist/types.d.ts +113 -29
- package/package.json +9 -6
- package/dist/api.d.ts +0 -3
- package/dist/entityDB.d.ts +0 -34
- package/dist/eventEmitter.d.ts +0 -8
- package/dist/idbStore.d.ts +0 -38
- package/dist/localStorageStore.d.ts +0 -36
- package/dist/memoryStore.d.ts +0 -40
- package/dist/queue.d.ts +0 -10
- package/dist/react/initSeedView.d.ts +0 -7
- package/dist/react/statusBar.d.ts +0 -7
- package/dist/shared/lib.d.ts +0 -2
- package/dist/shared/ops.d.ts +0 -4
- package/dist/shared/server.d.ts +0 -12
- package/dist/typedEventEmitter.d.ts +0 -8
- package/dist/useClient.d.ts +0 -4
package/dist/lib.d.ts
ADDED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import type { SyncClient } from "../client";
|
|
2
|
+
import { HostHandle } from "../shared/types";
|
|
1
3
|
import type { IDiplomaticClientState, IDiplomaticClientXferState } from "../types";
|
|
2
|
-
|
|
3
|
-
export declare function
|
|
4
|
-
export declare function
|
|
5
|
-
export declare function useSyncOnResume(client: DiplomaticClient): void;
|
|
4
|
+
export declare function useClientState<Handle extends HostHandle>(client: SyncClient<Handle>): IDiplomaticClientState | undefined;
|
|
5
|
+
export declare function useClientXferState<Handle extends HostHandle>(client: SyncClient<Handle>): IDiplomaticClientXferState | undefined;
|
|
6
|
+
export declare function useSyncOnResume<Handle extends HostHandle>(client: SyncClient<Handle>): void;
|
|
File without changes
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
export default function useStateWatcher<T>(mgr:
|
|
3
|
-
export declare function useStateWatcherSuspense<T>(mgr:
|
|
1
|
+
import { IStateManager } from "../types";
|
|
2
|
+
export default function useStateWatcher<T>(mgr: IStateManager, opType: string, callback: () => Promise<T>): T | undefined;
|
|
3
|
+
export declare function useStateWatcherSuspense<T>(mgr: IStateManager, opType: string, callback: () => Promise<T>): T;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { IClock } from "./clock.ts";
|
|
2
|
+
import { type IAuthTimestamp } from "./codecs/authTimestamp.ts";
|
|
3
|
+
import { Status } from "./consts.ts";
|
|
4
|
+
import type { ICrypto, IHostCrypto, KeyPair } from "./types.ts";
|
|
5
|
+
import { ValStat } from "./valstat.ts";
|
|
6
|
+
export type EncodedAuthTimestamp = Uint8Array;
|
|
7
|
+
export declare function makeAuthTimestamp(keys: KeyPair, ts: Date, crypto: ICrypto): Promise<ValStat<IAuthTimestamp>>;
|
|
8
|
+
export declare function validateAuthTimestamp(authTS: IAuthTimestamp, crypto: IHostCrypto, clock: IClock): Promise<Status>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { IMessageHead } from "./codecs/messageHead.ts";
|
|
2
|
+
import { Enclave } from "./enclave.ts";
|
|
3
|
+
import { EncodedMessage } from "./message.ts";
|
|
4
|
+
import { type ValStat } from "./valstat.ts";
|
|
5
|
+
import type { Hash, HostSpecificKeyPair, IBag, ICrypto, IHostCrypto, IMessage, IMessageWithHash, PublicKey } from "./types.ts";
|
|
6
|
+
export declare function bagSigValid(bag: IBag, pubKey: PublicKey, crypto: IHostCrypto): Promise<boolean>;
|
|
7
|
+
export declare function kdmFor(msgHeadEnc: Uint8Array, keys: HostSpecificKeyPair, crypto: ICrypto): Promise<Uint8Array>;
|
|
8
|
+
export declare function sealBag(msg: IMessage, keys: HostSpecificKeyPair, crypto: ICrypto, enclave: Enclave): Promise<ValStat<IBag>>;
|
|
9
|
+
interface IOpenBag {
|
|
10
|
+
msgHead: IMessageHead;
|
|
11
|
+
bod?: EncodedMessage;
|
|
12
|
+
headHash: Hash;
|
|
13
|
+
}
|
|
14
|
+
export declare function openBagBody(headEnc: Uint8Array, bodyCph: Uint8Array | undefined, key: Uint8Array, crypto: ICrypto): Promise<ValStat<IOpenBag>>;
|
|
15
|
+
export declare function openBag(bag: IBag, pubKey: PublicKey, crypto: ICrypto, enclave: Enclave): Promise<ValStat<IMessageWithHash>>;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare function btoh(bytes: Uint8Array): string;
|
|
2
|
+
export declare function htob(hex: string): Uint8Array;
|
|
3
|
+
export declare function bytesEqual(a: Uint8Array, b: Uint8Array): boolean;
|
|
4
|
+
export declare let btob64: (bytes: Uint8Array) => string;
|
|
5
|
+
export declare let b64tob: (b64: string) => Uint8Array;
|
|
6
|
+
export declare function concat(a: Uint8Array, b: Uint8Array): Uint8Array;
|
|
7
|
+
export declare function btob128(bytes: Uint8Array): string;
|
|
8
|
+
export declare function b128tob(str: string): Uint8Array;
|
package/dist/shared/client.d.ts
CHANGED
|
@@ -1,11 +1,22 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { IClock } from "./clock.ts";
|
|
2
|
+
import { Status } from "./consts.ts";
|
|
3
|
+
import { Enclave } from "./enclave.ts";
|
|
4
|
+
import type { HostHandle, HostSpecificKeyPair, IBag, ICrypto, IHostConnectionInfo, IHostMetadata, IMessage, ITransport, PushReceiver } from "./types.ts";
|
|
5
|
+
import { ValStat } from "./valstat.ts";
|
|
6
|
+
export default class DiplomaticClientAPI<Handle extends HostHandle> {
|
|
7
|
+
enclave: Enclave;
|
|
4
8
|
crypto: ICrypto;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
private host;
|
|
10
|
+
clock: IClock;
|
|
11
|
+
private transport;
|
|
12
|
+
private updateHostMeta;
|
|
13
|
+
constructor(enclave: Enclave, crypto: ICrypto, host: IHostConnectionInfo<Handle>, clock: IClock, transport: ITransport, updateHostMeta: (meta: IHostMetadata) => Promise<Status>);
|
|
14
|
+
private call;
|
|
15
|
+
keys: () => Promise<HostSpecificKeyPair>;
|
|
16
|
+
seal: (msg: IMessage) => Promise<ValStat<IBag>>;
|
|
17
|
+
register: () => Promise<ValStat<void>>;
|
|
18
|
+
peek: (lastSeq: number) => Promise<ValStat<import("./codecs/peekItem.ts").IBagPeekItem[]>>;
|
|
19
|
+
push: (bags: IBag[]) => Promise<ValStat<import("./codecs/pushItem.ts").IBagPushItem[]>>;
|
|
20
|
+
pull: (seqs: number[]) => Promise<ValStat<import("./codecs/pullItem.ts").IBagPullItem[]>>;
|
|
21
|
+
listen: (recv: PushReceiver) => Promise<Status>;
|
|
11
22
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface IClock {
|
|
2
|
+
now(): Date;
|
|
3
|
+
}
|
|
4
|
+
export declare class Clock implements IClock {
|
|
5
|
+
now(): Date;
|
|
6
|
+
}
|
|
7
|
+
export declare class MockClock implements IClock {
|
|
8
|
+
private _now;
|
|
9
|
+
constructor(_now: Date);
|
|
10
|
+
set(_now: Date): void;
|
|
11
|
+
now(): Date;
|
|
12
|
+
}
|
|
13
|
+
export declare function offset(timeSentClient: Date, timeRcvdHost: Date, timeSentHost: Date, timeRcvdClient: Date): number;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { ValStat } from "./valstat.ts";
|
|
2
|
+
import { Status } from "./consts.ts";
|
|
3
|
+
export declare function encodeVarInt(n: number | bigint): ValStat<Uint8Array>;
|
|
4
|
+
export declare function decodeVarInt(bytes: Uint8Array, offset?: number): ValStat<{
|
|
5
|
+
value: number | bigint;
|
|
6
|
+
bytesRead: number;
|
|
7
|
+
}>;
|
|
8
|
+
export declare class Decoder {
|
|
9
|
+
private data;
|
|
10
|
+
private pos;
|
|
11
|
+
constructor(data: Uint8Array);
|
|
12
|
+
static fromResponse(resp: Response): Promise<Decoder>;
|
|
13
|
+
readBigInt(): ValStat<bigint>;
|
|
14
|
+
readDate(): ValStat<Date>;
|
|
15
|
+
readVarInt(): ValStat<number>;
|
|
16
|
+
readVarString(): ValStat<string>;
|
|
17
|
+
readBytes(num: number): ValStat<Uint8Array>;
|
|
18
|
+
readVarBytes(): ValStat<Uint8Array>;
|
|
19
|
+
readStruct<T>(codec: ICodecStruct<T>): ValStat<T>;
|
|
20
|
+
readStructs<T>(codec: ICodecStruct<T>): ValStat<T[]>;
|
|
21
|
+
readBytesSeq(len: number): ValStat<Uint8Array[]>;
|
|
22
|
+
done(): boolean;
|
|
23
|
+
consumed(): number;
|
|
24
|
+
}
|
|
25
|
+
export declare class Encoder {
|
|
26
|
+
private parts;
|
|
27
|
+
writeBigInt(b: bigint): void;
|
|
28
|
+
writeDate(ts: Date): Status;
|
|
29
|
+
writeVarInt(n: number): Status;
|
|
30
|
+
writeVarString(s: string): Status;
|
|
31
|
+
prependBytes(bytes: Uint8Array): void;
|
|
32
|
+
writeBytes(bytes: Uint8Array): void;
|
|
33
|
+
writeVarBytes(bytes: Uint8Array): Status;
|
|
34
|
+
writeStruct<T>(codec: ICodecStruct<T>, str: T): Status;
|
|
35
|
+
writeStructs<T>(codec: ICodecStruct<T>, structs: Iterable<T>): Status;
|
|
36
|
+
writeBytesSeq(bytesSeq: Iterable<Uint8Array>): void;
|
|
37
|
+
result(): Uint8Array;
|
|
38
|
+
scan(): Generator<Uint8Array>;
|
|
39
|
+
}
|
|
40
|
+
export interface ICodecStruct<T> {
|
|
41
|
+
encode: (enc: Encoder, struct: T) => Status;
|
|
42
|
+
decode: (dec: Decoder) => ValStat<T>;
|
|
43
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ICodecStruct } from "../codec.ts";
|
|
2
|
+
import { ValStat } from "../valstat.ts";
|
|
3
|
+
import { EntityID } from "../types.ts";
|
|
4
|
+
export interface IEntityID {
|
|
5
|
+
id: Uint8Array;
|
|
6
|
+
ts: Date;
|
|
7
|
+
}
|
|
8
|
+
export declare const eidCodec: ICodecStruct<IEntityID>;
|
|
9
|
+
export declare function makeEID(eidObj: IEntityID): ValStat<EntityID>;
|
|
10
|
+
export declare function genSingletonEID(id: Uint8Array): Promise<ValStat<EntityID>>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ICodecStruct } from "../codec.ts";
|
|
2
|
+
import { EntityID } from "../types.ts";
|
|
3
|
+
export interface IMessageHead {
|
|
4
|
+
eid: EntityID;
|
|
5
|
+
off: number;
|
|
6
|
+
ctr: number;
|
|
7
|
+
len: number;
|
|
8
|
+
hsh?: Uint8Array;
|
|
9
|
+
}
|
|
10
|
+
export declare const messageHeadCodec: ICodecStruct<IMessageHead>;
|
|
11
|
+
export interface IMinimalMessageHead {
|
|
12
|
+
eid: EntityID;
|
|
13
|
+
off: number;
|
|
14
|
+
ctr: number;
|
|
15
|
+
}
|
|
16
|
+
export declare const minimalMessageHeadCodec: ICodecStruct<IMinimalMessageHead>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ICodecStruct } from "../codec.ts";
|
|
2
|
+
import { Status } from "../consts.ts";
|
|
3
|
+
export type IBagPushItem = {
|
|
4
|
+
idx: number;
|
|
5
|
+
status: Status.Success;
|
|
6
|
+
seq: number;
|
|
7
|
+
} | {
|
|
8
|
+
idx: number;
|
|
9
|
+
status: Exclude<Status, Status.Success>;
|
|
10
|
+
};
|
|
11
|
+
export declare const pushItemCodec: ICodecStruct<IBagPushItem>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ICodecStruct } from "../codec.ts";
|
|
2
|
+
import { Status } from "../consts.ts";
|
|
3
|
+
import { ISubscriptionMetadata } from "../types.ts";
|
|
4
|
+
export interface IRespHead {
|
|
5
|
+
status: Status;
|
|
6
|
+
timeRcvd: Date;
|
|
7
|
+
timeSent: Date;
|
|
8
|
+
subscription: ISubscriptionMetadata;
|
|
9
|
+
}
|
|
10
|
+
export declare const respHeadCodec: ICodecStruct<IRespHead>;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export declare const sigBytes = 64;
|
|
2
|
+
export declare const hashBytes = 32;
|
|
3
|
+
export declare const idxBytes = 8;
|
|
4
|
+
export declare const lenBytes = 8;
|
|
5
|
+
export declare const pubKeyBytes = 32;
|
|
6
|
+
export declare const kdmBytes = 8;
|
|
7
|
+
export declare const eidBytes = 16;
|
|
8
|
+
export declare const clkBytes = 8;
|
|
9
|
+
export declare const hshBytes = 32;
|
|
10
|
+
export declare const tsAuthSize: number;
|
|
11
|
+
export declare const bagHeaderSize: number;
|
|
12
|
+
export declare const responseItemSize = 33;
|
|
13
|
+
export declare const clockToleranceMs = 30000;
|
|
14
|
+
export declare const notifInlineBodyBytesThreshold = 512;
|
|
15
|
+
export declare enum Status {
|
|
16
|
+
Success = 0,
|
|
17
|
+
InvalidSignature = 3,
|
|
18
|
+
ClockOutOfSync = 4,
|
|
19
|
+
UserNotRegistered = 5,
|
|
20
|
+
ServerMisconfigured = 6,
|
|
21
|
+
MissingBody = 7,
|
|
22
|
+
ExtraBodyContent = 8,
|
|
23
|
+
MissingParam = 9,
|
|
24
|
+
InvalidParam = 10,
|
|
25
|
+
InvalidRequest = 11,
|
|
26
|
+
InternalError = 12,
|
|
27
|
+
NotFound = 13,
|
|
28
|
+
InvalidMessage = 14,
|
|
29
|
+
NoChange = 15,
|
|
30
|
+
DatabaseClosed = 16,
|
|
31
|
+
StorageError = 17,
|
|
32
|
+
DatabaseError = 18,
|
|
33
|
+
HashMismatch = 19,
|
|
34
|
+
DecryptionError = 20,
|
|
35
|
+
NotImplemented = 21,
|
|
36
|
+
MissingSeed = 22,
|
|
37
|
+
OutOfBounds = 23,
|
|
38
|
+
HostError = 24,
|
|
39
|
+
CommunicationError = 25,
|
|
40
|
+
VarLimitExceeded = 26,
|
|
41
|
+
InvalidResponse = 27,
|
|
42
|
+
ConnectionClosed = 28
|
|
43
|
+
}
|
|
44
|
+
export declare enum APICallName {
|
|
45
|
+
User = 0,
|
|
46
|
+
Peek = 1,
|
|
47
|
+
Push = 2,
|
|
48
|
+
Pull = 3
|
|
49
|
+
}
|
|
50
|
+
export declare const notifierTSAuthURLParam = "t";
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import type { ICrypto, KeyPair } from "../types.ts";
|
|
1
|
+
import type { DerivationSeed, Hash, ICrypto, KeyPair } from "../types.ts";
|
|
2
2
|
type Libsodium = any;
|
|
3
3
|
export declare class LibsodiumCrypto implements ICrypto {
|
|
4
4
|
sodium: Libsodium;
|
|
5
5
|
constructor(sodium: Libsodium);
|
|
6
|
-
|
|
6
|
+
genRandomBytes(bytes: number): Promise<Uint8Array>;
|
|
7
7
|
gen256BitSecureRandomSeed(): Promise<Uint8Array>;
|
|
8
|
-
deriveXSalsa20Poly1305Key(seed: Uint8Array): Promise<Uint8Array>;
|
|
8
|
+
deriveXSalsa20Poly1305Key(seed: Uint8Array, derivationIndex?: number): Promise<Uint8Array>;
|
|
9
9
|
encryptXSalsa20Poly1305Combined(data: Uint8Array, key: Uint8Array): Promise<Uint8Array>;
|
|
10
10
|
decryptXSalsa20Poly1305Combined(data: Uint8Array, key: Uint8Array): Promise<Uint8Array>;
|
|
11
|
-
deriveEd25519KeyPair(
|
|
11
|
+
deriveEd25519KeyPair(derivationSeed: DerivationSeed): Promise<KeyPair>;
|
|
12
12
|
signEd25519(message: Uint8Array | string, secKey: Uint8Array): Promise<Uint8Array>;
|
|
13
13
|
checkSigEd25519(sig: Uint8Array, message: Uint8Array | string, pubKey: Uint8Array): Promise<boolean>;
|
|
14
|
-
|
|
14
|
+
blake3(data: Uint8Array): Promise<Hash>;
|
|
15
15
|
}
|
|
16
16
|
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { DerivationSeed, ICrypto, MasterSeed } from "./types.ts";
|
|
2
|
+
export declare class Enclave {
|
|
3
|
+
private seed;
|
|
4
|
+
private crypto;
|
|
5
|
+
constructor(seed: MasterSeed, crypto: ICrypto);
|
|
6
|
+
deriveFromKDM(kdm: Uint8Array): Promise<DerivationSeed>;
|
|
7
|
+
derive(keyPath: string, idx?: number): Promise<DerivationSeed>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { IClock } from "./clock.ts";
|
|
2
|
+
import { Decoder, Encoder } from "./codec.ts";
|
|
3
|
+
import { IAuthTimestamp } from "./codecs/authTimestamp.ts";
|
|
4
|
+
import { Status } from "./consts.ts";
|
|
5
|
+
import { Enclave } from "./enclave.ts";
|
|
6
|
+
import { HostSpecificKeyPair, ICrypto, IProtoHost } from "./types.ts";
|
|
7
|
+
import { ValStat } from "./valstat.ts";
|
|
8
|
+
interface IProtoClient {
|
|
9
|
+
crypto: ICrypto;
|
|
10
|
+
enclave: Enclave;
|
|
11
|
+
clock: IClock;
|
|
12
|
+
}
|
|
13
|
+
export interface IAuthenticatedEndpoint<ReqItem, Resp> {
|
|
14
|
+
encodeReq(client: IProtoClient, keys: HostSpecificKeyPair, authTS: IAuthTimestamp, body: Iterable<ReqItem>, reqEnc: Encoder): Promise<Status>;
|
|
15
|
+
handleReq(host: IProtoHost, reqDec: Decoder, respEnc: Encoder): Promise<Status>;
|
|
16
|
+
decodeResp(respDec: Decoder): ValStat<Resp>;
|
|
17
|
+
}
|
|
18
|
+
export interface IAuthData {
|
|
19
|
+
keys: HostSpecificKeyPair;
|
|
20
|
+
authTS: IAuthTimestamp;
|
|
21
|
+
}
|
|
22
|
+
export declare function hostKeys(host: IProtoClient, keyPath: string, idx: number): Promise<HostSpecificKeyPair>;
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Enclave } from "./enclave.ts";
|
|
2
|
+
import { ICrypto, IMessageHead } from "./types.ts";
|
|
3
|
+
import { ValStat } from "./valstat.ts";
|
|
4
|
+
export declare const defaultFileExtension = "dpl";
|
|
5
|
+
export declare function encodeFile(keyLbl: string, keyIdx: number, msgs: Iterable<{
|
|
6
|
+
head: IMessageHead;
|
|
7
|
+
body?: Uint8Array;
|
|
8
|
+
}>, crypto: ICrypto, enclave: Enclave): Promise<ValStat<Uint8Array>>;
|
|
9
|
+
export declare function decodeFile(file: Uint8Array, crypto: ICrypto, enclave: Enclave): Promise<ValStat<{
|
|
10
|
+
head: IMessageHead;
|
|
11
|
+
body?: Uint8Array;
|
|
12
|
+
}[]>>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { IAuthTimestamp } from "../codecs/authTimestamp.ts";
|
|
2
|
+
import { Status } from "../consts.ts";
|
|
3
|
+
import { IPushListener, PushReceiver } from "../types.ts";
|
|
4
|
+
export declare class WebsocketListener implements IPushListener {
|
|
5
|
+
private url;
|
|
6
|
+
private websocket?;
|
|
7
|
+
constructor(url: URL);
|
|
8
|
+
connected(): boolean;
|
|
9
|
+
connect(authTS: IAuthTimestamp, recv: PushReceiver, onDisconnect: () => void): Promise<Status>;
|
|
10
|
+
disconnect(): void;
|
|
11
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { IClock } from "../clock.ts";
|
|
2
|
+
import { type IHostCrypto, type IProtoHost, type IStorage, type IWebSocketPushNotifier } from "../types.ts";
|
|
3
|
+
export declare class DiplomaticHTTPServer implements IProtoHost {
|
|
4
|
+
storage: IStorage;
|
|
5
|
+
crypto: IHostCrypto;
|
|
6
|
+
notifier: IWebSocketPushNotifier;
|
|
7
|
+
clock: IClock;
|
|
8
|
+
constructor(storage: IStorage, crypto: IHostCrypto, notifier: IWebSocketPushNotifier, clock: IClock);
|
|
9
|
+
corsHandler: (request: Request) => Promise<Response>;
|
|
10
|
+
handler: (request: Request) => Promise<Response>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { Decoder, Encoder } from "./codec.ts";
|
|
2
|
+
import { APICallName } from "./consts.ts";
|
|
3
|
+
import { IPushListener, ITransport } from "./types.ts";
|
|
4
|
+
import { IRespHead } from "./codecs/respHead.ts";
|
|
5
|
+
import { ValStat } from "./valstat.ts";
|
|
6
|
+
export declare const api: {
|
|
7
|
+
readonly user: {
|
|
8
|
+
readonly path: "/user";
|
|
9
|
+
readonly endpoint: import("./endpoint.ts").IAuthenticatedEndpoint<never, void>;
|
|
10
|
+
readonly name: APICallName.User;
|
|
11
|
+
};
|
|
12
|
+
readonly push: {
|
|
13
|
+
readonly path: "/push";
|
|
14
|
+
readonly endpoint: import("./endpoint.ts").IAuthenticatedEndpoint<import("./types.ts").IBag, import("./codecs/pushItem.ts").IBagPushItem[]>;
|
|
15
|
+
readonly name: APICallName.Push;
|
|
16
|
+
};
|
|
17
|
+
readonly peek: {
|
|
18
|
+
readonly path: "/peek";
|
|
19
|
+
readonly endpoint: import("./endpoint.ts").IAuthenticatedEndpoint<number, import("./codecs/peekItem.ts").IBagPeekItem[]>;
|
|
20
|
+
readonly name: APICallName.Peek;
|
|
21
|
+
};
|
|
22
|
+
readonly pull: {
|
|
23
|
+
readonly path: "/pull";
|
|
24
|
+
readonly endpoint: import("./endpoint.ts").IAuthenticatedEndpoint<number, import("./codecs/pullItem.ts").IBagPullItem[]>;
|
|
25
|
+
readonly name: APICallName.Pull;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
export declare const apiCalls: {
|
|
29
|
+
readonly 0: {
|
|
30
|
+
readonly path: "/user";
|
|
31
|
+
readonly endpoint: import("./endpoint.ts").IAuthenticatedEndpoint<never, void>;
|
|
32
|
+
readonly name: APICallName.User;
|
|
33
|
+
};
|
|
34
|
+
readonly 2: {
|
|
35
|
+
readonly path: "/push";
|
|
36
|
+
readonly endpoint: import("./endpoint.ts").IAuthenticatedEndpoint<import("./types.ts").IBag, import("./codecs/pushItem.ts").IBagPushItem[]>;
|
|
37
|
+
readonly name: APICallName.Push;
|
|
38
|
+
};
|
|
39
|
+
readonly 1: {
|
|
40
|
+
readonly path: "/peek";
|
|
41
|
+
readonly endpoint: import("./endpoint.ts").IAuthenticatedEndpoint<number, import("./codecs/peekItem.ts").IBagPeekItem[]>;
|
|
42
|
+
readonly name: APICallName.Peek;
|
|
43
|
+
};
|
|
44
|
+
readonly 3: {
|
|
45
|
+
readonly path: "/pull";
|
|
46
|
+
readonly endpoint: import("./endpoint.ts").IAuthenticatedEndpoint<number, import("./codecs/pullItem.ts").IBagPullItem[]>;
|
|
47
|
+
readonly name: APICallName.Pull;
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
export declare const callPaths: {
|
|
51
|
+
readonly "/user": {
|
|
52
|
+
readonly path: "/user";
|
|
53
|
+
readonly endpoint: import("./endpoint.ts").IAuthenticatedEndpoint<never, void>;
|
|
54
|
+
readonly name: APICallName.User;
|
|
55
|
+
};
|
|
56
|
+
readonly "/push": {
|
|
57
|
+
readonly path: "/push";
|
|
58
|
+
readonly endpoint: import("./endpoint.ts").IAuthenticatedEndpoint<import("./types.ts").IBag, import("./codecs/pushItem.ts").IBagPushItem[]>;
|
|
59
|
+
readonly name: APICallName.Push;
|
|
60
|
+
};
|
|
61
|
+
readonly "/peek": {
|
|
62
|
+
readonly path: "/peek";
|
|
63
|
+
readonly endpoint: import("./endpoint.ts").IAuthenticatedEndpoint<number, import("./codecs/peekItem.ts").IBagPeekItem[]>;
|
|
64
|
+
readonly name: APICallName.Peek;
|
|
65
|
+
};
|
|
66
|
+
readonly "/pull": {
|
|
67
|
+
readonly path: "/pull";
|
|
68
|
+
readonly endpoint: import("./endpoint.ts").IAuthenticatedEndpoint<number, import("./codecs/pullItem.ts").IBagPullItem[]>;
|
|
69
|
+
readonly name: APICallName.Pull;
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
export declare class HTTPTransport implements ITransport {
|
|
73
|
+
private url;
|
|
74
|
+
listener: IPushListener;
|
|
75
|
+
constructor(url: URL);
|
|
76
|
+
call(name: APICallName, enc: Encoder): Promise<ValStat<Decoder>>;
|
|
77
|
+
}
|
|
78
|
+
export declare function errResp(head: IRespHead): Response;
|
|
79
|
+
export declare function binResp(encoder: Encoder): Response;
|
|
80
|
+
export declare function cors(resp: Response): Response;
|
|
81
|
+
export declare function post(url: URL, enc: Encoder): Promise<ValStat<Decoder>>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { IAuthTimestamp } from "../codecs/authTimestamp.ts";
|
|
2
|
+
import { Status } from "../consts.ts";
|
|
3
|
+
import { IPushListener, IPushNotifier, PushReceiver } from "../types.ts";
|
|
4
|
+
import type { IHostCrypto } from "../types.ts";
|
|
5
|
+
import type { IClock } from "../clock.ts";
|
|
6
|
+
export declare class CallbackListener implements IPushListener {
|
|
7
|
+
private notifier;
|
|
8
|
+
private crypto;
|
|
9
|
+
private clock;
|
|
10
|
+
private _connected;
|
|
11
|
+
private _shut?;
|
|
12
|
+
constructor(notifier: IPushNotifier, crypto: IHostCrypto, clock: IClock);
|
|
13
|
+
connected(): boolean;
|
|
14
|
+
connect(authTS: IAuthTimestamp, recv: PushReceiver, _onDisconnect: () => void): Promise<Status>;
|
|
15
|
+
disconnect(): void;
|
|
16
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { IPushNotifier, IPushOpenResponse, PublicKey, PushReceiver } from "../types.ts";
|
|
2
|
+
import { IAuthTimestamp } from "../codecs/authTimestamp.ts";
|
|
3
|
+
import type { IHostCrypto } from "../types.ts";
|
|
4
|
+
import type { IClock } from "../clock.ts";
|
|
5
|
+
export declare class CallbackNotifier implements IPushNotifier {
|
|
6
|
+
private recvs;
|
|
7
|
+
open(authTS: IAuthTimestamp, recv: PushReceiver, crypto: IHostCrypto, clock: IClock): Promise<IPushOpenResponse>;
|
|
8
|
+
push(pubKey: PublicKey, data: Uint8Array): void;
|
|
9
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { IClock } from "../clock.ts";
|
|
2
|
+
import { Decoder, Encoder } from "../codec.ts";
|
|
3
|
+
import { APICallName, Status } from "../consts.ts";
|
|
4
|
+
import { type IHostCrypto, type IProtoHost, type IPushListener, type IPushNotifier, type IStorage, type ITransport } from "../types.ts";
|
|
5
|
+
import { ValStat } from "../valstat.ts";
|
|
6
|
+
export declare class DiplomaticLPCServer implements IProtoHost {
|
|
7
|
+
storage: IStorage;
|
|
8
|
+
crypto: IHostCrypto;
|
|
9
|
+
notifier: IPushNotifier;
|
|
10
|
+
clock: IClock;
|
|
11
|
+
constructor(storage: IStorage, crypto: IHostCrypto, notifier: IPushNotifier, clock: IClock);
|
|
12
|
+
handler: (callName: APICallName, dec: Decoder, enc: Encoder) => Promise<Status>;
|
|
13
|
+
}
|
|
14
|
+
export declare class LPCTransport implements ITransport {
|
|
15
|
+
private host;
|
|
16
|
+
listener: IPushListener;
|
|
17
|
+
constructor(host: DiplomaticLPCServer);
|
|
18
|
+
call: (name: APICallName, enc: Encoder) => Promise<ValStat<Decoder>>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { IClock } from "./clock.ts";
|
|
2
|
+
import type { ICrypto, IMessage, IMessageHead, SerializedContent } from "./types.ts";
|
|
3
|
+
import { ValStat } from "./valstat.ts";
|
|
4
|
+
interface IUpsertMessage extends IMessage {
|
|
5
|
+
bod: SerializedContent;
|
|
6
|
+
}
|
|
7
|
+
interface IDeleteMessage extends Omit<IMessage, "bod"> {
|
|
8
|
+
len: 0;
|
|
9
|
+
}
|
|
10
|
+
export type EncodedMessage = Uint8Array;
|
|
11
|
+
interface IInsertParams {
|
|
12
|
+
now: Date;
|
|
13
|
+
bod: SerializedContent;
|
|
14
|
+
crypto: ICrypto;
|
|
15
|
+
}
|
|
16
|
+
export declare function genInsertHead({ now, bod, crypto }: IInsertParams): Promise<ValStat<IMessageHead>>;
|
|
17
|
+
interface IUpsertParams extends Omit<IMessage, "off" | "len" | "hsh"> {
|
|
18
|
+
now: Date;
|
|
19
|
+
crypto: ICrypto;
|
|
20
|
+
}
|
|
21
|
+
export declare function genUpsertHead({ now, eid, ctr, bod, crypto }: IUpsertParams): Promise<ValStat<IMessageHead>>;
|
|
22
|
+
interface IDeleteParams extends Omit<IMessage, "off" | "len" | "hsh" | "bod"> {
|
|
23
|
+
now: Date;
|
|
24
|
+
crypto: ICrypto;
|
|
25
|
+
}
|
|
26
|
+
export declare function genDeleteHead({ now, eid, ctr, crypto }: IDeleteParams): Promise<ValStat<IMessageHead>>;
|
|
27
|
+
export declare function genInsert({ now, bod, crypto }: IInsertParams): Promise<ValStat<IUpsertMessage>>;
|
|
28
|
+
export declare function genDelete(params: IDeleteParams): Promise<ValStat<IDeleteMessage>>;
|
|
29
|
+
export declare function genSingletonUpsert(type: string, clk: IClock, content: Uint8Array, ctr?: number): Promise<ValStat<IUpsertMessage>>;
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type IStorage } from "../types.ts";
|
|
2
|
+
interface IMemoryStorage extends IStorage {
|
|
3
|
+
users: Set<string>;
|
|
4
|
+
bag: Map<string, Map<number, {
|
|
5
|
+
headCph: Uint8Array;
|
|
6
|
+
bodyCph: Uint8Array;
|
|
7
|
+
}>>;
|
|
8
|
+
}
|
|
9
|
+
declare const memStorage: IMemoryStorage;
|
|
10
|
+
export default memStorage;
|