Skip to content

Commit

Permalink
Merge branch 'proto'
Browse files Browse the repository at this point in the history
  • Loading branch information
benma committed Sep 18, 2024
2 parents 77c967c + 05b3cb5 commit 1efd120
Show file tree
Hide file tree
Showing 9 changed files with 254 additions and 15 deletions.
26 changes: 14 additions & 12 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,17 @@ jobs:
make wasm
make build-sandbox
Check-Protobufs:
name: Check that the generated protobuf file is up to date
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@stable
- run: |
sudo apt-get update
sudo apt-get install -y protobuf-compiler
cargo install rust-script
make build-protos
git diff --quiet
# Temporarily disabled; re-enable when we find a way to use the same protobuf compiler version
# in the developer docs and here, otherwise this check will often fail.
# Check-Protobufs:
# name: Check that the generated protobuf file is up to date
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v3
# - uses: dtolnay/rust-toolchain@stable
# - run: |
# sudo apt-get update
# sudo apt-get install -y protobuf-compiler
# cargo install rust-script
# make build-protos
# git diff --quiet
33 changes: 33 additions & 0 deletions messages/btc.proto
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ enum BTCCoin {
TBTC = 1;
LTC = 2;
TLTC = 3;
// Regtest
RBTC = 4;
};


Expand Down Expand Up @@ -112,6 +114,7 @@ message BTCSignInitRequest {
SAT = 1;
}
FormatUnit format_unit = 8;
bool contains_silent_payment_outputs = 9;
}

