diff --git a/README.md b/README.md index 2387a25..dac6aee 100644 --- a/README.md +++ b/README.md @@ -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); }); @@ -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); ``` diff --git a/internal/HelperMethods.js b/internal/HelperMethods.js index 83b9cf0..9dbc33c 100644 --- a/internal/HelperMethods.js +++ b/internal/HelperMethods.js @@ -1,5 +1,7 @@ -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. @@ -7,7 +9,6 @@ module.exports = class HelperMethods { * @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'); diff --git a/main.js b/main.js index ea63f65..c734b1f 100644 --- a/main.js +++ b/main.js @@ -1,11 +1,9 @@ -const key = require('./methods/Key.js'); -const data = require('./methods/Data'); -const helpers = require('./methods/Helpers.js'); -const product = require('./methods/Product.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, - Product: product +export { + Key, + Helpers, + Data } diff --git a/methods/Data.js b/methods/Data.js index 68cc14f..54d3443 100644 --- a/methods/Data.js +++ b/methods/Data.js @@ -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") { diff --git a/methods/Helpers.js b/methods/Helpers.js index 1ca4916..b760c63 100644 --- a/methods/Helpers.js +++ b/methods/Helpers.js @@ -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. diff --git a/methods/Key.js b/methods/Key.js index 1080e0a..1f08ec3 100644 --- a/methods/Key.js +++ b/methods/Key.js @@ -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) => { diff --git a/package-lock.json b/package-lock.json index 41fb5ec..8a82e4c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "cryptolens", - "version": "1.0.11", + "version": "1.0.15.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "cryptolens", - "version": "1.0.9", + "version": "1.0.15.1", "license": "MIT", "dependencies": { "got": "11.8.5", diff --git a/package.json b/package.json index b23d921..af1628d 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,8 @@ "name": "cryptolens", "version": "1.0.16", "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" }, diff --git a/test.js b/test.js index 56a0b7f..5878b76 100644 --- a/test.js +++ b/test.js @@ -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 = "sGbvxwdlDbqFXOMlVUnAF5ew0t0WpPW7rFpI5jHQOFkht/326dvh7t74RYeMpjy357NljouhpTLA3a6idnn4j6c3jmPWBkjZndGsPL4Bqm+fwE48nKpGPjkj4q/yzT4tHXBTyvaBjA8bVoCTnu+LiC4XEaLZRThGzIn5KQXKCigg6tQRy0GXE13XYFVz/x1mjFbT9/7dS8p85n8BuwlY5JvuBIQkKhuCNFfrUxBWyu87CFnXWjIupCD2VO/GbxaCvzrRjLZjAngLCMtZbYBALksqGPgTUN7ZM24XbPWyLtKPaXF2i4XRR9u6eTj5BfnLbKAU5PIVfjIS+vNYYogteQ==AQAB"; @@ -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));