Nostr Utils icon

Nostr Utils

Nostr Utility

Overview

This node, named "Nostr Utils," provides utility functions for working with Nostr protocol events and keys. It supports three main operations:

  • ConvertEvent: Converts a Nostr event JSON into either an naddr or nevent encoded string, which are standardized Nostr resource identifiers. This is useful when you want to generate compact references to events for sharing or indexing.
  • TransformKeys: Transforms cryptographic keys between different formats such as Bech32-encoded public keys (npub), secret keys (nsec), and their hexadecimal representations. This helps in key management and interoperability between systems expecting different key formats.
  • DecryptNip04: Decrypts messages encrypted using the NIP-04 standard (a Nostr encryption protocol) given the sender's public key and encrypted content. Useful for reading private messages.

Practical Examples

  • Converting a full event JSON into an naddr string to embed in a message or UI element.
  • Transforming a hex secret key into a Bech32 nsec format for use in other Nostr tools.
  • Decrypting a NIP-04 encrypted chat message received from another user.

Properties

Name Meaning
ConvertOutput Output format for event conversion: naddr (Nostr address) or nevent (Nostr event identifier).
Event The source event JSON object or string to convert (required for ConvertEvent operation).
Relay Hints Comma-separated list of relay WebSocket URLs used as hints during encoding of naddr or nevent.
Operation The utility operation to perform: convertEvent, transformKey, or decryptNip04.
TransformTo Target key format for transformation: npub, nsec, hexpubkey, or hexseckey (for transformKey operation).
TransformInput Input key value to transform (required for transformKey operation).
Sender Public Key Public key of the message sender in npub or hex format (required for decryptNip04 operation).
Encrypted Content The NIP-04 encrypted message content to decrypt (required for decryptNip04 operation).

Output

The node outputs a JSON array where each item depends on the selected operation:

  • ConvertEvent:

    • If naddr selected: { "naddr": "<encoded naddr string>" }
    • If nevent selected: { "nevent": "<encoded nevent string>" }
  • TransformKeys:

    • { "output": "<transformed key string>", "type": "<target format>" }
  • DecryptNip04:

    • { "decryptedContent": "<decrypted plaintext>", "senderPubkey": "<hex public key>", "originalEncrypted": "<original encrypted content>" }

No binary data output is produced by this node.

Dependencies

  • Uses the nostr-tools library for encoding/decoding and decryption.
  • Uses @noble/hashes/utils for hex-to-byte conversions.
  • Requires a WebSocket implementation (ws package) globally assigned.
  • For decryption, requires an API key credential containing a secret key (used internally for NIP-04 decryption).
  • Default relay addresses are provided but can be customized via input.

Troubleshooting

  • Invalid Event JSON value: Occurs if the provided event JSON is malformed or missing required fields like the d tag for naddr encoding. Ensure valid event JSON is supplied.
  • Invalid secret key was provided!: Happens if the secret key credential is missing or incorrectly formatted for decryption. Verify that the API key credential is configured properly.
  • Failed to decrypt NIP-04 message: Could be due to incorrect sender public key, corrupted encrypted content, or mismatched secret key. Double-check inputs and credentials.
  • Invalid transformTo value: When transforming keys, ensure the target format is one of the supported options.
  • Relay hints should be valid WebSocket URLs separated by commas; invalid URLs may cause encoding issues.

Links and References

Discussion