Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for v1 connectors with wallets #1029

Merged
merged 3 commits into from
Oct 5, 2020

Conversation

RosieMurphy0
Copy link
Contributor

Signed-off-by: RosieMurphy0 [email protected]

Adds support for v1 connectors through 2 files: WalletFacade and WalletFacadeFactory.

Contributes to #940

* @param {string} privateKey The identity private key
*/
async import(mspId, identityName, certificate, privateKey) {
const exists = await this.wallet.export(identityName);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is an exists call on the wallet that would be better just in case export throws an error if not found

const exists = await this.wallet.exists(identityName)

* @returns {[string]} all the identity names in the wallet
*/
async getAllIdentityNames() {
return await this.wallet.list();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the case of a v1 wallet, this.wallet.list doesn't return the list of identity names. It returns a list of IdentityInfo objects. The getAllLabels api should return just a list of identity names which is what we need.

* @param {[string]} walletPath optional path to a file system wallet
*/
async create(walletPath) {
const walletFacade = new WalletFacade();
Copy link
Contributor

@davidkel davidkel Oct 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that intiialize is not required, this can be simplified to

    async create(walletPath) {

        return new WalletFacade(walletPath);
    }

chai.should();
const mockery = require('mockery');

/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove comment

* simulate a node sdk v1 wallet
*/
class StubWallet {
/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove comment

this.map = new Map();
}

/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove comment

this.map.set(key, value);
}

/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove comment

}

/**
*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove comment

return this.map.get(key);
}

/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove comment

/**
*
*/
async list() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change this from list to getAllLabels as that api is the one we want to be using in the real wallet

}
}

/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove comments

*/
class InMemoryWallet extends StubWallet {}

/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove comment

async export(identityName) {
const exported = await this.wallet.export(identityName);
if (exported) {
return new ExportedIdentity(exported.mspid, exported.credentials.cert, exported.credentials.key);
Copy link
Contributor

@davidkel davidkel Oct 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a v1 wallet the format returned by the export is

{
  mspId,
  certificate,
  privateKey
}

So this line should read

return new ExportedIdentity(exported.mspId, exported.certificate, exported.privateKey);

*/
class FileSystemWallet extends StubWallet {}

/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove comment

* x509walletmixin class
*/
class X509WalletMixin {
/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove comment

* @param {*} key b
* @return {*} identity b
*/
static createIdentity(mspid, cert, key){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code from createIdentity can be almost directly copied from the 1.4 node sdk which is

	static createIdentity(mspId, certificate, privateKey) {
		logger.debug('in createIdentity: mspId = ' + mspId);
		return {
			type: 'X509',
			mspId,
			certificate,
			privateKey
		};
	}

just remove the logger.debug line


describe('When testing a V1 Wallet Facade Implementation', () => {

beforeEach(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't need this as a beforeEach, so can be removed

mockery.registerMock('fabric-network', {FileSystemWallet, InMemoryWallet, X509WalletMixin});
});

afterEach(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change this from afterEach to after by doing this it means the beforeEach can be removed

mockery.deregisterAll();
mockery.disable();
});
it('A Wallet Facade Factory should create a wallet facade', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs a new line before the it statement

const exported = await walletFacade.export('label');
exported.should.deep.equal({mspid: 'mspid', certificate: 'cert', privateKey: 'key'});
});

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to add this test in as well to the v2 tests so could you add this extra test in here as well

    it('A wallet facade should return null on export if the identity does not exist', async () => {
        const walletFacade = await new WalletFacadeFactory().create();
        const exported = await walletFacade.export('label');
        should.equal(exported, null);
    });

Copy link
Contributor

@davidkel davidkel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, I have made some comments, hopefully they make sense.

async export(identityName) {
const exported = await this.wallet.export(identityName);
if (exported) {
return new ExportedIdentity(exported.mspId, exported.credentials.certificate, exported.credentials.privateKey);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The information in exported is not in the format you are expecting here. If you look at the code for createIdentity in node-sdk 1.4 X509Wallet looks like this

	static createIdentity(mspId, certificate, privateKey) {
		return {
			type: 'X509',
			mspId,
			certificate,
			privateKey
		};
	}

You can ignore the type property but you see there is no credentials property.

class FileSystemWallet extends StubWallet {}

class X509WalletMixin {
static createIdentity(mspId, certificate, privateKey){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should match the 1.4 implementation, as shown in the comment above

Copy link
Contributor

@davidkel davidkel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, still some changes required.

Copy link
Contributor

@davidkel davidkel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@davidkel davidkel merged commit 4a3ed4e into hyperledger-caliper:master Oct 5, 2020
danielporto pushed a commit to danielporto/caliper that referenced this pull request Nov 3, 2020
* added wallet support for the v1 connectors

Signed-off-by: RosieMurphy0 <[email protected]>

* added wallet support for the v1 connectors

Signed-off-by: RosieMurphy0 <[email protected]>

* added wallet support for the v1 connectors

Signed-off-by: RosieMurphy0 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants