@ensdomains/ensjs 3.0.0-alpha.35 → 3.0.0-alpha.36

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.
@@ -303,9 +303,9 @@ const getNames = async ({ gqlInstance }, {
303
303
  const { account } = await client.request(finalQuery, queryVars);
304
304
  if (type === "all") {
305
305
  return [
306
- ...account.domains.map(mapDomain),
307
- ...account.registrations.map(mapRegistration),
308
- ...account.wrappedDomains.map(mapWrappedDomain)
306
+ ...account?.domains.map(mapDomain) || [],
307
+ ...account?.registrations.map(mapRegistration) || [],
308
+ ...account?.wrappedDomains.map(mapWrappedDomain) || []
309
309
  ].sort((a, b) => {
310
310
  if (orderDirection === "desc") {
311
311
  if (orderBy === "labelName") {
@@ -320,11 +320,11 @@ const getNames = async ({ gqlInstance }, {
320
320
  });
321
321
  }
322
322
  if (type === "owner") {
323
- return account.domains.map(mapDomain);
323
+ return account?.domains.map(mapDomain) || [];
324
324
  }
325
325
  if (type === "wrappedOwner") {
326
- return account.wrappedDomains.map(mapWrappedDomain);
326
+ return account?.wrappedDomains.map(mapWrappedDomain) || [];
327
327
  }
328
- return account.registrations.map(mapRegistration);
328
+ return account?.registrations.map(mapRegistration) || [];
329
329
  };
330
330
  var getNames_default = getNames;
@@ -202,34 +202,45 @@ const getDataForName = async ({
202
202
  );
203
203
  }
204
204
  } else {
205
- const resolvedData = await universalResolver["resolve(bytes,bytes[])"](
206
- (0, import_hexEncodedName.hexEncodeName)(name),
207
- data,
208
- {
209
- ccipReadEnabled: true
210
- }
211
- );
212
- recordData = [...resolvedData["0"]];
213
- resolverAddress = resolvedData["1"];
214
- for (let i = 0; i < recordData.length; i += 1) {
215
- if (recordData[i].startsWith("0x0d1947a9")) {
216
- calls[i] = null;
217
- recordData[i] = null;
205
+ try {
206
+ const resolvedData = await universalResolver["resolve(bytes,bytes[])"](
207
+ (0, import_hexEncodedName.hexEncodeName)(name),
208
+ data,
209
+ {
210
+ ccipReadEnabled: true
211
+ }
212
+ );
213
+ recordData = [...resolvedData["0"]];
214
+ resolverAddress = resolvedData["1"];
215
+ for (let i = 0; i < recordData.length; i += 1) {
216
+ if (recordData[i].startsWith("0x0d1947a9")) {
217
+ calls[i] = null;
218
+ recordData[i] = null;
219
+ }
218
220
  }
221
+ } catch {
222
+ const registryContract = await contracts?.getRegistry();
223
+ resolverAddress = await registryContract?.resolver((0, import_normalise.namehash)(name));
224
+ return {
225
+ address: void 0,
226
+ records: {},
227
+ resolverAddress,
228
+ isInvalidResolverAddress: true
229
+ };
219
230
  }
220
231
  }
221
232
  if (!resolverAddress || !recordData || (0, import_utils.hexStripZeros)(resolverAddress) === "0x") {
222
233
  return {
223
- address: null,
234
+ address: void 0,
224
235
  records: {},
225
- resolverAddress: null
236
+ resolverAddress: void 0
226
237
  };
227
238
  }
228
239
  const filteredCalls = calls.filter((x) => x);
229
240
  const filteredRecordData = recordData.filter((x) => x);
230
241
  const matchAddress = filteredRecordData[filteredCalls.findIndex((x) => x.key === "60")];
231
242
  return {
232
- address: matchAddress && await _getAddr.decode(matchAddress),
243
+ address: matchAddress && await _getAddr.decode(matchAddress).catch(() => false),
233
244
  records: await formatRecords(
234
245
  { _getAddr, _getContentHash, _getText },
235
246
  filteredRecordData,
@@ -281,9 +281,9 @@ var getNames = async ({ gqlInstance }, {
281
281
  const { account } = await client.request(finalQuery, queryVars);
282
282
  if (type === "all") {
283
283
  return [
284
- ...account.domains.map(mapDomain),
285
- ...account.registrations.map(mapRegistration),
286
- ...account.wrappedDomains.map(mapWrappedDomain)
284
+ ...account?.domains.map(mapDomain) || [],
285
+ ...account?.registrations.map(mapRegistration) || [],
286
+ ...account?.wrappedDomains.map(mapWrappedDomain) || []
287
287
  ].sort((a, b) => {
288
288
  if (orderDirection === "desc") {
289
289
  if (orderBy === "labelName") {
@@ -298,12 +298,12 @@ var getNames = async ({ gqlInstance }, {
298
298
  });
299
299
  }
300
300
  if (type === "owner") {
301
- return account.domains.map(mapDomain);
301
+ return account?.domains.map(mapDomain) || [];
302
302
  }
303
303
  if (type === "wrappedOwner") {
304
- return account.wrappedDomains.map(mapWrappedDomain);
304
+ return account?.wrappedDomains.map(mapWrappedDomain) || [];
305
305
  }
306
- return account.registrations.map(mapRegistration);
306
+ return account?.registrations.map(mapRegistration) || [];
307
307
  };
308
308
  var getNames_default = getNames;
309
309
  export {
@@ -180,34 +180,45 @@ var getDataForName = async ({
180
180
  );
181
181
  }
182
182
  } else {
183
- const resolvedData = await universalResolver["resolve(bytes,bytes[])"](
184
- hexEncodeName(name),
185
- data,
186
- {
187
- ccipReadEnabled: true
188
- }
189
- );
190
- recordData = [...resolvedData["0"]];
191
- resolverAddress = resolvedData["1"];
192
- for (let i = 0; i < recordData.length; i += 1) {
193
- if (recordData[i].startsWith("0x0d1947a9")) {
194
- calls[i] = null;
195
- recordData[i] = null;
183
+ try {
184
+ const resolvedData = await universalResolver["resolve(bytes,bytes[])"](
185
+ hexEncodeName(name),
186
+ data,
187
+ {
188
+ ccipReadEnabled: true
189
+ }
190
+ );
191
+ recordData = [...resolvedData["0"]];
192
+ resolverAddress = resolvedData["1"];
193
+ for (let i = 0; i < recordData.length; i += 1) {
194
+ if (recordData[i].startsWith("0x0d1947a9")) {
195
+ calls[i] = null;
196
+ recordData[i] = null;
197
+ }
196
198
  }
199
+ } catch {
200
+ const registryContract = await contracts?.getRegistry();
201
+ resolverAddress = await registryContract?.resolver(namehash(name));
202
+ return {
203
+ address: void 0,
204
+ records: {},
205
+ resolverAddress,
206
+ isInvalidResolverAddress: true
207
+ };
197
208
  }
198
209
  }
199
210
  if (!resolverAddress || !recordData || hexStripZeros(resolverAddress) === "0x") {
200
211
  return {
201
- address: null,
212
+ address: void 0,
202
213
  records: {},
203
- resolverAddress: null
214
+ resolverAddress: void 0
204
215
  };
205
216
  }
206
217
  const filteredCalls = calls.filter((x) => x);
207
218
  const filteredRecordData = recordData.filter((x) => x);
208
219
  const matchAddress = filteredRecordData[filteredCalls.findIndex((x) => x.key === "60")];
209
220
  return {
210
- address: matchAddress && await _getAddr.decode(matchAddress),
221
+ address: matchAddress && await _getAddr.decode(matchAddress).catch(() => false),
211
222
  records: await formatRecords(
212
223
  { _getAddr, _getContentHash, _getText },
213
224
  filteredRecordData,
@@ -24,6 +24,7 @@ declare type ResolvedProfile = {
24
24
  coinTypes?: DataItem[];
25
25
  };
26
26
  resolverAddress?: string;
27
+ isInvalidResolverAddress?: boolean;
27
28
  reverseResolverAddress?: string;
28
29
  };
29
30
  declare type ProfileOptions = {
@@ -28,6 +28,7 @@ export default function ({ getProfile }: ENSArgs<'getProfile'>, name: string, op
28
28
  }[] | undefined;
29
29
  } | undefined;
30
30
  resolverAddress?: string | undefined;
31
+ isInvalidResolverAddress?: boolean | undefined;
31
32
  reverseResolverAddress?: string | undefined;
32
33
  } | undefined>;
33
34
  export {};
@@ -182,6 +182,7 @@ export declare class ENS {
182
182
  }[] | undefined;
183
183
  } | undefined;
184
184
  resolverAddress?: string | undefined;
185
+ isInvalidResolverAddress?: boolean | undefined;
185
186
  reverseResolverAddress?: string | undefined;
186
187
  } | undefined>;
187
188
  getRecords: (name: string, options?: {
@@ -212,6 +213,7 @@ export declare class ENS {
212
213
  }[] | undefined;
213
214
  } | undefined;
214
215
  resolverAddress?: string | undefined;
216
+ isInvalidResolverAddress?: boolean | undefined;
215
217
  reverseResolverAddress?: string | undefined;
216
218
  } | undefined>;
217
219
  getName: GeneratedRawFunction<{
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ensdomains/ensjs",
3
- "version": "3.0.0-alpha.35",
3
+ "version": "3.0.0-alpha.36",
4
4
  "description": "ENS javascript library for contract interaction",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/esm/index.mjs",
@@ -350,9 +350,9 @@ const getNames = async (
350
350
  const { account } = await client.request(finalQuery, queryVars)
351
351
  if (type === 'all') {
352
352
  return [
353
- ...account.domains.map(mapDomain),
354
- ...account.registrations.map(mapRegistration),
355
- ...account.wrappedDomains.map(mapWrappedDomain),
353
+ ...(account?.domains.map(mapDomain) || []),
354
+ ...(account?.registrations.map(mapRegistration) || []),
355
+ ...(account?.wrappedDomains.map(mapWrappedDomain) || []),
356
356
  ].sort((a, b) => {
357
357
  if (orderDirection === 'desc') {
358
358
  if (orderBy === 'labelName') {
@@ -367,12 +367,12 @@ const getNames = async (
367
367
  }) as Name[]
368
368
  }
369
369
  if (type === 'owner') {
370
- return account.domains.map(mapDomain) as Name[]
370
+ return (account?.domains.map(mapDomain) || []) as Name[]
371
371
  }
372
372
  if (type === 'wrappedOwner') {
373
- return account.wrappedDomains.map(mapWrappedDomain) as Name[]
373
+ return (account?.wrappedDomains.map(mapWrappedDomain) || []) as Name[]
374
374
  }
375
- return account.registrations.map(mapRegistration) as Name[]
375
+ return (account?.registrations.map(mapRegistration) || []) as Name[]
376
376
  }
377
377
 
378
378
  export default getNames
@@ -15,6 +15,10 @@ beforeAll(async () => {
15
15
  accounts = await provider.listAccounts()
16
16
  })
17
17
 
18
+ beforeEach(async () => {
19
+ await revert()
20
+ })
21
+
18
22
  afterAll(async () => {
19
23
  await revert()
20
24
  })
@@ -143,4 +147,73 @@ describe('getProfile', () => {
143
147
  }
144
148
  })
145
149
  })
150
+ describe('with invalid resolver', () => {
151
+ it('should fail gracefully for a name with invalid resolver', async () => {
152
+ const tx = await ensInstance.setResolver('test123.eth', {
153
+ contract: 'registry',
154
+ resolver: '0xb794F5eA0ba39494cE839613fffBA74279579268',
155
+ addressOrIndex: 1,
156
+ })
157
+ expect(tx).toBeTruthy()
158
+ await tx.wait()
159
+ const result = await ensInstance.getProfile('test123.eth')
160
+ expect(result).toBeDefined()
161
+ if (result) {
162
+ expect(result.address).toBeUndefined()
163
+ expect(Object.keys(result.records!).length).toBe(0)
164
+ expect(result.resolverAddress).toBe(
165
+ '0xb794F5eA0ba39494cE839613fffBA74279579268',
166
+ )
167
+ expect(result.isInvalidResolverAddress).toBe(true)
168
+ }
169
+ })
170
+
171
+ it('should fail gracefully for a wrapped name with invalid resolver', async () => {
172
+ const tx = await ensInstance.setResolver('wrapped.eth', {
173
+ contract: 'nameWrapper',
174
+ resolver: '0xb794F5eA0ba39494cE839613fffBA74279579268',
175
+ addressOrIndex: 1,
176
+ })
177
+ expect(tx).toBeTruthy()
178
+ await tx.wait()
179
+ const result = await ensInstance.getProfile('wrapped.eth')
180
+ expect(result).toBeDefined()
181
+ if (result) {
182
+ expect(result.address).toBeUndefined()
183
+ expect(Object.keys(result.records!).length).toBe(0)
184
+ expect(result.resolverAddress).toBe(
185
+ '0xb794F5eA0ba39494cE839613fffBA74279579268',
186
+ )
187
+ expect(result.isInvalidResolverAddress).toBe(true)
188
+ }
189
+ })
190
+
191
+ it('should fail gracefully for name with invalid resolver option', async () => {
192
+ const result = await ensInstance.getProfile('test123.eth', {
193
+ resolverAddress: '0xb794F5eA0ba39494cE839613fffBA74279579268',
194
+ })
195
+ expect(result).toBeDefined()
196
+ if (result) {
197
+ expect(result.address).toBeFalsy()
198
+ expect(Object.keys(result.records!).length).toBe(0)
199
+ expect(result.resolverAddress).toBe(
200
+ '0xb794F5eA0ba39494cE839613fffBA74279579268',
201
+ )
202
+ }
203
+ })
204
+
205
+ it('should fail gracefully for wrapped name with invalid resolver option', async () => {
206
+ const result = await ensInstance.getProfile('wrapped.eth', {
207
+ resolverAddress: '0xb794F5eA0ba39494cE839613fffBA74279579268',
208
+ })
209
+ expect(result).toBeDefined()
210
+ if (result) {
211
+ expect(result.address).toBeFalsy()
212
+ expect(Object.keys(result.records!).length).toBe(0)
213
+ expect(result.resolverAddress).toBe(
214
+ '0xb794F5eA0ba39494cE839613fffBA74279579268',
215
+ )
216
+ }
217
+ })
218
+ })
146
219
  })
@@ -45,6 +45,7 @@ type ResolvedProfile = {
45
45
  coinTypes?: DataItem[]
46
46
  }
47
47
  resolverAddress?: string
48
+ isInvalidResolverAddress?: boolean
48
49
  reverseResolverAddress?: string
49
50
  }
50
51
 
@@ -293,21 +294,32 @@ const getDataForName = async (
293
294
  )
294
295
  }
295
296
  } else {
296
- const resolvedData = await universalResolver['resolve(bytes,bytes[])'](
297
- hexEncodeName(name),
298
- data,
299
- {
300
- ccipReadEnabled: true,
301
- },
302
- )
303
- recordData = [...resolvedData['0']]
304
- resolverAddress = resolvedData['1']
305
- for (let i = 0; i < recordData.length; i += 1) {
306
- // error code for reverted call in batch
307
- // this is expected when using offchain resolvers, so should be ignored
308
- if (recordData[i]!.startsWith('0x0d1947a9')) {
309
- calls[i] = null
310
- recordData[i] = null
297
+ try {
298
+ const resolvedData = await universalResolver['resolve(bytes,bytes[])'](
299
+ hexEncodeName(name),
300
+ data,
301
+ {
302
+ ccipReadEnabled: true,
303
+ },
304
+ )
305
+ recordData = [...resolvedData['0']]
306
+ resolverAddress = resolvedData['1']
307
+ for (let i = 0; i < recordData.length; i += 1) {
308
+ // error code for reverted call in batch
309
+ // this is expected when using offchain resolvers, so should be ignored
310
+ if (recordData[i]!.startsWith('0x0d1947a9')) {
311
+ calls[i] = null
312
+ recordData[i] = null
313
+ }
314
+ }
315
+ } catch {
316
+ const registryContract = await contracts?.getRegistry()
317
+ resolverAddress = await registryContract?.resolver(namehash(name))
318
+ return {
319
+ address: undefined,
320
+ records: {},
321
+ resolverAddress,
322
+ isInvalidResolverAddress: true,
311
323
  }
312
324
  }
313
325
  }
@@ -317,9 +329,9 @@ const getDataForName = async (
317
329
  hexStripZeros(resolverAddress) === '0x'
318
330
  ) {
319
331
  return {
320
- address: null,
332
+ address: undefined,
321
333
  records: {},
322
- resolverAddress: null,
334
+ resolverAddress: undefined,
323
335
  }
324
336
  }
325
337
 
@@ -330,7 +342,8 @@ const getDataForName = async (
330
342
  filteredRecordData[filteredCalls.findIndex((x) => x.key === '60')]
331
343
 
332
344
  return {
333
- address: matchAddress && (await _getAddr.decode(matchAddress)),
345
+ address:
346
+ matchAddress && (await _getAddr.decode(matchAddress).catch(() => false)),
334
347
  records: await formatRecords(
335
348
  { _getAddr, _getContentHash, _getText },
336
349
  filteredRecordData,
@@ -456,7 +469,7 @@ const getProfileFromName = async (
456
469
  >,
457
470
  name: string,
458
471
  options?: InputProfileOptions,
459
- ) => {
472
+ ): Promise<ResolvedProfile | undefined> => {
460
473
  const { resolverAddress, fallback, ..._options } = options || {}
461
474
  const optsLength = Object.keys(_options).length
462
475
  let usingOptions: InputProfileOptions | undefined