@ensdomains/ensjs 3.0.0-alpha.25 → 3.0.0-alpha.27
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/README.md +1 -1
- package/dist/cjs/contracts/getContractAddress.js +4 -4
- package/dist/cjs/functions/batchWrappers.js +41 -8
- package/dist/cjs/functions/deleteSubname.js +2 -5
- package/dist/cjs/functions/getName.js +2 -2
- package/dist/cjs/functions/getOwner.js +4 -4
- package/dist/cjs/functions/getProfile.js +117 -87
- package/dist/cjs/generated/factories/NameWrapper__factory.js +13 -0
- package/dist/cjs/generated/factories/UniversalResolver__factory.js +277 -0
- package/dist/cjs/utils/ccip.js +128 -0
- package/dist/cjs/utils/singleCall.js +1 -1
- package/dist/esm/contracts/getContractAddress.mjs +4 -4
- package/dist/esm/functions/batchWrappers.mjs +35 -8
- package/dist/esm/functions/deleteSubname.mjs +2 -5
- package/dist/esm/functions/getName.mjs +2 -2
- package/dist/esm/functions/getOwner.mjs +4 -4
- package/dist/esm/functions/getProfile.mjs +117 -87
- package/dist/esm/generated/factories/NameWrapper__factory.mjs +13 -0
- package/dist/esm/generated/factories/UniversalResolver__factory.mjs +277 -0
- package/dist/esm/utils/ccip.mjs +114 -0
- package/dist/esm/utils/singleCall.mjs +1 -1
- package/dist/types/functions/batchWrappers.d.ts +58 -1
- package/dist/types/functions/getProfile.d.ts +6 -0
- package/dist/types/generated/NameWrapper.d.ts +9 -1
- package/dist/types/generated/UniversalResolver.d.ts +123 -21
- package/dist/types/index.d.ts +64 -2
- package/dist/types/utils/ccip.d.ts +3 -0
- package/package.json +3 -3
- package/src/contracts/getContractAddress.ts +4 -4
- package/src/functions/batchWrappers.ts +40 -9
- package/src/functions/deleteSubname.test.ts +21 -1
- package/src/functions/deleteSubname.ts +2 -6
- package/src/functions/getName.ts +2 -2
- package/src/functions/getOwner.ts +4 -2
- package/src/functions/getProfile-ccip.test.ts +29 -0
- package/src/functions/getProfile.test.ts +1 -1
- package/src/functions/getProfile.ts +160 -100
- package/src/functions/setName.test.ts +6 -2
- package/src/functions/setRecord.test.ts +3 -3
- package/src/functions/setRecords.test.ts +2 -2
- package/src/generated/NameWrapper.ts +14 -0
- package/src/generated/UniversalResolver.ts +382 -19
- package/src/generated/factories/NameWrapper__factory.ts +13 -0
- package/src/generated/factories/UniversalResolver__factory.ts +277 -0
- package/src/index.ts +1 -1
- package/src/utils/ccip.ts +148 -0
- package/src/utils/singleCall.ts +1 -1
|
@@ -17,6 +17,11 @@ const _abi = [
|
|
|
17
17
|
name: "_registry",
|
|
18
18
|
type: "address",
|
|
19
19
|
},
|
|
20
|
+
{
|
|
21
|
+
internalType: "string[]",
|
|
22
|
+
name: "_urls",
|
|
23
|
+
type: "string[]",
|
|
24
|
+
},
|
|
20
25
|
],
|
|
21
26
|
stateMutability: "nonpayable",
|
|
22
27
|
type: "constructor",
|
|
@@ -52,6 +57,69 @@ const _abi = [
|
|
|
52
57
|
name: "OffchainLookup",
|
|
53
58
|
type: "error",
|
|
54
59
|
},
|
|
60
|
+
{
|
|
61
|
+
inputs: [
|
|
62
|
+
{
|
|
63
|
+
internalType: "bytes",
|
|
64
|
+
name: "name",
|
|
65
|
+
type: "bytes",
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
internalType: "bytes",
|
|
69
|
+
name: "data",
|
|
70
|
+
type: "bytes",
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
internalType: "string[]",
|
|
74
|
+
name: "gateways",
|
|
75
|
+
type: "string[]",
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
internalType: "bytes4",
|
|
79
|
+
name: "callbackFunction",
|
|
80
|
+
type: "bytes4",
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
internalType: "bytes",
|
|
84
|
+
name: "metaData",
|
|
85
|
+
type: "bytes",
|
|
86
|
+
},
|
|
87
|
+
],
|
|
88
|
+
name: "_resolveSingle",
|
|
89
|
+
outputs: [
|
|
90
|
+
{
|
|
91
|
+
internalType: "bytes",
|
|
92
|
+
name: "",
|
|
93
|
+
type: "bytes",
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
internalType: "address",
|
|
97
|
+
name: "",
|
|
98
|
+
type: "address",
|
|
99
|
+
},
|
|
100
|
+
],
|
|
101
|
+
stateMutability: "view",
|
|
102
|
+
type: "function",
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
inputs: [
|
|
106
|
+
{
|
|
107
|
+
internalType: "uint256",
|
|
108
|
+
name: "",
|
|
109
|
+
type: "uint256",
|
|
110
|
+
},
|
|
111
|
+
],
|
|
112
|
+
name: "batchGatewayURLs",
|
|
113
|
+
outputs: [
|
|
114
|
+
{
|
|
115
|
+
internalType: "string",
|
|
116
|
+
name: "",
|
|
117
|
+
type: "string",
|
|
118
|
+
},
|
|
119
|
+
],
|
|
120
|
+
stateMutability: "view",
|
|
121
|
+
type: "function",
|
|
122
|
+
},
|
|
55
123
|
{
|
|
56
124
|
inputs: [
|
|
57
125
|
{
|
|
@@ -89,6 +157,103 @@ const _abi = [
|
|
|
89
157
|
stateMutability: "view",
|
|
90
158
|
type: "function",
|
|
91
159
|
},
|
|
160
|
+
{
|
|
161
|
+
inputs: [
|
|
162
|
+
{
|
|
163
|
+
internalType: "bytes",
|
|
164
|
+
name: "name",
|
|
165
|
+
type: "bytes",
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
internalType: "bytes",
|
|
169
|
+
name: "data",
|
|
170
|
+
type: "bytes",
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
internalType: "string[]",
|
|
174
|
+
name: "gateways",
|
|
175
|
+
type: "string[]",
|
|
176
|
+
},
|
|
177
|
+
],
|
|
178
|
+
name: "resolve",
|
|
179
|
+
outputs: [
|
|
180
|
+
{
|
|
181
|
+
internalType: "bytes",
|
|
182
|
+
name: "",
|
|
183
|
+
type: "bytes",
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
internalType: "address",
|
|
187
|
+
name: "",
|
|
188
|
+
type: "address",
|
|
189
|
+
},
|
|
190
|
+
],
|
|
191
|
+
stateMutability: "view",
|
|
192
|
+
type: "function",
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
inputs: [
|
|
196
|
+
{
|
|
197
|
+
internalType: "bytes",
|
|
198
|
+
name: "name",
|
|
199
|
+
type: "bytes",
|
|
200
|
+
},
|
|
201
|
+
{
|
|
202
|
+
internalType: "bytes[]",
|
|
203
|
+
name: "data",
|
|
204
|
+
type: "bytes[]",
|
|
205
|
+
},
|
|
206
|
+
],
|
|
207
|
+
name: "resolve",
|
|
208
|
+
outputs: [
|
|
209
|
+
{
|
|
210
|
+
internalType: "bytes[]",
|
|
211
|
+
name: "",
|
|
212
|
+
type: "bytes[]",
|
|
213
|
+
},
|
|
214
|
+
{
|
|
215
|
+
internalType: "address",
|
|
216
|
+
name: "",
|
|
217
|
+
type: "address",
|
|
218
|
+
},
|
|
219
|
+
],
|
|
220
|
+
stateMutability: "view",
|
|
221
|
+
type: "function",
|
|
222
|
+
},
|
|
223
|
+
{
|
|
224
|
+
inputs: [
|
|
225
|
+
{
|
|
226
|
+
internalType: "bytes",
|
|
227
|
+
name: "name",
|
|
228
|
+
type: "bytes",
|
|
229
|
+
},
|
|
230
|
+
{
|
|
231
|
+
internalType: "bytes[]",
|
|
232
|
+
name: "data",
|
|
233
|
+
type: "bytes[]",
|
|
234
|
+
},
|
|
235
|
+
{
|
|
236
|
+
internalType: "string[]",
|
|
237
|
+
name: "gateways",
|
|
238
|
+
type: "string[]",
|
|
239
|
+
},
|
|
240
|
+
],
|
|
241
|
+
name: "resolve",
|
|
242
|
+
outputs: [
|
|
243
|
+
{
|
|
244
|
+
internalType: "bytes[]",
|
|
245
|
+
name: "",
|
|
246
|
+
type: "bytes[]",
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
internalType: "address",
|
|
250
|
+
name: "",
|
|
251
|
+
type: "address",
|
|
252
|
+
},
|
|
253
|
+
],
|
|
254
|
+
stateMutability: "view",
|
|
255
|
+
type: "function",
|
|
256
|
+
},
|
|
92
257
|
{
|
|
93
258
|
inputs: [
|
|
94
259
|
{
|
|
@@ -132,12 +297,85 @@ const _abi = [
|
|
|
132
297
|
},
|
|
133
298
|
],
|
|
134
299
|
name: "resolveCallback",
|
|
300
|
+
outputs: [
|
|
301
|
+
{
|
|
302
|
+
internalType: "bytes[]",
|
|
303
|
+
name: "",
|
|
304
|
+
type: "bytes[]",
|
|
305
|
+
},
|
|
306
|
+
{
|
|
307
|
+
internalType: "address",
|
|
308
|
+
name: "",
|
|
309
|
+
type: "address",
|
|
310
|
+
},
|
|
311
|
+
],
|
|
312
|
+
stateMutability: "nonpayable",
|
|
313
|
+
type: "function",
|
|
314
|
+
},
|
|
315
|
+
{
|
|
316
|
+
inputs: [
|
|
317
|
+
{
|
|
318
|
+
internalType: "bytes",
|
|
319
|
+
name: "response",
|
|
320
|
+
type: "bytes",
|
|
321
|
+
},
|
|
322
|
+
{
|
|
323
|
+
internalType: "bytes",
|
|
324
|
+
name: "extraData",
|
|
325
|
+
type: "bytes",
|
|
326
|
+
},
|
|
327
|
+
],
|
|
328
|
+
name: "resolveSingleCallback",
|
|
135
329
|
outputs: [
|
|
136
330
|
{
|
|
137
331
|
internalType: "bytes",
|
|
138
332
|
name: "",
|
|
139
333
|
type: "bytes",
|
|
140
334
|
},
|
|
335
|
+
{
|
|
336
|
+
internalType: "address",
|
|
337
|
+
name: "",
|
|
338
|
+
type: "address",
|
|
339
|
+
},
|
|
340
|
+
],
|
|
341
|
+
stateMutability: "nonpayable",
|
|
342
|
+
type: "function",
|
|
343
|
+
},
|
|
344
|
+
{
|
|
345
|
+
inputs: [
|
|
346
|
+
{
|
|
347
|
+
internalType: "bytes",
|
|
348
|
+
name: "reverseName",
|
|
349
|
+
type: "bytes",
|
|
350
|
+
},
|
|
351
|
+
{
|
|
352
|
+
internalType: "string[]",
|
|
353
|
+
name: "gateways",
|
|
354
|
+
type: "string[]",
|
|
355
|
+
},
|
|
356
|
+
],
|
|
357
|
+
name: "reverse",
|
|
358
|
+
outputs: [
|
|
359
|
+
{
|
|
360
|
+
internalType: "string",
|
|
361
|
+
name: "",
|
|
362
|
+
type: "string",
|
|
363
|
+
},
|
|
364
|
+
{
|
|
365
|
+
internalType: "address",
|
|
366
|
+
name: "",
|
|
367
|
+
type: "address",
|
|
368
|
+
},
|
|
369
|
+
{
|
|
370
|
+
internalType: "address",
|
|
371
|
+
name: "",
|
|
372
|
+
type: "address",
|
|
373
|
+
},
|
|
374
|
+
{
|
|
375
|
+
internalType: "address",
|
|
376
|
+
name: "",
|
|
377
|
+
type: "address",
|
|
378
|
+
},
|
|
141
379
|
],
|
|
142
380
|
stateMutability: "view",
|
|
143
381
|
type: "function",
|
|
@@ -176,6 +414,45 @@ const _abi = [
|
|
|
176
414
|
stateMutability: "view",
|
|
177
415
|
type: "function",
|
|
178
416
|
},
|
|
417
|
+
{
|
|
418
|
+
inputs: [
|
|
419
|
+
{
|
|
420
|
+
internalType: "bytes",
|
|
421
|
+
name: "response",
|
|
422
|
+
type: "bytes",
|
|
423
|
+
},
|
|
424
|
+
{
|
|
425
|
+
internalType: "bytes",
|
|
426
|
+
name: "extraData",
|
|
427
|
+
type: "bytes",
|
|
428
|
+
},
|
|
429
|
+
],
|
|
430
|
+
name: "reverseCallback",
|
|
431
|
+
outputs: [
|
|
432
|
+
{
|
|
433
|
+
internalType: "string",
|
|
434
|
+
name: "",
|
|
435
|
+
type: "string",
|
|
436
|
+
},
|
|
437
|
+
{
|
|
438
|
+
internalType: "address",
|
|
439
|
+
name: "",
|
|
440
|
+
type: "address",
|
|
441
|
+
},
|
|
442
|
+
{
|
|
443
|
+
internalType: "address",
|
|
444
|
+
name: "",
|
|
445
|
+
type: "address",
|
|
446
|
+
},
|
|
447
|
+
{
|
|
448
|
+
internalType: "address",
|
|
449
|
+
name: "",
|
|
450
|
+
type: "address",
|
|
451
|
+
},
|
|
452
|
+
],
|
|
453
|
+
stateMutability: "nonpayable",
|
|
454
|
+
type: "function",
|
|
455
|
+
},
|
|
179
456
|
{
|
|
180
457
|
inputs: [
|
|
181
458
|
{
|
package/src/index.ts
CHANGED
|
@@ -43,8 +43,8 @@ import type setName from './functions/setName'
|
|
|
43
43
|
import type setRecord from './functions/setRecord'
|
|
44
44
|
import type setRecords from './functions/setRecords'
|
|
45
45
|
import type setResolver from './functions/setResolver'
|
|
46
|
-
import type transferName from './functions/transferName'
|
|
47
46
|
import type transferController from './functions/transferController'
|
|
47
|
+
import type transferName from './functions/transferName'
|
|
48
48
|
import type transferSubname from './functions/transferSubname'
|
|
49
49
|
import type unwrapName from './functions/unwrapName'
|
|
50
50
|
import type wrapName from './functions/wrapName'
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import type { BaseProvider, TransactionRequest } from '@ethersproject/providers'
|
|
2
|
+
import { BigNumber, Transaction } from 'ethers'
|
|
3
|
+
import {
|
|
4
|
+
arrayify,
|
|
5
|
+
BytesLike,
|
|
6
|
+
hexConcat,
|
|
7
|
+
hexDataSlice,
|
|
8
|
+
toUtf8String,
|
|
9
|
+
} from 'ethers/lib/utils'
|
|
10
|
+
|
|
11
|
+
function bytesPad(value: Uint8Array): Uint8Array {
|
|
12
|
+
if (value.length % 32 === 0) {
|
|
13
|
+
return value
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const result = new Uint8Array(Math.ceil(value.length / 32) * 32)
|
|
17
|
+
result.set(value)
|
|
18
|
+
return result
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function numPad(value: number): Uint8Array {
|
|
22
|
+
const result = arrayify(value)
|
|
23
|
+
if (result.length > 32) {
|
|
24
|
+
throw new Error('internal; should not happen')
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const padded = new Uint8Array(32)
|
|
28
|
+
padded.set(result, 32 - result.length)
|
|
29
|
+
return padded
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// ABI Encodes a series of (bytes, bytes, ...)
|
|
33
|
+
function encodeBytes(datas: Array<BytesLike>) {
|
|
34
|
+
const result: Array<Uint8Array> = []
|
|
35
|
+
|
|
36
|
+
let byteCount = 0
|
|
37
|
+
|
|
38
|
+
// Add place-holders for pointers as we add items
|
|
39
|
+
for (let i = 0; i < datas.length; i += 1) {
|
|
40
|
+
result.push(new Uint8Array(0))
|
|
41
|
+
byteCount += 32
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
for (let i = 0; i < datas.length; i += 1) {
|
|
45
|
+
const data = arrayify(datas[i])
|
|
46
|
+
|
|
47
|
+
// Update the bytes offset
|
|
48
|
+
result[i] = numPad(byteCount)
|
|
49
|
+
|
|
50
|
+
// The length and padded value of data
|
|
51
|
+
result.push(numPad(data.length))
|
|
52
|
+
result.push(bytesPad(data))
|
|
53
|
+
byteCount += 32 + Math.ceil(data.length / 32) * 32
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return hexConcat(result)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function _parseBytes(result: string, start: number): null | string {
|
|
60
|
+
if (result === '0x') {
|
|
61
|
+
return null
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const offset = BigNumber.from(
|
|
65
|
+
hexDataSlice(result, start, start + 32),
|
|
66
|
+
).toNumber()
|
|
67
|
+
const length = BigNumber.from(
|
|
68
|
+
hexDataSlice(result, offset, offset + 32),
|
|
69
|
+
).toNumber()
|
|
70
|
+
|
|
71
|
+
return hexDataSlice(result, offset + 32, offset + 32 + length)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function _parseString(result: string, start: number): null | string {
|
|
75
|
+
try {
|
|
76
|
+
const bytes = _parseBytes(result, start)
|
|
77
|
+
if (bytes == null) return null
|
|
78
|
+
return toUtf8String(bytes)
|
|
79
|
+
} catch (error) {}
|
|
80
|
+
return null
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const ccipLookup = async (
|
|
84
|
+
provider: BaseProvider,
|
|
85
|
+
transaction: TransactionRequest,
|
|
86
|
+
result: string,
|
|
87
|
+
) => {
|
|
88
|
+
const txSender = transaction.to!
|
|
89
|
+
try {
|
|
90
|
+
const data = hexDataSlice(result, 4)
|
|
91
|
+
|
|
92
|
+
// Check the sender of the OffchainLookup matches the transaction
|
|
93
|
+
const sender = hexDataSlice(data, 0, 32)
|
|
94
|
+
if (!BigNumber.from(sender).eq(txSender)) {
|
|
95
|
+
throw new Error('CCIP Read sender did not match')
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Read the URLs from the response
|
|
99
|
+
const urls: Array<string> = []
|
|
100
|
+
const urlsOffset = BigNumber.from(hexDataSlice(data, 32, 64)).toNumber()
|
|
101
|
+
const urlsLength = BigNumber.from(
|
|
102
|
+
hexDataSlice(data, urlsOffset, urlsOffset + 32),
|
|
103
|
+
).toNumber()
|
|
104
|
+
const urlsData = hexDataSlice(data, urlsOffset + 32)
|
|
105
|
+
for (let u = 0; u < urlsLength; u += 1) {
|
|
106
|
+
const url = _parseString(urlsData, u * 32)
|
|
107
|
+
if (url == null) {
|
|
108
|
+
throw new Error('CCIP Read contained corrupt URL string')
|
|
109
|
+
}
|
|
110
|
+
urls.push(url)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Get the CCIP calldata to forward
|
|
114
|
+
const calldata = _parseBytes(data, 64)
|
|
115
|
+
|
|
116
|
+
// Get the callbackSelector (bytes4)
|
|
117
|
+
if (!BigNumber.from(hexDataSlice(data, 100, 128)).isZero()) {
|
|
118
|
+
throw new Error('CCIP Read callback selected included junk')
|
|
119
|
+
}
|
|
120
|
+
const callbackSelector = hexDataSlice(data, 96, 100)
|
|
121
|
+
|
|
122
|
+
// Get the extra data to send back to the contract as context
|
|
123
|
+
const extraData = _parseBytes(data, 128)
|
|
124
|
+
|
|
125
|
+
const ccipResult = await provider.ccipReadFetch(
|
|
126
|
+
<Transaction>transaction,
|
|
127
|
+
calldata!,
|
|
128
|
+
urls,
|
|
129
|
+
)
|
|
130
|
+
if (ccipResult == null) {
|
|
131
|
+
throw new Error('CCIP Read disabled or provided no URLs')
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const tx = {
|
|
135
|
+
to: sender,
|
|
136
|
+
data: hexConcat([
|
|
137
|
+
callbackSelector,
|
|
138
|
+
encodeBytes([ccipResult, extraData!]),
|
|
139
|
+
]),
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return await provider._call(tx, 'latest', 1)
|
|
143
|
+
} catch (error) {
|
|
144
|
+
console.error(error)
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export default ccipLookup
|
package/src/utils/singleCall.ts
CHANGED