-
Notifications
You must be signed in to change notification settings - Fork 1
IPFS Integration #1
base: master
Are you sure you want to change the base?
Conversation
app/extensions.js
Outdated
incognito: 'split', | ||
// TODO(diasdavid) How to get this key?? | ||
key: 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyWl+wMvL0wZX3JUs7GeZAvxMP+LWEh2bwMV1HyuBra/lGZIq3Fmh0+AFnvFPXz1NpQkbLS3QWyqhdIn/lepGwuc2ma0glPzzmieqwctUurMGSGManApGO1MkcbSPhb+R1mx8tMam5+wbme4WoW37PI3oATgOs2NvHYuP60qol3U7b/zB3IWuqtwtqKe2Q1xY17btvPuz148ygWWIHneedt0jwfr6Zp+CSLARB9Heq/jqGXV4dPSVZ5ebBHLQ452iZkHxS6fm4Z+IxjKdYs3HNj/s8xbfEZ2ydnArGdJ0lpSK9jkDGYyUBugq5Qp3FH6zV89WqBvoV1dqUmL9gxbHsQIDAQAB' | ||
} |
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.
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.
js/constants/config.js
Outdated
@@ -49,6 +49,8 @@ module.exports = { | |||
}, | |||
braveExtensionId: 'mnojpmjdmbbfmejpflffifhffcmidifd', | |||
torrentExtensionId: 'fmdpfempfmekjkcfdehndghogpnpjeno', | |||
// TODO(diasdavid) how to these get calculated? | |||
ipfsExtensionId: 'asdakdaklsjdaklsjdalsdaslkdjasds', |
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.
js/stores/appStore.js
Outdated
@@ -427,6 +427,8 @@ const handleAppAction = (action) => { | |||
appState = filtering.init(appState, action, appStore) | |||
appState = basicAuth.init(appState, action, appStore) | |||
appState = webtorrent.init(appState, action, appStore) | |||
// TODO(diasdavid) - init IPFS in the main process | |||
// appState = ipfs.init(appState, action, appStore) |
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.
@@ -316,7 +323,8 @@ class Frame extends React.Component { | |||
// In this case both the user display and the user think they're on this.props.location. | |||
if (this.props.tabUrl !== this.props.location && | |||
!this.isAboutPage() && | |||
!isTorrentViewerURL(this.props.location)) { | |||
!isTorrentViewerURL(this.props.location) && | |||
!isIPFSPath(this.props.location)) { |
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.
I believe I got this code path right (it checks if location starts with dweb:
or ipfs://
), however, I never managed to get the log on 74
to print.
4e40ac2
to
9d4381a
Compare
js/ipfs/entry.js
Outdated
@@ -0,0 +1,3 @@ | |||
// const ipc = window.chrome.ipcRenderer | |||
|
|||
console.log('woot! managed to capture the ipfs:// or dweb:// protocols') |
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.
🌟 if I get this one to run, I believe I know what to do next :)
app/extensions.js
Outdated
if (getSetting(settings.IPFS_ENABLED)) { | ||
extensionInfo.setState(config.ipfsExtensionId, extensionStates.REGISTERED) | ||
loadExtension(config.ipfsExtensionId, getExtensionsPath('ipfs'), generateIPFSManifest(), 'component') | ||
} else { |
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.
I can confirm that getSetting(settings.IPFS_ENABLED))
prints true, which means that the extension should be loaded.
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.
Line 537 and 538 do nothing for some reason.
e6be4bc
to
4737315
Compare
app/extensions.js
Outdated
@@ -471,6 +531,17 @@ module.exports.init = () => { | |||
extensionActions.extensionDisabled(config.torrentExtensionId) | |||
} | |||
|
|||
// ipfsExtension | |||
const isIPFSEnabled = getSetting(settings.IPFS_ENABLED) | |||
console.log('IPFS: is extension enabled', isIPFSEnabled, config.ipfsExtensionId, getExtensionsPath('ipfs')) |
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 prints:
IPFS: is extension enabled true interplanetaryfilesystemuniverse /Users/koruza/code/brave-browser-laptop/app/extensions/ipfs
@jonathansampson @bridiver @NejcZdovc mind taking a look at what I might be failing when loading this extension? |
app/extensions.js
Outdated
// Returns the Chromium extension manifest for the ipfsExtension | ||
// The ipfsExtension handles ipfs:// and dweb: | ||
// Analagous to the PDFJS extension, it shows a special UI for that type of resource | ||
let generateIPFSManifest = () => { |
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.
I don't think you need all this. You can just create a regular manifest file and pass the path to the directory like non-component extensions
@diasdavid I have not seen that issue before, but when I ran Tabby Cat in Brave, we didn't have the about:preferences#extensions page. Are you able to share any further information about the Exception itself? Perhaps file/line-number? You may even be able to break on exception from the Shift+F8 developer tools. Happy to help investigate further if needed. |
app/extensions/ipfs/js/main.js
Outdated
callback('hi there!' + test() + IPFS) // eslint-disable-line | ||
}) | ||
*/ | ||
callback('hi there!' + test() + IPFS) // eslint-disable-line |
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.
I'm being unable to create an IPFS node as the background process crashes (for some reason) and I have no way to inspect it. Looking for a better way to debug this background extension.
a3a481b
to
6ea5fdf
Compare
@@ -45,7 +45,8 @@ | |||
"watch-all": "npm run watch & npm run watch-test", | |||
"watch-test": "cross-env NODE_ENV=test webpack --watch", | |||
"webpack": "webpack", | |||
"win-renpm": "powershell ./tools/windows/re-npm.ps1" | |||
"win-renpm": "powershell ./tools/windows/re-npm.ps1", | |||
"ipfs": "wget https://unpkg.com/ipfs/dist/index.min.js -O app/extensions/ipfs/js/ipfs.min.js" |
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.
I added this step to make it simpler to reproduce my local set up.
Update - Great news everyone!We have successfully managed to run IPFS from a background process in a Brave Extension, capturing the The main issue we were facing was that the CSP was blocking our use of eval, which is exactly that @lidel while developing the Chrome and Firefox Web Extension with js-ipfs-api. For now, we removed that restriction for testing purposes but before we merge and release this feature, we want to:
|
Streaming Responses Issue brave#10629 |
app/extensions/brave/index-dev.html
Outdated
@@ -7,7 +7,7 @@ | |||
<!-- TODO: Don't allow img-src *, needed for favicons --> | |||
<!-- TODO: Refactor away all unsafe-inline content --> | |||
<!-- TODO: Replace suggestqueries.google.com and ac.duckduckgo.com and other search engines with a single config search engine --> | |||
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; form-action http://localhost:*; script-src 'self' http://localhost:*; connect-src 'self' https://s3.amazonaws.com/adblock-data/ https://s3.amazonaws.com/safe-browsing-data/ https://s3.amazonaws.com/tracking-protection-data/ https://s3.amazonaws.com/https-everywhere-data/ http://localhost:* ws://localhost:* https://suggestqueries.google.com https://ac.duckduckgo.com https://completion.amazon.com https://search.yahoo.com https://api.bing.com https://www.startpage.com https://infogalactic.com https://api.qwant.com https://ac.ecosia.org https://searx.me https://www.findx.com https://brave-download.global.ssl.fastly.net https://brave-laptop-updates.global.ssl.fastly.net https://brave-download.global.ssl.fastly.net https://laptop-updates-pre.brave.com https://brave-laptop-updates-pre.brave.com; style-src 'unsafe-inline'; font-src 'self' http://localhost:*; img-src 'self' * data: file: chrome-extension:; object-src 'self'; plugin-types application/browser-plugin"> | |||
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; form-action http://localhost:*; script-src 'self' 'unsafe-eval' http://localhost:*; connect-src 'self' https://s3.amazonaws.com/adblock-data/ https://s3.amazonaws.com/safe-browsing-data/ https://s3.amazonaws.com/tracking-protection-data/ https://s3.amazonaws.com/https-everywhere-data/ http://localhost:* ws://localhost:* https://suggestqueries.google.com https://ac.duckduckgo.com https://completion.amazon.com https://search.yahoo.com https://api.bing.com https://www.startpage.com https://infogalactic.com https://api.qwant.com https://ac.ecosia.org https://searx.me https://www.findx.com https://brave-download.global.ssl.fastly.net https://brave-laptop-updates.global.ssl.fastly.net https://brave-download.global.ssl.fastly.net https://laptop-updates-pre.brave.com https://brave-laptop-updates-pre.brave.com; style-src 'unsafe-inline'; font-src 'self' http://localhost:*; img-src 'self' * data: file: chrome-extension:; object-src 'self'; plugin-types application/browser-plugin"> |
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.
added the 'unsafe-eval'
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.
why is that needed? I think @diracdeltas will likely have an issue with it
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.
Unfortunately unsafe-eval
removes most of the purpose of having a CSP - please avoid it by refactoring all inline script code into external files.
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.
Removed it from here. It was not necessary
app/extensions/ipfs/ipfs.html
Outdated
wss://nyc-1.bootstrap.libp2p.io | ||
wss://nyc-2.bootstrap.libp2p.io | ||
; | ||
object-src 'self'; plugin-types application/browser-plugin"/> |
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.
In order to support a background page (and not just scripts) had to add manually all the endpoints a js-ipfs node connects on startup. This is a bit of annoyance as it will stop js-ipfs to connect dynamically to other public WebSockets endpoints unless the CSP can be relaxed.
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.
wss://*
?
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.
oh wow, it actually takes wildcards. I completely had discarded that option.
"page": "ipfs.html", | ||
"persistent": true | ||
}, | ||
"content_security_policy": "script-src 'self' 'unsafe-eval'" |
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.
I believe the csp you have defined in the page above can be defined here instead
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.
if the CSP is just for the IPFS extension, it should be defined here instead of in index-dev.html. i would still encourage refactoring such that unsafe-eval isn't needed.
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.
@bridiver when an extension has an index.html page, the extension loader ignores this CSP and applies the one in index.html. So yes, you are right, the index.html one is the only one necessary. My test yielded a false positive, it actually needs to have this in the manifest too.
@diracdeltas agreed that we should not have the need for unsafe-eval. We are working on it :)
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.
@diasdavid I think the latest version of js-ipfs-api is ready to be tested without evals :)
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.
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.
that is definitely still a protobuf thing
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.
looks like we missed two modules
npm ls protocol-buffers
ipfs@0.25.4 /Users/dignifiedquire/opensource/ipfs/js-ipfs
├─┬ libp2p-floodsub@0.11.0
│ └─┬ libp2p-crypto@0.9.4
│ └── protocol-buffers@3.2.1 deduped
└─┬ libp2p-kad-dht@0.5.0
└── protocol-buffers@3.2.1
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.
💡 So it is evident. Nice, I was worried that it was npm false deduping. Thanks for catching that!
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.
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.
🎉 🎉 🎉
Any updates here? Sounds like this is ready to go now that the eval issue is fixed. It would be nice to see this get merged into Brave and released. |
Yeah, I would love to see this too, have been waiting for a long time now 😅 |
Good news everyone! @alanshaw and @olizilla are coming to help us polish the last quirks here! \o/ You can expect more activity starting this week this week. Especially when it comes to the UX for the user, cleaning out any last bugs and following up on outstanding tasks such as the needed streaming API. @olizilla and @alanshaw welcome to this endeavor! Ping me through this thread or IRC if you have any questions! :) |
Just a few of notes:
|
} | ||
}) | ||
|
||
// TODO: bring back once brave supports registerURIHandlers |
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.
@diasdavid do you have any background info on why registerURIHandlers
is needed?
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.
because an IPFS hash is, in reality, a URI and not a URL, we should be able to do ipfs:QmHash
and not ipfs://QmHash
.
This is still an ongoing proposal, read more at:
Mh no, ipfs://QmHash is absolutely fine, and the URI variant is dweb:/ipfs/QmHash |
@lgierth i think @diasdavid is saying that in the context of this PR, the current impl can only do |
Notes to self (or others that might want to contribute :))
Folder structure