From bc76c9acbd749f45a0635e4c98eaee0802c4d5a5 Mon Sep 17 00:00:00 2001 From: Marcus Arnett Date: Tue, 9 Apr 2024 19:09:19 -0400 Subject: [PATCH] Fix initializer with zkLogin Signature type, add partial --- .../zkLogin/PartialZkLoginSignature.swift | 46 +++++++++++++++++++ .../zkLogin/zkLoginSignatureInputs.swift | 12 +++++ .../zkLogin/zkLoginSignatureInputsClaim.swift | 2 +- .../zkLoginSignatureInputsProofPoints.swift | 2 +- 4 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 Sources/SuiKit/Utils/zkLogin/PartialZkLoginSignature.swift diff --git a/Sources/SuiKit/Utils/zkLogin/PartialZkLoginSignature.swift b/Sources/SuiKit/Utils/zkLogin/PartialZkLoginSignature.swift new file mode 100644 index 0000000..4fca53c --- /dev/null +++ b/Sources/SuiKit/Utils/zkLogin/PartialZkLoginSignature.swift @@ -0,0 +1,46 @@ +// +// PartialZkLoginSignature.swift +// SuiKit +// +// Copyright (c) 2024 OpenDive +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// + +import Foundation + +public struct PartialZkLoginSignature: KeyProtocol, Equatable, Codable { + public var proofPoints: zkLoginSignatureInputsProofPoints + public var issBase64Details: zkLoginSignatureInputsClaim + public var headerBase64: String + + public func serialize(_ serializer: Serializer) throws { + try Serializer._struct(serializer, value: self.proofPoints) + try Serializer._struct(serializer, value: self.issBase64Details) + try Serializer.str(serializer, self.headerBase64) + } + + public static func deserialize(from deserializer: Deserializer) throws -> PartialZkLoginSignature { + return PartialZkLoginSignature( + proofPoints: try Deserializer._struct(deserializer), + issBase64Details: try Deserializer._struct(deserializer), + headerBase64: try Deserializer.string(deserializer) + ) + } +} diff --git a/Sources/SuiKit/Utils/zkLogin/zkLoginSignatureInputs.swift b/Sources/SuiKit/Utils/zkLogin/zkLoginSignatureInputs.swift index 99f3264..11f0184 100644 --- a/Sources/SuiKit/Utils/zkLogin/zkLoginSignatureInputs.swift +++ b/Sources/SuiKit/Utils/zkLogin/zkLoginSignatureInputs.swift @@ -31,6 +31,18 @@ public struct zkLoginSignatureInputs: KeyProtocol, Equatable { public var headerBase64: String public var userSignature: String + public init( + proofPoints: zkLoginSignatureInputsProofPoints, + issBase64Details: zkLoginSignatureInputsClaim, + headerBase64: String, + userSignature: String + ) { + self.proofPoints = proofPoints + self.issBase64Details = issBase64Details + self.headerBase64 = headerBase64 + self.userSignature = userSignature + } + public func serialize(_ serializer: Serializer) throws { try Serializer._struct(serializer, value: self.proofPoints) try Serializer._struct(serializer, value: self.issBase64Details) diff --git a/Sources/SuiKit/Utils/zkLogin/zkLoginSignatureInputsClaim.swift b/Sources/SuiKit/Utils/zkLogin/zkLoginSignatureInputsClaim.swift index 34d4d96..3a2bdd9 100644 --- a/Sources/SuiKit/Utils/zkLogin/zkLoginSignatureInputsClaim.swift +++ b/Sources/SuiKit/Utils/zkLogin/zkLoginSignatureInputsClaim.swift @@ -25,7 +25,7 @@ import Foundation -public struct zkLoginSignatureInputsClaim: KeyProtocol, Equatable { +public struct zkLoginSignatureInputsClaim: KeyProtocol, Equatable, Codable { public var value: String public var indexMod4: UInt8 diff --git a/Sources/SuiKit/Utils/zkLogin/zkLoginSignatureInputsProofPoints.swift b/Sources/SuiKit/Utils/zkLogin/zkLoginSignatureInputsProofPoints.swift index e24f026..d55b12f 100644 --- a/Sources/SuiKit/Utils/zkLogin/zkLoginSignatureInputsProofPoints.swift +++ b/Sources/SuiKit/Utils/zkLogin/zkLoginSignatureInputsProofPoints.swift @@ -25,7 +25,7 @@ import Foundation -public struct zkLoginSignatureInputsProofPoints: KeyProtocol, Equatable { +public struct zkLoginSignatureInputsProofPoints: KeyProtocol, Equatable, Codable { public var a: [String] public var b: [[String]] public var c: [String]