Skip to content

Commit

Permalink
Merge pull request #15 from freenet/web-container-contract
Browse files Browse the repository at this point in the history
Web container contract
  • Loading branch information
sanity authored Jan 19, 2025
2 parents 6626a72 + e9e9bfd commit a525a56
Show file tree
Hide file tree
Showing 14 changed files with 744 additions and 72 deletions.
41 changes: 22 additions & 19 deletions .github/workflows/dioxus-build.yml → .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
name: Dioxus Build
name: Build

on:
push:
branches: [ "**" ] # Run on all branches
pull_request:
push:
branches:
- main
- master
- develop
- 'releases/**'

env:
CARGO_TERM_COLOR: always
Expand All @@ -17,23 +21,12 @@ jobs:
with:
submodules: recursive

- name: Verify submodule
run: |
ls -la stdlib/
ls -la stdlib/rust/
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: wasm32-unknown-unknown

- name: Install cargo-make
uses: actions-rs/cargo@v1
with:
command: install
args: --force cargo-make

- name: Cache cargo registry
- name: Cache cargo
uses: actions/cache@v3
with:
path: |
Expand All @@ -43,14 +36,24 @@ jobs:
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-
- name: Cache Dioxus CLI
- name: Cache cargo-make
uses: actions/cache@v3
with:
path: ~/.cargo/bin/dx
key: ${{ runner.os }}-dioxus-cli
path: ~/.cargo/bin/cargo-make
key: ${{ runner.os }}-cargo-make

- name: Install cargo-make
uses: actions-rs/cargo@v1
with:
command: install
args: --force cargo-make

- name: Install cargo-binstall
uses: taiki-e/install-action@cargo-binstall

- name: Install Dioxus CLI
run: cargo install dioxus-cli --force
run: cargo binstall -y dioxus-cli

- name: Build Project
run: cargo make build
54 changes: 54 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Test

on:
pull_request:
push:
branches:
- main
- master
- develop
- 'releases/**'

env:
CARGO_TERM_COLOR: always

jobs:
test:
runs-on: freenet-default-runner

steps:
- uses: actions/checkout@v3
with:
submodules: recursive

- name: Install Rust
uses: dtolnay/rust-toolchain@stable

- name: Cache cargo
uses: actions/cache@v3
with:
path: |
~/.cargo/registry
~/.cargo/git
target/
key: ${{ runner.os }}-cargo-test-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-test-
- name: Cache cargo-make
uses: actions/cache@v3
with:
path: ~/.cargo/bin/cargo-make
key: ${{ runner.os }}-cargo-make

- name: Install cargo-make
uses: actions-rs/cargo@v1
with:
command: install
args: --force cargo-make

- name: Install cargo-binstall
uses: taiki-e/install-action@cargo-binstall

- name: Run Tests
run: cargo make test
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
contracts/

# Generated by Cargo
# will have compiled files and executables
debug/
Expand Down
2 changes: 2 additions & 0 deletions .idea/river.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

57 changes: 26 additions & 31 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ members = [
"common",
"ui",
"contracts/room-contract",
"contracts/web-container-contract",
"scaffold",
"scaffold-macro",
]
Expand All @@ -17,14 +18,14 @@ serde = { version = "1.0.130", features = ["derive"] }
ed25519-dalek = { version = "2.1.1", features = ["serde", "rand_core"] }
blake3 = { version = "1.5.3", features = ["serde"] }
x25519-dalek = { version = "2.0.0", features = ["static_secrets"] }
curve25519-dalek = "4.1.3"
curve25519-dalek = { version = "4.1.3" }
sha2 = "0.10.8"
aes-gcm = "0.11.0-pre.2"

# Utilities
itertools = "0.13.0"
rand = "0.8.5"
getrandom = { version = "0.2.15", features = ["js"] }
rand = { version = "0.8.5", features = ["getrandom"] }
getrandom = { version = "0.2.15", features = ["js", "wasm-bindgen"], default-features = false }
base64 = "0.22.1"
once_cell = "1.18.0"
data-encoding = "2.3.3"
Expand All @@ -40,6 +41,7 @@ wasm-bindgen-futures = "0.4.43"
common = { path = "common", package = "river-common" }
freenet-scaffold = { path = "scaffold" }
freenet-scaffold-macro = { path = "scaffold-macro" }
freenet-stdlib = { path = "stdlib/rust", features = ["contract"] }

[workspace.package]
version = "0.1.0"
Expand Down
39 changes: 36 additions & 3 deletions Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ default_to_workspace = false

