-
Notifications
You must be signed in to change notification settings - Fork 0
/
groups.go
executable file
·66 lines (46 loc) · 1.98 KB
/
groups.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
package crypt0cloud_sdk_go
import (
"crypto/sha256"
"encoding/base64"
"encoding/json"
"github.com/onlyangel/apihandlers"
"golang.org/x/crypto/ed25519"
model "github.com/crypt0cloud/model_go"
)
func (c Crypt0Client) GroupCreate(transaction *model.Transaction, publicKey, privateKey []byte) []byte {
transaction = signTransaction(transaction, publicKey, privateKey)
jsonstr, err := json.Marshal(transaction)
apihandlers.PanicIfNotNil(err)
return c._post("http://"+c.Endpoint+"/api/v1/create_group", jsonstr)
}
func (c Crypt0Client) SigningRequestCreate(transaction *model.Transaction) []byte {
jsonstr, err := json.Marshal(transaction)
apihandlers.PanicIfNotNil(err)
return c._post("http://"+c.Endpoint+"/api/v1/create_signingRequest", jsonstr)
}
func (c Crypt0Client) SigningRequestGet(transactionid int64) *model.Transaction {
responses := c._get("http://" + c.Endpoint + "/api/v1/get_signingRequest?id=" + string(transactionid))
transaction := new(model.Transaction)
err := json.Unmarshal(responses, transaction)
apihandlers.PanicIfNotNil(err)
return transaction
}
func (c Crypt0Client) SigningRequestSign(transaction *model.Transaction, publicKey, privateKey []byte) []byte {
transaction = signTransaction(transaction, publicKey, privateKey)
jsonstr, err := json.Marshal(transaction)
apihandlers.PanicIfNotNil(err)
return c._post("http://"+c.Endpoint+"/api/v1/sign_signingRequest", jsonstr)
}
func signTransaction(transaction *model.Transaction, publicKey, privateKey []byte) *model.Transaction {
jsonstr, err := json.Marshal(transaction)
apihandlers.PanicIfNotNil(err)
transaction.Content = base64.StdEncoding.EncodeToString(jsonstr)
sha_256 := sha256.New()
sha_256.Write(jsonstr)
contentsha := sha_256.Sum(nil)
transaction.Hash = base64.StdEncoding.EncodeToString(contentsha)
sign := ed25519.Sign(privateKey, contentsha)
transaction.Sign = base64.StdEncoding.EncodeToString(sign)
transaction.Signer = base64.StdEncoding.EncodeToString(publicKey)
return transaction
}