Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cip14 fingerprint #367

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

cip14 fingerprint #367

wants to merge 2 commits into from

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
Collaborator

@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
Collaborator

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
Status: No status
Development

Successfully merging this pull request may close these issues.

2 participants