{"id":13832715,"url":"https://github.com/nostr-connect/connect","last_synced_at":"2025-10-28T00:04:14.520Z","repository":{"id":73275119,"uuid":"582780726","full_name":"nostr-connect/connect","owner":"nostr-connect","description":"Nostr Connect SDK for TypeScript is a library that allows you to easily integrate Nostr Connect into your web application","archived":false,"fork":false,"pushed_at":"2023-12-17T02:22:42.000Z","size":769,"stargazers_count":57,"open_issues_count":2,"forks_count":10,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-10-13T20:48:35.260Z","etag":null,"topics":["bitcoin","nostr","typescript"],"latest_commit_sha":null,"homepage":"https://nostr-connect.github.io/connect","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nostr-connect.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2022-12-27T21:11:33.000Z","updated_at":"2025-10-13T07:30:20.000Z","dependencies_parsed_at":"2023-12-17T03:37:27.181Z","dependency_job_id":null,"html_url":"https://github.com/nostr-connect/connect","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/nostr-connect/connect","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nostr-connect%2Fconnect","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nostr-connect%2Fconnect/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nostr-connect%2Fconnect/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nostr-connect%2Fconnect/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nostr-connect","download_url":"https://codeload.github.com/nostr-connect/connect/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nostr-connect%2Fconnect/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":281361348,"owners_count":26487881,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-27T02:00:05.855Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bitcoin","nostr","typescript"],"created_at":"2024-08-04T11:00:28.615Z","updated_at":"2025-10-28T00:04:14.495Z","avatar_url":"https://github.com/nostr-connect.png","language":"TypeScript","funding_links":[],"categories":["Install from Source","Libraries","TypeScript"],"sub_categories":["Nostr","Client reviews and/or comparisons"],"readme":"# 🔌 Nostr Connect SDK for TypeScript\nNostr Connect SDK for TypeScript is a library that allows you to easily integrate Nostr Connect into your web application.\n\n\n## 📦 Installation\nYou can install the SDK using npm or yarn:\n\n```bash \nnpm install @nostr-connect/connect\n# or with yarn\nyarn add @nostr-connect/connect\n```\n\n\n## 📖 Usage \n\n1. [👩‍💻 For Apps developers](#-for-apps-developers)\n2. [🔐 For Wallet \u0026 Remote Signer developers](#-for-wallet-developers)\n\n\n## 👩‍💻 For Apps developers\n\n### Create an ephemeral key\n\nTo use the SDK, you need to create an ephemeral key. This key is used to authenticate your user and to create a session.\n\n```typescript\nimport { generatePrivateKey } from 'nostr-tools';\n\nconst sk = generatePrivateKey();\n```\n\n\n### Create a Nostr Connect instance\n\nTo create a Nostr Connect instance, you need to provide the ephemeral key and the Nostr Connect URL.\n\n```typescript\nimport { Connect } from '@nostr-connect/connect';\n\n\nconst connect = new Connect({ secretKey: sk, relay: 'wss://nostr.vulpem.com' });\nconnect.events.on('connect', ( walletPubkey:string ) =\u003e {\n  console.log('connected with wallet: ' + walletPubkey);\n});\nawait connect.init();\n```\n\n### Generate a ConnectURI and display it to the user\n\n\n```typescript\nconst connectURI = new ConnectURI({\n  target: webPK,\n  relay: 'wss://nostr.vulpem.com',\n  metadata: {\n    name: 'My Website',\n    description: 'lorem ipsum dolor sit amet',\n    url: 'https://vulpem.com',\n    icons: ['https://vulpem.com/1000x860-p-500.422be1bc.png'],\n  },\n});\n\nconst uri = connectURI.toString();\n```\n\n\n### Start making requests\n\n```typescript\n// send the get_public_key message to the mobile app \nconst pubkey = await connect.getPublicKey();\n\n// send the sign_event message to the mobile app\nconst sig = await connect.signEvent(event);\n```\n\n## 🔐 For Wallet developers\n\n### 🤓 Define your methods\n\nAs per [NIP-46](https://github.com/nostr-connect/nips/blob/nostr-connect/46.md), the Signer app **MUST** implement the following RPC methods:\n\n- `get_public_key`\n- `sign_event`\n\nYou need to define these methods in your app, each method must return a `Promise` that resolves to the expected result.\n\nThe NostrSigner class provides access to the Nostr public key via `this.self.pubkey`, the Nostr private key via `this.self.secret` and the full Nostr event that originated the current request.  You can access the event using the `this.event` property.\n\nIt's best to ask approval from the user before signing an event. To do so, you can emit an event to the UI and wait for the user to approve or reject the request.\n\n```typescript\nimport { NostrSigner } from '@nostr-connect/connect';\nimport { getPublicKey, getSignature, nip06 } from 'nostr-tools';\n\nconst sk = nip06.privateKeyFromSeedWords(myWords);\n\nclass MobileHandler extends NostrSigner {\n\n  async get_public_key(): Promise\u003cstring\u003e {\n    return getPublicKey(sk);\n  }\n\n  async sign_event(event: Event): Promise\u003cstring\u003e {\n    if (!this.event) throw new Error('No origin event');\n\n    // emit event to the UI to show a modal\n    this.events.emit('sign_event_request', event);\n\n    // wait for the user to approve or reject the request\n    return new Promise((resolve, reject) =\u003e {\n      \n      // listen for user accept \n      this.events.on('sign_event_approve', () =\u003e {\n        resolve(getSignature(event, this.self.secret));\n      });\n\n      // or reject\n      this.events.on('sign_event_reject', () =\u003e {\n        reject(new Error('User rejected request'));\n      });\n    });\n  }\n}\n```\n\n### 📱 Create a MobileHandler instance\n\nGenerate a key to identify the remote signer, it is used to be reached by the apps. At the moment it's your duty to persist locally a list of the apps that are allowed to connect to your remote signer.\n\n```typescript\n// random key\nconst secretKey = secp.utils.bytesToHex(secp.utils.randomPrivateKey());\n// create a new instance of the MobileHandler \nconst handler = new MobileHandler({ secretKey });\n\n// define how to consume the sign_event_request events\nremoteHandler.events.on('sign_event_request',\n  (event: Event) =\u003e {\n    // ⚠️⚠️⚠️ IMPORTANT: always check if the app is connected \n\n    // do your UI stuff here to ask the user to approve or reject the request    \n\n    // UI components can accept the sign\n    //this.events.emit('sign_event_approve');\n    \n    // or reject \n    //this.events.emit('sign_event_reject');\n  }\n);\n\n// 📡 Listen for incoming requests\nawait remoteHandler.listen();\n``` \n\n### 🔌 Intercept ConnectURI\n\nAllow user to scan the QR code and extract the ConnectURI, intercept it via deep linking or let use manually copy-paste the URI.\n\n```typescript\n// Show to the user the pubkey\nconst { target, relay, metadata } = ConnectURI.fromURI(text);\n\n// if he consents send the connect message\nawait connectURI.approve(key);\n// if rejects could be polite to notify the app of the rejection\nawait connectURI.reject(key);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnostr-connect%2Fconnect","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnostr-connect%2Fconnect","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnostr-connect%2Fconnect/lists"}