1import * as Crypto from 'expo-crypto'; 2import { CryptoDigestAlgorithm, CryptoEncoding } from 'expo-crypto'; 3import React from 'react'; 4import { ScrollView, StyleSheet } from 'react-native'; 5 6import FunctionDemo, { FunctionDescription } from '../components/FunctionDemo'; 7 8const GET_RANDOM_BYTES: FunctionDescription = { 9 name: 'getRandomBytes', 10 parameters: [ 11 { 12 name: 'byteCount', 13 type: 'number', 14 values: [10, 128, 512, 1024], 15 }, 16 ], 17 actions: Crypto.getRandomBytes, 18}; 19 20const GET_RANDOM_BYTES_ASYNC: FunctionDescription = { 21 name: 'getRandomBytesAsync', 22 parameters: [ 23 { 24 name: 'byteCount', 25 type: 'number', 26 values: [10, 128, 512, 1024], 27 }, 28 ], 29 actions: Crypto.getRandomBytesAsync, 30}; 31 32const GET_RANDOM_VALUES: FunctionDescription = { 33 name: 'getRandomValues', 34 parameters: [ 35 { 36 name: 'array', 37 type: 'enum', 38 values: [ 39 { 40 name: 'new Uint16Array(10)', 41 value: new Uint16Array(10), 42 }, 43 { 44 name: 'new Int8Array(100)', 45 value: new Int8Array(100), 46 }, 47 { 48 name: 'new Uint8ClampedArray(1)', 49 value: new Uint8ClampedArray(1), 50 }, 51 ], 52 }, 53 ], 54 actions: Crypto.getRandomValues, 55}; 56 57const RANDOM_UUID: FunctionDescription = { 58 name: 'randomUUID', 59 actions: Crypto.randomUUID, 60}; 61 62const DIGEST_STRING: FunctionDescription = { 63 name: 'digestString', 64 parameters: [ 65 { 66 name: 'algorithm', 67 type: 'string', 68 values: [ 69 CryptoDigestAlgorithm.MD2, 70 CryptoDigestAlgorithm.MD5, 71 CryptoDigestAlgorithm.SHA1, 72 CryptoDigestAlgorithm.SHA256, 73 CryptoDigestAlgorithm.SHA384, 74 CryptoDigestAlgorithm.SHA512, 75 ], 76 }, 77 { 78 name: 'data', 79 type: 'string', 80 values: ["I'm a string", "I'm not a number"], 81 }, 82 { 83 name: 'options', 84 type: 'object', 85 properties: [ 86 { 87 name: 'encoding', 88 type: 'string', 89 values: [CryptoEncoding.BASE64, CryptoEncoding.HEX], 90 }, 91 ], 92 }, 93 ], 94 actions: Crypto.digestStringAsync, 95}; 96 97const FUNCTIONS_DESCRIPTIONS = [ 98 GET_RANDOM_BYTES, 99 GET_RANDOM_BYTES_ASYNC, 100 DIGEST_STRING, 101 GET_RANDOM_VALUES, 102 RANDOM_UUID, 103]; 104 105function CryptoScreen() { 106 return ( 107 <ScrollView contentContainerStyle={styles.container}> 108 {FUNCTIONS_DESCRIPTIONS.map((props, idx) => ( 109 <FunctionDemo key={idx} namespace="Crypto" {...props} /> 110 ))} 111 </ScrollView> 112 ); 113} 114 115CryptoScreen.navigationOptions = { 116 title: 'Crypto', 117}; 118 119const styles = StyleSheet.create({ 120 container: { 121 padding: 10, 122 justifyContent: 'center', 123 }, 124}); 125 126export default CryptoScreen; 127