@ensdomains/ensjs 3.0.1 → 3.2.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.
- package/dist/cjs/clients/decorators/public.js.map +1 -1
- package/dist/cjs/contracts/consts.js +3 -3
- package/dist/cjs/contracts/universalResolver.js +92 -59
- package/dist/cjs/contracts/universalResolver.js.map +1 -1
- package/dist/cjs/errors/version.js +1 -1
- package/dist/cjs/functions/public/_getAbi.js +52 -45
- package/dist/cjs/functions/public/_getAbi.js.map +1 -1
- package/dist/cjs/functions/public/_getAddr.js +30 -23
- package/dist/cjs/functions/public/_getAddr.js.map +1 -1
- package/dist/cjs/functions/public/_getContentHash.js +14 -7
- package/dist/cjs/functions/public/_getContentHash.js.map +1 -1
- package/dist/cjs/functions/public/_getText.js +15 -8
- package/dist/cjs/functions/public/_getText.js.map +1 -1
- package/dist/cjs/functions/public/getAbiRecord.js +13 -5
- package/dist/cjs/functions/public/getAbiRecord.js.map +1 -1
- package/dist/cjs/functions/public/getAddressRecord.js +13 -5
- package/dist/cjs/functions/public/getAddressRecord.js.map +1 -1
- package/dist/cjs/functions/public/getContentHashRecord.js +13 -5
- package/dist/cjs/functions/public/getContentHashRecord.js.map +1 -1
- package/dist/cjs/functions/public/getName.js +53 -35
- package/dist/cjs/functions/public/getName.js.map +1 -1
- package/dist/cjs/functions/public/getRecords.js +164 -161
- package/dist/cjs/functions/public/getRecords.js.map +1 -1
- package/dist/cjs/functions/public/getTextRecord.js +13 -5
- package/dist/cjs/functions/public/getTextRecord.js.map +1 -1
- package/dist/cjs/functions/public/universalWrapper.js +45 -37
- package/dist/cjs/functions/public/universalWrapper.js.map +1 -1
- package/dist/cjs/functions/wallet/setAbiRecord.js +1 -2
- package/dist/cjs/functions/wallet/setAbiRecord.js.map +1 -1
- package/dist/cjs/utils/checkSafeUniversalResolverData.js +35 -0
- package/dist/cjs/utils/checkSafeUniversalResolverData.js.map +1 -0
- package/dist/cjs/utils/encoders/encodeAbi.js +13 -7
- package/dist/cjs/utils/encoders/encodeAbi.js.map +1 -1
- package/dist/cjs/utils/encoders/encodeSetAbi.js +1 -1
- package/dist/cjs/utils/encoders/encodeSetAbi.js.map +1 -1
- package/dist/cjs/utils/generateRecordCallArray.js +1 -2
- package/dist/cjs/utils/generateRecordCallArray.js.map +1 -1
- package/dist/esm/clients/decorators/public.js.map +1 -1
- package/dist/esm/contracts/consts.js +3 -3
- package/dist/esm/contracts/universalResolver.js +92 -59
- package/dist/esm/contracts/universalResolver.js.map +1 -1
- package/dist/esm/errors/version.js +1 -1
- package/dist/esm/functions/public/_getAbi.js +56 -49
- package/dist/esm/functions/public/_getAbi.js.map +1 -1
- package/dist/esm/functions/public/_getAddr.js +30 -23
- package/dist/esm/functions/public/_getAddr.js.map +1 -1
- package/dist/esm/functions/public/_getContentHash.js +14 -7
- package/dist/esm/functions/public/_getContentHash.js.map +1 -1
- package/dist/esm/functions/public/_getText.js +15 -8
- package/dist/esm/functions/public/_getText.js.map +1 -1
- package/dist/esm/functions/public/getAbiRecord.js +13 -5
- package/dist/esm/functions/public/getAbiRecord.js.map +1 -1
- package/dist/esm/functions/public/getAddressRecord.js +13 -5
- package/dist/esm/functions/public/getAddressRecord.js.map +1 -1
- package/dist/esm/functions/public/getContentHashRecord.js +13 -5
- package/dist/esm/functions/public/getContentHashRecord.js.map +1 -1
- package/dist/esm/functions/public/getName.js +54 -36
- package/dist/esm/functions/public/getName.js.map +1 -1
- package/dist/esm/functions/public/getRecords.js +168 -165
- package/dist/esm/functions/public/getRecords.js.map +1 -1
- package/dist/esm/functions/public/getTextRecord.js +13 -5
- package/dist/esm/functions/public/getTextRecord.js.map +1 -1
- package/dist/esm/functions/public/universalWrapper.js +46 -38
- package/dist/esm/functions/public/universalWrapper.js.map +1 -1
- package/dist/esm/functions/wallet/setAbiRecord.js +1 -2
- package/dist/esm/functions/wallet/setAbiRecord.js.map +1 -1
- package/dist/esm/utils/checkSafeUniversalResolverData.js +39 -0
- package/dist/esm/utils/checkSafeUniversalResolverData.js.map +1 -0
- package/dist/esm/utils/encoders/encodeAbi.js +13 -7
- package/dist/esm/utils/encoders/encodeAbi.js.map +1 -1
- package/dist/esm/utils/encoders/encodeSetAbi.js +1 -1
- package/dist/esm/utils/encoders/encodeSetAbi.js.map +1 -1
- package/dist/esm/utils/generateRecordCallArray.js +1 -2
- package/dist/esm/utils/generateRecordCallArray.js.map +1 -1
- package/dist/types/clients/decorators/public.d.ts +6 -6
- package/dist/types/clients/decorators/public.d.ts.map +1 -1
- package/dist/types/clients/public.d.ts +34 -8
- package/dist/types/clients/public.d.ts.map +1 -1
- package/dist/types/clients/wallet.d.ts +4 -4
- package/dist/types/contracts/consts.d.ts +3 -3
- package/dist/types/contracts/universalResolver.d.ts +73 -0
- package/dist/types/contracts/universalResolver.d.ts.map +1 -1
- package/dist/types/errors/version.d.ts +1 -1
- package/dist/types/functions/public/_getAbi.d.ts +3 -1
- package/dist/types/functions/public/_getAbi.d.ts.map +1 -1
- package/dist/types/functions/public/_getAddr.d.ts +3 -1
- package/dist/types/functions/public/_getAddr.d.ts.map +1 -1
- package/dist/types/functions/public/_getContentHash.d.ts +3 -1
- package/dist/types/functions/public/_getContentHash.d.ts.map +1 -1
- package/dist/types/functions/public/_getText.d.ts +3 -1
- package/dist/types/functions/public/_getText.d.ts.map +1 -1
- package/dist/types/functions/public/getAbiRecord.d.ts +8 -5
- package/dist/types/functions/public/getAbiRecord.d.ts.map +1 -1
- package/dist/types/functions/public/getAddressRecord.d.ts +8 -5
- package/dist/types/functions/public/getAddressRecord.d.ts.map +1 -1
- package/dist/types/functions/public/getContentHashRecord.d.ts +7 -4
- package/dist/types/functions/public/getContentHashRecord.d.ts.map +1 -1
- package/dist/types/functions/public/getName.d.ts +9 -3
- package/dist/types/functions/public/getName.d.ts.map +1 -1
- package/dist/types/functions/public/getRecords.d.ts +53 -26
- package/dist/types/functions/public/getRecords.d.ts.map +1 -1
- package/dist/types/functions/public/getTextRecord.d.ts +7 -4
- package/dist/types/functions/public/getTextRecord.d.ts.map +1 -1
- package/dist/types/functions/public/universalWrapper.d.ts +4 -2
- package/dist/types/functions/public/universalWrapper.d.ts.map +1 -1
- package/dist/types/functions/wallet/setAbiRecord.d.ts +1 -1
- package/dist/types/functions/wallet/setAbiRecord.d.ts.map +1 -1
- package/dist/types/types.d.ts +2 -2
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/utils/checkSafeUniversalResolverData.d.ts +14 -0
- package/dist/types/utils/checkSafeUniversalResolverData.d.ts.map +1 -0
- package/dist/types/utils/encoders/encodeAbi.d.ts +2 -2
- package/dist/types/utils/encoders/encodeAbi.d.ts.map +1 -1
- package/dist/types/utils/encoders/encodeSetAbi.d.ts +1 -4
- package/dist/types/utils/encoders/encodeSetAbi.d.ts.map +1 -1
- package/dist/types/utils/generateRecordCallArray.d.ts +2 -2
- package/dist/types/utils/generateRecordCallArray.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/clients/decorators/public.ts +31 -4
- package/src/contracts/consts.ts +3 -3
- package/src/contracts/universalResolver.ts +95 -59
- package/src/errors/version.ts +1 -1
- package/src/functions/public/_getAbi.ts +61 -53
- package/src/functions/public/_getAddr.ts +31 -24
- package/src/functions/public/_getContentHash.ts +15 -7
- package/src/functions/public/_getText.ts +16 -8
- package/src/functions/public/getAbiRecord.ts +21 -8
- package/src/functions/public/getAddressRecord.ts +25 -9
- package/src/functions/public/getContentHashRecord.ts +19 -7
- package/src/functions/public/getName.ts +58 -40
- package/src/functions/public/getRecords.ts +336 -235
- package/src/functions/public/getTextRecord.ts +19 -6
- package/src/functions/public/universalWrapper.ts +49 -43
- package/src/functions/wallet/setAbiRecord.ts +2 -3
- package/src/types.ts +4 -3
- package/src/utils/checkSafeUniversalResolverData.ts +62 -0
- package/src/utils/encoders/encodeAbi.ts +13 -9
- package/src/utils/encoders/encodeSetAbi.ts +2 -2
- package/src/utils/generateRecordCallArray.ts +2 -3
|
@@ -46,92 +46,128 @@ export const universalResolverErrors = [
|
|
|
46
46
|
},
|
|
47
47
|
] as const
|
|
48
48
|
|
|
49
|
+
const universalResolverReverse = {
|
|
50
|
+
inputs: [
|
|
51
|
+
{
|
|
52
|
+
name: 'reverseName',
|
|
53
|
+
type: 'bytes',
|
|
54
|
+
},
|
|
55
|
+
],
|
|
56
|
+
name: 'reverse',
|
|
57
|
+
outputs: [
|
|
58
|
+
{ type: 'string', name: 'resolvedName' },
|
|
59
|
+
{ type: 'address', name: 'resolvedAddress' },
|
|
60
|
+
{ type: 'address', name: 'reverseResolver' },
|
|
61
|
+
{ type: 'address', name: 'resolver' },
|
|
62
|
+
],
|
|
63
|
+
stateMutability: 'view',
|
|
64
|
+
type: 'function',
|
|
65
|
+
} as const
|
|
66
|
+
|
|
49
67
|
export const universalResolverReverseSnippet = [
|
|
50
68
|
...universalResolverErrors,
|
|
69
|
+
universalResolverReverse,
|
|
51
70
|
{
|
|
71
|
+
...universalResolverReverse,
|
|
52
72
|
inputs: [
|
|
73
|
+
...universalResolverReverse.inputs,
|
|
53
74
|
{
|
|
54
|
-
name: '
|
|
55
|
-
type: '
|
|
75
|
+
name: 'gateways',
|
|
76
|
+
type: 'string[]',
|
|
56
77
|
},
|
|
57
78
|
],
|
|
58
|
-
name: 'reverse',
|
|
59
|
-
outputs: [
|
|
60
|
-
{ type: 'string', name: 'resolvedName' },
|
|
61
|
-
{ type: 'address', name: 'resolvedAddress' },
|
|
62
|
-
{ type: 'address', name: 'reverseResolver' },
|
|
63
|
-
{ type: 'address', name: 'resolver' },
|
|
64
|
-
],
|
|
65
|
-
stateMutability: 'view',
|
|
66
|
-
type: 'function',
|
|
67
79
|
},
|
|
68
80
|
] as const
|
|
69
81
|
|
|
82
|
+
const universalResolverResolve = {
|
|
83
|
+
inputs: [
|
|
84
|
+
{
|
|
85
|
+
name: 'name',
|
|
86
|
+
type: 'bytes',
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
name: 'data',
|
|
90
|
+
type: 'bytes',
|
|
91
|
+
},
|
|
92
|
+
],
|
|
93
|
+
name: 'resolve',
|
|
94
|
+
outputs: [
|
|
95
|
+
{
|
|
96
|
+
name: 'data',
|
|
97
|
+
type: 'bytes',
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
name: 'resolver',
|
|
101
|
+
type: 'address',
|
|
102
|
+
},
|
|
103
|
+
],
|
|
104
|
+
stateMutability: 'view',
|
|
105
|
+
type: 'function',
|
|
106
|
+
} as const
|
|
107
|
+
|
|
70
108
|
export const universalResolverResolveSnippet = [
|
|
71
109
|
...universalResolverErrors,
|
|
110
|
+
universalResolverResolve,
|
|
72
111
|
{
|
|
112
|
+
...universalResolverResolve,
|
|
73
113
|
inputs: [
|
|
114
|
+
...universalResolverResolve.inputs,
|
|
74
115
|
{
|
|
75
|
-
name: '
|
|
76
|
-
type: '
|
|
77
|
-
},
|
|
78
|
-
{
|
|
79
|
-
name: 'data',
|
|
80
|
-
type: 'bytes',
|
|
116
|
+
name: 'gateways',
|
|
117
|
+
type: 'string[]',
|
|
81
118
|
},
|
|
82
119
|
],
|
|
83
|
-
name: 'resolve',
|
|
84
|
-
outputs: [
|
|
85
|
-
{
|
|
86
|
-
name: 'data',
|
|
87
|
-
type: 'bytes',
|
|
88
|
-
},
|
|
89
|
-
{
|
|
90
|
-
name: 'resolver',
|
|
91
|
-
type: 'address',
|
|
92
|
-
},
|
|
93
|
-
],
|
|
94
|
-
stateMutability: 'view',
|
|
95
|
-
type: 'function',
|
|
96
120
|
},
|
|
97
121
|
] as const
|
|
98
122
|
|
|
123
|
+
const universalResolverResolveArray = {
|
|
124
|
+
inputs: [
|
|
125
|
+
{
|
|
126
|
+
name: 'name',
|
|
127
|
+
type: 'bytes',
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
name: 'data',
|
|
131
|
+
type: 'bytes[]',
|
|
132
|
+
},
|
|
133
|
+
],
|
|
134
|
+
name: 'resolve',
|
|
135
|
+
outputs: [
|
|
136
|
+
{
|
|
137
|
+
components: [
|
|
138
|
+
{
|
|
139
|
+
name: 'success',
|
|
140
|
+
type: 'bool',
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
name: 'returnData',
|
|
144
|
+
type: 'bytes',
|
|
145
|
+
},
|
|
146
|
+
],
|
|
147
|
+
name: '',
|
|
148
|
+
type: 'tuple[]',
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
name: '',
|
|
152
|
+
type: 'address',
|
|
153
|
+
},
|
|
154
|
+
],
|
|
155
|
+
stateMutability: 'view',
|
|
156
|
+
type: 'function',
|
|
157
|
+
} as const
|
|
158
|
+
|
|
99
159
|
export const universalResolverResolveArraySnippet = [
|
|
100
160
|
...universalResolverErrors,
|
|
161
|
+
universalResolverResolveArray,
|
|
101
162
|
{
|
|
163
|
+
...universalResolverResolveArray,
|
|
102
164
|
inputs: [
|
|
165
|
+
...universalResolverResolveArray.inputs,
|
|
103
166
|
{
|
|
104
|
-
name: '
|
|
105
|
-
type: '
|
|
106
|
-
},
|
|
107
|
-
{
|
|
108
|
-
name: 'data',
|
|
109
|
-
type: 'bytes[]',
|
|
110
|
-
},
|
|
111
|
-
],
|
|
112
|
-
name: 'resolve',
|
|
113
|
-
outputs: [
|
|
114
|
-
{
|
|
115
|
-
components: [
|
|
116
|
-
{
|
|
117
|
-
name: 'success',
|
|
118
|
-
type: 'bool',
|
|
119
|
-
},
|
|
120
|
-
{
|
|
121
|
-
name: 'returnData',
|
|
122
|
-
type: 'bytes',
|
|
123
|
-
},
|
|
124
|
-
],
|
|
125
|
-
name: '',
|
|
126
|
-
type: 'tuple[]',
|
|
127
|
-
},
|
|
128
|
-
{
|
|
129
|
-
name: '',
|
|
130
|
-
type: 'address',
|
|
167
|
+
name: 'gateways',
|
|
168
|
+
type: 'string[]',
|
|
131
169
|
},
|
|
132
170
|
],
|
|
133
|
-
stateMutability: 'view',
|
|
134
|
-
type: 'function',
|
|
135
171
|
},
|
|
136
172
|
] as const
|
|
137
173
|
|
package/src/errors/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = 'v3.0
|
|
1
|
+
export const version = 'v3.2.0'
|
|
@@ -19,6 +19,8 @@ import { namehash } from '../../utils/normalise.js'
|
|
|
19
19
|
export type InternalGetAbiParameters = {
|
|
20
20
|
/** Name to get ABI record for */
|
|
21
21
|
name: string
|
|
22
|
+
/** Whether or not to throw decoding errors */
|
|
23
|
+
strict?: boolean
|
|
22
24
|
}
|
|
23
25
|
|
|
24
26
|
export type InternalGetAbiReturnType = Prettify<DecodedAbi | null>
|
|
@@ -28,11 +30,11 @@ export type InternalGetAbiReturnType = Prettify<DecodedAbi | null>
|
|
|
28
30
|
// ID 2: zlib compressed JSON
|
|
29
31
|
// ID 4: CBOR
|
|
30
32
|
// ID 8: URI
|
|
31
|
-
const supportedContentTypes =
|
|
33
|
+
const supportedContentTypes = 0xfn
|
|
32
34
|
|
|
33
35
|
const encode = (
|
|
34
36
|
_client: ClientWithEns,
|
|
35
|
-
{ name }: InternalGetAbiParameters,
|
|
37
|
+
{ name }: Omit<InternalGetAbiParameters, 'strict'>,
|
|
36
38
|
): SimpleTransactionRequest => {
|
|
37
39
|
return {
|
|
38
40
|
to: EMPTY_ADDRESS,
|
|
@@ -47,66 +49,72 @@ const encode = (
|
|
|
47
49
|
const decode = async (
|
|
48
50
|
_client: ClientWithEns,
|
|
49
51
|
data: Hex,
|
|
52
|
+
{ strict }: Pick<InternalGetAbiParameters, 'strict'>,
|
|
50
53
|
): Promise<InternalGetAbiReturnType> => {
|
|
51
54
|
if (data === '0x') return null
|
|
52
55
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
if (!bigintContentType || !encodedAbiData) {
|
|
60
|
-
return null
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const contentType = Number(bigintContentType)
|
|
64
|
-
if (!contentType) {
|
|
65
|
-
return null
|
|
66
|
-
}
|
|
56
|
+
try {
|
|
57
|
+
const [bigintContentType, encodedAbiData] = decodeFunctionResult({
|
|
58
|
+
abi: publicResolverAbiSnippet,
|
|
59
|
+
functionName: 'ABI',
|
|
60
|
+
data,
|
|
61
|
+
})
|
|
67
62
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
switch (contentType) {
|
|
71
|
-
// JSON
|
|
72
|
-
case 1:
|
|
73
|
-
abiData = JSON.parse(hexToString(encodedAbiData))
|
|
74
|
-
decoded = true
|
|
75
|
-
break
|
|
76
|
-
// zlib compressed JSON
|
|
77
|
-
case 2: {
|
|
78
|
-
const { inflate } = await import('pako/dist/pako_inflate.min.js')
|
|
79
|
-
abiData = JSON.parse(
|
|
80
|
-
inflate(hexToBytes(encodedAbiData), { to: 'string' }),
|
|
81
|
-
)
|
|
82
|
-
decoded = true
|
|
83
|
-
break
|
|
63
|
+
if (!bigintContentType || !encodedAbiData) {
|
|
64
|
+
return null
|
|
84
65
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
decoded = true
|
|
90
|
-
break
|
|
66
|
+
|
|
67
|
+
const contentType = Number(bigintContentType)
|
|
68
|
+
if (!contentType) {
|
|
69
|
+
return null
|
|
91
70
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
abiData = hexToString(encodedAbiData)
|
|
71
|
+
|
|
72
|
+
let abiData: string | object
|
|
73
|
+
let decoded = false
|
|
74
|
+
switch (contentType) {
|
|
75
|
+
// JSON
|
|
76
|
+
case 1:
|
|
77
|
+
abiData = JSON.parse(hexToString(encodedAbiData))
|
|
100
78
|
decoded = true
|
|
101
|
-
|
|
102
|
-
|
|
79
|
+
break
|
|
80
|
+
// zlib compressed JSON
|
|
81
|
+
case 2: {
|
|
82
|
+
const { inflate } = await import('pako/dist/pako_inflate.min.js')
|
|
83
|
+
abiData = JSON.parse(
|
|
84
|
+
inflate(hexToBytes(encodedAbiData), { to: 'string' }),
|
|
85
|
+
)
|
|
86
|
+
decoded = true
|
|
87
|
+
break
|
|
103
88
|
}
|
|
104
|
-
|
|
89
|
+
// CBOR
|
|
90
|
+
case 4: {
|
|
91
|
+
const { cborDecode } = await import('@ensdomains/address-encoder/utils')
|
|
92
|
+
abiData = await cborDecode(hexToBytes(encodedAbiData).buffer)
|
|
93
|
+
decoded = true
|
|
94
|
+
break
|
|
95
|
+
}
|
|
96
|
+
// URI
|
|
97
|
+
case 8:
|
|
98
|
+
abiData = hexToString(encodedAbiData)
|
|
99
|
+
decoded = true
|
|
100
|
+
break
|
|
101
|
+
default:
|
|
102
|
+
try {
|
|
103
|
+
abiData = hexToString(encodedAbiData)
|
|
104
|
+
decoded = true
|
|
105
|
+
} catch {
|
|
106
|
+
abiData = encodedAbiData
|
|
107
|
+
}
|
|
108
|
+
}
|
|
105
109
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
+
return {
|
|
111
|
+
contentType,
|
|
112
|
+
decoded,
|
|
113
|
+
abi: abiData,
|
|
114
|
+
}
|
|
115
|
+
} catch (error) {
|
|
116
|
+
if (strict) throw error
|
|
117
|
+
return null
|
|
110
118
|
}
|
|
111
119
|
}
|
|
112
120
|
|
|
@@ -28,13 +28,15 @@ export type InternalGetAddrParameters = {
|
|
|
28
28
|
coin?: string | number
|
|
29
29
|
/** Optionally return raw bytes value of address record (default: false) */
|
|
30
30
|
bypassFormat?: boolean
|
|
31
|
+
/** Whether or not to throw decoding errors */
|
|
32
|
+
strict?: boolean
|
|
31
33
|
}
|
|
32
34
|
|
|
33
35
|
export type InternalGetAddrReturnType = Prettify<DecodedAddr | null>
|
|
34
36
|
|
|
35
37
|
const encode = (
|
|
36
38
|
_client: ClientWithEns,
|
|
37
|
-
{ name, coin = 60, bypassFormat }: InternalGetAddrParameters,
|
|
39
|
+
{ name, coin = 60, bypassFormat }: Omit<InternalGetAddrParameters, 'strict'>,
|
|
38
40
|
): SimpleTransactionRequest => {
|
|
39
41
|
const coder = getCoderFromCoin(coin)
|
|
40
42
|
if (coder.coinType === 60) {
|
|
@@ -72,41 +74,46 @@ const encode = (
|
|
|
72
74
|
const decode = async (
|
|
73
75
|
_client: ClientWithEns,
|
|
74
76
|
data: Hex,
|
|
75
|
-
{ coin = 60 }: InternalGetAddrParameters,
|
|
77
|
+
{ coin = 60, strict }: Pick<InternalGetAddrParameters, 'coin' | 'strict'>,
|
|
76
78
|
): Promise<InternalGetAddrReturnType> => {
|
|
77
79
|
if (data === '0x') return null
|
|
78
80
|
|
|
79
81
|
const coder = getCoderFromCoin(coin)
|
|
80
82
|
let response: Hex
|
|
81
83
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
84
|
+
try {
|
|
85
|
+
if (coder.coinType === 60) {
|
|
86
|
+
response = decodeFunctionResult({
|
|
87
|
+
abi: publicResolverSingleAddrSnippet,
|
|
88
|
+
functionName: 'addr',
|
|
89
|
+
data,
|
|
90
|
+
})
|
|
91
|
+
} else {
|
|
92
|
+
response = decodeFunctionResult({
|
|
93
|
+
abi: publicResolverMultiAddrSnippet,
|
|
94
|
+
functionName: 'addr',
|
|
95
|
+
data,
|
|
96
|
+
})
|
|
97
|
+
}
|
|
95
98
|
|
|
96
|
-
|
|
99
|
+
if (!response) return null
|
|
97
100
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
101
|
+
const trimmed = trim(response)
|
|
102
|
+
if (trimmed === '0x' || trimmed === '0x0' || trimmed === '0x00') {
|
|
103
|
+
return null
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const decodedAddr = coder.encode(hexToBytes(response))
|
|
102
107
|
|
|
103
|
-
|
|
108
|
+
if (!decodedAddr) {
|
|
109
|
+
return null
|
|
110
|
+
}
|
|
104
111
|
|
|
105
|
-
|
|
112
|
+
return { id: coder.coinType, name: coder.name, value: decodedAddr }
|
|
113
|
+
} catch (error) {
|
|
114
|
+
if (strict) throw error
|
|
106
115
|
return null
|
|
107
116
|
}
|
|
108
|
-
|
|
109
|
-
return { id: coder.coinType, name: coder.name, value: decodedAddr }
|
|
110
117
|
}
|
|
111
118
|
|
|
112
119
|
const _getAddr = generateFunction({ encode, decode })
|
|
@@ -13,6 +13,8 @@ import { namehash } from '../../utils/normalise.js'
|
|
|
13
13
|
export type InternalGetContentHashParameters = {
|
|
14
14
|
/** Name to get content hash record for */
|
|
15
15
|
name: string
|
|
16
|
+
/** Whether or not to throw decoding errors */
|
|
17
|
+
strict?: boolean
|
|
16
18
|
}
|
|
17
19
|
|
|
18
20
|
export type InternalGetContentHashReturnType =
|
|
@@ -20,7 +22,7 @@ export type InternalGetContentHashReturnType =
|
|
|
20
22
|
|
|
21
23
|
const encode = (
|
|
22
24
|
_client: ClientWithEns,
|
|
23
|
-
{ name }: InternalGetContentHashParameters,
|
|
25
|
+
{ name }: Omit<InternalGetContentHashParameters, 'strict'>,
|
|
24
26
|
): SimpleTransactionRequest => {
|
|
25
27
|
return {
|
|
26
28
|
to: EMPTY_ADDRESS,
|
|
@@ -35,16 +37,22 @@ const encode = (
|
|
|
35
37
|
const decode = async (
|
|
36
38
|
_client: ClientWithEns,
|
|
37
39
|
data: Hex,
|
|
40
|
+
{ strict }: Pick<InternalGetContentHashParameters, 'strict'>,
|
|
38
41
|
): Promise<InternalGetContentHashReturnType> => {
|
|
39
42
|
if (data === '0x') return null
|
|
40
43
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
try {
|
|
45
|
+
const response = decodeFunctionResult({
|
|
46
|
+
abi: publicResolverContenthashSnippet,
|
|
47
|
+
functionName: 'contenthash',
|
|
48
|
+
data,
|
|
49
|
+
})
|
|
46
50
|
|
|
47
|
-
|
|
51
|
+
return decodeContentHash(response)
|
|
52
|
+
} catch (error) {
|
|
53
|
+
if (strict) throw error
|
|
54
|
+
return null
|
|
55
|
+
}
|
|
48
56
|
}
|
|
49
57
|
|
|
50
58
|
const _getContentHash = generateFunction({ encode, decode })
|
|
@@ -11,13 +11,15 @@ export type InternalGetTextParameters = {
|
|
|
11
11
|
name: string
|
|
12
12
|
/** Text record key to get */
|
|
13
13
|
key: string
|
|
14
|
+
/** Whether or not to throw decoding errors */
|
|
15
|
+
strict?: boolean
|
|
14
16
|
}
|
|
15
17
|
|
|
16
18
|
export type InternalGetTextReturnType = string | null
|
|
17
19
|
|
|
18
20
|
const encode = (
|
|
19
21
|
_client: ClientWithEns,
|
|
20
|
-
{ name, key }: InternalGetTextParameters,
|
|
22
|
+
{ name, key }: Omit<InternalGetTextParameters, 'strict'>,
|
|
21
23
|
): SimpleTransactionRequest => {
|
|
22
24
|
return {
|
|
23
25
|
to: EMPTY_ADDRESS,
|
|
@@ -32,18 +34,24 @@ const encode = (
|
|
|
32
34
|
const decode = async (
|
|
33
35
|
_client: ClientWithEns,
|
|
34
36
|
data: Hex,
|
|
37
|
+
{ strict }: Pick<InternalGetTextParameters, 'strict'>,
|
|
35
38
|
): Promise<InternalGetTextReturnType> => {
|
|
36
39
|
if (data === '0x') return null
|
|
37
40
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
try {
|
|
42
|
+
const response = decodeFunctionResult({
|
|
43
|
+
abi: publicResolverTextSnippet,
|
|
44
|
+
functionName: 'text',
|
|
45
|
+
data,
|
|
46
|
+
})
|
|
43
47
|
|
|
44
|
-
|
|
48
|
+
if (!response) return null
|
|
45
49
|
|
|
46
|
-
|
|
50
|
+
return response
|
|
51
|
+
} catch (error) {
|
|
52
|
+
if (strict) throw error
|
|
53
|
+
return null
|
|
54
|
+
}
|
|
47
55
|
}
|
|
48
56
|
|
|
49
57
|
const _getText = generateFunction({ encode, decode })
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Hex } from 'viem'
|
|
1
|
+
import type { BaseError, Hex } from 'viem'
|
|
2
2
|
import type { ClientWithEns } from '../../contracts/consts.js'
|
|
3
3
|
import type {
|
|
4
4
|
GenericPassthrough,
|
|
@@ -15,25 +15,38 @@ import _getAbi, {
|
|
|
15
15
|
} from './_getAbi.js'
|
|
16
16
|
import universalWrapper from './universalWrapper.js'
|
|
17
17
|
|
|
18
|
-
export type GetAbiRecordParameters = Prettify<
|
|
18
|
+
export type GetAbiRecordParameters = Prettify<
|
|
19
|
+
InternalGetAbiParameters & {
|
|
20
|
+
/** Batch gateway URLs to use for resolving CCIP-read requests. */
|
|
21
|
+
gatewayUrls?: string[]
|
|
22
|
+
}
|
|
23
|
+
>
|
|
19
24
|
|
|
20
25
|
export type GetAbiRecordReturnType = Prettify<InternalGetAbiReturnType>
|
|
21
26
|
|
|
22
27
|
const encode = (
|
|
23
28
|
client: ClientWithEns,
|
|
24
|
-
{ name }: GetAbiRecordParameters,
|
|
29
|
+
{ name, gatewayUrls }: Omit<GetAbiRecordParameters, 'strict'>,
|
|
25
30
|
): SimpleTransactionRequest => {
|
|
26
31
|
const prData = _getAbi.encode(client, { name })
|
|
27
|
-
return universalWrapper.encode(client, {
|
|
32
|
+
return universalWrapper.encode(client, {
|
|
33
|
+
name,
|
|
34
|
+
data: prData.data,
|
|
35
|
+
gatewayUrls,
|
|
36
|
+
})
|
|
28
37
|
}
|
|
29
38
|
|
|
30
39
|
const decode = async (
|
|
31
40
|
client: ClientWithEns,
|
|
32
|
-
data: Hex,
|
|
41
|
+
data: Hex | BaseError,
|
|
33
42
|
passthrough: GenericPassthrough,
|
|
43
|
+
{ strict }: Pick<GetAbiRecordParameters, 'strict'>,
|
|
34
44
|
): Promise<GetAbiRecordReturnType> => {
|
|
35
|
-
const urData = await universalWrapper.decode(client, data, passthrough
|
|
36
|
-
|
|
45
|
+
const urData = await universalWrapper.decode(client, data, passthrough, {
|
|
46
|
+
strict,
|
|
47
|
+
})
|
|
48
|
+
if (!urData) return null
|
|
49
|
+
return _getAbi.decode(client, urData.data, { strict })
|
|
37
50
|
}
|
|
38
51
|
|
|
39
52
|
type BatchableFunctionObject = GeneratedFunction<typeof encode, typeof decode>
|
|
@@ -59,7 +72,7 @@ type BatchableFunctionObject = GeneratedFunction<typeof encode, typeof decode>
|
|
|
59
72
|
*/
|
|
60
73
|
const getAbiRecord = generateFunction({ encode, decode }) as ((
|
|
61
74
|
client: ClientWithEns,
|
|
62
|
-
{ name }: GetAbiRecordParameters,
|
|
75
|
+
{ name, strict }: GetAbiRecordParameters,
|
|
63
76
|
) => Promise<GetAbiRecordReturnType>) &
|
|
64
77
|
BatchableFunctionObject
|
|
65
78
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Hex } from 'viem'
|
|
1
|
+
import type { BaseError, Hex } from 'viem'
|
|
2
2
|
import type { ClientWithEns } from '../../contracts/consts.js'
|
|
3
3
|
import type {
|
|
4
4
|
GenericPassthrough,
|
|
@@ -15,26 +15,42 @@ import _getAddr, {
|
|
|
15
15
|
} from './_getAddr.js'
|
|
16
16
|
import universalWrapper from './universalWrapper.js'
|
|
17
17
|
|
|
18
|
-
export type GetAddressRecordParameters = Prettify<
|
|
18
|
+
export type GetAddressRecordParameters = Prettify<
|
|
19
|
+
InternalGetAddrParameters & {
|
|
20
|
+
/** Batch gateway URLs to use for resolving CCIP-read requests. */
|
|
21
|
+
gatewayUrls?: string[]
|
|
22
|
+
}
|
|
23
|
+
>
|
|
19
24
|
|
|
20
25
|
export type GetAddressRecordReturnType = Prettify<InternalGetAddrReturnType>
|
|
21
26
|
|
|
22
27
|
const encode = (
|
|
23
28
|
client: ClientWithEns,
|
|
24
|
-
{
|
|
29
|
+
{
|
|
30
|
+
name,
|
|
31
|
+
coin,
|
|
32
|
+
gatewayUrls,
|
|
33
|
+
}: Omit<GetAddressRecordParameters, 'strict' | 'bypassFormat'>,
|
|
25
34
|
): SimpleTransactionRequest => {
|
|
26
35
|
const prData = _getAddr.encode(client, { name, coin })
|
|
27
|
-
return universalWrapper.encode(client, {
|
|
36
|
+
return universalWrapper.encode(client, {
|
|
37
|
+
name,
|
|
38
|
+
data: prData.data,
|
|
39
|
+
gatewayUrls,
|
|
40
|
+
})
|
|
28
41
|
}
|
|
29
42
|
|
|
30
43
|
const decode = async (
|
|
31
44
|
client: ClientWithEns,
|
|
32
|
-
data: Hex,
|
|
45
|
+
data: Hex | BaseError,
|
|
33
46
|
passthrough: GenericPassthrough,
|
|
34
|
-
|
|
47
|
+
{ coin, strict }: Pick<GetAddressRecordParameters, 'coin' | 'strict'>,
|
|
35
48
|
): Promise<GetAddressRecordReturnType> => {
|
|
36
|
-
const urData = await universalWrapper.decode(client, data, passthrough
|
|
37
|
-
|
|
49
|
+
const urData = await universalWrapper.decode(client, data, passthrough, {
|
|
50
|
+
strict,
|
|
51
|
+
})
|
|
52
|
+
if (!urData) return null
|
|
53
|
+
return _getAddr.decode(client, urData.data, { coin, strict })
|
|
38
54
|
}
|
|
39
55
|
|
|
40
56
|
type BatchableFunctionObject = GeneratedFunction<typeof encode, typeof decode>
|
|
@@ -60,7 +76,7 @@ type BatchableFunctionObject = GeneratedFunction<typeof encode, typeof decode>
|
|
|
60
76
|
*/
|
|
61
77
|
const getAddressRecord = generateFunction({ encode, decode }) as ((
|
|
62
78
|
client: ClientWithEns,
|
|
63
|
-
{ name, coin, bypassFormat }: GetAddressRecordParameters,
|
|
79
|
+
{ name, coin, bypassFormat, strict }: GetAddressRecordParameters,
|
|
64
80
|
) => Promise<GetAddressRecordReturnType>) &
|
|
65
81
|
BatchableFunctionObject
|
|
66
82
|
|