sodium-up v0.4.0
sodium-up
Convenience wrapper around
sodium-universal
Usage
var sodium = require('sodium-up')
var random = sodium.randombytes_buf(Buffer.allocUnsafe(16))API
WIP
See sodium-native for complete documentation.
sodium.randombytes_*
var output = sodium.randombytes_buf(output)
output can either be a Buffer or integer length. Will return output
sodium.crypto_sign_*
Constants:
sodium.crypto_sign_SEEDBYTESsodium.crypto_sign_PUBLICKEYBYTESsodium.crypto_sign_SECRETKEYBYTESsodium.crypto_sign_BYTES
var {publicKey, secretKey} = crypto_sign_seed_keypair([publicKey, secretKey], seed)
publicKey and secretKey are optional, but can be Buffer or integer length.
Defaults to Buffer of sodium.crypto_sign_PUBLICKEYBYTES and sodium.crypto_sign_SECRETKEYBYTES length.
Will return and object with {publicKey, secretKey}
var {publicKey, secretKey} = crypto_sign_keypair([publicKey, secretKey])
publicKey and secretKey are optional, but can be Buffer or integer length.
Defaults to Buffer of sodium.crypto_sign_PUBLICKEYBYTES and sodium.crypto_sign_SECRETKEYBYTES length.
Will return and object with {publicKey, secretKey}
var signedMessage = crypto_sign([signedMessage], message, secretKey)
signedMessage is optional, but can be Buffer or integer length. Defaults to Buffer of sodium.crypto_sign_BYTES length.
Will return signedMessage
var boolOrBuf = crypto_sign_open([message], signedMessage, publicKey)
message is optional, but can be Buffer or integer length. Defaults to Buffer of signedMessage.length - sodium.crypto_sign_BYTES length.
Will return false if the signature is invalid or message otherwise
var signature = crypto_sign_detached([signature], message, secretKey)
signature is optional, but can be Buffer or integer length. Defaults to Buffer of sodium.crypto_sign_BYTES length.
Will return signature
var bool = crypto_sign_verify_detached(signature, message, publicKey)
Alias to sodium-native#crypto_sign_verify_detached
sodium.crypto_generichash_*
Constants:
sodium.crypto_generichash_PRIMITIVEsodium.crypto_generichash_BYTES_MINsodium.crypto_generichash_BYTES_MAXsodium.crypto_generichash_BYTESsodium.crypto_generichash_KEYBYTES_MINsodium.crypto_generichash_KEYBYTES_MAXsodium.crypto_generichash_KEYBYTES
var output = crypto_generichash([output], input, [key])
output is optional, but can be Buffer or integer length. Defaults to Buffer of sodium.crypto_generichash_BYTES length. Will return output
Examples of input permutations:
sodium.crypto_generichash(input)
sodium.crypto_generichash(input, key)
sodium.crypto_generichash(output, input, null)
sodium.crypto_generichash(null, input, key)
sodium.crypto_generichash(null, input, null)var instance = crypto_generichash_instance([key], [outputLength])
sodium-native#crypto_generichash_instance wrapped in an object so .update() and .final() can be overridden.
var instance = instance.update(input)
Will return instance for easy chaining
var output = instance.final([output])
output is optional, but can be Buffer of outputLength or longer. Defaults to Buffer of outputLength length. Will return output
sodium.crypto_pwhash_*
Constants:
sodium.crypto_pwhash_ALG_DEFAULTsodium.crypto_pwhash_BYTES_MINsodium.crypto_pwhash_BYTES_MAXsodium.crypto_pwhash_PASSWD_MINsodium.crypto_pwhash_PASSWD_MAXsodium.crypto_pwhash_SALTBYTESsodium.crypto_pwhash_STRBYTESsodium.crypto_pwhash_STRPREFIXsodium.crypto_pwhash_OPSLIMIT_MINsodium.crypto_pwhash_OPSLIMIT_MAXsodium.crypto_pwhash_MEMLIMIT_MINsodium.crypto_pwhash_MEMLIMIT_MAXsodium.crypto_pwhash_OPSLIMIT_INTERACTIVEsodium.crypto_pwhash_MEMLIMIT_INTERACTIVEsodium.crypto_pwhash_OPSLIMIT_MODERATEsodium.crypto_pwhash_MEMLIMIT_MODERATEsodium.crypto_pwhash_OPSLIMIT_SENSITIVEsodium.crypto_pwhash_MEMLIMIT_SENSITIVEsodium.crypto_pwhash_PRIMITIVE
var output = sodium.crypto_pwhash([output], password, salt, opslimit, memlimit, algorithm)
output can either be a Buffer or integer length. Will return output
var output = sodium.crypto_pwhash_str([output], password, opslimit, memlimit)
output is optional, but can be Buffer or integer length. Defaults to Buffer of sodium.crypto_pwhash_STRBYTES length. Will return output
var bool = sodium.crypto_pwhash_str_verify(str, password)
Alias to sodium-native#crypto_pwhash_str_verify
Install
npm install sodium-up