How to use eth-ens-namehash - 10 common examples

To help you get started, we’ve selected a few eth-ens-namehash examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github JoinColony / colonyNetwork / test / contracts-network / colony-network.js View on Github external
it("should be able to register one unique label per user", async () => {
      const username = "test";
      const username2 = "test2";
      const hash = namehash.hash("test.user.joincolony.eth");

      // User cannot register blank label
      await checkErrorRevert(colonyNetwork.registerUserLabel("", orbitDBAddress, { from: accounts[1] }), "colony-user-label-invalid");

      // User can register unique label
      await colonyNetwork.registerUserLabel("test", orbitDBAddress, { from: accounts[1] });

      // Check label resolves correctly.
      // First, query the registry to get the resolver
      const resolverAddress = await ensRegistry.resolver(hash);
      expect(resolverAddress).to.equal(colonyNetwork.address);
      // Then query the resolver
      const resolvedAddress = await colonyNetwork.addr(hash);
      expect(resolvedAddress).to.equal(accounts[1]);
      const owner = await ensRegistry.owner(hash);
      expect(owner).to.equal(colonyNetwork.address);
github embark-framework / embark / packages / plugins / ens / src / index.js View on Github external
async function send() {
          self.ensContract = new web3.eth.Contract(config.registryAbi, config.registryAddress);
          self.registrarContract = new web3.eth.Contract(config.registrarAbi, config.registrarAddress);
          self.resolverContract = new web3.eth.Contract(config.resolverAbi, config.resolverAddress);

          const defaultAccount = await self.web3DefaultAccount;

          const rootNode = namehash.hash(registration.rootDomain);
          const reverseNode = namehash.hash(defaultAccount.toLowerCase().substr(2) + reverseAddrSuffix);
          const owner = await self.ensContract.methods.owner(rootNode).call();

          if (owner === defaultAccount) {
            return next();
          }

          // Set defaultAccount as the owner of the Registry
          secureSend(web3, self.ensContract.methods.setOwner(rootNode, defaultAccount), {
            from: defaultAccount,
            gas: ENS_GAS_PRICE
          }, false).then(() => {
            // Set Registry's resolver to the one deployed above
            return secureSend(web3, self.ensContract.methods.setResolver(rootNode, config.resolverAddress), {
              from: defaultAccount,
              gas: ENS_GAS_PRICE
github embark-framework / embark / packages / embarkjs / ens / src / index.js View on Github external
return callback('No rootDomain is declared in config/namesystem.js (register.rootDomain). Unable to register a subdomain until then.');
  }
  if (!address || !Web3.utils.isAddress(address)) {
    return callback('You need to specify a valid address for the subdomain');
  }

  // Register function generated by the index
  ENSFunctions.registerSubDomain(
    this.web3,
    this.ens,
    this.registrar,
    this.resolver,
    this.web3.eth.defaultAccount,
    name,
    this.registration.rootDomain,
    namehash.hash(address.toLowerCase().substr(2) + reverseAddrSuffix),
    address,
    console,
    EmbarkJS.Utils.secureSend,
    (err, result) => {
      if (err && err.indexOf('Transaction has been reverted by the EVM') > -1) {
        return callback('Registration was rejected. Are you the owner of the root domain?');
      }
      callback(err, result);
    });
};
github embark-framework / embark / packages / embarkjs / embarkjs-ens / src / index.js View on Github external
return callback('No rootDomain is declared in config/namesystem.js (register.rootDomain). Unable to register a subdomain until then.');
  }
  if (!address || !Web3.utils.isAddress(address)) {
    return callback('You need to specify a valid address for the subdomain');
  }

  // Register function generated by the index
  ENSFunctions.registerSubDomain(
    EmbarkJS.Blockchain.blockchainConnector.getInstance(),
    this.ens,
    this.registrar,
    this.resolver,
    EmbarkJS.Blockchain.blockchainConnector.getDefaultAccount(),
    name,
    this.registration.rootDomain,
    namehash.hash(address.toLowerCase().substr(2) + reverseAddrSuffix),
    address,
    console,
    EmbarkJS.Utils.secureSend,
    (err, result) => {
      if (err && err.indexOf('Transaction has been reverted by the EVM') > -1) {
        return callback('Registration was rejected. Are you the owner of the root domain?');
      }
      callback(err, result);
    });
};
github embark-framework / embark / packages / embarkjs-ens / src / index.js View on Github external
return callback('No rootDomain is declared in config/namesystem.js (register.rootDomain). Unable to register a subdomain until then.');
  }
  if (!address || !Web3.utils.isAddress(address)) {
    return callback('You need to specify a valid address for the subdomain');
  }

  // Register function generated by the index
  ENSFunctions.registerSubDomain(
    EmbarkJS.Blockchain.blockchainConnector.getInstance(),
    this.ens,
    this.registrar,
    this.resolver,
    EmbarkJS.Blockchain.blockchainConnector.getDefaultAccount(),
    name,
    this.registration.rootDomain,
    namehash.hash(address.toLowerCase().substr(2) + reverseAddrSuffix),
    address,
    console,
    EmbarkJS.Utils.secureSend,
    (err, result) => {
      if (err && err.indexOf('Transaction has been reverted by the EVM') > -1) {
        return callback('Registration was rejected. Are you the owner of the root domain?');
      }
      callback(err, result);
    });
};
github status-im / ens-usernames / test / usernameregistrar.spec.js View on Github external
it('should slash invalid username', async () => {
      let username = 'alicé';
      let label = web3Utils.sha3(username);
      let usernameHash = namehash.hash(username + '.' + registry.registry);
      let registrant = accountsArr[1];
      await TestToken.methods.mint(registry.price).send({from: registrant});
      await TestToken.methods.approve(UsernameRegistrar.address, registry.price).send({from: registrant});
      await UsernameRegistrar.methods.register(
        web3Utils.sha3(username),

        utils.zeroAddress,
        utils.zeroBytes32,
        utils.zeroBytes32
      ).send({from: registrant});
      await utils.increaseTime(20000)
      assert.equal(await ENSRegistry.methods.owner(usernameHash).call(), registrant);
      assert.notEqual(await UsernameRegistrar.methods.getCreationTime(label).call(), 0);
      const creationTime = await UsernameRegistrar.methods.getCreationTime(web3Utils.sha3(username)).call();
      const reserveSecret = 1337;
      const secret = web3Utils.soliditySha3(usernameHash, creationTime, reserveSecret);
github status-im / ens-usernames / test / enssubdomainregistry.js View on Github external
it('should slash invalid free subdomain', async () => {
    let subdomain = 'alicé';
    let usernameHash = namehash.hash(subdomain + '.' + domains.free.name);
    let registrant = accountsArr[1];
    let result = await ENSSubdomainRegistry.methods.register(
      web3Utils.sha3(subdomain),
      domains.free.namehash,
      utils.zeroAddress,
      utils.zeroBytes32,
      utils.zeroBytes32
    ).send({from: registrant});

    //TODO: check events
    result = await ens.methods.owner(usernameHash).call()
    assert.equal(result, registrant);
    
    let accountCreationTime = await ENSSubdomainRegistry.methods.getCreationTime(usernameHash).call();
    assert(accountCreationTime > 0);
github status-im / ens-usernames / test / enssubdomainregistry.spec.js View on Github external
it('should slash invalid subdomain', async () => {
      let subdomain = 'alicé';
      let subdomainHash = namehash.hash(subdomain + '.' + domains.free.name);
      let registrant = accountsArr[1];
      await ENSSubdomainRegistry.methods.register(
        web3Utils.sha3(subdomain),
        domains.free.namehash,
        utils.zeroAddress,
        utils.zeroBytes32,
        utils.zeroBytes32
      ).send({from: registrant});
      assert.equal(await ens.methods.owner(subdomainHash).call(), registrant);
      assert.notEqual(await ENSSubdomainRegistry.methods.getCreationTime(subdomainHash).call(), 0);
      await ENSSubdomainRegistry.methods.slashInvalidSubdomain(web3Utils.toHex(subdomain), domains.free.namehash, 4).send()
      //TODO: check events
      assert.equal(await ENSSubdomainRegistry.methods.getCreationTime(subdomainHash).call(), 0);
      assert.equal(await ens.methods.owner(subdomainHash).call(), utils.zeroAddress);
    });
    it('should not slash valid subdomain', async () => {
github status-im / ens-usernames / test / enssubdomainregistry.js View on Github external
it('should register free status contact code only resolver-defined subdomain', async () => {
    let registrant = accountsArr[2];
    let subdomain = 'bob2';
    let usernameHash = namehash.hash(subdomain + '.' + domains.free.name);
    let contactCode = '0x04dbb31252d9bddb4e4d362c7b9c80cba74732280737af97971f42ccbdc716f3f3efb1db366880e52d09b1bfd59842e833f3004088892b7d14b9ce9e957cea9a82';
    let points = utils.generateXY(contactCode);
    let result = await ENSSubdomainRegistry.methods.register(
      web3Utils.sha3(subdomain),
      domains.free.namehash,
      registrant,
      points.x,
      points.y
    ).send({from: registrant});

    result = await ens.methods.owner(usernameHash).call()
    assert.equal(result, registrant, "Owner not set");
    result = await ens.methods.resolver(usernameHash).call()
    assert.equal(result, PublicResolver.address, "PublicResolver not set");
    result = await PublicResolver.methods.pubkey(usernameHash).call();
    let pubKey = utils.keyFromXY(result[0], result[1]);
github aragon / aragen / scripts / deploy / beta-aragonid.js View on Github external
} = {}
) => {
  const log = (...args) => {
    if (verbose) {
      console.log(...args)
    }
  }

  const accounts = await getAccounts(web3)

  log(`Deploying AragonID with ENS: ${ensAddress} and owner: ${owner}`)
  const FIFSResolvingRegistrar = artifacts.require('FIFSResolvingRegistrar')
  const ENS = artifacts.require('AbstractENS')

  const publicResolver = await ENS.at(ensAddress).resolver(
    namehash('resolver.eth')
  )
  const aragonID = await FIFSResolvingRegistrar.new(
    ensAddress,
    publicResolver,
    node
  )
  await logDeploy(aragonID, { verbose })

  log('assigning ENS name to AragonID')
  const ens = ENS.at(ensAddress)

  if ((await ens.owner(node)) === accounts[0]) {
    log('Transferring name ownership from deployer to AragonID')
    await ens.setOwner(node, aragonID.address)
  } else {
    log('Creating subdomain and assigning it to AragonID')

eth-ens-namehash

A simple module for generating ENS namehashes per spec https://github.com/ethereum/EIPs/issues/137

ISC
Latest version published 7 years ago

Package Health Score

47 / 100
Full package analysis

Popular eth-ens-namehash functions