{"id":13832622,"url":"https://github.com/cmdruid/nostr-emitter","last_synced_at":"2025-05-07T20:43:43.850Z","repository":{"id":60211820,"uuid":"527311454","full_name":"cmdruid/nostr-emitter","owner":"cmdruid","description":"An end-to-end group encrypted event emitter, built on the Nostr protocol.","archived":false,"fork":false,"pushed_at":"2023-02-05T00:54:51.000Z","size":273,"stargazers_count":48,"open_issues_count":1,"forks_count":6,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-05-07T20:43:38.340Z","etag":null,"topics":["e2e","event-emitter","nostr","p2p","peer-to-peer","pubsub","realtime","websockets"],"latest_commit_sha":null,"homepage":"https://cmdruid.github.io/nostr-emitter/examples/nostr-chat","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"cc0-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cmdruid.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}},"created_at":"2022-08-21T19:50:14.000Z","updated_at":"2025-03-25T14:30:19.000Z","dependencies_parsed_at":"2023-02-18T20:45:30.250Z","dependency_job_id":null,"html_url":"https://github.com/cmdruid/nostr-emitter","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cmdruid%2Fnostr-emitter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cmdruid%2Fnostr-emitter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cmdruid%2Fnostr-emitter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cmdruid%2Fnostr-emitter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cmdruid","download_url":"https://codeload.github.com/cmdruid/nostr-emitter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252954140,"owners_count":21830894,"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","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":["e2e","event-emitter","nostr","p2p","peer-to-peer","pubsub","realtime","websockets"],"created_at":"2024-08-04T11:00:24.580Z","updated_at":"2025-05-07T20:43:43.815Z","avatar_url":"https://github.com/cmdruid.png","language":"JavaScript","funding_links":[],"categories":["Install from Source","Clients"],"sub_categories":["Nostr","Relay lists"],"readme":"# nostr-emitter\nA basic peer-to-peer event emitter, built on the Nostr protocol.\n\n\n## Installation\nThis package is designed to work in both the browser and nodejs.\n\n```html\n\u003c!-- Browser import --\u003e\n\u003cscript src='https://bundle.run/noble-secp256k1@1.2.14'\u003e\u003c/script\u003e\n\u003cscript src=\"https://unpkg.com/@cmdcode/nostr-emitter\"\u003e\u003c/script\u003e\n```\n```js\n// Commonjs import.\nconst NostrEmitter = require('@cmdcode/nostr-emitter')\n\n// ES6 import.\nimport NostrEmitter from '@cmdcode/nostr-emitter'\n```\n\n## How to use\nTo get started, simply provide a relay server and shared secret to use, then run `emitter.connect()`.\n\nOnce connected, the emitter behaves like a typical EventEmitter object.\n```js\n// Declare a new event emitter object.\nconst emitter = new NostrEmitter()\n\n// Connect your emitter to the relay.\nawait emitter.connect(\n  'wss://nostr.zebedee.cloud',\n  'secret-string'\n)\n\n// Register an event listener.\nemitter.on('some-event', eventData =\u003e {\n  console.log('Hello ', eventData)\n})\n\n// Publish events like any other emitter.\nemitter.emit('some-event', 'world!')\n\n// Self-published events are filtered out \n// by default, but you can enable them.\nemitter.opt.selfsub = true\n\n// Specify optional parameters.\nconst emitter = new NostrEmitter({\n  version : 0,          // Nostr protocol version.\n  kind    : 29001,      // Default event type (ephemeral).\n  selfPub : false,      // Filter self-published events.\n  socket  : WebSocket,  // Specify your own websocket object.\n  tags    : [],         // Add your own tags to each message.\n  filter  : {}          // Add your own subscription filters.\n})\n```\n\n\n## How it works\nThe contents of each event is end-to-end encrypted using a hash of the shared secret, then the event itself is tagged with a double-hash of the secret. \n\nEvents are filtered by this hash-tag, so each emitter will only see events tagged with the proper hash. Old events are also filtered out by default.\n\nEverything else works like a basic event emitter API. Methods include 'on', 'once', 'emit' and 'remove'.\n\nSome helpful tips:\n* For public channels, the shared secret can be something obvious, like 'general-chat'.\n* For organizing groups or channels, try using paths as a secret string: 'secret/topic/subtopic'\n* You can change the default emitter.filter before calling emitter.connect().\n* The main index.js file is less than 400 lines of code. Feel free to change it as you wish!\n\n\n## Resources\n\n**Noble-secp256k1 Library**  \nUsed for identity and signing events.  \nhttps://github.com/paulmillr/noble-secp256k1\n\n**Websockets** (nodejs only)  \nUsed for communicating over a websocket.  \nhttps://github.com/websockets/ws\n\n**Nostr Implementation Possibilities**  \nhttps://github.com/nostr-protocol/nips\n\n**Nostr-tools**  \nhttps://github.com/fiatjaf/nostr-tools\n\n## Contributions\nAll contributions are welcome!\n\n## Special Thanks\nSpecial thanks to supertestnet for his help and guidance.  \nhttps://github.com/supertestnet\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcmdruid%2Fnostr-emitter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcmdruid%2Fnostr-emitter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcmdruid%2Fnostr-emitter/lists"}