diff --git a/src/main/java/org/torusresearch/torusutils/helpers/IsNewKeyResponse.java b/src/main/java/org/torusresearch/torusutils/helpers/IsNewKeyResponse.java new file mode 100644 index 0000000..23e7106 --- /dev/null +++ b/src/main/java/org/torusresearch/torusutils/helpers/IsNewKeyResponse.java @@ -0,0 +1,14 @@ +package org.torusresearch.torusutils.helpers; + +import org.jetbrains.annotations.NotNull; + +public class IsNewKeyResponse { + + public boolean isNewKey; + public String publicKeyX; + + public IsNewKeyResponse(@NotNull boolean isNewKey, @NotNull String publicKeyX) { + this.isNewKey = isNewKey; + this.publicKeyX = publicKeyX; + } +} diff --git a/src/main/java/org/torusresearch/torusutils/helpers/NodeUtils.java b/src/main/java/org/torusresearch/torusutils/helpers/NodeUtils.java index fed27b2..9310030 100644 --- a/src/main/java/org/torusresearch/torusutils/helpers/NodeUtils.java +++ b/src/main/java/org/torusresearch/torusutils/helpers/NodeUtils.java @@ -353,10 +353,12 @@ public static TorusKey retrieveOrImportShare(@NotNull String legacyMetadataHost, ArrayList sessionTokens = new ArrayList<>(); ArrayList nodeIndexes = new ArrayList<>(); ArrayList sessionTokenDatas = new ArrayList<>(); - ArrayList isNewKeys = new ArrayList<>(); + ArrayList isNewKeys = new ArrayList<>(); for (ShareRequestResult item : shareResponses) { - isNewKeys.add(item.is_new_key.toString()); + if (item.keys.length > 0 && item.keys[0] != null) { + isNewKeys.add(new IsNewKeyResponse(item.is_new_key, item.keys[0].public_key.getX())); + } if (item.session_token_sigs != null && item.session_token_sigs.length > 0) { if (item.session_token_sig_metadata != null && item.session_token_sig_metadata.length > 0) { @@ -443,7 +445,12 @@ public static TorusKey retrieveOrImportShare(@NotNull String legacyMetadataHost, throw TorusUtilError.PRIVATE_KEY_DERIVE_FAILED; } - String thesholdIsNewKey = thresholdSame(isNewKeys.toArray(new String[0]), threshold); + boolean isNewKey = false; + for (IsNewKeyResponse item : isNewKeys) { + if (item.isNewKey && item.publicKeyX.equalsIgnoreCase(thresholdPublicKey.getX())) { + isNewKey = true; + } + } String oAuthKey = Common.padLeft(privateKey.toString(16), '0', 64); String oAuthPublicKey = KeyUtils.privateToPublic(privateKey); @@ -458,8 +465,7 @@ public static TorusKey retrieveOrImportShare(@NotNull String legacyMetadataHost, finalPublicKey = oAuthPublicKey; } else if (TorusUtils.isLegacyNetorkRouteMap(network)) { if (enableOneKey) { - Boolean isNewKey = (!(thesholdIsNewKey != null && thesholdIsNewKey.equalsIgnoreCase("true"))); - GetOrSetNonceResult nonce = MetadataUtils.getOrSetNonce(legacyMetadataHost, thresholdPublicKey.getX(), thresholdPublicKey.getY(), serverOffsetResponse, oAuthKey, isNewKey, null); + GetOrSetNonceResult nonce = MetadataUtils.getOrSetNonce(legacyMetadataHost, thresholdPublicKey.getX(), thresholdPublicKey.getY(), serverOffsetResponse, oAuthKey, !isNewKey, null); metadataNonce = (nonce.nonce != null) ? new BigInteger(Common.padLeft(nonce.nonce, '0', 64), 16) : BigInteger.ZERO; typeOfUser = (nonce.typeOfUser != null) ? nonce.typeOfUser : TypeOfUser.v1;