@ensdomains/ensjs 3.0.0-beta.1 → 3.0.0-beta.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.
Files changed (248) hide show
  1. package/dist/cjs/clients/decorators/subgraph.js.map +1 -1
  2. package/dist/cjs/contracts/consts.js +52 -1
  3. package/dist/cjs/contracts/consts.js.map +1 -1
  4. package/dist/cjs/dns.js +3 -3
  5. package/dist/cjs/dns.js.map +1 -1
  6. package/dist/cjs/errors/subgraph.js.map +1 -1
  7. package/dist/cjs/errors/utils.js +15 -18
  8. package/dist/cjs/errors/utils.js.map +1 -1
  9. package/dist/cjs/errors/version.js +1 -1
  10. package/dist/cjs/functions/dns/{prepareDnsImport.js → getDnsImportData.js} +3 -3
  11. package/dist/cjs/functions/dns/{prepareDnsImport.js.map → getDnsImportData.js.map} +1 -1
  12. package/dist/cjs/functions/dns/importDnsName.js +7 -7
  13. package/dist/cjs/functions/dns/importDnsName.js.map +1 -1
  14. package/dist/cjs/functions/public/_getContentHash.js +1 -1
  15. package/dist/cjs/functions/public/getSupportedInterfaces.js +1 -1
  16. package/dist/cjs/functions/public/getSupportedInterfaces.js.map +1 -1
  17. package/dist/cjs/functions/public/getWrapperData.js.map +1 -1
  18. package/dist/cjs/functions/subgraph/filters.js +3 -0
  19. package/dist/cjs/functions/subgraph/filters.js.map +1 -0
  20. package/dist/cjs/functions/subgraph/getNameHistory.js +1 -1
  21. package/dist/cjs/functions/subgraph/getNamesForAddress.js +140 -182
  22. package/dist/cjs/functions/subgraph/getNamesForAddress.js.map +1 -1
  23. package/dist/cjs/functions/subgraph/getSubnames.js +95 -108
  24. package/dist/cjs/functions/subgraph/getSubnames.js.map +1 -1
  25. package/dist/cjs/functions/subgraph/types.js +3 -0
  26. package/dist/cjs/functions/subgraph/types.js.map +1 -0
  27. package/dist/cjs/functions/subgraph/utils.js.map +1 -1
  28. package/dist/cjs/functions/wallet/createSubname.js +1 -1
  29. package/dist/cjs/functions/wallet/createSubname.js.map +1 -1
  30. package/dist/cjs/functions/wallet/setChildFuses.js +1 -1
  31. package/dist/cjs/functions/wallet/setChildFuses.js.map +1 -1
  32. package/dist/cjs/functions/wallet/setFuses.js +1 -1
  33. package/dist/cjs/functions/wallet/setFuses.js.map +1 -1
  34. package/dist/cjs/functions/wallet/wrapName.js +3 -1
  35. package/dist/cjs/functions/wallet/wrapName.js.map +1 -1
  36. package/dist/cjs/index.js +1 -2
  37. package/dist/cjs/index.js.map +1 -1
  38. package/dist/cjs/utils/contentHash.js +54 -131
  39. package/dist/cjs/utils/contentHash.js.map +1 -1
  40. package/dist/cjs/utils/encoders/encodeSetContentHash.js +1 -4
  41. package/dist/cjs/utils/encoders/encodeSetContentHash.js.map +1 -1
  42. package/dist/cjs/utils/format.js +1 -5
  43. package/dist/cjs/utils/format.js.map +1 -1
  44. package/dist/cjs/utils/fuses.js +181 -200
  45. package/dist/cjs/utils/fuses.js.map +1 -1
  46. package/dist/cjs/utils/index.js +4 -7
  47. package/dist/cjs/utils/index.js.map +1 -1
  48. package/dist/cjs/utils/registerHelpers.js +3 -1
  49. package/dist/cjs/utils/registerHelpers.js.map +1 -1
  50. package/dist/esm/clients/decorators/subgraph.js.map +1 -1
  51. package/dist/esm/contracts/consts.js +52 -1
  52. package/dist/esm/contracts/consts.js.map +1 -1
  53. package/dist/esm/dns.js +1 -1
  54. package/dist/esm/dns.js.map +1 -1
  55. package/dist/esm/errors/subgraph.js.map +1 -1
  56. package/dist/esm/errors/utils.js +13 -16
  57. package/dist/esm/errors/utils.js.map +1 -1
  58. package/dist/esm/errors/version.js +1 -1
  59. package/dist/esm/functions/dns/{prepareDnsImport.js → getDnsImportData.js} +9 -10
  60. package/dist/esm/functions/dns/getDnsImportData.js.map +1 -0
  61. package/dist/esm/functions/dns/importDnsName.js +12 -12
  62. package/dist/esm/functions/dns/importDnsName.js.map +1 -1
  63. package/dist/esm/functions/public/_getContentHash.js +2 -2
  64. package/dist/esm/functions/public/getSupportedInterfaces.js +2 -2
  65. package/dist/esm/functions/public/getSupportedInterfaces.js.map +1 -1
  66. package/dist/esm/functions/public/getWrapperData.js.map +1 -1
  67. package/dist/esm/functions/subgraph/filters.js +2 -0
  68. package/dist/esm/functions/subgraph/filters.js.map +1 -0
  69. package/dist/esm/functions/subgraph/getNameHistory.js +2 -2
  70. package/dist/esm/functions/subgraph/getNamesForAddress.js +144 -183
  71. package/dist/esm/functions/subgraph/getNamesForAddress.js.map +1 -1
  72. package/dist/esm/functions/subgraph/getSubnames.js +101 -111
  73. package/dist/esm/functions/subgraph/getSubnames.js.map +1 -1
  74. package/dist/esm/functions/subgraph/types.js +2 -0
  75. package/dist/esm/functions/subgraph/types.js.map +1 -0
  76. package/dist/esm/functions/subgraph/utils.js.map +1 -1
  77. package/dist/esm/functions/wallet/createSubname.js +1 -1
  78. package/dist/esm/functions/wallet/createSubname.js.map +1 -1
  79. package/dist/esm/functions/wallet/setChildFuses.js +1 -1
  80. package/dist/esm/functions/wallet/setChildFuses.js.map +1 -1
  81. package/dist/esm/functions/wallet/setFuses.js +2 -2
  82. package/dist/esm/functions/wallet/setFuses.js.map +1 -1
  83. package/dist/esm/functions/wallet/wrapName.js +4 -2
  84. package/dist/esm/functions/wallet/wrapName.js.map +1 -1
  85. package/dist/esm/index.js +1 -1
  86. package/dist/esm/index.js.map +1 -1
  87. package/dist/esm/utils/contentHash.js +51 -128
  88. package/dist/esm/utils/contentHash.js.map +1 -1
  89. package/dist/esm/utils/encoders/encodeSetContentHash.js +2 -5
  90. package/dist/esm/utils/encoders/encodeSetContentHash.js.map +1 -1
  91. package/dist/esm/utils/format.js +0 -2
  92. package/dist/esm/utils/format.js.map +1 -1
  93. package/dist/esm/utils/fuses.js +180 -201
  94. package/dist/esm/utils/fuses.js.map +1 -1
  95. package/dist/esm/utils/index.js +2 -2
  96. package/dist/esm/utils/index.js.map +1 -1
  97. package/dist/esm/utils/registerHelpers.js +4 -2
  98. package/dist/esm/utils/registerHelpers.js.map +1 -1
  99. package/dist/types/clients/decorators/subgraph.d.ts +1 -1
  100. package/dist/types/clients/decorators/subgraph.d.ts.map +1 -1
  101. package/dist/types/clients/decorators/wallet.d.ts +12 -12
  102. package/dist/types/clients/public.d.ts +1 -1
  103. package/dist/types/clients/subgraph.d.ts +1 -1
  104. package/dist/types/clients/wallet.d.ts +43 -79
  105. package/dist/types/clients/wallet.d.ts.map +1 -1
  106. package/dist/types/contracts/consts.d.ts +51 -2
  107. package/dist/types/contracts/consts.d.ts.map +1 -1
  108. package/dist/types/dns.d.ts +1 -1
  109. package/dist/types/dns.d.ts.map +1 -1
  110. package/dist/types/errors/subgraph.d.ts +4 -4
  111. package/dist/types/errors/subgraph.d.ts.map +1 -1
  112. package/dist/types/errors/utils.d.ts +10 -13
  113. package/dist/types/errors/utils.d.ts.map +1 -1
  114. package/dist/types/errors/version.d.ts +1 -1
  115. package/dist/types/functions/dns/{prepareDnsImport.d.ts → getDnsImportData.d.ts} +11 -12
  116. package/dist/types/functions/dns/{prepareDnsImport.d.ts.map → getDnsImportData.d.ts.map} +1 -1
  117. package/dist/types/functions/dns/importDnsName.d.ts +36 -36
  118. package/dist/types/functions/dns/importDnsName.d.ts.map +1 -1
  119. package/dist/types/functions/public/getSupportedInterfaces.d.ts +19 -4
  120. package/dist/types/functions/public/getSupportedInterfaces.d.ts.map +1 -1
  121. package/dist/types/functions/public/getWrapperData.d.ts +2 -2
  122. package/dist/types/functions/public/getWrapperData.d.ts.map +1 -1
  123. package/dist/types/functions/subgraph/filters.d.ts +693 -0
  124. package/dist/types/functions/subgraph/filters.d.ts.map +1 -0
  125. package/dist/types/functions/subgraph/getNamesForAddress.d.ts +2 -0
  126. package/dist/types/functions/subgraph/getNamesForAddress.d.ts.map +1 -1
  127. package/dist/types/functions/subgraph/getSubnames.d.ts +3 -1
  128. package/dist/types/functions/subgraph/getSubnames.d.ts.map +1 -1
  129. package/dist/types/functions/subgraph/types.d.ts +13 -0
  130. package/dist/types/functions/subgraph/types.d.ts.map +1 -0
  131. package/dist/types/functions/subgraph/utils.d.ts +2 -2
  132. package/dist/types/functions/subgraph/utils.d.ts.map +1 -1
  133. package/dist/types/functions/wallet/commitName.d.ts +25 -25
  134. package/dist/types/functions/wallet/createSubname.d.ts +28 -28
  135. package/dist/types/functions/wallet/createSubname.d.ts.map +1 -1
  136. package/dist/types/functions/wallet/deleteSubname.d.ts +25 -25
  137. package/dist/types/functions/wallet/registerName.d.ts +24 -24
  138. package/dist/types/functions/wallet/renewNames.d.ts +24 -24
  139. package/dist/types/functions/wallet/setAbiRecord.d.ts +25 -25
  140. package/dist/types/functions/wallet/setAddressRecord.d.ts +25 -25
  141. package/dist/types/functions/wallet/setChildFuses.d.ts +27 -27
  142. package/dist/types/functions/wallet/setChildFuses.d.ts.map +1 -1
  143. package/dist/types/functions/wallet/setContentHashRecord.d.ts +25 -25
  144. package/dist/types/functions/wallet/setFuses.d.ts +27 -27
  145. package/dist/types/functions/wallet/setFuses.d.ts.map +1 -1
  146. package/dist/types/functions/wallet/setPrimaryName.d.ts +25 -25
  147. package/dist/types/functions/wallet/setRecords.d.ts +25 -25
  148. package/dist/types/functions/wallet/setResolver.d.ts +25 -25
  149. package/dist/types/functions/wallet/setTextRecord.d.ts +25 -25
  150. package/dist/types/functions/wallet/transferName.d.ts +25 -25
  151. package/dist/types/functions/wallet/unwrapName.d.ts +25 -25
  152. package/dist/types/functions/wallet/wrapName.d.ts +27 -27
  153. package/dist/types/functions/wallet/wrapName.d.ts.map +1 -1
  154. package/dist/types/index.d.ts +1 -1
  155. package/dist/types/index.d.ts.map +1 -1
  156. package/dist/types/utils/contentHash.d.ts +7 -11
  157. package/dist/types/utils/contentHash.d.ts.map +1 -1
  158. package/dist/types/utils/encoders/encodeSetContentHash.d.ts.map +1 -1
  159. package/dist/types/utils/format.d.ts +0 -2
  160. package/dist/types/utils/format.d.ts.map +1 -1
  161. package/dist/types/utils/fuses.d.ts +164 -125
  162. package/dist/types/utils/fuses.d.ts.map +1 -1
  163. package/dist/types/utils/index.d.ts +2 -2
  164. package/dist/types/utils/index.d.ts.map +1 -1
  165. package/dist/types/utils/registerHelpers.d.ts +2 -2
  166. package/dist/types/utils/registerHelpers.d.ts.map +1 -1
  167. package/package.json +4 -3
  168. package/src/clients/decorators/subgraph.ts +1 -0
  169. package/src/contracts/consts.ts +57 -12
  170. package/src/dns.ts +5 -5
  171. package/src/errors/subgraph.ts +4 -4
  172. package/src/errors/utils.ts +21 -18
  173. package/src/errors/version.ts +1 -1
  174. package/src/functions/dns/{prepareDnsImport.ts → getDnsImportData.ts} +12 -13
  175. package/src/functions/dns/importDnsName.ts +20 -15
  176. package/src/functions/public/_getContentHash.ts +2 -2
  177. package/src/functions/public/getSupportedInterfaces.ts +48 -10
  178. package/src/functions/public/getWrapperData.ts +2 -2
  179. package/src/functions/subgraph/filters.ts +702 -0
  180. package/src/functions/subgraph/getNameHistory.ts +2 -2
  181. package/src/functions/subgraph/getNamesForAddress.ts +170 -186
  182. package/src/functions/subgraph/getSubnames.ts +121 -113
  183. package/src/functions/subgraph/types.ts +13 -0
  184. package/src/functions/subgraph/utils.ts +2 -2
  185. package/src/functions/wallet/createSubname.ts +4 -4
  186. package/src/functions/wallet/setChildFuses.ts +3 -3
  187. package/src/functions/wallet/setFuses.ts +6 -3
  188. package/src/functions/wallet/wrapName.ts +8 -3
  189. package/src/index.ts +0 -1
  190. package/src/utils/contentHash.ts +59 -113
  191. package/src/utils/encoders/encodeSetContentHash.ts +2 -4
  192. package/src/utils/format.ts +0 -6
  193. package/src/utils/fuses.ts +308 -308
  194. package/src/utils/index.ts +4 -5
  195. package/src/utils/registerHelpers.ts +5 -3
  196. package/dist/esm/functions/dns/prepareDnsImport.js.map +0 -1
  197. package/src/@types/@ensdomains/content-hash.d.ts +0 -1
  198. package/src/functions/dns/getDnsOwner.test.ts +0 -195
  199. package/src/functions/dns/importDnsName.test.ts +0 -117
  200. package/src/functions/dns/prepareDnsImport.test.ts +0 -115
  201. package/src/functions/public/batch.test.ts +0 -67
  202. package/src/functions/public/ccip.test.ts +0 -78
  203. package/src/functions/public/getAbiRecord.test.ts +0 -174
  204. package/src/functions/public/getAddressRecord.test.ts +0 -83
  205. package/src/functions/public/getAvailable.test.ts +0 -17
  206. package/src/functions/public/getContentHashRecord.test.ts +0 -28
  207. package/src/functions/public/getExpiry.test.ts +0 -48
  208. package/src/functions/public/getName.test.ts +0 -66
  209. package/src/functions/public/getOwner.test.ts +0 -87
  210. package/src/functions/public/getPrice.test.ts +0 -45
  211. package/src/functions/public/getRecords.test.ts +0 -49
  212. package/src/functions/public/getResolver.test.ts +0 -12
  213. package/src/functions/public/getTextRecord.test.ts +0 -20
  214. package/src/functions/public/getWrapperData.test.ts +0 -79
  215. package/src/functions/public/getWrapperName.test.ts +0 -19
  216. package/src/functions/subgraph/client.test.ts +0 -170
  217. package/src/functions/subgraph/getDecodedName.test.ts +0 -31
  218. package/src/functions/subgraph/getNameHistory.test.ts +0 -39
  219. package/src/functions/subgraph/getNamesForAddress.test.ts +0 -244
  220. package/src/functions/subgraph/getSubgraphRecords.test.ts +0 -74
  221. package/src/functions/subgraph/getSubgraphRegistrant.test.ts +0 -34
  222. package/src/functions/subgraph/getSubnames.test.ts +0 -202
  223. package/src/functions/wallet/commitName.test.ts +0 -58
  224. package/src/functions/wallet/createSubname.test.ts +0 -73
  225. package/src/functions/wallet/deleteSubname.test.ts +0 -150
  226. package/src/functions/wallet/registerName.test.ts +0 -81
  227. package/src/functions/wallet/renewNames.test.ts +0 -92
  228. package/src/functions/wallet/setAbiRecord.test.ts +0 -156
  229. package/src/functions/wallet/setAddressRecord.test.ts +0 -121
  230. package/src/functions/wallet/setChildFuses.test.ts +0 -97
  231. package/src/functions/wallet/setContentHashRecord.test.ts +0 -69
  232. package/src/functions/wallet/setFuses.test.ts +0 -287
  233. package/src/functions/wallet/setPrimaryName.test.ts +0 -71
  234. package/src/functions/wallet/setRecords.test.ts +0 -127
  235. package/src/functions/wallet/setResolver.test.ts +0 -114
  236. package/src/functions/wallet/setTextRecord.test.ts +0 -67
  237. package/src/functions/wallet/transferName.test.ts +0 -201
  238. package/src/functions/wallet/unwrapName.test.ts +0 -93
  239. package/src/functions/wallet/wrapName.test.ts +0 -195
  240. package/src/utils/generateRecordCallArray.test.ts +0 -84
  241. package/src/utils/labels.test.ts +0 -163
  242. package/src/utils/makeLabelNodeAndParent.test.ts +0 -11
  243. package/src/utils/makeSafeSecondsDate.test.ts +0 -14
  244. package/src/utils/normalise.test.ts +0 -35
  245. package/src/utils/ownerFromContract.test.ts +0 -52
  246. package/src/utils/registerHelpers.test.ts +0 -159
  247. package/src/utils/validation.test.ts +0 -170
  248. package/src/utils/wrapper.test.ts +0 -46
