diff --git a/README.md b/README.md index c654a11..e382771 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ repositories { maven { url "https://jitpack.io" } } dependencies { - implementation 'org.torusresearch:torus-utils-java:4.0.0' + implementation 'org.torusresearch:torus-utils-java:4.0.3' } ``` diff --git a/build.gradle b/build.gradle index 48861fc..0729bde 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ plugins { } group 'org.torusresearch' -version '4.0.0' +version '4.0.3' sourceCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8 diff --git a/src/main/java/org/torusresearch/torusutils/apis/responses/VerifierLookupResponse/VerifierKey.java b/src/main/java/org/torusresearch/torusutils/apis/responses/VerifierLookupResponse/VerifierKey.java index 6635d18..57d7d51 100644 --- a/src/main/java/org/torusresearch/torusutils/apis/responses/VerifierLookupResponse/VerifierKey.java +++ b/src/main/java/org/torusresearch/torusutils/apis/responses/VerifierLookupResponse/VerifierKey.java @@ -20,4 +20,12 @@ public VerifierKey(@NotNull String pub_key_X, @NotNull String pub_key_Y, @NotNul this.nonce_data = nonce_data; this.created_at = created_at; } + + public VerifierKey(@NotNull String pub_key_X, @NotNull String pub_key_Y, @NotNull String address) { + this.pub_key_X = pub_key_X; + this.pub_key_Y = pub_key_Y; + this.address = address; + this.nonce_data = null; + this.created_at = null; + } } diff --git a/src/main/java/org/torusresearch/torusutils/helpers/Common.java b/src/main/java/org/torusresearch/torusutils/helpers/Common.java index 32da76c..bf2b081 100644 --- a/src/main/java/org/torusresearch/torusutils/helpers/Common.java +++ b/src/main/java/org/torusresearch/torusutils/helpers/Common.java @@ -21,7 +21,7 @@ public static KeyResult normalizeKeyResult(@NotNull VerifierLookupResponse resul KeyResult finalResult = new KeyResult(isNewKey); if (result.keys.length > 0) { VerifierKey finalKey = result.keys[0]; - finalResult.keys = new VerifierKey[]{ finalKey }; + finalResult.keys = new VerifierKey[]{new VerifierKey(finalKey.pub_key_X, finalKey.pub_key_Y, finalKey.address)}; } return finalResult; } diff --git a/src/main/java/org/torusresearch/torusutils/helpers/NodeUtils.java b/src/main/java/org/torusresearch/torusutils/helpers/NodeUtils.java index 9310030..753aead 100644 --- a/src/main/java/org/torusresearch/torusutils/helpers/NodeUtils.java +++ b/src/main/java/org/torusresearch/torusutils/helpers/NodeUtils.java @@ -92,8 +92,8 @@ public static KeyLookupResult getPubKeyOrKeyAssign(@NotNull String[] endpoints, @SuppressWarnings({"unchecked"}) // Due to Type Erasure of Generic Types at Runtime. Java does this to ensure code is compatible with pre-generic versions of Java. JsonRPCResponse response = json.fromJson(result, JsonRPCResponse.class); collected.add(response); - lookupPubKeys = collected.stream().filter(item -> item.getError() == null && item.getTypedResult(VerifierLookupResponse.class) != null).collect(Collectors.toList()); - errResult = (JsonRPCErrorInfo) NodeUtils.thresholdSame(collected.stream().filter(item -> item.getError() != null).toArray(), threshold); + lookupPubKeys = collected.stream().filter(item -> item != null && item.getError() == null && item.getTypedResult(VerifierLookupResponse.class) != null).collect(Collectors.toList()); + errResult = (JsonRPCErrorInfo) NodeUtils.thresholdSame(collected.stream().filter(item -> item != null && item.getError() != null).toArray(), threshold); ArrayList normalizedKeys = new ArrayList<>(); for (JsonRPCResponse item : lookupPubKeys) { VerifierLookupResponse vlr = item.getTypedResult(VerifierLookupResponse.class); @@ -550,11 +550,11 @@ public static T thresholdSame(@NotNull T[] arr, int threshold) throws JsonPr ObjectMapper objectMapper = new ObjectMapper() .configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true); String value = objectMapper.writeValueAsString(s); - Integer index = hashMap.get(value); - if (index != null) { - hashMap.put(value, index+1); + Integer found = hashMap.get(value); + if (found != null) { + hashMap.put(value, found + 1); } else { - hashMap.put(value, 0); + hashMap.put(value, 1); } if (hashMap.get(value) != null && hashMap.get(value) == threshold) { return s;