@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.
package/README.md CHANGED
@@ -272,6 +272,8 @@ PaymentRequestProtocol.parseAmount('1.5', 8); // BigInt(150_000_000) (8 decimals
272
272
 
273
273
  ### Nametag Bindings
274
274
 
275
+ Nametags are lowercase alphanumeric strings (`[a-z0-9_-]`, 3–20 chars) or phone numbers (E.164 format). All input is normalized to lowercase before hashing. Use `isValidNametag(input)` to validate.
276
+
275
277
  ```typescript
276
278
  import { NametagBinding, NametagUtils } from '@unicitylabs/nostr-sdk';
277
279
 
@@ -5373,6 +5373,7 @@ class Filter {
5373
5373
  '#p';
5374
5374
  '#t';
5375
5375
  '#d';
5376
+ '#h';
5376
5377
  since;
5377
5378
  until;
5378
5379
  limit;
@@ -5396,6 +5397,8 @@ class Filter {
5396
5397
  this['#t'] = [...data['#t']];
5397
5398
  if (data['#d'])
5398
5399
  this['#d'] = [...data['#d']];
5400
+ if (data['#h'])
5401
+ this['#h'] = [...data['#h']];
5399
5402
  if (data.since !== undefined)
5400
5403
  this.since = data.since;
5401
5404
  if (data.until !== undefined)
@@ -5432,6 +5435,8 @@ class Filter {
5432
5435
  result['#t'] = this['#t'];
5433
5436
  if (this['#d'] && this['#d'].length > 0)
5434
5437
  result['#d'] = this['#d'];
5438
+ if (this['#h'] && this['#h'].length > 0)
5439
+ result['#h'] = this['#h'];
5435
5440
  if (this.since !== undefined)
5436
5441
  result.since = this.since;
5437
5442
  if (this.until !== undefined)
@@ -5518,6 +5523,15 @@ class FilterBuilder {
5518
5523
  }
5519
5524
  return this;
5520
5525
  }
5526
+ hTags(hTagsOrFirst, ...rest) {
5527
+ if (Array.isArray(hTagsOrFirst)) {
5528
+ this.data['#h'] = [...hTagsOrFirst];
5529
+ }
5530
+ else {
5531
+ this.data['#h'] = [hTagsOrFirst, ...rest];
5532
+ }
5533
+ return this;
5534
+ }
5521
5535
  /**
5522
5536
  * Set minimum timestamp (inclusive).
5523
5537
  * @param since Unix timestamp in seconds
@@ -9769,6 +9783,10 @@ function isValidPhoneNumber() {
9769
9783
  */
9770
9784
  /** Salt prefix for nametag hashing */
9771
9785
  const NAMETAG_SALT = 'unicity:nametag:';
9786
+ /** Minimum nametag length (after normalization) */
9787
+ const NAMETAG_MIN_LENGTH = 3;
9788
+ /** Maximum nametag length (after normalization) */
9789
+ const NAMETAG_MAX_LENGTH = 20;
9772
9790
  /** Default country code for phone number normalization */
9773
9791
  const DEFAULT_COUNTRY$1 = 'US';
9774
9792
  /**
@@ -9908,13 +9926,33 @@ function isPhoneNumber(str, defaultCountry = DEFAULT_COUNTRY$1) {
9908
9926
  return false;
9909
9927
  }
9910
9928
  }
9929
+ /**
9930
+ * Validate a nametag string. Strips leading @, normalizes, then checks format.
9931
+ * Regular nametags: lowercase alphanumeric, underscore, hyphen, 3-20 chars.
9932
+ * Phone numbers: validated via libphonenumber-js.
9933
+ * @param nametag Nametag to validate
9934
+ * @param defaultCountry Default country code for phone normalization
9935
+ * @returns true if the nametag is valid
9936
+ */
9937
+ function isValidNametag(nametag, defaultCountry = DEFAULT_COUNTRY$1) {
9938
+ const stripped = nametag.startsWith('@') ? nametag.slice(1) : nametag;
9939
+ const normalized = normalizeNametag(stripped, defaultCountry);
9940
+ if (isPhoneNumber(normalized)) {
9941
+ return true;
9942
+ }
9943
+ const pattern = new RegExp(`^[a-z0-9_-]{${NAMETAG_MIN_LENGTH},${NAMETAG_MAX_LENGTH}}$`);
9944
+ return pattern.test(normalized);
9945
+ }
9911
9946
 
9912
9947
  var NametagUtils = /*#__PURE__*/Object.freeze({
9913
9948
  __proto__: null,
9949
+ NAMETAG_MAX_LENGTH: NAMETAG_MAX_LENGTH,
9950
+ NAMETAG_MIN_LENGTH: NAMETAG_MIN_LENGTH,
9914
9951
  areSameNametag: areSameNametag,
9915
9952
  formatForDisplay: formatForDisplay,
9916
9953
  hashNametag: hashNametag,
9917
9954
  isPhoneNumber: isPhoneNumber,
9955
+ isValidNametag: isValidNametag,
9918
9956
  normalizeNametag: normalizeNametag
9919
9957
  });
9920
9958
 
@@ -10694,5 +10732,5 @@ function isReadReceipt(message) {
10694
10732
  return message.kind === 15;
10695
10733
  }
10696
10734
 
10697
- export { AGENT_LOCATION, AGENT_PROFILE, APP_DATA, AUTH, bech32 as Bech32, CHAT_MESSAGE, CLOSED, CLOSING, CONNECTING, CONTACTS, CallbackEventListener, DELETION, ENCRYPTED_DM, Event, EventKinds, FILE_METADATA, Filter, FilterBuilder, GIFT_WRAP, nip04 as NIP04, nip17 as NIP17, nip44 as NIP44, NametagBinding, NametagUtils, NostrClient, NostrKeyManager, OPEN, PAYMENT_REQUEST, PAYMENT_REQUEST_RESPONSE, PROFILE, PaymentRequestProtocol, REACTION, READ_RECEIPT, RECOMMEND_RELAY, RELAY_LIST, SEAL, schnorr as SchnorrSigner, TEXT_NOTE, TOKEN_TRANSFER, TokenTransferProtocol, areSameNametag, createBindingEvent, createGiftWrap, createNametagToPubkeyFilter, createPubkeyToNametagFilter, createReadReceipt, createWebSocket, decode, decodeNpub, decodeNsec, encode, encodeNpub, encodeNsec, extractMessageData, formatForDisplay, getName, getPublicKey, getPublicKeyHex, hashNametag, isChatMessage, isEphemeral, isParameterizedReplaceable, isPhoneNumber, isReadReceipt, isReplaceable, isValidBindingEvent, normalizeNametag, parseAddressFromEvent, parseNametagHashFromEvent, sign, signHex, unwrap, verify, verifyHex };
10735
+ export { AGENT_LOCATION, AGENT_PROFILE, APP_DATA, AUTH, bech32 as Bech32, CHAT_MESSAGE, CLOSED, CLOSING, CONNECTING, CONTACTS, CallbackEventListener, DELETION, ENCRYPTED_DM, Event, EventKinds, FILE_METADATA, Filter, FilterBuilder, GIFT_WRAP, NAMETAG_MAX_LENGTH, NAMETAG_MIN_LENGTH, nip04 as NIP04, nip17 as NIP17, nip44 as NIP44, NametagBinding, NametagUtils, NostrClient, NostrKeyManager, OPEN, PAYMENT_REQUEST, PAYMENT_REQUEST_RESPONSE, PROFILE, PaymentRequestProtocol, REACTION, READ_RECEIPT, RECOMMEND_RELAY, RELAY_LIST, SEAL, schnorr as SchnorrSigner, TEXT_NOTE, TOKEN_TRANSFER, TokenTransferProtocol, areSameNametag, createBindingEvent, createGiftWrap, createNametagToPubkeyFilter, createPubkeyToNametagFilter, createReadReceipt, createWebSocket, decode, decodeNpub, decodeNsec, encode, encodeNpub, encodeNsec, extractMessageData, formatForDisplay, getName, getPublicKey, getPublicKeyHex, hashNametag, isChatMessage, isEphemeral, isParameterizedReplaceable, isPhoneNumber, isReadReceipt, isReplaceable, isValidBindingEvent, isValidNametag, normalizeNametag, parseAddressFromEvent, parseNametagHashFromEvent, sign, signHex, unwrap, verify, verifyHex };
10698
10736
  //# sourceMappingURL=index.js.map