@@ -320,6 +320,7 @@ instance Error ScriptDataRangeError where
320320-- can round-trip the JSON.
321321--
322322-- The subset of JSON supported is all JSON except:
323+ --
323324-- * No null or bool values
324325-- * No floating point, only integers in the range of a 64bit signed integer
325326-- * A limitation on string lengths
@@ -345,6 +346,20 @@ instance Error ScriptDataRangeError where
345346-- precisely. It also means any script data can be converted into the JSON and
346347-- back without loss. That is we can round-trip the script data via the JSON and
347348-- also round-trip schema-compliant JSON via script data.
349+ --
350+ -- *Warning*: While the JSON representation does round-trip, the CBOR through
351+ -- JSON does not. When serialising and deserialising 'HashableScriptData'
352+ -- through JSON e.g:
353+ -- @
354+ -- CBOR -> HashableScriptData -> JSON -> HashableScriptData -> CBOR
355+ -- @
356+ -- the original CBOR representation is lost and the resulting CBOR *will*
357+ -- be different resulting in a different script data hash, which is
358+ -- calculated from CBOR. This is because cardano-ledger does not canonicalise
359+ -- CBOR representation, so you can have few slightly different serialised
360+ -- representations of a data structure, which represent the same value.
361+ --
362+ -- See: https://github.com/IntersectMBO/cardano-api/issues/612#issuecomment-2701256007
348363data ScriptDataJsonSchema
349364 = -- | Use the \"no schema\" mapping between JSON and script data as
350365 -- described above.
@@ -507,6 +522,10 @@ scriptDataJsonToHashable schema scriptDataVal = do
507522-- JSON conversion using the "detailed schema" style
508523--
509524
525+ -- | Convert a script data value into JSON using detailed schema.
526+ --
527+ -- This conversion is total but is not necessarily invertible.
528+ -- See 'ScriptDataJsonSchema' for the details.
510529scriptDataToJsonDetailedSchema :: HashableScriptData -> Aeson. Value
511530scriptDataToJsonDetailedSchema = conv . getScriptData
512531 where
@@ -538,6 +557,10 @@ scriptDataToJsonDetailedSchema = conv . getScriptData
538557
539558 singleFieldObject name v = Aeson. object [(name, v)]
540559
560+ -- | Convert a script data value from JSON using detailed schema.
561+ --
562+ -- This conversion is total but is not necessarily invertible.
563+ -- See 'ScriptDataJsonSchema' for the details.
541564scriptDataFromJsonDetailedSchema
542565 :: Aeson. Value
543566 -> Either
0 commit comments