@@ -34,8 +34,14 @@ public struct SessionToken: Sendable, Encodable {
3434 /// the account DID's signing key."
3535 public let signature : Data ?
3636
37- /// Decodes a session token, then initializes a new instance with the results.
38- public init ( sessionToken: String ) throws {
37+ /// Verifies and decodes a session token, then initializes a new instance with the results.
38+ ///
39+ /// - Parameters:
40+ /// - sessionToken: The session token to verify and decode.
41+ /// - didKey: The `did:key` string used to verify the session token.
42+ ///
43+ /// - Throws: An error if JWT decoding fails.
44+ public init ( _ sessionToken: String , verifyingWith didKey: String ) throws {
3945 let decodedJWT = try SessionToken . decodeJWT ( sessionToken)
4046
4147 self . header = decodedJWT. header
@@ -60,13 +66,13 @@ public struct SessionToken: Sendable, Encodable {
6066 /// extract the corresponding components.
6167 ///
6268 /// - Parameter jwt: The JWT string to decode.
63- /// - Throws: A `SessionTokenError` if:
69+ /// - Returns: A tuple containing the decoded header, payload, and signature values.
70+ ///
71+ /// - Throws: A ``SessionTokenError`` if:
72+ /// - The signature can't be verified.
6473 /// - The token does not have exactly three segments.
6574 /// - Any of the segments cannot be Base64-decoded.
6675 /// - The header or payload cannot be parsed into their respective types.
67- /// - Returns: A tuple containing the decoded header, payload, and signature values.
68- ///
69- /// - Throws: ``SessionTokenError`` if the token is invalid or there are missing segments.
7076 private static func decodeJWT( _ jwt: String ) throws -> ( header: Header , payload: Payload , signature: Data ) {
7177 let segments = jwt. split ( separator: " . " )
7278 guard segments. count == 3 else {
@@ -96,7 +102,7 @@ public struct SessionToken: Sendable, Encodable {
96102 /// the "type" value.
97103 public struct Header : Sendable , Codable {
98104
99- /// The type of
105+ /// The type of the session token.
100106 ///
101107 /// - Note: According to the AT Protocol specifications: "Currently `JWT`, but intend to
102108 /// update to a more specific value."
0 commit comments