-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbip32_example.go
50 lines (42 loc) · 1.72 KB
/
bip32_example.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main
import (
"fmt"
"log"
"github.com/tyler-smith/go-bip32"
)
// Example address creation for a fictitious company ComputerVoice Inc. where
// each department has their own wallet to manage
func test1() {
// Generate a seed to determine all keys from.
// This should be persisted, backed up, and secured
seed, err := bip32.NewSeed()
if err != nil {
log.Fatalln("Error generating seed:", err)
}
// Create master private key from seed
computerVoiceMasterKey, _ := bip32.NewMasterKey(seed)
// Map departments to keys
// There is a very small chance a given child index is invalid
// If so your real program should handle this by skipping the index
departmentKeys := map[string]*bip32.Key{}
departmentKeys["Sales"], _ = computerVoiceMasterKey.NewChildKey(0)
departmentKeys["Marketing"], _ = computerVoiceMasterKey.NewChildKey(1)
departmentKeys["Engineering"], _ = computerVoiceMasterKey.NewChildKey(2)
departmentKeys["Customer Support"], _ = computerVoiceMasterKey.NewChildKey(3)
// Create public keys for record keeping, auditors, payroll, etc
departmentAuditKeys := map[string]*bip32.Key{}
departmentAuditKeys["Sales"] = departmentKeys["Sales"].PublicKey()
departmentAuditKeys["Marketing"] = departmentKeys["Marketing"].PublicKey()
departmentAuditKeys["Engineering"] = departmentKeys["Engineering"].PublicKey()
departmentAuditKeys["Customer Support"] = departmentKeys["Customer Support"].PublicKey()
// Print public keys
for department, pubKey := range departmentAuditKeys {
fmt.Printf("[%s] : ", department)
fmt.Println(pubKey)
}
// Print public keys
for department, prvKey := range departmentKeys {
fmt.Printf("[%s] : ", department)
fmt.Println(prvKey)
}
}