forked from FactomProject/FactomCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsignature.go
More file actions
40 lines (32 loc) · 906 Bytes
/
signature.go
File metadata and controls
40 lines (32 loc) · 906 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Copyright 2015 Factom Foundation
// Use of this source code is governed by the MIT
// license that can be found in the LICENSE file.
package common
import (
"encoding/hex"
"github.com/FactomProject/ed25519"
)
type DetachedSignature [ed25519.SignatureSize]byte
type DetachedPublicKey [ed25519.PublicKeySize]byte
//Signature has signed data and its corresponsing PublicKey
type Signature struct {
Pub PublicKey
Sig *[ed25519.SignatureSize]byte
}
func (sig Signature) Key() []byte {
return (*sig.Pub.Key)[:]
}
func (sig *Signature) DetachSig() *DetachedSignature {
return (*DetachedSignature)(sig.Sig)
}
func (ds *DetachedSignature) String() string {
return hex.EncodeToString(ds[:])
}
func UnmarshalBinarySignature(data []byte) (sig Signature) {
sig.Pub.Key = new([32]byte)
sig.Sig = new([64]byte)
copy(sig.Pub.Key[:], data[:32])
data = data[32:]
copy(sig.Sig[:], data[:64])
return
}