@minip2p/web 0.0.0 → 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/dist/sdk.js ADDED
@@ -0,0 +1,191 @@
1
+ /* oxlint-disable func-style, max-classes-per-file, no-use-before-define -- Hoisted helpers keep the public entry points first. */
2
+ /**
3
+ * The implementation both entry points share: `Minip2p` over the wasm
4
+ * module's `WebEndpoint`, the key helpers, and `initMinip2p`.
5
+ */
6
+ import { ClosedError, DriverFailedError, DriverFailureKind, Minip2pBase, } from "@minip2p/core";
7
+ import { resolveEndpointConfig } from "@minip2p/core/backend";
8
+ import { SerdeBackend, typedNativeCall } from "@minip2p/core/serde-backend";
9
+ import { JsIo } from "./io.js";
10
+ import { loadWasm, wasm } from "./wasm.js";
11
+ /**
12
+ * Loads minip2p's wasm module. `@minip2p/web` calls it at import;
13
+ * `@minip2p/web/manual` leaves it to the host, which must await it before
14
+ * `Minip2p.create`. Safe to call again: later calls share the first load
15
+ * that succeeds, and a failed load can be retried.
16
+ */
17
+ export async function initMinip2p(options = {}) {
18
+ await loadWasm(options.wasm);
19
+ }
20
+ /** High-level browser owner for one minip2p endpoint. */
21
+ export class Minip2p extends Minip2pBase {
22
+ constructor(backend, relays) {
23
+ super(backend, relays);
24
+ }
25
+ /** Constructs and starts a browser endpoint. */
26
+ static create(config) {
27
+ return new Minip2p(webBackend(config), config.relays ?? []);
28
+ }
29
+ }
30
+ /** Generates a new 32-byte Ed25519 secret key with `crypto.getRandomValues`. */
31
+ export function generateSecretKey() {
32
+ return typedNativeCall(() => wasm().generateSecretKey());
33
+ }
34
+ /** Derives a peer ID from raw Ed25519 secret key material. */
35
+ export function peerIdFromSecretKey(secretKey) {
36
+ return typedNativeCall(() => wasm().peerIdFromSecretKey(toUint8Array(secretKey)));
37
+ }
38
+ /** Builds a circuit multiaddress through a direct relay address. */
39
+ export function circuitAddress(relayAddress, peerId) {
40
+ return typedNativeCall(() => wasm().circuitAddress(relayAddress, peerId));
41
+ }
42
+ /** Polls a batch of rounds back to back before yielding the event loop. */
43
+ const PUMP_ROUNDS = 64;
44
+ /**
45
+ * Drives the wasm endpoint on the page's event loop: one coalesced
46
+ * microtask per burst of calls and I/O events, at most {@link PUMP_ROUNDS}
47
+ * polls before yielding with `setTimeout(0)`, and one re-armed timer for
48
+ * the endpoint's next deadline.
49
+ */
50
+ class Pump {
51
+ #poll;
52
+ #queued = false;
53
+ #timer;
54
+ #stopped = false;
55
+ /**
56
+ * `poll` pumps once and returns the delay until the next pump; a throw
57
+ * stops the pump for good.
58
+ */
59
+ constructor(poll) {
60
+ this.#poll = poll;
61
+ }
62
+ schedule() {
63
+ if (this.#queued || this.#stopped) {
64
+ return;
65
+ }
66
+ this.#queued = true;
67
+ queueMicrotask(() => {
68
+ this.#run();
69
+ });
70
+ }
71
+ stop() {
72
+ this.#stopped = true;
73
+ clearTimeout(this.#timer);
74
+ }
75
+ #run() {
76
+ this.#queued = false;
77
+ clearTimeout(this.#timer);
78
+ this.#timer = undefined;
79
+ for (let round = 0; round < PUMP_ROUNDS && !this.#stopped; round += 1) {
80
+ let delay;
81
+ try {
82
+ delay = this.#poll();
83
+ }
84
+ catch {
85
+ // The endpoint failed, and its owner already reported it.
86
+ this.stop();
87
+ return;
88
+ }
89
+ if (delay === undefined) {
90
+ return;
91
+ }
92
+ if (delay > 0) {
93
+ this.#arm(delay);
94
+ return;
95
+ }
96
+ }
97
+ // Still busy: let the page run, then carry on.
98
+ this.#arm(0);
99
+ }
100
+ #arm(delay) {
101
+ if (this.#stopped) {
102
+ return;
103
+ }
104
+ this.#timer = setTimeout(() => {
105
+ this.#timer = undefined;
106
+ this.schedule();
107
+ }, delay);
108
+ }
109
+ }
110
+ /**
111
+ * Calls into one wasm instance. A trap (`WebAssembly.RuntimeError`, which a
112
+ * Rust panic becomes on wasm32) leaves the instance unusable: the call that
113
+ * hit it throws `DriverFailedError`, `onFail` fails the endpoint, and every
114
+ * later call throws `ClosedError` without touching wasm again.
115
+ */
116
+ class WasmCalls {
117
+ #onFail;
118
+ /** Trapped, or the instance was freed. */
119
+ #failed = false;
120
+ constructor(onFail) {
121
+ this.#onFail = onFail;
122
+ }
123
+ call(operation) {
124
+ if (this.#failed) {
125
+ throw new ClosedError();
126
+ }
127
+ try {
128
+ return operation();
129
+ }
130
+ catch (error) {
131
+ if (!(error instanceof WebAssembly.RuntimeError)) {
132
+ throw error;
133
+ }
134
+ this.#failed = true;
135
+ const detail = `the minip2p wasm module trapped: ${error.message}`;
136
+ this.#onFail(detail);
137
+ throw new DriverFailedError(DriverFailureKind.Panic, detail);
138
+ }
139
+ }
140
+ /** Runs `free` unless the instance trapped; later calls throw `ClosedError`. */
141
+ release(free) {
142
+ if (!this.#failed) {
143
+ this.#failed = true;
144
+ free();
145
+ }
146
+ }
147
+ }
148
+ function webBackend(config) {
149
+ const module = wasm();
150
+ // A trapped instance can neither close its sessions nor be freed: close
151
+ // them from TypeScript.
152
+ const calls = new WasmCalls((detail) => {
153
+ pump.stop();
154
+ io.dispose();
155
+ backend.fail(detail);
156
+ });
157
+ const pump = new Pump(() => calls.call(() => endpoint.pump()));
158
+ const io = new JsIo(() => {
159
+ pump.schedule();
160
+ });
161
+ const endpoint = typedNativeCall(() => new module.WebEndpoint(toUint8Array(config.secretKey), resolveEndpointConfig(config), io));
162
+ const backend = new SerdeBackend(endpoint, {
163
+ // Every command may queue work (a dial, a write): pump after it.
164
+ call: (operation) => {
165
+ try {
166
+ return calls.call(operation);
167
+ }
168
+ finally {
169
+ pump.schedule();
170
+ }
171
+ },
172
+ circuitAddress,
173
+ // Closed and drained: stop pumping and free the wasm object, which
174
+ // drops its doorbell and `JsIo`.
175
+ release: () => {
176
+ pump.stop();
177
+ calls.release(() => {
178
+ endpoint.free();
179
+ });
180
+ },
181
+ schedule: (task) => {
182
+ queueMicrotask(task);
183
+ },
184
+ });
185
+ return backend;
186
+ }
187
+ /** A view wasm-bindgen copies into wasm memory before the call returns. */
188
+ function toUint8Array(value) {
189
+ return value instanceof Uint8Array ? value : new Uint8Array(value);
190
+ }
191
+ //# sourceMappingURL=sdk.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sdk.js","sourceRoot":"","sources":["../src/sdk.ts"],"names":[],"mappings":"AAAA,kIAAkI;AAElI;;;GAGG;AAEH,OAAO,EACL,WAAW,EACX,iBAAiB,EACjB,iBAAiB,EACjB,WAAW,GACZ,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAE9D,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAE5E,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC/B,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAY3C;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,OAAO,GAAuB,EAAE;IAEhC,MAAM,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;AAC/B,CAAC;AAED,yDAAyD;AACzD,MAAM,OAAO,OAAQ,SAAQ,WAAW;IACtC,YAAoB,OAAuB,EAAE,MAAyB;QACpE,KAAK,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IACzB,CAAC;IAED,gDAAgD;IAChD,MAAM,CAAC,MAAM,CAAC,MAAqB;QACjC,OAAO,IAAI,OAAO,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC;IAC9D,CAAC;CACF;AAED,gFAAgF;AAChF,MAAM,UAAU,iBAAiB;IAC/B,OAAO,eAAe,CAAC,GAAG,EAAE,CAAC,IAAI,EAAE,CAAC,iBAAiB,EAAE,CAAC,CAAC;AAC3D,CAAC;AAED,8DAA8D;AAC9D,MAAM,UAAU,mBAAmB,CAAC,SAAgB;IAClD,OAAO,eAAe,CAAC,GAAG,EAAE,CAC1B,IAAI,EAAE,CAAC,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OAAO,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YAC/B,CAAC;oBAAS,CAAC;gBACT,IAAI,CAAC,QAAQ,EAAE,CAAC;YAClB,CAAC;QACH,CAAC;QACD,cAAc;QACd,mEAAmE;QACnE,iCAAiC;QACjC,OAAO,EAAE,GAAG,EAAE;YACZ,IAAI,CAAC,IAAI,EAAE,CAAC;YACZ,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE;gBACjB,QAAQ,CAAC,IAAI,EAAE,CAAC;YAClB,CAAC,CAAC,CAAC;QACL,CAAC;QACD,QAAQ,EAAE,CAAC,IAAI,EAAE,EAAE;YACjB,cAAc,CAAC,IAAI,CAAC,CAAC;QACvB,CAAC;KACF,CAAC,CAAC;IACH,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,2EAA2E;AAC3E,SAAS,YAAY,CAAC,KAAY;IAChC,OAAO,KAAK,YAAY,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,UAAU,CAAC,KAAK,CAAC,CAAC;AACrE,CAAC"}
package/dist/wasm.d.ts ADDED
@@ -0,0 +1,18 @@
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
+ import * as glue from "../wasm/minip2p_web.js";
7
+ import type { InitInput } from "../wasm/minip2p_web.js";
8
+ /** Where the `.wasm` comes from: a URL, a `Response`, its bytes, or a compiled module. */
9
+ export type WasmSource = InitInput | Promise<InitInput>;
10
+ /**
11
+ * Instantiates the module once; later calls share the first that succeeds.
12
+ * Without `source`, the `.wasm` beside this package is fetched (resolved
13
+ * from `import.meta.url`). A failed load can be retried, with another source.
14
+ */
15
+ export declare const loadWasm: (source?: WasmSource) => Promise<void>;
16
+ /** The initialised module's exports; throws until {@link loadWasm} resolved. */
17
+ export declare const wasm: () => typeof glue;
18
+ //# sourceMappingURL=wasm.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wasm.d.ts","sourceRoot":"","sources":["../src/wasm.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAa,KAAK,IAAI,MAAM,wBAAwB,CAAC;AACrD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAExD,0FAA0F;AAC1F,MAAM,MAAM,UAAU,GAAG,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;AAcxD;;;;GAIG;AACH,eAAO,MAAM,QAAQ,YAAmB,UAAU,KAAG,OAAO,CAAC,IAAI,CAQhE,CAAC;AAEF,gFAAgF;AAChF,eAAO,MAAM,IAAI,QAAO,OAAO,IAO9B,CAAC"}
package/dist/wasm.js ADDED
@@ -0,0 +1,37 @@
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
+ import init, * as glue from "../wasm/minip2p_web.js";
7
+ let loading;
8
+ let loaded = false;
9
+ const instantiate = async (source) => {
10
+ // wasm-bindgen fetches a string or URL only when it is passed directly,
11
+ // so a promised one is awaited here first.
12
+ await init(source === undefined ? undefined : { module_or_path: await source });
13
+ loaded = true;
14
+ };
15
+ /**
16
+ * Instantiates the module once; later calls share the first that succeeds.
17
+ * Without `source`, the `.wasm` beside this package is fetched (resolved
18
+ * from `import.meta.url`). A failed load can be retried, with another source.
19
+ */
20
+ export const loadWasm = async (source) => {
21
+ loading ??= instantiate(source);
22
+ try {
23
+ await loading;
24
+ }
25
+ catch (error) {
26
+ loading = undefined;
27
+ throw error;
28
+ }
29
+ };
30
+ /** The initialised module's exports; throws until {@link loadWasm} resolved. */
31
+ export const wasm = () => {
32
+ if (!loaded) {
33
+ throw new Error("minip2p's wasm module is not initialised: import @minip2p/web, or await initMinip2p() from @minip2p/web/manual before creating an endpoint");
34
+ }
35
+ return glue;
36
+ };
37
+ //# sourceMappingURL=wasm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wasm.js","sourceRoot":"","sources":["../src/wasm.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,IAAI,EAAE,KAAK,IAAI,MAAM,wBAAwB,CAAC;AAMrD,IAAI,OAAkC,CAAC;AACvC,IAAI,MAAM,GAAG,KAAK,CAAC;AAEnB,MAAM,WAAW,GAAG,KAAK,EAAE,MAA8B,EAAiB,EAAE;IAC1E,wEAAwE;IACxE,2CAA2C;IAC3C,MAAM,IAAI,CACR,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,cAAc,EAAE,MAAM,MAAM,EAAE,CACpE,CAAC;IACF,MAAM,GAAG,IAAI,CAAC;AAChB,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,KAAK,EAAE,MAAmB,EAAiB,EAAE;IACnE,OAAO,KAAK,WAAW,CAAC,MAAM,CAAC,CAAC;IAChC,IAAI,CAAC;QACH,MAAM,OAAO,CAAC;IAChB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,GAAG,SAAS,CAAC;QACpB,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC,CAAC;AAEF,gFAAgF;AAChF,MAAM,CAAC,MAAM,IAAI,GAAG,GAAgB,EAAE;IACpC,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,KAAK,CACb,4IAA4I,CAC7I,CAAC;IACJ,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,78 @@
1
1
  {
2
2
  "name": "@minip2p/web",
3
- "version": "0.0.0",
4
- "description": "Placeholder; the real package ships with minip2p 0.11.0",
3
+ "version": "0.10.1",
4
+ "description": "Browser SDK for minip2p over libp2p WebTransport",
5
+ "keywords": [
6
+ "browser",
7
+ "libp2p",
8
+ "p2p",
9
+ "peer-to-peer",
10
+ "wasm",
11
+ "webtransport"
12
+ ],
13
+ "homepage": "https://github.com/deepso7/minip2p#readme",
14
+ "bugs": {
15
+ "url": "https://github.com/deepso7/minip2p/issues"
16
+ },
5
17
  "license": "MIT",
6
- "repository": { "type": "git", "url": "git+https://github.com/deepso7/minip2p.git", "directory": "bindings/ts/web" }
7
- }
18
+ "author": "Deepso <deeps.o7o8.y@gmail.com> (https://github.com/deepso7)",
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/deepso7/minip2p.git",
22
+ "directory": "bindings/ts/web"
23
+ },
24
+ "files": [
25
+ "dist",
26
+ "src",
27
+ "wasm/minip2p_web.d.ts",
28
+ "wasm/minip2p_web.js",
29
+ "wasm/minip2p_web_bg.wasm",
30
+ "wasm/minip2p_web_bg.wasm.d.ts",
31
+ "README.md"
32
+ ],
33
+ "type": "module",
34
+ "sideEffects": [
35
+ "./dist/index.js",
36
+ "./src/index.ts"
37
+ ],
38
+ "main": "./dist/index.js",
39
+ "types": "./dist/index.d.ts",
40
+ "exports": {
41
+ ".": {
42
+ "minip2p-source": "./src/index.ts",
43
+ "types": "./dist/index.d.ts",
44
+ "default": "./dist/index.js"
45
+ },
46
+ "./manual": {
47
+ "minip2p-source": "./src/manual.ts",
48
+ "types": "./dist/manual.d.ts",
49
+ "default": "./dist/manual.js"
50
+ },
51
+ "./package.json": "./package.json"
52
+ },
53
+ "publishConfig": {
54
+ "access": "public",
55
+ "registry": "https://registry.npmjs.org/"
56
+ },
57
+ "dependencies": {
58
+ "@minip2p/core": "0.10.1"
59
+ },
60
+ "devDependencies": {
61
+ "@minip2p/node": "0.10.1",
62
+ "@minip2p/test-fixtures": "0.0.0",
63
+ "@playwright/test": "1.64.1",
64
+ "@types/node": "26.5.0",
65
+ "del-cli": "7.0.0",
66
+ "typescript": "7.0.2"
67
+ },
68
+ "scripts": {
69
+ "build": "del-cli dist && tsc -p tsconfig.build.json",
70
+ "clean": "del-cli dist",
71
+ "wasm:build": "node scripts/build-wasm.mjs",
72
+ "pretest": "node scripts/build-wasm.mjs",
73
+ "test": "vitest run",
74
+ "test:watch": "vitest",
75
+ "test:e2e": "playwright test",
76
+ "typecheck": "tsc -p tsconfig.json"
77
+ }
78
+ }
package/src/index.ts ADDED
@@ -0,0 +1,19 @@
1
+ /**
2
+ * `@minip2p/web`: minip2p for the browser, with the same API as
3
+ * `@minip2p/node`. Importing it loads the wasm module (the `.wasm` beside
4
+ * the package, resolved from `import.meta.url`) with top-level `await`, so
5
+ * `Minip2p.create` is ready to call. Use `@minip2p/web/manual` to load the
6
+ * `.wasm` yourself.
7
+ */
8
+
9
+ import { initMinip2p } from "./sdk.js";
10
+
11
+ await initMinip2p();
12
+
13
+ export * from "@minip2p/core";
14
+ export {
15
+ Minip2p,
16
+ circuitAddress,
17
+ generateSecretKey,
18
+ peerIdFromSecretKey,
19
+ } from "./sdk.js";