@arcblock/did-noise 0.0.0-stage → 1.30.25

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 (44) hide show
  1. package/LICENSE +13 -0
  2. package/esm/chacha20poly1305.d.mts +18 -0
  3. package/esm/chacha20poly1305.mjs +152 -0
  4. package/esm/chain-node-mesh.d.mts +79 -0
  5. package/esm/chain-node-mesh.mjs +187 -0
  6. package/esm/http-transport.d.mts +72 -0
  7. package/esm/http-transport.mjs +216 -0
  8. package/esm/index.d.mts +6 -0
  9. package/esm/index.mjs +7 -0
  10. package/esm/mesh-tunnel.d.mts +165 -0
  11. package/esm/mesh-tunnel.mjs +350 -0
  12. package/esm/noise-session.d.mts +157 -0
  13. package/esm/noise-session.mjs +491 -0
  14. package/lib/_vendor/@noble/curves/LICENSE +21 -0
  15. package/lib/_vendor/@noble/curves/abstract/curve.cjs +338 -0
  16. package/lib/_vendor/@noble/curves/abstract/edwards.cjs +542 -0
  17. package/lib/_vendor/@noble/curves/abstract/hash-to-curve.cjs +72 -0
  18. package/lib/_vendor/@noble/curves/abstract/modular.cjs +557 -0
  19. package/lib/_vendor/@noble/curves/abstract/montgomery.cjs +149 -0
  20. package/lib/_vendor/@noble/curves/ed25519.cjs +302 -0
  21. package/lib/_vendor/@noble/curves/utils.cjs +436 -0
  22. package/lib/_vendor/@noble/hashes/LICENSE +21 -0
  23. package/lib/_vendor/@noble/hashes/_blake.cjs +300 -0
  24. package/lib/_vendor/@noble/hashes/_md.cjs +194 -0
  25. package/lib/_vendor/@noble/hashes/_u64.cjs +60 -0
  26. package/lib/_vendor/@noble/hashes/blake2.cjs +291 -0
  27. package/lib/_vendor/@noble/hashes/hkdf.cjs +104 -0
  28. package/lib/_vendor/@noble/hashes/hmac.cjs +86 -0
  29. package/lib/_vendor/@noble/hashes/sha2.cjs +417 -0
  30. package/lib/_vendor/@noble/hashes/utils.cjs +422 -0
  31. package/lib/chacha20poly1305.cjs +153 -0
  32. package/lib/chacha20poly1305.d.cts +18 -0
  33. package/lib/chain-node-mesh.cjs +189 -0
  34. package/lib/chain-node-mesh.d.cts +79 -0
  35. package/lib/http-transport.cjs +219 -0
  36. package/lib/http-transport.d.cts +72 -0
  37. package/lib/index.cjs +31 -0
  38. package/lib/index.d.cts +6 -0
  39. package/lib/mesh-tunnel.cjs +354 -0
  40. package/lib/mesh-tunnel.d.cts +165 -0
  41. package/lib/noise-session.cjs +503 -0
  42. package/lib/noise-session.d.cts +157 -0
  43. package/package.json +80 -4
  44. package/README.md +0 -3
