@arkade-os/sdk 0.4.25 → 0.4.27

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 (222) hide show
  1. package/README.md +5 -25
  2. package/dist/cjs/contracts/contractManager.js +31 -11
  3. package/dist/cjs/contracts/contractWatcher.js +2 -2
  4. package/dist/cjs/identity/hdCapableIdentity.js +18 -0
  5. package/dist/cjs/identity/index.js +3 -1
  6. package/dist/cjs/identity/seedIdentity.js +16 -0
  7. package/dist/cjs/index.js +4 -2
  8. package/dist/cjs/script/address.js +2 -2
  9. package/dist/cjs/wallet/delegator.js +10 -4
  10. package/dist/cjs/wallet/hdDescriptorProvider.js +29 -0
  11. package/dist/cjs/wallet/inputSignerRouter.js +98 -0
  12. package/dist/cjs/wallet/serviceWorker/wallet.js +1 -0
  13. package/dist/cjs/wallet/signingErrors.js +32 -0
  14. package/dist/cjs/wallet/unroll.js +5 -1
  15. package/dist/cjs/wallet/wallet.js +232 -86
  16. package/dist/cjs/wallet/walletReceiveRotator.js +547 -0
  17. package/dist/cjs/worker/messageBus.js +1 -0
  18. package/dist/esm/adapters/asyncStorage.js +1 -1
  19. package/dist/esm/adapters/expo.js +2 -2
  20. package/dist/esm/adapters/fileSystem.js +1 -1
  21. package/dist/esm/adapters/indexedDB.js +1 -1
  22. package/dist/esm/adapters/localStorage.js +1 -1
  23. package/dist/esm/arkfee/index.js +1 -1
  24. package/dist/esm/arknote/index.js +1 -1
  25. package/dist/esm/bip322/index.js +2 -2
  26. package/dist/esm/contracts/arkcontract.js +2 -2
  27. package/dist/esm/contracts/contractManager.js +36 -16
  28. package/dist/esm/contracts/contractWatcher.js +5 -5
  29. package/dist/esm/contracts/handlers/default.js +4 -4
  30. package/dist/esm/contracts/handlers/delegate.js +4 -4
  31. package/dist/esm/contracts/handlers/helpers.js +2 -2
  32. package/dist/esm/contracts/handlers/index.js +8 -8
  33. package/dist/esm/contracts/handlers/vhtlc.js +3 -3
  34. package/dist/esm/contracts/index.js +8 -8
  35. package/dist/esm/extension/asset/assetGroup.js +7 -7
  36. package/dist/esm/extension/asset/assetId.js +2 -2
  37. package/dist/esm/extension/asset/assetInput.js +2 -2
  38. package/dist/esm/extension/asset/assetOutput.js +1 -1
  39. package/dist/esm/extension/asset/assetRef.js +3 -3
  40. package/dist/esm/extension/asset/index.js +8 -8
  41. package/dist/esm/extension/asset/metadata.js +1 -1
  42. package/dist/esm/extension/asset/packet.js +3 -3
  43. package/dist/esm/extension/index.js +4 -4
  44. package/dist/esm/forfeit.js +2 -2
  45. package/dist/esm/identity/hdCapableIdentity.js +17 -1
  46. package/dist/esm/identity/index.js +6 -5
  47. package/dist/esm/identity/seedIdentity.js +18 -2
  48. package/dist/esm/identity/serialize.js +2 -2
  49. package/dist/esm/identity/singleKey.js +1 -1
  50. package/dist/esm/identity/staticDescriptorProvider.js +2 -2
  51. package/dist/esm/index.js +48 -48
  52. package/dist/esm/intent/index.js +3 -3
  53. package/dist/esm/musig2/index.js +3 -3
  54. package/dist/esm/musig2/sign.js +1 -1
  55. package/dist/esm/providers/ark.js +3 -3
  56. package/dist/esm/providers/delegator.js +1 -1
  57. package/dist/esm/providers/electrum.js +2 -2
  58. package/dist/esm/providers/expoArk.js +2 -2
  59. package/dist/esm/providers/expoIndexer.js +3 -3
  60. package/dist/esm/providers/indexer.js +3 -3
  61. package/dist/esm/repositories/inMemory/walletRepository.js +1 -1
  62. package/dist/esm/repositories/index.js +9 -9
  63. package/dist/esm/repositories/indexedDB/contractRepository.js +4 -4
  64. package/dist/esm/repositories/indexedDB/db.js +2 -2
  65. package/dist/esm/repositories/indexedDB/schema.js +1 -1
  66. package/dist/esm/repositories/indexedDB/walletRepository.js +6 -6
  67. package/dist/esm/repositories/migrations/fromStorageAdapter.js +1 -1
  68. package/dist/esm/repositories/migrations/walletRepositoryImpl.js +1 -1
  69. package/dist/esm/repositories/realm/index.js +3 -3
  70. package/dist/esm/repositories/realm/schemas.js +1 -1
  71. package/dist/esm/repositories/realm/walletRepository.js +3 -3
  72. package/dist/esm/repositories/scriptFromAddress.js +1 -1
  73. package/dist/esm/repositories/sqlite/index.js +2 -2
  74. package/dist/esm/repositories/sqlite/walletRepository.js +3 -3
  75. package/dist/esm/script/address.js +3 -3
  76. package/dist/esm/script/base.js +3 -3
  77. package/dist/esm/script/default.js +2 -2
  78. package/dist/esm/script/delegate.js +3 -3
  79. package/dist/esm/script/tapscript.js +1 -1
  80. package/dist/esm/script/vhtlc.js +2 -2
  81. package/dist/esm/storage/indexedDB.js +1 -1
  82. package/dist/esm/tree/signingSession.js +2 -2
  83. package/dist/esm/tree/validation.js +2 -2
  84. package/dist/esm/utils/arkTransaction.js +7 -7
  85. package/dist/esm/utils/transactionHistory.js +1 -1
  86. package/dist/esm/utils/unknownFields.js +1 -1
  87. package/dist/esm/wallet/asset-manager.js +5 -5
  88. package/dist/esm/wallet/asset.js +1 -1
  89. package/dist/esm/wallet/batch.js +2 -2
  90. package/dist/esm/wallet/delegator.js +16 -10
  91. package/dist/esm/wallet/expo/background.js +5 -5
  92. package/dist/esm/wallet/expo/index.js +2 -2
  93. package/dist/esm/wallet/expo/wallet.js +8 -8
  94. package/dist/esm/wallet/hdDescriptorProvider.js +31 -2
  95. package/dist/esm/wallet/inputSignerRouter.js +94 -0
  96. package/dist/esm/wallet/onchain.js +7 -7
  97. package/dist/esm/wallet/ramps.js +3 -3
  98. package/dist/esm/wallet/serviceWorker/wallet-message-handler.js +6 -6
  99. package/dist/esm/wallet/serviceWorker/wallet.js +8 -7
  100. package/dist/esm/wallet/signingErrors.js +27 -0
  101. package/dist/esm/wallet/unroll.js +12 -8
  102. package/dist/esm/wallet/utils.js +2 -2
  103. package/dist/esm/wallet/validation.js +2 -2
  104. package/dist/esm/wallet/vtxo-manager.js +9 -9
  105. package/dist/esm/wallet/wallet.js +262 -117
  106. package/dist/esm/wallet/walletReceiveRotator.js +540 -0
  107. package/dist/esm/worker/expo/index.js +4 -4
  108. package/dist/esm/worker/expo/processors/contractPollProcessor.js +1 -1
  109. package/dist/esm/worker/expo/processors/index.js +1 -1
  110. package/dist/esm/worker/expo/taskRunner.js +1 -1
  111. package/dist/esm/worker/messageBus.js +7 -6
  112. package/dist/types/adapters/asyncStorage.d.ts +2 -2
  113. package/dist/types/adapters/expo.d.ts +4 -4
  114. package/dist/types/adapters/fileSystem.d.ts +2 -2
  115. package/dist/types/adapters/indexedDB.d.ts +2 -2
  116. package/dist/types/adapters/localStorage.d.ts +2 -2
  117. package/dist/types/arkfee/index.d.ts +2 -2
  118. package/dist/types/arknote/index.d.ts +2 -2
  119. package/dist/types/bip322/index.d.ts +1 -1
  120. package/dist/types/contracts/arkcontract.d.ts +1 -1
  121. package/dist/types/contracts/contractManager.d.ts +39 -9
  122. package/dist/types/contracts/contractWatcher.d.ts +3 -3
  123. package/dist/types/contracts/handlers/default.d.ts +3 -3
  124. package/dist/types/contracts/handlers/delegate.d.ts +3 -3
  125. package/dist/types/contracts/handlers/helpers.d.ts +1 -1
  126. package/dist/types/contracts/handlers/index.d.ts +7 -7
  127. package/dist/types/contracts/handlers/registry.d.ts +1 -1
  128. package/dist/types/contracts/handlers/vhtlc.d.ts +3 -3
  129. package/dist/types/contracts/index.d.ts +14 -14
  130. package/dist/types/contracts/types.d.ts +21 -4
  131. package/dist/types/contracts/vtxoOwnership.d.ts +3 -3
  132. package/dist/types/extension/asset/assetGroup.d.ts +6 -6
  133. package/dist/types/extension/asset/assetId.d.ts +1 -1
  134. package/dist/types/extension/asset/assetInput.d.ts +2 -2
  135. package/dist/types/extension/asset/assetOutput.d.ts +1 -1
  136. package/dist/types/extension/asset/assetRef.d.ts +3 -3
  137. package/dist/types/extension/asset/index.d.ts +8 -8
  138. package/dist/types/extension/asset/metadata.d.ts +1 -1
  139. package/dist/types/extension/asset/packet.d.ts +2 -2
  140. package/dist/types/extension/index.d.ts +6 -6
  141. package/dist/types/forfeit.d.ts +1 -1
  142. package/dist/types/identity/descriptorProvider.d.ts +8 -1
  143. package/dist/types/identity/hdCapableIdentity.d.ts +33 -6
  144. package/dist/types/identity/index.d.ts +12 -11
  145. package/dist/types/identity/seedIdentity.d.ts +21 -5
  146. package/dist/types/identity/serialize.d.ts +1 -1
  147. package/dist/types/identity/singleKey.d.ts +3 -3
  148. package/dist/types/identity/staticDescriptorProvider.d.ts +3 -3
  149. package/dist/types/index.d.ts +59 -59
  150. package/dist/types/intent/index.d.ts +2 -2
  151. package/dist/types/musig2/index.d.ts +4 -4
  152. package/dist/types/providers/ark.d.ts +5 -5
  153. package/dist/types/providers/delegator.d.ts +2 -2
  154. package/dist/types/providers/electrum.d.ts +5 -5
  155. package/dist/types/providers/expoArk.d.ts +1 -1
  156. package/dist/types/providers/expoIndexer.d.ts +1 -1
  157. package/dist/types/providers/indexer.d.ts +1 -1
  158. package/dist/types/providers/onchain.d.ts +2 -2
  159. package/dist/types/repositories/contractRepository.d.ts +1 -1
  160. package/dist/types/repositories/inMemory/contractRepository.d.ts +2 -2
  161. package/dist/types/repositories/inMemory/walletRepository.d.ts +2 -2
  162. package/dist/types/repositories/index.d.ts +9 -9
  163. package/dist/types/repositories/indexedDB/contractRepository.d.ts +2 -2
  164. package/dist/types/repositories/indexedDB/db.d.ts +3 -3
  165. package/dist/types/repositories/indexedDB/walletRepository.d.ts +2 -2
  166. package/dist/types/repositories/migrations/contractRepositoryImpl.d.ts +3 -3
  167. package/dist/types/repositories/migrations/fromStorageAdapter.d.ts +2 -2
  168. package/dist/types/repositories/migrations/walletRepositoryImpl.d.ts +3 -3
  169. package/dist/types/repositories/realm/contractRepository.d.ts +3 -3
  170. package/dist/types/repositories/realm/index.d.ts +4 -4
  171. package/dist/types/repositories/realm/walletRepository.d.ts +3 -3
  172. package/dist/types/repositories/serialization.d.ts +11 -11
  173. package/dist/types/repositories/sqlite/contractRepository.d.ts +3 -3
  174. package/dist/types/repositories/sqlite/index.d.ts +3 -3
  175. package/dist/types/repositories/sqlite/walletRepository.d.ts +3 -3
  176. package/dist/types/repositories/walletRepository.d.ts +1 -1
  177. package/dist/types/script/address.d.ts +2 -2
  178. package/dist/types/script/base.d.ts +2 -2
  179. package/dist/types/script/default.d.ts +2 -2
  180. package/dist/types/script/delegate.d.ts +3 -3
  181. package/dist/types/script/vhtlc.d.ts +2 -2
  182. package/dist/types/storage/asyncStorage.d.ts +1 -1
  183. package/dist/types/storage/fileSystem.d.ts +1 -1
  184. package/dist/types/storage/inMemory.d.ts +1 -1
  185. package/dist/types/storage/indexedDB.d.ts +1 -1
  186. package/dist/types/storage/localStorage.d.ts +1 -1
  187. package/dist/types/tree/signingSession.d.ts +2 -2
  188. package/dist/types/tree/validation.d.ts +1 -1
  189. package/dist/types/utils/arkTransaction.d.ts +5 -5
  190. package/dist/types/utils/syncCursors.d.ts +1 -1
  191. package/dist/types/utils/timelock.d.ts +1 -1
  192. package/dist/types/utils/transaction.d.ts +2 -2
  193. package/dist/types/utils/transactionHistory.d.ts +1 -1
  194. package/dist/types/utils/txSizeEstimator.d.ts +1 -1
  195. package/dist/types/wallet/asset-manager.d.ts +3 -3
  196. package/dist/types/wallet/asset.d.ts +2 -2
  197. package/dist/types/wallet/batch.d.ts +2 -2
  198. package/dist/types/wallet/delegator.d.ts +5 -5
  199. package/dist/types/wallet/expo/background.d.ts +4 -4
  200. package/dist/types/wallet/expo/index.d.ts +4 -4
  201. package/dist/types/wallet/expo/wallet.d.ts +8 -8
  202. package/dist/types/wallet/hdDescriptorProvider.d.ts +26 -5
  203. package/dist/types/wallet/index.d.ts +63 -26
  204. package/dist/types/wallet/inputSignerRouter.d.ts +35 -0
  205. package/dist/types/wallet/onchain.d.ts +6 -6
  206. package/dist/types/wallet/ramps.d.ts +2 -2
  207. package/dist/types/wallet/serviceWorker/wallet-message-handler.d.ts +7 -7
  208. package/dist/types/wallet/serviceWorker/wallet.d.ts +20 -10
  209. package/dist/types/wallet/signingErrors.d.ts +19 -0
  210. package/dist/types/wallet/unroll.d.ts +6 -6
  211. package/dist/types/wallet/utils.d.ts +5 -5
  212. package/dist/types/wallet/validation.d.ts +3 -3
  213. package/dist/types/wallet/vtxo-manager.d.ts +2 -2
  214. package/dist/types/wallet/wallet.d.ts +71 -22
  215. package/dist/types/wallet/walletReceiveRotator.d.ts +306 -0
  216. package/dist/types/worker/expo/asyncStorageTaskQueue.d.ts +1 -1
  217. package/dist/types/worker/expo/index.d.ts +7 -7
  218. package/dist/types/worker/expo/processors/contractPollProcessor.d.ts +1 -1
  219. package/dist/types/worker/expo/processors/index.d.ts +1 -1
  220. package/dist/types/worker/expo/taskRunner.d.ts +7 -7
  221. package/dist/types/worker/messageBus.d.ts +7 -6
  222. package/package.json +2 -2
