Skip to content

Commit

Permalink
Merge pull request #787 from netsirius/build-and-publish-email-web
Browse files Browse the repository at this point in the history
Build and publish email web
  • Loading branch information
iduartgomez authored Aug 22, 2023
2 parents 5b26878 + 49267e0 commit 3257c3e
Show file tree
Hide file tree
Showing 22 changed files with 904 additions and 1,084 deletions.
557 changes: 230 additions & 327 deletions Cargo.lock

Large diffs are not rendered by default.

726 changes: 229 additions & 497 deletions apps/freenet-email-app/Cargo.lock

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions apps/freenet-email-app/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[workspace]
resolver = "2"
members = ["contracts/*", "delegates/*", "web"]
members = ["contracts/*", "web", "web/container"]

[profile.dev.package."*"]
opt-level = 3
Expand All @@ -15,7 +15,6 @@ strip = true

[workspace.dependencies]
chrono = "0.4"
ed25519-dalek = { version = "1", features = ["serde"], default-features = false }
rsa = { version = "0.9.2", default-features = false, features = ["serde", "pem", "sha2"] }
serde = "1"
serde_json = "1"
Expand Down
18 changes: 15 additions & 3 deletions apps/freenet-email-app/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ endif
build: \
build-tool \
generate-id-manager-key \
build-inbox
build-inbox \
build-webapp \
publish-webapp

build-tool:
cd $(LOCUTUS_DIR)/crates/locutus-node && cargo build --release
Expand All @@ -46,8 +48,18 @@ run-node:

run-web:
cd $(INBOX_WEB_DIR)
trunk build --features use-node --no-default-features
trunk serve --features use-node --no-default-features --port 57616
dx build --target index.html --platform web --features use-node
dx serve --features use-node --port 57616

build-webapp:
cd $(INBOX_WEB_DIR)
dx build --target index.html --release --platform web --features use-node
sed -i 's@/./assets@./assets@g' dist/index.html
ldt build

publish-webapp:
cd $(INBOX_WEB_DIR)
ldt publish --code build/locutus/freenet_email_app_web contract --state build/locutus/contract-state

clean:
rm -rf $(CARGO_TARGET_DIR)
9 changes: 3 additions & 6 deletions apps/freenet-email-app/contracts/inbox/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ impl ContractInterface for Inbox {
let missing_related: Vec<_> = missing_related
.into_iter()
.filter_map(|missing| {
(!allocation_records.contains_key(&missing)).then(|| RelatedContract {
(!allocation_records.contains_key(&missing)).then_some(RelatedContract {
contract_instance_id: missing,
mode: RelatedMode::StateOnce,
})
Expand Down Expand Up @@ -495,14 +495,11 @@ impl ContractInterface for Inbox {
#[cfg(all(feature = "contract", test))]
mod tests {
use super::*;
use rsa::{pkcs1::DecodeRsaPrivateKey, Pkcs1v15Sign, RsaPrivateKey};
use rsa::{rand_core::OsRng, Pkcs1v15Sign, RsaPrivateKey};

#[test]
fn validate_test() -> Result<(), Box<dyn std::error::Error>> {
let private_key = RsaPrivateKey::from_pkcs1_pem(include_str!(
"../../../web/examples/rsa4096-id-1-priv.pem"
))
.unwrap();
let private_key = RsaPrivateKey::new(&mut OsRng, 32).unwrap();
let public_key = private_key.to_public_key();

let params: Parameters = InboxParams {
Expand Down
20 changes: 0 additions & 20 deletions apps/freenet-email-app/delegates/alias-allocation/Cargo.toml

This file was deleted.

21 changes: 0 additions & 21 deletions apps/freenet-email-app/delegates/alias-allocation/src/lib.rs

This file was deleted.

20 changes: 0 additions & 20 deletions apps/freenet-email-app/delegates/identity-management/Cargo.toml

This file was deleted.

13 changes: 0 additions & 13 deletions apps/freenet-email-app/delegates/identity-management/src/lib.rs

This file was deleted.

6 changes: 3 additions & 3 deletions apps/freenet-email-app/web/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ bs58 = "0.5"
arc-swap = "1.6"
rand_chacha = "0.3"
chrono = { workspace = true, features = ["wasmbind"] }
dioxus = { git = "https://github.com/DioxusLabs/dioxus.git", rev = "0fec47d" }
dioxus = "0.4.0"
futures = "0.3"
rsa = { workspace = true }
chacha20poly1305 = "0.10"
Expand All @@ -38,7 +38,7 @@ locutus-aft-interface = { workspace = true }
identity-management = { path = "../../../modules/identity-management" }

[target.'cfg(target_family = "wasm")'.dependencies]
dioxus-web = { git = "https://github.com/DioxusLabs/dioxus.git", rev = "0fec47d" }
dioxus-web = "0.4.0"
getrandom = { version = "*", features = ["js"] }
locutus-stdlib = { workspace = true, features = ["net"] }
serde-wasm-bindgen = { version = "0.5" }
Expand All @@ -58,7 +58,7 @@ features = [
]

[target.'cfg(not(target_family = "wasm"))'.dependencies]
dioxus-desktop = { git = "https://github.com/DioxusLabs/dioxus.git", rev = "0fec47d" }
dioxus-desktop = "0.4.0"

[features]
default = ["ui-testing"]
Expand Down
74 changes: 74 additions & 0 deletions apps/freenet-email-app/web/Dioxus.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
[application]

# dioxus project name
name = "freenet-email-app"

# default platfrom
# you can also use `dx serve/build --platform XXX` to use other platform
# value: web | desktop
default_platform = "web"

# Web `build` & `serve` dist path
out_dir = "dist"

# resource (static) file folder
asset_dir = "public"

[web.app]

# HTML title tag content
title = ""

[web.watcher]

index_on_404 = true

watch_path = ["src"]

# include `assets` in web platform
[web.resource]

# CSS style file
style = []

# Javascript code file
script = []

[web.resource.dev]

# Javascript code file
# serve: [dev-server] only
script = []

[application.plugins]

available = true

required = []

[bundler]
# Bundle identifier
identifier = ""

# Bundle publisher
publisher = ""

# Bundle icon
icon = ["icons/icon.png"]

# Bundle resources
resources = ["public/*"]

# Bundle copyright
copyright = ""

# Bundle category
category = "Utility"

# Bundle short description
short_description = "An amazing dioxus application."

# Bundle long description
long_description = """
An amazing dioxus application.
"""
13 changes: 13 additions & 0 deletions apps/freenet-email-app/web/container/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "freenet-email-app-web"
version = "0.0.0"
edition = "2021"
rust-version = "1.71.1"
resolver = "2"
publish = false

[dependencies]
locutus-stdlib = { workspace = true }

[lib]
crate-type = ["cdylib"]
47 changes: 47 additions & 0 deletions apps/freenet-email-app/web/container/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
use locutus_stdlib::prelude::*;

struct Contract;

// TODO: verify that the state is signed by a pub/key pair
// ~/.locutus/secrets/keys/keypair1.json

#[contract]
impl ContractInterface for Contract {
fn validate_state(
_parameters: Parameters<'static>,
_state: State<'static>,
_related: RelatedContracts,
) -> Result<ValidateResult, ContractError> {
Ok(ValidateResult::Valid)
}

fn validate_delta(
_parameters: Parameters<'static>,
_delta: StateDelta<'static>,
) -> Result<bool, ContractError> {
Ok(true)
}

fn update_state(
_parameters: Parameters<'static>,
state: State<'static>,
_updates: Vec<UpdateData>,
) -> Result<UpdateModification<'static>, ContractError> {
Ok(UpdateModification::valid(state))
}

fn summarize_state(
_parameters: Parameters<'static>,
_state: State<'static>,
) -> Result<StateSummary<'static>, ContractError> {
Ok(StateSummary::from(vec![]))
}

fn get_state_delta(
_parameters: Parameters<'static>,
_state: State<'static>,
_summary: StateSummary<'static>,
) -> Result<StateDelta<'static>, ContractError> {
Ok(StateDelta::from(vec![]))
}
}
8 changes: 8 additions & 0 deletions apps/freenet-email-app/web/locutus.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[contract]
type = "webapp"
lang = "rust"

[webapp]

[webapp.state-sources]
source_dirs = ["dist"]
Loading

0 comments on commit 3257c3e

Please sign in to comment.