@amigo-ai/platform-sdk 0.4.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +60 -55
- package/dist/core/webhooks.js +8 -2
- package/dist/core/webhooks.js.map +1 -1
- package/dist/index.cjs +10 -2
- package/dist/index.cjs.map +2 -2
- package/dist/index.mjs +10 -2
- package/dist/index.mjs.map +2 -2
- package/dist/types/core/webhooks.d.ts.map +1 -1
- package/package.json +9 -4
package/dist/index.mjs
CHANGED
|
@@ -2135,7 +2135,11 @@ var WebhookVerificationError = class extends Error {
|
|
|
2135
2135
|
async function verifyWebhookSignature(payloadOrOptions, signature, secret) {
|
|
2136
2136
|
const options = normalizeVerificationOptions(payloadOrOptions, signature, secret);
|
|
2137
2137
|
const payloadBytes = toUint8Array(options.payload);
|
|
2138
|
-
const expectedSignature = await signWebhookPayload(
|
|
2138
|
+
const expectedSignature = await signWebhookPayload(
|
|
2139
|
+
payloadBytes,
|
|
2140
|
+
options.secret,
|
|
2141
|
+
options.timestamp
|
|
2142
|
+
);
|
|
2139
2143
|
const actualSignature = normalizeSignature(options.signature);
|
|
2140
2144
|
if (!actualSignature || !constantTimeEqual(expectedSignature, actualSignature)) {
|
|
2141
2145
|
return false;
|
|
@@ -2216,7 +2220,7 @@ async function signWebhookPayload(payload, secret, timestamp) {
|
|
|
2216
2220
|
["sign"]
|
|
2217
2221
|
);
|
|
2218
2222
|
const message = timestamp ? concatUint8Arrays(textEncoder.encode(`v1:${timestamp}:`), payload) : payload;
|
|
2219
|
-
const mac = await crypto.subtle.sign("HMAC", key, message);
|
|
2223
|
+
const mac = await crypto.subtle.sign("HMAC", key, toCryptoBuffer(message));
|
|
2220
2224
|
return new Uint8Array(mac);
|
|
2221
2225
|
}
|
|
2222
2226
|
function normalizeSignature(signature) {
|
|
@@ -2252,6 +2256,10 @@ function concatUint8Arrays(left, right) {
|
|
|
2252
2256
|
combined.set(right, left.length);
|
|
2253
2257
|
return combined;
|
|
2254
2258
|
}
|
|
2259
|
+
function toCryptoBuffer(bytes) {
|
|
2260
|
+
const copy = Uint8Array.from(bytes);
|
|
2261
|
+
return copy.buffer;
|
|
2262
|
+
}
|
|
2255
2263
|
|
|
2256
2264
|
// src/index.ts
|
|
2257
2265
|
var DEFAULT_BASE_URL = "https://api.platform.amigo.ai";
|