@arkade-os/sdk 0.5.0-rc.1 → 0.5.0-rc.11

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 +41 -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-DqGRG66E.d.cts → asyncStorageTaskQueue-DBaZsltv.d.cts} +2 -2
  7. package/dist/{asyncStorageTaskQueue-DAs_n1xr.d.ts → asyncStorageTaskQueue-uAG3XLyg.d.ts} +2 -2
  8. package/dist/{chunk-RZ2NGS6A.cjs → chunk-5OBGYL6U.cjs} +57 -73
  9. package/dist/chunk-5OBGYL6U.cjs.map +1 -0
  10. package/dist/{chunk-6COJWPBO.js → chunk-CMLSTGOC.js} +55 -68
  11. package/dist/chunk-CMLSTGOC.js.map +1 -0
  12. package/dist/{chunk-WQIWUTYS.cjs → chunk-CQPQ7D4U.cjs} +52 -27
  13. package/dist/chunk-CQPQ7D4U.cjs.map +1 -0
  14. package/dist/{chunk-LPK4UBNJ.js → chunk-DD6MTNAS.js} +4 -4
  15. package/dist/{chunk-LPK4UBNJ.js.map → chunk-DD6MTNAS.js.map} +1 -1
  16. package/dist/{chunk-MXY23OPP.cjs → chunk-IA32YGLH.cjs} +10 -10
  17. package/dist/{chunk-MXY23OPP.cjs.map → chunk-IA32YGLH.cjs.map} +1 -1
  18. package/dist/{chunk-VTE3NYVD.js → chunk-M2ZUPLKQ.js} +1279 -941
  19. package/dist/chunk-M2ZUPLKQ.js.map +1 -0
  20. package/dist/{chunk-YEUXBECG.cjs → chunk-MGDXN74N.cjs} +1691 -1352
  21. package/dist/chunk-MGDXN74N.cjs.map +1 -0
  22. package/dist/{chunk-ZPSUBAWQ.js → chunk-OMJRW2D5.js} +23 -40
  23. package/dist/chunk-OMJRW2D5.js.map +1 -0
  24. package/dist/{chunk-KB7OP3FG.cjs → chunk-PWEBQNIE.cjs} +32 -29
  25. package/dist/chunk-PWEBQNIE.cjs.map +1 -0
  26. package/dist/{chunk-Q5WQ4Y2I.cjs → chunk-T2ILYGWE.cjs} +70 -87
  27. package/dist/chunk-T2ILYGWE.cjs.map +1 -0
  28. package/dist/{chunk-MEJSBJVH.js → chunk-VMLLYEYM.js} +22 -19
  29. package/dist/chunk-VMLLYEYM.js.map +1 -0
  30. package/dist/{chunk-SG4XYCS7.js → chunk-WSQAWSEH.js} +37 -12
  31. package/dist/chunk-WSQAWSEH.js.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-B9Bmrns7.d.ts → delegate-D3YHDERL.d.ts} +1 -1
  37. package/dist/{delegate-CZzIduW4.d.cts → delegate-DFwlkVYR.d.cts} +1 -1
  38. package/dist/{hdWalletCapable-Cr5nGpK5.d.ts → hdWalletCapable-C350s3bP.d.ts} +8 -34
  39. package/dist/{hdWalletCapable-BIl3yLVM.d.cts → hdWalletCapable-rrOmXcbT.d.cts} +8 -34
  40. package/dist/{index-Ci5MmNnK.d.cts → index-C0ZyGoyP.d.cts} +3 -3
  41. package/dist/{index-DQ1Hb2w_.d.ts → index-DASN1cVk.d.ts} +3 -3
  42. package/dist/{index-DnNIOqHS.d.ts → index-DTvUv5lD.d.cts} +188 -224
  43. package/dist/{index-DnNIOqHS.d.cts → index-DTvUv5lD.d.ts} +188 -224
  44. package/dist/index.cjs +328 -333
  45. package/dist/index.d.cts +270 -243
  46. package/dist/index.d.ts +270 -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-BDb5Ee2J.d.cts → taskRunner--sKy9Inv.d.cts} +2 -2
  61. package/dist/{taskRunner-F7wNJcF3.d.ts → taskRunner-B5bl0YRt.d.ts} +2 -2
  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-6COJWPBO.js.map +0 -1
  108. package/dist/chunk-KB7OP3FG.cjs.map +0 -1
  109. package/dist/chunk-MEJSBJVH.js.map +0 -1
  110. package/dist/chunk-NSBPE2FW.js +0 -15
  111. package/dist/chunk-NSBPE2FW.js.map +0 -1
  112. package/dist/chunk-Q5WQ4Y2I.cjs.map +0 -1
  113. package/dist/chunk-RZ2NGS6A.cjs.map +0 -1
  114. package/dist/chunk-SG4XYCS7.js.map +0 -1
  115. package/dist/chunk-VTE3NYVD.js.map +0 -1
  116. package/dist/chunk-WQIWUTYS.cjs.map +0 -1
  117. package/dist/chunk-YEUXBECG.cjs.map +0 -1
  118. package/dist/chunk-ZPSUBAWQ.js.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
