-
Notifications
You must be signed in to change notification settings - Fork 11
Why do IPFS hashes start with "Qm"? #22
Comments
No, if objects were hashed with other functions, the prefix would be different. try out this binary: https://github.com/jbenet/go-multihash/tree/master/multihash |
Thanks, when does IPFS use another function? So far I've only seen |
@moreati we use sha256-256, but it's not hard for someone to re-compile ipfs to use another function as a default, or change the importer code to add a way to specify the multihash choice. |
I see this question a lot; reopening it and labelling it as 'answered' to increase visibility. |
How is |
It is base58-btc encode of the two bytes prefix of that multihash. |
I'm a bit confused by "The letters Qm happen to correspond with the algorithm (SHA-256) and length (32 bytes)" Is it that |
@JustinDrake If I got it right, multihashes start with a byte (0x12) which indicates the hashing algorithm, followed by another byte for length (0x20) . "Qm" letters are the result of those bytes encoded in base58. Source: https://github.com/multiformats/go-multihash/blob/master/multihash.go#L146 |
maybe I just haven't put all the pieces together, but I'm wondering if anyone here can off-hand explain the steps for how one might precompute the IPFS hash (Under the current build) given some JSON. Thanks in advance! |
@alexanderattar You can do that using |
ah thanks @RichardLitt! I guess my question is actually in regard to how I would approach this programmatically by running the JSON through the encoding algorithms without necessarily using the IPFS CLI. I am looking to take some JSON I have in JavaScript and precompute the hash before sending to IPFS if that helps explain the use-case. |
I just want to add that I have tried encrypting JSON via sha256 to get a hash such as 4f72333148622e4ae56e9c65d57aee47186cd6910ca080757ab72cc0c650f6bb and have prefixed this with 1220 and then taken the entire string with the prefix: 122000c75938d356b000b34e7f7885f8982f29d89af76c234a8d439486b40fdc5469 and after running that through a base58 encoding, I get a hash that resembles an IPFS hash with the prefixed Qm, but the hash is not consistent with was is returned from adding the same JSON to IPFS via the command-line. I am wondering if I am doing something wrong, or missing a step. Thanks again! |
Try doing the add with Where raw block has multicodec of 0x55. |
Thanks @Kubuxu but I just want to reiterate that I am not looking to use the ipfs CLI, but rather go through the necessary encryption and encoding steps to get from JSON to a IPFS hash. So far my method has been: Take the JSON and encode via SHA256 to get the digest, then prefix the digest with 1220 as described here, so the entire hex string is composed of the prefix plus the digest and then base58 encoded. Does any of this approach sound incorrect? |
IPFS by default also wraps the file you give it into some metadata used by ipfs itself. That is why it is different. |
Wow, I was not aware of that, but that does explain why the hash is different. Is there documentation on the metadata IPFS wraps the file in before generating the SHA256 digest? I tried using the --raw-leaves flag which indeed gives me a different hash:
but I have not found any documentation on what algorithms and processing the data goes through to produce this hash. |
This issue has been moved to https://discuss.ipfs.io/t/why-do-ipfs-hashes-start-with-qm/477. |
@alexanderattar have you had any luck generating the hash simulating the metadata? |
Hi @lautarodragan, I recently revisited this and got some help from someone who was working on something similar using the js-ipfs implementation. Check out this thread: ipfs/js-ipfs#1205. Hope it helps! |
Thanks @alexanderattar! Don't know why I didn't see your response earlier, but it's a lot of help. That test you wrote sheds some light on the inner workings of the IPFS hashs. I'll give it a try! |
No problem! Glad it's helpful.
Cheers,
On Wed, Jul 4, 2018 at 2:44 PM Lautaro Dragan ***@***.***> wrote:
Thanks @alexanderattar <https://github.com/alexanderattar>! Don't know
why I didn't see your response earlier, but it's a lot of help. That test
you wrote sheds some light on the inner workings of the IPFS hashs. I'll
give it a try!
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#22 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ABb2GvNQDduZJ6Z1Uf7crGwplGc71RDdks5uDQz2gaJpZM4Ff80s>
.
--
*Alexander Attar* // Platform Lead // Ujo
alexander.attar@consensys.net <alexander.attar@consenSys.net> / *+1 941 323
1019 <+1%20941-323-1019>*
49 Bogart St, Suite 22, Brooklyn NY 11206
Web <https://consensys.net/> | Twitter <https://twitter.com/ConsenSysLLC> |
Facebook <https://www.facebook.com/consensussystems> | Linkedin
<https://www.linkedin.com/company/consensus-systems-consensys-> | Newsletter
<http://consensys.us11.list-manage.com/subscribe?u=947c9b18fc27e0b00fc2ad055&id=257df01285&utm_content=buffer1ce12&utm_medium=social&utm_source=facebook.com&utm_campaign=buffer>
|
It would be good to have an example implementation of (lets call it IPFS multihash) ipfsmh using Background: |
@NiKiZe that sounds like a great idea! Currently, that tool would have to depend on the |
@Stebalien thanks for your reply. The code would preferably be small enough that it can be copied over to a different machine by hand without to much effort. |
I agree that a full ipfs client is not the solution. However, go builds really portable binaries so I don't really see any reason to go with C (let alone Python).
There are a lot of options that can affect the resulting hash so the tool would need to replicate all the options available on Note: if you want something reasonably portable, you can probably build it with |
To run a go binary, go needs to be installed |
Nope, go is a compiled language. It just compiles really fast so you can run go programs with
Same with Python. Personally, I wouldn'g go with either. |
Answer:
IPFS represents the hash of files and objects using Multihash format and Base58 encoding. The letters
Qm
happen to correspond with the algorithm (SHA-256) and length (32 bytes) used by IPFS.TODO:
The text was updated successfully, but these errors were encountered: