for _, fi := range files {
path := filepath.Join(kc.keydir, fi.Name())
if skipKeyFile(fi) {
- //log.Printf("ignoring file %v", path)
- //fmt.Printf("ignoring file %v", path)
continue
}
fd, err := os.Open(path)
if err != nil {
- //log.Printf(err)
- fmt.Printf("err")
continue
}
buf.Reset(fd)
cacheMu sync.Mutex
keyStore keyStore
cache *keyCache
- //kdCache map[chainkd.XPub]chainkd.XPrv
}
// XPub type for pubkey for anyone can see
return &HSM{
keyStore: &keyStorePassphrase{keydir, LightScryptN, LightScryptP},
cache: newKeyCache(keydir),
- //kdCache: make(map[chainkd.XPub]chainkd.XPrv),
}, nil
}
h.cacheMu.Lock()
defer h.cacheMu.Unlock()
- //if xprv, ok := h.kdCache[xpub]; ok {
- // return xprv, nil
- //}
-
_, xkey, err := h.loadDecryptedKey(xpub, auth)
if err != nil {
return xprv, ErrLoadKey
}
- //h.kdCache[xpb.XPub] = xkey.XPrv
+
return xkey.XPrv, nil
}
package pseudohsm
-//"fmt"
-//"github.com/rjeczalik/notify"
-//"time"
-
type watcher struct {
kc *keyCache
starting bool
running bool
- //ev chan notify.EventInfo
- quit chan struct{}
+ quit chan struct{}
}
func newWatcher(kc *keyCache) *watcher {
return &watcher{
- kc: kc,
- //ev: make(chan notify.EventInfo, 10),
+ kc: kc,
quit: make(chan struct{}),
}
}
w.starting = false
w.kc.mu.Unlock()
}()
-
- /*
- err := notify.Watch(w.kc.keydir, w.ev, notify.All)
- if err != nil {
- fmt.Printf("can't watch %s: %v", w.kc.keydir, err)
- return
- }
- defer notify.Stop(w.ev)
- fmt.Printf("now watching %s", w.kc.keydir)
- defer fmt.Printf("no longer watching %s", w.kc.keydir)
-
- w.kc.mu.Lock()
- w.running = true
- w.kc.mu.Unlock()
-
- // Wait for file system events and reload.
- // When an event occurs, the reload call is delayed a bit so that
- // multiple events arriving quickly only cause a single reload.
- var (
- debounce = time.NewTimer(0)
- debounceDuration = 500 * time.Millisecond
- inCycle, hadEvent bool
- )
- defer debounce.Stop()
- for {
- select {
- case <-w.quit:
- return
- case <-w.ev:
- if !inCycle {
- debounce.Reset(debounceDuration)
- inCycle = true
- } else {
- hadEvent = true
- }
- case <-debounce.C:
- w.kc.mu.Lock()
- w.kc.reload()
- w.kc.mu.Unlock()
- if hadEvent {
- debounce.Reset(debounceDuration)
- inCycle, hadEvent = true, false
- } else {
- inCycle, hadEvent = false, false
- }
- }
- }
- */
}
+++ /dev/null
-package config
-
-/*func TestGenerateGenesisBlock(t *testing.T) {
- block := GenerateGenesisBlock()
- nonce := block.Nonce
- for {
- hash := block.Hash()
- if difficulty.CheckProofOfWork(&hash, consensus.InitialSeed, block.Bits) {
- break
- }
- block.Nonce++
- }
- if block.Nonce != nonce {
- t.Errorf("correct nonce is %d, but get %d", block.Nonce, nonce)
- }
-}*/
pruneIntermediateScalar(res[:32])
- // Unrolled the following loop:
- // var carry int
- // carry = 0
- // for i := 0; i < 32; i++ {
- // sum := int(xprv[i]) + int(res[i]) + carry
- // res[i] = byte(sum & 0xff)
- // carry = (sum >> 8)
- // }
-
sum := int(0)
sum = int(xprv[0]) + int(res[0]) + (sum >> 8)