{"_id":"@bitchat-sdk/nostr","_rev":"3-406dc1a3bc9e8e882a23ac9764ac47b4","name":"@bitchat-sdk/nostr","dist-tags":{"latest":"0.1.2"},"versions":{"0.1.0":{"name":"@bitchat-sdk/nostr","version":"0.1.0","keywords":["bitchat","nostr","nip17","relay","p2p","mesh"],"license":"Unlicense","_id":"@bitchat-sdk/nostr@0.1.0","maintainers":[{"name":"swarnavab","email":"swarnavacrypto@gmail.com"}],"homepage":"https://github.com/bitchat-sdk/nostr-js#readme","bugs":{"url":"https://github.com/bitchat-sdk/nostr-js/issues"},"dist":{"shasum":"8e60abdd5007b2ea16c858bd98948c7563c9c3a7","tarball":"https://registry.npmjs.org/@bitchat-sdk/nostr/-/nostr-0.1.0.tgz","fileCount":28,"integrity":"sha512-i9pWcouISeTmcLhKkBjUwy8BfTvxr+vMRwVN9FIqrdYF4HoW8gghre9p89v7AbVYorK0T8mOddHLYE60Ithnpw==","signatures":[{"sig":"MEQCIGMDlnWuEgtLX3Ter2Ui3IhmFHU0+k/vs8iBkuDWB+0EAiA6MRQcucA6GNcBvbVCi7ORiuK/MiqndShZftFslFpMag==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":69600},"main":"dist/index.js","types":"dist/index.d.ts","engines":{"node":">=18.0.0"},"exports":{".":{"types":"./dist/index.d.ts","require":"./dist/index.js"}},"gitHead":"92c8d469186f3059565d35fc1bd64243f21a7a2c","scripts":{"lint":"tsc --noEmit","test":"node --test dist/tests/*.test.js","build":"tsc","prepublishOnly":"npm run build && npm test"},"_npmUser":{"name":"swarnavab","email":"swarnavacrypto@gmail.com"},"repository":{"url":"git+https://github.com/bitchat-sdk/nostr-js.git","type":"git"},"_npmVersion":"10.9.4","description":"BitChat-over-Nostr transport — NIP-17 gift wrap, relay client, embedded packet helpers","directories":{},"_nodeVersion":"22.22.0","dependencies":{"ws":"^8.17.0","@bitchat-sdk/protocol-core":"^0.1.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"@types/ws":"^8.18.1","typescript":"^5.4.0"},"peerDependencies":{"@noble/curves":"^1.4.0","@noble/hashes":"^1.4.0"},"peerDependenciesMeta":{"@noble/curves":{"optional":true},"@noble/hashes":{"optional":true}},"_npmOperationalInternal":{"tmp":"tmp/nostr_0.1.0_1774366254953_0.9785649908645915","host":"s3://npm-registry-packages-npm-production"}},"0.1.1":{"name":"@bitchat-sdk/nostr","version":"0.1.1","keywords":["bitchat","nostr","nip17","relay","p2p","mesh"],"license":"Unlicense","_id":"@bitchat-sdk/nostr@0.1.1","maintainers":[{"name":"swarnavab","email":"swarnavacrypto@gmail.com"}],"homepage":"https://github.com/bitchat-sdk/nostr-js#readme","bugs":{"url":"https://github.com/bitchat-sdk/nostr-js/issues"},"dist":{"shasum":"3ab04fa9e32eeed3c236f128b00b025e7066afdf","tarball":"https://registry.npmjs.org/@bitchat-sdk/nostr/-/nostr-0.1.1.tgz","fileCount":28,"integrity":"sha512-/djkzuCuHsAi6dI9OzDt8nTPm5ySvzIObnuoU5O8PzTABH55TOJCXxNeX22qb5pXHE3/4nRQn3BF0DUyiJAULw==","signatures":[{"sig":"MEYCIQCr1jDkDGbE8xAUr8HwLwWMF9WlrQqdBMY4LngsfTqG7wIhAOUT68tjp0Xdy4fClKOg21a28GOA+XSG5YQjgyOwzIlM","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":70316},"main":"dist/index.js","types":"dist/index.d.ts","engines":{"node":">=18.0.0"},"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.js"}},"gitHead":"eececb9853d3877db8f7766999613ca7142ab96e","scripts":{"lint":"tsc --noEmit","test":"node --test dist/tests/*.test.js","build":"tsc","prepublishOnly":"npm run build && npm test"},"_npmUser":{"name":"swarnavab","email":"swarnavacrypto@gmail.com"},"repository":{"url":"git+https://github.com/bitchat-sdk/nostr-js.git","type":"git"},"_npmVersion":"10.9.4","description":"BitChat-over-Nostr transport — NIP-17 gift wrap, relay client, embedded packet helpers","directories":{},"_nodeVersion":"22.22.0","dependencies":{"ws":"^8.17.0","@bitchat-sdk/protocol-core":"^0.1.2"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"@types/ws":"^8.18.1","typescript":"^5.4.0","@types/node":"^25.5.0"},"peerDependencies":{"@noble/curves":"^1.4.0","@noble/hashes":"^1.4.0"},"peerDependenciesMeta":{"@noble/curves":{"optional":true},"@noble/hashes":{"optional":true}},"_npmOperationalInternal":{"tmp":"tmp/nostr_0.1.1_1777922324950_0.9619100580722288","host":"s3://npm-registry-packages-npm-production"}},"0.1.2":{"name":"@bitchat-sdk/nostr","version":"0.1.2","description":"BitChat-over-Nostr transport — NIP-17 gift wrap, relay client, embedded packet helpers","main":"dist/index.js","types":"dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.js"}},"scripts":{"build":"tsc","test":"node --test dist/tests/*.test.js","lint":"tsc --noEmit","prepublishOnly":"npm run build && npm test"},"keywords":["bitchat","nostr","nip17","relay","p2p","mesh"],"license":"Unlicense","repository":{"type":"git","url":"git+https://github.com/bitchat-sdk/nostr-js.git"},"homepage":"https://github.com/bitchat-sdk/nostr-js#readme","bugs":{"url":"https://github.com/bitchat-sdk/nostr-js/issues"},"publishConfig":{"access":"public"},"engines":{"node":">=18.0.0"},"devDependencies":{"@types/node":"^25.5.0","@types/ws":"^8.18.1","typescript":"^5.4.0"},"dependencies":{"@bitchat-sdk/protocol-core":"^0.2.0","ws":"^8.17.0"},"peerDependencies":{"@noble/curves":"^1.4.0","@noble/hashes":"^1.4.0"},"peerDependenciesMeta":{"@noble/curves":{"optional":true},"@noble/hashes":{"optional":true}},"_id":"@bitchat-sdk/nostr@0.1.2","gitHead":"23e340b45928351e0771a4bd40c1a6df79bf9088","_nodeVersion":"22.22.0","_npmVersion":"10.9.4","dist":{"integrity":"sha512-C7dsahP2atzaATusvftfdV0J2ycineWeX05Epa75s/7UhjTv+zfHhNa4pP3Z4hip3724Bm/cjAsMolhRNskvEQ==","shasum":"dc70c022e81db0ff982267096d340f87124eed8b","tarball":"https://registry.npmjs.org/@bitchat-sdk/nostr/-/nostr-0.1.2.tgz","fileCount":28,"unpackedSize":70692,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIHJSMPX7PqB9FZFRLg6VhTQVC55Zks8yefly3brbMS4MAiEAuiiL4slM/m3kZdghCRMTkuso0rPr8AwbO8KWeE55OSo="}]},"_npmUser":{"name":"swarnavab","email":"swarnavacrypto@gmail.com"},"directories":{},"maintainers":[{"name":"swarnavab","email":"swarnavacrypto@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/nostr_0.1.2_1782299355280_0.4090784680674726"},"_hasShrinkwrap":false}},"time":{"created":"2026-03-24T15:30:54.797Z","modified":"2026-06-24T11:09:15.527Z","0.1.0":"2026-03-24T15:30:55.099Z","0.1.1":"2026-05-04T19:18:45.119Z","0.1.2":"2026-06-24T11:09:15.412Z"},"bugs":{"url":"https://github.com/bitchat-sdk/nostr-js/issues"},"license":"Unlicense","homepage":"https://github.com/bitchat-sdk/nostr-js#readme","keywords":["bitchat","nostr","nip17","relay","p2p","mesh"],"repository":{"type":"git","url":"git+https://github.com/bitchat-sdk/nostr-js.git"},"description":"BitChat-over-Nostr transport — NIP-17 gift wrap, relay client, embedded packet helpers","maintainers":[{"name":"swarnavab","email":"swarnavacrypto@gmail.com"}],"readme":"# @bitchat-sdk/nostr\n\n[![npm](https://img.shields.io/npm/v/@bitchat-sdk/nostr)](https://www.npmjs.com/package/@bitchat-sdk/nostr)\n[![License: Unlicense](https://img.shields.io/badge/license-Unlicense-blue.svg)](https://unlicense.org)\n\nBitChat-over-Nostr transport for Node.js.\n\nImplements the relay transport layer used in the BitChat mesh app:\nNIP-17 gift-wrap private messages, relay client (NIP-01), and helpers\nfor embedding BitChat binary packets inside Nostr events.\n\n## Installation\n\n```bash\nnpm install @bitchat-sdk/nostr @bitchat-sdk/protocol-core\n# NIP-17 encryption requires a secp256k1 library (optional):\nnpm install @noble/curves @noble/hashes\n```\n\n## Quick Start\n\n### Listen for BitChat packets via Nostr relay\n\n```ts\nimport { RelayClient, extractPacketFromEvent } from '@bitchat-sdk/nostr';\nimport { NostrKind } from '@bitchat-sdk/nostr';\n\nconst relay = new RelayClient({ url: 'wss://relay.example.com' });\nawait relay.connect();\n\nrelay.subscribe('bitchat-dm', [{ kinds: [NostrKind.GiftWrap] }], async (event) => {\n  // After decrypting the gift wrap (see NIP-17 section), extract the BitChat packet:\n  const embedded = await extractPacketFromEvent(event);\n  if (embedded) {\n    console.log('Received BitChat packet from', embedded.senderIDHex);\n  }\n});\n```\n\n### Send a BitChat packet via NIP-17\n\n```ts\nimport { encode } from '@bitchat-sdk/protocol-core';\nimport { buildDMRumor, wrapAndSend } from '@bitchat-sdk/nostr';\nimport type { CryptoProvider } from '@bitchat-sdk/nostr';\n\n// 1. Encode your BitChat packet\nconst wire = await encode(myPacket, { padding: false });\n\n// 2. Build a NIP-17 DM rumor carrying the packet\nconst rumor = buildDMRumor(wire, senderNostrPubkey, recipientNostrPubkey);\n\n// 3. Wrap and publish (requires your CryptoProvider implementation)\nconst giftWrapEvent = await wrapAndSend(rumor, senderPrivkey, recipientPubkey, crypto);\nconst ok = await relay.publish(giftWrapEvent);\nconsole.log('Published:', ok);\n```\n\n## API\n\n### RelayClient\n\n```ts\nnew RelayClient(config: RelayConfig, options?: RelayClientOptions)\nclient.connect(): Promise<void>\nclient.close(): void\nclient.publish(event: NostrEvent): Promise<boolean>\nclient.subscribe(id, filters, onEvent, onEose?)\nclient.unsubscribe(id)\n```\n\n### Embedding Helpers\n\n```ts\nencodePacketToBase64(packet: Uint8Array): string\ndecodePacketFromBase64(content: string): Promise<BitchatPacket | null>\nbuildDMRumor(packet, senderPubkey, recipientPubkey): NostrRumor\nbuildGeohashPresenceEvent(packet, senderPubkey, geohash): NostrRumor\nextractPacketFromEvent(event: NostrEvent): Promise<EmbeddedBitChatPayload | null>\n```\n\n### NIP-17 Gift Wrap\n\n```ts\nwrapAndSend(rumor, senderPrivkey, recipientPubkey, crypto): Promise<NostrEvent>\nreceiveAndUnwrap(giftWrapEvent, recipientPrivkey, crypto): Promise<NostrRumor | null>\n// Individual operations:\nsealRumor(rumor, senderPrivkey, recipientPubkey, crypto): Promise<NostrEvent>\ngiftWrap(seal, recipientPubkey, crypto): Promise<NostrEvent>\nunwrapGift(giftWrapEvent, recipientPrivkey, crypto): Promise<NostrEvent | null>\nunsealRumor(sealEvent, recipientPrivkey, crypto): Promise<NostrRumor | null>\n```\n\n### CryptoProvider Interface\n\n`wrapAndSend` / `receiveAndUnwrap` require a `CryptoProvider`:\n\n```ts\ninterface CryptoProvider {\n  nip44Encrypt(plaintext, senderPrivkey, recipientPubkey): Promise<string>\n  nip44Decrypt(ciphertext, recipientPrivkey, senderPubkey): Promise<string | null>\n  getPublicKey(privateKey: Uint8Array): string\n  signEvent(event, privateKey): Promise<NostrEvent>\n  generateEphemeralKey(): Uint8Array\n}\n```\n\nImplement using `@noble/curves` (secp256k1) + NIP-44 spec.\n\n## BitChat-over-Nostr Protocol\n\nBitChat packets are base64-encoded and placed in the `content` field of Nostr events.\n\n- **Private messages**: kind 14 rumor → kind 13 seal → kind 1059 gift-wrap\n- **Peer announcements**: kind 20001 (GeohashPresence), no encryption\n- The inner BitChat packet carries all mesh-protocol metadata (sender ID, TTL, type)\n\n## Supported Relays\n\nAny NIP-01 compliant relay. Tested with:\n- `wss://relay.damus.io`\n- `wss://relay.nostr.band`\n- `wss://nos.lol`\n\n## Known Limitations\n\n- NIP-44 encryption is not bundled — inject your own `CryptoProvider`.\n- Relay rate limiting is not automatically enforced; add your own throttling for high-volume use cases.\n- Browser support requires a `WebSocket` polyfill in environments without native WS.\n\n## License\n\nUnlicense — public domain.\n","readmeFilename":"README.md"}