diff --git a/lib/entities/account.dart b/lib/entities/account.dart new file mode 100644 index 0000000..bc6329d --- /dev/null +++ b/lib/entities/account.dart @@ -0,0 +1,29 @@ +import 'package:flutter/widgets.dart'; +import 'profile.dart'; +import 'identity.dart'; + +@immutable +class Account { + final Profile profile; + final Identity identity; + + const Account({required this.profile, required this.identity}); + + Account copyWith({Profile? profile, Identity? identity}) { + return Account( + profile: profile ?? this.profile, + identity: identity ?? this.identity, + ); + } + + Account.fromJson(Map json) + : profile = Profile.fromJson(json['profile']), + identity = Identity.fromJson(json['identity']); + + Map toJson() { + return { + 'profile': profile.toJson(), + 'identity': identity.toJson(), + }; + } +} diff --git a/lib/entities/identity.dart b/lib/entities/identity.dart new file mode 100644 index 0000000..d343f86 --- /dev/null +++ b/lib/entities/identity.dart @@ -0,0 +1,45 @@ +import 'package:flutter/widgets.dart'; +import 'package:veilid/veilid.dart'; + +@immutable +class Identity { + final TypedKey identityPublicKey; + final TypedKey masterPublicKey; + final Signature identitySignature; + final Signature masterSignature; + + const Identity( + {required this.identityPublicKey, + required this.masterPublicKey, + required this.identitySignature, + required this.masterSignature}); + + // Todo with slightly different content. + Identity copyWith( + {TypedKey? identityPublicKey, + TypedKey? masterPublicKey, + Signature? identitySignature, + Signature? masterSignature}) { + return Identity( + identityPublicKey: identityPublicKey ?? this.identityPublicKey, + masterPublicKey: masterPublicKey ?? this.masterPublicKey, + identitySignature: identitySignature ?? this.identitySignature, + masterSignature: masterSignature ?? this.masterSignature, + ); + } + + Identity.fromJson(Map json) + : identityPublicKey = TypedKey.fromJson(json['identity_public_key']), + masterPublicKey = TypedKey.fromJson(json['master_public_key']), + identitySignature = Signature.fromJson(json['identity_signature']), + masterSignature = Signature.fromJson(json['master_signature']); + + Map toJson() { + return { + 'identity_public_key': identityPublicKey.toJson(), + 'master_public_key': masterPublicKey.toJson(), + 'identity_signature': identitySignature.toJson(), + 'master_signature': masterSignature.toJson(), + }; + } +} diff --git a/lib/entities/profile.dart b/lib/entities/profile.dart index 37340bf..b3f3fc9 100644 --- a/lib/entities/profile.dart +++ b/lib/entities/profile.dart @@ -1,19 +1,33 @@ -class Profile { - String name; - String publicKey; - bool invisible; +import 'package:flutter/widgets.dart'; +import 'package:veilid/veilid.dart'; - Profile(this.name, this.publicKey) : invisible = false; +@immutable +class Profile { + final String name; + final TypedKey publicKey; + final bool invisible; + + const Profile( + {required this.name, required this.publicKey, required this.invisible}); + + // Todo with slightly different content. + Profile copyWith({String? name, TypedKey? publicKey, bool? invisible}) { + return Profile( + name: name ?? this.name, + publicKey: publicKey ?? this.publicKey, + invisible: invisible ?? this.invisible, + ); + } Profile.fromJson(Map json) : name = json['name'], - publicKey = json['public_key'], + publicKey = TypedKey.fromJson(json['public_key']), invisible = json['invisible']; Map toJson() { return { 'name': name, - 'public_key': publicKey, + 'public_key': publicKey.toJson(), 'invisible': invisible, }; }