@@ -591,7 +591,6 @@ Access the `VtxoManager` from the wallet after configuring `settlementConfig`:
591
591
  const manager = await wallet.getVtxoManager()
592
592
  ```
593
593
 
594
- > **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.
595
594
 
596
595
  #### Renewal: Prevent Expiration
597
596
 
@@ -1109,72 +1108,17 @@ examples.
1109
1108
 
1110
1109
  ### Repositories (Storage)
1111
1110
 
1112
- The `StorageAdapter` API is deprecated. Use repositories instead. If you omit `storage`, the SDK uses IndexedDB repositories with the default database name.
1113
-
1114
- #### Migration from v1 StorageAdapter
1115
-
1116
- > [!WARNING]
1117
- > If you previously used the v1 `StorageAdapter`-based repositories, migrate
1118
- > data into the new IndexedDB repositories before use:
1119
- >
1120
- > ```typescript
1121
- > import {
1122
- > IndexedDBWalletRepository,
1123
- > IndexedDBContractRepository,
1124
- > getMigrationStatus,
1125
- > migrateWalletRepository,
1126
- > rollbackMigration,
1127
- > } from '@arkade-os/sdk'
1128
- > import { IndexedDBStorageAdapter } from '@arkade-os/sdk/adapters/indexedDB'
1129
- >
1130
- > const oldStorage = new IndexedDBStorageAdapter('legacy-wallet', 1)
1131
- > const newDbName = 'my-app-db'
1132
- > const walletRepository = new IndexedDBWalletRepository(newDbName)
1133
- >
1134
- > // Check migration status before running
1135
- > const status = await getMigrationStatus('wallet', oldStorage)
1136
- > // status: "not-needed" | "pending" | "in-progress" | "done"
1137
- >
1138
- > if (status === 'pending' || status === 'in-progress') {
1139
- > try {
1140
- > await migrateWalletRepository(oldStorage, walletRepository, {
1141
- > onchain: [ 'address-1', 'address-2' ],
1142
- > offchain: [ 'onboarding-address-1' ],
1143
- > })
1144
- > } catch (err) {
1145
- > // Reset migration flag so the next attempt starts clean
1146
- > await rollbackMigration('wallet', oldStorage)
1147
- > throw err
1148
- > }
1149
- > }
1150
- > ```
1151
- >
1152
- > **Migration status helpers:**
1153
- >
1154
- > | Helper | Description |
1155
- > |--------|-------------|
1156
- > | `getMigrationStatus(repoType, adapter)` | Returns `"not-needed"` (no legacy DB), `"pending"`, `"in-progress"` (interrupted), or `"done"` |
1157
- > | `requiresMigration(repoType, adapter)` | Returns `true` if status is `"pending"` or `"in-progress"` |
1158
- > | `rollbackMigration(repoType, adapter)` | Removes the migration flag so migration can re-run from scratch |
1159
- > | `MIGRATION_KEY(repoType)` | Returns the storage key used for the migration flag |
1160
- >
1161
- > `migrateWalletRepository` sets an `"in-progress"` flag before copying data.
1162
- > If the process crashes mid-way, the flag remains as `"in-progress"` so the
1163
- > next call to `getMigrationStatus` can detect the partial migration. Old data
1164
- > is never deleted — re-running migration after a rollback is safe.
1165
- >
1166
- > Anything related to contract repository migration must be handled by the
1167
- > package that created the contracts. The SDK doesn't manage external contracts
1168
- > in V1; data persisted by other packages remains untouched in its original
1169
- > location.
1111
+ Use repository implementations via `StorageConfig`. If you omit `storage`, the
1112
+ SDK uses IndexedDB repositories with the default database name.
1170
1113
 
1171
1114
  #### Repository Versioning
1172
1115
 
1173
- `WalletRepository`, `ContractRepository`, and `SwapRepository` (in
1174
- `@arkade-os/swap`) each declare a `readonly version` field with a literal
1175
- type. All built-in implementations set this to the current version. If you
1176
- maintain a custom repository implementation, TypeScript will produce a compile
1177
- 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:
1178
1122
 
1179
1123
  ```typescript
