Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Userinfo and Signature decoding fix for initialize function #27

Merged
merged 1 commit into from
Oct 25, 2024
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
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
Loading