💥 breaking: no more target in query string

This commit is contained in:
tiero
2023-01-14 01:18:36 +01:00
parent e7b12fad81
commit 52f6b6ced8
4 changed files with 14 additions and 12 deletions

View File

@@ -12,8 +12,10 @@ yarn add @nostr-connect/connect
```
## 🚀 Getting started
## 📖 Usage
1. [👩‍💻 For Apps developers](#-for-apps-developers)
2. [🔐 For Remote Signer developers](#-for-wallet-developers)
### Create an ephemeral key
To use the SDK, you need to create an ephemeral key. This key is used to authenticate your user and to create a session.

View File

@@ -11,7 +11,7 @@ import { getEventHash, getPublicKey, Event } from 'nostr-tools';
const secretKey = "5acff99d1ad3e1706360d213fd69203312d9b5e91a2d5f2e06100cc6f686e5b3";
const connectURI = new ConnectURI({
target: getPublicKey(secretKey),
relayURL: 'wss://nostr.vulpem.com',
relay: 'wss://nostr.vulpem.com',
metadata: {
name: 'Example',
description: '🔉🔉🔉',

View File

@@ -13,7 +13,7 @@ export interface Metadata {
export class ConnectURI {
target: string;
metadata: Metadata;
relayURL: string;
relay: string;
static fromURI(uri: string): ConnectURI {
const url = new URL(uri);
@@ -33,7 +33,7 @@ export class ConnectURI {
/* eslint-disable @typescript-eslint/no-unused-vars */
try {
const md = JSON.parse(metadata);
return new ConnectURI({ target, metadata: md, relayURL: relay });
return new ConnectURI({ target, metadata: md, relay: relay });
} catch (ignore) {
throw new Error('Invalid connect URI: metadata is not valid JSON');
}
@@ -42,26 +42,26 @@ export class ConnectURI {
constructor({
target,
metadata,
relayURL,
relay,
}: {
target: string;
metadata: Metadata;
relayURL: string;
relay: string;
}) {
this.target = target;
this.metadata = metadata;
this.relayURL = relayURL;
this.relay = relay;
}
toString() {
return `nostr://connect?target=${this.target}&metadata=${JSON.stringify(
return `nostr://connect?${this.target}?metadata=${JSON.stringify(
this.metadata
)}&relay=${this.relayURL}`;
)}&relay=${this.relay}`;
}
async approve(secretKey: string): Promise<void> {
const rpc = new NostrRPC({
relay: this.relayURL,
relay: this.relay,
secretKey,
});
await rpc.call(
@@ -78,7 +78,7 @@ export class ConnectURI {
async reject(secretKey: string): Promise<void> {
const rpc = new NostrRPC({
relay: this.relayURL,
relay: this.relay,
secretKey,
});
await rpc.call(

View File

@@ -36,7 +36,7 @@ describe('Nostr Connect', () => {
// send the connect message to the web app from the mobile
const connectURI = new ConnectURI({
target: webPK,
relayURL: 'wss://nostr.vulpem.com',
relay: 'wss://nostr.vulpem.com',
metadata: {
name: 'My Website',
description: 'lorem ipsum dolor sit amet',