Skip to content

Commit

Permalink
fix: create message to sign from transaction id bytes (FuelLabs#3201)
Browse files Browse the repository at this point in the history
  • Loading branch information
kayagokalp authored Nov 4, 2022
1 parent 76b1ee9 commit 32a9a3c
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions forc-plugins/forc-client/src/ops/tx_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ fn prompt_address() -> Result<Bech32Address> {
Bech32Address::from_str(buf.trim()).map_err(Error::msg)
}

fn prompt_signature(message: Message) -> Result<Signature> {
println!("Message to sign: {}", message);
print!("Please provide the signed message:");
fn prompt_signature(tx_id: fuel_tx::Bytes32) -> Result<Signature> {
println!("Transaction id to sign: {}", tx_id);
print!("Please provide the signature:");
std::io::stdout().flush()?;
let mut buf = String::new();
std::io::stdin().read_line(&mut buf)?;
Expand Down Expand Up @@ -163,11 +163,16 @@ impl<Tx: Buildable + SerializableVec + field::Witnesses + Send> TransactionBuild
let mut tx = self._finalize_without_signature();

if !unsigned {
let message = Message::new(tx.to_bytes());
let signature = if let Some(signing_key) = signing_key {
// Safety: `Message::from_bytes_unchecked` is unsafe because
// it can't guarantee that the provided bytes will be the product
// of a cryptographically secure hash. However, the bytes are
// coming from `tx.id()`, which already uses `Hasher::hash()`
// to hash it using a secure hash mechanism.
let message = unsafe { Message::from_bytes_unchecked(*tx.id()) };
Signature::sign(&signing_key, &message)
} else {
prompt_signature(message)?
prompt_signature(tx.id())?
};

let witness = Witness::from(signature.as_ref());
Expand Down

0 comments on commit 32a9a3c

Please sign in to comment.