@arkade-os/sdk 0.5.0-rc.0 → 0.5.0-rc.10

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 (120) hide show
  1. package/README.md +74 -67
  2. package/dist/adapters/expo.cjs +5 -6
  3. package/dist/adapters/expo.d.cts +2 -2
  4. package/dist/adapters/expo.d.ts +2 -2
  5. package/dist/adapters/expo.js +3 -4
  6. package/dist/{asyncStorageTaskQueue-BCzN3Y45.d.ts → asyncStorageTaskQueue-BNvkUO09.d.ts} +1 -1
  7. package/dist/{asyncStorageTaskQueue-CdF_ELX8.d.cts → asyncStorageTaskQueue-CcOeZy9Y.d.cts} +1 -1
  8. package/dist/{chunk-PPG6W34P.js → chunk-4AO4SYFM.js} +54 -67
  9. package/dist/chunk-4AO4SYFM.js.map +1 -0
  10. package/dist/{chunk-6AFUNKK7.cjs → chunk-7NWWFC7O.cjs} +57 -73
  11. package/dist/chunk-7NWWFC7O.cjs.map +1 -0
  12. package/dist/{chunk-ABJPM4JF.js → chunk-7NZTSBVR.js} +4 -4
  13. package/dist/{chunk-ABJPM4JF.js.map → chunk-7NZTSBVR.js.map} +1 -1
  14. package/dist/{chunk-5MJHZHG7.cjs → chunk-AGKVSRBX.cjs} +1998 -1388
  15. package/dist/chunk-AGKVSRBX.cjs.map +1 -0
  16. package/dist/{chunk-FVTJJQNM.js → chunk-D7XQK6VK.js} +37 -12
  17. package/dist/chunk-D7XQK6VK.js.map +1 -0
  18. package/dist/{chunk-PB5KJI4U.cjs → chunk-MHMFI2Q3.cjs} +10 -10
  19. package/dist/{chunk-PB5KJI4U.cjs.map → chunk-MHMFI2Q3.cjs.map} +1 -1
  20. package/dist/{chunk-HL7EC2Z5.cjs → chunk-NCSSQITM.cjs} +71 -88
  21. package/dist/chunk-NCSSQITM.cjs.map +1 -0
  22. package/dist/{chunk-CZ32XADN.cjs → chunk-NKJ6BSSM.cjs} +52 -27
  23. package/dist/chunk-NKJ6BSSM.cjs.map +1 -0
  24. package/dist/{chunk-KTU44AEH.js → chunk-OQTQPHW3.js} +24 -41
  25. package/dist/chunk-OQTQPHW3.js.map +1 -0
  26. package/dist/{chunk-JYP7YXT2.js → chunk-P3IY7EVL.js} +22 -19
  27. package/dist/chunk-P3IY7EVL.js.map +1 -0
  28. package/dist/{chunk-6F2Q32KA.js → chunk-W7E44EAT.js} +1585 -977
  29. package/dist/chunk-W7E44EAT.js.map +1 -0
  30. package/dist/{chunk-RXWKCEZP.cjs → chunk-ZJTTNDRG.cjs} +32 -29
  31. package/dist/chunk-ZJTTNDRG.cjs.map +1 -0
  32. package/dist/contracts/handlers/index.cjs +9 -10
  33. package/dist/contracts/handlers/index.d.cts +3 -3
  34. package/dist/contracts/handlers/index.d.ts +3 -3
  35. package/dist/contracts/handlers/index.js +2 -3
  36. package/dist/{delegate-Dyn5L80J.d.ts → delegate-DzEPFKb6.d.ts} +1 -1
  37. package/dist/{delegate-DLIOBQ5x.d.cts → delegate-Nm_rbfti.d.cts} +1 -1
  38. package/dist/{hdWalletCapable-Dt3MUiGE.d.cts → hdWalletCapable-KFhu6_49.d.ts} +54 -36
  39. package/dist/{hdWalletCapable-D9tooZ6F.d.ts → hdWalletCapable-vpYZROpY.d.cts} +54 -36
  40. package/dist/{index-D9tXd-tN.d.ts → index-4xd-xYf7.d.ts} +2 -2
  41. package/dist/{index-D3hmsuKs.d.cts → index-CHCtOzAa.d.cts} +2 -2
  42. package/dist/{index-Udm5V2xW.d.cts → index-DQYGp3A1.d.cts} +237 -225
  43. package/dist/{index-Udm5V2xW.d.ts → index-DQYGp3A1.d.ts} +237 -225
  44. package/dist/index.cjs +331 -332
  45. package/dist/index.d.cts +287 -243
  46. package/dist/index.d.ts +287 -243
  47. package/dist/index.js +4 -5
  48. package/dist/repositories/realm/index.cjs +57 -24
  49. package/dist/repositories/realm/index.cjs.map +1 -1
  50. package/dist/repositories/realm/index.d.cts +12 -4
  51. package/dist/repositories/realm/index.d.ts +12 -4
  52. package/dist/repositories/realm/index.js +43 -10
  53. package/dist/repositories/realm/index.js.map +1 -1
  54. package/dist/repositories/sqlite/index.cjs +103 -33
  55. package/dist/repositories/sqlite/index.cjs.map +1 -1
  56. package/dist/repositories/sqlite/index.d.cts +12 -2
  57. package/dist/repositories/sqlite/index.d.ts +12 -2
  58. package/dist/repositories/sqlite/index.js +90 -20
  59. package/dist/repositories/sqlite/index.js.map +1 -1
  60. package/dist/{taskRunner-DxZciNaa.d.cts → taskRunner-DGTvO-ne.d.cts} +1 -1
  61. package/dist/{taskRunner-ZdS16Ypm.d.ts → taskRunner-DxG06PKN.d.ts} +1 -1
  62. package/dist/wallet/expo/background.cjs +14 -15
  63. package/dist/wallet/expo/background.cjs.map +1 -1
  64. package/dist/wallet/expo/background.d.cts +3 -3
  65. package/dist/wallet/expo/background.d.ts +3 -3
  66. package/dist/wallet/expo/background.js +6 -7
  67. package/dist/wallet/expo/background.js.map +1 -1
  68. package/dist/wallet/expo/index.cjs +15 -23
  69. package/dist/wallet/expo/index.cjs.map +1 -1
  70. package/dist/wallet/expo/index.d.cts +4 -7
  71. package/dist/wallet/expo/index.d.ts +4 -7
  72. package/dist/wallet/expo/index.js +7 -15
  73. package/dist/wallet/expo/index.js.map +1 -1
  74. package/dist/worker/expo/index.cjs +9 -10
  75. package/dist/worker/expo/index.cjs.map +1 -1
  76. package/dist/worker/expo/index.d.cts +4 -4
  77. package/dist/worker/expo/index.d.ts +4 -4
  78. package/dist/worker/expo/index.js +5 -6
  79. package/dist/worker/expo/index.js.map +1 -1
  80. package/package.json +4 -42
  81. package/dist/adapters/asyncStorage.cjs +0 -48
  82. package/dist/adapters/asyncStorage.cjs.map +0 -1
  83. package/dist/adapters/asyncStorage.d.cts +0 -16
  84. package/dist/adapters/asyncStorage.d.ts +0 -16
  85. package/dist/adapters/asyncStorage.js +0 -46
  86. package/dist/adapters/asyncStorage.js.map +0 -1
  87. package/dist/adapters/fileSystem.cjs +0 -116
  88. package/dist/adapters/fileSystem.cjs.map +0 -1
  89. package/dist/adapters/fileSystem.d.cts +0 -17
  90. package/dist/adapters/fileSystem.d.ts +0 -17
  91. package/dist/adapters/fileSystem.js +0 -93
  92. package/dist/adapters/fileSystem.js.map +0 -1
  93. package/dist/adapters/indexedDB.cjs +0 -103
  94. package/dist/adapters/indexedDB.cjs.map +0 -1
  95. package/dist/adapters/indexedDB.d.cts +0 -18
  96. package/dist/adapters/indexedDB.d.ts +0 -18
  97. package/dist/adapters/indexedDB.js +0 -101
  98. package/dist/adapters/indexedDB.js.map +0 -1
  99. package/dist/adapters/localStorage.cjs +0 -50
  100. package/dist/adapters/localStorage.cjs.map +0 -1
  101. package/dist/adapters/localStorage.d.cts +0 -14
  102. package/dist/adapters/localStorage.d.ts +0 -14
  103. package/dist/adapters/localStorage.js +0 -48
  104. package/dist/adapters/localStorage.js.map +0 -1
  105. package/dist/chunk-5BLDMQED.cjs +0 -18
  106. package/dist/chunk-5BLDMQED.cjs.map +0 -1
  107. package/dist/chunk-5MJHZHG7.cjs.map +0 -1
  108. package/dist/chunk-6AFUNKK7.cjs.map +0 -1
  109. package/dist/chunk-6F2Q32KA.js.map +0 -1
  110. package/dist/chunk-CZ32XADN.cjs.map +0 -1
  111. package/dist/chunk-FVTJJQNM.js.map +0 -1
  112. package/dist/chunk-HL7EC2Z5.cjs.map +0 -1
  113. package/dist/chunk-JYP7YXT2.js.map +0 -1
  114. package/dist/chunk-KTU44AEH.js.map +0 -1
  115. package/dist/chunk-NSBPE2FW.js +0 -15
  116. package/dist/chunk-NSBPE2FW.js.map +0 -1
  117. package/dist/chunk-PPG6W34P.js.map +0 -1
  118. package/dist/chunk-RXWKCEZP.cjs.map +0 -1
  119. package/dist/index-C0IanN1m.d.cts +0 -11
  120. package/dist/index-C0IanN1m.d.ts +0 -11
