Skip to content

Commit b707a57

Browse files
committed
fix(ffi)!: replace usize with u32 or smaller
BREAKING CHANGE.
1 parent 742678d commit b707a57

File tree

5 files changed

+384
-561
lines changed

5 files changed

+384
-561
lines changed

cktap-ffi/src/error.rs

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -269,15 +269,15 @@ impl From<rust_cktap::DumpError> for DumpError {
269269
#[derive(Clone, Debug, PartialEq, Eq, thiserror::Error, uniffi::Error)]
270270
pub enum SignPsbtError {
271271
#[error("Invalid path at index: {index}")]
272-
InvalidPath { index: u64 },
272+
InvalidPath { index: u32 },
273273
#[error("Invalid script at index: {index}")]
274-
InvalidScript { index: u64 },
274+
InvalidScript { index: u32 },
275275
#[error("Missing pubkey at index: {index}")]
276-
MissingPubkey { index: u64 },
276+
MissingPubkey { index: u32 },
277277
#[error("Missing UTXO at index: {index}")]
278-
MissingUtxo { index: u64 },
278+
MissingUtxo { index: u32 },
279279
#[error("Pubkey mismatch at index: {index}")]
280-
PubkeyMismatch { index: u64 },
280+
PubkeyMismatch { index: u32 },
281281
#[error("Sighash error: {msg}")]
282282
SighashError { msg: String },
283283
#[error("Signature error: {msg}")]
@@ -300,21 +300,17 @@ pub enum SignPsbtError {
300300
impl From<rust_cktap::SignPsbtError> for SignPsbtError {
301301
fn from(value: rust_cktap::SignPsbtError) -> SignPsbtError {
302302
match value {
303-
rust_cktap::SignPsbtError::InvalidPath(index) => SignPsbtError::InvalidPath {
304-
index: index as u64,
305-
},
306-
rust_cktap::SignPsbtError::InvalidScript(index) => SignPsbtError::InvalidScript {
307-
index: index as u64,
308-
},
309-
rust_cktap::SignPsbtError::MissingPubkey(index) => SignPsbtError::MissingPubkey {
310-
index: index as u64,
311-
},
312-
rust_cktap::SignPsbtError::MissingUtxo(index) => SignPsbtError::MissingUtxo {
313-
index: index as u64,
314-
},
315-
rust_cktap::SignPsbtError::PubkeyMismatch(index) => SignPsbtError::PubkeyMismatch {
316-
index: index as u64,
317-
},
303+
rust_cktap::SignPsbtError::InvalidPath(index) => SignPsbtError::InvalidPath { index },
304+
rust_cktap::SignPsbtError::InvalidScript(index) => {
305+
SignPsbtError::InvalidScript { index }
306+
}
307+
rust_cktap::SignPsbtError::MissingPubkey(index) => {
308+
SignPsbtError::MissingPubkey { index }
309+
}
310+
rust_cktap::SignPsbtError::MissingUtxo(index) => SignPsbtError::MissingUtxo { index },
311+
rust_cktap::SignPsbtError::PubkeyMismatch(index) => {
312+
SignPsbtError::PubkeyMismatch { index }
313+
}
318314
rust_cktap::SignPsbtError::SighashError(msg) => SignPsbtError::SighashError { msg },
319315
rust_cktap::SignPsbtError::SignatureError(msg) => SignPsbtError::SignatureError { msg },
320316
rust_cktap::SignPsbtError::SlotNotUnsealed(slot) => {
@@ -349,9 +345,9 @@ pub enum ChangeError {
349345
err: CkTapError,
350346
},
351347
#[error("new cvc is too short, must be at least 6 bytes, was only {len} bytes")]
352-
TooShort { len: u64 },
348+
TooShort { len: u8 },
353349
#[error("new cvc is too long, must be at most 32 bytes, was {len} bytes")]
354-
TooLong { len: u64 },
350+
TooLong { len: u8 },
355351
#[error("new cvc is the same as the old one")]
356352
SameAsOld,
357353
}
@@ -360,8 +356,8 @@ impl From<rust_cktap::ChangeError> for ChangeError {
360356
fn from(value: rust_cktap::ChangeError) -> Self {
361357
match value {
362358
rust_cktap::ChangeError::CkTap(err) => ChangeError::CkTap { err: err.into() },
363-
rust_cktap::ChangeError::TooShort(len) => ChangeError::TooShort { len: len as u64 },
364-
rust_cktap::ChangeError::TooLong(len) => ChangeError::TooLong { len: len as u64 },
359+
rust_cktap::ChangeError::TooShort(len) => ChangeError::TooShort { len },
360+
rust_cktap::ChangeError::TooLong(len) => ChangeError::TooLong { len },
365361
rust_cktap::ChangeError::SameAsOld => ChangeError::SameAsOld,
366362
}
367363
}

cktap-ffi/src/sats_card.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ pub struct SatsCard(pub Mutex<rust_cktap::SatsCard>);
1616

1717
#[derive(uniffi::Record, Debug, Clone)]
1818
pub struct SatsCardStatus {
19-
pub proto: u64,
19+
pub proto: u32,
2020
pub ver: String,
21-
pub birth: u64,
21+
pub birth: u32,
2222
pub active_slot: u8,
2323
pub num_slots: u8,
2424
pub addr: Option<String>,
@@ -40,9 +40,9 @@ impl SatsCard {
4040
let card = self.0.lock().await;
4141
let pubkey = card.pubkey().to_string();
4242
SatsCardStatus {
43-
proto: card.proto as u64,
43+
proto: card.proto,
4444
ver: card.ver().to_string(),
45-
birth: card.birth as u64,
45+
birth: card.birth,
4646
active_slot: card.slots.0,
4747
num_slots: card.slots.1,
4848
addr: card.addr.clone(),

cktap-ffi/src/sats_chip.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ pub struct SatsChip(pub Mutex<rust_cktap::SatsChip>);
1515

1616
#[derive(uniffi::Record, Debug, Clone)]
1717
pub struct SatsChipStatus {
18-
pub proto: u64,
18+
pub proto: u32,
1919
pub ver: String,
20-
pub birth: u64,
21-
pub path: Option<Vec<u64>>,
20+
pub birth: u32,
21+
pub path: Option<Vec<u32>>,
2222
pub pubkey: String,
2323
pub card_ident: String,
2424
pub auth_delay: Option<u8>,
@@ -29,13 +29,10 @@ impl SatsChip {
2929
pub async fn status(&self) -> SatsChipStatus {
3030
let card = self.0.lock().await;
3131
SatsChipStatus {
32-
proto: card.proto as u64,
32+
proto: card.proto,
3333
ver: card.ver().to_string(),
34-
birth: card.birth as u64,
35-
path: card
36-
.path
37-
.clone()
38-
.map(|p| p.iter().map(|&p| p as u64).collect()),
34+
birth: card.birth,
35+
path: card.path.clone(),
3936
pubkey: card.pubkey().to_string(),
4037
card_ident: card.card_ident(),
4138
auth_delay: card.auth_delay(),

cktap-ffi/src/tap_signer.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ pub struct TapSigner(pub Mutex<rust_cktap::TapSigner>);
1616

1717
#[derive(uniffi::Record, Debug, Clone)]
1818
pub struct TapSignerStatus {
19-
pub proto: u64,
19+
pub proto: u32,
2020
pub ver: String,
21-
pub birth: u64,
22-
pub path: Option<Vec<u64>>,
23-
pub num_backups: u64,
21+
pub birth: u32,
22+
pub path: Option<Vec<u32>>,
23+
pub num_backups: u32,
2424
pub pubkey: String,
2525
pub card_ident: String,
2626
pub auth_delay: Option<u8>,
@@ -31,14 +31,11 @@ impl TapSigner {
3131
pub async fn status(&self) -> TapSignerStatus {
3232
let card = self.0.lock().await;
3333
TapSignerStatus {
34-
proto: card.proto as u64,
34+
proto: card.proto,
3535
ver: card.ver().to_string(),
36-
birth: card.birth as u64,
37-
path: card
38-
.path
39-
.clone()
40-
.map(|p| p.iter().map(|&p| p as u64).collect()),
41-
num_backups: card.num_backups.unwrap_or_default() as u64,
36+
birth: card.birth,
37+
path: card.path.clone(),
38+
num_backups: card.num_backups.unwrap_or_default(),
4239
pubkey: card.pubkey().to_string(),
4340
card_ident: card.card_ident(),
4441
auth_delay: card.auth_delay(),

0 commit comments

Comments
 (0)