How to use the fabric-common.HashPrimitives.SHA2_256 function in fabric-common

To help you get started, we’ve selected a few fabric-common examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github hyperledger / fabric-sdk-node / fabric-client / lib / TransactionID.js View on Github external
constructor(signer_or_userContext, admin) {
		logger.debug('constructor - start');
		if (!signer_or_userContext) {
			throw new Error('Missing userContext or signing identity parameter');
		}
		let signer = null;
		if ((User.isInstance(signer_or_userContext))) {
			signer = signer_or_userContext.getSigningIdentity();
		} else {
			signer = signer_or_userContext;
		}

		this._nonce = utils.getNonce(); // nonce is in bytes
		const creator_bytes = signer.serialize();// same as signatureHeader.Creator
		const trans_bytes = Buffer.concat([this._nonce, creator_bytes]);
		const trans_hash = HashPrimitives.SHA2_256(trans_bytes);
		this._transaction_id = Buffer.from(trans_hash).toString();
		logger.debug('const - transaction_id %s', this._transaction_id);

		this._admin = admin;
	}
github hyperledger / fabric-sdk-node / fabric-client / lib / Remote.js View on Github external
getClientCertHash() {
		if (this.clientCert) {
			const der_cert = utils.pemToDER(this.clientCert);
			return HashPrimitives.SHA2_256(der_cert, null /* We need a Buffer */);
		} else {
			return null;
		}
	}
github hyperledger / fabric-sdk-node / fabric-client / lib / TokenClient.js View on Github external
if (!request) {
			throw new Error(util.format('Missing input request parameter on the %s call', method));
		}
		if (!request.tokenTransaction) {
			throw new Error(util.format('Missing required "tokenTransaction" in request on the %s call', method));
		}
		if (!request.tokenCommand) {
			throw new Error(util.format('Missing required "tokenCommand" in request on the %s call', method));
		}
		if (!request.tokenCommand.header) {
			throw new Error(util.format('Missing required "header" in tokenCommand on the %s call', method));
		}

		const commandHeader = request.tokenCommand.header;
		const trans_bytes = Buffer.concat([commandHeader.nonce.toBuffer(), commandHeader.creator.toBuffer()]);
		const trans_hash = HashPrimitives.SHA2_256(trans_bytes);
		const txId = Buffer.from(trans_hash).toString();

		const channel_header = clientUtils.buildChannelHeader(
			fabprotos.common.HeaderType.TOKEN_TRANSACTION,
			this._channel._name,
			txId,
			null, // no epoch
			'',
			clientUtils.buildCurrentTimestamp(),
			this._client.getClientCertHash()
		);

		const signature_header = new fabprotos.common.SignatureHeader();
		signature_header.setCreator(commandHeader.creator);
		signature_header.setNonce(commandHeader.nonce);