feat: [SIW-3727] Implement soft-crypto utilities for hashing and randomBytes generation#49
feat: [SIW-3727] Implement soft-crypto utilities for hashing and randomBytes generation#49ale-mazz wants to merge 22 commits intoupdate-rn-78-3from
Conversation
Jira Pull Request LinkThis Pull Request refers to Jira issues: |
There was a problem hiding this comment.
Pull request overview
This PR adds cross-platform “soft crypto” primitives (salt generation, hashing, ephemeral ECDSA keypairs, sign/verify) implemented natively on Android (JCA/BC) and iOS (CryptoKit), exposes them through the React Native bridge, and provides high-level ES256/ES384/ES512 helpers plus example app UI updates.
Changes:
- Added native soft-crypto implementations and React Native bridge methods for salt/hash/ephemeral ECDSA operations.
- Added JS/TS bridge exports and ES256/ES384/ES512 helper APIs mirroring a WebCrypto-like shape.
- Refactored the example app UI to include a “Soft Crypto” section and improved styling/layout.
Reviewed changes
Copilot reviewed 9 out of 10 changed files in this pull request and generated 11 comments.
Show a summary per file
| File | Description |
|---|---|
| src/index.tsx | Exposes new soft-crypto primitives and ES256/ES384/ES512 helpers via the JS API. |
| ios/SoftCryptoUtils.swift | Implements salt/hash and ephemeral ECDSA key ops using CryptoKit. |
| ios/IoReactNativeCrypto.swift | Bridges soft-crypto utilities to React Native promises and adds new iOS error codes. |
| ios/IoReactNativeCrypto.m | Registers the new iOS bridge methods with React Native. |
| ios/IoReactNativeCrypto.xcodeproj/project.pbxproj | Adds SoftCryptoUtils.swift to the iOS build. |
| android/.../SoftCryptoUtils.kt | Implements salt/hash and ephemeral ECDSA key ops using JCA + BC ASN.1 conversion. |
| android/.../IoReactNativeCryptoModule.kt | Exposes soft-crypto methods through @ReactMethod bridge wrappers and adds new Android error codes. |
| example/src/App.tsx | Reorganizes UI into sections and adds soft-crypto demo actions. |
| example/ios/Podfile.lock | Updates lockfile checksum after iOS changes. |
| example/ios/.../project.pbxproj | Updates Xcode project configuration (notably test target-related entries). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…andom byte generation
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 10 changed files in this pull request and generated 11 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…oUtils.kt Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…oUtils.kt Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 16 out of 18 changed files in this pull request and generated 7 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…oUtils.kt Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Warning
Depends on #48
Short description
Adds native soft-crypto primitives to the React Native bridge — CSPRNG, hashing, and ES256 signature
verification — as drop-in replacements for their
node:crypto/Math.random()List of changes proposed in this pull request
SoftCryptoUtils.ktwith pure-JCA + BouncyCastle logic;IoReactNativeCryptoModule.ktexposes it via thin
@ReactMethodwrappers (randomBytes,hashString,hashBytes,verifyES256)SoftCryptoUtils.swiftusing CryptoKit and Security framework;IoReactNativeCrypto.swiftexposes it via
@objcmethods registered inIoReactNativeCrypto.m(randomBytes,hashString,hashBytes,verifyES256)src/index.tsxexports:generateRandomBytes(size): Promise<Uint8Array>— CSPRNG viaSecureRandom(Android) /SecRandomCopyBytes(iOS)generateRandomHex(size): Promise<string>— CSPRNG as a lowercase hex stringgenerateRandomString(size): Promise<string>— CSPRNG as an alphanumeric string (a–z, 0–9)digest(data: string | ArrayBuffer, algorithm?: SupportedHashAlgorithm): Promise<Uint8Array>—SHA-256/384/512; directly assignable to the
Hashertype from@sd-jwt/typesverifyES256(data, signatureBase64url, publicKeyJwk): Promise<boolean>— ECDSA P-256/SHA-256 verifier;accepts IEEE P1363 signatures (R‖S) via CryptoKit (iOS) and BouncyCastle
SHA256withPLAIN-ECDSA(Android)ES256.getVerifier(publicKeyJwk)— returns aVerifierfunction directly assignable to theVerifiertype from
@sd-jwt/typesHow to test
Run the example app on both platforms (
yarn android/yarn iosafterpod install).Random Bytes section:
generateRandomBytes(32)— tap and verify a 64-character lowercase hex string is displayed; tapagain and verify it differs (non-deterministic)
generateRandomHex(32)— same as above; output is a raw hex stringgenerateRandomString(32)— tap and verify a 32-character alphanumeric string (a–z, 0–9) isdisplayed
Hash section:
digest (string)— tap and verify the hex digest of"Hello, world!"matches the known SHA-256value (
315f5bdb...)digest (ArrayBuffer)— tap and verify the same digest is displayedBoth match?— tap and verify the log shows✓ YESRepeat on both platforms to confirm consistent output across Android and iOS.