@ensdomains/ensjs 4.3.0 → 4.3.1
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.
|
@@ -1,11 +1,26 @@
|
|
|
1
1
|
import { evmChainIdToCoinType } from '@ensdomains/address-encoder/utils';
|
|
2
2
|
import { decodeErrorResult, decodeFunctionResult, encodeFunctionData, zeroAddress, } from 'viem';
|
|
3
|
+
import { normalize } from 'viem/ens';
|
|
3
4
|
import { getChainContractAddress } from '../../contracts/getChainContractAddress.js';
|
|
4
5
|
import { universalResolverReverseSnippet, universalResolverReverseWithGatewaysSnippet, } from '../../contracts/universalResolver.js';
|
|
5
6
|
import { checkSafeUniversalResolverData } from '../../utils/checkSafeUniversalResolverData.js';
|
|
6
7
|
import { generateFunction, } from '../../utils/generateFunction.js';
|
|
7
8
|
import { getRevertErrorData } from '../../utils/getRevertErrorData.js';
|
|
8
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Checks whether a name is already normalised, without coercing it.
|
|
11
|
+
*
|
|
12
|
+
* Mirrors viem's `getEnsName` normalization enforcement (wevm/viem#4756):
|
|
13
|
+
* a name is only returned if it is already in its normalised form. Returns
|
|
14
|
+
* `false` if the name cannot be normalised (i.e. `normalize` throws).
|
|
15
|
+
*/
|
|
16
|
+
const isNormalised = (name) => {
|
|
17
|
+
try {
|
|
18
|
+
return name === normalize(name);
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
9
24
|
const encode = (client, { address, coinType, chainId, gatewayUrls, }) => {
|
|
10
25
|
const to = getChainContractAddress({
|
|
11
26
|
client,
|
|
@@ -65,8 +80,11 @@ const decode = async (_client, data, passthrough, { allowMismatch, strict, gatew
|
|
|
65
80
|
});
|
|
66
81
|
if (decodedError.errorName !== 'ReverseAddressMismatch')
|
|
67
82
|
return null;
|
|
83
|
+
const [name] = decodedError.args;
|
|
84
|
+
if (!isNormalised(name))
|
|
85
|
+
return null;
|
|
68
86
|
return {
|
|
69
|
-
name
|
|
87
|
+
name,
|
|
70
88
|
match: false,
|
|
71
89
|
reverseResolverAddress: zeroAddress,
|
|
72
90
|
resolverAddress: zeroAddress,
|
|
@@ -84,9 +102,10 @@ const decode = async (_client, data, passthrough, { allowMismatch, strict, gatew
|
|
|
84
102
|
});
|
|
85
103
|
if (!unnormalisedName)
|
|
86
104
|
return null;
|
|
87
|
-
|
|
105
|
+
if (!isNormalised(unnormalisedName))
|
|
106
|
+
return null;
|
|
88
107
|
return {
|
|
89
|
-
name:
|
|
108
|
+
name: unnormalisedName,
|
|
90
109
|
match: true,
|
|
91
110
|
reverseResolverAddress,
|
|
92
111
|
resolverAddress,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getName.js","sourceRoot":"","sources":["../../../src/functions/public/getName.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAA;AACxE,OAAO,EAIL,iBAAiB,EACjB,oBAAoB,EACpB,kBAAkB,EAClB,WAAW,GACZ,MAAM,MAAM,CAAA;
|
|
1
|
+
{"version":3,"file":"getName.js","sourceRoot":"","sources":["../../../src/functions/public/getName.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAA;AACxE,OAAO,EAIL,iBAAiB,EACjB,oBAAoB,EACpB,kBAAkB,EAClB,WAAW,GACZ,MAAM,MAAM,CAAA;AACb,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAEpC,OAAO,EAAE,uBAAuB,EAAE,MAAM,4CAA4C,CAAA;AACpF,OAAO,EACL,+BAA+B,EAC/B,2CAA2C,GAC5C,MAAM,sCAAsC,CAAA;AAK7C,OAAO,EAAE,8BAA8B,EAAE,MAAM,+CAA+C,CAAA;AAC9F,OAAO,EAEL,gBAAgB,GACjB,MAAM,iCAAiC,CAAA;AACxC,OAAO,EAAE,kBAAkB,EAAE,MAAM,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,IAAI,CAAC,YAAY,CAAC,gBAAgB,CAAC;YAAE,OAAO,IAAI,CAAA;QAChD,OAAO;YACL,IAAI,EAAE,gBAAgB;YACtB,KAAK,EAAE,IAAI;YACX,sBAAsB;YACtB,eAAe;SAChB,CAAA;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,MAAM;YAAE,MAAM,KAAK,CAAA;QACvB,OAAO,IAAI,CAAA;IACb,CAAC;AACH,CAAC,CAAA;AAID;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,OAAO,GAAG,gBAAgB,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,CAI1B,CAAA;AAEzB,eAAe,OAAO,CAAA"}
|
package/package.json
CHANGED
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
encodeFunctionData,
|
|
9
9
|
zeroAddress,
|
|
10
10
|
} from 'viem'
|
|
11
|
+
import { normalize } from 'viem/ens'
|
|
11
12
|
import type { ClientWithEns } from '../../contracts/consts.js'
|
|
12
13
|
import { getChainContractAddress } from '../../contracts/getChainContractAddress.js'
|
|
13
14
|
import {
|
|
@@ -24,7 +25,21 @@ import {
|
|
|
24
25
|
generateFunction,
|
|
25
26
|
} from '../../utils/generateFunction.js'
|
|
26
27
|
import { getRevertErrorData } from '../../utils/getRevertErrorData.js'
|
|
27
|
-
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Checks whether a name is already normalised, without coercing it.
|
|
31
|
+
*
|
|
32
|
+
* Mirrors viem's `getEnsName` normalization enforcement (wevm/viem#4756):
|
|
33
|
+
* a name is only returned if it is already in its normalised form. Returns
|
|
34
|
+
* `false` if the name cannot be normalised (i.e. `normalize` throws).
|
|
35
|
+
*/
|
|
36
|
+
const isNormalised = (name: string): boolean => {
|
|
37
|
+
try {
|
|
38
|
+
return name === normalize(name)
|
|
39
|
+
} catch {
|
|
40
|
+
return false
|
|
41
|
+
}
|
|
42
|
+
}
|
|
28
43
|
|
|
29
44
|
type GetNameCoinTypeParameters = {
|
|
30
45
|
coinType: number
|
|
@@ -134,8 +149,10 @@ const decode = async (
|
|
|
134
149
|
data: errorData,
|
|
135
150
|
})
|
|
136
151
|
if (decodedError.errorName !== 'ReverseAddressMismatch') return null
|
|
152
|
+
const [name] = decodedError.args
|
|
153
|
+
if (!isNormalised(name)) return null
|
|
137
154
|
return {
|
|
138
|
-
name
|
|
155
|
+
name,
|
|
139
156
|
match: false,
|
|
140
157
|
reverseResolverAddress: zeroAddress,
|
|
141
158
|
resolverAddress: zeroAddress,
|
|
@@ -155,9 +172,9 @@ const decode = async (
|
|
|
155
172
|
|
|
156
173
|
if (!unnormalisedName) return null
|
|
157
174
|
|
|
158
|
-
|
|
175
|
+
if (!isNormalised(unnormalisedName)) return null
|
|
159
176
|
return {
|
|
160
|
-
name:
|
|
177
|
+
name: unnormalisedName,
|
|
161
178
|
match: true,
|
|
162
179
|
reverseResolverAddress,
|
|
163
180
|
resolverAddress,
|