@unicitylabs/nostr-js-sdk 0.3.2 → 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
 
@@ -9783,6 +9783,10 @@ function isValidPhoneNumber() {
9783
9783
  */
9784
9784
  /** Salt prefix for nametag hashing */
9785
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;
9786
9790
  /** Default country code for phone number normalization */
9787
9791
  const DEFAULT_COUNTRY$1 = 'US';
9788
9792
  /**
@@ -9922,13 +9926,33 @@ function isPhoneNumber(str, defaultCountry = DEFAULT_COUNTRY$1) {
9922
9926
  return false;
9923
9927
  }
9924
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
+ }
9925
9946
 
9926
9947
  var NametagUtils = /*#__PURE__*/Object.freeze({
9927
9948
  __proto__: null,
9949
+ NAMETAG_MAX_LENGTH: NAMETAG_MAX_LENGTH,
9950
+ NAMETAG_MIN_LENGTH: NAMETAG_MIN_LENGTH,
9928
9951
  areSameNametag: areSameNametag,
9929
9952
  formatForDisplay: formatForDisplay,
9930
9953
  hashNametag: hashNametag,
9931
9954
  isPhoneNumber: isPhoneNumber,
9955
+ isValidNametag: isValidNametag,
9932
9956
  normalizeNametag: normalizeNametag
9933
9957
  });
9934
9958
 
@@ -10708,5 +10732,5 @@ function isReadReceipt(message) {
10708
10732
  return message.kind === 15;
10709
10733
  }
10710
10734
 
10711
- 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 };
10712
10736
  //# sourceMappingURL=index.js.map