near_pay_app/lib/data/core/wallet.dart
2024-05-08 16:06:58 +03:00

131 lines
3.5 KiB
Dart
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import 'package:flutterchain/flutterchain_lib/constants/core/supported_blockchains.dart';
import 'package:json_annotation/json_annotation.dart';
part 'wallet.g.dart';
@JsonSerializable()
class Wallet {
final String id;
final String name;
final String mnemonic;
final String? passphrase;
final Map<String, Set<BlockChainData>>? blockchainsData;
Wallet({
required this.id,
required this.name,
required this.mnemonic,
this.passphrase,
this.blockchainsData,
});
factory Wallet.fromJson(Map<String, dynamic> json) => _$WalletFromJson(json);
Map<String, dynamic> toJson() => _$WalletToJson(this);
@override
String toString() {
return "{mnemonic $mnemonic , passphrase $passphrase, blockchainsData $blockchainsData}";
}
}
@JsonSerializable()
class BlockChainData {
final String identifier;
final String publicKey;
final String privateKey;
final DerivationPath derivationPath;
final String passphrase;
BlockChainData({
required this.identifier,
required this.publicKey,
required this.privateKey,
required this.derivationPath,
required this.passphrase,
});
// factory BlockChainData.fromJson(Map<String, dynamic> json) =>
// _$BlockChainDataFromJson(json);
//"return NearBlockChainData.fromJson(json);"" this gives error I use that "return BlockChainData.fromJson(json);""
factory BlockChainData.fromJson(Map<String, dynamic> json) {
String identifier = json['identifier'] as String;
switch (identifier) {
case BlockChains.near:
return BlockChainData.fromJson(json);
// Add more cases for other supported blockchains
default:
throw Exception('Unsupported blockchain data type');
}
}
Map<String, dynamic> toJson() => _$BlockChainDataToJson(this);
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is BlockChainData &&
// runtimeType == other.runtimeType &&
publicKey == other.publicKey &&
privateKey == other.privateKey &&
derivationPath == other.derivationPath &&
passphrase == other.passphrase;
@override
int get hashCode =>
publicKey.hashCode ^
privateKey.hashCode ^
derivationPath.hashCode ^
passphrase.hashCode;
@override
String toString() {
return "{publicKey $publicKey , privateKey $privateKey }";
}
}
@JsonSerializable()
class DerivationPath {
// m / purpose’ / coin_type’ / accountNumber / change / address
final String purpose;
final String coinType;
final String accountNumber;
final String change;
final String address;
const DerivationPath({
required this.purpose,
required this.coinType,
required this.accountNumber,
required this.change,
required this.address,
});
factory DerivationPath.fromJson(Map<String, dynamic> json) =>
_$DerivationPathFromJson(json);
Map<String, dynamic> toJson() => _$DerivationPathToJson(this);
@override
String toString() {
return "m/$purpose/$coinType/$accountNumber/$change/$address";
}
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is DerivationPath &&
runtimeType == other.runtimeType &&
purpose == other.purpose &&
coinType == other.coinType &&
accountNumber == other.accountNumber &&
change == other.change &&
address == other.address;
@override
int get hashCode =>
purpose.hashCode ^
coinType.hashCode ^
accountNumber.hashCode ^
change.hashCode ^
address.hashCode;
}