@ensdomains/ensjs 3.0.0-alpha.6 → 3.0.0-alpha.9
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/GqlManager.d.ts +3 -0
- package/dist/cjs/GqlManager.js +62 -2
- package/dist/cjs/functions/getProfile.d.ts +4 -1
- package/dist/cjs/functions/getProfile.js +62 -18
- package/dist/cjs/functions/getRecords.d.ts +1 -0
- package/dist/cjs/functions/setRecord.d.ts +18 -0
- package/dist/cjs/functions/setRecord.js +27 -0
- package/dist/cjs/index.d.ts +7 -2
- package/dist/cjs/index.js +6 -1
- package/dist/cjs/utils/labels.js +4 -3
- package/dist/cjs/utils/normalise.d.ts +1 -1
- package/dist/cjs/utils/normalise.js +10 -3
- package/dist/cjs/utils/recordHelpers.d.ts +3 -0
- package/dist/cjs/utils/recordHelpers.js +42 -15
- package/dist/esm/GqlManager.d.ts +3 -0
- package/dist/esm/GqlManager.js +58 -2
- package/dist/esm/functions/getProfile.d.ts +4 -1
- package/dist/esm/functions/getProfile.js +62 -18
- package/dist/esm/functions/getRecords.d.ts +1 -0
- package/dist/esm/functions/setRecord.d.ts +18 -0
- package/dist/esm/functions/setRecord.js +24 -0
- package/dist/esm/index.d.ts +7 -2
- package/dist/esm/index.js +6 -1
- package/dist/esm/utils/labels.js +4 -3
- package/dist/esm/utils/normalise.d.ts +1 -1
- package/dist/esm/utils/normalise.js +10 -3
- package/dist/esm/utils/recordHelpers.d.ts +3 -0
- package/dist/esm/utils/recordHelpers.js +40 -14
- package/package.json +7 -5
- package/src/GqlManager.test.ts +170 -0
- package/src/GqlManager.ts +67 -2
- package/src/functions/getProfile.test.ts +16 -1
- package/src/functions/getProfile.ts +82 -19
- package/src/functions/getRecords.ts +1 -0
- package/src/functions/setRecord.test.ts +100 -0
- package/src/functions/setRecord.ts +63 -0
- package/src/functions/setRecords.test.ts +2 -2
- package/src/index.ts +8 -1
- package/src/utils/labels.ts +5 -3
- package/src/utils/normalise.ts +10 -4
- package/src/utils/recordHelpers.ts +52 -18
package/dist/cjs/GqlManager.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
export declare const enter: (node: any) => any;
|
|
2
|
+
export declare const requestMiddleware: (visit: any, parse: any) => (request: any) => any;
|
|
3
|
+
export declare const responseMiddleware: (traverse: any) => (response: any) => any;
|
|
1
4
|
export default class GqlManager {
|
|
2
5
|
gql: any;
|
|
3
6
|
client?: any | null;
|
package/dist/cjs/GqlManager.js
CHANGED
|
@@ -23,13 +23,73 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.responseMiddleware = exports.requestMiddleware = exports.enter = void 0;
|
|
27
|
+
// @ts-nocheck
|
|
28
|
+
const normalise_1 = require("./utils/normalise");
|
|
29
|
+
const generateSelection = (selection) => ({
|
|
30
|
+
kind: 'Field',
|
|
31
|
+
name: {
|
|
32
|
+
kind: 'Name',
|
|
33
|
+
value: selection,
|
|
34
|
+
},
|
|
35
|
+
arguments: [],
|
|
36
|
+
directives: [],
|
|
37
|
+
alias: undefined,
|
|
38
|
+
selectionSet: undefined,
|
|
39
|
+
});
|
|
40
|
+
const enter = (node) => {
|
|
41
|
+
if (node.kind === 'SelectionSet') {
|
|
42
|
+
const id = node.selections.find((x) => x.name && x.name.value === 'id');
|
|
43
|
+
const name = node.selections.find((x) => x.name && x.name.value === 'name');
|
|
44
|
+
if (!id && name) {
|
|
45
|
+
node.selections = [...node.selections, generateSelection('id')];
|
|
46
|
+
return node;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
exports.enter = enter;
|
|
51
|
+
const requestMiddleware = (visit, parse) => (request) => {
|
|
52
|
+
const requestBody = JSON.parse(request.body);
|
|
53
|
+
const rawQuery = requestBody.query;
|
|
54
|
+
const parsedQuery = parse(rawQuery);
|
|
55
|
+
const updatedQuery = visit(parsedQuery, { enter: exports.enter });
|
|
56
|
+
const updatedBody = { ...requestBody, query: updatedQuery.loc.source.body };
|
|
57
|
+
return {
|
|
58
|
+
...request,
|
|
59
|
+
body: JSON.stringify(updatedBody),
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
exports.requestMiddleware = requestMiddleware;
|
|
63
|
+
const responseMiddleware = (traverse) => (response) => {
|
|
64
|
+
traverse(response).forEach(function (responseItem) {
|
|
65
|
+
if (responseItem instanceof Object && responseItem.name) {
|
|
66
|
+
//Name already in hashed form
|
|
67
|
+
if (responseItem.name && responseItem.name.includes('[')) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
const hashedName = (0, normalise_1.namehash)(responseItem.name);
|
|
71
|
+
if (responseItem.id !== hashedName) {
|
|
72
|
+
this.update({ ...responseItem, name: hashedName, invalidName: true });
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
return response;
|
|
77
|
+
};
|
|
78
|
+
exports.responseMiddleware = responseMiddleware;
|
|
26
79
|
class GqlManager {
|
|
27
80
|
gql = () => null;
|
|
28
81
|
client = null;
|
|
29
82
|
setUrl = async (url) => {
|
|
30
83
|
if (url) {
|
|
31
|
-
const imported = await Promise.
|
|
32
|
-
|
|
84
|
+
const [imported, traverse, { visit, parse }] = await Promise.all([
|
|
85
|
+
Promise.resolve().then(() => __importStar(require('graphql-request'))),
|
|
86
|
+
Promise.resolve().then(() => __importStar(require('traverse'))),
|
|
87
|
+
Promise.resolve().then(() => __importStar(require('graphql/language'))),
|
|
88
|
+
]);
|
|
89
|
+
this.client = new imported.GraphQLClient(url, {
|
|
90
|
+
requestMiddleware: (0, exports.requestMiddleware)(visit, parse),
|
|
91
|
+
responseMiddleware: (0, exports.responseMiddleware)(traverse.default),
|
|
92
|
+
});
|
|
33
93
|
this.gql = imported.gql;
|
|
34
94
|
}
|
|
35
95
|
else {
|
|
@@ -26,5 +26,8 @@ declare type ProfileOptions = {
|
|
|
26
26
|
texts?: boolean | string[];
|
|
27
27
|
coinTypes?: boolean | string[];
|
|
28
28
|
};
|
|
29
|
-
|
|
29
|
+
declare type InputProfileOptions = ProfileOptions & {
|
|
30
|
+
resolverAddress?: string;
|
|
31
|
+
};
|
|
32
|
+
export default function ({ contracts, gqlInstance, getName, _getAddr, _getContentHash, _getText, resolverMulticallWrapper, multicallWrapper, }: ENSArgs<'contracts' | 'gqlInstance' | 'getName' | '_getText' | '_getAddr' | '_getContentHash' | 'resolverMulticallWrapper' | 'multicallWrapper'>, nameOrAddress: string, options?: InputProfileOptions): Promise<ResolvedProfile | undefined>;
|
|
30
33
|
export {};
|
|
@@ -4,6 +4,7 @@ const address_encoder_1 = require("@ensdomains/address-encoder");
|
|
|
4
4
|
const ethers_1 = require("ethers");
|
|
5
5
|
const contentHash_1 = require("../utils/contentHash");
|
|
6
6
|
const hexEncodedName_1 = require("../utils/hexEncodedName");
|
|
7
|
+
const normalise_1 = require("../utils/normalise");
|
|
7
8
|
const validation_1 = require("../utils/validation");
|
|
8
9
|
const makeMulticallData = async ({ _getAddr, _getContentHash, _getText, resolverMulticallWrapper, }, name, options) => {
|
|
9
10
|
let calls = [];
|
|
@@ -49,13 +50,19 @@ const fetchWithoutResolverMulticall = async ({ multicallWrapper }, calls, resolv
|
|
|
49
50
|
}));
|
|
50
51
|
return (await multicallWrapper(callsWithResolver)).map((x) => x[1]);
|
|
51
52
|
};
|
|
52
|
-
const getDataForName = async ({ contracts, _getAddr, _getContentHash, _getText, resolverMulticallWrapper, multicallWrapper, }, name, options, fallbackResolver) => {
|
|
53
|
+
const getDataForName = async ({ contracts, _getAddr, _getContentHash, _getText, resolverMulticallWrapper, multicallWrapper, }, name, options, fallbackResolver, specificResolver) => {
|
|
53
54
|
const universalResolver = await contracts?.getUniversalResolver();
|
|
54
55
|
const { data, calls } = await makeMulticallData({ _getAddr, _getContentHash, _getText, resolverMulticallWrapper }, name, options);
|
|
55
56
|
let resolvedData;
|
|
56
57
|
let useFallbackResolver = false;
|
|
57
58
|
try {
|
|
58
|
-
|
|
59
|
+
if (specificResolver) {
|
|
60
|
+
const publicResolver = await contracts?.getPublicResolver(undefined, specificResolver);
|
|
61
|
+
resolvedData = await publicResolver?.callStatic.multicall(calls.map((x) => x.data));
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
resolvedData = await universalResolver?.resolve((0, hexEncodedName_1.hexEncodeName)(name), data);
|
|
65
|
+
}
|
|
59
66
|
}
|
|
60
67
|
catch {
|
|
61
68
|
useFallbackResolver = true;
|
|
@@ -63,12 +70,18 @@ const getDataForName = async ({ contracts, _getAddr, _getContentHash, _getText,
|
|
|
63
70
|
let resolverAddress;
|
|
64
71
|
let recordData;
|
|
65
72
|
if (useFallbackResolver) {
|
|
66
|
-
resolverAddress = fallbackResolver;
|
|
73
|
+
resolverAddress = specificResolver || fallbackResolver;
|
|
67
74
|
recordData = await fetchWithoutResolverMulticall({ multicallWrapper }, calls, resolverAddress);
|
|
68
75
|
}
|
|
69
76
|
else {
|
|
70
|
-
resolverAddress = resolvedData['1'];
|
|
71
|
-
|
|
77
|
+
resolverAddress = specificResolver || resolvedData['1'];
|
|
78
|
+
if (specificResolver) {
|
|
79
|
+
recordData = resolvedData;
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
;
|
|
83
|
+
[recordData] = await resolverMulticallWrapper.decode(resolvedData['0']);
|
|
84
|
+
}
|
|
72
85
|
}
|
|
73
86
|
const matchAddress = recordData[calls.findIndex((x) => x.key === '60')];
|
|
74
87
|
return {
|
|
@@ -160,10 +173,10 @@ const formatRecords = async ({ _getText, _getAddr, _getContentHash, }, data, cal
|
|
|
160
173
|
}
|
|
161
174
|
return returnedResponse;
|
|
162
175
|
};
|
|
163
|
-
const graphFetch = async ({ gqlInstance }, name, wantedRecords) => {
|
|
176
|
+
const graphFetch = async ({ gqlInstance }, name, wantedRecords, resolverAddress) => {
|
|
164
177
|
const query = gqlInstance.gql `
|
|
165
|
-
query getRecords($
|
|
166
|
-
|
|
178
|
+
query getRecords($id: String!) {
|
|
179
|
+
domain(id: $id) {
|
|
167
180
|
isMigrated
|
|
168
181
|
createdAt
|
|
169
182
|
resolver {
|
|
@@ -177,12 +190,39 @@ const graphFetch = async ({ gqlInstance }, name, wantedRecords) => {
|
|
|
177
190
|
}
|
|
178
191
|
}
|
|
179
192
|
}
|
|
193
|
+
`;
|
|
194
|
+
const customResolverQuery = gqlInstance.gql `
|
|
195
|
+
query getRecordsWithCustomResolver($id: String!, $resolverId: String!) {
|
|
196
|
+
domain(id: $id) {
|
|
197
|
+
isMigrated
|
|
198
|
+
createdAt
|
|
199
|
+
}
|
|
200
|
+
resolver(id: $resolverId) {
|
|
201
|
+
texts
|
|
202
|
+
coinTypes
|
|
203
|
+
contentHash
|
|
204
|
+
addr {
|
|
205
|
+
id
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
180
209
|
`;
|
|
181
210
|
const client = gqlInstance.client;
|
|
182
|
-
const
|
|
183
|
-
|
|
211
|
+
const id = (0, normalise_1.namehash)(name);
|
|
212
|
+
let domain;
|
|
213
|
+
let resolverResponse;
|
|
214
|
+
if (!resolverAddress) {
|
|
215
|
+
;
|
|
216
|
+
({ domain } = await client.request(query, { id }));
|
|
217
|
+
resolverResponse = domain?.resolver;
|
|
218
|
+
}
|
|
219
|
+
else {
|
|
220
|
+
const resolverId = `${resolverAddress}-${id}`;
|
|
221
|
+
({ resolver: resolverResponse, domain } = await client.request(customResolverQuery, { id, resolverId }));
|
|
222
|
+
}
|
|
223
|
+
if (!domain)
|
|
184
224
|
return;
|
|
185
|
-
const
|
|
225
|
+
const { isMigrated, createdAt } = domain;
|
|
186
226
|
let returnedRecords = {};
|
|
187
227
|
if (!resolverResponse)
|
|
188
228
|
return { isMigrated, createdAt };
|
|
@@ -190,7 +230,7 @@ const graphFetch = async ({ gqlInstance }, name, wantedRecords) => {
|
|
|
190
230
|
return {
|
|
191
231
|
isMigrated,
|
|
192
232
|
createdAt,
|
|
193
|
-
graphResolverAddress: resolverResponse.address,
|
|
233
|
+
graphResolverAddress: resolverResponse.address || resolverAddress,
|
|
194
234
|
};
|
|
195
235
|
Object.keys(wantedRecords).forEach((key) => {
|
|
196
236
|
const data = wantedRecords[key];
|
|
@@ -207,18 +247,22 @@ const graphFetch = async ({ gqlInstance }, name, wantedRecords) => {
|
|
|
207
247
|
...returnedRecords,
|
|
208
248
|
isMigrated,
|
|
209
249
|
createdAt,
|
|
210
|
-
graphResolverAddress: resolverResponse.address,
|
|
250
|
+
graphResolverAddress: resolverResponse.address || resolverAddress,
|
|
211
251
|
};
|
|
212
252
|
};
|
|
213
253
|
const getProfileFromName = async ({ contracts, gqlInstance, _getAddr, _getContentHash, _getText, resolverMulticallWrapper, multicallWrapper, }, name, options) => {
|
|
214
|
-
const
|
|
215
|
-
|
|
254
|
+
const { resolverAddress, ..._options } = options || {};
|
|
255
|
+
const optsLength = Object.keys(_options).length;
|
|
256
|
+
const usingOptions = !optsLength || _options?.texts === true || _options?.coinTypes === true
|
|
257
|
+
? optsLength
|
|
258
|
+
? _options
|
|
259
|
+
: { contentHash: true, texts: true, coinTypes: true }
|
|
216
260
|
: undefined;
|
|
217
|
-
const graphResult = await graphFetch({ gqlInstance }, name, usingOptions);
|
|
261
|
+
const graphResult = await graphFetch({ gqlInstance }, name, usingOptions, resolverAddress);
|
|
218
262
|
if (!graphResult)
|
|
219
263
|
return;
|
|
220
264
|
const { isMigrated, createdAt, graphResolverAddress, ...wantedRecords } = graphResult;
|
|
221
|
-
if (!graphResolverAddress)
|
|
265
|
+
if (!graphResolverAddress && !options?.resolverAddress)
|
|
222
266
|
return { isMigrated, createdAt, message: "Name doesn't have a resolver" };
|
|
223
267
|
const result = await getDataForName({
|
|
224
268
|
contracts,
|
|
@@ -227,7 +271,7 @@ const getProfileFromName = async ({ contracts, gqlInstance, _getAddr, _getConten
|
|
|
227
271
|
_getText,
|
|
228
272
|
resolverMulticallWrapper,
|
|
229
273
|
multicallWrapper,
|
|
230
|
-
}, name, usingOptions ? wantedRecords : options, graphResolverAddress);
|
|
274
|
+
}, name, usingOptions ? wantedRecords : options, graphResolverAddress, options?.resolverAddress);
|
|
231
275
|
if (!result)
|
|
232
276
|
return { isMigrated, createdAt, message: "Records fetch didn't complete" };
|
|
233
277
|
return { ...result, isMigrated, createdAt, message: undefined };
|
|
@@ -3,6 +3,7 @@ declare type ProfileOptions = {
|
|
|
3
3
|
contentHash?: boolean;
|
|
4
4
|
texts?: boolean | string[];
|
|
5
5
|
coinTypes?: boolean | string[];
|
|
6
|
+
resolverAddress?: string;
|
|
6
7
|
};
|
|
7
8
|
export default function ({ getProfile }: ENSArgs<'getProfile'>, name: string, options?: ProfileOptions): Promise<{
|
|
8
9
|
isMigrated: boolean | null;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ENSArgs } from '..';
|
|
2
|
+
import { RecordInput, RecordTypes } from '../utils/recordHelpers';
|
|
3
|
+
declare type BaseInput = {
|
|
4
|
+
resolverAddress?: string;
|
|
5
|
+
};
|
|
6
|
+
declare type ContentHashInput = {
|
|
7
|
+
record: RecordInput<'contentHash'>;
|
|
8
|
+
type: 'contentHash';
|
|
9
|
+
};
|
|
10
|
+
declare type AddrOrTextInput = {
|
|
11
|
+
record: RecordInput<'addr' | 'text'>;
|
|
12
|
+
type: 'addr' | 'text';
|
|
13
|
+
};
|
|
14
|
+
export default function <T extends RecordTypes>({ contracts, provider, getResolver, signer, }: ENSArgs<'contracts' | 'provider' | 'getResolver' | 'signer'>, name: string, { record, type, resolverAddress, }: BaseInput & (ContentHashInput | AddrOrTextInput)): Promise<{
|
|
15
|
+
to: string;
|
|
16
|
+
data: string;
|
|
17
|
+
}>;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const normalise_1 = require("../utils/normalise");
|
|
4
|
+
const recordHelpers_1 = require("../utils/recordHelpers");
|
|
5
|
+
async function default_1({ contracts, provider, getResolver, signer, }, name, { record, type, resolverAddress, }) {
|
|
6
|
+
if (!name.includes('.')) {
|
|
7
|
+
throw new Error('Input is not an ENS name');
|
|
8
|
+
}
|
|
9
|
+
let resolverToUse;
|
|
10
|
+
if (resolverAddress) {
|
|
11
|
+
resolverToUse = resolverAddress;
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
resolverToUse = await getResolver(name);
|
|
15
|
+
}
|
|
16
|
+
if (!resolverToUse) {
|
|
17
|
+
throw new Error('No resolver found for input address');
|
|
18
|
+
}
|
|
19
|
+
const resolver = (await contracts?.getPublicResolver(provider, resolverToUse))?.connect(signer);
|
|
20
|
+
const hash = (0, normalise_1.namehash)(name);
|
|
21
|
+
const call = (0, recordHelpers_1.generateSingleRecordCall)(hash, resolver, type)(record);
|
|
22
|
+
return {
|
|
23
|
+
to: resolver.address,
|
|
24
|
+
data: call,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
exports.default = default_1;
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ import type burnFuses from './functions/burnFuses';
|
|
|
7
7
|
import type createSubname from './functions/createSubname';
|
|
8
8
|
import type deleteSubname from './functions/deleteSubname';
|
|
9
9
|
import type setName from './functions/setName';
|
|
10
|
+
import type setRecord from './functions/setRecord';
|
|
10
11
|
import type setRecords from './functions/setRecords';
|
|
11
12
|
import type setResolver from './functions/setResolver';
|
|
12
13
|
import type transferName from './functions/transferName';
|
|
@@ -133,11 +134,13 @@ export declare class ENS {
|
|
|
133
134
|
}>;
|
|
134
135
|
decode: ({ multicallWrapper }: ENSArgs<"multicallWrapper">, data: string, ...items: BatchFunctionResult<RawFunction>[]) => Promise<any[] | undefined>;
|
|
135
136
|
}>;
|
|
136
|
-
getProfile: (nameOrAddress: string, options?: {
|
|
137
|
+
getProfile: (nameOrAddress: string, options?: ({
|
|
137
138
|
contentHash?: boolean | undefined;
|
|
138
139
|
texts?: boolean | string[] | undefined;
|
|
139
140
|
coinTypes?: boolean | string[] | undefined;
|
|
140
|
-
}
|
|
141
|
+
} & {
|
|
142
|
+
resolverAddress?: string | undefined;
|
|
143
|
+
}) | undefined) => Promise<{
|
|
141
144
|
isMigrated: boolean | null;
|
|
142
145
|
createdAt: string | null;
|
|
143
146
|
address?: string | undefined;
|
|
@@ -166,6 +169,7 @@ export declare class ENS {
|
|
|
166
169
|
contentHash?: boolean | undefined;
|
|
167
170
|
texts?: boolean | string[] | undefined;
|
|
168
171
|
coinTypes?: boolean | string[] | undefined;
|
|
172
|
+
resolverAddress?: string | undefined;
|
|
169
173
|
} | undefined) => Promise<{
|
|
170
174
|
isMigrated: boolean | null;
|
|
171
175
|
createdAt: string | null;
|
|
@@ -454,6 +458,7 @@ export declare class ENS {
|
|
|
454
458
|
}>;
|
|
455
459
|
setName: WriteFunction<typeof setName>;
|
|
456
460
|
setRecords: WriteFunction<typeof setRecords>;
|
|
461
|
+
setRecord: WriteFunction<typeof setRecord>;
|
|
457
462
|
setResolver: WriteFunction<typeof setResolver>;
|
|
458
463
|
transferName: WriteFunction<typeof transferName>;
|
|
459
464
|
wrapName: WriteFunction<typeof wrapName>;
|
package/dist/cjs/index.js
CHANGED
|
@@ -90,7 +90,7 @@ class ENS {
|
|
|
90
90
|
await thisRef.checkInitialProvider();
|
|
91
91
|
// import the module dynamically
|
|
92
92
|
const mod = await Promise.resolve().then(() => __importStar(require(
|
|
93
|
-
/* webpackMode: "lazy", webpackChunkName: "[request]", webpackPreload: true */
|
|
93
|
+
/* webpackMode: "lazy", webpackChunkName: "[request]", webpackPreload: true, webpackExclude: /.*\.ts$/ */
|
|
94
94
|
`./functions/${path}`)));
|
|
95
95
|
// if combine isn't specified, run normally
|
|
96
96
|
// otherwise, create a function from the raw and decode functions
|
|
@@ -225,6 +225,11 @@ class ENS {
|
|
|
225
225
|
'contracts',
|
|
226
226
|
]);
|
|
227
227
|
setRecords = this.generateWriteFunction('setRecords', ['contracts', 'provider', 'getResolver']);
|
|
228
|
+
setRecord = this.generateWriteFunction('setRecord', [
|
|
229
|
+
'contracts',
|
|
230
|
+
'provider',
|
|
231
|
+
'getResolver',
|
|
232
|
+
]);
|
|
228
233
|
setResolver = this.generateWriteFunction('setResolver', ['contracts']);
|
|
229
234
|
transferName = this.generateWriteFunction('transferName', ['contracts']);
|
|
230
235
|
wrapName = this.generateWriteFunction('wrapName', [
|
package/dist/cjs/utils/labels.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.checkLocalStorageSize = exports.truncateUndecryptedName = exports.decryptName = exports.checkIsDecrypted = exports.parseName = exports.encodeLabel = exports.checkLabel = exports.saveName = exports.saveLabel = exports.isEncodedLabelhash = exports.encodeLabelhash = exports.decodeLabelhash = exports.keccakFromString = exports.labelhash = void 0;
|
|
4
4
|
const utils_1 = require("ethers/lib/utils");
|
|
5
5
|
const format_1 = require("./format");
|
|
6
|
+
const hasLocalStorage = typeof localStorage !== 'undefined';
|
|
6
7
|
const labelhash = (input) => (0, utils_1.solidityKeccak256)(['string'], [input]);
|
|
7
8
|
exports.labelhash = labelhash;
|
|
8
9
|
const keccakFromString = (input) => (0, exports.labelhash)(input);
|
|
@@ -32,12 +33,12 @@ function isEncodedLabelhash(hash) {
|
|
|
32
33
|
}
|
|
33
34
|
exports.isEncodedLabelhash = isEncodedLabelhash;
|
|
34
35
|
function getLabels() {
|
|
35
|
-
return
|
|
36
|
+
return hasLocalStorage
|
|
36
37
|
? JSON.parse(localStorage.getItem('ensjs:labels')) || {}
|
|
37
38
|
: {};
|
|
38
39
|
}
|
|
39
40
|
function _saveLabel(hash, label) {
|
|
40
|
-
if (!
|
|
41
|
+
if (!hasLocalStorage)
|
|
41
42
|
return hash;
|
|
42
43
|
const labels = getLabels();
|
|
43
44
|
localStorage.setItem('ensjs:labels', JSON.stringify({
|
|
@@ -97,7 +98,7 @@ exports.decryptName = decryptName;
|
|
|
97
98
|
const truncateUndecryptedName = (name) => (0, format_1.truncateFormat)(name);
|
|
98
99
|
exports.truncateUndecryptedName = truncateUndecryptedName;
|
|
99
100
|
function checkLocalStorageSize() {
|
|
100
|
-
if (!
|
|
101
|
+
if (!hasLocalStorage)
|
|
101
102
|
return 'Empty (0 KB)';
|
|
102
103
|
let allStrings = '';
|
|
103
104
|
for (const key in window.localStorage) {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export declare const normalise: (name: string) => any;
|
|
2
|
-
export declare const namehash: (
|
|
2
|
+
export declare const namehash: (name: string) => string;
|
|
@@ -6,17 +6,24 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.namehash = exports.normalise = void 0;
|
|
7
7
|
const utils_1 = require("ethers/lib/utils");
|
|
8
8
|
const uts46bundle_js_1 = __importDefault(require("idna-uts46-hx/uts46bundle.js"));
|
|
9
|
+
const labels_1 = require("./labels");
|
|
9
10
|
const zeros = new Uint8Array(32);
|
|
10
11
|
zeros.fill(0);
|
|
11
12
|
const normalise = (name) => name ? uts46bundle_js_1.default.toUnicode(name, { useStd3ASCII: true }) : name;
|
|
12
13
|
exports.normalise = normalise;
|
|
13
|
-
const namehash = (
|
|
14
|
+
const namehash = (name) => {
|
|
14
15
|
let result = zeros;
|
|
15
|
-
const name = (0, exports.normalise)(inputName);
|
|
16
16
|
if (name) {
|
|
17
17
|
const labels = name.split('.');
|
|
18
18
|
for (var i = labels.length - 1; i >= 0; i--) {
|
|
19
|
-
|
|
19
|
+
let labelSha;
|
|
20
|
+
if ((0, labels_1.isEncodedLabelhash)(labels[i])) {
|
|
21
|
+
labelSha = (0, labels_1.decodeLabelhash)(labels[i]);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
const normalised = (0, exports.normalise)(labels[i]);
|
|
25
|
+
labelSha = (0, utils_1.keccak256)((0, utils_1.toUtf8Bytes)(normalised));
|
|
26
|
+
}
|
|
20
27
|
result = (0, utils_1.keccak256)((0, utils_1.concat)([result, labelSha]));
|
|
21
28
|
}
|
|
22
29
|
}
|
|
@@ -9,5 +9,8 @@ export declare type RecordOptions = {
|
|
|
9
9
|
coinTypes?: RecordItem[];
|
|
10
10
|
};
|
|
11
11
|
export declare const generateSetAddr: (namehash: string, coinType: string, address: string, resolver: PublicResolver) => string;
|
|
12
|
+
export declare type RecordTypes = 'contentHash' | 'text' | 'addr';
|
|
13
|
+
export declare type RecordInput<T extends RecordTypes> = T extends 'contentHash' ? string : RecordItem;
|
|
14
|
+
export declare function generateSingleRecordCall<T extends RecordTypes>(namehash: string, resolver: PublicResolver, type: T): (record: RecordInput<T>) => string;
|
|
12
15
|
export declare const generateRecordCallArray: (namehash: string, records: RecordOptions, resolver: PublicResolver) => string[];
|
|
13
16
|
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateRecordCallArray = exports.generateSetAddr = void 0;
|
|
3
|
+
exports.generateRecordCallArray = exports.generateSingleRecordCall = exports.generateSetAddr = void 0;
|
|
4
4
|
const address_encoder_1 = require("@ensdomains/address-encoder");
|
|
5
5
|
const contentHash_1 = require("./contentHash");
|
|
6
6
|
const generateSetAddr = (namehash, coinType, address, resolver) => {
|
|
@@ -16,28 +16,55 @@ const generateSetAddr = (namehash, coinType, address, resolver) => {
|
|
|
16
16
|
return resolver?.interface.encodeFunctionData('setAddr(bytes32,uint256,bytes)', [namehash, inputCoinType, encodedAddress]);
|
|
17
17
|
};
|
|
18
18
|
exports.generateSetAddr = generateSetAddr;
|
|
19
|
+
function generateSingleRecordCall(namehash, resolver, type) {
|
|
20
|
+
if (type === 'contentHash') {
|
|
21
|
+
return (_r) => {
|
|
22
|
+
const record = _r;
|
|
23
|
+
let _contentHash = '';
|
|
24
|
+
if (record !== _contentHash) {
|
|
25
|
+
const encoded = (0, contentHash_1.encodeContenthash)(record);
|
|
26
|
+
if (encoded.error)
|
|
27
|
+
throw new Error(encoded.error);
|
|
28
|
+
_contentHash = encoded.encoded;
|
|
29
|
+
}
|
|
30
|
+
return resolver.interface.encodeFunctionData('setContenthash', [
|
|
31
|
+
namehash,
|
|
32
|
+
_contentHash,
|
|
33
|
+
]);
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
return (_r) => {
|
|
38
|
+
const record = _r;
|
|
39
|
+
if (type === 'text') {
|
|
40
|
+
return resolver.interface.encodeFunctionData('setText', [
|
|
41
|
+
namehash,
|
|
42
|
+
record.key,
|
|
43
|
+
record.value,
|
|
44
|
+
]);
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
return (0, exports.generateSetAddr)(namehash, record.key, record.value, resolver);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.generateSingleRecordCall = generateSingleRecordCall;
|
|
19
53
|
const generateRecordCallArray = (namehash, records, resolver) => {
|
|
20
54
|
const calls = [];
|
|
21
55
|
if (records.contentHash) {
|
|
22
|
-
const
|
|
23
|
-
const data = resolver?.interface.encodeFunctionData('setContenthash', [namehash, contentHash]);
|
|
56
|
+
const data = generateSingleRecordCall(namehash, resolver, 'contentHash')(records.contentHash);
|
|
24
57
|
data && calls.push(data);
|
|
25
58
|
}
|
|
26
59
|
if (records.texts && records.texts.length > 0) {
|
|
27
|
-
records.texts
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
key,
|
|
31
|
-
value,
|
|
32
|
-
]);
|
|
33
|
-
data && calls.push(data);
|
|
34
|
-
});
|
|
60
|
+
records.texts
|
|
61
|
+
.map(generateSingleRecordCall(namehash, resolver, 'text'))
|
|
62
|
+
.forEach((call) => calls.push(call));
|
|
35
63
|
}
|
|
36
64
|
if (records.coinTypes && records.coinTypes.length > 0) {
|
|
37
|
-
records.coinTypes
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
});
|
|
65
|
+
records.coinTypes
|
|
66
|
+
.map(generateSingleRecordCall(namehash, resolver, 'addr'))
|
|
67
|
+
.forEach((call) => calls.push(call));
|
|
41
68
|
}
|
|
42
69
|
return calls;
|
|
43
70
|
};
|
package/dist/esm/GqlManager.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
export declare const enter: (node: any) => any;
|
|
2
|
+
export declare const requestMiddleware: (visit: any, parse: any) => (request: any) => any;
|
|
3
|
+
export declare const responseMiddleware: (traverse: any) => (response: any) => any;
|
|
1
4
|
export default class GqlManager {
|
|
2
5
|
gql: any;
|
|
3
6
|
client?: any | null;
|
package/dist/esm/GqlManager.js
CHANGED
|
@@ -1,11 +1,67 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
import { namehash } from './utils/normalise';
|
|
3
|
+
const generateSelection = (selection) => ({
|
|
4
|
+
kind: 'Field',
|
|
5
|
+
name: {
|
|
6
|
+
kind: 'Name',
|
|
7
|
+
value: selection,
|
|
8
|
+
},
|
|
9
|
+
arguments: [],
|
|
10
|
+
directives: [],
|
|
11
|
+
alias: undefined,
|
|
12
|
+
selectionSet: undefined,
|
|
13
|
+
});
|
|
14
|
+
export const enter = (node) => {
|
|
15
|
+
if (node.kind === 'SelectionSet') {
|
|
16
|
+
const id = node.selections.find((x) => x.name && x.name.value === 'id');
|
|
17
|
+
const name = node.selections.find((x) => x.name && x.name.value === 'name');
|
|
18
|
+
if (!id && name) {
|
|
19
|
+
node.selections = [...node.selections, generateSelection('id')];
|
|
20
|
+
return node;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
export const requestMiddleware = (visit, parse) => (request) => {
|
|
25
|
+
const requestBody = JSON.parse(request.body);
|
|
26
|
+
const rawQuery = requestBody.query;
|
|
27
|
+
const parsedQuery = parse(rawQuery);
|
|
28
|
+
const updatedQuery = visit(parsedQuery, { enter });
|
|
29
|
+
const updatedBody = { ...requestBody, query: updatedQuery.loc.source.body };
|
|
30
|
+
return {
|
|
31
|
+
...request,
|
|
32
|
+
body: JSON.stringify(updatedBody),
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
export const responseMiddleware = (traverse) => (response) => {
|
|
36
|
+
traverse(response).forEach(function (responseItem) {
|
|
37
|
+
if (responseItem instanceof Object && responseItem.name) {
|
|
38
|
+
//Name already in hashed form
|
|
39
|
+
if (responseItem.name && responseItem.name.includes('[')) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const hashedName = namehash(responseItem.name);
|
|
43
|
+
if (responseItem.id !== hashedName) {
|
|
44
|
+
this.update({ ...responseItem, name: hashedName, invalidName: true });
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
return response;
|
|
49
|
+
};
|
|
1
50
|
export default class GqlManager {
|
|
2
51
|
constructor() {
|
|
3
52
|
this.gql = () => null;
|
|
4
53
|
this.client = null;
|
|
5
54
|
this.setUrl = async (url) => {
|
|
6
55
|
if (url) {
|
|
7
|
-
const imported = await
|
|
8
|
-
|
|
56
|
+
const [imported, traverse, { visit, parse }] = await Promise.all([
|
|
57
|
+
import('graphql-request'),
|
|
58
|
+
import('traverse'),
|
|
59
|
+
import('graphql/language'),
|
|
60
|
+
]);
|
|
61
|
+
this.client = new imported.GraphQLClient(url, {
|
|
62
|
+
requestMiddleware: requestMiddleware(visit, parse),
|
|
63
|
+
responseMiddleware: responseMiddleware(traverse.default),
|
|
64
|
+
});
|
|
9
65
|
this.gql = imported.gql;
|
|
10
66
|
}
|
|
11
67
|
else {
|
|
@@ -26,5 +26,8 @@ declare type ProfileOptions = {
|
|
|
26
26
|
texts?: boolean | string[];
|
|
27
27
|
coinTypes?: boolean | string[];
|
|
28
28
|
};
|
|
29
|
-
|
|
29
|
+
declare type InputProfileOptions = ProfileOptions & {
|
|
30
|
+
resolverAddress?: string;
|
|
31
|
+
};
|
|
32
|
+
export default function ({ contracts, gqlInstance, getName, _getAddr, _getContentHash, _getText, resolverMulticallWrapper, multicallWrapper, }: ENSArgs<'contracts' | 'gqlInstance' | 'getName' | '_getText' | '_getAddr' | '_getContentHash' | 'resolverMulticallWrapper' | 'multicallWrapper'>, nameOrAddress: string, options?: InputProfileOptions): Promise<ResolvedProfile | undefined>;
|
|
30
33
|
export {};
|