Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade contract to Cairo 2.7 #549

Merged
merged 14 commits into from
Aug 21, 2024
Prev Previous commit
Next Next commit
removed sha256 cairo version
piniom committed Aug 21, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 02fb13933d99f531f214b787d743260db58df532
20 changes: 2 additions & 18 deletions packages/account_sdk/src/signers/webauthn.rs
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@ use super::{DeviceError, HashSigner, SignError};
use crate::abigen::controller::Signature;
use crate::abigen::{
self,
controller::{Sha256Implementation, Signer, SignerSignature, WebauthnSignature},
controller::{Signer, SignerSignature, WebauthnSignature},
};
use crate::OriginProvider;

@@ -305,8 +305,7 @@ where
{
// According to https://www.w3.org/TR/webauthn/#clientdatajson-verification
async fn sign(&self, tx_hash: &Felt) -> Result<SignerSignature, SignError> {
let mut challenge = tx_hash.to_bytes_be().to_vec();
challenge.push(Sha256Implementation::Cairo1.encode());
let challenge = tx_hash.to_bytes_be().to_vec();

let options = PublicKeyCredentialRequestOptions {
challenge: Base64UrlSafeData::from(challenge),
@@ -357,7 +356,6 @@ where
s = s_neg;
y_parity = !y_parity;
}

let signature = Signature {
r: U256::from_bytes_be(r.to_bytes().as_slice().try_into().unwrap()),
s: U256::from_bytes_be(s.to_bytes().as_slice().try_into().unwrap()),
@@ -372,7 +370,6 @@ where
top_origin: client_data.top_origin.map(|s| s.into_bytes()),
sign_count: counter,
ec_signature: signature,
sha256_implementation: Sha256Implementation::Cairo1,
client_data_json_outro,
};

@@ -387,19 +384,6 @@ where
}
}

trait Sha256ImplementationEncoder {
fn encode(&self) -> u8;
}

impl Sha256ImplementationEncoder for Sha256Implementation {
fn encode(&self) -> u8 {
match self {
Sha256Implementation::Cairo0 => 0,
Sha256Implementation::Cairo1 => 1,
}
}
}

#[derive(Debug, Clone)]
pub struct WebauthnSigner<T: WebauthnBackend> {
pub rp_id: String,