react-native-nitro-ark 0.0.15 → 0.0.17

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,194 +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);
133
+ }
134
+
135
+ // --- Lightning Operations ---
136
+
137
+ /**
138
+ * Creates a Bolt 11 invoice.
139
+ * @param amountMsat The amount in millisatoshis for the invoice.
140
+ * @returns A promise resolving to the Bolt 11 invoice string.
141
+ */
142
+ export function bolt11Invoice(amountMsat: number): Promise<string> {
143
+ return NitroArkHybridObject.bolt11Invoice(amountMsat);
144
+ }
145
+
146
+ /**
147
+ * Claims a Bolt 11 payment.
148
+ * @param bolt11 The Bolt 11 invoice string to claim.
149
+ * @returns A promise that resolves on success or rejects on error.
150
+ */
151
+ export function claimBolt11Payment(bolt11: string): Promise<void> {
152
+ return NitroArkHybridObject.claimBolt11Payment(bolt11);
180
153
  }
181
154
 
182
155
  // --- Ark Operations ---
183
156
 
184
157
  /**
185
- * Refreshes VTXOs based on specified criteria.
186
- * @param datadir Path to the data directory.
187
- * @param mnemonic The wallet mnemonic phrase.
158
+ * Refreshes VTXOs based on specified criteria for the loaded wallet.
188
159
  * @param refreshOpts Options specifying which VTXOs to refresh.
189
- * `mode_type` should be one of: 'DefaultThreshold', 'ThresholdBlocks', 'ThresholdHours', 'Counterparty', 'All', 'Specific'.
190
- * @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.
191
161
  * @returns A promise resolving to a JSON status string.
192
- * @example
193
- * // Refresh using default threshold
194
- * refreshVtxos(datadir, mnemonic, { mode_type: 'DefaultThreshold' });
195
- * // Refresh specific VTXOs
196
- * refreshVtxos(datadir, mnemonic, { mode_type: 'Specific', specific_vtxo_ids: ['vtxo_id_1', 'vtxo_id_2'] });
197
- * // Refresh if older than 10 blocks
198
- * refreshVtxos(datadir, mnemonic, { mode_type: 'ThresholdBlocks', threshold_value: 10 });
199
162
  */
200
163
  export function refreshVtxos(
201
- datadir: string,
202
- mnemonic: string,
203
164
  refreshOpts: BarkRefreshOpts,
204
165
  no_sync: boolean = false
205
166
  ): Promise<string> {
206
- // Ensure mode_type is provided (should be handled by TS type system)
207
167
  if (!refreshOpts.mode_type) {
208
168
  return Promise.reject(
209
169
  new Error('refreshVtxos requires refreshOpts.mode_type')
210
170
  );
211
171
  }
212
- // Additional validation for specific modes could be added here if desired
213
172
  if (
214
173
  refreshOpts.mode_type === 'Specific' &&
215
174
  (!refreshOpts.specific_vtxo_ids ||
@@ -233,125 +192,78 @@ export function refreshVtxos(
233
192
  )
234
193
  );
235
194
  }
236
- return NitroArkHybridObject.refreshVtxos(
237
- datadir,
238
- mnemonic,
239
- refreshOpts,
240
- no_sync
241
- );
195
+ return NitroArkHybridObject.refreshVtxos(refreshOpts, no_sync);
242
196
  }
243
197
 
244
198
  /**
245
199
  * Boards a specific amount from the onchain wallet into Ark.
246
- * @param datadir Path to the data directory.
247
- * @param mnemonic The wallet mnemonic phrase.
248
200
  * @param amountSat The amount in satoshis to board.
249
- * @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.
250
202
  * @returns A promise resolving to a JSON status string.
251
203
  */
252
204
  export function boardAmount(
253
- datadir: string,
254
- mnemonic: string,
255
205
  amountSat: number,
256
206
  no_sync: boolean = false
257
207
  ): Promise<string> {
258
- return NitroArkHybridObject.boardAmount(
259
- datadir,
260
- mnemonic,
261
- amountSat,
262
- no_sync
263
- );
208
+ return NitroArkHybridObject.boardAmount(amountSat, no_sync);
264
209
  }
265
210
 
266
211
  /**
267
212
  * Boards all available funds from the onchain wallet into Ark.
268
- * @param datadir Path to the data directory.
269
- * @param mnemonic The wallet mnemonic phrase.
270
- * @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.
271
214
  * @returns A promise resolving to a JSON status string.
272
215
  */
