Skip to content

Commit

Permalink
Impl display trait for New and Unseal
Browse files Browse the repository at this point in the history
Address clippy warning to use writeln
  • Loading branch information
Ben Hindman committed Sep 12, 2023
1 parent af86c79 commit 77c04a3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
2 changes: 1 addition & 1 deletion cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ clap = { version = "4.3.1", features = ["derive"] }
rpassword = { version = "7.2" }

[features]
emulator = ["rust-cktap/emulator"]
emulator = ["rust-cktap/emulator"]
8 changes: 4 additions & 4 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,13 @@ fn main() -> Result<(), Error> {
SatsCardCommand::New => {
let slot = sc.slot().expect("current slot number");
let chain_code = Some(rand_chaincode(rng).to_vec());
let response = &sc.new_slot(slot, chain_code, cvc());
dbg!(response);
let response = &sc.new_slot(slot, chain_code, cvc()).unwrap();
println!("{}", response)
}
SatsCardCommand::Unseal => {
let slot = sc.slot().expect("current slot number");
let response = &sc.unseal(slot, cvc());
dbg!(response);
let response = &sc.unseal(slot, cvc()).unwrap();
println!("{}", response)
}
SatsCardCommand::Derive => {
dbg!(&sc.derive());
Expand Down
23 changes: 20 additions & 3 deletions lib/src/apdu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ use ciborium::de::from_reader;
use ciborium::ser::into_writer;
use ciborium::value::Value;
use secp256k1::ecdh::SharedSecret;
use secp256k1::ecdsa::Signature;
use secp256k1::hashes::hex::ToHex;
use secp256k1::PublicKey;
use secp256k1::{PublicKey, SecretKey, XOnlyPublicKey};
use serde;
use serde::{Deserialize, Serialize};
use std::fmt;
use std::fmt::{Debug, Formatter};

use secp256k1::ecdsa::Signature;

pub const APP_ID: [u8; 15] = *b"\xf0CoinkiteCARDv1";
pub const SELECT_CLA_INS_P1P2: [u8; 4] = [0x00, 0xA4, 0x04, 0x00];
pub const CBOR_CLA_INS_P1P2: [u8; 4] = [0x00, 0xCB, 0x00, 0x00];
Expand Down Expand Up @@ -708,6 +707,12 @@ pub struct NewResponse {

impl ResponseApdu for NewResponse {}

impl fmt::Display for NewResponse {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
writeln!(f, "slot {}", self.slot)
}
}

/// Unseal Command
///
/// Unseal the current slot.
Expand Down Expand Up @@ -768,6 +773,18 @@ pub struct UnsealResponse {

impl ResponseApdu for UnsealResponse {}

impl fmt::Display for UnsealResponse {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let master = XOnlyPublicKey::from_slice(self.master_pk.as_slice()).unwrap();
let pubkey = PublicKey::from_slice(self.pubkey.as_slice()).unwrap();
let privkey = SecretKey::from_slice(self.privkey.as_slice()).unwrap();
writeln!(f, "slot: {}", self.slot)?;
writeln!(f, "master_pk: {}", master)?;
writeln!(f, "pubkey: {}", pubkey)?;
writeln!(f, "privkey: {}", privkey.display_secret())
}
}

/// Dump Command
///
/// This reveals the details for any slot. The current slot is not affected. This is a no-op in
Expand Down

0 comments on commit 77c04a3

Please sign in to comment.