forked from hyperledger/fabric-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
user.go
67 lines (55 loc) · 1.81 KB
/
user.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
66
67
/*
Copyright SecureKey Technologies Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package msp
import (
"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/core"
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/msp"
pb_msp "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/msp"
"github.com/pkg/errors"
)
// User is a representation of a Fabric user
type User struct {
id string
mspID string
enrollmentCertificate []byte
privateKey core.Key
}
// Identifier returns user identifier
func (u *User) Identifier() *msp.IdentityIdentifier {
return &msp.IdentityIdentifier{MSPID: u.mspID, ID: u.id}
}
// Verify a signature over some message using this identity as reference
func (u *User) Verify(msg []byte, sig []byte) error {
return errors.New("not implemented")
}
// Serialize converts an identity to bytes
func (u *User) Serialize() ([]byte, error) {
serializedIdentity := &pb_msp.SerializedIdentity{
Mspid: u.mspID,
IdBytes: u.enrollmentCertificate,
}
identity, err := proto.Marshal(serializedIdentity)
if err != nil {
return nil, errors.Wrap(err, "marshal serializedIdentity failed")
}
return identity, nil
}
// EnrollmentCertificate Returns the underlying ECert representing this user’s identity.
func (u *User) EnrollmentCertificate() []byte {
return u.enrollmentCertificate
}
// PrivateKey returns the crypto suite representation of the private key
func (u *User) PrivateKey() core.Key {
return u.privateKey
}
// PublicVersion returns the public parts of this identity
func (u *User) PublicVersion() msp.Identity {
return u
}
// Sign the message
func (u *User) Sign(msg []byte) ([]byte, error) {
return nil, errors.New("Sign() function not implemented")
}