UNPKG

@bsv/overlay-express

Version:
71 lines 2.81 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BanAwareTopicManager = void 0; const sdk_1 = require("@bsv/sdk"); /** * Filters banned SHIP or SLAP advertisement outputs before the overlay engine * admits them into topic storage. */ class BanAwareTopicManager { constructor(wrapped, banService, protocol, logger = console) { this.wrapped = wrapped; this.banService = banService; this.protocol = protocol; this.logger = logger; } async identifyAdmissibleOutputs(beef, previousCoins, offChainValues, mode) { const instructions = await this.wrapped.identifyAdmissibleOutputs(beef, previousCoins, offChainValues, mode); if (instructions.outputsToAdmit.length === 0) return instructions; let tx; try { tx = sdk_1.Transaction.fromBEEF(beef); } catch { return instructions; } const txid = tx.id('hex'); const outputsToAdmit = []; for (const outputIndex of instructions.outputsToAdmit) { if (await this.banService.isOutpointBanned(txid, outputIndex)) { this.logger.log(`[BAN] Blocked banned outpoint ${txid}.${outputIndex} from ${this.protocol} topic admittance`); continue; } const output = tx.outputs[outputIndex]; if (output === undefined) continue; try { const result = sdk_1.PushDrop.decode(output.lockingScript); if (result.fields.length >= 3 && sdk_1.Utils.toUTF8(result.fields[0]) === this.protocol) { const domain = sdk_1.Utils.toUTF8(result.fields[2]); if (await this.banService.isDomainBanned(domain)) { this.logger.log(`[BAN] Blocked banned domain ${domain} from ${this.protocol} topic admittance (${txid}.${outputIndex})`); continue; } } } catch { // Non PushDrop outputs remain subject to the wrapped manager's decision. } outputsToAdmit.push(outputIndex); } return { ...instructions, outputsToAdmit }; } async identifyNeededInputs(beef, offChainValues) { if (typeof this.wrapped.identifyNeededInputs === 'function') { return await this.wrapped.identifyNeededInputs(beef, offChainValues); } return []; } async getDocumentation() { return await this.wrapped.getDocumentation(); } async getMetaData() { return await this.wrapped.getMetaData(); } } exports.BanAwareTopicManager = BanAwareTopicManager; //# sourceMappingURL=BanAwareTopicManager.js.map