Skip to content

Commit

Permalink
simplify from_backup example to omit the intermediate step
Browse files Browse the repository at this point in the history
  • Loading branch information
rohenaz committed Sep 4, 2024
1 parent 49286d2 commit 3b252bb
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ All notable changes to this project will be documented in this file. The format
## Table of Contents

- [Unreleased](#unreleased)
- [1.1.3 - 2024-09-03](#111---2024-09-02)
- [1.1.2 - 2024-09-02](#111---2024-09-02)
- [1.1.3 - 2024-09-03](#113---2024-09-03)
- [1.1.2 - 2024-09-02](#112---2024-09-02)
- [1.1.1 - 2024-08-28](#111---2024-08-28)
- [1.1.0 - 2024-08-19](#110---2024-08-19)
- [1.0.0 - 2024-06-06](#100---2024-06-06)
Expand Down
5 changes: 1 addition & 4 deletions docs/examples/keyshares_pk_from_backup/from_backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"log"

ec "github.com/bitcoin-sv/go-sdk/primitives/ec"
keyshares "github.com/bitcoin-sv/go-sdk/primitives/keyshares"
)

func main() {
Expand All @@ -17,9 +16,7 @@ func main() {
"BVk1tcvJEbhUfZagStg15rFRxQDeLzgSN15rWkGhNf19.CUB7p6zK3JPBkBriRRGdWj4y3Z3qCfsaCYutmMWKv1VJ.3.bbc45478",
}

keyshares, _ := keyshares.NewKeySharesFromBackupFormat(shares)

pk, _ := ec.PrivateKeyFromKeyShares(keyshares)
pk, _ := ec.PrivateKeyFromBackupShares(shares)

if pk.Wif() == expectedWif {
log.Println("Private key:", pk.Wif())
Expand Down
15 changes: 10 additions & 5 deletions util/big.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,15 @@ func Umod(x *big.Int, y *big.Int) *big.Int {

func NewRandomBigInt(byteLen int) *big.Int {
b := make([]byte, byteLen)
_, err := rand.Read(b)
if err != nil {
panic(err)
maxRetries := 10
// gracefully handle errors in low entropy environments
// or extreme resource constraints, embedded systems
for retries := 0; retries < maxRetries; retries++ {
_, err := rand.Read(b)
if err == nil {
return new(big.Int).SetBytes(b)
}
}

return new(big.Int).SetBytes(b)
// Failure here indicates a critical error
panic("failed to generate random big.Int")
}

0 comments on commit 3b252bb

Please sign in to comment.