i run this function in chaincode under hyperledger fabric:
func (c *SmartContract) InitiateUser(ctx contractapi.TransactionContextInterface, userID string) error {
// Generate a new ECC key pair
curve := elliptic.P256() // Use P-256 curve
privateKey, err := ecdsa.GenerateKey(curve, rand.Reader)
if err != nil {
return fmt.Errorf("failed to generate private key: %v", err)
}
// Hash the public and private keys using SHA-256
publicKeyHash := sha256.Sum256(elliptic.MarshalCompressed(curve, privateKey.PublicKey.X, privateKey.PublicKey.Y))
privateKeyHash := sha256.Sum256(privateKey.D.Bytes())
// Create a new User object from the input arguments and the ECC key pair
user := &User{
ID: userID,
PublicKey: hex.EncodeToString(publicKeyHash[:]),
PrivateKey: hex.EncodeToString(privateKeyHash[:]),
}
// Convert the User object to a JSON-encoded byte array
userBytes, err := json.Marshal(user)
if err != nil {
return fmt.Errorf("failed to marshal user data to JSON: %v", err)
}
// Store the JSON-encoded byte array in the ledger using PutState
err = ctx.GetStub().PutState(userID, userBytes)
if err != nil {
return fmt.Errorf("failed to put user data on the ledger: %v", err)
}
// Return a success response with the user data
return nil
}
As result a get this error:
Error: could not assemble transaction: ProposalResponsePayloads do not match (base64): 'CiD6XpjbMfvrXmPkeykGv7m1q8cRn02P8hBq3yi+yuNIBxKUAwr/AhI3CgpfbGlmZWN5Y2xlEikKJwohbmFtZXNwYWNlcy9maWVsZHMvZmFiY2FyL1NlcXVlbmNlEgIIBxLDAgoGZmFiY2FyErgCChYKEAD0j7+/aW5pdGlhbGl6ZWQSAggIGp0CCjF7ImlkIjoiMSIsInB1YmxpY19rZXkiOiJBdWRpIiwicHJpdmF0ZV9rZXkiOiJSOCJ9GucBeyJpZCI6IntcImlkXCI6XCIxXCIsXCJwdWJsaWNfa2V5XCI6XCJBdWRpXCIsXCJwcml2YXRlX2tleVwiOlwiUjhcIn0iLCJwdWJsaWNfa2V5IjoiZmE1MTI4Mjc5ZTVjMmY5Zjg2N2M0ZmZiMWI3MTJjNTlhZGFjMWE4M2ZjMGQ3NDA0OTI0MDY2MWY3NDE3YTk2YSIsInByaXZhdGVfa2V5IjoiMjk1M2Q2YzAzNDIzZWYxZTg5ODI3MmM5ZDZhZDNmYWFlZjcxMDM5MmMzOWM3OTZlYjg5OWRkMmMyNmM4ZGJkNiJ9GgMIyAEiCxIGZmFiY2FyGgEx' vs 'CiD6XpjbMfvrXmPkeykGv7m1q8cRn02P8hBq3yi+yuNIBxKUAwr/AhI3CgpfbGlmZWN5Y2xlEikKJwohbmFtZXNwYWNlcy9maWVsZHMvZmFiY2FyL1NlcXVlbmNlEgIIBxLDAgoGZmFiY2FyErgCChYKEAD0j7+/aW5pdGlhbGl6ZWQSAggIGp0CCjF7ImlkIjoiMSIsInB1YmxpY19rZXkiOiJBdWRpIiwicHJpdmF0ZV9rZXkiOiJSOCJ9GucBeyJpZCI6IntcImlkXCI6XCIxXCIsXCJwdWJsaWNfa2V5XCI6XCJBdWRpXCIsXCJwcml2YXRlX2tleVwiOlwiUjhcIn0iLCJwdWJsaWNfa2V5IjoiMzA5ZjI0Mjg5YmI0ZWJkZGRmZGNmZWVmYTMzYjFiYzU4ZWRlMzAyNTY1NWM5MzU1ZmEwMjBhMTcxNjQxYzEwNSIsInByaXZhdGVfa2V5IjoiZWFjZWVlODMwNWRkOTRjODI0MWFhZDQwNzZiMTViNzdjYWUyYTU4ZWI0OGJhZDYyMGY3MWQyZjY3MDFmMzI3MSJ9GgMIyAEiCxIGZmFiY2FyGgEx' - proposal response: version:1 response:<status:200 > payload:"\n \372^\230\3331\373\353^c\344{)\006\277\271\265\253\307\021\237M\217\362\020j\337(\276\312\343H\007\022\224\003\n\377\002\0227\n\n_lifecycle\022)\n'\n!namespaces/fields/fabcar/Sequence\022\002\010\007\022\303\002\n\006fabcar\022\270\002\n\026\n\020\000\364\217\277\277initialized\022\002\010\010\032\235\002\n1{\"id\":\"1\",\"public_key\":\"Audi\",\"private_key\":\"R8\"}\032\347\001{\"id\":\"{\\\"id\\\":\\\"1\\\",\\\"public_key\\\":\\\"Audi\\\",\\\"private_key\\\":\\\"R8\\\"}\",\"public_key\":\"309f24289bb4ebdddfdcfeefa33b1bc58ede3025655c9355fa020a171641c105\",\"private_key\":\"eaceee8305dd94c8241aad4076b15b77cae2a58eb48bad620f71d2f6701f3271\"}\032\003\010\310\001\"\013\022\006fabcar\032\0011" endorsement:<endorser:"\n\007Org1MSP\022\315\007-----BEGIN CERTIFICATE-----\nMIICojCCAkigAwIBAgIUDWYC5bxEYnHpgCznJRsqC+kZ6/MwCgYIKoZIzj0EAwIw\naDELMAkGA1UEBhMCVVMxFzAVBgNVBAgTDk5vcnRoIENhcm9saW5hMRQwEgYDVQQK\nEwtIeXBlcmxlZGdlcjEPMA0GA1UECxMGRmFicmljMRkwFwYDVQQDExBmYWJyaWMt\nY2Etc2VydmVyMB4XDTIzMDIyMDExMzQwMFoXDTI0MDIyMDExNDAwMFowWzELMAkG\nA1UEBhMCVVMxFzAVBgNVBAgTDk5vcnRoIENhcm9saW5hMRQwEgYDVQQKEwtIeXBl\ncmxlZGdlcjENMAsGA1UECxMEcGVlcjEOMAwGA1UEAxMFcGVlcjAwWTATBgcqhkjO\nPQIBBggqhkjOPQMBBwNCAAT+Wtt2RO/bZw+HOEmT2XpB43cSZFIoN4C7oHzsQXwn\nuUH33ewhZoXdd8OU/FOVZgClCTYVUF/muq1/arF74rZMo4HcMIHZMA4GA1UdDwEB\n/wQEAwIHgDAMBgNVHRMBAf8EAjAAMB0GA1UdDgQWBBT8T2I8s+PEojCgOQyE6MMA\nIc/U+DAfBgNVHSMEGDAWgBRZL2wM0bLnKnTrOyTnVcZN6GzQsTAhBgNVHREEGjAY\nghZwZWVyMC5vcmcxLmV4YW1wbGUuY29tMFYGCCoDBAUGBwgBBEp7ImF0dHJzIjp7\nImhmLkFmZmlsaWF0aW9uIjoiIiwiaGYuRW5yb2xsbWVudElEIjoicGVlcjAiLCJo\nZi5UeXBlIjoicGVlciJ9fTAKBggqhkjOPQQDAgNIADBFAiEAipyoKYkGNE03TKOz\nE5RBQj2C2gZybIsrGxb15Wm+2zwCIE2DQxPSnK7saifTPEzSJdMXTL0sJY3uacor\n3udX8ot2\n-----END CERTIFICATE-----\n" signature:"0D\002 \tG[\331@\373\333\005\323\265oL\242\252\025x[\221\304\026:\036h\003\322\322\311\271\021\t\021\246\002 Fn\362\267C\315j\3176g\255\320\002\222g\026\317\217\342*\311~fS5\016\34753\006\002\014" >
What should I do to fix the problem ? I use Linux mint. Tutorial is enter link description here I met this problem is the first step at “Invoking the chaincode” link
Your smart contract transaction function implementation is invalid since it will not return the same read/write sets and transaction result on multiple invocations for the same set of inputs and ledger state. Each invocation generates a new (unique) public/private key pair and stores this on the ledger. See the description of the transaction flow in the Fabric documentation for details:
https://hyperledger-fabric.readthedocs.io/en/latest/txflow.html
As an aside, storing user private encryption keys on a blockchain makes those private keys publicly visible to all the collaborating organizations using that blockchain. Typically private keys are intended to remain private so blockchain probably is not the best place to store them.