dao-xyz / peerbit-examples

Example library for learning and fun
Apache License 2.0
7 stars 3 forks source link

@peerbit/react -- Error occurred during XX handshake: ciphertext cannot be decrypted using that key #6

Closed Azaeres closed 10 months ago

Azaeres commented 10 months ago

I have a Next.js app in which I'm trying to use PeerProvider from @peerbit/react, like so: https://github.com/Azaeres/etherion-lab/blob/main/src/components/scenes/Experiment4/index.tsx

'use client'
import { PeerProvider } from '@peerbit/react'

export default function Experiment4() {
  console.log('Experiment4 render  :')
  return (
    <PeerProvider network="remote">
      <></>
    </PeerProvider>
  )
}

However, I'm getting the error "Failed to resolve relay addresses. Error: Error occurred during XX handshake: ciphertext cannot be decrypted using that key".

Live demo of error can be found here: https://lab.etherion.app/experiment4

When I try to provide my own keypair, Peerbit sees it as invalid. It looks like there are a few different defined Ed25519Keypair classes in the Next.js bundle, and Peerbit's instanceof check fails when there's a class reference mismatch. I've also tried creating a keypair using @peerbit/react's getKeypair() function, but Peerbit also sees it as invalid. Not sure if this is related to the "XX handshake" error.

In another, separate area, I've successfully created my own peer by borrowing bits of @peerbit/react. You can see this in a live demo at: https://lab.etherion.app/experiment3

The peer creation code I got to work can be found here: https://github.com/Azaeres/etherion-lab/blob/main/src/components/scenes/Experiment3/hooks/usePeerbitDatabase.ts

marcus-pousette commented 10 months ago

Interestingly

https://lab.etherion.app/experiment4

Worked once for me. Then next time I tried it I got the problem. I wonder if there is some caching going on..

Anyway.

https://github.com/Azaeres/etherion-lab/blob/c7d9864e42c86c26c7a8bbb3c1d824d600dd8662/yarn.lock#L7998C12-L7998C12

Looks like you have a old version of Peerbit lurking around. Can you see if you can bump all Peerbit related dependencies.

Most importantly

https://github.com/Azaeres/etherion-lab/blob/c7d9864e42c86c26c7a8bbb3c1d824d600dd8662/yarn.lock#L1577

this one should not exist in the lock file but only the 13^ one

marcus-pousette commented 10 months ago

Super cool that your are creating multiplayer (?) a space shooter game with Peerbit. Could feature it/link it from this repo if you want later

Azaeres commented 10 months ago

Okay, thank you for the tip on what to dig into!

@peerbit/react@0.0.4 off of NPM is asking for @libp2p/webrtc@^2.0.11, which is in turn asking for @chainsafe/libp2p-noise@^12.0.0. If I uninstall @peerbit/react, version 12 of libp2p-noise goes away.

However, I see that react-utils in the peerbit-examples is asking for @libp2p/webrtc@^3.1.9. See https://github.com/dao-xyz/peerbit-examples/blob/fe1729f1268c5b29fb61b59611e460d553ed3180/packages/react-utils/package.json#L28

If you're publishing this react-utils folder to NPM, maybe it's time to publish an update?

Super cool that your are creating multiplayer (?) a space shooter game with Peerbit. Could feature it/link it from this repo if you want later

Yeah, that's the idea! Would love for this to come together. Thanks again for your help.

marcus-pousette commented 10 months ago

Well it is more the

@dao-xyz/libp2p-noise@^12.0.0

noise implementation, that had a bug which yields your error message.

If you somehow manage to get rid of peerbit v1 dependency https://github.com/Azaeres/etherion-lab/blob/c7d9864e42c86c26c7a8bbb3c1d824d600dd8662/yarn.lock#L7998C12-L7998C12

and only use peerbit v2 I think your problems will be gone.

I have not actually used @peerbit/react in a separate repo yet. Been building it along side all the examples to reach a good API in the end, and I can see that there are a few dependencies there that perhaps needs to be removed or updated (however it should not affect your problem)

Azaeres commented 10 months ago

These are the listed dependencies of the @peerbit/react I grabbed off of NPM.

    "dependencies": {
        "@emotion/react": "^11.10.5",
        "@emotion/styled": "^11.10.5",
        "@libp2p/webrtc": "^2.0.11",
        "@mui/icons-material": "^5.10.16",
        "@mui/material": "^5.10.13",
        "@peerbit/proxy-window": "^1.0.1",
        "@types/react": "^18.0.25",
        "@types/react-dom": "^18.0.8",
        "path-browserify": "^1.0.1",
        "peerbit": "^1",
        "react": "^18.2.0",
        "react-dom": "^18.2.0",
        "react-router-dom": "^6.8.0",
        "react-use": "^17.4.0"
    },

I think that's where the peerbit@^1 is coming from, which explains why the @dao-xyz/libp2p-noise@^12.0.0 disappears when I uninstall @peerbit/react.

marcus-pousette commented 10 months ago

Ah! I see, this CI in github does not automatically release stuff in this repo.

Just relased

@peerbit/react@0.0.5

now. Try it out !

Azaeres commented 10 months ago

Nice! No longer getting the XX handshake error!

I've got a bunch of these "'Recieved hello message that did not verify. Header: false, Ping info true, Signatures false'" warnings, though. Does this mean I haven't configured something correctly?

image

Edit: And now that production's deployed I see a "Websocket connection failed" error.

image

Another edit: Never mind, I was looking at Experiment 3 when I thought I was looking at Experiment 4.

marcus-pousette commented 10 months ago

Great! No you don't have to worry about that error.

There is non-optimal logging now.

The warning and error messages should be gone when this issue is fixed.

The 87ecf9778ccaa08bd9f1e8c6104d82c469b35511.peerchecker.com address is not part of the bootstrapping nodes. And that server is down. But this should not affect your stuff running. The error messages you see are basically just the autodialer failing to establish connections