react-native-nitro-ark 0.0.131 → 0.0.133

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.
@@ -32,6 +32,7 @@
32
32
 
33
33
  #include <string>
34
34
  #include <optional>
35
+ #include <vector>
35
36
 
36
37
  namespace margelo::nitro::nitroark {
37
38
 
@@ -40,15 +41,19 @@ namespace margelo::nitro::nitroark {
40
41
  */
41
42
  struct LightningReceive final {
42
43
  public:
44
+ std::string state SWIFT_PRIVATE;
45
+ std::optional<std::string> phase SWIFT_PRIVATE;
43
46
  std::string payment_hash SWIFT_PRIVATE;
44
47
  std::string payment_preimage SWIFT_PRIVATE;
45
48
  std::string invoice SWIFT_PRIVATE;
46
- std::optional<double> preimage_revealed_at SWIFT_PRIVATE;
47
- std::optional<double> finished_at SWIFT_PRIVATE;
49
+ std::vector<std::string> htlc_vtxo_ids SWIFT_PRIVATE;
50
+ std::optional<double> movement_id SWIFT_PRIVATE;
51
+ std::optional<double> amount_sat SWIFT_PRIVATE;
52
+ std::optional<double> settled_at SWIFT_PRIVATE;
48
53
 
49
54
  public:
50
55
  LightningReceive() = default;
51
- explicit LightningReceive(std::string payment_hash, std::string payment_preimage, std::string invoice, std::optional<double> preimage_revealed_at, std::optional<double> finished_at): payment_hash(payment_hash), payment_preimage(payment_preimage), invoice(invoice), preimage_revealed_at(preimage_revealed_at), finished_at(finished_at) {}
56
+ explicit LightningReceive(std::string state, std::optional<std::string> phase, std::string payment_hash, std::string payment_preimage, std::string invoice, std::vector<std::string> htlc_vtxo_ids, std::optional<double> movement_id, std::optional<double> amount_sat, std::optional<double> settled_at): state(state), phase(phase), payment_hash(payment_hash), payment_preimage(payment_preimage), invoice(invoice), htlc_vtxo_ids(htlc_vtxo_ids), movement_id(movement_id), amount_sat(amount_sat), settled_at(settled_at) {}
52
57
 
53
58
  public:
54
59
  friend bool operator==(const LightningReceive& lhs, const LightningReceive& rhs) = default;
@@ -64,20 +69,28 @@ namespace margelo::nitro {
64
69
  static inline margelo::nitro::nitroark::LightningReceive fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
65
70
  jsi::Object obj = arg.asObject(runtime);
66
71
  return margelo::nitro::nitroark::LightningReceive(
72
+ JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "state"))),
73
+ JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "phase"))),
67
74
  JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "payment_hash"))),
68
75
  JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "payment_preimage"))),
69
76
  JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "invoice"))),
70
- JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "preimage_revealed_at"))),
71
- JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "finished_at")))
77
+ JSIConverter<std::vector<std::string>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "htlc_vtxo_ids"))),
78
+ JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "movement_id"))),
79
+ JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "amount_sat"))),
80
+ JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "settled_at")))
72
81
  );
73
82
  }
74
83
  static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::nitroark::LightningReceive& arg) {
75
84
  jsi::Object obj(runtime);
85
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "state"), JSIConverter<std::string>::toJSI(runtime, arg.state));
86
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "phase"), JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.phase));
76
87
  obj.setProperty(runtime, PropNameIDCache::get(runtime, "payment_hash"), JSIConverter<std::string>::toJSI(runtime, arg.payment_hash));
77
88
  obj.setProperty(runtime, PropNameIDCache::get(runtime, "payment_preimage"), JSIConverter<std::string>::toJSI(runtime, arg.payment_preimage));
78
89
  obj.setProperty(runtime, PropNameIDCache::get(runtime, "invoice"), JSIConverter<std::string>::toJSI(runtime, arg.invoice));
79
- obj.setProperty(runtime, PropNameIDCache::get(runtime, "preimage_revealed_at"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.preimage_revealed_at));
80
- obj.setProperty(runtime, PropNameIDCache::get(runtime, "finished_at"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.finished_at));
90
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "htlc_vtxo_ids"), JSIConverter<std::vector<std::string>>::toJSI(runtime, arg.htlc_vtxo_ids));
91
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "movement_id"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.movement_id));
92
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "amount_sat"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.amount_sat));
93
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "settled_at"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.settled_at));
81
94
  return obj;
