Skip to content

Commit

Permalink
fix: import share
Browse files Browse the repository at this point in the history
  • Loading branch information
metalurgical committed May 21, 2024
1 parent c20aec6 commit b4f7772
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions Sources/TorusUtils/Helpers/KeyUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b4f7772

Please sign in to comment.