@secondts/bark-react-native 0.24.0 → 0.25.0

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.
@@ -17,7 +17,7 @@ Pod::Spec.new do |s|
17
17
 
18
18
  s.source_files = "ios/*.{h,m,mm,swift}", "ios/generated/build/generated/ios/RNBarkReactNativeSpec/**/*.h", "ios/generated/build/generated/ios/RNBarkReactNativeSpecJSI.h", "ios/generated/build/generated/ios/RNBarkReactNativeSpecJSI-generated.cpp", "ios/generated/build/generated/ios/react/**/*.{h,cpp}", "cpp/**/*.{hpp,cpp,c,h}", "cpp/generated/**/*.{hpp,cpp,c,h}"
19
19
  s.vendored_frameworks = "build/RnBark.xcframework"
20
- s.dependency "uniffi-bindgen-react-native", "0.31.0-2"
20
+ s.dependency "uniffi-bindgen-react-native", "0.31.0-5"
21
21
 
22
22
  # Use install_modules_dependencies helper to install the dependencies if React Native version >=0.71.0.
23
23
  # See https://github.com/facebook/react-native/blob/febf6b7f33fdb4904669f99d795eba4c0f95d7bf/scripts/cocoapods/new_architecture.rb#L79.
package/README.md CHANGED
@@ -11,6 +11,8 @@ Bark is an implementation of the Ark protocol on bitcoin, led by [Second](https:
11
11
 
12
12
  ## Installation
13
13
 
14
+ Requires React Native 0.75+ (Expo SDK 52+) with the New Architecture enabled and Hermes, the default JavaScript engine.
15
+
14
16
  ### Expo
15
17
 
16
18
  1. Install the package:
@@ -60,7 +62,7 @@ npx expo install @secondts/bark-react-native@beta
60
62
 
61
63
  ```bash
62
64
  # Or install a specific beta version
63
- npx expo install @secondts/bark-react-native@0.23.0
65
+ npx expo install @secondts/bark-react-native@0.25.0
64
66
  ```
65
67
 
66
68
  For bare React Native projects, use:
@@ -1,14 +1,14 @@
1
1
  // Generated by uniffi-bindgen-react-native
2
2
  package com.barkreactnative
3
3
 
4
- import com.facebook.react.TurboReactPackage
4
+ import com.facebook.react.BaseReactPackage
5
5
  import com.facebook.react.bridge.NativeModule
6
6
  import com.facebook.react.bridge.ReactApplicationContext
7
7
  import com.facebook.react.module.model.ReactModuleInfo
8
8
  import com.facebook.react.module.model.ReactModuleInfoProvider
9
9
  import java.util.HashMap
10
10
 
11
- class BarkReactNativePackage : TurboReactPackage() {
11
+ class BarkReactNativePackage : BaseReactPackage() {
12
12
  override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? {
13
13
  return if (name == BarkReactNativeModule.NAME) {
14
14
  BarkReactNativeModule(reactContext)
@@ -457,6 +457,7 @@ extern "C" {
457
457
  /*handle*/ uint64_t uniffi_bark_ffi_fn_method_wallet_drain_exits(
458
458
  /*handle*/ uint64_t ptr,
459
459
  RustBuffer vtxo_ids,
460
+ int8_t drain_all,
460
461
  RustBuffer address,
461
462
  RustBuffer fee_rate_sat_per_vb
462
463
  );
@@ -573,6 +574,7 @@ extern "C" {
573
574
  );
574
575
  RustBuffer uniffi_bark_ffi_fn_method_wallet_mailbox_authorization(
575
576
  /*handle*/ uint64_t ptr,
577
+ uint32_t expiry_secs,
576
578
  RustCallStatus *uniffi_out_err
577
579
  );
578
580
  RustBuffer uniffi_bark_ffi_fn_method_wallet_mailbox_identifier(
@@ -1348,18 +1350,58 @@ template <> struct Bridging<RustBuffer> {
1348
1350
  static RustBuffer fromJs(jsi::Runtime &rt, std::shared_ptr<CallInvoker>,
1349
1351
  const jsi::Value &value) {
1350
1352
  try {
1353
+ auto obj = value.asObject(rt);
1354
+
1355
+ // Adoption vs copy. Two kinds of view arrive here:
1356
+ //
1357
+ // * Library-owned views from `rustbuffer_alloc`. Codegen allocates one,
1358
+ // fills it in place, and ships it as an argument — and never frees a
1359
+ // lowered argument, while the view's backing `CMutableBuffer` is
1360
+ // non-owning (its destructor leaves `data` alone). Such a view carries
1361
+ // a capacity hint (stamped by `rustbuffer_alloc` in the wrapper). We
1362
+ // *adopt* it: hand the existing allocation to the callee, which frees
1363
+ // it. Copying instead would orphan the allocation and leak one whole
1364
+ // payload per call.
1365
+ // * Ordinary JS-owned arrays, which carry no hint. These are *copied*
1366
+ // into a fresh library allocation — they are not ours to give away.
1367
+ //
1368
+ // On adoption we reset the hint to 0 so a later `rustbuffer_free(view)` is
1369
+ // a no-op rather than a double free.
1370
+ if (obj.hasProperty(rt, uniffi_jsi::kUbrnRustCapacity)) {
1371
+ auto capacity = static_cast<uint64_t>(
1372
+ obj.getProperty(rt, uniffi_jsi::kUbrnRustCapacity).asNumber());
1373
+ if (capacity == 0) {
1374
+ // Hint present but zeroed: the view was already adopted by a previous
1375
+ // call and its memory has been freed. Reading it would be a
1376
+ // use-after-free, so refuse rather than hand over a dangling pointer.
1377
+ throw jsi::JSError(
1378
+ rt,
1379
+ "RustBuffer argument was already consumed by a previous FFI call");
1380
+ }
1381
+ auto arrayBuffer =
1382
+ obj.getPropertyAsObject(rt, "buffer").getArrayBuffer(rt);
1383
+ auto byteOffset =
1384
+ static_cast<size_t>(obj.getProperty(rt, "byteOffset").asNumber());
1385
+ auto byteLength =
1386
+ static_cast<size_t>(obj.getProperty(rt, "byteLength").asNumber());
1387
+ obj.setProperty(rt, uniffi_jsi::kUbrnRustCapacity, jsi::Value(0));
1388
+ return RustBuffer{
1389
+ .capacity = capacity,
1390
+ .len = static_cast<uint64_t>(byteLength),
1391
+ .data = arrayBuffer.data(rt) + byteOffset,
1392
+ };
1393
+ }
1394
+
1351
1395
  auto buffer = uniffi_jsi::Bridging<jsi::ArrayBuffer>::value_to_arraybuffer(rt, value);
1352
1396
  auto bytes = ForeignBytes{
1353
1397
  .len = static_cast<int32_t>(buffer.length(rt)),
1354
1398
  .data = buffer.data(rt),
1355
1399
  };
1356
1400
 
1357
- // This buffer is constructed from foreign bytes. Rust scaffolding copies
1358
- // the bytes, to make the RustBuffer.
1401
+ // No hint: an ordinary JS-owned array. Rust scaffolding copies the bytes
1402
+ // to make the RustBuffer; the copy is destroyed when the callee
1403
+ // deserializes its arguments.
1359
1404
  auto buf = rustbuffer_from_bytes(bytes);
1360
- // Once it leaves this function, the buffer is immediately passed back
1361
- // into Rust, where it's used to deserialize into the Rust versions of the
1362
- // arguments. At that point, the copy is destroyed.
1363
1405
  return buf;
1364
1406
  } catch (const std::logic_error &e) {
1365
1407
  throw jsi::JSError(rt, e.what());
@@ -1368,24 +1410,31 @@ template <> struct Bridging<RustBuffer> {
1368
1410
 
1369
1411
  static jsi::Value toJs(jsi::Runtime &rt, std::shared_ptr<CallInvoker>,
1370
1412
  RustBuffer buf) {
1371
- // We need to make a copy of the bytes from Rust's memory space into
1372
- // Javascripts memory space. We need to do this because the two languages
1373
- // manages memory very differently: a garbage collector needs to track all
1374
- // the memory at runtime, Rust is doing it all closer to compile time.
1375
- uint8_t *bytes = new uint8_t[buf.len];
1376
- std::memcpy(bytes, buf.data, buf.len);
1377
-
1378
- // Construct an ArrayBuffer with copy of the bytes from the RustBuffer.
1413
+ // View-handoff: hand JS a `Uint8Array` view aliasing the Rust-owned bytes
1414
+ // (no boundary copy). The single mandatory copy now happens inside
1415
+ // `converter.lift(view)` (string decode, byte-array `set`, field-by-field
1416
+ // record reads). The codegen-emitted try/finally calls `rustbuffer_free`
1417
+ // on the view after `lift` returns, releasing the Rust allocation.
1418
+ //
1419
+ // Capacity hint: Rust may return a buffer where `capacity > len`. The
1420
+ // view's `byteLength` is `len` (so converters that decode the whole view
1421
+ // see only the message bytes), but `rustbuffer_free` needs `capacity` to
1422
+ // free correctly. We stash `capacity` on the view via a string-keyed
1423
+ // property when it differs from `len`; the JSI `rustbufferFree` host
1424
+ // function reads it back and falls back to `byteLength` for views from
1425
+ // `rustbufferAlloc(n)` where `byteLength == capacity` already.
1426
+ //
1427
+ // CMutableBuffer is non-owning here: its destructor leaves `buf.data`
1428
+ // alone. Only the codegen-emitted `rustbuffer_free` path frees it.
1379
1429
  auto payload = std::make_shared<uniffi_jsi::CMutableBuffer>(
1380
- uniffi_jsi::CMutableBuffer((uint8_t *)bytes, buf.len));
1381
- auto arrayBuffer = jsi::ArrayBuffer(rt, payload);
1382
-
1383
- // Once we have a Javascript version, we no longer need the Rust version, so
1384
- // we can call into Rust to tell it it's okay to free that memory.
1385
- rustbuffer_free(buf);
1386
-
1387
- // Finally, return the ArrayBuffer.
1388
- return uniffi_jsi::Bridging<jsi::ArrayBuffer>::arraybuffer_to_value(rt, arrayBuffer);;
1430
+ buf.data, static_cast<size_t>(buf.len));
1431
+ auto view = uniffi_jsi::arraybufferToUint8Array(
1432
+ rt, jsi::ArrayBuffer(rt, payload));
1433
+ if (buf.capacity != static_cast<uint64_t>(buf.len)) {
1434
+ view.setProperty(rt, uniffi_jsi::kUbrnRustCapacity,
1435
+ jsi::Value(static_cast<double>(buf.capacity)));
1436
+ }
1437
+ return jsi::Value(rt, view);
1389
1438
  }
1390
1439
  };
1391
1440
 
@@ -1410,9 +1459,22 @@ template <> struct Bridging<RustCallStatus> {
1410
1459
  const jsi::Value &jsStatus) {
1411
1460
  auto statusObject = jsStatus.asObject(rt);
1412
1461
  if (status.error_buf.data != nullptr) {
1413
- auto rbuf = Bridging<RustBuffer>::toJs(rt, callInvoker,
1414
- status.error_buf);
1415
- statusObject.setProperty(rt, "errorBuf", rbuf);
1462
+ // The error path is NOT wrapped in the codegen-emitted try/finally that
1463
+ // covers normal returns: `errorBuf` is read by the runtime's call-status
1464
+ // dispatcher (rust-call.ts) which throws straight to the user without
1465
+ // ever calling `rustbuffer_free`. Switching this site to view-handoff
1466
+ // would leak the Rust allocation, so we keep the copy semantics here:
1467
+ // copy the bytes into a JS-owned ArrayBuffer and free the Rust buffer
1468
+ // immediately. The errorBuf is small (a serialized error variant) and
1469
+ // only allocated on the cold error path, so the boundary copy is cheap.
1470
+ auto len = static_cast<size_t>(status.error_buf.len);
1471
+ uint8_t *bytes = new uint8_t[len];
1472
+ std::memcpy(bytes, status.error_buf.data, len);
1473
+ auto payload = std::make_shared<uniffi_jsi::CMutableBuffer>(bytes, len);
1474
+ auto view = uniffi_jsi::arraybufferToUint8Array(
1475
+ rt, jsi::ArrayBuffer(rt, payload));
1476
+ statusObject.setProperty(rt, "errorBuf", view);
1477
+ Bridging<RustBuffer>::rustbuffer_free(status.error_buf);
1416
1478
  }
1417
1479
  if (status.code != UNIFFI_CALL_STATUS_OK) {
1418
1480
  auto code =
@@ -2032,11 +2094,11 @@ template <> struct Bridging<UniffiForeignFutureResultU8> {
2032
2094
  // Create the vtable from the js callbacks.
2033
2095
  rsObject.return_value = uniffi_jsi::Bridging<uint8_t>::fromJs(
2034
2096
  rt, callInvoker,
2035
- jsObject.getProperty(rt, "returnValue")
2097
+ jsObject.getProperty(rt, "return_value")
2036
2098
  );
2037
2099
  rsObject.call_status = uniffi::bark::Bridging<RustCallStatus>::fromJs(
2038
2100
  rt, callInvoker,
2039
- jsObject.getProperty(rt, "callStatus")
2101
+ jsObject.getProperty(rt, "call_status")
2040
2102
  );
2041
2103
 
2042
2104
  return rsObject;
@@ -2106,11 +2168,11 @@ template <> struct Bridging<UniffiForeignFutureResultI8> {
2106
2168
  // Create the vtable from the js callbacks.
2107
2169
  rsObject.return_value = uniffi_jsi::Bridging<int8_t>::fromJs(
2108
2170
  rt, callInvoker,
2109
- jsObject.getProperty(rt, "returnValue")
2171
+ jsObject.getProperty(rt, "return_value")
2110
2172
  );
2111
2173
  rsObject.call_status = uniffi::bark::Bridging<RustCallStatus>::fromJs(
2112
2174
  rt, callInvoker,
2113
- jsObject.getProperty(rt, "callStatus")
2175
+ jsObject.getProperty(rt, "call_status")
2114
2176
  );
2115
2177
 
2116
2178
  return rsObject;
@@ -2180,11 +2242,11 @@ template <> struct Bridging<UniffiForeignFutureResultU16> {
2180
2242
  // Create the vtable from the js callbacks.
2181
2243
  rsObject.return_value = uniffi_jsi::Bridging<uint16_t>::fromJs(
2182
2244
  rt, callInvoker,
2183
- jsObject.getProperty(rt, "returnValue")
2245
+ jsObject.getProperty(rt, "return_value")
2184
2246
  );
2185
2247
  rsObject.call_status = uniffi::bark::Bridging<RustCallStatus>::fromJs(
2186
2248
  rt, callInvoker,
2187
- jsObject.getProperty(rt, "callStatus")
2249
+ jsObject.getProperty(rt, "call_status")
2188
2250
  );
2189
2251
 
2190
2252
  return rsObject;
@@ -2254,11 +2316,11 @@ template <> struct Bridging<UniffiForeignFutureResultI16> {
2254
2316
  // Create the vtable from the js callbacks.
2255
2317
  rsObject.return_value = uniffi_jsi::Bridging<int16_t>::fromJs(
2256
2318
  rt, callInvoker,
2257
- jsObject.getProperty(rt, "returnValue")
2319
+ jsObject.getProperty(rt, "return_value")
2258
2320
  );
2259
2321
  rsObject.call_status = uniffi::bark::Bridging<RustCallStatus>::fromJs(
2260
2322
  rt, callInvoker,
2261
- jsObject.getProperty(rt, "callStatus")
2323
+ jsObject.getProperty(rt, "call_status")
2262
2324
  );
2263
2325
 
2264
2326
  return rsObject;
@@ -2328,11 +2390,11 @@ template <> struct Bridging<UniffiForeignFutureResultU32> {
2328
2390
  // Create the vtable from the js callbacks.
2329
2391
  rsObject.return_value = uniffi_jsi::Bridging<uint32_t>::fromJs(
2330
2392
  rt, callInvoker,
2331
- jsObject.getProperty(rt, "returnValue")
2393
+ jsObject.getProperty(rt, "return_value")
2332
2394
  );
2333
2395
  rsObject.call_status = uniffi::bark::Bridging<RustCallStatus>::fromJs(
2334
2396
  rt, callInvoker,
2335
- jsObject.getProperty(rt, "callStatus")
2397
+ jsObject.getProperty(rt, "call_status")
2336
2398
  );
2337
2399
 
2338
2400
  return rsObject;
@@ -2402,11 +2464,11 @@ template <> struct Bridging<UniffiForeignFutureResultI32> {
2402
2464
  // Create the vtable from the js callbacks.
2403
2465
  rsObject.return_value = uniffi_jsi::Bridging<int32_t>::fromJs(
2404
2466
  rt, callInvoker,
2405
- jsObject.getProperty(rt, "returnValue")
2467
+ jsObject.getProperty(rt, "return_value")
2406
2468
  );
2407
2469
  rsObject.call_status = uniffi::bark::Bridging<RustCallStatus>::fromJs(
2408
2470
  rt, callInvoker,
2409
- jsObject.getProperty(rt, "callStatus")
2471
+ jsObject.getProperty(rt, "call_status")
2410
2472
  );
2411
2473
 
2412
2474
  return rsObject;
@@ -2476,11 +2538,11 @@ template <> struct Bridging<UniffiForeignFutureResultU64> {
2476
2538
  // Create the vtable from the js callbacks.
2477
2539
  rsObject.return_value = uniffi_jsi::Bridging<uint64_t>::fromJs(
2478
2540
  rt, callInvoker,
2479
- jsObject.getProperty(rt, "returnValue")
2541
+ jsObject.getProperty(rt, "return_value")
2480
2542
  );
2481
2543
  rsObject.call_status = uniffi::bark::Bridging<RustCallStatus>::fromJs(
2482
2544
  rt, callInvoker,
2483
- jsObject.getProperty(rt, "callStatus")
2545
+ jsObject.getProperty(rt, "call_status")
2484
2546
  );
2485
2547
 
2486
2548
  return rsObject;
@@ -2550,11 +2612,11 @@ template <> struct Bridging<UniffiForeignFutureResultI64> {
2550
2612
  // Create the vtable from the js callbacks.
2551
2613
  rsObject.return_value = uniffi_jsi::Bridging<int64_t>::fromJs(
2552
2614
  rt, callInvoker,
2553
- jsObject.getProperty(rt, "returnValue")
2615
+ jsObject.getProperty(rt, "return_value")
2554
2616
  );
2555
2617
  rsObject.call_status = uniffi::bark::Bridging<RustCallStatus>::fromJs(
2556
2618
  rt, callInvoker,
2557
- jsObject.getProperty(rt, "callStatus")
2619
+ jsObject.getProperty(rt, "call_status")
2558
2620
  );
2559
2621
 
2560
2622
  return rsObject;
@@ -2624,11 +2686,11 @@ template <> struct Bridging<UniffiForeignFutureResultF32> {
2624
2686
  // Create the vtable from the js callbacks.
2625
2687
  rsObject.return_value = uniffi_jsi::Bridging<float>::fromJs(
2626
2688
  rt, callInvoker,
2627
- jsObject.getProperty(rt, "returnValue")
2689
+ jsObject.getProperty(rt, "return_value")
2628
2690
  );
2629
2691
  rsObject.call_status = uniffi::bark::Bridging<RustCallStatus>::fromJs(
2630
2692
  rt, callInvoker,
2631
- jsObject.getProperty(rt, "callStatus")
2693
+ jsObject.getProperty(rt, "call_status")
2632
2694
  );
2633
2695
 
2634
2696
  return rsObject;
@@ -2698,11 +2760,11 @@ template <> struct Bridging<UniffiForeignFutureResultF64> {
2698
2760
  // Create the vtable from the js callbacks.
2699
2761
  rsObject.return_value = uniffi_jsi::Bridging<double>::fromJs(
2700
2762
  rt, callInvoker,
2701
- jsObject.getProperty(rt, "returnValue")
2763
+ jsObject.getProperty(rt, "return_value")
2702
2764
  );
2703
2765
  rsObject.call_status = uniffi::bark::Bridging<RustCallStatus>::fromJs(
2704
2766
  rt, callInvoker,
2705
- jsObject.getProperty(rt, "callStatus")
2767
+ jsObject.getProperty(rt, "call_status")
2706
2768
  );
2707
2769
 
2708
2770
  return rsObject;
@@ -2772,11 +2834,11 @@ template <> struct Bridging<UniffiForeignFutureResultRustBuffer> {
2772
2834
  // Create the vtable from the js callbacks.
2773
2835
  rsObject.return_value = uniffi::bark::Bridging<RustBuffer>::fromJs(
2774
2836
  rt, callInvoker,
2775
- jsObject.getProperty(rt, "returnValue")
2837
+ jsObject.getProperty(rt, "return_value")
2776
2838
  );
2777
2839
  rsObject.call_status = uniffi::bark::Bridging<RustCallStatus>::fromJs(
2778
2840
  rt, callInvoker,
2779
- jsObject.getProperty(rt, "callStatus")
2841
+ jsObject.getProperty(rt, "call_status")
2780
2842
  );
2781
2843
 
2782
2844
  return rsObject;
@@ -2846,7 +2908,7 @@ template <> struct Bridging<UniffiForeignFutureResultVoid> {
2846
2908
  // Create the vtable from the js callbacks.
2847
2909
  rsObject.call_status = uniffi::bark::Bridging<RustCallStatus>::fromJs(
2848
2910
  rt, callInvoker,
2849
- jsObject.getProperty(rt, "callStatus")
2911
+ jsObject.getProperty(rt, "call_status")
2850
2912
  );
2851
2913
 
2852
2914
  return rsObject;
@@ -4399,37 +4461,37 @@ template <> struct Bridging<UniffiVTableCallbackInterfaceCustomOnchainWalletCall
4399
4461
 
4400
4462
  // Create the vtable from the js callbacks.
4401
4463
  rsObject.uniffi_free = uniffi::bark::st::vtablecallbackinterfacecustomonchainwalletcallbacks::vtablecallbackinterfacecustomonchainwalletcallbacks::free::makeCallbackFunction(
4402
- rt, callInvoker, jsObject.getProperty(rt, "uniffiFree")
4464
+ rt, callInvoker, jsObject.getProperty(rt, "uniffi_free")
4403
4465
  );
4404
4466
  rsObject.uniffi_clone = uniffi::bark::cb::callbackinterfaceclone::vtablecallbackinterfacecustomonchainwalletcallbacks::makeCallbackFunction(
4405
- rt, callInvoker, jsObject.getProperty(rt, "uniffiClone")
4467
+ rt, callInvoker, jsObject.getProperty(rt, "uniffi_clone")
4406
4468
  );
4407
4469
  rsObject.get_balance = uniffi::bark::cb::callbackinterfacecustomonchainwalletcallbacksmethod0::vtablecallbackinterfacecustomonchainwalletcallbacks::makeCallbackFunction(
4408
- rt, callInvoker, jsObject.getProperty(rt, "getBalance")
4470
+ rt, callInvoker, jsObject.getProperty(rt, "get_balance")
4409
4471
  );
4410
4472
  rsObject.prepare_tx = uniffi::bark::cb::callbackinterfacecustomonchainwalletcallbacksmethod1::vtablecallbackinterfacecustomonchainwalletcallbacks::makeCallbackFunction(
4411
- rt, callInvoker, jsObject.getProperty(rt, "prepareTx")
4473
+ rt, callInvoker, jsObject.getProperty(rt, "prepare_tx")
4412
4474
  );
4413
4475
  rsObject.prepare_drain_tx = uniffi::bark::cb::callbackinterfacecustomonchainwalletcallbacksmethod2::vtablecallbackinterfacecustomonchainwalletcallbacks::makeCallbackFunction(
4414
- rt, callInvoker, jsObject.getProperty(rt, "prepareDrainTx")
4476
+ rt, callInvoker, jsObject.getProperty(rt, "prepare_drain_tx")
4415
4477
  );
4416
4478
  rsObject.finish_psbt = uniffi::bark::cb::callbackinterfacecustomonchainwalletcallbacksmethod3::vtablecallbackinterfacecustomonchainwalletcallbacks::makeCallbackFunction(
4417
- rt, callInvoker, jsObject.getProperty(rt, "finishPsbt")
4479
+ rt, callInvoker, jsObject.getProperty(rt, "finish_psbt")
4418
4480
  );
4419
4481
  rsObject.is_mine = uniffi::bark::cb::callbackinterfacecustomonchainwalletcallbacksmethod4::vtablecallbackinterfacecustomonchainwalletcallbacks::makeCallbackFunction(
4420
- rt, callInvoker, jsObject.getProperty(rt, "isMine")
4482
+ rt, callInvoker, jsObject.getProperty(rt, "is_mine")
4421
4483
  );
4422
4484
  rsObject.register_tx = uniffi::bark::cb::callbackinterfacecustomonchainwalletcallbacksmethod5::vtablecallbackinterfacecustomonchainwalletcallbacks::makeCallbackFunction(
4423
- rt, callInvoker, jsObject.getProperty(rt, "registerTx")
4485
+ rt, callInvoker, jsObject.getProperty(rt, "register_tx")
4424
4486
  );
4425
4487
  rsObject.evict_tx = uniffi::bark::cb::callbackinterfacecustomonchainwalletcallbacksmethod6::vtablecallbackinterfacecustomonchainwalletcallbacks::makeCallbackFunction(
4426
- rt, callInvoker, jsObject.getProperty(rt, "evictTx")
4488
+ rt, callInvoker, jsObject.getProperty(rt, "evict_tx")
4427
4489
  );
4428
4490
  rsObject.make_signed_p2a_cpfp = uniffi::bark::cb::callbackinterfacecustomonchainwalletcallbacksmethod7::vtablecallbackinterfacecustomonchainwalletcallbacks::makeCallbackFunction(
4429
- rt, callInvoker, jsObject.getProperty(rt, "makeSignedP2aCpfp")
4491
+ rt, callInvoker, jsObject.getProperty(rt, "make_signed_p2a_cpfp")
4430
4492
  );
4431
4493
  rsObject.store_signed_p2a_cpfp = uniffi::bark::cb::callbackinterfacecustomonchainwalletcallbacksmethod8::vtablecallbackinterfacecustomonchainwalletcallbacks::makeCallbackFunction(
4432
- rt, callInvoker, jsObject.getProperty(rt, "storeSignedP2aCpfp")
4494
+ rt, callInvoker, jsObject.getProperty(rt, "store_signed_p2a_cpfp")
4433
4495
  );
4434
4496
  rsObject.sync = uniffi::bark::cb::callbackinterfacecustomonchainwalletcallbacksmethod9::vtablecallbackinterfacecustomonchainwalletcallbacks::makeCallbackFunction(
4435
4497
  rt, callInvoker, jsObject.getProperty(rt, "sync")
@@ -4729,10 +4791,10 @@ template <> struct Bridging<UniffiVTableCallbackInterfaceBarkLogger> {
4729
4791
 
4730
4792
  // Create the vtable from the js callbacks.
4731
4793
  rsObject.uniffi_free = uniffi::bark::st::vtablecallbackinterfacebarklogger::vtablecallbackinterfacebarklogger::free::makeCallbackFunction(
4732
- rt, callInvoker, jsObject.getProperty(rt, "uniffiFree")
4794
+ rt, callInvoker, jsObject.getProperty(rt, "uniffi_free")
4733
4795
  );
4734
4796
  rsObject.uniffi_clone = uniffi::bark::cb::callbackinterfaceclone::vtablecallbackinterfacebarklogger::makeCallbackFunction(
4735
- rt, callInvoker, jsObject.getProperty(rt, "uniffiClone")
4797
+ rt, callInvoker, jsObject.getProperty(rt, "uniffi_clone")
4736
4798
  );
4737
4799
  rsObject.log = uniffi::bark::cb::callbackinterfacebarkloggermethod0::vtablecallbackinterfacebarklogger::makeCallbackFunction(
4738
4800
  rt, callInvoker, jsObject.getProperty(rt, "log")
@@ -4782,20 +4844,28 @@ NativeBark::NativeBark(
4782
4844
  return this->cpp_uniffi_internal_fn_func_ffi__string_to_byte_length(rt, thisVal, args, count);
4783
4845
  }
4784
4846
  );
4785
- props["ubrn_uniffi_internal_fn_func_ffi__string_to_arraybuffer"] = jsi::Function::createFromHostFunction(
4847
+ props["ubrn_uniffi_internal_fn_func_ffi__string_to_buffer"] = jsi::Function::createFromHostFunction(
4786
4848
  rt,
4787
- jsi::PropNameID::forAscii(rt, "ubrn_uniffi_internal_fn_func_ffi__string_to_arraybuffer"),
4849
+ jsi::PropNameID::forAscii(rt, "ubrn_uniffi_internal_fn_func_ffi__string_to_buffer"),
4788
4850
  1,
4789
4851
  [this](jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args, size_t count) -> jsi::Value {
4790
- return this->cpp_uniffi_internal_fn_func_ffi__string_to_arraybuffer(rt, thisVal, args, count);
4852
+ return this->cpp_uniffi_internal_fn_func_ffi__string_to_buffer(rt, thisVal, args, count);
4791
4853
  }
4792
4854
  );
4793
- props["ubrn_uniffi_internal_fn_func_ffi__arraybuffer_to_string"] = jsi::Function::createFromHostFunction(
4855
+ props["ubrn_uniffi_internal_fn_func_ffi__string_from_buffer"] = jsi::Function::createFromHostFunction(
4794
4856
  rt,
4795
- jsi::PropNameID::forAscii(rt, "ubrn_uniffi_internal_fn_func_ffi__arraybuffer_to_string"),
4857
+ jsi::PropNameID::forAscii(rt, "ubrn_uniffi_internal_fn_func_ffi__string_from_buffer"),
4796
4858
  1,
4797
4859
  [this](jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args, size_t count) -> jsi::Value {
4798
- return this->cpp_uniffi_internal_fn_func_ffi__arraybuffer_to_string(rt, thisVal, args, count);
4860
+ return this->cpp_uniffi_internal_fn_func_ffi__string_from_buffer(rt, thisVal, args, count);
4861
+ }
4862
+ );
4863
+ props["ubrn_uniffi_internal_fn_func_ffi__read_string_from_buffer"] = jsi::Function::createFromHostFunction(
4864
+ rt,
4865
+ jsi::PropNameID::forAscii(rt, "ubrn_uniffi_internal_fn_func_ffi__read_string_from_buffer"),
4866
+ 3,
4867
+ [this](jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args, size_t count) -> jsi::Value {
4868
+ return this->cpp_uniffi_internal_fn_func_ffi__read_string_from_buffer(rt, thisVal, args, count);
4799
4869
  }
4800
4870
  );
4801
4871
  props["ubrn_uniffi_bark_ffi_fn_clone_notificationholder"] = jsi::Function::createFromHostFunction(
@@ -5265,7 +5335,7 @@ NativeBark::NativeBark(
5265
5335
  props["ubrn_uniffi_bark_ffi_fn_method_wallet_drain_exits"] = jsi::Function::createFromHostFunction(
5266
5336
  rt,
5267
5337
  jsi::PropNameID::forAscii(rt, "ubrn_uniffi_bark_ffi_fn_method_wallet_drain_exits"),
5268
- 4,
5338
+ 5,
5269
5339
  [this](jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args, size_t count) -> jsi::Value {
5270
5340
  return this->cpp_uniffi_bark_ffi_fn_method_wallet_drain_exits(rt, thisVal, args, count);
5271
5341
  }
@@ -5489,7 +5559,7 @@ NativeBark::NativeBark(
5489
5559
  props["ubrn_uniffi_bark_ffi_fn_method_wallet_mailbox_authorization"] = jsi::Function::createFromHostFunction(
5490
5560
  rt,
5491
5561
  jsi::PropNameID::forAscii(rt, "ubrn_uniffi_bark_ffi_fn_method_wallet_mailbox_authorization"),
5492
- 1,
5562
+ 2,
5493
5563
  [this](jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args, size_t count) -> jsi::Value {
5494
5564
  return this->cpp_uniffi_bark_ffi_fn_method_wallet_mailbox_authorization(rt, thisVal, args, count);
5495
5565
  }
@@ -7534,6 +7604,101 @@ NativeBark::NativeBark(
7534
7604
  return this->cpp_uniffi_internal_fn_method_wallet_ffi__bless_pointer(rt, thisVal, args, count);
7535
7605
  }
7536
7606
  );
7607
+
7608
+ // `rustbuffer_alloc(n)` -> Uint8Array view over Rust-owned memory of capacity `n`.
7609
+ // `rustbuffer_free(view)` -> hands the underlying (ptr, capacity) back to the
7610
+ // crate's `rustbuffer_free`. Together they let JS allocate buffers that the
7611
+ // codegen-emitted lowering path can fill in place and ship to Rust without copying.
7612
+ props["rustbuffer_alloc"] = jsi::Function::createFromHostFunction(
7613
+ rt,
7614
+ jsi::PropNameID::forAscii(rt, "rustbuffer_alloc"),
7615
+ 1,
7616
+ [](jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args, size_t count) -> jsi::Value {
7617
+ if (count < 1 || !args[0].isNumber()) {
7618
+ throw jsi::JSError(rt, "rustbuffer_alloc expected a number argument");
7619
+ }
7620
+ double size = args[0].asNumber();
7621
+ if (size < 0) {
7622
+ throw jsi::JSError(rt, "rustbuffer_alloc: size must be non-negative");
7623
+ }
7624
+ if (size > INT32_MAX) {
7625
+ throw jsi::JSError(rt, "rustbuffer_alloc: size exceeds INT32_MAX");
7626
+ }
7627
+ auto rb = uniffi::bark::Bridging<RustBuffer>::rustbuffer_alloc(static_cast<int32_t>(size));
7628
+ if (rb.data == nullptr) {
7629
+ throw jsi::JSError(rt, "rustbuffer_alloc failed: alloc returned null");
7630
+ }
7631
+ // Non-owning view over Rust-allocated memory; CMutableBuffer's destructor
7632
+ // is the default and does not free `rb.data`. The allocation is released
7633
+ // either by an explicit `rustbuffer_free(view)` or by being adopted when
7634
+ // the view is lowered as an FFI argument.
7635
+ auto payload = std::make_shared<uniffi_jsi::CMutableBuffer>(
7636
+ rb.data, static_cast<size_t>(rb.capacity));
7637
+ // Wrap as Uint8Array so JS can index/assign bytes directly.
7638
+ auto view = uniffi_jsi::arraybufferToUint8Array(
7639
+ rt, jsi::ArrayBuffer(rt, payload));
7640
+ // Stamp the capacity so the argument-lowering path
7641
+ // (`Bridging<RustBuffer>::fromJs`) recognises this view as
7642
+ // library-owned and adopts the allocation instead of copying it.
7643
+ // Without the stamp, a lowered argument is copied and this
7644
+ // allocation is orphaned — one leaked payload per call.
7645
+ if (rb.capacity > 0) {
7646
+ view.setProperty(rt, uniffi_jsi::kUbrnRustCapacity,
7647
+ jsi::Value(static_cast<double>(rb.capacity)));
7648
+ }
7649
+ return jsi::Value(rt, view);
7650
+ }
7651
+ );
7652
+
7653
+ props["rustbuffer_free"] = jsi::Function::createFromHostFunction(
7654
+ rt,
7655
+ jsi::PropNameID::forAscii(rt, "rustbuffer_free"),
7656
+ 1,
7657
+ [](jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args, size_t count) -> jsi::Value {
7658
+ if (count < 1 || !args[0].isObject()) {
7659
+ throw jsi::JSError(rt, "rustbuffer_free expected a Uint8Array argument");
7660
+ }
7661
+ auto view = args[0].asObject(rt);
7662
+ auto byteLength =
7663
+ static_cast<size_t>(view.getProperty(rt, "byteLength").asNumber());
7664
+ // Empty views were never allocated by `rustbuffer_alloc`; nothing
7665
+ // to free. Bail out before reading buffer/byteOffset/capacity to
7666
+ // skip three JSI property traversals on the empty path.
7667
+ if (byteLength == 0) {
7668
+ return jsi::Value::undefined();
7669
+ }
7670
+ // Capacity resolution:
7671
+ // * For a view from `rustbuffer_alloc(n)`, `byteLength == n == capacity`,
7672
+ // and no `__ubrnRustCapacity` hint was set.
7673
+ // * For a view from a lift-handoff, the codegen-emitted
7674
+ // `Bridging<RustBuffer>::toJs` set `byteLength = len` and stashed
7675
+ // the original `capacity` on `__ubrnRustCapacity` whenever
7676
+ // `capacity != len`.
7677
+ // So: prefer the hint, fall back to byteLength.
7678
+ size_t capacity = byteLength;
7679
+ if (view.hasProperty(rt, uniffi_jsi::kUbrnRustCapacity)) {
7680
+ capacity = static_cast<size_t>(
7681
+ view.getProperty(rt, uniffi_jsi::kUbrnRustCapacity).asNumber());
7682
+ }
7683
+ // A zero capacity marks a view already adopted as an FFI argument
7684
+ // (its hint was reset to 0) and freed by the callee. Freeing again
7685
+ // would be a double free, so this is a no-op.
7686
+ if (capacity == 0) {
7687
+ return jsi::Value::undefined();
7688
+ }
7689
+ auto buffer = view.getPropertyAsObject(rt, "buffer").getArrayBuffer(rt);
7690
+ auto byteOffset =
7691
+ static_cast<size_t>(view.getProperty(rt, "byteOffset").asNumber());
7692
+ // Honour byteOffset for safety (defensive; currently always 0).
7693
+ RustBuffer rb {
7694
+ .capacity = static_cast<uint64_t>(capacity),
7695
+ .len = 0,
7696
+ .data = buffer.data(rt) + byteOffset,
7697
+ };
7698
+ uniffi::bark::Bridging<RustBuffer>::rustbuffer_free(rb);
7699
+ return jsi::Value::undefined();
7700
+ }
7701
+ );
7537
7702
  }
7538
7703
 
7539
7704
  void NativeBark::registerModule(jsi::Runtime &rt, std::shared_ptr<react::CallInvoker> callInvoker) {
@@ -7551,7 +7716,7 @@ jsi::Value NativeBark::get(jsi::Runtime& rt, const jsi::PropNameID& name) {
7551
7716
  try {
7552
7717
  return jsi::Value(rt, props.at(name.utf8(rt)));
7553
7718
  }
7554
- catch (std::out_of_range &e) {
7719
+ catch (std::out_of_range &) {
7555
7720
  return jsi::Value::undefined();
7556
7721
  }
7557
7722
  }
@@ -7595,12 +7760,16 @@ jsi::Value NativeBark::cpp_uniffi_internal_fn_func_ffi__string_to_byte_length(js
7595
7760
  return uniffi_jsi::Bridging<std::string>::string_to_bytelength(rt, args[0]);
7596
7761
  }
7597
7762
 
7598
- jsi::Value NativeBark::cpp_uniffi_internal_fn_func_ffi__string_to_arraybuffer(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count) {
7599
- return uniffi_jsi::Bridging<std::string>::string_to_arraybuffer(rt, args[0]);
7763
+ jsi::Value NativeBark::cpp_uniffi_internal_fn_func_ffi__string_to_buffer(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count) {
7764
+ return uniffi_jsi::Bridging<std::string>::string_to_buffer(rt, args[0]);
7765
+ }
7766
+
7767
+ jsi::Value NativeBark::cpp_uniffi_internal_fn_func_ffi__string_from_buffer(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count) {
7768
+ return uniffi_jsi::Bridging<std::string>::string_from_buffer(rt, args[0]);
7600
7769
  }
7601
7770
 
7602
- jsi::Value NativeBark::cpp_uniffi_internal_fn_func_ffi__arraybuffer_to_string(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count) {
7603
- return uniffi_jsi::Bridging<std::string>::arraybuffer_to_string(rt, args[0]);
7771
+ jsi::Value NativeBark::cpp_uniffi_internal_fn_func_ffi__read_string_from_buffer(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count) {
7772
+ return uniffi_jsi::Bridging<std::string>::read_string_from_buffer(rt, args[0], args[1], args[2]);
7604
7773
  }jsi::Value NativeBark::cpp_uniffi_internal_fn_method_notificationholder_ffi__bless_pointer(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count) {
7605
7774
  auto pointer = uniffi_jsi::Bridging<uint64_t>::fromJs(rt, callInvoker, args[0]);
7606
7775
  auto static destructor = [](uint64_t p) {
@@ -8145,7 +8314,7 @@ jsi::Value NativeBark::cpp_uniffi_bark_ffi_fn_method_wallet_config(jsi::Runtime&
8145
8314
  return uniffi_jsi::Bridging</*handle*/ uint64_t>::toJs(rt, callInvoker, value);
8146
8315
  }
8147
8316
  jsi::Value NativeBark::cpp_uniffi_bark_ffi_fn_method_wallet_drain_exits(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count) {
8148
- auto value = uniffi_bark_ffi_fn_method_wallet_drain_exits(uniffi_jsi::Bridging</*handle*/ uint64_t>::fromJs(rt, callInvoker, args[0]), uniffi::bark::Bridging<RustBuffer>::fromJs(rt, callInvoker, args[1]), uniffi::bark::Bridging<RustBuffer>::fromJs(rt, callInvoker, args[2]), uniffi::bark::Bridging<RustBuffer>::fromJs(rt, callInvoker, args[3])
8317
+ auto value = uniffi_bark_ffi_fn_method_wallet_drain_exits(uniffi_jsi::Bridging</*handle*/ uint64_t>::fromJs(rt, callInvoker, args[0]), uniffi::bark::Bridging<RustBuffer>::fromJs(rt, callInvoker, args[1]), uniffi_jsi::Bridging<int8_t>::fromJs(rt, callInvoker, args[2]), uniffi::bark::Bridging<RustBuffer>::fromJs(rt, callInvoker, args[3]), uniffi::bark::Bridging<RustBuffer>::fromJs(rt, callInvoker, args[4])
8149
8318
  );
8150
8319
 
8151
8320
 
@@ -8345,7 +8514,7 @@ jsi::Value NativeBark::cpp_uniffi_bark_ffi_fn_method_wallet_lock_vtxos(jsi::Runt
8345
8514
  }
8346
8515
  jsi::Value NativeBark::cpp_uniffi_bark_ffi_fn_method_wallet_mailbox_authorization(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count) {
8347
8516
  RustCallStatus status = uniffi::bark::Bridging<RustCallStatus>::rustSuccess(rt);
8348
- auto value = uniffi_bark_ffi_fn_method_wallet_mailbox_authorization(uniffi_jsi::Bridging</*handle*/ uint64_t>::fromJs(rt, callInvoker, args[0]),
8517
+ auto value = uniffi_bark_ffi_fn_method_wallet_mailbox_authorization(uniffi_jsi::Bridging</*handle*/ uint64_t>::fromJs(rt, callInvoker, args[0]), uniffi_jsi::Bridging<uint32_t>::fromJs(rt, callInvoker, args[1]),
8349
8518
  &status
8350
8519
  );
8351
8520
  uniffi::bark::Bridging<RustCallStatus>::copyIntoJs(rt, callInvoker, status, args[count - 1]);
@@ -19,8 +19,9 @@ class NativeBark : public jsi::HostObject {
19
19
  protected:
20
20
  std::map<std::string,jsi::Value> props;
21
21
  jsi::Value cpp_uniffi_internal_fn_func_ffi__string_to_byte_length(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count);
22
- jsi::Value cpp_uniffi_internal_fn_func_ffi__string_to_arraybuffer(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count);
23
- jsi::Value cpp_uniffi_internal_fn_func_ffi__arraybuffer_to_string(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count);
22
+ jsi::Value cpp_uniffi_internal_fn_func_ffi__string_to_buffer(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count);
23
+ jsi::Value cpp_uniffi_internal_fn_func_ffi__string_from_buffer(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count);
24
+ jsi::Value cpp_uniffi_internal_fn_func_ffi__read_string_from_buffer(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count);
24
25
  jsi::Value cpp_uniffi_bark_ffi_fn_clone_notificationholder(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count);
25
26
  jsi::Value cpp_uniffi_bark_ffi_fn_free_notificationholder(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count);
26
27
  jsi::Value cpp_uniffi_bark_ffi_fn_method_notificationholder_cancel_next_notification_wait(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count);