Add service.utils
with splitPrivateData
and isValid32ByteHex
This commit is contained in:
parent
dfae77de58
commit
c0d402b234
24
src/utils/service.utils.ts
Normal file
24
src/utils/service.utils.ts
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
export function splitPrivateData(data: Record<string, any>, privateFields: string[]): { privateData: Record<string, any>, publicData: Record<string, any> } {
|
||||||
|
const privateData: Record<string, any> = {};
|
||||||
|
const publicData: Record<string, any> = {};
|
||||||
|
|
||||||
|
for (const [key, value] of Object.entries(data)) {
|
||||||
|
if (privateFields.includes(key)) {
|
||||||
|
privateData[key] = value;
|
||||||
|
} else {
|
||||||
|
publicData[key] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return { privateData, publicData };
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isValid32ByteHex(value: string): boolean {
|
||||||
|
// Check if string is exactly 64 characters (32 bytes in hex)
|
||||||
|
if (value.length !== 64) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if string only contains valid hex characters
|
||||||
|
return /^[0-9a-fA-F]{64}$/.test(value);
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user