@interncom/diplomatic 0.20.0 → 0.22.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.
@@ -6,6 +6,11 @@ type OpenDiplomaticClientBase = {
6
6
  clock?: IClock;
7
7
  /** Max wait for setSeed → Enclave.spawnSyncWorker handshake (default 15s). */
8
8
  readyTimeoutMs?: number;
9
+ /**
10
+ * Timed `[dip]` traces for local writes, EntDB, and watchers (default false).
11
+ * Process-wide; same flag as {@link openEntDB}.
12
+ */
13
+ verbose?: boolean;
9
14
  /**
10
15
  * Debounce local write → worker sync (default `defaultSyncDebounceMs`).
11
16
  * Use `0` in tests for an immediate upload-queue handoff.
@@ -17,6 +17,11 @@ type UseClientBase = {
17
17
  * Set false to notify only after durable commit.
18
18
  */
19
19
  optimistic?: boolean;
20
+ /**
21
+ * Timed `[dip]` traces (default false). See {@link openEntDB} /
22
+ * {@link openDiplomaticClient}.
23
+ */
24
+ verbose?: boolean;
20
25
  };
21
26
  /**
22
27
  * Worker path: IndexedDB on main; sync Worker appears on setSeed via Enclave.
@@ -3,7 +3,7 @@ import { Status } from "../consts.ts";
3
3
  import { MASTER_SEED_LEN, type MasterSeed, type SealedMasterKey } from "../seed.ts";
4
4
  import type { ICrypto, PublicKey } from "../types.ts";
5
5
  import { type ValStat } from "../valstat.ts";
6
- import { type DHKEReq, type DHKEResp, PairRequest } from "./pairing.ts";
6
+ import { type DHKEReq, type DHKEResp } from "./pairing.ts";
7
7
  import { type LargeBlobCreateOpts, type LargeBlobRp } from "../webauthn/largeBlob.ts";
8
8
  import { type PrfCeremony, type PrfCreateOpts, type PrfEvalOpts, type PrfRp } from "../webauthn/prf.ts";
9
9
  export type { LargeBlobCreateOpts, LargeBlobRp };
@@ -60,10 +60,23 @@ export type Identity = {
60
60
  kdmFor: (msgHeadEnc: Uint8Array) => Promise<Uint8Array>;
61
61
  };
62
62
  declare const SEAL_BIND_DOMAIN: Uint8Array<ArrayBufferLike>;
63
+ declare const FP_MODE: Uint8Array<ArrayBufferLike>;
63
64
  declare const SEAL_KEY_LEN = 32;
64
65
  declare const SEAL_PRF_MIN_LEN = 16;
65
66
  /** Minimum musec length (Mandatory User-Space Entropy Contribution). */
66
67
  declare const MUSEC_MIN_LEN = 32;
68
+ declare class PairRequest {
69
+ #private;
70
+ private constructor();
71
+ static create(): Promise<ValStat<PairRequest>>;
72
+ wipe(): void;
73
+ get dhkeReq(): DHKEReq;
74
+ finish(dhkeResp: DHKEResp): Promise<ValStat<{
75
+ enclave: Enclave;
76
+ hosts: BundleHost[];
77
+ }>>;
78
+ }
79
+ export type { PairRequest };
67
80
  /** Brand `bytes` as {@link MasterSeed} only if length is {@link MASTER_SEED_LEN}. */
68
81
  export declare function asMasterSeed(bytes: Uint8Array): ValStat<MasterSeed>;
