Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions sdk/mobile/INTEGRATION_GUIDE.md
Original file line number Diff line number Diff line change
@@ -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.
7 changes: 7 additions & 0 deletions sdk/mobile/README.md
Original file line number Diff line number Diff line change
@@ -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
29 changes: 29 additions & 0 deletions sdk/mobile/common/contract_interface.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Mobile-Optimized Contract Interface (Dart)

abstract class PropChainMobileSDK {
Future<PropertyInfo> getPropertyInfo(String propertyId);
Future<TransactionResult> transferProperty(String propertyId, String to);
Future<String> signTransactionOffline(Map<String, dynamic> txData);
Future<String> scanQRCode();
void subscribeToPropertyUpdates(String propertyId, void Function(dynamic update) callback);
Future<bool> 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]);
}
26 changes: 26 additions & 0 deletions sdk/mobile/common/contract_interface.ts
Original file line number Diff line number Diff line change
@@ -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<PropertyInfo>;
transferProperty(propertyId: string, to: string): Promise<TransactionResult>;
signTransactionOffline(txData: object): Promise<string>; // Returns signed tx
scanQRCode(): Promise<string>; // Returns scanned data
subscribeToPropertyUpdates(propertyId: string, callback: (update: any) => void): void;
authenticateBiometric(): Promise<boolean>;
onError(callback: (error: string) => void): void;
}
6 changes: 6 additions & 0 deletions sdk/mobile/flutter/biometric.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Biometric authentication for Flutter (Dart)
// This is a stub. In a real app, use a package like 'local_auth'.
Future<bool> authenticateBiometric() async {
// Implementation would invoke biometric authentication
throw UnimplementedError('Biometric authentication not implemented. Use a package like local_auth.');
}
6 changes: 6 additions & 0 deletions sdk/mobile/flutter/error_handling.dart
Original file line number Diff line number Diff line change
@@ -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.');
}
6 changes: 6 additions & 0 deletions sdk/mobile/flutter/push_notifications.dart
Original file line number Diff line number Diff line change
@@ -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.');
}
6 changes: 6 additions & 0 deletions sdk/mobile/flutter/qr_scanner.dart
Original file line number Diff line number Diff line change
@@ -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<String> scanQRCode() async {
// Implementation would invoke camera and scan QR code
throw UnimplementedError('QR code scanning not implemented. Use a package like qr_code_scanner.');
}
12 changes: 12 additions & 0 deletions sdk/mobile/flutter/sample_app/README.md
Original file line number Diff line number Diff line change
@@ -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 `../`.
15 changes: 15 additions & 0 deletions sdk/mobile/flutter/signing.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Offline transaction signing utility for Flutter (Dart)
import 'package:web3dart/web3dart.dart';

Future<String> signTransactionOffline(Map<String, dynamic> 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);
}
6 changes: 6 additions & 0 deletions sdk/mobile/react-native/biometric.ts
Original file line number Diff line number Diff line change
@@ -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<boolean> {
// Implementation would invoke biometric authentication
throw new Error('Biometric authentication not implemented. Use a library like react-native-biometrics.');
}
6 changes: 6 additions & 0 deletions sdk/mobile/react-native/error_handling.ts
Original file line number Diff line number Diff line change
@@ -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.');
}
6 changes: 6 additions & 0 deletions sdk/mobile/react-native/push_notifications.ts
Original file line number Diff line number Diff line change
@@ -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.');
}
6 changes: 6 additions & 0 deletions sdk/mobile/react-native/qr_scanner.ts
Original file line number Diff line number Diff line change
@@ -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<string> {
// Implementation would invoke camera and scan QR code
throw new Error('QR code scanning not implemented. Use a library like expo-barcode-scanner.');
}
12 changes: 12 additions & 0 deletions sdk/mobile/react-native/sample-app/README.md
Original file line number Diff line number Diff line change
@@ -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 `../`.
8 changes: 8 additions & 0 deletions sdk/mobile/react-native/signing.ts
Original file line number Diff line number Diff line change
@@ -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<string> {
const wallet = new ethers.Wallet(privateKey);
const tx = await wallet.signTransaction(txData);
return tx;
}
Loading