Commit 2650bb34 authored by Chuck LeDuc Díaz's avatar Chuck LeDuc Díaz
Browse files

Merge branch 'polish' into 'master'

Prep for npm publishing, add CI

See merge request !1
parents 2bc44bfb 627adf45
Pipeline #95600124 passed with stage
in 1 minute and 20 seconds
image: node:10.16
all_tests:
script:
- yarn
- yarn lint
- yarn coverage
{
"cSpell.words": [
"Keypair",
"Zencode",
"Zenroom",
"encrypter",
"keypairs"
]
}
\ No newline at end of file
......@@ -2,18 +2,22 @@
zenroom-lib is a javascript library to interact with the [Zenroom Virtual Machine](https://zenroom.org/)
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.
|Branch|Pipeline|Coverage|
|:-:|:-:|:-:|
|[`master`](https://gitlab.com/caelum-tech/Lorena/zenroom-lib/tree/master)|[![pipeline status](https://gitlab.com/caelum-tech/Lorena/zenroom-lib/badges/master/pipeline.svg)](https://gitlab.com/caelum-tech/Lorena/zenroom-lib/commits/master)|[![coverage report](https://gitlab.com/caelum-tech/Lorena/zenroom-lib/badges/master/coverage.svg)](https://gitlab.com/caelum-tech/Lorena/zenroom-lib/commits/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
```shell
> npm install
> npm install @caelum-tech/zenroom-lib
```
## Usage
Initialize
```javascript
const Zen = require('../src/index')
const Zen = require('@caelum-tech/zenroom-lib')
let z = new Zen()
```
......
{
"name": "zenroom-lib",
"name": "@caelum-tech/zenroom-lib",
"version": "1.0.0",
"description": "zenroom-lib is a javascript library to interact with the Zenroom Virtual Machine",
"main": "index.js",
"author": "Alex Puig",
"license": "MIT",
"scripts": {
"test": "./node_modules/.bin/mocha --reporter spec",
"lint": "eslint ./src"
"coverage": "nyc mocha test --timeout 20000 && nyc report --reporter=html",
"lint": "eslint ./src",
"npm:publish": "npm publish --access public",
"test": "./node_modules/.bin/mocha --reporter spec"
},
"repository": {
......@@ -28,12 +31,20 @@
},
"devDependencies": {
"chai": "^4.2.0",
"chai-as-promised": "^7.1.1",
"eslint": "^6.6.0",
"eslint-config-standard": "^14.1.0",
"eslint-plugin-import": "^2.18.2",
"eslint-plugin-node": "^10.0.0",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.1",
"mocha": "^6.2.2"
"husky": "^3.0.5",
"mocha": "^6.2.2",
"nyc": "^14.1.1"
},
"husky": {
"hooks": {
"pre-commit": "yarn lint"
}
}
}
......@@ -9,7 +9,7 @@ module.exports = class Zen {
* Executes Zencode.
* @param {object} keys Input keys.
* @param {string} script Zencode to be executed
* @return {promise} Return a primise with the execution of the script.
* @return {promise} Return a promise with the execution of the script.
*/
execute (keys, script) {
return new Promise((resolve, reject) => {
......@@ -31,7 +31,7 @@ module.exports = class Zen {
/**
* Creates a new keypair.
* @param {string} name Holder of the keypair.
* @return {promise} Return a primise with the execution of the creation.
* @return {promise} Return a promise with the execution of the creation.
*/
newKeyPair (name) {
const keygenContract = `rule check version 1.0.0
......@@ -45,7 +45,7 @@ module.exports = class Zen {
/**
* Creates a new keypair.
* @param {string} name Holder of the keypair.
* @return {promise} Return a primise with the execution of the creation.
* @return {promise} Return a promise with the execution of the creation.
*/
publicKey (name, keys) {
const publicKeyContract = `rule check version 1.0.0
......@@ -62,7 +62,7 @@ module.exports = class Zen {
* @param {object} fromKeys Keypair for the encrypter (Zencode format)
* @param {string} toName Who's receiving the message.
* @param {object} toKeys Public Key for the receiver (Zencode format)
* @return {promise} Return a primise with the execution of the encryption.
* @return {promise} Return a promise with the execution of the encryption.
*/
encryptMessage (fromName, fromKeys, toName, toKeys, message) {
const encryptScript = ` Rule check version 1.0.0
......@@ -83,7 +83,7 @@ module.exports = class Zen {
* @param {object} fromKeys Keypair for the encrypter (Zencode format)
* @param {string} toName Who's receiving the message.
* @param {object} toKeys Public Key for the receiver (Zencode format)
* @return {promise} Return a primise with the execution of the encryption.
* @return {promise} Return a promise with the execution of the encryption.
*/
decryptMessage (fromName, fromKeys, toName, toKeys, message) {
const decryptScript = `Rule check version 1.0.0
......@@ -102,7 +102,7 @@ module.exports = class Zen {
* Signs a message with a keypair.
* @param {string} signer Who's signing the message.
* @param {object} keys Keypair for the signer (Zencode format)
* @return {promise} Return a primise with the execution of the signature.
* @return {promise} Return a promise with the execution of the signature.
*/
signMessage (signer, keys, message) {
const signatureScript = `Rule check version 1.0.0
......
const Zen = require('../src/index')
var assert = require('chai').assert
const chai = require('chai')
.use(require('chai-as-promised'))
const assert = chai.assert
const expect = chai.expect
const message = 'Hello_World'
let aliceKeypair; let alicePublic; let signature = false
......@@ -16,7 +19,7 @@ describe('Zenroom', function () {
assert.isNotEmpty(aliceKeypair.Alice)
})
it('Sould get the Public Key', async () => {
it('Should get the Public Key', async () => {
alicePublic = await z.publicKey('Alice', aliceKeypair)
bobPublic = await z.publicKey('Bob', bobKeypair)
assert.equal(aliceKeypair.zenroom.curve, 'goldilocks')
......@@ -29,7 +32,6 @@ describe('Zenroom', function () {
describe('Encryption: ', () => {
it('Should encrypt a message: ', async () => {
msgEncrypted = await z.encryptMessage('Alice', aliceKeypair, 'Bob', bobPublic, message)
console.log(msgEncrypted)
assert.equal(msgEncrypted.zenroom.curve, 'goldilocks')
assert.equal(msgEncrypted.zenroom.scenario, 'simple')
assert.isNotEmpty(msgEncrypted.secret_message)
......@@ -61,4 +63,10 @@ describe('Zenroom', function () {
assert.equal(check.signature, 'correct')
})
})
describe('Execution: ', () => {
it('Should Fail with Invalid Zencode: ', async () => {
return expect(z.execute(false, 'Invalid Zencode')).to.be.rejected
})
})
})
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment