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 CHANGELOG-npm.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Changelog

## [Unreleased]
- eth: add support for streaming transactions with large data
- eth: add support for streaming transactions and EIP-712 typed data with large data
- eth: add optional `useAntiklepto` argument to `ethSignTypedMessage()` (set to `false` for
deterministic typed-message signatures, firmware >=9.26.0)

Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG-rust.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Changelog

## [Unreleased]
- eth: add support for streaming transactions with large data
- eth: add support for streaming transactions and EIP-712 typed data with large data
- eth: add `use_antiklepto` toggle to `eth_sign_typed_message()` (set `false` for deterministic
typed-message signatures, firmware >=9.26.0)

Expand Down
14 changes: 1 addition & 13 deletions messages/antiklepto.proto
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
// Copyright 2020 Shift Crypto AG
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// SPDX-License-Identifier: Apache-2.0

syntax = "proto3";
package shiftcrypto.bitbox02;
Expand Down
14 changes: 1 addition & 13 deletions messages/backup_commands.proto
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
// Copyright 2019 Shift Cryptosecurity AG
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// SPDX-License-Identifier: Apache-2.0

// This file is named backup_commands to avoid conflicting header files with top-most backup.proto

Expand Down
21 changes: 6 additions & 15 deletions messages/bitbox02_system.proto
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
// Copyright 2019 Shift Cryptosecurity AG
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// SPDX-License-Identifier: Apache-2.0

syntax = "proto3";
package shiftcrypto.bitbox02;
Expand Down Expand Up @@ -39,10 +27,13 @@ message DeviceInfoResponse {
string version = 3;
bool mnemonic_passphrase_enabled = 4;
uint32 monotonic_increments_remaining = 5;
// From v9.6.0: "ATECC608A" or "ATECC608B".
// From v9.6.0: "ATECC608A" or "ATECC608B" or "OPTIGA_TRUST_M_V3".
string securechip_model = 6;
// Only present in Bluetooth-enabled devices.
optional Bluetooth bluetooth = 7;
// From v9.25.0. This together with `securechip_model` determines the password stretching
// algorithm.
string password_stretching_algo = 8;
}

message InsertRemoveSDCardRequest {
Expand All @@ -68,4 +59,4 @@ message SetPasswordRequest {
}

message ChangePasswordRequest{
}
}
14 changes: 1 addition & 13 deletions messages/bluetooth.proto
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
// Copyright 2025 Shift Crypto AG
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// SPDX-License-Identifier: Apache-2.0

syntax = "proto3";
package shiftcrypto.bitbox02;
Expand Down
15 changes: 1 addition & 14 deletions messages/btc.proto
Original file line number Diff line number Diff line change
@@ -1,17 +1,4 @@
// Copyright 2019 Shift Cryptosecurity AG
// Copyright 2020 Shift Crypto AG
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// SPDX-License-Identifier: Apache-2.0

syntax = "proto3";
package shiftcrypto.bitbox02;
Expand Down
14 changes: 1 addition & 13 deletions messages/cardano.proto
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
// Copyright 2021 Shift Crypto AG
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// SPDX-License-Identifier: Apache-2.0

syntax = "proto3";
package shiftcrypto.bitbox02;
Expand Down
14 changes: 1 addition & 13 deletions messages/common.proto
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
// Copyright 2019 Shift Cryptosecurity AG
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// SPDX-License-Identifier: Apache-2.0

