From 6bcd2d77c26fe7a7f00a093e0c914831c8357fc5 Mon Sep 17 00:00:00 2001 From: Abbakar Garba Date: Wed, 25 Feb 2026 06:19:05 +0100 Subject: [PATCH] Implement Mobile SDK for dApp Integration --- sdk/mobile/INTEGRATION_GUIDE.md | 41 +++++++++++++++++++ sdk/mobile/README.md | 7 ++++ sdk/mobile/common/contract_interface.dart | 29 +++++++++++++ sdk/mobile/common/contract_interface.ts | 26 ++++++++++++ sdk/mobile/flutter/biometric.dart | 6 +++ sdk/mobile/flutter/error_handling.dart | 6 +++ sdk/mobile/flutter/push_notifications.dart | 6 +++ sdk/mobile/flutter/qr_scanner.dart | 6 +++ sdk/mobile/flutter/sample_app/README.md | 12 ++++++ sdk/mobile/flutter/signing.dart | 15 +++++++ sdk/mobile/react-native/biometric.ts | 6 +++ sdk/mobile/react-native/error_handling.ts | 6 +++ sdk/mobile/react-native/push_notifications.ts | 6 +++ sdk/mobile/react-native/qr_scanner.ts | 6 +++ sdk/mobile/react-native/sample-app/README.md | 12 ++++++ sdk/mobile/react-native/signing.ts | 8 ++++ 16 files changed, 198 insertions(+) create mode 100644 sdk/mobile/INTEGRATION_GUIDE.md create mode 100644 sdk/mobile/README.md create mode 100644 sdk/mobile/common/contract_interface.dart create mode 100644 sdk/mobile/common/contract_interface.ts create mode 100644 sdk/mobile/flutter/biometric.dart create mode 100644 sdk/mobile/flutter/error_handling.dart create mode 100644 sdk/mobile/flutter/push_notifications.dart create mode 100644 sdk/mobile/flutter/qr_scanner.dart create mode 100644 sdk/mobile/flutter/sample_app/README.md create mode 100644 sdk/mobile/flutter/signing.dart create mode 100644 sdk/mobile/react-native/biometric.ts create mode 100644 sdk/mobile/react-native/error_handling.ts create mode 100644 sdk/mobile/react-native/push_notifications.ts create mode 100644 sdk/mobile/react-native/qr_scanner.ts create mode 100644 sdk/mobile/react-native/sample-app/README.md create mode 100644 sdk/mobile/react-native/signing.ts diff --git a/sdk/mobile/INTEGRATION_GUIDE.md b/sdk/mobile/INTEGRATION_GUIDE.md new file mode 100644 index 0000000..aae6c45 --- /dev/null +++ b/sdk/mobile/INTEGRATION_GUIDE.md @@ -0,0 +1,41 @@ +# PropChain Mobile SDK Integration Guide + +This documentation provides guidance for integrating the PropChain Mobile SDK into React Native and Flutter applications. + +## Features +- Mobile-optimized contract interface +- Offline transaction signing +- QR code scanning for property info +- Push notification system +- Biometric authentication +- Mobile-specific error handling + +## Directory Structure +- `sdk/mobile/common/` — Shared interfaces and logic +- `sdk/mobile/react-native/` — React Native SDK implementation +- `sdk/mobile/flutter/` — Flutter SDK implementation + +## Integration Steps + +### React Native +1. Install dependencies: `ethers`, `expo-barcode-scanner`, `expo-local-authentication`, `@react-native-firebase/messaging`, etc. +2. Import SDK modules from `sdk/mobile/react-native/`. +3. Use the provided interfaces and utilities to interact with PropChain contracts. + +### Flutter +1. Add dependencies: `web3dart`, `qr_code_scanner`, `local_auth`, `firebase_messaging`, etc. +2. Import SDK modules from `sdk/mobile/flutter/`. +3. Use the provided interfaces and utilities to interact with PropChain contracts. + +## Sample Apps +See `sdk/mobile/react-native/sample-app/` and `sdk/mobile/flutter/sample_app/` for starter templates. + +## Error Handling & Recovery +- Use the provided error handling hooks to catch and recover from mobile-specific issues. + +## Security +- Always store private keys securely (use OS keychain/secure storage). +- Use biometric authentication for sensitive actions. + +## Support +For questions or issues, see the main project README or contact the maintainers. diff --git a/sdk/mobile/README.md b/sdk/mobile/README.md new file mode 100644 index 0000000..0fca34a --- /dev/null +++ b/sdk/mobile/README.md @@ -0,0 +1,7 @@ +# PropChain Mobile SDK + +This directory contains the mobile SDK for integrating PropChain contracts into mobile applications. + +- `react-native/`: SDK implementation and sample app for React Native +- `flutter/`: SDK implementation and sample app for Flutter +- `common/`: Shared logic, documentation, and utilities diff --git a/sdk/mobile/common/contract_interface.dart b/sdk/mobile/common/contract_interface.dart new file mode 100644 index 0000000..dade29b --- /dev/null +++ b/sdk/mobile/common/contract_interface.dart @@ -0,0 +1,29 @@ +# Mobile-Optimized Contract Interface (Dart) + +abstract class PropChainMobileSDK { + Future getPropertyInfo(String propertyId); + Future transferProperty(String propertyId, String to); + Future signTransactionOffline(Map txData); + Future scanQRCode(); + void subscribeToPropertyUpdates(String propertyId, void Function(dynamic update) callback); + Future authenticateBiometric(); + void onError(void Function(String error) callback); +} + +class PropertyInfo { + final String id; + final String owner; + final String location; + final double valuation; + final String metadataUri; + + PropertyInfo(this.id, this.owner, this.location, this.valuation, this.metadataUri); +} + +class TransactionResult { + final String txHash; + final String status; // 'pending', 'confirmed', 'failed' + final String? error; + + TransactionResult(this.txHash, this.status, [this.error]); +} diff --git a/sdk/mobile/common/contract_interface.ts b/sdk/mobile/common/contract_interface.ts new file mode 100644 index 0000000..66d70ba --- /dev/null +++ b/sdk/mobile/common/contract_interface.ts @@ -0,0 +1,26 @@ +// Mobile-Optimized Contract Interface (TypeScript) +// This file defines the main interface for interacting with PropChain contracts from mobile apps. + +export interface PropertyInfo { + id: string; + owner: string; + location: string; + valuation: number; + metadataUri: string; +} + +export interface TransactionResult { + txHash: string; + status: 'pending' | 'confirmed' | 'failed'; + error?: string; +} + +export interface PropChainMobileSDK { + getPropertyInfo(propertyId: string): Promise; + transferProperty(propertyId: string, to: string): Promise; + signTransactionOffline(txData: object): Promise; // Returns signed tx + scanQRCode(): Promise; // Returns scanned data + subscribeToPropertyUpdates(propertyId: string, callback: (update: any) => void): void; + authenticateBiometric(): Promise; + onError(callback: (error: string) => void): void; +} diff --git a/sdk/mobile/flutter/biometric.dart b/sdk/mobile/flutter/biometric.dart new file mode 100644 index 0000000..b993b7e --- /dev/null +++ b/sdk/mobile/flutter/biometric.dart @@ -0,0 +1,6 @@ +// Biometric authentication for Flutter (Dart) +// This is a stub. In a real app, use a package like 'local_auth'. +Future authenticateBiometric() async { + // Implementation would invoke biometric authentication + throw UnimplementedError('Biometric authentication not implemented. Use a package like local_auth.'); +} diff --git a/sdk/mobile/flutter/error_handling.dart b/sdk/mobile/flutter/error_handling.dart new file mode 100644 index 0000000..55e1bc1 --- /dev/null +++ b/sdk/mobile/flutter/error_handling.dart @@ -0,0 +1,6 @@ +// Mobile-specific error handling for Flutter (Dart) +void onError(void Function(String error) callback) { + // Implementation would set up global error handler + // Example: FlutterError.onError = (FlutterErrorDetails details) { callback(details.exceptionAsString()); }; + throw UnimplementedError('Error handling not implemented. Use FlutterError.onError.'); +} diff --git a/sdk/mobile/flutter/push_notifications.dart b/sdk/mobile/flutter/push_notifications.dart new file mode 100644 index 0000000..ce90514 --- /dev/null +++ b/sdk/mobile/flutter/push_notifications.dart @@ -0,0 +1,6 @@ +// Push notification system for Flutter (Dart) +// This is a stub. In a real app, use a package like firebase_messaging. +void subscribeToPropertyUpdates(String propertyId, void Function(dynamic update) callback) { + // Implementation would use push notification service + throw UnimplementedError('Push notification not implemented. Use a package like firebase_messaging.'); +} diff --git a/sdk/mobile/flutter/qr_scanner.dart b/sdk/mobile/flutter/qr_scanner.dart new file mode 100644 index 0000000..8fefc30 --- /dev/null +++ b/sdk/mobile/flutter/qr_scanner.dart @@ -0,0 +1,6 @@ +// QR code scanning utility for Flutter (Dart) +// This is a stub. In a real app, use a package like 'qr_code_scanner' or 'mobile_scanner'. +Future scanQRCode() async { + // Implementation would invoke camera and scan QR code + throw UnimplementedError('QR code scanning not implemented. Use a package like qr_code_scanner.'); +} diff --git a/sdk/mobile/flutter/sample_app/README.md b/sdk/mobile/flutter/sample_app/README.md new file mode 100644 index 0000000..ec25928 --- /dev/null +++ b/sdk/mobile/flutter/sample_app/README.md @@ -0,0 +1,12 @@ +# Sample Flutter App for PropChain Mobile SDK + +This is a placeholder for a sample Flutter app demonstrating integration with the PropChain Mobile SDK. + +## Features +- Connect to PropChain contracts +- Scan property QR codes +- Sign transactions offline +- Receive property update notifications +- Biometric authentication + +> To implement: Use Flutter CLI, and integrate the SDK modules from `../`. diff --git a/sdk/mobile/flutter/signing.dart b/sdk/mobile/flutter/signing.dart new file mode 100644 index 0000000..b09f3a1 --- /dev/null +++ b/sdk/mobile/flutter/signing.dart @@ -0,0 +1,15 @@ +// Offline transaction signing utility for Flutter (Dart) +import 'package:web3dart/web3dart.dart'; + +Future signTransactionOffline(Map txData, String privateKey) async { + final credentials = EthPrivateKey.fromHex(privateKey); + final tx = Transaction( + to: EthereumAddress.fromHex(txData['to']), + value: EtherAmount.inWei(BigInt.parse(txData['value'])), + data: txData['data'] != null ? hexToBytes(txData['data']) : null, + gasPrice: txData['gasPrice'] != null ? EtherAmount.inWei(BigInt.parse(txData['gasPrice'])) : null, + maxGas: txData['gasLimit'], + ); + final signed = await credentials.signTransaction(tx); + return bytesToHex(signed, include0x: true); +} diff --git a/sdk/mobile/react-native/biometric.ts b/sdk/mobile/react-native/biometric.ts new file mode 100644 index 0000000..ead9e56 --- /dev/null +++ b/sdk/mobile/react-native/biometric.ts @@ -0,0 +1,6 @@ +// Biometric authentication for React Native (TypeScript) +// This is a stub. In a real app, use a library like 'react-native-biometrics' or 'expo-local-authentication'. +export async function authenticateBiometric(): Promise { + // Implementation would invoke biometric authentication + throw new Error('Biometric authentication not implemented. Use a library like react-native-biometrics.'); +} diff --git a/sdk/mobile/react-native/error_handling.ts b/sdk/mobile/react-native/error_handling.ts new file mode 100644 index 0000000..3fd1b3b --- /dev/null +++ b/sdk/mobile/react-native/error_handling.ts @@ -0,0 +1,6 @@ +// Mobile-specific error handling for React Native (TypeScript) +export function onError(callback: (error: string) => void): void { + // Implementation would set up global error handler + // Example: ErrorUtils.setGlobalHandler(callback); + throw new Error('Error handling not implemented. Use a global error handler.'); +} diff --git a/sdk/mobile/react-native/push_notifications.ts b/sdk/mobile/react-native/push_notifications.ts new file mode 100644 index 0000000..b62a306 --- /dev/null +++ b/sdk/mobile/react-native/push_notifications.ts @@ -0,0 +1,6 @@ +// Push notification system for React Native (TypeScript) +// This is a stub. In a real app, use a service like Firebase Cloud Messaging (FCM). +export function subscribeToPropertyUpdates(propertyId: string, callback: (update: any) => void): void { + // Implementation would use push notification service + throw new Error('Push notification not implemented. Use a service like FCM.'); +} diff --git a/sdk/mobile/react-native/qr_scanner.ts b/sdk/mobile/react-native/qr_scanner.ts new file mode 100644 index 0000000..0742ec5 --- /dev/null +++ b/sdk/mobile/react-native/qr_scanner.ts @@ -0,0 +1,6 @@ +// QR code scanning utility for React Native (TypeScript) +// This is a stub. In a real app, use a library like 'react-native-camera' or 'expo-barcode-scanner'. +export async function scanQRCode(): Promise { + // Implementation would invoke camera and scan QR code + throw new Error('QR code scanning not implemented. Use a library like expo-barcode-scanner.'); +} diff --git a/sdk/mobile/react-native/sample-app/README.md b/sdk/mobile/react-native/sample-app/README.md new file mode 100644 index 0000000..62a96a1 --- /dev/null +++ b/sdk/mobile/react-native/sample-app/README.md @@ -0,0 +1,12 @@ +# Sample React Native App for PropChain Mobile SDK + +This is a placeholder for a sample React Native app demonstrating integration with the PropChain Mobile SDK. + +## Features +- Connect to PropChain contracts +- Scan property QR codes +- Sign transactions offline +- Receive property update notifications +- Biometric authentication + +> To implement: Use Expo or React Native CLI, and integrate the SDK modules from `../`. diff --git a/sdk/mobile/react-native/signing.ts b/sdk/mobile/react-native/signing.ts new file mode 100644 index 0000000..884875f --- /dev/null +++ b/sdk/mobile/react-native/signing.ts @@ -0,0 +1,8 @@ +// Offline transaction signing utility for React Native (TypeScript) +import { ethers } from 'ethers'; + +export async function signTransactionOffline(txData: object, privateKey: string): Promise { + const wallet = new ethers.Wallet(privateKey); + const tx = await wallet.signTransaction(txData); + return tx; +}