To answer your question, what you have is (effectively) code, and just use a programming language for this, call it a function, give it a name, arguments, test suite and register it as a plugin to your platform. Oh, and documentation, change history, etc.
Seriously - the "overhead" more than pays for itself when 100 other yahoos do this nonsense and you end up with data files containing untestable code that breaks when combined with other code, breaks when the platform is changed, etc etc
What is a better way to share this important part of the schema (the matrix) without resorting to letting the "business logic" perform the evaluation? Optimally, any matrix should be able to run against the same business logic for evaluation.
Also, though I understand why you say that, we won't have "100 other yahoos doing this nonsense," and each schema would go through a pretty thorough review process.
Well, they _must_ have prior knowledge about it, because they must have to understand the concept of JsonLogic beforehand. So instead, you can just make these systems understand a proper programming language that can produce outputs. Something like https://github.com/dhall-lang/dhall-lang would probably be a much better option for this usecase.
If your concern is the sharability, consider making a library or service that provides the business logic.
Your problem is that you need the same logic in two places, and you can solve it by centralizing this logic in one place.
Libraries tend to cover broader spectrum of use cases than you'd need. Usually that's okay (eg: URL parsing, string manipulation, HTTP client, etc) but in cases like this the logic schema should be as absolutely minimal as possible.
If you're building an interpreter and need an interchangeable format then you can always generate that out of your own bespoke and very constrained format.
With all due respect, you're making a classic mistake: presenting the solution to a problem without tracing the problem back to the use case.
Why do you need to include the logic matrix in the schema? I can promise you that the real world use cases where you'd need to this are virtually non-existent. You wouldn't even do this for some extreme case like Mars rover software.
Your business logic should have a single source of truth. The vast majority of the time you can just write an API for other software to synchronize with.
Otherwise just ship new builds of your software package to the client instead of a new schema. If you need to be modular then use modular primitives such as shared libraries.
Again, there's virtually no real world scenario where you need to ship a logic schema (in any format) to a client. You might as well ship a shared library, importable module, a completely new binary, etc, etc.
> Interoperability is the main reason. We need this data and the evaluation matrix to be portable across different "credential wallets" as part of a standard model for matrix evaluation of Verifiable Credentials (see also https://www.w3.org/TR/vc-data-model/).
Representing verification logic in the schema flawed. Just because the W3C publishes a spec doesn't make it good.
So I guess one of the few valid use cases for JsonLogic (or similar) is if your company makes a bad technical decision and you're forced to implement something?
The "verification" required is one of tamper proof, cryptographic safe certificate chain verification, something like the one done using Certificate Authorities, certificate revogation list and the surrounding infrastructure used in TLS.
Encoding anything Turing complete is out-of-spec.
Here is the thing...There is already a crappy way to describe JSON Schemas[1,2].
It is hard to grok by visual inspection and expressing conditions like "this element can either be a list containing a subset of these values or a hash with keys that belong to the same set" etc make it unwieldy.
The schema ends up being really brittle and hard to modify. 100% green-lit test coverage don't mean a thing when it is soooo easy to end up with a false negative.
Now take that and add logic to it? One has to question the existence of all the programming languages in use if we are going to end up subjecting ourselves to that torture.
[1]: https://json-schema.org/ [2]: https://json-schema.org/draft/2020-12/json-schema-core.html
Json schema validates the data structure, while this seems to be more about writing algorithms in json
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.
This strikes me as nice:
(parsing-matrix
(if (or (= (var "credentialData" "rapidSarsCov2PCRTest" "testResult") "negative")
(= (var "credentialData" "covid19Vaccination" "hasVaccination") "negative"))
"valid"
"invalid")) ["if", ["or", ["===", ["var", "credentialData.rapidSarsCov2PCRTest.testResult" ], "negative"],
["===", ["var", "credentialData.covid19Vaccination.hasVaccination"], true ] ],
"valid",
"invalid"]
?It's hard to gauge whether or not it's better to go with an existing, possibly inferior standard, or to create a new one, like this...
But yes, does look like other people have grazed this idea as well: https://www.i-programmer.info/programming/javascript/2380-ja....
{...
parsingMatrix
(if (or (=== (var "credentialData.rapidSarsCov2PCRTest.testresult")
"negative")
(=== (var "credentialData.covid19Vaccination.hasVaccination")
true))
"valid"
"invalid")} (credentialData.rapidSarsCov2PCRTest.testResult==='negative')
|| credentialData.covid19Vaccination.hasVaccination)
? 'valid' : 'invalid'
Seem easier to read and maintain to me.It seems weird to me to pass a syntax tree over the network rather than just the syntax. But if the expression is not supposed to be viewed or edited as code at all, but only in some kind of GUI expression builder, then it might make sense.
Lisp is at least human-writable, but if it is supposed to be written by humans why not just use straightforward expression syntax like "a + b".
It walks through the process of building a Lisp in JSON and the associated parser in JavaScript. It could be a good starting point to build out a cross-platform approach to sending logic over the wire.
Say we have a schema which defines certain data. Let's say it's a "credential" which is a "COVID-19 Back to Work Credential." The credential is valid in the case that someone either 1) has a COVID vaccination or 2) has a negative COVID test in the past 72 hours. That data might look like this:
Now, say I want to define the conditions under which this "credential" is valid or invalid, but I want to include this "matrix" within the schema (not any business logic, just matrix logic that pertains to the data within the schema itself).Optimally, I'd be able to do this within the same schema or file.
With JsonLogic, that might look like this (probably flawed logic, just a demo, not using this in production, may cause your computer to go up in flames, etc.):
Can you think of another way to do this that doesn't rely on using JsonLogic or something like it (or a cleaner method for doing it in JSON)?