From 2d50f54af60f53c25bbd4454066ce1c997300479 Mon Sep 17 00:00:00 2001 From: parodyBit <58690522+parodyBit@users.noreply.github.com> Date: Thu, 2 Jan 2025 10:28:18 -0700 Subject: [PATCH] Include validator pkh in authorization --- node/src/actors/json_rpc/api.rs | 9 ++++++--- src/cli/node/json_rpc_client.rs | 21 +++++++++++++++++++-- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/node/src/actors/json_rpc/api.rs b/node/src/actors/json_rpc/api.rs index a3ba3a632..3dbc23e8a 100644 --- a/node/src/actors/json_rpc/api.rs +++ b/node/src/actors/json_rpc/api.rs @@ -2046,9 +2046,12 @@ pub async fn stake(params: Result) -> JsonRpcResult { let msg = withdrawer.as_secp256k1_msg(); let authorization = params - .authorization - .try_do_magic(|hex_str| KeyedSignature::from_recoverable_hex(&hex_str, &msg)) - .map_err(internal_error)?; + .authorization.try_do_magic(|hex_str| { + KeyedSignature::from_recoverable_hex( + &hex_str[hex_str.char_indices().nth_back(129).unwrap().0..], + &msg, + ) + }); let validator = PublicKeyHash::from_public_key(&authorization.public_key); log::debug!( "[STAKE] A stake authorization was provided, and it was signed by validator {}", diff --git a/src/cli/node/json_rpc_client.rs b/src/cli/node/json_rpc_client.rs index ea4be0786..6ae44845f 100644 --- a/src/cli/node/json_rpc_client.rs +++ b/src/cli/node/json_rpc_client.rs @@ -951,6 +951,7 @@ pub fn send_st( dry_run: true, ..build_stake_params.clone() }; + log::debug!("[SEND STAKE 1]: {}", dry_params.clone().value); let (bsr, ..): (BuildStakeResponse, _) = issue_method("stake", Some(dry_params), &mut stream, id.next())?; let dry_weight = bsr.transaction.weight(); @@ -975,6 +976,7 @@ pub fn send_st( dry_run: true, ..build_stake_params.clone() }; + log::debug!("[SEND STAKE 2]: {}", params.clone().value); let (dry, _): (BuildStakeResponse, _) = issue_method("stake", Some(params), &mut stream, id.next())?; @@ -1039,8 +1041,23 @@ pub fn authorize_st(addr: SocketAddr, withdrawer: Option) -> Result<(), let message = authorization.withdrawer.as_secp256k1_msg(); - let auth_bytes = authorization.signature.to_recoverable_bytes(&message)?; - let auth_string = hex::encode(auth_bytes); + // let validator_bytes: [u8; 20] = authorization.signature.public_key.pkh().as_ref().try_into()?; + // let signature_bytes: [u8; 65] = authorization.signature.to_recoverable_bytes(&message).unwrap(); + // let auth_string: String = hex::encode([&validator_bytes[..], &signature_bytes[..]].concat()); + + let auth_string = { + let validator_bytes: [u8; 20] = authorization + .signature + .public_key + .pkh() + .as_ref() + .try_into()?; + let signature_bytes: [u8; 65] = authorization + .signature + .to_recoverable_bytes(&message) + .unwrap(); + hex::encode([&validator_bytes[..], &signature_bytes[..]].concat()) + }; let auth_qr = qrcode::QrCode::new(&auth_string)?; let auth_ascii = auth_qr