Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Awesome Async Crypto + Less magic to 'run in the browser' #485

Merged
merged 22 commits into from
Nov 12, 2016
Merged

Conversation

dignifiedquire
Copy link
Member

@dignifiedquire dignifiedquire commented Sep 13, 2016

These are the changes that needed to bubble up from deep down in libp2p-crypto and multihashing.

This reduces the size of the browser build down to 2.4M and 1.2M unminified and minified respectively.

Associated PRs that need to be merged and shipped before this can get merged are

PR Next Aegir CR Sauce Credentials  RFM M
libp2p/js-libp2p-crypto#12 ✔️ ✔️ ✔️ ✔️ ✔️
multiformats/js-multihashing-async#1 ✔️ ✔️ ✔️ ✔️ ✔️
libp2p/js-peer-id#33 ✔️ ✔️ ✔️ ✔️ ✔️
libp2p/js-peer-info#22 ✔️ ✔️ ✔️ ✔️ ✔️
libp2p/js-libp2p-identify#6 ✔️ ✔️ ✔️ ✔️ ✔️
libp2p/js-libp2p-switch#108 ✔️ ✔️ ✔️ ✔️ ✔️
libp2p/js-libp2p-secio#19 ✔️ ✔️ ✔️ ✔️ ✔️
libp2p/js-libp2p-webrtc-star#27 ✔️ ✔️ ✔️ ✔️ ✔️
ipfs-inactive/js-libp2p-ipfs-nodejs#24 ✔️ ✔️ N/A ✔️ ✔️
ipfs-inactive/js-libp2p-ipfs-browser#99 ✔️ ✔️ ✔️ ✔️ ✔️
ipld/js-ipld-block#4 ✔️ ✔️ ✔️ ✔️ ✔️
ipfs/js-ipfs-repo#88 ✔️ ✔️ ✔️ ✔️ ✔️
ipfs-inactive/interface-js-ipfs-core#82 ✔️ ✔️ N/A ✔️ ✔️
ipfs-inactive/js-ipfs-http-client#390 ✔️ ✔️ ✔️ ✔️ ✔️
ipld/js-ipld-dag-pb#3 ✔️ ✔️ ✔️ ✔️ ✔️
ipld/js-ipld-dag-cbor#28 ✔️ ✔️ ✔️ ✔️ ✔️
ipfs/js-ipfs-unixfs#12 ✔️ ✔️ ✔️ ✔️ ✔️
ipfs/js-ipfs-bitswap#41 ✔️ ✔️ ✔️ ✔️ ✔️
multiformats/js-cid#5 ✔️ ✔️ ✔️ ✔️ ✔️
ipfs/js-ipfs-block-service#35 ✔️ ✔️ ✔️ ✔️ ✔️
libp2p/interface-connection#19 ✔️ ✔️ N/A ✔️ ✔️
libp2p/js-libp2p-spdy#36 ✔️ ✔️ ✔️ ✔️ ✔️
libp2p/js-libp2p-tcp#40 ✔️ ✔️ N/A ✔️ ✔️
ipfs-inactive/js-ipfs-unixfs-engine#82 ✔️ ✔️ ✔️ ✔️  ✔️
libp2p/js-libp2p-websockets#33 ✔️ ✔️ ✔️  ✔️  ✔️
ipld/js-ipld#65 ✔️ ✔️ ✔️ ✔️  ✔️
multiformats/js-multistream-select#25 ✔️ ✔️ ✔️ ✔️ ✔️
#485 ✔️ ✔️ ✔️ ✔️ ✔️
ipfs/aegir#66 ✔️ ✔️ N/A ✔️  ✔️

TODOs

@daviddias
Copy link
Member

awesome! :D

remember: if > half a day :)

@dignifiedquire dignifiedquire changed the title [WIP] refactor: use async crypto refactor: use async crypto Sep 15, 2016
@dignifiedquire
Copy link
Member Author

@diasdavid ready for review

@daviddias
Copy link
Member

@dignifiedquire will defer my review until there are good benchmarks. Thank you for pushing this! :)

@dignifiedquire
Copy link
Member Author

Doing more work on this, so not ready anymore ;)

@dignifiedquire
Copy link
Member Author

@diasdavid tests are passing locally for node, so you can start reviewing :)

@dignifiedquire dignifiedquire changed the title refactor: use async crypto feat: webcrypto and improved browser compatability Oct 3, 2016
@dignifiedquire
Copy link
Member Author

Added new todo

@nikuda
Copy link

nikuda commented Oct 3, 2016

Should ipfs-bitswap be on the above list too?

https://github.com/ipfs/js-ipfs-bitswap/tree/webcrypto

@dignifiedquire
Copy link
Member Author

@nikuda yes it should :D

@nikuda
Copy link

nikuda commented Oct 3, 2016

Proto files buffer to string progress:

@dignifiedquire
Copy link
Member Author

@nikuda awesome, thank you

@daviddias
Copy link
Member

From IRC

 <dignifiedquire> daviddias: good that you didn't review today :D I realised earlier that I hadn't tested the full down interop and had to fix some more issues, but now all is good and 💯 interop is back

Glad that I mentioned that several times :) Have you added CI tests to guarantee that interop remains? What were the tests you performed to verify?

@dignifiedquire
Copy link
Member Author

