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

Node.js support #16

Closed
CryptoMathician opened this issue Sep 9, 2020 · 6 comments
Closed

Node.js support #16

CryptoMathician opened this issue Sep 9, 2020 · 6 comments

Comments

@CryptoMathician
Copy link
Contributor

Hello,
I wanted to use the Javascript part of the library for my project in React and did some exports of the function to bundle them into a Node.js package, including index.js and package.json, to import them into my React project as a Node.js package. Is there any chance that this could be useful in this repository or is there any planing for a Node.js package for this library which will be maintained?
I saw a version of the old library in npm, but this isn't maintained anymore.

In the time were I added the exports, I found some minor bugs.

Minor Bugs:
In the file fp2.js in row 137: should be ctx.FP.BIG_ENDIAN_SIGN instead of FP.BIG_ENDIAN_SIGN.
In the file fp.js in row 32: should be x instanceof ctx.BIG instead of x instanceof BIG.

I don't know why Javascript don't say anything about it, but Node.js told me that the ctx part is necessary.

Thank you in advance!

@mcarrickscott
Copy link
Contributor

Thanks for finding those bugs!

What you suggest would be useful, but while we would certainly welcome a node.js package, we could not commit to maintaining it.

Mike

@CryptoMathician
Copy link
Contributor Author

CryptoMathician commented Sep 9, 2020

You are welcome and thank you for your fast response!

It seems to me that there isn't much to do to support Node.js. I am not sure how it will be for npm platform (I didn't it before), but for this repository to support Node.js there is not much to do (as I know in this moment of writing this). I did the following:

  • added export of the classes (prototypes) to every file e.g. for fp.js
if (typeof module !== "undefined" && typeof module.exports !== "undefined") {
    module.exports = {
        FP: FP
    };
}
  • added a index.js with the following code
    module.exports.CTX = require('./amcl-js/ctx');

  • added package.json(for simplicity with the following stub)

  "name": "<name>",
  "version": "3.X.X",
  "description": "<description>",
  "main": "<path>/index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "<Author Name>",
  "license": "<some licence>"
}

Afterm them I used in my React project `npm install ' and was able to use the node package with your Javascript code with

const CTX = require("pesto-client").CTX;
let ctxBls12461 = new CTX('BLS12461');

As of my understanding and testing it should be possible with these changes that the code is usable in Javascript as before and it is possible in another Javascript files as functions from a library in plain Javascript. Additionally a person is able to build a npm package locally and can use it in Node.js or React projects (I don't know much about AngularJS, but maybe also there - I didn't tested it yet).

@mcarrickscott
Copy link
Contributor

If you put together a Pull Request, and if it doesn't break anything, we will approve it. Unfortunately we don't have a JS expert on the team at the moment, so I cannot be of much help.

Mike

@CryptoMathician
Copy link
Contributor Author

Ok. Let me do some tests and if everything works fine I can do a Pull Request and you or some of the contributors can double check it, such that there exist no side effects, which maybe I am not aware of. Thank you! I will let you know, when I am done with the tests.

Pascal

@mcarrickscott
Copy link
Contributor

OK that's fine

@CryptoMathician
Copy link
Contributor Author

Pull Request + Merge done.

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

No branches or pull requests

2 participants