Skip to content

Node.js SDK

Terminal window
npm install @venmail/vsm

Requires Node.js 18+. Zero runtime dependencies.

FeatureDescription
Webhook verificationHMAC-SHA256 signature validation
Express middlewareDrop-in webhook handler
VVS-1 signingEd25519 message signing
VVS-1 verificationFull verification pipeline
Key managementKeypair generation, import/export
Key resolutionWell-known, DNS, and embedded key lookup
Type detectionDiscriminated union webhook type guards
Event normalizationConsistent delivery event schema
import { venmailIntegrationWebhook } from '@venmail/vsm';
app.post('/webhooks/venmail', venmailIntegrationWebhook({
secret: process.env.VENMAIL_WEBHOOK_SECRET,
onEvent: (event) => {
switch (event.event) {
case 'MessageDelivered':
console.log('Delivered to:', event.payload.rcpt_to);
break;
case 'MessageBounced':
console.log('Bounced:', event.payload.bounce_message);
break;
}
},
}));
import { vvs } from '@venmail/vsm';
// Generate keypair (once)
const keyPair = vvs.generateKeyPair();
// Sign a message
const result = vvs.signMessage(
'Hello, world!',
{ from: '[email protected]', to: '[email protected]', subject: 'Hi', date: new Date().toUTCString() },
{ agentId: '[email protected]', privateKey: keyPair.privateKey, verifyMethods: ['well-known'] }
);
// result.headers = { 'X-Venmail-Agent': '...', 'X-Venmail-Signature': '...', ... }
import { vvs } from '@venmail/vsm';
const result = await vvs.verifyMessage(
vvsHeaders, // Record<string, string> of X-Venmail-* headers
emailBody, // string
emailHeaders, // { from, to, subject, date }
);
console.log(result.trustLevel); // 'VERIFIED' | 'PARTIAL' | 'FAILED' | 'UNKNOWN'

Serve the .well-known/venmail-agent endpoint:

import { venmailWellKnown } from '@venmail/vsm';
app.use(venmailWellKnown(async (agentName) => {
const key = await db.getAgentKey(agentName);
if (!key) return null;
return {
agent_id: `${agentName}@yourdomain.com`,
public_key: key.publicKeyBase64url,
key_version: key.version,
status: 'active',
algorithm: 'ed25519',
};
}));
import { generateDnsRecord } from '@venmail/vsm';
const record = generateDnsRecord('billing', keyPair.publicKeyBase64url, 1);
// "v=VVS1; agent=billing; pubkey=...; kv=1; status=active"
// Add as TXT record on _venmail.yourdomain.com

Full TypeScript support with exported types:

import type { VvsTrustLevel, VvsHeaders, VvsSignResult, VvsVerifyResult, VvsKeyPair } from '@venmail/vsm';

See the GitHub repository for complete API documentation.