nash_protocol/types/blockchain/
btc.rs1use crate::errors::{ProtocolError, Result};
4
5#[cfg(feature = "secp256k1")]
6use nash_mpc::curves::secp256_k1::Secp256k1Point;
7#[cfg(feature = "k256")]
8use nash_mpc::curves::secp256_k1_rust::Secp256k1Point;
9
10use nash_mpc::curves::traits::ECPoint;
11
12#[derive(Clone, Debug, PartialEq)]
14pub struct Address {
15 pub(crate) inner: String,
16}
17
18impl Address {
19 pub fn new(s: &str) -> Result<Self> {
20 Ok(Self {
21 inner: s.to_string(),
22 })
23 }
24}
25
26#[derive(Clone, Debug, PartialEq)]
27pub struct PublicKey {
28 inner: Secp256k1Point,
29}
30
31impl PublicKey {
32 pub fn new(hex_str: &str) -> Result<Self> {
33 let inner = Secp256k1Point::from_hex(hex_str).map_err(|_| {
34 ProtocolError("Could not create public key (Secp256k1Point) from hex string")
35 })?;
36 Ok(Self { inner })
37 }
38
39 pub fn to_address(&self) -> Result<Address> {
40 Err(ProtocolError("This has not been implemented for BTC"))
41 }
42
43 pub fn to_hex(&self) -> String {
44 self.inner.to_hex()
45 }
46}
47
48#[cfg(test)]
49mod tests {
50 use super::Address;
51 #[test]
52 fn address() {
53 let _btc_addr = Address::new("3DxbL9tNd2yCn6yqCghgkGYnUcJihMbjtw").unwrap();
54 }
55}