<div dir="ltr">I&#39;m not sure I understand why you need any special structure for this at all. The way I&#39;d do it is just use regular HD wallets for everyone, of the regular form, and then swap the watching keys. Why do people need to be given a cosigner index at all, given that they all have unique root keys anyway?</div>
<div class="gmail_extra"><br><br><div class="gmail_quote">On Sat, Apr 26, 2014 at 12:27 AM, Manuel Araoz <span dir="ltr">&lt;<a href="mailto:manu@bitpay.com" target="_blank">manu@bitpay.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr"><div>Hi, I&#39;m part of the team building <a href="https://github.com/bitpay/copay" target="_blank">copay</a>, a multisignature P2SH HD wallet. We&#39;ve been following the discussion regarding standardizing the structure for branches both on this list and on github (<a href="https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki" target="_blank">1</a>, <a href="https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki" target="_blank">2</a>, <a href="https://github.com/bitcoin/bips/blob/master/bip-0043.mediawiki" target="_blank">3</a>, <a href="https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki" target="_blank">4</a>, <a href="https://github.com/bitcoin/bips/pull/52" target="_blank">5</a>). Soon, we realized the assumptions in the discussions were not true for a multisig hd wallet, so we wanted to share our current approach to that, to get feedback and see if we can arrive to a new standard (and possibly a new BIP)</div>




<div><br></div><div>These are our assumptions: </div><div> - N parties want to share an m-of-n wallet.</div><div> - Each party must generate their master private keys independently.</div><div> - Use multisig P2SH for all addresses.</div>



<div> - Use BIP32 to derive public keys, then create a multisig script, and use the P2SH address for that.</div><div> - The address generation process should not require communicating with other parties. (Thus, all parties must be able to generate all public keys)</div>



<div> - Transaction creation + signing requires communication between parties, of course.</div><div><br></div><div>-------------------------------------------------</div><div><br></div><div>Following BIP43, we&#39;re be using:</div>



<div><pre style="font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;font-size:13px;margin-top:15px;margin-bottom:15px;background-color:rgb(248,248,248);border:1px solid rgb(221,221,221);line-height:19px;overflow:auto;padding:6px 10px;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;word-wrap:normal;color:rgb(51,51,51)">

m / purpose&#39; / *</pre></div>where <i>purpose</i> is the hardened derivation scheme based on the new BIP number.<br><div>We then define the following levels:</div><div><pre style="font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;font-size:13px;margin-top:15px;margin-bottom:15px;background-color:rgb(248,248,248);border:1px solid rgb(221,221,221);line-height:19px;overflow:auto;padding:6px 10px;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;word-wrap:normal;color:rgb(51,51,51)">

m / purpose&#39; / cosigner_index / change / address_index</pre></div><div>Each level has a special meaning detailed below:</div><div><br></div><div><a href="http://en.wikipedia.org/wiki/Co-signing" target="_blank"><i>cosigner_index</i></a>: the index of the party creating this address. The indices can be determined independently by lexicographically sorting the master public keys of each cosigner.</div>



<div><br></div><div><i>change</i>: 0 for change, 1 for receive address.</div><div><br></div><div><i>address_index</i>: Addresses are numbered from index 0 in sequentially increasing manner. We&#39;re currently syncing the max used index for each branch between all parties when they connect, but we&#39;re open to considering removing the index sync and doing the more elegant used-address discovery via a gap limit, <a href="https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki#address-gap-limit" target="_blank">as discussed in BIP44</a>. We feel 20 might be too low though. </div>



<div><br></div><div><b>Wallet high-level description:</b></div><div>Each party generates their own extended master keypair and shares the extended purpose&#39; public key with the others, which is stored encrypted. Each party can generate any of the other&#39;s derived public keys, but only his own private keys. </div>



