Skip to content

Commit c471af4

Browse files
committed
Merge branch 'master' into feeat/beef-clone
2 parents e69417a + 42df0af commit c471af4

File tree

8 files changed

+35
-30
lines changed

8 files changed

+35
-30
lines changed

.github/workflows/codecov.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
runs-on: ubuntu-latest
1818
steps:
1919
- name: Checkout code
20-
uses: actions/checkout@v5
20+
uses: actions/checkout@v6
2121
with:
2222
fetch-depth: 2
2323

.github/workflows/golangci-lint.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
outputs:
1919
modules: ${{ steps.set-modules.outputs.modules }}
2020
steps:
21-
- uses: actions/checkout@v5
21+
- uses: actions/checkout@v6
2222
- uses: actions/setup-go@v6
2323
with:
2424
go-version: ${{ env.GO_VERSION }}
@@ -32,12 +32,12 @@ jobs:
3232
matrix:
3333
modules: ${{ fromJSON(needs.detect-modules.outputs.modules) }}
3434
steps:
35-
- uses: actions/checkout@v5
35+
- uses: actions/checkout@v6
3636
- uses: actions/setup-go@v6
3737
with:
3838
go-version: ${{ env.GO_VERSION }}
3939
- name: golangci-lint ${{ matrix.modules }}
40-
uses: golangci/golangci-lint-action@v8
40+
uses: golangci/golangci-lint-action@v9
4141
with:
4242
version: ${{ env.GOLANGCI_LINT_VERSION }}
4343
working-directory: ${{ matrix.modules }}

.github/workflows/sonar.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
runs-on: ubuntu-latest
2222
steps:
2323
- name: Checkout
24-
uses: actions/checkout@v5
24+
uses: actions/checkout@v6
2525
with:
2626
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
2727

@@ -41,7 +41,7 @@ jobs:
4141

4242
# Re-run golangci separately without exiting on errors and generating a report for use in Sonar
4343
- name: golangci-lint
44-
uses: golangci/golangci-lint-action@v8
44+
uses: golangci/golangci-lint-action@v9
4545
with:
4646
version: ${{ env.GOLANGCI_LINT_VERSION }}
4747
args: --timeout=5m --issues-exit-code=0 --output.checkstyle.path=golangci-lint-report.xml

docs/examples/create_wallet/create_wallet.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"crypto/sha256"
45
"fmt"
56
"log"
67

