package pijul
import("fmt""filippo.io/edwards25519")// A State represents a set of changes. It is calculated from the hashes of
// the changes, using the Edwards 25519 curve.
typeStatestruct{p edwards25519.Point
}func(s State)String()string{return base32Encoding.EncodeToString(append(s.p.Bytes(),1))}funcStateFromBase32(b32string)(State,error){b,err:= base32Encoding.DecodeString(b32)if err !=nil{return State{}, err
}iflen(b)!=33{return State{}, fmt.Errorf("expected 33 bytes, got %d",len(b))}if b[32]!=1{return State{}, fmt.Errorf("expected Ed25519 state, got type %d", b[32])}varp edwards25519.Point
_, err = p.SetBytes(b[:32])if err !=nil{return State{}, err
}return State{p},nil}funcmustStateFromBase32(b32string)State {s,err:=StateFromBase32(b32)if err !=nil{panic(err)}return s
}// EmptyState is the State that represents the empty set.
varEmptyState=mustStateFromBase32("LBTGMZTGMZTGMZTGMZTGMZTGMZTGMZTGMZTGMZTGMZTGMZTGMZTAC")func(s State)Add(h Hash)State {varwideBytes[64]bytecopy(wideBytes[:], h[:])varscalar edwards25519.Scalar
scalar.SetUniformBytes(wideBytes[:])p:= s.p
p.ScalarMult(&scalar,&p)return State{p}}