Skip to content

Commit

Permalink
feat(connector-iroha): sending transactions signed on the client-side
Browse files Browse the repository at this point in the history
- Add new endpoint `generate-transaction`, to create unsigned transactions
  that can be signed on the client side.
- Add a function to iroha-connector package to help signing iroha transactions
  on the client (BLP) side.
- Extend transact endpoint to accept signed transaction as an argument as well.
  New transact interface is backward compatible, all current code should work without any change.
- Add new test suite to check features implemented in this PR (i.e. signing on the client side).
- Perform minor cleanup in the connector code, remove unused fields and includes,
  fix some type related warnings.
- Perform openapi interface cleanup, format json correctly,
  mark baseConfig as required by transact (will fail otherwise),
  add error return type schemas, remove invoke-contract endpoint that was not implemented.

Closes 2077

Signed-off-by: Michal Bajer <[email protected]>
  • Loading branch information
outSH authored and takeutak committed Jul 15, 2022
1 parent 599205a commit da94cd6
Show file tree
Hide file tree
Showing 8 changed files with 1,069 additions and 146 deletions.
5 changes: 4 additions & 1 deletion packages/cactus-plugin-ledger-connector-iroha/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,17 @@
"express": "4.17.1",
"grpc": "1.24.11",
"iroha-helpers-ts": "0.9.25-ss",
"fast-safe-stringify": "2.1.1",
"sanitize-html": "2.7.0",
"openapi-types": "7.0.1",
"prom-client": "13.1.0",
"typescript-optional": "2.0.1"
},
"devDependencies": {
"@hyperledger/cactus-plugin-keychain-memory": "1.0.0",
"@hyperledger/cactus-test-tooling": "1.0.0",
"@types/express": "4.17.8"
"@types/express": "4.17.8",
"@types/sanitize-html": "2.6.2"
},
"engines": {
"node": ">=10",
Expand Down
200 changes: 170 additions & 30 deletions packages/cactus-plugin-ledger-connector-iroha/src/main/json/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,10 @@
},
"KeyPair": {
"type": "object",
"required": ["publicKey", "privateKey"],
"required": [
"publicKey",
"privateKey"
],
"properties": {
"publicKey": {
"description": "SHA-3 ed25519 public keys of length 64 are recommended.",
Expand All @@ -154,7 +157,11 @@
},
"RunTransactionRequestV1": {
"type": "object",
"required": ["commandName", "params"],
"required": [
"commandName",
"baseConfig",
"params"
],
"additionalProperties": false,
"properties": {
"commandName": {
Expand All @@ -172,6 +179,54 @@
}
}
},
"RunTransactionSignedRequestV1": {
"type": "object",
"required": [
"signedTransaction"
],
"properties": {
"signedTransaction": {
"description": "Signed transaction binary data received from generate-transaction endpoint.",
"type": "string",
"format": "binary"
},
"baseConfig": {
"$ref": "#/components/schemas/IrohaBaseConfig",
"nullable": false
}
}
},
"GenerateTransactionRequestV1": {
"type": "object",
"required": [
"commandName",
"commandParams",
"creatorAccountId"
],
"additionalProperties": false,
"properties": {
"commandName": {
"description": "Iroha command name.",
"type": "IrohaCommand",
"nullable": false
},
"commandParams": {
"description": "Parameters for iroha command specified in commandName",
"type": "object"
},
"creatorAccountId": {
"description": "Sender account id",
"type": "string",
"nullable": false
},
"quorum": {
"description": "Requested transaction quorum",
"type": "number",
"nullable": false,
"default": 1
}
}
},
"IrohaBaseConfig": {
"type": "object",
"additionalProperties": true,
Expand Down Expand Up @@ -211,26 +266,61 @@
},
"RunTransactionResponse": {
"type": "object",
"required": ["transactionReceipt"],
"required": [
"transactionReceipt"
],
"properties": {
"transactionReceipt": {}
}
},
"InvokeContractV1Request": {
"PrometheusExporterMetricsResponse": {
"type": "string",
"nullable": false
},
"ErrorExceptionJsonResponseV1": {
"type": "object",
"additionalProperties": false,
"required": [
"message"
],
"properties": {
"contractName": {}
"message": {
"type": "string",
"nullable": false
},
"name": {
"type": "string",
"nullable": false
},
"error": {
"type": "string",
"nullable": false
},
"stack": {
"type": "string",
"nullable": false
},
"cause": {
"type": "string",
"nullable": false
}
}
},
"InvokeContractV1Response": {
"ErrorExceptionResponseV1": {
"type": "object",
"required": ["success"],
"properties": {}
},
"PrometheusExporterMetricsResponse": {
"type": "string",
"nullable": false
"required": [
"message",
"error"
],
"properties": {
"message": {
"type": "string",
"nullable": false
},
"error": {
"type": "string",
"nullable": false
}
}
}
}
},
Expand All @@ -250,7 +340,14 @@
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/RunTransactionRequestV1"
"oneOf": [
{
"$ref": "#/components/schemas/RunTransactionRequestV1"
},
{
"$ref": "#/components/schemas/RunTransactionSignedRequestV1"
}
]
}
}
}
Expand All @@ -265,45 +362,88 @@
}
}
}
},
"405": {
"description": "Method Not Allowed error.",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ErrorExceptionJsonResponseV1"
}
}
}
},
"400": {
"description": "Bad Request error.",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ErrorExceptionJsonResponseV1"
}
}
}
},
"500": {
"description": "Internal Server Error.",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ErrorExceptionJsonResponseV1"
}
}
}
}
}
}
},
"/api/v1/plugins/@hyperledger/cactus-plugin-ledger-connector-iroha/invoke-contract": {
"/api/v1/plugins/@hyperledger/cactus-plugin-ledger-connector-iroha/generate-transaction": {
"post": {
"x-hyperledger-cactus": {
"http": {
"verbLowerCase": "post",
"path": "/api/v1/plugins/@hyperledger/cactus-plugin-ledger-connector-iroha/invoke-contract"
"path": "/api/v1/plugins/@hyperledger/cactus-plugin-ledger-connector-iroha/generate-transaction"
}
},
"operationId": "invokeContractV1",
"summary": "Invokes a contract on a Iroha ledger",
"operationId": "generateTransactionV1",
"summary": "Generate transaction that can be signed locally.",
"parameters": [],
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/InvokeContractV1Request"
"$ref": "#/components/schemas/GenerateTransactionRequestV1"
}
}
}
},
"responses": {
"501": {
"description": "Not implemented",
"200": {
"description": "OK",
"content": {
"application/octet-stream": {
"schema": {
"type": "string",
"format": "binary"
}
}
}
},
"400": {
"description": "Bad Request Error",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"message": {
"type": "string",
"nullable": false,
"minLength": 1,
"maxLength": 2048
}
}
"$ref": "#/components/schemas/ErrorExceptionResponseV1"
}
}
}
},
"500": {
"description": "Internal Server Error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ErrorExceptionResponseV1"
}
}
}
Expand Down
Loading

0 comments on commit da94cd6

Please sign in to comment.