Clean up nostr-tools dependencies

This commit is contained in:
Jon Staab
2025-04-01 10:50:43 -07:00
parent 04816f8377
commit 5ad6347123
10 changed files with 75 additions and 50 deletions
+1 -1
View File
@@ -30,6 +30,6 @@
"@welshman/lib": "^0.1.0",
"@welshman/net": "^0.0.49",
"@welshman/util": "^0.1.0",
"nostr-tools": "^2.7.2"
"@welshman/signer": "^0.1.1"
}
}
+9 -6
View File
@@ -1,6 +1,5 @@
import {hexToBytes} from "@noble/hashes/utils"
import {getPublicKey, finalizeEvent} from "nostr-tools/pure"
import {now} from "@welshman/lib"
import {Nip01Signer} from "@welshman/signer"
import {TrustedEvent, StampedEvent, Filter} from "@welshman/util"
import {MultiRequest, MultiPublish, PublishEvent, RequestEvent, AdapterContext} from "@welshman/net"
@@ -25,8 +24,11 @@ export class DVM {
logEvents = false
seen = new Set()
handlers = new Map()
signer: Nip01Signer
constructor(readonly opts: DVMOpts) {
this.signer = new Nip01Signer(opts.sk)
for (const [kind, createHandler] of Object.entries(this.opts.handlers)) {
this.handlers.set(parseInt(kind), createHandler(this))
}
@@ -35,7 +37,8 @@ export class DVM {
async start() {
this.active = true
const {sk, relays, context, requireMention = false} = this.opts
const {relays, context, requireMention = false} = this.opts
const pubkey = await this.signer.getPubkey()
while (this.active) {
await new Promise<void>(resolve => {
@@ -44,7 +47,7 @@ export class DVM {
const filter: Filter = {kinds, since}
if (requireMention) {
filter["#p"] = [getPublicKey(hexToBytes(sk))]
filter["#p"] = [pubkey]
}
const req = new MultiRequest({relays, filter, context})
@@ -109,8 +112,8 @@ export class DVM {
}
async publish(template: StampedEvent) {
const {sk, relays, context} = this.opts
const event = finalizeEvent(template, hexToBytes(sk))
const {relays, context} = this.opts
const event = await this.signer.sign(template)
await new Promise<void>(resolve => {
new MultiPublish({event, relays, context}).on(PublishEvent.Complete, resolve)