Incorrect signature when parsing mismatching datatypes
@AlexMikhalev noticed that one of the commits failed in his repo:
Incorrect signature for Commit. This could be due to an error during signing or serialization of the commit. Compare this to the serialized commit in the client:
{"https://atomicdata.dev/properties/createdAt":1750927650009,"https://atomicdata.dev/properties/isA":["https://atomicdata.dev/classes/Commit"],"https://atomicdata.dev/properties/set":{"https://atomicdata.dev/properties/isA":["https://common.terraphim.io/01jxw2jx8qze6yakh4fz24mnhy/class/eligibility-step"],"https://atomicdata.dev/properties/parent":"https://common.terraphim.io/01jynpn23jeedmqzsrx3wsqpy6","https://common.terraphim.io/01jxw2jx8qze6yakh4fz24mnhy/property/annual-revenue":5000,"https://common.terraphim.io/01jxw2jx8qze6yakh4fz24mnhy/property/business-type":"https://common.terraphim.io/01jxw2jx8qze6yakh4fz24mnhy/tag/sole-partnership","https://common.terraphim.io/01jxw2jx8qze6yakh4fz24mnhy/property/company-name":"Zestic ","https://common.terraphim.io/01jxw2jx8qze6yakh4fz24mnhy/property/contact-name":"Alex M","https://common.terraphim.io/01jxw2jx8qze6yakh4fz24mnhy/property/email":"[email protected]","https://common.terraphim.io/01jxw2jx8qze6yakh4fz24mnhy/property/existing-loans-or-debt":true,"https://common.terraphim.io/01jxw2jx8qze6yakh4fz24mnhy/property/industry":"https://common.terraphim.io/01jxw2jx8qze6yakh4fz24mnhy/tag/agriculture","https://common.terraphim.io/01jxw2jx8qze6yakh4fz24mnhy/property/loan-request":45566,"https://common.terraphim.io/01jxw2jx8qze6yakh4fz24mnhy/property/phone-number":"0784291274","https://common.terraphim.io/01jxw2jx8qze6yakh4fz24mnhy/property/select-loan-purposes":"https://common.terraphim.io/01jxw2jx8qze6yakh4fz24mnhy/tag/working-capital","https://common.terraphim.io/01jxw2jx8qze6yakh4fz24mnhy/property/years-in-business":23000},"https://atomicdata.dev/properties/signer":"https://common.terraphim.io/agents/Jn1nkEuUaQz5XgB+Ur6JpWAkfUNDok1NpUngKmq3u2Q=","https://atomicdata.dev/properties/subject":"https://common.terraphim.io/01jynpn255kwes4reankrd44yt"}
Both the front-end as the back-end should serialize to JSON canonically, but their implementation is different. A mismatch between these is likely the cause of the issue.
I could dive into the exact differences in serialization, but maybe its better to change the library we use (fast-json-stable-stringify) isn't perfect at canonicalization.
EDIT: this is likely happening because a float type was expected but a string type was passed. The JSON parser might be too forgiving, accepting a data type that doesn't match the property type.
Ok so I checked if fast-json-stable-stringify gives the same out as the rust one for this JSON object, and it seems to be the case:
import stringify from 'fast-json-stable-stringify';
const inputStr = `{"https://atomicdata.dev/properties/createdAt":1750927650009,"https://atomicdata.dev/properties/isA":["https://atomicdata.dev/classes/Commit"],"https://atomicdata.dev/properties/set":{"https://atomicdata.dev/properties/isA":["https://common.terraphim.io/01jxw2jx8qze6yakh4fz24mnhy/class/eligibility-step"],"https://atomicdata.dev/properties/parent":"https://common.terraphim.io/01jynpn23jeedmqzsrx3wsqpy6","https://common.terraphim.io/01jxw2jx8qze6yakh4fz24mnhy/property/annual-revenue":5000,"https://common.terraphim.io/01jxw2jx8qze6yakh4fz24mnhy/property/business-type":"https://common.terraphim.io/01jxw2jx8qze6yakh4fz24mnhy/tag/sole-partnership","https://common.terraphim.io/01jxw2jx8qze6yakh4fz24mnhy/property/company-name":"Zestic ","https://common.terraphim.io/01jxw2jx8qze6yakh4fz24mnhy/property/contact-name":"Alex M","https://common.terraphim.io/01jxw2jx8qze6yakh4fz24mnhy/property/email":"[email protected]","https://common.terraphim.io/01jxw2jx8qze6yakh4fz24mnhy/property/existing-loans-or-debt":true,"https://common.terraphim.io/01jxw2jx8qze6yakh4fz24mnhy/property/industry":"https://common.terraphim.io/01jxw2jx8qze6yakh4fz24mnhy/tag/agriculture","https://common.terraphim.io/01jxw2jx8qze6yakh4fz24mnhy/property/loan-request":45566,"https://common.terraphim.io/01jxw2jx8qze6yakh4fz24mnhy/property/phone-number":"0784291274","https://common.terraphim.io/01jxw2jx8qze6yakh4fz24mnhy/property/select-loan-purposes":"https://common.terraphim.io/01jxw2jx8qze6yakh4fz24mnhy/tag/working-capital","https://common.terraphim.io/01jxw2jx8qze6yakh4fz24mnhy/property/years-in-business":23000},"https://atomicdata.dev/properties/signer":"https://common.terraphim.io/agents/Jn1nkEuUaQz5XgB+Ur6JpWAkfUNDok1NpUngKmq3u2Q=","https://atomicdata.dev/properties/subject":"https://common.terraphim.io/01jynpn255kwes4reankrd44yt"}`;
let parsed = JSON.parse(inputStr);
let shuffled = Object.fromEntries(Object.entries(parsed).sort(() => Math.random() - 0.5));
let out = stringify(shuffled);
console.log("same: ", out === inputStr);
The issue was due to the front-end setting the value of a float property to a string. Fixing the app to use the correct field type fixed the issue but it's weird that the server failed at this stage and not while validating the properties.
Hmm, that probably means that an invalid value is parsed as if it was valid by the server.
The float value should throw as soon as it's being parsed.
I think this could be happening because the set attribute in a commit is a Nested Resource, which might miss the type checking steps.
So there are a few ways to improve this situation:
- Make sure nested resources are type checked on parsing
- Make sure the validation happens correctly in the front-end, perhaps when doing commits