Skip to content

Conversation

@Sbcdn
Copy link
Contributor

@Sbcdn Sbcdn commented Jul 22, 2022

@Sbcdn Sbcdn requested a review from scarmuega as a code owner July 22, 2022 11:27
use cryptoxide::{digest::Digest, blake2b::Blake2b};
use crate::utils::bech32::{Bech32Config,Bech32Provider};

pub fn blake2b160(data: &[u8]) -> [u8;20] {
Copy link
Contributor

@SmaugPool SmaugPool Jul 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code already exists in Pallas: https://github.com/txpipe/pallas/blob/main/pallas-crypto/src/hash/hasher.rs.

You just have to add:

common_hasher!(160);

at https://github.com/txpipe/pallas/blob/1482303616e9ba68f322eceb9ed03118efee28d5/pallas-crypto/src/hash/hasher.rs#L109 and some comments in the header, then you can do something like:

use pallas::crypto::hash::{Hash, Hasher};

fn asset_fingerprint(policy: &ByteVec, asset: &ByteVec) -> String {
    let mut hasher = Hasher::<160>::new();
    hasher.input(policy);
    hasher.input(asset);
    bech32::encode(
        &"asset".to_string(),
        hasher.finalize().to_base32(),
        bech32::Variant::Bech32,
    )
    .unwrap()
}

Likely returning a Result instead of the unwrap here.

@SmaugPool
Copy link
Contributor

I think we might also want the fingerprint in the MintRecord struct too, but this kind of leads to duplicates, so I'm not sure what's the best option here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

No open projects
Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants