feed: subscribe to pow events
ci/woodpecker/pr/woodpecker Pipeline was successful Details
ci/woodpecker/push/woodpecker Pipeline was successful Details

if difficulty-filter is set the subscription of the global feed
can filter only ids with 0-prefix to save bandwidth.

as there may not be many pow events within the last 24h, the
date range is now only enabled if there is no diffculty-filter
set so that the feed is not empty.

if this works as expected it could also only subscripe to
reactions and profile info with pow ids.

deps: update nostr-tools to 1.10.1

This version supports subscribing to prefixed ids, see
3bdb68020d
pull/75/head
OFF0 1 year ago
parent cb04e2c6b7
commit 5e61dcef0c
Signed by: offbyn
GPG Key ID: 94A2F643C51F37FA

100
package-lock.json generated

@ -8,7 +8,7 @@
"name": "nostrweb",
"version": "0.0.28",
"dependencies": {
"nostr-tools": "1.6.0"
"nostr-tools": "1.10.1"
},
"devDependencies": {
"@esbuild-plugins/node-globals-polyfill": "^0.1.1",
@ -43,24 +43,10 @@
"node": ">=12"
}
},
"node_modules/@noble/curves": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/@noble/curves/-/curves-1.0.0.tgz",
"integrity": "sha512-2upgEu0iLiDVDZkNLeFV2+ht0BAVgQnEmCk6JsOch9Rp8xfkMCbvbAZlA2pBHQc73dbl+vFOXfqkf4uemdn0bw==",
"funding": [
{
"type": "individual",
"url": "https://paulmillr.com/funding/"
}
],
"dependencies": {
"@noble/hashes": "1.3.0"
}
},
"node_modules/@noble/curves/node_modules/@noble/hashes": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.3.0.tgz",
"integrity": "sha512-ilHEACi9DwqJB0pw7kv+Apvh50jiiSyR/cQ3y4W7lOR5mhvn/50FLUfsnfJz0BDZtl/RR16kXvptiv6q1msYZg==",
"node_modules/@noble/hashes": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.2.0.tgz",
"integrity": "sha512-FZfhjEDbT5GRswV3C6uvLPHMiVD6lQBmpoX5+eSiPaMTXte/IKqI5dykDxzZB/WBeK/CDuQRBWarPdi3FNY2zQ==",
"funding": [
{
"type": "individual",
@ -68,11 +54,6 @@
}
]
},
"node_modules/@noble/hashes": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.0.0.tgz",
"integrity": "sha512-DZVbtY62kc3kkBtMHqwCOfXrT/hnoORy5BJ4+HU1IR59X0KWAOqsfzQPcUl/lQLlG7qXbe/fZ3r/emxtAl+sqg=="
},
"node_modules/@noble/secp256k1": {
"version": "1.7.1",
"resolved": "https://registry.npmjs.org/@noble/secp256k1/-/secp256k1-1.7.1.tgz",
@ -96,9 +77,9 @@
]
},
"node_modules/@scure/bip32": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/@scure/bip32/-/bip32-1.3.0.tgz",
"integrity": "sha512-bcKpo1oj54hGholplGLpqPHRbIsnbixFtc06nwuNM5/dwSXOq/AAYoIBRsBmnZJSdfeNW5rnff7NTAz3ZCqR9Q==",
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/@scure/bip32/-/bip32-1.1.4.tgz",
"integrity": "sha512-m925ACYK0wPELsF7Z/VdLGmKj1StIeHraPMYB9xiAFiq/PnvqWd/99I0TQ2OZhjjlMDsDJeZlyXMWi0beaA7NA==",
"funding": [
{
"type": "individual",
@ -106,26 +87,15 @@
}
],
"dependencies": {
"@noble/curves": "~1.0.0",
"@noble/hashes": "~1.3.0",
"@noble/hashes": "~1.2.0",
"@noble/secp256k1": "~1.7.0",
"@scure/base": "~1.1.0"
}
},
"node_modules/@scure/bip32/node_modules/@noble/hashes": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.3.0.tgz",
"integrity": "sha512-ilHEACi9DwqJB0pw7kv+Apvh50jiiSyR/cQ3y4W7lOR5mhvn/50FLUfsnfJz0BDZtl/RR16kXvptiv6q1msYZg==",
"funding": [
{
"type": "individual",
"url": "https://paulmillr.com/funding/"
}
]
},
"node_modules/@scure/bip39": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/@scure/bip39/-/bip39-1.2.0.tgz",
"integrity": "sha512-SX/uKq52cuxm4YFXWFaVByaSHJh2w3BnokVSeUJVCv6K7WulT9u2BuNRBhuFl8vAuYnzx9bEu9WgpcNYTrYieg==",
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/@scure/bip39/-/bip39-1.1.1.tgz",
"integrity": "sha512-t+wDck2rVkh65Hmv280fYdVdY25J9YeEUIgn2LG1WM6gxFkGzcksoDiUkWVpVp3Oex9xGC68JU2dSbUfwZ2jPg==",
"funding": [
{
"type": "individual",
@ -133,21 +103,10 @@
}
],
"dependencies": {
"@noble/hashes": "~1.3.0",
"@noble/hashes": "~1.2.0",
"@scure/base": "~1.1.0"
}
},
"node_modules/@scure/bip39/node_modules/@noble/hashes": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.3.0.tgz",
"integrity": "sha512-ilHEACi9DwqJB0pw7kv+Apvh50jiiSyR/cQ3y4W7lOR5mhvn/50FLUfsnfJz0BDZtl/RR16kXvptiv6q1msYZg==",
"funding": [
{
"type": "individual",
"url": "https://paulmillr.com/funding/"
}
]
},
"node_modules/abort-controller": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/abort-controller/-/abort-controller-3.0.0.tgz",
@ -605,30 +564,15 @@
]
},
"node_modules/nostr-tools": {
"version": "1.6.0",
"resolved": "https://registry.npmjs.org/nostr-tools/-/nostr-tools-1.6.0.tgz",
"integrity": "sha512-qjjJQ7YxJUMzgS24eVlxkZ87PKJtU6dlH04OzVuK6w+GSPL+VdUZkMe2lfSpnb7OkCrDIzmbFbtx+Q4LXdU2xw==",
"version": "1.10.1",
"resolved": "https://registry.npmjs.org/nostr-tools/-/nostr-tools-1.10.1.tgz",
"integrity": "sha512-zgTYJeuZQ3CDASsmBEcB5i6V6l0IaA6cjnll6OVik3FoZcvbCaL7yP8I40hYnOIi3KlJykV7jEF9fn8h1NzMnA==",
"dependencies": {
"@noble/hashes": "1.0.0",
"@noble/secp256k1": "^1.7.1",
"@scure/base": "^1.1.1",
"@scure/bip32": "^1.1.5",
"@scure/bip39": "^1.1.1",
"prettier": "^2.8.4"
}
},
"node_modules/prettier": {
"version": "2.8.7",
"resolved": "https://registry.npmjs.org/prettier/-/prettier-2.8.7.tgz",
"integrity": "sha512-yPngTo3aXUUmyuTjeTUT75txrf+aMh9FiD7q9ZE/i6r0bPb22g4FsE6Y338PQX1bmfy08i9QQCB7/rcUAVntfw==",
"bin": {
"prettier": "bin-prettier.js"
},
"engines": {
"node": ">=10.13.0"
},
"funding": {
"url": "https://github.com/prettier/prettier?sponsor=1"
"@noble/hashes": "1.2.0",
"@noble/secp256k1": "1.7.1",
"@scure/base": "1.1.1",
"@scure/bip32": "1.1.4",
"@scure/bip39": "1.1.1"
}
},
"node_modules/process": {

@ -11,7 +11,7 @@
"readable-stream": "4.3.0"
},
"dependencies": {
"nostr-tools": "1.6.0"
"nostr-tools": "1.10.1"
},
"scripts": {
"build": "node tools/build.js",

@ -3,10 +3,10 @@ import {zeroLeadingBitsCount} from './utils/crypto';
import {elem} from './utils/dom';
import {bounce} from './utils/time';
import {isWssUrl} from './utils/url';
import {closeSettingsView, config, toggleSettingsView} from './settings';
import {sub24hFeed, subNote, subProfile} from './subscriptions'
import {getReplyTo, hasEventTag, isMention, sortByCreatedAt, sortEventCreatedAt} from './events';
import {clearView, getViewContent, getViewElem, getViewOptions, setViewElem, view} from './view';
import {closeSettingsView, config, toggleSettingsView} from './settings';
import {handleReaction, handleUpvote} from './reactions';
import {closePublishView, openWriteInput, togglePublishView} from './write';
import {handleMetadata, renderProfile} from './profiles';

@ -1,5 +1,6 @@
import {Event} from 'nostr-tools';
import {getReplyTo, hasEventTag, isMention} from './events';
import {config} from './settings';
import {sub, subOnce, unsubAll} from './relays';
type SubCallback = (
@ -13,6 +14,7 @@ export const sub24hFeed = (onEvent: SubCallback) => {
const now = Math.floor(Date.now() * 0.001);
const pubkeys = new Set<string>();
const notes = new Set<string>();
const prefix = Math.floor(config.filterDifficulty / 4); // 4 bits in each '0' character
sub({ // get past events
cb: (evt, relay) => {
pubkeys.add(evt.pubkey);
@ -20,9 +22,10 @@ export const sub24hFeed = (onEvent: SubCallback) => {
onEvent(evt, relay);
},
filter: {
...(prefix && {ids: ['0'.repeat(prefix)]}),
kinds: [1],
until: now,
since: Math.floor(now - (24 * 60 * 60)),
...(!prefix && {since: Math.floor(now - (24 * 60 * 60))}),
limit: 100,
},
unsub: true
@ -76,6 +79,7 @@ export const sub24hFeed = (onEvent: SubCallback) => {
});
},
filter: {
...(prefix && {ids: ['0'.repeat(prefix)]}),
kinds: [0, 1, 7],
since: now,
},

Loading…
Cancel
Save