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

Minor fixes #199

Merged
merged 31 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
fc270b7
Update README
ospfranco Nov 28, 2023
e7a886b
Make test UI a bit nicer and fix an unhandled error on randomFill
ospfranco Nov 28, 2023
4153b5a
Fix some tests and some types
ospfranco Nov 28, 2023
8e2b6c2
Add a guard for buffer enconding
ospfranco Nov 28, 2023
91d2079
Add type to import pbkdf2
ospfranco Nov 29, 2023
debcda6
Typescript fixes
ospfranco Dec 1, 2023
81e68c3
Add types to parent package
ospfranco Dec 1, 2023
e6ad40f
Dependencies
ospfranco Dec 1, 2023
fddc858
Update gradle wrapper
ospfranco Dec 1, 2023
26d61aa
Update Java version on action
ospfranco Dec 1, 2023
4438955
Update Java version on action
ospfranco Dec 1, 2023
e40020e
Update Java version on action
ospfranco Dec 1, 2023
6b29968
Remove yarn.lock changes action
ospfranco Dec 1, 2023
f90833d
Do not use build caches
ospfranco Dec 1, 2023
0b192e8
Do not use build caches
ospfranco Dec 1, 2023
b278ae1
Change react native android dependency
ospfranco Dec 1, 2023
91b70e3
Fix Android compilation
ospfranco Dec 1, 2023
3267110
Change lint to run on example folder
ospfranco Dec 1, 2023
757be80
Change lint to run on example folder
ospfranco Dec 1, 2023
7b7d3d4
Change lint to run on example folder
ospfranco Dec 1, 2023
d4da5f7
Change lint to run on example folder
ospfranco Dec 1, 2023
d938cd3
Update Lint Report action version
ospfranco Dec 2, 2023
fd04d7d
Update Lint Report action version
ospfranco Dec 2, 2023
0c53ab3
Update JDK Setup
ospfranco Dec 2, 2023
c0834a9
Update dependencies
ospfranco Dec 2, 2023
34c1539
Update dependencies
ospfranco Dec 2, 2023
dba27ff
linting
ospfranco Dec 2, 2023
8c609f3
Reinsert deps
ospfranco Dec 2, 2023
0463e24
lock
ospfranco Dec 2, 2023
8afc4a5
lock
ospfranco Dec 2, 2023
12137dd
Add back debug config
ospfranco Dec 13, 2023
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
33 changes: 18 additions & 15 deletions .github/workflows/build-android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,17 @@ jobs:
steps:
- uses: actions/checkout@v2

- name: Setup JDK 1.8
uses: actions/setup-java@v1
- name: Setup JDK
uses: actions/setup-java@v3
with:
java-version: 1.8
distribution: zulu
java-version: 11
cache: gradle

- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"

- name: Restore node_modules from cache
uses: actions/cache@v2
id: yarn-cache
Expand All @@ -46,16 +49,16 @@ jobs:
- name: Install node_modules for example/
run: yarn install --frozen-lockfile --cwd example

- name: Restore Gradle cache
uses: actions/cache@v2
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Run Gradle Build for android/
run: cd android && ./gradlew assembleDebug --build-cache && cd ..
# - name: Restore Gradle cache
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why it's commented out?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setup-java@v3 already has a cache logic integrated, see line 33

# uses: actions/cache@v2
# with:
# path: |
# ~/.gradle/caches
# ~/.gradle/wrapper
# key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
# restore-keys: |
# ${{ runner.os }}-gradle-
# - name: Run Gradle Build for android/
# run: cd android && ./gradlew assembleDebug && cd ..
- name: Run Gradle Build for example/android/
run: cd example/android && ./gradlew assembleDebug --build-cache && cd ../..
run: cd example/android && ./gradlew assembleDebug && cd ../..
19 changes: 0 additions & 19 deletions .github/workflows/notice-yarn-changes.yml

This file was deleted.

35 changes: 20 additions & 15 deletions .github/workflows/validate-android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@ jobs:
working-directory: ./android
steps:
- uses: actions/checkout@v2
- name: Setup JDK 1.8
uses: actions/setup-java@v1

