mlabs-haskell / nft-marketplace-server

2 stars 2 forks source link

Convert encoding of CID #22

Open t4ccer opened 2 years ago

t4ccer commented 2 years ago

When receiving CID form nft.storage, CID is encoded in base32 (however docs do not guarantee that it will be always the case). CID encoded in NFT metadata cannot be in base32 due to limitation of onchain metdata string length so it has to be converted (for example to base36).

This is not critical as we control minting, but has to be done before launch where users can mint NFTs.

samuelWilliams99 commented 2 years ago

https://github.com/mlabs-haskell/nft-marketplace-server/blob/main/src/NftStorage.hs#L45 https://github.com/mlabs-haskell/nft-marketplace-server/blob/main/src/NftStorage.hs#L63

samuelWilliams99 commented 2 years ago

In second line, assume v is base 32, convert to base 36. Followup ticket to this will be to discover the real encoding of v, and convert to 36 accordingly. This would require the IPFS docs

rynoV commented 2 years ago

We need to make sure the base32 CIDs returned from nft.storage in the /admin/upload_image endpoint are converted to base36 before being added to the database. Note the CIDs have some prefixes that need to be dealt with (see here). The server should convert the CIDs in the same way as ipfs cid format -b base36 (ipfs command from seabug nix develop). An example CID base 32 => base 36: bafkreiec5jsqb262sayubmds3jyz5o6vu3kzmjmarppgpz5nqqful7quxq => k2cwuebwvb6kdiwob6sb2yqnz38r0yv72q1xijbts9ep5lq3nm8rw3i4 You can upload your own images for testing using the code in seabug/scripts/mint-nft.sh