@aria-cli/wireguard 1.0.18 → 1.0.23
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/index.js +52 -52
- package/package.json +14 -12
- package/dist/.aria-build-stamp.json +0 -4
- package/dist/bootstrap-authority.d.ts +0 -1
- package/dist/bootstrap-tls.d.ts +0 -13
- package/dist/db-owner-fencing.d.ts +0 -9
- package/dist/derp-relay.d.ts +0 -74
- package/dist/index.d.ts +0 -52
- package/dist/nat.d.ts +0 -83
- package/dist/network-state-store.d.ts +0 -45
- package/dist/network.d.ts +0 -589
- package/dist/peer-discovery.d.ts +0 -132
- package/dist/resilient-tunnel.d.ts +0 -69
- package/dist/route-ownership.d.ts +0 -22
- package/dist/tunnel.d.ts +0 -140
- package/dist/wireguard.node +0 -0
- package/index.d.ts +0 -59
package/dist/peer-discovery.d.ts
DELETED
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* PeerDiscoveryService — periodic peer discovery via coordination server.
|
|
3
|
-
*
|
|
4
|
-
* Polls the coordination server every 60s, diffs against local PeerRegistry,
|
|
5
|
-
* refreshes remote endpoints for known peers, and auto-starts/stops tunnels for
|
|
6
|
-
* new/disappeared peers. Emits events for peer join/leave so higher-level systems
|
|
7
|
-
* can react.
|
|
8
|
-
*
|
|
9
|
-
* Architecture:
|
|
10
|
-
* PeerDiscoveryService → POST /api/v1/network/peers → diff local →
|
|
11
|
-
* applyPeerRepair/startTunnel/stopTunnel
|
|
12
|
-
* STUN refreshes OUR endpoint. Peer discovery refreshes REMOTE peer endpoints.
|
|
13
|
-
*
|
|
14
|
-
* Limitation: The coordination server is a peer's ARIA HTTP server, NOT an
|
|
15
|
-
* independent highly-available service. If the coordination server peer goes
|
|
16
|
-
* offline, discovery stops for the entire mesh. For production meshes (>10 peers),
|
|
17
|
-
* deploy a dedicated coordination service at the coordinationUrl.
|
|
18
|
-
*
|
|
19
|
-
* Discovery only auto-connects peers that have completed the invite flow (PSK
|
|
20
|
-
* exchange). Unknown peers emit "peerDiscoveredUnknown" for the daemon to handle.
|
|
21
|
-
*/
|
|
22
|
-
import { EventEmitter } from "node:events";
|
|
23
|
-
import { type NodeId, type PeerTransportId, type LegacyPeerRegistryStatus, type NetworkManagerRef, type NetworkPeerRepairFailureRef, type NetworkPeerRepairResultRef } from "@aria-cli/tools";
|
|
24
|
-
/** Peer info returned from the coordination server */
|
|
25
|
-
export interface DiscoveredPeer {
|
|
26
|
-
nodeId: NodeId;
|
|
27
|
-
transportPublicKey: PeerTransportId;
|
|
28
|
-
displayNameSnapshot?: string;
|
|
29
|
-
status: LegacyPeerRegistryStatus;
|
|
30
|
-
endpointHost: string | null;
|
|
31
|
-
endpointPort: number | null;
|
|
32
|
-
endpointRevision?: number;
|
|
33
|
-
updatedAt?: number;
|
|
34
|
-
lastHandshake?: number | null;
|
|
35
|
-
createdAt?: number;
|
|
36
|
-
}
|
|
37
|
-
/** Minimal interface for the NetworkManager dependency */
|
|
38
|
-
type PeerDiscoveryRepairInput = Parameters<NonNullable<NetworkManagerRef["applyPeerRepair"]>>[0];
|
|
39
|
-
export interface PeerDiscoveryNetworkManager {
|
|
40
|
-
startTunnel(nodeId: NodeId): Promise<void>;
|
|
41
|
-
stopTunnel(nodeId: NodeId): void;
|
|
42
|
-
heartbeat(nodeId: NodeId): boolean;
|
|
43
|
-
applyPeerRepair(input: PeerDiscoveryRepairInput): NetworkPeerRepairResultRef | NetworkPeerRepairFailureRef;
|
|
44
|
-
readonly activeTunnelCount: number;
|
|
45
|
-
}
|
|
46
|
-
/** Envelope signer callback — creates a MutationEnvelope for a given operation */
|
|
47
|
-
export type EnvelopeSigner = (operation: string, payload: Record<string, unknown>) => Record<string, unknown>;
|
|
48
|
-
export interface PeerDiscoveryOptions {
|
|
49
|
-
/** NetworkManager for tunnel lifecycle */
|
|
50
|
-
networkManager: PeerDiscoveryNetworkManager;
|
|
51
|
-
/** Durable local node identity used on the control plane */
|
|
52
|
-
nodeId: NodeId;
|
|
53
|
-
/** Coordination server URL (e.g., https://leader:3000) */
|
|
54
|
-
coordinationUrl: string;
|
|
55
|
-
/** Our display snapshot for registration heartbeats */
|
|
56
|
-
displayNameSnapshot: string;
|
|
57
|
-
/** AbortSignal for clean shutdown */
|
|
58
|
-
signal?: AbortSignal;
|
|
59
|
-
/** Poll interval in ms (default: 60_000) */
|
|
60
|
-
pollIntervalMs?: number;
|
|
61
|
-
/** Max peers to auto-connect (respects NetworkManager.MAX_PEERS=128) */
|
|
62
|
-
maxPeers?: number;
|
|
63
|
-
/** Ed25519 signing public key (base64 SPKI DER) */
|
|
64
|
-
signingPublicKey: string;
|
|
65
|
-
/** Ed25519 signing private key (base64 PKCS#8 DER) */
|
|
66
|
-
signingPrivateKey: string;
|
|
67
|
-
/** Envelope signer for MutationEnvelope-based auth */
|
|
68
|
-
envelopeSigner: EnvelopeSigner;
|
|
69
|
-
/** Optional pinned CA cert for HTTPS coordination control-plane traffic. */
|
|
70
|
-
coordinationCaCert?: string;
|
|
71
|
-
/** Optional expected TLS identity for the coordination control plane. */
|
|
72
|
-
coordinationTlsIdentity?: string;
|
|
73
|
-
/** Read the runtime-owned local endpoint that should be published through register heartbeats. */
|
|
74
|
-
getLocalRegistrationState?: () => {
|
|
75
|
-
endpointHost?: string;
|
|
76
|
-
endpointPort?: number;
|
|
77
|
-
endpointRevision?: number;
|
|
78
|
-
} | null | undefined;
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Periodic peer discovery service.
|
|
82
|
-
*
|
|
83
|
-
* Polls coordination server, diffs against local state, auto-manages tunnels.
|
|
84
|
-
* Emits: "peerJoined" (displayNameSnapshot|nodeId, nodeId), "peerLeft" (displayNameSnapshot|nodeId, nodeId), "error" (Error)
|
|
85
|
-
*/
|
|
86
|
-
export declare class PeerDiscoveryService extends EventEmitter {
|
|
87
|
-
private interval;
|
|
88
|
-
private readonly networkManager;
|
|
89
|
-
private readonly nodeId;
|
|
90
|
-
private readonly coordinationUrl;
|
|
91
|
-
private readonly displayNameSnapshot;
|
|
92
|
-
private readonly signal?;
|
|
93
|
-
private readonly pollIntervalMs;
|
|
94
|
-
private readonly maxPeers;
|
|
95
|
-
private readonly signingPublicKey;
|
|
96
|
-
private readonly signingPrivateKey;
|
|
97
|
-
private readonly envelopeSigner;
|
|
98
|
-
private readonly coordinationCaCert?;
|
|
99
|
-
private readonly coordinationTlsIdentity?;
|
|
100
|
-
private readonly getLocalRegistrationState?;
|
|
101
|
-
/** Track known remote peers by durable peer principal for diff */
|
|
102
|
-
private knownRemotePeers;
|
|
103
|
-
private pollInFlight;
|
|
104
|
-
private readonly initialSyncPromise;
|
|
105
|
-
private resolveInitialSync;
|
|
106
|
-
private initialSyncSettled;
|
|
107
|
-
private stopped;
|
|
108
|
-
constructor(options: PeerDiscoveryOptions);
|
|
109
|
-
/** Start periodic peer discovery */
|
|
110
|
-
start(): void;
|
|
111
|
-
/** Resolve once the first discovery poll attempt finishes (success or failure). */
|
|
112
|
-
waitForInitialSync(): Promise<void>;
|
|
113
|
-
/** Stop periodic discovery */
|
|
114
|
-
stop(): void;
|
|
115
|
-
private schedulePoll;
|
|
116
|
-
private reportError;
|
|
117
|
-
private peerEndpointRevision;
|
|
118
|
-
private peerFreshness;
|
|
119
|
-
private classifyRepairOutcome;
|
|
120
|
-
private repairInputForPeer;
|
|
121
|
-
private postControlPlane;
|
|
122
|
-
/** Force an immediate heartbeat to the coordination server */
|
|
123
|
-
heartbeat(): Promise<void>;
|
|
124
|
-
private parseDiscoveredPeer;
|
|
125
|
-
/** Single poll cycle: heartbeat + discover + diff + act */
|
|
126
|
-
poll(): Promise<void>;
|
|
127
|
-
/** Fetch peers from coordination server using envelope-authenticated POST only. */
|
|
128
|
-
private fetchPeers;
|
|
129
|
-
/** Reconcile remote peers with local state */
|
|
130
|
-
private reconcile;
|
|
131
|
-
}
|
|
132
|
-
export {};
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ResilientTunnel — wraps SecureTunnel with dead peer detection, auto-reconnection,
|
|
3
|
-
* and outbound message queuing.
|
|
4
|
-
*
|
|
5
|
-
* State machine:
|
|
6
|
-
* CONNECTING → HANDSHAKING → CONNECTED → DISCONNECTED → RECONNECTING → HANDSHAKING → CONNECTED
|
|
7
|
-
* ↓
|
|
8
|
-
* DEAD (max retries exhausted)
|
|
9
|
-
*/
|
|
10
|
-
import { EventEmitter } from "node:events";
|
|
11
|
-
import { SecureTunnel, type SecureTunnelOptions } from "./tunnel.js";
|
|
12
|
-
export type TunnelState = "connecting" | "handshaking" | "connected" | "disconnected" | "reconnecting" | "dead";
|
|
13
|
-
export interface ResilientTunnelStats {
|
|
14
|
-
state: TunnelState;
|
|
15
|
-
reconnections: number;
|
|
16
|
-
reconnectAttempts: number;
|
|
17
|
-
queueDepth: number;
|
|
18
|
-
queueBytes: number;
|
|
19
|
-
}
|
|
20
|
-
export declare class ResilientTunnel extends EventEmitter {
|
|
21
|
-
private options;
|
|
22
|
-
private tunnel;
|
|
23
|
-
private _state;
|
|
24
|
-
private queue;
|
|
25
|
-
private queueBytes;
|
|
26
|
-
private reconnectAttempts;
|
|
27
|
-
private reconnectTimer;
|
|
28
|
-
private deadPeerTimer;
|
|
29
|
-
private lastPacketAt;
|
|
30
|
-
private reconnections;
|
|
31
|
-
private awaitingReplayReadiness;
|
|
32
|
-
private stopped;
|
|
33
|
-
static readonly MAX_QUEUE_SIZE = 1000;
|
|
34
|
-
static readonly MAX_QUEUE_BYTES = 1048576;
|
|
35
|
-
static readonly MAX_RECONNECT_ATTEMPTS = 10;
|
|
36
|
-
static readonly DEAD_PEER_TIMEOUT_MS = 300000;
|
|
37
|
-
static readonly MAX_BACKOFF_MS = 60000;
|
|
38
|
-
static readonly BASE_BACKOFF_MS = 1000;
|
|
39
|
-
constructor(options: SecureTunnelOptions);
|
|
40
|
-
/** Start the resilient tunnel — creates underlying SecureTunnel and waits for remote proof before CONNECTED */
|
|
41
|
-
start(): Promise<number>;
|
|
42
|
-
/** Send plaintext through the tunnel. Queues if not yet connected or reconnecting, throws if dead. */
|
|
43
|
-
sendPlaintext(data: Buffer): void;
|
|
44
|
-
/** Stop the tunnel permanently */
|
|
45
|
-
stop(): void;
|
|
46
|
-
/** Whether the tunnel is actively connected */
|
|
47
|
-
get isActive(): boolean;
|
|
48
|
-
/** Current tunnel state */
|
|
49
|
-
getState(): TunnelState;
|
|
50
|
-
/** Stats including reconnection count and queue depth */
|
|
51
|
-
getStats(): ResilientTunnelStats;
|
|
52
|
-
/** Get the underlying SecureTunnel (for event wiring, e.g. "plaintext") */
|
|
53
|
-
getInnerTunnel(): SecureTunnel | null;
|
|
54
|
-
private setState;
|
|
55
|
-
private requestSessionProof;
|
|
56
|
-
private createAndStartTunnel;
|
|
57
|
-
private disposeCurrentTunnel;
|
|
58
|
-
private handleDisconnect;
|
|
59
|
-
private promoteInitialReady;
|
|
60
|
-
private promoteReconnectReady;
|
|
61
|
-
private finalizeReconnect;
|
|
62
|
-
private attemptReconnect;
|
|
63
|
-
private resetDeadPeerTimer;
|
|
64
|
-
private clearDeadPeerTimer;
|
|
65
|
-
private clearTimers;
|
|
66
|
-
private enqueue;
|
|
67
|
-
private purgeExpired;
|
|
68
|
-
private flushQueue;
|
|
69
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
export type DirectRouteClaimStatus = "active" | "pending" | "pending_tunnel" | "pending_verification" | "revoked";
|
|
2
|
-
export interface DirectRouteClaim {
|
|
3
|
-
publicKey: string;
|
|
4
|
-
nodeId?: string | null;
|
|
5
|
-
status: DirectRouteClaimStatus;
|
|
6
|
-
endpointHost?: string | null;
|
|
7
|
-
endpointPort?: number | null;
|
|
8
|
-
endpointRevision?: number | null;
|
|
9
|
-
createdAt: number;
|
|
10
|
-
updatedAt?: number | null;
|
|
11
|
-
}
|
|
12
|
-
export interface DirectRouteOwnershipDecision {
|
|
13
|
-
routeKey: string | null;
|
|
14
|
-
ownership: "current" | "superseded";
|
|
15
|
-
ownerPublicKey: string;
|
|
16
|
-
supersededByPublicKey?: string;
|
|
17
|
-
}
|
|
18
|
-
export declare function getDirectRouteKey(input: {
|
|
19
|
-
endpointHost?: string | null;
|
|
20
|
-
endpointPort?: number | null;
|
|
21
|
-
}): string | null;
|
|
22
|
-
export declare function resolveDirectRouteOwnership(claims: readonly DirectRouteClaim[]): Map<string, DirectRouteOwnershipDecision>;
|
package/dist/tunnel.d.ts
DELETED
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SecureTunnel — TypeScript transport layer wrapping the boringtun native addon.
|
|
3
|
-
*
|
|
4
|
-
* Manages the UDP socket, port forwarding (plaintext ↔ encrypted), and the
|
|
5
|
-
* 250ms timer loop that drives WireGuard's internal state machine. The native
|
|
6
|
-
* addon handles all cryptographic operations; this module handles I/O.
|
|
7
|
-
*
|
|
8
|
-
* Usage:
|
|
9
|
-
* const tunnel = new SecureTunnel({ privateKey, peerPublicKey, listenPort });
|
|
10
|
-
* await tunnel.start();
|
|
11
|
-
* tunnel.sendPlaintext(Buffer.from("hello"));
|
|
12
|
-
* tunnel.on("plaintext", (data) => console.log("received:", data));
|
|
13
|
-
* tunnel.stop();
|
|
14
|
-
*/
|
|
15
|
-
import * as dgram from "node:dgram";
|
|
16
|
-
import { EventEmitter } from "node:events";
|
|
17
|
-
export interface PacketHandlingDisposition {
|
|
18
|
-
handled: boolean;
|
|
19
|
-
peerPublicKey: string;
|
|
20
|
-
outcome: "no_tunnel" | "done" | "write_to_network" | "write_to_tunnel" | "decrypt_error" | "decrypt_exception";
|
|
21
|
-
errorDetail?: string;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* External shared UDP socket interface.
|
|
25
|
-
* When provided, SecureTunnel uses this socket instead of creating its own.
|
|
26
|
-
* This enables the single-port WireGuard architecture where NetworkManager
|
|
27
|
-
* owns ONE socket for ALL peers (like the real WireGuard kernel module).
|
|
28
|
-
*/
|
|
29
|
-
export interface ExternalSocket {
|
|
30
|
-
/** Send encrypted data to a peer through the shared socket */
|
|
31
|
-
send(data: Buffer, port: number, host: string, cb?: (err?: Error) => void): void;
|
|
32
|
-
/** The bound port of the shared socket (returned from start()) */
|
|
33
|
-
port: number;
|
|
34
|
-
/**
|
|
35
|
-
* Subscribe to incoming packets on the shared socket.
|
|
36
|
-
* The handler receives ALL packets — the tunnel must check if each packet
|
|
37
|
-
* belongs to it (via decrypt) and report whether it consumed the packet.
|
|
38
|
-
* Returns an unsubscribe function.
|
|
39
|
-
*/
|
|
40
|
-
onPacket(handler: (msg: Buffer, rinfo: dgram.RemoteInfo) => PacketHandlingDisposition): () => void;
|
|
41
|
-
}
|
|
42
|
-
export interface SecureTunnelOptions {
|
|
43
|
-
/** Base64-encoded X25519 private key */
|
|
44
|
-
privateKey: string;
|
|
45
|
-
/** Base64-encoded X25519 peer public key */
|
|
46
|
-
peerPublicKey: string;
|
|
47
|
-
/** Optional preshared key (base64) */
|
|
48
|
-
presharedKey?: string;
|
|
49
|
-
/** Persistent keepalive interval in seconds (0 = disabled, default: 25) */
|
|
50
|
-
keepalive?: number;
|
|
51
|
-
/** Local UDP port for WireGuard protocol (default: random high port) */
|
|
52
|
-
listenPort?: number;
|
|
53
|
-
/** Peer's endpoint host */
|
|
54
|
-
peerHost?: string;
|
|
55
|
-
/** Peer's endpoint port */
|
|
56
|
-
peerPort?: number;
|
|
57
|
-
/** Tunnel-internal source IPv4 address as 32-bit integer (default: 10.0.0.1 = 0x0a000001) */
|
|
58
|
-
tunnelSrcIp?: number;
|
|
59
|
-
/** Tunnel-internal destination IPv4 address as 32-bit integer (default: 10.0.0.2 = 0x0a000002) */
|
|
60
|
-
tunnelDstIp?: number;
|
|
61
|
-
/**
|
|
62
|
-
* External shared UDP socket. When provided, the tunnel uses this socket
|
|
63
|
-
* instead of creating its own. This is the single-port WireGuard model
|
|
64
|
-
* where NetworkManager owns ONE socket for ALL peers.
|
|
65
|
-
*/
|
|
66
|
-
externalSocket?: ExternalSocket;
|
|
67
|
-
}
|
|
68
|
-
export interface TunnelStats {
|
|
69
|
-
/** Bytes sent through the tunnel */
|
|
70
|
-
bytesSent: number;
|
|
71
|
-
/** Bytes received through the tunnel */
|
|
72
|
-
bytesReceived: number;
|
|
73
|
-
/** Number of successful handshakes */
|
|
74
|
-
handshakes: number;
|
|
75
|
-
/** Timestamp of last handshake (epoch ms) */
|
|
76
|
-
lastHandshake: number | null;
|
|
77
|
-
/** Whether the tunnel is currently active */
|
|
78
|
-
active: boolean;
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Encrypted UDP tunnel backed by boringtun.
|
|
82
|
-
*
|
|
83
|
-
* Events:
|
|
84
|
-
* - "plaintext": decrypted data received from peer
|
|
85
|
-
* - "handshake": WireGuard handshake completed
|
|
86
|
-
* - "error": tunnel or socket error
|
|
87
|
-
* - "close": tunnel stopped
|
|
88
|
-
*/
|
|
89
|
-
/**
|
|
90
|
-
* Wrap arbitrary data in a minimal valid IPv4 packet for boringtun layer-3 tunnel.
|
|
91
|
-
*
|
|
92
|
-
* WireGuard is a layer-3 VPN — boringtun validates that decrypted plaintext is a
|
|
93
|
-
* valid IPv4 or IPv6 packet before returning it. Raw bytes are rejected with
|
|
94
|
-
* "InvalidPacket". This helper constructs a minimal 20-byte IPv4 header wrapping
|
|
95
|
-
* the given payload.
|
|
96
|
-
*/
|
|
97
|
-
declare function wrapIpv4(payload: Buffer, srcIp?: number, dstIp?: number): Buffer;
|
|
98
|
-
/**
|
|
99
|
-
* Extract payload from an IPv4 packet by reading the IHL field.
|
|
100
|
-
* Optionally validates that the source IP matches the expected peer IP.
|
|
101
|
-
*/
|
|
102
|
-
declare function unwrapIpv4(packet: Buffer, expectedSourceIp?: number): Buffer;
|
|
103
|
-
export { wrapIpv4, unwrapIpv4 };
|
|
104
|
-
export declare class SecureTunnel extends EventEmitter {
|
|
105
|
-
private options;
|
|
106
|
-
private socket;
|
|
107
|
-
private tickTimer;
|
|
108
|
-
private tunnel;
|
|
109
|
-
private stats;
|
|
110
|
-
/** Tracks whether the first successful decrypt has occurred (handshake completed) */
|
|
111
|
-
private handshakeCompleted;
|
|
112
|
-
private peerHost;
|
|
113
|
-
private peerPort;
|
|
114
|
-
/** Unsubscribe function for external socket mode */
|
|
115
|
-
private externalSocketUnsub;
|
|
116
|
-
constructor(options: SecureTunnelOptions);
|
|
117
|
-
/** Start the tunnel — binds UDP socket, creates WireGuard tunnel, starts timer */
|
|
118
|
-
start(): Promise<number>;
|
|
119
|
-
/**
|
|
120
|
-
* Handle an incoming encrypted packet. Called either by our own socket
|
|
121
|
-
* or by the shared socket dispatcher (in shared socket mode).
|
|
122
|
-
*
|
|
123
|
-
* Returns true if this tunnel consumed the packet, false otherwise.
|
|
124
|
-
*/
|
|
125
|
-
handleIncomingPacket(msg: Buffer, rinfo: dgram.RemoteInfo): boolean;
|
|
126
|
-
private classifyIncomingPacket;
|
|
127
|
-
/** Whether the tunnel is currently active */
|
|
128
|
-
get isActive(): boolean;
|
|
129
|
-
/** Send plaintext data through the encrypted tunnel */
|
|
130
|
-
sendPlaintext(data: Buffer): void;
|
|
131
|
-
/** Set or update the peer endpoint */
|
|
132
|
-
setPeerEndpoint(host: string, port: number): void;
|
|
133
|
-
/** Get tunnel statistics */
|
|
134
|
-
getStats(): TunnelStats;
|
|
135
|
-
private markAuthenticatedSessionProof;
|
|
136
|
-
/** Stop the tunnel — closes socket (or unsubscribes from shared), stops timer */
|
|
137
|
-
stop(): void;
|
|
138
|
-
/** Handle a WireGuard tunnel result */
|
|
139
|
-
private handleResult;
|
|
140
|
-
}
|
package/dist/wireguard.node
DELETED
|
Binary file
|
package/index.d.ts
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
/* auto-generated by NAPI-RS */
|
|
2
|
-
/* eslint-disable */
|
|
3
|
-
export declare class WireGuardTunnel {
|
|
4
|
-
/**
|
|
5
|
-
* Create a new WireGuard tunnel.
|
|
6
|
-
*
|
|
7
|
-
* private_key: base64-encoded 32-byte X25519 private key
|
|
8
|
-
* peer_public_key: base64-encoded 32-byte X25519 public key
|
|
9
|
-
* preshared_key: optional base64-encoded 32-byte preshared key
|
|
10
|
-
* keepalive: persistent keepalive interval in seconds (0 = disabled)
|
|
11
|
-
* index: tunnel index for session disambiguation (random if not provided)
|
|
12
|
-
*/
|
|
13
|
-
constructor(privateKey: string, peerPublicKey: string, presharedKey?: string | undefined | null, keepalive?: number | undefined | null, index?: number | undefined | null)
|
|
14
|
-
/**
|
|
15
|
-
* Encrypt plaintext data for sending over the network.
|
|
16
|
-
* Returns { op: "write_to_network", data: Buffer } on success.
|
|
17
|
-
*/
|
|
18
|
-
encrypt(src: Buffer): WireGuardResult
|
|
19
|
-
/**
|
|
20
|
-
* Decrypt data received from the network.
|
|
21
|
-
* Returns { op: "write_to_tunnel", data: Buffer } on success.
|
|
22
|
-
*
|
|
23
|
-
* `src_addr` is the IP address of the packet's sender. It is required by
|
|
24
|
-
* boringtun's rate limiter for cookie-based DoS protection on handshake
|
|
25
|
-
* messages. Passing null/undefined causes handshake packets to be rejected
|
|
26
|
-
* once the rate limiter is under load (after ~10 handshakes).
|
|
27
|
-
*
|
|
28
|
-
* The dst buffer must be large enough for chained output: when a handshake
|
|
29
|
-
* response (92 bytes) is decapsulated, boringtun may chain a queued transport
|
|
30
|
-
* packet whose size depends on the original encrypt() payload, not the
|
|
31
|
-
* handshake response size. We use max(src.len(), 65536) to handle payloads
|
|
32
|
-
* up to the WireGuard maximum segment size.
|
|
33
|
-
*/
|
|
34
|
-
decrypt(src: Buffer, srcAddr?: string | undefined | null): WireGuardResult
|
|
35
|
-
/**
|
|
36
|
-
* Timer tick — must be called every ~250ms.
|
|
37
|
-
* May produce keepalive or handshake initiation packets.
|
|
38
|
-
*/
|
|
39
|
-
tick(): WireGuardResult
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export declare function generateKeypair(): KeyPair
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Generate a new X25519 keypair for WireGuard.
|
|
46
|
-
* Returns { publicKey: string, privateKey: string } (base64-encoded).
|
|
47
|
-
*/
|
|
48
|
-
export interface KeyPair {
|
|
49
|
-
publicKey: string
|
|
50
|
-
privateKey: string
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/** Result from a tunnel operation. */
|
|
54
|
-
export interface WireGuardResult {
|
|
55
|
-
/** "ok" | "done" | "write_to_network" | "write_to_tunnel" | "error" */
|
|
56
|
-
op: string
|
|
57
|
-
/** Output data (if any) */
|
|
58
|
-
data?: Buffer
|
|
59
|
-
}
|