Skip to content

Commit 97a944a

Browse files
authored
Updated wasm code to work with new gateway and updated the example (#219)
* Updated wasm code to work with new gateway and updated the example * cargo fmt * Fixed test by ensuring destination is present at a gateway * Updated hardcoded default port * ibid. to correct value
1 parent f9d3ee7 commit 97a944a

File tree

23 files changed

+4551
-252
lines changed

23 files changed

+4551
-252
lines changed

Cargo.lock

Lines changed: 18 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

clients/webassembly/Cargo.toml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
[package]
2-
name = "sphinx-wasm"
3-
version = "0.1.0"
4-
authors = ["Dave Hrycyszyn <futurechimp@users.noreply.github.com>"]
2+
name = "nym-client-wasm"
3+
version = "0.1.2"
4+
authors = ["Dave Hrycyszyn <futurechimp@users.noreply.github.com>", "Jedrzej Stuczynski <andrew@nymtech.net>"]
55
edition = "2018"
6+
repository = "https://github.com/nymtech/nym"
7+
license = "Apache-2.0"
68

79
[lib]
810
crate-type = ["cdylib", "rlib"]
@@ -11,7 +13,6 @@ crate-type = ["cdylib", "rlib"]
1113
default = ["console_error_panic_hook"]
1214

1315
[dependencies]
14-
# itertools = "0.8.2"
1516
log = "0.4"
1617
serde = { version = "1.0", features = ["derive"] }
1718
serde_json = "1.0"

clients/webassembly/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,12 @@ See our [docs](https://nymtech.net/docs).
1414

1515
### Demo
1616

17-
There's a demo web application in the `www` folder. To run it, first make sure you've got a recent `npm` installed, then follow the instructions in its README.
17+
There's a demo web application in the `www` folder. To run it, first make sure you've got a recent `npm` installed, then follow the instructions in its README.
1818

1919
### Developing
2020

2121
Whenever you change your Rust, run `wasm-pack build` to update the built was artefact in the `pkg` directory.
22+
23+
# IMPORTANT!!
24+
25+
You also need to manually copy `helpers.js` file into the `pkg` and add it to `package.json`. I'm 100% sure one of the hundreds JS packagers could do that for us, but I didn't feel like spending 10 hours figuring this one out.

clients/webassembly/helpers.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import * as wasm from "nym-client-wasm";
2+
3+
export function makeRegisterRequest(address) {
4+
return JSON.stringify({ "type": "register", "address": address });
5+
}
6+
7+
export function makeAuthenticateRequest(address, token) {
8+
return JSON.stringify({ "type": "authenticate", "address": address, "token": token });
9+
}
10+
11+
// NOTE: this currently does not implement chunking and too long messages will cause a panic
12+
export function makeSendablePacket(topology, message, recipient) {
13+
return wasm.create_gateway_sphinx_packet(topology, message, recipient);
14+
}
15+
16+
export async function getTopology(directoryUrl) {
17+
let response = await http('get', directoryUrl);
18+
let topology = JSON.parse(response);
19+
return topology;
20+
}
21+
22+
function http(method, url) {
23+
return new Promise(function (resolve, reject) {
24+
let xhr = new XMLHttpRequest();
25+
xhr.open(method, url);
26+
xhr.onload = function () {
27+
if (this.status >= 200 && this.status < 300) {
28+
resolve(xhr.response);
29+
} else {
30+
reject({
31+
status: this.status,
32+
statusText: xhr.statusText
33+
});
34+
}
35+
};
36+
xhr.onerror = function () {
37+
reject({
38+
status: this.status,
39+
statusText: xhr.statusText
40+
});
41+
};
42+
xhr.send();
43+
});
44+
}
File renamed without changes.

0 commit comments

Comments
 (0)