mirror of
https://github.com/nbd-wtf/nostr-tools.git
synced 2025-12-09 16:48:50 +00:00
update readme for protocol update
This commit is contained in:
45
README.md
45
README.md
@@ -14,27 +14,42 @@ pool.setPrivateKey('<hex>') // optional
|
|||||||
pool.addRelay('ws://some.relay.com', {read: true, write: true})
|
pool.addRelay('ws://some.relay.com', {read: true, write: true})
|
||||||
pool.addRelay('ws://other.relay.cool', {read: true, write: true})
|
pool.addRelay('ws://other.relay.cool', {read: true, write: true})
|
||||||
|
|
||||||
pool.onEvent((event, context, relay) => {
|
// example callback function for a subscription
|
||||||
console.log(`got a relay with context ${context} from ${relay.url} which is already validated.`, event)
|
function onEvent(event, relay) => {
|
||||||
|
console.log(`got an event from ${relay.url} which is already validated.`, event)
|
||||||
|
}
|
||||||
|
|
||||||
|
// subscribing to a single user
|
||||||
|
// author is the user's public key
|
||||||
|
pool.sub({cb: onEvent, filter: {author: '<hex>'}})
|
||||||
|
|
||||||
|
// or bulk follow
|
||||||
|
pool.sub({cb:(event, relay) => {...}, filter: {authors: ['<hex1>', '<hex2>', ..., '<hexn>']}})
|
||||||
|
|
||||||
|
// get specific event
|
||||||
|
pool.sub({cb: (event, relay) => {...}, filter: {id: '<hex>'}})
|
||||||
|
|
||||||
|
// get all events
|
||||||
|
pool.sub({cb: (event, relay) => {...}, filter: {}})
|
||||||
|
|
||||||
|
// get recent events
|
||||||
|
pool.sub({cb: (event, relay) => {...}, filter: {since: timestamp}})
|
||||||
|
|
||||||
|
// publishing events(inside an async function):
|
||||||
|
const ev = await pool.publish(eventObject, (status, url) => {
|
||||||
|
if (status === 0) {
|
||||||
|
console.log(`publish request sent to ${url}`)
|
||||||
|
}
|
||||||
|
if (status === 1) {
|
||||||
|
console.log(`event published by ${url}`, ev)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// subscribing to users and requesting specific users or events:
|
|
||||||
pool.subKey('<hex>')
|
|
||||||
pool.subKey('<hex>')
|
|
||||||
pool.subKey('<hex>')
|
|
||||||
pool.reqFeed()
|
|
||||||
pool.reqEvent({id: '<hex>'})
|
|
||||||
pool.reqKey({key: '<hex>'})
|
|
||||||
// upon request the events will be received on .onEvent above
|
|
||||||
|
|
||||||
// publishing events:
|
|
||||||
pool.publish(<event object>)
|
|
||||||
// it will be signed automatically with the key supplied above
|
// it will be signed automatically with the key supplied above
|
||||||
// or pass an already signed event to bypass this
|
// or pass an already signed event to bypass this
|
||||||
|
|
||||||
// subscribing to a new relay
|
// subscribing to a new relay
|
||||||
pool.addRelay('<url>')
|
pool.addRelay('<url>')
|
||||||
// will automatically subscribe to the all the keys called with .subKey above
|
// will automatically subscribe to the all the events called with .sub above
|
||||||
```
|
```
|
||||||
|
|
||||||
For other utils please read the source (for now).
|
For other utils please read the source (for now).
|
||||||
|
|||||||
Reference in New Issue
Block a user