@ensdomains/ensjs 4.0.2 → 4.0.3-alpha.11
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/contracts/consts.js +26 -0
- package/dist/cjs/contracts/consts.js.map +1 -1
- package/dist/cjs/contracts/ethRegistrarController.js +41 -1
- package/dist/cjs/contracts/ethRegistrarController.js.map +1 -1
- package/dist/cjs/contracts/index.js +16 -2
- package/dist/cjs/contracts/index.js.map +1 -1
- package/dist/cjs/contracts/legacyEthRegistrarController.js +187 -0
- package/dist/cjs/contracts/legacyEthRegistrarController.js.map +1 -0
- package/dist/cjs/errors/register.js +23 -0
- package/dist/cjs/errors/register.js.map +1 -0
- package/dist/cjs/errors/version.js +1 -1
- package/dist/cjs/errors/version.js.map +1 -1
- package/dist/cjs/functions/wallet/legacyCommitName.js +50 -0
- package/dist/cjs/functions/wallet/legacyCommitName.js.map +1 -0
- package/dist/cjs/functions/wallet/legacyRegisterName.js +58 -0
- package/dist/cjs/functions/wallet/legacyRegisterName.js.map +1 -0
- package/dist/cjs/utils/index.js +9 -1
- package/dist/cjs/utils/index.js.map +1 -1
- package/dist/cjs/utils/legacyRegisterHelpers.js +55 -0
- package/dist/cjs/utils/legacyRegisterHelpers.js.map +1 -0
- package/dist/cjs/wallet.js +5 -1
- package/dist/cjs/wallet.js.map +1 -1
- package/dist/esm/contracts/consts.js +26 -0
- package/dist/esm/contracts/consts.js.map +1 -1
- package/dist/esm/contracts/ethRegistrarController.js +40 -0
- package/dist/esm/contracts/ethRegistrarController.js.map +1 -1
- package/dist/esm/contracts/index.js +2 -1
- package/dist/esm/contracts/index.js.map +1 -1
- package/dist/esm/contracts/legacyEthRegistrarController.js +184 -0
- package/dist/esm/contracts/legacyEthRegistrarController.js.map +1 -0
- package/dist/esm/errors/register.js +19 -0
- package/dist/esm/errors/register.js.map +1 -0
- package/dist/esm/errors/version.js +1 -1
- package/dist/esm/errors/version.js.map +1 -1
- package/dist/esm/functions/wallet/legacyCommitName.js +72 -0
- package/dist/esm/functions/wallet/legacyCommitName.js.map +1 -0
- package/dist/esm/functions/wallet/legacyRegisterName.js +94 -0
- package/dist/esm/functions/wallet/legacyRegisterName.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/legacyRegisterHelpers.js +45 -0
- package/dist/esm/utils/legacyRegisterHelpers.js.map +1 -0
- package/dist/esm/wallet.js +2 -0
- package/dist/esm/wallet.js.map +1 -1
- package/dist/types/clients/decorators/wallet.d.ts +4 -4
- package/dist/types/clients/wallet.d.ts +4 -4
- package/dist/types/contracts/consts.d.ts +27 -1
- package/dist/types/contracts/consts.d.ts.map +1 -1
- package/dist/types/contracts/ethRegistrarController.d.ts +31 -0
- package/dist/types/contracts/ethRegistrarController.d.ts.map +1 -1
- package/dist/types/contracts/index.d.ts +2 -1
- package/dist/types/contracts/index.d.ts.map +1 -1
- package/dist/types/contracts/legacyEthRegistrarController.d.ts +263 -0
- package/dist/types/contracts/legacyEthRegistrarController.d.ts.map +1 -0
- package/dist/types/errors/register.d.ts +10 -0
- package/dist/types/errors/register.d.ts.map +1 -0
- package/dist/types/errors/version.d.ts +1 -1
- package/dist/types/errors/version.d.ts.map +1 -1
- package/dist/types/functions/wallet/legacyCommitName.d.ts +41 -0
- package/dist/types/functions/wallet/legacyCommitName.d.ts.map +1 -0
- package/dist/types/functions/wallet/legacyRegisterName.d.ts +60 -0
- package/dist/types/functions/wallet/legacyRegisterName.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/dist/types/utils/legacyRegisterHelpers.d.ts +49 -0
- package/dist/types/utils/legacyRegisterHelpers.d.ts.map +1 -0
- package/dist/types/wallet.d.ts +2 -0
- package/dist/types/wallet.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/contracts/consts.ts +28 -0
- package/src/contracts/ethRegistrarController.ts +41 -0
- package/src/contracts/index.ts +15 -0
- package/src/contracts/legacyEthRegistrarController.ts +194 -0
- package/src/errors/register.ts +22 -0
- package/src/errors/version.ts +1 -1
- package/src/functions/wallet/legacyCommitName.ts +127 -0
- package/src/functions/wallet/legacyRegisterName.ts +161 -0
- package/src/utils/index.ts +15 -0
- package/src/utils/legacyRegisterHelpers.ts +147 -0
- package/src/wallet.ts +14 -0
package/src/contracts/index.ts
CHANGED
|
@@ -40,8 +40,23 @@ export {
|
|
|
40
40
|
ethRegistrarControllerRegisterSnippet,
|
|
41
41
|
ethRegistrarControllerRenewSnippet,
|
|
42
42
|
ethRegistrarControllerRentPriceSnippet,
|
|
43
|
+
ethRegistrarControllerNameRegisteredEventSnippet,
|
|
43
44
|
} from './ethRegistrarController.js'
|
|
44
45
|
export { getChainContractAddress } from './getChainContractAddress.js'
|
|
46
|
+
export {
|
|
47
|
+
legacyEthRegistrarControllerAvailableSnippet,
|
|
48
|
+
legacyEthRegistrarControllerCommitSnippet,
|
|
49
|
+
legacyEthRegistrarControllerCommitmentsSnippet,
|
|
50
|
+
legacyEthRegistrarControllerMakeCommitmentSnippet,
|
|
51
|
+
legacyEthRegistrarControllerMakeCommitmentWithConfigSnippet,
|
|
52
|
+
legacyEthRegistrarControllerRegisterSnippet,
|
|
53
|
+
legacyEthRegistrarControllerRegisterWithConfigSnippet,
|
|
54
|
+
legacyEthRegistrarControllerRenewSnippet,
|
|
55
|
+
legacyEthRegistrarControllerRentPriceSnippet,
|
|
56
|
+
legacyEthRegistrarControllerSupportsInterfaceSnippet,
|
|
57
|
+
legacyEthRegistrarControllerTransferOwnershipSnippet,
|
|
58
|
+
legacyEthRegistrarControllerNameRegisteredEventSnippet as legacyNameRegisteredEventSnippet,
|
|
59
|
+
} from './legacyEthRegistrarController.js'
|
|
45
60
|
export {
|
|
46
61
|
multicallGetCurrentBlockTimestampSnippet,
|
|
47
62
|
multicallTryAggregateSnippet,
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
export const legacyEthRegistrarControllerAvailableSnippet = [
|
|
2
|
+
{
|
|
3
|
+
constant: true,
|
|
4
|
+
inputs: [{ internalType: 'string', name: 'name', type: 'string' }],
|
|
5
|
+
name: 'available',
|
|
6
|
+
outputs: [{ internalType: 'bool', name: '', type: 'bool' }],
|
|
7
|
+
payable: false,
|
|
8
|
+
stateMutability: 'view',
|
|
9
|
+
type: 'function',
|
|
10
|
+
},
|
|
11
|
+
] as const
|
|
12
|
+
|
|
13
|
+
export const legacyEthRegistrarControllerCommitSnippet = [
|
|
14
|
+
{
|
|
15
|
+
constant: false,
|
|
16
|
+
inputs: [{ internalType: 'bytes32', name: 'commitment', type: 'bytes32' }],
|
|
17
|
+
name: 'commit',
|
|
18
|
+
outputs: [],
|
|
19
|
+
payable: false,
|
|
20
|
+
stateMutability: 'nonpayable',
|
|
21
|
+
type: 'function',
|
|
22
|
+
},
|
|
23
|
+
] as const
|
|
24
|
+
|
|
25
|
+
export const legacyEthRegistrarControllerCommitmentsSnippet = [
|
|
26
|
+
{
|
|
27
|
+
constant: true,
|
|
28
|
+
inputs: [{ internalType: 'bytes32', name: '', type: 'bytes32' }],
|
|
29
|
+
name: 'commitments',
|
|
30
|
+
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
|
|
31
|
+
payable: false,
|
|
32
|
+
stateMutability: 'view',
|
|
33
|
+
type: 'function',
|
|
34
|
+
},
|
|
35
|
+
] as const
|
|
36
|
+
|
|
37
|
+
export const legacyEthRegistrarControllerMakeCommitmentSnippet = [
|
|
38
|
+
{
|
|
39
|
+
constant: true,
|
|
40
|
+
inputs: [
|
|
41
|
+
{ internalType: 'string', name: 'name', type: 'string' },
|
|
42
|
+
{ internalType: 'address', name: 'owner', type: 'address' },
|
|
43
|
+
{ internalType: 'bytes32', name: 'secret', type: 'bytes32' },
|
|
44
|
+
],
|
|
45
|
+
name: 'makeCommitment',
|
|
46
|
+
outputs: [{ internalType: 'bytes32', name: '', type: 'bytes32' }],
|
|
47
|
+
payable: false,
|
|
48
|
+
stateMutability: 'pure',
|
|
49
|
+
type: 'function',
|
|
50
|
+
},
|
|
51
|
+
] as const
|
|
52
|
+
|
|
53
|
+
export const legacyEthRegistrarControllerMakeCommitmentWithConfigSnippet = [
|
|
54
|
+
{
|
|
55
|
+
constant: true,
|
|
56
|
+
inputs: [
|
|
57
|
+
{ internalType: 'string', name: 'name', type: 'string' },
|
|
58
|
+
{ internalType: 'address', name: 'owner', type: 'address' },
|
|
59
|
+
{ internalType: 'bytes32', name: 'secret', type: 'bytes32' },
|
|
60
|
+
{ internalType: 'address', name: 'resolver', type: 'address' },
|
|
61
|
+
{ internalType: 'address', name: 'addr', type: 'address' },
|
|
62
|
+
],
|
|
63
|
+
name: 'makeCommitmentWithConfig',
|
|
64
|
+
outputs: [{ internalType: 'bytes32', name: '', type: 'bytes32' }],
|
|
65
|
+
payable: false,
|
|
66
|
+
stateMutability: 'pure',
|
|
67
|
+
type: 'function',
|
|
68
|
+
},
|
|
69
|
+
] as const
|
|
70
|
+
|
|
71
|
+
export const legacyEthRegistrarControllerRegisterSnippet = [
|
|
72
|
+
{
|
|
73
|
+
constant: false,
|
|
74
|
+
inputs: [
|
|
75
|
+
{ internalType: 'string', name: 'name', type: 'string' },
|
|
76
|
+
{ internalType: 'address', name: 'owner', type: 'address' },
|
|
77
|
+
{ internalType: 'uint256', name: 'duration', type: 'uint256' },
|
|
78
|
+
{ internalType: 'bytes32', name: 'secret', type: 'bytes32' },
|
|
79
|
+
],
|
|
80
|
+
name: 'register',
|
|
81
|
+
outputs: [],
|
|
82
|
+
payable: true,
|
|
83
|
+
stateMutability: 'payable',
|
|
84
|
+
type: 'function',
|
|
85
|
+
},
|
|
86
|
+
] as const
|
|
87
|
+
|
|
88
|
+
export const legacyEthRegistrarControllerRegisterWithConfigSnippet = [
|
|
89
|
+
{
|
|
90
|
+
constant: false,
|
|
91
|
+
inputs: [
|
|
92
|
+
{ internalType: 'string', name: 'name', type: 'string' },
|
|
93
|
+
{ internalType: 'address', name: 'owner', type: 'address' },
|
|
94
|
+
{ internalType: 'uint256', name: 'duration', type: 'uint256' },
|
|
95
|
+
{ internalType: 'bytes32', name: 'secret', type: 'bytes32' },
|
|
96
|
+
{ internalType: 'address', name: 'resolver', type: 'address' },
|
|
97
|
+
{ internalType: 'address', name: 'addr', type: 'address' },
|
|
98
|
+
],
|
|
99
|
+
name: 'registerWithConfig',
|
|
100
|
+
outputs: [],
|
|
101
|
+
payable: true,
|
|
102
|
+
stateMutability: 'payable',
|
|
103
|
+
type: 'function',
|
|
104
|
+
},
|
|
105
|
+
] as const
|
|
106
|
+
|
|
107
|
+
export const legacyEthRegistrarControllerRenewSnippet = [
|
|
108
|
+
{
|
|
109
|
+
constant: false,
|
|
110
|
+
inputs: [
|
|
111
|
+
{ internalType: 'string', name: 'name', type: 'string' },
|
|
112
|
+
{ internalType: 'uint256', name: 'duration', type: 'uint256' },
|
|
113
|
+
],
|
|
114
|
+
name: 'renew',
|
|
115
|
+
outputs: [],
|
|
116
|
+
payable: true,
|
|
117
|
+
stateMutability: 'payable',
|
|
118
|
+
type: 'function',
|
|
119
|
+
},
|
|
120
|
+
] as const
|
|
121
|
+
|
|
122
|
+
export const legacyEthRegistrarControllerRentPriceSnippet = [
|
|
123
|
+
{
|
|
124
|
+
constant: true,
|
|
125
|
+
inputs: [
|
|
126
|
+
{ internalType: 'string', name: 'name', type: 'string' },
|
|
127
|
+
{ internalType: 'uint256', name: 'duration', type: 'uint256' },
|
|
128
|
+
],
|
|
129
|
+
name: 'rentPrice',
|
|
130
|
+
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
|
|
131
|
+
payable: false,
|
|
132
|
+
stateMutability: 'view',
|
|
133
|
+
type: 'function',
|
|
134
|
+
},
|
|
135
|
+
] as const
|
|
136
|
+
|
|
137
|
+
export const legacyEthRegistrarControllerSupportsInterfaceSnippet = [
|
|
138
|
+
{
|
|
139
|
+
constant: true,
|
|
140
|
+
inputs: [{ internalType: 'bytes4', name: 'interfaceID', type: 'bytes4' }],
|
|
141
|
+
name: 'supportsInterface',
|
|
142
|
+
outputs: [{ internalType: 'bool', name: '', type: 'bool' }],
|
|
143
|
+
payable: false,
|
|
144
|
+
stateMutability: 'pure',
|
|
145
|
+
type: 'function',
|
|
146
|
+
},
|
|
147
|
+
] as const
|
|
148
|
+
|
|
149
|
+
export const legacyEthRegistrarControllerTransferOwnershipSnippet = [
|
|
150
|
+
{
|
|
151
|
+
constant: false,
|
|
152
|
+
inputs: [{ internalType: 'address', name: 'newOwner', type: 'address' }],
|
|
153
|
+
name: 'transferOwnership',
|
|
154
|
+
outputs: [],
|
|
155
|
+
payable: false,
|
|
156
|
+
stateMutability: 'nonpayable',
|
|
157
|
+
type: 'function',
|
|
158
|
+
},
|
|
159
|
+
] as const
|
|
160
|
+
|
|
161
|
+
export const legacyEthRegistrarControllerNameRegisteredEventSnippet = [
|
|
162
|
+
{
|
|
163
|
+
anonymous: false,
|
|
164
|
+
inputs: [
|
|
165
|
+
{ indexed: false, internalType: 'string', name: 'name', type: 'string' },
|
|
166
|
+
{
|
|
167
|
+
indexed: true,
|
|
168
|
+
internalType: 'bytes32',
|
|
169
|
+
name: 'label',
|
|
170
|
+
type: 'bytes32',
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
indexed: true,
|
|
174
|
+
internalType: 'address',
|
|
175
|
+
name: 'owner',
|
|
176
|
+
type: 'address',
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
indexed: false,
|
|
180
|
+
internalType: 'uint256',
|
|
181
|
+
name: 'cost',
|
|
182
|
+
type: 'uint256',
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
indexed: false,
|
|
186
|
+
internalType: 'uint256',
|
|
187
|
+
name: 'expires',
|
|
188
|
+
type: 'uint256',
|
|
189
|
+
},
|
|
190
|
+
],
|
|
191
|
+
name: 'NameRegistered',
|
|
192
|
+
type: 'event',
|
|
193
|
+
},
|
|
194
|
+
] as const
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Address } from 'viem'
|
|
2
|
+
import { BaseError } from './base.js'
|
|
3
|
+
import { EMPTY_ADDRESS } from '../utils/consts.js'
|
|
4
|
+
|
|
5
|
+
export class LegacyRegistrationInvalidConfigError extends BaseError {
|
|
6
|
+
override name = 'LegacyRegistrationInvalidConfigError'
|
|
7
|
+
|
|
8
|
+
constructor({
|
|
9
|
+
resolverAddress,
|
|
10
|
+
address,
|
|
11
|
+
}: {
|
|
12
|
+
resolverAddress?: Address
|
|
13
|
+
address?: Address
|
|
14
|
+
}) {
|
|
15
|
+
super(`Resolver address is required when setting an address`, {
|
|
16
|
+
metaMessages: [
|
|
17
|
+
`- resolverAddress: ${resolverAddress || EMPTY_ADDRESS}`,
|
|
18
|
+
`- addr: ${address || EMPTY_ADDRESS}`,
|
|
19
|
+
],
|
|
20
|
+
})
|
|
21
|
+
}
|
|
22
|
+
}
|
package/src/errors/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = 'v4.0.
|
|
1
|
+
export const version = 'v4.0.3-alpha.11'
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import {
|
|
2
|
+
encodeFunctionData,
|
|
3
|
+
type Account,
|
|
4
|
+
type Hash,
|
|
5
|
+
type SendTransactionParameters,
|
|
6
|
+
type Transport,
|
|
7
|
+
} from 'viem'
|
|
8
|
+
import { sendTransaction } from 'viem/actions'
|
|
9
|
+
import type { ChainWithEns, ClientWithAccount } from '../../contracts/consts.js'
|
|
10
|
+
import { legacyEthRegistrarControllerCommitSnippet } from '../../contracts/legacyEthRegistrarController.js'
|
|
11
|
+
import { getChainContractAddress } from '../../contracts/getChainContractAddress.js'
|
|
12
|
+
import { UnsupportedNameTypeError } from '../../errors/general.js'
|
|
13
|
+
import type {
|
|
14
|
+
Prettify,
|
|
15
|
+
SimpleTransactionRequest,
|
|
16
|
+
WriteTransactionParameters,
|
|
17
|
+
} from '../../types.js'
|
|
18
|
+
import { getNameType } from '../../utils/getNameType.js'
|
|
19
|
+
import {
|
|
20
|
+
makeLegacyCommitment,
|
|
21
|
+
type LegacyRegistrationParameters,
|
|
22
|
+
} from '../../utils/legacyRegisterHelpers.js'
|
|
23
|
+
import { EMPTY_ADDRESS } from '../../utils/consts.js'
|
|
24
|
+
|
|
25
|
+
export type LegacyCommitNameDataParameters = LegacyRegistrationParameters
|
|
26
|
+
|
|
27
|
+
export type LegacyCommitNameDataReturnType = SimpleTransactionRequest
|
|
28
|
+
|
|
29
|
+
export type LegacyCommitNameParameters<
|
|
30
|
+
TChain extends ChainWithEns,
|
|
31
|
+
TAccount extends Account | undefined,
|
|
32
|
+
TChainOverride extends ChainWithEns | undefined,
|
|
33
|
+
> = Prettify<
|
|
34
|
+
LegacyCommitNameDataParameters &
|
|
35
|
+
WriteTransactionParameters<TChain, TAccount, TChainOverride>
|
|
36
|
+
>
|
|
37
|
+
|
|
38
|
+
export type LegacyCommitNameReturnType = Hash
|
|
39
|
+
|
|
40
|
+
export const makeFunctionData = <
|
|
41
|
+
TChain extends ChainWithEns,
|
|
42
|
+
TAccount extends Account | undefined,
|
|
43
|
+
>(
|
|
44
|
+
wallet: ClientWithAccount<Transport, TChain, TAccount>,
|
|
45
|
+
args: LegacyCommitNameDataParameters,
|
|
46
|
+
): LegacyCommitNameDataReturnType => {
|
|
47
|
+
const nameType = getNameType(args.name)
|
|
48
|
+
if (nameType !== 'eth-2ld')
|
|
49
|
+
throw new UnsupportedNameTypeError({
|
|
50
|
+
nameType,
|
|
51
|
+
supportedNameTypes: ['eth-2ld'],
|
|
52
|
+
details: 'Only 2ld-eth name registration is supported',
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
return {
|
|
56
|
+
to: getChainContractAddress({
|
|
57
|
+
client: wallet,
|
|
58
|
+
contract: 'legacyEthRegistrarController',
|
|
59
|
+
}),
|
|
60
|
+
data: encodeFunctionData({
|
|
61
|
+
abi: legacyEthRegistrarControllerCommitSnippet,
|
|
62
|
+
functionName: 'commit',
|
|
63
|
+
args: [makeLegacyCommitment(args)],
|
|
64
|
+
}),
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Commits a name to be registered
|
|
70
|
+
* @param wallet - {@link ClientWithAccount}
|
|
71
|
+
* @param parameters - {@link LegacyCommitNameParameters}
|
|
72
|
+
* @returns Transaction hash. {@link LegacyCommitNameReturnType}
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* import { createWalletClient, custom } from 'viem'
|
|
76
|
+
* import { mainnet } from 'viem/chains'
|
|
77
|
+
* import { addEnsContracts } from '@ensdomains/ensjs'
|
|
78
|
+
* import { commitName } from '@ensdomains/ensjs/wallet'
|
|
79
|
+
* import { randomSecret } from '@ensdomains/ensjs/utils'
|
|
80
|
+
*
|
|
81
|
+
* const wallet = createWalletClient({
|
|
82
|
+
* chain: addEnsContracts(mainnet),
|
|
83
|
+
* transport: custom(window.ethereum),
|
|
84
|
+
* })
|
|
85
|
+
* const secret = randomSecret()
|
|
86
|
+
* const hash = await commitName(wallet, {
|
|
87
|
+
* name: 'example.eth',
|
|
88
|
+
* owner: '0xFe89cc7aBB2C4183683ab71653C4cdc9B02D44b7',
|
|
89
|
+
* duration: 31536000, // 1 year
|
|
90
|
+
* secret,
|
|
91
|
+
* })
|
|
92
|
+
* // 0x...
|
|
93
|
+
*/
|
|
94
|
+
async function legacyCommitName<
|
|
95
|
+
TChain extends ChainWithEns,
|
|
96
|
+
TAccount extends Account | undefined,
|
|
97
|
+
TChainOverride extends ChainWithEns | undefined = ChainWithEns,
|
|
98
|
+
>(
|
|
99
|
+
wallet: ClientWithAccount<Transport, TChain, TAccount>,
|
|
100
|
+
{
|
|
101
|
+
name,
|
|
102
|
+
owner,
|
|
103
|
+
duration,
|
|
104
|
+
secret,
|
|
105
|
+
resolverAddress = EMPTY_ADDRESS,
|
|
106
|
+
address = EMPTY_ADDRESS,
|
|
107
|
+
...txArgs
|
|
108
|
+
}: LegacyCommitNameParameters<TChain, TAccount, TChainOverride>,
|
|
109
|
+
): Promise<LegacyCommitNameReturnType> {
|
|
110
|
+
const data = makeFunctionData(wallet, {
|
|
111
|
+
name,
|
|
112
|
+
owner,
|
|
113
|
+
duration,
|
|
114
|
+
secret,
|
|
115
|
+
resolverAddress,
|
|
116
|
+
address,
|
|
117
|
+
})
|
|
118
|
+
const writeArgs = {
|
|
119
|
+
...data,
|
|
120
|
+
...txArgs,
|
|
121
|
+
} as SendTransactionParameters<TChain, TAccount, TChainOverride>
|
|
122
|
+
return sendTransaction(wallet, writeArgs)
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
legacyCommitName.makeFunctionData = makeFunctionData
|
|
126
|
+
|
|
127
|
+
export default legacyCommitName
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import {
|
|
2
|
+
encodeFunctionData,
|
|
3
|
+
type Account,
|
|
4
|
+
type Hash,
|
|
5
|
+
type SendTransactionParameters,
|
|
6
|
+
type Transport,
|
|
7
|
+
} from 'viem'
|
|
8
|
+
import { sendTransaction } from 'viem/actions'
|
|
9
|
+
import type { ChainWithEns, ClientWithAccount } from '../../contracts/consts.js'
|
|
10
|
+
import { getChainContractAddress } from '../../contracts/getChainContractAddress.js'
|
|
11
|
+
import { UnsupportedNameTypeError } from '../../errors/general.js'
|
|
12
|
+
import type {
|
|
13
|
+
Prettify,
|
|
14
|
+
SimpleTransactionRequest,
|
|
15
|
+
WriteTransactionParameters,
|
|
16
|
+
} from '../../types.js'
|
|
17
|
+
import { getNameType } from '../../utils/getNameType.js'
|
|
18
|
+
import {
|
|
19
|
+
makeLegacyRegistrationTuple,
|
|
20
|
+
type LegacyRegistrationParameters,
|
|
21
|
+
isLegacyRegistrationWithConfigParameters,
|
|
22
|
+
makeLegacyRegistrationWithConfigTuple,
|
|
23
|
+
} from '../../utils/legacyRegisterHelpers.js'
|
|
24
|
+
import {
|
|
25
|
+
legacyEthRegistrarControllerRegisterSnippet,
|
|
26
|
+
legacyEthRegistrarControllerRegisterWithConfigSnippet,
|
|
27
|
+
} from '../../contracts/legacyEthRegistrarController.js'
|
|
28
|
+
|
|
29
|
+
export type LegacyRegisterNameDataParameters = LegacyRegistrationParameters & {
|
|
30
|
+
/** Value of registration */
|
|
31
|
+
value: bigint
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export type LegacyRegisterNameDataReturnType = SimpleTransactionRequest & {
|
|
35
|
+
value: bigint
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export type LegacyRegisterNameParameters<
|
|
39
|
+
TChain extends ChainWithEns,
|
|
40
|
+
TAccount extends Account | undefined,
|
|
41
|
+
TChainOverride extends ChainWithEns | undefined,
|
|
42
|
+
> = Prettify<
|
|
43
|
+
LegacyRegisterNameDataParameters &
|
|
44
|
+
WriteTransactionParameters<TChain, TAccount, TChainOverride>
|
|
45
|
+
>
|
|
46
|
+
|
|
47
|
+
export type LegacyRegisterNameReturnType = Hash
|
|
48
|
+
|
|
49
|
+
export const makeFunctionData = <
|
|
50
|
+
TChain extends ChainWithEns,
|
|
51
|
+
TAccount extends Account | undefined,
|
|
52
|
+
>(
|
|
53
|
+
wallet: ClientWithAccount<Transport, TChain, TAccount>,
|
|
54
|
+
{ value, ...args }: LegacyRegisterNameDataParameters,
|
|
55
|
+
): LegacyRegisterNameDataReturnType => {
|
|
56
|
+
const nameType = getNameType(args.name)
|
|
57
|
+
if (nameType !== 'eth-2ld')
|
|
58
|
+
throw new UnsupportedNameTypeError({
|
|
59
|
+
nameType,
|
|
60
|
+
supportedNameTypes: ['eth-2ld'],
|
|
61
|
+
details: 'Only 2ld-eth name registration is supported',
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
const data = isLegacyRegistrationWithConfigParameters(args)
|
|
65
|
+
? encodeFunctionData({
|
|
66
|
+
abi: legacyEthRegistrarControllerRegisterWithConfigSnippet,
|
|
67
|
+
functionName: 'registerWithConfig',
|
|
68
|
+
args: makeLegacyRegistrationWithConfigTuple(args),
|
|
69
|
+
})
|
|
70
|
+
: encodeFunctionData({
|
|
71
|
+
abi: legacyEthRegistrarControllerRegisterSnippet,
|
|
72
|
+
functionName: 'register',
|
|
73
|
+
args: makeLegacyRegistrationTuple(args),
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
return {
|
|
77
|
+
to: getChainContractAddress({
|
|
78
|
+
client: wallet,
|
|
79
|
+
contract: 'legacyEthRegistrarController',
|
|
80
|
+
}),
|
|
81
|
+
data,
|
|
82
|
+
value,
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Registers a name on ENS
|
|
88
|
+
* @param wallet - {@link ClientWithAccount}
|
|
89
|
+
* @param parameters - {@link RegisterNameParameters}
|
|
90
|
+
* @returns Transaction hash. {@link LegacyRegisterNameReturnType}
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* import { createPublicClient, createWalletClient, http, custom } from 'viem'
|
|
94
|
+
* import { mainnet } from 'viem/chains'
|
|
95
|
+
* import { addEnsContracts } from '@ensdomains/ensjs'
|
|
96
|
+
* import { getPrice } from '@ensdomains/ensjs/public'
|
|
97
|
+
* import { randomSecret } from '@ensdomains/ensjs/utils'
|
|
98
|
+
* import { commitName, registerName } from '@ensdomains/ensjs/wallet'
|
|
99
|
+
*
|
|
100
|
+
* const mainnetWithEns = addEnsContracts(mainnet)
|
|
101
|
+
* const client = createPublicClient({
|
|
102
|
+
* chain: mainnetWithEns,
|
|
103
|
+
* transport: http(),
|
|
104
|
+
* })
|
|
105
|
+
* const wallet = createWalletClient({
|
|
106
|
+
* chain: mainnetWithEns,
|
|
107
|
+
* transport: custom(window.ethereum),
|
|
108
|
+
* })
|
|
109
|
+
* const secret = randomSecret()
|
|
110
|
+
* const params = {
|
|
111
|
+
* name: 'example.eth',
|
|
112
|
+
* owner: '0xFe89cc7aBB2C4183683ab71653C4cdc9B02D44b7',
|
|
113
|
+
* duration: 31536000, // 1 year
|
|
114
|
+
* secret,
|
|
115
|
+
* }
|
|
116
|
+
*
|
|
117
|
+
* const commitmentHash = await commitName(wallet, params)
|
|
118
|
+
* await client.waitForTransactionReceipt({ hash: commitmentHash }) // wait for commitment to finalise
|
|
119
|
+
* await new Promise((resolve) => setTimeout(resolve, 60 * 1_000)) // wait for commitment to be valid
|
|
120
|
+
*
|
|
121
|
+
* const { base, premium } = await getPrice(client, { nameOrNames: params.name, duration: params.duration })
|
|
122
|
+
* const value = (base + premium) * 110n / 100n // add 10% to the price for buffer
|
|
123
|
+
* const hash = await registerName(wallet, { ...params, value })
|
|
124
|
+
* // 0x...
|
|
125
|
+
*/
|
|
126
|
+
async function legacyRegisterName<
|
|
127
|
+
TChain extends ChainWithEns,
|
|
128
|
+
TAccount extends Account | undefined,
|
|
129
|
+
TChainOverride extends ChainWithEns | undefined = ChainWithEns,
|
|
130
|
+
>(
|
|
131
|
+
wallet: ClientWithAccount<Transport, TChain, TAccount>,
|
|
132
|
+
{
|
|
133
|
+
name,
|
|
134
|
+
owner,
|
|
135
|
+
duration,
|
|
136
|
+
secret,
|
|
137
|
+
resolverAddress,
|
|
138
|
+
address,
|
|
139
|
+
value,
|
|
140
|
+
...txArgs
|
|
141
|
+
}: LegacyRegisterNameParameters<TChain, TAccount, TChainOverride>,
|
|
142
|
+
): Promise<LegacyRegisterNameReturnType> {
|
|
143
|
+
const data = makeFunctionData(wallet, {
|
|
144
|
+
name,
|
|
145
|
+
owner,
|
|
146
|
+
duration,
|
|
147
|
+
secret,
|
|
148
|
+
resolverAddress,
|
|
149
|
+
address,
|
|
150
|
+
value,
|
|
151
|
+
})
|
|
152
|
+
const writeArgs = {
|
|
153
|
+
...data,
|
|
154
|
+
...txArgs,
|
|
155
|
+
} as SendTransactionParameters<TChain, TAccount, TChainOverride>
|
|
156
|
+
return sendTransaction(wallet, writeArgs)
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
legacyRegisterName.makeFunctionData = makeFunctionData
|
|
160
|
+
|
|
161
|
+
export default legacyRegisterName
|
package/src/utils/index.ts
CHANGED
|
@@ -104,6 +104,21 @@ export {
|
|
|
104
104
|
saveLabel,
|
|
105
105
|
saveName,
|
|
106
106
|
} from './labels.js'
|
|
107
|
+
export {
|
|
108
|
+
makeLegacyCommitment,
|
|
109
|
+
makeLegacyCommitmentFromTuple,
|
|
110
|
+
makeLegacyCommitmentTuple,
|
|
111
|
+
makeLegacyCommitmentWithConfigTuple,
|
|
112
|
+
makeLegacyRegistrationTuple,
|
|
113
|
+
makeLegacyRegistrationWithConfigTuple,
|
|
114
|
+
isLegacyRegistrationWithConfigParameters,
|
|
115
|
+
type LegacyCommitmentTuple,
|
|
116
|
+
type LegacyCommitmentWithConfigTuple,
|
|
117
|
+
type LegacyRegistrationParameters,
|
|
118
|
+
type LegacyRegistrationWithConfigParameters,
|
|
119
|
+
type LegacyRegistrationTuple,
|
|
120
|
+
type LegacyRegistrationWithConfigTuple,
|
|
121
|
+
} from './legacyRegisterHelpers.js'
|
|
107
122
|
export { makeSafeSecondsDate } from './makeSafeSecondsDate.js'
|
|
108
123
|
export {
|
|
109
124
|
beautify,
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import {
|
|
2
|
+
keccak256,
|
|
3
|
+
labelhash,
|
|
4
|
+
type Address,
|
|
5
|
+
type Hex,
|
|
6
|
+
encodePacked,
|
|
7
|
+
} from 'viem'
|
|
8
|
+
import { EMPTY_ADDRESS } from './consts.js'
|
|
9
|
+
import { LegacyRegistrationInvalidConfigError } from '../errors/register.js'
|
|
10
|
+
|
|
11
|
+
export type LegacyRegistrationParameters = {
|
|
12
|
+
/** Name to register */
|
|
13
|
+
name: string
|
|
14
|
+
/** Address to set owner to */
|
|
15
|
+
owner: Address
|
|
16
|
+
/** Duration of registration */
|
|
17
|
+
duration: number
|
|
18
|
+
/** Random 32 bytes to use for registration */
|
|
19
|
+
secret: Hex
|
|
20
|
+
/** Custom resolver address, defaults to empty address */
|
|
21
|
+
resolverAddress?: Address
|
|
22
|
+
/** Address to set upon registration, defaults to empty address */
|
|
23
|
+
address?: Address
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export type LegacyRegistrationWithConfigParameters =
|
|
27
|
+
LegacyRegistrationParameters & {
|
|
28
|
+
resolverAddress: Address
|
|
29
|
+
address?: Address
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export const isLegacyRegistrationWithConfigParameters = (
|
|
33
|
+
params: LegacyRegistrationParameters,
|
|
34
|
+
): params is LegacyRegistrationWithConfigParameters => {
|
|
35
|
+
const { resolverAddress = EMPTY_ADDRESS, address = EMPTY_ADDRESS } =
|
|
36
|
+
params as LegacyRegistrationWithConfigParameters
|
|
37
|
+
|
|
38
|
+
if (resolverAddress === EMPTY_ADDRESS && address !== EMPTY_ADDRESS)
|
|
39
|
+
throw new LegacyRegistrationInvalidConfigError({
|
|
40
|
+
resolverAddress,
|
|
41
|
+
address,
|
|
42
|
+
})
|
|
43
|
+
return resolverAddress !== EMPTY_ADDRESS || address !== EMPTY_ADDRESS
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export type LegacyCommitmentTuple = [label: string, owner: Address, secret: Hex]
|
|
47
|
+
|
|
48
|
+
export type LegacyCommitmentWithConfigTuple = [
|
|
49
|
+
label: string,
|
|
50
|
+
owner: Address,
|
|
51
|
+
resolverAddress: Address,
|
|
52
|
+
address: Address,
|
|
53
|
+
secret: Hex,
|
|
54
|
+
]
|
|
55
|
+
|
|
56
|
+
export type LegacyRegistrationTuple = [
|
|
57
|
+
label: string,
|
|
58
|
+
owner: Address,
|
|
59
|
+
duration: bigint,
|
|
60
|
+
secret: Hex,
|
|
61
|
+
]
|
|
62
|
+
|
|
63
|
+
export type LegacyRegistrationWithConfigTuple = [
|
|
64
|
+
label: string,
|
|
65
|
+
owner: Address,
|
|
66
|
+
duration: bigint,
|
|
67
|
+
secret: Hex,
|
|
68
|
+
resolverAddress: Address,
|
|
69
|
+
address: Address,
|
|
70
|
+
]
|
|
71
|
+
|
|
72
|
+
export const makeLegacyCommitmentTuple = (
|
|
73
|
+
params: LegacyRegistrationParameters,
|
|
74
|
+
): LegacyCommitmentTuple => {
|
|
75
|
+
const { name, owner, secret } = params
|
|
76
|
+
const label = name.split('.')[0]
|
|
77
|
+
return [label, owner, secret]
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export const makeLegacyCommitmentWithConfigTuple = (
|
|
81
|
+
params: LegacyRegistrationWithConfigParameters,
|
|
82
|
+
): LegacyCommitmentWithConfigTuple => {
|
|
83
|
+
const {
|
|
84
|
+
name,
|
|
85
|
+
owner,
|
|
86
|
+
secret,
|
|
87
|
+
resolverAddress = EMPTY_ADDRESS,
|
|
88
|
+
address = EMPTY_ADDRESS,
|
|
89
|
+
} = params as LegacyRegistrationWithConfigParameters
|
|
90
|
+
const label = name.split('.')[0]
|
|
91
|
+
return [label, owner, secret, resolverAddress, address]
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export const makeLegacyRegistrationTuple = ({
|
|
95
|
+
name,
|
|
96
|
+
owner,
|
|
97
|
+
secret,
|
|
98
|
+
duration,
|
|
99
|
+
}: LegacyRegistrationParameters): LegacyRegistrationTuple => {
|
|
100
|
+
const label = name.split('.')[0]
|
|
101
|
+
return [label, owner, BigInt(duration), secret]
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export const makeLegacyRegistrationWithConfigTuple = ({
|
|
105
|
+
name,
|
|
106
|
+
owner,
|
|
107
|
+
secret,
|
|
108
|
+
duration,
|
|
109
|
+
resolverAddress,
|
|
110
|
+
address = EMPTY_ADDRESS,
|
|
111
|
+
}: LegacyRegistrationWithConfigParameters): LegacyRegistrationWithConfigTuple => {
|
|
112
|
+
const label = name.split('.')[0]
|
|
113
|
+
return [label, owner, BigInt(duration), secret, resolverAddress, address]
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export const makeLegacyCommitmentFromTuple = ([label, ...others]:
|
|
117
|
+
| LegacyCommitmentTuple
|
|
118
|
+
| LegacyCommitmentWithConfigTuple): Hex => {
|
|
119
|
+
const labelHash = labelhash(label)
|
|
120
|
+
const params = [labelHash, ...others] as const
|
|
121
|
+
|
|
122
|
+
if (params.length === 3)
|
|
123
|
+
return keccak256(encodePacked(['bytes32', 'address', 'bytes32'], params))
|
|
124
|
+
|
|
125
|
+
const [
|
|
126
|
+
owner,
|
|
127
|
+
secret,
|
|
128
|
+
resolverAddress = EMPTY_ADDRESS,
|
|
129
|
+
address = EMPTY_ADDRESS,
|
|
130
|
+
] = others
|
|
131
|
+
|
|
132
|
+
return keccak256(
|
|
133
|
+
encodePacked(
|
|
134
|
+
['bytes32', 'address', 'address', 'address', 'bytes32'],
|
|
135
|
+
[labelHash, owner, resolverAddress, address, secret],
|
|
136
|
+
),
|
|
137
|
+
)
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export const makeLegacyCommitment = (
|
|
141
|
+
params: LegacyRegistrationParameters | LegacyRegistrationWithConfigParameters,
|
|
142
|
+
): Hex => {
|
|
143
|
+
const touple = isLegacyRegistrationWithConfigParameters(params)
|
|
144
|
+
? makeLegacyCommitmentWithConfigTuple(params)
|
|
145
|
+
: makeLegacyCommitmentTuple(params)
|
|
146
|
+
return makeLegacyCommitmentFromTuple(touple)
|
|
147
|
+
}
|