react-native-nitro-ark 0.0.16 → 0.0.19

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/src/index.tsx CHANGED
@@ -22,226 +22,153 @@ export function createMnemonic(): Promise<string> {
22
22
  }
23
23
 
24
24
  /**
25
- * Creates a new wallet at the specified directory.
25
+ * Loads an existing wallet or creates a new one at the specified directory.
26
+ * Once loaded, the wallet state is managed internally.
26
27
  * @param datadir Path to the data directory.
27
- * @param opts Creation options.
28
+ * @param opts Creation and configuration options.
28
29
  * @returns A promise that resolves on success or rejects on error.
29
30
  */
30
- export function createWallet(
31
+ export function loadWallet(
31
32
  datadir: string,
32
33
  opts: BarkCreateOpts
33
34
  ): Promise<void> {
34
- return NitroArkHybridObject.createWallet(datadir, opts);
35
+ return NitroArkHybridObject.loadWallet(datadir, opts);
36
+ }
37
+
38
+ /**
39
+ * Closes the currently loaded wallet, clearing its state from memory.
40
+ * @returns A promise that resolves on success or rejects on error.
41
+ */
42
+ export function closeWallet(): Promise<void> {
43
+ return NitroArkHybridObject.closeWallet();
35
44
  }
36
45
 
37
46
  // --- Wallet Info ---
38
47
 
39
48
  /**
40
- * Gets the offchain and onchain balances.
41
- * @param datadir Path to the data directory.
42
- * @param no_sync Whether to skip syncing the wallet. Defaults to false.
43
- * @param mnemonic The wallet mnemonic phrase.
49
+ * Gets the onchain and offchain balances for the loaded wallet.
50
+ * @param no_sync If true, skips synchronization with the blockchain. Defaults to false.
44
51
  * @returns A promise resolving to the BarkBalance object.
45
52
  */
46
- export function getBalance(
47
- datadir: string,
48
- mnemonic: string,
49
- no_sync: boolean = false
50
- ): Promise<BarkBalance> {
51
- // Pass mnemonic correctly, adjusted default position for optional no_sync
52
- return NitroArkHybridObject.getBalance(datadir, no_sync, mnemonic);
53
+ export function getBalance(no_sync: boolean = false): Promise<BarkBalance> {
54
+ return NitroArkHybridObject.getBalance(no_sync);
53
55
  }
54
56
 
55
57
  /**
56
- * Gets a fresh onchain address.
57
- * @param datadir Path to the data directory.
58
- * @param mnemonic The wallet mnemonic phrase.
58
+ * Gets a fresh onchain address for the loaded wallet.
59
59
  * @returns A promise resolving to the Bitcoin address string.
60
60
  */
61
- export function getOnchainAddress(
62
- datadir: string,
63
- mnemonic: string
64
- ): Promise<string> {
65
- return NitroArkHybridObject.getOnchainAddress(datadir, mnemonic);
61
+ export function getOnchainAddress(): Promise<string> {
62
+ return NitroArkHybridObject.getOnchainAddress();
66
63
  }
67
64
 
68
65
  /**
69
- * Gets the list of onchain UTXOs as a JSON string.
70
- * @param datadir Path to the data directory.
71
- * @param mnemonic The wallet mnemonic phrase.
72
- * @param no_sync Whether to skip syncing the wallet. Defaults to false.
66
+ * Gets the list of onchain UTXOs as a JSON string for the loaded wallet.
67
+ * @param no_sync If true, skips synchronization with the blockchain. Defaults to false.
73
68
  * @returns A promise resolving to the JSON string of UTXOs.
74
69
  */
75
- export function getOnchainUtxos(
76
- datadir: string,
77
- mnemonic: string,
78
- no_sync: boolean = false
79
- ): Promise<string> {
80
- return NitroArkHybridObject.getOnchainUtxos(datadir, mnemonic, no_sync);
70
+ export function getOnchainUtxos(no_sync: boolean = false): Promise<string> {
71
+ return NitroArkHybridObject.getOnchainUtxos(no_sync);
81
72
  }
82
73
 
83
74
  /**
84
75
  * Gets the wallet's VTXO public key (hex string).
85
- * @param datadir Path to the data directory.
86
- * @param mnemonic The wallet mnemonic phrase.
76
+ * @param index Optional index of the VTXO pubkey to retrieve.
87
77
  * @returns A promise resolving to the hex-encoded public key string.
88
78
  */
89
- export function getVtxoPubkey(
90
- datadir: string,
91
- mnemonic: string
92
- ): Promise<string> {
93
- return NitroArkHybridObject.getVtxoPubkey(datadir, mnemonic);
79
+ export function getVtxoPubkey(index?: number): Promise<string> {
80
+ return NitroArkHybridObject.getVtxoPubkey(index);
94
81
  }
95
82
 
96
83
  /**
97
- * Gets the list of VTXOs as a JSON string.
98
- * @param datadir Path to the data directory.
99
- * @param mnemonic The wallet mnemonic phrase.
100
- * @param no_sync Whether to skip syncing the wallet. Defaults to false.
84
+ * Gets the list of VTXOs as a JSON string for the loaded wallet.
85
+ * @param no_sync If true, skips synchronization with the blockchain. Defaults to false.
101
86
  * @returns A promise resolving to the JSON string of VTXOs.
102
87
  */
103
- export function getVtxos(
104
- datadir: string,
105
- mnemonic: string,
106
- no_sync: boolean = false
107
- ): Promise<string> {
108
- return NitroArkHybridObject.getVtxos(datadir, mnemonic, no_sync);
88
+ export function getVtxos(no_sync: boolean = false): Promise<string> {
89
+ return NitroArkHybridObject.getVtxos(no_sync);
109
90
  }
110
91
 
111
92
  // --- Onchain Operations ---
112
93
 
113
94
  /**
114
95
  * Sends funds using the onchain wallet.
115
- * @param datadir Path to the data directory.
116
- * @param mnemonic The wallet mnemonic phrase.
117
96
  * @param destination The destination Bitcoin address.
118
97
  * @param amountSat The amount to send in satoshis.
119
- * @param no_sync Whether to skip syncing the wallet. Defaults to false.
98
+ * @param no_sync If true, skips synchronization with the blockchain. Defaults to false.
120
99
  * @returns A promise resolving to the transaction ID string.
121
100
  */
122
101
  export function sendOnchain(
123
- datadir: string,
124
- mnemonic: string,
125
102
  destination: string,
126
103
  amountSat: number,
127
104
  no_sync: boolean = false
128
105
  ): Promise<string> {
129
- return NitroArkHybridObject.sendOnchain(
130
- datadir,
131
- mnemonic,
132
- destination,
133
- amountSat,
134
- no_sync
135
- );
106
+ return NitroArkHybridObject.sendOnchain(destination, amountSat, no_sync);
136
107
  }
137
108
 
138
109
  /**
139
110
  * Sends all funds from the onchain wallet to a destination address.
140
- * @param datadir Path to the data directory.
141
- * @param mnemonic The wallet mnemonic phrase.
142
111
  * @param destination The destination Bitcoin address.
143
- * @param no_sync Whether to skip syncing the wallet. Defaults to false.
112
+ * @param no_sync If true, skips synchronization with the blockchain. Defaults to false.
144
113
  * @returns A promise resolving to the transaction ID string.
145
114
  */
146
115
  export function drainOnchain(
147
- datadir: string,
148
- mnemonic: string,
149
116
  destination: string,
150
117
  no_sync: boolean = false
151
118
  ): Promise<string> {
152
- return NitroArkHybridObject.drainOnchain(
153
- datadir,
154
- mnemonic,
155
- destination,
156
- no_sync
157
- );
119
+ return NitroArkHybridObject.drainOnchain(destination, no_sync);
158
120
  }
159
121
 
160
122
  /**
161
123
  * Sends funds to multiple recipients using the onchain wallet.
162
- * @param datadir Path to the data directory.
163
- * @param mnemonic The wallet mnemonic phrase.
164
124
  * @param outputs An array of objects containing destination address and amountSat.
165
- * @param no_sync Whether to skip syncing the wallet. Defaults to false.
125
+ * @param no_sync If true, skips synchronization with the blockchain. Defaults to false.
166
126
  * @returns A promise resolving to the transaction ID string.
167
127
  */
168
128
  export function sendManyOnchain(
169
- datadir: string,
170
- mnemonic: string,
171
129
  outputs: BarkSendManyOutput[],
172
130
  no_sync: boolean = false
173
131
  ): Promise<string> {
174
- return NitroArkHybridObject.sendManyOnchain(
175
- datadir,
176
- mnemonic,
177
- outputs,
178
- no_sync
179
- );
132
+ return NitroArkHybridObject.sendManyOnchain(outputs, no_sync);
180
133
  }
181
134
 
182
135
  // --- Lightning Operations ---
183
136
 
184
137
  /**
185
138
  * Creates a Bolt 11 invoice.
186
- * @param datadir Path to the data directory.
187
- * @param mnemonic The wallet mnemonic phrase.
188
- * @param amountSat The amount in satoshis for the invoice.
139
+ * @param amountMsat The amount in millisatoshis for the invoice.
189
140
  * @returns A promise resolving to the Bolt 11 invoice string.
190
141
  */
191
- export function bolt11Invoice(
192
- datadir: string,
193
- mnemonic: string,
194
- amountSat: number
195
- ): Promise<string> {
196
- return NitroArkHybridObject.bolt11Invoice(datadir, mnemonic, amountSat);
142
+ export function bolt11Invoice(amountMsat: number): Promise<string> {
143
+ return NitroArkHybridObject.bolt11Invoice(amountMsat);
197
144
  }
198
145
 
199
146
  /**
200
147
  * Claims a Bolt 11 payment.
201
- * @param datadir Path to the data directory.
202
- * @param mnemonic The wallet mnemonic phrase.
203
148
  * @param bolt11 The Bolt 11 invoice string to claim.
204
149
  * @returns A promise that resolves on success or rejects on error.
205
150
  */
206
- export function claimBolt11Payment(
207
- datadir: string,
208
- mnemonic: string,
209
- bolt11: string
210
- ): Promise<void> {
211
- return NitroArkHybridObject.claimBolt11Payment(datadir, mnemonic, bolt11);
151
+ export function claimBolt11Payment(bolt11: string): Promise<void> {
152
+ return NitroArkHybridObject.claimBolt11Payment(bolt11);
212
153
  }
213
154
 
214
155
  // --- Ark Operations ---
215
156
 
216
157
  /**
217
- * Refreshes VTXOs based on specified criteria.
218
- * @param datadir Path to the data directory.
219
- * @param mnemonic The wallet mnemonic phrase.
158
+ * Refreshes VTXOs based on specified criteria for the loaded wallet.
220
159
  * @param refreshOpts Options specifying which VTXOs to refresh.
221
- * `mode_type` should be one of: 'DefaultThreshold', 'ThresholdBlocks', 'ThresholdHours', 'Counterparty', 'All', 'Specific'.
222
- * @param no_sync Whether to skip syncing the wallet. Defaults to false.
160
+ * @param no_sync If true, skips synchronization with the blockchain. Defaults to false.
223
161
  * @returns A promise resolving to a JSON status string.
224
- * @example
225
- * // Refresh using default threshold
226
- * refreshVtxos(datadir, mnemonic, { mode_type: 'DefaultThreshold' });
227
- * // Refresh specific VTXOs
228
- * refreshVtxos(datadir, mnemonic, { mode_type: 'Specific', specific_vtxo_ids: ['vtxo_id_1', 'vtxo_id_2'] });
229
- * // Refresh if older than 10 blocks
230
- * refreshVtxos(datadir, mnemonic, { mode_type: 'ThresholdBlocks', threshold_value: 10 });
231
162
  */
232
163
  export function refreshVtxos(
233
- datadir: string,
234
- mnemonic: string,
235
164
  refreshOpts: BarkRefreshOpts,
236
165
  no_sync: boolean = false
237
166
  ): Promise<string> {
238
- // Ensure mode_type is provided (should be handled by TS type system)
239
167
  if (!refreshOpts.mode_type) {
240
168
  return Promise.reject(
241
169
  new Error('refreshVtxos requires refreshOpts.mode_type')
242
170
  );
243
171
  }
244
- // Additional validation for specific modes could be added here if desired
245
172
  if (
246
173
  refreshOpts.mode_type === 'Specific' &&
247
174
  (!refreshOpts.specific_vtxo_ids ||
@@ -265,125 +192,78 @@ export function refreshVtxos(
265
192
  )
266
193
  );
267
194
  }
268
- return NitroArkHybridObject.refreshVtxos(
269
- datadir,
270
- mnemonic,
271
- refreshOpts,
272
- no_sync
273
- );
195
+ return NitroArkHybridObject.refreshVtxos(refreshOpts, no_sync);
274
196
  }
275
197
 
276
198
  /**
277
199
  * Boards a specific amount from the onchain wallet into Ark.
278
- * @param datadir Path to the data directory.
279
- * @param mnemonic The wallet mnemonic phrase.
280
200
  * @param amountSat The amount in satoshis to board.
281
- * @param no_sync Whether to skip syncing the onchain wallet. Defaults to false.
201
+ * @param no_sync If true, skips synchronization with the onchain wallet. Defaults to false.
282
202
  * @returns A promise resolving to a JSON status string.
283
203
  */
284
204
  export function boardAmount(
285
- datadir: string,
286
- mnemonic: string,
287
205
  amountSat: number,
288
206
  no_sync: boolean = false
289
207
  ): Promise<string> {
290
- return NitroArkHybridObject.boardAmount(
291
- datadir,
292
- mnemonic,
293
- amountSat,
294
- no_sync
295
- );
208
+ return NitroArkHybridObject.boardAmount(amountSat, no_sync);
296
209
  }
297
210
 
298
211
  /**
299
212
  * Boards all available funds from the onchain wallet into Ark.
300
- * @param datadir Path to the data directory.
301
- * @param mnemonic The wallet mnemonic phrase.
302
- * @param no_sync Whether to skip syncing the onchain wallet. Defaults to false.
213
+ * @param no_sync If true, skips synchronization with the onchain wallet. Defaults to false.
303
214
  * @returns A promise resolving to a JSON status string.
304
215
  */
305
- export function boardAll(
306
- datadir: string,
307
- mnemonic: string,
308
- no_sync: boolean = false
309
- ): Promise<string> {
310
- return NitroArkHybridObject.boardAll(datadir, mnemonic, no_sync);
216
+ export function boardAll(no_sync: boolean = false): Promise<string> {
217
+ return NitroArkHybridObject.boardAll(no_sync);
311
218
  }
312
219
 
313
220
  /**
314
221
  * Sends funds offchain using Ark VTXOs.
315
- * @param datadir Path to the data directory.
316
- * @param mnemonic The wallet mnemonic phrase.
317
222
  * @param destination Ark address (VTXO pubkey) or onchain Bitcoin address.
318
223
  * @param amountSat The amount in satoshis to send.
319
- * @param comment Optional comment (can be null).
320
- * @param no_sync Whether to skip syncing the wallet. Defaults to false.
224
+ * @param comment Optional comment.
225
+ * @param no_sync If true, skips synchronization with the wallet. Defaults to false.
321
226
  * @returns A promise resolving to a JSON status string.
322
227
  */
323
228
  export function send(
324
- datadir: string,
325
- mnemonic: string,
326
229
  destination: string,
327
230
  amountSat: number,
328
231
  comment: string | null = null,
329
232
  no_sync: boolean = false
330
233
  ): Promise<string> {
331
- return NitroArkHybridObject.send(
332
- datadir,
333
- mnemonic,
334
- destination,
335
- amountSat,
336
- comment,
337
- no_sync
338
- );
234
+ return NitroArkHybridObject.send(destination, amountSat, comment, no_sync);
339
235
  }
340
236
 
341
237
  /**
342
238
  * Sends an onchain payment via an Ark round.
343
- * @param datadir Path to the data directory.
344
- * @param mnemonic The wallet mnemonic phrase.
345
239
  * @param destination The destination Bitcoin address.
346
240
  * @param amountSat The amount in satoshis to send.
347
- * @param no_sync Whether to skip syncing the wallet. Defaults to false.
241
+ * @param no_sync If true, skips synchronization with the wallet. Defaults to false.
348
242
  * @returns A promise resolving to a JSON status string.
349
243
  */
350
244
  export function sendRoundOnchain(
351
- datadir: string,
352
- mnemonic: string,
353
245
  destination: string,
354
246
  amountSat: number,
355
247
  no_sync: boolean = false
356
248
  ): Promise<string> {
357
- return NitroArkHybridObject.sendRoundOnchain(
358
- datadir,
359
- mnemonic,
360
- destination,
361
- amountSat,
362
- no_sync
363
- );
249
+ return NitroArkHybridObject.sendRoundOnchain(destination, amountSat, no_sync);
364
250
  }
365
251
 
366
252
  // --- Offboarding / Exiting ---
367
253
 
368
254
  /**
369
255
  * Offboards specific VTXOs to an optional onchain address.
370
- * @param datadir Path to the data directory.
371
- * @param mnemonic The wallet mnemonic phrase.
372
256
  * @param vtxoIds Array of VtxoId strings to offboard.
373
257
  * @param optionalAddress Optional destination Bitcoin address (null if sending to internal wallet).
374
- * @param no_sync Whether to skip syncing the wallet. Defaults to false.
258
+ * @param no_sync If true, skips synchronization with the wallet. Defaults to false.
375
259
  * @returns A promise resolving to a JSON result string.
376
260
  */
377
261
  export function offboardSpecific(
378
- datadir: string,
379
- mnemonic: string,
380
262
  vtxoIds: string[],
381
263
  optionalAddress: string | null = null,
382
264
  no_sync: boolean = false
383
265
  ): Promise<string> {
384
266
  return NitroArkHybridObject.offboardSpecific(
385
- datadir,
386
- mnemonic,
387
267
  vtxoIds,
388
268
  optionalAddress,
389
269
  no_sync
@@ -392,76 +272,40 @@ export function offboardSpecific(
392
272
 
393
273
  /**
394
274
  * Offboards all VTXOs to an optional onchain address.
395
- * @param datadir Path to the data directory.
396
- * @param mnemonic The wallet mnemonic phrase.
397
275
  * @param optionalAddress Optional destination Bitcoin address (null if sending to internal wallet).
398
- * @param no_sync Whether to skip syncing the wallet. Defaults to false.
276
+ * @param no_sync If true, skips synchronization with the wallet. Defaults to false.
399
277
  * @returns A promise resolving to a JSON result string.
400
278
  */
401
279
  export function offboardAll(
402
- datadir: string,
403
- mnemonic: string,
404
280
  optionalAddress: string | null = null,
405
281
  no_sync: boolean = false
406
282
  ): Promise<string> {
407
- return NitroArkHybridObject.offboardAll(
408
- datadir,
409
- mnemonic,
410
- optionalAddress,
411
- no_sync
412
- );
283
+ return NitroArkHybridObject.offboardAll(optionalAddress, no_sync);
413
284
  }
414
285
 
415
286
  /**
416
287
  * Starts the exit process for specific VTXOs.
417
- * @param datadir Path to the data directory.
418
- * @param mnemonic The wallet mnemonic phrase.
419
288
  * @param vtxoIds Array of VtxoId strings to start exiting.
420
- * @param no_sync Whether to skip syncing the wallet (Note: This might depend on potential C header updates). Defaults to false.
421
289
  * @returns A promise resolving to a JSON status string.
422
290
  */
423
- export function exitStartSpecific(
424
- datadir: string,
425
- mnemonic: string,
426
- vtxoIds: string[],
427
- no_sync: boolean = false
428
- ): Promise<string> {
429
- // Passing no_sync, aligning with the TS/C++ interface definition, even if C header might differ
430
- return NitroArkHybridObject.exitStartSpecific(
431
- datadir,
432
- mnemonic,
433
- vtxoIds,
434
- no_sync
435
- );
291
+ export function exitStartSpecific(vtxoIds: string[]): Promise<string> {
292
+ return NitroArkHybridObject.exitStartSpecific(vtxoIds);
436
293
  }
437
294
 
438
295
  /**
439
296
  * Starts the exit process for all VTXOs in the wallet.
440
- * @param datadir Path to the data directory.
441
- * @param mnemonic The wallet mnemonic phrase.
442
- * @param no_sync Whether to skip syncing the wallet (Note: This might depend on potential C header updates). Defaults to false.
443
297
  * @returns A promise resolving to a JSON status string.
444
298
  */
445
- export function exitStartAll(
446
- datadir: string,
447
- mnemonic: string,
448
- no_sync: boolean = false
449
- ): Promise<string> {
450
- // Passing no_sync, aligning with the TS/C++ interface definition, even if C header might differ
451
- return NitroArkHybridObject.exitStartAll(datadir, mnemonic, no_sync);
299
+ export function exitStartAll(): Promise<string> {
300
+ return NitroArkHybridObject.exitStartAll();
452
301
  }
453
302
 
454
303
  /**
455
304
  * Progresses the exit process once and returns the current status.
456
- * @param datadir Path to the data directory.
457
- * @param mnemonic The wallet mnemonic phrase.
458
305
  * @returns A promise resolving to a JSON status string.
459
306
  */
460
- export function exitProgressOnce(
461
- datadir: string,
462
- mnemonic: string
463
- ): Promise<string> {
464
- return NitroArkHybridObject.exitProgressOnce(datadir, mnemonic);
307
+ export function exitProgressOnce(): Promise<string> {
308
+ return NitroArkHybridObject.exitProgressOnce();
465
309
  }
466
310
 
467
311
  // --- Re-export types and enums ---