-
Notifications
You must be signed in to change notification settings - Fork 10
feat: human-readable cache keys for IPNS #38
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.
lgtm, but we need to normalize key
namesys.go
Outdated
@@ -215,7 +215,7 @@ func (ns *mpns) resolveOnceAsync(ctx context.Context, name string, options opts. | |||
|
|||
cacheKey := key | |||
if err == nil { | |||
cacheKey = string(ipnsKey) | |||
cacheKey = ipnsKey.String() |
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.
This won't be enough because of legacy mess: /ipns/id
can be Base58btc of peerid (12...
which is not a valid CID), or CIDv1 with libp2p-key multihash in base36 (k51..
).
This screates surface for bugs, where someone tries to use CIDv1 base36 (k..
) produced by ipfs key list -l
and it does not work because raw peerid 12...
is expected here.
I think we need something like:
import (
iface "github.com/ipfs/interface-go-ipfs-core"
...
cacheKey = iface.FormatKeyID(ipnsKey)
This way the key will be canonical cidv1+libp2p-key+base36, the same user can see in ipfs key list -l
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.
Got it, thanks for the review and details.
I guess since all the cache keys go through the same calls, that's "just" a problem for the user that tries to use something other than a raw peer id in IPFS_NS_MAP
.
I updated the PR so that we normalize all the keys loaded from IPFS_NS_MAP
with the same FormatKeyID
, and added tests!
a42ecbe
to
5fc1bc5
Compare
5fc1bc5
to
7c65803
Compare
7c65803
to
f9ab490
Compare
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.
Thank you @laurentsenta.
Merging, so we include this in future release.
Closes #37
Use
ipnsKey.String()
to generate cache keys, which generate a b58 encoding instead of using non-printable characters.This makes it practical to populate the
IPFS_NS_MAP
env variable with IPNS records: