Skip to content

feat: add biometric key generation and signing - #32

Open
LonelyCpp wants to merge 3 commits into
masterfrom
feat/key-generation
Open

LonelyCpp wants to merge 3 commits into
masterfrom
feat/key-generation

Conversation

@LonelyCpp

@LonelyCpp LonelyCpp commented Sep 20, 2026

Copy link
Copy Markdown
Member

Summary

Adds on-device biometric key generation and signing to the library. The private key is generated in secure hardware (iOS Secure Enclave / Android Keystore) and can only be used after the user passes biometric authentication.

New API

createKeys(options?: { keyName?: string }): Promise<BiometricKey>      // rejects if key already exists
biometricKeysExist(options?: { keyName?: string }): Promise<boolean>
deleteKeys(options?: { keyName?: string }): Promise<boolean>            // true if deleted, false if none
createSignature(payload: string, options?: { keyName?: string; promptMessage?: string }): Promise<Signature>
  • BiometricKey = { keyName, publicKey (base64), algorithm }
  • Signature = { keyName, publicKey, signature (base64) }

Design notes

  • RSA-2048, SHA-256 hashed payload (UTF-8 string).
  • Named keys (keyName, default "default") so multiple keys can coexist — the main future-proofing decision.
  • Objects returned, not primitives, so fields (algorithm, publicKey) can be added later without breaking changes.
  • Options objects (not positional args) for non-breaking extension.
  • Resolve/reject semantics consistent with requestBioAuth.

Changes

  • src/NativeSimpleBiometrics.ts: extend TurboModule spec (codegen propagates to both platforms).
  • src/index.tsx: JS wrappers with defaults + payload validation.
  • android/.../SimpleBiometricsModule.kt: KeyStore + KeyGenParameterSpec; BiometricPrompt.CryptoObject for signing.
  • ios/SimpleBiometrics.mm: SecKeyCreateRandomKey, SecItemCopyMatching/SecItemDelete, SecKeyCreateSignature.
  • SimpleBiometrics.podspec: link Security framework.
  • README + example app demo + unit tests.

Tests

  • yarn typecheck, yarn lint, yarn test (7 passing) — all green.
  • Codegen output verified against @react-native/codegen to confirm the generated native spec matches the Kotlin/ObjC implementations.

See docs/key-generation.md for the full implementation plan.

closes #14

Add createKeys, biometricKeysExist, deleteKeys and createSignature
methods to generate a biometric-protected RSA key pair in secure
hardware (iOS Secure Enclave / Android Keystore) and sign payloads
with it.

- extend the TurboModule spec and JS wrapper
- implement key generation/signing on Android and iOS
- link the Security framework in the podspec
- document the new API and demo it in the example app
- bump react-native, react and @react-native/* packages to 0.86.2
- upgrade @react-native-community/cli to 20.1.0 and builder-bob to 0.43
- update gradle wrapper to 9.3.1 and raise network timeout
- add nkf to Gemfile and refresh Podfile/pod lockfile
- switch jest preset to @react-native/jest-preset
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.

[Request] Key Generation Feature

1 participant