Skip to content

Examples of library usage #12

Open
@olliejm

Description

@olliejm

Hi, sorry if this is not the best place for such questions but I'm struggling to find any examples on how to achieve something with this library.

I'm looking to verify the signature of a payload signed with the dApp injected API function signData(address, payload). When I run this method I get an output of an object like this:

{
  "signature": "<long_hex_string>",
  "key": "<shorter_hex_string>"
}

Now on a server I want to validate this signature as a means of proof of address ownership.

Anyway, I found this example linked from the CIP-0008 readme.

So firstly I tried to do something similar to construct an instance of PublicKey, on a presumption that key from the JSON above is indeed a public key, trying:

let key_bytes = signed_data.key.as_bytes();
let pub_key = cardano_serialization_lib::crypto::PublicKey::from_bytes(key_bytes);

Unfortunately this creates an error of Invalid Public Key size. For good measure I also tried from_bech32 on the string itself, but that results in Malformed public key.

There is one other example linked, which seems to outline how to then verify a signature after getting an instance of PublicKey, but that example constructs the key from a private key - which in my case I don't have.

I believe I'll also need to use PublicKey to check that the address belongs to the key, as well verifying the signature, but I don't think I saw any examples of that unless I missed something.

I may well just be making a really stupid mistake here - as I am new to Rust, Cose, CBOR and all Cardano development beyond the injected dApp APIs. I appreciate that it's very early days for a library like this to have fleshed out documentation with detailed examples, however I'd be very grateful if anyone was able to offer any pointers. Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions