@candriajs/git-neko-kit
Version:
Github, Gitee, GitCode API封装库
1 lines • 979 B
JavaScript
import{GitHubClient as e,InvalidWebHookSignatureFormatMsg as t,MissingWebHookPayloadMsg as n,MissingWebHookSecretMsg as r,MissingWebHookSignatureMsg as i,WebHookSignatureSuccessMsg as a,WebHookSignatureVerificationFailedMsg as o}from"./client-sGV7POG-.mjs";import s from"node:crypto";var c=class extends e{async check_webhook_signature(e){if(!this.WebHook_Secret)throw Error(r);if(!e.payload)throw Error(n);if(!e.signature)throw Error(i);if(!e.signature.startsWith(`sha256=`))throw Error(t);let c=!1,l=`error`,u=400,d,f,p=s.createHmac(`sha256`,this.WebHook_Secret),m=typeof e.payload==`string`?e.payload:JSON.stringify(e.payload);p.update(m,`utf8`);let h=p.digest(`hex`),g=e.signature.replace(`sha256=`,``),_=s.timingSafeEqual(Buffer.from(h),Buffer.from(g));return _?(c=!0,l=`ok`,u=200,d=`请求成功`,f={success:c,message:a}):(c=!1,l=`error`,u=403,d=`请求失败`,f={success:c,message:o}),Promise.resolve({success:c,status:l,statusCode:u,msg:d,data:f})}};export{c as WebHook};