shrub/PSBT.md

80 lines
3.8 KiB
Markdown
Raw Normal View History

2020-12-07 15:00:53 +03:00
# PSBT Handling
2020-12-17 22:31:45 +03:00
## Signing with JS
See `psbt_sign.js` and follow instructions in that file.
2020-12-07 15:00:53 +03:00
## Sample Unsigned
From BIP174 docs.
Uses `bitcoin-cli decodepsbt` to parse.
txid is `fed6cd1fde4db4e13e7e800317e37f9cbd75ec364389670eeff80da993c7e560`
```
bitcoin-cli -rpcuser=__cookie__ -rpcpassword=9e0ca21c70d6b7307b750c8012d12df04ef77d0c5754abc29a3ae31304d946ce decodepsbt cHNidP8BAKACAAAAAqsJSaCMWvfEm4IS9Bfi8Vqz9cM9zxU4IagTn4d6W3vkAAAAAAD+////qwlJoIxa98SbghL0F+LxWrP1wz3PFTghqBOfh3pbe+QBAAAAAP7///8CYDvqCwAAAAAZdqkUdopAu9dAy+gdmI5x3ipNXHE5ax2IrI4kAAAAAAAAGXapFG9GILVT+glechue4O/p+gOcykWXiKwAAAAAAAEHakcwRAIgR1lmF5fAGwNrJZKJSGhiGDR9iYZLcZ4ff89X0eURZYcCIFMJ6r9Wqk2Ikf/REf3xM286KdqGbX+EhtdVRs7tr5MZASEDXNxh/HupccC1AaZGoqg7ECy0OIEhfKaC3Ibi1z+ogpIAAQEgAOH1BQAAAAAXqRQ1RebjO4MsRwUPJNPuuTycA5SLx4cBBBYAFIXRNTfy4mVAWjTbr6nj3aAfuCMIAAAA
```
## TXID from PSBT
```
=btc -build-file %/lib/btc/hoon
=psbt 'cHNidP8BAKACAAAAAqsJSaCMWvfEm4IS9Bfi8Vqz9cM9zxU4IagTn4d6W3vkAAAAAAD+////qwlJoIxa98SbghL0F+LxWrP1wz3PFTghqBOfh3pbe+QBAAAAAP7///8CYDvqCwAAAAAZdqkUdopAu9dAy+gdmI5x3ipNXHE5ax2IrI4kAAAAAAAAGXapFG9GILVT+glechue4O/p+gOcykWXiKwAAAAAAAEHakcwRAIgR1lmF5fAGwNrJZKJSGhiGDR9iYZLcZ4ff89X0eURZYcCIFMJ6r9Wqk2Ikf/REf3xM286KdqGbX+EhtdVRs7tr5MZASEDXNxh/HupccC1AaZGoqg7ECy0OIEhfKaC3Ibi1z+ogpIAAQEgAOH1BQAAAAAXqRQ1RebjO4MsRwUPJNPuuTycA5SLx4cBBBYAFIXRNTfy4mVAWjTbr6nj3aAfuCMIAAAA'
2021-02-08 22:21:19 +03:00
(get-txid:pbt:btc psbt)
2020-12-07 15:00:53 +03:00
:: gives [wid=%32 dat=0xfed6.cd1f.de4d.b4e1.3e7e.8003.17e3.7f9c.bd75.ec36.4389.670e.eff8.0da9.93c7.e560]
```
2020-12-08 17:48:40 +03:00
## Parse PSBT into Maps
```
=btc -build-file %/lib/btc/hoon
=psbt 'cHNidP8BAKACAAAAAqsJSaCMWvfEm4IS9Bfi8Vqz9cM9zxU4IagTn4d6W3vkAAAAAAD+////qwlJoIxa98SbghL0F+LxWrP1wz3PFTghqBOfh3pbe+QBAAAAAP7///8CYDvqCwAAAAAZdqkUdopAu9dAy+gdmI5x3ipNXHE5ax2IrI4kAAAAAAAAGXapFG9GILVT+glechue4O/p+gOcykWXiKwAAAAAAAEHakcwRAIgR1lmF5fAGwNrJZKJSGhiGDR9iYZLcZ4ff89X0eURZYcCIFMJ6r9Wqk2Ikf/REf3xM286KdqGbX+EhtdVRs7tr5MZASEDXNxh/HupccC1AaZGoqg7ECy0OIEhfKaC3Ibi1z+ogpIAAQEgAOH1BQAAAAAXqRQ1RebjO4MsRwUPJNPuuTycA5SLx4cBBBYAFIXRNTfy4mVAWjTbr6nj3aAfuCMIAAAA'
2020-12-10 16:22:48 +03:00
(parse:pbt:btc psbt)
2020-12-08 17:48:40 +03:00
```
2020-12-08 19:16:16 +03:00
## Make an HD Path
```
=btc -build-file %/lib/btc/hoon
2020-12-08 20:31:21 +03:00
=hk [[%4 0x9ca7.9d5b] %bip84 %1 11]
2020-12-08 19:16:16 +03:00
=pubkey [33 0x3.6093.e9e0.6a5f.736e.751f.5486.c1c6.7647.c258.b946.b314.d2d3.f03a.33c2.b5cf.b9ab]
2020-12-08 20:31:21 +03:00
(hd-path:^psbt:btc pubkey %output hk)
2020-12-08 19:16:16 +03:00
:: GIVES
[ key=[wid=34 dat=0x203.6093.e9e0.6a5f.736e.751f.5486.c1c6.7647.c258.b946.b314.d2d3.f03a.33c2.b5cf.b9ab]
val=[wid=21 dat=0x9c.a79d.5b54.0000.8000.0000.8000.0000.8001.0000.000b]]
```
2020-12-07 15:00:53 +03:00
## Making Derivation Paths
Below is hex for `m/84'/0'/0'/0/0`
`*80 is the ending for hardened paths*
54.00.00.80 00.00.00.80 00.00.00.80 00.00.00.00 00.00.00.00.00`
2020-12-08 17:48:40 +03:00
2020-12-11 13:10:40 +03:00
## CLI Debugging
```
bitcoin-cli -rpcuser=__cookie__ -rpcpassword=$(./rpc-password.sh) decodepsbt $PSBT
```
2020-12-08 17:48:40 +03:00
## ColdCard PSBT Export Structure
If we don't have the master fingerprint, can probably fake it. It's not "load-bearing".
Maps:
1. 1 keyval
- Raw tx hex
2. 3 keyvals (Input)
- Witness TX: {8byte amount}|{1 byte scriptpubkeylen}|{22byte scriptpubkey)}
- Non Witness TX: 82 byte input tx
- Wallet Derivation path.
* Key: {0x6}|{33byte pubkey}
2020-12-10 16:22:48 +03:00
* Val: {4byte master xpub fingerprint}|{17byte HD path}
2020-12-08 20:31:21 +03:00
3. skips the main output for some reason, even though it's in raw tx hex.
*skips* = double separator, I think
**we can skip an ouput if the path is on someone else's ship**
2020-12-08 17:48:40 +03:00
4. 1 keyval
- Change output Wallet derivation path
* Key: {0x2}|{33byte pubkey}
* Val: {4byte master xpub fingerprint}|{17byte HD path}
2020-12-11 19:07:42 +03:00
### Signed
Input: keeps above keyvals, and adds one more for the partial signature:
* (key type {0x2}|{publicKey})
* val: 71 byte signature
2021-02-08 22:21:19 +03:00
'0200000002ab0949a08c5af7c49b8212f417e2f15ab3f5c33dcf153821a8139f877a5b7be40000000000feffffffab0949a08c5af7c49b8212f417e2f15ab3f5c33dcf153821a8139f877a5b7be40100000000feffffff02603bea0b000000001976a914768a40bbd740cbe81d988e71de2a4d5c71396b1d88ac8e240000000000001976a9146f4620b553fa095e721b9ee0efe9fa039cca459788ac00000000'