@interncom/diplomatic 0.6.3 → 0.7.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.
@@ -1,8 +1,9 @@
1
1
  import { IClock } from "./clock.ts";
2
2
  import { type IAuthTimestamp } from "./codecs/authTimestamp.ts";
3
3
  import { Status } from "./consts.ts";
4
- import type { ICrypto, IHostCrypto, KeyPair } from "./types.ts";
4
+ import type { Identity } from "./crypto/enclave.ts";
5
+ import type { IHostCrypto } from "./types.ts";
5
6
  import { ValStat } from "./valstat.ts";
6
7
  export type EncodedAuthTimestamp = Uint8Array;
7
- export declare function makeAuthTimestamp(keys: KeyPair, ts: Date, crypto: ICrypto): Promise<ValStat<IAuthTimestamp>>;
8
+ export declare function makeAuthTimestamp(identity: Pick<Identity, "publicKey" | "sign">, ts: Date): Promise<ValStat<IAuthTimestamp>>;
8
9
  export declare function validateAuthTimestamp(authTS: IAuthTimestamp, crypto: IHostCrypto, clock: IClock): Promise<Status>;
@@ -1,17 +1,16 @@
1
1
  import { IMessageHead } from "./codecs/messageHead.ts";
2
- import { Enclave } from "./enclave.ts";
2
+ import { type DecryptCipher, Enclave, type Identity } from "./crypto/enclave.ts";
3
3
  import { EncodedMessage } from "./message.ts";
4
4
  import { type ValStat } from "./valstat.ts";
5
- import type { Hash, HostSpecificKeyPair, IBag, ICrypto, IHostCrypto, IMessage, IMessageWithHash, PublicKey } from "./types.ts";
5
+ import type { Hash, IBag, ICrypto, IHostCrypto, IMessage, IMessageWithHash, PublicKey } from "./types.ts";
6
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>>;
7
+ export declare function sealBag(msg: IMessage, identity: Identity, crypto: ICrypto, enclave: Enclave): Promise<ValStat<IBag>>;
9
8
  export interface IOpenBag {
10
9
  msgHead: IMessageHead;
11
10
  bod?: EncodedMessage;
12
11
  headHash: Hash;
13
12
  }
