@dataparty/crypto
dataparty cryptography
It slices, it dices, and it enciphers
Features
- Based on TweetNaCL
- Password derived keys
- Mnemonic derived keys seed phrases - See example
- bip39 - Phrases are generated using bip39.
Identity
Creating a random key pair
const dataparty_crypto = require('@dataparty/crypto')
const alice = new dataparty_crypto.Identity({id:'alice'})
const bob = new dataparty_crypto.Identity({id:'bob'})
Messages
let encryptedMessage = new dataparty_crypto.Message({
msg: {
data: 'hello world'
}
})
Encryption
//! Bob encrypts the message
await encryptedMessage.encrypt(bob, alice.toMini())
sendToAlice( encryptedMessage.toJSON() )
Decryption
//! Later alice decrypt a message
const decryptedMessage = new dataparty_crypto.Message(msgFromBob)
await decryptedMessage.decrypt(alice)
console.log(`alice read: ${JSON.stringify(decryptedMessage.msg,null,2)}`)
//! Another way to verify that bob sent the message
await decryptedMessage.assertVerified(bob)
Signing
//! Alice signs a message
const signedMsg = await alice.sign({a:'hello world'})
sendToAlice( signedMsg.toJSON() )
Verifying
const signedMsg = new dataparty_crypto.Message(msfFromAlice)
//! Verify that Alice sent the message
const verified = await alice.verify(signedMsg)
console.log('verified?', verified)
//! Another way to verify that alice sent the message
await signedMsg.assertVerified(alice)
Password key derivation
const password = 'super-strong-password'
const salt = await dataparty_crypto.Routines.generateSalt() //! Salt would be read from disk after 1st run
const key = await dataparty_crypto.Routines.createKeyFromPasswordArgon2(
argon2,
"supersecretpassword123",
salt
)
Mnemonic derived keys seed phrases
const phrase = await dataparty_crypto.Routines.generateMnemonic()
let key = await dataparty_crypto.Routines.createKeyFromMnemonic(phrase)
Developing
npm build
npm watch
npm test
Support
Buy us a coffee!