1.0.1 • Published 7 years ago
libsodium-tweetnacl-wrappers v1.0.1
crypto_hash function
nacl.lowlevel.crypto_hashconst nacl = require("./dist/modules-sumo/libsodium-tweetnacl-wrappers") x = Uint8Array.from("uE8PKeSYFIorw8ojOk4Cg7et0s4WSxf5WpjOORascdLW2wQuYvGoLDR7zM9USNh5") nacl.lowlevel.crypto_hash(x)- should return 0 and change the value of x to the new encrypted value
box.before function
- Returns a precomputed shared key which can be used in
nacl.box.afterandnacl.box.open.afterconst nacl = require("./dist/modules-sumo/libsodium-tweetnacl-wrappers") x = Uint8Array.from("T6Mjk3c65EI2C09F6jlr1fibgaqgC1eT") y = Uint8Array.from("T6Mjk3c65EI2C09F6jlr1fibgaqgC1eT") nacl.box.before(x, y) - should return a new array with 32U length
box.keyPair
- Generates a new random key pair for box and returns it as an object with
publicKeyandsecretKeymembersconst nacl = require("./dist/modules-sumo/libsodium-tweetnacl-wrappers") nacl.box.keyPair() - should return a new array with
publicKeyandsecretKeyeach with 32U length
box.keyPair.fromSecretKey
- Returns a key pair for box with public key corresponding to the given secret key.
const nacl = require("./dist/modules-sumo/libsodium-tweetnacl-wrappers") secret = (nacl.box.keyPair()).secretKey nacl.box.keyPair.fromSecretKey(secret) - should return a new array with
publicKeyandsecretKeyeach with 32U length
sign.keyPair
- Generates new random key pair for signing and returns it as an object with
publicKeyandsecretKeymembersconst nacl = require("./dist/modules-sumo/libsodium-tweetnacl-wrappers") nacl.sign.keyPair() - should return a new array with
publicKey32U length andsecretKey64U length
sign.detached function
nacl.sign.detachedconst nacl = require("./dist/modules-sumo/libsodium-tweetnacl-wrappers") message = Uint8Array.from("T6Mjk3c65EI2C09F6jlr1fibgaqgC1eT") key = Uint8Array.from("T6Mjk3c65EI2C09F6jlr1fibgaqgC1eTT6Mjk3c65EI2C09F6jlr1fibgaqgC1eT") nacl.sign.detached(message, key)- should return the new encrypted value with 32U length (in tweetnacl the length is 64 but in this case it's ok as at verification is also in sodium)
sign.detached.verify function
nacl.sign.detached.verifyconst nacl = require("./dist/modules-sumo/libsodium-tweetnacl-wrappers") message = Uint8Array.from("T6Mjk3c65EI2C09F6jlr1fibgaqgC1eT") key = Uint8Array.from("T6Mjk3c65EI2C09F6jlr1fibgaqgC1eTT6Mjk3c65EI2C09F6jlr1fibgaqgC1eT") token = nacl.sign.detached(message, key) nacl.sign.detached.verify(message, token, key)- should return true, as the message is verified with the right token
sign.keyPair.fromSeed function
nacl.sign.keyPair.fromSeedconst nacl = require("./dist/modules-sumo/libsodium-tweetnacl-wrappers") seed = Uint8Array.from("T6Mjk3c65EI2C09F6jlr1fibgaqgC1eT") nacl.sign.keyPair.fromSeed(seed)- should return a new array with
publicKey32U length andsecretKey64U length
notes
- testing will not working unless
npm ipasses (best to test in a unix, mac os is problematic) see node-sodium installation for instructions - all returned values should be of type
Uint8Array - all sodium functions receive a buffer,
the workaround is to convert the buffers to
Uint8Arraypass it to sodium and change the original arrays by reference copy