@interncom/diplomatic 0.1.3 → 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.
Files changed (117) hide show
  1. package/README.md +69 -42
  2. package/dist/cli/bin/host.js +6 -0
  3. package/dist/cli/bun/src/codec.d.ts +3 -0
  4. package/dist/cli/bun/src/crypto.d.ts +3 -0
  5. package/dist/cli/bun/src/host.d.ts +1 -0
  6. package/dist/cli/bun/src/storage/sqlite.d.ts +3 -0
  7. package/dist/cli/index.js +6020 -0
  8. package/dist/cli/index.mjs +6020 -0
  9. package/dist/{shared/crypto/libsodium.d.ts → cli/shared/crypto/noble.d.ts} +1 -6
  10. package/dist/{shared → cli/shared}/types.d.ts +1 -2
  11. package/dist/cli/src/index.d.ts +44 -0
  12. package/dist/{client.d.ts → web/client.d.ts} +1 -1
  13. package/dist/web/crypto.d.ts +3 -0
  14. package/dist/{index.d.ts → web/index.d.ts} +2 -2
  15. package/dist/web/index.js +6800 -0
  16. package/dist/web/index.mjs +7645 -0
  17. package/dist/web/shared/api/peek.d.ts +3 -0
  18. package/dist/web/shared/api/pull.d.ts +3 -0
  19. package/dist/web/shared/api/push.d.ts +4 -0
  20. package/dist/web/shared/api/user.d.ts +2 -0
  21. package/dist/web/shared/auth.d.ts +8 -0
  22. package/dist/web/shared/bag.d.ts +15 -0
  23. package/dist/web/shared/binary.d.ts +8 -0
  24. package/dist/web/shared/client.d.ts +22 -0
  25. package/dist/web/shared/clock.d.ts +13 -0
  26. package/dist/web/shared/codec.d.ts +43 -0
  27. package/dist/web/shared/codecs/authTimestamp.d.ts +8 -0
  28. package/dist/web/shared/codecs/bag.d.ts +3 -0
  29. package/dist/web/shared/codecs/eid.d.ts +10 -0
  30. package/dist/web/shared/codecs/messageHead.d.ts +16 -0
  31. package/dist/web/shared/codecs/notifItem.d.ts +7 -0
  32. package/dist/web/shared/codecs/peekItem.d.ts +6 -0
  33. package/dist/web/shared/codecs/peekItemHead.d.ts +7 -0
  34. package/dist/web/shared/codecs/pullItem.d.ts +6 -0
  35. package/dist/web/shared/codecs/pushItem.d.ts +11 -0
  36. package/dist/web/shared/codecs/respHead.d.ts +10 -0
  37. package/dist/web/shared/codecs/usageQuota.d.ts +6 -0
  38. package/dist/web/shared/consts.d.ts +50 -0
  39. package/dist/web/shared/crypto/noble.d.ts +11 -0
  40. package/dist/web/shared/enclave.d.ts +8 -0
  41. package/dist/web/shared/endpoint.d.ts +23 -0
  42. package/dist/web/shared/events.d.ts +8 -0
  43. package/dist/web/shared/http/listener.d.ts +11 -0
  44. package/dist/web/shared/http/server.d.ts +14 -0
  45. package/dist/web/shared/http.d.ts +82 -0
  46. package/dist/web/shared/message.d.ts +22 -0
  47. package/dist/web/shared/singleton.d.ts +15 -0
  48. package/dist/web/shared/sync.d.ts +9 -0
  49. package/dist/web/shared/types.d.ts +163 -0
  50. package/dist/web/shared/valstat.d.ts +6 -0
  51. package/package.json +27 -11
  52. package/dist/crypto.d.ts +0 -3
  53. package/dist/exim.d.ts +0 -0
  54. package/dist/index.mjs +0 -11295
  55. package/dist/lib.d.ts +0 -2
  56. /package/dist/{shared → cli/shared}/api/peek.d.ts +0 -0
  57. /package/dist/{shared → cli/shared}/api/pull.d.ts +0 -0
  58. /package/dist/{shared → cli/shared}/api/push.d.ts +0 -0
  59. /package/dist/{shared → cli/shared}/api/user.d.ts +0 -0
  60. /package/dist/{shared → cli/shared}/auth.d.ts +0 -0
  61. /package/dist/{shared → cli/shared}/bag.d.ts +0 -0
  62. /package/dist/{shared → cli/shared}/binary.d.ts +0 -0
  63. /package/dist/{shared → cli/shared}/client.d.ts +0 -0
  64. /package/dist/{shared → cli/shared}/clock.d.ts +0 -0
  65. /package/dist/{shared → cli/shared}/codec.d.ts +0 -0
  66. /package/dist/{shared → cli/shared}/codecs/authTimestamp.d.ts +0 -0
  67. /package/dist/{shared → cli/shared}/codecs/bag.d.ts +0 -0
  68. /package/dist/{shared → cli/shared}/codecs/eid.d.ts +0 -0
  69. /package/dist/{shared → cli/shared}/codecs/messageHead.d.ts +0 -0
  70. /package/dist/{shared → cli/shared}/codecs/notifItem.d.ts +0 -0
  71. /package/dist/{shared → cli/shared}/codecs/peekItem.d.ts +0 -0
  72. /package/dist/{shared → cli/shared}/codecs/peekItemHead.d.ts +0 -0
  73. /package/dist/{shared → cli/shared}/codecs/pullItem.d.ts +0 -0
  74. /package/dist/{shared → cli/shared}/codecs/pushItem.d.ts +0 -0
  75. /package/dist/{shared → cli/shared}/codecs/respHead.d.ts +0 -0
  76. /package/dist/{shared → cli/shared}/codecs/usageQuota.d.ts +0 -0
  77. /package/dist/{shared → cli/shared}/consts.d.ts +0 -0
  78. /package/dist/{shared → cli/shared}/enclave.d.ts +0 -0
  79. /package/dist/{shared → cli/shared}/endpoint.d.ts +0 -0
  80. /package/dist/{shared → cli/shared}/events.d.ts +0 -0
  81. /package/dist/{shared → cli/shared}/http/listener.d.ts +0 -0
  82. /package/dist/{shared → cli/shared}/http/server.d.ts +0 -0
  83. /package/dist/{shared → cli/shared}/http.d.ts +0 -0
  84. /package/dist/{shared → cli/shared}/message.d.ts +0 -0
  85. /package/dist/{shared → cli/shared}/singleton.d.ts +0 -0
  86. /package/dist/{shared → cli/shared}/sync.d.ts +0 -0
  87. /package/dist/{shared → cli/shared}/valstat.d.ts +0 -0
  88. /package/dist/{entdb → web/entdb}/entdb.d.ts +0 -0
  89. /package/dist/{entdb → web/entdb}/idb.d.ts +0 -0
  90. /package/dist/{entdb → web/entdb}/memory.d.ts +0 -0
  91. /package/dist/{events.d.ts → web/events.d.ts} +0 -0
  92. /package/dist/{react → web/react}/useClient.d.ts +0 -0
  93. /package/dist/{react → web/react}/useEntities.d.ts +0 -0
  94. /package/dist/{react → web/react}/useStateWatcher.d.ts +0 -0
  95. /package/dist/{shared → web/shared}/codecs/file.d.ts +0 -0
  96. /package/dist/{shared → web/shared}/codecs/fileHead.d.ts +0 -0
  97. /package/dist/{shared → web/shared}/codecs/fileIndexItem.d.ts +0 -0
  98. /package/dist/{shared → web/shared}/exim.d.ts +0 -0
  99. /package/dist/{shared → web/shared}/lpc/listener.d.ts +0 -0
  100. /package/dist/{shared → web/shared}/lpc/pusher.d.ts +0 -0
  101. /package/dist/{shared → web/shared}/lpc/server.d.ts +0 -0
  102. /package/dist/{shared → web/shared}/storage/memory.d.ts +0 -0
  103. /package/dist/{state.d.ts → web/state.d.ts} +0 -0
  104. /package/dist/{stores → web/stores}/idb/dnlds.d.ts +0 -0
  105. /package/dist/{stores → web/stores}/idb/hosts.d.ts +0 -0
  106. /package/dist/{stores → web/stores}/idb/msgs.d.ts +0 -0
  107. /package/dist/{stores → web/stores}/idb/seed.d.ts +0 -0
  108. /package/dist/{stores → web/stores}/idb/store.d.ts +0 -0
  109. /package/dist/{stores → web/stores}/idb/uplds.d.ts +0 -0
  110. /package/dist/{stores → web/stores}/memory/dnlds.d.ts +0 -0
  111. /package/dist/{stores → web/stores}/memory/hosts.d.ts +0 -0
  112. /package/dist/{stores → web/stores}/memory/msgs.d.ts +0 -0
  113. /package/dist/{stores → web/stores}/memory/seed.d.ts +0 -0
  114. /package/dist/{stores → web/stores}/memory/store.d.ts +0 -0
  115. /package/dist/{stores → web/stores}/memory/uplds.d.ts +0 -0
  116. /package/dist/{sync.d.ts → web/sync.d.ts} +0 -0
  117. /package/dist/{types.d.ts → web/types.d.ts} +0 -0
