@minip2p/core 0.1.0

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Deepso
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,9 @@
1
+ # @minip2p/core
2
+
3
+ Platform-neutral types and SDK behavior for minip2p.
4
+
5
+ Applications normally install a platform package such as `react-native-minip2p` or `@minip2p/node`; those packages bind the SDK to a native backend and re-export the public core types.
6
+
7
+ Adapter authors implement the deliberately small contract exported from `@minip2p/core/backend`. The core package never imports React Native, Node.js, UniFFI, napi-rs, or generated native code.
8
+
9
+ The shared endpoint API covers identity and Identify snapshots, QUIC connections, explicit ping, relay/AutoNAT/DCUtR state, gossipsub or floodsub, signed discovery, mDNS, and arbitrary negotiated protocols/streams. Platform adapters own the background driver that implements Rust's caller-driven poll/wake contract.
@@ -0,0 +1,44 @@
1
+ import type { Bytes, IdentifyInfo, KnownPeerInfo, MiniP2pConfig, P2pEvent, Reachability, RelayReservationInfo } from "./types.js";
2
+ /** Native endpoint operations required by the platform-neutral SDK. */
3
+ export interface MiniP2pBackend {
4
+ start: (listener: (event: P2pEvent) => void) => void;
5
+ close: () => void;
6
+ peerId: () => string;
7
+ listenAddrs: () => string[];
8
+ connectedPeers: () => string[];
9
+ isPeerReady: (peerId: string) => boolean;
10
+ peerInfo: (peerId: string) => IdentifyInfo | undefined;
11
+ knownPeers: () => KnownPeerInfo[];
12
+ discoveryNowMs: () => number | undefined;
13
+ activeReservation: () => RelayReservationInfo | undefined;
14
+ circuitAddress: (relayAddress: string, peerId: string) => string;
15
+ reachability: () => Reachability;
16
+ isRunning: () => boolean;
17
+ setActive: (active: boolean) => void;
18
+ subscribe: (topic: string) => boolean;
19
+ unsubscribe: (topic: string) => boolean;
20
+ publish: (topic: string, data: Uint8Array) => void;
21
+ ping: (peerId: string) => void;
22
+ addProtocol: (protocolId: string) => void;
23
+ openStream: (peerId: string, protocolId: string) => number;
24
+ sendStream: (peerId: string, streamId: number, data: Uint8Array) => void;
25
+ closeStreamWrite: (peerId: string, streamId: number) => void;
26
+ resetStream: (peerId: string, streamId: number) => void;
27
+ abandonStream: (peerId: string, streamId: number) => void;
28
+ connect: (peerId: string) => number;
29
+ connectWithAddrs: (peerId: string, addresses: readonly string[]) => number;
30
+ connectAddr: (address: string) => number;
31
+ dial: (address: string) => number[];
32
+ dialIp4: (address: string) => number;
33
+ dialIp6: (address: string) => number;
34
+ cancelConnect: (id: number) => void;
35
+ disconnect: (peerId: string) => void;
36
+ }
37
+ /** Platform implementation used to construct endpoints and identity helpers. */
38
+ export interface MiniP2pBackendFactory {
39
+ create: (config: MiniP2pConfig) => MiniP2pBackend;
40
+ generateSecretKey: () => Uint8Array;
41
+ peerIdFromSecretKey: (secretKey: Bytes) => string;
42
+ circuitAddress: (relayAddress: string, peerId: string) => string;
43
+ }
44
+ //# sourceMappingURL=backend.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"backend.d.ts","sourceRoot":"","sources":["../src/backend.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,KAAK,EACL,YAAY,EACZ,aAAa,EACb,aAAa,EACb,QAAQ,EACR,YAAY,EACZ,oBAAoB,EACrB,MAAM,YAAY,CAAC;AAEpB,uEAAuE;AACvE,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,QAAQ,KAAK,IAAI,KAAK,IAAI,CAAC;IACrD,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,MAAM,EAAE,MAAM,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,MAAM,EAAE,CAAC;IAC5B,cAAc,EAAE,MAAM,MAAM,EAAE,CAAC;IAC/B,WAAW,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC;IACzC,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,YAAY,GAAG,SAAS,CAAC;IACvD,UAAU,EAAE,MAAM,aAAa,EAAE,CAAC;IAClC,cAAc,EAAE,MAAM,MAAM,GAAG,SAAS,CAAC;IACzC,iBAAiB,EAAE,MAAM,oBAAoB,GAAG,SAAS,CAAC;IAC1D,cAAc,EAAE,CAAC,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,MAAM,CAAC;IACjE,YAAY,EAAE,MAAM,YAAY,CAAC;IACjC,SAAS,EAAE,MAAM,OAAO,CAAC;IACzB,SAAS,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,CAAC;IACrC,SAAS,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC;IACtC,WAAW,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC;IACxC,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,K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D,iBAAiB,EAAE,MAAM,UAAU,CAAC;IACpC,mBAAmB,EAAE,CAAC,SAAS,EAAE,KAAK,KAAK,MAAM,CAAC;IAClD,cAAc,EAAE,CAAC,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,MAAM,CAAC;CAClE"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=backend.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"backend.js","sourceRoot":"","sources":["../src/backend.ts"],"names":[],"mappings":""}
@@ -0,0 +1,32 @@
1
+ import type { DriverFailureKind } from "./types.js";
2
+ /** The native pubsub queue rejected work because it is full. */
3
+ export declare class BackpressureError extends Error {
4
+ constructor();
5
+ }
6
+ /** The payload exceeds the native pubsub protocol limit. */
7
+ export declare class MessageTooLargeError extends Error {
8
+ constructor();
9
+ }
10
+ /** A valid operation was rejected by endpoint policy. */
11
+ export declare class NotPermittedError extends Error {
12
+ constructor(message?: string);
13
+ }
14
+ /** A bounded SDK wait elapsed without a matching event. */
15
+ export declare class TimeoutError extends Error {
16
+ constructor(timeoutMs: number);
17
+ }
18
+ /** The SDK was closed before an operation could complete. */
19
+ export declare class ClosedError extends Error {
20
+ constructor();
21
+ }
22
+ /** The native background driver terminated with a fatal failure. */
23
+ export declare class DriverFailedError extends Error {
24
+ readonly kind: DriverFailureKind;
25
+ constructor(kind: DriverFailureKind, detail: string);
26
+ }
27
+ /** A peer disconnected before the awaited operation could complete. */
28
+ export declare class PeerDisconnectedError extends Error {
29
+ readonly peerId: string;
30
+ constructor(peerId: string);
31
+ }
32
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEpD,gEAAgE;AAChE,qBAAa,iBAAkB,SAAQ,KAAK;;CAK3C;AAED,4DAA4D;AAC5D,qBAAa,oBAAqB,SAAQ,KAAK;;CAK9C;AAED,yDAAyD;AACzD,qBAAa,iBAAkB,SAAQ,KAAK;gBAC9B,OAAO,SAAmC;CAIvD;AAED,2DAA2D;AAC3D,qBAAa,YAAa,SAAQ,KAAK;gBACzB,SAAS,EAAE,MAAM;CAI9B;AAED,6DAA6D;AAC7D,qBAAa,WAAY,SAAQ,KAAK;;CAKrC;AAED,oEAAoE;AACpE,qBAAa,iBAAkB,SAAQ,KAAK;IAC1C,QAAQ,CAAC,IAAI,EAAE,iBAAiB,CAAC;gBAErB,IAAI,EAAE,iBAAiB,EAAE,MAAM,EAAE,MAAM;CAKpD;AAED,uEAAuE;AACvE,qBAAa,qBAAsB,SAAQ,KAAK;IAC9C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;gBAEZ,MAAM,EAAE,MAAM;CAK3B"}
package/dist/errors.js ADDED
@@ -0,0 +1,55 @@
1
+ /* oxlint-disable max-classes-per-file -- The small public SDK error family is intentionally colocated and exported from one module. */
2
+ /** The native pubsub queue rejected work because it is full. */
3
+ export class BackpressureError extends Error {
4
+ constructor() {
5
+ super("The native pubsub queue is full");
6
+ this.name = "BackpressureError";
7
+ }
8
+ }
9
+ /** The payload exceeds the native pubsub protocol limit. */
10
+ export class MessageTooLargeError extends Error {
11
+ constructor() {
12
+ super("The message exceeds the native pubsub size limit");
13
+ this.name = "MessageTooLargeError";
14
+ }
15
+ }
16
+ /** A valid operation was rejected by endpoint policy. */
17
+ export class NotPermittedError extends Error {
18
+ constructor(message = "The operation is not permitted") {
19
+ super(message);
20
+ this.name = "NotPermittedError";
21
+ }
22
+ }
23
+ /** A bounded SDK wait elapsed without a matching event. */
24
+ export class TimeoutError extends Error {
25
+ constructor(timeoutMs) {
26
+ super(`Timed out after ${timeoutMs} ms`);
27
+ this.name = "TimeoutError";
28
+ }
29
+ }
30
+ /** The SDK was closed before an operation could complete. */
31
+ export class ClosedError extends Error {
32
+ constructor() {
33
+ super("The minip2p endpoint is closed");
34
+ this.name = "ClosedError";
35
+ }
36
+ }
37
+ /** The native background driver terminated with a fatal failure. */
38
+ export class DriverFailedError extends Error {
39
+ kind;
40
+ constructor(kind, detail) {
41
+ super(detail.length > 0 ? detail : "The minip2p driver failed");
42
+ this.name = "DriverFailedError";
43
+ this.kind = kind;
44
+ }
45
+ }
46
+ /** A peer disconnected before the awaited operation could complete. */
47
+ export class PeerDisconnectedError extends Error {
48
+ peerId;
49
+ constructor(peerId) {
50
+ super(`Peer ${peerId} disconnected before becoming ready`);
51
+ this.name = "PeerDisconnectedError";
52
+ this.peerId = peerId;
53
+ }
54
+ }
55
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,uIAAuI;AAIvI,gEAAgE;AAChE,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IAC1C;QACE,KAAK,CAAC,iCAAiC,CAAC,CAAC;QACzC,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;IAClC,CAAC;CACF;AAED,4DAA4D;AAC5D,MAAM,OAAO,oBAAqB,SAAQ,KAAK;IAC7C;QACE,KAAK,CAAC,kDAAkD,CAAC,CAAC;QAC1D,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAC;IACrC,CAAC;CACF;AAED,yDAAyD;AACzD,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IAC1C,YAAY,OAAO,GAAG,gCAAgC;QACpD,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;IAClC,CAAC;CACF;AAED,2DAA2D;AAC3D,MAAM,OAAO,YAAa,SAAQ,KAAK;IACrC,YAAY,SAAiB;QAC3B,KAAK,CAAC,mBAAmB,SAAS,KAAK,CAAC,CAAC;QACzC,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;IAC7B,CAAC;CACF;AAED,6DAA6D;AAC7D,MAAM,OAAO,WAAY,SAAQ,KAAK;IACpC;QACE,KAAK,CAAC,gCAAgC,CAAC,CAAC;QACxC,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;IAC5B,CAAC;CACF;AAED,oEAAoE;AACpE,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IACjC,IAAI,CAAoB;IAEjC,YAAY,IAAuB,EAAE,MAAc;QACjD,KAAK,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,2BAA2B,CAAC,CAAC;QAChE,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;QAChC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF;AAED,uEAAuE;AACvE,MAAM,OAAO,qBAAsB,SAAQ,KAAK;IACrC,MAAM,CAAS;IAExB,YAAY,MAAc;QACxB,KAAK,CAAC,QAAQ,MAAM,qCAAqC,CAAC,CAAC;QAC3D,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAC;QACpC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;CACF"}
@@ -0,0 +1,4 @@
1
+ export { BackpressureError, ClosedError, DriverFailedError, MessageTooLargeError, NotPermittedError, PeerDisconnectedError, TimeoutError, } from "./errors.js";
2
+ export { MiniP2pBase } from "./sdk.js";
3
+ export { DiscoverySource, DriverFailureKind, EndpointErrorKind, NatErrorKind, P2pEvent_Tags, PathKind_Tags, PubsubRouter, Reachability, type Bytes, type IdentifyInfo, type KnownPeerInfo, type MiniP2pConfig, type MiniP2pDiscoveryOptions, type MiniP2pMdnsOptions, type MiniP2pEvent, type P2pEvent, type P2pEventByTag, type PathKind, type QueueOverflowEvent, type RelayReservationInfo, type Unsubscribe, } from "./types.js";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,WAAW,EACX,iBAAiB,EACjB,oBAAoB,EACpB,iBAAiB,EACjB,qBAAqB,EACrB,YAAY,GACb,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EACL,eAAe,EACf,iBAAiB,EACjB,iBAAiB,EACjB,YAAY,EACZ,aAAa,EACb,aAAa,EACb,YAAY,EACZ,YAAY,EACZ,KAAK,KAAK,EACV,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,uBAAuB,EAC5B,KAAK,kBAAkB,EACvB,KAAK,YAAY,EACjB,KAAK,QAAQ,EACb,KAAK,aAAa,EAClB,KAAK,QAAQ,EACb,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,EACzB,KAAK,WAAW,GACjB,MAAM,YAAY,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ export { BackpressureError, ClosedError, DriverFailedError, MessageTooLargeError, NotPermittedError, PeerDisconnectedError, TimeoutError, } from "./errors.js";
2
+ export { MiniP2pBase } from "./sdk.js";
3
+ export { DiscoverySource, DriverFailureKind, EndpointErrorKind, NatErrorKind, P2pEvent_Tags, PathKind_Tags, PubsubRouter, Reachability, } from "./types.js";
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,WAAW,EACX,iBAAiB,EACjB,oBAAoB,EACpB,iBAAiB,EACjB,qBAAqB,EACrB,YAAY,GACb,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EACL,eAAe,EACf,iBAAiB,EACjB,iBAAiB,EACjB,YAAY,EACZ,aAAa,EACb,aAAa,EACb,YAAY,EACZ,YAAY,GAcb,MAAM,YAAY,CAAC"}
package/dist/sdk.d.ts ADDED
@@ -0,0 +1,89 @@
1
+ import type { MiniP2pBackend } from "./backend.js";
2
+ import { P2pEvent_Tags } from "./types.js";
3
+ import type { Bytes, IdentifyInfo, KnownPeerInfo, MiniP2pEvent, P2pEventByTag, Reachability, RelayReservationInfo, Unsubscribe } from "./types.js";
4
+ type EventHandler = (event: MiniP2pEvent) => void;
5
+ /**
6
+ * Platform-neutral owner for one native minip2p endpoint.
7
+ *
8
+ * Platform packages extend this class and expose a zero-argument `create`
9
+ * method backed by their native adapter.
10
+ */
11
+ export declare class MiniP2pBase {
12
+ #private;
13
+ protected constructor(backend: MiniP2pBackend, relayAddresses: readonly string[]);
14
+ /** Adds an event subscriber and returns an idempotent unsubscribe function. */
15
+ on(handler: EventHandler): Unsubscribe;
16
+ /** Resolves with the first event matching `predicate`. */
17
+ waitFor<EventType extends MiniP2pEvent>(predicate: (event: MiniP2pEvent) => event is EventType, timeoutMs?: number): Promise<EventType>;
18
+ waitFor(predicate: (event: MiniP2pEvent) => boolean, timeoutMs?: number): Promise<MiniP2pEvent>;
19
+ /** Requests native shutdown and releases the platform backend. */
20
+ close(): void;
21
+ /** Returns the endpoint's base58 peer ID. */
22
+ peerId(): string;
23
+ /** Returns the endpoint's bound peer addresses. */
24
+ listenAddrs(): string[];
25
+ /** Returns currently connected peer IDs. */
26
+ connectedPeers(): string[];
27
+ /** Returns whether Identify has completed for a connected peer. */
28
+ isPeerReady(peerId: string): boolean;
29
+ /** Returns the latest Identify snapshot for a connected peer. */
30
+ peerInfo(peerId: string): IdentifyInfo | undefined;
31
+ /** Returns the normalized discovery address book. */
32
+ knownPeers(): KnownPeerInfo[];
33
+ /** Returns the native discovery monotonic clock, when discovery is enabled. */
34
+ discoveryNowMs(): number | undefined;
35
+ /** Returns the active relay reservation, if one exists. */
36
+ activeReservation(): RelayReservationInfo | undefined;
37
+ /** Returns this endpoint's currently usable circuit address, if known. */
38
+ get circuitAddress(): string | undefined;
39
+ /** Returns the current native reachability state. */
40
+ reachability(): Reachability;
41
+ /** Returns whether the native driver is accepting work. */
42
+ isRunning(): boolean;
43
+ /** Selects foreground or idle native polling. */
44
+ setActive(active: boolean): void;
45
+ /** Subscribes to a pubsub topic. */
46
+ subscribe(topic: string): boolean;
47
+ /** Withdraws a pubsub subscription. */
48
+ unsubscribe(topic: string): boolean;
49
+ /** Publishes UTF-8 text or bytes. */
50
+ publish(topic: string, data: string | Bytes): void;
51
+ /** Sends an explicit ping; the result is emitted as a ping event. */
52
+ ping(peerId: string): void;
53
+ /** Waits until Identify completes for `peerId`. */
54
+ waitPeerReady(peerId: string, timeoutMs?: number): Promise<P2pEventByTag<P2pEvent_Tags.PeerReady>>;
55
+ /** Waits for the next explicit or keepalive ping RTT for `peerId`. */
56
+ waitPingRtt(peerId: string, timeoutMs?: number): Promise<P2pEventByTag<P2pEvent_Tags.PingRttMeasured>>;
57
+ /** Registers an application protocol at runtime. */
58
+ addProtocol(protocolId: string): void;
59
+ /** Opens a negotiated custom-protocol stream. */
60
+ openStream(peerId: string, protocolId: string): number;
61
+ /** Sends UTF-8 text or bytes on a custom-protocol stream. */
62
+ sendStream(peerId: string, streamId: number, data: string | Bytes): void;
63
+ /** Half-closes the local write side of a stream. */
64
+ closeStreamWrite(peerId: string, streamId: number): void;
65
+ /** Resets a stream while retaining later close events. */
66
+ resetStream(peerId: string, streamId: number): void;
67
+ /** Resets and forgets a stream, suppressing later stream events. */
68
+ abandonStream(peerId: string, streamId: number): void;
69
+ /** Starts a connection attempt and returns its endpoint-local ID. */
70
+ connect(peerId: string): number;
71
+ /** Starts a NAT connection attempt using an explicit ordered address set. */
72
+ connectWithAddrs(peerId: string, addresses: readonly string[]): number;
73
+ /** Waits for a connection attempt's first usable path or terminal failure. */
74
+ waitConnectResult(connectId: number, timeoutMs?: number): Promise<P2pEventByTag<P2pEvent_Tags.PathEstablished> | P2pEventByTag<P2pEvent_Tags.ConnectFailed>>;
75
+ /** Starts a direct-address connection attempt. */
76
+ connectAddr(address: string): number;
77
+ /** Dials a direct address on every applicable local address family. */
78
+ dial(address: string): number[];
79
+ /** Dials a direct address using IPv4. */
80
+ dialIp4(address: string): number;
81
+ /** Dials a direct address using IPv6. */
82
+ dialIp6(address: string): number;
83
+ /** Suppresses future events for a known connection attempt. */
84
+ cancelConnect(id: number): void;
85
+ /** Closes an established connection to a peer. */
86
+ disconnect(peerId: string): void;
87
+ }
88
+ export {};
89
+ //# sourceMappingURL=sdk.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sdk.d.ts","sourceRoot":"","sources":["../src/sdk.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAOnD,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,KAAK,EACV,KAAK,EACL,YAAY,EACZ,aAAa,EACb,YAAY,EAEZ,aAAa,EACb,YAAY,EACZ,oBAAoB,EACpB,WAAW,EACZ,MAAM,YAAY,CAAC;AAapB,KAAK,YAAY,GAAG,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,CAAC;AAmIlD;;;;;GAKG;AACH,qBAAa,WAAW;;IAetB,SAAS,aACP,OAAO,EAAE,cAAc,EACvB,cAAc,EAAE,SAAS,MAAM,EAAE;IAcnC,+EAA+E;IAC/E,EAAE,CAAC,OAAO,EAAE,YAAY,GAAG,WAAW;IAYtC,0DAA0D;IAC1D,OAAO,CAAC,SAAS,SAAS,YAAY,EACpC,SAAS,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,KAAK,IAAI,SAAS,EACtD,SAAS,CAAC,EAAE,MAAM,GACjB,OAAO,CAAC,SAAS,CAAC;IACrB,OAAO,CACL,SAAS,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,OAAO,EAC3C,SAAS,CAAC,EAAE,MAAM,GACjB,OAAO,CAAC,YAAY,CAAC;IAoBxB,kEAAkE;IAClE,KAAK,IAAI,IAAI;IAiBb,6CAA6C;IAC7C,MAAM,IAAI,MAAM;IAKhB,mDAAmD;IACnD,WAAW,IAAI,MA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