account work

This commit is contained in:
Christien Rioux 2023-07-09 13:55:53 -04:00
parent 0aa586a29c
commit f44fdb8eeb
2 changed files with 25 additions and 2 deletions

View File

@ -38,6 +38,8 @@ class LocalAccount with _$LocalAccount {
required IdentityMaster identityMaster,
// The encrypted identity secret that goes with the identityPublicKey
@Uint8ListJsonConverter() required Uint8List identitySecretKeyBytes,
// The salt for the identity secret key encryption
@Uint8ListJsonConverter() required Uint8List identitySecretSaltBytes,
// The kind of encryption input used on the account
required EncryptionKeyType encryptionKeyType,
// If account is not hidden, password can be retrieved via

View File

@ -80,6 +80,12 @@ class LocalAccountManager {
Uint8List.fromList(utf8.encode(jsonEncode(identityMaster)));
await dhtctx.setDHTValue(masterRecordKey, 0, identityMasterBytes);
// Write empty identity to account map
const identity = Identity(accountKeyPairs: {});
final identityBytes =
Uint8List.fromList(utf8.encode(jsonEncode(identity)));
await dhtctx.setDHTValue(identityRecordKey, 0, identityBytes);
return IdentityMasterWithSecrets(
identityMaster: identityMaster,
masterSecret: masterSecret,
@ -91,6 +97,7 @@ class LocalAccountManager {
if (identityRec != null) {
await dhtctx.deleteDHTRecord(identityRec.key);
}
rethrow;
}
}
@ -100,15 +107,29 @@ class LocalAccountManager {
SecretKey identitySecret,
EncryptionKeyType encryptionKeyType,
String encryptionKey) async {
//
// Encrypt identitySecret with key
final cs = await Veilid.instance.bestCryptoSystem();
final ekbytes = Uint8List.fromList(utf8.encode(encryptionKey));
final nonce = await cs.randomNonce();
final eksalt = nonce.decode();
SharedSecret sharedSecret = await cs.deriveSharedSecret(ekbytes, eksalt);
final identitySecretBytes =
await cs.cryptNoAuth(identitySecret.decode(), nonce, sharedSecret);
return LocalAccount(
// Create local account object
final localAccount = LocalAccount(
identityMaster: identityMaster,
identitySecretKeyBytes: identitySecretBytes,
identitySecretSaltBytes: eksalt,
encryptionKeyType: encryptionKeyType,
biometricsEnabled: false,
hiddenAccount: false,
);
// Push
// Return local account object
return localAccount;
}
}