1180
1124
  import { WalletRepository } from '@arkade-os/sdk'
@@ -1283,6 +1227,7 @@ const wallet = await Wallet.create({
1283
1227
  })
1284
1228
  ```
1285
1229
 
1230
+ ### Using with Node.js
1286
1231
  ### Using with Node.js
1287
1232
 
1288
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:
@@ -1406,7 +1351,7 @@ When you call `wallet.notifyIncomingFunds()` or use `waitForIncomingFunds()`, it
1406
1351
 
1407
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.
1408
1353
 
1409
- 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.
1410
1355
 
1411
1356
  ```typescript
1412
1357
  const wallet = await Wallet.create({
@@ -1426,6 +1371,35 @@ const swWallet = await ServiceWorkerWallet.setup({
1426
1371
 
1427
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.
1428
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
+
1429
1403
  For advanced use cases, you can access the ContractManager directly to register external contracts:
1430
1404
 
1431
1405
  ```typescript
@@ -1471,7 +1445,7 @@ const paths = manager.getSpendablePaths({
1471
1445
  contractScript: contract.script,
1472
1446
  vtxo,
1473
1447
  collaborative: true,
1474
- walletPubKey: myPubKey,
1448
+ walletDescriptor: myDescriptor,
1475
1449
  })
1476
1450
  if (paths.length > 0) {
1477
1451
  console.log('Contract is spendable via:', paths[0].leaf)
@@ -1481,7 +1455,7 @@ if (paths.length > 0) {
1481
1455
  const allPaths = await manager.getAllSpendingPaths({
1482
1456
  contractScript: contract.script,
1483
1457
  collaborative: true,
1484
- walletPubKey: myPubKey,
1458
+ walletDescriptor: myDescriptor,
1485
1459
  })
1486
1460
 
1487
1461
  // Fetch contracts together with their current virtual outputs
@@ -1,19 +1,18 @@
1
1
  'use strict';
2
2
 
3
- var chunkKB7OP3FG_cjs = require('../chunk-KB7OP3FG.cjs');
4
- require('../chunk-WQIWUTYS.cjs');
5
- require('../chunk-RZ2NGS6A.cjs');
6
- require('../chunk-5BLDMQED.cjs');
3
+ var chunkPWEBQNIE_cjs = require('../chunk-PWEBQNIE.cjs');
4
+ require('../chunk-CQPQ7D4U.cjs');
5
+ require('../chunk-5OBGYL6U.cjs');
7
6
 
8
7
 
9
8
 
10
9
  Object.defineProperty(exports, "ExpoArkProvider", {
11
10
  enumerable: true,
12
- get: function () { return chunkKB7OP3FG_cjs.ExpoArkProvider; }
11
+ get: function () { return chunkPWEBQNIE_cjs.ExpoArkProvider; }
13
12
  });
14
13
  Object.defineProperty(exports, "ExpoIndexerProvider", {
15
14
  enumerable: true,
16
- get: function () { return chunkKB7OP3FG_cjs.ExpoIndexerProvider; }
15
+ get: function () { return chunkPWEBQNIE_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-DnNIOqHS.cjs';
2
- export { u as ArkProvider, v as IndexerProvider } from '../index-DnNIOqHS.cjs';
1
+ import { q as RestArkProvider, n as SettlementEvent, T as TxNotificationEvent, r as RestIndexerProvider, s as SubscriptionResponse } from '../index-DTvUv5lD.cjs';
2
+ export { t as ArkProvider, u as IndexerProvider } from '../index-DTvUv5lD.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-DnNIOqHS.js';
2
- export { u as ArkProvider, v as IndexerProvider } from '../index-DnNIOqHS.js';
1
+ import { q as RestArkProvider, n as SettlementEvent, T as TxNotificationEvent, r as RestIndexerProvider, s as SubscriptionResponse } from '../index-DTvUv5lD.js';
2
+ export { t as ArkProvider, u as IndexerProvider } from '../index-DTvUv5lD.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-MEJSBJVH.js';
2
- import '../chunk-SG4XYCS7.js';
3
- import '../chunk-6COJWPBO.js';
4
- import '../chunk-NSBPE2FW.js';
1
+ export { ExpoArkProvider, ExpoIndexerProvider } from '../chunk-VMLLYEYM.js';
2
+ import '../chunk-WSQAWSEH.js';
3
+ import '../chunk-CMLSTGOC.js';
5
4
  //# sourceMappingURL=expo.js.map
6
5
  //# sourceMappingURL=expo.js.map
@@ -1,4 +1,4 @@
1
- import { c as TaskQueue, a as TaskItem, b as TaskResult } from './taskRunner-BDb5Ee2J.cjs';
1
+ import { a as TaskQueue, c as TaskItem, d as TaskResult } from './taskRunner--sKy9Inv.cjs';
2
2
 
3
3
  /**
4
4
  * Minimal async key-value storage interface.
@@ -46,4 +46,4 @@ declare class AsyncStorageTaskQueue implements TaskQueue {
46
46
  private writeList;
47
47
  }
48
48
 
49
- export { type AsyncStorageLike as A, AsyncStorageTaskQueue as a };
49
+ export { AsyncStorageTaskQueue as A, type AsyncStorageLike as a };
@@ -1,4 +1,4 @@
1
- import { c as TaskQueue, a as TaskItem, b as TaskResult } from './taskRunner-F7wNJcF3.js';
1
+ import { a as TaskQueue, c as TaskItem, d as TaskResult } from './taskRunner-B5bl0YRt.js';
2
2
 
3
3
  /**
4
4
  * Minimal async key-value storage interface.
@@ -46,4 +46,4 @@ declare class AsyncStorageTaskQueue implements TaskQueue {
46
46
  private writeList;
47
47
  }
48
48
 
49
- export { type AsyncStorageLike as A, AsyncStorageTaskQueue as a };
49
+ export { AsyncStorageTaskQueue as A, type AsyncStorageLike as a };
@@ -29,7 +29,11 @@ function _interopNamespace(e) {
29
29
 
30
30
  var bip68__namespace = /*#__PURE__*/_interopNamespace(bip68);
31
31
 
32
- // src/utils/transaction.ts
32
+ var __defProp = Object.defineProperty;
33
+ var __export = (target, all) => {
34
+ for (var name in all)
35
+ __defProp(target, name, { get: all[name], enumerable: true });
36
+ };
33
37
  var Transaction = class extends btcSigner.Transaction {
34
38
  static ARK_TX_OPTS = {
35
39
  allowUnknown: true,
@@ -1045,11 +1049,15 @@ function resolveEventSource(override) {
1045
1049
  }
1046
1050
 
1047
1051
  // package.json
1048
- var version = "0.5.0-rc.1";
1052
+ var version = "0.5.0-rc.11";
1049
1053
 
1050
1054
  // src/utils/fetch.ts
1051
1055
  var buildVersion = "0.9.9";
1052
1056
  var sdkVersion = `ts-sdk/${version}`;
1057
+ var ARKADE_VERSION_HEADERS = {
1058
+ "X-Build-Version": buildVersion,
1059
+ "X-SDK-VERSION": sdkVersion
1060
+ };
1053
1061
  var FetchError = class extends Error {
1054
1062
  /** The request URL that failed, when derivable from the `fetch` input. */
1055
1063
  url;
@@ -1062,11 +1070,36 @@ var FetchError = class extends Error {
1062
1070
  this.method = options.method;
1063
1071
  }
1064
1072
  };
1073
+ var READ_TIMEOUT_MS = 3e4;
1074
+ var warnedNoTimeoutSupport = false;
1075
+ function readDeadline(input, init) {
1076
+ if (init?.signal || input instanceof Request) return void 0;
1077
+ const { method } = describeRequest(input, init);
1078
+ const verb = method.toUpperCase();
1079
+ if (verb !== "GET" && verb !== "HEAD") return void 0;
1080
+ if (typeof AbortSignal !== "undefined" && typeof AbortSignal.timeout === "function") {
1081
+ return AbortSignal.timeout(READ_TIMEOUT_MS);
1082
+ }
1083
+ if (typeof AbortController === "function") {
1084
+ const controller = new AbortController();
1085
+ const timer = setTimeout(() => controller.abort(), READ_TIMEOUT_MS);
1086
+ timer?.unref?.();
1087
+ return controller.signal;
1088
+ }
1089
+ if (!warnedNoTimeoutSupport) {
1090
+ warnedNoTimeoutSupport = true;
1091
+ console.warn(
1092
+ "Neither AbortSignal.timeout nor AbortController is available in this runtime: provider reads are UNBOUNDED and READ_TIMEOUT_MS is not being applied."
1093
+ );
1094
+ }
1095
+ return void 0;
1096
+ }
1065
1097
  function baseFetch(input, init) {
1066
1098
  if (typeof globalThis.fetch !== "function") {
1067
1099
  throw new Error("Fetch API is not available in this environment.");
1068
1100
  }
1069
- return globalThis.fetch(input, init).catch((cause) => {
1101
+ const signal = readDeadline(input, init);
1102
+ return globalThis.fetch(input, signal ? { ...init, signal } : init).catch((cause) => {
1070
1103
  const { url, method } = describeRequest(input, init);
1071
1104
  throw new FetchError(`Network request failed: ${method} ${url}`, { url, method, cause });
1072
1105
  });
@@ -2289,60 +2322,23 @@ function parseWireExpiry(raw) {
2289
2322
  if (ms >= EXPIRY_MIN_PLAUSIBLE_MS) return { expiresAt: new Date(ms) };
2290
2323
  return { expiresAtHeight: n };
2291
2324
  }
2292
- function toBatchExpiry(c) {
2293
- if (c.expiresAt !== void 0) return c.expiresAt.getTime();
2294
- if (c.expiresAtHeight !== void 0) return c.expiresAtHeight * 1e3;
2295
- return void 0;
2296
- }
2297
- function parseLegacyExpiry(batchExpiry) {
2298
- if (batchExpiry === void 0 || batchExpiry <= 0) return {};
2299
- if (batchExpiry >= EXPIRY_MIN_PLAUSIBLE_MS) return { expiresAt: new Date(batchExpiry) };
2300
- return { expiresAtHeight: batchExpiry / 1e3 };
2301
- }
2302
- function toVirtualStatus(c) {
2303
- return {
2304
- // Precedence is load-bearing: consumers bucket on this label, so any other order silently
2305
- // moves VTXOs between buckets.
2306
- state: c.isSpent ? "spent" : c.isSwept ? "swept" : c.isPreconfirmed ? "preconfirmed" : "settled",
2307
- commitmentTxIds: c.commitmentTxIds,
2308
- batchExpiry: toBatchExpiry(c)
2309
- };
2310
- }
2311
2325
  function normalizeVtxo(v) {
2312
- const state = v.virtualStatus?.state;
2313
- const canonicalExpiry = v.expiresAt !== void 0 || v.expiresAtHeight !== void 0;
2314
- const expiry = canonicalExpiry ? (
2315
- // Coerce: a backend that persists through JSON hands back an ISO string, which typechecks
2316
- // as `Date` but returns NaN from `.getTime()` — comparing false against everything.
2317
- {
2318
- expiresAt: v.expiresAt === void 0 ? void 0 : new Date(v.expiresAt),
2319
- expiresAtHeight: v.expiresAtHeight
2320
- }
2321
- ) : parseLegacyExpiry(v.virtualStatus?.batchExpiry);
2322
- const isSpent = v.isSpent ?? state === "spent";
2323
- const isSwept = v.isSwept ?? state === "swept";
2324
- const isPreconfirmed = v.isPreconfirmed ?? state === "preconfirmed";
2325
- const commitmentTxIds = v.commitmentTxIds ?? v.virtualStatus?.commitmentTxIds ?? [];
2326
+ const expiry = {
2327
+ expiresAt: v.expiresAt === void 0 ? void 0 : new Date(v.expiresAt),
2328
+ expiresAtHeight: v.expiresAtHeight
2329
+ };
2326
2330
  return {
2327
2331
  ...v,
2328
- isSpent,
2329
- isSwept,
2330
- isPreconfirmed,
2332
+ isSpent: v.isSpent ?? false,
2333
+ isSwept: v.isSwept ?? false,
2334
+ isPreconfirmed: v.isPreconfirmed ?? false,
2331
2335
  spentBy: v.spentBy ?? "",
2332
- commitmentTxIds,
2333
- ...expiry,
2334
- virtualStatus: v.virtualStatus ?? toVirtualStatus({ isSpent, isSwept, isPreconfirmed, commitmentTxIds, ...expiry })
2336
+ commitmentTxIds: v.commitmentTxIds ?? [],
2337
+ ...expiry
2335
2338
  };
2336
2339
  }
2337
2340
  function convertVtxo(vtxo) {
2338
2341
  const expiry = parseWireExpiry(vtxo.expiresAt);
2339
- const facts = {
2340
- isSpent: vtxo.isSpent,
2341
- isSwept: vtxo.isSwept,
2342
- isPreconfirmed: vtxo.isPreconfirmed,
2343
- commitmentTxIds: vtxo.commitmentTxids,
2344
- ...expiry
2345
- };
2346
2342
  return {
2347
2343
  txid: vtxo.outpoint.txid,
2348
2344
  vout: vtxo.outpoint.vout,
@@ -2351,8 +2347,11 @@ function convertVtxo(vtxo) {
2351
2347
  confirmed: !vtxo.isSwept && !vtxo.isPreconfirmed,
2352
2348
  isLeaf: !vtxo.isPreconfirmed
2353
2349
  },
2354
- ...facts,
2355
- virtualStatus: toVirtualStatus(facts),
2350
+ isSpent: vtxo.isSpent,
2351
+ isSwept: vtxo.isSwept,
2352
+ isPreconfirmed: vtxo.isPreconfirmed,
2353
+ commitmentTxIds: vtxo.commitmentTxids,
2354
+ ...expiry,
2356
2355
  spentBy: vtxo.spentBy ?? "",
2357
2356
  settledBy: vtxo.settledBy,
2358
2357
  arkTxId: vtxo.arkTxid,
@@ -2432,30 +2431,19 @@ function canSweepOnchain(vtxo) {
2432
2431
  return !hasTerminalSpend(n) && !!n.isUnrolled;
2433
2432
  }
2434
2433
  function toOffchainInputFeeParams(vtxo) {
2435
- const batchExpiry = toBatchExpiry(vtxo);
2436
2434
  return {
2437
2435
  amount: BigInt(vtxo.value),
2438
2436
  type: vtxo.isSwept ? "recoverable" : "vtxo",
2439
2437
  weight: 0,
2440
2438
  birth: vtxo.createdAt,
2441
- expiry: batchExpiry ? new Date(batchExpiry) : void 0
2439
+ expiry: vtxo.expiresAt
2442
2440
  };
2443
2441
  }
2444
2442
  function isVirtualCoin(input) {
2445
2443
  return typeof input === "object" && input !== null && typeof input.script === "string";
2446
2444
  }
2447
- function isSpendable(vtxo) {
2448
- return !hasTerminalSpend(vtxo);
2449
- }
2450
- function isRecoverable(vtxo) {
2451
- const n = normalizeVtxo(vtxo);
2452
- return n.isSwept && !hasTerminalSpend(n);
2453
- }
2454
- function isExpired(vtxo) {
2455
- const n = normalizeVtxo(vtxo);
2456
- return n.isSwept || n.expiresAt !== void 0 && n.expiresAt.getTime() <= Date.now();
2457
- }
2458
2445
 
2446
+ exports.ARKADE_VERSION_HEADERS = ARKADE_VERSION_HEADERS;
2459
2447
  exports.ArkAddress = ArkAddress;
2460
2448
  exports.ArkError = ArkError;
2461
2449
  exports.ArkErrorName = ArkErrorName;
@@ -2469,6 +2457,7 @@ exports.DEFAULT_NETWORK = DEFAULT_NETWORK;
2469
2457
  exports.DEFAULT_NETWORK_NAME = DEFAULT_NETWORK_NAME;
2470
2458
  exports.DEFAULT_PAGE_SIZE = DEFAULT_PAGE_SIZE;
2471
2459
  exports.DigestMismatchError = DigestMismatchError;
2460
+ exports.EXPIRY_MIN_PLAUSIBLE_MS = EXPIRY_MIN_PLAUSIBLE_MS;
2472
2461
  exports.EventSourceUnavailableError = EventSourceUnavailableError;
2473
2462
  exports.FetchError = FetchError;
2474
2463
  exports.INFO_FETCH_TIMEOUT_MS = INFO_FETCH_TIMEOUT_MS;
@@ -2477,6 +2466,7 @@ exports.OP_RETURN_EMPTY_PKSCRIPT = OP_RETURN_EMPTY_PKSCRIPT;
2477
2466
  exports.PrevArkTxField = PrevArkTxField;
2478
2467
  exports.PrevoutTxField = PrevoutTxField;
2479
2468
  exports.ProviderUnavailableError = ProviderUnavailableError;
2469
+ exports.READ_TIMEOUT_MS = READ_TIMEOUT_MS;
2480
2470
  exports.REGTEST_EMULATOR_PUBKEY = REGTEST_EMULATOR_PUBKEY;
2481
2471
  exports.RestArkProvider = RestArkProvider;
2482
2472
  exports.SCRIPT_QUERY_CHUNK_SIZE = SCRIPT_QUERY_CHUNK_SIZE;
@@ -2487,6 +2477,7 @@ exports.Transaction = Transaction;
2487
2477
  exports.VtxoScript = VtxoScript;
2488
2478
  exports.VtxoTaprootTree = VtxoTaprootTree;
2489
2479
  exports.VtxoTreeExpiry = VtxoTreeExpiry;
2480
+ exports.__export = __export;
2490
2481
  exports.assembleBtcdTaprootTree = assembleBtcdTaprootTree;
2491
2482
  exports.assertAllowedSighashTypes = assertAllowedSighashTypes;
2492
2483
  exports.baseFetch = baseFetch;
@@ -2500,7 +2491,6 @@ exports.craftToSpendTx = craftToSpendTx;
2500
2491
  exports.decodeTapscript = decodeTapscript;
2501
2492
  exports.defaultEmulatorPubkey = defaultEmulatorPubkey;
2502
2493
  exports.eventSourceIterator = eventSourceIterator;
2503
- exports.fetch = fetch;
2504
2494
  exports.fetchVtxoCreatedAtByTxid = fetchVtxoCreatedAtByTxid;
2505
2495
  exports.formatSighash = formatSighash;
2506
2496
  exports.getAllNormalizedVtxos = getAllNormalizedVtxos;
@@ -2513,18 +2503,14 @@ exports.hasTerminalSpend = hasTerminalSpend;
2513
2503
  exports.isArkError = isArkError;
2514
2504
  exports.isEventSourceError = isEventSourceError;
2515
2505
  exports.isEventSourceUnavailableError = isEventSourceUnavailableError;
2516
- exports.isExpired = isExpired;
2517
2506
  exports.isFetchTimeoutError = isFetchTimeoutError;
2518
2507
  exports.isPastExpiry = isPastExpiry;
2519
- exports.isRecoverable = isRecoverable;
2520
2508
  exports.isRetryableProviderError = isRetryableProviderError;
2521
- exports.isSpendable = isSpendable;
2522
2509
  exports.isVirtualCoin = isVirtualCoin;
2523
2510
  exports.maybeArkError = maybeArkError;
2524
2511
  exports.networkFromArkadeInfo = networkFromArkadeInfo;
2525
2512
  exports.networks = networks;
2526
2513
  exports.normalizeVtxo = normalizeVtxo;
2527
- exports.parseLegacyExpiry = parseLegacyExpiry;
2528
2514
  exports.rateGate = rateGate;
2529
2515
  exports.resolveEmulatorPubkey = resolveEmulatorPubkey;
2530
2516
  exports.resolveEventSource = resolveEventSource;
@@ -2535,9 +2521,7 @@ exports.sequenceToTimelock = sequenceToTimelock;
2535
2521
  exports.setArkPsbtField = setArkPsbtField;
2536
2522
  exports.throwIfHttpUnavailable = throwIfHttpUnavailable;
2537
2523
  exports.timelockToSequence = timelockToSequence;
2538
- exports.toBatchExpiry = toBatchExpiry;
2539
2524
  exports.toOffchainInputFeeParams = toOffchainInputFeeParams;
2540
2525
  exports.toProviderUnavailable = toProviderUnavailable;
2541
- exports.toVirtualStatus = toVirtualStatus;
2542
- //# sourceMappingURL=chunk-RZ2NGS6A.cjs.map
2543
- //# sourceMappingURL=chunk-RZ2NGS6A.cjs.map
2526
+ //# sourceMappingURL=chunk-5OBGYL6U.cjs.map
2527
+ //# sourceMappingURL=chunk-5OBGYL6U.cjs.map