From a8527625b35f8836dde06b941f94ff2b53e1b790 Mon Sep 17 00:00:00 2001 From: timlucmiptev Date: Fri, 16 Oct 2020 18:43:24 +0300 Subject: [PATCH] WIP: wrote down starting point for hash-legacy --- bippy-scratch.md | 14 ++++++++++++++ lib/btc.hoon | 12 +++++++----- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/bippy-scratch.md b/bippy-scratch.md index ddb19ead5b..ae6bfa3fab 100644 --- a/bippy-scratch.md +++ b/bippy-scratch.md @@ -197,6 +197,20 @@ Native P2WPKH :: gives [wid=32 dat=0xc37a.f311.16d1.b27c.af68.aae9.e3ac.82f1.4779.2901.4d5b.9176.57d0.eb49.478c.b670] ``` +### Signing the above +``` +=ecc secp256k1:secp:crypto +=h dat:(~(sighash unsigned-tx:btc utx) 1) +=priv 0x6.19c3.3502.5c7f.4012.e556.c2a5.8b25.06e3.0b85.11b5.3ade.95ea.316f.d8c0.3286.feb9 +(ecdsa-raw-sign:ecc h priv) + +:: desired r of sig: +:: 3609e17b84f6a7d30c80bfa610b5b4542f32a8a0d5447a12fb1366d7f01cc44a +:: +:: desired s of sig: +:: 573a954c4518331561406f90300e8f3358f51928d43c212a8caed02de67eebee +``` + ## cutting off the last 20 bytes (for bech32 address outputs): ``` `@ux`(end 3 2 0x14.6655) diff --git a/lib/btc.hoon b/lib/btc.hoon index 9ffc960d29..175f5d297f 100644 --- a/lib/btc.hoon +++ b/lib/btc.hoon @@ -93,15 +93,14 @@ =/ =input:tx (snag input-index inputs.ut) ?: =(1 witness-ver.input) (sighash-witness input) - (sighash-legacy input) + (sighash-legacy input-index) :: ++ sighash-witness |= =input:tx ^- hash =/ prevouts=byts %- concat-as-byts (turn inputs.ut prevouts-buffer) =/ sequences=byts - %- concat-as-byts - (turn inputs.ut sequence-buffer) + %- concat-as-byts (turn inputs.ut sequence-buffer) =/ outputs=byts %- concat-as-byts (turn outputs.ut outputs-buffer) :: Hash inputs in order, as per BIP143 examples @@ -139,8 +138,11 @@ == :: ++ sighash-legacy - |= =input:tx ^- hash - [0 0x0] + |= input-index=@ ^- hash + :: TODO: turn each input + :: make the script be 0x0 + :: at the end, use snap to replace ONLY the one at input-index with the real script + [0 0x0] -- :: :: Converts a list of bits to a list of n-bit numbers