Commit 7b805e0c authored by 袁邓@五瓣科技's avatar 袁邓@五瓣科技

修改userID和订单签名延签

parent e89c3116
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JavaScriptSettings">
<option name="languageLevel" value="ES6" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/test.iml" filepath="$PROJECT_DIR$/.idea/test.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
This diff is collapsed.
...@@ -167,7 +167,10 @@ type dsaSignature struct { ...@@ -167,7 +167,10 @@ type dsaSignature struct {
R, S *big.Int R, S *big.Int
} }
type PubSerialize struct {
PubSerialize []byte `json:"pub_serialize"`
PubType crypto.Hash `json:"pub_type"`
}
type PrivateKeySerialize struct { type PrivateKeySerialize struct {
PrivSerialize []byte `json:"priv_serialize"` //私钥序列化的数据 PrivSerialize []byte `json:"priv_serialize"` //私钥序列化的数据
PrivType crypto.Hash`json:"priv_type"` PrivType crypto.Hash`json:"priv_type"`
...@@ -508,4 +511,20 @@ func ReadBits(bigint *big.Int, buf []byte) { ...@@ -508,4 +511,20 @@ func ReadBits(bigint *big.Int, buf []byte) {
//func MarshalPublicKey(curve elliptic.Curve,x,y *big.Int ){ //func MarshalPublicKey(curve elliptic.Curve,x,y *big.Int ){
// //
//} //}
\ No newline at end of file
func ParsePublicKey(pubHex string)(pub interface{},hashType crypto.Hash,err error){
pubByte,err := hex.DecodeString(pubHex)
if err!=nil{
return nil,crypto.Hash(0),err
}
pubS :=&PubSerialize{}
err = json.Unmarshal(pubByte,pubS)
if err!=nil{
return nil,crypto.Hash(0),fmt.Errorf("pubByte Unmarshal error "+err.Error())
}
hashType = pubS.PubType
fmt.Println("namedCurveFromHash(hashType)",namedCurveFromHash(hashType))
pub,err = unmarshalPubkey(pubS.PubSerialize,namedCurveFromHash(hashType))
return
}
\ No newline at end of file
...@@ -268,7 +268,7 @@ func CheckCertSignature( message *Message,txType TxType,stub shim.ChaincodeStubI ...@@ -268,7 +268,7 @@ func CheckCertSignature( message *Message,txType TxType,stub shim.ChaincodeStubI
cert := &Certificate{} cert := &Certificate{}
switch txType { switch txType {
case CreateCoupon: case CreateCoupon:
cert ,err = getCert(message.UserId,0,stub) cert ,err = getCert(message.OwnId,0,stub)
if err != nil{ if err != nil{
return return
} }
...@@ -277,7 +277,7 @@ func CheckCertSignature( message *Message,txType TxType,stub shim.ChaincodeStubI ...@@ -277,7 +277,7 @@ func CheckCertSignature( message *Message,txType TxType,stub shim.ChaincodeStubI
return "",errors.New("only organization account can create coupon") return "",errors.New("only organization account can create coupon")
} }
case DisCoupon: case DisCoupon:
cert ,err = getCert(message.UserId,0,stub) cert ,err = getCert(message.OwnId,0,stub)
if err != nil{ if err != nil{
return return
} }
...@@ -286,7 +286,7 @@ func CheckCertSignature( message *Message,txType TxType,stub shim.ChaincodeStubI ...@@ -286,7 +286,7 @@ func CheckCertSignature( message *Message,txType TxType,stub shim.ChaincodeStubI
return "",errors.New("only organization account can distribute coupon") return "",errors.New("only organization account can distribute coupon")
} }
case ApplyCoupon: case ApplyCoupon:
cert ,err = getCert(message.UserId,1,stub) cert ,err = getCert(message.OwnId,1,stub)
if err != nil{ if err != nil{
return return
} }
...@@ -295,7 +295,7 @@ func CheckCertSignature( message *Message,txType TxType,stub shim.ChaincodeStubI ...@@ -295,7 +295,7 @@ func CheckCertSignature( message *Message,txType TxType,stub shim.ChaincodeStubI
return "",errors.New("only channel account can create apply coupon transaction") return "",errors.New("only channel account can create apply coupon transaction")
} }
case UseCoupon: case UseCoupon:
cert ,err = getCert(message.UserId,2,stub) cert ,err = getCert(message.OwnId,2,stub)
if err != nil{ if err != nil{
return return
} }
......
...@@ -20,27 +20,6 @@ var merchantPublicKey = "041922e1019b52daa86246b1a330efc2e7308f9019000bda3103bd8 ...@@ -20,27 +20,6 @@ var merchantPublicKey = "041922e1019b52daa86246b1a330efc2e7308f9019000bda3103bd8
var merchantPrivateKey = "7b22707269765f73657269616c697a65223a226e68724c34536c454d6b7431356c2b385651576b466d6d724c516333674b364a62527565757a39594451413d222c22707269765f74797065223a32317d" var merchantPrivateKey = "7b22707269765f73657269616c697a65223a226e68724c34536c454d6b7431356c2b385651576b466d6d724c516333674b364a62527565757a39594451413d222c22707269765f74797065223a32317d"
var merchantCert = `{"public_key_hash_algorithm":21,"public_key_byte":"BBki4QGbUtqoYkaxozDvwucwj5AZAAvaMQO9hjoFd2/z1tJ0s2h3i7v8z8sHF52uOa5Vy3mro9oU7NuyC7kjm/c=","publickey":null,"cert_type":3,"extensions":100,"not_before":1590482496,"not_after":1587890496,"cert_hash":"C/L+z0ZZPnbPX8mkab88feMYNlSPRx9s5Xsitls7zoU=","signature":"5o/BpTdBedJea7w/yYpIjuj1OJa/g5hh5c2oAYDN0pmOQlHw/nftJTERMpl8GqwU3sEXh5My3tFmuI6WbLyuXA==","signature_algorithm":16}` var merchantCert = `{"public_key_hash_algorithm":21,"public_key_byte":"BBki4QGbUtqoYkaxozDvwucwj5AZAAvaMQO9hjoFd2/z1tJ0s2h3i7v8z8sHF52uOa5Vy3mro9oU7NuyC7kjm/c=","publickey":null,"cert_type":3,"extensions":100,"not_before":1590482496,"not_after":1587890496,"cert_hash":"C/L+z0ZZPnbPX8mkab88feMYNlSPRx9s5Xsitls7zoU=","signature":"5o/BpTdBedJea7w/yYpIjuj1OJa/g5hh5c2oAYDN0pmOQlHw/nftJTERMpl8GqwU3sEXh5My3tFmuI6WbLyuXA==","signature_algorithm":16}`
//var createCouponsData = `{"expand": {"coup_id": "0001","coup_type": "XJQ","coup_valid": "2017-01-13 23:59:59","coup_available_time": "券可用时间段","coup_description": "券使用说明","coup_quantity": 1000000,"coup_amount": 10.00,"coup_total_amount": 10000000,"floor_amount": 10.00},"to":"org123"}`
//var createCouponsData = `{"value":"{\"coup_id\":\"0001\",\"coup_type\":\"XJQ\",\"coup_valid\":\"2017-01-13 23:59:59\",\"coup_available_time\":\"券可用时间段\",\"coup_description\":\"券描述\",\"coup_quantity\":1000000,\"coup_amount\":10,\"coup_discount\":0.5,\"coup_total_amount\":10000000,\"floor_amount\":10,\"extensions\":null}","fromAddress":"","toAddress":"org123","toPublicKey":""}`
var createCouponsData = `{"value": "{\"uAddress\":\"wwe=rrrrr\",\"mid\":\"0001\"}"}`
var createCouponsDataSign =[]byte{207 ,240, 50, 5, 177, 135, 76 ,137, 236 ,206, 203, 228, 77, 16 ,230, 64 ,57 ,97, 237, 151, 184, 122, 214, 119 ,20, 51, 130 ,35 ,49 ,218, 32, 17, 121 ,70 ,57 ,241 ,163, 172, 191, 6 ,126, 40 ,98, 228, 197, 88 ,44 ,79 ,253 ,13, 245, 85, 129 ,204 ,254, 196 ,26 ,60, 114 ,120, 65, 172, 95 ,200}
var disCouponsData =`{"from":"org123","to":"channel123","to_pub":"04aa7cf4f0950be19033848ab8956160f2ecb461e7034d4d2e95990f233c2166de4969eec6e69988d5cfbcf3461a2a5a53dd131bfab343dcefdc24a466d0faf09e","value":10000}`
var disCouponsDataSign =[]byte{115, 165, 9 ,100, 154 ,56 ,79 ,35 ,146, 86 ,229 ,88 ,160, 82 ,228, 62 ,242 ,32 ,244 ,183, 221 ,174, 172, 186 ,53 ,200, 168, 250, 230, 21, 90, 92 ,128 ,103 ,117 ,234, 168, 145 ,224, 178, 202, 9 ,206, 121, 0 ,139 ,38 ,78, 247, 161, 147 ,60 ,20, 115 ,131, 14, 161, 110, 232, 102, 37, 109, 167, 179}
var applyCouponsData =` {"from":"channel123","to":"user123","to_pub":"123456789"}`
var applyCouponsDataSign =[]byte{154,81,233,239,237,59,16,126,169,142,112,144,255,5,43,22,101,250,208,159,199,203,100,221,24,156,14,194,149,173,47,97,113,75,80,106,37,154,220,231,181,60,150,182,109,53,175,158,175,138,93,165,161,127,39,110,85,119,8,236,143,96,16,160}
var useCouponsData =` {"expand":"订单信息","from":"user123","to":"mert123","to_pub":"123456789"}`
var useCouponsDataSign =[]byte{146,15,96,112,62,182,206,85,28,253,120,129,194,242,121,150,74,147,144,171,164,196,54,187,76,79,69,228,236,208,5,194,112,184,191,20,74,120,48,39,161,14,44,160,238,52,13,1,172,8,155,132,43,145,157,245,253,52,74,48,14,164,10,50}
var getCouponsData = `{"expand": {"coup_id": "0001"}}`
var getCouponsByAddress = `{"from":"mert123"}`
var subsidiesData = `{"to_pub":"048014f3e260f1e202259c0e0dcf9a70478c8d8e808ec91f27af1320c31c4e9183b7a12813a4a524b07b0fa83850babff2194f18e7eed38cd639f3eb6c86b61d50"}`
func TestCreateCoupons(t *testing.T) { func TestCreateCoupons(t *testing.T) {
cc := new(CPSChainCode) cc := new(CPSChainCode)
...@@ -67,11 +46,11 @@ func TestCreateCoupons(t *testing.T) { ...@@ -67,11 +46,11 @@ func TestCreateCoupons(t *testing.T) {
//fmt.Printf("Invoke status %d,message %s and payload %s\n",responseByPutschema.Status,responseByPutschema.Message,string(responseByPutschema.Payload)) //fmt.Printf("Invoke status %d,message %s and payload %s\n",responseByPutschema.Status,responseByPutschema.Message,string(responseByPutschema.Payload))
fmt.Println("========================================invoke createTx createCoupons============================================") //fmt.Println("========================================invoke createTx createCoupons============================================")
fmt.Println() //fmt.Println()
fmt.Println() //fmt.Println()
responseByPutschema := stub.MockInvoke("invoke1",[][]byte{[]byte("createTx/updateMertUtxo"), []byte(orgPublicKey),[]byte(createCouponsData),[]byte(createCouponsDataSign)}) //responseByPutschema := stub.MockInvoke("invoke1",[][]byte{[]byte("createTx/updateMertUtxo"), []byte(orgPublicKey),[]byte(createCouponsData),[]byte(createCouponsDataSign)})
fmt.Printf("Invoke status %d,message %s and payload %s\n",responseByPutschema.Status,responseByPutschema.Message,string(responseByPutschema.Payload)) //fmt.Printf("Invoke status %d,message %s and payload %s\n",responseByPutschema.Status,responseByPutschema.Message,string(responseByPutschema.Payload))
//fmt.Println("========================================invoke createTx disCoupon============================================") //fmt.Println("========================================invoke createTx disCoupon============================================")
...@@ -241,7 +220,7 @@ func TestCreateTx(t *testing.T){ ...@@ -241,7 +220,7 @@ func TestCreateTx(t *testing.T){
fmt.Println(hex.EncodeToString(txByte)) fmt.Println(hex.EncodeToString(txByte))
fmt.Println(string(txByte)) fmt.Println(string(txByte))
message := &Message{ message := &Message{
UserId:"1", OwnId:"1",
Data:string(txByte), Data:string(txByte),
Sign:"c384f2bc27a9abc87b07ce798fd4a65323aab9ddbd4aee8b379c1a987e6cf272b9becc5fb4bcd2f3d8495fe715ed4c263c6b4c5ce68067d39922df12fd075fc9", Sign:"c384f2bc27a9abc87b07ce798fd4a65323aab9ddbd4aee8b379c1a987e6cf272b9becc5fb4bcd2f3d8495fe715ed4c263c6b4c5ce68067d39922df12fd075fc9",
} }
...@@ -261,9 +240,8 @@ var disCouponsDate = `{"value":"{\"amount\":99,\"did\":\"11\"}","fromAddress":"u ...@@ -261,9 +240,8 @@ var disCouponsDate = `{"value":"{\"amount\":99,\"did\":\"11\"}","fromAddress":"u
var ApplyCouponsSign = `7092dde322c376f5d43541f219ffe3234b8cea365a7e5aa49983865a36516e2c0e7b875cc5750e61b6a1bf3d22e0f004ae42d73aaad655fe972047b70ff91246` var ApplyCouponsSign = `7092dde322c376f5d43541f219ffe3234b8cea365a7e5aa49983865a36516e2c0e7b875cc5750e61b6a1bf3d22e0f004ae42d73aaad655fe972047b70ff91246`
var ApplyCouponsDate = `{"value":"{\"uid\":\"\",\"name\":\"\",\"number\":\"\",\"phone\":\"\",\"create_time\":\"0001-01-01T00:00:00Z\"}","fromAddress":"utxo2","toAddress":"utxo3","toPublicKey":"04e6496ec8db3af69f1efbe12dc6e6c28402d2ff928e69160040cd4e293402d224785cf12912635306a65dc08f2dc840daa71cc30049fb77d3a95480f09d011c7d"}` var ApplyCouponsDate = `{"value":"{\"uid\":\"\",\"name\":\"\",\"number\":\"\",\"phone\":\"\",\"create_time\":\"0001-01-01T00:00:00Z\"}","fromAddress":"utxo2","toAddress":"utxo3","toPublicKey":"04e6496ec8db3af69f1efbe12dc6e6c28402d2ff928e69160040cd4e293402d224785cf12912635306a65dc08f2dc840daa71cc30049fb77d3a95480f09d011c7d"}`
var useCouponsSign = `a0a253661923245cdc2eef15ab665d96fd7383608587a652baa68303687f1b6e5fb86fe2bda2b94b68e9bf5478793154c7420c3688d61996c95d87d43a49649b` var useCouponsSign = `2eb8f81b19a2e4c14d15c1736f8c9ea764e707ddb14a16c8a373e38e3000de3b7e62c56eac42241bdc739ad4ca52fc7d13c97a597e5c7e5993a845cc75a9f22d`
var useCouponsDate = `{"value":"{\"privHex\":\"7b22707269765f73657269616c697a65223a223453384363544476374a4862767867747076516969653961506a784e756c316b46324431496850765574553d222c22707269765f74797065223a32317d\"}","fromAddress":"utxo3","toAddress":"utxo4","toPublicKey":"04e6496ec8db3af69f1efbe12dc6e6c28402d2ff928e69160040cd4e293402d224785cf12912635306a65dc08f2dc840daa71cc30049fb77d3a95480f09d011c7d"}` var useCouponsDate = `{"value":"{\"orderSign\":\"eb12fd1922cdb15b8be9c43a685f342c455c8a44f9972d0c83761a760554f3cdee6e127378d1d3953aeed678e04d55d059be5f6ca65cb864310891626daf1336\",\"order\":\"订单信息\",\"algorithm\":1}","fromAddress":"utxo3","toAddress":"utxo4"}`
func TestCouponsFlow(t *testing.T){ func TestCouponsFlow(t *testing.T){
cc := new(CPSChainCode) cc := new(CPSChainCode)
......
...@@ -93,7 +93,7 @@ type Orgnazation struct { ...@@ -93,7 +93,7 @@ type Orgnazation struct {
} }
// 前端传递的数据 // 前端传递的数据
type Message struct { type Message struct {
UserId string `json:"user_id"` // 交易发起人的用户Id OwnId string `json:"own_id"` // 交易发起人的用户Id
Data string `json:"data"` // 交易参数 Data string `json:"data"` // 交易参数
Sign string `json:"sign"` // 交易签名信息,if是商户交易,这里是券公钥 Sign string `json:"sign"` // 交易签名信息,if是商户交易,这里是券公钥
} }
......
...@@ -6,6 +6,7 @@ import ( ...@@ -6,6 +6,7 @@ import (
pb "github.com/hyperledger/fabric/protos/peer" pb "github.com/hyperledger/fabric/protos/peer"
"encoding/json" "encoding/json"
"strings" "strings"
"encoding/hex"
) )
func transactionProcess(paths, args []string, stub shim.ChaincodeStubInterface) pb.Response { func transactionProcess(paths, args []string, stub shim.ChaincodeStubInterface) pb.Response {
...@@ -60,7 +61,7 @@ func createCouponsApi(args []string, stub shim.ChaincodeStubInterface) pb.Respon ...@@ -60,7 +61,7 @@ func createCouponsApi(args []string, stub shim.ChaincodeStubInterface) pb.Respon
//创建UTXO资产 //创建UTXO资产
utxo := &Utxo{ utxo := &Utxo{
Address: trans.To, Address: trans.To,
UserId: message.UserId, UserId: message.OwnId,
Status: "0", Status: "0",
CoupType: coupon.CoupType, CoupType: coupon.CoupType,
CoupQuantity: coupon.CoupQuantity, CoupQuantity: coupon.CoupQuantity,
...@@ -116,8 +117,8 @@ func disCouponApi(args []string, stub shim.ChaincodeStubInterface) pb.Response { ...@@ -116,8 +117,8 @@ func disCouponApi(args []string, stub shim.ChaincodeStubInterface) pb.Response {
if boo { if boo {
return shim.Error("Coupon distribution failed, utxo address already exists") return shim.Error("Coupon distribution failed, utxo address already exists")
} }
if orgUtxo.UserId != message.UserId { if orgUtxo.UserId != message.OwnId {
return shim.Error("UserId alignment error") return shim.Error("OwnId alignment error")
} }
if orgUtxo.Status != "0" { if orgUtxo.Status != "0" {
return shim.Error("Card coupon status is abnormal and cannot be dis") return shim.Error("Card coupon status is abnormal and cannot be dis")
...@@ -190,8 +191,8 @@ func userApplyCouponApi(args []string, stub shim.ChaincodeStubInterface) pb.Resp ...@@ -190,8 +191,8 @@ func userApplyCouponApi(args []string, stub shim.ChaincodeStubInterface) pb.Resp
if dictUtxo.Status != "1" { if dictUtxo.Status != "1" {
return shim.Error("Card coupon status is abnormal and cannot be apply") return shim.Error("Card coupon status is abnormal and cannot be apply")
} }
if dictUtxo.UserId != message.UserId { if dictUtxo.UserId != message.OwnId {
return shim.Error("UserId alignment error") return shim.Error("OwnId alignment error")
} }
if dictUtxo.CoupQuantity < 1 { if dictUtxo.CoupQuantity < 1 {
return shim.Error("Drawing failure, insufficient margin") return shim.Error("Drawing failure, insufficient margin")
...@@ -229,7 +230,6 @@ func useCouponApi(args []string, stub shim.ChaincodeStubInterface) pb.Response { ...@@ -229,7 +230,6 @@ func useCouponApi(args []string, stub shim.ChaincodeStubInterface) pb.Response {
if err != nil { if err != nil {
return shim.Error(err.Error()) return shim.Error(err.Error())
} }
utxo, err := getStateUtxo(KEY+trans.From, stub) utxo, err := getStateUtxo(KEY+trans.From, stub)
if err != nil { if err != nil {
return shim.Error(err.Error()) return shim.Error(err.Error())
...@@ -238,12 +238,12 @@ func useCouponApi(args []string, stub shim.ChaincodeStubInterface) pb.Response { ...@@ -238,12 +238,12 @@ func useCouponApi(args []string, stub shim.ChaincodeStubInterface) pb.Response {
return shim.Error("Card coupon status is abnormal and cannot be used") return shim.Error("Card coupon status is abnormal and cannot be used")
} }
//TODO 解析订单信息,校验券使用条件是否满足.待定。 //TODO 解析订单信息,校验券使用条件是否满足.待定。
isSupport,err := isSupportMerchants(utxo.CoupId,message.UserId,stub) isSupport,err := isSupportMerchants(utxo.CoupId,message.OwnId,stub)
if err != nil{ if err != nil{
return shim.Error(err.Error()) return shim.Error(err.Error())
} }
if !isSupport { if !isSupport {
shim.Error(fmt.Sprintf("coupon %s unsupport merchant %s use",utxo.CoupId,message.UserId)) shim.Error(fmt.Sprintf("coupon %s unsupport merchant %s use",utxo.CoupId,message.OwnId))
} }
expand, ok := trans.Value.(string) //判断类型 expand, ok := trans.Value.(string) //判断类型
if !ok { if !ok {
...@@ -254,16 +254,23 @@ func useCouponApi(args []string, stub shim.ChaincodeStubInterface) pb.Response { ...@@ -254,16 +254,23 @@ func useCouponApi(args []string, stub shim.ChaincodeStubInterface) pb.Response {
if err != nil{ if err != nil{
fmt.Println(err) fmt.Println(err)
} }
//拿到订单信息 order,orderSign,also,err :=parseArgsToOrderInfo(dat)
order, ok := dat["order"].(string) if err != nil {
//订单签名信息 return shim.Error(err.Error())
orderSign, ok := dat["orderSign"].(string) }
if !ok { pub,_,err :=ParsePublicKey(utxo.PublicKey)
return shim.Error("Error orderSign parameter type,must be string") if err != nil {
return shim.Error("PublicKey ParsePublicKey error,"+err.Error())
}
signature,err := hex.DecodeString(orderSign)
if err != nil{
return shim.Error("orderSign DecodeString error,"+err.Error())
} }
//TODO 验证订单签名信息 //TODO 验证订单签名信息
fmt.Println(order) err = checkSignature(also,[]byte(order),[]byte(signature),pub)
fmt.Println(orderSign) if err != nil {
return shim.Error(err.Error())
}
//_,pubKey,err := ParsePrivateKey(privHex) //_,pubKey,err := ParsePrivateKey(privHex)
//pubHex := hex.EncodeToString(pubKey) //pubHex := hex.EncodeToString(pubKey)
//if utxo.PublicKey != pubHex { //if utxo.PublicKey != pubHex {
...@@ -276,7 +283,7 @@ func useCouponApi(args []string, stub shim.ChaincodeStubInterface) pb.Response { ...@@ -276,7 +283,7 @@ func useCouponApi(args []string, stub shim.ChaincodeStubInterface) pb.Response {
if mertByteUtxo == nil { if mertByteUtxo == nil {
mertNewUtxo = Utxo{ mertNewUtxo = Utxo{
Address: trans.To, Address: trans.To,
UserId: message.UserId , UserId: message.OwnId ,
Status: "4", Status: "4",
CoupType: utxo.CoupType, CoupType: utxo.CoupType,
CoupQuantity: utxo.CoupQuantity, CoupQuantity: utxo.CoupQuantity,
......
...@@ -5,6 +5,7 @@ import ( ...@@ -5,6 +5,7 @@ import (
"fmt" "fmt"
"encoding/json" "encoding/json"
"github.com/hyperledger/fabric/core/chaincode/shim" "github.com/hyperledger/fabric/core/chaincode/shim"
"strconv"
) )
func splitPath(key string) []string { func splitPath(key string) []string {
...@@ -21,11 +22,11 @@ func messageToTrans(operation TxType,args []string,stub shim.ChaincodeStubInterf ...@@ -21,11 +22,11 @@ func messageToTrans(operation TxType,args []string,stub shim.ChaincodeStubInterf
return nil,nil, "",fmt.Errorf("put data operation expected more than 3 parameters! ") return nil,nil, "",fmt.Errorf("put data operation expected more than 3 parameters! ")
} }
message := &Message{ message := &Message{
UserId: args[0], OwnId: args[0],
Data: args[1], Data: args[1],
Sign: args[2], Sign: args[2],
} }
if message.UserId == "" || message.Sign == "" || message.Data == "" { if message.OwnId == "" || message.Sign == "" || message.Data == "" {
return nil,nil,"" ,fmt.Errorf("Parameter exception, cannot be null!") return nil,nil,"" ,fmt.Errorf("Parameter exception, cannot be null!")
} }
//验证证书和签名 //验证证书和签名
...@@ -42,3 +43,37 @@ func messageToTrans(operation TxType,args []string,stub shim.ChaincodeStubInterf ...@@ -42,3 +43,37 @@ func messageToTrans(operation TxType,args []string,stub shim.ChaincodeStubInterf
return &trans,message,pubKey , nil return &trans,message,pubKey , nil
} }
func parseArgsToOrderInfo(dat map[string]interface{}) (string,string,SignatureAlgorithm,error) {
//拿到订单信息
order, ok := dat["order"].(string)
if !ok {
return "","",-1,fmt.Errorf("Error order parameter type,must be string")
}
//订单签名信息
orderSign, ok := dat["orderSign"].(string)
if !ok {
return "","",-1,fmt.Errorf("Error orderSign parameter type,must be string")
}
//拿到订单信息
algorithm, ok := dat["algorithm"].(float64)
if !ok {
return "","",-1,fmt.Errorf("Error algorithm parameter type,must be int")
}
var algo SignatureAlgorithm
switch algorithm {
case 1:
algo = SM2WithSM3
case 2:
algo = ECDSAWithSHA256
}
return order,orderSign,algo,nil
}
func hexStringToBytes(s string) []byte {
bs := make([]byte, 0)
for i := 0; i < len(s); i = i + 2 {
b, _ := strconv.ParseInt(s[i:i+2], 16, 16)
bs = append(bs, byte(b))
}
return bs
}
\ 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