eslint and minor fixes.
This commit is contained in:
parent
60fc0d7940
commit
6d4916e6f7
|
@ -1,4 +1,5 @@
|
|||
{
|
||||
"root": true,
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 9,
|
||||
"ecmaFeatures": {
|
||||
|
|
8
event.js
8
event.js
|
@ -34,13 +34,13 @@ export function verifySignature(event) {
|
|||
if (event.id !== getEventHash(event)) return false
|
||||
return verifySchnorr(
|
||||
Buffer.from(event.id, 'hex'),
|
||||
Buffer.from(event.pubkey, 'hex')
|
||||
Buffer.from(event.sig, 'hex'),
|
||||
Buffer.from(event.pubkey, 'hex'),
|
||||
Buffer.from(event.sig, 'hex')
|
||||
)
|
||||
}
|
||||
|
||||
export function signEvent(event, key) {
|
||||
let eventHash = Buffer.from(getEventHash(event), 'hex')
|
||||
let key = Buffer.from(key, 'hex')
|
||||
return Buffer.from(signSchnorr(eventHash, key)).toString('hex')
|
||||
let keyB = Buffer.from(key, 'hex')
|
||||
return Buffer.from(signSchnorr(eventHash, keyB)).toString('hex')
|
||||
}
|
||||
|
|
1
index.js
1
index.js
|
@ -11,6 +11,7 @@ import {
|
|||
import {matchFilter, matchFilters} from './filter'
|
||||
|
||||
export {
|
||||
generatePrivateKey,
|
||||
relayConnect,
|
||||
relayPool,
|
||||
signEvent,
|
||||
|
|
1
nip06.js
1
nip06.js
|
@ -1,4 +1,3 @@
|
|||
import createHmac from 'create-hmac'
|
||||
import {wordlist} from 'micro-bip39/wordlists/english'
|
||||
import {
|
||||
generateMnemonic,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "nostr-tools",
|
||||
"version": "0.12.1",
|
||||
"version": "0.12.2",
|
||||
"description": "Tools for making a Nostr client.",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
@ -12,7 +12,6 @@
|
|||
"browserify-cipher": ">=1",
|
||||
"buffer": ">=5",
|
||||
"create-hash": "^1.2.0",
|
||||
"create-hmac": ">=1",
|
||||
"dns-packet": "^5.2.4",
|
||||
"micro-bip39": "^0.1.3",
|
||||
"randombytes": ">=2",
|
||||
|
@ -30,5 +29,9 @@
|
|||
"censorship",
|
||||
"censorship-resistance",
|
||||
"client"
|
||||
]
|
||||
],
|
||||
"devDependencies": {
|
||||
"eslint": "^8.5.0",
|
||||
"eslint-plugin-babel": "^5.3.1"
|
||||
}
|
||||
}
|
||||
|
|
50
pool.js
50
pool.js
|
@ -3,7 +3,6 @@ import {relayConnect, normalizeRelayURL} from './relay'
|
|||
|
||||
export function relayPool(globalPrivateKey) {
|
||||
const relays = {}
|
||||
const globalSub = []
|
||||
const noticeCallbacks = []
|
||||
|
||||
function propagateNotice(notice, relayURL) {
|
||||
|
@ -28,29 +27,34 @@ export function relayPool(globalPrivateKey) {
|
|||
const activeCallback = cb
|
||||
const activeFilters = filter
|
||||
|
||||
activeSubscriptions[id] = {
|
||||
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}, id)
|
||||
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())
|
||||
delete activeSubscriptions[id]
|
||||
const unsub = () => {
|
||||
Object.values(subControllers).forEach(sub => sub.unsub())
|
||||
delete activeSubscriptions[id]
|
||||
}
|
||||
const sub = ({cb = activeCallback, filter = activeFilters}) => {
|
||||
Object.entries(subControllers).map(([relayURL, sub]) => [
|
||||
relayURL,
|
||||
sub.sub({cb, filter}, id)
|
||||
])
|
||||
return activeSubscriptions[id]
|
||||
}
|
||||
const addRelay = relay => {
|
||||
subControllers[relay.url] = relay.sub({cb, filter}, id)
|
||||
return activeSubscriptions[id]
|
||||
}
|
||||
const removeRelay = relayURL => {
|
||||
if (relayURL in subControllers) {
|
||||
subControllers[relayURL].unsub()
|
||||
if (Object.keys(subControllers).length === 0) unsub()
|
||||
}
|
||||
return activeSubscriptions[id]
|
||||
}
|
||||
|
||||
activeSubscriptions[id] = {
|
||||
sub,
|
||||
unsub,
|
||||
addRelay,
|
||||
removeRelay
|
||||
}
|
||||
|
||||
return activeSubscriptions[id]
|
||||
|
|
4
relay.js
4
relay.js
|
@ -1,3 +1,5 @@
|
|||
/* global WebSocket */
|
||||
|
||||
import 'websocket-polyfill'
|
||||
|
||||
import {verifySignature} from './event'
|
||||
|
@ -148,7 +150,7 @@ export function relayConnect(url, onNotice) {
|
|||
try {
|
||||
await trySend(['EVENT', event])
|
||||
statusCallback(0)
|
||||
let {unsub} = relay.sub(
|
||||
let {unsub} = sub(
|
||||
{
|
||||
cb: () => {
|
||||
statusCallback(1)
|
||||
|
|
Loading…
Reference in New Issue