You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

1961 lines
98 KiB

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Begin Jekyll SEO tag v2.5.0 -->
<title>Blockstack Naming Service (BNS) | Blockstack</title>
<meta name="generator" content="Jekyll v3.8.3" />
<meta property="og:title" content="Blockstack Naming Service (BNS)" />
<meta name="author" content="Blockstack" />
<meta property="og:locale" content="en_US" />
<meta name="description" content="Blockstack Naming Service (BNS)" />
<meta property="og:description" content="Blockstack Naming Service (BNS)" />
<link rel="canonical" href="https://zbabystack.netlify.com/core/naming/introduction.html" />
<meta property="og:url" content="https://zbabystack.netlify.com/core/naming/introduction.html" />
<meta property="og:site_name" content="Blockstack" />
<meta property="og:type" content="article" />
<meta property="article:published_time" content="2018-08-30T13:25:56-07:00" />
<script type="application/ld+json">
{"description":"Blockstack Naming Service (BNS)","author":{"@type":"Person","name":"Blockstack"},"@type":"BlogPosting","url":"https://zbabystack.netlify.com/core/naming/introduction.html","headline":"Blockstack Naming Service (BNS)","dateModified":"2018-08-30T13:25:56-07:00","datePublished":"2018-08-30T13:25:56-07:00","mainEntityOfPage":{"@type":"WebPage","@id":"https://zbabystack.netlify.com/core/naming/introduction.html"},"@context":"http://schema.org"}</script>
<!-- End Jekyll SEO tag -->
<!-- <meta property="og:image" content="https://zbabystack.netlify.com/assets/posts/logo.png"/> -->
<meta property="og:image" content="/assets/posts/logo.png"/>
<link rel="stylesheet" href="/assets/css/main.css">
<link rel="shortcut icon" type="image/png" href="/assets/img/favicon.png" >
<link rel="alternate" type="application/rss+xml" title="Blockstack" href="/feed.xml">
<script src="/assets/js/main.js"></script>
</head>
<body>
<header class="uk-background-secondary">
<div data-uk-sticky="sel-target: .uk-navbar-container; cls-active: uk-navbar-sticky" class="uk-sticky uk-sticky-fixed" style="position: fixed; top: 0px; width: 1904px;">
<nav class="uk-navbar-container">
<div class="uk-container">
<div data-uk-navbar>
<div class="uk-navbar-left">
<!-- <a class="uk-navbar-item uk-logo" href="/"><img src="https://zbabystack.netlify.com/assets/posts/logo.png" alt="Docs"></a> -->
<a class="uk-navbar-item uk-logo" href="/"><img src="/assets/posts/logo.png" alt="Docs"></a>
</div>
<div class="uk-navbar-right">
<ul class="uk-navbar-nav uk-visible@m">
<li><a href="https://blockstack.org" target="_blank" >Blockstack.org</a></li>
<li><a href="https://forum.blockstack.org/" target="_blank" >Forums</a></li>
<li><a href="https://github.com/blockstack" target="_blank" >GitHub</a></li>
</ul>
<div>
<a class="uk-navbar-toggle" uk-search-icon href="#"></a>
<div class="uk-drop uk-background-default uk-border-rounded" uk-drop="mode: click; pos: left-center; offset: 0">
<form class="uk-search uk-search-navbar uk-width-1-1" onsubmit="return false;">
<input id="searchBox" class="uk-search-input" type="search" placeholder="Search..." autofocus>
</form>
<ul id="searchBox-results" class="uk-position-absolute uk-width-1-1 uk-list"></ul>
</div>
</div>
<script>
SimpleJekyllSearch({
searchInput: document.getElementById('searchBox'),
resultsContainer: document.getElementById('searchBox-results'),
noResultsText: '<li>No results found</li>',
searchResultTemplate: '<li><a href="{url}">{title}</a></li>',
json: '/search.json'
});
</script>
<a class="uk-navbar-toggle uk-hidden@m" href="#offcanvas" data-uk-navbar-toggle-icon data-uk-toggle></a>
</div>
</div>
</div>
</nav>
</div>
</header>
<div class="uk-section">
<div class="uk-container">
<div class="uk-grid-large" data-uk-grid>
<div class="sidebar-fixed-width uk-visible@m">
<div class="sidebar-docs uk-position-fixed">
<h5>Overview</h5>
<ul class="uk-nav uk-nav-default doc-nav">
<!-- -->
<li class="uk-active"><a href="/core/naming/introduction.html">Blockstack Naming Service (BNS)</a></li>
<!-- -->
<li class=""><a href="/core/naming/architecture.html">Understand the Architecture</a></li>
<!-- -->
<li class=""><a href="/core/naming/namespaces.html">Understand Namespaces</a></li>
</ul>
<h5>Tutorials</h5>
<ul class="uk-nav uk-nav-default doc-nav">
<!-- -->
<li class=""><a href="/core/naming/tutorial_creation.html">Creating a Namespace</a></li>
<!-- -->
<li class=""><a href="/core/naming/tutorial_subdomains.html">Subdomain Design and Implementation</a></li>
</ul>
<h5>How to use BNS</h5>
<ul class="uk-nav uk-nav-default doc-nav">
<!-- -->
<li class=""><a href="/core/naming/pickname.html">Choose a name</a></li>
<!-- -->
<li class=""><a href="/core/naming/resolving.html">Resolve a name</a></li>
<!-- -->
<li class=""><a href="/core/naming/register.html">Register a name</a></li>
<!-- -->
<li class=""><a href="/core/naming/manage.html">Manage BNS Names</a></li>
<!-- -->
<li class=""><a href="/core/naming/subdomains.html">BNS Subdomains</a></li>
</ul>
<h5>Other topics</h5>
<ul class="uk-nav uk-nav-default doc-nav">
<!-- -->
<li class=""><a href="/core/naming/forks.html">BNS Forks</a></li>
<!-- -->
<li class=""><a href="/core/naming/did.html">DID Encoding for Subdomains</a></li>
<!-- -->
<li class=""><a href="/core/naming/comparison.html">Naming system feature comparison</a></li>
</ul>
</div>
</div>
<div class="uk-width-1-1 uk-width-expand@m">
<article class="uk-article">
<h1 class="uk-article-title">Blockstack Naming Service (BNS)</h1>
<div class="uk-article-meta uk-margin-top uk-margin-medium-bottom">
<!-- <img class="avatar avatar-small" alt="Blockstack" width="32" height="32" data-proofer-ignore="true" src="https://avatars2.githubusercontent.com/Blockstack?v=3&s=32" srcset="https://avatars2.githubusercontent.com/Blockstack?v=3&s=32 1x, https://avatars2.githubusercontent.com/Blockstack?v=3&s=64 2x, https://avatars2.githubusercontent.com/Blockstack?v=3&s=96 3x, https://avatars2.githubusercontent.com/Blockstack?v=3&s=128 4x" /> -->
<!-- Written by <span itemprop="author" itemscope itemtype="http://schema.org/Person"><span itemprop="name">Blockstack</span></span><br> -->
<time datetime="2018-08-30T13:25:56-07:00" itemprop="datePublished">
<a "target="_blank" href="https://github.com/moxiegirl/docs-new/blob/master/_core/naming/introduction.md" class="btn btn-default githubEditButton" role="button"><span data-uk-icon="icon: pencil; ratio: 1.2"></span> Edit this page on Github</a>
<span style="font-family:Wingdings">&#119;</span> Aug 30, 2018
</time>
</div>
<div class="article-content">
<p>This document gives an overview of how the Blockstack Naming Service work. This
document explains the following concepts:</p>
<ul>
<li>Why a secure decentralized naming service is an important building
block in decentralized systems</li>
<li>How Blockstack applications can leverage BNS to solve real-world problems</li>
<li>How the Blockstack Naming Service is different from other offerings in this
space.</li>
</ul>
<p>The (<a href="https://github.com/blockstack/blockstack-core">Blockstack Core</a>)
repository is the reference implementation of the Blockstack Naming Service.</p>
<h1 id="introduction">Introduction</h1>
<p>The Blockstack Naming Service (BNS) is a network system that binds names
to off-chain state without relying on any central points of control.
It does so by embedding a log of its control-plane messages within a public blockchain, like Bitcoin.</p>
<p>Each BNS peer determines the state of each name by indexing these specially-crafted
transactions. In doing so, each peer independently calculates the same global
name state.</p>
<p>Names in BNS have three properties:</p>
<ul>
<li><strong>Names are globally unique.</strong> The protocol does not allow name collisions, and all
well-behaved nodes resolve a given name to the same state.</li>
<li><strong>Names are human-meaningful.</strong> Each name is chosen by its creator.</li>
<li><strong>Names are strongly-owned.</strong> Only the name’s owner can change the state it
resolves to. Specifically, a name is owned by one or more ECDSA private keys.</li>
</ul>
<p>Internally, a BNS node implements a replicated name database. Each BNS node keeps itself
synchronized to all of the other ones in the world, so queries on one BNS node
will be the same on other nodes. BNS nodes allow a name’s owner to bind
up to 40Kb of off-chain state to their name, which will be replicated to all
BNS nodes via the <a href="atlas_network.md">Atlas network</a>.</p>
<p>BNS nodes extract the name database log from an underlying blockchain (Blockstack
Core currently uses Bitcoin, and had used Namecoin in the past).
BNS uses the blockchain to establish a shared “ground truth” for the system: as long as
two nodes have the same view of the blockchain, then they will build up the same
database.</p>
<p>The biggest consequence for developers is that in BNS, reading name state is
fast and cheap but writing name state is slow and expensive. This is because
registering and modifying names requires one or more transactions to be sent to
the underlying blockchain, and BNS nodes will not process them until they are
sufficiently confirmed. Users and developers need to acquire and spend
the requisite cryptocurrency (i.e. Bitcoin) to send BNS transactions.</p>
<h1 id="motivation">Motivation</h1>
<p>We rely on naming systems in everyday life, and they play a critical
role in many different applications. For example, when you look up a
friend on social media, you are using the platform’s naming service to resolve
their name to their profile. When you look up a website, you are using the
Domain Name Service to
resolve the hostname to its host’s IP address. When you check out a Git branch, you
are using your Git client to resolve the branch name to a commit hash.
When you look up someone’s PGP key on a keyserver, you are resolving
their key ID to their public key.</p>
<p>What kinds of things do we want to be true about names? In BNS, names are
globally unique, names are human-meaningful, and names are strongly-owned.
However, if you look at these examples, you’ll see that each of them only
guarantees <em>two</em> of these properties. This limits how useful they can be.</p>
<ul>
<li>In DNS and social media, names are globally unique and human-readable, but not
strongly-owned. The system operator has the
final say as to what each names resolves to.
<ul>
<li><strong>Problem</strong>: Clients must trust the system to make the right
choice in what a given name resolves to. This includes trusting that
no one but the system administrators can make these changes.</li>
</ul>
</li>
<li>In Git, branch names are human-meaningful
and strongly-owned, but not globally unique. Two different Git nodes may resolve the same
branch name to different unrelated repository states.
<ul>
<li><strong>Problem</strong>: Since names can refer to conflicting state, developers
have to figure out some other mechanism to resolve ambiguities. In Git’s
case, the user has to manually intervene.</li>
</ul>
</li>
<li>In PGP, names are key IDs. They are
are globally unique and cryptographically owned, but not human-readable. PGP
key IDs are derived from the keys they reference.
<ul>
<li><strong>Problem</strong>: These names are difficult for most users to
remember since they do not carry semantic information relating to their use in the system.</li>
</ul>
</li>
</ul>
<p>BNS names have all three properties, and none of these problems. This makes it a
powerful tool for building all kinds of network applications. With BNS, we
can do the following and more:</p>
<ul>
<li>Build domain name services where hostnames can’t be hijacked.</li>
<li>Build social media platforms where user names can’t be stolen by phishers.</li>
<li>Build version control systems where repository branches do not conflict.</li>
<li>Build public-key infrastructure where it’s easy for users to discover and
remember each other’s keys.</li>
</ul>
<h1 id="how-to-use-bns">How to Use BNS</h1>
<p>BNS names are organized into a global name hierarchy. There are three different
layers in this hierarchy related to naming:</p>
<ul>
<li>
<p><strong>Namespaces</strong>. These are the top-level names in the hierarchy. An analogy
to BNS namespaces are DNS top-level domains. Existing BNS namespaces include
<code class="highlighter-rouge">.id</code>, <code class="highlighter-rouge">.podcast</code>, and <code class="highlighter-rouge">.helloworld</code>. All other names belong to exactly one
namespace. Anyone can create a namespace, but in order for the namespace
to be persisted, it must be <em>launched</em> so that anyone can register names in it.
Namespaces are not owned by their creators.</p>
</li>
<li>
<p><strong>BNS names</strong>. These are names whose records are stored directly on the
blockchain. The ownership and state of these names are controlled by sending
blockchain transactions. Example names include <code class="highlighter-rouge">verified.podcast</code> and
<code class="highlighter-rouge">muneeb.id</code>. Anyone can create a BNS name, as long as the namespace that
contains it exists already. The state for BNS names is usually stored in the <a href="atlas_network.md">Atlas
network</a>.</p>
</li>
<li>
<p><strong>BNS subdomains</strong>. These are names whose records are stored off-chain,
but are collectively anchored to the blockchain. The ownership and state for
these names lives within the <a href="atlas_network.md">Atlas network</a>. While BNS
subdomains are owned by separate private keys, a BNS name owner must
broadcast their subdomain state. Example subdomains include <code class="highlighter-rouge">jude.personal.id</code>
and <code class="highlighter-rouge">podsaveamerica.verified.podcast</code>. Unlike BNS namespaces and names, the
state of BNS subdomains is <em>not</em> part of the blockchain consensus rules.</p>
</li>
</ul>
<p>A feature comparison matrix summarizing the similarities and differences
between these name objects is presented below:</p>
<table>
<thead>
<tr>
<th>Feature</th>
<th><strong>Namespaces</strong></th>
<th><strong>BNS names</strong></th>
<th><strong>BNS Subdomains</strong></th>
</tr>
</thead>
<tbody>
<tr>
<td>Globally unique</td>
<td>X</td>
<td>X</td>
<td>X</td>
</tr>
<tr>
<td>Human-meaningful</td>
<td>X</td>
<td>X</td>
<td>X</td>
</tr>
<tr>
<td>Owned by a private key</td>
<td> </td>
<td>X</td>
<td>X</td>
</tr>
<tr>
<td>Anyone can create</td>
<td>X</td>
<td>X</td>
<td>[1]</td>
</tr>
<tr>
<td>Owner can update</td>
<td> </td>
<td>X</td>
<td>[1]</td>
</tr>
<tr>
<td>State hosted on-chain</td>
<td>X</td>
<td>X</td>
<td> </td>
</tr>
<tr>
<td>State hosted off-chain</td>
<td> </td>
<td>X</td>
<td>X</td>
</tr>
<tr>
<td>Behavior controlled by consensus rules</td>
<td>X</td>
<td>X</td>
<td> </td>
</tr>
<tr>
<td>May have an expiration date</td>
<td> </td>
<td>X</td>
<td> </td>
</tr>
</tbody>
</table>
<p>[1] Requires the cooperation of a BNS name owner to broadcast its transactions</p>
<h3 id="creating-a-namespace">Creating a Namespace</h3>
<p>There are four steps to creating a namespace:</p>
<ol>
<li>
<p><strong>Send a <code class="highlighter-rouge">NAMESPACE_PREORDER</code> transaction</strong> (<a href="https://www.blocktrail.com/BTC/tx/5f00b8e609821edd6f3369ee4ee86e03ea34b890e242236cdb66ef6c9c6a1b28">live example</a>).
This is the first step. This registers the <em>salted hash</em> of the namespace with BNS nodes, and burns the
requisite amount of cryptocurrency. In addition, it proves to the
BNS nodes that user has honored the BNS consensus rules by including
a recent <em>consensus hash</em> in the transaction
(see the section on <a href="#bns-forks">BNS forks</a> for details).</p>
</li>
<li>
<p><strong>Send a <code class="highlighter-rouge">NAMESPACE_REVEAL</code> transaction</strong> (<a href="https://www.blocktrail.com/BTC/tx/ab54b1c1dd5332dc86b24ca2f88b8ca0068485edf0c322416d104c5b84133a32">live example</a>).
This is the second step. This reveals the salt and the namespace ID (pairing it with its
<code class="highlighter-rouge">NAMESPACE_PREORDER</code>), it reveals how long names last in this namespace before
they expire or must be renewed, and it sets a <em>price function</em> for the namespace
that determines how cheap or expensive names its will be. The price function takes
a name in this namespace as input, and outputs the amount of cryptocurrency the
name will cost (i.e. by examining how long the name is, and whether or not it
has any vowels or non-alphabet characters). The namespace creator
has the option to collect name registration fees for the first year of the
namespace’s existence by setting a <em>namespace creator address</em>.</p>
</li>
<li>
<p><strong>Seed the namespace with <code class="highlighter-rouge">NAME_IMPORT</code> transactions</strong> (<a href="https://www.blocktrail.com/BTC/tx/c698ac4b4a61c90b2c93dababde867dea359f971e2efcf415c37c9a4d9c4f312">live example</a>).
Once the namespace has been revealed, the user has the option to populate it with a set of
names. Each imported name is given both an owner and some off-chain state.
This step is optional—namespace creators are not required to import names.</p>
</li>
<li>
<p><strong>Send a <code class="highlighter-rouge">NAMESPACE_READY</code> transaction</strong> (<a href="https://www.blocktrail.com/BTC/tx/2bf9a97e3081886f96c4def36d99a677059fafdbd6bdb6d626c0608a1e286032">live example</a>).
This is the final step of the process. It <em>launches</em> the namespace, which makes it available to the
public. Once a namespace is ready, anyone can register a name in it if they
pay the appropriate amount of cryptocurrency (according to the price funtion
revealed in step 2).</p>
</li>
</ol>
<p>The reason for the <code class="highlighter-rouge">NAMESPACE_PREORDER/NAMESPACE_REVEAL</code> pairing is to prevent
frontrunning. The BNS consensus rules require a <code class="highlighter-rouge">NAMESPACE_REVEAL</code> to be
paired with a previous <code class="highlighter-rouge">NAMESPACE_PREORDER</code> sent within the past 24 hours.
If it did not do this, then a malicious actor could watch the blockchain network
and race a victim to claim a namespace.</p>
<p>Namespaces are created on a first-come first-serve basis. If two people try to
create the same namespace, the one that successfully confirms both the
<code class="highlighter-rouge">NAMESPACE_PREORDER</code> and <code class="highlighter-rouge">NAMESPACE_REVEAL</code> wins. The fee burned in the
<code class="highlighter-rouge">NAMESPACE_PREORDER</code> is spent either way.</p>
<p>Once the user issues the <code class="highlighter-rouge">NAMESPACE_PREORDER</code> and <code class="highlighter-rouge">NAMESPACE_REVEAL</code>, they have
1 year before they must send the <code class="highlighter-rouge">NAMESPACE_READY</code> transaction. If they do not
do this, then the namespace they created disappears (along with all the names
they imported).</p>
<p>Developers wanting to create their own namespaces should read the <a href="namespace_creation.md">namespace
creation</a> document. It is highly recommended that
developers follow this tutorial closely, given the large amount of
cryptocurrency at stake.</p>
<h3 id="using-namespaces">Using Namespaces</h3>
<p>The intention is that each application can create its own BNS
namespace for its own purposes. Applications can use namespaces for things like:</p>
<ul>
<li>Giving users a SSO system, where each user registers their public key under a
username. Blockstack applications do this with names in the <code class="highlighter-rouge">.id</code> namespace,
for example.</li>
<li>Providing a subscription service, where each name is a 3rd party that provides
a service for users to subscribe to. For example, names in
<code class="highlighter-rouge">.podcast</code> point to podcasts that users of the
<a href="https://dotpodcast.co">DotPodcast</a> app can subscribe to.</li>
<li>Implementing software licenses, where each name corresponds to an access key.
Unlike conventional access keys, access keys implemented as names
can be sold and traded independently. The licensing fee (paid as a name
registration) would be set by the developer and sent to a developer-controlled
blockchain address.</li>
</ul>
<p>Names within a namespace can serve any purpose the developer wants. The ability
to collect registration fees for 1 year after creating the namespace not only
gives developers the incentive to get users to participate in the app, but also
gives them a way to measure economic activity.</p>
<p>Developers can query individual namespaces and look up names within them using
the BNS API. The API offers routes to do the following:</p>
<h4 id="list-all-namespaces-in-existence-reference">List all namespaces in existence (<a href="https://core.blockstack.org/#namespace-operations-get-all-namespaces">reference</a>).</h4>
<div class="language-bash highlighter-rouge"><pre class="highlight"><code><span class="gp">$ </span>curl https://core.blockstack.org/v1/namespaces
<span class="o">[</span>
<span class="s2">"id"</span>,
<span class="s2">"helloworld"</span>,
<span class="s2">"podcast"</span>
<span class="o">]</span>
</code></pre>
</div>
<h4 id="list-all-names-within-a-namespace-reference">List all names within a namespace (<a href="https://core.blockstack.org/#namespace-operations-get-all-namespaces">reference</a>)</h4>
<div class="language-bash highlighter-rouge"><pre class="highlight"><code><span class="gp">$ </span>curl https://core.blockstack.org/v1/namespaces/id/names?page<span class="o">=</span>0
<span class="o">[</span>
<span class="s2">"0.id"</span>,
<span class="s2">"0000.id"</span>,
<span class="s2">"000000.id"</span>,
<span class="s2">"000001.id"</span>,
<span class="s2">"00000111111.id"</span>,
<span class="s2">"000002.id"</span>,
<span class="s2">"000007.id"</span>,
<span class="s2">"0011sro.id"</span>,
<span class="s2">"007_007.id"</span>,
<span class="s2">"00n3w5.id"</span>,
<span class="s2">"00r4zr.id"</span>,
<span class="s2">"00w1k1.id"</span>,
<span class="s2">"0101010.id"</span>,
<span class="s2">"01jack.id"</span>,
<span class="s2">"06nenglish.id"</span>,
<span class="s2">"08.id"</span>,
<span class="s2">"0cool_f.id"</span>,
<span class="s2">"0dadj1an.id"</span>,
<span class="s2">"0nelove.id"</span>,
<span class="s2">"0nename.id"</span>
...
<span class="o">]</span>
</code></pre>
</div>
<p>Each page returns a batch of 100 names.</p>
<h4 id="get-the-cost-to-register-a-namespace-reference">Get the Cost to Register a Namespace (<a href="https://core.blockstack.org/#price-checks-get-namespace-price">reference</a>)</h4>
<div class="language-bash highlighter-rouge"><pre class="highlight"><code><span class="gp">$ </span>curl https://core.blockstack.org/v1/prices/namespaces/test
<span class="o">{</span>
<span class="s2">"satoshis"</span>: 40000000
<span class="o">}</span>
</code></pre>
</div>
<p>If you want to register a namespace, please see the <a href="namespace_creation.md">namespace creation tutorial</a>.</p>
<h4 id="getting-the-current-consensus-hash-reference">Getting the Current Consensus Hash (<a href="https://core.blockstack.org/#blockchain-operations-get-consensus-hash">reference</a>)</h4>
<div class="language-bash highlighter-rouge"><pre class="highlight"><code><span class="gp">$ </span>curl -sL https://core.blockstack.org/v1/blockchains/bitcoin/consensus
<span class="o">{</span>
<span class="s2">"consensus_hash"</span>: <span class="s2">"98adf31989bd937576aa190cc9f5fa3a"</span>
<span class="o">}</span>
</code></pre>
</div>
<p>A recent consensus hash is required to create a <code class="highlighter-rouge">NAMESPACE_PREORDER</code> transaction. The reference
BNS clients do this automatically. See the <a href="wire-format.md">transaction format</a>
document for details on how the consensus hash is used to construct the
transaction.</p>
<h2 id="resolving-bns-names">Resolving BNS Names</h2>
<p>BNS names are bound to both public keys and to about 40Kb of off-chain state.
The off-chain state is encoded as a <a href="https://en.wikipedia.org/wiki/Zone_file">DNS zone file</a>,
which contains routing information for discovering the user’s Blockstack data
(such as their profile and app data, which are hosted in the <a href="https://github.com/blockstack/gaia">Gaia storage
system</a>).</p>
<p>The blockchain is not used to store this information directly. Instead, the
blockchain stores the <em>public key hash</em> and the <em>zone file hash</em>. When
indexing the blockchain, each BNS node builds a database with
three columns: all the on-chain BNS names that have been registered, each
name’s public key hash, and each name’s zone file’s hash.
In addition, each BNS node maintains the <em>transaction history</em> of each name.
A developer can resolve a name to any configuration it was in at any prior
point in time.</p>
<p>Below is an example name table pulled from a live BNS node:</p>
<table>
<thead>
<tr>
<th>Name</th>
<th>Public key hash</th>
<th>Zone File Hash</th>
</tr>
</thead>
<tbody>
<tr>
<td><code class="highlighter-rouge">ryan.id</code></td>
<td><code class="highlighter-rouge">15BcxePn59Y6mYD2fRLCLCaaHScefqW2No</code></td>
<td><code class="highlighter-rouge">a455954b3e38685e487efa41480beeb315f4ec65</code></td>
</tr>
<tr>
<td><code class="highlighter-rouge">muneeb.id</code></td>
<td><code class="highlighter-rouge">1J3PUxY5uDShUnHRrMyU6yKtoHEUPhKULs</code></td>
<td><code class="highlighter-rouge">37aecf837c6ae9bdc9dbd98a268f263dacd00361</code></td>
</tr>
<tr>
<td><code class="highlighter-rouge">jude.id</code></td>
<td><code class="highlighter-rouge">16EMaNw3pkn3v6f2BgnSSs53zAKH4Q8YJg</code></td>
<td><code class="highlighter-rouge">b6e99200125e70d634b17fe61ce55b09881bfafd</code></td>
</tr>
<tr>
<td><code class="highlighter-rouge">verified.podcast</code></td>
<td><code class="highlighter-rouge">1MwPD6dH4fE3gQ9mCov81L1DEQWT7E85qH</code></td>
<td><code class="highlighter-rouge">6701ce856620d4f2f57cd23b166089759ef6eabd</code></td>
</tr>
<tr>
<td><code class="highlighter-rouge">cicero.res_publica.id</code></td>
<td><code class="highlighter-rouge">1EtE77Aa5AA8etzF2irk56vvkS4v7rZ7PE</code></td>
<td><code class="highlighter-rouge">7e4ac75f9d79ba9d5d284fac19617497433b832d</code></td>
</tr>
<tr>
<td><code class="highlighter-rouge">podsaveamerica.verified.podcast</code></td>
<td><code class="highlighter-rouge">1MwPD6dH4fE3gQ9mCov81L1DEQWT7E85qH</code></td>
<td><code class="highlighter-rouge">0d6f090db8945aa0e60759f9c866b17645893a95</code></td>
</tr>
</tbody>
</table>
<p>In practice, the zone file hash is the <code class="highlighter-rouge">RIPEMD160</code> hash of the <code class="highlighter-rouge">SHA256</code> hash of
the zone file, and the public key is the <code class="highlighter-rouge">base58check</code>-encoded <code class="highlighter-rouge">RIPEMD160</code> hash
of the double-<code class="highlighter-rouge">SHA256</code> hash of the ECDSA public key (i.e. a Bitcoin address).</p>
<p>The BNS consensus rules ensure that
a BNS name can only be registered if it is not already taken, and that only the
user who owns the name’s private key can change its public key hash or zone file
hash. This means that a name’s public key and zone file can be stored anywhere,
since they can be authenticated using the hashes discovered by indexing the
blockchain under the BNS consensus rules.</p>
<p>BNS nodes implement a decentralized storage system for zone files called the
<a href="atlas_network.md">Atlas network</a>. In this system, BNS nodes eagerly replicate
all the zone files they know about to one another, so that eventually every BNS
node has a full replica of all zone files.</p>
<p>The public keys for names are stored off-chain in <a href="https://github.com/blockstack/gaia">Gaia</a>.
The user controls where their public keys are hosted using the zone file
contents (if they are hosted online anywhere at all).</p>
<p>Developers can query this table via the BNS API. The API offers routes
to do the following:</p>
<h4 id="look-up-a-names-public-key-and-zone-file-reference">Look up a name’s public key and zone file (<a href="https://core.blockstack.org/#name-querying-get-name-info">reference</a>)</h4>
<div class="language-bash highlighter-rouge"><pre class="highlight"><code><span class="gp">$ </span>curl https://core.blockstack.org/v1/names/muneeb.id
<span class="o">{</span>
<span class="s2">"address"</span>: <span class="s2">"1J3PUxY5uDShUnHRrMyU6yKtoHEUPhKULs"</span>,
<span class="s2">"blockchain"</span>: <span class="s2">"bitcoin"</span>,
<span class="s2">"expire_block"</span>: 599266,
<span class="s2">"last_txid"</span>: <span class="s2">"7e16e8688ca0413a398bbaf16ad4b10d3c9439555fc140f58e5ab4e50793c476"</span>,
<span class="s2">"status"</span>: <span class="s2">"registered"</span>,
<span class="s2">"zonefile"</span>: <span class="s2">"</span><span class="nv">$ORIGIN</span><span class="s2"> muneeb.id</span><span class="se">\n</span><span class="nv">$TTL</span><span class="s2"> 3600</span><span class="se">\n</span><span class="s2">_http._tcp URI 10 1 </span><span class="se">\"</span><span class="s2">https://gaia.blockstack.org/hub/1J3PUxY5uDShUnHRrMyU6yKtoHEUPhKULs/0/profile.json</span><span class="se">\"\n</span><span class="s2">"</span>,
<span class="s2">"zonefile_hash"</span>: <span class="s2">"37aecf837c6ae9bdc9dbd98a268f263dacd00361"</span>
<span class="o">}</span>
</code></pre>
</div>
<p>Note that the <code class="highlighter-rouge">zonefile</code> field is given with the off-chain data that hashes
to the <code class="highlighter-rouge">zonefile_hash</code> field.</p>
<h4 id="list-all-names-the-node-knows-about-reference">List all names the node knows about (<a href="https://core.blockstack.org/#name-querying-get-all-names">reference</a>)</h4>
<div class="language-bash highlighter-rouge"><pre class="highlight"><code><span class="gp">$ </span>curl https://core.blockstack.org/v1/names?page<span class="o">=</span>0
<span class="o">[</span>
<span class="s2">"judecn.id"</span>,
<span class="s2">"3.id"</span>,
<span class="s2">"4.id"</span>,
<span class="s2">"8.id"</span>,
<span class="s2">"e.id"</span>,
<span class="s2">"h.id"</span>,
<span class="s2">"5.id"</span>,
<span class="s2">"9.id"</span>,
<span class="s2">"i.id"</span>,
<span class="s2">"l.id"</span>,
<span class="s2">"p.id"</span>,
<span class="s2">"w.id"</span>,
<span class="s2">"ba.id"</span>,
<span class="s2">"df.id"</span>,
...
<span class="o">]</span>
</code></pre>
</div>
<p>Each page returns 100 names. While no specific ordering is mandated by the
protocol, the reference implementation orders names by their order of creation
in the blockchain.</p>
<h4 id="look-up-the-history-of-states-a-name-was-in-reference">Look up the history of states a name was in (<a href="https://core.blockstack.org/#name-querying-name-history">reference</a>)</h4>
<div class="language-bash highlighter-rouge"><pre class="highlight"><code><span class="gp">$ </span>curl https://core.blockstack.org/v1/names/patrickstanley.id/history
<span class="o">{</span>
<span class="s2">"445838"</span>: <span class="o">[</span>
<span class="o">{</span>
<span class="s2">"address"</span>: <span class="s2">"1occgbip7tFDXX9MvzQhcnTUUjcVX2dYK"</span>,
<span class="s2">"block_number"</span>: 445838,
<span class="s2">"burn_address"</span>: <span class="s2">"1111111111111111111114oLvT2"</span>,
<span class="s2">"consensus_hash"</span>: <span class="s2">"7b696b6f4060b792d41912068944d73b"</span>,
<span class="s2">"op"</span>: <span class="s2">"?"</span>,
<span class="s2">"op_fee"</span>: 25000,
<span class="s2">"opcode"</span>: <span class="s2">"NAME_PREORDER"</span>,
<span class="s2">"preorder_hash"</span>: <span class="s2">"26bf7874706ac761afdd403ed6b3b9578fb01a34"</span>,
<span class="s2">"sender"</span>: <span class="s2">"76a91408d0dd44c1f0a3a4f0957ae95901929d7d66d55788ac"</span>,
<span class="s2">"sender_pubkey"</span>: <span class="s2">"039a8948d339ecbff44cf426cb85d90fce876f1658d385cdc47f007f279be626ea"</span>,
<span class="s2">"txid"</span>: <span class="s2">"6730ae09574d5935ffabe3dd63a9341ea54fafae62fde36c27738e9ee9c4e889"</span>,
<span class="s2">"vtxindex"</span>: 40
<span class="o">}</span>
<span class="o">]</span>,
<span class="s2">"445851"</span>: <span class="o">[</span>
<span class="o">{</span>
<span class="s2">"address"</span>: <span class="s2">"17CbHgTgBG3kLedXNneEKBkCTgW2fyrnUD"</span>,
<span class="s2">"block_number"</span>: 445838,
<span class="s2">"consensus_hash"</span>: null,
<span class="s2">"first_registered"</span>: 445851,
<span class="s2">"importer"</span>: null,
<span class="s2">"importer_address"</span>: null,
<span class="s2">"last_creation_op"</span>: <span class="s2">"?"</span>,
<span class="s2">"last_renewed"</span>: 445851,
<span class="s2">"name"</span>: <span class="s2">"patrickstanley.id"</span>,
<span class="s2">"name_hash128"</span>: <span class="s2">"683a3e1ee5f0296833c56e481cf41b77"</span>,
<span class="s2">"namespace_block_number"</span>: 373601,
<span class="s2">"namespace_id"</span>: <span class="s2">"id"</span>,
<span class="s2">"op"</span>: <span class="s2">":"</span>,
<span class="s2">"op_fee"</span>: 25000,
<span class="s2">"opcode"</span>: <span class="s2">"NAME_REGISTRATION"</span>,
<span class="s2">"preorder_block_number"</span>: 445838,
<span class="s2">"preorder_hash"</span>: <span class="s2">"26bf7874706ac761afdd403ed6b3b9578fb01a34"</span>,
<span class="s2">"revoked"</span>: <span class="nb">false</span>,
<span class="s2">"sender"</span>: <span class="s2">"76a9144401f3be5311585ea519c1cb471a8dc7b02fd6ee88ac"</span>,
<span class="s2">"sender_pubkey"</span>: <span class="s2">"039a8948d339ecbff44cf426cb85d90fce876f1658d385cdc47f007f279be626ea"</span>,
<span class="s2">"transfer_send_block_id"</span>: null,
<span class="s2">"txid"</span>: <span class="s2">"55b8b42fc3e3d23cbc0f07d38edae6a451dfc512b770fd7903725f9e465b2925"</span>,
<span class="s2">"value_hash"</span>: null,
<span class="s2">"vtxindex"</span>: 54
<span class="o">}</span>
<span class="o">]</span>,
<span class="s2">"445873"</span>: <span class="o">[</span>
<span class="o">{</span>
<span class="s2">"address"</span>: <span class="s2">"17CbHgTgBG3kLedXNneEKBkCTgW2fyrnUD"</span>,
<span class="s2">"block_number"</span>: 445838,
<span class="s2">"consensus_hash"</span>: <span class="s2">"18b8d69f0182b89ccb1aa536f83be18a"</span>,
<span class="s2">"first_registered"</span>: 445851,
<span class="s2">"importer"</span>: null,
<span class="s2">"importer_address"</span>: null,
<span class="s2">"last_creation_op"</span>: <span class="s2">"?"</span>,
<span class="s2">"last_renewed"</span>: 445851,
<span class="s2">"name"</span>: <span class="s2">"patrickstanley.id"</span>,
<span class="s2">"name_hash128"</span>: <span class="s2">"683a3e1ee5f0296833c56e481cf41b77"</span>,
<span class="s2">"namespace_block_number"</span>: 373601,
<span class="s2">"namespace_id"</span>: <span class="s2">"id"</span>,
<span class="s2">"op"</span>: <span class="s2">"+"</span>,
<span class="s2">"op_fee"</span>: 25000,
<span class="s2">"opcode"</span>: <span class="s2">"NAME_UPDATE"</span>,
<span class="s2">"preorder_block_number"</span>: 445838,
<span class="s2">"preorder_hash"</span>: <span class="s2">"26bf7874706ac761afdd403ed6b3b9578fb01a34"</span>,
<span class="s2">"revoked"</span>: <span class="nb">false</span>,
<span class="s2">"sender"</span>: <span class="s2">"76a9144401f3be5311585ea519c1cb471a8dc7b02fd6ee88ac"</span>,
<span class="s2">"sender_pubkey"</span>: <span class="s2">"039a8948d339ecbff44cf426cb85d90fce876f1658d385cdc47f007f279be626ea"</span>,
<span class="s2">"transfer_send_block_id"</span>: null,
<span class="s2">"txid"</span>: <span class="s2">"dc478659fc684a1a6e1e09901971e82de11f4dfe2b32a656700bf9a3b6030719"</span>,
<span class="s2">"value_hash"</span>: <span class="s2">"02af0ef21161ad06b0923106f40b994b9e4c1614"</span>,
<span class="s2">"vtxindex"</span>: 95
<span class="o">}</span>
<span class="o">]</span>,
<span class="s2">"445884"</span>: <span class="o">[</span>
<span class="o">{</span>
<span class="s2">"address"</span>: <span class="s2">"1GZqrVbamkaE6YNveJFWK6cDrCy6bXyS6b"</span>,
<span class="s2">"block_number"</span>: 445838,
<span class="s2">"consensus_hash"</span>: <span class="s2">"18b8d69f0182b89ccb1aa536f83be18a"</span>,
<span class="s2">"first_registered"</span>: 445851,
<span class="s2">"importer"</span>: null,
<span class="s2">"importer_address"</span>: null,
<span class="s2">"last_creation_op"</span>: <span class="s2">"?"</span>,
<span class="s2">"last_renewed"</span>: 445851,
<span class="s2">"name"</span>: <span class="s2">"patrickstanley.id"</span>,
<span class="s2">"name_hash128"</span>: <span class="s2">"683a3e1ee5f0296833c56e481cf41b77"</span>,
<span class="s2">"namespace_block_number"</span>: 373601,
<span class="s2">"namespace_id"</span>: <span class="s2">"id"</span>,
<span class="s2">"op"</span>: <span class="s2">"&gt;&gt;"</span>,
<span class="s2">"op_fee"</span>: 25000,
<span class="s2">"opcode"</span>: <span class="s2">"NAME_TRANSFER"</span>,
<span class="s2">"preorder_block_number"</span>: 445838,
<span class="s2">"preorder_hash"</span>: <span class="s2">"26bf7874706ac761afdd403ed6b3b9578fb01a34"</span>,
<span class="s2">"revoked"</span>: <span class="nb">false</span>,
<span class="s2">"sender"</span>: <span class="s2">"76a914aabffa6dd90d731d3a349f009323bb312483c15088ac"</span>,
<span class="s2">"sender_pubkey"</span>: null,
<span class="s2">"transfer_send_block_id"</span>: 445875,
<span class="s2">"txid"</span>: <span class="s2">"7a0a3bb7d39b89c3638abc369c85b5c028d0a55d7804ba1953ff19b0125f3c24"</span>,
<span class="s2">"value_hash"</span>: <span class="s2">"02af0ef21161ad06b0923106f40b994b9e4c1614"</span>,
<span class="s2">"vtxindex"</span>: 16
<span class="o">}</span>
<span class="o">]</span>
<span class="o">}</span>
</code></pre>
</div>
<p>All of the above information is extracted from the blockchain. Each top-level
field encodes the states the name transitioned to at the given block height (e.g.
445838, 445851, 445873, adn 445884). At each block height, the name’s zone file
hashes are returned in the order they were discovered in the blockchain.</p>
<p>Each name state contains a lot of ancillary data that is used internally by
other API calls and client libraries. The relevant fields for this document’s
scope are:</p>
<ul>
<li><code class="highlighter-rouge">address</code>: This is the base58check-encoded public key hash.</li>
<li><code class="highlighter-rouge">name</code>: This is the name queried.</li>
<li><code class="highlighter-rouge">value_hash</code>: This is the zone file hash.</li>
<li><code class="highlighter-rouge">opcode</code>: This is the type of transaction that was processed.</li>
<li><code class="highlighter-rouge">txid</code>: This is the transaction ID in the underlying blockchain.</li>
</ul>
<p>The name’s <em>entire</em> history is returned. This includes the history of the name
under its previous owner, if the name expired and was reregistered.</p>
<h4 id="look-up-the-list-of-names-owned-by-a-given-public-key-hash-reference">Look up the list of names owned by a given public key hash (<a href="https://core.blockstack.org/#name-querying-get-names-owned-by-address">reference</a>)</h4>
<div class="language-bash highlighter-rouge"><pre class="highlight"><code><span class="gp">$ </span>curl https://core.blockstack.org/v1/addresses/bitcoin/16EMaNw3pkn3v6f2BgnSSs53zAKH4Q8YJg
<span class="o">{</span>
<span class="s2">"names"</span>: <span class="o">[</span>
<span class="s2">"judecn.id"</span>,
<span class="s2">"patrickstanley1.id"</span>,
<span class="s2">"abcdefgh123456.id"</span>,
<span class="s2">"duckduckgo_tor.id"</span>,
<span class="s2">"jude.id"</span>,
<span class="s2">"blockstacknewyear2017.id"</span>,
<span class="s2">"jude.statism.id"</span>
<span class="o">]</span>
<span class="o">}</span>
</code></pre>
</div>
<p>Note that this API endpoint includes names and
<a href="#bns-subdomains">subdomains</a>.</p>
<h2 id="registering-bns-names">Registering BNS Names</h2>
<p>Registering a BNS name costs cryptocurrency. This cost comes from two sources:</p>
<ul>
<li>
<p><strong>Transaction fees:</strong> These are the fees imposed by the cost of storing the
transaction data to the blockchain itself. They are independent of BNS, since
all of the blockchain’s users are competing to have their transactions included
in the next block. The blockchain’s miners receive the transaction fee.</p>
</li>
<li>
<p><strong>Registration fees:</strong> Each BNS namespace imposes an <em>additional</em> fee on how
much a name costs. The registration fee is sent to the namespace creator
during the first year that a namespace exists, and is sent to a burn address
afterwards. The registration fee is different for each name and is
determined by the namespace itself, but can be queried in advance by the user.</p>
</li>
</ul>
<p>Registering a name takes two transactions. They are:</p>
<ul>
<li>
<p><strong><code class="highlighter-rouge">NAME_PREORDER</code> transaction</strong>: This is the first transaction to be sent.
It tells all BNS nodes the <em>salted hash</em> of the BNS name, and it pays the
registration fee to the namespace owner’s designated address (or the burn
address). In addition, it proves to the BNS nodes that the client knows about
the current state of the system by including a recent <em>consensus hash</em>
in the transaction (see the section on <a href="#bns-forks">BNS forks</a> for details).</p>
</li>
<li>
<p><strong><code class="highlighter-rouge">NAME_REGISTRATION</code> transaction</strong>: This is the second transaction to be
sent. It reveals the salt and the name to all BNS nodes, and assigns the name
an initial public key hash and zone file hash</p>
</li>
</ul>
<p>The reason this process takes two transactions is to prevent front-running.
The BNS consensus rules stipulate that a name can only be registered if its
matching preorder transaction was sent in the last 24 hours. Because a name
must be preordered before it is registered, someone watching the blockchain’s
peer network cannot race a victim to claim the name they were trying to
register (i.e. the attacker would have needed to send a <code class="highlighter-rouge">NAME_PREORDER</code>
transaction first, and would have had to have sent it no more than 24 hours
ago).</p>
<p>Registering a name on top of the Bitcoin blockchain takes 1-2 hours. This is
because you need to wait for the <code class="highlighter-rouge">NAME_PREORDER</code> transaction to be sufficiently
confirmed before sending the <code class="highlighter-rouge">NAME_REGISTRATION</code> transaction. The BNS nodes
only register the name once both transactions have at least 6 confirmations
(which itself usually takes about an hour).</p>
<p>Names are registered on a first-come first-serve basis.
If two different people try to register the same name at the same time, the
person who completes the two-step process <em>earliest</em> will receive the name. The
other person’s <code class="highlighter-rouge">NAME_REGISTRATION</code> transaction will be ignored, since it will
not be considered valid at this point. The registration fee paid by the
<code class="highlighter-rouge">NAME_PREORDER</code> will be lost. However, this situation is rare in practice—
as of early 2018, we only know of one confirmed instance in the system’s 3+ years
of operation.</p>
<p>Fully-qualified names can be between 3 and 37 characters long, and consist of
the characters <code class="highlighter-rouge">a-z</code>, <code class="highlighter-rouge">0-9</code>, <code class="highlighter-rouge">+</code>, <code class="highlighter-rouge">-</code>, <code class="highlighter-rouge">_</code>, and <code class="highlighter-rouge">.</code>. This is to prevent
<a href="https://en.wikipedia.org/wiki/IDN_homograph_attack">homograph attacks</a>.
<code class="highlighter-rouge">NAME_REGISTRATION</code> transactions that do not conform to this requirement will be
ignored.</p>
<h4 id="getting-a-names-registration-fee-reference">Getting a Name’s Registration Fee (<a href="https://core.blockstack.org/#price-checks-get-name-price">reference</a>)</h4>
<div class="language-bash highlighter-rouge"><pre class="highlight"><code><span class="gp">$ </span>curl -sL https://core.blockstack.org/v1/prices/names/helloworld.id | jq -r <span class="s2">".name_price"</span>
<span class="o">{</span>
<span class="s2">"btc"</span>: 2.5e-05,
<span class="s2">"satoshis"</span>: 2500
<span class="o">}</span>
</code></pre>
</div>
<p>Note the use of <code class="highlighter-rouge">jq -r</code> to select the <code class="highlighter-rouge">"name_price"</code> field. This API
endpoint may return other ancilliary data regarding transaction fee estimation,
but this is the only field guaranteed by this specification to be present.</p>
<h4 id="getting-the-current-consensus-hash-reference-1">Getting the Current Consensus Hash (<a href="https://core.blockstack.org/#blockchain-operations-get-consensus-hash">reference</a>)</h4>
<div class="language-bash highlighter-rouge"><pre class="highlight"><code><span class="gp">$ </span>curl -sL https://core.blockstack.org/v1/blockchains/bitcoin/consensus
<span class="o">{</span>
<span class="s2">"consensus_hash"</span>: <span class="s2">"98adf31989bd937576aa190cc9f5fa3a"</span>
<span class="o">}</span>
</code></pre>
</div>
<p>The consensus hash must be included in the <code class="highlighter-rouge">NAME_PREORDER</code> transaction. The BNS
clients do this automatically. See the <a href="wire-format.md">transaction format
document</a> for details as to how to include this in the
transaction.</p>
<h4 id="registering-a-name">Registering a Name</h4>
<p>Registration happens through a BNS client, such as the <a href="https://github.com/blockstack/blockstack-browser">Blockstack
Browser</a> or
<a href="https://github.com/blockstack/blockstack.js">blockstack.js</a>.
The reference BNS clients manage a local Bitcoin wallet, calculate transaction fees
dynamically and automatically, and broadcast both the <code class="highlighter-rouge">NAME_PREORDER</code> and
<code class="highlighter-rouge">NAME_REGISTRATION</code> transactions at the right times.</p>
<p>If you want to make your own registration client, you should see the
<a href="wire-format.md">transaction format</a> document.</p>
<h2 id="managing-bns-names">Managing BNS Names</h2>
<p>Once you register a BNS name, you have the power to change its zone file hash,
change its public key hash, destroy it (i.e. render it unresolvable),
or renew it. The BNS consensus rules ensure that <em>only</em> you, as the owner of
the name’s private key, have the ability to carry out these operations.</p>
<p>Each of these operations are executed by sending a specially-formatted
blockchain transaction to the blockchain, which BNS nodes read and process.
The operations are listed below:</p>
<table>
<thead>
<tr>
<th>Transaction Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code class="highlighter-rouge">NAME_UPDATE</code></td>
<td>This changes the name’s zone file hash. Any 20-byte string is allowed.</td>
</tr>
<tr>
<td><code class="highlighter-rouge">NAME_TRANSFER</code></td>
<td>This changes the name’s public key hash. In addition, the current owner has the option to atomically clear the name’s zone file hash (so the new owner won’t “receive” the zone file).</td>
</tr>
<tr>
<td><code class="highlighter-rouge">NAME_REVOKE</code></td>
<td>This renders a name unresolvable. You should do this if your private key is compromised.</td>
</tr>
<tr>
<td><code class="highlighter-rouge">NAME_RENEWAL</code></td>
<td>This pushes back the name’s expiration date (if it has one), and optionally both sets a new zone file hash and a new public key hash.</td>
</tr>
</tbody>
</table>
<p>The reference BNS clients—
<a href="https://github.com/blockstack/blockstack.js">blockstack.js</a> and the <a href="https://github.com/blockstack/blockstack-browser">Blockstack
Browser</a>—can handle creating
and sending all of these transactions for you.</p>
<h3 id="name_update-live-example">NAME_UPDATE (<a href="https://www.blocktrail.com/BTC/tx/e2029990fa75e9fc642f149dad196ac6b64b9c4a6db254f23a580b7508fc34d7">live example</a>)</h3>
<p>A <code class="highlighter-rouge">NAME_UPDATE</code> transaction changes the name’s zone file hash. You would send
one of these transactions if you wanted to change the name’s zone file contents.
For example, you would do this if you want to deploy your own <a href="https://github.com/blockstack/gaia">Gaia
hub</a> and want other people to read from it.</p>
<p>A <code class="highlighter-rouge">NAME_UPDATE</code> transaction is generated from the name, a recent <a href="#bns-forks">consensus
hash</a>, and the new zone file hash. The reference clients gather
this information automatically. See the <a href="wire-format.md">transaction format</a>
document for details on how to construct this transaction.</p>
<h3 id="name_transfer-live-example">NAME_TRANSFER (<a href="https://www.blocktrail.com/BTC/tx/7a0a3bb7d39b89c3638abc369c85b5c028d0a55d7804ba1953ff19b0125f3c24">live example</a>)</h3>
<p>A <code class="highlighter-rouge">NAME_TRANSFER</code> transaction changes the name’s public key hash. You would
send one of these transactions if you wanted to:</p>
<ul>
<li>Change your private key</li>
<li>Send the name to someone else</li>
</ul>
<p>When transferring a name, you have the option to also clear the name’s zone
file hash (i.e. set it to <code class="highlighter-rouge">null</code>).
This is useful for when you send the name to someone else, so the
recipient’s name does not resolve to your zone file.</p>
<p>The <code class="highlighter-rouge">NAME_TRANSFER</code> transaction is generated from the name, a recent <a href="#bns-forks">consensus
hash</a>, and the new public key hash. The reference clients gather
this information automatically. See the <a href="wire-format.md">transaction format</a>
document for details on how to construct this transaction.</p>
<h3 id="name_revoke-live-example">NAME_REVOKE (<a href="https://www.blocktrail.com/BTC/tx/eb2e84a45cf411e528185a98cd5fb45ed349843a83d39fd4dff2de47adad8c8f">live example</a>)</h3>
<p>A <code class="highlighter-rouge">NAME_REVOKE</code> transaction makes a name unresolvable. The BNS consensus rules
stipulate that once a name is revoked, no one can change its public key hash or
its zone file hash. The name’s zone file hash is set to <code class="highlighter-rouge">null</code> to prevent it
from resolving.</p>
<p>You should only do this if your private key is compromised, or if you want to
render your name unusable for whatever reason. It is rarely used in practice.</p>
<p>The <code class="highlighter-rouge">NAME_REVOKE</code> operation is generated using only the name. See the
<a href="wire-format.md">transaction format</a> document for details on how to construct
it.</p>
<h3 id="name_renewal-live-example">NAME_RENEWAL (<a href="https://www.blocktrail.com/BTC/tx/e543211b18e5d29fd3de7c0242cb017115f6a22ad5c6d51cf39e2b87447b7e65">live example</a>)</h3>
<p>Depending in the namespace rules, a name can expire. For example, names in the
<code class="highlighter-rouge">.id</code> namespace expire after 2 years. You need to send a <code class="highlighter-rouge">NAME_RENEWAL</code> every
so often to keep your name.</p>
<p>A <code class="highlighter-rouge">NAME_RENEWAL</code> costs both transaction fees and registration fees. You will
pay the registration cost of your name to the namespace’s designated burn address when you
renew it. You can find this fee using the <code class="highlighter-rouge">/v1/prices/names/{name}</code> endpoint.</p>
<p>When a name expires, it enters a month-long “grace period” (5000 blocks). It
will stop resolving in the grace period, and all of the above operations will
cease to be honored by the BNS consensus rules. You may, however, send a
<code class="highlighter-rouge">NAME_RENEWAL</code> during this grace period to preserve your name.</p>
<p>If your name is in a namespace where names do not expire, then you never need to
use this transaction.</p>
<p>When you send a <code class="highlighter-rouge">NAME_RENEWAL</code>, you have the option of also setting a new public
key hash and a new zone file hash. See the <a href="wire-format.md">transaction format</a>
document for details on how to construct this transaction.</p>
<h2 id="bns-subdomains">BNS Subdomains</h2>
<p>BNS names are strongly-owned because the owner of its private key can generate
valid transactions that update its zone file hash and owner. However, this comes at the
cost of requiring a name owner to pay for the underlying transaction in the
blockchain. Moreover, this approach limits the rate of BNS name registrations
and operations to the underlying blockchain’s transaction bandwidth.</p>
<p>BNS overcomes this with subdomains. A <strong>BNS subdomain</strong> is a type of BNS name whose state
and owner are stored outside of the blockchain, but whose existence and
operation history are anchored to the
blockchain. In the example table in the <a href="#resolving-bns-names">Resolving BNS
Names</a> section, the names <code class="highlighter-rouge">cicero.res_publica.id</code> and
<code class="highlighter-rouge">podsaveamerica.verified.podcast</code> are subdomains.</p>
<p>Like their on-chain counterparts, subdomains are globally
unique, strongly-owned, and human-readable. BNS gives them their own name state
and public keys.</p>
<p>Unlike on-chain names, subdomains can be created and managed
cheaply, because they are broadcast to the
BNS network in batches. A single blockchain transaction can send up to 120
subdomain operations.</p>
<p>This is achieved by storing subdomain records in the <a href="atlas_network.md">Atlas Network</a>.
An on-chain name owner broadcasts subdomain operations by encoding them as
<code class="highlighter-rouge">TXT</code> records within a DNS zone file. To broadcast the zone file,
the name owner sets the new zone file hash with a <code class="highlighter-rouge">NAME_UPDATE</code> transaction and
replicates the zone file via Atlas. This, in turn, replicates all subdomain
operations it contains, and anchors the set of subdomain operations to
an on-chain transaction. The BNS node’s consensus rules ensure that only
valid subdomain operations from <em>valid</em> <code class="highlighter-rouge">NAME_UPDATE</code> transactions will ever be
stored.</p>
<p>For example, the name <code class="highlighter-rouge">verified.podcast</code> once wrote the zone file hash <code class="highlighter-rouge">247121450ca0e9af45e85a82e61cd525cd7ba023</code>,
which is the hash of the following zone file:</p>
<div class="language-bash highlighter-rouge"><pre class="highlight"><code><span class="gp">$ </span>curl -sL https://core.blockstack.org/v1/names/verified.podcast/zonefile/247121450ca0e9af45e85a82e61cd525cd7ba023 | jq -r <span class="s1">'.zonefile'</span>
<span class="nv">$ORIGIN</span> verified.podcast
<span class="nv">$TTL</span> 3600
1yeardaily TXT <span class="s2">"owner=1MwPD6dH4fE3gQ9mCov81L1DEQWT7E85qH"</span> <span class="s2">"seqn=0"</span> <span class="s2">"parts=1"</span> <span class="s2">"zf0=JE9SSUdJTiAxeWVhcmRhaWx5CiRUVEwgMzYwMApfaHR0cC5fdGNwIFVSSSAxMCAxICJodHRwczovL3BoLmRvdHBvZGNhc3QuY28vMXllYXJkYWlseS9oZWFkLmpzb24iCg=="</span>
2dopequeens TXT <span class="s2">"owner=1MwPD6dH4fE3gQ9mCov81L1DEQWT7E85qH"</span> <span class="s2">"seqn=0"</span> <span class="s2">"parts=1"</span> <span class="s2">"zf0=JE9SSUdJTiAyZG9wZXF1ZWVucwokVFRMIDM2MDAKX2h0dHAuX3RjcCBVUkkgMTAgMSAiaHR0cHM6Ly9waC5kb3Rwb2RjYXN0LmNvLzJkb3BlcXVlZW5zL2hlYWQuanNvbiIK"</span>
10happier TXT <span class="s2">"owner=1MwPD6dH4fE3gQ9mCov81L1DEQWT7E85qH"</span> <span class="s2">"seqn=0"</span> <span class="s2">"parts=1"</span> <span class="s2">"zf0=JE9SSUdJTiAxMGhhcHBpZXIKJFRUTCAzNjAwCl9odHRwLl90Y3AgVVJJIDEwIDEgImh0dHBzOi8vcGguZG90cG9kY2FzdC5jby8xMGhhcHBpZXIvaGVhZC5qc29uIgo="</span>
31thoughts TXT <span class="s2">"owner=1MwPD6dH4fE3gQ9mCov81L1DEQWT7E85qH"</span> <span class="s2">"seqn=0"</span> <span class="s2">"parts=1"</span> <span class="s2">"zf0=JE9SSUdJTiAzMXRob3VnaHRzCiRUVEwgMzYwMApfaHR0cC5fdGNwIFVSSSAxMCAxICJodHRwczovL3BoLmRvdHBvZGNhc3QuY28vMzF0aG91Z2h0cy9oZWFkLmpzb24iCg=="</span>
359 TXT <span class="s2">"owner=1MwPD6dH4fE3gQ9mCov81L1DEQWT7E85qH"</span> <span class="s2">"seqn=0"</span> <span class="s2">"parts=1"</span> <span class="s2">"zf0=JE9SSUdJTiAzNTkKJFRUTCAzNjAwCl9odHRwLl90Y3AgVVJJIDEwIDEgImh0dHBzOi8vcGguZG90cG9kY2FzdC5jby8zNTkvaGVhZC5qc29uIgo="</span>
30for30 TXT <span class="s2">"owner=1MwPD6dH4fE3gQ9mCov81L1DEQWT7E85qH"</span> <span class="s2">"seqn=0"</span> <span class="s2">"parts=1"</span> <span class="s2">"zf0=JE9SSUdJTiAzMGZvcjMwCiRUVEwgMzYwMApfaHR0cC5fdGNwIFVSSSAxMCAxICJodHRwczovL3BoLmRvdHBvZGNhc3QuY28vMzBmb3IzMC9oZWFkLmpzb24iCg=="</span>
onea TXT <span class="s2">"owner=1MwPD6dH4fE3gQ9mCov81L1DEQWT7E85qH"</span> <span class="s2">"seqn=0"</span> <span class="s2">"parts=1"</span> <span class="s2">"zf0=JE9SSUdJTiBvbmVhCiRUVEwgMzYwMApfaHR0cC5fdGNwIFVSSSAxMCAxICJodHRwczovL3BoLmRvdHBvZGNhc3QuY28vb25lYS9oZWFkLmpzb24iCg=="</span>
10minuteteacher TXT <span class="s2">"owner=1MwPD6dH4fE3gQ9mCov81L1DEQWT7E85qH"</span> <span class="s2">"seqn=0"</span> <span class="s2">"parts=1"</span> <span class="s2">"zf0=JE9SSUdJTiAxMG1pbnV0ZXRlYWNoZXIKJFRUTCAzNjAwCl9odHRwLl90Y3AgVVJJIDEwIDEgImh0dHBzOi8vcGguZG90cG9kY2FzdC5jby8xMG1pbnV0ZXRlYWNoZXIvaGVhZC5qc29uIgo="</span>
36questionsthepodcastmusical TXT <span class="s2">"owner=1MwPD6dH4fE3gQ9mCov81L1DEQWT7E85qH"</span> <span class="s2">"seqn=0"</span> <span class="s2">"parts=1"</span> <span class="s2">"zf0=JE9SSUdJTiAzNnF1ZXN0aW9uc3RoZXBvZGNhc3RtdXNpY2FsCiRUVEwgMzYwMApfaHR0cC5fdGNwIFVSSSAxMCAxICJodHRwczovL3BoLmRvdHBvZGNhc3QuY28vMzZxdWVzdGlvbnN0aGVwb2RjYXN0bXVzaWNhbC9oZWFkLmpzb24iCg=="</span>
_http._tcp URI 10 1 <span class="s2">"https://dotpodcast.co/"</span>
</code></pre>
</div>
<p>Each <code class="highlighter-rouge">TXT</code> record in this zone file encodes a subdomain-creation.
For example, <code class="highlighter-rouge">1yeardaily.verified.podcast</code> resolves to:</p>
<div class="language-bash highlighter-rouge"><pre class="highlight"><code><span class="gp">$ </span>curl https://core.blockstack.org/v1/names/1yeardaily.verified.podcast
<span class="o">{</span>
<span class="s2">"address"</span>: <span class="s2">"1MwPD6dH4fE3gQ9mCov81L1DEQWT7E85qH"</span>,
<span class="s2">"blockchain"</span>: <span class="s2">"bitcoin"</span>,
<span class="s2">"last_txid"</span>: <span class="s2">"d87a22ebab3455b7399bfef8a41791935f94bc97aee55967edd5a87f22cce339"</span>,
<span class="s2">"status"</span>: <span class="s2">"registered_subdomain"</span>,
<span class="s2">"zonefile_hash"</span>: <span class="s2">"e7acc97fd42c48ed94fd4d41f674eddbee5557e3"</span>,
<span class="s2">"zonefile_txt"</span>: <span class="s2">"</span><span class="nv">$ORIGIN</span><span class="s2"> 1yeardaily</span><span class="se">\n</span><span class="nv">$TTL</span><span class="s2"> 3600</span><span class="se">\n</span><span class="s2">_http._tcp URI 10 1 </span><span class="se">\"</span><span class="s2">https://ph.dotpodcast.co/1yeardaily/head.json</span><span class="se">\"\n</span><span class="s2">"</span>
<span class="o">}</span>
</code></pre>
</div>
<p>This information was extracted from the <code class="highlighter-rouge">1yeardaily</code> <code class="highlighter-rouge">TXT</code> resource record in the zone
file for <code class="highlighter-rouge">verified.podcast</code>.</p>
<h3 id="subdomain-lifecycle">Subdomain Lifecycle</h3>
<p>Note that <code class="highlighter-rouge">1yeardaily.verified.podcast</code> has a different public key
hash (address) than <code class="highlighter-rouge">verified.podcast</code>. A BNS node will only process a
subsequent subdomain operation on <code class="highlighter-rouge">1yeardaily.verified.podcast</code> if it includes a
signature from this address’s private key. <code class="highlighter-rouge">verified.podcast</code> cannot generate
updates; only the owner of <code class="highlighter-rouge">1yeardaily.verified.podcast can do so</code>.</p>
<p>The lifecycle of a subdomain and its operations is shown in Figure 2.</p>
<div class="highlighter-rouge"><pre class="highlight"><code> subdomain subdomain subdomain
creation update transfer
+----------------+ +----------------+ +----------------+
| cicero | | cicero | | cicero |
| owner="1Et..." | signed | owner="1Et..." | signed | owner="1cJ..." |
| zf0="7e4..." |&lt;--------| zf0="111..." |&lt;--------| zf0="111..." |&lt;---- ...
| seqn=0 | | seqn=1 | | seqn=2 |
| | | sig="xxxx" | | sig="xxxx" |
+----------------+ +----------------+ +----------------+
| | |
| off-chain | |
~ ~ ~ ~ | ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~|~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ | ~ ~ ~ ~ ~ ~ ~ ...
| on-chain | |
V V (zone file hash ) V
+----------------+ +----------------+ +----------------+
| res_publica.id | | jude.id | | res_publica.id |
| NAME_UPDATE |&lt;--------| NAME_UPDATE |&lt;--------| NAME_UPDATE |&lt;---- ...
+----------------+ +----------------+ +----------------+
blockchain blockchain blockchain
block block block
Figure 2: Subdomain lifetime with respect to on-chain name operations. A new
subdomain operation will only be accepted if it has a later "sequence=" number,
and a valid signature in "sig=" over the transaction body. The "sig=" field
includes both the public key and signature, and the public key must hash to
the previous subdomain operation's "addr=" field.
Thesubdomain-creation and subdomain-transfer transactions for
"cicero.res_publica.id" are broadcast by the owner of "res_publica.id".
However, any on-chain name ("jude.id" in this case) can broadcast a subdomain
update for "cicero.res_publica.id".
</code></pre>
</div>
<p>Subdomain operations are ordered by sequence number, starting at 0. Each new
subdomain operation must include:</p>
<ul>
<li>The next sequence number</li>
<li>The public key that hashes to the previous subdomain transaction’s address</li>
<li>A signature from the corresponding private key over the entire subdomain
operation.</li>
</ul>
<p>If two correctly-signed but conflicting subdomain operations are discovered
(i.e. they have the same sequence number), the one that occurs earlier in the
blockchain’s history is accepted. Invalid subdomain operations are ignored.</p>
<p>Combined, this ensures that a BNS node with all of the zone files with a given
subdomain’s operations will be able to determine the valid sequence of
state-transitions it has undergone, and determine the current zone file and public
key hash for the subdomain.</p>
<h3 id="resolving-subdomains">Resolving Subdomains</h3>
<p>Developers interact with subdomains the same way they interact with names.
Using the BNS API, a developer can:</p>
<h4 id="look-up-a-subdomains-public-key-and-zone-file-reference">Look up a subdomain’s public key and zone file (<a href="https://core.blockstack.org/#name-querying-get-name-info">reference</a>)</h4>
<div class="language-bash highlighter-rouge"><pre class="highlight"><code><span class="gp">$ </span>curl https://core.blockstack.org/v1/names/aaron.personal.id
<span class="o">{</span>
<span class="s2">"address"</span>: <span class="s2">"1PwztPFd1s2STMv4Ntq6UPBdYgHSBr5pdF"</span>,
<span class="s2">"blockchain"</span>: <span class="s2">"bitcoin"</span>,
<span class="s2">"last_txid"</span>: <span class="s2">"85e8273b0a38d3e9f0af7b4b72faf0907de9f4616afc101caac13e7bbc832394"</span>,
<span class="s2">"status"</span>: <span class="s2">"registered_subdomain"</span>,
<span class="s2">"zonefile_hash"</span>: <span class="s2">"a6dda6b74ffecf85f4a162627d8df59577243813"</span>,
<span class="s2">"zonefile_txt"</span>: <span class="s2">"</span><span class="nv">$ORIGIN</span><span class="s2"> aaron.personal.id</span><span class="se">\n</span><span class="nv">$TTL</span><span class="s2"> 3600</span><span class="se">\n</span><span class="s2">_https._tcp URI 10 1 </span><span class="se">\"</span><span class="s2">https://gaia.blockstack.org/hub/1PwztPFd1s2STMv4Ntq6UPBdYgHSBr5pdF/profile.json</span><span class="se">\"\n</span><span class="s2">"</span>
<span class="o">}</span>
</code></pre>
</div>
<h4 id="look-up-a-subdomains-transaction-history-reference">Look up a subdomain’s transaction history (<a href="https://core.blockstack.org/#name-querying-name-history">reference</a>)</h4>
<div class="language-bash highlighter-rouge"><pre class="highlight"><code><span class="gp">$ </span>curl https://core.blockstack.org/v1/names/aaron.personal.id/history
<span class="o">{</span>
<span class="s2">"509981"</span>: <span class="o">[</span>
<span class="o">{</span>
<span class="s2">"address"</span>: <span class="s2">"1PwztPFd1s2STMv4Ntq6UPBdYgHSBr5pdF"</span>,
<span class="s2">"block_number"</span>: 509981,
<span class="s2">"domain"</span>: <span class="s2">"personal.id"</span>,
<span class="s2">"name"</span>: <span class="s2">"aaron.personal.id"</span>,
<span class="s2">"sequence"</span>: 0,
<span class="s2">"txid"</span>: <span class="s2">"85e8273b0a38d3e9f0af7b4b72faf0907de9f4616afc101caac13e7bbc832394"</span>,
<span class="s2">"value_hash"</span>: <span class="s2">"a6dda6b74ffecf85f4a162627d8df59577243813"</span>,
<span class="s2">"zonefile"</span>: <span class="s2">"JE9SSUdJTiBhYXJvbi5wZXJzb25hbC5pZAokVFRMIDM2MDAKX2h0dHBzLl90Y3AgVVJJIDEwIDEgImh0dHBzOi8vZ2FpYS5ibG9ja3N0YWNrLm9yZy9odWIvMVB3enRQRmQxczJTVE12NE50cTZVUEJkWWdIU0JyNXBkRi9wcm9maWxlLmpzb24iCg=="</span>
<span class="o">}</span>
<span class="o">]</span>
<span class="o">}</span>
</code></pre>
</div>
<h4 id="look-up-the-list-of-names-and-subdomains-owned-by-a-given-public-key-hash-reference">Look up the list of names and subdomains owned by a given public key hash (<a href="https://core.blockstack.org/#name-querying-get-names-owned-by-address">reference</a>)</h4>
<div class="language-bash highlighter-rouge"><pre class="highlight"><code><span class="gp">$ </span>curl https://core.blockstack.org/v1/addresses/bitcoin/1PwztPFd1s2STMv4Ntq6UPBdYgHSBr5pdF
<span class="o">{</span>
<span class="s2">"names"</span>: <span class="o">[</span>
<span class="s2">"aaron.personal.id"</span>
<span class="o">]</span>
<span class="o">}</span>
</code></pre>
</div>
<h3 id="subdomain-creation-and-management">Subdomain Creation and Management</h3>
<p>Unlike an on-chain name, a subdomain owner needs an on-chain name owner’s help
to broadcast their subdomain operations. In particular:</p>
<ul>
<li>A subdomain-creation transaction can only be processed by the owner of the on-chain
name that shares its suffix. For example, only the owner of <code class="highlighter-rouge">res_publica.id</code>
can broadcast subdomain-creation transactions for subdomain names ending in
<code class="highlighter-rouge">.res_publica.id</code>.</li>
<li>A subdomain-transfer transaction can only be broadcast by the owner of the
on-chain name that created it. For example, the owner of
<code class="highlighter-rouge">cicero.res_publica.id</code> needs the owner of <code class="highlighter-rouge">res_publica.id</code> to broadcast a
subdomain-transfer transaction to change <code class="highlighter-rouge">cicero.res_publica.id</code>’s public key.</li>
<li>In order to send a subdomain-creation or subdomain-transfer, all
of an on-chain name owner’s zone files must be present in the Atlas network.
This lets the BNS node prove the <em>absence</em> of any conflicting subdomain-creation and
subdomain-transfer operations when processing new zone files.</li>
<li>A subdomain update transaction can be broadcast by <em>any</em> on-chain name owner,
but the subdomain owner needs to find one who will cooperate. For example,
the owner of <code class="highlighter-rouge">verified.podcast</code> can broadcast a subdomain-update transaction
created by the owner of <code class="highlighter-rouge">cicero.res_publica.id</code>.</li>
</ul>
<p>That said, to create a subdomain, the subdomain owner generates a
subdomain-creation operation for their desired name
and gives it to the on-chain name owner.
The on-chain name owner then uses Atlas to
broadcast it to all other BNS nodes.</p>
<p>Once created, a subdomain owner can use any on-chain name owner to broadcast a
subdomain-update operation. To do so, they generate and sign the requisite
subdomain operation and give it to an on-chain name owner, who then packages it
with other subdomain operations into a DNS zone file
and sends them all out on the Atlas network.</p>
<p>If the subdomain owner wants to change the address of their subdomain, they need
to sign a subdomain-transfer operation and give it to the on-chain name owner
who created the subdomain. They then package it into a zone file and broadcast
it.</p>
<h3 id="subdomain-registrars">Subdomain Registrars</h3>
<p>Because subdomain names are cheap, developers may be inclined to run
subdomain registrars on behalf of their applications. For example,
the name <code class="highlighter-rouge">personal.id</code> is used to register Blockstack application users without
requiring them to spend any Bitcoin.</p>
<p>We supply a reference
implementation of a <a href="https://github.com/blockstack/subdomain-registrar">BNS Subdomain Registrar</a>
to help developers broadcast subdomain operations. Users would still own their
subdomain names; the registrar simply gives developers a convenient way for them
to register and manage them in the context of a particular application.
Please see the <a href="subdomains.md">tutorial on running a subdomain registrar</a> for
details on how to use it.</p>
<h2 id="bns-forks">BNS Forks</h2>
<p>BNS effectively uses a public blockchain to store a database log. A BNS peer
bootstraps itself by downloading and replaying the database log from the
blockchain, and in doing so, will calculate the same name database state as
every other (honest) BNS peer that has the same view of the blockchain.</p>
<p>Crucially, BNS is built on top of a public blockchain that is <em>unaware</em> of BNS’s existence.
This means that the blockchain peers do not validate BNS transactions. Instead,
the BNS peer needs to do so, and must know how to <em>reject</em> both invalid transactions
as well as well-formed transactions from dishonest peers (i.e. peers that do not
follow the same consensus rules).</p>
<p>BNS nodes do not directly communicate with one another—by design, the set of
BNS peers is not enumerable. The only shared communication medium between BNS
peers is the blockchain.</p>
<p>To identify and reject invalid and malicious transactions without the blockchain’s help,
the log of name operations embedded in the blockchain is constructed as a
<a href="http://www.scs.stanford.edu/~jinyuan/bft2f.pdf">fork*-consistent</a> database
log. Fork*-consistency is a <a href="https://en.wikipedia.org/wiki/Consistency_model">consistency
model</a> whereby the state
replicas in all of the nodes exhibit the following properties:</p>
<ul>
<li>
<p>Each correct peer maintains a history of well-formed, valid state operations. In this
case, each correct BNS node maintains a copy of the history blockchain transactions
that encoded well-formed, valid name operations.</p>
</li>
<li>
<p>Each honest peer’s history contains the sequence of all operations that it
sent. That is, a user’s BNS peer’s transaction log will contain the sequence of all valid
transactions that the user’s client wrote to the blockchain.</p>
</li>
<li>
<p>If two peers accept operations <em>op</em> and <em>op’</em> from the same correct client,
then both of their logs will have the both operations in the same order. If
<em>op’</em> was accepted before <em>op</em>, then both peers’ logs are identical up to <em>op’</em>.
In BNS, this means that if two peers both accept a given transaction, then it
means that they have accepted the same sequence of prior transactions.</p>
</li>
</ul>
<p>This means that unlike with blockchains,
there can be <em>multiple long-lived conflicting forks</em> of the BNS database log.
However, due to fork*-consistency, a correct BNS peer will only process <em>one</em>
of these forks, and will <em>ignore</em> transactions from peers in other forks. In other words,
fork*-consistency partitions the set of BNS peers into different <strong>fork-sets</strong>,
where all peers in a fork-set process each other’s transactions, but the
completely ignore peers in other fork-sets.</p>
<p>BNS nodes identify which fork set they belong to using a <strong>consensus hash</strong>. The
consensus hash is a cryptographic digest of a node’s operation
history. Each BNS peer calculates a new consensus hash each time it processes a
new block, and stores the history of consensus hashes for each block it
processed.</p>
<p>Two honest BNS peers can quickly determine if they are in the same fork-set by querying
each other’s consensus hashes for a given block. If they match, then they are
in the same fork-set (assming no hash collisions).</p>
<p>A BNS client executes a name operation on a specific fork-set by including a
recent consensus hash from that fork-set in the blockchain transaction.
At the same time, the BNS consensus rules state that a transaction can only be
accepted if it included a recent valid consensus hash.
This means that all BNS nodes in the client’s desired fork-set will accept
the transaction, and all other BNS nodes not in the fork-set will ignore it.
You can see where the consensus hash is included in blockchain transactions by reading
the <a href="wire-format.md">transaction wire format</a> document.</p>
<h3 id="fork-set-selection">Fork-set Selection</h3>
<p>The blockchain linearizes the history of transactions, which means that
in general, there exists a fork-set for each distinct set of BNS
consensus rules. For example, the Blockstack Core <a href="release_notes/changelog-0.14.md">2016 hard fork</a>
and <a href="release_notes/changelog-0.17.md">2017 hard fork</a> both introduced new consensus
rules, which means at the time of this writing there are three possible fork-sets:
the pre-2016 fork-set, the 2016-2017 fork-set, and the post-2017 fork-set.
The <a href="https://node.blockstack.org:6263">public BNS nodes</a> are always running
in the fork-set with the latest consensus rules.</p>
<p>BNS clients are incentivized to communicate with peers in the fork-set that has
the most use, since this fork-set’s name database will encode name/state
bindings that are the most widely-accepted and understood by users.
To identify this fork-set, a BNS client needs to learn one of
its recent consensus hashes. Once it has a recent consensus hash, it can
query an <em>untrusted</em> BNS node for a copy of
its name database, and use the consensus hash to verify that the name database
was used to generate it.</p>
<p>How does a BNS node determine whether or not a consensus hash corresponds to the
most widely-used fork-set? There are two strategies:</p>
<ul>
<li>
<p>Determine whether or not a <em>characteristic transaction</em> was accepted by the
widely-used fork-set. If a client knows that a specific transaction belongs to
the widely-used fork-set and not others, then they can use the consensus hash to
efficiently determine whether or not a given node belongs to this fork-set.</p>
</li>
<li>
<p>Determine how much “economic activity” exists in a fork-set by inspecting
the blockchain for burned cryptocurrency tokens. Namespace and name
registrations are structured in a way that sends cryptocurrency tokens to either
a well-known burn address, or to an easily-queried pay-to-namespace-creator
address.</p>
</li>
</ul>
<p>Both strategies rely on the fact that the consensus hash is calculated as a
<a href="https://github.com/blockstack/blockstack-core/issues/146">Merkle skip-list</a>
over the BNS node’s accepted transactions. A client can use a consensus hash to
determine whether or not a transaction <em>T</em> was accepted by a node with <em>O(log
n)</em> time and space complexity. We call the protocol for resolving a consensus hash to a specific transaction
<strong>Simplified Name Verification</strong> (SNV). See our <a href="https://blockstack.org/virtualchain_dccl16.pdf">paper on the subject</a>
for details of how SNV works under the hood.</p>
<p>If the client has a consensus hash and knows of a characteristic transaction in the widely-used fork-set,
it can use SNV to determine whether or not a node belongs to the fork-set that accepted it.</p>
<p>If the client knows about multiple conflicting consensus hashes,
they can still use SNV to determine which one corresponds
to the most-used fork-set. To do so, the client would use a
<a href="https://explorer.blockstack.org">blockchain explorer</a> to find the
list of transactions that burned cryptocurrency tokens. Each of these
transactions will be treated as potential characteristic transactions:
the client would first select the subset of transactions that are well-formed
BNS transactions, and then use SNV to determine which of them correspond to which
consensus hashes. The client chooses the consensus hash that corresponds
to the fork-set with the highest cumulative burn.</p>
<p>Work is currently underway to automate this process.</p>
<h2 id="decentralized-identifiers-dids">Decentralized Identifiers (DIDs)</h2>
<p>BNS nodes are compliant with the emerging
<a href="http://identity.foundation">Decentralized Identity Foundation</a> protocol
specification for decentralized identifiers (DIDs).</p>
<p>Each name in BNS has an associated DID. The DID format for BNS is:</p>
<div class="highlighter-rouge"><pre class="highlight"><code> did:stack:v0:{address}-{index}
</code></pre>
</div>
<p>Where:</p>
<ul>
<li><code class="highlighter-rouge"><span class="p">{</span><span class="err">address</span><span class="p">}</span></code> is an on-chain public key hash (e.g. a Bitcoin address).</li>
<li><code class="highlighter-rouge"><span class="p">{</span><span class="err">index</span><span class="p">}</span></code> refers to the <code class="highlighter-rouge">nth</code> name this address created.</li>
</ul>
<p>For example, the DID for <code class="highlighter-rouge">personal.id</code> is
<code class="highlighter-rouge">did:stack:v0:1dARRtzHPAFRNE7Yup2Md9w18XEQAtLiV-0</code>, because the name
<code class="highlighter-rouge">personal.id</code> was the first-ever name created by
<code class="highlighter-rouge">1dARRtzHPAFRNE7Yup2Md9w18XEQAtLiV</code>.</p>
<p>As another example, the DID for <code class="highlighter-rouge">jude.id</code> is <code class="highlighter-rouge">did:stack:v0:16EMaNw3pkn3v6f2BgnSSs53zAKH4Q8YJg-1</code>.
Here, the address <code class="highlighter-rouge">16EMaNw3pkn3v6f2BgnSSs53zAKH4Q8YJg</code> had created one earlier
name in history prior to this one (which happens to be <code class="highlighter-rouge">abcdefgh123456.id</code>).</p>
<p>The purpose of a DID is to provide an eternal identifier for a public key.
The public key may change, but the DID will not.</p>
<p>Blockstack Core implements a DID method of its own
in order to be compatible with other systems that use DIDs for public key resolution.
In order for a DID to be resolvable, all of the following must be true for a
name:</p>
<ul>
<li>The name must exist</li>
<li>The name’s zone file hash must be the hash of a well-formed DNS zone file</li>
<li>The DNS zone file must be present in the BNS <a href="atlas_network.md">Atlas Network</a></li>
<li>The DNS zone file must contain a <code class="highlighter-rouge">URI</code> resource record that points to a signed
JSON Web Token</li>
<li>The public key that signed the JSON Web Token (and is included with it) must
hash to the address that owns the name</li>
</ul>
<p>Not all names will have DIDs that resolve to public keys. However, names created by the <a href="https://github.com/blockstack/blockstack-browser">Blockstack
Browser</a> will have DIDs that
do.</p>
<p>Developers can programmatically resolve DIDs via the Python API:</p>
<pre><code class="language-Python">&gt;&gt;&gt; import blockstack
&gt;&gt;&gt; blockstack.lib.client.resolve_DID('did:stack:v0:16EMaNw3pkn3v6f2BgnSSs53zAKH4Q8YJg-1', hostport='https://node.blockstack.org:6263')
{'public_key': '020fadbbcea0ff3b05f03195b41cd991d7a0af8bd38559943aec99cbdaf0b22cc8'}
</code></pre>
<p>A RESTful API is under development.</p>
<h3 id="did-encoding-for-subdomains">DID Encoding for Subdomains</h3>
<p>Every name and subdomain in BNS has a DID. The encoding is slightly different
for subdomains, so the software can determine which code-path to take.</p>
<ul>
<li>
<p>For on-chain BNS names, the <code class="highlighter-rouge"><span class="p">{</span><span class="err">address</span><span class="p">}</span></code> is the same as the Bitcoin address
that owns the name. Currently, both version byte 0 and version byte 5
addresses are supported (i.e. addresses starting with <code class="highlighter-rouge">1</code> or <code class="highlighter-rouge">3</code>, meaning <code class="highlighter-rouge">p2pkh</code> and
<code class="highlighter-rouge">p2sh</code> addresses).</p>
</li>
<li>
<p>For off-chain BNS subdomains, the <code class="highlighter-rouge"><span class="p">{</span><span class="err">address</span><span class="p">}</span></code> has version byte 63 for
subdomains owned by a single private key, and version byte 50 for subdomains
owned by a m-of-n set of private keys. That is, subdomain DID addresses start
with <code class="highlighter-rouge">S</code> or <code class="highlighter-rouge">M</code>, respectively.</p>
</li>
</ul>
<p>The <code class="highlighter-rouge"><span class="p">{</span><span class="err">index</span><span class="p">}</span></code> field for a subdomain’s DID is distinct from the <code class="highlighter-rouge"><span class="p">{</span><span class="err">index</span><span class="p">}</span></code> field
for a BNS name’s DID, even if the same created both names and subdomains.
For example, the name <code class="highlighter-rouge">abcdefgh123456.id</code> has the DID <code class="highlighter-rouge">did:stack:v0:16EMaNw3pkn3v6f2BgnSSs53zAKH4Q8YJg-0</code>,
because it was the first name created by <code class="highlighter-rouge">16EMaNw3pkn3v6f2BgnSSs53zAKH4Q8YJg</code>.
However, <code class="highlighter-rouge">16EMaNw3pkn3v6f2BgnSSs53zAKH4Q8YJg</code> <em>also</em> created <code class="highlighter-rouge">jude.statism.id</code>
as its first subdomain name. The DID for <code class="highlighter-rouge">jude.statism.id</code> is
<code class="highlighter-rouge">did:stack:v0:SSXMcDiCZ7yFSQSUj7mWzmDcdwYhq97p2i-0</code>. Note that the address
<code class="highlighter-rouge">SSXMcDiCZ7yFSQSUj7mWzmDcdwYhq97p2i</code> encodes the same public key hash as the address
<code class="highlighter-rouge">16EMaNw3pkn3v6f2BgnSSs53zAKH4Q8YJg</code> (the only difference between these two
strings is that the first is base58check-encoded with version byte 0, and the
second is encoded with version byte 63).</p>
<p>You can see this play out in practice with the following code snippit:</p>
<div class="language-python highlighter-rouge"><pre class="highlight"><code><span class="o">&gt;&gt;&gt;</span> <span class="kn">import</span> <span class="nn">blockstack</span>
<span class="o">&gt;&gt;&gt;</span> <span class="n">blockstack</span><span class="o">.</span><span class="n">lib</span><span class="o">.</span><span class="n">client</span><span class="o">.</span><span class="n">get_name_record</span><span class="p">(</span><span class="s">'jude.statism.id'</span><span class="p">,</span> <span class="n">hostport</span><span class="o">=</span><span class="s">'https://node.blockstack.org:6263'</span><span class="p">)[</span><span class="s">'address'</span><span class="p">]</span>
<span class="s">u'16EMaNw3pkn3v6f2BgnSSs53zAKH4Q8YJg'</span>
<span class="o">&gt;&gt;&gt;</span> <span class="kn">import</span> <span class="nn">virtualchain</span>
<span class="o">&gt;&gt;&gt;</span> <span class="n">virtualchain</span><span class="o">.</span><span class="n">address_reencode</span><span class="p">(</span><span class="s">'16EMaNw3pkn3v6f2BgnSSs53zAKH4Q8YJg'</span><span class="p">,</span> <span class="n">version_byte</span><span class="o">=</span><span class="mi">63</span><span class="p">)</span>
<span class="s">'SSXMcDiCZ7yFSQSUj7mWzmDcdwYhq97p2i'</span>
<span class="o">&gt;&gt;&gt;</span> <span class="n">blockstack</span><span class="o">.</span><span class="n">lib</span><span class="o">.</span><span class="n">client</span><span class="o">.</span><span class="n">resolve_DID</span><span class="p">(</span><span class="s">'did:stack:v0:SSXMcDiCZ7yFSQSUj7mWzmDcdwYhq97p2i-0'</span><span class="p">,</span> <span class="n">hostport</span><span class="o">=</span><span class="s">'https://node.blockstack.org:6263'</span><span class="p">)</span>
<span class="p">{</span><span class="s">'public_key'</span><span class="p">:</span> <span class="s">'020fadbbcea0ff3b05f03195b41cd991d7a0af8bd38559943aec99cbdaf0b22cc8'</span><span class="p">}</span>
</code></pre>
</div>
<h2 id="summary">Summary</h2>
<p>BNS is a decentralized naming system that produces names that are
globally-unique, human-readable, and strongly-owned. It does so by embedding a
database log within a public blockchain like Bitcoin, and replaying it locally
to calculate the state and owner of each name. In doing so, a BNS node provides
a full replica of all of the network’s state, which gives it the ability to
service queries like prior name states and name historys.</p>
<p>BNS groups names by namespaces in order to provide different ways to register
and use names, and furthermore implements subdomains to provide a cheap,
scalable way to register many names for the cost of a single blockchain
transaction.</p>
<p><a href="https://github.com/blockstack/blockstack-core">Blockstack Core</a> is the
reference implementation of BNS, and provides a public BNS node with online
documentation at https://core.blockstack.org.</p>
<h2 id="appendix-1-feature-comparison">Appendix 1: Feature Comparison</h2>
<p>BNS is not the only naming system in wide-spread use, nor is it the only
decentralized naming system that implements human-readable,
globally-unique, and strongly-owned names. The following feature table
describes how BNS differs from other naming systems</p>
<table>
<thead>
<tr>
<th>Feature</th>
<th>BNS</th>
<th><a href="https://ens.domains/">ENS</a></th>
<th>DNS</th>
<th><a href="https://namecoin.org/">Namecoin</a></th>
</tr>
</thead>
<tbody>
<tr>
<td>Globally unique names</td>
<td>X</td>
<td>X</td>
<td>X</td>
<td>X</td>
</tr>
<tr>
<td>Human-readable names</td>
<td>X</td>
<td>X</td>
<td>X</td>
<td>X</td>
</tr>
<tr>
<td>Strongly-owned names</td>
<td>X</td>
<td>X</td>
<td> </td>
<td>X</td>
</tr>
<tr>
<td>Names are enumerable</td>
<td>X</td>
<td> </td>
<td> </td>
<td>X</td>
</tr>
<tr>
<td>Registration times</td>
<td>1-2 hours</td>
<td>~1 week</td>
<td>~1 day</td>
<td>1-2 hours</td>
</tr>
<tr>
<td>Subdomain registration times</td>
<td>1 hour (instant with <a href="https://github.com/blockstack/blockstack-core/issues/750">#750</a>)</td>
<td>varies</td>
<td>instant</td>
<td>~1 hour</td>
</tr>
<tr>
<td>Anyone can make a TLD/namespace</td>
<td>X</td>
<td>[1]</td>
<td> </td>
<td>[1]</td>
</tr>
<tr>
<td>TLD/Namespace owners get registration fees</td>
<td>X</td>
<td> </td>
<td>X</td>
<td> </td>
</tr>
<tr>
<td>TLD/Namespace can be seeded with initial names</td>
<td>X</td>
<td> </td>
<td>X</td>
<td> </td>
</tr>
<tr>
<td>Portable across blockchains</td>
<td>X</td>
<td> </td>
<td>N/A</td>
<td> </td>
</tr>
<tr>
<td>Off-chain names</td>
<td>X</td>
<td> </td>
<td>N/A</td>
<td> </td>
</tr>
<tr>
<td>Off-chain name state</td>
<td>X</td>
<td>X</td>
<td>N/A</td>
<td> </td>
</tr>
<tr>
<td>Name provenance</td>
<td>X</td>
<td>X</td>
<td> </td>
<td>X</td>
</tr>
<tr>
<td><a href="http://identity.foundation">DID</a> support</td>
<td>X</td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Turing-complete namespace rules</td>
<td> </td>
<td>X</td>
<td>X</td>
<td> </td>
</tr>
<tr>
<td>Miners are rewarded for participating</td>
<td>[1]</td>
<td> </td>
<td>N/A</td>
<td>X</td>
</tr>
</tbody>
</table>
<p>[1] Requires support in higher-level applications. These systems are not aware
of the existence of namespaces/TLDs at the protocol level.</p>
<p>[2] Blockstack Core destroys the underlying blockchain token to pay for
registration fees when there is no pay-to-namespace-creator address set in the
name’s namespace. This has the effect of making the blockchain miners’ holdings
slightly more valuable.</p>
<div class="share uk-text-center">
<a href="https://twitter.com/intent/tweet?text=Blockstack Naming Service (BNS)&url=https://zbabystack.netlify.com/core/naming/introduction.html&via=&related=" rel="nofollow" target="_blank" title="Share on Twitter" onclick="window.open(this.href, 'twitter', 'width=550,height=235');return false;"><span data-uk-icon="icon: twitter; ratio: 1.2"></span></a>
<a class="uk-margin-small-left" href="https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fzbabystack.netlify.com%2Fcore%2Fnaming%2Fintroduction.html" rel="nofollow" target="_blank" title="Share on Facebook" onclick="window.open(this.href, 'facebook-share','width=580,height=296');return false;"><span data-uk-icon="icon: facebook; ratio: 1.2"></span></a>
</div>
</div>
<hr class="uk-margin-medium">
<div class="uk-margin-large-top">
<h3>Related Articles</h3>
<ul class="uk-list">
</ul>
</div>
</article>
<script>
// Table of contents scroll to
UIkit.scroll('#markdown-toc a', {
duration: 400,
offset: 120
});
</script>
</div>
</div>
</div>
<div id="offcanvas" data-uk-offcanvas="flip: true; overlay: true">
<div class="uk-offcanvas-bar">
<button class="uk-offcanvas-close" type="button" data-uk-close></button>
<ul class="uk-nav uk-nav-default">
<!-- <li><a class="uk-logo uk-margin-small-bottom" href="/"><img src="https://zbabystack.netlify.com/assets/posts/logo.png" alt="Docs"></a></li> -->
<li><a class="uk-logo uk-margin-small-bottom" href="/"><img src="/assets/posts/logo.png" alt="Docs"></a></li>
<li><a href="https://blockstack.org" target="_blank" >Blockstack.org</a></li>
<li><a href="https://forum.blockstack.org/" target="_blank" >Forums</a></li>
<li><a href="https://github.com/blockstack" target="_blank" >GitHub</a></li>
</ul>
<div class="uk-margin-small-top uk-text-center uk-text-muted uk-link-muted">
<div data-uk-grid class="uk-child-width-auto uk-grid-small uk-flex-center uk-grid">
<div class="uk-first-column">
<a href="https://twitter.com/" data-uk-icon="icon: twitter" class="uk-icon-link uk-icon" target="_blank"></a>
</div>
<div>
<a href="https://www.facebook.com/" data-uk-icon="icon: facebook" class="uk-icon-link uk-icon" target="_blank"></a>
</div>
<div>
<a href="https://www.instagram.com/" data-uk-icon="icon: instagram" class="uk-icon-link uk-icon" target="_blank"></a>
</div>
<div>
<a href="https://vimeo.com/" data-uk-icon="icon: vimeo" class="uk-icon-link uk-icon" target="_blank"></a>
</div>
</div>
</div>
</div>
</div>
<footer class="uk-section uk-text-center uk-text-muted uk-link-muted">
<div class="uk-container uk-container-small">
<div>
<ul class="uk-subnav uk-flex-center">
<li><a href="https://blockstack.org" target="_blank" >Blockstack.org</a></li>
<li><a href="https://forum.blockstack.org/" target="_blank" >Forums</a></li>
<li><a href="https://github.com/blockstack" target="_blank" >GitHub</a></li>
</ul>
</div>
<div class="uk-margin-medium">
<div data-uk-grid class="uk-child-width-auto uk-grid-small uk-flex-center uk-grid">
<div class="uk-first-column">
<a href="https://twitter.com/" data-uk-icon="icon: twitter" class="uk-icon-link uk-icon" target="_blank"></a>
</div>
<div>
<a href="https://www.facebook.com/" data-uk-icon="icon: facebook" class="uk-icon-link uk-icon" target="_blank"></a>
</div>
<div>
<a href="https://www.instagram.com/" data-uk-icon="icon: instagram" class="uk-icon-link uk-icon" target="_blank"></a>
</div>
<div>
<a href="https://vimeo.com/" data-uk-icon="icon: vimeo" class="uk-icon-link uk-icon" target="_blank"></a>
</div>
</div>
</div>
<div class="uk-margin-medium uk-text-small copyright">Blockstack</div>
</div>
</footer>
<script type="text/javascript">
/* Create a configuration object */
var ss360Config = {
/* Your site id */
siteId: 'blockstack',
/* A CSS selector that points to your search box */
searchBox: {selector: '#searchBox'}
};
</script>
<script src="https://cdn.sitesearch360.com/sitesearch360-v11.min.js" async></script>
</body>
</html>