<p>I have an address with three compressed public keys:</p>
<pre><code>SCRIPT=&quot;5221&quot;$(cat compressed_public_key_1.txt)&quot;21&quot;$(cat compressed_public_key_2.txt)&quot;21&quot;$(cat compressed_public_key_3.txt)&quot;53AE&quot;
</code></pre>
<p>and I generated a P2SH address from here.</p>
<p>Now, I would like to use a descriptor to sign the multisignature transaction.</p>
<p>Previously, I used:</p>
<pre><code>TX_SIGNED=$(bitcoin-cli signrawtransactionwithkey $TX_DATA '[&quot;'$PK1'&quot;]' '[{&quot;txid&quot;:&quot;'$TXID'&quot;,&quot;vout&quot;:'$VOUT',&quot;scriptPubKey&quot;:&quot;'$SCRIPTPUBKEY'&quot;,&quot;redeemScript&quot;:&quot;'$REDEEM'&quot;}]'  | jq -r '.hex')
TX_SIGNED=$(bitcoin-cli signrawtransactionwithkey $TX_SIGNED '[&quot;'$PK2'&quot;]' '[{&quot;txid&quot;:&quot;'$TXID'&quot;,&quot;vout&quot;:'$VOUT',&quot;scriptPubKey&quot;:&quot;'$SCRIPTPUBKEY'&quot;,&quot;redeemScript&quot;:&quot;'$REDEEM'&quot;}]'  | jq -r '.hex')
</code></pre>
<p>and it is still working. However, I want to know if I need to use <code>signrawtransactionwithwallet</code>.</p>
<p>To check this, I attempted:</p>
<pre><code>PK1=`cat compressed_private_key_WIF_1.txt`
PK2=`cat compressed_private_key_WIF_2.txt`
PK3=`cat compressed_private_key_WIF_3.txt`


CHECKSUM=$(bitcoin-cli getdescriptorinfo &quot;sh(multi(2,$PK1,$PK2,$PK3))&quot; | jq -r .checksum)
bitcoin-cli importdescriptors '[{ &quot;desc&quot;: &quot;sh(multi(2,'$PK1','$PK2','$PK3'))#'$CHECKSUM'&quot;, &quot;timestamp&quot;: &quot;now&quot;, &quot;internal&quot;: true }]'
</code></pre>
<p>I could import without any error. But when I try to use:</p>
<pre><code>TX_SIGNED=$(bitcoin-cli signrawtransactionwithwallet $TX_DATA '[{&quot;txid&quot;:&quot;'$TXID'&quot;,&quot;vout&quot;:'$VOUT',&quot;scriptPubKey&quot;:&quot;'$SCRIPTPUBKEY'&quot;,&quot;redeemScript&quot;:&quot;'$REDEEM'&quot;}]'  | jq -r '.hex')
</code></pre>
<p>I get this error:</p>
<p>&quot;error&quot;: &quot;Unable to sign input, invalid stack size (possibly missing key)&quot;</p>
<p>I'm using this kind of script for my study notes</p>

CC BY-SA 4.0
2023-12-08T17:58:50.717Z
Are the PK1 etc private keys or public keys? It won't work without private keys.
Pieter Wuille
CC BY-SA 4.0
2023-12-08T18:03:36.613Z
private keys, updated the question.
monkeyUser
CC BY-SA 4.0
2023-12-08T18:11:33.900Z
Does the address match exactly? You can use `deriveaddresses` on the descriptor.
Pieter Wuille
CC BY-SA 4.0
2023-12-08T18:24:53.283Z
thanks for the reply, no the address is different after using `deriveaddresses` but the Order of PB during creating the Redeem script is the same
monkeyUser
CC BY-SA 4.0
2023-12-08T18:26:10.257Z
Well if the address doesn't match, it's not a descriptor for the exact output you have, so it won't work. BTW: your  `SCRIPT` uses the same public key twice.
Pieter Wuille
CC BY-SA 4.0
2023-12-08T18:37:05.110Z
My fault, even with the fix, I don't have the same address. Maybe the problem could be the PB and PK order?
monkeyUser
CC BY-SA 4.0
2023-12-08T18:43:55.633Z
What is "PB"? Try `getaddressinfo` on the address that comes out of `deriveaddresses`; it may tell you what the exact redeemscript is.
Pieter Wuille
CC BY-SA 4.0
2023-12-08T18:55:40.790Z
You are correct, PB stands for the public key. It now works properly. With `deriveaddress`, I can observe the correct order of public keys. Perhaps the main issue was the script type with `compressed_public_key_2.txt` repeated twice. Unfortunately, for study purposes, I cannot attempt to send the transaction with just one signature, as I could with `signrawtransactionwithkey`. The error message provided valuable insights.
monkeyUser
<wallet><address><multi-signature><output-script-descriptors>
Sign a multi-signature transaction with imported address
monkeyUser
# Sign a multi-signature transaction with imported address

