refactor(tests): new signature message
style(test): sign_bls_transactions use `dbg!` instead of `println!`
MODIFY
signer/tests/lib_test.rs
signer/tests/lib_test.rs
@@ -3,7 +3,8 @@ use std::convert::TryFrom;
use bip39::{Language, Seed};
use bls_signatures::Serialize;
use forest_address::Address;
-use forest_encoding::to_vec;
+use forest_encoding::{to_vec, Cbor};
+use forest_message::UnsignedMessage;
use rand::SeedableRng;
use rand_chacha::ChaCha8Rng;
use rayon::prelude::*;
@@ -290,7 +291,7 @@ fn sign_bls_transaction() {
let bls_key =
PrivateKey::try_from(test_value["bls_private_key"].as_str().unwrap().to_string()).unwrap();
- println!("{}", bls_address.to_string());
+ dbg!(bls_address.to_string());
// Prepare message with BLS address
let message = UnsignedMessageAPI {
@@ -307,23 +308,25 @@ fn sign_bls_transaction() {
let raw_sig = transaction_sign_raw(&message, &bls_key).unwrap();
- println!("{}", hex::encode(raw_sig.as_bytes()));
+ dbg!(hex::encode(raw_sig.as_bytes()));
let sig = bls_signatures::Signature::from_bytes(&raw_sig.as_bytes()).expect("FIX ME");
let bls_pk = bls_signatures::PublicKey::from_bytes(&bls_pubkey).unwrap();
- let message_cbor = transaction_serialize(&message).expect("FIX ME");
+ let message = UnsignedMessage::try_from(&message).expect("FIX ME");
+ let message_cbor = message.marshal_cbor().expect("FIX ME");
- println!("{}", hex::encode(&message_cbor));
+ dbg!(hex::encode(&message_cbor));
- assert!(bls_pk.verify(sig, &message_cbor));
+ assert!(bls_pk.verify(sig, &message.to_signing_bytes()));
}
#[test]
fn test_verify_bls_signature() {
let test_value = common::load_test_vectors("../test_vectors/bls_signature.json").unwrap();
+ //TODO: update signature (what is the private key?)
let sig = Signature::try_from(test_value["sig"].as_str().unwrap().to_string()).unwrap();
let message =
CborBuffer(hex::decode(test_value["cbor"].as_str().unwrap().to_string()).unwrap());
@@ -437,7 +440,10 @@ fn payment_channel_creation_bls_signing() {
);
// First check transaction_serialize() in creating an unsigned message
- let result = transaction_serialize(&pch_create_message_api).unwrap();
+ let _ = transaction_serialize(&pch_create_message_api).unwrap();
+
+ let unsigned_message = UnsignedMessage::try_from(&pch_create_message_api).unwrap();
+ let bls_signing_bytes = unsigned_message.to_signing_bytes();
// Now check that we can generate a correct signature
let sig = transaction_sign_raw(&pch_create_message_api, &bls_key).unwrap();
@@ -446,7 +452,7 @@ fn payment_channel_creation_bls_signing() {
let bls_sig = bls_signatures::Serialize::from_bytes(&sig.as_bytes()).expect("FIX ME");
- assert!(bls_pkey.verify(bls_sig, &result));
+ assert!(bls_pkey.verify(bls_sig, &bls_signing_bytes));
}
#[test]

MODIFY
test_vectors/bls_signature.json
test_vectors/bls_signature.json
{
- "sig": "a0e8380977d2ccc5dd4d5ebd823406ed22fde880a3bd0fa8426c16b34013c487c51107f5e2808031b680ff200aa16f770a12a82022cc0fd2a7b0302baacee87862fed11be087609d3b0daf90869558574e15b94b375a0f34bce9478e975bb02c",
+ "sig": "a3e507f89527472ad67ddd9bf555e8e745c284944cd855e2ed4b68660a325baacd4dfd93972af2c7e2d39ddc8a5ac37e0660ddc641cb7942ef5a31f3e62e83e006341f6a4b4f9c4cdddb0ba43031b4e9dc96d2b936b9050dccca9e95b8576653",
"cbor": "8a005501fd1d0f4dfcd7e99afcb99a8326b7dc459d32c628583103ade28c91045e89a0dcdb49d5ed0d62a4f02d78a96dbd406a4f9d37a1cd2fb5c29058def79b01b4d1556ade74ffc079040144000186a01961a8430009c4430009c40040"
}

refactor(tests): new signature message

style(test): sign_bls_transactions use `dbg!` instead of `println!`