- name: Setup JDK
uses: actions/setup-java@v3
with:
java-version: 1.8
distribution: zulu
java-version: 11
cache: gradle

- name: Get yarn cache directory path
id: yarn-cache-dir-path
Expand All @@ -44,22 +47,24 @@ jobs:
- name: Install node_modules for example/
run: yarn install --frozen-lockfile --cwd ../example

- name: Restore Gradle cache
uses: actions/cache@v2
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
# - name: Restore Gradle cache
# uses: actions/cache@v2
# with:
# path: |
# ~/.gradle/caches
# ~/.gradle/wrapper
# key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
# restore-keys: |
# ${{ runner.os }}-gradle-

- name: Run Gradle Lint
run: ./gradlew lint --build-cache
run: cd ../example/android && ./gradlew lint

- name: Parse Gradle Lint Report
uses: yutailang0119/action-android-lint@v1.0.2
uses: yutailang0119/action-android-lint@v3
with:
xml_path: android/build/reports/lint-results.xml
# ignore-warnings: true
report-path: example/android/app/build/reports/*.xml
# ktlint:
# name: Kotlin Lint
# runs-on: ubuntu-latest
Expand Down
108 changes: 54 additions & 54 deletions .github/workflows/validate-js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,74 +33,74 @@ jobs:
name: Compile JS (tsc)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v2

- name: Install reviewdog
uses: reviewdog/action-setup@v1
- name: Install reviewdog
uses: reviewdog/action-setup@v1

- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- name: Restore node_modules from cache
uses: actions/cache@v2
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- name: Restore node_modules from cache
uses: actions/cache@v2
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-

- name: Install node_modules
run: yarn install --frozen-lockfile
- name: Install node_modules (example/)
run: yarn install --frozen-lockfile --cwd example
- name: Install node_modules
run: yarn install --frozen-lockfile
- name: Install node_modules (example/)
run: yarn install --frozen-lockfile --cwd example

- name: Run TypeScript # Reviewdog tsc errorformat: %f:%l:%c - error TS%n: %m
run: |
yarn typescript | reviewdog -name="tsc" -efm="%f(%l,%c): error TS%n: %m" -reporter="github-pr-review" -filter-mode="nofilter" -fail-on-error -tee
env:
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Run TypeScript # Reviewdog tsc errorformat: %f:%l:%c - error TS%n: %m
run: |
yarn typescript | reviewdog -name="tsc" -efm="%f(%l,%c): error TS%n: %m" -reporter="github-pr-review" -filter-mode="nofilter" -fail-on-error -tee
env:
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Run TypeScript in example/ # Reviewdog tsc errorformat: %f:%l:%c - error TS%n: %m
run: |
cd example && yarn typescript | reviewdog -name="tsc" -efm="%f(%l,%c): error TS%n: %m" -reporter="github-pr-review" -filter-mode="nofilter" -fail-on-error -tee && cd ..
env:
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Run TypeScript in example/ # Reviewdog tsc errorformat: %f:%l:%c - error TS%n: %m
run: |
cd example && yarn typescript | reviewdog -name="tsc" -efm="%f(%l,%c): error TS%n: %m" -reporter="github-pr-review" -filter-mode="nofilter" -fail-on-error -tee && cd ..
env:
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}

lint:
name: Lint JS (eslint, prettier)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v2

- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- name: Restore node_modules from cache
uses: actions/cache@v2
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- name: Restore node_modules from cache
uses: actions/cache@v2
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-

- name: Install node_modules
run: yarn install --frozen-lockfile
- name: Install node_modules (example/)
run: yarn install --frozen-lockfile --cwd example
- name: Install node_modules
run: yarn install --frozen-lockfile
- name: Install node_modules (example/)
run: yarn install --frozen-lockfile --cwd example

- name: Run ESLint
run: yarn lint -f @jamesacarr/github-actions
- name: Run ESLint
run: yarn lint -f @jamesacarr/github-actions

- name: Run ESLint with auto-fix
run: yarn lint --fix
- name: Run ESLint with auto-fix
run: yarn lint --fix

- name: Run ESLint in example/
run: cd example && yarn lint -f @jamesacarr/github-actions && cd ..
- name: Run ESLint in example/
run: cd example && yarn lint -f @jamesacarr/github-actions && cd ..

- name: Run ESLint in example/ with auto-fix
run: cd example && yarn lint --fix && cd ..
- name: Run ESLint in example/ with auto-fix
run: cd example && yarn lint --fix && cd ..

- name: Verify no files have changed after auto-fix
run: git diff --exit-code HEAD
- name: Verify no files have changed after auto-fix
run: git diff --exit-code HEAD
36 changes: 19 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@ A fast implementation of Node's `crypto` module.
Unlike any other current JS-based polyfills, react-native-quick-crypto is written in C/C++ JSI and provides much greater performance - especially on mobile devices.
QuickCrypto can be used as a drop-in replacement for your Web3/Crypto apps to speed up common cryptography functions.

* 🏎️ Up to 58x faster than all other solutions
* ⚡️ Lightning fast implementation with pure C++ and JSI, instead of JS
* 🧪 Well tested in JS and C++ (OpenSSL)
* 💰 Made for crypto apps and Wallets
* 🔢 Secure native compiled cryptography
* 🔁 Easy drop-in replacement for [crypto-browserify](https://github.com/crypto-browserify/crypto-browserify) or [react-native-crypto](https://github.com/tradle/react-native-crypto)
- 🏎️ Up to 58x faster than all other solutions
- ⚡️ Lightning fast implementation with pure C++ and JSI, instead of JS
- 🧪 Well tested in JS and C++ (OpenSSL)
- 💰 Made for crypto apps and Wallets
- 🔢 Secure native compiled cryptography
- 🔁 Easy drop-in replacement for [crypto-browserify](https://github.com/crypto-browserify/crypto-browserify) or [react-native-crypto](https://github.com/tradle/react-native-crypto)

For example, creating a Wallet using ethers.js uses complex algorithms to generate a private-key/mnemonic-phrase pair:

```ts
const start = performance.now()
const wallet = ethers.Wallet.createRandom()
const end = performance.now()
console.log(`Creating a Wallet took ${end - start} ms.`)
const start = performance.now();
const wallet = ethers.Wallet.createRandom();
const end = performance.now();
console.log(`Creating a Wallet took ${end - start} ms.`);
```

**Without** react-native-quick-crypto 🐢:
Expand Down Expand Up @@ -65,7 +65,13 @@ expo prebuild

If you are using a library that depends on `crypto`, instead of polyfilling it with `crypto-browserify` (or `react-native-crypto`) you can use `react-native-quick-crypto` for a fully native implementation. This way you can get much faster crypto operations with just a single-line change!

In your `babel.config.js`, add a module resolver to replace `crypto` with `react-native-quick-crypto`:
You need to install `babel-plugin-module-resolver`, it's a babel plugin that will alias any imports in the code with the values you pass to it. It tricks any module that will try to import certain dependencies with the native versions we require for React Native.

```sh
yarn add --dev babel-plugin-module-resolver
```

In your `babel.config.js`, add the plugin to swap the `crypto`, `stream` and `buffer` dependencies:

```diff
module.exports = {
Expand All @@ -88,20 +94,16 @@ module.exports = {

Then restart your bundler using `yarn start --reset-cache`.

Now, all imports for `crypto` will be resolved as `react-native-quick-crypto` instead.

> 💡 Since react-native-quick-crypto depends on `stream` and `buffer`, we can resolve those to `stream-browserify` and @craftzdog's `react-native-buffer` (which is faster than `buffer` because it uses JSI for base64 encoding and decoding).

## Usage

For example, to hash a string with SHA256 you can do the following:

```ts
import Crypto from 'react-native-quick-crypto'
import Crypto from 'react-native-quick-crypto';

const hashed = Crypto.createHash('sha256')
.update('Damn, Margelo writes hella good software!')
.digest('hex')
.digest('hex');
```

---
Expand Down
Loading
Loading