Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
.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();
const signer = new Signer(cryptoUtils, testKey);
t.equal(signer.getPublicKey().isPrivate(), false, 'Test Signer class getPublicKey() method');
const signingID = new SigningIdentity(TEST_KEY_PRIVATE_CERT_PEM, pubKey, mspImpl.getId(), cryptoUtils, signer);
t.throws(
() => {
signingID.sign(TEST_MSG, {hashFunction: 'not_a_function'});
},
/The "hashFunction" field must be a function/,
'Test invalid hashFunction parameter for the sign() method'
);
const sig = signingID.sign(TEST_MSG);
t.equal(cryptoUtils.verify(pubKey, sig, TEST_MSG), true, 'Test SigningIdentity sign() method');
t.equal(signingID.verify(TEST_MSG, sig), true, 'Test Identity verify() method');
t.end();
}).then((pubKey) => {
t.pass('Successfully imported public key from the resulting enrollment certificate');
const cryptoSuite = caService.getCryptoSuite();
const id = ORGS[userOrg].mspid;
signingIdentity = new SigningIdentity(eResult.certificate, pubKey, id, cryptoSuite, new Signer(cryptoSuite, eResult.key));
return timeOutTest(signingIdentity, t);
}, (err) => {
t.fail('Failed to import the public key from the enrollment certificate. ' + err.stack ? err.stack : err);
() => {
new Signer('blah');
},
/Missing required parameter "key" for private key/,
throw new Error('Invalid parameter. Must have a valid private key.');
}
if (typeof certificate === 'undefined' || certificate === null || certificate === '') {
throw new Error('Invalid parameter. Must have a valid certificate.');
}
if (typeof mspid === 'undefined' || mspid === null || mspid === '') {
throw new Error('Invalid parameter. Must have a valid mspid.');
}
let crypto_suite = this.getCryptoSuite();
if (!crypto_suite) {
crypto_suite = BaseClient.newCryptoSuite();
}
const key = await crypto_suite.createKeyFromRaw(private_key);
const public_key = await crypto_suite.createKeyFromRaw(certificate);
this._adminSigningIdentity = new SigningIdentity(certificate, public_key, mspid, crypto_suite, new Signer(crypto_suite, key));
}