Example #1
0
func (w *SCWallet) SetSeed(seed []byte) {
	w.NextSeed = seed
	w.RootSeed = seed
	b := new(bytestore.ByteStore)
	b.SetBytes(w.RootSeed)
	err := w.db.Put([]byte(constants.W_SEEDS), constants.CURRENT_SEED[:], b)
	if err != nil {
		panic(err)
	}
	err = w.db.Put([]byte(constants.W_SEEDS), w.RootSeed[:32], b)
	if err != nil {
		panic(err)
	}
	err = w.db.Put([]byte(constants.W_SEED_HEADS), w.RootSeed[:32], b)
	if err != nil {
		panic(err)
	}
}
Example #2
0
func (w *SCWallet) GetSeed() []byte {
	iroot, err := w.db.Get([]byte(constants.W_SEEDS), constants.CURRENT_SEED[:], new(bytestore.ByteStore))
	if err != nil {
		panic(err)
	}
	if iroot == nil {
		randomstuff := make([]byte, 1024)
		rand.Read(randomstuff)
		w.NewSeed(randomstuff)
	}
	hasher := sha512.New()
	hasher.Write([]byte(w.NextSeed))
	seedhash := hasher.Sum(nil)
	w.NextSeed = seedhash

	b := new(bytestore.ByteStore)
	b.SetBytes(w.NextSeed)
	err = w.db.Put([]byte(constants.W_SEED_HEADS), w.RootSeed[:32], b)
	if err != nil {
		panic(err)
	}
	return w.NextSeed
}
Example #3
0
func (w *SCWallet) NewSeed(data []byte) {
	if len(data) == 0 {
		return
	} // No data, no change
	hasher := sha512.New()
	hasher.Write(data)
	seedhash := hasher.Sum(nil)
	w.NextSeed = seedhash
	w.RootSeed = seedhash
	b := new(bytestore.ByteStore)
	b.SetBytes(w.RootSeed)
	err := w.db.Put([]byte(constants.W_SEEDS), constants.CURRENT_SEED[:], b)
	if err != nil {
		panic(err)
	}
	err = w.db.Put([]byte(constants.W_SEEDS), w.RootSeed[:32], b)
	if err != nil {
		panic(err)
	}
	err = w.db.Put([]byte(constants.W_SEED_HEADS), w.RootSeed[:32], b)
	if err != nil {
		panic(err)
	}
}