Skip to content

Commit

Permalink
feat: add sender signature to txn output (#3020)
Browse files Browse the repository at this point in the history
  • Loading branch information
stringhandler committed Jun 22, 2021
2 parents 4b4af99 + f3d3c3a commit 7901b3c
Show file tree
Hide file tree
Showing 47 changed files with 9,316 additions and 4,967 deletions.
12 changes: 12 additions & 0 deletions applications/tari_app_grpc/proto/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ message TransactionOutput {
bytes script = 5;
// Tari script offset pubkey, K_O
bytes script_offset_public_key = 6;
// UTXO signature with the script offset private key, k_O
Signature sender_metadata_signature = 7;
}

// Options for UTXO's
Expand Down Expand Up @@ -296,12 +298,22 @@ message Peer{
}

message UnblindedOutput {
// Value of the output
uint64 value = 1;
// Spending key of the output
bytes spending_key = 2;
// Options for an output's structure or use
OutputFeatures features = 3;
// Tari script serialised script
bytes script = 4;
// Tari script input data for spending
bytes input_data = 5;
// The block height that the UTXO was mined
uint64 height = 6;
// Tari script private key
bytes script_private_key = 7;
// Tari script offset pubkey, K_O
bytes script_offset_public_key = 8;
// UTXO signature with the script offset private key, k_O
Signature sender_metadata_signature = 9;
}
14 changes: 14 additions & 0 deletions applications/tari_app_grpc/src/blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ impl From<tari_core::blocks::Block> for grpc::Block {
}),
commitment: Vec::from(output.commitment.as_bytes()),
range_proof: Vec::from(output.proof.as_bytes()),
hash: Vec::from(output.hash.as_bytes()),
script: Vec::from(output.script.as_bytes()),
script_offset_public_key: Vec::from(output.script_offset_public_key.as_bytes()),
sender_metadata_signature: Some(grpc::Signature {
public_nonce: Vec::from(output.sender_metadata_signature.get_public_nonce().as_bytes()),
signature: Vec::from(output.sender_metadata_signature.get_signature().as_bytes()),
}),
})
.collect(),
kernels: block
Expand Down Expand Up @@ -175,6 +182,13 @@ impl From<NewBlockTemplate> for grpc::NewBlockTemplate {
}),
commitment: Vec::from(output.commitment.as_bytes()),
range_proof: Vec::from(output.proof.as_bytes()),
hash: Vec::from(output.hash.as_bytes()),
script: Vec::from(output.script.as_bytes()),
script_offset_public_key: Vec::from(output.script_offset_public_key.as_bytes()),
sender_metadata_signature: Some(grpc::Signature {
public_nonce: Vec::from(output.sender_metadata_signature.get_public_nonce().as_bytes()),
signature: Vec::from(output.sender_metadata_signature.get_signature().as_bytes()),
}),
})
.collect(),
kernels: block
Expand Down
15 changes: 13 additions & 2 deletions applications/tari_app_grpc/src/conversions/transaction_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,29 @@ impl TryFrom<grpc::TransactionOutput> for TransactionOutput {
let features = output
.features
.map(TryInto::try_into)
.ok_or_else(|| "transaction output features not provided".to_string())??;
.ok_or_else(|| "Transaction output features not provided".to_string())??;

let commitment = Commitment::from_bytes(&output.commitment)
.map_err(|err| format!("Invalid output commitment: {}", err.to_string()))?;
let script_offset_public_key = PublicKey::from_bytes(output.script_offset_public_key.as_bytes())
.map_err(|err| format!("script_offset_public_key {:?}", err))?;
.map_err(|err| format!("Invalid script_offset_public_key {:?}", err))?;

let script = TariScript::from_bytes(output.script.as_slice())
.map_err(|err| format!("Script deserialization: {:?}", err))?;

let sender_metadata_signature = output
.sender_metadata_signature
.ok_or_else(|| "Sender signature not provided".to_string())?
.try_into()
.map_err(|_| "Sender signature could not be converted".to_string())?;

Ok(Self {
features,
commitment,
proof: BulletRangeProof(output.range_proof),
script,
script_offset_public_key,
sender_metadata_signature,
})
}
}
Expand All @@ -72,6 +79,10 @@ impl From<TransactionOutput> for grpc::TransactionOutput {
range_proof: Vec::from(output.proof.as_bytes()),
script: output.script.as_bytes(),
script_offset_public_key: output.script_offset_public_key.as_bytes().to_vec(),
sender_metadata_signature: Some(grpc::Signature {
public_nonce: Vec::from(output.sender_metadata_signature.get_public_nonce().as_bytes()),
signature: Vec::from(output.sender_metadata_signature.get_signature().as_bytes()),
}),
}
}
}
11 changes: 11 additions & 0 deletions applications/tari_app_grpc/src/conversions/unblinded_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ impl From<UnblindedOutput> for grpc::UnblindedOutput {
height: output.height,
script_private_key: output.script_private_key.as_bytes().to_vec(),
script_offset_public_key: output.script_offset_public_key.as_bytes().to_vec(),
sender_metadata_signature: Some(grpc::Signature {
public_nonce: Vec::from(output.sender_metadata_signature.get_public_nonce().as_bytes()),
signature: Vec::from(output.sender_metadata_signature.get_signature().as_bytes()),
}),
}
}
}
Expand Down Expand Up @@ -73,6 +77,12 @@ impl TryFrom<grpc::UnblindedOutput> for UnblindedOutput {
let script_offset_public_key = PublicKey::from_bytes(output.script_offset_public_key.as_bytes())
.map_err(|err| format!("script_offset_public_key {:?}", err))?;

let sender_metadata_signature = output
.sender_metadata_signature
.ok_or_else(|| "Sender signature not provided".to_string())?
.try_into()
.map_err(|_| "Sender signature could not be converted".to_string())?;

Ok(Self {
value: MicroTari::from(output.value),
spending_key,
Expand All @@ -82,6 +92,7 @@ impl TryFrom<grpc::UnblindedOutput> for UnblindedOutput {
height: output.height,
script_private_key,
script_offset_public_key,
sender_metadata_signature,
})
}
}
6 changes: 4 additions & 2 deletions applications/tari_console_wallet/src/automation/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -645,13 +645,13 @@ fn write_utxos_to_csv_file(utxos: Vec<UnblindedOutput>, file_path: String) -> Re
let mut csv_file = LineWriter::new(file);
writeln!(
csv_file,
r##""index","value","spending_key","commitment","flags","maturity","script","input_data","height","script_private_key","script_offset_public_key""##
r##""index","value","spending_key","commitment","flags","maturity","script","input_data","height","script_private_key","script_offset_public_key","signature","public_nonce""##
)
.map_err(|e| CommandError::CSVFile(e.to_string()))?;
for (i, utxo) in utxos.iter().enumerate() {
writeln!(
csv_file,
r##""{}","{}","{}","{}","{:?}","{}","{}","{}","{}","{}","{}""##,
r##""{}","{}","{}","{}","{:?}","{}","{}","{}","{}","{}","{}","{}","{}""##,
i + 1,
utxo.value.0,
utxo.spending_key.to_hex(),
Expand All @@ -663,6 +663,8 @@ fn write_utxos_to_csv_file(utxos: Vec<UnblindedOutput>, file_path: String) -> Re
utxo.height,
utxo.script_private_key.to_hex(),
utxo.script_offset_public_key.to_hex(),
utxo.sender_metadata_signature.get_signature().to_hex(),
utxo.sender_metadata_signature.get_public_nonce().to_hex(),
)
.map_err(|e| CommandError::CSVFile(e.to_string()))?;
}
Expand Down
Loading

0 comments on commit 7901b3c

Please sign in to comment.