diff --git a/Sources/TorusUtils/Helpers/KeyUtils.swift b/Sources/TorusUtils/Helpers/KeyUtils.swift index 6fe968e3..e5a97353 100644 --- a/Sources/TorusUtils/Helpers/KeyUtils.swift +++ b/Sources/TorusUtils/Helpers/KeyUtils.swift @@ -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 } @@ -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))) diff --git a/Sources/TorusUtils/TorusUtils.swift b/Sources/TorusUtils/TorusUtils.swift index a87e9d49..0e3201e6 100644 --- a/Sources/TorusUtils/TorusUtils.swift +++ b/Sources/TorusUtils/TorusUtils.swift @@ -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