In rest api I’m using ed25519 encryption to create the signature but I get “Signature for this request is not valid”.
This is the code:
import * as fs from "fs";
import crypto from "crypto";
import axios from "axios";
const BASE_ENDPOINT = "https://api.binance.com/api";
const API_KEY = 'xxxxxxxxxxxxxxxxxxxxxxxxxx';
const PRIVATE_KEY = fs.readFileSync("./../private_key.pem", "utf-8");
const TIMESTAMP = Date.now();
const PARAMS = {
symbol: "BTCUSDT",
side: "buy",
type: "LIMIT",
quantity: 0.1,
price: 26000,
timestamp: TIMESTAMP,
};
const SIGNATURE = crypto.sign(null, Buffer.from(JSON.stringify(PARAMS)), {
key: PRIVATE_KEY,
padding: crypto.constants.RSA_PKCS1_PSS_PADDING,
saltLength: crypto.constants.RSA_PSS_SALTLEN_DIGEST
}).toString("base64");
const DATA = new URLSearchParams({ ...PARAMS, signature: SIGNATURE });
const RESPONSE = await axios({
url: `/v3/order/test`,
method: "post",
baseURL: BASE_ENDPOINT,
data: DATA,
headers: {
"X-MBX-APIKEY": API_KEY,
}
});