@exromany/lido-csm-sdk
Version:
[](https://github.com/lidofinance/lido-csm-sdk/blob/main/LICENSE.txt) [](h
28 lines • 893 B
JavaScript
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