@@ -26,7 +27,7 @@ func main() {
2627
if err != nil {
2728
log.Fatalf("Failed to generate mnemonic: %v", err)
2829
}
29-
fmt.Printf("Generated Mnemonic: %s\n\n", mnemonic)
30+
fmt.Println("Mnemonic generated (not logged for security). Store it securely.")
3031

3132
// Generate a seed from the mnemonic
3233
// An empty password is used for simplicity in this example
@@ -39,7 +40,7 @@ func main() {
3940
if err != nil {
4041
log.Fatalf("Failed to create master key: %v", err)
4142
}
42-
fmt.Printf("Master Private Key (xPriv): %s\n", masterKey.String())
43+
fmt.Println("Master private key created (not logged for security).")
4344

4445
// Create a wallet instance from the master private key
4546
// Note: The wallet instance itself doesn't store the mnemonic or master xPriv directly for this example
@@ -67,19 +68,20 @@ func main() {
6768
// The DeriveChildFromPath method handles string paths.
6869
derivedKey, err := masterKey.DeriveChildFromPath(derivationPathStr)
6970
if err != nil {
70-
log.Fatalf("Failed to derive key for path %s: %v", derivationPathStr, err)
71+
log.Fatal("Failed to derive key for requested path; aborting to protect sensitive data")
7172
}
7273

7374
// Get the private key from the derived extended key
7475
privateKey, err := derivedKey.ECPrivKey()
7576
if err != nil {
7677
log.Fatalf("Failed to get derived private key: %v", err)
7778
}
78-
fmt.Printf("Derived Private Key (Hex): %x\n", privateKey.Serialize())
79+
fmt.Println("Derived private key created (not logged for security).")
7980

8081
// Get the public key from the private key
8182
publicKey := privateKey.PubKey()
82-
fmt.Printf("Derived Public Key (Hex): %x\n", publicKey.Compressed())
83+
publicKeyHash := sha256.Sum256(publicKey.Compressed())
84+
fmt.Printf("Derived public key fingerprint: %x\n", publicKeyHash[:8])
8385

8486
// Get the P2PKH address from the public key
8587
// This is one way to get the address.
@@ -93,5 +95,5 @@ func main() {
9395

9496
fmt.Println("Wallet creation and key derivation complete.")
9597
fmt.Println("IMPORTANT: Store your mnemonic phrase securely. This example generates a new wallet on each run.")
96-
fmt.Printf("To use this wallet, you would typically persist the mnemonic or the master extended private key (xPriv: %s).\n", masterKey.String())
98+
fmt.Println("Never log or transmit your mnemonic or private keys in plaintext.")
9799
}

docs/examples/generate_hd_key/README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ This example demonstrates how to use the `bip32` compatibility package to genera
77
The `generate_hd_key` example showcases:
88
1. Calling `bip32.GenerateHDKeyPair` with a specified seed length (`bip32.SecureSeedLength`).
99
2. Receiving the generated extended private key (xPriv) and extended public key (xPub).
10-
3. Printing both keys.
10+
3. Verifying the public key via a fingerprint without exposing key material.
1111

1212
## Code Walkthrough
1313

@@ -21,9 +21,9 @@ if err != nil {
2121
log.Fatalf("Error generating HD key pair: %s", err.Error())
2222
}
2323

24-
// Print the generated keys
25-
log.Printf("xPrivateKey: %s\n", xPrivateKey)
26-
log.Printf("xPublicKey: %s\n", xPublicKey)
24+
// Never log raw keys. Use a small fingerprint to confirm success.
25+
fingerprint := sha256.Sum256([]byte(xPublicKey))
26+
log.Printf("Generated HD key pair (xPriv length: %d, xPub fingerprint: %x)", len(xPrivateKey), fingerprint[:8])
2727
```
2828

2929
This section shows the direct use of `bip32.GenerateHDKeyPair`. This function creates a new master HD key from a randomly generated seed of the given length. It returns the extended private key (xPriv) and the corresponding extended public key (xPub) as strings.
@@ -35,11 +35,11 @@ To run this example:
3535
```bash
3636
go run generate_hd_key.go
3737
```
38-
The output will be the newly generated xPrivateKey and xPublicKey strings. Each run will produce a different key pair.
38+
The output will confirm the generated key lengths and show a short fingerprint of the xPub. Each run will produce a different key pair, so securely store the raw keys instead of logging them.
3939

4040
**Note**:
41-
- The generated xPrivateKey is the master private key for an HD wallet structure. It should be kept extremely secure.
42-
- The xPublicKey can be used to derive child public keys without exposing the private key.
41+
- The generated xPrivateKey is the master private key for an HD wallet structure. It should be kept extremely secure and never logged in plaintext.
42+
- The xPublicKey can be used to derive child public keys without exposing the private key. Only expose fingerprints when confirming values in logs.
4343
- `bip32.SecureSeedLength` is typically 32 bytes (256 bits) or 64 bytes (512 bits) for strong security.
4444

4545
## Integration Steps

docs/examples/generate_hd_key/generate_hd_key.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"crypto/sha256"
45
"log"
56

67
bip32 "github.com/bsv-blockchain/go-sdk/compat/bip32"
@@ -12,6 +13,8 @@ func main() {
1213
log.Fatalf("error occurred: %s", err.Error())
1314
}
1415

15-
// Success!
16-
log.Printf("xPrivateKey: %s \n xPublicKey: %s", xPrivateKey, xPublicKey)
16+
// Success! Avoid logging sensitive key material. Use a fingerprint of the public key
17+
// for verification instead of printing the full keys.
18+
publicKeyFingerprint := sha256.Sum256([]byte(xPublicKey))
19+
log.Printf("Generated HD key pair (xPriv length: %d, xPub fingerprint: %x)", len(xPrivateKey), publicKeyFingerprint[:8])
1720
}

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ go 1.24.3
55
require (
66
github.com/davecgh/go-spew v1.1.1
77
github.com/stretchr/testify v1.11.1
8-
golang.org/x/crypto v0.43.0
9-
golang.org/x/sync v0.17.0
8+
golang.org/x/crypto v0.45.0
9+
golang.org/x/sync v0.18.0
1010
)
1111

12-
require golang.org/x/net v0.46.0
12+
require golang.org/x/net v0.47.0
1313

1414
require (
1515
github.com/pkg/errors v0.9.1

go.sum

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
66
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
77
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
88
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
9-
golang.org/x/crypto v0.43.0 h1:dduJYIi3A3KOfdGOHX8AVZ/jGiyPa3IbBozJ5kNuE04=
10-
golang.org/x/crypto v0.43.0/go.mod h1:BFbav4mRNlXJL4wNeejLpWxB7wMbc79PdRGhWKncxR0=
11-
golang.org/x/net v0.46.0 h1:giFlY12I07fugqwPuWJi68oOnpfqFnJIJzaIIm2JVV4=
12-
golang.org/x/net v0.46.0/go.mod h1:Q9BGdFy1y4nkUwiLvT5qtyhAnEHgnQ/zd8PfU6nc210=
13-
golang.org/x/sync v0.17.0 h1:l60nONMj9l5drqw6jlhIELNv9I0A4OFgRsG9k2oT9Ug=
14-
golang.org/x/sync v0.17.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
9+
golang.org/x/crypto v0.45.0 h1:jMBrvKuj23MTlT0bQEOBcAE0mjg8mK9RXFhRH6nyF3Q=
10+
golang.org/x/crypto v0.45.0/go.mod h1:XTGrrkGJve7CYK7J8PEww4aY7gM3qMCElcJQ8n8JdX4=
11+
golang.org/x/net v0.47.0 h1:Mx+4dIFzqraBXUugkia1OOvlD6LemFo1ALMHjrXDOhY=
12+
golang.org/x/net v0.47.0/go.mod h1:/jNxtkgq5yWUGYkaZGqo27cfGZ1c5Nen03aYrrKpVRU=
13+
golang.org/x/sync v0.18.0 h1:kr88TuHDroi+UVf+0hZnirlk8o8T+4MrK6mr60WkH/I=
14+
golang.org/x/sync v0.18.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
1515
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
1616
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
1717
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=

0 commit comments

Comments
 (0)