expo-aes-vetkeys
v0.1.0
Published
Hooks and components for using AES & vetkeys in Expo Web/Native applications
Maintainers
Readme
expo-aes-vetkeys
An Expo library for managing AES encryption keys with vetkeys integration.
Features
- AES key generation and management with Identity-Based Encryption (IBE)
- Secure storage integration using
expo-storage-universal - Crypto operations using
expo-crypto-universal - Vetkeys integration for asymmetric encryption
- React hook for easy AES key management
- Loading component for encryption processing state
- Performance monitoring for cryptographic operations
- Comprehensive TypeScript types and JSDoc documentation
Installation
npm install expo-aes-vetkeysRequired Peer Dependencies
This package requires the following peer dependencies:
# For storage functionality
npx expo install @react-native-async-storage/async-storage
npx expo install expo-secure-store
# For crypto functionality
npx expo install expo-cryptoUsage
Hook Usage
import { useAesKey } from 'expo-aes-vetkeys';
// Define your backend implementation
const backend = {
asymmetricKeys: async (transportPublicKey: Uint8Array) => {
// Implement your backend logic
return {
publicKey: new Uint8Array(),
encryptedAesKey: undefined,
encryptedKey: undefined,
};
},
asymmetricSaveEncryptedAesKey: async (encryptedAesKey: Uint8Array) => {
// Implement your backend logic
},
};
// Use the hook in your component
const YourComponent = () => {
const { isProcessingAes, aesError } = useAesKey({
cryptoModule: yourCryptoModule, // Required: expo-crypto-universal CryptoModule
aesRawKeyStorage: yourStorage, // Required: Uint8ArrayValueStorageWrapper
identity: yourIdentity, // Optional: @dfinity/agent Identity
backend, // Required: AesBackend implementation
});
if (isProcessingAes) {
return <AesProcessingView />;
}
if (aesError) {
return <Text>Error: {aesError.message}</Text>;
}
return <Text>Ready!</Text>;
};Loading Component
The AesProcessingView component provides a user-friendly loading state during AES key processing operations. It's designed to be used with the useAesKey hook to display the processing state.
import { AesProcessingView } from 'expo-aes-vetkeys';
// Basic usage
const YourComponent = () => {
return <AesProcessingView />;
};
// With useAesKey hook
const YourComponent = () => {
const { isProcessingAes } = useAesKey({
// ... hook configuration
});
if (isProcessingAes) {
return <AesProcessingView />;
}
return <Text>Ready!</Text>;
};The component displays:
- A centered loading spinner in iOS-style blue (#007AFF)
- "Preparing Encryption..." status message
- "This may take a moment..." hint text
- Clean white background with proper padding
- Responsive layout that works on both mobile and web
API
useAesKey
A React hook for managing AES key initialization and encryption.
Props
cryptoModule: Requiredexpo-crypto-universalCryptoModule instance for cryptographic operationsaesRawKeyStorage: RequiredUint8ArrayValueStorageWrapperinstance for key persistenceidentity: Optional@dfinity/agentIdentity instance for authenticated operationsbackend: Required object implementing theAesBackendinterface
Returns
isProcessingAes: Boolean indicating if AES key processing is in progressaesError: Any error that occurred during processing
AesProcessingView
A React Native component that displays a loading state during AES key processing.
Features
- Centered loading indicator with iOS-style blue color (#007AFF)
- Informative status message "Preparing Encryption..."
- Hint text "This may take a moment..."
- Responsive layout with max-width container (400px)
- Clean white background with proper padding
- Vertically centered content with -80px top margin for visual balance
AesRawKeyStorage
A specialized storage wrapper for AES raw keys.
Features
- Extends
Uint8ArrayValueStorageWrapperfor type-safe storage - Uses 'aesRawKey' as the default storage key
- Provides specific functionality for AES key storage
Utility Functions
asymmetricKeys
- Generates asymmetric keys using the provided backend
- Measures and logs performance of key generation
- Returns
AsymmetricKeysResultwith public key and encrypted keys
decryptAesKey
- Decrypts AES keys using Identity-Based Encryption (IBE)
- Measures and logs performance of decryption
- Requires principal, encrypted key, public key, and transport secret key
encryptAesKey
- Encrypts AES keys using Identity-Based Encryption (IBE)
- Measures and logs performance of encryption
- Requires raw AES key, principal, public key, and seed
prepareAesKey
- Prepares AES key for encryption/decryption
- Creates transport secret key from seed
- Retrieves asymmetric keys from backend
saveEncryptedAesKeyToBackend
- Saves encrypted AES key to backend
- Measures and logs performance of save operation
Dependencies
Main Dependencies
@dfinity/agent: ^0.20.0expo-crypto-universal: ^0.1.0expo-storage-universal: ^0.1.0vetkeys-client-utils: ^0.1.1react: ^18.3.1react-native: ^0.76.7
Peer Dependencies
Storage
@react-native-async-storage/async-storageexpo-secure-store
Crypto
expo-crypto
License
MIT
