@minip2p/web 0.0.0-stage → 0.10.1
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 +21 -0
- package/README.md +65 -2
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -0
- package/dist/io.d.ts +107 -0
- package/dist/io.d.ts.map +1 -0
- package/dist/io.js +480 -0
- package/dist/io.js.map +1 -0
- package/dist/manual.d.ts +10 -0
- package/dist/manual.d.ts.map +1 -0
- package/dist/manual.js +10 -0
- package/dist/manual.js.map +1 -0
- package/dist/sdk.d.ts +35 -0
- package/dist/sdk.d.ts.map +1 -0
- package/dist/sdk.js +191 -0
- package/dist/sdk.js.map +1 -0
- package/dist/wasm.d.ts +18 -0
- package/dist/wasm.d.ts.map +1 -0
- package/dist/wasm.js +37 -0
- package/dist/wasm.js.map +1 -0
- package/package.json +75 -3
- package/src/index.ts +19 -0
- package/src/io.ts +601 -0
- package/src/manual.ts +17 -0
- package/src/sdk.ts +237 -0
- package/src/wasm.ts +48 -0
- package/wasm/minip2p_web.d.ts +241 -0
- package/wasm/minip2p_web.js +1100 -0
- package/wasm/minip2p_web_bg.wasm +0 -0
- package/wasm/minip2p_web_bg.wasm.d.ts +48 -0
package/src/sdk.ts
ADDED
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
/* oxlint-disable func-style, max-classes-per-file, no-use-before-define -- Hoisted helpers keep the public entry points first. */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The implementation both entry points share: `Minip2p` over the wasm
|
|
5
|
+
* module's `WebEndpoint`, the key helpers, and `initMinip2p`.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
ClosedError,
|
|
10
|
+
DriverFailedError,
|
|
11
|
+
DriverFailureKind,
|
|
12
|
+
Minip2pBase,
|
|
13
|
+
} from "@minip2p/core";
|
|
14
|
+
import type { Bytes, Minip2pConfig } from "@minip2p/core";
|
|
15
|
+
import { resolveEndpointConfig } from "@minip2p/core/backend";
|
|
16
|
+
import type { Minip2pBackend } from "@minip2p/core/backend";
|
|
17
|
+
import { SerdeBackend, typedNativeCall } from "@minip2p/core/serde-backend";
|
|
18
|
+
|
|
19
|
+
import { JsIo } from "./io.js";
|
|
20
|
+
import { loadWasm, wasm } from "./wasm.js";
|
|
21
|
+
import type { WasmSource } from "./wasm.js";
|
|
22
|
+
|
|
23
|
+
/** Options for {@link initMinip2p}. */
|
|
24
|
+
export interface InitMinip2pOptions {
|
|
25
|
+
/**
|
|
26
|
+
* The `.wasm`: a URL, a `Response`, its bytes, or a compiled
|
|
27
|
+
* `WebAssembly.Module`. Defaults to the file beside the package.
|
|
28
|
+
*/
|
|
29
|
+
readonly wasm?: WasmSource;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Loads minip2p's wasm module. `@minip2p/web` calls it at import;
|
|
34
|
+
* `@minip2p/web/manual` leaves it to the host, which must await it before
|
|
35
|
+
* `Minip2p.create`. Safe to call again: later calls share the first load
|
|
36
|
+
* that succeeds, and a failed load can be retried.
|
|
37
|
+
*/
|
|
38
|
+
export async function initMinip2p(
|
|
39
|
+
options: InitMinip2pOptions = {}
|
|
40
|
+
): Promise<void> {
|
|
41
|
+
await loadWasm(options.wasm);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** High-level browser owner for one minip2p endpoint. */
|
|
45
|
+
export class Minip2p extends Minip2pBase {
|
|
46
|
+
private constructor(backend: Minip2pBackend, relays: readonly string[]) {
|
|
47
|
+
super(backend, relays);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Constructs and starts a browser endpoint. */
|
|
51
|
+
static create(config: Minip2pConfig): Minip2p {
|
|
52
|
+
return new Minip2p(webBackend(config), config.relays ?? []);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Generates a new 32-byte Ed25519 secret key with `crypto.getRandomValues`. */
|
|
57
|
+
export function generateSecretKey(): Uint8Array {
|
|
58
|
+
return typedNativeCall(() => wasm().generateSecretKey());
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Derives a peer ID from raw Ed25519 secret key material. */
|
|
62
|
+
export function peerIdFromSecretKey(secretKey: Bytes): string {
|
|
63
|
+
return typedNativeCall(() =>
|
|
64
|
+
wasm().peerIdFromSecretKey(toUint8Array(secretKey))
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Builds a circuit multiaddress through a direct relay address. */
|
|
69
|
+
export function circuitAddress(relayAddress: string, peerId: string): string {
|
|
70
|
+
return typedNativeCall(() => wasm().circuitAddress(relayAddress, peerId));
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** Polls a batch of rounds back to back before yielding the event loop. */
|
|
74
|
+
const PUMP_ROUNDS = 64;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Drives the wasm endpoint on the page's event loop: one coalesced
|
|
78
|
+
* microtask per burst of calls and I/O events, at most {@link PUMP_ROUNDS}
|
|
79
|
+
* polls before yielding with `setTimeout(0)`, and one re-armed timer for
|
|
80
|
+
* the endpoint's next deadline.
|
|
81
|
+
*/
|
|
82
|
+
class Pump {
|
|
83
|
+
readonly #poll: () => number | undefined;
|
|
84
|
+
#queued = false;
|
|
85
|
+
#timer: ReturnType<typeof setTimeout> | undefined;
|
|
86
|
+
#stopped = false;
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* `poll` pumps once and returns the delay until the next pump; a throw
|
|
90
|
+
* stops the pump for good.
|
|
91
|
+
*/
|
|
92
|
+
constructor(poll: () => number | undefined) {
|
|
93
|
+
this.#poll = poll;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
schedule(): void {
|
|
97
|
+
if (this.#queued || this.#stopped) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
this.#queued = true;
|
|
101
|
+
queueMicrotask(() => {
|
|
102
|
+
this.#run();
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
stop(): void {
|
|
107
|
+
this.#stopped = true;
|
|
108
|
+
clearTimeout(this.#timer);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
#run(): void {
|
|
112
|
+
this.#queued = false;
|
|
113
|
+
clearTimeout(this.#timer);
|
|
114
|
+
this.#timer = undefined;
|
|
115
|
+
for (let round = 0; round < PUMP_ROUNDS && !this.#stopped; round += 1) {
|
|
116
|
+
let delay: number | undefined;
|
|
117
|
+
try {
|
|
118
|
+
delay = this.#poll();
|
|
119
|
+
} catch {
|
|
120
|
+
// The endpoint failed, and its owner already reported it.
|
|
121
|
+
this.stop();
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
if (delay === undefined) {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
if (delay > 0) {
|
|
128
|
+
this.#arm(delay);
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
// Still busy: let the page run, then carry on.
|
|
133
|
+
this.#arm(0);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
#arm(delay: number): void {
|
|
137
|
+
if (this.#stopped) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
this.#timer = setTimeout(() => {
|
|
141
|
+
this.#timer = undefined;
|
|
142
|
+
this.schedule();
|
|
143
|
+
}, delay);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Calls into one wasm instance. A trap (`WebAssembly.RuntimeError`, which a
|
|
149
|
+
* Rust panic becomes on wasm32) leaves the instance unusable: the call that
|
|
150
|
+
* hit it throws `DriverFailedError`, `onFail` fails the endpoint, and every
|
|
151
|
+
* later call throws `ClosedError` without touching wasm again.
|
|
152
|
+
*/
|
|
153
|
+
class WasmCalls {
|
|
154
|
+
readonly #onFail: (detail: string) => void;
|
|
155
|
+
/** Trapped, or the instance was freed. */
|
|
156
|
+
#failed = false;
|
|
157
|
+
|
|
158
|
+
constructor(onFail: (detail: string) => void) {
|
|
159
|
+
this.#onFail = onFail;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
call<T>(operation: () => T): T {
|
|
163
|
+
if (this.#failed) {
|
|
164
|
+
throw new ClosedError();
|
|
165
|
+
}
|
|
166
|
+
try {
|
|
167
|
+
return operation();
|
|
168
|
+
} catch (error) {
|
|
169
|
+
if (!(error instanceof WebAssembly.RuntimeError)) {
|
|
170
|
+
throw error;
|
|
171
|
+
}
|
|
172
|
+
this.#failed = true;
|
|
173
|
+
const detail = `the minip2p wasm module trapped: ${error.message}`;
|
|
174
|
+
this.#onFail(detail);
|
|
175
|
+
throw new DriverFailedError(DriverFailureKind.Panic, detail);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/** Runs `free` unless the instance trapped; later calls throw `ClosedError`. */
|
|
180
|
+
release(free: () => void): void {
|
|
181
|
+
if (!this.#failed) {
|
|
182
|
+
this.#failed = true;
|
|
183
|
+
free();
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function webBackend(config: Minip2pConfig): Minip2pBackend {
|
|
189
|
+
const module = wasm();
|
|
190
|
+
// A trapped instance can neither close its sessions nor be freed: close
|
|
191
|
+
// them from TypeScript.
|
|
192
|
+
const calls = new WasmCalls((detail) => {
|
|
193
|
+
pump.stop();
|
|
194
|
+
io.dispose();
|
|
195
|
+
backend.fail(detail);
|
|
196
|
+
});
|
|
197
|
+
const pump = new Pump(() => calls.call(() => endpoint.pump()));
|
|
198
|
+
const io = new JsIo(() => {
|
|
199
|
+
pump.schedule();
|
|
200
|
+
});
|
|
201
|
+
const endpoint = typedNativeCall(
|
|
202
|
+
() =>
|
|
203
|
+
new module.WebEndpoint(
|
|
204
|
+
toUint8Array(config.secretKey),
|
|
205
|
+
resolveEndpointConfig(config),
|
|
206
|
+
io
|
|
207
|
+
)
|
|
208
|
+
);
|
|
209
|
+
const backend = new SerdeBackend(endpoint, {
|
|
210
|
+
// Every command may queue work (a dial, a write): pump after it.
|
|
211
|
+
call: (operation) => {
|
|
212
|
+
try {
|
|
213
|
+
return calls.call(operation);
|
|
214
|
+
} finally {
|
|
215
|
+
pump.schedule();
|
|
216
|
+
}
|
|
217
|
+
},
|
|
218
|
+
circuitAddress,
|
|
219
|
+
// Closed and drained: stop pumping and free the wasm object, which
|
|
220
|
+
// drops its doorbell and `JsIo`.
|
|
221
|
+
release: () => {
|
|
222
|
+
pump.stop();
|
|
223
|
+
calls.release(() => {
|
|
224
|
+
endpoint.free();
|
|
225
|
+
});
|
|
226
|
+
},
|
|
227
|
+
schedule: (task) => {
|
|
228
|
+
queueMicrotask(task);
|
|
229
|
+
},
|
|
230
|
+
});
|
|
231
|
+
return backend;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/** A view wasm-bindgen copies into wasm memory before the call returns. */
|
|
235
|
+
function toUint8Array(value: Bytes): Uint8Array {
|
|
236
|
+
return value instanceof Uint8Array ? value : new Uint8Array(value);
|
|
237
|
+
}
|
package/src/wasm.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The minip2p wasm module (`crates/web`) and its one-time initialisation.
|
|
3
|
+
* Nothing here fetches on import: `@minip2p/web` initialises at its own
|
|
4
|
+
* import, `@minip2p/web/manual` when the host calls `initMinip2p`.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import init, * as glue from "../wasm/minip2p_web.js";
|
|
8
|
+
import type { InitInput } from "../wasm/minip2p_web.js";
|
|
9
|
+
|
|
10
|
+
/** Where the `.wasm` comes from: a URL, a `Response`, its bytes, or a compiled module. */
|
|
11
|
+
export type WasmSource = InitInput | Promise<InitInput>;
|
|
12
|
+
|
|
13
|
+
let loading: Promise<void> | undefined;
|
|
14
|
+
let loaded = false;
|
|
15
|
+
|
|
16
|
+
const instantiate = async (source: WasmSource | undefined): Promise<void> => {
|
|
17
|
+
// wasm-bindgen fetches a string or URL only when it is passed directly,
|
|
18
|
+
// so a promised one is awaited here first.
|
|
19
|
+
await init(
|
|
20
|
+
source === undefined ? undefined : { module_or_path: await source }
|
|
21
|
+
);
|
|
22
|
+
loaded = true;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Instantiates the module once; later calls share the first that succeeds.
|
|
27
|
+
* Without `source`, the `.wasm` beside this package is fetched (resolved
|
|
28
|
+
* from `import.meta.url`). A failed load can be retried, with another source.
|
|
29
|
+
*/
|
|
30
|
+
export const loadWasm = async (source?: WasmSource): Promise<void> => {
|
|
31
|
+
loading ??= instantiate(source);
|
|
32
|
+
try {
|
|
33
|
+
await loading;
|
|
34
|
+
} catch (error) {
|
|
35
|
+
loading = undefined;
|
|
36
|
+
throw error;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/** The initialised module's exports; throws until {@link loadWasm} resolved. */
|
|
41
|
+
export const wasm = (): typeof glue => {
|
|
42
|
+
if (!loaded) {
|
|
43
|
+
throw new Error(
|
|
44
|
+
"minip2p's wasm module is not initialised: import @minip2p/web, or await initMinip2p() from @minip2p/web/manual before creating an endpoint"
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
return glue;
|
|
48
|
+
};
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A minip2p endpoint in the browser, dialing over WebTransport.
|
|
6
|
+
*
|
|
7
|
+
* It is driven by its TypeScript owner: every call returns at once, and
|
|
8
|
+
* `pump` polls the endpoint, which the owner schedules after each call, each
|
|
9
|
+
* `JsIo` event, and at the deadline `pump` returns.
|
|
10
|
+
*/
|
|
11
|
+
export class WebEndpoint {
|
|
12
|
+
free(): void;
|
|
13
|
+
[Symbol.dispose](): void;
|
|
14
|
+
/**
|
|
15
|
+
* Resets and relinquishes a stream.
|
|
16
|
+
*/
|
|
17
|
+
abandonStream(conn_id: bigint, stream_id: bigint): void;
|
|
18
|
+
/**
|
|
19
|
+
* The relay reservation currently held, or `null`.
|
|
20
|
+
*/
|
|
21
|
+
activeReservation(): any;
|
|
22
|
+
/**
|
|
23
|
+
* Registers an application protocol.
|
|
24
|
+
*/
|
|
25
|
+
addProtocol(protocol_id: string): void;
|
|
26
|
+
/**
|
|
27
|
+
* Cancels a Connection attempt.
|
|
28
|
+
*/
|
|
29
|
+
cancelConnect(id: bigint): void;
|
|
30
|
+
/**
|
|
31
|
+
* Half-closes a stream's write side.
|
|
32
|
+
*/
|
|
33
|
+
closeStreamWrite(conn_id: bigint, stream_id: bigint): void;
|
|
34
|
+
/**
|
|
35
|
+
* Closes the endpoint; `EndpointClosed` is the last event drained.
|
|
36
|
+
*
|
|
37
|
+
* The timeout is ignored in the browser: every session closes at once
|
|
38
|
+
* (`WebTransport.close()` sends the close capsule), so there is no
|
|
39
|
+
* drain for it to bound.
|
|
40
|
+
*/
|
|
41
|
+
close(_timeout_ms: number): void;
|
|
42
|
+
/**
|
|
43
|
+
* Starts one Connection attempt: a peer ID string, or an array of peer
|
|
44
|
+
* addresses naming one peer. Returns the Connect ID.
|
|
45
|
+
*/
|
|
46
|
+
connect(target: any): bigint;
|
|
47
|
+
/**
|
|
48
|
+
* Connected peer IDs.
|
|
49
|
+
*/
|
|
50
|
+
connectedPeers(): string[];
|
|
51
|
+
/**
|
|
52
|
+
* A snapshot of a peer's connection, or `null`.
|
|
53
|
+
*/
|
|
54
|
+
connectionInfo(peer_id: string): any;
|
|
55
|
+
/**
|
|
56
|
+
* Disconnects one peer.
|
|
57
|
+
*/
|
|
58
|
+
disconnect(peer_id: string): void;
|
|
59
|
+
/**
|
|
60
|
+
* The discovery clock (always `null` in a browser).
|
|
61
|
+
*/
|
|
62
|
+
discoveryNowMs(): any;
|
|
63
|
+
/**
|
|
64
|
+
* Pulls a bounded batch of events.
|
|
65
|
+
*/
|
|
66
|
+
drainEvents(limit: number): any;
|
|
67
|
+
/**
|
|
68
|
+
* Whether Identify completed for a peer.
|
|
69
|
+
*/
|
|
70
|
+
isPeerReady(peer_id: string): boolean;
|
|
71
|
+
/**
|
|
72
|
+
* Whether the endpoint is started and not closed.
|
|
73
|
+
*/
|
|
74
|
+
isRunning(): boolean;
|
|
75
|
+
/**
|
|
76
|
+
* The discovery book (always empty in a browser).
|
|
77
|
+
*/
|
|
78
|
+
knownPeers(): any;
|
|
79
|
+
/**
|
|
80
|
+
* The listen set; empty, since browsers do not listen.
|
|
81
|
+
*/
|
|
82
|
+
listenAddrs(): string[];
|
|
83
|
+
/**
|
|
84
|
+
* Validates the key and config and builds the endpoint over `io`,
|
|
85
|
+
* without driving it yet.
|
|
86
|
+
*/
|
|
87
|
+
constructor(secret_key: Uint8Array, config: any, io: any);
|
|
88
|
+
/**
|
|
89
|
+
* Starts opening an application stream.
|
|
90
|
+
*/
|
|
91
|
+
openStream(peer_id: string, protocol_id: string): any;
|
|
92
|
+
/**
|
|
93
|
+
* The path of a peer's connection, or `null`.
|
|
94
|
+
*/
|
|
95
|
+
path(peer_id: string): any;
|
|
96
|
+
/**
|
|
97
|
+
* The local peer ID.
|
|
98
|
+
*/
|
|
99
|
+
peerId(): string;
|
|
100
|
+
/**
|
|
101
|
+
* The latest Identify snapshot, or `null`.
|
|
102
|
+
*/
|
|
103
|
+
peerInfo(peer_id: string): any;
|
|
104
|
+
/**
|
|
105
|
+
* Starts one ping.
|
|
106
|
+
*/
|
|
107
|
+
ping(peer_id: string): void;
|
|
108
|
+
/**
|
|
109
|
+
* Publishes one pubsub payload.
|
|
110
|
+
*/
|
|
111
|
+
publish(topic: string, data: Uint8Array): void;
|
|
112
|
+
/**
|
|
113
|
+
* Polls the endpoint once and returns the milliseconds until it needs
|
|
114
|
+
* polling again (`0` at once), or `undefined` when nothing is
|
|
115
|
+
* scheduled.
|
|
116
|
+
*/
|
|
117
|
+
pump(): number | undefined;
|
|
118
|
+
/**
|
|
119
|
+
* The reachability verdict (always `Unknown` in a browser).
|
|
120
|
+
*/
|
|
121
|
+
reachability(): any;
|
|
122
|
+
/**
|
|
123
|
+
* Resets a stream.
|
|
124
|
+
*/
|
|
125
|
+
resetStream(conn_id: bigint, stream_id: bigint): void;
|
|
126
|
+
/**
|
|
127
|
+
* Sends bytes on a stream: `true` once all are accepted, `false` while
|
|
128
|
+
* the tail is held and `StreamWriteAccepted` is still to come.
|
|
129
|
+
*/
|
|
130
|
+
sendStream(conn_id: bigint, stream_id: bigint, data: Uint8Array): boolean;
|
|
131
|
+
/**
|
|
132
|
+
* Ignored in the browser, kept for the shared SDK surface: there is no
|
|
133
|
+
* background driver whose cadence it could change. The page's own
|
|
134
|
+
* timers pump the endpoint.
|
|
135
|
+
*/
|
|
136
|
+
setActive(_active: boolean): void;
|
|
137
|
+
/**
|
|
138
|
+
* Starts driving; `doorbell` is called when events become ready to drain.
|
|
139
|
+
*/
|
|
140
|
+
start(doorbell: Function): void;
|
|
141
|
+
/**
|
|
142
|
+
* Acknowledges `bytes` of a stream's received data as consumed.
|
|
143
|
+
*/
|
|
144
|
+
streamConsumed(conn_id: bigint, stream_id: bigint, bytes: number): void;
|
|
145
|
+
/**
|
|
146
|
+
* Subscribes to a pubsub topic.
|
|
147
|
+
*/
|
|
148
|
+
subscribe(topic: string): boolean;
|
|
149
|
+
/**
|
|
150
|
+
* Unsubscribes from a pubsub topic.
|
|
151
|
+
*/
|
|
152
|
+
unsubscribe(topic: string): boolean;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Builds a circuit address through a direct relay address.
|
|
157
|
+
*/
|
|
158
|
+
export function circuitAddress(relay_address: string, peer_id: string): string;
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Generates a 32-byte Ed25519 secret key from `crypto.getRandomValues`.
|
|
162
|
+
*/
|
|
163
|
+
export function generateSecretKey(): Uint8Array;
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Derives a peer ID from raw Ed25519 secret key material.
|
|
167
|
+
*/
|
|
168
|
+
export function peerIdFromSecretKey(secret_key: Uint8Array): string;
|
|
169
|
+
|
|
170
|
+
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
171
|
+
|
|
172
|
+
export interface InitOutput {
|
|
173
|
+
readonly memory: WebAssembly.Memory;
|
|
174
|
+
readonly __wbg_webendpoint_free: (a: number, b: number) => void;
|
|
175
|
+
readonly circuitAddress: (a: number, b: number, c: number, d: number) => [number, number, number, number];
|
|
176
|
+
readonly generateSecretKey: () => [number, number, number, number];
|
|
177
|
+
readonly peerIdFromSecretKey: (a: number, b: number) => [number, number, number, number];
|
|
178
|
+
readonly webendpoint_abandonStream: (a: number, b: bigint, c: bigint) => [number, number];
|
|
179
|
+
readonly webendpoint_activeReservation: (a: number) => [number, number, number];
|
|
180
|
+
readonly webendpoint_addProtocol: (a: number, b: number, c: number) => [number, number];
|
|
181
|
+
readonly webendpoint_cancelConnect: (a: number, b: bigint) => [number, number];
|
|
182
|
+
readonly webendpoint_close: (a: number, b: number) => void;
|
|
183
|
+
readonly webendpoint_closeStreamWrite: (a: number, b: bigint, c: bigint) => [number, number];
|
|
184
|
+
readonly webendpoint_connect: (a: number, b: any) => [bigint, number, number];
|
|
185
|
+
readonly webendpoint_connectedPeers: (a: number) => [number, number, number, number];
|
|
186
|
+
readonly webendpoint_connectionInfo: (a: number, b: number, c: number) => [number, number, number];
|
|
187
|
+
readonly webendpoint_disconnect: (a: number, b: number, c: number) => [number, number];
|
|
188
|
+
readonly webendpoint_discoveryNowMs: (a: number) => [number, number, number];
|
|
189
|
+
readonly webendpoint_drainEvents: (a: number, b: number) => [number, number, number];
|
|
190
|
+
readonly webendpoint_isPeerReady: (a: number, b: number, c: number) => [number, number, number];
|
|
191
|
+
readonly webendpoint_isRunning: (a: number) => number;
|
|
192
|
+
readonly webendpoint_knownPeers: (a: number) => [number, number, number];
|
|
193
|
+
readonly webendpoint_listenAddrs: (a: number) => [number, number];
|
|
194
|
+
readonly webendpoint_new: (a: number, b: number, c: any, d: any) => [number, number, number];
|
|
195
|
+
readonly webendpoint_openStream: (a: number, b: number, c: number, d: number, e: number) => [number, number, number];
|
|
196
|
+
readonly webendpoint_path: (a: number, b: number, c: number) => [number, number, number];
|
|
197
|
+
readonly webendpoint_peerId: (a: number) => [number, number];
|
|
198
|
+
readonly webendpoint_peerInfo: (a: number, b: number, c: number) => [number, number, number];
|
|
199
|
+
readonly webendpoint_ping: (a: number, b: number, c: number) => [number, number];
|
|
200
|
+
readonly webendpoint_publish: (a: number, b: number, c: number, d: number, e: number) => [number, number];
|
|
201
|
+
readonly webendpoint_pump: (a: number) => [number, number];
|
|
202
|
+
readonly webendpoint_reachability: (a: number) => [number, number, number];
|
|
203
|
+
readonly webendpoint_resetStream: (a: number, b: bigint, c: bigint) => [number, number];
|
|
204
|
+
readonly webendpoint_sendStream: (a: number, b: bigint, c: bigint, d: number, e: number) => [number, number, number];
|
|
205
|
+
readonly webendpoint_setActive: (a: number, b: number) => void;
|
|
206
|
+
readonly webendpoint_start: (a: number, b: any) => [number, number];
|
|
207
|
+
readonly webendpoint_streamConsumed: (a: number, b: bigint, c: bigint, d: number) => [number, number];
|
|
208
|
+
readonly webendpoint_subscribe: (a: number, b: number, c: number) => [number, number, number];
|
|
209
|
+
readonly webendpoint_unsubscribe: (a: number, b: number, c: number) => [number, number, number];
|
|
210
|
+
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
211
|
+
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
212
|
+
readonly __wbindgen_exn_store: (a: number) => void;
|
|
213
|
+
readonly __externref_table_alloc: () => number;
|
|
214
|
+
readonly __wbindgen_externrefs: WebAssembly.Table;
|
|
215
|
+
readonly __externref_table_dealloc: (a: number) => void;
|
|
216
|
+
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
217
|
+
readonly __externref_drop_slice: (a: number, b: number) => void;
|
|
218
|
+
readonly __wbindgen_start: () => void;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Instantiates the given `module`, which can either be bytes or
|
|
225
|
+
* a precompiled `WebAssembly.Module`.
|
|
226
|
+
*
|
|
227
|
+
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
|
|
228
|
+
*
|
|
229
|
+
* @returns {InitOutput}
|
|
230
|
+
*/
|
|
231
|
+
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
|
|
235
|
+
* for everything else, calls `WebAssembly.instantiate` directly.
|
|
236
|
+
*
|
|
237
|
+
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
|
|
238
|
+
*
|
|
239
|
+
* @returns {Promise<InitOutput>}
|
|
240
|
+
*/
|
|
241
|
+
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
|