Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
TarekkMA committed Feb 18, 2024
1 parent 1cc3a6f commit ec4cac8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
6 changes: 3 additions & 3 deletions asm-scripts/assembly/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ function load_lines_of_code(): u32 {
}

@inline
function load_evaluated_years_of_experience(): u8 {
return load<u8>(4);
function load_evaluated_years_of_experience(): u32 {
return load<u32>(4);
}

@inline
function load_number_of_prs(): u32 {
return load<u32>(5);
return load<u32>(8);
}

export function calc(): i64 {
Expand Down
26 changes: 19 additions & 7 deletions pallets/credentials/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
#![cfg_attr(not(feature = "std"), no_std)]

pub use pallet::*;

#[frame_support::pallet]
pub mod pallet {
use frame_support::dispatch::Vec;
use frame_support::pallet_prelude::{*, OptionQuery};
use frame_system::pallet_prelude::*;
use scale_info::prelude::vec;
use sp_runtime::traits::Hash;
use frame_support::dispatch::Vec;

use pallet_issuers::Issuers;

use super::*;
Expand Down Expand Up @@ -146,7 +149,8 @@ pub mod pallet {
let schema = Schemas::<T>::get(schema_id)
.ok_or(Error::<T>::SchemaNotFound)?;

ensure!(Pallet::<T>::validate_attestation(&schema, &attestation), Error::<T>::InvalidFormat);
let attestation = Pallet::<T>::validate_attestation(&schema, &attestation)
.ok_or(Error::<T>::InvalidFormat)?;

Attestations::<T>::insert(for_account.clone(), schema_id, attestation.clone());

Expand Down Expand Up @@ -188,20 +192,28 @@ pub mod pallet {
}

impl<T: Config> Pallet<T> {
pub fn validate_attestation(schema: &CredSchema, attestation: &CredAttestation) -> bool {
pub fn validate_attestation(schema: &CredSchema, attestation: &CredAttestation) -> Option<CredAttestation> {
if schema.len() != attestation.len() {
return false;
return None;
}

for ((_, cred_type), val) in schema.iter().zip(attestation) {
let mut formatted = vec![vec![]; attestation.len()];

for (((_, cred_type), val), i) in schema.iter().zip(attestation).zip(0..attestation.len()) {
let SizeInBytes::Limited(expected_len) = cred_type.size_in_bytes();
if val.is_empty() || val.len() > expected_len as usize {
return None;
}
formatted[i] = val.clone();
if val.len() != expected_len as usize {
return false;
for _ in 0..(expected_len as usize - val.len()) {
formatted[i].insert(0, 0);
}
}
}


true
Some(formatted)
}
}
}

0 comments on commit ec4cac8

Please sign in to comment.