ArkProjectNFTs / ark-project

ArkProject is a liquidity layer for digital assets, uniting markets, empowering creators, and bridging the gap to mass adoption. Built on top of Starknet, ArkProject is designed to provide a fully decentralized and trustless orderbook on-chain.
https://arkproject.dev
Apache License 2.0
26 stars 12 forks source link

Add the hardware signer compatibility (secp256r1) #193

Open remiroyc opened 9 months ago

remiroyc commented 9 months ago

Problem

The Bravos wallets use secure enclave and NIST-P256 elliptic curve (secp256r1) to sign messages. We must implement this signer in Cairo to verify the order proof and be filly compatible with this kind of wallets.

Feature request

The task here is to add a variant to the SignerValidator enum to support this: https://github.com/starkware-libs/cairo/blob/v2.3.1/corelib/src/starknet/secp256r1.cairo

impl SignerValidator of SignatureChecker {
    fn verify(hash: felt252, signer: Signer) -> felt252 {
        match signer {
            Signer::WEIERSTRESS_STARKNET(sign_info) => {
                let is_valid = ecdsa::check_ecdsa_signature(
                    hash, sign_info.user_pubkey, sign_info.user_sig_r, sign_info.user_sig_s
                );
                assert(is_valid, 'INVALID_SIGNATURE');
                sign_info.user_pubkey
            }
        }
    }
}

#[derive(Serde, Copy, Drop)]
enum Signer {
    WEIERSTRESS_STARKNET: SignInfo,
}

Links

https://braavos.app/hardware-signer-2fa-security-crypto-smart-contract-wallets/