mirror of
https://github.com/nostr-connect/connect.git
synced 2026-02-23 05:04:23 +01:00
fix connect uri
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
"build": "parcel build --public-url /connect index.html"
|
||||
},
|
||||
"dependencies": {
|
||||
"@nostr-connect/connect": "^0.1.0",
|
||||
"@nostr-connect/connect": "^0.1.1",
|
||||
"nostr-tools": "^1.1.1",
|
||||
"qrcode.react": "^3.1.0",
|
||||
"react": "^18.2.0",
|
||||
|
||||
@@ -159,10 +159,10 @@
|
||||
resolved "https://registry.yarnpkg.com/@noble/secp256k1/-/secp256k1-1.7.0.tgz#d15357f7c227e751d90aa06b05a0e5cf993ba8c1"
|
||||
integrity sha512-kbacwGSsH/CTout0ZnZWxnW1B+jH/7r/WAAKLBtrRJ/+CUH7lgmQzl3GTrQua3SGKWNSDsS6lmjnDpIJ5Dxyaw==
|
||||
|
||||
"@nostr-connect/connect@^0.1.0":
|
||||
version "0.1.0"
|
||||
resolved "https://registry.yarnpkg.com/@nostr-connect/connect/-/connect-0.1.0.tgz#0f5537237d63e328922b9b13b97d98da53cc3bd4"
|
||||
integrity sha512-YcQvkvMEdWBFy1tnPJhuS+wNK+W1EOz0vdOeIth6KezdSKS+yTHoR/jV58nQdRLvmiAIAIr+ZY/gYTztFddiUA==
|
||||
"@nostr-connect/connect@^0.1.1":
|
||||
version "0.1.1"
|
||||
resolved "https://registry.yarnpkg.com/@nostr-connect/connect/-/connect-0.1.1.tgz#e289d6abd617fc537435321612df68a448df459d"
|
||||
integrity sha512-1lhogg58haTObD2KnnZZW4wEjYRrEIOOc8ll0N7s20WDVs4uoL+5bAetVXSzf1XzgyakDWJGTYawqbtbgCo45w==
|
||||
dependencies:
|
||||
events "^3.3.0"
|
||||
nostr-tools "^1.0.1"
|
||||
|
||||
@@ -17,10 +17,9 @@ export class ConnectURI {
|
||||
|
||||
static fromURI(uri: string): ConnectURI {
|
||||
const url = new URL(uri);
|
||||
const target = url.searchParams.get('target');
|
||||
if (!target) {
|
||||
const target = url.pathname.substring(2);
|
||||
if (!url.pathname.startsWith('//'))
|
||||
throw new Error('Invalid connect URI: missing target');
|
||||
}
|
||||
const relay = url.searchParams.get('relay');
|
||||
if (!relay) {
|
||||
throw new Error('Invalid connect URI: missing relay');
|
||||
@@ -33,7 +32,7 @@ export class ConnectURI {
|
||||
/* eslint-disable @typescript-eslint/no-unused-vars */
|
||||
try {
|
||||
const md = JSON.parse(metadata);
|
||||
return new ConnectURI({ target, metadata: md, relay: relay });
|
||||
return new ConnectURI({ target, metadata: md, relay });
|
||||
} catch (ignore) {
|
||||
throw new Error('Invalid connect URI: metadata is not valid JSON');
|
||||
}
|
||||
@@ -54,7 +53,7 @@ export class ConnectURI {
|
||||
}
|
||||
|
||||
toString() {
|
||||
return `nostr://connect?${this.target}?metadata=${JSON.stringify(
|
||||
return `nostrconnect://${this.target}?metadata=${JSON.stringify(
|
||||
this.metadata
|
||||
)}&relay=${this.relay}`;
|
||||
}
|
||||
|
||||
@@ -42,6 +42,10 @@ class MobileHandler extends NostrSigner {
|
||||
}
|
||||
|
||||
describe('Nostr Connect', () => {
|
||||
it.only('generates a connectURI', async () => {
|
||||
const url = ConnectURI.fromURI(`nostrconnect://b889ff5b1513b641e2a139f661a661364979c5beee91842f8f0ef42ab558e9d4?metadata={"name":"Example","description":"🔉🔉🔉","url":"https://example.com","icons":["https://example.com/icon.png"]}&relay=wss://nostr.vulpem.com`);
|
||||
console.log(url.target);
|
||||
});
|
||||
it('connect', async () => {
|
||||
const testHandler = jest.fn();
|
||||
|
||||
@@ -68,7 +72,7 @@ describe('Nostr Connect', () => {
|
||||
expect(testHandler).toBeCalledTimes(1);
|
||||
});
|
||||
|
||||
it.only('returns pubkey', async () => {
|
||||
it('returns pubkey', async () => {
|
||||
// start listening for connect messages on the mobile app
|
||||
const remoteHandler = new MobileHandler({
|
||||
secretKey: mobileSK,
|
||||
|
||||
Reference in New Issue
Block a user