Skip to content
This repository has been archived by the owner on Jun 26, 2023. It is now read-only.

feat: crypto interface #2

Merged
merged 4 commits into from
Oct 21, 2019
Merged

feat: crypto interface #2

merged 4 commits into from
Oct 21, 2019

Conversation

jacobheun
Copy link
Contributor

@jacobheun jacobheun commented Oct 20, 2019

This adds a crypto interface to js libp2p, we currently don't have one. This also includes a mock crypto file for tests, which demonstrates how a crypto module might be built, including a handshake and stream wrapping which can be used for crypto boxing/unboxing.

Aside from the clear change to async iterables, this also updates the "existing" interface to use the protocol property instead of tag to be clearer about its purpose.

I added the iterable wrapper logic to the js-libp2p docs in a PR, in case it's useful to others libp2p/js-libp2p#466


> A test suite you can use to implement a libp2p crypto module. A libp2p crypto module is used to ensure all exchanged data between two peers is encrypted.

**Modules that implement the interface**
Copy link
Member

@mkg20001 mkg20001 Oct 20, 2019

Choose a reason for hiding this comment

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

Is plaintext not going to be a module?

Edit: It would be useful to have it as one, so people who want to experiment with it can simply add it like "just another crypto module"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that's the intent, I'm planning on writing that and the private network refactor this week. I was planning on just bundling plaintext 2 with libp2p though, and linking to it here.

Copy link
Member

Choose a reason for hiding this comment

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

Ok, perfect. I'll keep this discussion open until that's resolved for tracking.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I also created #3 to track adding plaintext.

src/crypto/README.md Outdated Show resolved Hide resolved
src/crypto/README.md Outdated Show resolved Hide resolved
@jacobheun
Copy link
Contributor Author

I've updated the docs and added a test for the expected remotePeer on an inbound connection. I also added an errors export with an UnexpectedPeerError as an initial value. We can add to this as we determine other, common errors crypto modules should throw.

Copy link
Member

@vasco-santos vasco-santos left a comment

Choose a reason for hiding this comment

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

LGTM!

Just found a small typo

src/crypto/README.md Outdated Show resolved Hide resolved
Copy link
Member

@mkg20001 mkg20001 left a comment

Choose a reason for hiding this comment

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

LGTM

@mkg20001
Copy link
Member

I assume that with js-interfaces now being a thing, interface-connection is no longer needed and the functions return "just streams"
Is that correct?

Co-Authored-By: Vasco Santos <vasco.santos@moxy.studio>
@jacobheun
Copy link
Contributor Author

I assume that with js-interfaces now being a thing, interface-connection is no longer needed and the functions return "just streams"
Is that correct?

Yes, that's correct. Now when you dial in libp2p the Connection object is not created until just before the dial returns. It's now basically just a metadata/convenience wrapper around the muxer and transport connection (MultiaddrConnection).

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.

3 participants