clone

a self-hosted sync node for lofi apps: jazz sync over iroh, ticket-gated, with no static ip or cloud needed

release/0.5.0
lofi-node / native / iroh-js / index.d.ts
index.d.ts 14.7K
1/* auto-generated by NAPI-RS */2/* eslint-disable */3/** A server-side handshake in progress. */4export declare class Accepting {5 connect(): Promise<Connection>6 alpn(): Promise<Array<number>>7}89/** A bidirectional QUIC stream pair. */10export declare class BiStream {11 get send(): SendStream12 get recv(): RecvStream13}1415/** A client-side handshake in progress. */16export declare class Connecting {17 connect(): Promise<Connection>18 alpn(): Promise<Array<number>>19 remoteId(): Promise<EndpointId>20}2122/** An active QUIC connection. */23export declare class Connection {24 alpn(): Array<number>25 remoteId(): EndpointId26 side(): Side27 openUni(): Promise<SendStream>28 acceptUni(): Promise<RecvStream>29 openBi(): Promise<BiStream>30 acceptBi(): Promise<BiStream>31 readDatagram(): Promise<Array<number>>32 closed(): Promise<string>33 closeReason(): string | null34 close(errorCode: bigint, reason: Array<number>): void35 sendDatagram(data: Array<number>): void36 sendDatagramWait(data: Array<number>): Promise<void>37 maxDatagramSize(): number | null38 datagramSendBufferSpace(): number39 stableId(): number40 rtt(): number | null41 stats(): ConnectionStats42 paths(): Array<PathSnapshot>43 watchPaths(callback: (paths: Array<PathSnapshot>) => void): WatchHandle44 watchPathEvents(callback: (event: PathEvent) => void): WatchHandle45 setMaxConcurrentUniStreams(count: bigint): void46 setReceiveWindow(count: bigint): void47 setMaxConcurrentBiStreams(count: bigint): void48}4950/** An iroh endpoint. */51export declare class Endpoint {52 /** Create an endpoint builder (starts empty — apply a preset). */53 static builder(): EndpointBuilder54 /**55 * Bind a new endpoint. Applies the n0 preset, then the given options.56 * For a custom preset use [`Endpoint::builder`].57 */58 static bind(options?: EndpointOptions | undefined | null, relayMode?: RelayMode | undefined | null): Promise<Endpoint>59 /** This endpoint's id. */60 id(): EndpointId61 /** The [`EndpointAddr`] for this endpoint. */62 addr(): EndpointAddr63 /** Look up cached information about a remote endpoint, if any. */64 remoteAddr(id: EndpointId): Promise<EndpointAddr | null>65 /** Current statistics for this endpoint. */66 stats(): Record<string, CounterStats>67 /** The secret key backing this endpoint's identity. */68 secretKey(): SecretKey69 /** Replace the set of advertised ALPNs. */70 setAlpns(alpns: Array<Array<number>>): void71 /** Add an external (manually-known) socket address. */72 addExternalAddr(addr: string): Promise<void>73 /** Remove a previously-added external address. */74 removeExternalAddr(addr: string): Promise<boolean>75 /** The local socket addresses this endpoint is bound to. */76 boundSockets(): Array<string>77 /** Resolves once the endpoint has a usable home relay. */78 online(): Promise<void>79 /** Insert (or replace) a relay configuration at runtime. */80 insertRelay(config: RelayConfig): Promise<void>81 /** Remove a relay configuration at runtime. */82 removeRelay(url: string): Promise<boolean>83 /** Connect to a remote endpoint via the given ALPN. */84 connect(addr: EndpointAddr, alpn: Array<number>): Promise<Connection>85 /** Begin a connection attempt, returning the in-progress handle. */86 connectPending(addr: EndpointAddr, alpn: Array<number>): Promise<Connecting>87 /** Pull the next incoming connection attempt. */88 acceptNext(): Promise<Incoming | null>89 /** Watch for changes to this endpoint's address. */90 watchAddr(callback: (addr: EndpointAddr) => void): WatchHandle91 /** Watch for changes to the connected relays. */92 watchHomeRelay(callback: (relayUrls: Array<string>) => void): WatchHandle93 /** Watch for network-stack changes. */94 watchNetworkChange(callback: () => void): WatchHandle95 /** Close the endpoint. */96 close(): Promise<void>97 /** True if the endpoint is closed. */98 isClosed(): boolean99}100101/**102 * An endpoint's id together with the network-level addresses where it can be103 * reached. Mirrors the uniffi `EndpointAddr` object surface.104 */105export declare class EndpointAddr {106 /** Create a new [`EndpointAddr`]. */107 constructor(id: EndpointId, relayUrl?: string | undefined | null, addresses?: Array<string> | undefined | null)108 /** The endpoint id. */109 id(): EndpointId110 /** The direct (ip:port) addresses of this peer. */111 directAddresses(): Array<string>112 /** The home relay URL for this peer, if known. */113 relayUrl(): string | null114 /** Returns true if both [`EndpointAddr`]s have the same values. */115 equal(other: EndpointAddr): boolean116 /** Clean string representation. */117 toString(): string118}119120/**121 * A mutable handle to an endpoint builder.122 *123 * Mirrors the uniffi `EndpointBuilder`. A "preset" in JS is simply any124 * function `(builder: EndpointBuilder) => void` — call one of the built-in125 * [`presetN0`] / [`presetMinimal`] / [`presetN0DisableRelay`] helpers (which126 * install the crypto provider) and then layer on your own configuration.127 *128 * ```js129 * const b = Endpoint.builder()130 * presetMinimal(b)131 * b.alpns([alpn])132 * const ep = await b.bind()133 * ```134 */135export declare class EndpointBuilder {136 /** Replay the n0 production preset (relays + discovery + crypto provider). */137 applyN0(): void138 /** Replay the minimal preset (crypto provider only, no external deps). */139 applyMinimal(): void140 /** Replay the n0 preset with relays disabled. */141 applyN0DisableRelay(): void142 /** Set the endpoint secret key (32 bytes). */143 secretKey(bytes: Array<number>): void144 /** Set the advertised ALPNs. */145 alpns(alpns: Array<Array<number>>): void146 /** Set the relay mode. */147 relayMode(mode: RelayMode): void148 /** Set the address the endpoint binds to (`host:port`). */149 bindAddr(addr: string): void150 /** Bind the endpoint. */151 bind(): Promise<Endpoint>152}153154/** An endpoint's identifier, a 32-byte ed25519 public key. */155export declare class EndpointId {156 /** Returns true if both [`EndpointId`]s are equal. */157 equals(other: EndpointId): boolean158 /** Get the underlying 32 bytes. */159 toBytes(): Array<number>160 /** Parse an [`EndpointId`] from its base32 representation. */161 static fromString(s: string): EndpointId162 /** Construct an [`EndpointId`] from raw bytes (32 bytes). */163 static fromBytes(bytes: Array<number>): EndpointId164 /** Short base32 prefix. */165 fmtShort(): string166 /** Base32 string form. */167 toString(): string168 /** Verify a signature on `message` against this endpoint's key. */169 verify(message: Array<number>, signature: Signature): void170}171172/** A token containing information for establishing a connection to an endpoint. */173export declare class EndpointTicket {174 /** Wrap an [`EndpointAddr`] into a ticket. */175 static fromAddr(addr: EndpointAddr): EndpointTicket176 /** Parse a ticket from its base32 string form. */177 static fromString(s: string): EndpointTicket178 /** The [`EndpointAddr`] embedded in this ticket. */179 endpointAddr(): EndpointAddr180 /** Base32 string form. */181 toString(): string182}183184/** An incoming connection that has not yet begun its server-side handshake. */185export declare class Incoming {186 accept(): Promise<Accepting>187 refuse(): Promise<void>188 retry(): Promise<void>189 ignore(): Promise<void>190 localAddr(): Promise<IncomingLocalAddr>191 remoteAddr(): Promise<IncomingAddr>192 remoteAddrValidated(): Promise<boolean>193}194195/** The incoming half of a QUIC stream. */196export declare class RecvStream {197 read(sizeLimit: number): Promise<Array<number>>198 readExact(size: number): Promise<Array<number>>199 readToEnd(sizeLimit: number): Promise<Array<number>>200 id(): Promise<string>201 bytesRead(): Promise<number>202 stop(errorCode: bigint): Promise<void>203 receivedReset(): Promise<number | null>204}205206/** A collection of relay servers an endpoint should consider. */207export declare class RelayMap {208 /** Create an empty relay map. */209 static empty(): RelayMap210 /** Build a relay map from a list of relay URLs. */211 static fromUrls(urls: Array<string>): RelayMap212 /** Insert a relay (replacing any prior entry for the same URL). */213 insert(config: RelayConfig): void214 /** Remove the entry for the given relay URL. Returns true if removed. */215 remove(url: string): boolean216 /** Check whether the given relay URL is in the map. */217 contains(url: string): boolean218 /** Look up the configuration for the given relay URL. */219 get(url: string): RelayConfig | null220 /** All relay URLs currently in the map. */221 urls(): Array<string>222 /** Number of relays in the map. */223 len(): number224 /** True if the map has no relays. */225 isEmpty(): boolean226 /** Clean string representation. */227 toString(): string228}229230/** Configuration for which relay servers an endpoint uses. */231export declare class RelayMode {232 /** No relays. */233 static disabled(): RelayMode234 /** Use the n0 production relay map. */235 static defaultMode(): RelayMode236 /** Use the n0 staging relay map. */237 static staging(): RelayMode238 /** Use a custom relay map. */239 static custom(map: RelayMap): RelayMode240 /** Build a custom relay mode from a list of relay URLs. */241 static customFromUrls(urls: Array<string>): RelayMode242 /** The relay map this mode resolves to. */243 relayMap(): RelayMap244 /** Clean string representation. */245 toString(): string246}247248/** The secret key half of an endpoint identity. */249export declare class SecretKey {250 /** Generate a new random secret key. */251 static generate(): SecretKey252 /** Construct from raw bytes (32 bytes). */253 static fromBytes(bytes: Array<number>): SecretKey254 /** Raw 32-byte form. */255 toBytes(): Array<number>256 /** The public [`EndpointId`] derived from this secret key. */257 public(): EndpointId258 /** Sign a message, producing an ed25519 signature. */259 sign(message: Array<number>): Signature260}261262/** The outgoing half of a QUIC stream. */263export declare class SendStream {264 write(buf: Array<number>): Promise<number>265 writeAll(buf: Array<number>): Promise<void>266 finish(): Promise<void>267 reset(errorCode: bigint): Promise<void>268 setPriority(p: number): Promise<void>269 priority(): Promise<number>270 stopped(): Promise<number | null>271 id(): Promise<string>272}273274/** Client for services.iroh.computer. */275export declare class ServicesClient {276 /** Build a new client bound to the given endpoint. */277 static create(endpoint: Endpoint, options: ServicesOptions): Promise<ServicesClient>278 /** Read the current endpoint name from the local client. */279 name(): Promise<string | null>280 /** Set the endpoint name cloud-side. */281 setName(name: string): Promise<void>282 /** Ping the remote service. */283 ping(): Promise<void>284 /** Force a metrics flush. */285 pushMetrics(): Promise<void>286 /** Run a network-diagnostics report, optionally submitting it. */287 submitNetworkDiagnostics(send: boolean): Promise<DiagnosticsSummary>288}289290/** An ed25519 signature over a message. */291export declare class Signature {292 /** Construct from raw bytes (64 bytes). */293 static fromBytes(bytes: Array<number>): Signature294 /** Raw 64-byte form. */295 toBytes(): Array<number>296 /** Lowercase hex representation. */297 toString(): string298}299300/** Handle to a running watcher task. Call `stop()` (or drop) to unregister. */301export declare class WatchHandle {302 /** Stop the watcher, aborting the background task. */303 stop(): Promise<void>304}305306/** Flat snapshot of headline connection statistics. */307export interface ConnectionStats {308 udpTxDatagrams: number309 udpTxBytes: number310 udpRxDatagrams: number311 udpRxBytes: number312 lostPackets: number313 lostBytes: number314}315316/** A snapshot value for a single endpoint metric. */317export interface CounterStats {318 value: number319 description: string320}321322/** Flattened summary of an `iroh_services` diagnostics report. */323export interface DiagnosticsSummary {324 endpointId: string325 directAddrs: Array<string>326 irohVersion: string327 irohServicesVersion: string328 hasNetReport: boolean329 upnp?: boolean330 pcp?: boolean331 natPmp?: boolean332}333334/**335 * Options passed to [`Endpoint::bind`].336 *337 * `bind` applies the n0 preset by default. For a custom preset use338 * [`Endpoint::builder`] + the `EndpointBuilder` surface.339 */340export interface EndpointOptions {341 bindAddr?: string342 secretKey?: Array<number>343 alpns?: Array<Array<number>>344}345346/** Where an incoming connection came from. */347export interface IncomingAddr {348 /** One of "ip" | "relay" | "custom". */349 kind: string350 /** `ip:port` for ip, relay URL for relay. */351 addr?: string352 /** Remote endpoint id (relay only). */353 endpointId?: string354 /** Debug description (custom only). */355 description?: string356}357358/** The local address that received an incoming connection. */359export interface IncomingLocalAddr {360 /** One of "ip" | "relay" | "custom". */361 kind: string362 addr?: string363 description?: string364}365366/** The logging level. See the rust (log crate)[https://docs.rs/log] for more information. */367export declare const enum LogLevel {368 Trace = 'Trace',369 Debug = 'Debug',370 Info = 'Info',371 Warn = 'Warn',372 Error = 'Error',373 Off = 'Off'374}375376/** A path event with its associated data. */377export interface PathEvent {378 kind: PathEventKind379 id?: string380 remoteAddr?: string381 localAddr?: string382 lastStats?: PathStatsRecord383 missed?: number384}385386/** An event from `Connection::watchPathEvents`. */387export declare const enum PathEventKind {388 Opened = 'Opened',389 Closed = 'Closed',390 Selected = 'Selected',391 Lagged = 'Lagged'392}393394/** A flat snapshot of an open path's state. */395export interface PathSnapshot {396 id: string397 isSelected: boolean398 remoteAddr: string399 isIp: boolean400 isRelay: boolean401 rttMs: number402 stats: PathStatsRecord403}404405/** Flattened headline numbers from `noq::PathStats`. */406export interface PathStatsRecord {407 rttMs: number408 udpTxDatagrams: number409 udpTxBytes: number410 udpRxDatagrams: number411 udpRxBytes: number412 cwnd: number413 congestionEvents: number414 lostPackets: number415 lostBytes: number416 currentMtu: number417}418419/** The minimal preset (no external dependencies; good for tests / offline). */420export declare function presetMinimal(builder: EndpointBuilder): void421422/** The n0 production preset (relays + discovery). */423export declare function presetN0(builder: EndpointBuilder): void424425/** The n0 preset with relays disabled. */426export declare function presetN0DisableRelay(builder: EndpointBuilder): void427428/** Config for a single relay server. */429export interface RelayConfig {430 url: string431 quicPort?: number432 authToken?: string433}434435/** Build options for [`ServicesClient`]. */436export interface ServicesOptions {437 /** Encoded API secret string (`services1...`). */438 apiSecret?: string439 /** If true, read the API secret from `IROH_SERVICES_API_SECRET`. */440 apiSecretFromEnv?: boolean441 /** Unencrypted PEM-encoded OpenSSH ed25519 private key. */442 sshKeyPem?: string443 /** Optional endpoint name to register cloud-side. */444 name?: string445 /** Metrics push interval (ms). `0` disables interval pushes. */446 metricsIntervalMs?: number447}448449/** Set the logging level. */450export declare function setLogLevel(level: LogLevel): void451452/** Which side of a connection we are. */453export declare const enum Side {454 Client = 'Client',455 Server = 'Server'456}