upgrade function

Future<User?> upgrade({
  1. String? account,
  2. Signer? signer,
  3. dynamic additionalMeta,
  4. required dynamic progressHook(
    1. ProgressHookType
    ),
})

Implementation

Future<User?> upgrade({
  String? account,
  Signer? signer,
  additionalMeta,
  required Function(ProgressHookType) progressHook,
}) async {
  try {
    final wallet = getWallet(address: account, signer: signer);
    final address = getAccountAddress(wallet);

    if (!isValidETHAddress(address)) {
      throw Exception('Invalid address!');
    }

    var user = await getUser(address: address);
    if (user == null) {
      throw Exception('User Not Found!');
    }

    final recommendedPgpEncryptionVersion = ENCRYPTION_TYPE.PGP_V3;
    final version = user.parsedPrivateKey!.version;

    if (version == recommendedPgpEncryptionVersion ||
        version == ENCRYPTION_TYPE.NFTPGP_V1) {
      return user;
    }

    final pgpPrivateKey = await decryptPGPKey(
      encryptedPGPPrivateKey: user.encryptedPrivateKey!,
      wallet: wallet,
      toUpgrade: false,
      additionalMeta: additionalMeta,
    );

    final upgradedUser = await authUpdate(
      pgpPrivateKey: pgpPrivateKey, // decrypted pgp priv key
      pgpEncryptionVersion: recommendedPgpEncryptionVersion,
      wallet: wallet,
      pgpPublicKey: user.publicKey!,
      account: user.did!,
      additionalMeta: additionalMeta,
    );

    return upgradedUser;
  } catch (err) {
    log('[Push SDK] - API - Error - API upgrade -: $err');
    rethrow;
  }
}