From 08e39f40f72e6cd5f64892f9fa6cad01276294a5 Mon Sep 17 00:00:00 2001 From: Tom Mount Date: Tue, 28 May 2024 13:15:31 -0400 Subject: [PATCH 1/7] prepare for npm distribution as v2.0 --- example.js | 23 +++++++++++ index.js | 29 +++++--------- lib/ECToken.js | 73 ++++++++++++++++++++++++++++++++++ ECToken.js => lib/crypto.js | 78 ++++++------------------------------- package.json | 26 ++++++++++++- 5 files changed, 141 insertions(+), 88 deletions(-) create mode 100644 example.js create mode 100644 lib/ECToken.js rename ECToken.js => lib/crypto.js (67%) diff --git a/example.js b/example.js new file mode 100644 index 0000000..18db681 --- /dev/null +++ b/example.js @@ -0,0 +1,23 @@ +const { ECToken, encrypt, decrypt } = require('./index.js'); +// Alternatively: +// const { V3 } = require('./index.js') + +(async () => { + // Create the token. + const ec_token = new ECToken() + ec_token.addValue('ec_country_allow', 'US') + ec_token.addValue('ec_country_allow', 'CA') + ec_token.addValue('ec_expire', (Date.now() / 1000) + (60 * 60 * 24)) + + // Encrypt and encode it. + const ec_token_str = await encrypt('my-secret-key', ec_token) + console.log(`Encoded: ${ec_token_str}`) + + console.log(' ') + + // Now decrypt it back to plaintext. + const plaintext = await decrypt('my-secret-key', ec_token_str) + console.log(`Plaintext: ${plaintext}`) + + process.exit() +})(); diff --git a/index.js b/index.js index eae5bbc..d62fc5a 100644 --- a/index.js +++ b/index.js @@ -1,21 +1,10 @@ -const { ECToken, encrypt, decrypt } = require('./ECToken.js'); +'use strict'; +const { V3, encrypt, decrypt } = require('./lib/crypto') +const { ECToken } = require('./lib/ECToken') -(async () => { - // Create the token. - const ec_token = new ECToken() - ec_token.addValue('ec_country_allow', 'US') - ec_token.addValue('ec_country_allow', 'CA') - ec_token.addValue('ec_expire', (Date.now() / 1000) + (60 * 60 * 24)) - - // Encrypt and encode it. - const ec_token_str = await encrypt('my-secret-key', ec_token) - console.log(`Encoded: ${ec_token_str}`) - - console.log(' ') - - // Now decrypt it back to plaintext. - const plaintext = await decrypt('my-secret-key', ec_token_str) - console.log(`Plaintext: ${plaintext}`) - - process.exit() -})() +module.exports = { + V3, + ECToken, + encrypt, + decrypt +} \ No newline at end of file diff --git a/lib/ECToken.js b/lib/ECToken.js new file mode 100644 index 0000000..a9a2dd4 --- /dev/null +++ b/lib/ECToken.js @@ -0,0 +1,73 @@ +/** + * A class to manage Edgecast Token creation. + */ +class ECToken { + constructor() { + // Set default values for all valid token fields. + this.values = { + ec_expire: 0, + ec_country_allow: [], + ec_country_deny: [], + ec_url_allow: [], + ec_host_allow: [], + ec_host_deny: [], + ec_ref_allow: [], + ec_ref_deny: [], + ec_clientip: [], + ec_proto_allow: [], + ec_proto_deny: [] + } + } + + /** + * Set or append a value to the token. + * @param {String} key The key to set or append. + * @param {String} value The value to add. + * @returns None + */ + addValue(key, value) { + if (!(key in this.values)) { + throw new Error(`Invalid key: ${key}`) + } + + if (key === 'ec_expire') { + this.values.ec_expire = parseInt(value) + return + } + + // All other keys can be multivalue. + if (!this.values[key].includes(value)) { + this.values[key].push(value) + } + } + + /** + * @deprecated since v2.0.0; use toString() instead. + */ + serialize() { + return this.toString() + } + + /** + * Serialize the token object as a valid EdgeCast Token. + * @returns {String} + */ + toString() { + let token = Object.keys(this.values).reduce((acc, curr) => { + if (curr === 'ec_expire' && this.values.ec_expire && this.values.ec_expire > 0) { + acc.push(`ec_expire=${this.values.ec_expire}`) + } else { + if (this.values[curr].length) { + acc.push(`${curr}=${this.values[curr].join(',')}`) + } + } + return acc + }, []).join('&') + return token + } +} + +// Export the ECToken helper class. +module.exports = { + ECToken +} diff --git a/ECToken.js b/lib/crypto.js similarity index 67% rename from ECToken.js rename to lib/crypto.js index 072ea2a..ce534de 100644 --- a/ECToken.js +++ b/lib/crypto.js @@ -4,76 +4,14 @@ const base64url = require('base64url') const iv_size_bytes = 12 /** - * An EdgeCast Token - */ -class ECToken { - constructor() { - // Set default values for all valid token fields. - this.values = { - ec_expire: 0, - ec_country_allow: [], - ec_country_deny: [], - ec_url_allow: [], - ec_host_allow: [], - ec_host_deny: [], - ec_ref_allow: [], - ec_ref_deny: [], - ec_clientip: [], - ec_proto_allow: [], - ec_proto_deny: [] - } - } - - /** - * Set or append a value to the token. - * @param {String} key The key to set or append. - * @param {String} value The value to add. - * @returns None - */ - addValue(key, value) { - if (!(key in this.values)) { - throw new Error(`Invalid key: ${key}`) - } - - if (key === 'ec_expire') { - this.values.ec_expire = parseInt(value) - return - } - - // All other keys can be multivalue. - if (!this.values[key].includes(value)) { - this.values[key].push(value) - } - } - - /** - * Serialize the token object as a valid EdgeCast Token. - * @returns {String} The serialized output containing all the options the user set. - */ - serialize() { - let token = Object.keys(this.values).reduce((acc, curr) => { - if (curr === 'ec_expire' && this.values.ec_expire && this.values.ec_expire > 0) { - acc.push(`ec_expire=${this.values.ec_expire}`) - } else { - if (this.values[curr].length) { - acc.push(`${curr}=${this.values[curr].join(',')}`) - } - } - return acc - }, []).join('&') - return token - } -} - -/** - * Encrypt an ECToken with a key. + * Encrypt an ECToken string with a key. * @param {String} key The secret key to encode the token. - * @param {ECToken} token The token to encrypt. + * @param {ECToken|string} token The token to encrypt. * @param {Boolean} verbose Whether to print verbose output. * @returns {Promise} The encrypted token. */ async function encrypt(key, token, verbose = false) { - const token_str = new TextEncoder().encode(token.serialize()) + const token_str = new TextEncoder().encode(token.toString()) const key_encoded = new TextEncoder().encode(key) const key_digest = await crypto.subtle.digest('SHA-256', key_encoded) @@ -160,8 +98,14 @@ async function decrypt(key, token, verbose = false) { return new TextDecoder().decode(decrypted_str) } +// For backwards compatibility with Verizon ectoken, namespace the encrypt/decrypt +// functions, but also export them individually for backwards compatibility with +// this library. module.exports = { - ECToken, + V3: { + encrypt, + decrypt + }, encrypt, decrypt -} +} \ No newline at end of file diff --git a/package.json b/package.json index c2c6808..d42881e 100644 --- a/package.json +++ b/package.json @@ -1,10 +1,34 @@ { "name": "js-ectoken", - "version": "1.0.0", + "version": "2.0.0", "description": "JS implementation of Edgio token (ectoken)", "main": "index.js", + "directories": { + "lib": "lib" + }, + "scripts": { + }, + "repository": { + "type": "git", + "url": "git+https://github.com/Edgio/js-ectoken.git" + }, + "keywords": [ + "ectoken", + "token", + "auth", + "edgecast", + "edgio", + "vdms" + ], "author": "Tom Mount ", "license": "Apache-2.0", + "bugs": { + "url": "https://github.com/Edgio/js-ectoken/issues" + }, + "engines": { + "node": ">= 15.0.0" + }, + "homepage": "https://github.com/Edgio/js-ectoken#readme", "dependencies": { "base64url": "^3.0.1" } From 7e35303f61957114cab1cbe67c524f7af285c40d Mon Sep 17 00:00:00 2001 From: Tom Mount Date: Tue, 28 May 2024 14:18:09 -0400 Subject: [PATCH 2/7] add tests --- index.js | 2 +- package.json | 6 + test/test.js | 84 ++++++++ yarn.lock | 549 ++++++++++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 639 insertions(+), 2 deletions(-) create mode 100644 test/test.js diff --git a/index.js b/index.js index d62fc5a..49e7ab9 100644 --- a/index.js +++ b/index.js @@ -7,4 +7,4 @@ module.exports = { ECToken, encrypt, decrypt -} \ No newline at end of file +} diff --git a/package.json b/package.json index d42881e..8deef85 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ "lib": "lib" }, "scripts": { + "test": "mocha" }, "repository": { "type": "git", @@ -31,5 +32,10 @@ "homepage": "https://github.com/Edgio/js-ectoken#readme", "dependencies": { "base64url": "^3.0.1" + }, + "devDependencies": { + "chai": "^4", + "chai-as-promised": "^7.1.2", + "mocha": "^10.4.0" } } diff --git a/test/test.js b/test/test.js new file mode 100644 index 0000000..0422d34 --- /dev/null +++ b/test/test.js @@ -0,0 +1,84 @@ +'use strict'; + +const chai = require('chai') +const expect = chai.expect +const chaiAsPromised = require('chai-as-promised') +chai.use(chaiAsPromised) +const { ECToken, encrypt, decrypt } = require('../index.js') + +describe('ECToken Helper Class', function() { + it('should add a single value correctly', function() { + const token = new ECToken + token.addValue('ec_country_allow', 'CA') + expect(token.values.ec_country_allow).to.deep.equal(['CA']) + }) + + it('should add multiple values correctly', function() { + const token = new ECToken + token.addValue('ec_country_allow', 'US') + token.addValue('ec_country_allow', 'CA') + expect(token.values.ec_country_allow).to.deep.equal(['US', 'CA']) + }) + + it('should deduplicate multi-value entries', function() { + const token = new ECToken + token.addValue('ec_country_allow', 'US') + token.addValue('ec_country_allow', 'US') + expect(token.values.ec_country_allow).to.deep.equal(['US']) + }) + + it('should serialize to a string properly', function() { + const token = new ECToken + token.addValue('ec_country_allow', 'US') + token.addValue('ec_country_allow', 'CA') + token.addValue('ec_country_deny', 'MX') + const serialized = token.toString() + expect(serialized).to.equal('ec_country_allow=US,CA&ec_country_deny=MX') + }) + + it('should not allow arbitrary parameters', function() { + expect(function() { + const token = new ECToken + token.addValue('arbitrary', 'value') + }).to.throw() + }) +}) + +describe('Encryption and Decryption', function() { + const key = 'my-secret-key' // openssl rand -hex 8 + + // Specify a hard-coded string. + const params = 'ec_expire=12345678&ec_clientip=1.2.3.4' + + // Specify the same token as a helper object. + const token = new ECToken + token.addValue('ec_expire', 12345678) + token.addValue('ec_clientip', '1.2.3.4') + + // Specify an encrypted token using the key above. + const encrypted = 'WWNONztpLdGM11awAYiFRuIIiIG1LOBQaO2cEtCXjT5PelAA-Tavv7eD9YtSeGM13uQsobIkL0xYf6DZLzM6iMbe' + + it('should successfully encrypt a simple string', function() { + return expect(Promise.resolve( + encrypt(key, params) + )).to.eventually.not.be.rejected + }) + + it('should succesfully encrypt a helper token', function() { + expect(function() { + return expect(Promise.resolve( + encrypt(key, token) + )).to.eventually.be.a('string') + }) + }) + + it('should return a string when encrypting', function() { + return expect(Promise.resolve(encrypt(key, params))).to.eventually.be.a('string') + }) + + it('should decrypt a known token', function() { + return expect(Promise.resolve( + decrypt(key, encrypted) + )).to.eventually.equal(params) + }) +}) diff --git a/yarn.lock b/yarn.lock index 3842303..4af99a3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2,7 +2,554 @@ # yarn lockfile v1 +ansi-colors@4.1.1: + version "4.1.1" + resolved "https://registry.npmjs.org/ansi-colors/-/ansi-colors-4.1.1.tgz" + integrity sha512-JoX0apGbHaUJBNl6yF+p6JAFYZ666/hhCGKN5t9QFjbJQKUU/g8MNbFDbvfrgKXvI1QpZplPOnwIo99lX/AAmA== + +ansi-regex@^5.0.1: + version "5.0.1" + resolved "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz" + integrity sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ== + +ansi-styles@^4.0.0, ansi-styles@^4.1.0: + version "4.3.0" + resolved "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz" + integrity sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg== + dependencies: + color-convert "^2.0.1" + +anymatch@~3.1.2: + version "3.1.3" + resolved "https://registry.npmjs.org/anymatch/-/anymatch-3.1.3.tgz" + integrity sha512-KMReFUr0B4t+D+OBkjR3KYqvocp2XaSzO55UcB6mgQMd3KbcE+mWTyvVV7D/zsdEbNnV6acZUutkiHQXvTr1Rw== + dependencies: + normalize-path "^3.0.0" + picomatch "^2.0.4" + +argparse@^2.0.1: + version "2.0.1" + resolved "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz" + integrity sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q== + +assertion-error@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/assertion-error/-/assertion-error-1.1.0.tgz#e60b6b0e8f301bd97e5375215bda406c85118c0b" + integrity sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw== + +balanced-match@^1.0.0: + version "1.0.2" + resolved "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz" + integrity sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw== + base64url@^3.0.1: version "3.0.1" - resolved "https://registry.yarnpkg.com/base64url/-/base64url-3.0.1.tgz#6399d572e2bc3f90a9a8b22d5dbb0a32d33f788d" + resolved "https://registry.npmjs.org/base64url/-/base64url-3.0.1.tgz" integrity sha512-ir1UPr3dkwexU7FdV8qBBbNDRUhMmIekYMFZfi+C/sLNnRESKPl23nB9b2pltqfOQNnGzsDdId90AEtG5tCx4A== + +binary-extensions@^2.0.0: + version "2.3.0" + resolved "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.3.0.tgz" + integrity sha512-Ceh+7ox5qe7LJuLHoY0feh3pHuUDHAcRUeyL2VYghZwfpkNIy/+8Ocg0a3UuSoYzavmylwuLWQOf3hl0jjMMIw== + +brace-expansion@^2.0.1: + version "2.0.1" + resolved "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz" + integrity sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA== + dependencies: + balanced-match "^1.0.0" + +braces@~3.0.2: + version "3.0.3" + resolved "https://registry.npmjs.org/braces/-/braces-3.0.3.tgz" + integrity sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA== + dependencies: + fill-range "^7.1.1" + +browser-stdout@1.3.1: + version "1.3.1" + resolved "https://registry.npmjs.org/browser-stdout/-/browser-stdout-1.3.1.tgz" + integrity sha512-qhAVI1+Av2X7qelOfAIYwXONood6XlZE/fXaBSmW/T5SzLAmCgzi+eiWE7fUvbHaeNBQH13UftjpXxsfLkMpgw== + +camelcase@^6.0.0: + version "6.3.0" + resolved "https://registry.npmjs.org/camelcase/-/camelcase-6.3.0.tgz" + integrity sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA== + +chai-as-promised@^7.1.2: + version "7.1.2" + resolved "https://registry.yarnpkg.com/chai-as-promised/-/chai-as-promised-7.1.2.tgz#70cd73b74afd519754161386421fb71832c6d041" + integrity sha512-aBDHZxRzYnUYuIAIPBH2s511DjlKPzXNlXSGFC8CwmroWQLfrW0LtE1nK3MAwwNhJPa9raEjNCmRoFpG0Hurdw== + dependencies: + check-error "^1.0.2" + +chai@^4: + version "4.4.1" + resolved "https://registry.yarnpkg.com/chai/-/chai-4.4.1.tgz#3603fa6eba35425b0f2ac91a009fe924106e50d1" + integrity sha512-13sOfMv2+DWduEU+/xbun3LScLoqN17nBeTLUsmDfKdoiC1fr0n9PU4guu4AhRcOVFk/sW8LyZWHuhWtQZiF+g== + dependencies: + assertion-error "^1.1.0" + check-error "^1.0.3" + deep-eql "^4.1.3" + get-func-name "^2.0.2" + loupe "^2.3.6" + pathval "^1.1.1" + type-detect "^4.0.8" + +chalk@^4.1.0: + version "4.1.2" + resolved "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz" + integrity sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA== + dependencies: + ansi-styles "^4.1.0" + supports-color "^7.1.0" + +check-error@^1.0.2, check-error@^1.0.3: + version "1.0.3" + resolved "https://registry.yarnpkg.com/check-error/-/check-error-1.0.3.tgz#a6502e4312a7ee969f646e83bb3ddd56281bd694" + integrity sha512-iKEoDYaRmd1mxM90a2OEfWhjsjPpYPuQ+lMYsoxB126+t8fw7ySEO48nmDg5COTjxDI65/Y2OWpeEHk3ZOe8zg== + dependencies: + get-func-name "^2.0.2" + +chokidar@3.5.3: + version "3.5.3" + resolved "https://registry.npmjs.org/chokidar/-/chokidar-3.5.3.tgz" + integrity sha512-Dr3sfKRP6oTcjf2JmUmFJfeVMvXBdegxB0iVQ5eb2V10uFJUCAS8OByZdVAyVb8xXNz3GjjTgj9kLWsZTqE6kw== + dependencies: + anymatch "~3.1.2" + braces "~3.0.2" + glob-parent "~5.1.2" + is-binary-path "~2.1.0" + is-glob "~4.0.1" + normalize-path "~3.0.0" + readdirp "~3.6.0" + optionalDependencies: + fsevents "~2.3.2" + +cliui@^7.0.2: + version "7.0.4" + resolved "https://registry.npmjs.org/cliui/-/cliui-7.0.4.tgz" + integrity sha512-OcRE68cOsVMXp1Yvonl/fzkQOyjLSu/8bhPDfQt0e0/Eb283TKP20Fs2MqoPsr9SwA595rRCA+QMzYc9nBP+JQ== + dependencies: + string-width "^4.2.0" + strip-ansi "^6.0.0" + wrap-ansi "^7.0.0" + +color-convert@^2.0.1: + version "2.0.1" + resolved "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz" + integrity sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ== + dependencies: + color-name "~1.1.4" + +color-name@~1.1.4: + version "1.1.4" + resolved "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz" + integrity sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA== + +debug@4.3.4: + version "4.3.4" + resolved "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz" + integrity sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ== + dependencies: + ms "2.1.2" + +decamelize@^4.0.0: + version "4.0.0" + resolved "https://registry.npmjs.org/decamelize/-/decamelize-4.0.0.tgz" + integrity sha512-9iE1PgSik9HeIIw2JO94IidnE3eBoQrFJ3w7sFuzSX4DpmZ3v5sZpUiV5Swcf6mQEF+Y0ru8Neo+p+nyh2J+hQ== + +deep-eql@^4.1.3: + version "4.1.3" + resolved "https://registry.yarnpkg.com/deep-eql/-/deep-eql-4.1.3.tgz#7c7775513092f7df98d8df9996dd085eb668cc6d" + integrity sha512-WaEtAOpRA1MQ0eohqZjpGD8zdI0Ovsm8mmFhaDN8dvDZzyoUMcYDnf5Y6iu7HTXxf8JDS23qWa4a+hKCDyOPzw== + dependencies: + type-detect "^4.0.0" + +diff@5.0.0: + version "5.0.0" + resolved "https://registry.npmjs.org/diff/-/diff-5.0.0.tgz" + integrity sha512-/VTCrvm5Z0JGty/BWHljh+BAiw3IK+2j87NGMu8Nwc/f48WoDAC395uomO9ZD117ZOBaHmkX1oyLvkVM/aIT3w== + +emoji-regex@^8.0.0: + version "8.0.0" + resolved "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz" + integrity sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A== + +escalade@^3.1.1: + version "3.1.2" + resolved "https://registry.npmjs.org/escalade/-/escalade-3.1.2.tgz" + integrity sha512-ErCHMCae19vR8vQGe50xIsVomy19rg6gFu3+r3jkEO46suLMWBksvVyoGgQV+jOfl84ZSOSlmv6Gxa89PmTGmA== + +escape-string-regexp@4.0.0: + version "4.0.0" + resolved "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz" + integrity sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA== + +fill-range@^7.1.1: + version "7.1.1" + resolved "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz" + integrity sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg== + dependencies: + to-regex-range "^5.0.1" + +find-up@5.0.0: + version "5.0.0" + resolved "https://registry.npmjs.org/find-up/-/find-up-5.0.0.tgz" + integrity sha512-78/PXT1wlLLDgTzDs7sjq9hzz0vXD+zn+7wypEe4fXQxCmdmqfGsEPQxmiCSQI3ajFV91bVSsvNtrJRiW6nGng== + dependencies: + locate-path "^6.0.0" + path-exists "^4.0.0" + +flat@^5.0.2: + version "5.0.2" + resolved "https://registry.npmjs.org/flat/-/flat-5.0.2.tgz" + integrity sha512-b6suED+5/3rTpUBdG1gupIl8MPFCAMA0QXwmljLhvCUKcUvdE4gWky9zpuGCcXHOsz4J9wPGNWq6OKpmIzz3hQ== + +fs.realpath@^1.0.0: + version "1.0.0" + resolved "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz" + integrity sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw== + +fsevents@~2.3.2: + version "2.3.3" + resolved "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz" + integrity sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw== + +get-caller-file@^2.0.5: + version "2.0.5" + resolved "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz" + integrity sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg== + +get-func-name@^2.0.1, get-func-name@^2.0.2: + version "2.0.2" + resolved "https://registry.yarnpkg.com/get-func-name/-/get-func-name-2.0.2.tgz#0d7cf20cd13fda808669ffa88f4ffc7a3943fc41" + integrity sha512-8vXOvuE167CtIc3OyItco7N/dpRtBbYOsPsXCz7X/PMnlGjYjSGuZJgM1Y7mmew7BKf9BqvLX2tnOVy1BBUsxQ== + +glob-parent@~5.1.2: + version "5.1.2" + resolved "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz" + integrity sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow== + dependencies: + is-glob "^4.0.1" + +glob@8.1.0: + version "8.1.0" + resolved "https://registry.npmjs.org/glob/-/glob-8.1.0.tgz" + integrity sha512-r8hpEjiQEYlF2QU0df3dS+nxxSIreXQS1qRhMJM0Q5NDdR386C7jb7Hwwod8Fgiuex+k0GFjgft18yvxm5XoCQ== + dependencies: + fs.realpath "^1.0.0" + inflight "^1.0.4" + inherits "2" + minimatch "^5.0.1" + once "^1.3.0" + +has-flag@^4.0.0: + version "4.0.0" + resolved "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz" + integrity sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ== + +he@1.2.0: + version "1.2.0" + resolved "https://registry.npmjs.org/he/-/he-1.2.0.tgz" + integrity sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw== + +inflight@^1.0.4: + version "1.0.6" + resolved "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz" + integrity sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA== + dependencies: + once "^1.3.0" + wrappy "1" + +inherits@2: + version "2.0.4" + resolved "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz" + integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ== + +is-binary-path@~2.1.0: + version "2.1.0" + resolved "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz" + integrity sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw== + dependencies: + binary-extensions "^2.0.0" + +is-extglob@^2.1.1: + version "2.1.1" + resolved "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz" + integrity sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ== + +is-fullwidth-code-point@^3.0.0: + version "3.0.0" + resolved "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz" + integrity sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg== + +is-glob@^4.0.1, is-glob@~4.0.1: + version "4.0.3" + resolved "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz" + integrity sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg== + dependencies: + is-extglob "^2.1.1" + +is-number@^7.0.0: + version "7.0.0" + resolved "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz" + integrity sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng== + +is-plain-obj@^2.1.0: + version "2.1.0" + resolved "https://registry.npmjs.org/is-plain-obj/-/is-plain-obj-2.1.0.tgz" + integrity sha512-YWnfyRwxL/+SsrWYfOpUtz5b3YD+nyfkHvjbcanzk8zgyO4ASD67uVMRt8k5bM4lLMDnXfriRhOpemw+NfT1eA== + +is-unicode-supported@^0.1.0: + version "0.1.0" + resolved "https://registry.npmjs.org/is-unicode-supported/-/is-unicode-supported-0.1.0.tgz" + integrity sha512-knxG2q4UC3u8stRGyAVJCOdxFmv5DZiRcdlIaAQXAbSfJya+OhopNotLQrstBhququ4ZpuKbDc/8S6mgXgPFPw== + +js-yaml@4.1.0: + version "4.1.0" + resolved "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz" + integrity sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA== + dependencies: + argparse "^2.0.1" + +locate-path@^6.0.0: + version "6.0.0" + resolved "https://registry.npmjs.org/locate-path/-/locate-path-6.0.0.tgz" + integrity sha512-iPZK6eYjbxRu3uB4/WZ3EsEIMJFMqAoopl3R+zuq0UjcAm/MO6KCweDgPfP3elTztoKP3KtnVHxTn2NHBSDVUw== + dependencies: + p-locate "^5.0.0" + +log-symbols@4.1.0: + version "4.1.0" + resolved "https://registry.npmjs.org/log-symbols/-/log-symbols-4.1.0.tgz" + integrity sha512-8XPvpAA8uyhfteu8pIvQxpJZ7SYYdpUivZpGy6sFsBuKRY/7rQGavedeB8aK+Zkyq6upMFVL/9AW6vOYzfRyLg== + dependencies: + chalk "^4.1.0" + is-unicode-supported "^0.1.0" + +loupe@^2.3.6: + version "2.3.7" + resolved "https://registry.yarnpkg.com/loupe/-/loupe-2.3.7.tgz#6e69b7d4db7d3ab436328013d37d1c8c3540c697" + integrity sha512-zSMINGVYkdpYSOBmLi0D1Uo7JU9nVdQKrHxC8eYlV+9YKK9WePqAlL7lSlorG/U2Fw1w0hTBmaa/jrQ3UbPHtA== + dependencies: + get-func-name "^2.0.1" + +minimatch@5.0.1, minimatch@^5.0.1: + version "5.0.1" + resolved "https://registry.npmjs.org/minimatch/-/minimatch-5.0.1.tgz" + integrity sha512-nLDxIFRyhDblz3qMuq+SoRZED4+miJ/G+tdDrjkkkRnjAsBexeGpgjLEQ0blJy7rHhR2b93rhQY4SvyWu9v03g== + dependencies: + brace-expansion "^2.0.1" + +mocha@^10.4.0: + version "10.4.0" + resolved "https://registry.npmjs.org/mocha/-/mocha-10.4.0.tgz" + integrity sha512-eqhGB8JKapEYcC4ytX/xrzKforgEc3j1pGlAXVy3eRwrtAy5/nIfT1SvgGzfN0XZZxeLq0aQWkOUAmqIJiv+bA== + dependencies: + ansi-colors "4.1.1" + browser-stdout "1.3.1" + chokidar "3.5.3" + debug "4.3.4" + diff "5.0.0" + escape-string-regexp "4.0.0" + find-up "5.0.0" + glob "8.1.0" + he "1.2.0" + js-yaml "4.1.0" + log-symbols "4.1.0" + minimatch "5.0.1" + ms "2.1.3" + serialize-javascript "6.0.0" + strip-json-comments "3.1.1" + supports-color "8.1.1" + workerpool "6.2.1" + yargs "16.2.0" + yargs-parser "20.2.4" + yargs-unparser "2.0.0" + +ms@2.1.2: + version "2.1.2" + resolved "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz" + integrity sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w== + +ms@2.1.3: + version "2.1.3" + resolved "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz" + integrity sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA== + +normalize-path@^3.0.0, normalize-path@~3.0.0: + version "3.0.0" + resolved "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz" + integrity sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA== + +once@^1.3.0: + version "1.4.0" + resolved "https://registry.npmjs.org/once/-/once-1.4.0.tgz" + integrity sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w== + dependencies: + wrappy "1" + +p-limit@^3.0.2: + version "3.1.0" + resolved "https://registry.npmjs.org/p-limit/-/p-limit-3.1.0.tgz" + integrity sha512-TYOanM3wGwNGsZN2cVTYPArw454xnXj5qmWF1bEoAc4+cU/ol7GVh7odevjp1FNHduHc3KZMcFduxU5Xc6uJRQ== + dependencies: + yocto-queue "^0.1.0" + +p-locate@^5.0.0: + version "5.0.0" + resolved "https://registry.npmjs.org/p-locate/-/p-locate-5.0.0.tgz" + integrity sha512-LaNjtRWUBY++zB5nE/NwcaoMylSPk+S+ZHNB1TzdbMJMny6dynpAGt7X/tl/QYq3TIeE6nxHppbo2LGymrG5Pw== + dependencies: + p-limit "^3.0.2" + +path-exists@^4.0.0: + version "4.0.0" + resolved "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz" + integrity sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w== + +pathval@^1.1.1: + version "1.1.1" + resolved "https://registry.yarnpkg.com/pathval/-/pathval-1.1.1.tgz#8534e77a77ce7ac5a2512ea21e0fdb8fcf6c3d8d" + integrity sha512-Dp6zGqpTdETdR63lehJYPeIOqpiNBNtc7BpWSLrOje7UaIsE5aY92r/AunQA7rsXvet3lrJ3JnZX29UPTKXyKQ== + +picomatch@^2.0.4, picomatch@^2.2.1: + version "2.3.1" + resolved "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz" + integrity sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA== + +randombytes@^2.1.0: + version "2.1.0" + resolved "https://registry.npmjs.org/randombytes/-/randombytes-2.1.0.tgz" + integrity sha512-vYl3iOX+4CKUWuxGi9Ukhie6fsqXqS9FE2Zaic4tNFD2N2QQaXOMFbuKK4QmDHC0JO6B1Zp41J0LpT0oR68amQ== + dependencies: + safe-buffer "^5.1.0" + +readdirp@~3.6.0: + version "3.6.0" + resolved "https://registry.npmjs.org/readdirp/-/readdirp-3.6.0.tgz" + integrity sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA== + dependencies: + picomatch "^2.2.1" + +require-directory@^2.1.1: + version "2.1.1" + resolved "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz" + integrity sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q== + +safe-buffer@^5.1.0: + version "5.2.1" + resolved "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz" + integrity sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ== + +serialize-javascript@6.0.0: + version "6.0.0" + resolved "https://registry.npmjs.org/serialize-javascript/-/serialize-javascript-6.0.0.tgz" + integrity sha512-Qr3TosvguFt8ePWqsvRfrKyQXIiW+nGbYpy8XK24NQHE83caxWt+mIymTT19DGFbNWNLfEwsrkSmN64lVWB9ag== + dependencies: + randombytes "^2.1.0" + +string-width@^4.1.0, string-width@^4.2.0: + version "4.2.3" + resolved "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz" + integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== + dependencies: + emoji-regex "^8.0.0" + is-fullwidth-code-point "^3.0.0" + strip-ansi "^6.0.1" + +strip-ansi@^6.0.0, strip-ansi@^6.0.1: + version "6.0.1" + resolved "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz" + integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== + dependencies: + ansi-regex "^5.0.1" + +strip-json-comments@3.1.1: + version "3.1.1" + resolved "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz" + integrity sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig== + +supports-color@8.1.1: + version "8.1.1" + resolved "https://registry.npmjs.org/supports-color/-/supports-color-8.1.1.tgz" + integrity sha512-MpUEN2OodtUzxvKQl72cUF7RQ5EiHsGvSsVG0ia9c5RbWGL2CI4C7EpPS8UTBIplnlzZiNuV56w+FuNxy3ty2Q== + dependencies: + has-flag "^4.0.0" + +supports-color@^7.1.0: + version "7.2.0" + resolved "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz" + integrity sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw== + dependencies: + has-flag "^4.0.0" + +to-regex-range@^5.0.1: + version "5.0.1" + resolved "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz" + integrity sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ== + dependencies: + is-number "^7.0.0" + +type-detect@^4.0.0, type-detect@^4.0.8: + version "4.0.8" + resolved "https://registry.yarnpkg.com/type-detect/-/type-detect-4.0.8.tgz#7646fb5f18871cfbb7749e69bd39a6388eb7450c" + integrity sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g== + +workerpool@6.2.1: + version "6.2.1" + resolved "https://registry.npmjs.org/workerpool/-/workerpool-6.2.1.tgz" + integrity sha512-ILEIE97kDZvF9Wb9f6h5aXK4swSlKGUcOEGiIYb2OOu/IrDU9iwj0fD//SsA6E5ibwJxpEvhullJY4Sl4GcpAw== + +wrap-ansi@^7.0.0: + version "7.0.0" + resolved "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz" + integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q== + dependencies: + ansi-styles "^4.0.0" + string-width "^4.1.0" + strip-ansi "^6.0.0" + +wrappy@1: + version "1.0.2" + resolved "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz" + integrity sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ== + +y18n@^5.0.5: + version "5.0.8" + resolved "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz" + integrity sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA== + +yargs-parser@20.2.4, yargs-parser@^20.2.2: + version "20.2.4" + resolved "https://registry.npmjs.org/yargs-parser/-/yargs-parser-20.2.4.tgz" + integrity sha512-WOkpgNhPTlE73h4VFAFsOnomJVaovO8VqLDzy5saChRBFQFBoMYirowyW+Q9HB4HFF4Z7VZTiG3iSzJJA29yRA== + +yargs-unparser@2.0.0: + version "2.0.0" + resolved "https://registry.npmjs.org/yargs-unparser/-/yargs-unparser-2.0.0.tgz" + integrity sha512-7pRTIA9Qc1caZ0bZ6RYRGbHJthJWuakf+WmHK0rVeLkNrrGhfoabBNdue6kdINI6r4if7ocq9aD/n7xwKOdzOA== + dependencies: + camelcase "^6.0.0" + decamelize "^4.0.0" + flat "^5.0.2" + is-plain-obj "^2.1.0" + +yargs@16.2.0: + version "16.2.0" + resolved "https://registry.npmjs.org/yargs/-/yargs-16.2.0.tgz" + integrity sha512-D1mvvtDG0L5ft/jGWkLpG1+m0eQxOfaBvTNELraWj22wSVUMWxZUvYgJYcKh6jGGIkJFhH4IZPQhR4TKpc8mBw== + dependencies: + cliui "^7.0.2" + escalade "^3.1.1" + get-caller-file "^2.0.5" + require-directory "^2.1.1" + string-width "^4.2.0" + y18n "^5.0.5" + yargs-parser "^20.2.2" + +yocto-queue@^0.1.0: + version "0.1.0" + resolved "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz" + integrity sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q== From 22ca5f4d4a9b352e901e4a1ce1237999b5e640a6 Mon Sep 17 00:00:00 2001 From: Tom Mount Date: Tue, 28 May 2024 14:23:41 -0400 Subject: [PATCH 3/7] update readme --- README.md | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 6493c23..69ce1a2 100644 --- a/README.md +++ b/README.md @@ -15,15 +15,14 @@ JavaScript implementation of the "Edgio Token" (`ectoken`) - see main repo [ecto ## Install -1. Clone this repo. -2. `cd` into the repo directory -3. Run `npm install` +``` +$ npm install js-ectoken +``` ## Usage -This library is provided in CommonJS (CJS) format. To include the library in a script, `require` it: ```js -const { ECToken, encrypt, decrypt } = require('./ECToken.js') +const { ECToken, encrypt, decrypt } = require('js-ectoken') const ec_token = new ECToken() ec_token.addValue('ec_country_allow', 'US') @@ -33,6 +32,17 @@ const token = await encrypt('my-secret-key', ec_token) const plaintext = await decrypt('my-secret-key', token) ``` +If installing this library as a replacement for [`ectoken-nodejs`](https://github.com/hattan/ectoken-nodejs), import the `V3` namespace instead: + +```js +const { V3 } = require('js-ectoken') + +const token = await encrypt('my-secret-key', 'some_param=valueA&some_other_param=valueB') +const plaintext = await decrypt('my-secret-key', token) +``` + +**Please Note**: because this version of the token generator uses `crypto.subtle`, the `encrypt` and `decrypt` functions **are now asynchronous.** + ## Contribute We welcome issues, questions, and pull requests. From 97819e0238ed6ae594eb5b7bbf53240ef0b68207 Mon Sep 17 00:00:00 2001 From: Tom Mount Date: Tue, 28 May 2024 14:24:29 -0400 Subject: [PATCH 4/7] update readme with namespace info --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 69ce1a2..f57f13f 100644 --- a/README.md +++ b/README.md @@ -37,8 +37,8 @@ If installing this library as a replacement for [`ectoken-nodejs`](https://githu ```js const { V3 } = require('js-ectoken') -const token = await encrypt('my-secret-key', 'some_param=valueA&some_other_param=valueB') -const plaintext = await decrypt('my-secret-key', token) +const token = await V3.encrypt('my-secret-key', 'some_param=valueA&some_other_param=valueB') +const plaintext = await V3.decrypt('my-secret-key', token) ``` **Please Note**: because this version of the token generator uses `crypto.subtle`, the `encrypt` and `decrypt` functions **are now asynchronous.** From 8d368800e64b53ed769bb32b58f76b3c29cc8937 Mon Sep 17 00:00:00 2001 From: Tom Mount Date: Tue, 28 May 2024 14:26:36 -0400 Subject: [PATCH 5/7] add note on ectoken helper class --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index f57f13f..168217a 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,8 @@ const plaintext = await V3.decrypt('my-secret-key', token) **Please Note**: because this version of the token generator uses `crypto.subtle`, the `encrypt` and `decrypt` functions **are now asynchronous.** +The `ECToken` helper class is optional for both the namespaced and non-namespaced import variations. The `encrypt` function will accept either an `ECToken` object or a plain `string`. + ## Contribute We welcome issues, questions, and pull requests. From 862fcda849669d52a52d38772cf959903724f45d Mon Sep 17 00:00:00 2001 From: Tom Mount Date: Tue, 28 May 2024 14:39:36 -0400 Subject: [PATCH 6/7] namespace whole package --- README.md | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 168217a..3617ad3 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ $ npm install js-ectoken ## Usage ```js -const { ECToken, encrypt, decrypt } = require('js-ectoken') +const { ECToken, encrypt, decrypt } = require('@edgio/js-ectoken') const ec_token = new ECToken() ec_token.addValue('ec_country_allow', 'US') @@ -35,7 +35,7 @@ const plaintext = await decrypt('my-secret-key', token) If installing this library as a replacement for [`ectoken-nodejs`](https://github.com/hattan/ectoken-nodejs), import the `V3` namespace instead: ```js -const { V3 } = require('js-ectoken') +const { V3 } = require('@edgio/js-ectoken') const token = await V3.encrypt('my-secret-key', 'some_param=valueA&some_other_param=valueB') const plaintext = await V3.decrypt('my-secret-key', token) diff --git a/package.json b/package.json index 8deef85..568de72 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "js-ectoken", + "name": "@edgio/js-ectoken", "version": "2.0.0", "description": "JS implementation of Edgio token (ectoken)", "main": "index.js", From 04f8714e25bd44a65775e3675702468b8b1dd980 Mon Sep 17 00:00:00 2001 From: Tom Mount Date: Tue, 28 May 2024 14:44:30 -0400 Subject: [PATCH 7/7] fix install instructions --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3617ad3..aee33e3 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ JavaScript implementation of the "Edgio Token" (`ectoken`) - see main repo [ecto ## Install ``` -$ npm install js-ectoken +$ npm install @edgio/js-ectoken ``` ## Usage