* Recursively sorts object keys lexicographically. * @param obj - The object to sort * @returns A new object with sorted keys
(obj: SortableValue)
| 16 | * @returns A new object with sorted keys |
| 17 | */ |
| 18 | function sortObjectKeys(obj: SortableValue): SortableValue { |
| 19 | if (obj === null || obj === undefined) return obj; |
| 20 | if (typeof obj !== 'object') return obj; |
| 21 | if (Array.isArray(obj)) return obj.map(sortObjectKeys); |
| 22 | |
| 23 | const sortedObj: SortableObject = {}; |
| 24 | Object.keys(obj).sort().forEach(key => { |
| 25 | sortedObj[key] = sortObjectKeys((obj as SortableObject)[key]); |
| 26 | }); |
| 27 | return sortedObj; |
| 28 | } |
| 29 | |
| 30 | /** |
| 31 | * Browser-compatible SHA-256 hash using crypto-browserify |