Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add pbkdf2, test ncrypto #451

Draft
wants to merge 20 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .github/workflows/update-lockfiles.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: 'Update Lockfiles (bun.lockb + Podfile.lock)'

on:
pull_request:
paths:
- "packages/react-native-quick-crypto/package.json"
- "example/package.json"

permissions:
contents: write

jobs:
update-lockfiles:
name: "Update lockfiles (bun.lockb + Podfile.lock)"
if: github.actor == 'dependabot[bot]'
runs-on: ubuntu-latest
steps:
- uses: oven-sh/setup-bun@v2
- uses: ruby/setup-ruby@v1
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.ref }}
- run: |
bun install --frozen-lockfile
git add bun.lockb
cd example
bun pods
git add ios/Podfile.lock
cd ..
git config --global user.name 'dependabot[bot]'
git config --global user.email 'dependabot[bot]@users.noreply.github.com'
git commit --amend --no-edit
git push --force
16 changes: 12 additions & 4 deletions .github/workflows/validate-js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,11 @@ jobs:
name: JS Lint (eslint, prettier)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Checkout
uses: actions/checkout@v4

- uses: oven-sh/setup-bun@v2
- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: 1.1.26

Expand All @@ -69,10 +71,16 @@ jobs:
bun install

- name: Run ESLint (rnqc)
run: cd packages/react-native-quick-crypto && bun lint-fix
run: |
cd packages/react-native-quick-crypto
bun lint:fix
bun format:fix

- name: Run ESLint (example)
run: cd example && bun lint-fix
run: |
cd example
bun lint:fix
bun format:fix

- name: Verify no files have changed after auto-fix
run: git diff --exit-code HEAD
6 changes: 4 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,16 @@ bun example
Make sure your code passes TypeScript and ESLint. Run the following to verify:

```sh
bun tsx
bun tsc
bun lint
bun format
```

To fix formatting errors, run the following:

```sh
bun lint-fix
bun lint:fix
bun format:fix
```

Remember to add tests for your change if possible. Run the unit tests by:
Expand Down
Binary file modified bun.lockb
Binary file not shown.
4 changes: 2 additions & 2 deletions docs/implementation-coverage.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ This document attempts to describe the implementation status of Crypto APIs/Inte
* ❌ `crypto.getRandomValues(typedArray)`
* ❌ `crypto.hkdf(digest, ikm, salt, info, keylen, callback)`
* ❌ `crypto.hkdfSync(digest, ikm, salt, info, keylen)`
* `crypto.pbkdf2(password, salt, iterations, keylen, digest, callback)`
* `crypto.pbkdf2Sync(password, salt, iterations, keylen, digest)`
* `crypto.pbkdf2(password, salt, iterations, keylen, digest, callback)`
* `crypto.pbkdf2Sync(password, salt, iterations, keylen, digest)`
* ❌ `crypto.privateDecrypt(privateKey, buffer)`
* ❌ `crypto.privateEncrypt(privateKey, buffer)`
* ❌ `crypto.publicDecrypt(key, buffer)`
Expand Down
16 changes: 8 additions & 8 deletions example/index.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
// polyfills
import { install } from 'react-native-quick-crypto'
install()
import { install } from 'react-native-quick-crypto';
install();

// mocha things
global.process.cwd = () => 'sxsx'
global.process.cwd = () => 'sxsx';

// readable-stream
// @ts-expect-error - although process.version is readonly, we're setting it for readable-stream
global.process.version = 'v22.0.0'
global.process.version = 'v22.0.0';

// global.process.env = { NODE_ENV: 'production' };
// global.location = {};

import { AppRegistry } from 'react-native'
import App from './src/App'
import { name as appName } from './app.json'
import { AppRegistry } from 'react-native';
import App from './src/App';
import { name as appName } from './app.json';

