Skip to content

Commit e8a4973

Browse files
feat: add sdjwt as credential type (#206)
Signed-off-by: goncalo-frade-iohk <[email protected]>
1 parent 194377a commit e8a4973

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

EdgeAgentSDK/Domain/Sources/Models/Credentials/Credential.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ public enum CredentialType {
77

88
/// Represents a credential in AnonCred (Anonymous Credentials) format.
99
case anoncred
10+
11+
/// Represents a credential in SDJWT (Selective Disclosure JSON Web Token) format.
12+
case sdjwt
1013
}
1114

1215
/// `Claim` represents a claim in a credential. Claims are the attributes associated with the subject of a credential.

EdgeAgentSDK/EdgeAgent/Sources/DIDCommAgent/DIDCommAgent+Credentials.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public extension DIDCommAgent {
3030
)
3131
let attachment: AttachmentDescriptor
3232
switch type {
33-
case .jwt:
33+
case .jwt, .sdjwt:
3434
let data = try AttachmentBase64(base64: rqstStr.tryToData().base64URLEncoded())
3535
attachment = AttachmentDescriptor(
3636
mediaType: "application/json",

EdgeAgentSDK/Pollux/Sources/PolluxImpl+Presentation.swift

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ extension PolluxImpl {
3939
)
4040
}
4141
let presentationDefinition = PresentationDefinition(
42-
format: .init(jwt: .init(alg: [.ES256K]), sdJwt: .init(alg: [.ES256K])),
42+
format: .init(jwt: .init(alg: [.ES256K])),
4343
inputDescriptors: descriptors
4444
)
4545

@@ -85,6 +85,44 @@ extension PolluxImpl {
8585
)
8686

8787
return try JSONEncoder.didComm().encode(anoncredsPresentation)
88+
89+
case .sdjwt:
90+
let descriptors = claimFilters
91+
.map {
92+
InputDescriptor(
93+
name: $0.name,
94+
purpose: $0.purpose,
95+
group: nil,
96+
constraints: .init(
97+
fields: [
98+
.init(
99+
optional: !$0.required,
100+
path: $0.paths,
101+
purpose: $0.purpose,
102+
intentToRetain: nil,
103+
name: $0.name,
104+
filter: .init(
105+
type: $0.type,
106+
format: $0.format,
107+
const: $0.const,
108+
pattern: $0.pattern
109+
),
110+
predicate: nil
111+
)
112+
]
113+
)
114+
)
115+
}
116+
let presentationDefinition = PresentationDefinition(
117+
format: .init(sdJwt: .init(alg: [.ES256K])),
118+
inputDescriptors: descriptors
119+
)
120+
121+
let container = PresentationExchangeRequest(
122+
options: .init(domain: UUID().uuidString, challenge: UUID().uuidString),
123+
presentationDefinition: presentationDefinition
124+
)
125+
return try JSONEncoder.didComm().encode(container)
88126
}
89127
}
90128
}

0 commit comments

Comments
 (0)