Skip to content

Commit 838d080

Browse files
committed
fix(pr): address review feedback (async hkdf, polyfills, checkbox)
1 parent 4e355c1 commit 838d080

14 files changed

Lines changed: 79 additions & 135 deletions

File tree

bun.lock

Lines changed: 6 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/index.ts

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,13 @@ if (typeof global.structuredClone === 'undefined') {
3131
import 'event-target-polyfill';
3232

3333
// readable-stream
34-
if (typeof global.process !== 'undefined') {
35-
const descriptor = Object.getOwnPropertyDescriptor(global.process, 'version');
36-
if (!descriptor || descriptor.writable || descriptor.configurable) {
37-
try {
38-
Object.defineProperty(global.process, 'version', {
39-
value: 'v22.0.0',
40-
writable: true,
41-
enumerable: true,
42-
configurable: true,
43-
});
44-
} catch (e) {
45-
console.warn('Failed to define process.version:', e);
46-
}
47-
}
48-
} else {
34+
if (global.process == null) {
4935
// @ts-expect-error - process is not defined
50-
global.process = { version: 'v22.0.0' };
36+
global.process = {};
37+
}
38+
if (global.process.version == null) {
39+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
40+
(global.process as any).version = 'v22.0.0';
5141
}
5242

5343
import { AppRegistry } from 'react-native';

example/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,11 @@
3535
"events": "3.3.0",
3636
"react": "19.1.0",
3737
"react-native": "0.81.1",
38+
"react-native-bouncy-checkbox": "2.1.10",
3839
"react-native-fast-encoder": "0.3.1",
3940
"react-native-nitro-modules": "0.29.1",
4041
"react-native-quick-base64": "2.2.2",
41-
"react-native-quick-crypto": "1.0.2",
42+
"react-native-quick-crypto": "workspace:*",
4243
"react-native-safe-area-context": "^5.2.2",
4344
"react-native-screens": "4.18.0",
4445
"react-native-vector-icons": "^10.3.0",
@@ -75,4 +76,4 @@
7576
"engines": {
7677
"node": ">=18"
7778
}
78-
}
79+
}

example/src/components/BenchmarkItem.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
TouchableOpacity,
77
ActivityIndicator,
88
} from 'react-native';
9-
import { Checkbox } from './Checkbox';
9+
import BouncyCheckbox from 'react-native-bouncy-checkbox';
1010
import { useNavigation } from '@react-navigation/native';
1111
import { colors } from '../styles/colors';
1212
import type { BenchmarkSuite } from '../benchmarks/benchmarks';
@@ -60,11 +60,12 @@ export const BenchmarkItem: React.FC<BenchmarkItemProps> = ({
6060
<ActivityIndicator size="small" color={colors.blue} />
6161
</View>
6262
) : (
63-
<Checkbox
63+
<BouncyCheckbox
6464
isChecked={suite.enabled}
6565
onPress={() => toggle()}
6666
fillColor={colors.blue}
6767
style={styles.checkbox}
68+
disableBuiltInState={true}
6869
/>
6970
)}
7071
<TouchableOpacity

example/src/components/Checkbox.tsx

Lines changed: 0 additions & 67 deletions
This file was deleted.

example/src/components/TestItem.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import { View, Text, StyleSheet, TouchableOpacity } from 'react-native';
3-
import { Checkbox } from './Checkbox';
3+
import BouncyCheckbox from 'react-native-bouncy-checkbox';
44
import type { TestResult } from '../types/Results';
55
import { useNavigation } from '@react-navigation/native';
66
import { colors } from '../styles/colors';
@@ -41,13 +41,14 @@ export const TestItem: React.FC<TestItemProps> = ({
4141
style={styles.container}
4242
testID={`test-suite-${description.replace(/\s+/g, '-').toLowerCase()}`}
4343
>
44-
<Checkbox
44+
<BouncyCheckbox
4545
isChecked={value}
4646
onPress={() => {
4747
onToggle(description);
4848
}}
4949
fillColor={colors.blue}
5050
style={styles.checkbox}
51+
disableBuiltInState={true}
5152
/>
5253
<TouchableOpacity
5354
style={styles.touchable}

example/src/navigators/children/TestDetailsScreen.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { useState } from 'react';
22
import { SafeAreaView, ScrollView, StyleSheet, Text, View } from 'react-native';
3-
import { Checkbox } from '../../components/Checkbox';
3+
import BouncyCheckbox from 'react-native-bouncy-checkbox';
44
import { CorrectResultItem } from '../../components/CorrectResultItem';
55
import { IncorrectResultItem } from '../../components/IncorrectResultItem';
66
import { Suite } from '../../components/Suite';
@@ -25,22 +25,24 @@ export const TestDetailsScreen = ({ route }) => {
2525
</View>
2626
<View style={styles.showMenu}>
2727
<View style={styles.showMenuItem}>
28-
<Checkbox
28+
<BouncyCheckbox
2929
isChecked={showFailed}
3030
onPress={() => setShowFailed(!showFailed)}
3131
fillColor="red"
3232
style={styles.checkbox}
3333
testID="show-failed-checkbox"
34+
disableBuiltInState={true}
3435
/>
3536
<Text style={styles.showMenuLabel}>Show Failed</Text>
3637
</View>
3738
<View style={styles.showMenuItem}>
38-
<Checkbox
39+
<BouncyCheckbox
3940
isChecked={showPassed}
4041
onPress={() => setShowPassed(!showPassed)}
4142
fillColor={colors.green}
4243
style={styles.checkbox}
4344
testID="show-passed-checkbox"
45+
disableBuiltInState={true}
4446
/>
4547
<Text style={styles.showMenuLabel}>Show Passed</Text>
4648
</View>

packages/react-native-quick-crypto/cpp/hkdf/HybridHkdf.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,25 @@
88
#include <vector>
99

1010
#include "HybridHkdf.hpp"
11+
#include "Utils.hpp"
1112

1213
namespace margelo::nitro::crypto {
1314

14-
std::shared_ptr<ArrayBuffer> HybridHkdf::deriveKey(const std::string& algorithm, const std::shared_ptr<ArrayBuffer>& key,
15+
std::shared_ptr<Promise<std::shared_ptr<ArrayBuffer>>> HybridHkdf::hkdf(const std::string& algorithm,
16+
const std::shared_ptr<ArrayBuffer>& key,
17+
const std::shared_ptr<ArrayBuffer>& salt,
18+
const std::shared_ptr<ArrayBuffer>& info, double length) {
19+
// get owned NativeArrayBuffers before passing to sync function
20+
auto nativeKey = ToNativeArrayBuffer(key);
21+
auto nativeSalt = ToNativeArrayBuffer(salt);
22+
auto nativeInfo = ToNativeArrayBuffer(info);
23+
24+
return Promise<std::shared_ptr<ArrayBuffer>>::async([this, algorithm, nativeKey, nativeSalt, nativeInfo, length]() {
25+
return this->deriveKey(algorithm, nativeKey, nativeSalt, nativeInfo, length);
26+
});
27+
}
28+
29+
std::shared_ptr<ArrayBuffer> HybridHkdf::deriveKey(const std::string& algorithm, const std::shared_ptr<ArrayBuffer>& baseKey,
1530
const std::shared_ptr<ArrayBuffer>& salt, const std::shared_ptr<ArrayBuffer>& info,
1631
double length) {
1732
EVP_KDF* kdf = EVP_KDF_fetch(nullptr, "HKDF", nullptr);
@@ -32,8 +47,8 @@ std::shared_ptr<ArrayBuffer> HybridHkdf::deriveKey(const std::string& algorithm,
3247
params[paramIndex++] = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_DIGEST, const_cast<char*>(algorithm.c_str()), 0);
3348

3449
// Key (Input Keying Material)
35-
if (key && key->size() > 0) {
36-
params[paramIndex++] = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_KEY, key->data(), key->size());
50+
if (baseKey && baseKey->size() > 0) {
51+
params[paramIndex++] = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_KEY, baseKey->data(), baseKey->size());
3752
} else {
3853
// Empty key is allowed in HKDF (defaults to zero string of hashLen) but explicit param usually expected if not null
3954
// If we want empty, we can pass generic empty buffer or handle it.

packages/react-native-quick-crypto/cpp/hkdf/HybridHkdf.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ class HybridHkdf : public HybridHkdfSpec {
2020
std::shared_ptr<ArrayBuffer> deriveKey(const std::string& algorithm, const std::shared_ptr<ArrayBuffer>& key,
2121
const std::shared_ptr<ArrayBuffer>& salt, const std::shared_ptr<ArrayBuffer>& info,
2222
double length) override;
23+
std::shared_ptr<Promise<std::shared_ptr<ArrayBuffer>>> hkdf(const std::string& algorithm, const std::shared_ptr<ArrayBuffer>& key,
24+
const std::shared_ptr<ArrayBuffer>& salt,
25+
const std::shared_ptr<ArrayBuffer>& info, double length) override;
2326
};
2427

2528
} // namespace margelo::nitro::crypto

packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridHkdfSpec.cpp

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)