@ensdomains/ensjs 3.0.0-alpha.4 → 3.0.0-alpha.7
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/burnFuses.d.ts +3 -1
- package/dist/cjs/functions/burnFuses.js +2 -6
- package/dist/cjs/functions/createSubname.d.ts +1 -5
- package/dist/cjs/functions/createSubname.js +3 -7
- package/dist/cjs/functions/deleteSubname.d.ts +3 -3
- package/dist/cjs/functions/deleteSubname.js +5 -2
- package/dist/cjs/functions/setName.d.ts +4 -3
- package/dist/cjs/functions/setName.js +5 -10
- package/dist/cjs/functions/setRecords.d.ts +4 -1
- package/dist/cjs/functions/setRecords.js +11 -9
- package/dist/cjs/functions/setResolver.d.ts +4 -3
- package/dist/cjs/functions/setResolver.js +5 -11
- package/dist/cjs/functions/transferName.d.ts +4 -3
- package/dist/cjs/functions/transferName.js +8 -13
- package/dist/cjs/functions/transferSubname.d.ts +4 -3
- package/dist/cjs/functions/transferSubname.js +3 -7
- package/dist/cjs/functions/unwrapName.d.ts +4 -3
- package/dist/cjs/functions/unwrapName.js +3 -8
- package/dist/cjs/functions/wrapName.d.ts +5 -3
- package/dist/cjs/functions/wrapName.js +8 -12
- package/dist/cjs/index.d.ts +40 -44
- package/dist/cjs/index.js +39 -22
- package/dist/cjs/utils/normalise.d.ts +1 -1
- package/dist/cjs/utils/normalise.js +10 -3
- 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 -1
- package/dist/esm/functions/burnFuses.js +2 -6
- package/dist/esm/functions/createSubname.d.ts +1 -5
- package/dist/esm/functions/createSubname.js +3 -7
- package/dist/esm/functions/deleteSubname.d.ts +3 -3
- package/dist/esm/functions/deleteSubname.js +5 -2
- package/dist/esm/functions/setName.d.ts +4 -3
- package/dist/esm/functions/setName.js +5 -10
- package/dist/esm/functions/setRecords.d.ts +4 -1
- package/dist/esm/functions/setRecords.js +11 -9
- package/dist/esm/functions/setResolver.d.ts +4 -3
- package/dist/esm/functions/setResolver.js +5 -11
- package/dist/esm/functions/transferName.d.ts +4 -3
- package/dist/esm/functions/transferName.js +8 -13
- package/dist/esm/functions/transferSubname.d.ts +4 -3
- package/dist/esm/functions/transferSubname.js +3 -7
- package/dist/esm/functions/unwrapName.d.ts +4 -3
- package/dist/esm/functions/unwrapName.js +3 -8
- package/dist/esm/functions/wrapName.d.ts +5 -3
- package/dist/esm/functions/wrapName.js +8 -12
- package/dist/esm/index.d.ts +40 -44
- package/dist/esm/index.js +39 -22
- package/dist/esm/utils/normalise.d.ts +1 -1
- package/dist/esm/utils/normalise.js +10 -3
- package/dist/esm/utils/writeTx.d.ts +4 -0
- package/dist/esm/utils/writeTx.js +1 -0
- package/package.json +7 -5
- package/src/GqlManager.test.ts +170 -0
- package/src/GqlManager.ts +67 -2
- package/src/functions/burnFuses.test.ts +9 -8
- package/src/functions/burnFuses.ts +7 -9
- package/src/functions/createSubname.test.ts +8 -11
- package/src/functions/createSubname.ts +5 -12
- package/src/functions/deleteSubname.test.ts +28 -27
- package/src/functions/deleteSubname.ts +9 -12
- package/src/functions/getFuses.test.ts +11 -9
- package/src/functions/getOwner.test.ts +3 -1
- package/src/functions/setName.test.ts +3 -2
- package/src/functions/setName.ts +15 -17
- package/src/functions/setRecords.test.ts +7 -5
- package/src/functions/setRecords.ts +19 -13
- package/src/functions/setResolver.test.ts +12 -15
- package/src/functions/setResolver.ts +14 -19
- package/src/functions/transferName.test.ts +27 -29
- package/src/functions/transferName.ts +17 -21
- package/src/functions/transferSubname.test.ts +30 -29
- package/src/functions/transferSubname.ts +19 -12
- package/src/functions/unwrapName.test.ts +22 -22
- package/src/functions/unwrapName.ts +18 -14
- package/src/functions/wrapName.test.ts +15 -12
- package/src/functions/wrapName.ts +20 -22
- package/src/index.ts +105 -30
- package/src/tests/populateTransaction.test.ts +40 -0
- package/src/tests/signerInjection.test.ts +46 -0
- package/src/utils/normalise.ts +10 -4
- package/src/utils/writeTx.ts +6 -0
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,3 +1,5 @@
|
|
|
1
1
|
import { ENSArgs } from '..';
|
|
2
2
|
import { FuseOptions } from '../@types/FuseOptions';
|
|
3
|
-
export default function ({ contracts,
|
|
3
|
+
export default function ({ contracts, signer }: ENSArgs<'contracts' | 'signer'>, name: string, { fusesToBurn, }: {
|
|
4
|
+
fusesToBurn: FuseOptions;
|
|
5
|
+
}): Promise<import("ethers").PopulatedTransaction>;
|
|
@@ -5,14 +5,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const generateFuseInput_1 = __importDefault(require("../utils/generateFuseInput"));
|
|
7
7
|
const normalise_1 = require("../utils/normalise");
|
|
8
|
-
async function default_1({ contracts,
|
|
9
|
-
const signer = provider?.getSigner();
|
|
10
|
-
if (!signer) {
|
|
11
|
-
throw new Error('No signer found');
|
|
12
|
-
}
|
|
8
|
+
async function default_1({ contracts, signer }, name, { fusesToBurn, }) {
|
|
13
9
|
const nameWrapper = (await contracts?.getNameWrapper()).connect(signer);
|
|
14
10
|
const hash = (0, normalise_1.namehash)(name);
|
|
15
11
|
const encodedFuses = (0, generateFuseInput_1.default)(fusesToBurn);
|
|
16
|
-
return nameWrapper.burnFuses(hash, encodedFuses);
|
|
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 {};
|
|
@@ -6,11 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const ethers_1 = require("ethers");
|
|
7
7
|
const generateFuseInput_1 = __importDefault(require("../utils/generateFuseInput"));
|
|
8
8
|
const normalise_1 = require("../utils/normalise");
|
|
9
|
-
async function default_1({ contracts,
|
|
10
|
-
const signer = provider?.getSigner(options?.addressOrIndex);
|
|
11
|
-
if (!signer) {
|
|
12
|
-
throw new Error('No signer found');
|
|
13
|
-
}
|
|
9
|
+
async function default_1({ contracts, signer }, name, { owner, resolverAddress, contract, ...wrapperArgs }) {
|
|
14
10
|
const labels = name.split('.');
|
|
15
11
|
if (labels.length === 1) {
|
|
16
12
|
throw new Error('Subnames in ENS.js can only be created for 2LDs, not TLDs');
|
|
@@ -27,14 +23,14 @@ async function default_1({ contracts, provider }, { name, owner, resolverAddress
|
|
|
27
23
|
switch (contract) {
|
|
28
24
|
case 'registry': {
|
|
29
25
|
const registry = (await contracts?.getRegistry()).connect(signer);
|
|
30
|
-
return registry.setSubnodeRecord(parentNodehash, labelhash, owner, resolverAddress, 0);
|
|
26
|
+
return registry.populateTransaction.setSubnodeRecord(parentNodehash, labelhash, owner, resolverAddress, 0);
|
|
31
27
|
}
|
|
32
28
|
case 'nameWrapper': {
|
|
33
29
|
const nameWrapper = (await contracts?.getNameWrapper()).connect(signer);
|
|
34
30
|
const generatedFuses = 'fuses' in wrapperArgs && wrapperArgs.fuses
|
|
35
31
|
? (0, generateFuseInput_1.default)(wrapperArgs.fuses)
|
|
36
32
|
: '0';
|
|
37
|
-
return nameWrapper.setSubnodeRecord(parentNodehash, label, owner, resolverAddress, 0, generatedFuses);
|
|
33
|
+
return nameWrapper.populateTransaction.setSubnodeRecord(parentNodehash, label, owner, resolverAddress, 0, generatedFuses);
|
|
38
34
|
}
|
|
39
35
|
default: {
|
|
40
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;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ENSArgs } from '..';
|
|
2
|
-
export default function ({ contracts,
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
export default function ({ contracts, signer }: ENSArgs<'contracts' | 'signer'>, name: string, { address, resolver, }?: {
|
|
3
|
+
address?: string;
|
|
4
|
+
resolver?: string;
|
|
5
|
+
}): Promise<import("ethers").PopulatedTransaction>;
|
|
@@ -1,17 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
async function default_1({ contracts,
|
|
4
|
-
const signerAddress = await
|
|
5
|
-
|
|
6
|
-
.getAddress();
|
|
7
|
-
if (!signerAddress) {
|
|
8
|
-
throw new Error('No signer found');
|
|
9
|
-
}
|
|
10
|
-
const reverseRegistrar = (await contracts?.getReverseRegistrar())?.connect(provider?.getSigner());
|
|
3
|
+
async function default_1({ contracts, signer }, name, { address, resolver, } = {}) {
|
|
4
|
+
const signerAddress = await signer.getAddress();
|
|
5
|
+
const reverseRegistrar = (await contracts?.getReverseRegistrar())?.connect(signer);
|
|
11
6
|
if (address) {
|
|
12
7
|
const publicResolver = await contracts?.getPublicResolver();
|
|
13
|
-
return reverseRegistrar
|
|
8
|
+
return reverseRegistrar.populateTransaction.setNameForAddr(address, signerAddress, resolver || publicResolver.address, name);
|
|
14
9
|
}
|
|
15
|
-
return reverseRegistrar
|
|
10
|
+
return reverseRegistrar.populateTransaction.setName(name);
|
|
16
11
|
}
|
|
17
12
|
exports.default = default_1;
|
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
import { ENSArgs } from '..';
|
|
2
2
|
import { RecordOptions } from '../utils/recordHelpers';
|
|
3
|
-
export default function ({ contracts, provider, getResolver, }: ENSArgs<'contracts' | 'provider' | 'getResolver'>, name: string, records
|
|
3
|
+
export default function ({ contracts, provider, getResolver, signer, }: ENSArgs<'contracts' | 'provider' | 'getResolver' | 'signer'>, name: string, { records, resolverAddress, }: {
|
|
4
|
+
records: RecordOptions;
|
|
5
|
+
resolverAddress?: string;
|
|
6
|
+
}): Promise<import("ethers").PopulatedTransaction>;
|
|
@@ -2,21 +2,23 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const normalise_1 = require("../utils/normalise");
|
|
4
4
|
const recordHelpers_1 = require("../utils/recordHelpers");
|
|
5
|
-
async function default_1({ contracts, provider, getResolver, }, name, records) {
|
|
5
|
+
async function default_1({ contracts, provider, getResolver, signer, }, name, { records, resolverAddress, }) {
|
|
6
6
|
if (!name.includes('.')) {
|
|
7
7
|
throw new Error('Input is not an ENS name');
|
|
8
8
|
}
|
|
9
|
-
|
|
10
|
-
if (
|
|
11
|
-
|
|
9
|
+
let resolverToUse;
|
|
10
|
+
if (resolverAddress) {
|
|
11
|
+
resolverToUse = resolverAddress;
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
resolverToUse = await getResolver(name);
|
|
12
15
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
throw new Error('No signer found');
|
|
16
|
+
if (!resolverToUse) {
|
|
17
|
+
throw new Error('No resolver found for input address');
|
|
16
18
|
}
|
|
17
|
-
const resolver = (await contracts?.getPublicResolver(provider,
|
|
19
|
+
const resolver = (await contracts?.getPublicResolver(provider, resolverToUse))?.connect(signer);
|
|
18
20
|
const hash = (0, normalise_1.namehash)(name);
|
|
19
21
|
const calls = (0, recordHelpers_1.generateRecordCallArray)(hash, records, resolver);
|
|
20
|
-
return resolver
|
|
22
|
+
return resolver.populateTransaction.multicall(calls);
|
|
21
23
|
}
|
|
22
24
|
exports.default = default_1;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ENSArgs } from '..';
|
|
2
|
-
export default function ({ contracts,
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
export default function ({ contracts, signer }: ENSArgs<'contracts' | 'signer'>, name: string, { contract, resolver, }: {
|
|
3
|
+
contract: 'registry' | 'nameWrapper';
|
|
4
|
+
resolver?: string;
|
|
5
|
+
}): Promise<import("ethers").PopulatedTransaction>;
|
|
@@ -1,24 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const normalise_1 = require("../utils/normalise");
|
|
4
|
-
async function default_1({ contracts,
|
|
5
|
-
const address = await provider
|
|
6
|
-
?.getSigner(options?.addressOrIndex)
|
|
7
|
-
.getAddress();
|
|
8
|
-
if (!address) {
|
|
9
|
-
throw new Error('No signer found');
|
|
10
|
-
}
|
|
4
|
+
async function default_1({ contracts, signer }, name, { contract, resolver, }) {
|
|
11
5
|
if (!resolver) {
|
|
12
6
|
resolver = (await contracts?.getPublicResolver()).address;
|
|
13
7
|
}
|
|
14
8
|
switch (contract) {
|
|
15
9
|
case 'registry': {
|
|
16
|
-
const registry = (await contracts?.getRegistry()).connect(
|
|
17
|
-
return registry.setResolver((0, normalise_1.namehash)(name), resolver);
|
|
10
|
+
const registry = (await contracts?.getRegistry()).connect(signer);
|
|
11
|
+
return registry.populateTransaction.setResolver((0, normalise_1.namehash)(name), resolver);
|
|
18
12
|
}
|
|
19
13
|
case 'nameWrapper': {
|
|
20
|
-
const nameWrapper = (await contracts?.getNameWrapper()).connect(
|
|
21
|
-
return nameWrapper.setResolver((0, normalise_1.namehash)(name), resolver);
|
|
14
|
+
const nameWrapper = (await contracts?.getNameWrapper()).connect(signer);
|
|
15
|
+
return nameWrapper.populateTransaction.setResolver((0, normalise_1.namehash)(name), resolver);
|
|
22
16
|
}
|
|
23
17
|
default: {
|
|
24
18
|
throw new Error(`Unknown contract: ${contract}`);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ethers } from 'ethers';
|
|
2
2
|
import { ENSArgs } from '..';
|
|
3
|
-
export default function ({ contracts,
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
export default function ({ contracts, signer }: ENSArgs<'contracts' | 'signer'>, name: string, { newOwner, contract, }: {
|
|
4
|
+
newOwner: string;
|
|
5
|
+
contract: 'registry' | 'nameWrapper' | 'baseRegistrar';
|
|
6
|
+
}): Promise<ethers.PopulatedTransaction>;
|
|
@@ -2,29 +2,24 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const ethers_1 = require("ethers");
|
|
4
4
|
const normalise_1 = require("../utils/normalise");
|
|
5
|
-
async function default_1({ contracts,
|
|
6
|
-
const address = await
|
|
7
|
-
?.getSigner(options?.addressOrIndex)
|
|
8
|
-
.getAddress();
|
|
9
|
-
if (!address) {
|
|
10
|
-
throw new Error('No signer found');
|
|
11
|
-
}
|
|
5
|
+
async function default_1({ contracts, signer }, name, { newOwner, contract, }) {
|
|
6
|
+
const address = await signer.getAddress();
|
|
12
7
|
switch (contract) {
|
|
13
8
|
case 'registry': {
|
|
14
|
-
const registry = (await contracts?.getRegistry()).connect(
|
|
15
|
-
return registry.setOwner((0, normalise_1.namehash)(name), newOwner);
|
|
9
|
+
const registry = (await contracts?.getRegistry()).connect(signer);
|
|
10
|
+
return registry.populateTransaction.setOwner((0, normalise_1.namehash)(name), newOwner);
|
|
16
11
|
}
|
|
17
12
|
case 'baseRegistrar': {
|
|
18
|
-
const baseRegistrar = (await contracts?.getBaseRegistrar()).connect(
|
|
13
|
+
const baseRegistrar = (await contracts?.getBaseRegistrar()).connect(signer);
|
|
19
14
|
const labels = name.split('.');
|
|
20
15
|
if (labels.length > 2 || labels[labels.length - 1] !== 'eth') {
|
|
21
16
|
throw new Error('Invalid name for baseRegistrar');
|
|
22
17
|
}
|
|
23
|
-
return baseRegistrar['safeTransferFrom(address,address,uint256)'](address, newOwner, ethers_1.ethers.utils.solidityKeccak256(['string'], [labels[0]]));
|
|
18
|
+
return baseRegistrar.populateTransaction['safeTransferFrom(address,address,uint256)'](address, newOwner, ethers_1.ethers.utils.solidityKeccak256(['string'], [labels[0]]));
|
|
24
19
|
}
|
|
25
20
|
case 'nameWrapper': {
|
|
26
|
-
const nameWrapper = (await contracts?.getNameWrapper()).connect(
|
|
27
|
-
return nameWrapper.safeTransferFrom(address, newOwner, (0, normalise_1.namehash)(name), 1, '0x');
|
|
21
|
+
const nameWrapper = (await contracts?.getNameWrapper()).connect(signer);
|
|
22
|
+
return nameWrapper.populateTransaction.safeTransferFrom(address, newOwner, (0, normalise_1.namehash)(name), 1, '0x');
|
|
28
23
|
}
|
|
29
24
|
default: {
|
|
30
25
|
throw new Error(`Unknown contract: ${contract}`);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ethers } from 'ethers';
|
|
2
2
|
import { ENSArgs } from '..';
|
|
3
|
-
export default function ({ contracts,
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
export default function ({ contracts, signer }: ENSArgs<'contracts' | 'signer'>, name: string, { contract, address, }: {
|
|
4
|
+
contract: 'registry' | 'nameWrapper';
|
|
5
|
+
address: string;
|
|
6
|
+
}): Promise<ethers.PopulatedTransaction>;
|
|
@@ -2,11 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const ethers_1 = require("ethers");
|
|
4
4
|
const normalise_1 = require("../utils/normalise");
|
|
5
|
-
async function default_1({ contracts,
|
|
6
|
-
const signer = provider?.getSigner(options?.addressOrIndex);
|
|
7
|
-
if (!signer) {
|
|
8
|
-
throw new Error('No signer found');
|
|
9
|
-
}
|
|
5
|
+
async function default_1({ contracts, signer }, name, { contract, address, }) {
|
|
10
6
|
const labels = name.split('.');
|
|
11
7
|
const label = labels.shift();
|
|
12
8
|
const labelhash = ethers_1.ethers.utils.solidityKeccak256(['string'], [label]);
|
|
@@ -14,11 +10,11 @@ async function default_1({ contracts, provider }, name, contract, address, optio
|
|
|
14
10
|
switch (contract) {
|
|
15
11
|
case 'registry': {
|
|
16
12
|
const registry = (await contracts?.getRegistry()).connect(signer);
|
|
17
|
-
return registry.setSubnodeOwner(parentNodehash, labelhash, address);
|
|
13
|
+
return registry.populateTransaction.setSubnodeOwner(parentNodehash, labelhash, address);
|
|
18
14
|
}
|
|
19
15
|
case 'nameWrapper': {
|
|
20
16
|
const nameWrapper = (await contracts?.getNameWrapper()).connect(signer);
|
|
21
|
-
return nameWrapper.setSubnodeOwner(parentNodehash, label, address, '0');
|
|
17
|
+
return nameWrapper.populateTransaction.setSubnodeOwner(parentNodehash, label, address, '0');
|
|
22
18
|
}
|
|
23
19
|
default: {
|
|
24
20
|
throw new Error(`Unknown contract: ${contract}`);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ENSArgs } from '..';
|
|
2
|
-
export default function ({ contracts,
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
export default function ({ contracts, signer }: ENSArgs<'contracts' | 'signer'>, name: string, { newController, newRegistrant, }: {
|
|
3
|
+
newController: string;
|
|
4
|
+
newRegistrant?: string;
|
|
5
|
+
}): Promise<import("ethers").PopulatedTransaction>;
|
|
@@ -2,12 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const ethers_1 = require("ethers");
|
|
4
4
|
const normalise_1 = require("../utils/normalise");
|
|
5
|
-
async function default_1({ contracts,
|
|
6
|
-
const signer = provider?.getSigner(options?.addressOrIndex);
|
|
7
|
-
const address = await signer?.getAddress();
|
|
8
|
-
if (!signer || !address) {
|
|
9
|
-
throw new Error('No signer found');
|
|
10
|
-
}
|
|
5
|
+
async function default_1({ contracts, signer }, name, { newController, newRegistrant, }) {
|
|
11
6
|
const labels = name.split('.');
|
|
12
7
|
const labelhash = ethers_1.utils.solidityKeccak256(['string'], [labels[0]]);
|
|
13
8
|
const parentNodehash = (0, normalise_1.namehash)(labels.slice(1).join('.'));
|
|
@@ -16,13 +11,13 @@ async function default_1({ contracts, provider }, name, newController, newRegist
|
|
|
16
11
|
if (!newRegistrant) {
|
|
17
12
|
throw new Error('newRegistrant must be specified for .eth names');
|
|
18
13
|
}
|
|
19
|
-
return nameWrapper.unwrapETH2LD(labelhash, newRegistrant, newController);
|
|
14
|
+
return nameWrapper.populateTransaction.unwrapETH2LD(labelhash, newRegistrant, newController);
|
|
20
15
|
}
|
|
21
16
|
else {
|
|
22
17
|
if (newRegistrant) {
|
|
23
18
|
throw new Error('newRegistrant can only be specified for .eth names');
|
|
24
19
|
}
|
|
25
|
-
return nameWrapper.unwrap(parentNodehash, labelhash, newController);
|
|
20
|
+
return nameWrapper.populateTransaction.unwrap(parentNodehash, labelhash, newController);
|
|
26
21
|
}
|
|
27
22
|
}
|
|
28
23
|
exports.default = default_1;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { ethers } from 'ethers';
|
|
2
2
|
import { ENSArgs } from '..';
|
|
3
3
|
import type { FuseOptions } from '../@types/FuseOptions';
|
|
4
|
-
export default function ({ contracts,
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
export default function ({ contracts, signer, populate }: ENSArgs<'contracts' | 'signer' | 'populate'>, name: string, { wrappedOwner, fuseOptions, resolverAddress, }: {
|
|
5
|
+
wrappedOwner: string;
|
|
6
|
+
fuseOptions?: FuseOptions | string | number;
|
|
7
|
+
resolverAddress?: string;
|
|
8
|
+
}): Promise<ethers.PopulatedTransaction>;
|
|
@@ -10,24 +10,20 @@ async function wrapETH({ contracts }, labels, wrappedOwner, decodedFuses, resolv
|
|
|
10
10
|
const nameWrapper = await contracts?.getNameWrapper();
|
|
11
11
|
const baseRegistrar = (await contracts?.getBaseRegistrar()).connect(signer);
|
|
12
12
|
const labelhash = ethers_1.ethers.utils.solidityKeccak256(['string'], [labels[0]]);
|
|
13
|
-
const data = ethers_1.ethers.utils.defaultAbiCoder.encode(['string', 'address', '
|
|
14
|
-
return baseRegistrar['safeTransferFrom(address,address,uint256,bytes)'](address, nameWrapper.address, labelhash, data);
|
|
13
|
+
const data = ethers_1.ethers.utils.defaultAbiCoder.encode(['string', 'address', 'uint32', 'uint64', 'address'], [labels[0], wrappedOwner, '0x0', decodedFuses, resolverAddress]);
|
|
14
|
+
return baseRegistrar.populateTransaction['safeTransferFrom(address,address,uint256,bytes)'](address, nameWrapper.address, labelhash, data);
|
|
15
15
|
}
|
|
16
|
-
async function wrapOther({ contracts }, name, wrappedOwner, decodedFuses, resolverAddress, address) {
|
|
17
|
-
const nameWrapper = await contracts?.getNameWrapper();
|
|
16
|
+
async function wrapOther({ contracts }, name, wrappedOwner, decodedFuses, resolverAddress, address, signer) {
|
|
17
|
+
const nameWrapper = (await contracts?.getNameWrapper()).connect(signer);
|
|
18
18
|
const registry = await contracts?.getRegistry();
|
|
19
19
|
const hasApproval = await registry.isApprovedForAll(address, nameWrapper.address);
|
|
20
20
|
if (!hasApproval) {
|
|
21
21
|
throw new Error('NameWrapper must have approval to wrap a name from this address.');
|
|
22
22
|
}
|
|
23
|
-
return nameWrapper.wrap((0, hexEncodedName_1.hexEncodeName)(name), wrappedOwner, decodedFuses, resolverAddress);
|
|
23
|
+
return nameWrapper.populateTransaction.wrap((0, hexEncodedName_1.hexEncodeName)(name), wrappedOwner, decodedFuses, resolverAddress);
|
|
24
24
|
}
|
|
25
|
-
async function default_1({ contracts,
|
|
26
|
-
const
|
|
27
|
-
const address = await signer?.getAddress();
|
|
28
|
-
if (!signer || !address) {
|
|
29
|
-
throw new Error('No signer found');
|
|
30
|
-
}
|
|
25
|
+
async function default_1({ contracts, signer, populate }, name, { wrappedOwner, fuseOptions, resolverAddress, }) {
|
|
26
|
+
const address = await signer.getAddress();
|
|
31
27
|
let decodedFuses;
|
|
32
28
|
switch (typeof fuseOptions) {
|
|
33
29
|
case 'object': {
|
|
@@ -58,7 +54,7 @@ async function default_1({ contracts, provider }, name, wrappedOwner, fuseOption
|
|
|
58
54
|
return wrapETH({ contracts }, labels, wrappedOwner, decodedFuses, resolverAddress, signer, address);
|
|
59
55
|
}
|
|
60
56
|
else {
|
|
61
|
-
return wrapOther({ contracts }, name, wrappedOwner, decodedFuses, resolverAddress, address);
|
|
57
|
+
return wrapOther({ contracts }, name, wrappedOwner, decodedFuses, resolverAddress, address, signer);
|
|
62
58
|
}
|
|
63
59
|
}
|
|
64
60
|
exports.default = default_1;
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -1,7 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { JsonRpcSigner } from '@ethersproject/providers';
|
|
2
|
+
import { ContractTransaction, ethers, PopulatedTransaction } from 'ethers';
|
|
2
3
|
import ContractManager from './contracts';
|
|
3
4
|
import { getContractAddress as _getContractAddress } from './contracts/getContractAddress';
|
|
4
5
|
import { SupportedNetworkId } from './contracts/types';
|
|
6
|
+
import type burnFuses from './functions/burnFuses';
|
|
7
|
+
import type createSubname from './functions/createSubname';
|
|
8
|
+
import type deleteSubname from './functions/deleteSubname';
|
|
9
|
+
import type setName from './functions/setName';
|
|
10
|
+
import type setRecords from './functions/setRecords';
|
|
11
|
+
import type setResolver from './functions/setResolver';
|
|
12
|
+
import type transferName from './functions/transferName';
|
|
13
|
+
import type transferSubname from './functions/transferSubname';
|
|
14
|
+
import type unwrapName from './functions/unwrapName';
|
|
15
|
+
import type wrapName from './functions/wrapName';
|
|
5
16
|
import GqlManager from './GqlManager';
|
|
6
17
|
declare type ENSOptions = {
|
|
7
18
|
graphURI?: string | null;
|
|
@@ -10,6 +21,7 @@ declare type ENSOptions = {
|
|
|
10
21
|
export declare type InternalENS = {
|
|
11
22
|
options?: ENSOptions;
|
|
12
23
|
provider?: ethers.providers.Provider;
|
|
24
|
+
signer: JsonRpcSigner;
|
|
13
25
|
graphURI?: string | null;
|
|
14
26
|
} & ENS;
|
|
15
27
|
export declare type ENSArgs<K extends keyof InternalENS> = {
|
|
@@ -17,6 +29,15 @@ export declare type ENSArgs<K extends keyof InternalENS> = {
|
|
|
17
29
|
};
|
|
18
30
|
declare type OmitFirstArg<F> = F extends (x: any, ...args: infer P) => infer R ? (...args: P) => R : never;
|
|
19
31
|
declare type OmitFirstTwoArgs<F> = F extends (x: any, y: any, ...args: infer P) => infer R ? (...args: P) => R : never;
|
|
32
|
+
declare type WriteOptions = {
|
|
33
|
+
addressOrIndex?: string | number;
|
|
34
|
+
signer?: JsonRpcSigner;
|
|
35
|
+
};
|
|
36
|
+
declare type OptionalWriteOptions<F> = F extends (x: any, arg_0: infer Z, options?: infer P) => infer R ? (name: Z, options?: P & WriteOptions) => R : F extends (x: any, arg_0: infer Z, options: infer P) => infer R ? (name: Z, options: P & WriteOptions) => R : never;
|
|
37
|
+
interface WriteFunction<F extends (...args: any) => any> extends Function {
|
|
38
|
+
(...args: Parameters<OptionalWriteOptions<F>>): Promise<ContractTransaction>;
|
|
39
|
+
populateTransaction: (...args: Parameters<OptionalWriteOptions<F>>) => Promise<PopulatedTransaction>;
|
|
40
|
+
}
|
|
20
41
|
export declare type RawFunction = {
|
|
21
42
|
raw: (...args: any[]) => Promise<{
|
|
22
43
|
to: string;
|
|
@@ -77,6 +98,14 @@ export declare class ENS {
|
|
|
77
98
|
* @returns {OmitFirstArg} - The generated wrapped function
|
|
78
99
|
*/
|
|
79
100
|
private generateFunction;
|
|
101
|
+
/**
|
|
102
|
+
* Generates a write wrapped function
|
|
103
|
+
* @param {string} path - The path of the exported function
|
|
104
|
+
* @param {FunctionDeps} dependencies - An array of ENS properties
|
|
105
|
+
* @param {string} exportName - The export name of the target function
|
|
106
|
+
* @returns {OmitFirstArg} - The generated wrapped function
|
|
107
|
+
*/
|
|
108
|
+
private generateWriteFunction;
|
|
80
109
|
/**
|
|
81
110
|
* Generates a wrapped function from raw and decode exports
|
|
82
111
|
* @param {string} path - The path of the exported function
|
|
@@ -423,49 +452,16 @@ export declare class ENS {
|
|
|
423
452
|
}>;
|
|
424
453
|
decode: ({ contracts }: ENSArgs<"contracts">, data: string) => Promise<any>;
|
|
425
454
|
}>;
|
|
426
|
-
setName:
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
wrapName: (name: string, wrappedOwner: string, fuseOptions?: string | number | import("./@types/FuseOptions").FuseOptions | undefined, resolverAddress?: string | undefined, options?: {
|
|
437
|
-
addressOrIndex?: string | number | undefined;
|
|
438
|
-
} | undefined) => Promise<ethers.ContractTransaction>;
|
|
439
|
-
unwrapName: (name: string, newController: string, newRegistrant?: string | undefined, options?: {
|
|
440
|
-
addressOrIndex?: string | number | undefined;
|
|
441
|
-
} | undefined) => Promise<ethers.ContractTransaction>;
|
|
442
|
-
burnFuses: (name: string, fusesToBurn: import("./@types/FuseOptions").FuseOptions) => Promise<ethers.ContractTransaction>;
|
|
443
|
-
createSubname: (args_0: {
|
|
444
|
-
name: string;
|
|
445
|
-
owner: string;
|
|
446
|
-
resolverAddress?: string | undefined;
|
|
447
|
-
contract: "nameWrapper" | "registry";
|
|
448
|
-
options?: {
|
|
449
|
-
addressOrIndex?: string | number | undefined;
|
|
450
|
-
} | undefined;
|
|
451
|
-
} | ({
|
|
452
|
-
contract: "nameWrapper";
|
|
453
|
-
fuses?: import("./@types/FuseOptions").FuseOptions | undefined;
|
|
454
|
-
} & {
|
|
455
|
-
name: string;
|
|
456
|
-
owner: string;
|
|
457
|
-
resolverAddress?: string | undefined;
|
|
458
|
-
contract: "nameWrapper" | "registry";
|
|
459
|
-
options?: {
|
|
460
|
-
addressOrIndex?: string | number | undefined;
|
|
461
|
-
} | undefined;
|
|
462
|
-
})) => Promise<ethers.ContractTransaction>;
|
|
463
|
-
deleteSubname: (name: string, contract: "nameWrapper" | "registry", options?: {
|
|
464
|
-
addressOrIndex?: string | number | undefined;
|
|
465
|
-
} | undefined) => Promise<ethers.ContractTransaction>;
|
|
466
|
-
transferSubname: (name: string, contract: "nameWrapper" | "registry", address: string, options?: {
|
|
467
|
-
addressOrIndex?: string | number | undefined;
|
|
468
|
-
} | undefined) => Promise<ethers.ContractTransaction>;
|
|
455
|
+
setName: WriteFunction<typeof setName>;
|
|
456
|
+
setRecords: WriteFunction<typeof setRecords>;
|
|
457
|
+
setResolver: WriteFunction<typeof setResolver>;
|
|
458
|
+
transferName: WriteFunction<typeof transferName>;
|
|
459
|
+
wrapName: WriteFunction<typeof wrapName>;
|
|
460
|
+
unwrapName: WriteFunction<typeof unwrapName>;
|
|
461
|
+
burnFuses: WriteFunction<typeof burnFuses>;
|
|
462
|
+
createSubname: WriteFunction<typeof createSubname>;
|
|
463
|
+
deleteSubname: WriteFunction<typeof deleteSubname>;
|
|
464
|
+
transferSubname: WriteFunction<typeof transferSubname>;
|
|
469
465
|
getDNSOwner: (dnsName: string) => Promise<any>;
|
|
470
466
|
}
|
|
471
467
|
export {};
|