758 lines
55 KiB
HTML
758 lines
55 KiB
HTML
|
|
|
|
<!DOCTYPE html>
|
|
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
|
|
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
|
|
<head>
|
|
<meta charset="utf-8">
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
|
<title>Low-Level API — ethers.js 2.1.0 documentation</title>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
|
|
|
|
|
|
|
|
<link rel="stylesheet" href="_static/css/ethers.css" type="text/css" />
|
|
|
|
<link rel="stylesheet" href="_static/css/ethers.css" type="text/css" />
|
|
|
|
|
|
|
|
<link rel="top" title="ethers.js 2.1.0 documentation" href="index.html"/>
|
|
<link rel="next" title="Cookbook" href="cookbook.html"/>
|
|
<link rel="prev" title="Utilities" href="api-utils.html"/>
|
|
|
|
|
|
<script src="_static/js/modernizr.min.js"></script>
|
|
|
|
</head>
|
|
|
|
<body class="wy-body-for-nav" role="document">
|
|
|
|
<div class="wy-grid-for-nav">
|
|
|
|
|
|
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
|
|
<div class="wy-side-scroll">
|
|
<div class="wy-side-nav-search">
|
|
|
|
|
|
|
|
<a href="index.html" class="icon icon-home"> ethers.js
|
|
|
|
|
|
|
|
</a>
|
|
|
|
|
|
|
|
|
|
<div class="version">
|
|
2.1.0
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div role="search">
|
|
<form id="rtd-search-form" class="wy-form" action="search.html" method="get">
|
|
<input type="text" name="q" placeholder="Search docs" />
|
|
<input type="hidden" name="check_keywords" value="yes" />
|
|
<input type="hidden" name="area" value="default" />
|
|
</form>
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
|
|
|
|
|
|
|
|
<p class="caption"><span class="caption-text">Developer Documentation</span></p>
|
|
<ul class="current">
|
|
<li class="toctree-l1"><a class="reference internal" href="getting-started.html">Getting Started</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="api.html">Application Programming Interface (API)</a></li>
|
|
<li class="toctree-l1 current"><a class="current reference internal" href="#">Low-Level API</a><ul>
|
|
<li class="toctree-l2"><a class="reference internal" href="#hdnode">HDNode</a><ul>
|
|
<li class="toctree-l3"><a class="reference internal" href="#creating-instances">Creating Instances</a></li>
|
|
<li class="toctree-l3"><a class="reference internal" href="#prototype">Prototype</a></li>
|
|
<li class="toctree-l3"><a class="reference internal" href="#static-methods">Static Methods</a></li>
|
|
<li class="toctree-l3"><a class="reference internal" href="#examples"><em>Examples</em></a></li>
|
|
</ul>
|
|
</li>
|
|
<li class="toctree-l2"><a class="reference internal" href="#interface">Interface</a><ul>
|
|
<li class="toctree-l3"><a class="reference internal" href="#creating-an-instance">Creating an Instance</a></li>
|
|
<li class="toctree-l3"><a class="reference internal" href="#id1">Prototype</a></li>
|
|
<li class="toctree-l3"><a class="reference internal" href="#id2">Static Methods</a></li>
|
|
<li class="toctree-l3"><a class="reference internal" href="#id3"><em>Examples</em></a></li>
|
|
</ul>
|
|
</li>
|
|
<li class="toctree-l2"><a class="reference internal" href="#provider-sub-classing">Provider (Sub-Classing)</a><ul>
|
|
<li class="toctree-l3"><a class="reference internal" href="#id4">Prototype</a></li>
|
|
<li class="toctree-l3"><a class="reference internal" href="#id5">Static Methods</a></li>
|
|
<li class="toctree-l3"><a class="reference internal" href="#id6"><em>Examples</em></a></li>
|
|
</ul>
|
|
</li>
|
|
<li class="toctree-l2"><a class="reference internal" href="#signing-key">Signing Key</a><ul>
|
|
<li class="toctree-l3"><a class="reference internal" href="#id7">Creating Instances</a></li>
|
|
<li class="toctree-l3"><a class="reference internal" href="#id8">Prototype</a></li>
|
|
<li class="toctree-l3"><a class="reference internal" href="#id9">Static Methods</a></li>
|
|
<li class="toctree-l3"><a class="reference internal" href="#id10"><em>Examples</em></a></li>
|
|
</ul>
|
|
</li>
|
|
<li class="toctree-l2"><a class="reference internal" href="#recursive-length-prefixed-encoding-rlp">Recursive-Length Prefixed Encoding (RLP)</a><ul>
|
|
<li class="toctree-l3"><a class="reference internal" href="#id11">Static Methods</a></li>
|
|
<li class="toctree-l3"><a class="reference internal" href="#id12"><em>Examples</em></a></li>
|
|
</ul>
|
|
</li>
|
|
</ul>
|
|
</li>
|
|
<li class="toctree-l1"><a class="reference internal" href="cookbook.html">Cookbook</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="notes.html">Notes</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="testing.html">Testing</a></li>
|
|
</ul>
|
|
|
|
|
|
|
|
</div>
|
|
</div>
|
|
</nav>
|
|
|
|
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
|
|
|
|
|
|
<nav class="wy-nav-top" role="navigation" aria-label="top navigation">
|
|
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
|
|
<a href="index.html">ethers.js</a>
|
|
</nav>
|
|
|
|
|
|
|
|
<div class="wy-nav-content">
|
|
<div class="rst-content">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<div role="navigation" aria-label="breadcrumbs navigation">
|
|
<ul class="wy-breadcrumbs">
|
|
<li><a href="index.html">Docs</a> »</li>
|
|
|
|
<li>Low-Level API</li>
|
|
<li class="wy-breadcrumbs-aside">
|
|
|
|
|
|
<a href="_sources/api-advanced.txt" rel="nofollow"> View page source</a>
|
|
|
|
|
|
</li>
|
|
</ul>
|
|
<hr/>
|
|
</div>
|
|
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
|
|
<div itemprop="articleBody">
|
|
|
|
<div class="section" id="low-level-api">
|
|
<h1>Low-Level API<a class="headerlink" href="#low-level-api" title="Permalink to this headline">¶</a></h1>
|
|
<p>These are advanced, low-level API features that should, for most people not be
|
|
necessary to worry about.</p>
|
|
<p>They are lightly documented here, and in the future will have more documentation,
|
|
but the emphasis at this point is documenting the more <a class="reference internal" href="api.html#api"><span class="std std-ref">common methods</span></a>.</p>
|
|
<hr class="docutils" />
|
|
<div class="section" id="hdnode">
|
|
<span id="api-hdnode"></span><h2>HDNode<a class="headerlink" href="#hdnode" title="Permalink to this headline">¶</a></h2>
|
|
<p>A <em>Hierarchical Deterministic Wallet</em> represents a large tree of private keys
|
|
which can reliably be reproduced from an initial seed. Each node in the tree
|
|
is represended by an HDNode which can be descended into.</p>
|
|
<p>A <em>mnemonic phrase</em> represents a simple way to generate the initial seed.</p>
|
|
<p>See the <a class="reference external" href="https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki">BIP 32 Specification</a> to learn more about HD Wallets and hardened vs
|
|
non-hardened nodes.</p>
|
|
<p>See the <a class="reference external" href="https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki">BIP 39 Specification</a> to learn more about Mnemonic Phrases.</p>
|
|
<div class="section" id="creating-instances">
|
|
<h3>Creating Instances<a class="headerlink" href="#creating-instances" title="Permalink to this headline">¶</a></h3>
|
|
<dl class="docutils">
|
|
<dt><sup>HDNode</sup> <strong>. fromMnemonic</strong> ( mnemonic )</dt>
|
|
<dd>Create an HDNode from a <em>mnemonic</em> phrase.</dd>
|
|
<dt><sup>HDNode</sup> <strong>. fromSeed</strong> ( seed )</dt>
|
|
<dd>Create an HDNode from a seed.</dd>
|
|
</dl>
|
|
</div>
|
|
<div class="section" id="prototype">
|
|
<h3>Prototype<a class="headerlink" href="#prototype" title="Permalink to this headline">¶</a></h3>
|
|
<dl class="docutils">
|
|
<dt><sup>prototype</sup> <strong>. privateKey</strong></dt>
|
|
<dd>The <a class="reference internal" href="api-utils.html#hexstring"><span class="std std-ref">hex string</span></a> private key for this node.</dd>
|
|
<dt><sup>prototype</sup> <strong>. publicKey</strong></dt>
|
|
<dd>The (compressed) public key for this node.</dd>
|
|
<dt><sup>prototype</sup> <strong>. chainCode</strong></dt>
|
|
<dd>The chain code for this node.</dd>
|
|
<dt><sup>prototype</sup> <strong>. index</strong></dt>
|
|
<dd>The index (from the parent) of this node (0 for the master node).</dd>
|
|
<dt><sup>prototype</sup> <strong>. depth</strong></dt>
|
|
<dd>The depth within th hierarchy of this node.</dd>
|
|
<dt><sup>prototype</sup> <strong>. derivePath</strong> ( path )</dt>
|
|
<dd>Derive the path from this node. Path is slash (<strong>/</strong>) delimited path components.
|
|
The first component may be “m” for master (which enforces the starting node is
|
|
infact a master node) and each subsequent path component should be a positive
|
|
integer (up to 31 bits), which can optionally include an apostrophe (<strong>‘</strong>) to
|
|
indicate hardened derivation for that path components. See below for some examples.</dd>
|
|
</dl>
|
|
</div>
|
|
<div class="section" id="static-methods">
|
|
<h3>Static Methods<a class="headerlink" href="#static-methods" title="Permalink to this headline">¶</a></h3>
|
|
<dl class="docutils">
|
|
<dt><sup>HDNode</sup> <strong>. mnemonicToEntropy</strong> ( mnemonic )</dt>
|
|
<dd>Convert a <em>mnemonic</em> to its binary entropy. (throws an error if the checksum
|
|
is invalid)</dd>
|
|
<dt><sup>HDNode</sup> <strong>. entropyToMnemonic</strong> ( entropy )</dt>
|
|
<dd>Convert the binary <em>entropy</em> to the mnemonic phrase.</dd>
|
|
<dt><sup>HDNode</sup> <strong>. mnemonicToSeed</strong> ( mnemonic )</dt>
|
|
<dd>Compute the BIP39 seed from <em>mnemonic</em>.</dd>
|
|
<dt><sup>HDNode</sup> <strong>. isValidMnemonic</strong> ( string )</dt>
|
|
<dd>Returns true if and only if the string is a valid mnemonic (including
|
|
the checksum)</dd>
|
|
</dl>
|
|
</div>
|
|
<div class="section" id="examples">
|
|
<h3><em>Examples</em><a class="headerlink" href="#examples" title="Permalink to this headline">¶</a></h3>
|
|
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">var</span> <span class="n">HDNode</span> <span class="o">=</span> <span class="n">ethers</span><span class="o">.</span><span class="n">HDNode</span><span class="p">;</span>
|
|
|
|
<span class="n">var</span> <span class="n">mnemonic</span> <span class="o">=</span> <span class="s2">"radar blur cabbage chef fix engine embark joy scheme fiction master release"</span><span class="p">;</span>
|
|
|
|
<span class="n">var</span> <span class="n">masterNode</span> <span class="o">=</span> <span class="n">HDNode</span><span class="o">.</span><span class="n">fromMnemonic</span><span class="p">(</span><span class="n">mnemonic</span><span class="p">);</span>
|
|
|
|
<span class="n">var</span> <span class="n">standardEthereum</span> <span class="o">=</span> <span class="n">masterNode</span><span class="o">.</span><span class="n">derivePath</span><span class="p">(</span><span class="s2">"m/44'/60'/0'/0/0"</span><span class="p">);</span>
|
|
</pre></div>
|
|
</div>
|
|
<hr class="docutils" />
|
|
</div>
|
|
</div>
|
|
<div class="section" id="interface">
|
|
<span id="api-interface"></span><h2>Interface<a class="headerlink" href="#interface" title="Permalink to this headline">¶</a></h2>
|
|
<p>The Interface Object is a meta-class that accepts a Solidity (or compitible)
|
|
Application Binary Interface (ABI) and populates functions to deal with encoding
|
|
and decoding the parameters to pass in and results returned.</p>
|
|
<div class="section" id="creating-an-instance">
|
|
<h3>Creating an Instance<a class="headerlink" href="#creating-an-instance" title="Permalink to this headline">¶</a></h3>
|
|
<dl class="docutils">
|
|
<dt>new <sup>ethers</sup> . Interface ( abi )</dt>
|
|
<dd>Returns a new instance and populates the properties with the ABI constructor,
|
|
methods and events. The <em>abi</em> may be either a JSON string or the parsed JSON
|
|
Object.</dd>
|
|
</dl>
|
|
</div>
|
|
<div class="section" id="id1">
|
|
<h3>Prototype<a class="headerlink" href="#id1" title="Permalink to this headline">¶</a></h3>
|
|
<dl class="docutils">
|
|
<dt><sup>prototype</sup> . abi</dt>
|
|
<dd>A <strong>copy</strong> of the ABI is returned, modifying this object will not alter the ABI.</dd>
|
|
<dt><sup>prototype</sup> . functions</dt>
|
|
<dd>An object of the functions available in the ABI, by name. (collissions are dropped)</dd>
|
|
<dt><sup>prototype</sup> . events</dt>
|
|
<dd>An object of the events available in the ABI, by name. (collisions are dropped)</dd>
|
|
<dt><sup>prototype</sup> . deployFunction ( bytecode [ , params... ])</dt>
|
|
<dd>The function to deploy the contract (compiled to <em>bytecode</em>) to the network, passing
|
|
<em>params</em> into the ABI constructor. If the ABI does not have a constructor, a default
|
|
one is generated.</dd>
|
|
</dl>
|
|
</div>
|
|
<div class="section" id="id2">
|
|
<h3>Static Methods<a class="headerlink" href="#id2" title="Permalink to this headline">¶</a></h3>
|
|
<dl class="docutils">
|
|
<dt><sup>Interface</sup> . encodeParams( types , values )</dt>
|
|
<dd>Returns a <a class="reference internal" href="api-utils.html#hexstring"><span class="std std-ref">hex string</span></a> of the <em>values</em> encoded as the <em>types</em>. (throws if a
|
|
value is invalid for the type)</dd>
|
|
<dt><sup>Interface</sup> . decodeParams( [ names , ] types , data )</dt>
|
|
<dd>Returns an Object by parsing <em>data</em> assuming <em>types</em>, with each parameter
|
|
accessible as apositional parameters. If <em>names</em> is provided, each
|
|
parameter is also accessible by its name. (throws if <em>data</em> is invalid
|
|
for the <em>types</em>)</dd>
|
|
</dl>
|
|
</div>
|
|
<div class="section" id="id3">
|
|
<h3><em>Examples</em><a class="headerlink" href="#id3" title="Permalink to this headline">¶</a></h3>
|
|
<p><strong>Creating an Interface Instance</strong></p>
|
|
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">var</span> <span class="n">Interface</span> <span class="o">=</span> <span class="n">ethers</span><span class="o">.</span><span class="n">Interface</span><span class="p">;</span>
|
|
|
|
<span class="n">var</span> <span class="n">abi</span> <span class="o">=</span> <span class="p">[</span>
|
|
<span class="p">{</span>
|
|
<span class="n">constant</span><span class="p">:</span> <span class="n">true</span><span class="p">,</span>
|
|
<span class="n">inputs</span><span class="p">:[],</span>
|
|
<span class="n">name</span><span class="p">:</span> <span class="s2">"getValue"</span><span class="p">,</span>
|
|
<span class="n">outputs</span><span class="p">:[</span> <span class="p">{</span> <span class="n">name</span><span class="p">:</span> <span class="s2">"value"</span><span class="p">,</span> <span class="nb">type</span><span class="p">:</span> <span class="s2">"string"</span><span class="p">}</span> <span class="p">],</span>
|
|
<span class="nb">type</span><span class="p">:</span> <span class="s2">"function"</span>
|
|
<span class="p">},</span>
|
|
<span class="p">{</span>
|
|
<span class="n">constant</span><span class="p">:</span> <span class="n">false</span><span class="p">,</span>
|
|
<span class="n">inputs</span><span class="p">:</span> <span class="p">[</span> <span class="p">{</span> <span class="n">name</span><span class="p">:</span> <span class="s2">"value"</span><span class="p">,</span> <span class="nb">type</span><span class="p">:</span> <span class="s2">"string"</span> <span class="p">}</span> <span class="p">],</span>
|
|
<span class="n">name</span><span class="p">:</span> <span class="s2">"setValue"</span><span class="p">,</span>
|
|
<span class="n">outputs</span><span class="p">:</span> <span class="p">[],</span>
|
|
<span class="nb">type</span><span class="p">:</span> <span class="s2">"function"</span>
|
|
<span class="p">},</span>
|
|
<span class="p">{</span>
|
|
<span class="n">anonymous</span><span class="p">:</span> <span class="n">false</span><span class="p">,</span>
|
|
<span class="n">inputs</span><span class="p">:[</span>
|
|
<span class="p">{</span> <span class="n">indexed</span><span class="p">:</span><span class="n">false</span><span class="p">,</span> <span class="n">name</span><span class="p">:</span> <span class="s2">"oldValue"</span><span class="p">,</span> <span class="nb">type</span><span class="p">:</span> <span class="s2">"string"</span> <span class="p">},</span>
|
|
<span class="p">{</span> <span class="n">indexed</span><span class="p">:</span><span class="n">false</span><span class="p">,</span> <span class="n">name</span><span class="p">:</span> <span class="s2">"newValue"</span><span class="p">,</span> <span class="nb">type</span><span class="p">:</span> <span class="s2">"string"</span> <span class="p">}</span>
|
|
<span class="p">],</span>
|
|
<span class="n">name</span><span class="p">:</span> <span class="s2">"valueChanged"</span><span class="p">,</span>
|
|
<span class="nb">type</span><span class="p">:</span> <span class="s2">"event"</span>
|
|
<span class="p">}</span>
|
|
<span class="p">];</span>
|
|
|
|
<span class="o">//</span> <span class="n">NOTE</span><span class="p">:</span> <span class="s2">"interface"</span> <span class="ow">is</span> <span class="n">a</span> <span class="n">reserved</span> <span class="n">keyword</span> <span class="ow">in</span> <span class="n">JavaScript</span>
|
|
|
|
<span class="n">var</span> <span class="n">iface</span> <span class="o">=</span> <span class="n">new</span> <span class="n">Interface</span><span class="p">(</span><span class="n">abi</span><span class="p">)</span>
|
|
</pre></div>
|
|
</div>
|
|
<p><strong>Call (Constant) Functions</strong></p>
|
|
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">var</span> <span class="n">getValueInfo</span> <span class="o">=</span> <span class="n">iface</span><span class="o">.</span><span class="n">function</span><span class="o">.</span><span class="n">getValue</span><span class="p">();</span>
|
|
|
|
<span class="n">console</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="n">getValueInfo</span><span class="p">);</span>
|
|
<span class="o">//</span> <span class="p">{</span>
|
|
<span class="o">//</span> <span class="n">name</span><span class="p">:</span> <span class="s2">"getValue"</span><span class="p">,</span>
|
|
<span class="o">//</span> <span class="n">signature</span><span class="p">:</span> <span class="s2">"getValue()"</span><span class="p">,</span>
|
|
<span class="o">//</span> <span class="n">data</span><span class="p">:</span> <span class="s2">"0x20965255"</span><span class="p">,</span>
|
|
<span class="o">//</span> <span class="n">parse</span><span class="p">:</span> <span class="n">function</span><span class="p">(</span><span class="n">result</span><span class="p">),</span>
|
|
<span class="o">//</span> <span class="nb">type</span><span class="p">:</span> <span class="s2">"call"</span>
|
|
<span class="o">//</span> <span class="p">}</span>
|
|
|
|
<span class="o">//</span> <span class="n">Here</span> <span class="ow">is</span> <span class="n">the</span> <span class="n">result</span> <span class="n">of</span><span class="p">:</span>
|
|
<span class="o">//</span> <span class="n">provider</span><span class="o">.</span><span class="n">call</span><span class="p">({</span>
|
|
<span class="o">//</span> <span class="n">to</span><span class="p">:</span> <span class="s2">"0x954De93D9f1Cd1e2e3AE5964F614CDcc821Fac64"</span><span class="p">,</span>
|
|
<span class="o">//</span> <span class="n">data</span><span class="p">:</span> <span class="n">getValue</span><span class="o">.</span><span class="n">data</span><span class="p">,</span>
|
|
<span class="o">//</span> <span class="p">})</span><span class="o">.</span><span class="n">then</span><span class="p">(</span><span class="n">function</span><span class="p">(</span><span class="n">result</span><span class="p">)</span> <span class="p">{</span>
|
|
<span class="o">//</span> <span class="n">console</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="n">result</span><span class="p">);</span>
|
|
<span class="o">//</span> <span class="p">});</span>
|
|
<span class="n">var</span> <span class="n">getDataResult</span> <span class="o">=</span> <span class="s2">"0x0000000000000000000000000000000000000000000000000000000000000020"</span> <span class="o">+</span>
|
|
<span class="s2">"000000000000000000000000000000000000000000000000000000000000000b"</span> <span class="o">+</span>
|
|
<span class="s2">"48656c6c6f20576f726c64000000000000000000000000000000000000000000"</span>
|
|
|
|
<span class="n">console</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="n">getValueInfo</span><span class="o">.</span><span class="n">parse</span><span class="p">(</span><span class="n">getDataResult</span><span class="p">));</span>
|
|
<span class="o">//</span> <span class="p">{</span>
|
|
<span class="o">//</span> <span class="mi">0</span><span class="p">:</span> <span class="s2">"Hello World"</span><span class="p">,</span>
|
|
<span class="o">//</span> <span class="n">value</span><span class="p">:</span> <span class="s2">"Hello World"</span><span class="p">,</span>
|
|
<span class="o">//</span> <span class="n">length</span><span class="p">:</span> <span class="mi">1</span>
|
|
<span class="o">//</span> <span class="p">}</span>
|
|
</pre></div>
|
|
</div>
|
|
<p><strong>Transaction (Non-Constant) Functions</strong></p>
|
|
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">var</span> <span class="n">setValueInfo</span> <span class="o">=</span> <span class="n">iface</span><span class="o">.</span><span class="n">functions</span><span class="o">.</span><span class="n">setValue</span><span class="p">(</span><span class="s2">"Foobar!"</span><span class="p">);</span>
|
|
|
|
<span class="n">console</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="n">setValueInfo</span><span class="p">);</span>
|
|
<span class="o">//</span> <span class="p">{</span>
|
|
<span class="o">//</span> <span class="n">name</span><span class="p">:</span> <span class="s2">"setValue"</span><span class="p">,</span>
|
|
<span class="o">//</span> <span class="n">signature</span><span class="p">:</span> <span class="s2">"setValue(string)"</span><span class="p">,</span>
|
|
<span class="o">//</span> <span class="n">data</span><span class="p">:</span> <span class="s2">"0x93a09352"</span> <span class="o">+</span>
|
|
<span class="o">//</span> <span class="s2">"0000000000000000000000000000000000000000000000000000000000000020"</span> <span class="o">+</span>
|
|
<span class="o">//</span> <span class="s2">"0000000000000000000000000000000000000000000000000000000000000007"</span> <span class="o">+</span>
|
|
<span class="o">//</span> <span class="s2">"466f6f6261722100000000000000000000000000000000000000000000000000"</span>
|
|
<span class="o">//</span> <span class="nb">type</span><span class="p">:</span> <span class="s2">"transaction"</span>
|
|
<span class="o">//</span> <span class="p">}</span>
|
|
|
|
<span class="o">//</span> <span class="n">To</span> <span class="n">send</span> <span class="n">this</span> <span class="n">to</span> <span class="n">the</span> <span class="n">network</span><span class="p">,</span> <span class="n">you</span> <span class="n">would</span> <span class="n">sign</span> <span class="ow">and</span> <span class="n">send</span> <span class="n">the</span> <span class="n">transaction</span><span class="p">:</span>
|
|
<span class="o">//</span> <span class="p">{</span>
|
|
<span class="o">//</span> <span class="n">to</span><span class="p">:</span> <span class="s2">"0x954De93D9f1Cd1e2e3AE5964F614CDcc821Fac64"</span><span class="p">,</span>
|
|
<span class="o">//</span> <span class="n">data</span><span class="p">:</span> <span class="n">setValueInfo</span><span class="o">.</span><span class="n">data</span><span class="p">,</span>
|
|
<span class="o">//</span> <span class="n">gasLimit</span><span class="p">:</span> <span class="n">someGasLimit</span><span class="p">,</span>
|
|
<span class="o">//</span> <span class="n">gasPrice</span><span class="p">:</span> <span class="n">someGasPrice</span><span class="p">,</span>
|
|
<span class="o">//</span> <span class="n">nonce</span><span class="p">:</span> <span class="n">yourTransactionCountForYourAddress</span>
|
|
<span class="o">//</span> <span class="p">}</span>
|
|
</pre></div>
|
|
</div>
|
|
<p><strong>Events</strong></p>
|
|
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">var</span> <span class="n">valueChangedInfo</span> <span class="o">=</span> <span class="n">iface</span><span class="o">.</span><span class="n">events</span><span class="o">.</span><span class="n">valueChanged</span><span class="p">();</span>
|
|
|
|
<span class="n">console</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="n">valueChangedInfo</span><span class="p">);</span>
|
|
<span class="o">//</span> <span class="p">{</span>
|
|
<span class="o">//</span> <span class="n">name</span><span class="p">:</span> <span class="s2">"valueChanged"</span><span class="p">,</span>
|
|
<span class="o">//</span> <span class="n">inputs</span><span class="p">:</span> <span class="p">(</span><span class="n">same</span> <span class="k">as</span> <span class="n">iface</span><span class="o">.</span><span class="n">abi</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span><span class="o">.</span><span class="n">inputs</span><span class="p">,</span>
|
|
<span class="o">//</span> <span class="n">parse</span><span class="p">:</span> <span class="n">function</span><span class="p">(</span><span class="n">data</span><span class="p">),</span>
|
|
<span class="o">//</span> <span class="n">signature</span><span class="p">:</span> <span class="s2">"valueChanged(string,string)"</span><span class="p">,</span>
|
|
<span class="o">//</span> <span class="n">topics</span><span class="p">:</span> <span class="p">[</span>
|
|
<span class="o">//</span> <span class="s2">"0x68ad6719a0070b3bb2f866fa0d46c8123b18cefe9b387ddb4feb6647ca418435"</span>
|
|
<span class="o">//</span> <span class="p">]</span>
|
|
<span class="o">//</span> <span class="p">}</span>
|
|
|
|
<span class="o">//</span> <span class="n">To</span> <span class="n">listen</span> <span class="k">for</span> <span class="n">this</span> <span class="n">event</span><span class="p">:</span>
|
|
<span class="n">provider</span><span class="o">.</span><span class="n">on</span><span class="p">(</span><span class="n">valueChangedInfo</span><span class="o">.</span><span class="n">topics</span><span class="p">,</span> <span class="n">function</span><span class="p">(</span><span class="n">data</span><span class="p">)</span> <span class="p">{</span>
|
|
<span class="n">var</span> <span class="n">result</span> <span class="o">=</span> <span class="n">valueChangedInfo</span><span class="o">.</span><span class="n">parse</span><span class="p">(</span><span class="n">data</span><span class="p">);</span>
|
|
|
|
<span class="n">console</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="n">result</span><span class="p">);</span>
|
|
<span class="o">//</span> <span class="p">{</span>
|
|
<span class="o">//</span> <span class="mi">0</span><span class="p">:</span> <span class="s2">"Hello World"</span><span class="p">,</span>
|
|
<span class="o">//</span> <span class="n">oldValue</span><span class="p">:</span> <span class="s2">"Hello World"</span><span class="p">,</span>
|
|
<span class="o">//</span> <span class="mi">1</span><span class="p">:</span> <span class="s2">"Foobar!"</span><span class="p">,</span>
|
|
<span class="o">//</span> <span class="n">newValue</span><span class="p">:</span> <span class="s2">"Foobar!"</span><span class="p">,</span>
|
|
<span class="o">//</span> <span class="p">}</span>
|
|
<span class="p">});</span>
|
|
</pre></div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<hr class="docutils" />
|
|
<div class="section" id="provider-sub-classing">
|
|
<h2>Provider (Sub-Classing)<a class="headerlink" href="#provider-sub-classing" title="Permalink to this headline">¶</a></h2>
|
|
<p>See the <a class="reference internal" href="api-providers.html#api-provider"><span class="std std-ref">Provider API</span></a> for more common usage. This documentation
|
|
is designed for developers that are sub-classing Provider.</p>
|
|
<div class="section" id="id4">
|
|
<h3>Prototype<a class="headerlink" href="#id4" title="Permalink to this headline">¶</a></h3>
|
|
<dl class="docutils">
|
|
<dt><sup>prototype</sup> . perform ( method , params )</dt>
|
|
<dd>The only method needed to override in a subclass. All values are sanitized
|
|
and defaults populated in params and the result is sanitized before returning.
|
|
Returns a <a class="reference internal" href="notes.html#promise"><span class="std std-ref">Promise</span></a>, see the example below for overview of
|
|
<em>method</em> and <em>params</em>.</dd>
|
|
</dl>
|
|
</div>
|
|
<div class="section" id="id5">
|
|
<h3>Static Methods<a class="headerlink" href="#id5" title="Permalink to this headline">¶</a></h3>
|
|
<dl class="docutils">
|
|
<dt><sup>Provider</sup> . inherits ( childProvider )</dt>
|
|
<dd>Set up <em>childProvider</em> as an provider, inheriting the parent prototype and
|
|
set up a prototype.inherits on the <em>childProvider</em>.</dd>
|
|
<dt><sup>Provider</sup> . fetchJSON ( url , body , processFunc )</dt>
|
|
<dd>Convenience method for returning a <a class="reference internal" href="notes.html#promise"><span class="std std-ref">Promise</span></a> with the result of fetching JSON
|
|
from a <em>url</em> with an optional <em>body</em>. The optional <em>processFunc</em> is called on
|
|
the parsed JSON before being passed to the Promise’s resolve. (throwing an error
|
|
in the <em>processFunc</em> will cause the Promise to reject)</dd>
|
|
</dl>
|
|
</div>
|
|
<div class="section" id="id6">
|
|
<h3><em>Examples</em><a class="headerlink" href="#id6" title="Permalink to this headline">¶</a></h3>
|
|
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="o">//</span> <span class="n">The</span> <span class="n">new</span> <span class="n">provider</span> <span class="n">Object</span>
|
|
<span class="n">function</span> <span class="n">DemoProvider</span><span class="p">(</span><span class="n">testnet</span><span class="p">,</span> <span class="n">somethingElse</span><span class="p">)</span> <span class="p">{</span>
|
|
<span class="n">Provide</span><span class="o">.</span><span class="n">call</span><span class="p">(</span><span class="n">this</span><span class="p">,</span> <span class="n">testnet</span><span class="p">);</span>
|
|
|
|
<span class="n">utils</span><span class="o">.</span><span class="n">defineProperty</span><span class="p">(</span><span class="n">this</span><span class="p">,</span> <span class="s1">'somethingElse'</span><span class="p">,</span> <span class="n">somethingElse</span><span class="p">);</span>
|
|
<span class="p">}</span>
|
|
|
|
<span class="o">//</span> <span class="n">Inherit</span> <span class="n">the</span> <span class="n">Provider</span>
|
|
<span class="n">Provider</span><span class="o">.</span><span class="n">inherits</span><span class="p">(</span><span class="n">DemoProvider</span><span class="p">);</span>
|
|
|
|
<span class="o">//</span> <span class="n">Override</span> <span class="n">perform</span>
|
|
<span class="n">utils</span><span class="o">.</span><span class="n">defineProperty</span><span class="p">(</span><span class="n">DemoProvider</span><span class="o">.</span><span class="n">prototype</span><span class="p">,</span> <span class="s1">'perform'</span><span class="p">,</span> <span class="n">function</span><span class="p">(</span><span class="n">method</span><span class="p">,</span> <span class="n">params</span><span class="p">)</span> <span class="p">{</span>
|
|
<span class="n">switch</span> <span class="p">(</span><span class="n">method</span><span class="p">)</span> <span class="p">{</span>
|
|
<span class="n">case</span> <span class="s1">'getBlockNumber'</span><span class="p">:</span>
|
|
<span class="o">//</span> <span class="n">Params</span><span class="p">:</span>
|
|
<span class="o">//</span> <span class="p">{</span> <span class="p">}</span>
|
|
|
|
<span class="n">case</span> <span class="s1">'getGasPrice'</span><span class="p">:</span>
|
|
<span class="o">//</span> <span class="n">Params</span><span class="p">:</span>
|
|
<span class="o">//</span> <span class="p">{</span> <span class="p">}</span>
|
|
|
|
<span class="n">case</span> <span class="s1">'getBalance'</span><span class="p">:</span>
|
|
<span class="o">//</span> <span class="n">Params</span><span class="p">:</span>
|
|
<span class="o">//</span> <span class="p">{</span>
|
|
<span class="o">//</span> <span class="n">address</span><span class="p">:</span> <span class="n">address</span><span class="p">,</span>
|
|
<span class="o">//</span> <span class="n">blockTag</span><span class="p">:</span> <span class="n">blockTag</span>
|
|
<span class="o">//</span> <span class="p">}</span>
|
|
|
|
<span class="n">case</span> <span class="s1">'getTransactionCount'</span><span class="p">:</span>
|
|
<span class="o">//</span> <span class="n">Params</span><span class="p">:</span>
|
|
<span class="o">//</span> <span class="p">{</span>
|
|
<span class="o">//</span> <span class="n">address</span><span class="p">:</span> <span class="n">address</span><span class="p">,</span>
|
|
<span class="o">//</span> <span class="n">blockTag</span><span class="p">:</span> <span class="n">blockTag</span>
|
|
<span class="o">//</span> <span class="p">}</span>
|
|
|
|
<span class="n">case</span> <span class="s1">'getCode'</span><span class="p">:</span>
|
|
<span class="o">//</span> <span class="n">Params</span><span class="p">:</span>
|
|
<span class="o">//</span> <span class="p">{</span>
|
|
<span class="o">//</span> <span class="n">address</span><span class="p">:</span> <span class="n">address</span><span class="p">,</span>
|
|
<span class="o">//</span> <span class="n">blockTag</span><span class="p">:</span> <span class="n">blockTag</span>
|
|
<span class="o">//</span> <span class="p">}</span>
|
|
|
|
<span class="n">case</span> <span class="s1">'getStorageAt'</span><span class="p">:</span>
|
|
<span class="o">//</span> <span class="n">Params</span><span class="p">:</span>
|
|
<span class="o">//</span> <span class="p">{</span>
|
|
<span class="o">//</span> <span class="n">address</span><span class="p">:</span> <span class="n">address</span><span class="p">,</span>
|
|
<span class="o">//</span> <span class="n">position</span><span class="p">:</span> <span class="n">hexString</span><span class="p">,</span>
|
|
<span class="o">//</span> <span class="n">blockTag</span><span class="p">:</span> <span class="n">blockTag</span>
|
|
<span class="o">//</span> <span class="p">}</span>
|
|
|
|
<span class="n">case</span> <span class="s1">'sendTransaction'</span><span class="p">:</span>
|
|
<span class="o">//</span> <span class="n">Params</span><span class="p">:</span>
|
|
<span class="o">//</span> <span class="p">{</span>
|
|
<span class="o">//</span> <span class="n">signedTransaction</span><span class="p">:</span> <span class="n">hexString</span>
|
|
<span class="o">//</span> <span class="p">}</span>
|
|
|
|
<span class="n">case</span> <span class="s1">'getBlock'</span><span class="p">:</span>
|
|
<span class="o">//</span> <span class="n">Params</span><span class="p">:</span>
|
|
<span class="o">//</span> <span class="n">Exactly</span> <span class="n">one</span> <span class="n">of</span> <span class="n">the</span> <span class="n">following</span> <span class="n">will</span> <span class="n">be</span> <span class="n">specified</span><span class="p">,</span> <span class="n">the</span> <span class="n">other</span> <span class="n">will</span> <span class="n">be</span> <span class="n">absent</span>
|
|
<span class="o">//</span> <span class="p">{</span>
|
|
<span class="o">//</span> <span class="n">blockHash</span><span class="p">:</span> <span class="n">blockHash</span><span class="p">,</span>
|
|
<span class="o">//</span> <span class="n">blockTag</span><span class="p">:</span> <span class="n">blockTag</span>
|
|
<span class="o">//</span> <span class="p">}</span>
|
|
|
|
<span class="n">case</span> <span class="s1">'getTransaction'</span><span class="p">:</span>
|
|
<span class="o">//</span> <span class="n">Params</span><span class="p">:</span>
|
|
<span class="o">//</span> <span class="p">{</span>
|
|
<span class="o">//</span> <span class="n">transactionHash</span><span class="p">:</span> <span class="n">hexString</span>
|
|
<span class="o">//</span> <span class="p">}</span>
|
|
|
|
<span class="n">case</span> <span class="s1">'getTransactionReceipt'</span><span class="p">:</span>
|
|
<span class="o">//</span> <span class="n">Params</span><span class="p">:</span>
|
|
<span class="o">//</span> <span class="p">{</span>
|
|
<span class="o">//</span> <span class="n">transactionHash</span><span class="p">:</span> <span class="n">hexString</span>
|
|
<span class="o">//</span> <span class="p">}</span>
|
|
|
|
<span class="n">case</span> <span class="s1">'call'</span><span class="p">:</span>
|
|
<span class="o">//</span> <span class="n">Params</span><span class="p">:</span>
|
|
<span class="o">//</span> <span class="p">{</span>
|
|
<span class="o">//</span> <span class="n">transaction</span><span class="p">:</span> <span class="n">See</span> <span class="n">Transaction</span> <span class="n">Requests</span> <span class="p">(</span><span class="n">on</span> <span class="n">Providers</span> <span class="n">API</span><span class="p">)</span>
|
|
<span class="o">//</span> <span class="p">}</span>
|
|
|
|
<span class="n">case</span> <span class="s1">'estimateGas'</span><span class="p">:</span>
|
|
<span class="o">//</span> <span class="n">Params</span><span class="p">:</span>
|
|
<span class="o">//</span> <span class="p">{</span>
|
|
<span class="o">//</span> <span class="n">transaction</span><span class="p">:</span> <span class="n">See</span> <span class="n">Transaction</span> <span class="n">Requests</span> <span class="p">(</span><span class="n">on</span> <span class="n">Providers</span> <span class="n">API</span><span class="p">)</span>
|
|
<span class="o">//</span> <span class="p">}</span>
|
|
|
|
<span class="n">case</span> <span class="s1">'getLogs'</span><span class="p">:</span>
|
|
<span class="o">//</span> <span class="n">Params</span><span class="p">:</span>
|
|
<span class="o">//</span> <span class="p">{</span>
|
|
<span class="o">//</span> <span class="n">address</span><span class="p">:</span> <span class="n">address</span><span class="p">,</span>
|
|
<span class="o">//</span> <span class="n">fromBlock</span><span class="p">:</span> <span class="n">blockTag</span><span class="p">,</span>
|
|
<span class="o">//</span> <span class="n">toBlock</span><span class="p">:</span> <span class="n">blockTag</span><span class="p">,</span>
|
|
<span class="o">//</span> <span class="n">topics</span><span class="p">:</span> <span class="n">array</span> <span class="p">(</span><span class="n">possibly</span> <span class="n">nested</span><span class="p">)</span> <span class="n">of</span> <span class="n">topics</span>
|
|
<span class="o">//</span> <span class="p">}</span>
|
|
|
|
<span class="n">default</span><span class="p">:</span>
|
|
<span class="k">break</span><span class="p">;</span>
|
|
<span class="p">}</span>
|
|
|
|
<span class="k">return</span> <span class="n">Promise</span><span class="o">.</span><span class="n">reject</span><span class="p">(</span><span class="n">new</span> <span class="n">Error</span><span class="p">(</span><span class="s1">'not implemented - '</span> <span class="o">+</span> <span class="n">method</span><span class="p">));</span>
|
|
<span class="p">});</span>
|
|
</pre></div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<hr class="docutils" />
|
|
<div class="section" id="signing-key">
|
|
<h2>Signing Key<a class="headerlink" href="#signing-key" title="Permalink to this headline">¶</a></h2>
|
|
<p>The SigningKey interface provides an abstraction around the
|
|
<em>secp256k1 elliptic curve cryptography</em> library, which signs digests.</p>
|
|
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">var</span> <span class="n">SigningKey</span> <span class="o">=</span> <span class="n">ethers</span><span class="o">.</span><span class="n">_SigningKey</span><span class="p">;</span>
|
|
</pre></div>
|
|
</div>
|
|
<div class="section" id="id7">
|
|
<h3>Creating Instances<a class="headerlink" href="#id7" title="Permalink to this headline">¶</a></h3>
|
|
<p>A private key may be a any <a class="reference internal" href="api-utils.html#hexstring"><span class="std std-ref">hex string</span></a> or an <a class="reference internal" href="api-utils.html#api-arrayish"><span class="std std-ref">Arrayish</span></a>
|
|
representing 32 bytes.</p>
|
|
<dl class="docutils">
|
|
<dt>new <sup>ethers</sup> . _SigningKey ( privateKey )</dt>
|
|
<dd>Create a new SigningKey and compute the corresponding public key and address.</dd>
|
|
</dl>
|
|
</div>
|
|
<div class="section" id="id8">
|
|
<h3>Prototype<a class="headerlink" href="#id8" title="Permalink to this headline">¶</a></h3>
|
|
<dl class="docutils">
|
|
<dt><sup>prototype</sup> . privateKey</dt>
|
|
<dd>The private key.</dd>
|
|
<dt><sup>prototype</sup> . publicKey</dt>
|
|
<dd>The compressed public key.</dd>
|
|
<dt><sup>prototype</sup> . address</dt>
|
|
<dd>The Ethereum address for this key pair.</dd>
|
|
<dt><sup>prototype</sup> . signDigest ( messageDigest )</dt>
|
|
<dd>The compressed public key</dd>
|
|
</dl>
|
|
</div>
|
|
<div class="section" id="id9">
|
|
<h3>Static Methods<a class="headerlink" href="#id9" title="Permalink to this headline">¶</a></h3>
|
|
<dl class="docutils">
|
|
<dt><sup>_SigningKey</sup> . recover( digest, r, s, recoveryParam )</dt>
|
|
<dd>Given a message <em>digest</em> and the signature parameters <em>r</em>, <em>s</em>
|
|
and <em>recoveryParam</em> compute the the address that signed the
|
|
message.</dd>
|
|
<dt><sup>_SigningKey</sup> . getPublicKey( publicOrPrivateKey [, compressed] )</dt>
|
|
<dd><p class="first">Given a <em>publicOrPrivateKey</em>, return the public key, optionally <em>compressed</em>.</p>
|
|
<p class="last"><strong>default:</strong> <em>compressed</em>=false</p>
|
|
</dd>
|
|
<dt><sup>_SigningKey</sup> . publicKeyToAddress( publicOrPrivateKey )</dt>
|
|
<dd>Convert a <em>publicOrPrivateKey</em> to an Ethereum address.</dd>
|
|
</dl>
|
|
</div>
|
|
<div class="section" id="id10">
|
|
<h3><em>Examples</em><a class="headerlink" href="#id10" title="Permalink to this headline">¶</a></h3>
|
|
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">var</span> <span class="n">SigningKey</span> <span class="o">=</span> <span class="n">ethers</span><span class="o">.</span><span class="n">_SigningKey</span><span class="p">;</span>
|
|
|
|
<span class="n">var</span> <span class="n">privateKey</span> <span class="o">=</span> <span class="s1">'0x0123456789012345678901234567890123456789012345678901234567890123'</span><span class="p">;</span>
|
|
<span class="n">var</span> <span class="n">signingKey</span> <span class="o">=</span> <span class="n">new</span> <span class="n">SigningKey</span><span class="p">(</span><span class="n">privateKey</span><span class="p">);</span>
|
|
|
|
<span class="n">console</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="s1">'Address: '</span> <span class="o">+</span> <span class="n">signingKey</span><span class="o">.</span><span class="n">address</span><span class="p">;</span>
|
|
<span class="o">//</span> <span class="s2">"Address: 0x14791697260E4c9A71f18484C9f997B308e59325"</span>
|
|
|
|
<span class="n">var</span> <span class="n">message</span> <span class="o">=</span> <span class="s2">"Hello World"</span><span class="p">;</span>
|
|
<span class="n">var</span> <span class="n">messageBytes</span> <span class="o">=</span> <span class="n">ethers</span><span class="o">.</span><span class="n">utils</span><span class="o">.</span><span class="n">toUtf8Bytes</span><span class="p">(</span><span class="n">message</span><span class="p">);</span>
|
|
<span class="n">var</span> <span class="n">messageDigest</span> <span class="o">=</span> <span class="n">ethers</span><span class="o">.</span><span class="n">utils</span><span class="o">.</span><span class="n">keccak256</span><span class="p">(</span><span class="n">messageBytes</span><span class="p">);</span>
|
|
|
|
<span class="n">console</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="s2">"Digest: "</span> <span class="o">+</span> <span class="n">messageDigest</span><span class="p">);</span>
|
|
<span class="o">//</span> <span class="s2">"Digest: 0x592fa743889fc7f92ac2a37bb1f5ba1daf2a5c84741ca0e0061d243a2e6707ba"</span>
|
|
|
|
<span class="n">var</span> <span class="n">signature</span> <span class="o">=</span> <span class="n">signingKey</span><span class="o">.</span><span class="n">signDigest</span><span class="p">(</span><span class="n">messageDigest</span><span class="p">);</span>
|
|
|
|
<span class="n">console</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="n">signature</span><span class="p">);</span>
|
|
<span class="o">//</span> <span class="p">{</span>
|
|
<span class="o">//</span> <span class="n">recoveryParam</span><span class="p">:</span> <span class="mi">0</span><span class="p">,</span>
|
|
<span class="o">//</span> <span class="n">r</span><span class="p">:</span> <span class="s2">"0x79f56f3422dc67f57b2aeeb0b20295a99ec90420b203177f83d419c98beda7fe"</span><span class="p">,</span>
|
|
<span class="o">//</span> <span class="n">s</span><span class="p">:</span> <span class="s2">"0x1a9d05433883bdc7e6d882740f4ea7921ef458a61b2cfe6197c2bb1bc47236fd"</span>
|
|
<span class="o">//</span> <span class="p">}</span>
|
|
|
|
<span class="n">var</span> <span class="n">recovered</span> <span class="o">=</span> <span class="n">SigningKey</span><span class="o">.</span><span class="n">recover</span><span class="p">(</span><span class="n">messageDigest</span><span class="p">,</span> <span class="n">signature</span><span class="o">.</span><span class="n">r</span><span class="p">,</span>
|
|
<span class="n">signature</span><span class="o">.</span><span class="n">s</span><span class="p">,</span> <span class="n">signature</span><span class="o">.</span><span class="n">recoveryParam</span><span class="p">);</span>
|
|
|
|
<span class="n">console</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="s2">"Recovered: "</span> <span class="o">+</span> <span class="n">recovered</span><span class="p">);</span>
|
|
<span class="o">//</span> <span class="s2">"Recovered: 0x14791697260E4c9A71f18484C9f997B308e59325"</span>
|
|
|
|
<span class="n">var</span> <span class="n">publicKey</span> <span class="o">=</span> <span class="n">signingKey</span><span class="o">.</span><span class="n">publicKey</span><span class="p">;</span>
|
|
|
|
<span class="n">console</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="s1">'Public Key: '</span> <span class="o">+</span> <span class="n">publicKey</span><span class="p">);</span>
|
|
<span class="o">//</span> <span class="s2">"Public Key: 0x026655feed4d214c261e0a6b554395596f1f1476a77d999560e5a8df9b8a1a3515"</span>
|
|
|
|
<span class="n">var</span> <span class="n">compressedPublicKey</span> <span class="o">=</span> <span class="n">SigningKey</span><span class="o">.</span><span class="n">getPublicKey</span><span class="p">(</span><span class="n">publicKey</span><span class="p">,</span> <span class="n">true</span><span class="p">);</span>
|
|
<span class="n">var</span> <span class="n">uncompressedPublicKey</span> <span class="o">=</span> <span class="n">SigningKey</span><span class="o">.</span><span class="n">getPublicKey</span><span class="p">(</span><span class="n">publicKey</span><span class="p">,</span> <span class="n">false</span><span class="p">);</span>
|
|
|
|
<span class="n">console</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="s1">'Compressed: '</span> <span class="o">+</span> <span class="n">compressedPublicKey</span><span class="p">);</span>
|
|
<span class="o">//</span> <span class="s2">"Compressed: 0x026655feed4d214c261e0a6b554395596f1f1476a77d999560e5a8df9b8a1a3515"</span>
|
|
|
|
<span class="n">console</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="s1">'Uncompressed: '</span> <span class="o">+</span> <span class="n">uncompressedPublicKey</span><span class="p">);</span>
|
|
<span class="o">//</span> <span class="s2">"Uncompressed: 0x046655feed4d214c261e0a6b554395596f1f1476a77d999560e5a8df9b8a1a35"</span> <span class="o">+</span>
|
|
<span class="o">//</span> <span class="s2">"15217e88dd05e938efdd71b2cce322bf01da96cd42087b236e8f5043157a9c068e"</span>
|
|
|
|
<span class="n">var</span> <span class="n">address</span> <span class="o">=</span> <span class="n">SigningKey</span><span class="o">.</span><span class="n">publicKeyToAddress</span><span class="p">(</span><span class="n">publicKey</span><span class="p">);</span>
|
|
|
|
<span class="n">console</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="s1">'Address: '</span> <span class="o">+</span> <span class="n">address</span><span class="p">);</span>
|
|
<span class="o">//</span> <span class="s2">"Address: 0x14791697260E4c9A71f18484C9f997B308e59325"</span>
|
|
</pre></div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<hr class="docutils" />
|
|
<div class="section" id="recursive-length-prefixed-encoding-rlp">
|
|
<h2>Recursive-Length Prefixed Encoding (RLP)<a class="headerlink" href="#recursive-length-prefixed-encoding-rlp" title="Permalink to this headline">¶</a></h2>
|
|
<p>This encoding method is used internally for several aspects of Ethereum, such as
|
|
encoding transactions and determining contract addresses. For most developers this
|
|
should not be necessary to use.</p>
|
|
<p>RLP can encode nested arrays, with data as <a class="reference internal" href="api-utils.html#hexstring"><span class="std std-ref">hex strings</span></a> and Uint8Array (or other non-Array
|
|
<a class="reference internal" href="api-utils.html#api-arrayish"><span class="std std-ref">arrayish</span></a> objects). A decoded object will always have data represented as <a class="reference internal" href="api-utils.html#hexstring"><span class="std std-ref">hex strings</span></a> and
|
|
Arrays.</p>
|
|
<p>See: <a class="reference external" href="https://github.com/ethereum/wiki/wiki/RLP">https://github.com/ethereum/wiki/wiki/RLP</a></p>
|
|
<div class="section" id="id11">
|
|
<h3>Static Methods<a class="headerlink" href="#id11" title="Permalink to this headline">¶</a></h3>
|
|
<dl class="docutils">
|
|
<dt><sup>RLP</sup> . encode( object )</dt>
|
|
<dd>Encodes an object as an RLP <a class="reference internal" href="api-utils.html#hexstring"><span class="std std-ref">hex string</span></a>. (throws an Error if the object contains
|
|
invalid items)</dd>
|
|
<dt><sup>RLP</sup> . decode( hexStringOrArrayish )</dt>
|
|
<dd>Decode <em>hexStringOrArrayish</em> into the encoded object. (throws an Error if
|
|
invalid RLP-coded data)</dd>
|
|
</dl>
|
|
</div>
|
|
<div class="section" id="id12">
|
|
<h3><em>Examples</em><a class="headerlink" href="#id12" title="Permalink to this headline">¶</a></h3>
|
|
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">var</span> <span class="n">RLP</span> <span class="o">=</span> <span class="n">requrie</span><span class="p">(</span><span class="s1">'ethers-utils/rlp'</span><span class="p">);</span>
|
|
|
|
<span class="n">var</span> <span class="nb">object</span> <span class="o">=</span> <span class="p">[</span> <span class="p">[</span><span class="s2">"0x42"</span><span class="p">],</span> <span class="s2">"0x1234"</span><span class="p">,</span> <span class="p">[</span> <span class="p">[],</span> <span class="p">[]</span> <span class="p">]</span> <span class="p">];</span>
|
|
|
|
<span class="n">var</span> <span class="n">encoded</span> <span class="o">=</span> <span class="n">rlp</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span><span class="nb">object</span><span class="p">);</span>
|
|
<span class="n">console</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="n">encoded</span><span class="p">);</span>
|
|
<span class="o">//</span> <span class="mh">0xc8c142821234c2c0c0</span>
|
|
|
|
<span class="n">var</span> <span class="n">decoded</span> <span class="o">=</span> <span class="n">rlp</span><span class="o">.</span><span class="n">decode</span><span class="p">(</span><span class="n">encoded</span><span class="p">);</span>
|
|
<span class="n">console</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="n">decoded</span><span class="p">);</span>
|
|
<span class="o">//</span> <span class="p">[</span> <span class="p">[</span> <span class="s1">'0x42'</span> <span class="p">],</span> <span class="s1">'0x1234'</span><span class="p">,</span> <span class="p">[</span> <span class="p">[],</span> <span class="p">[]</span> <span class="p">]</span> <span class="p">]</span>
|
|
</pre></div>
|
|
</div>
|
|
<hr class="docutils" />
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
</div>
|
|
</div>
|
|
<footer>
|
|
|
|
<div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
|
|
|
|
<a href="cookbook.html" class="btn btn-neutral float-right" title="Cookbook" accesskey="n">Next <span class="fa fa-arrow-circle-right"></span></a>
|
|
|
|
|
|
<a href="api-utils.html" class="btn btn-neutral" title="Utilities" accesskey="p"><span class="fa fa-arrow-circle-left"></span> Previous</a>
|
|
|
|
</div>
|
|
|
|
|
|
<hr/>
|
|
|
|
<div role="contentinfo">
|
|
<p>
|
|
© Copyright 2016, Richard Moore <me@ricmoo.com>.
|
|
|
|
</p>
|
|
</div>
|
|
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
|
|
|
|
</footer>
|
|
|
|
</div>
|
|
</div>
|
|
|
|
</section>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<script type="text/javascript">
|
|
var DOCUMENTATION_OPTIONS = {
|
|
URL_ROOT:'./',
|
|
VERSION:'2.1.0',
|
|
COLLAPSE_INDEX:false,
|
|
FILE_SUFFIX:'.html',
|
|
HAS_SOURCE: true
|
|
};
|
|
</script>
|
|
<script type="text/javascript" src="_static/jquery.js"></script>
|
|
<script type="text/javascript" src="_static/underscore.js"></script>
|
|
<script type="text/javascript" src="_static/doctools.js"></script>
|
|
|
|
|
|
|
|
|
|
|
|
<script type="text/javascript" src="_static/js/theme.js"></script>
|
|
|
|
|
|
|
|
|
|
<script type="text/javascript">
|
|
jQuery(function () {
|
|
SphinxRtdTheme.StickyNav.enable();
|
|
});
|
|
</script>
|
|
|
|
|
|
</body>
|
|
</html> |