@bsv/overlay-express 2.4.0 → 2.4.2

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 (56) hide show
  1. package/README.md +122 -3
  2. package/dist/cjs/mod.js +8 -1
  3. package/dist/cjs/mod.js.map +1 -1
  4. package/dist/cjs/package.json +19 -19
  5. package/dist/cjs/src/ArcadeProvider.js +196 -0
  6. package/dist/cjs/src/ArcadeProvider.js.map +1 -0
  7. package/dist/cjs/src/ChaintracksProvider.js +65 -0
  8. package/dist/cjs/src/ChaintracksProvider.js.map +1 -0
  9. package/dist/cjs/src/OverlayExpress.js +270 -28
  10. package/dist/cjs/src/OverlayExpress.js.map +1 -1
  11. package/dist/cjs/src/OverlayMonitor.js +117 -3
  12. package/dist/cjs/src/OverlayMonitor.js.map +1 -1
  13. package/dist/cjs/src/ProviderChainBroadcaster.js +91 -0
  14. package/dist/cjs/src/ProviderChainBroadcaster.js.map +1 -0
  15. package/dist/cjs/src/generalGuide.md.js +1 -1
  16. package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
  17. package/dist/esm/mod.js +3 -0
  18. package/dist/esm/mod.js.map +1 -1
  19. package/dist/esm/src/ArcadeProvider.js +189 -0
  20. package/dist/esm/src/ArcadeProvider.js.map +1 -0
  21. package/dist/esm/src/ChaintracksProvider.js +62 -0
  22. package/dist/esm/src/ChaintracksProvider.js.map +1 -0
  23. package/dist/esm/src/OverlayExpress.js +265 -28
  24. package/dist/esm/src/OverlayExpress.js.map +1 -1
  25. package/dist/esm/src/OverlayMonitor.js +117 -3
  26. package/dist/esm/src/OverlayMonitor.js.map +1 -1
  27. package/dist/esm/src/ProviderChainBroadcaster.js +88 -0
  28. package/dist/esm/src/ProviderChainBroadcaster.js.map +1 -0
  29. package/dist/esm/src/generalGuide.md.js +1 -1
  30. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
  31. package/dist/types/mod.d.ts +3 -0
  32. package/dist/types/mod.d.ts.map +1 -1
  33. package/dist/types/src/ArcadeProvider.d.ts +37 -0
  34. package/dist/types/src/ArcadeProvider.d.ts.map +1 -0
  35. package/dist/types/src/ChaintracksProvider.d.ts +29 -0
  36. package/dist/types/src/ChaintracksProvider.d.ts.map +1 -0
  37. package/dist/types/src/OverlayExpress.d.ts +38 -1
  38. package/dist/types/src/OverlayExpress.d.ts.map +1 -1
  39. package/dist/types/src/OverlayMonitor.d.ts +28 -0
  40. package/dist/types/src/OverlayMonitor.d.ts.map +1 -1
  41. package/dist/types/src/ProviderChainBroadcaster.d.ts +18 -0
  42. package/dist/types/src/ProviderChainBroadcaster.d.ts.map +1 -0
  43. package/dist/types/src/generalGuide.md.d.ts +1 -1
  44. package/dist/types/tsconfig.types.tsbuildinfo +1 -1
  45. package/mod.ts +15 -0
  46. package/package.json +19 -19
  47. package/src/ArcadeProvider.ts +232 -0
  48. package/src/ChaintracksProvider.ts +79 -0
  49. package/src/OverlayExpress.ts +299 -28
  50. package/src/OverlayMonitor.ts +163 -3
  51. package/src/ProviderChainBroadcaster.ts +108 -0
  52. package/src/__tests__/OverlayExpress.test.ts +196 -4
  53. package/src/__tests__/OverlayMonitor.test.ts +74 -0
  54. package/src/__tests__/OverlayProviders.live.test.ts +43 -0
  55. package/src/__tests__/OverlayProviders.test.ts +123 -0
  56. package/src/generalGuide.md.ts +1 -1
@@ -55,6 +55,9 @@ const BanAwareDiscoveryStorage_js_1 = require("./BanAwareDiscoveryStorage.js");
55
55
  const ReorgStream_js_1 = require("./ReorgStream.js");
56
56
  const wallet_toolbox_client_1 = require("@bsv/wallet-toolbox-client");
57
57
  const auth_express_middleware_1 = require("@bsv/auth-express-middleware");
