Skip to content

Commit

Permalink
feat(sdk): propagate trust denial reason to consumer (#779)
Browse files Browse the repository at this point in the history
Signed-off-by: Rolson Quadras <[email protected]>
  • Loading branch information
rolsonquadras authored May 2, 2024
1 parent d3b5bd6 commit acdebf8
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 2 deletions.
10 changes: 8 additions & 2 deletions cmd/wallet-sdk-gomobile/docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -1844,7 +1844,10 @@ config.evaluatePresentationURL = evaluatePresentationURL
val evaluationResult = Registry(config).evaluatePresentation(presentationRequest)

// check if the txn is allowed
evaluationResult!.allowed
evaluationResult.allowed

// check txn denial reason if allowed=false
evaluationResult.denyReason()

// Get the requested attestations
for (rInd in 0 until evaluationResult.requestedAttestationLength() ) {
Expand Down Expand Up @@ -1886,7 +1889,10 @@ config.evaluatePresentationURL = evaluatePresentationURL
let evaluationResult = try TrustregistryRegistry(config)!.evaluatePresentation(presentationRequest)

// check if the txn is allowed
evaluationResult!.allowed
evaluationResult!.allowed

// check txn denial reason if allowed=false
evaluationResult!.denyReason()

// Get the requested attestations
for rInd in 0..<evaluationResult!.requestedAttestationLength() {
Expand Down
8 changes: 8 additions & 0 deletions cmd/wallet-sdk-gomobile/trustregistry/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ SPDX-License-Identifier: Apache-2.0
package trustregistry

import (
"strings"

"github.com/trustbloc/wallet-sdk/cmd/wallet-sdk-gomobile/api"
)

Expand All @@ -17,6 +19,12 @@ type EvaluationResult struct {
ErrorMessage string
MultipleCredentialAllowed bool
attestationsRequired []string
denyReasons []string
}

// DenyReason check the reasons when the transaction is not allowed (=false).
func (e *EvaluationResult) DenyReason() string {
return strings.Join(e.denyReasons, ", ")
}

// RequestedAttestationLength returns the number attestation requested.
Expand Down
2 changes: 2 additions & 0 deletions cmd/wallet-sdk-gomobile/trustregistry/trust_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ func (r *Registry) EvaluateIssuance(request *IssuanceRequest) (*EvaluationResult
ErrorCode: result.ErrorCode,
ErrorMessage: result.ErrorMessage,
attestationsRequired: attestationsRequired,
denyReasons: result.DenyReasons,
}, nil
}

Expand Down Expand Up @@ -114,6 +115,7 @@ func (r *Registry) EvaluatePresentation(request *PresentationRequest) (*Evaluati
ErrorMessage: result.ErrorMessage,
attestationsRequired: attestationsRequired,
MultipleCredentialAllowed: multipleCredentialAllowed,
denyReasons: result.DenyReasons,
}, nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ func TestRegistry_EvaluateIssuance(t *testing.T) {
require.NotNil(t, result)
require.False(t, result.Allowed)
require.Equal(t, result.ErrorCode, "didForbidden")
require.Equal(t, result.DenyReason(), "unauthorized issuer, empty credentials")
})

t.Run("Invalid server URI", func(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions pkg/trustregistry/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type EvaluationResult struct {
Allowed bool `json:"allowed,omitempty"`
ErrorCode string `json:"errorCode,omitempty"`
ErrorMessage string `json:"errorMessage,omitempty"`
DenyReasons []string `json:"deny_reasons,omitempty"`
Data *EvaluationData `json:"payload,omitempty"`
}

Expand Down
1 change: 1 addition & 0 deletions pkg/trustregistry/testsupport/mockhttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func HandleEvaluateIssuanceRequest(w http.ResponseWriter, r *http.Request) {
writeResponse(w, &trustregistry.EvaluationResult{
ErrorCode: "didForbidden",
ErrorMessage: "Interaction with given issuer is forbidden",
DenyReasons: []string{"unauthorized issuer", "empty credentials"},
})

return
Expand Down

0 comments on commit acdebf8

Please sign in to comment.