encryptNip44
Encrypt text messages for secure Nostr communications using the NIP-44 standard. Provide plaintext and recipient public key to generate encrypted content.
Instructions
Encrypt text with NIP-44
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| plaintext | Yes | Text to encrypt | |
| recipientPubkey | Yes | Recipient 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:108-117 (handler)The handler function for the encryptNip44 tool, which handles both local signing and remote signing (Bunker mode).
export async function encryptNip44Fn({ plaintext, recipientPubkey, privateKey }: z.infer<typeof encryptNip44Schema>) { const recipient = normalizePubkey(recipientPubkey); if (isBunkerMode()) { return nip44EncryptWithBunker(recipient, plaintext); } if (!privateKey) throw new Error('privateKey is required when NOSTR_BUNKER_URI is not configured'); const sk = normalizePrivateKey(privateKey); const conversationKey = nip44.v2.utils.getConversationKey(sk, recipient); return nip44.v2.encrypt(plaintext, conversationKey); } - src/tools/dm-tools.ts:39-43 (schema)Schema definition for the encryptNip44 tool using Zod.
export const encryptNip44Schema = z.object({ plaintext: z.string().describe('Text to encrypt'), recipientPubkey: z.string().describe('Recipient pubkey (hex or npub)'), privateKey: z.string().optional().describe(privateKeyDesc), });