Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
2 changes: 1 addition & 1 deletion Sources/TorusUtils/Extensions/TorusUtils+extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
30 changes: 30 additions & 0 deletions Tests/TorusUtilsTests/SapphireTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import JWTKit
import XCTest

import CommonSources
import curveSecp256k1
import encryption_aes_cbc_sha512

@testable import TorusUtils

Expand Down Expand Up @@ -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)

}

}