decodeSeed static method

Tuple<List<int>, XRPKeyAlgorithm> decodeSeed(
  1. String seed, [
  2. XRPKeyAlgorithm? algorithm
])

This method decodes a Ripple address (seed) into its corresponding entropy and encoding algorithm.

Implementation

static Tuple<List<int>, XRPKeyAlgorithm> decodeSeed(String seed,
    [XRPKeyAlgorithm? algorithm]) {
  if (algorithm != null) {
    /// If a specific algorithm is provided, attempt to decode with that algorithm's prefix.
    for (final prefix in _algorithmSeedPrefix[algorithm]!) {
      try {
        final decodedResult = _decode(seed, prefix);
        return Tuple(decodedResult, algorithm);
      } catch (e) {
        /// Prefix is incorrect, continue to the next prefix.
        continue;
      }
    }
    throw const XRPLAddressCodecException(
        'Wrong algorithm for the seed type.');
  }

  /// If no specific algorithm is provided, try all possible algorithms.
  for (final algorithm in XRPKeyAlgorithm.values) {
    final prefix = _algorithmSeedPrefix[algorithm]![0];
    try {
      final decodedResult = _decode(seed, prefix);
      return Tuple(decodedResult, algorithm);
    } catch (e) {
      /// Prefix is incorrect, continue to the next algorithm.
      continue;
    }
  }
  throw const XRPLAddressCodecException(
      'Invalid seed; could not determine encoding algorithm');
}