Skip to content

Support for CIP14 #289

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

Closed
theeldermillenial opened this issue Dec 30, 2023 · 0 comments · Fixed by #294
Closed

Support for CIP14 #289

theeldermillenial opened this issue Dec 30, 2023 · 0 comments · Fixed by #294

Comments

@theeldermillenial
Copy link
Contributor

theeldermillenial commented Dec 30, 2023

PyCardano does not currently support CIP14, which defines the mechanism for generating assets fingerprints (bech32).

https://developers.cardano.org/docs/governance/cardano-improvement-proposals/cip-0014/

A user requested this in Discord, and I was able to whip up a quick solution. PyCardano has all the necessary pre-requisites to implement this easily. I am posting this here mostly so it doesn't get lost in Discord history. At some point I should open a PR for this under pycardano.cip, but for now here is the quick sample I made up.

from nacl.encoding import RawEncoder
from nacl.hash import blake2b
from pycardano.crypto.bech32 import encode

tests = [
    {
        "policy_id": bytes.fromhex(
            "7eae28af2208be856f7a119668ae52a49b73725e326dc16579dcc373"
        ),
        "asset_name": bytes.fromhex(""),
        "asset_fingerprint": "asset1rjklcrnsdzqp65wjgrg55sy9723kw09mlgvlc3",
    }
]

asset_hash = blake2b(
    tests[0]["policy_id"] + tests[0]["asset_name"],
    digest_size=20,
    encoder=RawEncoder,
)
print(f"Calculated Asset Fingerprint: {encode('asset', asset_hash)}")
print(f"Expected Asset Fingerprint: {tests[0]['asset_fingerprint']}")

I think to finish this off, it should be:

  1. wrapped in a function that integrates well with other PyCardano types (i.e. MultiAsset encode/decode similar to Address with bech32 addresses)
  2. grab all test cases in CIP14 documentation, and use in unit tests

It's not much work, but I'm swamped right now. If someone want's to take a stab at it, be my guest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant