diff --git a/Sources/TorusUtils/Helpers/NodeUtils.swift b/Sources/TorusUtils/Helpers/NodeUtils.swift index 034b1e26..74b90c8c 100644 --- a/Sources/TorusUtils/Helpers/NodeUtils.swift +++ b/Sources/TorusUtils/Helpers/NodeUtils.swift @@ -403,10 +403,10 @@ internal class NodeUtils { var sessionTokens: [String?] = [] var nodeIndexes: [Int?] = [] var sessionTokenDatas: [SessionToken?] = [] - var isNewKeys: [String] = [] + var isNewKeys: [IsNewKeyResponse] = [] for item in shareResponses { - isNewKeys.append(item.isNewKey) + isNewKeys.append(IsNewKeyResponse(isNewKey: item.isNewKey == "true", publicKeyX: item.keys.first?.publicKey.X ?? "")) if !item.sessionTokenSigs.isEmpty { if !item.sessionTokenSigMetadata.isEmpty { @@ -506,7 +506,12 @@ internal class NodeUtils { throw TorusUtilError.privateKeyDeriveFailed } - let thresholdIsNewKey: String? = try thresholdSame(arr: isNewKeys, threshold: threshold) + var isNewKey = false; + for item in isNewKeys { + if (item.isNewKey && item.publicKeyX.lowercased() == thresholdPublicKey!.X.lowercased()) { + isNewKey = true + } + } let oAuthKey = privateKey! let oAuthPublicKey = try SecretKey(hex: oAuthKey).toPublic().serialize(compressed: false) @@ -520,8 +525,7 @@ internal class NodeUtils { finalPubKey = oAuthPublicKey } else if TorusUtils.isLegacyNetworkRouteMap(network: network) { if enableOneKey { - let isNewKey = !(thresholdIsNewKey == "true") - let nonce = try await MetadataUtils.getOrSetNonce(legacyMetadataHost: legacyMetadataHost, serverTimeOffset: serverTimeOffsetResponse, X: thresholdPublicKey!.X, Y: thresholdPublicKey!.Y, privateKey: oAuthKey, getOnly: isNewKey) + let nonce = try await MetadataUtils.getOrSetNonce(legacyMetadataHost: legacyMetadataHost, serverTimeOffset: serverTimeOffsetResponse, X: thresholdPublicKey!.X, Y: thresholdPublicKey!.Y, privateKey: oAuthKey, getOnly: !isNewKey) metadataNonce = BigInt(nonce.nonce?.addLeading0sForLength64() ?? "0", radix: 16) ?? BigInt(0) typeOfUser = UserType(rawValue: nonce.typeOfUser?.lowercased() ?? "v1")! if typeOfUser == .v2 { diff --git a/Sources/TorusUtils/Helpers/jsonRPC/Responses/IsNewKeyResponse.swift b/Sources/TorusUtils/Helpers/jsonRPC/Responses/IsNewKeyResponse.swift new file mode 100644 index 00000000..ed268ebf --- /dev/null +++ b/Sources/TorusUtils/Helpers/jsonRPC/Responses/IsNewKeyResponse.swift @@ -0,0 +1,11 @@ +import Foundation + +internal struct IsNewKeyResponse: Codable { + public var isNewKey: Bool; + public var publicKeyX: String; + + public init(isNewKey: Bool, publicKeyX: String) { + self.isNewKey = isNewKey + self.publicKeyX = publicKeyX + } +}