Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add getrandom js feature and wasm dependencies #43

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 104 additions & 5 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
resolver = "2"
members = [ "crates/bindings",
"crates/cli"
, "crates/metaboard"]
, "crates/metaboard", "crates/metadata_wasm"]

[workspace.dependencies]
reqwest = { version = "0.11.17", features = ["json"] }
Expand Down
21 changes: 21 additions & 0 deletions crates/metadata_wasm/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[package]
name = "metadata_wasm"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

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


[dependencies]
serde = { version = "1.0", features = ["derive"] }
serde_cbor = "0.11"
hex = "0.4.3"
wasm-bindgen = "0.2"
js-sys = "0.3"
rain-metadata = "0.0.2-alpha.6"
serde_bytes = "0.11.12"
serde-wasm-bindgen = "0.4"
wasm-bindgen-futures = "0.4"
22 changes: 22 additions & 0 deletions crates/metadata_wasm/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use wasm_bindgen::prelude::*;
use rain_metadata::meta::{
RainMetaDocumentV1Item };
use serde_wasm_bindgen::to_value;

#[wasm_bindgen]
pub fn cbor_decode_wasm(data: &[u8]) -> JsValue {
// Decode the data
let cbor_decoded = RainMetaDocumentV1Item::cbor_decode(&data);

// Convert the result to JsValue
match cbor_decoded {
Ok(decoded) => {
let js_value = to_value(&decoded);
match js_value {
Ok(value) => value,
Err(_) => JsValue::from_str("Error converting to JsValue"),
}
}
Err(err) => JsValue::from_str(&format!("CBOR decoding error: {:?}", err)),
}
}
Loading