@@ -0,0 +1,350 @@
1
+ import { NoiseSession, NoiseStealthDropError } from "./noise-session.mjs";
2
+ import { sha256 } from "@noble/hashes/sha2.js";
3
+
4
+ //#region src/mesh-tunnel.ts
5
+ /**
6
+ * MeshTunnel & MultiMeshRouter — Session Multiplexing and Multi-VLAN Isolation
7
+ *
8
+ * Provides:
9
+ * 1. `MeshTunnel` & `EncryptedChannel`: Peer-to-peer Noise_IK encrypted channel management
10
+ * 2. `deriveMeshSubnet` & `computeMeshAddress`: Deterministic `10.{b0}.{b1}.{host}/24` virtual IP allocation per mesh
11
+ * 3. `MultiMeshRouter`: Allows a single node to simultaneously join multiple isolated virtual LANs
12
+ * (e.g. `personal`, `team-core`, `ops-prod`, `dev-pair`) without switching networks (unlike Tailscale Tailnets),
13
+ * while enforcing cryptographic cross-VLAN isolation at the 1-RTT Noise_IK handshake boundary.
14
+ */
15
+ const encoder = new TextEncoder();
16
+ const decoder = new TextDecoder();
17
+ /**
18
+ * Derive a deterministic `/24` virtual subnet prefix (`10.{b0}.{b1}`) from a `meshId` or shared key.
19
+ * Each octect is constrained to `1..254` to avoid `.0` and `.255`.
20
+ */
21
+ function deriveMeshSubnet(meshIdOrKey) {
22
+ const hash = sha256(encoder.encode(`arcblock-mesh-subnet:${meshIdOrKey}`));
23
+ return `10.${hash[0] % 254 + 1}.${hash[1] % 254 + 1}`;
24
+ }
25
+ /**
26
+ * Compute a deterministic virtual IP (`10.{b0}.{b1}.{host}`) for a peer within a given `meshId`.
27
+ */
28
+ function computeMeshAddress(meshIdOrKey, peerId) {
29
+ return `${deriveMeshSubnet(meshIdOrKey)}.${sha256(encoder.encode(`${meshIdOrKey}:${peerId}`))[0] % 254 + 1}`;
30
+ }
31
+ var EncryptedChannel = class {
32
+ constructor(session, onClose) {
33
+ this.messageCallbacks = [];
34
+ this.binaryCallbacks = [];
35
+ this._closed = false;
36
+ this.session = session;
37
+ this.onCloseCallback = onClose;
38
+ }
39
+ get remotePubkeyHex() {
40
+ return this.session.remotePubkeyHex;
41
+ }
42
+ get remoteDid() {
43
+ return this.session.remoteDid;
44
+ }
45
+ get remoteClaims() {
46
+ return this.session.remoteClaims;
47
+ }
48
+ get meshId() {
49
+ return this.session.remoteClaims?.meshId;
50
+ }
51
+ get rawSession() {
52
+ return this.session;
53
+ }
54
+ isReady() {
55
+ return !this._closed && this.session.isReady();
56
+ }
57
+ /** Complete handshake on initiator side with responder's message 2. */
58
+ completeHandshake(responseMsg) {
59
+ this.session.handleResponse(responseMsg);
60
+ }
61
+ /** Encrypt a UTF-8 string message for sending over the wire. */
62
+ encryptMessage(plaintext) {
63
+ return this.session.encrypt(encoder.encode(plaintext));
64
+ }
65
+ /** Decrypt an incoming message and notify string listeners. */
66
+ handleEncrypted(ciphertext) {
67
+ const decrypted = this.session.decrypt(ciphertext);
68
+ const text = decoder.decode(decrypted);
69
+ for (const cb of this.messageCallbacks) cb(text);
70
+ return text;
71
+ }
72
+ /** Encrypt raw binary bytes for sending over the wire. */
73
+ encryptBytes(plaintext) {
74
+ return this.session.encrypt(plaintext);
75
+ }
76
+ /** Decrypt raw binary bytes and notify binary listeners. */
77
+ handleEncryptedBytes(ciphertext) {
78
+ const decrypted = this.session.decrypt(ciphertext);
79
+ for (const cb of this.binaryCallbacks) cb(decrypted);
80
+ return decrypted;
81
+ }
82
+ /** Register a callback for decrypted UTF-8 messages. */
83
+ onMessage(cb) {
84
+ this.messageCallbacks.push(cb);
85
+ return () => {
86
+ this.messageCallbacks = this.messageCallbacks.filter((item) => item !== cb);
87
+ };
88
+ }
89
+ /** Register a callback for decrypted binary frames. */
90
+ onBinaryMessage(cb) {
91
+ this.binaryCallbacks.push(cb);
92
+ return () => {
93
+ this.binaryCallbacks = this.binaryCallbacks.filter((item) => item !== cb);
94
+ };
95
+ }
96
+ /** Close the channel and remove from tunnel cache. */
97
+ close() {
98
+ this._closed = true;
99
+ this.messageCallbacks = [];
100
+ this.binaryCallbacks = [];
101
+ this.onCloseCallback();
102
+ }
103
+ };
104
+ var MeshTunnel = class {
105
+ constructor(identity, defaultResponderOptions) {
106
+ this.channels = /* @__PURE__ */ new Map();
107
+ this.identity = identity;
108
+ this.defaultResponderOptions = defaultResponderOptions;
109
+ }
110
+ /**
111
+ * Initiate a Noise_IK handshake with a remote peer.
112
+ * Returns the handshake message to send and the channel (not yet ready until `completeHandshake`).
113
+ */
114
+ initiateHandshake(remotePubkeyHex, options) {
115
+ const { handshakeMsg, session } = NoiseSession.initiator(this.identity, remotePubkeyHex, options);
116
+ const channel = new EncryptedChannel(session, () => {
117
+ this.channels.delete(remotePubkeyHex);
118
+ });
119
+ this.channels.set(remotePubkeyHex, channel);
120
+ return {
121
+ handshakeMsg,
122
+ channel
123
+ };
124
+ }
125
+ /**
126
+ * Respond to an incoming Noise_IK handshake from a remote peer.
127
+ * Returns the response message to send back and a ready channel.
128
+ */
129
+ respondHandshake(handshakeMsg, options) {
130
+ const { session, processHandshake } = NoiseSession.responder(this.identity, options ?? this.defaultResponderOptions);
131
+ const responseMsg = processHandshake(handshakeMsg);
132
+ const remotePub = session.remotePubkeyHex;
133
+ const channel = new EncryptedChannel(session, () => {
134
+ this.channels.delete(remotePub);
135
+ });
136
+ this.channels.set(remotePub, channel);
137
+ return {
138
+ responseMsg,
139
+ channel
140
+ };
141
+ }
142
+ /** Get an existing channel for a peer (by pubkey hex or DID), or null if none. */
143
+ getChannel(remotePubkeyOrDid) {
144
+ const direct = this.channels.get(remotePubkeyHexOrKey(remotePubkeyOrDid));
145
+ if (direct) return direct;
146
+ for (const ch of this.channels.values()) if (ch.remoteDid === remotePubkeyOrDid || ch.remotePubkeyHex === remotePubkeyOrDid) return ch;
147
+ return null;
148
+ }
149
+ /** List all active channels in this tunnel. */
150
+ listChannels() {
151
+ return Array.from(this.channels.values());
152
+ }
153
+ /** Close all channels. */
154
+ closeAll() {
155
+ for (const ch of this.channels.values()) ch.close();
156
+ this.channels.clear();
157
+ }
158
+ };
159
+ function remotePubkeyHexOrKey(key) {
160
+ return key.startsWith("0x") ? key.slice(2) : key;
161
+ }
162
+ /**
163
+ * `MultiMeshRouter` enables a single `arc` or chain node to simultaneously join and route across
164
+ * multiple isolated virtual LANs (`personal`, `team-core`, `ops-prod`, `dev-pair`) without
165
+ * switching Tailnets, while enforcing strict cryptographic isolation between meshes.
166
+ */
167
+ var MultiMeshRouter = class {
168
+ constructor(identity) {
169
+ this.meshes = /* @__PURE__ */ new Map();
170
+ this.identity = identity;
171
+ }
172
+ /**
173
+ * Join and mount an isolated virtual LAN (`meshId`).
174
+ */
175
+ joinMesh(config) {
176
+ const mounted = {
177
+ config,
178
+ subnet: deriveMeshSubnet(config.meshId),
179
+ localAddress: computeMeshAddress(config.meshId, this.identity.did ?? this.identity.pubkeyHex),
180
+ allowedSet: new Set(config.allowedPeers ?? []),
181
+ channels: /* @__PURE__ */ new Map(),
182
+ ipToPubkey: /* @__PURE__ */ new Map()
183
+ };
184
+ this.meshes.set(config.meshId, mounted);
185
+ return this.getMeshInfo(config.meshId);
186
+ }
187
+ /**
188
+ * Leave a virtual LAN and close all its active channels.
189
+ */
190
+ leaveMesh(meshId) {
191
+ const mesh = this.meshes.get(meshId);
192
+ if (!mesh) return false;
193
+ for (const ch of mesh.channels.values()) ch.close();
194
+ mesh.channels.clear();
195
+ mesh.ipToPubkey.clear();
196
+ return this.meshes.delete(meshId);
197
+ }
198
+ /**
199
+ * Dynamically authorize a peer (by DID or pubkeyHex) in a specific `meshId`.
200
+ */
201
+ authorizePeer(meshId, peerDidOrPubkey) {
202
+ const mesh = this.meshes.get(meshId);
203
+ if (!mesh) throw new Error(`Virtual mesh "${meshId}" is not mounted`);
204
+ mesh.allowedSet.add(peerDidOrPubkey);
205
+ }
206
+ /**
207
+ * Revoke a peer from a specific `meshId` and immediately terminate any active channel in that mesh.
208
+ */
209
+ revokePeer(meshId, peerDidOrPubkey) {
210
+ const mesh = this.meshes.get(meshId);
211
+ if (!mesh) return;
212
+ mesh.allowedSet.delete(peerDidOrPubkey);
213
+ for (const [pubkey, ch] of mesh.channels.entries()) if (pubkey === peerDidOrPubkey || ch.remoteDid === peerDidOrPubkey) {
214
+ ch.close();
215
+ mesh.channels.delete(pubkey);
216
+ }
217
+ }
218
+ /**
219
+ * Initiate a handshake to a remote peer within a specific isolated `meshId`.
220
+ */
221
+ initiateHandshake(meshId, remotePubkeyHex, extraOptions) {
222
+ const mesh = this.meshes.get(meshId);
223
+ if (!mesh) throw new Error(`Virtual mesh "${meshId}" is not mounted on this router`);
224
+ const { handshakeMsg, session } = NoiseSession.initiator(this.identity, remotePubkeyHex, {
225
+ meshId,
226
+ membershipProof: extraOptions?.membershipProof ?? mesh.config.localMembershipProof,
227
+ metadata: extraOptions?.metadata,
228
+ includeTimestamp: extraOptions?.includeTimestamp ?? true
229
+ });
230
+ session.setReplayProtection(true);
231
+ const virtualIp = computeMeshAddress(meshId, session.remoteDid ?? remotePubkeyHex);
232
+ const channel = new EncryptedChannel(session, () => {
233
+ mesh.channels.delete(remotePubkeyHex);
234
+ mesh.ipToPubkey.delete(virtualIp);
235
+ });
236
+ mesh.channels.set(remotePubkeyHex, channel);
237
+ mesh.ipToPubkey.set(virtualIp, remotePubkeyHex);
238
+ return {
239
+ handshakeMsg,
240
+ channel,
241
+ virtualIp
242
+ };
243
+ }
244
+ /**
245
+ * Process an incoming handshake and enforce 1-RTT Multi-VLAN admission isolation.
246
+ * Rejects with `NoiseStealthDropError` if:
247
+ * - `claims.meshId` is missing or not mounted on this node
248
+ * - Peer is not authorized in `claims.meshId` via `allowedPeers` or `admissionPolicy`
249
+ */
250
+ respondHandshake(handshakeMsg) {
251
+ let matchedMesh = null;
252
+ const { session, processHandshake } = NoiseSession.responder(this.identity, { admissionPolicy: (claims) => {
253
+ if (!claims.meshId) return false;
254
+ const mesh = this.meshes.get(claims.meshId);
255
+ if (!mesh) return false;
256
+ const inAllowedSet = mesh.allowedSet.has(claims.pubkeyHex) || mesh.allowedSet.has(claims.did);
257
+ const passesCustomPolicy = mesh.config.admissionPolicy ? mesh.config.admissionPolicy(claims) : false;
258
+ if (!inAllowedSet && !passesCustomPolicy) return false;
259
+ matchedMesh = mesh;
260
+ return true;
261
+ } });
262
+ const responseMsg = processHandshake(handshakeMsg);
263
+ if (!matchedMesh) throw new NoiseStealthDropError("No matching virtual mesh accepted handshake");
264
+ session.setReplayProtection(true);
265
+ const targetMesh = matchedMesh;
266
+ const remotePub = session.remotePubkeyHex;
267
+ const remoteDid = session.remoteDid;
268
+ const virtualIp = computeMeshAddress(targetMesh.config.meshId, remoteDid);
269
+ const channel = new EncryptedChannel(session, () => {
270
+ targetMesh.channels.delete(remotePub);
271
+ targetMesh.ipToPubkey.delete(virtualIp);
272
+ });
273
+ targetMesh.channels.set(remotePub, channel);
274
+ targetMesh.ipToPubkey.set(virtualIp, remotePub);
275
+ return {
276
+ responseMsg,
277
+ channel,
278
+ meshId: targetMesh.config.meshId,
279
+ virtualIp
280
+ };
281
+ }
282
+ /**
283
+ * Look up an active channel strictly within `meshId` (prevents cross-VLAN routing leaks).
284
+ */
285
+ getChannel(meshId, peerDidOrPubkeyOrIp) {
286
+ const mesh = this.meshes.get(meshId);
287
+ if (!mesh) return null;
288
+ const byPub = mesh.channels.get(peerDidOrPubkeyOrIp);
289
+ if (byPub?.isReady()) return byPub;
290
+ const mappedPub = mesh.ipToPubkey.get(peerDidOrPubkeyOrIp);
291
+ if (mappedPub) {
292
+ const byIp = mesh.channels.get(mappedPub);
293
+ if (byIp?.isReady()) return byIp;
294
+ }
295
+ for (const ch of mesh.channels.values()) if (ch.isReady() && (ch.remoteDid === peerDidOrPubkeyOrIp || ch.remoteDid === `did:abt:${peerDidOrPubkeyOrIp}`)) return ch;
296
+ return null;
297
+ }
298
+ /**
299
+ * Resolve a channel by virtual IP (`10.{b0}.{b1}.{host}`) across any mounted mesh on this node.
300
+ * Useful for transparent outbound proxy / `meshFetch("http://10.x.y.z/...")`.
301
+ */
302
+ resolveChannelByVirtualIp(virtualIp) {
303
+ for (const [meshId, mesh] of this.meshes.entries()) {
304
+ const pubkey = mesh.ipToPubkey.get(virtualIp);
305
+ if (pubkey) {
306
+ const ch = mesh.channels.get(pubkey);
307
+ if (ch?.isReady()) return {
308
+ meshId,
309
+ channel: ch
310
+ };
311
+ }
312
+ }
313
+ return null;
314
+ }
315
+ /**
316
+ * Inspect a specific virtual LAN's status and connected peers.
317
+ */
318
+ getMeshInfo(meshId) {
319
+ const mesh = this.meshes.get(meshId);
320
+ if (!mesh) return null;
321
+ const activePeers = [];
322
+ for (const [pubkeyHex, ch] of mesh.channels.entries()) if (ch.isReady() && ch.remoteDid) activePeers.push({
323
+ pubkeyHex,
324
+ did: ch.remoteDid,
325
+ virtualIp: computeMeshAddress(meshId, ch.remoteDid)
326
+ });
327
+ return {
328
+ meshId: mesh.config.meshId,
329
+ ...mesh.config.meshDid !== void 0 ? { meshDid: mesh.config.meshDid } : {},
330
+ ...mesh.config.label !== void 0 ? { label: mesh.config.label } : {},
331
+ subnet: mesh.subnet,
332
+ localAddress: mesh.localAddress,
333
+ activePeers
334
+ };
335
+ }
336
+ /**
337
+ * List all mounted virtual LANs on this node.
338
+ */
339
+ listMeshes() {
340
+ const list = [];
341
+ for (const meshId of this.meshes.keys()) {
342
+ const info = this.getMeshInfo(meshId);
343
+ if (info) list.push(info);
344
+ }
345
+ return list;
346
+ }
347
+ };
348
+
349
+ //#endregion
350
+ export { EncryptedChannel, MeshTunnel, MultiMeshRouter, computeMeshAddress, deriveMeshSubnet };
@@ -0,0 +1,157 @@
1
+ //#region src/noise-session.d.ts
2
+ /**
3
+ * Noise_IK Session — WireGuard-grade cryptographic transport for DID-Noise Mesh.
4
+ *
5
+ * Implements the Noise_IK handshake pattern (`Noise_IK_25519_ChaChaPoly_BLAKE2s`):
6
+ * - Curve25519 (X25519) for Diffie-Hellman, converted from Ed25519 (`did:abt`) keys
7
+ * - ChaCha20-Poly1305 (RFC 8439) for AEAD encryption
8
+ * - BLAKE2s for hashing and HKDF key derivation
9
+ * - 1-RTT First-Packet Stealth Admission (DID / Mesh VLAN / VC proof verification)
10
+ * - 64-bit sliding window anti-replay protection (WireGuard-style)
11
+ * - Symmetric session rekeying
12
+ */
13
+ declare const NONCE_SIZE = 12;
14
+ declare const KEY_SIZE = 32;
15
+ declare const TAG_SIZE = 16;
16
+ declare class NoiseStealthDropError extends Error {
17
+ readonly code = "NOISE_STEALTH_DROP";
18
+ constructor(reason: string);
19
+ }
20
+ declare class NoiseReplayError extends Error {
21
+ readonly code = "NOISE_REPLAY_DETECTED";
22
+ readonly nonce: bigint;
23
+ constructor(nonce: bigint, reason: string);
24
+ }
25
+ declare function toHex(bytes: Uint8Array): string;
26
+ declare function fromHex(hex: string): Uint8Array;
27
+ declare function didFromPublicKey(publicKey: Uint8Array | string): string;
28
+ /**
29
+ * Convert an Ed25519 public key (32 bytes) to an X25519 public key (32 bytes).
30
+ * Uses the birational map: u = (1 + y) / (1 - y) mod p, where p = 2^255 - 19.
31
+ */
32
+ declare function edToX25519Pub(edPub: Uint8Array): Uint8Array;
33
+ /**
34
+ * Convert an Ed25519 private key seed (first 32 bytes of 64-byte secretKey)
35
+ * to an X25519 private key (32 bytes).
36
+ */
37
+ declare function edToX25519Priv(edSeed: Uint8Array): Uint8Array;
38
+ interface NoiseIdentity {
39
+ secretKey: Uint8Array;
40
+ publicKey: Uint8Array;
41
+ pubkeyHex: string;
42
+ did?: string;
43
+ }
44
+ /**
45
+ * Generate a fresh Ed25519-backed NoiseIdentity with its corresponding `did:abt:` identifier.
46
+ */
47
+ declare function createNoiseIdentity(seed?: Uint8Array): NoiseIdentity;
48
+ declare class ReplayWindow {
49
+ private highestNonce;
50
+ private bitmap;
51
+ private readonly windowSize;
52
+ /**
53
+ * Check and record a nonce. Throws `NoiseReplayError` if the nonce is replayed or too old.
54
+ */
55
+ checkAndAccept(nonce: bigint): void;
56
+ reset(): void;
57
+ }
58
+ interface NoiseHandshakeClaims {
59
+ /** Initiator's 32-byte Ed25519 public key in hex */
60
+ pubkeyHex: string;
61
+ /** Initiator's derived `did:abt:...` identifier */
62
+ did: string;
63
+ /** Optional virtual LAN / Mesh identifier (e.g. `personal`, `team-core`, `ops-prod`) */
64
+ meshId?: string;
65
+ /** Optional Verifiable Credential (JWT or JSON VC) or delegation proof */
66
+ membershipProof?: string;
67
+ /** Unix timestamp (ms) when handshake was initiated */
68
+ timestamp?: number;
69
+ /** Optional application metadata */
70
+ metadata?: Record<string, unknown>;
71
+ }
72
+ /**
73
+ * Policy callback evaluated inside `readMessage1` after decrypting the initiator's static identity.
74
+ * Return `true` to accept the handshake, or `false` to trigger a silent 1-RTT Stealth Drop.
75
+ */
76
+ type NoiseAdmissionPolicy = (claims: NoiseHandshakeClaims) => boolean;
77
+ interface NoiseInitiatorOptions {
78
+ /** Target virtual LAN / Mesh ID */
79
+ meshId?: string;
80
+ /** Optional VC / delegation token proving membership in `meshId` */
81
+ membershipProof?: string;
82
+ /** Optional metadata included in encrypted first packet */
83
+ metadata?: Record<string, unknown>;
84
+ /** Include timestamp in encrypted first packet */
85
+ includeTimestamp?: boolean;
86
+ }
87
+ interface NoiseResponderOptions {
88
+ /**
89
+ * Optional 1-RTT stealth admission policy.
90
+ * Evaluated before sending any response packet; rejecting throws `NoiseStealthDropError`.
91
+ */
92
+ admissionPolicy?: NoiseAdmissionPolicy;
93
+ /**
94
+ * Maximum allowed clock skew (ms) when `claims.timestamp` is present.
95
+ * Defaults to 5 minutes (300_000 ms) if > 0.
96
+ */
97
+ maxClockSkewMs?: number;
98
+ }
99
+ declare class NoiseSession {
100
+ private sendCipher;
101
+ private recvCipher;
102
+ private _remotePubkeyHex;
103
+ private _remoteDid;
104
+ private _remoteClaims;
105
+ private _ready;
106
+ private _replayProtection;
107
+ /** The authenticated remote peer's Ed25519 pubkey hex (available after handshake). */
108
+ get remotePubkeyHex(): string | null;
109
+ /** The authenticated remote peer's `did:abt:...` identifier (available after handshake). */
110
+ get remoteDid(): string | null;
111
+ /** Full handshake claims presented by the remote peer (available after handshake). */
112
+ get remoteClaims(): NoiseHandshakeClaims | null;
113
+ isReady(): boolean;
114
+ /**
115
+ * Enable or disable 64-bit sliding window anti-replay enforcement on `decrypt()`.
116
+ */
117
+ setReplayProtection(enabled: boolean): this;
118
+ /**
119
+ * Create an initiator session and generate handshake message 1 (`→ e, es, s, ss`).
120
+ */
121
+ static initiator(localIdentity: NoiseIdentity, remoteEdPubHex: string, options?: NoiseInitiatorOptions): {
122
+ handshakeMsg: Uint8Array;
123
+ session: NoiseSession;
124
+ handleResponse: (msg2: Uint8Array) => void;
125
+ };
126
+ /** Complete handshake on initiator side (set by `NoiseSession.initiator()`). */
127
+ handleResponse: (msg2: Uint8Array) => void;
128
+ /**
129
+ * Create a responder session and process handshake message 1 (`← e, ee, se`).
130
+ */
131
+ static responder(localIdentity: NoiseIdentity, options?: NoiseResponderOptions): {
132
+ session: NoiseSession;
133
+ processHandshake: (msg1: Uint8Array) => Uint8Array;
134
+ };
135
+ /**
136
+ * Encrypt a message using the established transport session.
137
+ */
138
+ encrypt(plaintext: Uint8Array, aad?: Uint8Array): Uint8Array;
139
+ /**
140
+ * Decrypt a message using the established transport session.
141
+ */
142
+ decrypt(ciphertext: Uint8Array, aad?: Uint8Array): Uint8Array;
143
+ /**
144
+ * Ratchet the outbound transport key forward (forward-secure rekey).
145
+ */
146
+ rekeySend(): void;
147
+ /**
148
+ * Ratchet the inbound transport key forward (must be coordinated with peer's `rekeySend()`).
149
+ */
150
+ rekeyRecv(): void;
151
+ /**
152
+ * Check whether the session should be rekeyed based on message count or age.
153
+ */
154
+ needsRekey(maxMessages?: number, maxAgeMs?: number): boolean;
155
+ }
156
+ //#endregion
157
+ export { KEY_SIZE, NONCE_SIZE, NoiseAdmissionPolicy, NoiseHandshakeClaims, NoiseIdentity, NoiseInitiatorOptions, NoiseReplayError, NoiseResponderOptions, NoiseSession, NoiseStealthDropError, ReplayWindow, TAG_SIZE, createNoiseIdentity, didFromPublicKey, edToX25519Priv, edToX25519Pub, fromHex, toHex };