package/README.md CHANGED
@@ -346,6 +346,39 @@ if (incomingFunds.type === "vtxo") {
346
346
  }
347
347
  ```
348
348
 
349
+ #### Cancelling a wait
350
+
351
+ `waitForIncomingFunds` is **a live subscription, not a one-shot query**. It opens an onchain address watcher plus an indexer stream and holds them until it settles. Cancel it whenever you might not await it to completion — pass a `timeoutMs`, or an `AbortSignal`:
352
+
353
+ ```typescript
354
+ const controller = new AbortController()
355
+
356
+ try {
357
+ const funds = await waitForIncomingFunds(wallet, { signal: controller.signal })
358
+ } catch (error) {
359
+ if ((error as Error).name !== "AbortError") throw error
360
+ // cancelled — watchers already released
361
+ }
362
+
363
+ // or bound the wait directly
364
+ await waitForIncomingFunds(wallet, { timeoutMs: 30_000 })
365
+ ```
366
+
367
+ Do **not** `Promise.race` an uncancelled call against a timer:
368
+
369
+ ```typescript
370
+ // WRONG: race abandons the loser without stopping it. Repeat this on a
371
+ // polling loop and the subscriptions stack until the process exits.
372
+ await Promise.race([sleep(15_000), waitForIncomingFunds(wallet)])
373
+
374
+ // Right: the signal tears the watcher down when the timer wins.
375
+ await waitForIncomingFunds(wallet, { timeoutMs: 15_000 }).catch(() => null)
376
+ ```
377
+
378
+ If you want a plain polling loop, use your own timer plus `wallet.getBalance()` — it observes new funds on the next cycle. If you want to keep a watcher across many iterations, call `wallet.notifyIncomingFunds(cb)` **once** and hold its `stop()` function, rather than resubscribing per tick.
379
+
380
+ Concurrent watchers over the same address set share a single Esplora subscription, so a duplicated or leaked watcher no longer multiplies explorer traffic. That is a safety net, not a licence to skip `stop()`.
381
+
349
382
  ### Onboarding
350
383
 
351
384
  Onboarding allows you to swap onchain funds into virtual outputs:
@@ -558,7 +591,6 @@ Access the `VtxoManager` from the wallet after configuring `settlementConfig`:
558
591
  const manager = await wallet.getVtxoManager()
559
592
  ```
