Skip to content

Commit

Permalink
Merge pull request #101 from torusresearch/fix_backwards_compat_for_h…
Browse files Browse the repository at this point in the history
…ex_and_base64_tokens

fix: token could be hex or base64
  • Loading branch information
metalurgical authored Jul 30, 2024
2 parents 42caa33 + ecf4a77 commit 710a851
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
6 changes: 5 additions & 1 deletion Sources/TorusUtils/Helpers/NodeUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,11 @@ internal class NodeUtils {
if item == nil {
sessionTokenDatas.append(nil)
} else {
sessionTokenDatas.append(SessionToken(token: Data(hexString: item!)!.base64EncodedString(), signature: sessionTokenSigs[i]!.data(using: .utf8)!.hexString, node_pubx: shareResponses[i].nodePubX, node_puby: shareResponses[i].nodePubY))
if Data(hexString: item!) != nil {
sessionTokenDatas.append(SessionToken(token: Data(hexString: item!)!.base64EncodedString(), signature: sessionTokenSigs[i]!.data(using: .utf8)!.hexString, node_pubx: shareResponses[i].nodePubX, node_puby: shareResponses[i].nodePubY))
} else {
sessionTokenDatas.append(SessionToken(token: item!, signature: sessionTokenSigs[i]!.data(using: .utf8)!.hexString, node_pubx: shareResponses[i].nodePubX, node_puby: shareResponses[i].nodePubY))
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions Tests/TorusUtilsTests/SapphireDevnetTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -291,12 +291,12 @@ final class SapphireDevnetTest: XCTestCase {
let signatures = data.sessionData.sessionTokenData.map({ $0!.token })
let parsedSignatures = signatures.map({
let data = Data(base64Encoded: $0.data(using: .utf8)!)!
let hexString = String(data: data, encoding: .utf8)!
let json = hexString.hexEncodedToString()
let json = String(data: data, encoding: .utf8)!
return json
})
let now = Int(Date().timeIntervalSince1970)
for item in parsedSignatures {

let json = try JSONSerialization.jsonObject(with: item.data(using: .utf8)!) as? [String: Any]
let exp = json!["exp"] as! Int
let sessionTime = exp - now
Expand Down
3 changes: 1 addition & 2 deletions Tests/TorusUtilsTests/SapphireMainnetTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,7 @@ class SapphireMainnetTests: XCTestCase {
let signatures = data.sessionData.sessionTokenData.map({ $0!.token })
let parsedSignatures = signatures.map({
let data = Data(base64Encoded: $0.data(using: .utf8)!)!
let hexString = String(data: data, encoding: .utf8)!
let json = hexString.hexEncodedToString()
let json = String(data: data, encoding: .utf8)!
return json
})
let now = Int(Date().timeIntervalSince1970)
Expand Down

0 comments on commit 710a851

Please sign in to comment.