Skip to content

Commit

Permalink
fix: linter
Browse files Browse the repository at this point in the history
  • Loading branch information
alenmestrov committed Nov 29, 2024
1 parent 5bddfc3 commit 78f4be3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 24 deletions.
22 changes: 7 additions & 15 deletions contracts/icp/context-config/src/mutate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,12 @@ pub fn mutate(signed_request: ICPSigned<Request>) -> Result<(), String> {
ContextRequestKind::RemoveMembers { members } => {
remove_members(&request.signer_id, &context_id, members)
}
ContextRequestKind::Grant { capabilities } => grant(
&request.signer_id,
&context_id,
capabilities,
),
ContextRequestKind::Revoke { capabilities } => revoke(
&request.signer_id,
&context_id,
capabilities,
),
ContextRequestKind::Grant { capabilities } => {
grant(&request.signer_id, &context_id, capabilities)
}
ContextRequestKind::Revoke { capabilities } => {
revoke(&request.signer_id, &context_id, capabilities)
}
ContextRequestKind::UpdateProxyContract => {
// TODO: Implement update_proxy_contract
Ok(())
Expand Down Expand Up @@ -83,11 +79,7 @@ fn add_context(
};

// Store context
if configs
.contexts
.insert(context_id, context)
.is_some()
{
if configs.contexts.insert(context_id, context).is_some() {
return Err("context already exists".into());
}

Expand Down
10 changes: 6 additions & 4 deletions contracts/icp/context-config/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ impl<T: CandidType + Serialize + DeserializeOwned> ICPSigned<T> {
{
let bytes = candid::encode_one(payload)
.map_err(|e| ICPSignedError::SerializationError(e.to_string()))?;

let signature = sign(&bytes)
.into_result()
.map_err(ICPSignedError::DerivationError)?;
Expand Down Expand Up @@ -337,10 +337,12 @@ impl<T: CandidType + Serialize + DeserializeOwned> ICPSigned<T> {
.rt::<VerifyingKey>()
.map_err(|_| ICPSignedError::InvalidPublicKey)?;

let signature_bytes: [u8; 64] = self.signature.as_slice().try_into()
.map_err(|_| ICPSignedError::SignatureError(ed25519_dalek::ed25519::Error::new()))?;
let signature_bytes: [u8; 64] =
self.signature.as_slice().try_into().map_err(|_| {
ICPSignedError::SignatureError(ed25519_dalek::ed25519::Error::new())
})?;
let signature = ed25519_dalek::Signature::from_bytes(&signature_bytes);

key.verify(&self.payload, &signature)
.map_err(|_| ICPSignedError::InvalidSignature)?;

Expand Down
7 changes: 2 additions & 5 deletions contracts/icp/context-config/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,8 @@ fn setup() -> (PocketIc, Principal) {
}

fn create_signed_request(signer_key: &SigningKey, request: Request) -> ICPSigned<Request> {
ICPSigned::new(
request,
|bytes| signer_key.sign(bytes)
)
.expect("Failed to create signed request")
ICPSigned::new(request, |bytes| signer_key.sign(bytes))
.expect("Failed to create signed request")
}

fn get_time_nanos(pic: &PocketIc) -> u64 {
Expand Down

0 comments on commit 78f4be3

Please sign in to comment.