Skip to content

feat: [SIW-3727] Implement soft-crypto utilities for hashing and randomBytes generation#49

Open
ale-mazz wants to merge 22 commits intoupdate-rn-78-3from
SIW-3727
Open

feat: [SIW-3727] Implement soft-crypto utilities for hashing and randomBytes generation#49
ale-mazz wants to merge 22 commits intoupdate-rn-78-3from
SIW-3727

Conversation

@ale-mazz
Copy link
Copy Markdown
Contributor

@ale-mazz ale-mazz commented Feb 19, 2026

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

  • Android — new SoftCryptoUtils.kt with pure-JCA + BouncyCastle logic; IoReactNativeCryptoModule.kt
    exposes it via thin @ReactMethod wrappers (randomBytes, hashString, hashBytes, verifyES256)
  • iOS — new SoftCryptoUtils.swift using CryptoKit and Security framework; IoReactNativeCrypto.swift
    exposes it via @objc methods registered in IoReactNativeCrypto.m (randomBytes, hashString,
    hashBytes, verifyES256)
  • Bridgesrc/index.tsx exports:
    • generateRandomBytes(size): Promise<Uint8Array> — CSPRNG via SecureRandom (Android) /
      SecRandomCopyBytes (iOS)
    • generateRandomHex(size): Promise<string> — CSPRNG as a lowercase hex string
    • generateRandomString(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 Hasher type from @sd-jwt/types
    • verifyES256(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 a Verifier function directly assignable to the Verifier
      type from @sd-jwt/types
  • Example app — added Random Bytes and Hash sections to exercise the new functions

How to test

Run the example app on both platforms (yarn android / yarn ios after pod install).

Random Bytes section:

  1. generateRandomBytes(32) — tap and verify a 64-character lowercase hex string is displayed; tap
    again and verify it differs (non-deterministic)
  2. generateRandomHex(32) — same as above; output is a raw hex string
  3. generateRandomString(32) — tap and verify a 32-character alphanumeric string (a–z, 0–9) is
    displayed

Hash section:

  1. digest (string) — tap and verify the hex digest of "Hello, world!" matches the known SHA-256
    value (315f5bdb...)
  2. digest (ArrayBuffer) — tap and verify the same digest is displayed
  3. Both match? — tap and verify the log shows ✓ YES

Repeat on both platforms to confirm consistent output across Android and iOS.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Feb 19, 2026

Jira Pull Request Link

This Pull Request refers to Jira issues:

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

Comment thread src/index.tsx Outdated
Comment thread ios/IoReactNativeCrypto.swift Outdated
Comment thread ios/IoReactNativeCrypto.swift Outdated
Comment thread android/src/main/java/com/pagopa/ioreactnativecrypto/SoftCryptoUtils.kt Outdated
Comment thread android/src/main/java/com/pagopa/ioreactnativecrypto/IoReactNativeCryptoModule.kt Outdated
Comment thread example/src/App.tsx
Comment thread src/index.tsx Outdated
Comment thread ios/SoftCryptoUtils.swift Outdated
Comment thread android/src/main/java/com/pagopa/ioreactnativecrypto/SoftCryptoUtils.kt Outdated
Comment thread android/src/main/java/com/pagopa/ioreactnativecrypto/IoReactNativeCryptoModule.kt Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

Comment thread ios/IoReactNativeCrypto.swift Outdated
Comment thread android/src/main/java/com/pagopa/ioreactnativecrypto/SoftCryptoUtils.kt Outdated
Comment thread ios/SoftCryptoUtils.swift
Comment thread android/src/main/java/com/pagopa/ioreactnativecrypto/SoftCryptoUtils.kt Outdated
Comment thread ios/SoftCryptoUtils.swift
Comment thread ios/IoReactNativeCrypto.swift Outdated
Comment thread src/index.tsx Outdated
Comment thread android/src/main/java/com/pagopa/ioreactnativecrypto/SoftCryptoUtils.kt Outdated
Comment thread src/index.tsx
Comment thread ios/IoReactNativeCrypto.swift
@ale-mazz ale-mazz requested a review from Copilot February 19, 2026 16:46
@ale-mazz ale-mazz changed the title feat: [SIW-3727] Implement soft-crypto utilities for ephemeral key operations feat: [SIW-3727] Implement soft-crypto utilities for hashing and randomBytes generation Feb 19, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

Comment thread package.json
Comment thread example/src/App.tsx
Comment thread ios/IoReactNativeCrypto.swift Outdated
Comment thread src/index.tsx Outdated
Comment thread ios/SoftCryptoUtils.swift
Comment thread android/src/main/java/com/pagopa/ioreactnativecrypto/SoftCryptoUtils.kt Outdated
@ale-mazz ale-mazz marked this pull request as ready for review February 19, 2026 17:03
@ale-mazz ale-mazz requested a review from a team as a code owner February 19, 2026 17:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants