diff --git a/Package.resolved b/Package.resolved index 058df121..36c79bbd 100644 --- a/Package.resolved +++ b/Package.resolved @@ -21,11 +21,11 @@ }, { "package": "CryptoSwift", - "repositoryURL": "https://github.com/krzyzanowskim/CryptoSwift.git", + "repositoryURL": "https://github.com/krzyzanowskim/CryptoSwift", "state": { "branch": null, - "revision": "32f641cf24fc7abc1c591a2025e9f2f572648b0f", - "version": "1.7.2" + "revision": "7892a123f7e8d0fe62f9f03728b17bbd4f94df5c", + "version": "1.8.1" } }, { @@ -48,11 +48,11 @@ }, { "package": "jwt-kit", - "repositoryURL": "https://github.com/vapor/jwt-kit.git", + "repositoryURL": "https://github.com/vapor/jwt-kit", "state": { "branch": null, - "revision": "9e929d925434b91857661bcd455d1bd53f00bf22", - "version": "4.13.0" + "revision": "e05513b5aec24f88012b6e3034115b6bc915356a", + "version": "4.13.2" } }, { @@ -60,8 +60,8 @@ "repositoryURL": "https://github.com/apple/swift-crypto.git", "state": { "branch": null, - "revision": "60f13f60c4d093691934dc6cfdf5f508ada1f894", - "version": "2.6.0" + "revision": "f0525da24dc3c6cbb2b6b338b65042bc91cbc4bb", + "version": "3.3.0" } } ] diff --git a/Package.swift b/Package.swift index 70975ef7..5ca19183 100644 --- a/Package.swift +++ b/Package.swift @@ -24,7 +24,11 @@ let package = Package( targets: [ .target( name: "TorusUtils", - dependencies: ["FetchNodeDetails", "CryptoSwift", "AnyCodable", .product(name: "curveSecp256k1", package: "curvelib.swift")]), + dependencies: ["FetchNodeDetails", "CryptoSwift", "AnyCodable", + .product(name: "curveSecp256k1", package: "curvelib.swift"), + .product(name: "encryption_aes_cbc_sha512", package: "curvelib.swift"), + ] + ), .testTarget( name: "TorusUtilsTests", dependencies: ["TorusUtils", .product(name: "JWTKit", package: "jwt-kit")] diff --git a/Sources/TorusUtils/Extensions/TorusUtils+extension.swift b/Sources/TorusUtils/Extensions/TorusUtils+extension.swift index 507c5a3c..5ecdbf1d 100644 --- a/Sources/TorusUtils/Extensions/TorusUtils+extension.swift +++ b/Sources/TorusUtils/Extensions/TorusUtils+extension.swift @@ -687,7 +687,7 @@ extension TorusUtils { let ephemPrivateKey = SecretKey() let ephemPublicKey = try ephemPrivateKey.toPublic() - let sharedSecret = try ecdh_sha512(publicKey: ephemPublicKey, privateKey: ephemPrivateKey) + let sharedSecret = try ecdh_sha512(publicKey: PublicKey(hex: publicKey), privateKey: ephemPrivateKey) let encryptionKey = Array(sharedSecret[0 ..< 32]) let macKey = Array(sharedSecret[32 ..< 64]) diff --git a/Tests/TorusUtilsTests/SapphireTest.swift b/Tests/TorusUtilsTests/SapphireTest.swift index 55474525..05daf893 100644 --- a/Tests/TorusUtilsTests/SapphireTest.swift +++ b/Tests/TorusUtilsTests/SapphireTest.swift @@ -4,6 +4,8 @@ import JWTKit import XCTest import CommonSources +import curveSecp256k1 +import encryption_aes_cbc_sha512 @testable import TorusUtils @@ -356,5 +358,33 @@ final class SapphireTest: XCTestCase { } } + + func testencryption() async throws { + let torus = TorusUtils(enableOneKey: true, network: .sapphire(.SAPPHIRE_MAINNET), clientId: "YOUR_CLIENT_ID") + + let pk = curveSecp256k1.SecretKey() + let pk_str = try pk.serialize() + + 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 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) +// let emp = try curveMsg.ephemeralPublicKey().serialize(compressed: false); +// let eciesData2 = try ECIES(iv: curveMsg.iv(), ephemPublicKey: emp, ciphertext: curveMsg.chipherText(), mac: curveMsg.mac()) + + let decrypteData = try torus.decrypt(privateKey: pk_str, opts: eciesData) +// let decrypteData2 = try torus.decrypt(privateKey: pk_str, opts: eciesData2) + +// let result = try Encryption.decrypt(sk: pk, encrypted: em) +// let result2 = try Encryption.decrypt(sk: pk, encrypted: curveMsg) + + XCTAssertEqual(msg.data(using: .utf8)!, decrypteData) +// XCTAssertEqual(msg.data(using: .utf8)!, result2) + + } }