<!DOCTYPE html><htmllang="en"><head><metacharSet="utf-8"/><metahttp-equiv="X-UA-Compatible"content="IE=edge"/><title>Sign API · bitcoin-s</title><metaname="viewport"content="width=device-width"/><metaname="generator"content="Docusaurus"/><metaname="description"content="### The [`Sign` API](org/bitcoins/core/crypto/Sign.scala)"/><metaname="docsearch:version"content="next"/><metaname="docsearch:language"content="en"/><metaproperty="og:title"content="Sign API · bitcoin-s"/><metaproperty="og:type"content="website"/><metaproperty="og:url"content="https://bitcoin-s.org/"/><metaproperty="og:description"content="### The [`Sign` API](org/bitcoins/core/crypto/Sign.scala)"/><metaproperty="og:image"content="https://bitcoin-s.org/img/undraw_online.svg"/><metaname="twitter:card"content="summary"/><metaname="twitter:image"content="https://bitcoin-s.org/img/undraw_tweetstorm.svg"/><linkrel="shortcut icon"href="/img/favicon.ico"/><linkrel="stylesheet"href="https://cdn.jsdelivr.net/docsearch.js/1/docsearch.min.css"/><linkrel="stylesheet"href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/default.min.css"/><linkrel="stylesheet"href="/css/code-block-buttons.css"/><scripttype="text/javascript"src="https://buttons.github.io/buttons.js"></script><scripttype="text/javascript"src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.0/clipboard.min.js"></script><scripttype="text/javascript"src="https://fonts.googleapis.com/css?family=Montserrat:500"></script><scripttype="text/javascript"src="https://www.googletagmanager.com/gtag/js?id=UA-61958686-2"></script><scripttype="text/javascript"src="/js/code-block-buttons.js"></script><scriptsrc="/js/scrollSpy.js"></script><linkrel="stylesheet"href="/css/main.css"/><scriptsrc="/js/codetabs.js"></script></head><bodyclass="sideNavVisible separateOnPageNav"><divclass="fixedHeaderContainer"><divclass="headerWrapper wrapper"><header><ahref="/"><imgclass="logo"src="/img/favicon.ico"alt="bitcoin-s"/><h2class="headerTitleWithLogo">bitcoin-s</h2></a><ahref="/versions"><h3>next</h3></a><divclass="navigationWrapper navigationSlider"><navclass="slidingNav"><ulclass="nav-site nav-site-internal"><liclass="siteNavGroupActive"><ahref="/docs/next/core/core-intro"target="_self">Docs</a></li><liclass=""><ahref="/api/org/bitcoins"target="_self">API</a></li><liclass=""><ahref="/help"target="_self">Help</a></li><liclass="navSearchWrapper reactNavSearchWrapper"><inputtype="text"id="search_input_react"placeholder="Search"title="Search"/></li></ul></nav></div></header></div></div><divclass="navPusher"><divclass="docMainWrapper wrapper"><divclass="docsNavContainer"id="docsNav"><navclass="toc"><divclass="toggleNav"><sectionclass="navWrapper wrapper"><divclass="navBreadcrumb wrapper"><divclass="navToggle"id="navToggler"><divclass="hamburger-menu"><divclass="line1"></div><divclass="line2"></div><divclass="line3"></div></div></div><h2><i>›</i><span>Core Module</span></h2><divclass="tocToggler"id="tocToggler"><iclass="icon-toc"></i></div></div><divclass="navGroups"><divclass="navGroup"><h3class="navGroupCategoryTitle">Getting Started</h3><ulclass=""><liclass="navListItem"><aclass="navItem"href="/docs/next/getting-started">Intro and Getting Started</a></li></ul></div><divclass="navGroup"><h3class="navGroupCategoryTitle">Getting Setup</h3><ulclass=""><liclass="navListItem"><aclass="navItem"href="/docs/next/getting-setup">Getting Bitcoin-S installed on your machine</a></li></ul></div><divclass="navGroup"><h3class="navGroupCategoryTitle">Applications</h3><ulclass=""><liclass="navListItem"><aclass="navItem"href="/docs/next/applications/cli">CLI</a></li><liclass="navListItem"><aclass="navItem"href="/docs/next/applications/server">Application Server</a></li><liclass="navListItem"><aclass="navItem"href="/docs/next/applications/gui">GUI</a></li></ul></div><divclass="navGroup"><h3class="navGroupCategoryTitle">Chain</h3><ulclass=""><liclass="navListItem"><aclass="navItem"href="/docs/next/chain/chain">
<p>This is the API we define to sign things with. It takes in an arbitrary byte vector and returns a <code>Future[ECDigitalSignature]</code>. The reason we incorporate <code>Future</code>s here is for extensibility of this API. We would like to provide implementations of this API for hardware devices, which need to be asynchrnous since they may require user input.</p>
<p>The <code>ByteVector</code> that is input to the <code>signFunction</code> should be the hash that is output from <ahref="/api/org/bitcoins/core/crypto/TransactionSignatureSerializer"><code>TransactionSignatureSerializer</code></a>'s <code>hashForSignature</code> method. Our in-memory <ahref="/api/org/bitcoins/core/crypto/ECKey"><code>ECKey</code></a> types implement the <code>Sign</code> API.</p>
<p>If you wanted to implement a new <code>Sign</code> api for a hardware wallet, you can easily pass it into the <code>TxBuilder</code>/<code>Signer</code> classes to allow for you to use those devices to sign with Bitcoin-S.</p>
<p>This API is currently used to sign ordinary transactions with our <ahref="/api/org/bitcoins/core/wallet/signer/Signer"><code>Signer</code></a>s. The <code>Signer</code> subtypes (i.e. <code>P2PKHSigner</code>) implement the specific functionality needed to produce a valid digital signature for their corresponding script type.</p>
<p>An <ahref="org/bitcoins/core/crypto/ExtKey.scala">ExtKey</a> is a data structure that can be used to generate more keys from a parent key. For more information look at <ahref="/docs/next/core/hd-keys">/docs/next/core/hd-keys</a></p>
<p>You can sign with <code>ExtPrivateKey</code> the same way you could with a normal <code>ECPrivateKey</code>.</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>