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

Bech32m #209

Merged
merged 4 commits into from
Jun 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
84 changes: 84 additions & 0 deletions account/bech32_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package account

import (
"fmt"
"testing"

"github.com/breez/breez/config"
"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/chaincfg"
"github.com/btcsuite/btcd/txscript"
)

type MockTester struct {
}

// NOTE you will need to remove the logging from the ValidateAddress function in order to run these tests.
func TestValidbech32m(t *testing.T) {
mockService := Service{
cfg: &config.Config{
Network: "mainnet",
},
activeParams: &chaincfg.MainNetParams,
}

addresses := [...]string{
"BC1QW508D6QEJXTDG4Y5R3ZARVARY0C5XW7KV8F3T4",
"bc1pw508d6qejxtdg4y5r3zarvary0c5xw7kw508d6qejxtdg4y5r3zarvary0c5xw7kt5nd6y",
"BC1SW50QGDZ25J",
"bc1zw508d6qejxtdg4y5r3zarvaryvaxxpcs",
"bc1p0xlxvlhemja6c4dqv22uapctqupfhlxm9h8z3k2e72q4k9hcz7vqzk5jj0",
}

fmt.Println("testValidbech32m")
for _, address := range addresses {
err := mockService.ValidateAddress(address)
if err == nil {
return
} else {
t.Fatal("invalid address")
}

}

}

// NOTE you will need to remove the logging from the ValidateAddress function in order to run these tests.
func TestInvalidbech32m(t *testing.T) {
mockService := Service{
cfg: &config.Config{
Network: "mainnet",
},
activeParams: &chaincfg.MainNetParams,
}
var err error

addresses := [...]string{
"BC130XLXVLHEMJA6C4DQV22UAPCTQUPFHLXM9H8Z3K2E72Q4K9HCZ7VQ7ZWS8R",
"bc1p0xlxvlhemja6c4dqv22uapctqupfhlxm9h8z3k2e72q4k9hcz7vqh2y7hd",
"BC1S0XLXVLHEMJA6C4DQV22UAPCTQUPFHLXM9H8Z3K2E72Q4K9HCZ7VQ54WELL",
"bc1p0xlxvlhemja6c4dqv22uapctqupfhlxm9h8z3k2e72q4k9hcz7v8n0nx0muaewav253zgeav",
"BC1QR508D6QEJXTDG4Y5R3ZARVARYV98GJ9P",
"bc1p0xlxvlhemja6c4dqv22uapctqupfhlxm9h8z3k2e72q4k9hcz7v07qwwzcrf"}

for _, address := range addresses {
err = mockService.ValidateAddress(address)
if err == nil {
t.Fatalf("error %v", err)
}
}
}

func createAddress() (btcutil.Address, error) {
privateKey, err := btcec.NewPrivateKey()
if err != nil {
return nil, err
}
tapKey := txscript.ComputeTaprootKeyNoScript(privateKey.PubKey())
address, err := btcutil.NewAddressPubKey(tapKey.SerializeCompressed(), &chaincfg.MainNetParams)
if err != nil {
return nil, err
}
return address, nil
}
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/breez/breez
go 1.19

