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

feat(SPV-936): upgrade to go-sdk #250

Merged
merged 15 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions authentication.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,24 @@
"net/http"
"time"

bip32 "github.com/bitcoin-sv/go-sdk/compat/bip32"
bec "github.com/bitcoin-sv/go-sdk/primitives/ec"
bscript "github.com/bitcoin-sv/go-sdk/script"
sighash "github.com/bitcoin-sv/go-sdk/transaction/sighash"

"github.com/bitcoin-sv/spv-wallet-go-client/utils"
"github.com/bitcoin-sv/spv-wallet/models"
"github.com/bitcoinschema/go-bitcoin/v2"
"github.com/libsv/go-bk/bec"
"github.com/libsv/go-bk/bip32"
"github.com/libsv/go-bt/v2"
"github.com/libsv/go-bt/v2/bscript"
"github.com/libsv/go-bt/v2/sighash"
)

// TODO: Issues with "github.com/bitcoinschema/go-bitcoin/v2"

// TODO: Tx - go-sdk txJSON ?
// TODO: NewTxFromString - no replacement in v2
wregulski marked this conversation as resolved.
Show resolved Hide resolved
// TODO: NewFromHexString - no replacement in v2
// TODO: NewP2PKHUnlockingScript - not found
wregulski marked this conversation as resolved.
Show resolved Hide resolved

// SetSignature will set the signature on the header for the request
func setSignature(header *http.Header, xPriv *bip32.ExtendedKey, bodyString string) error {
// Create the signature
Expand Down Expand Up @@ -60,11 +68,11 @@

func setPreviousTxScript(tx *bt.Tx, inputIndex uint32, dst *models.Destination) (err error) {
var ls *bscript.Script
if ls, err = bscript.NewFromHexString(dst.LockingScript); err != nil {

Check failure on line 71 in authentication.go

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

undefined: bscript.NewFromHexString
return
}

tx.Inputs[inputIndex].PreviousTxScript = ls

Check failure on line 75 in authentication.go

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

cannot use ls (variable of type *script.Script) as *bscript.Script value in assignment
return
}

Expand All @@ -79,14 +87,14 @@
return
}

tx.Inputs[inputIndex].UnlockingScript = s

Check failure on line 90 in authentication.go

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

cannot use s (variable of type *script.Script) as *bscript.Script value in assignment
return
}

func getDerivedKeyForDestination(xPriv *bip32.ExtendedKey, dst *models.Destination) (key *bec.PrivateKey, err error) {
// Derive the child key (m/chain/num)
var derivedKey *bip32.ExtendedKey
if derivedKey, err = bitcoin.GetHDKeyByPath(xPriv, dst.Chain, dst.Num); err != nil {

Check failure on line 97 in authentication.go

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

cannot use bitcoin.GetHDKeyByPath(xPriv, dst.Chain, dst.Num) (value of type *bip32.ExtendedKey) as *"github.com/bitcoin-sv/go-sdk/compat/bip32".ExtendedKey value in assignment

Check failure on line 97 in authentication.go

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

cannot use xPriv (variable of type *"github.com/bitcoin-sv/go-sdk/compat/bip32".ExtendedKey) as *bip32.ExtendedKey value in argument to bitcoin.GetHDKeyByPath
return
}

Expand All @@ -99,7 +107,7 @@
}
}

if key, err = bitcoin.GetPrivateKeyFromHDKey(derivedKey); err != nil {

Check failure on line 110 in authentication.go

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

cannot use bitcoin.GetPrivateKeyFromHDKey(derivedKey) (value of type *bec.PrivateKey) as *"github.com/bitcoin-sv/go-sdk/primitives/ec".PrivateKey value in assignment

Check failure on line 110 in authentication.go

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

cannot use derivedKey (variable of type *"github.com/bitcoin-sv/go-sdk/compat/bip32".ExtendedKey) as *bip32.ExtendedKey value in argument to bitcoin.GetPrivateKeyFromHDKey
return
}