560
593
 
561
- > **Migration from `renewalConfig`:** Directly initializing a `VtxoManager` with `renewalConfig` is still supported but deprecated. Prefer `settlementConfig` where `vtxoThreshold` is expressed in **seconds** instead of milliseconds.
562
594
 
563
595
  #### Renewal: Prevent Expiration
564
596
 
@@ -1076,72 +1108,17 @@ examples.
1076
1108
 
1077
1109
  ### Repositories (Storage)
1078
1110
 
1079
- The `StorageAdapter` API is deprecated. Use repositories instead. If you omit `storage`, the SDK uses IndexedDB repositories with the default database name.
1080
-
1081
- #### Migration from v1 StorageAdapter
1082
-
1083
- > [!WARNING]
1084
- > If you previously used the v1 `StorageAdapter`-based repositories, migrate
1085
- > data into the new IndexedDB repositories before use:
1086
- >
1087
- > ```typescript
1088
- > import {
1089
- > IndexedDBWalletRepository,
1090
- > IndexedDBContractRepository,
1091
- > getMigrationStatus,
1092
- > migrateWalletRepository,
1093
- > rollbackMigration,
1094
- > } from '@arkade-os/sdk'
1095
- > import { IndexedDBStorageAdapter } from '@arkade-os/sdk/adapters/indexedDB'
1096
- >
1097
- > const oldStorage = new IndexedDBStorageAdapter('legacy-wallet', 1)
1098
- > const newDbName = 'my-app-db'
1099
- > const walletRepository = new IndexedDBWalletRepository(newDbName)
1100
- >
1101
- > // Check migration status before running
1102
- > const status = await getMigrationStatus('wallet', oldStorage)
1103
- > // status: "not-needed" | "pending" | "in-progress" | "done"
1104
- >
1105
- > if (status === 'pending' || status === 'in-progress') {
1106
- > try {
1107
- > await migrateWalletRepository(oldStorage, walletRepository, {
1108
- > onchain: [ 'address-1', 'address-2' ],
1109
- > offchain: [ 'onboarding-address-1' ],
1110
- > })
1111
- > } catch (err) {
1112
- > // Reset migration flag so the next attempt starts clean
1113
- > await rollbackMigration('wallet', oldStorage)
1114
- > throw err
1115
- > }
1116
- > }
1117
- > ```
1118
- >
1119
- > **Migration status helpers:**
1120
- >
1121
- > | Helper | Description |
1122
- > |--------|-------------|
1123
- > | `getMigrationStatus(repoType, adapter)` | Returns `"not-needed"` (no legacy DB), `"pending"`, `"in-progress"` (interrupted), or `"done"` |
1124
- > | `requiresMigration(repoType, adapter)` | Returns `true` if status is `"pending"` or `"in-progress"` |
1125
- > | `rollbackMigration(repoType, adapter)` | Removes the migration flag so migration can re-run from scratch |
1126
- > | `MIGRATION_KEY(repoType)` | Returns the storage key used for the migration flag |
1127
- >
1128
- > `migrateWalletRepository` sets an `"in-progress"` flag before copying data.
1129
- > If the process crashes mid-way, the flag remains as `"in-progress"` so the
1130
- > next call to `getMigrationStatus` can detect the partial migration. Old data
1131
- > is never deleted — re-running migration after a rollback is safe.
1132
- >
1133
- > Anything related to contract repository migration must be handled by the
1134
- > package that created the contracts. The SDK doesn't manage external contracts
1135
- > in V1; data persisted by other packages remains untouched in its original
1136
- > location.
1111
+ Use repository implementations via `StorageConfig`. If you omit `storage`, the
1112
+ SDK uses IndexedDB repositories with the default database name.
1137
1113
 
