@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.
- package/README.md +2 -0
- package/dist/cjs/GqlManager.d.ts +3 -0
- package/dist/cjs/GqlManager.js +62 -2
- package/dist/cjs/functions/burnFuses.d.ts +3 -2
- package/dist/cjs/functions/burnFuses.js +4 -8
- package/dist/cjs/functions/createSubname.d.ts +1 -5
- package/dist/cjs/functions/createSubname.js +5 -8
- package/dist/cjs/functions/deleteSubname.d.ts +3 -3
- 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/getFuses.js +3 -2
- package/dist/cjs/functions/getOwner.js +7 -6
- package/dist/cjs/functions/getProfile.d.ts +4 -1
- package/dist/cjs/functions/getProfile.js +102 -24
- package/dist/cjs/functions/getRecords.d.ts +1 -0
- package/dist/cjs/functions/getSpecificRecord.js +22 -5
- package/dist/cjs/functions/getSubnames.js +6 -6
- package/dist/cjs/functions/setName.d.ts +4 -3
- package/dist/cjs/functions/setName.js +5 -10
- package/dist/cjs/functions/setRecord.d.ts +18 -0
- package/dist/cjs/functions/setRecord.js +27 -0
- package/dist/cjs/functions/setRecords.d.ts +4 -2
- package/dist/cjs/functions/setRecords.js +14 -12
- package/dist/cjs/functions/setResolver.d.ts +4 -4
- package/dist/cjs/functions/setResolver.js +6 -12
- package/dist/cjs/functions/transferName.d.ts +4 -3
- package/dist/cjs/functions/transferName.js +9 -13
- package/dist/cjs/functions/transferSubname.d.ts +4 -3
- package/dist/cjs/functions/transferSubname.js +5 -8
- package/dist/cjs/functions/unwrapName.d.ts +4 -3
- package/dist/cjs/functions/unwrapName.js +5 -9
- package/dist/cjs/functions/wrapName.d.ts +5 -3
- package/dist/cjs/functions/wrapName.js +8 -12
- package/dist/cjs/index.d.ts +48 -46
- package/dist/cjs/index.js +43 -19
- package/dist/cjs/utils/labels.js +5 -4
- package/dist/cjs/utils/makeHashIndexes.js +2 -2
- package/dist/cjs/utils/normalise.d.ts +1 -0
- package/dist/cjs/utils/normalise.js +27 -1
- package/dist/cjs/utils/recordHelpers.d.ts +3 -0
- package/dist/cjs/utils/recordHelpers.js +42 -15
- package/dist/cjs/utils/registerHelpers.js +3 -4
- package/dist/cjs/utils/writeTx.d.ts +4 -0
- package/dist/cjs/utils/writeTx.js +3 -0
- package/dist/esm/GqlManager.d.ts +3 -0
- package/dist/esm/GqlManager.js +58 -2
- package/dist/esm/functions/burnFuses.d.ts +3 -2
- package/dist/esm/functions/burnFuses.js +4 -8
- package/dist/esm/functions/createSubname.d.ts +1 -5
- package/dist/esm/functions/createSubname.js +5 -8
- package/dist/esm/functions/deleteSubname.d.ts +3 -3
- 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/getFuses.js +4 -3
- package/dist/esm/functions/getOwner.js +7 -6
- package/dist/esm/functions/getProfile.d.ts +4 -1
- package/dist/esm/functions/getProfile.js +102 -24
- package/dist/esm/functions/getRecords.d.ts +1 -0
- package/dist/esm/functions/getSpecificRecord.js +22 -5
- package/dist/esm/functions/getSubnames.js +3 -3
- package/dist/esm/functions/setName.d.ts +4 -3
- package/dist/esm/functions/setName.js +5 -10
- package/dist/esm/functions/setRecord.d.ts +18 -0
- package/dist/esm/functions/setRecord.js +24 -0
- package/dist/esm/functions/setRecords.d.ts +4 -2
- package/dist/esm/functions/setRecords.js +14 -12
- package/dist/esm/functions/setResolver.d.ts +4 -4
- package/dist/esm/functions/setResolver.js +6 -12
- package/dist/esm/functions/transferName.d.ts +4 -3
- package/dist/esm/functions/transferName.js +9 -13
- package/dist/esm/functions/transferSubname.d.ts +4 -3
- package/dist/esm/functions/transferSubname.js +5 -8
- package/dist/esm/functions/unwrapName.d.ts +4 -3
- package/dist/esm/functions/unwrapName.js +5 -9
- package/dist/esm/functions/wrapName.d.ts +5 -3
- package/dist/esm/functions/wrapName.js +8 -12
- package/dist/esm/index.d.ts +48 -46
- package/dist/esm/index.js +43 -19
- package/dist/esm/utils/labels.js +5 -4
- package/dist/esm/utils/makeHashIndexes.js +2 -2
- package/dist/esm/utils/normalise.d.ts +1 -0
- package/dist/esm/utils/normalise.js +25 -0
- package/dist/esm/utils/recordHelpers.d.ts +3 -0
- package/dist/esm/utils/recordHelpers.js +40 -14
- package/dist/esm/utils/registerHelpers.js +3 -4
- package/dist/esm/utils/writeTx.d.ts +4 -0
- package/dist/esm/utils/writeTx.js +1 -0
- package/package.json +15 -7
- package/src/@types/dns-packet/index.d.ts +114 -0
- package/src/GqlManager.test.ts +170 -0
- package/src/GqlManager.ts +67 -2
- 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 +12 -10
- package/src/functions/burnFuses.ts +9 -11
- package/src/{tests → functions}/createSubname.test.ts +12 -16
- package/src/functions/createSubname.ts +7 -13
- package/src/{tests → functions}/deleteSubname.test.ts +32 -32
- 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/functions/getFuses.ts +4 -3
- 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 +14 -2
- package/src/functions/getOwner.ts +7 -7
- package/src/{tests → functions}/getProfile.test.ts +45 -12
- package/src/functions/getProfile.ts +151 -24
- package/src/functions/getRecords.ts +1 -0
- package/src/{tests → functions}/getResolver.test.ts +1 -1
- package/src/{tests → functions}/getSpecificRecord.test.ts +1 -1
- package/src/functions/getSpecificRecord.ts +28 -8
- package/src/{tests → functions}/getSubnames.test.ts +1 -1
- package/src/functions/getSubnames.ts +68 -66
- package/src/{tests → functions}/makeCommitment.test.ts +1 -1
- package/src/functions/normalise.test.ts +22 -0
- package/src/{tests → functions}/setName.test.ts +3 -2
- package/src/functions/setName.ts +15 -17
- package/src/functions/setRecord.test.ts +100 -0
- package/src/functions/setRecord.ts +63 -0
- package/src/{tests → functions}/setRecords.test.ts +12 -10
- package/src/functions/setRecords.ts +22 -16
- package/src/{tests → functions}/setResolver.test.ts +12 -15
- package/src/functions/setResolver.ts +15 -20
- package/src/{tests → functions}/transferName.test.ts +30 -31
- package/src/functions/transferName.ts +19 -22
- package/src/{tests → functions}/transferSubname.test.ts +34 -34
- package/src/functions/transferSubname.ts +21 -13
- package/src/{tests → functions}/unwrapName.test.ts +24 -23
- package/src/functions/unwrapName.ts +20 -15
- package/src/{tests → functions}/wrapName.test.ts +19 -19
- package/src/functions/wrapName.ts +20 -22
- package/src/index.ts +115 -26
- package/src/tests/populateTransaction.test.ts +40 -0
- package/src/tests/signerInjection.test.ts +46 -0
- package/src/tests/withProvider.test.ts +1 -1
- package/src/utils/labels.ts +6 -4
- package/src/utils/makeHashIndexes.ts +4 -4
- package/src/utils/normalise.ts +29 -0
- package/src/utils/recordHelpers.ts +52 -18
- package/src/utils/registerHelpers.ts +3 -4
- package/src/utils/writeTx.ts +6 -0
package/README.md
CHANGED
|
@@ -9,6 +9,8 @@ We also use undeployed contracts under the hood, so this **will not** work on an
|
|
|
9
9
|
|
|
10
10
|
Given the current development status, we're actively seeking feedback so feel free to create an issue or PR if you notice something!
|
|
11
11
|
|
|
12
|
+
If you are looking for documentation for **version 2**, it an be found [here](https://github.com/ensdomains/ensjs#readme).
|
|
13
|
+
|
|
12
14
|
## Features
|
|
13
15
|
|
|
14
16
|
- Dynamically load **everything**
|
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 {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { ethers } from 'ethers';
|
|
2
1
|
import { ENSArgs } from '..';
|
|
3
2
|
import { FuseOptions } from '../@types/FuseOptions';
|
|
4
|
-
export default function ({ contracts,
|
|
3
|
+
export default function ({ contracts, signer }: ENSArgs<'contracts' | 'signer'>, name: string, { fusesToBurn, }: {
|
|
4
|
+
fusesToBurn: FuseOptions;
|
|
5
|
+
}): Promise<import("ethers").PopulatedTransaction>;
|
|
@@ -3,16 +3,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const ethers_1 = require("ethers");
|
|
7
6
|
const generateFuseInput_1 = __importDefault(require("../utils/generateFuseInput"));
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
if (!signer) {
|
|
11
|
-
throw new Error('No signer found');
|
|
12
|
-
}
|
|
7
|
+
const normalise_1 = require("../utils/normalise");
|
|
8
|
+
async function default_1({ contracts, signer }, name, { fusesToBurn, }) {
|
|
13
9
|
const nameWrapper = (await contracts?.getNameWrapper()).connect(signer);
|
|
14
|
-
const
|
|
10
|
+
const hash = (0, normalise_1.namehash)(name);
|
|
15
11
|
const encodedFuses = (0, generateFuseInput_1.default)(fusesToBurn);
|
|
16
|
-
return nameWrapper.burnFuses(
|
|
12
|
+
return nameWrapper.populateTransaction.burnFuses(hash, encodedFuses);
|
|
17
13
|
}
|
|
18
14
|
exports.default = default_1;
|
|
@@ -2,18 +2,14 @@ import { ethers } from 'ethers';
|
|
|
2
2
|
import { ENSArgs } from '..';
|
|
3
3
|
import { FuseOptions } from '../@types/FuseOptions';
|
|
4
4
|
declare type BaseArgs = {
|
|
5
|
-
name: string;
|
|
6
5
|
owner: string;
|
|
7
6
|
resolverAddress?: string;
|
|
8
7
|
contract: 'registry' | 'nameWrapper';
|
|
9
|
-
options?: {
|
|
10
|
-
addressOrIndex?: string | number;
|
|
11
|
-
};
|
|
12
8
|
};
|
|
13
9
|
declare type NameWrapperArgs = {
|
|
14
10
|
contract: 'nameWrapper';
|
|
15
11
|
fuses?: FuseOptions;
|
|
16
12
|
} & BaseArgs;
|
|
17
13
|
declare type Args = BaseArgs | NameWrapperArgs;
|
|
18
|
-
export default function ({ contracts,
|
|
14
|
+
export default function ({ contracts, signer }: ENSArgs<'contracts' | 'signer'>, name: string, { owner, resolverAddress, contract, ...wrapperArgs }: Args): Promise<ethers.PopulatedTransaction>;
|
|
19
15
|
export {};
|
|
@@ -5,11 +5,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const ethers_1 = require("ethers");
|
|
7
7
|
const generateFuseInput_1 = __importDefault(require("../utils/generateFuseInput"));
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
if (!signer) {
|
|
11
|
-
throw new Error('No signer found');
|
|
12
|
-
}
|
|
8
|
+
const normalise_1 = require("../utils/normalise");
|
|
9
|
+
async function default_1({ contracts, signer }, name, { owner, resolverAddress, contract, ...wrapperArgs }) {
|
|
13
10
|
const labels = name.split('.');
|
|
14
11
|
if (labels.length === 1) {
|
|
15
12
|
throw new Error('Subnames in ENS.js can only be created for 2LDs, not TLDs');
|
|
@@ -22,18 +19,18 @@ async function default_1({ contracts, provider }, { name, owner, resolverAddress
|
|
|
22
19
|
}
|
|
23
20
|
const label = labels.shift();
|
|
24
21
|
const labelhash = ethers_1.ethers.utils.solidityKeccak256(['string'], [label]);
|
|
25
|
-
const parentNodehash =
|
|
22
|
+
const parentNodehash = (0, normalise_1.namehash)(labels.join('.'));
|
|
26
23
|
switch (contract) {
|
|
27
24
|
case 'registry': {
|
|
28
25
|
const registry = (await contracts?.getRegistry()).connect(signer);
|
|
29
|
-
return registry.setSubnodeRecord(parentNodehash, labelhash, owner, resolverAddress, 0);
|
|
26
|
+
return registry.populateTransaction.setSubnodeRecord(parentNodehash, labelhash, owner, resolverAddress, 0);
|
|
30
27
|
}
|
|
31
28
|
case 'nameWrapper': {
|
|
32
29
|
const nameWrapper = (await contracts?.getNameWrapper()).connect(signer);
|
|
33
30
|
const generatedFuses = 'fuses' in wrapperArgs && wrapperArgs.fuses
|
|
34
31
|
? (0, generateFuseInput_1.default)(wrapperArgs.fuses)
|
|
35
32
|
: '0';
|
|
36
|
-
return nameWrapper.setSubnodeRecord(parentNodehash, label, owner, resolverAddress, 0, generatedFuses);
|
|
33
|
+
return nameWrapper.populateTransaction.setSubnodeRecord(parentNodehash, label, owner, resolverAddress, 0, generatedFuses);
|
|
37
34
|
}
|
|
38
35
|
default: {
|
|
39
36
|
throw new Error(`Unknown contract: ${contract}`);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { ENSArgs } from '..';
|
|
2
|
-
export default function ({
|
|
3
|
-
|
|
4
|
-
}): Promise<import("ethers").
|
|
2
|
+
export default function ({ transferSubname }: ENSArgs<'transferSubname'>, name: string, { contract, }: {
|
|
3
|
+
contract: 'registry' | 'nameWrapper';
|
|
4
|
+
}): Promise<import("ethers").PopulatedTransaction>;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
async function default_1({
|
|
4
|
-
return transferSubname(name,
|
|
3
|
+
async function default_1({ transferSubname }, name, { contract, }) {
|
|
4
|
+
return transferSubname.populateTransaction(name, {
|
|
5
|
+
contract,
|
|
6
|
+
address: '0x0000000000000000000000000000000000000000',
|
|
7
|
+
});
|
|
5
8
|
}
|
|
6
9
|
exports.default = default_1;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as packet from 'dns-packet';
|
|
2
|
+
export declare function encodeURLParams(p: {
|
|
3
|
+
[key: string]: string;
|
|
4
|
+
}): string;
|
|
5
|
+
export declare const getDNS: (q: packet.Packet) => Promise<packet.Packet>;
|
|
6
|
+
export declare const dnsQuery: (qtype: string, qname: string) => Promise<packet.Packet>;
|
|
7
|
+
export default function (_: any, dnsName: string): Promise<any>;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.dnsQuery = exports.getDNS = exports.encodeURLParams = void 0;
|
|
27
|
+
const packet = __importStar(require("dns-packet"));
|
|
28
|
+
function encodeURLParams(p) {
|
|
29
|
+
return Object.entries(p)
|
|
30
|
+
.map((kv) => kv.map(encodeURIComponent).join('='))
|
|
31
|
+
.join('&');
|
|
32
|
+
}
|
|
33
|
+
exports.encodeURLParams = encodeURLParams;
|
|
34
|
+
const getDNS = async (q) => {
|
|
35
|
+
const response = await global.fetch(`https://cloudflare-dns.com/dns-query?${encodeURLParams({
|
|
36
|
+
ct: 'application/dns-udpwireformat',
|
|
37
|
+
dns: packet.encode(q)?.toString('base64'),
|
|
38
|
+
ts: Date.now().toString(),
|
|
39
|
+
})}`);
|
|
40
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
41
|
+
// @ts-ignore:next-line
|
|
42
|
+
const fromArrayBuffer = Buffer.from(arrayBuffer);
|
|
43
|
+
return packet.decode(fromArrayBuffer);
|
|
44
|
+
};
|
|
45
|
+
exports.getDNS = getDNS;
|
|
46
|
+
const dnsQuery = async (qtype, qname) => {
|
|
47
|
+
const query = {
|
|
48
|
+
type: 'query',
|
|
49
|
+
id: 1,
|
|
50
|
+
flags: packet.RECURSION_DESIRED,
|
|
51
|
+
questions: [
|
|
52
|
+
{
|
|
53
|
+
type: qtype,
|
|
54
|
+
class: 'IN',
|
|
55
|
+
name: qname,
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
additionals: [
|
|
59
|
+
{
|
|
60
|
+
type: 'OPT',
|
|
61
|
+
class: 'IN',
|
|
62
|
+
name: '.',
|
|
63
|
+
udpPayloadSize: 4096,
|
|
64
|
+
flags: packet.DNSSEC_OK,
|
|
65
|
+
},
|
|
66
|
+
],
|
|
67
|
+
answers: [],
|
|
68
|
+
};
|
|
69
|
+
const response = await (0, exports.getDNS)(query);
|
|
70
|
+
if (response.rcode !== 'NOERROR') {
|
|
71
|
+
throw new Error(`DNS query failed: ${response.rcode}`);
|
|
72
|
+
}
|
|
73
|
+
return response;
|
|
74
|
+
};
|
|
75
|
+
exports.dnsQuery = dnsQuery;
|
|
76
|
+
async function default_1(_, dnsName) {
|
|
77
|
+
const result = await (0, exports.dnsQuery)('TXT', `_ens.${dnsName}`);
|
|
78
|
+
const address = result?.answers?.[0]?.data?.[0]?.toString()?.split('=')?.[1];
|
|
79
|
+
return address;
|
|
80
|
+
}
|
|
81
|
+
exports.default = default_1;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const ethers_1 = require("ethers");
|
|
4
4
|
const fuses_1 = require("../utils/fuses");
|
|
5
|
+
const normalise_1 = require("../utils/normalise");
|
|
5
6
|
const NameSafety = [
|
|
6
7
|
'Safe',
|
|
7
8
|
'RegistrantNotWrapped',
|
|
@@ -14,7 +15,7 @@ const raw = async ({ contracts }, name) => {
|
|
|
14
15
|
return {
|
|
15
16
|
to: nameWrapper.address,
|
|
16
17
|
data: nameWrapper.interface.encodeFunctionData('getFuses', [
|
|
17
|
-
|
|
18
|
+
(0, normalise_1.namehash)(name),
|
|
18
19
|
]),
|
|
19
20
|
};
|
|
20
21
|
};
|
|
@@ -38,7 +39,7 @@ const decode = async ({ contracts }, data, name) => {
|
|
|
38
39
|
if (ethers_1.utils.hexStripZeros(vulnerableNode) !== '0x') {
|
|
39
40
|
name.split('.').forEach((label, index, arr) => {
|
|
40
41
|
const node = arr.slice(index).join('.');
|
|
41
|
-
const nodehash =
|
|
42
|
+
const nodehash = (0, normalise_1.namehash)(node);
|
|
42
43
|
if (nodehash === vulnerableNode) {
|
|
43
44
|
returnVulnerableNode = node;
|
|
44
45
|
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const ethers_1 = require("ethers");
|
|
4
4
|
const labels_1 = require("../utils/labels");
|
|
5
|
+
const normalise_1 = require("../utils/normalise");
|
|
5
6
|
const singleContractOwnerRaw = async ({ contracts }, contract, namehash, labels) => {
|
|
6
7
|
switch (contract) {
|
|
7
8
|
case 'nameWrapper': {
|
|
@@ -30,10 +31,10 @@ const singleContractOwnerRaw = async ({ contracts }, contract, namehash, labels)
|
|
|
30
31
|
}
|
|
31
32
|
};
|
|
32
33
|
const raw = async ({ contracts, multicallWrapper }, name, contract) => {
|
|
33
|
-
const namehash =
|
|
34
|
+
const namehash = (0, normalise_1.namehash)(name);
|
|
34
35
|
const labels = name.split('.');
|
|
35
|
-
if (contract) {
|
|
36
|
-
return await singleContractOwnerRaw({ contracts }, contract, namehash, labels);
|
|
36
|
+
if (contract || labels.length === 1) {
|
|
37
|
+
return await singleContractOwnerRaw({ contracts }, contract || 'registry', namehash, labels);
|
|
37
38
|
}
|
|
38
39
|
const registryData = await singleContractOwnerRaw({ contracts }, 'registry', namehash, labels);
|
|
39
40
|
const nameWrapperData = await singleContractOwnerRaw({ contracts }, 'nameWrapper', namehash, labels);
|
|
@@ -48,10 +49,11 @@ const singleContractOwnerDecode = (data) => ethers_1.ethers.utils.defaultAbiCode
|
|
|
48
49
|
const decode = async ({ contracts, multicallWrapper }, data, name, contract) => {
|
|
49
50
|
if (data === null)
|
|
50
51
|
return;
|
|
51
|
-
|
|
52
|
+
const labels = name.split('.');
|
|
53
|
+
if (contract || labels.length === 1) {
|
|
52
54
|
const singleOwner = singleContractOwnerDecode(data);
|
|
53
55
|
let obj = {
|
|
54
|
-
ownershipLevel: contract,
|
|
56
|
+
ownershipLevel: contract || 'registry',
|
|
55
57
|
};
|
|
56
58
|
if (contract === 'registrar') {
|
|
57
59
|
return {
|
|
@@ -76,7 +78,6 @@ const decode = async ({ contracts, multicallWrapper }, data, name, contract) =>
|
|
|
76
78
|
const registryOwner = decodedData[0][0];
|
|
77
79
|
const nameWrapperOwner = decodedData[1][0];
|
|
78
80
|
const registrarOwner = decodedData[2]?.[0];
|
|
79
|
-
const labels = name.split('.');
|
|
80
81
|
// check for only .eth names
|
|
81
82
|
if (labels[labels.length - 1] === 'eth') {
|
|
82
83
|
// if the owner on the registrar is the namewrapper, then the namewrapper owner is the owner
|
|
@@ -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 = [];
|
|
@@ -42,23 +43,51 @@ const makeMulticallData = async ({ _getAddr, _getContentHash, _getText, resolver
|
|
|
42
43
|
const prRawData = await resolverMulticallWrapper.raw(calls.map((x) => x.data));
|
|
43
44
|
return { data: prRawData.data, calls };
|
|
44
45
|
};
|
|
45
|
-
const
|
|
46
|
-
const
|
|
46
|
+
const fetchWithoutResolverMulticall = async ({ multicallWrapper }, calls, resolverAddress) => {
|
|
47
|
+
const callsWithResolver = calls.map((call) => ({
|
|
48
|
+
to: resolverAddress,
|
|
49
|
+
data: call.data.data,
|
|
50
|
+
}));
|
|
51
|
+
return (await multicallWrapper(callsWithResolver)).map((x) => x[1]);
|
|
52
|
+
};
|
|
53
|
+
const getDataForName = async ({ contracts, _getAddr, _getContentHash, _getText, resolverMulticallWrapper, multicallWrapper, }, name, options, fallbackResolver, specificResolver) => {
|
|
47
54
|
const universalResolver = await contracts?.getUniversalResolver();
|
|
48
55
|
const { data, calls } = await makeMulticallData({ _getAddr, _getContentHash, _getText, resolverMulticallWrapper }, name, options);
|
|
49
|
-
let
|
|
56
|
+
let resolvedData;
|
|
57
|
+
let useFallbackResolver = false;
|
|
50
58
|
try {
|
|
51
|
-
|
|
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
|
+
}
|
|
52
66
|
}
|
|
53
67
|
catch {
|
|
54
|
-
|
|
68
|
+
useFallbackResolver = true;
|
|
69
|
+
}
|
|
70
|
+
let resolverAddress;
|
|
71
|
+
let recordData;
|
|
72
|
+
if (useFallbackResolver) {
|
|
73
|
+
resolverAddress = specificResolver || fallbackResolver;
|
|
74
|
+
recordData = await fetchWithoutResolverMulticall({ multicallWrapper }, calls, resolverAddress);
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
resolverAddress = specificResolver || resolvedData['1'];
|
|
78
|
+
if (specificResolver) {
|
|
79
|
+
recordData = resolvedData;
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
;
|
|
83
|
+
[recordData] = await resolverMulticallWrapper.decode(resolvedData['0']);
|
|
84
|
+
}
|
|
55
85
|
}
|
|
56
|
-
const [recordData] = await resolverMulticallWrapper.decode(resolver['0']);
|
|
57
86
|
const matchAddress = recordData[calls.findIndex((x) => x.key === '60')];
|
|
58
87
|
return {
|
|
59
88
|
address: matchAddress && (await _getAddr.decode(matchAddress)),
|
|
60
89
|
records: await formatRecords({ _getAddr, _getContentHash, _getText }, recordData, calls, options),
|
|
61
|
-
resolverAddress
|
|
90
|
+
resolverAddress,
|
|
62
91
|
};
|
|
63
92
|
};
|
|
64
93
|
const formatRecords = async ({ _getText, _getAddr, _getContentHash, }, data, calls, options) => {
|
|
@@ -68,7 +97,7 @@ const formatRecords = async ({ _getText, _getAddr, _getContentHash, }, data, cal
|
|
|
68
97
|
key: calls[i].key,
|
|
69
98
|
type: calls[i].type,
|
|
70
99
|
};
|
|
71
|
-
if (itemRet.type === '
|
|
100
|
+
if (itemRet.type === 'contenthash') {
|
|
72
101
|
decodedFromAbi = ethers_1.ethers.utils.defaultAbiCoder.decode(['bytes'], item)[0];
|
|
73
102
|
if (ethers_1.ethers.utils.hexStripZeros(decodedFromAbi) === '0x') {
|
|
74
103
|
return;
|
|
@@ -144,10 +173,10 @@ const formatRecords = async ({ _getText, _getAddr, _getContentHash, }, data, cal
|
|
|
144
173
|
}
|
|
145
174
|
return returnedResponse;
|
|
146
175
|
};
|
|
147
|
-
const graphFetch = async ({ gqlInstance }, name, wantedRecords) => {
|
|
176
|
+
const graphFetch = async ({ gqlInstance }, name, wantedRecords, resolverAddress) => {
|
|
148
177
|
const query = gqlInstance.gql `
|
|
149
|
-
query getRecords($
|
|
150
|
-
|
|
178
|
+
query getRecords($id: String!) {
|
|
179
|
+
domain(id: $id) {
|
|
151
180
|
isMigrated
|
|
152
181
|
createdAt
|
|
153
182
|
resolver {
|
|
@@ -157,18 +186,52 @@ const graphFetch = async ({ gqlInstance }, name, wantedRecords) => {
|
|
|
157
186
|
addr {
|
|
158
187
|
id
|
|
159
188
|
}
|
|
189
|
+
address
|
|
190
|
+
}
|
|
191
|
+
}
|
|
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
|
|
160
206
|
}
|
|
161
207
|
}
|
|
162
208
|
}
|
|
163
209
|
`;
|
|
164
210
|
const client = gqlInstance.client;
|
|
165
|
-
const
|
|
166
|
-
|
|
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)
|
|
167
224
|
return;
|
|
168
|
-
const
|
|
225
|
+
const { isMigrated, createdAt } = domain;
|
|
169
226
|
let returnedRecords = {};
|
|
170
|
-
if (!
|
|
227
|
+
if (!resolverResponse)
|
|
171
228
|
return { isMigrated, createdAt };
|
|
229
|
+
if (!wantedRecords)
|
|
230
|
+
return {
|
|
231
|
+
isMigrated,
|
|
232
|
+
createdAt,
|
|
233
|
+
graphResolverAddress: resolverResponse.address || resolverAddress,
|
|
234
|
+
};
|
|
172
235
|
Object.keys(wantedRecords).forEach((key) => {
|
|
173
236
|
const data = wantedRecords[key];
|
|
174
237
|
if (typeof data === 'boolean' && data) {
|
|
@@ -180,28 +243,40 @@ const graphFetch = async ({ gqlInstance }, name, wantedRecords) => {
|
|
|
180
243
|
}
|
|
181
244
|
}
|
|
182
245
|
});
|
|
183
|
-
return {
|
|
246
|
+
return {
|
|
247
|
+
...returnedRecords,
|
|
248
|
+
isMigrated,
|
|
249
|
+
createdAt,
|
|
250
|
+
graphResolverAddress: resolverResponse.address || resolverAddress,
|
|
251
|
+
};
|
|
184
252
|
};
|
|
185
|
-
const getProfileFromName = async ({ contracts, gqlInstance, _getAddr, _getContentHash, _getText, resolverMulticallWrapper, }, name, options) => {
|
|
186
|
-
const
|
|
187
|
-
|
|
253
|
+
const getProfileFromName = async ({ contracts, gqlInstance, _getAddr, _getContentHash, _getText, resolverMulticallWrapper, multicallWrapper, }, name, options) => {
|
|
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 }
|
|
188
260
|
: undefined;
|
|
189
|
-
const graphResult = await graphFetch({ gqlInstance }, name, usingOptions);
|
|
261
|
+
const graphResult = await graphFetch({ gqlInstance }, name, usingOptions, resolverAddress);
|
|
190
262
|
if (!graphResult)
|
|
191
263
|
return;
|
|
192
|
-
const { isMigrated, createdAt, ...wantedRecords } = graphResult;
|
|
264
|
+
const { isMigrated, createdAt, graphResolverAddress, ...wantedRecords } = graphResult;
|
|
265
|
+
if (!graphResolverAddress && !options?.resolverAddress)
|
|
266
|
+
return { isMigrated, createdAt, message: "Name doesn't have a resolver" };
|
|
193
267
|
const result = await getDataForName({
|
|
194
268
|
contracts,
|
|
195
269
|
_getAddr,
|
|
196
270
|
_getContentHash,
|
|
197
271
|
_getText,
|
|
198
272
|
resolverMulticallWrapper,
|
|
199
|
-
|
|
273
|
+
multicallWrapper,
|
|
274
|
+
}, name, usingOptions ? wantedRecords : options, graphResolverAddress, options?.resolverAddress);
|
|
200
275
|
if (!result)
|
|
201
276
|
return { isMigrated, createdAt, message: "Records fetch didn't complete" };
|
|
202
277
|
return { ...result, isMigrated, createdAt, message: undefined };
|
|
203
278
|
};
|
|
204
|
-
const getProfileFromAddress = async ({ contracts, gqlInstance, getName, _getAddr, _getContentHash, _getText, resolverMulticallWrapper, }, address, options) => {
|
|
279
|
+
const getProfileFromAddress = async ({ contracts, gqlInstance, getName, _getAddr, _getContentHash, _getText, resolverMulticallWrapper, multicallWrapper, }, address, options) => {
|
|
205
280
|
let name;
|
|
206
281
|
try {
|
|
207
282
|
name = await getName(address);
|
|
@@ -220,6 +295,7 @@ const getProfileFromAddress = async ({ contracts, gqlInstance, getName, _getAddr
|
|
|
220
295
|
_getContentHash,
|
|
221
296
|
_getText,
|
|
222
297
|
resolverMulticallWrapper,
|
|
298
|
+
multicallWrapper,
|
|
223
299
|
}, name.name, options);
|
|
224
300
|
if (!result || result.message)
|
|
225
301
|
return;
|
|
@@ -230,7 +306,7 @@ const getProfileFromAddress = async ({ contracts, gqlInstance, getName, _getAddr
|
|
|
230
306
|
message: undefined,
|
|
231
307
|
};
|
|
232
308
|
};
|
|
233
|
-
async function default_1({ contracts, gqlInstance, getName, _getAddr, _getContentHash, _getText, resolverMulticallWrapper, }, nameOrAddress, options) {
|
|
309
|
+
async function default_1({ contracts, gqlInstance, getName, _getAddr, _getContentHash, _getText, resolverMulticallWrapper, multicallWrapper, }, nameOrAddress, options) {
|
|
234
310
|
if (options && options.coinTypes && typeof options.coinTypes !== 'boolean') {
|
|
235
311
|
options.coinTypes = options.coinTypes.map((coin) => {
|
|
236
312
|
if (!isNaN(parseInt(coin))) {
|
|
@@ -254,6 +330,7 @@ async function default_1({ contracts, gqlInstance, getName, _getAddr, _getConten
|
|
|
254
330
|
_getContentHash,
|
|
255
331
|
_getText,
|
|
256
332
|
resolverMulticallWrapper,
|
|
333
|
+
multicallWrapper,
|
|
257
334
|
}, nameOrAddress, options);
|
|
258
335
|
}
|
|
259
336
|
return getProfileFromName({
|
|
@@ -263,6 +340,7 @@ async function default_1({ contracts, gqlInstance, getName, _getAddr, _getConten
|
|
|
263
340
|
_getContentHash,
|
|
264
341
|
_getText,
|
|
265
342
|
resolverMulticallWrapper,
|
|
343
|
+
multicallWrapper,
|
|
266
344
|
}, nameOrAddress, options);
|
|
267
345
|
}
|
|
268
346
|
exports.default = default_1;
|
|
@@ -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;
|