diff --git a/Package.resolved b/Package.resolved index 37d12da1..81c0096f 100644 --- a/Package.resolved +++ b/Package.resolved @@ -33,7 +33,7 @@ "repositoryURL": "https://github.com/tkey/curvelib.swift", "state": { "branch": "main", - "revision": "1fc5b9fbf2927ce72a492b88b906852dda42c8e3", + "revision": "988edd4208d4aa0b17f70a8e02acdb353aa4bd55", "version": null } }, diff --git a/Sources/TorusUtils/Extensions/TorusUtils+extension.swift b/Sources/TorusUtils/Extensions/TorusUtils+extension.swift index 9b8939b9..96468391 100644 --- a/Sources/TorusUtils/Extensions/TorusUtils+extension.swift +++ b/Sources/TorusUtils/Extensions/TorusUtils+extension.swift @@ -122,7 +122,7 @@ extension TorusUtils { // try secp256k1.Signing.PrivateKey(dataRepresentation: Data(hex: privateKey), format: .uncompressed) - let publicKey = try curvelib.Secp256k1.PublicKey.fromPrivateKey(privateKey: privKey.rawData).getRaw() + let publicKey = try privKey.getPublicKey().getSec1Full().hexString // privKey.publicKey.dataRepresentation.hexString @@ -205,7 +205,7 @@ extension TorusUtils { let derivedPrivateKey = try curvelib.Secp256k1.PrivateKey(input: Data(hex: try lagrangeInterpolation(shares: currentCombiShares, offset: 0))) // try secp256k1.KeyAgreement.PrivateKey(dataRepresentation: Data(hex: try lagrangeInterpolation(shares: currentCombiShares, offset: 0).addLeading0sForLength64()), format: .uncompressed) - let decryptedPubKey = try derivedPrivateKey.getPublicKey().getRaw() + let decryptedPubKey = try derivedPrivateKey.getPublicKey().getSec1Full().hexString let decryptedPubKeyX = String(decryptedPubKey.suffix(128).prefix(64)) let decryptedPubKeyY = String(decryptedPubKey.suffix(64)) if decryptedPubKeyX == thresholdPublicKey.X.addLeading0sForLength64() && decryptedPubKeyY == thresholdPublicKey.Y.addLeading0sForLength64() { @@ -236,7 +236,7 @@ extension TorusUtils { let threshold = (endpoints.count / 2) + 1 let sessionAuthKey = try curvelib.Secp256k1.PrivateKey() - let serializedPublicKey = try sessionAuthKey.getPublicKey().getRaw() + let serializedPublicKey = try sessionAuthKey.getPublicKey().getSec1Full().hexString // Split key in 2 parts, X and Y let pubKeyX = String(serializedPublicKey.suffix(128).prefix(64)) @@ -447,7 +447,7 @@ extension TorusUtils { let derivedPrivateKey = try curvelib.Secp256k1.PrivateKey(input: Data(hex: oAuthKey)) // try secp256k1.KeyAgreement.PrivateKey(dataRepresentation: Data(hex: oAuthKey), format: .uncompressed) - let oAuthPubKey = try derivedPrivateKey.getPublicKey().getRaw() + let oAuthPubKey = try derivedPrivateKey.getPublicKey().getSec1Full().hexString let oAuthPubKeyX = String(oAuthPubKey.suffix(128).prefix(64)) let oAuthPubKeyY = String(oAuthPubKey.suffix(64)) @@ -768,7 +768,7 @@ extension TorusUtils { let data = try lagrangeInterpolation(shares: sharesToInterpolate) let finalPrivateKey = try curvelib.Secp256k1.PrivateKey(input: Data(hex: data)) // try secp256k1.KeyAgreement.PrivateKey(dataRepresentation: Data(hex: data), format: .uncompressed) - let finalPublicKey = try finalPrivateKey.getPublicKey().getRaw() + let finalPublicKey = try finalPrivateKey.getPublicKey().getSec1Full().hexString // Split key in 2 parts, X and Y let pubKeyX = String(finalPublicKey.suffix(128).prefix(64)) let pubKeyY = String(finalPublicKey.suffix(64)) @@ -1230,7 +1230,7 @@ extension TorusUtils { internal func generateNonceMetadataParams(message: String, privateKey: BigInt, nonce: BigInt?) throws -> NonceMetadataParams { let privKey = try curvelib.Secp256k1.PrivateKey(input: privateKey.magnitude.serialize()) // try secp256k1.Signing.PrivateKey(dataRepresentation: Data(hex: privateKey.magnitude.serialize().hexString.addLeading0sForLength64()), format: .uncompressed) - let publicKey = try privKey.getPublicKey().getRaw() + let publicKey = try privKey.getPublicKey().getSec1Full().hexString let timeStamp = String(BigUInt(serverTimeOffset + Date().timeIntervalSince1970), radix: 16) var setData: NonceMetadataParams.SetNonceData = .init(data: message, timestamp: timeStamp) @@ -1272,9 +1272,9 @@ extension TorusUtils { let combined = try curvelib.Secp256k1.PublicKey.combine(publicKeys: data) if compressed { - return try combined.getSec1Compress() + return try combined.getSec1Compress().hexString } - return try combined.getSec1Full() + return try combined.getSec1Full().hexString // let added = secp256k1.combineSerializedPublicKeys(keys: data, outputCompressed: compressed) // guard let result = added?.toHexString() // else { @@ -1301,7 +1301,7 @@ extension TorusUtils { finalPubKey = (pubKeyX.addLeading0sForLength64() + pubKeyY.addLeading0sForLength64()).add04Prefix() if nonce != BigInt(0) { let noncePrivateKey = try curvelib.Secp256k1.PrivateKey(input: BigUInt(nonce).magnitude.serialize()) - let noncePublicKey = try noncePrivateKey.getPublicKey().getRaw() + let noncePublicKey = try noncePrivateKey.getPublicKey().getSec1Full().hexString finalPubKey = try combinePublicKeys(keys: [finalPubKey, noncePublicKey], compressed: false) } else { finalPubKey = String(finalPubKey) @@ -1331,7 +1331,7 @@ extension TorusUtils { let nonce2 = BigInt(localNonce) let noncePrivateKey = try curvelib.Secp256k1.PrivateKey(input: BigUInt(nonce2).magnitude.serialize()) // try secp256k1.KeyAgreement.PrivateKey(dataRepresentation: BigUInt(nonce2).magnitude.serialize().addLeading0sForLength64(), format: .uncompressed) - let noncePublicKey = try noncePrivateKey.getPublicKey().getRaw() + let noncePublicKey = try noncePrivateKey.getPublicKey().getSec1Full().hexString finalPubKey = try combinePublicKeys(keys: [finalPubKey, noncePublicKey], compressed: false) } else { finalPubKey = String(finalPubKey) diff --git a/Sources/TorusUtils/TorusUtils.swift b/Sources/TorusUtils/TorusUtils.swift index be9ab193..5490b8d1 100644 --- a/Sources/TorusUtils/TorusUtils.swift +++ b/Sources/TorusUtils/TorusUtils.swift @@ -232,8 +232,8 @@ open class TorusUtils: AbstractTorusUtils { indexes: [BigUInt], endpoints: [String], verifier: String, verifierId: String, idToken: String, extraParams: [String: Codable]) async throws -> TorusKey { let privateKey = try curvelib.Secp256k1.PrivateKey() - let serializedPublicKey = try curvelib.Secp256k1.PublicKey.fromPrivateKey(privateKey: privateKey.rawData).getRaw(); - + let serializedPublicKey = try privateKey.getPublicKey().getSec1Full().hexString + // Split key in 2 parts, X and Y // let publicKeyHex = publicKey.toHexString() let pubKeyX = String(serializedPublicKey.suffix(128).prefix(64)) @@ -287,8 +287,7 @@ open class TorusUtils: AbstractTorusUtils { let serializedKey = Data(hex: privateKeyWithNonce.magnitude.serialize().hexString.addLeading0sForLength64()) let finalPrivateKey = try curvelib.Secp256k1.PrivateKey(input : serializedKey) - finalPubKey = try curvelib.Secp256k1.PublicKey.fromPrivateKey(privateKey: finalPrivateKey.rawData ).getRaw() -// finalPrivateKey.publicKey.dataRepresentation.hexString + finalPubKey = try finalPrivateKey.getPublicKey().getSec1Full().hexString } } else { // for imported keys in legacy networks @@ -296,8 +295,8 @@ open class TorusUtils: AbstractTorusUtils { var privateKeyWithNonce = BigInt(metadataNonce) + BigInt(oAuthKey, radix: 16)! privateKeyWithNonce = privateKeyWithNonce.modulus(modulusValue) let finalPrivateKey = try curvelib.Secp256k1.PrivateKey(input: privateKeyWithNonce.magnitude.serialize()) - - finalPubKey = try curvelib.Secp256k1.PublicKey.fromPrivateKey(privateKey: finalPrivateKey.rawData).getRaw() + + finalPubKey = try finalPrivateKey.getPublicKey().getSec1Full().hexString } print("pubkey data" , finalPubKey) print("pubkey length", finalPubKey.count )