@tinyhttp/cookie-signature
Advanced tools
Comparing version 0.1.3 to 0.1.4
# @tinyhttp/cookie-signature | ||
## 0.1.4 | ||
### Patch Changes | ||
- Upgrade dependencies of all of the packages | ||
## 0.1.3 | ||
@@ -4,0 +10,0 @@ |
@@ -1,1 +0,19 @@ | ||
import{createHmac as e,timingSafeEqual as r}from"crypto";const sign=(r,t)=>`${r}.${e("sha256",t).update(r).digest("base64").replace(/=+$/,"")}`,unsign=(e,t)=>{const o=e.slice(0,e.lastIndexOf(".")),f=sign(o,t),s=Buffer.from(f),a=Buffer.alloc(s.length);return a.write(e),!!r(s,a)&&o};export{sign,unsign}; | ||
import { createHmac, timingSafeEqual } from 'crypto'; | ||
/** | ||
* Sign the given `val` with `secret`. | ||
*/ | ||
const sign = (val, secret) => { | ||
return `${val}.${createHmac('sha256', secret).update(val).digest('base64').replace(/=+$/, '')}`; | ||
}; | ||
/** | ||
* Unsign and decode the given `val` with `secret`, | ||
* returning `false` if the signature is invalid. | ||
*/ | ||
const unsign = (val, secret) => { | ||
const str = val.slice(0, val.lastIndexOf('.')), mac = sign(str, secret), macBuffer = Buffer.from(mac), valBuffer = Buffer.alloc(macBuffer.length); | ||
valBuffer.write(val); | ||
return timingSafeEqual(macBuffer, valBuffer) ? str : false; | ||
}; | ||
export { sign, unsign }; |
{ | ||
"name": "@tinyhttp/cookie-signature", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"description": "HTTP cookie signing and unsigning", | ||
@@ -38,5 +38,5 @@ "homepage": "https://github.com/talentlessguy/tinyhttp#readme", | ||
"devDependencies": { | ||
"rollup": "^2.21.0", | ||
"rollup": "^2.22.0", | ||
"rollup-plugin-typescript2": "^0.27.1", | ||
"typescript": "^3.9.6" | ||
"typescript": "^3.9.7" | ||
}, | ||
@@ -43,0 +43,0 @@ "scripts": { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
5499
68
1