58
+ const ArcadeProvider_js_1 = require("./ArcadeProvider.js");
59
+ const ProviderChainBroadcaster_js_1 = require("./ProviderChainBroadcaster.js");
60
+ const ChaintracksProvider_js_1 = require("./ChaintracksProvider.js");
58
61
  /**
59
62
  * In-memory migration source for Knex migrations.
60
63
  * Allows running migrations defined in code rather than files.
@@ -88,6 +91,16 @@ class InMemoryMigrationSource {
88
91
  return await Promise.resolve(migration);
89
92
  }
90
93
  }
94
+ function parseTopicsHeader(header) {
95
+ const value = header.trim();
96
+ const parsed = value.startsWith('[')
97
+ ? JSON.parse(value)
98
+ : value.split(',').map(topic => topic.trim());
99
+ if (!Array.isArray(parsed) || parsed.some(topic => typeof topic !== 'string' || topic.length === 0)) {
100
+ throw new TypeError('Invalid x-topics header: expected a comma-separated list or JSON string array');
101
+ }
102
+ return parsed;
103
+ }
91
104
  /**
92
105
  * OverlayExpress class provides an Express-based server for hosting Overlay Services.
93
106
  * It allows configuration of various components like databases, topic managers, and lookup services.
@@ -133,12 +146,21 @@ class OverlayExpress {
133
146
  // chain with empty anchors, so the cumulative TAC advances "after each new
134
147
  // block" per BRC-136. Set to 0 to disable polling (startup extension still runs).
135
148
  this.basmBlockPollIntervalMs = 10 * 60 * 1000;
149
+ // How often (ms) to refresh proofs for old unproven rows and then evict rows
150
+ // that still have no proof. Set to 0 to disable background maintenance.
151
+ this.unprovenMaintenanceIntervalMs = 0;
136
152
  // Depth (in blocks from the tip) for the reorg revalidation sweep.
137
153
  this.reorgScanDepth = 3;
138
154
  // ARC API Key
139
155
  this.arcApiKey = undefined;
140
156
  // Optional ARC callback token for /arc-ingest notifications
141
157
  this.arcCallbackToken = undefined;
158
+ // Optional Arcade URL/API key used for propagation, proof refresh, and
159
+ // go-chaintracks header/reorg access when available.
160
+ this.arcadeUrl = undefined;
161
+ this.arcadeApiKey = undefined;
162
+ this.arcadeDeploymentId = undefined;
163
+ this.arcadeChaintracksApiPrefix = '/chaintracks/v2';
142
164
  // Verbose request logging
143
165
  this.verboseRequestLogging = false;
144
166
  // Web UI configuration
@@ -277,6 +299,42 @@ class OverlayExpress {
277
299
  this.arcCallbackToken = token;
278
300
  this.logger.log(chalk_1.default.blue('ARC callback token has been configured.'));
279
301
  }
302
+ /**
303
+ * Configures Arcade for first-choice transaction propagation and proof lookup.
304
+ */
305
+ configureArcade(url, config = {}) {
306
+ this.arcadeUrl = url;
307
+ this.arcadeApiKey = config.apiKey;
308
+ this.arcadeDeploymentId = config.deploymentId;
309
+ if (config.chaintracksApiPrefix !== undefined) {
310
+ this.arcadeChaintracksApiPrefix = config.chaintracksApiPrefix;
311
+ }
312
+ this.logger.log(chalk_1.default.blue('Arcade provider has been configured.'));
313
+ }
314
+ /**
315
+ * Configures a go-chaintracks compatible service for header validation and
316
+ * BASM reorg streaming. Arcade exposes this at `/chaintracks/v2`.
317
+ */
318
+ configureChaintracks(url, config = {}) {
319
+ var _a;
320
+ const apiPrefix = (_a = config.apiPrefix) !== null && _a !== void 0 ? _a : '/chaintracks/v2';
321
+ const client = new ChaintracksProvider_js_1.ChaintracksProvider(url, { apiPrefix });
322
+ this.configureChainTracker(client);
323
+ this.configureTopicAnchorHeaderResolver(async (blockHeight) => {
324
+ const header = await client.findHeaderForHeight(blockHeight);
325
+ if (header === undefined)
326
+ return undefined;
327
+ return {
328
+ blockHeight,
329
+ blockHash: header.hash,
330
+ merkleRoot: header.merkleRoot
331
+ };
332
+ });
333
+ if (config.reorgStream !== false) {
334
+ this.configureReorgStream(client.reorgStreamUrl(), config.scanDepth);
335
+ }
336
+ this.logger.log(chalk_1.default.blue('go-chaintracks provider has been configured.'));
337
+ }
280
338
  /**
281
339
  * Enables or disables GASP synchronization (high-level setting).
282
340
  * This is a broad toggle that can be overridden or customized through syncConfiguration.
@@ -323,6 +381,19 @@ class OverlayExpress {
323
381
  }
324
382
  this.logger.log(chalk_1.default.blue('Unproven transaction eviction has been configured.'));
325
383
  }
384
+ /**
385
+ * Configures periodic unproven maintenance. Each run first tries configured
386
+ * proof providers, then evicts rows that are still unproven past the threshold.
387
+ */
388
+ configureUnprovenMaintenance(config) {
389
+ if (config.intervalMs !== undefined) {
390
+ this.unprovenMaintenanceIntervalMs = config.intervalMs;
391
+ }
392
+ if (config.thresholdBlocks !== undefined) {
393
+ this.unprovenEvictionBlocks = config.thresholdBlocks;
394
+ }
395
+ this.logger.log(chalk_1.default.blue('Unproven transaction maintenance has been configured.'));
396
+ }
326
397
  /**
327
398
  * Configures how often the BASM anchor chain is extended with empty anchors to
328
399
  * follow the chain tip. Set to 0 to disable periodic polling.
@@ -445,22 +516,25 @@ class OverlayExpress {
445
516
  var _a, _b, _c, _d, _e, _f, _g, _h, _j;
446
517
  const knex = this.ensureKnex();
447
518
  if (autoConfigureShipSlap) {
519
+ const mongoDb = this.ensureMongo();
520
+ const shipStorage = new DiscoveryServices.SHIPStorage(mongoDb);
521
+ const slapStorage = new DiscoveryServices.SLAPStorage(mongoDb);
522
+ // Run the one-time discovery migration before the engine can accept
523
+ // traffic, so a failed unique-index build is a visible startup failure.
524
+ await shipStorage.ensureIndexes();
525
+ await slapStorage.ensureIndexes();
448
526
  this.configureTopicManager('tm_ship', new DiscoveryServices.SHIPTopicManager());
449
527
  this.configureTopicManager('tm_slap', new DiscoveryServices.SLAPTopicManager());
450
- this.configureLookupServiceWithMongo('ls_ship', (db) => {
451
- const storage = new DiscoveryServices.SHIPStorage(db);
452
- const storageForLookup = this.banService === undefined
453
- ? storage
454
- : new BanAwareDiscoveryStorage_js_1.BanAwareSHIPStorage(storage, this.banService, this.logger);
455
- return new DiscoveryServices.SHIPLookupService(storageForLookup);
456
- });
457
- this.configureLookupServiceWithMongo('ls_slap', (db) => {
458
- const storage = new DiscoveryServices.SLAPStorage(db);
459
- const storageForLookup = this.banService === undefined
460
- ? storage
461
- : new BanAwareDiscoveryStorage_js_1.BanAwareSLAPStorage(storage, this.banService, this.logger);
462
- return new DiscoveryServices.SLAPLookupService(storageForLookup);
463
- });
528
+ const shipStorageForLookup = this.banService === undefined
529
+ ? shipStorage
530
+ : new BanAwareDiscoveryStorage_js_1.BanAwareSHIPStorage(shipStorage, this.banService, this.logger);
531
+ const slapStorageForLookup = this.banService === undefined
532
+ ? slapStorage
533
+ : new BanAwareDiscoveryStorage_js_1.BanAwareSLAPStorage(slapStorage, this.banService, this.logger);
534
+ this.services.ls_ship = new DiscoveryServices.SHIPLookupService(shipStorageForLookup);
535
+ this.services.ls_slap = new DiscoveryServices.SLAPLookupService(slapStorageForLookup);
536
+ this.logger.log(chalk_1.default.blue('Configured lookup service ls_ship with MongoDB'));
537
+ this.logger.log(chalk_1.default.blue('Configured lookup service ls_slap with MongoDB'));
464
538
  }
465
539
  this.wrapBanAwareServices();
466
540
  const syncConfig = this.buildSyncConfig();
@@ -471,7 +545,7 @@ class OverlayExpress {
471
545
  const EngineWithBASM = overlay_1.Engine;
472
546
  this.engine = new EngineWithBASM(this.managers, this.services, storage, (_a = this.engineConfig.chainTracker) !== null && _a !== void 0 ? _a : this.chainTracker, `https://${this.advertisableFQDN}`, this.network === 'test'
473
547
  ? ((_b = this.engineConfig.shipTrackers) !== null && _b !== void 0 ? _b : sdk_1.DEFAULT_TESTNET_SLAP_TRACKERS)
474
- : this.engineConfig.shipTrackers, this.resolveSlapTrackers(), broadcaster !== null && broadcaster !== void 0 ? broadcaster : this.engineConfig.broadcaster, advertiser, syncConfig, (_c = this.engineConfig.logTime) !== null && _c !== void 0 ? _c : false, (_d = this.engineConfig.logPrefix) !== null && _d !== void 0 ? _d : '[OVERLAY_ENGINE] ', (_e = this.engineConfig.throwOnBroadcastFailure) !== null && _e !== void 0 ? _e : false, (_f = this.engineConfig.overlayBroadcastFacilitator) !== null && _f !== void 0 ? _f : new sdk_1.HTTPSOverlayBroadcastFacilitator(), this.logger, (_g = this.engineConfig.suppressDefaultSyncAdvertisements) !== null && _g !== void 0 ? _g : true, this.buildTopicAnchorHeaderResolver(), (_h = this.engineConfig.enableBASMSync) !== null && _h !== void 0 ? _h : this.enableBASMSync, (_j = this.engineConfig.unprovenEvictionBlocks) !== null && _j !== void 0 ? _j : this.unprovenEvictionBlocks);
548
+ : this.engineConfig.shipTrackers, this.resolveSlapTrackers(), broadcaster !== null && broadcaster !== void 0 ? broadcaster : this.engineConfig.broadcaster, advertiser, syncConfig, (_c = this.engineConfig.logTime) !== null && _c !== void 0 ? _c : false, (_d = this.engineConfig.logPrefix) !== null && _d !== void 0 ? _d : '[OVERLAY_ENGINE] ', (_e = this.engineConfig.throwOnBroadcastFailure) !== null && _e !== void 0 ? _e : true, (_f = this.engineConfig.overlayBroadcastFacilitator) !== null && _f !== void 0 ? _f : new sdk_1.HTTPSOverlayBroadcastFacilitator(), this.logger, (_g = this.engineConfig.suppressDefaultSyncAdvertisements) !== null && _g !== void 0 ? _g : true, this.buildTopicAnchorHeaderResolver(), (_h = this.engineConfig.enableBASMSync) !== null && _h !== void 0 ? _h : this.enableBASMSync, (_j = this.engineConfig.unprovenEvictionBlocks) !== null && _j !== void 0 ? _j : this.unprovenEvictionBlocks);
475
549
  this.initServerWallet();
476
550
  this.logger.log(chalk_1.default.green('Engine has been configured.'));
477
551
  }
@@ -506,16 +580,88 @@ class OverlayExpress {
506
580
  }
507
581
  return syncConfig;
508
582
  }
509
- /** Build the ARC broadcaster if an API key is configured. */
583
+ /** Build the configured transaction propagation provider chain. */
510
584
  buildBroadcaster() {
511
- if (typeof this.arcApiKey !== 'string')
585
+ const providers = [];
586
+ const callbackUrl = `https://${this.advertisableFQDN}/arc-ingest`;
587
+ if (typeof this.arcadeUrl === 'string' && this.arcadeUrl.length > 0) {
588
+ this.arcadeProvider = new ArcadeProvider_js_1.ArcadeProvider(this.arcadeUrl, {
589
+ apiKey: this.arcadeApiKey,
590
+ callbackUrl,
591
+ callbackToken: this.arcCallbackToken,
592
+ deploymentId: this.arcadeDeploymentId
593
+ });
594
+ providers.push({
595
+ name: 'Arcade',
596
+ broadcaster: this.arcadeProvider
597
+ });
598
+ }
599
+ else {
600
+ this.arcadeProvider = undefined;
601
+ }
602
+ if (typeof this.arcApiKey === 'string' && this.arcApiKey.length > 0) {
603
+ const arcUrl = this.network === 'test' ? 'https://arc-test.taal.com' : 'https://arc.taal.com';
604
+ providers.push({
605
+ name: 'ARC',
606
+ broadcaster: new sdk_1.ARC(arcUrl, {
607
+ apiKey: this.arcApiKey,
608
+ callbackUrl,
609
+ callbackToken: this.arcCallbackToken
610
+ })
611
+ });
612
+ }
613
+ if (providers.length === 0)
614
+ return undefined;
615
+ if (providers.length === 1)
616
+ return providers[0].broadcaster;
617
+ return new ProviderChainBroadcaster_js_1.ProviderChainBroadcaster(providers);
618
+ }
619
+ ensureArcadeProvider() {
620
+ if (this.arcadeProvider !== undefined)
621
+ return this.arcadeProvider;
622
+ if (typeof this.arcadeUrl !== 'string' || this.arcadeUrl.length === 0)
512
623
  return undefined;
513
- const arcUrl = this.network === 'test' ? 'https://arc-test.taal.com' : 'https://arc.taal.com';
514
- return new sdk_1.ARC(arcUrl, {
515
- apiKey: this.arcApiKey,
624
+ this.arcadeProvider = new ArcadeProvider_js_1.ArcadeProvider(this.arcadeUrl, {
625
+ apiKey: this.arcadeApiKey,
516
626
  callbackUrl: `https://${this.advertisableFQDN}/arc-ingest`,
517
- callbackToken: this.arcCallbackToken
627
+ callbackToken: this.arcCallbackToken,
628
+ deploymentId: this.arcadeDeploymentId
518
629
  });
630
+ return this.arcadeProvider;
631
+ }
632
+ async fetchArcadeProof(txid) {
633
+ var _a, _b;
634
+ const provider = this.ensureArcadeProvider();
635
+ if (provider === undefined)
636
+ return undefined;
637
+ const proof = await provider.fetchMerkleProof(txid);
638
+ if (proof === undefined)
639
+ return undefined;
640
+ const chainTracker = (_a = this.engineConfig.chainTracker) !== null && _a !== void 0 ? _a : this.chainTracker;
641
+ if (chainTracker === 'scripts only') {
642
+ throw new Error('Cannot validate Arcade proof with scripts-only chain tracker');
643
+ }
644
+ const blockHeight = (_b = proof.blockHeight) !== null && _b !== void 0 ? _b : proof.merklePath.blockHeight;
645
+ if (blockHeight === undefined) {
646
+ throw new Error(`Arcade proof for ${txid} did not include a block height`);
647
+ }
648
+ const valid = await chainTracker.isValidRootForHeight(proof.merkleRoot, blockHeight);
649
+ if (!valid) {
650
+ throw new Error(`Arcade proof for ${txid} did not match the chain tracker at height ${blockHeight}`);
651
+ }
652
+ return {
653
+ ...proof,
654
+ blockHeight
655
+ };
656
+ }
657
+ async fetchConfiguredMerkleProof(txid) {
658
+ const proof = await this.fetchArcadeProof(txid);
659
+ if (proof === undefined)
660
+ return undefined;
661
+ return {
662
+ merklePath: proof.merklePath,
663
+ blockHeight: proof.blockHeight
664
+ };
519
665
  }
520
666
  /** Build the BASM block header resolver. */
521
667
  buildTopicAnchorHeaderResolver() {
@@ -1060,9 +1206,13 @@ class OverlayExpress {
1060
1206
  if (typeof topicsHeader !== 'string') {
1061
1207
  throw new TypeError('Missing x-topics header');
1062
1208
  }
1063
- const topics = JSON.parse(topicsHeader);
1209
+ const topics = parseTopicsHeader(topicsHeader);
1210
+ const body = req.body;
1211
+ if (body == null || typeof body[Symbol.iterator] !== 'function' || body.length === 0) {
1212
+ throw new TypeError('Missing or empty BEEF body');
1213
+ }
1064
1214
  let offChainValues;
1065
- let beef = Array.from(req.body);
1215
+ let beef = Array.from(body);
1066
1216
  if (includesOffChain) {
1067
1217
  const r = new sdk_1.Utils.Reader(beef);
1068
1218
  const l = r.readVarIntNum();
@@ -1160,8 +1310,9 @@ class OverlayExpress {
1160
1310
  });
1161
1311
  });
1162
1312
  });
