diff --git a/PSBT.md b/PSBT.md index 93e586661..642011dab 100644 --- a/PSBT.md +++ b/PSBT.md @@ -22,7 +22,7 @@ bitcoin-cli -rpcuser=__cookie__ -rpcpassword=9e0ca21c70d6b7307b750c8012d12df04ef =btc -build-file %/lib/btc/hoon =psbt 'cHNidP8BAKACAAAAAqsJSaCMWvfEm4IS9Bfi8Vqz9cM9zxU4IagTn4d6W3vkAAAAAAD+////qwlJoIxa98SbghL0F+LxWrP1wz3PFTghqBOfh3pbe+QBAAAAAP7///8CYDvqCwAAAAAZdqkUdopAu9dAy+gdmI5x3ipNXHE5ax2IrI4kAAAAAAAAGXapFG9GILVT+glechue4O/p+gOcykWXiKwAAAAAAAEHakcwRAIgR1lmF5fAGwNrJZKJSGhiGDR9iYZLcZ4ff89X0eURZYcCIFMJ6r9Wqk2Ikf/REf3xM286KdqGbX+EhtdVRs7tr5MZASEDXNxh/HupccC1AaZGoqg7ECy0OIEhfKaC3Ibi1z+ogpIAAQEgAOH1BQAAAAAXqRQ1RebjO4MsRwUPJNPuuTycA5SLx4cBBBYAFIXRNTfy4mVAWjTbr6nj3aAfuCMIAAAA' -(parse:^psbt:btc psbt) +(parse:pbt:btc psbt) ``` ## Make an HD Path @@ -53,7 +53,7 @@ Maps: - Non Witness TX: 82 byte input tx - Wallet Derivation path. * Key: {0x6}|{33byte pubkey} - * Val: {4byte master xpub fingerprint}|{17byte HD path** + * Val: {4byte master xpub fingerprint}|{17byte HD path} 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** diff --git a/WALLET.scratch.md b/WALLET.scratch.md index c64571e23..9531cca3e 100644 --- a/WALLET.scratch.md +++ b/WALLET.scratch.md @@ -3,6 +3,7 @@ ## xpub xpub1 is from mnemonic from PRIVATE.scratch ``` +=bl -build-file %/lib/btc-wallet-store/hoon =xpub1 'zpub6r8dKyWJ31XF6n69KKeEwLjVC5ruqAbiJ4QCqLsrV36Mvx9WEjUaiPNPGFLHNCCqgCdy6iZC8ZgHsm6a1AUTVBMVbKGemNcWFcwBGSjJKbD' =xpub2 'xpub6D7yaZieZEeG617UcKXDhbsDeso6bmxSAiGWkvkASoiwcjaRtrH5HeNRnDT25s7zmxYzj6MtFe32dVqcf9YcBKKgn9THHjwn2uSjkvobK4e' =bl -build-file %/lib/btc-wallet-store/hoon diff --git a/app/btc-wallet-store.hoon b/app/btc-wallet-store.hoon index 86e52d6b9..e93961526 100644 --- a/app/btc-wallet-store.hoon +++ b/app/btc-wallet-store.hoon @@ -156,7 +156,8 @@ [~[(send-update [%generate-txbu xpub.act u.tb])] state] =/ [addr=address:btc =idx w=walt] ~(nixt-address wad u.uw %1) - =+ new-txbu=(~(add-output txb u.tb) addr u.chng `[fprint.w bipt.w %1 idx]) + =/ new-txbu=txbu + (~(add-output txb u.tb) addr u.chng `(~(hdkey wad w %1) idx)) :_ state(walts (~(put by walts) xpub.act w)) :~ (send-update [%generate-txbu xpub.act new-txbu]) %+ send-request ~[requests-path] diff --git a/lib/btc-wallet-store.hoon b/lib/btc-wallet-store.hoon index 058b5996a..a0150f1ab 100644 --- a/lib/btc-wallet-store.hoon +++ b/lib/btc-wallet-store.hoon @@ -74,6 +74,11 @@ pub:(derive-public:(derive-public:wilt.w (@ chyg)) idx) [(met 3 pk) pk] :: + ++ hdkey + |= =idx:btc + ^- hdkey:btc + [fprint.w (~(pubkey wad w chyg) idx) bipt.w chyg idx] + :: ++ mk-address |= =idx:btc ^- address:btc @@ -241,7 +246,8 @@ payee (total-vbytes is) %+ turn is - |=(i=input [utxo.i ~ [fprint.w bipt.w chyg.i idx.i]]) + |= i=input + [utxo.i ~ (~(hdkey wad w chyg.i) idx.i)] txos == -- diff --git a/lib/btc.hoon b/lib/btc.hoon index 62023ad07..736a47f3e 100644 --- a/lib/btc.hoon +++ b/lib/btc.hoon @@ -62,25 +62,44 @@ ++ globals |= =rawtx ^- map:psbt - *map:psbt - ++ inputs - |= (list in:psbt) + :~ [[1 0x0] rawtx] + == + :: + ++ input + |= i=in:psbt ^- map:psbt - *map:psbt - ++ outputs - |= (list out:psbt) + :~ [[1 0x0] rawtx.i] + (witness-tx i) + (hdkey %input hdkey.i) + == + :: + ++ output + |= =out:psbt ^- map:psbt - *map:psbt - -- + ?~ hk.out ~ + :~ (hdkey %output u.hk.out) + == + :: + ++ witness-tx + |= i=in:psbt + ^- keyval:psbt + :- [1 0x1] + %- cat:byt + :~ (flip:byt 4^value.utxo.i) + 1^0x16 + 2^0x14 + (hash-160 dat.pubkey.hdkey.i) + == + :: ++ hdkey - |= [pubkey=bytc =target:psbt h=^hdkey] + |= [=target:psbt h=^hdkey] ^- keyval:psbt =/ typ=@ux ?- target %input 0x6 %output 0x2 == - :- (cat:byt ~[1^typ pubkey]) + :- (cat:byt ~[1^typ pubkey.h]) %- cat:byt :~ fprint.h %- to-byts:buf @@ -91,11 +110,14 @@ == (flip:byt [(met 3 idx.h) idx.h]) == + -- :: +encode: make base64 cord of PSBT :: ++ encode - |= [=rawtx =txid inputs=(list in:psbt) outputs=(list out:psbt)] - ^- cord + |= [=rawtx =txid inputs=(list in:psbt) outputs=(list out:psbt)] + ^- cord +:: (globals rawtx) + :: TODO :: make global map :: raw tx hex @@ -104,18 +126,6 @@ :: parse to hex :: encode as base64! *cord - :: +create: make base64 cord of PSBT - :: - ++ create - |= [=rawtx =txid inputs=(list in:psbt) outputs=(list out:psbt)] - ^- cord - :: TODO - :: make global map - :: turn each input and output into a map (or ~) - :: put the 0x0 separator between all - :: parse to hex - :: encode as base64! - *cord :: ++ parse |= psbt-base64=cord diff --git a/sur/btc.hoon b/sur/btc.hoon index 4bbbffe83..a049592c5 100644 --- a/sur/btc.hoon +++ b/sur/btc.hoon @@ -10,7 +10,7 @@ +$ bipt $?(%44 %49 %84) +$ chyg $?(%0 %1) +$ idx @ud -+$ hdkey [=fprint =bipt =chyg =idx] ++$ hdkey [=fprint pubkey=bytc =bipt =chyg =idx] +$ sats @ud +$ vbytes @ud +$ bytc [wid=@ dat=@ux] @@ -20,7 +20,7 @@ +$ txid hash256 +$ rawtx bytc +$ 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 @@ -61,7 +61,7 @@ -- ++ psbt |% - +$ in [pubkey=bytc =utxo =rawtx =hdkey] + +$ in [=utxo =rawtx =hdkey] +$ out [=address hk=(unit hdkey)] +$ target $?(%input %output) +$ keyval [key=bytc val=bytc]