@@ -1,24 +1,27 @@
1
1
  import { TransactionOutput } from "@scure/btc-signer/psbt.js";
2
2
  import { Bytes } from "@scure/btc-signer/utils.js";
3
- import { ArkAddress } from "../script/address";
4
- import { DefaultVtxo } from "../script/default";
5
- import { Network, NetworkName } from "../networks";
6
- import { OnchainProvider } from "../providers/onchain";
7
- import { ArkProvider, SettlementEvent, SignedIntent } from "../providers/ark";
8
- import { SignerSession } from "../tree/signingSession";
9
- import { Identity, ReadonlyIdentity } from "../identity";
10
- import { ArkTransaction, Coin, ExtendedCoin, ExtendedVirtualCoin, GetVtxosFilter, IAssetManager, IReadonlyAssetManager, IReadonlyWallet, IWallet, ReadonlyWalletConfig, Recipient, SendBitcoinParams, SettleParams, WalletBalance, WalletConfig } from ".";
11
- import { CSVMultisigTapscript, RelativeTimelock } from "../script/tapscript";
12
- import { SettlementConfig, VtxoManager } from "./vtxo-manager";
13
- import { Intent } from "../intent";
14
- import { IndexerProvider } from "../providers/indexer";
15
- import { WalletRepository } from "../repositories/walletRepository";
16
- import { ContractRepository } from "../repositories/contractRepository";
17
- import { Batch } from "./batch";
18
- import { DelegatorProvider } from "../providers/delegator";
19
- import { DelegateVtxo } from "../script/delegate";
20
- import { IDelegatorManager } from "./delegator";
21
- import { ContractManager } from "../contracts/contractManager";
3
+ import { ArkAddress } from "../script/address.js";
4
+ import { DefaultVtxo } from "../script/default.js";
5
+ import { Network, NetworkName } from "../networks.js";
6
+ import { OnchainProvider } from "../providers/onchain.js";
7
+ import { ArkProvider, SettlementEvent, SignedIntent } from "../providers/ark.js";
8
+ import { SignerSession } from "../tree/signingSession.js";
9
+ import { Identity, ReadonlyIdentity } from "../identity/index.js";
10
+ import { ArkTransaction, Coin, ExtendedCoin, ExtendedVirtualCoin, GetVtxosFilter, IAssetManager, IReadonlyAssetManager, IReadonlyWallet, IWallet, ReadonlyWalletConfig, Recipient, SendBitcoinParams, SettleParams, WalletBalance, WalletConfig } from "./index.js";
11
+ import { CSVMultisigTapscript, RelativeTimelock } from "../script/tapscript.js";
12
+ import { SettlementConfig, VtxoManager } from "./vtxo-manager.js";
13
+ import { Intent } from "../intent/index.js";
14
+ import { IndexerProvider } from "../providers/indexer.js";
15
+ import { WalletRepository } from "../repositories/walletRepository.js";
16
+ import { ContractRepository } from "../repositories/contractRepository.js";
17
+ import { Batch } from "./batch.js";
18
+ import { DelegatorProvider } from "../providers/delegator.js";
19
+ import { DelegateVtxo } from "../script/delegate.js";
20
+ import { IDelegatorManager } from "./delegator.js";
21
+ import { ContractManager } from "../contracts/contractManager.js";
22
+ import { WalletReceiveRotator } from "./walletReceiveRotator.js";
23
+ import { DescriptorProvider } from "../identity/descriptorProvider.js";
24
+ import { DescriptorSigningProviderMissingError, MissingSigningDescriptorError } from "./signingErrors.js";
22
25
  export declare const getArkadeServerUrl: ({ arkServerUrl, }: {
23
26
  arkServerUrl?: string;
24
27
  }) => string;