1163
- // ARC ingest route (only if we have an ARC API key)
1164
- if (typeof this.arcApiKey === 'string' && this.arcApiKey.length > 0) {
1313
+ // ARC/Arcade ingest route (only if a provider is configured)
1314
+ if ((typeof this.arcApiKey === 'string' && this.arcApiKey.length > 0) ||
1315
+ (typeof this.arcadeUrl === 'string' && this.arcadeUrl.length > 0)) {
1165
1316
  this.app.post('/arc-ingest', (req, res) => {
1166
1317
  ;
1167
1318
  (async () => {
@@ -1178,9 +1329,44 @@ class OverlayExpress {
1178
1329
  return res.status(401).json({ status: 'error', message: 'Unauthorized callback' });
1179
1330
  }
1180
1331
  }
1181
- const { txid, merklePath: merklePathHex, blockHeight } = req.body;
1332
+ const { txid, merklePath: merklePathHex, blockHeight, txStatus, extraInfo, competingTxs, topic } = req.body;
1333
+ if (typeof txid !== 'string' || txid === '') {
1334
+ throw new TypeError('Provider callback is missing txid');
1335
+ }
1336
+ if ((0, ArcadeProvider_js_1.isTerminalArcStatus)(txStatus, extraInfo)) {
1337
+ const report = await engine.evictAppliedTransaction(txid, {
1338
+ topic: typeof topic === 'string' ? topic : undefined,
1339
+ reason: `${txStatus !== null && txStatus !== void 0 ? txStatus : ''} ${extraInfo !== null && extraInfo !== void 0 ? extraInfo : ''}`.trim()
1340
+ });
1341
+ this.logger.warn({
1342
+ operation: 'overlay.provider_callback',
1343
+ outcome: 'terminal_evicted',
1344
+ txid,
1345
+ txStatus,
1346
+ competingTxs,
1347
+ report
1348
+ });
1349
+ return res.status(200).json({
1350
+ status: 'success',
1351
+ message: 'Terminal transaction status processed',
1352
+ data: {
1353
+ ...report,
1354
+ txStatus,
1355
+ competingTxs
1356
+ }
1357
+ });
1358
+ }
1359
+ if (typeof merklePathHex !== 'string' || merklePathHex === '') {
1360
+ return res.status(202).json({ status: 'success', message: 'Transaction status received without proof' });
1361
+ }
1182
1362
  const merklePath = sdk_1.MerklePath.fromHex(merklePathHex);
1183
1363
  await engine.handleNewMerkleProof(txid, merklePath, blockHeight);
1364
+ this.logger.log({
1365
+ operation: 'overlay.provider_callback',
1366
+ outcome: 'proof_ingested',
1367
+ txid,
1368
+ blockHeight
1369
+ });
1184
1370
  return res.status(200).json({ status: 'success', message: 'Transaction status updated' });
1185
1371
  }
1186
1372
  catch (error) {
@@ -1199,7 +1385,7 @@ class OverlayExpress {
1199
1385
  });
1200
1386
  }
1201
1387
  else {
1202
- this.logger.warn(chalk_1.default.yellow('Disabling ARC because no ARC API key was provided.'));
1388
+ this.logger.warn(chalk_1.default.yellow('Disabling ARC/Arcade ingest because no provider was configured.'));
1203
1389
  }
1204
1390
  // GASP sync routes if enabled
1205
1391
  if (this.enableGASPSync) {
@@ -1505,8 +1691,9 @@ class OverlayExpress {
1505
1691
  this.app.post('/admin/health-check', checkAdminAuth, (req, res) => {
1506
1692
  ;
1507
1693
  (async () => {
1694
+ var _a;
1508
1695
  try {
1509
- const { url } = req.body;
1696
+ const url = (_a = req.body) === null || _a === void 0 ? void 0 : _a.url;
1510
1697
  if (typeof url !== 'string' || url.length === 0) {
1511
1698
  return res.status(400).json({ status: 'error', message: 'url is required' });
1512
1699
  }
@@ -1718,8 +1905,38 @@ class OverlayExpress {
1718
1905
  topic: typeof topic === 'string' ? topic : undefined,
1719
1906
  thresholdBlocks: typeof thresholdBlocks === 'number' ? thresholdBlocks : undefined
1720
1907
  });
1908
+ this.logger.log({ operation: 'overlay.unproven_eviction', outcome: 'ok', report });
1721
1909
  return { status: 'success', message: 'Unproven eviction completed', data: report };
1722
1910
  }, checkAdminAuth);
1911
+ /**
1912
+ * Admin route to refresh proofs for expired unproven topic transactions
1913
+ * using the configured proof providers.
1914
+ */
1915
+ registerJsonRoute('/admin/refreshUnprovenProofs', async (req) => {
1916
+ var _a;
1917
+ const { topic, thresholdBlocks } = (_a = req.body) !== null && _a !== void 0 ? _a : {};
1918
+ const report = await basmEngine.refreshUnprovenTransactionProofs({
1919
+ topic: typeof topic === 'string' ? topic : undefined,
1920
+ thresholdBlocks: typeof thresholdBlocks === 'number' ? thresholdBlocks : undefined,
1921
+ proofProvider: async (txid) => await this.fetchConfiguredMerkleProof(txid)
1922
+ });
1923
+ this.logger.log({ operation: 'overlay.unproven_proof_refresh', outcome: 'ok', report });
1924
+ return { status: 'success', message: 'Unproven proof refresh completed', data: report };
1925
+ }, checkAdminAuth);
1926
+ /**
1927
+ * Admin route to refresh proofs first, then evict rows that remain unproven.
1928
+ */
1929
+ registerJsonRoute('/admin/maintainUnproven', async (req) => {
1930
+ var _a;
1931
+ const { topic, thresholdBlocks } = (_a = req.body) !== null && _a !== void 0 ? _a : {};
1932
+ const report = await basmEngine.maintainUnprovenTransactions({
1933
+ topic: typeof topic === 'string' ? topic : undefined,
1934
+ thresholdBlocks: typeof thresholdBlocks === 'number' ? thresholdBlocks : undefined,
1935
+ proofProvider: async (txid) => await this.fetchConfiguredMerkleProof(txid)
1936
+ });
1937
+ this.logger.log({ operation: 'overlay.unproven_maintenance', outcome: 'ok', report });
1938
+ return { status: 'success', message: 'Unproven maintenance completed', data: report };
1939
+ }, checkAdminAuth);
1723
1940
  /**
1724
1941
  * Admin route to evict an outpoint, either from all services or a specific one.
1725
1942
  */
@@ -1830,6 +2047,7 @@ class OverlayExpress {
1830
2047
  }
1831
2048
  await this.runGaspStartupSync();
1832
2049
  await this.runBasmStartupSync();
2050
+ this.startUnprovenMaintenance();
1833
2051
  }
1834
2052
  /** Attempt a GASP sync at startup when enabled. */
1835
2053
  async runGaspStartupSync() {
@@ -1920,6 +2138,30 @@ class OverlayExpress {
1920
2138
  console.error(chalk_1.default.red('Failed to revalidate BASM anchors'), e);
1921
2139
  }
1922
2140
  }
2141
+ startUnprovenMaintenance() {
2142
+ var _a, _b, _c;
2143
+ const intervalMs = (_a = this.engineConfig.unprovenMaintenanceIntervalMs) !== null && _a !== void 0 ? _a : this.unprovenMaintenanceIntervalMs;
2144
+ if (intervalMs <= 0)
2145
+ return;
2146
+ const run = () => {
2147
+ void (async () => {
2148
+ var _a, _b;
2149
+ try {
2150
+ const report = await ((_a = this.engine) === null || _a === void 0 ? void 0 : _a.maintainUnprovenTransactions({
2151
+ thresholdBlocks: (_b = this.engineConfig.unprovenEvictionBlocks) !== null && _b !== void 0 ? _b : this.unprovenEvictionBlocks,
2152
+ proofProvider: async (txid) => await this.fetchConfiguredMerkleProof(txid)
2153
+ }));
2154
+ this.logger.log(chalk_1.default.green('Unproven transaction maintenance complete'), report);
2155
+ }
2156
+ catch (e) {
2157
+ console.error(chalk_1.default.red('Failed to maintain unproven transactions'), e);
2158
+ }
2159
+ })();
2160
+ };
2161
+ run();
2162
+ this.unprovenMaintenanceTimer = setInterval(run, intervalMs);
2163
+ (_c = (_b = this.unprovenMaintenanceTimer).unref) === null || _c === void 0 ? void 0 : _c.call(_b);
2164
+ }
1923
2165
  }
1924
2166
  exports.default = OverlayExpress;
1925
2167
  //# sourceMappingURL=OverlayExpress.js.map