DeriveJunction.fromStr constructor

DeriveJunction.fromStr(
  1. String str
)

Implementation

factory DeriveJunction.fromStr(String str) {
  final bool hard;
  final String code;
  if (str.startsWith('/')) {
    hard = true;
    code = str.substring(1);
  } else {
    hard = false;
    code = str;
  }

  final n = BigInt.tryParse(code, radix: 10);
  final Uint8List bytes;
  if (n != null &&
      n >= BigInt.zero &&
      n < BigInt.parse('18446744073709551616')) {
    // number
    bytes = U64Codec.codec.encode(n);
  } else {
    // something else
    bytes = StrCodec.codec.encode(code);
  }

  return DeriveJunction.fromBytes(hard, bytes);
}