Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

deed

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

deed - npm Package Compare versions

Comparing version 0.0.3 to 0.0.4

42

index.js
// deed - verify x-hub-signature
module.exports = verify
module.exports = deed
var string_decoder = require('string_decoder')
, crypto = require('crypto')
, util = require('util')
, stream = require('stream')
;
function write (buf) {
return new string_decoder.StringDecoder('hex').write(buf)
util.inherits(Verify, stream.Transform)
function Verify (sig) {
stream.Transform.call(this)
this.buf = 'sha1='
this.sig = sig
this.dec = new string_decoder.StringDecoder('hex')
this._readableState.objectMode = true
}
function match (hmac, sig) {
var chunk
, str = 'sha1='
;
while (null !== (chunk = hmac.read())) {
str += write(chunk)
}
return str === sig
Verify.prototype._transform = function (chunk, enc, cb) {
this.buf += this.dec.write(chunk)
cb()
}
function verify (secret, req, cb) {
Verify.prototype._flush = function () {
this.push(this.buf === this.sig ? true : false)
}
function deed (secret, req, cb) {
var xub = 'X-Hub-Signature'
, sig = req.headers[xub] || req.headers[xub.toLowerCase()]
, sig = req.headers[xub] || req.headers[xub.toLowerCase()]
;
if (!sig) return cb(new Error('no ' + xub))
var hmac = crypto.createHmac('sha1', secret)
hmac.once('finish', function () {
var verified = match(hmac, sig)
verified ? cb(null, req) : cb(new Error('unverified ' + xub))
, verify = new Verify(sig)
;
verify.once('readable', function () {
verify.read() ? cb(null, req) : cb(new Error('unverified ' + xub))
})
verify.once('error', cb)
hmac.once('error', cb)
req.once('error', cb)
req.pipe(hmac)
req.pipe(hmac).pipe(verify)
return req
}
{
"name": "deed",
"version": "0.0.3",
"version": "0.0.4",
"description": "verify x-hub-signature",

@@ -5,0 +5,0 @@ "main": "index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc