Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add grpc commitment signature proto type #5200

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
8 changes: 8 additions & 0 deletions applications/tari_app_grpc/proto/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ message ComAndPubSignature {
bytes u_y = 5;
}

// Define the explicit CommitmentSignature implementation for the Tari base layer. A different signature scheme can be
// employed by redefining this type
message CommitmentSignature {
bytes public_nonce = 1;
bytes u = 2;
bytes v = 3;
}

/// PoW Algorithm constants
message PowAlgorithmConstants {
uint64 max_target_time = 1;
Expand Down
2 changes: 1 addition & 1 deletion applications/tari_app_grpc/proto/wallet.proto
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ message CreateBurnTransactionResponse{
bool is_success = 2;
string failure_message = 3;
bytes commitment = 4;
bytes ownership_proof = 5;
CommitmentSignature ownership_proof = 5;
bytes rangeproof = 6;
}

Expand Down
52 changes: 52 additions & 0 deletions applications/tari_app_grpc/src/conversions/commitment_signature.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright 2020. The Tari Project
//
// Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
// following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following
// disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
// following disclaimer in the documentation and/or other materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote
// products derived from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

use std::convert::TryFrom;

use tari_common_types::types::{PrivateKey, PublicKey};
use tari_crypto::{commitment::HomomorphicCommitment, signatures::CommitmentSignature};
use tari_utilities::ByteArray;

use crate::tari_rpc as grpc;

impl TryFrom<grpc::CommitmentSignature> for CommitmentSignature<PublicKey, PrivateKey> {
type Error = String;

fn try_from(sig: grpc::CommitmentSignature) -> Result<Self, Self::Error> {
let public_nonce = HomomorphicCommitment::<PublicKey>::from_bytes(&sig.public_nonce)
.map_err(|_| "Could not get public nonce".to_string())?;
let u = PrivateKey::from_bytes(&sig.u).map_err(|_| "Could not get u_x".to_string())?;
let v = PrivateKey::from_bytes(&sig.v).map_err(|_| "Could not get v_x".to_string())?;

Ok(Self::new(public_nonce, u, v))
}
}

impl From<CommitmentSignature<PublicKey, PrivateKey>> for grpc::CommitmentSignature {
fn from(sig: CommitmentSignature<PublicKey, PrivateKey>) -> Self {
Self {
public_nonce: sig.public_nonce().to_vec(),
u: sig.u().to_vec(),
v: sig.v().to_vec(),
}
}
}
1 change: 1 addition & 0 deletions applications/tari_app_grpc/src/conversions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ mod block;
mod block_header;
mod chain_metadata;
mod com_and_pub_signature;
mod commitment_signature;
mod consensus_constants;
mod historical_block;
mod new_block_template;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ use tari_app_grpc::{
ClaimShaAtomicSwapResponse,
CoinSplitRequest,
CoinSplitResponse,
CommitmentSignature,
CreateBurnTransactionRequest,
CreateBurnTransactionResponse,
CreateTemplateRegistrationRequest,
Expand Down Expand Up @@ -617,7 +618,7 @@ impl wallet_server::Wallet for WalletGrpcServer {
is_success: true,
failure_message: Default::default(),
commitment: commitment.to_vec(),
ownership_proof: ownership_proof.map(|o| o.to_vec()).unwrap_or_default(),
ownership_proof: ownership_proof.map(CommitmentSignature::from),
rangeproof: rangeproof.to_vec(),
}
},
Expand Down