2023-07-17 22:39:33 -04:00
|
|
|
import 'package:fast_immutable_collections/fast_immutable_collections.dart';
|
2023-07-07 19:33:28 -04:00
|
|
|
import 'package:freezed_annotation/freezed_annotation.dart';
|
|
|
|
import 'package:veilid/veilid.dart';
|
|
|
|
|
|
|
|
part 'identity.freezed.dart';
|
|
|
|
part 'identity.g.dart';
|
|
|
|
|
2023-07-16 21:41:40 -04:00
|
|
|
// AccountOwnerInfo is the key and owner info for the account dht key that is
|
|
|
|
// stored in the identity key
|
|
|
|
@freezed
|
2023-07-17 22:39:33 -04:00
|
|
|
class AccountRecordInfo with _$AccountRecordInfo {
|
|
|
|
const factory AccountRecordInfo({
|
2023-07-16 21:41:40 -04:00
|
|
|
// Top level account keys and secrets
|
2023-07-17 22:39:33 -04:00
|
|
|
required TypedKey key,
|
|
|
|
required KeyPair owner,
|
|
|
|
}) = _AccountRecordInfo;
|
2023-07-16 21:41:40 -04:00
|
|
|
|
2023-07-25 01:04:34 -04:00
|
|
|
factory AccountRecordInfo.fromJson(dynamic json) =>
|
|
|
|
_$AccountRecordInfoFromJson(json as Map<String, dynamic>);
|
2023-07-16 21:41:40 -04:00
|
|
|
}
|
|
|
|
|
2023-07-07 19:33:28 -04:00
|
|
|
// Identity Key points to accounts associated with this identity
|
2023-07-25 01:04:34 -04:00
|
|
|
// accounts field has a map of bundle id or uuid to account key pairs
|
2023-07-07 19:33:28 -04:00
|
|
|
// DHT Schema: DFLT(1)
|
2023-07-09 00:07:21 -04:00
|
|
|
// DHT Key (Private): identityRecordKey
|
|
|
|
// DHT Owner Key: identityPublicKey
|
2023-07-26 17:42:11 -04:00
|
|
|
// DHT Secret: identitySecretKey (stored encrypted
|
|
|
|
// with unlock code in local table store)
|
2023-07-07 19:33:28 -04:00
|
|
|
@freezed
|
|
|
|
class Identity with _$Identity {
|
|
|
|
const factory Identity({
|
|
|
|
// Top level account keys and secrets
|
2023-07-17 22:39:33 -04:00
|
|
|
required IMap<String, ISet<AccountRecordInfo>> accountRecords,
|
2023-07-07 19:33:28 -04:00
|
|
|
}) = _Identity;
|
|
|
|
|
2023-07-25 01:04:34 -04:00
|
|
|
factory Identity.fromJson(dynamic json) =>
|
|
|
|
_$IdentityFromJson(json as Map<String, dynamic>);
|
2023-07-07 19:33:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Identity Master key structure for created account
|
|
|
|
// Master key allows for regeneration of identity DHT record
|
|
|
|
// Bidirectional Master<->Identity signature allows for
|
|
|
|
// chain of identity ownership for account recovery process
|
|
|
|
//
|
2023-07-09 00:07:21 -04:00
|
|
|
// Backed by a DHT key at masterRecordKey, the secret is kept
|
2023-07-07 19:33:28 -04:00
|
|
|
// completely offline and only written to upon account recovery
|
|
|
|
//
|
|
|
|
// DHT Schema: DFLT(1)
|
2023-07-09 00:07:21 -04:00
|
|
|
// DHT Record Key (Public): masterRecordKey
|
|
|
|
// DHT Owner Key: masterPublicKey
|
|
|
|
// DHT Owner Secret: masterSecretKey (kept offline)
|
2023-07-07 19:33:28 -04:00
|
|
|
// Encryption: None
|
|
|
|
@freezed
|
|
|
|
class IdentityMaster with _$IdentityMaster {
|
|
|
|
const factory IdentityMaster(
|
2023-07-09 00:07:21 -04:00
|
|
|
{
|
|
|
|
// Private DHT record storing identity account mapping
|
|
|
|
required TypedKey identityRecordKey,
|
|
|
|
// Public key of identity
|
|
|
|
required PublicKey identityPublicKey,
|
|
|
|
// Public DHT record storing this structure for account recovery
|
|
|
|
required TypedKey masterRecordKey,
|
|
|
|
// Public key of master identity used to sign identity keys for recovery
|
|
|
|
required PublicKey masterPublicKey,
|
|
|
|
// Signature of identityRecordKey and identityPublicKey by masterPublicKey
|
2023-07-07 19:33:28 -04:00
|
|
|
required Signature identitySignature,
|
2023-07-09 00:07:21 -04:00
|
|
|
// Signature of masterRecordKey and masterPublicKey by identityPublicKey
|
2023-07-07 19:33:28 -04:00
|
|
|
required Signature masterSignature}) = _IdentityMaster;
|
|
|
|
|
2023-07-25 01:04:34 -04:00
|
|
|
factory IdentityMaster.fromJson(dynamic json) =>
|
|
|
|
_$IdentityMasterFromJson(json as Map<String, dynamic>);
|
2023-07-07 19:33:28 -04:00
|
|
|
}
|
2023-07-09 00:07:21 -04:00
|
|
|
|
2023-07-16 21:41:40 -04:00
|
|
|
extension IdentityMasterExtension on IdentityMaster {
|
2023-07-26 17:42:11 -04:00
|
|
|
KeyPair identityWriter(SecretKey secret) =>
|
|
|
|
KeyPair(key: identityPublicKey, secret: secret);
|
2023-07-16 21:41:40 -04:00
|
|
|
|
2023-07-26 17:42:11 -04:00
|
|
|
KeyPair masterWriter(SecretKey secret) =>
|
|
|
|
KeyPair(key: masterPublicKey, secret: secret);
|
2023-07-16 21:41:40 -04:00
|
|
|
}
|