@moonmath-ai/zro 0.4.2 → 0.5.0-beta.1

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 (46) hide show
  1. package/README.md +63 -4
  2. package/dist/args.js +87 -0
  3. package/dist/args.js.map +1 -1
  4. package/dist/e2ee-proxy.d.ts +18 -0
  5. package/dist/e2ee-proxy.js +585 -0
  6. package/dist/e2ee-proxy.js.map +1 -0
  7. package/dist/e2ee.d.ts +187 -0
  8. package/dist/e2ee.js +907 -0
  9. package/dist/e2ee.js.map +1 -0
  10. package/dist/engine/tools/claude.js +9 -4
  11. package/dist/engine/tools/claude.js.map +1 -1
  12. package/dist/engine/tools/codex.js +8 -3
  13. package/dist/engine/tools/codex.js.map +1 -1
  14. package/dist/engine/tools/grok.js +3 -2
  15. package/dist/engine/tools/grok.js.map +1 -1
  16. package/dist/engine/tools/hermes.js +4 -3
  17. package/dist/engine/tools/hermes.js.map +1 -1
  18. package/dist/engine/tools/kilo.js +2 -4
  19. package/dist/engine/tools/kilo.js.map +1 -1
  20. package/dist/engine/tools/omp.js +4 -4
  21. package/dist/engine/tools/omp.js.map +1 -1
  22. package/dist/engine/tools/openclaw.js +4 -3
  23. package/dist/engine/tools/openclaw.js.map +1 -1
  24. package/dist/engine/tools/opencode.js +2 -4
  25. package/dist/engine/tools/opencode.js.map +1 -1
  26. package/dist/engine/tools/opencode2.js +2 -4
  27. package/dist/engine/tools/opencode2.js.map +1 -1
  28. package/dist/engine/tools/pi.js +3 -3
  29. package/dist/engine/tools/pi.js.map +1 -1
  30. package/dist/engine/tools/prime.js +2 -2
  31. package/dist/engine/tools/prime.js.map +1 -1
  32. package/dist/engine/types.d.ts +2 -0
  33. package/dist/install.js +19 -0
  34. package/dist/install.js.map +1 -1
  35. package/dist/run.js +207 -53
  36. package/dist/run.js.map +1 -1
  37. package/dist/selfupdate.d.ts +7 -0
  38. package/dist/selfupdate.js +136 -0
  39. package/dist/selfupdate.js.map +1 -0
  40. package/dist/types.d.ts +12 -0
  41. package/dist/ui.js +6 -1
  42. package/dist/ui.js.map +1 -1
  43. package/dist/version.d.ts +1 -0
  44. package/dist/version.js +6 -0
  45. package/dist/version.js.map +1 -0
  46. package/package.json +4 -1
