ethers.js/docs/v5/api/utils/hdnode/index.html
2020-07-03 01:54:56 -04:00

96 lines
23 KiB
HTML

<!DOCTYPE html>
<html class="paged">
<head>
<title>HD Wallet</title>
<link rel="stylesheet" type="text/css" href="/v5/static/style.css">
</head>
<body>
<div class="sidebar">
<div class="header">
<div class="logo"><a href="/v5/"><div class="image"></div><div class="name">ethers</div><div class="version">v5.0</div></a></div>
</div>
<div class="toc"><div>
<div class="link title"><a href="/v5/">Documentation</a></div><div class="base show link depth-1"><a href="/v5/getting-started/">Getting Started</a></div><div class="base show link depth-1"><a href="/v5/concepts/">Ethereum Basics</a></div><div class="hide link depth-2"><a href="/v5/concepts/events/">Events</a></div><div class="hide link depth-2"><a href="/v5/concepts/gas/">Gas</a></div><div class="hide link depth-2"><a href="/v5/concepts/security/">Security</a></div><div class="base ancestor show link depth-1"><a href="/v5/api/">Application Programming Interface</a></div><div class="show link depth-2"><a href="/v5/api/contract/">Contract Interaction</a></div><div class="hide link depth-3"><a href="/v5/api/contract/contract/">Contract</a></div><div class="hide link depth-3"><a href="/v5/api/contract/contract-factory/">ContractFactory</a></div><div class="hide link depth-3"><a href="/v5/api/contract/example/">Example: ERC-20 Contract</a></div><div class="show link depth-2"><a href="/v5/api/signer/">Signers</a></div><div class="show link depth-2"><a href="/v5/api/providers/">Providers</a></div><div class="hide link depth-3"><a href="/v5/api/providers/provider/">Provider</a></div><div class="hide link depth-3"><a href="/v5/api/providers/jsonrpc-provider/">JsonRpcProvider</a></div><div class="hide link depth-3"><a href="/v5/api/providers/api-providers/">API Providers</a></div><div class="hide link depth-3"><a href="/v5/api/providers/other/">Other Providers</a></div><div class="hide link depth-3"><a href="/v5/api/providers/types/">Types</a></div><div class="ancestor show link depth-2"><a href="/v5/api/utils/">Utilities</a></div><div class="show link depth-3"><a href="/v5/api/utils/abi/">Application Binary Interface</a></div><div class="hide link depth-4"><a href="/v5/api/utils/abi/coder/">AbiCoder</a></div><div class="hide link depth-4"><a href="/v5/api/utils/abi/formats/">ABI Formats</a></div><div class="hide link depth-4"><a href="/v5/api/utils/abi/fragments/">Fragments</a></div><div class="hide link depth-4"><a href="/v5/api/utils/abi/interface/">Interface</a></div><div class="show link depth-3"><a href="/v5/api/utils/address/">Addresses</a></div><div class="show link depth-3"><a href="/v5/api/utils/bignumber/">BigNumber</a></div><div class="show link depth-3"><a href="/v5/api/utils/bytes/">Byte Manipulation</a></div><div class="show link depth-3"><a href="/v5/api/utils/constants/">Constants</a></div><div class="show link depth-3"><a href="/v5/api/utils/display-logic/">Display Logic and Input</a></div><div class="show link depth-3"><a href="/v5/api/utils/encoding/">Encoding Utilities</a></div><div class="show link depth-3"><a href="/v5/api/utils/fixednumber/">FixedNumber</a></div><div class="show link depth-3"><a href="/v5/api/utils/hashing/">Hashing Algorithms</a></div><div class="myself ancestor ancestor show link depth-3"><a href="/v5/api/utils/hdnode/">HD Wallet</a></div><div class="show link depth-3"><a href="/v5/api/utils/logger/">Logging</a></div><div class="show link depth-3"><a href="/v5/api/utils/properties/">Property Utilities</a></div><div class="show link depth-3"><a href="/v5/api/utils/signing-key/">Signing Key</a></div><div class="show link depth-3"><a href="/v5/api/utils/strings/">Strings</a></div><div class="show link depth-3"><a href="/v5/api/utils/transactions/">Transactions</a></div><div class="show link depth-3"><a href="/v5/api/utils/web/">Web Utilities</a></div><div class="show link depth-3"><a href="/v5/api/utils/wordlists/">Wordlists</a></div><div class="show link depth-2"><a href="/v5/api/other/">Other Libraries</a></div><div class="hide link depth-3"><a href="/v5/api/other/assembly/">Assembly</a></div><div class="hide link depth-4"><a href="/v5/api/other/assembly/dialect/">Ethers ASM Dialect</a></div><div class="hide link depth-4"><a href="/v5/api/other/assembly/api/">Utilities</a></div><div class="hide link depth-4"><a href="/v5/api/other/assembly/ast/">Abstract Syntax Tree</a></div><div class="hide link depth-3"><a href="/v5/api/other/hardware/">Hardware Wallets</a></div><div class="show link depth-2"><a href="/v5/api/experimental/">Experimental</a></div><div class="base show link depth-1"><a href="/v5/cli/">Command Line Interfaces</a></div><div class="hide link depth-2"><a href="/v5/cli/ethers/">Sandbox Utility</a></div><div class="hide link depth-2"><a href="/v5/cli/asm/">Assembler</a></div><div class="hide link depth-2"><a href="/v5/cli/ens/">Ethereum Naming Service</a></div><div class="hide link depth-2"><a href="/v5/cli/typescript/">TypeScript</a></div><div class="hide link depth-2"><a href="/v5/cli/plugin/">Making Your Own</a></div><div class="base show link depth-1"><a href="/v5/cookbook/">Cookbook</a></div><div class="base show link depth-1"><a href="/v5/migration/">Migration Guide</a></div><div class="hide link depth-2"><a href="/v5/migration/web3/">Migration: From Web3.js</a></div><div class="hide link depth-2"><a href="/v5/migration/ethers-v4/">Migration: From Ethers v4</a></div><div class="base show link depth-1"><a href="/v5/testing/">Testing</a></div><div class="base show link depth-1"><a href="/v5/contributing/">Contributing and Hacking</a></div><div class="base show link depth-1"><a href="/v5/documentation/">Flatworm Docs</a></div><div class="base show link depth-1"><a href="/v5/license/">License and Copyright</a></div>
</div></div>
</div>
<div class="content">
<div class="breadcrumbs"><a href="/v5/">Documentation</a>&nbsp;&nbsp;&raquo;&nbsp;&nbsp;<a href="/v5/api/">API</a>&nbsp;&nbsp;&raquo;&nbsp;&nbsp;<a href="/v5/api/utils/">Utilities</a>&nbsp;&nbsp;&raquo;&nbsp;&nbsp;<span class="current">HD Wallet</span></div>
<a name="hdnodes"></a><a name="hdnodes"></a><h1 class="show-anchors"><div>HD Wallet<div class="anchors"><a class="self" href="/v5/api/utils/hdnode/#hdnodes"></a></div></div></h1><p>TODO: Explain <a href="https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki">BIP32</a> <a href="https://en.bitcoin.it/wiki/BIP_0039">BIP-39</a> and whatnot here...</p>
<a name="hdnodes--types"></a><h2 class="show-anchors"><div>Types<div class="anchors"><a class="self" href="/v5/api/utils/hdnode/#hdnodes--types"></a></div></div></h2>
<a name="hdnodes--defaultpath"></a><a name="hdnodes--types--hdnodes--defaultpath"></a><h3 class="show-anchors"><div>Constants<div class="anchors"><a class="self" href="/v5/api/utils/hdnode/#hdnodes--defaultpath"></a><a class="source" href="https://github.com/ethers-io/ethers.js/blob/master/packages/hdnode/src.ts/index.ts#L67">source</a></div></div></h3>
<div class="property show-anchors"><div class="signature"><span class="path">ethers</span><span class="symbol">.</span><span class="path">utils</span><span class="symbol">.</span><span class="method">defaultPath</span> <span class="arrow">&rArr;</span> <span class="returns">"m/44'/60'/0'/0/0"</span><div class="anchors"></div></div><div class="body"><p>The default path for Ethereum in an HD Wallet</p>
</div></div><a name="Mnemonic"></a><a name="hdnodes--types--Mnemonic"></a><h3 class="show-anchors"><div>Mnemonic<div class="anchors"><a class="self" href="/v5/api/utils/hdnode/#Mnemonic"></a></div></div></h3>
<div class="property show-anchors"><div class="signature"><span class="path">mnemonic</span><span class="symbol">.</span><span class="method">phrase</span> <span class="arrow">&rArr;</span> <span class="returns">string</span><div class="anchors"></div></div><div class="body"><p>The mnemonic phrase for this mnemonic. It is 12, 15, 18, 21 or 24 words long and separated by the whitespace specified by the <code class="inline">locale</code>.</p>
</div></div><div class="property show-anchors"><div class="signature"><span class="path">mnemonic</span><span class="symbol">.</span><span class="method">path</span> <span class="arrow">&rArr;</span> <span class="returns">string</span><div class="anchors"></div></div><div class="body"><p>The HD path for this mnemonic.</p>
</div></div><div class="property show-anchors"><div class="signature"><span class="path">mnemonic</span><span class="symbol">.</span><span class="method">locale</span> <span class="arrow">&rArr;</span> <span class="returns">string</span><div class="anchors"></div></div><div class="body"><p>The language of the wordlist this mnemonic is using.</p>
</div></div><a name="HDNode"></a><a name="hdnodes--HDNode"></a><h2 class="show-anchors"><div>HDNode<div class="anchors"><a class="self" href="/v5/api/utils/hdnode/#HDNode"></a><a class="source" href="https://github.com/ethers-io/ethers.js/blob/master/packages/hdnode/src.ts/index.ts#L75">source</a></div></div></h2>
<a name="HDNode--creating"></a><a name="hdnodes--HDNode--HDNode--creating"></a><h3 class="show-anchors"><div>Creating Instances<div class="anchors"><a class="self" href="/v5/api/utils/hdnode/#HDNode--creating"></a></div></div></h3>
<a name="HDNode-fromMnemonic"></a><div class="property show-anchors"><div class="signature"><span class="path">ethers</span><span class="symbol">.</span><span class="path">HDNode</span><span class="symbol">.</span><span class="method">fromMnemonic</span><span class="symbol">(</span> <span class="param">phrase</span> <span class="symbol">[</span> <span class="symbol">,</span> <span class="param">password</span> <span class="symbol">[</span> <span class="symbol">,</span> <span class="param">wordlist</span> <span class="symbol">]</span> <span class="symbol">]</span> <span class="symbol">)</span> <span class="arrow">&rArr;</span> <span class="returns"><a href="/v5/api/utils/hdnode/#HDNode">HDNode</a></span><div class="anchors"><a class="self" href="/v5/api/utils/hdnode/#HDNode-fromMnemonic"></a><a class="source" href="https://github.com/ethers-io/ethers.js/blob/master/packages/hdnode/src.ts/index.ts#L262">source</a></div></div><div class="body"><p>Return the <a href="/v5/api/utils/hdnode/#HDNode">HDNode</a> for <i>phrase</i> with the optional <i>password</i> and <i>wordlist</i>.</p>
</div></div><a name="HDNode-fromSeed"></a><div class="property show-anchors"><div class="signature"><span class="path">ethers</span><span class="symbol">.</span><span class="path">HDNode</span><span class="symbol">.</span><span class="method">fromSeed</span><span class="symbol">(</span> <span class="param">aBytesLike</span> <span class="symbol">)</span> <span class="arrow">&rArr;</span> <span class="returns"><a href="/v5/api/utils/hdnode/#HDNode">HDNode</a></span><div class="anchors"><a class="self" href="/v5/api/utils/hdnode/#HDNode-fromSeed"></a><a class="source" href="https://github.com/ethers-io/ethers.js/blob/master/packages/hdnode/src.ts/index.ts#L277">source</a></div></div><div class="body"><p>Return the <a href="/v5/api/utils/hdnode/#HDNode">HDNode</a> for the seed <i>aBytesLike</i>.</p>
</div></div><a name="HDNode-fromExtendedKey"></a><div class="property show-anchors"><div class="signature"><span class="path">ethers</span><span class="symbol">.</span><span class="path">HDNode</span><span class="symbol">.</span><span class="method">fromExtendedKey</span><span class="symbol">(</span> <span class="param">extendedKey</span> <span class="symbol">)</span> <span class="arrow">&rArr;</span> <span class="returns"><a href="/v5/api/utils/hdnode/#HDNode">HDNode</a></span><div class="anchors"><a class="self" href="/v5/api/utils/hdnode/#HDNode-fromExtendedKey"></a><a class="source" href="https://github.com/ethers-io/ethers.js/blob/master/packages/hdnode/src.ts/index.ts#L281">source</a></div></div><div class="body"><p>Return the <a href="/v5/api/utils/hdnode/#HDNode">HDNode</a> for the <i>extendedKey</i>. If <i>extendedKey</i> was neutered, the <b>HDNode</b> will only be able to compute addresses and not private keys.</p>
</div></div><a name="HDNode--properties"></a><a name="hdnodes--HDNode--HDNode--properties"></a><h3 class="show-anchors"><div>Properties<div class="anchors"><a class="self" href="/v5/api/utils/hdnode/#HDNode--properties"></a></div></div></h3>
<div class="property show-anchors"><div class="signature"><span class="path">hdNode</span><span class="symbol">.</span><span class="method">privateKey</span> <span class="arrow">&rArr;</span> <span class="returns">string&lt; <a href="/v5/api/utils/bytes/#DataHexString">DataHexString</a>&lt; 32 &gt; &gt;</span><div class="anchors"></div></div><div class="body"><p>The private key for this HDNode.</p>
</div></div><div class="property show-anchors"><div class="signature"><span class="path">hdNode</span><span class="symbol">.</span><span class="method">publicKey</span> <span class="arrow">&rArr;</span> <span class="returns">string&lt; <a href="/v5/api/utils/bytes/#DataHexString">DataHexString</a>&lt; 33 &gt; &gt;</span><div class="anchors"></div></div><div class="body"><p>The (compresses) public key for this HDNode.</p>
</div></div><div class="property show-anchors"><div class="signature"><span class="path">hdNode</span><span class="symbol">.</span><span class="method">fingerprint</span> <span class="arrow">&rArr;</span> <span class="returns">string&lt; <a href="/v5/api/utils/bytes/#DataHexString">DataHexString</a>&lt; 4 &gt; &gt;</span><div class="anchors"></div></div><div class="body"><p>The fingerprint is meant as an index to quickly match parent and children nodes together, however collisions may occur and software should verify matching nodes.</p>
<p>Most developers will not need to use this.</p>
</div></div><div class="property show-anchors"><div class="signature"><span class="path">hdNode</span><span class="symbol">.</span><span class="method">parentFingerprint</span> <span class="arrow">&rArr;</span> <span class="returns">string&lt; <a href="/v5/api/utils/bytes/#DataHexString">DataHexString</a>&lt; 4 &gt; &gt;</span><div class="anchors"></div></div><div class="body"><p>The fingerprint of the parent node. See <i>fingerprint</i> for more details.</p>
<p>Most developers will not need to use this.</p>
</div></div><div class="property show-anchors"><div class="signature"><span class="path">hdNode</span><span class="symbol">.</span><span class="method">address</span> <span class="arrow">&rArr;</span> <span class="returns">string&lt; <a href="/v5/api/utils/address/#address">Address</a> &gt;</span><div class="anchors"></div></div><div class="body"><p>The address of this HDNode.</p>
</div></div><div class="property show-anchors"><div class="signature"><span class="path">hdNode</span><span class="symbol">.</span><span class="method">mnemonic</span> <span class="arrow">&rArr;</span> <span class="returns"><a href="/v5/api/utils/hdnode/#Mnemonic">Mnemonic</a></span><div class="anchors"></div></div><div class="body"><p>The mnemonic of this HDNode, if known.</p>
</div></div><div class="property show-anchors"><div class="signature"><span class="path">hdNode</span><span class="symbol">.</span><span class="method">path</span> <span class="arrow">&rArr;</span> <span class="returns">string</span><div class="anchors"></div></div><div class="body"><p>The path of this HDNode, if known. If the <i>mnemonic</i> is also known, this will match <code class="inline">mnemonic.path</code>.</p>
</div></div><div class="property show-anchors"><div class="signature"><span class="path">hdNode</span><span class="symbol">.</span><span class="method">chainCode</span> <span class="arrow">&rArr;</span> <span class="returns">string&lt; <a href="/v5/api/utils/bytes/#DataHexString">DataHexString</a>&lt; 32 &gt; &gt;</span><div class="anchors"></div></div><div class="body"><p>The chain code is used as a non-secret private key which is then used with EC-multiply to provide the ability to derive addresses without the private key of child non-hardened nodes.</p>
<p>Most developers will not need to use this.</p>
</div></div><div class="property show-anchors"><div class="signature"><span class="path">hdNode</span><span class="symbol">.</span><span class="method">index</span> <span class="arrow">&rArr;</span> <span class="returns">number</span><div class="anchors"></div></div><div class="body"><p>The index of this HDNode. This will match the last component of the <i>path</i>.</p>
<p>Most developers will not need to use this.</p>
</div></div><div class="property show-anchors"><div class="signature"><span class="path">hdNode</span><span class="symbol">.</span><span class="method">depth</span> <span class="arrow">&rArr;</span> <span class="returns">number</span><div class="anchors"></div></div><div class="body"><p>The depth of this HDNode. This will match the number of components (less one, the <code class="inline">m/</code>) of the <i>path</i>.</p>
<p>Most developers will not need to use this.</p>
</div></div><div class="property show-anchors"><div class="signature"><span class="path">hdNode</span><span class="symbol">.</span><span class="method">extendedKey</span> <span class="arrow">&rArr;</span> <span class="returns">string</span><div class="anchors"></div></div><div class="body"><p>A serialized string representation of this HDNode. Not all properties are included in the serialization, such as the mnemonic and path, so serializing and deserializing (using the <code class="inline">fromExtendedKey</code> class method) will result in reduced information.</p>
</div></div><a name="HDNode--methods"></a><a name="hdnodes--HDNode--HDNode--methods"></a><h3 class="show-anchors"><div>Methods<div class="anchors"><a class="self" href="/v5/api/utils/hdnode/#HDNode--methods"></a></div></div></h3>
<a name="HDNode-neuter"></a><div class="property show-anchors"><div class="signature"><span class="path">hdNode</span><span class="symbol">.</span><span class="method">neuter</span><span class="symbol">(</span> <span class="symbol">)</span> <span class="arrow">&rArr;</span> <span class="returns"><a href="/v5/api/utils/hdnode/#HDNode">HDNode</a></span><div class="anchors"><a class="self" href="/v5/api/utils/hdnode/#HDNode-neuter"></a><a class="source" href="https://github.com/ethers-io/ethers.js/blob/master/packages/hdnode/src.ts/index.ts#L161">source</a></div></div><div class="body"><p>Return a new instance of <i>hdNode</i> with its private key removed but all otehr properties preserved. This ensures that the key can not leak the private key of itself or any derived children, but may still be used to compute the addresses of itself and any non-hardened children.</p>
</div></div><a name="HDNode-derivePath"></a><div class="property show-anchors"><div class="signature"><span class="path">hdNode</span><span class="symbol">.</span><span class="method">derivePath</span><span class="symbol">(</span> <span class="param">path</span> <span class="symbol">)</span> <span class="arrow">&rArr;</span> <span class="returns"><a href="/v5/api/utils/hdnode/#HDNode">HDNode</a></span><div class="anchors"><a class="self" href="/v5/api/utils/hdnode/#HDNode-derivePath"></a><a class="source" href="https://github.com/ethers-io/ethers.js/blob/master/packages/hdnode/src.ts/index.ts#L224">source</a></div></div><div class="body"><p>Return a new <a href="/v5/api/utils/hdnode/#HDNode">HDNode</a> which is the child of <i>hdNode</i> found by deriving <i>path</i>.</p>
</div></div><a name="HDNode--utilities"></a><a name="hdnodes--HDNode--utilities"></a><h2 class="show-anchors"><div>Other Functions<div class="anchors"><a class="self" href="/v5/api/utils/hdnode/#HDNode--utilities"></a></div></div></h2>
<a name="utils-mnemonicToSeed"></a><div class="property show-anchors"><div class="signature"><span class="path">ethers</span><span class="symbol">.</span><span class="path">utils</span><span class="symbol">.</span><span class="method">mnemonicToSeed</span><span class="symbol">(</span> <span class="param">phrase</span> <span class="symbol">[</span> <span class="symbol">,</span> <span class="param">password</span> <span class="symbol">]</span> <span class="symbol">)</span> <span class="arrow">&rArr;</span> <span class="returns">string&lt; <a href="/v5/api/utils/bytes/#DataHexString">DataHexString</a>&lt; 64 &gt; &gt;</span><div class="anchors"><a class="self" href="/v5/api/utils/hdnode/#utils-mnemonicToSeed"></a><a class="source" href="https://github.com/ethers-io/ethers.js/blob/master/packages/hdnode/src.ts/index.ts#L309">source</a></div></div><div class="body"><p>Convert a mnemonic phrase to a seed, according to <a href="https://en.bitcoin.it/wiki/BIP_0039">BIP-39</a>.</p>
</div></div><a name="utils-mnemonicToEntropy"></a><div class="property show-anchors"><div class="signature"><span class="path">ethers</span><span class="symbol">.</span><span class="path">utils</span><span class="symbol">.</span><span class="method">mnemonicToEntropy</span><span class="symbol">(</span> <span class="param">phrase</span> <span class="symbol">[</span> <span class="symbol">,</span> <span class="param">wordlist</span> <span class="symbol">]</span> <span class="symbol">)</span> <span class="arrow">&rArr;</span> <span class="returns">string&lt; <a href="/v5/api/utils/bytes/#DataHexString">DataHexString</a> &gt;</span><div class="anchors"><a class="self" href="/v5/api/utils/hdnode/#utils-mnemonicToEntropy"></a><a class="source" href="https://github.com/ethers-io/ethers.js/blob/master/packages/hdnode/src.ts/index.ts#L317">source</a></div></div><div class="body"><p>Convert a mnemonic phrase to its entropy, according to <a href="https://en.bitcoin.it/wiki/BIP_0039">BIP-39</a>.</p>
</div></div><a name="utils-isValidMnemonic"></a><div class="property show-anchors"><div class="signature"><span class="path">ethers</span><span class="symbol">.</span><span class="path">utils</span><span class="symbol">.</span><span class="method">isValidMnemonic</span><span class="symbol">(</span> <span class="param">phrase</span> <span class="symbol">[</span> <span class="symbol">,</span> <span class="param">wordlist</span> <span class="symbol">]</span> <span class="symbol">)</span> <span class="arrow">&rArr;</span> <span class="returns">boolean</span><div class="anchors"><a class="self" href="/v5/api/utils/hdnode/#utils-isValidMnemonic"></a><a class="source" href="https://github.com/ethers-io/ethers.js/blob/master/packages/hdnode/src.ts/index.ts#L398">source</a></div></div><div class="body"><p>Returns true if <i>phrase</i> is a valid mnemonic phrase, by testing the checksum.</p>
</div></div>
<div class="footer">
<div class="nav previous"><a href="/v5/api/utils/hashing/"><span class="arrow">&larr;</span>Hashing Algorithms</a></div>
<div class="nav next"><a href="/v5/api/utils/logger/">Logging<span class="arrow">&rarr;</span></a></div>
</div>
<div class="copyright">The content of this site is licensed under the <a href="https://choosealicense.com/licenses/cc-by-4.0/">Creative Commons License</a>. Generated on July 3, 2020, 1:44am.</div>
</div>
<script src="/v5/static/script.js" type="text/javascript"></script>
</body>
</html>