AppRegistry.registerComponent(appName, () => App)
AppRegistry.registerComponent(appName, () => App);
2 changes: 1 addition & 1 deletion example/ios/.xcode.env
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
# For example, to use nvm with brew, add the following line
# . "$(brew --prefix nvm)/nvm.sh" --no-use
export NODE_BINARY=$(command -v bun)
export ENTRY_FILE=index.ts
export ENTRY_FILE=index.ts
6 changes: 3 additions & 3 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ PODS:
- hermes-engine (0.74.5):
- hermes-engine/Pre-built (= 0.74.5)
- hermes-engine/Pre-built (0.74.5)
- NitroModules (0.7.0):
- NitroModules (0.9.2):
- DoubleConversion
- glog
- hermes-engine
Expand Down Expand Up @@ -1564,9 +1564,9 @@ SPEC CHECKSUMS:
fmt: 4c2741a687cc09f0634a2e2c72a838b99f1ff120
glog: fdfdfe5479092de0c4bdbebedd9056951f092c4f
hermes-engine: 8c1577f3fdb849cbe7729c2e7b5abc4b845e88f8
NitroModules: 7c4be57284deac5fbdfd23457cd1aaedfc810c98
NitroModules: 38b7870be128f26cb82a2ef256fa8eea04933fa2
OpenSSL-Universal: f8a9c4fdab7e21cb70bda471c269e86e9212439c
QuickCrypto: 744978daf1eb30c6dec0f68658de0c5726d9793b
QuickCrypto: 551d63cf0fdd977e6b8e0e78e853ab47e80de518
RCT-Folly: 02617c592a293bd6d418e0a88ff4ee1f88329b47
RCTDeprecation: 3afceddffa65aee666dafd6f0116f1d975db1584
RCTRequired: ec1239bc9d8bf63e10fb92bd8b26171a9258e0c1
Expand Down
2 changes: 1 addition & 1 deletion example/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module.exports = {
preset: 'react-native',
}
};
10 changes: 6 additions & 4 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
"scripts": {
"android": "react-native run-android",
"ios": "react-native run-ios",
"clean": "del-cli android/build node_modules/**/android/build lib",
"clean": "del-cli android/build android/app/build ios/build lib",
"tsc": "tsc --noEmit",
"typescript": "tsc --noEmit",
"lint": "eslint \"**/*.{js,ts,tsx}\"",
"lint-fix": "eslint \"**/*.{js,ts,tsx}\" --fix",
"lint:fix": "eslint \"**/*.{js,ts,tsx}\" --fix",
"format": "prettier --check \"**/*.{js,ts,tsx}\"",
"format:fix": "prettier --write \"**/*.{js,ts,tsx}\"",
"start": "react-native start",
"pods": "cd ios && RCT_NEW_ARCH_ENABLED=1 bundle exec pod install && rm -rf .xcode.env.local",
"pods": "cd ios && RCT_NEW_ARCH_ENABLED=1 bundle exec pod install",
"build:android": "cd android && ./gradlew assembleDebug --no-daemon --console=plain -PreactNativeArchitectures=arm64-v8a",
"build:ios": "cd ios && xcodebuild -workspace QuickCrytpExample.xcworkspace -scheme QuickCrytpExample -configuration Debug -sdk iphonesimulator CC=clang CPLUSPLUS=clang++ LD=clang LDPLUSPLUS=clang++ GCC_OPTIMIZATION_LEVEL=0 GCC_PRECOMPILE_PREFIX_HEADER=YES ASSETCATALOG_COMPILER_OPTIMIZATION=time DEBUG_INFORMATION_FORMAT=dwarf COMPILER_INDEX_STORE_ENABLE=NO"
},
Expand All @@ -29,7 +31,7 @@
"react": "^18.3.1",
"react-native": "^0.74.5",
"react-native-bouncy-checkbox": "4.0.1",
"react-native-nitro-modules": "0.7.0",
"react-native-nitro-modules": "0.9.2",
"react-native-quick-base64": "2.1.2",
"react-native-quick-crypto": "*",
"react-native-safe-area-context": "4.10.8",
Expand Down
6 changes: 3 additions & 3 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react'
import { Root } from './navigators/Root'
import * as React from 'react';
import { Root } from './navigators/Root';

export default function App() {
return <Root />
return <Root />;
}
14 changes: 7 additions & 7 deletions example/src/benchmarks/crypto-browserify/random.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
// @ts-expect-error - crypto-browserify is not typed
import { randomBytes } from 'crypto-browserify'
import type { BenchmarkFn } from '../types'
import { randomBytes } from 'crypto-browserify';
import type { BenchmarkFn } from '../types';

const randomBytes10: BenchmarkFn = () => {
randomBytes(10)
}
randomBytes(10);
};

const randomBytes1024: BenchmarkFn = () => {
randomBytes(1024)
}
randomBytes(1024);
};

