Skip to content

Commit

Permalink
Add DeriveBIP32WithPath
Browse files Browse the repository at this point in the history
  • Loading branch information
hundredark committed Sep 4, 2024
1 parent a7681b2 commit f40be3f
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions bitcoin/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ const (
TransactionConfirmations = 1
)

func BitcoinDefaultDerivationPath() []byte {
return []byte{2, 0, 0, 0}
}

func ParseSatoshi(amount string) (int64, error) {
amt, err := decimal.NewFromString(amount)
if err != nil {
Expand Down Expand Up @@ -145,6 +149,22 @@ func DeriveBIP32(public string, chainCode []byte, children ...uint32) (string, s
return extPub.String(), hex.EncodeToString(pub.SerializeCompressed()), nil
}

func DeriveBIP32WithPath(public, chaincode string, path8 []byte) (string, error) {
if path8[0] > 3 {
panic(path8[0])
}
path32 := make([]uint32, path8[0])
for i := 0; i < int(path8[0]); i++ {
path32[i] = uint32(path8[1+i])
}
cc, err := hex.DecodeString(chaincode)
if err != nil {
return "", err
}
_, sdk, err := DeriveBIP32(public, cc, path32...)
return sdk, err
}

func HashMessageForSignature(msg string, chain byte) ([]byte, error) {
var buf bytes.Buffer
prefix := "Bitcoin Signed Message:\n"
Expand Down

0 comments on commit f40be3f

Please sign in to comment.