Add utils splitPrivateData
This commit is contained in:
parent
1664b4aa69
commit
c8cf1b2efd
15
src/utils.ts
15
src/utils.ts
@ -1,6 +1,21 @@
|
|||||||
// Server-specific utility functions
|
// Server-specific utility functions
|
||||||
export const EMPTY32BYTES = String('').padStart(64, '0');
|
export const EMPTY32BYTES = String('').padStart(64, '0');
|
||||||
|
|
||||||
|
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 {
|
export function isValid32ByteHex(value: string): boolean {
|
||||||
// Check if the value is a valid 32-byte hex string (64 characters)
|
// Check if the value is a valid 32-byte hex string (64 characters)
|
||||||
const hexRegex = /^[0-9a-fA-F]{64}$/;
|
const hexRegex = /^[0-9a-fA-F]{64}$/;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user