Node.js 无法在Hyperledger结构中使用nodejs SDK注册管理员?

Node.js 无法在Hyperledger结构中使用nodejs SDK注册管理员?,node.js,hyperledger-fabric,Node.js,Hyperledger Fabric,问题: 我创建一个nodejs脚本,将管理员注册到我的区块链网络。这就是它的样子 /* * SPDX-License-Identifier: Apache-2.0 */ "use strict"; const FabricCAServices = require("fabric-ca-client"); const { FileSystemWallet, X509WalletMixin } = require("fabric-network"); const fs = require("

问题:

我创建一个nodejs脚本,将管理员注册到我的区块链网络。这就是它的样子

/*
 * SPDX-License-Identifier: Apache-2.0
 */

"use strict";

const FabricCAServices = require("fabric-ca-client");
const { FileSystemWallet, X509WalletMixin } = require("fabric-network");
const fs = require("fs");
const path = require("path");

const ccpPath = path.resolve(__dirname, ".", "connection.json");
const ccpJSON = fs.readFileSync(ccpPath, "utf8");
const ccp = JSON.parse(ccpJSON);

async function main() {
  try {
    // Create a new CA client for interacting with the CA.
    const caURL = ccp.certificateAuthorities["ca.org1.example.com"].url;
    const ca = new FabricCAServices(caURL);


    // Create a new file system based wallet for managing identities.
    const walletPath = path.join(process.cwd(), "wallet");
    const wallet = new FileSystemWallet(walletPath);
    console.log(`Wallet path: ${walletPath}`);

    // Check to see if we've already enrolled the admin user.
    const adminExists = await wallet.exists("Admin@org1.example.com");
    if (adminExists) {
      console.log(
        'An identity for the admin user "admin" already exists in the wallet'
      );
      return;
    }

    // Enroll the admin user, and import the new identity into the wallet.
    const enrollment = await ca.enroll({
      enrollmentID: "admin",
      enrollmentSecret: "adminpw"
    });

    const identity = X509WalletMixin.createIdentity(
      "Org1MSP",
      enrollment.certificate,
      enrollment.key.toBytes()
    );

    wallet.import("Admin@org1.example.com", identity);
    console.log(
      'Successfully enrolled admin user "admin" and imported it into the wallet'
    );
  } catch (error) {
    console.error(`Failed to enroll admin user "admin": ${error}`);
    process.exit(1);
  }
}

main();
{
    "name": "myapp",
    "version": "1.0.0",
    "client": {
      "organization": "Org1",
      "connection": {
        "timeout": {
          "peer": {
            "endorser": "300"
          },
          "orderer": "300"
        }
      }
    },
    "channels": {
      "mychannel": {
        "orderers": ["orderer.example.com"],
        "peers": {
          "peer0.org1.example.com": {
            "endorsingPeer": true,
            "chaincodeQuery": true,
            "ledgerQuery": true,
            "eventSource": true
          },
          "peer0.org2.example.com": {
            "endorsingPeer": true,
            "chaincodeQuery": true,
            "ledgerQuery": true,
            "eventSource": true
          }
        }
      }
    },
    "organizations": {
      "Org1": {
        "mspid": "Org1MSP",
        "peers": [
          "peer0.org1.example.com",
          "peer1.org1.example.com"
        ],
        "certificateAuthorities": ["ca.org1.example.com"],
        "adminPrivateKey": {
          "path": "../crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/keystore/816cc3ef430fc97813370cff3c55fdeacecb38ace6e75919e4b7e88d174b779d_sk"
        },
        "signedCert": {
          "path": "../crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/signcerts/Admin@org1.example.com-cert.pem"
        }
      },
      "Org2": {
        "mspid": "Org2MSP",
        "peers": [
          "peer0.org2.example.com",
          "peer1.org2.example.com"
        ],
        "certificateAuthorities": ["ca.org2.example.com"],
        "adminPrivateKey": {
          "path": "../crypto-config/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp/keystore/7c91e1816db0fabf3bbe0f2eb4195678f7ff6a0b16c8c7274be0175c4833cc6c_sk"
        },
        "signedCert": {
          "path": "../crypto-config/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp/signcerts/Admin@org2.example.com-cert.pem"
        }
      }
    },
    "orderers": {
      "orderer.example.com": {
        "url": "grpcs://localhost:7050",
        "grpcOptions": {
          "ssl-target-name-override": "orderer.example.com",
          "grpc-max-send-message-length": 15
        },
        " tlsCACerts": {
          "path": "../crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem"
        }
      }
    },
    "peers": {
      "peer0.org1.example.com": {
        "url": "grpcs://localhost:7051",
        "eventUrl": "grpcs://localhost:7053",
        "grpcOptions": {
          "ssl-target-name-override": "peer0.org1.example.com",
          "grpc.keepalive_time_ms": 600000
        },
        "tlsCACerts": {
          "path": "../crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/msp/tlscacerts/tlsca.org1.example.com-cert.pem"
        }
      },
      "peer1.org1.example.com": {
        "url": "grpcs://localhost:8051",
        "eventUrl": "grpcs://localhost:8053",
        "grpcOptions": {
          "ssl-target-name-override": "peer1.org1.example.com",
          "grpc.keepalive_time_ms": 600000
        },
        "tlsCACerts": {
          "path": "../crypto-config/peerOrganizations/org1.example.com/peers/peer1.org1.example.com/msp/tlscacerts/tlsca.org1.example.com-cert.pem"
        }
      },
      "peer0.org2.example.com": {
        "url": "grpcs://localhost:9051",
        "eventUrl": "grpcs://localhost:9053",
        "grpcOptions": {
          "ssl-target-name-override": "peer0.org2.example.com",
          "grpc.keepalive_time_ms": 600000
        },
        "tlsCACerts": {
          "path": "../crypto-config/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/msp/tlscacerts/tlsca.org2.example.com-cert.pem"
        }
      },
      "peer1.org2.example.com": {
        "url": "grpcs://localhost:7051",
        "eventUrl": "grpcs://localhost:7053",
        "grpcOptions": {
          "ssl-target-name-override": "peer1.org2.example.com",
          "grpc.keepalive_time_ms": 600000
        },
        "tlsCACerts": {
          "path": "../crypto-config/peerOrganizations/org2.example.com/peers/peer1.org2.example.com/msp/tlscacerts/tlsca.org2.example.com-cert.pem"
        }
      }
    },
    "certificateAuthorities": {
      "ca.org1.example.com": {
        "url": "https://localhost:7054",
        "httpOptions": {
          "verify": false
        },
        "caName": "ca.org1.example.com",
        "tlsCACerts": {
          "path": "../crypto-config/peerOrganizations/org1.example.com/ca/ca.org1.example.com-cert.pem"
        }
      },
      "ca.org2.example.com": {
        "url": "https://localhost:7054",
        "httpOptions": {
          "verify": false
        },
        "caName": "ca.org2.example.com",
        "tlsCACerts": {
          "path": "../crypto-config/peerOrganizations/org2.example.com/ca/ca.org2.example.com-cert.pem"
        }
      }
    }
  }
但当我运行它时,它在wallet path的控制台日志之后卡住了,没有做更多的操作。这就是我的connection.json文件的样子

/*
 * SPDX-License-Identifier: Apache-2.0
 */

"use strict";

const FabricCAServices = require("fabric-ca-client");
const { FileSystemWallet, X509WalletMixin } = require("fabric-network");
const fs = require("fs");
const path = require("path");

const ccpPath = path.resolve(__dirname, ".", "connection.json");
const ccpJSON = fs.readFileSync(ccpPath, "utf8");
const ccp = JSON.parse(ccpJSON);

async function main() {
  try {
    // Create a new CA client for interacting with the CA.
    const caURL = ccp.certificateAuthorities["ca.org1.example.com"].url;
    const ca = new FabricCAServices(caURL);


    // Create a new file system based wallet for managing identities.
    const walletPath = path.join(process.cwd(), "wallet");
    const wallet = new FileSystemWallet(walletPath);
    console.log(`Wallet path: ${walletPath}`);

    // Check to see if we've already enrolled the admin user.
    const adminExists = await wallet.exists("Admin@org1.example.com");
    if (adminExists) {
      console.log(
        'An identity for the admin user "admin" already exists in the wallet'
      );
      return;
    }

    // Enroll the admin user, and import the new identity into the wallet.
    const enrollment = await ca.enroll({
      enrollmentID: "admin",
      enrollmentSecret: "adminpw"
    });

    const identity = X509WalletMixin.createIdentity(
      "Org1MSP",
      enrollment.certificate,
      enrollment.key.toBytes()
    );

    wallet.import("Admin@org1.example.com", identity);
    console.log(
      'Successfully enrolled admin user "admin" and imported it into the wallet'
    );
  } catch (error) {
    console.error(`Failed to enroll admin user "admin": ${error}`);
    process.exit(1);
  }
}

main();
{
    "name": "myapp",
    "version": "1.0.0",
    "client": {
      "organization": "Org1",
      "connection": {
        "timeout": {
          "peer": {
            "endorser": "300"
          },
          "orderer": "300"
        }
      }
    },
    "channels": {
      "mychannel": {
        "orderers": ["orderer.example.com"],
        "peers": {
          "peer0.org1.example.com": {
            "endorsingPeer": true,
            "chaincodeQuery": true,
            "ledgerQuery": true,
            "eventSource": true
          },
          "peer0.org2.example.com": {
            "endorsingPeer": true,
            "chaincodeQuery": true,
            "ledgerQuery": true,
            "eventSource": true
          }
        }
      }
    },
    "organizations": {
      "Org1": {
        "mspid": "Org1MSP",
        "peers": [
          "peer0.org1.example.com",
          "peer1.org1.example.com"
        ],
        "certificateAuthorities": ["ca.org1.example.com"],
        "adminPrivateKey": {
          "path": "../crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/keystore/816cc3ef430fc97813370cff3c55fdeacecb38ace6e75919e4b7e88d174b779d_sk"
        },
        "signedCert": {
          "path": "../crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/signcerts/Admin@org1.example.com-cert.pem"
        }
      },
      "Org2": {
        "mspid": "Org2MSP",
        "peers": [
          "peer0.org2.example.com",
          "peer1.org2.example.com"
        ],
        "certificateAuthorities": ["ca.org2.example.com"],
        "adminPrivateKey": {
          "path": "../crypto-config/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp/keystore/7c91e1816db0fabf3bbe0f2eb4195678f7ff6a0b16c8c7274be0175c4833cc6c_sk"
        },
        "signedCert": {
          "path": "../crypto-config/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp/signcerts/Admin@org2.example.com-cert.pem"
        }
      }
    },
    "orderers": {
      "orderer.example.com": {
        "url": "grpcs://localhost:7050",
        "grpcOptions": {
          "ssl-target-name-override": "orderer.example.com",
          "grpc-max-send-message-length": 15
        },
        " tlsCACerts": {
          "path": "../crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem"
        }
      }
    },
    "peers": {
      "peer0.org1.example.com": {
        "url": "grpcs://localhost:7051",
        "eventUrl": "grpcs://localhost:7053",
        "grpcOptions": {
          "ssl-target-name-override": "peer0.org1.example.com",
          "grpc.keepalive_time_ms": 600000
        },
        "tlsCACerts": {
          "path": "../crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/msp/tlscacerts/tlsca.org1.example.com-cert.pem"
        }
      },
      "peer1.org1.example.com": {
        "url": "grpcs://localhost:8051",
        "eventUrl": "grpcs://localhost:8053",
        "grpcOptions": {
          "ssl-target-name-override": "peer1.org1.example.com",
          "grpc.keepalive_time_ms": 600000
        },
        "tlsCACerts": {
          "path": "../crypto-config/peerOrganizations/org1.example.com/peers/peer1.org1.example.com/msp/tlscacerts/tlsca.org1.example.com-cert.pem"
        }
      },
      "peer0.org2.example.com": {
        "url": "grpcs://localhost:9051",
        "eventUrl": "grpcs://localhost:9053",
        "grpcOptions": {
          "ssl-target-name-override": "peer0.org2.example.com",
          "grpc.keepalive_time_ms": 600000
        },
        "tlsCACerts": {
          "path": "../crypto-config/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/msp/tlscacerts/tlsca.org2.example.com-cert.pem"
        }
      },
      "peer1.org2.example.com": {
        "url": "grpcs://localhost:7051",
        "eventUrl": "grpcs://localhost:7053",
        "grpcOptions": {
          "ssl-target-name-override": "peer1.org2.example.com",
          "grpc.keepalive_time_ms": 600000
        },
        "tlsCACerts": {
          "path": "../crypto-config/peerOrganizations/org2.example.com/peers/peer1.org2.example.com/msp/tlscacerts/tlsca.org2.example.com-cert.pem"
        }
      }
    },
    "certificateAuthorities": {
      "ca.org1.example.com": {
        "url": "https://localhost:7054",
        "httpOptions": {
          "verify": false
        },
        "caName": "ca.org1.example.com",
        "tlsCACerts": {
          "path": "../crypto-config/peerOrganizations/org1.example.com/ca/ca.org1.example.com-cert.pem"
        }
      },
      "ca.org2.example.com": {
        "url": "https://localhost:7054",
        "httpOptions": {
          "verify": false
        },
        "caName": "ca.org2.example.com",
        "tlsCACerts": {
          "path": "../crypto-config/peerOrganizations/org2.example.com/ca/ca.org2.example.com-cert.pem"
        }
      }
    }
  }

有人能帮我找出这有什么问题吗?谢谢

Your connection.json显示ca1和ca2都在“https://localhost:7054”上,不知道这是否是问题所在。TLSCert的路径是否正确?CA是否在该地址和端口启动并可用将此作为一个测试来尝试`wget--no check certificate`Your connection.json显示ca1和ca2都在“https://localhost:7054”上—不知道这是否是问题所在。TLSCert的路径是否正确?CA是否在该地址和端口启动并可用将此作为测试“wget--无检查证书”`