@@ -30,13 +33,13 @@ export type IncomingFunds = {
30
33
  newVtxos: ExtendedVirtualCoin[];
31
34
  spentVtxos: ExtendedVirtualCoin[];
32
35
  };
36
+ export { DescriptorSigningProviderMissingError, MissingSigningDescriptorError };
33
37
  export declare class ReadonlyWallet implements IReadonlyWallet {
34
38
  readonly identity: ReadonlyIdentity;
35
39
  readonly network: Network;
36
40
  readonly onchainProvider: OnchainProvider;
37
41
  readonly indexerProvider: IndexerProvider;
38
42
  readonly arkServerPublicKey: Bytes;
39
- readonly offchainTapscript: DefaultVtxo.Script | DelegateVtxo.Script;
40
43
  readonly boardingTapscript: DefaultVtxo.Script;
41
44
  readonly dustAmount: bigint;
42
45
  readonly walletRepository: WalletRepository;
@@ -50,7 +53,20 @@ export declare class ReadonlyWallet implements IReadonlyWallet {
50
53
  readonly walletContractTimelocks: RelativeTimelock[];
51
54
  protected _pendingSpendOutpoints: Set<string>;
52
55
  get assetManager(): IReadonlyAssetManager;
56
+ /**
57
+ * Backing field for the active receive tapscript. Read via the
58
+ * public `offchainTapscript` getter; written only by
59
+ * {@link Wallet.setOffchainTapscriptForRotation}, which
60
+ * {@link WalletReceiveRotator.rotate} is the sole intended caller of.
61
+ */
62
+ protected _offchainTapscript: DefaultVtxo.Script | DelegateVtxo.Script;
53
63
  protected constructor(identity: ReadonlyIdentity, network: Network, onchainProvider: OnchainProvider, indexerProvider: IndexerProvider, arkServerPublicKey: Bytes, offchainTapscript: DefaultVtxo.Script | DelegateVtxo.Script, boardingTapscript: DefaultVtxo.Script, dustAmount: bigint, walletRepository: WalletRepository, contractRepository: ContractRepository, delegatorProvider?: DelegatorProvider | undefined, watcherConfig?: ReadonlyWalletConfig["watcherConfig"], walletContractTimelocks?: RelativeTimelock[]);
64
+ /**
65
+ * Currently-active receive tapscript. Read-only from the outside;
66
+ * mutated only via {@link Wallet.setOffchainTapscriptForRotation}
67
+ * by {@link WalletReceiveRotator.rotate}.
68
+ */
69
+ get offchainTapscript(): DefaultVtxo.Script | DelegateVtxo.Script;
54
70
  /**
55
71
  * Protected helper to set up shared wallet configuration.
56
72
  * Extracts common logic used by both ReadonlyWallet.create() and Wallet.create().
@@ -67,7 +83,7 @@ export declare class ReadonlyWallet implements IReadonlyWallet {
67
83
  dustAmount: bigint;
68
84
  walletRepository: WalletRepository;
69
85
  contractRepository: ContractRepository;
70
- info: import("../providers/ark").ArkInfo;
86
+ info: import("../providers/ark.js").ArkInfo;
71
87
  delegatorProvider: DelegatorProvider | undefined;
72
88
  walletContractTimelocks: RelativeTimelock[];
73
89
  }>;
@@ -215,6 +231,32 @@ export declare class Wallet extends ReadonlyWallet implements IWallet {
215
231
  private _vtxoManager?;
216
232
  private _vtxoManagerInitializing?;
217
233
  private _walletAssetManager?;
234
+ /**
235
+ * HD receive rotator. Owns the {@link DescriptorProvider}, the
236
+ * `vtxo_received` subscription, and the rotate-and-register
237
+ * lifecycle. Absent in `walletMode: 'static'` and for SingleKey
238
+ * wallets under `'auto'`. Wired in via the constructor; the actual
239
+ * subscription is installed lazily on first `getVtxoManager()` so
240
+ * the contract manager is up first.
241
+ */
242
+ private _receiveRotator?;
243
+ private _receiveRotatorInstalled;
244
+ /**
245
+ * Descriptor-aware signer used by {@link _signerRouter} to sign
246
+ * inputs locked by rotated pubkeys. Same instance the rotator owns;
247
+ * stashed here so the spending paths don't have to reach inside the
248
+ * rotator. Undefined for static / non-HD-capable wallets — those
249
+ * paths only ever take the identity-sign branch.
250
+ */
251
+ private readonly _descriptorProvider?;
252
+ private readonly _signerRouter;
253
+ /**
254
+ * @internal Sole write path for `offchainTapscript` after construction.
255
+ * Called by {@link WalletReceiveRotator.rotate} once the rotated
256
+ * display contract has been persisted. External code must treat
257
+ * `offchainTapscript` as read-only.
258
+ */
259
+ setOffchainTapscriptForRotation(tapscript: DefaultVtxo.Script | DelegateVtxo.Script): void;
218
260
  /**
219
261
  * Async mutex that serializes all operations submitting VTXOs to the Arkade
220
262
  * server (`settle`, `send`, `sendBitcoin`). This prevents VtxoManager's
@@ -233,7 +275,7 @@ export declare class Wallet extends ReadonlyWallet implements IWallet {
233
275
  readonly settlementConfig: SettlementConfig | false;
234
276
  protected constructor(identity: Identity, network: Network, onchainProvider: OnchainProvider, arkProvider: ArkProvider, indexerProvider: IndexerProvider, arkServerPublicKey: Bytes, offchainTapscript: DefaultVtxo.Script | DelegateVtxo.Script, boardingTapscript: DefaultVtxo.Script, serverUnrollScript: CSVMultisigTapscript.Type, forfeitOutputScript: Bytes, forfeitPubkey: Bytes, dustAmount: bigint, walletRepository: WalletRepository, contractRepository: ContractRepository,
235
277
  /** @deprecated Use settlementConfig */
236
- renewalConfig?: WalletConfig["renewalConfig"], delegatorProvider?: DelegatorProvider, watcherConfig?: WalletConfig["watcherConfig"], settlementConfig?: WalletConfig["settlementConfig"], walletContractTimelocks?: RelativeTimelock[]);
278
+ renewalConfig?: WalletConfig["renewalConfig"], delegatorProvider?: DelegatorProvider, watcherConfig?: WalletConfig["watcherConfig"], settlementConfig?: WalletConfig["settlementConfig"], walletContractTimelocks?: RelativeTimelock[], receiveRotator?: WalletReceiveRotator, descriptorProvider?: DescriptorProvider);
237
279
  get assetManager(): IAssetManager;
