@ensdomains/ensjs 3.0.0-alpha.1 → 3.0.0-alpha.10

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.
Files changed (147) hide show
  1. package/README.md +2 -0
  2. package/dist/cjs/GqlManager.d.ts +3 -0
  3. package/dist/cjs/GqlManager.js +62 -2
  4. package/dist/cjs/functions/burnFuses.d.ts +3 -2
  5. package/dist/cjs/functions/burnFuses.js +4 -8
  6. package/dist/cjs/functions/createSubname.d.ts +1 -5
  7. package/dist/cjs/functions/createSubname.js +5 -8
  8. package/dist/cjs/functions/deleteSubname.d.ts +3 -3
  9. package/dist/cjs/functions/deleteSubname.js +5 -2
  10. package/dist/cjs/functions/getDNSOwner.d.ts +7 -0
  11. package/dist/cjs/functions/getDNSOwner.js +81 -0
  12. package/dist/cjs/functions/getFuses.js +3 -2
  13. package/dist/cjs/functions/getOwner.js +7 -6
  14. package/dist/cjs/functions/getProfile.d.ts +4 -1
  15. package/dist/cjs/functions/getProfile.js +102 -24
  16. package/dist/cjs/functions/getRecords.d.ts +1 -0
  17. package/dist/cjs/functions/getSpecificRecord.js +22 -5
  18. package/dist/cjs/functions/getSubnames.js +6 -6
  19. package/dist/cjs/functions/setName.d.ts +4 -3
  20. package/dist/cjs/functions/setName.js +5 -10
  21. package/dist/cjs/functions/setRecord.d.ts +18 -0
  22. package/dist/cjs/functions/setRecord.js +27 -0
  23. package/dist/cjs/functions/setRecords.d.ts +4 -2
  24. package/dist/cjs/functions/setRecords.js +14 -12
  25. package/dist/cjs/functions/setResolver.d.ts +4 -4
  26. package/dist/cjs/functions/setResolver.js +6 -12
  27. package/dist/cjs/functions/transferName.d.ts +4 -3
  28. package/dist/cjs/functions/transferName.js +9 -13
  29. package/dist/cjs/functions/transferSubname.d.ts +4 -3
  30. package/dist/cjs/functions/transferSubname.js +5 -8
  31. package/dist/cjs/functions/unwrapName.d.ts +4 -3
  32. package/dist/cjs/functions/unwrapName.js +5 -9
  33. package/dist/cjs/functions/wrapName.d.ts +5 -3
  34. package/dist/cjs/functions/wrapName.js +8 -12
  35. package/dist/cjs/index.d.ts +48 -46
  36. package/dist/cjs/index.js +43 -19
  37. package/dist/cjs/utils/labels.js +5 -4
  38. package/dist/cjs/utils/makeHashIndexes.js +2 -2
  39. package/dist/cjs/utils/normalise.d.ts +1 -0
  40. package/dist/cjs/utils/normalise.js +27 -1
  41. package/dist/cjs/utils/recordHelpers.d.ts +3 -0
  42. package/dist/cjs/utils/recordHelpers.js +42 -15
  43. package/dist/cjs/utils/registerHelpers.js +3 -4
  44. package/dist/cjs/utils/writeTx.d.ts +4 -0
  45. package/dist/cjs/utils/writeTx.js +3 -0
  46. package/dist/esm/GqlManager.d.ts +3 -0
  47. package/dist/esm/GqlManager.js +58 -2
  48. package/dist/esm/functions/burnFuses.d.ts +3 -2
  49. package/dist/esm/functions/burnFuses.js +4 -8
  50. package/dist/esm/functions/createSubname.d.ts +1 -5
  51. package/dist/esm/functions/createSubname.js +5 -8
  52. package/dist/esm/functions/deleteSubname.d.ts +3 -3
  53. package/dist/esm/functions/deleteSubname.js +5 -2
  54. package/dist/esm/functions/getDNSOwner.d.ts +7 -0
  55. package/dist/esm/functions/getDNSOwner.js +51 -0
  56. package/dist/esm/functions/getFuses.js +4 -3
  57. package/dist/esm/functions/getOwner.js +7 -6
  58. package/dist/esm/functions/getProfile.d.ts +4 -1
  59. package/dist/esm/functions/getProfile.js +102 -24
  60. package/dist/esm/functions/getRecords.d.ts +1 -0
  61. package/dist/esm/functions/getSpecificRecord.js +22 -5
  62. package/dist/esm/functions/getSubnames.js +3 -3
  63. package/dist/esm/functions/setName.d.ts +4 -3
  64. package/dist/esm/functions/setName.js +5 -10
  65. package/dist/esm/functions/setRecord.d.ts +18 -0
  66. package/dist/esm/functions/setRecord.js +24 -0
  67. package/dist/esm/functions/setRecords.d.ts +4 -2
  68. package/dist/esm/functions/setRecords.js +14 -12
  69. package/dist/esm/functions/setResolver.d.ts +4 -4
  70. package/dist/esm/functions/setResolver.js +6 -12
  71. package/dist/esm/functions/transferName.d.ts +4 -3
  72. package/dist/esm/functions/transferName.js +9 -13
  73. package/dist/esm/functions/transferSubname.d.ts +4 -3
  74. package/dist/esm/functions/transferSubname.js +5 -8
  75. package/dist/esm/functions/unwrapName.d.ts +4 -3
  76. package/dist/esm/functions/unwrapName.js +5 -9
  77. package/dist/esm/functions/wrapName.d.ts +5 -3
  78. package/dist/esm/functions/wrapName.js +8 -12
  79. package/dist/esm/index.d.ts +48 -46
  80. package/dist/esm/index.js +43 -19
  81. package/dist/esm/utils/labels.js +5 -4
  82. package/dist/esm/utils/makeHashIndexes.js +2 -2
  83. package/dist/esm/utils/normalise.d.ts +1 -0
  84. package/dist/esm/utils/normalise.js +25 -0
  85. package/dist/esm/utils/recordHelpers.d.ts +3 -0
  86. package/dist/esm/utils/recordHelpers.js +40 -14
  87. package/dist/esm/utils/registerHelpers.js +3 -4
  88. package/dist/esm/utils/writeTx.d.ts +4 -0
  89. package/dist/esm/utils/writeTx.js +1 -0
  90. package/package.json +15 -7
  91. package/src/@types/dns-packet/index.d.ts +114 -0
  92. package/src/GqlManager.test.ts +170 -0
  93. package/src/GqlManager.ts +67 -2
  94. package/src/{tests → functions}/batch.test.ts +1 -1
  95. package/src/{tests → functions}/batchWrappers.test.ts +1 -1
  96. package/src/{tests → functions}/burnFuses.test.ts +12 -10
  97. package/src/functions/burnFuses.ts +9 -11
  98. package/src/{tests → functions}/createSubname.test.ts +12 -16
  99. package/src/functions/createSubname.ts +7 -13
  100. package/src/{tests → functions}/deleteSubname.test.ts +32 -32
  101. package/src/functions/deleteSubname.ts +9 -12
  102. package/src/functions/getDNSOwner.test.ts +122 -0
  103. package/src/functions/getDNSOwner.ts +61 -0
  104. package/src/{tests → functions}/getExpiry.test.ts +1 -1
  105. package/src/{tests → functions}/getFuses.test.ts +12 -10
  106. package/src/functions/getFuses.ts +4 -3
  107. package/src/{tests → functions}/getHistory.test.ts +1 -1
  108. package/src/{tests → functions}/getName.test.ts +1 -1
  109. package/src/{tests → functions}/getNames.test.ts +1 -1
  110. package/src/{tests → functions}/getOwner.test.ts +14 -2
  111. package/src/functions/getOwner.ts +7 -7
  112. package/src/{tests → functions}/getProfile.test.ts +45 -12
  113. package/src/functions/getProfile.ts +151 -24
  114. package/src/functions/getRecords.ts +1 -0
  115. package/src/{tests → functions}/getResolver.test.ts +1 -1
  116. package/src/{tests → functions}/getSpecificRecord.test.ts +1 -1
  117. package/src/functions/getSpecificRecord.ts +28 -8
  118. package/src/{tests → functions}/getSubnames.test.ts +1 -1
  119. package/src/functions/getSubnames.ts +68 -66
  120. package/src/{tests → functions}/makeCommitment.test.ts +1 -1
  121. package/src/functions/normalise.test.ts +22 -0
  122. package/src/{tests → functions}/setName.test.ts +3 -2
  123. package/src/functions/setName.ts +15 -17
  124. package/src/functions/setRecord.test.ts +100 -0
  125. package/src/functions/setRecord.ts +63 -0
  126. package/src/{tests → functions}/setRecords.test.ts +12 -10
  127. package/src/functions/setRecords.ts +22 -16
  128. package/src/{tests → functions}/setResolver.test.ts +12 -15
  129. package/src/functions/setResolver.ts +15 -20
  130. package/src/{tests → functions}/transferName.test.ts +30 -31
  131. package/src/functions/transferName.ts +19 -22
  132. package/src/{tests → functions}/transferSubname.test.ts +34 -34
  133. package/src/functions/transferSubname.ts +21 -13
  134. package/src/{tests → functions}/unwrapName.test.ts +24 -23
  135. package/src/functions/unwrapName.ts +20 -15
  136. package/src/{tests → functions}/wrapName.test.ts +19 -19
  137. package/src/functions/wrapName.ts +20 -22
  138. package/src/index.ts +115 -26
  139. package/src/tests/populateTransaction.test.ts +40 -0
  140. package/src/tests/signerInjection.test.ts +46 -0
  141. package/src/tests/withProvider.test.ts +1 -1
  142. package/src/utils/labels.ts +6 -4
  143. package/src/utils/makeHashIndexes.ts +4 -4
  144. package/src/utils/normalise.ts +29 -0
  145. package/src/utils/recordHelpers.ts +52 -18
  146. package/src/utils/registerHelpers.ts +3 -4
  147. package/src/utils/writeTx.ts +6 -0
