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
| Name | Required | Description | Default |
|---|---|---|---|
| ciphertext | Yes | NIP-04 encrypted text | |
| senderPubkey | Yes | Sender pubkey (hex or npub) | |
| privateKey | No | Private key (nsec or hex). Optional when NOSTR_BUNKER_URI is configured. |
Implementation Reference
- src/tools/dm-tools.ts:68-76 (handler)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); } - src/tools/dm-tools.ts:26-30 (schema)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) });