message BTCSignNextResponse {
Expand All @@ -124,6 +127,7 @@ message BTCSignNextResponse {
PREVTX_INPUT = 4;
PREVTX_OUTPUT = 5;
HOST_NONCE = 6;
PAYMENT_REQUEST = 7;
}
Type type = 1;
// index of the current input or output
Expand All @@ -134,6 +138,9 @@ message BTCSignNextResponse {
// Previous tx's input/output index in case of PREV_INPUT or PREV_OUTPUT, for the input at `index`.
uint32 prev_index = 5;
AntiKleptoSignerCommitment anti_klepto_signer_commitment = 6;
// Generated output. The host *must* verify its correctness using `silent_payment_dleq_proof`.
bytes generated_output_pkscript = 7;
bytes silent_payment_dleq_proof = 8;
}

message BTCSignInputRequest {
Expand All @@ -157,6 +164,10 @@ enum BTCOutputType {
}

message BTCSignOutputRequest {
// https://github.com/bitcoin/bips/blob/master/bip-0352.mediawiki
message SilentPayment {
string address = 1;
}
bool ours = 1;
BTCOutputType type = 2; // if ours is false
// 20 bytes for p2pkh, p2sh, pw2wpkh. 32 bytes for p2wsh.
Expand All @@ -165,6 +176,10 @@ message BTCSignOutputRequest {
repeated uint32 keypath = 5; // if ours is true
// If ours is true. References a script config from BTCSignInitRequest
uint32 script_config_index = 6;
optional uint32 payment_request_index = 7;
// If provided, `type` and `payload` is ignored. The generated output pkScript is returned in
// BTCSignNextResponse. `contains_silent_payment_outputs` in the init request must be true.
SilentPayment silent_payment = 8;
}

message BTCScriptConfigRegistration {
Expand Down Expand Up @@ -217,6 +232,23 @@ message BTCPrevTxOutputRequest {
bytes pubkey_script = 2;
}

message BTCPaymentRequestRequest {
message Memo {
message TextMemo {
string note = 1;
}
oneof memo {
TextMemo text_memo = 1;
}
}

string recipient_name = 1;
repeated Memo memos = 2;
bytes nonce = 3;
uint64 total_amount = 4;
bytes signature = 5;
}

message BTCSignMessageRequest {
BTCCoin coin = 1;
BTCScriptConfigWithKeypath script_config = 2;
Expand All @@ -238,6 +270,7 @@ message BTCRequest {
BTCPrevTxOutputRequest prevtx_output = 5;
BTCSignMessageRequest sign_message = 6;
AntiKleptoSignatureRequest antiklepto_signature = 7;
BTCPaymentRequestRequest payment_request = 8;
}
}

Expand Down
8 changes: 8 additions & 0 deletions messages/eth.proto
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ enum ETHCoin {
RinkebyETH = 2;
}

enum ETHAddressCase {
ETH_ADDRESS_CASE_MIXED = 0;
ETH_ADDRESS_CASE_UPPER = 1;
ETH_ADDRESS_CASE_LOWER = 2;
}

message ETHPubRequest {
repeated uint32 keypath = 1;
// Deprecated: use chain_id instead.
Expand Down Expand Up @@ -56,6 +62,7 @@ message ETHSignRequest {
AntiKleptoHostNonceCommitment host_nonce_commitment = 9;
// If non-zero, `coin` is ignored and `chain_id` is used to identify the network.
uint64 chain_id = 10;
ETHAddressCase address_case = 11;
}

// TX payload for an EIP-1559 (type 2) transaction: https://eips.ethereum.org/EIPS/eip-1559
Expand All @@ -70,6 +77,7 @@ message ETHSignEIP1559Request {
bytes value = 8; // smallest big endian serialization, max. 32 bytes
bytes data = 9;
AntiKleptoHostNonceCommitment host_nonce_commitment = 10;
ETHAddressCase address_case = 11;
}

message ETHSignMessageRequest {
Expand Down
2 changes: 2 additions & 0 deletions messages/hww.proto
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ message Request {
BTCRequest btc = 25;
ElectrumEncryptionKeyRequest electrum_encryption_key = 26;
CardanoRequest cardano = 27;
BIP85Request bip85 = 28;
}
}

Expand All @@ -87,5 +88,6 @@ message Response {
BTCResponse btc = 13;
ElectrumEncryptionKeyResponse electrum_encryption_key = 14;
CardanoResponse cardano = 15;
BIP85Response bip85 = 16;
}
}
20 changes: 20 additions & 0 deletions messages/keystore.proto
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,30 @@
syntax = "proto3";
package shiftcrypto.bitbox02;

import "google/protobuf/empty.proto";

message ElectrumEncryptionKeyRequest {
repeated uint32 keypath = 1;
}

message ElectrumEncryptionKeyResponse {
string key = 1;
}

message BIP85Request {
message AppLn {
uint32 account_number = 1;
}

oneof app {
google.protobuf.Empty bip39 = 1;
AppLn ln = 2;
}
}

message BIP85Response {
oneof app {
google.protobuf.Empty bip39 = 1;
bytes ln = 2;
}
}
2 changes: 2 additions & 0 deletions src/btc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,7 @@ impl<R: Runtime> PairedBitBox<R> {
num_outputs: transaction.outputs.len() as _,
locktime: transaction.locktime,
format_unit: format_unit as _,
contains_silent_payment_outputs: false,
}))
.await?;

Expand Down Expand Up @@ -846,6 +847,7 @@ impl<R: Runtime> PairedBitBox<R> {
pb::btc_sign_next_response::Type::HostNonce => {
return Err(Error::UnexpectedResponse);
}
_ => return Err(Error::UnexpectedResponse),
}
}
Ok(sigs)
Expand Down
2 changes: 2 additions & 0 deletions src/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,7 @@ impl<R: Runtime> PairedBitBox<R> {
commitment: crate::antiklepto::host_commit(&host_nonce).to_vec(),
}),
chain_id,
address_case: pb::EthAddressCase::Mixed as _,
});
let response = self.query_proto_eth(request).await?;
self.handle_antiklepto(&response, host_nonce).await
Expand Down Expand Up @@ -515,6 +516,7 @@ impl<R: Runtime> PairedBitBox<R> {
host_nonce_commitment: Some(pb::AntiKleptoHostNonceCommitment {
commitment: crate::antiklepto::host_commit(&host_nonce).to_vec(),
}),
address_case: pb::EthAddressCase::Mixed as _,
});
let response = self.query_proto_eth(request).await?;
self.handle_antiklepto(&response, host_nonce).await
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ mod u2fframing;
mod util;

/// BitBox protobuf messages.
#[allow(clippy::all)]
pub mod pb {
include!("./shiftcrypto.bitbox02.rs");
}
Expand Down
Loading

0 comments on commit 1efd120

Please sign in to comment.