Unverified Commit 683b3828 authored by Puria Nafisi Azizi's avatar Puria Nafisi Azizi
Browse files

Declutter JS builds

* Update babel-cli and babel-core
* Remove duplicated `wrapper.js`
* Add missing `printErr` to EXTRA_EXPORTED_RUNTIME_METHODS
* Declutter all the javascript targets and unify them with a universal
build by adding them to ENVIROMENTS make flag
* remove `javascript-asmjs`, `javascript-npm`, `javascript-wasm-web` in
favour of using just `javascript-wasm`
parent a7fab756
......@@ -3,8 +3,8 @@
[
"@babel/preset-env",
{
useBuiltIns: "usage", // or "entry"
corejs: 3,
"useBuiltIns": "usage",
"corejs": 3,
"targets": {
"browsers": [
"last 2 versions"
......@@ -22,7 +22,7 @@
"test": {
"plugins": [
"istanbul"
],
]
}
}
}
......@@ -12,7 +12,6 @@
<h4 align="center">
Zenroomjs provides a javascript wrapper of <a href="https://zenroom.dyne.org">Zenroom</a>, a secure and small virtual machine for crypto language processing.
</h4>
<p align="center">
<a href="https://travis-ci.com/DECODEproject/zenroomjs">
<img src="https://travis-ci.com/DECODEproject/zenroomjs.svg?branch=master" alt="Build Status">
......
......@@ -8,11 +8,11 @@
"license": "AGPL-3.0",
"scripts": {
"lint": "npx standard",
"build": "cd ../.. && make clean && make javascript-npm",
"build": "cd ../.. && make javascript-wasm",
"clean": "rimraf dist/lib && cd ../.. && make clean",
"coverage": "nyc report --reporter=text-lcov > coverage.lcov && codecov",
"pretranspile": "yarn build && mkdirp dist/lib && cp -v ../../build/npm/z* dist/lib",
"transpile": "babel src -d dist",
"pretranspile": "mkdirp dist/lib && cp -v ../../build/wasm/z* dist/lib",
"transpile": "npx babel src -d dist",
"test": "node index.js && nyc --require @babel/register mocha",
"test:html": "nyc report --reporter=html yarn test",
"test:watch": "yarn test --watch",
......@@ -24,8 +24,8 @@
"dist"
],
"devDependencies": {
"@babel/cli": "^7.2.0",
"@babel/core": "^7.2.0",
"@babel/cli": "^7.6.4",
"@babel/core": "^7.6.4",
"@babel/preset-env": "^7.2.0",
"@babel/preset-react": "^7.0.0",
"@babel/register": "^7.0.0",
......@@ -46,6 +46,7 @@
"standard": "^12.0.1"
},
"dependencies": {
"@babel/node": "^7.6.3",
"core-js": "^3.1.4",
"regenerator-runtime": "*"
},
......
import 'core-js/stable'
import 'regenerator-runtime/runtime'
const C = require('../dist/lib/zenroom')
import Zenroom from '../dist/lib/zenroom.js'
const C = Zenroom()
/* istanbul ignore next */
const zenroomExec = (script, conf = null, keys = null, data = null, verbosity = 1) => {
......
import 'core-js/stable'
import 'regenerator-runtime/runtime'
const C = require('../dist/lib/zenroom')
/* istanbul ignore next */
const zenroomExec = (script, conf = null, keys = null, data = null, verbosity = 1) => {
C.then(Module => {
Module.ccall(
'zenroom_exec',
'number',
['string', 'string', 'string', 'string', 'number'],
[script, conf, keys, data, verbosity]
)
})
}
/* istanbul ignore next */
const zencodeExec = (script, conf = null, keys = null, data = null, verbosity = 1) => {
C.then(Module => {
Module.ccall(
'zencode_exec',
'number',
['string', 'string', 'string', 'string', 'number'],
[script, conf, keys, data, verbosity]
)
})
}
const zenroom = (function () {
let self = {}
self.options = {}
const __debug = function () {
return self
}
/**
* Set the zenroom script to run
*
* The syntax of the zenroom scripts are extensively available at
* https://zenroom.dyne.org/api/tutorials/Syntax.html
* You may want also to look at some example in a live executable environment here https://zenroom.dyne.org/demo/
*
* @example <caption>Example usage of `script()`</caption>
* // returns zenroom
* import zenroom from 'zenroom'
* // or without ES6 syntax
* // const zenroom = require('zenroom').default
*
* const script = 'print("hello")'
* zenroom.script(script).zenroom_exec().reset()
*
* @param {string} script the lua script to be set
* @returns {zenroom} the zenroom module
*/
const script = function (script) {
self.script = script
return this
}
/**
* Set the keys JSON for you zenroom execution
*
* the keys will be available in script as the `KEYS` variable
*
* @example <caption>Example usage of `keys()`</caption>
* // returns zenroom
* import zenroom from 'zenroom'
* // or without ES6 syntax
* // const zenroom = require('zenroom').default
*
* const script = `
* keys = JSON.decode(KEYS)
* print(keys)
* `
*
* const keys = {a: 1, b: 2}
* zenroom.script(script).keys(keys).zenroom_exec().reset()
*
* @param {object} keys the keys to be set as an object
* @returns {object} the zenroom module
*/
const keys = function (keys) {
self.keys = keys ? JSON.stringify(keys) : null
return this
}
/**
* Set the conf before your zenroom execution
*
* by now the only conf available is the string `umm` that sets the minimal memory manager (64KiB max)
*
* @example <caption>Example usage of `conf()`</caption>
* // returns zenroom
* import zenroom from 'zenroom'
* // or without ES6 syntax
* // const zenroom = require('zenroom').default
*
* const script = 'print("hello")'
* const conf = 'umm'
* zenroom.script(script).conf(conf).zenroom_exec()
*
* @param {string} conf the string of configuration to be set
* @returns {object} the zenroom module
*/
const conf = function (conf) {
self.conf = conf
return this
}
/**
* Set the data for your zenroom execution
*
* The data will be available in script as the `DATA` variable
*
* @example <caption>Example usage of `data()`</caption>
* // returns zenroom
* import zenroom from 'zenroom'
* // or without ES6 syntax
* // const zenroom = require('zenroom').default
*
* const script = `
* data = JSON.decode(DATA)
* print(data)
* `
*
* const data = {a: 1, b: 2}
* zenroom.script(script).data(data).zenroom_exec()
*
* @param {string} data
* @returns {object} the zenroom module
*/
const data = function (data) {
self.data = data
return this
}
/**
* Set the print callback to customize
* the behaviour of the print calls made to stdout
* by default it prints to the console.log
*
* @example <caption>Example usage of `print()`</caption>
* // returns zenroom
* import zenroom from 'zenroom'
* // or without ES6 syntax
* // const zenroom = require('zenroom').default
*
* const savedLines = []
* const printFunction = (text) => { savedLines.push(text) }
* const script = 'print("hello")'
* zenroom.print(printFunction).script(script).zenroom_exec()
*
* @callback print
* @returns {object} the zenroom module
*/
const print = function (printFunction) {
self.print = printFunction
C.then(Module => {
Module.print = text => self.print(text)
})
return this
}
/**
* Set the success callback that is executed after a successful execution of zenroom
*
* @example <caption>Example usage of `success()`</caption>
* // returns zenroom
* import zenroom from 'zenroom'
* // or without ES6 syntax
* // const zenroom = require('zenroom').default
*
* const script = 'print("hello")'
* zenroom.script(script).success(()=>{
* pleaseRunSomeOtherMethodAfter()
* }).zenroom_exec()
*
* @callback success
* @returns {object} the zenroom module
*/
const success = function (successCallback) {
self.success = successCallback
C.then(Module => {
Module.exec_ok = successCallback
})
return this
}
/**
* Set the error callback that is executed after an unsuccessful execution of zenroom
*
* @example <caption>Example usage of `error()`</caption>
* // returns zenroom
* import zenroom from 'zenroom'
* // or without ES6 syntax
* // const zenroom = require('zenroom').default
*
* const script = 'print("hello")';
* zenroom.script(script).error(()=>{
* pleaseRunSomeOtherMethodAfterError()
* }).zenroom_exec()
*
* @callback error
* @returns {object} the zenroom module
*/
const error = function (errorCallback) {
self.error = errorCallback
C.then(Module => {
Module.exec_error = errorCallback
})
return this
}
/**
* Set the verbosity of the stderr messages outputted by the zenroom virtual machine
*
* As per now the set of accepted value:
*
* <ul>
* <li>1 = INFO</li>
* <li>2 = DEBUG</li>
* </ul>
*
* @example <caption>Example usage of `verbosity()`</caption>
* // returns zenroom
* import zenroom from 'zenroom'
* // or without ES6 syntax
* // const zenroom = require('zenroom').default
*
* const script = 'print("hello")'
* zenroom.script(script).verbosity(2).zenroom_exec()
*
* @param {number} verbosity
* @returns {object} the zenroom module
*/
const verbosity = function (verbosity) {
self.verbosity = verbosity
return this
}
/**
* Execute the zenroom vm (using the previously setted options)
*
* It is usually the last method of the chain, but like the other methods returns
* the zenroom module itself, so can be used for other calls if you need to make more
* executions in a row
*
* @example <caption>Example usage of `zenroom_exec()`</caption>
* // returns zenroom
* import zenroom from 'zenroom'
* // or without ES6 syntax
* // const zenroom = require('zenroom').default
*
* const script = 'print("hello")';
* zenroom.script(script).zenroom_exec()
*
* @returns {object} the zenroom module
*/
const zenroom_exec = function () {
zenroomExec(self.script, self.conf, self.keys, self.data, self.verbosity)
return this
}
/**
* Execute zencode contracts (using the previously setted options)
*
* It is usually the last method of the chain, but like the other methods returns
* the zenroom module itself, so can be used for other calls if you need to make more
* executions in a row
*
* @example <caption>Example usage of `zencode_exec()`</caption>
* // returns zenroom
* import zenroom from 'zenroom'
* // or without ES6 syntax
* // const zenroom = require('zenroom').default
*
* const zencode = 'print("hello")';
* zenroom.script(script).zencode_exec()
*
* @returns {object} the zenroom module
*/
const zencode_exec = function () {
zencodeExec(self.script, self.conf, self.keys, self.data, self.verbosity)
return this
}
/**
* This method allows the configuration of your call by passing one
* configuration option object. You can use the chain methods after this anyway.
*
* If some attribute is already set, those will be overwritten by the new options
*
* The following options are available:
* <ul>
* <li><strong>script</strong></li>
* <li><strong>keys</strong></li>
* <li><strong>conf</strong></li>
* <li><strong>data</strong></li>
* <li><strong>print</strong></li>
* <li><strong>success</strong></li>
* <li><strong>error</strong></li>
* <li><strong>verbosity</strong></li>
* </ul>
*
* @example <caption>Example usage of `init()`</caption>
* // returns zenroom
* import zenroom from 'zenroom'
* // or without ES6 syntax
* // const zenroom = require('zenroom').default
*
* const encrypt_secret_to_many = {
* script: `keyring = ECDH.new()
* secret = str(DATA)
* keys = JSON.decode(KEYS)
* keyring:private( base64(keys.keyring.secret) )
* res = {}
* for name,pubkey in pairs(keys.recipients) do
* pub = base64(pubkey)
* enc = ECDH.encrypt(keyring,pub,secret,keyring:public())
* res[name] = str( MSG.pack( map(enc,base64) ) ):base64()
* end
* print(JSON.encode(res))`,
*
* keys: {
* keyring : {
* public : "BHMjcDM/aljpi8pNxFQ436R6F3J+kaB/Xk1kAVFPmkoLVyeFltDZPgiIYRquh+m2IfvPioBfet7YCd5vVXYoRTk=",
* secret : "ChW5qi5y//ISDIHKx5Fvxl+XY8IyDGVBHUfELp3PqJQ="
* },
* recipients : {
* paulus : "BBUw6Nr3A30cN65maERvAk1cEv2Ji6Vs80kSlpodOC0SCtM8ucaS7e+s158uVMSr3BsvIXVspBeafiL8Qb3kcgc=",
* mayo : "BHqBoQ2WJ3/FGVNTXzdIc+K/HzNx05bWzEhn8m58FvSsaqWVdH52jI6fQWdkdjnbqVKCJGmbjA/OCJ+IKHbiySI=",
* mark : "BFgkjrRMvN+wkJ6qA4UvMaNlYBvl37C9cNYGkqOE4w43AUzkEzcyIIdE6BrgOEUEVefhOOnO6SCBQMgXHXJUUPY=",
* francesca : "BCo102mVybieKMyhex8tnVtFM5+Wo1oP02k8JVwKF9OLIjw7w0LmofItbuAcfWl9rcoe++XLI3sySZnqljIfeyU=",
* jim : "BEs1jeqL0nVwFi7OmG4YdtlWuKADyOvZR4XHpLAEswg8ONPXQHvwJ8+PkHkphoORfSjk2045bMdYkwboU4FdG2Y=",
* jaromil : "BBZYJtHvFg0vGCxPROAWrThcGZ+vFZJj86k+uncjvbm4DysIg7cWS3J6GrcJKCY55Uf40m2KfBwfaT+T7TTO1e8="
* }
* },
*
* data: 'This is a secret message.'
* }
*
*
* zenroom.init(encrypt_secret_to_many).zenroom_exec()
*
* @returns {object} the zenroom module
*/
const init = function (options) {
/* istanbul ignore next */
self.options = Object.assign(self.options, options) || {}
script(self.options.script || '')
keys(self.options.keys || null)
conf(self.options.conf || null)
data(self.options.data || null)
print(self.options.print || (text => console.log(text)))
success(self.options.success || new Function()) // eslint-disable-line no-new-func
error(self.options.error || new Function()) // eslint-disable-line no-new-func
verbosity(self.options.verbosity || 1)
return this
}
const __setup = function () {
print(self.print || (text => console.log(text)))
success(self.success || (() => {}))
error(self.error || (() => {}))
}
/**
* Reset the setted options already provided and cleans up the zenroom module
*
* It is usually the last method of the chain, but like the other methods returns
* the zenroom module itself, so can be used for other calls if you need to make more
* executions in a row
*
* @example <caption>Example usage of `reset()`</caption>
* // returns zenroom
* import zenroom from 'zenroom'
* // or without ES6 syntax
* // const zenroom = require('zenroom').default
*
* const script = 'print("hello")';
* zenroom.script(script)
* .zenroom_exec() // This runs the script
* .reset()
* .zenroom_exec() // This does not run the script anymore
*
* @returns {object} the zenroom module
*/
const reset = function () {
self = {}
self.options = {}
__setup()
return this
}
__setup()
return {
script,
keys,
conf,
data,
print,
success,
verbosity,
zenroom_exec,
zencode_exec,
error,
init,
reset,
__debug
}
})()
export default zenroom
......@@ -2,22 +2,22 @@
# yarn lockfile v1
"@babel/cli@^7.2.0":
version "7.5.0"
resolved "https://registry.yarnpkg.com/@babel/cli/-/cli-7.5.0.tgz#f403c930692e28ecfa3bf02a9e7562b474f38271"
integrity sha512-qNH55fWbKrEsCwID+Qc/3JDPnsSGpIIiMDbppnR8Z6PxLAqMQCFNqBctkIkBrMH49Nx+qqVTrHRWUR+ho2k+qQ==
"@babel/cli@^7.6.4":
version "7.6.4"
resolved "https://registry.yarnpkg.com/@babel/cli/-/cli-7.6.4.tgz#9b35a4e15fa7d8f487418aaa8229c8b0bc815f20"
integrity sha512-tqrDyvPryBM6xjIyKKUwr3s8CzmmYidwgdswd7Uc/Cv0ogZcuS1TYQTLx/eWKP3UbJ6JxZAiYlBZabXm/rtRsQ==
dependencies:
commander "^2.8.1"
convert-source-map "^1.1.0"
fs-readdir-recursive "^1.1.0"
glob "^7.0.0"
lodash "^4.17.11"
lodash "^4.17.13"
mkdirp "^0.5.1"
output-file-sync "^2.0.0"
slash "^2.0.0"
source-map "^0.5.0"
optionalDependencies:
chokidar "^2.0.4"
chokidar "^2.1.8"
"@babel/code-frame@^7.0.0":
version "7.0.0"
......@@ -26,22 +26,29 @@
dependencies:
"@babel/highlight" "^7.0.0"
"@babel/core@^7.2.0":
version "7.5.4"
resolved "https://registry.yarnpkg.com/@babel/core/-/core-7.5.4.tgz#4c32df7ad5a58e9ea27ad025c11276324e0b4ddd"
integrity sha512-+DaeBEpYq6b2+ZmHx3tHspC+ZRflrvLqwfv8E3hNr5LVQoyBnL8RPKSBCg+rK2W2My9PWlujBiqd0ZPsR9Q6zQ==
"@babel/code-frame@^7.5.5":
version "7.5.5"
resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.5.5.tgz#bc0782f6d69f7b7d49531219699b988f669a8f9d"
integrity sha512-27d4lZoomVyo51VegxI20xZPuSHusqbQag/ztrBC7wegWoQ1nLREPVSKSW8byhTlzTKyNE4ifaTA6lCp7JjpFw==
dependencies:
"@babel/code-frame" "^7.0.0"
"@babel/generator" "^7.5.0"
"@babel/helpers" "^7.5.4"
"@babel/parser" "^7.5.0"
"@babel/template" "^7.4.4"
"@babel/traverse" "^7.5.0"
"@babel/types" "^7.5.0"
"@babel/highlight" "^7.0.0"
"@babel/core@^7.6.4":
version "7.6.4"
resolved "https://registry.yarnpkg.com/@babel/core/-/core-7.6.4.tgz#6ebd9fe00925f6c3e177bb726a188b5f578088ff"
integrity sha512-Rm0HGw101GY8FTzpWSyRbki/jzq+/PkNQJ+nSulrdY6gFGOsNseCqD6KHRYe2E+EdzuBdr2pxCp6s4Uk6eJ+XQ==
dependencies:
"@babel/code-frame" "^7.5.5"
"@babel/generator" "^7.6.4"
"@babel/helpers" "^7.6.2"
"@babel/parser" "^7.6.4"
"@babel/template" "^7.6.0"
"@babel/traverse" "^7.6.3"
"@babel/types" "^7.6.3"
convert-source-map "^1.1.0"
debug "^4.1.0"
json5 "^2.1.0"
lodash "^4.17.11"
lodash "^4.17.13"
resolve "^1.3.2"
semver "^5.4.1"
source-map "^0.5.0"
......@@ -68,6 +75,16 @@
source-map "^0.5.0"
trim-right "^1.0.1"
"@babel/generator@^7.6.3", "@babel/generator@^7.6.4":
version "7.6.4"
resolved "https://registry.yarnpkg.com/@babel/generator/-/generator-7.6.4.tgz#a4f8437287bf9671b07f483b76e3bb731bc97671"
integrity sha512-jsBuXkFoZxk0yWLyGI9llT9oiQ2FeTASmRFE32U+aaDTfoE92t78eroO7PTpU/OrYq38hlcDM6vbfLDaOLy+7w==
dependencies:
"@babel/types" "^7.6.3"
jsesc "^2.5.1"
lodash "^4.17.13"
source-map "^0.5.0"
"@babel/helper-annotate-as-pure@^7.0.0":
version "7.0.0"
resolved "https://registry.yarnpkg.com/@babel/helper-annotate-as-pure/-/helper-annotate-as-pure-7.0.0.tgz#323d39dd0b50e10c7c06ca7d7638e6864d8c5c32"
......@@ -231,14 +248,14 @@
"@babel/traverse" "^7.1.0"
"@babel/types" "^7.2.0"
"@babel/helpers@^7.5.4":
version "7.5.4"
resolved "https://registry.yarnpkg.com/@babel/helpers/-/helpers-7.5.4.tgz#2f00608aa10d460bde0ccf665d6dcf8477357cf0"
integrity sha512-6LJ6xwUEJP51w0sIgKyfvFMJvIb9mWAfohJp0+m6eHJigkFdcH8duZ1sfhn0ltJRzwUIT/yqqhdSfRpCpL7oow==
"@babel/helpers@^7.6.2":
version "7.6.2"
resolved "https://registry.yarnpkg.com/@babel/helpers/-/helpers-7.6.2.tgz#681ffe489ea4dcc55f23ce469e58e59c1c045153"
integrity sha512-3/bAUL8zZxYs1cdX2ilEE0WobqbCmKWr/889lf2SS0PpDcpEIY8pb1CCyz0pEcX3pEb+MCbks1jIokz2xLtGTA==
dependencies:
"@babel/template" "^7.4.4"
"@babel/traverse" "^7.5.0"
"@babel/types" "^7.5.0"
"@babel/template" "^7.6.0"
"@babel/traverse" "^7.6.2"
"@babel/types" "^7.6.0"
"@babel/highlight@^7.0.0":
version "7.5.0"
......@@ -249,6 +266,19 @@
esutils "^2.0.2"
js-tokens "^4.0.0"
"@babel/node@^7.6.3":
version "7.6.3"
resolved "https://registry.yarnpkg.com/@babel/node/-/node-7.6.3.tgz#f175ab6718dde55431cbd4d9dee95f65c38be527"
integrity sha512-+nHje5AcE9TPlB/TRGYyOSQyTfhfU/WXniG6SkVf+V5+ibAjEqkH79lYdiEcytBTH4KeSf25IriySXs6TjaLjg==
dependencies:
"@babel/register" "^7.6.2"
commander "^2.8.1"
core-js "^3.2.1"
lodash "^4.17.13"
node-environment-flags "^1.0.5"
regenerator-runtime "^0.13.3"
v8flags "^3.1.1"
"@babel/parser@^7.4.3":
version "7.4.5"
resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.4.5.tgz#04af8d5d5a2b044a2a1bffacc1e5e6673544e872"
......@@ -259,6 +289,11 @@
resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.5.0.tgz#3e0713dff89ad6ae37faec3b29dcfc5c979770b7"
integrity sha512-I5nW8AhGpOXGCCNYGc+p7ExQIBxRFnS2fd/d862bNOKvmoEPjYPcfIjsfdy0ujagYOIYPczKgD9l3FsgTkAzKA==
"@babel/parser@^7.6.0", "@babel/parser@^7.6.3", "@babel/parser@^7.6.4":
version "7.6.4"
resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.6.4.tgz#cb9b36a7482110282d5cb6dd424ec9262b473d81"
integrity sha512-D8RHPW5qd0Vbyo3qb+YjO5nvUVRTXFLQ/FsDxJU2Nqz4uB5EnUN0ZQSEYpvTIbRuttig1XbHWU5oMeQwQSAA+A==
"@babel/plugin-proposal-async-generator-functions@^7.2.0":
version "7.2.0"
resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-async-generator-functions/-/plugin-proposal-async-generator-functions-7.2.0.tgz#b289b306669dce4ad20b0252889a15768c9d417e"
......@@ -708,6 +743,17 @@
pirates "^4.0.0"