From 96b8f613ca1ad867ea4574a63fde467316e62f7c Mon Sep 17 00:00:00 2001 From: harbourlark Date: Tue, 1 Dec 2026 16:02:03 +0000 Subject: [PATCH] docs(binance): show Ed25519 PEM keys in the API key guide Add a short section and example that load a self-generated Ed25519 private key from a file and pass the PEM as api_secret. --- sdks/binance/docs/guides/api-key.md | 10 ++++++++++ sdks/binance/examples/ed25519-client.ts | 13 +++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 sdks/binance/examples/ed25519-client.ts diff --git a/sdks/binance/docs/guides/api-key.md b/sdks/binance/docs/guides/api-key.md index 7cec4726..bffc90e1 100644 --- a/sdks/binance/docs/guides/api-key.md +++ b/sdks/binance/docs/guides/api-key.md @@ -37,6 +37,16 @@ node --env-file=.env account.mjs A successful request prints `Account access verified.` and the number of returned balances. See [`getAccountInformation()`](/api/classes/MainClient#getaccountinformation) and [Error handling](/guides/errors) if the request fails. +## Ed25519 keys + +Binance also accepts a self-generated Ed25519 key. In API Management, choose a self-generated key, register the public key, and keep the private key PEM on the server. + +Pass the PEM contents as `api_secret`. The SDK recognises an Ed25519 or RSA private key from the PEM and signs with it. Load the key from a file so the PEM stays out of `.env`: + +<<< @/../examples/ed25519-client.ts + +The same `api_secret` option works on `USDMClient`, `WebsocketClient` and `WebsocketAPIClient`. `session.logon` on the WebSocket API uses an Ed25519 key. + ## Testnet and demo keys - Spot Testnet: create the key at [Spot Testnet](https://testnet.binance.vision/) and set `testnet: true` on `MainClient` and any Spot WebSocket clients. See [Spot Testnet](/guides/testing-environments#spot-testnet). diff --git a/sdks/binance/examples/ed25519-client.ts b/sdks/binance/examples/ed25519-client.ts new file mode 100644 index 00000000..8be98616 --- /dev/null +++ b/sdks/binance/examples/ed25519-client.ts @@ -0,0 +1,13 @@ +import { readFileSync } from 'node:fs'; +import { MainClient } from 'binance'; + +const api_key = process.env.BINANCE_API_KEY; +const secretPath = process.env.BINANCE_API_SECRET_PATH; +if (!api_key || !secretPath) { + throw new Error('Set BINANCE_API_KEY and BINANCE_API_SECRET_PATH.'); +} + +export const client = new MainClient({ + api_key, + api_secret: readFileSync(secretPath, 'utf8'), +});