Deploy website

Deploy website version based on 905491fe0e
This commit is contained in:
Docusaurus bot 2020-12-20 13:41:17 +00:00
parent e76e5f3283
commit 0650bd1094
14 changed files with 90 additions and 90 deletions

View file

@ -80,7 +80,7 @@ reason to keep using legacy transaction formats.</p>
<span class="hljs-keyword">val</span> privkey = <span class="hljs-type">ECPrivateKey</span>() <span class="hljs-keyword">val</span> privkey = <span class="hljs-type">ECPrivateKey</span>()
<span class="hljs-comment">// privkey: ECPrivateKey = Masked(ECPrivateKeyImpl)</span> <span class="hljs-comment">// privkey: ECPrivateKey = Masked(ECPrivateKeyImpl)</span>
<span class="hljs-keyword">val</span> pubkey = privkey.publicKey <span class="hljs-keyword">val</span> pubkey = privkey.publicKey
<span class="hljs-comment">// pubkey: org.bitcoins.crypto.ECPublicKey = ECPublicKey(030e18f4d0d6a83bb9d639e8d16c2700e704f5c5cea207fb86e6df73bace6d6add)</span> <span class="hljs-comment">// pubkey: org.bitcoins.crypto.ECPublicKey = ECPublicKey(030ef7245eecd720c90ff155fb618b433f429522558bf1b962c90dddaea20cbb2b)</span>
<span class="hljs-keyword">val</span> segwitAddress = { <span class="hljs-keyword">val</span> segwitAddress = {
<span class="hljs-comment">// see https://bitcoin.org/en/glossary/pubkey-script</span> <span class="hljs-comment">// see https://bitcoin.org/en/glossary/pubkey-script</span>
@ -89,10 +89,10 @@ reason to keep using legacy transaction formats.</p>
<span class="hljs-keyword">val</span> scriptPubKey = <span class="hljs-type">P2WPKHWitnessSPKV0</span>(pubkey) <span class="hljs-keyword">val</span> scriptPubKey = <span class="hljs-type">P2WPKHWitnessSPKV0</span>(pubkey)
<span class="hljs-type">Bech32Address</span>(scriptPubKey, <span class="hljs-type">TestNet3</span>) <span class="hljs-type">Bech32Address</span>(scriptPubKey, <span class="hljs-type">TestNet3</span>)
} }
<span class="hljs-comment">// segwitAddress: Bech32Address = tb1qsq68crffzl69nc273pmavre2w492nd63zhahrv</span> <span class="hljs-comment">// segwitAddress: Bech32Address = tb1qvjffct45f49qpqy6cfk6s5srzvageph5g98p7c</span>
println(segwitAddress.toString) println(segwitAddress.toString)
<span class="hljs-comment">// tb1qsq68crffzl69nc273pmavre2w492nd63zhahrv</span> <span class="hljs-comment">// tb1qvjffct45f49qpqy6cfk6s5srzvageph5g98p7c</span>
</code></pre> </code></pre>
<h2><a class="anchor" aria-hidden="true" id="generating-legacy-base58-addresses"></a><a href="#generating-legacy-base58-addresses" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Generating legacy (base58) addresses</h2> <h2><a class="anchor" aria-hidden="true" id="generating-legacy-base58-addresses"></a><a href="#generating-legacy-base58-addresses" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Generating legacy (base58) addresses</h2>
<p>If you need to generate legacy addresses for backwards <p>If you need to generate legacy addresses for backwards
@ -101,10 +101,10 @@ Take a look:</p>
<pre><code class="hljs css language-scala"><span class="hljs-comment">// we&#x27;re reusing the same private/public key pair</span> <pre><code class="hljs css language-scala"><span class="hljs-comment">// we&#x27;re reusing the same private/public key pair</span>
<span class="hljs-comment">// from before. don&#x27;t do this in an actual application!</span> <span class="hljs-comment">// from before. don&#x27;t do this in an actual application!</span>
<span class="hljs-keyword">val</span> legacyAddress = <span class="hljs-type">P2PKHAddress</span>(pubkey, <span class="hljs-type">TestNet3</span>) <span class="hljs-keyword">val</span> legacyAddress = <span class="hljs-type">P2PKHAddress</span>(pubkey, <span class="hljs-type">TestNet3</span>)
<span class="hljs-comment">// legacyAddress: P2PKHAddress = msCqfJPP5MeBMuZYoicp3eJFQYx7kmPNZP</span> <span class="hljs-comment">// legacyAddress: P2PKHAddress = mpgjVtFqRmzkkU3U3AGDpR6TJ9RYpAzyHW</span>
println(legacyAddress.toString) println(legacyAddress.toString)
<span class="hljs-comment">// msCqfJPP5MeBMuZYoicp3eJFQYx7kmPNZP</span> <span class="hljs-comment">// mpgjVtFqRmzkkU3U3AGDpR6TJ9RYpAzyHW</span>
</code></pre> </code></pre>
</span></div></article></div><div class="docs-prevnext"><a class="docs-prev button" href="/docs/next/core/core-intro"><span class="arrow-prev"></span><span>Core Module</span></a><a class="docs-next button" href="/docs/next/core/hd-keys"><span>HD Key Generation</span><span class="arrow-next"></span></a></div></div></div><nav class="onPageNav"><ul class="toc-headings"><li><a href="#generating-segwit-bech32-addresses">Generating SegWit (bech32) addresses</a></li><li><a href="#generating-legacy-base58-addresses">Generating legacy (base58) addresses</a></li></ul></nav></div><footer class="nav-footer" id="footer"><section class="sitemap"><a href="/" class="nav-home"><img src="/img/favicon.ico" alt="bitcoin-s" width="66" height="58"/></a><div><h5>Docs</h5><a href="/docs/en/getting-started">Getting Started</a><a href="/docs/en/core/core-intro">Guides</a><a href="/api/org/bitcoins">API Reference</a></div><div><h5>Community</h5><a href="/en/users.html">User Showcase</a><a href="https://join.slack.com/t/suredbits/shared_invite/zt-eavycu0x-WQL7XOakzQo8tAy7jHHZUw" target="_blank" rel="noreferrer noopener">Slack</a><a href="https://gitter.im/bitcoin-s-core/">Gitter chat</a></div><div><h5>More</h5><a href="https://github.com/bitcoin-s/bitcoin-s">GitHub</a><a class="github-button" href="https://github.com/bitcoin-s/bitcoin-s" data-icon="octicon-star" data-count-href="/bitcoin-s/bitcoin-s-core/stargazers" data-show-count="true" data-count-aria-label="# stargazers on GitHub" aria-label="Star this project on GitHub">Star</a></div></section><section class="copyright">Copyright © 2020 Suredbits &amp; the bitcoin-s developers</section></footer></div><script type="text/javascript" src="https://cdn.jsdelivr.net/docsearch.js/1/docsearch.min.js"></script><script> </span></div></article></div><div class="docs-prevnext"><a class="docs-prev button" href="/docs/next/core/core-intro"><span class="arrow-prev"></span><span>Core Module</span></a><a class="docs-next button" href="/docs/next/core/hd-keys"><span>HD Key Generation</span><span class="arrow-next"></span></a></div></div></div><nav class="onPageNav"><ul class="toc-headings"><li><a href="#generating-segwit-bech32-addresses">Generating SegWit (bech32) addresses</a></li><li><a href="#generating-legacy-base58-addresses">Generating legacy (base58) addresses</a></li></ul></nav></div><footer class="nav-footer" id="footer"><section class="sitemap"><a href="/" class="nav-home"><img src="/img/favicon.ico" alt="bitcoin-s" width="66" height="58"/></a><div><h5>Docs</h5><a href="/docs/en/getting-started">Getting Started</a><a href="/docs/en/core/core-intro">Guides</a><a href="/api/org/bitcoins">API Reference</a></div><div><h5>Community</h5><a href="/en/users.html">User Showcase</a><a href="https://join.slack.com/t/suredbits/shared_invite/zt-eavycu0x-WQL7XOakzQo8tAy7jHHZUw" target="_blank" rel="noreferrer noopener">Slack</a><a href="https://gitter.im/bitcoin-s-core/">Gitter chat</a></div><div><h5>More</h5><a href="https://github.com/bitcoin-s/bitcoin-s">GitHub</a><a class="github-button" href="https://github.com/bitcoin-s/bitcoin-s" data-icon="octicon-star" data-count-href="/bitcoin-s/bitcoin-s-core/stargazers" data-show-count="true" data-count-aria-label="# stargazers on GitHub" aria-label="Star this project on GitHub">Star</a></div></section><section class="copyright">Copyright © 2020 Suredbits &amp; the bitcoin-s developers</section></footer></div><script type="text/javascript" src="https://cdn.jsdelivr.net/docsearch.js/1/docsearch.min.js"></script><script>
document.addEventListener('keyup', function(e) { document.addEventListener('keyup', function(e) {

View file

@ -80,7 +80,7 @@ reason to keep using legacy transaction formats.</p>
<span class="hljs-keyword">val</span> privkey = <span class="hljs-type">ECPrivateKey</span>() <span class="hljs-keyword">val</span> privkey = <span class="hljs-type">ECPrivateKey</span>()
<span class="hljs-comment">// privkey: ECPrivateKey = Masked(ECPrivateKeyImpl)</span> <span class="hljs-comment">// privkey: ECPrivateKey = Masked(ECPrivateKeyImpl)</span>
<span class="hljs-keyword">val</span> pubkey = privkey.publicKey <span class="hljs-keyword">val</span> pubkey = privkey.publicKey
<span class="hljs-comment">// pubkey: org.bitcoins.crypto.ECPublicKey = ECPublicKey(030e18f4d0d6a83bb9d639e8d16c2700e704f5c5cea207fb86e6df73bace6d6add)</span> <span class="hljs-comment">// pubkey: org.bitcoins.crypto.ECPublicKey = ECPublicKey(030ef7245eecd720c90ff155fb618b433f429522558bf1b962c90dddaea20cbb2b)</span>
<span class="hljs-keyword">val</span> segwitAddress = { <span class="hljs-keyword">val</span> segwitAddress = {
<span class="hljs-comment">// see https://bitcoin.org/en/glossary/pubkey-script</span> <span class="hljs-comment">// see https://bitcoin.org/en/glossary/pubkey-script</span>
@ -89,10 +89,10 @@ reason to keep using legacy transaction formats.</p>
<span class="hljs-keyword">val</span> scriptPubKey = <span class="hljs-type">P2WPKHWitnessSPKV0</span>(pubkey) <span class="hljs-keyword">val</span> scriptPubKey = <span class="hljs-type">P2WPKHWitnessSPKV0</span>(pubkey)
<span class="hljs-type">Bech32Address</span>(scriptPubKey, <span class="hljs-type">TestNet3</span>) <span class="hljs-type">Bech32Address</span>(scriptPubKey, <span class="hljs-type">TestNet3</span>)
} }
<span class="hljs-comment">// segwitAddress: Bech32Address = tb1qsq68crffzl69nc273pmavre2w492nd63zhahrv</span> <span class="hljs-comment">// segwitAddress: Bech32Address = tb1qvjffct45f49qpqy6cfk6s5srzvageph5g98p7c</span>
println(segwitAddress.toString) println(segwitAddress.toString)
<span class="hljs-comment">// tb1qsq68crffzl69nc273pmavre2w492nd63zhahrv</span> <span class="hljs-comment">// tb1qvjffct45f49qpqy6cfk6s5srzvageph5g98p7c</span>
</code></pre> </code></pre>
<h2><a class="anchor" aria-hidden="true" id="generating-legacy-base58-addresses"></a><a href="#generating-legacy-base58-addresses" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Generating legacy (base58) addresses</h2> <h2><a class="anchor" aria-hidden="true" id="generating-legacy-base58-addresses"></a><a href="#generating-legacy-base58-addresses" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Generating legacy (base58) addresses</h2>
<p>If you need to generate legacy addresses for backwards <p>If you need to generate legacy addresses for backwards
@ -101,10 +101,10 @@ Take a look:</p>
<pre><code class="hljs css language-scala"><span class="hljs-comment">// we&#x27;re reusing the same private/public key pair</span> <pre><code class="hljs css language-scala"><span class="hljs-comment">// we&#x27;re reusing the same private/public key pair</span>
<span class="hljs-comment">// from before. don&#x27;t do this in an actual application!</span> <span class="hljs-comment">// from before. don&#x27;t do this in an actual application!</span>
<span class="hljs-keyword">val</span> legacyAddress = <span class="hljs-type">P2PKHAddress</span>(pubkey, <span class="hljs-type">TestNet3</span>) <span class="hljs-keyword">val</span> legacyAddress = <span class="hljs-type">P2PKHAddress</span>(pubkey, <span class="hljs-type">TestNet3</span>)
<span class="hljs-comment">// legacyAddress: P2PKHAddress = msCqfJPP5MeBMuZYoicp3eJFQYx7kmPNZP</span> <span class="hljs-comment">// legacyAddress: P2PKHAddress = mpgjVtFqRmzkkU3U3AGDpR6TJ9RYpAzyHW</span>
println(legacyAddress.toString) println(legacyAddress.toString)
<span class="hljs-comment">// msCqfJPP5MeBMuZYoicp3eJFQYx7kmPNZP</span> <span class="hljs-comment">// mpgjVtFqRmzkkU3U3AGDpR6TJ9RYpAzyHW</span>
</code></pre> </code></pre>
</span></div></article></div><div class="docs-prevnext"><a class="docs-prev button" href="/docs/next/core/core-intro"><span class="arrow-prev"></span><span>Core Module</span></a><a class="docs-next button" href="/docs/next/core/hd-keys"><span>HD Key Generation</span><span class="arrow-next"></span></a></div></div></div><nav class="onPageNav"><ul class="toc-headings"><li><a href="#generating-segwit-bech32-addresses">Generating SegWit (bech32) addresses</a></li><li><a href="#generating-legacy-base58-addresses">Generating legacy (base58) addresses</a></li></ul></nav></div><footer class="nav-footer" id="footer"><section class="sitemap"><a href="/" class="nav-home"><img src="/img/favicon.ico" alt="bitcoin-s" width="66" height="58"/></a><div><h5>Docs</h5><a href="/docs/en/getting-started">Getting Started</a><a href="/docs/en/core/core-intro">Guides</a><a href="/api/org/bitcoins">API Reference</a></div><div><h5>Community</h5><a href="/en/users.html">User Showcase</a><a href="https://join.slack.com/t/suredbits/shared_invite/zt-eavycu0x-WQL7XOakzQo8tAy7jHHZUw" target="_blank" rel="noreferrer noopener">Slack</a><a href="https://gitter.im/bitcoin-s-core/">Gitter chat</a></div><div><h5>More</h5><a href="https://github.com/bitcoin-s/bitcoin-s">GitHub</a><a class="github-button" href="https://github.com/bitcoin-s/bitcoin-s" data-icon="octicon-star" data-count-href="/bitcoin-s/bitcoin-s-core/stargazers" data-show-count="true" data-count-aria-label="# stargazers on GitHub" aria-label="Star this project on GitHub">Star</a></div></section><section class="copyright">Copyright © 2020 Suredbits &amp; the bitcoin-s developers</section></footer></div><script type="text/javascript" src="https://cdn.jsdelivr.net/docsearch.js/1/docsearch.min.js"></script><script> </span></div></article></div><div class="docs-prevnext"><a class="docs-prev button" href="/docs/next/core/core-intro"><span class="arrow-prev"></span><span>Core Module</span></a><a class="docs-next button" href="/docs/next/core/hd-keys"><span>HD Key Generation</span><span class="arrow-next"></span></a></div></div></div><nav class="onPageNav"><ul class="toc-headings"><li><a href="#generating-segwit-bech32-addresses">Generating SegWit (bech32) addresses</a></li><li><a href="#generating-legacy-base58-addresses">Generating legacy (base58) addresses</a></li></ul></nav></div><footer class="nav-footer" id="footer"><section class="sitemap"><a href="/" class="nav-home"><img src="/img/favicon.ico" alt="bitcoin-s" width="66" height="58"/></a><div><h5>Docs</h5><a href="/docs/en/getting-started">Getting Started</a><a href="/docs/en/core/core-intro">Guides</a><a href="/api/org/bitcoins">API Reference</a></div><div><h5>Community</h5><a href="/en/users.html">User Showcase</a><a href="https://join.slack.com/t/suredbits/shared_invite/zt-eavycu0x-WQL7XOakzQo8tAy7jHHZUw" target="_blank" rel="noreferrer noopener">Slack</a><a href="https://gitter.im/bitcoin-s-core/">Gitter chat</a></div><div><h5>More</h5><a href="https://github.com/bitcoin-s/bitcoin-s">GitHub</a><a class="github-button" href="https://github.com/bitcoin-s/bitcoin-s" data-icon="octicon-star" data-count-href="/bitcoin-s/bitcoin-s-core/stargazers" data-show-count="true" data-count-aria-label="# stargazers on GitHub" aria-label="Star this project on GitHub">Star</a></div></section><section class="copyright">Copyright © 2020 Suredbits &amp; the bitcoin-s developers</section></footer></div><script type="text/javascript" src="https://cdn.jsdelivr.net/docsearch.js/1/docsearch.min.js"></script><script>
document.addEventListener('keyup', function(e) { document.addEventListener('keyup', function(e) {

View file

@ -86,13 +86,13 @@ use that to generate further private and public keys:</p>
<span class="hljs-comment">// how long our phrase ends up being</span> <span class="hljs-comment">// how long our phrase ends up being</span>
<span class="hljs-comment">// 256 bits of entropy results in 24 words</span> <span class="hljs-comment">// 256 bits of entropy results in 24 words</span>
<span class="hljs-keyword">val</span> entropy: <span class="hljs-type">BitVector</span> = <span class="hljs-type">MnemonicCode</span>.getEntropy256Bits <span class="hljs-keyword">val</span> entropy: <span class="hljs-type">BitVector</span> = <span class="hljs-type">MnemonicCode</span>.getEntropy256Bits
<span class="hljs-comment">// entropy: BitVector = BitVector(256 bits, 0x1014f475d4221d6c260f0b2a744f0f59a9466aaa66883debf16bcde4a33f1d82)</span> <span class="hljs-comment">// entropy: BitVector = BitVector(256 bits, 0x415016390b2b0ccf6a51ef8d5fe41620d1b0a7c1bca45d8069b28f59dea0353d)</span>
<span class="hljs-keyword">val</span> mnemonicCode = <span class="hljs-type">MnemonicCode</span>.fromEntropy(entropy) <span class="hljs-keyword">val</span> mnemonicCode = <span class="hljs-type">MnemonicCode</span>.fromEntropy(entropy)
<span class="hljs-comment">// mnemonicCode: MnemonicCode = Masked(MnemonicCodeImpl)</span> <span class="hljs-comment">// mnemonicCode: MnemonicCode = Masked(MnemonicCodeImpl)</span>
mnemonicCode.words <span class="hljs-comment">// the phrase the user should write down</span> mnemonicCode.words <span class="hljs-comment">// the phrase the user should write down</span>
<span class="hljs-comment">// res0: Vector[String] = Vector(avoid, police, buddy, portion, canyon, render, oblige, thumb, clerk, pen, sense, rebuild, nerve, crystal, praise, speed, digital, garbage, foot, orange, enforce, panel, invite, famous) // the phrase the user should write down</span> <span class="hljs-comment">// res0: Vector[String] = Vector(donor, level, mixture, bind, radio, guilt, power, digital, minute, you, airport, double, brand, fault, alone, nest, frown, addict, hole, burger, over, exotic, stay, provide) // the phrase the user should write down</span>
<span class="hljs-comment">// the password argument is an optional, extra security</span> <span class="hljs-comment">// the password argument is an optional, extra security</span>
<span class="hljs-comment">// measure. all MnemonicCode instances will give you a</span> <span class="hljs-comment">// measure. all MnemonicCode instances will give you a</span>
@ -108,7 +108,7 @@ mnemonicCode.words <span class="hljs-comment">// the phrase the user should writ
bip39Seed) bip39Seed)
<span class="hljs-comment">// xpriv: ExtPrivateKey = Masked(ExtPrivateKeyImpl)</span> <span class="hljs-comment">// xpriv: ExtPrivateKey = Masked(ExtPrivateKeyImpl)</span>
<span class="hljs-keyword">val</span> xpub = xpriv.extPublicKey <span class="hljs-keyword">val</span> xpub = xpriv.extPublicKey
<span class="hljs-comment">// xpub: ExtPublicKey = zpub6jftahH18ngZwaeayY15dwzjsgPaBfJrJAYDQGzr2zjQhdmFpm7GSUTHSKEzz4yBPg45Y13zRreGkQVhZdsj2FeQEJjKQzop1wxRwCnNmaY</span> <span class="hljs-comment">// xpub: ExtPublicKey = zpub6jftahH18ngZy9kJa6kwttXADawKMohd1m5gJWzNnFLuMa5b8L5qcTvjpTm6noyCbZAfayDaKtUHtvTNq7DnYX3vSk8RsAgwgC8yqaTG6Tt</span>
<span class="hljs-comment">// you can now use the generated xpriv to derive further</span> <span class="hljs-comment">// you can now use the generated xpriv to derive further</span>
<span class="hljs-comment">// private or public keys</span> <span class="hljs-comment">// private or public keys</span>
@ -154,7 +154,7 @@ spend or steal any of your money.</p>
<span class="hljs-comment">// can generate addresses with it!</span> <span class="hljs-comment">// can generate addresses with it!</span>
accountXpriv.extPublicKey accountXpriv.extPublicKey
} }
<span class="hljs-comment">// accountXpub: ExtPublicKey = zpub6qguXgjhAnKf3BbkER2bFLBKAR5XNwz5ECMLKxqmbTongL6CqTpnEgpjaKDhoSrugybhgEdTn6C5ybjTNK2VfoaG5FMZ3PEid5FzHensG1V</span> <span class="hljs-comment">// accountXpub: ExtPublicKey = zpub6rU2UXrKCuxi1rSucgY3o5CYrGXY3ECfN9jFCnkXk1uSKPM7Au4nQ6mANqPSvEFcsMxZghEUwkKsMjQMhzUrtG2iBJgTrUrh9zmy3xs3JPx</span>
<span class="hljs-comment">// address no. 0 ---------------┐</span> <span class="hljs-comment">// address no. 0 ---------------┐</span>
<span class="hljs-comment">// external address ----------┐ |</span> <span class="hljs-comment">// external address ----------┐ |</span>
@ -177,12 +177,12 @@ spend or steal any of your money.</p>
<span class="hljs-keyword">val</span> scriptPubKey = <span class="hljs-type">P2WPKHWitnessSPKV0</span>(pubkey) <span class="hljs-keyword">val</span> scriptPubKey = <span class="hljs-type">P2WPKHWitnessSPKV0</span>(pubkey)
<span class="hljs-type">Bech32Address</span>(scriptPubKey, <span class="hljs-type">TestNet3</span>) <span class="hljs-type">Bech32Address</span>(scriptPubKey, <span class="hljs-type">TestNet3</span>)
} }
<span class="hljs-comment">// firstAccountAddress: Bech32Address = tb1qjqu8vp25wwwv59cc8ze729xad9rfjtdyzpv58t</span> <span class="hljs-comment">// firstAccountAddress: Bech32Address = tb1qm55tx0t8xkfpawd2mrxfmy4qpu3pgrvtgry7u0</span>
<span class="hljs-comment">// tada! We just generated an address you can send money to,</span> <span class="hljs-comment">// tada! We just generated an address you can send money to,</span>
<span class="hljs-comment">// without having access to the private key!</span> <span class="hljs-comment">// without having access to the private key!</span>
firstAccountAddress.value firstAccountAddress.value
<span class="hljs-comment">// res2: String = tb1qjqu8vp25wwwv59cc8ze729xad9rfjtdyzpv58t</span> <span class="hljs-comment">// res2: String = tb1qm55tx0t8xkfpawd2mrxfmy4qpu3pgrvtgry7u0</span>
<span class="hljs-comment">// you can now continue deriving addresses from the same public</span> <span class="hljs-comment">// you can now continue deriving addresses from the same public</span>
<span class="hljs-comment">// key, by imitating what we did above. To get the next</span> <span class="hljs-comment">// key, by imitating what we did above. To get the next</span>

View file

@ -86,13 +86,13 @@ use that to generate further private and public keys:</p>
<span class="hljs-comment">// how long our phrase ends up being</span> <span class="hljs-comment">// how long our phrase ends up being</span>
<span class="hljs-comment">// 256 bits of entropy results in 24 words</span> <span class="hljs-comment">// 256 bits of entropy results in 24 words</span>
<span class="hljs-keyword">val</span> entropy: <span class="hljs-type">BitVector</span> = <span class="hljs-type">MnemonicCode</span>.getEntropy256Bits <span class="hljs-keyword">val</span> entropy: <span class="hljs-type">BitVector</span> = <span class="hljs-type">MnemonicCode</span>.getEntropy256Bits
<span class="hljs-comment">// entropy: BitVector = BitVector(256 bits, 0x1014f475d4221d6c260f0b2a744f0f59a9466aaa66883debf16bcde4a33f1d82)</span> <span class="hljs-comment">// entropy: BitVector = BitVector(256 bits, 0x415016390b2b0ccf6a51ef8d5fe41620d1b0a7c1bca45d8069b28f59dea0353d)</span>
<span class="hljs-keyword">val</span> mnemonicCode = <span class="hljs-type">MnemonicCode</span>.fromEntropy(entropy) <span class="hljs-keyword">val</span> mnemonicCode = <span class="hljs-type">MnemonicCode</span>.fromEntropy(entropy)
<span class="hljs-comment">// mnemonicCode: MnemonicCode = Masked(MnemonicCodeImpl)</span> <span class="hljs-comment">// mnemonicCode: MnemonicCode = Masked(MnemonicCodeImpl)</span>
mnemonicCode.words <span class="hljs-comment">// the phrase the user should write down</span> mnemonicCode.words <span class="hljs-comment">// the phrase the user should write down</span>
<span class="hljs-comment">// res0: Vector[String] = Vector(avoid, police, buddy, portion, canyon, render, oblige, thumb, clerk, pen, sense, rebuild, nerve, crystal, praise, speed, digital, garbage, foot, orange, enforce, panel, invite, famous) // the phrase the user should write down</span> <span class="hljs-comment">// res0: Vector[String] = Vector(donor, level, mixture, bind, radio, guilt, power, digital, minute, you, airport, double, brand, fault, alone, nest, frown, addict, hole, burger, over, exotic, stay, provide) // the phrase the user should write down</span>
<span class="hljs-comment">// the password argument is an optional, extra security</span> <span class="hljs-comment">// the password argument is an optional, extra security</span>
<span class="hljs-comment">// measure. all MnemonicCode instances will give you a</span> <span class="hljs-comment">// measure. all MnemonicCode instances will give you a</span>
@ -108,7 +108,7 @@ mnemonicCode.words <span class="hljs-comment">// the phrase the user should writ
bip39Seed) bip39Seed)
<span class="hljs-comment">// xpriv: ExtPrivateKey = Masked(ExtPrivateKeyImpl)</span> <span class="hljs-comment">// xpriv: ExtPrivateKey = Masked(ExtPrivateKeyImpl)</span>
<span class="hljs-keyword">val</span> xpub = xpriv.extPublicKey <span class="hljs-keyword">val</span> xpub = xpriv.extPublicKey
<span class="hljs-comment">// xpub: ExtPublicKey = zpub6jftahH18ngZwaeayY15dwzjsgPaBfJrJAYDQGzr2zjQhdmFpm7GSUTHSKEzz4yBPg45Y13zRreGkQVhZdsj2FeQEJjKQzop1wxRwCnNmaY</span> <span class="hljs-comment">// xpub: ExtPublicKey = zpub6jftahH18ngZy9kJa6kwttXADawKMohd1m5gJWzNnFLuMa5b8L5qcTvjpTm6noyCbZAfayDaKtUHtvTNq7DnYX3vSk8RsAgwgC8yqaTG6Tt</span>
<span class="hljs-comment">// you can now use the generated xpriv to derive further</span> <span class="hljs-comment">// you can now use the generated xpriv to derive further</span>
<span class="hljs-comment">// private or public keys</span> <span class="hljs-comment">// private or public keys</span>
@ -154,7 +154,7 @@ spend or steal any of your money.</p>
<span class="hljs-comment">// can generate addresses with it!</span> <span class="hljs-comment">// can generate addresses with it!</span>
accountXpriv.extPublicKey accountXpriv.extPublicKey
} }
<span class="hljs-comment">// accountXpub: ExtPublicKey = zpub6qguXgjhAnKf3BbkER2bFLBKAR5XNwz5ECMLKxqmbTongL6CqTpnEgpjaKDhoSrugybhgEdTn6C5ybjTNK2VfoaG5FMZ3PEid5FzHensG1V</span> <span class="hljs-comment">// accountXpub: ExtPublicKey = zpub6rU2UXrKCuxi1rSucgY3o5CYrGXY3ECfN9jFCnkXk1uSKPM7Au4nQ6mANqPSvEFcsMxZghEUwkKsMjQMhzUrtG2iBJgTrUrh9zmy3xs3JPx</span>
<span class="hljs-comment">// address no. 0 ---------------┐</span> <span class="hljs-comment">// address no. 0 ---------------┐</span>
<span class="hljs-comment">// external address ----------┐ |</span> <span class="hljs-comment">// external address ----------┐ |</span>
@ -177,12 +177,12 @@ spend or steal any of your money.</p>
<span class="hljs-keyword">val</span> scriptPubKey = <span class="hljs-type">P2WPKHWitnessSPKV0</span>(pubkey) <span class="hljs-keyword">val</span> scriptPubKey = <span class="hljs-type">P2WPKHWitnessSPKV0</span>(pubkey)
<span class="hljs-type">Bech32Address</span>(scriptPubKey, <span class="hljs-type">TestNet3</span>) <span class="hljs-type">Bech32Address</span>(scriptPubKey, <span class="hljs-type">TestNet3</span>)
} }
<span class="hljs-comment">// firstAccountAddress: Bech32Address = tb1qjqu8vp25wwwv59cc8ze729xad9rfjtdyzpv58t</span> <span class="hljs-comment">// firstAccountAddress: Bech32Address = tb1qm55tx0t8xkfpawd2mrxfmy4qpu3pgrvtgry7u0</span>
<span class="hljs-comment">// tada! We just generated an address you can send money to,</span> <span class="hljs-comment">// tada! We just generated an address you can send money to,</span>
<span class="hljs-comment">// without having access to the private key!</span> <span class="hljs-comment">// without having access to the private key!</span>
firstAccountAddress.value firstAccountAddress.value
<span class="hljs-comment">// res2: String = tb1qjqu8vp25wwwv59cc8ze729xad9rfjtdyzpv58t</span> <span class="hljs-comment">// res2: String = tb1qm55tx0t8xkfpawd2mrxfmy4qpu3pgrvtgry7u0</span>
<span class="hljs-comment">// you can now continue deriving addresses from the same public</span> <span class="hljs-comment">// you can now continue deriving addresses from the same public</span>
<span class="hljs-comment">// key, by imitating what we did above. To get the next</span> <span class="hljs-comment">// key, by imitating what we did above. To get the next</span>

