Skip to content

Commit b91e2a4

Browse files
committed
Fixed PLC Operation lexicons and api methods per specifications
PLC Operation lexicons where incomplete and incorrect. These updates align the lexicons with the specifications. Included init, decode, encode methods too.
1 parent 5048826 commit b91e2a4

File tree

4 files changed

+126
-10
lines changed

4 files changed

+126
-10
lines changed

Sources/ATProtoKit/APIReference/ComAtprotoAPI/ComAtprotoIdentitySignPlcOperationMethod.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ extension ATProtoKit {
3838
token: String,
3939
rotationKeys: [String]? = nil,
4040
alsoKnownAs: [String]? = nil,
41-
verificationMethods: VerificationMethod?,
42-
service: ATService?
41+
verificationMethods: [String:String]?,
42+
services: [String: ComAtprotoLexicon.Identity.PLCOperationATService]?
4343
) async throws -> ComAtprotoLexicon.Identity.SignPLCOperationOutput {
4444
guard let session = try await self.getUserSession(),
4545
let keychain = sessionConfiguration?.keychainProtocol else {
@@ -59,7 +59,7 @@ extension ATProtoKit {
5959
rotationKeys: rotationKeys,
6060
alsoKnownAs: alsoKnownAs,
6161
verificationMethods: verificationMethods,
62-
service: service
62+
services: services
6363
)
6464

6565
do {

Sources/ATProtoKit/APIReference/ComAtprotoAPI/ComAtprotoIdentitySubmitPlcOperationMethod.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ extension ATProtoKit {
2626
///
2727
/// - Throws: An ``ATProtoError``-conforming error type, depending on the issue. Go to
2828
/// ``ATAPIError`` and ``ATRequestPrepareError`` for more details.
29-
public func submitPLCOperation(_ operation: UnknownType) async throws {
29+
public func submitPLCOperation(_ operation: ComAtprotoLexicon.Identity.SignedPLCOperation) async throws {
3030
guard let requestURL = URL(string: "\(self.pdsURL)/xrpc/com.atproto.identity.submitPlcOperation") else {
3131
throw ATRequestPrepareError.invalidRequestURL
3232
}

Sources/ATProtoKit/Models/Lexicons/com.atproto/Identity/ComAtprotoIdentitySignPLCOperation.swift

Lines changed: 121 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,61 @@ extension ComAtprotoLexicon.Identity {
3030
public let token: String?
3131

3232
/// The rotation keys recommended to be added in the DID document. Optional.
33+
/// An array of aliases of the user account. Optional.
34+
/// - Important: To add a new rotation key, include all existing rotation keys with the new
35+
/// rotation key.
36+
///
37+
/// - Important: To remove a rotation key, include all existing rotation keys except the
38+
/// rotation key being removed.
3339
public let rotationKeys: [String]?
3440

3541
/// An array of aliases of the user account. Optional.
42+
/// - Important: To add a new alias, include all existing aliases with the new alias.
43+
///
44+
/// - Important: To remove an alias, include all existing alias' except the alias being removed.
3645
public let alsoKnownAs: [String]?
3746

38-
/// A verification method recommeneded to be added in the DID document. Optional.
39-
public let verificationMethods: VerificationMethod?
47+
/// A dictionary of verification methods to inckude in the DID document. Optional.
48+
/// - Important: To add a new verification method, include all existing verification methods with the
49+
/// new verification method.
50+
///
51+
/// - Important: To remove a verification method, include all existing verification methods except the
52+
/// verification method being removed.
53+
public let verificationMethods: [String: String]? //VerificationMethod?
4054

41-
/// The service endpoint recommended in the DID document. Optional.
42-
public let service: ATService?
55+
/// A dictionary of service endpoints to include in the DID document. Optional.
56+
/// - Important: To add a new service endpoint, include all existing service endpoints with the
57+
/// new service endpoint.
58+
///
59+
/// - Important: To remove a service endpoint, include all existing service endpoints except the
60+
/// service endpoint being removed.
61+
public let services: [String: PLCOperationATService]? //ATService?
62+
63+
public init(token: String?, rotationKeys: [String]?, alsoKnownAs: [String]?, verificationMethods: [String : String]?, services: [String : PLCOperationATService]?) {
64+
self.token = token
65+
self.rotationKeys = rotationKeys
66+
self.alsoKnownAs = alsoKnownAs
67+
self.verificationMethods = verificationMethods
68+
self.services = services
69+
}
70+
71+
public func encode(to encoder: any Encoder) throws {
72+
var container = encoder.container(keyedBy: CodingKeys.self)
73+
74+
try container.encodeIfPresent(self.token, forKey: .token)
75+
try container.encodeIfPresent(self.rotationKeys, forKey: .rotationKeys)
76+
try container.encodeIfPresent(self.alsoKnownAs, forKey: .alsoKnownAs)
77+
try container.encodeIfPresent(self.verificationMethods, forKey: .verificationMethods)
78+
try container.encodeIfPresent(self.services, forKey: .services)
79+
}
80+
81+
enum CodingKeys: String, CodingKey {
82+
case token
83+
case rotationKeys
84+
case alsoKnownAs
85+
case verificationMethods
86+
case services
87+
}
4388
}
4489

4590
/// An output model for signing a PLC operation to a DID document.
@@ -53,6 +98,77 @@ extension ComAtprotoLexicon.Identity {
5398
public struct SignPLCOperationOutput: Sendable, Codable {
5499

55100
/// A signed PLC operation.
56-
public let operation: UnknownType
101+
public let operation: SignedPLCOperation
102+
}
103+
104+
/// Represents a service endpoint in a DID document in a PLC operation
105+
///
106+
/// - SeeAlso: This is based on the PLC Directory [`CreatePlcOp`][plc].
107+
///
108+
/// [plc]: https://web.plc.directory/api/redoc#operation/CreatePlcOp
109+
public struct PLCOperationATService: Sendable, Codable {
110+
111+
/// The type of service.
112+
public let type: String
113+
114+
/// The endpoint URL for the service, specifying the location of the service.
115+
public let serviceEndpointURI: String
116+
117+
public init(type: String, serviceEndpointURI: String) {
118+
self.type = type
119+
self.serviceEndpointURI = serviceEndpointURI
120+
}
121+
122+
public init(from decoder: any Decoder) throws {
123+
let container = try decoder.container(keyedBy: CodingKeys.self)
124+
125+
self.type = try container.decode(String.self, forKey: .type)
126+
self.serviceEndpointURI = try container.decode(String.self, forKey: .serviceEndpointURI)
127+
}
128+
129+
public func encode(to encoder: any Encoder) throws {
130+
var container = encoder.container(keyedBy: CodingKeys.self)
131+
132+
try container.encode(self.type, forKey: .type)
133+
try container.encode(self.serviceEndpointURI, forKey: .serviceEndpointURI)
134+
}
135+
136+
enum CodingKeys: String, CodingKey {
137+
case type
138+
case serviceEndpointURI = "endpoint"
139+
}
140+
}
141+
142+
/// Represents a signed PLC operation response
143+
///
144+
/// - Note: A signed PLC operation is returned in the response to calling
145+
/// [`com.atproto.identity.signPlcOperation`][github]
146+
///
147+
/// - SeeAlso: This is based on the PLC Directory [`CreatePlcOp`][plc].
148+
///
149+
/// [github]: https://github.com/bluesky-social/atproto/blob/main/lexicons/com/atproto/identity/signPlcOperation.json
150+
/// [plc]: https://web.plc.directory/api/redoc#operation/CreatePlcOp
151+
public struct SignedPLCOperation: Sendable, Codable {
152+
153+
/// The PLC operation type
154+
public let type: String
155+
156+
/// Ordered set (no duplicates) of cryptographic public keys in did:key format
157+
public let rotationKeys: [String]
158+
159+
/// Map (object) of application-specific cryptographic public keys in did:key format
160+
public let verificationMethods: [String: String]
161+
162+
/// Ordered set (no duplicates) of aliases and names for this account, in the form of URIs
163+
public let alsoKnownAs: [String]
164+
165+
/// Map (object) of application-specific service endpoints for this account
166+
public let services: [String: PLCOperationATService]
167+
168+
/// Strong reference (hash) of preceeding operation for this DID, in string CID format. Null for genesis operation
169+
public let prev: String
170+
171+
/// Cryptographic signature of this object, with base64 string encoding
172+
public let sig: String
57173
}
58174
}

Sources/ATProtoKit/Models/Lexicons/com.atproto/Identity/ComAtprotoIdentitySubmitPLCOperation.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ extension ComAtprotoLexicon.Identity {
2424
public struct SubmitPLCOperationRequestBody: Sendable, Codable {
2525

2626
/// A PLC operation.
27-
public let operation: UnknownType
27+
public let operation: SignedPLCOperation
2828
}
2929
}

0 commit comments

Comments
 (0)