@ensdomains/ensjs 3.2.1 → 3.4.0

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 (47) hide show
  1. package/dist/cjs/dns.js +3 -1
  2. package/dist/cjs/dns.js.map +1 -1
  3. package/dist/cjs/errors/version.js +1 -1
  4. package/dist/cjs/functions/dns/getDnsOffchainData.js +72 -0
  5. package/dist/cjs/functions/dns/getDnsOffchainData.js.map +1 -0
  6. package/dist/cjs/functions/dns/getDnsOwner.js +30 -57
  7. package/dist/cjs/functions/dns/getDnsOwner.js.map +1 -1
  8. package/dist/cjs/utils/dns/getDnsTxtRecords.js +14 -0
  9. package/dist/cjs/utils/dns/getDnsTxtRecords.js.map +1 -0
  10. package/dist/cjs/utils/dns/misc.js +34 -0
  11. package/dist/cjs/utils/dns/misc.js.map +1 -0
  12. package/dist/cjs/utils/index.js +7 -2
  13. package/dist/cjs/utils/index.js.map +1 -1
  14. package/dist/esm/dns.js +1 -0
  15. package/dist/esm/dns.js.map +1 -1
  16. package/dist/esm/errors/version.js +1 -1
  17. package/dist/esm/functions/dns/getDnsOffchainData.js +81 -0
  18. package/dist/esm/functions/dns/getDnsOffchainData.js.map +1 -0
  19. package/dist/esm/functions/dns/getDnsOwner.js +30 -57
  20. package/dist/esm/functions/dns/getDnsOwner.js.map +1 -1
  21. package/dist/esm/utils/dns/getDnsTxtRecords.js +21 -0
  22. package/dist/esm/utils/dns/getDnsTxtRecords.js.map +1 -0
  23. package/dist/esm/utils/dns/misc.js +31 -0
  24. package/dist/esm/utils/dns/misc.js.map +1 -0
  25. package/dist/esm/utils/index.js +2 -0
  26. package/dist/esm/utils/index.js.map +1 -1
  27. package/dist/types/dns.d.ts +1 -0
  28. package/dist/types/dns.d.ts.map +1 -1
  29. package/dist/types/errors/version.d.ts +1 -1
  30. package/dist/types/functions/dns/getDnsOffchainData.d.ts +28 -0
  31. package/dist/types/functions/dns/getDnsOffchainData.d.ts.map +1 -0
  32. package/dist/types/functions/dns/getDnsOwner.d.ts +4 -4
  33. package/dist/types/functions/dns/getDnsOwner.d.ts.map +1 -1
  34. package/dist/types/utils/dns/getDnsTxtRecords.d.ts +21 -0
  35. package/dist/types/utils/dns/getDnsTxtRecords.d.ts.map +1 -0
  36. package/dist/types/utils/dns/misc.d.ts +50 -0
  37. package/dist/types/utils/dns/misc.d.ts.map +1 -0
  38. package/dist/types/utils/index.d.ts +2 -0
  39. package/dist/types/utils/index.d.ts.map +1 -1
  40. package/package.json +1 -1
  41. package/src/dns.ts +5 -0
  42. package/src/errors/version.ts +1 -1
  43. package/src/functions/dns/getDnsOffchainData.ts +139 -0
  44. package/src/functions/dns/getDnsOwner.ts +36 -88
  45. package/src/utils/dns/getDnsTxtRecords.ts +38 -0
  46. package/src/utils/dns/misc.ts +53 -0
  47. package/src/utils/index.ts +12 -0
@@ -1,3 +1,5 @@
1
+ export { getDnsTxtRecords, } from './dns/getDnsTxtRecords.js';
2
+ export { DnsRecordType, DnsResponseStatus, } from './dns/misc.js';
1
3
  export { contentTypeToEncodeAs, encodeAbi, encodeAsToContentType, } from './encoders/encodeAbi.js';
2
4
  export { encodeClearRecords } from './encoders/encodeClearRecords.js';