require (
github.com/breez/boltz v0.0.0-20220719050749-9af40a046ccc
github.com/breez/boltz v0.0.0-20230529122619-7972e1f7a7b7
github.com/breez/lspd v0.0.0-20230216140105-14f93d934eb1
github.com/btcsuite/btcd v0.23.5-0.20230228185050-38331963bddd
github.com/btcsuite/btcd/btcec/v2 v2.3.2
Expand All @@ -19,7 +19,7 @@ require (
github.com/jessevdk/go-flags v1.5.0
github.com/lightninglabs/neutrino v0.15.0
github.com/lightninglabs/protobuf-hex-display v1.4.3-hex-display
github.com/lightningnetwork/lnd v0.16.1-beta
github.com/lightningnetwork/lnd v0.16.2-beta
github.com/lightningnetwork/lnd/kvdb v1.4.1
github.com/lightningnetwork/lnd/tor v1.1.0
github.com/status-im/doubleratchet v0.0.0-20181102064121-4dcb6cba284a
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84=
github.com/breez/boltz v0.0.0-20220719050749-9af40a046ccc h1:7tiYawiredvY+7Wlpi4CxGOPWRYFAsu3ilk4thgcAqg=
github.com/breez/boltz v0.0.0-20220719050749-9af40a046ccc/go.mod h1:q1ctBQknkIIL3Yjld6Iyb6iP9RRWVP3yoUyD4LfBto0=
github.com/breez/boltz v0.0.0-20230529122619-7972e1f7a7b7 h1:Q7iDlT21T4Fd1VkeczVsN7sm5HEfXYI5Q0k4wZGBuPo=
github.com/breez/boltz v0.0.0-20230529122619-7972e1f7a7b7/go.mod h1:dG529kzhIfB2W9PWFRo7/mldB3m+M1TTHgPZcAfQj2Y=
github.com/breez/btcwallet v0.16.9-breez h1:InfxVusZxRRNSehehqGp7aqRLX72XezhwzyOLACrSBg=
github.com/breez/btcwallet v0.16.9-breez/go.mod h1:T3DjEAMZYIqQ28l+ixlB6DX4mFJXCX8Pzz+yACQcLsc=
github.com/breez/btcwallet/walletdb v1.4.0-breez h1:Ukwi/c4iO2qhQbjQkrz6ieBLqf9K8Dn57o4uU/iBIj4=
Expand Down
21 changes: 15 additions & 6 deletions lncli/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,35 +155,44 @@ var newAddressCommand = cli.Command{
Category: "Wallet",
Usage: "Generates a new address.",
ArgsUsage: "address-type",
Flags: []cli.Flag{
cli.StringFlag{
Name: "account",
Usage: "(optional) the name of the account to " +
"generate a new address for",
},
},
Description: `
Generate a wallet new address. Address-types has to be one of:
- p2wkh: Pay to witness key hash
- np2wkh: Pay to nested witness key hash`,
- np2wkh: Pay to nested witness key hash
- p2tr: Pay to taproot pubkey`,
Action: actionDecorator(newAddress),
}

func newAddress(ctx *cli.Context) error {
client, cleanUp := getClient(ctx)
defer cleanUp()

stringAddrType := ctx.Args().First()

// Map the string encoded address type, to the concrete typed address
// type enum. An unrecognized address type will result in an error.
stringAddrType := ctx.Args().First()
var addrType lnrpc.AddressType
switch stringAddrType { // TODO(roasbeef): make them ints on the cli?
case "p2wkh":
addrType = lnrpc.AddressType_WITNESS_PUBKEY_HASH
case "np2wkh":
addrType = lnrpc.AddressType_NESTED_PUBKEY_HASH
case "p2tr":
addrType = lnrpc.AddressType_TAPROOT_PUBKEY
default:
return fmt.Errorf("invalid address type %v, support address type "+
"are: p2wkh and np2wkh", stringAddrType)
"are: p2wkh, np2wkh, and p2tr", stringAddrType)
}

ctxb := context.Background()
addr, err := client.NewAddress(ctxb, &lnrpc.NewAddressRequest{
Type: addrType,
Type: addrType,
Account: ctx.String("account"),
})
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion swapfunds/boltzreverseswap.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ func (s *Service) NewReverseSwap(amt int64, feesHash, claimAddress string) (stri
TimeoutBlockHeight: r.TimeoutBlockHeight,
StartBlockHeight: int64(info.BlockHeight),
}
s.log.Errorf("data.ReverseSwap: %#v", rs)
s.log.Infof("data.ReverseSwap: %#v", rs)
h, err := s.breezDB.SaveReverseSwap(rs)
if err != nil {
return "", fmt.Errorf("breezDB.SaveReverseSwap(%#v): %w", rs, err)
Expand Down