Skip to content

datapartyjs/dataparty-crypto

Repository files navigation

@dataparty/crypto

stablelicense

dataparty cryptography

It slices, it dices, and it enciphers

Features

  • GPU Resistant
  • Post-Quantum Ready
  • Identity contains:
    • TweetNaCL Box & Sign Keys
    • Crystal-Kybers KEM Key
    • Dilithium Signing Key
    • SPHINCS+ Singing Key
  • Mnemonic derived keys seed phrases - See example
    • bip39 - Phrases are generated using bip39.
    • pharses are combined with a password using argon2 instead of the typical pbkdf2
  • Password derived keys

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!

Releases

No releases published

Packages

No packages published