@secondts/bark 0.6.3

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/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2026 The Bark Contributors
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,54 @@
1
+ ![bark: Ark on bitcoin](https://gitlab.com/ark-bitcoin/bark-ffi-bindings/-/raw/master/wasm/assets/bark-header-white.jpg)
2
+
3
+ <div align="center">
4
+ <h1>bark</h1>
5
+ <p>WebAssembly bindings for Bark</p>
6
+ </div>
7
+
8
+ <br />
9
+
10
+ Bark is an implementation of the Ark protocol on bitcoin, led by [Second](https://second.tech). The Ark protocol is a bitcoin layer 2 for making fast, low-cost, self-custodial payments at scale. Ark uses a client-server model to enable users to transact off-chain while still being able to "exit" their balances on-chain at any time.
11
+
12
+ Runs in the browser via WebAssembly with IndexedDB persistence.
13
+
14
+ ## Installation
15
+
16
+ ```bash
17
+ npm install @secondts/bark
18
+ ```
19
+
20
+ ### Bundlers (webpack, Rollup, Vite, Next.js, React, Vue, Svelte)
21
+
22
+ The default entrypoint is the wasm-bindgen `bundler` target. Your bundler discovers the `.wasm` file via `new URL(..., import.meta.url)` and bundles it.
23
+
24
+ ```js
25
+ import init, { Wallet, generateMnemonic } from "@secondts/bark";
26
+
27
+ await init?.();
28
+
29
+ const mnemonic = generateMnemonic();
30
+ const wallet = await Wallet.create(mnemonic, config, "wallet-db");
31
+ ```
32
+
33
+ ### Vanilla browser (`<script type="module">`)
34
+
35
+ Use the `./web` subpath. Pass the `.wasm` URL to `init()` explicitly (or let it auto-resolve via `import.meta.url`).
36
+
37
+ ```html
38
+ <script type="module">
39
+ import init, { Wallet, generateMnemonic } from "https://unpkg.com/@secondts/bark/web/bark_ffi_wasm.js";
40
+ await init();
41
+
42
+ const mnemonic = generateMnemonic();
43
+ </script>
44
+ ```
45
+
46
+ ## Notes
47
+
48
+ - Persistence uses IndexedDB; the wallet is keyed by the name passed to `Wallet.create(..., dbName)`.
49
+ - WASM runs in the main thread by default. For heavy operations consider running it inside a Web Worker.
50
+ - Crypto requires the page to be served over HTTPS (or `localhost`); `crypto.subtle` is only available in secure contexts.
51
+
52
+ ## License
53
+
54
+ Released under the **MIT** license.
@@ -0,0 +1,481 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ /**
4
+ * The `ReadableStreamType` enum.
5
+ *
6
+ * *This API requires the following crate features to be activated: `ReadableStreamType`*
7
+ */
8
+
9
+ export type ReadableStreamType = "bytes";
10
+ /**
11
+ * A Bitcoin transaction outpoint (reference to a previous output)
12
+ */
13
+ export interface OutPoint {
14
+ txid: string;
15
+ vout: number;
16
+ }
17
+
18
+ /**
19
+ * A Bitcoin transaction output destination
20
+ */
21
+ export interface Destination {
22
+ address: string;
23
+ amountSats: number;
24
+ }
25
+
26
+ /**
27
+ * A VTXO that is being unilaterally exited
28
+ */
29
+ export interface ExitVtxo {
30
+ vtxoId: string;
31
+ amountSats: number;
32
+ state: string;
33
+ isClaimable: boolean;
34
+ }
35
+
36
+ /**
37
+ * A notification event from the wallet
38
+ */
39
+ export type WalletNotification = { type: "MovementCreated"; movement: Movement } | { type: "MovementUpdated"; movement: Movement } | { type: "ChannelLagging" };
40
+
41
+ /**
42
+ * A pending round state
43
+ */
44
+ export interface RoundState {
45
+ id: number;
46
+ /**
47
+ * Whether the round is ongoing
48
+ */
49
+ ongoing: boolean;
50
+ }
51
+
52
+ /**
53
+ * Claim transaction for exited funds
54
+ */
55
+ export interface ExitClaimTransaction {
56
+ psbtBase64: string;
57
+ feeSats: number;
58
+ }
59
+
60
+ /**
61
+ * Detailed status of an exit transaction
62
+ */
63
+ export interface ExitTransactionStatus {
64
+ vtxoId: string;
65
+ state: string;
66
+ history: string[] | undefined;
67
+ transactionCount: number;
68
+ }
69
+
70
+ /**
71
+ * Parameters for creating a CPFP (Child Pays For Parent) transaction
72
+ */
73
+ export interface CpfpParams {
74
+ txHex: string;
75
+ feesType: string;
76
+ effectiveFeeRateSatPerVb: number;
77
+ currentPackageFeeSats: number | undefined;
78
+ }
79
+
80
+ /**
81
+ * Reference to a block in the blockchain
82
+ */
83
+ export interface BlockRef {
84
+ height: number;
85
+ hash: string;
86
+ }
87
+
88
+ /**
89
+ * Status of an exit progression
90
+ */
91
+ export interface ExitProgressStatus {
92
+ vtxoId: string;
93
+ state: string;
94
+ error: string | undefined;
95
+ }
96
+
97
+ export interface AddressWithIndex {
98
+ address: string;
99
+ index: number;
100
+ }
101
+
102
+ export interface ArkInfo {
103
+ network: Network;
104
+ serverPubkey: string;
105
+ roundIntervalSecs: number;
106
+ nbRoundNonces: number;
107
+ vtxoExitDelta: number;
108
+ vtxoExpiryDelta: number;
109
+ htlcSendExpiryDelta: number;
110
+ htlcExpiryDelta: number;
111
+ maxVtxoAmountSats: number | undefined;
112
+ requiredBoardConfirmations: number;
113
+ maxUserInvoiceCltvDelta: number;
114
+ minBoardAmountSats: number;
115
+ lnReceiveAntiDosRequired: boolean;
116
+ /**
117
+ * Fee schedule as JSON string (contains board, offboard, refresh, lightning fees)
118
+ */
119
+ feeScheduleJson: string;
120
+ /**
121
+ * Maximum exit depth (genesis chain length) allowed for a VTXO before the
122
+ * server refuses to cosign further OOR transactions spending it.
123
+ */
124
+ maxVtxoExitDepth: number;
125
+ }
126
+
127
+ export interface Balance {
128
+ spendableSats: number;
129
+ pendingInRoundSats: number;
130
+ pendingExitSats: number;
131
+ pendingLightningSendSats: number;
132
+ claimableLightningReceiveSats: number;
133
+ pendingBoardSats: number;
134
+ }
135
+
136
+ export interface Bolt11InvoiceArgs {
137
+ amountSats: number;
138
+ description?: string;
139
+ }
140
+
141
+ export interface CheckLightningPaymentArgs {
142
+ paymentHash: string;
143
+ wait: boolean;
144
+ }
145
+
146
+ export interface Config {
147
+ serverAddress: string;
148
+ serverAccessToken?: string;
149
+ esploraAddress?: string;
150
+ bitcoindAddress?: string;
151
+ bitcoindCookiefile?: string;
152
+ bitcoindUser?: string;
153
+ bitcoindPass?: string;
154
+ network: Network;
155
+ vtxoRefreshExpiryThreshold?: number;
156
+ vtxoExitMargin?: number;
157
+ htlcRecvClaimDelta?: number;
158
+ fallbackFeeRate?: number;
159
+ roundTxRequiredConfirmations?: number;
160
+ daemonSyncIntervalSecs?: number;
161
+ offboardRequiredConfirmations?: number;
162
+ daemonManualSync?: boolean;
163
+ lightningReceiveClaimRetries?: number;
164
+ }
165
+
166
+ export interface DrainExitsArgs {
167
+ vtxoIds: string[];
168
+ address: string;
169
+ feeRateSatPerVb?: number;
170
+ }
171
+
172
+ export interface FeeEstimate {
173
+ grossAmountSats: number;
174
+ feeSats: number;
175
+ netAmountSats: number;
176
+ vtxosSpent: string[];
177
+ }
178
+
179
+ export interface GetExitStatusArgs {
180
+ vtxoId: string;
181
+ includeHistory: boolean;
182
+ includeTransactions: boolean;
183
+ }
184
+
185
+ export interface LightningInvoice {
186
+ invoice: string;
187
+ paymentHash: string;
188
+ amountSats: number;
189
+ }
190
+
191
+ export interface LightningReceive {
192
+ paymentHash: string;
193
+ paymentPreimage: string;
194
+ invoice: string;
195
+ amountSats: number;
196
+ hasHtlcVtxos: boolean;
197
+ preimageRevealed: boolean;
198
+ }
199
+
200
+ export interface LightningSend {
201
+ invoice: string;
202
+ amountSats: number;
203
+ htlcVtxoCount: number;
204
+ preimage: string | undefined;
205
+ }
206
+
207
+ export interface Movement {
208
+ id: number;
209
+ status: string;
210
+ subsystemName: string;
211
+ subsystemKind: string;
212
+ metadataJson: string;
213
+ intendedBalanceSats: number;
214
+ effectiveBalanceSats: number;
215
+ offchainFeeSats: number;
216
+ sentToAddresses: string[];
217
+ receivedOnAddresses: string[];
218
+ inputVtxoIds: string[];
219
+ outputVtxoIds: string[];
220
+ exitedVtxoIds: string[];
221
+ createdAt: string;
222
+ updatedAt: string;
223
+ completedAt: string | undefined;
224
+ }
225
+
226
+ export interface OffboardResult {
227
+ roundId: string;
228
+ }
229
+
230
+ export interface OnchainBalance {
231
+ confirmedSats: number;
232
+ pendingSats: number;
233
+ totalSats: number;
234
+ }
235
+
236
+ export interface OnchainWalletDefaultArgs {
237
+ mnemonic: string;
238
+ config: Config;
239
+ dbName: string;
240
+ }
241
+
242
+ export interface PayLightningInvoiceArgs {
243
+ invoice: string;
244
+ amountSats?: number;
245
+ }
246
+
247
+ export interface PayLightningOfferArgs {
248
+ offer: string;
249
+ amountSats?: number;
250
+ }
251
+
252
+ export interface PendingBoard {
253
+ vtxoId: string;
254
+ amountSats: number;
255
+ txid: string;
256
+ }
257
+
258
+ export interface ProgressExitsArgs {
259
+ feeRateSatPerVb?: number;
260
+ }
261
+
262
+ export interface TryClaimAllLightningReceivesArgs {
263
+ wait: boolean;
264
+ }
265
+
266
+ export interface TryClaimLightningReceiveArgs {
267
+ paymentHash: string;
268
+ wait: boolean;
269
+ }
270
+
271
+ export interface Vtxo {
272
+ id: string;
273
+ amountSats: number;
274
+ expiryHeight: number;
275
+ kind: string;
276
+ state: string;
277
+ /**
278
+ * Genesis chain length. Compare against `ArkInfo.max_vtxo_exit_depth` to
279
+ * detect VTXOs nearing the server\'s OOR-cosign refusal threshold.
280
+ */
281
+ exitDepth: number;
282
+ /**
283
+ * Weight units of the unilateral exit transaction chain. Lets clients
284
+ * estimate exit cost without loading the full genesis.
285
+ */
286
+ exitTxWeightWu: number;
287
+ }
288
+
289
+ export interface WalletCreateArgs {
290
+ mnemonic: string;
291
+ config: Config;
292
+ dbName: string;
293
+ forceRescan: boolean;
294
+ }
295
+
296
+ export interface WalletOpenArgs {
297
+ mnemonic: string;
298
+ config: Config;
299
+ dbName: string;
300
+ }
301
+
302
+ export interface WalletProperties {
303
+ network: Network;
304
+ fingerprint: string;
305
+ }
306
+
307
+ export type Network = "Bitcoin" | "Testnet" | "Signet" | "Regtest";
308
+
309
+
310
+ export class IntoUnderlyingByteSource {
311
+ private constructor();
312
+ free(): void;
313
+ [Symbol.dispose](): void;
314
+ cancel(): void;
315
+ pull(controller: ReadableByteStreamController): Promise<any>;
316
+ start(controller: ReadableByteStreamController): void;
317
+ readonly autoAllocateChunkSize: number;
318
+ readonly type: ReadableStreamType;
319
+ }
320
+
321
+ export class IntoUnderlyingSink {
322
+ private constructor();
323
+ free(): void;
324
+ [Symbol.dispose](): void;
325
+ abort(reason: any): Promise<any>;
326
+ close(): Promise<any>;
327
+ write(chunk: any): Promise<any>;
328
+ }
329
+
330
+ export class IntoUnderlyingSource {
331
+ private constructor();
332
+ free(): void;
333
+ [Symbol.dispose](): void;
334
+ cancel(): void;
335
+ pull(controller: ReadableStreamDefaultController): Promise<any>;
336
+ }
337
+
338
+ /**
339
+ * Pull-based notification handle exposed to JS.
340
+ *
341
+ * Obtain via `wallet.notifications()`. Loop on `await notif.nextNotification()`.
342
+ * Each call to `wallet.notifications()` creates an independent stream — existing
343
+ * holders are unaffected.
344
+ *
345
+ * Single-consumer per holder: concurrent `nextNotification()` calls reject with
346
+ * an `Internal` error.
347
+ */
348
+ export class NotificationHolder {
349
+ private constructor();
350
+ free(): void;
351
+ [Symbol.dispose](): void;
352
+ /**
353
+ * Cancel the currently pending `nextNotification()` wait.
354
+ *
355
+ * Causes a blocked `nextNotification()` to resolve to `null`. Does NOT
356
+ * destroy the underlying stream — a subsequent call resumes normally.
357
+ */
358
+ cancelNextNotificationWait(): void;
359
+ /**
360
+ * Wait for the next wallet notification.
361
+ *
362
+ * Resolves to a `WalletNotification` object, or `null` if:
363
+ * - `cancelNextNotificationWait()` was called while pending, or
364
+ * - the wallet's notification source was shut down.
365
+ */
366
+ nextNotification(): Promise<WalletNotification | undefined>;
367
+ }
368
+
369
+ export class OnchainWallet {
370
+ private constructor();
371
+ free(): void;
372
+ [Symbol.dispose](): void;
373
+ balance(): Promise<OnchainBalance>;
374
+ /**
375
+ * Open (or create) the onchain wallet against an IndexedDB-backed persister.
376
+ */
377
+ static default(args: OnchainWalletDefaultArgs): Promise<OnchainWallet>;
378
+ newAddress(): Promise<string>;
379
+ send(address: string, amountSats: number, feeRateSatPerVb: number): Promise<string>;
380
+ sync(): Promise<number>;
381
+ }
382
+
383
+ export class Wallet {
384
+ private constructor();
385
+ free(): void;
386
+ [Symbol.dispose](): void;
387
+ allExitsClaimableAtHeight(): Promise<number | undefined>;
388
+ allVtxos(): Promise<Vtxo[]>;
389
+ arkInfo(): Promise<ArkInfo | undefined>;
390
+ balance(): Promise<Balance>;
391
+ boardAll(onchainWallet: OnchainWallet): Promise<PendingBoard>;
392
+ boardAmount(onchainWallet: OnchainWallet, amountSats: number): Promise<PendingBoard>;
393
+ bolt11Invoice(args: Bolt11InvoiceArgs): Promise<LightningInvoice>;
394
+ broadcastTx(txHex: string): Promise<string>;
395
+ cancelAllPendingRounds(): Promise<void>;
396
+ cancelLightningReceive(paymentHash: string): Promise<void>;
397
+ cancelPendingRound(roundId: number): Promise<void>;
398
+ checkLightningPayment(args: CheckLightningPaymentArgs): Promise<string | undefined>;
399
+ claimableLightningReceiveBalanceSats(): Promise<number>;
400
+ config(): Promise<Config>;
401
+ static create(args: WalletCreateArgs): Promise<Wallet>;
402
+ static createWithOnchain(onchainWallet: OnchainWallet, args: WalletCreateArgs): Promise<Wallet>;
403
+ drainExits(args: DrainExitsArgs): Promise<ExitClaimTransaction>;
404
+ estimateArkoorPaymentFee(amountSats: number): Promise<FeeEstimate>;
405
+ estimateBoardFee(amountSats: number): Promise<FeeEstimate>;
406
+ estimateLightningReceiveFee(amountSats: number): Promise<FeeEstimate>;
407
+ estimateLightningSendFee(amountSats: number): Promise<FeeEstimate>;
408
+ estimateOffboardAllFee(address: string): Promise<FeeEstimate>;
409
+ estimateOffboardFee(address: string, vtxoIds: string[]): Promise<FeeEstimate>;
410
+ estimateRefreshFee(vtxoIds: string[]): Promise<FeeEstimate>;
411
+ estimateSendOnchainFee(address: string, amountSats: number): Promise<FeeEstimate>;
412
+ fingerprint(): string;
413
+ getExitStatus(args: GetExitStatusArgs): Promise<ExitTransactionStatus | undefined>;
414
+ getExitVtxos(): Promise<ExitVtxo[]>;
415
+ getExpiringVtxos(thresholdBlocks: number): Promise<Vtxo[]>;
416
+ getFirstExpiringVtxoBlockheight(): Promise<number | undefined>;
417
+ getNextRequiredRefreshBlockheight(): Promise<number | undefined>;
418
+ getVtxoById(vtxoId: string): Promise<Vtxo>;
419
+ getVtxosToRefresh(): Promise<Vtxo[]>;
420
+ hasPendingExits(): Promise<boolean>;
421
+ history(): Promise<Movement[]>;
422
+ historyByPaymentMethod(paymentMethodType: string, paymentMethodValue: string): Promise<Movement[]>;
423
+ importVtxo(vtxoBase64: string): Promise<void>;
424
+ lightningReceiveStatus(paymentHash: string): Promise<LightningReceive | undefined>;
425
+ listClaimableExits(): Promise<ExitVtxo[]>;
426
+ mailboxAuthorization(): string;
427
+ mailboxIdentifier(): string;
428
+ maintenance(): Promise<void>;
429
+ maintenanceDelegated(): Promise<void>;
430
+ maintenanceRefresh(): Promise<string | undefined>;
431
+ maintenanceWithOnchain(onchainWallet: OnchainWallet): Promise<void>;
432
+ maintenanceWithOnchainDelegated(onchainWallet: OnchainWallet): Promise<void>;
433
+ maybeScheduleMaintenanceRefresh(): Promise<number | undefined>;
434
+ network(): Promise<Network>;
435
+ newAddress(): Promise<string>;
436
+ newAddressWithIndex(): Promise<AddressWithIndex>;
437
+ nextRoundStartTime(): Promise<number>;
438
+ notifications(): NotificationHolder;
439
+ offboardAll(bitcoinAddress: string): Promise<OffboardResult>;
440
+ offboardVtxos(vtxoIds: string[], bitcoinAddress: string): Promise<string>;
441
+ static open(args: WalletOpenArgs): Promise<Wallet>;
442
+ static openWithOnchain(onchainWallet: OnchainWallet, args: WalletOpenArgs): Promise<Wallet>;
443
+ payLightningInvoice(args: PayLightningInvoiceArgs): Promise<LightningSend>;
444
+ payLightningOffer(args: PayLightningOfferArgs): Promise<LightningSend>;
445
+ peekAddress(index: number): Promise<string>;
446
+ pendingBoardVtxos(): Promise<Vtxo[]>;
447
+ pendingBoards(): Promise<PendingBoard[]>;
448
+ pendingExitsTotalSats(): Promise<number>;
449
+ pendingLightningReceives(): Promise<LightningReceive[]>;
450
+ pendingLightningSendVtxos(): Promise<Vtxo[]>;
451
+ pendingLightningSends(): Promise<LightningSend[]>;
452
+ pendingRoundInputVtxos(): Promise<Vtxo[]>;
453
+ pendingRoundStates(): Promise<RoundState[]>;
454
+ progressExits(onchainWallet: OnchainWallet, args: ProgressExitsArgs): Promise<ExitProgressStatus[]>;
455
+ progressPendingRounds(): Promise<void>;
456
+ properties(): Promise<WalletProperties>;
457
+ refreshServer(): Promise<void>;
458
+ refreshVtxos(vtxoIds: string[]): Promise<string | undefined>;
459
+ refreshVtxosDelegated(vtxoIds: string[]): Promise<RoundState | undefined>;
460
+ sendArkoorPayment(arkAddress: string, amountSats: number): Promise<string>;
461
+ sendOnchain(address: string, amountSats: number): Promise<string>;
462
+ signExitClaimInputs(psbtBase64: string): Promise<string>;
463
+ spendableVtxos(): Promise<Vtxo[]>;
464
+ startExitForEntireWallet(): Promise<void>;
465
+ startExitForVtxos(vtxoIds: string[]): Promise<void>;
466
+ sync(): Promise<void>;
467
+ syncExits(onchainWallet: OnchainWallet): Promise<void>;
468
+ syncPendingBoards(): Promise<void>;
469
+ tryClaimAllLightningReceives(args: TryClaimAllLightningReceivesArgs): Promise<LightningReceive[]>;
470
+ tryClaimLightningReceive(args: TryClaimLightningReceiveArgs): Promise<void>;
471
+ validateArkoorAddress(address: string): Promise<boolean>;
472
+ vtxos(): Promise<Vtxo[]>;
473
+ }
474
+
475
+ export function extractTxFromPsbt(psbtBase64: string): string;
476
+
477
+ export function generateMnemonic(): string;
478
+
479
+ export function validateArkAddress(address: string): boolean;
480
+
481
+ export function validateMnemonic(mnemonic: string): boolean;
@@ -0,0 +1,9 @@
1
+ /* @ts-self-types="./bark_ffi_wasm.d.ts" */
2
+ import * as wasm from "./bark_ffi_wasm_bg.wasm";
3
+ import { __wbg_set_wasm } from "./bark_ffi_wasm_bg.js";
4
+
5
+ __wbg_set_wasm(wasm);
6
+
7
+ export {
8
+ IntoUnderlyingByteSource, IntoUnderlyingSink, IntoUnderlyingSource, NotificationHolder, OnchainWallet, Wallet, extractTxFromPsbt, generateMnemonic, validateArkAddress, validateMnemonic
9
+ } from "./bark_ffi_wasm_bg.js";