Skip to content

Commit

Permalink
wip: sapphire mainnet tests
Browse files Browse the repository at this point in the history
  • Loading branch information
metalurgical committed May 13, 2024
1 parent 8127382 commit 3162d49
Show file tree
Hide file tree
Showing 4 changed files with 413 additions and 355 deletions.
2 changes: 1 addition & 1 deletion Sources/TorusUtils/Polynomial.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public struct Polynomial {
func generateShares(shareIndexes: [BigInt]) -> ShareMap {
var shares: ShareMap = [:]
for x in 0 ..< shareIndexes.count {
let hexString = shareIndexes[x].serialize().toHexString()
let hexString = shareIndexes[x].serialize().addLeading0sForLength64().toHexString()
shares[hexString] = Share(shareIndex: shareIndexes[x], share: polyEval(x: shareIndexes[x]))
}
return shares
Expand Down
14 changes: 8 additions & 6 deletions Sources/TorusUtils/TorusUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -121,16 +121,18 @@ public class TorusUtils {
}
}

private func importPrivateKey(
public func importPrivateKey(
endpoints: [String],
nodeIndexes: [Int],
nodePubKeys: [INodePub],
nodeIndexes: [BigUInt],
nodePubKeys: [TorusNodePubModel],
verifier: String,
verifierParams: VerifierParams,
idToken: String,
newPrivateKey: String,
extraParams: [String: Codable] = [:]
) async throws -> TorusKey {
let nodePubs = TorusNodePubModelToINodePub(nodes: nodePubKeys)

if isLegacyNetwork() {
throw TorusUtilError.runtime("This function is not supported on legacy networks")
}
Expand All @@ -144,7 +146,7 @@ public class TorusUtils {
try key.addAssign(key: try randomNonce.inv())

let oAuthKey = try key.serialize().addLeading0sForLength64()
let oAuthPublicKey = try key.toPublic().serialize(compressed: false).strip04Prefix()
let oAuthPublicKey = try key.toPublic().serialize(compressed: false)

let threshold = Int(trunc(Double((endpoints.count / 2) + 1)))

Expand All @@ -167,12 +169,12 @@ public class TorusUtils {
var jsonShares: [Data] = []

for i in 0 ..< nodeIndexes.count {
let share: Share? = shares[String(nodeIndexes[i]).addLeading0sForLength64().hexa.toHexString()]
let share: Share? = shares[nodeIndexes[i].serialize().addLeading0sForLength64().hexString]
if share == nil {
throw TorusUtilError.runtime("Missing node pub key for node index")
}
let shareJson = try encoder.encode(share)
enc.append(try MetadataUtils.encrypt(publicKey: nodePubKeys[i].X + nodePubKeys[i].Y, msg: share?.share.magnitude.serialize().hexString ?? ""))
enc.append(try MetadataUtils.encrypt(publicKey: KeyUtils.getPublicKeyFromCoords(pubKeyX: nodePubs[i].X, pubKeyY: nodePubs[i].Y, prefixed: true), msg: share!.share.magnitude.serialize().hexString))
jsonShares.append(shareJson)
}

Expand Down
Loading

0 comments on commit 3162d49

Please sign in to comment.