"use strict";var K=Object.defineProperty;var J=(t,a,r)=>a in t?K(t,a,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[a]=r;var u=(t,a,r)=>(J(t,typeof a!="symbol"?a+"":a,r),r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Q=require("@cosmjs/cosmwasm-stargate"),X=require("js-sha3"),Y=require("idna-uts46-hx");function Z(t){const a=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const r in t)if(r!=="default"){const e=Object.getOwnPropertyDescriptor(t,r);Object.defineProperty(a,r,e.get?e:{enumerable:!0,get:()=>t[r]})}}return a.default=t,Object.freeze(a)}const ee=Z(X);var S="qpzry9x8gf2tvdw0s3jn54khce6mua7l",T={};for(var D=0;D>25;return(t&33554431)<<5^-(a>>0&1)&996825010^-(a>>1&1)&642813549^-(a>>2&1)&513874426^-(a>>3&1)&1027748829^-(a>>4&1)&705979059}function R(t){for(var a=1,r=0;r126)return"Invalid prefix ("+t+")";a=g(a)^e>>5}for(a=g(a),r=0;rr)throw new TypeError("Exceeds length limit");t=t.toLowerCase();var e=R(t);if(typeof e=="string")throw new Error(e);for(var n=t+"1",s=0;s>5)throw new Error("Non 5-bit word");e=g(e)^c,n+=S.charAt(c)}for(s=0;s<6;++s)e=g(e);for(e^=1,s=0;s<6;++s){var h=e>>(5-s)*5&31;n+=S.charAt(h)}return n}function P(t,a){if(a=a||90,t.length<8)return t+" too short";if(t.length>a)return"Exceeds length limit";var r=t.toLowerCase(),e=t.toUpperCase();if(t!==r&&t!==e)return"Mixed-case string "+t;t=r;var n=t.lastIndexOf("1");if(n===-1)return"No separator character for "+t;if(n===0)return"Missing prefix for "+t;var s=t.slice(0,n),c=t.slice(n+1);if(c.length<6)return"Data too short";var h=R(s);if(typeof h=="string")return h;for(var w=[],d=0;d=c.length)&&w.push(m)}return h!==1?"Invalid checksum for "+t:{prefix:s,words:w}}function re(){var t=P.apply(null,arguments);if(typeof t=="object")return t}function se(t){var a=P.apply(null,arguments);if(typeof a=="object")return a;throw new Error(a)}function j(t,a,r,e){for(var n=0,s=0,c=(1<=r;)s-=r,h.push(n>>s&c);if(e)s>0&&h.push(n<=a)return"Excess padding";if(n<(t.NETWORK="network",t.NOT_FOUND="not-found",t.UNREGISTERED_SERVICE="unregistered-service",t.DUPLICATE_SERVICE="duplicate-service",t.INVALID_ADDRESS="invalid-address",t.UNAVAILABLE_METHOD="invalid-address",t))(o||{});class i extends Error{constructor(r,e){super(r);u(this,"type");this.name="MatchaError",this.type=e}}const U=class{};let N=U;u(N,"clients",{}),u(N,"getClient",async a=>{let r=U.clients[a];return r===void 0&&(r=await Q.CosmWasmClient.connect(a),U.clients[a]=r),r});class y{getCosmWasmClient(a){return N.getClient(a)}}const F={mainnet:"https://rpc.cosmos.directory/osmosis",testnet:"https://rpc-test.osmosis.zone"},O="icns";class ie extends y{constructor(){super(...arguments);u(this,"serviceID",O);u(this,"chain","osmosis");u(this,"contractAddress",{mainnet:"osmo1xk0s8xgktn9x5vwcgtjdxqzadg88fgn33p8u9cnpdxwemvxscvast52cdd",testnet:"osmo1q2qpencrnnlamwalxt6tac2ytl35z5jejn0v4frnp6jff7gwp37sjcnhu5"})}async resolve(r,e,n){var w,d,l,m;const s=await this.getCosmWasmClient(((d=(w=n==null?void 0:n.rpcUrls)==null?void 0:w[O])==null?void 0:d[e])??F[e]),[c,h]=r.split(".");try{const f=await(s==null?void 0:s.queryContractSmart(this.contractAddress[e],{address:{name:c,bech32_prefix:h}}));if(!(f!=null&&f.address)||((m=(l=n==null?void 0:n.allowedTopLevelDomains)==null?void 0:l.icns)==null?void 0:m.indexOf(h))===-1)throw new i("",o.NOT_FOUND);return f.address}catch{throw new i("",o.NOT_FOUND)}}async lookup(r,e,n){var h,w;const s=await this.getCosmWasmClient(((w=(h=n==null?void 0:n.rpcUrls)==null?void 0:h[O])==null?void 0:w[e])??F[e]),c={prefix:null,words:null};try{const{prefix:d,words:l}=v.decode(r);c.prefix=d,c.words=l}catch{throw new i("",o.INVALID_ADDRESS)}try{const d=await(s==null?void 0:s.queryContractSmart(this.contractAddress[e],{primary_name:{address:r}}));if(!(d!=null&&d.name))throw new i("",o.NOT_FOUND);return`${d.name}.${c.prefix}`}catch{throw new i("",o.NOT_FOUND)}}}const E={mainnet:"https://rpc.cosmos.directory/juno",testnet:"https://rpc.uni.kingnodes.com"},x="ibcDomains";class de extends y{constructor(){super(...arguments);u(this,"serviceID",x);u(this,"chain","juno");u(this,"contractAddress",{mainnet:"juno1ce7wjfsuk79t2mdvpdjtv8280pcc64yh9mh62qptuvxe64twt4pqa68z2a",testnet:"juno19al2ptpxz3xk6q8nl3eyvyslkz8g6nz25w48dfpaepwaxavq3mhqsjjqe5"})}async resolve(r,e,n){var w,d,l,m;const s=await this.getCosmWasmClient(((d=(w=n==null?void 0:n.rpcUrls)==null?void 0:w[x])==null?void 0:d[e])??E[e]),[c,h]=r.split(".");try{const f=await(s==null?void 0:s.queryContractSmart(this.contractAddress[e],{owner_of:{token_id:c}}));if(!(f!=null&&f.owner)||((m=(l=n==null?void 0:n.allowedTopLevelDomains)==null?void 0:l.ibcDomains)==null?void 0:m.indexOf(h))===-1)throw new i("",o.NOT_FOUND);try{const{words:C}=v.decode(f.owner);return v.encode(h,C)}catch{throw new i("",o.NOT_FOUND)}}catch{throw new i("",o.NOT_FOUND)}}async lookup(r,e,n){var w,d;const s=await this.getCosmWasmClient(((d=(w=n==null?void 0:n.rpcUrls)==null?void 0:w[x])==null?void 0:d[e])??E[e]),c={prefix:null,words:null};try{const{prefix:l,words:m}=v.decode(r);c.prefix=l,c.words=m}catch{throw new i("",o.INVALID_ADDRESS)}const h=v.encode("juno",c.words);try{const l=await(s==null?void 0:s.queryContractSmart(this.contractAddress[e],{primary_domain:{address:h}}));if(!(l!=null&&l.domain))throw new i("",o.NOT_FOUND);return`${l.domain}.${c.prefix}`}catch{throw new i("",o.NOT_FOUND)}}}const k={mainnet:"https://rpc.cosmos.directory/stargaze",testnet:"https://rpc.elgafar-1.stargaze-apis.com"},A="stargazeNames";class le extends y{constructor(){super(...arguments);u(this,"serviceID",A);u(this,"chain","stargaze");u(this,"contractAddress",{mainnet:"stars1fx74nkqkw2748av8j7ew7r3xt9cgjqduwn8m0ur5lhe49uhlsasszc5fhr",testnet:"stars1rp5ttjvd5g0vlpltrkyvq62tcrdz949gjtpah000ynh4n2laz52qarz2z8"})}async resolve(r,e,n){var w,d,l,m;const s=await this.getCosmWasmClient(((d=(w=n==null?void 0:n.rpcUrls)==null?void 0:w[A])==null?void 0:d[e])??k[e]),[c,h]=r.split(".");try{const f=await s.queryContractSmart(this.contractAddress[e],{associated_address:{name:c}});if(!f||((m=(l=n==null?void 0:n.allowedTopLevelDomains)==null?void 0:l.stargazeNames)==null?void 0:m.indexOf(h))===-1)throw new i("",o.NOT_FOUND);try{const{words:C}=v.decode(f);return v.encode(h,C)}catch{throw new i("",o.NOT_FOUND)}}catch{throw new i("",o.NOT_FOUND)}}async lookup(r,e,n){var h,w;const s=await this.getCosmWasmClient(((w=(h=n==null?void 0:n.rpcUrls)==null?void 0:h[A])==null?void 0:w[e])??k[e]),c={prefix:null,words:null};try{const{prefix:d,words:l}=v.decode(r);c.prefix=d,c.words=l}catch{throw new i("",o.INVALID_ADDRESS)}try{return`${await s.queryContractSmart(this.contractAddress[e],{name:{address:r}})}.${c.prefix}`}catch{throw new i("",o.NOT_FOUND)}}}const L={mainnet:"https://rpc.mainnet.archway.io",testnet:"https://rpc.constantine.archway.tech"},_="archIds";class he extends y{constructor(){super(...arguments);u(this,"serviceID",_);u(this,"chain","archway");u(this,"contractAddress",{mainnet:"archway1275jwjpktae4y4y0cdq274a2m0jnpekhttnfuljm6n59wnpyd62qppqxq0",testnet:"archway1lr8rstt40s697hqpedv2nvt27f4cuccqwvly9gnvuszxmcevrlns60xw4r"})}async resolve(r,e,n){var h,w,d,l;const s=await this.getCosmWasmClient(((w=(h=n==null?void 0:n.rpcUrls)==null?void 0:h[_])==null?void 0:w[e])??L[e]),[,c]=r.split(".");try{const m=await(s==null?void 0:s.queryContractSmart(this.contractAddress[e],{resolve_record:{name:r}}));if(!(m!=null&&m.address)||((l=(d=n==null?void 0:n.allowedTopLevelDomains)==null?void 0:d.archIds)==null?void 0:l.indexOf(c))===-1)throw new i("",o.NOT_FOUND);return m.address}catch{throw new i("",o.NOT_FOUND)}}async lookup(r,e,n){var h,w,d;const s=await this.getCosmWasmClient(((w=(h=n==null?void 0:n.rpcUrls)==null?void 0:h[_])==null?void 0:w[e])??L[e]),c={prefix:null,words:null};try{const{prefix:l,words:m}=v.decode(r);c.prefix=l,c.words=m}catch{throw new i("",o.INVALID_ADDRESS)}try{const l=await(s==null?void 0:s.queryContractSmart(this.contractAddress[e],{resolve_address:{address:r}}));if(!(l!=null&&l.names)||!((d=l==null?void 0:l.names)!=null&&d.length))throw new i("",o.NOT_FOUND);return l.names.join(", ")}catch{throw new i("",o.NOT_FOUND)}}}const{keccak_256:z}=ee,we=t=>t&&Y.toUnicode(t,{useStd3ASCII:!0}),me=t=>{if(!(t.startsWith("[")&&t.endsWith("]")))throw Error("Expected encoded labelhash to start and end with square brackets");if(t.length!==66)throw Error("Expected encoded labelhash to have a length of 66");return`${t.slice(1,-1)}`},ue=t=>t.startsWith("[")&&t.endsWith("]")&&t.length===66,fe=t=>{let a="";for(let r=0;r<32;r++)a+="00";if(t){const r=t.split(".");for(let e=r.length-1;e>=0;e--){let n;if(ue(r[e]))n=me(r[e]);else{const s=we(r[e]);n=z(s)}a=z(Buffer.from(a+n,"hex"))}}return"0x"+a};function ve(t){if(!t)return[];const a=fe(t);return Array.from(Buffer.from(a.slice(2),"hex"))}const p={inj:{mainnet:"https://tm.injective.network",testnet:"https://testnet.tm.injective.dev"},sei:{mainnet:"https://rpc.wallet.pacific-1.sei.io",testnet:"https://sei-testnet-rpc.polkachu.com"}},B="spaceIds";class ye extends y{constructor(){super(...arguments);u(this,"serviceID",B);u(this,"chain",["injective","sei"]);u(this,"contractAddress",{inj:{mainnet:"inj1x9m0hceug9qylcyrrtwqtytslv2jrph433thgu",testnet:"inj1ppneyx6qfnye26k9mwnf3ngyelvqng67f5v948"},sei:{mainnet:"sei1qujw7gxacyk08fpg0lsf377f727ldq8f9cmjlrxt6awdkag9ypjsdnkh98",testnet:"sei1a59k7mc9hsvtaeu532etl2geqmqdyufjncjkg0h3lxsu5u2rpensanaxwf"}})}async resolve(r,e,n){var s,c,h;try{const[,w]=r.split("."),d=(s=p==null?void 0:p[w])==null?void 0:s[e],l=this.contractAddress[w][e];if(d&&l){const m=await this.getCosmWasmClient(d),f=await(m==null?void 0:m.queryContractSmart(l,{address:{node:ve(r)}}));if(!(f!=null&&f.address)||((h=(c=n==null?void 0:n.allowedTopLevelDomains)==null?void 0:c.spaceIds)==null?void 0:h.indexOf(w))===-1)throw new i("",o.NOT_FOUND);return f==null?void 0:f.address}else throw new i("",o.NOT_FOUND)}catch{throw new i("",o.NOT_FOUND)}}async lookup(r,e){var s;const n={prefix:null,words:null};try{const{prefix:c,words:h}=v.decode(r);n.prefix=c,n.words=h}catch{throw new i("",o.INVALID_ADDRESS)}try{const c=(s=p==null?void 0:p[n.prefix])==null?void 0:s[e],h=this.contractAddress[n.prefix][e];if(c&&h){const w=await this.getCosmWasmClient(c),d=await(w==null?void 0:w.queryContractSmart(h,{name:{address:r.toLowerCase()}}));if(!(d!=null&&d.name))throw new i("",o.NOT_FOUND);return d.name.endsWith(n.prefix)?d.name:d.name+n.prefix}else throw new i("",o.NOT_FOUND)}catch{throw new i("",o.NOT_FOUND)}}}const G="sns",W={mainnet:"https://injective-rpc.publicnode.com:443",testnet:"https://testnet.sentry.tm.injective.network:443"},pe=t=>t.endsWith(".sol")?t.slice(0,-4):t;class ge extends y{constructor(){super(...arguments);u(this,"serviceID",G);u(this,"chain","injective");u(this,"contractAddress",{mainnet:"inj1v7chmgm7vmuwldjt80utmw9c95jkrch979ps8z",testnet:"inj1q79ujqyh72p43mhr2ldaly3x6d50rzp3354at3"})}async resolve(r,e){const n=await this.getCosmWasmClient(W[e]);try{const s=await n.queryContractSmart(this.contractAddress[e],{resolve:{domain_name:pe(r)}});if(!s)throw new i("",o.NOT_FOUND);return s}catch{throw new i("",o.NOT_FOUND)}}async lookup(r,e){var s,c;const n=await this.getCosmWasmClient(W[e]);try{const h=v.decode(r),w=v.fromWords(h.words),d=[...new Array(12).fill(0),...w],l=await n.queryContractSmart(this.contractAddress[e],{get_domains_for_owner:{owner_chain:19,owner_address:d,max_len:1,domain_offset:void 0}});if(!l)throw new i("",o.NOT_FOUND);const m=(c=(s=l==null?void 0:l.domains)==null?void 0:s.pop)==null?void 0:c.call(s);if(!m)throw new i("",o.NOT_FOUND);return m+".sol"}catch{throw new i("",o.NOT_FOUND)}}}const I="bdd",$={mainnet:"https://full-node.mainnet-1.coreum.dev:26657",testnet:"https://full-node.testnet-1.coreum.dev:26657"};class Ne extends y{constructor(){super(...arguments);u(this,"serviceID",I);u(this,"chain","coreum");u(this,"contractAddress",{mainnet:"core1z22n0xy004sxm5w9fms48exwpl3vwqxd890nt8ve0kwjj048tgqstlqf6f",testnet:"testcore1uwe9yemth6gr58tm56sx3u37t0c5rhmk963fjt480y4nz3cfxers9fn2kh"})}async resolve(r,e){const n=await this.getCosmWasmClient($[e]);try{const s=await n.queryContractSmart(this.contractAddress[e],{resolve:{name:r}});if(!s)throw new i("",o.NOT_FOUND);return s}catch{throw new i("",o.NOT_FOUND)}}async lookup(r,e,n){var d,l;const s=await this.getCosmWasmClient(((l=(d=n==null?void 0:n.rpcUrls)==null?void 0:d[I])==null?void 0:l[e])??$[e]),c={prefix:null,words:null};try{const{prefix:m,words:f}=v.decode(r);c.prefix=m,c.words=f}catch{throw new i("",o.INVALID_ADDRESS)}const h=e==="mainnet"?"core":"testcore",w=v.encode(h,c.words);try{const m=await(s==null?void 0:s.queryContractSmart(this.contractAddress[e],{primary:{address:w}}));if(!m)throw new i("",o.NOT_FOUND);return m}catch{throw new i("",o.NOT_FOUND)}}}const H="nibId",De={mainnet:"https://rpc.nibiru.fi:443",testnet:"https://rpc.testnet-2.nibiru.fi:443"},Oe=t=>t.endsWith(".nibi")?t.slice(0,-5):t;class xe extends y{constructor(){super(...arguments);u(this,"serviceID",H);u(this,"chain","nibiru");u(this,"contractAddress",{mainnet:"nibi1q0e70vhrv063eah90mu97sazhywmeegptx642t5px7yfcrf0rrsq2dylen",testnet:""})}async resolve(r,e){const n=await this.getCosmWasmClient(De[e]);if(this.contractAddress[e]=="")throw new i("",o.NOT_FOUND);try{const s=await n.queryContractSmart(this.contractAddress[e],{resolve_record:{name:Oe(r)}});if(s==""||s==null)throw new i("",o.NOT_FOUND);return s==null?void 0:s.address}catch{throw new i("",o.NOT_FOUND)}}async lookup(r,e){throw new i(`Lookup is unavailable for ${r} on ${e}`,o.UNAVAILABLE_METHOD)}}const M="degeNS",V={mainnet:"https://rpc.sei-apis.com:443"};class Ae extends y{constructor(){super(...arguments);u(this,"serviceID",M);u(this,"chain","sei");u(this,"contractAddress",{mainnet:"sei10nulnfpdhx2wf7lp9kqa8aez2yxuyxwjyfw9rzlrexd500nhal0sl7mtzm",testnet:""})}async resolve(r,e){if(e==="testnet")throw new i(`Resolve is unavailable for ${r} on ${e}`,o.UNAVAILABLE_METHOD);const n=await this.getCosmWasmClient(V[e]);if(this.contractAddress[e]=="")throw new i("",o.NOT_FOUND);try{const s=await n.queryContractSmart(this.contractAddress[e],{extension:{msg:{resolves_to:{domain_name:r}}}});if(s==""||s==null)throw new i("",o.NOT_FOUND);return s==null?void 0:s.address}catch{throw new i("",o.NOT_FOUND)}}async lookup(r,e){if(e==="testnet")throw new i(`Lookup is unavailable for ${r} on ${e}`,o.UNAVAILABLE_METHOD);const n=await this.getCosmWasmClient(V[e]);if(this.contractAddress[e]=="")throw new i("",o.NOT_FOUND);try{const s=await n.queryContractSmart(this.contractAddress[e],{extension:{msg:{primary_of:{owner:r}}}});if(s==""||s==null)throw new i("",o.NOT_FOUND);return s==null?void 0:s.domain_name}catch{throw new i("",o.NOT_FOUND)}}}const b=["agoric","akash","arkh","axelar","band","bcna","bitsong","bostrom","cerberus","certik","cheqd","chihuahua","chronic","comdex","cosmos","crc","cre","cro","cudos","darc","decentr","desmos","dig","echelon","emoney","evmos","fetch","firma","galaxy","genesis","gravity","iaa","inj","ixo","juno","kava","ki","like","logos","lum","mantle","mars","meme","micro","mythos","nomic","octa","odin","orai","osmo","panacea","pb","persistence","regen","rizon","secret","sent","sif","somm","star","stars","swth","terra","thor","umee","vdl","kujira","sei","stride","jkl","tori","omniflix","canto","pasg","archway","quasar","neutron","testcore","core","quick","migaloo","kyve","onomy","noble","plq","nolus","c4e","gitopia","nibi","maya","empower","dydx"],_e={icns:b,ibcDomains:b,stargazeNames:b,archIds:["arch"],spaceIds:["inj","sei"],sns:["sol"],nibId:["nibi"],degeNS:["pp","sei"],bdd:["core"]},Se={icns:O,ibcDomains:x,stargazeNames:A,archIds:_,spaceIds:B,sns:G,bdd:I,nibId:H,degeNS:M},Ue=_e;class je{constructor(a){u(this,"services",{});this.network=a,this.network=a,this.registerService(new ie),this.registerService(new de),this.registerService(new le),this.registerService(new he),this.registerService(new ye),this.registerService(new ge),this.registerService(new Ne),this.registerService(new xe),this.registerService(new Ae)}registerService(a){if(this.services[a.serviceID])throw new i("Service already registered",o.DUPLICATE_SERVICE);this.services[a.serviceID]=a}getService(a){const r=this.services[a];if(!r)throw new i("Service not registered",o.UNREGISTERED_SERVICE);return r}listServices(){return Object.keys(this.services)}setNetwork(a){this.network=a}getNetwork(){return this.network}async resolve(a,r,e){return this.getService(r).resolve(a,this.network,e)}async lookup(a,r,e){return this.getService(r).lookup(a,this.network,e)}async resolveAll(a,r){const e={};return await Promise.all(Object.entries(this.services).map(async([n,s])=>{try{const c=await s.resolve(a,this.network,r);e[n]=c}catch{e[n]=null}})),e}async lookupAll(a,r){const e={};return await Promise.all(Object.entries(this.services).map(async([n,s])=>{try{const c=await s.lookup(a,this.network,r);e[n]=c}catch{e[n]=null}})),e}}const Ce=new je("mainnet");exports.allowedTopLevelDomains=Ue;exports.registry=Ce;exports.services=Se; //# sourceMappingURL=index.cjs.map