From ed56fe9e3833e9ea985f88ef261a8ca8bdc9b01c Mon Sep 17 00:00:00 2001 From: Daniel Gonzalez Date: Tue, 9 Sep 2025 18:27:27 -0400 Subject: [PATCH] feat(nostr): Removed entries from authors on the npub blacklist --- src/App.js | 1 + src/components/app-body/nostr-chat/index.js | 3 +- src/services/nostr-queries.js | 47 +++++++++++++++++++++ 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/src/App.js b/src/App.js index 579c5a0..9c8dec0 100644 --- a/src/App.js +++ b/src/App.js @@ -74,6 +74,7 @@ function App (props) { console.log('asyncInitStarted: ', appData.asyncInitStarted) console.log('is single view : ', singleView) + await appData.nostrQueries.start() if (!appData.asyncInitStarted && !singleView) { try { // Instantiate the async load object. diff --git a/src/components/app-body/nostr-chat/index.js b/src/components/app-body/nostr-chat/index.js index 095736e..d745fe4 100644 --- a/src/components/app-body/nostr-chat/index.js +++ b/src/components/app-body/nostr-chat/index.js @@ -203,7 +203,8 @@ function NostrChat (props) { pool.on('event', (relay, subId, ev) => { console.log('Group post retrieved from ', relay.url, ev.content) - onMsgRead(ev) + const onBlackList = nostrQueries.blackList.find((val) => { return val === ev.pubkey }) + if (!onBlackList)onMsgRead(ev) }) return () => { diff --git a/src/services/nostr-queries.js b/src/services/nostr-queries.js index 0b36508..d619a07 100644 --- a/src/services/nostr-queries.js +++ b/src/services/nostr-queries.js @@ -6,6 +6,7 @@ import { RelayPool } from 'nostr' import * as nip19 from 'nostr-tools/nip19' import { nip04 } from 'nostr-tools' import { hexToBytes } from '@noble/hashes/utils' // already an installed dependency +import axios from 'axios' export default class NostrQueries { constructor ({ relays }) { @@ -13,6 +14,17 @@ export default class NostrQueries { this.loadedProfiles = {} this.loadedChannelsInfo = {} + this.blackList = [] + this.blackListFetched = false + } + + async start () { + try { + await this.getBlackList() + } catch (error) { + console.error('NostrQueries.start() error : ', error.message) + throw error + } } setRelays (relays) { @@ -459,4 +471,39 @@ export default class NostrQueries { throw error } } + + async getBlackList () { + try { + if (this.blackListFetched) return + const opts = { + method: 'GET', + url: 'https://blacklists.psfoundation.info/nostr-chat-blacklist.json', + headers: { + 'Content-Type': 'application/json' + } + } + + const result = await axios.request(opts) + const { data } = result + const { npubs } = data + + // // Dev test mock npub for testing purposes + // const myNpubMock = 'npub1y3xq402pu9aqms3khetnt5gzm54t63pzcla56wwfmwshde0ws77qkff5gc' + // npubs.push(myNpubMock) + // // + + this.blackListFetched = true + for (let i = 0; i < npubs.length; i++) { + const npub = npubs[i] + const pubKey = this.npubToHex(npub) + this.blackList.push(pubKey) + } + console.log('BlackList ', this.blackList) + + return data + } catch (error) { + console.log('Error on getBlackList()') + throw error + } + } }