UNPKG

@exromany/lido-csm-sdk

Version:

[![GitHub license](https://img.shields.io/github/license/lidofinance/lido-csm-sdk?color=limegreen)](https://github.com/lidofinance/lido-csm-sdk/blob/main/LICENSE.txt) [![Version npm](https://img.shields.io/npm/v/@lidofinance/lido-csm-sdk?label=version)](h

28 lines 893 B
const MAX_JSON_LENGTH = 1048576; // 1MB export const normalizeHexInJson = (text) => text.replace(/"0x/gm, '"'); export const parseJson = (data) => { if (!data) { throw new Error('deposit data should not be empty'); } if (data.length > MAX_JSON_LENGTH) { throw new Error('deposit data is too big (max 1MB)'); } let depositData; try { const parsed = data ? JSON.parse(data) : undefined; depositData = Array.isArray(parsed) ? parsed : [parsed]; } catch { throw new Error('invalid json format'); } depositData.forEach((item) => { if (typeof item !== 'object') { throw new Error('it should be an array of a objects'); } }); if (depositData.length === 0) { throw new Error(`Should have at least 1 key`); } return depositData; }; //# sourceMappingURL=parse-json.js.map