mattrglobal / pairing_crypto

A library for pairing based cryptography
Apache License 2.0
14 stars 7 forks source link

feat: react-native wrapper #96

Closed zhenwenc closed 1 year ago

zhenwenc commented 2 years ago

Description

The primary purpose of this PR was to implement a React Native wrapper for the pairing crypto library and to be published as an NPM package. But it also slightly modified the build scripts for the Obj-c and Java wrappers to accommodate the bundling requirements.

Development

The wrappers/react-native package comes with a set of independent build scripts, which will manage to build the dependant native libraries (eg: C, Obj-c, Java, and Rust wrappers) automatically.

To build all the libraries:

yarn build:all 

which essentially executes the following scripts:

~/code/pairing_crypto/wrappers/react-native fc/react-native ⇡ 31s ❯ tree ios/lib
ios/lib
├── PairingCryptoError.h
├── PairingCryptoError.m
├── bbs_bls12381_sha256_key_pair.h
├── bbs_bls12381_sha256_key_pair.m
├── bbs_bls12381_sha256_proof.h
├── bbs_bls12381_sha256_proof.m
├── bbs_bls12381_sha256_signature.h
├── bbs_bls12381_sha256_signature.m
├── bbs_bls12381_shake256_key_pair.h
├── bbs_bls12381_shake256_key_pair.m
├── bbs_bls12381_shake256_proof.h
├── bbs_bls12381_shake256_proof.m
├── bbs_bls12381_shake256_signature.h
├── bbs_bls12381_shake256_signature.m
├── bbs_key_pair.h
├── bbs_key_pair.m
├── bbs_proof.h
├── bbs_proof.m
├── bbs_signature.h
├── bbs_signature.m
├── libpairing_crypto_c.a
├── pairing_crypto_bbs.h
└── pairing_crypto_common.h

0 directories, 23 files

~/code/pairing_crypto/wrappers/react-native fc/react-native ❯ tree android/lib
android/lib
├── PairingCrypto.jar
└── native
    ├── arm64-v8a
    │   └── libpairing_crypto_jni.so
    ├── armeabi-v7a
    │   └── libpairing_crypto_jni.so
    ├── x86
    │   └── libpairing_crypto_jni.so
    └── x86_64
        └── libpairing_crypto_jni.so

5 directories, 5 files

E2E Tests

The package also comes with an example React Native App that integrates all the library functions in a simple UI:

To run Detox tests:

yarn detox:build       # build both iOS and Android apps
yarn detox:ios         # run iOS tests
yarn detox:android     # run Android tests

Usage

The React Native wrapper will be published as a standalone NPM package that is also bundled with the native library dependencies. And the package also enables RN auto-linking, that being said, it doesn't require any special setup on the consumers of this package (such as Mobile Wallet).

yarn add @mattrglobal/pairing-crypto-rn

# For iOS, the podspec will be detected and installed automatically
cd ios && pod install

# For Android, it will just work magically :)
echo "Magic!"

Others

NPM Package: https://www.npmjs.com/package/@mattrglobal/pairing-crypto-rn