@qntx/nostr-wasm 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-APACHE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/LICENSE-MIT ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 QuantX
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 CHANGED
@@ -1,3 +1,29 @@
1
- # Temporary Holding Version
1
+ # @qntx/nostr-wasm
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ WebAssembly-accelerated cryptography for [`@qntx/nostr`](https://www.npmjs.com/package/@qntx/nostr) (BIP-340 signing and event verification), built from the `nk-wasm` Rust crate.
4
+
5
+ ```bash
6
+ npm install @qntx/nostr-wasm @qntx/nostr
7
+ ```
8
+
9
+ ```ts
10
+ import { Keys } from "@qntx/nostr";
11
+ import { loadNostrWasm } from "@qntx/nostr-wasm";
12
+ import { Relay } from "@qntx/nostr/relay";
13
+
14
+ const wasm = await loadNostrWasm();
15
+
16
+ // Signing backend: `keys` signs with the wasm module.
17
+ const keys = Keys.fromSecretKey(secretKey, wasm);
18
+
19
+ // Verifier injection: relays verify incoming events with wasm.
20
+ const relay = await Relay.connect("wss://relay.example", {
21
+ verifyEvent: wasm.verifyEvent,
22
+ });
23
+ ```
24
+
25
+ The default (Node) entry reads the bundled `.wasm` file from disk; bundlers and browsers should resolve the `browser` export condition (or import `@qntx/nostr-wasm/browser`), which fetches the asset served next to the module. Both accept explicit bytes via `loadNostrWasm({ module })`.
26
+
27
+ ## License
28
+
29
+ MIT OR Apache-2.0
@@ -0,0 +1,14 @@
1
+ import { EventVerifier, SigningBackend, WasmPoisonedError as WasmPoisonedError$1 } from "@qntx/nostr/core";
2
+ //#region src/instance.d.ts
3
+ type LoadNostrWasmOptions = {
4
+ /** Bytes, or a URL whose bytes will be read by the platform loader. */
5
+ module?: ArrayBuffer | ArrayBufferView | URL | undefined;
6
+ };
7
+ type NostrWasm = SigningBackend & {
8
+ verify: (id: Uint8Array, pubkey: Uint8Array, sig: Uint8Array) => boolean;
9
+ verifySerialized: (serializedUtf8: Uint8Array, id: Uint8Array, pubkey: Uint8Array, sig: Uint8Array) => boolean;
10
+ verifyEvent: EventVerifier;
11
+ };
12
+ //#endregion
13
+ export { LoadNostrWasmOptions as n, NostrWasm as r, WasmPoisonedError$1 as t };
14
+ //# sourceMappingURL=adapter-BPemxR6e.d.mts.map
@@ -0,0 +1,7 @@
1
+ import { n as LoadNostrWasmOptions, r as NostrWasm, t as WasmPoisonedError } from "./adapter-BPemxR6e.mjs";
2
+ //#region src/load.browser.d.ts
3
+ /** Instantiate once. Repeats reuse the same module. Failure throws; no noble fallback. */
4
+ export declare function loadNostrWasm(opts?: LoadNostrWasmOptions): Promise<NostrWasm>;
5
+ //#endregion
6
+ export { type LoadNostrWasmOptions, type NostrWasm, WasmPoisonedError };
7
+ //# sourceMappingURL=browser.d.mts.map
@@ -0,0 +1,19 @@
1
+ import { i as WasmPoisonedError, n as fetchWasmUrl, r as isWasmBytes, t as createNostrWasmLoader } from "./instance-DS92CCrA.mjs";
2
+ import { CryptoError } from "@qntx/nostr/core";
3
+ //#region src/load.browser.ts
4
+ async function wasmBytes(opts) {
5
+ const source = opts?.module;
6
+ if (source !== void 0 && isWasmBytes(source)) return source;
7
+ if (source instanceof URL && source.protocol !== "file:") return fetchWasmUrl(source);
8
+ if (source instanceof URL) throw new CryptoError(`cannot fetch wasm from ${source.href}`);
9
+ return fetchWasmUrl(new URL("nk_wasm_bg.wasm", import.meta.url));
10
+ }
11
+ const loader = createNostrWasmLoader(wasmBytes);
12
+ /** Instantiate once. Repeats reuse the same module. Failure throws; no noble fallback. */
13
+ async function loadNostrWasm(opts) {
14
+ return loader.loadNostrWasm(opts);
15
+ }
16
+ //#endregion
17
+ export { WasmPoisonedError, loadNostrWasm };
18
+
19
+ //# sourceMappingURL=browser.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser.mjs","names":[],"sources":["../src/load.browser.ts"],"sourcesContent":["import { CryptoError } from \"@qntx/nostr/core\";\n\nimport { createNostrWasmLoader, fetchWasmUrl, isWasmBytes } from \"./instance.ts\";\nimport type { LoadNostrWasmOptions, NostrWasm } from \"./instance.ts\";\n\nexport type { LoadNostrWasmOptions, NostrWasm } from \"./instance.ts\";\n\nasync function wasmBytes(opts?: LoadNostrWasmOptions): Promise<ArrayBuffer | ArrayBufferView> {\n const source = opts?.module;\n if (source !== undefined && isWasmBytes(source)) {\n return source;\n }\n if (source instanceof URL && source.protocol !== \"file:\") {\n return fetchWasmUrl(source);\n }\n if (source instanceof URL) {\n throw new CryptoError(`cannot fetch wasm from ${source.href}`);\n }\n return fetchWasmUrl(new URL(\"nk_wasm_bg.wasm\", import.meta.url));\n}\n\nconst loader = createNostrWasmLoader(wasmBytes);\n\n/** Instantiate once. Repeats reuse the same module. Failure throws; no noble fallback. */\nexport async function loadNostrWasm(opts?: LoadNostrWasmOptions): Promise<NostrWasm> {\n return loader.loadNostrWasm(opts);\n}\n"],"mappings":";;;AAOA,eAAe,UAAU,MAAqE;CAC5F,MAAM,SAAS,MAAM;CACrB,IAAI,WAAW,KAAA,KAAa,YAAY,MAAM,GAC5C,OAAO;CAET,IAAI,kBAAkB,OAAO,OAAO,aAAa,SAC/C,OAAO,aAAa,MAAM;CAE5B,IAAI,kBAAkB,KACpB,MAAM,IAAI,YAAY,0BAA0B,OAAO,MAAM;CAE/D,OAAO,aAAa,IAAI,IAAI,mBAAmB,YAAY,GAAG,CAAC;AACjE;AAEA,MAAM,SAAS,sBAAsB,SAAS;;AAG9C,eAAsB,cAAc,MAAiD;CACnF,OAAO,OAAO,cAAc,IAAI;AAClC"}
@@ -0,0 +1,7 @@
1
+ import { n as LoadNostrWasmOptions, r as NostrWasm, t as WasmPoisonedError } from "./adapter-BPemxR6e.mjs";
2
+ //#region src/load.d.ts
3
+ /** Instantiate once. Repeats reuse the same module. Failure throws; no noble fallback. */
4
+ export declare function loadNostrWasm(opts?: LoadNostrWasmOptions): Promise<NostrWasm>;
5
+ //#endregion
6
+ export { type LoadNostrWasmOptions, type NostrWasm, WasmPoisonedError };
7
+ //# sourceMappingURL=index.d.mts.map
package/dist/index.mjs ADDED
@@ -0,0 +1,27 @@
1
+ import { i as WasmPoisonedError, n as fetchWasmUrl, r as isWasmBytes, t as createNostrWasmLoader } from "./instance-DS92CCrA.mjs";
2
+ //#region src/load.ts
3
+ async function defaultWasmHref() {
4
+ return (await import("./nk_wasm_bg-BjJ0ckB7.mjs")).default;
5
+ }
6
+ async function readWasmUrl(url) {
7
+ if (url.protocol === "file:") {
8
+ const { readFile } = await import("node:fs/promises");
9
+ const { fileURLToPath } = await import("node:url");
10
+ return new Uint8Array(await readFile(fileURLToPath(url)));
11
+ }
12
+ return fetchWasmUrl(url);
13
+ }
14
+ async function wasmBytes(opts) {
15
+ const source = opts?.module;
16
+ if (source !== void 0 && isWasmBytes(source)) return source;
17
+ return readWasmUrl(source instanceof URL ? source : new URL(await defaultWasmHref(), import.meta.url));
18
+ }
19
+ const loader = createNostrWasmLoader(wasmBytes);
20
+ /** Instantiate once. Repeats reuse the same module. Failure throws; no noble fallback. */
21
+ async function loadNostrWasm(opts) {
22
+ return loader.loadNostrWasm(opts);
23
+ }
24
+ //#endregion
25
+ export { WasmPoisonedError, loadNostrWasm };
26
+
27
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/load.ts"],"sourcesContent":["import { createNostrWasmLoader, fetchWasmUrl, isWasmBytes } from \"./instance.ts\";\nimport type { LoadNostrWasmOptions, NostrWasm } from \"./instance.ts\";\n\nexport { WasmPoisonedError } from \"./adapter.ts\";\nexport type { LoadNostrWasmOptions, NostrWasm } from \"./instance.ts\";\n\nasync function defaultWasmHref(): Promise<string> {\n const mod = await import(\"./nk_wasm_bg.wasm?url\");\n return mod.default;\n}\n\nasync function readWasmUrl(url: URL): Promise<Uint8Array> {\n if (url.protocol === \"file:\") {\n const { readFile } = await import(\"node:fs/promises\");\n const { fileURLToPath } = await import(\"node:url\");\n return new Uint8Array(await readFile(fileURLToPath(url)));\n }\n return fetchWasmUrl(url);\n}\n\nasync function wasmBytes(opts?: LoadNostrWasmOptions): Promise<ArrayBuffer | ArrayBufferView> {\n const source = opts?.module;\n if (source !== undefined && isWasmBytes(source)) {\n return source;\n }\n const href = source instanceof URL ? source : new URL(await defaultWasmHref(), import.meta.url);\n return readWasmUrl(href);\n}\n\nconst loader = createNostrWasmLoader(wasmBytes);\n\n/** Instantiate once. Repeats reuse the same module. Failure throws; no noble fallback. */\nexport async function loadNostrWasm(opts?: LoadNostrWasmOptions): Promise<NostrWasm> {\n return loader.loadNostrWasm(opts);\n}\n"],"mappings":";;AAMA,eAAe,kBAAmC;CAEhD,QAAO,MADW,OAAO,6BAAA,CACd;AACb;AAEA,eAAe,YAAY,KAA+B;CACxD,IAAI,IAAI,aAAa,SAAS;EAC5B,MAAM,EAAE,aAAa,MAAM,OAAO;EAClC,MAAM,EAAE,kBAAkB,MAAM,OAAO;EACvC,OAAO,IAAI,WAAW,MAAM,SAAS,cAAc,GAAG,CAAC,CAAC;CAC1D;CACA,OAAO,aAAa,GAAG;AACzB;AAEA,eAAe,UAAU,MAAqE;CAC5F,MAAM,SAAS,MAAM;CACrB,IAAI,WAAW,KAAA,KAAa,YAAY,MAAM,GAC5C,OAAO;CAGT,OAAO,YADM,kBAAkB,MAAM,SAAS,IAAI,IAAI,MAAM,gBAAgB,GAAG,YAAY,GAAG,CACvE;AACzB;AAEA,MAAM,SAAS,sBAAsB,SAAS;;AAG9C,eAAsB,cAAc,MAAiD;CACnF,OAAO,OAAO,cAAc,IAAI;AAClC"}
@@ -0,0 +1,219 @@
1
+ import { CryptoError, WasmPoisonedError, WasmPoisonedError as WasmPoisonedError$1, createEventVerifier } from "@qntx/nostr/core";
2
+ //#region src/abi.ts
3
+ /** Imports 0.2.122 may request. Instantiation fails if anything else appears. */
4
+ const ALLOWED_WASM_IMPORTS = [{
5
+ module: "wbg",
6
+ name: "__wbindgen_throw"
7
+ }, {
8
+ module: "./nk_wasm_bg.js",
9
+ name: "__wbindgen_throw"
10
+ }];
11
+ const utf8 = new TextDecoder();
12
+ function decodeUtf8(memory, ptr, len) {
13
+ return utf8.decode(new Uint8Array(memory.buffer, ptr, len));
14
+ }
15
+ function makeWbgImports(holder) {
16
+ const throwRuntime = (ptr, len) => {
17
+ const mem = holder.exports?.memory;
18
+ const msg = mem ? decodeUtf8(mem, ptr, len) : "wasm panic";
19
+ throw new WebAssembly.RuntimeError(msg);
20
+ };
21
+ const wbg = { __wbindgen_throw: throwRuntime };
22
+ return {
23
+ wbg,
24
+ "./nk_wasm_bg.js": wbg
25
+ };
26
+ }
27
+ /** Fail if the module imports anything outside {@link ALLOWED_WASM_IMPORTS}. */
28
+ function assertAllowedWasmImports(mod) {
29
+ const allowed = new Set(ALLOWED_WASM_IMPORTS.map((item) => `${item.module}\0${item.name}`));
30
+ for (const imp of WebAssembly.Module.imports(mod)) {
31
+ if (imp.kind !== "function") throw new TypeError(`unexpected wasm import kind ${imp.kind}: ${imp.module}.${imp.name}`);
32
+ if (!allowed.has(`${imp.module}\0${imp.name}`)) throw new TypeError(`unexpected wasm import ${imp.module}.${imp.name}`);
33
+ }
34
+ }
35
+ function requireMemory(value) {
36
+ if (!(value instanceof WebAssembly.Memory)) throw new TypeError("wasm missing memory export");
37
+ return value;
38
+ }
39
+ function requireFn(value, name) {
40
+ if (typeof value !== "function") throw new TypeError(`wasm missing ${name} export`);
41
+ return value;
42
+ }
43
+ function asExports(raw) {
44
+ const exports = {
45
+ memory: requireMemory(raw["memory"]),
46
+ verify: requireFn(raw["verify"], "verify"),
47
+ verify_serialized: requireFn(raw["verify_serialized"], "verify_serialized"),
48
+ sign: requireFn(raw["sign"], "sign"),
49
+ public_key: requireFn(raw["public_key"], "public_key"),
50
+ __wbindgen_export: requireFn(raw["__wbindgen_export"], "__wbindgen_export"),
51
+ __wbindgen_export2: requireFn(raw["__wbindgen_export2"], "__wbindgen_export2"),
52
+ __wbindgen_add_to_stack_pointer: requireFn(raw["__wbindgen_add_to_stack_pointer"], "__wbindgen_add_to_stack_pointer")
53
+ };
54
+ const start = raw["__wbindgen_start"];
55
+ if (typeof start === "function") exports.__wbindgen_start = requireFn(start, "__wbindgen_start");
56
+ return exports;
57
+ }
58
+ function passBytes(exports, bytes) {
59
+ const len = bytes.length;
60
+ const ptr = exports.__wbindgen_export(len, 1) >>> 0;
61
+ new Uint8Array(exports.memory.buffer, ptr, len).set(bytes);
62
+ return {
63
+ ptr,
64
+ len
65
+ };
66
+ }
67
+ function wasmVerify(exports, id, pubkey, sig) {
68
+ const idP = passBytes(exports, id);
69
+ const pkP = passBytes(exports, pubkey);
70
+ const sigP = passBytes(exports, sig);
71
+ return exports.verify(idP.ptr, idP.len, pkP.ptr, pkP.len, sigP.ptr, sigP.len) !== 0;
72
+ }
73
+ function wasmVerifySerialized(exports, serialized, id, pubkey, sig) {
74
+ const serP = passBytes(exports, serialized);
75
+ const idP = passBytes(exports, id);
76
+ const pkP = passBytes(exports, pubkey);
77
+ const sigP = passBytes(exports, sig);
78
+ return exports.verify_serialized(serP.ptr, serP.len, idP.ptr, idP.len, pkP.ptr, pkP.len, sigP.ptr, sigP.len) !== 0;
79
+ }
80
+ function takeBytes(exports, ptr, len) {
81
+ const out = new Uint8Array(len);
82
+ if (len > 0) {
83
+ out.set(new Uint8Array(exports.memory.buffer, ptr, len));
84
+ exports.__wbindgen_export2(ptr, len, 1);
85
+ }
86
+ return out;
87
+ }
88
+ function callReturningBytes(exports, invoke) {
89
+ const retptr = exports.__wbindgen_add_to_stack_pointer(-16);
90
+ try {
91
+ invoke(retptr);
92
+ const view = new DataView(exports.memory.buffer);
93
+ return takeBytes(exports, view.getUint32(retptr, true), view.getUint32(retptr + 4, true));
94
+ } finally {
95
+ exports.__wbindgen_add_to_stack_pointer(16);
96
+ }
97
+ }
98
+ function wasmSign(exports, id, seckey, aux) {
99
+ const idP = passBytes(exports, id);
100
+ const skP = passBytes(exports, seckey);
101
+ const auxP = passBytes(exports, aux);
102
+ return callReturningBytes(exports, (retptr) => {
103
+ exports.sign(retptr, idP.ptr, idP.len, skP.ptr, skP.len, auxP.ptr, auxP.len);
104
+ });
105
+ }
106
+ function wasmPublicKey(exports, seckey) {
107
+ const skP = passBytes(exports, seckey);
108
+ return callReturningBytes(exports, (retptr) => {
109
+ exports.public_key(retptr, skP.ptr, skP.len);
110
+ });
111
+ }
112
+ async function instantiateCryptoWasm(bytes) {
113
+ const holder = {};
114
+ const { module, instance } = await WebAssembly.instantiate(bytes, makeWbgImports(holder));
115
+ assertAllowedWasmImports(module);
116
+ holder.exports = asExports(instance.exports);
117
+ holder.exports.__wbindgen_start?.();
118
+ return holder.exports;
119
+ }
120
+ //#endregion
121
+ //#region src/adapter.ts
122
+ /**
123
+ * Run `fn` unless the instance is already poisoned; a `WebAssembly.RuntimeError` aborts the
124
+ * instance, so it is converted to {@link WasmPoisonedError} and rethrown on every later call.
125
+ */
126
+ function runPoisoned(poison, fn) {
127
+ if (poison.error !== void 0) throw poison.error;
128
+ try {
129
+ return fn();
130
+ } catch (error) {
131
+ if (error instanceof WebAssembly.RuntimeError) {
132
+ poison.error = new WasmPoisonedError("wasm instance aborted", { cause: error });
133
+ throw poison.error;
134
+ }
135
+ throw error;
136
+ }
137
+ }
138
+ /**
139
+ * Build the WASM event verifier on {@link createEventVerifier}. A `WebAssembly.RuntimeError` from
140
+ * the module means the instance aborted — it poisons every later call with the same
141
+ * `WasmPoisonedError`; any other backend error verifies `false` (the event is marked failed).
142
+ */
143
+ function createWasmEventVerifier(verifySerialized, poison) {
144
+ const backend = (serializedUtf8, id, pubkey, sig) => {
145
+ try {
146
+ return runPoisoned(poison, () => verifySerialized(serializedUtf8, id, pubkey, sig));
147
+ } catch (error) {
148
+ if (error instanceof WasmPoisonedError) throw error;
149
+ return false;
150
+ }
151
+ };
152
+ return createEventVerifier(backend);
153
+ }
154
+ //#endregion
155
+ //#region src/instance.ts
156
+ function isWasmBytes(value) {
157
+ return value instanceof ArrayBuffer || ArrayBuffer.isView(value);
158
+ }
159
+ async function fetchWasmUrl(url) {
160
+ const res = await fetch(url);
161
+ if (!res.ok) throw new CryptoError(`failed to fetch wasm: ${res.status} ${url.href}`);
162
+ return new Uint8Array(await res.arrayBuffer());
163
+ }
164
+ function requireByteLength(bytes, expected, label) {
165
+ if (bytes.length !== expected) throw new CryptoError(`invalid ${label} length: expected ${expected}, got ${bytes.length}`);
166
+ }
167
+ function bindExports(exports) {
168
+ const poison = {};
169
+ const rawSerialized = (serializedUtf8, id, pubkey, sig) => wasmVerifySerialized(exports, serializedUtf8, id, pubkey, sig);
170
+ return {
171
+ verify: (id, pubkey, sig) => runPoisoned(poison, () => wasmVerify(exports, id, pubkey, sig)),
172
+ verifySerialized: (serializedUtf8, id, pubkey, sig) => runPoisoned(poison, () => rawSerialized(serializedUtf8, id, pubkey, sig)),
173
+ verifyEvent: createWasmEventVerifier(rawSerialized, poison),
174
+ sign: (id, seckey, aux) => runPoisoned(poison, () => {
175
+ requireByteLength(id, 32, "id");
176
+ requireByteLength(seckey, 32, "secret key");
177
+ requireByteLength(aux, 32, "aux");
178
+ const sig = wasmSign(exports, id, seckey, aux);
179
+ if (sig.length !== 64) throw new CryptoError("wasm sign failed");
180
+ return sig;
181
+ }),
182
+ publicKey: (seckey) => runPoisoned(poison, () => {
183
+ requireByteLength(seckey, 32, "secret key");
184
+ const pk = wasmPublicKey(exports, seckey);
185
+ if (pk.length !== 32) throw new CryptoError("wasm publicKey failed");
186
+ return pk;
187
+ })
188
+ };
189
+ }
190
+ /** Builds a loader that interns a single instance per module slot. */
191
+ function createNostrWasmLoader(wasmBytes) {
192
+ let interned;
193
+ async function instantiate(opts) {
194
+ return bindExports(await instantiateCryptoWasm(await wasmBytes(opts)));
195
+ }
196
+ /** Instantiate once. Repeats reuse the same module. Failure throws; no noble fallback. */
197
+ async function loadNostrWasm(opts) {
198
+ if (interned) return interned;
199
+ const pending = instantiate(opts);
200
+ interned = pending;
201
+ try {
202
+ return await pending;
203
+ } catch (error) {
204
+ if (interned === pending) interned = void 0;
205
+ throw error;
206
+ }
207
+ }
208
+ function resetNostrWasm() {
209
+ interned = void 0;
210
+ }
211
+ return {
212
+ loadNostrWasm,
213
+ resetNostrWasm
214
+ };
215
+ }
216
+ //#endregion
217
+ export { WasmPoisonedError$1 as i, fetchWasmUrl as n, isWasmBytes as r, createNostrWasmLoader as t };
218
+
219
+ //# sourceMappingURL=instance-DS92CCrA.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"instance-DS92CCrA.mjs","names":[],"sources":["../src/abi.ts","../src/adapter.ts","../src/instance.ts"],"sourcesContent":["/** Wasm-bindgen 0.2.122 bundler-produced exports used by interned TS glue. */\nexport type CryptoWasmExports = {\n memory: WebAssembly.Memory;\n verify: (\n idPtr: number,\n idLen: number,\n pkPtr: number,\n pkLen: number,\n sigPtr: number,\n sigLen: number,\n ) => number;\n verify_serialized: (\n serPtr: number,\n serLen: number,\n idPtr: number,\n idLen: number,\n pkPtr: number,\n pkLen: number,\n sigPtr: number,\n sigLen: number,\n ) => number;\n sign: (\n retptr: number,\n idPtr: number,\n idLen: number,\n skPtr: number,\n skLen: number,\n auxPtr: number,\n auxLen: number,\n ) => void;\n public_key: (retptr: number, skPtr: number, skLen: number) => void;\n /** 0.2.122 name for `__wbindgen_malloc(size, align)`. */\n __wbindgen_export: (size: number, align: number) => number;\n /** 0.2.122 name for `__wbindgen_free(ptr, size, align)` after malloc claimed `__wbindgen_export`. */\n __wbindgen_export2: (ptr: number, size: number, align: number) => void;\n __wbindgen_add_to_stack_pointer: (delta: number) => number;\n __wbindgen_start?: () => void;\n};\n\n/** Imports 0.2.122 may request. Instantiation fails if anything else appears. */\nexport const ALLOWED_WASM_IMPORTS: ReadonlyArray<{ module: string; name: string }> = [\n { module: \"wbg\", name: \"__wbindgen_throw\" },\n { module: \"./nk_wasm_bg.js\", name: \"__wbindgen_throw\" },\n];\n\nconst utf8 = new TextDecoder();\n\nfunction decodeUtf8(memory: WebAssembly.Memory, ptr: number, len: number): string {\n return utf8.decode(new Uint8Array(memory.buffer, ptr, len));\n}\n\nfunction makeWbgImports(holder: { exports?: CryptoWasmExports }): WebAssembly.Imports {\n const throwRuntime = (ptr: number, len: number): never => {\n const mem = holder.exports?.memory;\n const msg = mem ? decodeUtf8(mem, ptr, len) : \"wasm panic\";\n throw new WebAssembly.RuntimeError(msg);\n };\n const wbg = {\n __wbindgen_throw: throwRuntime,\n };\n return {\n wbg,\n \"./nk_wasm_bg.js\": wbg,\n };\n}\n\n/** Fail if the module imports anything outside {@link ALLOWED_WASM_IMPORTS}. */\nexport function assertAllowedWasmImports(mod: WebAssembly.Module): void {\n const allowed = new Set(ALLOWED_WASM_IMPORTS.map((item) => `${item.module}\\0${item.name}`));\n for (const imp of WebAssembly.Module.imports(mod)) {\n if (imp.kind !== \"function\") {\n throw new TypeError(`unexpected wasm import kind ${imp.kind}: ${imp.module}.${imp.name}`);\n }\n if (!allowed.has(`${imp.module}\\0${imp.name}`)) {\n throw new TypeError(`unexpected wasm import ${imp.module}.${imp.name}`);\n }\n }\n}\n\nfunction requireMemory(value: WebAssembly.ExportValue | undefined): WebAssembly.Memory {\n if (!(value instanceof WebAssembly.Memory)) {\n throw new TypeError(\"wasm missing memory export\");\n }\n return value;\n}\n\n// oxlint-disable-next-line no-unnecessary-type-parameters -- T binds the declared ABI signature at each call site\nfunction requireFn<T extends (...args: number[]) => unknown>(\n value: WebAssembly.ExportValue | undefined,\n name: string,\n): T {\n if (typeof value !== \"function\") {\n throw new TypeError(`wasm missing ${name} export`);\n }\n // oxlint-disable-next-line no-unsafe-type-assertion -- wasm exports are opaque; each name is bound to the signature the ABI contract requires\n return value as T;\n}\n\nfunction asExports(raw: WebAssembly.Exports): CryptoWasmExports {\n const exports: CryptoWasmExports = {\n memory: requireMemory(raw[\"memory\"]),\n verify: requireFn(raw[\"verify\"], \"verify\"),\n verify_serialized: requireFn(raw[\"verify_serialized\"], \"verify_serialized\"),\n sign: requireFn(raw[\"sign\"], \"sign\"),\n public_key: requireFn(raw[\"public_key\"], \"public_key\"),\n __wbindgen_export: requireFn(raw[\"__wbindgen_export\"], \"__wbindgen_export\"),\n __wbindgen_export2: requireFn(raw[\"__wbindgen_export2\"], \"__wbindgen_export2\"),\n __wbindgen_add_to_stack_pointer: requireFn(\n raw[\"__wbindgen_add_to_stack_pointer\"],\n \"__wbindgen_add_to_stack_pointer\",\n ),\n };\n const start = raw[\"__wbindgen_start\"];\n if (typeof start === \"function\") {\n exports.__wbindgen_start = requireFn<() => void>(start, \"__wbindgen_start\");\n }\n return exports;\n}\n\nfunction passBytes(exports: CryptoWasmExports, bytes: Uint8Array): { ptr: number; len: number } {\n const len = bytes.length;\n const ptr = exports.__wbindgen_export(len, 1) >>> 0;\n new Uint8Array(exports.memory.buffer, ptr, len).set(bytes);\n return { ptr, len };\n}\n\nexport function wasmVerify(\n exports: CryptoWasmExports,\n id: Uint8Array,\n pubkey: Uint8Array,\n sig: Uint8Array,\n): boolean {\n const idP = passBytes(exports, id);\n const pkP = passBytes(exports, pubkey);\n const sigP = passBytes(exports, sig);\n return exports.verify(idP.ptr, idP.len, pkP.ptr, pkP.len, sigP.ptr, sigP.len) !== 0;\n}\n\nexport function wasmVerifySerialized(\n exports: CryptoWasmExports,\n serialized: Uint8Array,\n id: Uint8Array,\n pubkey: Uint8Array,\n sig: Uint8Array,\n): boolean {\n const serP = passBytes(exports, serialized);\n const idP = passBytes(exports, id);\n const pkP = passBytes(exports, pubkey);\n const sigP = passBytes(exports, sig);\n return (\n exports.verify_serialized(\n serP.ptr,\n serP.len,\n idP.ptr,\n idP.len,\n pkP.ptr,\n pkP.len,\n sigP.ptr,\n sigP.len,\n ) !== 0\n );\n}\n\nfunction takeBytes(exports: CryptoWasmExports, ptr: number, len: number): Uint8Array {\n const out = new Uint8Array(len);\n if (len > 0) {\n out.set(new Uint8Array(exports.memory.buffer, ptr, len));\n exports.__wbindgen_export2(ptr, len, 1);\n }\n return out;\n}\n\nfunction callReturningBytes(\n exports: CryptoWasmExports,\n invoke: (retptr: number) => void,\n): Uint8Array {\n const retptr = exports.__wbindgen_add_to_stack_pointer(-16);\n try {\n invoke(retptr);\n const view = new DataView(exports.memory.buffer);\n const ptr = view.getUint32(retptr, true);\n const len = view.getUint32(retptr + 4, true);\n return takeBytes(exports, ptr, len);\n } finally {\n exports.__wbindgen_add_to_stack_pointer(16);\n }\n}\n\nexport function wasmSign(\n exports: CryptoWasmExports,\n id: Uint8Array,\n seckey: Uint8Array,\n aux: Uint8Array,\n): Uint8Array {\n const idP = passBytes(exports, id);\n const skP = passBytes(exports, seckey);\n const auxP = passBytes(exports, aux);\n return callReturningBytes(exports, (retptr) => {\n exports.sign(retptr, idP.ptr, idP.len, skP.ptr, skP.len, auxP.ptr, auxP.len);\n });\n}\n\nexport function wasmPublicKey(exports: CryptoWasmExports, seckey: Uint8Array): Uint8Array {\n const skP = passBytes(exports, seckey);\n return callReturningBytes(exports, (retptr) => {\n exports.public_key(retptr, skP.ptr, skP.len);\n });\n}\n\nexport async function instantiateCryptoWasm(\n bytes: ArrayBuffer | ArrayBufferView,\n): Promise<CryptoWasmExports> {\n const holder: { exports?: CryptoWasmExports } = {};\n const { module, instance } = await WebAssembly.instantiate(bytes, makeWbgImports(holder));\n assertAllowedWasmImports(module);\n holder.exports = asExports(instance.exports);\n holder.exports.__wbindgen_start?.();\n return holder.exports;\n}\n","import { WasmPoisonedError, createEventVerifier } from \"@qntx/nostr/core\";\nimport type { EventVerifier, SerializedEventVerifier } from \"@qntx/nostr/core\";\n\nexport { WasmPoisonedError } from \"@qntx/nostr/core\";\n\n/**\n * Run `fn` unless the instance is already poisoned; a `WebAssembly.RuntimeError` aborts the\n * instance, so it is converted to {@link WasmPoisonedError} and rethrown on every later call.\n */\nexport function runPoisoned<T>(poison: { error?: Error }, fn: () => T): T {\n if (poison.error !== undefined) {\n throw poison.error;\n }\n try {\n return fn();\n } catch (error) {\n if (error instanceof WebAssembly.RuntimeError) {\n poison.error = new WasmPoisonedError(\"wasm instance aborted\", {\n cause: error,\n });\n throw poison.error;\n }\n throw error;\n }\n}\n\n/**\n * Build the WASM event verifier on {@link createEventVerifier}. A `WebAssembly.RuntimeError` from\n * the module means the instance aborted — it poisons every later call with the same\n * `WasmPoisonedError`; any other backend error verifies `false` (the event is marked failed).\n */\nexport function createWasmEventVerifier(\n verifySerialized: SerializedEventVerifier,\n poison: { error?: Error },\n): EventVerifier {\n const backend: SerializedEventVerifier = (serializedUtf8, id, pubkey, sig) => {\n try {\n return runPoisoned(poison, () => verifySerialized(serializedUtf8, id, pubkey, sig));\n } catch (error) {\n if (error instanceof WasmPoisonedError) {\n throw error;\n }\n return false;\n }\n };\n return createEventVerifier(backend);\n}\n","import { CryptoError } from \"@qntx/nostr/core\";\nimport type { SigningBackend, EventVerifier } from \"@qntx/nostr/core\";\n\nimport {\n instantiateCryptoWasm,\n wasmPublicKey,\n wasmSign,\n wasmVerify,\n wasmVerifySerialized,\n} from \"./abi.ts\";\nimport type { CryptoWasmExports } from \"./abi.ts\";\nimport { createWasmEventVerifier, runPoisoned } from \"./adapter.ts\";\n\nexport type LoadNostrWasmOptions = {\n /** Bytes, or a URL whose bytes will be read by the platform loader. */\n module?: ArrayBuffer | ArrayBufferView | URL | undefined;\n};\n\nexport type NostrWasm = SigningBackend & {\n verify: (id: Uint8Array, pubkey: Uint8Array, sig: Uint8Array) => boolean;\n verifySerialized: (\n serializedUtf8: Uint8Array,\n id: Uint8Array,\n pubkey: Uint8Array,\n sig: Uint8Array,\n ) => boolean;\n verifyEvent: EventVerifier;\n};\n\nexport function isWasmBytes(value: unknown): value is ArrayBuffer | ArrayBufferView {\n return value instanceof ArrayBuffer || ArrayBuffer.isView(value);\n}\n\nexport async function fetchWasmUrl(url: URL): Promise<Uint8Array> {\n const res = await fetch(url);\n if (!res.ok) {\n throw new CryptoError(`failed to fetch wasm: ${res.status} ${url.href}`);\n }\n return new Uint8Array(await res.arrayBuffer());\n}\n\nfunction requireByteLength(bytes: Uint8Array, expected: number, label: string): void {\n if (bytes.length !== expected) {\n throw new CryptoError(`invalid ${label} length: expected ${expected}, got ${bytes.length}`);\n }\n}\n\nfunction bindExports(exports: CryptoWasmExports): NostrWasm {\n const poison: { error?: Error } = {};\n const rawSerialized = (\n serializedUtf8: Uint8Array,\n id: Uint8Array,\n pubkey: Uint8Array,\n sig: Uint8Array,\n ): boolean => wasmVerifySerialized(exports, serializedUtf8, id, pubkey, sig);\n return {\n verify: (id, pubkey, sig) => runPoisoned(poison, () => wasmVerify(exports, id, pubkey, sig)),\n verifySerialized: (serializedUtf8, id, pubkey, sig) =>\n runPoisoned(poison, () => rawSerialized(serializedUtf8, id, pubkey, sig)),\n verifyEvent: createWasmEventVerifier(rawSerialized, poison),\n sign: (id, seckey, aux) =>\n runPoisoned(poison, () => {\n requireByteLength(id, 32, \"id\");\n requireByteLength(seckey, 32, \"secret key\");\n requireByteLength(aux, 32, \"aux\");\n const sig = wasmSign(exports, id, seckey, aux);\n if (sig.length !== 64) {\n throw new CryptoError(\"wasm sign failed\");\n }\n return sig;\n }),\n publicKey: (seckey) =>\n runPoisoned(poison, () => {\n requireByteLength(seckey, 32, \"secret key\");\n const pk = wasmPublicKey(exports, seckey);\n if (pk.length !== 32) {\n throw new CryptoError(\"wasm publicKey failed\");\n }\n return pk;\n }),\n };\n}\n\n/** Builds a loader that interns a single instance per module slot. */\nexport function createNostrWasmLoader(\n wasmBytes: (opts?: LoadNostrWasmOptions) => Promise<ArrayBuffer | ArrayBufferView>,\n): {\n loadNostrWasm: (opts?: LoadNostrWasmOptions) => Promise<NostrWasm>;\n resetNostrWasm: () => void;\n} {\n let interned: Promise<NostrWasm> | undefined;\n\n async function instantiate(opts?: LoadNostrWasmOptions): Promise<NostrWasm> {\n const bytes = await wasmBytes(opts);\n const exports = await instantiateCryptoWasm(bytes);\n return bindExports(exports);\n }\n\n /** Instantiate once. Repeats reuse the same module. Failure throws; no noble fallback. */\n async function loadNostrWasm(opts?: LoadNostrWasmOptions): Promise<NostrWasm> {\n if (interned) {\n return interned;\n }\n const pending = instantiate(opts);\n interned = pending;\n try {\n return await pending;\n } catch (error) {\n if (interned === pending) {\n interned = undefined;\n }\n throw error;\n }\n }\n\n function resetNostrWasm(): void {\n interned = undefined;\n }\n\n return { loadNostrWasm, resetNostrWasm };\n}\n"],"mappings":";;;AAwCA,MAAa,uBAAwE,CACnF;CAAE,QAAQ;CAAO,MAAM;AAAmB,GAC1C;CAAE,QAAQ;CAAmB,MAAM;AAAmB,CACxD;AAEA,MAAM,OAAO,IAAI,YAAY;AAE7B,SAAS,WAAW,QAA4B,KAAa,KAAqB;CACh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AAK,IAAI,KAAK;GAChC,MAAM,MAAM,SAAS,SAAS,IAAI,QAAQ,GAAG;GAC7C,IAAI,IAAI,WAAW,IACjB,MAAM,IAAI,YAAY,kBAAkB;GAE1C,OAAO;EACT,CAAC;EACH,YAAY,WACV,YAAY,cAAc;GACxB,kBAAkB,QAAQ,IAAI,YAAY;GAC1C,MAAM,KAAK,cAAc,SAAS,MAAM;GACxC,IAAI,GAAG,WAAW,IAChB,MAAM,IAAI,YAAY,uBAAuB;GAE/C,OAAO;EACT,CAAC;CACL;AACF;;AAGA,SAAgB,sBACd,WAIA;CACA,IAAI;CAEJ,eAAe,YAAY,MAAiD;EAG1E,OAAO,YAAY,MADG,sBAAsB,MADxB,UAAU,IAAI,CACe,CACvB;CAC5B;;CAGA,eAAe,cAAc,MAAiD;EAC5E,IAAI,UACF,OAAO;EAET,MAAM,UAAU,YAAY,IAAI;EAChC,WAAW;EACX,IAAI;GACF,OAAO,MAAM;EACf,SAAS,OAAO;GACd,IAAI,aAAa,SACf,WAAW,KAAA;GAEb,MAAM;EACR;CACF;CAEA,SAAS,iBAAuB;EAC9B,WAAW,KAAA;CACb;CAEA,OAAO;EAAE;EAAe;CAAe;AACzC"}
@@ -0,0 +1,4 @@
1
+ //#region \0wasm-url:/home/runner/work/nostr/nostr/packages/nostr-wasm/src/nk_wasm_bg.wasm
2
+ var nk_wasm_bg_default = new URL("nk_wasm_bg.wasm", import.meta.url).href;
3
+ //#endregion
4
+ export { nk_wasm_bg_default as default };
Binary file
package/package.json CHANGED
@@ -1,6 +1,79 @@
1
1
  {
2
2
  "name": "@qntx/nostr-wasm",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.10.1",
4
+ "description": "WebAssembly-accelerated cryptography backend for @qntx/nostr",
5
+ "keywords": [
6
+ "nostr",
7
+ "wasm",
8
+ "webassembly"
9
+ ],
10
+ "homepage": "https://github.com/qntx/nostr#readme",
11
+ "bugs": {
12
+ "url": "https://github.com/qntx/nostr/issues"
13
+ },
14
+ "license": "MIT OR Apache-2.0",
15
+ "author": "QuantX <x@qntx.org>",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/qntx/nostr.git",
19
+ "directory": "packages/nostr-wasm"
20
+ },
21
+ "files": [
22
+ "dist",
23
+ "LICENSE-MIT",
24
+ "LICENSE-APACHE"
25
+ ],
26
+ "type": "module",
27
+ "sideEffects": [
28
+ "**/*.wasm"
29
+ ],
30
+ "types": "./dist/index.d.mts",
31
+ "exports": {
32
+ ".": {
33
+ "types": "./dist/index.d.mts",
34
+ "browser": "./dist/browser.mjs",
35
+ "import": "./dist/index.mjs",
36
+ "default": "./dist/index.mjs"
37
+ },
38
+ "./browser": {
39
+ "types": "./dist/browser.d.mts",
40
+ "import": "./dist/browser.mjs",
41
+ "default": "./dist/browser.mjs"
42
+ },
43
+ "./package.json": "./package.json"
44
+ },
45
+ "publishConfig": {
46
+ "access": "public"
47
+ },
48
+ "scripts": {
49
+ "build:wasm": "vp run @qntx/nostr#build && bash scripts/build.sh && vp pack && publint && attw --pack . --profile esm-only",
50
+ "test:wasm": "vp test",
51
+ "bench:wasm": "BENCH=1 vp test tests/bench.ts",
52
+ "typecheck": "tsc --noEmit && tsc --noEmit -p tsconfig.src.json",
53
+ "check:pkg": "vp run @qntx/nostr#build && vp pack && publint && attw --pack . --profile esm-only"
54
+ },
55
+ "devDependencies": {
56
+ "@arethetypeswrong/cli": "0.18.5",
57
+ "@noble/curves": "2.4.0",
58
+ "@qntx/nostr": "0.10.1",
59
+ "@qntx/tsconfig": "1.0.1",
60
+ "@types/node": "26.6.3",
61
+ "binaryen": "132.0.0",
62
+ "publint": "0.3.24",
63
+ "typescript": "7.0.2",
64
+ "vite-plus": "1.0.0"
65
+ },
66
+ "peerDependencies": {
67
+ "@qntx/nostr": "^0.10.1"
68
+ },
69
+ "devEngines": {
70
+ "packageManager": {
71
+ "name": "bun",
72
+ "version": "1.4.0",
73
+ "onFail": "ignore"
74
+ }
75
+ },
76
+ "engines": {
77
+ "node": ">=20.19.0"
78
+ }
79
+ }