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

Feat/migrate to esm #35

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@ npm add cryptolens
To verify a license key, you can use the code below. The RSAPublicKey, token and the product id can be found on [this page](https://help.cryptolens.io/examples/key-verification).

```js
const key = require('cryptolens').Key;
const Helpers = require('cryptolens').Helpers;
import { Key, Helpers } from 'cryptolens';

var RSAPubKey = "Your RSA Public key, which can be found here: https://app.cryptolens.io/User/Security";
var result = key.Activate(token="Access token with with Activate permission", RSAPubKey, ProductId=3349, Key="GEBNC-WZZJD-VJIHG-GCMVD", MachineCode=Helpers.GetMachineCode());
const RSAPubKey = "Your RSA Public key, which can be found here: https://app.cryptolens.io/User/Security";
const token="Access token with with Activate permission", ProductId=3349, licenseKey="GEBNC-WZZJD-VJIHG-GCMVD";
const MachineCode=Helpers.GetMachineCode();

result.then(function(license) {

const result = Key.Activate(token, RSAPubKey, ProductId, licenseKey, MachineCode);

result.then((license) => {
// success

// Please see https://app.cryptolens.io/docs/api/v3/model/LicenseKey for a complete list of parameters.
console.log(license.Created);

}).catch(function(error) {
}).catch((error) => {
// in case of an error, an Error object is returned.
console.log(error.message);
});
Expand All @@ -39,22 +39,22 @@ Assuming the license key verification was successful, we can save the result in
First, we need to add the reference to the helper methods:

```js
const Helpers = require('cryptolens').Helpers;
import { Helpers } from 'cryptolens';
```

We can now proceed and save it as a string.

```js
var licenseString = Helpers.SaveAsString(license);
const licenseString = Helpers.SaveAsString(license);
```

When loading it back, we can use the code below:
```js
var license = Helpers.LoadFromString(RSAPubKey, licenseString);
const license = Helpers.LoadFromString(RSAPubKey, licenseString);
```

If you want to make sure that the license file is not too old, you can specify the maximum number of days as shown below (after 30 days, this method will return null).
```js
var license = Helpers.LoadFromString(RSAPubKey, licenseString, 30);
const license = Helpers.LoadFromString(RSAPubKey, licenseString, 30);
```

7 changes: 4 additions & 3 deletions internal/HelperMethods.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
const got = require("got");
module.exports = class HelperMethods {
import got from 'got';
import NodeRSA from 'node-rsa';

export default class HelperMethods {

/**
* Verify that a response obtained from Key.Activate has not been tampered with.
* @param {object} response
* @param {string} rsaPubKey
*/
static VerifySignature(response, rsaPubKey) {
const NodeRSA = require('node-rsa');
const key = new NodeRSA();
const pubKey = HelperMethods.GetPublicKeyParams(rsaPubKey);
key.importKey({ n: pubKey.modulus, e: pubKey.exponent }, 'components-public');
Expand Down
14 changes: 7 additions & 7 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const key = require('./methods/Key.js');
const data = require('./methods/Data');
const helpers = require('./methods/Helpers.js');
import Key from './methods/Key.js';
import Data from './methods/Data.js';
import Helpers from './methods/Helpers.js';

module.exports = {
Key : key,
Helpers : helpers,
Data: data
export {
Key,
Helpers,
Data
}
5 changes: 2 additions & 3 deletions methods/Data.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const got = require('got');
const helpers = require('../internal/HelperMethods.js');
import helpers from '../internal/HelperMethods.js';

module.exports = class Key {
export default class Key {

static AddDataObjectToKey(token, ProductId, Key, CheckForDuplicates = false, Name = null, StringValue = null, IntValue= 0, LicenseServerUrl = "https://api.cryptolens.io") {

Expand Down
9 changes: 4 additions & 5 deletions methods/Helpers.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
const helpers = require('../internal/HelperMethods.js');
const { execSync } = require("child_process");
const crypto = require('crypto');
import helpers from '../internal/HelperMethods.js';
import { execSync } from 'child_process';
import crypto from 'crypto';


module.exports = class Helpers {
export default class Helpers {

/**
* Save the license as a string that can later be read by LoadFromString.
Expand Down
6 changes: 3 additions & 3 deletions methods/Key.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const got = require('got');
const helpers = require('../internal/HelperMethods.js');
import got from 'got';
import helpers from '../internal/HelperMethods.js';

module.exports = class Key {
export default class Key {

static Activate(token, rsaPubKey, ProductId, Key, MachineCode = "", FriendlyName = "", FieldsToReturn = 0, Metadata = false, FloatingTimeInterval = 0, MaxOverdraft = 0, LicenseServerUrl = "https://api.cryptolens.io") {
return new Promise(async (resolve, reject) => {
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"name": "cryptolens",
"version": "1.0.15.1",
"description": "Client API for NodeJS to access Cryptolens Software Licensing API.",
"main": "main.js",
"exports": "./main.js",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
Expand Down
13 changes: 7 additions & 6 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var key = require("./methods/Key.js")
const Helpers = require('./methods/Helpers.js');
import key from './methods/Key.js';

import Helpers from './methods/Helpers.js';

//var RSAPubKey = "<RSAKeyValue><Modulus>sGbvxwdlDbqFXOMlVUnAF5ew0t0WpPW7rFpI5jHQOFkht/326dvh7t74RYeMpjy357NljouhpTLA3a6idnn4j6c3jmPWBkjZndGsPL4Bqm+fwE48nKpGPjkj4q/yzT4tHXBTyvaBjA8bVoCTnu+LiC4XEaLZRThGzIn5KQXKCigg6tQRy0GXE13XYFVz/x1mjFbT9/7dS8p85n8BuwlY5JvuBIQkKhuCNFfrUxBWyu87CFnXWjIupCD2VO/GbxaCvzrRjLZjAngLCMtZbYBALksqGPgTUN7ZM24XbPWyLtKPaXF2i4XRR9u6eTj5BfnLbKAU5PIVfjIS+vNYYogteQ==</Modulus><Exponent>AQAB</Exponent></RSAKeyValue>";

Expand All @@ -9,15 +10,15 @@ const Helpers = require('./methods/Helpers.js');
//var result2 = Key.GetKey(token="", RSAPubKey, ProductId=3349, Key="GEBNC-WZZJD-VJIHG-GCMVD");
//result2.then((s)=> console.log(Helpers.LoadFromString(RSAPubKey, Helpers.SaveAsString(s))));

var result = key.CreateKey(token ="", ProductId=15189, MachineCode="test")
let token ="", ProductId=15189, MachineCode="test";

const result = key.CreateKey(token ="", ProductId=15189, MachineCode="test")
result.then((s) => console.log(s));


//console.log(Helpers.GetMachineCode());

var test = {};

test = {"ActivatedMachines" :[{"Mid":"floating:" + Helpers.GetMachineCode()}]};
const test = {"ActivatedMachines" :[{"Mid":"floating:" + Helpers.GetMachineCode()}]};

console.log(Helpers.IsOnRightMachine(test,true));

Expand Down