-
Notifications
You must be signed in to change notification settings - Fork 108
feat: expand support with modern curves, AEAD, key wrapping, derivation & HMAC #840
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
225eece
feat: add X25519/X448 ECDH support
athexweb3 faf6541
feat: add ChaCha20-Poly1305 support
athexweb3 c8f90ca
feat: implement wrapKey, unwrapKey, and deriveKey WebCrypto methods
athexweb3 245b0f7
feat: implement HMAC sign/verify and fix X25519/X448 deriveBits
athexweb3 e8e60b3
chore: use workspace protocol for example app dependency
athexweb3 de37c5d
fix: address review feedback from rebase
athexweb3 d3cca97
fix: sort subtle test imports alphabetically
athexweb3 5f47598
fix: restored mistakenly removed lines
athexweb3 e2c1c80
fix; final cleanup
boorad dae1fb9
fix: make screenshot upload optional when IMGBB_API_KEY is unavailabl…
boorad cfb4b56
fix: implement AES-KW (RFC 3394) for wrapKey/unwrapKey operations
boorad File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,7 +14,7 @@ inputs: | |
| default: 'unknown' | ||
| imgbb-api-key: | ||
| description: 'ImgBB API key for image hosting' | ||
| required: true | ||
| required: false | ||
|
|
||
| runs: | ||
| using: 'composite' | ||
|
|
@@ -69,7 +69,7 @@ runs: | |
| fi | ||
|
|
||
| - name: Upload screenshot to ImgBB | ||
| if: steps.check-screenshot.outputs.exists == 'true' && github.event_name == 'pull_request' | ||
| if: steps.check-screenshot.outputs.exists == 'true' && github.event_name == 'pull_request' && inputs.imgbb-api-key != '' | ||
| id: upload-screenshot | ||
| uses: McCzarny/[email protected] | ||
| with: | ||
|
|
@@ -82,13 +82,15 @@ runs: | |
| uses: peter-evans/find-comment@v3 | ||
| id: find-comment | ||
| if: github.event_name == 'pull_request' | ||
| continue-on-error: true | ||
| with: | ||
| issue-number: ${{ github.event.pull_request.number }} | ||
| comment-author: 'github-actions[bot]' | ||
| body-includes: End-to-End Test Results - ${{ inputs.platform == 'ios' && 'iOS' || 'Android' }} | ||
|
|
||
| - name: Create or update PR comment (with screenshot) | ||
| if: github.event_name == 'pull_request' && steps.check-screenshot.outputs.exists == 'true' && steps.upload-screenshot.outputs.url | ||
| continue-on-error: true | ||
| uses: peter-evans/create-or-update-comment@v4 | ||
| with: | ||
| token: ${{ inputs.github-token }} | ||
|
|
@@ -113,6 +115,7 @@ runs: | |
|
|
||
| - name: Create or update PR comment (no screenshot) | ||
| if: github.event_name == 'pull_request' && steps.check-screenshot.outputs.exists != 'true' | ||
| continue-on-error: true | ||
| uses: peter-evans/create-or-update-comment@v4 | ||
| with: | ||
| token: ${{ inputs.github-token }} | ||
|
|
@@ -135,6 +138,7 @@ runs: | |
|
|
||
| - name: Create or update PR comment (upload failed) | ||
| if: github.event_name == 'pull_request' && steps.check-screenshot.outputs.exists == 'true' && !steps.upload-screenshot.outputs.url | ||
| continue-on-error: true | ||
| uses: peter-evans/create-or-update-comment@v4 | ||
| with: | ||
| token: ${{ inputs.github-token }} | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -187,4 +187,6 @@ tsconfig.tsbuildinfo | |
| # development stuffs | ||
| *scratch* | ||
|
|
||
| # agents | ||
| .claude/settings.local.json | ||
| .agent/ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,7 +30,7 @@ | |
| }, | ||
| "example": { | ||
| "name": "react-native-quick-crypto-example", | ||
| "version": "1.0.0", | ||
| "version": "1.0.1", | ||
| "dependencies": { | ||
| "@craftzdog/react-native-buffer": "6.1.0", | ||
| "@noble/ciphers": "^2.0.1", | ||
|
|
@@ -47,7 +47,7 @@ | |
| "react": "19.1.0", | ||
| "react-native": "0.81.1", | ||
| "react-native-bouncy-checkbox": "4.1.2", | ||
| "react-native-fast-encoder": "^0.3.1", | ||
| "react-native-fast-encoder": "0.3.1", | ||
| "react-native-nitro-modules": "0.29.1", | ||
| "react-native-quick-base64": "2.2.2", | ||
| "react-native-quick-crypto": "workspace:*", | ||
|
|
@@ -87,7 +87,7 @@ | |
| }, | ||
| "packages/react-native-quick-crypto": { | ||
| "name": "react-native-quick-crypto", | ||
| "version": "1.0.0", | ||
| "version": "1.0.1", | ||
| "dependencies": { | ||
| "@craftzdog/react-native-buffer": "6.1.0", | ||
| "events": "3.3.0", | ||
|
|
@@ -1308,7 +1308,7 @@ | |
|
|
||
| "expo-asset": ["[email protected]", "", { "dependencies": { "@expo/image-utils": "^0.8.7", "expo-constants": "~18.0.10" }, "peerDependencies": { "expo": "*", "react": "*", "react-native": "*" } }, "sha512-pZyeJkoDsALh4gpCQDzTA/UCLaPH/1rjQNGubmLn/uDM27S4iYJb/YWw4+CNZOtd5bCUOhDPg5DtGQnydNFSXg=="], | ||
|
|
||
| "expo-build-properties": ["[email protected].9", "", { "dependencies": { "ajv": "^8.11.0", "semver": "^7.6.0" }, "peerDependencies": { "expo": "*" } }, "sha512-2icttCy3OPTk/GWIFt+vwA+0hup53jnmYb7JKRbvNvrrOrz+WblzpeoiaOleI2dYG/vjwpNO8to8qVyKhYJtrQ=="], | ||
| "expo-build-properties": ["[email protected].10", "", { "dependencies": { "ajv": "^8.11.0", "semver": "^7.6.0" }, "peerDependencies": { "expo": "*" } }, "sha512-mFCZbrbrv0AP5RB151tAoRzwRJelqM7bCJzCkxpu+owOyH+p/rFC/q7H5q8B9EpVWj8etaIuszR+gKwohpmu1Q=="], | ||
|
|
||
| "expo-constants": ["[email protected]", "", { "dependencies": { "@expo/config": "~12.0.10", "@expo/env": "~2.0.7" }, "peerDependencies": { "expo": "*", "react-native": "*" } }, "sha512-Rhtv+X974k0Cahmvx6p7ER5+pNhBC0XbP1lRviL2J1Xl4sT2FBaIuIxF/0I0CbhOsySf0ksqc5caFweAy9Ewiw=="], | ||
|
|
||
|
|
@@ -1340,7 +1340,7 @@ | |
|
|
||
| "fast-levenshtein": ["[email protected]", "", {}, ""], | ||
|
|
||
| "fast-uri": ["fast-uri@3.1.0", "", {}, "sha512-iPeeDKJSWf4IEOasVVrknXpaBV0IApz/gp7S2bb7Z4Lljbl2MGJRqInZiUrQwV16cpzw/D3S5j5Julj/gT52AA=="], | ||
| "fast-uri": ["fast-uri@3.0.6", "", {}, "sha512-Atfo14OibSv5wAp4VWNsFYE1AchQRTv9cBGWET4pZWHzYshFSS9NQI6I57rdKn9croWVMbYFbLhJ+yJvmZIIHw=="], | ||
|
|
||
| "fast-xml-parser": ["[email protected]", "", { "dependencies": { "strnum": "^1.0.5" }, "bin": { "fxparser": "src/cli/cli.js" } }, ""], | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| import { test } from '../util'; | ||
| import { expect } from 'chai'; | ||
| import { subtle, getRandomValues } from 'react-native-quick-crypto'; | ||
| import { CryptoKey } from 'react-native-quick-crypto'; | ||
| import type { CryptoKeyPair } from 'react-native-quick-crypto'; | ||
|
|
||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| const subtleAny = subtle as any; | ||
|
|
||
| const SUITE = 'subtle.deriveKey'; | ||
|
|
||
| // Test 1: PBKDF2 deriveKey | ||
| test(SUITE, 'PBKDF2 deriveKey to AES-GCM', async () => { | ||
| const password = new TextEncoder().encode('my-password'); | ||
| const salt = getRandomValues(new Uint8Array(16)); | ||
|
|
||
| const baseKey = await subtle.importKey( | ||
| 'raw', | ||
| password, | ||
| { name: 'PBKDF2' }, | ||
| false, | ||
| ['deriveKey'], | ||
| ); | ||
|
|
||
| const derivedKey = await subtleAny.deriveKey( | ||
| { | ||
| name: 'PBKDF2', | ||
| salt, | ||
| iterations: 100000, | ||
| hash: 'SHA-256', | ||
| }, | ||
| baseKey as CryptoKey, | ||
| { name: 'AES-GCM', length: 256 }, | ||
| true, | ||
| ['encrypt', 'decrypt'], | ||
| ); | ||
|
|
||
| // Verify key can encrypt/decrypt | ||
| const plaintext = new Uint8Array([1, 2, 3, 4]); | ||
| const iv = getRandomValues(new Uint8Array(12)); | ||
|
|
||
| const ciphertext = await subtle.encrypt( | ||
| { name: 'AES-GCM', iv }, | ||
| derivedKey as CryptoKey, | ||
| plaintext, | ||
| ); | ||
|
|
||
| const decrypted = await subtle.decrypt( | ||
| { name: 'AES-GCM', iv }, | ||
| derivedKey as CryptoKey, | ||
| ciphertext, | ||
| ); | ||
|
|
||
| expect(Buffer.from(decrypted).toString('hex')).to.equal( | ||
| Buffer.from(plaintext).toString('hex'), | ||
| ); | ||
| }); | ||
|
|
||
| // Test 2: X25519 deriveKey | ||
| test(SUITE, 'X25519 deriveKey to AES-GCM', async () => { | ||
| const aliceKeyPair = await subtle.generateKey({ name: 'X25519' }, false, [ | ||
| 'deriveKey', | ||
| 'deriveBits', | ||
| ]); | ||
|
|
||
| const bobKeyPair = await subtle.generateKey({ name: 'X25519' }, false, [ | ||
| 'deriveKey', | ||
| 'deriveBits', | ||
| ]); | ||
|
|
||
| const aliceDerivedKey = await subtleAny.deriveKey( | ||
| { | ||
| name: 'X25519', | ||
| public: (bobKeyPair as CryptoKeyPair).publicKey, | ||
| }, | ||
| (aliceKeyPair as CryptoKeyPair).privateKey, | ||
| { name: 'AES-GCM', length: 256 }, | ||
| true, | ||
| ['encrypt', 'decrypt'], | ||
| ); | ||
|
|
||
| const bobDerivedKey = await subtleAny.deriveKey( | ||
| { | ||
| name: 'X25519', | ||
| public: (aliceKeyPair as CryptoKeyPair).publicKey, | ||
| }, | ||
| (bobKeyPair as CryptoKeyPair).privateKey, | ||
| { name: 'AES-GCM', length: 256 }, | ||
| true, | ||
| ['encrypt', 'decrypt'], | ||
| ); | ||
|
|
||
| // Both should derive the same key | ||
| const aliceRaw = await subtle.exportKey('raw', aliceDerivedKey as CryptoKey); | ||
| const bobRaw = await subtle.exportKey('raw', bobDerivedKey as CryptoKey); | ||
|
|
||
| expect(Buffer.from(aliceRaw as ArrayBuffer).toString('hex')).to.equal( | ||
| Buffer.from(bobRaw as ArrayBuffer).toString('hex'), | ||
| ); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.