feat: event emitter
This commit is contained in:
@ -80,15 +80,16 @@ export class NostrConnectWallet implements LNWallet {
|
||||
|
||||
return await new Promise<boolean>(resolve => {
|
||||
this.#conn = new Connection(this.#config.relayUrl, { read: true, write: true });
|
||||
this.#conn.OnConnected = () => resolve(true);
|
||||
this.#conn.Auth = async (c, r) => {
|
||||
this.#conn.on("connected", () => resolve(true));
|
||||
this.#conn.on("auth", async (c, r, cb) => {
|
||||
const eb = new EventBuilder();
|
||||
eb.kind(EventKind.Auth).tag(["relay", r]).tag(["challenge", c]);
|
||||
return await eb.buildAndSign(this.#config.secret);
|
||||
};
|
||||
this.#conn.OnEvent = (s, e) => {
|
||||
const ev = await eb.buildAndSign(this.#config.secret);
|
||||
cb(ev);
|
||||
});
|
||||
this.#conn.on("event", (s, e) => {
|
||||
this.#onReply(s, e);
|
||||
};
|
||||
});
|
||||
this.#conn.Connect();
|
||||
});
|
||||
}
|
||||
|
@ -87,13 +87,14 @@ const System = new NostrSystem({
|
||||
relayMetrics: RelayMetrics,
|
||||
queryOptimizer: hasWasm ? WasmQueryOptimizer : undefined,
|
||||
db: SystemDb,
|
||||
authHandler: async (c, r) => {
|
||||
const { id } = LoginStore.snapshot();
|
||||
const pub = LoginStore.getPublisher(id);
|
||||
if (pub) {
|
||||
return await pub.nip42Auth(c, r);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
System.on("auth", async (c, r, cb) => {
|
||||
const { id } = LoginStore.snapshot();
|
||||
const pub = LoginStore.getPublisher(id);
|
||||
if (pub) {
|
||||
cb(await pub.nip42Auth(c, r));
|
||||
}
|
||||
});
|
||||
|
||||
async function fetchProfile(key: string) {
|
||||
|
Reference in New Issue
Block a user