2023-01-06 23:30:41 +01:00
2023-01-06 23:30:41 +01:00
2023-01-06 01:21:19 +01:00
2023-01-03 17:03:56 +01:00
2023-01-03 17:03:56 +01:00
2023-01-03 17:08:14 +01:00
2022-12-27 22:11:34 +01:00
2023-01-06 01:34:40 +01:00
2023-01-06 01:34:40 +01:00
2022-12-27 22:21:01 +01:00
2023-01-04 03:35:48 +01:00

🔌 Nostr Connect SDK for TypeScript

Nostr Connect SDK for TypeScript is a library that allows you to easily integrate Nostr Connect into your web application.

📦 Installation

You can install the SDK using npm or yarn:

npm install @nostr-connect/connect
# or with yarn
yarn add @nostr-connect/connect

🚀 Getting started

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.

import { generatePrivateKey } from 'nostr-tools';

const sk = generatePrivateKey();

Create a Nostr Connect instance

To create a Nostr Connect instance, you need to provide the ephemeral key and the Nostr Connect URL.

import { Connect } from '@nostr-connect/connect';


const connect = new Connect({ secretKey: sk, relay: 'wss://nostr.vulpem.com' });
connect.events.on('connect', ( walletPubkey:string ) => {
  console.log('connected with wallet: ' + walletPubkey);
});
await connect.init();

Generate a ConnectURI and display it to the user

const connectURI = new ConnectURI({
  target: webPK,
  relayURL: 'wss://nostr.vulpem.com',
  metadata: {
    name: 'My Website',
    description: 'lorem ipsum dolor sit amet',
    url: 'https://vulpem.com',
    icons: ['https://vulpem.com/1000x860-p-500.422be1bc.png'],
  },
});

const uri = connectURI.toString();

Start making requests

// send the get_public_key message to the mobile app 
const pubkey = await connect.getPublicKey();

// send the sign_event message to the mobile app
const sig = await connect.signEvent(event);
Description
No description provided
Readme MIT 860 KiB
Languages
TypeScript 98.2%
HTML 1.5%
JavaScript 0.3%