69
82
  export declare class Enclave {
@@ -143,15 +156,24 @@ export declare class Enclave {
143
156
  /** UV + overwrite largeBlob with zeros (destroys stored seed material). */
144
157
  static clearLargeBlob(credId: Uint8Array, opts?: LargeBlobRp): Promise<Status>;
145
158
  /**
146
- * Absorb seed‖hosts plaintext (pair AEAD inner).
147
- * Encoder/Decoder never see the seed.
159
+ * Write numbered `n] xxxx xxxx` hex lines plus a # check to /dev/tty.
160
+ * Paced mode erases the previous line before the next (Enter between).
161
+ * Web bundles set DIP_CLI_DUMP=false; the write is compiled out.
148
162
  */
149
- static fromPairPlain(plain: Uint8Array): ValStat<{
150
- enclave: Enclave;
151
- hosts: BundleHost[];
152
- }>;
163
+ dumpToTty(): Promise<Status>;
153
164
  static pairRequest(): Promise<ValStat<PairRequest>>;
154
- pairAccept(dhkeReq: DHKEReq, hosts: BundleHost[]): Promise<ValStat<DHKEResp>>;
165
+ /**
166
+ * Seals seed+hosts for dhkeReq. Returns dhkeResp to send back.
167
+ * @param acks Set fields only after explicit user affirmation (e.g. a checkbox).
168
+ * Do not default these to `true` in application code.
169
+ */
170
+ pairAccept(dhkeReq: DHKEReq, hosts: BundleHost[], acks: {
171
+ /**
172
+ * Set `true` only after the user explicitly affirms they control both
173
+ * devices in this pair. Never hard-code in a client.
174
+ */
175
+ userControlsBothSidesOfPair: true;
176
+ }): Promise<ValStat<DHKEResp>>;
155
177
  /**
156
178
  * Spawn a new sync Worker from the embedded bundle and inject this enclave's
157
179
  * master seed into it (transfer). Seed never goes to a caller-supplied port —
@@ -178,4 +200,4 @@ export declare class Enclave {
178
200
  }
179
201
  /** Derive seal key from PRF output (domain-separated). Used by enclave seal/unseal. */
180
202
  export declare function sealKeyFromPrf(crypto: ICrypto, prf: Uint8Array, domain?: Uint8Array): Promise<ValStat<Uint8Array>>;
181
- export { MASTER_SEED_LEN, MUSEC_MIN_LEN, SEAL_BIND_DOMAIN, SEAL_KEY_LEN, SEAL_PRF_MIN_LEN, };
203
+ export { FP_MODE, MASTER_SEED_LEN, MUSEC_MIN_LEN, SEAL_BIND_DOMAIN, SEAL_KEY_LEN, SEAL_PRF_MIN_LEN, };
@@ -1,5 +1,5 @@
1
1
  import { type X25519Sk } from "./x25519.ts";
2
- import type { DerivationSeed, Hash, ICrypto, KeyPair } from "../types.ts";
2
+ import type { Blake3Opts, DerivationSeed, Hash, ICrypto, KeyPair } from "../types.ts";
3
3
  /**
4
4
  * ICrypto: noble for XSalsa20 + blake3; WebCrypto Ed25519 + X25519
5
5
  * (our scalar; RFC 7748 check before trusting pub/DH).
@@ -15,7 +15,7 @@ export declare class NobleCrypto implements ICrypto {
15
15
  private importVerifyKey;
16
16
  signEd25519(message: Uint8Array | string, secKey: Uint8Array): Promise<Uint8Array>;
17
17
  checkSigEd25519(sig: Uint8Array, message: Uint8Array | string, pubKey: Uint8Array): Promise<boolean>;
18
- blake3(data: Uint8Array): Promise<Hash>;
18
+ blake3(data: Uint8Array, opts?: Blake3Opts): Promise<Hash>;
19
19
  genX25519(): Promise<{
20
20
  priv: X25519Sk;
21
21
  pub: Uint8Array;
@@ -1,6 +1,4 @@
1
- import type { BundleHost } from "../codecs/bundleHost.ts";
2
1
  import { type ValStat } from "../valstat.ts";
3
- import { Enclave } from "./enclave.ts";
4
2
  import type { X25519Sk } from "./x25519.ts";
5
3
  export declare const SEAL_PAIR_DOMAIN: Uint8Array<ArrayBufferLike>;
6
4
  export declare const X25519_PUB_LEN = 32;
@@ -20,15 +18,4 @@ export declare function pairKey(sk: X25519Sk, // local X25519 priv
20
18
  peer: Uint8Array, // ECDH peer pub (enroller: dhkeReq; enrollee: respPub)
21
19
  reqPub: Uint8Array, // enrollee pub, bound into KDF
22
20
  respPub: Uint8Array): Promise<ValStat<Uint8Array>>;
23
- export declare class PairRequest {
24
- #private;
25
- private constructor();
26
- static create(): Promise<ValStat<PairRequest>>;
27
- wipe(): void;
28
- get dhkeReq(): DHKEReq;
29
- finish(dhkeResp: DHKEResp): Promise<ValStat<{
30
- enclave: Enclave;
31
- hosts: BundleHost[];
32
- }>>;
33
- }
34
21
  export {};
@@ -125,6 +125,13 @@ export type Hash = Uint8Array & {
125
125
  export interface IHostCrypto {
126
126
  checkSigEd25519: (sig: Uint8Array, message: Uint8Array | string, pubKey: PublicKey) => Promise<boolean>;
127
127
  }
128
+ /** BLAKE3 hash / MAC / KDF (noble: `key` XOR `context`, not both). */
129
+ export type Blake3Opts = {
130
+ /** 32-byte MAC key. */
131
+ key?: Uint8Array;
132
+ /** KDF context (hardcoded, app-specific). */
133
+ context?: Uint8Array | string;
134
+ };
128
135
  export interface ICrypto extends IHostCrypto {
129
136
  genRandomBytes: (bytes: number) => Promise<Uint8Array>;
130
137
  gen256BitSecureRandomSeed: () => Promise<Uint8Array>;
@@ -132,7 +139,7 @@ export interface ICrypto extends IHostCrypto {
132
139
  decryptXSalsa20Poly1305Combined: (headerAndCipher: Uint8Array, key: Uint8Array) => Promise<Uint8Array>;
133
140
  deriveEd25519KeyPair: (derivationSeed: DerivationSeed) => Promise<KeyPair>;
134
141
  signEd25519: (message: Uint8Array | string, secKey: PrivateKey) => Promise<Uint8Array>;
135
- blake3: (data: Uint8Array) => Promise<Hash>;
142
+ blake3: (data: Uint8Array, opts?: Blake3Opts) => Promise<Hash>;
136
143
  }
137
144
  export interface IMsgpackCodec {
138
145
  encode: (source: unknown) => Uint8Array;
@@ -295,7 +295,7 @@ export interface IStateEmitter<T> {
295
295
  export interface IClient<Handle extends HostHandle> {
296
296
  /** Install session enclave (master seed stays inside enclave). */
297
297
  setSeed(enclave: Enclave, opts?: SetSeedOpts): Promise<void>;
298
- link(host: IHostConnectionInfo<Handle>): Promise<void>;
298
+ link(host: IHostConnectionInfo<Handle>, connect?: boolean): Promise<void>;
299
299
  unlink(label: string): Promise<void>;
300
300
  /** Linked hosts from the protocol store (handle, label, lastSeq, …). */
301
301
  hosts(): Promise<IHostRow<Handle>[]>;
@@ -0,0 +1,4 @@
1
+ /** Turn `[dip]` timings on or off. */
2
+ export declare function setVerbose(v: boolean): void;
3
+ /** Timed `[dip]` line when verbose. */
4
+ export declare function dipLog(msg: string, extra?: object): void;