UNPKG

@credo-ts/core

Version:

<p align="center"> <br /> <img alt="Credo Logo" src="https://github.com/openwallet-foundation/credo-ts/blob/c7886cb8377ceb8ee4efe8d264211e561a75072d/images/credo-logo.png" height="250px" /> </p> <h1 align="center"><b>Credo - Core</b></h1

1 lines • 2.01 kB
{"version":3,"file":"normalization.mjs","names":[],"sources":["../../../../src/modules/w3c-di/proof-processing/normalization.ts"],"sourcesContent":["/**\n * Returns true when the value is a plain record-like object that can be safely\n * traversed and rebuilt during Data Integrity boundary normalization.\n */\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n if (value === null || typeof value !== 'object') {\n return false\n }\n\n const prototype = Object.getPrototypeOf(value)\n return prototype === Object.prototype || prototype === null\n}\n\n/**\n * JavaScript permits object properties to be set to `undefined`, but `undefined`\n * is not part of the JSON data model used by Data Integrity processing.\n *\n * Recursively removes properties whose value is `undefined` from plain-object\n * inputs before canonicalization.\n *\n * Arrays are preserved and normalized element-by-element so that only object\n * fields are omitted at the service boundary before cryptosuite processing.\n */\nexport function omitUndefinedFields<T>(value: T): T {\n if (Array.isArray(value)) {\n return value.map((item) => omitUndefinedFields(item)) as T\n }\n\n if (!isPlainObject(value)) {\n return value\n }\n\n const normalizedEntries = Object.entries(value).flatMap(([key, nestedValue]) => {\n if (nestedValue === undefined) {\n return []\n }\n\n return [[key, omitUndefinedFields(nestedValue)] as const]\n })\n\n return Object.fromEntries(normalizedEntries) as T\n}\n"],"mappings":";;;;;AAIA,SAAS,cAAc,OAAkD;CACvE,IAAI,UAAU,QAAQ,OAAO,UAAU,UACrC,OAAO;CAGT,MAAM,YAAY,OAAO,eAAe,KAAK;CAC7C,OAAO,cAAc,OAAO,aAAa,cAAc;AACzD;;;;;;;;;;;AAYA,SAAgB,oBAAuB,OAAa;CAClD,IAAI,MAAM,QAAQ,KAAK,GACrB,OAAO,MAAM,KAAK,SAAS,oBAAoB,IAAI,CAAC;CAGtD,IAAI,CAAC,cAAc,KAAK,GACtB,OAAO;CAGT,MAAM,oBAAoB,OAAO,QAAQ,KAAK,CAAC,CAAC,SAAS,CAAC,KAAK,iBAAiB;EAC9E,IAAI,gBAAgB,KAAA,GAClB,OAAO,CAAC;EAGV,OAAO,CAAC,CAAC,KAAK,oBAAoB,WAAW,CAAC,CAAU;CAC1D,CAAC;CAED,OAAO,OAAO,YAAY,iBAAiB;AAC7C"}