@bsv/overlay-express 2.2.0 → 2.3.0
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.
- package/README.md +33 -0
- package/dist/cjs/mod.js +4 -1
- package/dist/cjs/mod.js.map +1 -1
- package/dist/cjs/package.json +19 -15
- package/dist/cjs/src/BanService.js +2 -2
- package/dist/cjs/src/BanService.js.map +1 -1
- package/dist/cjs/src/OverlayExpress.js +191 -189
- package/dist/cjs/src/OverlayExpress.js.map +1 -1
- package/dist/cjs/src/OverlayMonitor.js +306 -0
- package/dist/cjs/src/OverlayMonitor.js.map +1 -0
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/mod.js +1 -0
- package/dist/esm/mod.js.map +1 -1
- package/dist/esm/src/BanService.js +2 -2
- package/dist/esm/src/BanService.js.map +1 -1
- package/dist/esm/src/OverlayExpress.js +186 -186
- package/dist/esm/src/OverlayExpress.js.map +1 -1
- package/dist/esm/src/OverlayMonitor.js +304 -0
- package/dist/esm/src/OverlayMonitor.js.map +1 -0
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/types/mod.d.ts +1 -0
- package/dist/types/mod.d.ts.map +1 -1
- package/dist/types/src/OverlayExpress.d.ts +29 -1
- package/dist/types/src/OverlayExpress.d.ts.map +1 -1
- package/dist/types/src/OverlayMonitor.d.ts +125 -0
- package/dist/types/src/OverlayMonitor.d.ts.map +1 -0
- package/dist/types/tsconfig.types.tsbuildinfo +1 -1
- package/mod.ts +13 -0
- package/package.json +32 -28
- package/src/BanService.ts +2 -2
- package/src/OverlayExpress.ts +199 -197
- package/src/OverlayMonitor.ts +445 -0
- package/src/__tests__/OverlayExpress.test.ts +86 -1
- package/src/__tests__/OverlayMonitor.test.ts +116 -0
|
@@ -45,7 +45,7 @@ const mongodb_1 = require("mongodb");
|
|
|
45
45
|
const makeUserInterface_js_1 = __importDefault(require("./makeUserInterface.js"));
|
|
46
46
|
const DiscoveryServices = __importStar(require("@bsv/overlay-discovery-services"));
|
|
47
47
|
const chalk_1 = __importDefault(require("chalk"));
|
|
48
|
-
const
|
|
48
|
+
const node_util_1 = __importDefault(require("node:util"));
|
|
49
49
|
const uuid_1 = require("uuid");
|
|
50
50
|
const JanitorService_js_1 = require("./JanitorService.js");
|
|
51
51
|
const BanService_js_1 = require("./BanService.js");
|
|
@@ -123,6 +123,8 @@ class OverlayExpress {
|
|
|
123
123
|
this.enableGASPSync = true;
|
|
124
124
|
// ARC API Key
|
|
125
125
|
this.arcApiKey = undefined;
|
|
126
|
+
// Optional ARC callback token for /arc-ingest notifications
|
|
127
|
+
this.arcCallbackToken = undefined;
|
|
126
128
|
// Verbose request logging
|
|
127
129
|
this.verboseRequestLogging = false;
|
|
128
130
|
// Web UI configuration
|
|
@@ -253,6 +255,14 @@ class OverlayExpress {
|
|
|
253
255
|
this.arcApiKey = apiKey;
|
|
254
256
|
this.logger.log(chalk_1.default.blue('ARC API key has been configured.'));
|
|
255
257
|
}
|
|
258
|
+
/**
|
|
259
|
+
* Configures the ARC callback token expected by /arc-ingest.
|
|
260
|
+
* @param token - The token ARC should present when posting callback notifications.
|
|
261
|
+
*/
|
|
262
|
+
configureArcCallbackToken(token) {
|
|
263
|
+
this.arcCallbackToken = token;
|
|
264
|
+
this.logger.log(chalk_1.default.blue('ARC callback token has been configured.'));
|
|
265
|
+
}
|
|
256
266
|
/**
|
|
257
267
|
* Enables or disables GASP synchronization (high-level setting).
|
|
258
268
|
* This is a broad toggle that can be overridden or customized through syncConfiguration.
|
|
@@ -272,7 +282,7 @@ class OverlayExpress {
|
|
|
272
282
|
}
|
|
273
283
|
/**
|
|
274
284
|
* Configure Knex (SQL) database connection.
|
|
275
|
-
* @param config - Knex configuration object, or MySQL connection string
|
|
285
|
+
* @param config - Knex configuration object, or a MySQL connection string loaded from configuration.
|
|
276
286
|
*/
|
|
277
287
|
async configureKnex(config) {
|
|
278
288
|
if (typeof config === 'string') {
|
|
@@ -376,126 +386,102 @@ class OverlayExpress {
|
|
|
376
386
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
377
387
|
const knex = this.ensureKnex();
|
|
378
388
|
if (autoConfigureShipSlap) {
|
|
379
|
-
// Auto-configure SHIP and SLAP services
|
|
380
389
|
this.configureTopicManager('tm_ship', new DiscoveryServices.SHIPTopicManager());
|
|
381
390
|
this.configureTopicManager('tm_slap', new DiscoveryServices.SLAPTopicManager());
|
|
382
391
|
this.configureLookupServiceWithMongo('ls_ship', (db) => new DiscoveryServices.SHIPLookupService(new DiscoveryServices.SHIPStorage(db)));
|
|
383
392
|
this.configureLookupServiceWithMongo('ls_slap', (db) => new DiscoveryServices.SLAPLookupService(new DiscoveryServices.SLAPStorage(db)));
|
|
384
393
|
}
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
394
|
+
this.wrapBanAwareServices();
|
|
395
|
+
const syncConfig = this.buildSyncConfig();
|
|
396
|
+
const storage = new overlay_1.KnexStorage(knex);
|
|
397
|
+
this.migrationsToRun = [...overlay_1.KnexStorageMigrations.default, ...this.migrationsToRun];
|
|
398
|
+
const broadcaster = this.buildBroadcaster();
|
|
399
|
+
const advertiser = await this.buildAdvertiser();
|
|
400
|
+
this.engine = new overlay_1.Engine(this.managers, this.services, storage, (_a = this.engineConfig.chainTracker) !== null && _a !== void 0 ? _a : this.chainTracker, `https://${this.advertisableFQDN}`, this.network === 'test'
|
|
401
|
+
? ((_b = this.engineConfig.shipTrackers) !== null && _b !== void 0 ? _b : sdk_1.DEFAULT_TESTNET_SLAP_TRACKERS)
|
|
402
|
+
: 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);
|
|
403
|
+
this.initServerWallet();
|
|
404
|
+
this.logger.log(chalk_1.default.green('Engine has been configured.'));
|
|
405
|
+
}
|
|
406
|
+
/** Wrap SHIP/SLAP with ban-aware filter if BanService is configured. */
|
|
407
|
+
wrapBanAwareServices() {
|
|
408
|
+
if (this.banService === undefined)
|
|
409
|
+
return;
|
|
410
|
+
for (const key of ['ls_ship', 'ls_slap']) {
|
|
411
|
+
if (this.services[key] !== undefined) {
|
|
412
|
+
const label = key === 'ls_ship' ? 'SHIP' : 'SLAP';
|
|
413
|
+
this.services[key] = new BanAwareLookupWrapper_js_1.BanAwareLookupWrapper(this.services[key], this.banService, label, this.logger);
|
|
414
|
+
this.logger.log(chalk_1.default.blue(`${label} lookup service wrapped with ban-aware filter.`));
|
|
395
415
|
}
|
|
396
416
|
}
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
}
|
|
417
|
+
}
|
|
418
|
+
/** Build the sync config based on enableGASPSync and engineConfig. */
|
|
419
|
+
buildSyncConfig() {
|
|
420
|
+
var _a;
|
|
421
|
+
if (this.enableGASPSync) {
|
|
422
|
+
return (_a = this.engineConfig.syncConfiguration) !== null && _a !== void 0 ? _a : {};
|
|
404
423
|
}
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
syncConfig =
|
|
424
|
+
const syncConfig = {};
|
|
425
|
+
for (const name of Object.keys(this.managers)) {
|
|
426
|
+
syncConfig[name] = false;
|
|
408
427
|
}
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
this.
|
|
419
|
-
|
|
420
|
-
|
|
428
|
+
return syncConfig;
|
|
429
|
+
}
|
|
430
|
+
/** Build the ARC broadcaster if an API key is configured. */
|
|
431
|
+
buildBroadcaster() {
|
|
432
|
+
if (typeof this.arcApiKey !== 'string')
|
|
433
|
+
return undefined;
|
|
434
|
+
const arcUrl = this.network === 'test' ? 'https://arc-test.taal.com' : 'https://arc.taal.com';
|
|
435
|
+
return new sdk_1.ARC(arcUrl, {
|
|
436
|
+
apiKey: this.arcApiKey,
|
|
437
|
+
callbackUrl: `https://${this.advertisableFQDN}/arc-ingest`,
|
|
438
|
+
callbackToken: this.arcCallbackToken
|
|
439
|
+
});
|
|
440
|
+
}
|
|
441
|
+
/** Resolve the SLAP trackers from config or network defaults. */
|
|
442
|
+
resolveSlapTrackers() {
|
|
443
|
+
if (Array.isArray(this.engineConfig.slapTrackers))
|
|
444
|
+
return this.engineConfig.slapTrackers;
|
|
445
|
+
return this.network === 'test' ? sdk_1.DEFAULT_TESTNET_SLAP_TRACKERS : sdk_1.DEFAULT_SLAP_TRACKERS;
|
|
446
|
+
}
|
|
447
|
+
/** Build the WalletAdvertiser (or use user-provided one). */
|
|
448
|
+
async buildAdvertiser() {
|
|
449
|
+
if (this.engineConfig.advertiser !== undefined)
|
|
450
|
+
return this.engineConfig.advertiser;
|
|
451
|
+
const storageBase = this.network === 'test'
|
|
452
|
+
? 'https://staging-storage.babbage.systems'
|
|
453
|
+
: 'https://storage.babbage.systems';
|
|
454
|
+
try {
|
|
455
|
+
return new DiscoveryServices.WalletAdvertiser(this.network, this.privateKey, storageBase, `https://${this.advertisableFQDN}`);
|
|
421
456
|
}
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
try {
|
|
426
|
-
advertiser = new DiscoveryServices.WalletAdvertiser(this.network, this.privateKey, this.network === 'test' // For now, we hard-code some storage servers. In the future, this needs to be configurable.
|
|
427
|
-
? 'https://staging-storage.babbage.systems'
|
|
428
|
-
: 'https://storage.babbage.systems',
|
|
429
|
-
// Until multiple protocols (like https+bsvauth+smf) are fully supported, HTTPS is the one to always use.
|
|
430
|
-
`https://${this.advertisableFQDN}`);
|
|
431
|
-
}
|
|
432
|
-
catch (e) {
|
|
433
|
-
this.logger.log(`Advertiser not initialized for FQDN ${this.advertisableFQDN} - SHIP and SLAP will be disabled.`);
|
|
434
|
-
}
|
|
457
|
+
catch (e) {
|
|
458
|
+
this.logger.log(`Advertiser not initialized for FQDN ${this.advertisableFQDN} - SHIP and SLAP will be disabled. Reason: ${e}`);
|
|
459
|
+
return undefined;
|
|
435
460
|
}
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
? this.engineConfig.chainTracker
|
|
441
|
-
: this.chainTracker,
|
|
442
|
-
// hostingURL
|
|
443
|
-
`https://${this.advertisableFQDN}`,
|
|
444
|
-
// shipTrackers
|
|
445
|
-
this.network === 'test'
|
|
446
|
-
? ((_b = this.engineConfig.shipTrackers) !== null && _b !== void 0 ? _b : sdk_1.DEFAULT_TESTNET_SLAP_TRACKERS)
|
|
447
|
-
: this.engineConfig.shipTrackers,
|
|
448
|
-
// slapTrackers
|
|
449
|
-
Array.isArray(this.engineConfig.slapTrackers)
|
|
450
|
-
? this.engineConfig.slapTrackers
|
|
451
|
-
: this.network === 'test'
|
|
452
|
-
? sdk_1.DEFAULT_TESTNET_SLAP_TRACKERS
|
|
453
|
-
: sdk_1.DEFAULT_SLAP_TRACKERS,
|
|
454
|
-
// broadcaster
|
|
455
|
-
broadcaster !== null && broadcaster !== void 0 ? broadcaster : this.engineConfig.broadcaster,
|
|
456
|
-
// advertiser
|
|
457
|
-
advertiser,
|
|
458
|
-
// syncConfiguration
|
|
459
|
-
syncConfig,
|
|
460
|
-
// logTime
|
|
461
|
-
(_c = this.engineConfig.logTime) !== null && _c !== void 0 ? _c : false,
|
|
462
|
-
// logPrefix
|
|
463
|
-
(_d = this.engineConfig.logPrefix) !== null && _d !== void 0 ? _d : '[OVERLAY_ENGINE] ',
|
|
464
|
-
// throwOnBroadcastFailure
|
|
465
|
-
(_e = this.engineConfig.throwOnBroadcastFailure) !== null && _e !== void 0 ? _e : false,
|
|
466
|
-
// overlayBroadcastFacilitator
|
|
467
|
-
(_f = this.engineConfig.overlayBroadcastFacilitator) !== null && _f !== void 0 ? _f : new sdk_1.HTTPSOverlayBroadcastFacilitator(),
|
|
468
|
-
// logger
|
|
469
|
-
this.logger,
|
|
470
|
-
// suppressDefaultSyncAdvertisements
|
|
471
|
-
(_g = this.engineConfig.suppressDefaultSyncAdvertisements) !== null && _g !== void 0 ? _g : true);
|
|
472
|
-
// Create the server wallet for BSV mutual authentication.
|
|
473
|
-
// This uses the same private key as the WalletAdvertiser.
|
|
461
|
+
}
|
|
462
|
+
/** Initialize the server wallet for BSV mutual authentication. */
|
|
463
|
+
initServerWallet() {
|
|
464
|
+
var _a;
|
|
474
465
|
try {
|
|
475
466
|
const keyDeriver = new sdk_1.KeyDeriver(new sdk_1.PrivateKey(this.privateKey, 'hex'));
|
|
476
467
|
const storageManager = new wallet_toolbox_client_1.WalletStorageManager(keyDeriver.identityKey);
|
|
477
468
|
const signer = new wallet_toolbox_client_1.WalletSigner(this.network, keyDeriver, storageManager);
|
|
478
469
|
const services = new wallet_toolbox_client_1.Services(this.network);
|
|
479
|
-
|
|
480
|
-
this.
|
|
481
|
-
// Auto-set the admin identity key from the server's own key if not configured
|
|
482
|
-
if (typeof this.adminIdentityKey === 'undefined') {
|
|
483
|
-
this.adminIdentityKey = keyDeriver.identityKey;
|
|
484
|
-
}
|
|
470
|
+
this.serverWallet = new wallet_toolbox_client_1.Wallet(signer, services);
|
|
471
|
+
(_a = this.adminIdentityKey) !== null && _a !== void 0 ? _a : (this.adminIdentityKey = keyDeriver.identityKey);
|
|
485
472
|
this.logger.log(chalk_1.default.blue('Server wallet initialized for BSV mutual authentication.'));
|
|
486
473
|
}
|
|
487
474
|
catch (e) {
|
|
488
|
-
this.logger.log(chalk_1.default.yellow(
|
|
475
|
+
this.logger.log(chalk_1.default.yellow(`Server wallet could not be initialized. BSV auth will not be available. Reason: ${e}`));
|
|
489
476
|
}
|
|
490
|
-
this.logger.log(chalk_1.default.green('Engine has been configured.'));
|
|
491
477
|
}
|
|
492
478
|
/**
|
|
493
479
|
* Ensures that Knex is configured and returns it.
|
|
494
480
|
* @throws Error if Knex is not configured
|
|
495
481
|
*/
|
|
496
482
|
ensureKnex() {
|
|
497
|
-
if (
|
|
498
|
-
throw new
|
|
483
|
+
if (this.knex === undefined) {
|
|
484
|
+
throw new TypeError('You must configure your SQL database with the .configureKnex() method first!');
|
|
499
485
|
}
|
|
500
486
|
return this.knex;
|
|
501
487
|
}
|
|
@@ -504,8 +490,8 @@ class OverlayExpress {
|
|
|
504
490
|
* @throws Error if MongoDB is not configured
|
|
505
491
|
*/
|
|
506
492
|
ensureMongo() {
|
|
507
|
-
if (
|
|
508
|
-
throw new
|
|
493
|
+
if (this.mongoDb === undefined) {
|
|
494
|
+
throw new TypeError('You must configure your MongoDB connection with the .configureMongo() method first!');
|
|
509
495
|
}
|
|
510
496
|
return this.mongoDb;
|
|
511
497
|
}
|
|
@@ -514,8 +500,8 @@ class OverlayExpress {
|
|
|
514
500
|
* @throws Error if the Engine is not configured
|
|
515
501
|
*/
|
|
516
502
|
ensureEngine() {
|
|
517
|
-
if (
|
|
518
|
-
throw new
|
|
503
|
+
if (this.engine === undefined) {
|
|
504
|
+
throw new TypeError('You must configure your Overlay Services engine with the .configureEngine() method first!');
|
|
519
505
|
}
|
|
520
506
|
return this.engine;
|
|
521
507
|
}
|
|
@@ -533,6 +519,71 @@ class OverlayExpress {
|
|
|
533
519
|
autoBanOnRemoval: this.janitorConfig.autoBanOnRemoval
|
|
534
520
|
});
|
|
535
521
|
}
|
|
522
|
+
/** Ban a domain and remove all its SHIP/SLAP records from MongoDB. */
|
|
523
|
+
async handleBanDomain(res, value, reason) {
|
|
524
|
+
await this.banService.banDomain(value, reason);
|
|
525
|
+
const db = this.ensureMongo();
|
|
526
|
+
const [shipDeleted, slapDeleted] = await Promise.all([
|
|
527
|
+
db.collection('shipRecords').deleteMany({ domain: value }),
|
|
528
|
+
db.collection('slapRecords').deleteMany({ domain: value })
|
|
529
|
+
]);
|
|
530
|
+
return res.status(200).json({
|
|
531
|
+
status: 'success',
|
|
532
|
+
message: `Domain "${value}" banned. Removed ${shipDeleted.deletedCount} SHIP and ${slapDeleted.deletedCount} SLAP records.`
|
|
533
|
+
});
|
|
534
|
+
}
|
|
535
|
+
/** Parse outpoint string, ban it, and evict it from all lookup services. */
|
|
536
|
+
async handleBanOutpoint(res, engine, value, reason) {
|
|
537
|
+
const dotIndex = value.lastIndexOf('.');
|
|
538
|
+
if (dotIndex === -1) {
|
|
539
|
+
return res.status(400).json({ status: 'error', message: 'Outpoint format must be "txid.outputIndex"' });
|
|
540
|
+
}
|
|
541
|
+
const txid = value.substring(0, dotIndex);
|
|
542
|
+
const outputIndex = Number.parseInt(value.substring(dotIndex + 1));
|
|
543
|
+
if (Number.isNaN(outputIndex)) {
|
|
544
|
+
return res.status(400).json({ status: 'error', message: 'Invalid outputIndex in outpoint' });
|
|
545
|
+
}
|
|
546
|
+
await this.banService.banOutpoint(txid, outputIndex, reason);
|
|
547
|
+
await this.evictFromServices(engine, txid, outputIndex);
|
|
548
|
+
return res.status(200).json({
|
|
549
|
+
status: 'success',
|
|
550
|
+
message: `Outpoint "${value}" banned and evicted from lookup services.`
|
|
551
|
+
});
|
|
552
|
+
}
|
|
553
|
+
/** Evict an output from a specific service or all services (silent per-service errors). */
|
|
554
|
+
async evictFromServices(engine, txid, outputIndex, service) {
|
|
555
|
+
if (typeof service === 'string') {
|
|
556
|
+
const svc = engine.lookupServices[service];
|
|
557
|
+
if (svc !== undefined)
|
|
558
|
+
await svc.outputEvicted(txid, outputIndex);
|
|
559
|
+
return;
|
|
560
|
+
}
|
|
561
|
+
for (const svc of Object.values(engine.lookupServices)) {
|
|
562
|
+
try {
|
|
563
|
+
await svc.outputEvicted(txid, outputIndex);
|
|
564
|
+
}
|
|
565
|
+
catch { /* best-effort */ }
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
/** Look up the domain of an outpoint from SHIP or SLAP records. */
|
|
569
|
+
async lookupDomainForOutpoint(txid, outputIndex) {
|
|
570
|
+
var _a;
|
|
571
|
+
const db = this.ensureMongo();
|
|
572
|
+
const [shipRecord, slapRecord] = await Promise.all([
|
|
573
|
+
db.collection('shipRecords').findOne({ txid, outputIndex }),
|
|
574
|
+
db.collection('slapRecords').findOne({ txid, outputIndex })
|
|
575
|
+
]);
|
|
576
|
+
return ((_a = shipRecord === null || shipRecord === void 0 ? void 0 : shipRecord.domain) !== null && _a !== void 0 ? _a : slapRecord === null || slapRecord === void 0 ? void 0 : slapRecord.domain);
|
|
577
|
+
}
|
|
578
|
+
/** Ban a domain and delete all SHIP/SLAP records for it. */
|
|
579
|
+
async banDomainAndRemoveRecords(domain, reason) {
|
|
580
|
+
await this.banService.banDomain(domain, reason);
|
|
581
|
+
const db = this.ensureMongo();
|
|
582
|
+
await Promise.all([
|
|
583
|
+
db.collection('shipRecords').deleteMany({ domain }),
|
|
584
|
+
db.collection('slapRecords').deleteMany({ domain })
|
|
585
|
+
]);
|
|
586
|
+
}
|
|
536
587
|
async runHealthCheck(definition) {
|
|
537
588
|
var _a, _b;
|
|
538
589
|
const startedAt = Date.now();
|
|
@@ -583,8 +634,8 @@ class OverlayExpress {
|
|
|
583
634
|
scope: 'ready',
|
|
584
635
|
critical: true,
|
|
585
636
|
handler: async () => {
|
|
586
|
-
if (
|
|
587
|
-
throw new
|
|
637
|
+
if (this.engine === undefined) {
|
|
638
|
+
throw new TypeError('Overlay engine is not configured');
|
|
588
639
|
}
|
|
589
640
|
return {
|
|
590
641
|
status: 'ok',
|
|
@@ -601,8 +652,8 @@ class OverlayExpress {
|
|
|
601
652
|
critical: true,
|
|
602
653
|
handler: async () => {
|
|
603
654
|
var _a, _b, _c;
|
|
604
|
-
if (
|
|
605
|
-
throw new
|
|
655
|
+
if (this.knex === undefined) {
|
|
656
|
+
throw new TypeError('Knex is not configured');
|
|
606
657
|
}
|
|
607
658
|
await this.knex.raw('select 1 as ok');
|
|
608
659
|
return {
|
|
@@ -618,8 +669,8 @@ class OverlayExpress {
|
|
|
618
669
|
scope: 'ready',
|
|
619
670
|
critical: true,
|
|
620
671
|
handler: async () => {
|
|
621
|
-
if (
|
|
622
|
-
throw new
|
|
672
|
+
if (this.mongoDb === undefined) {
|
|
673
|
+
throw new TypeError('MongoDB is not configured');
|
|
623
674
|
}
|
|
624
675
|
await this.mongoDb.command({ ping: 1 });
|
|
625
676
|
return {
|
|
@@ -670,7 +721,7 @@ class OverlayExpress {
|
|
|
670
721
|
port: this.port,
|
|
671
722
|
network: this.network,
|
|
672
723
|
startedAt: (_c = this.startTime) === null || _c === void 0 ? void 0 : _c.toISOString(),
|
|
673
|
-
uptimeMs:
|
|
724
|
+
uptimeMs: this.startTime === undefined ? 0 : Date.now() - this.startTime.getTime(),
|
|
674
725
|
topicManagerCount: Object.keys(this.managers).length,
|
|
675
726
|
lookupServiceCount: Object.keys(this.services).length
|
|
676
727
|
},
|
|
@@ -699,7 +750,7 @@ class OverlayExpress {
|
|
|
699
750
|
this.logger.log(chalk_1.default.magenta.bold(`Incoming Request: ${String(req.method)} ${String(req.originalUrl)}`));
|
|
700
751
|
// Pretty-print headers
|
|
701
752
|
this.logger.log(chalk_1.default.cyan('Headers:'));
|
|
702
|
-
this.logger.log(
|
|
753
|
+
this.logger.log(node_util_1.default.inspect(req.headers, { colors: true, depth: null }));
|
|
703
754
|
// Handle request body
|
|
704
755
|
if (req.body != null && Object.keys(req.body).length > 0) {
|
|
705
756
|
let bodyContent;
|
|
@@ -733,7 +784,7 @@ class OverlayExpress {
|
|
|
733
784
|
const duration = Date.now() - startTime;
|
|
734
785
|
this.logger.log(chalk_1.default.magenta.bold(`Outgoing Response: ${String(req.method)} ${String(req.originalUrl)} - Status: ${String(res.statusCode)} - Duration: ${String(duration)}ms`));
|
|
735
786
|
this.logger.log(chalk_1.default.cyan('Response Headers:'));
|
|
736
|
-
this.logger.log(
|
|
787
|
+
this.logger.log(node_util_1.default.inspect(res.getHeaders(), { colors: true, depth: null }));
|
|
737
788
|
// Handle response body
|
|
738
789
|
if (responseBody != null) {
|
|
739
790
|
let bodyContent;
|
|
@@ -916,7 +967,7 @@ class OverlayExpress {
|
|
|
916
967
|
const topicsHeader = req.headers['x-topics'];
|
|
917
968
|
const includesOffChain = req.headers['x-includes-off-chain-values'] === 'true';
|
|
918
969
|
if (typeof topicsHeader !== 'string') {
|
|
919
|
-
throw new
|
|
970
|
+
throw new TypeError('Missing x-topics header');
|
|
920
971
|
}
|
|
921
972
|
const topics = JSON.parse(topicsHeader);
|
|
922
973
|
let offChainValues;
|
|
@@ -1024,6 +1075,18 @@ class OverlayExpress {
|
|
|
1024
1075
|
;
|
|
1025
1076
|
(async () => {
|
|
1026
1077
|
try {
|
|
1078
|
+
if (typeof this.arcCallbackToken === 'string' && this.arcCallbackToken.length > 0) {
|
|
1079
|
+
const authorization = req.headers.authorization;
|
|
1080
|
+
const headerToken = Array.isArray(authorization) ? authorization[0] : authorization;
|
|
1081
|
+
const xCallbackToken = req.headers['x-callback-token'];
|
|
1082
|
+
const callbackToken = Array.isArray(xCallbackToken) ? xCallbackToken[0] : xCallbackToken;
|
|
1083
|
+
const bearerToken = typeof headerToken === 'string' && headerToken.startsWith('Bearer ')
|
|
1084
|
+
? headerToken.slice('Bearer '.length)
|
|
1085
|
+
: headerToken;
|
|
1086
|
+
if (bearerToken !== this.arcCallbackToken && callbackToken !== this.arcCallbackToken) {
|
|
1087
|
+
return res.status(401).json({ status: 'error', message: 'Unauthorized callback' });
|
|
1088
|
+
}
|
|
1089
|
+
}
|
|
1027
1090
|
const { txid, merklePath: merklePathHex, blockHeight } = req.body;
|
|
1028
1091
|
const merklePath = sdk_1.MerklePath.fromHex(merklePathHex);
|
|
1029
1092
|
await engine.handleNewMerkleProof(txid, merklePath, blockHeight);
|
|
@@ -1178,7 +1241,7 @@ class OverlayExpress {
|
|
|
1178
1241
|
data: {
|
|
1179
1242
|
nodeName: this.name,
|
|
1180
1243
|
network: this.network,
|
|
1181
|
-
uptime: this.startTime
|
|
1244
|
+
uptime: this.startTime != null ? Date.now() - this.startTime.getTime() : 0,
|
|
1182
1245
|
startedAt: (_c = this.startTime) === null || _c === void 0 ? void 0 : _c.toISOString(),
|
|
1183
1246
|
shipRecordCount: shipCount,
|
|
1184
1247
|
slapRecordCount: slapCount,
|
|
@@ -1211,9 +1274,9 @@ class OverlayExpress {
|
|
|
1211
1274
|
const db = this.ensureMongo();
|
|
1212
1275
|
const collection = db.collection('shipRecords');
|
|
1213
1276
|
const search = typeof req.query.search === 'string' ? req.query.search : undefined;
|
|
1214
|
-
const rawPage = parseInt(req.query.page, 10);
|
|
1277
|
+
const rawPage = Number.parseInt(req.query.page, 10);
|
|
1215
1278
|
const page = Math.max(1, Number.isNaN(rawPage) ? 1 : rawPage);
|
|
1216
|
-
const rawLimit = parseInt(req.query.limit, 10);
|
|
1279
|
+
const rawLimit = Number.parseInt(req.query.limit, 10);
|
|
1217
1280
|
const limit = Math.min(200, Math.max(1, Number.isNaN(rawLimit) ? 50 : rawLimit));
|
|
1218
1281
|
const skip = (page - 1) * limit;
|
|
1219
1282
|
const query = {};
|
|
@@ -1254,9 +1317,9 @@ class OverlayExpress {
|
|
|
1254
1317
|
const db = this.ensureMongo();
|
|
1255
1318
|
const collection = db.collection('slapRecords');
|
|
1256
1319
|
const search = typeof req.query.search === 'string' ? req.query.search : undefined;
|
|
1257
|
-
const rawPage = parseInt(req.query.page, 10);
|
|
1320
|
+
const rawPage = Number.parseInt(req.query.page, 10);
|
|
1258
1321
|
const page = Math.max(1, Number.isNaN(rawPage) ? 1 : rawPage);
|
|
1259
|
-
const rawLimit = parseInt(req.query.limit, 10);
|
|
1322
|
+
const rawLimit = Number.parseInt(req.query.limit, 10);
|
|
1260
1323
|
const limit = Math.min(200, Math.max(1, Number.isNaN(rawLimit) ? 50 : rawLimit));
|
|
1261
1324
|
const skip = (page - 1) * limit;
|
|
1262
1325
|
const query = {};
|
|
@@ -1330,45 +1393,9 @@ class OverlayExpress {
|
|
|
1330
1393
|
return res.status(400).json({ status: 'error', message: 'value is required' });
|
|
1331
1394
|
}
|
|
1332
1395
|
if (type === 'domain') {
|
|
1333
|
-
await this.
|
|
1334
|
-
// Also remove any existing records for this domain from SHIP and SLAP
|
|
1335
|
-
const db = this.ensureMongo();
|
|
1336
|
-
const [shipDeleted, slapDeleted] = await Promise.all([
|
|
1337
|
-
db.collection('shipRecords').deleteMany({ domain: value }),
|
|
1338
|
-
db.collection('slapRecords').deleteMany({ domain: value })
|
|
1339
|
-
]);
|
|
1340
|
-
return res.status(200).json({
|
|
1341
|
-
status: 'success',
|
|
1342
|
-
message: `Domain "${value}" banned. Removed ${shipDeleted.deletedCount} SHIP and ${slapDeleted.deletedCount} SLAP records.`
|
|
1343
|
-
});
|
|
1344
|
-
}
|
|
1345
|
-
else {
|
|
1346
|
-
// Parse outpoint: "txid.outputIndex"
|
|
1347
|
-
const dotIndex = value.lastIndexOf('.');
|
|
1348
|
-
if (dotIndex === -1) {
|
|
1349
|
-
return res.status(400).json({ status: 'error', message: 'Outpoint format must be "txid.outputIndex"' });
|
|
1350
|
-
}
|
|
1351
|
-
const txid = value.substring(0, dotIndex);
|
|
1352
|
-
const outputIndex = parseInt(value.substring(dotIndex + 1));
|
|
1353
|
-
if (isNaN(outputIndex)) {
|
|
1354
|
-
return res.status(400).json({ status: 'error', message: 'Invalid outputIndex in outpoint' });
|
|
1355
|
-
}
|
|
1356
|
-
await this.banService.banOutpoint(txid, outputIndex, reason);
|
|
1357
|
-
// Also evict from lookup services
|
|
1358
|
-
const services = Object.values(engine.lookupServices);
|
|
1359
|
-
for (const service of services) {
|
|
1360
|
-
try {
|
|
1361
|
-
await service.outputEvicted(txid, outputIndex);
|
|
1362
|
-
}
|
|
1363
|
-
catch {
|
|
1364
|
-
continue;
|
|
1365
|
-
}
|
|
1366
|
-
}
|
|
1367
|
-
return res.status(200).json({
|
|
1368
|
-
status: 'success',
|
|
1369
|
-
message: `Outpoint "${value}" banned and evicted from lookup services.`
|
|
1370
|
-
});
|
|
1396
|
+
return await this.handleBanDomain(res, value, reason);
|
|
1371
1397
|
}
|
|
1398
|
+
return await this.handleBanOutpoint(res, engine, value, reason);
|
|
1372
1399
|
}
|
|
1373
1400
|
catch (error) {
|
|
1374
1401
|
return res.status(400).json({
|
|
@@ -1441,55 +1468,30 @@ class OverlayExpress {
|
|
|
1441
1468
|
this.app.post('/admin/remove-token', checkAdminAuth, (req, res) => {
|
|
1442
1469
|
;
|
|
1443
1470
|
(async () => {
|
|
1444
|
-
var _a;
|
|
1445
1471
|
try {
|
|
1446
1472
|
const { txid, outputIndex, service, ban, banDomain: shouldBanDomain } = req.body;
|
|
1447
1473
|
if (typeof txid !== 'string' || typeof outputIndex !== 'number') {
|
|
1448
1474
|
return res.status(400).json({ status: 'error', message: 'txid (string) and outputIndex (number) are required' });
|
|
1449
1475
|
}
|
|
1450
|
-
//
|
|
1476
|
+
// Look up domain before eviction if needed for banning
|
|
1451
1477
|
let removedDomain;
|
|
1452
1478
|
if (shouldBanDomain === true || ban === true) {
|
|
1453
|
-
|
|
1454
|
-
const shipRecord = await db.collection('shipRecords').findOne({ txid, outputIndex });
|
|
1455
|
-
const slapRecord = await db.collection('slapRecords').findOne({ txid, outputIndex });
|
|
1456
|
-
removedDomain = ((_a = shipRecord === null || shipRecord === void 0 ? void 0 : shipRecord.domain) !== null && _a !== void 0 ? _a : slapRecord === null || slapRecord === void 0 ? void 0 : slapRecord.domain);
|
|
1479
|
+
removedDomain = await this.lookupDomainForOutpoint(txid, outputIndex);
|
|
1457
1480
|
}
|
|
1458
|
-
|
|
1459
|
-
if (typeof service === 'string') {
|
|
1460
|
-
const svc = engine.lookupServices[service];
|
|
1461
|
-
if (svc !== undefined) {
|
|
1462
|
-
await svc.outputEvicted(txid, outputIndex);
|
|
1463
|
-
}
|
|
1464
|
-
}
|
|
1465
|
-
else {
|
|
1466
|
-
const services = Object.values(engine.lookupServices);
|
|
1467
|
-
for (const svc of services) {
|
|
1468
|
-
try {
|
|
1469
|
-
await svc.outputEvicted(txid, outputIndex);
|
|
1470
|
-
}
|
|
1471
|
-
catch {
|
|
1472
|
-
continue;
|
|
1473
|
-
}
|
|
1474
|
-
}
|
|
1475
|
-
}
|
|
1476
|
-
// Ban the outpoint if requested
|
|
1481
|
+
await this.evictFromServices(engine, txid, outputIndex, service);
|
|
1477
1482
|
if (ban === true && this.banService !== undefined) {
|
|
1478
1483
|
await this.banService.banOutpoint(txid, outputIndex, 'Manually removed by admin', removedDomain);
|
|
1479
1484
|
}
|
|
1480
|
-
// Ban the domain if requested
|
|
1481
1485
|
if (shouldBanDomain === true && typeof removedDomain === 'string' && this.banService !== undefined) {
|
|
1482
|
-
await this.
|
|
1483
|
-
// Remove all records for this domain
|
|
1484
|
-
const banDb = this.ensureMongo();
|
|
1485
|
-
await Promise.all([
|
|
1486
|
-
banDb.collection('shipRecords').deleteMany({ domain: removedDomain }),
|
|
1487
|
-
banDb.collection('slapRecords').deleteMany({ domain: removedDomain })
|
|
1488
|
-
]);
|
|
1486
|
+
await this.banDomainAndRemoveRecords(removedDomain, 'Domain banned by admin via token removal');
|
|
1489
1487
|
}
|
|
1488
|
+
const banMsg = ban === true ? ' Outpoint banned.' : '';
|
|
1489
|
+
const domainMsg = shouldBanDomain === true && typeof removedDomain === 'string'
|
|
1490
|
+
? ` Domain "${removedDomain}" banned.`
|
|
1491
|
+
: '';
|
|
1490
1492
|
return res.status(200).json({
|
|
1491
1493
|
status: 'success',
|
|
1492
|
-
message: `Token ${txid}.${outputIndex} removed.${
|
|
1494
|
+
message: `Token ${txid}.${outputIndex} removed.${banMsg}${domainMsg}`
|
|
1493
1495
|
});
|
|
1494
1496
|
}
|
|
1495
1497
|
catch (error) {
|
|
@@ -1563,9 +1565,9 @@ class OverlayExpress {
|
|
|
1563
1565
|
}
|
|
1564
1566
|
else {
|
|
1565
1567
|
const services = Object.values(engine.lookupServices);
|
|
1566
|
-
for (
|
|
1568
|
+
for (const service of services) {
|
|
1567
1569
|
try {
|
|
1568
|
-
await
|
|
1570
|
+
await service.outputEvicted(req.body.txid, req.body.outputIndex);
|
|
1569
1571
|
}
|
|
1570
1572
|
catch {
|
|
1571
1573
|
continue;
|