Проблема:
Я очень новичок в ткани Hyperledger.Я создаю сеть и регистрирую администратора с помощью узла sdk, а затем, чтобы зарегистрировать пользователя, создаю такой скрипт.
/*
* SPDX-License-Identifier: Apache-2.0
*/
"use strict";
const {
FileSystemWallet,
Gateway,
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 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 user.
const userExists = await wallet.exists("tharinduSA");
if (userExists) {
console.log(
'An identity for the user "tharinduSA" already exists in the wallet'
);
return;
}
// Check to see if we've already enrolled the admin user.
const adminExists = await wallet.exists("admin");
if (!adminExists) {
console.log(
'An identity for the admin user "admin" does not exist in the wallet'
);
console.log("Run the enrollAdmin.js application before retrying");
return;
}
// Create a new gateway for connecting to our peer node.
const gateway = new Gateway();
await gateway.connect(
ccp,
{ wallet, identity: "admin", discovery: { enabled: false } }
);
// Get the CA client object from the gateway for interacting with the CA.
const ca = gateway.getClient().getCertificateAuthority();
const adminIdentity = gateway.getCurrentIdentity();
// Register the user, enroll the user, and import the new identity into the wallet.
const secret = await ca.register(
{
affiliation: "org1.department1",
enrollmentID: "tharinduSA",
role: "client"
},
adminIdentity
);
console.log(secret);
const enrollment = await ca.enroll({
enrollmentID: "tharinduSA",
enrollmentSecret: secret
});
const userIdentity = X509WalletMixin.createIdentity(
"Org1MSP",
enrollment.certificate,
enrollment.key.toBytes()
);
wallet.import("tharinduSA", userIdentity);
console.log(
'Successfully registered and enrolled admin user "user1" and imported it into the wallet'
);
} catch (error) {
console.error(`Failed to register user "user1": ${error}`);
process.exit(1);
}
}
main();
Но когда я запускаю этот скрипт, он оставляет мне такую ошибку.
Failed to register user "user1": Error: Calling register endpoint failed with error [Error: unsupported certificate purpose]
Когда я отлаживал код, я смог обнаружить, что на этом этапе происходит сбой кода.
const secret = await ca.register(
{
affiliation: "org1.department1",
enrollmentID: "tharinduSA",
role: "client"
},
adminIdentity
);
Это мой файл connection.json.
{
"name": "basic-network",
"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": {},
"peer0.org2.example.com": {}
}
}
},
"organizations": {
"Org1": {
"mspid": "Org1MSP",
"peers": ["peer0.org1.example.com", "peer1.org1.example.com"],
"certificateAuthorities": ["ca.org1.example.com"]
},
"Org2": {
"mspid": "Org2MSP",
"peers": ["peer0.org2.example.com", "peer1.org2.example.com"],
"certificateAuthorities": ["ca.org2.example.com"]
}
},
"orderers": {
"orderer.example.com": {
"url": "grpc://localhost:7050"
}
},
"peers": {
"peer0.org1.example.com": {
"url": "grpc://localhost:7051"
},
"peer1.org1.example.com": {
"url": "grpc://localhost:7051"
},
"peer0.org2.example.com": {
"url": "grpc://localhost:7051"
},
"peer1.org2.example.com": {
"url": "grpc://localhost:7051"
}
},
"certificateAuthorities": {
"ca.org1.example.com": {
"url": "https://localhost:7054",
"caName": "ca.org1.example.com"
},
"ca.org2.example.com": {
"url": "https://localhost:7054",
"caName": "ca.org2.example.com"
}
}
}
Но я не смог выяснить, что с этим не так.Может ли кто-нибудь помочь мне решить эту проблему?Спасибо !!