From cb508d6c697034418f1d0e549aebc7a949e1ef5b Mon Sep 17 00:00:00 2001 From: Max Murphy Date: Mon, 16 Sep 2024 14:12:50 +0200 Subject: [PATCH 01/11] Remove threshold APIs --- src/backend/src/lib.rs | 115 +---------------------------------------- 1 file changed, 1 insertion(+), 114 deletions(-) diff --git a/src/backend/src/lib.rs b/src/backend/src/lib.rs index ebbf00c2f..5deba097c 100644 --- a/src/backend/src/lib.rs +++ b/src/backend/src/lib.rs @@ -1,9 +1,6 @@ use crate::assertions::{assert_token_enabled_is_some, assert_token_symbol_length}; use crate::bitcoin_utils::public_key_to_p2pkh_address; -use crate::guards::{ - caller_is_allowed, caller_is_allowed_and_may_read_threshold_keys, may_read_threshold_keys, - may_read_user_data, may_threshold_sign, may_write_user_data, -}; +use crate::guards::{caller_is_allowed, may_read_user_data, may_write_user_data}; use crate::token::{add_to_user_token, remove_from_user_token}; use candid::{Nat, Principal}; use config::find_credential_config; @@ -245,27 +242,6 @@ fn parse_eth_address(address: &str) -> [u8; 20] { } } -/// Returns the Ethereum address of the caller. -#[update(guard = "may_read_threshold_keys")] -async fn caller_eth_address() -> String { - pubkey_bytes_to_address(&ecdsa_pubkey_of(&ic_cdk::caller()).await) -} - -/// Returns the Ethereum address of the specified user. -#[update(guard = "caller_is_allowed_and_may_read_threshold_keys")] -async fn eth_address_of(p: Principal) -> String { - if p == Principal::anonymous() { - ic_cdk::trap("Anonymous principal is not authorized"); - } - pubkey_bytes_to_address(&ecdsa_pubkey_of(&p).await) -} - -/// Returns the Bitcoin address of the caller. -#[update(guard = "may_read_threshold_keys")] -async fn caller_btc_address(network: BitcoinNetwork) -> String { - public_key_to_p2pkh_address(network, &ecdsa_pubkey_of(&ic_cdk::caller()).await) -} - fn nat_to_u256(n: &Nat) -> U256 { let be_bytes = n.0.to_bytes_be(); U256::from_big_endian(&be_bytes) @@ -296,95 +272,6 @@ async fn pubkey_and_signature(caller: &Principal, message_hash: Vec) -> (Vec ) } -/// Computes a signature for an [EIP-1559](https://eips.ethereum.org/EIPS/eip-1559) transaction. -#[update(guard = "may_threshold_sign")] -async fn sign_transaction(req: SignRequest) -> String { - use ethers_core::types::transaction::eip1559::Eip1559TransactionRequest; - use ethers_core::types::Signature; - - const EIP1559_TX_ID: u8 = 2; - - let caller = ic_cdk::caller(); - - let data = req.data.as_ref().map(|s| decode_hex(s)); - - let tx = Eip1559TransactionRequest { - chain_id: Some(nat_to_u64(&req.chain_id)), - from: None, - to: Some( - Address::from_str(&req.to) - .expect("failed to parse the destination address") - .into(), - ), - gas: Some(nat_to_u256(&req.gas)), - value: Some(nat_to_u256(&req.value)), - nonce: Some(nat_to_u256(&req.nonce)), - data, - access_list: AccessList::default(), - max_priority_fee_per_gas: Some(nat_to_u256(&req.max_priority_fee_per_gas)), - max_fee_per_gas: Some(nat_to_u256(&req.max_fee_per_gas)), - }; - - let mut unsigned_tx_bytes = tx.rlp().to_vec(); - unsigned_tx_bytes.insert(0, EIP1559_TX_ID); - - let txhash = keccak256(&unsigned_tx_bytes); - - let (pubkey, signature) = pubkey_and_signature(&caller, txhash.to_vec()).await; - - let signature = Signature { - v: y_parity(&txhash, &signature, &pubkey), - r: U256::from_big_endian(&signature[0..32]), - s: U256::from_big_endian(&signature[32..64]), - }; - - let mut signed_tx_bytes = tx.rlp_signed(&signature).to_vec(); - signed_tx_bytes.insert(0, EIP1559_TX_ID); - - format!("0x{}", hex::encode(&signed_tx_bytes)) -} - -/// Computes a signature for a hex-encoded message according to [EIP-191](https://eips.ethereum.org/EIPS/eip-191). -#[update(guard = "may_threshold_sign")] -async fn personal_sign(plaintext: String) -> String { - let caller = ic_cdk::caller(); - - let bytes = decode_hex(&plaintext); - - let message = [ - b"\x19Ethereum Signed Message:\n", - bytes.len().to_string().as_bytes(), - bytes.as_ref(), - ] - .concat(); - - let msg_hash = keccak256(&message); - - let (pubkey, mut signature) = pubkey_and_signature(&caller, msg_hash.to_vec()).await; - - let v = y_parity(&msg_hash, &signature, &pubkey); - signature.push(u8::try_from(v).unwrap_or_else(|_| { - unreachable!("The value should be one bit, so should easily fit into a byte") - })); - format!("0x{}", hex::encode(&signature)) -} - -/// Computes a signature for a precomputed hash. -#[update(guard = "may_threshold_sign")] -async fn sign_prehash(prehash: String) -> String { - let caller = ic_cdk::caller(); - - let hash_bytes = decode_hex(&prehash); - - let (pubkey, mut signature) = pubkey_and_signature(&caller, hash_bytes.to_vec()).await; - - let v = y_parity(&hash_bytes, &signature, &pubkey); - signature.push(u8::try_from(v).unwrap_or_else(|_| { - unreachable!("The value should be just one bit, so should fit easily into a byte") - })); - format!("0x{}", hex::encode(&signature)) -} - #[update(guard = "may_write_user_data")] #[allow(clippy::needless_pass_by_value)] fn set_user_token(token: UserToken) { From 50ffd4616816471f01e27f9acec73504b86f7dc9 Mon Sep 17 00:00:00 2001 From: Max Murphy Date: Mon, 16 Sep 2024 14:13:51 +0200 Subject: [PATCH 02/11] Remove threshold guards --- src/backend/src/guards.rs | 27 +-------------------------- 1 file changed, 1 insertion(+), 26 deletions(-) diff --git a/src/backend/src/guards.rs b/src/backend/src/guards.rs index ea523e6ed..e0cfd8221 100644 --- a/src/backend/src/guards.rs +++ b/src/backend/src/guards.rs @@ -38,29 +38,4 @@ pub fn may_read_user_data() -> Result<(), String> { } else { Err("User data cannot be read at this time due to a migration.".to_string()) } -} - -/// Is getting threshold public keys is enabled? -pub fn may_read_threshold_keys() -> Result<(), String> { - caller_is_not_anonymous()?; - if read_config(|s| s.api.unwrap_or_default().threshold_key.readable()) { - Ok(()) - } else { - Err("Reading threshold keys is disabled.".to_string()) - } -} -/// Caller is allowed AND reading threshold keys is enabled. -pub fn caller_is_allowed_and_may_read_threshold_keys() -> Result<(), String> { - caller_is_allowed()?; - may_read_threshold_keys() -} - -/// Is signing with threshold keys is enabled? -pub fn may_threshold_sign() -> Result<(), String> { - caller_is_not_anonymous()?; - if read_config(|s| s.api.unwrap_or_default().threshold_key.writable()) { - Ok(()) - } else { - Err("Threshold signing is disabled.".to_string()) - } -} +} \ No newline at end of file From e0e1af6a19b3954fdc3f11cc56b3e6140b18294a Mon Sep 17 00:00:00 2001 From: Max Murphy Date: Mon, 16 Sep 2024 14:15:31 +0200 Subject: [PATCH 03/11] rm threshold utils --- src/backend/src/lib.rs | 88 ------------------------------------------ 1 file changed, 88 deletions(-) diff --git a/src/backend/src/lib.rs b/src/backend/src/lib.rs index 5deba097c..03fd6ba6d 100644 --- a/src/backend/src/lib.rs +++ b/src/backend/src/lib.rs @@ -201,38 +201,6 @@ fn principal_to_derivation_path(p: &Principal) -> Vec> { vec![vec![SCHEMA], p.as_slice().to_vec()] } -/// Converts the public key bytes to an Ethereum address with a checksum. -fn pubkey_bytes_to_address(pubkey_bytes: &[u8]) -> String { - use k256::elliptic_curve::sec1::ToEncodedPoint; - - let key = - PublicKey::from_sec1_bytes(pubkey_bytes).expect("failed to parse the public key as SEC1"); - let point = key.to_encoded_point(false); - // we re-encode the key to the decompressed representation. - let point_bytes = point.as_bytes(); - assert_eq!(point_bytes[0], 0x04); - - let hash = keccak256(&point_bytes[1..]); - - ethers_core::utils::to_checksum(&Address::from_slice(&hash[12..32]), None) -} - -/// Computes the public key of the specified principal. -async fn ecdsa_pubkey_of(principal: &Principal) -> Vec { - let name = read_config(|s| s.ecdsa_key_name.clone()); - let (key,) = ecdsa_public_key(EcdsaPublicKeyArgument { - canister_id: None, - derivation_path: principal_to_derivation_path(principal), - key_id: EcdsaKeyId { - curve: EcdsaCurve::Secp256k1, - name, - }, - }) - .await - .expect("failed to get public key"); - key.public_key -} - fn parse_eth_address(address: &str) -> [u8; 20] { match address.parse() { Ok(H160(addr)) => addr, @@ -242,36 +210,6 @@ fn parse_eth_address(address: &str) -> [u8; 20] { } } -fn nat_to_u256(n: &Nat) -> U256 { - let be_bytes = n.0.to_bytes_be(); - U256::from_big_endian(&be_bytes) -} - -fn nat_to_u64(n: &Nat) -> U64 { - let be_bytes = n.0.to_bytes_be(); - U64::from_big_endian(&be_bytes) -} - -/// Returns the public key and a message signature for the specified principal. -async fn pubkey_and_signature(caller: &Principal, message_hash: Vec) -> (Vec, Vec) { - // Fetch the pubkey and the signature concurrently to reduce latency. - let (pubkey, response) = futures::join!( - ecdsa_pubkey_of(caller), - sign_with_ecdsa(SignWithEcdsaArgument { - message_hash, - derivation_path: principal_to_derivation_path(caller), - key_id: EcdsaKeyId { - curve: EcdsaCurve::Secp256k1, - name: read_config(|s| s.ecdsa_key_name.clone()), - }, - }) - ); - ( - pubkey, - response.expect("failed to sign the message").0.signature, - ) -} - #[update(guard = "may_write_user_data")] #[allow(clippy::needless_pass_by_value)] fn set_user_token(token: UserToken) { @@ -531,30 +469,4 @@ async fn step_migration() { }; } -/// Computes the parity bit allowing to recover the public key from the signature. -fn y_parity(prehash: &[u8], sig: &[u8], pubkey: &[u8]) -> u64 { - use k256::ecdsa::{RecoveryId, Signature, VerifyingKey}; - - let orig_key = VerifyingKey::from_sec1_bytes(pubkey).expect("failed to parse the pubkey"); - let signature = Signature::try_from(sig).unwrap(); - for parity in [0u8, 1] { - let recid = RecoveryId::try_from(parity).unwrap(); - let recovered_key = VerifyingKey::recover_from_prehash(prehash, &signature, recid) - .expect("failed to recover key"); - if recovered_key == orig_key { - return u64::from(parity); - } - } - - panic!( - "failed to recover the parity bit from a signature; sig: {}, pubkey: {}", - hex::encode(sig), - hex::encode(pubkey) - ) -} - -fn decode_hex(hex: &str) -> Bytes { - Bytes::from(hex::decode(hex.trim_start_matches("0x")).expect("failed to decode hex")) -} - export_candid!(); From 70c696be67def3f9622e3bed4285e30f7a56f975 Mon Sep 17 00:00:00 2001 From: Max Murphy Date: Mon, 16 Sep 2024 14:17:42 +0200 Subject: [PATCH 04/11] Rm threshold tests --- src/backend/tests/it/address.rs | 132 -------------------------------- src/backend/tests/it/main.rs | 1 - 2 files changed, 133 deletions(-) delete mode 100644 src/backend/tests/it/address.rs diff --git a/src/backend/tests/it/address.rs b/src/backend/tests/it/address.rs deleted file mode 100644 index 70af4e0a4..000000000 --- a/src/backend/tests/it/address.rs +++ /dev/null @@ -1,132 +0,0 @@ -use crate::utils::mock::{ - CALLER, CALLER_BTC_ADDRESS_MAINNET, CALLER_BTC_ADDRESS_TESTNET, CALLER_ETH_ADDRESS, -}; -use crate::utils::pocketic::{setup, PicCanisterTrait}; -use candid::Principal; -use ic_cdk::api::management_canister::bitcoin::BitcoinNetwork; - -#[test] -fn test_caller_eth_address() { - let pic_setup = setup(); - - let caller = Principal::from_text(CALLER).unwrap(); - - let address = pic_setup - .update::(caller, "caller_eth_address", ()) - .expect("Failed to call eth address."); - - assert_eq!(address, CALLER_ETH_ADDRESS.to_string()); -} - -#[test] -fn test_eth_address_of() { - let pic_setup = setup(); - - let caller = Principal::from_text(CALLER).unwrap(); - - let address = pic_setup - .update::(caller, "eth_address_of", caller) - .expect("Failed to call eth address of."); - - assert_eq!(address, CALLER_ETH_ADDRESS.to_string()); -} - -#[test] -fn test_anonymous_cannot_call_eth_address() { - let pic_setup = setup(); - - let address = pic_setup.update::(Principal::anonymous(), "caller_eth_address", ()); - - assert!(address.is_err()); - assert_eq!( - address.unwrap_err(), - "Anonymous caller not authorized.".to_string() - ); -} - -#[test] -fn test_non_allowed_caller_cannot_call_eth_address_of() { - let pic_setup = setup(); - - let caller = Principal::from_text(CALLER).unwrap(); - - let address = pic_setup.update::(Principal::anonymous(), "eth_address_of", caller); - - assert!(address.is_err()); - assert_eq!(address.unwrap_err(), "Caller is not allowed.".to_string()); -} - -#[test] -fn test_cannot_call_eth_address_of_for_anonymous() { - let pic_setup = setup(); - - let caller = Principal::from_text(CALLER).unwrap(); - - let address = pic_setup.update::(caller, "eth_address_of", Principal::anonymous()); - - assert!(address.is_err()); - assert!(address - .unwrap_err() - .contains("Anonymous principal is not authorized")); -} - -#[test] -fn test_caller_btc_address_mainnet() { - let pic_setup = setup(); - - let caller = Principal::from_text(CALLER).unwrap(); - let network = BitcoinNetwork::Mainnet; - - let address = pic_setup - .update::(caller, "caller_btc_address", network) - .expect("Failed to call mainnet btc address."); - - assert_eq!(address, CALLER_BTC_ADDRESS_MAINNET.to_string()); -} - -#[test] -fn test_caller_btc_address_testnet() { - let pic_setup = setup(); - - let caller = Principal::from_text(CALLER).unwrap(); - let network = BitcoinNetwork::Testnet; - - let address = pic_setup - .update::(caller, "caller_btc_address", network) - .expect("Failed to call testnet btc address."); - - assert_eq!(address, CALLER_BTC_ADDRESS_TESTNET.to_string()); -} - -#[test] -fn test_anonymous_cannot_call_btc_address() { - let pic_setup = setup(); - let network = BitcoinNetwork::Testnet; - - let address = pic_setup.update::(Principal::anonymous(), "caller_btc_address", network); - - assert!(address.is_err()); - assert_eq!( - address.unwrap_err(), - "Anonymous caller not authorized.".to_string() - ); -} - -#[test] -fn test_testnet_btc_address_is_same_as_regtest() { - let pic_setup = setup(); - - let caller = Principal::from_text(CALLER).unwrap(); - let testnet = BitcoinNetwork::Testnet; - let regtest = BitcoinNetwork::Regtest; - - let address_testnet = pic_setup - .update::(caller, "caller_btc_address", testnet) - .expect("Failed to call testnet btc address."); - - let address_regtest = pic_setup - .update::(caller, "caller_btc_address", regtest) - .expect("Failed to call regtest btc address."); - - assert_eq!(address_testnet, address_regtest); -} diff --git a/src/backend/tests/it/main.rs b/src/backend/tests/it/main.rs index 182aefdbe..43fcc04d4 100644 --- a/src/backend/tests/it/main.rs +++ b/src/backend/tests/it/main.rs @@ -1,4 +1,3 @@ -mod address; mod config; mod custom_token; mod guard; From 49f7be7e0c260bd24466f74af3841d78f5efce03 Mon Sep 17 00:00:00 2001 From: Max Murphy Date: Mon, 16 Sep 2024 14:19:51 +0200 Subject: [PATCH 05/11] Rm unused --- src/backend/src/bitcoin_utils.rs | 20 -------------------- src/backend/src/lib.rs | 15 --------------- 2 files changed, 35 deletions(-) delete mode 100644 src/backend/src/bitcoin_utils.rs diff --git a/src/backend/src/bitcoin_utils.rs b/src/backend/src/bitcoin_utils.rs deleted file mode 100644 index d97b8e3b6..000000000 --- a/src/backend/src/bitcoin_utils.rs +++ /dev/null @@ -1,20 +0,0 @@ -use bitcoin::{Address, Network, PublicKey}; -use ic_cdk::api::management_canister::bitcoin::BitcoinNetwork; - -fn transform_network(network: BitcoinNetwork) -> Network { - match network { - BitcoinNetwork::Mainnet => Network::Bitcoin, - BitcoinNetwork::Testnet => Network::Testnet, - BitcoinNetwork::Regtest => Network::Regtest, - } -} - -/// Converts a public key to a P2PKH address. -/// Reference: [IC Bitcoin Documentation](https://internetcomputer.org/docs/current/developer-docs/multi-chain/bitcoin/using-btc/generate-addresses#generating-addresses-with-threshold-ecdsa) -pub fn public_key_to_p2pkh_address(network: BitcoinNetwork, public_key: &[u8]) -> String { - Address::p2pkh( - PublicKey::from_slice(public_key).expect("failed to parse public key"), - transform_network(network), - ) - .to_string() -} diff --git a/src/backend/src/lib.rs b/src/backend/src/lib.rs index 03fd6ba6d..f859e237c 100644 --- a/src/backend/src/lib.rs +++ b/src/backend/src/lib.rs @@ -1,5 +1,4 @@ use crate::assertions::{assert_token_enabled_is_some, assert_token_symbol_length}; -use crate::bitcoin_utils::public_key_to_p2pkh_address; use crate::guards::{caller_is_allowed, may_read_user_data, may_write_user_data}; use crate::token::{add_to_user_token, remove_from_user_token}; use candid::{Nat, Principal}; @@ -9,10 +8,6 @@ use ethers_core::types::transaction::eip2930::AccessList; use ethers_core::types::Bytes; use ethers_core::utils::keccak256; use ic_cdk::api::management_canister::bitcoin::BitcoinNetwork; -use ic_cdk::api::management_canister::ecdsa::{ - ecdsa_public_key, sign_with_ecdsa, EcdsaCurve, EcdsaKeyId, EcdsaPublicKeyArgument, - SignWithEcdsaArgument, -}; use ic_cdk::api::time; use ic_cdk::eprintln; use ic_cdk_macros::{export_candid, init, post_upgrade, query, update}; @@ -22,16 +17,13 @@ use ic_stable_structures::{ DefaultMemoryImpl, }; use ic_verifiable_credentials::validate_ii_presentation_and_claims; -use k256::PublicKey; use oisy_user::oisy_users; -use pretty_assertions::assert_eq; use serde_bytes::ByteBuf; use shared::http::{HttpRequest, HttpResponse}; use shared::metrics::get_metrics; use shared::std_canister_status; use shared::types::custom_token::{CustomToken, CustomTokenId}; use shared::types::token::{UserToken, UserTokenId}; -use shared::types::transaction::SignRequest; use shared::types::user_profile::{ AddUserCredentialError, AddUserCredentialRequest, GetUserProfileError, ListUsersRequest, ListUsersResponse, OisyUser, UserProfile, @@ -50,7 +42,6 @@ use user_profile::{add_credential, create_profile, find_profile}; use user_profile_model::UserProfileModel; mod assertions; -mod bitcoin_utils; mod config; mod guards; mod impls; @@ -195,12 +186,6 @@ pub fn http_request(request: HttpRequest) -> HttpResponse { } } -fn principal_to_derivation_path(p: &Principal) -> Vec> { - const SCHEMA: u8 = 1; - - vec![vec![SCHEMA], p.as_slice().to_vec()] -} - fn parse_eth_address(address: &str) -> [u8; 20] { match address.parse() { Ok(H160(addr)) => addr, From d94de1d503d7f802cf67765ef3616ac4f540285e Mon Sep 17 00:00:00 2001 From: Max Murphy Date: Mon, 16 Sep 2024 14:20:16 +0200 Subject: [PATCH 06/11] Rm more unused --- src/backend/src/lib.rs | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/backend/src/lib.rs b/src/backend/src/lib.rs index f859e237c..312f47954 100644 --- a/src/backend/src/lib.rs +++ b/src/backend/src/lib.rs @@ -1,13 +1,9 @@ use crate::assertions::{assert_token_enabled_is_some, assert_token_symbol_length}; use crate::guards::{caller_is_allowed, may_read_user_data, may_write_user_data}; use crate::token::{add_to_user_token, remove_from_user_token}; -use candid::{Nat, Principal}; +use candid::Principal; use config::find_credential_config; -use ethers_core::abi::ethereum_types::{Address, H160, U256, U64}; -use ethers_core::types::transaction::eip2930::AccessList; -use ethers_core::types::Bytes; -use ethers_core::utils::keccak256; -use ic_cdk::api::management_canister::bitcoin::BitcoinNetwork; +use ethers_core::abi::ethereum_types::H160; use ic_cdk::api::time; use ic_cdk::eprintln; use ic_cdk_macros::{export_candid, init, post_upgrade, query, update}; @@ -32,7 +28,6 @@ use shared::types::{ Arg, Config, Guards, InitArg, Migration, MigrationProgress, MigrationReport, Stats, }; use std::cell::RefCell; -use std::str::FromStr; use std::time::Duration; use types::{ Candid, ConfigCell, CustomTokenMap, StoredPrincipal, UserProfileMap, UserProfileUpdatedMap, From 476f37962baaaa3c8ec9f323f056e4b7df2c6c4e Mon Sep 17 00:00:00 2001 From: Max Murphy Date: Mon, 16 Sep 2024 14:21:44 +0200 Subject: [PATCH 07/11] Rm unused tests --- src/backend/tests/it/main.rs | 1 - src/backend/tests/it/sign.rs | 110 ----------------------------- src/backend/tests/it/utils/mock.rs | 2 - 3 files changed, 113 deletions(-) delete mode 100644 src/backend/tests/it/sign.rs diff --git a/src/backend/tests/it/main.rs b/src/backend/tests/it/main.rs index 43fcc04d4..05926e039 100644 --- a/src/backend/tests/it/main.rs +++ b/src/backend/tests/it/main.rs @@ -3,7 +3,6 @@ mod custom_token; mod guard; mod list_users; mod migration; -mod sign; mod stats; mod token; mod upgrade; diff --git a/src/backend/tests/it/sign.rs b/src/backend/tests/it/sign.rs deleted file mode 100644 index 2d29091f5..000000000 --- a/src/backend/tests/it/sign.rs +++ /dev/null @@ -1,110 +0,0 @@ -use crate::utils::mock::{CALLER, CALLER_ETH_ADDRESS, SEPOLIA_CHAIN_ID}; -use crate::utils::pocketic::{setup, PicCanisterTrait}; -use candid::{Nat, Principal}; -use shared::types::transaction::SignRequest; - -#[test] -fn test_sign_transaction() { - let pic_setup = setup(); - - let sign_request: SignRequest = SignRequest { - chain_id: Nat::from(SEPOLIA_CHAIN_ID), - to: CALLER_ETH_ADDRESS.to_string(), - gas: Nat::from(123u64), - max_fee_per_gas: Nat::from(456u64), - max_priority_fee_per_gas: Nat::from(789u64), - value: Nat::from(1u64), - nonce: Nat::from(0u64), - data: None, - }; - - let caller = Principal::from_text(CALLER).unwrap(); - - let transaction = pic_setup.update::(caller, "sign_transaction", sign_request); - - assert_eq!( - transaction.unwrap(), - "0x02f86783aa36a7808203158201c87b94dd7fec4c49cd2dd4eaa884d22d92503eaba5a7910180c080a03591058f85526c5e20432e303c3244c6525c3bf8b212eb84179c10acce3adf61a008e46df594b856a80ed5f15a5dfd1631ca8be9609395f2a2f047f84622745243".to_string() - ); -} - -#[test] -fn test_personal_sign() { - let pic_setup = setup(); - - let caller = Principal::from_text(CALLER).unwrap(); - - let transaction = pic_setup.update::( - caller, - "personal_sign", - hex::encode("test message".to_string()), - ); - - assert_eq!( - transaction.unwrap(), - "0x304e37956709f56327742df8cbb0533407aad95f18fc052c039ac9cee1eea30462d8b68aab6799a70fd9163827b521030679c3c6d7d6027b3c255e34e02695fc00".to_string() - ); -} - -#[test] -fn test_cannot_personal_sign_if_message_is_not_hex_string() { - let pic_setup = setup(); - - let caller = Principal::from_text(CALLER).unwrap(); - - let result = pic_setup.update::(caller, "personal_sign", "test message".to_string()); - - assert!(result.is_err()); - assert!(result.unwrap_err().contains("failed to decode hex")); -} - -#[test] -fn test_cannot_sign_transaction_with_invalid_to_address() { - let pic_setup = setup(); - - let sign_request: SignRequest = SignRequest { - chain_id: Nat::from(SEPOLIA_CHAIN_ID), - to: "invalid_address".to_string(), - gas: Nat::from(123u64), - max_fee_per_gas: Nat::from(456u64), - max_priority_fee_per_gas: Nat::from(789u64), - value: Nat::from(1u64), - nonce: Nat::from(0u64), - data: None, - }; - - let caller = Principal::from_text(CALLER).unwrap(); - - let result = pic_setup.update::(caller, "sign_transaction", sign_request); - - assert!(result.is_err()); - assert!(result - .unwrap_err() - .contains("failed to parse the destination address")); -} - -#[test] -fn test_anonymous_cannot_sign_transaction() { - let pic_setup = setup(); - - let result = pic_setup.update::(Principal::anonymous(), "sign_transaction", ()); - - assert!(result.is_err()); - assert_eq!( - result.unwrap_err(), - "Anonymous caller not authorized.".to_string() - ); -} - -#[test] -fn test_anonymous_cannot_personal_sign() { - let pic_setup = setup(); - - let result = pic_setup.update::(Principal::anonymous(), "personal_sign", ()); - - assert!(result.is_err()); - assert_eq!( - result.unwrap_err(), - "Anonymous caller not authorized.".to_string() - ); -} diff --git a/src/backend/tests/it/utils/mock.rs b/src/backend/tests/it/utils/mock.rs index cc010d70a..d737aec04 100644 --- a/src/backend/tests/it/utils/mock.rs +++ b/src/backend/tests/it/utils/mock.rs @@ -1,7 +1,5 @@ pub const CALLER: &str = "xzg7k-thc6c-idntg-knmtz-2fbhh-utt3e-snqw6-5xph3-54pbp-7axl5-tae"; pub const CALLER_ETH_ADDRESS: &str = "0xdd7fec4C49CD2Dd4eaa884D22D92503EabA5A791"; -pub const CALLER_BTC_ADDRESS_MAINNET: &str = "16K9uN3ey148TYcQJhQGmMVRLLBhCKVqDK"; -pub const CALLER_BTC_ADDRESS_TESTNET: &str = "mkq7CR8dn2VPEf622GNebGhkCKnQ8gTD85"; /// An admin user. Typically, controls the backend canister. pub const CONTROLLER: &str = "l3lfs-gak7g-xrbil-j4v4h-aztjn-4jyki-wprso-m27h3-ibcl3-2cwuz-oqe"; From 02721bf3680933fc0163f3e28edfaae4eedd9534 Mon Sep 17 00:00:00 2001 From: Max Murphy Date: Mon, 16 Sep 2024 14:27:24 +0200 Subject: [PATCH 08/11] Rm more signing tests --- scripts/test.backend.sh | 2 +- src/backend/src/guards.rs | 2 +- src/backend/tests/it/upgrade/constants.rs | 3 +- .../tests/it/upgrade/credentials_init_args.rs | 47 ------------------- src/backend/tests/it/upgrade/mod.rs | 1 - src/backend/tests/it/upgrade/token_version.rs | 27 +---------- 6 files changed, 4 insertions(+), 78 deletions(-) delete mode 100644 src/backend/tests/it/upgrade/credentials_init_args.rs diff --git a/scripts/test.backend.sh b/scripts/test.backend.sh index ab27f77d4..4627a286b 100755 --- a/scripts/test.backend.sh +++ b/scripts/test.backend.sh @@ -1,7 +1,7 @@ #!/bin/bash POCKET_IC_SERVER_VERSION=3.0.1 -OISY_UPGRADE_VERSIONS="v0.0.13,v0.0.19,v0.0.25" +OISY_UPGRADE_VERSIONS="v0.0.13,v0.0.19" # If a backend wasm file exists at the root, it will be used for the tests. diff --git a/src/backend/src/guards.rs b/src/backend/src/guards.rs index e0cfd8221..bbc4d96a8 100644 --- a/src/backend/src/guards.rs +++ b/src/backend/src/guards.rs @@ -38,4 +38,4 @@ pub fn may_read_user_data() -> Result<(), String> { } else { Err("User data cannot be read at this time due to a migration.".to_string()) } -} \ No newline at end of file +} diff --git a/src/backend/tests/it/upgrade/constants.rs b/src/backend/tests/it/upgrade/constants.rs index 7f51a31de..3eb332bd2 100644 --- a/src/backend/tests/it/upgrade/constants.rs +++ b/src/backend/tests/it/upgrade/constants.rs @@ -1,3 +1,2 @@ pub const BACKEND_V0_0_13_WASM_PATH: &str = "../../backend-v0.0.13.wasm.gz"; -pub const BACKEND_V0_0_19_WASM_PATH: &str = "../../backend-v0.0.19.wasm.gz"; -pub const BACKEND_V0_0_25_WASM_PATH: &str = "../../backend-v0.0.25.wasm.gz"; +pub const BACKEND_V0_0_19_WASM_PATH: &str = "../../backend-v0.0.19.wasm.gz"; \ No newline at end of file diff --git a/src/backend/tests/it/upgrade/credentials_init_args.rs b/src/backend/tests/it/upgrade/credentials_init_args.rs deleted file mode 100644 index 2be45ea75..000000000 --- a/src/backend/tests/it/upgrade/credentials_init_args.rs +++ /dev/null @@ -1,47 +0,0 @@ -use crate::upgrade::constants::BACKEND_V0_0_25_WASM_PATH; -use crate::upgrade::types::{ArgV0_0_25, InitArgV0_0_25}; -use crate::utils::mock::CALLER; -use crate::utils::pocketic::{BackendBuilder, PicCanisterTrait}; -use candid::{encode_one, Principal}; -use shared::types::{Arg, InitArg}; - -#[test] -fn test_upgrade_credential_init_args() { - let ecdsa_key_name = "master_ecdsa_public_key_fscpm-uiaaa-aaaaa-aaaap-yai".to_string(); - let allowed_callers = vec![Principal::from_text(CALLER).unwrap()]; - // Deploy a released canister - let initial_arg = ArgV0_0_25::Init(InitArgV0_0_25 { - ecdsa_key_name: ecdsa_key_name.clone(), - allowed_callers: allowed_callers.clone(), - }); - let encoded_initial_arg = encode_one(initial_arg).unwrap(); - let pic_setup = BackendBuilder::default() - .with_wasm(BACKEND_V0_0_25_WASM_PATH) - .with_arg(encoded_initial_arg) - .deploy(); - - // Get ETH address before upgrade for post-upgrade test - let caller = Principal::from_text(CALLER).unwrap(); - let initial_result = pic_setup.update::(caller, "caller_eth_address", ()); - - let updated_arg = Arg::Init(InitArg { - ecdsa_key_name: ecdsa_key_name.clone(), - allowed_callers: allowed_callers.clone(), - ic_root_key_der: None, - supported_credentials: None, - api: None, - }); - let encoded_updated_arg = encode_one(updated_arg).unwrap(); - - // Upgrade canister with new wasm - pic_setup - .upgrade_latest_wasm(Some(encoded_updated_arg)) - .unwrap_or_else(|e| panic!("Upgrade canister failed with error: {}", e)); - - let after_upgrade_result = pic_setup.update::(caller, "caller_eth_address", ()); - - assert_eq!( - initial_result.expect("Initial ETH address err"), - after_upgrade_result.expect("Post-upgrade ETH address err") - ); -} diff --git a/src/backend/tests/it/upgrade/mod.rs b/src/backend/tests/it/upgrade/mod.rs index d9630eb2e..7fc7b2c32 100644 --- a/src/backend/tests/it/upgrade/mod.rs +++ b/src/backend/tests/it/upgrade/mod.rs @@ -1,5 +1,4 @@ mod constants; -mod credentials_init_args; mod impls; mod token_enabled; mod token_version; diff --git a/src/backend/tests/it/upgrade/token_version.rs b/src/backend/tests/it/upgrade/token_version.rs index 4ed2cc6dc..5a3a0257c 100644 --- a/src/backend/tests/it/upgrade/token_version.rs +++ b/src/backend/tests/it/upgrade/token_version.rs @@ -2,7 +2,7 @@ use crate::upgrade::constants::{BACKEND_V0_0_13_WASM_PATH, BACKEND_V0_0_19_WASM_ use crate::upgrade::types::{AddUserTokenAfterUpgradeOptions, UserTokenV0_0_13, UserTokenV0_0_19}; use crate::utils::assertion::assert_tokens_data_eq; use crate::utils::mock::{ - CALLER, CALLER_ETH_ADDRESS, WEENUS_CONTRACT_ADDRESS, WEENUS_DECIMALS, WEENUS_SYMBOL, + CALLER, WEENUS_CONTRACT_ADDRESS, WEENUS_DECIMALS, WEENUS_SYMBOL, }; use crate::utils::pocketic::{BackendBuilder, PicCanisterTrait}; use candid::Principal; @@ -57,31 +57,6 @@ fn test_upgrade_user_token() { assert_tokens_data_eq(&results_tokens, &expected_tokens); } -#[test] -fn test_upgrade_allowed_caller_eth_address_of() { - // Deploy a released canister - let pic_setup = BackendBuilder::default() - .with_wasm(BACKEND_V0_0_13_WASM_PATH) - .deploy(); - - // Caller is allowed to call eth_address_of - let caller = Principal::from_text(CALLER).unwrap(); - - let result = pic_setup.update::(caller, "eth_address_of", caller); - assert!(result.is_ok()); - - // Upgrade canister with new wasm - pic_setup - .upgrade_latest_wasm(None) - .unwrap_or_else(|e| panic!("Upgrade canister failed with error: {}", e)); - - // Caller is still allowed to call eth_address_of - let post_upgrade_result = pic_setup.update::(caller, "eth_address_of", caller); - - assert!(post_upgrade_result.is_ok()); - assert_eq!(post_upgrade_result.unwrap(), CALLER_ETH_ADDRESS.to_string()); -} - #[test] fn test_add_user_token_after_upgrade() { test_add_user_token_after_upgrade_with_options(AddUserTokenAfterUpgradeOptions::default()); From e029214defbf7b679f1a720039e7b0578498c7a8 Mon Sep 17 00:00:00 2001 From: Max Murphy Date: Mon, 16 Sep 2024 14:41:14 +0200 Subject: [PATCH 09/11] Update bindings --- src/backend/backend.did | 17 --------------- src/backend/tests/it/upgrade/constants.rs | 2 +- src/backend/tests/it/upgrade/token_version.rs | 4 +--- src/backend/tests/it/utils/mock.rs | 1 - src/declarations/backend/backend.did | 17 --------------- src/declarations/backend/backend.did.d.ts | 17 --------------- .../backend/backend.factory.certified.did.js | 21 ------------------- .../backend/backend.factory.did.js | 21 ------------------- 8 files changed, 2 insertions(+), 98 deletions(-) diff --git a/src/backend/backend.did b/src/backend/backend.did index c4c38c93a..0eb1b48bd 100644 --- a/src/backend/backend.did +++ b/src/backend/backend.did @@ -13,7 +13,6 @@ type AddUserCredentialRequest = record { type ApiEnabled = variant { ReadOnly; Enabled; Disabled }; type Arg = variant { Upgrade; Init : InitArg }; type ArgumentValue = variant { Int : int32; String : text }; -type BitcoinNetwork = variant { mainnet; regtest; testnet }; type CanisterStatusResultV2 = record { controller : principal; status : CanisterStatusType; @@ -114,16 +113,6 @@ type Result = variant { Ok; Err : AddUserCredentialError }; type Result_1 = variant { Ok : UserProfile; Err : GetUserProfileError }; type Result_2 = variant { Ok : MigrationReport; Err : text }; type Result_3 = variant { Ok; Err : text }; -type SignRequest = record { - to : text; - gas : nat; - value : nat; - max_priority_fee_per_gas : nat; - data : opt text; - max_fee_per_gas : nat; - chain_id : nat; - nonce : nat; -}; type Stats = record { user_profile_count : nat64; custom_token_count : nat64; @@ -161,11 +150,8 @@ type UserTokenId = record { chain_id : nat64; contract_address : text }; service : (Arg) -> { add_user_credential : (AddUserCredentialRequest) -> (Result); bulk_up : (blob) -> (); - caller_btc_address : (BitcoinNetwork) -> (text); - caller_eth_address : () -> (text); config : () -> (Config) query; create_user_profile : () -> (UserProfile); - eth_address_of : (principal) -> (text); get_canister_status : () -> (CanisterStatusResultV2); get_user_profile : () -> (Result_1) query; http_request : (HttpRequest) -> (HttpResponse) query; @@ -175,15 +161,12 @@ service : (Arg) -> { migrate_user_data_to : (principal) -> (Result_2); migration : () -> (opt MigrationReport) query; migration_stop_timer : () -> (Result_3); - personal_sign : (text) -> (text); remove_user_token : (UserTokenId) -> (); set_custom_token : (CustomToken) -> (); set_guards : (Guards) -> (); set_many_custom_tokens : (vec CustomToken) -> (); set_many_user_tokens : (vec UserToken) -> (); set_user_token : (UserToken) -> (); - sign_prehash : (text) -> (text); - sign_transaction : (SignRequest) -> (text); stats : () -> (Stats) query; step_migration : () -> (); } diff --git a/src/backend/tests/it/upgrade/constants.rs b/src/backend/tests/it/upgrade/constants.rs index 3eb332bd2..c43796236 100644 --- a/src/backend/tests/it/upgrade/constants.rs +++ b/src/backend/tests/it/upgrade/constants.rs @@ -1,2 +1,2 @@ pub const BACKEND_V0_0_13_WASM_PATH: &str = "../../backend-v0.0.13.wasm.gz"; -pub const BACKEND_V0_0_19_WASM_PATH: &str = "../../backend-v0.0.19.wasm.gz"; \ No newline at end of file +pub const BACKEND_V0_0_19_WASM_PATH: &str = "../../backend-v0.0.19.wasm.gz"; diff --git a/src/backend/tests/it/upgrade/token_version.rs b/src/backend/tests/it/upgrade/token_version.rs index 5a3a0257c..de718c2e7 100644 --- a/src/backend/tests/it/upgrade/token_version.rs +++ b/src/backend/tests/it/upgrade/token_version.rs @@ -1,9 +1,7 @@ use crate::upgrade::constants::{BACKEND_V0_0_13_WASM_PATH, BACKEND_V0_0_19_WASM_PATH}; use crate::upgrade::types::{AddUserTokenAfterUpgradeOptions, UserTokenV0_0_13, UserTokenV0_0_19}; use crate::utils::assertion::assert_tokens_data_eq; -use crate::utils::mock::{ - CALLER, WEENUS_CONTRACT_ADDRESS, WEENUS_DECIMALS, WEENUS_SYMBOL, -}; +use crate::utils::mock::{CALLER, WEENUS_CONTRACT_ADDRESS, WEENUS_DECIMALS, WEENUS_SYMBOL}; use crate::utils::pocketic::{BackendBuilder, PicCanisterTrait}; use candid::Principal; use lazy_static::lazy_static; diff --git a/src/backend/tests/it/utils/mock.rs b/src/backend/tests/it/utils/mock.rs index d737aec04..99165f588 100644 --- a/src/backend/tests/it/utils/mock.rs +++ b/src/backend/tests/it/utils/mock.rs @@ -1,5 +1,4 @@ pub const CALLER: &str = "xzg7k-thc6c-idntg-knmtz-2fbhh-utt3e-snqw6-5xph3-54pbp-7axl5-tae"; -pub const CALLER_ETH_ADDRESS: &str = "0xdd7fec4C49CD2Dd4eaa884D22D92503EabA5A791"; /// An admin user. Typically, controls the backend canister. pub const CONTROLLER: &str = "l3lfs-gak7g-xrbil-j4v4h-aztjn-4jyki-wprso-m27h3-ibcl3-2cwuz-oqe"; diff --git a/src/declarations/backend/backend.did b/src/declarations/backend/backend.did index c4c38c93a..0eb1b48bd 100644 --- a/src/declarations/backend/backend.did +++ b/src/declarations/backend/backend.did @@ -13,7 +13,6 @@ type AddUserCredentialRequest = record { type ApiEnabled = variant { ReadOnly; Enabled; Disabled }; type Arg = variant { Upgrade; Init : InitArg }; type ArgumentValue = variant { Int : int32; String : text }; -type BitcoinNetwork = variant { mainnet; regtest; testnet }; type CanisterStatusResultV2 = record { controller : principal; status : CanisterStatusType; @@ -114,16 +113,6 @@ type Result = variant { Ok; Err : AddUserCredentialError }; type Result_1 = variant { Ok : UserProfile; Err : GetUserProfileError }; type Result_2 = variant { Ok : MigrationReport; Err : text }; type Result_3 = variant { Ok; Err : text }; -type SignRequest = record { - to : text; - gas : nat; - value : nat; - max_priority_fee_per_gas : nat; - data : opt text; - max_fee_per_gas : nat; - chain_id : nat; - nonce : nat; -}; type Stats = record { user_profile_count : nat64; custom_token_count : nat64; @@ -161,11 +150,8 @@ type UserTokenId = record { chain_id : nat64; contract_address : text }; service : (Arg) -> { add_user_credential : (AddUserCredentialRequest) -> (Result); bulk_up : (blob) -> (); - caller_btc_address : (BitcoinNetwork) -> (text); - caller_eth_address : () -> (text); config : () -> (Config) query; create_user_profile : () -> (UserProfile); - eth_address_of : (principal) -> (text); get_canister_status : () -> (CanisterStatusResultV2); get_user_profile : () -> (Result_1) query; http_request : (HttpRequest) -> (HttpResponse) query; @@ -175,15 +161,12 @@ service : (Arg) -> { migrate_user_data_to : (principal) -> (Result_2); migration : () -> (opt MigrationReport) query; migration_stop_timer : () -> (Result_3); - personal_sign : (text) -> (text); remove_user_token : (UserTokenId) -> (); set_custom_token : (CustomToken) -> (); set_guards : (Guards) -> (); set_many_custom_tokens : (vec CustomToken) -> (); set_many_user_tokens : (vec UserToken) -> (); set_user_token : (UserToken) -> (); - sign_prehash : (text) -> (text); - sign_transaction : (SignRequest) -> (text); stats : () -> (Stats) query; step_migration : () -> (); } diff --git a/src/declarations/backend/backend.did.d.ts b/src/declarations/backend/backend.did.d.ts index 6010a23a1..c5b66eb0c 100644 --- a/src/declarations/backend/backend.did.d.ts +++ b/src/declarations/backend/backend.did.d.ts @@ -16,7 +16,6 @@ export interface AddUserCredentialRequest { export type ApiEnabled = { ReadOnly: null } | { Enabled: null } | { Disabled: null }; export type Arg = { Upgrade: null } | { Init: InitArg }; export type ArgumentValue = { Int: number } | { String: string }; -export type BitcoinNetwork = { mainnet: null } | { regtest: null } | { testnet: null }; export interface CanisterStatusResultV2 { controller: Principal; status: CanisterStatusType; @@ -126,16 +125,6 @@ export type Result = { Ok: null } | { Err: AddUserCredentialError }; export type Result_1 = { Ok: UserProfile } | { Err: GetUserProfileError }; export type Result_2 = { Ok: MigrationReport } | { Err: string }; export type Result_3 = { Ok: null } | { Err: string }; -export interface SignRequest { - to: string; - gas: bigint; - value: bigint; - max_priority_fee_per_gas: bigint; - data: [] | [string]; - max_fee_per_gas: bigint; - chain_id: bigint; - nonce: bigint; -} export interface Stats { user_profile_count: bigint; custom_token_count: bigint; @@ -176,11 +165,8 @@ export interface UserTokenId { export interface _SERVICE { add_user_credential: ActorMethod<[AddUserCredentialRequest], Result>; bulk_up: ActorMethod<[Uint8Array | number[]], undefined>; - caller_btc_address: ActorMethod<[BitcoinNetwork], string>; - caller_eth_address: ActorMethod<[], string>; config: ActorMethod<[], Config>; create_user_profile: ActorMethod<[], UserProfile>; - eth_address_of: ActorMethod<[Principal], string>; get_canister_status: ActorMethod<[], CanisterStatusResultV2>; get_user_profile: ActorMethod<[], Result_1>; http_request: ActorMethod<[HttpRequest], HttpResponse>; @@ -190,15 +176,12 @@ export interface _SERVICE { migrate_user_data_to: ActorMethod<[Principal], Result_2>; migration: ActorMethod<[], [] | [MigrationReport]>; migration_stop_timer: ActorMethod<[], Result_3>; - personal_sign: ActorMethod<[string], string>; remove_user_token: ActorMethod<[UserTokenId], undefined>; set_custom_token: ActorMethod<[CustomToken], undefined>; set_guards: ActorMethod<[Guards], undefined>; set_many_custom_tokens: ActorMethod<[Array], undefined>; set_many_user_tokens: ActorMethod<[Array], undefined>; set_user_token: ActorMethod<[UserToken], undefined>; - sign_prehash: ActorMethod<[string], string>; - sign_transaction: ActorMethod<[SignRequest], string>; stats: ActorMethod<[], Stats>; step_migration: ActorMethod<[], undefined>; } diff --git a/src/declarations/backend/backend.factory.certified.did.js b/src/declarations/backend/backend.factory.certified.did.js index 60d3713ca..8c0e84b6e 100644 --- a/src/declarations/backend/backend.factory.certified.did.js +++ b/src/declarations/backend/backend.factory.certified.did.js @@ -46,11 +46,6 @@ export const idlFactory = ({ IDL }) => { Ok: IDL.Null, Err: AddUserCredentialError }); - const BitcoinNetwork = IDL.Variant({ - mainnet: IDL.Null, - regtest: IDL.Null, - testnet: IDL.Null - }); const Config = IDL.Record({ api: IDL.Opt(Guards), ecdsa_key_name: IDL.Text, @@ -180,24 +175,11 @@ export const idlFactory = ({ IDL }) => { chain_id: IDL.Nat64, contract_address: IDL.Text }); - const SignRequest = IDL.Record({ - to: IDL.Text, - gas: IDL.Nat, - value: IDL.Nat, - max_priority_fee_per_gas: IDL.Nat, - data: IDL.Opt(IDL.Text), - max_fee_per_gas: IDL.Nat, - chain_id: IDL.Nat, - nonce: IDL.Nat - }); return IDL.Service({ add_user_credential: IDL.Func([AddUserCredentialRequest], [Result], []), bulk_up: IDL.Func([IDL.Vec(IDL.Nat8)], [], []), - caller_btc_address: IDL.Func([BitcoinNetwork], [IDL.Text], []), - caller_eth_address: IDL.Func([], [IDL.Text], []), config: IDL.Func([], [Config]), create_user_profile: IDL.Func([], [UserProfile], []), - eth_address_of: IDL.Func([IDL.Principal], [IDL.Text], []), get_canister_status: IDL.Func([], [CanisterStatusResultV2], []), get_user_profile: IDL.Func([], [Result_1]), http_request: IDL.Func([HttpRequest], [HttpResponse]), @@ -207,15 +189,12 @@ export const idlFactory = ({ IDL }) => { migrate_user_data_to: IDL.Func([IDL.Principal], [Result_2], []), migration: IDL.Func([], [IDL.Opt(MigrationReport)]), migration_stop_timer: IDL.Func([], [Result_3], []), - personal_sign: IDL.Func([IDL.Text], [IDL.Text], []), remove_user_token: IDL.Func([UserTokenId], [], []), set_custom_token: IDL.Func([CustomToken], [], []), set_guards: IDL.Func([Guards], [], []), set_many_custom_tokens: IDL.Func([IDL.Vec(CustomToken)], [], []), set_many_user_tokens: IDL.Func([IDL.Vec(UserToken)], [], []), set_user_token: IDL.Func([UserToken], [], []), - sign_prehash: IDL.Func([IDL.Text], [IDL.Text], []), - sign_transaction: IDL.Func([SignRequest], [IDL.Text], []), stats: IDL.Func([], [Stats]), step_migration: IDL.Func([], [], []) }); diff --git a/src/declarations/backend/backend.factory.did.js b/src/declarations/backend/backend.factory.did.js index 815111027..28a8cdaa7 100644 --- a/src/declarations/backend/backend.factory.did.js +++ b/src/declarations/backend/backend.factory.did.js @@ -46,11 +46,6 @@ export const idlFactory = ({ IDL }) => { Ok: IDL.Null, Err: AddUserCredentialError }); - const BitcoinNetwork = IDL.Variant({ - mainnet: IDL.Null, - regtest: IDL.Null, - testnet: IDL.Null - }); const Config = IDL.Record({ api: IDL.Opt(Guards), ecdsa_key_name: IDL.Text, @@ -180,24 +175,11 @@ export const idlFactory = ({ IDL }) => { chain_id: IDL.Nat64, contract_address: IDL.Text }); - const SignRequest = IDL.Record({ - to: IDL.Text, - gas: IDL.Nat, - value: IDL.Nat, - max_priority_fee_per_gas: IDL.Nat, - data: IDL.Opt(IDL.Text), - max_fee_per_gas: IDL.Nat, - chain_id: IDL.Nat, - nonce: IDL.Nat - }); return IDL.Service({ add_user_credential: IDL.Func([AddUserCredentialRequest], [Result], []), bulk_up: IDL.Func([IDL.Vec(IDL.Nat8)], [], []), - caller_btc_address: IDL.Func([BitcoinNetwork], [IDL.Text], []), - caller_eth_address: IDL.Func([], [IDL.Text], []), config: IDL.Func([], [Config], ['query']), create_user_profile: IDL.Func([], [UserProfile], []), - eth_address_of: IDL.Func([IDL.Principal], [IDL.Text], []), get_canister_status: IDL.Func([], [CanisterStatusResultV2], []), get_user_profile: IDL.Func([], [Result_1], ['query']), http_request: IDL.Func([HttpRequest], [HttpResponse], ['query']), @@ -207,15 +189,12 @@ export const idlFactory = ({ IDL }) => { migrate_user_data_to: IDL.Func([IDL.Principal], [Result_2], []), migration: IDL.Func([], [IDL.Opt(MigrationReport)], ['query']), migration_stop_timer: IDL.Func([], [Result_3], []), - personal_sign: IDL.Func([IDL.Text], [IDL.Text], []), remove_user_token: IDL.Func([UserTokenId], [], []), set_custom_token: IDL.Func([CustomToken], [], []), set_guards: IDL.Func([Guards], [], []), set_many_custom_tokens: IDL.Func([IDL.Vec(CustomToken)], [], []), set_many_user_tokens: IDL.Func([IDL.Vec(UserToken)], [], []), set_user_token: IDL.Func([UserToken], [], []), - sign_prehash: IDL.Func([IDL.Text], [IDL.Text], []), - sign_transaction: IDL.Func([SignRequest], [IDL.Text], []), stats: IDL.Func([], [Stats], ['query']), step_migration: IDL.Func([], [], []) }); From 6d5244508b223c199baab76abbbe08b729265ea7 Mon Sep 17 00:00:00 2001 From: Max Murphy Date: Mon, 16 Sep 2024 14:57:22 +0200 Subject: [PATCH 10/11] Rm unused crates --- Cargo.lock | 99 ------------------------------------------ Cargo.toml | 1 - src/backend/Cargo.toml | 1 - 3 files changed, 101 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a896dc2aa..994dbcf45 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -123,7 +123,6 @@ checksum = "f1fdabc7756949593fe60f30ec81974b613357de856987752631dea1e3394c80" name = "backend" version = "0.0.3" dependencies = [ - "bitcoin", "candid", "ethers-core", "futures", @@ -176,16 +175,6 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "23ce669cd6c8588f79e15cf450314f9638f967fc5770ff1c7c1deb0925ea7cfa" -[[package]] -name = "base58ck" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c8d66485a3a2ea485c1913c4572ce0256067a5377ac8c75c4960e1cda98605f" -dependencies = [ - "bitcoin-internals", - "bitcoin_hashes", -] - [[package]] name = "base64" version = "0.13.1" @@ -204,12 +193,6 @@ version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" -[[package]] -name = "bech32" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d965446196e3b7decd44aa7ee49e31d630118f90ef12f97900f262eb915c951d" - [[package]] name = "bincode" version = "1.3.3" @@ -242,54 +225,6 @@ dependencies = [ "syn 1.0.109", ] -[[package]] -name = "bitcoin" -version = "0.32.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea507acc1cd80fc084ace38544bbcf7ced7c2aa65b653b102de0ce718df668f6" -dependencies = [ - "base58ck", - "bech32", - "bitcoin-internals", - "bitcoin-io", - "bitcoin-units", - "bitcoin_hashes", - "hex-conservative", - "hex_lit", - "secp256k1", -] - -[[package]] -name = "bitcoin-internals" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30bdbe14aa07b06e6cfeffc529a1f099e5fbe249524f8125358604df99a4bed2" - -[[package]] -name = "bitcoin-io" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "340e09e8399c7bd8912f495af6aa58bea0c9214773417ffaa8f6460f93aaee56" - -[[package]] -name = "bitcoin-units" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5285c8bcaa25876d07f37e3d30c303f2609179716e11d688f51e8f1fe70063e2" -dependencies = [ - "bitcoin-internals", -] - -[[package]] -name = "bitcoin_hashes" -version = "0.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb18c03d0db0247e147a21a6faafd5a7eb851c743db062de72018b6b7e8e4d16" -dependencies = [ - "bitcoin-io", - "hex-conservative", -] - [[package]] name = "bitflags" version = "1.3.2" @@ -1411,21 +1346,6 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" -[[package]] -name = "hex-conservative" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5313b072ce3c597065a808dbf612c4c8e8590bdbf8b579508bf7a762c5eae6cd" -dependencies = [ - "arrayvec 0.7.4", -] - -[[package]] -name = "hex_lit" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3011d1213f159867b13cfd6ac92d2cd5f1345762c63be3554e84092d85a50bbd" - [[package]] name = "hkdf" version = "0.12.4" @@ -3612,25 +3532,6 @@ dependencies = [ "zeroize", ] -[[package]] -name = "secp256k1" -version = "0.29.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e0cc0f1cf93f4969faf3ea1c7d8a9faed25918d96affa959720823dfe86d4f3" -dependencies = [ - "bitcoin_hashes", - "secp256k1-sys", -] - -[[package]] -name = "secp256k1-sys" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1433bd67156263443f14d603720b082dd3121779323fce20cba2aa07b874bc1b" -dependencies = [ - "cc", -] - [[package]] name = "semver" version = "1.0.23" diff --git a/Cargo.toml b/Cargo.toml index a5f7068a5..859d782d9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,6 +24,5 @@ k256 = "0.13" lazy_static = "1.5.0" pocket-ic = "2.2.0" pretty_assertions = "1.4.0" -bitcoin = "0.32.2" strum = "0.26.3" strum_macros = "0.26.4" diff --git a/src/backend/Cargo.toml b/src/backend/Cargo.toml index cc797dd39..5023f2ffb 100644 --- a/src/backend/Cargo.toml +++ b/src/backend/Cargo.toml @@ -7,7 +7,6 @@ edition = "2021" crate-type = ["cdylib"] [dependencies] -bitcoin = { workspace = true } candid = { workspace = true } ethers-core = { workspace = true } futures = { workspace = true } From f90b049c2514b1b3563fdfdd29640a3026822eef Mon Sep 17 00:00:00 2001 From: Max Murphy Date: Mon, 16 Sep 2024 15:06:04 +0200 Subject: [PATCH 11/11] Use the SignRequest type from the signer, not the backend --- src/frontend/src/eth/services/send.services.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/frontend/src/eth/services/send.services.ts b/src/frontend/src/eth/services/send.services.ts index 4fb89d4dd..4fe0381c4 100644 --- a/src/frontend/src/eth/services/send.services.ts +++ b/src/frontend/src/eth/services/send.services.ts @@ -1,4 +1,4 @@ -import type { SignRequest } from '$declarations/backend/backend.did'; +import type { SignRequest } from '$declarations/signer/signer.did'; import { ETH_BASE_FEE } from '$eth/constants/eth.constants'; import { infuraCkErc20Providers } from '$eth/providers/infura-ckerc20.providers'; import { infuraCkETHProviders } from '$eth/providers/infura-cketh.providers';