Skip to content

Commit

Permalink
feat: add error message for not existing value specified in the path
Browse files Browse the repository at this point in the history
  • Loading branch information
cristianIOHK committed May 7, 2024
1 parent 7337db5 commit 8afa1fe
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -825,51 +825,57 @@ class PolluxImpl(
paths.forEach { path ->
val fieldValue =
verifiableCredentialDescriptorPath.getValue(path)
if (field.filter != null && fieldValue != null) {
val filter: InputFieldFilter = field.filter
filter.pattern?.let { pattern ->
val regexPattern = Regex(pattern)
if (regexPattern.matches(fieldValue.toString()) || fieldValue == pattern) {
validClaim = true
return@forEach
} else {
reason =
"Expected the $path field to be $pattern but got $fieldValue"
}
}
filter.enum?.let { enum ->
enum.forEach { predicate ->
if (fieldValue == predicate) {
if (fieldValue != null) {
if (field.filter != null) {
val filter: InputFieldFilter = field.filter
filter.pattern?.let { pattern ->
val regexPattern = Regex(pattern)
if (regexPattern.matches(fieldValue.toString()) || fieldValue == pattern) {
validClaim = true
return@forEach
} else {
reason =
"Expected the $path field to be $pattern but got $fieldValue"
}
}
if (!validClaim) {
reason =
"Expected the $path field to be one of ${filter.enum.joinToString { ", " }} but got $fieldValue"
filter.enum?.let { enum ->
enum.forEach { predicate ->
if (fieldValue == predicate) {
validClaim = true
return@forEach
}
}
if (!validClaim) {
reason =
"Expected the $path field to be one of ${filter.enum.joinToString { ", " }} but got $fieldValue"
}
}
}
filter.const?.let { const ->
const.forEach { constValue ->
if (fieldValue == constValue) {
filter.const?.let { const ->
const.forEach { constValue ->
if (fieldValue == constValue) {
validClaim = true
return@forEach
}
}
if (!validClaim) {
reason =
"Expected the $path field to be one of ${filter.const.joinToString { ", " }} but got $fieldValue"
}
}
filter.value?.let { value ->
if (value == fieldValue) {
validClaim = true
return@forEach
} else {
reason =
"Expected the $path field to be $value but got $fieldValue"
}
}
if (!validClaim) {
reason =
"Expected the $path field to be one of ${filter.const.joinToString { ", " }} but got $fieldValue"
}
}
filter.value?.let { value ->
if (value == fieldValue) {
validClaim = true
return@forEach
} else {
reason =
"Expected the $path field to be $value but got $fieldValue"
}
} else {
reason = "Input field filter for ${field.name} is null"
}
} else {
reason = "Field value for path $path is null"
}
}
if (!validClaim) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ data class PresentationDefinitionRequest(
@Serializable
data class Constraints constructor(
val fields: Array<Field>? = null,
// @SerialName("limit_disclosure")
@SerialName("limit_disclosure")
val limitDisclosure: LimitDisclosure? = null
) {
@Serializable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class CredentialsAdapter(private var data: MutableList<Credential> = mutableList

inner class CredentialHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
private val type: TextView = itemView.findViewById(R.id.credential_id)
private val issuanceDate: TextView = itemView.findViewById(R.id.credential_issuance_date)
private val expiryDate: TextView = itemView.findViewById(R.id.credential_expiry_date)
private val revoked: TextView = itemView.findViewById(R.id.revoked)
private val typeString: String = itemView.context.getString(R.string.credential_type)
private val issuanceString: String = itemView.context.getString(R.string.credential_issuance)
Expand All @@ -75,8 +75,8 @@ class CredentialsAdapter(private var data: MutableList<Credential> = mutableList
}
type.text = String.format(typeString, "JWT")
// TODO: Check what else to display
jwt.nbf?.let {
issuanceDate.text = formatTimeStamp(Instant.ofEpochMilli(it * 1000))
jwt.exp?.let {
expiryDate.text = formatTimeStamp(Instant.ofEpochMilli(it * 1000))
}
}

Expand All @@ -88,7 +88,7 @@ class CredentialsAdapter(private var data: MutableList<Credential> = mutableList
AnonCredential::class -> {
val anon = cred as AnonCredential
type.text = String.format(typeString, "Anoncred")
issuanceDate.text = String.format("Issuer: ${anon.credentialDefinitionID}")
expiryDate.text = String.format("Issuer: ${anon.credentialDefinitionID}")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,19 +98,14 @@ class MessagesViewModel(application: Application) : AndroidViewModel(application
toDID = DID(toDID),
presentationClaims = PresentationClaims(
claims = mapOf(
"test" to InputFieldFilter(
"issuer" to InputFieldFilter(
type = "string",
pattern = "aliceTest"
pattern = "did:prism:bc9daaeaf0ad673f5d55b3b6612a1653bc72ac1659cefa81c6eef45c1f721639"
),
"emailAddress" to InputFieldFilter(
type = "string",
pattern = "cristian.castro@iohk.io"
)
// ),
// "issuer" to InputFieldFilter(
// type = "string",
// pattern = "did:prism:50e6cd35d1d57654af2269e6f4c70f32408c96e75b58c1d5a519b8621aac2413:CscBCsQBEmQKD2F1dGhlbnRpY2F0aW9uMBAEQk8KCXNlY3AyNTZrMRIgtzWR-rgd87zym6fi1LoyUZ4M7RmUlyD0EhTDCrQSNOAaIMe5sR-zMlaJguzP0aVjuLjKJV_-ItAic0lOOP45vjo_ElwKB21hc3RlcjAQAUJPCglzZWNwMjU2azESILc1kfq4HfO88pun4tS6MlGeDO0ZlJcg9BIUwwq0EjTgGiDHubEfszJWiYLsz9GlY7i4yiVf_iLQInNJTjj-Ob46Pw"
// )
// "emailAddress" to InputFieldFilter(
// type = "string",
// pattern = "cristian.castro@iohk.io"
// )
)
),
domain = "domain",
Expand Down Expand Up @@ -167,12 +162,12 @@ class MessagesViewModel(application: Application) : AndroidViewModel(application
viewModelScope.launch(handler) {
messages.value?.find { it.id == uiMessage.id }?.let { message ->
val sdk = Sdk.getInstance()
val valid = sdk.agent.handlePresentation(message)
if (valid) {
liveData.postValue("Valid!")
} else {
liveData.postValue("Not valid!")
}
val valid = sdk.agent.handlePresentation(message)
if (valid) {
liveData.postValue("Valid!")
} else {
liveData.postValue("Not valid!")
}
}
}
return liveData
Expand Down
2 changes: 1 addition & 1 deletion sampleapp/src/main/res/layout/placeholder_credential.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
android:textStyle="bold"/>

<TextView
android:id="@+id/credential_issuance_date"
android:id="@+id/credential_expiry_date"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp" />
Expand Down

0 comments on commit 8afa1fe

Please sign in to comment.