@ensdomains/ensjs 3.0.0-alpha.1 → 3.0.0-alpha.4
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/functions/burnFuses.d.ts +1 -2
- package/dist/cjs/functions/burnFuses.js +3 -3
- package/dist/cjs/functions/createSubname.js +2 -1
- 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 +1 -1
- package/dist/cjs/functions/getProfile.js +49 -15
- package/dist/cjs/functions/getSpecificRecord.js +22 -5
- package/dist/cjs/functions/getSubnames.js +6 -6
- package/dist/cjs/functions/setRecords.d.ts +1 -2
- package/dist/cjs/functions/setRecords.js +3 -3
- package/dist/cjs/functions/setResolver.d.ts +1 -2
- package/dist/cjs/functions/setResolver.js +3 -3
- package/dist/cjs/functions/transferName.js +3 -2
- package/dist/cjs/functions/transferSubname.js +2 -1
- package/dist/cjs/functions/unwrapName.js +2 -1
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js +2 -0
- package/dist/cjs/utils/makeHashIndexes.js +2 -2
- package/dist/cjs/utils/normalise.d.ts +1 -0
- package/dist/cjs/utils/normalise.js +20 -1
- package/dist/cjs/utils/registerHelpers.js +3 -4
- package/dist/esm/functions/burnFuses.d.ts +1 -2
- package/dist/esm/functions/burnFuses.js +3 -3
- package/dist/esm/functions/createSubname.js +2 -1
- 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 +1 -1
- package/dist/esm/functions/getProfile.js +49 -15
- package/dist/esm/functions/getSpecificRecord.js +22 -5
- package/dist/esm/functions/getSubnames.js +3 -3
- package/dist/esm/functions/setRecords.d.ts +1 -2
- package/dist/esm/functions/setRecords.js +3 -3
- package/dist/esm/functions/setResolver.d.ts +1 -2
- package/dist/esm/functions/setResolver.js +3 -3
- package/dist/esm/functions/transferName.js +3 -2
- package/dist/esm/functions/transferSubname.js +2 -1
- package/dist/esm/functions/unwrapName.js +2 -1
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/utils/makeHashIndexes.js +2 -2
- package/dist/esm/utils/normalise.d.ts +1 -0
- package/dist/esm/utils/normalise.js +18 -0
- package/dist/esm/utils/registerHelpers.js +3 -4
- package/package.json +11 -5
- package/src/@types/dns-packet/index.d.ts +114 -0
- 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 +4 -3
- package/src/functions/burnFuses.ts +3 -3
- package/src/{tests → functions}/createSubname.test.ts +5 -6
- package/src/functions/createSubname.ts +2 -1
- package/src/{tests → functions}/deleteSubname.test.ts +5 -6
- 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 +1 -1
- 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 +11 -1
- package/src/functions/getOwner.ts +7 -7
- package/src/{tests → functions}/getProfile.test.ts +29 -11
- package/src/functions/getProfile.ts +77 -13
- 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 +1 -1
- package/src/{tests → functions}/setRecords.test.ts +4 -4
- package/src/functions/setRecords.ts +3 -3
- package/src/{tests → functions}/setResolver.test.ts +1 -1
- package/src/functions/setResolver.ts +3 -3
- package/src/{tests → functions}/transferName.test.ts +4 -3
- package/src/functions/transferName.ts +3 -2
- package/src/{tests → functions}/transferSubname.test.ts +5 -6
- package/src/functions/transferSubname.ts +2 -1
- package/src/{tests → functions}/unwrapName.test.ts +3 -2
- package/src/functions/unwrapName.ts +2 -1
- package/src/{tests → functions}/wrapName.test.ts +5 -8
- package/src/index.ts +7 -0
- package/src/tests/withProvider.test.ts +1 -1
- package/src/utils/makeHashIndexes.ts +4 -4
- package/src/utils/normalise.ts +23 -0
- package/src/utils/registerHelpers.ts +3 -4
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**
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { ethers } from 'ethers';
|
|
2
1
|
import { ENSArgs } from '..';
|
|
3
2
|
import { FuseOptions } from '../@types/FuseOptions';
|
|
4
|
-
export default function ({ contracts, provider }: ENSArgs<'contracts' | 'provider'>, name: string, fusesToBurn: FuseOptions): Promise<ethers.ContractTransaction>;
|
|
3
|
+
export default function ({ contracts, provider }: ENSArgs<'contracts' | 'provider'>, name: string, fusesToBurn: FuseOptions): Promise<import("ethers").ContractTransaction>;
|
|
@@ -3,16 +3,16 @@ 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"));
|
|
7
|
+
const normalise_1 = require("../utils/normalise");
|
|
8
8
|
async function default_1({ contracts, provider }, name, fusesToBurn) {
|
|
9
9
|
const signer = provider?.getSigner();
|
|
10
10
|
if (!signer) {
|
|
11
11
|
throw new Error('No signer found');
|
|
12
12
|
}
|
|
13
13
|
const nameWrapper = (await contracts?.getNameWrapper()).connect(signer);
|
|
14
|
-
const
|
|
14
|
+
const hash = (0, normalise_1.namehash)(name);
|
|
15
15
|
const encodedFuses = (0, generateFuseInput_1.default)(fusesToBurn);
|
|
16
|
-
return nameWrapper.burnFuses(
|
|
16
|
+
return nameWrapper.burnFuses(hash, encodedFuses);
|
|
17
17
|
}
|
|
18
18
|
exports.default = default_1;
|
|
@@ -5,6 +5,7 @@ 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
|
+
const normalise_1 = require("../utils/normalise");
|
|
8
9
|
async function default_1({ contracts, provider }, { name, owner, resolverAddress, contract, options, ...wrapperArgs }) {
|
|
9
10
|
const signer = provider?.getSigner(options?.addressOrIndex);
|
|
10
11
|
if (!signer) {
|
|
@@ -22,7 +23,7 @@ async function default_1({ contracts, provider }, { name, owner, resolverAddress
|
|
|
22
23
|
}
|
|
23
24
|
const label = labels.shift();
|
|
24
25
|
const labelhash = ethers_1.ethers.utils.solidityKeccak256(['string'], [label]);
|
|
25
|
-
const parentNodehash =
|
|
26
|
+
const parentNodehash = (0, normalise_1.namehash)(labels.join('.'));
|
|
26
27
|
switch (contract) {
|
|
27
28
|
case 'registry': {
|
|
28
29
|
const registry = (await contracts?.getRegistry()).connect(signer);
|
|
@@ -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,5 @@ declare type ProfileOptions = {
|
|
|
26
26
|
texts?: boolean | string[];
|
|
27
27
|
coinTypes?: boolean | string[];
|
|
28
28
|
};
|
|
29
|
-
export default function ({ contracts, gqlInstance, getName, _getAddr, _getContentHash, _getText, resolverMulticallWrapper, }: ENSArgs<'contracts' | 'gqlInstance' | 'getName' | '_getText' | '_getAddr' | '_getContentHash' | 'resolverMulticallWrapper'>, nameOrAddress: string, options?: ProfileOptions): Promise<ResolvedProfile | undefined>;
|
|
29
|
+
export default function ({ contracts, gqlInstance, getName, _getAddr, _getContentHash, _getText, resolverMulticallWrapper, multicallWrapper, }: ENSArgs<'contracts' | 'gqlInstance' | 'getName' | '_getText' | '_getAddr' | '_getContentHash' | 'resolverMulticallWrapper' | 'multicallWrapper'>, nameOrAddress: string, options?: ProfileOptions): Promise<ResolvedProfile | undefined>;
|
|
30
30
|
export {};
|
|
@@ -42,23 +42,39 @@ const makeMulticallData = async ({ _getAddr, _getContentHash, _getText, resolver
|
|
|
42
42
|
const prRawData = await resolverMulticallWrapper.raw(calls.map((x) => x.data));
|
|
43
43
|
return { data: prRawData.data, calls };
|
|
44
44
|
};
|
|
45
|
-
const
|
|
46
|
-
const
|
|
45
|
+
const fetchWithoutResolverMulticall = async ({ multicallWrapper }, calls, resolverAddress) => {
|
|
46
|
+
const callsWithResolver = calls.map((call) => ({
|
|
47
|
+
to: resolverAddress,
|
|
48
|
+
data: call.data.data,
|
|
49
|
+
}));
|
|
50
|
+
return (await multicallWrapper(callsWithResolver)).map((x) => x[1]);
|
|
51
|
+
};
|
|
52
|
+
const getDataForName = async ({ contracts, _getAddr, _getContentHash, _getText, resolverMulticallWrapper, multicallWrapper, }, name, options, fallbackResolver) => {
|
|
47
53
|
const universalResolver = await contracts?.getUniversalResolver();
|
|
48
54
|
const { data, calls } = await makeMulticallData({ _getAddr, _getContentHash, _getText, resolverMulticallWrapper }, name, options);
|
|
49
|
-
let
|
|
55
|
+
let resolvedData;
|
|
56
|
+
let useFallbackResolver = false;
|
|
50
57
|
try {
|
|
51
|
-
|
|
58
|
+
resolvedData = await universalResolver?.resolve((0, hexEncodedName_1.hexEncodeName)(name), data);
|
|
52
59
|
}
|
|
53
60
|
catch {
|
|
54
|
-
|
|
61
|
+
useFallbackResolver = true;
|
|
62
|
+
}
|
|
63
|
+
let resolverAddress;
|
|
64
|
+
let recordData;
|
|
65
|
+
if (useFallbackResolver) {
|
|
66
|
+
resolverAddress = fallbackResolver;
|
|
67
|
+
recordData = await fetchWithoutResolverMulticall({ multicallWrapper }, calls, resolverAddress);
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
resolverAddress = resolvedData['1'];
|
|
71
|
+
[recordData] = await resolverMulticallWrapper.decode(resolvedData['0']);
|
|
55
72
|
}
|
|
56
|
-
const [recordData] = await resolverMulticallWrapper.decode(resolver['0']);
|
|
57
73
|
const matchAddress = recordData[calls.findIndex((x) => x.key === '60')];
|
|
58
74
|
return {
|
|
59
75
|
address: matchAddress && (await _getAddr.decode(matchAddress)),
|
|
60
76
|
records: await formatRecords({ _getAddr, _getContentHash, _getText }, recordData, calls, options),
|
|
61
|
-
resolverAddress
|
|
77
|
+
resolverAddress,
|
|
62
78
|
};
|
|
63
79
|
};
|
|
64
80
|
const formatRecords = async ({ _getText, _getAddr, _getContentHash, }, data, calls, options) => {
|
|
@@ -68,7 +84,7 @@ const formatRecords = async ({ _getText, _getAddr, _getContentHash, }, data, cal
|
|
|
68
84
|
key: calls[i].key,
|
|
69
85
|
type: calls[i].type,
|
|
70
86
|
};
|
|
71
|
-
if (itemRet.type === '
|
|
87
|
+
if (itemRet.type === 'contenthash') {
|
|
72
88
|
decodedFromAbi = ethers_1.ethers.utils.defaultAbiCoder.decode(['bytes'], item)[0];
|
|
73
89
|
if (ethers_1.ethers.utils.hexStripZeros(decodedFromAbi) === '0x') {
|
|
74
90
|
return;
|
|
@@ -157,6 +173,7 @@ const graphFetch = async ({ gqlInstance }, name, wantedRecords) => {
|
|
|
157
173
|
addr {
|
|
158
174
|
id
|
|
159
175
|
}
|
|
176
|
+
address
|
|
160
177
|
}
|
|
161
178
|
}
|
|
162
179
|
}
|
|
@@ -167,8 +184,14 @@ const graphFetch = async ({ gqlInstance }, name, wantedRecords) => {
|
|
|
167
184
|
return;
|
|
168
185
|
const [{ resolver: resolverResponse, isMigrated, createdAt }] = domains;
|
|
169
186
|
let returnedRecords = {};
|
|
170
|
-
if (!
|
|
187
|
+
if (!resolverResponse)
|
|
171
188
|
return { isMigrated, createdAt };
|
|
189
|
+
if (!wantedRecords)
|
|
190
|
+
return {
|
|
191
|
+
isMigrated,
|
|
192
|
+
createdAt,
|
|
193
|
+
graphResolverAddress: resolverResponse.address,
|
|
194
|
+
};
|
|
172
195
|
Object.keys(wantedRecords).forEach((key) => {
|
|
173
196
|
const data = wantedRecords[key];
|
|
174
197
|
if (typeof data === 'boolean' && data) {
|
|
@@ -180,28 +203,36 @@ const graphFetch = async ({ gqlInstance }, name, wantedRecords) => {
|
|
|
180
203
|
}
|
|
181
204
|
}
|
|
182
205
|
});
|
|
183
|
-
return {
|
|
206
|
+
return {
|
|
207
|
+
...returnedRecords,
|
|
208
|
+
isMigrated,
|
|
209
|
+
createdAt,
|
|
210
|
+
graphResolverAddress: resolverResponse.address,
|
|
211
|
+
};
|
|
184
212
|
};
|
|
185
|
-
const getProfileFromName = async ({ contracts, gqlInstance, _getAddr, _getContentHash, _getText, resolverMulticallWrapper, }, name, options) => {
|
|
213
|
+
const getProfileFromName = async ({ contracts, gqlInstance, _getAddr, _getContentHash, _getText, resolverMulticallWrapper, multicallWrapper, }, name, options) => {
|
|
186
214
|
const usingOptions = !options || options?.texts === true || options?.coinTypes === true
|
|
187
215
|
? options || { contentHash: true, texts: true, coinTypes: true }
|
|
188
216
|
: undefined;
|
|
189
217
|
const graphResult = await graphFetch({ gqlInstance }, name, usingOptions);
|
|
190
218
|
if (!graphResult)
|
|
191
219
|
return;
|
|
192
|
-
const { isMigrated, createdAt, ...wantedRecords } = graphResult;
|
|
220
|
+
const { isMigrated, createdAt, graphResolverAddress, ...wantedRecords } = graphResult;
|
|
221
|
+
if (!graphResolverAddress)
|
|
222
|
+
return { isMigrated, createdAt, message: "Name doesn't have a resolver" };
|
|
193
223
|
const result = await getDataForName({
|
|
194
224
|
contracts,
|
|
195
225
|
_getAddr,
|
|
196
226
|
_getContentHash,
|
|
197
227
|
_getText,
|
|
198
228
|
resolverMulticallWrapper,
|
|
199
|
-
|
|
229
|
+
multicallWrapper,
|
|
230
|
+
}, name, usingOptions ? wantedRecords : options, graphResolverAddress);
|
|
200
231
|
if (!result)
|
|
201
232
|
return { isMigrated, createdAt, message: "Records fetch didn't complete" };
|
|
202
233
|
return { ...result, isMigrated, createdAt, message: undefined };
|
|
203
234
|
};
|
|
204
|
-
const getProfileFromAddress = async ({ contracts, gqlInstance, getName, _getAddr, _getContentHash, _getText, resolverMulticallWrapper, }, address, options) => {
|
|
235
|
+
const getProfileFromAddress = async ({ contracts, gqlInstance, getName, _getAddr, _getContentHash, _getText, resolverMulticallWrapper, multicallWrapper, }, address, options) => {
|
|
205
236
|
let name;
|
|
206
237
|
try {
|
|
207
238
|
name = await getName(address);
|
|
@@ -220,6 +251,7 @@ const getProfileFromAddress = async ({ contracts, gqlInstance, getName, _getAddr
|
|
|
220
251
|
_getContentHash,
|
|
221
252
|
_getText,
|
|
222
253
|
resolverMulticallWrapper,
|
|
254
|
+
multicallWrapper,
|
|
223
255
|
}, name.name, options);
|
|
224
256
|
if (!result || result.message)
|
|
225
257
|
return;
|
|
@@ -230,7 +262,7 @@ const getProfileFromAddress = async ({ contracts, gqlInstance, getName, _getAddr
|
|
|
230
262
|
message: undefined,
|
|
231
263
|
};
|
|
232
264
|
};
|
|
233
|
-
async function default_1({ contracts, gqlInstance, getName, _getAddr, _getContentHash, _getText, resolverMulticallWrapper, }, nameOrAddress, options) {
|
|
265
|
+
async function default_1({ contracts, gqlInstance, getName, _getAddr, _getContentHash, _getText, resolverMulticallWrapper, multicallWrapper, }, nameOrAddress, options) {
|
|
234
266
|
if (options && options.coinTypes && typeof options.coinTypes !== 'boolean') {
|
|
235
267
|
options.coinTypes = options.coinTypes.map((coin) => {
|
|
236
268
|
if (!isNaN(parseInt(coin))) {
|
|
@@ -254,6 +286,7 @@ async function default_1({ contracts, gqlInstance, getName, _getAddr, _getConten
|
|
|
254
286
|
_getContentHash,
|
|
255
287
|
_getText,
|
|
256
288
|
resolverMulticallWrapper,
|
|
289
|
+
multicallWrapper,
|
|
257
290
|
}, nameOrAddress, options);
|
|
258
291
|
}
|
|
259
292
|
return getProfileFromName({
|
|
@@ -263,6 +296,7 @@ async function default_1({ contracts, gqlInstance, getName, _getAddr, _getConten
|
|
|
263
296
|
_getContentHash,
|
|
264
297
|
_getText,
|
|
265
298
|
resolverMulticallWrapper,
|
|
299
|
+
multicallWrapper,
|
|
266
300
|
}, nameOrAddress, options);
|
|
267
301
|
}
|
|
268
302
|
exports.default = default_1;
|
|
@@ -4,13 +4,14 @@ exports.getAddr = exports._getAddr = exports.getText = exports._getText = export
|
|
|
4
4
|
const address_encoder_1 = require("@ensdomains/address-encoder");
|
|
5
5
|
const ethers_1 = require("ethers");
|
|
6
6
|
const contentHash_1 = require("../utils/contentHash");
|
|
7
|
+
const normalise_1 = require("../utils/normalise");
|
|
7
8
|
exports._getContentHash = {
|
|
8
9
|
raw: async ({ contracts }, name) => {
|
|
9
10
|
const publicResolver = await contracts?.getPublicResolver();
|
|
10
11
|
return {
|
|
11
12
|
to: '0x0000000000000000000000000000000000000000',
|
|
12
13
|
data: publicResolver.interface.encodeFunctionData('contenthash', [
|
|
13
|
-
|
|
14
|
+
(0, normalise_1.namehash)(name),
|
|
14
15
|
]),
|
|
15
16
|
};
|
|
16
17
|
},
|
|
@@ -48,7 +49,7 @@ exports._getText = {
|
|
|
48
49
|
return {
|
|
49
50
|
to: '0x0000000000000000000000000000000000000000',
|
|
50
51
|
data: publicResolver.interface.encodeFunctionData('text', [
|
|
51
|
-
|
|
52
|
+
(0, normalise_1.namehash)(name),
|
|
52
53
|
key,
|
|
53
54
|
]),
|
|
54
55
|
};
|
|
@@ -80,10 +81,18 @@ exports._getAddr = {
|
|
|
80
81
|
coinType = 60;
|
|
81
82
|
}
|
|
82
83
|
const publicResolver = await contracts?.getPublicResolver();
|
|
84
|
+
if (coinType === 60 || coinType === '60') {
|
|
85
|
+
return {
|
|
86
|
+
to: '0x0000000000000000000000000000000000000000',
|
|
87
|
+
data: publicResolver.interface.encodeFunctionData('addr(bytes32)', [
|
|
88
|
+
(0, normalise_1.namehash)(name),
|
|
89
|
+
]),
|
|
90
|
+
};
|
|
91
|
+
}
|
|
83
92
|
if (bypassFormat) {
|
|
84
93
|
return {
|
|
85
94
|
to: '0x0000000000000000000000000000000000000000',
|
|
86
|
-
data: publicResolver.interface.encodeFunctionData('addr(bytes32,uint256)', [
|
|
95
|
+
data: publicResolver.interface.encodeFunctionData('addr(bytes32,uint256)', [(0, normalise_1.namehash)(name), coinType]),
|
|
87
96
|
};
|
|
88
97
|
}
|
|
89
98
|
const formatter = typeof coinType === 'string' && isNaN(parseInt(coinType))
|
|
@@ -94,7 +103,7 @@ exports._getAddr = {
|
|
|
94
103
|
}
|
|
95
104
|
return {
|
|
96
105
|
to: '0x0000000000000000000000000000000000000000',
|
|
97
|
-
data: publicResolver.interface.encodeFunctionData('addr(bytes32,uint256)', [
|
|
106
|
+
data: publicResolver.interface.encodeFunctionData('addr(bytes32,uint256)', [(0, normalise_1.namehash)(name), formatter.coinType]),
|
|
98
107
|
};
|
|
99
108
|
},
|
|
100
109
|
decode: async ({ contracts }, data, _name, coinType) => {
|
|
@@ -107,7 +116,15 @@ exports._getAddr = {
|
|
|
107
116
|
const formatter = typeof coinType === 'string' && isNaN(parseInt(coinType))
|
|
108
117
|
? address_encoder_1.formatsByName[coinType]
|
|
109
118
|
: address_encoder_1.formatsByCoinType[typeof coinType === 'number' ? coinType : parseInt(coinType)];
|
|
110
|
-
|
|
119
|
+
let response;
|
|
120
|
+
if (coinType === 60 || coinType === '60') {
|
|
121
|
+
;
|
|
122
|
+
[response] = publicResolver.interface.decodeFunctionResult('addr(bytes32)', data);
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
;
|
|
126
|
+
[response] = publicResolver.interface.decodeFunctionResult('addr(bytes32,uint256)', data);
|
|
127
|
+
}
|
|
111
128
|
if (!response)
|
|
112
129
|
return;
|
|
113
130
|
if (ethers_1.ethers.utils.hexStripZeros(response) === '0x') {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const utils_1 = require("ethers/lib/utils");
|
|
4
3
|
const format_1 = require("../utils/format");
|
|
5
4
|
const labels_1 = require("../utils/labels");
|
|
5
|
+
const normalise_1 = require("../utils/normalise");
|
|
6
6
|
const largeQuery = async ({ gqlInstance }, { name, page, pageSize = 10, orderDirection, orderBy, lastSubnames }) => {
|
|
7
7
|
const client = gqlInstance.client;
|
|
8
8
|
let finalQuery = gqlInstance.gql `
|
|
@@ -38,7 +38,7 @@ const largeQuery = async ({ gqlInstance }, { name, page, pageSize = 10, orderDir
|
|
|
38
38
|
}
|
|
39
39
|
`;
|
|
40
40
|
let queryVars = {
|
|
41
|
-
id: (0,
|
|
41
|
+
id: (0, normalise_1.namehash)(name),
|
|
42
42
|
first: pageSize,
|
|
43
43
|
lastCreatedAt: lastSubnames[lastSubnames.length - 1]?.createdAt,
|
|
44
44
|
orderBy,
|
|
@@ -55,7 +55,7 @@ const largeQuery = async ({ gqlInstance }, { name, page, pageSize = 10, orderDir
|
|
|
55
55
|
});
|
|
56
56
|
return {
|
|
57
57
|
subnames: subdomains,
|
|
58
|
-
subnameCount: domain.subdomainCount
|
|
58
|
+
subnameCount: domain.subdomainCount,
|
|
59
59
|
};
|
|
60
60
|
};
|
|
61
61
|
const smallQuery = async ({ gqlInstance }, { name, page, pageSize = 10, orderDirection, orderBy }) => {
|
|
@@ -94,7 +94,7 @@ const smallQuery = async ({ gqlInstance }, { name, page, pageSize = 10, orderDir
|
|
|
94
94
|
}
|
|
95
95
|
`;
|
|
96
96
|
queryVars = {
|
|
97
|
-
id: (0,
|
|
97
|
+
id: (0, normalise_1.namehash)(name),
|
|
98
98
|
orderBy,
|
|
99
99
|
orderDirection,
|
|
100
100
|
};
|
|
@@ -124,7 +124,7 @@ const smallQuery = async ({ gqlInstance }, { name, page, pageSize = 10, orderDir
|
|
|
124
124
|
}
|
|
125
125
|
`;
|
|
126
126
|
queryVars = {
|
|
127
|
-
id: (0,
|
|
127
|
+
id: (0, normalise_1.namehash)(name),
|
|
128
128
|
first: pageSize,
|
|
129
129
|
skip: (page || 0) * pageSize,
|
|
130
130
|
orderBy,
|
|
@@ -142,7 +142,7 @@ const smallQuery = async ({ gqlInstance }, { name, page, pageSize = 10, orderDir
|
|
|
142
142
|
});
|
|
143
143
|
return {
|
|
144
144
|
subnames: subdomains,
|
|
145
|
-
subnameCount: domain.subdomainCount
|
|
145
|
+
subnameCount: domain.subdomainCount,
|
|
146
146
|
};
|
|
147
147
|
};
|
|
148
148
|
const getSubnames = (injected, functionArgs) => {
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { ethers } from 'ethers';
|
|
2
1
|
import { ENSArgs } from '..';
|
|
3
2
|
import { RecordOptions } from '../utils/recordHelpers';
|
|
4
|
-
export default function ({ contracts, provider, getResolver, }: ENSArgs<'contracts' | 'provider' | 'getResolver'>, name: string, records: RecordOptions): Promise<ethers.ContractTransaction | undefined>;
|
|
3
|
+
export default function ({ contracts, provider, getResolver, }: ENSArgs<'contracts' | 'provider' | 'getResolver'>, name: string, records: RecordOptions): Promise<import("ethers").ContractTransaction | undefined>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
3
|
+
const normalise_1 = require("../utils/normalise");
|
|
4
4
|
const recordHelpers_1 = require("../utils/recordHelpers");
|
|
5
5
|
async function default_1({ contracts, provider, getResolver, }, name, records) {
|
|
6
6
|
if (!name.includes('.')) {
|
|
@@ -15,8 +15,8 @@ async function default_1({ contracts, provider, getResolver, }, name, records) {
|
|
|
15
15
|
throw new Error('No signer found');
|
|
16
16
|
}
|
|
17
17
|
const resolver = (await contracts?.getPublicResolver(provider, resolverAddress))?.connect(provider?.getSigner());
|
|
18
|
-
const
|
|
19
|
-
const calls = (0, recordHelpers_1.generateRecordCallArray)(
|
|
18
|
+
const hash = (0, normalise_1.namehash)(name);
|
|
19
|
+
const calls = (0, recordHelpers_1.generateRecordCallArray)(hash, records, resolver);
|
|
20
20
|
return resolver?.multicall(calls);
|
|
21
21
|
}
|
|
22
22
|
exports.default = default_1;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { ethers } from 'ethers';
|
|
2
1
|
import { ENSArgs } from '..';
|
|
3
2
|
export default function ({ contracts, provider }: ENSArgs<'contracts' | 'provider'>, name: string, contract: 'registry' | 'nameWrapper', resolver?: string, options?: {
|
|
4
3
|
addressOrIndex?: string | number;
|
|
5
|
-
}): Promise<ethers.ContractTransaction>;
|
|
4
|
+
}): Promise<import("ethers").ContractTransaction>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
3
|
+
const normalise_1 = require("../utils/normalise");
|
|
4
4
|
async function default_1({ contracts, provider }, name, contract, resolver, options) {
|
|
5
5
|
const address = await provider
|
|
6
6
|
?.getSigner(options?.addressOrIndex)
|
|
@@ -14,11 +14,11 @@ async function default_1({ contracts, provider }, name, contract, resolver, opti
|
|
|
14
14
|
switch (contract) {
|
|
15
15
|
case 'registry': {
|
|
16
16
|
const registry = (await contracts?.getRegistry()).connect(provider?.getSigner(options?.addressOrIndex));
|
|
17
|
-
return registry.setResolver(
|
|
17
|
+
return registry.setResolver((0, normalise_1.namehash)(name), resolver);
|
|
18
18
|
}
|
|
19
19
|
case 'nameWrapper': {
|
|
20
20
|
const nameWrapper = (await contracts?.getNameWrapper()).connect(provider?.getSigner(options?.addressOrIndex));
|
|
21
|
-
return nameWrapper.setResolver(
|
|
21
|
+
return nameWrapper.setResolver((0, normalise_1.namehash)(name), resolver);
|
|
22
22
|
}
|
|
23
23
|
default: {
|
|
24
24
|
throw new Error(`Unknown contract: ${contract}`);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const ethers_1 = require("ethers");
|
|
4
|
+
const normalise_1 = require("../utils/normalise");
|
|
4
5
|
async function default_1({ contracts, provider }, name, newOwner, contract, options) {
|
|
5
6
|
const address = await provider
|
|
6
7
|
?.getSigner(options?.addressOrIndex)
|
|
@@ -11,7 +12,7 @@ async function default_1({ contracts, provider }, name, newOwner, contract, opti
|
|
|
11
12
|
switch (contract) {
|
|
12
13
|
case 'registry': {
|
|
13
14
|
const registry = (await contracts?.getRegistry()).connect(provider?.getSigner(options?.addressOrIndex));
|
|
14
|
-
return registry.setOwner(
|
|
15
|
+
return registry.setOwner((0, normalise_1.namehash)(name), newOwner);
|
|
15
16
|
}
|
|
16
17
|
case 'baseRegistrar': {
|
|
17
18
|
const baseRegistrar = (await contracts?.getBaseRegistrar()).connect(provider?.getSigner(options?.addressOrIndex));
|
|
@@ -23,7 +24,7 @@ async function default_1({ contracts, provider }, name, newOwner, contract, opti
|
|
|
23
24
|
}
|
|
24
25
|
case 'nameWrapper': {
|
|
25
26
|
const nameWrapper = (await contracts?.getNameWrapper()).connect(provider?.getSigner(options?.addressOrIndex));
|
|
26
|
-
return nameWrapper.safeTransferFrom(address, newOwner,
|
|
27
|
+
return nameWrapper.safeTransferFrom(address, newOwner, (0, normalise_1.namehash)(name), 1, '0x');
|
|
27
28
|
}
|
|
28
29
|
default: {
|
|
29
30
|
throw new Error(`Unknown contract: ${contract}`);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const ethers_1 = require("ethers");
|
|
4
|
+
const normalise_1 = require("../utils/normalise");
|
|
4
5
|
async function default_1({ contracts, provider }, name, contract, address, options) {
|
|
5
6
|
const signer = provider?.getSigner(options?.addressOrIndex);
|
|
6
7
|
if (!signer) {
|
|
@@ -9,7 +10,7 @@ async function default_1({ contracts, provider }, name, contract, address, optio
|
|
|
9
10
|
const labels = name.split('.');
|
|
10
11
|
const label = labels.shift();
|
|
11
12
|
const labelhash = ethers_1.ethers.utils.solidityKeccak256(['string'], [label]);
|
|
12
|
-
const parentNodehash =
|
|
13
|
+
const parentNodehash = (0, normalise_1.namehash)(labels.join('.'));
|
|
13
14
|
switch (contract) {
|
|
14
15
|
case 'registry': {
|
|
15
16
|
const registry = (await contracts?.getRegistry()).connect(signer);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const ethers_1 = require("ethers");
|
|
4
|
+
const normalise_1 = require("../utils/normalise");
|
|
4
5
|
async function default_1({ contracts, provider }, name, newController, newRegistrant, options) {
|
|
5
6
|
const signer = provider?.getSigner(options?.addressOrIndex);
|
|
6
7
|
const address = await signer?.getAddress();
|
|
@@ -9,7 +10,7 @@ async function default_1({ contracts, provider }, name, newController, newRegist
|
|
|
9
10
|
}
|
|
10
11
|
const labels = name.split('.');
|
|
11
12
|
const labelhash = ethers_1.utils.solidityKeccak256(['string'], [labels[0]]);
|
|
12
|
-
const parentNodehash =
|
|
13
|
+
const parentNodehash = (0, normalise_1.namehash)(labels.slice(1).join('.'));
|
|
13
14
|
const nameWrapper = (await contracts?.getNameWrapper()).connect(signer);
|
|
14
15
|
if (labels.length === 2 && labels[1] === 'eth') {
|
|
15
16
|
if (!newRegistrant) {
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -466,5 +466,6 @@ export declare class ENS {
|
|
|
466
466
|
transferSubname: (name: string, contract: "nameWrapper" | "registry", address: string, options?: {
|
|
467
467
|
addressOrIndex?: string | number | undefined;
|
|
468
468
|
} | undefined) => Promise<ethers.ContractTransaction>;
|
|
469
|
+
getDNSOwner: (dnsName: string) => Promise<any>;
|
|
469
470
|
}
|
|
470
471
|
export {};
|
package/dist/cjs/index.js
CHANGED
|
@@ -166,6 +166,7 @@ class ENS {
|
|
|
166
166
|
'gqlInstance',
|
|
167
167
|
'getName',
|
|
168
168
|
'resolverMulticallWrapper',
|
|
169
|
+
'multicallWrapper',
|
|
169
170
|
'_getAddr',
|
|
170
171
|
'_getContentHash',
|
|
171
172
|
'_getText',
|
|
@@ -219,5 +220,6 @@ class ENS {
|
|
|
219
220
|
createSubname = this.generateFunction('createSubname', ['contracts', 'provider']);
|
|
220
221
|
deleteSubname = this.generateFunction('deleteSubname', ['contracts', 'provider', 'transferSubname']);
|
|
221
222
|
transferSubname = this.generateFunction('transferSubname', ['contracts', 'provider']);
|
|
223
|
+
getDNSOwner = this.generateFunction('getDNSOwner', []);
|
|
222
224
|
}
|
|
223
225
|
exports.ENS = ENS;
|