@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
|
@@ -15,25 +15,38 @@ import _getText, {
|
|
|
15
15
|
} from './_getText.js'
|
|
16
16
|
import universalWrapper from './universalWrapper.js'
|
|
17
17
|
|
|
18
|
-
export type GetTextRecordParameters = Prettify<
|
|
18
|
+
export type GetTextRecordParameters = Prettify<
|
|
19
|
+
InternalGetTextParameters & {
|
|
20
|
+
/** Batch gateway URLs to use for resolving CCIP-read requests. */
|
|
21
|
+
gatewayUrls?: string[]
|
|
22
|
+
}
|
|
23
|
+
>
|
|
19
24
|
|
|
20
25
|
export type GetTextRecordReturnType = Prettify<InternalGetTextReturnType>
|
|
21
26
|
|
|
22
27
|
const encode = (
|
|
23
28
|
client: ClientWithEns,
|
|
24
|
-
{ name, key }: GetTextRecordParameters,
|
|
29
|
+
{ name, key, gatewayUrls }: Omit<GetTextRecordParameters, 'strict'>,
|
|
25
30
|
): SimpleTransactionRequest => {
|
|
26
31
|
const prData = _getText.encode(client, { name, key })
|
|
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
41
|
data: Hex | BaseError,
|
|
33
42
|
passthrough: GenericPassthrough,
|
|
43
|
+
{ strict }: Pick<GetTextRecordParameters, 'strict'>,
|
|
34
44
|
): Promise<GetTextRecordReturnType> => {
|
|
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 _getText.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 getTextRecord = generateFunction({ encode, decode }) as ((
|
|
61
74
|
client: ClientWithEns,
|
|
62
|
-
{ name, key }: GetTextRecordParameters,
|
|
75
|
+
{ name, key, strict }: GetTextRecordParameters,
|
|
63
76
|
) => Promise<GetTextRecordReturnType>) &
|
|
64
77
|
BatchableFunctionObject
|
|
65
78
|
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
BaseError,
|
|
3
|
-
decodeErrorResult,
|
|
4
3
|
decodeFunctionResult,
|
|
5
4
|
encodeFunctionData,
|
|
6
|
-
getContractError,
|
|
7
5
|
labelhash,
|
|
8
6
|
toBytes,
|
|
9
7
|
toHex,
|
|
@@ -17,25 +15,26 @@ import type {
|
|
|
17
15
|
GenericPassthrough,
|
|
18
16
|
TransactionRequestWithPassthrough,
|
|
19
17
|
} from '../../types.js'
|
|
20
|
-
import {
|
|
18
|
+
import { checkSafeUniversalResolverData } from '../../utils/checkSafeUniversalResolverData.js'
|
|
21
19
|
import { generateFunction } from '../../utils/generateFunction.js'
|
|
22
|
-
import { getRevertErrorData } from '../../utils/getRevertErrorData.js'
|
|
23
20
|
import { packetToBytes } from '../../utils/hexEncodedName.js'
|
|
24
21
|
import { encodeLabelhash } from '../../utils/labels.js'
|
|
25
22
|
|
|
26
23
|
export type UniversalWrapperParameters = {
|
|
27
24
|
name: string
|
|
28
25
|
data: Hex
|
|
26
|
+
strict?: boolean
|
|
27
|
+
gatewayUrls?: string[]
|
|
29
28
|
}
|
|
30
29
|
|
|
31
30
|
export type UniversalWrapperReturnType = {
|
|
32
31
|
data: Hex
|
|
33
32
|
resolver: Address
|
|
34
|
-
}
|
|
33
|
+
} | null
|
|
35
34
|
|
|
36
35
|
const encode = (
|
|
37
36
|
client: ClientWithEns,
|
|
38
|
-
{ name, data }: UniversalWrapperParameters,
|
|
37
|
+
{ name, data, gatewayUrls }: Omit<UniversalWrapperParameters, 'strict'>,
|
|
39
38
|
): TransactionRequestWithPassthrough => {
|
|
40
39
|
const nameWithSizedLabels = name
|
|
41
40
|
.split('.')
|
|
@@ -52,17 +51,32 @@ const encode = (
|
|
|
52
51
|
contract: 'ensUniversalResolver',
|
|
53
52
|
})
|
|
54
53
|
const args = [toHex(packetToBytes(nameWithSizedLabels)), data] as const
|
|
54
|
+
|
|
55
55
|
return {
|
|
56
|
-
to
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
56
|
+
to,
|
|
57
|
+
...(gatewayUrls?.length
|
|
58
|
+
? {
|
|
59
|
+
data: encodeFunctionData({
|
|
60
|
+
abi: universalResolverResolveSnippet,
|
|
61
|
+
functionName: 'resolve',
|
|
62
|
+
args: [...args, gatewayUrls] as const,
|
|
63
|
+
}),
|
|
64
|
+
passthrough: {
|
|
65
|
+
args: [...args, gatewayUrls],
|
|
66
|
+
address: to,
|
|
67
|
+
},
|
|
68
|
+
}
|
|
69
|
+
: {
|
|
70
|
+
data: encodeFunctionData({
|
|
71
|
+
abi: universalResolverResolveSnippet,
|
|
72
|
+
functionName: 'resolve',
|
|
73
|
+
args,
|
|
74
|
+
}),
|
|
75
|
+
passthrough: {
|
|
76
|
+
args,
|
|
77
|
+
address: to,
|
|
78
|
+
},
|
|
79
|
+
}),
|
|
66
80
|
}
|
|
67
81
|
}
|
|
68
82
|
|
|
@@ -70,37 +84,29 @@ const decode = async (
|
|
|
70
84
|
_client: ClientWithEns,
|
|
71
85
|
data: Hex | BaseError,
|
|
72
86
|
passthrough: GenericPassthrough,
|
|
87
|
+
{ strict }: Pick<UniversalWrapperParameters, 'strict'>,
|
|
73
88
|
): Promise<UniversalWrapperReturnType> => {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
if (errorData) {
|
|
77
|
-
const decodedError = decodeErrorResult({
|
|
78
|
-
abi: universalResolverResolveSnippet,
|
|
79
|
-
data: errorData,
|
|
80
|
-
})
|
|
81
|
-
if (
|
|
82
|
-
decodedError.errorName === 'ResolverNotFound' ||
|
|
83
|
-
decodedError.errorName === 'ResolverWildcardNotSupported'
|
|
84
|
-
)
|
|
85
|
-
return {
|
|
86
|
-
data: '0x',
|
|
87
|
-
resolver: EMPTY_ADDRESS,
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
throw getContractError(data, {
|
|
91
|
-
abi: universalResolverResolveSnippet,
|
|
92
|
-
functionName: 'resolve',
|
|
93
|
-
args: passthrough.args,
|
|
94
|
-
address: passthrough.address,
|
|
95
|
-
}) as BaseError
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
const result = decodeFunctionResult({
|
|
89
|
+
const isSafe = checkSafeUniversalResolverData(data, {
|
|
90
|
+
strict,
|
|
99
91
|
abi: universalResolverResolveSnippet,
|
|
92
|
+
args: passthrough.args,
|
|
100
93
|
functionName: 'resolve',
|
|
101
|
-
|
|
94
|
+
address: passthrough.address,
|
|
102
95
|
})
|
|
103
|
-
|
|
96
|
+
|
|
97
|
+
if (!isSafe) return null
|
|
98
|
+
|
|
99
|
+
try {
|
|
100
|
+
const result = decodeFunctionResult({
|
|
101
|
+
abi: universalResolverResolveSnippet,
|
|
102
|
+
functionName: 'resolve',
|
|
103
|
+
data,
|
|
104
|
+
})
|
|
105
|
+
return { data: result[0], resolver: result[1] }
|
|
106
|
+
} catch (error) {
|
|
107
|
+
if (strict) throw error
|
|
108
|
+
return null
|
|
109
|
+
}
|
|
104
110
|
}
|
|
105
111
|
|
|
106
112
|
const universalWrapper = generateFunction({ encode, decode })
|
|
@@ -22,7 +22,7 @@ export type SetAbiRecordDataParameters = {
|
|
|
22
22
|
/** Name to set ABI for */
|
|
23
23
|
name: string
|
|
24
24
|
/** Encoded ABI data to set */
|
|
25
|
-
encodedAbi: EncodedAbi
|
|
25
|
+
encodedAbi: EncodedAbi
|
|
26
26
|
/** Resolver address to set ABI on */
|
|
27
27
|
resolverAddress: Address
|
|
28
28
|
}
|
|
@@ -47,12 +47,11 @@ export const makeFunctionData = <
|
|
|
47
47
|
_wallet: WalletWithEns<Transport, TChain, TAccount>,
|
|
48
48
|
{ name, encodedAbi, resolverAddress }: SetAbiRecordDataParameters,
|
|
49
49
|
): SetAbiRecordDataReturnType => {
|
|
50
|
-
const encodedAbi_ = encodedAbi || { contentType: 0, encodedData: null }
|
|
51
50
|
return {
|
|
52
51
|
to: resolverAddress,
|
|
53
52
|
data: encodeSetAbi({
|
|
54
53
|
namehash: namehash(name),
|
|
55
|
-
...
|
|
54
|
+
...encodedAbi,
|
|
56
55
|
} as EncodeSetAbiParameters),
|
|
57
56
|
}
|
|
58
57
|
}
|
package/src/types.ts
CHANGED
|
@@ -18,9 +18,10 @@ export type SimpleTransactionRequest = {
|
|
|
18
18
|
>
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
export type TransactionRequestWithPassthrough =
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
export type TransactionRequestWithPassthrough<TPassthrough = any> =
|
|
22
|
+
SimpleTransactionRequest & {
|
|
23
|
+
passthrough?: TPassthrough
|
|
24
|
+
}
|
|
24
25
|
|
|
25
26
|
export type GenericPassthrough = { args: any; address: Address }
|
|
26
27
|
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CallExecutionError,
|
|
3
|
+
decodeErrorResult,
|
|
4
|
+
getContractError,
|
|
5
|
+
type BaseError,
|
|
6
|
+
type Hex,
|
|
7
|
+
} from 'viem'
|
|
8
|
+
import type { Prettify } from '../types.js'
|
|
9
|
+
import { getRevertErrorData } from './getRevertErrorData.js'
|
|
10
|
+
|
|
11
|
+
type CheckSafeUniversalResolverDataParameters = Prettify<
|
|
12
|
+
{
|
|
13
|
+
strict: boolean | undefined
|
|
14
|
+
args: any[] | (() => any[])
|
|
15
|
+
} & Omit<Parameters<typeof getContractError>[1], 'args'>
|
|
16
|
+
>
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Checks if the data returned from a universal resolver is safe to use, or if it is a known revert error
|
|
20
|
+
* @param parameters - {@link CheckSafeUniversalResolverDataParameters}
|
|
21
|
+
* @returns `true` if the data is safe to use, `false` if it is a known revert error, or throws if it is an unknown error
|
|
22
|
+
*/
|
|
23
|
+
export const checkSafeUniversalResolverData = (
|
|
24
|
+
data: Hex | BaseError,
|
|
25
|
+
{
|
|
26
|
+
strict,
|
|
27
|
+
abi,
|
|
28
|
+
args,
|
|
29
|
+
functionName,
|
|
30
|
+
address,
|
|
31
|
+
docsPath,
|
|
32
|
+
sender,
|
|
33
|
+
}: CheckSafeUniversalResolverDataParameters,
|
|
34
|
+
): data is Hex => {
|
|
35
|
+
if (typeof data === 'object') {
|
|
36
|
+
// if not strict, attempt to check if the error is a known revert error before throwing
|
|
37
|
+
// if it is a known revert error, return false instead of throwing
|
|
38
|
+
// even if strict is false, we want to throw unknown contract errors
|
|
39
|
+
if (!strict) {
|
|
40
|
+
const errorData = getRevertErrorData(data)
|
|
41
|
+
if (errorData) {
|
|
42
|
+
try {
|
|
43
|
+
decodeErrorResult({
|
|
44
|
+
abi,
|
|
45
|
+
data: errorData,
|
|
46
|
+
})
|
|
47
|
+
return false
|
|
48
|
+
} catch (error) {}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
if (data instanceof CallExecutionError) throw data
|
|
52
|
+
throw getContractError(data, {
|
|
53
|
+
abi,
|
|
54
|
+
args: typeof args === 'function' ? args() : args,
|
|
55
|
+
functionName,
|
|
56
|
+
address,
|
|
57
|
+
docsPath,
|
|
58
|
+
sender,
|
|
59
|
+
}) as BaseError
|
|
60
|
+
}
|
|
61
|
+
return true
|
|
62
|
+
}
|
|
@@ -20,11 +20,11 @@ export type EncodeAbiParameters<TEncodeAs extends AbiEncodeAs = AbiEncodeAs> =
|
|
|
20
20
|
TEncodeAs extends 'uri'
|
|
21
21
|
? {
|
|
22
22
|
encodeAs: TEncodeAs
|
|
23
|
-
data: string
|
|
23
|
+
data: string | null
|
|
24
24
|
}
|
|
25
25
|
: {
|
|
26
26
|
encodeAs: TEncodeAs
|
|
27
|
-
data: Record<any, any>
|
|
27
|
+
data: Record<any, any> | null
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
export type EncodedAbi<TContentType extends AbiContentType = AbiContentType> = {
|
|
@@ -72,27 +72,31 @@ export const encodeAbi = async <
|
|
|
72
72
|
Prettify<EncodeAbiReturnType<TContentType>>
|
|
73
73
|
> => {
|
|
74
74
|
let contentType: AbiContentType
|
|
75
|
-
let encodedData: Hex
|
|
75
|
+
let encodedData: Hex = '0x'
|
|
76
76
|
switch (encodeAs) {
|
|
77
77
|
case 'json':
|
|
78
78
|
contentType = 1
|
|
79
|
-
encodedData = stringToHex(JSON.stringify(data))
|
|
79
|
+
if (data) encodedData = stringToHex(JSON.stringify(data))
|
|
80
80
|
break
|
|
81
81
|
case 'zlib': {
|
|
82
82
|
contentType = 2
|
|
83
|
-
|
|
84
|
-
|
|
83
|
+
if (data) {
|
|
84
|
+
const { deflate } = await import('pako/dist/pako_deflate.min.js')
|
|
85
|
+
encodedData = bytesToHex(deflate(JSON.stringify(data)))
|
|
86
|
+
}
|
|
85
87
|
break
|
|
86
88
|
}
|
|
87
89
|
case 'cbor': {
|
|
88
90
|
contentType = 4
|
|
89
|
-
|
|
90
|
-
|
|
91
|
+
if (data) {
|
|
92
|
+
const { cborEncode } = await import('@ensdomains/address-encoder/utils')
|
|
93
|
+
encodedData = bytesToHex(new Uint8Array(cborEncode(data)))
|
|
94
|
+
}
|
|
91
95
|
break
|
|
92
96
|
}
|
|
93
97
|
default: {
|
|
94
98
|
contentType = 8
|
|
95
|
-
encodedData = stringToHex(data as string)
|
|
99
|
+
if (data) encodedData = stringToHex(data as string)
|
|
96
100
|
break
|
|
97
101
|
}
|
|
98
102
|
}
|
|
@@ -4,7 +4,7 @@ import type { EncodedAbi } from './encodeAbi.js'
|
|
|
4
4
|
|
|
5
5
|
export type EncodeSetAbiParameters = {
|
|
6
6
|
namehash: Hex
|
|
7
|
-
} &
|
|
7
|
+
} & EncodedAbi
|
|
8
8
|
|
|
9
9
|
export type EncodeSetAbiReturnType = Hex
|
|
10
10
|
|
|
@@ -16,6 +16,6 @@ export const encodeSetAbi = ({
|
|
|
16
16
|
return encodeFunctionData({
|
|
17
17
|
abi: publicResolverSetAbiSnippet,
|
|
18
18
|
functionName: 'setABI',
|
|
19
|
-
args: [namehash, BigInt(contentType), encodedData
|
|
19
|
+
args: [namehash, BigInt(contentType), encodedData],
|
|
20
20
|
})
|
|
21
21
|
}
|
|
@@ -26,7 +26,7 @@ export type RecordOptions = Prettify<{
|
|
|
26
26
|
/** Array of coin records */
|
|
27
27
|
coins?: Omit<EncodeSetAddrParameters, 'namehash'>[]
|
|
28
28
|
/** ABI value */
|
|
29
|
-
abi?: EncodedAbi
|
|
29
|
+
abi?: EncodedAbi
|
|
30
30
|
}>
|
|
31
31
|
|
|
32
32
|
export const generateRecordCallArray = ({
|
|
@@ -49,8 +49,7 @@ export const generateRecordCallArray = ({
|
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
if (abi !== undefined) {
|
|
52
|
-
const
|
|
53
|
-
const data = encodeSetAbi({ namehash, ...abi_ } as EncodeSetAbiParameters)
|
|
52
|
+
const data = encodeSetAbi({ namehash, ...abi } as EncodeSetAbiParameters)
|
|
54
53
|
if (data) calls.push(data)
|
|
55
54
|
}
|
|
56
55
|
|