@ensdomains/ensjs 4.1.2 → 4.2.2
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 +1 -1
- package/dist/clients/decorators/subgraph.d.ts +1 -1
- package/dist/clients/decorators/wallet.d.ts +3 -3
- package/dist/contracts/addEnsContracts.d.ts +6 -1
- package/dist/contracts/addEnsContracts.js +20 -1
- package/dist/contracts/addEnsContracts.js.map +1 -1
- package/dist/contracts/bulkRenewal.d.ts +6 -0
- package/dist/contracts/bulkRenewal.js +7 -0
- package/dist/contracts/bulkRenewal.js.map +1 -1
- package/dist/contracts/consts.d.ts +35 -59
- package/dist/contracts/consts.js +35 -60
- package/dist/contracts/consts.js.map +1 -1
- package/dist/contracts/ethRegistrarController.d.ts +394 -27
- package/dist/contracts/ethRegistrarController.js +180 -34
- package/dist/contracts/ethRegistrarController.js.map +1 -1
- package/dist/errors/utils.js +1 -0
- package/dist/errors/utils.js.map +1 -1
- package/dist/errors/version.d.ts +1 -1
- package/dist/errors/version.js +1 -1
- package/dist/errors/version.js.map +1 -1
- package/dist/functions/public/batch.js.map +1 -1
- package/dist/functions/public/getName.js.map +1 -1
- package/dist/functions/public/getRecords.js +2 -2
- package/dist/functions/public/getRecords.js.map +1 -1
- package/dist/functions/subgraph/client.js +1 -0
- package/dist/functions/subgraph/client.js.map +1 -1
- package/dist/functions/subgraph/getDecodedName.d.ts +5 -1
- package/dist/functions/subgraph/getDecodedName.js +5 -1
- package/dist/functions/subgraph/getDecodedName.js.map +1 -1
- package/dist/functions/subgraph/getNameHistory.d.ts +3 -0
- package/dist/functions/subgraph/getNameHistory.js +3 -0
- package/dist/functions/subgraph/getNameHistory.js.map +1 -1
- package/dist/functions/subgraph/getNamesForAddress.d.ts +3 -0
- package/dist/functions/subgraph/getNamesForAddress.js +4 -0
- package/dist/functions/subgraph/getNamesForAddress.js.map +1 -1
- package/dist/functions/subgraph/getSubgraphRecords.d.ts +4 -1
- package/dist/functions/subgraph/getSubgraphRecords.js +4 -1
- package/dist/functions/subgraph/getSubgraphRecords.js.map +1 -1
- package/dist/functions/subgraph/getSubgraphRegistrant.d.ts +3 -0
- package/dist/functions/subgraph/getSubgraphRegistrant.js +3 -0
- package/dist/functions/subgraph/getSubgraphRegistrant.js.map +1 -1
- package/dist/functions/subgraph/getSubnames.d.ts +3 -0
- package/dist/functions/subgraph/getSubnames.js +3 -0
- package/dist/functions/subgraph/getSubnames.js.map +1 -1
- package/dist/functions/wallet/commitName.d.ts +1 -1
- package/dist/functions/wallet/commitName.js +2 -2
- package/dist/functions/wallet/commitName.js.map +1 -1
- package/dist/functions/wallet/registerName.d.ts +1 -1
- package/dist/functions/wallet/registerName.js +4 -7
- package/dist/functions/wallet/registerName.js.map +1 -1
- package/dist/functions/wallet/renewNames.d.ts +5 -3
- package/dist/functions/wallet/renewNames.js +4 -3
- package/dist/functions/wallet/renewNames.js.map +1 -1
- package/dist/functions/wallet/setContentHashRecord.d.ts +1 -1
- package/dist/functions/wallet/setContentHashRecord.js +1 -1
- package/dist/subgraph.d.ts +11 -0
- package/dist/subgraph.js +11 -0
- package/dist/subgraph.js.map +1 -1
- package/dist/utils/checkSafeUniversalResolverData.js.map +1 -1
- package/dist/utils/consts.d.ts +1 -0
- package/dist/utils/consts.js +1 -0
- package/dist/utils/consts.js.map +1 -1
- package/dist/utils/encoders/encodeAbi.js.map +1 -1
- package/dist/utils/generateFunction.js.map +1 -1
- package/dist/utils/index.d.ts +2 -3
- package/dist/utils/index.js +2 -3
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/labels.js +4 -2
- package/dist/utils/labels.js.map +1 -1
- package/dist/utils/registerHelpers.d.ts +20 -27
- package/dist/utils/registerHelpers.js +19 -33
- package/dist/utils/registerHelpers.js.map +1 -1
- package/dist/wallet.d.ts +0 -2
- package/dist/wallet.js +0 -2
- package/dist/wallet.js.map +1 -1
- package/package.json +6 -7
- package/src/@types/dns-packet/index.d.ts +1 -0
- package/src/@types/pako.d.ts +4 -1
- package/src/clients/decorators/subgraph.ts +1 -1
- package/src/clients/decorators/wallet.ts +3 -3
- package/src/contracts/addEnsContracts.ts +32 -1
- package/src/contracts/bulkRenewal.ts +7 -0
- package/src/contracts/consts.ts +39 -60
- package/src/contracts/ethRegistrarController.ts +181 -34
- package/src/errors/utils.ts +1 -0
- package/src/errors/version.ts +1 -1
- package/src/functions/public/batch.ts +1 -0
- package/src/functions/public/getName.ts +1 -0
- package/src/functions/public/getRecords.ts +8 -2
- package/src/functions/subgraph/client.ts +1 -0
- package/src/functions/subgraph/getDecodedName.ts +5 -1
- package/src/functions/subgraph/getNameHistory.ts +3 -0
- package/src/functions/subgraph/getNamesForAddress.ts +4 -0
- package/src/functions/subgraph/getSubgraphRecords.ts +4 -1
- package/src/functions/subgraph/getSubgraphRegistrant.ts +3 -0
- package/src/functions/subgraph/getSubnames.ts +3 -0
- package/src/functions/wallet/commitName.ts +2 -2
- package/src/functions/wallet/registerName.ts +4 -8
- package/src/functions/wallet/renewNames.ts +12 -3
- package/src/functions/wallet/setContentHashRecord.ts +1 -1
- package/src/subgraph.ts +11 -0
- package/src/types.ts +2 -0
- package/src/utils/checkSafeUniversalResolverData.ts +1 -0
- package/src/utils/consts.ts +2 -0
- package/src/utils/encoders/encodeAbi.ts +1 -0
- package/src/utils/generateFunction.ts +6 -0
- package/src/utils/index.ts +5 -20
- package/src/utils/labels.ts +8 -4
- package/src/utils/registerHelpers.ts +40 -64
- package/src/wallet.ts +0 -14
- package/dist/functions/wallet/legacyCommitName.d.ts +0 -40
- package/dist/functions/wallet/legacyCommitName.js +0 -72
- package/dist/functions/wallet/legacyCommitName.js.map +0 -1
- package/dist/functions/wallet/legacyRegisterName.d.ts +0 -59
- package/dist/functions/wallet/legacyRegisterName.js +0 -93
- package/dist/functions/wallet/legacyRegisterName.js.map +0 -1
- package/dist/utils/legacyRegisterHelpers.d.ts +0 -48
- package/dist/utils/legacyRegisterHelpers.js +0 -45
- package/dist/utils/legacyRegisterHelpers.js.map +0 -1
- package/src/functions/wallet/legacyCommitName.ts +0 -127
- package/src/functions/wallet/legacyRegisterName.ts +0 -159
- package/src/utils/legacyRegisterHelpers.ts +0 -147
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { encodePacked, keccak256, labelhash, } from 'viem';
|
|
2
|
-
import { LegacyRegistrationInvalidConfigError } from '../errors/register.js';
|
|
3
|
-
import { EMPTY_ADDRESS } from './consts.js';
|
|
4
|
-
export const isLegacyRegistrationWithConfigParameters = (params) => {
|
|
5
|
-
const { resolverAddress = EMPTY_ADDRESS, address = EMPTY_ADDRESS } = params;
|
|
6
|
-
if (resolverAddress === EMPTY_ADDRESS && address !== EMPTY_ADDRESS)
|
|
7
|
-
throw new LegacyRegistrationInvalidConfigError({
|
|
8
|
-
resolverAddress,
|
|
9
|
-
address,
|
|
10
|
-
});
|
|
11
|
-
return resolverAddress !== EMPTY_ADDRESS || address !== EMPTY_ADDRESS;
|
|
12
|
-
};
|
|
13
|
-
export const makeLegacyCommitmentTuple = (params) => {
|
|
14
|
-
const { name, owner, secret } = params;
|
|
15
|
-
const label = name.split('.')[0];
|
|
16
|
-
return [label, owner, secret];
|
|
17
|
-
};
|
|
18
|
-
export const makeLegacyCommitmentWithConfigTuple = (params) => {
|
|
19
|
-
const { name, owner, secret, resolverAddress = EMPTY_ADDRESS, address = EMPTY_ADDRESS, } = params;
|
|
20
|
-
const label = name.split('.')[0];
|
|
21
|
-
return [label, owner, secret, resolverAddress, address];
|
|
22
|
-
};
|
|
23
|
-
export const makeLegacyRegistrationTuple = ({ name, owner, secret, duration, }) => {
|
|
24
|
-
const label = name.split('.')[0];
|
|
25
|
-
return [label, owner, BigInt(duration), secret];
|
|
26
|
-
};
|
|
27
|
-
export const makeLegacyRegistrationWithConfigTuple = ({ name, owner, secret, duration, resolverAddress, address = EMPTY_ADDRESS, }) => {
|
|
28
|
-
const label = name.split('.')[0];
|
|
29
|
-
return [label, owner, BigInt(duration), secret, resolverAddress, address];
|
|
30
|
-
};
|
|
31
|
-
export const makeLegacyCommitmentFromTuple = ([label, ...others]) => {
|
|
32
|
-
const labelHash = labelhash(label);
|
|
33
|
-
const params = [labelHash, ...others];
|
|
34
|
-
if (params.length === 3)
|
|
35
|
-
return keccak256(encodePacked(['bytes32', 'address', 'bytes32'], params));
|
|
36
|
-
const [owner, secret, resolverAddress = EMPTY_ADDRESS, address = EMPTY_ADDRESS,] = others;
|
|
37
|
-
return keccak256(encodePacked(['bytes32', 'address', 'address', 'address', 'bytes32'], [labelHash, owner, resolverAddress, address, secret]));
|
|
38
|
-
};
|
|
39
|
-
export const makeLegacyCommitment = (params) => {
|
|
40
|
-
const touple = isLegacyRegistrationWithConfigParameters(params)
|
|
41
|
-
? makeLegacyCommitmentWithConfigTuple(params)
|
|
42
|
-
: makeLegacyCommitmentTuple(params);
|
|
43
|
-
return makeLegacyCommitmentFromTuple(touple);
|
|
44
|
-
};
|
|
45
|
-
//# sourceMappingURL=legacyRegisterHelpers.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"legacyRegisterHelpers.js","sourceRoot":"","sources":["../../src/utils/legacyRegisterHelpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,YAAY,EACZ,SAAS,EACT,SAAS,GACV,MAAM,MAAM,CAAA;AACb,OAAO,EAAE,oCAAoC,EAAE,MAAM,uBAAuB,CAAA;AAC5E,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAuB3C,MAAM,CAAC,MAAM,wCAAwC,GAAG,CACtD,MAAoC,EACc,EAAE;IACpD,MAAM,EAAE,eAAe,GAAG,aAAa,EAAE,OAAO,GAAG,aAAa,EAAE,GAChE,MAAgD,CAAA;IAElD,IAAI,eAAe,KAAK,aAAa,IAAI,OAAO,KAAK,aAAa;QAChE,MAAM,IAAI,oCAAoC,CAAC;YAC7C,eAAe;YACf,OAAO;SACR,CAAC,CAAA;IACJ,OAAO,eAAe,KAAK,aAAa,IAAI,OAAO,K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encodeFunctionData,
|
|
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 { legacyEthRegistrarControllerCommitSnippet } from '../../contracts/legacyEthRegistrarController.js'
|
|
12
|
-
import { UnsupportedNameTypeError } from '../../errors/general.js'
|
|
13
|
-
import type {
|
|
14
|
-
Prettify,
|
|
15
|
-
SimpleTransactionRequest,
|
|
16
|
-
WriteTransactionParameters,
|
|
17
|
-
} from '../../types.js'
|
|
18
|
-
import { EMPTY_ADDRESS } from '../../utils/consts.js'
|
|
19
|
-
import { getNameType } from '../../utils/getNameType.js'
|
|
20
|
-
import {
|
|
21
|
-
type LegacyRegistrationParameters,
|
|
22
|
-
makeLegacyCommitment,
|
|
23
|
-
} from '../../utils/legacyRegisterHelpers.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
|
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type Account,
|
|
3
|
-
type Hash,
|
|
4
|
-
type SendTransactionParameters,
|
|
5
|
-
type Transport,
|
|
6
|
-
encodeFunctionData,
|
|
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 {
|
|
12
|
-
legacyEthRegistrarControllerRegisterSnippet,
|
|
13
|
-
legacyEthRegistrarControllerRegisterWithConfigSnippet,
|
|
14
|
-
} from '../../contracts/legacyEthRegistrarController.js'
|
|
15
|
-
import { UnsupportedNameTypeError } from '../../errors/general.js'
|
|
16
|
-
import type {
|
|
17
|
-
Prettify,
|
|
18
|
-
SimpleTransactionRequest,
|
|
19
|
-
WriteTransactionParameters,
|
|
20
|
-
} from '../../types.js'
|
|
21
|
-
import { getNameType } from '../../utils/getNameType.js'
|
|
22
|
-
import {
|
|
23
|
-
type LegacyRegistrationParameters,
|
|
24
|
-
isLegacyRegistrationWithConfigParameters,
|
|
25
|
-
makeLegacyRegistrationTuple,
|
|
26
|
-
makeLegacyRegistrationWithConfigTuple,
|
|
27
|
-
} from '../../utils/legacyRegisterHelpers.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
|
-
return {
|
|
65
|
-
to: getChainContractAddress({
|
|
66
|
-
client: wallet,
|
|
67
|
-
contract: 'legacyEthRegistrarController',
|
|
68
|
-
}),
|
|
69
|
-
data: isLegacyRegistrationWithConfigParameters(args)
|
|
70
|
-
? encodeFunctionData({
|
|
71
|
-
abi: legacyEthRegistrarControllerRegisterWithConfigSnippet,
|
|
72
|
-
functionName: 'registerWithConfig',
|
|
73
|
-
args: makeLegacyRegistrationWithConfigTuple(args),
|
|
74
|
-
})
|
|
75
|
-
: encodeFunctionData({
|
|
76
|
-
abi: legacyEthRegistrarControllerRegisterSnippet,
|
|
77
|
-
functionName: 'register',
|
|
78
|
-
args: makeLegacyRegistrationTuple(args),
|
|
79
|
-
}),
|
|
80
|
-
value,
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Registers a name on ENS
|
|
86
|
-
* @param wallet - {@link ClientWithAccount}
|
|
87
|
-
* @param parameters - {@link RegisterNameParameters}
|
|
88
|
-
* @returns Transaction hash. {@link LegacyRegisterNameReturnType}
|
|
89
|
-
*
|
|
90
|
-
* @example
|
|
91
|
-
* import { createPublicClient, createWalletClient, http, custom } from 'viem'
|
|
92
|
-
* import { mainnet } from 'viem/chains'
|
|
93
|
-
* import { addEnsContracts } from '@ensdomains/ensjs'
|
|
94
|
-
* import { getPrice } from '@ensdomains/ensjs/public'
|
|
95
|
-
* import { randomSecret } from '@ensdomains/ensjs/utils'
|
|
96
|
-
* import { commitName, registerName } from '@ensdomains/ensjs/wallet'
|
|
97
|
-
*
|
|
98
|
-
* const mainnetWithEns = addEnsContracts(mainnet)
|
|
99
|
-
* const client = createPublicClient({
|
|
100
|
-
* chain: mainnetWithEns,
|
|
101
|
-
* transport: http(),
|
|
102
|
-
* })
|
|
103
|
-
* const wallet = createWalletClient({
|
|
104
|
-
* chain: mainnetWithEns,
|
|
105
|
-
* transport: custom(window.ethereum),
|
|
106
|
-
* })
|
|
107
|
-
* const secret = randomSecret()
|
|
108
|
-
* const params = {
|
|
109
|
-
* name: 'example.eth',
|
|
110
|
-
* owner: '0xFe89cc7aBB2C4183683ab71653C4cdc9B02D44b7',
|
|
111
|
-
* duration: 31536000, // 1 year
|
|
112
|
-
* secret,
|
|
113
|
-
* }
|
|
114
|
-
*
|
|
115
|
-
* const commitmentHash = await commitName(wallet, params)
|
|
116
|
-
* await client.waitForTransactionReceipt({ hash: commitmentHash }) // wait for commitment to finalise
|
|
117
|
-
* await new Promise((resolve) => setTimeout(resolve, 60 * 1_000)) // wait for commitment to be valid
|
|
118
|
-
*
|
|
119
|
-
* const { base, premium } = await getPrice(client, { nameOrNames: params.name, duration: params.duration })
|
|
120
|
-
* const value = (base + premium) * 110n / 100n // add 10% to the price for buffer
|
|
121
|
-
* const hash = await registerName(wallet, { ...params, value })
|
|
122
|
-
* // 0x...
|
|
123
|
-
*/
|
|
124
|
-
async function legacyRegisterName<
|
|
125
|
-
TChain extends ChainWithEns,
|
|
126
|
-
TAccount extends Account | undefined,
|
|
127
|
-
TChainOverride extends ChainWithEns | undefined = ChainWithEns,
|
|
128
|
-
>(
|
|
129
|
-
wallet: ClientWithAccount<Transport, TChain, TAccount>,
|
|
130
|
-
{
|
|
131
|
-
name,
|
|
132
|
-
owner,
|
|
133
|
-
duration,
|
|
134
|
-
secret,
|
|
135
|
-
resolverAddress,
|
|
136
|
-
address,
|
|
137
|
-
value,
|
|
138
|
-
...txArgs
|
|
139
|
-
}: LegacyRegisterNameParameters<TChain, TAccount, TChainOverride>,
|
|
140
|
-
): Promise<LegacyRegisterNameReturnType> {
|
|
141
|
-
const data = makeFunctionData(wallet, {
|
|
142
|
-
name,
|
|
143
|
-
owner,
|
|
144
|
-
duration,
|
|
145
|
-
secret,
|
|
146
|
-
resolverAddress,
|
|
147
|
-
address,
|
|
148
|
-
value,
|
|
149
|
-
})
|
|
150
|
-
const writeArgs = {
|
|
151
|
-
...data,
|
|
152
|
-
...txArgs,
|
|
153
|
-
} as SendTransactionParameters<TChain, TAccount, TChainOverride>
|
|
154
|
-
return sendTransaction(wallet, writeArgs)
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
legacyRegisterName.makeFunctionData = makeFunctionData
|
|
158
|
-
|
|
159
|
-
export default legacyRegisterName
|
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type Address,
|
|
3
|
-
type Hex,
|
|
4
|
-
encodePacked,
|
|
5
|
-
keccak256,
|
|
6
|
-
labelhash,
|
|
7
|
-
} from 'viem'
|
|
8
|
-
import { LegacyRegistrationInvalidConfigError } from '../errors/register.js'
|
|
9
|
-
import { EMPTY_ADDRESS } from './consts.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
|
-
}
|