@blockfrost/blockfrost-js
Advanced tools
Comparing version 6.0.0-beta.0 to 6.0.0-beta.1
@@ -167,2 +167,13 @@ "use strict"; | ||
exports.parseAsset = parseAsset; | ||
const parseWebhookPayload = (payload) => { | ||
if (Buffer.isBuffer(payload)) { | ||
return JSON.parse(payload.toString('utf8')); | ||
} | ||
else if (typeof payload === 'string') { | ||
return JSON.parse(payload); | ||
} | ||
else { | ||
return payload; | ||
} | ||
}; | ||
/** | ||
@@ -190,6 +201,4 @@ * Verifies webhook signature | ||
} | ||
// Stringified webhook payload | ||
const decodedWebhookPayload = Buffer.isBuffer(webhookPayload) | ||
? webhookPayload.toString('utf8') | ||
: webhookPayload; | ||
const parsedWebhookPayload = parseWebhookPayload(webhookPayload); | ||
const stringifiedWebhookPayload = JSON.stringify(parsedWebhookPayload); | ||
const decodedSignatureHeader = Buffer.isBuffer(signatureHeader) | ||
@@ -218,3 +227,3 @@ ? signatureHeader.toString('utf8') | ||
signatureHeader: decodedSignatureHeader, | ||
webhookPayload: decodedWebhookPayload, | ||
webhookPayload: stringifiedWebhookPayload, | ||
}); | ||
@@ -225,3 +234,3 @@ } | ||
signatureHeader: decodedSignatureHeader, | ||
webhookPayload: decodedWebhookPayload, | ||
webhookPayload: stringifiedWebhookPayload, | ||
}); | ||
@@ -233,3 +242,3 @@ } | ||
// then compute HMAC using sha256 and provided secret (auth token) | ||
const signaturePayload = `${timestamp}.${decodedWebhookPayload}`; | ||
const signaturePayload = `${timestamp}.${stringifiedWebhookPayload}`; | ||
const hmac = (0, crypto_1.createHmac)('sha256', secret) | ||
@@ -246,3 +255,3 @@ .update(signaturePayload) | ||
signatureHeader: decodedSignatureHeader, | ||
webhookPayload: decodedWebhookPayload, | ||
webhookPayload: stringifiedWebhookPayload, | ||
}); | ||
@@ -255,3 +264,3 @@ } | ||
signatureHeader: decodedSignatureHeader, | ||
webhookPayload: decodedWebhookPayload, | ||
webhookPayload: stringifiedWebhookPayload, | ||
}); | ||
@@ -261,3 +270,3 @@ } | ||
// Successfully validate the signature only if it is within timestamp_tolerance_seconds tolerance | ||
const webhookEvent = JSON.parse(decodedWebhookPayload); | ||
const webhookEvent = parsedWebhookPayload; | ||
return webhookEvent; | ||
@@ -264,0 +273,0 @@ } |
{ | ||
"name": "@blockfrost/blockfrost-js", | ||
"version": "6.0.0-beta.0", | ||
"version": "6.0.0-beta.1", | ||
"description": "A JavaScript/TypeScript SDK for interacting with the https://blockfrost.io API", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
250314
5291