@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.
- package/LICENSE +13 -0
- package/esm/chacha20poly1305.d.mts +18 -0
- package/esm/chacha20poly1305.mjs +152 -0
- package/esm/chain-node-mesh.d.mts +79 -0
- package/esm/chain-node-mesh.mjs +187 -0
- package/esm/http-transport.d.mts +72 -0
- package/esm/http-transport.mjs +216 -0
- package/esm/index.d.mts +6 -0
- package/esm/index.mjs +7 -0
- package/esm/mesh-tunnel.d.mts +165 -0
- package/esm/mesh-tunnel.mjs +350 -0
- package/esm/noise-session.d.mts +157 -0
- package/esm/noise-session.mjs +491 -0
- package/lib/_vendor/@noble/curves/LICENSE +21 -0
- package/lib/_vendor/@noble/curves/abstract/curve.cjs +338 -0
- package/lib/_vendor/@noble/curves/abstract/edwards.cjs +542 -0
- package/lib/_vendor/@noble/curves/abstract/hash-to-curve.cjs +72 -0
- package/lib/_vendor/@noble/curves/abstract/modular.cjs +557 -0
- package/lib/_vendor/@noble/curves/abstract/montgomery.cjs +149 -0
- package/lib/_vendor/@noble/curves/ed25519.cjs +302 -0
- package/lib/_vendor/@noble/curves/utils.cjs +436 -0
- package/lib/_vendor/@noble/hashes/LICENSE +21 -0
- package/lib/_vendor/@noble/hashes/_blake.cjs +300 -0
- package/lib/_vendor/@noble/hashes/_md.cjs +194 -0
- package/lib/_vendor/@noble/hashes/_u64.cjs +60 -0
- package/lib/_vendor/@noble/hashes/blake2.cjs +291 -0
- package/lib/_vendor/@noble/hashes/hkdf.cjs +104 -0
- package/lib/_vendor/@noble/hashes/hmac.cjs +86 -0
- package/lib/_vendor/@noble/hashes/sha2.cjs +417 -0
- package/lib/_vendor/@noble/hashes/utils.cjs +422 -0
- package/lib/chacha20poly1305.cjs +153 -0
- package/lib/chacha20poly1305.d.cts +18 -0
- package/lib/chain-node-mesh.cjs +189 -0
- package/lib/chain-node-mesh.d.cts +79 -0
- package/lib/http-transport.cjs +219 -0
- package/lib/http-transport.d.cts +72 -0
- package/lib/index.cjs +31 -0
- package/lib/index.d.cts +6 -0
- package/lib/mesh-tunnel.cjs +354 -0
- package/lib/mesh-tunnel.d.cts +165 -0
- package/lib/noise-session.cjs +503 -0
- package/lib/noise-session.d.cts +157 -0
- package/package.json +80 -4
- package/README.md +0 -3
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
//#region src/http-transport.ts
|
|
2
|
+
function headersToRecord(headers) {
|
|
3
|
+
const out = {};
|
|
4
|
+
headers.forEach((value, key) => {
|
|
5
|
+
out[key] = value;
|
|
6
|
+
});
|
|
7
|
+
return out;
|
|
8
|
+
}
|
|
9
|
+
let reqSeq = 0;
|
|
10
|
+
function nextRequestId() {
|
|
11
|
+
reqSeq = (reqSeq + 1) % 2147483647;
|
|
12
|
+
return `nreq-${Date.now().toString(36)}-${reqSeq.toString(36)}`;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Multiplexes standard Web `Request` / `Response` pairs over a single `EncryptedChannel`.
|
|
16
|
+
*/
|
|
17
|
+
var NoiseHttpBridge = class {
|
|
18
|
+
constructor(channel, options) {
|
|
19
|
+
this.pending = /* @__PURE__ */ new Map();
|
|
20
|
+
this.channel = channel;
|
|
21
|
+
this.sendEncrypted = options.sendEncrypted;
|
|
22
|
+
this.timeoutMs = options.timeoutMs ?? 15e3;
|
|
23
|
+
this.handler = options.handler;
|
|
24
|
+
this.unsubMessage = this.channel.onMessage((jsonText) => {
|
|
25
|
+
this.onDecryptedMessage(jsonText);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
setHandler(handler) {
|
|
29
|
+
this.handler = handler;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Feed an incoming encrypted frame from the network into the bridge.
|
|
33
|
+
*/
|
|
34
|
+
receiveEncrypted(ciphertext) {
|
|
35
|
+
this.channel.handleEncrypted(ciphertext);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Standard Web `fetch` implementation bound to this encrypted channel.
|
|
39
|
+
*/
|
|
40
|
+
async fetch(input, init) {
|
|
41
|
+
if (!this.channel.isReady()) throw new Error("NoiseHttpBridge: EncryptedChannel is not ready");
|
|
42
|
+
const req = input instanceof Request ? input : new Request(input.toString(), init);
|
|
43
|
+
const id = nextRequestId();
|
|
44
|
+
const arrayBuf = req.body ? await req.arrayBuffer() : null;
|
|
45
|
+
const bodyBase64 = arrayBuf && arrayBuf.byteLength > 0 ? Buffer.from(arrayBuf).toString("base64") : void 0;
|
|
46
|
+
const envelope = {
|
|
47
|
+
kind: "noise-http-req",
|
|
48
|
+
id,
|
|
49
|
+
method: req.method,
|
|
50
|
+
url: req.url,
|
|
51
|
+
headers: headersToRecord(req.headers),
|
|
52
|
+
...bodyBase64 !== void 0 ? { bodyBase64 } : {}
|
|
53
|
+
};
|
|
54
|
+
const encrypted = this.channel.encryptMessage(JSON.stringify(envelope));
|
|
55
|
+
return new Promise((resolve, reject) => {
|
|
56
|
+
const timer = setTimeout(() => {
|
|
57
|
+
this.pending.delete(id);
|
|
58
|
+
reject(/* @__PURE__ */ new Error(`Noise HTTP request timed out after ${this.timeoutMs}ms: ${req.url}`));
|
|
59
|
+
}, this.timeoutMs);
|
|
60
|
+
this.pending.set(id, {
|
|
61
|
+
resolve,
|
|
62
|
+
reject,
|
|
63
|
+
timer
|
|
64
|
+
});
|
|
65
|
+
Promise.resolve(this.sendEncrypted(encrypted)).catch((err) => {
|
|
66
|
+
clearTimeout(timer);
|
|
67
|
+
this.pending.delete(id);
|
|
68
|
+
reject(err instanceof Error ? err : new Error(String(err)));
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
async onDecryptedMessage(jsonText) {
|
|
73
|
+
let parsed;
|
|
74
|
+
try {
|
|
75
|
+
parsed = JSON.parse(jsonText);
|
|
76
|
+
} catch {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
if (parsed.kind === "noise-http-res") {
|
|
80
|
+
const entry = this.pending.get(parsed.id);
|
|
81
|
+
if (!entry) return;
|
|
82
|
+
clearTimeout(entry.timer);
|
|
83
|
+
this.pending.delete(parsed.id);
|
|
84
|
+
if (parsed.error) {
|
|
85
|
+
entry.reject(new Error(parsed.error));
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
const body = parsed.bodyBase64 ? Buffer.from(parsed.bodyBase64, "base64") : null;
|
|
89
|
+
const response = new Response(body, {
|
|
90
|
+
status: parsed.status,
|
|
91
|
+
statusText: parsed.statusText,
|
|
92
|
+
headers: parsed.headers
|
|
93
|
+
});
|
|
94
|
+
entry.resolve(response);
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
if (parsed.kind === "noise-http-req") {
|
|
98
|
+
if (!this.handler) {
|
|
99
|
+
const errEnvelope = {
|
|
100
|
+
kind: "noise-http-res",
|
|
101
|
+
id: parsed.id,
|
|
102
|
+
status: 501,
|
|
103
|
+
statusText: "Not Implemented",
|
|
104
|
+
headers: { "content-type": "application/json" },
|
|
105
|
+
bodyBase64: Buffer.from(JSON.stringify({ error: "No handler registered" })).toString("base64")
|
|
106
|
+
};
|
|
107
|
+
const ct = this.channel.encryptMessage(JSON.stringify(errEnvelope));
|
|
108
|
+
await this.sendEncrypted(ct);
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
try {
|
|
112
|
+
const reqBody = parsed.bodyBase64 ? Buffer.from(parsed.bodyBase64, "base64") : void 0;
|
|
113
|
+
const headers = new Headers(parsed.headers);
|
|
114
|
+
if (this.channel.remoteDid) headers.set("x-noise-peer-did", this.channel.remoteDid);
|
|
115
|
+
if (this.channel.remotePubkeyHex) headers.set("x-noise-peer-pubkey", this.channel.remotePubkeyHex);
|
|
116
|
+
if (this.channel.meshId) headers.set("x-noise-mesh-id", this.channel.meshId);
|
|
117
|
+
const request = new Request(parsed.url, {
|
|
118
|
+
method: parsed.method,
|
|
119
|
+
headers,
|
|
120
|
+
body: parsed.method === "GET" || parsed.method === "HEAD" ? void 0 : reqBody
|
|
121
|
+
});
|
|
122
|
+
const context = {
|
|
123
|
+
remoteDid: this.channel.remoteDid ?? "",
|
|
124
|
+
remotePubkeyHex: this.channel.remotePubkeyHex ?? "",
|
|
125
|
+
...this.channel.meshId !== void 0 ? { meshId: this.channel.meshId } : {},
|
|
126
|
+
claims: this.channel.remoteClaims
|
|
127
|
+
};
|
|
128
|
+
const response = await this.handler(request, context);
|
|
129
|
+
const resBuf = response.body ? await response.arrayBuffer() : null;
|
|
130
|
+
const resBase64 = resBuf && resBuf.byteLength > 0 ? Buffer.from(resBuf).toString("base64") : void 0;
|
|
131
|
+
const resEnvelope = {
|
|
132
|
+
kind: "noise-http-res",
|
|
133
|
+
id: parsed.id,
|
|
134
|
+
status: response.status,
|
|
135
|
+
statusText: response.statusText,
|
|
136
|
+
headers: headersToRecord(response.headers),
|
|
137
|
+
...resBase64 !== void 0 ? { bodyBase64: resBase64 } : {}
|
|
138
|
+
};
|
|
139
|
+
const ct = this.channel.encryptMessage(JSON.stringify(resEnvelope));
|
|
140
|
+
await this.sendEncrypted(ct);
|
|
141
|
+
} catch (err) {
|
|
142
|
+
const resEnvelope = {
|
|
143
|
+
kind: "noise-http-res",
|
|
144
|
+
id: parsed.id,
|
|
145
|
+
status: 500,
|
|
146
|
+
statusText: "Internal Server Error",
|
|
147
|
+
headers: {},
|
|
148
|
+
error: err instanceof Error ? err.message : String(err)
|
|
149
|
+
};
|
|
150
|
+
const ct = this.channel.encryptMessage(JSON.stringify(resEnvelope));
|
|
151
|
+
await this.sendEncrypted(ct);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
close() {
|
|
156
|
+
this.unsubMessage();
|
|
157
|
+
for (const [id, entry] of this.pending.entries()) {
|
|
158
|
+
clearTimeout(entry.timer);
|
|
159
|
+
entry.reject(/* @__PURE__ */ new Error("NoiseHttpBridge closed"));
|
|
160
|
+
this.pending.delete(id);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
/**
|
|
165
|
+
* Convenience helper to create a standard `(input, init) => Promise<Response>` fetch function
|
|
166
|
+
* bound to a `NoiseHttpBridge`.
|
|
167
|
+
*/
|
|
168
|
+
function createNoiseFetch(bridge) {
|
|
169
|
+
return bridge.fetch.bind(bridge);
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Normalize URLs containing `did:abt:<address>.<meshId>.arc` in the authority position
|
|
173
|
+
* so standard `URL` / `Request` parsers do not treat `:abt:` as a port number.
|
|
174
|
+
*/
|
|
175
|
+
function normalizeNoiseUrl(rawUrl) {
|
|
176
|
+
const match = rawUrl.match(/^(https?:\/\/)([^/?#]+)(.*)$/i);
|
|
177
|
+
if (!match) return {
|
|
178
|
+
normalizedUrl: rawUrl,
|
|
179
|
+
rawHost: new URL(rawUrl).hostname
|
|
180
|
+
};
|
|
181
|
+
const [, scheme, authority, rest] = match;
|
|
182
|
+
if (authority.startsWith("did:abt:")) return {
|
|
183
|
+
normalizedUrl: `${scheme}${authority.slice(8)}${rest}`,
|
|
184
|
+
rawHost: authority
|
|
185
|
+
};
|
|
186
|
+
return {
|
|
187
|
+
normalizedUrl: rawUrl,
|
|
188
|
+
rawHost: new URL(rawUrl).hostname
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Create a Multi-VLAN aware `fetch` function that routes requests by virtual IP (`http://10.x.y.z/...`)
|
|
193
|
+
* or explicit mesh URL (`http://<peerDid>.<meshId>.arc/...`) across a `MultiMeshRouter`.
|
|
194
|
+
*/
|
|
195
|
+
function createMultiMeshFetch(router, getBridgeForChannel) {
|
|
196
|
+
return async (input, init) => {
|
|
197
|
+
const { normalizedUrl, rawHost } = normalizeNoiseUrl(input instanceof Request ? input.url : input.toString());
|
|
198
|
+
if (rawHost.endsWith(".arc")) {
|
|
199
|
+
const parts = rawHost.slice(0, -4).split(".");
|
|
200
|
+
if (parts.length >= 2) {
|
|
201
|
+
const meshId = parts[parts.length - 1];
|
|
202
|
+
const peerId = parts.slice(0, -1).join(".");
|
|
203
|
+
const channel = router.getChannel(meshId, peerId);
|
|
204
|
+
if (!channel) throw new Error(`No active channel for peer "${peerId}" in virtual mesh "${meshId}"`);
|
|
205
|
+
const targetInput = input instanceof Request ? new Request(normalizedUrl, input) : normalizedUrl;
|
|
206
|
+
return getBridgeForChannel(channel, meshId).fetch(targetInput, init);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
const resolved = router.resolveChannelByVirtualIp(rawHost);
|
|
210
|
+
if (resolved) return getBridgeForChannel(resolved.channel, resolved.meshId).fetch(input, init);
|
|
211
|
+
throw new Error(`Unable to route host "${rawHost}" in any mounted virtual mesh`);
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
//#endregion
|
|
216
|
+
export { NoiseHttpBridge, createMultiMeshFetch, createNoiseFetch };
|
package/esm/index.d.mts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ChaCha20Poly1305Cipher, chacha20poly1305 } from "./chacha20poly1305.mjs";
|
|
2
|
+
import { KEY_SIZE, NONCE_SIZE, NoiseAdmissionPolicy, NoiseHandshakeClaims, NoiseIdentity, NoiseInitiatorOptions, NoiseReplayError, NoiseResponderOptions, NoiseSession, NoiseStealthDropError, ReplayWindow, TAG_SIZE, createNoiseIdentity, didFromPublicKey, edToX25519Priv, edToX25519Pub, fromHex, toHex } from "./noise-session.mjs";
|
|
3
|
+
import { EncryptedChannel, MeshTunnel, MultiMeshRouter, VirtualMeshConfig, VirtualMeshNetworkInfo, computeMeshAddress, deriveMeshSubnet } from "./mesh-tunnel.mjs";
|
|
4
|
+
import { NoiseHttpBridge, NoiseHttpBridgeOptions, NoiseHttpHandler, NoiseHttpRequestEnvelope, NoiseHttpResponseEnvelope, NoisePeerContext, createMultiMeshFetch, createNoiseFetch } from "./http-transport.mjs";
|
|
5
|
+
import { ChainCommitmentPayload, ChainNodeDarknet, ChainNodeDarknetOptions, ChainNodeRole, ChainReplicaSyncAck, ChainWitnessAttestation, canonicalizeCommitment, verifyWitnessAttestation } from "./chain-node-mesh.mjs";
|
|
6
|
+
export { type ChaCha20Poly1305Cipher, type ChainCommitmentPayload, ChainNodeDarknet, type ChainNodeDarknetOptions, type ChainNodeRole, type ChainReplicaSyncAck, type ChainWitnessAttestation, EncryptedChannel, KEY_SIZE, MeshTunnel, MultiMeshRouter, NONCE_SIZE, type NoiseAdmissionPolicy, type NoiseHandshakeClaims, NoiseHttpBridge, type NoiseHttpBridgeOptions, type NoiseHttpHandler, type NoiseHttpRequestEnvelope, type NoiseHttpResponseEnvelope, type NoiseIdentity, type NoiseInitiatorOptions, type NoisePeerContext, NoiseReplayError, type NoiseResponderOptions, NoiseSession, NoiseStealthDropError, ReplayWindow, TAG_SIZE, type VirtualMeshConfig, type VirtualMeshNetworkInfo, canonicalizeCommitment, chacha20poly1305, computeMeshAddress, createMultiMeshFetch, createNoiseFetch, createNoiseIdentity, deriveMeshSubnet, didFromPublicKey, edToX25519Priv, edToX25519Pub, fromHex, toHex, verifyWitnessAttestation };
|
package/esm/index.mjs
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { chacha20poly1305 } from "./chacha20poly1305.mjs";
|
|
2
|
+
import { NoiseHttpBridge, createMultiMeshFetch, createNoiseFetch } from "./http-transport.mjs";
|
|
3
|
+
import { KEY_SIZE, NONCE_SIZE, NoiseReplayError, NoiseSession, NoiseStealthDropError, ReplayWindow, TAG_SIZE, createNoiseIdentity, didFromPublicKey, edToX25519Priv, edToX25519Pub, fromHex, toHex } from "./noise-session.mjs";
|
|
4
|
+
import { EncryptedChannel, MeshTunnel, MultiMeshRouter, computeMeshAddress, deriveMeshSubnet } from "./mesh-tunnel.mjs";
|
|
5
|
+
import { ChainNodeDarknet, canonicalizeCommitment, verifyWitnessAttestation } from "./chain-node-mesh.mjs";
|
|
6
|
+
|
|
7
|
+
export { ChainNodeDarknet, EncryptedChannel, KEY_SIZE, MeshTunnel, MultiMeshRouter, NONCE_SIZE, NoiseHttpBridge, NoiseReplayError, NoiseSession, NoiseStealthDropError, ReplayWindow, TAG_SIZE, canonicalizeCommitment, chacha20poly1305, computeMeshAddress, createMultiMeshFetch, createNoiseFetch, createNoiseIdentity, deriveMeshSubnet, didFromPublicKey, edToX25519Priv, edToX25519Pub, fromHex, toHex, verifyWitnessAttestation };
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { NoiseAdmissionPolicy, NoiseHandshakeClaims, NoiseIdentity, NoiseInitiatorOptions, NoiseResponderOptions, NoiseSession } from "./noise-session.mjs";
|
|
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 };
|