Skip to content

Commit

Permalink
fix: update curvelib
Browse files Browse the repository at this point in the history
  • Loading branch information
ieow committed Apr 16, 2024
1 parent 9082e32 commit 8ea9262
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 15 deletions.
4 changes: 2 additions & 2 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/tkey/curvelib.swift",
"state" : {
"branch" : "feat/cocoapod",
"revision" : "282343f23790dcdf189d844eb65c485bbad3eb73"
"revision" : "2df9f638fd121b445ce3b410cd79ac4d0cfa94ed",
"version" : "1.0.0"
}
},
{
Expand Down
4 changes: 1 addition & 3 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ let package = Package(
targets: ["TorusUtils"])
],
dependencies: [
.package(url: "https://github.com/tkey/curvelib.swift", branch: "feat/cocoapod"),
.package(url: "https://github.com/tkey/curvelib.swift", from: "1.0.0"),
.package(name:"FetchNodeDetails", url: "https://github.com/torusresearch/fetch-node-details-swift", from: "5.2.0"),
.package(name:"jwt-kit", url: "https://github.com/vapor/jwt-kit", from: "4.0.0"),
.package(
Expand All @@ -25,8 +25,6 @@ let package = Package(
name: "TorusUtils",
dependencies: ["AnyCodable", "FetchNodeDetails",
.product(name: "curveSecp256k1", package: "curvelib.swift"),
.product(name: "encryption_aes_cbc_sha512", package: "curvelib.swift"),
.product(name: "curvelibSha3", package: "curvelib.swift")
]),
.testTarget(
name: "TorusUtilsTests",
Expand Down
4 changes: 2 additions & 2 deletions Sources/TorusUtils/Extensions/TorusUtils+extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import CommonSources
import CryptoKit
import FetchNodeDetails
import OSLog
import encryption_aes_cbc_sha512



extension TorusUtils {
Expand Down Expand Up @@ -683,7 +683,7 @@ extension TorusUtils {
guard let data = msg.data(using: .utf8) else {
throw TorusUtilError.runtime("Encryption: Invalid utf8 string")
}
let curveMsg = try Encryption.encrypt(pk: PublicKey(hex: publicKey), data: data)
let curveMsg = try Encryption.encrypt(pk: PublicKey(hex: publicKey), plainText: data)
return try .init(iv: curveMsg.iv(), ephemPublicKey: curveMsg.ephemeralPublicKey().serialize(compressed: false), ciphertext: curveMsg.chipherText(), mac: curveMsg.mac())
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/TorusUtils/Helpers/Common.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import BigInt
import Foundation
//import CryptoSwift

import curvelibSha3
import curveSecp256k1

func keccak256Data(_ data: Data) -> Data {
let hash = try? keccak256(data: data)
Expand Down
11 changes: 4 additions & 7 deletions Tests/TorusUtilsTests/SapphireTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ import FetchNodeDetails
import JWTKit
import XCTest
import curveSecp256k1
import encryption_aes_cbc_sha512
import CommonSources
import curveSecp256k1
import encryption_aes_cbc_sha512

@testable import TorusUtils

Expand Down Expand Up @@ -124,7 +121,7 @@ final class SapphireTest: XCTestCase {
XCTAssertNotEqual(data.sessionData?.sessionAuthKey, "")
XCTAssertEqual(data.metadata?.pubNonce?.x, "5d03a0df9b3db067d3363733df134598d42873bb4730298a53ee100975d703cc")
XCTAssertEqual(data.metadata?.pubNonce?.y, "279434dcf0ff22f077877a70bcad1732412f853c96f02505547f7ca002b133ed")
XCTAssertEqual(data.metadata?.nonce?.serialize().hexString, "b7d126751b68ecd09e371a23898e6819dee54708a5ead4f6fe83cdc79c0f1c4a")
XCTAssertEqual(data.metadata?.nonce?.serialize().toHexString(), "b7d126751b68ecd09e371a23898e6819dee54708a5ead4f6fe83cdc79c0f1c4a")
XCTAssertEqual(data.metadata?.typeOfUser, .v2)
XCTAssertEqual(data.metadata?.upgraded, false)
}
Expand Down Expand Up @@ -188,7 +185,7 @@ final class SapphireTest: XCTestCase {
XCTAssertNotEqual(data.sessionData?.sessionAuthKey, "")
XCTAssertEqual(data.metadata?.pubNonce?.x, "5d03a0df9b3db067d3363733df134598d42873bb4730298a53ee100975d703cc")
XCTAssertEqual(data.metadata?.pubNonce?.y, "279434dcf0ff22f077877a70bcad1732412f853c96f02505547f7ca002b133ed")
XCTAssertEqual(data.metadata?.nonce?.serialize().hexString, "b7d126751b68ecd09e371a23898e6819dee54708a5ead4f6fe83cdc79c0f1c4a")
XCTAssertEqual(data.metadata?.nonce?.serialize().toHexString(), "b7d126751b68ecd09e371a23898e6819dee54708a5ead4f6fe83cdc79c0f1c4a")
XCTAssertEqual(data.metadata?.typeOfUser, .v2)
XCTAssertEqual(data.metadata?.upgraded, false)
}
Expand Down Expand Up @@ -291,7 +288,7 @@ final class SapphireTest: XCTestCase {
XCTAssertNotEqual(result.sessionData?.sessionAuthKey, "")
XCTAssertEqual(result.metadata?.pubNonce?.x, "5712d789f7ecf3435dd9bf1136c2daaa634f0222d64e289d2abe30a729a6a22b")
XCTAssertEqual(result.metadata?.pubNonce?.y, "2d2b4586fd5fd9d15c22f66b61bc475742754a8b96d1edb7b2590e4c4f97b3f0")
XCTAssertEqual(result.metadata?.nonce?.serialize().hexString, "8e80e560ae59319938f7ef727ff2c5346caac1c7f5be96d3076e3342ad1d20b7")
XCTAssertEqual(result.metadata?.nonce?.serialize().toHexString(), "8e80e560ae59319938f7ef727ff2c5346caac1c7f5be96d3076e3342ad1d20b7")
XCTAssertEqual(result.metadata?.typeOfUser, .v2)
XCTAssertEqual(result.metadata?.upgraded, false)
}
Expand Down Expand Up @@ -369,7 +366,7 @@ final class SapphireTest: XCTestCase {
let msg = "hello test data"
let encryptData = try torus.encrypt(publicKey: pk.toPublic().serialize(compressed: false), msg: msg)

let curveMsg = try Encryption.encrypt(pk: pk.toPublic(), data: msg.data(using: .utf8)!)
let curveMsg = try Encryption.encrypt(pk: pk.toPublic(), plainText: msg.data(using: .utf8)!)
let em = try EncryptedMessage(cipherText: encryptData.ciphertext, ephemeralPublicKey: PublicKey(hex: encryptData.ephemPublicKey) , iv: encryptData.iv, mac: encryptData.mac)

let eciesData = ECIES(iv: encryptData.iv, ephemPublicKey: encryptData.ephemPublicKey, ciphertext: encryptData.ciphertext, mac: encryptData.mac)
Expand Down

0 comments on commit 8ea9262

Please sign in to comment.