【问题标题】:Hyperledger Indy Creating RevocationRegistry Fails, malformed credDefId because of schema_refHyperledger Indy 创建 RevocationRegistry 失败,由于 schema_ref 而导致 credDefId 格式错误
【发布时间】:2021-11-01 14:28:45
【问题描述】:

我目前正在尝试将撤销注册表定义 (revRegDef) 写入 Hyperledger Indy 池,如 Indy Getting Started 所示。 工作流程是这样的:

  1. 创建架构
  2. 使用 schemaId,创建凭据定义 (credDef)
  3. 使用 credDefId,创建一个 revRegDef

由于我需要使用Java,所以我将分类帐的适当请求添加到Java Sample,我上传了我修改后的版本here

创建架构和 credDef 工作正常,但是当我发送最后一个请求时,我收到以下错误消息:

reason -> client request invalid: InvalidClientRequest("Format of credDefId field is not acceptable. 
Expected: 'did:marker:signature_type:schema_ref' or 'did:marker:signature_type:schema_ref:tag'",)

此时,提到的 credDefId 如下所示:Th7MpTaRZVRYnPiabds81Y:3:CL:Th7MpTaRZVRYnPiabds81Y:2:gvt:1.0:Tag1 而 schemaId 是 Th7MpTaRZVRYnPiabds81Y:2:gvt:1.0

显然没有满足提到的模式,但Ledger.buildCredDefReq() 函数像这样返回credDefId,所以我希望它是正确的。

【问题讨论】:

    标签: java hyperledger hyperledger-indy


    【解决方案1】:

    编辑:虽然我的旧答案有效,但它只是一种解决方法和完整的 bs.. 以下应该是创建凭证架构、凭证定义和撤销注册表定义的正确方法。

    // Create Credential Schema
    String name = "schema_name";
    String schemaAttrs = new JSONArray().put("name").put("age").toString();
    AnoncredsResults.IssuerCreateSchemaResult schema =
            Anoncreds.issuerCreateSchema(verinym, name, "1.0", schemaAttrs).get();
    String schemaId = schema.getSchemaId();
    String schemaJson = schema.getSchemaJson();
    JSONObject schemaRes = new JSONObject(Ledger.signAndSubmitRequest(PoolUtils.getInstance(), wallet, verinym,
            Ledger.buildSchemaRequest(verinym, schemaJson).get()
    ).get());
    int schemaSeqNo = schemaRes.getJSONObject("result").getJSONObject("txnMetadata").getInt("seqNo");
    schemaJson = new JSONObject(schemaJson).put("seqNo", schemaSeqNo).toString();
    
    // Create Credential Definition
    AnoncredsResults.IssuerCreateAndStoreCredentialDefResult credDef =
            Anoncreds.issuerCreateAndStoreCredentialDef(
                    wallet, verinym, schemaJson, "tag", null,
                    new JSONObject().put("support_revocation", true).toString()
            ).get();
    
    // creating credDef req and sending it to the ledger
    JSONObject credDefRes = new JSONObject(
            Ledger.signAndSubmitRequest(
                    PoolUtils.getInstance(), wallet, verinym,
                    Ledger.buildCredDefRequest(verinym, credDef.getCredDefJson()).get()
            ).get()
    );
    int credSeqNo = credDefRes.getJSONObject("result").getJSONObject("txnMetadata").getInt("seqNo");
    
    // Create Revocation Registry Definition
    String tailsWriterConfig = new JSONObject().put("base_dir", "/tmp/indy_tails").put("uri_pattern", "").toString();
    BlobStorageWriter tails = BlobStorageWriter.openWriter("default", tailsWriterConfig).get();
    AnoncredsResults.IssuerCreateAndStoreRevocRegResult revocRegDef = Anoncreds.issuerCreateAndStoreRevocReg(
            wallet, verinym, null, "contractDef", credDefId,
            "{}", tails
    ).get();
    JSONObject revocRegDefRes = new JSONObject(
            Ledger.signAndSubmitRequest(PoolUtils.getInstance(), wallet, verinym,
                    Ledger.buildRevocRegDefRequest(verinym, revocRegDef.getRevRegDefJson()).get()
            ).get());
    revocRegDefSeqNo = revocRegDefRes.getJSONObject("result").getJSONObject("txnMetadata").getInt("seqNo");
    

    学习是账本返回用于定义创建的重要值

    此外,没有提到您需要创建初始撤销注册表项:

    // Create initial revocation entry
    JSONObject revocRegEntryRes = new JSONObject(Ledger.signAndSubmitRequest(PoolUtils.getInstance(), wallet, verinym,
    Ledger.buildRevocRegEntryRequest(verinym, revocRegDef.getRevRegId(),
    "CL_ACCUM", revocRegDef.getRevRegEntryJson()).get()).get());
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-12-28
      • 1970-01-01
      • 1970-01-01
      • 2015-12-18
      • 1970-01-01
      • 1970-01-01
      • 2013-01-29
      相关资源
      最近更新 更多