A Javascript Library for Zenroom
zenroom-lib is a javascript library to interact with the Zenroom Virtual Machine
Package | Branch | Pipeline | Coverage |
---|---|---|---|
master |
Zenroom is a tiny and portable virtual machine that integrates in any application to authenticate and restrict access to data and execute human-readable smart contracts.
Installation
npm install @caelum-tech/zenroom-lib
For React
This library uses Zenroom 1.0.0 which has a problem with create-react-app. To fix this issue we've added a script which patches the installed package:
./node_modules/@caelum-tech/zenroom-lib/bin/zenroom_modules.sh
Usage
Initialize
const Zen = let z =
Keypairs
Create keypairs
// Create a new keypair for Alice & Boblet alice_keypair = await zlet bob_keypair = await z
Being the result:
zenroom: curve: 'goldilocks' encoding: 'url64' version: '1.0.0+a7fab75' scenario: 'simple' Alice: keypair: public_key: 'u64:BH4GCburF7yL1KhITA676nxKIgEB2SQZ9BmeehuoWgPObMpb9ZTTigBgfhbrwLTxf0tWtRK6kM6D0DVItqdMWGRDsII75qXcLOunQTTiGcpAH3_iTlqjzXUDeDzcudyFhZByFohsi1wCqeAXPsKsjeQ' private_key: 'u64:IKwYf6BRXMQBveMizlkx0k1ru3qg3wApZBAfZ2sUL6nUGKG9tvU6hB9s4cmN-Gi2rXDjeIm-quk'
Retrieve only the public Key
// Create a new keypair for Alice & Boblet alice_public = await zlet bob_public = await z
Being the result:
zenroom: curve: 'goldilocks' encoding: 'url64' version: '1.0.0+a7fab75' scenario: 'simple' Alice: public_key: 'u64:BJeFhvqKzJERiHrZaMHlPR6ms59086qcwtafngq2nJvyDUatcdH7NSkVGvf5iKnWpsC546lTjhLIxWDf1-wfUdRy3dXa6Y6OzQvmMtqrRh33t5pXvuCDylRGiA4DqWKV6ocymggIvhdtMaXLOvNDoy4'
Signatures
Sign a message
// Create a new keypair for Alice & Bobconst signature = await z
Being the result:
zenroom: curve: 'goldilocks' encoding: 'url64' version: '1.0.0+a7fab75' scenario: 'simple' Alice: draft: 'u64:SGVsbG9fV29ybGQ' signature: s: 'u64:H71LonTCQOhhvuYCx9dMXNLDe0g-qngR28njL0tAgn8mdX2YYu2tAn9jyeaUJmBpk9iJijr7cvE' r: 'u64:Pv4lnBlJgPaFxEGXHntwIaUem__tjFpWQMOG9yelvb2VB5xvj2PXMTg-SsHExfL6BSPaHwFSbdo'
Check the signature
// Create a new keypair for Alice & Bobconst check = await z
Being the result:
zenroom: curve: 'goldilocks' encoding: 'url64' version: '1.0.0+a7fab75' scenario: 'simple' signature: 'correct'
Encryption
encrypts a message
// Create a new keypair for Alice & Bobconst msg_encrypted = await z
Being the result:
secret_message: iv: 'u64:Da57UyzCWz0gbxCeLpPPLA' header: 'u64:VGhpc19pc190aGVfaGVhZGVy' text: 'u64:4vazxwae5d4Pi9E' checksum: 'u64:pRGDjsiYg_9dQS1rWk-gVg' zenroom: curve: 'goldilocks' encoding: 'url64' version: '1.0.0+a7fab75' scenario: 'simple'
Decrypts a message
// Create a new keypair for Alice & Boblet msg = await z
Being the result:
message: 'Hello_World' zenroom: curve: 'goldilocks' encoding: 'url64' version: '1.0.0+a7fab75' scenario: 'simple' header: 'This_is_the_header'