Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TLS Notary WASM client #75

Merged
merged 33 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
f1d7bf0
make cargo check work under linux
mattes Jul 16, 2024
fceb05a
cargo check succeeds for wasm32 target with websocket flag
mattes Jul 16, 2024
f7a4ea7
bring back package.json and try to run wasm demo
mattes Jul 16, 2024
fcffeba
fix wasm prover config input
mattes Jul 16, 2024
16c7e7b
fix tracing issues
mattes Jul 16, 2024
939e492
fix websocket url,
mattes Jul 16, 2024
4a213e0
add TODOs
mattes Jul 16, 2024
89fb6d2
configure session and receive session_id from notary
mattes Jul 18, 2024
34b3812
include_bytes! notary ca cert
mattes Jul 18, 2024
e799165
connect to correct Websocket Notary and Websocket Proxy
mattes Jul 18, 2024
ea9f3e2
dirty working version
mattes Jul 19, 2024
f600067
cleanup
mattes Jul 19, 2024
829eaf9
remove unstable build-std from .cargo/config.toml
mattes Jul 19, 2024
7f6b293
update build.rs and Makefile
mattes Jul 19, 2024
1edf996
Remove [lib] from Cargo.toml and update make wasm command
mattes Jul 19, 2024
9874d84
update Makefile
mattes Jul 19, 2024
2bfb23d
make wasm demo functional
mattes Jul 19, 2024
22d8f36
make tlsnotary compile
mattes Jul 20, 2024
8cd6459
hardcode config
mattes Jul 20, 2024
100d2f7
remove unused certs
mattes Jul 20, 2024
f824c3e
actually clean up certs even more
mattes Jul 20, 2024
fdd4a3e
move request_notarization into client
mattes Jul 20, 2024
e377458
move routes.rs into proxy to remove cognitive load
mattes Jul 20, 2024
193593f
move wasm_utils into client
mattes Jul 20, 2024
887fdc7
delete wasm-proxy-client dir and move lib.rs into client/mod.rs for now
mattes Jul 20, 2024
d0c764b
move tests to integration_test.rs
mattes Jul 20, 2024
20a7c2e
things are getting interesting
mattes Jul 20, 2024
1b2e64c
wasm and ios crates
mattes Jul 22, 2024
20139d6
new directory layout
mattes Jul 22, 2024
89f164a
tlsnotary is compiling
mattes Jul 22, 2024
2d9dec0
client_wasm compiles with more code
mattes Jul 22, 2024
29e52bd
client::Config and prover_inner
mattes Jul 22, 2024
9639a81
wasm pack builds
mattes Jul 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 0 additions & 21 deletions .cargo/config.toml

This file was deleted.

