diff --git a/asm-scripts/assembly/index.ts b/asm-scripts/assembly/index.ts index c72267e..515d494 100644 --- a/asm-scripts/assembly/index.ts +++ b/asm-scripts/assembly/index.ts @@ -4,13 +4,13 @@ function load_lines_of_code(): u32 { } @inline -function load_evaluated_years_of_experience(): u8 { - return load(4); +function load_evaluated_years_of_experience(): u32 { + return load(4); } @inline function load_number_of_prs(): u32 { - return load(5); + return load(8); } export function calc(): i64 { diff --git a/pallets/credentials/src/lib.rs b/pallets/credentials/src/lib.rs index a89f859..e589b20 100644 --- a/pallets/credentials/src/lib.rs +++ b/pallets/credentials/src/lib.rs @@ -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::*; @@ -146,7 +149,8 @@ pub mod pallet { let schema = Schemas::::get(schema_id) .ok_or(Error::::SchemaNotFound)?; - ensure!(Pallet::::validate_attestation(&schema, &attestation), Error::::InvalidFormat); + let attestation = Pallet::::validate_attestation(&schema, &attestation) + .ok_or(Error::::InvalidFormat)?; Attestations::::insert(for_account.clone(), schema_id, attestation.clone()); @@ -188,20 +192,28 @@ pub mod pallet { } impl Pallet { - pub fn validate_attestation(schema: &CredSchema, attestation: &CredAttestation) -> bool { + pub fn validate_attestation(schema: &CredSchema, attestation: &CredAttestation) -> Option { 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) } } } \ No newline at end of file