https://github.com/koba-e964/bip32-typesafe
A Go implementation of BIP 32 which is type-safe and a best-effort attempt at timing-attack resistance
https://github.com/koba-e964/bip32-typesafe
bitcoin-wallet cryptocurrency cryptography-library golang
Last synced: 4 months ago
JSON representation
A Go implementation of BIP 32 which is type-safe and a best-effort attempt at timing-attack resistance
- Host: GitHub
- URL: https://github.com/koba-e964/bip32-typesafe
- Owner: koba-e964
- License: mit
- Created: 2023-11-27T08:58:25.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2025-02-12T17:25:34.000Z (over 1 year ago)
- Last Synced: 2025-02-12T18:33:37.076Z (over 1 year ago)
- Topics: bitcoin-wallet, cryptocurrency, cryptography-library, golang
- Language: Go
- Homepage:
- Size: 75.2 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# bip32-typesafe 
**bip32-typesafe** is a type safe, cryptographically secure implementation of BIP 32 (hierarchical deterministic wallets).
Functions in this implementation let users avoid common mistakes/vulnerablities like:
- mixing private keys and public keys: by type safety (for example, PrivateKey and PublicKey are different types)
- side-channel attacks such as [timing attacks](https://en.wikipedia.org/wiki/Timing_attack): by making functions *constant-time* (taking the same amount of time regardless of the input)
Therefore, this is an easy-to-use and hard-to-misuse library that users can use with confidence.
## Examples
```go
package main
import (
"crypto/rand"
"fmt"
"log"
bip32 "github.com/koba-e964/bip32-typesafe"
)
func main() {
// Generate random 32 bytes
seed := make([]byte, 32)
if _, err := rand.Read(seed); err != nil {
panic(err)
}
master := bip32.NewMasterKey(seed)
log.Println(master.PrivateKey())
child0, err := master.NewChildKey(0) // master/0
if err != nil {
panic(err)
}
fmt.Println("master/0 =", child0.B58Serialize())
childH0, err := master.NewChildKey(bip32.FirstHardenedChildIndex + 0) // master/0_H
if err != nil {
panic(err)
}
fmt.Println("master/0_H =", childH0.B58Serialize())
}
```
## Documentation
Package info: [https://pkg.go.dev/github.com/koba-e964/bip32-typesafe](https://pkg.go.dev/github.com/koba-e964/bip32-typesafe)
## Development
This repo uses pre-commit to run `gofmt` and `staticcheck` before each commit.
```sh
pre-commit install
pre-commit run --all-files
```