package com.binance.connector.client.utils.signaturegenerator;

import com.binance.connector.client.utils.ParameterChecker;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.security.Security;
import java.util.Base64;
import org.bouncycastle.crypto.params.Ed25519PrivateKeyParameters;
import org.bouncycastle.crypto.signers.Ed25519Signer;
import org.bouncycastle.crypto.util.PrivateKeyFactory;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.bouncycastle.util.io.pem.PemReader;

/* loaded from: binance-connector-java-3.0.0rc3.jar:com/binance/connector/client/utils/signaturegenerator/Ed25519SignatureGenerator.class */
public final class Ed25519SignatureGenerator implements SignatureGenerator {
    private Ed25519PrivateKeyParameters privateKey;
    private final int offset = 0;

    public Ed25519SignatureGenerator(String privateKey) throws FileNotFoundException, IOException {
        ParameterChecker.checkParameterType(privateKey, String.class, "privateKey");
        Security.addProvider(new BouncyCastleProvider());
        PemReader pemReader = new PemReader(new FileReader(privateKey));
        this.privateKey = (Ed25519PrivateKeyParameters) PrivateKeyFactory.createKey(pemReader.readPemObject().getContent());
        pemReader.close();
    }

    @Override // com.binance.connector.client.utils.signaturegenerator.SignatureGenerator
    public String getSignature(String data) {
        byte[] dataBytes = data.getBytes(StandardCharsets.UTF_8);
        Ed25519Signer signer = new Ed25519Signer();
        signer.init(true, this.privateKey);
        signer.update(dataBytes, 0, dataBytes.length);
        return Base64.getEncoder().encodeToString(signer.generateSignature());
    }
}
