Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4x ENS functionality #4794

Merged
merged 16 commits into from
Mar 3, 2022
11 changes: 9 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -338,14 +338,14 @@ Released with 1.0.0-beta.37 code base.
4. The function `isAddress` now includes an optional parameter `checkChecksum` type boolean
5. `isBoolean` now accept `1`, and `0` as valid values to test. Ref: `web3-validator`

### web3-eth-accounts
#### web3-eth-accounts

1. `create` function does not take in the optional parameter `entropy`
2. `ignoreLength` will be removed as an optional parameter for `privateKeyToAccount`
3. The `Wallet` no more supports address/number indexing. Have to use `wallet.get` instead.
4. `Wallet.create` function doesn't accepts `entropy` param

### web3-validator
#### web3-validator

1. `isBoolean` now accept `1`, and `0` as valid values to test.

Expand All @@ -357,3 +357,10 @@ Released with 1.0.0-beta.37 code base.
4. `recover` function's last param is boolean `hashed`, it is used to indicate if data provided is already hashed or not. By default this function will assume data is not hashed.
5. The `Wallet` no more supports address/number indexing. Have to use `wallet.get` instead.
6. `Wallet.create` function doesn't accepts `entropy` param

#### web3-eth-ens

1. `setMultihash` is not supported in web3-eth-ens 4.x as its deprecated in ENS public resolver (https://github.com/ensdomains/resolvers/blob/master/contracts/PublicResolver.sol)
2. `setContent` is not supported in web3-eth-ens 4.x as its deprecated in ENS public resolver (https://github.com/ensdomains/resolvers/blob/master/contracts/PublicResolver.sol)
3. `getContent` is not supported in web3-eth-ens 4.x as its deprecated in ENS public resolver.
4. `getMultihash` is not supported in web3-eth-ens 4.x as its deprecated in ENS public resolver.
2 changes: 2 additions & 0 deletions packages/web3-common/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,5 @@ export const JSONRPC_ERR_UNAUTHORIZED = 4001;
export const JSONRPC_ERR_UNSUPPORTED_METHOD = 4200;
export const JSONRPC_ERR_DISCONNECTED = 4900;
export const JSONRPC_ERR_CHAIN_DISCONNECTED = 4901;

export const ERR_ENS_CHECK_INTERFACE_SUPPORT = 901;
8 changes: 8 additions & 0 deletions packages/web3-common/src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import {
ERR_INVALID_PASSWORD,
ERR_IV_LENGTH,
ERR_PBKDF2_ITERATIONS,
ERR_ENS_CHECK_INTERFACE_SUPPORT,
} from './constants';
import { isResponseWithError } from './json_rpc';

Expand Down Expand Up @@ -481,3 +482,10 @@ export class PBKDF2IterationsError extends Web3Error {
super('c > 1000, pbkdf2 is less secure with less iterations');
}
}

export class ENSCheckInterfaceSupportError extends Web3Error {
public code = ERR_ENS_CHECK_INTERFACE_SUPPORT;
public constructor(errorDetails: string) {
super(`ENS resolver check interface support error. "${errorDetails}"`);
}
}
21 changes: 21 additions & 0 deletions packages/web3-eth-ens/src/config.ts
Original file line number Diff line number Diff line change
@@ -1 +1,22 @@
export const registryContractAddress = '0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e';

// https://docs.ens.domains/contract-developer-guide/writing-a-resolver
// resolver interface Ids
export const interfaceIds: { [T: string]: string } = {
addr: '0x3b3b57de',
name: '0x691f3431',
abi: '0x2203ab56',
pubkey: '0xc8690233',
text: '0x59d1d43c',
contenthash: '0xbc1c58d1',
jdevcs marked this conversation as resolved.
Show resolved Hide resolved
};

// functions list supported in resolver interfaces
export const methodsInInterface: { [T: string]: string } = {
setAddr: 'addr',
addr: 'addr',
setPubkey: 'pubkey',
pubkey: 'pubkey',
setContenthash: 'contenthash',
contenthash: 'contenthash',
};
122 changes: 79 additions & 43 deletions packages/web3-eth-ens/src/ens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,24 @@ import { NonPayableCallOptions, TransactionReceipt, Contract } from 'web3-eth-co
import { RESOLVER } from './abi/resolver';
import { Registry } from './registry';
import { registryContractAddress } from './config';
import { Resolver } from './resolver';

export class ENS {
public _registryAddress: string;
private readonly registry: Registry;
public registryAddress: string;
private readonly _registry: Registry;
private readonly _resolver: Resolver;

public constructor(registryAddr?: string) {
this.registry = new Registry(registryAddr);
this._registryAddress = registryAddr ?? registryContractAddress; // TODO change this when eth.net is finished
this._registry = new Registry(registryAddr);
this.registryAddress = registryAddr ?? registryContractAddress; // TODO change this when eth.net is finished
this._resolver = new Resolver(this._registry);
}

/**
* Returns the Resolver by the given address
*/
public async getResolver(name: string): Promise<Contract<typeof RESOLVER>> {
return this.registry.getResolver(name);
return this._registry.getResolver(name);
}

/**
Expand All @@ -29,7 +32,7 @@ export class ENS {
address: Address,
txConfig: NonPayableCallOptions,
): Promise<TransactionReceipt | RevertInstructionError> {
return this.registry.setResolver(name, address, txConfig);
return this._registry.setResolver(name, address, txConfig);
}

/**
Expand All @@ -43,7 +46,7 @@ export class ENS {
ttl: number,
txConfig: NonPayableCallOptions,
): Promise<TransactionReceipt | RevertInstructionError> {
return this.registry.setSubnodeRecord(name, label, owner, resolver, ttl, txConfig);
return this._registry.setSubnodeRecord(name, label, owner, resolver, ttl, txConfig);
}

/**
Expand All @@ -54,21 +57,21 @@ export class ENS {
approved: boolean,
txConfig: NonPayableCallOptions,
): Promise<TransactionReceipt | RevertInstructionError> {
return this.registry.setApprovalForAll(operator, approved, txConfig);
return this._registry.setApprovalForAll(operator, approved, txConfig);
}

/**
* Returns true if the operator is approved
*/
public async isApprovedForAll(owner: Address, operator: Address): Promise<unknown> {
return this.registry.isApprovedForAll(owner, operator);
return this._registry.isApprovedForAll(owner, operator);
}

/**
* Returns true if the record exists
*/
public async recordExists(name: string): Promise<unknown> {
return this.registry.recordExists(name);
return this._registry.recordExists(name);
}

/**
Expand All @@ -80,14 +83,14 @@ export class ENS {
address: Address,
txConfig: NonPayableCallOptions,
): Promise<TransactionReceipt | RevertInstructionError> {
return this.registry.setSubnodeOwner(name, label, address, txConfig);
return this._registry.setSubnodeOwner(name, label, address, txConfig);
}

/**
* Returns the address of the owner of an ENS name.
*/
public async getTTL(name: string): Promise<unknown> {
return this.registry.getTTL(name);
return this._registry.getTTL(name);
}

/**
Expand All @@ -98,14 +101,14 @@ export class ENS {
ttl: number,
txConfig: NonPayableCallOptions,
): Promise<TransactionReceipt | RevertInstructionError> {
return this.registry.setTTL(name, ttl, txConfig);
return this._registry.setTTL(name, ttl, txConfig);
}

/**
* Returns the owner by the given name and current configured or detected Registry
*/
public async getOwner(name: string): Promise<unknown> {
return this.registry.getOwner(name);
return this._registry.getOwner(name);
}

/**
Expand All @@ -116,46 +119,79 @@ export class ENS {
address: Address,
txConfig: NonPayableCallOptions,
): Promise<TransactionReceipt | RevertInstructionError> {
return this.registry.setOwner(name, address, txConfig);
return this._registry.setOwner(name, address, txConfig);
}

// TODO in resolver
// public getAddress () { return true };

// TODO in resolver
// public setAddress () { return true };

// TODO in resolver
// public getPubkey () { return true };

// TODO in resolver
// public setPubkey (): boolean { return true };
/**
* Returns the address of the owner of an ENS name.
*/
public async setRecord(
name: string,
owner: Address,
resolver: Address,
ttl: number,
txConfig: NonPayableCallOptions,
): Promise<TransactionReceipt | RevertInstructionError> {
return this._registry.setRecord(name, owner, resolver, ttl, txConfig);
}

// TODO in resolver
// public getContent (): boolean { return true };
/*
* Sets the address of an ENS name in his resolver.
*/
public async setAddress(
name: string,
address: Address,
txConfig: NonPayableCallOptions,
): Promise<TransactionReceipt | RevertInstructionError> {
return this._resolver.setAddress(name, address, txConfig);
}

// TODO in resolver
// public setContent (): boolean { return true };
/*
* Sets the SECP256k1 public key associated with an ENS node.
*/
public async setPubkey(
name: string,
x: string,
y: string,
txConfig: NonPayableCallOptions,
): Promise<TransactionReceipt | RevertInstructionError> {
return this._resolver.setPubkey(name, x, y, txConfig);
}

// TODO in resolver
// public getContentHash (): boolean { return true };
/*
* Sets the content hash associated with an ENS node.
*/
public async setContenthash(
name: string,
hash: string,
txConfig: NonPayableCallOptions,
): Promise<TransactionReceipt | RevertInstructionError> {
return this._resolver.setContenthash(name, hash, txConfig);
}

// TODO in resolver
// public setContentHash (): boolean { return true };
/*
* Resolves an ENS name to an Ethereum address.
*/
public async getAddress(ENSName: string) {
return this._resolver.getAddress(ENSName);
}

// TODO in resolver
// public getMultiHash (): boolean { return true };
/*
* Returns the X and Y coordinates of the curve point for the public key.
*/
public async getPubkey(ENSName: string) {
return this._resolver.getPubkey(ENSName);
}

// TODO in resolver
// public setMultiHash (): boolean { return true };
/*
* Returns the content hash object associated with an ENS node.
*/
public async getContenthash(ENSName: string) {
return this._resolver.getContenthash(ENSName);
}

// TODO after eth.net.getNetworkType is complete
// public checkNetwork (): boolean {
// return true;
// };

// TODO finish in resolver
// public supportsInterface(){
jdevcs marked this conversation as resolved.
Show resolved Hide resolved
// return true;
// }
}
21 changes: 21 additions & 0 deletions packages/web3-eth-ens/src/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,25 @@ export class Registry {
throw new Error(); // TODO: TransactionRevertError Needs to be added after web3-eth call method is implemented
}
}

public setRecord(
name: string,
owner: Address,
resolver: Address,
ttl: number,
txConfig: NonPayableCallOptions,
) {
try {
return this.contract.methods
.setRecord(
namehash(name),
inputAddressFormatter(owner),
inputAddressFormatter(resolver),
ttl,
)
.send(txConfig);
} catch (error) {
throw new Error(); // TODO: TransactionRevertError Needs to be added after web3-eth call method is implemented
}
}
}
Loading