defuse_webauthn/
p256.rs

1use defuse_crypto::Curve;
2pub use defuse_crypto::{P256CompressedPublicKey, P256Signature};
3use near_sdk::env;
4
5use crate::Algorithm;
6
7/// [COSE ES256 (-7) algorithm](https://www.iana.org/assignments/cose/cose.xhtml#algorithms):
8/// P256 (a.k.a secp256r1) over SHA-256
9#[derive(Debug, Clone)]
10pub struct P256;
11
12impl Algorithm for P256 {
13    type PublicKey = P256CompressedPublicKey;
14    type Signature = P256Signature;
15
16    #[inline]
17    fn verify(msg: &[u8], public_key: &Self::PublicKey, signature: &Self::Signature) -> bool {
18        // Use host impl of SHA-256 here to reduce gas consumption
19        let prehashed = env::sha256_array(msg);
20
21        defuse_crypto::P256::verify(&signature.0, &prehashed, &public_key.0).is_some()
22    }
23}