Skip to content
This repository was archived by the owner on May 12, 2022. It is now read-only.

Comments

Add ipfs and ipns resolving support#13

Open
MakMuftic wants to merge 16 commits intoMetaMask:developfrom
ChainSafe:mmuftic/ipfs-ipns-resolving-support
Open

Add ipfs and ipns resolving support#13
MakMuftic wants to merge 16 commits intoMetaMask:developfrom
ChainSafe:mmuftic/ipfs-ipns-resolving-support

Conversation

@MakMuftic
Copy link

@MakMuftic MakMuftic commented Oct 5, 2021

This PR will enable Metamask users to resolve ipfs:// and ipns:// URLs (on browsers that don't have integrated support for this).

⚠️ IMPORTANT ⚠️
For this feature to work properly, we should first merge fix #12

Browser support:

Brave Opera

Brave and Opera already have native support for resolving ipfs:// and ipns://, so there is no sense in providing these features.


Chrome

Metamasks advanced settings have been expanded with a new category (Enable IPFS and IPNS URL resolving). When the user enables this feature, the browser will ask the user to give Metamask permission for handling IPFS and IPNS URLs. After this initial setup, the users' browser will resolve ipfs:// and ipns:// using gateway from settings.

Manual testing steps:

  • Enable IPFS and IPNS URL resolving
  • Resolve one valid IPFS and one valid IPNS URL
  • Change gateway in settings (make sure new gateway is used)
  • Disable IPFS and IPNS URL resolving (make sure that URLs are not still resolving)

Explanation of solution:

As chrome doesn't support setting protocol_handlers as part of manifest definition, the only way to support URL resolving was to set protocol handler through code using window.navigator.registerProtocolHandler. The limitation here was that it must be invoked from a page that will handle these requests. Because of this, when the user wants to turn on the URL resolving feature new view is shown and the protocol handler then registers on chrome-extension://<extension-id>/. Now all ipfs:// and ipns:// requests are rerouted to extension and then handled by the onBeforeRequest handler.


Firefox

After metamask is installed, firefox handles ipfs:// and ipns:// requests by routing them to https://dweb.link/ipfs/...

Explanation of solution:

Same implementation as Chrome solution wasn't possible as Firefox doesn't allow setting permission for routing requests on extension page (moz-extension), because of that it was impossible to invoke window.navigator.registerProtocolHandler and mimic Chrome flow. On the other side, Firefox does support setting protocol_handlers as part of manifest definition, so this was used to enable URL resolving. This solution does limit any kind of configuration or enabling/disabling this feature, it just registers protocol handlers when adding metamask.

I have read the CLA Document and I hereby sign the CLA

@MakMuftic MakMuftic requested a review from a team as a code owner October 5, 2021 11:00
@MakMuftic MakMuftic requested a review from ryanml October 5, 2021 11:00
@MakMuftic
Copy link
Author

I have read the CLA Document and I hereby sign the CLA

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant