"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.SignOptions=void 0,exports.sign=sign;const node_crypto_1=require("node:crypto");function sha256(e,s=""){return(0,node_crypto_1.createHmac)("sha256",s).update(e).digest("hex")}function getHash(e){return(0,node_crypto_1.createHash)("sha256").update(e).digest("hex")}class SignOptions{path;query;secretId;secretKey;method;body;headers;timestamp;signedHeaders;isMySql;constructor(s){this.secretId=s.secretId,this.secretKey=s.secretKey,this.method=s.method,this.headers=s.headers,this.timestamp=s.timestamp,this.body=s.body,this.signedHeaders=s.signedHeaders,this.isMySql=s.isMySql}}exports.SignOptions=SignOptions;function sign(e){const s=e.signedHeaders.join(";");let t="";for(const a of e.signedHeaders){const u=e.headers[a];t+=`${a}:${u}
`}const d=getHash(e.body||""),n=e.method.toUpperCase()+`
`+(e.isMySql?"":e.path+`
`)+(e.isMySql?"":e.query+`
`)+t+`
`+s+`
`+d+`
`,r="HMAC-SHA256",c=getHash(n),h=`${r}
${e.timestamp}
${c}
`,i=sha256(h,e.secretKey);return`${r} Credential=${e.secretId}, SignedHeaders=${s}, Signature=${i}`}