<div><br><div><b>General address generation procedure:</b></div><div>When generating an address, each party can independently generate the N needed public keys. They do this by deriving the public key in each of the different trees, but using the same path. They can then generate the multisig script and the corresponding p2sh address. In this way, each path corresponds to an address, but the public keys for that address come from different trees.</div>



<div><br></div><div><b>Receive address case:</b></div><div>Each cosigner generates addresses only on his own branch. One of the n cosigners wants to receive a payment, and the others are offline. He knows the last used index in his own branch, because only he generates addresses there. Thus, he can generate the public keys for all of the others using the next index, and calculate the needed script for the address. </div>



<div><br></div><div><i>Example: </i>Cosigner #2 wants to receive a payment to the shared wallet. His last used index on his own branch is 4. Then, the path for the next receive address is m/$purpose/2/1/5. He uses this same path in all of the cosigners trees to generate a public key for each one, and from that he gets the new p2sh address.</div>



<div><br></div><div><b>Change address case:</b></div><div>Again, each cosigner generates addresses only on his own branch. One of the n cosigners wants to create an outgoing payment, for which he&#39;ll need a change address. He generates a new address using the same procedure as above, but using a separate index to track the used change addresses. </div>



<div><i><br>Example: </i>Cosigner #5 wants to send a payment from the shared wallet, for which he&#39;ll need a change address. His last used change index on his own branch is 11. Then, the path for the next change address is m/$purpose/5/0/12. He uses this same path in all of the cosigners trees to generate a public key for each one, and from that he gets the new p2sh address.</div>



<div><br></div><div><br></div><div><b>Transaction creation and signing:</b></div><div>When creating a transaction, first one of the parties creates a Transaction Proposal. This is a transaction that spends some output stored in any of the p2sh multisig addresses (corresponding to any of the copayers&#39; branches). This proposal is sent to the other parties, who decide if they want to sign. If they approve the proposal, they can generate their needed private key for that specific address (using the same path that generated the public key in that address, but deriving the private key instead), and sign it. Once the proposal reaches m signatures, any cosigner can broadcast it to the network, becoming final. The specifics of how this proposal is structured, and the protocol to accept or reject it, belong to another BIP, in my opinion. </div>



<div><br></div><div><b>Final comments:</b></div><div>- We&#39;re currently lexicographically sorting the public keys for each address separately. We&#39;ve read Mike Belshe&#39;s comments about sorting the master public keys and then using the same order for all derived addresses, but we couldn&#39;t think of any benefits of doing that (I mean, the benefits of knowing whose public key is which).</div>


<div>- We originally thought we would need a non-hardened version of purpose for the path, because we needed every party to be able to generate all the public keys of the others. With the proposed path, is it true that the cosigners will be able to generate them, by knowing the extended purpose public key for each copayer? (m/purpose&#39;)</div>



</div><div>- The reason for using separate branches for each cosigner is we don&#39;t want two of them generating the same address and receiving simultaneous payments to it. The ideal case is that each address receives at most one payment, requested by the corresponding cosigner. </div>


<div><br></div><div><br></div><div>Thoughts?<span class="HOEnZb"><font color="#888888"><br>Manuel</font></span></div></div>
<br>------------------------------------------------------------------------------<br>
Start Your Social Network Today - Download eXo Platform<br>
Build your Enterprise Intranet with eXo Platform Software<br>
Java Based Open Source Intranet - Social, Extensible, Cloud Ready<br>
Get Started Now And Turn Your Intranet Into A Collaboration Platform<br>
<a href="http://p.sf.net/sfu/ExoPlatform" target="_blank">http://p.sf.net/sfu/ExoPlatform</a><br>_______________________________________________<br>
Bitcoin-development mailing list<br>
<a href="mailto:Bitcoin-development@lists.sourceforge.net">Bitcoin-development@lists.sourceforge.net</a><br>
<a href="https://lists.sourceforge.net/lists/listinfo/bitcoin-development" target="_blank">https://lists.sourceforge.net/lists/listinfo/bitcoin-development</a><br>
<br></blockquote></div><br></div>