Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Utilize zokrates-js/node build variant #286

Merged

Conversation

dumivo
Copy link
Contributor

@dumivo dumivo commented Dec 18, 2020

Co-authored-by: myronrotter myronrotter01@t-online.de

Description

Usage of the privacy package @baseline-protocol/privacy for Node.js applications fails due to the fact that zokrates-js uses the bundler variant leveraging ES2016 features by default.

Related Issue

#224

Motivation and Context

One acceptance criteria of #224 consists of refactoring the existing the codebase to import and use @baseline-protocol/privacy.
However, importing mentioned package fails with the error

import wrapper from './wrapper.js';
       ^^^^^^^

SyntaxError: Unexpected identifier
    at Module._compile (internal/modules/cjs/loader.js:723:23)
    at Module._compile (/home/minh/baseline/examples/radish34/zkp/node_modules/pirates/lib/index.js:99:24)
    at Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Object.newLoader [as .js] (/home/minh/baseline/examples/radish34/zkp/node_modules/pirates/lib/index.js:104:7)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at Object.<anonymous> (/home/minh/baseline/examples/radish34/zkp/node_modules/@baseline-protocol/privacy/src/zkp/zokrates.ts:1:1)

When refactoring the privacy package to use zokrates-js/node instead of zokrates-js, this error gets resolved. This variant uses require instead of import in the entrypoint, making zokrates-js/node a valid CommonJS package. See https://zokrates.github.io/toolbox/zokrates_js.html#importing for more information.

Result

Node.js applications should now be able to use @baseline-protocol/privacy out-of-the-box without adding a transpilation step like Typescript or Babel, including the radish34 demo project.

How Has This Been Tested

The following steps were made:

  • passing all tests using npm test in the privacy package
  • running npm run build successfully
  • importing the privacy package locally in a Node.js project is successful

Screenshots (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Co-authored-by: myronrotter <myronrotter01@t-online.de>
@CLAassistant
Copy link

CLAassistant commented Dec 18, 2020

CLA assistant check
All committers have signed the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants