Skip to content

Commit

Permalink
fix: decoding in initialize
Browse files Browse the repository at this point in the history
  • Loading branch information
metalurgical committed Oct 25, 2024
1 parent 4514ea7 commit bd63d08
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/Web3Auth/session-manager-swift.git",
"state" : {
"revision" : "90afccc0e5e2ea8d671cdacb26899f60740b4e0b",
"version" : "6.0.0"
"revision" : "d86cd2a7f6d8095531ed609c728d851820fe85be",
"version" : "6.0.1"
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion SingleFactorAuth.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |spec|
spec.name = "SingleFactorAuth"
spec.version = "9.0.1"
spec.version = "9.0.2"
spec.ios.deployment_target = "14.0"
spec.summary = "Enable one key flow for Web3Auth"
spec.homepage = "https://github.com/Web3Auth/single-factor-auth-swift"
Expand Down
11 changes: 10 additions & 1 deletion Sources/SingleFactorAuth/SingleFactorAuth.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,21 @@ public class SingleFactorAuth {
if savedSessionId != nil && !savedSessionId!.isEmpty {
sessionManager.setSessionId(sessionId: savedSessionId!)

// TODO: FIXME!!! Underlying dependency must use codable as a return type and not [String: Any] since it makes life difficult for ourselves unnecessarily
let data = try await sessionManager.authorizeSession(origin: Bundle.main.bundleIdentifier ?? "single-factor-auth-swift")
guard let privKey = data["privateKey"] as? String,
let publicAddress = data["publicAddress"] as? String,
let userInfo = data["userInfo"],
let signatures = data["signatures"] else { throw SessionManagerError.decodingError }
state = SessionData(privateKey: privKey, publicAddress: publicAddress, signatures: signatures as? TorusKey.SessionData, userInfo: userInfo as? UserInfo)

let jsonInfo = try JSONSerialization.data(withJSONObject: userInfo, options: [])

let finalUserInfo = try JSONDecoder().decode(UserInfo.self, from: jsonInfo)

let jsonData = try JSONSerialization.data(withJSONObject: signatures, options: [])

let finalSignatures = try JSONDecoder().decode(TorusKey.SessionData.self, from: jsonData)
state = SessionData(privateKey: privKey, publicAddress: publicAddress, signatures: finalSignatures, userInfo: finalUserInfo)
}
}

Expand Down

0 comments on commit bd63d08

Please sign in to comment.