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
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.
Returns the message
decrypted or null
if something went wrong.
Returns an object with an ed25519 publicKey
and privateKey
Returns a 32 bytes Blake2b
hashed buffer
data
can be a buffer, uintArray or string
Uses blake2b to derive a 32 bytes key
Returns a shared secret between a public and private keys. Uses diffieHellman
.
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 XChaCha20Poly1305
.
Authenticated (asymmetric) decryption between a public and private keys. If nonce
is not present, is extracted from the ciphertext. Uses XChaCha20Poly1305
.
Anonymous (symmetric) encryption usin a common sharedSecret
. AAD
for addional data. Uses XChaCha20Poly1305
.
Anonymous (symmetric) decryption usin a common sharedSecret
. Uses XChaCha20Poly1305
.
Returns the signature of data from the given keys. The salt
is optional, concats with data.
Verifies the signature from the given publicKey.
Faythe export this class to easy manage identity related features. WIP
See test folder for Identity management examples
MIT
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.