export default {
randomBytes10,
randomBytes1024,
}
};
14 changes: 7 additions & 7 deletions example/src/benchmarks/rnqc/random.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import rnqc from 'react-native-quick-crypto'
import type { BenchmarkFn } from '../types'
import rnqc from 'react-native-quick-crypto';
import type { BenchmarkFn } from '../types';

const randomBytes10: BenchmarkFn = () => {
rnqc.randomBytes(10)
}
rnqc.randomBytes(10);
};

const randomBytes1024: BenchmarkFn = () => {
rnqc.randomBytes(1024)
}
rnqc.randomBytes(1024);
};

export default {
randomBytes10,
randomBytes1024,
}
};
2 changes: 1 addition & 1 deletion example/src/benchmarks/types.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export type BenchmarkFn = () => void
export type BenchmarkFn = () => void;
14 changes: 7 additions & 7 deletions example/src/benchmarks/utils.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import type { BenchmarkResult } from '../types/Results'
import type { BenchmarkResult } from '../types/Results';

export const formatNumber = (
n: number,
decimals: number,
suffix: string
suffix: string,
): string => {
if (isNaN(n)) {
return ''
return '';
}
return n.toFixed(decimals) + suffix
}
return n.toFixed(decimals) + suffix;
};

export const calculateTimes = (result: BenchmarkResult): number => {
return result.type === 'faster'
? 1 + (result.them - result.us) / result.us
: 1 + (result.us - result.them) / result.them
}
: 1 + (result.us - result.them) / result.them;
};
57 changes: 28 additions & 29 deletions example/src/components/BenchmarkItem.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import React from 'react'
import { View, Text, StyleSheet, TouchableOpacity } from 'react-native'
import BouncyCheckbox from 'react-native-bouncy-checkbox'
import type { BenchmarkResult } from '../types/Results'
import { useNavigation } from '@react-navigation/native'
import { calculateTimes, formatNumber } from '../benchmarks/utils'
import { colors } from '../styles/colors'
import React from 'react';
import { View, Text, StyleSheet, TouchableOpacity } from 'react-native';
import BouncyCheckbox from 'react-native-bouncy-checkbox';
import type { BenchmarkResult } from '../types/Results';
import { useNavigation } from '@react-navigation/native';
import { calculateTimes, formatNumber } from '../benchmarks/utils';
import { colors } from '../styles/colors';

type BenchmarkItemProps = {
description: string
value: boolean
count: number
results: BenchmarkResult[]
onToggle: (description: string) => void
}
description: string;
value: boolean;
count: number;
results: BenchmarkResult[];
onToggle: (description: string) => void;
};

export const BenchmarkItem: React.FC<BenchmarkItemProps> = ({
description,
Expand All @@ -21,32 +21,32 @@ export const BenchmarkItem: React.FC<BenchmarkItemProps> = ({
results,
onToggle,
}: BenchmarkItemProps) => {
const navigation = useNavigation()
const navigation = useNavigation();
const stats = {
us: 0,
them: 0,
}
results.map((r) => {
stats.us += r.us
stats.them += r.them
})
const timesType = stats.us < stats.them ? 'faster' : 'slower'
const timesStyle = timesType === 'faster' ? styles.faster : styles.slower
};
results.map(r => {
stats.us += r.us;
stats.them += r.them;
});
const timesType = stats.us < stats.them ? 'faster' : 'slower';
const timesStyle = timesType === 'faster' ? styles.faster : styles.slower;
const times = calculateTimes({
type: timesType,
...stats,
// rest of these are for matching type, ignore
description: '',
indentation: 0,
suiteName: '',
})
});

return (
<View style={styles.container}>
<BouncyCheckbox
isChecked={value}
onPress={() => {
onToggle(description)
onToggle(description);
}}
disableText={true}
fillColor={colors.blue}
Expand All @@ -59,9 +59,8 @@ export const BenchmarkItem: React.FC<BenchmarkItemProps> = ({
navigation.navigate('BenchmarkDetailsScreen', {
results,
suiteName: description,
})
}}
>
});
}}>
<Text style={styles.label} numberOfLines={1}>
{description}
</Text>
Expand All @@ -73,8 +72,8 @@ export const BenchmarkItem: React.FC<BenchmarkItemProps> = ({
</Text>
</TouchableOpacity>
</View>
)
}
);
};

const styles = StyleSheet.create({
container: {
Expand Down Expand Up @@ -117,4 +116,4 @@ const styles = StyleSheet.create({
flex: 1,
textAlign: 'right',
},
})
});
Loading
Loading