First upload version 0.0.1
This commit is contained in:
65
node_modules/@octokit/webhooks-methods/dist-node/index.js
generated
vendored
Normal file
65
node_modules/@octokit/webhooks-methods/dist-node/index.js
generated
vendored
Normal file
@@ -0,0 +1,65 @@
|
||||
// pkg/dist-src/node/sign.js
|
||||
import { createHmac } from "node:crypto";
|
||||
|
||||
// pkg/dist-src/version.js
|
||||
var VERSION = "6.0.0";
|
||||
|
||||
// pkg/dist-src/node/sign.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;
|
||||
|
||||
// pkg/dist-src/node/verify.js
|
||||
import { timingSafeEqual } from "node:crypto";
|
||||
import { Buffer } from "node:buffer";
|
||||
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;
|
||||
|
||||
// pkg/dist-src/index.js
|
||||
async function verifyWithFallback(secret, payload, signature, additionalSecrets) {
|
||||
const firstPass = await verify(secret, payload, signature);
|
||||
if (firstPass) {
|
||||
return true;
|
||||
}
|
||||
if (additionalSecrets !== void 0) {
|
||||
for (const s of additionalSecrets) {
|
||||
const v = await verify(s, payload, signature);
|
||||
if (v) {
|
||||
return v;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
export {
|
||||
sign,
|
||||
verify,
|
||||
verifyWithFallback
|
||||
};
|
||||
Reference in New Issue
Block a user