ZCashAccount.fromUnifiedFullViewKey constructor

ZCashAccount.fromUnifiedFullViewKey({
  1. required String ufvk,
  2. required ZCashAccountConfig config,
  3. required ZCryptoContext context,
})

Implementation

factory ZCashAccount.fromUnifiedFullViewKey({
  required String ufvk,
  required ZCashAccountConfig config,
  required ZCryptoContext context,
}) {
  final key = ZCashEncodingUtils.decodeUnifiedObject(
    address: ufvk,
    mode: UnifiedReceiverMode.fvk,
    expectedHrp: config.coinConfig.hrpUnifiedFvk,
  );
  if (key == null) {
    throw ArgumentException.invalidOperationArguments(
      "fromUnifiedFullViewKey",
      reason: "Invalid UFVK encoded string.",
    );
  }
  final r = key.$1;
  final sapling = r.firstWhereNullable((e) => e.type == Typecode.sapling);
  final orchard = r.firstWhereNullable((e) => e.type == Typecode.orchard);
  final transparent = r.firstWhereNullable((e) => e.type == Typecode.p2pkh);
  return ZCashAccount._(
    config: config,
    context: context,
    sapling:
        sapling == null
            ? null
            : Zip32Sapling.fromExtendedFullViewKey(sapling.data),
    orchard:
        orchard == null
            ? null
            : Zip32Orchard.fromFullViewKey(
              fvk: orchard.data,
              context: context,
            ),
    transparent:
        transparent == null
            ? null
            : ZCashEncodingUtils.decodeBip44Fvk(transparent.data),
  );
}