nostr-tools
Advanced tools
Comparing version 0.18.0 to 0.19.0
{ | ||
"name": "nostr-tools", | ||
"version": "0.18.0", | ||
"version": "0.19.0", | ||
"description": "Tools for making a Nostr client.", | ||
@@ -5,0 +5,0 @@ "repository": { |
21
pool.js
@@ -1,2 +0,2 @@ | ||
import {getEventHash, signEvent} from './event' | ||
import {getEventHash, verifySignature, signEvent} from './event' | ||
import {relayConnect, normalizeRelayURL} from './relay' | ||
@@ -6,2 +6,4 @@ | ||
var globalPrivateKey | ||
var globalSigningFunction | ||
const poolPolicy = { | ||
@@ -80,2 +82,5 @@ // setting this to a number will cause events to be published to a random | ||
}, | ||
registerSigningFunction(fn) { | ||
globalSigningFunction = fn | ||
}, | ||
setPolicy(key, value) { | ||
@@ -128,5 +133,17 @@ poolPolicy[key] = value | ||
event.sig = await signEvent(event, globalPrivateKey) | ||
} else if (globalSigningFunction) { | ||
event.sig = await globalSigningFunction(event) | ||
if (!event.sig) { | ||
// abort here | ||
return | ||
} else { | ||
// check | ||
if (!(await verifySignature(event))) | ||
throw new Error( | ||
'signature provided by custom signing function is invalid.' | ||
) | ||
} | ||
} else { | ||
throw new Error( | ||
"can't publish unsigned event. either sign this event beforehand or pass a private key while initializing this relay pool so it can be signed automatically." | ||
"can't publish unsigned event. either sign this event beforehand, provide a signing function or pass a private key while initializing this relay pool so it can be signed automatically." | ||
) | ||
@@ -133,0 +150,0 @@ } |
22730
671