Skip to content

Commit 6aec202

Browse files
authored
Merge pull request #259 from nymtech/hotfix/wasm_topology_version_filter
Filtering compatible node versions
2 parents c1e921d + 4e4187a commit 6aec202

File tree

7 files changed

+37
-5
lines changed

7 files changed

+37
-5
lines changed

clients/webassembly/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ Cargo.lock
44
bin/
55
pkg/
66
wasm-pack.log
7+
node_modules

clients/webassembly/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "nym-client-wasm"
33
authors = ["Dave Hrycyszyn <futurechimp@users.noreply.github.com>", "Jedrzej Stuczynski <andrew@nymtech.net>"]
4-
version = "0.7.4"
4+
version = "0.7.5"
55
edition = "2018"
66
keywords = ["nym", "sphinx", "wasm", "webassembly", "privacy", "client"]
77
license = "Apache-2.0"

clients/webassembly/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ First, make sure you've got all the [Rust wasm toolchain](https://rustwasm.githu
2828

2929
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.
3030

31-
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.
31+
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.
3232

3333
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!
3434

@@ -37,6 +37,6 @@ To be clear, this is not something that most JS developers need to worry about,
3737
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:
3838

3939
1. `wasm-pack build --scope nymproject` builds the wasm binaries into the `pkg` directory (not in source control)
40-
2. copy `client.js` into the `pkg` folder and add it to the `package.json` manifest
40+
2. copy `client.js` into the `pkg` folder and update `package.json` manifest with the provided one
4141
3. bump version numbers as necessary for SemVer
4242
4. `wasm-pack publish --access=public` will publish your changed package to NPM

clients/webassembly/client.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as wasm from ".";
2-
2+
import { version } from './package.json';
3+
import { major, minor, parse } from "semver";
34
/**
45
* A Nym identity, consisting of a public/private keypair and a Nym
56
* gateway address.
@@ -49,6 +50,15 @@ export class Client {
4950
return this.authToken !== null
5051
}
5152

53+
/**
54+
* Checks if given node is compatible with this client
55+
*/
56+
isNodeVersionCompatible(node) {
57+
const clientVersion = parse(version);
58+
const mixVersion = parse(node.version);
59+
return major(clientVersion) === major(mixVersion) && minor(clientVersion) === minor(mixVersion)
60+
}
61+
5262
/**
5363
* Update the Nym network topology.
5464
*
@@ -57,6 +67,8 @@ export class Client {
5767
async updateTopology() {
5868
let response = await http('get', this.topologyEndpoint);
5969
let topology = JSON.parse(response); // make sure it's a valid json
70+
topology.mixNodes = topology.mixNodes.filter(this.isNodeVersionCompatible)
71+
topology.gatewayNodes = topology.gatewayNodes.filter(this.isNodeVersionCompatible)
6072
this.topology = topology;
6173
this.onUpdatedTopology();
6274
return topology;

clients/webassembly/js-example/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@
3434
"webpack-dev-server": "^3.11.0"
3535
},
3636
"dependencies": {
37-
"@nymproject/nym-client-wasm": "^0.7.4"
37+
"@nymproject/nym-client-wasm": "^0.7.5"
3838
}
3939
}

clients/webassembly/package-lock.json

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

clients/webassembly/package.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"files": [
3+
"client.js"
4+
],
5+
"dependencies": {
6+
"semver": "^7.3.2"
7+
}
8+
}

0 commit comments

Comments
 (0)