Skip to content
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
2 changes: 1 addition & 1 deletion cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ async fn main() -> Result<(), Error> {
SatsCardCommand::Debug => {
dbg!(&sc);
}
SatsCardCommand::Address => println!("Address: {}", sc.address().unwrap()),
SatsCardCommand::Address => println!("Address: {}", sc.address().await.unwrap()),
SatsCardCommand::Certs => check_cert(sc).await,
SatsCardCommand::Read => read(sc, None).await,
SatsCardCommand::New => {
Expand Down
25 changes: 11 additions & 14 deletions lib/src/sats_card.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use bitcoin::secp256k1::{
ecdsa::Signature,
hashes::{sha256, Hash as _},
All, Message, PublicKey, Secp256k1,
};
use bitcoin::hashes::{sha256, Hash as _};
use bitcoin::key::CompressedPublicKey as BitcoinPublicKey;
use bitcoin::secp256k1::{ecdsa::Signature, All, Message, PublicKey, Secp256k1};
use bitcoin::{Address, Network};

use crate::apdu::{
CommandApdu as _, DeriveCommand, DeriveResponse, DumpCommand, DumpResponse, Error, NewCommand,
Expand Down Expand Up @@ -140,15 +139,13 @@ impl<T: CkTransport> SatsCard<T> {
self.transport.transmit(&dump_command).await
}

pub fn address(&mut self) -> Result<String, Error> {
// let pubkey = self.read(None).unwrap().pubkey;
// // let hrp = match self.testnet() { }
// let encoded = bech32::encode("bc", pubkey.to_base32(), Variant::Bech32);
// match encoded {
// Ok(e) => Ok(e),
// Err(_) => panic!("Failed to encoded pubkey")
// }
todo!()
pub async fn address(&mut self) -> Result<String, Error> {
// TODO: support testnet
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK SATSCARDs and TAPSIGNERs will never support testnet as part of their security policy to prevent people from tricking users into accepting cards with bogus bitcoin.

let network = Network::Bitcoin;
let slot_pubkey = self.read(None).await?.pubkey;
let pk = BitcoinPublicKey::from_slice(&slot_pubkey)?;
let address = Address::p2wpkh(&pk, network);
Ok(address.to_string())
}
}

Expand Down
Loading