diff --git a/bitcoin/common.go b/bitcoin/common.go index df60d2a..8edec87 100644 --- a/bitcoin/common.go +++ b/bitcoin/common.go @@ -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 { @@ -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"