Skip to content

Commit

Permalink
Merge github.com:burnt-labs/contracts into feat/custom-query
Browse files Browse the repository at this point in the history
  • Loading branch information
Peartes committed Jan 31, 2024
2 parents 91ec6f9 + 0e8b099 commit cc859c9
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
5 changes: 3 additions & 2 deletions account/src/auth/jwt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ static AUD_KEY_MAP: Map<&'static str, &'static str> = phf_map! {
"integration-test-project" => "olg7TF3aai-wR4HTDe5oR-WRhEsdW3u-O3IJHl0BiHkmR4MLskHG9HzivWoXsloUBnBMrFNxOH0x5cNMI07oi4PeRbHySiogRW9CXPjJaNlTi-pT_IgKFsyJNXsLyzrnajLkDbQU6pRsHmNeL0hAOUv48rtXv8VVWWN8okJehD2q9N7LHoFAOmIUEPg_VTHTt8K__O-9eMZKN4eMjh_4-sxRX6NXPSPT87XRlrK4GZ4pUdp86K0tOFLhwO4Uj0JkMNfI82eVZ1tAbDlqjd8jFnAb8fWm8wtdaTNbL_AAXmbDhswwJOyrw8fARZIhrXSdKBWa6e4k7sLwTIy-OO8saebnlARsjGst7ZCzmw5KCm2ctEVl3hYhHwyXu_A5rOblMrV3H0G7WqeKMCMVSJ11ssrlsmfVhNIwu1Qlt5GYmPTTJiCgGUGRxZkgDyOyjFNHglYpZamCGyJ9oyofsukEGoqMQ6WzjFi_hjVapzXi7Li-Q0OjEopIUUDDgeUrgjbGY0eiHI6sAz5hoaD0Qjc9e3Hk6-y7VcKCTCAanZOlJV0vJkHB98LBLh9qAoVUei_VaLFe2IcfVlrL_43aXlsHhr_SUQY5pHPlUMbQihE_57dpPRh31qDX_w6ye8dilniP8JmpKM2uIwnJ0x7hfJ45Qa0oLHmrGlzY9wi-RGP0YUk;AQAB",
};

const AVERAGE_BLOCK_TIME: u64 = 6;
// The average block time of 2 blocks.
const AVERAGE_BLOCK_TIME_OF_TWO_BLOCKS: u64 = 12;

#[derive(Debug, Serialize, Deserialize)]
struct Claims {
Expand Down Expand Up @@ -98,7 +99,7 @@ pub fn verify(
// the average block time to allow for a more realistic timestamp. this has
// implications for the "not before" and "expiration" timestamps, in that we
// are more forgiving for "not before" and less forgiving for "expiration"
let working_time = &current_time.plus_seconds(AVERAGE_BLOCK_TIME);
let working_time = &current_time.plus_seconds(AVERAGE_BLOCK_TIME_OF_TWO_BLOCKS);
let expiration = Timestamp::from_seconds(claims.exp as u64);
if expiration.lt(working_time) {
return Err(InvalidTime {
Expand Down
4 changes: 2 additions & 2 deletions account/src/auth/sign_arb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ fn wrap_message(msg_bytes: &[u8], signer: Addr) -> Vec<u8> {
mod tests {
use crate::auth::sign_arb::wrap_message;
use crate::auth::util;
use crate::auth::AddAuthenticator::Secp256K1;
use crate::auth::Authenticator::Secp256K1;

Check warning on line 34 in account/src/auth/sign_arb.rs

View workflow job for this annotation

GitHub Actions / Test Suite

unused import: `crate::auth::Authenticator::Secp256K1`
use crate::contract::instantiate;
use crate::msg::InstantiateMsg;
use crate::proto::XionCustomQuery;
Expand Down Expand Up @@ -123,7 +123,7 @@ mod tests {
let signature_bytes = general_purpose::STANDARD.decode(signature).unwrap();

let instantiate_msg = InstantiateMsg {
authenticator: Secp256K1 {
authenticator: crate::auth::AddAuthenticator::Secp256K1 {
id: 0,
pubkey: Binary::from(pubkey_bytes),
signature: Binary::from(signature_bytes),
Expand Down
3 changes: 3 additions & 0 deletions account/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ pub enum ContractError {

#[error("url parse error: {url}")]
URLParse { url: String },

#[error("cannot override existing authenticator at index {index}")]
OverridingIndex { index: u8 },
}

pub type ContractResult<T> = Result<T, ContractError>;
22 changes: 18 additions & 4 deletions account/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::borrow::BorrowMut;
use cosmwasm_std::{Addr, Binary, Deps, DepsMut, Env, Event, Order, Response};

use crate::auth::{passkey, AddAuthenticator, Authenticator};
use crate::error::ContractError::OverridingIndex;
use crate::proto::XionCustomQuery;
use crate::{
error::{ContractError, ContractResult},
Expand Down Expand Up @@ -112,7 +113,7 @@ pub fn add_auth_method(
)? {
Err(ContractError::InvalidSignature)
} else {
AUTHENTICATORS.save(deps.storage, *id, &auth)?;
save_authenticator(deps, *id, &auth)?;
Ok(())
}
}
Expand All @@ -133,7 +134,7 @@ pub fn add_auth_method(
)? {
Err(ContractError::InvalidSignature)
} else {
AUTHENTICATORS.save(deps.storage, *id, &auth)?;
save_authenticator(deps, *id, &auth)?;
Ok(())
}
}
Expand All @@ -154,7 +155,7 @@ pub fn add_auth_method(
)? {
Err(ContractError::InvalidSignature)
} else {
AUTHENTICATORS.save(deps.storage, *id, &auth)?;
save_authenticator(deps, *id, &auth)?;
Ok(())
}
}
Expand All @@ -177,7 +178,7 @@ pub fn add_auth_method(
)? {
Err(ContractError::InvalidSignature)
} else {
AUTHENTICATORS.save(deps.storage, *id, &auth)?;
save_authenticator(deps, *id, &auth)?;
Ok(())
}
}
Expand Down Expand Up @@ -236,6 +237,19 @@ pub fn add_auth_method(
)
}

pub fn save_authenticator(
deps: DepsMut<XionCustomQuery>,
id: u8,
authenticator: &Authenticator,
) -> ContractResult<()> {
if AUTHENTICATORS.has(deps.storage, id) {
return Err(OverridingIndex { index: id });
}

AUTHENTICATORS.save(deps.storage, id, authenticator)?;
Ok(())
}

pub fn remove_auth_method(
deps: DepsMut<XionCustomQuery>,
env: Env,
Expand Down

0 comments on commit cc859c9

Please sign in to comment.