@@ -0,0 +1,114 @@
1
+ declare module 'dns-packet' {
2
+ const AUTHORITATIVE_ANSWER: number
3
+ const TRUNCATED_RESPONSE: number
4
+ const RECURSION_DESIRED: number
5
+ const RECURSION_AVAILABLE: number
6
+ const AUTHENTIC_DATA: number
7
+ const CHECKING_DISABLED: number
8
+ const DNSSEC_OK: number
9
+
10
+ interface decoder<T> {
11
+ (buf: Buffer, offset?: number): T
12
+ bytes: number;
13
+ }
14
+
15
+ const decode: decoder<Packet>;
16
+
17
+ interface encoder<T> {
18
+ (packet: T, buf?: Buffer, offset?: number): Buffer
19
+ bytes: number;
20
+ }
21
+
22
+ const encode: encoder<Packet>;
23
+
24
+ interface Packet {
25
+ id?: number
26
+ type: 'query' | 'response'
27
+ flags?: number
28
+ rcode?: string
29
+ questions: Question[]
30
+ answers?: Answer[]
31
+ authorities?: Answer[]
32
+ additionals?: Answer[]
33
+ }
34
+
35
+ interface Question {
36
+ type: string
37
+ class: string
38
+ name: string
39
+ }
40
+
41
+ interface AnswerBase {
42
+ type: string
43
+ class: string
44
+ name: string
45
+ ttl?: number
46
+ }
47
+
48
+ interface A extends AnswerBase {
49
+ type: 'A'
50
+ data: string
51
+ }
52
+
53
+ interface Dnskey extends AnswerBase {
54
+ type: 'DNSKEY'
55
+ data: {
56
+ flags: number
57
+ algorithm: number
58
+ key: Buffer
59
+ }
60
+ }
61
+
62
+ interface Ds extends AnswerBase {
63
+ type: 'DS'
64
+ data: {
65
+ keyTag: number
66
+ algorithm: number
67
+ digestType: number
68
+ digest: Buffer
69
+ }
70
+ }
71
+
72
+ interface Opt extends AnswerBase {
73
+ type: 'OPT'
74
+ udpPayloadSize?: number
75
+ extendedRcode?: number
76
+ ednsVersion?: number
77
+ flags?: number
78
+ data?: any
79
+ }
80
+
81
+ interface Rrsig extends AnswerBase {
82
+ type: 'RRSIG'
83
+ data: {
84
+ typeCovered: string
85
+ algorithm: number
86
+ labels: number
87
+ originalTTL: number
88
+ expiration: number
89
+ inception: number
90
+ keyTag: number
91
+ signersName: string
92
+ signature: Buffer
93
+ }
94
+ }
95
+
96
+ interface Rtxt extends AnswerBase {
97
+ type: 'TXT'
98
+ data: Buffer[]
99
+ }
100
+
101
+ type Answer = A|Dnskey|Ds|Opt|Rrsig|Rtxt
102
+
103
+ interface Encodable<T> {
104
+ decode: decoder<T>
105
+ encode: encoder<T>
106
+ }
107
+
108
+ const record: (type: string) => Encodable<Answer>
109
+ const answer: Encodable<Answer>
110
+ const dnskey: Encodable<Dnskey['data']>
111
+ const name: Encodable<string>
112
+ const rrsig: Encodable<Rrsig['data']>
113
+ }
114
+
@@ -0,0 +1,170 @@
1
+ import traverse from 'traverse'
2
+ import { visit, parse } from 'graphql'
3
+
4
+ import { requestMiddleware, responseMiddleware, enter } from './GqlManager'
5
+ import { namehash } from './utils/normalise'
6
+
7
+ describe('GqlManager', () => {
8
+ const queryWithoutId = `
9
+ query getNames($id: ID!, $expiryDate: Int) {
10
+ account(id: $id) {
11
+ registrations(first: 1000, where: { expiryDate_gt: $expiryDate }) {
12
+ registrationDate
13
+ expiryDate
14
+ domain {
15
+ labelName
16
+ labelhash
17
+ name
18
+ isMigrated
19
+ parent {
20
+ name
21
+ }
22
+ }
23
+ }
24
+ domains(first: 1000) {
25
+ labelName
26
+ labelhash
27
+ name
28
+ isMigrated
29
+ parent {
30
+ name
31
+ }
32
+ createdAt
33
+ }
34
+ }
35
+ }
36
+ `
37
+
38
+ const mockRequest = {
39
+ method: 'POST',
40
+ headers: {
41
+ 'Content-Type': 'application/json',
42
+ },
43
+ body: JSON.stringify({ query: queryWithoutId }),
44
+ }
45
+
46
+ const mockResponse = {
47
+ data: {
48
+ account: {
49
+ registrations: [
50
+ {
51
+ registrationDate: '1659245504',
52
+ expiryDate: '1690781504',
53
+ domain: {
54
+ id: '0xb1ccf7f6bb648f39ba48bf80f4a8a4522f474ee7d1edd6ea65f7fa51fe8b1612',
55
+ labelName: 'randydandy',
56
+ labelhash:
57
+ '0x63fd5bfdd0b1eb9f4c33c209b7c3e7dcb87a761d926a65e267f7cb99ee313ddd',
58
+ name: '0xde2551f43e950a2a4d4e6052f25edc450c48a5338faa27f09d1ee99ca9dc04fd',
59
+ isMigrated: true,
60
+ parent: {
61
+ name: '0x93cdeb708b7545dc668eb9280176169d1c33cfd8ed6f04690a0bcc88a93fc4ae',
62
+ invalidName: true,
63
+ },
64
+ invalidName: true,
65
+ },
66
+ },
67
+ {
68
+ registrationDate: '1635284756',
69
+ expiryDate: '1666841708',
70
+ domain: {
71
+ id: '0xde2551f43e950a2a4d4e6052f25edc450c48a5338faa27f09d1ee99ca9dc04fd',
72
+ labelName: 'randydandy',
73
+ labelhash:
74
+ '0x6a877a8d92ad83c8d044d0c5b69aa0da3050f4d653dcc149fca952d6439e4105',
75
+ name: 'randydandy.eth',
76
+ isMigrated: true,
77
+ parent: {
78
+ name: '0x93cdeb708b7545dc668eb9280176169d1c33cfd8ed6f04690a0bcc88a93fc4ae',
79
+ invalidName: true,
80
+ },
81
+ },
82
+ },
83
+ {
84
+ registrationDate: '1659250465',
85
+ expiryDate: '1690786465',
86
+ domain: {
87
+ id: '0xaf119e72f050e5acad6b2d97826a7afb45afe9407376a2ab8240b62173b2d7c2',
88
+ labelName: 'nullbyte',
89
+ labelhash:
90
+ '0xc8985f8323b3dc707003a6ef5b379d9e8a058b6d6bcc2cfb307c61ca36920e27',
91
+ name: '0xb54c7c79c89d571f1fbf4c67f524e336a04441eeee4d76f156e835da99a46ddb',
92
+ isMigrated: true,
93
+ parent: {
94
+ name: '0x93cdeb708b7545dc668eb9280176169d1c33cfd8ed6f04690a0bcc88a93fc4ae',
95
+ invalidName: true,
96
+ },
97
+ invalidName: true,
98
+ },
99
+ },
100
+ ],
101
+ domains: [
102
+ {
103
+ id: '0xaf119e72f050e5acad6b2d97826a7afb45afe9407376a2ab8240b62173b2d7c2',
104
+ labelName: 'nullbyte',
105
+ labelhash:
106
+ '0xc8985f8323b3dc707003a6ef5b379d9e8a058b6d6bcc2cfb307c61ca36920e27',
107
+ name: '0xb54c7c79c89d571f1fbf4c67f524e336a04441eeee4d76f156e835da99a46ddb',
108
+ isMigrated: true,
109
+ parent: {
110
+ name: '0x93cdeb708b7545dc668eb9280176169d1c33cfd8ed6f04690a0bcc88a93fc4ae',
111
+ invalidName: true,
112
+ },
113
+ createdAt: '1659250465',
114
+ invalidName: true,
115
+ },
116
+ {
117
+ id: '0xb1ccf7f6bb648f39ba48bf80f4a8a4522f474ee7d1edd6ea65f7fa51fe8b1612',
118
+ labelName: 'randydandy',
119
+ labelhash:
120
+ '0x63fd5bfdd0b1eb9f4c33c209b7c3e7dcb87a761d926a65e267f7cb99ee313ddd',
121
+ name: '0xde2551f43e950a2a4d4e6052f25edc450c48a5338faa27f09d1ee99ca9dc04fd',
122
+ isMigrated: true,
123
+ parent: {
124
+ name: '0x93cdeb708b7545dc668eb9280176169d1c33cfd8ed6f04690a0bcc88a93fc4ae',
125
+ invalidName: true,
126
+ },
127
+ createdAt: '1659245504',
128
+ invalidName: true,
129
+ },
130
+ {
131
+ id: '0xde2551f43e950a2a4d4e6052f25edc450c48a5338faa27f09d1ee99ca9dc04fd',
132
+ labelName: 'randydandy',
133
+ labelhash:
134
+ '0x6a877a8d92ad83c8d044d0c5b69aa0da3050f4d653dcc149fca952d6439e4105',
135
+ name: 'randydandy.eth',
136
+ isMigrated: true,
137
+ parent: {
138
+ name: '0x93cdeb708b7545dc668eb9280176169d1c33cfd8ed6f04690a0bcc88a93fc4ae',
139
+ invalidName: true,
140
+ },
141
+ createdAt: '1635284756',
142
+ },
143
+ ],
144
+ },
145
+ },
146
+ headers: {
147
+ map: {
148
+ 'content-type': 'application/json',
149
+ },
150
+ },
151
+ status: 200,
152
+ }
153
+
154
+ describe('requestMiddleware', () => {
155
+ it('should add id to a SelectionSet if name is present and id is not', () => {
156
+ const result = requestMiddleware(visit, parse)(mockRequest)
157
+ expect(result.body.includes('id')).toBe(true)
158
+ })
159
+ })
160
+ describe('responseMiddleware', () => {
161
+ it('should replace name with the namehash when there is an invalid name and id combo', () => {
162
+ const result = responseMiddleware(traverse)(mockResponse)
163
+ expect(result.data.account.domains[0].name).toBe(
164
+ namehash(
165
+ '0xb54c7c79c89d571f1fbf4c67f524e336a04441eeee4d76f156e835da99a46ddb',
166
+ ),
167
+ )
168
+ })
169
+ })
170
+ })
package/src/GqlManager.ts CHANGED
@@ -1,11 +1,76 @@
1
+ // @ts-nocheck
2
+ import { namehash } from './utils/normalise'
3
+
4
+ const generateSelection = (selection: any) => ({
5
+ kind: 'Field',
6
+ name: {
7
+ kind: 'Name',
8
+ value: selection,
9
+ },
10
+ arguments: [],
11
+ directives: [],
12
+ alias: undefined,
13
+ selectionSet: undefined,
14
+ })
15
+
16
+ export const enter = (node: any) => {
17
+ if (node.kind === 'SelectionSet') {
18
+ const id = node.selections.find((x) => x.name && x.name.value === 'id')
19
+ const name = node.selections.find((x) => x.name && x.name.value === 'name')
20
+
21
+ if (!id && name) {
22
+ node.selections = [...node.selections, generateSelection('id')]
23
+ return node
24
+ }
25
+ }
26
+ }
27
+
28
+ export const requestMiddleware = (visit, parse) => (request: any) => {
29
+ const requestBody = JSON.parse(request.body)
30
+ const rawQuery = requestBody.query
31
+ const parsedQuery = parse(rawQuery)
32
+ const updatedQuery = visit(parsedQuery, { enter })
33
+ const updatedBody = { ...requestBody, query: updatedQuery.loc.source.body }
34
+
35
+ return {
36
+ ...request,
37
+ body: JSON.stringify(updatedBody),
38
+ }
39
+ }
40
+
41
+ export const responseMiddleware = (traverse) => (response: any) => {
42
+ traverse(response).forEach(function (responseItem: any) {
43
+ if (responseItem instanceof Object && responseItem.name) {
44
+ //Name already in hashed form
45
+ if (responseItem.name && responseItem.name.includes('[')) {
46
+ return
47
+ }
48
+
49
+ const hashedName = namehash(responseItem.name)
50
+ if (responseItem.id !== hashedName) {
51
+ this.update({ ...responseItem, name: hashedName, invalidName: true })
52
+ }
53
+ }
54
+ })
55
+ return response
56
+ }
57
+
1
58
  export default class GqlManager {
2
59
  public gql: any = () => null
3
60
  public client?: any | null = null
4
61
 
5
62
  public setUrl = async (url: string | null) => {
6
63
  if (url) {
7
- const imported = await import('graphql-request')
8
- this.client = new imported.GraphQLClient(url)
64
+ const [imported, traverse, { visit, parse }] = await Promise.all([
65
+ import('graphql-request'),
66
+ import('traverse'),
67
+ import('graphql/language'),
68
+ ])
69
+
70
+ this.client = new imported.GraphQLClient(url, {
71
+ requestMiddleware: requestMiddleware(visit, parse),
72
+ responseMiddleware: responseMiddleware(traverse.default),
73
+ })
9
74
  this.gql = imported.gql
10
75
  } else {
11
76
  this.client = null
@@ -1,5 +1,5 @@
1
1
  import { ENS } from '..'
2
- import setup from './setup'
2
+ import setup from '../tests/setup'
3
3
 
4
4
  let ENSInstance: ENS
5
5
 
@@ -1,5 +1,5 @@
1
1
  import { ENS } from '..'
2
- import setup from './setup'
2
+ import setup from '../tests/setup'
3
3
 
4
4
  let ENSInstance: ENS
5
5
 
@@ -1,6 +1,7 @@
1
- import { BigNumber, ethers, utils } from 'ethers'
1
+ import { BigNumber, ethers } from 'ethers'
2
2
  import { ENS } from '..'
3
- import setup from './setup'
3
+ import setup from '../tests/setup'
4
+ import { namehash } from '../utils/normalise'
4
5
 
5
6
  let ENSInstance: ENS
6
7
  let revert: Awaited<ReturnType<typeof setup>>['revert']
@@ -21,22 +22,23 @@ describe('burnFuses', () => {
21
22
  await revert()
22
23
  })
23
24
  it('should return a burnFuses transaction and succeed', async () => {
24
- const wrapNameTx = await ENSInstance.wrapName(
25
- 'parthtejpal.eth',
26
- accounts[0],
27
- )
25
+ const wrapNameTx = await ENSInstance.wrapName('parthtejpal.eth', {
26
+ wrappedOwner: accounts[0],
27
+ })
28
28
  await wrapNameTx.wait()
29
29
 
30
30
  const tx = await ENSInstance.burnFuses('parthtejpal.eth', {
31
- cannotUnwrap: true,
32
- cannotCreateSubdomain: true,
33
- cannotSetTtl: true,
31
+ fusesToBurn: {
32
+ cannotUnwrap: true,
33
+ cannotCreateSubdomain: true,
34
+ cannotSetTtl: true,
35
+ },
34
36
  })
35
37
  expect(tx).toBeTruthy()
36
38
  await tx.wait()
37
39
 
38
40
  const nameWrapper = await ENSInstance.contracts!.getNameWrapper()!
39
- const result = await nameWrapper.getFuses(utils.namehash('parthtejpal.eth'))
41
+ const result = await nameWrapper.getFuses(namehash('parthtejpal.eth'))
40
42
  const fuseBN = result.fuses as BigNumber
41
43
  expect(fuseBN.toHexString()).toBe('0x71')
42
44
  })
@@ -1,23 +1,21 @@
1
- import { ethers } from 'ethers'
2
1
  import { ENSArgs } from '..'
3
2
  import { FuseOptions } from '../@types/FuseOptions'
4
3
  import generateFuseInput from '../utils/generateFuseInput'
4
+ import { namehash } from '../utils/normalise'
5
5
 
6
6
  export default async function (
7
- { contracts, provider }: ENSArgs<'contracts' | 'provider'>,
7
+ { contracts, signer }: ENSArgs<'contracts' | 'signer'>,
8
8
  name: string,
9
- fusesToBurn: FuseOptions,
9
+ {
10
+ fusesToBurn,
11
+ }: {
12
+ fusesToBurn: FuseOptions
13
+ },
10
14
  ) {
11
- const signer = provider?.getSigner()
12
-
13
- if (!signer) {
14
- throw new Error('No signer found')
15
- }
16
-
17
15
  const nameWrapper = (await contracts?.getNameWrapper()!).connect(signer)
18
- const namehash = ethers.utils.namehash(name)
16
+ const hash = namehash(name)
19
17
 
20
18
  const encodedFuses = generateFuseInput(fusesToBurn)
21
19
 
22
- return nameWrapper.burnFuses(namehash, encodedFuses)
20
+ return nameWrapper.populateTransaction.burnFuses(hash, encodedFuses)
23
21
  }
@@ -1,6 +1,7 @@
1
- import { ethers, utils } from 'ethers'
1
+ import { ethers } from 'ethers'
2
2
  import { ENS } from '..'
3
- import setup from './setup'
3
+ import setup from '../tests/setup'
4
+ import { namehash } from '../utils/normalise'
4
5
 
5
6
  let ENSInstance: ENS
6
7
  let revert: Awaited<ReturnType<typeof setup>>['revert']
@@ -22,38 +23,33 @@ describe('createSubname', () => {
22
23
  await revert()
23
24
  })
24
25
  it('should allow creating a subname on the registry', async () => {
25
- const tx = await ENSInstance.createSubname({
26
+ const tx = await ENSInstance.createSubname('test.parthtejpal.eth', {
26
27
  contract: 'registry',
27
- name: 'test.parthtejpal.eth',
28
28
  owner: accounts[0],
29
- options: { addressOrIndex: 0 },
29
+ addressOrIndex: 0,
30
30
  })
31
31
  expect(tx).toBeTruthy()
32
32
  await tx.wait()
33
33
 
34
34
  const registry = await ENSInstance.contracts!.getRegistry()!
35
- const result = await registry.owner(utils.namehash('test.parthtejpal.eth'))
35
+ const result = await registry.owner(namehash('test.parthtejpal.eth'))
36
36
  expect(result).toBe(accounts[0])
37
37
  })
38
38
  it('should allow creating a subname on the namewrapper', async () => {
39
- const wrapNameTx = await ENSInstance.wrapName(
40
- 'parthtejpal.eth',
41
- accounts[0],
42
- )
39
+ const wrapNameTx = await ENSInstance.wrapName('parthtejpal.eth', {
40
+ wrappedOwner: accounts[0],
41
+ })
43
42
  await wrapNameTx.wait()
44
- const tx = await ENSInstance.createSubname({
43
+ const tx = await ENSInstance.createSubname('test.parthtejpal.eth', {
45
44
  contract: 'nameWrapper',
46
- name: 'test.parthtejpal.eth',
47
45
  owner: accounts[0],
48
- options: { addressOrIndex: 0 },
46
+ addressOrIndex: 0,
49
47
  })
50
48
  expect(tx).toBeTruthy()
51
49
  await tx.wait()
52
50
 
53
51
  const nameWrapper = await ENSInstance.contracts!.getNameWrapper()!
54
- const result = await nameWrapper.ownerOf(
55
- utils.namehash('test.parthtejpal.eth'),
56
- )
52
+ const result = await nameWrapper.ownerOf(namehash('test.parthtejpal.eth'))
57
53
  expect(result).toBe(accounts[0])
58
54
  })
59
55
  })
@@ -2,13 +2,12 @@ import { ethers } from 'ethers'
2
2
  import { ENSArgs } from '..'
3
3
  import { FuseOptions } from '../@types/FuseOptions'
4
4
  import generateFuseInput from '../utils/generateFuseInput'
5
+ import { namehash } from '../utils/normalise'
5
6
 
6
7
  type BaseArgs = {
7
- name: string
8
8
  owner: string
9
9
  resolverAddress?: string
10
10
  contract: 'registry' | 'nameWrapper'
11
- options?: { addressOrIndex?: string | number }
12
11
  }
13
12
 
14
13
  type NameWrapperArgs = {
@@ -19,15 +18,10 @@ type NameWrapperArgs = {
19
18
  type Args = BaseArgs | NameWrapperArgs
20
19
 
21
20
  export default async function (
22
- { contracts, provider }: ENSArgs<'contracts' | 'provider'>,
23
- { name, owner, resolverAddress, contract, options, ...wrapperArgs }: Args,
21
+ { contracts, signer }: ENSArgs<'contracts' | 'signer'>,
22
+ name: string,
23
+ { owner, resolverAddress, contract, ...wrapperArgs }: Args,
24
24
  ) {
25
- const signer = provider?.getSigner(options?.addressOrIndex)
26
-
27
- if (!signer) {
28
- throw new Error('No signer found')
29
- }
30
-
31
25
  const labels = name.split('.')
32
26
 
33
27
  if (labels.length === 1) {
@@ -44,13 +38,13 @@ export default async function (
44
38
 
45
39
  const label = labels.shift() as string
46
40
  const labelhash = ethers.utils.solidityKeccak256(['string'], [label])
47
- const parentNodehash = ethers.utils.namehash(labels.join('.'))
41
+ const parentNodehash = namehash(labels.join('.'))
48
42
 
49
43
  switch (contract) {
50
44
  case 'registry': {
51
45
  const registry = (await contracts?.getRegistry()!).connect(signer)
52
46
 
53
- return registry.setSubnodeRecord(
47
+ return registry.populateTransaction.setSubnodeRecord(
54
48
  parentNodehash,
55
49
  labelhash,
56
50
  owner,
@@ -66,7 +60,7 @@ export default async function (
66
60
  ? generateFuseInput(wrapperArgs.fuses)
67
61
  : '0'
68
62
 
69
- return nameWrapper.setSubnodeRecord(
63
+ return nameWrapper.populateTransaction.setSubnodeRecord(
70
64
  parentNodehash,
71
65
  label,
72
66
  owner,
@@ -1,6 +1,7 @@
1
- import { ethers, utils } from 'ethers'
1
+ import { ethers } from 'ethers'
2
2
  import { ENS } from '..'
3
- import setup from './setup'
3
+ import setup from '../tests/setup'
4
+ import { namehash } from '../utils/normalise'
4
5
 
5
6
  let ENSInstance: ENS
6
7
  let revert: Awaited<ReturnType<typeof setup>>['revert']
@@ -21,52 +22,51 @@ describe('deleteSubname', () => {
21
22
  await revert()
22
23
  })
23
24
  it('should allow deleting a subname on the registry', async () => {
24
- const createSubnameTx = await ENSInstance.createSubname({
25
- contract: 'registry',
26
- name: 'test.parthtejpal.eth',
27
- owner: accounts[0],
28
- options: { addressOrIndex: 0 },
29
- })
30
- await createSubnameTx.wait()
31
-
32
- const tx = await ENSInstance.deleteSubname(
25
+ const createSubnameTx = await ENSInstance.createSubname(
33
26
  'test.parthtejpal.eth',
34
- 'registry',
35
- { addressOrIndex: 0 },
27
+ {
28
+ contract: 'registry',
29
+ owner: accounts[0],
30
+ addressOrIndex: 0,
31
+ },
36
32
  )
33
+ await createSubnameTx.wait()
34
+
35
+ const tx = await ENSInstance.deleteSubname('test.parthtejpal.eth', {
36
+ contract: 'registry',
37
+ addressOrIndex: 0,
38
+ })
37
39
  expect(tx).toBeTruthy()
38
40
  await tx.wait()
39
41
 
40
42
  const registry = await ENSInstance.contracts!.getRegistry()!
41
- const result = await registry.owner(utils.namehash('test.parthtejpal.eth'))
43
+ const result = await registry.owner(namehash('test.parthtejpal.eth'))
42
44
  expect(result).toBe('0x0000000000000000000000000000000000000000')
43
45
  })
44
46
  it('should allow deleting a subname on the nameWrapper', async () => {
45
- const wrapNameTx = await ENSInstance.wrapName(
46
- 'parthtejpal.eth',
47
- accounts[0],
48
- )
49
- await wrapNameTx.wait()
50
- const createSubnameTx = await ENSInstance.createSubname({
51
- contract: 'nameWrapper',
52
- name: 'test.parthtejpal.eth',
53
- owner: accounts[0],
54
- options: { addressOrIndex: 0 },
47
+ const wrapNameTx = await ENSInstance.wrapName('parthtejpal.eth', {
48
+ wrappedOwner: accounts[0],
55
49
  })
56
- await createSubnameTx.wait()
57
-
58
- const tx = await ENSInstance.deleteSubname(
50
+ await wrapNameTx.wait()
51
+ const createSubnameTx = await ENSInstance.createSubname(
59
52
  'test.parthtejpal.eth',
60
- 'nameWrapper',
61
- { addressOrIndex: 0 },
53
+ {
54
+ contract: 'nameWrapper',
55
+ owner: accounts[0],
56
+ addressOrIndex: 0,
57
+ },
62
58
  )
59
+ await createSubnameTx.wait()
60
+
61
+ const tx = await ENSInstance.deleteSubname('test.parthtejpal.eth', {
62
+ contract: 'nameWrapper',
63
+ addressOrIndex: 0,
64
+ })
63
65
  expect(tx).toBeTruthy()
64
66
  await tx.wait()
65
67
 
66
68
  const nameWrapper = await ENSInstance.contracts!.getNameWrapper()!
67
- const result = await nameWrapper.ownerOf(
68
- utils.namehash('test.parthtejpal.eth'),
69
- )
69
+ const result = await nameWrapper.ownerOf(namehash('test.parthtejpal.eth'))
70
70
  expect(result).toBe('0x0000000000000000000000000000000000000000')
71
71
  })
72
72
  })
@@ -1,19 +1,16 @@
1
1
  import { ENSArgs } from '..'
2
2
 
3
3
  export default async function (
4
- {
5
- contracts,
6
- provider,
7
- transferSubname,
8
- }: ENSArgs<'contracts' | 'provider' | 'transferSubname'>,
4
+ { transferSubname }: ENSArgs<'transferSubname'>,
9
5
  name: string,
10
- contract: 'registry' | 'nameWrapper',
11
- options?: { addressOrIndex?: string | number },
6
+ {
7
+ contract,
8
+ }: {
9
+ contract: 'registry' | 'nameWrapper'
10
+ },
12
11
  ) {
13
- return transferSubname(
14
- name,
12
+ return transferSubname.populateTransaction(name, {
15
13
  contract,
16
- '0x0000000000000000000000000000000000000000',
17
- options,
18
- )
14
+ address: '0x0000000000000000000000000000000000000000',
15
+ })
19
16
  }