3
5
  export { encodeSetAbi, } from './encoders/encodeSetAbi.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,SAAS,EACT,qBAAqB,GAItB,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAA;AACrE,OAAO,EACL,YAAY,GAGb,MAAM,4BAA4B,CAAA;AACnC,OAAO,EACL,aAAa,GAGd,MAAM,6BAA6B,CAAA;AACpC,OAAO,EACL,oBAAoB,GAGrB,MAAM,oCAAoC,CAAA;AAC3C,OAAO,EACL,aAAa,GAGd,MAAM,6BAA6B,CAAA;AAEpC,OAAO,EACL,aAAa,EACb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B,EAAE,MAAM,oCAAoC,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,GAGjB,MAAM,2BAA2B,CAAA;AAClC,OAAO,EACL,aAAa,EACb,iBAAiB,GAIlB,MAAM,eAAe,CAAA;AACtB,OAAO,EACL,qBAAqB,EACrB,SAAS,EACT,qBAAqB,GAItB,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAA;AACrE,OAAO,EACL,YAAY,GAGb,MAAM,4BAA4B,CAAA;AACnC,OAAO,EACL,aAAa,GAGd,MAAM,6BAA6B,CAAA;AACpC,OAAO,EACL,oBAAoB,GAGrB,MAAM,oCAAoC,CAAA;AAC3C,OAAO,EACL,aAAa,GAGd,MAAM,6BAA6B,CAAA;AAEpC,OAAO,EACL,aAAa,EACb,oBAAoB,EACpB,YAAY,EACZ,UAAU,EACV,qBAAqB,GACtB,MAAM,aAAa,CAAA;AACpB,OAAO,EACL,aAAa,EACb,kBAAkB,EAClB,UAAU,EACV,kBAAkB,EAClB,uBAAuB,EACvB,eAAe,EACf,UAAU,EACV,cAAc,EACd,mBAAmB,EACnB,WAAW,EACX,oBAAoB,EACpB,iBAAiB,EACjB,qBAAqB,EACrB,kBAAkB,EAClB,oBAAoB,EACpB,iBAAiB,EACjB,cAAc,EACd,WAAW,EACX,WAAW,GAQZ,MAAM,YAAY,CAAA;AAEnB,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EACjB,eAAe,EACf,gBAAgB,EAChB,eAAe,EACf,kBAAkB,GAGnB,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAC5C,OAAO,EACL,uBAAuB,GAExB,MAAM,8BAA8B,CAAA;AACrC,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAClE,OAAO,EACL,gBAAgB,EAChB,UAAU,EACV,eAAe,EACf,WAAW,EACX,eAAe,EACf,kBAAkB,EAClB,SAAS,EACT,QAAQ,GACT,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AAC9D,OAAO,EACL,QAAQ,EACR,KAAK,EACL,eAAe,EACf,QAAQ,EACR,SAAS,EACT,iBAAiB,EACjB,YAAY,EACZ,KAAK,EACL,QAAQ,GAWT,MAAM,gBAAgB,CAAA;AACvB,OAAO,EACL,cAAc,EACd,uBAAuB,EACvB,mBAAmB,EACnB,qBAAqB,EACrB,YAAY,GAIb,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EACL,aAAa,EACb,UAAU,EACV,YAAY,GAEb,MAAM,iBAAiB,CAAA;AACxB,OAAO,EACL,UAAU,EACV,cAAc,EACd,uBAAuB,GACxB,MAAM,cAAc,CAAA;AACrB,OAAO,EAAE,6BAA6B,EAAE,MAAM,oCAAoC,CAAA"}
@@ -1,4 +1,5 @@
1
1
  export { default as getDnsImportData, type GetDnsImportDataParameters, type GetDnsImportDataReturnType, } from './functions/dns/getDnsImportData.js';
2
+ export { default as getDnsOffchainData, type GetDnsOffchainDataParameters, type GetDnsOffchainDataReturnType, } from './functions/dns/getDnsOffchainData.js';
2
3
  export { default as getDnsOwner, type GetDnsOwnerParameters, type GetDnsOwnerReturnType, } from './functions/dns/getDnsOwner.js';
3
4
  export { default as importDnsName, type ImportDnsNameDataParameters, type ImportDnsNameDataReturnType, type ImportDnsNameParameters, type ImportDnsNameReturnType, } from './functions/dns/importDnsName.js';
4
5
  export type { Endpoint } from './functions/dns/types.js';
