Skip to content

Commit

Permalink
tokio blocks wasm-unknown-unknown & ∴ wasm-pack & wasm-bindgen
Browse files Browse the repository at this point in the history
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 rustwasm/wasm-bindgen#3421
probably no big deal and other tools will work, this was just the first resource I tried
  • Loading branch information
sneurlax committed Oct 13, 2024
1 parent dddd3e3 commit ef9d5ec
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "www"]
path = www
url = [email protected]:ManyMath/create-wasm-app
6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "monero-wasm"
version = "0.0.1"
authors = ["sneurlax <[email protected]>"]
edition = "2018"
edition = "2021"

[lib]
crate-type = ["cdylib", "rlib"]
Expand All @@ -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"]
21 changes: 20 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
mod utils;

use monero_rust::{MoneroWallet, Language, Network};
use wasm_bindgen::prelude::*;

#[wasm_bindgen]
Expand All @@ -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());
}
1 change: 1 addition & 0 deletions www
Submodule www added at 553175

0 comments on commit ef9d5ec

Please sign in to comment.