Skip to content
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

Feature/support dogecoin #112

Merged
merged 2 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions token-core/tcx-btc-kin/src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ mod tests {

use crate::address::BtcKinAddress;
use crate::tcx_keystore::Address;
use crate::tests::sample_hd_keystore;
use crate::BtcKinNetwork;

#[test]
Expand Down Expand Up @@ -302,6 +303,18 @@ mod tests {
.unwrap()
.to_string();
assert_eq!(addr, "bc1qum864wd9nwsc0u9ytkctz6wzrw6g7zdntm7f4e");

let network = BtcKinNetwork::find_by_coin("DOGECOIN", "MAINNET").unwrap();
let addr = BtcKinAddress::p2pkh(&pub_key, &network)
.unwrap()
.to_string();
assert_eq!(addr, "DSBWjKzZtz7fPzu4N6mBRwQFHCQ6KQSjue");

let network = BtcKinNetwork::find_by_coin("DOGECOIN", "TESTNET").unwrap();
let addr = BtcKinAddress::p2pkh(&pub_key, &network)
.unwrap()
.to_string();
assert_eq!(addr, "nqEaTLjUpxaPGyUFPvQdgLzYX4nPLCD1Py");
}

#[test]
Expand Down Expand Up @@ -477,6 +490,23 @@ mod tests {
assert_eq!(address, "bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4");
}

#[test]
fn test_dogecoin_address() {
let mut hd = sample_hd_keystore();
let account = hd
.derive_coin::<BtcKinAddress>(&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(),
})
.unwrap();
assert_eq!(account.address, "DQ4tVEqdPWHc1aVBm4Sfwft8XyNRPMEchR");
assert_eq!(account.ext_pub_key, "xpub6CDSaXHQokkKmHHG2kNCFZeirJkcZgRZE97ZZUtViif3SFHSNVAvRpWC3CxeRt2VZetEGCcPTmWEFpKF4NDeeZrMNPQgfUaX5Hkw89kW8qE");
}


#[test]
fn test_bip84_spec_vector() {
let pub_key = TypedPublicKey::from_slice(
Expand Down
18 changes: 18 additions & 0 deletions token-core/tcx-btc-kin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ pub use transaction::{BtcKinTxInput, BtcKinTxOutput, OmniTxInput, Utxo};
pub const BITCOIN: &str = "BITCOIN";
pub const BITCOINCASH: &str = "BITCOINCASH";

pub const DOGECOIN: &str = "DOGECOIN";

pub const LITECOIN: &str = "LITECOIN";

pub const OMNI: &str = "OMNI";
Expand Down Expand Up @@ -90,6 +92,22 @@ pub mod bitcoincash {
pub type MessageOutput = crate::transaction::BtcMessageOutput;
}

pub mod dogecoin {
use crate::DOGECOIN;

pub static CHAINS: [&str; 1] = [DOGECOIN];

pub type Address = crate::BtcKinAddress;

pub type TransactionInput = crate::transaction::BtcKinTxInput;

pub type TransactionOutput = crate::transaction::BtcKinTxOutput;

pub type MessageInput = crate::transaction::BtcMessageInput;

pub type MessageOutput = crate::transaction::BtcMessageOutput;
}

pub mod omni {
use crate::OMNI;

Expand Down
22 changes: 21 additions & 1 deletion token-core/tcx-btc-kin/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub struct BtcKinNetwork {
pub xpub_prefix: [u8; 4],
pub xprv_prefix: [u8; 4],
}
const BTC_KIN_NETWORKS: [BtcKinNetwork; 6] = [
const BTC_KIN_NETWORKS: [BtcKinNetwork; 8] = [
BtcKinNetwork {
coin: "BITCOIN",
network: "MAINNET",
Expand Down Expand Up @@ -72,6 +72,26 @@ const BTC_KIN_NETWORKS: [BtcKinNetwork; 6] = [
xpub_prefix: [0x04, 0x35, 0x87, 0xcf],
xprv_prefix: [0x04, 0x35, 0x83, 0x94],
},
BtcKinNetwork {
coin: "DOGECOIN",
network: "TESTNET",
bech32_hrp: "",
p2pkh_prefix: 0x71,
p2sh_prefix: 0xc4,
private_prefix: 0xf1,
xpub_prefix: [0x04, 0x35, 0x87, 0xcf],
xprv_prefix: [0x04, 0x35, 0x83, 0x94],
},
BtcKinNetwork {
coin: "DOGECOIN",
network: "MAINNET",
bech32_hrp: "",
p2pkh_prefix: 0x1e,
p2sh_prefix: 0x16,
private_prefix: 0x9e,
xpub_prefix: [0x02, 0xfa, 0xca, 0xfd],
xprv_prefix: [0x02, 0xfa, 0xc3, 0x98],
},
];

impl BtcKinNetwork {
Expand Down
Loading