3 ms·
Clojure Spec works really well for this sort of thing. It doesn't serialize to JSON, but it would be able to check for it. You could also think about Dhall as
by mmcdermott 5y ago
Clojure Spec works really well for this sort of thing. It doesn't serialize to JSON, but it would be able to check for it.
You could also think about Dhall as a front-end. You could represent the whole credential as a union type. This isn't deeply thought out, but this should give an idea as to how this would look:
let TestResult = < Positive | Negative >
let ScreeningTestDetails =
{ hasTestResult : Bool, testResult : TestResult, testTime : Natural }
let CredentialData =
< Vaccinated | RapidSarsCov2PCRTest : ScreeningTestDetails >
let Credential =
{ credentialName : Text
, credentialIssuer : Text
, credentialData : CredentialData
}
let result
: Credential
= { credentialName = "COVID-19 Back to Work Credential"
, credentialIssuer = "Acme Labs Inc."
, credentialData = CredentialData.Vaccinated
}
let result2
: Credential
= { credentialName = "COVID-19 Back to Work Credential"
, credentialIssuer = "Acme Labs Inc."
, credentialData =
CredentialData.RapidSarsCov2PCRTest
{ hasTestResult = True
, testResult = TestResult.Negative
, testTime = 1622145851
}
}
let prop0 =
λ(x : ScreeningTestDetails) →
assert : greaterThan x.testTime 1522145851 ≡ True
in result2
Notice here that the type for credential data can only be vaccinated or a test result. It can't even represent unvaccinated. You could probably take it farther with dependent types and assertions.
Edit: added an assertion to model the 72 hour requirement.