func (db *T) GetPreviousEnvelopeHashForPublicKey(publicKey *ecdsa.PublicKey) (h types.Hash, e error) { enc, e := keys.EncodeECDSAPublicKey(publicKey) if e != nil { return } readable(&e, db, func(dbtx *bolt.Tx) { bucket := dbtx.Bucket([]byte("blocks")) if bucket != nil { h = bucket.Get(append([]byte("<"), enc...)) } }) return }
func (a *KeyAuth) Marshal() []byte { key, err := keys.EncodeECDSAPublicKey(&a.key.PublicKey) if err != nil { panic(err) // TODO: better error handling } sigR, sigS, err := ecdsa.Sign(rand.Reader, a.key, util.SHA256(key)) if err != nil { panic(err) // TODO: better error handling } var buf bytes.Buffer enc := gob.NewEncoder(&buf) enc.Encode([][]byte{key, sigR.Bytes(), sigS.Bytes()}) return buf.Bytes() }
func (e *Envelope) Sign(privateKey *ecdsa.PrivateKey) error { pubkey, err := keys.EncodeECDSAPublicKey(&privateKey.PublicKey) if err != nil { return err } if len(e.NextPublicKey) == 0 || bytes.Compare(e.NextPublicKey, e.PublicKey) == 0 { e.NextPublicKey = pubkey } e.PublicKey = pubkey sigR, sigS, err := ecdsa.Sign(rand.Reader, privateKey, e.Hash()) if err != nil { return err } e.SignatureR = sigR.Bytes() e.SignatureS = sigS.Bytes() return nil }