How do I resolve the “Zencode runtime error” indicating an invalid ‘keyring’ when generating a public key using executeContract with Zenroom?
const generateKeys = async () => {
const contract = `
Scenario 'ecdh': Generate a key
Given I am 'c'
When I create the ecdh key
Then print my keyring
`;
try {
const result = await executeContract(contract);
console.log("Result in generateKeys:", result);
// Extract the private key from the result
const parsedResult = JSON.parse(result);
const keyring = parsedResult.c.keyring;
if (keyring && keyring.ecdh) {
setPrivateKey(keyring.ecdh);
return keyring.ecdh;
}
} catch (error) {
console.error('Error generating keys:', error);
throw error;
}
};
const executeContract = async (contract, props = {}) => {
try {
const result = await zencode_exec(contract, props);
console.log('Contract execution result:', result);
if (result && result.result) {
return result.result;
} else {
throw new Error('Unexpected result format from zencode_exec');
}
} catch (error) {
console.error('Error executing contract:', error);
throw error;
}
};
const contract = Rule check version 4.33.0 Scenario 'ecdh': Generate public key Given that I am known as 'c' Given that I have a valid 'keyring' When I create the ecdh public key Then print my 'ecdh public key'
;
const result = await executeContract(contract, { keys: privateKey });
How do I resolve the “Zencode runtime error” indicating an invalid ‘keyring’ when generating a public key using executeContract with Zenroom?