mirror of
https://git.um-react.app/um/lib_um_crypto_rust.git
synced 2026-03-07 20:19:51 +00:00
build: experimental build with node package
This commit is contained in:
1
um_wasm/.gitignore
vendored
1
um_wasm/.gitignore
vendored
@@ -3,4 +3,5 @@
|
||||
Cargo.lock
|
||||
bin/
|
||||
pkg/
|
||||
pkg_*/
|
||||
wasm-pack.log
|
||||
|
||||
@@ -3,6 +3,9 @@ name = "um_wasm"
|
||||
version = "0.1.0"
|
||||
authors = ["鲁树人 <lu.shuren@um-react.app>"]
|
||||
edition = "2018"
|
||||
description = "um_crypo in WebAssembly"
|
||||
repository = "https://git.unlock-music.dev/lsr/lib_um_crypto_rust.git"
|
||||
license = "Apache-2.0 + MIT"
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib", "rlib"]
|
||||
@@ -12,6 +15,7 @@ default = ["console_error_panic_hook"]
|
||||
|
||||
[dependencies]
|
||||
wasm-bindgen = "0.2.84"
|
||||
anyhow = "1.0.86"
|
||||
|
||||
# The `console_error_panic_hook` crate provides better debugging of panics by
|
||||
# logging them with `console.error`. This is great for development, but requires
|
||||
|
||||
22
um_wasm/src/errors.rs
Normal file
22
um_wasm/src/errors.rs
Normal file
@@ -0,0 +1,22 @@
|
||||
use wasm_bindgen::JsError;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct WasmError {
|
||||
error: anyhow::Error,
|
||||
}
|
||||
|
||||
impl From<anyhow::Error> for WasmError {
|
||||
fn from(err: anyhow::Error) -> WasmError {
|
||||
WasmError { error: err }
|
||||
}
|
||||
}
|
||||
|
||||
impl From<WasmError> for JsError {
|
||||
fn from(error: WasmError) -> Self {
|
||||
JsError::new(&error.error.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn map_js_error(error: anyhow::Error) -> wasm_bindgen::JsError {
|
||||
JsError::new(&error.to_string())
|
||||
}
|
||||
9
um_wasm/src/exports/kuwo.rs
Normal file
9
um_wasm/src/exports/kuwo.rs
Normal file
@@ -0,0 +1,9 @@
|
||||
use crate::errors::map_js_error;
|
||||
use wasm_bindgen::prelude::wasm_bindgen;
|
||||
use wasm_bindgen::JsError;
|
||||
|
||||
#[wasm_bindgen(js_name=kuwoDecodeEKey)]
|
||||
pub fn decode_ekey(ekey: &str) -> Result<String, JsError> {
|
||||
let ekey = umc_kuwo::des::decode_ekey(ekey, &umc_kuwo::SECRET_KEY).map_err(map_js_error)?;
|
||||
Ok(ekey)
|
||||
}
|
||||
1
um_wasm/src/exports/mod.rs
Normal file
1
um_wasm/src/exports/mod.rs
Normal file
@@ -0,0 +1 @@
|
||||
pub mod kuwo;
|
||||
@@ -1,3 +1,5 @@
|
||||
mod errors;
|
||||
pub mod exports;
|
||||
mod utils;
|
||||
|
||||
use utils::set_panic_hook;
|
||||
|
||||
Reference in New Issue
Block a user