diff options
Diffstat (limited to 'types/types.go')
-rw-r--r-- | types/types.go | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/types/types.go b/types/types.go index d031b29..405c825 100644 --- a/types/types.go +++ b/types/types.go @@ -1,9 +1,12 @@ package types import ( + "crypto" + "fmt" + "strings" + "crypto/ed25519" "crypto/sha256" - "strings" ) const ( @@ -113,3 +116,38 @@ type LeafRequest struct { type CosignatureRequest struct { SigIdent } + +// Sign signs the tree head using the log's signature scheme +func (th *TreeHead) Sign(signer crypto.Signer) (*SignedTreeHead, error) { + sig, err := signer.Sign(nil, th.Marshal(), crypto.Hash(0)) + if err != nil { + return nil, fmt.Errorf("Sign: %v", err) + } + + sigident := SigIdent{ + KeyHash: Hash(signer.Public().(ed25519.PublicKey)[:]), + Signature: &[SignatureSize]byte{}, + } + copy(sigident.Signature[:], sig) + return &SignedTreeHead{ + TreeHead: *th, + SigIdent: []*SigIdent{ + &sigident, + }, + }, nil +} + +// Verify verifies the tree head signature using the log's signature scheme +func (th *TreeHead) Verify(pub crypto.PublicKey) error { // TODO + return nil +} + +// Verify checks if a leaf is included in the log +func (p *InclusionProof) Verify(leaf *Leaf, th *TreeHead) error { // TODO + return nil +} + +// Verify checks if two tree heads are consistent +func (p *ConsistencyProof) Verify(oldTH, newTH *TreeHead) error { // TODO + return nil +} |