@ensdomains/ensjs 3.0.0-alpha.1 → 3.0.0-alpha.12
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/README.md +2 -0
- package/dist/cjs/GqlManager.d.ts +3 -0
- package/dist/cjs/GqlManager.js +62 -2
- package/dist/cjs/contracts/baseRegistrar.d.ts +1 -1
- package/dist/cjs/contracts/index.d.ts +3 -3
- package/dist/cjs/contracts/multicall.d.ts +1 -1
- package/dist/cjs/contracts/registry.d.ts +1 -1
- package/dist/cjs/functions/burnFuses.d.ts +3 -2
- package/dist/cjs/functions/burnFuses.js +4 -8
- package/dist/cjs/functions/createSubname.d.ts +3 -5
- package/dist/cjs/functions/createSubname.js +7 -8
- package/dist/cjs/functions/deleteSubname.d.ts +3 -3
- package/dist/cjs/functions/deleteSubname.js +6 -2
- package/dist/cjs/functions/getDNSOwner.d.ts +7 -0
- package/dist/cjs/functions/getDNSOwner.js +81 -0
- package/dist/cjs/functions/getExpiry.d.ts +9 -2
- package/dist/cjs/functions/getExpiry.js +52 -7
- package/dist/cjs/functions/getFuses.d.ts +2 -3
- package/dist/cjs/functions/getFuses.js +6 -14
- package/dist/cjs/functions/getHistory.d.ts +0 -30
- package/dist/cjs/functions/getHistory.js +3 -99
- package/dist/cjs/functions/getName.d.ts +2 -2
- package/dist/cjs/functions/getName.js +1 -1
- package/dist/cjs/functions/getOwner.js +7 -6
- package/dist/cjs/functions/getProfile.d.ts +4 -1
- package/dist/cjs/functions/getProfile.js +102 -24
- package/dist/cjs/functions/getRecords.d.ts +1 -0
- package/dist/cjs/functions/getSpecificRecord.js +30 -6
- package/dist/cjs/functions/getSubnames.d.ts +1 -1
- package/dist/cjs/functions/getSubnames.js +7 -7
- package/dist/cjs/functions/setName.d.ts +4 -3
- package/dist/cjs/functions/setName.js +5 -10
- package/dist/cjs/functions/setRecord.d.ts +18 -0
- package/dist/cjs/functions/setRecord.js +27 -0
- package/dist/cjs/functions/setRecords.d.ts +4 -2
- package/dist/cjs/functions/setRecords.js +14 -12
- package/dist/cjs/functions/setResolver.d.ts +4 -4
- package/dist/cjs/functions/setResolver.js +6 -12
- package/dist/cjs/functions/transferName.d.ts +4 -3
- package/dist/cjs/functions/transferName.js +9 -13
- package/dist/cjs/functions/transferSubname.d.ts +13 -3
- package/dist/cjs/functions/transferSubname.js +7 -8
- package/dist/cjs/functions/unwrapName.d.ts +4 -3
- package/dist/cjs/functions/unwrapName.js +5 -9
- package/dist/cjs/functions/wrapName.d.ts +7 -3
- package/dist/cjs/functions/wrapName.js +38 -36
- package/dist/cjs/generated/BaseRegistrarImplementation.d.ts +222 -201
- package/dist/cjs/generated/DNSRegistrar.d.ts +68 -64
- package/dist/cjs/generated/DNSSECImpl.d.ts +111 -111
- package/dist/cjs/generated/DefaultReverseResolver.d.ts +17 -17
- package/dist/cjs/generated/ENSRegistry.d.ts +126 -111
- package/dist/cjs/generated/ETHRegistrarController.d.ts +111 -109
- package/dist/cjs/generated/Multicall.d.ts +60 -60
- package/dist/cjs/generated/NameWrapper.d.ts +493 -354
- package/dist/cjs/generated/P256SHA256Algorithm.d.ts +11 -7
- package/dist/cjs/generated/PublicResolver.d.ts +259 -235
- package/dist/cjs/generated/RSASHA1Algorithm.d.ts +11 -7
- package/dist/cjs/generated/RSASHA256Algorithm.d.ts +11 -7
- package/dist/cjs/generated/ReverseRegistrar.d.ts +112 -103
- package/dist/cjs/generated/Root.d.ts +77 -77
- package/dist/cjs/generated/SHA1Digest.d.ts +7 -7
- package/dist/cjs/generated/SHA1NSEC3Digest.d.ts +11 -7
- package/dist/cjs/generated/SHA256Digest.d.ts +7 -7
- package/dist/cjs/generated/StaticMetadataService.d.ts +7 -7
- package/dist/cjs/generated/TLDPublicSuffixList.d.ts +7 -7
- package/dist/cjs/generated/UniversalResolver.d.ts +31 -31
- package/dist/cjs/generated/common.d.ts +1 -0
- package/dist/cjs/generated/factories/DNSRegistrar__factory.d.ts +3 -15
- package/dist/cjs/generated/factories/DNSRegistrar__factory.js +3 -26
- package/dist/cjs/generated/factories/DNSSECImpl__factory.d.ts +3 -15
- package/dist/cjs/generated/factories/DNSSECImpl__factory.js +3 -26
- package/dist/cjs/generated/factories/ETHRegistrarController__factory.js +14 -4
- package/dist/cjs/generated/factories/NameWrapper__factory.js +210 -79
- package/dist/cjs/generated/factories/P256SHA256Algorithm__factory.d.ts +3 -15
- package/dist/cjs/generated/factories/P256SHA256Algorithm__factory.js +3 -26
- package/dist/cjs/generated/factories/RSASHA1Algorithm__factory.d.ts +3 -15
- package/dist/cjs/generated/factories/RSASHA1Algorithm__factory.js +3 -26
- package/dist/cjs/generated/factories/RSASHA256Algorithm__factory.d.ts +3 -15
- package/dist/cjs/generated/factories/RSASHA256Algorithm__factory.js +3 -26
- package/dist/cjs/generated/factories/SHA1Digest__factory.d.ts +3 -15
- package/dist/cjs/generated/factories/SHA1Digest__factory.js +3 -26
- package/dist/cjs/generated/factories/SHA1NSEC3Digest__factory.d.ts +3 -15
- package/dist/cjs/generated/factories/SHA1NSEC3Digest__factory.js +3 -26
- package/dist/cjs/generated/factories/SHA256Digest__factory.d.ts +3 -15
- package/dist/cjs/generated/factories/SHA256Digest__factory.js +3 -26
- package/dist/cjs/generated/factories/TLDPublicSuffixList__factory.d.ts +3 -15
- package/dist/cjs/generated/factories/TLDPublicSuffixList__factory.js +3 -26
- package/dist/cjs/generated/factories/index.d.ts +14 -0
- package/dist/cjs/generated/factories/index.js +29 -1
- package/dist/cjs/generated/index.d.ts +29 -1
- package/dist/cjs/generated/index.js +31 -3
- package/dist/cjs/index.d.ts +62 -84
- package/dist/cjs/index.js +44 -21
- package/dist/cjs/utils/labels.js +5 -4
- package/dist/cjs/utils/makeHashIndexes.js +2 -2
- package/dist/cjs/utils/normalise.d.ts +1 -0
- package/dist/cjs/utils/normalise.js +27 -1
- package/dist/cjs/utils/recordHelpers.d.ts +3 -0
- package/dist/cjs/utils/recordHelpers.js +42 -15
- package/dist/cjs/utils/registerHelpers.js +3 -4
- package/dist/cjs/utils/wrapperExpiry.d.ts +5 -0
- package/dist/cjs/utils/wrapperExpiry.js +30 -0
- package/dist/cjs/utils/writeTx.d.ts +4 -0
- package/dist/cjs/utils/writeTx.js +3 -0
- package/dist/esm/GqlManager.d.ts +3 -0
- package/dist/esm/GqlManager.js +58 -2
- package/dist/esm/contracts/baseRegistrar.d.ts +1 -1
- package/dist/esm/contracts/index.d.ts +3 -3
- package/dist/esm/contracts/multicall.d.ts +1 -1
- package/dist/esm/contracts/registry.d.ts +1 -1
- package/dist/esm/functions/burnFuses.d.ts +3 -2
- package/dist/esm/functions/burnFuses.js +4 -8
- package/dist/esm/functions/createSubname.d.ts +3 -5
- package/dist/esm/functions/createSubname.js +7 -8
- package/dist/esm/functions/deleteSubname.d.ts +3 -3
- package/dist/esm/functions/deleteSubname.js +6 -2
- package/dist/esm/functions/getDNSOwner.d.ts +7 -0
- package/dist/esm/functions/getDNSOwner.js +51 -0
- package/dist/esm/functions/getExpiry.d.ts +9 -2
- package/dist/esm/functions/getExpiry.js +52 -7
- package/dist/esm/functions/getFuses.d.ts +2 -3
- package/dist/esm/functions/getFuses.js +7 -15
- package/dist/esm/functions/getHistory.d.ts +0 -30
- package/dist/esm/functions/getHistory.js +2 -96
- package/dist/esm/functions/getName.d.ts +2 -2
- package/dist/esm/functions/getName.js +1 -1
- package/dist/esm/functions/getOwner.js +7 -6
- package/dist/esm/functions/getProfile.d.ts +4 -1
- package/dist/esm/functions/getProfile.js +102 -24
- package/dist/esm/functions/getRecords.d.ts +1 -0
- package/dist/esm/functions/getSpecificRecord.js +30 -6
- package/dist/esm/functions/getSubnames.d.ts +1 -1
- package/dist/esm/functions/getSubnames.js +4 -4
- package/dist/esm/functions/setName.d.ts +4 -3
- package/dist/esm/functions/setName.js +5 -10
- package/dist/esm/functions/setRecord.d.ts +18 -0
- package/dist/esm/functions/setRecord.js +24 -0
- package/dist/esm/functions/setRecords.d.ts +4 -2
- package/dist/esm/functions/setRecords.js +14 -12
- package/dist/esm/functions/setResolver.d.ts +4 -4
- package/dist/esm/functions/setResolver.js +6 -12
- package/dist/esm/functions/transferName.d.ts +4 -3
- package/dist/esm/functions/transferName.js +9 -13
- package/dist/esm/functions/transferSubname.d.ts +13 -3
- package/dist/esm/functions/transferSubname.js +7 -8
- package/dist/esm/functions/unwrapName.d.ts +4 -3
- package/dist/esm/functions/unwrapName.js +5 -9
- package/dist/esm/functions/wrapName.d.ts +7 -3
- package/dist/esm/functions/wrapName.js +38 -36
- package/dist/esm/generated/BaseRegistrarImplementation.d.ts +222 -201
- package/dist/esm/generated/DNSRegistrar.d.ts +68 -64
- package/dist/esm/generated/DNSSECImpl.d.ts +111 -111
- package/dist/esm/generated/DefaultReverseResolver.d.ts +17 -17
- package/dist/esm/generated/ENSRegistry.d.ts +126 -111
- package/dist/esm/generated/ETHRegistrarController.d.ts +111 -109
- package/dist/esm/generated/Multicall.d.ts +60 -60
- package/dist/esm/generated/NameWrapper.d.ts +493 -354
- package/dist/esm/generated/P256SHA256Algorithm.d.ts +11 -7
- package/dist/esm/generated/PublicResolver.d.ts +259 -235
- package/dist/esm/generated/RSASHA1Algorithm.d.ts +11 -7
- package/dist/esm/generated/RSASHA256Algorithm.d.ts +11 -7
- package/dist/esm/generated/ReverseRegistrar.d.ts +112 -103
- package/dist/esm/generated/Root.d.ts +77 -77
- package/dist/esm/generated/SHA1Digest.d.ts +7 -7
- package/dist/esm/generated/SHA1NSEC3Digest.d.ts +11 -7
- package/dist/esm/generated/SHA256Digest.d.ts +7 -7
- package/dist/esm/generated/StaticMetadataService.d.ts +7 -7
- package/dist/esm/generated/TLDPublicSuffixList.d.ts +7 -7
- package/dist/esm/generated/UniversalResolver.d.ts +31 -31
- package/dist/esm/generated/common.d.ts +1 -0
- package/dist/esm/generated/factories/DNSRegistrar__factory.d.ts +3 -15
- package/dist/esm/generated/factories/DNSRegistrar__factory.js +2 -25
- package/dist/esm/generated/factories/DNSSECImpl__factory.d.ts +3 -15
- package/dist/esm/generated/factories/DNSSECImpl__factory.js +2 -25
- package/dist/esm/generated/factories/ETHRegistrarController__factory.js +14 -4
- package/dist/esm/generated/factories/NameWrapper__factory.js +210 -79
- package/dist/esm/generated/factories/P256SHA256Algorithm__factory.d.ts +3 -15
- package/dist/esm/generated/factories/P256SHA256Algorithm__factory.js +2 -25
- package/dist/esm/generated/factories/RSASHA1Algorithm__factory.d.ts +3 -15
- package/dist/esm/generated/factories/RSASHA1Algorithm__factory.js +2 -25
- package/dist/esm/generated/factories/RSASHA256Algorithm__factory.d.ts +3 -15
- package/dist/esm/generated/factories/RSASHA256Algorithm__factory.js +2 -25
- package/dist/esm/generated/factories/SHA1Digest__factory.d.ts +3 -15
- package/dist/esm/generated/factories/SHA1Digest__factory.js +2 -25
- package/dist/esm/generated/factories/SHA1NSEC3Digest__factory.d.ts +3 -15
- package/dist/esm/generated/factories/SHA1NSEC3Digest__factory.js +2 -25
- package/dist/esm/generated/factories/SHA256Digest__factory.d.ts +3 -15
- package/dist/esm/generated/factories/SHA256Digest__factory.js +2 -25
- package/dist/esm/generated/factories/TLDPublicSuffixList__factory.d.ts +3 -15
- package/dist/esm/generated/factories/TLDPublicSuffixList__factory.js +2 -25
- package/dist/esm/generated/factories/index.d.ts +14 -0
- package/dist/esm/generated/factories/index.js +14 -0
- package/dist/esm/generated/index.d.ts +29 -1
- package/dist/esm/generated/index.js +15 -1
- package/dist/esm/index.d.ts +62 -84
- package/dist/esm/index.js +44 -21
- package/dist/esm/utils/labels.js +5 -4
- package/dist/esm/utils/makeHashIndexes.js +2 -2
- package/dist/esm/utils/normalise.d.ts +1 -0
- package/dist/esm/utils/normalise.js +25 -0
- package/dist/esm/utils/recordHelpers.d.ts +3 -0
- package/dist/esm/utils/recordHelpers.js +40 -14
- package/dist/esm/utils/registerHelpers.js +3 -4
- package/dist/esm/utils/wrapperExpiry.d.ts +5 -0
- package/dist/esm/utils/wrapperExpiry.js +26 -0
- package/dist/esm/utils/writeTx.d.ts +4 -0
- package/dist/esm/utils/writeTx.js +1 -0
- package/package.json +24 -14
- package/src/@types/dns-packet/index.d.ts +114 -0
- package/src/ABIs/Multicall.json +452 -0
- package/src/GqlManager.test.ts +170 -0
- package/src/GqlManager.ts +67 -2
- package/src/contracts/index.ts +1 -1
- package/src/{tests → functions}/batch.test.ts +7 -7
- package/src/{tests → functions}/batchWrappers.test.ts +6 -6
- package/src/{tests → functions}/burnFuses.test.ts +12 -15
- package/src/functions/burnFuses.ts +9 -11
- package/src/{tests → functions}/createSubname.test.ts +9 -17
- package/src/functions/createSubname.ts +20 -14
- package/src/{tests → functions}/deleteSubname.test.ts +12 -31
- package/src/functions/deleteSubname.ts +10 -12
- package/src/functions/getDNSOwner.test.ts +118 -0
- package/src/functions/getDNSOwner.ts +61 -0
- package/src/functions/getExpiry.test.ts +59 -0
- package/src/functions/getExpiry.ts +87 -9
- package/src/{tests → functions}/getFuses.test.ts +16 -37
- package/src/functions/getFuses.ts +12 -17
- package/src/functions/getHistory.test.ts +29 -0
- package/src/functions/getHistory.ts +2 -127
- package/src/{tests → functions}/getName.test.ts +6 -6
- package/src/functions/getName.ts +1 -1
- package/src/{tests → functions}/getNames.test.ts +98 -69
- package/src/{tests → functions}/getOwner.test.ts +21 -24
- package/src/functions/getOwner.ts +7 -7
- package/src/functions/getProfile.test.ts +143 -0
- package/src/functions/getProfile.ts +151 -24
- package/src/functions/getRecords.ts +1 -0
- package/src/functions/getResolver.test.ts +15 -0
- package/src/{tests → functions}/getSpecificRecord.test.ts +17 -14
- package/src/functions/getSpecificRecord.ts +38 -12
- package/src/functions/getSubnames.test.ts +35 -0
- package/src/functions/getSubnames.ts +76 -67
- package/src/{tests → functions}/makeCommitment.test.ts +2 -2
- package/src/functions/normalise.test.ts +22 -0
- package/src/{tests → functions}/setName.test.ts +11 -11
- package/src/functions/setName.ts +15 -17
- package/src/functions/setRecord.test.ts +103 -0
- package/src/functions/setRecord.ts +63 -0
- package/src/{tests → functions}/setRecords.test.ts +16 -13
- package/src/functions/setRecords.ts +22 -16
- package/src/{tests → functions}/setResolver.test.ts +13 -19
- package/src/functions/setResolver.ts +15 -20
- package/src/{tests → functions}/transferName.test.ts +20 -35
- package/src/functions/transferName.ts +19 -22
- package/src/{tests → functions}/transferSubname.test.ts +14 -33
- package/src/functions/transferSubname.ts +39 -13
- package/src/{tests → functions}/unwrapName.test.ts +16 -30
- package/src/functions/unwrapName.ts +20 -15
- package/src/functions/wrapName.test.ts +142 -0
- package/src/functions/wrapName.ts +63 -49
- package/src/generated/BaseRegistrarImplementation.ts +382 -296
- package/src/generated/DNSRegistrar.ts +103 -89
- package/src/generated/DNSSECImpl.ts +180 -149
- package/src/generated/DefaultReverseResolver.ts +37 -21
- package/src/generated/ENSRegistry.ts +257 -184
- package/src/generated/ETHRegistrarController.ts +252 -191
- package/src/generated/Multicall.ts +73 -57
- package/src/generated/NameWrapper.ts +979 -649
- package/src/generated/P256SHA256Algorithm.ts +21 -16
- package/src/generated/PublicResolver.ts +452 -362
- package/src/generated/RSASHA1Algorithm.ts +21 -16
- package/src/generated/RSASHA256Algorithm.ts +21 -16
- package/src/generated/ReverseRegistrar.ts +193 -141
- package/src/generated/Root.ts +146 -86
- package/src/generated/SHA1Digest.ts +12 -11
- package/src/generated/SHA1NSEC3Digest.ts +21 -16
- package/src/generated/SHA256Digest.ts +12 -11
- package/src/generated/StaticMetadataService.ts +22 -6
- package/src/generated/TLDPublicSuffixList.ts +10 -6
- package/src/generated/UniversalResolver.ts +44 -40
- package/src/generated/common.ts +2 -0
- package/src/generated/factories/DNSRegistrar__factory.ts +4 -56
- package/src/generated/factories/DNSSECImpl__factory.ts +4 -49
- package/src/generated/factories/ETHRegistrarController__factory.ts +14 -4
- package/src/generated/factories/NameWrapper__factory.ts +210 -79
- package/src/generated/factories/P256SHA256Algorithm__factory.ts +4 -40
- package/src/generated/factories/RSASHA1Algorithm__factory.ts +4 -40
- package/src/generated/factories/RSASHA256Algorithm__factory.ts +4 -40
- package/src/generated/factories/SHA1Digest__factory.ts +4 -40
- package/src/generated/factories/SHA1NSEC3Digest__factory.ts +4 -40
- package/src/generated/factories/SHA256Digest__factory.ts +4 -40
- package/src/generated/factories/TLDPublicSuffixList__factory.ts +4 -40
- package/src/generated/factories/index.ts +14 -0
- package/src/generated/index.ts +29 -1
- package/src/index.ts +117 -47
- package/src/tests/populateTransaction.test.ts +40 -0
- package/src/tests/setup.ts +17 -13
- package/src/tests/signerInjection.test.ts +46 -0
- package/src/tests/withProvider.test.ts +3 -3
- package/src/utils/labels.ts +6 -4
- package/src/utils/makeHashIndexes.ts +4 -4
- package/src/utils/normalise.ts +29 -0
- package/src/utils/recordHelpers.ts +52 -18
- package/src/utils/registerHelpers.ts +3 -4
- package/src/utils/wrapperExpiry.ts +31 -0
- package/src/utils/writeTx.ts +6 -0
- package/dist/cjs/contracts/doNotCallOnChainUniversalResolverProxy.d.ts +0 -3
- package/dist/cjs/contracts/doNotCallOnChainUniversalResolverProxy.js +0 -4
- package/dist/cjs/generated/DoNotCallOnChainUniversalResolverProxy.d.ts +0 -144
- package/dist/cjs/generated/DoNotCallOnChainUniversalResolverProxy.js +0 -2
- package/dist/cjs/generated/factories/DoNotCallOnChainUniversalResolverProxy__factory.d.ts +0 -56
- package/dist/cjs/generated/factories/DoNotCallOnChainUniversalResolverProxy__factory.js +0 -171
- package/dist/esm/contracts/doNotCallOnChainUniversalResolverProxy.d.ts +0 -3
- package/dist/esm/contracts/doNotCallOnChainUniversalResolverProxy.js +0 -2
- package/dist/esm/generated/DoNotCallOnChainUniversalResolverProxy.d.ts +0 -144
- package/dist/esm/generated/DoNotCallOnChainUniversalResolverProxy.js +0 -1
- package/dist/esm/generated/factories/DoNotCallOnChainUniversalResolverProxy__factory.d.ts +0 -56
- package/dist/esm/generated/factories/DoNotCallOnChainUniversalResolverProxy__factory.js +0 -167
- package/src/ABIs/ETHRegistrarController.json +0 -494
- package/src/ABIs/NameWrapper.json +0 -1183
- package/src/ABIs/PublicResolver.json +0 -875
- package/src/ABIs/ReverseRegistrar.json +0 -323
- package/src/ABIs/StaticMetadataService.json +0 -32
- package/src/ABIs/UniversalResolver.json +0 -187
- package/src/contracts/doNotCallOnChainUniversalResolverProxy.ts +0 -5
- package/src/generated/DoNotCallOnChainUniversalResolverProxy.ts +0 -285
- package/src/generated/factories/DoNotCallOnChainUniversalResolverProxy__factory.ts +0 -186
- package/src/tests/getExpiry.test.ts +0 -37
- package/src/tests/getHistory.test.ts +0 -101
- package/src/tests/getProfile.test.ts +0 -102
- package/src/tests/getResolver.test.ts +0 -19
- package/src/tests/getSubnames.test.ts +0 -31
- package/src/tests/wrapName.test.ts +0 -67
package/src/index.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { JsonRpcSigner } from '@ethersproject/providers'
|
|
2
|
+
import { ContractTransaction, ethers, PopulatedTransaction } from 'ethers'
|
|
2
3
|
import ContractManager from './contracts'
|
|
3
4
|
import { getContractAddress as _getContractAddress } from './contracts/getContractAddress'
|
|
4
5
|
import { SupportedNetworkId } from './contracts/types'
|
|
@@ -11,13 +12,10 @@ import type {
|
|
|
11
12
|
import type burnFuses from './functions/burnFuses'
|
|
12
13
|
import type createSubname from './functions/createSubname'
|
|
13
14
|
import type deleteSubname from './functions/deleteSubname'
|
|
15
|
+
import type getDNSOwner from './functions/getDNSOwner'
|
|
14
16
|
import type getExpiry from './functions/getExpiry'
|
|
15
17
|
import type getFuses from './functions/getFuses'
|
|
16
|
-
import type {
|
|
17
|
-
getHistory,
|
|
18
|
-
getHistoryDetailForTransactionHash,
|
|
19
|
-
getHistoryWithDetail,
|
|
20
|
-
} from './functions/getHistory'
|
|
18
|
+
import type { getHistory } from './functions/getHistory'
|
|
21
19
|
import type getName from './functions/getName'
|
|
22
20
|
import type getNames from './functions/getNames'
|
|
23
21
|
import type getOwner from './functions/getOwner'
|
|
@@ -35,6 +33,7 @@ import type {
|
|
|
35
33
|
} from './functions/getSpecificRecord'
|
|
36
34
|
import type getSubnames from './functions/getSubnames'
|
|
37
35
|
import type setName from './functions/setName'
|
|
36
|
+
import type setRecord from './functions/setRecord'
|
|
38
37
|
import type setRecords from './functions/setRecords'
|
|
39
38
|
import type setResolver from './functions/setResolver'
|
|
40
39
|
import type transferName from './functions/transferName'
|
|
@@ -43,6 +42,7 @@ import type unwrapName from './functions/unwrapName'
|
|
|
43
42
|
import type wrapName from './functions/wrapName'
|
|
44
43
|
import GqlManager from './GqlManager'
|
|
45
44
|
import singleCall from './utils/singleCall'
|
|
45
|
+
import writeTx from './utils/writeTx'
|
|
46
46
|
|
|
47
47
|
type ENSOptions = {
|
|
48
48
|
graphURI?: string | null
|
|
@@ -52,6 +52,7 @@ type ENSOptions = {
|
|
|
52
52
|
export type InternalENS = {
|
|
53
53
|
options?: ENSOptions
|
|
54
54
|
provider?: ethers.providers.Provider
|
|
55
|
+
signer: JsonRpcSigner
|
|
55
56
|
graphURI?: string | null
|
|
56
57
|
} & ENS
|
|
57
58
|
|
|
@@ -75,6 +76,28 @@ type FirstArg<F> = F extends (x: infer A, ...args: any[]) => any ? A : never
|
|
|
75
76
|
|
|
76
77
|
type FunctionDeps<F> = Extract<keyof FirstArg<F>, string>[]
|
|
77
78
|
|
|
79
|
+
type WriteOptions = {
|
|
80
|
+
addressOrIndex?: string | number
|
|
81
|
+
signer?: JsonRpcSigner
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
type OptionalWriteOptions<F> = F extends (
|
|
85
|
+
x: any,
|
|
86
|
+
arg_0: infer Z,
|
|
87
|
+
options?: infer P,
|
|
88
|
+
) => infer R
|
|
89
|
+
? (name: Z, options?: P & WriteOptions) => R
|
|
90
|
+
: F extends (x: any, arg_0: infer Z, options: infer P) => infer R
|
|
91
|
+
? (name: Z, options: P & WriteOptions) => R
|
|
92
|
+
: never
|
|
93
|
+
|
|
94
|
+
interface WriteFunction<F extends (...args: any) => any> extends Function {
|
|
95
|
+
(...args: Parameters<OptionalWriteOptions<F>>): Promise<ContractTransaction>
|
|
96
|
+
populateTransaction: (
|
|
97
|
+
...args: Parameters<OptionalWriteOptions<F>>
|
|
98
|
+
) => Promise<PopulatedTransaction>
|
|
99
|
+
}
|
|
100
|
+
|
|
78
101
|
const graphURIEndpoints: Record<string, string> = {
|
|
79
102
|
1: 'https://api.thegraph.com/subgraphs/name/ensdomains/ens',
|
|
80
103
|
3: 'https://api.thegraph.com/subgraphs/name/ensdomains/ensropsten',
|
|
@@ -171,7 +194,13 @@ export class ENS {
|
|
|
171
194
|
path: string,
|
|
172
195
|
dependencies: FunctionDeps<F>,
|
|
173
196
|
exportName: string = 'default',
|
|
174
|
-
subFunc?:
|
|
197
|
+
subFunc?:
|
|
198
|
+
| 'raw'
|
|
199
|
+
| 'decode'
|
|
200
|
+
| 'combine'
|
|
201
|
+
| 'batch'
|
|
202
|
+
| 'write'
|
|
203
|
+
| 'populateTransaction',
|
|
175
204
|
passthrough?: RawFunction,
|
|
176
205
|
): Function => {
|
|
177
206
|
// if batch is specified, create batch func
|
|
@@ -185,18 +214,40 @@ export class ENS {
|
|
|
185
214
|
await thisRef.checkInitialProvider()
|
|
186
215
|
// import the module dynamically
|
|
187
216
|
const mod = await import(
|
|
188
|
-
/* webpackMode: "lazy", webpackChunkName: "[request]", webpackPreload: true */
|
|
217
|
+
/* webpackMode: "lazy", webpackChunkName: "[request]", webpackPreload: true, webpackExclude: /.*\.ts$/ */
|
|
189
218
|
`./functions/${path}`
|
|
190
219
|
)
|
|
191
220
|
|
|
192
221
|
// if combine isn't specified, run normally
|
|
193
222
|
// otherwise, create a function from the raw and decode functions
|
|
194
223
|
if (subFunc !== 'combine') {
|
|
224
|
+
const writeable =
|
|
225
|
+
subFunc === 'write' || subFunc === 'populateTransaction'
|
|
195
226
|
// get the function to call
|
|
196
|
-
const func =
|
|
227
|
+
const func =
|
|
228
|
+
subFunc && !writeable ? mod[exportName][subFunc] : mod[exportName]
|
|
197
229
|
// get the dependencies to forward to the function as the first arg
|
|
198
|
-
|
|
230
|
+
let dependenciesToForward =
|
|
199
231
|
thisRef.forwardDependenciesFromArray<F>(dependencies)
|
|
232
|
+
|
|
233
|
+
// if func is write func, inject signer into dependencies
|
|
234
|
+
if (writeable) {
|
|
235
|
+
const options = (args[1] || {}) as WriteOptions
|
|
236
|
+
const signer =
|
|
237
|
+
options.signer ||
|
|
238
|
+
thisRef.provider?.getSigner(options.addressOrIndex)
|
|
239
|
+
const populate = subFunc === 'populateTransaction'
|
|
240
|
+
if (!signer) {
|
|
241
|
+
throw new Error('No signer specified')
|
|
242
|
+
}
|
|
243
|
+
delete options.addressOrIndex
|
|
244
|
+
delete options.signer
|
|
245
|
+
dependenciesToForward = { ...dependenciesToForward, signer }
|
|
246
|
+
return func(dependenciesToForward, args[0], options).then(
|
|
247
|
+
writeTx(signer, populate),
|
|
248
|
+
)
|
|
249
|
+
}
|
|
250
|
+
|
|
200
251
|
// return the function with the dependencies forwarded
|
|
201
252
|
return func(dependenciesToForward, ...args)
|
|
202
253
|
} else {
|
|
@@ -236,6 +287,13 @@ export class ENS {
|
|
|
236
287
|
'batch',
|
|
237
288
|
{ raw: mainFunc.raw as any, decode: mainFunc.decode as any },
|
|
238
289
|
)
|
|
290
|
+
} else if (subFunc === 'write') {
|
|
291
|
+
mainFunc.populateTransaction = this.importGenerator<F>(
|
|
292
|
+
path,
|
|
293
|
+
dependencies,
|
|
294
|
+
exportName,
|
|
295
|
+
'populateTransaction',
|
|
296
|
+
)
|
|
239
297
|
}
|
|
240
298
|
|
|
241
299
|
return mainFunc as Function
|
|
@@ -255,6 +313,25 @@ export class ENS {
|
|
|
255
313
|
): OmitFirstArg<F> =>
|
|
256
314
|
this.importGenerator<F>(path, dependencies, exportName) as OmitFirstArg<F>
|
|
257
315
|
|
|
316
|
+
/**
|
|
317
|
+
* Generates a write wrapped function
|
|
318
|
+
* @param {string} path - The path of the exported function
|
|
319
|
+
* @param {FunctionDeps} dependencies - An array of ENS properties
|
|
320
|
+
* @param {string} exportName - The export name of the target function
|
|
321
|
+
* @returns {OmitFirstArg} - The generated wrapped function
|
|
322
|
+
*/
|
|
323
|
+
private generateWriteFunction = <F extends (...args: any) => any>(
|
|
324
|
+
path: string,
|
|
325
|
+
dependencies: FunctionDeps<F>,
|
|
326
|
+
exportName: string = 'default',
|
|
327
|
+
): WriteFunction<F> =>
|
|
328
|
+
this.importGenerator<F>(
|
|
329
|
+
path,
|
|
330
|
+
dependencies,
|
|
331
|
+
exportName,
|
|
332
|
+
'write',
|
|
333
|
+
) as WriteFunction<F>
|
|
334
|
+
|
|
258
335
|
/**
|
|
259
336
|
* Generates a wrapped function from raw and decode exports
|
|
260
337
|
* @param {string} path - The path of the exported function
|
|
@@ -321,6 +398,7 @@ export class ENS {
|
|
|
321
398
|
'gqlInstance',
|
|
322
399
|
'getName',
|
|
323
400
|
'resolverMulticallWrapper',
|
|
401
|
+
'multicallWrapper',
|
|
324
402
|
'_getAddr',
|
|
325
403
|
'_getContentHash',
|
|
326
404
|
'_getText',
|
|
@@ -355,22 +433,6 @@ export class ENS {
|
|
|
355
433
|
'getHistory',
|
|
356
434
|
)
|
|
357
435
|
|
|
358
|
-
public getHistoryWithDetail = this.generateFunction<
|
|
359
|
-
typeof getHistoryWithDetail
|
|
360
|
-
>(
|
|
361
|
-
'getHistory',
|
|
362
|
-
['contracts', 'gqlInstance', 'provider'],
|
|
363
|
-
'getHistoryWithDetail',
|
|
364
|
-
)
|
|
365
|
-
|
|
366
|
-
public getHistoryDetailForTransactionHash = this.generateFunction<
|
|
367
|
-
typeof getHistoryDetailForTransactionHash
|
|
368
|
-
>(
|
|
369
|
-
'getHistory',
|
|
370
|
-
['contracts', 'provider'],
|
|
371
|
-
'getHistoryDetailForTransactionHash',
|
|
372
|
-
)
|
|
373
|
-
|
|
374
436
|
public getContentHash = this.generateRawFunction<typeof getContentHash>(
|
|
375
437
|
'initialGetters',
|
|
376
438
|
['contracts', 'universalWrapper'],
|
|
@@ -453,54 +515,62 @@ export class ENS {
|
|
|
453
515
|
'multicallWrapper',
|
|
454
516
|
)
|
|
455
517
|
|
|
456
|
-
public setName = this.
|
|
518
|
+
public setName = this.generateWriteFunction<typeof setName>('setName', [
|
|
457
519
|
'contracts',
|
|
458
|
-
'provider',
|
|
459
520
|
])
|
|
460
521
|
|
|
461
|
-
public setRecords = this.
|
|
522
|
+
public setRecords = this.generateWriteFunction<typeof setRecords>(
|
|
523
|
+
'setRecords',
|
|
524
|
+
['contracts', 'provider', 'getResolver'],
|
|
525
|
+
)
|
|
526
|
+
|
|
527
|
+
public setRecord = this.generateWriteFunction<typeof setRecord>('setRecord', [
|
|
462
528
|
'contracts',
|
|
463
529
|
'provider',
|
|
464
530
|
'getResolver',
|
|
465
531
|
])
|
|
466
532
|
|
|
467
|
-
public setResolver = this.
|
|
533
|
+
public setResolver = this.generateWriteFunction<typeof setResolver>(
|
|
468
534
|
'setResolver',
|
|
469
|
-
['contracts'
|
|
535
|
+
['contracts'],
|
|
470
536
|
)
|
|
471
537
|
|
|
472
|
-
public transferName = this.
|
|
538
|
+
public transferName = this.generateWriteFunction<typeof transferName>(
|
|
473
539
|
'transferName',
|
|
474
|
-
['contracts'
|
|
540
|
+
['contracts'],
|
|
475
541
|
)
|
|
476
542
|
|
|
477
|
-
public wrapName = this.
|
|
543
|
+
public wrapName = this.generateWriteFunction<typeof wrapName>('wrapName', [
|
|
478
544
|
'contracts',
|
|
479
|
-
'
|
|
545
|
+
'getExpiry',
|
|
480
546
|
])
|
|
481
547
|
|
|
482
|
-
public unwrapName = this.
|
|
483
|
-
'
|
|
484
|
-
'
|
|
485
|
-
|
|
548
|
+
public unwrapName = this.generateWriteFunction<typeof unwrapName>(
|
|
549
|
+
'unwrapName',
|
|
550
|
+
['contracts'],
|
|
551
|
+
)
|
|
486
552
|
|
|
487
|
-
public burnFuses = this.
|
|
553
|
+
public burnFuses = this.generateWriteFunction<typeof burnFuses>('burnFuses', [
|
|
488
554
|
'contracts',
|
|
489
|
-
'provider',
|
|
490
555
|
])
|
|
491
556
|
|
|
492
|
-
public createSubname = this.
|
|
557
|
+
public createSubname = this.generateWriteFunction<typeof createSubname>(
|
|
493
558
|
'createSubname',
|
|
494
|
-
['contracts', '
|
|
559
|
+
['contracts', 'getExpiry'],
|
|
495
560
|
)
|
|
496
561
|
|
|
497
|
-
public deleteSubname = this.
|
|
562
|
+
public deleteSubname = this.generateWriteFunction<typeof deleteSubname>(
|
|
498
563
|
'deleteSubname',
|
|
499
|
-
['
|
|
564
|
+
['transferSubname'],
|
|
500
565
|
)
|
|
501
566
|
|
|
502
|
-
public transferSubname = this.
|
|
567
|
+
public transferSubname = this.generateWriteFunction<typeof transferSubname>(
|
|
503
568
|
'transferSubname',
|
|
504
|
-
['contracts', '
|
|
569
|
+
['contracts', 'getExpiry'],
|
|
570
|
+
)
|
|
571
|
+
|
|
572
|
+
public getDNSOwner = this.generateFunction<typeof getDNSOwner>(
|
|
573
|
+
'getDNSOwner',
|
|
574
|
+
[],
|
|
505
575
|
)
|
|
506
576
|
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { ethers } from 'ethers'
|
|
2
|
+
import { ENS } from '..'
|
|
3
|
+
import setup from '../tests/setup'
|
|
4
|
+
|
|
5
|
+
let ENSInstance: ENS
|
|
6
|
+
let revert: Awaited<ReturnType<typeof setup>>['revert']
|
|
7
|
+
let provider: ethers.providers.JsonRpcProvider
|
|
8
|
+
let accounts: string[]
|
|
9
|
+
|
|
10
|
+
beforeAll(async () => {
|
|
11
|
+
;({ ENSInstance, revert, provider } = await setup())
|
|
12
|
+
accounts = await provider.listAccounts()
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
afterAll(async () => {
|
|
16
|
+
await revert()
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
jest.setTimeout(20000)
|
|
20
|
+
|
|
21
|
+
describe('populateTransaction', () => {
|
|
22
|
+
beforeEach(async () => {
|
|
23
|
+
await revert()
|
|
24
|
+
})
|
|
25
|
+
it('should return a transaction successfully', async () => {
|
|
26
|
+
const tx = await ENSInstance.setName('fleek.eth')
|
|
27
|
+
expect(tx).toBeTruthy()
|
|
28
|
+
if (tx) {
|
|
29
|
+
await tx.wait()
|
|
30
|
+
expect(tx.hash).toBeTruthy()
|
|
31
|
+
}
|
|
32
|
+
})
|
|
33
|
+
it('should return a populated transaction successfully', async () => {
|
|
34
|
+
const tx = await ENSInstance.setName.populateTransaction('fleek.eth')
|
|
35
|
+
expect(tx).toBeTruthy()
|
|
36
|
+
if (tx) {
|
|
37
|
+
expect(tx).not.toHaveProperty('hash')
|
|
38
|
+
}
|
|
39
|
+
})
|
|
40
|
+
})
|
package/src/tests/setup.ts
CHANGED
|
@@ -1,23 +1,27 @@
|
|
|
1
|
+
import { config } from 'dotenv'
|
|
1
2
|
import { ethers } from 'ethers'
|
|
3
|
+
import { resolve } from 'path'
|
|
2
4
|
import { ENS } from '../'
|
|
3
5
|
import { ContractName, SupportedNetworkId } from '../contracts/types'
|
|
4
6
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
7
|
+
config({
|
|
8
|
+
path: resolve(__dirname, '../../.env.local'),
|
|
9
|
+
override: true,
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
const deploymentAddresses = JSON.parse(
|
|
13
|
+
process.env.DEPLOYMENT_ADDRESSES!,
|
|
14
|
+
) as Record<ContractName | 'ENSRegistry', string>
|
|
14
15
|
|
|
15
16
|
const createENS = (graphURI: string) =>
|
|
16
17
|
new ENS({
|
|
17
18
|
graphURI,
|
|
18
|
-
getContractAddress:
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
getContractAddress: (_: SupportedNetworkId) => (contractName) =>
|
|
20
|
+
deploymentAddresses[
|
|
21
|
+
contractName === 'ENSRegistryWithFallback'
|
|
22
|
+
? 'ENSRegistry'
|
|
23
|
+
: contractName
|
|
24
|
+
],
|
|
21
25
|
})
|
|
22
26
|
|
|
23
27
|
export default async (useReal?: boolean) => {
|
|
@@ -27,7 +31,7 @@ export default async (useReal?: boolean) => {
|
|
|
27
31
|
|
|
28
32
|
const provider = new ethers.providers.JsonRpcProvider(
|
|
29
33
|
'http://localhost:8545',
|
|
30
|
-
|
|
34
|
+
1337,
|
|
31
35
|
)
|
|
32
36
|
|
|
33
37
|
let ENSInstance = createENS(graphURI)
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { ContractTransaction, ethers } from 'ethers'
|
|
2
|
+
import { ENS } from '..'
|
|
3
|
+
import setup from '../tests/setup'
|
|
4
|
+
|
|
5
|
+
let ENSInstance: ENS
|
|
6
|
+
let revert: Awaited<ReturnType<typeof setup>>['revert']
|
|
7
|
+
let provider: ethers.providers.JsonRpcProvider
|
|
8
|
+
let accounts: string[]
|
|
9
|
+
|
|
10
|
+
beforeAll(async () => {
|
|
11
|
+
;({ ENSInstance, revert, provider } = await setup())
|
|
12
|
+
accounts = await provider.listAccounts()
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
afterAll(async () => {
|
|
16
|
+
await revert()
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
jest.setTimeout(20000)
|
|
20
|
+
|
|
21
|
+
describe('Signer Injection', () => {
|
|
22
|
+
beforeEach(async () => {
|
|
23
|
+
await revert()
|
|
24
|
+
})
|
|
25
|
+
it('should return a transaction successfully for a custom signer', async () => {
|
|
26
|
+
const signer = provider.getSigner(accounts[3])
|
|
27
|
+
const tx = await ENSInstance.setName('fleek.eth', {
|
|
28
|
+
signer,
|
|
29
|
+
})
|
|
30
|
+
expect(tx).toBeTruthy()
|
|
31
|
+
if (tx) {
|
|
32
|
+
await tx.wait()
|
|
33
|
+
expect(tx.from).toBe(accounts[3])
|
|
34
|
+
}
|
|
35
|
+
})
|
|
36
|
+
it('should return a transaction succesfully for a custom signer index', async () => {
|
|
37
|
+
const tx = (await ENSInstance.setName('fleek.eth', {
|
|
38
|
+
addressOrIndex: 3,
|
|
39
|
+
})) as ContractTransaction
|
|
40
|
+
expect(tx).toBeTruthy()
|
|
41
|
+
if (tx) {
|
|
42
|
+
await tx.wait()
|
|
43
|
+
expect(tx.from).toBe(accounts[3])
|
|
44
|
+
}
|
|
45
|
+
})
|
|
46
|
+
})
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ethers } from 'ethers'
|
|
2
2
|
import { ENS } from '..'
|
|
3
|
-
import setup from '
|
|
3
|
+
import setup from '../tests/setup'
|
|
4
4
|
|
|
5
5
|
let ENSInstance: ENS
|
|
6
6
|
let providerFake: ethers.providers.JsonRpcProvider
|
|
@@ -15,11 +15,11 @@ beforeAll(async () => {
|
|
|
15
15
|
|
|
16
16
|
describe('withProvider', () => {
|
|
17
17
|
it('should be able to use a new provider', async () => {
|
|
18
|
-
const addr = await ENSInstance.getAddr('
|
|
18
|
+
const addr = await ENSInstance.getAddr('with-profile.eth')
|
|
19
19
|
expect(addr).toBeTruthy()
|
|
20
20
|
|
|
21
21
|
try {
|
|
22
|
-
await ENSInstance.withProvider(providerFake).getOwner('
|
|
22
|
+
await ENSInstance.withProvider(providerFake).getOwner('with-profile.eth')
|
|
23
23
|
expect(false).toBeTruthy()
|
|
24
24
|
} catch {
|
|
25
25
|
expect(true).toBeTruthy()
|
package/src/utils/labels.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { solidityKeccak256 } from 'ethers/lib/utils'
|
|
2
2
|
import { truncateFormat } from './format'
|
|
3
3
|
|
|
4
|
+
const hasLocalStorage = typeof localStorage !== 'undefined'
|
|
5
|
+
|
|
4
6
|
export const labelhash = (input: string) =>
|
|
5
7
|
solidityKeccak256(['string'], [input])
|
|
6
8
|
|
|
@@ -17,7 +19,7 @@ export function decodeLabelhash(hash: string) {
|
|
|
17
19
|
throw Error('Expected encoded labelhash to have a length of 66')
|
|
18
20
|
}
|
|
19
21
|
|
|
20
|
-
return
|
|
22
|
+
return `0x${hash.slice(1, -1)}`
|
|
21
23
|
}
|
|
22
24
|
|
|
23
25
|
export function encodeLabelhash(hash: string) {
|
|
@@ -37,13 +39,13 @@ export function isEncodedLabelhash(hash: string) {
|
|
|
37
39
|
}
|
|
38
40
|
|
|
39
41
|
function getLabels() {
|
|
40
|
-
return
|
|
42
|
+
return hasLocalStorage
|
|
41
43
|
? JSON.parse(localStorage.getItem('ensjs:labels') as string) || {}
|
|
42
44
|
: {}
|
|
43
45
|
}
|
|
44
46
|
|
|
45
47
|
function _saveLabel(hash: string, label: any) {
|
|
46
|
-
if (!
|
|
48
|
+
if (!hasLocalStorage) return hash
|
|
47
49
|
const labels = getLabels()
|
|
48
50
|
localStorage.setItem(
|
|
49
51
|
'ensjs:labels',
|
|
@@ -106,7 +108,7 @@ export function decryptName(name: string) {
|
|
|
106
108
|
export const truncateUndecryptedName = (name: string) => truncateFormat(name)
|
|
107
109
|
|
|
108
110
|
export function checkLocalStorageSize() {
|
|
109
|
-
if (!
|
|
111
|
+
if (!hasLocalStorage) return 'Empty (0 KB)'
|
|
110
112
|
let allStrings = ''
|
|
111
113
|
for (const key in window.localStorage) {
|
|
112
114
|
if (Object.prototype.hasOwnProperty.call(window.localStorage, key)) {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { namehash } from './normalise'
|
|
2
2
|
|
|
3
3
|
export const makeOtherIndexes = (data: string, findStr: string) =>
|
|
4
4
|
Array.from(data.matchAll(findStr as any)).map((x: any) => x.index / 2 - 1)
|
|
5
5
|
|
|
6
6
|
export const makeNamehashIndexes = (data: string, name: string) =>
|
|
7
|
-
Array.from(
|
|
8
|
-
|
|
9
|
-
)
|
|
7
|
+
Array.from(data.matchAll(namehash(name).substring(2) as any)).map(
|
|
8
|
+
(x: any) => x.index / 2 - 1,
|
|
9
|
+
)
|
package/src/utils/normalise.ts
CHANGED
|
@@ -1,4 +1,33 @@
|
|
|
1
|
+
import { concat, hexlify, keccak256, toUtf8Bytes } from 'ethers/lib/utils'
|
|
1
2
|
import uts46 from 'idna-uts46-hx/uts46bundle.js'
|
|
3
|
+
import { decodeLabelhash, isEncodedLabelhash } from './labels'
|
|
4
|
+
|
|
5
|
+
const zeros = new Uint8Array(32)
|
|
6
|
+
zeros.fill(0)
|
|
2
7
|
|
|
3
8
|
export const normalise = (name: string) =>
|
|
4
9
|
name ? uts46.toUnicode(name, { useStd3ASCII: true }) : name
|
|
10
|
+
|
|
11
|
+
export const namehash = (name: string): string => {
|
|
12
|
+
let result: string | Uint8Array = zeros
|
|
13
|
+
|
|
14
|
+
if (name) {
|
|
15
|
+
const labels = name.split('.')
|
|
16
|
+
|
|
17
|
+
for (var i = labels.length - 1; i >= 0; i--) {
|
|
18
|
+
let labelSha: string
|
|
19
|
+
if (isEncodedLabelhash(labels[i])) {
|
|
20
|
+
labelSha = decodeLabelhash(labels[i])
|
|
21
|
+
} else {
|
|
22
|
+
const normalised = normalise(labels[i])
|
|
23
|
+
labelSha = keccak256(toUtf8Bytes(normalised))
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
result = keccak256(concat([result, labelSha]))
|
|
27
|
+
}
|
|
28
|
+
} else {
|
|
29
|
+
result = hexlify(zeros)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return result as string
|
|
33
|
+
}
|
|
@@ -33,6 +33,47 @@ export const generateSetAddr = (
|
|
|
33
33
|
)
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
export type RecordTypes = 'contentHash' | 'text' | 'addr'
|
|
37
|
+
|
|
38
|
+
export type RecordInput<T extends RecordTypes> = T extends 'contentHash'
|
|
39
|
+
? string
|
|
40
|
+
: RecordItem
|
|
41
|
+
|
|
42
|
+
export function generateSingleRecordCall<T extends RecordTypes>(
|
|
43
|
+
namehash: string,
|
|
44
|
+
resolver: PublicResolver,
|
|
45
|
+
type: T,
|
|
46
|
+
): (record: RecordInput<T>) => string {
|
|
47
|
+
if (type === 'contentHash') {
|
|
48
|
+
return (_r: RecordInput<T>) => {
|
|
49
|
+
const record = _r as string
|
|
50
|
+
let _contentHash = ''
|
|
51
|
+
if (record !== _contentHash) {
|
|
52
|
+
const encoded = encodeContenthash(record)
|
|
53
|
+
if (encoded.error) throw new Error(encoded.error)
|
|
54
|
+
_contentHash = encoded.encoded as string
|
|
55
|
+
}
|
|
56
|
+
return resolver.interface.encodeFunctionData('setContenthash', [
|
|
57
|
+
namehash,
|
|
58
|
+
_contentHash,
|
|
59
|
+
])
|
|
60
|
+
}
|
|
61
|
+
} else {
|
|
62
|
+
return (_r: RecordInput<T>) => {
|
|
63
|
+
const record = _r as RecordItem
|
|
64
|
+
if (type === 'text') {
|
|
65
|
+
return resolver.interface.encodeFunctionData('setText', [
|
|
66
|
+
namehash,
|
|
67
|
+
record.key,
|
|
68
|
+
record.value,
|
|
69
|
+
])
|
|
70
|
+
} else {
|
|
71
|
+
return generateSetAddr(namehash, record.key, record.value, resolver)
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
36
77
|
export const generateRecordCallArray = (
|
|
37
78
|
namehash: string,
|
|
38
79
|
records: RecordOptions,
|
|
@@ -41,31 +82,24 @@ export const generateRecordCallArray = (
|
|
|
41
82
|
const calls: string[] = []
|
|
42
83
|
|
|
43
84
|
if (records.contentHash) {
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
'
|
|
48
|
-
|
|
49
|
-
)
|
|
85
|
+
const data = generateSingleRecordCall(
|
|
86
|
+
namehash,
|
|
87
|
+
resolver,
|
|
88
|
+
'contentHash',
|
|
89
|
+
)(records.contentHash)
|
|
50
90
|
data && calls.push(data)
|
|
51
91
|
}
|
|
52
92
|
|
|
53
93
|
if (records.texts && records.texts.length > 0) {
|
|
54
|
-
records.texts
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
key,
|
|
58
|
-
value,
|
|
59
|
-
])
|
|
60
|
-
data && calls.push(data)
|
|
61
|
-
})
|
|
94
|
+
records.texts
|
|
95
|
+
.map(generateSingleRecordCall(namehash, resolver, 'text'))
|
|
96
|
+
.forEach((call) => calls.push(call))
|
|
62
97
|
}
|
|
63
98
|
|
|
64
99
|
if (records.coinTypes && records.coinTypes.length > 0) {
|
|
65
|
-
records.coinTypes
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
})
|
|
100
|
+
records.coinTypes
|
|
101
|
+
.map(generateSingleRecordCall(namehash, resolver, 'addr'))
|
|
102
|
+
.forEach((call) => calls.push(call))
|
|
69
103
|
}
|
|
70
104
|
|
|
71
105
|
return calls
|
|
@@ -3,6 +3,7 @@ import type { FuseOptions } from '../@types/FuseOptions'
|
|
|
3
3
|
import type { PublicResolver } from '../generated'
|
|
4
4
|
import generateFuseInput from './generateFuseInput'
|
|
5
5
|
import { labelhash } from './labels'
|
|
6
|
+
import { namehash } from './normalise'
|
|
6
7
|
import { generateRecordCallArray, RecordOptions } from './recordHelpers'
|
|
7
8
|
|
|
8
9
|
export const randomSecret = () => {
|
|
@@ -28,11 +29,9 @@ export const makeCommitment = ({
|
|
|
28
29
|
fuses?: FuseOptions
|
|
29
30
|
}) => {
|
|
30
31
|
const label = labelhash(name.split('.')[0])
|
|
31
|
-
const
|
|
32
|
+
const hash = namehash(name)
|
|
32
33
|
const resolverAddress = resolver.address
|
|
33
|
-
const data = records
|
|
34
|
-
? generateRecordCallArray(namehash, records, resolver)
|
|
35
|
-
: []
|
|
34
|
+
const data = records ? generateRecordCallArray(hash, records, resolver) : []
|
|
36
35
|
const secret = randomSecret()
|
|
37
36
|
const fuseData = fuses ? generateFuseInput(fuses) : '0'
|
|
38
37
|
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { BigNumber } from 'ethers'
|
|
2
|
+
import { ENSArgs } from '..'
|
|
3
|
+
|
|
4
|
+
export type Expiry = string | number | Date | BigNumber
|
|
5
|
+
|
|
6
|
+
export const MAX_EXPIRY = BigNumber.from(2).pow(64).sub(1)
|
|
7
|
+
|
|
8
|
+
export const makeExpiry = async (
|
|
9
|
+
{ getExpiry }: ENSArgs<'getExpiry'>,
|
|
10
|
+
name: string,
|
|
11
|
+
expiry?: Expiry,
|
|
12
|
+
) => {
|
|
13
|
+
if (expiry) {
|
|
14
|
+
if (expiry instanceof Date) {
|
|
15
|
+
return BigNumber.from(expiry.getTime() / 1000)
|
|
16
|
+
} else if (expiry instanceof BigNumber) {
|
|
17
|
+
return expiry
|
|
18
|
+
} else {
|
|
19
|
+
return BigNumber.from(expiry)
|
|
20
|
+
}
|
|
21
|
+
} else {
|
|
22
|
+
if (name.endsWith('.eth')) {
|
|
23
|
+
const expResponse = await getExpiry(name)
|
|
24
|
+
if (!expResponse?.expiry)
|
|
25
|
+
throw new Error("Couldn't get expiry for name, please provide one.")
|
|
26
|
+
return BigNumber.from(expResponse.expiry.getTime() / 1000)
|
|
27
|
+
} else {
|
|
28
|
+
return MAX_EXPIRY
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|