@ensdomains/ensjs 3.0.0-alpha.12 → 3.0.0-alpha.13
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/functions/commitName.d.ts +26 -0
- package/dist/cjs/functions/commitName.js +24 -0
- package/dist/cjs/functions/getProfile.js +1 -1
- 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 +10 -2
- package/dist/cjs/index.js +6 -1
- package/dist/cjs/utils/registerHelpers.d.ts +44 -16
- package/dist/cjs/utils/registerHelpers.js +43 -15
- package/dist/cjs/utils/writeTx.d.ts +18 -1
- package/dist/cjs/utils/writeTx.js +4 -1
- package/dist/esm/functions/commitName.d.ts +26 -0
- package/dist/esm/functions/commitName.js +21 -0
- package/dist/esm/functions/getProfile.js +1 -1
- 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 +10 -2
- package/dist/esm/index.js +6 -1
- package/dist/esm/utils/registerHelpers.d.ts +44 -16
- package/dist/esm/utils/registerHelpers.js +40 -14
- 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/commitName.test.ts +61 -0
- package/src/functions/commitName.ts +36 -0
- 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 +25 -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
|
@@ -6,12 +6,56 @@ import { labelhash } from './labels'
|
|
|
6
6
|
import { namehash } from './normalise'
|
|
7
7
|
import { generateRecordCallArray, RecordOptions } from './recordHelpers'
|
|
8
8
|
|
|
9
|
+
export type RegistrationParams = {
|
|
10
|
+
name: string
|
|
11
|
+
owner: string
|
|
12
|
+
duration: number
|
|
13
|
+
secret: string
|
|
14
|
+
resolver: PublicResolver
|
|
15
|
+
records?: RecordOptions
|
|
16
|
+
reverseRecord?: boolean
|
|
17
|
+
fuses?: FuseOptions
|
|
18
|
+
wrapperExpiry: number
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export type CommitmentParams = Omit<
|
|
22
|
+
RegistrationParams,
|
|
23
|
+
'secret' | 'wrapperExpiry'
|
|
24
|
+
> & {
|
|
25
|
+
secret?: string
|
|
26
|
+
wrapperExpiry?: number
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export type RegistrationTuple = [
|
|
30
|
+
name: string,
|
|
31
|
+
owner: string,
|
|
32
|
+
duration: number,
|
|
33
|
+
secret: string,
|
|
34
|
+
resolver: string,
|
|
35
|
+
data: string[],
|
|
36
|
+
reverseRecord: boolean,
|
|
37
|
+
fuses: string,
|
|
38
|
+
wrapperExpiry: number,
|
|
39
|
+
]
|
|
40
|
+
|
|
41
|
+
export type CommitmentTuple = [
|
|
42
|
+
labelhash: string,
|
|
43
|
+
owner: string,
|
|
44
|
+
duration: number,
|
|
45
|
+
resolver: string,
|
|
46
|
+
data: string[],
|
|
47
|
+
secret: string,
|
|
48
|
+
reverseRecord: boolean,
|
|
49
|
+
fuses: string,
|
|
50
|
+
wrapperExpiry: number,
|
|
51
|
+
]
|
|
52
|
+
|
|
9
53
|
export const randomSecret = () => {
|
|
10
54
|
const bytes = Buffer.allocUnsafe(32)
|
|
11
55
|
return '0x' + crypto.getRandomValues(bytes).toString('hex')
|
|
12
56
|
}
|
|
13
57
|
|
|
14
|
-
export const
|
|
58
|
+
export const makeCommitmentData = ({
|
|
15
59
|
name,
|
|
16
60
|
owner,
|
|
17
61
|
duration,
|
|
@@ -19,69 +63,83 @@ export const makeCommitment = ({
|
|
|
19
63
|
records,
|
|
20
64
|
reverseRecord,
|
|
21
65
|
fuses,
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
records?: RecordOptions
|
|
28
|
-
reverseRecord?: boolean
|
|
29
|
-
fuses?: FuseOptions
|
|
30
|
-
}) => {
|
|
66
|
+
wrapperExpiry,
|
|
67
|
+
secret,
|
|
68
|
+
}: CommitmentParams & {
|
|
69
|
+
secret: string
|
|
70
|
+
}): CommitmentTuple => {
|
|
31
71
|
const label = labelhash(name.split('.')[0])
|
|
32
72
|
const hash = namehash(name)
|
|
33
73
|
const resolverAddress = resolver.address
|
|
34
|
-
const data = records ? generateRecordCallArray(hash, records, resolver) : []
|
|
35
|
-
const secret = randomSecret()
|
|
36
74
|
const fuseData = fuses ? generateFuseInput(fuses) : '0'
|
|
37
75
|
|
|
38
|
-
|
|
39
|
-
|
|
76
|
+
if (reverseRecord) {
|
|
77
|
+
if (!records) {
|
|
78
|
+
records = { coinTypes: [{ key: 'ETH', value: owner }] }
|
|
79
|
+
} else if (!records.coinTypes?.find((c) => c.key === 'ETH')) {
|
|
80
|
+
if (!records.coinTypes) records.coinTypes = []
|
|
81
|
+
records.coinTypes.push({ key: 'ETH', value: owner })
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const data = records ? generateRecordCallArray(hash, records, resolver) : []
|
|
86
|
+
|
|
87
|
+
return [
|
|
88
|
+
label,
|
|
40
89
|
owner,
|
|
41
90
|
duration,
|
|
42
|
-
|
|
43
|
-
resolver: resolverAddress,
|
|
91
|
+
resolverAddress,
|
|
44
92
|
data,
|
|
45
|
-
|
|
46
|
-
|
|
93
|
+
secret,
|
|
94
|
+
!!reverseRecord,
|
|
95
|
+
fuseData,
|
|
96
|
+
wrapperExpiry || Math.floor(Date.now() / 1000) + duration,
|
|
97
|
+
]
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export const makeRegistrationData = (
|
|
101
|
+
params: RegistrationParams,
|
|
102
|
+
): RegistrationTuple => {
|
|
103
|
+
const commitmentData = makeCommitmentData(params)
|
|
104
|
+
commitmentData[0] = params.name.split('.')[0]
|
|
105
|
+
const secret = commitmentData.splice(5, 1)[0]
|
|
106
|
+
commitmentData.splice(3, 0, secret)
|
|
107
|
+
return commitmentData as unknown as RegistrationTuple
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export const makeCommitment = ({
|
|
111
|
+
secret = randomSecret(),
|
|
112
|
+
...inputParams
|
|
113
|
+
}: CommitmentParams) => {
|
|
114
|
+
const generatedParams = makeCommitmentData({
|
|
115
|
+
...inputParams,
|
|
116
|
+
secret,
|
|
47
117
|
})
|
|
48
118
|
|
|
119
|
+
const commitment = _makeCommitment(generatedParams)
|
|
120
|
+
|
|
49
121
|
return {
|
|
50
122
|
secret,
|
|
51
123
|
commitment,
|
|
124
|
+
wrapperExpiry: generatedParams[8],
|
|
52
125
|
}
|
|
53
126
|
}
|
|
54
127
|
|
|
55
|
-
export const _makeCommitment = ({
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
reverseRecord: boolean
|
|
72
|
-
fuses: string
|
|
73
|
-
}) => {
|
|
74
|
-
return utils.solidityKeccak256(
|
|
75
|
-
[
|
|
76
|
-
'bytes32',
|
|
77
|
-
'address',
|
|
78
|
-
'uint256',
|
|
79
|
-
'bytes32',
|
|
80
|
-
'address',
|
|
81
|
-
'bytes[]',
|
|
82
|
-
'bool',
|
|
83
|
-
'uint96',
|
|
84
|
-
],
|
|
85
|
-
[labelhash, owner, duration, secret, resolver, data, reverseRecord, fuses],
|
|
128
|
+
export const _makeCommitment = (params: CommitmentTuple) => {
|
|
129
|
+
return utils.keccak256(
|
|
130
|
+
utils.defaultAbiCoder.encode(
|
|
131
|
+
[
|
|
132
|
+
'bytes32',
|
|
133
|
+
'address',
|
|
134
|
+
'uint256',
|
|
135
|
+
'address',
|
|
136
|
+
'bytes[]',
|
|
137
|
+
'bytes32',
|
|
138
|
+
'bool',
|
|
139
|
+
'uint32',
|
|
140
|
+
'uint64',
|
|
141
|
+
],
|
|
142
|
+
params,
|
|
143
|
+
),
|
|
86
144
|
)
|
|
87
145
|
}
|
package/src/utils/writeTx.ts
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
import { JsonRpcSigner } from '@ethersproject/providers'
|
|
2
2
|
import type { PopulatedTransaction } from 'ethers'
|
|
3
3
|
|
|
4
|
+
type CustomData = Record<string, any>
|
|
5
|
+
|
|
6
|
+
const withCustomData = <T extends object>(
|
|
7
|
+
tx: T,
|
|
8
|
+
customData: CustomData | undefined,
|
|
9
|
+
): (T & { customData: CustomData }) | T =>
|
|
10
|
+
customData ? { ...tx, customData } : tx
|
|
11
|
+
|
|
4
12
|
export default (signer: JsonRpcSigner, populate: boolean) =>
|
|
5
|
-
(tx: PopulatedTransaction) =>
|
|
6
|
-
populate
|
|
13
|
+
({ customData, ...tx }: PopulatedTransaction) =>
|
|
14
|
+
populate
|
|
15
|
+
? withCustomData(tx, customData)
|
|
16
|
+
: signer.sendTransaction(tx).then((r) => withCustomData(r, customData))
|
|
@@ -1,40 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { config } from 'dotenv'
|
|
2
|
-
import { ethers } from 'ethers'
|
|
3
|
-
import { resolve } from 'path'
|
|
4
|
-
import { ENS } from '../'
|
|
5
|
-
import { ContractName, SupportedNetworkId } from '../contracts/types'
|
|
6
|
-
|
|
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>
|
|
15
|
-
|
|
16
|
-
const createENS = (graphURI: string) =>
|
|
17
|
-
new ENS({
|
|
18
|
-
graphURI,
|
|
19
|
-
getContractAddress: (_: SupportedNetworkId) => (contractName) =>
|
|
20
|
-
deploymentAddresses[
|
|
21
|
-
contractName === 'ENSRegistryWithFallback'
|
|
22
|
-
? 'ENSRegistry'
|
|
23
|
-
: contractName
|
|
24
|
-
],
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
export default async (useReal?: boolean) => {
|
|
28
|
-
const graphURI = useReal
|
|
29
|
-
? 'https://api.thegraph.com/subgraphs/name/ensdomains/ensropsten'
|
|
30
|
-
: 'http://localhost:8000/subgraphs/name/graphprotocol/ens'
|
|
31
|
-
|
|
32
|
-
const provider = new ethers.providers.JsonRpcProvider(
|
|
33
|
-
'http://localhost:8545',
|
|
34
|
-
1337,
|
|
35
|
-
)
|
|
36
|
-
|
|
37
|
-
let ENSInstance = createENS(graphURI)
|
|
38
|
-
await ENSInstance.setProvider(provider)
|
|
39
|
-
|
|
40
|
-
let snapshot = await provider.send('evm_snapshot', [])
|
|
41
|
-
|
|
42
|
-
const revert = async (customSnapshot?: any) => {
|
|
43
|
-
const snapshotToUse = customSnapshot || snapshot
|
|
44
|
-
await provider.send('evm_revert', [snapshotToUse])
|
|
45
|
-
if (parseInt(snapshot, 16) >= parseInt(snapshotToUse, 16)) {
|
|
46
|
-
snapshot = await provider.send('evm_snapshot', [])
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
ENSInstance = createENS(graphURI)
|
|
50
|
-
await ENSInstance.setProvider(provider)
|
|
51
|
-
return
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const createSnapshot = async () => await provider.send('evm_snapshot', [])
|
|
55
|
-
|
|
56
|
-
return { ENSInstance, revert, createSnapshot, provider }
|
|
57
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
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,28 +0,0 @@
|
|
|
1
|
-
import { ethers } from 'ethers'
|
|
2
|
-
import { ENS } from '..'
|
|
3
|
-
import setup from '../tests/setup'
|
|
4
|
-
|
|
5
|
-
let ENSInstance: ENS
|
|
6
|
-
let providerFake: ethers.providers.JsonRpcProvider
|
|
7
|
-
|
|
8
|
-
beforeAll(async () => {
|
|
9
|
-
;({ ENSInstance } = await setup())
|
|
10
|
-
providerFake = new ethers.providers.JsonRpcProvider(
|
|
11
|
-
'http://localhost:34023',
|
|
12
|
-
'ropsten',
|
|
13
|
-
)
|
|
14
|
-
})
|
|
15
|
-
|
|
16
|
-
describe('withProvider', () => {
|
|
17
|
-
it('should be able to use a new provider', async () => {
|
|
18
|
-
const addr = await ENSInstance.getAddr('with-profile.eth')
|
|
19
|
-
expect(addr).toBeTruthy()
|
|
20
|
-
|
|
21
|
-
try {
|
|
22
|
-
await ENSInstance.withProvider(providerFake).getOwner('with-profile.eth')
|
|
23
|
-
expect(false).toBeTruthy()
|
|
24
|
-
} catch {
|
|
25
|
-
expect(true).toBeTruthy()
|
|
26
|
-
}
|
|
27
|
-
})
|
|
28
|
-
})
|