Is it possible to use verify_ecdsa_signature in cairo to verify a web3.js/wallet ecdsa signature?

I am pretty new to Cairo and I am thinking of building a dApp that takes web3 wallet signatures and validate it in Cairo-based contract on Starknet.

When using web3.js, I can sign a message like this:

web3.eth.accounts.sign('Some data', '0x4c0883a69102937d6231471b5dbb6204fe5129617082792ae468d01a3f362318');
> {
    message: 'Some data',
    messageHash: '0x1da44b586eb0729ff70a73c326926f6ed5a25f5b056e7f47fbc6e58d86871655',
    v: '0x1c',
    r: '0xb91467e570a6466aa9e9876cbcd013baba02900b8979d43fe208a4a4f339f5fd',
    s: '0x6007e74cd82e037b800186422fc2da167c747ef045e5d18a5f5d4300f8e1a029',
    signature: '0xb91467e570a6466aa9e9876cbcd013baba02900b8979d43fe208a4a4f339f5fd6007e74cd82e037b800186422fc2da167c747ef045e5d18a5f5d4300f8e1a0291c'
}
// note public key is "0x2c7536E3605D9C16a7a3D7b1898e529396a65c23"

when I tried to use Cairo’s builtin verify_ecdsa_signature, It did not work (maybe I’m doing something wrong). It was failing at the line assert ecdsa_ptr.pub_key = public_key.

The way I tried to use verify_ecdsa_signature is by first converting all the hex values in the msg_hash,r,s and public key to decimals. then call

    let (msg_hash) = hash2{hash_ptr=pedersen_ptr}(1539108943018361713761, 0)
    
    verify_ecdsa_signature(
        message=msg_hash,
        public_key=253809562540106565134163611412781682525957676067,
        signature_r=83713930994764734002432606962255364472443135907807238282514898577139886061053,
        signature_s=43435997768575461196683613590576722655951133545204789519877940758262837256233)

I have two questions here:
1- Does it even make sense to do this in the first place? in another word is verify_ecdsa_signature secp256k1n compatible? if not (according to Support Web3 wallets in StarkNet) then when is Starkware planning on releasing the ability to do this?
2- If it does, then what’s going wrong here? and what am i supposed to do with the v value? as it’s part of the signature.

UPDATE: have you tried this? I found this example and might be what I’m looking for cairo-examples/secp at master · starkware-libs/cairo-examples · GitHub correct me if I am wrong
Thanks!

11 Likes

It’s not, that’s the StarkKey’s signing algorithm. Check Support Web3 wallets in StarkNet

1 Like

have you tried this? @martriay cairo-examples/secp at master · starkware-libs/cairo-examples · GitHub

10 Likes

I haven’t, I didn’t know that was released!

5 Likes