Closed
Description
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:
- wrapped in a function that integrates well with other PyCardano types (i.e.
MultiAsset
encode/decode similar toAddress
with bech32 addresses) - 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.
Metadata
Metadata
Assignees
Labels
No labels