From ef9d5ec6229bf7e1530f521c4865baabf5396d9d Mon Sep 17 00:00:00 2001 From: sneurlax Date: Sat, 12 Oct 2024 19:51:16 -0500 Subject: [PATCH] =?UTF-8?q?tokio=20blocks=20wasm-unknown-unknown=20&=20?= =?UTF-8?q?=E2=88=B4=20wasm-pack=20&=20wasm-bindgen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit web takeaway for the day: tokio doesn't support wasm32-unknown-unknown. will have to use wasm32-unknown-wasi, which tokio supports. i don't think wasm32-unknown-emscripten is going to help so: skip the wasm-pack and wasm-bindgen crates, which use wasm32-unknown-unknown see https://github.com/rustwasm/wasm-bindgen/issues/3421 probably no big deal and other tools will work, this was just the first resource I tried --- .gitmodules | 3 +++ Cargo.toml | 6 +++++- src/lib.rs | 21 ++++++++++++++++++++- www | 1 + 4 files changed, 29 insertions(+), 2 deletions(-) create mode 160000 www diff --git a/.gitmodules b/.gitmodules index e69de29..0e05201 100644 --- a/.gitmodules +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "www"] + path = www + url = git@github.com:ManyMath/create-wasm-app diff --git a/Cargo.toml b/Cargo.toml index 1c67d38..ece112e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ name = "monero-wasm" version = "0.0.1" authors = ["sneurlax "] -edition = "2018" +edition = "2021" [lib] crate-type = ["cdylib", "rlib"] @@ -28,3 +28,7 @@ wasm-bindgen-test = "0.3.34" [profile.release] # Tell `rustc` to optimize for small code size. opt-level = "s" + +[target.'cfg(target_arch = "wasm32")'.dependencies.getrandom] +version = "0.2.15" +features = ["js"] diff --git a/src/lib.rs b/src/lib.rs index e94a431..a3e0271 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,6 @@ mod utils; +use monero_rust::{MoneroWallet, Language, Network}; use wasm_bindgen::prelude::*; #[wasm_bindgen] @@ -9,5 +10,23 @@ extern "C" { #[wasm_bindgen] pub fn greet() { - alert("Hello, monero-wasm!"); + // Generate a mnemonic seed in English + let mnemonic = MoneroWallet::generate_mnemonic(Language::English); + println!("Generated mnemonic: {}", mnemonic); + + let mut primary_address = String::new(); + // Create a wallet from the mnemonic + match MoneroWallet::new(&mnemonic, Network::Mainnet) { + Ok(wallet) => { + // Get the primary address of the wallet + primary_address = wallet.get_primary_address(); + println!("Primary address: {}", primary_address); + } + Err(e) => { + eprintln!("Failed to create wallet: {}", e); + } + } + + let message = format!("{}: {}", &mnemonic, &primary_address); + alert(message.as_str()); } diff --git a/www b/www new file mode 160000 index 0000000..5531752 --- /dev/null +++ b/www @@ -0,0 +1 @@ +Subproject commit 55317529ec535b93c04a161a23910658f290bee3