Skip to content

Commit

Permalink
fix: check for nil pubnonce for v2 user
Browse files Browse the repository at this point in the history
  • Loading branch information
metalurgical committed Jul 16, 2024
1 parent 6516d25 commit 2df77d4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
12 changes: 7 additions & 5 deletions Sources/TorusUtils/Helpers/NodeUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -534,12 +534,14 @@ internal class NodeUtils {
} else {
typeOfUser = .v2
let oAuthPubKey = KeyUtils.getPublicKeyFromCoords(pubKeyX: oAuthPublicKeyX, pubKeyY: oAuthPublicKeyY)
finalPubKey = oAuthPubKey
if thresholdNonceData!.pubNonce != nil {
let publicNonce = KeyUtils.getPublicKeyFromCoords(pubKeyX: thresholdNonceData!.pubNonce!.x, pubKeyY: thresholdNonceData!.pubNonce!.y)
finalPubKey = try KeyUtils.combinePublicKeys(keys: [oAuthPubKey, publicNonce])
pubNonce = PubNonce(x: thresholdNonceData!.pubNonce!.x, y: thresholdNonceData!.pubNonce!.y)
} else {
finalPubKey = oAuthPubKey
let pubNonceKey = thresholdNonceData!.pubNonce!
if !(pubNonceKey.x.isEmpty || pubNonceKey.y.isEmpty) {
let publicNonce = KeyUtils.getPublicKeyFromCoords(pubKeyX: pubNonceKey.x, pubKeyY: pubNonceKey.y)
finalPubKey = try KeyUtils.combinePublicKeys(keys: [oAuthPubKey, publicNonce])
pubNonce = PubNonce(x: thresholdNonceData!.pubNonce!.x, y: thresholdNonceData!.pubNonce!.y)
}
}
}

Expand Down
13 changes: 9 additions & 4 deletions Sources/TorusUtils/TorusUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -242,12 +242,17 @@ public class TorusUtils {
let legacyResult = LegacyVerifierLookupResponse(keys: legacyKeysResult, serverTimeOffset: String(finalServerTimeOffset))
return try await formatLegacyPublicKeyData(finalKeyResult: legacyResult, enableOneKey: enableOneKey, isNewKey: keyAssignResult.keyResult!.is_new_key, serverTimeOffset: finalServerTimeOffset)
} else {
let pubNonceResult = keyAssignResult.nonceResult!.pubNonce!
let (X, Y) = try KeyUtils.getPublicKeyCoords(pubKey: pubKey)
oAuthPubKey = KeyUtils.getPublicKeyFromCoords(pubKeyX: X, pubKeyY: Y)
let pubNonceKey = KeyUtils.getPublicKeyFromCoords(pubKeyX: pubNonceResult.x, pubKeyY: pubNonceResult.y)
finalPubKey = try KeyUtils.combinePublicKeys(keys: [oAuthPubKey!, pubNonceKey])
pubNonce = pubNonceResult
finalPubKey = oAuthPubKey!
if keyAssignResult.nonceResult!.pubNonce != nil {
let pubNonceResult = keyAssignResult.nonceResult!.pubNonce!
if !(pubNonceResult.x.isEmpty || pubNonceResult.y.isEmpty) {
let pubNonceKey = KeyUtils.getPublicKeyFromCoords(pubKeyX: pubNonceResult.x, pubKeyY: pubNonceResult.y)
finalPubKey = try KeyUtils.combinePublicKeys(keys: [oAuthPubKey!, pubNonceKey])
pubNonce = pubNonceResult
}
}
}

if oAuthPubKey == nil || finalPubKey == nil {
Expand Down

0 comments on commit 2df77d4

Please sign in to comment.