Skip to content

Commit 4694844

Browse files
committed
refactor!: move factory_root_keys mod code to shared
Also update README completed commands.
1 parent 2d408d4 commit 4694844

File tree

5 files changed

+88
-80
lines changed

5 files changed

+88
-80
lines changed

README.md

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ It is up to the crate user to send and receive the raw cktap APDU messages via N
2020
#### Shared Commands
2121

2222
- [x] [status](https://github.com/coinkite/coinkite-tap-proto/blob/master/docs/protocol.md#status)
23-
- [x] [read](https://github.com/coinkite/coinkite-tap-proto/blob/master/docs/protocol.md#status) (messages)
24-
- [x] response verification
25-
- [x] [derive](https://github.com/coinkite/coinkite-tap-proto/blob/master/docs/protocol.md#derive) (messages)
23+
- [x] [read](https://github.com/coinkite/coinkite-tap-proto/blob/master/docs/protocol.md#read)
2624
- [x] response verification
25+
- [x] [derive](https://github.com/coinkite/coinkite-tap-proto/blob/master/docs/protocol.md#derive)
26+
- [ ] response verification
2727
- [x] [certs](https://github.com/coinkite/coinkite-tap-proto/blob/master/docs/protocol.md#certs)
2828
- [x] [new](https://github.com/coinkite/coinkite-tap-proto/blob/master/docs/protocol.md#new)
29-
- [x] [nfc](https://github.com/coinkite/coinkite-tap-proto/blob/master/docs/protocol.md#nfc)
30-
- [x] [sign](https://github.com/coinkite/coinkite-tap-proto/blob/master/docs/protocol.md#sign) (messages)
31-
- [ ] response verification
29+
- [ ] [nfc](https://github.com/coinkite/coinkite-tap-proto/blob/master/docs/protocol.md#nfc)
30+
- [x] [sign](https://github.com/coinkite/coinkite-tap-proto/blob/master/docs/protocol.md#sign)
31+
- [x] response verification
3232
- [x] [wait](https://github.com/coinkite/coinkite-tap-proto/blob/master/docs/protocol.md#wait)
3333

3434
#### SATSCARD-Only Commands
@@ -39,31 +39,49 @@ It is up to the crate user to send and receive the raw cktap APDU messages via N
3939
#### TAPSIGNER-Only Commands
4040

4141
- [x] [change](https://github.com/coinkite/coinkite-tap-proto/blob/master/docs/protocol.md#change)
42-
- [x] [xpub](https://github.com/coinkite/coinkite-tap-proto/blob/master/docs/protocol.md#xpub)
42+
- [ ] [xpub](https://github.com/coinkite/coinkite-tap-proto/blob/master/docs/protocol.md#xpub)
4343
- [x] [backup](https://github.com/coinkite/coinkite-tap-proto/blob/master/docs/protocol.md#backup)
4444

45-
### Automated Testing with Emulator
45+
### Automated and CLI Testing with Emulator
46+
47+
#### Prerequisites
4648

4749
1. Install dependencies for [cktap emulator](https://github.com/coinkite/coinkite-tap-proto/blob/master/emulator/README.md)
48-
2. run tests with emulator: `just test`
50+
51+
#### Run tests with emulator
52+
53+
```
54+
just test
55+
```
56+
57+
#### Run CLI with emulated card reader
58+
59+
```
60+
just start # for SATSCARD emulator
61+
just start -t # for TAPSIGNER emulator
62+
just run_emu --help
63+
just run_emu certs
64+
just run_emu read
65+
just stop # stop emulator
66+
```
4967

5068
### Manual Testing with real cards
5169

5270
#### Prerequisites
5371

54-
1. USB PCSC NFC card reader, for example:
72+
1. Get USB PCSC NFC card reader, for example:
5573
- [OMNIKEY 5022 CL](https://www.hidglobal.com/products/omnikey-5022-reader)
56-
2. Coinkite SATSCARD, TAPSIGNER, or SATSCHIP cards
57-
Install vendor PCSC driver
58-
3. Connect NFC reader to desktop system
59-
4. Place SATSCARD, TAPSIGNER, or SATSCHIP on reader
74+
2. Get Coinkite SATSCARD, TAPSIGNER, or SATSCHIP cards
75+
3. Install card reader PCSC driver
76+
4. Connect USB PCSC NFC reader to desktop system
77+
5. Place SATSCARD, TAPSIGNER, or SATSCHIP on reader
6078

61-
#### Run CLI
79+
#### Run CLI with desktop USB PCSC NFC card reader
6280

6381
```
64-
cargo run -p cktap-cli -- --help
65-
cargo run -p cktap-cli -- certs
66-
cargo run -p cktap-cli -- read
82+
just run --help
83+
just run certs
84+
just run read
6785
```
6886

6987
## Minimum Supported Rust Version (MSRV)

cktap-ffi/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use crate::sats_chip::SatsChip;
1616
use crate::tap_signer::TapSigner;
1717
use futures::lock::Mutex;
1818
use rust_cktap::Network;
19-
use rust_cktap::factory_root_key::FactoryRootKey;
19+
use rust_cktap::shared::FactoryRootKey;
2020
use rust_cktap::shared::{Certificate, Read};
2121
use std::fmt::Debug;
2222
use std::str::FromStr;

lib/src/factory_root_key.rs

Lines changed: 0 additions & 57 deletions
This file was deleted.

lib/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ use bitcoin::key::rand::Rng as _;
2020

2121
pub(crate) mod apdu;
2222
pub mod error;
23-
pub mod factory_root_key;
2423
pub mod sats_card;
2524
pub mod sats_chip;
2625
pub mod shared;

lib/src/shared.rs

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright (c) 2025 rust-cktap contributors
22
// SPDX-License-Identifier: MIT OR Apache-2.0
33

4-
use crate::factory_root_key::FactoryRootKey;
54
use crate::{CardError, CkTapCard, CkTapError, SatsCard, TapSigner};
65
use crate::{apdu::*, rand_nonce};
76

@@ -12,14 +11,63 @@ use bitcoin::secp256k1::ecdsa::{RecoverableSignature, RecoveryId, Signature};
1211
use bitcoin::secp256k1::{All, Message, Secp256k1};
1312
use bitcoin_hashes::sha256;
1413

15-
use std::convert::TryFrom;
16-
1714
use crate::error::{CertsError, ReadError, StatusError};
1815
use crate::sats_chip::SatsChip;
1916
use async_trait::async_trait;
17+
use bitcoin_hashes::hex::DisplayHex;
18+
use std::convert::TryFrom;
19+
use std::fmt;
2020
use std::fmt::Debug;
2121
use std::sync::Arc;
2222

23+
/// Published Coinkite factory root keys.
24+
const PUB_FACTORY_ROOT_KEY: &str =
25+
"03028a0e89e70d0ec0d932053a89ab1da7d9182bdc6d2f03e706ee99517d05d9e1";
26+
/// Obsolete dev value, but keeping for a little while longer.
27+
const DEV_FACTORY_ROOT_KEY: &str =
28+
"027722ef208e681bac05f1b4b3cc478d6bf353ac9a09ff0c843430138f65c27bab";
29+
30+
pub enum FactoryRootKey {
31+
Pub(secp256k1::PublicKey),
32+
Dev(secp256k1::PublicKey),
33+
}
34+
35+
impl TryFrom<secp256k1::PublicKey> for FactoryRootKey {
36+
type Error = CertsError;
37+
38+
fn try_from(pubkey: secp256k1::PublicKey) -> Result<Self, CertsError> {
39+
match pubkey.serialize().to_lower_hex_string().as_str() {
40+
PUB_FACTORY_ROOT_KEY => Ok(FactoryRootKey::Pub(pubkey)),
41+
DEV_FACTORY_ROOT_KEY => Ok(FactoryRootKey::Dev(pubkey)),
42+
_ => Err(CertsError::InvalidRootCert(
43+
pubkey.serialize().to_lower_hex_string(),
44+
)),
45+
}
46+
}
47+
}
48+
49+
impl FactoryRootKey {
50+
pub fn name(&self) -> String {
51+
match &self {
52+
FactoryRootKey::Pub(_) => "Root Factory Certificate".to_string(),
53+
FactoryRootKey::Dev(_) => "Root Factory Certificate (TESTING ONLY)".to_string(),
54+
}
55+
}
56+
}
57+
58+
impl Debug for FactoryRootKey {
59+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
60+
match &self {
61+
FactoryRootKey::Pub(pk) => {
62+
write!(f, "FactoryRootKey::Pub({pk:?})")
63+
}
64+
FactoryRootKey::Dev(pk) => {
65+
write!(f, "FactoryRootKey::Dev({pk:?})")
66+
}
67+
}
68+
}
69+
}
70+
2371
/// Helper functions for authenticated commands.
2472
pub trait Authentication {
2573
fn secp(&self) -> &Secp256k1<All>;

0 commit comments

Comments
 (0)