import { encodeTextAsBinary, decodeTextFromBinary } from "encoding/text"; import { encodeCanonicalJSON } from "./canonical"; import { JSONValue } from "./types"; export function encodeJSONAsBinary(object: JSONValue): Uint8Array { // Ensure that encoding the same data as JSON will result in the // exact same output. This will ensure signing and verifying // will work correctly. const text = encodeCanonicalJSON(object); return encodeTextAsBinary(text); } export function decodeJSONFromBinary( binary: Uint8Array | ArrayBuffer ): JSONValue { const text = decodeTextFromBinary(binary); return JSON.parse(text); }