Skip to content

Commit

Permalink
fix: missing else case for v1 in retrieveShares
Browse files Browse the repository at this point in the history
  • Loading branch information
metalurgical committed Oct 9, 2023
1 parent 2fe6350 commit cb7ccea
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 6 additions & 2 deletions Sources/TorusUtils/TorusUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,13 @@ open class TorusUtils: AbstractTorusUtils {
let newkey = "04" + (nonceResult.pubNonce?.x.addLeading0sForLength64())! + (nonceResult.pubNonce?.y.addLeading0sForLength64())!
finalPubKey = combinePublicKeys(keys: [finalPubKey, newkey], compressed: false)
pubKeyNonceResult = .init(x: nonceResult.pubNonce!.x, y: nonceResult.pubNonce!.y)
} else {
// for imported keys in legacy networks
metadataNonce = try await getMetadata(dictionary: ["pub_key_X": oAuthKeyX, "pub_key_Y": oAuthKeyY])
var privateKeyWithNonce = BigInt(metadataNonce) + BigInt(oAuthKey, radix: 16)!
privateKeyWithNonce = privateKeyWithNonce.modulus(modulusValue)
finalPubKey = (SECP256K1.privateToPublic(privateKey: Data(hex: String(privateKeyWithNonce, radix: 16).addLeading0sForLength64()))?.toHexString())!
}


} else {
// for imported keys in legacy networks
metadataNonce = try await getMetadata(dictionary: ["pub_key_X": oAuthKeyX, "pub_key_Y": oAuthKeyY])
Expand Down
2 changes: 2 additions & 0 deletions Tests/TorusUtilsTests/oneKeyTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ class OneKeyTest: XCTestCase {
let extraParams = ["verifier_id": verifierID] as [String: Codable]
let nodeDetails = try await getFNDAndTUData(verifer: verifier, veriferID: verifierID)
let data = try await tu.retrieveShares(endpoints: nodeDetails.getTorusNodeEndpoints(), torusNodePubs: nodeDetails.getTorusNodePub(), indexes: nodeDetails.getTorusIndexes(), verifier: verifier, verifierParams: verifierParams, idToken: jwt, extraParams: extraParams)
XCTAssertEqual(data.oAuthKeyData?.privKey, "068ee4f97468ef1ae95d18554458d372e31968190ae38e377be59d8b3c9f7a25")
XCTAssertEqual(data.oAuthKeyData?.evmAddress, "0xEfd7eDAebD0D99D1B7C8424b54835457dD005Dc4")
XCTAssertEqual(data.finalKeyData?.privKey, "296045a5599afefda7afbdd1bf236358baff580a0fe2db62ae5c1bbe817fbae4")
XCTAssertEqual(data.finalKeyData?.evmAddress, "0x53010055542cCc0f2b6715a5c53838eC4aC96EF7")
}
Expand Down

0 comments on commit cb7ccea

Please sign in to comment.