Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianmontero committed Mar 21, 2024
2 parents 9e91527 + 02ad9fd commit a7474ec
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 13 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
6 changes: 0 additions & 6 deletions src/SmartVaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion src/event-kind-handler/MetadataHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
32 changes: 29 additions & 3 deletions src/service/NostrClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/util/NostrUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export function getTagValue(
* @example
* const isNip05Verified = await isNip05Verified([email protected], aliciesPublicKey);
*/
export async function isNip05Verified(nip05: string, publicKey: string, timeout = 700): Promise<boolean> {
export async function isNip05Verified(nip05: string, publicKey: string, timeout = 1000): Promise<boolean> {

const HTTP_OK = 200;
const nip05Array = nip05.split('@');
Expand Down

0 comments on commit a7474ec

Please sign in to comment.