webycash-sdk 0.2.15 → 0.2.16

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.
@@ -39,6 +39,15 @@ function takeString(val) {
39
39
  return "";
40
40
  return String(val);
41
41
  }
42
+ /** Parse "Recovery completed! Webcash recovered: N, Total amount: X" */
43
+ function parseRecoveryResult(s) {
44
+ const countMatch = s.match(/recovered:\s*(\d+)/i);
45
+ const amountMatch = s.match(/amount:\s*([\d.]+)/i);
46
+ return {
47
+ recoveredCount: countMatch ? parseInt(countMatch[1], 10) : 0,
48
+ totalAmount: amountMatch ? BigInt(Math.round(parseFloat(amountMatch[1]) * 1e8)) : 0n,
49
+ };
50
+ }
42
51
  function assertFfi(handle) {
43
52
  if (handle._tag !== "ffi")
44
53
  throw new Error("Expected FFI handle");
@@ -126,8 +135,11 @@ export class FfiBackend {
126
135
  return { handle, paymentWebcash: takeString(out[0]) };
127
136
  }
128
137
  async walletCheck(handle) {
138
+ // FFI check() only returns success/failure — no detailed counts available via C ABI
129
139
  check(ffi.weby_wallet_check(assertFfi(handle)));
130
- return { handle, result: { validCount: 0, spentCount: 0 } };
140
+ // Re-query stats to get actual counts post-check
141
+ const stats = await this.walletStats(handle);
142
+ return { handle, result: { validCount: stats.unspentWebcash, spentCount: stats.spentWebcash } };
131
143
  }
132
144
  async walletMerge(handle, maxOutputs) {
133
145
  const out = [null];
@@ -137,12 +149,12 @@ export class FfiBackend {
137
149
  async walletRecover(handle, masterSecretHex, gapLimit) {
138
150
  const out = [null];
139
151
  check(ffi.weby_wallet_recover(assertFfi(handle), masterSecretHex, gapLimit, out));
140
- return { handle, result: { recoveredCount: 0, totalAmount: 0n } };
152
+ return { handle, result: parseRecoveryResult(takeString(out[0])) };
141
153
  }
142
154
  async walletRecoverFromWallet(handle, gapLimit) {
143
155
  const out = [null];
144
156
  check(ffi.weby_wallet_recover_from_wallet(assertFfi(handle), gapLimit, out));
145
- return { handle, result: { recoveredCount: 0, totalAmount: 0n } };
157
+ return { handle, result: parseRecoveryResult(takeString(out[0])) };
146
158
  }
147
159
  // ── Inspection ─────────────────────────────────────────────
148
160
  async walletStats(handle) {
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webycash-sdk",
3
- "version": "0.2.15",
3
+ "version": "0.2.16",
4
4
  "description": "Webcash SDK — Node.js, Browser, Deno, Bun (FFI + WASM)",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
package/wasm/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "Webycash Developers"
6
6
  ],
7
7
  "description": "Webcash SDK — WebAssembly bindings",
8
- "version": "0.2.15",
8
+ "version": "0.2.16",
9
9
  "license": "MIT",
10
10
  "repository": {
11
11
  "type": "git",
Binary file
package/webycash_sdk.dll CHANGED
Binary file