encryptPGPKey function
Implementation
Future<EncryptedPrivateKeyModel> encryptPGPKey({
String encryptionType = Constants.ENC_TYPE_V3,
required String generatedPrivateKey,
required Wallet wallet,
dynamic additionalMeta,
}) async {
if (wallet.signer == null) {
throw Exception('Provide signer in the function');
}
EncryptedPrivateKeyModel encryptedPrivateKey;
switch (encryptionType) {
// case Constants.ENC_TYPE_V1:
// String walletPublicKey = wallet.publicKey!;
// encryptedPrivateKey =
// encryptV1(generatedPrivateKey, walletPublicKey, encryptionType);
// break;
case Constants.ENC_TYPE_V3:
Uint8List input = await getRandomValues(Uint8List(32));
final decodedInput = bytesToHex(input);
String enableProfileMessage = 'Enable Push Profile \n$decodedInput';
final signature = await getEip191Signature(wallet, enableProfileMessage);
dynamic secret = signature['verificationProof'];
List<int> encodedPrivateKey = utf8.encode(generatedPrivateKey);
encryptedPrivateKey = await encryptV2(
data: encodedPrivateKey,
secret: hexToBytesInternal(secret),
);
encryptedPrivateKey.version = encryptionType;
encryptedPrivateKey.preKey = bytesToHex(input);
break;
case Constants.ENC_TYPE_V4:
if (additionalMeta?.NFTPGP_V1?.password == null) {
throw Exception('Password is required!');
}
List<int> encodedPrivateKey = utf8.encode(generatedPrivateKey);
encryptedPrivateKey = await encryptV2(
data: encodedPrivateKey,
secret: hexToBytes(stringToHex(additionalMeta.NFTPGP_V1.password)),
);
encryptedPrivateKey.version = Constants.ENC_TYPE_V4;
encryptedPrivateKey.preKey = '';
break;
default:
throw Exception('Invalid Encryption Type');
}
return encryptedPrivateKey;
}