基于Hyperledger Indy的身份系统:Schema上链失败及查询报错
Hyperledger Indy Schema 提交与查询问题处理
问题1:Schema 提交被拒绝(未授权)
提交"Device Profile" Schema到账本时收到拒绝响应,错误显示当前身份无权限:
"Schema Builder" -> Send "Device Profile" Schema to Ledger {"reqId":1683198357199119479,"identifier":"2qzghpxTM5H81hUbYFmPR4","reason":"client request invalid: UnauthorizedClientRequest('Rule for this action is: 1 TRUSTEE signature is required OR 1 STEWARD signature is required OR 1 ENDORSER signature is required\\nFailed checks:\\nConstraint: 1 TRUSTEE signature is required, Error: Not enough TRUSTEE signatures\\nConstraint: 1 STEWARD signature is required, Error: Not enough STEWARD signatures\\nConstraint: 1 ENDORSER signature is required, Error: Not enough ENDORSER signatures',)","op":"REJECT"}
原因
Hyperledger Indy账本要求写入Schema的请求必须由TRUSTEE、STEWARD或ENDORSER角色的身份签名,当前使用的身份(2qzghpxTM5H81hUbYFmPR4)不具备以上任何一种权限。
解决办法
- 使用已有TRUSTEE/STEWARD身份签署Schema提交请求,重新提交。
- 若需要将当前身份升级为ENDORSER,通过TRUSTEE身份发起
NYM交易,为该身份添加ENDORSER角色:# 示例:用TRUSTEE身份给目标身份设置ENDORSER角色 await ledger.build_nym_request(trustee_did, target_did, None, None, "ENDORSER") - 确认提交请求的签名身份权限正确后,重新执行Schema提交操作。
问题2:Schema 查询返回 LedgerNotFound
提交失败后尝试从账本获取Schema时抛出错误:
STEP5 - theCredDefGenerator 创建设备凭证定义 ================================ -------------------------------------------------- "theCredDefGenerator" -> Get "device profile " Schema from Ledger Traceback (most recent call last): File "main.py", line 177, in <module> loop.run_until_complete(run()) File "/usr/lib/python3.6/asyncio/base_events.py", line 484, in run_until_complete return future.result() File "main.py", line 151, in run (theCredDefGenerator['deviceprofile_schema_id'], theCredDefGenerator['deviceprofile_schema']) = await ledger.parse_get_schema_response(get_schema_response) File "/home/amit_jatola/.local/lib/python3.6/site-packages/indy/ledger.py", line 568, in parse_get_schema_response parse_get_schema_response.cb) indy.error.LedgerNotFound
原因
因为第一个问题导致Schema从未成功写入账本,所以查询时找不到对应数据;另外需检查查询的Schema名称/ID是否存在拼写错误(日志中"device profile "多了末尾空格,需确认代码中Schema ID与提交时一致)。
解决办法
- 先解决第一个授权问题,确保Schema成功写入账本。
- 核对查询时使用的Schema ID或名称,修正拼写错误(比如多余的空格)。
- 重新执行Schema查询操作。
内容的提问来源于stack exchange,提问作者amit jatola
相关产品推荐
相关产品推荐