1138
1114
  #### Repository Versioning
1139
1115
 
1140
- `WalletRepository`, `ContractRepository`, and `SwapRepository` (in
1141
- `@arkade-os/swap`) each declare a `readonly version` field with a literal
1142
- type. All built-in implementations set this to the current version. If you
1143
- maintain a custom repository implementation, TypeScript will produce a compile
1144
- error when the version is bumped, signaling that a semantic update is required:
1116
+ `WalletRepository`, `ContractRepository`, `IntentRepository`,
1117
+ `VirtualTxRepository`, and `AssetSwapRepository` (in `@arkade-os/swap`) each
1118
+ declare a `readonly version` field with a literal type. All built-in
1119
+ implementations set this to the current version. If you maintain a custom
1120
+ repository implementation, TypeScript will produce a compile error when the
1121
+ version is bumped, signaling that a semantic update is required:
1145
1122
 
1146
1123
  ```typescript
1147
1124
  import { WalletRepository } from '@arkade-os/sdk'
@@ -1250,6 +1227,7 @@ const wallet = await Wallet.create({
1250
1227
  })
1251
1228
  ```
1252
1229
 
1230
+ ### Using with Node.js
1253
1231
  ### Using with Node.js
1254
1232
 
1255
1233
  Node.js does not provide a global `EventSource` implementation (24.x has one behind `--experimental-eventsource`). The SDK relies on `EventSource` for Server-Sent Events during settlement (onboarding/offboarding) and contract watching, so tell it which one to use:
@@ -1373,7 +1351,7 @@ When you call `wallet.notifyIncomingFunds()` or use `waitForIncomingFunds()`, it
1373
1351
 
1374
1352
  HD wallets (`walletMode: 'hd'`, or an explicit HD `DescriptorProvider`) also watch a band of *unused* offchain receive scripts around their allocation watermark, so a payment to an address that some other party issued from the same seed — a merchant backend such as BTCPay Server, or the .NET SDK driving the same wallet — arrives without the user calling `restore()`. `lookAheadWindow` (default `20`) is the per-side width of that band: the wallet watches `[watermark - N, watermark + N]`. Speculative entries are subscription-only; they become contract rows, and enter balances, only once funded.
1375
1353
 
1376
- The issuer, not the wallet, picks the contract shape, so each index is watched at *every* variant the wallet could own there: `default` and `delegate`, crossed with the unilateral-exit timelock matrix and the operator's current plus deprecated signers. That is the candidate set `restore()` probes too, so watching and restoring cover identical scripts.
1354
+ The issuer, not the wallet, picks the contract shape, so each index is watched at *every* variant the wallet could own there: `default` and `delegate`, crossed with the unilateral-exit timelock matrix and the operator's active plus retired signers. That is the candidate set `restore()` probes too, so watching and restoring cover identical scripts.
1377
1355
 
1378
1356
  ```typescript
1379
1357
  const wallet = await Wallet.create({
@@ -1393,6 +1371,35 @@ const swWallet = await ServiceWorkerWallet.setup({
1393
1371
 
1394
1372
  Raise it when the external issuer is expected to burn more than `N` consecutive addresses without any of them being paid — every index in such a run is a miss, and the funded one sits past the band. When that happens the funds are invisible until a `restore()` whose `gapLimit` is large enough to cross the run (`wallet.restore({ gapLimit: 200 })`); a default restore closes its gap window before reaching the funded index. Keep the value modest: the band adds up to `2N + 1` indices × the candidate matrix (typically 1-4 scripts each) to the wallet's subscription.
1395
1373
 
1374
+ #### Restoring plugin state
1375
+
1376
+ `wallet.restore()` is the explicit imported-wallet recovery boundary. It first restores the
1377
+ wallet's own addresses, contracts, history, and balances, then runs every restore hook registered
1378
+ for that wallet instance. `Wallet` and `ServiceWorkerWallet` both follow this ordering, and
1379
+ concurrent calls coalesce until the hooks finish.
1380
+
1381
+ ```typescript
1382
+ import { registerWalletRestoreHook } from '@arkade-os/sdk'
1383
+
1384
+ const unregister = registerWalletRestoreHook(wallet, {
1385
+ id: 'my-plugin',
1386
+ restore: async (restoredWallet) => {
1387
+ await rebuildPluginState(await restoredWallet.getTransactionHistory())
1388
+ },
1389
+ })
1390
+
1391
+ await wallet.restore()
1392
+ ```
1393
+
1394
+ Registering the same `id` again replaces that hook without changing its position. A run uses a
1395
+ stable snapshot, attempts every hook in registration order, and throws an `AggregateError` after
1396
+ all failures have been collected. If core recovery fails, hooks do not run. The returned function
1397
+ removes only that exact registration and is safe to call more than once.
1398
+
1399
+ Hooks do not run during `Wallet.create()`, `ServiceWorkerWallet.setup()`, or ordinary startup. A
1400
+ plugin should register before an application calls `restore()` and keep its normal incremental
1401
+ reconciliation for state that arrives later.
1402
+
1396
1403
  For advanced use cases, you can access the ContractManager directly to register external contracts:
1397
1404
 
1398
1405
  ```typescript
