Skip to content

Commit 2952221

Browse files
committed
feat(cactus-plugin-ledger-connector-fabric): support delegated (offline) signatures
- Add new `RunDelegatedSignTransactionEndpointV1` endpoint for delegated / offline signing. Takes `signerCertificate` and `signerMspID`, uses `signCallback` on connector to sign messages. Sign must be implemented by a user, can contain any logic (contacting 3'rd party services, reading from secure sources, etc…). Interface is similar to transact. Supports private transactions. - Refactor transact endpoint: Use common logic for handling response format. with delegated transact - Refactor logic of choosing ednorsers in transact endpoint. Previously both `endorsingPeers` and `endorsingParties` were selecting organizations in sligly different way under different circumstances. Now `endorsingPeers` selectes peers and `endorsingOrgs` selects orgs for all cases (query, send, privatesend) in both transact and transact with delegated sign. This is more consistent and predictable. - Add new socketio endpoint `SubscribeDelegatedSign` for monitoring new blocks with delegated sign. - Use common error handling in getblock, transact and transact delgated endpoints. - Add functional tests for delegated signing feature. Depends on: #2598 Signed-off-by: Michal Bajer <[email protected]>
1 parent 0f3e7e9 commit 2952221

File tree

39 files changed

+2850
-284
lines changed

39 files changed

+2850
-284
lines changed

.github/workflows/ci.yaml

+67-7
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,11 @@ jobs:
134134
uses: actions/[email protected]
135135
with:
136136
script: |
137-
const failMsg = "yarn codegen script produced version control " +
138-
"side-effects: source files have been changed by it that are " +
139-
"otherwise are under version control. " +
140-
"This means (99% of the time) that you need to run the " +
141-
"yarn codegen script locally and then include the changes it " +
137+
const failMsg = "yarn codegen script produced version control " +
138+
"side-effects: source files have been changed by it that are " +
139+
"otherwise are under version control. " +
140+
"This means (99% of the time) that you need to run the " +
141+
"yarn codegen script locally and then include the changes it " +
142142
"makes in your own commit when submitting your pull request.";
143143
core.setFailed(failMsg)
144144
@@ -1214,6 +1214,66 @@ jobs:
12141214
- run: npm run configure
12151215
- run: yarn ts-node ./packages/cactus-plugin-ledger-connector-fabric/src/test/typescript/integration/fabric-v2-2-x/run-transaction-with-ws-ids.test.ts
12161216

1217+
plugin-ledger-connector-fabric-13:
1218+
continue-on-error: false
1219+
env:
1220+
CACTI_NPM_PACKAGE_NAME: "@hyperledger/cactus-plugin-ledger-connector-fabric"
1221+
HFC_LOGGING: '{"debug":"console","info":"console","warn": "console","error":"console"}'
1222+
FULL_BUILD_DISABLED: true
1223+
JEST_TEST_PATTERN: packages/cactus-plugin-ledger-connector-fabric/src/test/typescript/(unit|integration|benchmark)/.*/*.test.ts
1224+
JEST_TEST_RUNNER_DISABLED: true
1225+
TAPE_TEST_PATTERN: ""
1226+
TAPE_TEST_RUNNER_DISABLED: true
1227+
needs: build-dev
1228+
runs-on: ubuntu-20.04
1229+
steps:
1230+
- name: Use Node.js v16.14.2
1231+
uses: actions/[email protected]
1232+
with:
1233+
node-version: v16.14.2
1234+
- uses: actions/[email protected]
1235+
1236+
- id: yarn-cache
1237+
name: Restore Yarn Cache
1238+
uses: actions/[email protected]
1239+
with:
1240+
key: ${{ runner.os }}-yarn-${{ hashFiles('./yarn.lock') }}
1241+
path: ./.yarn/
1242+
restore-keys: |
1243+
${{ runner.os }}-yarn-${{ hashFiles('./yarn.lock') }}
1244+
- run: npm run configure
1245+
- run: yarn ts-node ./packages/cactus-plugin-ledger-connector-fabric/src/test/typescript/integration/fabric-v2-2-x/delegate-signing-methods.test.ts
1246+
1247+
plugin-ledger-connector-fabric-14:
1248+
continue-on-error: false
1249+
env:
1250+
CACTI_NPM_PACKAGE_NAME: "@hyperledger/cactus-plugin-ledger-connector-fabric"
1251+
HFC_LOGGING: '{"debug":"console","info":"console","warn": "console","error":"console"}'
1252+
FULL_BUILD_DISABLED: true
1253+
JEST_TEST_PATTERN: packages/cactus-plugin-ledger-connector-fabric/src/test/typescript/(unit|integration|benchmark)/.*/*.test.ts
1254+
JEST_TEST_RUNNER_DISABLED: true
1255+
TAPE_TEST_PATTERN: ""
1256+
TAPE_TEST_RUNNER_DISABLED: true
1257+
needs: build-dev
1258+
runs-on: ubuntu-20.04
1259+
steps:
1260+
- name: Use Node.js v16.14.2
1261+
uses: actions/[email protected]
1262+
with:
1263+
node-version: v16.14.2
1264+
- uses: actions/[email protected]
1265+
1266+
- id: yarn-cache
1267+
name: Restore Yarn Cache
1268+
uses: actions/[email protected]
1269+
with:
1270+
key: ${{ runner.os }}-yarn-${{ hashFiles('./yarn.lock') }}
1271+
path: ./.yarn/
1272+
restore-keys: |
1273+
${{ runner.os }}-yarn-${{ hashFiles('./yarn.lock') }}
1274+
- run: npm run configure
1275+
- run: yarn ts-node ./packages/cactus-plugin-ledger-connector-fabric/src/test/typescript/integration/fabric-v2-2-x/fabric-watch-blocks-delegated-sign-v1-endpoint.test.ts
1276+
12171277
cactus-plugin-ledger-connector-fabric-socketio:
12181278
continue-on-error: false
12191279
env:
@@ -1608,13 +1668,13 @@ jobs:
16081668
restore-keys: |
16091669
${{ runner.os }}-yarn-${{ hashFiles('./yarn.lock') }}
16101670
- run: ./tools/ci.sh
1611-
1671+
16121672
- name: Install Foundry
16131673
uses: foundry-rs/foundry-toolchain@v1
16141674

16151675
- name: Run solidity tests
16161676
run: cd packages/cactus-plugin-htlc-eth-besu && forge test -vvvvv
1617-
1677+
16181678
cactus-test-plugin-htlc-eth-besu-erc20:
16191679
continue-on-error: false
16201680
env:

packages/cactus-plugin-ledger-connector-fabric/README.md

+43
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
- [1.5 Monitoring new blocks (WatchBlocks)](#15-monitoring-new-blocks-watchblocks)
1414
- [1.5.1 Example](#151-example)
1515
- [1.5.2 Listener Type](#152-listener-type)
16+
- [1.6 Delegated Signature](#16-delegated-signature)
17+
- [1.6.1 Example](#161-example)
1618
- [2. Architecture](#2-architecture)
1719
- [2.1. run-transaction-endpoint](#21-run-transaction-endpoint)
1820
- [3. Containerization](#3-containerization)
@@ -329,6 +331,47 @@ Corresponds directly to `BlockType` from `fabric-common`:
329331
- `WatchBlocksListenerTypeV1.Full`,
330332
- `WatchBlocksListenerTypeV1.Private`,
331333

334+
### 1.6 Delegated Signature
335+
- Custom signature callback can be used when increased security is needed or currently available options are not sufficient.
336+
- Signature callback is used whenever fabric request must be signed.
337+
- To use delegate signature instead of identity supplied directly / through keychain use `transactDelegatedSign` (for transact) or `watchBlocksDelegatedSignV1` for block monitoring.
338+
- `uniqueTransactionData` can be passed to each delegate sign method on connector. This data is passed to signCallback to identify and verify the request. It can be used to pass signing tokens or any other data needed for performing the signing (e.g. user, scopes, etc...).
339+
- `signProposal` method from this package can be used to sign the requests in offline location.
340+
- For more complex examples see tests: `delegate-signing-methods.test` and `fabric-watch-blocks-delegated-sign-v1-endpoint.test`.
341+
342+
#### 1.6.1 Example
343+
```typescript
344+
// Setup - supply callback when instantiating the connector plugin
345+
fabricConnectorPlugin = new PluginLedgerConnectorFabric({
346+
instanceId: uuidv4(),
347+
// ...
348+
signCallback: async (payload, txData) => {
349+
log.debug("signCallback called with txData (token):", txData);
350+
return signProposal(adminIdentity.credentials.privateKey, payload);
351+
},
352+
});
353+
354+
// Run transactions
355+
await apiClient.runDelegatedSignTransactionV1({
356+
signerCertificate: adminIdentity.credentials.certificate,
357+
signerMspID: adminIdentity.mspId,
358+
channelName: ledgerChannelName,
359+
contractName: assetTradeContractName,
360+
invocationType: FabricContractInvocationType.Call,
361+
methodName: "ReadAsset",
362+
params: ["asset1"],
363+
uniqueTransactionData: myJwtToken,
364+
});
365+
366+
// Monitor for transactions:
367+
apiClient.watchBlocksDelegatedSignV1({
368+
type: WatchBlocksListenerTypeV1.CactusTransactions,
369+
signerCertificate: adminIdentity.credentials.certificate,
370+
signerMspID: adminIdentity.mspId,
371+
channelName: ledgerChannelName,
372+
})
373+
```
374+
332375
##### Cactus (custom)
333376
Parses the data and returns custom formatted block.
334377
- `WatchBlocksListenerTypeV1.CactusTransactions`: Returns transactions summary. Compatible with legacy `fabric-socketio` monitoring operation.

packages/cactus-plugin-ledger-connector-fabric/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
"node-vault": "0.9.22",
7878
"openapi-types": "9.1.0",
7979
"prom-client": "13.2.0",
80+
"run-time-error": "1.4.0",
8081
"rxjs": "7.8.1",
8182
"sanitize-filename": "1.6.3",
8283
"sanitize-html": "2.7.0",

0 commit comments

Comments
 (0)