[env]
CARGO_MAKE_EXTEND_WORKSPACE_MAKEFILE = true
CARGO_MAKE_WORKSPACE_INCLUDE_MEMBERS = ["contracts/room-contract", "ui"]
CARGO_MAKE_WORKSPACE_INCLUDE_MEMBERS = ["contracts/room-contract", "contracts/web-container-contract", "ui"]
CONTRACT_TARGET = "wasm32-unknown-unknown"
CONTRACT_NAME = "room_contract"
BUILD_PROFILE = "release"
Expand All @@ -16,15 +16,24 @@ description = "Clean build artifacts"
command = "cargo"
args = ["clean"]

[tasks.build-contract]
[tasks.build-room-contract]
description = "Build the room contract WASM"
command = "cargo"
args = ["build", "--profile", "${BUILD_PROFILE}", "--target", "${CONTRACT_TARGET}", "-p", "room-contract", "--target-dir", "target"]

[tasks.build-web-container]
description = "Build the web container contract WASM"
command = "cargo"
args = ["build", "--profile", "${BUILD_PROFILE}", "--target", "${CONTRACT_TARGET}", "-p", "web-container-contract", "--target-dir", "target"]

[tasks.build-contracts]
description = "Build all contracts"
dependencies = ["build-room-contract", "build-web-container"]


[tasks.build-ui]
description = "Build the Dioxus UI"
dependencies = ["build-contract"]
dependencies = ["build-contracts"]
command = "dx"
args = ["build", "--${BUILD_PROFILE}", "--features", "${UI_FEATURES}"]
cwd = "./ui"
Expand Down Expand Up @@ -53,6 +62,30 @@ command = "dx"
args = ["build", "--${BUILD_PROFILE}", "--features", "${UI_FEATURES}"]
cwd = "./ui"

[tasks.test-web-container]
description = "Run tests for web-container-contract"
command = "cargo"
args = ["test", "--package", "web-container-contract", "--target-dir", "target/native", "--target", "x86_64-unknown-linux-gnu"]

[tasks.test-room-contract]
description = "Run tests for room-contract"
command = "cargo"
args = ["test", "--package", "room-contract", "--target-dir", "target/native", "--target", "x86_64-unknown-linux-gnu"]

[tasks.test-scaffold]
description = "Run tests for scaffold crate"
command = "cargo"
args = ["test", "--package", "freenet-scaffold", "--target-dir", "target/native", "--target", "x86_64-unknown-linux-gnu"]

[tasks.test-common]
description = "Run tests for common crate"
command = "cargo"
args = ["test", "--package", "river-common", "--target-dir", "target/native", "--target", "x86_64-unknown-linux-gnu"]

[tasks.test]
description = "Run all tests"
dependencies = ["test-web-container", "test-room-contract", "test-scaffold", "test-common"]

[tasks.build]
description = "Build everything in release mode (optimized)"
dependencies = ["build-ui"]
Expand Down
7 changes: 5 additions & 2 deletions common/src/room_state/member_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,11 @@ impl ComposableState for MemberInfoV1 {
if *member_id == parameters.owner_id() {
// If it's the owner, verify against the room owner's key
member_info.verify_signature(parameters)?;
} else if let Some(member) = parent_state.members.members_by_member_id().get(member_id) {
// For non-owners, verify against their member key
} else {
// For non-owners, verify they exist and check their signature
let members = parent_state.members.members_by_member_id();
let member = members.get(member_id)
.ok_or_else(|| format!("MemberInfo exists for non-existent member: {:?}", member_id))?;
member_info.verify_signature_with_key(&member.member.member_vk)?;
}

Expand Down
24 changes: 13 additions & 11 deletions contracts/room-contract/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,20 @@ version = "0.1.0"
edition = "2021"

[dependencies]
common.workspace = true
ciborium.workspace = true
getrandom.workspace = true
freenet-scaffold = { path = "../../scaffold" }
freenet-stdlib = { path = "../../stdlib/rust", features = ["contract"] }
serde.workspace = true
ed25519-dalek.workspace = true
rand.workspace = true
freenet-stdlib.workspace = true
freenet-scaffold.workspace = true
common.workspace = true
getrandom = { workspace = true, features = ["js", "wasm-bindgen"], default-features = false }

[lib]
crate-type = ["cdylib"]

[profile.release]
lto = true
opt-level = 'z'
panic = 'abort'
strip = true
crate-type = ["cdylib", "rlib"]

[features]
default = ["freenet-main-contract"]
contract = ["freenet-stdlib/contract"]
freenet-main-contract = []
trace = ["freenet-stdlib/trace"]
3 changes: 3 additions & 0 deletions contracts/room-contract/wasm32-unknown-unknown/CACHEDIR.TAG
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Signature: 8a477f597d28d172789f06886806bc55
# This file is a cache directory tag created by cargo.
# For information about cache directory tags see https://bford.info/cachedir/
Loading

0 comments on commit a525a56

Please sign in to comment.