-
Notifications
You must be signed in to change notification settings - Fork 18
/
signer.go
65 lines (51 loc) · 1.62 KB
/
signer.go
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package ledger
import (
"fmt"
coreSignature "github.com/oasisprotocol/oasis-core/go/common/crypto/signature"
"github.com/oasisprotocol/oasis-sdk/client-sdk/go/crypto/signature"
"github.com/oasisprotocol/oasis-sdk/client-sdk/go/crypto/signature/ed25519"
)
type ledgerCoreSigner struct {
path []uint32
pk coreSignature.PublicKey
dev *ledgerDevice
}
func (ls *ledgerCoreSigner) Public() coreSignature.PublicKey {
return ls.pk
}
func (ls *ledgerCoreSigner) ContextSign(context coreSignature.Context, message []byte) ([]byte, error) {
preparedContext, err := coreSignature.PrepareSignerContext(context)
if err != nil {
return nil, fmt.Errorf("ledger: failed to prepare signing context: %w", err)
}
signature, err := ls.dev.SignEd25519(ls.path, preparedContext, message)
if err != nil {
return nil, fmt.Errorf("ledger: failed to sign message: %w", err)
}
return signature, nil
}
func (ls *ledgerCoreSigner) String() string {
return fmt.Sprintf("[ledger signer: %s]", ls.pk)
}
func (ls *ledgerCoreSigner) Reset() {
_ = ls.dev.Close()
}
type ledgerSigner struct {
pk ed25519.PublicKey
dev *ledgerDevice
}
func (ls *ledgerSigner) Public() signature.PublicKey {
return ls.pk
}
func (ls *ledgerSigner) ContextSign(context, message []byte) ([]byte, error) {
return nil, fmt.Errorf("ledger: signing paratime transactions not supported")
}
func (ls *ledgerSigner) Sign(message []byte) ([]byte, error) {
return nil, fmt.Errorf("ledger: signing paratime transactions not supported")
}
func (ls *ledgerSigner) String() string {
return fmt.Sprintf("[ledger signer: %s]", ls.pk)
}
func (ls *ledgerSigner) Reset() {
_ = ls.dev.Close()
}