update sth
This commit is contained in:
parent
7e4bc1a637
commit
a7b0501896
@ -23,11 +23,10 @@ cargo install cargo-expand
|
|||||||
cargo install cargo-edit
|
cargo install cargo-edit
|
||||||
cargo install cargo-ndk
|
cargo install cargo-ndk
|
||||||
cargo install cargo-lipo
|
cargo install cargo-lipo
|
||||||
|
cargo install wasm-pack
|
||||||
rustup target add aarch64-linux-android armv7-linux-androideabi i686-linux-android x86_64-linux-android
|
rustup target add aarch64-linux-android armv7-linux-androideabi i686-linux-android x86_64-linux-android
|
||||||
rustup target add aarch64-apple-ios x86_64-apple-ios
|
rustup target add aarch64-apple-ios x86_64-apple-ios
|
||||||
|
|
||||||
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
|
|
||||||
|
|
||||||
|
|
||||||
## setup and install oh-my-zsh
|
## setup and install oh-my-zsh
|
||||||
sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
|
sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
|
||||||
|
@ -24,6 +24,6 @@ shamir_secret_sharing = "0.1.1"
|
|||||||
tiny-keccak = "1.5"
|
tiny-keccak = "1.5"
|
||||||
primitive-types = "0.12.1"
|
primitive-types = "0.12.1"
|
||||||
getrandom = { version = "0.2.7", features = ["js"]}
|
getrandom = { version = "0.2.7", features = ["js"]}
|
||||||
[target.'cfg(target_arch = "wasm32")'.dependencies]
|
#[target.'cfg(target_arch = "wasm32")'.dependencies]
|
||||||
wasm-bindgen = "0.2.83"
|
wasm-bindgen = "0.2.83"
|
||||||
|
|
||||||
|
@ -10,6 +10,12 @@ typedef struct CWallet {
|
|||||||
char *backup_key;
|
char *backup_key;
|
||||||
} CWallet;
|
} CWallet;
|
||||||
|
|
||||||
|
extern void log(const str *s);
|
||||||
|
|
||||||
|
extern void log_u32(uint32_t a);
|
||||||
|
|
||||||
|
extern void log_many(const str *a, const str *b);
|
||||||
|
|
||||||
struct CWallet new_wallet(const char *msg);
|
struct CWallet new_wallet(const char *msg);
|
||||||
|
|
||||||
struct CWallet reset_wallet(const char *msg_key,
|
struct CWallet reset_wallet(const char *msg_key,
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
cargo install --force cbindgen
|
||||||
# install cargo-ndk
|
# install cargo-ndk
|
||||||
cargo install cargo-ndk
|
cargo install cargo-ndk
|
||||||
# install cargo-lipo
|
# install cargo-lipo
|
||||||
|
40
src/lib.rs
40
src/lib.rs
@ -84,6 +84,30 @@ pub struct CWallet {
|
|||||||
pub backup_key: *mut c_char,
|
pub backup_key: *mut c_char,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[wasm_bindgen]
|
||||||
|
extern "C" {
|
||||||
|
// Use `js_namespace` here to bind `console.log(..)` instead of just
|
||||||
|
// `log(..)`
|
||||||
|
#[wasm_bindgen(js_namespace = console)]
|
||||||
|
fn log(s: &str);
|
||||||
|
|
||||||
|
// The `console.log` is quite polymorphic, so we can bind it with multiple
|
||||||
|
// signatures. Note that we need to use `js_name` to ensure we always call
|
||||||
|
// `log` in JS.
|
||||||
|
#[wasm_bindgen(js_namespace = console, js_name = log)]
|
||||||
|
fn log_u32(a: u32);
|
||||||
|
|
||||||
|
// Multiple arguments too!
|
||||||
|
#[wasm_bindgen(js_namespace = console, js_name = log)]
|
||||||
|
fn log_many(a: &str, b: &str);
|
||||||
|
}
|
||||||
|
|
||||||
|
macro_rules! console_log {
|
||||||
|
// Note that this is using the `log` function imported above during
|
||||||
|
// `bare_bones`
|
||||||
|
($($t:tt)*) => (log(&format_args!($($t)*).to_string()))
|
||||||
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn new_wallet(msg: *const c_char) -> CWallet {
|
pub unsafe extern "C" fn new_wallet(msg: *const c_char) -> CWallet {
|
||||||
let str = cchar_to_str!(msg);
|
let str = cchar_to_str!(msg);
|
||||||
@ -113,7 +137,6 @@ pub unsafe extern "C" fn free_cwallet(cw: CWallet) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
#[wasm_bindgen]
|
|
||||||
pub unsafe extern "C" fn get_address(
|
pub unsafe extern "C" fn get_address(
|
||||||
msg_key: *const c_char,
|
msg_key: *const c_char,
|
||||||
master_key: *const c_char,
|
master_key: *const c_char,
|
||||||
@ -127,6 +150,21 @@ pub unsafe extern "C" fn get_address(
|
|||||||
c_address.into_raw()
|
c_address.into_raw()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[wasm_bindgen]
|
||||||
|
pub fn wget_address(msg_key: String, master_key: String, second_key: Option<String>, backup_key: Option<String>) -> String {
|
||||||
|
console_log!("wget_address: {}, {}!", msg_key, master_key);
|
||||||
|
let rwallet = Wallet{
|
||||||
|
msg_key,
|
||||||
|
master_key,
|
||||||
|
second_key,
|
||||||
|
backup_key
|
||||||
|
};
|
||||||
|
console_log!("wallet: {:?}", rwallet);
|
||||||
|
let address = rwallet.get_address();
|
||||||
|
let address_str = format!("{:?}", address);
|
||||||
|
address_str
|
||||||
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn generate_sec_key(
|
pub unsafe extern "C" fn generate_sec_key(
|
||||||
msg_key: *const c_char,
|
msg_key: *const c_char,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user