toip.tools

function · Browser and Node

canonicalJson

JSON Canonicalization Scheme (RFC 8785) — the byte form eddsa-jcs-2022 and ecdsa-jcs-2019 hash.

Object keys are sorted by UTF-16 code unit (what Array.prototype.sort does on strings, which is what RFC 8785 §3.2.3 specifies), strings are serialised with JSON's own escaping, and numbers use the shortest round-tripping form — which for the integers and JSON doubles a Trust Task document carries is exactly JSON.stringify(n). Trust Task documents carry no number outside the safe-integer / plain-double range, so no bespoke number formatter is needed.

@toip-tools/trust-coreView source
TypeScriptImport
import { canonicalJson } from "@toip-tools/trust-core";

Declaration

TypeScriptSignature
canonicalJson(value: unknown): string;

Parameters

valuerequired
unknown

Returns

string