syntax = "proto3";
package shiftcrypto.bitbox02;
Expand Down
3 changes: 3 additions & 0 deletions messages/eth.proto
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ message ETHTypedMessageValueResponse {

message ETHTypedMessageValueRequest {
bytes value = 1;
// If non-zero, value should be empty and data will be streamed via
// DataRequestChunk/DataResponseChunk.
uint32 data_length = 2;
}

message ETHRequest {
Expand Down
14 changes: 1 addition & 13 deletions messages/hww.proto
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
// Copyright 2019 Shift Cryptosecurity AG
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// SPDX-License-Identifier: Apache-2.0

syntax = "proto3";
package shiftcrypto.bitbox02;
Expand Down
2 changes: 2 additions & 0 deletions messages/keystore.proto
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: Apache-2.0

// This function can be used to get an identifying xpub at the keypath m/4541509'/1112098098'"
// The keypath argument has to be m/4541509'/1112098098'

Expand Down
14 changes: 1 addition & 13 deletions messages/mnemonic.proto
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
// Copyright 2019 Shift Cryptosecurity AG
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// SPDX-License-Identifier: Apache-2.0

syntax = "proto3";
package shiftcrypto.bitbox02;
Expand Down
1 change: 1 addition & 0 deletions messages/perform_attestation.proto
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// SPDX-License-Identifier: Apache-2.0

syntax = "proto3";
package shiftcrypto.bitbox02;
Expand Down
14 changes: 1 addition & 13 deletions messages/system.proto
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
// Copyright 2019 Shift Cryptosecurity AG
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// SPDX-License-Identifier: Apache-2.0

syntax = "proto3";
package shiftcrypto.bitbox02;
Expand Down
4 changes: 2 additions & 2 deletions scripts/build-protos.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// SPDX-License-Identifier: Apache-2.0

//! ```cargo
//! [dependencies]
//! # If you change this, also change the version of prost in Cargo.toml.
//! prost-build = { version = "0.13" }
//! ```

// SPDX-License-Identifier: Apache-2.0

use std::io::Result;

fn add_serde_attrs(c: &mut prost_build::Config) {
Expand Down
41 changes: 28 additions & 13 deletions src/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ fn encode_value(typ: &MemberType, value: &Value) -> Result<Vec<u8>, String> {
fn get_value(
what: &pb::EthTypedMessageValueResponse,
msg: &Eip712Message,
) -> Result<Vec<u8>, String> {
) -> Result<(Vec<u8>, DataType), String> {
enum Either<'a> {
HashMap(&'a HashMap<String, Value>),
JsonValue(Value),
Expand Down Expand Up @@ -446,8 +446,10 @@ fn get_value(
_ => return Err("path element does not point to struct or array".into()),
}
}
let data_type =
DataType::try_from(typ.r#type).map_err(|_| format!("invalid data type: {}", typ.r#type))?;
if let Either::JsonValue(value) = &value {
encode_value(&typ, value)
encode_value(&typ, value).map(|v| (v, data_type))
} else {
Err("path points to struct or array; value expected".to_string())
}
Expand Down Expand Up @@ -700,12 +702,25 @@ impl<R: Runtime> PairedBitBox<R> {
))
.await?;
while let pb::eth_response::Response::TypedMsgValue(typed_msg_value) = &response {
let value = get_value(typed_msg_value, &msg).map_err(Error::EthTypedMessage)?;
let (value, data_type) =
get_value(typed_msg_value, &msg).map_err(Error::EthTypedMessage)?;
if data_type == DataType::String && value.len() > STREAMING_THRESHOLD {
return Err(Error::EthTypedMessage(
"string value exceeds maximum size".into(),
));
}
let use_streaming = value.len() > STREAMING_THRESHOLD;
response = self
.query_proto_eth(pb::eth_request::Request::TypedMsgValue(
pb::EthTypedMessageValueRequest { value },
pb::EthTypedMessageValueRequest {
value: if use_streaming { vec![] } else { value.clone() },
data_length: if use_streaming { value.len() as u32 } else { 0 },
},
))
.await?;
if use_streaming {
response = self.handle_eth_data_streaming(&value, response).await?;
}
}
let mut signature = if use_antiklepto {
self.handle_antiklepto(&response, host_nonce.unwrap())
Expand Down Expand Up @@ -1224,7 +1239,7 @@ mod tests {
.is_err());

// domain.name
let value = get_value(
let (value, _) = get_value(
&pb::EthTypedMessageValueResponse {
root_object: RootObject::Domain as _,
path: vec![0],
Expand All @@ -1235,7 +1250,7 @@ mod tests {
assert_eq!(value, b"Ether Mail".to_vec());

// domain.version
let value = get_value(
let (value, _) = get_value(
&pb::EthTypedMessageValueResponse {
root_object: RootObject::Domain as _,
path: vec![1],
Expand All @@ -1246,7 +1261,7 @@ mod tests {
assert_eq!(value, b"1".to_vec());

// domain.chainId
let value = get_value(
let (value, _) = get_value(
&pb::EthTypedMessageValueResponse {
root_object: RootObject::Domain as _,
path: vec![2],
Expand All @@ -1257,7 +1272,7 @@ mod tests {
assert_eq!(value, b"\x01".to_vec());

// domain.verifyingContract
let value = get_value(
let (value, _) = get_value(
&pb::EthTypedMessageValueResponse {
root_object: RootObject::Domain as _,
path: vec![3],
Expand All @@ -1282,7 +1297,7 @@ mod tests {
// MESSAGE

// message.from.name
let value = get_value(
let (value, _) = get_value(
&pb::EthTypedMessageValueResponse {
root_object: RootObject::Message as _,
path: vec![0, 0],
Expand All @@ -1293,7 +1308,7 @@ mod tests {
assert_eq!(value, b"Cow".to_vec());

// message.from.wallet
let value = get_value(
let (value, _) = get_value(
&pb::EthTypedMessageValueResponse {
root_object: RootObject::Message as _,
path: vec![0, 1],
Expand All @@ -1307,7 +1322,7 @@ mod tests {
);

// message.to.wallet
let value = get_value(
let (value, _) = get_value(
&pb::EthTypedMessageValueResponse {
root_object: RootObject::Message as _,
path: vec![1, 1],
Expand All @@ -1321,7 +1336,7 @@ mod tests {
);

// message.attachments.0.contents
let value = get_value(
let (value, _) = get_value(
&pb::EthTypedMessageValueResponse {
root_object: RootObject::Message as _,
path: vec![3, 0, 0],
Expand All @@ -1332,7 +1347,7 @@ mod tests {
assert_eq!(value, b"attachment1".to_vec());

// message.attachments.1.contents
let value = get_value(
let (value, _) = get_value(
&pb::EthTypedMessageValueResponse {
root_object: RootObject::Message as _,
path: vec![3, 1, 0],
Expand Down
4 changes: 4 additions & 0 deletions src/shiftcrypto.bitbox02.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1973,6 +1973,10 @@ pub mod eth_typed_message_value_response {
pub struct EthTypedMessageValueRequest {
#[prost(bytes = "vec", tag = "1")]
pub value: ::prost::alloc::vec::Vec<u8>,
/// If non-zero, value should be empty and data will be streamed via
/// DataRequestChunk/DataResponseChunk.
#[prost(uint32, tag = "2")]
pub data_length: u32,
}
#[cfg_attr(feature = "wasm", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "wasm", serde(rename_all = "camelCase"))]
Expand Down
Loading
Loading