@@ -1,9 +1,11 @@
1
+ /* eslint-disable @typescript-eslint/naming-convention */
1
2
  import { gql } from 'graphql-request'
2
3
  import type { ClientWithEns } from '../../contracts/consts.js'
3
4
  import { InvalidOrderByError } from '../../errors/subgraph.js'
4
- import { GRACE_PERIOD_SECONDS } from '../../utils/consts.js'
5
+ import { EMPTY_ADDRESS, GRACE_PERIOD_SECONDS } from '../../utils/consts.js'
5
6
  import { namehash } from '../../utils/normalise.js'
6
7
  import { createSubgraphClient } from './client.js'
8
+ import type { DomainFilter } from './filters.js'
7
9
  import {
8
10
  domainDetailsWithoutParentFragment,
9
11
  registrationDetailsFragment,
@@ -21,6 +23,8 @@ export type GetSubnamesParameters = {
21
23
  searchString?: string
22
24
  /** Allows expired names to be included (default: false) */
23
25
  allowExpired?: boolean
26
+ /** Allows deleted names to be included (default: false) */
27
+ allowDeleted?: boolean
24
28
  /** Parameter to order names by (default: name) */
25
29
  orderBy?: GetSubnamesOrderBy
26
30
  /** Direction to order names in (default: asc) */
@@ -39,6 +43,71 @@ type SubgraphResult = {
39
43
  }
40
44
  }
41
45
 
46
+ const getOrderByFilter = ({
47
+ name,
48
+ orderBy,
49
+ orderDirection,
50
+ previousPage,
51
+ }: Required<
52
+ Pick<
53
+ GetSubnamesParameters,
54
+ 'name' | 'orderBy' | 'orderDirection' | 'previousPage'
55
+ >
56
+ >): DomainFilter => {
57
+ const lastDomain = previousPage[previousPage.length - 1]
58
+ const operator = orderDirection === 'asc' ? 'gt' : 'lt'
59
+
60
+ switch (orderBy) {
61
+ case 'expiryDate': {
62
+ let lastExpiryDate = lastDomain.expiryDate?.value
63
+ ? lastDomain.expiryDate.value / 1000
64
+ : 0
65
+ if (name === 'eth' && lastExpiryDate) {
66
+ lastExpiryDate += GRACE_PERIOD_SECONDS
67
+ }
68
+
69
+ if (orderDirection === 'asc' && lastExpiryDate === 0) {
70
+ return {
71
+ and: [{ expiryDate: null }, { [`id_${operator}`]: lastDomain.id }],
72
+ }
73
+ }
74
+ if (orderDirection === 'desc' && lastExpiryDate !== 0) {
75
+ return {
76
+ [`expiryDate_${operator}`]: `${lastExpiryDate}`,
77
+ }
78
+ }
79
+ return {
80
+ or: [
81
+ {
82
+ [`expiryDate_${operator}`]: `${lastExpiryDate}`,
83
+ },
84
+ { expiryDate: null },
85
+ ],
86
+ }
87
+ }
88
+ case 'name': {
89
+ return {
90
+ [`name_${operator}`]: lastDomain.name ?? '',
91
+ }
92
+ }
93
+ case 'labelName': {
94
+ return {
95
+ [`labelName_${operator}`]: lastDomain.labelName ?? '',
96
+ }
97
+ }
98
+ case 'createdAt': {
99
+ return {
100
+ [`createdAt_${operator}`]: `${lastDomain.createdAt.value / 1000}`,
101
+ }
102
+ }
103
+ default:
104
+ throw new InvalidOrderByError({
105
+ orderBy: orderBy || '<no orderBy provided>',
106
+ supportedOrderBys: ['expiryDate', 'name', 'labelName', 'createdAt'],
107
+ })
108
+ }
109
+ }
110
+
42
111
  /**
43
112
  * Gets the subnames for a name from the subgraph.
44
113
  * @param client - {@link ClientWithEns}
@@ -62,6 +131,7 @@ const getSubnames = async (
62
131
  name,
63
132
  searchString,
64
133
  allowExpired = false,
134
+ allowDeleted = false,
65
135
  orderBy = 'name',
66
136
  orderDirection = 'asc',
67
137
  pageSize = 100,
@@ -70,119 +140,68 @@ const getSubnames = async (
70
140
  ): Promise<GetSubnamesReturnType> => {
71
141
  const subgraphClient = createSubgraphClient({ client })
72
142
 
73
- const whereFilters: string[] = []
74
-
75
- let orderByFilter = ''
76
- let orderByStringVar = ''
77
-
78
- if (previousPage && previousPage.length > 0) {
79
- const lastDomain = previousPage[previousPage.length - 1]
80
- const operator = orderDirection === 'asc' ? 'gt' : 'lt'
81
- switch (orderBy) {
82
- case 'expiryDate': {
83
- let lastExpiryDate = lastDomain.expiryDate?.value
84
- ? lastDomain.expiryDate.value / 1000
85
- : 0
86
- if (name === 'eth' && lastExpiryDate) {
87
- lastExpiryDate += GRACE_PERIOD_SECONDS
88
- }
89
- if (orderDirection === 'asc' && lastExpiryDate === 0) {
90
- orderByFilter = `
91
- {
92
- and: [
93
- { expiryDate: null }
94
- { id_${operator}: "${lastDomain.id}" }
95
- ]
96
- }
97
- `
98
- } else if (orderDirection === 'desc' && lastExpiryDate !== 0) {
99
- orderByFilter = `
100
- {
101
- expiryDate_${operator}: ${lastExpiryDate}
102
- }
103
- `
104
- } else {
105
- orderByFilter = `
106
- {
107
- or: [
108
- {
109
- expiryDate_${operator}: ${lastExpiryDate}
110
- }
111
- { expiryDate: null }
112
- ]
113
- }
114
- `
115
- }
116
- break
117
- }
118
- case 'name': {
119
- orderByFilter = `
120
- {
121
- name_${operator}: $orderByStringVar
122
- }
123
- `
124
- orderByStringVar = lastDomain.name ?? ''
125
- break
126
- }
127
- case 'labelName': {
128
- orderByFilter = `
129
- {
130
- labelName_${operator}: $orderByStringVar
131
- }
132
- `
133
- orderByStringVar = lastDomain.labelName ?? ''
134
- break
135
- }
136
- case 'createdAt': {
137
- orderByFilter = `
138
- {
139
- createdAt_${operator}: ${lastDomain.createdAt.value / 1000}
140
- }
141
- `
142
- break
143
- }
144
- default:
145
- throw new InvalidOrderByError({
146
- orderBy,
147
- supportedOrderBys: ['expiryDate', 'name', 'labelName', 'createdAt'],
148
- })
149
- }
150
- whereFilters.push(orderByFilter)
143
+ const whereFilters: DomainFilter[] = []
144
+
145
+ if (previousPage?.length) {
146
+ whereFilters.push(
147
+ getOrderByFilter({
148
+ name,
149
+ orderBy,
150
+ orderDirection,
151
+ previousPage,
152
+ }),
153
+ )
151
154
  }
152
155
 
153
156
  if (!allowExpired) {
154
157
  // Exclude domains that are expired
155
158
  // if expiryDate is null, there is no expiry on the domain (registration or wrapped)
156
- whereFilters.push(`
157
- {
158
- or: [
159
- { expiryDate_gt: $expiryDate }
160
- { expiryDate: null }
161
- ]
162
- }
163
- `)
159
+ whereFilters.push({
160
+ or: [
161
+ { expiryDate_gt: `${Math.floor(Date.now() / 1000)}` },
162
+ { expiryDate: null },
163
+ ],
164
+ })
165
+ }
166
+
167
+ if (!allowDeleted) {
168
+ // exclude "deleted" domains
169
+ // when owner/resolver/registrant = null
170
+ whereFilters.push({
171
+ or: [
172
+ {
173
+ owner_not: EMPTY_ADDRESS,
174
+ },
175
+ {
176
+ resolver_not: null,
177
+ },
178
+ ...(name.toLowerCase() === 'eth'
179
+ ? [
180
+ {
181
+ registrant_not: EMPTY_ADDRESS,
182
+ },
183
+ ]
184
+ : []),
185
+ ],
186
+ })
164
187
  }
165
188
 
166
189
  if (searchString) {
167
190
  // using labelName_contains instead of name_contains because name_contains
168
191
  // includes the parent name
169
- whereFilters.push(`
170
- {
171
- labelName_contains: $searchString
172
- }
173
- `)
192
+ whereFilters.push({
193
+ labelName_contains: searchString,
194
+ })
174
195
  }
175
196
 
176
- let whereFilter = ''
197
+ let whereFilter: DomainFilter = {}
177
198
 
178
199
  if (whereFilters.length > 1) {
179
- whereFilter = `
180
- and: [
181
- ${whereFilters.join('\n')}
182
- ]
183
- `
200
+ whereFilter = {
201
+ and: whereFilters,
202
+ }
184
203
  } else if (whereFilters.length === 1) {
185
- whereFilter = whereFilters[0].replace(/{(.*)}/gs, '$1')
204
+ ;[whereFilter] = whereFilters
186
205
  }
187
206
 
188
207
  const query = gql`
@@ -190,24 +209,15 @@ const getSubnames = async (
190
209
  $id: String!
191
210
  $orderBy: Domain_orderBy
192
211
  $orderDirection: OrderDirection
212
+ $whereFilter: Domain_filter
193
213
  $first: Int
194
- $expiryDate: Int
195
- $searchString: String
196
- $orderByStringVar: String
197
214
  ) {
198
215
  domain(id: $id) {
199
216
  subdomains(
200
217
  orderBy: $orderBy
201
218
  orderDirection: $orderDirection
202
219
  first: $first
203
- ${
204
- whereFilter &&
205
- `
206
- where: {
207
- ${whereFilter}
208
- }
209
- `
210
- }
220
+ where: $whereFilter
211
221
  ) {
212
222
  ...DomainDetailsWithoutParent
213
223
  registration {
@@ -229,9 +239,7 @@ const getSubnames = async (
229
239
  orderBy,
230
240
  orderDirection,
231
241
  first: pageSize,
232
- expiryDate: Math.floor(Date.now() / 1000),
233
- searchString,
234
- orderByStringVar,
242
+ whereFilter,
235
243
  }
236
244
 
237
245
  const result = await subgraphClient.request<SubgraphResult, typeof queryVars>(
@@ -0,0 +1,13 @@
1
+ import type { Hex } from 'viem'
2
+
3
+ export type InputMaybe<T> = T | null
4
+ /** All built-in and custom scalars, mapped to their actual values */
5
+ export type Scalars = {
6
+ ID: string
7
+ String: string
8
+ Boolean: boolean
9
+ Int: number
10
+ Float: number
11
+ Bytes: Hex
12
+ BigInt: string
13
+ }
@@ -1,7 +1,7 @@
1
1
  import { getAddress, type Address, type Hex } from 'viem'
2
2
  import type { DateWithValue } from '../../types.js'
3
3
  import { truncateFormat } from '../../utils/format.js'
4
- import { decodeFuses, type AllCurrentFuses } from '../../utils/fuses.js'
4
+ import { decodeFuses, type DecodedFuses } from '../../utils/fuses.js'
5
5
  import { decryptName } from '../../utils/labels.js'
6
6
  import type { SubgraphDomain } from './fragments.js'
7
7
 
@@ -27,7 +27,7 @@ export type Name = {
27
27
  /** Expiry date of name */
28
28
  expiryDate: DateWithValue<number> | null
29
29
  /** Fuse values for name */
30
- fuses: AllCurrentFuses | null
30
+ fuses: DecodedFuses | null
31
31
  /** Owner address */
32
32
  owner: Address
33
33
  /** Registrant address */
@@ -20,7 +20,7 @@ import type {
20
20
  SimpleTransactionRequest,
21
21
  WriteTransactionParameters,
22
22
  } from '../../types.js'
23
- import { encodeFuses, type CombinedFuseInput } from '../../utils/fuses.js'
23
+ import { encodeFuses, type EncodeFusesInputObject } from '../../utils/fuses.js'
24
24
  import { getNameType } from '../../utils/getNameType.js'
25
25
  import { makeLabelNodeAndParent } from '../../utils/makeLabelNodeAndParent.js'
26
26
  import {
@@ -41,7 +41,7 @@ type BaseCreateSubnameDataParameters = {
41
41
  /** Expiry to set (only on NameWrapper) */
42
42
  expiry?: AnyDate
43
43
  /** Fuses to set (only on NameWrapper) */
44
- fuses?: CombinedFuseInput
44
+ fuses?: EncodeFusesInputObject
45
45
  }
46
46
 
47
47
  type RegistryCreateSubnameDataParameters = {
@@ -53,7 +53,7 @@ type RegistryCreateSubnameDataParameters = {
53
53
  type NameWrapperCreateSubnameDataParameters = {
54
54
  contract: 'nameWrapper'
55
55
  expiry?: AnyDate
56
- fuses?: CombinedFuseInput
56
+ fuses?: EncodeFusesInputObject
57
57
  }
58
58
 
59
59
  export type CreateSubnameDataParameters = BaseCreateSubnameDataParameters &
@@ -119,7 +119,7 @@ export const makeFunctionData = <
119
119
  }
120
120
  case 'nameWrapper': {
121
121
  wrappedLabelLengthCheck(label)
122
- const generatedFuses = fuses ? encodeFuses(fuses) : 0
122
+ const generatedFuses = fuses ? encodeFuses({ input: fuses }) : 0
123
123
  const generatedExpiry = expiry ? expiryToBigInt(expiry) : MAX_EXPIRY
124
124
  return {
125
125
  to: getChainContractAddress({
@@ -14,14 +14,14 @@ import type {
14
14
  SimpleTransactionRequest,
15
15
  WriteTransactionParameters,
16
16
  } from '../../types.js'
17
- import { encodeFuses, type CombinedFuseInput } from '../../utils/fuses.js'
17
+ import { encodeFuses, type EncodeFusesInputObject } from '../../utils/fuses.js'
18
18
  import { namehash } from '../../utils/normalise.js'
19
19
 
20
20
  export type SetChildFusesDataParameters = {
21
21
  /** Name to set child fuses for */
22
22
  name: string
23
23
  /** Fuse object or number value to set to */
24
- fuses: Partial<CombinedFuseInput> | number
24
+ fuses: EncodeFusesInputObject
25
25
  /** Expiry to set for fuses */
26
26
  expiry?: number | bigint
27
27
  }
@@ -46,7 +46,7 @@ export const makeFunctionData = <
46
46
  wallet: WalletWithEns<Transport, TChain, TAccount>,
47
47
  { name, fuses, expiry }: SetChildFusesDataParameters,
48
48
  ): SetChildFusesDataReturnType => {
49
- const encodedFuses = encodeFuses(fuses)
49
+ const encodedFuses = encodeFuses({ input: fuses })
50
50
  const labels = name.split('.')
51
51
  const labelHash = labelhash(labels.shift()!)
52
52
  const parentNode = namehash(labels.join('.'))
@@ -13,14 +13,17 @@ import type {
13
13
  SimpleTransactionRequest,
14
14
  WriteTransactionParameters,
15
15
  } from '../../types.js'
16
- import { encodeFuses, type CombinedFuseInput } from '../../utils/fuses.js'
16
+ import {
17
+ encodeFuses,
18
+ type EncodeChildFusesInputObject,
19
+ } from '../../utils/fuses.js'
17
20
  import { namehash } from '../../utils/normalise.js'
18
21
 
19
22
  export type SetFusesDataParameters = {
20
23
  /** Name to set fuses for */
21
24
  name: string
22
25
  /** Fuse object to set to */
23
- fuses: Prettify<CombinedFuseInput['child']>
26
+ fuses: EncodeChildFusesInputObject
24
27
  }
25
28
 
26
29
  export type SetFusesDataReturnType = SimpleTransactionRequest
@@ -43,7 +46,7 @@ export const makeFunctionData = <
43
46
  wallet: WalletWithEns<Transport, TChain, TAccount>,
44
47
  { name, fuses }: SetFusesDataParameters,
45
48
  ): SetFusesDataReturnType => {
46
- const encodedFuses = encodeFuses(fuses, 'child')
49
+ const encodedFuses = encodeFuses({ restriction: 'child', input: fuses })
47
50
  return {
48
51
  to: getChainContractAddress({ client: wallet, contract: 'ensNameWrapper' }),
49
52
  data: encodeFunctionData({
@@ -22,7 +22,10 @@ import type {
22
22
  SimpleTransactionRequest,
23
23
  WriteTransactionParameters,
24
24
  } from '../../types.js'
25
- import { encodeFuses, type CombinedFuseInput } from '../../utils/fuses.js'
25
+ import {
26
+ encodeFuses,
27
+ type EncodeChildFusesInputObject,
28
+ } from '../../utils/fuses.js'
26
29
  import { packetToBytes } from '../../utils/hexEncodedName.js'
27
30
  import { checkIsDotEth } from '../../utils/validation.js'
28
31
  import { wrappedLabelLengthCheck } from '../../utils/wrapper.js'
@@ -37,7 +40,7 @@ export type WrapNameDataParameters<
37
40
  newOwnerAddress: Address
38
41
  /** Fuses to set on wrap (eth-2ld only) */
39
42
  fuses?: TNameOption extends Eth2ldNameSpecifier
40
- ? CombinedFuseInput['child']
43
+ ? EncodeChildFusesInputObject
41
44
  : never
42
45
  /** The resolver address to set on wrap */
43
46
  resolverAddress?: Address
@@ -83,7 +86,9 @@ export const makeFunctionData = <
83
86
 
84
87
  if (isEth2ld) {
85
88
  wrappedLabelLengthCheck(labels[0])
86
- const encodedFuses = fuses ? encodeFuses(fuses, 'child') : 0
89
+ const encodedFuses = fuses
90
+ ? encodeFuses({ restriction: 'child', input: fuses })
91
+ : 0
87
92
  const tokenId = BigInt(labelhash(labels[0]))
88
93
 
89
94
  const data = encodeAbiParameters(
package/src/index.ts CHANGED
@@ -59,7 +59,6 @@ export {
59
59
  FusesInvalidFuseObjectError,
60
60
  FusesInvalidNamedFuseError,
61
61
  FusesInvalidUnnamedFuseError,
62
- FusesNonIntegerError,
63
62
  FusesOutOfRangeError,
64
63
  FusesRestrictionNotAllowedError,
65
64
  FusesValueRequiredError,
@@ -1,5 +1,11 @@
1
- import contentHash from '@ensdomains/content-hash'
1
+ import {
2
+ decode,
3
+ encode,
4
+ getCodec,
5
+ type Codec as InternalCodec,
6
+ } from '@ensdomains/content-hash'
2
7
  import { isHex, type Hex } from 'viem'
8
+ import { InvalidContentHashError } from '../errors/utils.js'
3
9
 
4
10
  export type ProtocolType =
5
11
  | 'ipfs'
@@ -16,16 +22,6 @@ export type DecodedContentHash = {
16
22
  decoded: string
17
23
  }
18
24
 
19
- const supportedCodecs = [
20
- 'ipns-ns',
21
- 'ipfs-ns',
22
- 'swarm-ns',
23
- 'onion',
24
- 'onion3',
25
- 'skynet-ns',
26
- 'arweave-ns',
27
- ]
28
-
29
25
  function matchProtocol(text: string) {
30
26
  return (
31
27
  text.match(/^(ipfs|sia|ipns|bzz|onion|onion3|arweave|ar):\/\/(.*)/) ||
@@ -34,117 +30,67 @@ function matchProtocol(text: string) {
34
30
  )
35
31
  }
36
32
 
37
- export function decodeContenthash(encoded: Hex): DecodedContentHash | null {
33
+ const getDisplayCodec = (encoded: string): ProtocolType => {
34
+ const codec = getCodec(encoded)
35
+ switch (codec) {
36
+ case 'ipfs':
37
+ case 'ipns':
38
+ case 'onion':
39
+ case 'onion3':
40
+ return codec
41
+ case 'swarm':
42
+ return 'bzz'
43
+ case 'skynet':
44
+ return 'sia'
45
+ case 'arweave':
46
+ return 'ar'
47
+ default:
48
+ return null
49
+ }
50
+ }
51
+
52
+ const getInternalCodec = (
53
+ displayCodec: NonNullable<ProtocolType>,
54
+ ): InternalCodec => {
55
+ switch (displayCodec) {
56
+ case 'bzz':
57
+ return 'swarm'
58
+ case 'sia':
59
+ return 'skynet'
60
+ case 'ar':
61
+ return 'arweave'
62
+ default:
63
+ return displayCodec
64
+ }
65
+ }
66
+
67
+ export function decodeContentHash(encoded: Hex): DecodedContentHash | null {
38
68
  if (!encoded || encoded === '0x') {
39
69
  return null
40
70
  }
41
- let decoded = contentHash.decode(encoded)
42
- let protocolType: ProtocolType = null
43
- const codec = contentHash.getCodec(encoded)
44
- if (codec === 'ipfs-ns') {
45
- protocolType = 'ipfs'
46
- } else if (codec === 'ipns-ns') {
47
- protocolType = 'ipns'
48
- } else if (codec === 'swarm-ns') {
49
- protocolType = 'bzz'
50
- } else if (codec === 'onion') {
51
- protocolType = 'onion'
52
- } else if (codec === 'onion3') {
53
- protocolType = 'onion3'
54
- } else if (codec === 'skynet-ns') {
55
- protocolType = 'sia'
56
- } else if (codec === 'arweave-ns') {
57
- protocolType = 'ar'
58
- } else {
59
- decoded = encoded
60
- }
71
+ const decoded = decode(encoded)
72
+ const protocolType = getDisplayCodec(encoded)
61
73
  return { protocolType, decoded }
62
74
  }
63
75
 
64
- export function validateContent(encoded: any) {
65
- return (
66
- contentHash.isHashOfType(encoded, contentHash.Types.ipfs) ||
67
- contentHash.isHashOfType(encoded, contentHash.Types.swarm)
68
- )
76
+ export function isValidContentHash(encoded: unknown) {
77
+ if (typeof encoded !== 'string') return false
78
+ const codec = getCodec(encoded)
79
+ return Boolean(codec && isHex(encoded))
69
80
  }
70
81
 
71
- export function isValidContenthash(encoded: any) {
72
- try {
73
- const codec = contentHash.getCodec(encoded)
74
- return isHex(encoded) && supportedCodecs.includes(codec)
75
- } catch (e) {
76
- console.log(e)
77
- }
78
- return false
82
+ export function getProtocolType(encoded: string) {
83
+ const matched = matchProtocol(encoded)
84
+ if (!matched) return null
85
+ const [, protocolType, decoded] = matched
86
+ return { protocolType: protocolType as NonNullable<ProtocolType>, decoded }
79
87
  }
80
88
 
81
- export function getProtocolType(encoded: any) {
82
- let protocolType
83
- let decoded
84
- try {
85
- const matched = matchProtocol(encoded)
86
- if (matched) {
87
- ;[, protocolType, decoded] = matched
88
- }
89
- return {
90
- protocolType,
91
- decoded,
92
- }
93
- } catch (e) {
94
- console.log(e)
95
- }
96
- return
97
- }
89
+ export function encodeContentHash(text: string): Hex {
90
+ const typeData = getProtocolType(text)
91
+ if (!typeData) throw new InvalidContentHashError()
98
92
 
99
- export function encodeContenthash(text: string) {
100
- let content = text
101
- let contentType
102
- let encoded: string | boolean = false
103
- let error
104
- if (text) {
105
- const matched = matchProtocol(text)
106
- if (matched) {
107
- ;[, contentType, content] = matched
108
- }
109
- try {
110
- if (contentType === 'ipfs') {
111
- if (content.length >= 4) {
112
- encoded = `0x${contentHash.encode('ipfs-ns', content)}`
113
- }
114
- } else if (contentType === 'ipns') {
115
- encoded = `0x${contentHash.encode('ipns-ns', content)}`
116
- } else if (contentType === 'bzz') {
117
- if (content.length >= 4) {
118
- encoded = `0x${contentHash.fromSwarm(content)}`
119
- }
120
- } else if (contentType === 'onion') {
121
- if (content.length === 16) {
122
- encoded = `0x${contentHash.encode('onion', content)}`
123
- }
124
- } else if (contentType === 'onion3') {
125
- if (content.length === 56) {
126
- encoded = `0x${contentHash.encode('onion3', content)}`
127
- }
128
- } else if (contentType === 'sia') {
129
- if (content.length === 46) {
130
- encoded = `0x${contentHash.encode('skynet-ns', content)}`
131
- }
132
- } else if (contentType === 'arweave' || contentType === 'ar') {
133
- if (content.length === 43) {
134
- encoded = `0x${contentHash.encode('arweave-ns', content)}`
135
- }
136
- } else {
137
- console.warn('Unsupported protocol or invalid value', {
138
- contentType,
139
- text,
140
- })
141
- }
142
- } catch (err) {
143
- const errorMessage = 'Error encoding content hash'
144
- console.warn(errorMessage, { text, encoded })
145
- error = errorMessage
146
- // throw 'Error encoding content hash'
147
- }
148
- }
149
- return { encoded, error }
93
+ const internalCodec = getInternalCodec(typeData.protocolType)
94
+
95
+ return `0x${encode(internalCodec, typeData.decoded)}`
150
96
  }
@@ -1,6 +1,6 @@
1
1
  import { encodeFunctionData, type Hex } from 'viem'
2
2
  import { publicResolverSetContenthashSnippet } from '../../contracts/publicResolver.js'
3
- import { encodeContenthash } from '../contentHash.js'
3
+ import { encodeContentHash } from '../contentHash.js'
4
4
 
5
5
  export type EncodeSetContentHashParameters = {
6
6
  namehash: Hex
@@ -15,9 +15,7 @@ export const encodeSetContentHash = ({
15
15
  }: EncodeSetContentHashParameters): EncodeSetContentHashReturnType => {
16
16
  let encodedHash: Hex = '0x'
17
17
  if (contentHash) {
18
- const encodedObject = encodeContenthash(contentHash)
19
- if (encodedObject.error) throw new Error(encodedObject.error)
20
- encodedHash = encodedObject.encoded as Hex
18
+ encodedHash = encodeContentHash(contentHash)
21
19
  }
22
20
  return encodeFunctionData({
23
21
  abi: publicResolverSetContenthashSnippet,