This is documentation for the BitcoinJ-based name lookup client by Namecoin’s Lead Application Engineer Jeremy Rand. It is based on the following pre-existing projects:

  • libdohj by Ross Nicoll
  • ConsensusJ by Sean Gilligan
  • Webbtc by Marius Hanne

Warning: this is beta software, and is not suitable for production use. It is being made available for testing purposes only. It doesn’t support proxying or stream isolation. In the examples on this page, we explicitly pass command-line arguments telling the client that this is okay. Leaving off those arguments will result in an error for safety reasons.

Build prerequisites

(This is only if you want to build from source.)

GNU/Linux

  1. Install OpenJDK from your package repositories. These instructions will be updated later with specific package names. Development was done with JDK 8; JDK 7 might work but is untested.
  2. Make sure that the JAVA_HOME environment variable is set. On Jeremy’s Debian Jessie VM, he had to manually set it to /usr/lib/jvm/java-8-openjdk-amd64.
  3. Install Maven from your package repositories. These instructions will be updated later with specific package names.

Windows

  1. Install JDK. Note that Oracle’s download site doesn’t support TLS. If you enjoy being MITM-attacked and installing malware, you can download it here (non-TLS link).
  2. Make sure that the JAVA_HOME environment variable is set. On Jeremy’s Windows 10 VM, he had to manually set it to C:\Program Files\Java\jdk1.8.0_101.
  3. Install Maven. Note that Maven’s official download site uses non-TLS downloads (insecure), MD5 checksums (insecure), and 1024-bit DSA signing keys (insecure). If you enjoy being MITM-attacked and installing malware, you can use the Maven download page and the Maven install page.

For those of you who don’t enjoy installing malware, we suggest building from source on GNU/Linux and copying the binary to Windows.

OS X

No idea. If anyone can contribute instructions for OS X, let us know.

Build instructions

(This is only if you want to build from source.)

There are 2 different branches available. A partially-stable branch has received substantially more QA testing by the Namecoin community, but uses an older fork of libdohj and ConsensusJ. A bleeding-edge branch has received less QA testing by the Namecoin community, but uses upstream libdohj and a more recent fork of ConsensusJ. Neither branch should be considered stable, since they are both using a modified fork of ConsensusJ that is not yet upstreamed. Test reports against the bleeding-edge branch are likely to be more useful. Trying to install both branches on the same machine is likely to cause problems unless the Gradle caches are entirely cleared when switching between them.

For the partially stable branch:

git clone https://github.com/JeremyRand/libdohj.git
cd libdohj
git checkout namecoin-local-lookup-2
mvn clean install
cd namecoin
mvn clean install
cd ../..
git clone https://github.com/JeremyRand/bitcoinj-addons.git
cd bitcoinj-addons
git checkout getd4-draft-local-lookup-2
./gradlew clean :bitcoinj-daemon:assemble

For the bleeding-edge branch:

git clone https://github.com/dogecoin/libdohj.git
cd libdohj
mvn clean install
cd namecoin
mvn clean install
cd ../..
git clone https://github.com/JeremyRand/bitcoinj-addons.git
cd bitcoinj-addons
git checkout getd4-draft-local-lookup-2-rebase
./gradlew clean :bitcoinj-daemon:assemble

For the partially stable branch, the binary will be created at bitcoinj-daemon/build/libs/bitcoinj-daemon-0.1.1-SNAPSHOT.jar. For the bleeding-edge branch, the binary will be created at bitcoinj-daemon/build/libs/bitcoinj-daemon-0.2.7-SNAPSHOT.jar.

Running it

All API elements that are not directly taken from Namecoin Core (including all command-line arguments and all URL formats and JSON structures for the upstream REST API) are not guaranteed to have a stable API; they might be renamed, modified, or removed in the future.

java -jar ./bitcoinj-daemon-0.1.1-SNAPSHOT.jar --connection.proxyenabled=false --connection.streamisolation=false

The blockchain takes around 5 minutes to download. Once it is fully synchronized, the RPC server will automatically start; it listens on port 8080.

You can also customize the behavior of the server with some command line options:

--server.port=<port> (default: 8080)

Change what port the RPC server listens on.

--namelookup.latest.algo=<algo> (default: restmerkleapi)

