Auth
We use the secp256k1 signature algorithm with the Private Key as the app_secret to sign the string to be signed.
Java code 【secp256k1 signature algorithm】
import org.web3j.crypto.Credentials;
import org.web3j.crypto.Sign;
import org.web3j.utils.Numeric;
import java.nio.charset.StandardCharsets;
public class CryptoUtils {
public static String createSign(String message, String privateKey) {
Credentials credentials = Credentials.create(privateKey);
byte[] hash = message.getBytes(StandardCharsets.UTF_8);
Sign.SignatureData signatureData = Sign.signPrefixedMessage(hash, credentials.getEcKeyPair());
String r = Numeric.toHexString(signatureData.getR());
String s = Numeric.toHexString(signatureData.getS()).substring(2);
String v = Numeric.toHexString(signatureData.getV()).substring(2);
return r + s + v;
}
}⚠️ Special Note: All signatures here are in string format.
Strings to be signed
The string to be signed does not include the data of the signature field;
If there are spaces in the parameters, the spaces will also be included in the signature;
For JSON request bodies, convert to a JSON format string for signing;
For URL parameter requests, directly convert to a string for signing
Last updated