@ensdomains/ensjs 3.0.0-alpha.12 → 3.0.0-alpha.15
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/index.d.ts +8 -8
- package/dist/cjs/functions/burnFuses.d.ts +31 -4
- package/dist/cjs/functions/burnFuses.js +36 -6
- package/dist/cjs/functions/commitName.d.ts +26 -0
- package/dist/cjs/functions/commitName.js +24 -0
- package/dist/cjs/functions/getFuses.d.ts +2 -1
- package/dist/cjs/functions/getFuses.js +9 -18
- package/dist/cjs/functions/getProfile.js +1 -1
- package/dist/cjs/functions/getSpecificRecord.d.ts +4 -4
- package/dist/cjs/functions/registerName.d.ts +11 -0
- package/dist/cjs/functions/registerName.js +19 -0
- package/dist/cjs/functions/renewName.d.ts +6 -0
- package/dist/cjs/functions/renewName.js +10 -0
- package/dist/cjs/index.d.ts +22 -3
- package/dist/cjs/index.js +8 -1
- package/dist/cjs/utils/fuses.d.ts +18 -17
- package/dist/cjs/utils/fuses.js +10 -4
- package/dist/cjs/utils/registerHelpers.d.ts +44 -16
- package/dist/cjs/utils/registerHelpers.js +43 -15
- package/dist/cjs/utils/wrapperExpiry.d.ts +1 -1
- package/dist/cjs/utils/writeTx.d.ts +18 -1
- package/dist/cjs/utils/writeTx.js +4 -1
- package/dist/esm/contracts/index.d.ts +8 -8
- package/dist/esm/functions/burnFuses.d.ts +31 -4
- package/dist/esm/functions/burnFuses.js +36 -3
- package/dist/esm/functions/commitName.d.ts +26 -0
- package/dist/esm/functions/commitName.js +21 -0
- package/dist/esm/functions/getFuses.d.ts +2 -1
- package/dist/esm/functions/getFuses.js +10 -19
- package/dist/esm/functions/getProfile.js +1 -1
- package/dist/esm/functions/getSpecificRecord.d.ts +4 -4
- package/dist/esm/functions/registerName.d.ts +11 -0
- package/dist/esm/functions/registerName.js +16 -0
- package/dist/esm/functions/renewName.d.ts +6 -0
- package/dist/esm/functions/renewName.js +7 -0
- package/dist/esm/index.d.ts +22 -3
- package/dist/esm/index.js +8 -1
- package/dist/esm/utils/fuses.d.ts +18 -17
- package/dist/esm/utils/fuses.js +9 -3
- package/dist/esm/utils/registerHelpers.d.ts +44 -16
- package/dist/esm/utils/registerHelpers.js +40 -14
- package/dist/esm/utils/wrapperExpiry.d.ts +1 -1
- package/dist/esm/utils/writeTx.d.ts +18 -1
- package/dist/esm/utils/writeTx.js +4 -1
- package/package.json +19 -22
- package/src/functions/burnFuses.test.ts +123 -15
- package/src/functions/burnFuses.ts +101 -10
- package/src/functions/commitName.test.ts +61 -0
- package/src/functions/commitName.ts +36 -0
- package/src/functions/getFuses.test.ts +33 -15
- package/src/functions/getFuses.ts +13 -25
- package/src/functions/getProfile.ts +1 -1
- package/src/functions/registerName.test.ts +59 -0
- package/src/functions/registerName.ts +38 -0
- package/src/functions/renewName.test.ts +44 -0
- package/src/functions/renewName.ts +22 -0
- package/src/index.ts +27 -4
- package/src/utils/fuses.ts +12 -4
- package/src/utils/registerHelpers.ts +107 -49
- package/src/utils/writeTx.ts +12 -2
- package/src/tests/populateTransaction.test.ts +0 -40
- package/src/tests/setup.ts +0 -57
- package/src/tests/signerInjection.test.ts +0 -46
- package/src/tests/withProvider.test.ts +0 -28
|
@@ -1,26 +1,54 @@
|
|
|
1
1
|
import type { FuseOptions } from '../@types/FuseOptions';
|
|
2
2
|
import type { PublicResolver } from '../generated';
|
|
3
3
|
import { RecordOptions } from './recordHelpers';
|
|
4
|
-
export declare
|
|
5
|
-
export declare const makeCommitment: ({ name, owner, duration, resolver, records, reverseRecord, fuses, }: {
|
|
4
|
+
export declare type RegistrationParams = {
|
|
6
5
|
name: string;
|
|
7
6
|
owner: string;
|
|
8
7
|
duration: number;
|
|
8
|
+
secret: string;
|
|
9
9
|
resolver: PublicResolver;
|
|
10
|
-
records?: RecordOptions
|
|
11
|
-
reverseRecord?: boolean
|
|
12
|
-
fuses?: FuseOptions
|
|
13
|
-
|
|
10
|
+
records?: RecordOptions;
|
|
11
|
+
reverseRecord?: boolean;
|
|
12
|
+
fuses?: FuseOptions;
|
|
13
|
+
wrapperExpiry: number;
|
|
14
|
+
};
|
|
15
|
+
export declare type CommitmentParams = Omit<RegistrationParams, 'secret' | 'wrapperExpiry'> & {
|
|
16
|
+
secret?: string;
|
|
17
|
+
wrapperExpiry?: number;
|
|
18
|
+
};
|
|
19
|
+
export declare type RegistrationTuple = [
|
|
20
|
+
name: string,
|
|
21
|
+
owner: string,
|
|
22
|
+
duration: number,
|
|
23
|
+
secret: string,
|
|
24
|
+
resolver: string,
|
|
25
|
+
data: string[],
|
|
26
|
+
reverseRecord: boolean,
|
|
27
|
+
fuses: string,
|
|
28
|
+
wrapperExpiry: number
|
|
29
|
+
];
|
|
30
|
+
export declare type CommitmentTuple = [
|
|
31
|
+
labelhash: string,
|
|
32
|
+
owner: string,
|
|
33
|
+
duration: number,
|
|
34
|
+
resolver: string,
|
|
35
|
+
data: string[],
|
|
36
|
+
secret: string,
|
|
37
|
+
reverseRecord: boolean,
|
|
38
|
+
fuses: string,
|
|
39
|
+
wrapperExpiry: number
|
|
40
|
+
];
|
|
41
|
+
export declare const randomSecret: () => string;
|
|
42
|
+
export declare const makeCommitmentData: ({ name, owner, duration, resolver, records, reverseRecord, fuses, wrapperExpiry, secret, }: Omit<RegistrationParams, "secret" | "wrapperExpiry"> & {
|
|
43
|
+
secret?: string | undefined;
|
|
44
|
+
wrapperExpiry?: number | undefined;
|
|
45
|
+
} & {
|
|
46
|
+
secret: string;
|
|
47
|
+
}) => CommitmentTuple;
|
|
48
|
+
export declare const makeRegistrationData: (params: RegistrationParams) => RegistrationTuple;
|
|
49
|
+
export declare const makeCommitment: ({ secret, ...inputParams }: CommitmentParams) => {
|
|
14
50
|
secret: string;
|
|
15
51
|
commitment: string;
|
|
52
|
+
wrapperExpiry: number;
|
|
16
53
|
};
|
|
17
|
-
export declare const _makeCommitment: (
|
|
18
|
-
labelhash: string;
|
|
19
|
-
owner: string;
|
|
20
|
-
duration: number;
|
|
21
|
-
secret: string;
|
|
22
|
-
resolver: string;
|
|
23
|
-
data: string[];
|
|
24
|
-
reverseRecord: boolean;
|
|
25
|
-
fuses: string;
|
|
26
|
-
}) => string;
|
|
54
|
+
export declare const _makeCommitment: (params: CommitmentTuple) => string;
|
|
@@ -7,37 +7,63 @@ export const randomSecret = () => {
|
|
|
7
7
|
const bytes = Buffer.allocUnsafe(32);
|
|
8
8
|
return '0x' + crypto.getRandomValues(bytes).toString('hex');
|
|
9
9
|
};
|
|
10
|
-
export const
|
|
10
|
+
export const makeCommitmentData = ({ name, owner, duration, resolver, records, reverseRecord, fuses, wrapperExpiry, secret, }) => {
|
|
11
11
|
const label = labelhash(name.split('.')[0]);
|
|
12
12
|
const hash = namehash(name);
|
|
13
13
|
const resolverAddress = resolver.address;
|
|
14
|
-
const data = records ? generateRecordCallArray(hash, records, resolver) : [];
|
|
15
|
-
const secret = randomSecret();
|
|
16
14
|
const fuseData = fuses ? generateFuseInput(fuses) : '0';
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
if (reverseRecord) {
|
|
16
|
+
if (!records) {
|
|
17
|
+
records = { coinTypes: [{ key: 'ETH', value: owner }] };
|
|
18
|
+
}
|
|
19
|
+
else if (!records.coinTypes?.find((c) => c.key === 'ETH')) {
|
|
20
|
+
if (!records.coinTypes)
|
|
21
|
+
records.coinTypes = [];
|
|
22
|
+
records.coinTypes.push({ key: 'ETH', value: owner });
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
const data = records ? generateRecordCallArray(hash, records, resolver) : [];
|
|
26
|
+
return [
|
|
27
|
+
label,
|
|
19
28
|
owner,
|
|
20
29
|
duration,
|
|
21
|
-
|
|
22
|
-
resolver: resolverAddress,
|
|
30
|
+
resolverAddress,
|
|
23
31
|
data,
|
|
24
|
-
|
|
25
|
-
|
|
32
|
+
secret,
|
|
33
|
+
!!reverseRecord,
|
|
34
|
+
fuseData,
|
|
35
|
+
wrapperExpiry || Math.floor(Date.now() / 1000) + duration,
|
|
36
|
+
];
|
|
37
|
+
};
|
|
38
|
+
export const makeRegistrationData = (params) => {
|
|
39
|
+
const commitmentData = makeCommitmentData(params);
|
|
40
|
+
commitmentData[0] = params.name.split('.')[0];
|
|
41
|
+
const secret = commitmentData.splice(5, 1)[0];
|
|
42
|
+
commitmentData.splice(3, 0, secret);
|
|
43
|
+
return commitmentData;
|
|
44
|
+
};
|
|
45
|
+
export const makeCommitment = ({ secret = randomSecret(), ...inputParams }) => {
|
|
46
|
+
const generatedParams = makeCommitmentData({
|
|
47
|
+
...inputParams,
|
|
48
|
+
secret,
|
|
26
49
|
});
|
|
50
|
+
const commitment = _makeCommitment(generatedParams);
|
|
27
51
|
return {
|
|
28
52
|
secret,
|
|
29
53
|
commitment,
|
|
54
|
+
wrapperExpiry: generatedParams[8],
|
|
30
55
|
};
|
|
31
56
|
};
|
|
32
|
-
export const _makeCommitment = (
|
|
33
|
-
return utils.
|
|
57
|
+
export const _makeCommitment = (params) => {
|
|
58
|
+
return utils.keccak256(utils.defaultAbiCoder.encode([
|
|
34
59
|
'bytes32',
|
|
35
60
|
'address',
|
|
36
61
|
'uint256',
|
|
37
|
-
'bytes32',
|
|
38
62
|
'address',
|
|
39
63
|
'bytes[]',
|
|
64
|
+
'bytes32',
|
|
40
65
|
'bool',
|
|
41
|
-
'
|
|
42
|
-
|
|
66
|
+
'uint32',
|
|
67
|
+
'uint64',
|
|
68
|
+
], params));
|
|
43
69
|
};
|
|
@@ -2,4 +2,4 @@ import { BigNumber } from 'ethers';
|
|
|
2
2
|
import { ENSArgs } from '..';
|
|
3
3
|
export declare type Expiry = string | number | Date | BigNumber;
|
|
4
4
|
export declare const MAX_EXPIRY: BigNumber;
|
|
5
|
-
export declare const makeExpiry: ({ getExpiry }: ENSArgs<'getExpiry'>, name: string, expiry?: Expiry
|
|
5
|
+
export declare const makeExpiry: ({ getExpiry }: ENSArgs<'getExpiry'>, name: string, expiry?: Expiry) => Promise<BigNumber>;
|
|
@@ -1,4 +1,21 @@
|
|
|
1
1
|
import { JsonRpcSigner } from '@ethersproject/providers';
|
|
2
2
|
import type { PopulatedTransaction } from 'ethers';
|
|
3
|
-
declare
|
|
3
|
+
declare type CustomData = Record<string, any>;
|
|
4
|
+
declare const _default: (signer: JsonRpcSigner, populate: boolean) => ({ customData, ...tx }: PopulatedTransaction) => {
|
|
5
|
+
to?: string | undefined;
|
|
6
|
+
from?: string | undefined;
|
|
7
|
+
nonce?: number | undefined;
|
|
8
|
+
gasLimit?: import("ethers").BigNumber | undefined;
|
|
9
|
+
gasPrice?: import("ethers").BigNumber | undefined;
|
|
10
|
+
data?: string | undefined;
|
|
11
|
+
value?: import("ethers").BigNumber | undefined;
|
|
12
|
+
chainId?: number | undefined;
|
|
13
|
+
type?: number | undefined;
|
|
14
|
+
accessList?: import("ethers/lib/utils").AccessList | undefined;
|
|
15
|
+
maxFeePerGas?: import("ethers").BigNumber | undefined;
|
|
16
|
+
maxPriorityFeePerGas?: import("ethers").BigNumber | undefined;
|
|
17
|
+
ccipReadEnabled?: boolean | undefined;
|
|
18
|
+
} | Promise<import("@ethersproject/providers").TransactionResponse | (import("@ethersproject/providers").TransactionResponse & {
|
|
19
|
+
customData: CustomData;
|
|
20
|
+
})>;
|
|
4
21
|
export default _default;
|
|
@@ -1 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
const withCustomData = (tx, customData) => customData ? { ...tx, customData } : tx;
|
|
2
|
+
export default (signer, populate) => ({ customData, ...tx }) => populate
|
|
3
|
+
? withCustomData(tx, customData)
|
|
4
|
+
: signer.sendTransaction(tx).then((r) => withCustomData(r, customData));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ensdomains/ensjs",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.15",
|
|
4
4
|
"description": "ENS javascript library for contract interaction",
|
|
5
5
|
"main": "./dist/cjs/index.js",
|
|
6
6
|
"types": "./dist/cjs/index.d.ts",
|
|
@@ -22,26 +22,8 @@
|
|
|
22
22
|
"repository": "git@github.com:ensdomains/ensjs-v3.git",
|
|
23
23
|
"author": "TateB <yo@taytems.xyz>",
|
|
24
24
|
"license": "MIT",
|
|
25
|
-
"scripts": {
|
|
26
|
-
"env": "yarn ens-test-env",
|
|
27
|
-
"generate-types": "ts-node scripts/runTypechain.ts",
|
|
28
|
-
"generate-abis": "hardhat export-abi",
|
|
29
|
-
"start": "ts-node --files src/index.test.ts",
|
|
30
|
-
"test": "jest --run-in-band",
|
|
31
|
-
"test:watch": "jest --watch --run-in-band",
|
|
32
|
-
"test:specific": "ts-node --files ",
|
|
33
|
-
"clean": "rm -rf ./dist ./README.md ./LICENSE",
|
|
34
|
-
"build:esm": "tsc --project tsconfig.esm.json",
|
|
35
|
-
"build:cjs": "tsc --project tsconfig.cjs.json",
|
|
36
|
-
"build": "yarn clean && yarn build:esm && yarn build:cjs",
|
|
37
|
-
"prepublish": "yarn build && cp ../../{README.md,LICENSE} ./",
|
|
38
|
-
"remove-stableVersion": "ex -c '%s/,\\n\\s\\+\"stableVersion\".*\"//g' -cwq ./package.json",
|
|
39
|
-
"version:create": "yarn remove-stableVersion && yarn version",
|
|
40
|
-
"enode": "ganache --wallet.mnemonic=\"test test test test test test test test test test test junk\" --chain.chainId 1337 --chain.networkId 1337 --chain.time 1659500634000"
|
|
41
|
-
},
|
|
42
|
-
"packageManager": "yarn@3.2.0",
|
|
43
25
|
"dependencies": {
|
|
44
|
-
"@ensdomains/address-encoder": "
|
|
26
|
+
"@ensdomains/address-encoder": "0.2.16",
|
|
45
27
|
"@ensdomains/content-hash": "^2.5.7",
|
|
46
28
|
"dns-packet": "^5.3.1",
|
|
47
29
|
"ethers": "^5.6.1",
|
|
@@ -53,7 +35,7 @@
|
|
|
53
35
|
"devDependencies": {
|
|
54
36
|
"@ensdomains/buffer": "^0.0.13",
|
|
55
37
|
"@ensdomains/ens-contracts": "^0.0.12",
|
|
56
|
-
"@ensdomains/ens-test-env": "0.
|
|
38
|
+
"@ensdomains/ens-test-env": "0.2.2",
|
|
57
39
|
"@ethersproject/abi": "^5.6.0",
|
|
58
40
|
"@ethersproject/providers": "^5.6.2",
|
|
59
41
|
"@nomiclabs/hardhat-ethers": "npm:hardhat-deploy-ethers",
|
|
@@ -85,5 +67,20 @@
|
|
|
85
67
|
"peerDependencies": {
|
|
86
68
|
"ethers": "*"
|
|
87
69
|
},
|
|
88
|
-
"
|
|
70
|
+
"scripts": {
|
|
71
|
+
"tenv": "ens-test-env -a",
|
|
72
|
+
"generate-types": "ts-node scripts/runTypechain.ts",
|
|
73
|
+
"generate-abis": "hardhat export-abi",
|
|
74
|
+
"start": "ts-node --files src/index.test.ts",
|
|
75
|
+
"test": "jest --run-in-band",
|
|
76
|
+
"test:watch": "jest --watch --run-in-band",
|
|
77
|
+
"test:specific": "ts-node --files ",
|
|
78
|
+
"clean": "rm -rf ./dist ./README.md ./LICENSE",
|
|
79
|
+
"build:esm": "tsc --project tsconfig.esm.json",
|
|
80
|
+
"build:cjs": "tsc --project tsconfig.cjs.json",
|
|
81
|
+
"build": "pnpm clean && pnpm build:esm && pnpm build:cjs",
|
|
82
|
+
"prepublish": "pnpm build && cp ../../README.md ../../LICENSE ./",
|
|
83
|
+
"enode": "ganache --wallet.mnemonic=\"test test test test test test test test test test test junk\" --chain.chainId 1337 --chain.networkId 1337 --chain.time 1659500634000",
|
|
84
|
+
"ver": "pnpm version --no-workspaces-update"
|
|
85
|
+
}
|
|
89
86
|
}
|
|
@@ -21,20 +21,128 @@ describe('burnFuses', () => {
|
|
|
21
21
|
beforeEach(async () => {
|
|
22
22
|
await revert()
|
|
23
23
|
})
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
24
|
+
describe('Array', () => {
|
|
25
|
+
it('should return a burnFuses transaction from a named fuse array and succeed', async () => {
|
|
26
|
+
const tx = await ENSInstance.burnFuses('wrapped.eth', {
|
|
27
|
+
namedFusesToBurn: [
|
|
28
|
+
'CANNOT_UNWRAP',
|
|
29
|
+
'CANNOT_CREATE_SUBDOMAIN',
|
|
30
|
+
'CANNOT_SET_TTL',
|
|
31
|
+
],
|
|
32
|
+
addressOrIndex: accounts[1],
|
|
33
|
+
})
|
|
34
|
+
expect(tx).toBeTruthy()
|
|
35
|
+
await tx.wait()
|
|
36
|
+
|
|
37
|
+
const nameWrapper = await ENSInstance.contracts!.getNameWrapper()!
|
|
38
|
+
const [fuses] = await nameWrapper.getFuses(namehash('wrapped.eth'))
|
|
39
|
+
expect(fuses).toBe(113)
|
|
40
|
+
})
|
|
41
|
+
it('should return a burnFuses transaction from an unnamed fuse array and succeed', async () => {
|
|
42
|
+
const tx0 = await ENSInstance.burnFuses('wrapped.eth', {
|
|
43
|
+
namedFusesToBurn: ['CANNOT_UNWRAP'],
|
|
44
|
+
addressOrIndex: accounts[1],
|
|
45
|
+
})
|
|
46
|
+
expect(tx0).toBeTruthy()
|
|
47
|
+
await tx0.wait()
|
|
48
|
+
|
|
49
|
+
const tx = await ENSInstance.burnFuses('wrapped.eth', {
|
|
50
|
+
unnamedFusesToBurn: [128, 256, 512],
|
|
51
|
+
addressOrIndex: accounts[1],
|
|
52
|
+
})
|
|
53
|
+
expect(tx).toBeTruthy()
|
|
54
|
+
await tx.wait()
|
|
55
|
+
|
|
56
|
+
const nameWrapper = await ENSInstance.contracts!.getNameWrapper()!
|
|
57
|
+
const [fuses] = await nameWrapper.getFuses(namehash('wrapped.eth'))
|
|
58
|
+
expect(fuses).toBe(961)
|
|
59
|
+
})
|
|
60
|
+
it('should return a burnFuses transaction from both an unnamed and named fuse array and succeed', async () => {
|
|
61
|
+
const tx = await ENSInstance.burnFuses('wrapped.eth', {
|
|
62
|
+
namedFusesToBurn: [
|
|
63
|
+
'CANNOT_UNWRAP',
|
|
64
|
+
'CANNOT_CREATE_SUBDOMAIN',
|
|
65
|
+
'CANNOT_SET_TTL',
|
|
66
|
+
],
|
|
67
|
+
unnamedFusesToBurn: [128, 256, 512],
|
|
68
|
+
addressOrIndex: accounts[1],
|
|
69
|
+
})
|
|
70
|
+
expect(tx).toBeTruthy()
|
|
71
|
+
await tx.wait()
|
|
72
|
+
|
|
73
|
+
const nameWrapper = await ENSInstance.contracts!.getNameWrapper()!
|
|
74
|
+
const [fuses] = await nameWrapper.getFuses(namehash('wrapped.eth'))
|
|
75
|
+
expect(fuses).toBe(1009)
|
|
76
|
+
})
|
|
77
|
+
it('should throw an error when trying to burn a named fuse in an unnamed fuse array', async () => {
|
|
78
|
+
try {
|
|
79
|
+
await ENSInstance.burnFuses('wrapped.eth', {
|
|
80
|
+
unnamedFusesToBurn: [64] as any,
|
|
81
|
+
})
|
|
82
|
+
expect(false).toBeTruthy()
|
|
83
|
+
} catch (e: any) {
|
|
84
|
+
expect(e.message).toBe(
|
|
85
|
+
'64 is not a valid unnamed fuse. If you are trying to burn a named fuse, use the namedFusesToBurn property.',
|
|
86
|
+
)
|
|
87
|
+
}
|
|
88
|
+
})
|
|
89
|
+
it('should throw an error when trying to burn an unnamed fuse in a named fuse array', async () => {
|
|
90
|
+
try {
|
|
91
|
+
await ENSInstance.burnFuses('wrapped.eth', {
|
|
92
|
+
namedFusesToBurn: ['COOL_SWAG_FUSE'] as any,
|
|
93
|
+
})
|
|
94
|
+
expect(false).toBeTruthy()
|
|
95
|
+
} catch (e: any) {
|
|
96
|
+
expect(e.message).toBe('COOL_SWAG_FUSE is not a valid named fuse.')
|
|
97
|
+
}
|
|
98
|
+
})
|
|
99
|
+
})
|
|
100
|
+
describe('Number', () => {
|
|
101
|
+
it('should return a burnFuses transaction from a number and succeed', async () => {
|
|
102
|
+
const tx = await ENSInstance.burnFuses('wrapped.eth', {
|
|
103
|
+
fuseNumberToBurn: 49,
|
|
104
|
+
addressOrIndex: accounts[1],
|
|
105
|
+
})
|
|
106
|
+
expect(tx).toBeTruthy()
|
|
107
|
+
await tx.wait()
|
|
108
|
+
|
|
109
|
+
const nameWrapper = await ENSInstance.contracts!.getNameWrapper()!
|
|
110
|
+
const [fuses] = await nameWrapper.getFuses(namehash('wrapped.eth'))
|
|
111
|
+
expect(fuses).toBe(113)
|
|
112
|
+
})
|
|
113
|
+
it('should throw an error if the number is too high', async () => {
|
|
114
|
+
try {
|
|
115
|
+
await ENSInstance.burnFuses('wrapped.eth', {
|
|
116
|
+
fuseNumberToBurn: 4294967297,
|
|
117
|
+
})
|
|
118
|
+
expect(false).toBeTruthy()
|
|
119
|
+
} catch (e: any) {
|
|
120
|
+
expect(e.message).toBe(
|
|
121
|
+
'Fuse number must be limited to uint32, 4294967297 was too high.',
|
|
122
|
+
)
|
|
123
|
+
}
|
|
124
|
+
})
|
|
125
|
+
it('should throw an error if the number is too low', async () => {
|
|
126
|
+
try {
|
|
127
|
+
await ENSInstance.burnFuses('wrapped.eth', {
|
|
128
|
+
fuseNumberToBurn: -1,
|
|
129
|
+
})
|
|
130
|
+
expect(false).toBeTruthy()
|
|
131
|
+
} catch (e: any) {
|
|
132
|
+
expect(e.message).toBe(
|
|
133
|
+
'Fuse number must be limited to uint32, -1 was too low.',
|
|
134
|
+
)
|
|
135
|
+
}
|
|
136
|
+
})
|
|
137
|
+
it('should throw an error if the number is not an integer', async () => {
|
|
138
|
+
try {
|
|
139
|
+
await ENSInstance.burnFuses('wrapped.eth', {
|
|
140
|
+
fuseNumberToBurn: 7.5,
|
|
141
|
+
})
|
|
142
|
+
expect(false).toBeTruthy()
|
|
143
|
+
} catch (e: any) {
|
|
144
|
+
expect(e.message).toBe('Fuse number must be an integer, 7.5 was not.')
|
|
145
|
+
}
|
|
146
|
+
})
|
|
39
147
|
})
|
|
40
148
|
})
|
|
@@ -1,21 +1,112 @@
|
|
|
1
1
|
import { ENSArgs } from '..'
|
|
2
|
-
import {
|
|
3
|
-
import generateFuseInput from '../utils/generateFuseInput'
|
|
2
|
+
import { fuseEnum, unnamedFuses } from '../utils/fuses'
|
|
4
3
|
import { namehash } from '../utils/normalise'
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
type FuseObj = typeof fuseEnum
|
|
6
|
+
type UnnamedFuseType = typeof unnamedFuses
|
|
7
|
+
type Fuse = keyof FuseObj
|
|
8
|
+
type NamedFuseValues = FuseObj[Fuse]
|
|
9
|
+
type UnnamedFuseValues = UnnamedFuseType[number]
|
|
10
|
+
|
|
11
|
+
// We need this type so that the following type isn't infinite. This type limits the max length of the fuse array to 7.
|
|
12
|
+
type FuseArrayPossibilities =
|
|
13
|
+
| [Fuse]
|
|
14
|
+
| [Fuse, Fuse]
|
|
15
|
+
| [Fuse, Fuse, Fuse]
|
|
16
|
+
| [Fuse, Fuse, Fuse, Fuse]
|
|
17
|
+
| [Fuse, Fuse, Fuse, Fuse, Fuse]
|
|
18
|
+
| [Fuse, Fuse, Fuse, Fuse, Fuse, Fuse]
|
|
19
|
+
| [Fuse, Fuse, Fuse, Fuse, Fuse, Fuse, Fuse]
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* This type creates a type error if there are any duplicate fuses.
|
|
23
|
+
* It effectively works like a reduce function, starting with 0 included types, adding a type each time, and then checking for duplicates.
|
|
24
|
+
*
|
|
25
|
+
* @template A The array to check for duplicates.
|
|
26
|
+
* @template B The union of all checked existing types.
|
|
27
|
+
*/
|
|
28
|
+
// CLAUSE A: This extension unwraps the type as a fuse tuple.
|
|
29
|
+
type FusesWithoutDuplicates<A, B = never> = A extends FuseArrayPossibilities
|
|
30
|
+
? // CLAUSE A > TRUE: CLAUSE B: Pick out the first item in the current array, separating the current item from the rest.
|
|
31
|
+
A extends [infer Head, ...infer Tail]
|
|
32
|
+
? // CLAUSE B > TRUE: CLAUSE C: Check if the current item is a duplicate based on the input union.
|
|
33
|
+
Head extends B
|
|
34
|
+
? // CLAUSE C > TRUE: Duplicate found, return an empty array to throw a type error.
|
|
35
|
+
[]
|
|
36
|
+
: // CLAUSE C > FALSE: Return a new array to continue the recursion, adds the current item type to the union.
|
|
37
|
+
[Head, ...FusesWithoutDuplicates<Tail, Head | B>]
|
|
38
|
+
: // CLAUSE B > FALSE: Return the input array as there is no more array elements to check.
|
|
39
|
+
A
|
|
40
|
+
: // CLAUSE A > FALSE: Return an empty array as it isn't a fuse tuple.
|
|
41
|
+
[]
|
|
42
|
+
|
|
43
|
+
type FusePropsNamedArray<A extends FuseArrayPossibilities> = {
|
|
44
|
+
namedFusesToBurn: FusesWithoutDuplicates<A>
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
type FusePropsUnnamedArray = {
|
|
48
|
+
unnamedFusesToBurn: UnnamedFuseValues[]
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
type FusePropsNumber = {
|
|
52
|
+
fuseNumberToBurn: number
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
type FuseProps<A extends FuseArrayPossibilities> =
|
|
56
|
+
| (Partial<FusePropsNamedArray<A>> & FusePropsUnnamedArray)
|
|
57
|
+
| (FusePropsNamedArray<A> & Partial<FusePropsUnnamedArray>)
|
|
58
|
+
| FusePropsNumber
|
|
59
|
+
|
|
60
|
+
export default async function <A extends FuseArrayPossibilities>(
|
|
7
61
|
{ contracts, signer }: ENSArgs<'contracts' | 'signer'>,
|
|
8
62
|
name: string,
|
|
9
|
-
|
|
10
|
-
fusesToBurn,
|
|
11
|
-
}: {
|
|
12
|
-
fusesToBurn: FuseOptions
|
|
13
|
-
},
|
|
63
|
+
props: FuseProps<A>,
|
|
14
64
|
) {
|
|
65
|
+
const isNumber = 'fuseNumberToBurn' in props
|
|
66
|
+
const hasNamedArray = 'namedFusesToBurn' in props
|
|
67
|
+
const hasUnnamedArray = 'unnamedFusesToBurn' in props
|
|
68
|
+
|
|
69
|
+
let encodedFuses: number = 0
|
|
70
|
+
|
|
71
|
+
if (isNumber) {
|
|
72
|
+
if (props.fuseNumberToBurn > 2 ** 32 || props.fuseNumberToBurn < 1) {
|
|
73
|
+
throw new Error(
|
|
74
|
+
`Fuse number must be limited to uint32, ${
|
|
75
|
+
props.fuseNumberToBurn
|
|
76
|
+
} was too ${props.fuseNumberToBurn < 1 ? 'low' : 'high'}.`,
|
|
77
|
+
)
|
|
78
|
+
} else if (props.fuseNumberToBurn % 1 !== 0) {
|
|
79
|
+
throw new Error(
|
|
80
|
+
`Fuse number must be an integer, ${props.fuseNumberToBurn} was not.`,
|
|
81
|
+
)
|
|
82
|
+
}
|
|
83
|
+
encodedFuses = props.fuseNumberToBurn
|
|
84
|
+
} else {
|
|
85
|
+
if (!hasNamedArray && !hasUnnamedArray) {
|
|
86
|
+
throw new Error('Please provide fuses to burn')
|
|
87
|
+
}
|
|
88
|
+
if (hasNamedArray) {
|
|
89
|
+
for (const fuse of props.namedFusesToBurn!) {
|
|
90
|
+
if (!(fuse in fuseEnum)) {
|
|
91
|
+
throw new Error(`${fuse} is not a valid named fuse.`)
|
|
92
|
+
}
|
|
93
|
+
encodedFuses |= fuseEnum[fuse]
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
if (hasUnnamedArray) {
|
|
97
|
+
for (const fuse of props.unnamedFusesToBurn!) {
|
|
98
|
+
if (!unnamedFuses.includes(fuse)) {
|
|
99
|
+
throw new Error(
|
|
100
|
+
`${fuse} is not a valid unnamed fuse. If you are trying to burn a named fuse, use the namedFusesToBurn property.`,
|
|
101
|
+
)
|
|
102
|
+
}
|
|
103
|
+
encodedFuses |= fuse
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
15
108
|
const nameWrapper = (await contracts?.getNameWrapper()!).connect(signer)
|
|
16
109
|
const hash = namehash(name)
|
|
17
110
|
|
|
18
|
-
const encodedFuses = generateFuseInput(fusesToBurn)
|
|
19
|
-
|
|
20
111
|
return nameWrapper.populateTransaction.setFuses(hash, encodedFuses)
|
|
21
112
|
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { ethers } from 'ethers'
|
|
2
|
+
import { ENS } from '..'
|
|
3
|
+
import setup from '../tests/setup'
|
|
4
|
+
import { randomSecret } from '../utils/registerHelpers'
|
|
5
|
+
|
|
6
|
+
let ENSInstance: ENS
|
|
7
|
+
let revert: Awaited<ReturnType<typeof setup>>['revert']
|
|
8
|
+
let provider: ethers.providers.JsonRpcProvider
|
|
9
|
+
let accounts: string[]
|
|
10
|
+
|
|
11
|
+
beforeAll(async () => {
|
|
12
|
+
;({ ENSInstance, revert, provider } = await setup())
|
|
13
|
+
accounts = await provider.listAccounts()
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
afterAll(async () => {
|
|
17
|
+
await revert()
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
describe('commitName', () => {
|
|
21
|
+
beforeEach(async () => {
|
|
22
|
+
await revert()
|
|
23
|
+
})
|
|
24
|
+
it('should return a populated commit transaction with extra data and succeed', async () => {
|
|
25
|
+
const { customData, ...popTx } =
|
|
26
|
+
await ENSInstance.commitName.populateTransaction('commitment.eth', {
|
|
27
|
+
duration: 31536000,
|
|
28
|
+
owner: accounts[1],
|
|
29
|
+
addressOrIndex: accounts[1],
|
|
30
|
+
})
|
|
31
|
+
expect(popTx).toBeTruthy()
|
|
32
|
+
expect(customData).toHaveProperty('secret')
|
|
33
|
+
expect(customData).toHaveProperty('commitment')
|
|
34
|
+
expect(customData).toHaveProperty('wrapperExpiry')
|
|
35
|
+
|
|
36
|
+
const tx = await provider.getSigner().sendTransaction(popTx)
|
|
37
|
+
await tx.wait()
|
|
38
|
+
|
|
39
|
+
const controller = await ENSInstance.contracts!.getEthRegistrarController()!
|
|
40
|
+
const commitment = await controller.commitments(customData!.commitment)
|
|
41
|
+
expect(commitment).toBeTruthy()
|
|
42
|
+
})
|
|
43
|
+
it('should return a customised commmit transaction and succeed', async () => {
|
|
44
|
+
const secret = randomSecret()
|
|
45
|
+
const tx = await ENSInstance.commitName('commitment.eth', {
|
|
46
|
+
duration: 31536000,
|
|
47
|
+
owner: accounts[1],
|
|
48
|
+
addressOrIndex: accounts[1],
|
|
49
|
+
secret,
|
|
50
|
+
wrapperExpiry: 100000,
|
|
51
|
+
})
|
|
52
|
+
await tx.wait()
|
|
53
|
+
expect(tx.customData).toBeTruthy()
|
|
54
|
+
expect(tx.customData!.wrapperExpiry).toBe(100000)
|
|
55
|
+
expect(tx.customData!.secret).toBe(secret)
|
|
56
|
+
|
|
57
|
+
const controller = await ENSInstance.contracts!.getEthRegistrarController()!
|
|
58
|
+
const commitment = await controller.commitments(tx.customData!.commitment)
|
|
59
|
+
expect(commitment).toBeTruthy()
|
|
60
|
+
})
|
|
61
|
+
})
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { ENSArgs } from '..'
|
|
2
|
+
import { CommitmentParams, makeCommitment } from '../utils/registerHelpers'
|
|
3
|
+
|
|
4
|
+
type Params = Omit<CommitmentParams, 'resolver' | 'name'> & {
|
|
5
|
+
resolverAddress?: string
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export default async function (
|
|
9
|
+
{ contracts }: ENSArgs<'contracts'>,
|
|
10
|
+
name: string,
|
|
11
|
+
{ resolverAddress, ...params }: Params,
|
|
12
|
+
) {
|
|
13
|
+
const labels = name.split('.')
|
|
14
|
+
if (labels.length !== 2 || labels[1] !== 'eth')
|
|
15
|
+
throw new Error('Currently only .eth TLD registrations are supported')
|
|
16
|
+
|
|
17
|
+
const controller = await contracts!.getEthRegistrarController()
|
|
18
|
+
const resolver = await contracts!.getPublicResolver(
|
|
19
|
+
undefined,
|
|
20
|
+
resolverAddress,
|
|
21
|
+
)
|
|
22
|
+
const { secret, commitment, wrapperExpiry } = makeCommitment({
|
|
23
|
+
name,
|
|
24
|
+
resolver,
|
|
25
|
+
...params,
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
return {
|
|
29
|
+
...(await controller.populateTransaction.commit(commitment)),
|
|
30
|
+
customData: {
|
|
31
|
+
secret,
|
|
32
|
+
commitment,
|
|
33
|
+
wrapperExpiry,
|
|
34
|
+
},
|
|
35
|
+
}
|
|
36
|
+
}
|