Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions Sources/TorusUtils/Helpers/NodeUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
}