@arquebus-io/libauth-react-native
v1.0.0
Published
React Native wrapper for libauth with full CashTokens support
Maintainers
Readme
libauth-react-native
React Native wrapper for libauth with full CashTokens support.
Uses Polygen to compile WebAssembly to native code for iOS and Android.
Installation
npm install @yourorg/libauth-react-native
# or
yarn add @yourorg/libauth-react-nativeiOS
cd ios && pod installAndroid
No additional steps - Gradle handles it automatically.
Usage
Use exactly like the original libauth:
import {
generatePrivateKey,
derivePublicKeyUncompressed,
encodeCashAddress
} from '@yourorg/libauth-react-native';
// Generate wallet
const privateKey = generatePrivateKey();
const publicKey = derivePublicKeyUncompressed(privateKey);
const address = encodeCashAddress('bitcoincash', {
type: 'p2pkh',
payload: publicKey,
});
console.log('Address:', address);CashTokens Support
Full support for CashTokens operations:
import {
encodeTokenPrefix,
decodeTokenPrefix,
encodeFungibleTokenAmount
} from '@yourorg/libauth-react-native';
// Create a token-aware transaction
const tokenPrefix = encodeTokenPrefix({
category: categoryId,
nft: {
capability: 'minting',
commitment: commitmentData
}
});Advanced Features
All libauth features are available:
- Wallet Operations: Key generation, HD wallets, address encoding/decoding
- Transaction Building: Complete transaction construction and signing
- Script Evaluation: Full Bitcoin Script VM implementation
- CashTokens: Complete fungible and NFT token support
- Authentication Templates: Bitauth IDE template support
- Crypto Operations: SHA256, RIPEMD160, Secp256k1, and more
Performance
- WASM crypto operations run at native speed
- ~50x faster than pure JS implementations
- No overhead - Polygen compiles WASM ahead of time
API Documentation
This library re-exports all functions from @bitauth/libauth. For complete API documentation, see:
Example App
See the example/ directory for a complete React Native app demonstrating:
- Wallet generation
- Address derivation
- Transaction building
- CashTokens operations
Requirements
- React Native >= 0.60
- iOS >= 12.0
- Android minSdkVersion >= 21
Development
Building from Source
# Install dependencies
npm install
# Build TypeScript
npm run build
# Run tests
npm test
# Link for development
npm linkGenerating Native Code (Optional)
For maximum performance, you can compile the WASM modules to native C code:
Install WABT (WebAssembly Binary Toolkit)
Set the WABT_PATH environment variable:
export WABT_PATH=/path/to/wabt/binGenerate native code:
npm run generate-native
This generates C source files from libauth's WASM modules (secp256k1, sha256, ripemd160, etc.) which are then compiled to native code when building the iOS/Android apps.
Project Structure
libauth-react-native/
├── src/ # TypeScript source
├── lib/ # Compiled JavaScript
├── ios/ # iOS native module
│ └── Polygen/ # WASM compiled frameworks
├── android/ # Android native module
│ └── libs/ # WASM compiled libraries
└── example/ # Example React Native appTroubleshooting
iOS Build Issues
If you encounter build errors on iOS:
cd ios
pod deintegrate
pod installAndroid Build Issues
Clear the build cache:
cd android
./gradlew clean
cd ..
npx react-native run-androidContributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
MIT