View file

@ -64,7 +64,7 @@
}); });
</script></nav></div><div class="container mainContainer docsContainer"><div class="wrapper"><div class="post"><header class="postHeader"><a class="edit-page-link button" href="https://github.com/bitcoin-s/bitcoin-s/blob/master/docs/core/txbuilder.md" target="_blank" rel="noreferrer noopener">Edit</a><h1 id="__docusaurus" class="postHeaderTitle">TxBuilder Example</h1></header><article><div><span><p>Bitcoin-S features a transaction building API that allows you to construct and sign Bitcoin transactions. Here's an example of how to use it</p> </script></nav></div><div class="container mainContainer docsContainer"><div class="wrapper"><div class="post"><header class="postHeader"><a class="edit-page-link button" href="https://github.com/bitcoin-s/bitcoin-s/blob/master/docs/core/txbuilder.md" target="_blank" rel="noreferrer noopener">Edit</a><h1 id="__docusaurus" class="postHeaderTitle">TxBuilder Example</h1></header><article><div><span><p>Bitcoin-S features a transaction building API that allows you to construct and sign Bitcoin transactions. Here's an example of how to use it</p>
<pre><code class="hljs css language-scala"><span class="hljs-keyword">implicit</span> <span class="hljs-keyword">val</span> ec: <span class="hljs-type">ExecutionContext</span> = <span class="hljs-type">ExecutionContext</span>.<span class="hljs-type">Implicits</span>.global <pre><code class="hljs css language-scala"><span class="hljs-keyword">implicit</span> <span class="hljs-keyword">val</span> ec: <span class="hljs-type">ExecutionContext</span> = <span class="hljs-type">ExecutionContext</span>.<span class="hljs-type">Implicits</span>.global
<span class="hljs-comment">// ec: ExecutionContext = scala.concurrent.impl.ExecutionContextImpl$$anon$3@35378fe1[Running, parallelism = 2, size = 2, active = 0, running = 0, steals = 37, tasks = 0, submissions = 0]</span> <span class="hljs-comment">// ec: ExecutionContext = scala.concurrent.impl.ExecutionContextImpl$$anon$3@399c0f8b[Running, parallelism = 2, size = 2, active = 0, running = 0, steals = 33, tasks = 0, submissions = 0]</span>
<span class="hljs-comment">// Initialize a transaction builder</span> <span class="hljs-comment">// Initialize a transaction builder</span>
<span class="hljs-keyword">val</span> builder = <span class="hljs-type">RawTxBuilder</span>() <span class="hljs-keyword">val</span> builder = <span class="hljs-type">RawTxBuilder</span>()
@ -74,19 +74,19 @@
<span class="hljs-keyword">val</span> privKey = <span class="hljs-type">ECPrivateKey</span>.freshPrivateKey <span class="hljs-keyword">val</span> privKey = <span class="hljs-type">ECPrivateKey</span>.freshPrivateKey
<span class="hljs-comment">// privKey: ECPrivateKey = Masked(ECPrivateKeyImpl)</span> <span class="hljs-comment">// privKey: ECPrivateKey = Masked(ECPrivateKeyImpl)</span>
<span class="hljs-keyword">val</span> pubKey = privKey.publicKey <span class="hljs-keyword">val</span> pubKey = privKey.publicKey
<span class="hljs-comment">// pubKey: ECPublicKey = ECPublicKey(02530ee3fd565e59f937e56bda48e9225ea8b09986e6987e6c89afa4930dae7326)</span> <span class="hljs-comment">// pubKey: ECPublicKey = ECPublicKey(022a992a3bf2b093045485ea8217c1912a636c4cfd50f4361b9b51e3c5a3799ffd)</span>
<span class="hljs-comment">// this is the script that the TxBuilder is going to create a</span> <span class="hljs-comment">// this is the script that the TxBuilder is going to create a</span>
<span class="hljs-comment">// script signature that validly spends this scriptPubKey</span> <span class="hljs-comment">// script signature that validly spends this scriptPubKey</span>
<span class="hljs-keyword">val</span> creditingSpk = <span class="hljs-type">P2PKHScriptPubKey</span>(pubKey = privKey.publicKey) <span class="hljs-keyword">val</span> creditingSpk = <span class="hljs-type">P2PKHScriptPubKey</span>(pubKey = privKey.publicKey)
<span class="hljs-comment">// creditingSpk: P2PKHScriptPubKey = pkh(76ee004f76fdda7861782f616b6b36d0c3425c71)</span> <span class="hljs-comment">// creditingSpk: P2PKHScriptPubKey = pkh(ec2c33f1b36ef6c7d660e125d05754718bf6f1a4)</span>
<span class="hljs-keyword">val</span> amount = <span class="hljs-number">10000.</span>satoshis <span class="hljs-keyword">val</span> amount = <span class="hljs-number">10000.</span>satoshis
<span class="hljs-comment">// amount: Satoshis = 10000 sats</span> <span class="hljs-comment">// amount: Satoshis = 10000 sats</span>
<span class="hljs-comment">// this is the UTXO we are going to be spending</span> <span class="hljs-comment">// this is the UTXO we are going to be spending</span>
<span class="hljs-keyword">val</span> utxo = <span class="hljs-keyword">val</span> utxo =
<span class="hljs-type">TransactionOutput</span>(value = amount, scriptPubKey = creditingSpk) <span class="hljs-type">TransactionOutput</span>(value = amount, scriptPubKey = creditingSpk)
<span class="hljs-comment">// utxo: TransactionOutput = TransactionOutput(10000 sats,pkh(76ee004f76fdda7861782f616b6b36d0c3425c71))</span> <span class="hljs-comment">// utxo: TransactionOutput = TransactionOutput(10000 sats,pkh(ec2c33f1b36ef6c7d660e125d05754718bf6f1a4))</span>
<span class="hljs-comment">// the private key that locks the funds for the script we are spending too</span> <span class="hljs-comment">// the private key that locks the funds for the script we are spending too</span>
<span class="hljs-keyword">val</span> destinationPrivKey = <span class="hljs-type">ECPrivateKey</span>.freshPrivateKey <span class="hljs-keyword">val</span> destinationPrivKey = <span class="hljs-type">ECPrivateKey</span>.freshPrivateKey
@ -99,7 +99,7 @@
<span class="hljs-comment">// the script that corresponds to destination private key, this is what is receiving the money</span> <span class="hljs-comment">// the script that corresponds to destination private key, this is what is receiving the money</span>
<span class="hljs-keyword">val</span> destinationSPK = <span class="hljs-keyword">val</span> destinationSPK =
<span class="hljs-type">P2PKHScriptPubKey</span>(pubKey = destinationPrivKey.publicKey) <span class="hljs-type">P2PKHScriptPubKey</span>(pubKey = destinationPrivKey.publicKey)
<span class="hljs-comment">// destinationSPK: P2PKHScriptPubKey = pkh(492685e43f739cb5e4ba10fffca6ea92ba5bb501)</span> <span class="hljs-comment">// destinationSPK: P2PKHScriptPubKey = pkh(93daee134f71680ea95752cdb7efc19a8b70ba1f)</span>
<span class="hljs-comment">// this is where we are sending money too</span> <span class="hljs-comment">// this is where we are sending money too</span>
<span class="hljs-comment">// we could add more destinations here if we</span> <span class="hljs-comment">// we could add more destinations here if we</span>
@ -110,7 +110,7 @@
<span class="hljs-type">Vector</span>(destination0) <span class="hljs-type">Vector</span>(destination0)
} }
<span class="hljs-comment">// destinations: Vector[TransactionOutput] = Vector(TransactionOutput(5000 sats,pkh(492685e43f739cb5e4ba10fffca6ea92ba5bb501)))</span> <span class="hljs-comment">// destinations: Vector[TransactionOutput] = Vector(TransactionOutput(5000 sats,pkh(93daee134f71680ea95752cdb7efc19a8b70ba1f)))</span>
<span class="hljs-comment">// Add the destinations to the tx builder</span> <span class="hljs-comment">// Add the destinations to the tx builder</span>
builder ++= destinations builder ++= destinations
@ -123,17 +123,17 @@ builder ++= destinations
inputs = <span class="hljs-type">Vector</span>.empty, inputs = <span class="hljs-type">Vector</span>.empty,
outputs = <span class="hljs-type">Vector</span>(utxo), outputs = <span class="hljs-type">Vector</span>(utxo),
lockTime = <span class="hljs-type">UInt32</span>.zero) lockTime = <span class="hljs-type">UInt32</span>.zero)
<span class="hljs-comment">// creditingTx: BaseTransaction = BaseTransaction(Int32Impl(1),Vector(),Vector(TransactionOutput(10000 sats,pkh(76ee004f76fdda7861782f616b6b36d0c3425c71))),UInt32Impl(0))</span> <span class="hljs-comment">// creditingTx: BaseTransaction = BaseTransaction(Int32Impl(1),Vector(),Vector(TransactionOutput(10000 sats,pkh(ec2c33f1b36ef6c7d660e125d05754718bf6f1a4))),UInt32Impl(0))</span>
<span class="hljs-comment">// this is the information we need from the crediting TX</span> <span class="hljs-comment">// this is the information we need from the crediting TX</span>
<span class="hljs-comment">// to properly &quot;link&quot; it in the transaction we are creating</span> <span class="hljs-comment">// to properly &quot;link&quot; it in the transaction we are creating</span>
<span class="hljs-keyword">val</span> outPoint = <span class="hljs-type">TransactionOutPoint</span>(creditingTx.txId, <span class="hljs-type">UInt32</span>.zero) <span class="hljs-keyword">val</span> outPoint = <span class="hljs-type">TransactionOutPoint</span>(creditingTx.txId, <span class="hljs-type">UInt32</span>.zero)
<span class="hljs-comment">// outPoint: TransactionOutPoint = TransactionOutPoint(f7ccf1e4d6e77bd17387c4e64ed79e17fbd7ffffccd06fdd7ef3c3e490b9d5ee:0)</span> <span class="hljs-comment">// outPoint: TransactionOutPoint = TransactionOutPoint(5e6d204bd5aa3fad3760c66b3cdc77b32fdcefb224a41fdcf5af9a7793abd4b8:0)</span>
<span class="hljs-keyword">val</span> input = <span class="hljs-type">TransactionInput</span>( <span class="hljs-keyword">val</span> input = <span class="hljs-type">TransactionInput</span>(
outPoint, outPoint,
<span class="hljs-type">EmptyScriptSignature</span>, <span class="hljs-type">EmptyScriptSignature</span>,
sequenceNumber = <span class="hljs-type">UInt32</span>.zero) sequenceNumber = <span class="hljs-type">UInt32</span>.zero)
<span class="hljs-comment">// input: TransactionInput = TransactionInputImpl(TransactionOutPoint(f7ccf1e4d6e77bd17387c4e64ed79e17fbd7ffffccd06fdd7ef3c3e490b9d5ee:0),EmptyScriptSignature,UInt32Impl(0))</span> <span class="hljs-comment">// input: TransactionInput = TransactionInputImpl(TransactionOutPoint(5e6d204bd5aa3fad3760c66b3cdc77b32fdcefb224a41fdcf5af9a7793abd4b8:0),EmptyScriptSignature,UInt32Impl(0))</span>
<span class="hljs-comment">// Add a new input to our builder</span> <span class="hljs-comment">// Add a new input to our builder</span>
builder += input builder += input
@ -141,11 +141,11 @@ builder += input
<span class="hljs-comment">// We can now generate a RawTxBuilderResult ready to be finalized</span> <span class="hljs-comment">// We can now generate a RawTxBuilderResult ready to be finalized</span>
<span class="hljs-keyword">val</span> builderResult = builder.result() <span class="hljs-keyword">val</span> builderResult = builder.result()
<span class="hljs-comment">// builderResult: RawTxBuilderResult = RawTxBuilderResult(Int32Impl(2),Vector(TransactionInputImpl(TransactionOutPoint(f7ccf1e4d6e77bd17387c4e64ed79e17fbd7ffffccd06fdd7ef3c3e490b9d5ee:0),EmptyScriptSignature,UInt32Impl(0))),Vector(TransactionOutput(5000 sats,pkh(492685e43f739cb5e4ba10fffca6ea92ba5bb501))),UInt32Impl(0))</span> <span class="hljs-comment">// builderResult: RawTxBuilderResult = RawTxBuilderResult(Int32Impl(2),Vector(TransactionInputImpl(TransactionOutPoint(5e6d204bd5aa3fad3760c66b3cdc77b32fdcefb224a41fdcf5af9a7793abd4b8:0),EmptyScriptSignature,UInt32Impl(0))),Vector(TransactionOutput(5000 sats,pkh(93daee134f71680ea95752cdb7efc19a8b70ba1f))),UInt32Impl(0))</span>
<span class="hljs-comment">// this contains the information needed to analyze our input during finalization</span> <span class="hljs-comment">// this contains the information needed to analyze our input during finalization</span>
<span class="hljs-keyword">val</span> inputInfo = <span class="hljs-type">P2PKHInputInfo</span>(outPoint, amount, privKey.publicKey) <span class="hljs-keyword">val</span> inputInfo = <span class="hljs-type">P2PKHInputInfo</span>(outPoint, amount, privKey.publicKey)
<span class="hljs-comment">// inputInfo: P2PKHInputInfo = P2PKHInputInfo(TransactionOutPoint(f7ccf1e4d6e77bd17387c4e64ed79e17fbd7ffffccd06fdd7ef3c3e490b9d5ee:0),10000 sats,ECPublicKey(02530ee3fd565e59f937e56bda48e9225ea8b09986e6987e6c89afa4930dae7326))</span> <span class="hljs-comment">// inputInfo: P2PKHInputInfo = P2PKHInputInfo(TransactionOutPoint(5e6d204bd5aa3fad3760c66b3cdc77b32fdcefb224a41fdcf5af9a7793abd4b8:0),10000 sats,ECPublicKey(022a992a3bf2b093045485ea8217c1912a636c4cfd50f4361b9b51e3c5a3799ffd))</span>
<span class="hljs-comment">// this is how much we are going to pay as a fee to the network</span> <span class="hljs-comment">// this is how much we are going to pay as a fee to the network</span>
<span class="hljs-comment">// for this example, we are going to pay 1 satoshi per byte</span> <span class="hljs-comment">// for this example, we are going to pay 1 satoshi per byte</span>
@ -155,18 +155,18 @@ builder += input
<span class="hljs-keyword">val</span> changePrivKey = <span class="hljs-type">ECPrivateKey</span>.freshPrivateKey <span class="hljs-keyword">val</span> changePrivKey = <span class="hljs-type">ECPrivateKey</span>.freshPrivateKey
<span class="hljs-comment">// changePrivKey: ECPrivateKey = Masked(ECPrivateKeyImpl)</span> <span class="hljs-comment">// changePrivKey: ECPrivateKey = Masked(ECPrivateKeyImpl)</span>
<span class="hljs-keyword">val</span> changeSPK = <span class="hljs-type">P2PKHScriptPubKey</span>(pubKey = changePrivKey.publicKey) <span class="hljs-keyword">val</span> changeSPK = <span class="hljs-type">P2PKHScriptPubKey</span>(pubKey = changePrivKey.publicKey)
<span class="hljs-comment">// changeSPK: P2PKHScriptPubKey = pkh(e896cc908f35f392ede12450e96f886b1b963c08)</span> <span class="hljs-comment">// changeSPK: P2PKHScriptPubKey = pkh(b531643f691903cd6a8184ab4d3969cfd15a3651)</span>
<span class="hljs-comment">// We chose a finalizer that adds a change output to our tx based on a fee rate</span> <span class="hljs-comment">// We chose a finalizer that adds a change output to our tx based on a fee rate</span>
<span class="hljs-keyword">val</span> finalizer = <span class="hljs-type">StandardNonInteractiveFinalizer</span>( <span class="hljs-keyword">val</span> finalizer = <span class="hljs-type">StandardNonInteractiveFinalizer</span>(
<span class="hljs-type">Vector</span>(inputInfo), <span class="hljs-type">Vector</span>(inputInfo),
feeRate, feeRate,
changeSPK) changeSPK)
<span class="hljs-comment">// finalizer: StandardNonInteractiveFinalizer = StandardNonInteractiveFinalizer(Vector(P2PKHInputInfo(TransactionOutPoint(f7ccf1e4d6e77bd17387c4e64ed79e17fbd7ffffccd06fdd7ef3c3e490b9d5ee:0),10000 sats,ECPublicKey(02530ee3fd565e59f937e56bda48e9225ea8b09986e6987e6c89afa4930dae7326))),1 sats/byte,pkh(e896cc908f35f392ede12450e96f886b1b963c08))</span> <span class="hljs-comment">// finalizer: StandardNonInteractiveFinalizer = StandardNonInteractiveFinalizer(Vector(P2PKHInputInfo(TransactionOutPoint(5e6d204bd5aa3fad3760c66b3cdc77b32fdcefb224a41fdcf5af9a7793abd4b8:0),10000 sats,ECPublicKey(022a992a3bf2b093045485ea8217c1912a636c4cfd50f4361b9b51e3c5a3799ffd))),1 sats/byte,pkh(b531643f691903cd6a8184ab4d3969cfd15a3651))</span>
<span class="hljs-comment">// We can now finalize the tx builder result from earlier with this finalizer</span> <span class="hljs-comment">// We can now finalize the tx builder result from earlier with this finalizer</span>
<span class="hljs-keyword">val</span> unsignedTxF: <span class="hljs-type">Future</span>[<span class="hljs-type">Transaction</span>] = finalizer.buildTx(builderResult) <span class="hljs-keyword">val</span> unsignedTxF: <span class="hljs-type">Future</span>[<span class="hljs-type">Transaction</span>] = finalizer.buildTx(builderResult)
<span class="hljs-comment">// unsignedTxF: Future[Transaction] = Future(Success(BaseTransaction(Int32Impl(2),Vector(TransactionInputImpl(TransactionOutPoint(f7ccf1e4d6e77bd17387c4e64ed79e17fbd7ffffccd06fdd7ef3c3e490b9d5ee:0),EmptyScriptSignature,UInt32Impl(0))),Vector(TransactionOutput(5000 sats,pkh(492685e43f739cb5e4ba10fffca6ea92ba5bb501)), TransactionOutput(4775 sats,pkh(e896cc908f35f392ede12450e96f886b1b963c08))),UInt32Impl(0))))</span> <span class="hljs-comment">// unsignedTxF: Future[Transaction] = Future(Success(BaseTransaction(Int32Impl(2),Vector(TransactionInputImpl(TransactionOutPoint(5e6d204bd5aa3fad3760c66b3cdc77b32fdcefb224a41fdcf5af9a7793abd4b8:0),EmptyScriptSignature,UInt32Impl(0))),Vector(TransactionOutput(5000 sats,pkh(93daee134f71680ea95752cdb7efc19a8b70ba1f)), TransactionOutput(4775 sats,pkh(b531643f691903cd6a8184ab4d3969cfd15a3651))),UInt32Impl(0))))</span>
<span class="hljs-comment">// We now turn to signing the unsigned transaction</span> <span class="hljs-comment">// We now turn to signing the unsigned transaction</span>
<span class="hljs-comment">// this contains all the information we need to</span> <span class="hljs-comment">// this contains all the information we need to</span>
@ -176,12 +176,12 @@ builder += input
signers = <span class="hljs-type">Vector</span>(privKey), signers = <span class="hljs-type">Vector</span>(privKey),
hashType = hashType =
<span class="hljs-type">HashType</span>.sigHashAll) <span class="hljs-type">HashType</span>.sigHashAll)
<span class="hljs-comment">// utxoInfo: ScriptSignatureParams[P2PKHInputInfo] = ScriptSignatureParams(P2PKHInputInfo(TransactionOutPoint(f7ccf1e4d6e77bd17387c4e64ed79e17fbd7ffffccd06fdd7ef3c3e490b9d5ee:0),10000 sats,ECPublicKey(02530ee3fd565e59f937e56bda48e9225ea8b09986e6987e6c89afa4930dae7326)),BaseTransaction(Int32Impl(1),Vector(),Vector(TransactionOutput(10000 sats,pkh(76ee004f76fdda7861782f616b6b36d0c3425c71))),UInt32Impl(0)),Vector(Masked(ECPrivateKeyImpl)),SIGHASH_ALL(Int32Impl(1)))</span> <span class="hljs-comment">// utxoInfo: ScriptSignatureParams[P2PKHInputInfo] = ScriptSignatureParams(P2PKHInputInfo(TransactionOutPoint(5e6d204bd5aa3fad3760c66b3cdc77b32fdcefb224a41fdcf5af9a7793abd4b8:0),10000 sats,ECPublicKey(022a992a3bf2b093045485ea8217c1912a636c4cfd50f4361b9b51e3c5a3799ffd)),BaseTransaction(Int32Impl(1),Vector(),Vector(TransactionOutput(10000 sats,pkh(ec2c33f1b36ef6c7d660e125d05754718bf6f1a4))),UInt32Impl(0)),Vector(Masked(ECPrivateKeyImpl)),SIGHASH_ALL(Int32Impl(1)))</span>
<span class="hljs-comment">// all of the UTXO spending information, since we only have</span> <span class="hljs-comment">// all of the UTXO spending information, since we only have</span>
<span class="hljs-comment">// one input, this is just one element</span> <span class="hljs-comment">// one input, this is just one element</span>
<span class="hljs-keyword">val</span> utxoInfos: <span class="hljs-type">Vector</span>[<span class="hljs-type">ScriptSignatureParams</span>[<span class="hljs-type">InputInfo</span>]] = <span class="hljs-type">Vector</span>(utxoInfo) <span class="hljs-keyword">val</span> utxoInfos: <span class="hljs-type">Vector</span>[<span class="hljs-type">ScriptSignatureParams</span>[<span class="hljs-type">InputInfo</span>]] = <span class="hljs-type">Vector</span>(utxoInfo)
<span class="hljs-comment">// utxoInfos: Vector[ScriptSignatureParams[InputInfo]] = Vector(ScriptSignatureParams(P2PKHInputInfo(TransactionOutPoint(f7ccf1e4d6e77bd17387c4e64ed79e17fbd7ffffccd06fdd7ef3c3e490b9d5ee:0),10000 sats,ECPublicKey(02530ee3fd565e59f937e56bda48e9225ea8b09986e6987e6c89afa4930dae7326)),BaseTransaction(Int32Impl(1),Vector(),Vector(TransactionOutput(10000 sats,pkh(76ee004f76fdda7861782f616b6b36d0c3425c71))),UInt32Impl(0)),Vector(Masked(ECPrivateKeyImpl)),SIGHASH_ALL(Int32Impl(1))))</span> <span class="hljs-comment">// utxoInfos: Vector[ScriptSignatureParams[InputInfo]] = Vector(ScriptSignatureParams(P2PKHInputInfo(TransactionOutPoint(5e6d204bd5aa3fad3760c66b3cdc77b32fdcefb224a41fdcf5af9a7793abd4b8:0),10000 sats,ECPublicKey(022a992a3bf2b093045485ea8217c1912a636c4cfd50f4361b9b51e3c5a3799ffd)),BaseTransaction(Int32Impl(1),Vector(),Vector(TransactionOutput(10000 sats,pkh(ec2c33f1b36ef6c7d660e125d05754718bf6f1a4))),UInt32Impl(0)),Vector(Masked(ECPrivateKeyImpl)),SIGHASH_ALL(Int32Impl(1))))</span>
<span class="hljs-comment">// Yay! Now we use the RawTxSigner object to sign the tx.</span> <span class="hljs-comment">// Yay! Now we use the RawTxSigner object to sign the tx.</span>
<span class="hljs-comment">// The &#x27;sign&#x27; method is going produce a validly signed transaction</span> <span class="hljs-comment">// The &#x27;sign&#x27; method is going produce a validly signed transaction</span>
@ -201,7 +201,7 @@ builder += input
} }
<span class="hljs-type">Await</span>.result(signedTxF, <span class="hljs-number">30.</span>seconds) <span class="hljs-type">Await</span>.result(signedTxF, <span class="hljs-number">30.</span>seconds)
} }
<span class="hljs-comment">// signedTx: Transaction = BaseTransaction(Int32Impl(2),Vector(TransactionInputImpl(TransactionOutPoint(f7ccf1e4d6e77bd17387c4e64ed79e17fbd7ffffccd06fdd7ef3c3e490b9d5ee:0),P2PKHScriptSignature(ECPublicKey(02530ee3fd565e59f937e56bda48e9225ea8b09986e6987e6c89afa4930dae7326), ECDigitalSignature(304402205af538c9ab33dcf531c8acb49a6da8849390a6cf0b3d1ccd4a8cd8989062e18e02203dce90afcb95d6605cad4eb60c8026ac5884ccac66c27eeba420191feb112d3e01)),UInt32Impl(0))),Vector(TransactionOutput(5000 sats,pkh(492685e43f739cb5e4ba10fffca6ea92ba5bb501)), TransactionOutput(4775 sats,pkh(e896cc908f35f392ede12450e96f886b1b963c08))),UInt32Impl(0))</span> <span class="hljs-comment">// signedTx: Transaction = BaseTransaction(Int32Impl(2),Vector(TransactionInputImpl(TransactionOutPoint(5e6d204bd5aa3fad3760c66b3cdc77b32fdcefb224a41fdcf5af9a7793abd4b8:0),P2PKHScriptSignature(ECPublicKey(022a992a3bf2b093045485ea8217c1912a636c4cfd50f4361b9b51e3c5a3799ffd), ECDigitalSignature(3044022076f64ffd051890d4fc5f0f5c05bf0bd4dbdac51b0984539fb3a9d05d9b1e51d30220704b82d8f69d2e90da5db98898caed6261f80ac9eedb8369ef1ff269441a039601)),UInt32Impl(0))),Vector(TransactionOutput(5000 sats,pkh(93daee134f71680ea95752cdb7efc19a8b70ba1f)), TransactionOutput(4775 sats,pkh(b531643f691903cd6a8184ab4d3969cfd15a3651))),UInt32Impl(0))</span>
</code></pre> </code></pre>
<pre><code class="hljs css language-scala">signedTx.inputs.length <pre><code class="hljs css language-scala">signedTx.inputs.length
<span class="hljs-comment">// res2: Int = 1</span> <span class="hljs-comment">// res2: Int = 1</span>
@ -211,7 +211,7 @@ signedTx.outputs.length
<span class="hljs-comment">//remember, you can call .hex on any bitcoin-s data structure to get the hex representation!</span> <span class="hljs-comment">//remember, you can call .hex on any bitcoin-s data structure to get the hex representation!</span>
signedTx.hex signedTx.hex
<span class="hljs-comment">// res4: String = 0200000001eed5b990e4c3f37edd6fd0ccffffd7fb179ed74ee6c48773d17be7d6e4f1ccf7000000006a47304402205af538c9ab33dcf531c8acb49a6da8849390a6cf0b3d1ccd4a8cd8989062e18e02203dce90afcb95d6605cad4eb60c8026ac5884ccac66c27eeba420191feb112d3e012102530ee3fd565e59f937e56bda48e9225ea8b09986e6987e6c89afa4930dae7326000000000288130000000000001976a914492685e43f739cb5e4ba10fffca6ea92ba5bb50188aca7120000000000001976a914e896cc908f35f392ede12450e96f886b1b963c0888ac00000000</span> <span class="hljs-comment">// res4: String = 0200000001b8d4ab93779aaff5dc1fa424b2efdc2fb377dc3c6bc66037ad3faad54b206d5e000000006a473044022076f64ffd051890d4fc5f0f5c05bf0bd4dbdac51b0984539fb3a9d05d9b1e51d30220704b82d8f69d2e90da5db98898caed6261f80ac9eedb8369ef1ff269441a03960121022a992a3bf2b093045485ea8217c1912a636c4cfd50f4361b9b51e3c5a3799ffd000000000288130000000000001976a91493daee134f71680ea95752cdb7efc19a8b70ba1f88aca7120000000000001976a914b531643f691903cd6a8184ab4d3969cfd15a365188ac00000000</span>
</code></pre> </code></pre>
</span></div></article></div><div class="docs-prevnext"><a class="docs-prev button" href="/docs/next/core/psbts"><span class="arrow-prev"></span><span>Partially Signed Bitcoin Transactions</span></a><a class="docs-next button" href="/docs/next/core/lightning-network"><span>Lightning Network Data Types</span><span class="arrow-next"></span></a></div></div></div><nav class="onPageNav"></nav></div><footer class="nav-footer" id="footer"><section class="sitemap"><a href="/" class="nav-home"><img src="/img/favicon.ico" alt="bitcoin-s" width="66" height="58"/></a><div><h5>Docs</h5><a href="/docs/en/getting-started">Getting Started</a><a href="/docs/en/core/core-intro">Guides</a><a href="/api/org/bitcoins">API Reference</a></div><div><h5>Community</h5><a href="/en/users.html">User Showcase</a><a href="https://join.slack.com/t/suredbits/shared_invite/zt-eavycu0x-WQL7XOakzQo8tAy7jHHZUw" target="_blank" rel="noreferrer noopener">Slack</a><a href="https://gitter.im/bitcoin-s-core/">Gitter chat</a></div><div><h5>More</h5><a href="https://github.com/bitcoin-s/bitcoin-s">GitHub</a><a class="github-button" href="https://github.com/bitcoin-s/bitcoin-s" data-icon="octicon-star" data-count-href="/bitcoin-s/bitcoin-s-core/stargazers" data-show-count="true" data-count-aria-label="# stargazers on GitHub" aria-label="Star this project on GitHub">Star</a></div></section><section class="copyright">Copyright © 2020 Suredbits &amp; the bitcoin-s developers</section></footer></div><script type="text/javascript" src="https://cdn.jsdelivr.net/docsearch.js/1/docsearch.min.js"></script><script> </span></div></article></div><div class="docs-prevnext"><a class="docs-prev button" href="/docs/next/core/psbts"><span class="arrow-prev"></span><span>Partially Signed Bitcoin Transactions</span></a><a class="docs-next button" href="/docs/next/core/lightning-network"><span>Lightning Network Data Types</span><span class="arrow-next"></span></a></div></div></div><nav class="onPageNav"></nav></div><footer class="nav-footer" id="footer"><section class="sitemap"><a href="/" class="nav-home"><img src="/img/favicon.ico" alt="bitcoin-s" width="66" height="58"/></a><div><h5>Docs</h5><a href="/docs/en/getting-started">Getting Started</a><a href="/docs/en/core/core-intro">Guides</a><a href="/api/org/bitcoins">API Reference</a></div><div><h5>Community</h5><a href="/en/users.html">User Showcase</a><a href="https://join.slack.com/t/suredbits/shared_invite/zt-eavycu0x-WQL7XOakzQo8tAy7jHHZUw" target="_blank" rel="noreferrer noopener">Slack</a><a href="https://gitter.im/bitcoin-s-core/">Gitter chat</a></div><div><h5>More</h5><a href="https://github.com/bitcoin-s/bitcoin-s">GitHub</a><a class="github-button" href="https://github.com/bitcoin-s/bitcoin-s" data-icon="octicon-star" data-count-href="/bitcoin-s/bitcoin-s-core/stargazers" data-show-count="true" data-count-aria-label="# stargazers on GitHub" aria-label="Star this project on GitHub">Star</a></div></section><section class="copyright">Copyright © 2020 Suredbits &amp; the bitcoin-s developers</section></footer></div><script type="text/javascript" src="https://cdn.jsdelivr.net/docsearch.js/1/docsearch.min.js"></script><script>
document.addEventListener('keyup', function(e) { document.addEventListener('keyup', function(e) {

View file

@ -64,7 +64,7 @@
}); });
</script></nav></div><div class="container mainContainer docsContainer"><div class="wrapper"><div class="post"><header class="postHeader"><a class="edit-page-link button" href="https://github.com/bitcoin-s/bitcoin-s/blob/master/docs/core/txbuilder.md" target="_blank" rel="noreferrer noopener">Edit</a><h1 id="__docusaurus" class="postHeaderTitle">TxBuilder Example</h1></header><article><div><span><p>Bitcoin-S features a transaction building API that allows you to construct and sign Bitcoin transactions. Here's an example of how to use it</p> </script></nav></div><div class="container mainContainer docsContainer"><div class="wrapper"><div class="post"><header class="postHeader"><a class="edit-page-link button" href="https://github.com/bitcoin-s/bitcoin-s/blob/master/docs/core/txbuilder.md" target="_blank" rel="noreferrer noopener">Edit</a><h1 id="__docusaurus" class="postHeaderTitle">TxBuilder Example</h1></header><article><div><span><p>Bitcoin-S features a transaction building API that allows you to construct and sign Bitcoin transactions. Here's an example of how to use it</p>
<pre><code class="hljs css language-scala"><span class="hljs-keyword">implicit</span> <span class="hljs-keyword">val</span> ec: <span class="hljs-type">ExecutionContext</span> = <span class="hljs-type">ExecutionContext</span>.<span class="hljs-type">Implicits</span>.global <pre><code class="hljs css language-scala"><span class="hljs-keyword">implicit</span> <span class="hljs-keyword">val</span> ec: <span class="hljs-type">ExecutionContext</span> = <span class="hljs-type">ExecutionContext</span>.<span class="hljs-type">Implicits</span>.global
<span class="hljs-comment">// ec: ExecutionContext = scala.concurrent.impl.ExecutionContextImpl$$anon$3@35378fe1[Running, parallelism = 2, size = 2, active = 0, running = 0, steals = 37, tasks = 0, submissions = 0]</span> <span class="hljs-comment">// ec: ExecutionContext = scala.concurrent.impl.ExecutionContextImpl$$anon$3@399c0f8b[Running, parallelism = 2, size = 2, active = 0, running = 0, steals = 33, tasks = 0, submissions = 0]</span>
<span class="hljs-comment">// Initialize a transaction builder</span> <span class="hljs-comment">// Initialize a transaction builder</span>
<span class="hljs-keyword">val</span> builder = <span class="hljs-type">RawTxBuilder</span>() <span class="hljs-keyword">val</span> builder = <span class="hljs-type">RawTxBuilder</span>()
@ -74,19 +74,19 @@
<span class="hljs-keyword">val</span> privKey = <span class="hljs-type">ECPrivateKey</span>.freshPrivateKey <span class="hljs-keyword">val</span> privKey = <span class="hljs-type">ECPrivateKey</span>.freshPrivateKey
<span class="hljs-comment">// privKey: ECPrivateKey = Masked(ECPrivateKeyImpl)</span> <span class="hljs-comment">// privKey: ECPrivateKey = Masked(ECPrivateKeyImpl)</span>
<span class="hljs-keyword">val</span> pubKey = privKey.publicKey <span class="hljs-keyword">val</span> pubKey = privKey.publicKey
<span class="hljs-comment">// pubKey: ECPublicKey = ECPublicKey(02530ee3fd565e59f937e56bda48e9225ea8b09986e6987e6c89afa4930dae7326)</span> <span class="hljs-comment">// pubKey: ECPublicKey = ECPublicKey(022a992a3bf2b093045485ea8217c1912a636c4cfd50f4361b9b51e3c5a3799ffd)</span>
<span class="hljs-comment">// this is the script that the TxBuilder is going to create a</span> <span class="hljs-comment">// this is the script that the TxBuilder is going to create a</span>
<span class="hljs-comment">// script signature that validly spends this scriptPubKey</span> <span class="hljs-comment">// script signature that validly spends this scriptPubKey</span>
<span class="hljs-keyword">val</span> creditingSpk = <span class="hljs-type">P2PKHScriptPubKey</span>(pubKey = privKey.publicKey) <span class="hljs-keyword">val</span> creditingSpk = <span class="hljs-type">P2PKHScriptPubKey</span>(pubKey = privKey.publicKey)
<span class="hljs-comment">// creditingSpk: P2PKHScriptPubKey = pkh(76ee004f76fdda7861782f616b6b36d0c3425c71)</span> <span class="hljs-comment">// creditingSpk: P2PKHScriptPubKey = pkh(ec2c33f1b36ef6c7d660e125d05754718bf6f1a4)</span>
<span class="hljs-keyword">val</span> amount = <span class="hljs-number">10000.</span>satoshis <span class="hljs-keyword">val</span> amount = <span class="hljs-number">10000.</span>satoshis
<span class="hljs-comment">// amount: Satoshis = 10000 sats</span> <span class="hljs-comment">// amount: Satoshis = 10000 sats</span>
<span class="hljs-comment">// this is the UTXO we are going to be spending</span> <span class="hljs-comment">// this is the UTXO we are going to be spending</span>
<span class="hljs-keyword">val</span> utxo = <span class="hljs-keyword">val</span> utxo =
<span class="hljs-type">TransactionOutput</span>(value = amount, scriptPubKey = creditingSpk) <span class="hljs-type">TransactionOutput</span>(value = amount, scriptPubKey = creditingSpk)
<span class="hljs-comment">// utxo: TransactionOutput = TransactionOutput(10000 sats,pkh(76ee004f76fdda7861782f616b6b36d0c3425c71))</span> <span class="hljs-comment">// utxo: TransactionOutput = TransactionOutput(10000 sats,pkh(ec2c33f1b36ef6c7d660e125d05754718bf6f1a4))</span>
<span class="hljs-comment">// the private key that locks the funds for the script we are spending too</span> <span class="hljs-comment">// the private key that locks the funds for the script we are spending too</span>
<span class="hljs-keyword">val</span> destinationPrivKey = <span class="hljs-type">ECPrivateKey</span>.freshPrivateKey <span class="hljs-keyword">val</span> destinationPrivKey = <span class="hljs-type">ECPrivateKey</span>.freshPrivateKey
@ -99,7 +99,7 @@
<span class="hljs-comment">// the script that corresponds to destination private key, this is what is receiving the money</span> <span class="hljs-comment">// the script that corresponds to destination private key, this is what is receiving the money</span>
<span class="hljs-keyword">val</span> destinationSPK = <span class="hljs-keyword">val</span> destinationSPK =
<span class="hljs-type">P2PKHScriptPubKey</span>(pubKey = destinationPrivKey.publicKey) <span class="hljs-type">P2PKHScriptPubKey</span>(pubKey = destinationPrivKey.publicKey)
<span class="hljs-comment">// destinationSPK: P2PKHScriptPubKey = pkh(492685e43f739cb5e4ba10fffca6ea92ba5bb501)</span> <span class="hljs-comment">// destinationSPK: P2PKHScriptPubKey = pkh(93daee134f71680ea95752cdb7efc19a8b70ba1f)</span>
<span class="hljs-comment">// this is where we are sending money too</span> <span class="hljs-comment">// this is where we are sending money too</span>
<span class="hljs-comment">// we could add more destinations here if we</span> <span class="hljs-comment">// we could add more destinations here if we</span>
@ -110,7 +110,7 @@
<span class="hljs-type">Vector</span>(destination0) <span class="hljs-type">Vector</span>(destination0)
} }
<span class="hljs-comment">// destinations: Vector[TransactionOutput] = Vector(TransactionOutput(5000 sats,pkh(492685e43f739cb5e4ba10fffca6ea92ba5bb501)))</span> <span class="hljs-comment">// destinations: Vector[TransactionOutput] = Vector(TransactionOutput(5000 sats,pkh(93daee134f71680ea95752cdb7efc19a8b70ba1f)))</span>
<span class="hljs-comment">// Add the destinations to the tx builder</span> <span class="hljs-comment">// Add the destinations to the tx builder</span>
builder ++= destinations builder ++= destinations
@ -123,17 +123,17 @@ builder ++= destinations
inputs = <span class="hljs-type">Vector</span>.empty, inputs = <span class="hljs-type">Vector</span>.empty,
outputs = <span class="hljs-type">Vector</span>(utxo), outputs = <span class="hljs-type">Vector</span>(utxo),
lockTime = <span class="hljs-type">UInt32</span>.zero) lockTime = <span class="hljs-type">UInt32</span>.zero)
<span class="hljs-comment">// creditingTx: BaseTransaction = BaseTransaction(Int32Impl(1),Vector(),Vector(TransactionOutput(10000 sats,pkh(76ee004f76fdda7861782f616b6b36d0c3425c71))),UInt32Impl(0))</span> <span class="hljs-comment">// creditingTx: BaseTransaction = BaseTransaction(Int32Impl(1),Vector(),Vector(TransactionOutput(10000 sats,pkh(ec2c33f1b36ef6c7d660e125d05754718bf6f1a4))),UInt32Impl(0))</span>
<span class="hljs-comment">// this is the information we need from the crediting TX</span> <span class="hljs-comment">// this is the information we need from the crediting TX</span>
<span class="hljs-comment">// to properly &quot;link&quot; it in the transaction we are creating</span> <span class="hljs-comment">// to properly &quot;link&quot; it in the transaction we are creating</span>
<span class="hljs-keyword">val</span> outPoint = <span class="hljs-type">TransactionOutPoint</span>(creditingTx.txId, <span class="hljs-type">UInt32</span>.zero) <span class="hljs-keyword">val</span> outPoint = <span class="hljs-type">TransactionOutPoint</span>(creditingTx.txId, <span class="hljs-type">UInt32</span>.zero)
<span class="hljs-comment">// outPoint: TransactionOutPoint = TransactionOutPoint(f7ccf1e4d6e77bd17387c4e64ed79e17fbd7ffffccd06fdd7ef3c3e490b9d5ee:0)</span> <span class="hljs-comment">// outPoint: TransactionOutPoint = TransactionOutPoint(5e6d204bd5aa3fad3760c66b3cdc77b32fdcefb224a41fdcf5af9a7793abd4b8:0)</span>
<span class="hljs-keyword">val</span> input = <span class="hljs-type">TransactionInput</span>( <span class="hljs-keyword">val</span> input = <span class="hljs-type">TransactionInput</span>(
outPoint, outPoint,
<span class="hljs-type">EmptyScriptSignature</span>, <span class="hljs-type">EmptyScriptSignature</span>,
sequenceNumber = <span class="hljs-type">UInt32</span>.zero) sequenceNumber = <span class="hljs-type">UInt32</span>.zero)
<span class="hljs-comment">// input: TransactionInput = TransactionInputImpl(TransactionOutPoint(f7ccf1e4d6e77bd17387c4e64ed79e17fbd7ffffccd06fdd7ef3c3e490b9d5ee:0),EmptyScriptSignature,UInt32Impl(0))</span> <span class="hljs-comment">// input: TransactionInput = TransactionInputImpl(TransactionOutPoint(5e6d204bd5aa3fad3760c66b3cdc77b32fdcefb224a41fdcf5af9a7793abd4b8:0),EmptyScriptSignature,UInt32Impl(0))</span>
<span class="hljs-comment">// Add a new input to our builder</span> <span class="hljs-comment">// Add a new input to our builder</span>
builder += input builder += input
@ -141,11 +141,11 @@ builder += input
<span class="hljs-comment">// We can now generate a RawTxBuilderResult ready to be finalized</span> <span class="hljs-comment">// We can now generate a RawTxBuilderResult ready to be finalized</span>
<span class="hljs-keyword">val</span> builderResult = builder.result() <span class="hljs-keyword">val</span> builderResult = builder.result()
<span class="hljs-comment">// builderResult: RawTxBuilderResult = RawTxBuilderResult(Int32Impl(2),Vector(TransactionInputImpl(TransactionOutPoint(f7ccf1e4d6e77bd17387c4e64ed79e17fbd7ffffccd06fdd7ef3c3e490b9d5ee:0),EmptyScriptSignature,UInt32Impl(0))),Vector(TransactionOutput(5000 sats,pkh(492685e43f739cb5e4ba10fffca6ea92ba5bb501))),UInt32Impl(0))</span> <span class="hljs-comment">// builderResult: RawTxBuilderResult = RawTxBuilderResult(Int32Impl(2),Vector(TransactionInputImpl(TransactionOutPoint(5e6d204bd5aa3fad3760c66b3cdc77b32fdcefb224a41fdcf5af9a7793abd4b8:0),EmptyScriptSignature,UInt32Impl(0))),Vector(TransactionOutput(5000 sats,pkh(93daee134f71680ea95752cdb7efc19a8b70ba1f))),UInt32Impl(0))</span>
<span class="hljs-comment">// this contains the information needed to analyze our input during finalization</span> <span class="hljs-comment">// this contains the information needed to analyze our input during finalization</span>
<span class="hljs-keyword">val</span> inputInfo = <span class="hljs-type">P2PKHInputInfo</span>(outPoint, amount, privKey.publicKey) <span class="hljs-keyword">val</span> inputInfo = <span class="hljs-type">P2PKHInputInfo</span>(outPoint, amount, privKey.publicKey)
<span class="hljs-comment">// inputInfo: P2PKHInputInfo = P2PKHInputInfo(TransactionOutPoint(f7ccf1e4d6e77bd17387c4e64ed79e17fbd7ffffccd06fdd7ef3c3e490b9d5ee:0),10000 sats,ECPublicKey(02530ee3fd565e59f937e56bda48e9225ea8b09986e6987e6c89afa4930dae7326))</span> <span class="hljs-comment">// inputInfo: P2PKHInputInfo = P2PKHInputInfo(TransactionOutPoint(5e6d204bd5aa3fad3760c66b3cdc77b32fdcefb224a41fdcf5af9a7793abd4b8:0),10000 sats,ECPublicKey(022a992a3bf2b093045485ea8217c1912a636c4cfd50f4361b9b51e3c5a3799ffd))</span>
<span class="hljs-comment">// this is how much we are going to pay as a fee to the network</span> <span class="hljs-comment">// this is how much we are going to pay as a fee to the network</span>
<span class="hljs-comment">// for this example, we are going to pay 1 satoshi per byte</span> <span class="hljs-comment">// for this example, we are going to pay 1 satoshi per byte</span>
@ -155,18 +155,18 @@ builder += input
<span class="hljs-keyword">val</span> changePrivKey = <span class="hljs-type">ECPrivateKey</span>.freshPrivateKey <span class="hljs-keyword">val</span> changePrivKey = <span class="hljs-type">ECPrivateKey</span>.freshPrivateKey
<span class="hljs-comment">// changePrivKey: ECPrivateKey = Masked(ECPrivateKeyImpl)</span> <span class="hljs-comment">// changePrivKey: ECPrivateKey = Masked(ECPrivateKeyImpl)</span>
<span class="hljs-keyword">val</span> changeSPK = <span class="hljs-type">P2PKHScriptPubKey</span>(pubKey = changePrivKey.publicKey) <span class="hljs-keyword">val</span> changeSPK = <span class="hljs-type">P2PKHScriptPubKey</span>(pubKey = changePrivKey.publicKey)
<span class="hljs-comment">// changeSPK: P2PKHScriptPubKey = pkh(e896cc908f35f392ede12450e96f886b1b963c08)</span> <span class="hljs-comment">// changeSPK: P2PKHScriptPubKey = pkh(b531643f691903cd6a8184ab4d3969cfd15a3651)</span>
<span class="hljs-comment">// We chose a finalizer that adds a change output to our tx based on a fee rate</span> <span class="hljs-comment">// We chose a finalizer that adds a change output to our tx based on a fee rate</span>
<span class="hljs-keyword">val</span> finalizer = <span class="hljs-type">StandardNonInteractiveFinalizer</span>( <span class="hljs-keyword">val</span> finalizer = <span class="hljs-type">StandardNonInteractiveFinalizer</span>(
<span class="hljs-type">Vector</span>(inputInfo), <span class="hljs-type">Vector</span>(inputInfo),
feeRate, feeRate,
changeSPK) changeSPK)
<span class="hljs-comment">// finalizer: StandardNonInteractiveFinalizer = StandardNonInteractiveFinalizer(Vector(P2PKHInputInfo(TransactionOutPoint(f7ccf1e4d6e77bd17387c4e64ed79e17fbd7ffffccd06fdd7ef3c3e490b9d5ee:0),10000 sats,ECPublicKey(02530ee3fd565e59f937e56bda48e9225ea8b09986e6987e6c89afa4930dae7326))),1 sats/byte,pkh(e896cc908f35f392ede12450e96f886b1b963c08))</span> <span class="hljs-comment">// finalizer: StandardNonInteractiveFinalizer = StandardNonInteractiveFinalizer(Vector(P2PKHInputInfo(TransactionOutPoint(5e6d204bd5aa3fad3760c66b3cdc77b32fdcefb224a41fdcf5af9a7793abd4b8:0),10000 sats,ECPublicKey(022a992a3bf2b093045485ea8217c1912a636c4cfd50f4361b9b51e3c5a3799ffd))),1 sats/byte,pkh(b531643f691903cd6a8184ab4d3969cfd15a3651))</span>
<span class="hljs-comment">// We can now finalize the tx builder result from earlier with this finalizer</span> <span class="hljs-comment">// We can now finalize the tx builder result from earlier with this finalizer</span>
<span class="hljs-keyword">val</span> unsignedTxF: <span class="hljs-type">Future</span>[<span class="hljs-type">Transaction</span>] = finalizer.buildTx(builderResult) <span class="hljs-keyword">val</span> unsignedTxF: <span class="hljs-type">Future</span>[<span class="hljs-type">Transaction</span>] = finalizer.buildTx(builderResult)
<span class="hljs-comment">// unsignedTxF: Future[Transaction] = Future(Success(BaseTransaction(Int32Impl(2),Vector(TransactionInputImpl(TransactionOutPoint(f7ccf1e4d6e77bd17387c4e64ed79e17fbd7ffffccd06fdd7ef3c3e490b9d5ee:0),EmptyScriptSignature,UInt32Impl(0))),Vector(TransactionOutput(5000 sats,pkh(492685e43f739cb5e4ba10fffca6ea92ba5bb501)), TransactionOutput(4775 sats,pkh(e896cc908f35f392ede12450e96f886b1b963c08))),UInt32Impl(0))))</span> <span class="hljs-comment">// unsignedTxF: Future[Transaction] = Future(Success(BaseTransaction(Int32Impl(2),Vector(TransactionInputImpl(TransactionOutPoint(5e6d204bd5aa3fad3760c66b3cdc77b32fdcefb224a41fdcf5af9a7793abd4b8:0),EmptyScriptSignature,UInt32Impl(0))),Vector(TransactionOutput(5000 sats,pkh(93daee134f71680ea95752cdb7efc19a8b70ba1f)), TransactionOutput(4775 sats,pkh(b531643f691903cd6a8184ab4d3969cfd15a3651))),UInt32Impl(0))))</span>
<span class="hljs-comment">// We now turn to signing the unsigned transaction</span> <span class="hljs-comment">// We now turn to signing the unsigned transaction</span>
<span class="hljs-comment">// this contains all the information we need to</span> <span class="hljs-comment">// this contains all the information we need to</span>
@ -176,12 +176,12 @@ builder += input
signers = <span class="hljs-type">Vector</span>(privKey), signers = <span class="hljs-type">Vector</span>(privKey),
hashType = hashType =
<span class="hljs-type">HashType</span>.sigHashAll) <span class="hljs-type">HashType</span>.sigHashAll)
<span class="hljs-comment">// utxoInfo: ScriptSignatureParams[P2PKHInputInfo] = ScriptSignatureParams(P2PKHInputInfo(TransactionOutPoint(f7ccf1e4d6e77bd17387c4e64ed79e17fbd7ffffccd06fdd7ef3c3e490b9d5ee:0),10000 sats,ECPublicKey(02530ee3fd565e59f937e56bda48e9225ea8b09986e6987e6c89afa4930dae7326)),BaseTransaction(Int32Impl(1),Vector(),Vector(TransactionOutput(10000 sats,pkh(76ee004f76fdda7861782f616b6b36d0c3425c71))),UInt32Impl(0)),Vector(Masked(ECPrivateKeyImpl)),SIGHASH_ALL(Int32Impl(1)))</span> <span class="hljs-comment">// utxoInfo: ScriptSignatureParams[P2PKHInputInfo] = ScriptSignatureParams(P2PKHInputInfo(TransactionOutPoint(5e6d204bd5aa3fad3760c66b3cdc77b32fdcefb224a41fdcf5af9a7793abd4b8:0),10000 sats,ECPublicKey(022a992a3bf2b093045485ea8217c1912a636c4cfd50f4361b9b51e3c5a3799ffd)),BaseTransaction(Int32Impl(1),Vector(),Vector(TransactionOutput(10000 sats,pkh(ec2c33f1b36ef6c7d660e125d05754718bf6f1a4))),UInt32Impl(0)),Vector(Masked(ECPrivateKeyImpl)),SIGHASH_ALL(Int32Impl(1)))</span>
<span class="hljs-comment">// all of the UTXO spending information, since we only have</span> <span class="hljs-comment">// all of the UTXO spending information, since we only have</span>
<span class="hljs-comment">// one input, this is just one element</span> <span class="hljs-comment">// one input, this is just one element</span>
<span class="hljs-keyword">val</span> utxoInfos: <span class="hljs-type">Vector</span>[<span class="hljs-type">ScriptSignatureParams</span>[<span class="hljs-type">InputInfo</span>]] = <span class="hljs-type">Vector</span>(utxoInfo) <span class="hljs-keyword">val</span> utxoInfos: <span class="hljs-type">Vector</span>[<span class="hljs-type">ScriptSignatureParams</span>[<span class="hljs-type">InputInfo</span>]] = <span class="hljs-type">Vector</span>(utxoInfo)
<span class="hljs-comment">// utxoInfos: Vector[ScriptSignatureParams[InputInfo]] = Vector(ScriptSignatureParams(P2PKHInputInfo(TransactionOutPoint(f7ccf1e4d6e77bd17387c4e64ed79e17fbd7ffffccd06fdd7ef3c3e490b9d5ee:0),10000 sats,ECPublicKey(02530ee3fd565e59f937e56bda48e9225ea8b09986e6987e6c89afa4930dae7326)),BaseTransaction(Int32Impl(1),Vector(),Vector(TransactionOutput(10000 sats,pkh(76ee004f76fdda7861782f616b6b36d0c3425c71))),UInt32Impl(0)),Vector(Masked(ECPrivateKeyImpl)),SIGHASH_ALL(Int32Impl(1))))</span> <span class="hljs-comment">// utxoInfos: Vector[ScriptSignatureParams[InputInfo]] = Vector(ScriptSignatureParams(P2PKHInputInfo(TransactionOutPoint(5e6d204bd5aa3fad3760c66b3cdc77b32fdcefb224a41fdcf5af9a7793abd4b8:0),10000 sats,ECPublicKey(022a992a3bf2b093045485ea8217c1912a636c4cfd50f4361b9b51e3c5a3799ffd)),BaseTransaction(Int32Impl(1),Vector(),Vector(TransactionOutput(10000 sats,pkh(ec2c33f1b36ef6c7d660e125d05754718bf6f1a4))),UInt32Impl(0)),Vector(Masked(ECPrivateKeyImpl)),SIGHASH_ALL(Int32Impl(1))))</span>
<span class="hljs-comment">// Yay! Now we use the RawTxSigner object to sign the tx.</span> <span class="hljs-comment">// Yay! Now we use the RawTxSigner object to sign the tx.</span>
<span class="hljs-comment">// The &#x27;sign&#x27; method is going produce a validly signed transaction</span> <span class="hljs-comment">// The &#x27;sign&#x27; method is going produce a validly signed transaction</span>
@ -201,7 +201,7 @@ builder += input
} }
<span class="hljs-type">Await</span>.result(signedTxF, <span class="hljs-number">30.</span>seconds) <span class="hljs-type">Await</span>.result(signedTxF, <span class="hljs-number">30.</span>seconds)
} }
<span class="hljs-comment">// signedTx: Transaction = BaseTransaction(Int32Impl(2),Vector(TransactionInputImpl(TransactionOutPoint(f7ccf1e4d6e77bd17387c4e64ed79e17fbd7ffffccd06fdd7ef3c3e490b9d5ee:0),P2PKHScriptSignature(ECPublicKey(02530ee3fd565e59f937e56bda48e9225ea8b09986e6987e6c89afa4930dae7326), ECDigitalSignature(304402205af538c9ab33dcf531c8acb49a6da8849390a6cf0b3d1ccd4a8cd8989062e18e02203dce90afcb95d6605cad4eb60c8026ac5884ccac66c27eeba420191feb112d3e01)),UInt32Impl(0))),Vector(TransactionOutput(5000 sats,pkh(492685e43f739cb5e4ba10fffca6ea92ba5bb501)), TransactionOutput(4775 sats,pkh(e896cc908f35f392ede12450e96f886b1b963c08))),UInt32Impl(0))</span> <span class="hljs-comment">// signedTx: Transaction = BaseTransaction(Int32Impl(2),Vector(TransactionInputImpl(TransactionOutPoint(5e6d204bd5aa3fad3760c66b3cdc77b32fdcefb224a41fdcf5af9a7793abd4b8:0),P2PKHScriptSignature(ECPublicKey(022a992a3bf2b093045485ea8217c1912a636c4cfd50f4361b9b51e3c5a3799ffd), ECDigitalSignature(3044022076f64ffd051890d4fc5f0f5c05bf0bd4dbdac51b0984539fb3a9d05d9b1e51d30220704b82d8f69d2e90da5db98898caed6261f80ac9eedb8369ef1ff269441a039601)),UInt32Impl(0))),Vector(TransactionOutput(5000 sats,pkh(93daee134f71680ea95752cdb7efc19a8b70ba1f)), TransactionOutput(4775 sats,pkh(b531643f691903cd6a8184ab4d3969cfd15a3651))),UInt32Impl(0))</span>
</code></pre> </code></pre>
<pre><code class="hljs css language-scala">signedTx.inputs.length <pre><code class="hljs css language-scala">signedTx.inputs.length
<span class="hljs-comment">// res2: Int = 1</span> <span class="hljs-comment">// res2: Int = 1</span>
@ -211,7 +211,7 @@ signedTx.outputs.length
<span class="hljs-comment">//remember, you can call .hex on any bitcoin-s data structure to get the hex representation!</span> <span class="hljs-comment">//remember, you can call .hex on any bitcoin-s data structure to get the hex representation!</span>
signedTx.hex signedTx.hex
<span class="hljs-comment">// res4: String = 0200000001eed5b990e4c3f37edd6fd0ccffffd7fb179ed74ee6c48773d17be7d6e4f1ccf7000000006a47304402205af538c9ab33dcf531c8acb49a6da8849390a6cf0b3d1ccd4a8cd8989062e18e02203dce90afcb95d6605cad4eb60c8026ac5884ccac66c27eeba420191feb112d3e012102530ee3fd565e59f937e56bda48e9225ea8b09986e6987e6c89afa4930dae7326000000000288130000000000001976a914492685e43f739cb5e4ba10fffca6ea92ba5bb50188aca7120000000000001976a914e896cc908f35f392ede12450e96f886b1b963c0888ac00000000</span> <span class="hljs-comment">// res4: String = 0200000001b8d4ab93779aaff5dc1fa424b2efdc2fb377dc3c6bc66037ad3faad54b206d5e000000006a473044022076f64ffd051890d4fc5f0f5c05bf0bd4dbdac51b0984539fb3a9d05d9b1e51d30220704b82d8f69d2e90da5db98898caed6261f80ac9eedb8369ef1ff269441a03960121022a992a3bf2b093045485ea8217c1912a636c4cfd50f4361b9b51e3c5a3799ffd000000000288130000000000001976a91493daee134f71680ea95752cdb7efc19a8b70ba1f88aca7120000000000001976a914b531643f691903cd6a8184ab4d3969cfd15a365188ac00000000</span>
</code></pre> </code></pre>
</span></div></article></div><div class="docs-prevnext"><a class="docs-prev button" href="/docs/next/core/psbts"><span class="arrow-prev"></span><span>Partially Signed Bitcoin Transactions</span></a><a class="docs-next button" href="/docs/next/core/lightning-network"><span>Lightning Network Data Types</span><span class="arrow-next"></span></a></div></div></div><nav class="onPageNav"></nav></div><footer class="nav-footer" id="footer"><section class="sitemap"><a href="/" class="nav-home"><img src="/img/favicon.ico" alt="bitcoin-s" width="66" height="58"/></a><div><h5>Docs</h5><a href="/docs/en/getting-started">Getting Started</a><a href="/docs/en/core/core-intro">Guides</a><a href="/api/org/bitcoins">API Reference</a></div><div><h5>Community</h5><a href="/en/users.html">User Showcase</a><a href="https://join.slack.com/t/suredbits/shared_invite/zt-eavycu0x-WQL7XOakzQo8tAy7jHHZUw" target="_blank" rel="noreferrer noopener">Slack</a><a href="https://gitter.im/bitcoin-s-core/">Gitter chat</a></div><div><h5>More</h5><a href="https://github.com/bitcoin-s/bitcoin-s">GitHub</a><a class="github-button" href="https://github.com/bitcoin-s/bitcoin-s" data-icon="octicon-star" data-count-href="/bitcoin-s/bitcoin-s-core/stargazers" data-show-count="true" data-count-aria-label="# stargazers on GitHub" aria-label="Star this project on GitHub">Star</a></div></section><section class="copyright">Copyright © 2020 Suredbits &amp; the bitcoin-s developers</section></footer></div><script type="text/javascript" src="https://cdn.jsdelivr.net/docsearch.js/1/docsearch.min.js"></script><script> </span></div></article></div><div class="docs-prevnext"><a class="docs-prev button" href="/docs/next/core/psbts"><span class="arrow-prev"></span><span>Partially Signed Bitcoin Transactions</span></a><a class="docs-next button" href="/docs/next/core/lightning-network"><span>Lightning Network Data Types</span><span class="arrow-next"></span></a></div></div></div><nav class="onPageNav"></nav></div><footer class="nav-footer" id="footer"><section class="sitemap"><a href="/" class="nav-home"><img src="/img/favicon.ico" alt="bitcoin-s" width="66" height="58"/></a><div><h5>Docs</h5><a href="/docs/en/getting-started">Getting Started</a><a href="/docs/en/core/core-intro">Guides</a><a href="/api/org/bitcoins">API Reference</a></div><div><h5>Community</h5><a href="/en/users.html">User Showcase</a><a href="https://join.slack.com/t/suredbits/shared_invite/zt-eavycu0x-WQL7XOakzQo8tAy7jHHZUw" target="_blank" rel="noreferrer noopener">Slack</a><a href="https://gitter.im/bitcoin-s-core/">Gitter chat</a></div><div><h5>More</h5><a href="https://github.com/bitcoin-s/bitcoin-s">GitHub</a><a class="github-button" href="https://github.com/bitcoin-s/bitcoin-s" data-icon="octicon-star" data-count-href="/bitcoin-s/bitcoin-s-core/stargazers" data-show-count="true" data-count-aria-label="# stargazers on GitHub" aria-label="Star this project on GitHub">Star</a></div></section><section class="copyright">Copyright © 2020 Suredbits &amp; the bitcoin-s developers</section></footer></div><script type="text/javascript" src="https://cdn.jsdelivr.net/docsearch.js/1/docsearch.min.js"></script><script>
document.addEventListener('keyup', function(e) { document.addEventListener('keyup', function(e) {

View file

@ -96,13 +96,13 @@
<span class="hljs-comment">// extPrivKey: ExtPrivateKey = Masked(ExtPrivateKeyImpl)</span> <span class="hljs-comment">// extPrivKey: ExtPrivateKey = Masked(ExtPrivateKeyImpl)</span>
extPrivKey.sign(<span class="hljs-type">DoubleSha256Digest</span>.empty.bytes) extPrivKey.sign(<span class="hljs-type">DoubleSha256Digest</span>.empty.bytes)
<span class="hljs-comment">// res0: ECDigitalSignature = ECDigitalSignature(304402207f609e37932fc1b8314311137b899d8f248a02b6419b177b6e7d89502b38301502201eef921872c68c0509c51a5ff1a61d9a56e3e0aa56ea205f6b6f03c1a89747af)</span> <span class="hljs-comment">// res0: ECDigitalSignature = ECDigitalSignature(3045022100b672a52e3ee6901c21c2bf99e9addbb322a2d17bfca8b5dadd937920b08d28a4022040558965dd7ae6e72fa999087c64e688ee2a51d916b992f1f09982cbc016acf8)</span>
<span class="hljs-keyword">val</span> path = <span class="hljs-type">BIP32Path</span>(<span class="hljs-type">Vector</span>(<span class="hljs-type">BIP32Node</span>(<span class="hljs-number">0</span>,<span class="hljs-literal">false</span>))) <span class="hljs-keyword">val</span> path = <span class="hljs-type">BIP32Path</span>(<span class="hljs-type">Vector</span>(<span class="hljs-type">BIP32Node</span>(<span class="hljs-number">0</span>,<span class="hljs-literal">false</span>)))
<span class="hljs-comment">// path: BIP32Path = m/0</span> <span class="hljs-comment">// path: BIP32Path = m/0</span>
extPrivKey.sign(<span class="hljs-type">DoubleSha256Digest</span>.empty.bytes,path) extPrivKey.sign(<span class="hljs-type">DoubleSha256Digest</span>.empty.bytes,path)
<span class="hljs-comment">// res1: ECDigitalSignature = ECDigitalSignature(3045022100d597a70f40dafb63c1a08da7c5185b789a9a3eda334cedcb119055dbacbe429302200149fbbefb15d857e8cbc38c2ebfb032ed9674d2c667425ea1ef0fb9f74920f9)</span> <span class="hljs-comment">// res1: ECDigitalSignature = ECDigitalSignature(3045022100869adf08072d25dd90d9a3034be13f09539b37201f58bedcac0e918b06114a8f022061886010e691adec7d3f49888b428b8687a3df612d468fb648bdbb380a8d93b0)</span>
</code></pre> </code></pre>
<p>With <code>ExtSign</code>, you can use <code>ExtPrivateKey</code> to sign transactions inside of <code>TxBuilder</code> since <code>UTXOSpendingInfo</code> takes in <code>Sign</code> as a parameter.</p> <p>With <code>ExtSign</code>, you can use <code>ExtPrivateKey</code> to sign transactions inside of <code>TxBuilder</code> since <code>UTXOSpendingInfo</code> takes in <code>Sign</code> as a parameter.</p>
<p>You can also provide a <code>path</code> to use to derive a child <code>ExtPrivateKey</code>, and then sign with that child private key</p> <p>You can also provide a <code>path</code> to use to derive a child <code>ExtPrivateKey</code>, and then sign with that child private key</p>

View file

@ -96,13 +96,13 @@
<span class="hljs-comment">// extPrivKey: ExtPrivateKey = Masked(ExtPrivateKeyImpl)</span> <span class="hljs-comment">// extPrivKey: ExtPrivateKey = Masked(ExtPrivateKeyImpl)</span>
extPrivKey.sign(<span class="hljs-type">DoubleSha256Digest</span>.empty.bytes) extPrivKey.sign(<span class="hljs-type">DoubleSha256Digest</span>.empty.bytes)
<span class="hljs-comment">// res0: ECDigitalSignature = ECDigitalSignature(304402207f609e37932fc1b8314311137b899d8f248a02b6419b177b6e7d89502b38301502201eef921872c68c0509c51a5ff1a61d9a56e3e0aa56ea205f6b6f03c1a89747af)</span> <span class="hljs-comment">// res0: ECDigitalSignature = ECDigitalSignature(3045022100b672a52e3ee6901c21c2bf99e9addbb322a2d17bfca8b5dadd937920b08d28a4022040558965dd7ae6e72fa999087c64e688ee2a51d916b992f1f09982cbc016acf8)</span>
<span class="hljs-keyword">val</span> path = <span class="hljs-type">BIP32Path</span>(<span class="hljs-type">Vector</span>(<span class="hljs-type">BIP32Node</span>(<span class="hljs-number">0</span>,<span class="hljs-literal">false</span>))) <span class="hljs-keyword">val</span> path = <span class="hljs-type">BIP32Path</span>(<span class="hljs-type">Vector</span>(<span class="hljs-type">BIP32Node</span>(<span class="hljs-number">0</span>,<span class="hljs-literal">false</span>)))
<span class="hljs-comment">// path: BIP32Path = m/0</span> <span class="hljs-comment">// path: BIP32Path = m/0</span>
extPrivKey.sign(<span class="hljs-type">DoubleSha256Digest</span>.empty.bytes,path) extPrivKey.sign(<span class="hljs-type">DoubleSha256Digest</span>.empty.bytes,path)
<span class="hljs-comment">// res1: ECDigitalSignature = ECDigitalSignature(3045022100d597a70f40dafb63c1a08da7c5185b789a9a3eda334cedcb119055dbacbe429302200149fbbefb15d857e8cbc38c2ebfb032ed9674d2c667425ea1ef0fb9f74920f9)</span> <span class="hljs-comment">// res1: ECDigitalSignature = ECDigitalSignature(3045022100869adf08072d25dd90d9a3034be13f09539b37201f58bedcac0e918b06114a8f022061886010e691adec7d3f49888b428b8687a3df612d468fb648bdbb380a8d93b0)</span>
</code></pre> </code></pre>
<p>With <code>ExtSign</code>, you can use <code>ExtPrivateKey</code> to sign transactions inside of <code>TxBuilder</code> since <code>UTXOSpendingInfo</code> takes in <code>Sign</code> as a parameter.</p> <p>With <code>ExtSign</code>, you can use <code>ExtPrivateKey</code> to sign transactions inside of <code>TxBuilder</code> since <code>UTXOSpendingInfo</code> takes in <code>Sign</code> as a parameter.</p>
<p>You can also provide a <code>path</code> to use to derive a child <code>ExtPrivateKey</code>, and then sign with that child private key</p> <p>You can also provide a <code>path</code> to use to derive a child <code>ExtPrivateKey</code>, and then sign with that child private key</p>

View file

@ -120,7 +120,7 @@ libraryDependencies += <span class="hljs-string">&quot;org.bitcoin-s&quot;</span
<h3><a class="anchor" aria-hidden="true" id="nightly-builds"></a><a href="#nightly-builds" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Nightly builds</h3> <h3><a class="anchor" aria-hidden="true" id="nightly-builds"></a><a href="#nightly-builds" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Nightly builds</h3>
<p>You can also run on the bleeding edge of Bitcoin-S, by <p>You can also run on the bleeding edge of Bitcoin-S, by
adding a snapshot build to your <code>build.sbt</code>. The most adding a snapshot build to your <code>build.sbt</code>. The most
recent snapshot published is <code>0.4.0+174-bb4a2667-SNAPSHOT</code>.</p> recent snapshot published is <code>0.4.0+175-905491fe-SNAPSHOT</code>.</p>
<p>To fetch snapshots, you will need to add the correct <p>To fetch snapshots, you will need to add the correct
resolver in your <code>build.sbt</code>:</p> resolver in your <code>build.sbt</code>:</p>
<pre><code class="hljs css language-sbt">resolvers += Resolver.sonatypeRepo(<span class="hljs-string">&quot;snapshots&quot;</span>) <pre><code class="hljs css language-sbt">resolvers += Resolver.sonatypeRepo(<span class="hljs-string">&quot;snapshots&quot;</span>)

View file

@ -120,7 +120,7 @@ libraryDependencies += <span class="hljs-string">&quot;org.bitcoin-s&quot;</span
<h3><a class="anchor" aria-hidden="true" id="nightly-builds"></a><a href="#nightly-builds" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Nightly builds</h3> <h3><a class="anchor" aria-hidden="true" id="nightly-builds"></a><a href="#nightly-builds" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Nightly builds</h3>
<p>You can also run on the bleeding edge of Bitcoin-S, by <p>You can also run on the bleeding edge of Bitcoin-S, by
adding a snapshot build to your <code>build.sbt</code>. The most adding a snapshot build to your <code>build.sbt</code>. The most
recent snapshot published is <code>0.4.0+174-bb4a2667-SNAPSHOT</code>.</p> recent snapshot published is <code>0.4.0+175-905491fe-SNAPSHOT</code>.</p>
<p>To fetch snapshots, you will need to add the correct <p>To fetch snapshots, you will need to add the correct
resolver in your <code>build.sbt</code>:</p> resolver in your <code>build.sbt</code>:</p>
<pre><code class="hljs css language-sbt">resolvers += Resolver.sonatypeRepo(<span class="hljs-string">&quot;snapshots&quot;</span>) <pre><code class="hljs css language-sbt">resolvers += Resolver.sonatypeRepo(<span class="hljs-string">&quot;snapshots&quot;</span>)

View file

@ -77,14 +77,14 @@
<span class="hljs-comment">//get 256 bits of random entropy</span> <span class="hljs-comment">//get 256 bits of random entropy</span>
<span class="hljs-keyword">val</span> entropy = <span class="hljs-type">MnemonicCode</span>.getEntropy256Bits <span class="hljs-keyword">val</span> entropy = <span class="hljs-type">MnemonicCode</span>.getEntropy256Bits
<span class="hljs-comment">// entropy: scodec.bits.BitVector = BitVector(256 bits, 0x66f2c129c5b635645a63c2accc681175c8166a4085d3d7e4c6e77bc995ed3cbb)</span> <span class="hljs-comment">// entropy: scodec.bits.BitVector = BitVector(256 bits, 0xc03cbb1200a9a0f8dab2036107d8d6ba7f31f4dae9e3a3eaa332b898cde29694)</span>
<span class="hljs-keyword">val</span> mnemonic = <span class="hljs-type">MnemonicCode</span>.fromEntropy(entropy) <span class="hljs-keyword">val</span> mnemonic = <span class="hljs-type">MnemonicCode</span>.fromEntropy(entropy)
<span class="hljs-comment">// mnemonic: MnemonicCode = Masked(MnemonicCodeImpl)</span> <span class="hljs-comment">// mnemonic: MnemonicCode = Masked(MnemonicCodeImpl)</span>
<span class="hljs-comment">//you can print that mnemonic seed with this</span> <span class="hljs-comment">//you can print that mnemonic seed with this</span>
println(mnemonic.words) println(mnemonic.words)
<span class="hljs-comment">// Vector(group, noodle, engine, merge, globe, rate, hat, joke, proud, globe, affair, twist, lift, cry, acoustic, risk, subject, change, right, wasp, off, walk, very, issue)</span> <span class="hljs-comment">// Vector(scan, total, setup, access, old, ladder, hello, document, genre, disagree, cup, insane, vessel, whip, hill, detect, physical, fence, smile, illness, mimic, vanish, fog, lyrics)</span>
</code></pre> </code></pre>
<p>Now that we have a <code>MnemonicCode</code> that was securely generated, we need to now create <code>KeyManagerParams</code> which tells us how to generate <p>Now that we have a <code>MnemonicCode</code> that was securely generated, we need to now create <code>KeyManagerParams</code> which tells us how to generate
generate specific kinds of addresses for wallets.</p> generate specific kinds of addresses for wallets.</p>
@ -99,7 +99,7 @@ generate specific kinds of addresses for wallets.</p>
<pre><code class="hljs css language-scala"><span class="hljs-comment">//this will create a temp directory with the prefix &#x27;key-manager-example` that will</span> <pre><code class="hljs css language-scala"><span class="hljs-comment">//this will create a temp directory with the prefix &#x27;key-manager-example` that will</span>
<span class="hljs-comment">//have a file in it called &quot;encrypted-bitcoin-s-seed.json&quot;</span> <span class="hljs-comment">//have a file in it called &quot;encrypted-bitcoin-s-seed.json&quot;</span>
<span class="hljs-keyword">val</span> seedPath = <span class="hljs-type">Files</span>.createTempDirectory(<span class="hljs-string">&quot;key-manager-example&quot;</span>).resolve(<span class="hljs-type">WalletStorage</span>.<span class="hljs-type">ENCRYPTED_SEED_FILE_NAME</span>) <span class="hljs-keyword">val</span> seedPath = <span class="hljs-type">Files</span>.createTempDirectory(<span class="hljs-string">&quot;key-manager-example&quot;</span>).resolve(<span class="hljs-type">WalletStorage</span>.<span class="hljs-type">ENCRYPTED_SEED_FILE_NAME</span>)
<span class="hljs-comment">// seedPath: Path = /tmp/key-manager-example6042123096565278199/encrypted-bitcoin-s-seed.json</span> <span class="hljs-comment">// seedPath: Path = /tmp/key-manager-example645851460867555165/encrypted-bitcoin-s-seed.json</span>
<span class="hljs-comment">//let&#x27;s create a native segwit key manager</span> <span class="hljs-comment">//let&#x27;s create a native segwit key manager</span>
<span class="hljs-keyword">val</span> purpose = <span class="hljs-type">HDPurposes</span>.<span class="hljs-type">SegWit</span> <span class="hljs-keyword">val</span> purpose = <span class="hljs-type">HDPurposes</span>.<span class="hljs-type">SegWit</span>
@ -110,19 +110,19 @@ generate specific kinds of addresses for wallets.</p>
<span class="hljs-comment">// network: RegTest.type = RegTest</span> <span class="hljs-comment">// network: RegTest.type = RegTest</span>
<span class="hljs-keyword">val</span> kmParams = <span class="hljs-type">KeyManagerParams</span>(seedPath, purpose, network) <span class="hljs-keyword">val</span> kmParams = <span class="hljs-type">KeyManagerParams</span>(seedPath, purpose, network)
<span class="hljs-comment">// kmParams: KeyManagerParams = KeyManagerParams(/tmp/key-manager-example6042123096565278199/encrypted-bitcoin-s-seed.json,m/84&#x27;,RegTest)</span> <span class="hljs-comment">// kmParams: KeyManagerParams = KeyManagerParams(/tmp/key-manager-example645851460867555165/encrypted-bitcoin-s-seed.json,m/84&#x27;,RegTest)</span>
<span class="hljs-keyword">val</span> aesPasswordOpt = <span class="hljs-type">Some</span>(<span class="hljs-type">AesPassword</span>.fromString(<span class="hljs-string">&quot;password&quot;</span>)) <span class="hljs-keyword">val</span> aesPasswordOpt = <span class="hljs-type">Some</span>(<span class="hljs-type">AesPassword</span>.fromString(<span class="hljs-string">&quot;password&quot;</span>))
<span class="hljs-comment">// aesPasswordOpt: Some[AesPassword] = Some(Masked(AesPassword))</span> <span class="hljs-comment">// aesPasswordOpt: Some[AesPassword] = Some(Masked(AesPassword))</span>
<span class="hljs-keyword">val</span> km = <span class="hljs-type">BIP39KeyManager</span>.initializeWithMnemonic(aesPasswordOpt, mnemonic, <span class="hljs-type">None</span>, kmParams) <span class="hljs-keyword">val</span> km = <span class="hljs-type">BIP39KeyManager</span>.initializeWithMnemonic(aesPasswordOpt, mnemonic, <span class="hljs-type">None</span>, kmParams)
<span class="hljs-comment">// km: Either[KeyManagerInitializeError, BIP39KeyManager] = Right(org.bitcoins.keymanager.bip39.BIP39KeyManager@73ec27ea)</span> <span class="hljs-comment">// km: Either[KeyManagerInitializeError, BIP39KeyManager] = Right(org.bitcoins.keymanager.bip39.BIP39KeyManager@3e07d000)</span>
<span class="hljs-keyword">val</span> rootXPub = km.right.get.getRootXPub <span class="hljs-keyword">val</span> rootXPub = km.right.get.getRootXPub
<span class="hljs-comment">// rootXPub: ExtPublicKey = vpub5SLqN2bLY4WeYTgZ5MHSR96Djq66aXTzfKU6RWn6DVcchkLRWCGrak9FByHmXwdXsCtjtmAMyzgBLCSqg2secQE67ABm74QvSWfh8UBtkKj</span> <span class="hljs-comment">// rootXPub: ExtPublicKey = vpub5SLqN2bLY4WeaRaCAmcXVtJioJdYgy5qkxPfMtqbaH9JRaZ5s6FiY2DzgBBtfmYNUKa6R5CL6K7buRd1Kn6vFGppiV66AdpMU6esL25yZVK</span>
println(rootXPub) println(rootXPub)
<span class="hljs-comment">// vpub5SLqN2bLY4WeYTgZ5MHSR96Djq66aXTzfKU6RWn6DVcchkLRWCGrak9FByHmXwdXsCtjtmAMyzgBLCSqg2secQE67ABm74QvSWfh8UBtkKj</span> <span class="hljs-comment">// vpub5SLqN2bLY4WeaRaCAmcXVtJioJdYgy5qkxPfMtqbaH9JRaZ5s6FiY2DzgBBtfmYNUKa6R5CL6K7buRd1Kn6vFGppiV66AdpMU6esL25yZVK</span>
</code></pre> </code></pre>
<p>Which should print something that looks like this</p> <p>Which should print something that looks like this</p>
<p><code>vpub5SLqN2bLY4WeXxMqwJHJFBEwxSscGB2uDUnsTS3edVjZEwTrQDFDNqoR2xLqARQPabGaXsHSTenTRcqm2EnB9MpuC4vSk3LqSgNmGGZtuq7</code></p> <p><code>vpub5SLqN2bLY4WeXxMqwJHJFBEwxSscGB2uDUnsTS3edVjZEwTrQDFDNqoR2xLqARQPabGaXsHSTenTRcqm2EnB9MpuC4vSk3LqSgNmGGZtuq7</code></p>
@ -131,17 +131,17 @@ println(rootXPub)
again after initializing it once. You can use the same <code>mnemonic</code> for different networks, which you control <code>KeyManagerParams</code>.</p> again after initializing it once. You can use the same <code>mnemonic</code> for different networks, which you control <code>KeyManagerParams</code>.</p>
<pre><code class="hljs css language-scala"><span class="hljs-comment">//let&#x27;s create a nested segwit key manager for mainnet</span> <pre><code class="hljs css language-scala"><span class="hljs-comment">//let&#x27;s create a nested segwit key manager for mainnet</span>
<span class="hljs-keyword">val</span> mainnetKmParams = <span class="hljs-type">KeyManagerParams</span>(seedPath, <span class="hljs-type">HDPurposes</span>.<span class="hljs-type">SegWit</span>, <span class="hljs-type">MainNet</span>) <span class="hljs-keyword">val</span> mainnetKmParams = <span class="hljs-type">KeyManagerParams</span>(seedPath, <span class="hljs-type">HDPurposes</span>.<span class="hljs-type">SegWit</span>, <span class="hljs-type">MainNet</span>)
<span class="hljs-comment">// mainnetKmParams: KeyManagerParams = KeyManagerParams(/tmp/key-manager-example6042123096565278199/encrypted-bitcoin-s-seed.json,m/84&#x27;,MainNet)</span> <span class="hljs-comment">// mainnetKmParams: KeyManagerParams = KeyManagerParams(/tmp/key-manager-example645851460867555165/encrypted-bitcoin-s-seed.json,m/84&#x27;,MainNet)</span>
<span class="hljs-comment">//we do not need to all `initializeWithMnemonic()` again as we have saved the seed to dis</span> <span class="hljs-comment">//we do not need to all `initializeWithMnemonic()` again as we have saved the seed to dis</span>
<span class="hljs-keyword">val</span> mainnetKeyManager = <span class="hljs-type">BIP39KeyManager</span>.fromMnemonic(mnemonic, mainnetKmParams, <span class="hljs-type">None</span>, <span class="hljs-type">Instant</span>.now) <span class="hljs-keyword">val</span> mainnetKeyManager = <span class="hljs-type">BIP39KeyManager</span>.fromMnemonic(mnemonic, mainnetKmParams, <span class="hljs-type">None</span>, <span class="hljs-type">Instant</span>.now)
<span class="hljs-comment">// mainnetKeyManager: BIP39KeyManager = org.bitcoins.keymanager.bip39.BIP39KeyManager@3cfd0c7a</span> <span class="hljs-comment">// mainnetKeyManager: BIP39KeyManager = org.bitcoins.keymanager.bip39.BIP39KeyManager@35d1951</span>
<span class="hljs-keyword">val</span> mainnetXpub = mainnetKeyManager.getRootXPub <span class="hljs-keyword">val</span> mainnetXpub = mainnetKeyManager.getRootXPub
<span class="hljs-comment">// mainnetXpub: ExtPublicKey = zpub6jftahH18ngZweT2QnRwFVUERhftM1RzKmYyZ6MdjX88v9bLWpw74zmoGo87XaFDVmMxtfYbpe6NsLu6YpXhoLxVaWyTShgsXQvGgmaGory</span> <span class="hljs-comment">// mainnetXpub: ExtPublicKey = zpub6jftahH18ngZycLfWCm2LEgjVBDLTT3qRQUYVUR96Jepdyozsiuy2GrYm12EfQA46t3KQyaZvxXoSa5GCZkySDZEBqsnWH6JYzuStN28h2B</span>
println(mainnetXpub) println(mainnetXpub)
<span class="hljs-comment">// zpub6jftahH18ngZweT2QnRwFVUERhftM1RzKmYyZ6MdjX88v9bLWpw74zmoGo87XaFDVmMxtfYbpe6NsLu6YpXhoLxVaWyTShgsXQvGgmaGory</span> <span class="hljs-comment">// zpub6jftahH18ngZycLfWCm2LEgjVBDLTT3qRQUYVUR96Jepdyozsiuy2GrYm12EfQA46t3KQyaZvxXoSa5GCZkySDZEBqsnWH6JYzuStN28h2B</span>
</code></pre> </code></pre>
<p>Which gives us something that looks like this</p> <p>Which gives us something that looks like this</p>
<p><code>zpub6jftahH18ngZw98KGjRo5XcxeKTQ2eztsvskb1dC9XF5TLimQquTs6Ry7nBBA425D9joXmfgJJCexmJ1u2SELJZJfRi95gcnXadLpZzYb5c</code></p> <p><code>zpub6jftahH18ngZw98KGjRo5XcxeKTQ2eztsvskb1dC9XF5TLimQquTs6Ry7nBBA425D9joXmfgJJCexmJ1u2SELJZJfRi95gcnXadLpZzYb5c</code></p>

View file

@ -77,14 +77,14 @@
<span class="hljs-comment">//get 256 bits of random entropy</span> <span class="hljs-comment">//get 256 bits of random entropy</span>
<span class="hljs-keyword">val</span> entropy = <span class="hljs-type">MnemonicCode</span>.getEntropy256Bits <span class="hljs-keyword">val</span> entropy = <span class="hljs-type">MnemonicCode</span>.getEntropy256Bits
<span class="hljs-comment">// entropy: scodec.bits.BitVector = BitVector(256 bits, 0x66f2c129c5b635645a63c2accc681175c8166a4085d3d7e4c6e77bc995ed3cbb)</span> <span class="hljs-comment">// entropy: scodec.bits.BitVector = BitVector(256 bits, 0xc03cbb1200a9a0f8dab2036107d8d6ba7f31f4dae9e3a3eaa332b898cde29694)</span>
<span class="hljs-keyword">val</span> mnemonic = <span class="hljs-type">MnemonicCode</span>.fromEntropy(entropy) <span class="hljs-keyword">val</span> mnemonic = <span class="hljs-type">MnemonicCode</span>.fromEntropy(entropy)
<span class="hljs-comment">// mnemonic: MnemonicCode = Masked(MnemonicCodeImpl)</span> <span class="hljs-comment">// mnemonic: MnemonicCode = Masked(MnemonicCodeImpl)</span>
<span class="hljs-comment">//you can print that mnemonic seed with this</span> <span class="hljs-comment">//you can print that mnemonic seed with this</span>
println(mnemonic.words) println(mnemonic.words)
<span class="hljs-comment">// Vector(group, noodle, engine, merge, globe, rate, hat, joke, proud, globe, affair, twist, lift, cry, acoustic, risk, subject, change, right, wasp, off, walk, very, issue)</span> <span class="hljs-comment">// Vector(scan, total, setup, access, old, ladder, hello, document, genre, disagree, cup, insane, vessel, whip, hill, detect, physical, fence, smile, illness, mimic, vanish, fog, lyrics)</span>
</code></pre> </code></pre>
<p>Now that we have a <code>MnemonicCode</code> that was securely generated, we need to now create <code>KeyManagerParams</code> which tells us how to generate <p>Now that we have a <code>MnemonicCode</code> that was securely generated, we need to now create <code>KeyManagerParams</code> which tells us how to generate
generate specific kinds of addresses for wallets.</p> generate specific kinds of addresses for wallets.</p>
@ -99,7 +99,7 @@ generate specific kinds of addresses for wallets.</p>
<pre><code class="hljs css language-scala"><span class="hljs-comment">//this will create a temp directory with the prefix &#x27;key-manager-example` that will</span> <pre><code class="hljs css language-scala"><span class="hljs-comment">//this will create a temp directory with the prefix &#x27;key-manager-example` that will</span>
<span class="hljs-comment">//have a file in it called &quot;encrypted-bitcoin-s-seed.json&quot;</span> <span class="hljs-comment">//have a file in it called &quot;encrypted-bitcoin-s-seed.json&quot;</span>
<span class="hljs-keyword">val</span> seedPath = <span class="hljs-type">Files</span>.createTempDirectory(<span class="hljs-string">&quot;key-manager-example&quot;</span>).resolve(<span class="hljs-type">WalletStorage</span>.<span class="hljs-type">ENCRYPTED_SEED_FILE_NAME</span>) <span class="hljs-keyword">val</span> seedPath = <span class="hljs-type">Files</span>.createTempDirectory(<span class="hljs-string">&quot;key-manager-example&quot;</span>).resolve(<span class="hljs-type">WalletStorage</span>.<span class="hljs-type">ENCRYPTED_SEED_FILE_NAME</span>)
<span class="hljs-comment">// seedPath: Path = /tmp/key-manager-example6042123096565278199/encrypted-bitcoin-s-seed.json</span> <span class="hljs-comment">// seedPath: Path = /tmp/key-manager-example645851460867555165/encrypted-bitcoin-s-seed.json</span>
<span class="hljs-comment">//let&#x27;s create a native segwit key manager</span> <span class="hljs-comment">//let&#x27;s create a native segwit key manager</span>
<span class="hljs-keyword">val</span> purpose = <span class="hljs-type">HDPurposes</span>.<span class="hljs-type">SegWit</span> <span class="hljs-keyword">val</span> purpose = <span class="hljs-type">HDPurposes</span>.<span class="hljs-type">SegWit</span>
@ -110,19 +110,19 @@ generate specific kinds of addresses for wallets.</p>
<span class="hljs-comment">// network: RegTest.type = RegTest</span> <span class="hljs-comment">// network: RegTest.type = RegTest</span>
<span class="hljs-keyword">val</span> kmParams = <span class="hljs-type">KeyManagerParams</span>(seedPath, purpose, network) <span class="hljs-keyword">val</span> kmParams = <span class="hljs-type">KeyManagerParams</span>(seedPath, purpose, network)
<span class="hljs-comment">// kmParams: KeyManagerParams = KeyManagerParams(/tmp/key-manager-example6042123096565278199/encrypted-bitcoin-s-seed.json,m/84&#x27;,RegTest)</span> <span class="hljs-comment">// kmParams: KeyManagerParams = KeyManagerParams(/tmp/key-manager-example645851460867555165/encrypted-bitcoin-s-seed.json,m/84&#x27;,RegTest)</span>
<span class="hljs-keyword">val</span> aesPasswordOpt = <span class="hljs-type">Some</span>(<span class="hljs-type">AesPassword</span>.fromString(<span class="hljs-string">&quot;password&quot;</span>)) <span class="hljs-keyword">val</span> aesPasswordOpt = <span class="hljs-type">Some</span>(<span class="hljs-type">AesPassword</span>.fromString(<span class="hljs-string">&quot;password&quot;</span>))
<span class="hljs-comment">// aesPasswordOpt: Some[AesPassword] = Some(Masked(AesPassword))</span> <span class="hljs-comment">// aesPasswordOpt: Some[AesPassword] = Some(Masked(AesPassword))</span>
<span class="hljs-keyword">val</span> km = <span class="hljs-type">BIP39KeyManager</span>.initializeWithMnemonic(aesPasswordOpt, mnemonic, <span class="hljs-type">None</span>, kmParams) <span class="hljs-keyword">val</span> km = <span class="hljs-type">BIP39KeyManager</span>.initializeWithMnemonic(aesPasswordOpt, mnemonic, <span class="hljs-type">None</span>, kmParams)
<span class="hljs-comment">// km: Either[KeyManagerInitializeError, BIP39KeyManager] = Right(org.bitcoins.keymanager.bip39.BIP39KeyManager@73ec27ea)</span> <span class="hljs-comment">// km: Either[KeyManagerInitializeError, BIP39KeyManager] = Right(org.bitcoins.keymanager.bip39.BIP39KeyManager@3e07d000)</span>
<span class="hljs-keyword">val</span> rootXPub = km.right.get.getRootXPub <span class="hljs-keyword">val</span> rootXPub = km.right.get.getRootXPub
<span class="hljs-comment">// rootXPub: ExtPublicKey = vpub5SLqN2bLY4WeYTgZ5MHSR96Djq66aXTzfKU6RWn6DVcchkLRWCGrak9FByHmXwdXsCtjtmAMyzgBLCSqg2secQE67ABm74QvSWfh8UBtkKj</span> <span class="hljs-comment">// rootXPub: ExtPublicKey = vpub5SLqN2bLY4WeaRaCAmcXVtJioJdYgy5qkxPfMtqbaH9JRaZ5s6FiY2DzgBBtfmYNUKa6R5CL6K7buRd1Kn6vFGppiV66AdpMU6esL25yZVK</span>
println(rootXPub) println(rootXPub)
<span class="hljs-comment">// vpub5SLqN2bLY4WeYTgZ5MHSR96Djq66aXTzfKU6RWn6DVcchkLRWCGrak9FByHmXwdXsCtjtmAMyzgBLCSqg2secQE67ABm74QvSWfh8UBtkKj</span> <span class="hljs-comment">// vpub5SLqN2bLY4WeaRaCAmcXVtJioJdYgy5qkxPfMtqbaH9JRaZ5s6FiY2DzgBBtfmYNUKa6R5CL6K7buRd1Kn6vFGppiV66AdpMU6esL25yZVK</span>
</code></pre> </code></pre>
<p>Which should print something that looks like this</p> <p>Which should print something that looks like this</p>
<p><code>vpub5SLqN2bLY4WeXxMqwJHJFBEwxSscGB2uDUnsTS3edVjZEwTrQDFDNqoR2xLqARQPabGaXsHSTenTRcqm2EnB9MpuC4vSk3LqSgNmGGZtuq7</code></p> <p><code>vpub5SLqN2bLY4WeXxMqwJHJFBEwxSscGB2uDUnsTS3edVjZEwTrQDFDNqoR2xLqARQPabGaXsHSTenTRcqm2EnB9MpuC4vSk3LqSgNmGGZtuq7</code></p>
@ -131,17 +131,17 @@ println(rootXPub)
again after initializing it once. You can use the same <code>mnemonic</code> for different networks, which you control <code>KeyManagerParams</code>.</p> again after initializing it once. You can use the same <code>mnemonic</code> for different networks, which you control <code>KeyManagerParams</code>.</p>
<pre><code class="hljs css language-scala"><span class="hljs-comment">//let&#x27;s create a nested segwit key manager for mainnet</span> <pre><code class="hljs css language-scala"><span class="hljs-comment">//let&#x27;s create a nested segwit key manager for mainnet</span>
<span class="hljs-keyword">val</span> mainnetKmParams = <span class="hljs-type">KeyManagerParams</span>(seedPath, <span class="hljs-type">HDPurposes</span>.<span class="hljs-type">SegWit</span>, <span class="hljs-type">MainNet</span>) <span class="hljs-keyword">val</span> mainnetKmParams = <span class="hljs-type">KeyManagerParams</span>(seedPath, <span class="hljs-type">HDPurposes</span>.<span class="hljs-type">SegWit</span>, <span class="hljs-type">MainNet</span>)
<span class="hljs-comment">// mainnetKmParams: KeyManagerParams = KeyManagerParams(/tmp/key-manager-example6042123096565278199/encrypted-bitcoin-s-seed.json,m/84&#x27;,MainNet)</span> <span class="hljs-comment">// mainnetKmParams: KeyManagerParams = KeyManagerParams(/tmp/key-manager-example645851460867555165/encrypted-bitcoin-s-seed.json,m/84&#x27;,MainNet)</span>
<span class="hljs-comment">//we do not need to all `initializeWithMnemonic()` again as we have saved the seed to dis</span> <span class="hljs-comment">//we do not need to all `initializeWithMnemonic()` again as we have saved the seed to dis</span>
<span class="hljs-keyword">val</span> mainnetKeyManager = <span class="hljs-type">BIP39KeyManager</span>.fromMnemonic(mnemonic, mainnetKmParams, <span class="hljs-type">None</span>, <span class="hljs-type">Instant</span>.now) <span class="hljs-keyword">val</span> mainnetKeyManager = <span class="hljs-type">BIP39KeyManager</span>.fromMnemonic(mnemonic, mainnetKmParams, <span class="hljs-type">None</span>, <span class="hljs-type">Instant</span>.now)
<span class="hljs-comment">// mainnetKeyManager: BIP39KeyManager = org.bitcoins.keymanager.bip39.BIP39KeyManager@3cfd0c7a</span> <span class="hljs-comment">// mainnetKeyManager: BIP39KeyManager = org.bitcoins.keymanager.bip39.BIP39KeyManager@35d1951</span>
<span class="hljs-keyword">val</span> mainnetXpub = mainnetKeyManager.getRootXPub <span class="hljs-keyword">val</span> mainnetXpub = mainnetKeyManager.getRootXPub
<span class="hljs-comment">// mainnetXpub: ExtPublicKey = zpub6jftahH18ngZweT2QnRwFVUERhftM1RzKmYyZ6MdjX88v9bLWpw74zmoGo87XaFDVmMxtfYbpe6NsLu6YpXhoLxVaWyTShgsXQvGgmaGory</span> <span class="hljs-comment">// mainnetXpub: ExtPublicKey = zpub6jftahH18ngZycLfWCm2LEgjVBDLTT3qRQUYVUR96Jepdyozsiuy2GrYm12EfQA46t3KQyaZvxXoSa5GCZkySDZEBqsnWH6JYzuStN28h2B</span>
println(mainnetXpub) println(mainnetXpub)
<span class="hljs-comment">// zpub6jftahH18ngZweT2QnRwFVUERhftM1RzKmYyZ6MdjX88v9bLWpw74zmoGo87XaFDVmMxtfYbpe6NsLu6YpXhoLxVaWyTShgsXQvGgmaGory</span> <span class="hljs-comment">// zpub6jftahH18ngZycLfWCm2LEgjVBDLTT3qRQUYVUR96Jepdyozsiuy2GrYm12EfQA46t3KQyaZvxXoSa5GCZkySDZEBqsnWH6JYzuStN28h2B</span>
</code></pre> </code></pre>
<p>Which gives us something that looks like this</p> <p>Which gives us something that looks like this</p>
<p><code>zpub6jftahH18ngZw98KGjRo5XcxeKTQ2eztsvskb1dC9XF5TLimQquTs6Ry7nBBA425D9joXmfgJJCexmJ1u2SELJZJfRi95gcnXadLpZzYb5c</code></p> <p><code>zpub6jftahH18ngZw98KGjRo5XcxeKTQ2eztsvskb1dC9XF5TLimQquTs6Ry7nBBA425D9joXmfgJJCexmJ1u2SELJZJfRi95gcnXadLpZzYb5c</code></p>

View file

@ -114,12 +114,12 @@ println(<span class="hljs-string">s&quot;Verified with NativeSecp256k1 again=<sp
<pre><code class="hljs css language-scala"><span class="hljs-keyword">val</span> privKey = <span class="hljs-type">ECPrivateKey</span>.freshPrivateKey <pre><code class="hljs css language-scala"><span class="hljs-keyword">val</span> privKey = <span class="hljs-type">ECPrivateKey</span>.freshPrivateKey
<span class="hljs-comment">// privKey: ECPrivateKey = Masked(ECPrivateKeyImpl)</span> <span class="hljs-comment">// privKey: ECPrivateKey = Masked(ECPrivateKeyImpl)</span>
<span class="hljs-keyword">val</span> publicKey = privKey.publicKeyWithBouncyCastle <span class="hljs-keyword">val</span> publicKey = privKey.publicKeyWithBouncyCastle
<span class="hljs-comment">// publicKey: ECPublicKey = ECPublicKey(0296c11742dddfdaa8a3d129f7db34b6699563f34693d69060bc8f35a113cc28df)</span> <span class="hljs-comment">// publicKey: ECPublicKey = ECPublicKey(027f4681a183c88cb43a8d120438ba827277e84f9215c454f83c9db631aa32cacf)</span>
<span class="hljs-keyword">val</span> dataToSign = <span class="hljs-type">DoubleSha256Digest</span>.empty <span class="hljs-keyword">val</span> dataToSign = <span class="hljs-type">DoubleSha256Digest</span>.empty
<span class="hljs-comment">// dataToSign: DoubleSha256Digest = DoubleSha256Digest(0000000000000000000000000000000000000000000000000000000000000000)</span> <span class="hljs-comment">// dataToSign: DoubleSha256Digest = DoubleSha256Digest(0000000000000000000000000000000000000000000000000000000000000000)</span>
<span class="hljs-keyword">val</span> signature = privKey.signWithBouncyCastle(dataToSign.bytes) <span class="hljs-keyword">val</span> signature = privKey.signWithBouncyCastle(dataToSign.bytes)
<span class="hljs-comment">// signature: ECDigitalSignature = ECDigitalSignature(304402202db5633feb909407dec71ab7db5787ddfd60c748c1f32f9e7dfebf4edd4e7f660220759bdeda9f3d8131b1f45994c94762b8cf1c1167ad61ef56ee614a2817c19e60)</span> <span class="hljs-comment">// signature: ECDigitalSignature = ECDigitalSignature(304402201b5ec60501e433a1f57cc347391bd10a02af21d5ac9c80f9905c6d1f51d7de9b02207b901f1a010afcbe1f07ded25cf8e33cca5e53e645076aa6bd4f8cbcdec186be)</span>
<span class="hljs-keyword">val</span> verified = publicKey.verifyWithBouncyCastle(dataToSign.bytes, signature) <span class="hljs-keyword">val</span> verified = publicKey.verifyWithBouncyCastle(dataToSign.bytes, signature)
<span class="hljs-comment">// verified: Boolean = true</span> <span class="hljs-comment">// verified: Boolean = true</span>

View file

@ -114,12 +114,12 @@ println(<span class="hljs-string">s&quot;Verified with NativeSecp256k1 again=<sp
<pre><code class="hljs css language-scala"><span class="hljs-keyword">val</span> privKey = <span class="hljs-type">ECPrivateKey</span>.freshPrivateKey <pre><code class="hljs css language-scala"><span class="hljs-keyword">val</span> privKey = <span class="hljs-type">ECPrivateKey</span>.freshPrivateKey
<span class="hljs-comment">// privKey: ECPrivateKey = Masked(ECPrivateKeyImpl)</span> <span class="hljs-comment">// privKey: ECPrivateKey = Masked(ECPrivateKeyImpl)</span>
<span class="hljs-keyword">val</span> publicKey = privKey.publicKeyWithBouncyCastle <span class="hljs-keyword">val</span> publicKey = privKey.publicKeyWithBouncyCastle
<span class="hljs-comment">// publicKey: ECPublicKey = ECPublicKey(0296c11742dddfdaa8a3d129f7db34b6699563f34693d69060bc8f35a113cc28df)</span> <span class="hljs-comment">// publicKey: ECPublicKey = ECPublicKey(027f4681a183c88cb43a8d120438ba827277e84f9215c454f83c9db631aa32cacf)</span>
<span class="hljs-keyword">val</span> dataToSign = <span class="hljs-type">DoubleSha256Digest</span>.empty <span class="hljs-keyword">val</span> dataToSign = <span class="hljs-type">DoubleSha256Digest</span>.empty
<span class="hljs-comment">// dataToSign: DoubleSha256Digest = DoubleSha256Digest(0000000000000000000000000000000000000000000000000000000000000000)</span> <span class="hljs-comment">// dataToSign: DoubleSha256Digest = DoubleSha256Digest(0000000000000000000000000000000000000000000000000000000000000000)</span>
<span class="hljs-keyword">val</span> signature = privKey.signWithBouncyCastle(dataToSign.bytes) <span class="hljs-keyword">val</span> signature = privKey.signWithBouncyCastle(dataToSign.bytes)
<span class="hljs-comment">// signature: ECDigitalSignature = ECDigitalSignature(304402202db5633feb909407dec71ab7db5787ddfd60c748c1f32f9e7dfebf4edd4e7f660220759bdeda9f3d8131b1f45994c94762b8cf1c1167ad61ef56ee614a2817c19e60)</span> <span class="hljs-comment">// signature: ECDigitalSignature = ECDigitalSignature(304402201b5ec60501e433a1f57cc347391bd10a02af21d5ac9c80f9905c6d1f51d7de9b02207b901f1a010afcbe1f07ded25cf8e33cca5e53e645076aa6bd4f8cbcdec186be)</span>
<span class="hljs-keyword">val</span> verified = publicKey.verifyWithBouncyCastle(dataToSign.bytes, signature) <span class="hljs-keyword">val</span> verified = publicKey.verifyWithBouncyCastle(dataToSign.bytes, signature)
<span class="hljs-comment">// verified: Boolean = true</span> <span class="hljs-comment">// verified: Boolean = true</span>