10 changes: 2 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
/logs/*
webproof.json

# js
package-lock.json

# Generated by Cargo
# will have compiled files and executables
debug/
Expand All @@ -30,9 +27,6 @@ Cargo.lock
.vscode/
.viscode

# transcript
*.json

# env var
*.env

Expand All @@ -54,5 +48,5 @@ dump
*.swo

/target
/wasm-client
node_modules/

Cargo.toml.backup
189 changes: 18 additions & 171 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,182 +1,29 @@
[package]
name ="web-prover"
version="0.1.0"
edition="2021"
build ="build.rs"

[features]
tracing=["dep:tracing", "dep:tracing-subscriber"]
# Should be able to set this up for both wasm and not wasm with the right deps
# May need to default the websocket or something to make this work nicely? Can always turn off defaults for conditional comp
# There are dependencies that should be here like `ws_stream_wasm` and `tokio-tungstenite` but I'm afraid it may be difficult to have them be conditional
websocket=[]
[workspace]
members =["client", "client_ios", "client_wasm"]
resolver="2"

# Crate type is really only needed for wasm, but I don't know how to specify it only for wasm.
[lib]
crate-type=["cdylib", "rlib"]

[[bin]]
name="mock_client"
path="src/bin/mock_client.rs"
[package]
name="webprover"
edition = "2021"

# TODO: merge tlsnotary and origo into one `notary` bin
# TODO: put rust websocket proxy code into tlsnotary and origo
[[bin]]
name="tlsn"
path="src/bin/tlsn.rs"
name="tlsnotary"
path="bin/tlsnotary.rs"

[[bin]]
name="proxy"
path="src/bin/proxy.rs"
name="origo"
path="bin/origo.rs"

[[bin]]
name="mock_target"
path="src/bin/mock_target.rs"
name="mock_server"
path="bin/mock_server.rs"

# Shared build profile for all targets
# This release profile attempts to create the smallest possible binary size
[profile.release]
strip =true
opt-level ="z"
lto =true
codegen-units=1
panic ="unwind" # abort helps decrease file size, but makes the mobile app crash on panic
# Can use something like this for e2e testing of the workspace
# https://doc.rust-lang.org/cargo/reference/manifest.html
# [[test]]

[dependencies]
serde ={ version="1.0.147", features=["derive"] }
serde_json="1.0"

# Web
url ="2.5.0"
hyper ={ version="1.1", features=["client", "http1"] }
http-body-util="0.1"
rustls ={ version="0.23.10" }
rustls-pemfile={ version="2.1.2" }
# Logging and errors
tracing ={ version="0.1", optional=true }
tracing-subscriber={ version="0.3", optional=true }
thiserror ="1.0.61"
# Async
futures ="0.3"
futures-util="0.3.28"
# Other
base64="0.22.0"

anyhow="1.0.86"

# hyper ={ version="1.1", features=["client", "http1", "full"] }
hyper-util={ version="0.1", features=["full"] }
# http-body-util="0.1"

# rustls ={ version="0.23.10" }
# rustls-pemfile={ version="2.0.0" }

tokio-util ="0.7"
tokio-rustls={ version="0.26.0" }
tokio ={ version="1", features=["rt", "rt-multi-thread", "macros", "net", "io-std", "fs"] }

notary-server={ git="https://github.com/tlsnotary/tlsn.git " }
eyre ="0.6.8"
structopt ="0.3.26"

form_urlencoded ="1.2.1"
tokio-tungstenite="0.23.0"

tlsn-prover={ git="https://github.com/tlsnotary/tlsn.git" }
# tlsn-core ={ git="https://github.com/tlsnotary/tlsn.git" }
tlsn-tls-client ={ git="https://github.com/tlsnotary/tlsn.git" }
tlsn-tls-client-async={ git="https://github.com/tlsnotary/tlsn.git" }

webpki-roots="0.26.1"
pki-types ={ package="rustls-pki-types", version="1.7" }

clap={ version="4.5.8", features=["derive"] }

####################################################################################################
# Target-specific configuration
####################################################################################################

#- Non-wasm target configuration ------------------------------------------------------------------#
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
# Web
hyper-util={ version="0.1", features=["full"] }
# Async
tokio-util={ version="0.7", features=[
"compat",
] } # compat is used to work with AsyncRead and AsyncWrite from other crates
tokio-rustls={ version="0.26.0" }
tokio={ version="1", features=["rt", "rt-multi-thread", "macros", "net", "io-std", "fs"] }
# TLSN
tlsn-prover={ git="https://github.com/tlsnotary/tlsn.git" }
tlsn-core ={ git="https://github.com/tlsnotary/tlsn.git" }

#- Wasm target configuration ----------------------------------------------------------------------#
[target.'cfg(target_arch = "wasm32")'.dependencies]
# TLSN
tls-client={ git="https://github.com/tlsnotary/tlsn.git", package="tlsn-tls-client" }
# Web
hyper-util={ version="0.1", features=["http1"] }
## Use the patched ws_stream_wasm to fix the issue https://github.com/najamelan/ws_stream_wasm/issues/12#issuecomment-1711902958
ws_stream_wasm={ version="0.7.4", git="https://github.com/tlsnotary/ws_stream_wasm", rev="2ed12aad9f0236e5321f577672f309920b2aef51" }
# Serde
serde-wasm-bindgen="0.6.5"

# Other
ring ={ version="0.17", features=["wasm32_unknown_unknown_js"] }
chrono ="0.4"
elliptic-curve={ version="0.13.5", features=["pkcs8"] }
getrandom ={ version="0.2", features=["js"] }
js-sys ="0.3.64"
p256 ={ version="0.13", features=["pem", "ecdsa"] }
rayon ="1.5"
# time crate: https://crates.io/crates/time
# NOTE: It is required, otherwise "time not implemented on this platform" error happens right after "!@# 2".
# Probably due to tokio's time feature is used in tlsn-prover?
time={ version="0.3.34", features=["wasm-bindgen"] }
# Used to calculate elapsed time.
web-time="1.0"

web-sys={ version="0.3.4", features=[
"BinaryType",
"Blob",
"ErrorEvent",
"FileReader",
"MessageEvent",
"ProgressEvent",
"WebSocket",
"console",
'Document',
'HtmlElement',
'HtmlInputElement',
'Window',
'Worker',
'Headers',
'Request',
'RequestInit',
'RequestMode',
'Response',
] }

# The `console_error_panic_hook` crate provides better debugging of panics by
# logging them with `console.error`. This is great for development, but requires
# all the `std::fmt` and `std::panicking` infrastructure, so isn't great for
# code size when deploying.
console_error_panic_hook={ version="0.1.7" }

webpki-roots ="0.26.1"
pki-types ={ package="rustls-pki-types", version="1.7" }
pin-project-lite ="0.2.4"
wasm-bindgen ="0.2.87"
wasm-bindgen-futures="0.4.37"
wasm-bindgen-rayon ="1.0"
tracing-subscriber ={ version="0.3", features=["time", "env-filter"] }
tracing-web ="0.1.2"

# TLSN
tlsn-prover={ git="https://github.com/tlsnotary/tlsn.git" }
tlsn-core ={ git="https://github.com/tlsnotary/tlsn.git" }

[target.'cfg(target_arch = "wasm32")'.dev-dependencies]
wasm-bindgen-test="0.3.42"

[package.metadata.wasm-pack.profile.release]
wasm-opt=false
#---------------------------------------------------------------------------------------------#
tokio ={ version="1" }
48 changes: 18 additions & 30 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,50 +1,38 @@
UNAME := $(shell uname -s)
wasm:
cargo install wasm-pack
cd client_wasm && \
RUSTFLAGS="-C target-feature=+atomics,+bulk-memory,+mutable-globals" \
~/.cargo/bin/wasm-pack build --release --target web ./ -- \
-Z build-std=panic_abort,std

ifeq ($(UNAME),Linux)
SED_CMD = sed -i
endif
ifeq ($(UNAME),Darwin)
SED_CMD = sed -i ''
endif
ios:
# TODO

wasm-demo/node_modules:
cd wasm-demo && npm install

wasm-demo: wasm-demo/node_modules
cd wasm-demo && npm run start

libs:
# TODO ios target
-mkdir build
cargo build --release --target aarch64-apple-ios
cargo build --release --target aarch64-apple-ios-sim
cp target/aarch64-apple-ios/release/libtlsnotary.a build/tlsnotary-ios-device.a
cp target/aarch64-apple-ios-sim/release/libtlsnotary.a build/tlsnotary-ios-simulator.a

cbindgen:
# TODO ios target
cbindgen --lang c --crate tlsnotary --output build/tlsnotary.h

xcframework:
# TODO ios target
xcodebuild -create-xcframework \
-library target/aarch64-apple-ios/release/libtlsnotary.a \
-headers ./build/tlsnotary.h \
-library target/aarch64-apple-ios-sim/release/libtlsnotary.a \
-headers ./build/tlsnotary.h \
-output build/tlsnotary.xcframework

.PHONY: libs xcframework cbindgen


CARGO_CONFIG := .cargo/config.toml

switch-to-wasm:
$(SED_CMD) 's/^target="aarch64-apple-ios"/# target="aarch64-apple-ios"/' $(CARGO_CONFIG)
$(SED_CMD) 's/^# target="wasm32-unknown-unknown"/target="wasm32-unknown-unknown"/' $(CARGO_CONFIG)
@echo "Switched to WASM target"
@$(MAKE) restart-rust-analyzer

switch-to-ios:
$(SED_CMD) 's/^target="wasm32-unknown-unknown"/# target="wasm32-unknown-unknown"/' $(CARGO_CONFIG)
$(SED_CMD) 's/^# target="aarch64-apple-ios"/target="aarch64-apple-ios"/' $(CARGO_CONFIG)
@echo "Switched to iOS target"
@$(MAKE) restart-rust-analyzer

restart-rust-analyzer:
@echo "Restarting Rust Analyzer..."
@if pgrep -f "rust-analyzer" > /dev/null; then \
pkill -f "rust-analyzer"; \
fi
@echo "Rust Analyzer has been restarted. You may need to reopen your editor."
.PHONY: wasm wasm-demo ios libs xcframework cbindgen
Loading
Loading