diff --git a/Cargo.lock b/Cargo.lock index 07aa6d0..cbf77b9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,41 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "aead" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b613b8e1e3cf911a086f53f03bf286f52fd7a7258e4fa606f0ef220d39d8877" +dependencies = [ + "generic-array", +] + +[[package]] +name = "aes" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e8b47f52ea9bae42228d07ec09eb676433d7c4ed1ebdf0f1d1c29ed446f1ab8" +dependencies = [ + "cfg-if", + "cipher 0.3.0", + "cpufeatures", + "opaque-debug", +] + +[[package]] +name = "aes-gcm" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df5f85a83a7d8b0442b6aa7b504b8212c1733da07b98aae43d4bc21b2cb3cdf6" +dependencies = [ + "aead", + "aes", + "cipher 0.3.0", + "ctr", + "ghash", + "subtle", +] + [[package]] name = "anstyle" version = "0.3.1" @@ -140,6 +175,24 @@ dependencies = [ "futures-micro", ] +[[package]] +name = "async-process" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6381ead98388605d0d9ff86371043b5aa922a3905824244de40dc263a14fcba4" +dependencies = [ + "async-io", + "async-lock", + "autocfg", + "blocking", + "cfg-if", + "event-listener", + "futures-lite", + "libc", + "signal-hook", + "windows-sys 0.42.0", +] + [[package]] name = "async-std" version = "1.12.0" @@ -151,6 +204,7 @@ dependencies = [ "async-global-executor", "async-io", "async-lock", + "async-process", "crossbeam-utils", "futures-channel", "futures-core", @@ -198,6 +252,17 @@ dependencies = [ "tungstenite", ] +[[package]] +name = "async_io_stream" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6d7b9decdf35d8908a7e3ef02f64c5e9b1695e230154c0e8de3969142d9b94c" +dependencies = [ + "futures", + "pharos", + "rustc_version", +] + [[package]] name = "atomic-waker" version = "1.1.0" @@ -231,6 +296,15 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" +[[package]] +name = "blake2" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46502ad458c9a52b69d4d4d32775c788b7a1b85e8bc9d482d92250fc0e3f8efe" +dependencies = [ + "digest 0.10.6", +] + [[package]] name = "blake3" version = "1.3.3" @@ -245,6 +319,16 @@ dependencies = [ "digest 0.10.6", ] +[[package]] +name = "blob-uuid" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83fc15853171b33280f5614e77f5fa4debd33f51a86c44daa4ba3d759674c561" +dependencies = [ + "base64", + "uuid 1.3.0", +] + [[package]] name = "block-buffer" version = "0.9.0" @@ -319,6 +403,18 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "chacha20" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c80e5460aa66fe3b91d40bcbdab953a597b60053e34d684ac6903f863b680a6" +dependencies = [ + "cfg-if", + "cipher 0.3.0", + "cpufeatures", + "zeroize", +] + [[package]] name = "chacha20" version = "0.9.0" @@ -326,10 +422,32 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c7fc89c7c5b9e7a02dfe45cd2367bae382f9ed31c61ca8debe5f827c420a2f08" dependencies = [ "cfg-if", - "cipher", + "cipher 0.4.4", "cpufeatures", ] +[[package]] +name = "chacha20poly1305" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a18446b09be63d457bbec447509e85f662f32952b035ce892290396bc0b0cff5" +dependencies = [ + "aead", + "chacha20 0.8.2", + "cipher 0.3.0", + "poly1305", + "zeroize", +] + +[[package]] +name = "cipher" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ee52072ec15386f770805afd189a01c8841be8696bed250fa2f13c4c0d6dfb7" +dependencies = [ + "generic-array", +] + [[package]] name = "cipher" version = "0.4.4" @@ -349,6 +467,16 @@ dependencies = [ "crossbeam-utils", ] +[[package]] +name = "console_error_panic_hook" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a06aeb73f470f66dcdbf7223caeebb85984942f22f1adb2a088cf9668146bbbc" +dependencies = [ + "cfg-if", + "wasm-bindgen", +] + [[package]] name = "constant_time_eq" version = "0.2.5" @@ -393,6 +521,15 @@ dependencies = [ "syn", ] +[[package]] +name = "ctr" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "049bb91fb4aaf0e3c7efa6cd5ef877dbbbd15b39dad06d9948de4ec8a75761ea" +dependencies = [ + "cipher 0.3.0", +] + [[package]] name = "cuckoofilter" version = "0.5.0" @@ -417,6 +554,20 @@ dependencies = [ "zeroize", ] +[[package]] +name = "curve25519-dalek" +version = "4.0.0-rc.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d4ba9852b42210c7538b75484f9daa0655e9a3ac04f693747bb0f02cf3cfe16" +dependencies = [ + "cfg-if", + "fiat-crypto", + "packed_simd_2", + "platforms", + "subtle", + "zeroize", +] + [[package]] name = "debug_print" version = "1.0.0" @@ -470,11 +621,11 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c762bae6dcaf24c4c84667b8579785430908723d5c889f469d76a41d59cc7a9d" dependencies = [ - "curve25519-dalek", + "curve25519-dalek 3.2.1", "ed25519", "rand 0.7.3", "serde", - "sha2", + "sha2 0.9.9", "zeroize", ] @@ -538,6 +689,12 @@ dependencies = [ "instant", ] +[[package]] +name = "fiat-crypto" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93ace6ec7cc19c8ed33a32eaa9ea692d7faea05006b5356b9e2b668ec4bc3955" + [[package]] name = "fnv" version = "1.0.7" @@ -683,8 +840,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" dependencies = [ "cfg-if", + "js-sys", "libc", "wasi 0.9.0+wasi-snapshot-preview1", + "wasm-bindgen", ] [[package]] @@ -700,6 +859,16 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "ghash" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1583cc1656d7839fd3732b80cf4f38850336cdb9b8ded1cd399ca62958de3c99" +dependencies = [ + "opaque-debug", + "polyval", +] + [[package]] name = "gloo-timers" version = "0.2.6" @@ -840,6 +1009,12 @@ version = "0.2.140" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "99227334921fae1a979cf0bfdfcc6b3e5ce376ef57e16fb6fb3ea2ed6095f80c" +[[package]] +name = "libm" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fc7aa29613bd6a620df431842069224d8bc9011086b1db4c0e0cd47fa03ec9a" + [[package]] name = "linux-raw-sys" version = "0.1.4" @@ -897,8 +1072,21 @@ checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" name = "ng-app-js-sdk" version = "0.1.0" dependencies = [ - "getrandom 0.2.8", + "async-std", + "debug_print", + "futures", + "getrandom 0.1.16", + "p2p-client-ws", + "p2p-net", + "p2p-repo", + "pharos", + "serde", + "serde_bare", + "serde_bytes", + "snow", "wasm-bindgen", + "wasm-bindgen-test", + "ws_stream_wasm", ] [[package]] @@ -913,6 +1101,7 @@ dependencies = [ "futures", "p2p-broker", "p2p-client", + "p2p-client-ws", "p2p-net", "p2p-repo", "p2p-stores-lmdb", @@ -927,6 +1116,7 @@ version = "0.1.0" dependencies = [ "async-std", "p2p-broker", + "p2p-net", ] [[package]] @@ -988,7 +1178,7 @@ dependencies = [ "async-std", "async-trait", "async-tungstenite", - "chacha20", + "chacha20 0.9.0", "debug_print", "futures", "getrandom 0.2.8", @@ -1006,20 +1196,46 @@ dependencies = [ [[package]] name = "p2p-client" version = "0.1.0" +dependencies = [ + "async-channel", + "async-oneshot", + "async-std", + "async-trait", + "chacha20 0.9.0", + "debug_print", + "futures", + "p2p-net", + "p2p-repo", + "serde", + "serde_bare", + "serde_bytes", + "snow", + "xactor", +] + +[[package]] +name = "p2p-client-ws" +version = "0.1.0" dependencies = [ "async-channel", "async-oneshot", "async-std", "async-trait", "async-tungstenite", - "chacha20", + "chacha20 0.9.0", "debug_print", "futures", + "getrandom 0.2.8", + "p2p-client", "p2p-net", "p2p-repo", + "pharos", "serde", "serde_bare", "serde_bytes", + "wasm-bindgen", + "wasm-bindgen-test", + "ws_stream_wasm", "xactor", ] @@ -1028,6 +1244,7 @@ name = "p2p-net" version = "0.1.0" dependencies = [ "async-broadcast", + "async-std", "async-trait", "blake3", "debug_print", @@ -1037,6 +1254,8 @@ dependencies = [ "serde", "serde_bare", "serde_bytes", + "unique_id", + "wasm-bindgen", ] [[package]] @@ -1044,7 +1263,7 @@ name = "p2p-repo" version = "0.1.0" dependencies = [ "blake3", - "chacha20", + "chacha20 0.9.0", "debug_print", "ed25519-dalek", "fastbloom-rs", @@ -1073,7 +1292,7 @@ name = "p2p-verifier" version = "0.1.0" dependencies = [ "blake3", - "chacha20", + "chacha20 0.9.0", "p2p-net", "p2p-repo", "serde", @@ -1081,6 +1300,16 @@ dependencies = [ "serde_bytes", ] +[[package]] +name = "packed_simd_2" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1914cd452d8fccd6f9db48147b29fd4ae05bea9dc5d9ad578509f72415de282" +dependencies = [ + "cfg-if", + "libm", +] + [[package]] name = "parking" version = "2.0.0" @@ -1122,6 +1351,16 @@ version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e" +[[package]] +name = "pharos" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e9567389417feee6ce15dd6527a8a1ecac205ef62c2932bcf3d9f6fc5b78b414" +dependencies = [ + "futures", + "rustc_version", +] + [[package]] name = "pin-project-lite" version = "0.2.9" @@ -1140,6 +1379,12 @@ version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6ac9a59f73473f1b8d852421e59e64809f025994837ef743615c6d0c5b305160" +[[package]] +name = "platforms" +version = "3.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3d7ddaed09e0eb771a79ab0fd64609ba0afb0a8366421957936ad14cbd13630" + [[package]] name = "polling" version = "2.5.2" @@ -1154,6 +1399,29 @@ dependencies = [ "windows-sys 0.42.0", ] +[[package]] +name = "poly1305" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "048aeb476be11a4b6ca432ca569e375810de9294ae78f4774e78ea98a9246ede" +dependencies = [ + "cpufeatures", + "opaque-debug", + "universal-hash", +] + +[[package]] +name = "polyval" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8419d2b623c7c0896ff2d5d96e2cb4ede590fed28fcc34934f4c33c036e620a1" +dependencies = [ + "cfg-if", + "cpufeatures", + "opaque-debug", + "universal-hash", +] + [[package]] name = "ppv-lite86" version = "0.2.17" @@ -1321,7 +1589,7 @@ dependencies = [ "serde_derive", "thiserror", "url", - "uuid", + "uuid 0.8.2", ] [[package]] @@ -1343,6 +1611,15 @@ dependencies = [ "syn", ] +[[package]] +name = "rustc_version" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" +dependencies = [ + "semver", +] + [[package]] name = "rustix" version = "0.36.9" @@ -1357,12 +1634,30 @@ dependencies = [ "windows-sys 0.45.0", ] +[[package]] +name = "scoped-tls" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294" + [[package]] name = "scopeguard" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" +[[package]] +name = "semver" +version = "1.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bebd363326d05ec3e2f532ab7660680f3b02130d780c299bca73469d521bc0ed" + +[[package]] +name = "send_wrapper" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd0b0ec5f1c1ca621c432a25813d8d60c88abe6d3e08a3eb9cf37d97a0fe3d73" + [[package]] name = "serde" version = "1.0.142" @@ -1425,6 +1720,36 @@ dependencies = [ "opaque-debug", ] +[[package]] +name = "sha2" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "82e6b795fe2e3b1e845bafcb27aa35405c4d47cdfc92af5fc8d3002f76cebdc0" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest 0.10.6", +] + +[[package]] +name = "signal-hook" +version = "0.3.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "732768f1176d21d09e076c23a93123d40bba92d50c4058da34d45c8de8e682b9" +dependencies = [ + "libc", + "signal-hook-registry", +] + +[[package]] +name = "signal-hook-registry" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1" +dependencies = [ + "libc", +] + [[package]] name = "signature" version = "1.6.4" @@ -1446,6 +1771,22 @@ version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" +[[package]] +name = "snow" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ccba027ba85743e09d15c03296797cad56395089b832b48b5a5217880f57733" +dependencies = [ + "aes-gcm", + "blake2", + "chacha20poly1305", + "curve25519-dalek 4.0.0-rc.1", + "rand_core 0.6.4", + "rustc_version", + "sha2 0.10.6", + "subtle", +] + [[package]] name = "socket2" version = "0.4.9" @@ -1608,6 +1949,27 @@ version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" +[[package]] +name = "unique_id" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae605c39dfbdec433798d4a8b03ffbac711dc51cdeb1ba5c725bdcaf24e464cc" +dependencies = [ + "blob-uuid", + "lazy_static", + "uuid 1.3.0", +] + +[[package]] +name = "universal-hash" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f214e8f697e925001e66ec2c6e37a4ef93f0f78c2eed7814394e10c62025b05" +dependencies = [ + "generic-array", + "subtle", +] + [[package]] name = "url" version = "2.3.1" @@ -1631,6 +1993,15 @@ version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7" +[[package]] +name = "uuid" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1674845326ee10d37ca60470760d4288a6f80f304007d92e5c53bab78c9cfd79" +dependencies = [ + "getrandom 0.2.8", +] + [[package]] name = "value-bag" version = "1.0.0-alpha.9" @@ -1740,6 +2111,30 @@ version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0046fef7e28c3804e5e38bfa31ea2a0f73905319b677e57ebe37e49358989b5d" +[[package]] +name = "wasm-bindgen-test" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6db36fc0f9fb209e88fb3642590ae0205bb5a56216dabd963ba15879fe53a30b" +dependencies = [ + "console_error_panic_hook", + "js-sys", + "scoped-tls", + "wasm-bindgen", + "wasm-bindgen-futures", + "wasm-bindgen-test-macro", +] + +[[package]] +name = "wasm-bindgen-test-macro" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0734759ae6b3b1717d661fe4f016efcfb9828f5edb4520c18eaee05af3b43be9" +dependencies = [ + "proc-macro2", + "quote", +] + [[package]] name = "web-sys" version = "0.3.61" @@ -1871,6 +2266,25 @@ dependencies = [ "memchr", ] +[[package]] +name = "ws_stream_wasm" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7999f5f4217fe3818726b66257a4475f71e74ffd190776ad053fa159e50737f5" +dependencies = [ + "async_io_stream", + "futures", + "js-sys", + "log", + "pharos", + "rustc_version", + "send_wrapper", + "thiserror", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", +] + [[package]] name = "xactor" version = "0.7.11" diff --git a/README.md b/README.md index 03affb5..e288e44 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,7 @@ Read our [getting started guide](https://docs.nextgraph.org/en/getting-started/) ``` cargo install wasm-pack +// optionally, if you want a Rust REPL: cargo install evcxr_repl git clone git@git.nextgraph.org:NextGraph/nextgraph-rs.git cd nextgraph-rs cargo build @@ -84,6 +85,17 @@ Test end-to-end client and server: cargo test --package ngcli -- --nocapture ``` +Test WASM websocket +``` +cd ng-app-js +wasm-pack test --chrome --headless +``` + +Test Rust websocket +``` +cargo test --package p2p-client-ws --lib -- --nocapture +``` + ### Build release binaries ``` diff --git a/ng-app-js/Cargo.toml b/ng-app-js/Cargo.toml index fabe137..b4c650e 100644 --- a/ng-app-js/Cargo.toml +++ b/ng-app-js/Cargo.toml @@ -15,9 +15,27 @@ crate-type = ["cdylib"] [dependencies] wasm-bindgen = "0.2" -getrandom = "0.2.7" -# p2p-client = { path = "../p2p-client" } +ws_stream_wasm = "0.7" +p2p-net = { path = "../p2p-net" } +p2p-repo = { path = "../p2p-repo" } +p2p-client-ws = { path = "../p2p-client-ws" } +async-std = { version = "1.12.0", features = ["attributes","unstable"] } +futures = "0.3.24" +pharos = "0.5" +debug_print = "1.0.0" +serde = { version = "1.0", features = ["derive"] } +serde_bare = "0.5.0" +serde_bytes = "0.11.7" +snow = "0.9.2" +getrandom = { version = "0.1.1", features = ["wasm-bindgen"] } -[target.'cfg(target_arch = "wasm32")'.dependencies.getrandom] -version = "0.2.7" -features = ["js"] \ No newline at end of file + +# [target.'cfg(target_arch = "wasm32")'.dependencies.getrandom] +# version = "0.2.7" +# features = ["js"] + +# [target.'cfg(target_arch = "wasm32")'.dependencies] +# wasm-bindgen-futures = "0.4.34" + +[dev-dependencies] +wasm-bindgen-test = "^0.3" \ No newline at end of file diff --git a/ng-app-js/README.md b/ng-app-js/README.md index 20a20b1..6ac6f73 100644 --- a/ng-app-js/README.md +++ b/ng-app-js/README.md @@ -50,6 +50,18 @@ cd pkg-node // npm publish --access=public ``` +For testing in vanilla JS +``` +wasm-pack build --target web -d web +python3 -m http.server +// open http://localhost:8000 + +``` +Or automated testing with headless chrome: +``` +wasm-pack test --chrome --headless +``` + ### Plain JS web app ``` diff --git a/ng-app-js/index.html b/ng-app-js/index.html index b18814f..9ea7cdd 100644 --- a/ng-app-js/index.html +++ b/ng-app-js/index.html @@ -18,7 +18,7 @@

run python3 -m http.server to use it