Skip to content

Commit e4dbcbb

Browse files
committed
Merge branch 'fixproto'
2 parents f8d1b72 + 3448c9d commit e4dbcbb

File tree

9 files changed

+940
-342
lines changed

9 files changed

+940
-342
lines changed

messages/eth.proto

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,12 @@ package shiftcrypto.bitbox02;
1818
import "common.proto";
1919
import "antiklepto.proto";
2020

21+
// Kept for backwards compatibility. Use chain_id instead, introduced in v9.10.0.
2122
enum ETHCoin {
2223
ETH = 0;
24+
// Removed in v9.14.0 - deprecated
2325
RopstenETH = 1;
26+
// Removed in v9.14.0 - deprecated
2427
RinkebyETH = 2;
2528
}
2629

py/bitbox02/bitbox02/communication/generated/btc_pb2.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ class BTCSignInitRequest(google.protobuf.message.Message):
243243
class _FormatUnitEnumTypeWrapper(google.protobuf.internal.enum_type_wrapper._EnumTypeWrapper[BTCSignInitRequest._FormatUnit.ValueType], builtins.type):
244244
DESCRIPTOR: google.protobuf.descriptor.EnumDescriptor
245245
DEFAULT: BTCSignInitRequest._FormatUnit.ValueType # 0
246-
"""According to BTCCoin (BTC, LTC, etc.)."""
246+
"""According to `coin` (BTC, LTC, etc.)."""
247247

248248
SAT: BTCSignInitRequest._FormatUnit.ValueType # 1
249249
"""Only valid for BTC/TBTC, formats as "sat"/"tsat"."""
@@ -252,7 +252,7 @@ class BTCSignInitRequest(google.protobuf.message.Message):
252252
pass
253253

254254
DEFAULT: BTCSignInitRequest.FormatUnit.ValueType # 0
255-
"""According to BTCCoin (BTC, LTC, etc.)."""
255+
"""According to `coin` (BTC, LTC, etc.)."""
256256

257257
SAT: BTCSignInitRequest.FormatUnit.ValueType # 1
258258
"""Only valid for BTC/TBTC, formats as "sat"/"tsat"."""

