From e40c7690e4168a1121dc0639dab09ebb80217ce1 Mon Sep 17 00:00:00 2001 From: metalurgical <97008724+metalurgical@users.noreply.github.com> Date: Mon, 20 May 2024 06:47:45 +0200 Subject: [PATCH] update --- .../jsonRPC/Requests/NonceMetadataParams.swift | 6 +++--- .../Helpers/jsonRPC/Requests/SetNonceData.swift | 16 +++++++++++++++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/Sources/TorusUtils/Helpers/jsonRPC/Requests/NonceMetadataParams.swift b/Sources/TorusUtils/Helpers/jsonRPC/Requests/NonceMetadataParams.swift index d475675d..de6b00ac 100644 --- a/Sources/TorusUtils/Helpers/jsonRPC/Requests/NonceMetadataParams.swift +++ b/Sources/TorusUtils/Helpers/jsonRPC/Requests/NonceMetadataParams.swift @@ -1,6 +1,6 @@ import Foundation -internal struct NonceMetadataParams: Codable { +internal struct NonceMetadataParams { public var namespace: String? public var pub_key_X: String public var pub_key_Y: String @@ -8,9 +8,9 @@ internal struct NonceMetadataParams: Codable { public var key_type: TorusKeyType public var signature: String public var encodedData: String - public var seed: String + public var seed: String? - public init(pub_key_X: String, pub_key_Y: String, setData: SetNonceData, encodedData: String, signature: String, namespace: String? = nil, key_type: TorusKeyType = .secp256k1, seed: String = "") { + public init(pub_key_X: String, pub_key_Y: String, setData: SetNonceData, encodedData: String, signature: String, namespace: String? = nil, key_type: TorusKeyType = .secp256k1, seed: String? = nil) { self.namespace = namespace self.pub_key_X = pub_key_X self.pub_key_Y = pub_key_Y diff --git a/Sources/TorusUtils/Helpers/jsonRPC/Requests/SetNonceData.swift b/Sources/TorusUtils/Helpers/jsonRPC/Requests/SetNonceData.swift index 432d1c01..b9461d8b 100644 --- a/Sources/TorusUtils/Helpers/jsonRPC/Requests/SetNonceData.swift +++ b/Sources/TorusUtils/Helpers/jsonRPC/Requests/SetNonceData.swift @@ -6,11 +6,25 @@ internal struct SetNonceData: Codable { public var timestamp: String? public var seed: String? - public init(operation: String? = nil, data: String? = nil, timestamp: String? = nil, seed: String = "") { + public init(operation: String? = nil, data: String? = nil, timestamp: String? = nil, seed: String? = nil) { self.operation = operation self.data = data self.timestamp = timestamp self.seed = seed } + + public func encode(to encoder: any Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encodeIfPresent(self.operation, forKey: .operation) + try container.encodeIfPresent(self.data, forKey: .data) + try container.encodeIfPresent(self.timestamp, forKey: .timestamp) + // There is a bug in the server that expects seed to be empty and not optional, when it checks signatures. It is optional in the interface as such. + if (seed == nil) { + try container.encode("", forKey: .seed) + } else { + try container.encode(self.seed, forKey: .seed) + } + + } }