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 8, 2025
1 parent 8c65a50 commit f574b32
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
10 changes: 6 additions & 4 deletions node/src/actors/json_rpc/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2045,10 +2045,12 @@ pub async fn stake(params: Result<BuildStakeParams, Error>) -> JsonRpcResult {
// This is the actual message that gets signed as part of the authorization
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)?;
let authorization = params.authorization.try_do_magic(|hex_str| {
KeyedSignature::from_recoverable_hex(
&hex_str[hex_str.char_indices().nth_back(129).unwrap().0..],
&msg,
)
}).map_err(internal_error)?;
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
15 changes: 13 additions & 2 deletions src/cli/node/json_rpc_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1039,8 +1039,19 @@ 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 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 f574b32

Please sign in to comment.