only sign the hashed_essence
@@ -7,7 +7,12 @@ use bee_common::packable::Packable;
use bee_message::prelude::*;
use bee_pow::providers::ProviderBuilder;
use bee_rest_api::types::{AddressDto, OutputDto};
+use blake2::{
+ digest::{Update, VariableOutput},
+ VarBlake2b,
+};
use slip10::BIP32Path;
+
use std::{
collections::{HashMap, HashSet},
ops::Range,
@@ -426,6 +431,13 @@ impl<'a> ClientMessageBuilder<'a> {
.pack(&mut serialized_essence)
.map_err(|_| Error::InvalidParameter("inputs".to_string()))?;
+ let mut hasher = VarBlake2b::new(32).unwrap();
+ hasher.update(serialized_essence);
+ let mut hashed_essence: [u8; 32] = [0; 32];
+ hasher.finalize_variable(|res| {
+ hashed_essence[..32].clone_from_slice(&res[..32]);
+ });
+
let mut unlock_blocks = Vec::new();
let mut signature_indexes = HashMap::<String, usize>::new();
address_index_recorders.sort_by(|a, b| a.input.cmp(&b.input));
@@ -446,7 +458,7 @@ impl<'a> ClientMessageBuilder<'a> {
.generate_private_key(&recorder.address_path)?;
let public_key = private_key.public_key().to_compressed_bytes();
// The block should sign the entire transaction essence part of the transaction payload
- let signature = Box::new(private_key.sign(&serialized_essence).to_bytes());
+ let signature = Box::new(private_key.sign(&hashed_essence).to_bytes());
unlock_blocks.push(UnlockBlock::Signature(SignatureUnlock::Ed25519(Ed25519Signature::new(
public_key, signature,
))));
