From 45628edb61d0152b6a108cdaee22cc4b985efd76 Mon Sep 17 00:00:00 2001 From: Sosthene Date: Tue, 20 Aug 2024 12:22:03 +0200 Subject: [PATCH] Add Process --- src/api.rs | 126 ++++++++++++++++++------------------------ src/lib.rs | 1 - src/user.rs | 140 +---------------------------------------------- tests/pairing.rs | 10 +++- tests/prd.rs | 18 +++++- tests/utils.rs | 2 + 6 files changed, 79 insertions(+), 218 deletions(-) diff --git a/src/api.rs b/src/api.rs index 6f5ec06..0ecfd7a 100644 --- a/src/api.rs +++ b/src/api.rs @@ -14,6 +14,8 @@ use anyhow::Error as AnyhowError; use sdk_common::crypto::{ AeadCore, Aes256Decryption, Aes256Encryption, Aes256Gcm, AnkSharedSecret, KeyInit, Purpose, }; +use sdk_common::device::{REVOKATION_INDEX, SESSION_INDEX}; +use sdk_common::process::{Member, PairingPcd, Process, Role, ValidationRules}; use sdk_common::sp_client::bitcoin::blockdata::fee_rate; use sdk_common::sp_client::bitcoin::consensus::{deserialize, serialize}; use sdk_common::sp_client::bitcoin::hashes::HashEngine; @@ -47,20 +49,18 @@ use wasm_bindgen::convert::FromWasmAbi; use wasm_bindgen::prelude::*; use sdk_common::network::{ - self, AnkFlag, CachedMessage, CachedMessageStatus, Envelope, FaucetMessage, NewTxMessage, Pcd, Prd + self, AnkFlag, CachedMessage, CachedMessageStatus, Envelope, FaucetMessage, NewTxMessage, Pcd, Prd, PrdType }; use sdk_common::silentpayments::{create_transaction, map_outputs_to_sp_address}; - -use crate::wallet::{generate_sp_wallet, lock_freezed_utxos}; use sdk_common::sp_client::spclient::{ derive_keys_from_seed, OutputList, OutputSpendStatus, OwnedOutput, Recipient, SpClient, }; use sdk_common::sp_client::spclient::{SpWallet, SpendKey}; +use sdk_common::device::Device; -use crate::user::{lock_local_device, set_new_device, Device, LOCAL_DEVICE}; +use crate::user::{lock_local_device, set_new_device, LOCAL_DEVICE}; use crate::{lock_messages, CACHEDMESSAGES}; - -use crate::process::Process; +use crate::wallet::{generate_sp_wallet, lock_freezed_utxos}; pub type ApiResult = Result; @@ -218,7 +218,7 @@ pub fn create_new_device(birthday: u32, network_str: String) -> ApiResult ApiResult<()> { +pub fn pair_device(nym: String, message_id: u32, incoming_pairing_txid: String) -> ApiResult { let mut local_device = lock_local_device()?; // check that we're still in pairing phase @@ -270,75 +270,25 @@ pub fn pair_device(message_id: u32, incoming_pairing_txid: String) -> ApiResult< )?; message.status = CachedMessageStatus::Closed; + + let pairing_pcd = PairingPcd::new( + nym, + local_device.get_wallet().get_client().get_receiving_address().try_into().unwrap(), + local_device.get_paired_device_info().unwrap().address.try_into().unwrap(), + SESSION_INDEX, + REVOKATION_INDEX, + Txid::from_str(&incoming_pairing_txid)?, + pairing_tx.txid + ); + + let pairing_process = Process::new_pairing_process(pairing_pcd, pairing_tx.txid); + + Ok(pairing_process) } else { return Err(ApiError { message: format!("Can't find message with id {}", message_id), }); } - - Ok(()) -} - -#[derive(Tsify, Serialize, Deserialize)] -#[tsify(into_wasm_abi)] -#[allow(non_camel_case_types)] -pub struct get_process_return(Vec); - -#[wasm_bindgen] -pub fn get_processes() -> ApiResult { - let MEMBERS: [String;5] = [ - "tsp1qqdvmxycf3c3tf2qhpev0npx25rj05270d6j2pcsrfk2qn5gdy0rpwq6hd9u9sztl3fwmrzzqafzl3ymkq86aqfz5jl5egdkz72tqmhcnrswdz3pk".to_owned(), - "tsp1qqwafwn7dcr9d6ta0w8fjtd9s53u72x9qmmtgd8adqr7454xl90a5jq3vw23l2x8ypt55nrg7trl9lwz5xr5j357ucu4sf9rfmvc0zujcpqcps6rm".to_owned(), - "tsp1qqw02t5hmg5rxpjdkmjdnnmhvuc76wt6vlqdmn2zafnh6axxjd6e2gqcz04gzvnkzf572mur8spyx2a2s8sqzll2ymdpyz59cpl96j4zuvcdvrzxz".to_owned(), - "tsp1qqgpay2r5jswm7vcv24xd94shdf90w30vxtql9svw7qnlnrzd6xt02q7s7z57uw0sssh6c0xddcrryq4mxup93jsh3gfau3autrawl8umkgsyupkm".to_owned(), - "tsp1qqtsqmtgnxp0lsmnxyxcq52zpgxwugwlq8urlprs5pr5lwyqc789gjqhx5qra6g4rszsq43pms6nguee2l9trx905rk5sgntek05hnf7say4ru69y".to_owned(), - ]; - //instances of process - let process1 = Process { - id: 6, - name: String::from("Messaging"), - version: String::from("1.0"), - members: MEMBERS.to_vec(), - html: crate::process::HTML_MESSAGING.to_owned(), - style: crate::process::CSS.to_owned(), - script: "".to_owned(), - }; - let process2 = Process { - id: 7, - name: String::from("Kotpart"), - version: String::from("1.0"), - members: MEMBERS.to_vec(), - html: crate::process::HTML_MESSAGING.to_owned(), - style: crate::process::CSS.to_owned(), - script: "".to_owned(), - }; - let process3 = Process { - id: 8, - name: String::from("Storage"), - version: String::from("1.0"), - members: MEMBERS.to_vec(), - html: crate::process::HTML_MESSAGING.to_owned(), - style: crate::process::CSS.to_owned(), - script: "".to_owned(), - }; - - // vec with the instances of processes - let mut data_process: Vec = Vec::new(); - data_process.push(process1); - data_process.push(process2); - data_process.push(process3); - Ok(get_process_return(data_process)) -} - -#[derive(Debug, Tsify, Serialize, Deserialize)] -#[tsify(from_wasm_abi)] -#[allow(non_camel_case_types)] -pub struct recover_data(Vec); - -impl recover_data { - fn as_inner(&self) -> &[u8] { - &self.0 - } } #[derive(Debug, Tsify, Serialize, Deserialize)] @@ -728,6 +678,7 @@ pub fn parse_cipher(cipher_msg: String, fee_rate: u32) -> ApiResult ApiResult ApiResult ApiResult { @@ -1093,10 +1069,12 @@ pub fn create_notification_transaction( let key: [u8; 32] = Aes256Gcm::generate_key(thread_rng()).into(); let prd = Prd::new( + PrdType::Message, + process, sp_wallet.get_client().get_receiving_address().try_into().unwrap(), key, pcd_commitment - ); + )?; let prd_commitment = sha256sum(prd.to_string().as_bytes()); diff --git a/src/lib.rs b/src/lib.rs index 983e281..4661ad5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -10,7 +10,6 @@ use tsify::Tsify; pub mod api; mod peers; -mod process; mod user; mod wallet; diff --git a/src/user.rs b/src/user.rs index f244aa2..2f8b11d 100644 --- a/src/user.rs +++ b/src/user.rs @@ -25,6 +25,7 @@ use sdk_common::sp_client::bitcoin::secp256k1::constants::SECRET_KEY_SIZE; use sdk_common::sp_client::silentpayments::bitcoin_hashes::sha256; use sdk_common::sp_client::silentpayments::utils::{Network as SpNetwork, SilentPaymentAddress}; use sdk_common::sp_client::spclient::{OutputList, SpWallet, SpendKey}; +use sdk_common::device::Device; use crate::peers::Peer; use crate::wallet::generate_sp_wallet; @@ -58,142 +59,3 @@ pub fn lock_local_device() -> Result> { .get_or_init(|| Mutex::new(Device::default())) .lock_anyhow() } - -#[derive(Debug, Serialize, Deserialize, Clone, Default, Tsify)] -#[tsify(into_wasm_abi, from_wasm_abi)] -pub struct PairedDevice { - pub address: String, - pub outgoing_pairing_transaction: [u8; 32], - pub revokation_index: u32, - pub incoming_pairing_transaction: [u8; 32], - pub current_remote_key: [u8; 32], - pub current_session_outpoint: OutPoint, // This will be spend by remote device to notify us of next login - pub current_session_revokation_outpoint: OutPoint, // remote device can revoke current session by spending this -} - -impl PairedDevice { - pub fn new(address: SilentPaymentAddress, pairing_txid: Txid, revokation_index: u32) -> Self { - let mut pairing_transaction_buf = [0u8; 32]; - pairing_transaction_buf.copy_from_slice(&serialize(&pairing_txid)); - - Self { - address: address.into(), - outgoing_pairing_transaction: pairing_transaction_buf, - revokation_index, - incoming_pairing_transaction: [0u8; 32], - current_session_revokation_outpoint: OutPoint::default(), - current_session_outpoint: OutPoint::default(), - current_remote_key: [0u8; 32], - } - } -} - -#[derive(Debug, Serialize, Deserialize, Clone, Default, Tsify)] -#[tsify(into_wasm_abi, from_wasm_abi)] -pub struct Device { - sp_wallet: SpWallet, - current_session_outpoint: OutPoint, // This is the notification output of incoming login tx - current_session_key: [u8; 32], - current_session_revokation_outpoint: OutPoint, // This is the revokation outpoint of outgoing login tx - paired_device: Option, -} - -impl Device { - pub fn new(sp_wallet: SpWallet) -> Self { - Self { - sp_wallet, - current_session_outpoint: OutPoint::default(), - current_session_key: [0u8; 32], - current_session_revokation_outpoint: OutPoint::default(), - paired_device: None, - } - } - - pub fn get_wallet(&self) -> &SpWallet { - &self.sp_wallet - } - - pub fn get_mut_wallet(&mut self) -> &mut SpWallet { - &mut self.sp_wallet - } - - pub fn is_linked(&self) -> bool { - self.paired_device.is_some() - } - - pub fn is_pairing(&self) -> bool { - self.current_session_key == [0u8; 32] - } - - pub fn get_paired_device_info(&self) -> Option { - self.paired_device.clone() - } - - pub fn get_next_output_to_spend(&self) -> OutPoint { - self.current_session_outpoint - } - - pub fn get_session_revokation_outpoint(&self) -> OutPoint { - self.current_session_revokation_outpoint - } - - pub fn sign_with_current_session_key(&self) -> Result<()> { - unimplemented!(); - } - - pub fn encrypt_with_current_session_key(&self) -> Result<()> { - unimplemented!(); - } - - pub fn new_link( - &mut self, - link_with: SilentPaymentAddress, - outgoing_pairing_tx: Txid, - revokation_output: u32, - incoming_pairing_tx: Txid, - ) -> Result<()> { - let address_looked_for: String = link_with.into(); - if let Some(paired_device) = self.paired_device.as_ref() { - return Err(Error::msg(format!( - "Found an already paired device with address {} and revokable by {}:{}", - paired_device.address, - Txid::from_byte_array(paired_device.outgoing_pairing_transaction), - paired_device.revokation_index - ))); - } else { - let mut new_device = - PairedDevice::new(link_with, outgoing_pairing_tx, revokation_output); - new_device.incoming_pairing_transaction = incoming_pairing_tx.to_byte_array(); - self.paired_device = Some(new_device); - } - - Ok(()) - } - - // We call that when we spent to the remote device and it similarly spent to us - pub fn update_session( - &mut self, - new_session_key: SecretKey, - new_session_outpoint: OutPoint, - new_revokation_outpoint: OutPoint, - new_remote_key: XOnlyPublicKey, - new_remote_session_outpoint: OutPoint, - new_remote_revokation_outpoint: OutPoint, - ) -> Result<()> { - if !self.is_linked() { - return Err(Error::msg("Can't update an unpaired device")); - } - self.paired_device - .as_mut() - .map(|d| { - d.current_remote_key = new_remote_key.serialize(); - d.current_session_outpoint = new_remote_session_outpoint; - d.current_session_revokation_outpoint = new_remote_revokation_outpoint; - }); - self.current_session_key = new_session_key.secret_bytes(); - self.current_session_outpoint = new_session_outpoint; - self.current_session_revokation_outpoint = new_revokation_outpoint; - - Ok(()) - } -} diff --git a/tests/pairing.rs b/tests/pairing.rs index 2543070..d3686d0 100644 --- a/tests/pairing.rs +++ b/tests/pairing.rs @@ -79,7 +79,13 @@ fn test_pairing() { helper_parse_transaction(&bob_pairing_tx.transaction, &bob_pairing_tweak_data); debug!("Bob pairs device with Alice"); - pair_device(bob_pairing_tx.new_network_msg.id, incoming_txid.to_string()).unwrap(); + let pairing_process = pair_device(DEFAULT_NYM.to_owned(), bob_pairing_tx.new_network_msg.id, incoming_txid.to_string()).unwrap(); + + // sign the pairing process + + // send it to Alice so that she can sign it too + + // commit it to a transaction to make it public // ======================== Alice reset_device().unwrap(); @@ -95,7 +101,7 @@ fn test_pairing() { assert!(bob_pairing_msg.status == CachedMessageStatus::Pairing); debug!("Alice pairs device"); - pair_device(alice_msg_id, bob_pairing_tx.txid).unwrap(); + pair_device(DEFAULT_NYM.to_owned(), alice_msg_id, bob_pairing_tx.txid).unwrap(); } #[wasm_bindgen_test] diff --git a/tests/prd.rs b/tests/prd.rs index 5fea339..736d487 100644 --- a/tests/prd.rs +++ b/tests/prd.rs @@ -7,9 +7,12 @@ use sdk_client::api::{ use sdk_common::network::{ CachedMessage, CachedMessageStatus, Pcd }; -use sdk_common::sp_client::bitcoin::OutPoint; +use sdk_common::process::{Process, Role, ValidationRules}; +use sdk_common::sp_client::bitcoin::hashes::Hash; +use sdk_common::sp_client::bitcoin::{OutPoint, Txid}; use sdk_common::sp_client::spclient::OwnedOutput; +use serde_json::Value; use tsify::JsValueSerdeExt; use wasm_bindgen_test::*; @@ -32,8 +35,19 @@ fn test_alice_sends_prd_message_to_bob() { let pcd = Pcd::new("TEST".to_owned()); debug!("Alice notified Bob about a message it sent"); + let empty_process = Process::new( + "empty".to_owned(), + vec![], + ValidationRules::new(0.0, Role::User), + Txid::all_zeros(), + String::default(), + String::default(), + String::default(), + Value::Null + ); + let notification_tx = - create_notification_transaction(helper_get_bob_address(), pcd, 1).unwrap(); + create_notification_transaction(helper_get_bob_address(), empty_process, pcd, 1).unwrap(); let get_outputs_result = get_outputs().unwrap(); diff --git a/tests/utils.rs b/tests/utils.rs index 4116688..ed8e4d1 100644 --- a/tests/utils.rs +++ b/tests/utils.rs @@ -37,6 +37,8 @@ pub const ALICE_ANSWER_DEVICE: &str = "{\"sp_wallet\":{\"client\":{\"label\":\"d pub const BOB_ANSWER_DEVICE: &str = "{\"sp_wallet\":{\"client\":{\"label\":\"default\",\"scan_sk\":\"0de90b7195c1380d5fde13de3f1d66d53423a9896314839e36ba672653af60b4\",\"spend_key\":{\"Secret\":\"affe686075ecbe17b8ce7de45ec31314804259d0a4bc1c863de21ffd6dc598f8\"},\"mnemonic\":null,\"sp_receiver\":{\"version\":0,\"network\":\"Regtest\",\"scan_pubkey\":[2,85,96,92,243,247,237,192,205,9,178,146,101,237,132,232,15,2,69,138,31,118,76,140,142,207,90,13,192,94,254,150,133],\"spend_pubkey\":[3,5,157,91,250,169,41,61,190,37,30,98,152,253,180,138,250,86,162,102,82,148,130,220,44,153,127,83,43,246,93,17,232],\"change_label\":\"56572fc770b52096879662f97f98263d3e126f5a4a38f00f2895a9dde4c47c1c\",\"labels\":[[\"56572fc770b52096879662f97f98263d3e126f5a4a38f00f2895a9dde4c47c1c\",[2,237,237,247,213,154,87,34,239,168,235,87,122,152,94,41,35,101,184,201,58,201,6,185,58,157,52,208,129,167,2,224,198]]]},\"network\":\"regtest\"},\"outputs\":{\"wallet_fingerprint\":[203,200,4,248,139,36,241,232],\"birthday\":2146,\"last_scan\":2146,\"outputs\":{\"23a09cb1af6a2d350f02c38e9e8727f8ec0e75181f19f781ef6985862577792d:2\":{\"blockheight\":0,\"tweak\":\"e02bb8059b6c787d22715be95de87ea75c120e0f4e0507233bb3e1547b50d98b\",\"amount\":99895292,\"script\":\"51203207d027bb48df9a7c5798091b8bd4912c436c19ea41f04b48ea5dad31118183\",\"label\":\"56572fc770b52096879662f97f98263d3e126f5a4a38f00f2895a9dde4c47c1c\",\"spend_status\":{\"Spent\":\"4b7a78bb8a715fa4875543025182b3f0bb1bc5ca44b852cab57c2929231ddf3f\"}},\"78e97c940d3353718864c251489da99be99441323cabe619522169d22b030fb8:0\":{\"blockheight\":0,\"tweak\":\"898284108952bd8b0e74030e00b81c1b387ee151a810ca3b40143da227707df2\",\"amount\":1200,\"script\":\"5120c0ff94a1318f0061960a713c927ff175a0d71a791497e94e70601c3baae739b8\",\"label\":null,\"spend_status\":{\"Spent\":\"4b7a78bb8a715fa4875543025182b3f0bb1bc5ca44b852cab57c2929231ddf3f\"}},\"4b7a78bb8a715fa4875543025182b3f0bb1bc5ca44b852cab57c2929231ddf3f:2\":{\"blockheight\":0,\"tweak\":\"b13107995241e7daaf13e89ff62a007dd592173c02284a46c9d40778e9fd8165\",\"amount\":99894746,\"script\":\"5120fc7226dc54ed54144d7f6081726fa1d6b5d0fc6aca09a0cc689cc9552e81db14\",\"label\":\"56572fc770b52096879662f97f98263d3e126f5a4a38f00f2895a9dde4c47c1c\",\"spend_status\":\"Unspent\"},\"5e18963dcdd5e94b4b5dfaa147a6e62889a367d9fc1a016973f84c07a192982c:0\":{\"blockheight\":0,\"tweak\":\"ac6c259ddf88509b3663a412f4d40403cafb3a89c8a6922770384ba1806ecda0\",\"amount\":1200,\"script\":\"512010bb317e1ee70b2be456609f5c7aeaa8106b615326220f0e73ad5e78d0322f22\",\"label\":null,\"spend_status\":\"Unspent\"},\"650088ebc28e4d5d7b4ee2e0337b4907a02537f5be6c28c63da88a6b67b9af1d:1\":{\"blockheight\":0,\"tweak\":\"281ea54f74e5f6582a7462bdd9397b9a786f97455e858e7901a6a4fa95f39192\",\"amount\":654,\"script\":\"5120aa4395e2be9cbce580e94f4308d64422da251b7df12fb8c571675d40cc50cf00\",\"label\":\"56572fc770b52096879662f97f98263d3e126f5a4a38f00f2895a9dde4c47c1c\",\"spend_status\":\"Unspent\"},\"576c2e53fe924d68deb7262cfc0e4023b5889652dec35671e1e7cf255d61c28f:1\":{\"blockheight\":0,\"tweak\":\"f0ad83734cdc7d73575e5a32651390cf30b92cc7e44cf94ec37da46900ecaf71\",\"amount\":654,\"script\":\"5120230cc1e85829be238e666f469653cbc2f1c0e3675a9bf33e1d1f91115f5dd306\",\"label\":\"56572fc770b52096879662f97f98263d3e126f5a4a38f00f2895a9dde4c47c1c\",\"spend_status\":\"Unspent\"},\"e2c6ff9927c8a5f7a60087117732c07ab7cd82c0c65462e9c780eb5ce9c35292:0\":{\"blockheight\":0,\"tweak\":\"0e3395ff27bde9187ffaeeb2521f6277d3b83911f16ccbaf59a1a68d99a0ab93\",\"amount\":1200,\"script\":\"512010f06f764cbc923ec3198db946307bf0c06a1b4f09206055e47a6fec0a33d52c\",\"label\":null,\"spend_status\":{\"Spent\":\"576c2e53fe924d68deb7262cfc0e4023b5889652dec35671e1e7cf255d61c28f\"}},\"23a09cb1af6a2d350f02c38e9e8727f8ec0e75181f19f781ef6985862577792d:1\":{\"blockheight\":0,\"tweak\":\"a68aed757eb3aca6bcbd0deb749eb26767963401e07d568b19f05f9945fce9b3\",\"amount\":248,\"script\":\"5120d3a39aed25fccd3338aa8c9d40c015febfb4361cffb6cfdcede3032317dc26ff\",\"label\":null,\"spend_status\":\"Unspent\"},\"4b7a78bb8a715fa4875543025182b3f0bb1bc5ca44b852cab57c2929231ddf3f:1\":{\"blockheight\":0,\"tweak\":\"73cd0a0ebe8e61c3f5ec6b414107934238c4642924272823fb630ef828c14a97\",\"amount\":248,\"script\":\"51202c1f1be3cff73416dc34de0d5f7760095a51f6b4a7bfa118441221718394beea\",\"label\":null,\"spend_status\":\"Unspent\"},\"93722ea2fb9b74954210b4cdd1360e280b7ff1bc156d6b75f847e62411c588fb:0\":{\"blockheight\":0,\"tweak\":\"da5e3aa2378e3a257f99eb1e0ae4c672916f6a2f32a8ed9a8e146f2074da981b\",\"amount\":443,\"script\":\"51209eb9e950127b6a7d81668f25b4d5b164b42dafe59ce40b80e6c489ec983540d7\",\"label\":null,\"spend_status\":{\"Spent\":\"23a09cb1af6a2d350f02c38e9e8727f8ec0e75181f19f781ef6985862577792d\"}},\"fbd9c63e0dd08c2569b51a0d6095a79ee2acfcac66acdb594328a095f1fadb63:1\":{\"blockheight\":2146,\"tweak\":\"678dbcbdb40cd3733c8dbbd508761a0937009cf75a9f466e3c98877e79037cbc\",\"amount\":99896595,\"script\":\"5120deab0c5a3d23de30477b0b5a95a261c96e29afdd9813c665d2bf025ad2b3f919\",\"label\":null,\"spend_status\":{\"Spent\":\"23a09cb1af6a2d350f02c38e9e8727f8ec0e75181f19f781ef6985862577792d\"}},\"494aa6088c4ff368c04ee9dcacad8ab20d91587bacd48e030ab510b012131fe2:0\":{\"blockheight\":0,\"tweak\":\"21fc32bded971dd15387671436232f17d932e18758f69b476219e2d6e688767f\",\"amount\":1200,\"script\":\"5120230d06322d10a5838634df3c55eef9959a1c0c144108e0416b9687eaf22e6baa\",\"label\":null,\"spend_status\":{\"Spent\":\"650088ebc28e4d5d7b4ee2e0337b4907a02537f5be6c28c63da88a6b67b9af1d\"}}}},\"tx_history\":[]},\"current_session_outpoint\":\"5e18963dcdd5e94b4b5dfaa147a6e62889a367d9fc1a016973f84c07a192982c:0\",\"current_session_key\":[92,106,141,254,85,117,14,178,239,50,33,247,83,151,23,25,144,142,183,115,190,26,14,113,238,72,13,18,29,254,37,87],\"current_session_revokation_outpoint\":\"4b7a78bb8a715fa4875543025182b3f0bb1bc5ca44b852cab57c2929231ddf3f:1\",\"paired_device\":{\"address\":\"sprt1qqf50y6deqe7dqg3vj562xf3lmktqe3sct78ha6e9jh54sa3q2m5esq7x2tz0xrpm0ekclyyaszc2sh3ksm5gkumxpwegpa80lv5wgsuefqaufx8q\",\"outgoing_pairing_transaction\":[45,121,119,37,134,133,105,239,129,247,25,31,24,117,14,236,248,39,135,158,142,195,2,15,53,45,106,175,177,156,160,35],\"revokation_index\":1,\"incoming_pairing_transaction\":[184,15,3,43,210,105,33,82,25,230,171,60,50,65,148,233,155,169,157,72,81,194,100,136,113,83,51,13,148,124,233,120],\"current_remote_key\":[156,58,113,25,63,127,197,36,130,253,81,106,26,54,244,223,85,246,70,161,95,21,236,196,245,84,151,38,43,6,231,200],\"current_session_outpoint\":\"4b7a78bb8a715fa4875543025182b3f0bb1bc5ca44b852cab57c2929231ddf3f:0\",\"current_session_revokation_outpoint\":\"5e18963dcdd5e94b4b5dfaa147a6e62889a367d9fc1a016973f84c07a192982c:1\"}}"; pub const ALICE_FINAL_DEVICE: &str = "{\"sp_wallet\":{\"client\":{\"label\":\"default\",\"scan_sk\":\"e3d8922a41a7cb1a84a90f4334e987bb5ea2df6a1fdf44f789b5302de119f9e2\",\"spend_key\":{\"Secret\":\"93292e5b21042c6cfc742ba30e9d2a1e01609b12d154a1825184ed12c7b9631b\"},\"mnemonic\":null,\"sp_receiver\":{\"version\":0,\"network\":\"Regtest\",\"scan_pubkey\":[2,104,242,105,185,6,124,208,34,44,149,52,163,38,63,221,150,12,198,24,95,143,126,235,37,149,233,88,118,32,86,233,152],\"spend_pubkey\":[3,198,82,196,243,12,59,126,109,143,144,157,128,176,168,94,54,134,232,139,115,102,11,178,128,244,239,251,40,228,67,153,72],\"change_label\":\"ac14a827e2d023b8f7804303a47259366117d99ed932b641d4a8eaf1b82cc992\",\"labels\":[[\"ac14a827e2d023b8f7804303a47259366117d99ed932b641d4a8eaf1b82cc992\",[2,244,223,255,57,50,216,27,133,112,138,69,120,126,85,110,6,242,141,33,136,191,82,164,241,54,179,115,84,161,145,174,154]]]},\"network\":\"regtest\"},\"outputs\":{\"wallet_fingerprint\":[187,119,108,230,171,125,106,11],\"birthday\":1620,\"last_scan\":2146,\"outputs\":{\"78e97c940d3353718864c251489da99be99441323cabe619522169d22b030fb8:1\":{\"blockheight\":0,\"tweak\":\"cfea493360d6ffe2bfd13e4c5c2f677351e0c038f1ce0cd5383fadad6adc79f1\",\"amount\":191,\"script\":\"51200f008ff13f876bf328c69f10ad8621c9770ff8d5eb1861cb67199189a6308bb9\",\"label\":null,\"spend_status\":{\"Spent\":\"5e18963dcdd5e94b4b5dfaa147a6e62889a367d9fc1a016973f84c07a192982c\"}},\"650088ebc28e4d5d7b4ee2e0337b4907a02537f5be6c28c63da88a6b67b9af1d:0\":{\"blockheight\":0,\"tweak\":\"de507c854cee16d2e157fbf6c6dbfd2e721b861efc7f657bb724790fc7829665\",\"amount\":349,\"script\":\"5120028143243ed5d4554e60d96ee61fdf6f6e359a9083311c210645c0a7fef51248\",\"label\":null,\"spend_status\":{\"Spent\":\"f07c116303c88e7b22169f0872c67e3196ad8312170313643a8f47482c6bd308\"}},\"494aa6088c4ff368c04ee9dcacad8ab20d91587bacd48e030ab510b012131fe2:1\":{\"blockheight\":0,\"tweak\":\"97b06ded6644c6ae2a861342db3375d10a002da72f367a0acd5b8890c277df1e\",\"amount\":248,\"script\":\"5120902e75b33f6a80f20edd2574f02f5eaf3fc196aaad9c494263465519606a47a7\",\"label\":null,\"spend_status\":{\"Spent\":\"f07c116303c88e7b22169f0872c67e3196ad8312170313643a8f47482c6bd308\"}},\"5e18963dcdd5e94b4b5dfaa147a6e62889a367d9fc1a016973f84c07a192982c:1\":{\"blockheight\":0,\"tweak\":\"49471984d232f62afb7421c904a26ec073b968e76e3e1b8f4371f2f730ba627f\",\"amount\":191,\"script\":\"51203b12839f99ca62bd09eb277bab720b9bb506003ed5b3fa6654f37a42f3cf1825\",\"label\":null,\"spend_status\":{\"Spent\":\"494aa6088c4ff368c04ee9dcacad8ab20d91587bacd48e030ab510b012131fe2\"}},\"e2c6ff9927c8a5f7a60087117732c07ab7cd82c0c65462e9c780eb5ce9c35292:2\":{\"blockheight\":0,\"tweak\":\"e3e21d551e933199f8c977bc0362616bdfb128da7ca9728bd7254977541c39cc\",\"amount\":3936897,\"script\":\"5120df3af55a63bd056c5d6d09f47a3a19c382d938c08db8bc41a59c5235970209ad\",\"label\":\"ac14a827e2d023b8f7804303a47259366117d99ed932b641d4a8eaf1b82cc992\",\"spend_status\":{\"Spent\":\"78e97c940d3353718864c251489da99be99441323cabe619522169d22b030fb8\"}},\"78e97c940d3353718864c251489da99be99441323cabe619522169d22b030fb8:2\":{\"blockheight\":0,\"tweak\":\"6ebffdcaf1da7b160b167caed039e795f8b6d5168903972f9436aaedef574f28\",\"amount\":3935806,\"script\":\"5120fe0ec587ba0a8f8b1ef7c708a8b67723e55d45fb8e5c12ffc8874d61dedc3c16\",\"label\":\"ac14a827e2d023b8f7804303a47259366117d99ed932b641d4a8eaf1b82cc992\",\"spend_status\":{\"Spent\":\"5e18963dcdd5e94b4b5dfaa147a6e62889a367d9fc1a016973f84c07a192982c\"}},\"9a4a67cc5a40bf882d8b300d91024d7c97024b3b68b2df7745a5b9ea1df1888c:1\":{\"blockheight\":1620,\"tweak\":\"b8b63b3ed97d297b744135cfac2fb4a344c881a77543b71f1fcd16bc67514f26\",\"amount\":3938643,\"script\":\"51205b7b324bb71d411e32f2c61fda5d1db23f5c7d6d416a77fab87c913a1b120be1\",\"label\":\"ac14a827e2d023b8f7804303a47259366117d99ed932b641d4a8eaf1b82cc992\",\"spend_status\":{\"Spent\":\"e2c6ff9927c8a5f7a60087117732c07ab7cd82c0c65462e9c780eb5ce9c35292\"}},\"23a09cb1af6a2d350f02c38e9e8727f8ec0e75181f19f781ef6985862577792d:0\":{\"blockheight\":0,\"tweak\":\"dac814c1ceff86cac3476e028ffa6eda0d9858bd74288a0e6e9e5cef271f723c\",\"amount\":1200,\"script\":\"51205e349be9fff1dc0c8e6bae3d35679029c57d9e554f0bb9705b71491d9b7569f1\",\"label\":null,\"spend_status\":{\"Spent\":\"5e18963dcdd5e94b4b5dfaa147a6e62889a367d9fc1a016973f84c07a192982c\"}},\"576c2e53fe924d68deb7262cfc0e4023b5889652dec35671e1e7cf255d61c28f:0\":{\"blockheight\":0,\"tweak\":\"6e5c1d4690b9ff4fa26e5185ada25af5c2987650e629a518db8a43fdaad7a26c\",\"amount\":349,\"script\":\"512088ac90e180c87b7fa6aa33db4c72a8620cd08fda3ba1c71430b904eb068c587f\",\"label\":null,\"spend_status\":{\"Spent\":\"78e97c940d3353718864c251489da99be99441323cabe619522169d22b030fb8\"}},\"4b7a78bb8a715fa4875543025182b3f0bb1bc5ca44b852cab57c2929231ddf3f:0\":{\"blockheight\":0,\"tweak\":\"2e3636950174a42842da254d7936f589e8c9ded6e17c90656bb759467fff9ea0\",\"amount\":1200,\"script\":\"51209c3a71193f7fc52482fd516a1a36f4df55f646a15f15ecc4f55497262b06e7c8\",\"label\":null,\"spend_status\":\"Unspent\"},\"e2c6ff9927c8a5f7a60087117732c07ab7cd82c0c65462e9c780eb5ce9c35292:1\":{\"blockheight\":0,\"tweak\":\"7c84a3074c18c23a65eceaca49a327989ef6e7240e0e080421afb80f06906d73\",\"amount\":306,\"script\":\"5120eb78084d7a2ccbdb7eb7e9bba7cf875c4e54a5aba0beac57c5d3e41133bd8fdd\",\"label\":null,\"spend_status\":{\"Spent\":\"78e97c940d3353718864c251489da99be99441323cabe619522169d22b030fb8\"}},\"5e18963dcdd5e94b4b5dfaa147a6e62889a367d9fc1a016973f84c07a192982c:2\":{\"blockheight\":0,\"tweak\":\"86a78efb4f522790d46096df9261435e3f7cab5f5129efe4ff77562fb4834a0c\",\"amount\":3935451,\"script\":\"5120c314279d078acaa41b5d897f98b81f09546001b6422e90e0b3f902ac7442a6b7\",\"label\":\"ac14a827e2d023b8f7804303a47259366117d99ed932b641d4a8eaf1b82cc992\",\"spend_status\":{\"Spent\":\"494aa6088c4ff368c04ee9dcacad8ab20d91587bacd48e030ab510b012131fe2\"}},\"494aa6088c4ff368c04ee9dcacad8ab20d91587bacd48e030ab510b012131fe2:2\":{\"blockheight\":0,\"tweak\":\"6493d306b4650a36321d05270e2067b58839637da52f0fc29cd2f05817fff0d6\",\"amount\":3933896,\"script\":\"51206666fc11233881b1c831e032e9b06cf05a90ed93fef4f35c78583b9eec845ab5\",\"label\":\"ac14a827e2d023b8f7804303a47259366117d99ed932b641d4a8eaf1b82cc992\",\"spend_status\":\"Unspent\"}}},\"tx_history\":[]},\"current_session_outpoint\":\"4b7a78bb8a715fa4875543025182b3f0bb1bc5ca44b852cab57c2929231ddf3f:0\",\"current_session_key\":[193,95,100,240,34,120,208,149,63,78,80,240,135,212,31,167,234,42,121,233,178,209,49,231,189,60,70,89,71,185,1,187],\"current_session_revokation_outpoint\":\"5e18963dcdd5e94b4b5dfaa147a6e62889a367d9fc1a016973f84c07a192982c:1\",\"paired_device\":{\"address\":\"sprt1qqf2kqh8n7lkupngfk2fxtmvyaq8sy3v2ramyeryweadqmsz7l6tg2qc9n4dl42ff8klz28nznr7mfzh6263xv555stwzextl2v4lvhg3aqq7ru8u\",\"outgoing_pairing_transaction\":[184,15,3,43,210,105,33,82,25,230,171,60,50,65,148,233,155,169,157,72,81,194,100,136,113,83,51,13,148,124,233,120],\"revokation_index\":1,\"incoming_pairing_transaction\":[45,121,119,37,134,133,105,239,129,247,25,31,24,117,14,236,248,39,135,158,142,195,2,15,53,45,106,175,177,156,160,35],\"current_remote_key\":[16,187,49,126,30,231,11,43,228,86,96,159,92,122,234,168,16,107,97,83,38,34,15,14,115,173,94,120,208,50,47,34],\"current_session_outpoint\":\"5e18963dcdd5e94b4b5dfaa147a6e62889a367d9fc1a016973f84c07a192982c:0\",\"current_session_revokation_outpoint\":\"4b7a78bb8a715fa4875543025182b3f0bb1bc5ca44b852cab57c2929231ddf3f:1\"}}"; +pub const DEFAULT_NYM: &str = "AliceBob"; + pub fn helper_switch_device(wallet: String) { reset_device().unwrap(); restore_device_from_sp_wallet(wallet.clone()).unwrap();