@@ -1 +1 @@
1
- {"version":3,"file":"dns.d.ts","sourceRoot":"","sources":["../../src/dns.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,IAAI,gBAAgB,EAC3B,KAAK,0BAA0B,EAC/B,KAAK,0BAA0B,GAChC,MAAM,qCAAqC,CAAA;AAC5C,OAAO,EACL,OAAO,IAAI,WAAW,EACtB,KAAK,qBAAqB,EAC1B,KAAK,qBAAqB,GAC3B,MAAM,gCAAgC,CAAA;AACvC,OAAO,EACL,OAAO,IAAI,aAAa,EACxB,KAAK,2BAA2B,EAChC,KAAK,2BAA2B,EAChC,KAAK,uBAAuB,EAC5B,KAAK,uBAAuB,GAC7B,MAAM,kCAAkC,CAAA;AACzC,YAAY,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAA"}
1
+ {"version":3,"file":"dns.d.ts","sourceRoot":"","sources":["../../src/dns.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,IAAI,gBAAgB,EAC3B,KAAK,0BAA0B,EAC/B,KAAK,0BAA0B,GAChC,MAAM,qCAAqC,CAAA;AAC5C,OAAO,EACL,OAAO,IAAI,kBAAkB,EAC7B,KAAK,4BAA4B,EACjC,KAAK,4BAA4B,GAClC,MAAM,uCAAuC,CAAA;AAC9C,OAAO,EACL,OAAO,IAAI,WAAW,EACtB,KAAK,qBAAqB,EAC1B,KAAK,qBAAqB,GAC3B,MAAM,gCAAgC,CAAA;AACvC,OAAO,EACL,OAAO,IAAI,aAAa,EACxB,KAAK,2BAA2B,EAChC,KAAK,2BAA2B,EAChC,KAAK,uBAAuB,EAC5B,KAAK,uBAAuB,GAC7B,MAAM,kCAAkC,CAAA;AACzC,YAAY,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAA"}
@@ -1,2 +1,2 @@
1
- export declare const version = "v3.2.1";
1
+ export declare const version = "v3.4.0";
2
2
  //# sourceMappingURL=version.d.ts.map
@@ -0,0 +1,28 @@
1
+ import { type Address, type Client, type Transport } from 'viem';
2
+ import type { ChainWithEns } from '../../contracts/consts.js';
3
+ import type { Endpoint } from './types.js';
4
+ export type GetDnsOffchainDataParameters = {
5
+ /** Name to get the offchain data for */
6
+ name: string;
7
+ /** An RFC-1035 compatible DNS endpoint to use (default: `https://cloudflare-dns.com/dns-query`) */
8
+ endpoint?: Endpoint;
9
+ /** Whether or not to throw errors */
10
+ strict?: boolean;
11
+ };
12
+ export type GetDnsOffchainDataReturnType = {
13
+ resolverAddress: Address;
14
+ extraData: string | null;
15
+ } | null;
16
+ /**
17
+ * Gets the DNS offchain data for a name, via DNS record lookup
18
+ * @param parameters - {@link GetDnsOffchainDataParameters}
19
+ * @returns Resolver address and extra data, or null. {@link GetDnsOffchainDataReturnType}
20
+ *
21
+ * @example
22
+ * import { getDnsOffchainData } from '@ensdomains/ensjs/dns'
23
+ *
24
+ * const owner = await getDnsOffchainData({ name: 'ethleaderboard.xyz' })
25
+ */
26
+ declare const getDnsOffchainData: (client: Client<Transport, ChainWithEns>, { name, endpoint, strict }: GetDnsOffchainDataParameters) => Promise<GetDnsOffchainDataReturnType>;
27
+ export default getDnsOffchainData;
28
+ //# sourceMappingURL=getDnsOffchainData.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getDnsOffchainData.d.ts","sourceRoot":"","sources":["../../../../src/functions/dns/getDnsOffchainData.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,KAAK,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,SAAS,EAAE,MAAM,MAAM,CAAA;AAC3E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAgB7D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAE1C,MAAM,MAAM,4BAA4B,GAAG;IACzC,wCAAwC;IACxC,IAAI,EAAE,MAAM,CAAA;IACZ,mGAAmG;IACnG,QAAQ,CAAC,EAAE,QAAQ,CAAA;IACnB,qCAAqC;IACrC,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB,CAAA;AAED,MAAM,MAAM,4BAA4B,GAAG;IACzC,eAAe,EAAE,OAAO,CAAA;IACxB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;CACzB,GAAG,IAAI,CAAA;AA8CR;;;;;;;;;GASG;AACH,QAAA,MAAM,kBAAkB,WACd,OAAO,SAAS,EAAE,YAAY,CAAC,8BACX,4BAA4B,KACvD,QAAQ,4BAA4B,CA8CtC,CAAA;AAED,eAAe,kBAAkB,CAAA"}
@@ -5,10 +5,10 @@ export type GetDnsOwnerParameters = {
5
5
  name: string;
6
6
  /** An RFC-1035 compatible DNS endpoint to use (default: `https://cloudflare-dns.com/dns-query`) */
7
7
  endpoint?: Endpoint;
8
- /** Optional flag to allow the function to fail silently (default: `true`) */
9
- allowFailure?: boolean;
8
+ /** Whether or not to throw errors */
9
+ strict?: boolean;
10
10
  };
11
- export type GetDnsOwnerReturnType = Address;
11
+ export type GetDnsOwnerReturnType = Address | null;
12
12
  /**
13
13
  * Gets the DNS owner of a name, via DNS record lookup
14
14
  * @param parameters - {@link GetDnsOwnerParameters}
@@ -20,6 +20,6 @@ export type GetDnsOwnerReturnType = Address;
20
20
  * const owner = await getDnsOwner({ name: 'ens.domains' })
21
21
  * // '0xb8c2C29ee19D8307cb7255e1Cd9CbDE883A267d5'
22
22
  */
23
- declare const getDnsOwner: ({ name, endpoint, }: GetDnsOwnerParameters) => Promise<GetDnsOwnerReturnType>;
23
+ declare const getDnsOwner: ({ name, endpoint, strict, }: GetDnsOwnerParameters) => Promise<GetDnsOwnerReturnType>;
24
24
  export default getDnsOwner;
25
25
  //# sourceMappingURL=getDnsOwner.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"getDnsOwner.d.ts","sourceRoot":"","sources":["../../../../src/functions/dns/getDnsOwner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,KAAK,OAAO,EAAE,MAAM,MAAM,CAAA;AAU/C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAE1C,MAAM,MAAM,qBAAqB,GAAG;IAClC,gCAAgC;IAChC,IAAI,EAAE,MAAM,CAAA;IACZ,mGAAmG;IACnG,QAAQ,CAAC,EAAE,QAAQ,CAAA;IACnB,6EAA6E;IAC7E,YAAY,CAAC,EAAE,OAAO,CAAA;CACvB,CAAA;AAED,MAAM,MAAM,qBAAqB,GAAG,OAAO,CAAA;AAyD3C;;;;;;;;;;GAUG;AACH,QAAA,MAAM,WAAW,wBAGd,qBAAqB,KAAG,QAAQ,qBAAqB,CA8CvD,CAAA;AAED,eAAe,WAAW,CAAA"}
1
+ {"version":3,"file":"getDnsOwner.d.ts","sourceRoot":"","sources":["../../../../src/functions/dns/getDnsOwner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,KAAK,OAAO,EAAE,MAAM,MAAM,CAAA;AAY/C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAE1C,MAAM,MAAM,qBAAqB,GAAG;IAClC,gCAAgC;IAChC,IAAI,EAAE,MAAM,CAAA;IACZ,mGAAmG;IACnG,QAAQ,CAAC,EAAE,QAAQ,CAAA;IACnB,qCAAqC;IACrC,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB,CAAA;AAED,MAAM,MAAM,qBAAqB,GAAG,OAAO,GAAG,IAAI,CAAA;AAElD;;;;;;;;;;GAUG;AACH,QAAA,MAAM,WAAW,gCAId,qBAAqB,KAAG,QAAQ,qBAAqB,CA8CvD,CAAA;AAED,eAAe,WAAW,CAAA"}
@@ -0,0 +1,21 @@
1
+ import type { Endpoint } from '../../functions/dns/types.js';
2
+ import { type DnsResponse } from './misc.js';
3
+ export type GetDnsTxtRecordsParameters = {
4
+ /** Name to get the txt records for */
5
+ name: string;
6
+ /** An RFC-1035 compatible DNS endpoint to use (default: `https://cloudflare-dns.com/dns-query`) */
7
+ endpoint?: Endpoint;
8
+ };
9
+ export type GetDnsTxtRecordsReturnType = DnsResponse;
10
+ /**
11
+ * Gets the DNS record response of a name, via DNS record lookup
12
+ * @param parameters - {@link GetDnsTxtRecordsParameters}
13
+ * @returns DNS response. {@link GetDnsTxtRecordsReturnType}
14
+ *
15
+ * @example
16
+ * import { getDnsTxtRecords } from '@ensdomains/ensjs/utils'
17
+ *
18
+ * const owner = await getDnsTxtRecords({ name: '_ens.ens.domains' })
19
+ */
20
+ export declare const getDnsTxtRecords: ({ name, endpoint, }: GetDnsTxtRecordsParameters) => Promise<GetDnsTxtRecordsReturnType>;
21
+ //# sourceMappingURL=getDnsTxtRecords.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getDnsTxtRecords.d.ts","sourceRoot":"","sources":["../../../../src/utils/dns/getDnsTxtRecords.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAA;AAC5D,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,WAAW,CAAA;AAE5C,MAAM,MAAM,0BAA0B,GAAG;IACvC,sCAAsC;IACtC,IAAI,EAAE,MAAM,CAAA;IACZ,mGAAmG;IACnG,QAAQ,CAAC,EAAE,QAAQ,CAAA;CACpB,CAAA;AAED,MAAM,MAAM,0BAA0B,GAAG,WAAW,CAAA;AAEpD;;;;;;;;;GASG;AACH,eAAO,MAAM,gBAAgB,wBAG1B,0BAA0B,KAAG,QAAQ,0BAA0B,CAYjE,CAAA"}
@@ -0,0 +1,50 @@
1
+ export declare enum DnsResponseStatus {
2
+ NOERROR = 0,
3
+ FORMERR = 1,
4
+ SERVFAIL = 2,
5
+ NXDOMAIN = 3,
6
+ NOTIMP = 4,
7
+ REFUSED = 5,
8
+ YXDOMAIN = 6,
9
+ YXRRSET = 7,
10
+ NXRRSET = 8,
11
+ NOTAUTH = 9,
12
+ NOTZONE = 10,
13
+ DSOTYPENI = 11,
14
+ BADVERS = 16,
15
+ BADKEY = 17,
16
+ BADTIME = 18,
17
+ BADMODE = 19,
18
+ BADNAME = 20,
19
+ BADALG = 21,
20
+ BADTRUNC = 22,
21
+ BADCOOKIE = 23
22
+ }
23
+ export declare enum DnsRecordType {
24
+ TXT = 16,
25
+ DS = 43,
26
+ RRSIG = 46,
27
+ DNSKEY = 48
28
+ }
29
+ export type DnsQuestionItem = {
30
+ name: string;
31
+ type: DnsRecordType;
32
+ };
33
+ export type DnsResponseItem = DnsQuestionItem & {
34
+ TTL: number;
35
+ data: string;
36
+ };
37
+ export type DnsResponse = {
38
+ Status: DnsResponseStatus;
39
+ TC: boolean;
40
+ RD: boolean;
41
+ RA: boolean;
42
+ AD: boolean;
43
+ CD: boolean;
44
+ Question: DnsQuestionItem[];
45
+ Answer?: DnsResponseItem[];
46
+ Authority?: DnsResponseItem[];
47
+ Additional?: DnsResponseItem[];
48
+ Comment?: string;
49
+ };
50
+ //# sourceMappingURL=misc.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"misc.d.ts","sourceRoot":"","sources":["../../../../src/utils/dns/misc.ts"],"names":[],"mappings":"AAAA,oBAAY,iBAAiB;IAC3B,OAAO,IAAI;IACX,OAAO,IAAI;IACX,QAAQ,IAAI;IACZ,QAAQ,IAAI;IACZ,MAAM,IAAI;IACV,OAAO,IAAI;IACX,QAAQ,IAAI;IACZ,OAAO,IAAI;IACX,OAAO,IAAI;IACX,OAAO,IAAI;IACX,OAAO,KAAK;IACZ,SAAS,KAAK;IACd,OAAO,KAAK;IACZ,MAAM,KAAK;IACX,OAAO,KAAK;IACZ,OAAO,KAAK;IACZ,OAAO,KAAK;IACZ,MAAM,KAAK;IACX,QAAQ,KAAK;IACb,SAAS,KAAK;CACf;AAED,oBAAY,aAAa;IACvB,GAAG,KAAK;IACR,EAAE,KAAK;IACP,KAAK,KAAK;IACV,MAAM,KAAK;CACZ;AAED,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,aAAa,CAAA;CACpB,CAAA;AAED,MAAM,MAAM,eAAe,GAAG,eAAe,GAAG;IAC9C,GAAG,EAAE,MAAM,CAAA;IACX,IAAI,EAAE,MAAM,CAAA;CACb,CAAA;AAED,MAAM,MAAM,WAAW,GAAG;IACxB,MAAM,EAAE,iBAAiB,CAAA;IACzB,EAAE,EAAE,OAAO,CAAA;IACX,EAAE,EAAE,OAAO,CAAA;IACX,EAAE,EAAE,OAAO,CAAA;IACX,EAAE,EAAE,OAAO,CAAA;IACX,EAAE,EAAE,OAAO,CAAA;IACX,QAAQ,EAAE,eAAe,EAAE,CAAA;IAC3B,MAAM,CAAC,EAAE,eAAe,EAAE,CAAA;IAC1B,SAAS,CAAC,EAAE,eAAe,EAAE,CAAA;IAC7B,UAAU,CAAC,EAAE,eAAe,EAAE,CAAA;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB,CAAA"}
@@ -1,3 +1,5 @@
1
+ export { getDnsTxtRecords, type GetDnsTxtRecordsParameters, type GetDnsTxtRecordsReturnType, } from './dns/getDnsTxtRecords.js';
2
+ export { DnsRecordType, DnsResponseStatus, type DnsQuestionItem, type DnsResponse, type DnsResponseItem, } from './dns/misc.js';
1
3
  export { contentTypeToEncodeAs, encodeAbi, encodeAsToContentType, type EncodeAbiParameters, type EncodeAbiReturnType, type EncodedAbi, } from './encoders/encodeAbi.js';
2
4
  export { encodeClearRecords } from './encoders/encodeClearRecords.js';
3
5
  export { encodeSetAbi, type EncodeSetAbiParameters, type EncodeSetAbiReturnType, } from './encoders/encodeSetAbi.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,SAAS,EACT,qBAAqB,EACrB,KAAK,mBAAmB,EACxB,KAAK,mBAAmB,EACxB,KAAK,UAAU,GAChB,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAA;AACrE,OAAO,EACL,YAAY,EACZ,KAAK,sBAAsB,EAC3B,KAAK,sBAAsB,GAC5B,MAAM,4BAA4B,CAAA;AACnC,OAAO,EACL,aAAa,EACb,KAAK,uBAAuB,EAC5B,KAAK,uBAAuB,GAC7B,MAAM,6BAA6B,CAAA;AACpC,OAAO,EACL,oBAAoB,EACpB,KAAK,8BAA8B,EACnC,KAAK,8BAA8B,GACpC,MAAM,oCAAoC,CAAA;AAC3C,OAAO,EACL,aAAa,EACb,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K,eAAe,EACpB,KAAK,UAAU,EACf,KAAK,YAAY,EACjB,KAAK,KAAK,EACV,KAAK,WAAW,EAChB,KAAK,QAAQ,EACb,KAAK,SAAS,EACd,KAAK,SAAS,EACd,KAAK,KAAK,EACV,KAAK,UAAU,GAChB,MAAM,gBAAgB,CAAA;AACvB,OAAO,EACL,cAAc,EACd,uBAAuB,EACvB,mBAAmB,EACnB,qBAAqB,EACrB,YAAY,EACZ,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAC3B,KAAK,iBAAiB,GACvB,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EACL,aAAa,EACb,UAAU,EACV,YAAY,EACZ,KAAK,iBAAiB,GACvB,MAAM,iBAAiB,CAAA;AACxB,OAAO,EACL,UAAU,EACV,cAAc,EACd,uBAAuB,GACxB,MAAM,cAAc,CAAA;AACrB,OAAO,EAAE,6BAA6B,EAAE,MAAM,oCAAoC,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,KAAK,0BAA0B,EAC/B,KAAK,0BAA0B,GAChC,MAAM,2BAA2B,CAAA;AAClC,OAAO,EACL,aAAa,EACb,iBAAiB,EACjB,KAAK,eAAe,EACpB,KAAK,WAAW,EAChB,KAAK,eAAe,GACrB,MAAM,eAAe,CAAA;AACtB,OAAO,EACL,qBAAqB,EACrB,SAAS,EACT,qBAAqB,EACrB,KAAK,mBAAmB,EACxB,KAAK,mBAAmB,EACxB,KAAK,UAAU,GAChB,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAA;AACrE,OAAO,EACL,YAAY,EACZ,KAAK,sBAAsB,EAC3B,KAAK,sBAAsB,GAC5B,MAAM,4BAA4B,CAAA;AACnC,OAAO,EACL,aAAa,EACb,KAAK,uBAAuB,EAC5B,KAAK,uBAAuB,GAC7B,MAAM,6BAA6B,CAAA;AACpC,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,EACL,QAAQ,EACR,KAAK,EACL,eAAe,EACf,QAAQ,EACR,SAAS,EACT,iBAAiB,EACjB,YAAY,EACZ,KAAK,EACL,QAAQ,EACR,KAAK,eAAe,EACpB,KAAK,UAAU,EACf,KAAK,YAAY,EACjB,KAAK,KAAK,EACV,KAAK,WAAW,EAChB,KAAK,QAAQ,EACb,KAAK,SAAS,EACd,KAAK,SAAS,EACd,KAAK,KAAK,EACV,KAAK,UAAU,GAChB,MAAM,gBAAgB,CAAA;AACvB,OAAO,EACL,cAAc,EACd,uBAAuB,EACvB,mBAAmB,EACnB,qBAAqB,EACrB,YAAY,EACZ,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAC3B,KAAK,iBAAiB,GACvB,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EACL,aAAa,EACb,UAAU,EACV,YAAY,EACZ,KAAK,iBAAiB,GACvB,MAAM,iBAAiB,CAAA;AACxB,OAAO,EACL,UAAU,EACV,cAAc,EACd,uBAAuB,GACxB,MAAM,cAAc,CAAA;AACrB,OAAO,EAAE,6BAA6B,EAAE,MAAM,oCAAoC,CAAA"}
package/package.json CHANGED
@@ -16,7 +16,7 @@
16
16
  "peerDependencies": {
17
17
  "viem": "^1.16.4"
18
18
  },
19
- "version": "3.2.1",
19
+ "version": "3.4.0",
20
20
  "files": [
21
21
  "dist/",
22
22
  "src/",
package/src/dns.ts CHANGED
@@ -3,6 +3,11 @@ export {
3
3
  type GetDnsImportDataParameters,
4
4
  type GetDnsImportDataReturnType,
5
5
  } from './functions/dns/getDnsImportData.js'
6
+ export {
7
+ default as getDnsOffchainData,
8
+ type GetDnsOffchainDataParameters,
9
+ type GetDnsOffchainDataReturnType,
10
+ } from './functions/dns/getDnsOffchainData.js'
6
11
  export {
7
12
  default as getDnsOwner,
8
13
  type GetDnsOwnerParameters,
@@ -1 +1 @@
1
- export const version = 'v3.2.1'
1
+ export const version = 'v3.4.0'
@@ -0,0 +1,139 @@
1
+ import { isAddress, type Address, type Client, type Transport } from 'viem'
2
+ import type { ChainWithEns } from '../../contracts/consts.js'
3
+ import {
4
+ DnsDnssecVerificationFailedError,
5
+ DnsInvalidTxtRecordError,
6
+ DnsNoTxtRecordError,
7
+ DnsResponseStatusError,
8
+ } from '../../errors/dns.js'
9
+ import { UnsupportedNameTypeError } from '../../errors/general.js'
10
+ import { getDnsTxtRecords } from '../../utils/dns/getDnsTxtRecords.js'
11
+ import {
12
+ DnsRecordType,
13
+ DnsResponseStatus,
14
+ type DnsResponseItem,
15
+ } from '../../utils/dns/misc.js'
16
+ import { getNameType } from '../../utils/getNameType.js'
17
+ import getAddressRecord from '../public/getAddressRecord.js'
18
+ import type { Endpoint } from './types.js'
19
+
20
+ export type GetDnsOffchainDataParameters = {
21
+ /** Name to get the offchain data for */
22
+ name: string
23
+ /** An RFC-1035 compatible DNS endpoint to use (default: `https://cloudflare-dns.com/dns-query`) */
24
+ endpoint?: Endpoint
25
+ /** Whether or not to throw errors */
26
+ strict?: boolean
27
+ }
28
+
29
+ export type GetDnsOffchainDataReturnType = {
30
+ resolverAddress: Address
31
+ extraData: string | null
32
+ } | null
33
+
34
+ type ValidTextRecord = {
35
+ isValid: true
36
+ resolverAddress: Address
37
+ extraData: string | null
38
+ }
39
+ type InvalidTextRecord = { isValid: false; recordData: string }
40
+
41
+ const checkValidEnsTxtRecord = async (
42
+ client: Client<Transport, ChainWithEns>,
43
+ record: DnsResponseItem,
44
+ ): Promise<InvalidTextRecord | ValidTextRecord | null> => {
45
+ if (record.type !== DnsRecordType.TXT) return null
46
+ if (!record.data.startsWith('"ENS1 ')) return null
47
+
48
+ const unwrappedRecordData = record.data.replace(/^"(.*)"$/g, '$1')
49
+
50
+ const resolverAndExtraData = unwrappedRecordData.slice(5)
51
+ const splitIndex = resolverAndExtraData.indexOf(' ')
52
+ const resolverNameOrAddress =
53
+ splitIndex === -1
54
+ ? resolverAndExtraData
55
+ : resolverAndExtraData.slice(0, splitIndex)
56
+ const extraData =
57
+ splitIndex === -1 ? null : resolverAndExtraData.slice(splitIndex + 1)
58
+
59
+ if (isAddress(resolverNameOrAddress))
60
+ return { isValid: true, resolverAddress: resolverNameOrAddress, extraData }
61
+
62
+ const resolverAddress = await getAddressRecord(client, {
63
+ name: resolverNameOrAddress,
64
+ // force no ccip-read, since dnsregistrar doesn't allow resolvers with ccip-read addresses
65
+ gatewayUrls: [],
66
+ }).catch(() => null) // if ccip-read is attempted, an error will be thrown. we can just ignore it
67
+
68
+ if (resolverAddress)
69
+ return {
70
+ isValid: true,
71
+ resolverAddress: resolverAddress.value as Address,
72
+ extraData,
73
+ }
74
+
75
+ return { isValid: false, recordData: unwrappedRecordData }
76
+ }
77
+
78
+ /**
79
+ * Gets the DNS offchain data for a name, via DNS record lookup
80
+ * @param parameters - {@link GetDnsOffchainDataParameters}
81
+ * @returns Resolver address and extra data, or null. {@link GetDnsOffchainDataReturnType}
82
+ *
83
+ * @example
84
+ * import { getDnsOffchainData } from '@ensdomains/ensjs/dns'
85
+ *
86
+ * const owner = await getDnsOffchainData({ name: 'ethleaderboard.xyz' })
87
+ */
88
+ const getDnsOffchainData = async (
89
+ client: Client<Transport, ChainWithEns>,
90
+ { name, endpoint, strict }: GetDnsOffchainDataParameters,
91
+ ): Promise<GetDnsOffchainDataReturnType> => {
92
+ const nameType = getNameType(name)
93
+
94
+ if (nameType !== 'other-2ld' && nameType !== 'other-subname')
95
+ throw new UnsupportedNameTypeError({
96
+ nameType,
97
+ supportedNameTypes: ['other-2ld', 'other-subname'],
98
+ })
99
+
100
+ try {
101
+ const response = await getDnsTxtRecords({ name, endpoint })
102
+
103
+ if (response.Status !== DnsResponseStatus.NOERROR)
104
+ throw new DnsResponseStatusError({
105
+ responseStatus: DnsResponseStatus[response.Status],
106
+ })
107
+
108
+ if (response.AD === false)
109
+ throw new DnsDnssecVerificationFailedError({ record: undefined })
110
+
111
+ if (!response.Answer?.length) throw new DnsNoTxtRecordError()
112
+
113
+ const ensTxtRecords = await Promise.all(
114
+ response.Answer.map((record) => checkValidEnsTxtRecord(client, record)),
115
+ )
116
+
117
+ const validRecord = ensTxtRecords.find(
118
+ (record): record is ValidTextRecord => record?.isValid === true,
119
+ )
120
+ if (validRecord)
121
+ return {
122
+ resolverAddress: validRecord.resolverAddress,
123
+ extraData: validRecord.extraData,
124
+ }
125
+
126
+ const invalidRecord = ensTxtRecords.find(
127
+ (record): record is InvalidTextRecord => record?.isValid === false,
128
+ )
129
+ if (invalidRecord)
130
+ throw new DnsInvalidTxtRecordError({ record: invalidRecord.recordData })
131
+
132
+ throw new DnsNoTxtRecordError()
133
+ } catch (error) {
134
+ if (!strict) return null
135
+ throw error
136
+ }
137
+ }
138
+
139
+ export default getDnsOffchainData
@@ -7,6 +7,8 @@ import {
7
7
  DnsResponseStatusError,
8
8
  } from '../../errors/dns.js'
9
9
  import { UnsupportedNameTypeError } from '../../errors/general.js'
10
+ import { getDnsTxtRecords } from '../../utils/dns/getDnsTxtRecords.js'
11
+ import { DnsRecordType, DnsResponseStatus } from '../../utils/dns/misc.js'
10
12
  import { getNameType } from '../../utils/getNameType.js'
11
13
  import type { Endpoint } from './types.js'
12
14
 
@@ -15,66 +17,11 @@ export type GetDnsOwnerParameters = {
15
17
  name: string
16
18
  /** An RFC-1035 compatible DNS endpoint to use (default: `https://cloudflare-dns.com/dns-query`) */
17
19
  endpoint?: Endpoint
18
- /** Optional flag to allow the function to fail silently (default: `true`) */
19
- allowFailure?: boolean
20
+ /** Whether or not to throw errors */
21
+ strict?: boolean
20
22
  }
21
23
 
22
- export type GetDnsOwnerReturnType = Address
23
-
24
- enum DnsResponseStatus {
25
- NOERROR = 0,
26
- FORMERR = 1,
27
- SERVFAIL = 2,
28
- NXDOMAIN = 3,
29
- NOTIMP = 4,
30
- REFUSED = 5,
31
- YXDOMAIN = 6,
32
- YXRRSET = 7,
33
- NXRRSET = 8,
34
- NOTAUTH = 9,
35
- NOTZONE = 10,
36
- DSOTYPENI = 11,
37
- BADVERS = 16,
38
- BADSIG = 16,
39
- BADKEY = 17,
40
- BADTIME = 18,
41
- BADMODE = 19,
42
- BADNAME = 20,
43
- BADALG = 21,
44
- BADTRUNC = 22,
45
- BADCOOKIE = 23,
46
- }
47
-
48
- enum DnsRecordType {
49
- TXT = 16,
50
- DS = 43,
51
- RRSIG = 46,
52
- DNSKEY = 48,
53
- }
54
-
55
- type DnsQuestionItem = {
56
- name: string
57
- type: DnsRecordType
58
- }
59
-
60
- type DnsResponseItem = DnsQuestionItem & {
61
- TTL: number
62
- data: string
63
- }
64
-
65
- type DnsResponse = {
66
- Status: DnsResponseStatus
67
- TC: boolean
68
- RD: boolean
69
- RA: boolean
70
- AD: boolean
71
- CD: boolean
72
- Question: DnsQuestionItem[]
73
- Answer?: DnsResponseItem[]
74
- Authority?: DnsResponseItem[]
75
- Additional?: DnsResponseItem[]
76
- Comment?: string
77
- }
24
+ export type GetDnsOwnerReturnType = Address | null
78
25
 
79
26
  /**
80
27
  * Gets the DNS owner of a name, via DNS record lookup
@@ -89,7 +36,8 @@ type DnsResponse = {
89
36
  */
90
37
  const getDnsOwner = async ({
91
38
  name,
92
- endpoint = 'https://cloudflare-dns.com/dns-query',
39
+ endpoint,
40
+ strict,
93
41
  }: GetDnsOwnerParameters): Promise<GetDnsOwnerReturnType> => {
94
42
  const nameType = getNameType(name)
95
43
 
@@ -99,43 +47,43 @@ const getDnsOwner = async ({
99
47
  supportedNameTypes: ['other-2ld'],
100
48
  })
101
49
 
102
- const response: DnsResponse = await fetch(
103
- `${endpoint}?name=_ens.${name}.&type=TXT`,
104
- {
105
- method: 'GET',
106
- headers: {
107
- accept: 'application/dns-json',
108
- },
109
- },
110
- ).then((res) => res.json())
50
+ try {
51
+ const response = await getDnsTxtRecords({ name: `_ens.${name}`, endpoint })
111
52
 
112
- if (response.Status !== DnsResponseStatus.NOERROR)
113
- throw new DnsResponseStatusError({
114
- responseStatus: DnsResponseStatus[response.Status],
115
- })
53
+ if (response.Status !== DnsResponseStatus.NOERROR)
54
+ throw new DnsResponseStatusError({
55
+ responseStatus: DnsResponseStatus[response.Status],
56
+ })
116
57
 
117
- const addressRecord = response.Answer?.find(
118
- (record) => record.type === DnsRecordType.TXT,
119
- )
120
- const unwrappedAddressRecord = addressRecord?.data?.replace(/^"(.*)"$/g, '$1')
58
+ const addressRecord = response.Answer?.find(
59
+ (record) => record.type === DnsRecordType.TXT,
60
+ )
61
+ const unwrappedAddressRecord = addressRecord?.data?.replace(
62
+ /^"(.*)"$/g,
63
+ '$1',
64
+ )
121
65
 
122
- if (response.AD === false)
123
- throw new DnsDnssecVerificationFailedError({
124
- record: unwrappedAddressRecord,
125
- })
66
+ if (response.AD === false)
67
+ throw new DnsDnssecVerificationFailedError({
68
+ record: unwrappedAddressRecord,
69
+ })
126
70
 
127
- if (!addressRecord?.data) throw new DnsNoTxtRecordError()
71
+ if (!addressRecord?.data) throw new DnsNoTxtRecordError()
128
72
 
129
- if (!unwrappedAddressRecord!.match(/^a=0x[a-fA-F0-9]{40}$/g))
130
- throw new DnsInvalidTxtRecordError({ record: unwrappedAddressRecord! })
73
+ if (!unwrappedAddressRecord!.match(/^a=0x[a-fA-F0-9]{40}$/g))
74
+ throw new DnsInvalidTxtRecordError({ record: unwrappedAddressRecord! })
131
75
 
132
- const address = unwrappedAddressRecord!.slice(2)
133
- const checksumAddress = getAddress(address)
76
+ const address = unwrappedAddressRecord!.slice(2)
77
+ const checksumAddress = getAddress(address)
134
78
 
135
- if (address !== checksumAddress)
136
- throw new DnsInvalidAddressChecksumError({ address })
79
+ if (address !== checksumAddress)
80
+ throw new DnsInvalidAddressChecksumError({ address })
137
81
 
138
- return checksumAddress
82
+ return checksumAddress
83
+ } catch (error) {
84
+ if (!strict) return null
85
+ throw error
86
+ }
139
87
  }
140
88
 
141
89
  export default getDnsOwner
@@ -0,0 +1,38 @@
1
+ import type { Endpoint } from '../../functions/dns/types.js'
2
+ import { type DnsResponse } from './misc.js'
3
+
4
+ export type GetDnsTxtRecordsParameters = {
5
+ /** Name to get the txt records for */
6
+ name: string
7
+ /** An RFC-1035 compatible DNS endpoint to use (default: `https://cloudflare-dns.com/dns-query`) */
8
+ endpoint?: Endpoint
9
+ }
10
+
11
+ export type GetDnsTxtRecordsReturnType = DnsResponse
12
+
13
+ /**
14
+ * Gets the DNS record response of a name, via DNS record lookup
15
+ * @param parameters - {@link GetDnsTxtRecordsParameters}
16
+ * @returns DNS response. {@link GetDnsTxtRecordsReturnType}
17
+ *
18
+ * @example
19
+ * import { getDnsTxtRecords } from '@ensdomains/ensjs/utils'
20
+ *
21
+ * const owner = await getDnsTxtRecords({ name: '_ens.ens.domains' })
22
+ */
23
+ export const getDnsTxtRecords = async ({
24
+ name,
25
+ endpoint = 'https://cloudflare-dns.com/dns-query',
26
+ }: GetDnsTxtRecordsParameters): Promise<GetDnsTxtRecordsReturnType> => {
27
+ const response: DnsResponse = await fetch(
28
+ `${endpoint}?name=${name}.&type=TXT`,
29
+ {
30
+ method: 'GET',
31
+ headers: {
32
+ accept: 'application/dns-json',
33
+ },
34
+ },
35
+ ).then((res) => res.json())
36
+
37
+ return response
38
+ }
@@ -0,0 +1,53 @@
1
+ export enum DnsResponseStatus {
2
+ NOERROR = 0,
3
+ FORMERR = 1,
4
+ SERVFAIL = 2,
5
+ NXDOMAIN = 3,
6
+ NOTIMP = 4,
7
+ REFUSED = 5,
8
+ YXDOMAIN = 6,
9
+ YXRRSET = 7,
10
+ NXRRSET = 8,
11
+ NOTAUTH = 9,
12
+ NOTZONE = 10,
13
+ DSOTYPENI = 11,
14
+ BADVERS = 16, // also 16 = BADSIG but not important
15
+ BADKEY = 17,
16
+ BADTIME = 18,
17
+ BADMODE = 19,
18
+ BADNAME = 20,
19
+ BADALG = 21,
20
+ BADTRUNC = 22,
21
+ BADCOOKIE = 23,
22
+ }
23
+
24
+ export enum DnsRecordType {
25
+ TXT = 16,
26
+ DS = 43,
27
+ RRSIG = 46,
28
+ DNSKEY = 48,
29
+ }
30
+
31
+ export type DnsQuestionItem = {
32
+ name: string
33
+ type: DnsRecordType
34
+ }
35
+
36
+ export type DnsResponseItem = DnsQuestionItem & {
37
+ TTL: number
38
+ data: string
39
+ }
40
+
41
+ export type DnsResponse = {
42
+ Status: DnsResponseStatus
43
+ TC: boolean
44
+ RD: boolean
45
+ RA: boolean
46
+ AD: boolean
47
+ CD: boolean
48
+ Question: DnsQuestionItem[]
49
+ Answer?: DnsResponseItem[]
50
+ Authority?: DnsResponseItem[]
51
+ Additional?: DnsResponseItem[]
52
+ Comment?: string
53
+ }
@@ -1,3 +1,15 @@
1
+ export {
2
+ getDnsTxtRecords,
3
+ type GetDnsTxtRecordsParameters,
4
+ type GetDnsTxtRecordsReturnType,
5
+ } from './dns/getDnsTxtRecords.js'
6
+ export {
7
+ DnsRecordType,
8
+ DnsResponseStatus,
9
+ type DnsQuestionItem,
10
+ type DnsResponse,
11
+ type DnsResponseItem,
12
+ } from './dns/misc.js'
1
13
  export {
2
14
  contentTypeToEncodeAs,
3
15
  encodeAbi,