working HD path for PSBT

This commit is contained in:
timlucmiptev 2020-12-08 18:16:16 +02:00 committed by ixv
parent 1497b4127c
commit 98fa36ffd6
3 changed files with 47 additions and 1 deletions

12
PSBT.md
View File

@ -25,6 +25,18 @@ bitcoin-cli -rpcuser=__cookie__ -rpcpassword=9e0ca21c70d6b7307b750c8012d12df04ef
(parse:^psbt:btc psbt)
```
## Make an HD Path
```
=btc -build-file %/lib/btc/hoon
=print [4 0x9ca7.9d5b]
=pubkey [33 0x3.6093.e9e0.6a5f.736e.751f.5486.c1c6.7647.c258.b946.b314.d2d3.f03a.33c2.b5cf.b9ab]
(hd-path:^psbt:btc print pubkey %output %bip84 %1 11)
:: 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]]
```
## Making Derivation Paths
Below is hex for `m/84'/0'/0'/0/0`
`*80 is the ending for hardened paths*

View File

@ -68,6 +68,37 @@
::
++ psbt
|%
++ hd-path
|= [print=btc-byts pubkey=btc-byts =target:^psbt =bipt =chyg idx=@ud]
^- keyval:^psbt
=/ k=btc-byts
%- to-byts:buffer
?- target
%input
[0x6 (from-byts:buffer pubkey)]
::
%output
[0x2 (from-byts:buffer pubkey)]
==
=/ bip ?- bipt
%bip84 0x54
%bip49 0x31
%bip44 0x2c
==
=/ hdpath=^buffer
%+ weld
:~ bip 0x0 0x0 0x80
0x0 0x0 0x0 0x80
0x0 0x0 0x0 0x80
`@ux`chyg 0x0 0x0 0x0
==
(from-atom-le:buffer (met 3 idx) idx)
:- k
%- concat-as-byts:buffer
:~ (from-byts:buffer print)
hdpath
==
::
++ parse
|= psbt-base64=cord
^- (list map:^psbt)
@ -136,6 +167,7 @@
=/ bigend=@ux (swp 3 q.u.p)
(from-byts:buffer [(met 3 bigend) bigend])
--
:: buffer: byte buffer utilities
:: list of @ux that is big endian for hashing purposes
:: used to preserve 0s when concatenating byte sequences
::

View File

@ -5,6 +5,7 @@
+$ bech32-address $%([%bech32 cord])
+$ address ?(legacy-address bech32-address)
+$ bipt $?(%bip44 %bip49 %bip84)
+$ chyg $?(%0 %1)
+$ sats @ud
+$ vbytes @ud
+$ btc-byts [wid=@ dat=@ux]
@ -14,7 +15,7 @@
+$ txid hash256
+$ rawtx btc-byts
+$ buffer (list @ux)
+$ utxo [pos=@ =txid height=@ value=sats recvd=(unit @da)]
+$ utxo [pos=@ =txid height=@ value=sats recvd=(unit @da)]
++ address-info
$: =address
confirmed-value=sats
@ -55,6 +56,7 @@
--
++ psbt
|%
+$ target $?(%input %output)
+$ keyval [key=btc-byts val=btc-byts]
+$ map (list keyval)
--