Skip to content

Commit

Permalink
refactor(.): Consolidate and polyfill sodium APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
jwerle committed Aug 14, 2018
1 parent 6b5cb7c commit 4c3d059
Show file tree
Hide file tree
Showing 15 changed files with 82 additions and 7,458 deletions.
8 changes: 4 additions & 4 deletions auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ const isBuffer = require('is-buffer')

/* eslint-disable camelcase */
const {
crypto_auth_KEYBYTES,
crypto_auth_BYTES,
crypto_auth_KEYBYTES = 32,
crypto_auth_BYTES = 32,

crypto_auth_verify,
crypto_auth,
} = require('sodium-universal')
} = require('./sodium')

// export verify so we can access it like `crypto.auth.verify`
auth.verify = verify
Expand Down Expand Up @@ -72,7 +72,7 @@ function verify(mac, message, key) {
throw new TypeError(`verify: Invalid key length: ${key.length}`)
}

return crypto_auth_verify(mac, message, key)
return Boolean(crypto_auth_verify(mac, message, key))
}

module.exports = {
Expand Down
2 changes: 1 addition & 1 deletion blake2b.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable camelcase */
const { crypto_generichash_batch } = require('sodium-universal')
const { crypto_generichash_batch } = require('./sodium')
const isBuffer = require('is-buffer')
const alloc = require('buffer-alloc-unsafe')

Expand Down
2 changes: 1 addition & 1 deletion box.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const {
crypto_secretbox_MACBYTES,

crypto_secretbox_easy,
} = require('sodium-universal')
} = require('./sodium')

const kBoxHeaderSize = 2 + (2 * crypto_secretbox_MACBYTES)
const kBoxBufferSize = 4 * 1024
Expand Down
2 changes: 1 addition & 1 deletion curve25519.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const {
crypto_sign_seed_keypair,
crypto_sign_keypair,
crypto_scalarmult,
} = require('sodium-universal')
} = require('./sodium')

/**
* Generate a Curve25519 public and secret key pair from an optional
Expand Down
2 changes: 1 addition & 1 deletion discovery-key.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const kDefaultDiscoveryKeySize = 32
const {
crypto_generichash,
crypto_generichash_KEYBYTES_MIN,
} = require('sodium-universal')
} = require('./sodium')

const kDefaultDiscoveryKeyMessageKey = alloc(crypto_generichash_KEYBYTES_MIN)
kDefaultDiscoveryKeyMessageKey.fill('ara')
Expand Down
2 changes: 1 addition & 1 deletion ed25519.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const {
crypto_sign_seed_keypair,
crypto_sign_detached,
crypto_sign_keypair,
} = require('sodium-universal')
} = require('./sodium')

/**
* Generate a public and secret key pair from an optional
Expand Down
2 changes: 1 addition & 1 deletion kx.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const {
crypto_kx_client_session_keys,
crypto_kx_server_session_keys,
crypto_kx_seed_keypair,
} = require('sodium-universal')
} = require('./sodium')

/**
* Generates a key exchange key pair.
Expand Down
Loading

0 comments on commit 4c3d059

Please sign in to comment.