mirror of
https://github.com/hzrd149/nostrudel.git
synced 2025-09-20 13:01:07 +02:00
Merge branch 'fix-bunker-uri' into next
This commit is contained in:
5
.changeset/quick-peas-remain.md
Normal file
5
.changeset/quick-peas-remain.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"nostrudel": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fix bunker://pubkey connect URIs
|
@@ -12,7 +12,6 @@ import { truncatedId } from "../helpers/nostr/events";
|
|||||||
import { NostrConnectAccount } from "./account";
|
import { NostrConnectAccount } from "./account";
|
||||||
import { bytesToHex, hexToBytes } from "@noble/hashes/utils";
|
import { bytesToHex, hexToBytes } from "@noble/hashes/utils";
|
||||||
import { safeRelayUrl } from "../helpers/relay";
|
import { safeRelayUrl } from "../helpers/relay";
|
||||||
import Subject from "../classes/subject";
|
|
||||||
|
|
||||||
export function isErrorResponse(response: any): response is NostrConnectErrorResponse {
|
export function isErrorResponse(response: any): response is NostrConnectErrorResponse {
|
||||||
return !!response.error;
|
return !!response.error;
|
||||||
@@ -262,6 +261,7 @@ class NostrConnectService {
|
|||||||
fromHostedBunker(pubkey: string, relays: string[], provider?: string) {
|
fromHostedBunker(pubkey: string, relays: string[], provider?: string) {
|
||||||
return this.getClient(pubkey) || this.createClient(pubkey, relays, undefined, provider);
|
return this.getClient(pubkey) || this.createClient(pubkey, relays, undefined, provider);
|
||||||
}
|
}
|
||||||
|
/** create client from: pubkey@wss://relay.com (with optional bunker://) */
|
||||||
fromBunkerAddress(address: string) {
|
fromBunkerAddress(address: string) {
|
||||||
const parts = address.replace("bunker://", "").split("@");
|
const parts = address.replace("bunker://", "").split("@");
|
||||||
if (parts.length !== 2) throw new Error("Invalid bunker address");
|
if (parts.length !== 2) throw new Error("Invalid bunker address");
|
||||||
@@ -272,21 +272,20 @@ class NostrConnectService {
|
|||||||
|
|
||||||
return this.getClient(pubkey) || this.createClient(pubkey, [pathRelay]);
|
return this.getClient(pubkey) || this.createClient(pubkey, [pathRelay]);
|
||||||
}
|
}
|
||||||
|
/** create client from: bunker://<pubkey>?relay=<relay> */
|
||||||
fromBunkerURI(uri: string) {
|
fromBunkerURI(uri: string) {
|
||||||
const url = new URL(uri);
|
const url = new URL(uri);
|
||||||
|
|
||||||
const pathParts = url.pathname.replace(/^\/\//, "").split("@");
|
const pubkey = url.host;
|
||||||
const pubkey = pathParts[0];
|
|
||||||
const pathRelay = pathParts[1] as string | undefined;
|
|
||||||
if (!isHexKey(pubkey)) throw new Error("Invalid connection URI");
|
if (!isHexKey(pubkey)) throw new Error("Invalid connection URI");
|
||||||
const relays = url.searchParams.getAll("relay");
|
const relays = url.searchParams.getAll("relay");
|
||||||
if (pathRelay) relays.push(pathRelay);
|
|
||||||
if (relays.length === 0) throw new Error("Missing relays");
|
if (relays.length === 0) throw new Error("Missing relays");
|
||||||
|
|
||||||
return this.getClient(pubkey) || this.createClient(pubkey, relays);
|
return this.getClient(pubkey) || this.createClient(pubkey, relays);
|
||||||
}
|
}
|
||||||
fromBunkerToken(token: string) {
|
/** create client from: pubkey#token */
|
||||||
const [npub, hexToken] = token.split("#");
|
fromBunkerToken(pubkeyWithToken: string) {
|
||||||
|
const [npub, hexToken] = pubkeyWithToken.split("#");
|
||||||
const decoded = nip19.decode(npub);
|
const decoded = nip19.decode(npub);
|
||||||
const pubkey = getPubkeyFromDecodeResult(decoded);
|
const pubkey = getPubkeyFromDecodeResult(decoded);
|
||||||
if (!pubkey) throw new Error("Cant find pubkey");
|
if (!pubkey) throw new Error("Cant find pubkey");
|
||||||
@@ -296,6 +295,7 @@ class NostrConnectService {
|
|||||||
const client = this.getClient(pubkey) || this.createClient(pubkey, relays);
|
const client = this.getClient(pubkey) || this.createClient(pubkey, relays);
|
||||||
return client;
|
return client;
|
||||||
}
|
}
|
||||||
|
/** create client from NIP-05 */
|
||||||
fromAccount(account: NostrConnectAccount) {
|
fromAccount(account: NostrConnectAccount) {
|
||||||
const existingClient = this.getClient(account.pubkey);
|
const existingClient = this.getClient(account.pubkey);
|
||||||
if (existingClient) return existingClient;
|
if (existingClient) return existingClient;
|
||||||
|
Reference in New Issue
Block a user