How to retrieve user information from recent version of Hyperledger Fabric? -
i'm new hyperledger fabric. in current version of hyperledger fabric, in chaincode.go can't find function called readcertattributes. there way attributes?
starting hypeledger fabric 1.0.0 can use getcreator
method of chaincodestubinterface
obtain clients certificate, e.g.:
// getcreator returns `signatureheader.creator` (e.g. identity) // of `signedproposal`. identity of agent (or user) // submitting transaction. getcreator() ([]byte, error)
for example can similar to:
func (*smartcontract) invoke(stub shim.chaincodestubinterface) peer.response { fmt.println("invoke") // getcreator returns marshaled serialized identity of client serializedid, _ := stub.getcreator() sid := &msp.serializedidentity{} err := proto.unmarshal(serializedid, sid) if err != nil { return shim.error(fmt.sprintf("could not deserialize serializedidentity, err %s", err)) } bl, _ := pem.decode(sid.idbytes) if bl == nil { return shim.error(fmt.sprintf("failed decode pem structure")) } cert, err := x509.parsecertificate(bl.bytes) if err != nil { return shim.error(fmt.sprintf("unable parse certificate %s", err)) } // whatever need certificate return shim.success(nil) }
Comments
Post a Comment