@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
package/dist/esm/mod.js
CHANGED
|
@@ -2,4 +2,5 @@ export { default } from './src/OverlayExpress.js';
|
|
|
2
2
|
export { BanService } from './src/BanService.js';
|
|
3
3
|
export { BanAwareLookupWrapper } from './src/BanAwareLookupWrapper.js';
|
|
4
4
|
export { JanitorService } from './src/JanitorService.js';
|
|
5
|
+
export { OverlayMonitor, analyzeOverlayLookupResponse } from './src/OverlayMonitor.js';
|
|
5
6
|
//# sourceMappingURL=mod.js.map
|
package/dist/esm/mod.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.js","sourceRoot":"","sources":["../../mod.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EAQR,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAAE,UAAU,EAAqB,MAAM,qBAAqB,CAAA;AACnE,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAA;AACtE,OAAO,EAAE,cAAc,EAAiE,MAAM,yBAAyB,CAAA"}
|
|
1
|
+
{"version":3,"file":"mod.js","sourceRoot":"","sources":["../../mod.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EAQR,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAAE,UAAU,EAAqB,MAAM,qBAAqB,CAAA;AACnE,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAA;AACtE,OAAO,EAAE,cAAc,EAAiE,MAAM,yBAAyB,CAAA;AACvH,OAAO,EACL,cAAc,EACd,4BAA4B,EAU7B,MAAM,yBAAyB,CAAA"}
|
|
@@ -18,7 +18,7 @@ export class BanService {
|
|
|
18
18
|
*/
|
|
19
19
|
sanitize(value) {
|
|
20
20
|
if (typeof value !== 'string') {
|
|
21
|
-
throw new
|
|
21
|
+
throw new TypeError('Invalid input: expected a string value');
|
|
22
22
|
}
|
|
23
23
|
return value;
|
|
24
24
|
}
|
|
@@ -66,7 +66,7 @@ export class BanService {
|
|
|
66
66
|
$set: {
|
|
67
67
|
type: 'outpoint',
|
|
68
68
|
value,
|
|
69
|
-
domain: domain
|
|
69
|
+
domain: domain != null ? this.sanitize(domain) : undefined,
|
|
70
70
|
reason: reason ?? 'Manually banned',
|
|
71
71
|
bannedAt: new Date(),
|
|
72
72
|
bannedBy
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BanService.js","sourceRoot":"","sources":["../../../src/BanService.ts"],"names":[],"mappings":"AAoBA;;;;;;;GAOG;AACH,MAAM,OAAO,UAAU;IACJ,IAAI,CAA0B;IAE/C,YAAa,EAAM;QACjB,IAAI,CAAC,IAAI,GAAG,EAAE,CAAC,UAAU,CAAe,eAAe,CAAC,CAAA;IAC1D,CAAC;IAED;;;;OAIG;IACK,QAAQ,CAAE,KAAc;QAC9B,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YAC9B,MAAM,IAAI,
|
|
1
|
+
{"version":3,"file":"BanService.js","sourceRoot":"","sources":["../../../src/BanService.ts"],"names":[],"mappings":"AAoBA;;;;;;;GAOG;AACH,MAAM,OAAO,UAAU;IACJ,IAAI,CAA0B;IAE/C,YAAa,EAAM;QACjB,IAAI,CAAC,IAAI,GAAG,EAAE,CAAC,UAAU,CAAe,eAAe,CAAC,CAAA;IAC1D,CAAC;IAED;;;;OAIG;IACK,QAAQ,CAAE,KAAc;QAC9B,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YAC9B,MAAM,IAAI,SAAS,CAAC,wCAAwC,CAAC,CAAA;QAC/D,CAAC;QACD,OAAO,KAAK,CAAA;IACd,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,aAAa;QACjB,MAAM,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAA;QACpE,MAAM,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,EAAE,CAAC,CAAA;IAC/C,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,SAAS,CAAE,MAAc,EAAE,MAAe,EAAE,QAAiB;QACjE,MAAM,UAAU,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,KAAK,CAAC,SAAS,CAAE,IAA2B,EAAE,KAAa;QACzD,MAAM,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAA0B,EAAE,KAAK,EAAE,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;IAChH,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,QAAQ;QACZ,MAAM,CAAC,UAAU,EAAE,YAAY,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;YACnD,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;YAC5C,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC;SAC/C,CAAC,CAAA;QACF,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,SAAS,EAAE,UAAU,GAAG,YAAY,EAAE,CAAA;IAC3E,CAAC;CACF"}
|
|
@@ -7,7 +7,7 @@ import { MongoClient } from 'mongodb';
|
|
|
7
7
|
import makeUserInterface from './makeUserInterface.js';
|
|
8
8
|
import * as DiscoveryServices from '@bsv/overlay-discovery-services';
|
|
9
9
|
import chalk from 'chalk';
|
|
10
|
-
import util from 'util';
|
|
10
|
+
import util from 'node:util';
|
|
11
11
|
import { v4 as uuidv4 } from 'uuid';
|
|
12
12
|
import { JanitorService } from './JanitorService.js';
|
|
13
13
|
import { BanService } from './BanService.js';
|
|
@@ -87,6 +87,8 @@ export default class OverlayExpress {
|
|
|
87
87
|
enableGASPSync = true;
|
|
88
88
|
// ARC API Key
|
|
89
89
|
arcApiKey = undefined;
|
|
90
|
+
// Optional ARC callback token for /arc-ingest notifications
|
|
91
|
+
arcCallbackToken = undefined;
|
|
90
92
|
// Verbose request logging
|
|
91
93
|
verboseRequestLogging = false;
|
|
92
94
|
// Web UI configuration
|
|
@@ -240,6 +242,14 @@ export default class OverlayExpress {
|
|
|
240
242
|
this.arcApiKey = apiKey;
|
|
241
243
|
this.logger.log(chalk.blue('ARC API key has been configured.'));
|
|
242
244
|
}
|
|
245
|
+
/**
|
|
246
|
+
* Configures the ARC callback token expected by /arc-ingest.
|
|
247
|
+
* @param token - The token ARC should present when posting callback notifications.
|
|
248
|
+
*/
|
|
249
|
+
configureArcCallbackToken(token) {
|
|
250
|
+
this.arcCallbackToken = token;
|
|
251
|
+
this.logger.log(chalk.blue('ARC callback token has been configured.'));
|
|
252
|
+
}
|
|
243
253
|
/**
|
|
244
254
|
* Enables or disables GASP synchronization (high-level setting).
|
|
245
255
|
* This is a broad toggle that can be overridden or customized through syncConfiguration.
|
|
@@ -259,7 +269,7 @@ export default class OverlayExpress {
|
|
|
259
269
|
}
|
|
260
270
|
/**
|
|
261
271
|
* Configure Knex (SQL) database connection.
|
|
262
|
-
* @param config - Knex configuration object, or MySQL connection string
|
|
272
|
+
* @param config - Knex configuration object, or a MySQL connection string loaded from configuration.
|
|
263
273
|
*/
|
|
264
274
|
async configureKnex(config) {
|
|
265
275
|
if (typeof config === 'string') {
|
|
@@ -362,126 +372,100 @@ export default class OverlayExpress {
|
|
|
362
372
|
async configureEngine(autoConfigureShipSlap = true) {
|
|
363
373
|
const knex = this.ensureKnex();
|
|
364
374
|
if (autoConfigureShipSlap) {
|
|
365
|
-
// Auto-configure SHIP and SLAP services
|
|
366
375
|
this.configureTopicManager('tm_ship', new DiscoveryServices.SHIPTopicManager());
|
|
367
376
|
this.configureTopicManager('tm_slap', new DiscoveryServices.SLAPTopicManager());
|
|
368
377
|
this.configureLookupServiceWithMongo('ls_ship', (db) => new DiscoveryServices.SHIPLookupService(new DiscoveryServices.SHIPStorage(db)));
|
|
369
378
|
this.configureLookupServiceWithMongo('ls_slap', (db) => new DiscoveryServices.SLAPLookupService(new DiscoveryServices.SLAPStorage(db)));
|
|
370
379
|
}
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
380
|
+
this.wrapBanAwareServices();
|
|
381
|
+
const syncConfig = this.buildSyncConfig();
|
|
382
|
+
const storage = new KnexStorage(knex);
|
|
383
|
+
this.migrationsToRun = [...KnexStorageMigrations.default, ...this.migrationsToRun];
|
|
384
|
+
const broadcaster = this.buildBroadcaster();
|
|
385
|
+
const advertiser = await this.buildAdvertiser();
|
|
386
|
+
this.engine = new Engine(this.managers, this.services, storage, this.engineConfig.chainTracker ?? this.chainTracker, `https://${this.advertisableFQDN}`, this.network === 'test'
|
|
387
|
+
? (this.engineConfig.shipTrackers ?? DEFAULT_TESTNET_SLAP_TRACKERS)
|
|
388
|
+
: this.engineConfig.shipTrackers, this.resolveSlapTrackers(), broadcaster ?? this.engineConfig.broadcaster, advertiser, syncConfig, this.engineConfig.logTime ?? false, this.engineConfig.logPrefix ?? '[OVERLAY_ENGINE] ', this.engineConfig.throwOnBroadcastFailure ?? false, this.engineConfig.overlayBroadcastFacilitator ?? new HTTPSOverlayBroadcastFacilitator(), this.logger, this.engineConfig.suppressDefaultSyncAdvertisements ?? true);
|
|
389
|
+
this.initServerWallet();
|
|
390
|
+
this.logger.log(chalk.green('Engine has been configured.'));
|
|
391
|
+
}
|
|
392
|
+
/** Wrap SHIP/SLAP with ban-aware filter if BanService is configured. */
|
|
393
|
+
wrapBanAwareServices() {
|
|
394
|
+
if (this.banService === undefined)
|
|
395
|
+
return;
|
|
396
|
+
for (const key of ['ls_ship', 'ls_slap']) {
|
|
397
|
+
if (this.services[key] !== undefined) {
|
|
398
|
+
const label = key === 'ls_ship' ? 'SHIP' : 'SLAP';
|
|
399
|
+
this.services[key] = new BanAwareLookupWrapper(this.services[key], this.banService, label, this.logger);
|
|
400
|
+
this.logger.log(chalk.blue(`${label} lookup service wrapped with ban-aware filter.`));
|
|
381
401
|
}
|
|
382
402
|
}
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
syncConfig[managerName] = false;
|
|
389
|
-
}
|
|
403
|
+
}
|
|
404
|
+
/** Build the sync config based on enableGASPSync and engineConfig. */
|
|
405
|
+
buildSyncConfig() {
|
|
406
|
+
if (this.enableGASPSync) {
|
|
407
|
+
return this.engineConfig.syncConfiguration ?? {};
|
|
390
408
|
}
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
syncConfig =
|
|
409
|
+
const syncConfig = {};
|
|
410
|
+
for (const name of Object.keys(this.managers)) {
|
|
411
|
+
syncConfig[name] = false;
|
|
394
412
|
}
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
this.
|
|
405
|
-
|
|
406
|
-
|
|
413
|
+
return syncConfig;
|
|
414
|
+
}
|
|
415
|
+
/** Build the ARC broadcaster if an API key is configured. */
|
|
416
|
+
buildBroadcaster() {
|
|
417
|
+
if (typeof this.arcApiKey !== 'string')
|
|
418
|
+
return undefined;
|
|
419
|
+
const arcUrl = this.network === 'test' ? 'https://arc-test.taal.com' : 'https://arc.taal.com';
|
|
420
|
+
return new ARC(arcUrl, {
|
|
421
|
+
apiKey: this.arcApiKey,
|
|
422
|
+
callbackUrl: `https://${this.advertisableFQDN}/arc-ingest`,
|
|
423
|
+
callbackToken: this.arcCallbackToken
|
|
424
|
+
});
|
|
425
|
+
}
|
|
426
|
+
/** Resolve the SLAP trackers from config or network defaults. */
|
|
427
|
+
resolveSlapTrackers() {
|
|
428
|
+
if (Array.isArray(this.engineConfig.slapTrackers))
|
|
429
|
+
return this.engineConfig.slapTrackers;
|
|
430
|
+
return this.network === 'test' ? DEFAULT_TESTNET_SLAP_TRACKERS : DEFAULT_SLAP_TRACKERS;
|
|
431
|
+
}
|
|
432
|
+
/** Build the WalletAdvertiser (or use user-provided one). */
|
|
433
|
+
async buildAdvertiser() {
|
|
434
|
+
if (this.engineConfig.advertiser !== undefined)
|
|
435
|
+
return this.engineConfig.advertiser;
|
|
436
|
+
const storageBase = this.network === 'test'
|
|
437
|
+
? 'https://staging-storage.babbage.systems'
|
|
438
|
+
: 'https://storage.babbage.systems';
|
|
439
|
+
try {
|
|
440
|
+
return new DiscoveryServices.WalletAdvertiser(this.network, this.privateKey, storageBase, `https://${this.advertisableFQDN}`);
|
|
407
441
|
}
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
try {
|
|
412
|
-
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.
|
|
413
|
-
? 'https://staging-storage.babbage.systems'
|
|
414
|
-
: 'https://storage.babbage.systems',
|
|
415
|
-
// Until multiple protocols (like https+bsvauth+smf) are fully supported, HTTPS is the one to always use.
|
|
416
|
-
`https://${this.advertisableFQDN}`);
|
|
417
|
-
}
|
|
418
|
-
catch (e) {
|
|
419
|
-
this.logger.log(`Advertiser not initialized for FQDN ${this.advertisableFQDN} - SHIP and SLAP will be disabled.`);
|
|
420
|
-
}
|
|
442
|
+
catch (e) {
|
|
443
|
+
this.logger.log(`Advertiser not initialized for FQDN ${this.advertisableFQDN} - SHIP and SLAP will be disabled. Reason: ${e}`);
|
|
444
|
+
return undefined;
|
|
421
445
|
}
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
typeof this.engineConfig.chainTracker !== 'undefined'
|
|
426
|
-
? this.engineConfig.chainTracker
|
|
427
|
-
: this.chainTracker,
|
|
428
|
-
// hostingURL
|
|
429
|
-
`https://${this.advertisableFQDN}`,
|
|
430
|
-
// shipTrackers
|
|
431
|
-
this.network === 'test'
|
|
432
|
-
? (this.engineConfig.shipTrackers ?? DEFAULT_TESTNET_SLAP_TRACKERS)
|
|
433
|
-
: this.engineConfig.shipTrackers,
|
|
434
|
-
// slapTrackers
|
|
435
|
-
Array.isArray(this.engineConfig.slapTrackers)
|
|
436
|
-
? this.engineConfig.slapTrackers
|
|
437
|
-
: this.network === 'test'
|
|
438
|
-
? DEFAULT_TESTNET_SLAP_TRACKERS
|
|
439
|
-
: DEFAULT_SLAP_TRACKERS,
|
|
440
|
-
// broadcaster
|
|
441
|
-
broadcaster ?? this.engineConfig.broadcaster,
|
|
442
|
-
// advertiser
|
|
443
|
-
advertiser,
|
|
444
|
-
// syncConfiguration
|
|
445
|
-
syncConfig,
|
|
446
|
-
// logTime
|
|
447
|
-
this.engineConfig.logTime ?? false,
|
|
448
|
-
// logPrefix
|
|
449
|
-
this.engineConfig.logPrefix ?? '[OVERLAY_ENGINE] ',
|
|
450
|
-
// throwOnBroadcastFailure
|
|
451
|
-
this.engineConfig.throwOnBroadcastFailure ?? false,
|
|
452
|
-
// overlayBroadcastFacilitator
|
|
453
|
-
this.engineConfig.overlayBroadcastFacilitator ?? new HTTPSOverlayBroadcastFacilitator(),
|
|
454
|
-
// logger
|
|
455
|
-
this.logger,
|
|
456
|
-
// suppressDefaultSyncAdvertisements
|
|
457
|
-
this.engineConfig.suppressDefaultSyncAdvertisements ?? true);
|
|
458
|
-
// Create the server wallet for BSV mutual authentication.
|
|
459
|
-
// This uses the same private key as the WalletAdvertiser.
|
|
446
|
+
}
|
|
447
|
+
/** Initialize the server wallet for BSV mutual authentication. */
|
|
448
|
+
initServerWallet() {
|
|
460
449
|
try {
|
|
461
450
|
const keyDeriver = new KeyDeriver(new PrivateKey(this.privateKey, 'hex'));
|
|
462
451
|
const storageManager = new WalletStorageManager(keyDeriver.identityKey);
|
|
463
452
|
const signer = new WalletSigner(this.network, keyDeriver, storageManager);
|
|
464
453
|
const services = new Services(this.network);
|
|
465
|
-
|
|
466
|
-
this.
|
|
467
|
-
// Auto-set the admin identity key from the server's own key if not configured
|
|
468
|
-
if (typeof this.adminIdentityKey === 'undefined') {
|
|
469
|
-
this.adminIdentityKey = keyDeriver.identityKey;
|
|
470
|
-
}
|
|
454
|
+
this.serverWallet = new Wallet(signer, services);
|
|
455
|
+
this.adminIdentityKey ??= keyDeriver.identityKey;
|
|
471
456
|
this.logger.log(chalk.blue('Server wallet initialized for BSV mutual authentication.'));
|
|
472
457
|
}
|
|
473
458
|
catch (e) {
|
|
474
|
-
this.logger.log(chalk.yellow(
|
|
459
|
+
this.logger.log(chalk.yellow(`Server wallet could not be initialized. BSV auth will not be available. Reason: ${e}`));
|
|
475
460
|
}
|
|
476
|
-
this.logger.log(chalk.green('Engine has been configured.'));
|
|
477
461
|
}
|
|
478
462
|
/**
|
|
479
463
|
* Ensures that Knex is configured and returns it.
|
|
480
464
|
* @throws Error if Knex is not configured
|
|
481
465
|
*/
|
|
482
466
|
ensureKnex() {
|
|
483
|
-
if (
|
|
484
|
-
throw new
|
|
467
|
+
if (this.knex === undefined) {
|
|
468
|
+
throw new TypeError('You must configure your SQL database with the .configureKnex() method first!');
|
|
485
469
|
}
|
|
486
470
|
return this.knex;
|
|
487
471
|
}
|
|
@@ -490,8 +474,8 @@ export default class OverlayExpress {
|
|
|
490
474
|
* @throws Error if MongoDB is not configured
|
|
491
475
|
*/
|
|
492
476
|
ensureMongo() {
|
|
493
|
-
if (
|
|
494
|
-
throw new
|
|
477
|
+
if (this.mongoDb === undefined) {
|
|
478
|
+
throw new TypeError('You must configure your MongoDB connection with the .configureMongo() method first!');
|
|
495
479
|
}
|
|
496
480
|
return this.mongoDb;
|
|
497
481
|
}
|
|
@@ -500,8 +484,8 @@ export default class OverlayExpress {
|
|
|
500
484
|
* @throws Error if the Engine is not configured
|
|
501
485
|
*/
|
|
502
486
|
ensureEngine() {
|
|
503
|
-
if (
|
|
504
|
-
throw new
|
|
487
|
+
if (this.engine === undefined) {
|
|
488
|
+
throw new TypeError('You must configure your Overlay Services engine with the .configureEngine() method first!');
|
|
505
489
|
}
|
|
506
490
|
return this.engine;
|
|
507
491
|
}
|
|
@@ -519,6 +503,70 @@ export default class OverlayExpress {
|
|
|
519
503
|
autoBanOnRemoval: this.janitorConfig.autoBanOnRemoval
|
|
520
504
|
});
|
|
521
505
|
}
|
|
506
|
+
/** Ban a domain and remove all its SHIP/SLAP records from MongoDB. */
|
|
507
|
+
async handleBanDomain(res, value, reason) {
|
|
508
|
+
await this.banService.banDomain(value, reason);
|
|
509
|
+
const db = this.ensureMongo();
|
|
510
|
+
const [shipDeleted, slapDeleted] = await Promise.all([
|
|
511
|
+
db.collection('shipRecords').deleteMany({ domain: value }),
|
|
512
|
+
db.collection('slapRecords').deleteMany({ domain: value })
|
|
513
|
+
]);
|
|
514
|
+
return res.status(200).json({
|
|
515
|
+
status: 'success',
|
|
516
|
+
message: `Domain "${value}" banned. Removed ${shipDeleted.deletedCount} SHIP and ${slapDeleted.deletedCount} SLAP records.`
|
|
517
|
+
});
|
|
518
|
+
}
|
|
519
|
+
/** Parse outpoint string, ban it, and evict it from all lookup services. */
|
|
520
|
+
async handleBanOutpoint(res, engine, value, reason) {
|
|
521
|
+
const dotIndex = value.lastIndexOf('.');
|
|
522
|
+
if (dotIndex === -1) {
|
|
523
|
+
return res.status(400).json({ status: 'error', message: 'Outpoint format must be "txid.outputIndex"' });
|
|
524
|
+
}
|
|
525
|
+
const txid = value.substring(0, dotIndex);
|
|
526
|
+
const outputIndex = Number.parseInt(value.substring(dotIndex + 1));
|
|
527
|
+
if (Number.isNaN(outputIndex)) {
|
|
528
|
+
return res.status(400).json({ status: 'error', message: 'Invalid outputIndex in outpoint' });
|
|
529
|
+
}
|
|
530
|
+
await this.banService.banOutpoint(txid, outputIndex, reason);
|
|
531
|
+
await this.evictFromServices(engine, txid, outputIndex);
|
|
532
|
+
return res.status(200).json({
|
|
533
|
+
status: 'success',
|
|
534
|
+
message: `Outpoint "${value}" banned and evicted from lookup services.`
|
|
535
|
+
});
|
|
536
|
+
}
|
|
537
|
+
/** Evict an output from a specific service or all services (silent per-service errors). */
|
|
538
|
+
async evictFromServices(engine, txid, outputIndex, service) {
|
|
539
|
+
if (typeof service === 'string') {
|
|
540
|
+
const svc = engine.lookupServices[service];
|
|
541
|
+
if (svc !== undefined)
|
|
542
|
+
await svc.outputEvicted(txid, outputIndex);
|
|
543
|
+
return;
|
|
544
|
+
}
|
|
545
|
+
for (const svc of Object.values(engine.lookupServices)) {
|
|
546
|
+
try {
|
|
547
|
+
await svc.outputEvicted(txid, outputIndex);
|
|
548
|
+
}
|
|
549
|
+
catch { /* best-effort */ }
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
/** Look up the domain of an outpoint from SHIP or SLAP records. */
|
|
553
|
+
async lookupDomainForOutpoint(txid, outputIndex) {
|
|
554
|
+
const db = this.ensureMongo();
|
|
555
|
+
const [shipRecord, slapRecord] = await Promise.all([
|
|
556
|
+
db.collection('shipRecords').findOne({ txid, outputIndex }),
|
|
557
|
+
db.collection('slapRecords').findOne({ txid, outputIndex })
|
|
558
|
+
]);
|
|
559
|
+
return (shipRecord?.domain ?? slapRecord?.domain);
|
|
560
|
+
}
|
|
561
|
+
/** Ban a domain and delete all SHIP/SLAP records for it. */
|
|
562
|
+
async banDomainAndRemoveRecords(domain, reason) {
|
|
563
|
+
await this.banService.banDomain(domain, reason);
|
|
564
|
+
const db = this.ensureMongo();
|
|
565
|
+
await Promise.all([
|
|
566
|
+
db.collection('shipRecords').deleteMany({ domain }),
|
|
567
|
+
db.collection('slapRecords').deleteMany({ domain })
|
|
568
|
+
]);
|
|
569
|
+
}
|
|
522
570
|
async runHealthCheck(definition) {
|
|
523
571
|
const startedAt = Date.now();
|
|
524
572
|
try {
|
|
@@ -567,8 +615,8 @@ export default class OverlayExpress {
|
|
|
567
615
|
scope: 'ready',
|
|
568
616
|
critical: true,
|
|
569
617
|
handler: async () => {
|
|
570
|
-
if (
|
|
571
|
-
throw new
|
|
618
|
+
if (this.engine === undefined) {
|
|
619
|
+
throw new TypeError('Overlay engine is not configured');
|
|
572
620
|
}
|
|
573
621
|
return {
|
|
574
622
|
status: 'ok',
|
|
@@ -584,8 +632,8 @@ export default class OverlayExpress {
|
|
|
584
632
|
scope: 'ready',
|
|
585
633
|
critical: true,
|
|
586
634
|
handler: async () => {
|
|
587
|
-
if (
|
|
588
|
-
throw new
|
|
635
|
+
if (this.knex === undefined) {
|
|
636
|
+
throw new TypeError('Knex is not configured');
|
|
589
637
|
}
|
|
590
638
|
await this.knex.raw('select 1 as ok');
|
|
591
639
|
return {
|
|
@@ -601,8 +649,8 @@ export default class OverlayExpress {
|
|
|
601
649
|
scope: 'ready',
|
|
602
650
|
critical: true,
|
|
603
651
|
handler: async () => {
|
|
604
|
-
if (
|
|
605
|
-
throw new
|
|
652
|
+
if (this.mongoDb === undefined) {
|
|
653
|
+
throw new TypeError('MongoDB is not configured');
|
|
606
654
|
}
|
|
607
655
|
await this.mongoDb.command({ ping: 1 });
|
|
608
656
|
return {
|
|
@@ -653,7 +701,7 @@ export default class OverlayExpress {
|
|
|
653
701
|
port: this.port,
|
|
654
702
|
network: this.network,
|
|
655
703
|
startedAt: this.startTime?.toISOString(),
|
|
656
|
-
uptimeMs:
|
|
704
|
+
uptimeMs: this.startTime === undefined ? 0 : Date.now() - this.startTime.getTime(),
|
|
657
705
|
topicManagerCount: Object.keys(this.managers).length,
|
|
658
706
|
lookupServiceCount: Object.keys(this.services).length
|
|
659
707
|
},
|
|
@@ -898,7 +946,7 @@ export default class OverlayExpress {
|
|
|
898
946
|
const topicsHeader = req.headers['x-topics'];
|
|
899
947
|
const includesOffChain = req.headers['x-includes-off-chain-values'] === 'true';
|
|
900
948
|
if (typeof topicsHeader !== 'string') {
|
|
901
|
-
throw new
|
|
949
|
+
throw new TypeError('Missing x-topics header');
|
|
902
950
|
}
|
|
903
951
|
const topics = JSON.parse(topicsHeader);
|
|
904
952
|
let offChainValues;
|
|
@@ -1006,6 +1054,18 @@ export default class OverlayExpress {
|
|
|
1006
1054
|
;
|
|
1007
1055
|
(async () => {
|
|
1008
1056
|
try {
|
|
1057
|
+
if (typeof this.arcCallbackToken === 'string' && this.arcCallbackToken.length > 0) {
|
|
1058
|
+
const authorization = req.headers.authorization;
|
|
1059
|
+
const headerToken = Array.isArray(authorization) ? authorization[0] : authorization;
|
|
1060
|
+
const xCallbackToken = req.headers['x-callback-token'];
|
|
1061
|
+
const callbackToken = Array.isArray(xCallbackToken) ? xCallbackToken[0] : xCallbackToken;
|
|
1062
|
+
const bearerToken = typeof headerToken === 'string' && headerToken.startsWith('Bearer ')
|
|
1063
|
+
? headerToken.slice('Bearer '.length)
|
|
1064
|
+
: headerToken;
|
|
1065
|
+
if (bearerToken !== this.arcCallbackToken && callbackToken !== this.arcCallbackToken) {
|
|
1066
|
+
return res.status(401).json({ status: 'error', message: 'Unauthorized callback' });
|
|
1067
|
+
}
|
|
1068
|
+
}
|
|
1009
1069
|
const { txid, merklePath: merklePathHex, blockHeight } = req.body;
|
|
1010
1070
|
const merklePath = MerklePath.fromHex(merklePathHex);
|
|
1011
1071
|
await engine.handleNewMerkleProof(txid, merklePath, blockHeight);
|
|
@@ -1158,7 +1218,7 @@ export default class OverlayExpress {
|
|
|
1158
1218
|
data: {
|
|
1159
1219
|
nodeName: this.name,
|
|
1160
1220
|
network: this.network,
|
|
1161
|
-
uptime: this.startTime
|
|
1221
|
+
uptime: this.startTime != null ? Date.now() - this.startTime.getTime() : 0,
|
|
1162
1222
|
startedAt: this.startTime?.toISOString(),
|
|
1163
1223
|
shipRecordCount: shipCount,
|
|
1164
1224
|
slapRecordCount: slapCount,
|
|
@@ -1191,9 +1251,9 @@ export default class OverlayExpress {
|
|
|
1191
1251
|
const db = this.ensureMongo();
|
|
1192
1252
|
const collection = db.collection('shipRecords');
|
|
1193
1253
|
const search = typeof req.query.search === 'string' ? req.query.search : undefined;
|
|
1194
|
-
const rawPage = parseInt(req.query.page, 10);
|
|
1254
|
+
const rawPage = Number.parseInt(req.query.page, 10);
|
|
1195
1255
|
const page = Math.max(1, Number.isNaN(rawPage) ? 1 : rawPage);
|
|
1196
|
-
const rawLimit = parseInt(req.query.limit, 10);
|
|
1256
|
+
const rawLimit = Number.parseInt(req.query.limit, 10);
|
|
1197
1257
|
const limit = Math.min(200, Math.max(1, Number.isNaN(rawLimit) ? 50 : rawLimit));
|
|
1198
1258
|
const skip = (page - 1) * limit;
|
|
1199
1259
|
const query = {};
|
|
@@ -1234,9 +1294,9 @@ export default class OverlayExpress {
|
|
|
1234
1294
|
const db = this.ensureMongo();
|
|
1235
1295
|
const collection = db.collection('slapRecords');
|
|
1236
1296
|
const search = typeof req.query.search === 'string' ? req.query.search : undefined;
|
|
1237
|
-
const rawPage = parseInt(req.query.page, 10);
|
|
1297
|
+
const rawPage = Number.parseInt(req.query.page, 10);
|
|
1238
1298
|
const page = Math.max(1, Number.isNaN(rawPage) ? 1 : rawPage);
|
|
1239
|
-
const rawLimit = parseInt(req.query.limit, 10);
|
|
1299
|
+
const rawLimit = Number.parseInt(req.query.limit, 10);
|
|
1240
1300
|
const limit = Math.min(200, Math.max(1, Number.isNaN(rawLimit) ? 50 : rawLimit));
|
|
1241
1301
|
const skip = (page - 1) * limit;
|
|
1242
1302
|
const query = {};
|
|
@@ -1310,45 +1370,9 @@ export default class OverlayExpress {
|
|
|
1310
1370
|
return res.status(400).json({ status: 'error', message: 'value is required' });
|
|
1311
1371
|
}
|
|
1312
1372
|
if (type === 'domain') {
|
|
1313
|
-
await this.
|
|
1314
|
-
// Also remove any existing records for this domain from SHIP and SLAP
|
|
1315
|
-
const db = this.ensureMongo();
|
|
1316
|
-
const [shipDeleted, slapDeleted] = await Promise.all([
|
|
1317
|
-
db.collection('shipRecords').deleteMany({ domain: value }),
|
|
1318
|
-
db.collection('slapRecords').deleteMany({ domain: value })
|
|
1319
|
-
]);
|
|
1320
|
-
return res.status(200).json({
|
|
1321
|
-
status: 'success',
|
|
1322
|
-
message: `Domain "${value}" banned. Removed ${shipDeleted.deletedCount} SHIP and ${slapDeleted.deletedCount} SLAP records.`
|
|
1323
|
-
});
|
|
1324
|
-
}
|
|
1325
|
-
else {
|
|
1326
|
-
// Parse outpoint: "txid.outputIndex"
|
|
1327
|
-
const dotIndex = value.lastIndexOf('.');
|
|
1328
|
-
if (dotIndex === -1) {
|
|
1329
|
-
return res.status(400).json({ status: 'error', message: 'Outpoint format must be "txid.outputIndex"' });
|
|
1330
|
-
}
|
|
1331
|
-
const txid = value.substring(0, dotIndex);
|
|
1332
|
-
const outputIndex = parseInt(value.substring(dotIndex + 1));
|
|
1333
|
-
if (isNaN(outputIndex)) {
|
|
1334
|
-
return res.status(400).json({ status: 'error', message: 'Invalid outputIndex in outpoint' });
|
|
1335
|
-
}
|
|
1336
|
-
await this.banService.banOutpoint(txid, outputIndex, reason);
|
|
1337
|
-
// Also evict from lookup services
|
|
1338
|
-
const services = Object.values(engine.lookupServices);
|
|
1339
|
-
for (const service of services) {
|
|
1340
|
-
try {
|
|
1341
|
-
await service.outputEvicted(txid, outputIndex);
|
|
1342
|
-
}
|
|
1343
|
-
catch {
|
|
1344
|
-
continue;
|
|
1345
|
-
}
|
|
1346
|
-
}
|
|
1347
|
-
return res.status(200).json({
|
|
1348
|
-
status: 'success',
|
|
1349
|
-
message: `Outpoint "${value}" banned and evicted from lookup services.`
|
|
1350
|
-
});
|
|
1373
|
+
return await this.handleBanDomain(res, value, reason);
|
|
1351
1374
|
}
|
|
1375
|
+
return await this.handleBanOutpoint(res, engine, value, reason);
|
|
1352
1376
|
}
|
|
1353
1377
|
catch (error) {
|
|
1354
1378
|
return res.status(400).json({
|
|
@@ -1426,49 +1450,25 @@ export default class OverlayExpress {
|
|
|
1426
1450
|
if (typeof txid !== 'string' || typeof outputIndex !== 'number') {
|
|
1427
1451
|
return res.status(400).json({ status: 'error', message: 'txid (string) and outputIndex (number) are required' });
|
|
1428
1452
|
}
|
|
1429
|
-
//
|
|
1453
|
+
// Look up domain before eviction if needed for banning
|
|
1430
1454
|
let removedDomain;
|
|
1431
1455
|
if (shouldBanDomain === true || ban === true) {
|
|
1432
|
-
|
|
1433
|
-
const shipRecord = await db.collection('shipRecords').findOne({ txid, outputIndex });
|
|
1434
|
-
const slapRecord = await db.collection('slapRecords').findOne({ txid, outputIndex });
|
|
1435
|
-
removedDomain = (shipRecord?.domain ?? slapRecord?.domain);
|
|
1456
|
+
removedDomain = await this.lookupDomainForOutpoint(txid, outputIndex);
|
|
1436
1457
|
}
|
|
1437
|
-
|
|
1438
|
-
if (typeof service === 'string') {
|
|
1439
|
-
const svc = engine.lookupServices[service];
|
|
1440
|
-
if (svc !== undefined) {
|
|
1441
|
-
await svc.outputEvicted(txid, outputIndex);
|
|
1442
|
-
}
|
|
1443
|
-
}
|
|
1444
|
-
else {
|
|
1445
|
-
const services = Object.values(engine.lookupServices);
|
|
1446
|
-
for (const svc of services) {
|
|
1447
|
-
try {
|
|
1448
|
-
await svc.outputEvicted(txid, outputIndex);
|
|
1449
|
-
}
|
|
1450
|
-
catch {
|
|
1451
|
-
continue;
|
|
1452
|
-
}
|
|
1453
|
-
}
|
|
1454
|
-
}
|
|
1455
|
-
// Ban the outpoint if requested
|
|
1458
|
+
await this.evictFromServices(engine, txid, outputIndex, service);
|
|
1456
1459
|
if (ban === true && this.banService !== undefined) {
|
|
1457
1460
|
await this.banService.banOutpoint(txid, outputIndex, 'Manually removed by admin', removedDomain);
|
|
1458
1461
|
}
|
|
1459
|
-
// Ban the domain if requested
|
|
1460
1462
|
if (shouldBanDomain === true && typeof removedDomain === 'string' && this.banService !== undefined) {
|
|
1461
|
-
await this.
|
|
1462
|
-
// Remove all records for this domain
|
|
1463
|
-
const banDb = this.ensureMongo();
|
|
1464
|
-
await Promise.all([
|
|
1465
|
-
banDb.collection('shipRecords').deleteMany({ domain: removedDomain }),
|
|
1466
|
-
banDb.collection('slapRecords').deleteMany({ domain: removedDomain })
|
|
1467
|
-
]);
|
|
1463
|
+
await this.banDomainAndRemoveRecords(removedDomain, 'Domain banned by admin via token removal');
|
|
1468
1464
|
}
|
|
1465
|
+
const banMsg = ban === true ? ' Outpoint banned.' : '';
|
|
1466
|
+
const domainMsg = shouldBanDomain === true && typeof removedDomain === 'string'
|
|
1467
|
+
? ` Domain "${removedDomain}" banned.`
|
|
1468
|
+
: '';
|
|
1469
1469
|
return res.status(200).json({
|
|
1470
1470
|
status: 'success',
|
|
1471
|
-
message: `Token ${txid}.${outputIndex} removed.${
|
|
1471
|
+
message: `Token ${txid}.${outputIndex} removed.${banMsg}${domainMsg}`
|
|
1472
1472
|
});
|
|
1473
1473
|
}
|
|
1474
1474
|
catch (error) {
|
|
@@ -1542,9 +1542,9 @@ export default class OverlayExpress {
|
|
|
1542
1542
|
}
|
|
1543
1543
|
else {
|
|
1544
1544
|
const services = Object.values(engine.lookupServices);
|
|
1545
|
-
for (
|
|
1545
|
+
for (const service of services) {
|
|
1546
1546
|
try {
|
|
1547
|
-
await
|
|
1547
|
+
await service.outputEvicted(req.body.txid, req.body.outputIndex);
|
|
1548
1548
|
}
|
|
1549
1549
|
catch {
|
|
1550
1550
|
continue;
|