@getopenpay/client
Version:
OpenPay API TypeScript SDK
51 lines (50 loc) • 2.03 kB
TypeScript
/**
* Raised when a webhook event signature is invalid.
*/
declare class InvalidSignatureError extends Error {
constructor();
}
/**
* Supported signature versions.
*/
declare enum SignatureVersion {
V1 = "v1"
}
declare class WebhookUtils {
constructor();
/**
* Verification algorithm for OpenPay v1 event signatures.
* See _verifySignature for usage.
*/
private _verifyV1Signature;
/**
* Verifies the signature string for the event message.
*
* @param version - The signature version.
* @param payload - The serialized event data JSON.
* @param timestamp - The timestamp of the signature.
* @param secretKey - The secret key to use for the signature.
* @param signatureDigest - The signature digest to validate.
* @returns True if the signature is valid, False otherwise.
* @throws Error if the signature version is not supported.
*/
private _verifySignature;
/**
* Extracts the timestamp from the signature digest.
*
* @param signatureDigest - The signature digest to extract the timestamp from.
* @returns The timestamp extracted from the signature digest.
*/
extractTimestampFromDigest(signatureDigest: string): number;
/**
* Validates a webhook event payload using the value of the
* signature digest header and a secret key.
*
* @param eventData - The serialized event data JSON. This is the value of the `data` field in the event payload.
* @param signatureDigest - The signature digest to validate. This is the value of the `signature-digest` field in the event payload.
* @param secret - The secret key to use for the signature. This is autogenerated when you create a webhook endpoint. You can find it in the OpenPay dashboard.
* @throws InvalidSignatureError if the signature is invalid.
*/
validatePayload(eventData: string, signatureDigest: string, secret: string): void;
}
export { InvalidSignatureError, SignatureVersion, WebhookUtils };