@Override public String digestParams(RestInvocation restInvocation) { return restInvocation.getPath(); } }
@Override public String digestParams(RestInvocation restInvocation) { MessageDigest sha256; try { sha256 = MessageDigest.getInstance("SHA-256"); } catch (NoSuchAlgorithmException e) { throw new RuntimeException( "Illegal algorithm for post body digest. Check the implementation."); } sha256.update(restInvocation.getParamValue(FormParam.class, "nonce").toString().getBytes()); sha256.update(restInvocation.getRequestBody().getBytes()); Mac mac512 = getMac(); mac512.update(("/" + restInvocation.getPath()).getBytes()); mac512.update(sha256.digest()); return Base64.getEncoder().encodeToString(mac512.doFinal()).trim(); } }
@Override public String digestParams(RestInvocation restInvocation) { String postBody = restInvocation.getRequestBody(); if (postBody == null) { postBody = ""; } String uri = restInvocation.getPath() + "?" + restInvocation.getQueryString(); String message = uri + postBody; mac.update(message.getBytes()); return DigestUtils.bytesToHex(mac.doFinal()).toLowerCase(); } }
@Override public String digestParams(RestInvocation restInvocation) { MessageDigest sha256; try { sha256 = MessageDigest.getInstance("SHA-256"); } catch (NoSuchAlgorithmException e) { throw new RuntimeException( "Illegal algorithm for post body digest. Check the implementation."); } String decodedQuery = null; try { decodedQuery = URLDecoder.decode(restInvocation.getQueryString(), "UTF-8"); } catch (UnsupportedEncodingException e) { throw new IllegalArgumentException("Unsupported query encoding", e); } sha256.update(decodedQuery.getBytes()); sha256.update(restInvocation.getParamValue(HeaderParam.class, "Nonce").toString().getBytes()); sha256.update((restInvocation.getPath()).getBytes()); Mac mac512 = getMac(); mac512.update(sha256.digest()); return Base64.getEncoder().encodeToString(mac512.doFinal()).trim(); } }
@Override public String digestParams(RestInvocation restInvocation) { final String path = restInvocation.getPath(); final Map<String, String> httpHeadersFromParams = restInvocation.getHttpHeadersFromParams(); final String requestBody = restInvocation.getRequestBody(); final String input = String.join(";", path, requestBody, httpHeadersFromParams.get("Api-Nonce")); final Mac mac = getMac(); try { mac.update(input.getBytes("UTF-8")); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } final String printBase64Binary = bytesToHex(mac.doFinal()); return Base64.getEncoder().encodeToString(printBase64Binary.getBytes()); } }
@Override public String digestParams(RestInvocation restInvocation) { String timestamp = restInvocation.getParamValue(HeaderParam.class, CB_ACCESS_TIMESTAMP).toString(); String methodPath = "/v2" + restInvocation.getPath(); // todo - move the /v2 bit of the path to the interface String message = timestamp + restInvocation.getHttpMethod() + methodPath; String body = null; // todo - deal with POST requests String sign = DigestUtils.bytesToHex(getMac().doFinal(message.getBytes())); // String apiKey = restInvocation.getParamValue(HeaderParam.class, // CB_ACCESS_KEY).toString(); // showCurl(restInvocation.getHttpMethod(), apiKey, timestamp, sign, methodPath, body); return sign; }
@Override public String digestParams(RestInvocation restInvocation) { String timestamp = restInvocation.getHttpHeadersFromParams().get("AC-ACCESS-TIMESTAMP"); String method = restInvocation.getHttpMethod(); String path = restInvocation.getPath(); String queryParameters = restInvocation.getQueryString(); if (!queryParameters.isEmpty()) { queryParameters = '?' + queryParameters; } String body = restInvocation.getRequestBody(); body = body == null ? "" : body; String queryArgs = timestamp + method + path + (queryParameters + body); Mac shaMac = getMac(); final byte[] macData = shaMac.doFinal(queryArgs.getBytes()); return Base64.getEncoder().encodeToString(macData); } }
@Override public String digestParams(RestInvocation restInvocation) { // just write down their example code without thinking too much // https://kucoinapidocs.docs.apiary.io/#introduction/authentication/signature-calculation String endpoint = "/" + restInvocation.getPath(); // needs leading slash String queryString = restInvocation .getParamsMap() .get(QueryParam.class) .asHttpHeaders() .entrySet() .stream() .sorted((e1, e2) -> e1.getKey().compareTo(e2.getKey())) .map(e -> e.getKey() + "=" + e.getValue()) .collect(Collectors.joining("&")); Long nonce = (Long) restInvocation.getParamValue(HeaderParam.class, KucoinAuthenticated.HEADER_NONCE); String strForSign = endpoint + "/" + nonce + "/" + queryString; Mac mac = getMac(); try { mac.update(Base64.getEncoder().encode(strForSign.getBytes("UTF-8"))); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } return DigestUtils.bytesToHex(mac.doFinal()).toLowerCase(); } }
@Override public String digestParams(RestInvocation restInvocation) { String method = restInvocation.getHttpMethod(); String path = stripParams(restInvocation.getPath()); String query = Stream.of( restInvocation.getParamsMap().get(PathParam.class), restInvocation.getParamsMap().get(FormParam.class)) .map(Params::asHttpHeaders) .map(Map::entrySet) .flatMap(Collection::stream) .filter(e -> !"signature".equals(e.getKey())) .sorted(Entry.comparingByKey()) .map(e -> e.getKey() + "=" + e.getValue()) .collect(Collectors.joining("&")); String toSign = String.format("%s|/api/v2/%s|%s", method, path, query); Mac sha256hmac = getMac(); byte[] signed = sha256hmac.doFinal(toSign.getBytes()); String signature = new String(encodeHex(signed)); replaceInvocationUrl(restInvocation, signature); return signature; }
@Override public String digestParams(RestInvocation restInvocation) { String date = restInvocation.getHttpHeadersFromParams().get("date"); String sha1 = sha1(restInvocation.getRequestBody()); String s = restInvocation.getHttpMethod() + "\n" + sha1 + "\n" + MediaType.APPLICATION_JSON + "\n" + date + "\n" + "/" + restInvocation.getPath(); Mac mac = getMac(); mac.update(s.getBytes()); return api + ":" + Base64.getEncoder().encodeToString(mac.doFinal()); }
@Override public String digestParams(RestInvocation restInvocation) { String queryString = restInvocation.getQueryString(); // System.out.println("queryString = " + queryString); String httpMethod = restInvocation.getHttpMethod(); String uri = restInvocation.getPath(); if (queryString != null && queryString.length() > 0) { uri += "?" + restInvocation.getQueryString(); } // System.out.println("uri = " + uri); String requestBody = restInvocation.getRequestBody(); String nonce = restInvocation.getHttpHeadersFromParams().get(Bitflyer.ACCESS_TIMESTAMP); // ACCESS-SIGN is the resulting HMAC-SHA256 signature done with the API secret path using the // ACCESS-TIMESTAMP, HTTP method, request path, and // request body linked together as a character string. String hmac_data = String.format("%s%s%s%s", nonce, httpMethod, uri, requestBody); Mac mac256 = getMac(); mac256.update(hmac_data.getBytes()); return DigestUtils.bytesToHex(mac256.doFinal()).trim(); } }
final String input; if (restInvocation.getPath().startsWith("wapi/")) {
@Override public String digestParams(RestInvocation restInvocation) { String postBody = restInvocation.getRequestBody(); if (postBody == null) { postBody = ""; } String uri = restInvocation.getPath() + "?" + restInvocation.getQueryString(); String message = uri + postBody; mac.update(message.getBytes()); return DigestUtils.bytesToHex(mac.doFinal()).toLowerCase(); } }
@Override public String digestParams(RestInvocation restInvocation) { MessageDigest sha256; try { sha256 = MessageDigest.getInstance("SHA-256"); } catch (NoSuchAlgorithmException e) { throw new RuntimeException( "Illegal algorithm for post body digest. Check the implementation."); } sha256.update(restInvocation.getParamValue(FormParam.class, "nonce").toString().getBytes()); sha256.update(restInvocation.getRequestBody().getBytes()); Mac mac512 = getMac(); mac512.update(("/" + restInvocation.getPath()).getBytes()); mac512.update(sha256.digest()); return Base64.getEncoder().encodeToString(mac512.doFinal()).trim(); } }
@Override public String digestParams(RestInvocation restInvocation) { String postBody = restInvocation.getRequestBody(); if (postBody == null) { postBody = ""; } String uri = restInvocation.getPath() + "?" + restInvocation.getQueryString(); String message = uri + postBody; mac.update(message.getBytes()); return DigestUtils.bytesToHex(mac.doFinal()).toLowerCase(); }
@Override public String digestParams(RestInvocation restInvocation) { MessageDigest sha256; try { sha256 = MessageDigest.getInstance("SHA-256"); } catch (NoSuchAlgorithmException e) { throw new RuntimeException("Illegal algorithm for post body digest. Check the implementation."); } sha256.update(restInvocation.getParamValue(FormParam.class, "nonce").toString().getBytes()); sha256.update(restInvocation.getRequestBody().getBytes()); Mac mac512 = getMac(); mac512.update(("/" + restInvocation.getPath()).getBytes()); mac512.update(sha256.digest()); return Base64.encodeBytes(mac512.doFinal()).trim(); } }
@Override public String digestParams(RestInvocation restInvocation) { String timestamp = restInvocation.getParamValue(HeaderParam.class, CB_ACCESS_TIMESTAMP).toString(); String methodPath = "/v2" + restInvocation.getPath(); // todo - move the /v2 bit of the path to the interface String message = timestamp + restInvocation.getHttpMethod() + methodPath; String body = null; // todo - deal with POST requests String sign = DigestUtils.bytesToHex(getMac().doFinal(message.getBytes())); // String apiKey = restInvocation.getParamValue(HeaderParam.class, // CB_ACCESS_KEY).toString(); // showCurl(restInvocation.getHttpMethod(), apiKey, timestamp, sign, methodPath, body); return sign; }
@Override public String digestParams(RestInvocation restInvocation) { String queryString = restInvocation.getQueryString(); // System.out.println("queryString = " + queryString); String httpMethod = restInvocation.getHttpMethod(); String uri = restInvocation.getPath(); if (queryString != null && queryString.length() > 0) { uri += "?" + restInvocation.getQueryString(); } // System.out.println("uri = " + uri); String requestBody = restInvocation.getRequestBody(); String nonce = restInvocation.getHttpHeadersFromParams().get(Bitflyer.ACCESS_TIMESTAMP); // ACCESS-SIGN is the resulting HMAC-SHA256 signature done with the API secret path using the // ACCESS-TIMESTAMP, HTTP method, request path, and // request body linked together as a character string. String hmac_data = String.format("%s%s%s%s", nonce, httpMethod, uri, requestBody); Mac mac256 = getMac(); mac256.update(hmac_data.getBytes()); return DigestUtils.bytesToHex(mac256.doFinal()).trim(); } }
final String input; if (restInvocation.getPath().startsWith("wapi/")) {