- 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
23 lines
669 B
TypeScript
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'
|
|
);
|
|
}
|