Skip to content

Commit

Permalink
feat(pollux): add anoncreds predicate on requests
Browse files Browse the repository at this point in the history
 Fixes ATL-6848

Signed-off-by: goncalo-frade-iohk <[email protected]>
  • Loading branch information
goncalo-frade-iohk committed May 22, 2024
1 parent 5573ef4 commit 423daf4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion EdgeAgentSDK/EdgeAgent/Sources/EdgeAgent+Credentials.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public extension EdgeAgent {
)

let rqstStr = try request.tryToString()
Logger(label: "").log(level: .info, "Request: \(rqstStr)")
logger.debug(message: "Request: \(rqstStr)")
let attachment: AttachmentDescriptor
switch type {
case .jwt:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ final class AnoncredsPresentationFlowTest: XCTestCase {
fromDID: DID(method: "test", methodId: "alice"),
toDID: DID(method: "test", methodId: "bob"),
claimFilters: [
.init(paths: [], type: "sex")
.init(paths: [], type: "sex"),
.init(paths: [], type: "age", const: "20", pattern: ">=")
]
)

Expand Down
21 changes: 20 additions & 1 deletion EdgeAgentSDK/Pollux/Sources/PolluxImpl+Presentation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,34 @@ extension PolluxImpl {
.reduce([String: AnoncredsPresentationRequest.RequestedAttribute](), { partialResult, filter in
var dic = partialResult
let key = filter.name ?? filter.type
guard filter.pattern == nil else {
return dic
}
dic[key] = AnoncredsPresentationRequest.RequestedAttribute(name: key, restrictions: [])
return dic
})

let requestedPredicates = claimFilters
.reduce([String: AnoncredsPresentationRequest.RequestedPredicate](), { partialResult, filter in
var dic = partialResult
guard
let pType = filter.pattern,
let pValueStr = filter.const,
let pValue = Int(pValueStr)
else {
return dic
}
let key = filter.name ?? filter.type
dic[key] = AnoncredsPresentationRequest.RequestedPredicate(name: key, pType: pType, pValue: pValue)
return dic
})

let anoncredsPresentation = AnoncredsPresentationRequest(
nonce: try Nonce().getValue(),
name: name,
version: version,
requestedAttributes: requestedFields,
requestedPredicates: [:]
requestedPredicates: requestedPredicates
)

return try JSONEncoder.didComm().encode(anoncredsPresentation)
Expand Down

0 comments on commit 423daf4

Please sign in to comment.