I have a problem storing a generated ecdsa Private Key in the database of Hyperledger Fabric.
What I am doing is using the ecdsa.GenerateKey(elliptic.P224(), rand.Reader) function that ecdsa provides and trying to store that key in the ledger with the PutState() function of shim. The type of variable that is in struct is ecdsa.PrivateKey but when I try that the chaincode seems to stop and get the following error:
Error: could not assemble transaction: ProposalResponsePayloads do not match - proposal response: version:1 response:
Of course this indicates that the chaincode is not installed in both Organization peers. But I have. Then I tried to convert the ecdsa.PrivateKey into bytes and then to string but nothing seems to work. I will attach the code bellow.
type UserDetails struct {
ObjectType string `json:"docType"`
FirstName string `json:"firstName"`
LastName string `json:"lastName"`
PublicKey ecdsa.PublicKey `json:"publicKey"`
PrivateKey []byte `json:"privateKey"`
}
This above is my structure
priv, err := ecdsa.GenerateKey(elliptic.P224(), rand.Reader)
if err != nil {
fmt.Println(err)
}
enc_key := priv.D.Bytes()
fmt.Println(enc_key)
bytesPrivK := string(enc_key)
objectType := "userDetails"
userDetailsReg := &UserDetails{objectType, firstName, lastName, *ecdsaPublicKey, enc_key}
userDetailsJSONasBytes, err := json.Marshal(userDetailsReg)
if err != nil {
return shim.Error(err.Error())
}
fmt.Println(userDetailsReg)
// === Save userDetails to state ===
err = stub.PutState(lastName, userDetailsJSONasBytes)
if err != nil {
return shim.Error(err.Error())
}
I also tried with the ecies package to generate an ecies private key then convert it to ecdsa and store it but still same error. I used ecies cause I need to encrypt message with the ecies encryption.
prv, err := ecies.GenerateKey(rand.Reader, ecies.DefaultCurve, nil)
if err != nil {
fmt.Println(err.Error())
}
eciesPrivatePem, err1 := ecies.MarshalPrivate(prv)
if err1 != nil {
fmt.Println(err1)
}
encodedToStr := string(eciesPrivatePem)
ecdsaPrivate := prv.ExportECDSA()
Here I tried either to store in an ecies.PrivateKey type or in string or even ecdsa.PrivateKey but always getting the same error.
I am using the Hyperledger Fabric and CouchDB for this. Does anyone know why I cant store that even as a string? It seems really strange that even as a string a cant store it although the other 2 variables are strings and 1 ecdsa.PublicKey types. I cant find any other error in logs that indicates something more here.
Any help or recommendation would be appreciated.
Thank you