diff --git a/Cargo.lock b/Cargo.lock index 34fd775d..7ceaa94d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -471,7 +471,7 @@ dependencies = [ "config", "electrum-client", "hex", - "mercury-lib", + "mercurylib", "rand", "reqwest", "schemars", @@ -803,9 +803,9 @@ checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" [[package]] name = "fastrand" -version = "2.0.2" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "658bd65b1cf4c852a3cc96f18a8ce7b5640f6b703f905c7d74532294c2a63984" +checksum = "9fc0510504f03c51ada170672ac806f1f105a88aa97a5281117e1ddc3368e51a" [[package]] name = "figment" @@ -1043,9 +1043,9 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.14.3" +version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" dependencies = [ "ahash 0.8.11", "allocator-api2", @@ -1057,7 +1057,7 @@ version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e8094feaf31ff591f651a2664fb9cfd92bba7a60ce3197265e9482ebe753c8f7" dependencies = [ - "hashbrown 0.14.3", + "hashbrown 0.14.5", ] [[package]] @@ -1232,7 +1232,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" dependencies = [ "equivalent", - "hashbrown 0.14.3", + "hashbrown 0.14.5", "serde", ] @@ -1460,21 +1460,6 @@ version = "2.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" -[[package]] -name = "mercury-lib" -version = "0.1.0" -dependencies = [ - "anyhow", - "bech32", - "bip39", - "bitcoin", - "ecies", - "hex", - "secp256k1-zkp", - "serde", - "serde_json", -] - [[package]] name = "mercury-server" version = "0.1.0" @@ -1483,7 +1468,7 @@ dependencies = [ "config", "dotenv", "hex", - "mercury-lib", + "mercurylib", "rand", "reqwest", "rocket", @@ -1503,7 +1488,7 @@ dependencies = [ "console_error_panic_hook", "getrandom", "js-sys", - "mercury-lib", + "mercurylib", "rand", "serde", "serde-wasm-bindgen", @@ -1513,6 +1498,21 @@ dependencies = [ "web-sys", ] +[[package]] +name = "mercurylib" +version = "0.1.0" +dependencies = [ + "anyhow", + "bech32", + "bip39", + "bitcoin", + "ecies", + "hex", + "secp256k1-zkp", + "serde", + "serde_json", +] + [[package]] name = "mime" version = "0.3.17" @@ -2277,9 +2277,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.21.11" +version = "0.21.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fecbfb7b1444f477b345853b1fce097a2c6fb637b2bfb87e6bc5db0f043fae4" +checksum = "3f56a14d1f48b391359b22f731fd4bd7e43c97f3c50eee276f3aa09c94784d3e" dependencies = [ "log", "ring", @@ -2329,9 +2329,9 @@ dependencies = [ [[package]] name = "schemars" -version = "0.8.16" +version = "0.8.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "45a28f4c49489add4ce10783f7911893516f15afe45d015608d41faca6bc4d29" +checksum = "7f55c82c700538496bdc329bb4918a81f87cc8888811bd123cf325a0f2f8d309" dependencies = [ "chrono", "dyn-clone", @@ -2343,14 +2343,14 @@ dependencies = [ [[package]] name = "schemars_derive" -version = "0.8.16" +version = "0.8.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c767fd6fa65d9ccf9cf026122c1b555f2ef9a4f0cea69da4d7dbc3e258d30967" +checksum = "83263746fe5e32097f06356968a077f96089739c927a61450efa069905eec108" dependencies = [ "proc-macro2", "quote", "serde_derive_internals", - "syn 1.0.109", + "syn 2.0.60", ] [[package]] @@ -2441,9 +2441,9 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.198" +version = "1.0.199" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9846a40c979031340571da2545a4e5b7c4163bdae79b301d5f86d03979451fcc" +checksum = "0c9f6e76df036c77cd94996771fb40db98187f096dd0b9af39c6c6e452ba966a" dependencies = [ "serde_derive", ] @@ -2461,9 +2461,9 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.198" +version = "1.0.199" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e88edab869b01783ba905e7d0153f9fc1a6505a96e4ad3018011eedb838566d9" +checksum = "11bd257a6541e141e42ca6d24ae26f7714887b47e89aa739099104c7e4d3b7fc" dependencies = [ "proc-macro2", "quote", @@ -2472,13 +2472,13 @@ dependencies = [ [[package]] name = "serde_derive_internals" -version = "0.26.0" +version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85bf8229e7920a9f636479437026331ce11aa132b4dde37d121944a44d6e5f3c" +checksum = "330f01ce65a3a5fe59a60c82f3c9a024b573b8a6e875bd233fe5f934e71d54e3" dependencies = [ "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.60", ] [[package]] @@ -3008,7 +3008,6 @@ dependencies = [ "config", "dotenv", "hex", - "mercury-lib", "rand", "reqwest", "rocket", @@ -3694,9 +3693,9 @@ checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" [[package]] name = "winnow" -version = "0.6.6" +version = "0.6.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0c976aaaa0e1f90dbb21e9587cdaf1d9679a1cde8875c0d6bd83ab96a208352" +checksum = "14b9415ee827af173ebb3f15f9083df5a122eb93572ec28741fb153356ea2578" dependencies = [ "memchr", ] diff --git a/clients/rust/Cargo.toml b/clients/rust/Cargo.toml index a234e5ce..725da835 100644 --- a/clients/rust/Cargo.toml +++ b/clients/rust/Cargo.toml @@ -24,6 +24,4 @@ serde_json = "1.0.96" sqlx = { version = "0.7", features = [ "runtime-tokio", "sqlite", "time", "uuid" ] } tokio = { version = "1.27.0", features = ["full"] } uuid = { version = "1.3.1", features = ["v4", "serde"] } - -[dependencies.mercury-lib] -path = "../../lib" \ No newline at end of file +mercurylib = { path = "../../lib" } diff --git a/clients/rust/Readme.md b/clients/rust/Readme.md new file mode 100644 index 00000000..4aaa5b96 --- /dev/null +++ b/clients/rust/Readme.md @@ -0,0 +1,31 @@ +# Mercury Layer Client + +Mercury layer client provides a user interface to the Mercury Layer protocol, via the Mercury Layer server. + +# Running + +1. Run the `enclave` project on localhost +2. Run the `server` project on localhost +3. Run one of the commands below + +# Some commands + +`cargo run create-wallet ` to create a wallet + +`cargo run new-token` to create a new token + +`cargo run new-deposit-address ` creates a deposit address + +`cargo run list-statecoins ` shows wallet coins + +`cargo run new-transfer-address ` generates a statechain address to receive statechain coins + +`cargo run transfer-send ` transfers the specified statechain coin to the specified address + +`cargo run transfer-receive ` scans for new statechain transfers + +`cargo run withdraw ` withdraws the statechain coin to the specified bitcoin address + +`cargo run broadcast-backup-transaction ` broadcasts the backup transaction to the network + +This is a work in progress. Several changes to the project are expected. \ No newline at end of file diff --git a/clients/rust/src/broadcast_backup_tx.rs b/clients/rust/src/broadcast_backup_tx.rs index f7042cc4..b79dda96 100644 --- a/clients/rust/src/broadcast_backup_tx.rs +++ b/clients/rust/src/broadcast_backup_tx.rs @@ -1,13 +1,19 @@ use crate::{client_config::ClientConfig, sqlite_manager::{get_backup_txs, get_wallet, update_wallet}}; use anyhow::{anyhow, Result}; use electrum_client::ElectrumApi; -use mercury_lib::wallet::{cpfp_tx, CoinStatus}; +use mercurylib::wallet::{cpfp_tx, CoinStatus}; pub async fn execute(client_config: &ClientConfig, wallet_name: &str, statechain_id: &str, to_address: &str, fee_rate: Option) -> Result<()> { - let mut wallet: mercury_lib::wallet::Wallet = get_wallet(&client_config.pool, &wallet_name).await?; + let mut wallet: mercurylib::wallet::Wallet = get_wallet(&client_config.pool, &wallet_name).await?; - let is_address_valid = mercury_lib::validate_address(to_address, &wallet.network)?; + let is_address_valid = mercurylib::validate_address(to_address, &wallet.network)?; + + if !is_address_valid { + return Err(anyhow!("Invalid address")); + } + + let is_address_valid = mercurylib::validate_address(to_address, &wallet.network)?; if !is_address_valid { return Err(anyhow!("Invalid address")); diff --git a/clients/rust/src/coin_status.rs b/clients/rust/src/coin_status.rs index d46cd3bc..bae7ecb4 100644 --- a/clients/rust/src/coin_status.rs +++ b/clients/rust/src/coin_status.rs @@ -4,7 +4,7 @@ use std::str::FromStr; use bitcoin::Address; use electrum_client::{ElectrumApi, ListUnspentRes}; -use mercury_lib::wallet::{CoinStatus, Coin, Activity, BackupTx}; +use mercurylib::wallet::{CoinStatus, Coin, Activity, BackupTx}; use anyhow::{anyhow, Result, Ok}; use serde_json::Value; @@ -174,7 +174,7 @@ async fn check_withdrawal(client_config: &ClientConfig, coin: &mut Coin) -> Resu pub async fn update_coins(client_config: &ClientConfig, wallet_name: &str) -> Result<()> { - let mut wallet: mercury_lib::wallet::Wallet = get_wallet(&client_config.pool, &wallet_name).await?; + let mut wallet: mercurylib::wallet::Wallet = get_wallet(&client_config.pool, &wallet_name).await?; let network = wallet.network.clone(); diff --git a/clients/rust/src/deposit.rs b/clients/rust/src/deposit.rs index 7b6b969d..454986fe 100644 --- a/clients/rust/src/deposit.rs +++ b/clients/rust/src/deposit.rs @@ -1,5 +1,5 @@ use anyhow::{anyhow, Result, Ok}; -use mercury_lib::{deposit::{create_deposit_msg1, create_aggregated_address}, wallet::{Wallet, BackupTx, CoinStatus, Coin}, transaction:: get_user_backup_address, utils::get_blockheight}; +use mercurylib::{deposit::{create_deposit_msg1, create_aggregated_address}, wallet::{Wallet, BackupTx, CoinStatus, Coin}, transaction:: get_user_backup_address, utils::get_blockheight}; use crate::{sqlite_manager::update_wallet, get_wallet, client_config::ClientConfig, transaction::new_transaction}; @@ -98,13 +98,13 @@ pub async fn init(client_config: &ClientConfig, wallet: &Wallet, token_id: uuid: let value = response.text().await?; - let deposit_msg_1_response: mercury_lib::deposit::DepositMsg1Response = serde_json::from_str(value.as_str())?; + let deposit_msg_1_response: mercurylib::deposit::DepositMsg1Response = serde_json::from_str(value.as_str())?; // println!("value: {:?}", value); // println!("response: {:?}", deposit_msg_1_response); - let deposit_init_result = mercury_lib::deposit::handle_deposit_msg_1_response(&coin, &deposit_msg_1_response)?; + let deposit_init_result = mercurylib::deposit::handle_deposit_msg_1_response(&coin, &deposit_msg_1_response)?; let coin = wallet.coins.last_mut().unwrap(); @@ -134,7 +134,7 @@ pub async fn get_token(client_config: &ClientConfig) -> Result { let value = response.text().await?; - let token: mercury_lib::deposit::TokenID = serde_json::from_str(value.as_str())?; + let token: mercurylib::deposit::TokenID = serde_json::from_str(value.as_str())?; return Ok(token.token_id); } diff --git a/clients/rust/src/main.rs b/clients/rust/src/main.rs index 126d61d9..f31d8931 100644 --- a/clients/rust/src/main.rs +++ b/clients/rust/src/main.rs @@ -98,7 +98,7 @@ async fn main() -> Result<()> { }, Commands::ListStatecoins { wallet_name } => { coin_status::update_coins(&client_config, &wallet_name).await?; - let wallet: mercury_lib::wallet::Wallet = get_wallet(&client_config.pool, &wallet_name).await?; + let wallet: mercurylib::wallet::Wallet = get_wallet(&client_config.pool, &wallet_name).await?; for coin in wallet.coins.iter() { println!("----\ncoin.user_pubkey: {}", coin.user_pubkey); println!("coin.aggregated_address: {}", coin.aggregated_address.as_ref().unwrap_or(&"".to_string())); diff --git a/clients/rust/src/sqlite_manager.rs b/clients/rust/src/sqlite_manager.rs index b06d51e6..088fb753 100644 --- a/clients/rust/src/sqlite_manager.rs +++ b/clients/rust/src/sqlite_manager.rs @@ -1,4 +1,4 @@ -use mercury_lib::wallet::{Wallet, BackupTx}; +use mercurylib::wallet::{Wallet, BackupTx}; use serde_json::json; use sqlx::{Pool, Sqlite, Row}; use anyhow::{anyhow, Result}; diff --git a/clients/rust/src/transaction.rs b/clients/rust/src/transaction.rs index bd1563e7..b914ec0c 100644 --- a/clients/rust/src/transaction.rs +++ b/clients/rust/src/transaction.rs @@ -1,5 +1,5 @@ use electrum_client::ElectrumApi; -use mercury_lib::{transaction::{SignFirstRequestPayload, PartialSignatureRequestPayload, PartialSignatureResponsePayload, get_partial_sig_request, create_signature, new_backup_transaction}, wallet::Coin}; +use mercurylib::{transaction::{SignFirstRequestPayload, PartialSignatureRequestPayload, PartialSignatureResponsePayload, get_partial_sig_request, create_signature, new_backup_transaction}, wallet::Coin}; use anyhow::Result; use secp256k1_zkp::musig::MusigPartialSignature; use crate::{client_config::ClientConfig, utils::info_config}; @@ -16,7 +16,7 @@ pub async fn new_transaction( // TODO: validate address first - let coin_nonce = mercury_lib::transaction::create_and_commit_nonces(&coin)?; + let coin_nonce = mercurylib::transaction::create_and_commit_nonces(&coin)?; coin.secret_nonce = Some(coin_nonce.secret_nonce); coin.public_nonce = Some(coin_nonce.public_nonce); coin.blinding_factor = Some(coin_nonce.blinding_factor); @@ -84,7 +84,7 @@ pub async fn sign_first(client_config: &ClientConfig, sign_first_request_payload let value = request.json(&sign_first_request_payload).send().await?.text().await?; - let sign_first_response_payload: mercury_lib::transaction::SignFirstResponsePayload = serde_json::from_str(value.as_str())?; + let sign_first_response_payload: mercurylib::transaction::SignFirstResponsePayload = serde_json::from_str(value.as_str())?; let mut server_pubnonce_hex = sign_first_response_payload.server_pubnonce.to_string(); diff --git a/clients/rust/src/transfer_receiver.rs b/clients/rust/src/transfer_receiver.rs index 715bf7ba..4481e71e 100644 --- a/clients/rust/src/transfer_receiver.rs +++ b/clients/rust/src/transfer_receiver.rs @@ -5,7 +5,7 @@ use anyhow::{anyhow, Result}; use bitcoin::{Txid, Address}; use chrono::Utc; use electrum_client::ElectrumApi; -use mercury_lib::{transfer::receiver::{GetMsgAddrResponsePayload, verify_transfer_signature, StatechainInfoResponsePayload, validate_tx0_output_pubkey, verify_latest_backup_tx_pays_to_user_pubkey, TxOutpoint, verify_transaction_signature, verify_blinded_musig_scheme, create_transfer_receiver_request_payload, TransferReceiverRequestPayload, get_new_key_info}, wallet::{Coin, Activity, CoinStatus}, utils::{get_network, InfoConfig, get_blockheight}}; +use mercurylib::{transfer::receiver::{GetMsgAddrResponsePayload, verify_transfer_signature, StatechainInfoResponsePayload, validate_tx0_output_pubkey, verify_latest_backup_tx_pays_to_user_pubkey, TxOutpoint, verify_transaction_signature, verify_blinded_musig_scheme, create_transfer_receiver_request_payload, TransferReceiverRequestPayload, get_new_key_info}, wallet::{Coin, Activity, CoinStatus}, utils::{get_network, InfoConfig, get_blockheight}}; use serde_json::Value; pub async fn new_transfer_address(client_config: &ClientConfig, wallet_name: &str) -> Result{ @@ -80,11 +80,11 @@ async fn process_encrypted_message(client_config: &ClientConfig, coin: &mut Coin for enc_message in enc_messages { - let transfer_msg = mercury_lib::transfer::receiver::decrypt_transfer_msg(enc_message, &client_auth_key)?; + let transfer_msg = mercurylib::transfer::receiver::decrypt_transfer_msg(enc_message, &client_auth_key)?; // println!("transfer_msg: {:?}", transfer_msg); - let tx0_outpoint = mercury_lib::transfer::receiver::get_tx0_outpoint(&transfer_msg.backup_transactions)?; + let tx0_outpoint = mercurylib::transfer::receiver::get_tx0_outpoint(&transfer_msg.backup_transactions)?; println!("tx0_outpoint: {:?}", tx0_outpoint); @@ -253,7 +253,7 @@ async fn get_statechain_info(statechain_id: &str, client_config: &ClientConfig) } async fn verify_tx0_output_is_unspent_and_confirmed(electrum_client: &electrum_client::Client, tx0_outpoint: &TxOutpoint, tx0_hex: &str, coin: &mut Coin, network: &str, confirmation_target: u32) -> Result { - let output_address = mercury_lib::transfer::receiver::get_output_address_from_tx0(&tx0_outpoint, &tx0_hex, &network)?; + let output_address = mercurylib::transfer::receiver::get_output_address_from_tx0(&tx0_outpoint, &tx0_hex, &network)?; let network = get_network(&network)?; let address = Address::from_str(&output_address)?.require_network(network)?; diff --git a/clients/rust/src/transfer_sender.rs b/clients/rust/src/transfer_sender.rs index 14d34ea1..68b711fe 100644 --- a/clients/rust/src/transfer_sender.rs +++ b/clients/rust/src/transfer_sender.rs @@ -1,13 +1,19 @@ use crate::{client_config::ClientConfig, sqlite_manager::{get_wallet, get_backup_txs, update_wallet, update_backup_txs}, transaction::new_transaction}; use anyhow::{anyhow, Result}; use chrono::Utc; -use mercury_lib::{wallet::{Coin, BackupTx, Activity, CoinStatus}, utils::get_blockheight, decode_transfer_address, transfer::sender::{TransferSenderRequestPayload, TransferSenderResponsePayload, create_transfer_signature, create_transfer_update_msg}}; +use mercurylib::{wallet::{Coin, BackupTx, Activity, CoinStatus}, utils::get_blockheight, decode_transfer_address, transfer::sender::{TransferSenderRequestPayload, TransferSenderResponsePayload, create_transfer_signature, create_transfer_update_msg}}; pub async fn execute(client_config: &ClientConfig, recipient_address: &str, wallet_name: &str, statechain_id: &str) -> Result<()> { - let mut wallet: mercury_lib::wallet::Wallet = get_wallet(&client_config.pool, &wallet_name).await?; + let mut wallet: mercurylib::wallet::Wallet = get_wallet(&client_config.pool, &wallet_name).await?; - let is_address_valid = mercury_lib::validate_address(recipient_address, &wallet.network)?; + let is_address_valid = mercurylib::validate_address(recipient_address, &wallet.network)?; + + if !is_address_valid { + return Err(anyhow!("Invalid address")); + } + + let is_address_valid = mercurylib::validate_address(recipient_address, &wallet.network)?; if !is_address_valid { return Err(anyhow!("Invalid address")); diff --git a/clients/rust/src/utils.rs b/clients/rust/src/utils.rs index a959a656..f1b15ad4 100644 --- a/clients/rust/src/utils.rs +++ b/clients/rust/src/utils.rs @@ -1,7 +1,7 @@ use chrono::Utc; use electrum_client::ElectrumApi; -use mercury_lib::{utils::{ServerConfig, InfoConfig}, wallet::Activity}; +use mercurylib::{utils::{ServerConfig, InfoConfig}, wallet::Activity}; use anyhow::{Result, Ok}; use crate::client_config::ClientConfig; diff --git a/clients/rust/src/wallet.rs b/clients/rust/src/wallet.rs index 3e1985b4..5c126bab 100644 --- a/clients/rust/src/wallet.rs +++ b/clients/rust/src/wallet.rs @@ -1,6 +1,6 @@ use anyhow::Result; use electrum_client::ElectrumApi; -use mercury_lib::wallet::{generate_mnemonic, Settings, Wallet}; +use mercurylib::wallet::{generate_mnemonic, Settings, Wallet}; use crate::{utils::info_config, client_config::ClientConfig}; diff --git a/clients/rust/src/withdraw.rs b/clients/rust/src/withdraw.rs index 89a2716d..6830ca9c 100644 --- a/clients/rust/src/withdraw.rs +++ b/clients/rust/src/withdraw.rs @@ -2,13 +2,19 @@ use crate::{client_config::ClientConfig, sqlite_manager::{get_wallet, update_wal use anyhow::{anyhow, Result}; use chrono::Utc; use electrum_client::ElectrumApi; -use mercury_lib::wallet::{BackupTx, Activity, CoinStatus}; +use mercurylib::wallet::{BackupTx, Activity, CoinStatus}; pub async fn execute(client_config: &ClientConfig, wallet_name: &str, statechain_id: &str, to_address: &str, fee_rate: Option) -> Result<()>{ - let mut wallet: mercury_lib::wallet::Wallet = get_wallet(&client_config.pool, &wallet_name).await?; + let mut wallet: mercurylib::wallet::Wallet = get_wallet(&client_config.pool, &wallet_name).await?; - let is_address_valid = mercury_lib::validate_address(to_address, &wallet.network)?; + let is_address_valid = mercurylib::validate_address(to_address, &wallet.network)?; + + if !is_address_valid { + return Err(anyhow!("Invalid address")); + } + + let is_address_valid = mercurylib::validate_address(to_address, &wallet.network)?; if !is_address_valid { return Err(anyhow!("Invalid address")); diff --git a/enclave/.gitignore b/enclave/.gitignore index 26d1dd83..ef345d26 100644 --- a/enclave/.gitignore +++ b/enclave/.gitignore @@ -37,5 +37,4 @@ App/Enclave_u.h Enclave/Enclave_t.c Enclave/Enclave_t.h app -Settings.toml node.sealed_seed \ No newline at end of file diff --git a/enclave/Settings.toml b/enclave/Settings.toml new file mode 100644 index 00000000..8614792d --- /dev/null +++ b/enclave/Settings.toml @@ -0,0 +1,2 @@ +[intel_sgx] +database_connection_string = "postgresql://postgres:postgres@localhost/enclave" \ No newline at end of file diff --git a/lib/Cargo.toml b/lib/Cargo.toml index 79c42b29..6b0282af 100644 --- a/lib/Cargo.toml +++ b/lib/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "mercury-lib" +name = "mercurylib" version = "0.1.0" edition = "2021" @@ -9,9 +9,11 @@ edition = "2021" bitcoin = { version = "0.30.1", features = ["serde", "base64", "rand-std", "std"], default-features = false } bip39 = "1.2.0" bech32 = { version = "0.9.1", default-features = false } -ecies = {version = "0.2", default-features = false, features = ["pure"]} +# TODO: Cannot update Cargo because it will get once_cell 1.19.0 and will break the ecies dependency +# When version 0.27.0 is released, update the ecies dependency to use it +ecies = {version = "0.2.6", default-features = false, features = ["pure"]} hex = "0.4.3" serde = { version = "1.0.163", features = ["derive"] } serde_json = "1.0.96" secp256k1-zkp = { git = "https://github.com/ssantos21/rust-secp256k1-zkp.git", branch = "blinded-musig-scheme", features = [ "rand-std", "bitcoin_hashes", "std" ] } -anyhow = "1.0" \ No newline at end of file +anyhow = "1.0" diff --git a/server/Cargo.toml b/server/Cargo.toml index b64f543e..15493e9e 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -20,6 +20,4 @@ hex = "0.4.3" secp256k1-zkp = { git = "https://github.com/ssantos21/rust-secp256k1-zkp.git", branch = "blinded-musig-scheme", features = [ "rand-std", "bitcoin_hashes", "std" ] } dotenv = "0.15.0" # secp256k1-zkp = { path = "../ss-rust-secp256k1-zkp", features = [ "rand-std", "bitcoin_hashes", "std" ] } - -[dependencies.mercury-lib] -path = "../lib" +mercurylib = { path = "../lib" } diff --git a/server/src/endpoints/deposit.rs b/server/src/endpoints/deposit.rs index dc2f9f1d..221cadb6 100644 --- a/server/src/endpoints/deposit.rs +++ b/server/src/endpoints/deposit.rs @@ -56,7 +56,7 @@ pub async fn set_token_spent(pool: &sqlx::PgPool, token_id: &str) { transaction.commit().await.unwrap(); } -pub async fn check_existing_key(pool: &sqlx::PgPool, auth_key: &XOnlyPublicKey) -> Option { +pub async fn check_existing_key(pool: &sqlx::PgPool, auth_key: &XOnlyPublicKey) -> Option { let row = sqlx::query( "SELECT statechain_id, server_public_key \ @@ -78,7 +78,7 @@ pub async fn check_existing_key(pool: &sqlx::PgPool, auth_key: &XOnlyPublicKey) let server_public_key_bytes = row_ur.get::, _>(1); let server_pubkey = PublicKey::from_slice(&server_public_key_bytes).unwrap(); - let deposit_msg1_response = mercury_lib::deposit::DepositMsg1Response { + let deposit_msg1_response = mercurylib::deposit::DepositMsg1Response { server_pubkey: server_pubkey.to_string(), statechain_id: row_ur.get(0), }; @@ -103,7 +103,7 @@ pub async fn get_token(statechain_entity: &State) -> status::C insert_new_token(&statechain_entity.pool, &token_id).await; - let token = mercury_lib::deposit::TokenID { + let token = mercurylib::deposit::TokenID { token_id }; @@ -113,7 +113,7 @@ pub async fn get_token(statechain_entity: &State) -> status::C } #[post("/deposit/init/pod", format = "json", data = "")] -pub async fn post_deposit(statechain_entity: &State, deposit_msg1: Json) -> status::Custom> { +pub async fn post_deposit(statechain_entity: &State, deposit_msg1: Json) -> status::Custom> { let statechain_entity = statechain_entity.inner(); @@ -214,7 +214,7 @@ pub async fn post_deposit(statechain_entity: &State, deposit_m set_token_spent(&statechain_entity.pool, &token_id).await; - let deposit_msg1_response = mercury_lib::deposit::DepositMsg1Response { + let deposit_msg1_response = mercurylib::deposit::DepositMsg1Response { server_pubkey: server_pubkey.to_string(), statechain_id, }; diff --git a/server/src/endpoints/sign.rs b/server/src/endpoints/sign.rs index 89e814b9..7bbd004e 100644 --- a/server/src/endpoints/sign.rs +++ b/server/src/endpoints/sign.rs @@ -1,4 +1,4 @@ -use mercury_lib::transaction::SignFirstRequestPayload; +use mercurylib::transaction::SignFirstRequestPayload; use rocket::{State, serde::json::Json, response::status, http::Status}; use secp256k1_zkp::musig::MusigSession; use serde::{Deserialize, Serialize}; @@ -86,7 +86,7 @@ pub async fn sign_first(statechain_entity: &State, sign_first_ println!("value: {}", value); - let response: mercury_lib::transaction::SignFirstResponsePayload = serde_json::from_str(value.as_str()).expect(&format!("failed to parse: {}", value.as_str())); + let response: mercurylib::transaction::SignFirstResponsePayload = serde_json::from_str(value.as_str()).expect(&format!("failed to parse: {}", value.as_str())); let mut server_pubnonce_hex = response.server_pubnonce.clone(); @@ -126,7 +126,7 @@ pub async fn update_signature_data_challenge(pool: &sqlx::PgPool, server_pub_non } #[post("/sign/second", format = "json", data = "")] -pub async fn sign_second (statechain_entity: &State, partial_signature_request_payload: Json) -> status::Custom> { +pub async fn sign_second (statechain_entity: &State, partial_signature_request_payload: Json) -> status::Custom> { let statechain_entity = statechain_entity.inner(); diff --git a/server/src/endpoints/transfer_receiver.rs b/server/src/endpoints/transfer_receiver.rs index 7f147a4c..bd167ed4 100644 --- a/server/src/endpoints/transfer_receiver.rs +++ b/server/src/endpoints/transfer_receiver.rs @@ -1,7 +1,7 @@ use std::str::FromStr; use bitcoin::hashes::sha256; -use mercury_lib::transfer::receiver::{GetMsgAddrResponsePayload, StatechainInfo}; +use mercurylib::transfer::receiver::{GetMsgAddrResponsePayload, StatechainInfo}; use rocket::{State, response::status, serde::json::Json, http::Status}; use secp256k1_zkp::{PublicKey, schnorr::Signature, Message, Secp256k1, XOnlyPublicKey, SecretKey}; use serde::{Serialize, Deserialize}; @@ -188,7 +188,7 @@ async fn get_auth_pubkey_and_x1(pool: &sqlx::PgPool, statechain_id: &str) -> Opt Some((new_user_auth_public_key, x1_bytes)) } -type TransferReceiverRequestPayload = mercury_lib::transfer::receiver::TransferReceiverRequestPayload; +type TransferReceiverRequestPayload = mercurylib::transfer::receiver::TransferReceiverRequestPayload; #[post("/transfer/receiver", format = "json", data = "")] pub async fn transfer_receiver(statechain_entity: &State, transfer_receiver_request_payload: Json) -> status::Custom> { @@ -254,7 +254,7 @@ pub async fn transfer_receiver(statechain_entity: &State, tran let x1_hex = hex::encode(x1); - let key_update_response_payload = mercury_lib::transfer::receiver::KeyUpdateResponsePayload { + let key_update_response_payload = mercurylib::transfer::receiver::KeyUpdateResponsePayload { statechain_id: statechain_id.clone(), t2, x1: x1_hex, diff --git a/server/src/endpoints/transfer_sender.rs b/server/src/endpoints/transfer_sender.rs index fffd2de8..b9d77252 100644 --- a/server/src/endpoints/transfer_sender.rs +++ b/server/src/endpoints/transfer_sender.rs @@ -1,6 +1,6 @@ use std::str::FromStr; -use mercury_lib::transfer::sender::TransferSenderResponsePayload; +use mercurylib::transfer::sender::TransferSenderResponsePayload; use rocket::{State, serde::json::Json, response::status, http::Status}; use secp256k1_zkp::{PublicKey, Scalar, SecretKey}; use serde::{Serialize, Deserialize}; diff --git a/server/src/endpoints/utils.rs b/server/src/endpoints/utils.rs index 0a8853cc..9bb564ac 100644 --- a/server/src/endpoints/utils.rs +++ b/server/src/endpoints/utils.rs @@ -47,7 +47,7 @@ pub async fn validate_signature(pool: &sqlx::PgPool, signed_message_hex: &str, s pub async fn info_config(statechain_entity: &State) -> status::Custom> { let statechain_entity = statechain_entity.inner(); - let server_config = mercury_lib::utils::ServerConfig { + let server_config = mercurylib::utils::ServerConfig { initlock: statechain_entity.config.lockheight_init, interval: statechain_entity.config.lh_decrement, }; @@ -78,7 +78,7 @@ pub async fn info_keylist(statechain_entity: &State) -> status .await .unwrap(); - let mut result = Vec::::new(); + let mut result = Vec::::new(); for row in rows { @@ -86,7 +86,7 @@ pub async fn info_keylist(statechain_entity: &State) -> status let server_pubkey = PublicKey::from_slice(&server_public_key_bytes).unwrap(); let statechain_id: String = row.get(1); - let mut keyinfo: mercury_lib::utils::PubKeyInfo = mercury_lib::utils::PubKeyInfo { + let mut keyinfo: mercurylib::utils::PubKeyInfo = mercurylib::utils::PubKeyInfo { server_pubkey: server_pubkey.to_string(), tx_n: 0, updated_at: "".to_string(), @@ -105,7 +105,7 @@ pub async fn info_keylist(statechain_entity: &State) -> status result.push(keyinfo); } - let key_list_response_payload = mercury_lib::utils::KeyListResponsePayload { + let key_list_response_payload = mercurylib::utils::KeyListResponsePayload { list_keyinfo:result }; diff --git a/server/src/endpoints/withdraw.rs b/server/src/endpoints/withdraw.rs index ca4e9ee4..ff16cdcd 100644 --- a/server/src/endpoints/withdraw.rs +++ b/server/src/endpoints/withdraw.rs @@ -29,7 +29,7 @@ async fn delete_statechain_db(pool: &sqlx::PgPool, statechain_id: &String) { } #[delete("/delete_statechain", format = "json", data = "")] -pub async fn delete_statechain(statechain_entity: &State, delete_statechain_payload: Json) -> status::Custom> { +pub async fn delete_statechain(statechain_entity: &State, delete_statechain_payload: Json) -> status::Custom> { let statechain_id = delete_statechain_payload.0.statechain_id.clone(); let signed_statechain_id = delete_statechain_payload.0.signed_statechain_id.clone(); diff --git a/token-server/Cargo.toml b/token-server/Cargo.toml index 8599b154..6132d19e 100644 --- a/token-server/Cargo.toml +++ b/token-server/Cargo.toml @@ -18,5 +18,3 @@ rand = "0.8.5" hex = "0.4.3" dotenv = "0.15.0" -[dependencies.mercury-lib] -path = "../lib" diff --git a/wasm/Cargo.toml b/wasm/Cargo.toml index 53dbb455..79ac9a21 100644 --- a/wasm/Cargo.toml +++ b/wasm/Cargo.toml @@ -19,6 +19,7 @@ serde = { version = "1.0", features = ["derive"] } serde-wasm-bindgen = "0.4" bip39 = "1.2.0" rand = "0.8" +mercurylib = { path = "../lib" } # The `console_error_panic_hook` crate provides better debugging of panics by # logging them with `console.error`. This is great for development, but requires @@ -44,8 +45,5 @@ wasm-bindgen-test = "0.3.34" # Tell `rustc` to optimize for small code size. opt-level = "s" -[dependencies.mercury-lib] -path = "../lib" - [dependencies.getrandom] features = ["js"] diff --git a/wasm/README.md b/wasm/README.md index c82e8b3d..2e6b2ec5 100644 --- a/wasm/README.md +++ b/wasm/README.md @@ -7,9 +7,17 @@ Building it with a higher version will fail. To build with `wasm-pack`: -``` +```bash # For web -wasm-pack build --release --target web +$ wasm-pack build --release --target web --out-dir web_pkg/release/ +$ wasm-pack build --debug --target web --out-dir web_pkg/debug/ # Or for nodejs -wasm-pack build --release --target nodejs +$ wasm-pack build --release --target nodejs --out-dir node_pkg/release/ +$ wasm-pack build --debug --target nodejs --out-dir node_pkg/debug/ +``` + +The file `build_pkgs.sh` does this. + +```bash +$ ./build_pkgs.sh ``` \ No newline at end of file diff --git a/wasm/build_pkgs.sh b/wasm/build_pkgs.sh new file mode 100755 index 00000000..9eef328f --- /dev/null +++ b/wasm/build_pkgs.sh @@ -0,0 +1,9 @@ +rm node_pkg/debug/* +rm node_pkg/release/* +rm web_pkg/debug/* +rm web_pkg/release/* + +wasm-pack build --release --target web --out-dir web_pkg/release/ +wasm-pack build --debug --target web --out-dir web_pkg/debug/ +wasm-pack build --release --target nodejs --out-dir node_pkg/release/ +wasm-pack build --debug --target nodejs --out-dir node_pkg/debug/ \ No newline at end of file diff --git a/wasm/node_pkg/README.md b/wasm/node_pkg/README.md deleted file mode 100644 index c82e8b3d..00000000 --- a/wasm/node_pkg/README.md +++ /dev/null @@ -1,15 +0,0 @@ -# Mercury layer WASM library - -A `wasm-bindgen` library of functions for the mercury layer clients. - -This project works only with clang 14. -Building it with a higher version will fail. - -To build with `wasm-pack`: - -``` -# For web -wasm-pack build --release --target web -# Or for nodejs -wasm-pack build --release --target nodejs -``` \ No newline at end of file diff --git a/wasm/node_pkg/mercury_wasm.d.ts b/wasm/node_pkg/mercury_wasm.d.ts deleted file mode 100644 index 93c270b2..00000000 --- a/wasm/node_pkg/mercury_wasm.d.ts +++ /dev/null @@ -1,237 +0,0 @@ -/* tslint:disable */ -/* eslint-disable */ -/** -* @param {any} config_json -* @param {any} wallet_json -* @returns {any} -*/ -export function setConfig(config_json: any, wallet_json: any): any; -/** -* @param {number} blockheight -* @param {any} wallet_json -* @returns {any} -*/ -export function setBlockheight(blockheight: number, wallet_json: any): any; -/** -* @param {any} token_json -* @param {any} wallet_json -* @returns {any} -*/ -export function addToken(token_json: any, wallet_json: any): any; -/** -* @param {string} token_id -* @param {any} wallet_json -* @returns {any} -*/ -export function confirmToken(token_id: string, wallet_json: any): any; -/** -* @param {any} wallet_json -* @returns {any} -*/ -export function getTokens(wallet_json: any): any; -/** -* @param {any} wallet_json -* @returns {number} -*/ -export function getBalance(wallet_json: any): number; -/** -* @param {any} wallet_json -* @param {number} index -* @returns {string} -*/ -export function getSCAddress(wallet_json: any, index: number): string; -/** -* @returns {string} -*/ -export function generateMnemonic(): string; -/** -* @param {string} name -* @param {string} mnemonic -* @returns {any} -*/ -export function fromMnemonic(name: string, mnemonic: string): any; -/** -* @param {any} wallet_json -* @returns {any} -*/ -export function getActivityLog(wallet_json: any): any; -/** -* @param {any} wallet_json -* @returns {any} -*/ -export function getCoins(wallet_json: any): any; -/** -* @param {any} wallet_json -* @returns {any} -*/ -export function getNewCoin(wallet_json: any): any; -/** -* @param {any} coin_json -* @param {string} token_id -* @returns {any} -*/ -export function createDepositMsg1(coin_json: any, token_id: string): any; -/** -* @param {any} coin_json -* @param {any} deposit_msg_1_response_json -* @returns {any} -*/ -export function handleDepositMsg1Response(coin_json: any, deposit_msg_1_response_json: any): any; -/** -* @param {any} coin_json -* @param {string} network -* @returns {any} -*/ -export function createAggregatedAddress(coin_json: any, network: string): any; -/** -* @param {any} coin_json -* @returns {any} -*/ -export function createAndCommitNonces(coin_json: any): any; -/** -* @param {any} coin_json -* @param {string} network -* @returns {string} -*/ -export function getUserBackupAddress(coin_json: any, network: string): string; -/** -* @param {any} coin_json -* @param {number} block_height -* @param {number} initlock -* @param {number} interval -* @param {number} fee_rate_sats_per_byte -* @param {number} qt_backup_tx -* @param {string} to_address -* @param {string} network -* @param {boolean} is_withdrawal -* @returns {any} -*/ -export function getPartialSigRequest(coin_json: any, block_height: number, initlock: number, interval: number, fee_rate_sats_per_byte: number, qt_backup_tx: number, to_address: string, network: string, is_withdrawal: boolean): any; -/** -* @param {string} msg -* @param {string} client_partial_sig_hex -* @param {string} server_partial_sig_hex -* @param {string} session_hex -* @param {string} output_pubkey_hex -* @returns {string} -*/ -export function createSignature(msg: string, client_partial_sig_hex: string, server_partial_sig_hex: string, session_hex: string, output_pubkey_hex: string): string; -/** -* @param {string} encoded_unsigned_tx -* @param {string} signature_hex -* @returns {string} -*/ -export function newBackupTransaction(encoded_unsigned_tx: string, signature_hex: string): string; -/** -* @param {any} backup_tx_json -* @param {any} coin_json -* @param {string} to_address -* @param {number} fee_rate_sats_per_byte -* @param {string} network -* @returns {string} -*/ -export function createCpfpTx(backup_tx_json: any, coin_json: any, to_address: string, fee_rate_sats_per_byte: number, network: string): string; -/** -* @param {string} recipient_address -* @param {string} input_txid -* @param {number} input_vout -* @param {string} client_seckey -* @returns {string} -*/ -export function createTransferSignature(recipient_address: string, input_txid: string, input_vout: number, client_seckey: string): string; -/** -* @param {string} x1 -* @param {string} recipient_address -* @param {any} coin_json -* @param {string} transfer_signature -* @param {any} backup_transactions -* @returns {any} -*/ -export function createTransferUpdateMsg(x1: string, recipient_address: string, coin_json: any, transfer_signature: string, backup_transactions: any): any; -/** -* @param {string} sc_address -* @returns {any} -*/ -export function decodeTransferAddress(sc_address: string): any; -/** -* @param {string} encrypted_message -* @param {string} private_key_wif -* @returns {any} -*/ -export function decryptTransferMsg(encrypted_message: string, private_key_wif: string): any; -/** -* @param {any} backup_transactions -* @returns {any} -*/ -export function getTx0Outpoint(backup_transactions: any): any; -/** -* @param {string} new_user_pubkey -* @param {any} tx0_outpoint -* @param {any} transfer_msg -* @returns {boolean} -*/ -export function verifyTransferSignature(new_user_pubkey: string, tx0_outpoint: any, transfer_msg: any): boolean; -/** -* @param {string} enclave_public_key -* @param {any} transfer_msg -* @param {any} tx0_outpoint -* @param {string} tx0_hex -* @param {string} network -* @returns {boolean} -*/ -export function validateTx0OutputPubkey(enclave_public_key: string, transfer_msg: any, tx0_outpoint: any, tx0_hex: string, network: string): boolean; -/** -* @param {any} transfer_msg -* @param {string} client_pubkey_share -* @param {string} network -* @returns {boolean} -*/ -export function verifyLatestBackupTxPaysToUserPubkey(transfer_msg: any, client_pubkey_share: string, network: string): boolean; -/** -* @param {any} tx0_outpoint -* @param {string} tx0_hex -* @param {string} network -* @returns {string} -*/ -export function getOutputAddressFromTx0(tx0_outpoint: any, tx0_hex: string, network: string): string; -/** -* @param {string} tx_n_hex -* @param {string} tx0_hex -* @param {number} fee_rate_tolerance -* @param {number} current_fee_rate_sats_per_byte -* @returns {any} -*/ -export function verifyTransactionSignature(tx_n_hex: string, tx0_hex: string, fee_rate_tolerance: number, current_fee_rate_sats_per_byte: number): any; -/** -* @param {any} backup_tx -* @param {string} tx0_hex -* @param {any} statechain_info -* @returns {any} -*/ -export function verifyBlindedMusigScheme(backup_tx: any, tx0_hex: string, statechain_info: any): any; -/** -* @param {any} backup_tx -* @returns {number} -*/ -export function getBlockheight(backup_tx: any): number; -/** -* @param {any} statechain_info -* @param {any} transfer_msg -* @param {any} coin -* @returns {any} -*/ -export function createTransferReceiverRequestPayload(statechain_info: any, transfer_msg: any, coin: any): any; -/** -* @param {string} server_public_key_hex -* @param {any} coin -* @param {string} statechain_id -* @param {any} tx0_outpoint -* @param {string} tx0_hex -* @param {string} network -* @returns {any} -*/ -export function getNewKeyInfo(server_public_key_hex: string, coin: any, statechain_id: string, tx0_outpoint: any, tx0_hex: string, network: string): any; -/** -* @returns {any} -*/ -export function getMockWallet(): any; diff --git a/wasm/node_pkg/mercury_wasm.js b/wasm/node_pkg/mercury_wasm.js deleted file mode 100644 index b5514a05..00000000 --- a/wasm/node_pkg/mercury_wasm.js +++ /dev/null @@ -1,1126 +0,0 @@ -let imports = {}; -imports['__wbindgen_placeholder__'] = module.exports; -let wasm; -const { TextEncoder, TextDecoder } = require(`util`); - -const heap = new Array(128).fill(undefined); - -heap.push(undefined, null, true, false); - -function getObject(idx) { return heap[idx]; } - -function _assertBoolean(n) { - if (typeof(n) !== 'boolean') { - throw new Error('expected a boolean argument'); - } -} - -function _assertNum(n) { - if (typeof(n) !== 'number') throw new Error('expected a number argument'); -} - -let WASM_VECTOR_LEN = 0; - -let cachedUint8Memory0 = null; - -function getUint8Memory0() { - if (cachedUint8Memory0 === null || cachedUint8Memory0.byteLength === 0) { - cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer); - } - return cachedUint8Memory0; -} - -let cachedTextEncoder = new TextEncoder('utf-8'); - -const encodeString = (typeof cachedTextEncoder.encodeInto === 'function' - ? function (arg, view) { - return cachedTextEncoder.encodeInto(arg, view); -} - : function (arg, view) { - const buf = cachedTextEncoder.encode(arg); - view.set(buf); - return { - read: arg.length, - written: buf.length - }; -}); - -function passStringToWasm0(arg, malloc, realloc) { - - if (typeof(arg) !== 'string') throw new Error('expected a string argument'); - - if (realloc === undefined) { - const buf = cachedTextEncoder.encode(arg); - const ptr = malloc(buf.length, 1) >>> 0; - getUint8Memory0().subarray(ptr, ptr + buf.length).set(buf); - WASM_VECTOR_LEN = buf.length; - return ptr; - } - - let len = arg.length; - let ptr = malloc(len, 1) >>> 0; - - const mem = getUint8Memory0(); - - let offset = 0; - - for (; offset < len; offset++) { - const code = arg.charCodeAt(offset); - if (code > 0x7F) break; - mem[ptr + offset] = code; - } - - if (offset !== len) { - if (offset !== 0) { - arg = arg.slice(offset); - } - ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0; - const view = getUint8Memory0().subarray(ptr + offset, ptr + len); - const ret = encodeString(arg, view); - if (ret.read !== arg.length) throw new Error('failed to pass whole string'); - offset += ret.written; - } - - WASM_VECTOR_LEN = offset; - return ptr; -} - -function isLikeNone(x) { - return x === undefined || x === null; -} - -let cachedInt32Memory0 = null; - -function getInt32Memory0() { - if (cachedInt32Memory0 === null || cachedInt32Memory0.byteLength === 0) { - cachedInt32Memory0 = new Int32Array(wasm.memory.buffer); - } - return cachedInt32Memory0; -} - -let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }); - -cachedTextDecoder.decode(); - -function getStringFromWasm0(ptr, len) { - ptr = ptr >>> 0; - return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len)); -} - -let heap_next = heap.length; - -function addHeapObject(obj) { - if (heap_next === heap.length) heap.push(heap.length + 1); - const idx = heap_next; - heap_next = heap[idx]; - - if (typeof(heap_next) !== 'number') throw new Error('corrupt heap'); - - heap[idx] = obj; - return idx; -} - -let cachedFloat64Memory0 = null; - -function getFloat64Memory0() { - if (cachedFloat64Memory0 === null || cachedFloat64Memory0.byteLength === 0) { - cachedFloat64Memory0 = new Float64Array(wasm.memory.buffer); - } - return cachedFloat64Memory0; -} - -function dropObject(idx) { - if (idx < 132) return; - heap[idx] = heap_next; - heap_next = idx; -} - -function takeObject(idx) { - const ret = getObject(idx); - dropObject(idx); - return ret; -} - -function debugString(val) { - // primitive types - const type = typeof val; - if (type == 'number' || type == 'boolean' || val == null) { - return `${val}`; - } - if (type == 'string') { - return `"${val}"`; - } - if (type == 'symbol') { - const description = val.description; - if (description == null) { - return 'Symbol'; - } else { - return `Symbol(${description})`; - } - } - if (type == 'function') { - const name = val.name; - if (typeof name == 'string' && name.length > 0) { - return `Function(${name})`; - } else { - return 'Function'; - } - } - // objects - if (Array.isArray(val)) { - const length = val.length; - let debug = '['; - if (length > 0) { - debug += debugString(val[0]); - } - for(let i = 1; i < length; i++) { - debug += ', ' + debugString(val[i]); - } - debug += ']'; - return debug; - } - // Test for built-in - const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val)); - let className; - if (builtInMatches.length > 1) { - className = builtInMatches[1]; - } else { - // Failed to match the standard '[object ClassName]' - return toString.call(val); - } - if (className == 'Object') { - // we're a user defined class or Object - // JSON.stringify avoids problems with cycles, and is generally much - // easier than looping through ownProperties of `val`. - try { - return 'Object(' + JSON.stringify(val) + ')'; - } catch (_) { - return 'Object'; - } - } - // errors - if (val instanceof Error) { - return `${val.name}: ${val.message}\n${val.stack}`; - } - // TODO we could test for more things here, like `Set`s and `Map`s. - return className; -} -/** -* @param {any} config_json -* @param {any} wallet_json -* @returns {any} -*/ -module.exports.setConfig = function(config_json, wallet_json) { - const ret = wasm.setConfig(addHeapObject(config_json), addHeapObject(wallet_json)); - return takeObject(ret); -}; - -/** -* @param {number} blockheight -* @param {any} wallet_json -* @returns {any} -*/ -module.exports.setBlockheight = function(blockheight, wallet_json) { - _assertNum(blockheight); - const ret = wasm.setBlockheight(blockheight, addHeapObject(wallet_json)); - return takeObject(ret); -}; - -/** -* @param {any} token_json -* @param {any} wallet_json -* @returns {any} -*/ -module.exports.addToken = function(token_json, wallet_json) { - const ret = wasm.addToken(addHeapObject(token_json), addHeapObject(wallet_json)); - return takeObject(ret); -}; - -/** -* @param {string} token_id -* @param {any} wallet_json -* @returns {any} -*/ -module.exports.confirmToken = function(token_id, wallet_json) { - const ptr0 = passStringToWasm0(token_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len0 = WASM_VECTOR_LEN; - const ret = wasm.confirmToken(ptr0, len0, addHeapObject(wallet_json)); - return takeObject(ret); -}; - -/** -* @param {any} wallet_json -* @returns {any} -*/ -module.exports.getTokens = function(wallet_json) { - const ret = wasm.getTokens(addHeapObject(wallet_json)); - return takeObject(ret); -}; - -/** -* @param {any} wallet_json -* @returns {number} -*/ -module.exports.getBalance = function(wallet_json) { - const ret = wasm.getBalance(addHeapObject(wallet_json)); - return ret >>> 0; -}; - -/** -* @param {any} wallet_json -* @param {number} index -* @returns {string} -*/ -module.exports.getSCAddress = function(wallet_json, index) { - let deferred1_0; - let deferred1_1; - try { - const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); - _assertNum(index); - wasm.getSCAddress(retptr, addHeapObject(wallet_json), index); - var r0 = getInt32Memory0()[retptr / 4 + 0]; - var r1 = getInt32Memory0()[retptr / 4 + 1]; - deferred1_0 = r0; - deferred1_1 = r1; - return getStringFromWasm0(r0, r1); - } finally { - wasm.__wbindgen_add_to_stack_pointer(16); - wasm.__wbindgen_free(deferred1_0, deferred1_1, 1); - } -}; - -/** -* @returns {string} -*/ -module.exports.generateMnemonic = function() { - let deferred1_0; - let deferred1_1; - try { - const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); - wasm.generateMnemonic(retptr); - var r0 = getInt32Memory0()[retptr / 4 + 0]; - var r1 = getInt32Memory0()[retptr / 4 + 1]; - deferred1_0 = r0; - deferred1_1 = r1; - return getStringFromWasm0(r0, r1); - } finally { - wasm.__wbindgen_add_to_stack_pointer(16); - wasm.__wbindgen_free(deferred1_0, deferred1_1, 1); - } -}; - -/** -* @param {string} name -* @param {string} mnemonic -* @returns {any} -*/ -module.exports.fromMnemonic = function(name, mnemonic) { - const ptr0 = passStringToWasm0(name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len0 = WASM_VECTOR_LEN; - const ptr1 = passStringToWasm0(mnemonic, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len1 = WASM_VECTOR_LEN; - const ret = wasm.fromMnemonic(ptr0, len0, ptr1, len1); - return takeObject(ret); -}; - -/** -* @param {any} wallet_json -* @returns {any} -*/ -module.exports.getActivityLog = function(wallet_json) { - const ret = wasm.getActivityLog(addHeapObject(wallet_json)); - return takeObject(ret); -}; - -/** -* @param {any} wallet_json -* @returns {any} -*/ -module.exports.getCoins = function(wallet_json) { - const ret = wasm.getCoins(addHeapObject(wallet_json)); - return takeObject(ret); -}; - -/** -* @param {any} wallet_json -* @returns {any} -*/ -module.exports.getNewCoin = function(wallet_json) { - const ret = wasm.getNewCoin(addHeapObject(wallet_json)); - return takeObject(ret); -}; - -/** -* @param {any} coin_json -* @param {string} token_id -* @returns {any} -*/ -module.exports.createDepositMsg1 = function(coin_json, token_id) { - const ptr0 = passStringToWasm0(token_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len0 = WASM_VECTOR_LEN; - const ret = wasm.createDepositMsg1(addHeapObject(coin_json), ptr0, len0); - return takeObject(ret); -}; - -/** -* @param {any} coin_json -* @param {any} deposit_msg_1_response_json -* @returns {any} -*/ -module.exports.handleDepositMsg1Response = function(coin_json, deposit_msg_1_response_json) { - const ret = wasm.handleDepositMsg1Response(addHeapObject(coin_json), addHeapObject(deposit_msg_1_response_json)); - return takeObject(ret); -}; - -/** -* @param {any} coin_json -* @param {string} network -* @returns {any} -*/ -module.exports.createAggregatedAddress = function(coin_json, network) { - const ptr0 = passStringToWasm0(network, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len0 = WASM_VECTOR_LEN; - const ret = wasm.createAggregatedAddress(addHeapObject(coin_json), ptr0, len0); - return takeObject(ret); -}; - -/** -* @param {any} coin_json -* @returns {any} -*/ -module.exports.createAndCommitNonces = function(coin_json) { - const ret = wasm.createAndCommitNonces(addHeapObject(coin_json)); - return takeObject(ret); -}; - -/** -* @param {any} coin_json -* @param {string} network -* @returns {string} -*/ -module.exports.getUserBackupAddress = function(coin_json, network) { - let deferred2_0; - let deferred2_1; - try { - const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); - const ptr0 = passStringToWasm0(network, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len0 = WASM_VECTOR_LEN; - wasm.getUserBackupAddress(retptr, addHeapObject(coin_json), ptr0, len0); - var r0 = getInt32Memory0()[retptr / 4 + 0]; - var r1 = getInt32Memory0()[retptr / 4 + 1]; - deferred2_0 = r0; - deferred2_1 = r1; - return getStringFromWasm0(r0, r1); - } finally { - wasm.__wbindgen_add_to_stack_pointer(16); - wasm.__wbindgen_free(deferred2_0, deferred2_1, 1); - } -}; - -/** -* @param {any} coin_json -* @param {number} block_height -* @param {number} initlock -* @param {number} interval -* @param {number} fee_rate_sats_per_byte -* @param {number} qt_backup_tx -* @param {string} to_address -* @param {string} network -* @param {boolean} is_withdrawal -* @returns {any} -*/ -module.exports.getPartialSigRequest = function(coin_json, block_height, initlock, interval, fee_rate_sats_per_byte, qt_backup_tx, to_address, network, is_withdrawal) { - _assertNum(block_height); - _assertNum(initlock); - _assertNum(interval); - _assertNum(fee_rate_sats_per_byte); - _assertNum(qt_backup_tx); - const ptr0 = passStringToWasm0(to_address, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len0 = WASM_VECTOR_LEN; - const ptr1 = passStringToWasm0(network, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len1 = WASM_VECTOR_LEN; - _assertBoolean(is_withdrawal); - const ret = wasm.getPartialSigRequest(addHeapObject(coin_json), block_height, initlock, interval, fee_rate_sats_per_byte, qt_backup_tx, ptr0, len0, ptr1, len1, is_withdrawal); - return takeObject(ret); -}; - -/** -* @param {string} msg -* @param {string} client_partial_sig_hex -* @param {string} server_partial_sig_hex -* @param {string} session_hex -* @param {string} output_pubkey_hex -* @returns {string} -*/ -module.exports.createSignature = function(msg, client_partial_sig_hex, server_partial_sig_hex, session_hex, output_pubkey_hex) { - let deferred6_0; - let deferred6_1; - try { - const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); - const ptr0 = passStringToWasm0(msg, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len0 = WASM_VECTOR_LEN; - const ptr1 = passStringToWasm0(client_partial_sig_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len1 = WASM_VECTOR_LEN; - const ptr2 = passStringToWasm0(server_partial_sig_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len2 = WASM_VECTOR_LEN; - const ptr3 = passStringToWasm0(session_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len3 = WASM_VECTOR_LEN; - const ptr4 = passStringToWasm0(output_pubkey_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len4 = WASM_VECTOR_LEN; - wasm.createSignature(retptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, ptr4, len4); - var r0 = getInt32Memory0()[retptr / 4 + 0]; - var r1 = getInt32Memory0()[retptr / 4 + 1]; - deferred6_0 = r0; - deferred6_1 = r1; - return getStringFromWasm0(r0, r1); - } finally { - wasm.__wbindgen_add_to_stack_pointer(16); - wasm.__wbindgen_free(deferred6_0, deferred6_1, 1); - } -}; - -/** -* @param {string} encoded_unsigned_tx -* @param {string} signature_hex -* @returns {string} -*/ -module.exports.newBackupTransaction = function(encoded_unsigned_tx, signature_hex) { - let deferred3_0; - let deferred3_1; - try { - const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); - const ptr0 = passStringToWasm0(encoded_unsigned_tx, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len0 = WASM_VECTOR_LEN; - const ptr1 = passStringToWasm0(signature_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len1 = WASM_VECTOR_LEN; - wasm.newBackupTransaction(retptr, ptr0, len0, ptr1, len1); - var r0 = getInt32Memory0()[retptr / 4 + 0]; - var r1 = getInt32Memory0()[retptr / 4 + 1]; - deferred3_0 = r0; - deferred3_1 = r1; - return getStringFromWasm0(r0, r1); - } finally { - wasm.__wbindgen_add_to_stack_pointer(16); - wasm.__wbindgen_free(deferred3_0, deferred3_1, 1); - } -}; - -/** -* @param {any} backup_tx_json -* @param {any} coin_json -* @param {string} to_address -* @param {number} fee_rate_sats_per_byte -* @param {string} network -* @returns {string} -*/ -module.exports.createCpfpTx = function(backup_tx_json, coin_json, to_address, fee_rate_sats_per_byte, network) { - let deferred3_0; - let deferred3_1; - try { - const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); - const ptr0 = passStringToWasm0(to_address, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len0 = WASM_VECTOR_LEN; - _assertNum(fee_rate_sats_per_byte); - const ptr1 = passStringToWasm0(network, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len1 = WASM_VECTOR_LEN; - wasm.createCpfpTx(retptr, addHeapObject(backup_tx_json), addHeapObject(coin_json), ptr0, len0, fee_rate_sats_per_byte, ptr1, len1); - var r0 = getInt32Memory0()[retptr / 4 + 0]; - var r1 = getInt32Memory0()[retptr / 4 + 1]; - deferred3_0 = r0; - deferred3_1 = r1; - return getStringFromWasm0(r0, r1); - } finally { - wasm.__wbindgen_add_to_stack_pointer(16); - wasm.__wbindgen_free(deferred3_0, deferred3_1, 1); - } -}; - -/** -* @param {string} recipient_address -* @param {string} input_txid -* @param {number} input_vout -* @param {string} client_seckey -* @returns {string} -*/ -module.exports.createTransferSignature = function(recipient_address, input_txid, input_vout, client_seckey) { - let deferred4_0; - let deferred4_1; - try { - const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); - const ptr0 = passStringToWasm0(recipient_address, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len0 = WASM_VECTOR_LEN; - const ptr1 = passStringToWasm0(input_txid, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len1 = WASM_VECTOR_LEN; - _assertNum(input_vout); - const ptr2 = passStringToWasm0(client_seckey, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len2 = WASM_VECTOR_LEN; - wasm.createTransferSignature(retptr, ptr0, len0, ptr1, len1, input_vout, ptr2, len2); - var r0 = getInt32Memory0()[retptr / 4 + 0]; - var r1 = getInt32Memory0()[retptr / 4 + 1]; - deferred4_0 = r0; - deferred4_1 = r1; - return getStringFromWasm0(r0, r1); - } finally { - wasm.__wbindgen_add_to_stack_pointer(16); - wasm.__wbindgen_free(deferred4_0, deferred4_1, 1); - } -}; - -/** -* @param {string} x1 -* @param {string} recipient_address -* @param {any} coin_json -* @param {string} transfer_signature -* @param {any} backup_transactions -* @returns {any} -*/ -module.exports.createTransferUpdateMsg = function(x1, recipient_address, coin_json, transfer_signature, backup_transactions) { - const ptr0 = passStringToWasm0(x1, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len0 = WASM_VECTOR_LEN; - const ptr1 = passStringToWasm0(recipient_address, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len1 = WASM_VECTOR_LEN; - const ptr2 = passStringToWasm0(transfer_signature, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len2 = WASM_VECTOR_LEN; - const ret = wasm.createTransferUpdateMsg(ptr0, len0, ptr1, len1, addHeapObject(coin_json), ptr2, len2, addHeapObject(backup_transactions)); - return takeObject(ret); -}; - -/** -* @param {string} sc_address -* @returns {any} -*/ -module.exports.decodeTransferAddress = function(sc_address) { - const ptr0 = passStringToWasm0(sc_address, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len0 = WASM_VECTOR_LEN; - const ret = wasm.decodeTransferAddress(ptr0, len0); - return takeObject(ret); -}; - -/** -* @param {string} encrypted_message -* @param {string} private_key_wif -* @returns {any} -*/ -module.exports.decryptTransferMsg = function(encrypted_message, private_key_wif) { - const ptr0 = passStringToWasm0(encrypted_message, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len0 = WASM_VECTOR_LEN; - const ptr1 = passStringToWasm0(private_key_wif, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len1 = WASM_VECTOR_LEN; - const ret = wasm.decryptTransferMsg(ptr0, len0, ptr1, len1); - return takeObject(ret); -}; - -/** -* @param {any} backup_transactions -* @returns {any} -*/ -module.exports.getTx0Outpoint = function(backup_transactions) { - const ret = wasm.getTx0Outpoint(addHeapObject(backup_transactions)); - return takeObject(ret); -}; - -/** -* @param {string} new_user_pubkey -* @param {any} tx0_outpoint -* @param {any} transfer_msg -* @returns {boolean} -*/ -module.exports.verifyTransferSignature = function(new_user_pubkey, tx0_outpoint, transfer_msg) { - const ptr0 = passStringToWasm0(new_user_pubkey, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len0 = WASM_VECTOR_LEN; - const ret = wasm.verifyTransferSignature(ptr0, len0, addHeapObject(tx0_outpoint), addHeapObject(transfer_msg)); - return ret !== 0; -}; - -/** -* @param {string} enclave_public_key -* @param {any} transfer_msg -* @param {any} tx0_outpoint -* @param {string} tx0_hex -* @param {string} network -* @returns {boolean} -*/ -module.exports.validateTx0OutputPubkey = function(enclave_public_key, transfer_msg, tx0_outpoint, tx0_hex, network) { - const ptr0 = passStringToWasm0(enclave_public_key, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len0 = WASM_VECTOR_LEN; - const ptr1 = passStringToWasm0(tx0_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len1 = WASM_VECTOR_LEN; - const ptr2 = passStringToWasm0(network, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len2 = WASM_VECTOR_LEN; - const ret = wasm.validateTx0OutputPubkey(ptr0, len0, addHeapObject(transfer_msg), addHeapObject(tx0_outpoint), ptr1, len1, ptr2, len2); - return ret !== 0; -}; - -/** -* @param {any} transfer_msg -* @param {string} client_pubkey_share -* @param {string} network -* @returns {boolean} -*/ -module.exports.verifyLatestBackupTxPaysToUserPubkey = function(transfer_msg, client_pubkey_share, network) { - const ptr0 = passStringToWasm0(client_pubkey_share, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len0 = WASM_VECTOR_LEN; - const ptr1 = passStringToWasm0(network, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len1 = WASM_VECTOR_LEN; - const ret = wasm.verifyLatestBackupTxPaysToUserPubkey(addHeapObject(transfer_msg), ptr0, len0, ptr1, len1); - return ret !== 0; -}; - -/** -* @param {any} tx0_outpoint -* @param {string} tx0_hex -* @param {string} network -* @returns {string} -*/ -module.exports.getOutputAddressFromTx0 = function(tx0_outpoint, tx0_hex, network) { - let deferred3_0; - let deferred3_1; - try { - const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); - const ptr0 = passStringToWasm0(tx0_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len0 = WASM_VECTOR_LEN; - const ptr1 = passStringToWasm0(network, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len1 = WASM_VECTOR_LEN; - wasm.getOutputAddressFromTx0(retptr, addHeapObject(tx0_outpoint), ptr0, len0, ptr1, len1); - var r0 = getInt32Memory0()[retptr / 4 + 0]; - var r1 = getInt32Memory0()[retptr / 4 + 1]; - deferred3_0 = r0; - deferred3_1 = r1; - return getStringFromWasm0(r0, r1); - } finally { - wasm.__wbindgen_add_to_stack_pointer(16); - wasm.__wbindgen_free(deferred3_0, deferred3_1, 1); - } -}; - -/** -* @param {string} tx_n_hex -* @param {string} tx0_hex -* @param {number} fee_rate_tolerance -* @param {number} current_fee_rate_sats_per_byte -* @returns {any} -*/ -module.exports.verifyTransactionSignature = function(tx_n_hex, tx0_hex, fee_rate_tolerance, current_fee_rate_sats_per_byte) { - const ptr0 = passStringToWasm0(tx_n_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len0 = WASM_VECTOR_LEN; - const ptr1 = passStringToWasm0(tx0_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len1 = WASM_VECTOR_LEN; - _assertNum(fee_rate_tolerance); - _assertNum(current_fee_rate_sats_per_byte); - const ret = wasm.verifyTransactionSignature(ptr0, len0, ptr1, len1, fee_rate_tolerance, current_fee_rate_sats_per_byte); - return takeObject(ret); -}; - -/** -* @param {any} backup_tx -* @param {string} tx0_hex -* @param {any} statechain_info -* @returns {any} -*/ -module.exports.verifyBlindedMusigScheme = function(backup_tx, tx0_hex, statechain_info) { - const ptr0 = passStringToWasm0(tx0_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len0 = WASM_VECTOR_LEN; - const ret = wasm.verifyBlindedMusigScheme(addHeapObject(backup_tx), ptr0, len0, addHeapObject(statechain_info)); - return takeObject(ret); -}; - -/** -* @param {any} backup_tx -* @returns {number} -*/ -module.exports.getBlockheight = function(backup_tx) { - const ret = wasm.getBlockheight(addHeapObject(backup_tx)); - return ret >>> 0; -}; - -/** -* @param {any} statechain_info -* @param {any} transfer_msg -* @param {any} coin -* @returns {any} -*/ -module.exports.createTransferReceiverRequestPayload = function(statechain_info, transfer_msg, coin) { - const ret = wasm.createTransferReceiverRequestPayload(addHeapObject(statechain_info), addHeapObject(transfer_msg), addHeapObject(coin)); - return takeObject(ret); -}; - -/** -* @param {string} server_public_key_hex -* @param {any} coin -* @param {string} statechain_id -* @param {any} tx0_outpoint -* @param {string} tx0_hex -* @param {string} network -* @returns {any} -*/ -module.exports.getNewKeyInfo = function(server_public_key_hex, coin, statechain_id, tx0_outpoint, tx0_hex, network) { - const ptr0 = passStringToWasm0(server_public_key_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len0 = WASM_VECTOR_LEN; - const ptr1 = passStringToWasm0(statechain_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len1 = WASM_VECTOR_LEN; - const ptr2 = passStringToWasm0(tx0_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len2 = WASM_VECTOR_LEN; - const ptr3 = passStringToWasm0(network, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len3 = WASM_VECTOR_LEN; - const ret = wasm.getNewKeyInfo(ptr0, len0, addHeapObject(coin), ptr1, len1, addHeapObject(tx0_outpoint), ptr2, len2, ptr3, len3); - return takeObject(ret); -}; - -/** -* @returns {any} -*/ -module.exports.getMockWallet = function() { - const ret = wasm.getMockWallet(); - return takeObject(ret); -}; - -function logError(f, args) { - try { - return f.apply(this, args); - } catch (e) { - let error = (function () { - try { - return e instanceof Error ? `${e.message}\n\nStack:\n${e.stack}` : e.toString(); - } catch(_) { - return ""; - } - }()); - console.error("wasm-bindgen: imported JS function that was not marked as `catch` threw an error:", error); - throw e; - } -} - -function handleError(f, args) { - try { - return f.apply(this, args); - } catch (e) { - wasm.__wbindgen_exn_store(addHeapObject(e)); - } -} - -module.exports.__wbindgen_is_undefined = function(arg0) { - const ret = getObject(arg0) === undefined; - _assertBoolean(ret); - return ret; -}; - -module.exports.__wbindgen_in = function(arg0, arg1) { - const ret = getObject(arg0) in getObject(arg1); - _assertBoolean(ret); - return ret; -}; - -module.exports.__wbindgen_boolean_get = function(arg0) { - const v = getObject(arg0); - const ret = typeof(v) === 'boolean' ? (v ? 1 : 0) : 2; - _assertNum(ret); - return ret; -}; - -module.exports.__wbindgen_string_get = function(arg0, arg1) { - const obj = getObject(arg1); - const ret = typeof(obj) === 'string' ? obj : undefined; - var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - var len1 = WASM_VECTOR_LEN; - getInt32Memory0()[arg0 / 4 + 1] = len1; - getInt32Memory0()[arg0 / 4 + 0] = ptr1; -}; - -module.exports.__wbindgen_is_object = function(arg0) { - const val = getObject(arg0); - const ret = typeof(val) === 'object' && val !== null; - _assertBoolean(ret); - return ret; -}; - -module.exports.__wbindgen_is_string = function(arg0) { - const ret = typeof(getObject(arg0)) === 'string'; - _assertBoolean(ret); - return ret; -}; - -module.exports.__wbindgen_error_new = function(arg0, arg1) { - const ret = new Error(getStringFromWasm0(arg0, arg1)); - return addHeapObject(ret); -}; - -module.exports.__wbindgen_number_get = function(arg0, arg1) { - const obj = getObject(arg1); - const ret = typeof(obj) === 'number' ? obj : undefined; - if (!isLikeNone(ret)) { - _assertNum(ret); - } - getFloat64Memory0()[arg0 / 8 + 1] = isLikeNone(ret) ? 0 : ret; - getInt32Memory0()[arg0 / 4 + 0] = !isLikeNone(ret); -}; - -module.exports.__wbindgen_number_new = function(arg0) { - const ret = arg0; - return addHeapObject(ret); -}; - -module.exports.__wbindgen_string_new = function(arg0, arg1) { - const ret = getStringFromWasm0(arg0, arg1); - return addHeapObject(ret); -}; - -module.exports.__wbindgen_jsval_loose_eq = function(arg0, arg1) { - const ret = getObject(arg0) == getObject(arg1); - _assertBoolean(ret); - return ret; -}; - -module.exports.__wbindgen_object_clone_ref = function(arg0) { - const ret = getObject(arg0); - return addHeapObject(ret); -}; - -module.exports.__wbg_getwithrefkey_15c62c2b8546208d = function() { return logError(function (arg0, arg1) { - const ret = getObject(arg0)[getObject(arg1)]; - return addHeapObject(ret); -}, arguments) }; - -module.exports.__wbg_set_20cbc34131e76824 = function() { return logError(function (arg0, arg1, arg2) { - getObject(arg0)[takeObject(arg1)] = takeObject(arg2); -}, arguments) }; - -module.exports.__wbindgen_object_drop_ref = function(arg0) { - takeObject(arg0); -}; - -module.exports.__wbg_crypto_c48a774b022d20ac = function() { return logError(function (arg0) { - const ret = getObject(arg0).crypto; - return addHeapObject(ret); -}, arguments) }; - -module.exports.__wbg_msCrypto_bcb970640f50a1e8 = function() { return logError(function (arg0) { - const ret = getObject(arg0).msCrypto; - return addHeapObject(ret); -}, arguments) }; - -module.exports.__wbg_getRandomValues_37fa2ca9e4e07fab = function() { return handleError(function (arg0, arg1) { - getObject(arg0).getRandomValues(getObject(arg1)); -}, arguments) }; - -module.exports.__wbg_randomFillSync_dc1e9a60c158336d = function() { return handleError(function (arg0, arg1) { - getObject(arg0).randomFillSync(takeObject(arg1)); -}, arguments) }; - -module.exports.__wbg_require_8f08ceecec0f4fee = function() { return handleError(function () { - const ret = module.require; - return addHeapObject(ret); -}, arguments) }; - -module.exports.__wbg_process_298734cf255a885d = function() { return logError(function (arg0) { - const ret = getObject(arg0).process; - return addHeapObject(ret); -}, arguments) }; - -module.exports.__wbg_versions_e2e78e134e3e5d01 = function() { return logError(function (arg0) { - const ret = getObject(arg0).versions; - return addHeapObject(ret); -}, arguments) }; - -module.exports.__wbg_node_1cd7a5d853dbea79 = function() { return logError(function (arg0) { - const ret = getObject(arg0).node; - return addHeapObject(ret); -}, arguments) }; - -module.exports.__wbg_new_898a68150f225f2e = function() { return logError(function () { - const ret = new Array(); - return addHeapObject(ret); -}, arguments) }; - -module.exports.__wbg_get_44be0491f933a435 = function() { return logError(function (arg0, arg1) { - const ret = getObject(arg0)[arg1 >>> 0]; - return addHeapObject(ret); -}, arguments) }; - -module.exports.__wbg_set_502d29070ea18557 = function() { return logError(function (arg0, arg1, arg2) { - getObject(arg0)[arg1 >>> 0] = takeObject(arg2); -}, arguments) }; - -module.exports.__wbg_isArray_4c24b343cb13cfb1 = function() { return logError(function (arg0) { - const ret = Array.isArray(getObject(arg0)); - _assertBoolean(ret); - return ret; -}, arguments) }; - -module.exports.__wbg_length_fff51ee6522a1a18 = function() { return logError(function (arg0) { - const ret = getObject(arg0).length; - _assertNum(ret); - return ret; -}, arguments) }; - -module.exports.__wbg_instanceof_ArrayBuffer_39ac22089b74fddb = function() { return logError(function (arg0) { - let result; - try { - result = getObject(arg0) instanceof ArrayBuffer; - } catch { - result = false; - } - const ret = result; - _assertBoolean(ret); - return ret; -}, arguments) }; - -module.exports.__wbg_newnoargs_581967eacc0e2604 = function() { return logError(function (arg0, arg1) { - const ret = new Function(getStringFromWasm0(arg0, arg1)); - return addHeapObject(ret); -}, arguments) }; - -module.exports.__wbg_call_cb65541d95d71282 = function() { return handleError(function (arg0, arg1) { - const ret = getObject(arg0).call(getObject(arg1)); - return addHeapObject(ret); -}, arguments) }; - -module.exports.__wbg_call_01734de55d61e11d = function() { return handleError(function (arg0, arg1, arg2) { - const ret = getObject(arg0).call(getObject(arg1), getObject(arg2)); - return addHeapObject(ret); -}, arguments) }; - -module.exports.__wbg_next_ddb3312ca1c4e32a = function() { return handleError(function (arg0) { - const ret = getObject(arg0).next(); - return addHeapObject(ret); -}, arguments) }; - -module.exports.__wbg_next_526fc47e980da008 = function() { return logError(function (arg0) { - const ret = getObject(arg0).next; - return addHeapObject(ret); -}, arguments) }; - -module.exports.__wbg_done_5c1f01fb660d73b5 = function() { return logError(function (arg0) { - const ret = getObject(arg0).done; - _assertBoolean(ret); - return ret; -}, arguments) }; - -module.exports.__wbg_value_1695675138684bd5 = function() { return logError(function (arg0) { - const ret = getObject(arg0).value; - return addHeapObject(ret); -}, arguments) }; - -module.exports.__wbg_isSafeInteger_bb8e18dd21c97288 = function() { return logError(function (arg0) { - const ret = Number.isSafeInteger(getObject(arg0)); - _assertBoolean(ret); - return ret; -}, arguments) }; - -module.exports.__wbg_entries_e51f29c7bba0c054 = function() { return logError(function (arg0) { - const ret = Object.entries(getObject(arg0)); - return addHeapObject(ret); -}, arguments) }; - -module.exports.__wbg_new_b51585de1b234aff = function() { return logError(function () { - const ret = new Object(); - return addHeapObject(ret); -}, arguments) }; - -module.exports.__wbg_iterator_97f0c81209c6c35a = function() { return logError(function () { - const ret = Symbol.iterator; - return addHeapObject(ret); -}, arguments) }; - -module.exports.__wbg_globalThis_1d39714405582d3c = function() { return handleError(function () { - const ret = globalThis.globalThis; - return addHeapObject(ret); -}, arguments) }; - -module.exports.__wbg_self_1ff1d729e9aae938 = function() { return handleError(function () { - const ret = self.self; - return addHeapObject(ret); -}, arguments) }; - -module.exports.__wbg_window_5f4faef6c12b79ec = function() { return handleError(function () { - const ret = window.window; - return addHeapObject(ret); -}, arguments) }; - -module.exports.__wbg_global_651f05c6a0944d1c = function() { return handleError(function () { - const ret = global.global; - return addHeapObject(ret); -}, arguments) }; - -module.exports.__wbg_instanceof_Uint8Array_d8d9cb2b8e8ac1d4 = function() { return logError(function (arg0) { - let result; - try { - result = getObject(arg0) instanceof Uint8Array; - } catch { - result = false; - } - const ret = result; - _assertBoolean(ret); - return ret; -}, arguments) }; - -module.exports.__wbg_new_8125e318e6245eed = function() { return logError(function (arg0) { - const ret = new Uint8Array(getObject(arg0)); - return addHeapObject(ret); -}, arguments) }; - -module.exports.__wbg_newwithlength_e5d69174d6984cd7 = function() { return logError(function (arg0) { - const ret = new Uint8Array(arg0 >>> 0); - return addHeapObject(ret); -}, arguments) }; - -module.exports.__wbg_newwithbyteoffsetandlength_6da8e527659b86aa = function() { return logError(function (arg0, arg1, arg2) { - const ret = new Uint8Array(getObject(arg0), arg1 >>> 0, arg2 >>> 0); - return addHeapObject(ret); -}, arguments) }; - -module.exports.__wbg_subarray_13db269f57aa838d = function() { return logError(function (arg0, arg1, arg2) { - const ret = getObject(arg0).subarray(arg1 >>> 0, arg2 >>> 0); - return addHeapObject(ret); -}, arguments) }; - -module.exports.__wbg_length_72e2208bbc0efc61 = function() { return logError(function (arg0) { - const ret = getObject(arg0).length; - _assertNum(ret); - return ret; -}, arguments) }; - -module.exports.__wbg_set_5cf90238115182c3 = function() { return logError(function (arg0, arg1, arg2) { - getObject(arg0).set(getObject(arg1), arg2 >>> 0); -}, arguments) }; - -module.exports.__wbindgen_is_function = function(arg0) { - const ret = typeof(getObject(arg0)) === 'function'; - _assertBoolean(ret); - return ret; -}; - -module.exports.__wbg_buffer_085ec1f694018c4f = function() { return logError(function (arg0) { - const ret = getObject(arg0).buffer; - return addHeapObject(ret); -}, arguments) }; - -module.exports.__wbg_get_97b561fb56f034b5 = function() { return handleError(function (arg0, arg1) { - const ret = Reflect.get(getObject(arg0), getObject(arg1)); - return addHeapObject(ret); -}, arguments) }; - -module.exports.__wbindgen_debug_string = function(arg0, arg1) { - const ret = debugString(getObject(arg1)); - const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len1 = WASM_VECTOR_LEN; - getInt32Memory0()[arg0 / 4 + 1] = len1; - getInt32Memory0()[arg0 / 4 + 0] = ptr1; -}; - -module.exports.__wbindgen_throw = function(arg0, arg1) { - throw new Error(getStringFromWasm0(arg0, arg1)); -}; - -module.exports.__wbindgen_memory = function() { - const ret = wasm.memory; - return addHeapObject(ret); -}; - -const path = require('path').join(__dirname, 'mercury_wasm_bg.wasm'); -const bytes = require('fs').readFileSync(path); - -const wasmModule = new WebAssembly.Module(bytes); -const wasmInstance = new WebAssembly.Instance(wasmModule, imports); -wasm = wasmInstance.exports; -module.exports.__wasm = wasm; - diff --git a/wasm/node_pkg/mercury_wasm_bg.wasm b/wasm/node_pkg/mercury_wasm_bg.wasm deleted file mode 100644 index 7549133e..00000000 Binary files a/wasm/node_pkg/mercury_wasm_bg.wasm and /dev/null differ diff --git a/wasm/node_pkg/mercury_wasm_bg.wasm.d.ts b/wasm/node_pkg/mercury_wasm_bg.wasm.d.ts deleted file mode 100644 index 28eed6df..00000000 --- a/wasm/node_pkg/mercury_wasm_bg.wasm.d.ts +++ /dev/null @@ -1,50 +0,0 @@ -/* tslint:disable */ -/* eslint-disable */ -export const memory: WebAssembly.Memory; -export function setConfig(a: number, b: number): number; -export function setBlockheight(a: number, b: number): number; -export function addToken(a: number, b: number): number; -export function confirmToken(a: number, b: number, c: number): number; -export function getTokens(a: number): number; -export function getBalance(a: number): number; -export function getSCAddress(a: number, b: number, c: number): void; -export function generateMnemonic(a: number): void; -export function fromMnemonic(a: number, b: number, c: number, d: number): number; -export function getActivityLog(a: number): number; -export function getCoins(a: number): number; -export function getNewCoin(a: number): number; -export function createDepositMsg1(a: number, b: number, c: number): number; -export function handleDepositMsg1Response(a: number, b: number): number; -export function createAggregatedAddress(a: number, b: number, c: number): number; -export function createAndCommitNonces(a: number): number; -export function getUserBackupAddress(a: number, b: number, c: number, d: number): void; -export function getPartialSigRequest(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number): number; -export function createSignature(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number): void; -export function newBackupTransaction(a: number, b: number, c: number, d: number, e: number): void; -export function createCpfpTx(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number): void; -export function createTransferSignature(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number): void; -export function createTransferUpdateMsg(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number): number; -export function decodeTransferAddress(a: number, b: number): number; -export function decryptTransferMsg(a: number, b: number, c: number, d: number): number; -export function getTx0Outpoint(a: number): number; -export function verifyTransferSignature(a: number, b: number, c: number, d: number): number; -export function validateTx0OutputPubkey(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number): number; -export function verifyLatestBackupTxPaysToUserPubkey(a: number, b: number, c: number, d: number, e: number): number; -export function getOutputAddressFromTx0(a: number, b: number, c: number, d: number, e: number, f: number): void; -export function verifyTransactionSignature(a: number, b: number, c: number, d: number, e: number, f: number): number; -export function verifyBlindedMusigScheme(a: number, b: number, c: number, d: number): number; -export function getBlockheight(a: number): number; -export function createTransferReceiverRequestPayload(a: number, b: number, c: number): number; -export function getNewKeyInfo(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number): number; -export function getMockWallet(): number; -export function rustsecp256k1zkp_v0_8_1_default_illegal_callback_fn(a: number, b: number): void; -export function rustsecp256k1zkp_v0_8_1_default_error_callback_fn(a: number, b: number): void; -export function rustsecp256k1_v0_8_1_context_create(a: number): number; -export function rustsecp256k1_v0_8_1_context_destroy(a: number): void; -export function rustsecp256k1_v0_8_1_default_illegal_callback_fn(a: number, b: number): void; -export function rustsecp256k1_v0_8_1_default_error_callback_fn(a: number, b: number): void; -export function __wbindgen_malloc(a: number, b: number): number; -export function __wbindgen_realloc(a: number, b: number, c: number, d: number): number; -export function __wbindgen_add_to_stack_pointer(a: number): number; -export function __wbindgen_free(a: number, b: number, c: number): void; -export function __wbindgen_exn_store(a: number): void; diff --git a/wasm/node_pkg/package.json b/wasm/node_pkg/package.json deleted file mode 100644 index e9330880..00000000 --- a/wasm/node_pkg/package.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "name": "mercury-wasm", - "collaborators": [ - "ttrevethan" - ], - "version": "0.1.0", - "files": [ - "mercury_wasm_bg.wasm", - "mercury_wasm.js", - "mercury_wasm.d.ts" - ], - "main": "mercury_wasm.js", - "types": "mercury_wasm.d.ts" -} \ No newline at end of file diff --git a/wasm/src/lib.rs b/wasm/src/lib.rs index fef709e2..338fc8eb 100644 --- a/wasm/src/lib.rs +++ b/wasm/src/lib.rs @@ -2,7 +2,7 @@ mod utils; -use mercury_lib::{decode_transfer_address, deposit::DepositMsg1Response, transfer::{receiver::{create_transfer_receiver_request_payload, decrypt_transfer_msg, get_new_key_info, StatechainInfo, StatechainInfoResponsePayload, TxOutpoint}, sender::create_transfer_signature, TransferMsg}, utils::ServerConfig, wallet::{Activity, BackupTx, Coin, Settings, Token, Wallet}}; +use mercurylib::{decode_transfer_address, deposit::DepositMsg1Response, transfer::{receiver::{create_transfer_receiver_request_payload, decrypt_transfer_msg, get_new_key_info, StatechainInfo, StatechainInfoResponsePayload, TxOutpoint}, sender::create_transfer_signature, TransferMsg}, utils::ServerConfig, wallet::{Activity, BackupTx, Coin, Settings, Token, Wallet}}; use wasm_bindgen::prelude::*; use serde::{Serialize, Deserialize}; use bip39::Mnemonic; @@ -48,7 +48,7 @@ pub fn setConfig(config_json: JsValue, wallet_json: JsValue) -> JsValue { let mut wallet: Wallet = serde_wasm_bindgen::from_value(wallet_json).unwrap(); let config: ServerConfig = serde_wasm_bindgen::from_value(config_json).unwrap(); - mercury_lib::wallet::set_config(&mut wallet, &config); + mercurylib::wallet::set_config(&mut wallet, &config); serde_wasm_bindgen::to_value(&wallet).unwrap() } @@ -98,7 +98,7 @@ pub fn getBalance(wallet_json: JsValue) -> u32 { #[wasm_bindgen] pub fn getSCAddress(wallet_json: JsValue, index: u32, network: String) -> String { let wallet: Wallet = serde_wasm_bindgen::from_value(wallet_json).unwrap(); - let address = mercury_lib::get_sc_address(&wallet.mnemonic, index, &network).unwrap(); + let address = mercurylib::get_sc_address(&wallet.mnemonic, index, &network).unwrap(); address.to_string() } @@ -170,7 +170,7 @@ pub fn getNewCoin(wallet_json: JsValue) -> JsValue { #[wasm_bindgen] pub fn createDepositMsg1(coin_json: JsValue, token_id: String) -> JsValue { let coin: Coin = serde_wasm_bindgen::from_value(coin_json).unwrap(); - let deposit_msg_1 = mercury_lib::deposit::create_deposit_msg1(&coin, &token_id).unwrap(); + let deposit_msg_1 = mercurylib::deposit::create_deposit_msg1(&coin, &token_id).unwrap(); serde_wasm_bindgen::to_value(&deposit_msg_1).unwrap() } @@ -178,28 +178,28 @@ pub fn createDepositMsg1(coin_json: JsValue, token_id: String) -> JsValue { pub fn handleDepositMsg1Response(coin_json: JsValue, deposit_msg_1_response_json: JsValue) -> JsValue { let coin: Coin = serde_wasm_bindgen::from_value(coin_json).unwrap(); let deposit_msg_1_response: DepositMsg1Response = serde_wasm_bindgen::from_value(deposit_msg_1_response_json).unwrap(); - let deposit_init_result = mercury_lib::deposit::handle_deposit_msg_1_response(&coin, &deposit_msg_1_response).unwrap(); + let deposit_init_result = mercurylib::deposit::handle_deposit_msg_1_response(&coin, &deposit_msg_1_response).unwrap(); serde_wasm_bindgen::to_value(&deposit_init_result).unwrap() } #[wasm_bindgen] pub fn createAggregatedAddress(coin_json: JsValue, network: String) -> JsValue { let coin: Coin = serde_wasm_bindgen::from_value(coin_json).unwrap(); - let aggregated_public_key = mercury_lib::deposit::create_aggregated_address(&coin, network).unwrap(); + let aggregated_public_key = mercurylib::deposit::create_aggregated_address(&coin, network).unwrap(); serde_wasm_bindgen::to_value(&aggregated_public_key).unwrap() } #[wasm_bindgen] pub fn createAndCommitNonces(coin_json: JsValue) -> JsValue { let coin: Coin = serde_wasm_bindgen::from_value(coin_json).unwrap(); - let coin_nonce = mercury_lib::transaction::create_and_commit_nonces(&coin).unwrap(); + let coin_nonce = mercurylib::transaction::create_and_commit_nonces(&coin).unwrap(); serde_wasm_bindgen::to_value(&coin_nonce).unwrap() } #[wasm_bindgen] pub fn getUserBackupAddress(coin_json: JsValue, network: String) -> String { let coin: Coin = serde_wasm_bindgen::from_value(coin_json).unwrap(); - let backup_address = mercury_lib::transaction::get_user_backup_address(&coin, network).unwrap(); + let backup_address = mercurylib::transaction::get_user_backup_address(&coin, network).unwrap(); backup_address } @@ -217,7 +217,7 @@ pub fn getPartialSigRequest( { let coin: Coin = serde_wasm_bindgen::from_value(coin_json).unwrap(); - let partial_sig_request = mercury_lib::transaction::get_partial_sig_request( + let partial_sig_request = mercurylib::transaction::get_partial_sig_request( &coin, block_height, initlock, @@ -239,14 +239,14 @@ pub fn createSignature( session_hex: String, output_pubkey_hex: String) -> String { - let signature = mercury_lib::transaction::create_signature(msg, client_partial_sig_hex, server_partial_sig_hex, session_hex, output_pubkey_hex).unwrap(); + let signature = mercurylib::transaction::create_signature(msg, client_partial_sig_hex, server_partial_sig_hex, session_hex, output_pubkey_hex).unwrap(); signature } #[wasm_bindgen] pub fn newBackupTransaction(encoded_unsigned_tx: String, signature_hex: String) -> String { - let backup_tx = mercury_lib::transaction::new_backup_transaction(encoded_unsigned_tx, signature_hex).unwrap(); + let backup_tx = mercurylib::transaction::new_backup_transaction(encoded_unsigned_tx, signature_hex).unwrap(); backup_tx } @@ -255,7 +255,7 @@ pub fn createCpfpTx(backup_tx_json: JsValue, coin_json: JsValue, to_address: Str let coin: Coin = serde_wasm_bindgen::from_value(coin_json).unwrap(); let backup_tx: BackupTx = serde_wasm_bindgen::from_value(backup_tx_json).unwrap(); - let backup_tx = mercury_lib::wallet::cpfp_tx::create(&backup_tx, &coin, &to_address, fee_rate_sats_per_byte as u64, &network).unwrap(); + let backup_tx = mercurylib::wallet::cpfp_tx::create(&backup_tx, &coin, &to_address, fee_rate_sats_per_byte as u64, &network).unwrap(); backup_tx // "".to_string() } @@ -271,7 +271,7 @@ pub fn createTransferUpdateMsg(x1: String, recipient_address: String, coin_json: let coin: Coin = serde_wasm_bindgen::from_value(coin_json).unwrap(); let backup_transactions: Vec = serde_wasm_bindgen::from_value(backup_transactions).unwrap(); - let transfer_update_msg_request_payload = mercury_lib::transfer::sender::create_transfer_update_msg(&x1, &recipient_address, &coin, &transfer_signature, &backup_transactions).unwrap(); + let transfer_update_msg_request_payload = mercurylib::transfer::sender::create_transfer_update_msg(&x1, &recipient_address, &coin, &transfer_signature, &backup_transactions).unwrap(); serde_wasm_bindgen::to_value(&transfer_update_msg_request_payload).unwrap() } @@ -306,7 +306,7 @@ pub fn decryptTransferMsg(encrypted_message: String, private_key_wif: String) -> #[wasm_bindgen] pub fn getTx0Outpoint(backup_transactions: JsValue) -> JsValue { let backup_transactions: Vec = serde_wasm_bindgen::from_value(backup_transactions).unwrap(); - let tx0_outpoint = mercury_lib::transfer::receiver::get_tx0_outpoint(&backup_transactions).unwrap(); + let tx0_outpoint = mercurylib::transfer::receiver::get_tx0_outpoint(&backup_transactions).unwrap(); serde_wasm_bindgen::to_value(&tx0_outpoint).unwrap() } @@ -314,7 +314,7 @@ pub fn getTx0Outpoint(backup_transactions: JsValue) -> JsValue { pub fn verifyTransferSignature(new_user_pubkey: String, tx0_outpoint: JsValue, transfer_msg: JsValue) -> bool { let tx0_outpoint: TxOutpoint = serde_wasm_bindgen::from_value(tx0_outpoint).unwrap(); let transfer_msg: TransferMsg = serde_wasm_bindgen::from_value(transfer_msg).unwrap(); - let result = mercury_lib::transfer::receiver::verify_transfer_signature(&new_user_pubkey, &tx0_outpoint, &transfer_msg).unwrap(); + let result = mercurylib::transfer::receiver::verify_transfer_signature(&new_user_pubkey, &tx0_outpoint, &transfer_msg).unwrap(); result } @@ -322,27 +322,27 @@ pub fn verifyTransferSignature(new_user_pubkey: String, tx0_outpoint: JsValue, t pub fn validateTx0OutputPubkey(enclave_public_key: String, transfer_msg: JsValue, tx0_outpoint: JsValue, tx0_hex: String, network: String) -> bool { let tx0_outpoint: TxOutpoint = serde_wasm_bindgen::from_value(tx0_outpoint).unwrap(); let transfer_msg: TransferMsg = serde_wasm_bindgen::from_value(transfer_msg).unwrap(); - let result = mercury_lib::transfer::receiver::validate_tx0_output_pubkey(&enclave_public_key, &transfer_msg, &tx0_outpoint, &tx0_hex, &network).unwrap(); + let result = mercurylib::transfer::receiver::validate_tx0_output_pubkey(&enclave_public_key, &transfer_msg, &tx0_outpoint, &tx0_hex, &network).unwrap(); result } #[wasm_bindgen] pub fn verifyLatestBackupTxPaysToUserPubkey(transfer_msg: JsValue, client_pubkey_share: String, network: String) -> bool { let transfer_msg: TransferMsg = serde_wasm_bindgen::from_value(transfer_msg).unwrap(); - let result = mercury_lib::transfer::receiver::verify_latest_backup_tx_pays_to_user_pubkey(&transfer_msg, &client_pubkey_share, &network).unwrap(); + let result = mercurylib::transfer::receiver::verify_latest_backup_tx_pays_to_user_pubkey(&transfer_msg, &client_pubkey_share, &network).unwrap(); result } #[wasm_bindgen] pub fn getOutputAddressFromTx0(tx0_outpoint: JsValue, tx0_hex: String, network: String) -> String { let tx0_outpoint: TxOutpoint = serde_wasm_bindgen::from_value(tx0_outpoint).unwrap(); - let output_address = mercury_lib::transfer::receiver::get_output_address_from_tx0(&tx0_outpoint, &tx0_hex, &network).unwrap(); + let output_address = mercurylib::transfer::receiver::get_output_address_from_tx0(&tx0_outpoint, &tx0_hex, &network).unwrap(); output_address } #[wasm_bindgen] pub fn verifyTransactionSignature(tx_n_hex: String, tx0_hex: String, fee_rate_tolerance: u32, current_fee_rate_sats_per_byte: u32) -> JsValue { - let result = mercury_lib::transfer::receiver::verify_transaction_signature(&tx_n_hex, &tx0_hex, fee_rate_tolerance, current_fee_rate_sats_per_byte); + let result = mercurylib::transfer::receiver::verify_transaction_signature(&tx_n_hex, &tx0_hex, fee_rate_tolerance, current_fee_rate_sats_per_byte); #[derive(Serialize, Deserialize)] struct ValidationResult { @@ -368,7 +368,7 @@ pub fn verifyBlindedMusigScheme(backup_tx: JsValue, tx0_hex: String, statechain_ let backup_tx: BackupTx = serde_wasm_bindgen::from_value(backup_tx).unwrap(); let statechain_info: StatechainInfo = serde_wasm_bindgen::from_value(statechain_info).unwrap(); - let result = mercury_lib::transfer::receiver::verify_blinded_musig_scheme(&backup_tx, &tx0_hex, &statechain_info); + let result = mercurylib::transfer::receiver::verify_blinded_musig_scheme(&backup_tx, &tx0_hex, &statechain_info); #[derive(Serialize, Deserialize)] struct ValidationResult { result: bool, @@ -390,7 +390,7 @@ pub fn verifyBlindedMusigScheme(backup_tx: JsValue, tx0_hex: String, statechain_ #[wasm_bindgen] pub fn getBlockheight(backup_tx: JsValue) -> u32 { let backup_tx: BackupTx = serde_wasm_bindgen::from_value(backup_tx).unwrap(); - let blockheight = mercury_lib::utils::get_blockheight(&backup_tx).unwrap(); + let blockheight = mercurylib::utils::get_blockheight(&backup_tx).unwrap(); blockheight } @@ -414,31 +414,13 @@ pub fn getNewKeyInfo(server_public_key_hex: String, coin: JsValue, statechain_id serde_wasm_bindgen::to_value(&new_key_info).unwrap() } - -// pub fn create_transfer_update_msg(x1: &str, recipient_address: &str, coin: &Coin, transfer_signature: &str, backup_transactions: &Vec) -> Result { -/* #[wasm_bindgen] -pub fn getCoin(wallet_json: JsValue, statechain_id: String) -> JsValue { - let wallet: Wallet = serde_wasm_bindgen::from_value(wallet_json).unwrap(); - for coin in wallet.coins.iter() { - if coin.statechain_id == statechain_id { - return serde_wasm_bindgen::to_value(&coin).unwrap(); - } - } - serde_wasm_bindgen::to_value(&Coin { - utxo: String::from(""), - index: 0, - address: String::from(""), - amount: 0, - statechain_id: String::from(""), - privkey: String::from(""), - auth_key: String::from(""), - locktime: 0, - status: String::from(""), - }).unwrap() -} - */ +pub fn validateAddress(address: String, network: String) -> bool { + let result = mercurylib::validate_address(&address, &network).unwrap(); + result +} + #[wasm_bindgen] pub fn getMockWallet() -> JsValue { let tokens = vec![ @@ -485,42 +467,6 @@ pub fn getMockWallet() -> JsValue { } ]; - /*let coins = vec![ - Coin { - utxo: String::from("9ec324592502d377dc92cee0cce84b532ce912e0379bdd3d768339819251cf57:0"), - index: 1, - address: String::from("sc1qd8tt2cme0heruuf9zlxeygq96lum7qzl4tf32hnkyvlta9gqvumud8su7pvdzelx5ku2hrggwhuv5v3x824re8gcjl7yhq4quhtf5vfgwszp5"), - amount: 100, - statechain_id: String::from("6bbf638f-107f-4ea0-8e72-1a72b7e8155b"), - privkey: String::from("fed3c39e0b1a2cfcd4b71571a10ebf194644c7554793a312ff8970541cbad346"), - auth_key: String::from("f5a3717cfff6a03f8f8d8681b34558ac60f706ee3e68b29b6c130acd45c33da1"), - locktime: 854231, - status: String::from("Confirmed"), - }, - Coin { - utxo: String::from("e29e13b48c83b40e1fd81120c55144c5593dca6017f098422983f7dfaeb70913:0"), - index: 2, - address: String::from("sc1qd8tt2cme0heruuf9zlxeygq96lum7qzl4tf32hnkyvlta9gqvumud8su7pvdzelx5ku2hrggwhuv5v3x824re8gcjl7yhq4quhtf5vfgwszp5"), - amount: 200, - statechain_id: String::from("aed9a34c-5666-4d83-940f-9b74e16b8672"), - privkey: String::from("60e9cec644dc22e0137088729d61372436de6067a7625b3b0733bf0c98ae04a2"), - auth_key: String::from("a3e88f9f13ef06cd35ac55d2c34c8ce2e8874cccb50e2545975f046f7acee8f1"), - locktime: 845321, - status: String::from("Confirmed"), - }, - Coin { - utxo: String::from("84fa1bd2ff0fb9bd5ee4256671c4f6a40dca311e5301668b282dbf66a6bedcc6100p:0"), - index: 3, - address: String::from("sc1qd8tt2cme0heruuf9zlxeygq96lum7qzl4tf32hnkyvlta9gqvumud8su7pvdzelx5ku2hrggwhuv5v3x824re8gcjl7yhq4quhtf5vfgwszp5"), - amount: 300, - statechain_id: String::from("b94cba9b-93f8-419f-8adb-a943125a20f8"), - privkey: String::from("60e9cec644dc22e0137088729d61372436de6067a7625b3b0733bf0c98ae04a2"), - auth_key: String::from("a3e88f9f13ef06cd35ac55d2c34c8ce2e8874cccb50e2545975f046f7acee8f1"), - locktime: 835321, - status: String::from("Confirmed"), - } - ]; */ - let settings = Settings { network: String::from("signet"), block_explorerURL: None, diff --git a/wasm/web_pkg/README.md b/wasm/web_pkg/README.md deleted file mode 100644 index c82e8b3d..00000000 --- a/wasm/web_pkg/README.md +++ /dev/null @@ -1,15 +0,0 @@ -# Mercury layer WASM library - -A `wasm-bindgen` library of functions for the mercury layer clients. - -This project works only with clang 14. -Building it with a higher version will fail. - -To build with `wasm-pack`: - -``` -# For web -wasm-pack build --release --target web -# Or for nodejs -wasm-pack build --release --target nodejs -``` \ No newline at end of file diff --git a/wasm/web_pkg/mercury_wasm.d.ts b/wasm/web_pkg/mercury_wasm.d.ts deleted file mode 100644 index 08006c79..00000000 --- a/wasm/web_pkg/mercury_wasm.d.ts +++ /dev/null @@ -1,311 +0,0 @@ -/* tslint:disable */ -/* eslint-disable */ -/** -* @param {any} config_json -* @param {any} wallet_json -* @returns {any} -*/ -export function setConfig(config_json: any, wallet_json: any): any; -/** -* @param {number} blockheight -* @param {any} wallet_json -* @returns {any} -*/ -export function setBlockheight(blockheight: number, wallet_json: any): any; -/** -* @param {any} token_json -* @param {any} wallet_json -* @returns {any} -*/ -export function addToken(token_json: any, wallet_json: any): any; -/** -* @param {string} token_id -* @param {any} wallet_json -* @returns {any} -*/ -export function confirmToken(token_id: string, wallet_json: any): any; -/** -* @param {any} wallet_json -* @returns {any} -*/ -export function getTokens(wallet_json: any): any; -/** -* @param {any} wallet_json -* @returns {number} -*/ -export function getBalance(wallet_json: any): number; -/** -* @param {any} wallet_json -* @param {number} index -* @returns {string} -*/ -export function getSCAddress(wallet_json: any, index: number): string; -/** -* @returns {string} -*/ -export function generateMnemonic(): string; -/** -* @param {string} name -* @param {string} mnemonic -* @returns {any} -*/ -export function fromMnemonic(name: string, mnemonic: string): any; -/** -* @param {any} wallet_json -* @returns {any} -*/ -export function getActivityLog(wallet_json: any): any; -/** -* @param {any} wallet_json -* @returns {any} -*/ -export function getCoins(wallet_json: any): any; -/** -* @param {any} wallet_json -* @returns {any} -*/ -export function getNewCoin(wallet_json: any): any; -/** -* @param {any} coin_json -* @param {string} token_id -* @returns {any} -*/ -export function createDepositMsg1(coin_json: any, token_id: string): any; -/** -* @param {any} coin_json -* @param {any} deposit_msg_1_response_json -* @returns {any} -*/ -export function handleDepositMsg1Response(coin_json: any, deposit_msg_1_response_json: any): any; -/** -* @param {any} coin_json -* @param {string} network -* @returns {any} -*/ -export function createAggregatedAddress(coin_json: any, network: string): any; -/** -* @param {any} coin_json -* @returns {any} -*/ -export function createAndCommitNonces(coin_json: any): any; -/** -* @param {any} coin_json -* @param {string} network -* @returns {string} -*/ -export function getUserBackupAddress(coin_json: any, network: string): string; -/** -* @param {any} coin_json -* @param {number} block_height -* @param {number} initlock -* @param {number} interval -* @param {number} fee_rate_sats_per_byte -* @param {number} qt_backup_tx -* @param {string} to_address -* @param {string} network -* @param {boolean} is_withdrawal -* @returns {any} -*/ -export function getPartialSigRequest(coin_json: any, block_height: number, initlock: number, interval: number, fee_rate_sats_per_byte: number, qt_backup_tx: number, to_address: string, network: string, is_withdrawal: boolean): any; -/** -* @param {string} msg -* @param {string} client_partial_sig_hex -* @param {string} server_partial_sig_hex -* @param {string} session_hex -* @param {string} output_pubkey_hex -* @returns {string} -*/ -export function createSignature(msg: string, client_partial_sig_hex: string, server_partial_sig_hex: string, session_hex: string, output_pubkey_hex: string): string; -/** -* @param {string} encoded_unsigned_tx -* @param {string} signature_hex -* @returns {string} -*/ -export function newBackupTransaction(encoded_unsigned_tx: string, signature_hex: string): string; -/** -* @param {any} backup_tx_json -* @param {any} coin_json -* @param {string} to_address -* @param {number} fee_rate_sats_per_byte -* @param {string} network -* @returns {string} -*/ -export function createCpfpTx(backup_tx_json: any, coin_json: any, to_address: string, fee_rate_sats_per_byte: number, network: string): string; -/** -* @param {string} recipient_address -* @param {string} input_txid -* @param {number} input_vout -* @param {string} client_seckey -* @returns {string} -*/ -export function createTransferSignature(recipient_address: string, input_txid: string, input_vout: number, client_seckey: string): string; -/** -* @param {string} x1 -* @param {string} recipient_address -* @param {any} coin_json -* @param {string} transfer_signature -* @param {any} backup_transactions -* @returns {any} -*/ -export function createTransferUpdateMsg(x1: string, recipient_address: string, coin_json: any, transfer_signature: string, backup_transactions: any): any; -/** -* @param {string} sc_address -* @returns {any} -*/ -export function decodeTransferAddress(sc_address: string): any; -/** -* @param {string} encrypted_message -* @param {string} private_key_wif -* @returns {any} -*/ -export function decryptTransferMsg(encrypted_message: string, private_key_wif: string): any; -/** -* @param {any} backup_transactions -* @returns {any} -*/ -export function getTx0Outpoint(backup_transactions: any): any; -/** -* @param {string} new_user_pubkey -* @param {any} tx0_outpoint -* @param {any} transfer_msg -* @returns {boolean} -*/ -export function verifyTransferSignature(new_user_pubkey: string, tx0_outpoint: any, transfer_msg: any): boolean; -/** -* @param {string} enclave_public_key -* @param {any} transfer_msg -* @param {any} tx0_outpoint -* @param {string} tx0_hex -* @param {string} network -* @returns {boolean} -*/ -export function validateTx0OutputPubkey(enclave_public_key: string, transfer_msg: any, tx0_outpoint: any, tx0_hex: string, network: string): boolean; -/** -* @param {any} transfer_msg -* @param {string} client_pubkey_share -* @param {string} network -* @returns {boolean} -*/ -export function verifyLatestBackupTxPaysToUserPubkey(transfer_msg: any, client_pubkey_share: string, network: string): boolean; -/** -* @param {any} tx0_outpoint -* @param {string} tx0_hex -* @param {string} network -* @returns {string} -*/ -export function getOutputAddressFromTx0(tx0_outpoint: any, tx0_hex: string, network: string): string; -/** -* @param {string} tx_n_hex -* @param {string} tx0_hex -* @param {number} fee_rate_tolerance -* @param {number} current_fee_rate_sats_per_byte -* @returns {any} -*/ -export function verifyTransactionSignature(tx_n_hex: string, tx0_hex: string, fee_rate_tolerance: number, current_fee_rate_sats_per_byte: number): any; -/** -* @param {any} backup_tx -* @param {string} tx0_hex -* @param {any} statechain_info -* @returns {any} -*/ -export function verifyBlindedMusigScheme(backup_tx: any, tx0_hex: string, statechain_info: any): any; -/** -* @param {any} backup_tx -* @returns {number} -*/ -export function getBlockheight(backup_tx: any): number; -/** -* @param {any} statechain_info -* @param {any} transfer_msg -* @param {any} coin -* @returns {any} -*/ -export function createTransferReceiverRequestPayload(statechain_info: any, transfer_msg: any, coin: any): any; -/** -* @param {string} server_public_key_hex -* @param {any} coin -* @param {string} statechain_id -* @param {any} tx0_outpoint -* @param {string} tx0_hex -* @param {string} network -* @returns {any} -*/ -export function getNewKeyInfo(server_public_key_hex: string, coin: any, statechain_id: string, tx0_outpoint: any, tx0_hex: string, network: string): any; -/** -* @returns {any} -*/ -export function getMockWallet(): any; - -export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module; - -export interface InitOutput { - readonly memory: WebAssembly.Memory; - readonly setConfig: (a: number, b: number) => number; - readonly setBlockheight: (a: number, b: number) => number; - readonly addToken: (a: number, b: number) => number; - readonly confirmToken: (a: number, b: number, c: number) => number; - readonly getTokens: (a: number) => number; - readonly getBalance: (a: number) => number; - readonly getSCAddress: (a: number, b: number, c: number) => void; - readonly generateMnemonic: (a: number) => void; - readonly fromMnemonic: (a: number, b: number, c: number, d: number) => number; - readonly getActivityLog: (a: number) => number; - readonly getCoins: (a: number) => number; - readonly getNewCoin: (a: number) => number; - readonly createDepositMsg1: (a: number, b: number, c: number) => number; - readonly handleDepositMsg1Response: (a: number, b: number) => number; - readonly createAggregatedAddress: (a: number, b: number, c: number) => number; - readonly createAndCommitNonces: (a: number) => number; - readonly getUserBackupAddress: (a: number, b: number, c: number, d: number) => void; - readonly getPartialSigRequest: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number) => number; - readonly createSignature: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number) => void; - readonly newBackupTransaction: (a: number, b: number, c: number, d: number, e: number) => void; - readonly createCpfpTx: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => void; - readonly createTransferSignature: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => void; - readonly createTransferUpdateMsg: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => number; - readonly decodeTransferAddress: (a: number, b: number) => number; - readonly decryptTransferMsg: (a: number, b: number, c: number, d: number) => number; - readonly getTx0Outpoint: (a: number) => number; - readonly verifyTransferSignature: (a: number, b: number, c: number, d: number) => number; - readonly validateTx0OutputPubkey: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => number; - readonly verifyLatestBackupTxPaysToUserPubkey: (a: number, b: number, c: number, d: number, e: number) => number; - readonly getOutputAddressFromTx0: (a: number, b: number, c: number, d: number, e: number, f: number) => void; - readonly verifyTransactionSignature: (a: number, b: number, c: number, d: number, e: number, f: number) => number; - readonly verifyBlindedMusigScheme: (a: number, b: number, c: number, d: number) => number; - readonly getBlockheight: (a: number) => number; - readonly createTransferReceiverRequestPayload: (a: number, b: number, c: number) => number; - readonly getNewKeyInfo: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number) => number; - readonly getMockWallet: () => number; - readonly rustsecp256k1zkp_v0_8_1_default_illegal_callback_fn: (a: number, b: number) => void; - readonly rustsecp256k1zkp_v0_8_1_default_error_callback_fn: (a: number, b: number) => void; - readonly rustsecp256k1_v0_8_1_context_create: (a: number) => number; - readonly rustsecp256k1_v0_8_1_context_destroy: (a: number) => void; - readonly rustsecp256k1_v0_8_1_default_illegal_callback_fn: (a: number, b: number) => void; - readonly rustsecp256k1_v0_8_1_default_error_callback_fn: (a: number, b: number) => void; - readonly __wbindgen_malloc: (a: number, b: number) => number; - readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number; - readonly __wbindgen_add_to_stack_pointer: (a: number) => number; - readonly __wbindgen_free: (a: number, b: number, c: number) => void; - readonly __wbindgen_exn_store: (a: number) => void; -} - -export type SyncInitInput = BufferSource | WebAssembly.Module; -/** -* Instantiates the given `module`, which can either be bytes or -* a precompiled `WebAssembly.Module`. -* -* @param {SyncInitInput} module -* -* @returns {InitOutput} -*/ -export function initSync(module: SyncInitInput): InitOutput; - -/** -* If `module_or_path` is {RequestInfo} or {URL}, makes a request and -* for everything else, calls `WebAssembly.instantiate` directly. -* -* @param {InitInput | Promise} module_or_path -* -* @returns {Promise} -*/ -export default function __wbg_init (module_or_path?: InitInput | Promise): Promise; diff --git a/wasm/web_pkg/mercury_wasm.js b/wasm/web_pkg/mercury_wasm.js deleted file mode 100644 index 248f2b43..00000000 --- a/wasm/web_pkg/mercury_wasm.js +++ /dev/null @@ -1,1148 +0,0 @@ -let wasm; - -const heap = new Array(128).fill(undefined); - -heap.push(undefined, null, true, false); - -function getObject(idx) { return heap[idx]; } - -function _assertBoolean(n) { - if (typeof(n) !== 'boolean') { - throw new Error('expected a boolean argument'); - } -} - -function _assertNum(n) { - if (typeof(n) !== 'number') throw new Error('expected a number argument'); -} - -let WASM_VECTOR_LEN = 0; - -let cachedUint8Memory0 = null; - -function getUint8Memory0() { - if (cachedUint8Memory0 === null || cachedUint8Memory0.byteLength === 0) { - cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer); - } - return cachedUint8Memory0; -} - -const cachedTextEncoder = (typeof TextEncoder !== 'undefined' ? new TextEncoder('utf-8') : { encode: () => { throw Error('TextEncoder not available') } } ); - -const encodeString = (typeof cachedTextEncoder.encodeInto === 'function' - ? function (arg, view) { - return cachedTextEncoder.encodeInto(arg, view); -} - : function (arg, view) { - const buf = cachedTextEncoder.encode(arg); - view.set(buf); - return { - read: arg.length, - written: buf.length - }; -}); - -function passStringToWasm0(arg, malloc, realloc) { - - if (typeof(arg) !== 'string') throw new Error('expected a string argument'); - - if (realloc === undefined) { - const buf = cachedTextEncoder.encode(arg); - const ptr = malloc(buf.length, 1) >>> 0; - getUint8Memory0().subarray(ptr, ptr + buf.length).set(buf); - WASM_VECTOR_LEN = buf.length; - return ptr; - } - - let len = arg.length; - let ptr = malloc(len, 1) >>> 0; - - const mem = getUint8Memory0(); - - let offset = 0; - - for (; offset < len; offset++) { - const code = arg.charCodeAt(offset); - if (code > 0x7F) break; - mem[ptr + offset] = code; - } - - if (offset !== len) { - if (offset !== 0) { - arg = arg.slice(offset); - } - ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0; - const view = getUint8Memory0().subarray(ptr + offset, ptr + len); - const ret = encodeString(arg, view); - if (ret.read !== arg.length) throw new Error('failed to pass whole string'); - offset += ret.written; - } - - WASM_VECTOR_LEN = offset; - return ptr; -} - -function isLikeNone(x) { - return x === undefined || x === null; -} - -let cachedInt32Memory0 = null; - -function getInt32Memory0() { - if (cachedInt32Memory0 === null || cachedInt32Memory0.byteLength === 0) { - cachedInt32Memory0 = new Int32Array(wasm.memory.buffer); - } - return cachedInt32Memory0; -} - -const cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : { decode: () => { throw Error('TextDecoder not available') } } ); - -if (typeof TextDecoder !== 'undefined') { cachedTextDecoder.decode(); }; - -function getStringFromWasm0(ptr, len) { - ptr = ptr >>> 0; - return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len)); -} - -let heap_next = heap.length; - -function addHeapObject(obj) { - if (heap_next === heap.length) heap.push(heap.length + 1); - const idx = heap_next; - heap_next = heap[idx]; - - if (typeof(heap_next) !== 'number') throw new Error('corrupt heap'); - - heap[idx] = obj; - return idx; -} - -let cachedFloat64Memory0 = null; - -function getFloat64Memory0() { - if (cachedFloat64Memory0 === null || cachedFloat64Memory0.byteLength === 0) { - cachedFloat64Memory0 = new Float64Array(wasm.memory.buffer); - } - return cachedFloat64Memory0; -} - -function dropObject(idx) { - if (idx < 132) return; - heap[idx] = heap_next; - heap_next = idx; -} - -function takeObject(idx) { - const ret = getObject(idx); - dropObject(idx); - return ret; -} - -function debugString(val) { - // primitive types - const type = typeof val; - if (type == 'number' || type == 'boolean' || val == null) { - return `${val}`; - } - if (type == 'string') { - return `"${val}"`; - } - if (type == 'symbol') { - const description = val.description; - if (description == null) { - return 'Symbol'; - } else { - return `Symbol(${description})`; - } - } - if (type == 'function') { - const name = val.name; - if (typeof name == 'string' && name.length > 0) { - return `Function(${name})`; - } else { - return 'Function'; - } - } - // objects - if (Array.isArray(val)) { - const length = val.length; - let debug = '['; - if (length > 0) { - debug += debugString(val[0]); - } - for(let i = 1; i < length; i++) { - debug += ', ' + debugString(val[i]); - } - debug += ']'; - return debug; - } - // Test for built-in - const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val)); - let className; - if (builtInMatches.length > 1) { - className = builtInMatches[1]; - } else { - // Failed to match the standard '[object ClassName]' - return toString.call(val); - } - if (className == 'Object') { - // we're a user defined class or Object - // JSON.stringify avoids problems with cycles, and is generally much - // easier than looping through ownProperties of `val`. - try { - return 'Object(' + JSON.stringify(val) + ')'; - } catch (_) { - return 'Object'; - } - } - // errors - if (val instanceof Error) { - return `${val.name}: ${val.message}\n${val.stack}`; - } - // TODO we could test for more things here, like `Set`s and `Map`s. - return className; -} -/** -* @param {any} config_json -* @param {any} wallet_json -* @returns {any} -*/ -export function setConfig(config_json, wallet_json) { - const ret = wasm.setConfig(addHeapObject(config_json), addHeapObject(wallet_json)); - return takeObject(ret); -} - -/** -* @param {number} blockheight -* @param {any} wallet_json -* @returns {any} -*/ -export function setBlockheight(blockheight, wallet_json) { - _assertNum(blockheight); - const ret = wasm.setBlockheight(blockheight, addHeapObject(wallet_json)); - return takeObject(ret); -} - -/** -* @param {any} token_json -* @param {any} wallet_json -* @returns {any} -*/ -export function addToken(token_json, wallet_json) { - const ret = wasm.addToken(addHeapObject(token_json), addHeapObject(wallet_json)); - return takeObject(ret); -} - -/** -* @param {string} token_id -* @param {any} wallet_json -* @returns {any} -*/ -export function confirmToken(token_id, wallet_json) { - const ptr0 = passStringToWasm0(token_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len0 = WASM_VECTOR_LEN; - const ret = wasm.confirmToken(ptr0, len0, addHeapObject(wallet_json)); - return takeObject(ret); -} - -/** -* @param {any} wallet_json -* @returns {any} -*/ -export function getTokens(wallet_json) { - const ret = wasm.getTokens(addHeapObject(wallet_json)); - return takeObject(ret); -} - -/** -* @param {any} wallet_json -* @returns {number} -*/ -export function getBalance(wallet_json) { - const ret = wasm.getBalance(addHeapObject(wallet_json)); - return ret >>> 0; -} - -/** -* @param {any} wallet_json -* @param {number} index -* @returns {string} -*/ -export function getSCAddress(wallet_json, index) { - let deferred1_0; - let deferred1_1; - try { - const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); - _assertNum(index); - wasm.getSCAddress(retptr, addHeapObject(wallet_json), index); - var r0 = getInt32Memory0()[retptr / 4 + 0]; - var r1 = getInt32Memory0()[retptr / 4 + 1]; - deferred1_0 = r0; - deferred1_1 = r1; - return getStringFromWasm0(r0, r1); - } finally { - wasm.__wbindgen_add_to_stack_pointer(16); - wasm.__wbindgen_free(deferred1_0, deferred1_1, 1); - } -} - -/** -* @returns {string} -*/ -export function generateMnemonic() { - let deferred1_0; - let deferred1_1; - try { - const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); - wasm.generateMnemonic(retptr); - var r0 = getInt32Memory0()[retptr / 4 + 0]; - var r1 = getInt32Memory0()[retptr / 4 + 1]; - deferred1_0 = r0; - deferred1_1 = r1; - return getStringFromWasm0(r0, r1); - } finally { - wasm.__wbindgen_add_to_stack_pointer(16); - wasm.__wbindgen_free(deferred1_0, deferred1_1, 1); - } -} - -/** -* @param {string} name -* @param {string} mnemonic -* @returns {any} -*/ -export function fromMnemonic(name, mnemonic) { - const ptr0 = passStringToWasm0(name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len0 = WASM_VECTOR_LEN; - const ptr1 = passStringToWasm0(mnemonic, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len1 = WASM_VECTOR_LEN; - const ret = wasm.fromMnemonic(ptr0, len0, ptr1, len1); - return takeObject(ret); -} - -/** -* @param {any} wallet_json -* @returns {any} -*/ -export function getActivityLog(wallet_json) { - const ret = wasm.getActivityLog(addHeapObject(wallet_json)); - return takeObject(ret); -} - -/** -* @param {any} wallet_json -* @returns {any} -*/ -export function getCoins(wallet_json) { - const ret = wasm.getCoins(addHeapObject(wallet_json)); - return takeObject(ret); -} - -/** -* @param {any} wallet_json -* @returns {any} -*/ -export function getNewCoin(wallet_json) { - const ret = wasm.getNewCoin(addHeapObject(wallet_json)); - return takeObject(ret); -} - -/** -* @param {any} coin_json -* @param {string} token_id -* @returns {any} -*/ -export function createDepositMsg1(coin_json, token_id) { - const ptr0 = passStringToWasm0(token_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len0 = WASM_VECTOR_LEN; - const ret = wasm.createDepositMsg1(addHeapObject(coin_json), ptr0, len0); - return takeObject(ret); -} - -/** -* @param {any} coin_json -* @param {any} deposit_msg_1_response_json -* @returns {any} -*/ -export function handleDepositMsg1Response(coin_json, deposit_msg_1_response_json) { - const ret = wasm.handleDepositMsg1Response(addHeapObject(coin_json), addHeapObject(deposit_msg_1_response_json)); - return takeObject(ret); -} - -/** -* @param {any} coin_json -* @param {string} network -* @returns {any} -*/ -export function createAggregatedAddress(coin_json, network) { - const ptr0 = passStringToWasm0(network, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len0 = WASM_VECTOR_LEN; - const ret = wasm.createAggregatedAddress(addHeapObject(coin_json), ptr0, len0); - return takeObject(ret); -} - -/** -* @param {any} coin_json -* @returns {any} -*/ -export function createAndCommitNonces(coin_json) { - const ret = wasm.createAndCommitNonces(addHeapObject(coin_json)); - return takeObject(ret); -} - -/** -* @param {any} coin_json -* @param {string} network -* @returns {string} -*/ -export function getUserBackupAddress(coin_json, network) { - let deferred2_0; - let deferred2_1; - try { - const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); - const ptr0 = passStringToWasm0(network, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len0 = WASM_VECTOR_LEN; - wasm.getUserBackupAddress(retptr, addHeapObject(coin_json), ptr0, len0); - var r0 = getInt32Memory0()[retptr / 4 + 0]; - var r1 = getInt32Memory0()[retptr / 4 + 1]; - deferred2_0 = r0; - deferred2_1 = r1; - return getStringFromWasm0(r0, r1); - } finally { - wasm.__wbindgen_add_to_stack_pointer(16); - wasm.__wbindgen_free(deferred2_0, deferred2_1, 1); - } -} - -/** -* @param {any} coin_json -* @param {number} block_height -* @param {number} initlock -* @param {number} interval -* @param {number} fee_rate_sats_per_byte -* @param {number} qt_backup_tx -* @param {string} to_address -* @param {string} network -* @param {boolean} is_withdrawal -* @returns {any} -*/ -export function getPartialSigRequest(coin_json, block_height, initlock, interval, fee_rate_sats_per_byte, qt_backup_tx, to_address, network, is_withdrawal) { - _assertNum(block_height); - _assertNum(initlock); - _assertNum(interval); - _assertNum(fee_rate_sats_per_byte); - _assertNum(qt_backup_tx); - const ptr0 = passStringToWasm0(to_address, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len0 = WASM_VECTOR_LEN; - const ptr1 = passStringToWasm0(network, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len1 = WASM_VECTOR_LEN; - _assertBoolean(is_withdrawal); - const ret = wasm.getPartialSigRequest(addHeapObject(coin_json), block_height, initlock, interval, fee_rate_sats_per_byte, qt_backup_tx, ptr0, len0, ptr1, len1, is_withdrawal); - return takeObject(ret); -} - -/** -* @param {string} msg -* @param {string} client_partial_sig_hex -* @param {string} server_partial_sig_hex -* @param {string} session_hex -* @param {string} output_pubkey_hex -* @returns {string} -*/ -export function createSignature(msg, client_partial_sig_hex, server_partial_sig_hex, session_hex, output_pubkey_hex) { - let deferred6_0; - let deferred6_1; - try { - const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); - const ptr0 = passStringToWasm0(msg, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len0 = WASM_VECTOR_LEN; - const ptr1 = passStringToWasm0(client_partial_sig_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len1 = WASM_VECTOR_LEN; - const ptr2 = passStringToWasm0(server_partial_sig_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len2 = WASM_VECTOR_LEN; - const ptr3 = passStringToWasm0(session_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len3 = WASM_VECTOR_LEN; - const ptr4 = passStringToWasm0(output_pubkey_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len4 = WASM_VECTOR_LEN; - wasm.createSignature(retptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, ptr4, len4); - var r0 = getInt32Memory0()[retptr / 4 + 0]; - var r1 = getInt32Memory0()[retptr / 4 + 1]; - deferred6_0 = r0; - deferred6_1 = r1; - return getStringFromWasm0(r0, r1); - } finally { - wasm.__wbindgen_add_to_stack_pointer(16); - wasm.__wbindgen_free(deferred6_0, deferred6_1, 1); - } -} - -/** -* @param {string} encoded_unsigned_tx -* @param {string} signature_hex -* @returns {string} -*/ -export function newBackupTransaction(encoded_unsigned_tx, signature_hex) { - let deferred3_0; - let deferred3_1; - try { - const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); - const ptr0 = passStringToWasm0(encoded_unsigned_tx, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len0 = WASM_VECTOR_LEN; - const ptr1 = passStringToWasm0(signature_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len1 = WASM_VECTOR_LEN; - wasm.newBackupTransaction(retptr, ptr0, len0, ptr1, len1); - var r0 = getInt32Memory0()[retptr / 4 + 0]; - var r1 = getInt32Memory0()[retptr / 4 + 1]; - deferred3_0 = r0; - deferred3_1 = r1; - return getStringFromWasm0(r0, r1); - } finally { - wasm.__wbindgen_add_to_stack_pointer(16); - wasm.__wbindgen_free(deferred3_0, deferred3_1, 1); - } -} - -/** -* @param {any} backup_tx_json -* @param {any} coin_json -* @param {string} to_address -* @param {number} fee_rate_sats_per_byte -* @param {string} network -* @returns {string} -*/ -export function createCpfpTx(backup_tx_json, coin_json, to_address, fee_rate_sats_per_byte, network) { - let deferred3_0; - let deferred3_1; - try { - const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); - const ptr0 = passStringToWasm0(to_address, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len0 = WASM_VECTOR_LEN; - _assertNum(fee_rate_sats_per_byte); - const ptr1 = passStringToWasm0(network, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len1 = WASM_VECTOR_LEN; - wasm.createCpfpTx(retptr, addHeapObject(backup_tx_json), addHeapObject(coin_json), ptr0, len0, fee_rate_sats_per_byte, ptr1, len1); - var r0 = getInt32Memory0()[retptr / 4 + 0]; - var r1 = getInt32Memory0()[retptr / 4 + 1]; - deferred3_0 = r0; - deferred3_1 = r1; - return getStringFromWasm0(r0, r1); - } finally { - wasm.__wbindgen_add_to_stack_pointer(16); - wasm.__wbindgen_free(deferred3_0, deferred3_1, 1); - } -} - -/** -* @param {string} recipient_address -* @param {string} input_txid -* @param {number} input_vout -* @param {string} client_seckey -* @returns {string} -*/ -export function createTransferSignature(recipient_address, input_txid, input_vout, client_seckey) { - let deferred4_0; - let deferred4_1; - try { - const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); - const ptr0 = passStringToWasm0(recipient_address, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len0 = WASM_VECTOR_LEN; - const ptr1 = passStringToWasm0(input_txid, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len1 = WASM_VECTOR_LEN; - _assertNum(input_vout); - const ptr2 = passStringToWasm0(client_seckey, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len2 = WASM_VECTOR_LEN; - wasm.createTransferSignature(retptr, ptr0, len0, ptr1, len1, input_vout, ptr2, len2); - var r0 = getInt32Memory0()[retptr / 4 + 0]; - var r1 = getInt32Memory0()[retptr / 4 + 1]; - deferred4_0 = r0; - deferred4_1 = r1; - return getStringFromWasm0(r0, r1); - } finally { - wasm.__wbindgen_add_to_stack_pointer(16); - wasm.__wbindgen_free(deferred4_0, deferred4_1, 1); - } -} - -/** -* @param {string} x1 -* @param {string} recipient_address -* @param {any} coin_json -* @param {string} transfer_signature -* @param {any} backup_transactions -* @returns {any} -*/ -export function createTransferUpdateMsg(x1, recipient_address, coin_json, transfer_signature, backup_transactions) { - const ptr0 = passStringToWasm0(x1, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len0 = WASM_VECTOR_LEN; - const ptr1 = passStringToWasm0(recipient_address, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len1 = WASM_VECTOR_LEN; - const ptr2 = passStringToWasm0(transfer_signature, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len2 = WASM_VECTOR_LEN; - const ret = wasm.createTransferUpdateMsg(ptr0, len0, ptr1, len1, addHeapObject(coin_json), ptr2, len2, addHeapObject(backup_transactions)); - return takeObject(ret); -} - -/** -* @param {string} sc_address -* @returns {any} -*/ -export function decodeTransferAddress(sc_address) { - const ptr0 = passStringToWasm0(sc_address, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len0 = WASM_VECTOR_LEN; - const ret = wasm.decodeTransferAddress(ptr0, len0); - return takeObject(ret); -} - -/** -* @param {string} encrypted_message -* @param {string} private_key_wif -* @returns {any} -*/ -export function decryptTransferMsg(encrypted_message, private_key_wif) { - const ptr0 = passStringToWasm0(encrypted_message, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len0 = WASM_VECTOR_LEN; - const ptr1 = passStringToWasm0(private_key_wif, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len1 = WASM_VECTOR_LEN; - const ret = wasm.decryptTransferMsg(ptr0, len0, ptr1, len1); - return takeObject(ret); -} - -/** -* @param {any} backup_transactions -* @returns {any} -*/ -export function getTx0Outpoint(backup_transactions) { - const ret = wasm.getTx0Outpoint(addHeapObject(backup_transactions)); - return takeObject(ret); -} - -/** -* @param {string} new_user_pubkey -* @param {any} tx0_outpoint -* @param {any} transfer_msg -* @returns {boolean} -*/ -export function verifyTransferSignature(new_user_pubkey, tx0_outpoint, transfer_msg) { - const ptr0 = passStringToWasm0(new_user_pubkey, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len0 = WASM_VECTOR_LEN; - const ret = wasm.verifyTransferSignature(ptr0, len0, addHeapObject(tx0_outpoint), addHeapObject(transfer_msg)); - return ret !== 0; -} - -/** -* @param {string} enclave_public_key -* @param {any} transfer_msg -* @param {any} tx0_outpoint -* @param {string} tx0_hex -* @param {string} network -* @returns {boolean} -*/ -export function validateTx0OutputPubkey(enclave_public_key, transfer_msg, tx0_outpoint, tx0_hex, network) { - const ptr0 = passStringToWasm0(enclave_public_key, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len0 = WASM_VECTOR_LEN; - const ptr1 = passStringToWasm0(tx0_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len1 = WASM_VECTOR_LEN; - const ptr2 = passStringToWasm0(network, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len2 = WASM_VECTOR_LEN; - const ret = wasm.validateTx0OutputPubkey(ptr0, len0, addHeapObject(transfer_msg), addHeapObject(tx0_outpoint), ptr1, len1, ptr2, len2); - return ret !== 0; -} - -/** -* @param {any} transfer_msg -* @param {string} client_pubkey_share -* @param {string} network -* @returns {boolean} -*/ -export function verifyLatestBackupTxPaysToUserPubkey(transfer_msg, client_pubkey_share, network) { - const ptr0 = passStringToWasm0(client_pubkey_share, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len0 = WASM_VECTOR_LEN; - const ptr1 = passStringToWasm0(network, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len1 = WASM_VECTOR_LEN; - const ret = wasm.verifyLatestBackupTxPaysToUserPubkey(addHeapObject(transfer_msg), ptr0, len0, ptr1, len1); - return ret !== 0; -} - -/** -* @param {any} tx0_outpoint -* @param {string} tx0_hex -* @param {string} network -* @returns {string} -*/ -export function getOutputAddressFromTx0(tx0_outpoint, tx0_hex, network) { - let deferred3_0; - let deferred3_1; - try { - const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); - const ptr0 = passStringToWasm0(tx0_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len0 = WASM_VECTOR_LEN; - const ptr1 = passStringToWasm0(network, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len1 = WASM_VECTOR_LEN; - wasm.getOutputAddressFromTx0(retptr, addHeapObject(tx0_outpoint), ptr0, len0, ptr1, len1); - var r0 = getInt32Memory0()[retptr / 4 + 0]; - var r1 = getInt32Memory0()[retptr / 4 + 1]; - deferred3_0 = r0; - deferred3_1 = r1; - return getStringFromWasm0(r0, r1); - } finally { - wasm.__wbindgen_add_to_stack_pointer(16); - wasm.__wbindgen_free(deferred3_0, deferred3_1, 1); - } -} - -/** -* @param {string} tx_n_hex -* @param {string} tx0_hex -* @param {number} fee_rate_tolerance -* @param {number} current_fee_rate_sats_per_byte -* @returns {any} -*/ -export function verifyTransactionSignature(tx_n_hex, tx0_hex, fee_rate_tolerance, current_fee_rate_sats_per_byte) { - const ptr0 = passStringToWasm0(tx_n_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len0 = WASM_VECTOR_LEN; - const ptr1 = passStringToWasm0(tx0_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len1 = WASM_VECTOR_LEN; - _assertNum(fee_rate_tolerance); - _assertNum(current_fee_rate_sats_per_byte); - const ret = wasm.verifyTransactionSignature(ptr0, len0, ptr1, len1, fee_rate_tolerance, current_fee_rate_sats_per_byte); - return takeObject(ret); -} - -/** -* @param {any} backup_tx -* @param {string} tx0_hex -* @param {any} statechain_info -* @returns {any} -*/ -export function verifyBlindedMusigScheme(backup_tx, tx0_hex, statechain_info) { - const ptr0 = passStringToWasm0(tx0_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len0 = WASM_VECTOR_LEN; - const ret = wasm.verifyBlindedMusigScheme(addHeapObject(backup_tx), ptr0, len0, addHeapObject(statechain_info)); - return takeObject(ret); -} - -/** -* @param {any} backup_tx -* @returns {number} -*/ -export function getBlockheight(backup_tx) { - const ret = wasm.getBlockheight(addHeapObject(backup_tx)); - return ret >>> 0; -} - -/** -* @param {any} statechain_info -* @param {any} transfer_msg -* @param {any} coin -* @returns {any} -*/ -export function createTransferReceiverRequestPayload(statechain_info, transfer_msg, coin) { - const ret = wasm.createTransferReceiverRequestPayload(addHeapObject(statechain_info), addHeapObject(transfer_msg), addHeapObject(coin)); - return takeObject(ret); -} - -/** -* @param {string} server_public_key_hex -* @param {any} coin -* @param {string} statechain_id -* @param {any} tx0_outpoint -* @param {string} tx0_hex -* @param {string} network -* @returns {any} -*/ -export function getNewKeyInfo(server_public_key_hex, coin, statechain_id, tx0_outpoint, tx0_hex, network) { - const ptr0 = passStringToWasm0(server_public_key_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len0 = WASM_VECTOR_LEN; - const ptr1 = passStringToWasm0(statechain_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len1 = WASM_VECTOR_LEN; - const ptr2 = passStringToWasm0(tx0_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len2 = WASM_VECTOR_LEN; - const ptr3 = passStringToWasm0(network, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len3 = WASM_VECTOR_LEN; - const ret = wasm.getNewKeyInfo(ptr0, len0, addHeapObject(coin), ptr1, len1, addHeapObject(tx0_outpoint), ptr2, len2, ptr3, len3); - return takeObject(ret); -} - -/** -* @returns {any} -*/ -export function getMockWallet() { - const ret = wasm.getMockWallet(); - return takeObject(ret); -} - -function logError(f, args) { - try { - return f.apply(this, args); - } catch (e) { - let error = (function () { - try { - return e instanceof Error ? `${e.message}\n\nStack:\n${e.stack}` : e.toString(); - } catch(_) { - return ""; - } - }()); - console.error("wasm-bindgen: imported JS function that was not marked as `catch` threw an error:", error); - throw e; - } -} - -function handleError(f, args) { - try { - return f.apply(this, args); - } catch (e) { - wasm.__wbindgen_exn_store(addHeapObject(e)); - } -} - -async function __wbg_load(module, imports) { - if (typeof Response === 'function' && module instanceof Response) { - if (typeof WebAssembly.instantiateStreaming === 'function') { - try { - return await WebAssembly.instantiateStreaming(module, imports); - - } catch (e) { - if (module.headers.get('Content-Type') != 'application/wasm') { - console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e); - - } else { - throw e; - } - } - } - - const bytes = await module.arrayBuffer(); - return await WebAssembly.instantiate(bytes, imports); - - } else { - const instance = await WebAssembly.instantiate(module, imports); - - if (instance instanceof WebAssembly.Instance) { - return { instance, module }; - - } else { - return instance; - } - } -} - -function __wbg_get_imports() { - const imports = {}; - imports.wbg = {}; - imports.wbg.__wbindgen_is_undefined = function(arg0) { - const ret = getObject(arg0) === undefined; - _assertBoolean(ret); - return ret; - }; - imports.wbg.__wbindgen_in = function(arg0, arg1) { - const ret = getObject(arg0) in getObject(arg1); - _assertBoolean(ret); - return ret; - }; - imports.wbg.__wbindgen_boolean_get = function(arg0) { - const v = getObject(arg0); - const ret = typeof(v) === 'boolean' ? (v ? 1 : 0) : 2; - _assertNum(ret); - return ret; - }; - imports.wbg.__wbindgen_string_get = function(arg0, arg1) { - const obj = getObject(arg1); - const ret = typeof(obj) === 'string' ? obj : undefined; - var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - var len1 = WASM_VECTOR_LEN; - getInt32Memory0()[arg0 / 4 + 1] = len1; - getInt32Memory0()[arg0 / 4 + 0] = ptr1; - }; - imports.wbg.__wbindgen_is_object = function(arg0) { - const val = getObject(arg0); - const ret = typeof(val) === 'object' && val !== null; - _assertBoolean(ret); - return ret; - }; - imports.wbg.__wbindgen_is_string = function(arg0) { - const ret = typeof(getObject(arg0)) === 'string'; - _assertBoolean(ret); - return ret; - }; - imports.wbg.__wbindgen_error_new = function(arg0, arg1) { - const ret = new Error(getStringFromWasm0(arg0, arg1)); - return addHeapObject(ret); - }; - imports.wbg.__wbindgen_number_get = function(arg0, arg1) { - const obj = getObject(arg1); - const ret = typeof(obj) === 'number' ? obj : undefined; - if (!isLikeNone(ret)) { - _assertNum(ret); - } - getFloat64Memory0()[arg0 / 8 + 1] = isLikeNone(ret) ? 0 : ret; - getInt32Memory0()[arg0 / 4 + 0] = !isLikeNone(ret); - }; - imports.wbg.__wbindgen_number_new = function(arg0) { - const ret = arg0; - return addHeapObject(ret); - }; - imports.wbg.__wbindgen_string_new = function(arg0, arg1) { - const ret = getStringFromWasm0(arg0, arg1); - return addHeapObject(ret); - }; - imports.wbg.__wbindgen_jsval_loose_eq = function(arg0, arg1) { - const ret = getObject(arg0) == getObject(arg1); - _assertBoolean(ret); - return ret; - }; - imports.wbg.__wbindgen_object_clone_ref = function(arg0) { - const ret = getObject(arg0); - return addHeapObject(ret); - }; - imports.wbg.__wbg_getwithrefkey_15c62c2b8546208d = function() { return logError(function (arg0, arg1) { - const ret = getObject(arg0)[getObject(arg1)]; - return addHeapObject(ret); - }, arguments) }; - imports.wbg.__wbg_set_20cbc34131e76824 = function() { return logError(function (arg0, arg1, arg2) { - getObject(arg0)[takeObject(arg1)] = takeObject(arg2); - }, arguments) }; - imports.wbg.__wbindgen_object_drop_ref = function(arg0) { - takeObject(arg0); - }; - imports.wbg.__wbg_crypto_c48a774b022d20ac = function() { return logError(function (arg0) { - const ret = getObject(arg0).crypto; - return addHeapObject(ret); - }, arguments) }; - imports.wbg.__wbg_msCrypto_bcb970640f50a1e8 = function() { return logError(function (arg0) { - const ret = getObject(arg0).msCrypto; - return addHeapObject(ret); - }, arguments) }; - imports.wbg.__wbg_getRandomValues_37fa2ca9e4e07fab = function() { return handleError(function (arg0, arg1) { - getObject(arg0).getRandomValues(getObject(arg1)); - }, arguments) }; - imports.wbg.__wbg_randomFillSync_dc1e9a60c158336d = function() { return handleError(function (arg0, arg1) { - getObject(arg0).randomFillSync(takeObject(arg1)); - }, arguments) }; - imports.wbg.__wbg_require_8f08ceecec0f4fee = function() { return handleError(function () { - const ret = module.require; - return addHeapObject(ret); - }, arguments) }; - imports.wbg.__wbg_process_298734cf255a885d = function() { return logError(function (arg0) { - const ret = getObject(arg0).process; - return addHeapObject(ret); - }, arguments) }; - imports.wbg.__wbg_versions_e2e78e134e3e5d01 = function() { return logError(function (arg0) { - const ret = getObject(arg0).versions; - return addHeapObject(ret); - }, arguments) }; - imports.wbg.__wbg_node_1cd7a5d853dbea79 = function() { return logError(function (arg0) { - const ret = getObject(arg0).node; - return addHeapObject(ret); - }, arguments) }; - imports.wbg.__wbg_new_898a68150f225f2e = function() { return logError(function () { - const ret = new Array(); - return addHeapObject(ret); - }, arguments) }; - imports.wbg.__wbg_get_44be0491f933a435 = function() { return logError(function (arg0, arg1) { - const ret = getObject(arg0)[arg1 >>> 0]; - return addHeapObject(ret); - }, arguments) }; - imports.wbg.__wbg_set_502d29070ea18557 = function() { return logError(function (arg0, arg1, arg2) { - getObject(arg0)[arg1 >>> 0] = takeObject(arg2); - }, arguments) }; - imports.wbg.__wbg_isArray_4c24b343cb13cfb1 = function() { return logError(function (arg0) { - const ret = Array.isArray(getObject(arg0)); - _assertBoolean(ret); - return ret; - }, arguments) }; - imports.wbg.__wbg_length_fff51ee6522a1a18 = function() { return logError(function (arg0) { - const ret = getObject(arg0).length; - _assertNum(ret); - return ret; - }, arguments) }; - imports.wbg.__wbg_instanceof_ArrayBuffer_39ac22089b74fddb = function() { return logError(function (arg0) { - let result; - try { - result = getObject(arg0) instanceof ArrayBuffer; - } catch { - result = false; - } - const ret = result; - _assertBoolean(ret); - return ret; - }, arguments) }; - imports.wbg.__wbg_newnoargs_581967eacc0e2604 = function() { return logError(function (arg0, arg1) { - const ret = new Function(getStringFromWasm0(arg0, arg1)); - return addHeapObject(ret); - }, arguments) }; - imports.wbg.__wbg_call_cb65541d95d71282 = function() { return handleError(function (arg0, arg1) { - const ret = getObject(arg0).call(getObject(arg1)); - return addHeapObject(ret); - }, arguments) }; - imports.wbg.__wbg_call_01734de55d61e11d = function() { return handleError(function (arg0, arg1, arg2) { - const ret = getObject(arg0).call(getObject(arg1), getObject(arg2)); - return addHeapObject(ret); - }, arguments) }; - imports.wbg.__wbg_next_ddb3312ca1c4e32a = function() { return handleError(function (arg0) { - const ret = getObject(arg0).next(); - return addHeapObject(ret); - }, arguments) }; - imports.wbg.__wbg_next_526fc47e980da008 = function() { return logError(function (arg0) { - const ret = getObject(arg0).next; - return addHeapObject(ret); - }, arguments) }; - imports.wbg.__wbg_done_5c1f01fb660d73b5 = function() { return logError(function (arg0) { - const ret = getObject(arg0).done; - _assertBoolean(ret); - return ret; - }, arguments) }; - imports.wbg.__wbg_value_1695675138684bd5 = function() { return logError(function (arg0) { - const ret = getObject(arg0).value; - return addHeapObject(ret); - }, arguments) }; - imports.wbg.__wbg_isSafeInteger_bb8e18dd21c97288 = function() { return logError(function (arg0) { - const ret = Number.isSafeInteger(getObject(arg0)); - _assertBoolean(ret); - return ret; - }, arguments) }; - imports.wbg.__wbg_entries_e51f29c7bba0c054 = function() { return logError(function (arg0) { - const ret = Object.entries(getObject(arg0)); - return addHeapObject(ret); - }, arguments) }; - imports.wbg.__wbg_new_b51585de1b234aff = function() { return logError(function () { - const ret = new Object(); - return addHeapObject(ret); - }, arguments) }; - imports.wbg.__wbg_iterator_97f0c81209c6c35a = function() { return logError(function () { - const ret = Symbol.iterator; - return addHeapObject(ret); - }, arguments) }; - imports.wbg.__wbg_globalThis_1d39714405582d3c = function() { return handleError(function () { - const ret = globalThis.globalThis; - return addHeapObject(ret); - }, arguments) }; - imports.wbg.__wbg_self_1ff1d729e9aae938 = function() { return handleError(function () { - const ret = self.self; - return addHeapObject(ret); - }, arguments) }; - imports.wbg.__wbg_window_5f4faef6c12b79ec = function() { return handleError(function () { - const ret = window.window; - return addHeapObject(ret); - }, arguments) }; - imports.wbg.__wbg_global_651f05c6a0944d1c = function() { return handleError(function () { - const ret = global.global; - return addHeapObject(ret); - }, arguments) }; - imports.wbg.__wbg_instanceof_Uint8Array_d8d9cb2b8e8ac1d4 = function() { return logError(function (arg0) { - let result; - try { - result = getObject(arg0) instanceof Uint8Array; - } catch { - result = false; - } - const ret = result; - _assertBoolean(ret); - return ret; - }, arguments) }; - imports.wbg.__wbg_new_8125e318e6245eed = function() { return logError(function (arg0) { - const ret = new Uint8Array(getObject(arg0)); - return addHeapObject(ret); - }, arguments) }; - imports.wbg.__wbg_newwithlength_e5d69174d6984cd7 = function() { return logError(function (arg0) { - const ret = new Uint8Array(arg0 >>> 0); - return addHeapObject(ret); - }, arguments) }; - imports.wbg.__wbg_newwithbyteoffsetandlength_6da8e527659b86aa = function() { return logError(function (arg0, arg1, arg2) { - const ret = new Uint8Array(getObject(arg0), arg1 >>> 0, arg2 >>> 0); - return addHeapObject(ret); - }, arguments) }; - imports.wbg.__wbg_subarray_13db269f57aa838d = function() { return logError(function (arg0, arg1, arg2) { - const ret = getObject(arg0).subarray(arg1 >>> 0, arg2 >>> 0); - return addHeapObject(ret); - }, arguments) }; - imports.wbg.__wbg_length_72e2208bbc0efc61 = function() { return logError(function (arg0) { - const ret = getObject(arg0).length; - _assertNum(ret); - return ret; - }, arguments) }; - imports.wbg.__wbg_set_5cf90238115182c3 = function() { return logError(function (arg0, arg1, arg2) { - getObject(arg0).set(getObject(arg1), arg2 >>> 0); - }, arguments) }; - imports.wbg.__wbindgen_is_function = function(arg0) { - const ret = typeof(getObject(arg0)) === 'function'; - _assertBoolean(ret); - return ret; - }; - imports.wbg.__wbg_buffer_085ec1f694018c4f = function() { return logError(function (arg0) { - const ret = getObject(arg0).buffer; - return addHeapObject(ret); - }, arguments) }; - imports.wbg.__wbg_get_97b561fb56f034b5 = function() { return handleError(function (arg0, arg1) { - const ret = Reflect.get(getObject(arg0), getObject(arg1)); - return addHeapObject(ret); - }, arguments) }; - imports.wbg.__wbindgen_debug_string = function(arg0, arg1) { - const ret = debugString(getObject(arg1)); - const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len1 = WASM_VECTOR_LEN; - getInt32Memory0()[arg0 / 4 + 1] = len1; - getInt32Memory0()[arg0 / 4 + 0] = ptr1; - }; - imports.wbg.__wbindgen_throw = function(arg0, arg1) { - throw new Error(getStringFromWasm0(arg0, arg1)); - }; - imports.wbg.__wbindgen_memory = function() { - const ret = wasm.memory; - return addHeapObject(ret); - }; - - return imports; -} - -function __wbg_init_memory(imports, maybe_memory) { - -} - -function __wbg_finalize_init(instance, module) { - wasm = instance.exports; - __wbg_init.__wbindgen_wasm_module = module; - cachedFloat64Memory0 = null; - cachedInt32Memory0 = null; - cachedUint8Memory0 = null; - - - return wasm; -} - -function initSync(module) { - if (wasm !== undefined) return wasm; - - const imports = __wbg_get_imports(); - - __wbg_init_memory(imports); - - if (!(module instanceof WebAssembly.Module)) { - module = new WebAssembly.Module(module); - } - - const instance = new WebAssembly.Instance(module, imports); - - return __wbg_finalize_init(instance, module); -} - -async function __wbg_init(input) { - if (wasm !== undefined) return wasm; - - if (typeof input === 'undefined') { - input = new URL('mercury_wasm_bg.wasm', import.meta.url); - } - const imports = __wbg_get_imports(); - - if (typeof input === 'string' || (typeof Request === 'function' && input instanceof Request) || (typeof URL === 'function' && input instanceof URL)) { - input = fetch(input); - } - - __wbg_init_memory(imports); - - const { instance, module } = await __wbg_load(await input, imports); - - return __wbg_finalize_init(instance, module); -} - -export { initSync } -export default __wbg_init; diff --git a/wasm/web_pkg/mercury_wasm_bg.wasm b/wasm/web_pkg/mercury_wasm_bg.wasm deleted file mode 100644 index b81c5ac2..00000000 Binary files a/wasm/web_pkg/mercury_wasm_bg.wasm and /dev/null differ diff --git a/wasm/web_pkg/mercury_wasm_bg.wasm.d.ts b/wasm/web_pkg/mercury_wasm_bg.wasm.d.ts deleted file mode 100644 index 28eed6df..00000000 --- a/wasm/web_pkg/mercury_wasm_bg.wasm.d.ts +++ /dev/null @@ -1,50 +0,0 @@ -/* tslint:disable */ -/* eslint-disable */ -export const memory: WebAssembly.Memory; -export function setConfig(a: number, b: number): number; -export function setBlockheight(a: number, b: number): number; -export function addToken(a: number, b: number): number; -export function confirmToken(a: number, b: number, c: number): number; -export function getTokens(a: number): number; -export function getBalance(a: number): number; -export function getSCAddress(a: number, b: number, c: number): void; -export function generateMnemonic(a: number): void; -export function fromMnemonic(a: number, b: number, c: number, d: number): number; -export function getActivityLog(a: number): number; -export function getCoins(a: number): number; -export function getNewCoin(a: number): number; -export function createDepositMsg1(a: number, b: number, c: number): number; -export function handleDepositMsg1Response(a: number, b: number): number; -export function createAggregatedAddress(a: number, b: number, c: number): number; -export function createAndCommitNonces(a: number): number; -export function getUserBackupAddress(a: number, b: number, c: number, d: number): void; -export function getPartialSigRequest(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number): number; -export function createSignature(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number): void; -export function newBackupTransaction(a: number, b: number, c: number, d: number, e: number): void; -export function createCpfpTx(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number): void; -export function createTransferSignature(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number): void; -export function createTransferUpdateMsg(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number): number; -export function decodeTransferAddress(a: number, b: number): number; -export function decryptTransferMsg(a: number, b: number, c: number, d: number): number; -export function getTx0Outpoint(a: number): number; -export function verifyTransferSignature(a: number, b: number, c: number, d: number): number; -export function validateTx0OutputPubkey(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number): number; -export function verifyLatestBackupTxPaysToUserPubkey(a: number, b: number, c: number, d: number, e: number): number; -export function getOutputAddressFromTx0(a: number, b: number, c: number, d: number, e: number, f: number): void; -export function verifyTransactionSignature(a: number, b: number, c: number, d: number, e: number, f: number): number; -export function verifyBlindedMusigScheme(a: number, b: number, c: number, d: number): number; -export function getBlockheight(a: number): number; -export function createTransferReceiverRequestPayload(a: number, b: number, c: number): number; -export function getNewKeyInfo(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number): number; -export function getMockWallet(): number; -export function rustsecp256k1zkp_v0_8_1_default_illegal_callback_fn(a: number, b: number): void; -export function rustsecp256k1zkp_v0_8_1_default_error_callback_fn(a: number, b: number): void; -export function rustsecp256k1_v0_8_1_context_create(a: number): number; -export function rustsecp256k1_v0_8_1_context_destroy(a: number): void; -export function rustsecp256k1_v0_8_1_default_illegal_callback_fn(a: number, b: number): void; -export function rustsecp256k1_v0_8_1_default_error_callback_fn(a: number, b: number): void; -export function __wbindgen_malloc(a: number, b: number): number; -export function __wbindgen_realloc(a: number, b: number, c: number, d: number): number; -export function __wbindgen_add_to_stack_pointer(a: number): number; -export function __wbindgen_free(a: number, b: number, c: number): void; -export function __wbindgen_exn_store(a: number): void; diff --git a/wasm/web_pkg/package.json b/wasm/web_pkg/package.json deleted file mode 100644 index 8a18fde9..00000000 --- a/wasm/web_pkg/package.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "name": "mercury-wasm", - "collaborators": [ - "ttrevethan" - ], - "version": "0.1.0", - "files": [ - "mercury_wasm_bg.wasm", - "mercury_wasm.js", - "mercury_wasm.d.ts" - ], - "module": "mercury_wasm.js", - "types": "mercury_wasm.d.ts", - "sideEffects": [ - "./snippets/*" - ] -} \ No newline at end of file