First upload version 0.0.1

This commit is contained in:
Neyra
2026-02-05 15:27:49 +08:00
commit 8e9b7201ed
4182 changed files with 593136 additions and 0 deletions

View File

@@ -0,0 +1,18 @@
import { createHmac } from "node:crypto";
import { VERSION } from "../version.js";
async function sign(secret, payload) {
if (!secret || !payload) {
throw new TypeError(
"[@octokit/webhooks-methods] secret & payload required for sign()"
);
}
if (typeof payload !== "string") {
throw new TypeError("[@octokit/webhooks-methods] payload must be a string");
}
const algorithm = "sha256";
return `${algorithm}=${createHmac(algorithm, secret).update(payload).digest("hex")}`;
}
sign.VERSION = VERSION;
export {
sign
};

View File

@@ -0,0 +1,26 @@
import { timingSafeEqual } from "node:crypto";
import { Buffer } from "node:buffer";
import { sign } from "./sign.js";
import { VERSION } from "../version.js";
async function verify(secret, eventPayload, signature) {
if (!secret || !eventPayload || !signature) {
throw new TypeError(
"[@octokit/webhooks-methods] secret, eventPayload & signature required"
);
}
if (typeof eventPayload !== "string") {
throw new TypeError(
"[@octokit/webhooks-methods] eventPayload must be a string"
);
}
const signatureBuffer = Buffer.from(signature);
const verificationBuffer = Buffer.from(await sign(secret, eventPayload));
if (signatureBuffer.length !== verificationBuffer.length) {
return false;
}
return timingSafeEqual(signatureBuffer, verificationBuffer);
}
verify.VERSION = VERSION;
export {
verify
};