build: experimental build with node package

This commit is contained in:
鲁树人
2024-09-03 00:17:54 +01:00
parent d51cfae9c2
commit 3f9d4b5084
24 changed files with 732 additions and 1 deletions

1
um_wasm/.gitignore vendored
View File

@@ -3,4 +3,5 @@
Cargo.lock
bin/
pkg/
pkg_*/
wasm-pack.log

View File

@@ -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
View 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())
}

View 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)
}

View File

@@ -0,0 +1 @@
pub mod kuwo;

View File

@@ -1,3 +1,5 @@
mod errors;
pub mod exports;
mod utils;
use utils::set_panic_hook;