Skip to main content
Glama

decryptNip04

Decrypt NIP-04 encrypted messages on Nostr using sender's public key and your private key to access private content.

Instructions

Decrypt NIP-04 ciphertext

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
ciphertextYesNIP-04 encrypted text
senderPubkeyYesSender pubkey (hex or npub)
privateKeyNoPrivate key (nsec or hex). Optional when NOSTR_BUNKER_URI is configured.

Implementation Reference

  • The implementation logic for decrypting NIP-04 messages, which handles both bunker-based and local private key decryption.
    export async function decryptNip04Fn({ ciphertext, senderPubkey, privateKey }: z.infer<typeof decryptNip04Schema>) {
      const sender = normalizePubkey(senderPubkey);
      if (isBunkerMode()) {
        return nip04DecryptWithBunker(sender, ciphertext);
      }
      if (!privateKey) throw new Error('privateKey is required when NOSTR_BUNKER_URI is not configured');
      const sk = normalizePrivateKey(privateKey);
      return nip04.decrypt(sk, sender, ciphertext);
    }
  • Validation schema for the decryptNip04 tool input.
    export const decryptNip04Schema = z.object({
      ciphertext: z.string().describe('NIP-04 encrypted text'),
      senderPubkey: z.string().describe('Sender pubkey (hex or npub)'),
      privateKey: z.string().optional().describe(privateKeyDesc),
    });
  • src/index.ts:129-130 (registration)
    Registration of the decryptNip04 tool with the MCP server.
    server.tool('decryptNip04', 'Decrypt NIP-04 ciphertext', decryptNip04Schema.shape, async (params) => {
      return textResult({ decrypted: await decryptNip04Fn(params) });

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/jorgenclaw/nostr-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server