-
Notifications
You must be signed in to change notification settings - Fork 6
/
auth_deprecated.go
50 lines (43 loc) · 1.31 KB
/
auth_deprecated.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
//nolint:gomnd
package core
import (
"encoding/hex"
"errors"
"fmt"
"strings"
"github.com/anoideaopen/foundation/core/helpers"
"github.com/anoideaopen/foundation/core/types"
"github.com/btcsuite/btcutil/base58"
"github.com/hyperledger/fabric-chaincode-go/shim"
"golang.org/x/crypto/ed25519"
"golang.org/x/crypto/sha3"
)
// CheckSign exists fo backward compatibility
func CheckSign(
stub shim.ChaincodeStubInterface,
fn string,
args []string,
auth []string,
) (*types.Address, string, error) {
signers := len(auth) / 2
if signers == 0 {
return &types.Address{}, "", errors.New("should be signed")
}
message := sha3.Sum256([]byte(fn + strings.Join(append(args, auth[:signers]...), "")))
for i := 0; i < signers; i++ {
key := base58.Decode(auth[i])
sign := base58.Decode(auth[i+signers])
if !ed25519.Verify(key, message[:], sign) {
return &types.Address{}, "", errors.New("incorrect signature")
}
}
acl, err := helpers.CheckACL(stub, auth[:signers])
if err != nil {
return &types.Address{}, "", err
}
if acl.GetAccount().GetGrayListed() {
errMsg := fmt.Sprintf("address %s is graylisted", (*types.Address)(acl.GetAddress().GetAddress()).String())
return &types.Address{}, "", errors.New(errMsg)
}
return (*types.Address)(acl.GetAddress().GetAddress()), hex.EncodeToString(message[:]), nil
}