Skip to content

Commit

Permalink
Committing local changes before pull
Browse files Browse the repository at this point in the history
  • Loading branch information
sarthak13gupta committed Jun 20, 2023
1 parent 987bc46 commit 4b69103
Show file tree
Hide file tree
Showing 18 changed files with 856 additions and 29 deletions.
4 changes: 3 additions & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,11 @@ dependencies {
implementation 'com.google.code.gson:gson:2.10.1'
implementation 'com.theartofdev.edmodo:android-image-cropper:2.8.0'

implementation platform('com.google.firebase:firebase-bom:29.3.1')
implementation platform('com.google.firebase:firebase-bom:31.5.0')
implementation 'com.google.firebase:firebase-messaging'

implementation 'com.google.firebase:firebase-analytics-ktx'

implementation 'info.guardianproject:tor-android:0.4.7.8'
implementation 'info.guardianproject:jtorctl:0.4.5.7'
}
Expand Down
6 changes: 4 additions & 2 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {

dependencies {
classpath 'com.android.tools.build:gradle:7.1.3'
classpath 'com.google.gms:google-services:4.3.14'
classpath 'com.google.gms:google-services:4.3.15'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.20"
}
}
Expand All @@ -15,7 +15,9 @@ allprojects {
repositories {
google()
mavenCentral()
maven { url "https://raw.githubusercontent.com/guardianproject/gpmaven/master" }
maven { url "https://raw.githubusercontent.com/guardianproject/gpmaven/master"
url 'https://storage.googleapis.com/download.flutter.io'
}
flatDir {
dirs 'libs'
}
Expand Down
18 changes: 0 additions & 18 deletions ios/Flutter/Flutter.podspec

This file was deleted.

14 changes: 13 additions & 1 deletion lib/bloc/marketplace/marketplace_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,25 @@ class MarketplaceBloc {
final _vendorController = BehaviorSubject<List<VendorModel>>();
Stream<List<VendorModel>> get vendorsStream => _vendorController.stream;

bool isVendorToggle = true;

MarketplaceBloc() {
loadVendors();
}

Future loadVendors() async {
String jsonVendors = await rootBundle.loadString('src/json/vendors.json');
_vendorController.add(vendorListFromJson(jsonVendors));
// _vendorController.add(vendorListFromJson(jsonVendors));

// To display and hide Snort
List<VendorModel> vendorList = vendorListFromJson(jsonVendors);
if (isVendorToggle) {
vendorList.removeWhere((element) => element.displayName == "Snort");
_vendorController.add(vendorList);
} else {
_vendorController.add(vendorListFromJson(jsonVendors));
}
_vendorController.value;
}

close() {
Expand Down
28 changes: 28 additions & 0 deletions lib/bloc/nostr/nostr_actions.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import 'package:breez/bloc/async_action.dart';

class GetPublicKey extends AsyncAction {
GetPublicKey();
}

class SignEvent extends AsyncAction {
final Map<String, dynamic> eventObject;
final String privateKey;

SignEvent(this.eventObject, this.privateKey);
}

class GetRelays extends AsyncAction {}

class Nip04Encrypt extends AsyncAction {
final String data;
final String publicKey;

Nip04Encrypt(this.data, this.publicKey);
}

class Nip04Decrypt extends AsyncAction {
final String encryptedData;
final String privateKey;

Nip04Decrypt(this.encryptedData, this.privateKey);
}
168 changes: 168 additions & 0 deletions lib/bloc/nostr/nostr_bloc.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
import 'dart:async';

import 'package:breez/bloc/async_actions_handler.dart';
import 'package:breez/bloc/nostr/nostr_actions.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:nostr_tools/nostr_tools.dart';
import 'package:shared_preferences/shared_preferences.dart';

class NostrBloc with AsyncActionsHandler {
String nostrPublicKey;
String nostrPrivateKey;

FlutterSecureStorage _secureStorage;
SharedPreferences sharedPreferences;

NostrBloc() {
_secureStorage = const FlutterSecureStorage();

initNostr();

registerAsyncHandlers({
GetPublicKey: _handleGetPublicKey,
SignEvent: _handleSignEvent,
GetRelays: _handleGetRelays,
Nip04Encrypt: _handleNip04Encrypt,
Nip04Decrypt: _handleNip04Decrypt,
});
listenActions();
}

void initNostr() async {
nostrPublicKey = await _secureStorage.read(key: 'nostrPublicKey');
nostrPrivateKey = await _secureStorage.read(key: 'nostrPrivateKey');
SharedPreferences sharedPreferences = await SharedPreferences.getInstance();

if (nostrPublicKey == null) {
sharedPreferences.setBool('rememberGetPubKeyChoice', false);
sharedPreferences.setBool('rememberSignEventChoice', false);
}
}

final StreamController<String> _publicKeyController =
StreamController<String>.broadcast();
Stream<String> get publicKeyStream => _publicKeyController.stream;

final StreamController<Map<String, dynamic>> _eventController =
StreamController<Map<String, dynamic>>.broadcast();

Stream<Map<String, dynamic>> get eventStream => _eventController.stream;

Future<void> _handleGetPublicKey(GetPublicKey action) async {
// to get the public key
String publicKey = await _fetchPublicKey();
_publicKeyController.add(publicKey);
action.resolve(publicKey);
}

Future<void> _handleSignEvent(SignEvent action) async {
// to sign the event
Map<String, dynamic> signedEvent =
await _signEvent(action.eventObject, action.privateKey);

_eventController.add(signedEvent);
action.resolve(signedEvent);
}

Future<void> _handleGetRelays(GetRelays action) async {
// to get the relays
List<String> relays = await _fetchRelays();
// Perform any processing on the relays if needed
action.resolve(relays);
}

Future<void> _handleNip04Encrypt(Nip04Encrypt action) async {
// to encrypt the data`
String encryptedData = await _encryptData(action.data, action.publicKey);
action.resolve(encryptedData);
}

Future<void> _handleNip04Decrypt(Nip04Decrypt action) async {
// to decrypt the data
String decryptedData =
await _decryptData(action.encryptedData, action.privateKey);
action.resolve(decryptedData);
}

// Methods to simulate the actual logic

Future<String> _fetchPublicKey() async {
// check if key pair already exists otherwise generate it

if (nostrPublicKey == null) {
final keyGenerator = KeyApi();
nostrPrivateKey = keyGenerator.generatePrivateKey();
nostrPublicKey = keyGenerator.getPublicKey(nostrPrivateKey);

// Write value
await _secureStorage.write(
key: 'nostrPrivateKey', value: nostrPrivateKey);
await _secureStorage.write(key: 'nostrPublicKey', value: nostrPublicKey);

Future.delayed(const Duration(seconds: 1));
}

return nostrPublicKey;
}

Future<Map<String, dynamic>> _signEvent(
Map<String, dynamic> eventObject, String nostrPrivateKey) async {
final eventApi = EventApi();

if (eventObject['pubkey'] == null) {
eventObject['pubkey'] = nostrPublicKey;
}

List<dynamic> dynamicList = eventObject['tags'];
List<List<String>> stringList =
dynamicList.map((innerList) => List<String>.from(innerList)).toList();

final event = Event(
content: eventObject['content'],
created_at: eventObject['created_at'],
kind: eventObject['kind'],
pubkey: eventObject['pubkey'],
tags: stringList,
);

if (eventObject['id'] == null || eventObject['id'] == '') {
event.id = eventApi.getEventHash(event);
eventObject['id'] = event.id;
} else {
event.id = eventObject['id'];
}

event.sig = eventApi.signEvent(event, nostrPrivateKey);

if (eventApi.verifySignature(event)) {
eventObject['sig'] = event.sig;
}
await Future.delayed(const Duration(seconds: 1));

return eventObject;
}

Future<List<String>> _fetchRelays() async {
await Future.delayed(const Duration(seconds: 1));
return ['Relay1', 'Relay2', 'Relay3'];
}

Future<String> _encryptData(String data, String publicKey) async {
// Simulating an encryption operation
await Future.delayed(const Duration(seconds: 1));
return 'EncryptedData';
}

Future<String> _decryptData(String encryptedData, String privateKey) async {
// Simulating a decryption operation
await Future.delayed(const Duration(seconds: 1));
return 'DecryptedData';
}

@override
Future dispose() {
// _actionsHandler.dispose();
_publicKeyController.close();
return super.dispose();
}
}
34 changes: 34 additions & 0 deletions lib/bloc/nostr/nostr_model.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
class Event {
String id;
int kind;
String pubKey;
String content;
List<List<String>> tags;
int created_at;
String sig;

Event({
this.id,
this.kind,
this.pubKey,
this.content,
this.tags,
this.created_at,
this.sig,
});
}

Map<int, String> eventKind = {
0: 'metadata',
1: 'Text',
2: 'RecommendRelay',
3: 'Contacts',
4: 'EncryptedDirectMessage',
5: 'EventDeletion',
6: 'Repost',
7: 'Reaction',
9734: 'ZapRequest',
9735: 'Zap',
10002: 'RelayList',
30078: 'Application Specific Data'
};
21 changes: 21 additions & 0 deletions lib/routes/dev/dev.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import 'package:breez/bloc/account/add_funds_model.dart';
import 'package:breez/bloc/backup/backup_bloc.dart';
import 'package:breez/bloc/backup/backup_model.dart';
import 'package:breez/bloc/blocs_provider.dart';
import 'package:breez/bloc/marketplace/marketplace_bloc.dart';
import 'package:breez/bloc/marketplace/vendor_model.dart';
import 'package:breez/bloc/podcast_history/sqflite/podcast_history_database.dart';
import 'package:breez/bloc/pos_catalog/bloc.dart';
import 'package:breez/bloc/pos_catalog/sqlite/db.dart';
Expand Down Expand Up @@ -150,6 +152,8 @@ class DevViewState extends State<DevView> {
BackupBloc backupBloc = AppBlocsProvider.of<BackupBloc>(context);
AddFundsBloc addFundsBloc = BlocProvider.of<AddFundsBloc>(context);
UserProfileBloc userBloc = AppBlocsProvider.of<UserProfileBloc>(context);
MarketplaceBloc marketplaceBloc =
AppBlocsProvider.of<MarketplaceBloc>(context);
return StreamBuilder<BackupState>(
stream: backupBloc.backupStateStream,
builder: (ctx, backupSnapshot) => StreamBuilder(
Expand Down Expand Up @@ -187,6 +191,7 @@ class DevViewState extends State<DevView> {
addFundsSettingsSnapshot.data,
userBloc,
userSnapshot.data,
marketplaceBloc,
).map((Choice choice) {
return PopupMenuItem<Choice>(
value: choice,
Expand Down Expand Up @@ -356,6 +361,7 @@ class DevViewState extends State<DevView> {
AddFundsSettings addFundsSettings,
UserProfileBloc userBloc,
BreezUserModel userModel,
MarketplaceBloc marketplaceBloc,
) {
List<Choice> choices = <Choice>[];
choices.addAll(
Expand Down Expand Up @@ -599,6 +605,15 @@ class DevViewState extends State<DevView> {
},
),
);
choices.add(Choice(
title: marketplaceBloc.isVendorToggle == true
? 'Display Snort'
: 'Hide Snort',
icon: Icons.phone_android,
function: () {
_toggleVendor(marketplaceBloc);
},
));

return choices;
}
Expand All @@ -610,6 +625,12 @@ class DevViewState extends State<DevView> {
.pushReplacementNamed("/splash");
}*/

void _toggleVendor(MarketplaceBloc marketplaceBloc) async {
marketplaceBloc.isVendorToggle = !marketplaceBloc.isVendorToggle;

await marketplaceBloc.loadVendors();
}

void _shareFile(String command, String text) async {
Directory tempDir = await getTemporaryDirectory();
tempDir = await tempDir.createTemp("command");
Expand Down
Loading

0 comments on commit 4b69103

Please sign in to comment.