Skip to content

Commit 08104ea

Browse files
authored
fix: export Buffer from react-native-quick-crypto (#899)
1 parent 21ffee2 commit 08104ea

32 files changed

Lines changed: 143 additions & 51 deletions

.claude/commands/pr.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# /pr - Create Pull Request
2+
3+
Create a pull request for the current branch.
4+
5+
## Instructions
6+
7+
When activated, create a pull request for the current branch:
8+
9+
1. **Verify branch state**:
10+
- Run `git branch --show-current` to get the current branch name
11+
- Ensure we're not on `main` (abort if so)
12+
- Run `git log main..HEAD --oneline` to see commits to include
13+
14+
2. **Push the branch** (if not already pushed):
15+
- Run `git push -u origin <branch-name>`
16+
17+
3. **Check for related issues**:
18+
- Look at the branch name for issue numbers (e.g., `fix/896-buffer-import` references #896)
19+
- Check commit messages for issue references
20+
- Run `gh issue list --state open --limit 20` to see recent open issues that might be related
21+
- If the PR resolves an issue, note it for the body
22+
23+
4. **Generate PR title and body**:
24+
- Title: Use conventional commit format based on the primary change (e.g., `fix: import Buffer from react-native-quick-crypto`)
25+
- Body should include:
26+
- **Summary**: Brief description of what this PR does
27+
- **Changes**: Bullet list of key changes
28+
- **Testing**: How to test the changes (if applicable)
29+
- **Issue references**: Add `Fixes #XXX` or `Closes #XXX` for any issues this PR resolves (these will auto-close the issues when merged)
30+
31+
5. **Create the PR**:
32+
```bash
33+
gh pr create --title "<title>" --body "<body>" --base main
34+
```
35+
36+
6. **Report the PR URL** to the user
37+
38+
If the user provides arguments (e.g., `/pr "Custom title"`), use that as the PR title instead of generating one.

.claude/commands/review.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# /review - Code Review Branch Commits
2+
3+
Review all commits on the current branch since diverging from main.
4+
5+
## Prerequisites
6+
7+
**IMPORTANT**: Before starting the review, check if this is a fresh context/session:
8+
- If there is prior conversation history in this session (e.g., you helped write the code being reviewed), STOP immediately
9+
- Inform the user: "Code reviews should be done in a fresh context to avoid bias. Please start a new Claude Code session and run /review there."
10+
- A reviewer should not be the same "person" who wrote the code
11+
12+
## Instructions
13+
14+
When activated (in a fresh session), perform a full code review of the commits since branching from main:
15+
16+
1. **Get the commits**: Run `git log main..HEAD --oneline` to see all commits on this branch
17+
2. **Get the full diff**: Run `git diff main..HEAD` to see all changes
18+
3. **For each file changed**, read enough context to understand the changes
19+
4. **Review for**:
20+
- Correctness and logic errors
21+
- Consistency with existing patterns in the codebase
22+
- TypeScript best practices
23+
- C++ best practices (if touching native code)
24+
- Cryptographic correctness (if touching crypto code)
25+
- Potential bugs or edge cases
26+
- Missing error handling
27+
- Code clarity and maintainability
28+
5. **Provide a structured review** with:
29+
- Summary of what the branch does
30+
- Positives (what's done well)
31+
- Issues & suggestions (ranked by severity)
32+
- Recommended actions (if any)
33+
34+
Run `bun tsc` to verify the code compiles.

.github/workflows/e2e-android-test.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,7 @@ jobs:
7070
example/android/build
7171
example/android/app/.cxx
7272
example/android/app/build
73-
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
74-
restore-keys: |
75-
${{ runner.os }}-gradle-
73+
key: ${{ runner.os }}-gradle
7674

7775
- name: Install System Dependencies
7876
run: |
@@ -174,7 +172,7 @@ jobs:
174172
example/android/build
175173
example/android/app/.cxx
176174
example/android/app/build
177-
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
175+
key: ${{ runner.os }}-gradle
178176

179177
- name: Exit with Test Result
180178
if: always()

.github/workflows/e2e-ios-test.yml

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,22 +65,22 @@ jobs:
6565
run: bun install
6666

6767
- name: Restore CocoaPods cache
68-
uses: actions/cache@v5
6968
id: pods-cache
69+
uses: actions/cache/restore@v5
7070
with:
7171
path: |
7272
example/ios/Pods
7373
~/Library/Caches/CocoaPods
74-
key: ${{ runner.os }}-pods-${{ hashFiles('example/ios/Podfile.lock') }}
74+
packages/react-native-quick-crypto/ios/libsodium-stable
75+
packages/react-native-quick-crypto/deps
76+
key: ${{ runner.os }}-pods
7577

7678
- name: Restore DerivedData cache
7779
id: dd-cache
7880
uses: actions/cache/restore@v5
7981
with:
8082
path: ${{ env.DERIVED_DATA_PATH }}
81-
key: ${{ runner.os }}-dd-${{ hashFiles('example/ios/Podfile.lock', 'package.json', 'bun.lock') }}-xcode26.2
82-
restore-keys: |
83-
${{ runner.os }}-dd-
83+
key: ${{ runner.os }}-dd
8484

8585
- name: Boot iOS Simulator (background)
8686
run: |
@@ -215,12 +215,23 @@ jobs:
215215
${{ env.OUTPUT_DIR }}/screenshots/*.png
216216
retention-days: 5
217217

218+
- name: Save CocoaPods cache
219+
if: always()
220+
uses: actions/cache/save@v5
221+
with:
222+
path: |
223+
example/ios/Pods
224+
~/Library/Caches/CocoaPods
225+
packages/react-native-quick-crypto/ios/libsodium-stable
226+
packages/react-native-quick-crypto/deps
227+
key: ${{ runner.os }}-pods
228+
218229
- name: Save DerivedData cache
219230
if: always()
220231
uses: actions/cache/save@v5
221232
with:
222233
path: ${{ env.DERIVED_DATA_PATH }}
223-
key: ${{ runner.os }}-dd-${{ hashFiles('example/ios/Podfile.lock', 'package.json', 'bun.lock') }}-xcode26.2
234+
key: ${{ runner.os }}-dd
224235

225236
- name: Exit with Test Result
226237
if: always()

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ module.exports = {
114114
+ alias: {
115115
+ 'crypto': 'react-native-quick-crypto',
116116
+ 'stream': 'readable-stream',
117-
+ 'buffer': '@craftzdog/react-native-buffer',
117+
+ 'buffer': 'react-native-quick-crypto',
118118
+ },
119119
+ },
120120
+ ],
@@ -123,6 +123,8 @@ module.exports = {
123123
};
124124
```
125125

126+
> **Note:** `react-native-quick-crypto` re-exports `Buffer` from `@craftzdog/react-native-buffer`, so you can use either as the buffer alias. Using `react-native-quick-crypto` ensures a single Buffer instance across your app.
127+
126128
Then restart your bundler using `yarn start --reset-cache`.
127129

128130
## Usage

docs/content/docs/api/install.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,6 @@ const buf = Buffer.from('hello');
5252

5353
## What gets polyfilled?
5454

55-
1. **`global.Buffer`**: Via [`@craftzdog/react-native-buffer`](https://github.com/craftzdog/react-native-buffer).
55+
1. **`global.Buffer`**: Re-exported from [`@craftzdog/react-native-buffer`](https://github.com/craftzdog/react-native-buffer). You can also import it directly: `import { Buffer } from 'react-native-quick-crypto'`.
5656
2. **`global.crypto`**: Points to `QuickCrypto`.
5757
3. **`global.process`**: Adds `process.nextTick` (mapped to `setImmediate`).

docs/content/docs/introduction/complete-setup.mdx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,14 +173,18 @@ module.exports = {
173173
+ alias: {
174174
+ 'crypto': 'react-native-quick-crypto',
175175
+ 'stream': 'readable-stream',
176-
+ 'buffer': '@craftzdog/react-native-buffer',
176+
+ 'buffer': 'react-native-quick-crypto',
177177
+ },
178178
+ },
179179
+ ],
180180
...
181181
],
182182
};
183183
```
184+
185+
<Callout type="info">
186+
`react-native-quick-crypto` re-exports `Buffer` from `@craftzdog/react-native-buffer`, so you can use either as the buffer alias. Using `react-native-quick-crypto` ensures a single Buffer instance across your app.
187+
</Callout>
184188
</Step>
185189

186190
<Step>

example/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
"build:ios": "cd ios && xcodebuild -workspace QuickCryptoExample.xcworkspace -scheme QuickCryptoExample -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"
2323
},
2424
"dependencies": {
25-
"@craftzdog/react-native-buffer": "6.1.0",
2625
"@noble/ciphers": "2.0.1",
2726
"@noble/curves": "1.7.0",
2827
"@noble/hashes": "1.5.0",

example/src/benchmarks/hkdf/hkdf.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import rnqc from 'react-native-quick-crypto';
1+
import rnqc, { Buffer } from 'react-native-quick-crypto';
22
import { hkdf } from '@noble/hashes/hkdf';
33
import { sha256 } from '@noble/hashes/sha2';
44
import type { BenchFn } from '../../types/benchmarks';
55
import { Bench } from 'tinybench';
6-
import { Buffer } from '@craftzdog/react-native-buffer';
76

87
const TIME_MS = 1000;
98

example/src/tests/blake3/blake3_tests.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
import { Buffer } from '@craftzdog/react-native-buffer';
21
import { expect } from 'chai';
3-
import { Blake3, createBlake3, blake3 } from 'react-native-quick-crypto';
2+
import {
3+
Blake3,
4+
Buffer,
5+
createBlake3,
6+
blake3,
7+
} from 'react-native-quick-crypto';
48
import { test } from '../util';
59

610
const SUITE = 'blake3';

0 commit comments

Comments
 (0)