An easy crypto library to send messages using key encapsulation. A courier for Alice, Bob and friends.
Mainly to learn crypto, and i wanted to have library that works in the browser and node with a simple api. Another requirement was that it had to be versioned and with fixed constants.
npm install faythe --save
const faythe = require('faythe').v1 const Alice = new faythe.Identity() const Bob = new faythe.Identity() const packed = faythe.packMessage('Hello world', [Bob], Alice) const unpacked = faythe.unpackMessage(packed, Bob).toString() console.log(unpacked) // Hello world
faythe.packMessage(message, recipientPublicKeys, [senderKeys], [nonRepubiable])
Returns an object, with the encrypted message and the keys to decrypt for each recipient. If no
senderKeys, the message is packed anonymously. Follows some Aries RFC 0019 specs, but can't be considered an implementation.
recipientPublicKeys an array of publicKeys
senderKeys an object with publicKey and privateKey
nonRepubiable false by default. Boolean to sign or not the message.
message decrypted or
null if something went wrong.
Returns an object with an ed25519
Returns a 32 bytes
Blake2b hashed buffer
data can be a buffer, uintArray or string
faythe.derive (key, [[namespace], [name]])
Uses blake2b to derive a 32 bytes key
faythe.precomputeSharedKey (myPrivateKey, theirPublicKey, [initiator])
Returns a shared secret between a public and private keys. Uses
faythe.authEncrypt (theirPublicKey, myPrivateKey, data, [nonce])
Authenticated (asymmetric) encryption between a public and private keys. The
nonce is randomly generated if not present, then, concatenated to de begining of the ciphertext. Uses
faythe.authDecrypt (theirPublicKey, myPrivateKey, data, [nonce])
Authenticated (asymmetric) decryption between a public and private keys. If
nonce is not present, is extracted from the ciphertext. Uses
faythe.secretEncrypt (secretKey, data, [[nonce], [AAD]])
Anonymous (symmetric) encryption usin a common
AAD for addional data. Uses
faythe.secretDecrypt (secretKey, data, [[nonce], [AAD]])
Anonymous (symmetric) decryption usin a common
faythe.sign (myKeys, data, [salt])
Returns the signature of data from the given keys. The
salt is optional, concats with data.
faythe.verify (publicKey, data, signature, [salt])
Verifies the signature from the given publicKey.
new faythe.Identity([[idspace], [name], [passphrase], [rotation], [mnemonic], [seed]])
Faythe export this class to easy manage identity related features. WIP
See test folder for Identity management examples
Copyright (c) 2020 Javi Santos
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.