mirror of
https://github.com/hyperledger/fabric-samples.git
synced 2026-06-25 19:15:10 +00:00
application-typescript code refactor
Signed-off-by: sapthasurendran <saptha.surendran@ibm.com>
This commit is contained in:
parent
318b4cc250
commit
efeb603139
1 changed files with 24 additions and 21 deletions
|
|
@ -27,34 +27,37 @@ const peerEndpoint = 'localhost:7051';
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
console.log('\nRunning the Node HSM sample');
|
console.log('\nRunning the Node HSM sample');
|
||||||
|
let client;
|
||||||
// The gRPC client connection should be shared by all Gateway connections to this endpoint
|
let gateway;
|
||||||
const client = await newGrpcConnection();
|
let hsmSignerFactory;
|
||||||
|
let hsmSigner;
|
||||||
// get an HSMSigner Factory. You only need to do this once for the application
|
|
||||||
const hsmSignerFactory = signers.newHSMSignerFactory(findSoftHSMPKCS11Lib());
|
|
||||||
const credentials = await fs.promises.readFile(certPath);
|
|
||||||
|
|
||||||
// Get the signer function and a close function. The close function closes the signer
|
|
||||||
// once there is no further need for it.
|
|
||||||
const {signer, close} = await newHSMSigner(hsmSignerFactory, credentials.toString());
|
|
||||||
|
|
||||||
const gateway = connect({
|
|
||||||
client,
|
|
||||||
identity: {mspId, credentials},
|
|
||||||
signer,
|
|
||||||
});
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
// The gRPC client connection should be shared by all Gateway connections to this endpoint
|
||||||
|
client = await newGrpcConnection();
|
||||||
|
|
||||||
|
// get an HSMSigner Factory. You only need to do this once for the application
|
||||||
|
hsmSignerFactory = signers.newHSMSignerFactory(findSoftHSMPKCS11Lib());
|
||||||
|
const credentials = await fs.promises.readFile(certPath);
|
||||||
|
|
||||||
|
// Get the signer function and a close function. The close function closes the signer
|
||||||
|
// once there is no further need for it.
|
||||||
|
hsmSigner = await newHSMSigner(hsmSignerFactory, credentials.toString());
|
||||||
|
gateway = connect({
|
||||||
|
client,
|
||||||
|
identity: { mspId, credentials },
|
||||||
|
signer:hsmSigner.signer,
|
||||||
|
});
|
||||||
|
|
||||||
await exampleTransaction(gateway);
|
await exampleTransaction(gateway);
|
||||||
console.log();
|
console.log();
|
||||||
console.log('Node HSM sample completed successfully');
|
console.log('Node HSM sample completed successfully');
|
||||||
} finally {
|
} finally {
|
||||||
gateway.close();
|
gateway?.close();
|
||||||
client.close();
|
client?.close();
|
||||||
|
hsmSignerFactory?.dispose();
|
||||||
// close the HSM Signer
|
// close the HSM Signer
|
||||||
close();
|
hsmSigner?.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue