mirror of
https://gitlab.com/veilid/veilidchat.git
synced 2024-10-01 06:55:46 -04:00
account work
This commit is contained in:
parent
0aa586a29c
commit
f44fdb8eeb
@ -38,6 +38,8 @@ class LocalAccount with _$LocalAccount {
|
|||||||
required IdentityMaster identityMaster,
|
required IdentityMaster identityMaster,
|
||||||
// The encrypted identity secret that goes with the identityPublicKey
|
// The encrypted identity secret that goes with the identityPublicKey
|
||||||
@Uint8ListJsonConverter() required Uint8List identitySecretKeyBytes,
|
@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
|
// The kind of encryption input used on the account
|
||||||
required EncryptionKeyType encryptionKeyType,
|
required EncryptionKeyType encryptionKeyType,
|
||||||
// If account is not hidden, password can be retrieved via
|
// If account is not hidden, password can be retrieved via
|
||||||
|
@ -80,6 +80,12 @@ class LocalAccountManager {
|
|||||||
Uint8List.fromList(utf8.encode(jsonEncode(identityMaster)));
|
Uint8List.fromList(utf8.encode(jsonEncode(identityMaster)));
|
||||||
await dhtctx.setDHTValue(masterRecordKey, 0, identityMasterBytes);
|
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(
|
return IdentityMasterWithSecrets(
|
||||||
identityMaster: identityMaster,
|
identityMaster: identityMaster,
|
||||||
masterSecret: masterSecret,
|
masterSecret: masterSecret,
|
||||||
@ -91,6 +97,7 @@ class LocalAccountManager {
|
|||||||
if (identityRec != null) {
|
if (identityRec != null) {
|
||||||
await dhtctx.deleteDHTRecord(identityRec.key);
|
await dhtctx.deleteDHTRecord(identityRec.key);
|
||||||
}
|
}
|
||||||
|
rethrow;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,15 +107,29 @@ class LocalAccountManager {
|
|||||||
SecretKey identitySecret,
|
SecretKey identitySecret,
|
||||||
EncryptionKeyType encryptionKeyType,
|
EncryptionKeyType encryptionKeyType,
|
||||||
String encryptionKey) async {
|
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,
|
identityMaster: identityMaster,
|
||||||
identitySecretKeyBytes: identitySecretBytes,
|
identitySecretKeyBytes: identitySecretBytes,
|
||||||
|
identitySecretSaltBytes: eksalt,
|
||||||
encryptionKeyType: encryptionKeyType,
|
encryptionKeyType: encryptionKeyType,
|
||||||
biometricsEnabled: false,
|
biometricsEnabled: false,
|
||||||
hiddenAccount: false,
|
hiddenAccount: false,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Push
|
||||||
|
|
||||||
|
// Return local account object
|
||||||
|
return localAccount;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user