Comparing version 0.3.1 to 0.4.0
41
index.js
@@ -10,3 +10,12 @@ var fs = require('fs') | ||
var createHmac = require('hmac') | ||
var deepEqual = require('deep-equal') | ||
function clone (obj) { | ||
var _obj = {} | ||
for(var k in obj) { | ||
if(Object.hasOwnProperty.call(obj, k)) | ||
_obj[k] = obj[k] | ||
} | ||
return _obj | ||
} | ||
@@ -175,1 +184,33 @@ function hash (data, enc) { | ||
exports.signObj = function (keys, obj) { | ||
var _obj = clone(obj) | ||
var str = JSON.stringify(_obj, null, 2) | ||
var h = hash(str, 'utf8') | ||
_obj.signature = sign(keys, h) | ||
return _obj | ||
} | ||
exports.verifyObj = function (keys, obj) { | ||
obj = clone(obj) | ||
var sig = obj.signature | ||
delete obj.signature | ||
var str = JSON.stringify(obj, null, 2) | ||
var h = hash(str, 'utf8') | ||
return exports.verify(keys, sig, h) | ||
} | ||
exports.signObjHmac = function (secret, obj) { | ||
obj = clone(obj) | ||
var str = JSON.stringify(obj, null, 2) | ||
obj.hmac = exports.hmac(str, secret) | ||
return obj | ||
} | ||
exports.verifyObjHmac = function (secret, obj) { | ||
obj = clone(obj) | ||
var hmac = obj.hmac | ||
delete obj.hmac | ||
var str = JSON.stringify(obj, null, 2) | ||
var _hmac = exports.hmac(str, secret) | ||
return deepEqual(hmac, _hmac) | ||
} |
{ | ||
"name": "ssb-keys", | ||
"description": "create or load a keypair file for secure-scuttlebutt", | ||
"version": "0.3.1", | ||
"version": "0.4.0", | ||
"homepage": "https://github.com/pfraze/ssb-keys", | ||
@@ -6,0 +6,0 @@ "repository": { |
@@ -49,5 +49,21 @@ # SSB-Keys | ||
var sig = ssbkeys.sign(k, hash) | ||
ssbkeys.verify(k.public, sig, hash) | ||
ssbkeys.verify(k.public, sig, hash) // => true | ||
ssbkeys.hmac(new Buffer('deadbeef', 'hex'), k.private) // => String | ||
var secret = new Buffer('deadbeef', 'hex') | ||
ssbkeys.hmac(secret, k.private) // => String | ||
var obj = ssbkeys.signObj(k, { foo: 'bar' }) | ||
console.log(obj) /* => { | ||
foo: 'bar', | ||
signature: ... | ||
} */ | ||
ssbkeys.verifyObj(k, obj) // => true | ||
var secret = new Buffer('deadbeef', 'hex') | ||
var obj = ssbkeys.signObjHmac(secret, { foo: 'bar' }) | ||
console.log(obj) /* => { | ||
foo: 'bar', | ||
hmac: ... | ||
} */ | ||
ssbkeys.verifyObjHmac(secret, obj) // => true | ||
``` |
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
8233
206
68