verifyIPFS
verifyIPFS copied to clipboard
base 58 decode function?
The b58 encode function is awesome, would there be a way to make a similar one that decodes instead?
Hi @MrChico , thank you so much I'm using your code in production for Ninfa.io marketplace nft contracts, you're leet!
I'm currently using javascript for encoding ipfs CID to bytes32, do you have any pointers for doing the same in Solidity? For writing some scripts in Foundry!
For the record @hen-hao
const bs58 = require("bs58");
const getBytes32FromCID = (str) => {
// remove leading 0x
const remove0x = str.slice(2, str.length);
// add back the multihash id
const bytes = Buffer.from(`1220${remove0x}`, "hex");
const hash = bs58.encode(bytes);
return hash;
};
const getCIDFromBytes32 = (hash) => {
let bytes = bs58.decode(hash);
const multiHashId = 2;
// remove the multihash hash id
bytes = bytes.slice(multiHashId, bytes.length);
return web3.utils.bytesToHex(bytes);
};