Fabric Node SDK - 违反实例化策略:签名集不满足策略
Fabric Node SDK - Instantiation policy violation: signature set did not satisfy policy
我有一个 hyperledger fabric 测试网,有 2 个组织,org1 中有 3 个对等点,org2 中有 2 个对等点。每个组织的 peer0 是锚节点。
当我尝试实例化链码时出现以下错误:
Error: instantiation policy violation: signature set did not satisfy policy
代码如下
async function main() {
try {
// Create a new CA client for interacting with the CA.
const caInfo = ccp.certificateAuthorities['ca.org1.example.com'];
const caTLSCACerts = caInfo.tlsCACerts.pem;
const ca = new FabricCAServices(caInfo.url, { trustedRoots: caTLSCACerts, verify: false }, caInfo.caName);
// 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}`);
const enrollment = await ca.enroll({ enrollmentID: 'adminCA', enrollmentSecret: 'adminpw' });
const identity = X509WalletMixin.createIdentity('org1MSP', enrollment.certificate, enrollment.key.toBytes());
await wallet.import('adminCA', identity);
console.log('Successfully enrolled admin user "admin" and imported it into the wallet');
// Create a new gateway for connecting to our peer node.
const gateway = new Gateway();
await gateway.connect(ccpPath, { wallet, identity: 'adminCA', discovery: { enabled: true, asLocalhost: true } });
let client = gateway.getClient()
var cryptoSuite = Client.newCryptoSuite();
cryptoSuite.setCryptoKeyStore(Client.newCryptoKeyStore({ path: '/tmp' }));
client.setCryptoSuite(cryptoSuite);
const pathCert = path.resolve('/Users/mtng/go1.10/src/github.com/hf-dev/hyperledgerfabrictestnet/crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/admincerts/Admin@org1.example.com-cert.pem')
const pathKey = path.resolve('/Users/mtng/go1.10/src/github.com/hf-dev/hyperledgerfabrictestnet/crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/keystore/0d0ed5f38a1084b1ca12d0836c0e4b011e8a97ca93d919a9d4d4275b147b3e30_sk')
let cert = fs.readFileSync(pathCert)
let pk = fs.readFileSync(pathKey)
const channel = client.newChannel('channel')
client.setAdminSigningIdentity(pk, cert, 'org1MSP')
let targets = [];
let json = peersConfig.peers
for (var key in json) {
console.log(json[key])
let data = fs.readFileSync(json[key].tlsCACerts.path)
let peer = client.newPeer(json[key].url, {
pem: Buffer.from(data).toString(),
'ssl-target-name-override': json[key].grpcOptions['ssl-target-name-override']
})
channel.addPeer(peer)
targets.push(peer)
}
await channel.initialize({ discover: false })
let request = {
targets: targets,
chaincodePath: 'chaincode_example02',
chaincodeId: 'mycc2',
chaincodeType: 'golang',
chaincodeVersion: '1',
channelName: ['channel']
};
const res = await client.installChaincode(request);
const tx_id = client.newTransactionID();
const requestIntantiate = {
chaincodePath: 'chaincode_example02',
chaincodeId: 'mycc2',
chaincodeType: 'golang',
chaincodeVersion: '1',
channelName: ['channel'],
fcn: 'init',
args: ['a', '100', 'b', '200'],
txId: tx_id,
'endorsement-policy': {
identities: [
{ role: { name: "member", mspId: "org1MSP" } },
],
policy: {
"1-of": [{ "signed-by": 0 }, { "signed-by": 1 }]
}
}
}
const resInst = await channel.sendInstantiateProposal(requestIntantiate)
console.log(resInst)
} catch (error) {
console.error(`Failed to enroll admin user "admin": ${error}`);
process.exit(1);
}
}
这是我的配置文件:https://gist.github.com/mtnieto/3442cbd5d2617fcfafcabbf13fb6953c
我该如何解决这个问题?为什么会这样?
创建交易 ID 时需要使用管理参数。
const tx_id = client.newTransactionID(true);
并使用加密生成的管理证书创建一个用户
const pathCert = path.resolve('hf-dev/hyperledgerfabrictestnet/crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/signcerts/Admin@org1.example.com-cert.pem')
const pathKey = path.resolve('hf-dev/hyperledgerfabrictestnet/crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/keystore/d52b5370d5fe1657cad43a3828978a2bebf528e838462c9236801e774229e311_sk')
let cert = fs.readFileSync(pathCert)
let pk = fs.readFileSync(pathKey)
const user = await client.createUser({
username: 'peerUser',
mspid: 'org1MSP',
cryptoContent: {
privateKeyPEM: pk.toString('utf8'),
signedCertPEM: cert.toString('utf8')
}
});
有点小错误
检查下方
var request = {
chaincodeId: this.chaincodeName,
chaincodeType: this.chaincodeType,
chaincodeVersion: this.chaincodeVersion,
args: args,
txId: tx_id,
'collections-config': collectionsConfigPath
};
你必须提到collections-config
我有一个 hyperledger fabric 测试网,有 2 个组织,org1 中有 3 个对等点,org2 中有 2 个对等点。每个组织的 peer0 是锚节点。
当我尝试实例化链码时出现以下错误:
Error: instantiation policy violation: signature set did not satisfy policy
代码如下
async function main() {
try {
// Create a new CA client for interacting with the CA.
const caInfo = ccp.certificateAuthorities['ca.org1.example.com'];
const caTLSCACerts = caInfo.tlsCACerts.pem;
const ca = new FabricCAServices(caInfo.url, { trustedRoots: caTLSCACerts, verify: false }, caInfo.caName);
// 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}`);
const enrollment = await ca.enroll({ enrollmentID: 'adminCA', enrollmentSecret: 'adminpw' });
const identity = X509WalletMixin.createIdentity('org1MSP', enrollment.certificate, enrollment.key.toBytes());
await wallet.import('adminCA', identity);
console.log('Successfully enrolled admin user "admin" and imported it into the wallet');
// Create a new gateway for connecting to our peer node.
const gateway = new Gateway();
await gateway.connect(ccpPath, { wallet, identity: 'adminCA', discovery: { enabled: true, asLocalhost: true } });
let client = gateway.getClient()
var cryptoSuite = Client.newCryptoSuite();
cryptoSuite.setCryptoKeyStore(Client.newCryptoKeyStore({ path: '/tmp' }));
client.setCryptoSuite(cryptoSuite);
const pathCert = path.resolve('/Users/mtng/go1.10/src/github.com/hf-dev/hyperledgerfabrictestnet/crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/admincerts/Admin@org1.example.com-cert.pem')
const pathKey = path.resolve('/Users/mtng/go1.10/src/github.com/hf-dev/hyperledgerfabrictestnet/crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/keystore/0d0ed5f38a1084b1ca12d0836c0e4b011e8a97ca93d919a9d4d4275b147b3e30_sk')
let cert = fs.readFileSync(pathCert)
let pk = fs.readFileSync(pathKey)
const channel = client.newChannel('channel')
client.setAdminSigningIdentity(pk, cert, 'org1MSP')
let targets = [];
let json = peersConfig.peers
for (var key in json) {
console.log(json[key])
let data = fs.readFileSync(json[key].tlsCACerts.path)
let peer = client.newPeer(json[key].url, {
pem: Buffer.from(data).toString(),
'ssl-target-name-override': json[key].grpcOptions['ssl-target-name-override']
})
channel.addPeer(peer)
targets.push(peer)
}
await channel.initialize({ discover: false })
let request = {
targets: targets,
chaincodePath: 'chaincode_example02',
chaincodeId: 'mycc2',
chaincodeType: 'golang',
chaincodeVersion: '1',
channelName: ['channel']
};
const res = await client.installChaincode(request);
const tx_id = client.newTransactionID();
const requestIntantiate = {
chaincodePath: 'chaincode_example02',
chaincodeId: 'mycc2',
chaincodeType: 'golang',
chaincodeVersion: '1',
channelName: ['channel'],
fcn: 'init',
args: ['a', '100', 'b', '200'],
txId: tx_id,
'endorsement-policy': {
identities: [
{ role: { name: "member", mspId: "org1MSP" } },
],
policy: {
"1-of": [{ "signed-by": 0 }, { "signed-by": 1 }]
}
}
}
const resInst = await channel.sendInstantiateProposal(requestIntantiate)
console.log(resInst)
} catch (error) {
console.error(`Failed to enroll admin user "admin": ${error}`);
process.exit(1);
}
}
这是我的配置文件:https://gist.github.com/mtnieto/3442cbd5d2617fcfafcabbf13fb6953c
我该如何解决这个问题?为什么会这样?
创建交易 ID 时需要使用管理参数。
const tx_id = client.newTransactionID(true);
并使用加密生成的管理证书创建一个用户
const pathCert = path.resolve('hf-dev/hyperledgerfabrictestnet/crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/signcerts/Admin@org1.example.com-cert.pem')
const pathKey = path.resolve('hf-dev/hyperledgerfabrictestnet/crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/keystore/d52b5370d5fe1657cad43a3828978a2bebf528e838462c9236801e774229e311_sk')
let cert = fs.readFileSync(pathCert)
let pk = fs.readFileSync(pathKey)
const user = await client.createUser({
username: 'peerUser',
mspid: 'org1MSP',
cryptoContent: {
privateKeyPEM: pk.toString('utf8'),
signedCertPEM: cert.toString('utf8')
}
});
有点小错误
检查下方
var request = {
chaincodeId: this.chaincodeName,
chaincodeType: this.chaincodeType,
chaincodeVersion: this.chaincodeVersion,
args: args,
txId: tx_id,
'collections-config': collectionsConfigPath
};
你必须提到collections-config