Skip to content

Commit

Permalink
Include validator pkh in authorization
Browse files Browse the repository at this point in the history
  • Loading branch information
parodyBit committed Jan 2, 2025
1 parent 8c65a50 commit 2d50f54
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
9 changes: 6 additions & 3 deletions node/src/actors/json_rpc/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2046,9 +2046,12 @@ pub async fn stake(params: Result<BuildStakeParams, Error>) -> 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 {}",
Expand Down
21 changes: 19 additions & 2 deletions src/cli/node/json_rpc_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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())?;

Expand Down Expand Up @@ -1039,8 +1041,23 @@ pub fn authorize_st(addr: SocketAddr, withdrawer: Option<String>) -> 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
Expand Down

0 comments on commit 2d50f54

Please sign in to comment.