I’m using hyperledger indy for a project.
In my code I use anoncreds.prover_create_credential_req() as follow:
(device['device_attributes_cred_request'], device['device_attributes_cred_request_metadata']) =
await anoncreds.prover_create_credential_req(
device['wallet'],
device['User_info']['Pairwise_did_for_User'],
json.dumps(device['credential_offer']),
json.dumps(device['device_attributes_cred_def']) ,
device['master_secret_id'])
Everything seems correct, but when i run the code it returns this error:
Traceback (most recent call last):
File "/home/indy-sdk/app/main.py", line 597, in <module>
File "/usr/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete
return future.result()
File "/home/indy-sdk/app/main.py", line 583, in run
device['wallet'],
File "/home/.local/lib/python3.10/site-packages/indy/anoncreds.py", line 729, in prover_create_credential_req
(credential_req_json, credential_req_metadata_json) = await do_call('indy_prover_create_credential_req',
indy.error.CommonInvalidStructure
Here’s how the parameter where generated:
device[‘wallet’] is generated from
async def create_wallet(identity):
print(""{}" -> Create wallet".format(identity['name']))
try:
await wallet.create_wallet(identity['wallet_config'],
identity['wallet_credentials'])
except IndyError as ex:
if ex.error_code == ErrorCode.PoolLedgerConfigAlreadyExistsError:
pass
identity['wallet'] = await wallet.open_wallet(identity['wallet_config'],
identity['wallet_credentials'])
device[‘User_info’][‘Pairwise_did_for_User’] is the DID Device created for a secure communication with User, using did.create_and_store_my_did()
device[‘credential_offer’] comes from
user['device_attributes_cred_offer'] = await anoncreds.issuer_create_credential_offer(user['wallet'], user['device_attributes_cred_def_id'])
device_attributes_cred_offer = user['device_attributes_cred_offer']
#User Agent send encrypted credential offer
authcrypted_device_attributes_credential_offer =
await crypto.auth_crypt(user['wallet'], user['Device_info']['Pairwise_verkey_for_Device'], user['Device_info']['Device_key_for_User'], (device_attributes_cred_offer).encode('utf-8'))
#Device Agend decrypte and store credential offer
authdecrypted_device_attributes_credential_offer =
await crypto.auth_decrypt(device['wallet'], device['User_info']['Pairwise_verkey_for_User'], authcrypted_device_attributes_credential_offer)
device['credential_offer'] = json.loads(((authdecrypted_device_attributes_credential_offer)[1]).decode('utf-8'))
I had to transform it in a json string using json.loads because anoncreds.prover_create_credential_req() requires it to has that type, but to do so, i had to select the second element of the tuple, since was not possible to cast the first element into a json string; for a better understanding this is the initial part of authdecrypted_device_attributes_credential_offer:
('DDzKRUEjZP3F5evtsSVyj9hvM3PneHK1PSPbA9QTijN4', b'{"schema_id":"Uo9cHmH6LKgQHqGK1K41UG:2:Device_attributes:1.2","cred_def_id":"Uo9cHmH6LKgQHqGK1K41UG:3:CL:601:TAG1".....and so on
device[‘device_attributes_cred_def’] derives from
get_cred_def_request = await ledger.build_get_cred_def_request(device['User_info']['Pairwise_did_for_User'], device['credential_offer']['cred_def_id'])
get_cred_def_response = await ledger.submit_request(device['pool'], get_cred_def_request)
device['device_attributes_cred_def'] = await ledger.parse_get_cred_def_response(get_cred_def_response)
And in the end device[‘master_secret_id’] is generated from the function
device['master_secret_id'] = await anoncreds.prover_create_master_secret(device['wallet'], None)