💥 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 ### 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. 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 secretKey = "5acff99d1ad3e1706360d213fd69203312d9b5e91a2d5f2e06100cc6f686e5b3";
const connectURI = new ConnectURI({ const connectURI = new ConnectURI({
target: getPublicKey(secretKey), target: getPublicKey(secretKey),
relayURL: 'wss://nostr.vulpem.com', relay: 'wss://nostr.vulpem.com',
metadata: { metadata: {
name: 'Example', name: 'Example',
description: '🔉🔉🔉', description: '🔉🔉🔉',

View File

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

View File

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