Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
t.notEqual(msp._intermediateCerts, null, 'Check loaded MSP instance for intermediateCerts');
}
}
// test deserialization using the msp manager
const cryptoUtils = utils.newCryptoSuite();
cryptoUtils.setCryptoKeyStore(utils.newCryptoKeyStore());
const mspImpl = new MSP({
rootCerts: [],
admins: [],
id: 'peerOrg0',
cryptoSuite: cryptoUtils
});
const pubKey = cryptoUtils.importKey(TEST_CERT_PEM);
let identity = new Identity(TEST_CERT_PEM, pubKey, mspImpl.getId(), cryptoUtils);
const serializedID = identity.serialize();
identity = await mspm.deserializeIdentity(serializedID);
t.equal(identity.getMSPId(), 'peerOrg0', 'Deserialized identity using MSP manager');
t.equal(mspm.getMSP('peerOrg0').getId(), 'peerOrg0', 'Checking MSPManager getMSP() method');
t.end();
});
'Checking required input parameters'
);
const cryptoUtils = utils.newCryptoSuite();
cryptoUtils.setCryptoKeyStore(utils.newCryptoKeyStore());
// test identity serialization and deserialization
const mspImpl = new MSP({
rootCerts: [],
admins: [],
id: 'testMSP',
cryptoSuite: cryptoUtils
});
let pubKey = cryptoUtils.importKey(TEST_CERT_PEM, {algorithm: CryptoAlgorithms.X509Certificate});
const identity = new Identity(TEST_CERT_PEM, pubKey, mspImpl.getId(), cryptoUtils);
const serializedID = identity.serialize();
// deserializeIdentity should work both ways ... with promise and without
const identity_g = mspImpl.deserializeIdentity(serializedID, false);
t.equals(identity_g.getMSPId(), 'testMSP', 'deserializeIdentity call without promise');
mspImpl.deserializeIdentity(serializedID)
.then((dsID) => {
t.equal(dsID._certificate, TEST_CERT_PEM, 'Identity class function tests: deserialized certificate');
t.equal(dsID._publicKey.isPrivate(), false, 'Identity class function tests: deserialized public key');
t.equal(dsID._publicKey._key.pubKeyHex, '0452a75e1ee105da7ab3d389fda69d8a04f5cf65b305b49cec7cdbdeb91a585cf87bef5a96aa9683d96bbabfe60d8cc6f5db9d0bc8c58d56bb28887ed81c6005ac', 'Identity class function tests: deserialized public key ecparam check');
// manually construct a key based on the saved privKeyHex and pubKeyHex
const f = KEYUTIL.getKey(TEST_KEY_PRIVATE_PEM);
const testKey = new ecdsaKey(f);
pubKey = testKey.getPublicKey();
if (request.commandName === 'issue') {
tokenCommand = tokenUtils.buildIssueCommand(request);
} else if (request.commandName === 'transfer') {
tokenCommand = tokenUtils.buildTransferCommand(request);
} else if (request.commandName === 'redeem') {
tokenCommand = tokenUtils.buildRedeemCommand(request);
} else if (request.commandName === 'list') {
tokenCommand = tokenUtils.buildListCommand(request);
} else if (!request.commandName) {
throw new Error(utils.format('Missing commandName on the %s call', method));
} else {
throw new Error(utils.format('Invalid commandName (%s) on the %s call', request.commandName, method));
}
// create identity using certificate, publicKey (null), and mspId
const identity = new Identity(certificate, null, mspId);
const txId = new TransactionID(identity, admin);
const header = tokenUtils.buildTokenCommandHeader(
identity,
this._channel._name,
txId.getNonce(),
this._client.getClientCertHash()
);
tokenCommand.setHeader(header);
return tokenCommand;
}
const { endorsement } = proposalResponse;
let identity;
const sid = fabproto6.msp.SerializedIdentity.decode(endorsement.endorser);
const { mspid } = sid;
logger.debug("getMSPbyIdentity - found mspid %s", mspid);
try {
const idCryptoSuite = FabCommon.Utils.newCryptoSuite();
idCryptoSuite.setCryptoKeyStore(FabCommon.Utils.newCryptoKeyStore());
const idPubKey = await idCryptoSuite.importKey(sid.id_bytes.toString(), {
// algorithm: FabCommon.CryptoAlgorithms.X509Certificate,
ephemeral: true,
});
identity = new Identity(sid.id_bytes, idPubKey, sid.mspid, idCryptoSuite);
if (!identity) {
throw new Error("Unable to find the remote endorser identity");
}
} catch (error) {
logger.error("verifyDecryptedRemoteProposalResponse - getting remote endorser identity failed with: ", error);
return false;
}
try {
// see if the identity is trusted
if (!identity.isValid()) {
logger.error("Endorser identity is not valid");
return false;
}
logger.debug("verifyDecryptedRemoteProposalResponse - have a valid identity");
if (certificate || mspId) {
certificate = null;
mspId = null;
}
}
if (certificate || mspId) {
if (!certificate) {
throw new Error('"options.certificate" is required to generate unsigned fabric service registration');
}
if (!mspId) {
throw new Error('"options.mspId" is required to generate unsigned fabric service registration');
}
}
if (!identity) {
identity = new Identity(certificate, null, mspId);
txId = new TransactionID(identity, options.admin === true);
}
// The behavior when a missing block is encountered
let behavior = fabprotos.orderer.SeekInfo.SeekBehavior.BLOCK_UNTIL_READY;
// build start
const seekStart = new fabprotos.orderer.SeekPosition();
if (!this._starting_block_number || this._starting_block_number === NEWEST) {
const seekNewest = new fabprotos.orderer.SeekNewest();
seekStart.setNewest(seekNewest);
} else if (this._starting_block_number === OLDEST) {
const seekOldest = new fabprotos.orderer.SeekOldest();
seekStart.setOldest(seekOldest);
} else if (this._starting_block_number) {
const seekSpecifiedStart = new fabprotos.orderer.SeekSpecified();
() => {
new Identity('cert', 'pubKey');
},
/Missing required parameter "mspId"/,