Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes from nonce musig eltoo branch to taproot wallet branch #3

Open
wants to merge 283 commits into
base: ddustin/taproot
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
283 commits
Select commit Hold shift + click to select a range
08c0f54
Compute and pass in inner pubkeys
instagibbs Jul 6, 2022
f850dc4
fix to_node script
instagibbs Jul 6, 2022
5eba4fc
Checkin
instagibbs Jul 6, 2022
19439a7
initial settlement tx compiling
instagibbs Jul 7, 2022
3f274c1
Add initial settlement tx testing stub
instagibbs Jul 7, 2022
f840081
update libwally
instagibbs Jul 7, 2022
a99151b
Revert "update libwally"
instagibbs Jul 7, 2022
6af5636
update libwally
instagibbs Jul 7, 2022
74fac28
test compiling
instagibbs Jul 7, 2022
2ec21ef
No crashes on test
instagibbs Jul 7, 2022
877dd5c
fixup the pay amounts
instagibbs Jul 7, 2022
87932e5
Add regression vector that may be wrong
instagibbs Jul 7, 2022
505ac0d
Forgot to tack on sighash flag for APO sig
instagibbs Jul 8, 2022
a9a60fb
Logging... fixed this?
instagibbs Jul 8, 2022
4af08d5
Fix balance outputs, was pushing compressed pubkey...
instagibbs Jul 11, 2022
8ce6f95
add htlc success script for eltoo
instagibbs Jul 11, 2022
ff34772
Add eltoo HTLC timeout tapscript creation
instagibbs Jul 11, 2022
b69a34c
compartmentalise settlement tx test
instagibbs Jul 11, 2022
d6346ea
Add basic HTLC test cross-reffed with scriptwiz results
instagibbs Jul 11, 2022
2f459c5
f
instagibbs Jul 11, 2022
3dcfba6
simplify key storage with eltoo_keyset
instagibbs Jul 12, 2022
36b31a6
refactor out tx_add_to_node_output
instagibbs Jul 13, 2022
a618247
Refactor out settlement transaction input creation
instagibbs Jul 15, 2022
ce92a02
Add non-initial settlement tx creation plus test without htlcs
instagibbs Jul 15, 2022
9a7431b
Add very basic update number test
instagibbs Jul 15, 2022
c147c4e
some more settlement tx with htlc testing
instagibbs Jul 15, 2022
25d126b
Set proper nlocktime, redefine obscured update number
instagibbs Jul 15, 2022
9c4b35b
fixup eltoo update script constant to become time
instagibbs Jul 18, 2022
9e8a400
f
instagibbs Jul 18, 2022
f9b7efc
Update script in settlement input is one larger than settlement locktime
instagibbs Jul 18, 2022
ba076f2
Update settlement hex
instagibbs Jul 18, 2022
67aeb34
Add initial update tx creation code
instagibbs Jul 18, 2022
3195f25
Fix annex creation
instagibbs Jul 18, 2022
7992f64
updating libwally
instagibbs Jul 19, 2022
ff02df6
Thread annex through to sign_tx_taproot_input
instagibbs Jul 19, 2022
d54d35c
Don't crudely embed annex witness data in PSBT
instagibbs Jul 19, 2022
9a9dd49
Complete MuSig signing example in update tx test
instagibbs Jul 20, 2022
37b5766
Maybe signed update tx in test
instagibbs Jul 20, 2022
d0a375b
Funding output only has one script
instagibbs Jul 21, 2022
79fb637
actually populate the tap merkle root for update funding spend
instagibbs Jul 21, 2022
bfaa3c8
Fix control block for funding update
instagibbs Jul 21, 2022
8d07532
Fixup signatures a bit for update tx
instagibbs Jul 21, 2022
fe70398
update libwally for annex update
instagibbs Jul 21, 2022
92104e1
Incorrect miniscript...
instagibbs Jul 21, 2022
b1db6e8
Fix test signing of update tx
instagibbs Jul 21, 2022
f916e8f
Refactor update transaction flow to follow actual rebinding flow
instagibbs Jul 25, 2022
058f974
Implement annex hint stuff for update to update tx
instagibbs Jul 25, 2022
6ab9f1a
Rename initial_update_tx to update_tx since it's not just initial
instagibbs Jul 26, 2022
fb36456
Delete the copious amount of printing for debugging
instagibbs Jul 26, 2022
c880d71
Outpoint doesnt make sense to set for non-initial settlement tx
instagibbs Jul 26, 2022
c3e3a77
Checkin
instagibbs Jul 26, 2022
84f79b5
Compiling through
instagibbs Jul 26, 2022
e454e0c
Print out 2nd settlement tx
instagibbs Jul 27, 2022
1fd630f
Spec wrong, and me being wrong...
instagibbs Jul 27, 2022
6dda4cd
F
instagibbs Jul 27, 2022
6b8f042
Check in work
instagibbs Aug 2, 2022
b99ae7e
openingd_eltoo messages compiling
instagibbs Aug 3, 2022
b902edd
Delete reserve requirements from eltoo
instagibbs Aug 3, 2022
d14f35a
Add new files
instagibbs Aug 3, 2022
abdc3d1
Remove rest of reserve requirement stuff for eltoo
instagibbs Aug 3, 2022
a387627
more reserve removing
instagibbs Aug 3, 2022
573e34a
add check_eltoo_config_bounds
instagibbs Aug 3, 2022
c2efb3c
Create funding script helper, use in funder_channel_start
instagibbs Aug 3, 2022
07a10d6
More openingd compiling
instagibbs Aug 4, 2022
8e438fb
Fixup fromwire_openingd_eltoo_funder_start
instagibbs Aug 4, 2022
e312b81
finish up handle_master_in
instagibbs Aug 4, 2022
4e2d4e4
All FIXMEs except p2p messages done
instagibbs Aug 4, 2022
fc4b5c7
Add eltoo peer wire changes
instagibbs Aug 4, 2022
a2501b6
fixup
instagibbs Aug 4, 2022
5a59fe6
working through compilation....
instagibbs Aug 4, 2022
9fd7208
Partial sig stuff compiling
instagibbs Aug 4, 2022
6c81a17
All wire messages implemented for openingd eltoo
instagibbs Aug 4, 2022
4aad440
Validation wire
instagibbs Aug 4, 2022
7a137c5
Make eltoo BOLT processing more narrow
instagibbs Aug 4, 2022
af02f23
Synchonize sighash usage
instagibbs Aug 5, 2022
a4ac5a8
compiling
instagibbs Aug 5, 2022
bf6263f
both funding paths done?
instagibbs Aug 5, 2022
f8fc3cf
Add nonce to shutdown_eltoo message
instagibbs Aug 9, 2022
b9852f7
Update HSM signing protocol
instagibbs Aug 9, 2022
24ba7bc
Checking
instagibbs Aug 9, 2022
30ee738
fixup
instagibbs Aug 9, 2022
7c68d97
Implement hsm eltoo channel ready msg
instagibbs Aug 9, 2022
711353a
Set hsmd eltoo capabilitiy to HSM_CAP_MASTER
instagibbs Aug 9, 2022
370327d
Start implementing partial signature for update tx in hsmd
instagibbs Aug 9, 2022
d9d0e51
Merge the two peer BOLTs into one CSV
instagibbs Aug 9, 2022
3d5e2b9
Look for ELTOO opener
instagibbs Aug 9, 2022
61064de
Refactor everything to use compressed pubkeys except JIT blockchain u…
instagibbs Aug 10, 2022
31470f9
replyreply
instagibbs Aug 10, 2022
3aa742a
fixup null ptrs for keyagg_cache
instagibbs Aug 10, 2022
753042e
Psigs have stringified
instagibbs Aug 10, 2022
ded1ef3
Don't use eltoo_keyset in openenind, yet
instagibbs Aug 10, 2022
1e26cda
Fixups, why didn't channel reserve stop working long ago....
instagibbs Aug 10, 2022
d8841ff
Generate nonce for channel
instagibbs Aug 10, 2022
1c44885
Get peer_ir and dbid from hsm_client...?
instagibbs Aug 10, 2022
9cd573d
Start adding eltoo channeld stuff
instagibbs Aug 11, 2022
f52ef98
put nonces into keyset
instagibbs Aug 12, 2022
5108aef
put nonces into keyset
instagibbs Aug 12, 2022
96f0309
Stuff compiling, reworked musig session flow
instagibbs Aug 15, 2022
e79488f
Many changes
instagibbs Aug 16, 2022
2ee681c
start compiling
instagibbs Aug 18, 2022
b89649a
more compiling
instagibbs Aug 18, 2022
398a9e9
eltoo_channeld starting to compile
instagibbs Aug 18, 2022
8dc1b52
Adding more files
instagibbs Aug 18, 2022
d92d6a3
get rid of eltoo_channel_config
instagibbs Aug 19, 2022
00006d2
Working on compiling/deduping...
instagibbs Aug 19, 2022
b76ca54
eltoo_channeld compiling
instagibbs Aug 29, 2022
6add5a1
Thread through some more reestablishment state
instagibbs Aug 29, 2022
f17d1a2
fixup extra shared_delay serialization
instagibbs Aug 31, 2022
dede6b7
set eltoo channel to false for now
instagibbs Sep 1, 2022
8228690
More motion towards eltoo fundchannel
instagibbs Sep 1, 2022
82ddc79
fundchannel hanging now
instagibbs Sep 1, 2022
8d5f928
Try threading through settle pubkey from hsmd
instagibbs Sep 2, 2022
262fcad
bunch of stuff
instagibbs Sep 2, 2022
d478da3
keyset shenanigans for opening
instagibbs Sep 2, 2022
a1bd080
keyset shenanigans for opening
instagibbs Sep 2, 2022
a8e78fc
stop sending hsmd messages to peers...
instagibbs Sep 2, 2022
44d4f61
Send eltoo funder_complte msg if appropr
instagibbs Sep 2, 2022
59fee25
more bullish errors
instagibbs Sep 2, 2022
fc74636
workshop delays in config
instagibbs Sep 2, 2022
27973c1
enable printing of partial sigs
instagibbs Sep 2, 2022
68a24bb
nice bug
instagibbs Sep 6, 2022
4fc3a7d
save progress
instagibbs Sep 6, 2022
6269281
Nonces working
instagibbs Sep 6, 2022
a18027d
Maybe will fire off normal channel operation
instagibbs Sep 7, 2022
4a26071
failing at channeld creation :)
instagibbs Sep 7, 2022
ed8ffb5
maybe eltoo_channeld starts
instagibbs Sep 7, 2022
f009304
more settle key stuff
instagibbs Sep 7, 2022
88dd367
Thinking of removing settle_pubkey in favor or remote basepoint
instagibbs Sep 7, 2022
7389f80
Attempt to reuse payment basepoint as settle pubkey
instagibbs Sep 7, 2022
4bbedd3
lock-in sanity checks for 2-of-2 CMS failing
instagibbs Sep 7, 2022
1834977
disable sanity checks and signature announcements for now
instagibbs Sep 7, 2022
a52cc8b
reloading working a bit
instagibbs Sep 7, 2022
95ce0ad
shared_delay seems to be loading properly
instagibbs Sep 7, 2022
76443c8
refactor bind_update_tx_to_* to take bip340sig
instagibbs Sep 8, 2022
a2ec975
onchaind explodes when it sees update tx, yay
instagibbs Sep 8, 2022
0abd204
put obvioulsy bogus prevout in settlement tx instead of funding outpu…
instagibbs Sep 8, 2022
9bb41de
eltoo CHANNELD_NORMAL achieved
instagibbs Sep 8, 2022
4c84903
dev-debgger causing msg issues, working on htlc
instagibbs Sep 12, 2022
adf8dd0
Rework what data is passed from opening to channel... explosions surely
instagibbs Sep 13, 2022
a184877
Back to where I was before with paying invoice broken
instagibbs Sep 13, 2022
2e6e147
Try to move htlc resolution forward
instagibbs Sep 14, 2022
18b26ea
Getting all the way to ACK construction
instagibbs Sep 14, 2022
410aae9
Push forward on responding to updatesig
instagibbs Sep 15, 2022
3ab2be0
ACK being received, stalling after
instagibbs Sep 15, 2022
9c23b7d
Some more ACK handling
instagibbs Sep 15, 2022
b82df52
Checkin HTLC work, MuSig for htlc removal failing
instagibbs Sep 17, 2022
63a3671
Trivial single payment is clearing
instagibbs Sep 19, 2022
d8c36ce
l2-cli now sees the htlc as resolving, working on l1-cli
instagibbs Sep 20, 2022
ff1e92c
HTLCs resolving in *both directions*
instagibbs Sep 20, 2022
a0ab01d
Comment out unknown things
instagibbs Sep 20, 2022
32fb6ae
Remove pubnonce storage from hsmd
instagibbs Sep 21, 2022
e5f3377
Multichannel musig working?
instagibbs Sep 21, 2022
db30ca8
test script with three nodes going
instagibbs Sep 21, 2022
9de5672
single hop example working
instagibbs Sep 22, 2022
f1c696b
Bit more logging for debugging
instagibbs Sep 22, 2022
ea22144
Create eltoo_onchaind, need to auto-rebind update/settle tx still
instagibbs Sep 22, 2022
1ec83e7
Enough to trigger and explode the new subd
instagibbs Sep 22, 2022
1aed83d
eltoo_onchaind is alive
instagibbs Sep 26, 2022
8c4159e
Expose update/settle txs in rpc, propagate txs to onchaind
instagibbs Sep 27, 2022
c75ac6c
RPC endpoint serving up funding-output-bound update/settle txs
instagibbs Sep 27, 2022
b77cbe9
add unbound versions as well
instagibbs Sep 27, 2022
beb88a1
bind first settle transaction as well
instagibbs Sep 27, 2022
811221f
remove comment
instagibbs Sep 28, 2022
a983fe1
rework rebinding a bit
instagibbs Sep 28, 2022
bbed97d
Implement bind_txs_to_funding_outpoint with sane interface for fundin…
instagibbs Sep 28, 2022
076229a
lightning now fires off funding output bound update tx when channel f…
instagibbs Sep 28, 2022
df93b56
eltoo_onchaind: track funding output
instagibbs Sep 28, 2022
90063a1
oops, add eltoo onchaind
instagibbs Sep 28, 2022
25becf2
Compiling with some close handling
instagibbs Sep 29, 2022
a3cdbfd
Stick closer to the legacy flow for now
instagibbs Sep 30, 2022
dfa5c29
Stuff crashing because I'm not handling eltoo_onchaind responses...
instagibbs Sep 30, 2022
32229da
Start handling a bunch more messages
instagibbs Oct 17, 2022
f8bef22
Send committed but not completed transactions to lightningd
instagibbs Nov 14, 2022
0ac56c5
moved around tx signing state to aid support for committed but not co…
instagibbs Nov 14, 2022
9cbe577
f
instagibbs Nov 15, 2022
02056a1
pass around committed state all the way to onchaind
instagibbs Nov 16, 2022
2217e24
Wrong enum for ELTOO_UPDATE
instagibbs Nov 17, 2022
f52db64
Add binding of settlement tx for onchaind
instagibbs Nov 18, 2022
98326e5
Mutual close is locktime of 0
instagibbs Nov 18, 2022
c604c4b
migrate more over to eltoo
instagibbs Nov 18, 2022
446cbee
fixup tx type
instagibbs Nov 18, 2022
e89dfdb
Basic settlement broadcasting works
instagibbs Nov 18, 2022
8eed3b6
Sync up tx format with BOLT, update handling
instagibbs Nov 22, 2022
cb6be2f
Propagate keys to eltoo onchaind
instagibbs Nov 22, 2022
15de384
Fixup state updates in lightningd, both eltoo_onchainds should match …
instagibbs Nov 23, 2022
33eef50
Fixup eltoo_onchaind lifetime of htlc scripts
instagibbs Nov 23, 2022
f2d8ce7
eltoo_onchaind resolves when no htlcs left
instagibbs Nov 28, 2022
1a01914
fixup unit test with updated tx format
instagibbs Nov 30, 2022
65d878a
Add locktime to onchaind_spent message
instagibbs Nov 30, 2022
84c5bfb
test success message
instagibbs Nov 30, 2022
3d6b2ae
maybe support initial rebinding of invalidated update transactions
instagibbs Nov 30, 2022
81051e2
propose fixed update tx
instagibbs Nov 30, 2022
69d0234
Testing out handling old updates for funding output spend
instagibbs Nov 30, 2022
6643e74
add/remove comments
instagibbs Nov 30, 2022
a72daf0
Expose rebound update txns over RPC, fix some bugs
instagibbs Dec 2, 2022
2eca9b1
Add untested hooks to introspect committed settle tx in RPC
instagibbs Dec 2, 2022
07ee5b7
onchaind state machine up to HTLC resolution
instagibbs Dec 5, 2022
130e4f0
Add htlc feerate to eltoo_onchaind
instagibbs Dec 5, 2022
cb34f3f
HTLC timeout resolution implemented except for final witness construc…
instagibbs Dec 7, 2022
cd58de8
Create witness construction for HTLC resolutions
instagibbs Dec 8, 2022
a19b427
Implement HTLC success txns
instagibbs Dec 8, 2022
8e5be4a
Cache preimages prior to settle phase
instagibbs Dec 8, 2022
70b8059
Add schema changes for eltoo json
instagibbs Dec 12, 2022
54ffcae
Start some proper testing of HTLC resolution
instagibbs Dec 12, 2022
4c8adf3
more test
instagibbs Dec 12, 2022
bba5ddd
HTLC resolution crashing now
instagibbs Dec 13, 2022
ccabcde
Stuff to revert?
instagibbs Dec 13, 2022
af80f2b
some notes
instagibbs Dec 13, 2022
8103859
fix ripemd of htlc payment hash, reorder keys for contract
instagibbs Dec 14, 2022
4d6b416
Don't sizeof a pointer...
instagibbs Dec 14, 2022
b5fcb59
fixup add_eltoo_htlc_out side arg, revert key ordering
instagibbs Dec 14, 2022
88b585e
Both HTLC txns being handled... and crashing in hsmd
instagibbs Dec 14, 2022
e961bfb
fixup some hsmd signing stuff
instagibbs Dec 14, 2022
f4853ce
unroll taphashing, more printing
instagibbs Dec 15, 2022
d226c1c
Add more belt and suspender check for tapleafs
instagibbs Dec 15, 2022
84d69c5
WRONG PUBKEYS OMG
instagibbs Dec 15, 2022
144c9db
F
instagibbs Dec 15, 2022
3029ab9
HTLC txns are being mined/replaced
instagibbs Dec 15, 2022
a171fdb
Fix preimage fetching from success tx
instagibbs Dec 16, 2022
6fce49e
Test runs until end... plus memory leaks
instagibbs Dec 16, 2022
862633f
Test runs until end... plus memory leaks
instagibbs Dec 16, 2022
aa4cea3
Test runs until end... plus memory leaks
instagibbs Dec 16, 2022
da845e0
cleanup htlc eltoo test
instagibbs Dec 19, 2022
22701ba
cleanup htlc eltoo test
instagibbs Dec 19, 2022
c200768
Tests for all working scenarioes
instagibbs Dec 19, 2022
f7e0aec
Silence memory leaks
instagibbs Dec 19, 2022
6258943
f
instagibbs Dec 19, 2022
1ef3836
Implement turn-taking ala Simplified Update
instagibbs Dec 20, 2022
5bc8c9c
Fixup eltoo_channeld transaction tracking
instagibbs Dec 21, 2022
240c633
Start implementing reconnection logic
instagibbs Dec 21, 2022
fdbb1fa
Maybe implemented channel reestablishment
instagibbs Jan 4, 2023
23071e3
Start writing test for reestablishment
instagibbs Jan 5, 2023
668e71f
Move eltoo tests to own thing
instagibbs Jan 5, 2023
876ff95
oops s/gen/regen/
instagibbs Jan 5, 2023
53ecd77
test_eltoo_offerer_ack_reestablishment failing with bad combine_psig …
instagibbs Jan 5, 2023
6e83d3c
ostensibly complete basic reestablishment tests
instagibbs Jan 5, 2023
5a9a21b
Fixup committed state in lightningd
instagibbs Jan 6, 2023
8c51c50
test_eltoo_offerer_ack_reestablishment working
instagibbs Jan 6, 2023
2ff8dc3
Add some asserts that should break in other cases
instagibbs Jan 6, 2023
e8d1830
More plausible support for reestablishments during htlc removal
instagibbs Jan 6, 2023
4958e51
Test another uncommited reestablishment scenario
instagibbs Jan 6, 2023
9f9af91
fixup one test where it breaks
instagibbs Jan 6, 2023
5aa9e70
uneven test working, need to cleanup keyagg cache lifecycle
instagibbs Jan 9, 2023
7c5c8fc
Send failures instead of crashing hsmd on combine failure
instagibbs Jan 9, 2023
9dfb3ef
rephrase
instagibbs Jan 9, 2023
23278da
untested: fix the commit-to-no-taptree musig implementation
instagibbs Feb 21, 2023
60b8df2
Revert "untested: fix the commit-to-no-taptree musig implementation"
instagibbs Feb 21, 2023
60a7cc2
Adapt eltoo implementation to bitcoin-inquisition annex support
instagibbs Mar 14, 2023
864ac82
fixup compute_control_block
instagibbs Mar 16, 2023
be3919d
Have update txns get an ephemeral anchor, remove test's prioritisetra…
instagibbs Mar 16, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
url = https://github.com/ianlancetaylor/libbacktrace.git
[submodule "external/libwally-core"]
path = external/libwally-core
url = https://github.com/ElementsProject/libwally-core.git
url = https://github.com/instagibbs/libwally-core.git
ignore = dirty
branch = taproot
[submodule "external/gheap"]
path = external/gheap
url = https://github.com/valyala/gheap
Expand Down
7 changes: 6 additions & 1 deletion .msggen.json
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,10 @@
"ListPeers.peers[].channels[].in_payments_offered": 38,
"ListPeers.peers[].channels[].inflight[]": 13,
"ListPeers.peers[].channels[].initial_feerate": 9,
"ListPeers.peers[].channels[].last_committed_settle_tx": 54,
"ListPeers.peers[].channels[].last_feerate": 10,
"ListPeers.peers[].channels[].last_settle_tx": 51,
"ListPeers.peers[].channels[].last_update_tx": 50,
"ListPeers.peers[].channels[].max_accepted_htlcs": 35,
"ListPeers.peers[].channels[].max_to_us_msat": 22,
"ListPeers.peers[].channels[].max_total_htlc_in_msat": 27,
Expand Down Expand Up @@ -713,7 +716,9 @@
"ListPeers.peers[].channels[].their_reserve_msat": 28,
"ListPeers.peers[].channels[].their_to_self_delay": 33,
"ListPeers.peers[].channels[].to_us_msat": 20,
"ListPeers.peers[].channels[].total_msat": 23
"ListPeers.peers[].channels[].total_msat": 23,
"ListPeers.peers[].channels[].unbound_settle_tx": 53,
"ListPeers.peers[].channels[].unbound_update_tx": 52
},
"ListpeersPeersChannelsFeerate": {
"ListPeers.peers[].channels[].feerate.perkb": 2,
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ PKGLIBEXEC_PROGRAMS = \
lightningd/lightning_hsmd \
lightningd/lightning_onchaind \
lightningd/lightning_openingd \
lightningd/lightning_eltoo_openingd \
lightningd/lightning_websocketd

# Don't delete these intermediaries.
Expand Down
12 changes: 12 additions & 0 deletions bitcoin/psbt.c
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,18 @@ struct amount_sat psbt_input_get_amount(const struct wally_psbt *psbt,
return val;
}

const unsigned char *psbt_input_get_scriptpubkey(const struct wally_psbt *psbt,
size_t in)
{
if (psbt->inputs[in].witness_utxo) {
return psbt->inputs[in].witness_utxo->script;
} else if (psbt->inputs[in].utxo) {
return psbt->inputs[in].utxo->outputs[psbt->tx->inputs[in].index].script;
} else {
abort();
}
}

struct amount_sat psbt_output_get_amount(const struct wally_psbt *psbt,
size_t out)
{
Expand Down
8 changes: 8 additions & 0 deletions bitcoin/psbt.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,14 @@ void psbt_output_set_unknown(const tal_t *ctx,
struct amount_sat psbt_input_get_amount(const struct wally_psbt *psbt,
size_t in);

/* psbt_input_get_scriptpubkey - Returns pointer to the input's scriptPubKey
*
* @psbt - psbt
* in - index of input whose value script returning
*/
const unsigned char *psbt_input_get_scriptpubkey(const struct wally_psbt *psbt,
size_t in);

/* psbt_output_get_amount - Returns the value of this output
*
* @psbt - psbt
Expand Down
38 changes: 38 additions & 0 deletions bitcoin/pubkey.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,32 @@ void towire_point32(u8 **pptr, const struct point32 *point32)
towire(pptr, output, sizeof(output));
}

void fromwire_nonce(const u8 **cursor, size_t *max, struct nonce *nonce)
{
u8 raw[66];

if (!fromwire(cursor, max, raw, sizeof(raw)))
return;

if (!secp256k1_musig_pubnonce_parse(secp256k1_ctx,
&nonce->nonce,
raw)) {
SUPERVERBOSE("not a valid musig nonce");
fromwire_fail(cursor, max);
}
}

void towire_nonce(u8 **pptr, const struct nonce *nonce)
{
u8 nonce_output[66];

secp256k1_musig_pubnonce_serialize(secp256k1_ctx,
nonce_output,
&nonce->nonce);

towire(pptr, nonce_output, sizeof(nonce_output));
}

static char *point32_to_hexstr(const tal_t *ctx, const struct point32 *point32)
{
u8 output[32];
Expand All @@ -159,3 +185,15 @@ static char *point32_to_hexstr(const tal_t *ctx, const struct point32 *point32)
return tal_hexstr(ctx, output, sizeof(output));
}
REGISTER_TYPE_TO_STRING(point32, point32_to_hexstr);

static char *nonce_to_hexstr(const tal_t *ctx, const struct nonce *nonce)
{
u8 nonce_output[66];

secp256k1_musig_pubnonce_serialize(secp256k1_ctx,
nonce_output,
&nonce->nonce);

return tal_hexstr(ctx, nonce_output, sizeof(nonce_output));
}
REGISTER_TYPE_TO_STRING(nonce, nonce_to_hexstr);
9 changes: 9 additions & 0 deletions bitcoin/pubkey.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <ccan/structeq/structeq.h>
#include <ccan/tal/tal.h>
#include <secp256k1_extrakeys.h>
#include <secp256k1_musig.h>

struct privkey;
struct secret;
Expand All @@ -26,6 +27,11 @@ struct point32 {
/* Define pubkey_eq (no padding) */
STRUCTEQ_DEF(point32, 0, pubkey.data);

struct nonce {
/* Un-aggregated public nonce for MuSig2 */
secp256k1_musig_pubnonce nonce;
};

/* Convert from hex string of DER (scriptPubKey from validateaddress) */
bool pubkey_from_hexstr(const char *derstr, size_t derlen, struct pubkey *key);

Expand Down Expand Up @@ -72,4 +78,7 @@ void fromwire_pubkey(const u8 **cursor, size_t *max, struct pubkey *pubkey);
void towire_point32(u8 **pptr, const struct point32 *pubkey);
void fromwire_point32(const u8 **cursor, size_t *max, struct point32 *pubkey);

void towire_nonce(u8 **pptr, const struct nonce *nonce);
void fromwire_nonce(const u8 **cursor, size_t *max, struct nonce *nonce);

#endif /* LIGHTNING_BITCOIN_PUBKEY_H */