node-red-contrib-nostr
Version:
Node-RED nodes for seamless Nostr protocol integration. Features robust WebSocket handling, event filtering, and NPUB-based routing. Built with TypeScript for type safety and extensive testing. Perfect for Nostr automation flows.
35 lines (34 loc) • 1.27 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.NIP19 = void 0;
const bech32_1 = require("bech32");
class NIP19 {
static npubEncode(pubkey) {
const words = bech32_1.bech32.toWords(Buffer.from(pubkey, 'hex'));
return bech32_1.bech32.encode('npub', words);
}
static npubDecode(npub) {
const { words } = bech32_1.bech32.decode(npub);
const bytes = Buffer.from(bech32_1.bech32.fromWords(words));
return bytes.toString('hex');
}
static nsecEncode(privkey) {
const words = bech32_1.bech32.toWords(Buffer.from(privkey, 'hex'));
return bech32_1.bech32.encode('nsec', words);
}
static nsecDecode(nsec) {
const { words } = bech32_1.bech32.decode(nsec);
const bytes = Buffer.from(bech32_1.bech32.fromWords(words));
return bytes.toString('hex');
}
static noteEncode(id) {
const words = bech32_1.bech32.toWords(Buffer.from(id, 'hex'));
return bech32_1.bech32.encode('note', words);
}
static noteDecode(note) {
const { words } = bech32_1.bech32.decode(note);
const bytes = Buffer.from(bech32_1.bech32.fromWords(words));
return bytes.toString('hex');
}
}
exports.NIP19 = NIP19;