1
1
import Builders
2
2
import Core
3
3
import Domain
4
+ import eudi_lib_sdjwt_swift
4
5
import Logging
5
6
import JSONWebSignature
6
7
import JSONWebToken
@@ -99,6 +100,44 @@ final class PresentationExchangeFlowTests: XCTestCase {
99
100
}
100
101
}
101
102
103
+ func testSDJWTPresentationRequest( ) async throws {
104
+ let prismDID = try await edgeAgent. createNewPrismDID ( )
105
+ let subjectDID = try await edgeAgent. createNewPrismDID ( )
106
+
107
+ let sdjwt = try await makeCredentialSDJWT ( issuerDID: prismDID, subjectDID: subjectDID)
108
+ let credential = try SDJWTCredential ( sdjwtString: sdjwt)
109
+
110
+ logger. info ( " Creating presentation request " )
111
+ let message = try await edgeAgent. initiatePresentationRequest (
112
+ type: . jwt,
113
+ fromDID: DID ( method: " test " , methodId: " alice " ) ,
114
+ toDID: DID ( method: " test " , methodId: " bob " ) ,
115
+ claimFilters: [
116
+ . init(
117
+ paths: [ " $.vc.credentialSubject.test " ] ,
118
+ type: " string " ,
119
+ required: true ,
120
+ pattern: " aliceTest "
121
+ )
122
+ ]
123
+ )
124
+
125
+ try await edgeAgent. pluto. storeMessage ( message: message. makeMessage ( ) , direction: . sent) . first ( ) . await ( )
126
+
127
+ let presentation = try await edgeAgent. createPresentationForRequestProof (
128
+ request: message,
129
+ credential: credential
130
+ )
131
+
132
+ let verification = try await edgeAgent. pollux. verifyPresentation (
133
+ message: presentation. makeMessage ( ) ,
134
+ options: [ ]
135
+ )
136
+
137
+ logger. info ( verification ? " Verification was successful " : " Verification failed " )
138
+ XCTAssertTrue ( verification)
139
+ }
140
+
102
141
private func makeCredentialJWT( issuerDID: DID , subjectDID: DID ) async throws -> String {
103
142
let payload = MockCredentialClaim (
104
143
iss: issuerDID. string,
@@ -121,6 +160,31 @@ final class PresentationExchangeFlowTests: XCTestCase {
121
160
}
122
161
return try JWT . signed ( payload: payload, protectedHeader: jwsHeader, key: jwkD. toJoseJWK ( ) ) . jwtString
123
162
}
163
+
164
+ private func makeCredentialSDJWT( issuerDID: DID , subjectDID: DID ) async throws -> String {
165
+ guard
166
+ let key = try await edgeAgent. pluto. getDIDPrivateKeys ( did: issuerDID) . first ( ) . await ( ) ? . first,
167
+ let jwkD = try await edgeAgent. apollo. restorePrivateKey ( key) . exporting? . jwk
168
+ else {
169
+ XCTFail ( )
170
+ fatalError ( )
171
+ }
172
+
173
+ let sdjwt = try SDJWTIssuer . issue (
174
+ issuersPrivateKey: try jwkD. toJoseJWK ( ) ,
175
+ header: DefaultJWSHeaderImpl ( algorithm: . ES256K)
176
+ ) {
177
+ ConstantClaims . iss ( domain: issuerDID. string)
178
+ ConstantClaims . sub ( subject: subjectDID. string)
179
+ ObjectClaim ( " vc " ) {
180
+ ObjectClaim ( " credentialSubject " ) {
181
+ FlatDisclosedClaim ( " test " , " aliceTest " )
182
+ }
183
+ }
184
+ }
185
+
186
+ return CompactSerialiser ( signedSDJWT: sdjwt) . serialised
187
+ }
124
188
}
125
189
126
190
private struct MockCredentialClaim : JWTRegisteredFieldsClaims , Codable {
0 commit comments