@arkade-os/sdk 0.4.20 → 0.4.21

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.
@@ -153,62 +153,75 @@ export class RestIndexerProvider {
153
153
  }
154
154
  return data;
155
155
  }
156
- async *getSubscription(subscriptionId, abortSignal) {
156
+ getSubscription(subscriptionId, abortSignal) {
157
157
  const url = `${this.serverUrl}/v1/indexer/script/subscription/${subscriptionId}`;
158
- while (!abortSignal?.aborted) {
158
+ let iterator = null;
159
+ const closeIterator = () => iterator?.close();
160
+ const gen = (async function* () {
161
+ const abortHandler = closeIterator;
162
+ abortSignal?.addEventListener("abort", abortHandler);
159
163
  try {
160
- const eventSource = new EventSource(url);
161
- // Set up abort handling
162
- const abortHandler = () => {
163
- eventSource.close();
164
- };
165
- abortSignal?.addEventListener("abort", abortHandler);
166
- try {
167
- for await (const event of eventSourceIterator(eventSource)) {
168
- if (abortSignal?.aborted)
169
- break;
170
- try {
171
- const data = JSON.parse(event.data);
172
- if (data.event) {
173
- yield {
174
- txid: data.event.txid,
175
- scripts: data.event.scripts || [],
176
- newVtxos: (data.event.newVtxos || []).map(convertVtxo),
177
- spentVtxos: (data.event.spentVtxos || []).map(convertVtxo),
178
- sweptVtxos: (data.event.sweptVtxos || []).map(convertVtxo),
179
- tx: data.event.tx,
180
- checkpointTxs: data.event.checkpointTxs,
181
- };
164
+ while (!abortSignal?.aborted) {
165
+ try {
166
+ const currentIterator = eventSourceIterator(new EventSource(url));
167
+ iterator = currentIterator;
168
+ for await (const event of currentIterator) {
169
+ if (abortSignal?.aborted)
170
+ break;
171
+ try {
172
+ const data = JSON.parse(event.data);
173
+ if (data.event) {
174
+ yield {
175
+ txid: data.event.txid,
176
+ scripts: data.event.scripts || [],
177
+ newVtxos: (data.event.newVtxos || []).map(convertVtxo),
178
+ spentVtxos: (data.event.spentVtxos || []).map(convertVtxo),
179
+ sweptVtxos: (data.event.sweptVtxos || []).map(convertVtxo),
180
+ tx: data.event.tx,
181
+ checkpointTxs: data.event.checkpointTxs,
182
+ };
183
+ }
184
+ }
185
+ catch (err) {
186
+ console.error("Failed to parse subscription event:", err);
187
+ throw err;
182
188
  }
183
189
  }
184
- catch (err) {
185
- console.error("Failed to parse subscription event:", err);
186
- throw err;
190
+ }
191
+ catch (error) {
192
+ if (abortSignal?.aborted ||
193
+ (error instanceof Error &&
194
+ error.name === "AbortError")) {
195
+ break;
187
196
  }
197
+ // ignore timeout errors, they're expected when the server is not sending anything for 5 min
198
+ if (isFetchTimeoutError(error)) {
199
+ console.debug("Timeout error ignored");
200
+ continue;
201
+ }
202
+ if (isEventSourceError(error)) {
203
+ throw error;
204
+ }
205
+ console.error("Subscription error:", error);
206
+ throw error;
207
+ }
208
+ finally {
209
+ closeIterator();
210
+ iterator = null;
188
211
  }
189
- }
190
- finally {
191
- abortSignal?.removeEventListener("abort", abortHandler);
192
- eventSource.close();
193
212
  }
194
213
  }
195
- catch (error) {
196
- if (abortSignal?.aborted ||
197
- (error instanceof Error && error.name === "AbortError")) {
198
- break;
199
- }
200
- // ignore timeout errors, they're expected when the server is not sending anything for 5 min
201
- if (isFetchTimeoutError(error)) {
202
- console.debug("Timeout error ignored");
203
- continue;
204
- }
205
- if (isEventSourceError(error)) {
206
- throw error;
207
- }
208
- console.error("Subscription error:", error);
209
- throw error;
214
+ finally {
215
+ abortSignal?.removeEventListener("abort", abortHandler);
216
+ closeIterator();
210
217
  }
211
- }
218
+ })();
219
+ const origReturn = gen.return.bind(gen);
220
+ gen.return = (value) => {
221
+ closeIterator();
222
+ return origReturn(value);
223
+ };
224
+ return gen;
212
225
  }
213
226
  async getVirtualTxs(txids, opts) {
214
227
  let url = `${this.serverUrl}/v1/indexer/virtualTx/${txids.join(",")}`;
@@ -1,29 +1,67 @@
1
+ function createAbortError() {
2
+ const error = new Error("EventSource closed");
3
+ error.name = "AbortError";
4
+ return error;
5
+ }
1
6
  /**
2
- * Creates an async iterator over EventSource messages that attaches listeners
3
- * eagerly (at call time) rather than lazily (at first .next() call).
4
- * This ensures events are buffered immediately, preventing race conditions
5
- * where events arrive before iteration begins.
7
+ * Creates a close-aware EventSource async iterator.
8
+ *
9
+ * Listeners attach eagerly so events are buffered before the first next() call.
10
+ * close() closes the EventSource, removes listeners, and wakes any pending
11
+ * next() even when the browser does not emit an error from EventSource.close().
6
12
  */
7
13
  export function eventSourceIterator(eventSource) {
8
14
  const messageQueue = [];
9
15
  const errorQueue = [];
10
16
  let messageResolve = null;
11
17
  let errorResolve = null;
18
+ let closed = false;
19
+ let cleanedUp = false;
20
+ const cleanup = () => {
21
+ if (cleanedUp)
22
+ return;
23
+ cleanedUp = true;
24
+ eventSource.removeEventListener("message", messageHandler);
25
+ eventSource.removeEventListener("error", errorHandler);
26
+ };
27
+ const close = () => {
28
+ if (closed)
29
+ return;
30
+ closed = true;
31
+ messageQueue.length = 0;
32
+ errorQueue.length = 0;
33
+ eventSource.close();
34
+ cleanup();
35
+ if (errorResolve) {
36
+ const reject = errorResolve;
37
+ messageResolve = null;
38
+ errorResolve = null;
39
+ reject(createAbortError());
40
+ }
41
+ };
12
42
  const messageHandler = (event) => {
43
+ if (closed)
44
+ return;
13
45
  if (messageResolve) {
14
- messageResolve(event);
46
+ const resolve = messageResolve;
15
47
  messageResolve = null;
48
+ errorResolve = null;
49
+ resolve(event);
16
50
  }
17
51
  else {
18
52
  messageQueue.push(event);
19
53
  }
20
54
  };
21
55
  const errorHandler = () => {
56
+ if (closed)
57
+ return;
22
58
  const error = new Error("EventSource error");
23
59
  error.name = "EventSourceError";
24
60
  if (errorResolve) {
25
- errorResolve(error);
61
+ const reject = errorResolve;
62
+ messageResolve = null;
26
63
  errorResolve = null;
64
+ reject(error);
27
65
  }
28
66
  else {
29
67
  errorQueue.push(error);
@@ -33,9 +71,9 @@ export function eventSourceIterator(eventSource) {
33
71
  // even before the caller starts iterating
34
72
  eventSource.addEventListener("message", messageHandler);
35
73
  eventSource.addEventListener("error", errorHandler);
36
- return (async function* () {
74
+ const gen = (async function* () {
37
75
  try {
38
- while (true) {
76
+ while (!closed) {
39
77
  // if we have queued messages, yield the first one, remove it from the queue
40
78
  if (messageQueue.length > 0) {
41
79
  yield messageQueue.shift();
@@ -54,17 +92,25 @@ export function eventSourceIterator(eventSource) {
54
92
  messageResolve = null;
55
93
  errorResolve = null;
56
94
  });
57
- if (result) {
95
+ if (!closed && result) {
58
96
  yield result;
59
97
  }
60
98
  }
61
99
  }
62
100
  finally {
63
- // clean up
64
- eventSource.removeEventListener("message", messageHandler);
65
- eventSource.removeEventListener("error", errorHandler);
101
+ closed = true;
102
+ cleanup();
103
+ eventSource.close();
66
104
  }
67
105
  })();
106
+ const origReturn = gen.return.bind(gen);
107
+ const managed = gen;
108
+ managed.close = close;
109
+ managed.return = (value) => {
110
+ close();
111
+ return origReturn(value);
112
+ };
113
+ return managed;
68
114
  }
69
115
  export function isEventSourceError(error) {
70
116
  return error instanceof Error && error.name === "EventSourceError";
@@ -34,10 +34,28 @@ import { ContractManager } from '../contracts/contractManager.js';
34
34
  import { contractHandlers } from '../contracts/handlers/index.js';
35
35
  import { timelockToSequence } from '../contracts/handlers/helpers.js';
36
36
  import { clearSyncCursor, updateWalletState } from '../utils/syncCursors.js';
37
- // Hardcoded unilateral exit delay for mainnet (~7 days in seconds).
38
- // Pinned here so that address derivation stays stable for existing mainnet
39
- // wallets even after the server lowers the delay it advertises.
37
+ // Historical unilateral exit delay for mainnet (~7 days in seconds).
38
+ // Kept so existing wallets can still discover and spend VTXOs sent to the
39
+ // legacy address after arkd starts advertising a different delay.
40
40
  const MAINNET_UNILATERAL_EXIT_DELAY = 605184n;
41
+ function delayToTimelock(delay) {
42
+ return {
43
+ value: delay,
44
+ type: delay < 512n ? "blocks" : "seconds",
45
+ };
46
+ }
47
+ function dedupeTimelocks(timelocks) {
48
+ const seen = new Set();
49
+ const deduped = [];
50
+ for (const timelock of timelocks) {
51
+ const sequence = timelockToSequence(timelock).toString();
52
+ if (seen.has(sequence))
53
+ continue;
54
+ seen.add(sequence);
55
+ deduped.push(timelock);
56
+ }
57
+ return deduped;
58
+ }
41
59
  /**
42
60
  * Type guard function to check if an identity has a toReadonly method.
43
61
  */
@@ -51,7 +69,7 @@ export class ReadonlyWallet {
51
69
  get assetManager() {
52
70
  return this._assetManager;
53
71
  }
54
- constructor(identity, network, onchainProvider, indexerProvider, arkServerPublicKey, offchainTapscript, boardingTapscript, dustAmount, walletRepository, contractRepository, delegatorProvider, watcherConfig) {
72
+ constructor(identity, network, onchainProvider, indexerProvider, arkServerPublicKey, offchainTapscript, boardingTapscript, dustAmount, walletRepository, contractRepository, delegatorProvider, watcherConfig, walletContractTimelocks) {
55
73
  this.identity = identity;
56
74
  this.network = network;
57
75
  this.onchainProvider = onchainProvider;
@@ -84,6 +102,15 @@ export class ReadonlyWallet {
84
102
  }
85
103
  this.watcherConfig = watcherConfig;
86
104
  this._assetManager = new ReadonlyAssetManager(this.indexerProvider);
105
+ // Defensive for direct-construction callers; setupWalletConfig already
106
+ // passes a deduped list through the public create() factories.
107
+ this.walletContractTimelocks =
108
+ walletContractTimelocks && walletContractTimelocks.length > 0
109
+ ? dedupeTimelocks(walletContractTimelocks)
110
+ : [
111
+ this.offchainTapscript.options.csvTimelock ??
112
+ DefaultVtxo.Script.DEFAULT_TIMELOCK,
113
+ ];
87
114
  }
88
115
  /**
89
116
  * Protected helper to set up shared wallet configuration.
@@ -139,17 +166,17 @@ export class ReadonlyWallet {
139
166
  throw new Error("invalid exitTimelock");
140
167
  }
141
168
  }
142
- // On mainnet, pin the unilateral exit delay to the historical value so
143
- // that addresses derived by existing wallets remain stable even if the
144
- // server starts advertising a shorter delay.
145
- const unilateralExitDelay = info.network === "bitcoin"
146
- ? MAINNET_UNILATERAL_EXIT_DELAY
147
- : info.unilateralExitDelay;
169
+ const arkdExitTimelock = delayToTimelock(info.unilateralExitDelay);
148
170
  // create unilateral exit timelock
149
- const exitTimelock = config.exitTimelock ?? {
150
- value: unilateralExitDelay,
151
- type: unilateralExitDelay < 512n ? "blocks" : "seconds",
152
- };
171
+ const exitTimelock = config.exitTimelock ?? arkdExitTimelock;
172
+ const walletContractTimelocks = config.exitTimelock
173
+ ? [exitTimelock]
174
+ : dedupeTimelocks([
175
+ arkdExitTimelock,
176
+ ...(info.network === "bitcoin"
177
+ ? [delayToTimelock(MAINNET_UNILATERAL_EXIT_DELAY)]
178
+ : []),
179
+ ]);
153
180
  // validate boarding timelock passed in config if any
154
181
  if (config.boardingTimelock) {
155
182
  const { value, type } = config.boardingTimelock;
@@ -199,6 +226,7 @@ export class ReadonlyWallet {
199
226
  contractRepository,
200
227
  info,
201
228
  delegatorProvider: config.delegatorProvider,
229
+ walletContractTimelocks,
202
230
  };
203
231
  }
204
232
  /**
@@ -213,14 +241,14 @@ export class ReadonlyWallet {
213
241
  throw new Error("Invalid configured public key");
214
242
  }
215
243
  const setup = await ReadonlyWallet.setupWalletConfig(config, pubkey);
216
- return new ReadonlyWallet(config.identity, setup.network, setup.onchainProvider, setup.indexerProvider, setup.serverPubKey, setup.offchainTapscript, setup.boardingTapscript, setup.dustAmount, setup.walletRepository, setup.contractRepository, setup.delegatorProvider, config.watcherConfig);
244
+ return new ReadonlyWallet(config.identity, setup.network, setup.onchainProvider, setup.indexerProvider, setup.serverPubKey, setup.offchainTapscript, setup.boardingTapscript, setup.dustAmount, setup.walletRepository, setup.contractRepository, setup.delegatorProvider, config.watcherConfig, setup.walletContractTimelocks);
217
245
  }
218
246
  get arkAddress() {
219
247
  return this.offchainTapscript.address(this.network.hrp, this.arkServerPublicKey);
220
248
  }
221
249
  /**
222
- * Get the contract script for the wallet's default address.
223
- * This is the pkScript hex, used to identify the wallet in ContractManager.
250
+ * Get the pkScript hex for the wallet's primary offchain address.
251
+ * For the full wallet-owned script set registered in ContractManager, use getWalletScripts().
224
252
  */
225
253
  get defaultContractScript() {
226
254
  return hex.encode(this.offchainTapscript.pkScript);
@@ -464,56 +492,39 @@ export class ReadonlyWallet {
464
492
  });
465
493
  }
466
494
  if (this.indexerProvider && arkAddress) {
467
- const walletScripts = await this.getWalletScripts();
468
- const subscriptionId = await this.indexerProvider.subscribeForScripts(walletScripts);
469
- const abortController = new AbortController();
470
- const subscription = this.indexerProvider.getSubscription(subscriptionId, abortController.signal);
471
- indexerStopFunc = async () => {
472
- abortController.abort();
473
- await this.indexerProvider?.unsubscribeForScripts(subscriptionId);
474
- };
475
- // Handle subscription updates asynchronously without blocking.
476
- // Subscription covers all wallet scripts (default + delegate) plus
477
- // any additional registered contracts. Virtual outputs carry a
478
- // `script` field from the indexer which the contract manager
479
- // resolves to the owning contract so the extension uses the
480
- // correct forfeit/intent tapscripts.
481
- (async () => {
482
- try {
483
- const cm = await this.getContractManager();
484
- for await (const update of subscription) {
485
- if (update.newVtxos?.length === 0 &&
486
- update.spentVtxos?.length === 0) {
487
- continue;
488
- }
489
- // Isolate per-update annotation failures (e.g. a VTXO
490
- // arriving for a contract we haven't registered yet).
491
- // Without this a single bad update would kill the
492
- // for-await loop and silently drop every subsequent
493
- // subscription event for the session.
494
- try {
495
- // Default to `[]` so a one-sided update (e.g.
496
- // only `newVtxos`) doesn't pass `undefined` into
497
- // annotateVtxos and throw on `.length`.
498
- const [newVtxos, spentVtxos] = await Promise.all([
499
- cm.annotateVtxos(update.newVtxos ?? []),
500
- cm.annotateVtxos(update.spentVtxos ?? []),
501
- ]);
502
- eventCallback({
503
- type: "vtxo",
504
- newVtxos,
505
- spentVtxos,
506
- });
507
- }
508
- catch (error) {
509
- console.warn("Dropping subscription update after annotation failed; next sync will reconcile:", error);
510
- }
511
- }
495
+ // Share the ContractWatcher's single subscription instead of
496
+ // opening a second SSE stream.
497
+ const cm = await this.getContractManager();
498
+ // Serialize annotation+notification: parallel `annotateVtxos`
499
+ // awaits could resolve out of order and deliver eventCallback
500
+ // calls in the wrong sequence (e.g. `vtxo_spent` before its
501
+ // matching `vtxo_received`).
502
+ let annotationQueue = Promise.resolve();
503
+ indexerStopFunc = cm.onContractEvent((event) => {
504
+ if (event.type !== "vtxo_received" &&
505
+ event.type !== "vtxo_spent") {
506
+ return;
512
507
  }
513
- catch (error) {
514
- console.error("Subscription error:", error);
508
+ if (event.contract.type !== "default" &&
509
+ event.contract.type !== "delegate") {
510
+ return;
515
511
  }
516
- })();
512
+ // `event.vtxos` carries placeholder tapscript fields from
513
+ // the watcher; `annotateVtxos` fills them in.
514
+ annotationQueue = annotationQueue.then(async () => {
515
+ try {
516
+ const annotated = await cm.annotateVtxos(event.vtxos);
517
+ eventCallback({
518
+ type: "vtxo",
519
+ newVtxos: event.type === "vtxo_received" ? annotated : [],
520
+ spentVtxos: event.type === "vtxo_spent" ? annotated : [],
521
+ });
522
+ }
523
+ catch (error) {
524
+ console.warn("Dropping subscription update after annotation failed; next sync will reconcile:", error);
525
+ }
526
+ });
527
+ });
517
528
  }
518
529
  const stopFunc = () => {
519
530
  onchainStopFunc?.();
@@ -540,27 +551,13 @@ export class ReadonlyWallet {
540
551
  /**
541
552
  * Get all pkScript hex strings for the wallet's own addresses
542
553
  * (both delegate and non-delegate, current and historical).
543
- * Falls back to only the current script if ContractManager is not yet initialized.
544
554
  */
545
555
  async getWalletScripts() {
546
- // Only use the contract manager if it's already initialized or
547
- // currently initializing never trigger initialization here to
548
- // avoid blocking callers that don't need it.
549
- if (this._contractManager || this._contractManagerInitializing) {
550
- try {
551
- const manager = await this.getContractManager();
552
- const contracts = await manager.getContracts({
553
- type: ["default", "delegate"],
554
- });
555
- if (contracts.length > 0) {
556
- return contracts.map((c) => c.script);
557
- }
558
- }
559
- catch {
560
- // fall through to current script only
561
- }
562
- }
563
- return [hex.encode(this.offchainTapscript.pkScript)];
556
+ const manager = await this.getContractManager();
557
+ const contracts = await manager.getContracts({
558
+ type: ["default", "delegate"],
559
+ });
560
+ return contracts.map((c) => c.script);
564
561
  }
565
562
  /**
566
563
  * Build a map of scriptHex → VtxoScript for all wallet contracts,
@@ -568,26 +565,17 @@ export class ReadonlyWallet {
568
565
  */
569
566
  async getScriptMap() {
570
567
  const map = new Map();
571
- // Always include the current script
572
- const currentScriptHex = hex.encode(this.offchainTapscript.pkScript);
573
- map.set(currentScriptHex, this.offchainTapscript);
574
- if (this._contractManager) {
575
- try {
576
- const contracts = await this._contractManager.getContracts({
577
- type: ["default", "delegate"],
578
- });
579
- for (const contract of contracts) {
580
- if (map.has(contract.script))
581
- continue;
582
- const handler = contractHandlers.get(contract.type);
583
- if (handler) {
584
- const script = handler.createScript(contract.params);
585
- map.set(contract.script, script);
586
- }
587
- }
588
- }
589
- catch {
590
- // ContractManager error — only current script in map
568
+ const manager = await this.getContractManager();
569
+ const contracts = await manager.getContracts({
570
+ type: ["default", "delegate"],
571
+ });
572
+ for (const contract of contracts) {
573
+ if (map.has(contract.script))
574
+ continue;
575
+ const handler = contractHandlers.get(contract.type);
576
+ if (handler) {
577
+ const script = handler.createScript(contract.params);
578
+ map.set(contract.script, script);
591
579
  }
592
580
  }
593
581
  return map;
@@ -655,62 +643,48 @@ export class ReadonlyWallet {
655
643
  walletRepository: this.walletRepository,
656
644
  watcherConfig: this.watcherConfig,
657
645
  });
658
- // Register the wallet's current address as a contract
659
- const csvTimelock = this.offchainTapscript.options.csvTimelock ??
660
- DefaultVtxo.Script.DEFAULT_TIMELOCK;
661
- const csvTimelockStr = timelockToSequence(csvTimelock).toString();
662
- const isDelegateScript = this.offchainTapscript instanceof DelegateVtxo.Script;
663
- if (isDelegateScript) {
664
- const delegateScript = this
665
- .offchainTapscript;
666
- // Register the delegate contract (current address)
667
- await manager.createContract({
668
- type: "delegate",
669
- params: {
670
- pubKey: hex.encode(delegateScript.options.pubKey),
671
- serverPubKey: hex.encode(delegateScript.options.serverPubKey),
672
- delegatePubKey: hex.encode(delegateScript.options.delegatePubKey),
673
- csvTimelock: csvTimelockStr,
674
- },
675
- script: this.defaultContractScript,
676
- address: await this.getAddress(),
677
- state: "active",
678
- });
679
- // Also register the non-delegate version so old virtual outputs remain visible
680
- const nonDelegateScript = new DefaultVtxo.Script({
681
- pubKey: delegateScript.options.pubKey,
682
- serverPubKey: delegateScript.options.serverPubKey,
646
+ for (const csvTimelock of this.walletContractTimelocks) {
647
+ const csvTimelockStr = timelockToSequence(csvTimelock).toString();
648
+ const defaultScript = new DefaultVtxo.Script({
649
+ pubKey: this.offchainTapscript.options.pubKey,
650
+ serverPubKey: this.offchainTapscript.options.serverPubKey,
683
651
  csvTimelock,
684
652
  });
685
653
  await manager.createContract({
686
654
  type: "default",
687
655
  params: {
688
- pubKey: hex.encode(delegateScript.options.pubKey),
689
- serverPubKey: hex.encode(delegateScript.options.serverPubKey),
656
+ pubKey: hex.encode(defaultScript.options.pubKey),
657
+ serverPubKey: hex.encode(defaultScript.options.serverPubKey),
690
658
  csvTimelock: csvTimelockStr,
691
659
  },
692
- script: hex.encode(nonDelegateScript.pkScript),
693
- address: nonDelegateScript
660
+ script: hex.encode(defaultScript.pkScript),
661
+ address: defaultScript
694
662
  .address(this.network.hrp, this.arkServerPublicKey)
695
663
  .encode(),
696
664
  state: "active",
697
665
  });
698
- }
699
- else {
700
- // Register the default contract (current address)
701
- await manager.createContract({
702
- type: "default",
703
- params: {
704
- pubKey: hex.encode(this.offchainTapscript.options.pubKey),
705
- serverPubKey: hex.encode(this.offchainTapscript.options.serverPubKey),
706
- csvTimelock: csvTimelockStr,
707
- },
708
- script: this.defaultContractScript,
709
- address: await this.getAddress(),
710
- state: "active",
711
- });
712
- // Any old "delegate" contract from a prior wallet incarnation
713
- // is already loaded by ContractManager.initialize() from ContractRepository
666
+ if (this.offchainTapscript instanceof DelegateVtxo.Script) {
667
+ const delegateScript = new DelegateVtxo.Script({
668
+ pubKey: this.offchainTapscript.options.pubKey,
669
+ serverPubKey: this.offchainTapscript.options.serverPubKey,
670
+ delegatePubKey: this.offchainTapscript.options.delegatePubKey,
671
+ csvTimelock,
672
+ });
673
+ await manager.createContract({
674
+ type: "delegate",
675
+ params: {
676
+ pubKey: hex.encode(delegateScript.options.pubKey),
677
+ serverPubKey: hex.encode(delegateScript.options.serverPubKey),
678
+ delegatePubKey: hex.encode(delegateScript.options.delegatePubKey),
679
+ csvTimelock: csvTimelockStr,
680
+ },
681
+ script: hex.encode(delegateScript.pkScript),
682
+ address: delegateScript
683
+ .address(this.network.hrp, this.arkServerPublicKey)
684
+ .encode(),
685
+ state: "active",
686
+ });
687
+ }
714
688
  }
715
689
  return manager;
716
690
  }
@@ -793,8 +767,8 @@ export class Wallet extends ReadonlyWallet {
793
767
  }
794
768
  constructor(identity, network, onchainProvider, arkProvider, indexerProvider, arkServerPublicKey, offchainTapscript, boardingTapscript, serverUnrollScript, forfeitOutputScript, forfeitPubkey, dustAmount, walletRepository, contractRepository,
795
769
  /** @deprecated Use settlementConfig */
796
- renewalConfig, delegatorProvider, watcherConfig, settlementConfig) {
797
- super(identity, network, onchainProvider, indexerProvider, arkServerPublicKey, offchainTapscript, boardingTapscript, dustAmount, walletRepository, contractRepository, delegatorProvider, watcherConfig);
770
+ renewalConfig, delegatorProvider, watcherConfig, settlementConfig, walletContractTimelocks) {
771
+ super(identity, network, onchainProvider, indexerProvider, arkServerPublicKey, offchainTapscript, boardingTapscript, dustAmount, walletRepository, contractRepository, delegatorProvider, watcherConfig, walletContractTimelocks);
798
772
  this.arkProvider = arkProvider;
799
773
  this.serverUnrollScript = serverUnrollScript;
800
774
  this.forfeitOutputScript = forfeitOutputScript;
@@ -914,7 +888,7 @@ export class Wallet extends ReadonlyWallet {
914
888
  const forfeitPubkey = hex.decode(setup.info.forfeitPubkey).slice(1);
915
889
  const forfeitAddress = Address(setup.network).decode(setup.info.forfeitAddress);
916
890
  const forfeitOutputScript = OutScript.encode(forfeitAddress);
917
- const wallet = new Wallet(config.identity, setup.network, setup.onchainProvider, setup.arkProvider, setup.indexerProvider, setup.serverPubKey, setup.offchainTapscript, setup.boardingTapscript, serverUnrollScript, forfeitOutputScript, forfeitPubkey, setup.dustAmount, setup.walletRepository, setup.contractRepository, config.renewalConfig, config.delegatorProvider, config.watcherConfig, config.settlementConfig);
891
+ const wallet = new Wallet(config.identity, setup.network, setup.onchainProvider, setup.arkProvider, setup.indexerProvider, setup.serverPubKey, setup.offchainTapscript, setup.boardingTapscript, serverUnrollScript, forfeitOutputScript, forfeitPubkey, setup.dustAmount, setup.walletRepository, setup.contractRepository, config.renewalConfig, config.delegatorProvider, config.watcherConfig, config.settlementConfig, setup.walletContractTimelocks);
918
892
  await wallet.getVtxoManager();
919
893
  return wallet;
920
894
  }
@@ -940,7 +914,7 @@ export class Wallet extends ReadonlyWallet {
940
914
  const readonlyIdentity = hasToReadonly(this.identity)
941
915
  ? await this.identity.toReadonly()
942
916
  : this.identity; // Identity extends ReadonlyIdentity, so this is safe
943
- return new ReadonlyWallet(readonlyIdentity, this.network, this.onchainProvider, this.indexerProvider, this.arkServerPublicKey, this.offchainTapscript, this.boardingTapscript, this.dustAmount, this.walletRepository, this.contractRepository, this.delegatorProvider, this.watcherConfig);
917
+ return new ReadonlyWallet(readonlyIdentity, this.network, this.onchainProvider, this.indexerProvider, this.arkServerPublicKey, this.offchainTapscript, this.boardingTapscript, this.dustAmount, this.walletRepository, this.contractRepository, this.delegatorProvider, this.watcherConfig, this.walletContractTimelocks);
944
918
  }
945
919
  /** Returns the delegator manager when delegation support is configured. */
946
920
  async getDelegatorManager() {
@@ -168,6 +168,9 @@ export declare class ContractWatcher {
168
168
  forcePoll(): Promise<void>;
169
169
  /**
170
170
  * Connect to the subscription.
171
+ *
172
+ * @param skipUpdate - Skip the leading `updateSubscription` call when
173
+ * the caller has already established `subscriptionId`.
171
174
  */
172
175
  private connect;
173
176
  /**