py/bitbox02/bitbox02/communication/generated/eth_pb2.pyi

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,22 @@ class _ETHCoinEnumTypeWrapper(google.protobuf.internal.enum_type_wrapper._EnumTy
2121
DESCRIPTOR: google.protobuf.descriptor.EnumDescriptor
2222
ETH: _ETHCoin.ValueType # 0
2323
RopstenETH: _ETHCoin.ValueType # 1
24+
"""Removed in v9.14.0 - deprecated"""
25+
2426
RinkebyETH: _ETHCoin.ValueType # 2
27+
"""Removed in v9.14.0 - deprecated"""
28+
2529
class ETHCoin(_ETHCoin, metaclass=_ETHCoinEnumTypeWrapper):
30+
"""Kept for backwards compatibility. Use chain_id instead, introduced in v9.10.0."""
2631
pass
2732

2833
ETH: ETHCoin.ValueType # 0
2934
RopstenETH: ETHCoin.ValueType # 1
35+
"""Removed in v9.14.0 - deprecated"""
36+
3037
RinkebyETH: ETHCoin.ValueType # 2
38+
"""Removed in v9.14.0 - deprecated"""
39+
3140
global___ETHCoin = ETHCoin
3241

3342

src/rust/bitbox02-rust/src/hww/api/ethereum/params.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const PARAMS: &[Params] = &[
4343
unit: "ETH",
4444
},
4545
Params {
46-
coin: Some(EthCoin::GoerliEth),
46+
coin: None,
4747
bip44_coin: 1 + HARDENED,
4848
chain_id: 5,
4949
name: "Goerli",
@@ -144,7 +144,6 @@ mod tests {
144144
pub fn test_get() {
145145
assert_eq!(get(EthCoin::Eth, 0).unwrap().name, "Ethereum");
146146
assert_eq!(get(EthCoin::Eth, 1).unwrap().name, "Ethereum");
147-
assert_eq!(get(EthCoin::GoerliEth, 0).unwrap().name, "Goerli");
148147
assert_eq!(get(EthCoin::Eth, 5).unwrap().name, "Goerli");
149148
assert_eq!(get(EthCoin::Eth, 56).unwrap().name, "Binance Smart Chain");
150149

src/rust/bitbox02-rust/src/hww/api/ethereum/pubrequest.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,10 +231,10 @@ mod tests {
231231
block_on(process(&pb::EthPubRequest {
232232
output_type: OutputType::Address as _,
233233
keypath: [44 + HARDENED, 60 + HARDENED, 0 + HARDENED, 0, 0].to_vec(),
234-
coin: pb::EthCoin::GoerliEth as _,
234+
coin: pb::EthCoin::Eth as _,
235235
display: true,
236236
contract_address: b"".to_vec(),
237-
chain_id: 0,
237+
chain_id: 5,
238238
})),
239239
Ok(Response::Pub(pb::PubResponse {
240240
r#pub: ADDRESS.into()

src/rust/bitbox02-rust/src/hww/api/ethereum/sign.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ mod tests {
472472
mock_unlocked();
473473

474474
block_on(process(&pb::EthSignRequest {
475-
coin: pb::EthCoin::GoerliEth as _,
475+
coin: pb::EthCoin::Eth as _,
476476
keypath: KEYPATH.to_vec(),
477477
nonce: b"\x1f\xdc".to_vec(),
478478
gas_price: b"\x01\x65\xa0\xbc\x00".to_vec(),
@@ -483,7 +483,7 @@ mod tests {
483483
value: b"\x07\x5c\xf1\x25\x9e\x9c\x40\x00".to_vec(),
484484
data: b"".to_vec(),
485485
host_nonce_commitment: None,
486-
chain_id: 0,
486+
chain_id: 5,
487487
}))
488488
.unwrap();
489489
assert_eq!(unsafe { CONFIRM_COUNTER }, 1);
@@ -567,7 +567,7 @@ mod tests {
567567
mock_unlocked();
568568
assert_eq!(
569569
block_on(process(&pb::EthSignRequest {
570-
coin: pb::EthCoin::GoerliEth as _, // ignored because chain_id > 0
570+
coin: pb::EthCoin::RopstenEth as _, // ignored because chain_id > 0
571571
keypath: KEYPATH.to_vec(),
572572
nonce: b"\x23\x67".to_vec(),
573573
gas_price: b"\x02\x7a\xca\x1a\x80".to_vec(),

src/rust/bitbox02-rust/src/hww/api/ethereum/signmsg.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,11 @@ mod tests {
178178
});
179179
mock_unlocked();
180180
block_on(process(&pb::EthSignMessageRequest {
181-
coin: pb::EthCoin::GoerliEth as _,
181+
coin: pb::EthCoin::Eth as _,
182182
keypath: KEYPATH.to_vec(),
183183
msg: MESSAGE.to_vec(),
184184
host_nonce_commitment: None,
185-
chain_id: 0,
185+
chain_id: 5,
186186
}))
187187
.unwrap();
188188
assert_eq!(unsafe { CONFIRM_COUNTER }, 3);
Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,36 @@
1+
#[allow(clippy::derive_partial_eq_without_eq)]
12
#[derive(Clone, PartialEq, ::prost::Message)]
23
pub struct BackupMetaData {
3-
#[prost(uint32, tag="1")]
4+
#[prost(uint32, tag = "1")]
45
pub timestamp: u32,
5-
#[prost(string, tag="2")]
6+
#[prost(string, tag = "2")]
67
pub name: ::prost::alloc::string::String,
7-
#[prost(enumeration="BackupMode", tag="3")]
8+
#[prost(enumeration = "BackupMode", tag = "3")]
89
pub mode: i32,
910
}
10-
///*
11+
/// *
1112
/// BackupData is encoded in the data field of the BackupContent
1213
/// and depends on the BackupMode.
1314
/// Defining it as a protobuf message allows language/architecture independent
1415
/// encoding/decoding.
16+
#[allow(clippy::derive_partial_eq_without_eq)]
1517
#[derive(Clone, PartialEq, ::prost::Message)]
1618
pub struct BackupData {
17-
#[prost(uint32, tag="1")]
19+
#[prost(uint32, tag = "1")]
1820
pub seed_length: u32,
19-
#[prost(bytes="vec", tag="2")]
21+
#[prost(bytes = "vec", tag = "2")]
2022
pub seed: ::prost::alloc::vec::Vec<u8>,
21-
#[prost(uint32, tag="3")]
23+
#[prost(uint32, tag = "3")]
2224
pub birthdate: u32,
23-
#[prost(string, tag="4")]
25+
#[prost(string, tag = "4")]
2426
pub generator: ::prost::alloc::string::String,
2527
}
28+
#[allow(clippy::derive_partial_eq_without_eq)]
2629
#[derive(Clone, PartialEq, ::prost::Message)]
2730
pub struct BackupContent {
28-
#[prost(bytes="vec", tag="1")]
31+
#[prost(bytes = "vec", tag = "1")]
2932
pub checksum: ::prost::alloc::vec::Vec<u8>,
30-
#[prost(message, optional, tag="2")]
33+
#[prost(message, optional, tag = "2")]
3134
pub metadata: ::core::option::Option<BackupMetaData>,
3235
/// This field is obsolete and from v9.13.0, it is set to 0.
3336
///
@@ -39,35 +42,30 @@ pub struct BackupContent {
3942
/// Since this field is part of the checksum computation, we keep it so that existing backups can
4043
/// be loaded and the checksum verified. Other than that, it serves no purpose, as it is not
4144
/// needed to deserialize or interpret the data.
42-
#[prost(uint32, tag="3")]
45+
#[prost(uint32, tag = "3")]
4346
pub length: u32,
44-
#[prost(bytes="vec", tag="4")]
47+
#[prost(bytes = "vec", tag = "4")]
4548
pub data: ::prost::alloc::vec::Vec<u8>,
4649
}
47-
// NOTE! Once the firmware is released to the general public and there are actual backups it is
48-
// strictly forbidden to modify BackupV1 and any types contained within BackupV1 because the
49-
// checksum covers all fields.
50-
50+
#[allow(clippy::derive_partial_eq_without_eq)]
5151
#[derive(Clone, PartialEq, ::prost::Message)]
5252
pub struct BackupV1 {
53-
#[prost(message, optional, tag="1")]
53+
#[prost(message, optional, tag = "1")]
5454
pub content: ::core::option::Option<BackupContent>,
5555
}
56-
//message Backup_V2 {
57-
//RSBackupContent rs_content = 1;
58-
//}
59-
56+
#[allow(clippy::derive_partial_eq_without_eq)]
6057
#[derive(Clone, PartialEq, ::prost::Message)]
6158
pub struct Backup {
62-
#[prost(oneof="backup::BackupVersion", tags="1")]
59+
#[prost(oneof = "backup::BackupVersion", tags = "1")]
6360
pub backup_version: ::core::option::Option<backup::BackupVersion>,
6461
}
6562
/// Nested message and enum types in `Backup`.
6663
pub mod backup {
64+
#[allow(clippy::derive_partial_eq_without_eq)]
6765
#[derive(Clone, PartialEq, ::prost::Oneof)]
6866
pub enum BackupVersion {
69-
/// Backup_V2 backup_V2 = 2;
70-
#[prost(message, tag="1")]
67+
/// Backup_V2 backup_V2 = 2;
68+
#[prost(message, tag = "1")]
7169
BackupV1(super::BackupV1),
7270
}
7371
}
@@ -76,3 +74,21 @@ pub mod backup {
7674
pub enum BackupMode {
7775
Plaintext = 0,
7876
}
77+
impl BackupMode {
78+
/// String value of the enum field names used in the ProtoBuf definition.
79+
///
80+
/// The values are not transformed in any way and thus are considered stable
81+
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
82+
pub fn as_str_name(&self) -> &'static str {
83+
match self {
84+
BackupMode::Plaintext => "PLAINTEXT",
85+
}
86+
}
87+
/// Creates an enum from field names used in the ProtoBuf definition.
88+
pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
89+
match value {
90+
"PLAINTEXT" => Some(Self::Plaintext),
91+
_ => None,
92+
}
93+
}
94+
}

0 commit comments

Comments
 (0)