react-native-nitro-ark 0.0.2

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.
Files changed (55) hide show
  1. package/LICENSE +20 -0
  2. package/NitroArk.podspec +30 -0
  3. package/README.md +22 -0
  4. package/android/CMakeLists.txt +64 -0
  5. package/android/build.gradle +145 -0
  6. package/android/gradle.properties +5 -0
  7. package/android/src/main/AndroidManifest.xml +3 -0
  8. package/android/src/main/AndroidManifestNew.xml +2 -0
  9. package/android/src/main/cpp/cpp-adapter.cpp +6 -0
  10. package/android/src/main/java/com/nitroark/NitroArkPackage.kt +22 -0
  11. package/cpp/HybridArk.cpp +8 -0
  12. package/cpp/NitroArk.hpp +558 -0
  13. package/cpp/bark-cpp.h +382 -0
  14. package/lib/commonjs/NitroArk.nitro.js +6 -0
  15. package/lib/commonjs/NitroArk.nitro.js.map +1 -0
  16. package/lib/commonjs/index.js +292 -0
  17. package/lib/commonjs/index.js.map +1 -0
  18. package/lib/commonjs/package.json +1 -0
  19. package/lib/module/NitroArk.nitro.js +4 -0
  20. package/lib/module/NitroArk.nitro.js.map +1 -0
  21. package/lib/module/index.js +268 -0
  22. package/lib/module/index.js.map +1 -0
  23. package/lib/module/package.json +1 -0
  24. package/lib/typescript/commonjs/package.json +1 -0
  25. package/lib/typescript/commonjs/src/NitroArk.nitro.d.ts +59 -0
  26. package/lib/typescript/commonjs/src/NitroArk.nitro.d.ts.map +1 -0
  27. package/lib/typescript/commonjs/src/index.d.ts +180 -0
  28. package/lib/typescript/commonjs/src/index.d.ts.map +1 -0
  29. package/lib/typescript/module/package.json +1 -0
  30. package/lib/typescript/module/src/NitroArk.nitro.d.ts +59 -0
  31. package/lib/typescript/module/src/NitroArk.nitro.d.ts.map +1 -0
  32. package/lib/typescript/module/src/index.d.ts +180 -0
  33. package/lib/typescript/module/src/index.d.ts.map +1 -0
  34. package/nitrogen/generated/android/NitroArk+autolinking.cmake +78 -0
  35. package/nitrogen/generated/android/NitroArk+autolinking.gradle +27 -0
  36. package/nitrogen/generated/android/NitroArkOnLoad.cpp +44 -0
  37. package/nitrogen/generated/android/NitroArkOnLoad.hpp +25 -0
  38. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroark/NitroArkOnLoad.kt +35 -0
  39. package/nitrogen/generated/ios/NitroArk+autolinking.rb +60 -0
  40. package/nitrogen/generated/ios/NitroArk-Swift-Cxx-Bridge.cpp +17 -0
  41. package/nitrogen/generated/ios/NitroArk-Swift-Cxx-Bridge.hpp +27 -0
  42. package/nitrogen/generated/ios/NitroArk-Swift-Cxx-Umbrella.hpp +38 -0
  43. package/nitrogen/generated/ios/NitroArkAutolinking.mm +35 -0
  44. package/nitrogen/generated/ios/NitroArkAutolinking.swift +12 -0
  45. package/nitrogen/generated/shared/c++/BarkBalance.hpp +77 -0
  46. package/nitrogen/generated/shared/c++/BarkConfigOpts.hpp +90 -0
  47. package/nitrogen/generated/shared/c++/BarkCreateOpts.hpp +96 -0
  48. package/nitrogen/generated/shared/c++/BarkRefreshModeType.hpp +94 -0
  49. package/nitrogen/generated/shared/c++/BarkRefreshOpts.hpp +81 -0
  50. package/nitrogen/generated/shared/c++/BarkSendManyOutput.hpp +73 -0
  51. package/nitrogen/generated/shared/c++/HybridNitroArkSpec.cpp +40 -0
  52. package/nitrogen/generated/shared/c++/HybridNitroArkSpec.hpp +95 -0
  53. package/package.json +178 -0
  54. package/src/NitroArk.nitro.ts +159 -0
  55. package/src/index.tsx +443 -0
