Skip to content

Commit

Permalink
fix: public key size error bug
Browse files Browse the repository at this point in the history
  • Loading branch information
metalurgical committed Jul 15, 2024
1 parent 99c90c8 commit 1fcc104
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
8 changes: 6 additions & 2 deletions Sources/TorusUtils/Helpers/KeyUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ public class KeyUtils {
}

public static func getPublicKeyCoords(pubKey: String) throws -> (String, String) {
let publicKeyUnprefixed = pubKey.strip04Prefix()
var publicKeyUnprefixed = pubKey
if publicKeyUnprefixed.count > 128 {
publicKeyUnprefixed = publicKeyUnprefixed.strip04Prefix()
}

if !(publicKeyUnprefixed.count == 128) {
throw TorusUtilError.invalidPubKeySize
}
Expand Down Expand Up @@ -143,7 +147,7 @@ public class KeyUtils {
if keyType != TorusKeyType.secp256k1 {
throw TorusUtilError.runtime("Unsupported key type")
}

let keyData = try generateKeyData(privateKey: privateKey)

let threshold = Int(trunc(Double((nodePubKeys.count / 2) + 1)))
Expand Down
3 changes: 2 additions & 1 deletion Sources/TorusUtils/TorusUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,8 @@ public class TorusUtils {
return try await formatLegacyPublicKeyData(finalKeyResult: legacyResult, enableOneKey: enableOneKey, isNewKey: keyAssignResult.keyResult!.is_new_key, serverTimeOffset: finalServerTimeOffset)
} else {
let pubNonceResult = keyAssignResult.nonceResult!.pubNonce!
oAuthPubKey = pubKey
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
Expand Down

0 comments on commit 1fcc104

Please sign in to comment.