【问题标题】:How to use fabric sdk to initialize the fabric CA如何使用fabric sdk初始化fabric CA
【发布时间】:2019-10-12 03:09:44
【问题描述】:

我在使用fabric ca初始化fabric-sdk-go时遇到了困难。

  1. 我正在使用默认配置运行结构 CA 服务器,为此我使用以下代码。

    当我使用下面的代码时,它将生成带有数据库的服务器配置文件。

    ./bin/fabric-ca-server start -b  admin:adminpwd --home ~/ca  
    
  2. 接下来我使用下面的代码来注册管理员,这将在客户端和密钥中生成管理员 yaml 文件。

    ./bin/fabric-ca-client enroll admin:adminpws localhost:7054
    

    我想使用https://github.com/hyperledger/fabric-sdk-go/pkg/client/msp 来创建客户端上下文。

    我的问题是

    我需要加载哪个配置文件,以在 fabric-sdk-go 中创建客户端上下文 因为我想打电话

    func New(clientProvider context.ClientProvider, opts ...ClientOption) (*Client, error)
    

    它给我错误请建议我

    failed to create msp client organization is not provided
    

【问题讨论】:

    标签: hyperledger-fabric hyperledger


    【解决方案1】:

    请按照我的步骤,NodeJS SDK

     const caEndPoint = "https://localhost:7054"
     const caName = "ca-org1"
     let tlsOptions = {
        trustedRoots: [],
        verify: false
      };
    const fabricCAServices = require('fabric-ca-client');
    const caService = new fabricCAServices(caEndPoint, tlsOptions, caName);
    

    您可以使用 caService 调用可用的方法

    • 注册
    • 添加从属关系
    • 新身份服务
    • newCertificateService

    注册新身份

    const identityService = caService.newIdentityService();
        let registerObject = {
          enrollmentID: enrollmentId,
          type: type,
          affiliation: userOrg,
          maxEnrollments: maxEnrollments || 1,
          attrs: attributes,
          caname: caName
        }
    const response = await identityService.create(registerObject, admin_user);
    

    【讨论】:

    • 感谢重播!,我正在运行 go,我遇到了一些与 fabric-sdk-go 相关的问题,我需要在其中创建上下文,但我不确定我需要哪个配置文件用于加载/运行fabric sdk。我正在启动fabric ca服务器,它还创建fabric-ca-config.yaml我需要加载这个配置文件来创建上下文或任何其他配置文件。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-22
    • 1970-01-01
    • 2017-07-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多