Improve feed loader, wait for db before executing reads/updates, make taskQueue subscribable, add race, rename auth methods, fix failed wasm verify, fix localhost urls

This commit is contained in:
Jon Staab
2025-04-09 15:39:07 -07:00
parent 1bcc57d695
commit 859f7fa68f
14 changed files with 155 additions and 32 deletions
+20 -2
View File
@@ -1,5 +1,5 @@
import EventEmitter from "events"
import {on, call} from "@welshman/lib"
import {on, poll, call} from "@welshman/lib"
import {SignedEvent, StampedEvent} from "@welshman/util"
import {makeEvent, CLIENT_AUTH} from "@welshman/util"
import {isRelayAuth, isClientAuth, isRelayOk, RelayMessage} from "./message.js"
@@ -97,7 +97,7 @@ export class AuthState extends EventEmitter {
this.emit(AuthStateEvent.Status, status)
}
async authenticate(sign: (event: StampedEvent) => Promise<SignedEvent>) {
async doAuth(sign: (event: StampedEvent) => Promise<SignedEvent>) {
if (!this.challenge) {
throw new Error("Attempted to authenticate with no challenge")
}
@@ -119,6 +119,24 @@ export class AuthState extends EventEmitter {
}
}
async attemptAuth(sign: (event: StampedEvent) => Promise<SignedEvent>) {
this.socket.attemptToOpen()
await poll({
signal: AbortSignal.timeout(800),
condition: () => this.status === AuthStatus.Requested,
})
if (this.status === AuthStatus.Requested) {
await this.doAuth(sign)
}
await poll({
signal: AbortSignal.timeout(800),
condition: () => this.status !== AuthStatus.PendingResponse,
})
}
cleanup() {
this.removeAllListeners()
this._unsubscribers.forEach(call)