Authentication
Authentication is required only for API partner methods.
You can authenticate by adding your partner API-Key
and a Signature
to the header.
More information about these parameters is given below.
API-Key
Header parameter name: | API-Key |
---|
The API key is a unique identifier given by Switchere to each partner.
This parameter is required in the header of the partner API request for authentication
Signature
Header parameter name: | API-Signature |
---|
The signature used to verify your request.
The following parameters are required to create a signature:
secret
-- provided to you by our servicepath
-- only the URI request pathcontent
-- the body of the request, converted to a string When all the parameters are ready, you need to use the cryptographic hashing for those parameters, as shown below:signature = hmac_sha512_base64( sha256(path + content), secret )
You have to add the prepared signature to the header of the request
Examples
perl
my $secret = 'xxxxxxxx'; # provided by our service
my $path = '/api/v1/order';
my $content = '{"partner_order_id":"xxxxx-xxxxx-xxxx1"}';
my $signature = hmac_sha512_base64( sha256($path.$content), $secret );
php
$secret = 'xxxxxxxx'; # provided by our service
$content = '{"partner_order_id":"xxxxx-xxxxx-xxxx1"}';
$signature = trim(base64_encode(hash_hmac('sha512', hash('sha256', $path . $content, true), $secret, true)), ‘=‘);
python
import hashlib
import hmac
import base64
m = hashlib.sha256()
m.update(b'/api/hidden20220928/v2/partner/order/fee{"payin_group": "crypto","payin_amount": 1,"payin_currency": "ETH","payout_group": "crypto","payout_currency": "BTC","payout_group": "balance"}')
tmp = m.digest()
sign = hmac.new(b'xS!R1yRxZp8MoOJKC2?FsC8f2u027qAA', tmp, hashlib.sha512).hexdigest()
print(base64.b64encode(hmac.new(b"xS!R1yRxZp8MoOJKC2?FsC8f2u027qAA", msg=tmp, digestmod=hashlib.sha512).digest()))
java
import java.security.MessageDigest;
import java.nio.charset.StandardCharsets;
import javax.crypto.spec.SecretKeySpec;
import javax.crypto.Mac;
import javax.xml.bind.DatatypeConverter;
public class Sign {
public static void main(String args[]) {
try {
String content = "/api/v2/partner/order/f9198b78-5f2b-8841-7037-f9853e19ea83";
String secret = "xU4OfNlpcf0NMmlASDSMLGZB7cIaYhCWl";
MessageDigest digest = MessageDigest.getInstance("SHA-256");
byte[] hash = digest.digest(
content.getBytes(StandardCharsets.UTF_8));
SecretKeySpec secretKeySpec = new SecretKeySpec(secret.getBytes(), "HmacSHA512");
Mac mac = Mac.getInstance("HmacSHA512");
mac.init(secretKeySpec);
String sign = DatatypeConverter.printBase64Binary( mac.doFinal(hash));
System.out.println(sign);
} catch (Exception e) {}
}
}