Change how name_show lookups are performed. The following algorithms are available:

  • restheightapi: Only available on bleeding-edge branch. Looks up the height of the latest name_anyupdate operation for the name that has at least 12 confirmations by using a REST API (default URL is https://namecoin.webbtc.com/name/heights/<name>.json?raw), and retrieves that block over the P2P network. This is usually fast, but if the name is part of a very large block, it can take a couple of seconds. It reveals to the REST API which name is being looked up, and it reveals to a P2P peer what the height of that name is. The REST API can hide recent name_anyupdate operations without being detected.
  • restmerkleapi: Looks up a Merkle proof for the latest name_anyupdate operation for the name that has at least 12 confirmations by using a REST API (default URL is https://namecoin.webbtc.com/name/<name>.json?history&with_height&with_rawtx&with_mrkl_branch&with_tx_idx&raw). This is slower than restheightapi for most names, but it’s faster than restheightapi if the name is in a very large block. It reveals to the REST API which name is being looked up; it doesn’t reveal anything to the P2P network. The REST API can hide recent name_anyupdate operations without being detected.
  • restmerkleapisingle: Unreliable in the current version. Similar to restmerkleapi, but increases lookup speed by asking the REST API to only generate a Merkle proof for the most recent name_anyupdate operation for the name (default URL is https://namecoin.webbtc.com/name/<name>.json?with_height&with_rawtx&with_mrkl_branch&with_tx_idx&raw). Faster than restmerkleapi, but will return an error if the name’s most recent update has between 1 and 11 confirmations (inclusive). The REST API can hide recent name_anyupdate operations without being detected.
  • leveldbtxcache: Maintains a cache of all unexpired name_anyupdate operations, obtained by downloading full blocks (instead of just headers) for all blocks that are newer than 366 days old. Much, much faster lookups than the REST-API-based algos, and lookups don’t generate any network traffic (so lookup operations are as private as Namecoin Core). Initial syncup will take somewhat longer, and approximately 412 MB of extra storage will be used for the name database. It is not feasible for name_anyupdate operations to be hidden without detection, because full blocks are downloaded. There are known hypothetical attacks possible involving reorganizations deeper than 12 blocks; see the libdohj source code comments for details.
--namelookup.latest.resturlprefix=<prefix>
--namelookup.latest.resturlsuffix=<suffix>

Change what REST API URL is constructed; default depends on the value of --namelookup.latest.algo. The URL is constructed by concatenating the prefix, the name, and the suffix.

Using it

namecoin-cli

All API elements that are not directly taken from Namecoin Core (including the valueParsed field and name_show_at_height method) are not guaranteed to have a stable API; they might be renamed, modified, or removed in the future.

You can use the namecoin-cli tool that comes with Namecoin Core to look up names. Make sure that you’re using the correct port. Any username and password are okay.

The following RPC commands are supported:

name_show <name>

Similar to name_show provided by Namecoin Core. Does not show a result for expired names. Uses the algorithm specified by --namelookup.latest.algo. As of this writing, the vout and expired fields normally provided by Namecoin Core are not supported (they are always null). If the value field is valid as a JSON object, it will be parsed and made available as a JSON object in the valueParsed field.

name_show_at_height <name> <height>

Similar to name_show, but displays the name_anyupdate operation from the given block height, even if it isn’t the latest name_anyupdate operation for that name. Does not show a result for expired operations. Does not show a result if the specified block doesn’t contain a name_anyupdate operation for the specified name. The algorithm always retrieves the block over the P2P network. Usually faster than name_show, unless --namelookup.latest.algo=leveldbtxcache is set. It reveals to a P2P peer which block height is being looked up; it doesn’t reveal anything to a REST API.

Example usage:

./namecoin-cli -rpcport=8080 -rpcuser=user -rpcpassword=pass name_show d/domob

curl

If you don’t have namecoin-cli, any JSON-RPC client should work. For example, you can use curl:

curl --user user:pass --data-binary '{"jsonrpc":"1.0","id":"curltext","method":"name_show","params":["d/domob"]}' -H 'content-type:text/plain;' http://127.0.0.1:8080

ncdns

ncdns should work as long as it’s set to the correct port. For example, you might set the following line in ncdns.conf:

namecoinrpcaddress="127.0.0.1:8080"

However, note that --namelookup.latest.algo=leveldbtxcache will be more reliable on many setups than the other algorithms, because of DNS timeouts.