create static method

BaseAuthenticator create(
  1. String creds
)

Implementation

static BaseAuthenticator create(String creds) {
  RegExp re = RegExp(
    r'\s*(?:(?:[-]{3,}[^\n]*[-]{3,}\n)(.+)(?:\n\s*[-]{3,}[^\n]*[-]{3,}\n))',
    caseSensitive: false,
    multiLine: true,
  );
  var m = re.allMatches(creds);
  if (m.length != 2 ||
      m.elementAt(0).groupCount != 1 ||
      m.elementAt(1).groupCount != 1) {
    throw NatsError.errorForCode(ErrorCode.BAD_CREDS);
  }
  String jwt = m.elementAt(0).group(1).toString().trim();
  String seed = m.elementAt(1).group(1).toString().trim();
  return CredsAuthenticator().buildAuthenticator({'jwt': jwt, 'seed': seed});
}