11import { ZNS } from 'zcashname-sdk'
22
3+ // Canonical suffix used when rendering a name resolved from an address.
34export const ZNS_SUFFIX = '.zcash'
45
6+ // All suffixes accepted as ZNS input. Order matters for `stripZnsSuffix`:
7+ // longer suffixes must be checked first so that e.g. ".zcash" is preferred
8+ // over a hypothetical ".z" prefix-match.
9+ const ZNS_INPUT_SUFFIXES = [ '.zcash' , '.zec' ] as const
10+
511// The SDK's `network` option only selects the registry address; its `url`
612// always falls back to the testnet indexer unless overridden explicitly.
713const ZNS_MAINNET_URL = 'https://main.zcashnames.com'
@@ -17,14 +23,18 @@ export const resetZnsClient = (): void => {
1723 znsClient = null
1824}
1925
20- export const isZnsName = ( input : string ) : boolean =>
21- input . toLowerCase ( ) . endsWith ( ZNS_SUFFIX )
26+ export const isZnsName = ( input : string ) : boolean => {
27+ const lower = input . toLowerCase ( )
28+ return ZNS_INPUT_SUFFIXES . some ( suffix => lower . endsWith ( suffix ) )
29+ }
2230
2331export const stripZnsSuffix = ( input : string ) : string => {
2432 const lower = input . toLowerCase ( )
25- return lower . endsWith ( ZNS_SUFFIX )
26- ? lower . slice ( 0 , lower . length - ZNS_SUFFIX . length )
27- : lower
33+ for ( const suffix of ZNS_INPUT_SUFFIXES ) {
34+ if ( lower . endsWith ( suffix ) )
35+ return lower . slice ( 0 , lower . length - suffix . length )
36+ }
37+ return lower
2838}
2939
3040export const resolveZnsName = async ( input : string ) : Promise < string | null > => {
0 commit comments