UNPKG

@kyuzan/mountain-webhook-sdk

Version:

Webhook signature verification SDK for MOUNTAIN platform

85 lines (78 loc) 1.9 kB
/** * Type for webhook event verification result */ type EventVerificationResult = { /** * Whether the verification was successful */ isValid: boolean; /** * Error message if verification failed */ error?: string; /** * Payload data if verification was successful */ payload?: EventPayload; }; /** * Type for webhook event payload */ type EventPayload = { /** * ID of the event record */ id: string; /** * Decoded event log */ event: object; /** * Transaction hash */ transactionHash: string; /** * Block number */ blockNumber: number; /** * Transaction index */ transactionIndex: number; /** * Log index */ logIndex: number; /** * Block timestamp */ blockTimestamp: number; }; /** * Simple webhook request type */ type WebhookRequest = { headers: { [key: string]: string | string[] | undefined; }; body: any; }; type SdkOptions = {}; declare class MountainWebhookSdk { private options; private constructor(); static initialize(opts?: SdkOptions): MountainWebhookSdk; getEventFromRequest: (request: WebhookRequest, webhookSecret: string, toleranceInSeconds?: number | undefined) => EventVerificationResult; } /** * Get event from request * * @param sdk MountainWebhookSdk instance * @param request Webhook request object * @param webhookSecret Webhook secret * @param toleranceInSeconds Timestamp tolerance in seconds * @returns Verification result */ declare function getEventFromRequest(sdk: MountainWebhookSdk, request: WebhookRequest, webhookSecret: string, toleranceInSeconds?: number): EventVerificationResult; declare const initializeSDK: typeof MountainWebhookSdk.initialize; export { MountainWebhookSdk, type SdkOptions, getEventFromRequest, initializeSDK };