82
95
  }
83
96
  static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
@@ -88,11 +101,15 @@ namespace margelo::nitro {
88
101
  if (!nitro::isPlainObject(runtime, obj)) {
89
102
  return false;
90
103
  }
104
+ if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "state")))) return false;
105
+ if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "phase")))) return false;
91
106
  if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "payment_hash")))) return false;
92
107
  if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "payment_preimage")))) return false;
93
108
  if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "invoice")))) return false;
94
- if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "preimage_revealed_at")))) return false;
95
- if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "finished_at")))) return false;
109
+ if (!JSIConverter<std::vector<std::string>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "htlc_vtxo_ids")))) return false;
110
+ if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "movement_id")))) return false;
111
+ if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "amount_sat")))) return false;
112
+ if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "settled_at")))) return false;
96
113
  return true;
97
114
  }
98
115
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-nitro-ark",
3
- "version": "0.0.131",
3
+ "version": "0.0.133",
4
4
  "description": "Pure C++ Nitro Modules for Ark client",
5
5
  "source": "./src/index.tsx",
6
6
  "main": "./lib/module/index.js",
@@ -6,7 +6,8 @@ import type { HybridObject } from 'react-native-nitro-modules';
6
6
 
7
7
  export interface BarkConfigOpts {
8
8
  ark: string;
9
- server_access_token?: string;
9
+ /** Client identifier sent as `x-user-agent`, formatted as `<name>/<version>`. */
10
+ user_agent?: string;
10
11
  esplora?: string;
11
12
  bitcoind?: string;
12
13
  bitcoind_cookie?: string;
@@ -227,11 +228,15 @@ export interface MailboxAuthorizationResult {
227
228
  }
228
229
 
229
230
  export interface LightningReceive {
231
+ state: string;
232
+ phase?: string;
230
233
  payment_hash: string;
231
234
  payment_preimage: string;
232
235
  invoice: string;
233
- preimage_revealed_at?: number;
234
- finished_at?: number;
236
+ htlc_vtxo_ids: string[];
237
+ movement_id?: number;
238
+ amount_sat?: number;
239
+ settled_at?: number;
235
240
  }
236
241
 
237
242
  export interface BarkMovementSubsystem {
@@ -320,6 +325,7 @@ export interface WalletStateChangeSubscription
320
325
 
321
326
  export interface NitroArk extends HybridObject<{ ios: 'c++'; android: 'c++' }> {
322
327
  // --- Management ---
328
+ getBarkVersion(): string;
323
329
  createMnemonic(): Promise<string>;
324
330
  createWallet(datadir: string, opts: BarkCreateOpts): Promise<void>;
325
331
  loadWallet(datadir: string, config: BarkCreateOpts): Promise<void>;
@@ -336,9 +342,7 @@ export interface NitroArk extends HybridObject<{ ios: 'c++'; android: 'c++' }> {
336
342
  refreshServer(): Promise<void>;
337
343
  syncPendingBoards(): Promise<void>;
338
344
  maintenance(): Promise<void>;
339
- maintenanceWithOnchain(): Promise<void>;
340
345
  maintenanceDelegated(): Promise<void>;
341
- maintenanceWithOnchainDelegated(): Promise<void>;
342
346
  maintenanceRefresh(): Promise<void>;
343
347
  sync(): Promise<void>;
344
348
 
@@ -410,6 +414,7 @@ export interface NitroArk extends HybridObject<{ ios: 'c++'; android: 'c++' }> {
410
414
  decodeVtxoHex(vtxoHex: string): Promise<BarkVtxo>;
411
415
  importVtxo(vtxoHex: string): Promise<BarkVtxo>;
412
416
  dangerousDropVtxo(vtxoId: string): Promise<void>;
417
+ unlockVtxos(vtxoIds: string[]): Promise<void>;
413
418
  refreshVtxosDelegated(
414
419
  vtxoIds: string[]
415
420
  ): Promise<DelegatedRoundState | undefined>;
@@ -480,19 +485,17 @@ export interface NitroArk extends HybridObject<{ ios: 'c++'; android: 'c++' }> {
480
485
  // --- Lightning Invoicing ---
481
486
  bolt11Invoice(
482
487
  amountMsat: number,
483
- description?: string
488
+ description?: string,
489
+ token?: string
484
490
  ): Promise<Bolt11Invoice>;
485
- lightningReceiveStatus(
486
- paymentHash: string
487
- ): Promise<LightningReceive | undefined>;
491
+ lightningReceiveStatus(paymentHash: string): Promise<LightningReceive>;
488
492
  checkLightningPayment(
489
493
  paymentHash: string,
490
494
  wait: boolean
491
495
  ): Promise<LightningPaymentResult>;
492
496
  tryClaimLightningReceive(
493
497
  paymentHash: string,
494
- wait: boolean,
495
- token?: string
498
+ wait: boolean
496
499
  ): Promise<LightningReceive>; // Throws on error
497
500
  tryClaimAllLightningReceives(wait: boolean): Promise<void>; // Throws on error
498
501
 
package/src/index.tsx CHANGED
@@ -25,7 +25,7 @@ import type {
25
25
  NewAddressResult,
26
26
  KeyPairResult,
27
27
  MailboxAuthorizationResult,
28
- LightningReceive,
28
+ LightningReceive as NitroLightningReceive,
29
29
  BarkNotificationEvent as NitroBarkNotificationEvent,
30
30
  BarkNotificationSubscription,
31
31
  BarkMovement as NitroBarkMovement,
@@ -61,37 +61,79 @@ export type ExitProgressState =
61
61
  | 'Claimable'
62
62
  | 'ClaimInProgress'
63
63
  | 'Claimed'
64
- | 'VtxoAlreadySpent';
64
+ | 'VtxoAlreadySpent'
65
+ | 'Canceled';
66
+
67
+ export type ExitStateKind =
68
+ | 'start'
69
+ | 'processing'
70
+ | 'awaiting-delta'
71
+ | 'claimable'
72
+ | 'claim-in-progress'
73
+ | 'claimed'
74
+ | 'vtxo-already-spent'
75
+ | 'canceled';
65
76
 
66
77
  export type BlockRef = NitroExitBlockRefResult;
67
78
  export type ExitTxOrigin = NitroExitTxOriginResult;
68
79
  export type ExitTxStatus = NitroExitTxStatusResult;
69
80
  export type ExitTx = NitroExitTxResult;
70
- export type ExitStateDetails = NitroExitStateDetailsResult;
81
+ export type ExitStateDetails = Omit<NitroExitStateDetailsResult, 'kind'> & {
82
+ kind: ExitStateKind;
83
+ };
71
84
 
72
85
  export type ExitProgressStatusResult = Omit<
73
86
  NitroExitProgressStatusResult,
74
- 'state'
87
+ 'state' | 'state_details'
75
88
  > & {
76
89
  state: ExitProgressState;
90
+ state_details: ExitStateDetails;
77
91
  };
78
92
 
79
- export type ExitVtxoResult = Omit<NitroExitVtxoResult, 'state' | 'history'> & {
93
+ export type ExitVtxoResult = Omit<
94
+ NitroExitVtxoResult,
95
+ 'state' | 'state_details' | 'history' | 'history_details'
96
+ > & {
80
97
  state: ExitProgressState;
98
+ state_details: ExitStateDetails;
81
99
  history: ExitProgressState[];
100
+ history_details: ExitStateDetails[];
82
101
  };
83
102
 
84
103
  export type ExitTransactionPackageResult = NitroExitTransactionPackageResult;
85
104
 
86
105
  export type ExitStatusResult = Omit<
87
106
  NitroExitStatusResult,
88
- 'state' | 'history'
107
+ 'state' | 'state_details' | 'history' | 'history_details'
89
108
  > & {
90
109
  state: ExitProgressState;
110
+ state_details: ExitStateDetails;
91
111
  history: ExitProgressState[];
112
+ history_details: ExitStateDetails[];
92
113
  transactions: ExitTransactionPackageResult[];
93
114
  };
94
115
 
116
+ export type LightningReceivePhase =
117
+ | 'awaiting_payment'
118
+ | 'htlcs_ready'
119
+ | 'preimage_revealed';
120
+
121
+ type LightningReceiveBase = Omit<NitroLightningReceive, 'state' | 'phase'>;
122
+
123
+ export type LightningReceive =
124
+ | (LightningReceiveBase & {
125
+ state: 'in_progress';
126
+ phase: LightningReceivePhase;
127
+ amount_sat?: undefined;
128
+ settled_at?: undefined;
129
+ })
130
+ | (LightningReceiveBase & {
131
+ state: 'settled';
132
+ phase?: undefined;
133
+ amount_sat: number;
134
+ settled_at: number;
135
+ });
136
+
95
137
  export type BarkMovementDestination = NitroBarkMovementDestination & {
96
138
  payment_method:
97
139
  | 'ark'
@@ -168,33 +210,76 @@ export const NitroArkHybridObject =
168
210
  function enrichExitProgressStatus(
169
211
  result: NitroExitProgressStatusResult
170
212
  ): ExitProgressStatusResult {
171
- const { state, ...rest } = result;
213
+ const { state, state_details, ...rest } = result;
172
214
  return {
173
215
  ...rest,
174
216
  state: state as ExitProgressState,
217
+ state_details: {
218
+ ...state_details,
219
+ kind: state_details.kind as ExitStateKind,
220
+ },
175
221
  };
176
222
  }
177
223
 
178
224
  function enrichExitVtxo(result: NitroExitVtxoResult): ExitVtxoResult {
179
- const { state, history: stateHistory, ...rest } = result;
225
+ const {
226
+ state,
227
+ state_details,
228
+ history: stateHistory,
229
+ history_details,
230
+ ...rest
231
+ } = result;
180
232
  return {
181
233
  ...rest,
182
234
  state: state as ExitProgressState,
235
+ state_details: {
236
+ ...state_details,
237
+ kind: state_details.kind as ExitStateKind,
238
+ },
183
239
  history: stateHistory as ExitProgressState[],
240
+ history_details: history_details.map((details) => ({
241
+ ...details,
242
+ kind: details.kind as ExitStateKind,
243
+ })),
184
244
  };
185
245
  }
186
246
 
187
247
  function enrichExitStatus(result: NitroExitStatusResult): ExitStatusResult {
188
- const { state, history: stateHistory, ...rest } = result;
248
+ const {
249
+ state,
250
+ state_details,
251
+ history: stateHistory,
252
+ history_details,
253
+ ...rest
254
+ } = result;
189
255
  return {
190
256
  ...rest,
191
257
  state: state as ExitProgressState,
258
+ state_details: {
259
+ ...state_details,
260
+ kind: state_details.kind as ExitStateKind,
261
+ },
192
262
  history: stateHistory as ExitProgressState[],
263
+ history_details: history_details.map((details) => ({
264
+ ...details,
265
+ kind: details.kind as ExitStateKind,
266
+ })),
193
267
  };
194
268
  }
195
269
 
270
+ function enrichLightningReceive(
271
+ result: NitroLightningReceive
272
+ ): LightningReceive {
273
+ return result as LightningReceive;
274
+ }
275
+
196
276
  // --- Management ---
197
277
 
278
+ /** Returns the semver of the Bark wallet library compiled into the native module. */
279
+ export function getBarkVersion(): string {
280
+ return NitroArkHybridObject.getBarkVersion();
281
+ }
282
+
198
283
  /**
199
284
  * Creates a new BIP39 mnemonic phrase.
200
285
  * @returns A promise resolving to the mnemonic string.
@@ -295,42 +380,16 @@ export function syncPendingBoards(): Promise<void> {
295
380
  return NitroArkHybridObject.syncPendingBoards();
296
381
  }
297
382
 
298
- /**
299
- * Runs wallet maintenance tasks for offchain.
300
- * This includes refreshing vtxos that need to be refreshed.
301
- * @returns A promise that resolves on success.
302
- */
383
+ /** Runs wallet maintenance, including on-chain synchronization and exit progression. */
303
384
  export function maintenance(): Promise<void> {
304
385
  return NitroArkHybridObject.maintenance();
305
386
  }
306
387
 
307
- /**
308
- * Runs wallet maintenance tasks for both offchain and onchain.
309
- * This includes refreshing vtxos that need to be refreshed.
310
- * @returns A promise that resolves on success.
311
- */
312
- export function maintenanceWithOnchain(): Promise<void> {
313
- return NitroArkHybridObject.maintenanceWithOnchain();
314
- }
315
-
316
- /**
317
- * Runs delegated wallet maintenance tasks for offchain.
318
- * This includes refreshing vtxos that need to be refreshed using delegated signing.
319
- * @returns A promise that resolves on success.
320
- */
388
+ /** Runs delegated wallet maintenance, including on-chain synchronization. */
321
389
  export function maintenanceDelegated(): Promise<void> {
322
390
  return NitroArkHybridObject.maintenanceDelegated();
323
391
  }
324
392
 
325
- /**
326
- * Runs delegated wallet maintenance tasks for both offchain and onchain.
327
- * This includes refreshing vtxos that need to be refreshed using delegated signing.
328
- * @returns A promise that resolves on success.
329
- */
330
- export function maintenanceWithOnchainDelegated(): Promise<void> {
331
- return NitroArkHybridObject.maintenanceWithOnchainDelegated();
332
- }
333
-
334
393
  /**
335
394
  * Refreshes vtxos that need to be refreshed.
336
395
  * @returns A promise that resolves on success.
@@ -737,6 +796,15 @@ export function dangerousDropVtxo(vtxoId: string): Promise<void> {
737
796
  return NitroArkHybridObject.dangerousDropVtxo(vtxoId);
738
797
  }
739
798
 
799
+ /**
800
+ * Unlocks locked VTXOs and returns them to the spendable state.
801
+ * Already-spendable VTXOs are left unchanged. Spent, unknown, or malformed IDs reject the batch.
802
+ * @param vtxoIds VTXO IDs to unlock.
803
+ */
804
+ export function unlockVtxos(vtxoIds: string[]): Promise<void> {
805
+ return NitroArkHybridObject.unlockVtxos(vtxoIds);
806
+ }
807
+
740
808
  /**
741
809
  * Gets the first expiring VTXO blockheight for the loaded wallet.
742
810
  * @returns A promise resolving to the first expiring VTXO blockheight.
@@ -872,9 +940,10 @@ export function onchainSendMany(
872
940
  */
873
941
  export function bolt11Invoice(
874
942
  amountMsat: number,
875
- description?: string
943
+ description?: string,
944
+ token?: string
876
945
  ): Promise<Bolt11Invoice> {
877
- return NitroArkHybridObject.bolt11Invoice(amountMsat, description);
946
+ return NitroArkHybridObject.bolt11Invoice(amountMsat, description, token);
878
947
  }
879
948
 
880
949
  /**
@@ -884,8 +953,10 @@ export function bolt11Invoice(
884
953
  */
885
954
  export function lightningReceiveStatus(
886
955
  paymentHash: string
887
- ): Promise<LightningReceive | undefined> {
888
- return NitroArkHybridObject.lightningReceiveStatus(paymentHash);
956
+ ): Promise<LightningReceive> {
957
+ return NitroArkHybridObject.lightningReceiveStatus(paymentHash).then(
958
+ enrichLightningReceive
959
+ );
889
960
  }
890
961
 
891
962
  /**
@@ -907,21 +978,17 @@ export function checkLightningPayment(
907
978
  }
908
979
 
909
980
  /**
910
- * Attempts to claim a Lightning payment, optionally using a claim token.
981
+ * Attempts to claim a Lightning payment.
911
982
  * @param paymentHash The payment hash of the Lightning payment.
912
983
  * @param wait Whether to wait for the claim to complete.
913
- * @param token Optional claim token used when no spendable VTXOs are owned.
914
- * @returns A promise resolving to the claimed LightningReceive if successful, or null if not.
984
+ * @returns A promise resolving to the current Lightning receive state.
915
985
  */
916
986
  export function tryClaimLightningReceive(
917
987
  paymentHash: string,
918
- wait: boolean,
919
- token?: string
988
+ wait: boolean
920
989
  ): Promise<LightningReceive> {
921
- return NitroArkHybridObject.tryClaimLightningReceive(
922
- paymentHash,
923
- wait,
924
- token
990
+ return NitroArkHybridObject.tryClaimLightningReceive(paymentHash, wait).then(
991
+ enrichLightningReceive
925
992
  );
926
993
  }
927
994
 
@@ -1168,5 +1235,4 @@ export type {
1168
1235
  OnchainBalanceResult,
1169
1236
  NewAddressResult,
1170
1237
  KeyPairResult,
1171
- LightningReceive,
1172
1238
  } from './NitroArk.nitro';