Skip to content

Commit

Permalink
feat: imKey support dogecoin[R2D2-12636] (#132)
Browse files Browse the repository at this point in the history
* feat: support dogecoin address

* feat: ikc supprot dogecoin

* test: add dogecoin device_accounts test case

* test: add dogecoin device_sub_account test case

* feat: Modify the bitcoin address generation method

* feat: support dogecoin sign and add test case

* chore: modify dogecoin instance id

* test: delete useless test case
  • Loading branch information
xiaoguang1010 authored Oct 25, 2024
1 parent cece9e9 commit 85a2e35
Show file tree
Hide file tree
Showing 21 changed files with 1,422 additions and 347 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions imkey-core/ikc-common/src/applet.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::constants::{
BCH_AID, BTC_AID, COSMOS_AID, EOS_AID, ETH_AID, FILECOIN_AID, IMK_AID, KUSAMA_AID, LTC_AID,
NERVOS_AID, POLKADOT_AID, TEZOS_AID, TRON_AID,
BCH_AID, BTC_AID, COSMOS_AID, DOGECOIN_AID, EOS_AID, ETH_AID, FILECOIN_AID, IMK_AID,
KUSAMA_AID, LTC_AID, NERVOS_AID, POLKADOT_AID, TEZOS_AID, TRON_AID,
};
// type __appletName = 'IMK' | 'Ethereum' | 'Bitcoin' | 'EOS' | 'Cosmos' | 'Filecoin' | 'Kusama' | 'Tezos' | 'Polkadot' | 'TRON' | 'Bitcoin Cash' | 'Litecoin' | 'Nervos'
pub fn get_appname_by_instid(instid: &str) -> Option<&str> {
Expand All @@ -18,6 +18,7 @@ pub fn get_appname_by_instid(instid: &str) -> Option<&str> {
IMK_AID => Some("IMK"),
NERVOS_AID => Some("Nervos"),
TEZOS_AID => Some("Tezos"),
DOGECOIN_AID => Some("Dogecoin"),
_ => None,
}
}
Expand All @@ -36,6 +37,7 @@ pub fn get_instid_by_appname(appname: &str) -> Option<&str> {
"Bitcoin Cash" => Some(BCH_AID),
"Litecoin" => Some(LTC_AID),
"IMK" => Some(IMK_AID),
"Dogecoin" => Some(DOGECOIN_AID),
_ => None,
}
}
Expand All @@ -56,6 +58,7 @@ mod tests {
assert_eq!(get_appname_by_instid("695F626368").unwrap(), "Bitcoin Cash");
assert_eq!(get_appname_by_instid("695F6C7463").unwrap(), "Litecoin");
assert_eq!(get_appname_by_instid("695F696D6B").unwrap(), "IMK");
assert_eq!(get_appname_by_instid("695F646F6765636F696E").unwrap(), "Dogecoin");
assert!(get_appname_by_instid("1111111111").is_none());
}