Expand All @@ -110,7 +118,7 @@
func getUnlockingScript(tx *bt.Tx, inputIndex uint32, privateKey *bec.PrivateKey) (*bscript.Script, error) {
sigHashFlags := sighash.AllForkID

sigHash, err := tx.CalcInputSignatureHash(inputIndex, sigHashFlags)

Check failure on line 121 in authentication.go

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

cannot use sigHashFlags (variable of type "github.com/bitcoin-sv/go-sdk/transaction/sighash".Flag) as sighash.Flag value in argument to tx.CalcInputSignatureHash
if err != nil {
return nil, err
}
Expand All @@ -124,7 +132,7 @@
signature := sig.Serialise()

var script *bscript.Script
if script, err = bscript.NewP2PKHUnlockingScript(pubKey, signature, sigHashFlags); err != nil {

Check failure on line 135 in authentication.go

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

undefined: bscript.NewP2PKHUnlockingScript
return nil, err
}

Expand All @@ -142,7 +150,7 @@
// Get the xPub
payload = new(models.AuthPayload)
if payload.XPub, err = bitcoin.GetExtendedPublicKey(
xPriv,

Check failure on line 153 in authentication.go

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

cannot use xPriv (variable of type *"github.com/bitcoin-sv/go-sdk/compat/bip32".ExtendedKey) as *bip32.ExtendedKey value in argument to bitcoin.GetExtendedPublicKey
); err != nil { // Should never error if key is correct
return
}
Expand Down
9 changes: 7 additions & 2 deletions client_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@ import (
"net/http"
"net/url"

"github.com/bitcoinschema/go-bitcoin/v2"
"github.com/libsv/go-bk/bec"
bec "github.com/bitcoin-sv/go-sdk/primitives/ec"
"github.com/libsv/go-bk/wif"

"github.com/bitcoinschema/go-bitcoin/v2"

"github.com/pkg/errors"
)

// TODO: Issues with "github.com/bitcoinschema/go-bitcoin/v2"
// TODO: wif "github.com/bitcoin-sv/go-sdk/compat/wif" - is not found although used in the go-sdk repo?

// configurator is the interface for configuring WalletClient
type configurator interface {
Configure(c *WalletClient)
Expand Down
28 changes: 1 addition & 27 deletions go.mod

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

89 changes: 2 additions & 87 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions http.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@ import (
"net/http"
"strconv"

bip32 "github.com/bitcoin-sv/go-sdk/compat/bip32"
bec "github.com/bitcoin-sv/go-sdk/primitives/ec"
"github.com/bitcoin-sv/spv-wallet-go-client/utils"
"github.com/bitcoin-sv/spv-wallet/models"
"github.com/bitcoin-sv/spv-wallet/models/filter"
"github.com/bitcoinschema/go-bitcoin/v2"
"github.com/libsv/go-bk/bec"
"github.com/libsv/go-bk/bip32"
)

// TODO: Issues with "github.com/bitcoinschema/go-bitcoin/v2"

// SetSignRequest turn the signing of the http request on or off
func (wc *WalletClient) SetSignRequest(signRequest bool) {
wc.signRequest = signRequest
Expand Down
8 changes: 5 additions & 3 deletions totp.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@ import (
"fmt"
"time"

bip32 "github.com/bitcoin-sv/go-sdk/compat/bip32"
bec "github.com/bitcoin-sv/go-sdk/primitives/ec"
"github.com/bitcoin-sv/spv-wallet-go-client/utils"
"github.com/bitcoin-sv/spv-wallet/models"
"github.com/bitcoinschema/go-bitcoin/v2"
"github.com/libsv/go-bk/bec"
"github.com/libsv/go-bk/bip32"
"github.com/pquerna/otp"
"github.com/pquerna/otp/totp"
)

// TODO: Issues with "github.com/bitcoinschema/go-bitcoin/v2"

// ErrClientInitNoXpriv error per init client with first xpriv key
var ErrClientInitNoXpriv = errors.New("init client with xPriv first")

Expand Down Expand Up @@ -123,7 +125,7 @@ func convertPubKey(pubKey string) (*bec.PublicKey, error) {
return nil, err
}

return bec.ParsePubKey(hex, bec.S256())
return bec.ParsePubKey(hex)
}

// directedSecret appends a paymail to the secret and encodes it into base32 string
Expand Down
2 changes: 1 addition & 1 deletion totp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import (
"net/http/httptest"
"testing"

bip32 "github.com/bitcoin-sv/go-sdk/compat/bip32"
"github.com/bitcoin-sv/spv-wallet-go-client/fixtures"
"github.com/bitcoin-sv/spv-wallet-go-client/xpriv"
"github.com/bitcoin-sv/spv-wallet/models"
"github.com/libsv/go-bk/bip32"
"github.com/stretchr/testify/require"
)

Expand Down
2 changes: 1 addition & 1 deletion utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"math"
"strconv"

"github.com/libsv/go-bk/bip32"
bip32 "github.com/bitcoin-sv/go-sdk/compat/bip32"
)

const (
Expand Down
4 changes: 2 additions & 2 deletions walletclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package walletclient
import (
"net/http"

"github.com/libsv/go-bk/bec"
"github.com/libsv/go-bk/bip32"
bip32 "github.com/bitcoin-sv/go-sdk/compat/bip32"
bec "github.com/bitcoin-sv/go-sdk/primitives/ec"
)

// WalletClient is the spv wallet Go client representation.
Expand Down
9 changes: 7 additions & 2 deletions xpriv/xpriv.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
// Package xpriv manges keys
package xpriv

// "github.com/libsv/go-bk/bip39" - no replacements

import (
"fmt"

"github.com/libsv/go-bk/bip32"
bip32 "github.com/bitcoin-sv/go-sdk/compat/bip32"
chaincfg "github.com/bitcoin-sv/go-sdk/transaction/chaincfg"

"github.com/libsv/go-bk/bip39"
"github.com/libsv/go-bk/chaincfg"
)

// TODO: "github.com/libsv/go-bk/bip39" - no replacement (GenerateEntropy, Mnemonic, MnemonicToSeed)
wregulski marked this conversation as resolved.
Show resolved Hide resolved

// Keys is a struct containing the xpriv, xpub and mnemonic
type Keys struct {
xpriv string
Expand Down
Loading