Commit 175b6ea3 authored by pengjun's avatar pengjun

init chain33-sdk-go

parent fce9f88a
# chain33-sdk-go
chain33 sdk golang
### 接口文档
#### 1. 账户相关
#### 1.1 创建账户
**函数原型**
```
NewAccount(signType string) (*Account, error)
```
**请求参数**
|参数|类型|是否必填|说明|
|----|----|----|----|
|signType|string|是|签名类型,支持"secp256k1",默认"secp256k1"|
**返回字段:**
|返回字段|字段类型|说明|
|----|----|----|
|Account|PrivateKey []byte | 私钥
| |PublicKey []byte| 公钥
| |Address string | 地址
| |SignType string| 签名类型
#### 1.2 交易签名
**函数原型**
```
SignRawTransaction(raw string, privateKey string, signType string) (string, error)
```
**请求参数**
|参数|类型|是否必填|说明|
|----|----|----|----|
|raw|string|是|原始交易数据|
|privateKey|string|是|私钥|
|signType|string|是|签名类型|
**返回字段:**
|返回字段|字段类型|说明|
|----|----|----|
|result|string | 签名后的交易
#### 2. 代理重加密
#### 2.1 生成对称加密秘钥
**函数原型**
```
GenerateEncryptKey(pubOwner []byte) ([]byte, string, string)
```
**请求参数**
|参数|类型|是否必填|说明|
|----|----|----|----|
|pubOwner|[]byte|是|加密用户非对称秘钥公钥|
**返回字段:**
|返回字段|字段类型|说明|
|----|----|----|
|key |[]byte | 对称加密秘钥
|pub_r |string | 随机公钥r,用于重加密授权
|pub_u |string | 随机公钥u,用于重加密授权
#### 2.2 生成重加密秘钥分片
**函数原型**
```
GenerateKeyFragments(privOwner []byte, pubRecipient []byte, numSplit, threshold int) ([]*KFrag, error)
```
**请求参数**
|参数|类型|是否必填|说明|
|----|----|----|----|
|privOwner |[]byte|是|共享用户私钥|
|pubRecipient |[]byte|是|授权用户公钥|
|numSplit |int |是|秘钥分片数|
|threshold |int|是|最小秘钥分片重组阈值,不得大于numSplit|
**返回字段:**
|返回字段|字段类型|说明|
|----|----|----|
|KFrag |Random string | 随机数,每个分片不同
| |Value string | 重加密证明,每个分片不同
| |PrecurPub string | 随机公钥,所有分片相同
|err |error | 错误返回
#### 2.3 重组重加密秘钥分片
**函数原型**
```
AssembleReencryptFragment(privRecipient []byte, reKeyFrags []*ReKeyFrag) ([]byte, error)
```
**请求参数**
|参数|类型|是否必填|说明|
|----|----|----|----|
|privRecipient |[]byte|是|授权用户私钥|
|reKeyFrags |ReKeyFrag|是|重加密秘钥分片,从各个重加密节点获取|
```
type ReKeyFrag struct {
ReKeyR string // 重加密证明R
ReKeyU string // 重加密证明U
Random string // 随机数,每个分片不同
PrecurPub string // 随机公钥,所有分片相同
}
```
**返回字段:**
|返回字段|字段类型|说明|
|----|----|----|
|key |[]byte | 重组后的对称秘钥
|err |error | 错误返回
#### 3. RPC客户端
#### 3.1 创建jsonRPC客户端
**函数原型**
```
NewJSONClient(prefix, url string) (*JSONClient, error)
```
**请求参数**
|参数|类型|是否必填|说明|
|----|----|----|----|
|prefix |string|是|前缀|
|url |string|是|rpc服务端连接|
**返回字段:**
|返回字段|字段类型|说明|
|----|----|----|
|JSONClient |JSONClient | 客户端对象
|err |error | 错误返回
#### 3.2 rpc调用
**函数原型**
```
JSONClient.Call(method string, params, resp interface{}) error
```
**请求参数**
|参数|类型|是否必填|说明|
|----|----|----|----|
|method |string|是|rpc调用方法|
|params |interface|是|调用方法对应的参数|
|resp |interface|是|调用方法对应的返回值|
**返回字段:**
|返回字段|字段类型|说明|
|----|----|----|
|err |error | 错误返回
#### 3.3 发送交易
**函数原型**
```
JSONClient.SendTransaction(signedTx string) (string, error)
```
**请求参数**
|参数|类型|是否必填|说明|
|----|----|----|----|
|signedTx |string|是|已签名的交易|
**返回字段:**
|返回字段|字段类型|说明|
|----|----|----|
|string |string | 返回哈希
|err |error | 错误返回
#### 3.4 交易查询
**函数原型**
```
JSONClient.QueryTransaction(hash string) (*TransactionDetail, error)
```
**请求参数**
|参数|类型|是否必填|说明|
|----|----|----|----|
|hash |string|是|交易哈希|
**返回字段:**
|返回字段|字段类型|说明|
|----|----|----|
|TransactionDetail |TransactionDetail | 交易详情
|err |error | 错误返回
package sdk
import (
"errors"
"github.com/33cn/chain33-sdk-go/crypto"
"github.com/33cn/chain33-sdk-go/crypto/gm"
)
type Account struct {
PrivateKey []byte
PublicKey []byte
Address string
SignType string
}
func NewAccount(signType string) (*Account, error) {
if signType == "" {
signType = crypto.SECP256K1
}
account := Account{}
account.SignType = signType
if signType == crypto.SECP256K1 {
account.PrivateKey = crypto.GeneratePrivateKey()
account.PublicKey = crypto.PubKeyFromPrivate(account.PrivateKey)
addr, err := crypto.PubKeyToAddress(account.PublicKey)
if err != nil {
return nil, err
}
account.Address = addr
} else if signType == crypto.SM2 {
account.PrivateKey, account.PublicKey = gm.GenetateKey()
addr, err := crypto.PubKeyToAddress(account.PublicKey)
if err != nil {
return nil, err
}
account.Address = addr
} else if signType == crypto.ED25519 {
// TODO
} else {
return nil, errors.New("sign type not support")
}
return &account, nil
}
\ No newline at end of file
// Copyright Fuzamei Corp. 2020 All Rights Reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package jsonclient 实现JSON rpc客户端请求功能
package client
import (
"bytes"
"crypto/tls"
"encoding/json"
"errors"
"fmt"
"github.com/golang/protobuf/proto"
"io/ioutil"
"net/http"
"strings"
)
// JSONClient a object of jsonclient
type JSONClient struct {
url string
prefix string
tlsVerify bool
client *http.Client
}
func addPrefix(prefix, name string) string {
if strings.Contains(name, ".") {
return name
}
return prefix + "." + name
}
// NewJSONClient produce a json object
func NewJSONClient(prefix, url string) (*JSONClient, error) {
return new(prefix, url, false)
}
// New produce a jsonclient by perfix and url
func new(prefix, url string, tlsVerify bool) (*JSONClient, error) {
httpcli := http.DefaultClient
if strings.Contains(url, "https") { //暂不校验tls证书
httpcli = &http.Client{Transport: &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: !tlsVerify}}}
}
return &JSONClient{
url: url,
prefix: prefix,
tlsVerify: tlsVerify,
client: httpcli,
}, nil
}
type clientRequest struct {
Method string `json:"method"`
Params [1]interface{} `json:"params"`
ID uint64 `json:"id"`
}
type clientResponse struct {
ID uint64 `json:"id"`
Result *json.RawMessage `json:"result"`
Error interface{} `json:"error"`
}
func (client *JSONClient) Call(method string, params, resp interface{}) error {
method = addPrefix(client.prefix, method)
req := &clientRequest{}
req.Method = method
req.Params[0] = params
data, err := json.Marshal(req)
if err != nil {
return err
}
postresp, err := client.client.Post(client.url, "application/json", bytes.NewBuffer(data))
if err != nil {
return err
}
defer postresp.Body.Close()
b, err := ioutil.ReadAll(postresp.Body)
if err != nil {
return err
}
cresp := &clientResponse{}
err = json.Unmarshal(b, &cresp)
if err != nil {
return err
}
if cresp.Error != nil {
x, ok := cresp.Error.(string)
if !ok {
return fmt.Errorf("invalid error %v", cresp.Error)
}
if x == "" {
x = "unspecified error"
}
return fmt.Errorf(x)
}
if cresp.Result == nil {
return errors.New("Empty result")
}
if msg, ok := resp.(proto.Message); ok {
var str json.RawMessage
err = json.Unmarshal(*cresp.Result, &str)
if err != nil {
return err
}
b, err := str.MarshalJSON()
if err != nil {
return err
}
err = json.Unmarshal(b, msg)
if err != nil {
fmt.Println("err", err)
return err
}
return nil
}
return json.Unmarshal(*cresp.Result, resp)
}
type ParseFunc func(result json.RawMessage) (interface{},error)
//回调函数,用于自定义解析返回得result数据
func (client *JSONClient) CallBack(method string, params interface{},parseFunc ParseFunc) (interface{}, error) {
method = addPrefix(client.prefix, method)
req := &clientRequest{}
req.Method = method
req.Params[0] = params
data, err := json.Marshal(req)
if err != nil {
return nil, err
}
postresp, err := client.client.Post(client.url, "application/json", bytes.NewBuffer(data))
if err != nil {
return nil, err
}
defer postresp.Body.Close()
b, err := ioutil.ReadAll(postresp.Body)
if err != nil {
return nil, err
}
cresp := &clientResponse{}
err = json.Unmarshal(b, &cresp)
if err != nil {
return nil, err
}
if cresp.Error != nil {
x, ok := cresp.Error.(string)
if !ok {
return nil, fmt.Errorf("invalid error %v", cresp.Error)
}
if x == "" {
x = "unspecified error"
}
return nil, fmt.Errorf(x)
}
if cresp.Result == nil {
return nil, errors.New("Empty result")
}
return parseFunc(*cresp.Result)
}
// 发送交易
func (client *JSONClient) SendTransaction(signedTx string) (string, error) {
var res string
send := &RawParm{
Token: "BTY",
Data: signedTx,
}
err := client.Call("Chain33.SendTransaction", send, &res)
if err != nil {
return "", err
}
return res, nil
}
// 查询交易
func (client *JSONClient) QueryTransaction(hash string) (*TransactionDetail, error) {
query := QueryParm{
Hash: hash,
}
var detail TransactionDetail
err := client.Call("Chain33.QueryTransaction", query, &detail)
if err != nil {
return nil, err
}
return &detail, nil
}
package client
import "encoding/json"
// RawParm defines raw parameter command
type RawParm struct {
Token string `json:"token"`
Data string `json:"data"`
}
// CreateTxIn create tx input
type CreateTxIn struct {
Execer string `json:"execer"`
ActionName string `json:"actionName"`
Payload json.RawMessage `json:"payload"`
}
// QueryParm Query parameter
type QueryParm struct {
Hash string `json:"hash"`
}
// Signature parameter
type Signature struct {
Ty int32 `json:"ty"`
Pubkey string `json:"pubkey"`
Signature string `json:"signature"`
}
// Transaction parameter
type Transaction struct {
Execer string `json:"execer"`
Payload json.RawMessage `json:"payload"`
RawPayload string `json:"rawPayload"`
Signature *Signature `json:"signature"`
Fee int64 `json:"fee"`
FeeFmt string `json:"feefmt"`
Expire int64 `json:"expire"`
Nonce int64 `json:"nonce"`
From string `json:"from,omitempty"`
To string `json:"to"`
Amount int64 `json:"amount,omitempty"`
AmountFmt string `json:"amountfmt,omitempty"`
GroupCount int32 `json:"groupCount,omitempty"`
Header string `json:"header,omitempty"`
Next string `json:"next,omitempty"`
Hash string `json:"hash,omitempty"`
}
// ReceiptDataResult receipt data result
type ReceiptDataResult struct {
Ty int32 `json:"ty"`
TyName string `json:"tyName"`
Logs []*ReceiptLogResult `json:"logs"`
}
// ReceiptLogResult receipt log result
type ReceiptLogResult struct {
Ty int32 `json:"ty"`
TyName string `json:"tyName"`
Log json.RawMessage `json:"log"`
RawLog string `json:"rawLog"`
}
// Asset asset
type Asset struct {
Exec string `json:"exec"`
Symbol string `json:"symbol"`
Amount int64 `json:"amount"`
}
// TxProof :
type TxProof struct {
Proofs []string `json:"proofs"`
Index uint32 `json:"index"`
RootHash string `json:"rootHash"`
}
// TransactionDetail transaction detail
type TransactionDetail struct {
Tx *Transaction `json:"tx"`
Receipt *ReceiptDataResult `json:"receipt"`
Proofs []string `json:"proofs"`
Height int64 `json:"height"`
Index int64 `json:"index"`
Blocktime int64 `json:"blockTime"`
Amount int64 `json:"amount"`
Fromaddr string `json:"fromAddr"`
ActionName string `json:"actionName"`
Assets []*Asset `json:"assets"`
TxProofs []*TxProof `json:"txProofs"`
FullHash string `json:"fullHash"`
}
// Query4Jrpc query jrpc
type Query4Jrpc struct {
Execer string `json:"execer"`
FuncName string `json:"funcName"`
Payload json.RawMessage `json:"payload"`
}
package crypto
import (
"crypto/sha256"
"fmt"
"github.com/mr-tron/base58/base58"
)
//不同币种的前缀版本号
var coinPrefix = map[string][]byte{
"BTC": {0x00},
"BCH": {0x00},
"BTY": {0x00},
"LTC": {0x30},
"ZEC": {0x1c, 0xb8},
"USDT": {0x00},
}
var addrSeed = []byte("address seed bytes for public key")
//MaxExecNameLength 执行器名最大长度
const MaxExecNameLength = 100
func PubKeyToAddress(pub []byte) (addr string, err error) {
if len(pub) != 33 && len(pub) != 65 { //压缩格式 与 非压缩格式
return "", fmt.Errorf("invalid public key byte")
}
//添加版本号
hash160res := append(coinPrefix["BTY"], Rimp160(pub)...)
//添加校验码
cksum := checksum(hash160res)
address := append(hash160res, cksum[:]...)
//地址进行base58编码
addr = base58.Encode(address)
return
}
//checksum: first four bytes of double-SHA256.
func checksum(input []byte) (cksum [4]byte) {
h := sha256.New()
_, err := h.Write(input)
if err != nil {
return
}
intermediateHash := h.Sum(nil)
h.Reset()
_, err = h.Write(intermediateHash)
if err != nil {
return
}
finalHash := h.Sum(nil)
copy(cksum[:], finalHash[:])
return
}
func GetExecAddress(name string) string {
if len(name) > MaxExecNameLength {
panic("name too long")
}
var bname [200]byte
buf := append(bname[:0], addrSeed...)
buf = append(buf, []byte(name)...)
pub := Sha2Sum(buf)
var ad [25]byte
ad[0] = 0
copy(ad[1:21], Rimp160(pub))
sh := Sha2Sum(ad[0:21])
checksum := make([]byte, 4)
copy(checksum, sh[:4])
copy(ad[21:25], checksum[:])
addr := base58.Encode(ad[:])
return addr
}
\ No newline at end of file
package crypto
import (
"bytes"
"crypto/aes"
"crypto/cipher"
"crypto/rand"
"errors"
"io"
)
const (
AESPrivateKeyLength = 16
)
func pkcs7Padding(src []byte) []byte {
padding := aes.BlockSize - len(src)%aes.BlockSize
padtext := bytes.Repeat([]byte{byte(padding)}, padding)
return append(src, padtext...)
}
func aesCBCEncrypt(key, s []byte) ([]byte, error) {
return aesCBCEncryptWithRand(rand.Reader, key, s)
}
func aesCBCEncryptWithRand(prng io.Reader, key, s []byte) ([]byte, error) {
if len(s)%aes.BlockSize != 0 {
return nil, errors.New("Invalid plaintext. It must be a multiple of the block size")
}
block, err := aes.NewCipher(key)
if err != nil {
return nil, err
}
ciphertext := make([]byte, aes.BlockSize+len(s))
iv := ciphertext[:aes.BlockSize]
if _, err := io.ReadFull(prng, iv); err != nil {
return nil, err
}
mode := cipher.NewCBCEncrypter(block, iv)
mode.CryptBlocks(ciphertext[aes.BlockSize:], s)
return ciphertext, nil
}
func aesCBCDecrypt(key, src []byte) ([]byte, error) {
block, err := aes.NewCipher(key)
if err != nil {
return nil, err
}
if len(src) < aes.BlockSize {
return nil, errors.New("Invalid ciphertext. It must be a multiple of the block size")
}
iv := src[:aes.BlockSize]
src = src[aes.BlockSize:]
if len(src)%aes.BlockSize != 0 {
return nil, errors.New("Invalid ciphertext. It must be a multiple of the block size")
}
mode := cipher.NewCBCDecrypter(block, iv)
mode.CryptBlocks(src, src)
return src, nil
}
func pkcs7UnPadding(src []byte) ([]byte, error) {
length := len(src)
unpadding := int(src[length-1])
if unpadding > aes.BlockSize || unpadding == 0 {
return nil, errors.New("Invalid pkcs7 padding (unpadding > aes.BlockSize || unpadding == 0)")
}
pad := src[len(src)-unpadding:]
for i := 0; i < unpadding; i++ {
if pad[i] != byte(unpadding) {
return nil, errors.New("Invalid pkcs7 padding (pad[i] != unpadding)")
}
}
return src[:(length - unpadding)], nil
}
func AESCBCPKCS7Encrypt(key, src []byte) ([]byte, error) {
tmp := pkcs7Padding(src)
return aesCBCEncrypt(key, tmp)
}
func AESCBCPKCS7Decrypt(key, src []byte) ([]byte, error) {
pt, err := aesCBCDecrypt(key, src)
if err == nil {
return pkcs7UnPadding(pt)
}
return nil, err
}
func GenetateAESKey() []byte {
return getRandBytes(AESPrivateKeyLength)
}
\ No newline at end of file
package crypto
import (
"bytes"
"crypto/rand"
secp256k1 "github.com/btcsuite/btcd/btcec"
)
var (
SECP256K1 = "secp256k1"
SM2 = "sm2"
ED25519 = "ed25519" //TODO
)
func GeneratePrivateKey() []byte {
privKeyBytes := make([]byte, 32)
for {
key := getRandBytes(32)
if bytes.Compare(key, secp256k1.S256().Params().N.Bytes()) >= 0 {
continue
}
copy(privKeyBytes[:], key)
break
}
priv, _ := secp256k1.PrivKeyFromBytes(secp256k1.S256(), privKeyBytes[:])
copy(privKeyBytes[:], priv.Serialize())
return privKeyBytes
}
func PubKeyFromPrivate(privKey []byte) []byte {
_, pub := secp256k1.PrivKeyFromBytes(secp256k1.S256(), privKey[:])
pubSecp256k1 := make([]byte, 33)
copy(pubSecp256k1[:], pub.SerializeCompressed())
return pubSecp256k1
}
func Sign(msg []byte, privKey []byte) []byte {
priv, _ := secp256k1.PrivKeyFromBytes(secp256k1.S256(), privKey[:])
sig, err := priv.Sign(Sha256(msg))
if err != nil {
panic("Error signing secp256k1" + err.Error())
}
return sig.Serialize()
}
func PrivateFromByte(privKey []byte) *secp256k1.PrivateKey {
priv, _ := secp256k1.PrivKeyFromBytes(secp256k1.S256(), privKey[:])
return priv
}
func PublicFromByte(pubKey []byte) *secp256k1.PublicKey {
pub, _ := secp256k1.ParsePubKey(pubKey, secp256k1.S256())
return pub
}
func getRandBytes(numBytes int) []byte {
b := make([]byte, numBytes)
_, err := rand.Read(b)
if err != nil {
panic("Panic on a Crisis" + err.Error())
}
return b
}
\ No newline at end of file
package crypto
import (
"fmt"
"github.com/33cn/chain33-sdk-go/crypto/gm"
"github.com/33cn/chain33-sdk-go/types"
"github.com/stretchr/testify/assert"
"testing"
)
func TestAES(t *testing.T) {
var text = "hello aes"
var key = getRandBytes(16)
cipherText, err := AESCBCPKCS7Encrypt(key, []byte(text))
if err != nil {
fmt.Println(err)
return
}
cipher, err := AESCBCPKCS7Decrypt(key, cipherText)
if err != nil {
fmt.Println(err)
return
}
assert.Equal(t, text, string(cipher))
}
func TestSign(t *testing.T) {
priv, _ := types.FromHex("0xc2b31057b8692a56c7dd18199df71c1d21b781c0b6858c52997c9dbf778e8550")
msg := []byte("sign test")
sig := Sign(msg, priv)
fmt.Printf("sig = %x\n", sig)
}
func TestSM2(t *testing.T) {
priv, pub := gm.GenetateKey()
fmt.Println(types.ToHex(pub))
msg := []byte("sign test")
sig := gm.SM2Sign(msg, priv, nil)
fmt.Printf("sig = %x\n", sig)
result := gm.SM2Verify(msg, pub, sig, nil)
fmt.Println(result)
}
func TestSM4(t *testing.T) {
key := []byte{0x1, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10}
fmt.Printf("key = %v\n", key)
data := []byte{0x1, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10}
fmt.Printf("data = %x\n", data)
d0 := gm.SM4Encrypt(key, data)
fmt.Printf("d0 = %x\n", d0)
d1 := gm.SM4Decrypt(key, d0)
fmt.Printf("d1 = %x\n", d1)
assert.Equal(t, data, d1)
}
func TestAddress(t *testing.T) {
priv, _ := types.FromHex("0xc2b31057b8692a56c7dd18199df71c1d21b781c0b6858c52997c9dbf778e8550")
pub := PubKeyFromPrivate(priv)
fmt.Println(types.ToHex(pub))
addr, err := PubKeyToAddress(pub)
if err != nil {
panic(err)
}
fmt.Println(addr)
}
\ No newline at end of file
package gm
import (
"bytes"
"crypto/elliptic"
"crypto/rand"
"fmt"
"github.com/btcsuite/btcd/btcec"
"github.com/tjfoc/gmsm/sm2"
"math/big"
)
const (
SM2PrivateKeyLength = 32
)
var DefaultUID = []byte{0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38,
0x13, 0x23, 0x33, 0x43, 0x53, 0x63, 0x73, 0x83}
func getRandBytes(numBytes int) []byte {
b := make([]byte, numBytes)
_, err := rand.Read(b)
if err != nil {
panic("Panic on a Crisis" + err.Error())
}
return b
}
func privKeyFromBytes(curve elliptic.Curve, pk []byte) (*sm2.PrivateKey, *sm2.PublicKey) {
x, y := curve.ScalarBaseMult(pk)
priv := &sm2.PrivateKey{
PublicKey: sm2.PublicKey{
Curve: curve,
X: x,
Y: y,
},
D: new(big.Int).SetBytes(pk),
}
return priv, &priv.PublicKey
}
func parsePubKey(pubKeyStr []byte) (key *sm2.PublicKey) {
return sm2.Decompress(pubKeyStr)
}
//SerializePrivateKey 私钥序列化
func serializePrivateKey(p *sm2.PrivateKey) []byte {
b := make([]byte, 0, SM2PrivateKeyLength)
return paddedAppend(SM2PrivateKeyLength, b, p.D.Bytes())
}
//SerializePublicKey 公钥序列化
func serializePublicKey(p *sm2.PublicKey) []byte {
return sm2.Compress(p)
}
func paddedAppend(size uint, dst, src []byte) []byte {
for i := 0; i < int(size)-len(src); i++ {
dst = append(dst, 0)
}
return append(dst, src...)
}
func canonicalizeInt(val *big.Int) []byte {
b := val.Bytes()
if len(b) == 0 {
b = []byte{0x00}
}
if b[0]&0x80 != 0 {
paddedBytes := make([]byte, len(b)+1)
copy(paddedBytes[1:], b)
b = paddedBytes
}
return b
}
func serializeSignature(r, s *big.Int) []byte {
rb := canonicalizeInt(r)
sb := canonicalizeInt(s)
length := 6 + len(rb) + len(sb)
b := make([]byte, length)
b[0] = 0x30
b[1] = byte(length - 2)
b[2] = 0x02
b[3] = byte(len(rb))
offset := copy(b[4:], rb) + 4
b[offset] = 0x02
b[offset+1] = byte(len(sb))
copy(b[offset+2:], sb)
return b
}
func deserializeSignature(sigStr []byte) (*big.Int, *big.Int, error) {
sig, err := btcec.ParseDERSignature(sigStr, sm2.P256Sm2())
if err != nil {
return nil, nil, err
}
return sig.R, sig.S, nil
}
func GenetateKey() ([]byte, []byte) {
privKeyBytes := [SM2PrivateKeyLength]byte{}
for {
key := getRandBytes(32)
if bytes.Compare(key, sm2.P256Sm2().Params().N.Bytes()) >= 0 {
continue
}
copy(privKeyBytes[:], key)
break
}
priv, pub := privKeyFromBytes(sm2.P256Sm2(), privKeyBytes[:])
return serializePrivateKey(priv), serializePublicKey(pub)
}
func SM2Sign(msg []byte, privateKey []byte, uid []byte) []byte {
if uid == nil {
uid = DefaultUID
}
priv, _ := privKeyFromBytes(sm2.P256Sm2(), privateKey)
r, s, err := sm2.Sm2Sign(priv, msg, uid)
if err != nil {
return nil
}
return serializeSignature(r, s)
}
func SM2Verify(msg []byte, publicKey []byte, sig []byte, uid []byte) bool {
if uid == nil {
uid = DefaultUID
}
pub := parsePubKey(publicKey[:])
r, s, err := deserializeSignature(sig)
if err != nil {
fmt.Errorf("unmarshal sign failed")
return false
}
return sm2.Sm2Verify(pub, msg, uid, r, s)
}
func SM2Encrypt(publicKey []byte, data []byte) ([]byte, error) {
pub := parsePubKey(publicKey[:])
return sm2.Encrypt(pub, data)
}
func SM2Decrypt(privateKey []byte, data []byte) ([]byte, error) {
priv, _ := privKeyFromBytes(sm2.P256Sm2(), privateKey)
return sm2.Decrypt(priv, data)
}
func PubKeyFromPrivate(privKey []byte) []byte {
_, pub := privKeyFromBytes(sm2.P256Sm2(), privKey)
return serializePublicKey(pub)
}
\ No newline at end of file
package gm
import "github.com/tjfoc/gmsm/sm3"
//SM3Hash 加密算法
func SM3Hash(msg []byte) []byte {
c := sm3.New()
c.Write(msg)
return c.Sum(nil)
}
package gm
import (
"github.com/tjfoc/gmsm/sm4"
"log"
)
const (
SM4PrivateKeyLength = 16
)
func GenetateSM4Key() []byte {
return getRandBytes(SM4PrivateKeyLength)
}
func SM4Encrypt(key []byte, data []byte) []byte {
c, err := sm4.NewCipher(key)
if err != nil {
log.Fatal(err)
}
cipher := make([]byte, 16)
c.Encrypt(cipher, data)
return cipher
}
func SM4Decrypt(key []byte, data []byte) []byte {
c, err := sm4.NewCipher(key)
if err != nil {
log.Fatal(err)
}
cipher := make([]byte, 16)
c.Decrypt(cipher, data)
return cipher
}
\ No newline at end of file
package crypto
import (
"crypto/sha256"
"golang.org/x/crypto/ripemd160"
)
func Sha256(b []byte) []byte {
hasher := sha256.New()
hasher.Write(b)
return hasher.Sum(nil)
}
func Sha2Sum(b []byte) []byte {
tmp := sha256.Sum256(b)
tmp = sha256.Sum256(tmp[:])
return tmp[:]
}
func rimpHash(in []byte, out []byte) {
sha := sha256.New()
_, err := sha.Write(in)
if err != nil {
return
}
rim := ripemd160.New()
_, err = rim.Write(sha.Sum(nil)[:])
if err != nil {
return
}
copy(out, rim.Sum(nil))
}
// Rimp160 Returns hash: RIMP160( SHA256( data ) )
// Where possible, using RimpHash() should be a bit faster
func Rimp160(b []byte) []byte {
out := make([]byte, 20)
rimpHash(b, out[:])
return out[:]
}
# storage 合约sdk 使用
## 直接调用github.com/33cn/chain33-sdk-go/dapp/storage下面封装得函数
#### storage
#### 1.1 创建明文存证交易
**函数原型**
```
CreateContentStorageTx(paraName string, op int32, key string, content []byte, value string) (*types.Transaction, error)
```
**请求参数**
|参数|类型|是否必填|说明|
|----|----|----|----|
|paraName |string|是|平行链链名前缀,主链填空字符串|
|op |string|否|操作类型,0为新建存储,1为追加|
|key |string|否|不填默认采用txhash为key值|
|content |bytes|否|content和value二选一填值|
|value |string|否|content和value二选一填值|
**返回字段:**
|返回字段|字段类型|说明|
|----|----|----|
|*types.Transaction|*types.Transaction | 未签名的交易
|err |error | 错误返回
#### 1.2 创建hash存证交易
**函数原型**
```
CreateHashStorageTx(paraName string, key string, hash []byte, value string) (*types.Transaction, error)
```
**请求参数**
|参数|类型|是否必填|说明|
|----|----|----|----|
|paraName |string|是|平行链链名前缀,主链填空字符串|
|key |string|否|不填默认采用txhash为key值|
|hash |bytes|否|hash和value二选一填值|
|value |string|否|hash和value二选一填值|
**返回字段:**
|返回字段|字段类型|说明|
|----|----|----|
|*types.Transaction|*types.Transaction | 未签名的交易
|err |error | 错误返回
#### 1.3 创建链接存证交易
**函数原型**
```
CreateLinkStorageTx(paraName string, key string, link []byte, value string) (*types.Transaction, error)
```
**请求参数**
|参数|类型|是否必填|说明|
|----|----|----|----|
|paraName |string|是|平行链链名前缀,主链填空字符串|
|key |string|否|不填默认采用txhash为key值|
|link |bytes|否|link和value二选一填值|
|value |string|否|link和value二选一填值|
**返回字段:**
|返回字段|字段类型|说明|
|----|----|----|
|*types.Transaction|*types.Transaction | 未签名的交易
|err |error | 错误返回
#### 1.4 创建隐私存证交易
**函数原型**
```
CreateEncryptStorageTx(paraName string, key string, contentHash, encryptContent, nonce []byte, value string) *types.Transaction
```
**请求参数**
|参数|类型|是否必填|说明|
|----|----|----|----|
|paraName |string|是|平行链链名前缀,主链填空字符串|
|key |string|否|不填默认采用txhash为key值|
|contentHash |bytes|是|明文hash值用于校验结果一致性|
|encryptContent |bytes|是|源文件的密文,由加密key及nonce对明文加密得到该值|
|nonce |bytes|是|加密iv,通过AES进行加密时制定随机生成的iv,解密时需要使用该值|
|value |string|否|预留字段|
**返回字段:**
|返回字段|字段类型|说明|
|----|----|----|
|*types.Transaction|*types.Transaction | 未签名的交易
|err |error | 错误返回
#### 1.4 创建分享隐私交易
**函数原型**
```
CreateEncryptShareStorageTx(paraName string, key string, contentHash, encryptContent, publickey []byte, value string) *types.Transaction
```
**请求参数**
|参数|类型|是否必填|说明|
|----|----|----|----|
|paraName |string|是|平行链链名前缀,主链填空字符串|
|key |string|否|不填默认采用txhash为key值|
|contentHash |bytes|是|明文hash值用于校验结果一致性|
|encryptContent |bytes|是|源文件得密文,采用非对称加密,用公钥地址加密,用私钥解密|
|publickey |bytes|是|公钥|
|value |string|否|预留字段|
**返回字段:**
|返回字段|字段类型|说明|
|----|----|----|
|*types.Transaction|*types.Transaction | 未签名的交易
|err |error | 错误返回
#### 1.5 根据key查询存储内容
**函数原型**
```
QueryStorageByKey(prefix, url, key string) (*types.Storage, error)
```
**请求参数**
|参数|类型|是否必填|说明|
|----|----|----|----|
|prefix |string|是|平行链链名前缀,主链填空字符串|
|url |string|是|地址|
|key |string|是|key值|
**返回字段:**
|返回字段|字段类型|说明|
|----|----|----|
|*types.Storage|*types.Storage| 存证内容
|err |error | 错误返回
字段信息,可参考github.com/33cn/chain33-sdk-go/proto/sotrage.proto文件
\ No newline at end of file
package storage
const (
TyUnknowAction = iota
TyContentStorageAction
TyHashStorageAction
TyLinkStorageAction
TyEncryptStorageAction
TyEncryptShareStorageAction
FuncNameQueryStorage = "QueryStorage"
)
const (
OpCreate = int32(iota)
OpAdd
)
const StorageX = "storage"
const Addr = "1MCftFynyvG2F4ED5mdHYgziDxx6vDrScs"
package storage
import (
"encoding/json"
"fmt"
. "github.com/bitly/go-simplejson"
"github.com/33cn/chain33-sdk-go/client"
"github.com/33cn/chain33-sdk-go/types"
)
func QueryStorageByKey(prefix, url, key string) (*types.Storage, error) {
jsonClient, err := client.NewJSONClient(prefix, url)
if err != nil {
return nil, err
}
jsonraw, err := json.Marshal(&types.QueryStorage{TxHash: key})
if err != nil {
return nil, err
}
query := client.Query4Jrpc{
Execer: prefix + StorageX,
FuncName: FuncNameQueryStorage,
Payload: jsonraw,
}
//var storage types.Storage
data, err := jsonClient.CallBack("Chain33.Query", query, ParseStorage)
if err != nil {
return nil, err
}
return data.(*types.Storage), nil
}
//回调解析函数
func ParseStorage(raw json.RawMessage) (interface{}, error) {
js, err := NewJson(raw)
if err != nil {
return nil, err
}
if contentStorge, ok := js.CheckGet("contentStorage"); ok {
contentHex, _ := contentStorge.Get("content").String()
content, _ := types.FromHex(contentHex)
key, _ := contentStorge.Get("key").String()
value, _ := contentStorge.Get("value").String()
op, _ := contentStorge.Get("op").Int()
storage := &types.Storage{Ty: TyContentStorageAction, Value: &types.Storage_ContentStorage{ContentStorage: &types.ContentOnlyNotaryStorage{
Content: content,
Key: key,
Op: int32(op),
Value: value,
XXX_NoUnkeyedLiteral: struct{}{},
XXX_unrecognized: nil,
XXX_sizecache: 0,
}}}
return storage, nil
}
if linkStorge, ok := js.CheckGet("linkStorage"); ok {
linkHex, _ := linkStorge.Get("link").String()
link, _ := types.FromHex(linkHex)
key, _ := linkStorge.Get("key").String()
value, _ := linkStorge.Get("value").String()
storage := &types.Storage{Ty: TyLinkStorageAction, Value: &types.Storage_LinkStorage{LinkStorage: &types.LinkNotaryStorage{
Link: link,
Key: key,
Value: value,
XXX_NoUnkeyedLiteral: struct{}{},
XXX_unrecognized: nil,
XXX_sizecache: 0,
}}}
return storage, nil
}
if hashStorge, ok := js.CheckGet("hashStorage"); ok {
hashHex, _ := hashStorge.Get("hash").String()
hash, _ := types.FromHex(hashHex)
key, _ := hashStorge.Get("key").String()
value, _ := hashStorge.Get("value").String()
storage := &types.Storage{Ty: TyHashStorageAction, Value: &types.Storage_HashStorage{HashStorage: &types.HashOnlyNotaryStorage{
Hash: hash,
Key: key,
Value: value,
XXX_NoUnkeyedLiteral: struct{}{},
XXX_unrecognized: nil,
XXX_sizecache: 0,
}}}
return storage, nil
}
if encryptStorage, ok := js.CheckGet("encryptStorage"); ok {
contentHashHex, _ := encryptStorage.Get("contentHash").String()
contentHash, _ := types.FromHex(contentHashHex)
encryptContentHex, _ := encryptStorage.Get("encryptContent").String()
encryptContent, _ := types.FromHex(encryptContentHex)
nonceHex, _ := encryptStorage.Get("nonce").String()
nonce, _ := types.FromHex(nonceHex)
key, _ := encryptStorage.Get("key").String()
value, _ := encryptStorage.Get("value").String()
storage := &types.Storage{Ty: TyEncryptStorageAction, Value: &types.Storage_EncryptStorage{EncryptStorage: &types.EncryptNotaryStorage{
EncryptContent: encryptContent,
ContentHash: contentHash,
Nonce: nonce,
Key: key,
Value: value,
XXX_NoUnkeyedLiteral: struct{}{},
XXX_unrecognized: nil,
XXX_sizecache: 0,
}}}
return storage, nil
}
if encryptStorage, ok := js.CheckGet("encryptShareStorage"); ok {
contentHashHex, _ := encryptStorage.Get("contentHash").String()
contentHash, _ := types.FromHex(contentHashHex)
encryptContentHex, _ := encryptStorage.Get("encryptContent").String()
encryptContent, _ := types.FromHex(encryptContentHex)
pubKeyHex, _ := encryptStorage.Get("pubKey").String()
pubKey, _ := types.FromHex(pubKeyHex)
key, _ := encryptStorage.Get("key").String()
value, _ := encryptStorage.Get("value").String()
storage := &types.Storage{Ty: TyEncryptShareStorageAction, Value: &types.Storage_EncryptShareStorage{EncryptShareStorage: &types.EncryptShareNotaryStorage{
EncryptContent: encryptContent,
ContentHash: contentHash,
PubKey: pubKey,
Key: key,
Value: value,
XXX_NoUnkeyedLiteral: struct{}{},
XXX_unrecognized: nil,
XXX_sizecache: 0,
}}}
return storage, nil
}
return nil, fmt.Errorf("unknow type!")
}
package storage
import (
"fmt"
"github.com/33cn/chain33-sdk-go/crypto"
. "github.com/33cn/chain33-sdk-go/types"
"math/rand"
)
/*
//Op 0表示创建 1表示追加add (新版本才支持)
int32 op = 1;
//存在内容
bytes content = 2;
//自定义的主键,可以为空,如果没传,则用txhash为key
string key = 3;
//字符串值
string value = 4;
value 为预留字段
content和value只能有一个有效值
*/
//明文存证溯源
func CreateContentStorageTx(paraName string, op int32, key string, content []byte, value string) (*Transaction, error) {
if op != 0 && op != 1 {
return nil, fmt.Errorf("unknow op..,op only 0 or 1,please check!")
}
payload := &StorageAction{Ty: TyContentStorageAction, Value: &StorageAction_ContentStorage{&ContentOnlyNotaryStorage{
Content: content,
Op: op,
Key: key,
Value: value,
XXX_NoUnkeyedLiteral: struct{}{},
XXX_unrecognized: nil,
XXX_sizecache: 0,
}},
}
if paraName == "" {
tx := &Transaction{Execer: []byte(StorageX), Payload: Encode(payload), Fee: 1e5, Nonce: rand.Int63(), To: Addr}
return tx, nil
} else {
tx := &Transaction{Execer: []byte(paraName + StorageX), Payload: Encode(payload), Fee: 1e5, Nonce: rand.Int63(), To: crypto.GetExecAddress(paraName + StorageX)}
return tx, nil
}
}
//链接存证 paraName 平行链前缀,如果是主链则为空字符串,key唯一性,如果不填默认采用txhash为key
func CreateLinkStorageTx(paraName string, key string, link []byte, value string) (*Transaction, error) {
payload := &StorageAction{Ty: TyLinkStorageAction, Value: &StorageAction_LinkStorage{&LinkNotaryStorage{
Link: link,
Key: key,
Value: value,
XXX_NoUnkeyedLiteral: struct{}{},
XXX_unrecognized: nil,
XXX_sizecache: 0,
}},
}
if paraName == "" {
tx := &Transaction{Execer: []byte(StorageX), Payload: Encode(payload), Fee: 1e5, Nonce: rand.Int63(), To: Addr}
return tx, nil
} else {
tx := &Transaction{Execer: []byte(paraName + StorageX), Payload: Encode(payload), Fee: 1e5, Nonce: rand.Int63(), To: crypto.GetExecAddress(paraName + StorageX)}
return tx, nil
}
}
//hash存证
func CreateHashStorageTx(paraName string, key string, hash []byte, value string) (*Transaction, error) {
payload := &StorageAction{Ty: TyHashStorageAction, Value: &StorageAction_HashStorage{&HashOnlyNotaryStorage{
Hash: hash,
Key: key,
Value: value,
XXX_NoUnkeyedLiteral: struct{}{},
XXX_unrecognized: nil,
XXX_sizecache: 0,
}},
}
if paraName == "" {
tx := &Transaction{Execer: []byte(StorageX), Payload: Encode(payload), Fee: 1e5, Nonce: rand.Int63(), To: Addr}
return tx, nil
} else {
tx := &Transaction{Execer: []byte(paraName + StorageX), Payload: Encode(payload), Fee: 1e5, Nonce: rand.Int63(), To: crypto.GetExecAddress(paraName + StorageX)}
return tx, nil
}
}
//隐私加密存储
func CreateEncryptStorageTx(paraName string, key string, contentHash, encryptContent, nonce []byte, value string) *Transaction {
payload := &StorageAction{Ty: TyEncryptStorageAction, Value: &StorageAction_EncryptStorage{&EncryptNotaryStorage{
ContentHash: contentHash,
EncryptContent: encryptContent,
Nonce: nonce,
Key: key,
Value: value,
XXX_NoUnkeyedLiteral: struct{}{},
XXX_unrecognized: nil,
XXX_sizecache: 0,
}},
}
if paraName == "" {
tx := &Transaction{Execer: []byte(StorageX), Payload: Encode(payload), Fee: 1e5, Nonce: rand.Int63(), To: Addr}
return tx
} else {
tx := &Transaction{Execer: []byte(paraName + StorageX), Payload: Encode(payload), Fee: 1e5, Nonce: rand.Int63(), To: crypto.GetExecAddress(paraName + StorageX)}
return tx
}
}
//分享隐私加密存储
func CreateEncryptShareStorageTx(paraName string, key string, contentHash, encryptContent, publickey []byte, value string) *Transaction {
payload := &StorageAction{Ty: TyEncryptShareStorageAction, Value: &StorageAction_EncryptShareStorage{&EncryptShareNotaryStorage{
ContentHash: contentHash,
EncryptContent: encryptContent,
PubKey: publickey,
Key: key,
Value: value,
XXX_NoUnkeyedLiteral: struct{}{},
XXX_unrecognized: nil,
XXX_sizecache: 0,
}},
}
if paraName == "" {
tx := &Transaction{Execer: []byte(StorageX), Payload: Encode(payload), Fee: 1e5, Nonce: rand.Int63(), To: Addr}
return tx
} else {
tx := &Transaction{Execer: []byte(paraName + StorageX), Payload: Encode(payload), Fee: 1e5, Nonce: rand.Int63(), To: crypto.GetExecAddress(paraName + StorageX)}
return tx
}
}
package storage
import (
sdk "github.com/33cn/chain33-sdk-go"
"github.com/33cn/chain33-sdk-go/client"
"github.com/33cn/chain33-sdk-go/crypto"
"github.com/33cn/chain33-sdk-go/types"
"github.com/stretchr/testify/assert"
"testing"
"time"
)
var (
privkey = "cc38546e9e659d15e6b4893f0ab32a06d103931a8230b0bde71459d2b27d6944"
url = "http://fd.33.cn:1276"
)
func TestCreateContentStorageTx(t *testing.T) {
//第一次存储
tx, err := CreateContentStorageTx("", OpCreate, "", []byte("hello"), "")
assert.Nil(t, err)
hexbytes, _ := types.FromHex(privkey)
sdk.Sign(tx, hexbytes, crypto.SECP256K1)
txhash := types.ToHexPrefix(sdk.Hash(tx))
jsonclient, err := client.NewJSONClient("", url)
assert.Nil(t, err)
signTx := types.ToHexPrefix(types.Encode(tx))
reply, err := jsonclient.SendTransaction(signTx)
assert.Nil(t, err)
assert.Equal(t, txhash, reply)
time.Sleep(2 * time.Second)
detail, err := jsonclient.QueryTransaction(txhash)
assert.Nil(t, err)
assert.Equal(t, types.ExecOk, int(detail.Receipt.Ty))
//查询
storage, err := QueryStorageByKey("", url, txhash)
assert.Nil(t, err)
assert.Equal(t, []byte("hello"), storage.GetContentStorage().Content)
//第二次追加 老版本不支持
//tx,err=CreateContentStorageTx("",OpAdd,txhash,[]byte("world"),"")
//assert.Nil(t,err)
//tx.Sign(types.SECP256K1, priv)
//signTx =common.ToHexPrefix(types.Encode(tx))
//_,err=jsonclient.SendTransaction(signTx)
//assert.Nil(t,err)
//time.Sleep(2*time.Second)
////查询
//storage,err=QueryStorageByKey("",url,txhash)
//assert.Nil(t,err)
//assert.Equal(t,[]byte("hello,world"),storage.GetContentStorage().Content)
}
//hash,or link 存证
func TestCreateHashStorageTx(t *testing.T) {
tx, err := CreateHashStorageTx("", "", []byte("123456harrylee"), "")
assert.Nil(t, err)
//签名
hexbytes, _ := types.FromHex(privkey)
sdk.Sign(tx, hexbytes, crypto.SECP256K1)
txhash := types.ToHexPrefix(sdk.Hash(tx))
jsonclient, err := client.NewJSONClient("", url)
assert.Nil(t, err)
signTx := types.ToHexPrefix(types.Encode(tx))
reply, err := jsonclient.SendTransaction(signTx)
assert.Nil(t, err)
assert.Equal(t, txhash, reply)
time.Sleep(time.Second)
detail, err := jsonclient.QueryTransaction(txhash)
assert.Nil(t, err)
assert.Equal(t, types.ExecOk, int(detail.Receipt.Ty))
//查询
storage, err := QueryStorageByKey("", url, txhash)
assert.Nil(t, err)
assert.Equal(t, []byte("123456harrylee"), storage.GetHashStorage().Hash)
}
//hash,or link 存证
func TestCreateLinkStorageTx(t *testing.T) {
tx, err := CreateLinkStorageTx("", "", []byte("hello"), "")
assert.Nil(t, err)
hexbytes, _ := types.FromHex(privkey)
sdk.Sign(tx, hexbytes, crypto.SECP256K1)
txhash := types.ToHexPrefix(sdk.Hash(tx))
jsonclient, err := client.NewJSONClient("", url)
assert.Nil(t, err)
signTx := types.ToHexPrefix(types.Encode(tx))
reply, err := jsonclient.SendTransaction(signTx)
assert.Nil(t, err)
assert.Equal(t, txhash, reply)
time.Sleep(time.Second)
storage, err := QueryStorageByKey("", url, txhash)
assert.Nil(t, err)
assert.Equal(t, []byte("hello"), storage.GetLinkStorage().Link)
}
func TestByteFromHex(t *testing.T) {
hex := "0x313233343536"
data, err := types.FromHex(hex)
if err != nil {
t.Error(err)
}
t.Log(string(data))
}
module github.com/33cn/chain33-sdk-go
go 1.12
require (
github.com/NebulousLabs/Sia v1.3.7 // indirect
github.com/NebulousLabs/entropy-mnemonics v0.0.0-20181203154559-bc7e13c5ccd8 // indirect
github.com/NebulousLabs/errors v0.0.0-20181203160057-9f787ce8f69e // indirect
github.com/NebulousLabs/fastrand v0.0.0-20181203155948-6fb6489aac4e // indirect
github.com/NebulousLabs/merkletree v0.0.0-20181203152040-08d5d54b07f5 // indirect
github.com/XiaoMi/pegasus-go-client v0.0.0-20200509085530-e2f054e1ad99 // indirect
github.com/bitly/go-simplejson v0.5.0
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869
github.com/btcsuite/btcd v0.0.0-20190824003749-130ea5bddde3
github.com/decred/base58 v1.0.2 // indirect
github.com/dgraph-io/badger v1.6.1 // indirect
github.com/golang/protobuf v1.3.4
github.com/haltingstate/secp256k1-go v0.0.0-20151224084235-572209b26df6 // indirect
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/huin/goupnp v1.0.0 // indirect
github.com/jackpal/go-nat-pmp v1.0.2 // indirect
github.com/mattn/go-colorable v0.1.6 // indirect
github.com/mr-tron/base58 v1.1.3
github.com/pkg/errors v0.9.1 // indirect
github.com/rs/cors v1.7.0 // indirect
github.com/spf13/cobra v1.0.0 // indirect
github.com/stretchr/testify v1.5.1
github.com/syndtr/goleveldb v1.0.0 // indirect
github.com/tjfoc/gmsm v1.3.1
golang.org/x/crypto v0.0.0-20191219195013-becbf705a915
google.golang.org/grpc v1.29.1 // indirect
)
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
github.com/33cn/chain33 v6.1.0+incompatible h1:N3SgEnRMkX7XlWD1t4I9wyMvE+GKOt8LxnND1hDUY+o=
github.com/33cn/chain33 v6.1.0+incompatible/go.mod h1:khADGunPneuDRjGaLqtVPhdf3og3ci+f7f8s/FLVcS0=
github.com/33cn/chain33-sdk-go v0.0.0-20200608040832-fce9f88a2d72 h1:BTBW6DqHyGUDlKT4FgjB7iTgKfSbFySnHyThChTDpUM=
github.com/AndreasBriese/bbloom v0.0.0-20190306092124-e2d15f34fcf9 h1:HD8gA2tkByhMAwYaFAX9w2l7vxvBQ5NMoxDrkhqhtn4=
github.com/AndreasBriese/bbloom v0.0.0-20190306092124-e2d15f34fcf9/go.mod h1:bOvUY6CB00SOBii9/FifXqc0awNKxLFCL/+pkDPuyl8=
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46/go.mod h1:3wb06e3pkSAbeQ52E9H9iFoQsEEwGN64994WTCIhntQ=
github.com/NebulousLabs/Sia v1.3.7 h1:gYfYnXVyeaEzyyVwjpQjszBcENNZ8DPIJc/pgOiLuGA=
github.com/NebulousLabs/Sia v1.3.7/go.mod h1:SCASk6mV8QdEojKyecjj/Jd0OGSXkZonkhow7XXKk6Q=
github.com/NebulousLabs/entropy-mnemonics v0.0.0-20181203154559-bc7e13c5ccd8 h1:wPFCU8DwC4k5C2LfJc/rVp4cmTqzF3vyydxRR3b3HhQ=
github.com/NebulousLabs/entropy-mnemonics v0.0.0-20181203154559-bc7e13c5ccd8/go.mod h1:ed2ZsnmJfqVNZOwxWWFZaSHJY3ifOjCS7i5yX9dvKHs=
github.com/NebulousLabs/errors v0.0.0-20181203160057-9f787ce8f69e h1:9UwdEr0AFI021vXG+hXDGH9ZHGuNtPCdJkRTqcIhJ3A=
github.com/NebulousLabs/errors v0.0.0-20181203160057-9f787ce8f69e/go.mod h1:J7tUI9Fg4YuFLsqeLE5uIp93Fot9oBCw2vwZJvLmWso=
github.com/NebulousLabs/fastrand v0.0.0-20181203155948-6fb6489aac4e h1:n+DcnTNkQnHlwpsrHoQtkrJIO7CBx029fw6oR4vIob4=
github.com/NebulousLabs/fastrand v0.0.0-20181203155948-6fb6489aac4e/go.mod h1:Bdzq+51GR4/0DIhaICZEOm+OHvXGwwB2trKZ8B4Y6eQ=
github.com/NebulousLabs/merkletree v0.0.0-20181203152040-08d5d54b07f5 h1:pk9SclNGplPbF6YDIDKMhHh9SaUWcoxPkMr7zdu1hfk=
github.com/NebulousLabs/merkletree v0.0.0-20181203152040-08d5d54b07f5/go.mod h1:Cn056wBLKay+uIS9LJn7ymwhgC5mqbOtG6iOhEvyy4M=
github.com/OneOfOne/xxhash v1.2.2 h1:KMrpdQIwFcEqXDklaen+P1axHaj9BSKzvpUUfnHldSE=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/PuerkitoBio/purell v1.0.0/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0=
github.com/PuerkitoBio/urlesc v0.0.0-20160726150825-5bd2802263f2/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
github.com/XiaoMi/pegasus-go-client v0.0.0-20200509085530-e2f054e1ad99 h1:6pai/DC2n9MptYa2SJVvay3TapspjrayvLj3GuX8yZM=
github.com/XiaoMi/pegasus-go-client v0.0.0-20200509085530-e2f054e1ad99/go.mod h1:H83dStz3HvHBFC0n7QK+qLHAjqsIghFOFx2TCvq6vzI=
github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/apache/thrift v0.13.0 h1:5hryIiq9gtn+MiLVn0wP37kb/uTeRZgN08WoCsAhIhI=
github.com/apache/thrift v0.13.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ=
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
github.com/bitly/go-simplejson v0.5.0 h1:6IH+V8/tVMab511d5bn4M7EwGXZf9Hj6i2xSwkNEM+Y=
github.com/bitly/go-simplejson v0.5.0/go.mod h1:cXHtHw4XUPsvGaxgjIAn8PhEWG9NfngEKAMDJEczWVA=
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 h1:DDGfHa7BWjL4YnC6+E63dPcxHo2sUxDIu8g3QgEJdRY=
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4=
github.com/btcsuite/btcd v0.0.0-20190824003749-130ea5bddde3 h1:A/EVblehb75cUgXA5njHPn0kLAsykn6mJGz7rnmW5W0=
github.com/btcsuite/btcd v0.0.0-20190824003749-130ea5bddde3/go.mod h1:3J08xEfcugPacsc34/LKRU2yO7YmuT8yt28J8k2+rrI=
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f/go.mod h1:TdznJufoqS23FtqVCzL0ZqgP5MqXbb4fg/WgDys70nA=
github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg=
github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd/go.mod h1:HHNXQzUsZCxOoE+CPiyCTO6x34Zs86zZUiwtpXoGdtg=
github.com/btcsuite/goleveldb v0.0.0-20160330041536-7834afc9e8cd/go.mod h1:F+uVaaLLH7j4eDXPRvw78tMflu7Ie2bzYOH4Y8rRKBY=
github.com/btcsuite/snappy-go v0.0.0-20151229074030-0bdef8d06723/go.mod h1:8woku9dyThutzjeg+3xrA5iCpBRH8XEEg3lh6TiUghc=
github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792/go.mod h1:ghJtEyQwv5/p4Mg4C0fgbePVuGr935/5ddU9Z3TmDRY=
github.com/btcsuite/winsvc v1.0.0/go.mod h1:jsenWakMcC0zFBFurPLEAyrnc/teJEM1O46fmI40EZs=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko=
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
github.com/coreos/bbolt v1.3.2 h1:wZwiHHUieZCquLkDL0B8UhzreNWsPHooDAG3q34zk0s=
github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk=
github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE=
github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/davecgh/go-spew v0.0.0-20151105211317-5215b55f46b2/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495 h1:6IyqGr3fnd0tM3YxipK27TUskaOVUjU2nG45yzwcQKY=
github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/decred/base58 v1.0.2 h1:yupIH6bg+q7KYfBk7oUv3xFjKGb5Ypm4+v/61X4keGY=
github.com/decred/base58 v1.0.2/go.mod h1:pXP9cXCfM2sFLb2viz2FNIdeMWmZDBKG3ZBYbiSM78E=
github.com/decred/dcrd/crypto/blake256 v1.0.0 h1:/8DMNYp9SGi5f0w7uCm6d6M4OU2rGFK09Y2A4Xv7EE0=
github.com/decred/dcrd/crypto/blake256 v1.0.0/go.mod h1:sQl2p6Y26YV+ZOcSTP6thNdn47hh8kt6rqSlvmrXFAc=
github.com/dgraph-io/badger v1.6.1 h1:w9pSFNSdq/JPM1N12Fz/F/bzo993Is1W+Q7HjPzi7yg=
github.com/dgraph-io/badger v1.6.1/go.mod h1:FRmFw3uxvcpa8zG3Rxs0th+hCLIuaQg8HlNV5bjgnuU=
github.com/dgraph-io/ristretto v0.0.2 h1:a5WaUrDa0qm0YrAAS1tUykT5El3kt62KNZZeMxQn3po=
github.com/dgraph-io/ristretto v0.0.2/go.mod h1:KPxhHT9ZxKefz+PCeOGsrHpl1qZ7i70dGTu2u+Ahh6E=
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2 h1:tdlZCpZ/P9DhczCTSixgIKmwPv6+wP5DGjqLYw5SUiA=
github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw=
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
github.com/docker/spdystream v0.0.0-20160310174837-449fdfce4d96/go.mod h1:Qh8CwZgvJUkLughtfhJv5dyTYa91l1fOUCrgjqmcifM=
github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo=
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/elazarl/goproxy v0.0.0-20170405201442-c4fc26588b6e/go.mod h1:/Zj4wYkgs4iZTTu3o/KG3Itv/qCCa8VVMlb3i9OVuzc=
github.com/emicklei/go-restful v0.0.0-20170410110728-ff4f55a20633/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs=
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/evanphx/json-patch v4.2.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8vw=
github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g=
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/ghodss/yaml v0.0.0-20150909031657-73d445a93680/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
github.com/go-logr/logr v0.1.0/go.mod h1:ixOQHD9gLJUVQQ2ZOR7zLEifBX6tGkNJF4QyIY7sIas=
github.com/go-openapi/jsonpointer v0.0.0-20160704185906-46af16f9f7b1/go.mod h1:+35s3my2LFTysnkMfxsJBAMHj/DoqoB9knIWoYG/Vk0=
github.com/go-openapi/jsonreference v0.0.0-20160704190145-13c6e3589ad9/go.mod h1:W3Z9FmVs9qj+KR4zFKmDPGiLdk1D9Rlm7cyMvf57TTg=
github.com/go-openapi/spec v0.0.0-20160808142527-6aced65f8501/go.mod h1:J8+jY1nAiCcj+friV/PDoE1/3eeccG9LYBs0tYvLOWc=
github.com/go-openapi/swag v0.0.0-20160704191624-1d0bd113de87/go.mod h1:DXUve3Dpr1UfpPtxFw+EFuQ41HhCWZfha5jSVRG7C7I=
github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4=
github.com/gogo/protobuf v1.2.2-0.20190723190241-65acae22fc9d/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
github.com/golang/protobuf v0.0.0-20161109072736-4bd1920723d7/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw=
github.com/golang/protobuf v1.3.4 h1:87PNWwrRvUSnqS4dlcBU/ftvOIBep4sYuBLlh6rX2wk=
github.com/golang/protobuf v1.3.4/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw=
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db h1:woRePGFeVFfLKN/pOkfl+p/TAqKOfFu+7KPlMVpok/w=
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/google/go-cmp v0.3.0 h1:crn/baboCvb5fXaQ0IJ1SGTsTVrWpDsCWC8EGETZijY=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/gofuzz v0.0.0-20161122191042-44d81051d367/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY=
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/googleapis/gnostic v0.0.0-20170729233727-0c5108395e2d/go.mod h1:sJBsCZ4ayReDTBIg8b9dl28c5xFWyhBTVRp3pOg5EKY=
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
github.com/haltingstate/secp256k1-go v0.0.0-20151224084235-572209b26df6 h1:HE4YDtvtpZgjRJ2tCOmaXlcpBTFG2e0jvfNntM5sXOs=
github.com/haltingstate/secp256k1-go v0.0.0-20151224084235-572209b26df6/go.mod h1:73mKQiY8bLnscfGakn57WAJZTzT0eSUAy3qgMQNR/DI=
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/golang-lru v0.5.4 h1:YDjusn29QI/Das2iO9M0BHnIbxPeyuCHsjMW+lJfyTc=
github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/huin/goupnp v1.0.0 h1:wg75sLpL6DZqwHQN6E1Cfk6mtfzS45z8OV+ic+DtHRo=
github.com/huin/goupnp v1.0.0/go.mod h1:n9v9KO1tAxYH82qOn+UTIFQDmx5n1Zxd/ClZDMX7Bnc=
github.com/huin/goutil v0.0.0-20170803182201-1ca381bf3150/go.mod h1:PpLOETDnJ0o3iZrZfqZzyLl6l7F3c6L1oWn7OICBi6o=
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/jackpal/go-nat-pmp v1.0.2 h1:KzKSgb7qkJvOUTqYl9/Hg/me3pWgBmERKrTGD7BdWus=
github.com/jackpal/go-nat-pmp v1.0.2/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc=
github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ=
github.com/json-iterator/go v0.0.0-20180612202835-f2b4162afba3/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
github.com/json-iterator/go v1.1.8/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4=
github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.2.0 h1:s5hAObm+yFO5uHYt5dYjxi2rXrsnmRpJx4OYvIWUaQs=
github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/mailru/easyjson v0.0.0-20160728113105-d5b7844b561a/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
github.com/mattn/go-colorable v0.1.6 h1:6Su7aK7lXmJ/U79bYtBjLNaha4Fs1Rg9plHpcH+vvnE=
github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v0.0.0-20180320133207-05fbef0ca5da/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/mr-tron/base58 v1.1.3 h1:v+sk57XuaCKGXpWtVBX8YJzO7hMGx4Aajh4TQbdEFdc=
github.com/mr-tron/base58 v1.1.3/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc=
github.com/munnerz/goautoneg v0.0.0-20120707110453-a547fc61f48d/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+o7JKHSa8/e818NopupXU1YMK5fe1lsApnBw=
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
github.com/onsi/ginkgo v0.0.0-20170829012221-11459a886d9c/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.10.1 h1:q/mM8GF/n0shIN8SaAZ0V+jnLPzen6WIVZdiwrRlMlo=
github.com/onsi/ginkgo v1.10.1/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/gomega v0.0.0-20170829124025-dcabb60a477c/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA=
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/onsi/gomega v1.7.0 h1:XPnZz8VVBHjVsy1vzJmRwIcSwiUO+JFfrv/xGiigmME=
github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v0.0.0-20151028094244-d8ed2627bdf0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso=
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/prometheus/common v0.0.0-20181113130724-41aa239b4cce/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro=
github.com/prometheus/common v0.4.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4=
github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
github.com/rs/cors v1.7.0 h1:+88SsELBHx5r+hZ8TCkggzSstaWNbDvThkVK8H6f9ik=
github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU=
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI=
github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
github.com/spf13/cobra v0.0.5 h1:f0B+LkLX6DtmRH1isoNA9VTtNUK9K8xYd28JNNfOv/s=
github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tLCHU=
github.com/spf13/cobra v1.0.0 h1:6m/oheQuQ13N9ks4hubMG6BnvwOeaJrqSPLahSnczz8=
github.com/spf13/cobra v1.0.0/go.mod h1:/6GTrnGXV9HjY+aR4k0oJ5tcvakLuG6EuKReYlHNrgE=
github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
github.com/spf13/pflag v0.0.0-20170130214245-9ff6c6923cff/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s=
github.com/spf13/viper v1.4.0/go.mod h1:PTJ7Z/lr49W6bUbkmS1V3by4uWynFiR9p7+dSq/yZzE=
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1 h1:2vfRuCMp5sSVIDSqO8oNnWJq7mPa6KVP3iPIwFBuy8A=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v0.0.0-20151208002404-e3a8ff8ce365/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/syndtr/goleveldb v1.0.0 h1:fBdIW9lB4Iz0n9khmH8w27SJ3QEJ7+IgjPEwGSZiFdE=
github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ=
github.com/tjfoc/gmsm v1.3.1 h1:+k3IAlF81c31/TllJmIfuCYnjl8ziMdTWGWJcP9J1uo=
github.com/tjfoc/gmsm v1.3.1/go.mod h1:HaUcFuY0auTiaHB9MHFGCPx5IaLhTUd2atbCFBQXn9w=
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc=
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
go.etcd.io/bbolt v1.3.2 h1:Z/90sZLPOeCy2PwprqkFa25PdkusRzaj9P8zm/KNyvk=
go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44 h1:9lP3x0pW80sDI6t1UMSLA4to18W7R7imwAI/sWS9S8Q=
golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191219195013-becbf705a915 h1:aJ0ex187qoXrJHPo8ZasVTASQB7llQP6YeNzgDALPRk=
golang.org/x/crypto v0.0.0-20191219195013-becbf705a915/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/net v0.0.0-20170114055629-f2499483f923/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20181011144130-49bb7cea24b1/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3 h1:0GoQqolDA55aaLxZyTzK/Y2ePZzZTUrRacwib7cNsYQ=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190522155817-f3200d17e092/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20191004110552-13f9640d40b9/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20191105084925-a882066a44e0 h1:QPlSTtPE2k6PZPasQUbzuK3p9JbS+vMXYVto8g/yrsg=
golang.org/x/net v0.0.0-20191105084925-a882066a44e0/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20170830134202-bb24a47a89ea/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191010194322-b09406accb47/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae h1:/WDfKMnPU+m5M4xB+6x4kaepxRw6jWvR5iDRdvjHgy8=
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.0.0-20160726164857-2910a502d2bf/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20181011042414-1f849cf54d09/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135 h1:5Beo0mZN8dRzgrMMkDp0jc8YXQKx9DiJ2k1dkvGsn5A=
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55 h1:gSJIx1SDwno+2ElGhA4+qG2zF97qiUzTM+rQ0klBOcE=
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
google.golang.org/grpc v1.21.0/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM=
google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY=
google.golang.org/grpc v1.29.1 h1:EC2SB8S04d2r73uptxphDSUG+kTKVgjRPF+N3xpxRB4=
google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3IjizoKk=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
gopkg.in/natefinch/lumberjack.v2 v2.0.0 h1:1Lc07Kr7qY4U2YPouBjpCLxpiyxIVoxqXgkXLknAOE8=
gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k=
gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/tomb.v2 v2.0.0-20161208151619-d5d1b5820637 h1:yiW+nvdHb9LVqSHQBXfZCieqV4fzYhNBql77zY0ykqs=
gopkg.in/tomb.v2 v2.0.0-20161208151619-d5d1b5820637/go.mod h1:BHsqpu/nsuzkT5BpiH1EMZPLyqSMM8JbIavyFACoFNk=
gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
k8s.io/apimachinery v0.0.0-20191123233150-4c4803ed55e3 h1:FErmbNIJruD5GT2oVEjtPn5Ar5+rcWJsC8/PPUkR0s4=
k8s.io/apimachinery v0.0.0-20191123233150-4c4803ed55e3/go.mod h1:b9qmWdKlLuU9EBh+06BtLcSf/Mu89rWL33naRxs1uZg=
k8s.io/gengo v0.0.0-20190128074634-0689ccc1d7d6/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0=
k8s.io/klog v0.0.0-20181102134211-b9b56d5dfc92/go.mod h1:Gq+BEi5rUBO/HRz0bTSXDUcqjScdoY3a9IHpCEIOOfk=
k8s.io/klog v1.0.0/go.mod h1:4Bi6QPql/J/LkTDqv7R/cd3hPo4k2DG6Ptcz060Ez5I=
k8s.io/kube-openapi v0.0.0-20191107075043-30be4d16710a/go.mod h1:1TqjTSzOxsLGIKfj0lK8EeCP7K1iUG65v09OM0/WG5E=
sigs.k8s.io/structured-merge-diff v0.0.0-20190525122527-15d366b2352e/go.mod h1:wWxsB5ozmmv/SG7nM11ayaAW51xMvak/t1r0CSlcokI=
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
package sdk
import (
"crypto/rand"
"errors"
"fmt"
secp256k1 "github.com/btcsuite/btcd/btcec"
"github.com/33cn/chain33-sdk-go/crypto"
"github.com/33cn/chain33-sdk-go/types"
"golang.org/x/crypto/blake2b"
"math/big"
)
var baseN = secp256k1.S256().Params().N
type KFrag struct {
Random string
Value string
PrecurPub string
}
type ReKeyFrag struct {
ReKeyR string
ReKeyU string
Random string
PrecurPub string
}
type EccPoit struct {
x *big.Int
y *big.Int
}
func NewEccPoint(pubStr string) (*EccPoit, error) {
reKeyRByte, err := types.FromHex(pubStr)
if err != nil {
fmt.Errorf("get reKeyRByte err", err)
return nil, err
}
reKeyR := crypto.PublicFromByte(reKeyRByte)
return &EccPoit{x: reKeyR.X, y: reKeyR.Y}, nil
}
func (p *EccPoit) Add(v *EccPoit) *EccPoit {
if v == nil {
return p
}
p.x, p.y = secp256k1.S256().Add(p.x, p.y, v.x, v.y)
return p
}
func (p *EccPoit) MulInt(i *big.Int) *EccPoit {
p.x, p.y = secp256k1.S256().ScalarMult(p.x, p.y, i.Bytes())
return p
}
func (p *EccPoit) ToPublicKey() *secp256k1.PublicKey {
return &secp256k1.PublicKey{
X: p.x,
Y: p.y,
Curve: secp256k1.S256(),
}
}
func hashToModInt(digest []byte) *big.Int {
sum := new(big.Int).SetBytes(digest)
one := big.NewInt(1)
order_minus_1 := big.NewInt(0)
order_minus_1.Sub(baseN, one)
bigNum := big.NewInt(0)
bigNum.Mod(sum, order_minus_1).Add(bigNum, one)
return bigNum
}
func makeShamirPolyCoeff(threshold int) []*big.Int {
coeffs := make([]*big.Int, threshold-1)
for i,_ := range coeffs {
coeffs[i] = new(big.Int).SetBytes(crypto.GeneratePrivateKey())
}
return coeffs
}
// p0*x^2 + p1 * x + p2
func hornerPolyEval(poly []*big.Int, x *big.Int) *big.Int {
result := big.NewInt(0)
result.Add(result, poly[0])
for i := 1; i < len(poly); i++ {
result = result.Mul(result, x).Add(result, poly[i])
}
return result.Mod(result, baseN)
}
func calcPart(a *big.Int, b *big.Int) *big.Int {
p := big.NewInt(0)
p.Sub(a, b).Mod(p, baseN)
res := big.NewInt(0)
res.Mul(a, p.ModInverse(p, baseN)).Mod(res, baseN)
return res
}
func calcLambdaCoeff(inId *big.Int, selectedIds []*big.Int) *big.Int {
var ids []*big.Int
for _, id := range selectedIds {
if inId.Cmp(id) == 0 {
continue
}
ids = append(ids, id)
}
if len(ids) == 0 {
return big.NewInt(1)
}
result := calcPart(ids[0], inId)
if len(ids) > 1 {
for _, id_j := range ids[1:] {
result.Mul(result, calcPart(id_j, inId)).Mod(result, baseN)
}
}
return result
}
func getRandomInt(order *big.Int) *big.Int {
randInt, err := rand.Int(rand.Reader, order)
if err != nil {
panic(err)
}
return randInt
}
func GeneratePreEncryptKey(pubOwner []byte) ([]byte, string, string) {
pubOwnerKey := crypto.PublicFromByte(pubOwner)
priv_r := crypto.PrivateFromByte(crypto.GeneratePrivateKey())
priv_u := crypto.PrivateFromByte(crypto.GeneratePrivateKey())
result := &secp256k1.PublicKey{}
result.Curve = pubOwnerKey.Curve
sum := big.NewInt(0)
sum.Add(priv_u.D, priv_r.D).Mod(sum, baseN)
result.X, result.Y = secp256k1.S256().ScalarMult(pubOwnerKey.X, pubOwnerKey.Y, sum.Bytes())
pub_r := types.ToHex((*secp256k1.PublicKey)(&priv_r.PublicKey).SerializeCompressed())
pub_u := types.ToHex((*secp256k1.PublicKey)(&priv_u.PublicKey).SerializeCompressed())
return result.SerializeCompressed()[1:], pub_r, pub_u
}
func GenerateKeyFragments(privOwner []byte, pubRecipient []byte, numSplit, threshold int) ([]*KFrag, error) {
precursor := crypto.PrivateFromByte(crypto.GeneratePrivateKey())
precurPub := types.ToHex((*secp256k1.PublicKey)(&precursor.PublicKey).SerializeCompressed())
privOwnerKey := crypto.PrivateFromByte(privOwner)
pubRecipientKey := crypto.PublicFromByte(pubRecipient)
dh_Alice_poit_x := types.ECDH(precursor, pubRecipientKey)
dAliceHash, err := blake2b.New256(precursor.X.Bytes())
if err != nil {
fmt.Errorf("Generate precursor Key err", err)
return nil, err
}
dAliceHash.Write(pubRecipientKey.X.Bytes())
dAliceHash.Write(dh_Alice_poit_x)
dAlice := dAliceHash.Sum(nil)
dAliceBN := hashToModInt(dAlice)
// c0, c1, c2
f0 := big.NewInt(0)
f0.Mul(privOwnerKey.D, f0.ModInverse(dAliceBN, baseN)).Mod(f0, baseN)
kFrags := make([]*KFrag, numSplit)
if numSplit == 1 {
id := getRandomInt(baseN)
kFrags[0] = &KFrag{Random: id.String(), Value: f0.String(), PrecurPub: precurPub}
} else {
coeffs := makeShamirPolyCoeff(threshold)
coeffs = append(coeffs, f0)
// rk[i] = f2*id^2 + f1*id + f0
for i, _ := range kFrags {
id := getRandomInt(baseN)
dShareHash, err := blake2b.New256(precursor.X.Bytes())
if err != nil {
fmt.Errorf("Generate precursor Key err", err)
return nil, err
}
dShareHash.Write(pubRecipientKey.X.Bytes())
dShareHash.Write(dh_Alice_poit_x)
dShareHash.Write(id.Bytes())
share := hashToModInt(dShareHash.Sum(nil))
rk := hornerPolyEval(coeffs, share)
kFrags[i] = &KFrag{Random: id.String(), Value: rk.String(), PrecurPub: precurPub}
}
}
return kFrags, nil
}
func AssembleReencryptFragment(privRecipient []byte, reKeyFrags []*ReKeyFrag) ([]byte, error) {
privRecipientKey := crypto.PrivateFromByte(privRecipient)
precursor, err := types.FromHex(reKeyFrags[0].PrecurPub)
if err != nil {
fmt.Errorf("FromHex", err)
return nil, err
}
precursorPubKey := crypto.PublicFromByte(precursor)
dh_Bob_poit_x := types.ECDH(privRecipientKey, precursorPubKey)
dBobHash, err := blake2b.New256(precursorPubKey.X.Bytes())
if err != nil {
fmt.Errorf("Generate precursor Key err", err)
return nil, err
}
dBobHash.Write(privRecipientKey.X.Bytes())
dBobHash.Write(dh_Bob_poit_x)
dhBob := dBobHash.Sum(nil)
dhBobBN := hashToModInt(dhBob)
var share_key *EccPoit
if len(reKeyFrags) == 1 {
rPoint, err := NewEccPoint(reKeyFrags[0].ReKeyR)
if err != nil {
fmt.Errorf("get reKeyRByte err", err)
return nil, err
}
uPoint, err := NewEccPoint(reKeyFrags[0].ReKeyU)
if err != nil {
fmt.Errorf("get reKeyRByte err", err)
return nil, err
}
share_key = rPoint.Add(uPoint).MulInt(dhBobBN)
} else {
var eFinal, vFinal *EccPoit
ids := make([]*big.Int, len(reKeyFrags))
for x, _ := range ids {
xs, err := blake2b.New256(precursorPubKey.X.Bytes())
if err != nil {
fmt.Errorf("Generate precursor Key err", err)
return nil, err
}
xs.Write(privRecipientKey.X.Bytes())
xs.Write(dh_Bob_poit_x)
random, ret := new(big.Int).SetString(reKeyFrags[x].Random, 10)
if !ret {
fmt.Errorf("AssembleReencryptFragment.get value int",)
return nil, errors.New("get big int value from keyFragment failed")
}
xs.Write(random.Bytes())
ids[x] = hashToModInt(xs.Sum(nil))
}
for i, id := range ids {
lambda := calcLambdaCoeff(id, ids)
if lambda == nil {
continue
}
rPoint, err := NewEccPoint(reKeyFrags[i].ReKeyR)
if err != nil {
fmt.Errorf("get reKeyRByte err", err)
return nil, err
}
uPoint, err := NewEccPoint(reKeyFrags[i].ReKeyU)
if err != nil {
fmt.Errorf("get reKeyRByte err", err)
return nil, err
}
e := rPoint.MulInt(lambda)
v := uPoint.MulInt(lambda)
eFinal = e.Add(eFinal)
vFinal = v.Add(vFinal)
}
share_key = eFinal.Add(vFinal).MulInt(dhBobBN)
}
return share_key.ToPublicKey().SerializeCompressed(), nil
}
\ No newline at end of file
#!/bin/sh
protoc --go_out=plugins=grpc:../types/ ./*.proto --proto_path=.
syntax = "proto3";
package types;
message Transaction {
bytes execer = 1;
bytes payload = 2;
Signature signature = 3;
int64 fee = 4;
int64 expire = 5;
//随机ID,可以防止payload 相同的时候,交易重复
int64 nonce = 6;
//对方地址,如果没有对方地址,可以为空
string to = 7;
int32 groupCount = 8;
bytes header = 9;
bytes next = 10;
}
message Signature {
int32 ty = 1;
bytes pubkey = 2;
//当ty为5时,格式应该用RingSignature去解析
bytes signature = 3;
}
syntax = "proto3";
package types;
//后面如果有其他数据模型可继续往上面添加
message Storage {
oneof value {
ContentOnlyNotaryStorage contentStorage = 1;
HashOnlyNotaryStorage hashStorage = 2;
LinkNotaryStorage linkStorage = 3;
EncryptNotaryStorage encryptStorage = 4;
EncryptShareNotaryStorage encryptShareStorage = 5;
}
int32 ty = 6;
}
message StorageAction {
oneof value {
ContentOnlyNotaryStorage contentStorage = 1;
HashOnlyNotaryStorage hashStorage = 2;
LinkNotaryStorage linkStorage = 3;
EncryptNotaryStorage encryptStorage = 4;
EncryptShareNotaryStorage encryptShareStorage = 5;
}
int32 ty = 6;
}
// 内容存证模型
message ContentOnlyNotaryStorage {
//长度需要小于512k
bytes content = 1;
//自定义的主键,可以为空,如果没传,则用txhash为key
string key = 2;
// Op 0表示创建 1表示追加add
int32 op = 3;
//字符串值
string value = 4;
}
//哈希存证模型,推荐使用sha256哈希,限制256位得摘要值
message HashOnlyNotaryStorage {
//长度固定为32字节
bytes hash = 1;
//自定义的主键,可以为空,如果没传,则用txhash为key
string key = 2;
//字符串值
string value = 3;
}
// 链接存证模型
message LinkNotaryStorage {
//存证内容的链接,可以写入URL,或者其他可用于定位源文件得线索.
bytes link = 1;
//源文件得hash值,推荐使用sha256哈希,限制256位得摘要值
bytes hash = 2;
//自定义的主键,可以为空,如果没传,则用txhash为key
string key = 3;
//字符串值
string value = 4;
}
// 隐私存证模型,如果一个文件需要存证,且不公开内容,可以选择将源文件通过对称加密算法加密后上链
message EncryptNotaryStorage {
//存证明文内容的hash值,推荐使用sha256哈希,限制256位得摘要值
bytes contentHash = 1;
//源文件得密文,由加密key及nonce对明文加密得到该值。
bytes encryptContent = 2;
//加密iv,通过AES进行加密时制定随机生成的iv,解密时需要使用该值
bytes nonce = 3;
//自定义的主键,可以为空,如果没传,则用txhash为key
string key = 4;
//字符串值
string value = 5;
}
// 分享隐私存证模型,需要完备的sdk或者相应的密钥库支持
message EncryptShareNotaryStorage {
//存证明文内容的hash值,推荐使用sha256哈希,限制256位得摘要值
bytes contentHash = 1;
//源文件得密文。,用公钥地址加密
bytes encryptContent = 2;
//公钥
bytes pubKey = 3;
//自定义的主键,可以为空,如果没传,则用txhash为key
string key = 4;
//字符串值
string value = 5;
}
//根据txhash去状态数据库中查询存储内容
message QueryStorage {
string txHash = 1;
}
//批量查询有可能导致数据库崩溃
message BatchQueryStorage {
repeated string txHashs = 1;
}
message BatchReplyStorage {
repeated Storage storages = 1;
}
message ReceiptStorage {
}
\ No newline at end of file
package sdk
import (
"errors"
"github.com/33cn/chain33-sdk-go/crypto"
"github.com/33cn/chain33-sdk-go/crypto/gm"
. "github.com/33cn/chain33-sdk-go/types"
)
func Sign(tx *Transaction, privateKey []byte, signType string) (*Transaction, error) {
if signType == "" {
signType = crypto.SECP256K1
}
tx.Signature = nil
if signType == crypto.SECP256K1 {
pub := crypto.PubKeyFromPrivate(privateKey)
data := Encode(tx)
signature := crypto.Sign(data, privateKey)
tx.Signature = &Signature{
Ty: 1,
Pubkey: pub,
Signature: signature,
}
} else if signType == crypto.SM2 {
pub := gm.PubKeyFromPrivate(privateKey)
data := Encode(tx)
signature := gm.SM2Sign(data, privateKey, nil)
tx.Signature = &Signature{
Ty: 1,
Pubkey: pub,
Signature: signature,
}
} else if signType == crypto.ED25519 {
// TODO
} else {
return nil, errors.New("sign type not support")
}
return tx, nil
}
func cloneTx(tx *Transaction) *Transaction {
copytx := &Transaction{}
copytx.Execer = tx.Execer
copytx.Payload = tx.Payload
copytx.Signature = tx.Signature
copytx.Fee = tx.Fee
copytx.Expire = tx.Expire
copytx.Nonce = tx.Nonce
copytx.To = tx.To
copytx.GroupCount = tx.GroupCount
copytx.Header = tx.Header
copytx.Next = tx.Next
return copytx
}
func Hash(tx *Transaction) []byte {
copytx := cloneTx(tx)
copytx.Signature = nil
copytx.Header = nil
data := Encode(copytx)
return crypto.Sha256(data)
}
\ No newline at end of file
// Code generated by protoc-gen-go. DO NOT EDIT.
// source: sdk.proto
package types
import (
fmt "fmt"
proto "github.com/golang/protobuf/proto"
math "math"
)
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf
// This is a compile-time assertion to ensure that this generated file
// is compatible with the proto package it is being compiled against.
// A compilation error at this line likely means your copy of the
// proto package needs to be updated.
const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package
type Transaction struct {
Execer []byte `protobuf:"bytes,1,opt,name=execer,proto3" json:"execer,omitempty"`
Payload []byte `protobuf:"bytes,2,opt,name=payload,proto3" json:"payload,omitempty"`
Signature *Signature `protobuf:"bytes,3,opt,name=signature,proto3" json:"signature,omitempty"`
Fee int64 `protobuf:"varint,4,opt,name=fee,proto3" json:"fee,omitempty"`
Expire int64 `protobuf:"varint,5,opt,name=expire,proto3" json:"expire,omitempty"`
//随机ID,可以防止payload 相同的时候,交易重复
Nonce int64 `protobuf:"varint,6,opt,name=nonce,proto3" json:"nonce,omitempty"`
//对方地址,如果没有对方地址,可以为空
To string `protobuf:"bytes,7,opt,name=to,proto3" json:"to,omitempty"`
GroupCount int32 `protobuf:"varint,8,opt,name=groupCount,proto3" json:"groupCount,omitempty"`
Header []byte `protobuf:"bytes,9,opt,name=header,proto3" json:"header,omitempty"`
Next []byte `protobuf:"bytes,10,opt,name=next,proto3" json:"next,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *Transaction) Reset() { *m = Transaction{} }
func (m *Transaction) String() string { return proto.CompactTextString(m) }
func (*Transaction) ProtoMessage() {}
func (*Transaction) Descriptor() ([]byte, []int) {
return fileDescriptor_70decb0fb6f436df, []int{0}
}
func (m *Transaction) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_Transaction.Unmarshal(m, b)
}
func (m *Transaction) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_Transaction.Marshal(b, m, deterministic)
}
func (m *Transaction) XXX_Merge(src proto.Message) {
xxx_messageInfo_Transaction.Merge(m, src)
}
func (m *Transaction) XXX_Size() int {
return xxx_messageInfo_Transaction.Size(m)
}
func (m *Transaction) XXX_DiscardUnknown() {
xxx_messageInfo_Transaction.DiscardUnknown(m)
}
var xxx_messageInfo_Transaction proto.InternalMessageInfo
func (m *Transaction) GetExecer() []byte {
if m != nil {
return m.Execer
}
return nil
}
func (m *Transaction) GetPayload() []byte {
if m != nil {
return m.Payload
}
return nil
}
func (m *Transaction) GetSignature() *Signature {
if m != nil {
return m.Signature
}
return nil
}
func (m *Transaction) GetFee() int64 {
if m != nil {
return m.Fee
}
return 0
}
func (m *Transaction) GetExpire() int64 {
if m != nil {
return m.Expire
}
return 0
}
func (m *Transaction) GetNonce() int64 {
if m != nil {
return m.Nonce
}
return 0
}
func (m *Transaction) GetTo() string {
if m != nil {
return m.To
}
return ""
}
func (m *Transaction) GetGroupCount() int32 {
if m != nil {
return m.GroupCount
}
return 0
}
func (m *Transaction) GetHeader() []byte {
if m != nil {
return m.Header
}
return nil
}
func (m *Transaction) GetNext() []byte {
if m != nil {
return m.Next
}
return nil
}
type Signature struct {
Ty int32 `protobuf:"varint,1,opt,name=ty,proto3" json:"ty,omitempty"`
Pubkey []byte `protobuf:"bytes,2,opt,name=pubkey,proto3" json:"pubkey,omitempty"`
//当ty为5时,格式应该用RingSignature去解析
Signature []byte `protobuf:"bytes,3,opt,name=signature,proto3" json:"signature,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *Signature) Reset() { *m = Signature{} }
func (m *Signature) String() string { return proto.CompactTextString(m) }
func (*Signature) ProtoMessage() {}
func (*Signature) Descriptor() ([]byte, []int) {
return fileDescriptor_70decb0fb6f436df, []int{1}
}
func (m *Signature) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_Signature.Unmarshal(m, b)
}
func (m *Signature) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_Signature.Marshal(b, m, deterministic)
}
func (m *Signature) XXX_Merge(src proto.Message) {
xxx_messageInfo_Signature.Merge(m, src)
}
func (m *Signature) XXX_Size() int {
return xxx_messageInfo_Signature.Size(m)
}
func (m *Signature) XXX_DiscardUnknown() {
xxx_messageInfo_Signature.DiscardUnknown(m)
}
var xxx_messageInfo_Signature proto.InternalMessageInfo
func (m *Signature) GetTy() int32 {
if m != nil {
return m.Ty
}
return 0
}
func (m *Signature) GetPubkey() []byte {
if m != nil {
return m.Pubkey
}
return nil
}
func (m *Signature) GetSignature() []byte {
if m != nil {
return m.Signature
}
return nil
}
func init() {
proto.RegisterType((*Transaction)(nil), "types.Transaction")
proto.RegisterType((*Signature)(nil), "types.Signature")
}
func init() {
proto.RegisterFile("sdk.proto", fileDescriptor_70decb0fb6f436df)
}
var fileDescriptor_70decb0fb6f436df = []byte{
// 255 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x5c, 0x90, 0x41, 0x4e, 0xc3, 0x30,
0x10, 0x45, 0xe5, 0xa4, 0x49, 0xc9, 0xb4, 0x42, 0xd5, 0x08, 0xa1, 0x59, 0x20, 0x14, 0x75, 0xe5,
0x55, 0x16, 0x70, 0x04, 0x4e, 0x80, 0xe1, 0x02, 0x6e, 0x32, 0x94, 0xa8, 0xc8, 0xb6, 0x1c, 0x47,
0xaa, 0xcf, 0xc0, 0xa5, 0x51, 0x9c, 0x14, 0x2a, 0x76, 0xf3, 0x5e, 0xa2, 0x3f, 0x9e, 0x0f, 0xd5,
0xd0, 0x9d, 0x1a, 0xe7, 0x6d, 0xb0, 0x58, 0x84, 0xe8, 0x78, 0xd8, 0x7f, 0x67, 0xb0, 0x79, 0xf7,
0xda, 0x0c, 0xba, 0x0d, 0xbd, 0x35, 0x78, 0x0f, 0x25, 0x9f, 0xb9, 0x65, 0x4f, 0xa2, 0x16, 0x72,
0xab, 0x16, 0x42, 0x82, 0xb5, 0xd3, 0xf1, 0xcb, 0xea, 0x8e, 0xb2, 0xf4, 0xe1, 0x82, 0xd8, 0x40,
0x35, 0xf4, 0x47, 0xa3, 0xc3, 0xe8, 0x99, 0xf2, 0x5a, 0xc8, 0xcd, 0xd3, 0xae, 0x49, 0xe1, 0xcd,
0xdb, 0xc5, 0xab, 0xbf, 0x5f, 0x70, 0x07, 0xf9, 0x07, 0x33, 0xad, 0x6a, 0x21, 0x73, 0x35, 0x8d,
0xf3, 0x4e, 0xd7, 0x7b, 0xa6, 0x22, 0xc9, 0x85, 0xf0, 0x0e, 0x0a, 0x63, 0x4d, 0xcb, 0x54, 0x26,
0x3d, 0x03, 0xde, 0x42, 0x16, 0x2c, 0xad, 0x6b, 0x21, 0x2b, 0x95, 0x05, 0x8b, 0x8f, 0x00, 0x47,
0x6f, 0x47, 0xf7, 0x62, 0x47, 0x13, 0xe8, 0xa6, 0x16, 0xb2, 0x50, 0x57, 0x66, 0x4a, 0xff, 0x64,
0xdd, 0xb1, 0xa7, 0x6a, 0xbe, 0x68, 0x26, 0x44, 0x58, 0x19, 0x3e, 0x07, 0x82, 0x64, 0xd3, 0xbc,
0x7f, 0x85, 0xea, 0xf7, 0xcd, 0x69, 0x51, 0x4c, 0x35, 0x14, 0x2a, 0x0b, 0x71, 0x0a, 0x72, 0xe3,
0xe1, 0xc4, 0x71, 0x69, 0x60, 0x21, 0x7c, 0xf8, 0x5f, 0xc0, 0xf6, 0xea, 0xdc, 0x43, 0x99, 0xea,
0x7e, 0xfe, 0x09, 0x00, 0x00, 0xff, 0xff, 0x21, 0x50, 0x6b, 0x04, 0x7b, 0x01, 0x00, 0x00,
}
// Code generated by protoc-gen-go. DO NOT EDIT.
// source: storage.proto
package types
import (
fmt "fmt"
proto "github.com/golang/protobuf/proto"
math "math"
)
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf
// This is a compile-time assertion to ensure that this generated file
// is compatible with the proto package it is being compiled against.
// A compilation error at this line likely means your copy of the
// proto package needs to be updated.
const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package
//后面如果有其他数据模型可继续往上面添加
type Storage struct {
// Types that are valid to be assigned to Value:
// *Storage_ContentStorage
// *Storage_HashStorage
// *Storage_LinkStorage
// *Storage_EncryptStorage
// *Storage_EncryptShareStorage
Value isStorage_Value `protobuf_oneof:"value"`
Ty int32 `protobuf:"varint,6,opt,name=ty,proto3" json:"ty,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *Storage) Reset() { *m = Storage{} }
func (m *Storage) String() string { return proto.CompactTextString(m) }
func (*Storage) ProtoMessage() {}
func (*Storage) Descriptor() ([]byte, []int) {
return fileDescriptor_0d2c4ccf1453ffdb, []int{0}
}
func (m *Storage) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_Storage.Unmarshal(m, b)
}
func (m *Storage) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_Storage.Marshal(b, m, deterministic)
}
func (m *Storage) XXX_Merge(src proto.Message) {
xxx_messageInfo_Storage.Merge(m, src)
}
func (m *Storage) XXX_Size() int {
return xxx_messageInfo_Storage.Size(m)
}
func (m *Storage) XXX_DiscardUnknown() {
xxx_messageInfo_Storage.DiscardUnknown(m)
}
var xxx_messageInfo_Storage proto.InternalMessageInfo
type isStorage_Value interface {
isStorage_Value()
}
type Storage_ContentStorage struct {
ContentStorage *ContentOnlyNotaryStorage `protobuf:"bytes,1,opt,name=contentStorage,proto3,oneof"`
}
type Storage_HashStorage struct {
HashStorage *HashOnlyNotaryStorage `protobuf:"bytes,2,opt,name=hashStorage,proto3,oneof"`
}
type Storage_LinkStorage struct {
LinkStorage *LinkNotaryStorage `protobuf:"bytes,3,opt,name=linkStorage,proto3,oneof"`
}
type Storage_EncryptStorage struct {
EncryptStorage *EncryptNotaryStorage `protobuf:"bytes,4,opt,name=encryptStorage,proto3,oneof"`
}
type Storage_EncryptShareStorage struct {
EncryptShareStorage *EncryptShareNotaryStorage `protobuf:"bytes,5,opt,name=encryptShareStorage,proto3,oneof"`
}
func (*Storage_ContentStorage) isStorage_Value() {}
func (*Storage_HashStorage) isStorage_Value() {}
func (*Storage_LinkStorage) isStorage_Value() {}
func (*Storage_EncryptStorage) isStorage_Value() {}
func (*Storage_EncryptShareStorage) isStorage_Value() {}
func (m *Storage) GetValue() isStorage_Value {
if m != nil {
return m.Value
}
return nil
}
func (m *Storage) GetContentStorage() *ContentOnlyNotaryStorage {
if x, ok := m.GetValue().(*Storage_ContentStorage); ok {
return x.ContentStorage
}
return nil
}
func (m *Storage) GetHashStorage() *HashOnlyNotaryStorage {
if x, ok := m.GetValue().(*Storage_HashStorage); ok {
return x.HashStorage
}
return nil
}
func (m *Storage) GetLinkStorage() *LinkNotaryStorage {
if x, ok := m.GetValue().(*Storage_LinkStorage); ok {
return x.LinkStorage
}
return nil
}
func (m *Storage) GetEncryptStorage() *EncryptNotaryStorage {
if x, ok := m.GetValue().(*Storage_EncryptStorage); ok {
return x.EncryptStorage
}
return nil
}
func (m *Storage) GetEncryptShareStorage() *EncryptShareNotaryStorage {
if x, ok := m.GetValue().(*Storage_EncryptShareStorage); ok {
return x.EncryptShareStorage
}
return nil
}
func (m *Storage) GetTy() int32 {
if m != nil {
return m.Ty
}
return 0
}
// XXX_OneofWrappers is for the internal use of the proto package.
func (*Storage) XXX_OneofWrappers() []interface{} {
return []interface{}{
(*Storage_ContentStorage)(nil),
(*Storage_HashStorage)(nil),
(*Storage_LinkStorage)(nil),
(*Storage_EncryptStorage)(nil),
(*Storage_EncryptShareStorage)(nil),
}
}
type StorageAction struct {
// Types that are valid to be assigned to Value:
// *StorageAction_ContentStorage
// *StorageAction_HashStorage
// *StorageAction_LinkStorage
// *StorageAction_EncryptStorage
// *StorageAction_EncryptShareStorage
Value isStorageAction_Value `protobuf_oneof:"value"`
Ty int32 `protobuf:"varint,6,opt,name=ty,proto3" json:"ty,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *StorageAction) Reset() { *m = StorageAction{} }
func (m *StorageAction) String() string { return proto.CompactTextString(m) }
func (*StorageAction) ProtoMessage() {}
func (*StorageAction) Descriptor() ([]byte, []int) {
return fileDescriptor_0d2c4ccf1453ffdb, []int{1}
}
func (m *StorageAction) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_StorageAction.Unmarshal(m, b)
}
func (m *StorageAction) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_StorageAction.Marshal(b, m, deterministic)
}
func (m *StorageAction) XXX_Merge(src proto.Message) {
xxx_messageInfo_StorageAction.Merge(m, src)
}
func (m *StorageAction) XXX_Size() int {
return xxx_messageInfo_StorageAction.Size(m)
}
func (m *StorageAction) XXX_DiscardUnknown() {
xxx_messageInfo_StorageAction.DiscardUnknown(m)
}
var xxx_messageInfo_StorageAction proto.InternalMessageInfo
type isStorageAction_Value interface {
isStorageAction_Value()
}
type StorageAction_ContentStorage struct {
ContentStorage *ContentOnlyNotaryStorage `protobuf:"bytes,1,opt,name=contentStorage,proto3,oneof"`
}
type StorageAction_HashStorage struct {
HashStorage *HashOnlyNotaryStorage `protobuf:"bytes,2,opt,name=hashStorage,proto3,oneof"`
}
type StorageAction_LinkStorage struct {
LinkStorage *LinkNotaryStorage `protobuf:"bytes,3,opt,name=linkStorage,proto3,oneof"`
}
type StorageAction_EncryptStorage struct {
EncryptStorage *EncryptNotaryStorage `protobuf:"bytes,4,opt,name=encryptStorage,proto3,oneof"`
}
type StorageAction_EncryptShareStorage struct {
EncryptShareStorage *EncryptShareNotaryStorage `protobuf:"bytes,5,opt,name=encryptShareStorage,proto3,oneof"`
}
func (*StorageAction_ContentStorage) isStorageAction_Value() {}
func (*StorageAction_HashStorage) isStorageAction_Value() {}
func (*StorageAction_LinkStorage) isStorageAction_Value() {}
func (*StorageAction_EncryptStorage) isStorageAction_Value() {}
func (*StorageAction_EncryptShareStorage) isStorageAction_Value() {}
func (m *StorageAction) GetValue() isStorageAction_Value {
if m != nil {
return m.Value
}
return nil
}
func (m *StorageAction) GetContentStorage() *ContentOnlyNotaryStorage {
if x, ok := m.GetValue().(*StorageAction_ContentStorage); ok {
return x.ContentStorage
}
return nil
}
func (m *StorageAction) GetHashStorage() *HashOnlyNotaryStorage {
if x, ok := m.GetValue().(*StorageAction_HashStorage); ok {
return x.HashStorage
}
return nil
}
func (m *StorageAction) GetLinkStorage() *LinkNotaryStorage {
if x, ok := m.GetValue().(*StorageAction_LinkStorage); ok {
return x.LinkStorage
}
return nil
}
func (m *StorageAction) GetEncryptStorage() *EncryptNotaryStorage {
if x, ok := m.GetValue().(*StorageAction_EncryptStorage); ok {
return x.EncryptStorage
}
return nil
}
func (m *StorageAction) GetEncryptShareStorage() *EncryptShareNotaryStorage {
if x, ok := m.GetValue().(*StorageAction_EncryptShareStorage); ok {
return x.EncryptShareStorage
}
return nil
}
func (m *StorageAction) GetTy() int32 {
if m != nil {
return m.Ty
}
return 0
}
// XXX_OneofWrappers is for the internal use of the proto package.
func (*StorageAction) XXX_OneofWrappers() []interface{} {
return []interface{}{
(*StorageAction_ContentStorage)(nil),
(*StorageAction_HashStorage)(nil),
(*StorageAction_LinkStorage)(nil),
(*StorageAction_EncryptStorage)(nil),
(*StorageAction_EncryptShareStorage)(nil),
}
}
// 内容存证模型
type ContentOnlyNotaryStorage struct {
//长度需要小于512k
Content []byte `protobuf:"bytes,1,opt,name=content,proto3" json:"content,omitempty"`
//自定义的主键,可以为空,如果没传,则用txhash为key
Key string `protobuf:"bytes,2,opt,name=key,proto3" json:"key,omitempty"`
// Op 0表示创建 1表示追加add
Op int32 `protobuf:"varint,3,opt,name=op,proto3" json:"op,omitempty"`
//字符串值
Value string `protobuf:"bytes,4,opt,name=value,proto3" json:"value,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *ContentOnlyNotaryStorage) Reset() { *m = ContentOnlyNotaryStorage{} }
func (m *ContentOnlyNotaryStorage) String() string { return proto.CompactTextString(m) }
func (*ContentOnlyNotaryStorage) ProtoMessage() {}
func (*ContentOnlyNotaryStorage) Descriptor() ([]byte, []int) {
return fileDescriptor_0d2c4ccf1453ffdb, []int{2}
}
func (m *ContentOnlyNotaryStorage) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_ContentOnlyNotaryStorage.Unmarshal(m, b)
}
func (m *ContentOnlyNotaryStorage) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_ContentOnlyNotaryStorage.Marshal(b, m, deterministic)
}
func (m *ContentOnlyNotaryStorage) XXX_Merge(src proto.Message) {
xxx_messageInfo_ContentOnlyNotaryStorage.Merge(m, src)
}
func (m *ContentOnlyNotaryStorage) XXX_Size() int {
return xxx_messageInfo_ContentOnlyNotaryStorage.Size(m)
}
func (m *ContentOnlyNotaryStorage) XXX_DiscardUnknown() {
xxx_messageInfo_ContentOnlyNotaryStorage.DiscardUnknown(m)
}
var xxx_messageInfo_ContentOnlyNotaryStorage proto.InternalMessageInfo
func (m *ContentOnlyNotaryStorage) GetContent() []byte {
if m != nil {
return m.Content
}
return nil
}
func (m *ContentOnlyNotaryStorage) GetKey() string {
if m != nil {
return m.Key
}
return ""
}
func (m *ContentOnlyNotaryStorage) GetOp() int32 {
if m != nil {
return m.Op
}
return 0
}
func (m *ContentOnlyNotaryStorage) GetValue() string {
if m != nil {
return m.Value
}
return ""
}
//哈希存证模型,推荐使用sha256哈希,限制256位得摘要值
type HashOnlyNotaryStorage struct {
//长度固定为32字节
Hash []byte `protobuf:"bytes,1,opt,name=hash,proto3" json:"hash,omitempty"`
//自定义的主键,可以为空,如果没传,则用txhash为key
Key string `protobuf:"bytes,2,opt,name=key,proto3" json:"key,omitempty"`
//字符串值
Value string `protobuf:"bytes,3,opt,name=value,proto3" json:"value,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *HashOnlyNotaryStorage) Reset() { *m = HashOnlyNotaryStorage{} }
func (m *HashOnlyNotaryStorage) String() string { return proto.CompactTextString(m) }
func (*HashOnlyNotaryStorage) ProtoMessage() {}
func (*HashOnlyNotaryStorage) Descriptor() ([]byte, []int) {
return fileDescriptor_0d2c4ccf1453ffdb, []int{3}
}
func (m *HashOnlyNotaryStorage) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_HashOnlyNotaryStorage.Unmarshal(m, b)
}
func (m *HashOnlyNotaryStorage) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_HashOnlyNotaryStorage.Marshal(b, m, deterministic)
}
func (m *HashOnlyNotaryStorage) XXX_Merge(src proto.Message) {
xxx_messageInfo_HashOnlyNotaryStorage.Merge(m, src)
}
func (m *HashOnlyNotaryStorage) XXX_Size() int {
return xxx_messageInfo_HashOnlyNotaryStorage.Size(m)
}
func (m *HashOnlyNotaryStorage) XXX_DiscardUnknown() {
xxx_messageInfo_HashOnlyNotaryStorage.DiscardUnknown(m)
}
var xxx_messageInfo_HashOnlyNotaryStorage proto.InternalMessageInfo
func (m *HashOnlyNotaryStorage) GetHash() []byte {
if m != nil {
return m.Hash
}
return nil
}
func (m *HashOnlyNotaryStorage) GetKey() string {
if m != nil {
return m.Key
}
return ""
}
func (m *HashOnlyNotaryStorage) GetValue() string {
if m != nil {
return m.Value
}
return ""
}
// 链接存证模型
type LinkNotaryStorage struct {
//存证内容的链接,可以写入URL,或者其他可用于定位源文件得线索.
Link []byte `protobuf:"bytes,1,opt,name=link,proto3" json:"link,omitempty"`
//源文件得hash值,推荐使用sha256哈希,限制256位得摘要值
Hash []byte `protobuf:"bytes,2,opt,name=hash,proto3" json:"hash,omitempty"`
//自定义的主键,可以为空,如果没传,则用txhash为key
Key string `protobuf:"bytes,3,opt,name=key,proto3" json:"key,omitempty"`
//字符串值
Value string `protobuf:"bytes,4,opt,name=value,proto3" json:"value,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *LinkNotaryStorage) Reset() { *m = LinkNotaryStorage{} }
func (m *LinkNotaryStorage) String() string { return proto.CompactTextString(m) }
func (*LinkNotaryStorage) ProtoMessage() {}
func (*LinkNotaryStorage) Descriptor() ([]byte, []int) {
return fileDescriptor_0d2c4ccf1453ffdb, []int{4}
}
func (m *LinkNotaryStorage) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_LinkNotaryStorage.Unmarshal(m, b)
}
func (m *LinkNotaryStorage) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_LinkNotaryStorage.Marshal(b, m, deterministic)
}
func (m *LinkNotaryStorage) XXX_Merge(src proto.Message) {
xxx_messageInfo_LinkNotaryStorage.Merge(m, src)
}
func (m *LinkNotaryStorage) XXX_Size() int {
return xxx_messageInfo_LinkNotaryStorage.Size(m)
}
func (m *LinkNotaryStorage) XXX_DiscardUnknown() {
xxx_messageInfo_LinkNotaryStorage.DiscardUnknown(m)
}
var xxx_messageInfo_LinkNotaryStorage proto.InternalMessageInfo
func (m *LinkNotaryStorage) GetLink() []byte {
if m != nil {
return m.Link
}
return nil
}
func (m *LinkNotaryStorage) GetHash() []byte {
if m != nil {
return m.Hash
}
return nil
}
func (m *LinkNotaryStorage) GetKey() string {
if m != nil {
return m.Key
}
return ""
}
func (m *LinkNotaryStorage) GetValue() string {
if m != nil {
return m.Value
}
return ""
}
// 隐私存证模型,如果一个文件需要存证,且不公开内容,可以选择将源文件通过对称加密算法加密后上链
type EncryptNotaryStorage struct {
//存证明文内容的hash值,推荐使用sha256哈希,限制256位得摘要值
ContentHash []byte `protobuf:"bytes,1,opt,name=contentHash,proto3" json:"contentHash,omitempty"`
//源文件得密文,由加密key及nonce对明文加密得到该值。
EncryptContent []byte `protobuf:"bytes,2,opt,name=encryptContent,proto3" json:"encryptContent,omitempty"`
//加密iv,通过AES进行加密时制定随机生成的iv,解密时需要使用该值
Nonce []byte `protobuf:"bytes,3,opt,name=nonce,proto3" json:"nonce,omitempty"`
//自定义的主键,可以为空,如果没传,则用txhash为key
Key string `protobuf:"bytes,4,opt,name=key,proto3" json:"key,omitempty"`
//字符串值
Value string `protobuf:"bytes,5,opt,name=value,proto3" json:"value,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *EncryptNotaryStorage) Reset() { *m = EncryptNotaryStorage{} }
func (m *EncryptNotaryStorage) String() string { return proto.CompactTextString(m) }
func (*EncryptNotaryStorage) ProtoMessage() {}
func (*EncryptNotaryStorage) Descriptor() ([]byte, []int) {
return fileDescriptor_0d2c4ccf1453ffdb, []int{5}
}
func (m *EncryptNotaryStorage) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_EncryptNotaryStorage.Unmarshal(m, b)
}
func (m *EncryptNotaryStorage) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_EncryptNotaryStorage.Marshal(b, m, deterministic)
}
func (m *EncryptNotaryStorage) XXX_Merge(src proto.Message) {
xxx_messageInfo_EncryptNotaryStorage.Merge(m, src)
}
func (m *EncryptNotaryStorage) XXX_Size() int {
return xxx_messageInfo_EncryptNotaryStorage.Size(m)
}
func (m *EncryptNotaryStorage) XXX_DiscardUnknown() {
xxx_messageInfo_EncryptNotaryStorage.DiscardUnknown(m)
}
var xxx_messageInfo_EncryptNotaryStorage proto.InternalMessageInfo
func (m *EncryptNotaryStorage) GetContentHash() []byte {
if m != nil {
return m.ContentHash
}
return nil
}
func (m *EncryptNotaryStorage) GetEncryptContent() []byte {
if m != nil {
return m.EncryptContent
}
return nil
}
func (m *EncryptNotaryStorage) GetNonce() []byte {
if m != nil {
return m.Nonce
}
return nil
}
func (m *EncryptNotaryStorage) GetKey() string {
if m != nil {
return m.Key
}
return ""
}
func (m *EncryptNotaryStorage) GetValue() string {
if m != nil {
return m.Value
}
return ""
}
// 分享隐私存证模型,需要完备的sdk或者相应的密钥库支持
type EncryptShareNotaryStorage struct {
//存证明文内容的hash值,推荐使用sha256哈希,限制256位得摘要值
ContentHash []byte `protobuf:"bytes,1,opt,name=contentHash,proto3" json:"contentHash,omitempty"`
//源文件得密文。,用公钥地址加密
EncryptContent []byte `protobuf:"bytes,2,opt,name=encryptContent,proto3" json:"encryptContent,omitempty"`
//公钥
PubKey []byte `protobuf:"bytes,3,opt,name=pubKey,proto3" json:"pubKey,omitempty"`
//自定义的主键,可以为空,如果没传,则用txhash为key
Key string `protobuf:"bytes,4,opt,name=key,proto3" json:"key,omitempty"`
//字符串值
Value string `protobuf:"bytes,5,opt,name=value,proto3" json:"value,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *EncryptShareNotaryStorage) Reset() { *m = EncryptShareNotaryStorage{} }
func (m *EncryptShareNotaryStorage) String() string { return proto.CompactTextString(m) }
func (*EncryptShareNotaryStorage) ProtoMessage() {}
func (*EncryptShareNotaryStorage) Descriptor() ([]byte, []int) {
return fileDescriptor_0d2c4ccf1453ffdb, []int{6}
}
func (m *EncryptShareNotaryStorage) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_EncryptShareNotaryStorage.Unmarshal(m, b)
}
func (m *EncryptShareNotaryStorage) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_EncryptShareNotaryStorage.Marshal(b, m, deterministic)
}
func (m *EncryptShareNotaryStorage) XXX_Merge(src proto.Message) {
xxx_messageInfo_EncryptShareNotaryStorage.Merge(m, src)
}
func (m *EncryptShareNotaryStorage) XXX_Size() int {
return xxx_messageInfo_EncryptShareNotaryStorage.Size(m)
}
func (m *EncryptShareNotaryStorage) XXX_DiscardUnknown() {
xxx_messageInfo_EncryptShareNotaryStorage.DiscardUnknown(m)
}
var xxx_messageInfo_EncryptShareNotaryStorage proto.InternalMessageInfo
func (m *EncryptShareNotaryStorage) GetContentHash() []byte {
if m != nil {
return m.ContentHash
}
return nil
}
func (m *EncryptShareNotaryStorage) GetEncryptContent() []byte {
if m != nil {
return m.EncryptContent
}
return nil
}
func (m *EncryptShareNotaryStorage) GetPubKey() []byte {
if m != nil {
return m.PubKey
}
return nil
}
func (m *EncryptShareNotaryStorage) GetKey() string {
if m != nil {
return m.Key
}
return ""
}
func (m *EncryptShareNotaryStorage) GetValue() string {
if m != nil {
return m.Value
}
return ""
}
//根据txhash去状态数据库中查询存储内容
type QueryStorage struct {
TxHash string `protobuf:"bytes,1,opt,name=txHash,proto3" json:"txHash,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *QueryStorage) Reset() { *m = QueryStorage{} }
func (m *QueryStorage) String() string { return proto.CompactTextString(m) }
func (*QueryStorage) ProtoMessage() {}
func (*QueryStorage) Descriptor() ([]byte, []int) {
return fileDescriptor_0d2c4ccf1453ffdb, []int{7}
}
func (m *QueryStorage) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_QueryStorage.Unmarshal(m, b)
}
func (m *QueryStorage) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_QueryStorage.Marshal(b, m, deterministic)
}
func (m *QueryStorage) XXX_Merge(src proto.Message) {
xxx_messageInfo_QueryStorage.Merge(m, src)
}
func (m *QueryStorage) XXX_Size() int {
return xxx_messageInfo_QueryStorage.Size(m)
}
func (m *QueryStorage) XXX_DiscardUnknown() {
xxx_messageInfo_QueryStorage.DiscardUnknown(m)
}
var xxx_messageInfo_QueryStorage proto.InternalMessageInfo
func (m *QueryStorage) GetTxHash() string {
if m != nil {
return m.TxHash
}
return ""
}
//批量查询有可能导致数据库崩溃
type BatchQueryStorage struct {
TxHashs []string `protobuf:"bytes,1,rep,name=txHashs,proto3" json:"txHashs,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *BatchQueryStorage) Reset() { *m = BatchQueryStorage{} }
func (m *BatchQueryStorage) String() string { return proto.CompactTextString(m) }
func (*BatchQueryStorage) ProtoMessage() {}
func (*BatchQueryStorage) Descriptor() ([]byte, []int) {
return fileDescriptor_0d2c4ccf1453ffdb, []int{8}
}
func (m *BatchQueryStorage) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_BatchQueryStorage.Unmarshal(m, b)
}
func (m *BatchQueryStorage) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_BatchQueryStorage.Marshal(b, m, deterministic)
}
func (m *BatchQueryStorage) XXX_Merge(src proto.Message) {
xxx_messageInfo_BatchQueryStorage.Merge(m, src)
}
func (m *BatchQueryStorage) XXX_Size() int {
return xxx_messageInfo_BatchQueryStorage.Size(m)
}
func (m *BatchQueryStorage) XXX_DiscardUnknown() {
xxx_messageInfo_BatchQueryStorage.DiscardUnknown(m)
}
var xxx_messageInfo_BatchQueryStorage proto.InternalMessageInfo
func (m *BatchQueryStorage) GetTxHashs() []string {
if m != nil {
return m.TxHashs
}
return nil
}
type BatchReplyStorage struct {
Storages []*Storage `protobuf:"bytes,1,rep,name=storages,proto3" json:"storages,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *BatchReplyStorage) Reset() { *m = BatchReplyStorage{} }
func (m *BatchReplyStorage) String() string { return proto.CompactTextString(m) }
func (*BatchReplyStorage) ProtoMessage() {}
func (*BatchReplyStorage) Descriptor() ([]byte, []int) {
return fileDescriptor_0d2c4ccf1453ffdb, []int{9}
}
func (m *BatchReplyStorage) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_BatchReplyStorage.Unmarshal(m, b)
}
func (m *BatchReplyStorage) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_BatchReplyStorage.Marshal(b, m, deterministic)
}
func (m *BatchReplyStorage) XXX_Merge(src proto.Message) {
xxx_messageInfo_BatchReplyStorage.Merge(m, src)
}
func (m *BatchReplyStorage) XXX_Size() int {
return xxx_messageInfo_BatchReplyStorage.Size(m)
}
func (m *BatchReplyStorage) XXX_DiscardUnknown() {
xxx_messageInfo_BatchReplyStorage.DiscardUnknown(m)
}
var xxx_messageInfo_BatchReplyStorage proto.InternalMessageInfo
func (m *BatchReplyStorage) GetStorages() []*Storage {
if m != nil {
return m.Storages
}
return nil
}
type ReceiptStorage struct {
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *ReceiptStorage) Reset() { *m = ReceiptStorage{} }
func (m *ReceiptStorage) String() string { return proto.CompactTextString(m) }
func (*ReceiptStorage) ProtoMessage() {}
func (*ReceiptStorage) Descriptor() ([]byte, []int) {
return fileDescriptor_0d2c4ccf1453ffdb, []int{10}
}
func (m *ReceiptStorage) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_ReceiptStorage.Unmarshal(m, b)
}
func (m *ReceiptStorage) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_ReceiptStorage.Marshal(b, m, deterministic)
}
func (m *ReceiptStorage) XXX_Merge(src proto.Message) {
xxx_messageInfo_ReceiptStorage.Merge(m, src)
}
func (m *ReceiptStorage) XXX_Size() int {
return xxx_messageInfo_ReceiptStorage.Size(m)
}
func (m *ReceiptStorage) XXX_DiscardUnknown() {
xxx_messageInfo_ReceiptStorage.DiscardUnknown(m)
}
var xxx_messageInfo_ReceiptStorage proto.InternalMessageInfo
func init() {
proto.RegisterType((*Storage)(nil), "types.Storage")
proto.RegisterType((*StorageAction)(nil), "types.StorageAction")
proto.RegisterType((*ContentOnlyNotaryStorage)(nil), "types.ContentOnlyNotaryStorage")
proto.RegisterType((*HashOnlyNotaryStorage)(nil), "types.HashOnlyNotaryStorage")
proto.RegisterType((*LinkNotaryStorage)(nil), "types.LinkNotaryStorage")
proto.RegisterType((*EncryptNotaryStorage)(nil), "types.EncryptNotaryStorage")
proto.RegisterType((*EncryptShareNotaryStorage)(nil), "types.EncryptShareNotaryStorage")
proto.RegisterType((*QueryStorage)(nil), "types.QueryStorage")
proto.RegisterType((*BatchQueryStorage)(nil), "types.BatchQueryStorage")
proto.RegisterType((*BatchReplyStorage)(nil), "types.BatchReplyStorage")
proto.RegisterType((*ReceiptStorage)(nil), "types.ReceiptStorage")
}
func init() {
proto.RegisterFile("storage.proto", fileDescriptor_0d2c4ccf1453ffdb)
}
var fileDescriptor_0d2c4ccf1453ffdb = []byte{
// 484 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xec, 0x55, 0xc1, 0x8a, 0xd4, 0x40,
0x10, 0x35, 0xc9, 0x64, 0xc6, 0xa9, 0x64, 0xc3, 0x6e, 0xbb, 0x2e, 0x11, 0x05, 0x43, 0x0e, 0xcb,
0x20, 0x38, 0x87, 0xf5, 0x2a, 0xa8, 0x2b, 0x0b, 0x23, 0x8a, 0x62, 0xaf, 0x3f, 0x90, 0x0d, 0x8d,
0x09, 0x13, 0xba, 0x43, 0xd2, 0x23, 0xe6, 0x17, 0x3c, 0xf9, 0x05, 0xde, 0xfc, 0x4f, 0x49, 0xa7,
0xba, 0x37, 0x99, 0x64, 0xc0, 0x83, 0xe0, 0x65, 0x6f, 0x5d, 0x5d, 0xaf, 0xde, 0x7b, 0x55, 0x95,
0xd0, 0x70, 0x54, 0x4b, 0x51, 0x25, 0x5f, 0xd9, 0xba, 0xac, 0x84, 0x14, 0xc4, 0x95, 0x4d, 0xc9,
0xea, 0xf8, 0x87, 0x03, 0x8b, 0xeb, 0x2e, 0x41, 0xde, 0x41, 0x90, 0x0a, 0x2e, 0x19, 0x97, 0x78,
0x13, 0x5a, 0x91, 0xb5, 0xf2, 0x2e, 0x9e, 0xae, 0x15, 0x76, 0xfd, 0xb6, 0x4b, 0x7e, 0xe2, 0x45,
0xf3, 0x51, 0xc8, 0xa4, 0x6a, 0x10, 0xb6, 0xb9, 0x47, 0xf7, 0x0a, 0xc9, 0x6b, 0xf0, 0xb2, 0xa4,
0xce, 0x34, 0x8f, 0xad, 0x78, 0x9e, 0x20, 0xcf, 0x26, 0xa9, 0xb3, 0x29, 0x92, 0x7e, 0x09, 0x79,
0x09, 0x5e, 0x91, 0xf3, 0xad, 0x66, 0x70, 0x14, 0x43, 0x88, 0x0c, 0x1f, 0x72, 0xbe, 0x1d, 0x55,
0xf7, 0xe0, 0xe4, 0x0a, 0x02, 0xc6, 0xd3, 0xaa, 0x29, 0x4d, 0x2b, 0x33, 0x45, 0xf0, 0x18, 0x09,
0xae, 0xba, 0xe4, 0xa8, 0x8d, 0x61, 0x11, 0xf9, 0x02, 0x0f, 0xf4, 0x4d, 0x96, 0x54, 0x4c, 0x73,
0xb9, 0x8a, 0x2b, 0x1a, 0x72, 0x29, 0xc4, 0x3e, 0xe1, 0x54, 0x39, 0x09, 0xc0, 0x96, 0x4d, 0x38,
0x8f, 0xac, 0x95, 0x4b, 0x6d, 0xd9, 0x5c, 0x2e, 0xc0, 0xfd, 0x96, 0x14, 0x3b, 0x16, 0xff, 0x74,
0xe0, 0x08, 0x41, 0x6f, 0x52, 0x99, 0x0b, 0x7e, 0xb7, 0x92, 0xff, 0xbd, 0x92, 0x02, 0xc2, 0x43,
0x33, 0x26, 0x21, 0x2c, 0x70, 0xc6, 0x6a, 0x2b, 0x3e, 0xd5, 0x21, 0x39, 0x06, 0x67, 0xcb, 0x1a,
0x35, 0xe3, 0x25, 0x6d, 0x8f, 0xad, 0x80, 0x28, 0xd5, 0xc8, 0x5c, 0x6a, 0x8b, 0x92, 0x9c, 0xa2,
0x80, 0x1a, 0xc2, 0x92, 0xa2, 0xda, 0x35, 0x3c, 0x9c, 0xdc, 0x04, 0x21, 0x30, 0x6b, 0x37, 0x81,
0x3a, 0xea, 0x3c, 0x21, 0x62, 0x48, 0x9d, 0x3e, 0x69, 0x0a, 0x27, 0xa3, 0xe5, 0xb4, 0x84, 0xed,
0x72, 0x34, 0x61, 0x7b, 0x36, 0x22, 0xf6, 0x58, 0xc4, 0x99, 0x10, 0x19, 0x38, 0xff, 0x65, 0xc1,
0xe9, 0xd4, 0x06, 0x49, 0x04, 0x1e, 0x4e, 0x65, 0x73, 0xdb, 0x40, 0xff, 0x8a, 0x9c, 0x9b, 0x0f,
0x03, 0x27, 0x8d, 0x06, 0xf6, 0x6e, 0x5b, 0x61, 0x2e, 0x78, 0xda, 0x75, 0xe7, 0xd3, 0x2e, 0xd0,
0x06, 0x67, 0x13, 0x06, 0xdd, 0xbe, 0xc1, 0xdf, 0x16, 0x3c, 0x3a, 0xf8, 0x59, 0xfc, 0x43, 0x97,
0x67, 0x30, 0x2f, 0x77, 0x37, 0xef, 0x71, 0x66, 0x3e, 0xc5, 0xe8, 0xaf, 0x7d, 0x9e, 0x83, 0xff,
0x79, 0xc7, 0x6e, 0x9d, 0x9d, 0xc1, 0x5c, 0x7e, 0x37, 0xa6, 0x96, 0x14, 0xa3, 0xf8, 0x39, 0x9c,
0x5c, 0x26, 0x32, 0xcd, 0x06, 0xe0, 0x10, 0x16, 0x5d, 0xba, 0x0e, 0xad, 0xc8, 0x59, 0x2d, 0xa9,
0x0e, 0xe3, 0x57, 0x08, 0xa7, 0xac, 0x2c, 0x0c, 0xfc, 0x19, 0xdc, 0xc7, 0x47, 0xa1, 0xc3, 0x7b,
0x17, 0x01, 0xfe, 0x40, 0x88, 0xa0, 0x26, 0x1f, 0x1f, 0x43, 0x40, 0x59, 0xca, 0x72, 0xf3, 0x27,
0xde, 0xcc, 0xd5, 0x43, 0xf2, 0xe2, 0x4f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x50, 0x57, 0xda, 0x93,
0x59, 0x06, 0x00, 0x00,
}
package types
import (
"encoding/hex"
secp256k1 "github.com/btcsuite/btcd/btcec"
"github.com/golang/protobuf/proto"
)
//exec type
const (
ExecErr = 0
ExecPack = 1
ExecOk = 2
)
//FromHex hex -> []byte
func FromHex(s string) ([]byte, error) {
if len(s) > 1 {
if s[0:2] == "0x" || s[0:2] == "0X" {
s = s[2:]
}
if len(s)%2 == 1 {
s = "0" + s
}
return hex.DecodeString(s)
}
return []byte{}, nil
}
//ToHex []byte -> hex
func ToHex(b []byte) string {
hex := hex.EncodeToString(b)
// Prefer output of "0x0" instead of "0x"
if len(hex) == 0 {
return ""
}
return hex
}
//ToHex []byte -> hex
func ToHexPrefix(b []byte) string {
hex := hex.EncodeToString(b)
// Prefer output of "0x0" instead of "0x"
if len(hex) == 0 {
return ""
}
return "0x" + hex
}
//Encode 编码
func Encode(data proto.Message) []byte {
b, err := proto.Marshal(data)
if err != nil {
panic(err)
}
return b
}
//Decode 解码
func Decode(data []byte, msg proto.Message) error {
return proto.Unmarshal(data, msg)
}
// ECDH Calculate a shared secret using elliptic curve Diffie-Hellman
func ECDH(priv *secp256k1.PrivateKey, pub *secp256k1.PublicKey) []byte {
ecKey := &secp256k1.PublicKey{}
ecKey.X, ecKey.Y = secp256k1.S256().ScalarMult(pub.X, pub.Y, priv.D.Bytes())
return ecKey.SerializeCompressed()
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment