Skip to content

Commit

Permalink
Add koba.go
Browse files Browse the repository at this point in the history
  • Loading branch information
koba-e964 committed Dec 6, 2023
1 parent 27cfd5c commit 12186b7
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
5 changes: 3 additions & 2 deletions algorithm/bip32/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ go 1.21.2

require github.com/tyler-smith/go-bip32 v1.0.0

require github.com/koba-e964/bip32-typesafe v0.1.0

require (
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e // indirect
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
golang.org/x/crypto v0.0.0-20170613210332-850760c427c5 // indirect
golang.org/x/crypto v0.16.0 // indirect
)
10 changes: 8 additions & 2 deletions algorithm/bip32/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,19 @@ github.com/cmars/basen v0.0.0-20150613233007-fe3947df716e/go.mod h1:P13beTBKr5Q1
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/koba-e964/bip32-typesafe v0.1.0 h1:xbKhbQaUq7Hs6xKG/WmV/uo+XNj0y+bDKoZRxoQpxo8=
github.com/koba-e964/bip32-typesafe v0.1.0/go.mod h1:mGBpH6qVwWrDU2SRqv170elwqSsqChnA2bX8jwBqN/U=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.1.5-0.20170601210322-f6abca593680 h1:oAXco1Ts88F75L1qvG3BAa4ChXI3EZDfxbB+p+y8+gE=
github.com/stretchr/testify v1.1.5-0.20170601210322-f6abca593680/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/tyler-smith/go-bip32 v1.0.0 h1:sDR9juArbUgX+bO/iblgZnMPeWY1KZMUC2AFUJdv5KE=
github.com/tyler-smith/go-bip32 v1.0.0/go.mod h1:onot+eHknzV4BVPwrzqY5OoVpyCvnwD7lMawL5aQupE=
golang.org/x/crypto v0.0.0-20170613210332-850760c427c5 h1:LtqPZJBT4TN+oR4PYeP4NsEXw48n76ZGyUh3RzL4VH8=
golang.org/x/crypto v0.0.0-20170613210332-850760c427c5/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.16.0 h1:mMMrFzRSCF0GvB7Ne27XVtVAaXLrPmgPC7/v0tkwHaY=
golang.org/x/crypto v0.16.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
launchpad.net/gocheck v0.0.0-20140225173054-000000000087 h1:Izowp2XBH6Ya6rv+hqbceQyw/gSGoXfH/UPoTGduL54=
launchpad.net/gocheck v0.0.0-20140225173054-000000000087/go.mod h1:hj7XX3B/0A+80Vse0e+BUHsHMTEhd0O4cpUHr/e/BUM=
30 changes: 30 additions & 0 deletions algorithm/bip32/koba.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
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())
}

0 comments on commit 12186b7

Please sign in to comment.