This code creates a married keychain for a N-of-M multisig wallet (N= signersRequired, M=# following keys): MarriedKeyChain m = MarriedKeyChain.builder().seed(seed).threshold( signersRequired).followingKeys(followingKeys).build();
Bitcoinj MarriedKeyChain.java <https://github.com/bitcoinj/bitcoinj/blob/master/core/src/main/java/org/bitcoinj/wallet/MarriedKeyChain.java> uses the code below to create a Redeem Script. The script includes: 1-*followedKey (xprivate) *+ M-*followingKeys (xpublic)* *which means instead of N-of-M, you get N-of-M+1.* /** Create a new married key and return the matching output script */ @Override public Script freshOutputScript(KeyPurpose purpose) { DeterministicKey followedKey = getKey(purpose); ImmutableList.Builder<ECKey> keys = ImmutableList.<ECKey>builder().add(*followedKey*); for (DeterministicKeyChain keyChain : followingKeyChains) { DeterministicKey followingKey = keyChain.getKey(purpose); checkState(followedKey.getChildNumber().equals(followingKey.getChildNumber()), "Following keychains should be in sync"); keys.add(*followingKey*); } List<ECKey> marriedKeys = keys.build(); Script redeemScript = ScriptBuilder.createRedeemScript(sigsRequiredToSpend, marriedKeys); return ScriptBuilder.createP2SHOutputScript(redeemScript); } *For example*, spending funds from a 3-of-3 multisig produces a spending tx with 3-of-4 redeem script: 3 PUSHDATA(33)[ 0233e8638451a166daa520a907b50d4ee6067550d48c3b0f90e0705647fd3df2d1] PUSHDATA(33)[0392c9009e3d1db6a96a9ed1adfc2712ba1bdb0c645e76912892fa9a76da046571] PUSHDATA(33)[03da563b5be24f6b59e36bd3c9adf314f057a05586bad344dd8c4ee1f81a0c830c] PUSHDATA(33)[03db70aca2c9a0d9010013a9c432ae205a6285230840c6d6e845c11e76930fc5e8] 4 CHECKMULTISIG -- You received this message because you are subscribed to the Google Groups "bitcoinj" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
