JAVA
Initiate Withdrawal
import com.fasterxml.jackson.databind.ObjectMapper;
import okhttp3.*;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import java.nio.charset.StandardCharsets;
import java.security.*;
import java.security.spec.PKCS8EncodedKeySpec;
import java.util.Base64;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
public class InitiateWithdrawal {
private static final String PRIVATE_KEY = "YOUR_PRIVATE_KEY_HERE"; // Replace with your RSA private key
public static void main(String[] args) throws Exception {
Security.addProvider(new BouncyCastleProvider());
Map<String, Object> data = new HashMap<>();
data.put("chain", "tron");
data.put("symbol", "trx");
data.put("address", "TJCBzku1S8TPTgyyk3Ja4kepk1BFDQAVq1");
data.put("amount", 1);
data.put("nonce", makeId(10));
data.put("timestamp", System.currentTimeMillis() / 1000);
String jsonData = new ObjectMapper().writeValueAsString(data);
String hash = rsaEncrypt(jsonData);
Map<String, Object> postData = new HashMap<>();
postData.put("merchant_id", "xxxx-xxxx-xxxx-xxxx");
postData.put("hash", hash);
postData.put("data", data);
sendPostRequest("https://payment.hyperhashing.com/v1/token/withdraw", postData);
}
private static String rsaEncrypt(String data) throws Exception {
byte[] privateKeyBytes = Base64.getDecoder().decode(PRIVATE_KEY);
PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(privateKeyBytes);
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
PrivateKey privateKey = keyFactory.generatePrivate(keySpec);
Signature signature = Signature.getInstance("SHA256withRSA");
signature.initSign(privateKey);
signature.update(data.getBytes(StandardCharsets.UTF_8));
return Base64.getEncoder().encodeToString(signature.sign());
}
private static String makeId(int length) {
String characters = "abcdefghijklmnopqrstuvwxyz0123456789";
Random random = new Random();
StringBuilder result = new StringBuilder(length);
for (int i = 0; i < length; i++) {
result.append(characters.charAt(random.nextInt(characters.length())));
}
return result.toString();
}
private static void sendPostRequest(String url, Map<String, Object> postData) throws Exception {
ObjectMapper objectMapper = new ObjectMapper();
String json = objectMapper.writeValueAsString(postData);
OkHttpClient client = new OkHttpClient();
RequestBody body = RequestBody.create(json, MediaType.parse("application/json"));
Request request = new Request.Builder()
.url(url)
.post(body)
.build();
try (Response response = client.newCall(request).execute()) {
System.out.println(response.body().string());
}
}
}
Check Withdrawal Status
import com.fasterxml.jackson.databind.ObjectMapper;
import okhttp3.*;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import java.nio.charset.StandardCharsets;
import java.security.*;
import java.security.spec.PKCS8EncodedKeySpec;
import java.util.Base64;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
public class CheckWithdrawalStatus {
private static final String PRIVATE_KEY = "YOUR_PRIVATE_KEY_HERE"; // Replace with your RSA private key
public static void main(String[] args) throws Exception {
Security.addProvider(new BouncyCastleProvider());
Map<String, Object> data = new HashMap<>();
data.put("order_id", "17188041436139639757");
data.put("nonce", makeId(10));
data.put("timestamp", System.currentTimeMillis() / 1000);
String jsonData = new ObjectMapper().writeValueAsString(data);
String hash = rsaEncrypt(jsonData);
Map<String, Object> postData = new HashMap<>();
postData.put("merchant_id", "xxxx-xxxx-xxxx-xxxx");
postData.put("hash", hash);
postData.put("data", data);
sendPostRequest("https://payment.hyperhashing.com/v1/token/withdraw_status", postData);
}
private static String rsaEncrypt(String data) throws Exception {
byte[] privateKeyBytes = Base64.getDecoder().decode(PRIVATE_KEY);
PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(privateKeyBytes);
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
PrivateKey privateKey = keyFactory.generatePrivate(keySpec);
Signature signature = Signature.getInstance("SHA256withRSA");
signature.initSign(privateKey);
signature.update(data.getBytes(StandardCharsets.UTF_8));
return Base64.getEncoder().encodeToString(signature.sign());
}
private static String makeId(int length) {
String characters = "abcdefghijklmnopqrstuvwxyz0123456789";
Random random = new Random();
StringBuilder result = new StringBuilder(length);
for (int i = 0; i < length; i++) {
result.append(characters.charAt(random.nextInt(characters.length())));
}
return result.toString();
}
private static void sendPostRequest(String url, Map<String, Object> postData) throws Exception {
ObjectMapper objectMapper = new ObjectMapper();
String json = objectMapper.writeValueAsString(postData);
OkHttpClient client = new OkHttpClient();
RequestBody body = RequestBody.create(json, MediaType.parse("application/json"));
Request request = new Request.Builder()
.url(url)
.post(body)
.build();
try (Response response = client.newCall(request).execute()) {
System.out.println(response.body().string());
}
}
}
Last updated