@@ -1438,7 +1445,7 @@ const paths = manager.getSpendablePaths({
1438
1445
  contractScript: contract.script,
1439
1446
  vtxo,
1440
1447
  collaborative: true,
1441
- walletPubKey: myPubKey,
1448
+ walletDescriptor: myDescriptor,
1442
1449
  })
1443
1450
  if (paths.length > 0) {
1444
1451
  console.log('Contract is spendable via:', paths[0].leaf)
@@ -1448,7 +1455,7 @@ if (paths.length > 0) {
1448
1455
  const allPaths = await manager.getAllSpendingPaths({
1449
1456
  contractScript: contract.script,
1450
1457
  collaborative: true,
1451
- walletPubKey: myPubKey,
1458
+ walletDescriptor: myDescriptor,
1452
1459
  })
1453
1460
 
1454
1461
  // Fetch contracts together with their current virtual outputs
@@ -1,19 +1,18 @@
1
1
  'use strict';
2
2
 
3
- var chunkRXWKCEZP_cjs = require('../chunk-RXWKCEZP.cjs');
4
- require('../chunk-CZ32XADN.cjs');
5
- require('../chunk-6AFUNKK7.cjs');
6
- require('../chunk-5BLDMQED.cjs');
3
+ var chunkZJTTNDRG_cjs = require('../chunk-ZJTTNDRG.cjs');
4
+ require('../chunk-NKJ6BSSM.cjs');
5
+ require('../chunk-7NWWFC7O.cjs');
7
6
 
8
7
 
9
8
 
10
9
  Object.defineProperty(exports, "ExpoArkProvider", {
11
10
  enumerable: true,
12
- get: function () { return chunkRXWKCEZP_cjs.ExpoArkProvider; }
11
+ get: function () { return chunkZJTTNDRG_cjs.ExpoArkProvider; }
13
12
  });
14
13
  Object.defineProperty(exports, "ExpoIndexerProvider", {
15
14
  enumerable: true,
16
- get: function () { return chunkRXWKCEZP_cjs.ExpoIndexerProvider; }
15
+ get: function () { return chunkZJTTNDRG_cjs.ExpoIndexerProvider; }
17
16
  });
18
17
  //# sourceMappingURL=expo.cjs.map
19
18
  //# sourceMappingURL=expo.cjs.map
@@ -1,5 +1,5 @@
1
- import { r as RestArkProvider, o as SettlementEvent, T as TxNotificationEvent, s as RestIndexerProvider, t as SubscriptionResponse } from '../index-Udm5V2xW.cjs';
2
- export { u as ArkProvider, v as IndexerProvider } from '../index-Udm5V2xW.cjs';
1
+ import { q as RestArkProvider, n as SettlementEvent, T as TxNotificationEvent, r as RestIndexerProvider, s as SubscriptionResponse } from '../index-DQYGp3A1.cjs';
2
+ export { t as ArkProvider, u as IndexerProvider } from '../index-DQYGp3A1.cjs';
3
3
  import '@scure/btc-signer/utils.js';
4
4
  import '@scure/btc-signer/transaction.js';
5
5
  import '@scure/btc-signer';
@@ -1,5 +1,5 @@
1
- import { r as RestArkProvider, o as SettlementEvent, T as TxNotificationEvent, s as RestIndexerProvider, t as SubscriptionResponse } from '../index-Udm5V2xW.js';
2
- export { u as ArkProvider, v as IndexerProvider } from '../index-Udm5V2xW.js';
1
+ import { q as RestArkProvider, n as SettlementEvent, T as TxNotificationEvent, r as RestIndexerProvider, s as SubscriptionResponse } from '../index-DQYGp3A1.js';
2
+ export { t as ArkProvider, u as IndexerProvider } from '../index-DQYGp3A1.js';
3
3
  import '@scure/btc-signer/utils.js';
4
4
  import '@scure/btc-signer/transaction.js';
5
5
  import '@scure/btc-signer';
@@ -1,6 +1,5 @@
1
- export { ExpoArkProvider, ExpoIndexerProvider } from '../chunk-JYP7YXT2.js';
2
- import '../chunk-FVTJJQNM.js';
3
- import '../chunk-PPG6W34P.js';
4
- import '../chunk-NSBPE2FW.js';
1
+ export { ExpoArkProvider, ExpoIndexerProvider } from '../chunk-P3IY7EVL.js';
2
+ import '../chunk-D7XQK6VK.js';
3
+ import '../chunk-4AO4SYFM.js';
5
4
  //# sourceMappingURL=expo.js.map
6
5
  //# sourceMappingURL=expo.js.map
@@ -1,4 +1,4 @@
1
- import { a as TaskQueue, c as TaskItem, d as TaskResult } from './taskRunner-ZdS16Ypm.js';
1
+ import { a as TaskQueue, c as TaskItem, d as TaskResult } from './taskRunner-DxG06PKN.js';
2
2
 
3
3
  /**
4
4
  * Minimal async key-value storage interface.
@@ -1,4 +1,4 @@
1
- import { a as TaskQueue, c as TaskItem, d as TaskResult } from './taskRunner-DxZciNaa.cjs';
1
+ import { a as TaskQueue, c as TaskItem, d as TaskResult } from './taskRunner-DGTvO-ne.cjs';
2
2
 
3
3
  /**
4
4
  * Minimal async key-value storage interface.
@@ -7,7 +7,11 @@ import { TAP_LEAF_VERSION } from '@scure/btc-signer/payment.js';
7
7
  import { PSBTOutput } from '@scure/btc-signer/psbt.js';
8
8
  import { schnorr } from '@noble/curves/secp256k1.js';
9
9
 
10
- // src/utils/transaction.ts
10
+ var __defProp = Object.defineProperty;
11
+ var __export = (target, all) => {
12
+ for (var name in all)
13
+ __defProp(target, name, { get: all[name], enumerable: true });
14
+ };
11
15
  var Transaction = class extends Transaction$1 {
12
16
  static ARK_TX_OPTS = {
13
17
  allowUnknown: true,
@@ -1023,11 +1027,15 @@ function resolveEventSource(override) {
1023
1027
  }
1024
1028
 
1025
1029
  // package.json
1026
- var version = "0.5.0-rc.0";
1030
+ var version = "0.5.0-rc.10";
1027
1031
 
1028
1032
  // src/utils/fetch.ts
1029
1033
  var buildVersion = "0.9.9";
1030
1034
  var sdkVersion = `ts-sdk/${version}`;
1035
+ var ARKADE_VERSION_HEADERS = {
1036
+ "X-Build-Version": buildVersion,
1037
+ "X-SDK-VERSION": sdkVersion
1038
+ };
1031
1039
  var FetchError = class extends Error {
1032
1040
  /** The request URL that failed, when derivable from the `fetch` input. */
1033
1041
  url;
@@ -1040,11 +1048,36 @@ var FetchError = class extends Error {
1040
1048
  this.method = options.method;
1041
1049
  }
1042
1050
  };
1051
+ var READ_TIMEOUT_MS = 3e4;
1052
+ var warnedNoTimeoutSupport = false;
1053
+ function readDeadline(input, init) {
1054
+ if (init?.signal || input instanceof Request) return void 0;
1055
+ const { method } = describeRequest(input, init);
1056
+ const verb = method.toUpperCase();
1057
+ if (verb !== "GET" && verb !== "HEAD") return void 0;
1058
+ if (typeof AbortSignal !== "undefined" && typeof AbortSignal.timeout === "function") {
1059
+ return AbortSignal.timeout(READ_TIMEOUT_MS);
1060
+ }
1061
+ if (typeof AbortController === "function") {
1062
+ const controller = new AbortController();
1063
+ const timer = setTimeout(() => controller.abort(), READ_TIMEOUT_MS);
1064
+ timer?.unref?.();
1065
+ return controller.signal;
1066
+ }
1067
+ if (!warnedNoTimeoutSupport) {
1068
+ warnedNoTimeoutSupport = true;
1069
+ console.warn(
1070
+ "Neither AbortSignal.timeout nor AbortController is available in this runtime: provider reads are UNBOUNDED and READ_TIMEOUT_MS is not being applied."
1071
+ );
1072
+ }
1073
+ return void 0;
1074
+ }
1043
1075
  function baseFetch(input, init) {
1044
1076
  if (typeof globalThis.fetch !== "function") {
1045
1077
  throw new Error("Fetch API is not available in this environment.");
1046
1078
  }
1047
- return globalThis.fetch(input, init).catch((cause) => {
1079
+ const signal = readDeadline(input, init);
1080
+ return globalThis.fetch(input, signal ? { ...init, signal } : init).catch((cause) => {
1048
1081
  const { url, method } = describeRequest(input, init);
1049
1082
  throw new FetchError(`Network request failed: ${method} ${url}`, { url, method, cause });
1050
1083
  });
@@ -2267,60 +2300,23 @@ function parseWireExpiry(raw) {
2267
2300
  if (ms >= EXPIRY_MIN_PLAUSIBLE_MS) return { expiresAt: new Date(ms) };
2268
2301
  return { expiresAtHeight: n };
2269
2302
  }
2270
- function toBatchExpiry(c) {
2271
- if (c.expiresAt !== void 0) return c.expiresAt.getTime();
2272
- if (c.expiresAtHeight !== void 0) return c.expiresAtHeight * 1e3;
2273
- return void 0;
2274
- }
2275
- function parseLegacyExpiry(batchExpiry) {
2276
- if (batchExpiry === void 0 || batchExpiry <= 0) return {};
2277
- if (batchExpiry >= EXPIRY_MIN_PLAUSIBLE_MS) return { expiresAt: new Date(batchExpiry) };
2278
- return { expiresAtHeight: batchExpiry / 1e3 };
2279
- }
2280
- function toVirtualStatus(c) {
2281
- return {
2282
- // Precedence is load-bearing: consumers bucket on this label, so any other order silently
2283
- // moves VTXOs between buckets.
2284
- state: c.isSpent ? "spent" : c.isSwept ? "swept" : c.isPreconfirmed ? "preconfirmed" : "settled",
2285
- commitmentTxIds: c.commitmentTxIds,
2286
- batchExpiry: toBatchExpiry(c)
2287
- };
2288
- }
2289
2303
  function normalizeVtxo(v) {
2290
- const state = v.virtualStatus?.state;
2291
- const canonicalExpiry = v.expiresAt !== void 0 || v.expiresAtHeight !== void 0;
2292
- const expiry = canonicalExpiry ? (
2293
- // Coerce: a backend that persists through JSON hands back an ISO string, which typechecks
2294
- // as `Date` but returns NaN from `.getTime()` — comparing false against everything.
2295
- {
2296
- expiresAt: v.expiresAt === void 0 ? void 0 : new Date(v.expiresAt),
2297
- expiresAtHeight: v.expiresAtHeight
2298
- }
2299
- ) : parseLegacyExpiry(v.virtualStatus?.batchExpiry);
2300
- const isSpent = v.isSpent ?? state === "spent";
2301
- const isSwept = v.isSwept ?? state === "swept";
2302
- const isPreconfirmed = v.isPreconfirmed ?? state === "preconfirmed";
2303
- const commitmentTxIds = v.commitmentTxIds ?? v.virtualStatus?.commitmentTxIds ?? [];
2304
+ const expiry = {
2305
+ expiresAt: v.expiresAt === void 0 ? void 0 : new Date(v.expiresAt),
2306
+ expiresAtHeight: v.expiresAtHeight
2307
+ };
2304
2308
  return {
2305
2309
  ...v,
2306
- isSpent,
2307
- isSwept,
2308
- isPreconfirmed,
2310
+ isSpent: v.isSpent ?? false,
2311
+ isSwept: v.isSwept ?? false,
2312
+ isPreconfirmed: v.isPreconfirmed ?? false,
2309
2313
  spentBy: v.spentBy ?? "",
2310
- commitmentTxIds,
2311
- ...expiry,
2312
- virtualStatus: v.virtualStatus ?? toVirtualStatus({ isSpent, isSwept, isPreconfirmed, commitmentTxIds, ...expiry })
2314
+ commitmentTxIds: v.commitmentTxIds ?? [],
2315
+ ...expiry
2313
2316
  };
2314
2317
  }
2315
2318
  function convertVtxo(vtxo) {
2316
2319
  const expiry = parseWireExpiry(vtxo.expiresAt);
2317
- const facts = {
2318
- isSpent: vtxo.isSpent,
2319
- isSwept: vtxo.isSwept,
2320
- isPreconfirmed: vtxo.isPreconfirmed,
2321
- commitmentTxIds: vtxo.commitmentTxids,
2322
- ...expiry
2323
- };
2324
2320
  return {
2325
2321
  txid: vtxo.outpoint.txid,
2326
2322
  vout: vtxo.outpoint.vout,
@@ -2329,8 +2325,11 @@ function convertVtxo(vtxo) {
2329
2325
  confirmed: !vtxo.isSwept && !vtxo.isPreconfirmed,
2330
2326
  isLeaf: !vtxo.isPreconfirmed
2331
2327
  },
2332
- ...facts,
2333
- virtualStatus: toVirtualStatus(facts),
2328
+ isSpent: vtxo.isSpent,
2329
+ isSwept: vtxo.isSwept,
2330
+ isPreconfirmed: vtxo.isPreconfirmed,
2331
+ commitmentTxIds: vtxo.commitmentTxids,
2332
+ ...expiry,
2334
2333
  spentBy: vtxo.spentBy ?? "",
2335
2334
  settledBy: vtxo.settledBy,
2336
2335
  arkTxId: vtxo.arkTxid,
@@ -2410,30 +2409,18 @@ function canSweepOnchain(vtxo) {
2410
2409
  return !hasTerminalSpend(n) && !!n.isUnrolled;
2411
2410
  }
2412
2411
  function toOffchainInputFeeParams(vtxo) {
2413
- const batchExpiry = toBatchExpiry(vtxo);
2414
2412
  return {
2415
2413
  amount: BigInt(vtxo.value),
2416
2414
  type: vtxo.isSwept ? "recoverable" : "vtxo",
2417
2415
  weight: 0,
2418
2416
  birth: vtxo.createdAt,
2419
- expiry: batchExpiry ? new Date(batchExpiry) : void 0
2417
+ expiry: vtxo.expiresAt
2420
2418
  };
2421
2419
  }
2422
2420
  function isVirtualCoin(input) {
2423
2421
  return typeof input === "object" && input !== null && typeof input.script === "string";
2424
2422
  }
2425
- function isSpendable(vtxo) {
2426
- return !hasTerminalSpend(vtxo);
2427
- }
2428
- function isRecoverable(vtxo) {
2429
- const n = normalizeVtxo(vtxo);
2430
- return n.isSwept && !hasTerminalSpend(n);
2431
- }
2432
- function isExpired(vtxo) {
2433
- const n = normalizeVtxo(vtxo);
2434
- return n.isSwept || n.expiresAt !== void 0 && n.expiresAt.getTime() <= Date.now();
2435
- }
2436
2423
 
2437
- export { ArkAddress, ArkError, ArkErrorName, ArkPsbtFieldKey, ArkPsbtFieldKeyType, BITCOIN_EMULATOR_PUBKEY, CLTVMultisigTapscript, CSVMultisigTapscript, ConditionCSVMultisigTapscript, ConditionMultisigTapscript, ConditionWitness, CosignerPublicKey, DEFAULT_ARKADE_SERVER_URL, DEFAULT_NETWORK, DEFAULT_NETWORK_NAME, DEFAULT_PAGE_SIZE, DigestMismatchError, EventSourceUnavailableError, FetchError, INFO_FETCH_TIMEOUT_MS, Intent, MUTINYNET_EMULATOR_PUBKEY, MultisigTapscript, OP_RETURN_EMPTY_PKSCRIPT, PrevArkTxField, PrevoutTxField, ProviderUnavailableError, REGTEST_EMULATOR_PUBKEY, RestArkProvider, SCRIPT_QUERY_CHUNK_SIZE, ServerResponseMismatchError, SettlementEventType, TapTreeCoder, Transaction, VtxoScript, VtxoTaprootTree, VtxoTreeExpiry, assembleBtcdTaprootTree, assertAllowedSighashTypes, baseFetch, buildVersion, canRecoverOnchain, canSpendOffchain, canSweepOnchain, configureEventSource, convertVtxo, craftToSpendTx, decodeTapscript, defaultEmulatorPubkey, eventSourceIterator, fetch, fetchVtxoCreatedAtByTxid, formatSighash, getAllNormalizedVtxos, getArkPsbtFields, getConfiguredEventSource, getNetwork, getNormalizedVtxos, getSequence, hasTerminalSpend, isArkError, isEventSourceError, isEventSourceUnavailableError, isExpired, isFetchTimeoutError, isPastExpiry, isRecoverable, isRetryableProviderError, isSpendable, isVirtualCoin, maybeArkError, networkFromArkadeInfo, networks, normalizeVtxo, parseLegacyExpiry, rateGate, resolveEmulatorPubkey, resolveEventSource, resolveTimeHeight, scriptFromTapLeafScript, sdkVersion, sequenceToTimelock, setArkPsbtField, throwIfHttpUnavailable, timelockToSequence, toBatchExpiry, toOffchainInputFeeParams, toProviderUnavailable, toVirtualStatus };
2438
- //# sourceMappingURL=chunk-PPG6W34P.js.map
2439
- //# sourceMappingURL=chunk-PPG6W34P.js.map
2424
+ export { ARKADE_VERSION_HEADERS, ArkAddress, ArkError, ArkErrorName, ArkPsbtFieldKey, ArkPsbtFieldKeyType, BITCOIN_EMULATOR_PUBKEY, CLTVMultisigTapscript, CSVMultisigTapscript, ConditionCSVMultisigTapscript, ConditionMultisigTapscript, ConditionWitness, CosignerPublicKey, DEFAULT_ARKADE_SERVER_URL, DEFAULT_NETWORK, DEFAULT_NETWORK_NAME, DEFAULT_PAGE_SIZE, DigestMismatchError, EXPIRY_MIN_PLAUSIBLE_MS, EventSourceUnavailableError, FetchError, INFO_FETCH_TIMEOUT_MS, Intent, MUTINYNET_EMULATOR_PUBKEY, MultisigTapscript, OP_RETURN_EMPTY_PKSCRIPT, PrevArkTxField, PrevoutTxField, ProviderUnavailableError, READ_TIMEOUT_MS, REGTEST_EMULATOR_PUBKEY, RestArkProvider, SCRIPT_QUERY_CHUNK_SIZE, ServerResponseMismatchError, SettlementEventType, TapTreeCoder, Transaction, VtxoScript, VtxoTaprootTree, VtxoTreeExpiry, __export, assembleBtcdTaprootTree, assertAllowedSighashTypes, baseFetch, buildVersion, canRecoverOnchain, canSpendOffchain, canSweepOnchain, configureEventSource, convertVtxo, craftToSpendTx, decodeTapscript, defaultEmulatorPubkey, eventSourceIterator, fetchVtxoCreatedAtByTxid, formatSighash, getAllNormalizedVtxos, getArkPsbtFields, getConfiguredEventSource, getNetwork, getNormalizedVtxos, getSequence, hasTerminalSpend, isArkError, isEventSourceError, isEventSourceUnavailableError, isFetchTimeoutError, isPastExpiry, isRetryableProviderError, isVirtualCoin, maybeArkError, networkFromArkadeInfo, networks, normalizeVtxo, rateGate, resolveEmulatorPubkey, resolveEventSource, resolveTimeHeight, scriptFromTapLeafScript, sdkVersion, sequenceToTimelock, setArkPsbtField, throwIfHttpUnavailable, timelockToSequence, toOffchainInputFeeParams, toProviderUnavailable };
2425
+ //# sourceMappingURL=chunk-4AO4SYFM.js.map
2426
+ //# sourceMappingURL=chunk-4AO4SYFM.js.map