added doga

This commit is contained in:
szabomarton
2025-02-25 09:55:29 +01:00
parent 5174ab4cc4
commit 13254e5623
1149 changed files with 80161 additions and 0 deletions

View File

@@ -0,0 +1,10 @@
/**
* Sign the given `val` with `secret`.
*/
export declare const sign: (val: string, secret: string) => string;
/**
* Unsign and decode the given `val` with `secret`,
* returning `false` if the signature is invalid.
*/
export declare const unsign: (val: string, secret: string) => string | false;
//# sourceMappingURL=index.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,eAAO,MAAM,IAAI,QAAS,MAAM,UAAU,MAAM,KAAG,MACuC,CAAA;AAE1F;;;GAGG;AACH,eAAO,MAAM,MAAM,QAAS,MAAM,UAAU,MAAM,KAAG,MAAM,GAAG,KAQ7D,CAAA"}

View File

@@ -0,0 +1,15 @@
import { createHmac, timingSafeEqual } from "node:crypto";
const sign = (val, secret) => `${val}.${createHmac("sha256", secret).update(val).digest("base64").replace(/=+$/, "")}`;
const unsign = (val, secret) => {
const str = val.slice(0, val.lastIndexOf("."));
const mac = sign(str, secret);
const macBuffer = Buffer.from(mac);
const valBuffer = Buffer.alloc(macBuffer.length);
valBuffer.write(val);
return timingSafeEqual(macBuffer, valBuffer) ? str : false;
};
export {
sign,
unsign
};
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["import { createHmac, timingSafeEqual } from 'node:crypto'\n\n/**\n * Sign the given `val` with `secret`.\n */\nexport const sign = (val: string, secret: string): string =>\n `${val}.${createHmac('sha256', secret).update(val).digest('base64').replace(/=+$/, '')}`\n\n/**\n * Unsign and decode the given `val` with `secret`,\n * returning `false` if the signature is invalid.\n */\nexport const unsign = (val: string, secret: string): string | false => {\n const str = val.slice(0, val.lastIndexOf('.'))\n const mac = sign(str, secret)\n const macBuffer = Buffer.from(mac)\n const valBuffer = Buffer.alloc(macBuffer.length)\n\n valBuffer.write(val)\n return timingSafeEqual(macBuffer, valBuffer) ? str : false\n}\n"],"names":[],"mappings":";AAKa,MAAA,OAAO,CAAC,KAAa,WAChC,GAAG,GAAG,IAAI,WAAW,UAAU,MAAM,EAAE,OAAO,GAAG,EAAE,OAAO,QAAQ,EAAE,QAAQ,OAAO,EAAE,CAAC;AAM3E,MAAA,SAAS,CAAC,KAAa,WAAmC;AACrE,QAAM,MAAM,IAAI,MAAM,GAAG,IAAI,YAAY,GAAG,CAAC;AACvC,QAAA,MAAM,KAAK,KAAK,MAAM;AACtB,QAAA,YAAY,OAAO,KAAK,GAAG;AACjC,QAAM,YAAY,OAAO,MAAM,UAAU,MAAM;AAE/C,YAAU,MAAM,GAAG;AACnB,SAAO,gBAAgB,WAAW,SAAS,IAAI,MAAM;AACvD;"}