-
Notifications
You must be signed in to change notification settings - Fork 87
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
Ipfs base32 cid v1 #46
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See why: ensdomains/ens-app#538 (review)
this actually looks good to merge (minus the yarn.lock conflict), is something blocking it? @makoto can we merge this + ensdomains/ens-app#538 ? |
I tried this PR. It seems encoding IPNS I am suspecting that it is because the encoding method use Base 58 but that's for v0 and it is something else according to the IPFS content addressing doc. Does it mean we need to add v1 specific encoding method at https://github.com/pldespaigne/content-hash ? |
@makoto for the specific snippet you pointed at, the fix is most likely something like this: ipfs: (value) => {
- const multihash = multiH.fromB58String(value);
- return new CID(1, 'dag-pb', multihash).buffer;
+ return new CID(value).toV1().buffer;
}, As a rule of thumb, there should be just a generic code dealing with CID, parser should not care about the details of CID itself (v0, v1, codec, base, etc). Note that this PR is over year old and:
@makoto @pldespaigne Let me know how I you need help with any of the above. |
@lidel thanks for the explanation.
Is it always the case regardless of encoding v0 or v1?
Are they changes required on |
This fixes issue described in ensdomains/ui#46 (comment)
Yes, it will create a valid CID from the string
all needs to happen in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs new release of content-hash
, details inline
@@ -54,7 +54,7 @@ | |||
"base58check": "^2.0.0", | |||
"bech32": "^1.1.3", | |||
"bs58": "^4.0.1", | |||
"content-hash": "^2.4.1", | |||
"content-hash": "^2.5.2", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs new release with fixes from pldespaigne/content-hash#43
|
||
// convert the ipfs from base58 to base32 (url host compatible) | ||
// if needed the hash can now be resolved through a secured origin gateway (<hash>.gateway.com) | ||
decoded = contentHash.helpers.cidV0ToV1Base32(decoded) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@makoto
Unsure about context, but if this is needed for subdomain gateways, it should use cidForWeb
from pldespaigne/content-hash#43 instead.
Feel free to ping me if more context from IPFS side is needed.
Hello guys 👋 @makoto @Arachnid @jefflau
I just updated the
decodeContenthash(encoded)
function to convert ipfs hash to cid v1 base32.Explenation
Recently the folks from IPFS have updated their libs & gateways to support cid v1 base 32.
That means that now we can resolve ipfs content with
<hash>.gateway.com
instead ofgateway.com/ipfs/<hash>
.This is really more secure since ipfs served content doesn't share the same origin (cookies, localStorage, etc...) anymore.
The trick is that we need to use base32 cid v1 hash instead of regular cid v0 btc58 ipfs hash, because domains cannot contains capital letters.
So I updated my
content-hash
lib with a small helper function to convert cid v0 hash to cid v1 so that they can be resolved to a secure gateway. Then I have used this helpers function in this PR.As always thanks a lot for your time and your work!
PS : I have also open a PR on the ens-app, but it depends on this PR to work correctly.