Contact constructor

Contact({
  1. required String publicKey,
  2. String url = '',
  3. String petname = '',
})

Creates a new Contact.

publicKey is a public key to identify the contact. url is a relay URL where events from publicKey can be found. petname is a local name (nickname) for the profile.

An ArgumentError is thrown if publicKey is invalid or if url is not a valid relay URL.

Implementation

Contact({required this.publicKey, this.url = '', this.petname = ''}) {
  if (!keyIsValid(publicKey)) {
    throw ArgumentError.value(publicKey, 'publicKey', 'Invalid key');
  }
  if (url.isNotEmpty &&
      !url.contains(RegExp(
          r'^(wss?:\/\/)([0-9]{1,3}(?:\.[0-9]{1,3}){3}|[^:]+):?([0-9]{1,5})?$'))) {
    throw ArgumentError.value(url, 'url', 'Invalid relay address');
  }
}