Skip to content

feat: support external wallet signing for channel funding#1120

Open
joii2020 wants to merge 34 commits intonervosnetwork:developfrom
joii2020:dev.wasm-signer2
Open

feat: support external wallet signing for channel funding#1120
joii2020 wants to merge 34 commits intonervosnetwork:developfrom
joii2020:dev.wasm-signer2

Conversation

@joii2020
Copy link
Contributor

@joii2020 joii2020 commented Feb 9, 2026

Background

This PR is built on top of #1083.

Fiber currently relies on a CKB private key for initialization and transaction signing, but most Web Wallets do not support private key export.
This PR adds support for opening channels with externally signed funding transactions.

Changes

  • Added two RPCs:
  1. open_channel_with_external_funding
  2. submit_signed_funding_tx
  • open_channel_with_external_funding now returns temporary_channel_id and unsigned_funding_tx
  • Users can sign the transaction externally and submit it via submit_signed_funding_tx
  • Added external-funding state transitions and persistence fields (including schema/store updates)
  • Added signed transaction validation: transaction structure must remain unchanged and the tx must be final
  • Updated RPC docs, fiber-wasm, and fiber-js interfaces accordingly
  • This feature is unaffected even if a CKB private key is configured at startup.
  • The channel negotiation flow is still preserved; only funding transaction signing is moved to an external wallet (via open_channel_with_external_funding + submit_signed_funding_tx).
  • e2e test: tests/bruno/e2e/external-funding-open/

Impact

No change to the existing open_channel flow; this only adds a new external-funding path.

e2e test

Because an external signature is required, the e2e test is not placed in CI and can be executed manually:

REMOVE_OLD_STATE=y ./tests/nodes/start.sh e2e/external-funding-open

Execute in another terminal:

# Need to wait for the node to be init
./tests/nodes/wait.sh

./tests/bruno/e2e/external-funding-open/run-success-flow.sh

@joii2020 joii2020 force-pushed the dev.wasm-signer2 branch 2 times, most recently from d03759a to 7aac5c9 Compare February 12, 2026 15:05
@joii2020 joii2020 changed the title [WIP] feat: support external wallet signing for channel funding feat: support external wallet signing for channel funding Feb 26, 2026
joii2020 and others added 25 commits March 4, 2026 08:43
Implement RPC endpoints that allow users to open payment channels by signing
funding transactions with their own external wallets, instead of having the
node automatically sign with its private key.

New RPC methods:
- open_channel_with_external_funding: negotiates channel with peer and returns
  unsigned funding tx for user to sign externally
- submit_signed_funding_tx: accepts signed tx and completes channel opening

Key changes:
- Add AwaitingExternalFunding channel state for channels waiting for user signature
- Add ExternalFundingTxBuilder to build unsigned funding transactions
- Add BuildUnsignedFundingTx message to CKB chain actor
- Add timeout mechanism for external funding (reuses existing funding timeout)
- Update RPC documentation with new endpoints

(cherry picked from commit f6f6dd2)
Co-authored-by: Cursor <cursoragent@cursor.com>
…ingTxBuilder

Extract duplicated methods into shared free functions:
- collect_udt_inputs_outputs: UDT cell collection logic
- build_base_from_funding_cell: common build_base_async logic
- build_and_balance_tx: CKB RPC balance/unlock logic
- finalize_funding_tx_update: FundingTx update + exclusion map

This eliminates ~150 lines of duplicated code while keeping
build_funding_cell separate since the two builders have
legitimately different funding cell construction logic.

Co-authored-by: Cursor <cursoragent@cursor.com>
Add clarifying comments to two independent fixes that were included
in this branch but are unrelated to external funding:

1. restore_missing_revocation_send_nonce: fixes deadlock during
   channel reestablishment when send nonce is lost during persistence
2. On-the-fly channel reestablish in ChannelNormalOperation handler:
   prevents messages from being dropped after reconnect

These should ideally be reviewed/cherry-picked separately.

Co-authored-by: Cursor <cursoragent@cursor.com>
…ngth

The assert!(data.as_ref().len() >= 16) in is_tx_final would panic if
an externally-submitted funding transaction had malformed UDT output
data. Replace with a proper InvalidParameter error return since this
code path is now exposed to external input via external funding.

Co-authored-by: Cursor <cursoragent@cursor.com>
Document why the runtime JS object patching is needed (CKB dep_type
naming inconsistency between camelCase and snake_case across different
SDKs/wallets) and add a TODO for a proper serde-layer fix.

Co-authored-by: Cursor <cursoragent@cursor.com>
POSIX text files should end with a newline character.

Co-authored-by: Cursor <cursoragent@cursor.com>
Move external funding runtime context out of ChannelActorState persistence and store it in ChannelEphemeralConfig, so open_channel_with_external_funding -> submit_signed_funding_tx no longer writes local channel state.

Also keep ChannelState bincode compatibility by appending AwaitingExternalFunding variant, and update tests/samples accordingly.
joii2020 added 8 commits March 4, 2026 08:47
…heck

Replace panic-inducing assert! with a proper error return when UDT
output data is shorter than expected. This prevents node crash
when processing malformed transactions.

This is an independent bug fix unrelated to external funding.
Fix a deadlock during channel reestablishment when the send nonce
is lost during persistence (e.g., consumed before state was saved).
Restore it from verify/next nonces if available.

This is an independent bug fix unrelated to external funding.
If a channel message arrives for a channel not yet tracked in
session_channels_map (e.g., after reconnect), attempt to reestablish
it on-the-fly so the message is not dropped.

This is an independent bug fix unrelated to external funding.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant