<?php
class HDWaaSClient {
private string $apiKey;
private string $secretKey;
private string $baseUrl;
public function __construct(string $apiKey, string $secretKey, string $baseUrl = 'https://api.2settle.io') {
$this->apiKey = $apiKey;
$this->secretKey = $secretKey;
$this->baseUrl = $baseUrl;
}
private function sign(string $method, string $path, array $body = []): array {
$timestamp = (string) round(microtime(true) * 1000);
$bodyStr = json_encode($body ?: new stdClass(), JSON_UNESCAPED_SLASHES);
$bodyHash = hash('sha256', $bodyStr);
$payload = "{$timestamp}|{$method}|{$path}|{$bodyHash}";
$hmacKey = hash('sha256', $this->secretKey);
$signature = hash_hmac('sha256', $payload, $hmacKey);
return [$timestamp, $signature, $bodyStr];
}
private function request(string $method, string $path, array $body = null): array {
[$timestamp, $signature, $bodyStr] = $this->sign($method, $path, $body ?? []);
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => $this->baseUrl . $path,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => $method,
CURLOPT_HTTPHEADER => [
'Content-Type: application/json',
'X-API-Key: ' . $this->apiKey,
'X-Timestamp: ' . $timestamp,
'X-Signature: ' . $signature,
],
]);
if ($method !== 'GET' && $body !== null) {
curl_setopt($ch, CURLOPT_POSTFIELDS, $bodyStr);
}
$response = curl_exec($ch);
curl_close($ch);
return json_decode($response, true);
}
public function createWallet(string $network, string $crypto, array $metadata = null, int $expiresInMinutes = null): array {
$body = ['network' => $network, 'crypto' => $crypto];
if ($metadata) $body['metadata'] = $metadata;
if ($expiresInMinutes) $body['expiresInMinutes'] = $expiresInMinutes;
return $this->request('POST', '/v1/wallets', $body);
}
public function getWallet(string $walletId): array {
return $this->request('GET', "/v1/wallets/{$walletId}", []);
}
public function listWallets(string $status = null, int $limit = 50, int $offset = 0): array {
$query = http_build_query(array_filter([
'status' => $status,
'limit' => $limit,
'offset' => $offset,
]));
return $this->request('GET', "/v1/wallets?{$query}", []);
}
}
// Usage
$client = new HDWaaSClient('pk_your_api_key', 'sk_your_secret_key');
// Create USDT deposit address
$result = $client->createWallet('trc20', 'USDT', ['orderId' => 'ORD-12345'], 60);
echo "Deposit address: " . $result['wallet']['address'] . "\n";
// Check deposit status
$status = $client->getWallet($result['wallet']['id']);
echo "Status: " . $status['wallet']['status'] . "\n";