learning_ai_common_plat/packages/client-encrypt/src/guards.ts
saravanakumardb1 1bce981f43 feat(client-encrypt): create @bytelyst/client-encrypt — Web Crypto API encryption
- AES-256-GCM via SubtleCrypto (browsers + React Native with polyfill)
- Wire-compatible EncryptedField with @bytelyst/field-encrypt (server) and
  BLFieldEncrypt (Swift/Kotlin native SDKs)
- encryptField, decryptField, generateKey, keyFromHex, keyToHex
- PBKDF2 key derivation (600k iterations per OWASP 2023)
- isEncryptedField type guard, toHex/fromHex helpers
- 22 Vitest tests, all passing
- Add Web Crypto globals to root ESLint config
2026-03-21 11:15:27 -07:00

23 lines
669 B
TypeScript

/**
* @bytelyst/client-encrypt — Type guards
*
* Compatible with @bytelyst/field-encrypt isEncryptedField() on the server.
*/
import type { EncryptedField } from './types.js';
/** Check if a value is an EncryptedField object. */
export function isEncryptedField(value: unknown): value is EncryptedField {
if (typeof value !== 'object' || value === null) return false;
const obj = value as Record<string, unknown>;
return (
obj.__encrypted === true &&
obj.v !== undefined &&
obj.alg !== undefined &&
typeof obj.ct === 'string' &&
typeof obj.iv === 'string' &&
typeof obj.tag === 'string' &&
typeof obj.dekId === 'string'
);
}