@aria-cli/wireguard 1.0.37 → 1.0.39

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.
@@ -0,0 +1,2 @@
1
+ export declare function loadStoredBootstrapCaCert(ariaDir: string): string | undefined;
2
+ //# sourceMappingURL=bootstrap-authority.d.ts.map
@@ -0,0 +1,14 @@
1
+ export interface BootstrapTlsRequestOptions {
2
+ method?: string;
3
+ body?: string;
4
+ headers?: Record<string, string>;
5
+ timeoutMs?: number;
6
+ caCert: string;
7
+ expectedTlsIdentity: string;
8
+ }
9
+ export interface BootstrapTlsResponse {
10
+ status: number;
11
+ body: string;
12
+ }
13
+ export declare function bootstrapTlsRequest(url: string, options: BootstrapTlsRequestOptions): Promise<BootstrapTlsResponse>;
14
+ //# sourceMappingURL=bootstrap-tls.d.ts.map
@@ -0,0 +1,10 @@
1
+ import type Database from "better-sqlite3";
2
+ export declare class StaleOwnerError extends Error {
3
+ readonly kind: "StaleOwnerError";
4
+ readonly claimedGeneration: number;
5
+ readonly currentGeneration: number;
6
+ constructor(claimed: number, current: number);
7
+ }
8
+ export declare function ensureOwnerEpochTable(db: Database.Database): void;
9
+ export declare function claimDbOwnerEpoch(db: Database.Database, generation: number): void;
10
+ //# sourceMappingURL=db-owner-fencing.d.ts.map
@@ -0,0 +1,75 @@
1
+ /**
2
+ * DerpRelay — DERP relay client for NAT traversal.
3
+ *
4
+ * When both peers are behind symmetric NAT, direct WireGuard tunnels fail.
5
+ * DerpRelay connects to a relay server via WebSocket and forwards encrypted
6
+ * WireGuard packets through it. The relay CANNOT read the content (WireGuard
7
+ * encryption is end-to-end).
8
+ *
9
+ * Implements the same { send(data: Buffer): void } interface as tunnel transports,
10
+ * so it plugs into Mailbox.registerTunnel() transparently.
11
+ *
12
+ * Authentication: Ed25519 signature challenge on connect to prevent impersonation.
13
+ * Auto-reconnect: Exponential backoff, matching ResilientTunnel's pattern.
14
+ */
15
+ import { EventEmitter } from "node:events";
16
+ import { type NodeId } from "@aria-cli/tools";
17
+ export interface DerpRelayOptions {
18
+ /** Relay server URL (e.g., wss://relay.example.com/api/v1/relay) */
19
+ relayUrl: string;
20
+ /** Our durable node identity for relay auth */
21
+ nodeId: NodeId;
22
+ /** Optional display snapshot for local logs/debug output */
23
+ displayNameSnapshot?: string;
24
+ /** Ed25519 private key (base64 PKCS#8 DER) for authentication */
25
+ signingPrivateKey: string;
26
+ /** Ed25519 public key (base64 SPKI DER) for identification */
27
+ signingPublicKey: string;
28
+ /** Target node identity to communicate with */
29
+ targetNodeId: NodeId;
30
+ /** AbortSignal for clean shutdown */
31
+ signal?: AbortSignal;
32
+ }
33
+ export type DerpRelayState = "disconnected" | "connecting" | "authenticating" | "connected" | "dead";
34
+ /**
35
+ * DERP relay client.
36
+ *
37
+ * Emits: "plaintext" (data: Buffer, fromNodeId: NodeId, displayNameSnapshot?: string), "connected", "disconnected",
38
+ * "dead", "error" (Error), "stateChange" (newState, prevState)
39
+ */
40
+ export declare class DerpRelay extends EventEmitter {
41
+ private ws;
42
+ private _state;
43
+ private reconnectAttempts;
44
+ private reconnectTimer;
45
+ private stopped;
46
+ private closing;
47
+ private readonly relayUrl;
48
+ private readonly nodeId;
49
+ private readonly displayNameSnapshot?;
50
+ private readonly signingPrivateKey;
51
+ private readonly signingPublicKey;
52
+ private readonly targetNodeId;
53
+ private readonly signal?;
54
+ /** Queued messages while not connected */
55
+ private queue;
56
+ private static readonly MAX_QUEUE;
57
+ constructor(options: DerpRelayOptions);
58
+ /** Connect to the relay server */
59
+ connect(): Promise<void>;
60
+ /** Send data through the relay to the target peer */
61
+ send(data: Buffer): void;
62
+ /** Disconnect from the relay server */
63
+ disconnect(): void;
64
+ /** Get current relay state */
65
+ getState(): DerpRelayState;
66
+ /** Whether the relay is actively connected */
67
+ get isConnected(): boolean;
68
+ private setState;
69
+ private signChallenge;
70
+ private attemptReconnect;
71
+ private clearReconnectTimer;
72
+ private enqueue;
73
+ private flushQueue;
74
+ }
75
+ //# sourceMappingURL=derp-relay.d.ts.map
@@ -0,0 +1,53 @@
1
+ /**
2
+ * @aria/wireguard — WireGuard native addon for ARIA secure networking.
3
+ *
4
+ * Wraps Cloudflare's boringtun (BSD-3) via napi-rs for userspace
5
+ * encrypted tunnels. Three hot-path functions: encrypt, decrypt, tick.
6
+ *
7
+ * @packageDocumentation
8
+ */
9
+ export interface WireGuardResult {
10
+ /** "done" | "write_to_network" | "write_to_tunnel" | "error" */
11
+ op: string;
12
+ /** Output data (if any) */
13
+ data?: Buffer;
14
+ }
15
+ export interface KeyPair {
16
+ publicKey: string;
17
+ privateKey: string;
18
+ }
19
+ export interface WireGuardTunnelOptions {
20
+ /** Base64-encoded X25519 private key */
21
+ privateKey: string;
22
+ /** Base64-encoded X25519 peer public key */
23
+ peerPublicKey: string;
24
+ /** Optional base64-encoded preshared key */
25
+ presharedKey?: string;
26
+ /** Persistent keepalive interval in seconds (0 = disabled) */
27
+ keepalive?: number;
28
+ /** Tunnel index for session disambiguation (random if not provided) */
29
+ index?: number;
30
+ }
31
+ /** Validate that the native addon can be loaded in the current runtime. */
32
+ export declare function assertNativeAddonAvailable(): void;
33
+ /** Create a new WireGuard tunnel */
34
+ export declare function createTunnel(options: WireGuardTunnelOptions): {
35
+ encrypt(src: Buffer): WireGuardResult;
36
+ decrypt(src: Buffer, srcAddr?: string | undefined | null): WireGuardResult;
37
+ tick(): WireGuardResult;
38
+ };
39
+ /** Generate a new X25519 keypair for WireGuard */
40
+ export declare function generateKeypair(): KeyPair;
41
+ export { SecureTunnel } from "./tunnel.js";
42
+ export type { SecureTunnelOptions, TunnelStats } from "./tunnel.js";
43
+ export { ResilientTunnel } from "./resilient-tunnel.js";
44
+ export type { TunnelState, ResilientTunnelStats } from "./resilient-tunnel.js";
45
+ export { StunClient, discoverEndpoint, detectNatType } from "./nat.js";
46
+ export type { StunResult, NatType } from "./nat.js";
47
+ export { NetworkManager, PeerRegistry, generateKeyPair, generateSigningKeypair, createInviteToken, decodeInviteToken, ensureSecureNetwork, } from "./network.js";
48
+ export type { NetworkConfig, PeerInfo, InviteToken } from "./network.js";
49
+ export { PeerDiscoveryService } from "./peer-discovery.js";
50
+ export type { PeerDiscoveryOptions, DiscoveredPeer, PeerDiscoveryNetworkManager, } from "./peer-discovery.js";
51
+ export { DerpRelay } from "./derp-relay.js";
52
+ export type { DerpRelayOptions, DerpRelayState } from "./derp-relay.js";
53
+ //# sourceMappingURL=index.d.ts.map
package/dist/nat.d.ts ADDED
@@ -0,0 +1,84 @@
1
+ /**
2
+ * STUN client + NAT traversal for ARIA secure networking.
3
+ *
4
+ * Discovers external IP:port via STUN (RFC 5389), enabling WireGuard
5
+ * peers to find each other through NAT. Falls back to a UDP relay
6
+ * when symmetric NAT prevents direct connectivity.
7
+ *
8
+ * No external dependencies — implements STUN binding request/response
9
+ * directly using node:dgram.
10
+ */
11
+ import * as dgram from "node:dgram";
12
+ /** Result of STUN endpoint discovery */
13
+ export interface StunResult {
14
+ /** External (public) IP address */
15
+ address: string;
16
+ /** External (public) port */
17
+ port: number;
18
+ /** STUN server used for discovery */
19
+ server: string;
20
+ }
21
+ /**
22
+ * Discover our external endpoint by sending a STUN Binding Request.
23
+ *
24
+ * Tries multiple STUN servers in parallel, returns the first successful response.
25
+ * Timeout: 3 seconds per server, 5 second total.
26
+ */
27
+ /**
28
+ * Discover external endpoint via STUN.
29
+ *
30
+ * @param server STUN server hostname:port (or undefined to try defaults)
31
+ * @param timeoutMs Timeout in milliseconds
32
+ * @param existingSocket Optional: use this socket for STUN instead of creating
33
+ * ephemeral ones. This is critical for the shared-socket WG model — STUN must
34
+ * discover the NAT mapping of the ACTUAL listening socket, not a throwaway one.
35
+ * When provided, the socket is NOT closed after discovery.
36
+ */
37
+ export declare function discoverEndpoint(server?: string, timeoutMs?: number, existingSocket?: dgram.Socket): Promise<StunResult>;
38
+ /**
39
+ * NAT type classification.
40
+ *
41
+ * Detected by comparing mapped ports from two different STUN servers:
42
+ * - Same port from both servers → Full Cone or Restricted Cone (direct tunnel works)
43
+ * - Different port from each server → Symmetric NAT (needs relay)
44
+ */
45
+ export type NatType = "full_cone" | "restricted" | "symmetric" | "unknown";
46
+ /**
47
+ * Detect NAT type by querying two STUN servers and comparing mapped ports.
48
+ *
49
+ * Symmetric NAT allocates a new external port for each destination,
50
+ * so mapped ports will differ across STUN servers. Cone NATs reuse
51
+ * the same external port, so mapped ports will match.
52
+ *
53
+ * Returns "unknown" if fewer than 2 STUN servers respond.
54
+ */
55
+ export declare function detectNatType(servers?: string[], timeoutMs?: number): Promise<{
56
+ natType: NatType;
57
+ results: StunResult[];
58
+ }>;
59
+ /**
60
+ * STUN client for periodic endpoint discovery.
61
+ *
62
+ * Use for ongoing NAT traversal — discovers and tracks endpoint changes.
63
+ */
64
+ export declare class StunClient {
65
+ private servers;
66
+ private pollIntervalMs;
67
+ private interval;
68
+ private lastResult;
69
+ private _natType;
70
+ /** Number of consecutive discovery failures (reset to 0 on success) */
71
+ consecutiveFailures: number;
72
+ constructor(servers?: string[], pollIntervalMs?: number);
73
+ /** Get the detected NAT type (null if not yet detected) */
74
+ getNatType(): NatType | null;
75
+ /** Get the last discovered endpoint */
76
+ getEndpoint(): StunResult | null;
77
+ /** Discover endpoint once — uses first configured server (or defaults) */
78
+ discover(): Promise<StunResult>;
79
+ /** Start periodic endpoint discovery. Detects NAT type on first call. */
80
+ start(onUpdate?: (result: StunResult) => void): void;
81
+ /** Stop periodic discovery */
82
+ stop(): void;
83
+ }
84
+ //# sourceMappingURL=nat.d.ts.map
@@ -0,0 +1,46 @@
1
+ /**
2
+ * NetworkStateStore — canonical, machine-scoped persistence for network control-plane state.
3
+ *
4
+ * All network-adjacent durable state (peers, signing keys, revocations, nonces, trust)
5
+ * lives in ONE canonical store at ARIA_HOME/network/state.db, independent of any
6
+ * arion-specific Memoria DB. This eliminates the split-brain where peer state could
7
+ * drift across multiple DB paths.
8
+ *
9
+ * PeerRegistry, RevocationStore, and other network stores all use the Database
10
+ * returned by getDatabase().
11
+ */
12
+ import type Database from "better-sqlite3";
13
+ export interface NetworkStateStoreOptions {
14
+ /** Base ARIA home directory (e.g., ~/.aria) */
15
+ ariaHome: string;
16
+ /** Override DB path (for testing) */
17
+ dbPath?: string;
18
+ }
19
+ export declare class NetworkStateStore {
20
+ private readonly options;
21
+ private db;
22
+ private readonly dbPath;
23
+ constructor(options: NetworkStateStoreOptions);
24
+ /** Canonical path to the network state DB */
25
+ get path(): string;
26
+ /** Whether the store has been opened */
27
+ get isOpen(): boolean;
28
+ /** Open the database, creating schema if needed */
29
+ open(): Database.Database;
30
+ private reconcilePeerTableSchema;
31
+ /** Get the underlying Database handle (opens if needed) */
32
+ getDatabase(): Database.Database;
33
+ /**
34
+ * Claim the owner epoch for this runtime on the shared network state DB.
35
+ * Must be called after open() and before any durable writes.
36
+ * Throws StaleOwnerError if a newer generation already owns the DB.
37
+ */
38
+ claimOwnerEpoch(generation: number): void;
39
+ /** Close the database */
40
+ close(): void;
41
+ }
42
+ /**
43
+ * Resolve the canonical network state DB path for a given ARIA home.
44
+ */
45
+ export declare function canonicalNetworkStatePath(ariaHome: string): string;
46
+ //# sourceMappingURL=network-state-store.d.ts.map