@unicitylabs/nostr-js-sdk 0.3.1 → 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5379,6 +5379,7 @@
5379
5379
  '#p';
5380
5380
  '#t';
5381
5381
  '#d';
5382
+ '#h';
5382
5383
  since;
5383
5384
  until;
5384
5385
  limit;
@@ -5402,6 +5403,8 @@
5402
5403
  this['#t'] = [...data['#t']];
5403
5404
  if (data['#d'])
5404
5405
  this['#d'] = [...data['#d']];
5406
+ if (data['#h'])
5407
+ this['#h'] = [...data['#h']];
5405
5408
  if (data.since !== undefined)
5406
5409
  this.since = data.since;
5407
5410
  if (data.until !== undefined)
@@ -5438,6 +5441,8 @@
5438
5441
  result['#t'] = this['#t'];
5439
5442
  if (this['#d'] && this['#d'].length > 0)
5440
5443
  result['#d'] = this['#d'];
5444
+ if (this['#h'] && this['#h'].length > 0)
5445
+ result['#h'] = this['#h'];
5441
5446
  if (this.since !== undefined)
5442
5447
  result.since = this.since;
5443
5448
  if (this.until !== undefined)
@@ -5524,6 +5529,15 @@
5524
5529
  }
5525
5530
  return this;
5526
5531
  }
5532
+ hTags(hTagsOrFirst, ...rest) {
5533
+ if (Array.isArray(hTagsOrFirst)) {
5534
+ this.data['#h'] = [...hTagsOrFirst];
5535
+ }
5536
+ else {
5537
+ this.data['#h'] = [hTagsOrFirst, ...rest];
5538
+ }
5539
+ return this;
5540
+ }
5527
5541
  /**
5528
5542
  * Set minimum timestamp (inclusive).
5529
5543
  * @param since Unix timestamp in seconds
@@ -9775,6 +9789,10 @@
9775
9789
  */
9776
9790
  /** Salt prefix for nametag hashing */
9777
9791
  const NAMETAG_SALT = 'unicity:nametag:';
9792
+ /** Minimum nametag length (after normalization) */
9793
+ const NAMETAG_MIN_LENGTH = 3;
9794
+ /** Maximum nametag length (after normalization) */
9795
+ const NAMETAG_MAX_LENGTH = 20;
9778
9796
  /** Default country code for phone number normalization */
9779
9797
  const DEFAULT_COUNTRY$1 = 'US';
9780
9798
  /**
@@ -9914,13 +9932,33 @@
9914
9932
  return false;
9915
9933
  }
9916
9934
  }
9935
+ /**
9936
+ * Validate a nametag string. Strips leading @, normalizes, then checks format.
9937
+ * Regular nametags: lowercase alphanumeric, underscore, hyphen, 3-20 chars.
9938
+ * Phone numbers: validated via libphonenumber-js.
9939
+ * @param nametag Nametag to validate
9940
+ * @param defaultCountry Default country code for phone normalization
9941
+ * @returns true if the nametag is valid
9942
+ */
9943
+ function isValidNametag(nametag, defaultCountry = DEFAULT_COUNTRY$1) {
9944
+ const stripped = nametag.startsWith('@') ? nametag.slice(1) : nametag;
9945
+ const normalized = normalizeNametag(stripped, defaultCountry);
9946
+ if (isPhoneNumber(normalized)) {
9947
+ return true;
9948
+ }
9949
+ const pattern = new RegExp(`^[a-z0-9_-]{${NAMETAG_MIN_LENGTH},${NAMETAG_MAX_LENGTH}}$`);
9950
+ return pattern.test(normalized);
9951
+ }
9917
9952
 
9918
9953
  var NametagUtils = /*#__PURE__*/Object.freeze({
9919
9954
  __proto__: null,
9955
+ NAMETAG_MAX_LENGTH: NAMETAG_MAX_LENGTH,
9956
+ NAMETAG_MIN_LENGTH: NAMETAG_MIN_LENGTH,
9920
9957
  areSameNametag: areSameNametag,
9921
9958
  formatForDisplay: formatForDisplay,
9922
9959
  hashNametag: hashNametag,
9923
9960
  isPhoneNumber: isPhoneNumber,
9961
+ isValidNametag: isValidNametag,
9924
9962
  normalizeNametag: normalizeNametag
9925
9963
  });
9926
9964
 
@@ -10719,6 +10757,8 @@
10719
10757
  exports.Filter = Filter;
10720
10758
  exports.FilterBuilder = FilterBuilder;
10721
10759
  exports.GIFT_WRAP = GIFT_WRAP;
10760
+ exports.NAMETAG_MAX_LENGTH = NAMETAG_MAX_LENGTH;
10761
+ exports.NAMETAG_MIN_LENGTH = NAMETAG_MIN_LENGTH;
10722
10762
  exports.NIP04 = nip04;
10723
10763
  exports.NIP17 = nip17;
10724
10764
  exports.NIP44 = nip44;
@@ -10766,6 +10806,7 @@
10766
10806
  exports.isReadReceipt = isReadReceipt;
10767
10807
  exports.isReplaceable = isReplaceable;
10768
10808
  exports.isValidBindingEvent = isValidBindingEvent;
10809
+ exports.isValidNametag = isValidNametag;
10769
10810
  exports.normalizeNametag = normalizeNametag;
10770
10811
  exports.parseAddressFromEvent = parseAddressFromEvent;
10771
10812
  exports.parseNametagHashFromEvent = parseNametagHashFromEvent;