@ensdomains/ensjs 3.2.0 → 3.2.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.
- package/dist/cjs/clients/public.js.map +1 -1
- package/dist/cjs/clients/subgraph.js.map +1 -1
- package/dist/cjs/clients/wallet.js.map +1 -1
- package/dist/cjs/contracts/addEnsContracts.js.map +1 -1
- package/dist/cjs/contracts/consts.js +74 -32
- package/dist/cjs/contracts/consts.js.map +1 -1
- package/dist/cjs/contracts/dnsRegistrar.js +65 -9
- package/dist/cjs/contracts/dnsRegistrar.js.map +1 -1
- package/dist/cjs/contracts/dnssecImpl.js +18 -16
- package/dist/cjs/contracts/dnssecImpl.js.map +1 -1
- package/dist/cjs/contracts/getChainContractAddress.js +5 -1
- package/dist/cjs/contracts/getChainContractAddress.js.map +1 -1
- package/dist/cjs/contracts/index.js +4 -3
- package/dist/cjs/contracts/index.js.map +1 -1
- package/dist/cjs/errors/version.js +1 -1
- package/dist/cjs/functions/dns/getDnsImportData.js +22 -45
- package/dist/cjs/functions/dns/getDnsImportData.js.map +1 -1
- package/dist/cjs/functions/dns/importDnsName.js +2 -12
- package/dist/cjs/functions/dns/importDnsName.js.map +1 -1
- package/dist/cjs/functions/public/_getAbi.js +1 -2
- package/dist/cjs/functions/public/_getAbi.js.map +1 -1
- package/dist/cjs/functions/public/getAbiRecord.js +2 -2
- package/dist/cjs/functions/public/getAbiRecord.js.map +1 -1
- package/dist/cjs/functions/public/getRecords.js +2 -2
- package/dist/cjs/functions/public/getRecords.js.map +1 -1
- package/dist/cjs/utils/generateRecordCallArray.js +6 -3
- package/dist/cjs/utils/generateRecordCallArray.js.map +1 -1
- package/dist/cjs/utils/generateSupportedContentTypes.js +22 -0
- package/dist/cjs/utils/generateSupportedContentTypes.js.map +1 -0
- package/dist/cjs/utils/generateSupportedContentTypes.test.ts.js +20 -0
- package/dist/cjs/utils/generateSupportedContentTypes.test.ts.js.map +1 -0
- package/dist/cjs/utils/index.js +3 -1
- package/dist/cjs/utils/index.js.map +1 -1
- package/dist/cjs/utils/registerHelpers.js +1 -1
- package/dist/cjs/utils/registerHelpers.js.map +1 -1
- package/dist/esm/clients/public.js.map +1 -1
- package/dist/esm/clients/subgraph.js.map +1 -1
- package/dist/esm/clients/wallet.js.map +1 -1
- package/dist/esm/contracts/addEnsContracts.js.map +1 -1
- package/dist/esm/contracts/consts.js +74 -32
- package/dist/esm/contracts/consts.js.map +1 -1
- package/dist/esm/contracts/dnsRegistrar.js +64 -8
- package/dist/esm/contracts/dnsRegistrar.js.map +1 -1
- package/dist/esm/contracts/dnssecImpl.js +17 -15
- package/dist/esm/contracts/dnssecImpl.js.map +1 -1
- package/dist/esm/contracts/getChainContractAddress.js +5 -1
- package/dist/esm/contracts/getChainContractAddress.js.map +1 -1
- package/dist/esm/contracts/index.js +2 -2
- package/dist/esm/contracts/index.js.map +1 -1
- package/dist/esm/errors/version.js +1 -1
- package/dist/esm/functions/dns/getDnsImportData.js +25 -48
- package/dist/esm/functions/dns/getDnsImportData.js.map +1 -1
- package/dist/esm/functions/dns/importDnsName.js +3 -13
- package/dist/esm/functions/dns/importDnsName.js.map +1 -1
- package/dist/esm/functions/public/_getAbi.js +1 -7
- package/dist/esm/functions/public/_getAbi.js.map +1 -1
- package/dist/esm/functions/public/getAbiRecord.js +2 -2
- package/dist/esm/functions/public/getAbiRecord.js.map +1 -1
- package/dist/esm/functions/public/getRecords.js +2 -2
- package/dist/esm/functions/public/getRecords.js.map +1 -1
- package/dist/esm/utils/generateRecordCallArray.js +6 -3
- package/dist/esm/utils/generateRecordCallArray.js.map +1 -1
- package/dist/esm/utils/generateSupportedContentTypes.js +18 -0
- package/dist/esm/utils/generateSupportedContentTypes.js.map +1 -0
- package/dist/esm/utils/generateSupportedContentTypes.test.ts.js +18 -0
- package/dist/esm/utils/generateSupportedContentTypes.test.ts.js.map +1 -0
- package/dist/esm/utils/index.js +1 -0
- package/dist/esm/utils/index.js.map +1 -1
- package/dist/esm/utils/registerHelpers.js +1 -1
- package/dist/esm/utils/registerHelpers.js.map +1 -1
- package/dist/types/clients/decorators/wallet.d.ts +12 -12
- package/dist/types/clients/public.d.ts +9 -8
- package/dist/types/clients/public.d.ts.map +1 -1
- package/dist/types/clients/subgraph.d.ts +4 -4
- package/dist/types/clients/subgraph.d.ts.map +1 -1
- package/dist/types/clients/wallet.d.ts +116 -116
- package/dist/types/clients/wallet.d.ts.map +1 -1
- package/dist/types/contracts/addEnsContracts.d.ts +2 -2
- package/dist/types/contracts/addEnsContracts.d.ts.map +1 -1
- package/dist/types/contracts/consts.d.ts +75 -34
- package/dist/types/contracts/consts.d.ts.map +1 -1
- package/dist/types/contracts/dnsRegistrar.d.ts +135 -6
- package/dist/types/contracts/dnsRegistrar.d.ts.map +1 -1
- package/dist/types/contracts/dnssecImpl.d.ts +14 -13
- package/dist/types/contracts/dnssecImpl.d.ts.map +1 -1
- package/dist/types/contracts/getChainContractAddress.d.ts +15 -7
- package/dist/types/contracts/getChainContractAddress.d.ts.map +1 -1
- package/dist/types/contracts/index.d.ts +2 -2
- package/dist/types/contracts/index.d.ts.map +1 -1
- package/dist/types/errors/version.d.ts +1 -1
- package/dist/types/functions/dns/getDnsImportData.d.ts +6 -8
- package/dist/types/functions/dns/getDnsImportData.d.ts.map +1 -1
- package/dist/types/functions/dns/importDnsName.d.ts +25 -25
- package/dist/types/functions/dns/importDnsName.d.ts.map +1 -1
- package/dist/types/functions/public/_getAbi.d.ts +8 -1
- package/dist/types/functions/public/_getAbi.d.ts.map +1 -1
- package/dist/types/functions/public/getAbiRecord.d.ts +1 -1
- package/dist/types/functions/public/getAbiRecord.d.ts.map +1 -1
- package/dist/types/functions/public/getRecords.d.ts +6 -9
- package/dist/types/functions/public/getRecords.d.ts.map +1 -1
- package/dist/types/functions/wallet/clearRecords.d.ts +24 -24
- package/dist/types/functions/wallet/commitName.d.ts +24 -24
- package/dist/types/functions/wallet/createSubname.d.ts +24 -24
- package/dist/types/functions/wallet/deleteSubname.d.ts +24 -24
- package/dist/types/functions/wallet/registerName.d.ts +24 -24
- package/dist/types/functions/wallet/renewNames.d.ts +24 -24
- package/dist/types/functions/wallet/setAbiRecord.d.ts +24 -24
- package/dist/types/functions/wallet/setAddressRecord.d.ts +24 -24
- package/dist/types/functions/wallet/setChildFuses.d.ts +24 -24
- package/dist/types/functions/wallet/setContentHashRecord.d.ts +24 -24
- package/dist/types/functions/wallet/setFuses.d.ts +24 -24
- package/dist/types/functions/wallet/setPrimaryName.d.ts +24 -24
- package/dist/types/functions/wallet/setRecords.d.ts +24 -24
- package/dist/types/functions/wallet/setResolver.d.ts +24 -24
- package/dist/types/functions/wallet/setTextRecord.d.ts +24 -24
- package/dist/types/functions/wallet/transferName.d.ts +24 -24
- package/dist/types/functions/wallet/unwrapName.d.ts +24 -24
- package/dist/types/functions/wallet/wrapName.d.ts +24 -24
- package/dist/types/types.d.ts +4 -0
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/utils/encoders/encodeAbi.d.ts +1 -1
- package/dist/types/utils/encoders/encodeAbi.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/dist/types/utils/generateSupportedContentTypes.d.ts +3 -0
- package/dist/types/utils/generateSupportedContentTypes.d.ts.map +1 -0
- package/dist/types/utils/generateSupportedContentTypes.test.ts.d.ts +2 -0
- package/dist/types/utils/generateSupportedContentTypes.test.ts.d.ts.map +1 -0
- package/dist/types/utils/index.d.ts +1 -0
- package/dist/types/utils/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/clients/public.ts +6 -4
- package/src/clients/subgraph.ts +6 -4
- package/src/clients/wallet.ts +19 -13
- package/src/contracts/addEnsContracts.ts +3 -3
- package/src/contracts/consts.ts +92 -37
- package/src/contracts/dnsRegistrar.ts +65 -8
- package/src/contracts/dnssecImpl.ts +17 -15
- package/src/contracts/getChainContractAddress.ts +22 -7
- package/src/contracts/index.ts +2 -1
- package/src/errors/version.ts +1 -1
- package/src/functions/dns/getDnsImportData.ts +32 -62
- package/src/functions/dns/importDnsName.ts +4 -14
- package/src/functions/public/_getAbi.ts +11 -8
- package/src/functions/public/getAbiRecord.ts +6 -2
- package/src/functions/public/getRecords.ts +23 -31
- package/src/types.ts +10 -0
- package/src/utils/encoders/encodeAbi.ts +1 -1
- package/src/utils/generateRecordCallArray.ts +6 -3
- package/src/utils/generateSupportedContentTypes.test.ts.ts +24 -0
- package/src/utils/generateSupportedContentTypes.ts +21 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/registerHelpers.ts +1 -1
package/src/contracts/index.ts
CHANGED
|
@@ -24,12 +24,13 @@ export {
|
|
|
24
24
|
type WalletWithEns,
|
|
25
25
|
} from './consts.js'
|
|
26
26
|
export {
|
|
27
|
+
dnsRegistrarErrors,
|
|
27
28
|
dnsRegistrarProveAndClaimSnippet,
|
|
28
29
|
dnsRegistrarProveAndClaimWithResolverSnippet,
|
|
29
30
|
} from './dnsRegistrar.js'
|
|
30
31
|
export {
|
|
31
32
|
dnssecImplAnchorsSnippet,
|
|
32
|
-
|
|
33
|
+
dnssecImplVerifyRrSetSnippet,
|
|
33
34
|
} from './dnssecImpl.js'
|
|
34
35
|
export { erc165SupportsInterfaceSnippet } from './erc165.js'
|
|
35
36
|
export {
|
package/src/errors/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = 'v3.2.
|
|
1
|
+
export const version = 'v3.2.1'
|
|
@@ -1,16 +1,11 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { SignedSet, type ProvableAnswer } from '@ensdomains/dnsprovejs'
|
|
2
2
|
import type * as packet from 'dns-packet'
|
|
3
|
-
import {
|
|
4
|
-
import { keccak256, toBytes, toHex } from 'viem'
|
|
3
|
+
import { toHex, type Client, type Hex, type Transport } from 'viem'
|
|
5
4
|
import { readContract } from 'viem/actions'
|
|
6
|
-
import type {
|
|
7
|
-
import {
|
|
8
|
-
dnssecImplAnchorsSnippet,
|
|
9
|
-
dnssecImplRrDataSnippet,
|
|
10
|
-
} from '../../contracts/dnssecImpl.js'
|
|
5
|
+
import type { ChainWithEns } from '../../contracts/consts.js'
|
|
6
|
+
import { dnssecImplVerifyRrSetSnippet } from '../../contracts/dnssecImpl.js'
|
|
11
7
|
import { getChainContractAddress } from '../../contracts/getChainContractAddress.js'
|
|
12
|
-
import { DnsNewerRecordTypeAvailableError } from '../../
|
|
13
|
-
import { packetToBytes } from '../../utils/hexEncodedName.js'
|
|
8
|
+
import { DnsNewerRecordTypeAvailableError } from '../../index.js'
|
|
14
9
|
import type { Endpoint } from './types.js'
|
|
15
10
|
|
|
16
11
|
export type GetDnsImportDataParameters = {
|
|
@@ -21,14 +16,11 @@ export type GetDnsImportDataParameters = {
|
|
|
21
16
|
}
|
|
22
17
|
|
|
23
18
|
export type RrSetWithSig = {
|
|
24
|
-
rrset:
|
|
25
|
-
sig:
|
|
19
|
+
rrset: Hex
|
|
20
|
+
sig: Hex
|
|
26
21
|
}
|
|
27
22
|
|
|
28
|
-
export type GetDnsImportDataReturnType =
|
|
29
|
-
rrsets: RrSetWithSig[]
|
|
30
|
-
proof: Uint8Array
|
|
31
|
-
}
|
|
23
|
+
export type GetDnsImportDataReturnType = RrSetWithSig[]
|
|
32
24
|
|
|
33
25
|
// Compares two serial numbers using RFC1982 serial number math.
|
|
34
26
|
const serialNumberGt = (i1: number, i2: number): boolean =>
|
|
@@ -38,8 +30,8 @@ const encodeProofs = (
|
|
|
38
30
|
proofs: SignedSet<packet.Ds | packet.Dnskey | packet.Rtxt>[],
|
|
39
31
|
): RrSetWithSig[] =>
|
|
40
32
|
proofs.map((proof) => ({
|
|
41
|
-
rrset: proof.toWire(true),
|
|
42
|
-
sig: proof.signature.data.signature,
|
|
33
|
+
rrset: toHex(proof.toWire(true)),
|
|
34
|
+
sig: toHex(proof.signature.data.signature),
|
|
43
35
|
}))
|
|
44
36
|
|
|
45
37
|
/**
|
|
@@ -63,7 +55,7 @@ const encodeProofs = (
|
|
|
63
55
|
* })
|
|
64
56
|
*/
|
|
65
57
|
const getDnsImportData = async (
|
|
66
|
-
client:
|
|
58
|
+
client: Client<Transport, ChainWithEns>,
|
|
67
59
|
{
|
|
68
60
|
name,
|
|
69
61
|
endpoint = 'https://cloudflare-dns.com/dns-query',
|
|
@@ -81,53 +73,31 @@ const getDnsImportData = async (
|
|
|
81
73
|
result.proofs as SignedSet<packet.Ds | packet.Dnskey | packet.Rtxt>[]
|
|
82
74
|
).concat([result.answer])
|
|
83
75
|
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
|
|
76
|
+
const rrsets = encodeProofs(allProofs)
|
|
77
|
+
|
|
78
|
+
const [onchainRrData, inception] = await readContract(client, {
|
|
79
|
+
abi: dnssecImplVerifyRrSetSnippet,
|
|
80
|
+
address: getChainContractAddress({
|
|
81
|
+
client,
|
|
82
|
+
contract: 'ensDnssecImpl',
|
|
83
|
+
}),
|
|
84
|
+
functionName: 'verifyRRSet',
|
|
85
|
+
args: [rrsets],
|
|
87
86
|
})
|
|
88
87
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
address: ensDnssecImplAddress,
|
|
97
|
-
functionName: 'rrdata',
|
|
98
|
-
args: [type, hexEncodedName],
|
|
88
|
+
const lastProof = allProofs[allProofs.length - 1]
|
|
89
|
+
if (serialNumberGt(inception, lastProof.signature.data.inception))
|
|
90
|
+
throw new DnsNewerRecordTypeAvailableError({
|
|
91
|
+
typeCovered: lastProof.signature.data.typeCovered,
|
|
92
|
+
signatureName: lastProof.signature.name,
|
|
93
|
+
onchainInception: inception,
|
|
94
|
+
dnsInception: lastProof.signature.data.inception,
|
|
99
95
|
})
|
|
100
|
-
if (serialNumberGt(inception, proof.signature.data.inception))
|
|
101
|
-
throw new DnsNewerRecordTypeAvailableError({
|
|
102
|
-
typeCovered: proof.signature.data.typeCovered,
|
|
103
|
-
signatureName: proof.signature.name,
|
|
104
|
-
onchainInception: inception,
|
|
105
|
-
dnsInception: proof.signature.data.inception,
|
|
106
|
-
})
|
|
107
|
-
const expired = serialNumberGt(Date.now() / 1000, expiration)
|
|
108
|
-
const proofHash = keccak256(proof.toWire(false)).slice(0, 42)
|
|
109
|
-
const isKnownProof = hash === proofHash && !expired
|
|
110
|
-
if (isKnownProof) {
|
|
111
|
-
if (i === allProofs.length - 1) {
|
|
112
|
-
return { rrsets: [], proof: proof.toWire(false) }
|
|
113
|
-
}
|
|
114
|
-
return {
|
|
115
|
-
rrsets: encodeProofs(allProofs.slice(i + 1, allProofs.length)),
|
|
116
|
-
proof: proof.toWire(false),
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
96
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
abi: dnssecImplAnchorsSnippet,
|
|
126
|
-
address: ensDnssecImplAddress,
|
|
127
|
-
functionName: 'anchors',
|
|
128
|
-
}),
|
|
129
|
-
),
|
|
130
|
-
}
|
|
97
|
+
if (toHex(lastProof.toWire(false)) !== onchainRrData)
|
|
98
|
+
throw new Error('Mismatched proof data')
|
|
99
|
+
|
|
100
|
+
return rrsets
|
|
131
101
|
}
|
|
132
102
|
|
|
133
103
|
export default getDnsImportData
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import {
|
|
2
|
-
bytesToHex,
|
|
3
2
|
encodeFunctionData,
|
|
4
3
|
toHex,
|
|
5
4
|
type Account,
|
|
@@ -7,6 +6,7 @@ import {
|
|
|
7
6
|
type Hash,
|
|
8
7
|
type SendTransactionParameters,
|
|
9
8
|
type Transport,
|
|
9
|
+
type WalletClient,
|
|
10
10
|
} from 'viem'
|
|
11
11
|
import type { ChainWithEns, WalletWithEns } from '../../contracts/consts.js'
|
|
12
12
|
import {
|
|
@@ -64,7 +64,7 @@ export const makeFunctionData = <
|
|
|
64
64
|
TChain extends ChainWithEns,
|
|
65
65
|
TAccount extends Account | undefined,
|
|
66
66
|
>(
|
|
67
|
-
wallet:
|
|
67
|
+
wallet: WalletClient<Transport, TChain, TAccount>,
|
|
68
68
|
{
|
|
69
69
|
name,
|
|
70
70
|
dnsImportData,
|
|
@@ -72,10 +72,6 @@ export const makeFunctionData = <
|
|
|
72
72
|
resolverAddress,
|
|
73
73
|
}: ImportDnsNameDataParameters,
|
|
74
74
|
): ImportDnsNameDataReturnType => {
|
|
75
|
-
const data = dnsImportData.rrsets.map((rrset) => ({
|
|
76
|
-
rrset: bytesToHex(rrset.rrset),
|
|
77
|
-
sig: bytesToHex(rrset.sig),
|
|
78
|
-
}))
|
|
79
75
|
const hexEncodedName = toHex(packetToBytes(name))
|
|
80
76
|
const dnsRegistrarAddress = getChainContractAddress({
|
|
81
77
|
client: wallet,
|
|
@@ -95,7 +91,7 @@ export const makeFunctionData = <
|
|
|
95
91
|
data: encodeFunctionData({
|
|
96
92
|
abi: dnsRegistrarProveAndClaimSnippet,
|
|
97
93
|
functionName: 'proveAndClaim',
|
|
98
|
-
args: [hexEncodedName,
|
|
94
|
+
args: [hexEncodedName, dnsImportData],
|
|
99
95
|
}),
|
|
100
96
|
}
|
|
101
97
|
}
|
|
@@ -109,13 +105,7 @@ export const makeFunctionData = <
|
|
|
109
105
|
data: encodeFunctionData({
|
|
110
106
|
abi: dnsRegistrarProveAndClaimWithResolverSnippet,
|
|
111
107
|
functionName: 'proveAndClaimWithResolver',
|
|
112
|
-
args: [
|
|
113
|
-
hexEncodedName,
|
|
114
|
-
data,
|
|
115
|
-
bytesToHex(dnsImportData.proof),
|
|
116
|
-
resolverAddress_,
|
|
117
|
-
address,
|
|
118
|
-
],
|
|
108
|
+
args: [hexEncodedName, dnsImportData, resolverAddress_, address],
|
|
119
109
|
}),
|
|
120
110
|
}
|
|
121
111
|
}
|
|
@@ -19,22 +19,25 @@ import { namehash } from '../../utils/normalise.js'
|
|
|
19
19
|
export type InternalGetAbiParameters = {
|
|
20
20
|
/** Name to get ABI record for */
|
|
21
21
|
name: string
|
|
22
|
+
/** Supported content types as bitwise
|
|
23
|
+
* ID 1: JSON
|
|
24
|
+
* ID 2: zlib compressed JSON
|
|
25
|
+
* ID 4: CBOR
|
|
26
|
+
* ID 8: URI
|
|
27
|
+
*/
|
|
28
|
+
supportedContentTypes?: bigint
|
|
22
29
|
/** Whether or not to throw decoding errors */
|
|
23
30
|
strict?: boolean
|
|
24
31
|
}
|
|
25
32
|
|
|
26
33
|
export type InternalGetAbiReturnType = Prettify<DecodedAbi | null>
|
|
27
34
|
|
|
28
|
-
// Supported content types as bitwise OR
|
|
29
|
-
// ID 1: JSON
|
|
30
|
-
// ID 2: zlib compressed JSON
|
|
31
|
-
// ID 4: CBOR
|
|
32
|
-
// ID 8: URI
|
|
33
|
-
const supportedContentTypes = 0xfn
|
|
34
|
-
|
|
35
35
|
const encode = (
|
|
36
36
|
_client: ClientWithEns,
|
|
37
|
-
{
|
|
37
|
+
{
|
|
38
|
+
name,
|
|
39
|
+
supportedContentTypes = 0xfn,
|
|
40
|
+
}: Omit<InternalGetAbiParameters, 'strict'>,
|
|
38
41
|
): SimpleTransactionRequest => {
|
|
39
42
|
return {
|
|
40
43
|
to: EMPTY_ADDRESS,
|
|
@@ -26,9 +26,13 @@ export type GetAbiRecordReturnType = Prettify<InternalGetAbiReturnType>
|
|
|
26
26
|
|
|
27
27
|
const encode = (
|
|
28
28
|
client: ClientWithEns,
|
|
29
|
-
{
|
|
29
|
+
{
|
|
30
|
+
name,
|
|
31
|
+
supportedContentTypes,
|
|
32
|
+
gatewayUrls,
|
|
33
|
+
}: Omit<GetAbiRecordParameters, 'strict'>,
|
|
30
34
|
): SimpleTransactionRequest => {
|
|
31
|
-
const prData = _getAbi.encode(client, { name })
|
|
35
|
+
const prData = _getAbi.encode(client, { name, supportedContentTypes })
|
|
32
36
|
return universalWrapper.encode(client, {
|
|
33
37
|
name,
|
|
34
38
|
data: prData.data,
|
|
@@ -81,20 +81,18 @@ type WithCoinsResult = {
|
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
export type GetRecordsReturnType<
|
|
84
|
-
TTexts extends readonly string[] = readonly
|
|
85
|
-
TCoins extends readonly (string | number)[] = readonly
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
],
|
|
89
|
-
TContentHash extends boolean = true,
|
|
90
|
-
TAbi extends boolean = true,
|
|
84
|
+
TTexts extends readonly string[] | undefined = readonly string[],
|
|
85
|
+
TCoins extends readonly (string | number)[] | undefined = readonly (
|
|
86
|
+
| string
|
|
87
|
+
| number
|
|
88
|
+
)[],
|
|
89
|
+
TContentHash extends boolean | undefined = true,
|
|
90
|
+
TAbi extends boolean | undefined = true,
|
|
91
91
|
> = Prettify<
|
|
92
92
|
(TContentHash extends true ? WithContentHashResult : {}) &
|
|
93
93
|
(TAbi extends true ? WithAbiResult : {}) &
|
|
94
|
-
(TTexts extends readonly
|
|
95
|
-
(TCoins extends readonly
|
|
96
|
-
? WithCoinsResult
|
|
97
|
-
: {}) & {
|
|
94
|
+
(TTexts extends readonly string[] ? WithTextsResult : {}) &
|
|
95
|
+
(TCoins extends readonly (string | number)[] ? WithCoinsResult : {}) & {
|
|
98
96
|
/** Resolver address used for fetch */
|
|
99
97
|
resolverAddress: Address
|
|
100
98
|
}
|
|
@@ -261,8 +259,8 @@ const createEmptyResult = <
|
|
|
261
259
|
GetRecordsParameters<TTexts, TCoins, TContentHash, TAbi>,
|
|
262
260
|
'texts' | 'coins' | 'abi' | 'contentHash'
|
|
263
261
|
>) => ({
|
|
264
|
-
...(texts
|
|
265
|
-
...(coins
|
|
262
|
+
...(texts ? { texts: [] as DecodedText[] } : {}),
|
|
263
|
+
...(coins ? { coins: [] as DecodedAddr[] } : {}),
|
|
266
264
|
...(contentHash ? { contentHash: null } : {}),
|
|
267
265
|
...(abi ? { abi: null } : {}),
|
|
268
266
|
})
|
|
@@ -347,13 +345,13 @@ const createRecordResult = (
|
|
|
347
345
|
}
|
|
348
346
|
|
|
349
347
|
const decode = async <
|
|
350
|
-
const TTexts extends readonly string[] = readonly string[],
|
|
351
|
-
const TCoins extends readonly (string | number)[] = readonly (
|
|
348
|
+
const TTexts extends readonly string[] | undefined = readonly string[],
|
|
349
|
+
const TCoins extends readonly (string | number)[] | undefined = readonly (
|
|
352
350
|
| string
|
|
353
351
|
| number
|
|
354
352
|
)[],
|
|
355
|
-
const TContentHash extends boolean =
|
|
356
|
-
const TAbi extends boolean =
|
|
353
|
+
const TContentHash extends boolean | undefined = undefined,
|
|
354
|
+
const TAbi extends boolean | undefined = undefined,
|
|
357
355
|
>(
|
|
358
356
|
client: ClientWithEns,
|
|
359
357
|
data: Hex | BaseError,
|
|
@@ -434,13 +432,10 @@ type BatchableFunctionObject = {
|
|
|
434
432
|
encode: EncoderFunction
|
|
435
433
|
decode: DecoderFunction
|
|
436
434
|
batch: <
|
|
437
|
-
const TTexts extends readonly string[] =
|
|
438
|
-
const TCoins extends readonly (string | number)[] =
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
)[],
|
|
442
|
-
const TContentHash extends boolean = true,
|
|
443
|
-
const TAbi extends boolean = true,
|
|
435
|
+
const TTexts extends readonly string[] | undefined = undefined,
|
|
436
|
+
const TCoins extends readonly (string | number)[] | undefined = undefined,
|
|
437
|
+
const TContentHash extends boolean | undefined = undefined,
|
|
438
|
+
const TAbi extends boolean | undefined = undefined,
|
|
444
439
|
>(
|
|
445
440
|
args: GetRecordsParameters<TTexts, TCoins, TContentHash, TAbi>,
|
|
446
441
|
) => {
|
|
@@ -477,13 +472,10 @@ type BatchableFunctionObject = {
|
|
|
477
472
|
* // { texts: [{ key: 'com.twitter', value: 'ensdomains' }, { key: 'com.github', value: 'ensdomains' }], coins: [{ id: 60, name: 'ETH', value: '0xFe89cc7aBB2C4183683ab71653C4cdc9B02D44b7' }], contentHash: { protocolType: 'ipns', decoded: 'k51qzi5uqu5djdczd6zw0grmo23j2vkj9uzvujencg15s5rlkq0ss4ivll8wqw' } }
|
|
478
473
|
*/
|
|
479
474
|
const getRecords = generateFunction({ encode, decode }) as (<
|
|
480
|
-
const TTexts extends readonly string[] =
|
|
481
|
-
const TCoins extends readonly (string | number)[] =
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
)[],
|
|
485
|
-
const TContentHash extends boolean = true,
|
|
486
|
-
const TAbi extends boolean = true,
|
|
475
|
+
const TTexts extends readonly string[] | undefined = undefined,
|
|
476
|
+
const TCoins extends readonly (string | number)[] | undefined = undefined,
|
|
477
|
+
const TContentHash extends boolean | undefined = undefined,
|
|
478
|
+
const TAbi extends boolean | undefined = undefined,
|
|
487
479
|
>(
|
|
488
480
|
client: ClientWithEns,
|
|
489
481
|
{
|
package/src/types.ts
CHANGED
|
@@ -11,6 +11,16 @@ export type Prettify<T> = {
|
|
|
11
11
|
[K in keyof T]: T[K]
|
|
12
12
|
} & {}
|
|
13
13
|
|
|
14
|
+
type AssignI<T, U> = {
|
|
15
|
+
[K in keyof T as K extends keyof U
|
|
16
|
+
? U[K] extends void
|
|
17
|
+
? never
|
|
18
|
+
: K
|
|
19
|
+
: K]: K extends keyof U ? U[K] : T[K]
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export type Assign<T, U> = AssignI<T, U> & U
|
|
23
|
+
|
|
14
24
|
export type SimpleTransactionRequest = {
|
|
15
25
|
[P in keyof Pick<TransactionRequest, 'to' | 'data'>]-?: Exclude<
|
|
16
26
|
TransactionRequest[P],
|
|
@@ -2,7 +2,7 @@ import { bytesToHex, stringToHex, type Hex } from 'viem'
|
|
|
2
2
|
import { UnknownContentTypeError } from '../../errors/utils.js'
|
|
3
3
|
import type { Prettify } from '../../types.js'
|
|
4
4
|
|
|
5
|
-
type AbiEncodeAs = 'json' | 'zlib' | 'cbor' | 'uri'
|
|
5
|
+
export type AbiEncodeAs = 'json' | 'zlib' | 'cbor' | 'uri'
|
|
6
6
|
|
|
7
7
|
type AbiContentType = 1 | 2 | 4 | 8
|
|
8
8
|
|
|
@@ -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 | EncodedAbi[]
|
|
30
30
|
}>
|
|
31
31
|
|
|
32
32
|
export const generateRecordCallArray = ({
|
|
@@ -49,8 +49,11 @@ export const generateRecordCallArray = ({
|
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
if (abi !== undefined) {
|
|
52
|
-
const
|
|
53
|
-
|
|
52
|
+
const abis = Array.isArray(abi) ? abi : [abi]
|
|
53
|
+
for (const abi_ of abis) {
|
|
54
|
+
const data = encodeSetAbi({ namehash, ...abi_ } as EncodeSetAbiParameters)
|
|
55
|
+
if (data) calls.push(data)
|
|
56
|
+
}
|
|
54
57
|
}
|
|
55
58
|
|
|
56
59
|
if (texts && texts.length > 0) {
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { generateSupportedContentTypes } from './generateSupportedContentTypes.js'
|
|
2
|
+
|
|
3
|
+
type FunctionParameters = Parameters<typeof generateSupportedContentTypes>
|
|
4
|
+
type EncodeAsParameter = FunctionParameters[0]
|
|
5
|
+
|
|
6
|
+
describe('generateSupportedContentTypes', () => {
|
|
7
|
+
it.each([
|
|
8
|
+
['json', 1n],
|
|
9
|
+
['zlib', 2n],
|
|
10
|
+
['cbor', 4n],
|
|
11
|
+
['uri', 8n],
|
|
12
|
+
['unknown', 0n],
|
|
13
|
+
[['json', 'zlib'], 3n],
|
|
14
|
+
[['zlib', 'cbor'], 6n],
|
|
15
|
+
[['cbor', 'uri'], 12n],
|
|
16
|
+
[['json', 'zlib', 'cbor', 'uri'], 15n],
|
|
17
|
+
] as [EncodeAsParameter, bigint][])(
|
|
18
|
+
'should return the correct bitwise value supportedContentTypes %p (%p)',
|
|
19
|
+
(encodedAs, expected) => {
|
|
20
|
+
const result = generateSupportedContentTypes(encodedAs)
|
|
21
|
+
expect(result).toEqual(expected)
|
|
22
|
+
},
|
|
23
|
+
)
|
|
24
|
+
})
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { AbiEncodeAs } from './encoders/encodeAbi.js'
|
|
2
|
+
|
|
3
|
+
const abiEncodeAsMap: { [key in AbiEncodeAs]: bigint } = {
|
|
4
|
+
json: 1n,
|
|
5
|
+
zlib: 2n,
|
|
6
|
+
cbor: 4n,
|
|
7
|
+
uri: 8n,
|
|
8
|
+
} as const
|
|
9
|
+
|
|
10
|
+
export const generateSupportedContentTypes = (
|
|
11
|
+
encodeAsItemOrList: AbiEncodeAs | AbiEncodeAs[],
|
|
12
|
+
): bigint => {
|
|
13
|
+
const encodeAsList = Array.isArray(encodeAsItemOrList)
|
|
14
|
+
? encodeAsItemOrList
|
|
15
|
+
: [encodeAsItemOrList]
|
|
16
|
+
return encodeAsList.reduce<bigint>((result, encodeAs) => {
|
|
17
|
+
const contentType = abiEncodeAsMap[encodeAs]
|
|
18
|
+
if (contentType) result |= contentType
|
|
19
|
+
return result
|
|
20
|
+
}, 0n)
|
|
21
|
+
}
|
package/src/utils/index.ts
CHANGED
|
@@ -103,7 +103,7 @@ export const makeCommitmentTuple = ({
|
|
|
103
103
|
reverseRecord &&
|
|
104
104
|
!coins.find(
|
|
105
105
|
(c) =>
|
|
106
|
-
c.coin === '
|
|
106
|
+
(typeof c.coin === 'string' && c.coin.toLowerCase() === 'eth') ||
|
|
107
107
|
(typeof c.coin === 'string' ? parseInt(c.coin) === 60 : c.coin === 60),
|
|
108
108
|
)
|
|
109
109
|
) {
|