-
Notifications
You must be signed in to change notification settings - Fork 516
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FAB-3568] NodeSDK - Remove nonce requirement
Autogenerate the generate the nonce and the txId at the same time and return both in a "TransactionID" object. Users will be able to have a transaction value to be used for tracking and SDK will be able to provide the correct 'nonce' for the transaction id. Remove all user API referrences to the 'nonce' and update all test cases required. Change-Id: I6429733c1ee7ecae642f6cd3b0518b3cbddd1691 Signed-off-by: Bret Harrison <[email protected]>
- Loading branch information
Showing
23 changed files
with
463 additions
and
535 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
Copyright 2017 IBM All Rights Reserved. | ||
Licensed under the Apache License, Version 2.0 (the 'License'); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an 'AS IS' BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
var sdkUtils = require('./utils.js'); | ||
var logger = sdkUtils.getLogger('TransactionID.js'); | ||
var User = require('./User.js'); | ||
var hashPrimitives = require('./hash.js'); | ||
|
||
|
||
/** | ||
* The class representing the transaction identifier. Provides for | ||
* automatically creating the `nonce` value when an instance of this | ||
* object is created. | ||
* | ||
* @class | ||
*/ | ||
var TransactionID = class { | ||
|
||
/** | ||
* Builds a new tranaction Id based on a user's certificate and an automatically | ||
* generated nonce value. | ||
* @param {Client} clientContext An instance of {@link Client} that provides an unique | ||
* base for this transaction id. | ||
*/ | ||
constructor(userContext) { | ||
logger.debug('const - start'); | ||
if (typeof userContext === 'undefined' || userContext === null) { | ||
throw new Error('Missing userContext parameter'); | ||
} | ||
if(!(userContext instanceof User)) { | ||
throw new Error('Parameter "userContext" must be an instance of the "User" class'); | ||
} | ||
this._nonce = sdkUtils.getNonce(); //nonce is in bytes | ||
let creator_bytes = userContext.getIdentity().serialize();//same as signatureHeader.Creator | ||
let trans_bytes = Buffer.concat([this._nonce, creator_bytes]); | ||
let trans_hash = hashPrimitives.sha2_256(trans_bytes); | ||
this._transaction_id = Buffer.from(trans_hash).toString(); | ||
logger.debug('const - transaction_id %s',this._transaction_id); | ||
} | ||
|
||
/** | ||
* The transaction ID | ||
*/ | ||
getTransactionID() { | ||
return this._transaction_id; | ||
} | ||
|
||
/** | ||
* The nonce value | ||
*/ | ||
getNonce() { | ||
return this._nonce; | ||
} | ||
}; | ||
|
||
module.exports = TransactionID; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.