aws-delivlib
Version:
A fabulous library for defining continuous pipelines for building, testing and releasing code libraries.
25 lines (24 loc) • 813 B
JavaScript
import { createHmac } from "crypto";
import { Algorithm } from "../types";
import { VERSION } from "../version";
async function sign(options, payload) {
const { secret, algorithm } = typeof options === "object" ? {
secret: options.secret,
algorithm: options.algorithm || Algorithm.SHA256
} : { secret: options, algorithm: Algorithm.SHA256 };
if (!secret || !payload) {
throw new TypeError(
"[@octokit/webhooks-methods] secret & payload required for sign()"
);
}
if (!Object.values(Algorithm).includes(algorithm)) {
throw new TypeError(
`[@octokit/webhooks] Algorithm ${algorithm} is not supported. Must be 'sha1' or 'sha256'`
);
}
return `${algorithm}=${createHmac(algorithm, secret).update(payload).digest("hex")}`;
}
sign.VERSION = VERSION;
export {
sign
};