From 485533d53f75b860a5e0aab8727238716ac8bb42 Mon Sep 17 00:00:00 2001 From: Dreyhh Date: Wed, 20 Mar 2024 18:06:50 -0600 Subject: [PATCH 1/2] Updaded callback for failure to publish events to add automatic retry, removed query for key agency status when fetching profile data, increases nip05 verify timeout --- src/SmartVaults.ts | 6 ----- src/event-kind-handler/MetadataHandler.ts | 2 +- src/service/NostrClient.ts | 32 ++++++++++++++++++++--- src/util/NostrUtil.ts | 2 +- 4 files changed, 31 insertions(+), 11 deletions(-) diff --git a/src/SmartVaults.ts b/src/SmartVaults.ts index d482d26..25c9404 100644 --- a/src/SmartVaults.ts +++ b/src/SmartVaults.ts @@ -236,12 +236,6 @@ export class SmartVaults { .toFilters() const metadataEvents = await this.nostrClient.list(metadataFilter) const profiles: SmartVaultsTypes.Profile[] = await this.eventKindHandlerFactor.getHandler(Kind.Metadata).handle(metadataEvents) - const verifiedKeyAgentsPubkeys = new Set(await this.getVerifiedKeyAgentsPubKeys()) - const unverifiedKeyAgentsPubkeys = await this.getUnverifiedKeyAgentEventsByPubkey() - profiles.forEach(profile => { - profile.isKeyAgent = unverifiedKeyAgentsPubkeys.has(profile.publicKey) || verifiedKeyAgentsPubkeys.has(profile.publicKey) - profile.isVerified = verifiedKeyAgentsPubkeys.has(profile.publicKey) - }) return profiles } diff --git a/src/event-kind-handler/MetadataHandler.ts b/src/event-kind-handler/MetadataHandler.ts index 865d0b4..132ee58 100644 --- a/src/event-kind-handler/MetadataHandler.ts +++ b/src/event-kind-handler/MetadataHandler.ts @@ -42,7 +42,7 @@ export class MetadataHandler extends EventKindHandler { } } - this.store.store({ content: { publicKey, ...metadata }, id: event.id }); + this.store.store({ content: { publicKey, ...metadata, isKeyAgent: false, isVerified: false }, id: event.id }); }); const results = await Promise.allSettled(fetchPromises); diff --git a/src/service/NostrClient.ts b/src/service/NostrClient.ts index bb9ca3f..4da89fc 100644 --- a/src/service/NostrClient.ts +++ b/src/service/NostrClient.ts @@ -68,19 +68,45 @@ export class NostrClient { ok: [], failed: [] } - function onResponse(status, relay) { + + function onOkResponse(status: string, relay: string): void { + result[status].push(relay) + numRelays-- + if (numRelays <= 0) { + listeners.forEach(cb => { cb(result) }) + listeners = new Set() + } + } + + const onFailedResponse = (status: string, relay: string, count: number): void => { + if (count === 1) console.log(`Event with id ${event.id} failed to publish to ${relay}, retrying...`) + if (count > 5) { + console.log(`Event with id ${event.id} failed to publish to ${relay}, max retries reached`) + return + } result[status].push(relay) numRelays-- + // Retry + setTimeout(() => { + const pub = this.pool.publish([relay], event) + pub.on('ok', (relay) => { + console.log(`Retry ${count} for event ${event.id} suceeded`, relay) + }) + pub.on('failed', (relay) => { + console.log(`Retry ${count} for event ${event.id} failed, retrying...`, relay) + onFailedResponse('failed', relay, count + 1) + }) + }, 61000) if (numRelays <= 0) { listeners.forEach(cb => { cb(result) }) listeners = new Set() } } pub.on('ok', (relay) => { - onResponse('ok', relay) + onOkResponse('ok', relay) }) pub.on('failed', (relay) => { - onResponse('failed', relay) + onFailedResponse('failed', relay, 1) }) return { on(type, cb) { diff --git a/src/util/NostrUtil.ts b/src/util/NostrUtil.ts index 4a21a69..f9dde50 100644 --- a/src/util/NostrUtil.ts +++ b/src/util/NostrUtil.ts @@ -77,7 +77,7 @@ export function getTagValue( * @example * const isNip05Verified = await isNip05Verified(alice@smartvaults.app, aliciesPublicKey); */ -export async function isNip05Verified(nip05: string, publicKey: string, timeout = 700): Promise { +export async function isNip05Verified(nip05: string, publicKey: string, timeout = 1000): Promise { const HTTP_OK = 200; const nip05Array = nip05.split('@'); From 02ad9fdab0327bdc322c7e28d8137a837aad16b8 Mon Sep 17 00:00:00 2001 From: Sebastian Montero Date: Thu, 21 Mar 2024 08:46:10 -0600 Subject: [PATCH 2/2] 0.0.64 --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index b7b7ec6..b54afc8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@smontero/smartvaults-js-client", - "version": "0.0.63", + "version": "0.0.64", "lockfileVersion": 3, "requires": true, "packages": { diff --git a/package.json b/package.json index 11968d5..c7a017b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@smontero/smartvaults-js-client", - "version": "0.0.63", + "version": "0.0.64", "description": "SmartVaults javascript client", "main": "dist/index.js", "types": "dist/index.d.ts",