@@ -96,4 +96,54 @@ public struct P256Operations {
9696 return false
9797 }
9898 }
99+
100+ // MARK: - With SessionToken
101+
102+ /// Verifies a DID-based signature from a session token.
103+ ///
104+ /// A ``SessionToken`` instance must be created before calling this method. The reason for this instead
105+ /// of the method itself having to call the method is to help in ensuring the session token was
106+ /// actually used.
107+ ///
108+ /// - Parameters:
109+ /// - did: The DID of the signer.
110+ /// - data: The original message that was signed.
111+ /// - sessionToken: The session token containing the signature to verify.
112+ /// - options: Optional verification settings. Optional. Defaults to `nil`.
113+ /// - Returns: `true` if the signature is valid, otherwise `false`.
114+ ///
115+ /// - Throws: An error if the DID is not a valid p256 `did:key`.
116+ public static func verifyDIDSignature( did: String , data: [ UInt8 ] , sessionToken: SessionToken , options: VerifyOptions ? = nil ) async throws -> Bool {
117+ let jwt = sessionToken
118+
119+ guard let signature = jwt. signature else {
120+ throw SignatureVerificationError . invalidEncoding ( reason: " No valid signature found in the provided session token. " )
121+ }
122+
123+ return try await P256Operations . verifyDIDSignature ( did: did, data: data, signature: [ UInt8] ( signature) , options: options)
124+ }
125+
126+ /// Verifies a p256 signature from a session token.
127+ ///
128+ /// A ``SessionToken`` instance must be created before calling this method. The reason for this instead
129+ /// of the method itself having to call the method is to help in ensuring the session token was
130+ /// actually used.
131+ ///
132+ /// - Parameters:
133+ /// - publicKey: The public key in raw bytes.
134+ /// - data: The original message that was signed.
135+ /// - sessionToken: The session token containing the signature to verify.
136+ /// - options: Options for signature verification. Optional. Defaults to `nil`.
137+ /// - Returns: `true` if the signature is valid, or `false` if not.
138+ ///
139+ /// - Throws: An error if signature verification fails.
140+ public static func verifySignature( publicKey: [ UInt8 ] , data: [ UInt8 ] , sessionToken: SessionToken , options: VerifyOptions ? = nil ) async throws -> Bool {
141+ let jwt = sessionToken
142+
143+ guard let signature = jwt. signature else {
144+ throw SignatureVerificationError . invalidEncoding ( reason: " No valid signature found in the provided session token. " )
145+ }
146+
147+ return try await P256Operations . verifySignature ( publicKey: publicKey, data: data, signature: [ UInt8] ( signature) , options: options)
148+ }
99149}
0 commit comments