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

ssb-keys

Package Overview
Dependencies
Maintainers
1
Versions
76
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ssb-keys - npm Package Compare versions

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)
}

2

package.json
{
"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
```
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