Skip to content

Commit

Permalink
Merge branch 'main' into wasm-action
Browse files Browse the repository at this point in the history
  • Loading branch information
dariusc93 authored Jun 21, 2024
2 parents ed55a0c + e39eb14 commit ed3b2a3
Show file tree
Hide file tree
Showing 95 changed files with 4,872 additions and 2,335 deletions.
26 changes: 24 additions & 2 deletions .github/workflows/cargo-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ jobs:
- name: Catch common mistakes and unwrap calls
run: cargo clippy -- -D warnings

test:
name: Test
test-native:
name: Test (Native)
runs-on: ubuntu-latest
env:
RUSTFLAGS: -D warnings
Expand All @@ -45,3 +45,25 @@ jobs:
toolchain: stable
- uses: Swatinem/rust-cache@v2
- run: cargo test

test-wasm:
name: Check (WASM)
runs-on: ubuntu-latest
env:
RUSTFLAGS: -D warnings
RUST_BACKTRACE: full
steps:
- uses: actions/checkout@v4

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y build-essential pkg-config libssl-dev
sudo apt-get install -y librust-alsa-sys-dev libxdo-dev llvm-dev cmake libudev-dev
- uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
target: wasm32-unknown-unknown
- uses: Swatinem/rust-cache@v2
- run: cargo check -p warp-ipfs -p warp --target wasm32-unknown-unknown
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ Cargo.lock

*.csv

# Compiled wasm
www/wasm
# Built wasm files
built-wasm/
6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ members = [
"extensions/*",
"warp",
"tools/*",
"extensions/warp-ipfs/shuttle",
"extensions/warp-ipfs/examples/wasm-ipfs-identity",
"extensions/warp-ipfs/examples/wasm-ipfs-friends",
"extensions/warp-ipfs/examples/wasm-ipfs-storage",
]
exclude = ["deprecated/*", "tools/opencv-test", "tools/video-codec-cli"]