238
280
  getVtxoManager(): Promise<VtxoManager>;
239
281
  dispose(): Promise<void>;
@@ -297,6 +339,13 @@ export declare class Wallet extends ReadonlyWallet implements IWallet {
297
339
  * @param session - Optional musig2 signing session. When omitted, signing steps are skipped.
298
340
  */
299
341
  createBatchHandler(intentId: string, inputs: ExtendedCoin[], expectedRecipients: Recipient[], session?: SignerSession): Batch.Handler;
342
+ /**
343
+ * Build {@link InputSigningJob}s for a tx whose signable inputs can be
344
+ * resolved from their own `witnessUtxo.script`. Inputs without a
345
+ * `witnessUtxo` are silently omitted, mirroring the wallet's
346
+ * historical silent-skip behaviour for cosigner/connector inputs.
347
+ */
348
+ private inputSigningJobsFromWitnessUtxos;
300
349
  safeRegisterIntent(intent: SignedIntent<Intent.RegisterMessage>, inputs: ExtendedCoin[]): Promise<string>;
301
350
  makeRegisterIntentSignature(coins: ExtendedCoin[], outputs: TransactionOutput[], onchainOutputsIndexes: number[], cosignerPubKeys: string[], validAt?: number): Promise<SignedIntent<Intent.RegisterMessage>>;
302
351
  makeDeleteIntentSignature(coins: ExtendedCoin[]): Promise<SignedIntent<Intent.DeleteMessage>>;
@@ -0,0 +1,306 @@
1
+ import { DescriptorProvider } from "../identity/descriptorProvider.js";
2
+ import { ContractRepository } from "../repositories/contractRepository.js";
3
+ import { WalletRepository } from "../repositories/walletRepository.js";
4
+ import { IContractManager } from "../contracts/contractManager.js";
5
+ import { DefaultVtxo } from "../script/default.js";
6
+ import { DelegateVtxo } from "../script/delegate.js";
7
+ import type { WalletConfig } from "./index.js";
8
+ /**
9
+ * Inputs the wallet hands to a {@link ReceiveRotatorFactory} when
10
+ * asking it to construct the rotator at boot. The factory uses these
11
+ * to look up the wallet's current display contract (or allocate a
12
+ * fresh receive descriptor). Note: no `offchainTapscript` here — the
13
+ * factory's job is allocation, not script construction. The wallet's
14
+ * orchestrator (`WalletReceiveRotator.resolveBoot`) handles the
15
+ * tapscript rebuild on top of the factory's result.
16
+ */
17
+ export interface ReceiveRotatorBootOpts {
18
+ walletRepository: WalletRepository;
19
+ contractRepository: ContractRepository;
20
+ serverPubKey: Uint8Array;
21
+ /**
22
+ * Expected contract family ("default" or "delegate"). When provided,
23
+ * boot will only consider contracts of this type when looking up the
24
+ * wallet's current display contract, preventing a default wallet from
25
+ * accidentally picking up a delegate contract or vice versa.
26
+ */
27
+ expectedContractType?: "default" | "delegate";
28
+ /**
29
+ * Logger to receive rotation-failure + backoff diagnostics. Defaults
30
+ * to `console` when omitted. Any object implementing
31
+ * {@link Logger.error} works (winston, pino, Sentry breadcrumbs,
32
+ * the runtime's own logger).
33
+ */
34
+ logger?: Logger;
35
+ }
36
+ /**
37
+ * Output of {@link ReceiveRotatorFactory.createReceiveRotator}: the
38
+ * constructed rotator paired with the receive pubkey it resolved at
39
+ * boot (either the existing tagged display contract's pubkey, or a
40
+ * freshly allocated one).
41
+ */
42
+ export interface ReceiveRotatorBoot {
43
+ rotator: WalletReceiveRotator;
44
+ receivePubkey: Uint8Array;
45
+ }
46
+ /**
47
+ * Result returned by {@link WalletReceiveRotator.resolveBoot} to the
48
+ * wallet: the rotator plus the offchain tapscript the wallet should
49
+ * actually use (rebuilt to the resolved boot pubkey when it differs
50
+ * from the identity's static pubkey), plus the {@link DescriptorProvider}
51
+ * the rotator was built around. The wallet retains the provider so
52
+ * spending paths can route per-input signing through
53
+ * {@link DescriptorProvider.signWithDescriptor} instead of the
54
+ * identity's index-0 key.
55
+ */
56
+ export interface ReceiveRotatorBootResult {
57
+ rotator: WalletReceiveRotator;
58
+ offchainTapscript: DefaultVtxo.Script | DelegateVtxo.Script;
59
+ provider: DescriptorProvider;
60
+ }
61
+ /**
62
+ * Opt-in extension to {@link DescriptorProvider} for providers that
63
+ * drive HD receive rotation. Implemented by {@link HDDescriptorProvider}
64
+ * out of the box; custom providers (HSMs, external signers, …) can also
65
+ * implement it when they want to participate.
66
+ *
67
+ * Kept out of the core `DescriptorProvider` interface so providers that
68
+ * only do allocation + signing don't have to know about the wallet's
69
+ * receive lifecycle. The wallet detects support via
70
+ * {@link hasReceiveRotatorFactory} (a duck-typed `instanceof`-style
71
+ * check) and falls back to {@link WalletReceiveRotator.defaultBoot}
72
+ * when the provider doesn't implement the extension.
73
+ */
74
+ export interface ReceiveRotatorFactory {
75
+ createReceiveRotator(opts: ReceiveRotatorBootOpts): Promise<ReceiveRotatorBoot | undefined>;
76
+ }
77
+ /** Type guard: does this provider implement {@link ReceiveRotatorFactory}? */
78
+ export declare function hasReceiveRotatorFactory(provider: DescriptorProvider): provider is DescriptorProvider & ReceiveRotatorFactory;
79
+ /**
80
+ * Sentinel value stored in `contract.metadata.source` to identify the
81
+ * wallet's current display contract. Borrowed from btcpay-arkade's
82
+ * source-tagging pattern: every contract records "where and why it was
83
+ * generated", and the wallet only cares about the ones it generated for
84
+ * its own receive address.
85
+ *
86
+ * Tagging makes the boot lookup unambiguous — the rotator filters on
87
+ * `metadata.source === WALLET_RECEIVE_SOURCE` rather than on "any active
88
+ * default contract", so a contract repo that also holds default contracts
89
+ * created for other reasons (legacy timelock variants, external
90
+ * integrations) doesn't confuse the wallet's display state.
91
+ */
92
+ export declare const WALLET_RECEIVE_SOURCE = "wallet-receive";
93
+ /**
94
+ * Thrown when a descriptor expected to be rangeable (have a wildcard
95
+ * leaf) cannot produce a leaf pubkey. Surfaces from the rotator's
96
+ * `defaultBoot` path so `resolveBoot` can distinguish a legitimate
97
+ * incompatibility (silent fallback under `walletMode: 'auto'`) from
98
+ * any other runtime failure.
99
+ */
100
+ export declare class NonRangeableDescriptorError extends Error {
101
+ constructor(message: string, options?: {
102
+ cause?: unknown;
103
+ });
104
+ }
105
+ /**
106
+ * Minimal logging surface the rotator needs. `console` satisfies it
107
+ * out of the box; SDK consumers can pass a structured logger
108
+ * (winston / pino / Sentry adapter) via {@link ReceiveRotatorBootOpts}
109
+ * to capture rotation failures + backoff diagnostics through their
110
+ * own pipeline.
111
+ */
112
+ export interface Logger {
113
+ error(message: string, ...args: unknown[]): void;
114
+ }
115
+ /**
116
+ * Cap on the exponential backoff applied to repeated rotation
117
+ * failures. After this delay, every fresh `vtxo_received` event
118
+ * re-attempts a rotation at this rate until one succeeds (which
119
+ * resets the counter) or the wallet is disposed.
120
+ */
121
+ export declare const ROTATION_MAX_BACKOFF_MS = 60000;
122
+ /**
123
+ * Narrow surface the rotator needs from the wallet at runtime: the
124
+ * mutable display tapscript, the display contract's script hex, the
125
+ * contract manager (for subscribing + registering rotated contracts),
126
+ * and the display address (for the contract's `address` field).
127
+ *
128
+ * Kept as an interface so the rotator module avoids a circular
129
+ * dependency on `wallet.ts`. `Wallet` implements this surface
130
+ * structurally — no `implements` clause is required.
131
+ */
132
+ export interface RotatableWallet {
133
+ readonly defaultContractScript: string;
134
+ readonly network: {
135
+ hrp: string;
136
+ };
137
+ readonly arkServerPublicKey: Uint8Array;
138
+ readonly offchainTapscript: DefaultVtxo.Script | DelegateVtxo.Script;
139
+ /**
140
+ * @internal Sole sanctioned write path for `offchainTapscript`
141
+ * after construction. The rotator calls this once per rotation
142
+ * after persisting the new display contract.
143
+ */
144
+ setOffchainTapscriptForRotation(tapscript: DefaultVtxo.Script | DelegateVtxo.Script): void;
145
+ getContractManager(): Promise<IContractManager>;
146
+ getAddress(): Promise<string>;
147
+ }
148
+ /**
149
+ * Owns the wallet's HD receive-rotation lifecycle.
150
+ *
151
+ * The rotator is constructed only when the wallet's `walletMode`
152
+ * resolves to a {@link DescriptorProvider}; static wallets and
153
+ * non-HD-capable wallets under `'auto'` never see one.
154
+ *
155
+ * Lifecycle:
156
+ * 1. `resolveBoot()` — pre-Wallet-construction. Resolves the provider
157
+ * from `walletMode`, then either reuses the existing display
158
+ * contract's pubkey (if any) or allocates the first descriptor.
159
+ * Returns the rotator paired with the boot pubkey.
160
+ * 2. `install(wallet)` — post-`getVtxoManager()`. Subscribes to
161
+ * `vtxo_received` on the contract manager and routes matching events
162
+ * through the rotation chain.
163
+ * 3. `dispose()` — tears down the subscription and drains any in-flight
164
+ * rotation so the contract manager can be disposed cleanly.
165
+ *
166
+ * This class follows the dotnet-sdk's split of responsibilities: the
167
+ * provider is a pure rotating allocator; "what address am I currently
168
+ * bound to?" is answered by querying the contract repository, not by
169
+ * asking the provider.
170
+ */
171
+ export declare class WalletReceiveRotator {
172
+ private readonly provider;
173
+ private unsubscribe?;
174
+ private chain;
175
+ /**
176
+ * Script of the most-recent tagged display contract — populated
177
+ * either from the boot-time repo lookup or from the previous
178
+ * `rotate()` call within this session. The next `rotate()` marks
179
+ * this contract `inactive` once the new tagged contract is in
180
+ * place. `undefined` means the wallet's current display is the
181
+ * untagged index-0 baseline (no rotation has happened yet on this
182
+ * repo), and the baseline must NOT be deactivated.
183
+ */
184
+ private currentTaggedScript;
185
+ /**
186
+ * Consecutive rotation failures since the last successful rotate.
187
+ * Drives an exponential backoff (capped at
188
+ * {@link ROTATION_MAX_BACKOFF_MS}) so a broken provider can't make
189
+ * the rotator hammer `getNextSigningDescriptor` + `createContract`
190
+ * on every inbound VTXO. Reset to zero on a successful rotate.
191
+ */
192
+ private consecutiveFailures;
193
+ /**
194
+ * Unix-ms timestamp before which incoming `vtxo_received` events
195
+ * skip the rotation attempt entirely. Zero means "no backoff
196
+ * active" — the next event can rotate immediately.
197
+ */
198
+ private nextRotationAllowedAt;
199
+ private readonly logger;
200
+ private constructor();
201
+ /**
202
+ * Phase 1 — pre-Wallet-construction. Resolves `walletMode` to a
203
+ * {@link DescriptorProvider}, then asks that provider to construct
204
+ * the rotator (delegated through
205
+ * {@link DescriptorProvider.createReceiveRotator}, which falls back
206
+ * to {@link defaultBoot} when the provider doesn't override it).
207
+ *
208
+ * Returns the rotator paired with the offchain tapscript the wallet
209
+ * should actually install (rebuilt to the resolved receive pubkey
210
+ * when it differs from the identity's static pubkey), or
211
+ * `undefined` when the wallet should stay on the static path.
212
+ *
213
+ * Errors during pubkey resolution propagate when:
214
+ * - `walletMode === 'hd'` (caller asked for HD; loud failure expected).
215
+ * - `walletMode` is a {@link DescriptorProvider} (caller supplied an
216
+ * explicit allocator; silently degrading would hide misconfig).
217
+ *
218
+ * Errors are silently swallowed (returning `undefined`) only under
219
+ * `walletMode: 'auto'` with the built-in HD provider, to preserve
220
+ * backwards compatibility with wallets whose identity descriptor
221
+ * isn't actually rangeable.
222
+ */
223
+ static resolveBoot(config: WalletConfig, setup: ReceiveRotatorBootOpts & {
224
+ offchainTapscript: DefaultVtxo.Script | DelegateVtxo.Script;
225
+ }): Promise<ReceiveRotatorBootResult | undefined>;
226
+ /**
227
+ * Default factory-shaped boot any
228
+ * {@link ReceiveRotatorFactory.createReceiveRotator} implementation
229
+ * can delegate to. Pulls the wallet's current display contract from
230
+ * the contract repository (or allocates a fresh receive descriptor
231
+ * via the provider when no tagged display contract exists), and
232
+ * returns the rotator paired with the resolved receive pubkey.
233
+ *
234
+ * Used internally by `resolveBoot` when the provider doesn't
235
+ * implement {@link ReceiveRotatorFactory}. Exported so providers
236
+ * that *do* override can still invoke the default work for the
237
+ * parts of the boot path they don't want to customise. Tapscript
238
+ * construction is intentionally NOT in here — that's the
239
+ * orchestrator's job.
240
+ */
241
+ static defaultBoot(provider: DescriptorProvider, opts: ReceiveRotatorBootOpts): Promise<ReceiveRotatorBoot>;
242
+ /**
243
+ * Phase 2 — post-`getVtxoManager()`. Subscribe to `vtxo_received`
244
+ * and trigger a rotation whenever the currently-active display
245
+ * contract receives funds. Old display contracts remain `active`
246
+ * in the repo so earlier shared addresses keep crediting this
247
+ * wallet.
248
+ */
249
+ install(wallet: RotatableWallet): Promise<void>;
250
+ /**
251
+ * Run a single rotation attempt, applying exponential backoff on
252
+ * failure. Public-shaped behavior:
253
+ * - During a backoff window: log + skip (no `rotate()` call).
254
+ * - On success: reset failure count and backoff.
255
+ * - On failure: increment counter, schedule next attempt at
256
+ * `min(2^consecutiveFailures * 1s, ROTATION_MAX_BACKOFF_MS)`.
257
+ *
258
+ * Errors are deliberately swallowed (logged, not rethrown) so the
259
+ * surrounding `chain` Promise never settles to rejected — the next
260
+ * `vtxo_received` event must still get a chance to run.
261
+ */
262
+ private runRotateWithBackoff;
263
+ /**
264
+ * Wait for any in-flight rotation to complete. Useful in tests
265
+ * that need to observe the post-rotation state after dispatching
266
+ * a `vtxo_received` event synchronously; production code rarely
267
+ * needs to call this directly.
268
+ */
269
+ drain(): Promise<void>;
270
+ /**
271
+ * Tear down the subscription first so no late `vtxo_received` event
272
+ * can queue work on a disposing wallet, then drain any in-flight
273
+ * rotation so its `createContract` finishes before the contract
274
+ * manager itself disposes.
275
+ */
276
+ dispose(): Promise<void>;
277
+ /**
278
+ * Allocate the next descriptor, swap it into the wallet's active
279
+ * offchain tapscript, register the new tagged contract, and retire
280
+ * the previous tagged contract (if any) by setting its state to
281
+ * `inactive`. The contract watcher keeps watching inactive
282
+ * contracts until their VTXOs are spent, so funds in flight at the
283
+ * old display address are not lost — only the address stops being
284
+ * advertised.
285
+ *
286
+ * Contract type matches the wallet's tapscript shape: a default
287
+ * wallet rotates to a new `default` contract, a delegate wallet to
288
+ * a new `delegate` contract.
289
+ *
290
+ * The first rotation on a fresh wallet does NOT deactivate
291
+ * anything: `currentTaggedScript` is `undefined` because the wallet
292
+ * was displaying the untagged index-0 baseline, which must stay
293
+ * active forever.
294
+ */
295
+ private rotate;
296
+ }
297
+ /**
298
+ * Rebuild the given offchain tapscript with a different owner pubkey,
299
+ * preserving its {@link DelegateVtxo.Script} vs {@link DefaultVtxo.Script}
300
+ * shape and all other options.
301
+ *
302
+ * Exported because the wallet's boot path also needs to rebuild the
303
+ * initial tapscript when the resolved boot pubkey differs from the
304
+ * identity's default pubkey.
305
+ */
306
+ export declare function rebuildTapscript(current: DefaultVtxo.Script | DelegateVtxo.Script, pubKey: Uint8Array): DefaultVtxo.Script | DelegateVtxo.Script;
@@ -1,4 +1,4 @@
1
- import type { TaskItem, TaskResult, TaskQueue } from "./taskQueue";
1
+ import type { TaskItem, TaskResult, TaskQueue } from "./taskQueue.js";
2
2
  /**
3
3
  * Minimal async key-value storage interface.
4
4
  *
@@ -1,7 +1,7 @@
1
- export type { TaskItem, TaskResult, TaskQueue } from "./taskQueue";
2
- export { InMemoryTaskQueue } from "./taskQueue";
3
- export type { AsyncStorageLike } from "./asyncStorageTaskQueue";
4
- export { AsyncStorageTaskQueue } from "./asyncStorageTaskQueue";
5
- export type { TaskProcessor, TaskDependencies, CreateTaskDependenciesOptions, } from "./taskRunner";
6
- export { runTasks, createTaskDependencies } from "./taskRunner";
7
- export { contractPollProcessor, CONTRACT_POLL_TASK_TYPE } from "./processors";
1
+ export type { TaskItem, TaskResult, TaskQueue } from "./taskQueue.js";
2
+ export { InMemoryTaskQueue } from "./taskQueue.js";
3
+ export type { AsyncStorageLike } from "./asyncStorageTaskQueue.js";
4
+ export { AsyncStorageTaskQueue } from "./asyncStorageTaskQueue.js";
5
+ export type { TaskProcessor, TaskDependencies, CreateTaskDependenciesOptions, } from "./taskRunner.js";
6
+ export { runTasks, createTaskDependencies } from "./taskRunner.js";
7
+ export { contractPollProcessor, CONTRACT_POLL_TASK_TYPE } from "./processors/index.js";
@@ -1,4 +1,4 @@
1
- import type { TaskProcessor } from "../taskRunner";
1
+ import type { TaskProcessor } from "../taskRunner.js";
2
2
  export declare const CONTRACT_POLL_TASK_TYPE = "contract-poll";
3
3
  /**
4
4
  * Polls the indexer for the latest VTXO state of every contract and
@@ -1 +1 @@
1
- export { contractPollProcessor, CONTRACT_POLL_TASK_TYPE, } from "./contractPollProcessor";
1
+ export { contractPollProcessor, CONTRACT_POLL_TASK_TYPE, } from "./contractPollProcessor.js";
@@ -1,10 +1,10 @@
1
- import type { TaskItem, TaskResult, TaskQueue } from "./taskQueue";
2
- import type { WalletRepository } from "../../repositories/walletRepository";
3
- import type { ContractRepository } from "../../repositories/contractRepository";
4
- import type { IndexerProvider } from "../../providers/indexer";
5
- import type { ArkProvider } from "../../providers/ark";
6
- import type { ExtendedVirtualCoin, VirtualCoin } from "../../wallet";
7
- import type { Contract } from "../../contracts/types";
1
+ import type { TaskItem, TaskResult, TaskQueue } from "./taskQueue.js";
2
+ import type { WalletRepository } from "../../repositories/walletRepository.js";
3
+ import type { ContractRepository } from "../../repositories/contractRepository.js";
4
+ import type { IndexerProvider } from "../../providers/indexer.js";
5
+ import type { ArkProvider } from "../../providers/ark.js";
6
+ import type { ExtendedVirtualCoin, VirtualCoin } from "../../wallet/index.js";
7
+ import type { Contract } from "../../contracts/types.js";
8
8
  /**
9
9
  * Shared dependencies injected into every processor at runtime.
10
10
  *
@@ -1,9 +1,9 @@
1
- import { ArkProvider } from "../providers/ark";
2
- import { type SerializedIdentity, type LegacySerializedIdentity } from "../identity";
3
- import { ReadonlyWallet, Wallet } from "../wallet/wallet";
4
- import type { SettlementConfig } from "../wallet/vtxo-manager";
5
- import type { ContractWatcherConfig } from "../contracts/contractWatcher";
6
- import { ContractRepository, WalletRepository } from "../repositories";
1
+ import { ArkProvider } from "../providers/ark.js";
2
+ import { type SerializedIdentity, type LegacySerializedIdentity } from "../identity/index.js";
3
+ import { ReadonlyWallet, Wallet } from "../wallet/wallet.js";
4
+ import type { SettlementConfig } from "../wallet/vtxo-manager.js";
5
+ import type { ContractWatcherConfig } from "../contracts/contractWatcher.js";
6
+ import { ContractRepository, WalletRepository } from "../repositories/index.js";
7
7
  export type RequestEnvelope = {
8
8
  tag: string;
9
9
  id: string;
@@ -89,6 +89,7 @@ type Initialize = {
89
89
  indexerUrl?: string;
90
90
  esploraUrl?: string;
91
91
  settlementConfig?: SettlementConfig | false;
92
+ walletMode?: "auto" | "static" | "hd";
92
93
  watcherConfig?: Partial<Omit<ContractWatcherConfig, "indexerProvider">>;
93
94
  /**
94
95
  * Page-supplied per-operation timeout map. Keys are message types
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arkade-os/sdk",
3
- "version": "0.4.25",
3
+ "version": "0.4.27",
4
4
  "description": "TypeScript SDK for building Bitcoin wallets using the Arkade protocol",
5
5
  "type": "module",
6
6
  "main": "./dist/cjs/index.js",
@@ -153,7 +153,7 @@
153
153
  "pnpm": ">=10.25.0 <11"
154
154
  },
155
155
  "scripts": {
156
- "build": "rimraf dist && pnpm run build:esm && pnpm run build:expo:esm && node scripts/add-extensions.js && pnpm run build:cjs && pnpm run build:expo:cjs && pnpm run build:types && pnpm run build:expo:types && node scripts/generate-package-files.js",
156
+ "build": "rimraf dist && pnpm run build:esm && pnpm run build:expo:esm && pnpm run build:cjs && pnpm run build:expo:cjs && pnpm run build:types && pnpm run build:expo:types && node scripts/add-extensions.js && node scripts/generate-package-files.js",
157
157
  "build:esm": "tsc -p tsconfig.esm.json --outDir dist/esm",
158
158
  "build:cjs": "tsc -p tsconfig.cjs.json --outDir dist/cjs",
159
159
  "build:types": "tsc -p tsconfig.json --outDir dist/types --emitDeclarationOnly",