14
- export declare function openBagBody(headEnc: Uint8Array, bodyCph: Uint8Array | undefined, key: Uint8Array, crypto: ICrypto,
13
+ export declare function openBagBody(headEnc: Uint8Array, bodyCph: Uint8Array | undefined, cipher: DecryptCipher, crypto: ICrypto,
15
14
  /** When set (e.g. from peek), skip blake3(headEnc). */
16
15
  headHashKnown?: Hash): Promise<ValStat<IOpenBag>>;
17
16
  export declare function openBag(bag: IBag, pubKey: PublicKey, crypto: ICrypto, enclave: Enclave): Promise<ValStat<IMessageWithHash>>;
@@ -1,7 +1,7 @@
1
1
  import { IClock } from "./clock.ts";
2
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";
3
+ import { Enclave, type Identity } from "./crypto/enclave.ts";
4
+ import type { HostHandle, IBag, ICrypto, IHostConnectionInfo, IHostMetadata, IMessage, ITransport, PushReceiver } from "./types.ts";
5
5
  import { ValStat } from "./valstat.ts";
6
6
  export default class DiplomaticClientAPI<Handle extends HostHandle> {
7
7
  enclave: Enclave;
@@ -12,7 +12,7 @@ export default class DiplomaticClientAPI<Handle extends HostHandle> {
12
12
  private updateHostMeta;
13
13
  constructor(enclave: Enclave, crypto: ICrypto, host: IHostConnectionInfo<Handle>, clock: IClock, transport: ITransport, updateHostMeta: (meta: IHostMetadata) => Promise<Status>);
14
14
  private call;
15
- keys: () => Promise<HostSpecificKeyPair>;
15
+ identity: () => Promise<Identity>;
16
16
  seal: (msg: IMessage) => Promise<ValStat<IBag>>;
17
17
  register: () => Promise<ValStat<void>>;
18
18
  peek: (lastSeq: number) => Promise<ValStat<import("./codecs/peekItem.ts").IBagPeekItem[]>>;
@@ -0,0 +1,42 @@
1
+ import type { ICrypto, MasterSeed, PublicKey } from "../types.ts";
2
+ export type EncryptCipher = {
3
+ encrypt: (data: Uint8Array) => Promise<Uint8Array>;
4
+ };
5
+ export type DecryptCipher = {
6
+ decrypt: (data: Uint8Array) => Promise<Uint8Array>;
7
+ };
8
+ /** Encrypt + decrypt capability for one KDM. */
9
+ export type DerivedCipher = EncryptCipher & DecryptCipher;
10
+ /** Which ops the caller needs; only those methods are present on the handle. */
11
+ export type CipherUsage = "encrypt" | "decrypt" | "both";
12
+ /** Return shape of `deriveCipher` for a given usage (type-level enforcement). */
13
+ export type CipherForUsage<U extends CipherUsage> = {
14
+ encrypt: EncryptCipher;
15
+ decrypt: DecryptCipher;
16
+ both: DerivedCipher;
17
+ }[U];
18
+ /**
19
+ * Path-scoped signing identity: public key is public; sign/kdmFor re-enter
20
+ * the enclave so the private key never leaves. Used for hosts, export files, etc.
21
+ */
22
+ export type Identity = {
23
+ readonly publicKey: PublicKey;
24
+ sign: (message: Uint8Array | string) => Promise<Uint8Array>;
25
+ /** Per-bag KDM mixed with this identity's private key (see bag seal). */
26
+ kdmFor: (msgHeadEnc: Uint8Array) => Promise<Uint8Array>;
27
+ };
28
+ export declare class Enclave {
29
+ #private;
30
+ constructor(seed: MasterSeed, crypto: ICrypto);
31
+ /**
32
+ * Cipher for public KDM. Does not hold key bytes; each op re-enters the
33
+ * enclave (async, hardware-shaped). `usage` selects the return shape:
34
+ * `"encrypt"` → `{ encrypt }`, `"decrypt"` → `{ decrypt }`, `"both"` → both.
35
+ */
36
+ deriveCipher<U extends CipherUsage>(kdm: Uint8Array, usage: U): CipherForUsage<U>;
37
+ /**
38
+ * Path-scoped identity (label+index). Private key stays in the enclave; only
39
+ * publicKey and capability methods are returned (frozen).
40
+ */
41
+ deriveIdentity(keyPath: string, idx?: number): Promise<Identity>;
42
+ }
@@ -2,8 +2,8 @@ import { IClock } from "./clock.ts";
2
2
  import { Decoder, Encoder } from "./codec.ts";
3
3
  import { IAuthTimestamp } from "./codecs/authTimestamp.ts";
4
4
  import { Status } from "./consts.ts";
5
- import { Enclave } from "./enclave.ts";
6
- import { HostSpecificKeyPair, ICrypto, IProtoHost } from "./types.ts";
5
+ import { Enclave, type Identity } from "./crypto/enclave.ts";
6
+ import { ICrypto, IProtoHost } from "./types.ts";
7
7
  import { ValStat } from "./valstat.ts";
8
8
  interface IProtoClient {
9
9
  crypto: ICrypto;
@@ -11,13 +11,12 @@ interface IProtoClient {
11
11
  clock: IClock;
12
12
  }
13
13
  export interface IAuthenticatedEndpoint<ReqItem, Resp> {
14
- encodeReq(client: IProtoClient, keys: HostSpecificKeyPair, authTS: IAuthTimestamp, body: Iterable<ReqItem>, reqEnc: Encoder): Promise<Status>;
14
+ encodeReq(client: IProtoClient, identity: Identity, authTS: IAuthTimestamp, body: Iterable<ReqItem>, reqEnc: Encoder): Promise<Status>;
15
15
  handleReq(host: IProtoHost, reqDec: Decoder, respEnc: Encoder): Promise<Status>;
16
16
  decodeResp(respDec: Decoder): ValStat<Resp>;
17
17
  }
18
18
  export interface IAuthData {
19
- keys: HostSpecificKeyPair;
19
+ identity: Identity;
20
20
  authTS: IAuthTimestamp;
21
21
  }
22
- export declare function hostKeys(host: IProtoClient, keyPath: string, idx?: number): Promise<HostSpecificKeyPair>;
23
22
  export {};
@@ -1,4 +1,4 @@
1
- import { Enclave } from "./enclave.ts";
1
+ import { Enclave } from "./crypto/enclave.ts";
2
2
  import { ICrypto, IMessageHead } from "./types.ts";
3
3
  import { ValStat } from "./valstat.ts";
4
4
  export declare const defaultFileExtension = "dpl";
@@ -1,9 +1,9 @@
1
1
  import { IBagPeekItem } from "./codecs/peekItem.ts";
2
- import { Enclave } from "./enclave.ts";
3
- import { HostSpecificKeyPair, ICrypto } from "./types.ts";
2
+ import { Enclave } from "./crypto/enclave.ts";
3
+ import { ICrypto, PublicKey } from "./types.ts";
4
4
  import { ValStat } from "./valstat.ts";
5
5
  export interface IDecryptedBagPeekItem {
6
6
  kdm: Uint8Array;
7
7
  headEnc: Uint8Array;
8
8
  }
9
- export declare function decryptPeekItem(item: IBagPeekItem, hostKeys: HostSpecificKeyPair, enclave: Enclave, crypto: ICrypto): Promise<ValStat<IDecryptedBagPeekItem>>;
9
+ export declare function decryptPeekItem(item: IBagPeekItem, pubKey: PublicKey, enclave: Enclave, crypto: ICrypto): Promise<ValStat<IDecryptedBagPeekItem>>;
@@ -14,6 +14,12 @@ export type SerializedContent = Uint8Array;
14
14
  export interface IMsgEntBody<T = unknown> {
15
15
  gid?: GroupID;
16
16
  pid?: EntityID;
17
+ /**
18
+ * Optional multi-value tags for reverse multi-ref / label lookup (multiEntry-indexed).
19
+ * Opaque strings; entDB does not parse semantics. Empty strings and duplicates are
20
+ * dropped on apply. Omit or [] means no tags.
21
+ */
22
+ tags?: string[];
17
23
  type: string;
18
24
  body?: T;
19
25
  }
@@ -1,4 +1,4 @@
1
- import { Enclave } from "../../shared/enclave";
1
+ import { Enclave } from "../../shared/crypto/enclave";
2
2
  import { MasterSeed } from "../../shared/types";
3
3
  import { ISeedStore } from "../../types";
4
4
  export declare class IDBSeedStore implements ISeedStore {
@@ -1,4 +1,4 @@
1
- import { Enclave } from "../../shared/enclave";
1
+ import { Enclave } from "../../shared/crypto/enclave";
2
2
  import { MasterSeed } from "../../shared/types";
3
3
  import { ISeedStore } from "../../types";
4
4
  export declare class MemorySeedStore implements ISeedStore {
@@ -1,6 +1,6 @@
1
1
  import DiplomaticClientAPI from "./shared/client";
2
2
  import { Status } from "./shared/consts";
3
- import { Enclave } from "./shared/enclave";
3
+ import { Enclave } from "./shared/crypto/enclave";
4
4
  import { Hash, HostHandle, IBag, ICrypto } from "./shared/types";
5
5
  import { ValStat } from "./shared/valstat";
6
6
  import { ProgressFn } from "./progress";
@@ -20,7 +20,7 @@ export type IPulled = {
20
20
  bodyCph?: Uint8Array;
21
21
  };
22
22
  /** Host connection methods used by sync phases. */
23
- export type SyncConn<Handle extends HostHandle> = Pick<DiplomaticClientAPI<Handle>, "pull" | "push" | "peek" | "seal" | "keys">;
23
+ export type SyncConn<Handle extends HostHandle> = Pick<DiplomaticClientAPI<Handle>, "pull" | "push" | "peek" | "seal" | "identity">;
24
24
  export interface ISyncParams<Handle extends HostHandle> {
25
25
  conn: SyncConn<Handle>;
26
26
  store: IStore<Handle>;
@@ -1,6 +1,6 @@
1
1
  import type { SyncProgressEvent } from "./progress";
2
2
  import { Status } from "./shared/consts";
3
- import type { Enclave } from "./shared/enclave";
3
+ import type { Enclave } from "./shared/crypto/enclave";
4
4
  import type { EncodedMessage } from "./shared/message";
5
5
  import type { EntityID, Hash, HostHandle, IDeleteParams, IEntRev, IHostConnectionInfo, IHostMetadata, IInsertParams, IMessageHead, IOp, IUpdateParams, MasterSeed, SerializedContent } from "./shared/types";
6
6
  import { ValStat } from "./shared/valstat";