-
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?
Changes from all commits
a6d660c
3e82c59
08b4f38
4d2b5cc
4ca81cf
e248f2d
faa9afe
3952beb
f2a0df9
ca10910
bc43e50
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ipfs=Distributed Web |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="availableLanguages" content=""> | ||
<meta name="defaultLanguage" content="en-US"> | ||
<meta http-equiv="Content-Security-Policy" content=" | ||
default-src 'none'; | ||
form-action http://localhost:*; | ||
script-src 'self' 'unsafe-eval'; | ||
img-src * data: file: chrome-extension:; | ||
style-src 'self' 'unsafe-inline'; font-src 'self'; | ||
connect-src 'self' wss://* ; | ||
object-src 'self'; | ||
plugin-types application/browser-plugin" | ||
/> | ||
<meta name="referrer" content="no-referrer"> | ||
<title>IPFS</title> | ||
<script src="js/ipfs.min.js"></script> | ||
<script src="js/main.js"></script> | ||
<script src="js/some-other.js"></script> | ||
</head> | ||
<body> | ||
<h1>IPFS</h1> | ||
</body> | ||
</html> |
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* global Ipfs */ | ||
|
||
chrome.protocol.registerStringProtocol('ipfs', handler) | ||
|
||
const node = new Ipfs({ | ||
config: { | ||
Addresses: { | ||
Swarm: [] | ||
} | ||
} | ||
}) | ||
|
||
// TODO: bring back once brave supports registerURIHandlers | ||
// chrome.protocol.registerStringProtocol('dweb', handler) | ||
|
||
/* | ||
* request is an object with: | ||
* - method (e.g GET) | ||
* - referrer (always empty for now) | ||
* - url (full ipfs://<path>) | ||
* reply is a functin that takes one argument which is the response to the request | ||
*/ | ||
function handler (request, reply) { | ||
if (!node.isOnline()) { | ||
node.once('ready', () => handler(request, reply)) | ||
} | ||
|
||
const path = request.url.split('ipfs://')[1] | ||
|
||
// TODO check if it is valid IPFS Path | ||
// callback('hi there!' + test()) // eslint-disable-line | ||
|
||
// TODO here I need to check if it is a directory or a file: | ||
// if file load it | ||
// if directory fetch it and look for an index.html | ||
// if index.html load that | ||
// if no index.html, load the directory listing just like the gateway | ||
|
||
node.files.cat(path, (err, stream) => { | ||
if (err) { | ||
// TODO create a nice error page | ||
return reply('err: ' + err.message) | ||
} | ||
|
||
// TODO replace this by something like BL | ||
let buf = '' | ||
|
||
stream.on('data', (data) => { | ||
buf += data.toString() | ||
}) | ||
|
||
stream.on('end', () => reply(buf)) | ||
}) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
function test () { | ||
return 'yeeah' | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was a test to make sure I could in fact run a function from another file. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"manifest_version": 2, | ||
"name": "IPFS", | ||
"version": "0.1.0", | ||
"default_locale": "en", | ||
"description": "InterPlanetary FileSystem", | ||
"icons": { | ||
"128": "img/ipfs-128.png", | ||
"48": "img/ipfs-48.png", | ||
"16": "img/ipfs-16.png" | ||
}, | ||
"offline_enabled": true, | ||
"background": { | ||
"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 commentThe 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. @bridiver @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 commentThe 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 commentThe 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. looks like we missed two modules
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. 🎉 🎉 🎉 |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,6 +48,18 @@ module.exports.getTorrentExtUrl = function (relativeUrl) { | |
return 'chrome-extension://' + config.torrentExtensionId + '/' + relativeUrl | ||
} | ||
|
||
/** | ||
* Gets the URL of a page hosted by the ipfsExtension | ||
* Returns 'chrome-extension://<...>' | ||
*/ | ||
module.exports.getIpfsExtUrl = function (relativeUrl) { | ||
if (relativeUrl === undefined) { | ||
relativeUrl = '' | ||
} | ||
|
||
return 'chrome-extension://' + config.ipfsExtensionId + '/' + relativeUrl | ||
} | ||
|
||
module.exports.getExtensionsPath = function (extensionDir) { | ||
return (process.env.NODE_ENV !== 'development' && process.env.NODE_ENV !== 'test') | ||
// the path is different for release builds because extensions are not in the asar file | ||
|
@@ -210,6 +222,47 @@ module.exports.isTargetMagnetUrl = function (input) { | |
return !!module.exports.getSourceMagnetUrl(input) | ||
} | ||
|
||
/** | ||
* Obtains the target URL associated with a IPFS path | ||
* Returns null if the input is not a IPFS path | ||
* Example: getTargetIpfsPath('ipfs:/...') -> 'chrome-extension://<...>.html#/ipfs/...' | ||
*/ | ||
module.exports.getTargetIpfsPath = function (input) { | ||
if (!input.startsWith('ipfs://') && | ||
!input.startsWith('dweb:')) { | ||
return null | ||
} | ||
const url = module.exports.getIpfsExtUrl('ipfs.html') | ||
return [url, input].join('#') | ||
} | ||
|
||
/** | ||
* Obtains the source IPFS Path associated with a target URL | ||
* Returns null if the input is not the local URL for a IPFS Path | ||
* Example: getSourceIPFSPath('chrome-extension://<...>.html#/ipfs/...') -> 'ipfs:/:...' | ||
*/ | ||
module.exports.getSourceIPFSPath = function (input) { | ||
if (getBaseUrl(input) !== module.exports.getIpfsExtUrl('ipfs.html')) return null | ||
const url = decodeURIComponent(getHash(input)) | ||
return url | ||
} | ||
|
||
/** | ||
* Checks if the input looks like a magnet: URL | ||
* Example: isSourceIpfsPath('ipfs:/..') -> true | ||
*/ | ||
module.exports.isSourceIpfsPath = function (input) { | ||
return !!module.exports.getTargetIpfsPath(input) | ||
} | ||
|
||
/* | ||
* Checks if the input looks like the local URL for a IPFS Path | ||
* Example: isSourceIpfsPath('chrome-extension://<...>.html#/ipfs/') -> true | ||
*/ | ||
module.exports.isTargetIPFSPath = function (input) { | ||
return !!module.exports.getSourceIPFSPath(input) | ||
} | ||
|
||
/** | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This might be no longer necessary as we now capture the |
||
* Determines whether a string is a valid URL. Based on node-urlutil.js. | ||
* @param {string} input | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe 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. |
||
}, | ||
"repository": "brave/browser-laptop", | ||
"author": { | ||
|
@@ -148,6 +149,7 @@ | |
"electron-chromedriver": "^1.7.1", | ||
"electron-packager": "brave/electron-packager", | ||
"electron-prebuilt": "brave/electron-prebuilt", | ||
"electron-rebuild": "^1.5.11", | ||
"empty-port": "0.0.2", | ||
"enzyme": "^2.9.1", | ||
"flow-bin": "^0.22.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.
@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 notipfs://QmHash
.This is still an ongoing proposal, read more at: