tiagosiebler / binance

Node.js & JavaScript SDK for Binance REST APIs & WebSockets, with TypeScript & browser support, integration tests, beautification & more.
MIT License
747 stars 266 forks source link

Add support for RSA keys #284

Closed tiagosiebler closed 1 year ago

tiagosiebler commented 1 year ago

https://binance-docs.github.io/apidocs/spot/en/#signed-trade-user_data-and-margin-endpoint-security https://www.binance.com/en/support/faq/how-to-generate-an-rsa-key-pair-to-send-api-requests-on-binance-2b79728f331e43079b27440d9d15c5db

posman commented 1 year ago

Need some help on how to correctly assign the RSA key

I generated the public and private key, added the public key in binance. But I keep getting errors like "Invalid character in header content ["X-MBX-APIKEY"]" "API-key format invalid"

I've tried to assign the value in environment variables and load them with "process.env". Tried removing newlines to convert key to a single line. Also tried to replace newline with text "\n". I've also assigned the keys directly in the code.

Maybe it's something very simple but iI can figure it out .

tiagosiebler commented 1 year ago

Need some help on how to correctly assign the RSA key

I generated the public and private key, added the public key in binance. But I keep getting errors like "Invalid character in header content ["X-MBX-APIKEY"]" "API-key format invalid"

I've tried to assign the value in environment variables and load them with "process.env". Tried removing newlines to convert key to a single line. Also tried to replace newline with text "\n". I've also assigned the keys directly in the code.

Maybe it's something very simple but iI can figure it out .

Hi @posman - does your private key by any chance have this as the header?

-----BEGIN RSA PRIVATE KEY-----

Or how does the header look? There's an assumption right now in how the RSA auth works, I'll adapt it slightly, as well as providing an example.

tiagosiebler commented 1 year ago

@posman here's a full example for RSA authentication using this SDK: https://github.com/tiagosiebler/binance/blob/master/examples/rest-private-rsa.md

If you have any problems with it, please open another issue. Thanks!