From 4e4187ad5717ac4e6bf272d1fbfc26ceba9f7321 Mon Sep 17 00:00:00 2001 From: jstuczyn Date: Fri, 5 Jun 2020 18:06:38 +0100 Subject: [PATCH] Filtering compatible node versions --- clients/webassembly/.gitignore | 1 + clients/webassembly/Cargo.toml | 2 +- clients/webassembly/README.md | 4 ++-- clients/webassembly/client.js | 14 +++++++++++++- clients/webassembly/js-example/package.json | 2 +- clients/webassembly/package-lock.json | 11 +++++++++++ clients/webassembly/package.json | 8 ++++++++ 7 files changed, 37 insertions(+), 5 deletions(-) create mode 100644 clients/webassembly/package-lock.json create mode 100644 clients/webassembly/package.json diff --git a/clients/webassembly/.gitignore b/clients/webassembly/.gitignore index 4e301317e5..90a2a4d375 100644 --- a/clients/webassembly/.gitignore +++ b/clients/webassembly/.gitignore @@ -4,3 +4,4 @@ Cargo.lock bin/ pkg/ wasm-pack.log +node_modules \ No newline at end of file diff --git a/clients/webassembly/Cargo.toml b/clients/webassembly/Cargo.toml index b11ca51ee2..cedd92610c 100644 --- a/clients/webassembly/Cargo.toml +++ b/clients/webassembly/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "nym-client-wasm" authors = ["Dave Hrycyszyn ", "Jedrzej Stuczynski "] -version = "0.7.4" +version = "0.7.5" edition = "2018" keywords = ["nym", "sphinx", "wasm", "webassembly", "privacy", "client"] license = "Apache-2.0" diff --git a/clients/webassembly/README.md b/clients/webassembly/README.md index 61441fc11a..856bc21e4b 100644 --- a/clients/webassembly/README.md +++ b/clients/webassembly/README.md @@ -28,7 +28,7 @@ First, make sure you've got all the [Rust wasm toolchain](https://rustwasm.githu Whenever you change any Rust in the `src` directory, run `wasm-pack build --scope nymproject` to update the built wasm artefact in the `pkg` directory. -For now, when you compile `nym-client-wasm` using `wasm-pack build --scope nymproject` you will need to manually copy the file `client.js` into the `pkg` and add it to `package.json`. Once [these](https://github.com/rustwasm/wasm-pack/issues/840) [issues](https://github.com/rustwasm/rfcs/pull/8#issuecomment-564725214) get closed, this annoying extra step will go away. +For now, when you compile `nym-client-wasm` using `wasm-pack build --scope nymproject` you will need to manually copy the file `client.js` into the `pkg` and `package.json` with entries from `package.json` on the main path. Once [these](https://github.com/rustwasm/wasm-pack/issues/840) [issues](https://github.com/rustwasm/rfcs/pull/8#issuecomment-564725214) get closed, this annoying extra step will go away. To be clear, this is not something that most JS developers need to worry about, this is only for Nym devs. The packages on NPM have all files in place. Just install and enjoy! @@ -37,6 +37,6 @@ To be clear, this is not something that most JS developers need to worry about, If you're a Nym platform developer who's made changes to the Rust (or JS) files and wants to re-publish the package to NPM, here's how you do it: 1. `wasm-pack build --scope nymproject` builds the wasm binaries into the `pkg` directory (not in source control) -2. copy `client.js` into the `pkg` folder and add it to the `package.json` manifest +2. copy `client.js` into the `pkg` folder and update `package.json` manifest with the provided one 3. bump version numbers as necessary for SemVer 4. `wasm-pack publish --access=public` will publish your changed package to NPM diff --git a/clients/webassembly/client.js b/clients/webassembly/client.js index 6d80a70dcb..c5381dc937 100644 --- a/clients/webassembly/client.js +++ b/clients/webassembly/client.js @@ -1,5 +1,6 @@ import * as wasm from "."; - +import { version } from './package.json'; +import { major, minor, parse } from "semver"; /** * A Nym identity, consisting of a public/private keypair and a Nym * gateway address. @@ -49,6 +50,15 @@ export class Client { return this.authToken !== null } + /** + * Checks if given node is compatible with this client + */ + isNodeVersionCompatible(node) { + const clientVersion = parse(version); + const mixVersion = parse(node.version); + return major(clientVersion) === major(mixVersion) && minor(clientVersion) === minor(mixVersion) + } + /** * Update the Nym network topology. * @@ -57,6 +67,8 @@ export class Client { async updateTopology() { let response = await http('get', this.topologyEndpoint); let topology = JSON.parse(response); // make sure it's a valid json + topology.mixNodes = topology.mixNodes.filter(this.isNodeVersionCompatible) + topology.gatewayNodes = topology.gatewayNodes.filter(this.isNodeVersionCompatible) this.topology = topology; this.onUpdatedTopology(); return topology; diff --git a/clients/webassembly/js-example/package.json b/clients/webassembly/js-example/package.json index 5707c11ae0..5814e8b357 100644 --- a/clients/webassembly/js-example/package.json +++ b/clients/webassembly/js-example/package.json @@ -34,6 +34,6 @@ "webpack-dev-server": "^3.11.0" }, "dependencies": { - "@nymproject/nym-client-wasm": "^0.7.4" + "@nymproject/nym-client-wasm": "^0.7.5" } } \ No newline at end of file diff --git a/clients/webassembly/package-lock.json b/clients/webassembly/package-lock.json new file mode 100644 index 0000000000..6e580e1b85 --- /dev/null +++ b/clients/webassembly/package-lock.json @@ -0,0 +1,11 @@ +{ + "requires": true, + "lockfileVersion": 1, + "dependencies": { + "semver": { + "version": "7.3.2", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.2.tgz", + "integrity": "sha512-OrOb32TeeambH6UrhtShmF7CRDqhL6/5XpPNp2DuRH6+9QLw/orhp72j87v8Qa1ScDkvrrBNpZcDejAirJmfXQ==" + } + } +} diff --git a/clients/webassembly/package.json b/clients/webassembly/package.json new file mode 100644 index 0000000000..f2d07eb7f7 --- /dev/null +++ b/clients/webassembly/package.json @@ -0,0 +1,8 @@ +{ + "files": [ + "client.js" + ], + "dependencies": { + "semver": "^7.3.2" + } +}