Skip to content

Commit

Permalink
Merge pull request #36 from identity-com/issues/CCS-582_injection_of_…
Browse files Browse the repository at this point in the history
…secure_random

Changing injection of SecureRandom
  • Loading branch information
dmelosantos authored Nov 22, 2018
2 parents 64169c2 + e10f93f commit 2bddd9b
Show file tree
Hide file tree
Showing 12 changed files with 40 additions and 54 deletions.
2 changes: 1 addition & 1 deletion dist/browser/creds/VerifiableCredential.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/browser/services/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/browser/uca/UserCollectableAttribute.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 9 additions & 12 deletions dist/cjs/creds/VerifiableCredential.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@ const definitions = require('./definitions');
const UCA = require('../uca/UserCollectableAttribute');
const { services } = require('../services');

const secureRandom = services.container.SecureRandom;

function getAnchorService() {
return services.container.AnchorService;
}

function sha256(string) {
return sjcl.codec.hex.fromBits(sjcl.hash.sha256.hash(string));
}
Expand Down Expand Up @@ -164,6 +158,7 @@ class CvcMerkleProof {
const currentLength = nodes.length;
const targetLength = currentLength < CvcMerkleProof.PADDING_INCREMENTS ? CvcMerkleProof.PADDING_INCREMENTS : _.ceil(currentLength / CvcMerkleProof.PADDING_INCREMENTS) * CvcMerkleProof.PADDING_INCREMENTS;
const newNodes = _.clone(nodes);
const secureRandom = services.container.SecureRandom;
while (newNodes.length < targetLength) {
newNodes.push(new UCA('cvc:Random:node', secureRandom.wordWith(16)));
}
Expand Down Expand Up @@ -279,7 +274,8 @@ function VerifiableCredentialBaseConstructor(identifier, issuer, expiryIn, ucas,
*/
this.requestAnchor = (() => {
var _ref = _asyncToGenerator(function* (options) {
const anchor = yield getAnchorService().anchor(_this.identifier, _this.proof.merkleRoot, options);
const anchorService = services.container.AnchorService;
const anchor = yield anchorService.anchor(_this.identifier, _this.proof.merkleRoot, options);
_this.proof.anchor = anchor;
return _this;
});
Expand All @@ -294,7 +290,8 @@ function VerifiableCredentialBaseConstructor(identifier, issuer, expiryIn, ucas,
* already confirmed on the blockchain.
*/
this.updateAnchor = _asyncToGenerator(function* () {
const anchor = yield getAnchorService().update(_this.proof.anchor);
const anchorService = services.container.AnchorService;
const anchor = yield anchorService.update(_this.proof.anchor);
_this.proof.anchor = anchor;
return _this;
});
Expand Down Expand Up @@ -384,30 +381,30 @@ function VerifiableCredentialBaseConstructor(identifier, issuer, expiryIn, ucas,
* @return true or false for the validation
*/
this.verifySignature = _asyncToGenerator(function* () {
return getAnchorService().verifySignature(_this.proof);
return services.container.AnchorService.verifySignature(_this.proof);
});

/**
* This method checks that the attestation / anchor exists on the BC
*/
this.verifyAttestation = _asyncToGenerator(function* () {
return getAnchorService().verifyAttestation(_this.proof);
return services.container.AnchorService.verifyAttestation(_this.proof);
});

/**
* This method will revoke the attestation on the chain
* @returns {Promise<Promise<*>|void>}
*/
this.revokeAttestation = _asyncToGenerator(function* () {
return getAnchorService().revokeAttestation(_this.proof);
return services.container.AnchorService.revokeAttestation(_this.proof);
});

/**
* This method will check on the chain the balance of the transaction and if it's still unspent, than it's not revoked
* @returns {Promise<Promise<*>|void>}
*/
this.isRevoked = _asyncToGenerator(function* () {
return getAnchorService().isRevoked(_this.proof);
return services.container.AnchorService.isRevoked(_this.proof);
});

this.isMatch = constraints => {
Expand Down
2 changes: 1 addition & 1 deletion dist/cjs/services/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ services.factory('Config', () => config);
logger.info('Registering request-promise-native as Http service implementation.');
services.service('Http', HttpServiceConstructor);

services.service('SecureRandom', SecureRandom);
services.factory('SecureRandom', () => new SecureRandom());

services.service('AnchorService', CurrentCivicAnchor, 'Config', 'Http');

Expand Down
Loading

0 comments on commit 2bddd9b

Please sign in to comment.