Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include validator pkh in authorization #2567

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading