I'm trying to create a basic HTTP server that authorizes users with Authorization Pubkey:Sig like what Crust explained here.

However, creating a Signature from &str with Signature::fromSlice() failing. How can I convert the &str to a Signature?

pub type Signature = subxt::sp_core::sr25519::Signature;
pub type PublicKey = subxt::sp_core::sr25519::Public;
let pub_key = value.get(0).unwrap(); // 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY
let sig = value.get(1).unwrap(); // f2f7211fcc2204dc3fa50cf1aca98b7c49c82510efbc84fd808b46c459069017db7a47acf4040d1cc0363eb5e3416c197e15fd2439e70a69dcdfa2eb8b520280
let public_key = PublicKey::from_str(pub_key);
let signature = Signature::from_slice(sig.as_bytes());

if public_key.is_err() {
    return Err(actix_web::error::ErrorUnauthorized("Invalid Public Key"));

if signature.is_none() {
    return Err(actix_web::error::ErrorUnauthorized("Invalid Signature"));

1 Answer 1


Are you sure that sig you're getting from value.get(1).unwrap() is correct?

documentation on from_slice says the following:

A new instance from the given slice that should be 64 bytes long. NOTE: No checking goes on to ensure this is a real signature. Only use it if you are certain that the array actually is a signature. GIGO!

also, checking your code:

let sig = "f2f7211fcc2204dc3fa50cf1aca98b7c49c82510efbc84fd808b46c459069017db7a47acf4040d1cc0363eb5e3416c197e15fd2439e70a69dcdfa2eb8b520280";
println!("{}", sig.as_bytes().len());

prints out 128, which is 2x the expected.

if I cut it down to half:

let sig = "f2f7211fcc2204dc3fa50cf1aca98b7c49c82510efbc84fd808b46c459069017";
let signature = Signature::from_slice(sig.as_bytes());
println!("{:?}", signature);

I get:


Which doesn't necessarily mean that you should also cut down in half whatever is coming from value.get(1).unwrap(). But it does mean that for some reason, this value is 2x bigger than a correct signature would be.

  • I signed Alice's public key using polkadot.js.org/apps/#/signing. I',m sure that sig is what I send with the header. After signing, I send the combination as a header using Postman. I guess I need to use a client library that can create a 64-byes long signature.
    – Burak
    Jun 9, 2022 at 21:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.