Skip to content

Instantly share code, notes, and snippets.

@kaichen
Last active November 6, 2018 06:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kaichen/e7586f33251e797b2d14f7e5d8162f63 to your computer and use it in GitHub Desktop.
Save kaichen/e7586f33251e797b2d14f7e5d8162f63 to your computer and use it in GitHub Desktop.
how to integrate with luxe IANA

luxe ens managment

data structure:

mapping(uint=>mapping(address=>bool)) public registrars; // Maps IANA IDs to authorised accounts
mapping(bytes32=>uint) public nonces; // Maps namehashes to domain nonces

keep track mapping of user id and ethereum address, and domain nonce

All name registeration is hash, using namehash algorithm, or just request to namehash API

namehash, hash of domain

about nonce, domain change index

roles

  • owner: ENS team
  • authoriser: IANA
  • transactor: pass address owner with signation to bind a domain

call setRegistrar to bind user and ethereum address

setRegistrar(uint id, address registrar)

associateWithSig to set owner to ens

associateWithSig(bytes32 node, bytes32 label, address owner, uint nonce, uint registrarId, bytes32 r, bytes32 s, uint8 v)

// get nonce first
const nonce = JSON.parse(await fetch('https://example.api/v2/nonce'))

// generate signation
const dataToSign = web3.eth.abi.encodeParameters(['bytes32','address', 'uint'], [namehash("example.luxe"), "0xcccccccccccccccccccccccccccccccccccccccc", nonce]);
const signature = web3.sign(web3.utils.sha3(dataToSign))

// request to associate owner address and domain
fetch('https://example.api/v2/associate', {
    method: 'POST',
    body: JSON.stringify({
        domain: "example.luxe",
        owner: "0xcccccccccccccccccccccccccccccccccccccccc",
        nonce: nonce,
        signature: signature,
    })
}).then(resp => { console.log(resp) })

After registration, user could set address to a ens domain, by setAddr($namehash)

http://docs.ens.domains/en/latest/userguide.html#setting-a-name-s-resolver

const ENS = require('ethereum-ens')
const ens = new ENS(window.web3)
ens.owner(namehash('example.luxe')).then(addr => {
    if (addr == web3.accounts[0]) {
        // be able to set address
    }
})
// ---
web3.eth.ens.setAddress('example.luxe', 0xcccccccccccccccccccccccccccccccccccccccc').then(result => console.log(result))

reference

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment