@agentproto/secrets 0.2.6 → 1.0.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/dist/{chunk-Q6K3AT3V.mjs → chunk-2FHFW2AU.mjs} +3 -3
- package/dist/{chunk-Q6K3AT3V.mjs.map → chunk-2FHFW2AU.mjs.map} +1 -1
- package/dist/chunk-3YRYO6LK.mjs +222 -0
- package/dist/chunk-3YRYO6LK.mjs.map +1 -0
- package/dist/chunk-432SC3XS.mjs +100 -0
- package/dist/chunk-432SC3XS.mjs.map +1 -0
- package/dist/chunk-5HUHYBPR.mjs +69 -0
- package/dist/chunk-5HUHYBPR.mjs.map +1 -0
- package/dist/{chunk-NLZ5HXGO.mjs → chunk-7V6U6DII.mjs} +4 -4
- package/dist/{chunk-NLZ5HXGO.mjs.map → chunk-7V6U6DII.mjs.map} +1 -1
- package/dist/chunk-JNTDSOZQ.mjs +623 -0
- package/dist/chunk-JNTDSOZQ.mjs.map +1 -0
- package/dist/chunk-NQX3KBPW.mjs +50 -0
- package/dist/chunk-NQX3KBPW.mjs.map +1 -0
- package/dist/chunk-PCFPJ47T.mjs +28 -0
- package/dist/chunk-PCFPJ47T.mjs.map +1 -0
- package/dist/cli.mjs +10 -7
- package/dist/cli.mjs.map +1 -1
- package/dist/core-CIn0-z-Y.d.ts +42 -0
- package/dist/core-D8zVNPDb.d.ts +58 -0
- package/dist/identity/index.d.ts +25 -46
- package/dist/identity/index.mjs +76 -1
- package/dist/identity/index.mjs.map +1 -1
- package/dist/pairing/browser.d.ts +18 -0
- package/dist/pairing/browser.mjs +6 -0
- package/dist/pairing/browser.mjs.map +1 -0
- package/dist/pairing/index.d.ts +45 -440
- package/dist/pairing/index.mjs +33 -465
- package/dist/pairing/index.mjs.map +1 -1
- package/dist/provision/index.mjs +5 -2
- package/dist/provision/recipe/index.mjs +6 -3
- package/dist/seal/index.d.ts +21 -31
- package/dist/seal/index.mjs +4 -1
- package/dist/types-B2ZfEhsU.d.ts +57 -0
- package/dist/webcrypto-BU57p0_g.d.ts +652 -0
- package/package.json +8 -2
- package/dist/chunk-2DL6W33G.mjs +0 -126
- package/dist/chunk-2DL6W33G.mjs.map +0 -1
- package/dist/chunk-MVHOJPML.mjs +0 -132
- package/dist/chunk-MVHOJPML.mjs.map +0 -1
|
@@ -0,0 +1,652 @@
|
|
|
1
|
+
import { C as CryptoProvider } from './types-B2ZfEhsU.js';
|
|
2
|
+
import { D as DaemonIdentity } from './core-D8zVNPDb.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @agentproto/secrets/pairing — the `pair/v2` session handshake
|
|
6
|
+
* (design: DESIGN §4).
|
|
7
|
+
*
|
|
8
|
+
* A Noise-flavoured, two-message handshake that lets a client and a daemon —
|
|
9
|
+
* connected only through an untrusted rendezvous that byte-splices their
|
|
10
|
+
* sockets — derive per-direction AEAD keys such that the rendezvous can neither
|
|
11
|
+
* read nor forge the session:
|
|
12
|
+
*
|
|
13
|
+
* ```
|
|
14
|
+
* client → daemon: e_pub // ephemeral X25519
|
|
15
|
+
* ct₀ = Seal(to = daemon_x25519,
|
|
16
|
+
* {clientPub: e_pub, clientName, auth})
|
|
17
|
+
* daemon → client: d_e_pub, sig = Ed25519(daemon_ed25519,
|
|
18
|
+
* transcript = sha256(e_pub ‖ ct₀ ‖ d_e_pub))
|
|
19
|
+
* both: K = HKDF-SHA256(ECDH(e, d_e) ‖ ECDH(e, daemon_x25519),
|
|
20
|
+
* salt = transcript, info = "agentproto/pair/v2")
|
|
21
|
+
* → K_c2d ‖ K_d2c (two AES-256-GCM keys)
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* Why this shape:
|
|
25
|
+
* - The client learned the daemon's static public keys out-of-band (the offer
|
|
26
|
+
* URL / QR). Verifying `sig` against the offer's Ed25519 key proves the peer
|
|
27
|
+
* is the daemon the human scanned, not a rendezvous impersonating it — MITM
|
|
28
|
+
* protection without a CA.
|
|
29
|
+
* - The daemon proves the client is authorised by opening `ct₀` (only the
|
|
30
|
+
* daemon's X25519 private key can) and checking the sealed `auth` token in
|
|
31
|
+
* constant time. `auth` is derived from the pairing secret under a label
|
|
32
|
+
* distinct from the broker ROUTE token (./derive.ts), so the one value the
|
|
33
|
+
* broker sees in clear — the route on the upgrade URL — never authenticates.
|
|
34
|
+
* pair/v1 sealed the route itself as the proof, which let a broker that
|
|
35
|
+
* knew the route (all of them) seal its own hello and pair; v1 is retired
|
|
36
|
+
* (see `respondToLegacyHandshake`).
|
|
37
|
+
* - `sig` covers the whole transcript and the transcript salts the key
|
|
38
|
+
* schedule, so any tampering with `e_pub`, `ct₀`, or `d_e_pub` in flight
|
|
39
|
+
* makes either the signature or the derived keys disagree — the session
|
|
40
|
+
* fails closed, never continuing with attacker-chosen material.
|
|
41
|
+
*
|
|
42
|
+
* The primitives come from a `CryptoProvider` (node:crypto or WebCrypto), so this
|
|
43
|
+
* one implementation runs in Node and in a browser; every entry point that does
|
|
44
|
+
* crypto is async and takes an optional trailing `crypto` argument.
|
|
45
|
+
*
|
|
46
|
+
* This module is deliberately **transport-agnostic**: it produces and consumes
|
|
47
|
+
* plain messages (`encode*`/`decode*` give byte arrays). The code that pumps
|
|
48
|
+
* those bytes over a `FrameSink` lives in `@agentproto/acp/tunnel`, which stays
|
|
49
|
+
* free of any dependency on this package — it receives only the derived keys.
|
|
50
|
+
* All crypto stays here so the acp layer never touches key material beyond the
|
|
51
|
+
* two symmetric session keys.
|
|
52
|
+
*/
|
|
53
|
+
|
|
54
|
+
/** Wire version of the handshake. Bumped if the message shape or key schedule
|
|
55
|
+
* changes; both sides refuse a version they don't recognise. v2: the sealed
|
|
56
|
+
* hello carries a dedicated auth token, never the broker route (./derive.ts). */
|
|
57
|
+
declare const PAIR_VERSION: 2;
|
|
58
|
+
/** The retired pair/v1 wire version. Recognised only to answer it with a
|
|
59
|
+
* re-pair notice (`respondToLegacyHandshake`); never served. */
|
|
60
|
+
declare const LEGACY_PAIR_VERSION: 1;
|
|
61
|
+
/** What a peer is told when it speaks the retired protocol: pairings made
|
|
62
|
+
* under pair/v1 can't be upgraded in place, so the fix is a fresh pairing. */
|
|
63
|
+
declare const PAIRING_PROTOCOL_OUTDATED_MESSAGE: string;
|
|
64
|
+
/** Stable, machine-readable failure codes. Every rejection maps to one of
|
|
65
|
+
* these so callers (and tests) branch on a code, not a message string. */
|
|
66
|
+
type PairingErrorCode = "malformed_hello" | "malformed_reply" | "invalid_key" | "unseal_failed" | "ephemeral_mismatch" | "offer_rejected" | "bad_signature" | "malformed_offer" | "offer_expired" | "pairing_protocol_outdated";
|
|
67
|
+
/** Raised for every handshake failure. Never carries key material or
|
|
68
|
+
* plaintext; the `code` is the contract, the message is for humans. */
|
|
69
|
+
declare class PairingError extends Error {
|
|
70
|
+
readonly code: PairingErrorCode;
|
|
71
|
+
constructor(code: PairingErrorCode, message: string);
|
|
72
|
+
}
|
|
73
|
+
/** Client → daemon. `ePub` is the client ephemeral X25519 public key (base64
|
|
74
|
+
* SPKI DER); `ct0` is the sealed hello payload (a `seal()` envelope string). */
|
|
75
|
+
interface PairingHello {
|
|
76
|
+
v: typeof PAIR_VERSION;
|
|
77
|
+
ePub: string;
|
|
78
|
+
ct0: string;
|
|
79
|
+
}
|
|
80
|
+
/** Daemon → client. `dePub` is the daemon ephemeral X25519 public key (base64
|
|
81
|
+
* SPKI DER); `sig` is the Ed25519 transcript signature (base64). */
|
|
82
|
+
interface PairingReply {
|
|
83
|
+
v: typeof PAIR_VERSION;
|
|
84
|
+
dePub: string;
|
|
85
|
+
sig: string;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* The result of a completed handshake, on either side. `sendKey`/`recvKey` are
|
|
89
|
+
* already role-adjusted (a client's `sendKey` is a daemon's `recvKey`), so the
|
|
90
|
+
* consumer — `wrapE2E` — never has to know which side it is.
|
|
91
|
+
*/
|
|
92
|
+
interface PairingSession {
|
|
93
|
+
/** AES-256-GCM key for frames THIS side sends. 32 bytes. */
|
|
94
|
+
sendKey: Uint8Array;
|
|
95
|
+
/** AES-256-GCM key for frames THIS side receives. 32 bytes. */
|
|
96
|
+
recvKey: Uint8Array;
|
|
97
|
+
/** Fingerprint of the peer's static identity (the daemon's X25519 key on the
|
|
98
|
+
* client side; in P1, the client's ephemeral key on the daemon side, since
|
|
99
|
+
* clients have no persisted identity until P2's pairings store). */
|
|
100
|
+
peerFingerprint: string;
|
|
101
|
+
/** `sha256(e_pub ‖ ct₀ ‖ d_e_pub)` — the exact transcript both sides bound
|
|
102
|
+
* to. A later phase channel-binds reconnect tokens to this. */
|
|
103
|
+
transcriptHash: Uint8Array;
|
|
104
|
+
/**
|
|
105
|
+
* The human-facing client label carried in the sealed hello. On the daemon
|
|
106
|
+
* side this is the name the peer chose (surfaced in `pairings.json` and on
|
|
107
|
+
* `pair accept`); on the client side it echoes the name this side supplied.
|
|
108
|
+
* Optional so pre-P2 callers constructing a session literal are unaffected —
|
|
109
|
+
* P2 (pairing-registry) reads it to name a persisted pairing without opening
|
|
110
|
+
* the seal a second time. Populated by both handshake entry points below.
|
|
111
|
+
*/
|
|
112
|
+
clientName?: string;
|
|
113
|
+
}
|
|
114
|
+
/** Everything the client learned from the offer URL, plus its chosen name. */
|
|
115
|
+
interface ClientHandshakeParams {
|
|
116
|
+
/** Daemon static X25519 public key (base64 SPKI DER) — the seal recipient
|
|
117
|
+
* and one ECDH input. From the offer's `pk`. */
|
|
118
|
+
daemonX25519Pub: string;
|
|
119
|
+
/** Daemon static Ed25519 public key (base64 SPKI DER) — verifies `sig`.
|
|
120
|
+
* From the offer's `sk`. */
|
|
121
|
+
daemonEd25519Pub: string;
|
|
122
|
+
/** Auth token sealed into the hello: `deriveOfferTokens(offer.secret).auth`
|
|
123
|
+
* on first contact, `deriveEpochAuthToken(pairRoot, epoch)` on reconnect.
|
|
124
|
+
* NEVER the route token the broker sees. */
|
|
125
|
+
authToken: string;
|
|
126
|
+
/** Human-facing client label the daemon displays on accept. */
|
|
127
|
+
clientName: string;
|
|
128
|
+
}
|
|
129
|
+
/** A started client handshake: send `hello`, then feed the daemon's reply to
|
|
130
|
+
* `complete` to derive the session. */
|
|
131
|
+
interface StartedClientHandshake {
|
|
132
|
+
hello: PairingHello;
|
|
133
|
+
/** Verify the daemon reply and derive the session. Rejects with
|
|
134
|
+
* `PairingError` on a bad signature, malformed reply, or invalid key —
|
|
135
|
+
* never resolves partial state. */
|
|
136
|
+
complete(reply: PairingReply): Promise<PairingSession>;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Begin a client handshake. Generates the client ephemeral keypair, seals the
|
|
140
|
+
* hello payload to the daemon's static key, and resolves to the `hello` to send
|
|
141
|
+
* plus a `complete` to run once the daemon replies.
|
|
142
|
+
*
|
|
143
|
+
* `crypto` selects the primitive implementation (default: WebCrypto here,
|
|
144
|
+
* `node:crypto` through the `@agentproto/secrets/pairing` Node entry). The
|
|
145
|
+
* provider is captured for `complete` as well.
|
|
146
|
+
*/
|
|
147
|
+
declare function startClientHandshake(params: ClientHandshakeParams, crypto?: CryptoProvider): Promise<StartedClientHandshake>;
|
|
148
|
+
/** What the daemon brings to the handshake: its identity, and a predicate that
|
|
149
|
+
* validates (and, for an offer, spends) the sealed auth token. */
|
|
150
|
+
interface DaemonHandshakeParams {
|
|
151
|
+
identity: DaemonIdentity;
|
|
152
|
+
/**
|
|
153
|
+
* Validate the presented auth token (constant time). Returning false
|
|
154
|
+
* rejects the handshake with `offer_rejected`. The daemon owns single-use +
|
|
155
|
+
* expiry policy here so this module never needs to know about the offer
|
|
156
|
+
* store — a stale, spent, or wrong token simply returns false. May be async.
|
|
157
|
+
*/
|
|
158
|
+
verifyAuthToken: (token: string) => boolean | Promise<boolean>;
|
|
159
|
+
}
|
|
160
|
+
/** A completed daemon handshake: send `reply`, keep `session`. */
|
|
161
|
+
interface DaemonHandshakeResult {
|
|
162
|
+
reply: PairingReply;
|
|
163
|
+
session: PairingSession;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Respond to a client hello. Opens the sealed payload with the daemon's X25519
|
|
167
|
+
* private key, checks the ephemeral-key binding and the auth token, signs the
|
|
168
|
+
* transcript, and derives the session. Rejects with `PairingError` on any
|
|
169
|
+
* failure — a tampered `ct₀`, a swapped `ePub`, a rejected token — before
|
|
170
|
+
* producing any reply, so a rejected client learns nothing and gets no session.
|
|
171
|
+
*/
|
|
172
|
+
declare function respondToHandshake(hello: PairingHello, params: DaemonHandshakeParams, crypto?: CryptoProvider): Promise<DaemonHandshakeResult>;
|
|
173
|
+
/**
|
|
174
|
+
* Answer a retired pair/v1 hello so its client can be TOLD to re-pair.
|
|
175
|
+
*
|
|
176
|
+
* An unmodified v1 client only surfaces what arrives inside a completed v1
|
|
177
|
+
* channel — anything short of that (a closed socket, a WS close reason, which
|
|
178
|
+
* its transport drops) reads as a timeout. So the daemon completes the v1 key
|
|
179
|
+
* schedule (`agentproto/pair/v1`) and hands back the reply + keys; the caller
|
|
180
|
+
* sends ONLY the outdated notice over them and closes.
|
|
181
|
+
*
|
|
182
|
+
* Deliberately performs NO authorisation: the v1 token proves nothing (it's
|
|
183
|
+
* the broker-visible route), so it isn't even read. The result must never be
|
|
184
|
+
* served — it is a one-way notice channel, and a party that gets one (the
|
|
185
|
+
* broker included) gains nothing but that notice. Rejects with `PairingError`
|
|
186
|
+
* for anything that isn't a well-formed v1 hello sealed to this daemon.
|
|
187
|
+
*/
|
|
188
|
+
declare function respondToLegacyHandshake(helloBytes: Uint8Array, identity: DaemonIdentity, crypto?: CryptoProvider): Promise<{
|
|
189
|
+
reply: Uint8Array;
|
|
190
|
+
keys: {
|
|
191
|
+
sendKey: Uint8Array;
|
|
192
|
+
recvKey: Uint8Array;
|
|
193
|
+
};
|
|
194
|
+
}>;
|
|
195
|
+
/** Serialize a handshake message to bytes for transport. */
|
|
196
|
+
declare function encodePairingMessage(message: PairingHello | PairingReply): Uint8Array;
|
|
197
|
+
/** Parse + validate a client hello from raw bytes. Truncated or malformed
|
|
198
|
+
* input throws `PairingError("malformed_hello")` — never a partial object. A
|
|
199
|
+
* retired pair/v1 hello throws `PairingError("pairing_protocol_outdated")` so
|
|
200
|
+
* the daemon can answer it with `respondToLegacyHandshake`. */
|
|
201
|
+
declare function decodePairingHello(bytes: Uint8Array): PairingHello;
|
|
202
|
+
/** Parse + validate a daemon reply from raw bytes. Truncated or malformed
|
|
203
|
+
* input throws `PairingError("malformed_reply")`. */
|
|
204
|
+
declare function decodePairingReply(bytes: Uint8Array): PairingReply;
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* The pairing offer URL codec (design: DESIGN §2).
|
|
208
|
+
*
|
|
209
|
+
* `agentproto pair offer` prints a single URL (also renderable as a QR):
|
|
210
|
+
*
|
|
211
|
+
* ```
|
|
212
|
+
* agentproto://pair?v=2
|
|
213
|
+
* &rv=<rendezvous ws/wss url> // where both sides meet
|
|
214
|
+
* &id=<fingerprint> // daemon identity fingerprint (32 hex)
|
|
215
|
+
* &pk=<b64url x25519 SPKI DER> // daemon static encryption key
|
|
216
|
+
* &sk=<b64url ed25519 SPKI DER> // daemon signing key
|
|
217
|
+
* &s=<one-time offer secret> // derives the route + auth tokens
|
|
218
|
+
* &exp=<unix seconds> // offer expiry
|
|
219
|
+
* ```
|
|
220
|
+
*
|
|
221
|
+
* The URL **is** the bootstrap secret. It carries the daemon's public keys, so
|
|
222
|
+
* a client that scans it can pin the daemon and detect a man-in-the-middle
|
|
223
|
+
* rendezvous (verifying the handshake signature against `sk`); and it carries a
|
|
224
|
+
* one-time, short-TTL secret so a stranger who never saw the URL can't pair.
|
|
225
|
+
* The secret itself never goes on the wire: both sides derive from it a ROUTE
|
|
226
|
+
* token for the broker and an AUTH token for the sealed hello
|
|
227
|
+
* (`deriveOfferTokens`, ./derive.ts), so the broker — which sees the route —
|
|
228
|
+
* can't pair.
|
|
229
|
+
*
|
|
230
|
+
* v=1 offers (pair/v1) used their `t` token as both route and proof; they are
|
|
231
|
+
* refused with `pairing_protocol_outdated`.
|
|
232
|
+
*
|
|
233
|
+
* This module is a **pure codec** — it validates structure and echoes bytes; it
|
|
234
|
+
* performs no I/O and no network calls, so it is safe to run on either side
|
|
235
|
+
* (the daemon builds it, the client parses it). It lives in `@agentproto/secrets`
|
|
236
|
+
* beside the handshake so both sides share one authority on the format.
|
|
237
|
+
*
|
|
238
|
+
* ## The web form (phone QR)
|
|
239
|
+
*
|
|
240
|
+
* A phone camera opens `https://` links, not `agentproto://`. For a browser
|
|
241
|
+
* client the same parameters ride in the **fragment** of a web URL:
|
|
242
|
+
*
|
|
243
|
+
* ```
|
|
244
|
+
* https://<fingerprint>.agentproto.cloud/pair#v=2&rv=…&id=…&pk=…&sk=…&s=…&exp=…
|
|
245
|
+
* ```
|
|
246
|
+
*
|
|
247
|
+
* i.e. the query string of the `agentproto://` URL, verbatim, after the `#`.
|
|
248
|
+
* A fragment is never sent to a server (not in the request line, not in
|
|
249
|
+
* `Referer`), so the page host never sees the token. `encodeOfferWebUrl` builds
|
|
250
|
+
* it; `parseOfferUrl` accepts both forms and validates them identically.
|
|
251
|
+
*
|
|
252
|
+
* Key material travels **base64url** in the URL (no `+`/`/`/`=` to percent-
|
|
253
|
+
* escape). The handshake, however, speaks standard base64 SPKI DER, so
|
|
254
|
+
* `parseOfferUrl` returns `daemonX25519Pub`/`daemonEd25519Pub` already converted
|
|
255
|
+
* back to standard base64 — feed them straight into `startClientHandshake`.
|
|
256
|
+
*/
|
|
257
|
+
|
|
258
|
+
/** URL scheme + host for offer URLs. */
|
|
259
|
+
declare const OFFER_URL_SCHEME: "agentproto:";
|
|
260
|
+
declare const OFFER_URL_HOST: "pair";
|
|
261
|
+
/** Offer-format version. Bumped if the param set changes. v2: `s` (a secret
|
|
262
|
+
* that never goes on the wire) replaces v1's `t` (route-and-proof). */
|
|
263
|
+
declare const OFFER_VERSION: 2;
|
|
264
|
+
/** A single shared-origin page for the web form of an offer: every daemon's
|
|
265
|
+
* pairing on one origin (AIP-59 §5.8 fallback, which exposes each pairing to
|
|
266
|
+
* every other paired daemon's UI). Not the default: select it explicitly with
|
|
267
|
+
* `pairing.pairPage` / `--pair-page`. */
|
|
268
|
+
declare const PAIR_WEB_URL: "https://cli.agentproto.sh/pair";
|
|
269
|
+
/** Placeholder for the daemon fingerprint in a pair-page template. Allowed in
|
|
270
|
+
* the hostname only. */
|
|
271
|
+
declare const PAIR_PAGE_FP_PLACEHOLDER: "{fp}";
|
|
272
|
+
/**
|
|
273
|
+
* The default pair page: one origin per daemon
|
|
274
|
+
* (`<fingerprint>.agentproto.cloud`, AIP-59 §5.8), so each daemon's page,
|
|
275
|
+
* service worker and stored credential are isolated from every other
|
|
276
|
+
* pairing's by the browser's same-origin policy. Override it with
|
|
277
|
+
* `pairing.pairPage` / `--pair-page` (a self-hosted page, or a plain URL).
|
|
278
|
+
*/
|
|
279
|
+
declare const PAIR_WEB_URL_TEMPLATE_CLOUD: "https://{fp}.agentproto.cloud/pair";
|
|
280
|
+
/** The pair page used when none is configured. */
|
|
281
|
+
declare const DEFAULT_PAIR_PAGE: "https://{fp}.agentproto.cloud/pair";
|
|
282
|
+
/**
|
|
283
|
+
* A parsed, structurally-valid pairing offer. `daemonX25519Pub` /
|
|
284
|
+
* `daemonEd25519Pub` are standard-base64 SPKI DER (handshake-ready). `secret` is
|
|
285
|
+
* the opaque one-time offer secret verbatim — derive the route + auth tokens
|
|
286
|
+
* from it with `deriveOfferTokens`; never send it anywhere. `exp` is unix
|
|
287
|
+
* **seconds**.
|
|
288
|
+
*/
|
|
289
|
+
interface PairingOffer {
|
|
290
|
+
v: typeof OFFER_VERSION;
|
|
291
|
+
/** Rendezvous endpoint both sides dial (ws:// or wss://). */
|
|
292
|
+
rendezvousUrl: string;
|
|
293
|
+
/** Daemon identity fingerprint (32 lowercase hex) — must equal fingerprint(pk). */
|
|
294
|
+
fingerprint: string;
|
|
295
|
+
/** Daemon static X25519 public key, standard base64 SPKI DER. */
|
|
296
|
+
daemonX25519Pub: string;
|
|
297
|
+
/** Daemon static Ed25519 public key, standard base64 SPKI DER. */
|
|
298
|
+
daemonEd25519Pub: string;
|
|
299
|
+
/** One-time offer secret — derives the broker route and the sealed auth
|
|
300
|
+
* token (`deriveOfferTokens`). Never sent on its own. */
|
|
301
|
+
secret: string;
|
|
302
|
+
/** Offer expiry, unix seconds. */
|
|
303
|
+
exp: number;
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Build the offer URL from an offer. The public keys come in as standard
|
|
307
|
+
* base64 (the shape the identity file + handshake use) and are emitted as
|
|
308
|
+
* base64url. `secret` is emitted verbatim (callers mint it as base64url).
|
|
309
|
+
*/
|
|
310
|
+
declare function encodeOfferUrl(offer: PairingOffer): string;
|
|
311
|
+
/**
|
|
312
|
+
* Resolve a pair-page setting for one daemon. `templateOrUrl` is either a plain
|
|
313
|
+
* http(s) URL (returned unchanged) or a template with `{fp}` in its HOSTNAME,
|
|
314
|
+
* e.g. `https://{fp}.agentproto.cloud/pair`, where `{fp}` becomes the daemon
|
|
315
|
+
* identity `fingerprint` (lowercase hex, which must be a valid DNS label).
|
|
316
|
+
* Throws `PairingError("malformed_offer")` for a template with `{fp}` outside
|
|
317
|
+
* the hostname (userinfo, port, path, query, fragment), for any other brace
|
|
318
|
+
* left in the URL, for a non-http(s) URL, or for a URL with a fragment (the
|
|
319
|
+
* offer goes there).
|
|
320
|
+
*/
|
|
321
|
+
declare function resolvePairPageUrl(templateOrUrl: string, fingerprint: string): string;
|
|
322
|
+
/**
|
|
323
|
+
* The `host` (hostname[:port]) a pair page for `fingerprint` must be served
|
|
324
|
+
* from under `templateOrUrl`. The page compares it with its own
|
|
325
|
+
* `location.host` to refuse an offer meant for another daemon's origin.
|
|
326
|
+
*/
|
|
327
|
+
declare function expectedPairHost(templateOrUrl: string, fingerprint: string): string;
|
|
328
|
+
/**
|
|
329
|
+
* Re-wrap an `agentproto://pair?…` offer URL as its web form
|
|
330
|
+
* `<pageUrl>#<query>` (see "The web form" above). The parameters are carried
|
|
331
|
+
* byte-for-byte. `pageUrl` is a plain http(s) URL without a fragment, or a
|
|
332
|
+
* `{fp}` template (see `resolvePairPageUrl`) filled in with the offer's daemon
|
|
333
|
+
* fingerprint (`id`).
|
|
334
|
+
*/
|
|
335
|
+
declare function encodeOfferWebUrl(offerUrl: string, pageUrl?: string): string;
|
|
336
|
+
interface ParseOfferOptions {
|
|
337
|
+
/**
|
|
338
|
+
* When set, the parser rejects an offer whose `exp` is at or before this
|
|
339
|
+
* instant (unix **milliseconds**) with `PairingError("offer_expired")`. Omit
|
|
340
|
+
* to parse structure only and let the caller decide when to check expiry
|
|
341
|
+
* (the daemon's offer store is the authoritative single-use + expiry gate).
|
|
342
|
+
*/
|
|
343
|
+
now?: number;
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* Parse + strictly validate an offer URL. Rejects with `PairingError` — never
|
|
347
|
+
* resolves a partial object — on any structural problem:
|
|
348
|
+
*
|
|
349
|
+
* - `pairing_protocol_outdated`: a v=1 (pair/v1) offer from an older daemon.
|
|
350
|
+
* - `malformed_offer`: wrong scheme/host, unknown version, missing/blank
|
|
351
|
+
* params, non-base64url keys/token, non-integer `exp`, or a `fingerprint`
|
|
352
|
+
* that does not match `fingerprint(pk)` (tamper detection: a rendezvous or
|
|
353
|
+
* link-mangler that swaps the daemon key can't keep `id` consistent).
|
|
354
|
+
* - `offer_expired`: only when `opts.now` is supplied and `exp` has passed.
|
|
355
|
+
*
|
|
356
|
+
* Accepts the `agentproto://pair?…` form and the web form
|
|
357
|
+
* (`https://…/pair#<query>`, see `encodeOfferWebUrl`).
|
|
358
|
+
*
|
|
359
|
+
* Async because the `id` ↔ `fingerprint(pk)` check hashes the key, and
|
|
360
|
+
* WebCrypto's SHA-256 is async; `crypto` selects the provider.
|
|
361
|
+
*/
|
|
362
|
+
declare function parseOfferUrl(url: string, opts?: ParseOfferOptions, crypto?: CryptoProvider): Promise<PairingOffer>;
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* The hosted rendezvous broker — the meeting point `pair offer` defaults to
|
|
366
|
+
* when neither `--rendezvous` nor `pairing.rendezvous` is configured.
|
|
367
|
+
*
|
|
368
|
+
* ## Why it lives here
|
|
369
|
+
*
|
|
370
|
+
* It sits in `@agentproto/secrets/pairing`, beside `offer-url.ts` — the codec
|
|
371
|
+
* that bakes this endpoint into every offer's `rv=` param. The daemon runtime
|
|
372
|
+
* already depends on `@agentproto/secrets`, so it reaches this constant without
|
|
373
|
+
* `@agentproto/runtime` gaining a dependency on `@agentproto/rendezvous`. That
|
|
374
|
+
* matters: the broker package is a deliberately lean, standalone container (its
|
|
375
|
+
* only dep is `ws`), and nothing on the daemon/CLI side should have to pull it
|
|
376
|
+
* in just to learn the default endpoint's URL.
|
|
377
|
+
*
|
|
378
|
+
* ## What the broker sees
|
|
379
|
+
*
|
|
380
|
+
* The hosted broker only ever relays **ciphertext** — it learns the route
|
|
381
|
+
* token (opaque; it authenticates nothing — see ./derive.ts), the peers' IPs,
|
|
382
|
+
* ciphertext sizes, and timing; never plaintext or an auth token, and it
|
|
383
|
+
* cannot pair, inject, or alter frames (the pairing handshake is transcript-bound and
|
|
384
|
+
* every frame is AEAD-sealed). See `docs/cli/concepts/pairing.md` for the full
|
|
385
|
+
* threat model.
|
|
386
|
+
*
|
|
387
|
+
* ## Pointing elsewhere / self-hosting
|
|
388
|
+
*
|
|
389
|
+
* The broker is self-hostable (`agentproto rendezvous serve`). To route through
|
|
390
|
+
* your own instead of the hosted default, set `pairing.rendezvous` in
|
|
391
|
+
* `config.json` (or pass `--rendezvous` for a single offer). To disable the
|
|
392
|
+
* default entirely — so a daemon never reaches the hosted broker unless an
|
|
393
|
+
* endpoint is named explicitly — set `pairing.rendezvous: ""` (an explicit
|
|
394
|
+
* opt-out; `pair offer` then requires `--rendezvous`).
|
|
395
|
+
*/
|
|
396
|
+
declare const HOSTED_RENDEZVOUS_URL: "wss://rdv.agentproto.sh/v1";
|
|
397
|
+
|
|
398
|
+
/**
|
|
399
|
+
* Pairing-derived key material (design: DESIGN §3/§4).
|
|
400
|
+
*
|
|
401
|
+
* All derivations are HKDF-SHA256 over secret material the untrusted
|
|
402
|
+
* rendezvous never sees, so it can't reproduce any of them:
|
|
403
|
+
*
|
|
404
|
+
* - **pair root** `K_pair = HKDF(session, "pair-root")`: the long-term shared
|
|
405
|
+
* secret persisted by both sides (daemon `pairings.json`, client
|
|
406
|
+
* `pair-credentials.json`). Everything a reconnect needs derives from it.
|
|
407
|
+
* - **route / auth split** (pair/v2): every pairing secret — the offer secret
|
|
408
|
+
* from the offer URL, and the pair root per epoch — yields TWO one-way
|
|
409
|
+
* outputs under distinct labels:
|
|
410
|
+
* - a **route token**, the ONLY value that goes on the broker upgrade URL
|
|
411
|
+
* (`?side=…&t=<route>`). It is an opaque meeting-point name; it
|
|
412
|
+
* authenticates nothing.
|
|
413
|
+
* - an **auth token**, sent ONLY inside the sealed hello (opened by the
|
|
414
|
+
* daemon's X25519 key alone) and checked by the daemon in constant time.
|
|
415
|
+
* HKDF is one-way, so a broker that logs every route it ever sees still
|
|
416
|
+
* can't compute an auth token. pair/v1 used a single value for both jobs,
|
|
417
|
+
* which let the broker pair as a client (offer) or replay a reconnect.
|
|
418
|
+
*
|
|
419
|
+
* Labels (salt ‖ info), all HKDF-SHA256:
|
|
420
|
+
*
|
|
421
|
+
* | output | IKM | salt | info | len |
|
|
422
|
+
* | ----------------- | ---------------------- | --------------------------- | ------------------------------ | --- |
|
|
423
|
+
* | pair root | sorted session keys | transcript hash | `agentproto/pair-root` | 32 |
|
|
424
|
+
* | offer route | UTF-8 of offer secret | `agentproto/pair-offer` | `agentproto/rv-route` | 16 |
|
|
425
|
+
* | offer auth | UTF-8 of offer secret | `agentproto/pair-offer` | `agentproto/rv-auth` | 32 |
|
|
426
|
+
* | epoch route `e` | pair root (raw bytes) | `agentproto/rv-route-salt` | `agentproto/rv-route` ‖ u64(e) | 16 |
|
|
427
|
+
* | epoch auth `e` | pair root (raw bytes) | `agentproto/rv-auth-salt` | `agentproto/rv-auth` ‖ u64(e) | 32 |
|
|
428
|
+
*
|
|
429
|
+
* Tokens are base64url: a 16-byte route is 22 chars (the broker's width), a
|
|
430
|
+
* 32-byte auth is 43. The epoch route is byte-identical to pair/v1's epoch
|
|
431
|
+
* token on purpose: a legacy (v1) client still meets the daemon at the same
|
|
432
|
+
* place, so the daemon can tell it to re-pair instead of leaving it to time out.
|
|
433
|
+
* That leaks nothing new — the route was always public to the broker.
|
|
434
|
+
*
|
|
435
|
+
* ## Why the pair root is derived order-independently
|
|
436
|
+
*
|
|
437
|
+
* A `PairingSession` exposes `sendKey`/`recvKey`, which are **role-swapped**
|
|
438
|
+
* between the two peers (the client's `sendKey` is the daemon's `recvKey`). To
|
|
439
|
+
* get an identical root on both sides without threading a "which side am I"
|
|
440
|
+
* flag, we sort the two keys byte-wise before mixing them: the *set* {sendKey,
|
|
441
|
+
* recvKey} is identical on both sides, so the sorted concatenation — and thus
|
|
442
|
+
* the HKDF output — is identical. Both keys are secret ECDH-derived material the
|
|
443
|
+
* rendezvous never sees, so the root (and every epoch token) stays secret.
|
|
444
|
+
*
|
|
445
|
+
* Every derivation is async (WebCrypto HKDF is) and takes an optional trailing
|
|
446
|
+
* `crypto` provider.
|
|
447
|
+
*
|
|
448
|
+
* ## The pair root as a non-extractable key
|
|
449
|
+
*
|
|
450
|
+
* The epoch derivations accept the pair root either as base64 or as a
|
|
451
|
+
* **non-extractable** WebCrypto HKDF `CryptoKey` (`importPairRootKey`). A
|
|
452
|
+
* browser client can keep that key in IndexedDB, and script can derive tokens
|
|
453
|
+
* with it but never read the root back out. The salts, infos and lengths are
|
|
454
|
+
* the same either way, so the tokens are byte-identical.
|
|
455
|
+
*/
|
|
456
|
+
|
|
457
|
+
/**
|
|
458
|
+
* Derive the long-term pair root from a completed handshake session. Returns
|
|
459
|
+
* standard base64 (persisted in `pairings.json` / `credentials.json`). Both
|
|
460
|
+
* peers, despite role-swapped direction keys, produce the identical root.
|
|
461
|
+
*/
|
|
462
|
+
declare function derivePairRoot(session: Pick<PairingSession, "sendKey" | "recvKey" | "transcriptHash">, crypto?: CryptoProvider): Promise<string>;
|
|
463
|
+
/** The current pairing epoch — the UTC day number. Injectable `now` (ms) for
|
|
464
|
+
* tests; defaults to the wall clock. */
|
|
465
|
+
declare function currentEpoch(now?: number): number;
|
|
466
|
+
/** A route token (broker URL only) and its paired auth token (sealed hello
|
|
467
|
+
* only), both base64url. */
|
|
468
|
+
interface RouteAuthTokens {
|
|
469
|
+
route: string;
|
|
470
|
+
auth: string;
|
|
471
|
+
}
|
|
472
|
+
/**
|
|
473
|
+
* Import a base64 pair root as a **non-extractable** WebCrypto HKDF key (see
|
|
474
|
+
* "The pair root as a non-extractable key" above). IndexedDB stores it by
|
|
475
|
+
* structured clone, so it stays non-extractable at rest.
|
|
476
|
+
*/
|
|
477
|
+
declare function importPairRootKey(pairRoot: string): Promise<CryptoKey>;
|
|
478
|
+
/**
|
|
479
|
+
* Derive the rendezvous ROUTE token for a pairing at a given epoch:
|
|
480
|
+
* `HKDF(pairRoot, salt "agentproto/rv-route-salt", "agentproto/rv-route" ‖ epoch)`.
|
|
481
|
+
* base64url, so it drops straight into a `?t=` upgrade param. This is the only
|
|
482
|
+
* reconnect value the broker sees; it does not authenticate. Deterministic —
|
|
483
|
+
* both sides derive the same token for the same `(pairRoot, epoch)`.
|
|
484
|
+
*/
|
|
485
|
+
declare function deriveEpochRoutingToken(pairRoot: string | CryptoKey, epoch: number, crypto?: CryptoProvider): Promise<string>;
|
|
486
|
+
/**
|
|
487
|
+
* Derive the reconnect AUTH token for a pairing at a given epoch:
|
|
488
|
+
* `HKDF(pairRoot, salt "agentproto/rv-auth-salt", "agentproto/rv-auth" ‖ epoch)`.
|
|
489
|
+
* Carried only inside the sealed hello; the daemon compares it in constant
|
|
490
|
+
* time. Never put it on a URL.
|
|
491
|
+
*/
|
|
492
|
+
declare function deriveEpochAuthToken(pairRoot: string | CryptoKey, epoch: number, crypto?: CryptoProvider): Promise<string>;
|
|
493
|
+
/** Route + auth tokens for a pairing at one epoch. */
|
|
494
|
+
declare function deriveEpochTokens(pairRoot: string | CryptoKey, epoch: number, crypto?: CryptoProvider): Promise<RouteAuthTokens>;
|
|
495
|
+
/**
|
|
496
|
+
* Derive the route + auth tokens for a pairing offer from its secret (the
|
|
497
|
+
* offer URL's `s`): the daemon parks on — and the client dials — `route`; the
|
|
498
|
+
* client seals `auth` into its hello. The secret itself never leaves the offer
|
|
499
|
+
* URL.
|
|
500
|
+
*/
|
|
501
|
+
declare function deriveOfferTokens(offerSecret: string, crypto?: CryptoProvider): Promise<RouteAuthTokens>;
|
|
502
|
+
/**
|
|
503
|
+
* The route + auth tokens a peer should accept/dial to bridge clock skew
|
|
504
|
+
* around a day boundary: the current epoch and the previous one (design:
|
|
505
|
+
* PLAN "accept current and previous epoch"). The daemon parks on both routes
|
|
506
|
+
* so a client whose clock sits on either side of midnight still finds it; the
|
|
507
|
+
* client likewise tries both when reconnecting.
|
|
508
|
+
*/
|
|
509
|
+
declare function epochRoutingTokens(pairRoot: string | CryptoKey, now?: number, crypto?: CryptoProvider): Promise<({
|
|
510
|
+
epoch: number;
|
|
511
|
+
} & RouteAuthTokens)[]>;
|
|
512
|
+
|
|
513
|
+
/**
|
|
514
|
+
* @agentproto/secrets/pairing — the `tunnel-e2e/v1` handshake.
|
|
515
|
+
*
|
|
516
|
+
* The reverse tunnel (`agentproto serve --connect <host>`) is a DIFFERENT trust
|
|
517
|
+
* relationship from the client↔daemon pairing in ./handshake.ts:
|
|
518
|
+
*
|
|
519
|
+
* - There is no offer URL, no QR, no PKI. The daemon and the host already
|
|
520
|
+
* share one pre-provisioned secret — the `apt_` **tunnel token** the daemon
|
|
521
|
+
* presents as its WS bearer. Both ends hold it before the socket opens.
|
|
522
|
+
* - So instead of authenticating with a static-key seal + Ed25519 signature,
|
|
523
|
+
* both ends authenticate by proving knowledge of that shared token, and get
|
|
524
|
+
* forward secrecy from a fresh ephemeral X25519 exchange.
|
|
525
|
+
*
|
|
526
|
+
* ```
|
|
527
|
+
* daemon → host: offer = { ePub_d, mac_d = HMAC(K_auth, "offer/v1" ‖ ePub_d) }
|
|
528
|
+
* host → daemon: accept = { ePub_h, mac_h = HMAC(K_auth, "accept/v1" ‖ ePub_d ‖ ePub_h) }
|
|
529
|
+
* both: K_auth = HKDF(ikm = utf8(token),
|
|
530
|
+
* salt = sha256(token), info = "…/auth/v1") // token-only MAC key
|
|
531
|
+
* K = HKDF(ikm = ECDH(e_d, e_h),
|
|
532
|
+
* salt = sha256(token), info = "…/v1") // → K_d2h ‖ K_h2d
|
|
533
|
+
* ```
|
|
534
|
+
*
|
|
535
|
+
* Why this shape:
|
|
536
|
+
* - **Mutual authentication at handshake time.** `mac_d` binds the daemon
|
|
537
|
+
* ephemeral to the token; the host verifies it and refuses (`bad_auth`) if
|
|
538
|
+
* the token differs — no partial session, no plaintext, before the daemon's
|
|
539
|
+
* first byte. `mac_h` binds BOTH ephemerals to the token; the daemon
|
|
540
|
+
* verifies it symmetrically. A man-in-the-middle without the token cannot
|
|
541
|
+
* forge either MAC for its own ephemeral, and cannot reuse a recorded one
|
|
542
|
+
* (it lacks the matching private key to finish the ECDH). So the confirm is
|
|
543
|
+
* a **transcript/confirm step that fails a token mismatch AT handshake time,
|
|
544
|
+
* not mid-stream** — exactly what a wrong `tunnel.token` on one side needs.
|
|
545
|
+
* - **Forward secrecy.** The session keys mix ONLY the ephemeral ECDH output;
|
|
546
|
+
* the long-term token merely salts them. A later token compromise can't
|
|
547
|
+
* decrypt a recorded past session.
|
|
548
|
+
* - **Salt-binds the token.** Because `sha256(token)` salts the session-key
|
|
549
|
+
* HKDF too, even if the MACs were somehow bypassed the derived AEAD keys
|
|
550
|
+
* still disagree under a mismatched token → the channel fails closed.
|
|
551
|
+
*
|
|
552
|
+
* Like ./handshake.ts, the primitives come from a `CryptoProvider` (node:crypto
|
|
553
|
+
* or WebCrypto) and every crypto entry point is async with an optional trailing
|
|
554
|
+
* `crypto` argument. Like ./handshake.ts, this module is also deliberately **transport-agnostic**: it
|
|
555
|
+
* produces and consumes plain byte messages (`encode*`/`decode*`). The code that
|
|
556
|
+
* pumps those bytes over a `FrameSink` and wraps the channel lives in
|
|
557
|
+
* `@agentproto/acp/tunnel`, which never depends on this package — it receives
|
|
558
|
+
* only the two derived symmetric keys. Everything crypto stays here.
|
|
559
|
+
*/
|
|
560
|
+
|
|
561
|
+
/** Wire version. Bumped if the message shape or key schedule changes; both
|
|
562
|
+
* sides refuse a version they don't recognise. */
|
|
563
|
+
declare const TUNNEL_E2E_VERSION: 1;
|
|
564
|
+
/** Stable, machine-readable failure codes. Every rejection maps to one of these
|
|
565
|
+
* so callers (and tests) branch on a code, not a message string. */
|
|
566
|
+
type TunnelHandshakeErrorCode = "malformed_offer" | "malformed_accept" | "invalid_key" | "bad_auth" | "unsupported_version";
|
|
567
|
+
/** Raised for every tunnel-handshake failure. Never carries key material or the
|
|
568
|
+
* token; the `code` is the contract, the message is for humans. */
|
|
569
|
+
declare class TunnelHandshakeError extends Error {
|
|
570
|
+
readonly code: TunnelHandshakeErrorCode;
|
|
571
|
+
constructor(code: TunnelHandshakeErrorCode, message: string);
|
|
572
|
+
}
|
|
573
|
+
/** Daemon → host. `ePub` is the daemon ephemeral X25519 public key (base64 SPKI
|
|
574
|
+
* DER); `mac` authenticates it under the shared tunnel token. */
|
|
575
|
+
interface TunnelOffer {
|
|
576
|
+
v: typeof TUNNEL_E2E_VERSION;
|
|
577
|
+
ePub: string;
|
|
578
|
+
mac: string;
|
|
579
|
+
}
|
|
580
|
+
/** Host → daemon. `ePub` is the host ephemeral X25519 public key (base64 SPKI
|
|
581
|
+
* DER); `mac` authenticates both ephemerals under the shared tunnel token. */
|
|
582
|
+
interface TunnelAccept {
|
|
583
|
+
v: typeof TUNNEL_E2E_VERSION;
|
|
584
|
+
ePub: string;
|
|
585
|
+
mac: string;
|
|
586
|
+
}
|
|
587
|
+
/**
|
|
588
|
+
* A completed tunnel handshake, on either side. `sendKey`/`recvKey` are already
|
|
589
|
+
* role-adjusted (the daemon's `sendKey` is the host's `recvKey`), so the
|
|
590
|
+
* consumer — `wrapE2E` — never has to know which side it is.
|
|
591
|
+
*/
|
|
592
|
+
interface TunnelE2ESession {
|
|
593
|
+
/** AES-256-GCM key for frames THIS side sends. 32 bytes. */
|
|
594
|
+
sendKey: Uint8Array;
|
|
595
|
+
/** AES-256-GCM key for frames THIS side receives. 32 bytes. */
|
|
596
|
+
recvKey: Uint8Array;
|
|
597
|
+
/** `sha256(SESSION_INFO ‖ ePub_d ‖ ePub_h)` — the exact transcript both sides
|
|
598
|
+
* bound to. Exposed for parity with `PairingSession`; not required to use. */
|
|
599
|
+
transcriptHash: Uint8Array;
|
|
600
|
+
}
|
|
601
|
+
/** A started daemon handshake: send `offer`, then feed the host's `accept` to
|
|
602
|
+
* `complete` to derive the session. */
|
|
603
|
+
interface StartedTunnelHandshake {
|
|
604
|
+
offer: TunnelOffer;
|
|
605
|
+
/**
|
|
606
|
+
* Verify the host accept and derive the session. Throws `TunnelHandshakeError`
|
|
607
|
+
* on a bad MAC (`bad_auth` — the host holds a different token), a malformed
|
|
608
|
+
* accept, or an invalid key — never returns partial state.
|
|
609
|
+
*/
|
|
610
|
+
complete(accept: TunnelAccept): Promise<TunnelE2ESession>;
|
|
611
|
+
}
|
|
612
|
+
/**
|
|
613
|
+
* Begin the daemon (initiator) side. Generates the daemon ephemeral keypair,
|
|
614
|
+
* MACs it under the token, and resolves to the `offer` to send plus a
|
|
615
|
+
* `complete` to run once the host replies with its `accept`. `crypto` selects
|
|
616
|
+
* the primitive implementation (captured for `complete` too).
|
|
617
|
+
*/
|
|
618
|
+
declare function startTunnelHandshake(token: string, crypto?: CryptoProvider): Promise<StartedTunnelHandshake>;
|
|
619
|
+
/** A completed host handshake: send `accept`, keep `session`. */
|
|
620
|
+
interface TunnelHandshakeResult {
|
|
621
|
+
accept: TunnelAccept;
|
|
622
|
+
session: TunnelE2ESession;
|
|
623
|
+
}
|
|
624
|
+
/**
|
|
625
|
+
* Respond to a daemon offer (host side). Verifies the offer MAC under the shared
|
|
626
|
+
* token, generates the host ephemeral, MACs both ephemerals, and derives the
|
|
627
|
+
* session. Rejects with `TunnelHandshakeError` on a bad MAC (`bad_auth`),
|
|
628
|
+
* malformed offer, or invalid key BEFORE producing any accept — so a mismatched
|
|
629
|
+
* token yields no session and no reply, failing closed at handshake time.
|
|
630
|
+
*/
|
|
631
|
+
declare function respondToTunnelHandshake(offer: TunnelOffer, token: string, crypto?: CryptoProvider): Promise<TunnelHandshakeResult>;
|
|
632
|
+
/** Serialize a handshake message to bytes for transport. */
|
|
633
|
+
declare function encodeTunnelMessage(message: TunnelOffer | TunnelAccept): Uint8Array;
|
|
634
|
+
/** Parse + validate a daemon offer from raw bytes. Truncated or malformed input
|
|
635
|
+
* throws `TunnelHandshakeError("malformed_offer")` — never a partial object. */
|
|
636
|
+
declare function decodeTunnelOffer(bytes: Uint8Array): TunnelOffer;
|
|
637
|
+
/** Parse + validate a host accept from raw bytes. Truncated or malformed input
|
|
638
|
+
* throws `TunnelHandshakeError("malformed_accept")`. */
|
|
639
|
+
declare function decodeTunnelAccept(bytes: Uint8Array): TunnelAccept;
|
|
640
|
+
|
|
641
|
+
/**
|
|
642
|
+
* `CryptoProvider` over WebCrypto (`globalThis.crypto.subtle`) — the default in
|
|
643
|
+
* the browser-safe entry. Browser-safe: no `node:` import, no `Buffer`.
|
|
644
|
+
*
|
|
645
|
+
* Needs X25519 + Ed25519 in `SubtleCrypto` (Chrome 133+, Safari 17+, Firefox
|
|
646
|
+
* 130+, Node ≥ 20). The subtle instance is resolved lazily, per call, so merely
|
|
647
|
+
* importing this module never throws in an environment without WebCrypto.
|
|
648
|
+
*/
|
|
649
|
+
|
|
650
|
+
declare const webCryptoProvider: CryptoProvider;
|
|
651
|
+
|
|
652
|
+
export { startClientHandshake as $, decodeTunnelOffer as A, deriveEpochAuthToken as B, type ClientHandshakeParams as C, DEFAULT_PAIR_PAGE as D, deriveEpochRoutingToken as E, deriveEpochTokens as F, deriveOfferTokens as G, HOSTED_RENDEZVOUS_URL as H, derivePairRoot as I, encodeOfferUrl as J, encodeOfferWebUrl as K, LEGACY_PAIR_VERSION as L, encodePairingMessage as M, encodeTunnelMessage as N, OFFER_URL_HOST as O, PAIRING_PROTOCOL_OUTDATED_MESSAGE as P, epochRoutingTokens as Q, type RouteAuthTokens as R, type StartedClientHandshake as S, TUNNEL_E2E_VERSION as T, expectedPairHost as U, importPairRootKey as V, parseOfferUrl as W, resolvePairPageUrl as X, respondToHandshake as Y, respondToLegacyHandshake as Z, respondToTunnelHandshake as _, type DaemonHandshakeParams as a, startTunnelHandshake as a0, webCryptoProvider as a1, type DaemonHandshakeResult as b, OFFER_URL_SCHEME as c, OFFER_VERSION as d, PAIR_PAGE_FP_PLACEHOLDER as e, PAIR_VERSION as f, PAIR_WEB_URL as g, PAIR_WEB_URL_TEMPLATE_CLOUD as h, PairingError as i, type PairingErrorCode as j, type PairingHello as k, type PairingOffer as l, type PairingReply as m, type PairingSession as n, type ParseOfferOptions as o, type StartedTunnelHandshake as p, type TunnelAccept as q, type TunnelE2ESession as r, TunnelHandshakeError as s, type TunnelHandshakeErrorCode as t, type TunnelHandshakeResult as u, type TunnelOffer as v, currentEpoch as w, decodePairingHello as x, decodePairingReply as y, decodeTunnelAccept as z };
|