Expand Down Expand Up @@ -69,6 +71,7 @@ chrono = { version = "~0.4.27", default-features = false, features = [
serde = { version = "1.0", features = ["derive", "rc"] }
serde_json = { version = "1.0" }
serde_cbor = "0.11.2"
cbor4ii = { version = "0.3.2", features = ["serde1", "use_std"] }
serde_yaml = "0.9"
toml = "0.5"
bs58 = "0.4"
Expand All @@ -90,7 +93,7 @@ tracing = { version = "0.1" }
either = "1"
void = "1"

#ipfs dependency
# ipfs dependency
rust-ipfs = "0.11.18"

# wasm crates
Expand All @@ -102,6 +105,7 @@ console_error_panic_hook = "0.1.7"
wasm-streams = "0.4"
wasm-bindgen-futures = "0.4"
serde-wasm-bindgen = "0.4"
send_wrapper = "0.6.0"

# Blink related crates
# av-data is needed to use libaom. need to ensure that Warp and libaom use the same version of av-data
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ outside of localhost.
| Rust | `curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs \| sh` |
| CMake | `brew install cmake` |

## Building to WASM and using it within the browser
## Usage

[See wasm docs](./tools/wasm-example/README.md)
[See warp-ipfs examples](./extensions/warp-ipfs/examples/README.md)

## Docs

Expand Down
2 changes: 1 addition & 1 deletion extensions/warp-blink-wrtc/src/blink_impl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl BlinkImpl {
tokio::spawn(async move {
let f = async move {
let identity = loop {
if let Ok(identity) = account.get_own_identity().await {
if let Ok(identity) = account.identity().await {
break identity;
}
tokio::time::sleep(Duration::from_millis(100)).await
Expand Down
10 changes: 9 additions & 1 deletion extensions/warp-ipfs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ crate-type = ["cdylib", "rlib", "staticlib"]
warp.workspace = true

futures-timeout.workspace = true
cbor4ii.workspace = true
rust-ipfs = { workspace = true, features = ["webrtc_transport", "experimental_stream"] }
libipld.workspace = true
uuid = { workspace = true, features = ["serde", "v4"] }
Expand Down Expand Up @@ -38,14 +39,16 @@ mediatype.workspace = true
bincode.workspace = true
bytes.workspace = true

shuttle = { path = "../../tools/shuttle", default-features = false }
fs = { path = "../../tools/fs", default-features = false }

tokio-util = { workspace = true }
tokio-stream = { workspace = true }

web-time = "1.1.0"

base64 = "0.21"


[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
tokio = { workspace = true }
futures-timer = { workspace = true }
Expand All @@ -71,6 +74,11 @@ clap = { version = "4.0", features = ["derive"] }

rpassword = "7.3"

# crates for examples
tiny_file_server = "0.1.5"

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

[features]
default = []
Expand Down
50 changes: 50 additions & 0 deletions extensions/warp-ipfs/examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Examples

Example usages of warp-ipfs

## Using from Rust (desktop)

CLI for interacting with Multipass (identity):
```
cargo run --example identity-interface
```

Basic ipfs setup example:
```
cargo run --example ipfs-example
```

Basic friends example:
```
cargo run --example ipfs-friends
```

Basic identity example:
```
cargo run --example ipfs-identity
```

CLI for interacting with Constellation (file management):
```
cargo run --example ipfs-persisent
```

CLI messenger example:
```
cargo run --example messenger
```

## Using from Rust (WASM)

[wasm-ipfs-friends](./wasm-ipfs-friends/README.md)

[wasm-ipfs-identity](./wasm-ipfs-identity/README.md)

[wasm-ipfs-storage](./wasm-ipfs-storage/README.md)

## Using from Javascript

Serves web files that contain examples of javascript calling into wasm built from `warp-ipfs`:
```
cargo run --example from-js
```
55 changes: 55 additions & 0 deletions extensions/warp-ipfs/examples/from-js.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
use std::process::Command;
use tiny_file_server::FileServer;
use tracing_subscriber::{filter::LevelFilter, EnvFilter};

const ADDR: &str = "127.0.0.1:9080";
const PATH: &str = "extensions/warp-ipfs/examples/from-js";

fn main() {
//set up logger so we can get an output from tiny_file_server
tracing_subscriber::fmt()
.with_env_filter(
EnvFilter::builder()
.with_default_directive(LevelFilter::INFO.into())
.from_env_lossy(),
)
.init();

println!("\nInstalling wasm-pack ...");
let cmd = get_cmd("cargo install wasm-pack");
spawn_and_wait(cmd);

println!("\nBuilding warp-ipfs wasm files ...");
let cmd = get_cmd("wasm-pack build extensions/warp-ipfs --target web --out-dir examples/from-js/built-wasm/warp-ipfs");
spawn_and_wait(cmd);

println!("\nStarting file server ...");
FileServer::http(ADDR)
.expect("Server should be created")
.run(PATH)
.expect("Server should start");
}

// assumes all spaces are argument separators. args containing spaces will yield unexpected results (such as strings)
fn get_cmd(cmd_str: &str) -> Command {
let mut split = cmd_str.split(' ');

// first item is the program, then the rest of the items are the args
let mut cmd = Command::new(split.next().unwrap());
for arg in split {
cmd.arg(arg);
}
cmd
}

fn spawn_and_wait(mut cmd: Command) {
let status = cmd
.spawn()
.expect("command failed to start")
.wait()
.expect("failed to get ExitStatus");

if !status.success() {
panic!("cmd ExitStatus not successful");
};
}
Binary file added extensions/warp-ipfs/examples/from-js/circle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
<body>
<h1>WASM Examples:</h1>
<ul>
<li><a href="./basic-wasm.html">basic-wasm</a></li>
<li><a href="./tesseract.html">tesseract</a></li>
<li><a href="./ipfs-identity.html">ipfs-identity</a></li>
<li><a href="./ipfs-friends.html">ipfs-friends</a></li>
<li><a href="./ipfs-raygun.html">ipfs-raygun</a></li>
<li><a href="./ipfs-persistent.html">ipfs-persistent</a></li>
</ul>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,20 @@
<title>Warp Wasm Test</title>
</head>
<script type="module">
import init, * as wasm from './wasm/warp-ipfs/warp_ipfs.js';
import init, * as wasm from './built-wasm/warp-ipfs/warp_ipfs.js';
init().then(async (_exports) => {
console.log(wasm)

async function account(username) {
let tesseract = new wasm.Tesseract()
tesseract.load_from_storage()

const passphrase = new Uint8Array([1,2,3,4,5,6,7,8,9,0]);
tesseract.unlock(passphrase)

let ipfs = await new wasm.WarpIpfs(wasm.Config.minimal_testing(), tesseract)
let ipfs = await new wasm.WarpIpfs(wasm.Config.minimal_testing(), null)

let multipass = ipfs.multipass

let tesseract = multipass.tesseract()

const passphrase = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 0]);
tesseract.unlock(passphrase)

let profile = await multipass.create_identity(username, null)

return multipass
Expand All @@ -38,8 +37,8 @@
let asynciterator_b = await account_b.multipass_subscribe()
let subscribe_b = { [Symbol.asyncIterator]() { return asynciterator_b } }

let identity_a = await account_a.get_own_identity()
let identity_b = await account_b.get_own_identity()
let identity_a = await account_a.identity()
let identity_b = await account_b.identity()

console.log(`${username(identity_a)} with ${identity_a.did_key()}` )
console.log(`${username(identity_b)} with ${identity_b.did_key()}` )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,22 @@
<title>Warp Wasm Test</title>
</head>
<script type="module">
import init, * as wasm from './wasm/warp-ipfs/warp_ipfs.js';
import init, * as wasm from './built-wasm/warp-ipfs/warp_ipfs.js';
init().then(async (_exports) => {
console.log(wasm)

let tesseract = new wasm.Tesseract()
tesseract.load_from_storage()
console.log(`loaded data`)

const passphrase = new Uint8Array([1,2,3,4,5,6,7,8,9,0]);
tesseract.unlock(passphrase)
console.log(`unlocked`)

let ipfs = await new wasm.WarpIpfs(wasm.Config.minimal_testing(), tesseract)
let ipfs = await new wasm.WarpIpfs(wasm.Config.minimal_testing(), null)
console.log(ipfs)

let multipass = ipfs.multipass
console.log(multipass)

let tesseract = multipass.tesseract()

const passphrase = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 0]);
tesseract.unlock(passphrase)
console.log(`unlocked`)

//let identity = await multipass.create_identity("username", "crop cash unable insane eight faith inflict route frame loud box vibrant")
let profile = await multipass.create_identity(null, null)
console.log(profile)
Expand All @@ -45,7 +43,7 @@
await multipass.update_identity(wasm.IdentityUpdate.Username, wasm.generate_name())
await multipass.update_identity(wasm.IdentityUpdate.StatusMessage, "New status message")

let updated_identity = await multipass.get_own_identity()
let updated_identity = await multipass.identity()
console.log(`Done updating identity:`)
log_identity(updated_identity)

Expand Down
Loading

0 comments on commit ed3b2a3

Please sign in to comment.