BithumbDigest extends BaseParamsDigest { @Override public String digestParams(RestInvocation restInvocation) { final String path = restInvocation.getPath(); final Map<String, String> httpHeadersFromParams = restInvocation.getHttpHeadersFromParams(); final String requestBody; if (restInvocation.getParamsMap().containsKey(FormParam.class)) { requestBody = restInvocation .getParamsMap() .getOrDefault(FormParam.class, Params.of()) .asHttpHeaders() .entrySet() .stream() .map( e -> { final String value = "endpoint".equals(e.getKey()) ? urlEncode(path) : e.getValue(); return e.getKey() + "=" + value; }) .collect(Collectors.joining("&")); } else { requestBody = StringUtils.EMPTY; } final String input = String.join(";", path, requestBody, httpHeadersFromParams.get("Api-Nonce")); final Mac mac = getMac(); mac.update(input.getBytes(StandardCharsets.UTF_8)); final String printBase64Binary = bytesToHex(mac.doFinal()); return Base64.getEncoder().encodeToString(printBase64Binary.getBytes()); } private  BithumbDigest(String secretKeyBase64); static BithumbDigest createInstance(String secretKeyBase64); @Override String digestParams(RestInvocation restInvocation);  }
@Test public void testDigestParams() { final Map<String, String> map = new HashMap<>(); map.put("Api-Nonce", "1547303756000"); final Map<Class<? extends Annotation>, Params> formParams = new LinkedHashMap<>(); formParams.put(FormParam.class, Params.of("endpoint", "/info/balance", "currency", "ALL")); final RestInvocation restInvocation = mock(RestInvocation.class); when(restInvocation.getPath()).thenReturn("/info/balance"); when(restInvocation.getParamsMap()).thenReturn(formParams); when(restInvocation.getHttpHeadersFromParams()).thenReturn(map); final String sign = bithumbDigest.digestParams(restInvocation); assertThat(sign) .isEqualTo( "MTkzMGVmY2QzZGUzZWQ1ZmRkZmVhMGFhMmU2MjNkMThlYmQ2NTkyOTU1ZTcxMTc2N2NjZTY0ODdhOTJmOWRhMTNjZTYxMWVlYTJlOTEzOTBlYzlmMDU1MDVkMTk5OGY3YjUyMDY1NzVhZThlYWUxMmJmNjIxNjlkNTY2YmM0Nzc="); }