mirror of
https://github.com/nbd-wtf/nostr-tools.git
synced 2025-12-08 16:28:49 +00:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7447524028 |
1
nip06.js
1
nip06.js
@@ -1,5 +1,4 @@
|
||||
import createHmac from 'create-hmac'
|
||||
import randomBytes from 'randombytes'
|
||||
import * as bip39 from 'bip39'
|
||||
|
||||
export function privateKeyFromSeed(seed) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "nostr-tools",
|
||||
"version": "0.8.1",
|
||||
"version": "0.7.0",
|
||||
"description": "Tools for making a Nostr client.",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
8
pool.js
8
pool.js
@@ -29,23 +29,19 @@ export function relayPool(globalPrivateKey) {
|
||||
const activeFilters = filter
|
||||
|
||||
activeSubscriptions[id] = {
|
||||
sub: ({cb = activeCallback, filter = activeFilters}) => {
|
||||
sub: ({cb = activeCallback, filter = activeFilters}) =>
|
||||
Object.entries(subControllers).map(([relayURL, sub]) => [
|
||||
relayURL,
|
||||
sub.sub({cb, filter}, id)
|
||||
])
|
||||
return activeSubscriptions[id]
|
||||
},
|
||||
]),
|
||||
addRelay: relay => {
|
||||
subControllers[relay.url] = relay.sub({cb, filter})
|
||||
return activeSubscriptions[id]
|
||||
},
|
||||
removeRelay: relayURL => {
|
||||
if (relayURL in subControllers) {
|
||||
subControllers[relayURL].unsub()
|
||||
if (Object.keys(subControllers).length === 0) unsub()
|
||||
}
|
||||
return activeSubscriptions[id]
|
||||
},
|
||||
unsub: () => {
|
||||
Object.values(subControllers).forEach(sub => sub.unsub())
|
||||
|
||||
7
relay.js
7
relay.js
@@ -46,10 +46,7 @@ export function relayConnect(url, onNotice) {
|
||||
ws.onclose = () => {
|
||||
resetOpenState()
|
||||
attemptNumber++
|
||||
nextAttemptSeconds += attemptNumber ** 3
|
||||
if (nextAttemptSeconds > 14400) {
|
||||
nextAttemptSeconds = 14400 // 4 hours
|
||||
}
|
||||
nextAttemptSeconds += attemptNumber
|
||||
console.log(
|
||||
`relay ${url} connection closed. reconnecting in ${nextAttemptSeconds} seconds.`
|
||||
)
|
||||
@@ -87,6 +84,8 @@ export function relayConnect(url, onNotice) {
|
||||
if (channels[channel]) {
|
||||
channels[channel](event)
|
||||
}
|
||||
} else {
|
||||
console.warn('got event with invalid signature from ' + url, event)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user