← Back to Pull requests

Add BIP-0322 message signing to `SignMessageWithAddr` RPC #10798

Open
guggero opened this pull request with 1600 lines diff across 11 files
View on GitHub
guggero guggero commented on May 09, 2026 15:25 UTC
Author

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

# New Taproot address
$ lncli newaddress p2tr
{
    "address":  "bcrt1p9e5rsfm0c0nrx88jvgu0lr6rfrdryzmy2uj74n4pxlgpm7nsnsrssll0z8"
}

# Legacy format
$ lncli wallet addresses signmessage bcrt1p9e5rsfm0c0nrx88jvgu0lr6rfrdryzmy2uj74n4pxlgpm7nsnsrssll0z8 "foo bar"
{
    "signature":  "ICMQCUOIgoumLJ/i9lxcZ88nvyxVPLBaNVKQqyYVe0ArUuSw7Hqg1aeyELxtdVZHcEAirnlM1CJ4ZiWrYYZHejA="
}

$ lncli wallet addresses verifymessage bcrt1p9e5rsfm0c0nrx88jvgu0lr6rfrdryzmy2uj74n4pxlgpm7nsnsrssll0z8 ICMQCUOIgoumLJ/i9lxcZ88nvyxVPLBaNVKQqyYVe0ArUuSw7Hqg1aeyELxtdVZHcEAirnlM1CJ4ZiWrYYZHejA= "foo bar"
{
    "valid":  true,
    "pubkey":  "022d2ae0b1b0c96accdaae08c6323134568528ece23df5900d9e702916e1e5e980",
    "signature_type":  "MSG_SIGNATURE_TYPE_LEGACY",
    "time_constraints":  null
}

# BIP-0322 format
$ lncli wallet addresses signmessage bcrt1p9e5rsfm0c0nrx88jvgu0lr6rfrdryzmy2uj74n4pxlgpm7nsnsrssll0z8 "foo bar" --bip322
{
    "signature":  "smpAUCaDN4rmBK51+sF3ItMqnqAYhPh4ofAZdRuWnSA7WPcnnntCkCuqHcZAj01So5JyA1bZ6CXp2wa8bAZKut5L+g0"
}

$ lncli wallet addresses verifymessage bcrt1p9e5rsfm0c0nrx88jvgu0lr6rfrdryzmy2uj74n4pxlgpm7nsnsrssll0z8 smpAUCaDN4rmBK51+sF3ItMqnqAYhPh4ofAZdRuWnSA7WPcnnntCkCuqHcZAj01So5JyA1bZ6CXp2wa8bAZKut5L+g0 "foo bar"
{
    "valid":  true,
    "pubkey":  "",
    "signature_type":  "MSG_SIGNATURE_TYPE_BIP0322_SIMPLE",
    "time_constraints":  null
}

# Incorrect message / invalid signature
$ lncli wallet addresses verifymessage bcrt1p9e5rsfm0c0nrx88jvgu0lr6rfrdryzmy2uj74n4pxlgpm7nsnsrssll0z8 smpAUCaDN4rmBK51+sF3ItMqnqAYhPh4ofAZdRuWnSA7WPcnnntCkCuqHcZAj01So5JyA1bZ6CXp2wa8bAZKut5L+g0 "foo barz"
{
    "valid":  false,
    "pubkey":  "",
    "signature_type":  "MSG_SIGNATURE_TYPE_BIP0322_SIMPLE",
    "time_constraints":  null
}

# Invalid signature format
$ lncli wallet addresses verifymessage bcrt1p9e5rsfm0c0nrx88jvgu0lr6rfrdryzmy2uj74n4pxlgpm7nsnsrssll0z8 smpAUCaDN4rmBK51+sF3ItMqnqAYhPh4ofAZaaaaaaaaaaaaaaaaaaaaaaa "foo bar" 
[lncli] rpc error: code = Unknown desc = unable to verify message: error parsing signature as witness: witness item length 64 exceeds remaining input 61


Pull Request Checklist


Testing


  • [X] Your PR passes all CI checks.

  • [X] Tests covering the positive and negative (error paths) are included.

  • [X] Bug fixes contain tests triggering the bug to prevent regressions.
  • Code Style and Documentation


  • [X] The change is not insubstantial. Typo fixes are not accepted to fight bot spam.

  • [X] The change obeys the Code Documentation and Commenting guidelines, and lines wrap at 80.

  • [X] Commits follow the Ideal Git Commit Structure.

  • [X] Any new logging statements use an appropriate subsystem and logging level.

  • [X] Any new lncli commands have appropriate tags in the comments for the rpc in the proto file.

  • [X] There is a change description in the release notes, or [skip ci] in the commit message for small changes.
  • 📝 Please see our Contribution Guidelines for further guidance.

    Diff: 1600 lines (+1084 / -516) across 11 files Reviewer: guggero Review duration: 285472m
    All Vouch review confidence checks passed
    Residual risk 0.14 = Change Risk (0.79) × (1 − Review Confidence (0.82)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.79 · 1600 lines diff across 11 files
    0.79
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.92 · 5 substantive comment(s)
    0.92
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    82%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.400
    Self Review self_review
    0.140
    Real PR Conversation Timeline
    34 items
    gemini-code-assist[bot] gemini-code-assist[bot] commented on May 09, 2026 15:25 UTC
    Bot

    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.

    github-actions[bot] github-actions[bot] commented on May 09, 2026 15:27 UTC
    Bot

    🟠 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 definition

  • cmd/commands/walletrpc_active.go - CLI client command (cmd/, not server-side)

  • go.mod - Go module dependency update

  • go.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 notes

  • itest/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 code

  • lnrpc/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:

  • Files (non-test/non-generated): 7 — below the 20-file threshold

  • Lines changed (non-test/non-generated): 456 — below the 500-line threshold

  • No multiple distinct critical packages touched
  • 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 -->

    gemini-code-assist[bot] gemini-code-assist[bot] commented on May 09, 2026 15:29 UTC
    Reviewer

    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.

    gemini-code-assist[bot] gemini-code-assist[bot] commented on code on May 09, 2026 15:30 UTC
    Code Review
    lnrpc/walletrpc/walletkit_server.go:1
    @@ -22,6 +22,7 @@ import (
     	"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"
     	"github.com/btcsuite/btcd/btcutil/hdkeychain"
     	"github.com/btcsuite/btcd/btcutil/psbt"
     	"github.com/btcsuite/btcd/chaincfg/chainhash"

    !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"
    

    gemini-code-assist[bot] gemini-code-assist[bot] commented on code on May 09, 2026 15:30 UTC
    Code Review
    lnrpc/walletrpc/walletkit_server.go:1
    @@ -2779,23 +2828,136 @@ func (w *WalletKit) SignMessageWithAddr(_ context.Context,
     	}, nil
     }
     
    -// VerifyMessageWithAddr verifies a signature on a message with a provided
    -// address, it checks both the validity of the signature itself and then
    -// verifies whether the signature corresponds to the public key of the
    -// provided address. There is no dependence on the private key of the address
    -// therefore also external addresses are allowed to verify signatures.
    +// msgSignatureType returns the RPC message signature type for a given signature
    +// prefix and true if the type is a BIP-0322 signature type.
    +func msgSignatureType(prefix string) (MsgSignatureType, bool) {
    +	switch prefix {
    +	case bip322.PrefixSimple:
    +		return MsgSignatureType_MSG_SIGNATURE_TYPE_BIP0322_SIMPLE, true
    +
    +	case bip322.PrefixFull:
    +		return MsgSignatureType_MSG_SIGNATURE_TYPE_BIP0322_FULL, true
    +
    +	case bip322.PrefixProofOfFunds:
    +		return MsgSignatureType_MSG_SIGNATURE_TYPE_BIP0322_POF, true
    +
    +	default:
    +		return MsgSignatureType_MSG_SIGNATURE_TYPE_LEGACY, false
    +	}
    +}
    +
    +// VerifyMessageWithAddr returns the validity and the recovered public key of
    +// the provided compact signature (base64 encoded). The verification is
    +// twofold. First, the validity of the signature itself is checked, and then
    +// it is verified that the recovered public key of the signature equals
    +// the public key of the provided address. There is no dependence on the
    +// private key of the address. Therefore, also external addresses are allowed
    +// to verify signatures.
     // Supported address types are P2PKH, P2WKH, NP2WKH, P2TR.
    +//
    +// This method is the counterpart of the related signing method
    +// (SignMessageWithAddr) and aims to provide full compatibility to
    +// bitcoin-core's implementation. Although bitcoin-core/btcd only provide
    +// this functionality for legacy addresses this function enhances it to
    +// the address types: P2PKH, P2WKH, NP2WKH, P2TR.
    +//
    +// The verification for P2TR addresses is a special case and requires the
    +// ECDSA compact signature to compare the recovered public key to the internal
    +// taproot key. The compact ECDSA signature format was used because there
    +// are still no known compact signature schemes for schnorr signatures.
     func (w *WalletKit) VerifyMessageWithAddr(_ context.Context,
     	req *VerifyMessageWithAddrRequest) (*VerifyMessageWithAddrResponse,
     	error) {
     
    +	addr, err := btcutil.DecodeAddress(req.Addr, w.cfg.ChainParams)
    +	if err != nil {
    +		return nil, fmt.Errorf("unable to decode address: %w", err)
    +	}
    +
    +	if !addr.IsForNet(w.cfg.ChainParams) {
    +		return nil, fmt.Errorf("encoded address is for"+
    +			"the wrong network %s", req.Addr)
    +	}
    +
    +	// A valid signature is always more than three characters long,
    +	// independent of the format.
    +	if len(req.Signature) < 3 {
    +		return nil, fmt.Errorf("signature is too short")
    +	}
    +
    +	msg := string(req.Msg)
    +	prefix := req.Signature[:3]
    +	rpcSigType, isBip322 := msgSignatureType(prefix)
    +
    +	// If the signature has a BIP-0322 prefix, we require it to be valid in
    +	// that format.
    +	if isBip322 {
    +		valid, constraints, err := bip322.VerifyMessage(
    +			msg, addr, req.Signature,
    +		)
    +
    +		// In the BIP-0322 library, the `valid` return value is only
    +		// ever true if there is no error. Or, expressed in another way,
    +		// we could only look at the error itself.
    +		switch {
    +		// The witness stack couldn't be validated, which means the
    +		// signature itself is incorrect (but everything else was
    +		// formally correct).
    +		case errors.Is(err, bip322.ErrInvalidSignature):
    +			log.Infof("Message signature validation failed with "+
    +				"invalid signature error: %v", err)
    +			return &VerifyMessageWithAddrResponse{
    +				Valid:         false,
    +				SignatureType: rpcSigType,
    +			}, nil
    +
    +		// Any other error means something in the signature format was
    +		// not correct.
    +		case err != nil:
    +			return nil, fmt.Errorf("unable to verify message: %w",
    +				err)
    +
    +		// No error, the signature should be valid.
    +		default:
    +			var rpcConstraints *MsgSignatureTimeConstraints
    +			if constraints.Constrained {

    !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 {
    

    gemini-code-assist[bot] gemini-code-assist[bot] commented on code on May 09, 2026 15:30 UTC
    Code Review
    lnrpc/walletrpc/walletkit_server.go:1
    @@ -2757,18 +2774,50 @@ func (w *WalletKit) SignMessageWithAddr(_ context.Context,
     		return nil, err
     	}
     
    -	// For all address types (P2WKH, NP2WKH,P2TR) the ECDSA compact signing
    -	// algorithm is used. For P2TR addresses this represents a special case.
    -	// ECDSA is used to create a compact signature which makes the public
    -	// key of the signature recoverable. For Schnorr no known compact
    -	// signing algorithm exists yet.
    -	privKey, err := pubKey.PrivKey()
    +	// For all address types (P2WKH, NP2WKH, P2TR) the ECDSA compact signing
    +	// algorithm is used, if the legacy format is chosen. For P2TR addresses
    +	// this represents a special case. ECDSA is used to create a compact
    +	// signature which makes the public key of the signature recoverable.
    +	// For Schnorr no known compact signing algorithm exists yet.
    +	privKey, err := pubKeyAddr.PrivKey()
     	if err != nil {
     		return nil, fmt.Errorf("no private key could be "+
     			"fetched from wallet database: %w", err)
     	}
     
    -	sigBytes := ecdsa.SignCompact(privKey, digest, pubKey.Compressed())
    +	// Branch off for BIP-0322 signatures, which are produced slightly
    +	// differently and depend on the actual address type.
    +	if req.Bip322 {
    +		var (
    +			msg = string(req.Msg)
    +			sig string
    +			err error
    +		)
    +		switch pubKeyAddr.Address().(type) {
    +		case *btcutil.AddressScriptHash:
    +			sig, err = bip322.SignNestedP2WPKH(msg, privKey)
    +
    +		case *btcutil.AddressWitnessPubKeyHash:
    +			sig, err = bip322.SignP2WPKH(msg, privKey)
    +
    +		case *btcutil.AddressTaproot:
    +			sig, err = bip322.SignP2TR(msg, privKey)
    +
    +		default:
    +			err = fmt.Errorf("unexpected address type from "+
    +				"internal wallet: %T", pubKeyAddr.Address())

    !medium

    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())
    

    guggero guggero commented on code on May 09, 2026 16:15 UTC
    Code Review
    lnrpc/walletrpc/walletkit_server.go:1
    @@ -22,6 +22,7 @@ import (
     	"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"
     	"github.com/btcsuite/btcd/btcutil/hdkeychain"
     	"github.com/btcsuite/btcd/btcutil/psbt"
     	"github.com/btcsuite/btcd/chaincfg/chainhash"

    It was already imported.

    guggero guggero commented on code on May 09, 2026 16:15 UTC
    Code Review
    lnrpc/walletrpc/walletkit_server.go:1
    @@ -2779,23 +2828,136 @@ func (w *WalletKit) SignMessageWithAddr(_ context.Context,
     	}, nil
     }
     
    -// VerifyMessageWithAddr verifies a signature on a message with a provided
    -// address, it checks both the validity of the signature itself and then
    -// verifies whether the signature corresponds to the public key of the
    -// provided address. There is no dependence on the private key of the address
    -// therefore also external addresses are allowed to verify signatures.
    +// msgSignatureType returns the RPC message signature type for a given signature
    +// prefix and true if the type is a BIP-0322 signature type.
    +func msgSignatureType(prefix string) (MsgSignatureType, bool) {
    +	switch prefix {
    +	case bip322.PrefixSimple:
    +		return MsgSignatureType_MSG_SIGNATURE_TYPE_BIP0322_SIMPLE, true
    +
    +	case bip322.PrefixFull:
    +		return MsgSignatureType_MSG_SIGNATURE_TYPE_BIP0322_FULL, true
    +
    +	case bip322.PrefixProofOfFunds:
    +		return MsgSignatureType_MSG_SIGNATURE_TYPE_BIP0322_POF, true
    +
    +	default:
    +		return MsgSignatureType_MSG_SIGNATURE_TYPE_LEGACY, false
    +	}
    +}
    +
    +// VerifyMessageWithAddr returns the validity and the recovered public key of
    +// the provided compact signature (base64 encoded). The verification is
    +// twofold. First, the validity of the signature itself is checked, and then
    +// it is verified that the recovered public key of the signature equals
    +// the public key of the provided address. There is no dependence on the
    +// private key of the address. Therefore, also external addresses are allowed
    +// to verify signatures.
     // Supported address types are P2PKH, P2WKH, NP2WKH, P2TR.
    +//
    +// This method is the counterpart of the related signing method
    +// (SignMessageWithAddr) and aims to provide full compatibility to
    +// bitcoin-core's implementation. Although bitcoin-core/btcd only provide
    +// this functionality for legacy addresses this function enhances it to
    +// the address types: P2PKH, P2WKH, NP2WKH, P2TR.
    +//
    +// The verification for P2TR addresses is a special case and requires the
    +// ECDSA compact signature to compare the recovered public key to the internal
    +// taproot key. The compact ECDSA signature format was used because there
    +// are still no known compact signature schemes for schnorr signatures.
     func (w *WalletKit) VerifyMessageWithAddr(_ context.Context,
     	req *VerifyMessageWithAddrRequest) (*VerifyMessageWithAddrResponse,
     	error) {
     
    +	addr, err := btcutil.DecodeAddress(req.Addr, w.cfg.ChainParams)
    +	if err != nil {
    +		return nil, fmt.Errorf("unable to decode address: %w", err)
    +	}
    +
    +	if !addr.IsForNet(w.cfg.ChainParams) {
    +		return nil, fmt.Errorf("encoded address is for"+
    +			"the wrong network %s", req.Addr)
    +	}
    +
    +	// A valid signature is always more than three characters long,
    +	// independent of the format.
    +	if len(req.Signature) < 3 {
    +		return nil, fmt.Errorf("signature is too short")
    +	}
    +
    +	msg := string(req.Msg)
    +	prefix := req.Signature[:3]
    +	rpcSigType, isBip322 := msgSignatureType(prefix)
    +
    +	// If the signature has a BIP-0322 prefix, we require it to be valid in
    +	// that format.
    +	if isBip322 {
    +		valid, constraints, err := bip322.VerifyMessage(
    +			msg, addr, req.Signature,
    +		)
    +
    +		// In the BIP-0322 library, the `valid` return value is only
    +		// ever true if there is no error. Or, expressed in another way,
    +		// we could only look at the error itself.
    +		switch {
    +		// The witness stack couldn't be validated, which means the
    +		// signature itself is incorrect (but everything else was
    +		// formally correct).
    +		case errors.Is(err, bip322.ErrInvalidSignature):
    +			log.Infof("Message signature validation failed with "+
    +				"invalid signature error: %v", err)
    +			return &VerifyMessageWithAddrResponse{
    +				Valid:         false,
    +				SignatureType: rpcSigType,
    +			}, nil
    +
    +		// Any other error means something in the signature format was
    +		// not correct.
    +		case err != nil:
    +			return nil, fmt.Errorf("unable to verify message: %w",
    +				err)
    +
    +		// No error, the signature should be valid.
    +		default:
    +			var rpcConstraints *MsgSignatureTimeConstraints
    +			if constraints.Constrained {

    It's not a pointer.

    guggero guggero commented on code on May 09, 2026 16:15 UTC
    Code Review
    lnrpc/walletrpc/walletkit_server.go:1
    @@ -2757,18 +2774,50 @@ func (w *WalletKit) SignMessageWithAddr(_ context.Context,
     		return nil, err
     	}
     
    -	// For all address types (P2WKH, NP2WKH,P2TR) the ECDSA compact signing
    -	// algorithm is used. For P2TR addresses this represents a special case.
    -	// ECDSA is used to create a compact signature which makes the public
    -	// key of the signature recoverable. For Schnorr no known compact
    -	// signing algorithm exists yet.
    -	privKey, err := pubKey.PrivKey()
    +	// For all address types (P2WKH, NP2WKH, P2TR) the ECDSA compact signing
    +	// algorithm is used, if the legacy format is chosen. For P2TR addresses
    +	// this represents a special case. ECDSA is used to create a compact
    +	// signature which makes the public key of the signature recoverable.
    +	// For Schnorr no known compact signing algorithm exists yet.
    +	privKey, err := pubKeyAddr.PrivKey()
     	if err != nil {
     		return nil, fmt.Errorf("no private key could be "+
     			"fetched from wallet database: %w", err)
     	}
     
    -	sigBytes := ecdsa.SignCompact(privKey, digest, pubKey.Compressed())
    +	// Branch off for BIP-0322 signatures, which are produced slightly
    +	// differently and depend on the actual address type.
    +	if req.Bip322 {
    +		var (
    +			msg = string(req.Msg)
    +			sig string
    +			err error
    +		)
    +		switch pubKeyAddr.Address().(type) {
    +		case *btcutil.AddressScriptHash:
    +			sig, err = bip322.SignNestedP2WPKH(msg, privKey)
    +
    +		case *btcutil.AddressWitnessPubKeyHash:
    +			sig, err = bip322.SignP2WPKH(msg, privKey)
    +
    +		case *btcutil.AddressTaproot:
    +			sig, err = bip322.SignP2TR(msg, privKey)
    +
    +		default:
    +			err = fmt.Errorf("unexpected address type from "+
    +				"internal wallet: %T", pubKeyAddr.Address())

    This should never happen in the first place.

    TechLateef TechLateef commented on code on May 10, 2026 08:29 UTC
    Code Review
    go.mod:1
    @@ -221,6 +222,13 @@ replace github.com/gogo/protobuf => github.com/gogo/protobuf v1.3.2
     // allows us to specify that as an option.
     replace google.golang.org/protobuf => github.com/lightninglabs/protobuf-go-hex-display v1.33.0-hex-display
     
    +// TODO(guggero): Remove this when https://github.com/btcsuite/btcd/pull/2521 is
    +// merged.
    +replace (
    +	github.com/btcsuite/btcd/btcutil/bip322 => github.com/guggero/btcd/btcutil/bip322 v0.0.0-20260509142453-ddfb6e63e0a1
    +	github.com/btcsuite/btcd/btcutil/psbt => github.com/guggero/btcd/btcutil/psbt v0.0.0-20260509142453-ddfb6e63e0a1

    Is the temporary psbt replacement required for this PR as well, or is it only needed internally by the custom bip322 dependency?

    TechLateef TechLateef commented on code on May 10, 2026 08:46 UTC
    Code Review
    itest/lnd_misc_test.go:1

    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.

    TechLateef TechLateef commented on code on May 10, 2026 10:04 UTC
    Code Review
    go.mod:1
    @@ -221,6 +222,13 @@ replace github.com/gogo/protobuf => github.com/gogo/protobuf v1.3.2
     // allows us to specify that as an option.
     replace google.golang.org/protobuf => github.com/lightninglabs/protobuf-go-hex-display v1.33.0-hex-display
     
    +// TODO(guggero): Remove this when https://github.com/btcsuite/btcd/pull/2521 is
    +// merged.
    +replace (
    +	github.com/btcsuite/btcd/btcutil/bip322 => github.com/guggero/btcd/btcutil/bip322 v0.0.0-20260509142453-ddfb6e63e0a1
    +	github.com/btcsuite/btcd/btcutil/psbt => github.com/guggero/btcd/btcutil/psbt v0.0.0-20260509142453-ddfb6e63e0a1

    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.

    github-actions[bot] github-actions[bot] commented on Jun 25, 2026 06:02 UTC
    Bot

    ⚠️ 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 manifest

  • go.sum — dependency checksums

  • lnrpc/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 -->

    guggero guggero commented on code on Jun 25, 2026 06:13 UTC
    Code Review
    itest/lnd_misc_test.go:1

    Good idea, done.

    guggero guggero commented on code on Jun 25, 2026 06:14 UTC
    Code Review
    go.mod:1
    @@ -221,6 +222,13 @@ replace github.com/gogo/protobuf => github.com/gogo/protobuf v1.3.2
     // allows us to specify that as an option.
     replace google.golang.org/protobuf => github.com/lightninglabs/protobuf-go-hex-display v1.33.0-hex-display
     
    +// TODO(guggero): Remove this when https://github.com/btcsuite/btcd/pull/2521 is
    +// merged.
    +replace (
    +	github.com/btcsuite/btcd/btcutil/bip322 => github.com/guggero/btcd/btcutil/bip322 v0.0.0-20260509142453-ddfb6e63e0a1
    +	github.com/btcsuite/btcd/btcutil/psbt => github.com/guggero/btcd/btcutil/psbt v0.0.0-20260509142453-ddfb6e63e0a1

    Yes, and with the latest changes to the implementation, the txscript module is also touched by https://github.com/btcsuite/btcd/pull/2521.

    guggero guggero commented on Jun 25, 2026 06:14 UTC
    Author

    This PR still depends on https://github.com/btcsuite/btcd/pull/2521, but is otherwise ready to review.

    litbot-9000 litbot-9000 commented on Aug 06, 2026 11:26 UTC
    Contributor

    @guggero, remember to re-request review from reviewers when ready

    litbot-9000 litbot-9000 commented on Aug 13, 2026 12:42 UTC
    Contributor

    @guggero, remember to re-request review from reviewers when ready

    litbot-9000 litbot-9000 commented on Aug 20, 2026 13:29 UTC
    Contributor

    @guggero, remember to re-request review from reviewers when ready

    litbot-9000 litbot-9000 commented on Aug 27, 2026 13:57 UTC
    Contributor

    @guggero, remember to re-request review from reviewers when ready

    litbot-9000 litbot-9000 commented on Sep 03, 2026 14:45 UTC
    Contributor

    @guggero, remember to re-request review from reviewers when ready

    litbot-9000 litbot-9000 commented on Sep 10, 2026 15:10 UTC
    Contributor

    @guggero, remember to re-request review from reviewers when ready

    guggero guggero commented on Sep 17, 2026 09:32 UTC
    Author

    Rebased and updated to latest version of https://github.com/btcsuite/btcd/pull/2521.

    github-actions[bot] github-actions[bot] commented on Sep 17, 2026 09:34 UTC
    Bot

    ⚠️ 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 manifest

  • go.sum — dependency checksums

  • lnrpc/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 -->

    litbot-9000 litbot-9000 commented on Sep 24, 2026 09:45 UTC
    Contributor

    @guggero, remember to re-request review from reviewers when ready

    litbot-9000 litbot-9000 commented on Oct 01, 2026 10:44 UTC
    Contributor

    @guggero, remember to re-request review from reviewers when ready

    litbot-9000 litbot-9000 commented on Oct 08, 2026 10:53 UTC
    Contributor

    @guggero, remember to re-request review from reviewers when ready

    litbot-9000 litbot-9000 commented on Oct 15, 2026 12:17 UTC
    Contributor

    @guggero, remember to re-request review from reviewers when ready

    litbot-9000 litbot-9000 commented on Oct 22, 2026 13:19 UTC
    Contributor

    @guggero, remember to re-request review from reviewers when ready

    litbot-9000 litbot-9000 commented on Oct 29, 2026 14:19 UTC
    Contributor

    @guggero, remember to re-request review from reviewers when ready

    litbot-9000 litbot-9000 commented on Nov 05, 2026 15:48 UTC
    Contributor

    @guggero, remember to re-request review from reviewers when ready

    litbot-9000 litbot-9000 commented on Nov 12, 2026 16:54 UTC
    Contributor

    @guggero, remember to re-request review from reviewers when ready

    litbot-9000 litbot-9000 commented on Nov 19, 2026 18:26 UTC
    Contributor

    @guggero, remember to re-request review from reviewers when ready

    Reviewers
    Assignees
    guggero guggero
    Labels
    risk: low confidence: 82.2% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 78.6% (HIGH) · Higher = larger blast radius
    78.6%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 82.2% · Lower = rushed or shallow review
    82.2%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 14.0% · Safe to merge
    14.0%