mirror of
https://github.com/hzrd149/nostrudel.git
synced 2025-04-10 12:49:29 +02:00
Merge pull request #142 from brugeman/fix/nip46_issues
Dedup auth_urls, fix nip05 login not showing auth_url, add requested …
This commit is contained in:
commit
ae3bf1a8e7
@ -27,8 +27,8 @@ export enum NostrConnectMethod {
|
||||
Nip04Decrypt = "nip04_decrypt",
|
||||
}
|
||||
type RequestParams = {
|
||||
[NostrConnectMethod.Connect]: [string] | [string, string];
|
||||
[NostrConnectMethod.CreateAccount]: [string, string] | [string, string, string];
|
||||
[NostrConnectMethod.Connect]: [string] | [string, string] | [string, string, string];
|
||||
[NostrConnectMethod.CreateAccount]: [string, string] | [string, string, string] | [string, string, string, string];
|
||||
[NostrConnectMethod.Disconnect]: [];
|
||||
[NostrConnectMethod.GetPublicKey]: [];
|
||||
[NostrConnectMethod.SignEvent]: [string];
|
||||
@ -56,6 +56,9 @@ export type NostrConnectErrorResponse = {
|
||||
error: string;
|
||||
};
|
||||
|
||||
// FIXME list all requested perms
|
||||
const Perms = "nip04_encrypt,nip04_decrypt,sign_event:0,sign_event:1,sign_event:3,sign_event:4,sign_event:6,sign_event:7"
|
||||
|
||||
export class NostrConnectClient {
|
||||
sub: NostrMultiSubscription;
|
||||
log = logger.extend("NostrConnectClient");
|
||||
@ -106,6 +109,7 @@ export class NostrConnectClient {
|
||||
}
|
||||
|
||||
private requests = new Map<string, Deferred<any>>();
|
||||
private auths = new Set<string>();
|
||||
async handleEvent(event: NostrEvent) {
|
||||
if (this.provider && event.pubkey !== this.provider) return;
|
||||
|
||||
@ -121,10 +125,13 @@ export class NostrConnectClient {
|
||||
if (response.error) {
|
||||
this.log("Got Error", response.id, response.result, response.error);
|
||||
if (response.result === "auth_url") {
|
||||
try {
|
||||
await this.handleAuthURL(response.error);
|
||||
} catch (e) {
|
||||
p.reject(e);
|
||||
if (!this.auths.has(response.id)) {
|
||||
this.auths.add(response.id)
|
||||
try {
|
||||
await this.handleAuthURL(response.error);
|
||||
} catch (e) {
|
||||
p.reject(e);
|
||||
}
|
||||
}
|
||||
} else p.reject(response);
|
||||
} else if (response.result) {
|
||||
@ -185,7 +192,7 @@ export class NostrConnectClient {
|
||||
try {
|
||||
const result = await this.makeRequest(
|
||||
NostrConnectMethod.Connect,
|
||||
token ? [this.publicKey, token] : [this.publicKey],
|
||||
[this.publicKey, token || '', Perms],
|
||||
);
|
||||
this.isConnected = true;
|
||||
return result;
|
||||
@ -202,7 +209,7 @@ export class NostrConnectClient {
|
||||
try {
|
||||
const newPubkey = await this.makeAdminRequest(
|
||||
NostrConnectMethod.CreateAccount,
|
||||
email ? [name, domain, email] : [name, domain],
|
||||
[name, domain, email || '', Perms],
|
||||
);
|
||||
this.pubkey = newPubkey;
|
||||
this.isConnected = true;
|
||||
|
@ -42,7 +42,7 @@ export default function LoginNostrAddressView() {
|
||||
if (nip05.hasNip46) {
|
||||
setLoading("Connecting...");
|
||||
const relays = safeRelayUrls(nip05.nip46Relays || rootNip05?.nip46Relays || rootNip05?.relays || nip05.relays);
|
||||
const client = nostrConnectService.fromHostedBunker(nip05.pubkey, relays, rootNip05?.pubkey);
|
||||
const client = nostrConnectService.fromHostedBunker(nip05.pubkey, relays);
|
||||
await client.connect();
|
||||
|
||||
nostrConnectService.saveClient(client);
|
||||
|
Loading…
x
Reference in New Issue
Block a user