Skip to content

Commit b95183c

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 b95183c

File tree

40 files changed

+2794
-284
lines changed

40 files changed

+2794
-284
lines changed

.cspell.json

+4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
"cafile",
2222
"caio",
2323
"cccs",
24+
"ccep",
25+
"cccg",
2426
"cbdc",
2527
"Cbdc",
2628
"ccid",
@@ -64,6 +66,7 @@
6466
"HTLC",
6567
"Hursley",
6668
"HyperLedger",
69+
"immalleable",
6770
"ipaddress",
6871
"ipfs",
6972
"Iroha",
@@ -86,6 +89,7 @@
8689
"miekg",
8790
"mitchellh",
8891
"MSPCONFIGPATH",
92+
"Mspids",
8993
"MSPID",
9094
"MSPIDSCOPEALLFORTX",
9195
"MSPIDSCOPEANYFORTX",

.github/workflows/ci.yaml

+7-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
@@ -1608,13 +1608,13 @@ jobs:
16081608
restore-keys: |
16091609
${{ runner.os }}-yarn-${{ hashFiles('./yarn.lock') }}
16101610
- run: ./tools/ci.sh
1611-
1611+
16121612
- name: Install Foundry
16131613
uses: foundry-rs/foundry-toolchain@v1
16141614

16151615
- name: Run solidity tests
16161616
run: cd packages/cactus-plugin-htlc-eth-besu && forge test -vvvvv
1617-
1617+
16181618
cactus-test-plugin-htlc-eth-besu-erc20:
16191619
continue-on-error: false
16201620
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)