mirror of
https://github.com/hzrd149/nostrudel.git
synced 2025-03-29 11:12:12 +01:00
fix bug with nsec accounts
This commit is contained in:
parent
a38efa5399
commit
1b7799dd7d
@ -24,7 +24,7 @@ export default class NostrConnectAccount extends Account {
|
||||
this.signer = nostrConnectService.createSigner(data.pubkey, data.signerRelays, data.clientSecretKey);
|
||||
|
||||
// presume the client has already connected
|
||||
nostrConnectService.saveClient(data.pubKey);
|
||||
nostrConnectService.saveSigner(data.pubKey);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ export default class NsecAccount extends Account {
|
||||
fromJSON(data: any): this {
|
||||
const parse = nip19.decode(data.nsec);
|
||||
|
||||
if (parse.type === "nsec") throw new Error("Unknown nsec type");
|
||||
if (parse.type !== "nsec") throw new Error("Unknown nsec type");
|
||||
this.signer = new SimpleSigner(parse.data as Uint8Array);
|
||||
|
||||
return this;
|
||||
|
@ -51,15 +51,15 @@ class NostrConnectService {
|
||||
log = logger.extend("NostrConnect");
|
||||
clients: NostrConnectSigner[] = [];
|
||||
|
||||
getClient(pubkey: string) {
|
||||
getSigner(pubkey: string) {
|
||||
return this.clients.find((client) => client.pubkey === pubkey);
|
||||
}
|
||||
saveClient(client: NostrConnectSigner) {
|
||||
saveSigner(client: NostrConnectSigner) {
|
||||
if (!this.clients.includes(client)) this.clients.push(client);
|
||||
}
|
||||
|
||||
createSigner(pubkey: string, relays: string[], secretKey?: string, provider?: string) {
|
||||
if (this.getClient(pubkey)) throw new Error("A client for that pubkey already exists");
|
||||
if (this.getSigner(pubkey)) throw new Error("A client for that pubkey already exists");
|
||||
|
||||
const client = new NostrConnectSigner(pubkey, relays, secretKey, provider);
|
||||
client.log = this.log.extend(pubkey);
|
||||
@ -70,7 +70,7 @@ class NostrConnectService {
|
||||
}
|
||||
|
||||
fromHostedBunker(pubkey: string, relays: string[], provider?: string) {
|
||||
return this.getClient(pubkey) || this.createSigner(pubkey, relays, undefined, provider);
|
||||
return this.createSigner(pubkey, relays, undefined, provider);
|
||||
}
|
||||
/** create client from: pubkey@wss://relay.com (with optional bunker://) */
|
||||
fromBunkerAddress(address: string) {
|
||||
@ -81,7 +81,7 @@ class NostrConnectService {
|
||||
if (!pathRelay) throw new Error("Missing relay");
|
||||
if (!pubkey || !isHexKey(pubkey)) throw new Error("Missing pubkey");
|
||||
|
||||
return this.getClient(pubkey) || this.createSigner(pubkey, [pathRelay]);
|
||||
return this.createSigner(pubkey, [pathRelay]);
|
||||
}
|
||||
/** create client from: bunker://<pubkey>?relay=<relay> */
|
||||
fromBunkerURI(uri: string) {
|
||||
@ -93,7 +93,7 @@ class NostrConnectService {
|
||||
const relays = url.searchParams.getAll("relay");
|
||||
if (relays.length === 0) throw new Error("Missing relays");
|
||||
|
||||
return this.getClient(pubkey) || this.createSigner(pubkey, relays);
|
||||
return this.createSigner(pubkey, relays);
|
||||
}
|
||||
/** create client from: pubkey#token */
|
||||
fromBunkerToken(pubkeyWithToken: string) {
|
||||
@ -104,8 +104,7 @@ class NostrConnectService {
|
||||
const relays = ["wss://relay.nsecbunker.com", "wss://nos.lol"];
|
||||
if (relays.length === 0) throw new Error("Missing relays");
|
||||
|
||||
const client = this.getClient(pubkey) || this.createSigner(pubkey, relays);
|
||||
return client;
|
||||
return this.createSigner(pubkey, relays);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
import { EventTemplate } from "nostr-tools";
|
||||
import { EventTemplate, NostrEvent } from "nostr-tools";
|
||||
|
||||
import { NostrEvent } from "../types/nostr-event";
|
||||
import { Account } from "../classes/accounts/account";
|
||||
import PasswordAccount from "../classes/accounts/password-account";
|
||||
|
||||
|
@ -100,7 +100,7 @@ export default function LoginNostrAddressCreate() {
|
||||
|
||||
const account = new NostrConnectAccount(signer.pubkey!, signer);
|
||||
|
||||
nostrConnectService.saveClient(signer);
|
||||
nostrConnectService.saveSigner(signer);
|
||||
accountService.addAccount(account);
|
||||
accountService.switchAccount(account.pubkey);
|
||||
} catch (e) {
|
||||
|
@ -49,7 +49,7 @@ export default function LoginNostrAddressView() {
|
||||
const signer = nostrConnectService.fromHostedBunker(nip05.pubkey, relays);
|
||||
await signer.connect(undefined, NOSTR_CONNECT_PERMISSIONS);
|
||||
|
||||
nostrConnectService.saveClient(signer);
|
||||
nostrConnectService.saveSigner(signer);
|
||||
const account = new NostrConnectAccount(signer.pubkey!, signer);
|
||||
accountService.addAccount(account);
|
||||
accountService.switchAccount(signer.pubkey!);
|
||||
|
@ -46,7 +46,7 @@ function ClientConnectForm() {
|
||||
const c = new NostrConnectSigner(undefined, [relay]);
|
||||
setSigner(c);
|
||||
c.listen().then(() => {
|
||||
nostrConnectService.saveClient(c);
|
||||
nostrConnectService.saveSigner(c);
|
||||
const account = new NostrConnectAccount(c.pubkey!, c);
|
||||
accountService.addAccount(account);
|
||||
accountService.switchAccount(c.pubkey!);
|
||||
@ -121,7 +121,7 @@ export default function LoginNostrConnectView() {
|
||||
await client.connect(hexToken);
|
||||
} else throw new Error("Unknown format");
|
||||
|
||||
nostrConnectService.saveClient(client);
|
||||
nostrConnectService.saveSigner(client);
|
||||
const account = new NostrConnectAccount(client.pubkey!, client);
|
||||
accountService.addAccount(account);
|
||||
accountService.switchAccount(client.pubkey!);
|
||||
|
Loading…
x
Reference in New Issue
Block a user