nostr-tools
Advanced tools
Comparing version 0.4.3 to 0.4.4
10
event.js
@@ -5,2 +5,12 @@ import * as secp256k1 from 'noble-secp256k1' | ||
export function getBlankEvent(evt) { | ||
return { | ||
kind: -1, | ||
pubkey: null, | ||
content: '', | ||
tags: [], | ||
created_at: Math.round(Date.now() / 1000) | ||
} | ||
} | ||
export function serializeEvent(evt) { | ||
@@ -7,0 +17,0 @@ return JSON.stringify([ |
11
index.js
import {relayConnect} from './relay' | ||
import {relayPool} from './pool' | ||
import {signEvent, verifySignature, serializeEvent, getEventHash} from './event' | ||
import { | ||
getBlankEvent, | ||
signEvent, | ||
verifySignature, | ||
serializeEvent, | ||
getEventHash | ||
} from './event' | ||
import {makeRandom32, sha256, getPublicKey} from './utils' | ||
@@ -15,3 +21,4 @@ | ||
sha256, | ||
getPublicKey | ||
getPublicKey, | ||
getBlankEvent | ||
} |
{ | ||
"name": "nostr-tools", | ||
"version": "0.4.3", | ||
"version": "0.4.4", | ||
"description": "Tools for making a Nostr client.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -29,10 +29,20 @@ # nostr-tools | ||
// reuse a subscription channel | ||
const mySubscription = pool.sub({cb: ..., filter: ....}) | ||
mySubscription.sub({filter: ....}) | ||
mySubscription.sub({cb: ...}) | ||
mySubscription.unsub() | ||
// get specific event | ||
pool.sub({cb: (event, relay) => {...}, filter: {id: '<hex>'}}) | ||
// or get a specific event plus all the events that reference it in the 'e' tag | ||
pool.sub({ | ||
cb: (event, relay) => {...}, | ||
filter: [{id: '<hex>'}, {'#e': '<hex>'}] | ||
const specificChannel = pool.sub({ | ||
cb: (event, relay) => { | ||
console.log('got specific event from relay', event, relay) | ||
specificChannel.unsub() | ||
}, | ||
filter: {id: '<hex>'} | ||
}) | ||
// or get a specific event plus all the events that reference it in the 'e' tag | ||
pool.sub({ cb: (event, relay) => { ... }, filter: [{id: '<hex>'}, {'#e': '<hex>'}] }) | ||
// get all events | ||
@@ -39,0 +49,0 @@ pool.sub({cb: (event, relay) => {...}, filter: {}}) |
11116
302
71
9