Skip to content

Commit

Permalink
feat(connector-fabric): signing credentials for fabric
Browse files Browse the repository at this point in the history
Signed-off-by: AzaharaC <a.castano.benito@accenture.com>
  • Loading branch information
AzaharaC authored and petermetz committed Mar 16, 2021
1 parent 438dcda commit ebfff9f
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,27 @@
],
"components": {
"schemas": {
"FabricSigningCredential": {
"type": "object",
"required": [
"keychainId",
"keychainRef"
],
"properties": {
"keychainId": {
"type": "string",
"minLength": 1,
"maxLength": 100,
"nullable": false
},
"keychainRef": {
"type": "string",
"minLength": 1,
"maxLength": 100,
"nullable": false
}
}
},
"ConnectionProfile": {
"type": "object",
"required": [
Expand Down Expand Up @@ -195,25 +216,16 @@
"RunTransactionRequest": {
"type": "object",
"required": [
"keychainId",
"keychainRef",
"fabricSigningCredential",
"channelName",
"chainCodeId",
"invocationType",
"functionName",
"functionArgs"
],
"properties": {
"keychainId": {
"type": "string",
"minLength": 1,
"maxLength": 100,
"nullable": false
},
"keychainRef": {
"type": "string",
"minLength": 1,
"maxLength": 100,
"fabricSigningCredential": {
"$ref": "#/components/schemas/FabricSigningCredential",
"nullable": false
},
"channelName": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,25 @@ export enum FabricContractInvocationType {
CALL = 'FabricContractInvocationType.CALL'
}

/**
*
* @export
* @interface FabricSigningCredential
*/
export interface FabricSigningCredential {
/**
*
* @type {string}
* @memberof FabricSigningCredential
*/
keychainId: string;
/**
*
* @type {string}
* @memberof FabricSigningCredential
*/
keychainRef: string;
}
/**
* Represents a file-system file that has a name and a body which holds the file contents as a Base64 encoded string
* @export
Expand Down Expand Up @@ -355,16 +374,10 @@ export interface InlineResponse501 {
export interface RunTransactionRequest {
/**
*
* @type {string}
* @type {FabricSigningCredential}
* @memberof RunTransactionRequest
*/
keychainId: string;
/**
*
* @type {string}
* @memberof RunTransactionRequest
*/
keychainRef: string;
fabricSigningCredential: FabricSigningCredential;
/**
*
* @type {string}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -439,8 +439,7 @@ export class PluginLedgerConnectorFabric

const { connectionProfile } = this.opts;
const {
keychainId,
keychainRef,
fabricSigningCredential,
channelName,
chainCodeId,
invocationType,
Expand All @@ -450,15 +449,25 @@ export class PluginLedgerConnectorFabric

const gateway = new Gateway();
const wallet = new InMemoryWallet(new X509WalletMixin());
const keychain = this.opts.pluginRegistry.findOneByKeychainId(keychainId);
this.log.debug("transact() obtained keychain by ID=%o OK", keychainId);
const keychain = this.opts.pluginRegistry.findOneByKeychainId(
fabricSigningCredential.keychainId,
);
this.log.debug(
"transact() obtained keychain by ID=%o OK",
fabricSigningCredential.keychainId,
);

const fabricX509IdentityJson = await keychain.get<string>(keychainRef);
this.log.debug("transact() obtained keychain entry Key=%o OK", keychainRef);
const fabricX509IdentityJson = await keychain.get<string>(
fabricSigningCredential.keychainRef,
);
this.log.debug(
"transact() obtained keychain entry Key=%o OK",
fabricSigningCredential.keychainRef,
);
const identity = JSON.parse(fabricX509IdentityJson);

try {
await wallet.import(keychainRef, identity);
await wallet.import(fabricSigningCredential.keychainRef, identity);
this.log.debug("transact() imported identity to in-memory wallet OK");

const eventHandlerOptions: DefaultEventHandlerOptions = {
Expand All @@ -474,7 +483,7 @@ export class PluginLedgerConnectorFabric
const gatewayOptions: GatewayOptions = {
discovery: this.opts.discoveryOptions,
eventHandlerOptions,
identity: keychainRef,
identity: fabricSigningCredential.keychainRef,
wallet,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ import {

import { HELLO_WORLD_CONTRACT_GO_SOURCE } from "../../../fixtures/go/hello-world-contract-fabric-v14/hello-world-contract-go-source";

import { DefaultApi as FabricApi } from "../../../../../main/typescript/public-api";
import {
DefaultApi as FabricApi,
FabricSigningCredential,
} from "../../../../../main/typescript/public-api";

import { IPluginLedgerConnectorFabricOptions } from "../../../../../main/typescript/plugin-ledger-connector-fabric";

Expand Down Expand Up @@ -174,15 +177,18 @@ test("deploys contract from go source", async (t: Test) => {

const testKey = uuidv4();
const testValue = uuidv4();
const fabricSigningCredential: FabricSigningCredential = {
keychainId,
keychainRef: keychainEntryKey,
};

const setRes = await apiClient.runTransactionV1({
chainCodeId: "hello-world",
channelName: "mychannel",
functionArgs: [testKey, testValue],
functionName: "set",
invocationType: FabricContractInvocationType.SEND,
keychainId,
keychainRef: keychainEntryKey,
fabricSigningCredential,
});
t.ok(setRes, "setRes truthy OK");
t.true(setRes.status > 199 && setRes.status < 300, "setRes status 2xx OK");
Expand All @@ -194,8 +200,7 @@ test("deploys contract from go source", async (t: Test) => {
functionArgs: [testKey],
functionName: "get",
invocationType: FabricContractInvocationType.CALL,
keychainId,
keychainRef: keychainEntryKey,
fabricSigningCredential,
});
t.ok(getRes, "getRes truthy OK");
t.true(getRes.status > 199 && setRes.status < 300, "getRes status 2xx OK");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
RunTransactionRequest,
FabricContractInvocationType,
DefaultEventHandlerStrategy,
FabricSigningCredential,
} from "../../../../main/typescript/public-api";

import { IPluginLedgerConnectorFabricOptions } from "../../../../main/typescript/plugin-ledger-connector-fabric";
Expand Down Expand Up @@ -124,11 +125,14 @@ test("runs tx on a Fabric v1.4.8 ledger", async (t: Test) => {

const carId = "CAR277";
const carOwner = uuidv4();
const fabricSigningCredential: FabricSigningCredential = {
keychainId,
keychainRef: keychainEntryKey,
};

{
const res = await apiClient.runTransactionV1({
keychainId,
keychainRef: keychainEntryKey,
fabricSigningCredential,
channelName: "mychannel",
chainCodeId: "fabcar",
invocationType: FabricContractInvocationType.CALL,
Expand All @@ -143,8 +147,7 @@ test("runs tx on a Fabric v1.4.8 ledger", async (t: Test) => {

{
const req: RunTransactionRequest = {
keychainId,
keychainRef: keychainEntryKey,
fabricSigningCredential,
channelName: "mychannel",
invocationType: FabricContractInvocationType.SEND,
chainCodeId: "fabcar",
Expand All @@ -159,8 +162,7 @@ test("runs tx on a Fabric v1.4.8 ledger", async (t: Test) => {
}
{
const res = await apiClient.runTransactionV1({
keychainId,
keychainRef: keychainEntryKey,
fabricSigningCredential,
channelName: "mychannel",
chainCodeId: "fabcar",
invocationType: FabricContractInvocationType.CALL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
RunTransactionRequest,
FabricContractInvocationType,
DefaultEventHandlerStrategy,
FabricSigningCredential,
} from "../../../../main/typescript/public-api";

import { IPluginLedgerConnectorFabricOptions } from "../../../../main/typescript/plugin-ledger-connector-fabric";
Expand Down Expand Up @@ -141,10 +142,13 @@ test("runs tx on a Fabric v2.2.0 ledger", async (t: Test) => {

const channelName = "mychannel";
const chainCodeId = "basic";
const fabricSigningCredential: FabricSigningCredential = {
keychainId,
keychainRef: keychainEntryKey,
};
{
const res = await apiClient.runTransactionV1({
keychainId,
keychainRef: keychainEntryKey,
fabricSigningCredential,
channelName,
chainCodeId,
invocationType: FabricContractInvocationType.CALL,
Expand All @@ -158,8 +162,7 @@ test("runs tx on a Fabric v2.2.0 ledger", async (t: Test) => {
}
{
const req: RunTransactionRequest = {
keychainId,
keychainRef: keychainEntryKey,
fabricSigningCredential,
channelName,
invocationType: FabricContractInvocationType.SEND,
chainCodeId,
Expand All @@ -175,8 +178,7 @@ test("runs tx on a Fabric v2.2.0 ledger", async (t: Test) => {

{
const res = await apiClient.runTransactionV1({
keychainId,
keychainRef: keychainEntryKey,
fabricSigningCredential,
channelName,
chainCodeId,
invocationType: FabricContractInvocationType.CALL,
Expand Down

0 comments on commit ebfff9f

Please sign in to comment.