package/src/index.tsx ADDED
@@ -0,0 +1,443 @@
1
+ import { NitroModules } from 'react-native-nitro-modules';
2
+ import type {
3
+ NitroArk,
4
+ BarkCreateOpts,
5
+ BarkBalance,
6
+ BarkRefreshOpts,
7
+ BarkSendManyOutput,
8
+ } from './NitroArk.nitro';
9
+
10
+ // Create the hybrid object instance
11
+ export const NitroArkHybridObject =
12
+ NitroModules.createHybridObject<NitroArk>('NitroArk');
13
+
14
+ // --- Management ---
15
+
16
+ /**
17
+ * Creates a new BIP39 mnemonic phrase.
18
+ * @returns A promise resolving to the mnemonic string.
19
+ */
20
+ export function createMnemonic(): Promise<string> {
21
+ return NitroArkHybridObject.createMnemonic();
22
+ }
23
+
24
+ /**
25
+ * Creates a new wallet at the specified directory.
26
+ * @param datadir Path to the data directory.
27
+ * @param opts Creation options.
28
+ * @returns A promise that resolves on success or rejects on error.
29
+ */
30
+ export function createWallet(
31
+ datadir: string,
32
+ opts: BarkCreateOpts
33
+ ): Promise<void> {
34
+ return NitroArkHybridObject.createWallet(datadir, opts);
35
+ }
36
+
37
+ // --- Wallet Info ---
38
+
39
+ /**
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.
44
+ * @returns A promise resolving to the BarkBalance object.
45
+ */
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
+ }
54
+
55
+ /**
56
+ * Gets a fresh onchain address.
57
+ * @param datadir Path to the data directory.
58
+ * @param mnemonic The wallet mnemonic phrase.
59
+ * @returns A promise resolving to the Bitcoin address string.
60
+ */
61
+ export function getOnchainAddress(
62
+ datadir: string,
63
+ mnemonic: string
64
+ ): Promise<string> {
65
+ return NitroArkHybridObject.getOnchainAddress(datadir, mnemonic);
66
+ }
67
+
68
+ /**
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.
73
+ * @returns A promise resolving to the JSON string of UTXOs.
74
+ */
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);
81
+ }
82
+
83
+ /**
84
+ * Gets the wallet's VTXO public key (hex string).
85
+ * @param datadir Path to the data directory.
86
+ * @param mnemonic The wallet mnemonic phrase.
87
+ * @returns A promise resolving to the hex-encoded public key string.
88
+ */
89
+ export function getVtxoPubkey(
90
+ datadir: string,
91
+ mnemonic: string
92
+ ): Promise<string> {
93
+ return NitroArkHybridObject.getVtxoPubkey(datadir, mnemonic);
94
+ }
95
+
96
+ /**
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.
101
+ * @returns A promise resolving to the JSON string of VTXOs.
102
+ */
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);
109
+ }
110
+
111
+ // --- Onchain Operations ---
112
+
113
+ /**
114
+ * Sends funds using the onchain wallet.
115
+ * @param datadir Path to the data directory.
116
+ * @param mnemonic The wallet mnemonic phrase.
117
+ * @param destination The destination Bitcoin address.
118
+ * @param amountSat The amount to send in satoshis.
119
+ * @param no_sync Whether to skip syncing the wallet. Defaults to false.
120
+ * @returns A promise resolving to the transaction ID string.
121
+ */
122
+ export function sendOnchain(
123
+ datadir: string,
124
+ mnemonic: string,
125
+ destination: string,
126
+ amountSat: number,
127
+ no_sync: boolean = false
128
+ ): Promise<string> {
129
+ return NitroArkHybridObject.sendOnchain(
130
+ datadir,
131
+ mnemonic,
132
+ destination,
133
+ amountSat,
134
+ no_sync
135
+ );
136
+ }
137
+
138
+ /**
139
+ * 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
+ * @param destination The destination Bitcoin address.
143
+ * @param no_sync Whether to skip syncing the wallet. Defaults to false.
144
+ * @returns A promise resolving to the transaction ID string.
145
+ */
146
+ export function drainOnchain(
147
+ datadir: string,
148
+ mnemonic: string,
149
+ destination: string,
150
+ no_sync: boolean = false
151
+ ): Promise<string> {
152
+ return NitroArkHybridObject.drainOnchain(
153
+ datadir,
154
+ mnemonic,
155
+ destination,
156
+ no_sync
157
+ );
158
+ }
159
+
160
+ /**
161
+ * 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
+ * @param outputs An array of objects containing destination address and amountSat.
165
+ * @param no_sync Whether to skip syncing the wallet. Defaults to false.
166
+ * @returns A promise resolving to the transaction ID string.
167
+ */
168
+ export function sendManyOnchain(
169
+ datadir: string,
170
+ mnemonic: string,
171
+ outputs: BarkSendManyOutput[],
172
+ no_sync: boolean = false
173
+ ): Promise<string> {
174
+ return NitroArkHybridObject.sendManyOnchain(
175
+ datadir,
176
+ mnemonic,
177
+ outputs,
178
+ no_sync
179
+ );
180
+ }
181
+
182
+ // --- Ark Operations ---
183
+
184
+ /**
185
+ * Refreshes VTXOs based on specified criteria.
186
+ * @param datadir Path to the data directory.
187
+ * @param mnemonic The wallet mnemonic phrase.
188
+ * @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.
191
+ * @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
+ */
200
+ export function refreshVtxos(
201
+ datadir: string,
202
+ mnemonic: string,
203
+ refreshOpts: BarkRefreshOpts,
204
+ no_sync: boolean = false
205
+ ): Promise<string> {
206
+ // Ensure mode_type is provided (should be handled by TS type system)
207
+ if (!refreshOpts.mode_type) {
208
+ return Promise.reject(
209
+ new Error('refreshVtxos requires refreshOpts.mode_type')
210
+ );
211
+ }
212
+ // Additional validation for specific modes could be added here if desired
213
+ if (
214
+ refreshOpts.mode_type === 'Specific' &&
215
+ (!refreshOpts.specific_vtxo_ids ||
216
+ refreshOpts.specific_vtxo_ids.length === 0)
217
+ ) {
218
+ return Promise.reject(
219
+ new Error(
220
+ "refreshVtxos with mode_type 'Specific' requires non-empty specific_vtxo_ids array"
221
+ )
222
+ );
223
+ }
224
+ if (
225
+ (refreshOpts.mode_type === 'ThresholdBlocks' ||
226
+ refreshOpts.mode_type === 'ThresholdHours') &&
227
+ (refreshOpts.threshold_value === undefined ||
228
+ refreshOpts.threshold_value <= 0)
229
+ ) {
230
+ return Promise.reject(
231
+ new Error(
232
+ `refreshVtxos with mode_type '${refreshOpts.mode_type}' requires a positive threshold_value`
233
+ )
234
+ );
235
+ }
236
+ return NitroArkHybridObject.refreshVtxos(
237
+ datadir,
238
+ mnemonic,
239
+ refreshOpts,
240
+ no_sync
241
+ );
242
+ }
243
+
244
+ /**
245
+ * 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
+ * @param amountSat The amount in satoshis to board.
249
+ * @param no_sync Whether to skip syncing the onchain wallet. Defaults to false.
250
+ * @returns A promise resolving to a JSON status string.
251
+ */
252
+ export function boardAmount(
253
+ datadir: string,
254
+ mnemonic: string,
255
+ amountSat: number,
256
+ no_sync: boolean = false
257
+ ): Promise<string> {
258
+ return NitroArkHybridObject.boardAmount(
259
+ datadir,
260
+ mnemonic,
261
+ amountSat,
262
+ no_sync
263
+ );
264
+ }
265
+
266
+ /**
267
+ * 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.
271
+ * @returns A promise resolving to a JSON status string.
272
+ */
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);
279
+ }
280
+
281
+ /**
282
+ * Sends funds offchain using Ark VTXOs.
283
+ * @param datadir Path to the data directory.
284
+ * @param mnemonic The wallet mnemonic phrase.
285
+ * @param destination Ark address (VTXO pubkey) or onchain Bitcoin address.
286
+ * @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.
289
+ * @returns A promise resolving to a JSON status string.
290
+ */
291
+ export function send(
292
+ datadir: string,
293
+ mnemonic: string,
294
+ destination: string,
295
+ amountSat: number,
296
+ comment: string | null = null,
297
+ no_sync: boolean = false
298
+ ): Promise<string> {
299
+ return NitroArkHybridObject.send(
300
+ datadir,
301
+ mnemonic,
302
+ destination,
303
+ amountSat,
304
+ comment,
305
+ no_sync
306
+ );
307
+ }
308
+
309
+ /**
310
+ * Sends an onchain payment via an Ark round.
311
+ * @param datadir Path to the data directory.
312
+ * @param mnemonic The wallet mnemonic phrase.
313
+ * @param destination The destination Bitcoin address.
314
+ * @param amountSat The amount in satoshis to send.
315
+ * @param no_sync Whether to skip syncing the wallet. Defaults to false.
316
+ * @returns A promise resolving to a JSON status string.
317
+ */
318
+ export function sendRoundOnchain(
319
+ datadir: string,
320
+ mnemonic: string,
321
+ destination: string,
322
+ amountSat: number,
323
+ no_sync: boolean = false
324
+ ): Promise<string> {
325
+ return NitroArkHybridObject.sendRoundOnchain(
326
+ datadir,
327
+ mnemonic,
328
+ destination,
329
+ amountSat,
330
+ no_sync
331
+ );
332
+ }
333
+
334
+ // --- Offboarding / Exiting ---
335
+
336
+ /**
337
+ * Offboards specific VTXOs to an optional onchain address.
338
+ * @param datadir Path to the data directory.
339
+ * @param mnemonic The wallet mnemonic phrase.
340
+ * @param vtxoIds Array of VtxoId strings to offboard.
341
+ * @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.
343
+ * @returns A promise resolving to a JSON result string.
344
+ */
345
+ export function offboardSpecific(
346
+ datadir: string,
347
+ mnemonic: string,
348
+ vtxoIds: string[],
349
+ optionalAddress: string | null = null,
350
+ no_sync: boolean = false
351
+ ): Promise<string> {
352
+ return NitroArkHybridObject.offboardSpecific(
353
+ datadir,
354
+ mnemonic,
355
+ vtxoIds,
356
+ optionalAddress,
357
+ no_sync
358
+ );
359
+ }
360
+
361
+ /**
362
+ * Offboards all VTXOs to an optional onchain address.
363
+ * @param datadir Path to the data directory.
364
+ * @param mnemonic The wallet mnemonic phrase.
365
+ * @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.
367
+ * @returns A promise resolving to a JSON result string.
368
+ */
369
+ export function offboardAll(
370
+ datadir: string,
371
+ mnemonic: string,
372
+ optionalAddress: string | null = null,
373
+ no_sync: boolean = false
374
+ ): Promise<string> {
375
+ return NitroArkHybridObject.offboardAll(
376
+ datadir,
377
+ mnemonic,
378
+ optionalAddress,
379
+ no_sync
380
+ );
381
+ }
382
+
383
+ /**
384
+ * Starts the exit process for specific VTXOs.
385
+ * @param datadir Path to the data directory.
386
+ * @param mnemonic The wallet mnemonic phrase.
387
+ * @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
+ * @returns A promise resolving to a JSON status string.
390
+ */
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
+ );
404
+ }
405
+
406
+ /**
407
+ * 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
+ * @returns A promise resolving to a JSON status string.
412
+ */
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);
420
+ }
421
+
422
+ /**
423
+ * 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
+ * @returns A promise resolving to a JSON status string.
427
+ */
428
+ export function exitProgressOnce(
429
+ datadir: string,
430
+ mnemonic: string
431
+ ): Promise<string> {
432
+ return NitroArkHybridObject.exitProgressOnce(datadir, mnemonic);
433
+ }
434
+
435
+ // --- Re-export types and enums ---
436
+ export type {
437
+ BarkCreateOpts,
438
+ BarkConfigOpts,
439
+ BarkBalance,
440
+ BarkRefreshOpts,
441
+ BarkRefreshModeType,
442
+ BarkSendManyOutput,
443
+ } from './NitroArk.nitro';