cobox-crypto
Advanced tools
Comparing version 1.2.3 to 1.2.4
17
index.js
@@ -43,11 +43,16 @@ const sodium = require('sodium-native') | ||
keyPair (masterKey, id, ctxt = 'coboxcobox') { | ||
_deriveSeed (masterKey, id, ctxt = 'coboxcobox') { | ||
const context = sodium.sodium_malloc(sodium.crypto_hash_sha256_BYTES) | ||
sodium.crypto_hash_sha256(context, Buffer.from(ctxt)) | ||
const seed = sodium.sodium_malloc(sodium.crypto_kdf_KEYBYTES) | ||
sodium.crypto_kdf_derive_from_key(seed, id, context, masterKey) | ||
zero(context) | ||
return crypto.keyPair(seed) | ||
return seed | ||
} | ||
keyPair (masterKey, id, ctxt = 'coboxcobox') { | ||
return crypto.keyPair(this._deriveSeed(masterKey, id, ctxt)) | ||
} | ||
keySet () { | ||
@@ -116,3 +121,7 @@ return { | ||
boxKeypair (seed) { | ||
boxKeypair (masterKey, id, ctxt = 'coboxcobox') { | ||
return this._boxKeypair(this._deriveSeed(masterKey, id, ctxt)) | ||
} | ||
_boxKeypair (seed) { | ||
const publicKey = sodium.sodium_malloc(sodium.crypto_box_PUBLICKEYBYTES) | ||
@@ -135,3 +144,3 @@ const secretKey = sodium.sodium_malloc(sodium.crypto_box_SECRETKEYBYTES) | ||
var boxed = Buffer.alloc(messageBuffer.length + sodium.crypto_secretbox_MACBYTES) | ||
const ephKeypair = this.boxKeypair() | ||
const ephKeypair = this._boxKeypair() | ||
const nonce = this.randomBytes(sodium.crypto_secretbox_NONCEBYTES) | ||
@@ -138,0 +147,0 @@ var sharedSecret = this.genericHash( |
{ | ||
"name": "cobox-crypto", | ||
"version": "1.2.3", | ||
"version": "1.2.4", | ||
"description": "crypto encoding library for use in cobox", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -213,7 +213,8 @@ const { describe } = require('tape-plus') | ||
context('boxkeypair', (assert, next) => { | ||
const { publicKey, secretKey } = crypto.boxKeypair() | ||
const masterKey = crypto.masterKey() | ||
const { publicKey, secretKey } = crypto.boxKeypair(masterKey, 4) | ||
assert.ok(Buffer.isBuffer(publicKey), 'public key generated') | ||
assert.ok(Buffer.isBuffer(secretKey), 'secret key generated') | ||
const seed = crypto.randomBytes(sodium.crypto_box_SEEDBYTES) | ||
const seedKeypair = crypto.boxKeypair(seed) | ||
const seedKeypair = crypto._boxKeypair(seed) | ||
assert.ok(Buffer.isBuffer(seedKeypair.publicKey), 'public key generated from seed') | ||
@@ -225,3 +226,4 @@ assert.ok(Buffer.isBuffer(seedKeypair.secretKey), 'secret key generated from seed') | ||
context('box and unbox', (assert, next) => { | ||
const { publicKey, secretKey } = crypto.boxKeypair() | ||
const masterKey = crypto.masterKey() | ||
const { publicKey, secretKey } = crypto.boxKeypair(masterKey, 4) | ||
const msg = 'beep boop' | ||
@@ -228,0 +230,0 @@ const boxedMsg = crypto.box(publicKey, Buffer.from(msg)) |
Sorry, the diff of this file is not supported yet
132905
401