-
Notifications
You must be signed in to change notification settings - Fork 111
feat(wallet-connect): impl BTC (UTxO) activation via WalletConnect #2499
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 44 commits
e39ff92
facae9d
638fe3f
a5b5909
ab0edba
42ddeb1
fd0c6ab
803d8f5
9799ec9
72e845b
9a03495
3769d41
bc796a2
f15163f
735403d
6dd49c1
31d9edc
a665b55
028ff49
b892571
ca8e1a0
2c72ad6
98f9d5f
17bf308
eee71ca
16aa656
f3451fe
4587a1d
af1cc4b
c86a2bf
87bb907
480ad38
9bf308a
4149627
a22b14b
35d7353
f17f300
6521246
84f3f0b
e893297
33868a6
f0719d6
821a5dd
188424a
0947655
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4294,11 +4294,14 @@ impl CoinsContext { | |
| } | ||
|
|
||
| /// This enum is used in coin activation requests. | ||
| #[derive(Copy, Clone, Debug, Deserialize, Serialize, Default)] | ||
| #[derive(Clone, Debug, Deserialize, Serialize, Default)] | ||
| pub enum PrivKeyActivationPolicy { | ||
| #[default] | ||
| ContextPrivKey, | ||
| Trezor, | ||
| WalletConnect { | ||
| session_topic: kdf_walletconnect::WcTopic, | ||
| }, | ||
| } | ||
|
|
||
| impl PrivKeyActivationPolicy { | ||
|
|
@@ -4356,10 +4359,16 @@ pub enum PrivKeyPolicy<T> { | |
| /// - `public_key`: Compressed public key, represented as [H264]. | ||
| /// - `public_key_uncompressed`: Uncompressed public key, represented as [H520]. | ||
| /// - `session_topic`: WalletConnect session that was used to activate this coin. | ||
| // TODO: We want to have different variants of WalletConnect policy for different coin types: | ||
| // - ETH uses the structure found here. | ||
| // - Tendermint doesn't use this variant all together. Tendermint generalizes one level on top of PrivKeyPolicy by having a different activation policy | ||
| // structure that is either Priv(PrivKeyPolicy) or Pubkey(PublicKey) and when activated via wallet connect it uses the Pubkey(PublicKey) variant. | ||
| // - UTXO coins on the otherhand need to keep a list of all the addresses activated in the wallet and not just a single account. | ||
| // - Note: We need to have a way to select which account and address are the active ones (WalletConnect just spams us with all the addresses in every account). | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As discussed, we might not go the active address route for UTXO walletconnect, specially for ledger support to make sense. This is of course for next PRs. |
||
| WalletConnect { | ||
| public_key: H264, | ||
| public_key_uncompressed: H520, | ||
| session_topic: String, | ||
| session_topic: kdf_walletconnect::WcTopic, | ||
| }, | ||
| } | ||
|
|
||
|
|
@@ -4502,6 +4511,7 @@ pub enum PrivKeyBuildPolicy { | |
| IguanaPrivKey(IguanaPrivKey), | ||
| GlobalHDAccount(GlobalHDAccountArc), | ||
| Trezor, | ||
| WalletConnect { session_topic: kdf_walletconnect::WcTopic }, | ||
| } | ||
|
|
||
| impl PrivKeyBuildPolicy { | ||
|
|
@@ -4677,11 +4687,21 @@ pub trait IguanaBalanceOps { | |
| async fn iguana_balances(&self) -> BalanceResult<Self::BalanceObject>; | ||
| } | ||
|
|
||
| #[derive(Clone, Debug, Default, Deserialize, Serialize)] | ||
| /// Information about the UTXO protocol used by a coin. | ||
| pub struct UtxoProtocolInfo { | ||
| /// A CAIP-2 compliant chain ID. Starts with `b122:` | ||
| /// This is used to identify the blockchain when using WalletConnect. | ||
| /// https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-4.md | ||
| chain_id: String, | ||
| } | ||
|
|
||
|
||
| #[allow(clippy::upper_case_acronyms)] | ||
| #[derive(Clone, Debug, Deserialize, Serialize)] | ||
| #[serde(tag = "type", content = "protocol_data")] | ||
| pub enum CoinProtocol { | ||
| UTXO, | ||
| // TODO: Nest this option deep into the innert struct fields when more fields are added to the UTXO protocol info. | ||
| UTXO(Option<UtxoProtocolInfo>), | ||
| QTUM, | ||
| QRC20 { | ||
| platform: String, | ||
|
|
@@ -4758,7 +4778,7 @@ impl CoinProtocol { | |
| CoinProtocol::TENDERMINTTOKEN(info) => Some(&info.platform), | ||
| #[cfg(not(target_arch = "wasm32"))] | ||
| CoinProtocol::LIGHTNING { platform, .. } => Some(platform), | ||
| CoinProtocol::UTXO | ||
| CoinProtocol::UTXO { .. } | ||
| | CoinProtocol::QTUM | ||
| | CoinProtocol::ETH { .. } | ||
| | CoinProtocol::TRX { .. } | ||
|
|
@@ -4777,7 +4797,7 @@ impl CoinProtocol { | |
| Some(contract_address) | ||
| }, | ||
| CoinProtocol::SLPTOKEN { .. } | ||
| | CoinProtocol::UTXO | ||
| | CoinProtocol::UTXO { .. } | ||
| | CoinProtocol::QTUM | ||
| | CoinProtocol::ETH { .. } | ||
| | CoinProtocol::TRX { .. } | ||
|
|
@@ -5069,7 +5089,7 @@ pub async fn lp_coininit(ctx: &MmArc, ticker: &str, req: &Json) -> Result<MmCoin | |
| let protocol: CoinProtocol = try_s!(json::from_value(coins_en["protocol"].clone())); | ||
|
|
||
| let coin: MmCoinEnum = match &protocol { | ||
| CoinProtocol::UTXO => { | ||
| CoinProtocol::UTXO { .. } => { | ||
| let params = try_s!(UtxoActivationParams::from_legacy_req(req)); | ||
| try_s!(utxo_standard_coin_with_policy(ctx, ticker, &coins_en, ¶ms, priv_key_policy).await).into() | ||
| }, | ||
|
|
@@ -5742,7 +5762,7 @@ pub fn address_by_coin_conf_and_pubkey_str( | |
| }, | ||
| // Todo: implement TRX address generation | ||
| CoinProtocol::TRX { .. } => ERR!("TRX address generation is not implemented yet"), | ||
| CoinProtocol::UTXO | CoinProtocol::QTUM | CoinProtocol::QRC20 { .. } | CoinProtocol::BCH { .. } => { | ||
| CoinProtocol::UTXO { .. } | CoinProtocol::QTUM | CoinProtocol::QRC20 { .. } | CoinProtocol::BCH { .. } => { | ||
| utxo::address_by_conf_and_pubkey_str(coin, conf, pubkey, addr_format) | ||
| }, | ||
| CoinProtocol::SLPTOKEN { platform, .. } => { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.