mol_crypto2_lib
v0.0.9
Published
Simple and fast API for effective cross platform cryptography with minimal extra size. Uses SHA-1 and Curve25519.
Maintainers
Keywords
Readme
$mol_crypto2
Simple and fast API for effective cross platform cryptography with minimal extra size. Uses SHA-1 and Curve25519.
Hashing
Fast sync implementation of SHA-1 (20B, 160b).
const data = new Uint8Array([ 1, 2, 3 ]) // 3 B
const hash = $mol_crypto2_hash( data ) // 20 BSigning & Verifying
Native async implementation of Ed25519.
Auditor= 32B public key for sign verification.Signer= Auditor + 32B private key for signing.Sign= 64B signature of data.
const Alice = await $mol_crypto2_signer.generate() // 64 B
const Bella = await $mol_crypto2_signer.generate() // 64 B
const data = new Uint8Array([ 1, 2, 3 ]) // 3 B
const digest = $mol_crypto2_hash( data ) // 20 B
const sign = await Alice.sign( digest ) // 64 B
const auditor = Alice.auditor() // 32 B
const verified = await auditor.verify( digest, sign ) // trueEncryption & Decryption
Native async implementation of x25519.
Socket= 32B public key for encryption/decryption.Cipher= Socket + 32B private key for encryption/decryption.Nonce= 16B unique bytes. May be predictable.
const Alice = await $mol_crypto2_cipher.generate() // 64 B
const Bella = await $mol_crypto2_cipher.generate() // 64 B
const secret = Bella.secret( Alice.socket() ) // 16 B
// const secret = Alice.secret( Bella.socket() ) // same
const data = new Uint8Array([ 1, 2, 3 ]) // 3 B
const nonce = $mol_crypto2_nonce() // 16 B
const closed = await secret.encrypt( data, nonce ) // 16 B
const opened = await secret.decrypt( closed, nonce ) // 3 BSigning & Verifying & Encryption & Decryption
Composition of Ed25519 and x25519.
const Alice = await $mol_crypto2_private.generate() // 128 B
const Bella = await $mol_crypto2_private.generate() // 128 B
const secret = await Alice.cipher().secret( Bella.socket() ) // 16 B
// const secret = await Bella.cipher().secret( Alice.socket() ) // same
const data = new Uint8Array([ 1, 2, 3 ]) // 3 B
const nonce = $mol_crypto2_nonce() // 16 B
const closed = await secretA.encrypt( data, nonce ) // 16 B
const digest = $mol_crypto2_hash( closed ) // 20 B
const sign = await Alice.signer().sign( digest ) // 64 B
const auditor = Alice.auditor() // 32 B
const verified = await auditor.verify( digest, sign ) ) // true
const opened = await secretA.decrypt( closed, nonce ) ) // 3 BUsage from NPM
http://npmjs.com/package/mol_crypto2_lib
npm install mol_crypto2_libexport { $mol_crypto2_private, default as $ } from "mol_crypto2_lib"