Hyperledger Aries云代理向Aries-Bifold发放凭证报错排查
问题排查与解决方案
一、protocolVersion: "v2" 类型不匹配问题
这个错误源于Aries Framework JavaScript(AFJ)的类型约束,新版本AFJ对protocolVersion的类型要求为枚举值而非字符串,解决步骤如下:
- 导入AFJ内置的
ProtocolVersion枚举 - 将字符串
"v2"替换为枚举常量ProtocolVersion.V2
示例代码:
import { ProtocolVersion } from '@aries-framework/core' // 调用offerCredential时的配置 const offerConfig = { protocolVersion: ProtocolVersion.V2, connectionId: "your-active-connection-id", // 其他参数... }
如果使用旧版AFJ(v0.3x及以下),可直接省略protocolVersion配置,框架会自动与对方代理协商版本。
二、AriesFrameworkError: Unable to create offer. No supported formats 错误
该问题核心是云代理未正确加载AnonCreds格式支持,或参数配置有误,按以下方向排查:
1. 确认AnonCreds模块与格式服务已注册
云代理初始化时,必须注册AnonCredsModule及对应的格式服务,否则框架无法识别AnonCreds格式:
import { AnonCredsModule, AnonCredsCredentialFormatService } from '@aries-framework/anoncreds' const agent = new Agent({ // 基础配置(端点、存储等)... modules: { anoncreds: new AnonCredsModule({ credentialFormats: [new AnonCredsCredentialFormatService()], }), // 其他必要模块(如didexchange)... }, })
2. 检查凭证参数的正确性
调用offerCredential时,必须明确指定anoncreds格式的参数,不能遗漏关键字段:
const offerResult = await agent.credentials.offerCredential({ protocolVersion: ProtocolVersion.V2, connectionId: "your-active-connection-id", credentialFormats: { anoncreds: { credentialDefinitionId: "your-registered-cred-def-id", attributes: [ { name: "user_id", value: "12345" }, { name: "username", value: "Simone" } ] } } })
- 确保
credentialDefinitionId是已在账本上发布的有效ID - 属性名称必须与凭证定义(Credential Definition)中的schema字段完全匹配
3. 验证版本兼容性
- 确认云代理使用的AFJ版本与Aries-Bifold兼容:Bifold默认支持AnonCreds v1/v2,需使用AFJ v0.4x及以上版本
- 若使用AnonCreds v1格式,需将
protocolVersion设为ProtocolVersion.V1
内容的提问来源于stack exchange,提问作者Simone Tosatto
相关产品推荐
相关产品推荐

