-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Browser support #2
Comments
Yeah, the hard part is getting all the hyperswarm features into the browser. I've got hyperswarm-web working, mostly, but it's missing the connection deduplication code. Try using webpack to compile your project, but replacing |
@RangerMauve thanks for the quick reply! Yeah -- actually none of the hyperswarm specific stuff is an issue wrt to using in the browser. I had aliased your |
Ah, yes. I think this is the same issue we had in dat-sdk, try checking out the webpack config there which replaced sodium-native with a fork by Geut. That should hopefully work. |
That got it further along. I had to make some modifications to const toHex = buff => {
if (typeof buff === 'string') {
return buff;
}
// this is new, previous Buffer.isBuffer would fail with a `uint8array`
// being passed here via noisePeer.keygen();
if (buff && buff.buffer) {
const str = Buffer.from(buff.buffer).toString('hex');
return str;
}
throw new Error('Cannot convert the buffer to hex: ', buff);
}; |
I think @mafintosh or @martinheidegger recently mentioned that sodium-javascript got updated with the missing crypto functions. Maybe it'd make sense to try using that instead of the @geut fork? |
I think the |
See here -> https://github.com/aulneau/p2plex-next.js Had to change this: https://github.com/aulneau/p2plex-next.js/blob/master/vendor/discovery-swarm-webrtc/lib/utils.js#L6-L9 to accept the buffer correctly. The next error which I have a screenshot above is linked to this line of I feel like it's related to buffer and not using the right one, or something along the lines of that. |
Hmm, is |
It is a |
Cool, I think it's a Buffer when running in Node.js, so it'd be good to convert it to a buffer inside the key generation in p2plex. That's probably what's causing all these weird issues. Try changing the get publicKey () {
return Buffer.from(this.keyPair.publicKey)
} |
I think for that we need to add some stubbed methods for the This info object is defined here: https://github.com/RangerMauve/hyperswarm-web/blob/master/index.js#L53 I think I've stubbed out the deduplicate method in hyperswarm-proxy already: https://github.com/RangerMauve/hyperswarm-proxy/blob/master/client.js#L191 |
Actually, I'm not sure why that might be happening. Is there a stack trace you could post? |
It could be that we need to change |
yep, this seems to be making it work. get keyPair() {
const _keypair = this.opts.keyPair || noisePeer.keygen();
return {
publicKey: Buffer.from(_keypair.publicKey),
secretKey: Buffer.from(_keypair.secretKey),
};
} Running this const plex1 = p2plex()
const plex2 = p2plex()
plex1.on('connection', (peer) => {
peer.receiveStream('example').on('data', (data) => {
console.log('Got data from', peer.publicKey, ':', data.toString('utf8'))
plex1.destroy()
plex2.destroy()
})
})
plex2.findByPublicKey(plex1.publicKey).then((peer) => {
peer.createStream('example').end('Hello World!')
}) Does not seem to cause any data console logs though. Additionally, the default wss server is down -> |
Dang. 🤔 Are WebRTC connections not going through, do you think? |
I'll have to play around with it more, seems like things are happening via the wss connection: You've been so helpful, thank you. I wonder if you'd be open to help out getting my mental model of how this could function within my app? It's a decentralized document editor built with blockstack auth and storage. I think I'll have to generate the keypairs that this uses for each user, and persist that, and then when they enter a document they would do something along the lines of |
Since the last release |
@aulneau That sounds like a good plan TBH. 😁 p2plex will also be handy got multiplexing across documents and stuff. By the way, would you be down to submit a PR with whatever changes you added to hyperswarm-web / p2plex that made things work for you? |
I have found another issue unfortunately, this time related to the use of Best |
Could the upgrade of noise-peer have affected this? Try using the older version and see if that helps. |
Could it be that upgrade is required for compatibility? |
Nah, it was the next issue regardless of version bump. Seems like noise-peer has used secretstream for a long time. I don't really know the difference between |
Jeeze, yeah I have no clue. 😅 I'm also down for switching the encryption layer with whatever works instead. |
@aulneau worth opening an issue and pinging emilbayes or tinchoz |
@RangerMauve would this possibly work? https://github.com/paulmillr/noble-secp256k1 |
@aulneau It doesn't look like that library supports streaming encryption, but otherwise it looks good enough. 🤷 |
It would be cool to have this working in a browser 🚀 |
This is such a cool project! I started playing around with implementing this in a next.js react application, but found that certain dependencies don't really work in the context of a browser. Do you have any ideas on how to replicate or replace certain libs in this package to work universally?
Thanks!
The text was updated successfully, but these errors were encountered: