From 40853350d012afc6e2a0791960f6748ab6e6223f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Bruus=20Zeppelin?= Date: Wed, 9 Oct 2024 10:32:08 +0200 Subject: [PATCH] Make retroactive protocol conformance backwards compatible --- Sources/Concordium/Domain/Account.swift | 2 +- Sources/Concordium/Domain/Identity.swift | 14 +++---- Sources/Concordium/Domain/Queries.swift | 2 +- Sources/Concordium/Domain/Types.swift | 38 ++++++++++--------- Sources/Concordium/Proofs/Id.swift | 8 ++-- Sources/Concordium/Proofs/Web3Id.swift | 16 ++++---- .../ConcordiumExampleClient/commands.swift | 10 ++--- 7 files changed, 46 insertions(+), 44 deletions(-) diff --git a/Sources/Concordium/Domain/Account.swift b/Sources/Concordium/Domain/Account.swift index d1352f4..4b1bedf 100644 --- a/Sources/Concordium/Domain/Account.swift +++ b/Sources/Concordium/Domain/Account.swift @@ -406,7 +406,7 @@ extension VerifyKey: Codable { } } -extension VerifyKey: @retroactive CustomStringConvertible { +extension ConcordiumWalletCrypto.VerifyKey: Swift.CustomStringConvertible { public var description: String { "\(key.hex)" } } diff --git a/Sources/Concordium/Domain/Identity.swift b/Sources/Concordium/Domain/Identity.swift index 84e2c9f..c0c672c 100644 --- a/Sources/Concordium/Domain/Identity.swift +++ b/Sources/Concordium/Domain/Identity.swift @@ -43,7 +43,7 @@ extension AnonymityRevokerInfo: FromGRPC { } } -extension IdentityObject: @retroactive Decodable { +extension ConcordiumWalletCrypto.IdentityObject: Swift.Decodable { enum CodingKeys: CodingKey { case preIdentityObject case attributeList @@ -60,7 +60,7 @@ extension IdentityObject: @retroactive Decodable { } } -extension PreIdentityObject: @retroactive Decodable { +extension ConcordiumWalletCrypto.PreIdentityObject: Swift.Decodable { enum CodingKeys: CodingKey { case idCredPub case ipArData @@ -90,7 +90,7 @@ extension PreIdentityObject: @retroactive Decodable { } } -extension AnonymityRevokerData: @retroactive Decodable { +extension ConcordiumWalletCrypto.ArData: Swift.Decodable { enum CodingKeys: CodingKey { case encPrfKeyShare case proofComEncEq @@ -105,7 +105,7 @@ extension AnonymityRevokerData: @retroactive Decodable { } } -extension ChoiceArParameters: @retroactive Decodable { +extension ConcordiumWalletCrypto.ChoiceArParameters: Swift.Decodable { enum CodingKeys: CodingKey { case arIdentities case threshold @@ -120,7 +120,7 @@ extension ChoiceArParameters: @retroactive Decodable { } } -extension AttributeList: @retroactive Decodable { +extension ConcordiumWalletCrypto.AttributeList: Swift.Decodable { enum CodingKeys: CodingKey { case validTo case createdAt @@ -145,7 +145,7 @@ extension Description: FromGRPC { } } -extension Description: @retroactive Decodable { +extension ConcordiumWalletCrypto.Description: Swift.Decodable { /// Fields used in Wallet Proxy response. enum CodingKeys: CodingKey { case name @@ -285,7 +285,7 @@ public struct IdentityRecoveryError: Decodable, Error { /// [here](https://docs.google.com/spreadsheets/d/1CxpFvtAoUcylHQyeBtRBaRt1zsibtpmQOVsk7bsHPGA/edit). public typealias AttributeTag = ConcordiumWalletCrypto.AttributeTag -extension AttributeTag: @retroactive CustomStringConvertible, @retroactive CaseIterable, @retroactive CodingKeyRepresentable { +extension ConcordiumWalletCrypto.AttributeTag: Swift.CustomStringConvertible, Swift.CaseIterable, Swift.CodingKeyRepresentable { public enum CodingKeys: CodingKey { case firstName case lastName diff --git a/Sources/Concordium/Domain/Queries.swift b/Sources/Concordium/Domain/Queries.swift index e8b2c11..6787310 100644 --- a/Sources/Concordium/Domain/Queries.swift +++ b/Sources/Concordium/Domain/Queries.swift @@ -14,7 +14,7 @@ extension CryptographicParameters: FromGRPC { } } -extension CryptographicParameters: @retroactive Decodable { +extension ConcordiumWalletCrypto.GlobalContext: Swift.Decodable { private enum CodingKeys: CodingKey { case onChainCommitmentKey case bulletproofGenerators diff --git a/Sources/Concordium/Domain/Types.swift b/Sources/Concordium/Domain/Types.swift index b3e8b5a..58934a0 100644 --- a/Sources/Concordium/Domain/Types.swift +++ b/Sources/Concordium/Domain/Types.swift @@ -5,7 +5,7 @@ import NIO /// Describes the official public networks available for the concordium blockchain public typealias Network = ConcordiumWalletCrypto.Network -extension Network: @retroactive Codable { +extension ConcordiumWalletCrypto.Network: Swift.Codable { private enum JSON: String, Codable { case mainnet case testnet @@ -414,22 +414,7 @@ extension ScheduledTransfer: FromGRPC { /// Represents a contract address on chain public typealias ContractAddress = ConcordiumWalletCrypto.ContractAddress -extension ContractAddress: Serialize, Deserialize, FromGRPC, ToGRPC, @retroactive Codable { - public func encode(to encoder: any Encoder) throws { - try JSON(index: index, subindex: subindex).encode(to: encoder) - } - - public init(from decoder: any Decoder) throws { - let container = try decoder.singleValueContainer() - let value = try container.decode(JSON.self) - self = .init(index: value.index, subindex: value.subindex) - } - - struct JSON: Codable { - var index: UInt64 - var subindex: UInt64 - } - +extension ContractAddress: Serialize, Deserialize, FromGRPC, ToGRPC { public func serializeInto(buffer: inout NIOCore.ByteBuffer) -> Int { buffer.writeInteger(index) + buffer.writeInteger(subindex) } @@ -452,7 +437,24 @@ extension ContractAddress: Serialize, Deserialize, FromGRPC, ToGRPC, @retroactiv } } -extension ContractAddress: @retroactive CustomStringConvertible { +extension ConcordiumWalletCrypto.ContractAddress: Swift.Codable { + public func encode(to encoder: any Encoder) throws { + try JSON(index: index, subindex: subindex).encode(to: encoder) + } + + public init(from decoder: any Decoder) throws { + let container = try decoder.singleValueContainer() + let value = try container.decode(JSON.self) + self = .init(index: value.index, subindex: value.subindex) + } + + struct JSON: Codable { + var index: UInt64 + var subindex: UInt64 + } +} + +extension ConcordiumWalletCrypto.ContractAddress: Swift.CustomStringConvertible { public var description: String { "<\(index),\(subindex)>" } diff --git a/Sources/Concordium/Proofs/Id.swift b/Sources/Concordium/Proofs/Id.swift index dadcf20..ff3c19b 100644 --- a/Sources/Concordium/Proofs/Id.swift +++ b/Sources/Concordium/Proofs/Id.swift @@ -162,7 +162,7 @@ extension AtomicIdentityStatement { } } -extension AtomicIdentityStatement: @retroactive Codable { +extension ConcordiumWalletCrypto.AtomicIdentityStatement: Swift.Codable { public func encode(to encoder: any Encoder) throws { var container = encoder.singleValueContainer() try container.encode(toSDK()) @@ -329,7 +329,7 @@ extension AtomicIdentityProof { } } -extension AtomicIdentityProof: @retroactive Codable { +extension ConcordiumWalletCrypto.AtomicIdentityProof: Swift.Codable { public func encode(to encoder: any Encoder) throws { var container = encoder.singleValueContainer() try container.encode(toSDK()) @@ -346,7 +346,7 @@ extension AtomicIdentityProof: @retroactive Codable { */ public typealias IdentityProof = ConcordiumWalletCrypto.IdentityProof -extension IdentityProof: @retroactive Codable { +extension ConcordiumWalletCrypto.IdentityProof: Swift.Codable { private struct JSON: Codable { let proofs: [AtomicIdentityProof] } @@ -368,7 +368,7 @@ extension IdentityProof: @retroactive Codable { */ public typealias VersionedIdentityProof = ConcordiumWalletCrypto.VersionedIdentityProof -extension VersionedIdentityProof: @retroactive Codable { +extension ConcordiumWalletCrypto.VersionedIdentityProof: Swift.Codable { private typealias JSON = Versioned public func encode(to encoder: any Encoder) throws { diff --git a/Sources/Concordium/Proofs/Web3Id.swift b/Sources/Concordium/Proofs/Web3Id.swift index 98e5fb2..2a5a032 100644 --- a/Sources/Concordium/Proofs/Web3Id.swift +++ b/Sources/Concordium/Proofs/Web3Id.swift @@ -8,7 +8,7 @@ import Foundation /// proofs. public typealias Web3IdAttribute = ConcordiumWalletCrypto.Web3IdAttribute -extension Web3IdAttribute: @retroactive Codable { +extension ConcordiumWalletCrypto.Web3IdAttribute: Swift.Codable { private enum AttributeType: String, Codable { case dateTime = "date-time" } @@ -130,7 +130,7 @@ extension AtomicWeb3IdStatement { } } -extension AtomicWeb3IdStatement: @retroactive Codable { +extension ConcordiumWalletCrypto.AtomicWeb3IdStatement: Swift.Codable { public func encode(to encoder: any Encoder) throws { var container = encoder.singleValueContainer() try container.encode(toSDK()) @@ -161,7 +161,7 @@ public typealias Web3IdStatementWithProof = ConcordiumWalletCrypto.Web3IdStateme /// Commitments signed by the issuer. public typealias SignedCommitments = ConcordiumWalletCrypto.SignedCommitments -extension SignedCommitments: @retroactive Codable { +extension ConcordiumWalletCrypto.SignedCommitments: Swift.Codable { private struct JSON: Codable { let signature: String // HexString let commitments: [String: String] // [String: HexString] @@ -188,7 +188,7 @@ extension SignedCommitments: @retroactive Codable { /// Describes the differnet decentralized identifier variants public typealias DID = ConcordiumWalletCrypto.Did -extension DID: @retroactive Codable { +extension ConcordiumWalletCrypto.Did: Swift.Codable { public init(from decoder: any Decoder) throws { let container = try decoder.singleValueContainer() let value = try container.decode(String.self) @@ -215,7 +215,7 @@ func getDateFormatter() -> ISO8601DateFormatter { * `Account` proof. */ public typealias VerifiableCredentialProof = ConcordiumWalletCrypto.VerifiableCredentialProof -extension VerifiableCredentialProof: @retroactive Codable { +extension ConcordiumWalletCrypto.VerifiableCredentialProof: Swift.Codable { private enum CodingKeys: CodingKey { case credentialSubject case type @@ -370,7 +370,7 @@ extension VerifiableCredentialProof: @retroactive Codable { /// the presentation. At present this is a list of signatures. public typealias LinkingProof = ConcordiumWalletCrypto.LinkingProof -extension LinkingProof: @retroactive Codable { +extension ConcordiumWalletCrypto.LinkingProof: Swift.Codable { private struct JSON: Codable { /// Always "ConcordiumWeakLinkingProofV1" let type: String @@ -423,7 +423,7 @@ public extension VerifiablePresentation { } } -extension VerifiablePresentation: @retroactive Codable { +extension ConcordiumWalletCrypto.VerifiablePresentation: Swift.Codable { private struct JSON: Codable { /// Always "VerifiablePresentation" let type: String @@ -798,7 +798,7 @@ extension AtomicWeb3IdProof { } } -extension AtomicWeb3IdProof: @retroactive Codable { +extension ConcordiumWalletCrypto.AtomicWeb3IdProof: Swift.Codable { public func encode(to encoder: any Encoder) throws { var container = encoder.singleValueContainer() try container.encode(toSDK()) diff --git a/examples/CLI/Sources/ConcordiumExampleClient/commands.swift b/examples/CLI/Sources/ConcordiumExampleClient/commands.swift index 8fbd642..e2e0722 100644 --- a/examples/CLI/Sources/ConcordiumExampleClient/commands.swift +++ b/examples/CLI/Sources/ConcordiumExampleClient/commands.swift @@ -30,7 +30,7 @@ struct WalletProxyOptions: ParsableArguments { } } -extension BlockIdentifier: @retroactive ExpressibleByArgument { +extension Concordium.BlockIdentifier: ArgumentParser.ExpressibleByArgument { public init?(argument: String) { do { self = try .hash(BlockHash(fromHex: argument)) @@ -40,7 +40,7 @@ extension BlockIdentifier: @retroactive ExpressibleByArgument { } } -extension AccountAddress: @retroactive ExpressibleByArgument { +extension Concordium.AccountAddress: ArgumentParser.ExpressibleByArgument { public init?(argument: String) { do { try self.init(base58Check: argument) @@ -50,7 +50,7 @@ extension AccountAddress: @retroactive ExpressibleByArgument { } } -extension ModuleReference: @retroactive ExpressibleByArgument { +extension Concordium.ModuleReference: ArgumentParser.ExpressibleByArgument { public init?(argument: String) { do { try self.init(Data(hex: argument)) @@ -60,7 +60,7 @@ extension ModuleReference: @retroactive ExpressibleByArgument { } } -extension ReceiveName: @retroactive ExpressibleByArgument { +extension Concordium.ReceiveName: ArgumentParser.ExpressibleByArgument { public init?(argument: String) { do { try self.init(argument) @@ -70,7 +70,7 @@ extension ReceiveName: @retroactive ExpressibleByArgument { } } -extension CCD: @retroactive ExpressibleByArgument { +extension Concordium.CCD: ArgumentParser.ExpressibleByArgument { public init?(argument: String) { do { try self.init(argument, decimalSeparator: ".")