Glad that I mentioned that several times :) Have you added CI tests to guarantee that interop remains? What were the tests you performed to verify?

This interop are the tests you wanted to create scripts for. I just start a go and js node manually and connect them manually.

There are a lot of tests to verify that we interop with go on libp2p-crypto already if you look at the tests there. But for the full integration test we need a full go-ipfs node from master that works

@daviddias
Copy link
Member

@dignifiedquire reviewed a bunch of this PR. ipfs-block needs some changes that will cascade to to the remaining PRs that I haven't finalized reviewing (i.e removed the 'needs review label')

@daviddias daviddias changed the title feat: webcrypto and improved browser compatability feat: Move to Async Crypto + Less magic to 'run in the browser' Oct 12, 2016
@daviddias
Copy link
Member

Important to handle before moving forward with this PR - libp2p/js-libp2p-crypto#18

@dignifiedquire
Copy link
Member Author

Now that the changes have happened we need to update https://github.com/ipfs/community/blob/master/js-project-guidelines.md accordingly

@dignifiedquire
Copy link
Member Author

Unblocked with libp2p/js-libp2p-crypto#29

@dignifiedquire
Copy link
Member Author

All dependencies were merged and released, doing the last updates now 🎉

@dignifiedquire
Copy link
Member Author

@diasdavid can I get some last review on this?

@daviddias
Copy link
Member

@dignifiedquire all CI is failing, is that what you are expecting?

"libp2p-ipfs": "libp2p-ipfs-browser",
"./src/core/default-repo.js": "./src/core/default-repo-browser.js",
"./src/core/components/init-assets.js": false,
"fs-pull-blob-store": false,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to be reviewed

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need it as it is used in the tests, and does no harm otherwise

? argv.key
: new Buffer(bs58.decode(argv.key))
: mh.fromB58String(argv.key)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, does this still apply? we have standardised the block API

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, tests will fail otherwise

const mh = new Buffer(bs58.decode(argv.key))

ipfs.block.del(mh, (err) => {
ipfs.block.del(mh.fromB58String(argv.key), (err) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

block.del should support multihash as strings

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's exactly what I'm doing here, decoding the multihash from a string

(cb) => utils.getIPFS(cb),
(ipfs, cb) => ipfs.object.get(argv.key, {enc: 'base58'}, cb),
(node, cb) => node.toJSON(cb)
], (err, res) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/res/nodeJSON

(cb) => utils.getIPFS(cb),
(ipfs, cb) => ipfs.object.new(cb),
(node, cb) => node.toJSON(cb)
], (err, node) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/node/nodeJSON

waterfall([
(cb) => ipfs.object.get(key, cb),
(node, cb) => node.toJSON(cb)
], (err, res) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/res/nodeJSON

waterfall([
(cb) => ipfs.object.patch.setData(key, data, cb),
(node, cb) => node.toJSON(cb)
], (err, res) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/res/nodeJSON/g

},
(link, cb) => ipfs.object.patch.addLink(root, link, cb),
(node, cb) => node.toJSON(cb)
], (err, res) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/res/nodeJSON/g

waterfall([
(cb) => ipfs.object.patch.rmLink(root, link, cb),
(node, cb) => node.toJSON(cb)
], (err, res) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/res/nodeJSON

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems overly verbose, and I really dislike all caps naming. Not sure about a better name

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, toJSON is also JSON all caps

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because apis in JavaScript are note very consistent when it comes to naming :/

require('./test-files')
require('./test-generic')
require('./test-init')
require('./test-object')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@dignifiedquire
Copy link
Member Author

@dignifiedquire all CI is failing, is that what you are expecting?

yes, waiting for the bitswap PR I pinged you about

@daviddias
Copy link
Member

@dignifiedquire there you go ipfs/js-ipfs-bitswap#67

@dignifiedquire
Copy link
Member Author

CI is finally green, browsers are not perfect atm, most are failing due to one or the other issue

Firefox fails with this

Firefox 49.0.0 (Linux 0.0.0) ERROR
  SyntaxError: missing = in const declaration
  at webpack:///~/cbor/lib/encoder.js:383:0 <- test/browser.js:41233

though this code runs fine in Chrome.

@diasdavid if you are happy with the code please merge and ship at your earliest convenience, and I will investigate and fix various browser related issues next week.

@daviddias daviddias merged commit 219ef2c into master Nov 12, 2016
@daviddias daviddias deleted the fast-keys branch November 12, 2016 03:18
@daviddias daviddias removed the status/in-progress In progress label Nov 12, 2016
@daviddias
Copy link
Member

🎉 🎉 🎉 🎉 🎉 🎉 🎉 🎉 🎉 🎉 🎉 🎉 🎉 🎉 🎉 🎉 🎉 🎉 🎉 🎉 🎉

@daviddias daviddias changed the title Async Crypto + Less magic to 'run in the browser' Awesome Async Crypto + Less magic to 'run in the browser' Nov 22, 2016
MicrowaveDev pushed a commit to galtproject/js-ipfs that referenced this pull request May 22, 2020
* chore(package): update aegir to version 19.0.3

Closes ipfs#480

* fix: appease linter

License: MIT
Signed-off-by: Alan Shaw <alan.shaw@protocol.ai>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants