mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-12-12 13:54:31 +01:00
zpay32: add distinct hrp to invoice
The Core devs decided to us the same bech32 HRP for Signet as is used for the current Testnet3. This might be okay for on-chain addresses since they are compatible in theory. But for invoices we want to use a distinct HRP to distinguish testnet from signet. Also see spec PR https://github.com/lightningnetwork/lightning-rfc/pull/844 for more information about the reasoning.
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
|
||||
"github.com/btcsuite/btcd/chaincfg"
|
||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||
"github.com/btcsuite/btcutil"
|
||||
"github.com/btcsuite/btcutil/bech32"
|
||||
@@ -51,8 +52,16 @@ func (invoice *Invoice) Encode(signer MessageSigner) (string, error) {
|
||||
return "", err
|
||||
}
|
||||
|
||||
// The human-readable part (hrp) is "ln" + net hrp + optional amount.
|
||||
// The human-readable part (hrp) is "ln" + net hrp + optional amount,
|
||||
// except for signet where we add an additional "s" to differentiate it
|
||||
// from the older testnet3 (Core devs decided to use the same hrp for
|
||||
// signet as for testnet3 which is not optimal for LN). See
|
||||
// https://github.com/lightningnetwork/lightning-rfc/pull/844 for more
|
||||
// information.
|
||||
hrp := "ln" + invoice.Net.Bech32HRPSegwit
|
||||
if invoice.Net.Name == chaincfg.SigNetParams.Name {
|
||||
hrp = "lntbs"
|
||||
}
|
||||
if invoice.MilliSat != nil {
|
||||
// Encode the amount using the fewest possible characters.
|
||||
am, err := encodeAmount(*invoice.MilliSat)
|
||||
|
||||
Reference in New Issue
Block a user