273
- export function boardAll(
274
- datadir: string,
275
- mnemonic: string,
276
- no_sync: boolean = false
277
- ): Promise<string> {
278
- return NitroArkHybridObject.boardAll(datadir, mnemonic, no_sync);
216
+ export function boardAll(no_sync: boolean = false): Promise<string> {
217
+ return NitroArkHybridObject.boardAll(no_sync);
279
218
  }
280
219
 
281
220
  /**
282
221
  * Sends funds offchain using Ark VTXOs.
283
- * @param datadir Path to the data directory.
284
- * @param mnemonic The wallet mnemonic phrase.
285
222
  * @param destination Ark address (VTXO pubkey) or onchain Bitcoin address.
286
223
  * @param amountSat The amount in satoshis to send.
287
- * @param comment Optional comment (can be null).
288
- * @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.
289
226
  * @returns A promise resolving to a JSON status string.
290
227
  */
291
228
  export function send(
292
- datadir: string,
293
- mnemonic: string,
294
229
  destination: string,
295
230
  amountSat: number,
296
231
  comment: string | null = null,
297
232
  no_sync: boolean = false
298
233
  ): Promise<string> {
299
- return NitroArkHybridObject.send(
300
- datadir,
301
- mnemonic,
302
- destination,
303
- amountSat,
304
- comment,
305
- no_sync
306
- );
234
+ return NitroArkHybridObject.send(destination, amountSat, comment, no_sync);
307
235
  }
308
236
 
309
237
  /**
310
238
  * Sends an onchain payment via an Ark round.
311
- * @param datadir Path to the data directory.
312
- * @param mnemonic The wallet mnemonic phrase.
313
239
  * @param destination The destination Bitcoin address.
314
240
  * @param amountSat The amount in satoshis to send.
315
- * @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.
316
242
  * @returns A promise resolving to a JSON status string.
317
243
  */
318
244
  export function sendRoundOnchain(
319
- datadir: string,
320
- mnemonic: string,
321
245
  destination: string,
322
246
  amountSat: number,
323
247
  no_sync: boolean = false
324
248
  ): Promise<string> {
325
- return NitroArkHybridObject.sendRoundOnchain(
326
- datadir,
327
- mnemonic,
328
- destination,
329
- amountSat,
330
- no_sync
331
- );
249
+ return NitroArkHybridObject.sendRoundOnchain(destination, amountSat, no_sync);
332
250
  }
333
251
 
334
252
  // --- Offboarding / Exiting ---
335
253
 
336
254
  /**
337
255
  * Offboards specific VTXOs to an optional onchain address.
338
- * @param datadir Path to the data directory.
339
- * @param mnemonic The wallet mnemonic phrase.
340
256
  * @param vtxoIds Array of VtxoId strings to offboard.
341
257
  * @param optionalAddress Optional destination Bitcoin address (null if sending to internal wallet).
342
- * @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.
343
259
  * @returns A promise resolving to a JSON result string.
344
260
  */
345
261
  export function offboardSpecific(
346
- datadir: string,
347
- mnemonic: string,
348
262
  vtxoIds: string[],
349
263
  optionalAddress: string | null = null,
350
264
  no_sync: boolean = false
351
265
  ): Promise<string> {
352
266
  return NitroArkHybridObject.offboardSpecific(
353
- datadir,
354
- mnemonic,
355
267
  vtxoIds,
356
268
  optionalAddress,
357
269
  no_sync
@@ -360,76 +272,40 @@ export function offboardSpecific(
360
272
 
361
273
  /**
362
274
  * Offboards all VTXOs to an optional onchain address.
363
- * @param datadir Path to the data directory.
364
- * @param mnemonic The wallet mnemonic phrase.
365
275
  * @param optionalAddress Optional destination Bitcoin address (null if sending to internal wallet).
366
- * @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.
367
277
  * @returns A promise resolving to a JSON result string.
368
278
  */
369
279
  export function offboardAll(
370
- datadir: string,
371
- mnemonic: string,
372
280
  optionalAddress: string | null = null,
373
281
  no_sync: boolean = false
374
282
  ): Promise<string> {
375
- return NitroArkHybridObject.offboardAll(
376
- datadir,
377
- mnemonic,
378
- optionalAddress,
379
- no_sync
380
- );
283
+ return NitroArkHybridObject.offboardAll(optionalAddress, no_sync);
381
284
  }
382
285
 
383
286
  /**
384
287
  * Starts the exit process for specific VTXOs.
385
- * @param datadir Path to the data directory.
386
- * @param mnemonic The wallet mnemonic phrase.
387
288
  * @param vtxoIds Array of VtxoId strings to start exiting.
388
- * @param no_sync Whether to skip syncing the wallet (Note: This might depend on potential C header updates). Defaults to false.
389
289
  * @returns A promise resolving to a JSON status string.
390
290
  */
391
- export function exitStartSpecific(
392
- datadir: string,
393
- mnemonic: string,
394
- vtxoIds: string[],
395
- no_sync: boolean = false
396
- ): Promise<string> {
397
- // Passing no_sync, aligning with the TS/C++ interface definition, even if C header might differ
398
- return NitroArkHybridObject.exitStartSpecific(
399
- datadir,
400
- mnemonic,
401
- vtxoIds,
402
- no_sync
403
- );
291
+ export function exitStartSpecific(vtxoIds: string[]): Promise<string> {
292
+ return NitroArkHybridObject.exitStartSpecific(vtxoIds);
404
293
  }
405
294
 
406
295
  /**
407
296
  * Starts the exit process for all VTXOs in the wallet.
408
- * @param datadir Path to the data directory.
409
- * @param mnemonic The wallet mnemonic phrase.
410
- * @param no_sync Whether to skip syncing the wallet (Note: This might depend on potential C header updates). Defaults to false.
411
297
  * @returns A promise resolving to a JSON status string.
412
298
  */
413
- export function exitStartAll(
414
- datadir: string,
415
- mnemonic: string,
416
- no_sync: boolean = false
417
- ): Promise<string> {
418
- // Passing no_sync, aligning with the TS/C++ interface definition, even if C header might differ
419
- return NitroArkHybridObject.exitStartAll(datadir, mnemonic, no_sync);
299
+ export function exitStartAll(): Promise<string> {
300
+ return NitroArkHybridObject.exitStartAll();
420
301
  }
421
302
 
422
303
  /**
423
304
  * Progresses the exit process once and returns the current status.
424
- * @param datadir Path to the data directory.
425
- * @param mnemonic The wallet mnemonic phrase.
426
305
  * @returns A promise resolving to a JSON status string.
427
306
  */
428
- export function exitProgressOnce(
429
- datadir: string,
430
- mnemonic: string
431
- ): Promise<string> {
432
- return NitroArkHybridObject.exitProgressOnce(datadir, mnemonic);
307
+ export function exitProgressOnce(): Promise<string> {
308
+ return NitroArkHybridObject.exitProgressOnce();
433
309
  }
434
310
 
435
311
  // --- Re-export types and enums ---