massalabs / massa

The Decentralized and Scaled Blockchain
https://massa.net
5.57k stars 711 forks source link

Cannot verify signature on binary data #4388

Open sydhds opened 1 year ago

sydhds commented 1 year ago

In a SC, we can only pass string (for digest argument) to the function:

isSignatureValid(
    digest: string,
    signature: string,
    publicKey: string,
  ): bool;

in massa-sc-runtime, the digest argument is indeed read as a string then directly converted to a string as the massa function impl is defined as:

fn signature_verify(&self, data: &[u8], signature: &str, public_key: &str) -> Result<bool>

this prevents from verifying sig on binary data and should be changed on massa-sc-runtime && massa-as-sdk.

Bonus:

AurelienFT commented 1 year ago

As a workaround, for now, you can verify only strings by encoding your binary data to like base64 before giving it to the verify function?