@ -162,16 +162,6 @@ static int parse_config(char *argv[],
return argnum ;
return argnum ;
}
}
static char * sig_as_hex ( const struct bitcoin_signature * sig )
{
u8 compact_sig [ 64 ] ;
secp256k1_ecdsa_signature_serialize_compact ( secp256k1_ctx ,
compact_sig ,
& sig - > s ) ;
return tal_hexstr ( NULL , compact_sig , sizeof ( compact_sig ) ) ;
}
static int parse_htlc ( char * argv [ ] ,
static int parse_htlc ( char * argv [ ] ,
struct added_htlc * * htlcs ,
struct added_htlc * * htlcs ,
enum htlc_state * * htlc_states ,
enum htlc_state * * htlc_states ,
@ -224,6 +214,33 @@ static const struct preimage *preimage_of(const struct sha256 *hash,
abort ( ) ;
abort ( ) ;
}
}
static char * sig_as_hex ( const struct bitcoin_signature * sig )
{
u8 compact_sig [ 64 ] ;
secp256k1_ecdsa_signature_serialize_compact ( secp256k1_ctx ,
compact_sig ,
& sig - > s ) ;
return tal_hexstr ( NULL , compact_sig , sizeof ( compact_sig ) ) ;
}
static char * sig_notation ( const struct sha256_double * hash ,
const struct privkey * privkey ,
const struct bitcoin_signature * sig )
{
const char * pstr = tal_hexstr ( NULL , privkey - > secret . data , sizeof ( privkey - > secret . data ) ) ;
const char * hstr = type_to_string ( NULL , struct sha256_double , hash ) ;
if ( verbose )
return tal_fmt ( NULL ,
" SIG(%s:%s) \n privkey: %s \n tx_hash: %s \n "
" sig: %s " ,
pstr , hstr , pstr , hstr , sig_as_hex ( sig ) ) ;
return tal_fmt ( NULL , " SIG(%s:%s) " , pstr, hstr) ;
}
int main ( int argc , char * argv [ ] )
int main ( int argc , char * argv [ ] )
{
{
struct secrets local , remote ;
struct secrets local , remote ;
@ -252,6 +269,7 @@ int main(int argc, char *argv[])
struct privkey local_htlc_privkey , remote_htlc_privkey ;
struct privkey local_htlc_privkey , remote_htlc_privkey ;
struct pubkey local_htlc_pubkey , remote_htlc_pubkey ;
struct pubkey local_htlc_pubkey , remote_htlc_pubkey ;
bool option_static_remotekey = false ;
bool option_static_remotekey = false ;
struct sha256_double hash ;
setup_locale ( ) ;
setup_locale ( ) ;
chainparams = chainparams_for_network ( " bitcoin " ) ;
chainparams = chainparams_for_network ( " bitcoin " ) ;
@ -386,26 +404,33 @@ int main(int argc, char *argv[])
& local_per_commit_point , commitnum , LOCAL ) ;
& local_per_commit_point , commitnum , LOCAL ) ;
printf ( " ## local_commitment \n "
printf ( " ## local_commitment \n "
" # input amount %s, funding_wscript %s, key %s \n " ,
" # input amount %s, funding_wscript %s, pub key %s \n " ,
type_to_string ( NULL , struct amount_sat , & funding_amount ) ,
type_to_string ( NULL , struct amount_sat , & funding_amount ) ,
tal_hex ( NULL , funding_wscript ) ,
tal_hex ( NULL , funding_wscript ) ,
type_to_string ( NULL , struct pubkey , & funding_localkey ) ) ;
type_to_string ( NULL , struct pubkey , & funding_localkey ) ) ;
printf ( " # unsigned local commitment tx: %s \n " ,
printf ( " # unsigned local commitment tx: %s \n " ,
tal_hex ( NULL , linearize_tx ( NULL , local_txs [ 0 ] ) ) ) ;
tal_hex ( NULL , linearize_tx ( NULL , local_txs [ 0 ] ) ) ) ;
/* Get the hash out, for printing */
bitcoin_tx_hash_for_sig ( local_txs [ 0 ] , 0 , funding_wscript ,
SIGHASH_ALL , & hash ) ;
sign_tx_input ( local_txs [ 0 ] , 0 , NULL , funding_wscript ,
sign_tx_input ( local_txs [ 0 ] , 0 , NULL , funding_wscript ,
& local . funding_privkey ,
& local . funding_privkey ,
& funding_localkey ,
& funding_localkey ,
SIGHASH_ALL ,
SIGHASH_ALL ,
& local_sig ) ;
& local_sig ) ;
printf ( " localsig_on_local: %s \n " , sig_as_hex ( & local_sig ) ) ;
printf ( " localsig_on_local: %s \n " , sig_notation ( & hash ,
& local . funding_privkey ,
& local_sig ) ) ;
sign_tx_input ( local_txs [ 0 ] , 0 , NULL , funding_wscript ,
sign_tx_input ( local_txs [ 0 ] , 0 , NULL , funding_wscript ,
& remote . funding_privkey ,
& remote . funding_privkey ,
& funding_remotekey ,
& funding_remotekey ,
SIGHASH_ALL ,
SIGHASH_ALL ,
& remote_sig ) ;
& remote_sig ) ;
printf ( " remotesig_on_local: %s \n " , sig_as_hex ( & remote_sig ) ) ;
printf ( " remotesig_on_local: %s \n " , sig_notation ( & hash ,
& remote . funding_privkey ,
& remote_sig ) ) ;
witness =
witness =
bitcoin_witness_2of2 ( NULL , & local_sig , & remote_sig ,
bitcoin_witness_2of2 ( NULL , & local_sig , & remote_sig ,
@ -452,6 +477,9 @@ int main(int argc, char *argv[])
= tal_dup ( local_txs [ 1 + i ] , struct amount_sat , & amt ) ;
= tal_dup ( local_txs [ 1 + i ] , struct amount_sat , & amt ) ;
printf ( " # wscript: %s \n " , tal_hex ( NULL , wscripts [ 1 + i ] ) ) ;
printf ( " # wscript: %s \n " , tal_hex ( NULL , wscripts [ 1 + i ] ) ) ;
bitcoin_tx_hash_for_sig ( local_txs [ 1 + i ] , 0 , wscripts [ 1 + i ] ,
SIGHASH_ALL , & hash ) ;
sign_tx_input ( local_txs [ 1 + i ] , 0 , NULL , wscripts [ 1 + i ] ,
sign_tx_input ( local_txs [ 1 + i ] , 0 , NULL , wscripts [ 1 + i ] ,
& local_htlc_privkey , & local_htlc_pubkey ,
& local_htlc_privkey , & local_htlc_pubkey ,
SIGHASH_ALL , & local_htlc_sig ) ;
SIGHASH_ALL , & local_htlc_sig ) ;
@ -459,9 +487,9 @@ int main(int argc, char *argv[])
& remote_htlc_privkey , & remote_htlc_pubkey ,
& remote_htlc_privkey , & remote_htlc_pubkey ,
SIGHASH_ALL , & remote_htlc_sig ) ;
SIGHASH_ALL , & remote_htlc_sig ) ;
printf ( " localsig_on_local output %zu: %s \n " ,
printf ( " localsig_on_local output %zu: %s \n " ,
i , sig_as_hex ( & local_htlc_sig ) ) ;
i , sig_notation ( & hash , & local_htlc_privkey , & local_htlc_sig ) ) ;
printf ( " remotesig_on_local output %zu: %s \n " ,
printf ( " remotesig_on_local output %zu: %s \n " ,
i , sig_as_hex ( & remote_htlc_sig ) ) ;
i , sig_notation ( & hash , & remote_htlc_privkey , & remote_htlc_sig ) ) ;
if ( htlc_owner ( htlcmap [ i ] ) = = LOCAL )
if ( htlc_owner ( htlcmap [ i ] ) = = LOCAL )
witness = bitcoin_witness_htlc_timeout_tx ( NULL ,
witness = bitcoin_witness_htlc_timeout_tx ( NULL ,
@ -496,19 +524,25 @@ int main(int argc, char *argv[])
printf ( " # unsigned remote commitment tx: %s \n " ,
printf ( " # unsigned remote commitment tx: %s \n " ,
tal_hex ( NULL , linearize_tx ( NULL , remote_txs [ 0 ] ) ) ) ;
tal_hex ( NULL , linearize_tx ( NULL , remote_txs [ 0 ] ) ) ) ;
bitcoin_tx_hash_for_sig ( remote_txs [ 0 ] , 0 , funding_wscript ,
SIGHASH_ALL , & hash ) ;
sign_tx_input ( remote_txs [ 0 ] , 0 , NULL , funding_wscript ,
sign_tx_input ( remote_txs [ 0 ] , 0 , NULL , funding_wscript ,
& local . funding_privkey ,
& local . funding_privkey ,
& funding_localkey ,
& funding_localkey ,
SIGHASH_ALL ,
SIGHASH_ALL ,
& local_sig ) ;
& local_sig ) ;
printf ( " localsig_on_remote: %s \n " , sig_as_hex ( & local_sig ) ) ;
printf ( " localsig_on_remote: %s \n " , sig_notation ( & hash ,
& local . funding_privkey ,
& local_sig ) ) ;
sign_tx_input ( remote_txs [ 0 ] , 0 , NULL , funding_wscript ,
sign_tx_input ( remote_txs [ 0 ] , 0 , NULL , funding_wscript ,
& remote . funding_privkey ,
& remote . funding_privkey ,
& funding_remotekey ,
& funding_remotekey ,
SIGHASH_ALL ,
SIGHASH_ALL ,
& remote_sig ) ;
& remote_sig ) ;
printf ( " remotesig_on_remote: %s \n " , sig_as_hex ( & remote_sig ) ) ;
printf ( " remotesig_on_remote: %s \n " , sig_notation ( & hash ,
& remote . funding_privkey ,
& remote_sig ) ) ;
witness =
witness =
bitcoin_witness_2of2 ( NULL , & local_sig , & remote_sig ,
bitcoin_witness_2of2 ( NULL , & local_sig , & remote_sig ,
@ -555,6 +589,8 @@ int main(int argc, char *argv[])
= tal_dup ( remote_txs [ 1 + i ] , struct amount_sat , & amt ) ;
= tal_dup ( remote_txs [ 1 + i ] , struct amount_sat , & amt ) ;
printf ( " # wscript: %s \n " , tal_hex ( NULL , wscripts [ 1 + i ] ) ) ;
printf ( " # wscript: %s \n " , tal_hex ( NULL , wscripts [ 1 + i ] ) ) ;
bitcoin_tx_hash_for_sig ( remote_txs [ 1 + i ] , 0 , wscripts [ 1 + i ] ,
SIGHASH_ALL , & hash ) ;
sign_tx_input ( remote_txs [ 1 + i ] , 0 , NULL , wscripts [ 1 + i ] ,
sign_tx_input ( remote_txs [ 1 + i ] , 0 , NULL , wscripts [ 1 + i ] ,
& local_htlc_privkey , & local_htlc_pubkey ,
& local_htlc_privkey , & local_htlc_pubkey ,
SIGHASH_ALL , & local_htlc_sig ) ;
SIGHASH_ALL , & local_htlc_sig ) ;
@ -562,9 +598,9 @@ int main(int argc, char *argv[])
& remote_htlc_privkey , & remote_htlc_pubkey ,
& remote_htlc_privkey , & remote_htlc_pubkey ,
SIGHASH_ALL , & remote_htlc_sig ) ;
SIGHASH_ALL , & remote_htlc_sig ) ;
printf ( " localsig_on_remote output %zu: %s \n " ,
printf ( " localsig_on_remote output %zu: %s \n " ,
i , sig_as_hex ( & local_htlc_sig ) ) ;
i , sig_notation ( & hash , & local_htlc_privkey , & local_htlc_sig ) ) ;
printf ( " remotesig_on_remote output %zu: %s \n " ,
printf ( " remotesig_on_remote output %zu: %s \n " ,
i , sig_as_hex ( & remote_htlc_sig ) ) ;
i , sig_notation ( & hash , & remote_htlc_privkey , & remote_htlc_sig ) ) ;
if ( htlc_owner ( htlcmap [ i ] ) = = REMOTE )
if ( htlc_owner ( htlcmap [ i ] ) = = REMOTE )
witness = bitcoin_witness_htlc_timeout_tx ( NULL ,
witness = bitcoin_witness_htlc_timeout_tx ( NULL ,