Skip to content

Commit 783b4b2

Browse files
committed
feat: add Hub API TypeScript starter template
- New hub-api-ts starter with Vite + TypeScript - Basic Hub API integration (checkout, signMessage, chooseAddress) - Playwright browser tests with Vitest - Added to CI workflow - Fixed @nimiq/core patch format issues - Disabled broken patch (works without it)
1 parent eb4767d commit 783b4b2

File tree

12 files changed

+2979
-124
lines changed

12 files changed

+2979
-124
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
runs-on: ubuntu-latest
1818
strategy:
1919
matrix:
20-
package: [nimiq-vue-ts, nimiq-react-ts, nimiq-nextjs]
20+
package: [nimiq-vue-ts, nimiq-react-ts, nimiq-nextjs, nimiq-hub-api-ts]
2121
steps:
2222
- uses: actions/checkout@v4
2323
- uses: pnpm/action-setup@v4

patches/@nimiq__core.patch

Lines changed: 104 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,115 @@
11
diff --git a/bundler/main-wasm/index.js b/bundler/main-wasm/index.js
2-
index e933a032a55715e7ba3c7fe4c44949212f5ac499..9ce1989f2556faef79b3124dc7097693cece7ab0 100644
32
--- a/bundler/main-wasm/index.js
43
+++ b/bundler/main-wasm/index.js
5-
@@ -1,5 +1,11 @@
6-
import * as wasm from "./index_bg.wasm";
4+
@@ -1,5 +1,34 @@
5+
-import * as wasm from "./index_bg.wasm";
6+
+import * as wasmModule from "./index_bg.wasm";
77
export * from "./index_bg.js";
8-
import { __wbg_set_wasm } from "./index_bg.js";
8+
-import { __wbg_set_wasm } from "./index_bg.js";
99
-__wbg_set_wasm(wasm);
1010
-wasm.__wbindgen_start();
11+
+import * as wasmBindings from "./index_bg.js";
1112
+
12-
+const wasmExports = typeof wasm === 'object' && wasm !== null && 'default' in wasm ? wasm.default : wasm;
13+
+const { __wbg_set_wasm } = wasmBindings;
14+
+
15+
+let wasmExports = wasmModule;
16+
+
17+
+const hasClientConfigFactory = value => typeof value?.clientconfiguration_new === "function";
18+
+
19+
+if (!hasClientConfigFactory(wasmExports)) {
20+
+ const candidate = wasmModule?.default ?? wasmModule;
21+
+
22+
+ try {
23+
+ if (candidate instanceof WebAssembly.Module) {
24+
+ const instance = new WebAssembly.Instance(candidate, {
25+
+ "./index_bg.js": wasmBindings,
26+
+ });
27+
+ wasmExports = instance.exports;
28+
+ }
29+
+ else if (candidate?.instance?.exports && hasClientConfigFactory(candidate.instance.exports)) {
30+
+ wasmExports = candidate.instance.exports;
31+
+ }
32+
+ }
33+
+ catch (error) {
34+
+ console.warn("Failed to instantiate @nimiq/core wasm module", error);
35+
+ }
36+
+}
1337
+
1438
+__wbg_set_wasm(wasmExports);
1539
+
16-
+if (typeof wasmExports?.__wbindgen_start === 'function') {
17-
+ wasmExports.__wbindgen_start();
40+
+if (typeof wasmExports?.__wbindgen_start === "function") {
41+
+ wasmExports.__wbindgen_start();
1842
+}
43+
44+
diff --git a/bundler/worker-wasm/index.js b/bundler/worker-wasm/index.js
45+
--- a/bundler/worker-wasm/index.js
46+
+++ b/bundler/worker-wasm/index.js
47+
@@ -1,5 +1,34 @@
48+
-import * as wasm from "./index_bg.wasm";
49+
+import * as wasmModule from "./index_bg.wasm";
50+
export * from "./index_bg.js";
51+
-import { __wbg_set_wasm } from "./index_bg.js";
52+
-__wbg_set_wasm(wasm);
53+
-wasm.__wbindgen_start();
54+
+import * as wasmBindings from "./index_bg.js";
55+
+
56+
+const { __wbg_set_wasm } = wasmBindings;
57+
+
58+
+let wasmExports = wasmModule;
59+
+
60+
+const hasClientConfigFactory = value => typeof value?.clientconfiguration_new === "function";
61+
+
62+
+if (!hasClientConfigFactory(wasmExports)) {
63+
+ const candidate = wasmModule?.default ?? wasmModule;
64+
+
65+
+ try {
66+
+ if (candidate instanceof WebAssembly.Module) {
67+
+ const instance = new WebAssembly.Instance(candidate, {
68+
+ "./index_bg.js": wasmBindings,
69+
+ });
70+
+ wasmExports = instance.exports;
71+
+ }
72+
+ else if (candidate?.instance?.exports && hasClientConfigFactory(candidate.instance.exports)) {
73+
+ wasmExports = candidate.instance.exports;
74+
+ }
75+
+ }
76+
+ catch (error) {
77+
+ console.warn("Failed to instantiate @nimiq/core worker wasm module", error);
78+
+ }
79+
+}
80+
+
81+
+__wbg_set_wasm(wasmExports);
82+
+
83+
+if (typeof wasmExports?.__wbindgen_start === "function") {
84+
+ wasmExports.__wbindgen_start();
85+
+}
86+
87+
diff --git a/bundler/index.js b/bundler/index.js
88+
--- a/bundler/index.js
89+
+++ b/bundler/index.js
90+
@@ -28,3 +28,9 @@
91+
export * from './main-wasm/index.js';
92+
export { Client };
93+
export * from '../lib/bundler/index.mjs';
94+
+
95+
+// Add init function for compatibility with web version
96+
+const init = async () => {
97+
+ // No-op: WASM is already initialized by main-wasm/index.js
98+
+};
99+
+export default init;
100+
101+
diff --git a/package.json b/package.json
102+
--- a/package.json
103+
+++ b/package.json
104+
@@ -26,6 +26,11 @@
105+
"browser": "./web/index.js",
106+
"import": "./web/index.js",
107+
"types": "./types/web.d.ts"
108+
+ },
109+
+ "./bundler/worker-wasm": {
110+
+ "import": "./bundler/worker-wasm/index.js",
111+
+ "browser": "./bundler/worker-wasm/index.js",
112+
+ "types": "./types/wasm/bundler.d.ts"
113+
}
114+
},
115+
"homepage": "https://nimiq.com",

0 commit comments

Comments
 (0)