react-native-avo-inspector
Version:
[](https://badge.fury.io/js/react-native-avo-inspector)
62 lines (61 loc) • 2.32 kB
TypeScript
/**
* AvoEncryption — React Native ECIES encryption using @noble/ciphers.
*
* CRITICAL: React Native's Hermes runtime does NOT have crypto.subtle.
* This module uses @noble/ciphers/aes gcm() for AES-GCM instead — fully synchronous.
* Ephemeral key generation and ECDH use @noble/curves/p256.
*
* Wire format (MUST match all SDKs):
* [0x00][65-byte ephemeral pubkey (uncompressed)][16-byte IV][16-byte auth tag][ciphertext]
* → base64
*
* Algorithm:
* 1. Generate ephemeral P-256 key pair
* 2. ECDH: ephemeral private key + recipient public key → shared secret (X-coordinate)
* 3. KDF: SHA-256(shared secret) → 32-byte AES key
* 4. AES-256-GCM encrypt with random 16-byte IV
* 5. Serialize: version(1) + ephemeralPubKey(65) + IV(16) + authTag(16) + ciphertext
* 6. Base64 encode
*/
/**
* Determines whether encryption should be performed.
*
* Truth table:
* dev + key → true
* staging + key → true
* prod + key → false
* dev + null → false
* dev + empty → false
*/
export declare function shouldEncrypt(env: string, publicEncryptionKey: string | null | undefined): boolean;
/**
* Encrypts a value using ECIES (P-256 ECDH + AES-256-GCM).
* Fully synchronous — no async/await.
*
* @param value - The plaintext string to encrypt (already JSON-stringified by caller if needed)
* @param publicKeyHex - The recipient's P-256 public key as a hex string (uncompressed, 04...)
* @returns Base64-encoded ciphertext in Avo ECIES wire format
*/
export declare function encryptValue(value: string, publicKeyHex: string): string;
/**
* Encrypts event property values for transmission.
*
* Rules:
* - List-type properties are omitted entirely
* - On encryption failure: console.warn, omit the property, continue
* - Returns new array with encryptedPropertyValue set (propertyType/propertyName preserved)
*/
export declare function encryptEventProperties(properties: Array<{
propertyName: string;
propertyType: string;
children?: any;
failedEventIds?: string[];
passedEventIds?: string[];
}>, eventProps: Record<string, any>, publicKeyHex: string): Array<{
propertyName: string;
propertyType: string;
encryptedPropertyValue?: string;
children?: any;
failedEventIds?: string[];
passedEventIds?: string[];
}>;