@ensdomains/ensjs 3.0.0-alpha.59 → 3.0.0-alpha.60
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.
|
@@ -42,7 +42,11 @@ const generateSetAddr = (namehash, coinType, address, resolver) => {
|
|
|
42
42
|
coinTypeInstance = import_address_encoder.formatsByName[coinType.toUpperCase()];
|
|
43
43
|
}
|
|
44
44
|
const inputCoinType = coinTypeInstance.coinType;
|
|
45
|
-
|
|
45
|
+
let encodedAddress = address !== "" ? coinTypeInstance.decoder(address) : "0x";
|
|
46
|
+
if (inputCoinType === 60 && encodedAddress === "0x")
|
|
47
|
+
encodedAddress = coinTypeInstance.decoder(
|
|
48
|
+
"0x0000000000000000000000000000000000000000"
|
|
49
|
+
);
|
|
46
50
|
return resolver == null ? void 0 : resolver.interface.encodeFunctionData(
|
|
47
51
|
"setAddr(bytes32,uint256,bytes)",
|
|
48
52
|
[namehash, inputCoinType, encodedAddress]
|
|
@@ -11,7 +11,11 @@ var generateSetAddr = (namehash, coinType, address, resolver) => {
|
|
|
11
11
|
coinTypeInstance = formatsByName[coinType.toUpperCase()];
|
|
12
12
|
}
|
|
13
13
|
const inputCoinType = coinTypeInstance.coinType;
|
|
14
|
-
|
|
14
|
+
let encodedAddress = address !== "" ? coinTypeInstance.decoder(address) : "0x";
|
|
15
|
+
if (inputCoinType === 60 && encodedAddress === "0x")
|
|
16
|
+
encodedAddress = coinTypeInstance.decoder(
|
|
17
|
+
"0x0000000000000000000000000000000000000000"
|
|
18
|
+
);
|
|
15
19
|
return resolver?.interface.encodeFunctionData(
|
|
16
20
|
"setAddr(bytes32,uint256,bytes)",
|
|
17
21
|
[namehash, inputCoinType, encodedAddress]
|
package/package.json
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { formatsByName } from '@ensdomains/address-encoder'
|
|
1
2
|
import { decodeFirst } from 'cbor'
|
|
2
3
|
import { BigNumber } from 'ethers'
|
|
3
4
|
import { arrayify, toUtf8String } from 'ethers/lib/utils'
|
|
@@ -145,6 +146,22 @@ describe('setRecord', () => {
|
|
|
145
146
|
// record as hex
|
|
146
147
|
expect(resultEmptyAddr).toBe('0x')
|
|
147
148
|
})
|
|
149
|
+
|
|
150
|
+
Object.keys(formatsByName).forEach((coinName) => {
|
|
151
|
+
it(`should allow an empty address record for ${coinName}`, async () => {
|
|
152
|
+
const tx = await ensInstance.setRecord('test123.eth', {
|
|
153
|
+
type: 'addr',
|
|
154
|
+
record: {
|
|
155
|
+
key: coinName,
|
|
156
|
+
value: '',
|
|
157
|
+
},
|
|
158
|
+
addressOrIndex: 1,
|
|
159
|
+
})
|
|
160
|
+
expect(tx).toBeTruthy()
|
|
161
|
+
await tx.wait()
|
|
162
|
+
})
|
|
163
|
+
})
|
|
164
|
+
|
|
148
165
|
it('should allow a contenthash record set', async () => {
|
|
149
166
|
const tx = await ensInstance.setRecord('test123.eth', {
|
|
150
167
|
type: 'contentHash',
|
|
@@ -97,4 +97,120 @@ describe('setRecords', () => {
|
|
|
97
97
|
expect(contentType.toNumber()).toBe(1)
|
|
98
98
|
expect(toUtf8String(resultABI)).toBe(JSON.stringify(dummyABI))
|
|
99
99
|
})
|
|
100
|
+
|
|
101
|
+
describe('record types', () => {
|
|
102
|
+
it('should be able to set and delete a cointype for a wrapped name', async () => {
|
|
103
|
+
const tx = await ensInstance.setRecords('wrapped.eth', {
|
|
104
|
+
records: {
|
|
105
|
+
coinTypes: [
|
|
106
|
+
{
|
|
107
|
+
key: 'ETH',
|
|
108
|
+
value: '0x42D63ae25990889E35F215bC95884039Ba354115',
|
|
109
|
+
},
|
|
110
|
+
],
|
|
111
|
+
},
|
|
112
|
+
addressOrIndex: 1,
|
|
113
|
+
})
|
|
114
|
+
expect(tx).toBeTruthy()
|
|
115
|
+
await tx.wait()
|
|
116
|
+
|
|
117
|
+
const universalResolver =
|
|
118
|
+
await ensInstance.contracts!.getUniversalResolver()!
|
|
119
|
+
const publicResolver = await ensInstance.contracts!.getPublicResolver()!
|
|
120
|
+
|
|
121
|
+
const encodedAddr = await universalResolver['resolve(bytes,bytes)'](
|
|
122
|
+
hexEncodeName('wrapped.eth'),
|
|
123
|
+
publicResolver.interface.encodeFunctionData('addr(bytes32,uint256)', [
|
|
124
|
+
namehash('wrapped.eth'),
|
|
125
|
+
'60',
|
|
126
|
+
]),
|
|
127
|
+
)
|
|
128
|
+
const [resultAddr] = publicResolver.interface.decodeFunctionResult(
|
|
129
|
+
'addr(bytes32,uint256)',
|
|
130
|
+
encodedAddr[0],
|
|
131
|
+
)
|
|
132
|
+
expect(resultAddr).toBe(
|
|
133
|
+
'0x42D63ae25990889E35F215bC95884039Ba354115'.toLowerCase(),
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
const tx2 = await ensInstance.setRecords('wrapped.eth', {
|
|
137
|
+
records: {
|
|
138
|
+
coinTypes: [
|
|
139
|
+
{
|
|
140
|
+
key: 'ETH',
|
|
141
|
+
value: '',
|
|
142
|
+
},
|
|
143
|
+
],
|
|
144
|
+
},
|
|
145
|
+
addressOrIndex: 1,
|
|
146
|
+
})
|
|
147
|
+
expect(tx2).toBeTruthy()
|
|
148
|
+
await tx2.wait()
|
|
149
|
+
|
|
150
|
+
const encodedAddr2 = await universalResolver['resolve(bytes,bytes)'](
|
|
151
|
+
hexEncodeName('wrapped.eth'),
|
|
152
|
+
publicResolver.interface.encodeFunctionData('addr(bytes32,uint256)', [
|
|
153
|
+
namehash('wrapped.eth'),
|
|
154
|
+
'60',
|
|
155
|
+
]),
|
|
156
|
+
)
|
|
157
|
+
const [resultAddr2] = publicResolver.interface.decodeFunctionResult(
|
|
158
|
+
'addr(bytes32,uint256)',
|
|
159
|
+
encodedAddr2[0],
|
|
160
|
+
)
|
|
161
|
+
expect(resultAddr2).toBe(
|
|
162
|
+
'0x0000000000000000000000000000000000000000'.toLowerCase(),
|
|
163
|
+
)
|
|
164
|
+
})
|
|
165
|
+
|
|
166
|
+
it('should be able to set and delete a contenthash for a wrapped name', async () => {
|
|
167
|
+
const tx = await ensInstance.setRecords('wrapped.eth', {
|
|
168
|
+
records: {
|
|
169
|
+
contentHash: 'ipfs://QmRAQB6YaCyidP37UdDnjFY5vQuiBrcqdyoW1CuDgwxkD4',
|
|
170
|
+
},
|
|
171
|
+
addressOrIndex: 1,
|
|
172
|
+
})
|
|
173
|
+
expect(tx).toBeTruthy()
|
|
174
|
+
await tx.wait()
|
|
175
|
+
|
|
176
|
+
const universalResolver =
|
|
177
|
+
await ensInstance.contracts!.getUniversalResolver()!
|
|
178
|
+
const publicResolver = await ensInstance.contracts!.getPublicResolver()!
|
|
179
|
+
|
|
180
|
+
const encodedData = await universalResolver['resolve(bytes,bytes)'](
|
|
181
|
+
hexEncodeName('wrapped.eth'),
|
|
182
|
+
publicResolver.interface.encodeFunctionData('contenthash', [
|
|
183
|
+
namehash('wrapped.eth'),
|
|
184
|
+
]),
|
|
185
|
+
)
|
|
186
|
+
const [resultData] = publicResolver.interface.decodeFunctionResult(
|
|
187
|
+
'contenthash',
|
|
188
|
+
encodedData[0],
|
|
189
|
+
)
|
|
190
|
+
expect(resultData).toBe(
|
|
191
|
+
'0xe3010170122029f2d17be6139079dc48696d1f582a8530eb9805b561eda517e22a892c7e3f1f'.toLowerCase(),
|
|
192
|
+
)
|
|
193
|
+
|
|
194
|
+
const tx2 = await ensInstance.setRecords('wrapped.eth', {
|
|
195
|
+
records: {
|
|
196
|
+
contentHash: '',
|
|
197
|
+
},
|
|
198
|
+
addressOrIndex: 1,
|
|
199
|
+
})
|
|
200
|
+
expect(tx2).toBeTruthy()
|
|
201
|
+
await tx2.wait()
|
|
202
|
+
|
|
203
|
+
const encodedAddr2 = await universalResolver['resolve(bytes,bytes)'](
|
|
204
|
+
hexEncodeName('wrapped.eth'),
|
|
205
|
+
publicResolver.interface.encodeFunctionData('contenthash', [
|
|
206
|
+
namehash('wrapped.eth'),
|
|
207
|
+
]),
|
|
208
|
+
)
|
|
209
|
+
const [resultAddr2] = publicResolver.interface.decodeFunctionResult(
|
|
210
|
+
'contenthash',
|
|
211
|
+
encodedAddr2[0],
|
|
212
|
+
)
|
|
213
|
+
expect(resultAddr2).toBe('0x'.toLowerCase())
|
|
214
|
+
})
|
|
215
|
+
})
|
|
100
216
|
})
|
|
@@ -38,8 +38,12 @@ export const generateSetAddr = (
|
|
|
38
38
|
coinTypeInstance = formatsByName[coinType.toUpperCase()]
|
|
39
39
|
}
|
|
40
40
|
const inputCoinType = coinTypeInstance.coinType
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
let encodedAddress = address !== '' ? coinTypeInstance.decoder(address) : '0x'
|
|
42
|
+
if (inputCoinType === 60 && encodedAddress === '0x')
|
|
43
|
+
encodedAddress = coinTypeInstance.decoder(
|
|
44
|
+
'0x0000000000000000000000000000000000000000',
|
|
45
|
+
)
|
|
46
|
+
|
|
43
47
|
return resolver?.interface.encodeFunctionData(
|
|
44
48
|
'setAddr(bytes32,uint256,bytes)',
|
|
45
49
|
[namehash, inputCoinType, encodedAddress],
|