mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-02-24 06:57:51 +01:00
PSBT signing with BitcoinUTXOSpendingInfoSingle
This commit is contained in:
parent
a70b03d08a
commit
c535985d6f
1 changed files with 29 additions and 1 deletions
|
@ -16,6 +16,7 @@ creation, updating, combining, signing, finalizing,
|
|||
and transaction extraction.
|
||||
|
||||
An example on a typical PSBT workflow:
|
||||
|
||||
```scala mdoc:invisible
|
||||
import org.bitcoins.core.crypto.ECPrivateKey
|
||||
import org.bitcoins.core.protocol.script.ScriptPubKey
|
||||
|
@ -26,7 +27,7 @@ import scodec.bits._
|
|||
import scala.concurrent.{ExecutionContext, ExecutionContextExecutor}
|
||||
```
|
||||
|
||||
```scala mdoc:to-string
|
||||
```scala mdoc:compile-only
|
||||
implicit val ec: ExecutionContextExecutor = ExecutionContext.global
|
||||
|
||||
// First you need an unsigned transaction,
|
||||
|
@ -105,6 +106,33 @@ val psbtFirstSigF =
|
|||
.sign(inputIndex = 0, signer = privKey0)
|
||||
.flatMap(_.sign(inputIndex = 0, signer = privKey1))
|
||||
|
||||
// Alternatively, you can use produce a signature with a BitcoinUTXOSpendingInfoSingle
|
||||
// using the BitcoinSingleSigner will return a PartialSignature that can be added to a PSBT
|
||||
|
||||
// First we need to declare out spendingInfoSingle
|
||||
val outPoint = unsignedTransaction.inputs.head.previousOutput
|
||||
val output = utxo0.outputs(outPoint.vout.toInt)
|
||||
|
||||
val spendingInfoSingle = BitcoinUTXOSpendingInfoSingle(
|
||||
outPoint = outPoint,
|
||||
output = output,
|
||||
signer = privKey0,
|
||||
redeemScriptOpt = Some(redeemScript0),
|
||||
scriptWitnessOpt = None,
|
||||
hashType = HashType.sigHashAll,
|
||||
conditionalPath = ConditionalPath.NoConditionsLeft
|
||||
)
|
||||
|
||||
// Then we can sign the transaction
|
||||
val signatureF = BitcoinSignerSingle.signSingle(spendingInfo = spendingInfoSingle,
|
||||
unsignedTx = unsignedTransaction,
|
||||
isDummySignature = false)
|
||||
|
||||
// We can then add the signature to the PSBT
|
||||
// Note: this signature could be produced by us or another party
|
||||
signatureF.map(sig => psbtWithSigHashFlags.addSignature(sig, inputIndex = 0)
|
||||
|
||||
// With our first input signed we can now move on to showing how another party could sign our second input
|
||||
psbtFirstSigF.map { psbtFirstSig =>
|
||||
// In this scenario, let's say that the second input does not belong to us and we need
|
||||
// another party to sign it. In this case we would need to send the PSBT to the other party.
|
||||
|
|
Loading…
Add table
Reference in a new issue