From b4f7772c9439bd037cc1ad6caa08a5614ec181d2 Mon Sep 17 00:00:00 2001 From: metalurgical <97008724+metalurgical@users.noreply.github.com> Date: Tue, 21 May 2024 06:19:55 +0200 Subject: [PATCH] fix: import share --- Sources/TorusUtils/Helpers/KeyUtils.swift | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/Sources/TorusUtils/Helpers/KeyUtils.swift b/Sources/TorusUtils/Helpers/KeyUtils.swift index a2eaf859..66d080ef 100644 --- a/Sources/TorusUtils/Helpers/KeyUtils.swift +++ b/Sources/TorusUtils/Helpers/KeyUtils.swift @@ -102,22 +102,21 @@ public class KeyUtils { } internal static func generateKeyData(privateKey: String) throws -> PrivateKeyData { - let randomNonce = SecretKey() - let randomNonceInverse = try SecretKey(hex: randomNonce.serialize()).inv() + let scalar = BigInt(privateKey, radix: 16)! - let oAuthKey = try SecretKey(hex: privateKey) - try oAuthKey.addAssign(key: randomNonceInverse) + let randomNonce = BigInt(try SecretKey().serialize().addLeading0sForLength64(), radix: 16)! - let oAuthPrivateKeyString = try oAuthKey.serialize().addLeading0sForLength64() - let oAuthPubKeyString = try oAuthKey.toPublic().serialize(compressed: false) + let oAuthKey = (scalar - randomNonce).modulus(KeyUtils.getOrderOfCurve()) + + let oAuthPubKeyString = try SecretKey(hex: oAuthKey.magnitude.serialize().hexString.addLeading0sForLength64()).toPublic().serialize(compressed: false) let finalUserPubKey = try SecretKey(hex: privateKey).toPublic().serialize(compressed: false) return PrivateKeyData( - oAuthKey: oAuthPrivateKeyString, + oAuthKey: oAuthKey.magnitude.serialize().hexString.addLeading0sForLength64(), oAuthPubKey: oAuthPubKeyString, - nonce: try randomNonce.serialize().addLeading0sForLength64(), - signingKey: try oAuthKey.serialize().addLeading0sForLength64(), + nonce: randomNonce.magnitude.serialize().hexString.addLeading0sForLength64(), + signingKey: oAuthKey.magnitude.serialize().hexString.addLeading0sForLength64(), signingPubKey: oAuthPubKeyString, finalKey: privateKey, finalPubKey: finalUserPubKey