# JAVA

### Initiate Withdrawal

```php
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

```php
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());
        }
    }
}

```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://hyperhashing.gitbook.io/hyperhashing-api/withdraw-order-v2/example/java.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
