Filtering compatible node versions

This commit is contained in:
jstuczyn
2020-06-05 18:06:38 +01:00
parent c1e921db6a
commit 4e4187ad57
7 changed files with 37 additions and 5 deletions
+1
View File
@@ -4,3 +4,4 @@ Cargo.lock
bin/
pkg/
wasm-pack.log
node_modules
+1 -1
View File
@@ -1,7 +1,7 @@
[package]
name = "nym-client-wasm"
authors = ["Dave Hrycyszyn <futurechimp@users.noreply.github.com>", "Jedrzej Stuczynski <andrew@nymtech.net>"]
version = "0.7.4"
version = "0.7.5"
edition = "2018"
keywords = ["nym", "sphinx", "wasm", "webassembly", "privacy", "client"]
license = "Apache-2.0"
+2 -2
View File
@@ -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
+13 -1
View File
@@ -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;
+1 -1
View File
@@ -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"
}
}
+11
View File
@@ -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=="
}
}
}
+8
View File
@@ -0,0 +1,8 @@
{
"files": [
"client.js"
],
"dependencies": {
"semver": "^7.3.2"
}
}