@lorena-ssi/lorena-crypto

0.0.2 • Public • Published

A Javascript Library for Zenroom

zenroom-lib is a javascript library to interact with the Zenroom Virtual Machine

npm version Build Status Coverage Status

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 @lorena-ssi/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/@lorena-ssi/zenroom-lib/bin/zenroom_modules.sh

Usage

Initialize

const Zen = require('@lorena-ssi/zenroom-lib')
let z = new Zen()

Keypairs

Create keypairs

// Create a new keypair for Alice & Bob
let alice_keypair = await z.newKeyPair('Alice')
let bob_keypair = await z.newKeyPair('Bob')

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 & Bob
let alice_public = await z.publicKey('Alice', alice_keypair)
let bob_public = await z.publicKey('Bob', bob_keypair)

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 & Bob
const signature = await z.signMessage('Alice', alice_keypair, message)

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 & Bob
const check = await z.checkSignature('Alice', alice_public, signature, 'Bob')

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 & Bob
const msg_encrypted = await z.encryptMessage('Alice', alice_keypair, 'Bob', bob_public, 'HelloWorld')

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 & Bob
let msg = await z.decryptMessage('Alice', alice_public, 'Bob', bob_keypair, msg_encrypted)

Being the result:

{
  message: 'Hello_World',
  zenroom: {
    curve: 'goldilocks',
    encoding: 'url64',
    version: '1.0.0+a7fab75',
    scenario: 'simple'
  },
  header: 'This_is_the_header'
}

Package Sidebar

Install

npm i @lorena-ssi/lorena-crypto

Weekly Downloads

0

Version

0.0.2

License

MIT

Unpacked Size

10.3 kB

Total Files

4

Last publish

Collaborators

  • alexpuig
  • javisantos