MOUNTAIN Webhook SDK
Secure webhook verification and event processing for MOUNTAIN Events notifications.
What is the Webhook SDK?
The MOUNTAIN Webhook SDK provides a secure and easy way to receive and process blockchain event notifications from MOUNTAIN Events. It handles webhook signature verification, event parsing, and provides type-safe interfaces for processing events.
Key Features
- Secure Verification: Automatic HMAC-SHA256 signature verification
- Type Safety: Full TypeScript support with proper type definitions
- Easy Integration: Simple API that works with any Node.js web framework
- Event Processing: Structured event data with decoded parameters
- Error Handling: Clear error messages and validation feedback
📦 Installation
npm install @kyuzan/mountain-webhook-sdk
🚀 Quick Start
Basic Usage
import express from 'express';
import { initializeSDK } from '@kyuzan/mountain-webhook-sdk';
// Webhook secret (in production, get this from environment variables)
const WEBHOOK_SECRET = 'mtn_whsec_your_webhook_secret_here';
// Initialize the SDK
const sdk = initializeSDK();
// Initialize Express application
const app = express();
app.use(express.json());
// Webhook endpoint
app.post('/webhook', (req, res) => {
try {
// Validate and get the webhook event from the request
const result = sdk.getEventFromRequest(req, WEBHOOK_SECRET);
// If validation fails
if (!result.isValid) {
console.error(`Webhook validation error: ${result.error}`);
return res.status(400).json({ error: result.error });
}
// If validation succeeds, process the payload
const payload = result.payload;
console.log('Webhook event received:', payload);
// Implement your payload processing logic here
// Examples: Save to database, notify other services, etc.
// Return success response
return res.status(200).json({ received: true });
} catch (error) {
console.error('Webhook processing error:', error);
return res.status(500).json({ error: 'Internal server error' });
}
});
const PORT = process.env.PORT || 3011;
app.listen(PORT, () => {
console.log(`Webhook server started: http://localhost:${PORT}`);
});
Getting Your Webhook Secret
Your webhook secret is provided when you configure webhook settings via the MOUNTAIN API. The secret has the format: mtn_whsec_[base64_encoded_secret]
SDK API Reference
initializeSDK()
Initializes the webhook SDK instance.
const sdk = initializeSDK();
getEventFromRequest(request, secret)
Validates and extracts the event payload from an HTTP request.
Parameters:
request
: HTTP request object (Express.js format)secret
: Your webhook secret string
Returns:
{
isValid: boolean;
payload?: EventPayload;
error?: string;
}