@ensdomains/ensjs 3.0.0-alpha.2 → 3.0.0-alpha.5
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/burnFuses.d.ts +3 -1
- package/dist/cjs/functions/burnFuses.js +1 -5
- package/dist/cjs/functions/createSubname.d.ts +1 -5
- package/dist/cjs/functions/createSubname.js +1 -5
- package/dist/cjs/functions/deleteSubname.d.ts +2 -2
- package/dist/cjs/functions/deleteSubname.js +5 -2
- package/dist/cjs/functions/getDNSOwner.d.ts +7 -0
- package/dist/cjs/functions/getDNSOwner.js +81 -0
- package/dist/cjs/functions/setName.d.ts +3 -2
- package/dist/cjs/functions/setName.js +3 -8
- package/dist/cjs/functions/setRecords.d.ts +4 -1
- package/dist/cjs/functions/setRecords.js +10 -8
- package/dist/cjs/functions/setResolver.d.ts +3 -2
- package/dist/cjs/functions/setResolver.js +3 -9
- package/dist/cjs/functions/transferName.d.ts +3 -2
- package/dist/cjs/functions/transferName.js +5 -10
- package/dist/cjs/functions/transferSubname.d.ts +3 -2
- package/dist/cjs/functions/transferSubname.js +1 -5
- package/dist/cjs/functions/unwrapName.d.ts +3 -2
- package/dist/cjs/functions/unwrapName.js +1 -6
- package/dist/cjs/functions/wrapName.d.ts +4 -2
- package/dist/cjs/functions/wrapName.js +6 -10
- package/dist/cjs/index.d.ts +52 -34
- package/dist/cjs/index.js +36 -22
- package/dist/esm/functions/burnFuses.d.ts +3 -1
- package/dist/esm/functions/burnFuses.js +1 -5
- package/dist/esm/functions/createSubname.d.ts +1 -5
- package/dist/esm/functions/createSubname.js +1 -5
- package/dist/esm/functions/deleteSubname.d.ts +2 -2
- package/dist/esm/functions/deleteSubname.js +5 -2
- package/dist/esm/functions/getDNSOwner.d.ts +7 -0
- package/dist/esm/functions/getDNSOwner.js +51 -0
- package/dist/esm/functions/setName.d.ts +3 -2
- package/dist/esm/functions/setName.js +3 -8
- package/dist/esm/functions/setRecords.d.ts +4 -1
- package/dist/esm/functions/setRecords.js +10 -8
- package/dist/esm/functions/setResolver.d.ts +3 -2
- package/dist/esm/functions/setResolver.js +3 -9
- package/dist/esm/functions/transferName.d.ts +3 -2
- package/dist/esm/functions/transferName.js +5 -10
- package/dist/esm/functions/transferSubname.d.ts +3 -2
- package/dist/esm/functions/transferSubname.js +1 -5
- package/dist/esm/functions/unwrapName.d.ts +3 -2
- package/dist/esm/functions/unwrapName.js +1 -6
- package/dist/esm/functions/wrapName.d.ts +4 -2
- package/dist/esm/functions/wrapName.js +6 -10
- package/dist/esm/index.d.ts +52 -34
- package/dist/esm/index.js +36 -22
- package/package.json +10 -5
- package/src/@types/dns-packet/index.d.ts +114 -0
- package/src/{tests → functions}/batch.test.ts +1 -1
- package/src/{tests → functions}/batchWrappers.test.ts +1 -1
- package/src/{tests → functions}/burnFuses.test.ts +9 -8
- package/src/functions/burnFuses.ts +6 -8
- package/src/{tests → functions}/createSubname.test.ts +8 -11
- package/src/functions/createSubname.ts +3 -10
- package/src/{tests → functions}/deleteSubname.test.ts +28 -27
- package/src/functions/deleteSubname.ts +9 -12
- package/src/functions/getDNSOwner.test.ts +122 -0
- package/src/functions/getDNSOwner.ts +61 -0
- package/src/{tests → functions}/getExpiry.test.ts +1 -1
- package/src/{tests → functions}/getFuses.test.ts +12 -10
- package/src/{tests → functions}/getHistory.test.ts +1 -1
- package/src/{tests → functions}/getName.test.ts +1 -1
- package/src/{tests → functions}/getNames.test.ts +1 -1
- package/src/{tests → functions}/getOwner.test.ts +4 -2
- package/src/{tests → functions}/getProfile.test.ts +1 -1
- package/src/{tests → functions}/getResolver.test.ts +1 -1
- package/src/{tests → functions}/getSpecificRecord.test.ts +1 -1
- package/src/{tests → functions}/getSubnames.test.ts +1 -1
- package/src/{tests → functions}/makeCommitment.test.ts +1 -1
- package/src/{tests → functions}/normalise.test.ts +0 -0
- package/src/{tests → functions}/setName.test.ts +3 -2
- package/src/functions/setName.ts +10 -12
- package/src/{tests → functions}/setRecords.test.ts +7 -5
- package/src/functions/setRecords.ts +18 -12
- package/src/{tests → functions}/setResolver.test.ts +12 -15
- package/src/functions/setResolver.ts +10 -18
- package/src/{tests → functions}/transferName.test.ts +27 -29
- package/src/functions/transferName.ts +12 -18
- package/src/{tests → functions}/transferSubname.test.ts +30 -29
- package/src/functions/transferSubname.ts +8 -10
- package/src/{tests → functions}/unwrapName.test.ts +22 -22
- package/src/functions/unwrapName.ts +8 -12
- package/src/{tests → functions}/wrapName.test.ts +15 -12
- package/src/functions/wrapName.ts +16 -15
- package/src/index.ts +85 -29
- package/src/tests/signerInjection.test.ts +42 -0
- package/src/tests/withProvider.test.ts +1 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { BigNumber, ethers } from 'ethers'
|
|
2
2
|
import { ENS } from '..'
|
|
3
|
+
import setup from '../tests/setup'
|
|
3
4
|
import { hexEncodeName } from '../utils/hexEncodedName'
|
|
4
5
|
import { namehash } from '../utils/normalise'
|
|
5
|
-
import setup from './setup'
|
|
6
6
|
|
|
7
7
|
let ENSInstance: ENS
|
|
8
8
|
let revert: Awaited<ReturnType<typeof setup>>['revert']
|
|
@@ -24,7 +24,9 @@ describe('wrapName', () => {
|
|
|
24
24
|
await revert()
|
|
25
25
|
})
|
|
26
26
|
it('should return a wrap name transaction and succeed', async () => {
|
|
27
|
-
const tx = await ENSInstance.wrapName('parthtejpal.eth',
|
|
27
|
+
const tx = await ENSInstance.wrapName('parthtejpal.eth', {
|
|
28
|
+
wrappedOwner: accounts[0],
|
|
29
|
+
})
|
|
28
30
|
expect(tx).toBeTruthy()
|
|
29
31
|
await tx.wait()
|
|
30
32
|
|
|
@@ -33,24 +35,25 @@ describe('wrapName', () => {
|
|
|
33
35
|
expect((result as BigNumber).toHexString()).toBe('0x40')
|
|
34
36
|
})
|
|
35
37
|
it('should allow initial fuses', async () => {
|
|
36
|
-
const tx = await ENSInstance.wrapName('parthtejpal.eth',
|
|
37
|
-
|
|
38
|
-
|
|
38
|
+
const tx = await ENSInstance.wrapName('parthtejpal.eth', {
|
|
39
|
+
wrappedOwner: accounts[0],
|
|
40
|
+
fuseOptions: {
|
|
41
|
+
cannotUnwrap: true,
|
|
42
|
+
cannotSetTtl: true,
|
|
43
|
+
},
|
|
39
44
|
})
|
|
40
45
|
expect(tx).toBeTruthy()
|
|
41
46
|
await tx.wait()
|
|
42
47
|
|
|
43
48
|
const nameWrapper = await ENSInstance.contracts!.getNameWrapper()!
|
|
44
49
|
const [result] = await nameWrapper.getFuses(namehash('parthtejpal.eth'))
|
|
45
|
-
expect((result as BigNumber).toHexString()).toBe('
|
|
50
|
+
expect((result as BigNumber).toHexString()).toBe('0x40')
|
|
46
51
|
})
|
|
47
52
|
it('should allow an initial resolver address', async () => {
|
|
48
|
-
const tx = await ENSInstance.wrapName(
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
'0x42D63ae25990889E35F215bC95884039Ba354115',
|
|
53
|
-
)
|
|
53
|
+
const tx = await ENSInstance.wrapName('parthtejpal.eth', {
|
|
54
|
+
wrappedOwner: accounts[0],
|
|
55
|
+
resolverAddress: '0x42D63ae25990889E35F215bC95884039Ba354115',
|
|
56
|
+
})
|
|
54
57
|
expect(tx).toBeTruthy()
|
|
55
58
|
await tx.wait()
|
|
56
59
|
|
|
@@ -19,8 +19,8 @@ async function wrapETH(
|
|
|
19
19
|
const labelhash = ethers.utils.solidityKeccak256(['string'], [labels[0]])
|
|
20
20
|
|
|
21
21
|
const data = ethers.utils.defaultAbiCoder.encode(
|
|
22
|
-
['string', 'address', '
|
|
23
|
-
[labels[0], wrappedOwner, decodedFuses, resolverAddress],
|
|
22
|
+
['string', 'address', 'uint32', 'uint64', 'address'],
|
|
23
|
+
[labels[0], wrappedOwner, '0x0', decodedFuses, resolverAddress],
|
|
24
24
|
)
|
|
25
25
|
|
|
26
26
|
return baseRegistrar['safeTransferFrom(address,address,uint256,bytes)'](
|
|
@@ -38,8 +38,9 @@ async function wrapOther(
|
|
|
38
38
|
decodedFuses: string,
|
|
39
39
|
resolverAddress: string,
|
|
40
40
|
address: string,
|
|
41
|
+
signer: ethers.Signer,
|
|
41
42
|
) {
|
|
42
|
-
const nameWrapper = await contracts?.getNameWrapper()!
|
|
43
|
+
const nameWrapper = (await contracts?.getNameWrapper()!).connect(signer)
|
|
43
44
|
const registry = await contracts?.getRegistry()!
|
|
44
45
|
|
|
45
46
|
const hasApproval = await registry.isApprovedForAll(
|
|
@@ -62,20 +63,19 @@ async function wrapOther(
|
|
|
62
63
|
}
|
|
63
64
|
|
|
64
65
|
export default async function (
|
|
65
|
-
{ contracts,
|
|
66
|
+
{ contracts, signer }: ENSArgs<'contracts' | 'signer'>,
|
|
66
67
|
name: string,
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
68
|
+
{
|
|
69
|
+
wrappedOwner,
|
|
70
|
+
fuseOptions,
|
|
71
|
+
resolverAddress,
|
|
72
|
+
}: {
|
|
73
|
+
wrappedOwner: string
|
|
74
|
+
fuseOptions?: FuseOptions | string | number
|
|
75
|
+
resolverAddress?: string
|
|
76
|
+
},
|
|
71
77
|
) {
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
const address = await signer?.getAddress()
|
|
75
|
-
|
|
76
|
-
if (!signer || !address) {
|
|
77
|
-
throw new Error('No signer found')
|
|
78
|
-
}
|
|
78
|
+
const address = await signer.getAddress()
|
|
79
79
|
|
|
80
80
|
let decodedFuses: string
|
|
81
81
|
|
|
@@ -123,6 +123,7 @@ export default async function (
|
|
|
123
123
|
decodedFuses,
|
|
124
124
|
resolverAddress,
|
|
125
125
|
address,
|
|
126
|
+
signer,
|
|
126
127
|
)
|
|
127
128
|
}
|
|
128
129
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ethers } from 'ethers'
|
|
1
|
+
import { ethers, Signer } from 'ethers'
|
|
2
2
|
import ContractManager from './contracts'
|
|
3
3
|
import { getContractAddress as _getContractAddress } from './contracts/getContractAddress'
|
|
4
4
|
import { SupportedNetworkId } from './contracts/types'
|
|
@@ -11,6 +11,7 @@ import type {
|
|
|
11
11
|
import type burnFuses from './functions/burnFuses'
|
|
12
12
|
import type createSubname from './functions/createSubname'
|
|
13
13
|
import type deleteSubname from './functions/deleteSubname'
|
|
14
|
+
import type getDNSOwner from './functions/getDNSOwner'
|
|
14
15
|
import type getExpiry from './functions/getExpiry'
|
|
15
16
|
import type getFuses from './functions/getFuses'
|
|
16
17
|
import type {
|
|
@@ -52,6 +53,7 @@ type ENSOptions = {
|
|
|
52
53
|
export type InternalENS = {
|
|
53
54
|
options?: ENSOptions
|
|
54
55
|
provider?: ethers.providers.Provider
|
|
56
|
+
signer: Signer
|
|
55
57
|
graphURI?: string | null
|
|
56
58
|
} & ENS
|
|
57
59
|
|
|
@@ -75,6 +77,21 @@ type FirstArg<F> = F extends (x: infer A, ...args: any[]) => any ? A : never
|
|
|
75
77
|
|
|
76
78
|
type FunctionDeps<F> = Extract<keyof FirstArg<F>, string>[]
|
|
77
79
|
|
|
80
|
+
type WriteOptions = {
|
|
81
|
+
addressOrIndex?: string | number
|
|
82
|
+
signer?: Signer
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
type WriteFunction<F> = F extends (
|
|
86
|
+
x: any,
|
|
87
|
+
arg_0: infer Z,
|
|
88
|
+
options?: infer P,
|
|
89
|
+
) => infer R
|
|
90
|
+
? (name: Z, options?: P & WriteOptions) => R
|
|
91
|
+
: F extends (x: any, arg_0: infer Z, options: infer P) => infer R
|
|
92
|
+
? (name: Z, options: P & WriteOptions) => R
|
|
93
|
+
: never
|
|
94
|
+
|
|
78
95
|
const graphURIEndpoints: Record<string, string> = {
|
|
79
96
|
1: 'https://api.thegraph.com/subgraphs/name/ensdomains/ens',
|
|
80
97
|
3: 'https://api.thegraph.com/subgraphs/name/ensdomains/ensropsten',
|
|
@@ -171,7 +188,7 @@ export class ENS {
|
|
|
171
188
|
path: string,
|
|
172
189
|
dependencies: FunctionDeps<F>,
|
|
173
190
|
exportName: string = 'default',
|
|
174
|
-
subFunc?: 'raw' | 'decode' | 'combine' | 'batch',
|
|
191
|
+
subFunc?: 'raw' | 'decode' | 'combine' | 'batch' | 'write',
|
|
175
192
|
passthrough?: RawFunction,
|
|
176
193
|
): Function => {
|
|
177
194
|
// if batch is specified, create batch func
|
|
@@ -193,10 +210,29 @@ export class ENS {
|
|
|
193
210
|
// otherwise, create a function from the raw and decode functions
|
|
194
211
|
if (subFunc !== 'combine') {
|
|
195
212
|
// get the function to call
|
|
196
|
-
const func =
|
|
213
|
+
const func =
|
|
214
|
+
subFunc && subFunc !== 'write'
|
|
215
|
+
? mod[exportName][subFunc]
|
|
216
|
+
: mod[exportName]
|
|
197
217
|
// get the dependencies to forward to the function as the first arg
|
|
198
|
-
|
|
218
|
+
let dependenciesToForward =
|
|
199
219
|
thisRef.forwardDependenciesFromArray<F>(dependencies)
|
|
220
|
+
|
|
221
|
+
// if func is write func, inject signer into dependencies
|
|
222
|
+
if (subFunc === 'write') {
|
|
223
|
+
const options = (args[1] || {}) as WriteOptions
|
|
224
|
+
const signer =
|
|
225
|
+
options.signer ||
|
|
226
|
+
thisRef.provider?.getSigner(options.addressOrIndex)
|
|
227
|
+
if (!signer) {
|
|
228
|
+
throw new Error('No signer specified')
|
|
229
|
+
}
|
|
230
|
+
delete options.addressOrIndex
|
|
231
|
+
delete options.signer
|
|
232
|
+
dependenciesToForward = { ...dependenciesToForward, signer }
|
|
233
|
+
return func(dependenciesToForward, args[0], options)
|
|
234
|
+
}
|
|
235
|
+
|
|
200
236
|
// return the function with the dependencies forwarded
|
|
201
237
|
return func(dependenciesToForward, ...args)
|
|
202
238
|
} else {
|
|
@@ -255,6 +291,25 @@ export class ENS {
|
|
|
255
291
|
): OmitFirstArg<F> =>
|
|
256
292
|
this.importGenerator<F>(path, dependencies, exportName) as OmitFirstArg<F>
|
|
257
293
|
|
|
294
|
+
/**
|
|
295
|
+
* Generates a write wrapped function
|
|
296
|
+
* @param {string} path - The path of the exported function
|
|
297
|
+
* @param {FunctionDeps} dependencies - An array of ENS properties
|
|
298
|
+
* @param {string} exportName - The export name of the target function
|
|
299
|
+
* @returns {OmitFirstArg} - The generated wrapped function
|
|
300
|
+
*/
|
|
301
|
+
private generateWriteFunction = <F>(
|
|
302
|
+
path: string,
|
|
303
|
+
dependencies: FunctionDeps<F>,
|
|
304
|
+
exportName: string = 'default',
|
|
305
|
+
): WriteFunction<F> =>
|
|
306
|
+
this.importGenerator<F>(
|
|
307
|
+
path,
|
|
308
|
+
dependencies,
|
|
309
|
+
exportName,
|
|
310
|
+
'write',
|
|
311
|
+
) as WriteFunction<F>
|
|
312
|
+
|
|
258
313
|
/**
|
|
259
314
|
* Generates a wrapped function from raw and decode exports
|
|
260
315
|
* @param {string} path - The path of the exported function
|
|
@@ -454,54 +509,55 @@ export class ENS {
|
|
|
454
509
|
'multicallWrapper',
|
|
455
510
|
)
|
|
456
511
|
|
|
457
|
-
public setName = this.
|
|
512
|
+
public setName = this.generateWriteFunction<typeof setName>('setName', [
|
|
458
513
|
'contracts',
|
|
459
|
-
'provider',
|
|
460
514
|
])
|
|
461
515
|
|
|
462
|
-
public setRecords = this.
|
|
463
|
-
'
|
|
464
|
-
'provider',
|
|
465
|
-
|
|
466
|
-
])
|
|
516
|
+
public setRecords = this.generateWriteFunction<typeof setRecords>(
|
|
517
|
+
'setRecords',
|
|
518
|
+
['contracts', 'provider', 'getResolver'],
|
|
519
|
+
)
|
|
467
520
|
|
|
468
|
-
public setResolver = this.
|
|
521
|
+
public setResolver = this.generateWriteFunction<typeof setResolver>(
|
|
469
522
|
'setResolver',
|
|
470
|
-
['contracts'
|
|
523
|
+
['contracts'],
|
|
471
524
|
)
|
|
472
525
|
|
|
473
|
-
public transferName = this.
|
|
526
|
+
public transferName = this.generateWriteFunction<typeof transferName>(
|
|
474
527
|
'transferName',
|
|
475
|
-
['contracts'
|
|
528
|
+
['contracts'],
|
|
476
529
|
)
|
|
477
530
|
|
|
478
|
-
public wrapName = this.
|
|
531
|
+
public wrapName = this.generateWriteFunction<typeof wrapName>('wrapName', [
|
|
479
532
|
'contracts',
|
|
480
|
-
'provider',
|
|
481
533
|
])
|
|
482
534
|
|
|
483
|
-
public unwrapName = this.
|
|
484
|
-
'
|
|
485
|
-
'
|
|
486
|
-
|
|
535
|
+
public unwrapName = this.generateWriteFunction<typeof unwrapName>(
|
|
536
|
+
'unwrapName',
|
|
537
|
+
['contracts'],
|
|
538
|
+
)
|
|
487
539
|
|
|
488
|
-
public burnFuses = this.
|
|
540
|
+
public burnFuses = this.generateWriteFunction<typeof burnFuses>('burnFuses', [
|
|
489
541
|
'contracts',
|
|
490
|
-
'provider',
|
|
491
542
|
])
|
|
492
543
|
|
|
493
|
-
public createSubname = this.
|
|
544
|
+
public createSubname = this.generateWriteFunction<typeof createSubname>(
|
|
494
545
|
'createSubname',
|
|
495
|
-
['contracts'
|
|
546
|
+
['contracts'],
|
|
496
547
|
)
|
|
497
548
|
|
|
498
|
-
public deleteSubname = this.
|
|
549
|
+
public deleteSubname = this.generateWriteFunction<typeof deleteSubname>(
|
|
499
550
|
'deleteSubname',
|
|
500
|
-
['
|
|
551
|
+
['transferSubname'],
|
|
501
552
|
)
|
|
502
553
|
|
|
503
|
-
public transferSubname = this.
|
|
554
|
+
public transferSubname = this.generateWriteFunction<typeof transferSubname>(
|
|
504
555
|
'transferSubname',
|
|
505
|
-
['contracts'
|
|
556
|
+
['contracts'],
|
|
557
|
+
)
|
|
558
|
+
|
|
559
|
+
public getDNSOwner = this.generateFunction<typeof getDNSOwner>(
|
|
560
|
+
'getDNSOwner',
|
|
561
|
+
[],
|
|
506
562
|
)
|
|
507
563
|
}
|
|
@@ -0,0 +1,42 @@
|
|
|
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('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', { signer })
|
|
28
|
+
expect(tx).toBeTruthy()
|
|
29
|
+
if (tx) {
|
|
30
|
+
await tx.wait()
|
|
31
|
+
expect(tx.from).toBe(accounts[3])
|
|
32
|
+
}
|
|
33
|
+
})
|
|
34
|
+
it('should return a transaction succesfully for a custom signer index', async () => {
|
|
35
|
+
const tx = await ENSInstance.setName('fleek.eth', { addressOrIndex: 3 })
|
|
36
|
+
expect(tx).toBeTruthy()
|
|
37
|
+
if (tx) {
|
|
38
|
+
await tx.wait()
|
|
39
|
+
expect(tx.from).toBe(accounts[3])
|
|
40
|
+
}
|
|
41
|
+
})
|
|
42
|
+
})
|