Add BIP-0322 message signing to `SignMessageWithAddr` RPC #10798
Summary of Changes
Hello, I'm Gemini Code Assist[^1]! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request implements the BIP-0322 standard for generic message signing within the lnd wallet. It enables users to sign and verify messages using the standardized BIP-0322 format, significantly improving compatibility across various address types, including Taproot. The changes encompass updates to the RPC layer, CLI commands, and protobuf definitions, supported by comprehensive integration tests to ensure cross-format reliability.
Highlights
BIP-0322 Support: Added support for the BIP-0322 Generic Signed Message Format in the SignMessageWithAddr and VerifyMessageWithAddr RPCs.
CLI Update: Introduced the --bip322 flag to the lncli wallet addresses signmessage command to enable standardized message signing.
RPC Schema Changes: Updated the walletrpc protobuf definitions to include MsgSignatureType and MsgSignatureTimeConstraints for improved signature reporting.
Testing: Expanded integration tests to validate both legacy and BIP-0322 signature formats across P2WKH, NP2WKH, and P2TR address types.
<details>
<summary><b>New Features</b></summary>
🧠 You can now enable Memory (public preview) to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.
</details>
<details>
<summary><b>Using Gemini Code Assist</b></summary>
<br>
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
<b>Invoking Gemini</b>
You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.
Feature | Command | Description
--- | --- | ---
Code Review | /gemini review | Performs a code review for the current pull request in its current state.
Pull Request Summary | /gemini summary | Provides a summary of the current pull request in its current state.
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help | /gemini help | Displays a list of available commands.
<b>Customization</b>
To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
<b>Limitations & Feedback</b>
Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with :thumbsup: and :thumbsdown: on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.
</details>
[^1]: Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.
🟠 PR Severity: HIGH
Highest-severity file: lnrpc/walletrpc/walletkit_server.go | 7 files (non-test/non-generated) | 456 lines changed<details>
<summary>🟠 <strong>High</strong> (1 file)</summary>
lnrpc/walletrpc/walletkit_server.go - RPC server implementation in lnrpc/</details>
<details>
<summary>🟡 <strong>Medium</strong> (5 files)</summary>
lnrpc/walletrpc/walletkit.proto - .proto API definition (API change)lnrpc/walletrpc/walletkit.swagger.json - Swagger/OpenAPI definitioncmd/commands/walletrpc_active.go - CLI client command (cmd/, not server-side)go.mod - Go module dependency updatego.sum - Go module checksum update</details>
<details>
<summary>🟢 <strong>Low</strong> (2 files, excluded from counts)</summary>
docs/release-notes/release-notes-0.22.0.md - Release notesitest/lnd_misc_test.go - Integration test file</details>
<details>
<summary>⚙️ <strong>Auto-generated</strong> (2 files, excluded from counts)</summary>
lnrpc/walletrpc/walletkit.pb.go - Protobuf generated codelnrpc/walletrpc/walletkit_grpc.pb.go - Protobuf gRPC generated code</details>
Analysis
This PR modifies the walletrpc RPC subsystem, with the primary severity driver being walletkit_server.go — the server-side implementation of the WalletKit gRPC service (lnrpc/). It also updates the .proto definition and Swagger spec, indicating a new or changed RPC method is being introduced (181 additions in the server file alongside 78 proto additions suggest a meaningful API expansion).
The cmd/commands/walletrpc_active.go file is CLI client code under cmd/ and is correctly classified as MEDIUM regardless of the walletrpc name in the path.
Severity bump check:
No severity bump triggered; HIGH is the final classification based on the lnrpc/* server implementation change.
---
<sub>To override, add a severity-override-{critical,high,medium,low} label.</sub>
<\!-- pr-severity-bot -->
Code Review
This pull request implements support for the BIP-0322 Generic Signed Message Format, adding a --bip322 flag to the signmessage command and updating verifymessage to automatically detect and validate the new format. The changes span RPC definitions, server-side implementation, and integration tests. Feedback identifies a missing errors package import and a potential nil pointer dereference when handling signature constraints. It is also recommended to use more descriptive error messages for unsupported address types to improve the user experience.
!high
The errors package is used in VerifyMessageWithAddr (line 2906) but is not imported in this file. This will cause a compilation error.
"errors"
"github.com/btcsuite/btcd/btcec/v2/ecdsa"
"github.com/btcsuite/btcd/btcec/v2/schnorr"
"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/btcutil/bip322"
!high
The constraints variable is a pointer returned by bip322.VerifyMessage. If it is nil (which can happen for simple signatures that have no constraints), accessing constraints.Constrained will cause a panic. A nil check should be added before accessing its fields.
if constraints != nil && constraints.Constrained {
The error message uses %T to display the Go type of the address, which is not very descriptive for an RPC user. Additionally, this implementation currently only supports SegWit address types for BIP-0322 signing. It would be better to provide a more user-friendly error message and explicitly mention that legacy P2PKH addresses are not supported for this format yet.
default:
err = fmt.Errorf("unsupported address type for BIP-0322 "+
"signing: %T", pubKeyAddr.Address())
It was already imported.
It's not a pointer.
This should never happen in the first place.
Is the temporary psbt replacement required for this PR as well, or is it only needed internally by the custom bip322 dependency?
Would it make sense to also add a few negative-path integration tests for the new BIP-0322 flow (for example modified messages, malformed signatures, or verification against the wrong address)?
The implementation added several new validation/error branches that currently don't appear to be exercised here.
Update: I’ve checked again and confirmed that the related PR in btcd does touch PSBT, so this replace directive is expected here. My earlier question is resolved.
⚠️ Severity changed: severity-high → severity-critical (files changed since last classification)
🔴 PR Severity: CRITICAL
Automated classification | 7 files (non-test, non-generated) | 506 lines changed
<details>
<summary>🟠 <strong>High</strong> (1 file — drives base severity)</summary>
lnrpc/walletrpc/walletkit_server.go — RPC server implementation under lnrpc/</details>
<details>
<summary>🟡 <strong>Medium</strong> (4 files)</summary>
cmd/commands/walletrpc_active.go — CLI client command under cmd/go.mod — dependency manifestgo.sum — dependency checksumslnrpc/walletrpc/walletkit.proto — API definition (.proto file)lnrpc/walletrpc/walletkit.swagger.json — Swagger/OpenAPI spec</details>
<details>
<summary>🟢 <strong>Low</strong> (excluded from count)</summary>
docs/release-notes/release-notes-0.22.0.md — release notes (docs/)itest/lnd_misc_test.go — integration test (itest/)itest/lnd_psbt_test.go — integration test (itest/)</details>
<details>
<summary>⚙️ <strong>Auto-generated</strong> (excluded from count)</summary>
lnrpc/walletrpc/walletkit.pb.go — protobuf generated (.pb.go)lnrpc/walletrpc/walletkit_grpc.pb.go — protobuf gRPC generated (.pb.go)</details>
Analysis
The highest-severity non-generated file is lnrpc/walletrpc/walletkit_server.go in the lnrpc/ package, establishing a base severity of HIGH.
A severity bump is triggered because the non-test, non-auto-generated line count reaches 506 lines (threshold: >500). Breakdown: walletkit_server.go (212) + walletkit.proto (97) + walletrpc_active.go (70) + walletkit.swagger.json (56) + go.sum (38) + go.mod (25) + release notes (8) = 506.
This bumps the severity from HIGH → CRITICAL, requiring expert review. The PR extends the walletkit RPC service with new proto definitions and server-side logic, which touches the public API surface and server implementation of the wallet kit subsystem.
---
<sub>To override, add a severity-override-{critical,high,medium,low} label.</sub>
<\!-- pr-severity-bot -->
Good idea, done.
Yes, and with the latest changes to the implementation, the txscript module is also touched by https://github.com/btcsuite/btcd/pull/2521.
This PR still depends on https://github.com/btcsuite/btcd/pull/2521, but is otherwise ready to review.
@guggero, remember to re-request review from reviewers when ready
@guggero, remember to re-request review from reviewers when ready
@guggero, remember to re-request review from reviewers when ready
@guggero, remember to re-request review from reviewers when ready
@guggero, remember to re-request review from reviewers when ready
@guggero, remember to re-request review from reviewers when ready
Rebased and updated to latest version of https://github.com/btcsuite/btcd/pull/2521.
⚠️ Severity changed: severity-critical → severity-high (files changed since last classification)
🟠 PR Severity: HIGH
Automated classification | 7 files (non-test, non-generated) | 472 lines changed
<details>
<summary>🟠 <strong>High</strong> (1 file — drives base severity)</summary>
lnrpc/walletrpc/walletkit_server.go — RPC server implementation under lnrpc/</details>
<details>
<summary>🟡 <strong>Medium</strong> (4 files)</summary>
cmd/commands/walletrpc_active.go — CLI client command under cmd/go.mod — dependency manifestgo.sum — dependency checksumslnrpc/walletrpc/walletkit.proto — API definition (.proto file)lnrpc/walletrpc/walletkit.swagger.json — Swagger/OpenAPI spec</details>
<details>
<summary>🟢 <strong>Low</strong> (excluded from count)</summary>
docs/release-notes/release-notes-0.22.0.md — release notes (docs/)itest/lnd_misc_test.go — integration test (itest/)itest/lnd_psbt_test.go — integration test (itest/)</details>
<details>
<summary>⚙️ <strong>Auto-generated</strong> (excluded from count)</summary>
lnrpc/walletrpc/walletkit.pb.go — protobuf generated (.pb.go)lnrpc/walletrpc/walletkit_grpc.pb.go — protobuf gRPC generated (.pb.go)</details>
Analysis
The highest-severity non-generated file is lnrpc/walletrpc/walletkit_server.go in the lnrpc/ package, giving a base severity of HIGH.
Since the last classification, the PR was rebased and the diff shrank: non-test, non-auto-generated line count is now 472 lines (down from 506), which is below the >500 bump threshold. File count (7) also remains below the >20 threshold, and no distinct CRITICAL-tier packages (e.g. lnwallet/, channeldb/, keychain/*) are touched. No bump is triggered this time, so the severity moves back down from CRITICAL to HIGH.
The change still extends the walletkit RPC service (new proto fields, server-side BIP-322 signing/verification logic) and touches the public API surface, warranting review by a knowledgeable engineer.
---
<sub>To override, add a severity-override-{critical,high,medium,low} label.</sub>
<!-- pr-severity-bot -->
@guggero, remember to re-request review from reviewers when ready
@guggero, remember to re-request review from reviewers when ready
@guggero, remember to re-request review from reviewers when ready
@guggero, remember to re-request review from reviewers when ready
@guggero, remember to re-request review from reviewers when ready
@guggero, remember to re-request review from reviewers when ready
@guggero, remember to re-request review from reviewers when ready
@guggero, remember to re-request review from reviewers when ready
@guggero, remember to re-request review from reviewers when ready
guggero
This PR depends on https://github.com/btcsuite/btcd/pull/2521.
Change Description
The BIP-0322 was recently moved to status "Complete", which means wallets can finally implement it without needing to worry about breaking changes in the protocol.
Steps to Test
Pull Request Checklist
Testing
Code Style and Documentation
[skip ci]in the commit message for small changes.📝 Please see our Contribution Guidelines for further guidance.