Compare commits
No commits in common. "3ec413b70d96049b65a312497d64b163606101ae" and "fb1c239e152c2db8ce567afe495e1461ce49ce6d" have entirely different histories.
3ec413b70d
...
fb1c239e15
2 changed files with 3 additions and 40 deletions
|
|
@ -22,43 +22,6 @@ export class Backend extends NDKNip46Backend {
|
||||||
// this.setStrategy('publish_event', new PublishEventHandlingStrategy());
|
// this.setStrategy('publish_event', new PublishEventHandlingStrategy());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Override NDKNip46Backend.start() to await the kind-24133
|
|
||||||
* subscription's EOSE before resolving. The base implementation
|
|
||||||
* calls `this.ndk.subscribe(...)` and returns immediately — the
|
|
||||||
* NDKSubscription queues a REQ on the relay connection but the
|
|
||||||
* relay's acknowledgement (EOSE) hasn't arrived yet. Any caller
|
|
||||||
* that publishes a NIP-46 event in the immediate window after
|
|
||||||
* `start()` returns races against the relay registering this
|
|
||||||
* subscription.
|
|
||||||
*
|
|
||||||
* aiolabs/lnbits#33's eager-bind chain publishes a NIP-46
|
|
||||||
* `connect` event in the same HTTP round-trip as `create_new_key`,
|
|
||||||
* which loses this race deterministically — the bunker never
|
|
||||||
* sees the connect event because its subscription wasn't yet
|
|
||||||
* registered with the relay when the event was broadcast.
|
|
||||||
*
|
|
||||||
* Awaiting EOSE closes the race: by the time `start()` resolves,
|
|
||||||
* the relay has confirmed it has the bunker's subscription on
|
|
||||||
* file and will route matching kind-24133 events to it.
|
|
||||||
*
|
|
||||||
* See aiolabs/nsecbunkerd#9 for the full diagnosis.
|
|
||||||
*/
|
|
||||||
async start(): Promise<void> {
|
|
||||||
this.localUser = await this.signer.user();
|
|
||||||
await new Promise<void>((resolve) => {
|
|
||||||
const sub = this.ndk.subscribe(
|
|
||||||
{
|
|
||||||
kinds: [24133],
|
|
||||||
"#p": [this.localUser!.pubkey],
|
|
||||||
},
|
|
||||||
{ closeOnEose: false }
|
|
||||||
);
|
|
||||||
sub.on("event", (e: any) => this.handleIncomingEvent(e));
|
|
||||||
sub.on("eose", () => resolve());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private async validateToken(token: string) {
|
private async validateToken(token: string) {
|
||||||
if (!token) throw new Error("Invalid token");
|
if (!token) throw new Error("Invalid token");
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -257,14 +257,14 @@ class Daemon {
|
||||||
const nsec = decryptNsec(iv, data, passphrase);
|
const nsec = decryptNsec(iv, data, passphrase);
|
||||||
this.activeKeys[keyName] = nsec;
|
this.activeKeys[keyName] = nsec;
|
||||||
|
|
||||||
await this.startKey(keyName, nsec);
|
this.startKey(keyName, nsec);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
async loadNsec(keyName: string, nsec: string) {
|
loadNsec(keyName: string, nsec: string) {
|
||||||
this.activeKeys[keyName] = nsec;
|
this.activeKeys[keyName] = nsec;
|
||||||
|
|
||||||
await this.startKey(keyName, nsec);
|
this.startKey(keyName, nsec);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue