Skip to content

Commit

Permalink
refactor: update to latest torusutils
Browse files Browse the repository at this point in the history
  • Loading branch information
metalurgical committed Oct 6, 2024
1 parent 00ed189 commit 3d98988
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ let package = Package(
dependencies: [
// Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"),
.package(name: "TorusUtils", url: "https://github.com/torusresearch/torus-utils-swift" , from: "9.0.0"),
.package(name: "TorusUtils", url: "https://github.com/torusresearch/torus-utils-swift", branch: "encapsulate_torusnetwork"),
// dev dependencies only
.package(name:"jwt-kit", url: "https://github.com/vapor/jwt-kit.git", from: "4.0.0"),
],
Expand Down
12 changes: 6 additions & 6 deletions Sources/ThresholdKey/Modules/TssModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -540,27 +540,27 @@ public final class TssModule {
public static func find_device_share_index(threshold_key: ThresholdKey, factor_key: String) async throws -> String {
let result = try await threshold_key.storage_layer_get_metadata(private_key: factor_key)
guard let resultData = result.data(using: .utf8) else {
throw "Invalid factor key"
throw RuntimeError("Invalid factor key")
}
guard let resultJson = try JSONSerialization.jsonObject(with: resultData) as? [String: Any] else {
throw "Invalid factor key"
throw RuntimeError("Invalid factor key")
}

var deviceShareJson = resultJson;

// backward competible
if resultJson["deviceShare"] != nil {
guard let deviceShare = resultJson["deviceShare"] as? [String: Any] else {
throw "Invalid factor key"
throw RuntimeError("Invalid factor key")
}
deviceShareJson = deviceShare
}

guard let shareJson = deviceShareJson["share"] as? [String: Any] else {
throw "Invalid factor key"
throw RuntimeError("Invalid factor key")
}
guard let shareIndex = shareJson["shareIndex"] as? String else {
throw "Invalid factor key"
throw RuntimeError("Invalid factor key")
}
return shareIndex
}
Expand All @@ -579,7 +579,7 @@ public final class TssModule {
let extendedVerifierId = try threshold_key.get_extended_verifier_id()
let split = extendedVerifierId.components(separatedBy: "\u{001c}")

let result = try await torusUtils.getPublicAddress(endpoints: nodeDetails.torusNodeEndpoints, verifier: split[0], verifierId: split[1], extendedVerifierId: "\(split[1])\u{0015}\(tssTag)\u{0016}\(nonce)")
let result = try await torusUtils.getPublicAddress(endpoints: nodeDetails.getTorusNodeEndpoints(), verifier: split[0], verifierId: split[1], extendedVerifierId: "\(split[1])\u{0015}\(tssTag)\u{0016}\(nonce)")

guard let x = result.finalKeyData?.X, let y = result.finalKeyData?.Y, let nodeIndexes = result.nodesData?.nodeIndexes else {
throw RuntimeError("conversion error")
Expand Down
2 changes: 1 addition & 1 deletion Sources/ThresholdKey/ServiceProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public final class ServiceProvider {
let rssEndpoints = try JSONSerialization.data(withJSONObject: nodeDetails.getTorusNodeRSSEndpoints())
let tssEndpoints = try JSONSerialization.data(withJSONObject: nodeDetails.getTorusNodeTSSEndpoints())

let pub = nodeDetails.torusNodePub
let pub = nodeDetails.getTorusNodePub()
let pubkey = try JSONEncoder().encode(pub)

sss = try NodeDetails(server_endpoints: String(data: sssEndpoints, encoding: .utf8)!, server_public_keys: String(data: pubkey, encoding: .utf8)!, serverThreshold: 3)
Expand Down
12 changes: 6 additions & 6 deletions Tests/tkeypkgTests/IntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ final class integrationTests: XCTestCase {

let TORUS_TEST_VERIFIER = "torus-test-health"

let nodeManager = NodeDetailManager(network: .sapphire(.SAPPHIRE_DEVNET))
let nodeManager = NodeDetailManager(network: .SAPPHIRE_DEVNET)
let nodeDetail = try await nodeManager.getNodeDetails(verifier: TORUS_TEST_VERIFIER, verifierID: TORUS_TEST_EMAIL)
let options = TorusOptions(clientId: "CLIENT ID", network: .sapphire(.SAPPHIRE_DEVNET), serverTimeOffset: 1000)
let options = TorusOptions(clientId: "CLIENT ID", network: .SAPPHIRE_DEVNET, serverTimeOffset: 1000)
let torusUtils = try TorusUtils(params: options)

let idToken = try generateIdToken(email: TORUS_TEST_EMAIL)
let verifierParams = VerifierParams(verifier_id: TORUS_TEST_EMAIL)
let retrievedShare = try await torusUtils.retrieveShares(endpoints: nodeDetail.torusNodeEndpoints, verifier: TORUS_TEST_VERIFIER, verifierParams: verifierParams, idToken: idToken)
let retrievedShare = try await torusUtils.retrieveShares(endpoints: nodeDetail.getTorusNodeEndpoints(), verifier: TORUS_TEST_VERIFIER, verifierParams: verifierParams, idToken: idToken)

let signature_collection = retrievedShare.sessionData.sessionTokenData.map { token in
["data": token!.token,
Expand Down Expand Up @@ -123,14 +123,14 @@ final class integrationTests: XCTestCase {
var threshold: ThresholdKey!
var threshold2: ThresholdKey!

let nodeManager = NodeDetailManager(network: .sapphire(.SAPPHIRE_DEVNET))
let nodeManager = NodeDetailManager(network: .SAPPHIRE_DEVNET)
let nodeDetail = try await nodeManager.getNodeDetails(verifier: TORUS_TEST_VERIFIER, verifierID: TORUS_TEST_EMAIL)
let options = TorusOptions(clientId: "CLIENT ID", network: .sapphire(.SAPPHIRE_DEVNET), serverTimeOffset: 1000)
let options = TorusOptions(clientId: "CLIENT ID", network: .SAPPHIRE_DEVNET, serverTimeOffset: 1000)
let torusUtils = try TorusUtils(params: options)

let idToken = try generateIdToken(email: TORUS_TEST_EMAIL)
let verifierParams = VerifierParams(verifier_id: TORUS_TEST_EMAIL)
let retrievedShare = try await torusUtils.retrieveShares(endpoints: nodeDetail.torusNodeSSSEndpoints, verifier: TORUS_TEST_VERIFIER, verifierParams: verifierParams, idToken: idToken)
let retrievedShare = try await torusUtils.retrieveShares(endpoints: nodeDetail.getTorusNodeSSSEndpoints(), verifier: TORUS_TEST_VERIFIER, verifierParams: verifierParams, idToken: idToken)

let signature_collection = retrievedShare.sessionData.sessionTokenData.map { token in
["data": token!.token,
Expand Down
2 changes: 1 addition & 1 deletion Tests/tkeypkgTests/tkey_base.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import tkey
import TorusUtils

class tkey_baseTests: XCTestCase {
let options = TorusOptions(clientId: "CLIENT ID", network: .sapphire(.SAPPHIRE_DEVNET))
let options = TorusOptions(clientId: "CLIENT ID", network: .SAPPHIRE_DEVNET)
var torusUtils: TorusUtils!

override func setUp() async throws {
Expand Down
2 changes: 1 addition & 1 deletion tkey-mpc-swift.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ Pod::Spec.new do |spec|
spec.module_name = "tkey"
spec.source = { :git => "https://github.com/tkey/tkey-mpc-swift.git", :tag => spec.version }
spec.vendored_framework = "Sources/libtkey/libtkey.xcframework"
spec.dependency 'TorusUtils', '~> 9.0.0'
spec.dependency 'TorusUtils', '~> 10.0.0'
spec.source_files = "Sources/**/*.{swift,c,h}"
end

0 comments on commit 3d98988

Please sign in to comment.