package/dist/e2ee.d.ts ADDED
@@ -0,0 +1,187 @@
1
+ /**
2
+ * Zero-dependency RFC 9180 HPKE client (`zro-hpke-v1`) on Node 22+ `node:crypto`.
3
+ *
4
+ * Implements HPKE Base Mode (DHKEM(X25519, HKDF-SHA256), HKDF-SHA256, AES-256-GCM),
5
+ * Ed25519 manifest canonicalization & verification, outer shell builders, and
6
+ * non-streaming + streaming SSE response decryptors for `/v1/chat/completions`,
7
+ * `/v1/responses`, and `/v1/messages`.
8
+ */
9
+ export declare const HPKE_MODE_BASE = 0;
10
+ export declare const KEM_DHKEM_X25519_HKDF_SHA256 = 32;
11
+ export declare const KDF_HKDF_SHA256 = 1;
12
+ export declare const AEAD_AES_128_GCM = 1;
13
+ export declare const AEAD_AES_256_GCM = 2;
14
+ export declare const PROTOCOL_PREFIX = "zro-hpke:v1:";
15
+ export declare const MANIFEST_ALG = "HPKE-X25519-HKDF-SHA256-AES256GCM";
16
+ export declare const REQ_INFO_PREFIX = "zro-hpke-v1:";
17
+ export declare const REQ_AAD: Buffer<ArrayBuffer>;
18
+ export declare const RESP_KEY_EXPORT_LABEL: Buffer<ArrayBuffer>;
19
+ export declare const RESP_IV_EXPORT_LABEL: Buffer<ArrayBuffer>;
20
+ /**
21
+ * Production HSM Ed25519 root public key (unpadded base64url, 32 bytes).
22
+ * Mirrors the DNSSEC-protected TXT record at `_zro-e2ee.zro.moonmath.ai`.
23
+ * Override for staging or testing via `--e2ee-root-pubkey` or `ZRO_E2EE_ROOT_PUBKEY`.
24
+ */
25
+ export declare const DEFAULT_E2EE_ROOT_PUBKEY: string | undefined;
26
+ export type ZroEndpoint = "chat_completions" | "responses" | "messages";
27
+ export type FetchFn = (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
28
+ export declare class E2EEError extends Error {
29
+ constructor(message: string);
30
+ }
31
+ export declare class ManifestVerificationError extends E2EEError {
32
+ constructor(message: string);
33
+ }
34
+ export declare class DecryptionError extends E2EEError {
35
+ constructor(message: string);
36
+ }
37
+ export declare class StreamTruncationError extends E2EEError {
38
+ constructor(message: string);
39
+ }
40
+ export interface ManifestKeyEntry {
41
+ kid: string;
42
+ alg: string;
43
+ public_key: string;
44
+ fingerprint: string;
45
+ status: string;
46
+ not_before?: string;
47
+ not_after?: string;
48
+ }
49
+ export interface KeyManifest {
50
+ version: string;
51
+ published_at?: string;
52
+ keys: ManifestKeyEntry[];
53
+ supported_models?: string[];
54
+ signature: {
55
+ alg: string;
56
+ root_kid?: string;
57
+ sig: string;
58
+ };
59
+ [key: string]: unknown;
60
+ }
61
+ export interface DecryptedStreamResult {
62
+ endpoint: ZroEndpoint;
63
+ items: unknown[];
64
+ finishReason: string | null;
65
+ framesCount: number;
66
+ model: string | null;
67
+ usage: Record<string, unknown> | null;
68
+ }
69
+ export declare function resolveE2eeRootPubkey(flagValue?: string, env?: NodeJS.ProcessEnv): string;
70
+ export declare function b64uEncode(data: Uint8Array): string;
71
+ export declare function b64uDecode(text: string): Buffer;
72
+ export declare function x25519PublicFromPrivate(skBytes: Uint8Array): Buffer;
73
+ export declare function deriveKeyPair(ikm: Uint8Array): {
74
+ sk: Buffer;
75
+ pk: Buffer;
76
+ };
77
+ export declare class HpkeContext {
78
+ private readonly key;
79
+ private readonly baseNonce;
80
+ private readonly exporterSecret;
81
+ private readonly suiteId;
82
+ private readonly aeadId;
83
+ private readonly role;
84
+ private seq;
85
+ constructor(params: {
86
+ key: Buffer;
87
+ baseNonce: Buffer;
88
+ exporterSecret: Buffer;
89
+ suiteId: Buffer;
90
+ aeadId: number;
91
+ role: "sender" | "recipient";
92
+ });
93
+ private nextNonce;
94
+ seal(aad: Uint8Array, plaintext: Uint8Array): Buffer;
95
+ open(aad: Uint8Array, ciphertext: Uint8Array): Buffer;
96
+ exportSecret(exporterContext: Uint8Array, length: number): Buffer;
97
+ }
98
+ export declare function setupBaseS(pkR: Uint8Array, info: Uint8Array, options?: {
99
+ aeadId?: number;
100
+ ikmE?: Uint8Array;
101
+ }): {
102
+ enc: Buffer;
103
+ ctx: HpkeContext;
104
+ };
105
+ export declare function setupBaseR(enc: Uint8Array, skR: Uint8Array, info: Uint8Array, options?: {
106
+ aeadId?: number;
107
+ }): HpkeContext;
108
+ export declare function canonicalManifestBytes(manifest: Record<string, unknown>): Buffer;
109
+ export declare function keyFingerprint(publicKeyBytes: Uint8Array): string;
110
+ export declare function signManifest(unsignedManifest: Record<string, unknown>, rootPrivateKeyBytes: Uint8Array, rootKid: string): KeyManifest;
111
+ export declare function verifyManifest(manifest: unknown, pinnedRootPublicKey: string | Uint8Array): KeyManifest;
112
+ export declare function selectActiveKey(manifest: KeyManifest, options?: {
113
+ now?: Date;
114
+ checkTime?: boolean;
115
+ }): {
116
+ kid: string;
117
+ publicKey: Buffer;
118
+ };
119
+ export declare function supportedE2eeModels(manifest: KeyManifest): Set<string>;
120
+ export declare function fetchAndVerifyManifest(baseUrl: string, pinnedRootPublicKey: string | Uint8Array, fetcher?: FetchFn): Promise<KeyManifest>;
121
+ export declare function responseFrameNonce(respIv: Uint8Array, seq: number | bigint): Buffer;
122
+ export declare function responseFrameAad(kid: string, seq: number | bigint, isEof?: boolean): Buffer;
123
+ export declare function encryptResponseFrame(respKey: Uint8Array, respIv: Uint8Array, kid: string, seq: number | bigint, plaintext: Uint8Array, isEof?: boolean): string;
124
+ export declare function parseWireFrame(rawFrameNoSemi: string): {
125
+ seq: bigint;
126
+ isEof: boolean;
127
+ ct: Buffer;
128
+ };
129
+ export declare function decryptResponseFrame(respKey: Uint8Array, respIv: Uint8Array, kid: string, rawFrameNoSemi: string): {
130
+ seq: bigint;
131
+ isEof: boolean;
132
+ plaintext: Buffer;
133
+ };
134
+ export declare class StreamDecryptor {
135
+ readonly endpoint: ZroEndpoint;
136
+ readonly kid: string;
137
+ private readonly respKey;
138
+ private readonly respIv;
139
+ private buf;
140
+ private expectedSeq;
141
+ private dataFrames;
142
+ eofReceived: boolean;
143
+ finishReason: string | null;
144
+ constructor(params: {
145
+ endpoint: ZroEndpoint;
146
+ kid: string;
147
+ respKey: Buffer;
148
+ respIv: Buffer;
149
+ });
150
+ feedText(chunk: string): unknown[];
151
+ finish(): {
152
+ finishReason: string | null;
153
+ framesCount: number;
154
+ };
155
+ }
156
+ export declare function iterSseEvents(rawText: string): Generator<{
157
+ event: string | null;
158
+ data: string;
159
+ }>;
160
+ export declare function mergeUsage(base: Record<string, unknown> | null, update: Record<string, unknown> | undefined): Record<string, unknown> | null;
161
+ export declare class E2EESession {
162
+ readonly endpoint: ZroEndpoint;
163
+ readonly kid: string;
164
+ readonly enc: Buffer;
165
+ readonly respKey: Buffer;
166
+ readonly respIv: Buffer;
167
+ constructor(params: {
168
+ endpoint: ZroEndpoint;
169
+ kid: string;
170
+ enc: Buffer;
171
+ respKey: Buffer;
172
+ respIv: Buffer;
173
+ });
174
+ createStreamDecryptor(): StreamDecryptor;
175
+ decryptResponse(outerResponse: Record<string, unknown>): Record<string, unknown>;
176
+ decryptSseStream(sseText: string): DecryptedStreamResult;
177
+ }
178
+ export declare function encryptRequest(endpoint: ZroEndpoint, innerRequest: Record<string, unknown>, options: {
179
+ kid: string;
180
+ publicKey: Uint8Array | string;
181
+ outerReasoningEffort?: string;
182
+ outerMaxTokens?: number;
183
+ ikmE?: Uint8Array;
184
+ }): {
185
+ outerRequest: Record<string, unknown>;
186
+ session: E2EESession;
187
+ };