(Asked by: username_0 on 2023-12-08)

I have an address with three compressed public keys:

```
SCRIPT="5221"$(cat compressed_public_key_1.txt)"21"$(cat compressed_public_key_2.txt)"21"$(cat compressed_public_key_3.txt)"53AE"

```

and I generated a P2SH address from here.

Now, I would like to use a descriptor to sign the multisignature transaction.

Previously, I used:

```
TX_SIGNED=$(bitcoin-cli signrawtransactionwithkey $TX_DATA '["'$PK1'"]' '[{"txid":"'$TXID'","vout":'$VOUT',"scriptPubKey":"'$SCRIPTPUBKEY'","redeemScript":"'$REDEEM'"}]'  | jq -r '.hex')
TX_SIGNED=$(bitcoin-cli signrawtransactionwithkey $TX_SIGNED '["'$PK2'"]' '[{"txid":"'$TXID'","vout":'$VOUT',"scriptPubKey":"'$SCRIPTPUBKEY'","redeemScript":"'$REDEEM'"}]'  | jq -r '.hex')

```

and it is still working. However, I want to know if I need to use `signrawtransactionwithwallet`.

To check this, I attempted:

```
PK1=`cat compressed_private_key_WIF_1.txt`
PK2=`cat compressed_private_key_WIF_2.txt`
PK3=`cat compressed_private_key_WIF_3.txt`

CHECKSUM=$(bitcoin-cli getdescriptorinfo "sh(multi(2,$PK1,$PK2,$PK3))" | jq -r .checksum)
bitcoin-cli importdescriptors '[{ "desc": "sh(multi(2,'$PK1','$PK2','$PK3'))#'$CHECKSUM'", "timestamp": "now", "internal": true }]'

```

I could import without any error. But when I try to use:

```
TX_SIGNED=$(bitcoin-cli signrawtransactionwithwallet $TX_DATA '[{"txid":"'$TXID'","vout":'$VOUT',"scriptPubKey":"'$SCRIPTPUBKEY'","redeemScript":"'$REDEEM'"}]'  | jq -r '.hex')

```

I get this error:

"error": "Unable to sign input, invalid stack size (possibly missing key)"

I'm using this kind of script for my study notes

**Tags:** wallet, address, multi-signature, output-script-descriptors

> **Comments:**
> **username_1**: Are the PK1 etc private keys or public keys? It won't work without private keys.  
> **username_0**: private keys, updated the question.  
> **username_1**: Does the address match exactly? You can use `deriveaddresses` on the descriptor.  
> **username_0**: thanks for the reply, no the address is different after using `deriveaddresses` but the Order of PB during creating the Redeem script is the same  
> **username_1**: Well if the address doesn't match, it's not a descriptor for the exact output you have, so it won't work. BTW: your  `SCRIPT` uses the same public key twice.  
> **username_0**: My fault, even with the fix, I don't have the same address. Maybe the problem could be the PB and PK order?  
> **username_1**: What is "PB"? Try `getaddressinfo` on the address that comes out of `deriveaddresses`; it may tell you what the exact redeemscript is.  
> **username_0**: You are correct, PB stands for the public key. It now works properly. With `deriveaddress`, I can observe the correct order of public keys. Perhaps the main issue was the script type with `compressed_public_key_2.txt` repeated twice. Unfortunately, for study purposes, I cannot attempt to send the transaction with just one signature, as I could with `signrawtransactionwithkey`. The error message provided valuable insights.  

---

## 0 answers

