hirosystems / connect

A library for building excellent user experiences with Stacks.
https://connect.stacks.js.org
MIT License
76 stars 40 forks source link

[Connect] Error during auth request Error: Improperly formatted private-key. Private-key byte length should be 32 or 33. Length provided: 390 #321

Open himmelhargott opened 1 year ago

himmelhargott commented 1 year ago

Hello,

I hope this is a wallet issue, otherwise feel free to relocate, since I am somewhat at a loss.

I try to find out, why this message is happening: While developping a webapp locally, everthing went fine (as with parcel as with snowpack, tried both).

To connect to the app i use showConnect from @stacks/connect This opens the wallet extension, which I can unlock with the password. Then I can choose an account. When clicking on one, this error is in the browser console:

AuthRequestError

As long as i serve the project with parcel or snowpack on localhost, everything works fine. As soon as I build the project with either one of them the error occurs. If I omit the login, the rest oft the project works (except all that is linked to userData of course)

the import is done like so through the snowpack builder: import { showConnect } from "./_snowpack/pkg/@stacks/connect.js"; the webserver is nginx on a raspberryPi 4. The project has NO domain ONLY the internal IP of the raspPi (like 192.168.0.1) -> maybe thats the problem? If so, is there an easy way around that problem?

Hope very much that anyone can help me or show me a workaround, since I spent almost 2 month with learning and programming that app.

Many thanks in advance! Best Regards Stefan

markmhendrickson commented 1 year ago

@kyranjamie any initial ideas here?

kyranjamie commented 1 year ago

This is more an issue with connect, nothing is running in the wallet's context here.

Would be helpful to debug and see what the key is that's 390 length (but ofc that shouldn't be shared). Wonder if this is some snowpack bundling issue.

Transferring to Connect repo.

himmelhargott commented 1 year ago

Here is the repo:

with it it should be possible for you to recreate the error:

https://github.com/himmelhargott/prt.git

with npm start, serving locally with snowpack, there is no problem chosing an account in the wallet an logging in.

yet served on the raspPi4 with nginx (bundled with parcel or snowpack, tried both, both with the same error) I can choose an account and then get the above error.

I am somewhat desperate. Would appreciate very much if someone could look into it.

And thanks for the work done so far.

Best regards Stefan

janniks commented 1 year ago

This seems to be a build issue, likely unrelated to Stacks connect. Closing issue as unrelated...

~Are you serving the build directory via nginx?~ It works with npm run build and then npx serve build -- so the build step works, I believe. Likely a hosting related issue (maybe with the nginx config)

himmelhargott commented 1 year ago

Thank you very much for looking into it!

himmelhargott commented 1 year ago

follow up question:

since I am still stuck with the problem:

I did the same: cloned the repo from github, then npm run build and then npx serve build seems to work: npxServe

now with serving: I can choose local or network via link (see screenshot above) with local the programm works fine with network the same error occurs as mentioned above (now i am on the same machine, same bundler, same served files only once I connect over the locally served files, everything works, when i connect (without interruption or changing anything) via network the error ensues and i get back a key that is 390 characters long. Since I am not creating that key ( it s the response of a query to stacks, if I understand this correctly) I am not so sure if there isnt a bug on the serverside (stacks). I think what changes on my side is only the domain? - local http://localhost:3000/, network: http://192.168.178.23:3000/ could it be there is a problem with that? since the domain is used to generate the key?

did you try the same? did it work via network?

thanks for a quick update.

janniks commented 1 year ago

Can you try this link? https://n4yi3m-3000.csb.app/

himmelhargott commented 1 year ago

Yes, this works =)What did I miss?--Diese Nachricht wurde von meinem Android Mobiltelefon mit GMX Mail gesendet.Am 05.05.23, 3:19 PM schrieb janniks @.***>:

Can you try this link? https://n4yi3m-3000.csb.app/ —Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: @.***>

janniks commented 1 year ago

Hard to say, likely some weird install/version/build issue; might be something on the browser / extensions.

This codesandbox is forked from your reproduction repo: https://codesandbox.io/p/sandbox/competent-hellman-n4yi3m you might be able to work in a similar environment. Not sure how to best deploy to raspi

himmelhargott commented 1 year ago

Thank you very much!

For now I will try it like this. Since it is only for MVP its no big deal. And I dont think the final version is on a raspi.

Yet on a Windows machine, I had the same problem. Hopefully I will finally run it on a linux machine or vm and all will be fine =)

himmelhargott commented 1 year ago

As it looks to me the "problem" lies in not having a domain in document.location.href since as I understand it correctly this is used to generate the key. So in case of there is a IP address instead of a domain, there ensues the error (out of reasons unbeknownst to me)

As soon as the some code is served with a domain, everything works fine. Yet it s not so much of a bug since only the minority will want to test their app without a domain.

My solution up to now is to use tiiny.host to test the project. As such it is online as a normal website and this 24/7 for possible customers to test and play around.

Thank you very much for your cooperation.

Best regards S

janniks commented 1 year ago

Cool, thanks for the investigation! I’ll re-open so we fix this at some point 🙏🏻

himmelhargott commented 1 year ago

=) pleasure

though I would like to point out, that its only my best guess and a possible vector to investigate in. Not sure if its the real problem.

happy coding

MicaiahReid commented 1 month ago

@janniks I'm running into this issue as well.

We're providing a CLI tool that hosts a web server on the user's localhost. Whenever we bind to http://0.0.0.0:8545 and connect the wallet, we're getting this error.

However, if we bind to http://127.0.0.1:8545 or http://localhost:8545, we can successfully connect the wallet.

Any help here would be much appreciated 🙏