@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,354 @@
1
+ const require_sha2 = require('./_vendor/@noble/hashes/sha2.cjs');
2
+ const require_noise_session = require('./noise-session.cjs');
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 = require_sha2.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)}.${require_sha2.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 } = require_noise_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 } = require_noise_session.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 } = require_noise_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 } = require_noise_session.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 require_noise_session.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
+ exports.EncryptedChannel = EncryptedChannel;
351
+ exports.MeshTunnel = MeshTunnel;
352
+ exports.MultiMeshRouter = MultiMeshRouter;
353
+ exports.computeMeshAddress = computeMeshAddress;
354
+ exports.deriveMeshSubnet = deriveMeshSubnet;
@@ -0,0 +1,165 @@
1
+ import { NoiseAdmissionPolicy, NoiseHandshakeClaims, NoiseIdentity, NoiseInitiatorOptions, NoiseResponderOptions, NoiseSession } from "./noise-session.cjs";
2
+
3
+ //#region src/mesh-tunnel.d.ts
4
+
5
+ /**
6
+ * Derive a deterministic `/24` virtual subnet prefix (`10.{b0}.{b1}`) from a `meshId` or shared key.
7
+ * Each octect is constrained to `1..254` to avoid `.0` and `.255`.
8
+ */
9
+ declare function deriveMeshSubnet(meshIdOrKey: string): string;
10
+ /**
11
+ * Compute a deterministic virtual IP (`10.{b0}.{b1}.{host}`) for a peer within a given `meshId`.
12
+ */
13
+ declare function computeMeshAddress(meshIdOrKey: string, peerId: string): string;
14
+ declare class EncryptedChannel {
15
+ private readonly session;
16
+ private readonly onCloseCallback;
17
+ private messageCallbacks;
18
+ private binaryCallbacks;
19
+ private _closed;
20
+ constructor(session: NoiseSession, onClose: () => void);
21
+ get remotePubkeyHex(): string | null;
22
+ get remoteDid(): string | null;
23
+ get remoteClaims(): NoiseHandshakeClaims | null;
24
+ get meshId(): string | undefined;
25
+ get rawSession(): NoiseSession;
26
+ isReady(): boolean;
27
+ /** Complete handshake on initiator side with responder's message 2. */
28
+ completeHandshake(responseMsg: Uint8Array): void;
29
+ /** Encrypt a UTF-8 string message for sending over the wire. */
30
+ encryptMessage(plaintext: string): Uint8Array;
31
+ /** Decrypt an incoming message and notify string listeners. */
32
+ handleEncrypted(ciphertext: Uint8Array): string;
33
+ /** Encrypt raw binary bytes for sending over the wire. */
34
+ encryptBytes(plaintext: Uint8Array): Uint8Array;
35
+ /** Decrypt raw binary bytes and notify binary listeners. */
36
+ handleEncryptedBytes(ciphertext: Uint8Array): Uint8Array;
37
+ /** Register a callback for decrypted UTF-8 messages. */
38
+ onMessage(cb: (data: string) => void): () => void;
39
+ /** Register a callback for decrypted binary frames. */
40
+ onBinaryMessage(cb: (data: Uint8Array) => void): () => void;
41
+ /** Close the channel and remove from tunnel cache. */
42
+ close(): void;
43
+ }
44
+ declare class MeshTunnel {
45
+ private readonly identity;
46
+ private readonly channels;
47
+ private readonly defaultResponderOptions?;
48
+ constructor(identity: NoiseIdentity, defaultResponderOptions?: NoiseResponderOptions);
49
+ /**
50
+ * Initiate a Noise_IK handshake with a remote peer.
51
+ * Returns the handshake message to send and the channel (not yet ready until `completeHandshake`).
52
+ */
53
+ initiateHandshake(remotePubkeyHex: string, options?: NoiseInitiatorOptions): {
54
+ handshakeMsg: Uint8Array;
55
+ channel: EncryptedChannel;
56
+ };
57
+ /**
58
+ * Respond to an incoming Noise_IK handshake from a remote peer.
59
+ * Returns the response message to send back and a ready channel.
60
+ */
61
+ respondHandshake(handshakeMsg: Uint8Array, options?: NoiseResponderOptions): {
62
+ responseMsg: Uint8Array;
63
+ channel: EncryptedChannel;
64
+ };
65
+ /** Get an existing channel for a peer (by pubkey hex or DID), or null if none. */
66
+ getChannel(remotePubkeyOrDid: string): EncryptedChannel | null;
67
+ /** List all active channels in this tunnel. */
68
+ listChannels(): EncryptedChannel[];
69
+ /** Close all channels. */
70
+ closeAll(): void;
71
+ }
72
+ interface VirtualMeshConfig {
73
+ /** Unique virtual LAN identifier (e.g. `personal`, `team-core`, `ops-prod`, `dev-pair`) */
74
+ meshId: string;
75
+ /** Optional DID representing the virtual LAN authority */
76
+ meshDid?: string;
77
+ /** Local node's membership proof (e.g. VC / Delegation token) when initiating into this mesh */
78
+ localMembershipProof?: string;
79
+ /** Allowed peer DIDs or pubkeys (fast whitelist) */
80
+ allowedPeers?: Iterable<string>;
81
+ /** Custom admission verifier (e.g. Verifiable Credential signature & issuer check) */
82
+ admissionPolicy?: NoiseAdmissionPolicy;
83
+ /** Optional human-readable label */
84
+ label?: string;
85
+ }
86
+ interface VirtualMeshNetworkInfo {
87
+ meshId: string;
88
+ meshDid?: string;
89
+ label?: string;
90
+ subnet: string;
91
+ localAddress: string;
92
+ activePeers: Array<{
93
+ pubkeyHex: string;
94
+ did: string;
95
+ virtualIp: string;
96
+ }>;
97
+ }
98
+ /**
99
+ * `MultiMeshRouter` enables a single `arc` or chain node to simultaneously join and route across
100
+ * multiple isolated virtual LANs (`personal`, `team-core`, `ops-prod`, `dev-pair`) without
101
+ * switching Tailnets, while enforcing strict cryptographic isolation between meshes.
102
+ */
103
+ declare class MultiMeshRouter {
104
+ private readonly identity;
105
+ private readonly meshes;
106
+ constructor(identity: NoiseIdentity);
107
+ /**
108
+ * Join and mount an isolated virtual LAN (`meshId`).
109
+ */
110
+ joinMesh(config: VirtualMeshConfig): VirtualMeshNetworkInfo;
111
+ /**
112
+ * Leave a virtual LAN and close all its active channels.
113
+ */
114
+ leaveMesh(meshId: string): boolean;
115
+ /**
116
+ * Dynamically authorize a peer (by DID or pubkeyHex) in a specific `meshId`.
117
+ */
118
+ authorizePeer(meshId: string, peerDidOrPubkey: string): void;
119
+ /**
120
+ * Revoke a peer from a specific `meshId` and immediately terminate any active channel in that mesh.
121
+ */
122
+ revokePeer(meshId: string, peerDidOrPubkey: string): void;
123
+ /**
124
+ * Initiate a handshake to a remote peer within a specific isolated `meshId`.
125
+ */
126
+ initiateHandshake(meshId: string, remotePubkeyHex: string, extraOptions?: Omit<NoiseInitiatorOptions, 'meshId'>): {
127
+ handshakeMsg: Uint8Array;
128
+ channel: EncryptedChannel;
129
+ virtualIp: string;
130
+ };
131
+ /**
132
+ * Process an incoming handshake and enforce 1-RTT Multi-VLAN admission isolation.
133
+ * Rejects with `NoiseStealthDropError` if:
134
+ * - `claims.meshId` is missing or not mounted on this node
135
+ * - Peer is not authorized in `claims.meshId` via `allowedPeers` or `admissionPolicy`
136
+ */
137
+ respondHandshake(handshakeMsg: Uint8Array): {
138
+ responseMsg: Uint8Array;
139
+ channel: EncryptedChannel;
140
+ meshId: string;
141
+ virtualIp: string;
142
+ };
143
+ /**
144
+ * Look up an active channel strictly within `meshId` (prevents cross-VLAN routing leaks).
145
+ */
146
+ getChannel(meshId: string, peerDidOrPubkeyOrIp: string): EncryptedChannel | null;
147
+ /**
148
+ * Resolve a channel by virtual IP (`10.{b0}.{b1}.{host}`) across any mounted mesh on this node.
149
+ * Useful for transparent outbound proxy / `meshFetch("http://10.x.y.z/...")`.
150
+ */
151
+ resolveChannelByVirtualIp(virtualIp: string): {
152
+ meshId: string;
153
+ channel: EncryptedChannel;
154
+ } | null;
155
+ /**
156
+ * Inspect a specific virtual LAN's status and connected peers.
157
+ */
158
+ getMeshInfo(meshId: string): VirtualMeshNetworkInfo | null;
159
+ /**
160
+ * List all mounted virtual LANs on this node.
161
+ */
162
+ listMeshes(): VirtualMeshNetworkInfo[];
163
+ }
164
+ //#endregion
165
+ export { EncryptedChannel, MeshTunnel, MultiMeshRouter, VirtualMeshConfig, VirtualMeshNetworkInfo, computeMeshAddress, deriveMeshSubnet };