Expand All @@ -72,6 +75,7 @@ mod tests {
);
assert_eq!(get_instid_by_appname("Bitcoin Cash").unwrap(), "695F626368");
assert_eq!(get_instid_by_appname("Litecoin").unwrap(), "695F6C7463");
assert_eq!(get_instid_by_appname("Dogecoin").unwrap(), "695F646F6765636F696E");
assert!(get_instid_by_appname("APPLET").is_none());
}
}
56 changes: 56 additions & 0 deletions imkey-core/ikc-common/src/coin_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,62 @@ lazy_static! {
network: "TESTNET".to_string(),
seg_wit: "".to_string(),
},
CoinInfo {
coin: "DOGECOIN".to_string(),
derivation_path: "m/44'/3'/0'/0/0".to_string(),
curve: CurveType::SECP256k1,
network: "MAINNET".to_string(),
seg_wit: "NONE".to_string(),
},
CoinInfo {
coin: "DOGECOIN".to_string(),
derivation_path: "m/44'/1'/0'/0/0".to_string(),
curve: CurveType::SECP256k1,
network: "TESTNET".to_string(),
seg_wit: "NONE".to_string(),
},
CoinInfo {
coin: "DOGECOIN".to_string(),
derivation_path: "m/49'/3'/0'/0/0".to_string(),
curve: CurveType::SECP256k1,
network: "MAINNET".to_string(),
seg_wit: "P2WPKH".to_string(),
},
CoinInfo {
coin: "DOGECOIN".to_string(),
derivation_path: "m/49'/1'/0'/0/0".to_string(),
curve: CurveType::SECP256k1,
network: "TESTNET".to_string(),
seg_wit: "P2WPKH".to_string(),
},
CoinInfo {
coin: "DOGECOIN".to_string(),
derivation_path: "m/84'/3'/0'/0/0".to_string(),
curve: CurveType::SECP256k1,
network: "MAINNET".to_string(),
seg_wit: "VERSION_0".to_string(),
},
CoinInfo {
coin: "DOGECOIN".to_string(),
derivation_path: "m/84'/1'/0'/0/0".to_string(),
curve: CurveType::SECP256k1,
network: "TESTNET".to_string(),
seg_wit: "VERSION_0".to_string(),
},
CoinInfo {
coin: "DOGECOIN".to_string(),
derivation_path: "m/86'/3'/0'/0/0".to_string(),
curve: CurveType::SECP256k1,
network: "MAINNET".to_string(),
seg_wit: "VERSION_1".to_string(),
},
CoinInfo {
coin: "DOGECOIN".to_string(),
derivation_path: "m/86'/1'/0'/0/0".to_string(),
curve: CurveType::SECP256k1,
network: "TESTNET".to_string(),
seg_wit: "VERSION_1".to_string(),
},
];
RwLock::new(coin_infos)
};
Expand Down
1 change: 1 addition & 0 deletions imkey-core/ikc-common/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub const NERVOS_AID: &str = "695F6B315F636B62";
pub const TEZOS_AID: &str = "695F65645F78747A";
pub const BCH_AID: &str = "695F626368";
pub const LTC_AID: &str = "695F6C7463";
pub const DOGECOIN_AID: &str = "695F646F6765636F696E";

pub const BL_AID: &str = "D0426F6F746C6F61646572";

Expand Down
2 changes: 2 additions & 0 deletions imkey-core/ikc-common/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ pub enum CommonError {
InvalidKeyIvLength,
#[error("invalid_base58")]
InvalidBase58,
#[error("missing_network")]
MissingNetwork,
}

#[derive(Error, Debug, PartialOrd, PartialEq)]
Expand Down
1 change: 0 additions & 1 deletion imkey-core/ikc-wallet/coin-bch/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use crate::address::BchAddress;
use crate::transaction::Utxo;
use crate::Result;
use bitcoin::network::constants::Network;
use bitcoin::secp256k1::Secp256k1 as BitcoinSecp256k1;
use bitcoin::util::base58;
use bitcoin::util::bip32::{ChainCode, ChildNumber, ExtendedPubKey};
use bitcoin::{Address, PublicKey};
Expand Down
3 changes: 2 additions & 1 deletion imkey-core/ikc-wallet/coin-bitcoin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ num-bigint = "=0.4.3"
anyhow = "=1.0.79"
bytes = "=1.4.0"
prost = "=0.11.2"
prost-types = "=0.11.2"
prost-types = "=0.11.2"
bech32 = "=0.9.1"
1 change: 0 additions & 1 deletion imkey-core/ikc-wallet/coin-bitcoin/src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use bitcoin::network::constants::Network;
use bitcoin::schnorr::UntweakedPublicKey;
use bitcoin::util::bip32::{ChainCode, ChildNumber, DerivationPath, ExtendedPubKey, Fingerprint};
use bitcoin::{Address, PublicKey};
use bitcoin_hashes::{hash160, Hash};
use ikc_common::apdu::{ApduCheck, BtcApdu, CoinCommonApdu};
use ikc_common::constants;
use ikc_common::error::CommonError;
Expand Down
Loading

0 comments on commit 85a2e35

Please sign in to comment.