@@ -0,0 +1,3 @@
1
+ import { IAuthenticatedEndpoint } from "../endpoint.ts";
2
+ import { IBagPeekItem } from "../codecs/peekItem.ts";
3
+ export declare const peekEnd: IAuthenticatedEndpoint<number, IBagPeekItem[]>;
@@ -0,0 +1,3 @@
1
+ import { type IBagPullItem } from "../codecs/pullItem.ts";
2
+ import { IAuthenticatedEndpoint } from "../endpoint.ts";
3
+ export declare const pullEnd: IAuthenticatedEndpoint<number, IBagPullItem[]>;
@@ -0,0 +1,4 @@
1
+ import { type IBagPushItem } from "../codecs/pushItem.ts";
2
+ import { IAuthenticatedEndpoint } from "../endpoint.ts";
3
+ import { IBag } from "../types.ts";
4
+ export declare const pushEnd: IAuthenticatedEndpoint<IBag, IBagPushItem[]>;
@@ -0,0 +1,2 @@
1
+ import { IAuthenticatedEndpoint } from "../endpoint.ts";
2
+ export declare const userEnd: IAuthenticatedEndpoint<never, void>;
@@ -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,15 @@
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
+ export 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>>;
@@ -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;
@@ -0,0 +1,22 @@
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;
8
+ crypto: ICrypto;
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>;
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,8 @@
1
+ import { ICodecStruct } from "../codec.ts";
2
+ import type { PublicKey } from "../types.ts";
3
+ export interface IAuthTimestamp {
4
+ pubKey: PublicKey;
5
+ sig: Uint8Array;
6
+ timestamp: Date;
7
+ }
8
+ export declare const authTimestampCodec: ICodecStruct<IAuthTimestamp>;
@@ -0,0 +1,3 @@
1
+ import { ICodecStruct } from "../codec.ts";
2
+ import type { IBag } from "../types.ts";
3
+ export declare const bagCodec: ICodecStruct<IBag>;
@@ -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,7 @@
1
+ import { ICodecStruct } from "../codec.ts";
2
+ export interface IBagNotifItem {
3
+ seq: number;
4
+ headCph: Uint8Array;
5
+ bodyCph?: Uint8Array;
6
+ }
7
+ export declare const notifItemCodec: ICodecStruct<IBagNotifItem>;
@@ -0,0 +1,6 @@
1
+ import { ICodecStruct } from "../codec.ts";
2
+ export interface IBagPeekItem {
3
+ seq: number;
4
+ headCph: Uint8Array;
5
+ }
6
+ export declare const peekItemCodec: ICodecStruct<IBagPeekItem>;
@@ -0,0 +1,7 @@
1
+ import { ICodecStruct } from "../codec.ts";
2
+ export interface IBagPeekItemHead {
3
+ sig: Uint8Array;
4
+ kdm: Uint8Array;
5
+ headCph: Uint8Array;
6
+ }
7
+ export declare const peekItemHeadCodec: ICodecStruct<IBagPeekItemHead>;
@@ -0,0 +1,6 @@
1
+ import { ICodecStruct } from "../codec.ts";
2
+ export interface IBagPullItem {
3
+ seq: number;
4
+ bodyCph: Uint8Array;
5
+ }
6
+ export declare const pullItemCodec: ICodecStruct<IBagPullItem>;
@@ -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,6 @@
1
+ import { ICodecStruct } from "../codec.ts";
2
+ export interface IUsageQuota {
3
+ quota: number;
4
+ usage?: number;
5
+ }
6
+ export declare const usageQuotaCodec: ICodecStruct<IUsageQuota>;
@@ -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";
@@ -0,0 +1,11 @@
1
+ import type { DerivationSeed, Hash, ICrypto, KeyPair } from "../types.ts";
2
+ export declare class NobleCrypto implements ICrypto {
3
+ genRandomBytes(bytes: number): Promise<Uint8Array>;
4
+ gen256BitSecureRandomSeed(): Promise<Uint8Array>;
5
+ encryptXSalsa20Poly1305Combined(data: Uint8Array, key: Uint8Array): Promise<Uint8Array>;
6
+ decryptXSalsa20Poly1305Combined(data: Uint8Array, key: Uint8Array): Promise<Uint8Array>;
7
+ deriveEd25519KeyPair(derivationSeed: DerivationSeed): Promise<KeyPair>;
8
+ signEd25519(message: Uint8Array | string, secKey: Uint8Array): Promise<Uint8Array>;
9
+ checkSigEd25519(sig: Uint8Array, message: Uint8Array | string, pubKey: Uint8Array): Promise<boolean>;
10
+ blake3(data: Uint8Array): Promise<Hash>;
11
+ }
@@ -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,8 @@
1
+ type TypedListener<T> = (data: T) => void;
2
+ export declare class TypedEventEmitter<T> {
3
+ private listeners;
4
+ addEventListener(eventType: string, listener: TypedListener<T>): () => void;
5
+ removeEventListener(eventType: string, listener: TypedListener<T>): void;
6
+ emit(eventType: string, data: T): void;
7
+ }
8
+ export {};
@@ -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,14 @@
1
+ import { IClock } from "../clock.ts";
2
+ import { IAuthTimestamp } from "../codecs/authTimestamp.ts";
3
+ import { type IHostCrypto, type IProtoHost, type IPushNotifier, type IStorage } from "../types.ts";
4
+ import { ValStat } from "../valstat.ts";
5
+ export declare class DiplomaticHTTPServer implements IProtoHost {
6
+ storage: IStorage;
7
+ crypto: IHostCrypto;
8
+ notifier: IPushNotifier;
9
+ clock: IClock;
10
+ constructor(storage: IStorage, crypto: IHostCrypto, notifier: IPushNotifier, clock: IClock);
11
+ corsHandler: (request: Request) => Promise<Response>;
12
+ handler: (request: Request) => Promise<Response>;
13
+ }
14
+ export declare function validateWebSocketAuth(request: Request, host: IProtoHost): Promise<ValStat<IAuthTimestamp>>;
@@ -0,0 +1,82 @@
1
+ import { Decoder, Encoder } from "./codec.ts";
2
+ import { APICallName } from "./consts.ts";
3
+ import { IHostConnectionInfo, 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 const hostHTTPTransport: (host: IHostConnectionInfo<URL>) => HTTPTransport;
79
+ export declare function errResp(head: IRespHead): Response;
80
+ export declare function binResp(encoder: Encoder): Response;
81
+ export declare function cors(resp: Response): Response;
82
+ export declare function post(url: URL, enc: Encoder): Promise<ValStat<Decoder>>;
@@ -0,0 +1,22 @@
1
+ import type { ICrypto, IDeleteMessage, IMessage, IMessageHead, IUpsertMessage, SerializedContent } from "./types.ts";
2
+ import { ValStat } from "./valstat.ts";
3
+ export type EncodedMessage = Uint8Array;
4
+ interface IInsertParams {
5
+ now: Date;
6
+ bod: SerializedContent;
7
+ crypto: ICrypto;
8
+ }
9
+ export declare function genInsertHead({ now, bod, crypto }: IInsertParams): Promise<ValStat<IMessageHead>>;
10
+ interface IUpsertParams extends Omit<IMessage, "off" | "len" | "hsh"> {
11
+ now: Date;
12
+ crypto: ICrypto;
13
+ }
14
+ export declare function genUpsertHead({ now, eid, ctr, bod, crypto }: IUpsertParams): Promise<ValStat<IMessageHead>>;
15
+ interface IDeleteParams extends Omit<IMessage, "off" | "len" | "hsh" | "bod"> {
16
+ now: Date;
17
+ crypto: ICrypto;
18
+ }
19
+ export declare function genDeleteHead({ now, eid, ctr, crypto }: IDeleteParams): Promise<ValStat<IMessageHead>>;
20
+ export declare function genInsert({ now, bod, crypto }: IInsertParams): Promise<ValStat<IUpsertMessage>>;
21
+ export declare function genDelete(params: IDeleteParams): Promise<ValStat<IDeleteMessage>>;
22
+ export {};
@@ -0,0 +1,15 @@
1
+ import { IClock } from "./clock.ts";
2
+ import { Status } from "./consts.ts";
3
+ import { IMessage, IStateManager, IUpsertMessage, SerializedContent } from "./types.ts";
4
+ import { ValStat } from "./valstat.ts";
5
+ export declare function genSingletonUpsert(type: string, clk: IClock, content: Uint8Array, ctr?: number): Promise<ValStat<IUpsertMessage>>;
6
+ export declare class SingletonStateManager implements IStateManager {
7
+ private singletonType;
8
+ latest: SerializedContent | undefined;
9
+ private latestOff;
10
+ private emitter;
11
+ constructor(singletonType: string);
12
+ apply(messages: IMessage[]): Promise<Status[]>;
13
+ on: (event: string, listener: () => void) => void;
14
+ off: (event: string, listener: () => void) => void;
15
+ }
@@ -0,0 +1,9 @@
1
+ import { IBagPeekItem } from "./codecs/peekItem.ts";
2
+ import { Enclave } from "./enclave.ts";
3
+ import { HostSpecificKeyPair, ICrypto } from "./types.ts";
4
+ import { ValStat } from "./valstat.ts";
5
+ export interface IDecryptedBagPeekItem {
6
+ kdm: Uint8Array;
7
+ headEnc: Uint8Array;
8
+ }
9
+ export declare function decryptPeekItem(item: IBagPeekItem, hostKeys: HostSpecificKeyPair, enclave: Enclave, crypto: ICrypto): Promise<ValStat<IDecryptedBagPeekItem>>;