Skip to content

Commit

Permalink
fix(legacy jor sig check): chain crypto sig check
Browse files Browse the repository at this point in the history
aligns with legacy snapshot
  • Loading branch information
cong-or committed May 4, 2024
1 parent 5d165b5 commit 0a04966
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 27 deletions.
9 changes: 5 additions & 4 deletions catalyst-gateway/bin/src/cardano/cip36_registration/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use anyhow::Ok;
use cardano_chain_follower::Network;
use chain_crypto::{AsymmetricPublicKey, Ed25519, Verification, VerificationAlgorithm};
use cryptoxide::{blake2b::Blake2b, digest::Digest};

use pallas::ledger::{
primitives::{conway::Metadatum, Fragment},
traverse::MultiEraMeta,
Expand Down Expand Up @@ -209,9 +208,11 @@ pub fn validate_signature(
&hash_bytes,
) {
Verification::Success => Ok(()),
Verification::Failed => Err(anyhow::anyhow!(
"Cannot decode cbor object from bytes, err: "
)),
Verification::Failed => {
Err(anyhow::anyhow!(
"Cannot decode cbor object from bytes, err: "
))
},
}
}

Expand Down
54 changes: 31 additions & 23 deletions catalyst-gateway/bin/src/cardano/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,11 @@ pub struct PolicyAsset {
pub fn parse_policy_assets(assets: &[MultiEraPolicyAssets<'_>]) -> Vec<PolicyAsset> {
assets
.iter()
.map(|asset| PolicyAsset {
policy_hash: asset.policy().to_string(),
assets: parse_child_assets(&asset.assets()),
.map(|asset| {
PolicyAsset {
policy_hash: asset.policy().to_string(),
assets: parse_child_assets(&asset.assets()),
}
})
.collect()
}
Expand All @@ -69,21 +71,25 @@ pub fn parse_policy_assets(assets: &[MultiEraPolicyAssets<'_>]) -> Vec<PolicyAss
pub fn parse_child_assets(assets: &[MultiEraAsset]) -> Vec<Asset> {
assets
.iter()
.filter_map(|asset| match asset {
MultiEraAsset::AlonzoCompatibleOutput(id, name, amount) => Some(Asset {
policy_id: id.to_string(),
name: name.to_string(),
amount: *amount,
}),
MultiEraAsset::AlonzoCompatibleMint(id, name, amount) => {
let amount = u64::try_from(*amount).ok()?;
Some(Asset {
policy_id: id.to_string(),
name: name.to_string(),
amount,
})
},
_ => Some(Asset::default()),
.filter_map(|asset| {
match asset {
MultiEraAsset::AlonzoCompatibleOutput(id, name, amount) => {
Some(Asset {
policy_id: id.to_string(),
name: name.to_string(),
amount: *amount,
})
},
MultiEraAsset::AlonzoCompatibleMint(id, name, amount) => {
let amount = u64::try_from(*amount).ok()?;
Some(Asset {
policy_id: id.to_string(),
name: name.to_string(),
amount,
})
},
_ => Some(Asset::default()),
}
})
.collect()
}
Expand All @@ -107,11 +113,13 @@ pub fn extract_stake_credentials_from_certs(
pallas::ledger::primitives::alonzo::Certificate::StakeDelegation(
stake_credential,
_,
) => match stake_credential {
StakeCredential::AddrKeyhash(stake_credential) => {
stake_credentials.push(hex::encode(stake_credential.as_slice()));
},
StakeCredential::Scripthash(_) => (),
) => {
match stake_credential {
StakeCredential::AddrKeyhash(stake_credential) => {
stake_credentials.push(hex::encode(stake_credential.as_slice()));
},
StakeCredential::Scripthash(_) => (),
}
},
_ => continue,
}
Expand Down

0 comments on commit 0a04966

Please sign in to comment.