-
Notifications
You must be signed in to change notification settings - Fork 285
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(plugin-keychain-memory-wasm): add WebAssmebly PoC
Adding a new keychain in-memory plugin that has it's implementation written in Rust that is then compiled down to WebAssmebly via wasm-pack and used by the wrapper Typescript code. This is NOT meant for production because it stores everything in plain text and also provides zero durability/persistence guarantees given that it's only storing everything in memory. The actual news here is that we have a plugin now written in Rust which is the pre-cursor to us being able to do something similar with the Weaver relay component as the next phase of a bigger PoC. The reason why not the entire plugin is implemented in Rust is because we are unable to hook up ExpressJS request handlers from the Rust code as far as I could determine. See this link for further details on this: https://rustwasm.github.io/book/reference/js-ffi.html#from-the-rust-side Because of the above, the way it works is this: +--------+ API Request +----------+ | HTTP |-------------->| ExpressJS| | Client | +----------+ +--------+ Method| Call | v +---------+ Method Call +----------+ | Calling |------------->|JS Plugin | | Module | |Module | +---------+ +----------+ |get() |set() |has() |delete() +-------------+ | | Wasm Plugin |<---+ | Module | +-------------+ ^ | | v +------------------------+ |Rust Native | |HashMap<String, String> | +------------------------+ Resolves #1281 Signed-off-by: Peter Somogyvari <peter.somogyvari@accenture.com>
- Loading branch information
Showing
57 changed files
with
7,285 additions
and
653 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,5 @@ | |
**/generated/ | ||
packages/core | ||
packages/connection-chain | ||
contribs/ | ||
contribs/ | ||
**/src/main/typescript/generated/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# `@hyperledger/cactus-plugin-keychain-memory-wasm` <!-- omit in toc --> | ||
|
||
## Table of Contents <!-- omit in toc --> | ||
|
||
- [1. Summary](#1-summary) | ||
- [Usage](#usage) | ||
|
||
## Summary | ||
|
||
Dummy keychain implementation doing NO encryption and storing everything in-memory. Only suitable for development and testing. Same as the non-wasm version but this one has the backing implementation written in Rust and compiled down to WebAssembly. | ||
|
||
> **Do not use this in production. It does not encrypt the stored data at all. It stores everything in plain text!** | ||
## Usage | ||
|
||
Can be used the same way as the non-WASM implementation in the package: `@hyperledger/cactus-plugin-keychain-memory` | ||
The only difference is that this one is backed by code written in Rust that is compiled down to WebAssembly modules to be loaded instead of the usual TS->JS transpilation process. |
7 changes: 7 additions & 0 deletions
7
packages/cactus-plugin-keychain-memory-wasm/openapitools.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"$schema": "node_modules/@openapitools/openapi-generator-cli/config.schema.json", | ||
"spaces": 2, | ||
"generator-cli": { | ||
"version": "5.2.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
{ | ||
"name": "@hyperledger/cactus-plugin-keychain-memory-wasm", | ||
"version": "1.0.0-rc.1", | ||
"description": "Dummy keychain implementation doing NO encryption and storing everything in-memory. Only suitable for development and testing. Same as the non-wasm version but this one has the backing implementation written in Rust and compiled down to WebAssembly.", | ||
"main": "dist/lib/main/typescript/index.js", | ||
"mainMinified": "dist/cactus-plugin-keychain-memory-wasm.node.umd.min.js", | ||
"browser": "dist/cactus-plugin-keychain-memory-wasm.web.umd.js", | ||
"browserMinified": "dist/cactus-plugin-keychain-memory-wasm.web.umd.min.js", | ||
"module": "dist/lib/main/typescript/index.js", | ||
"types": "dist/lib/main/typescript/index.d.ts", | ||
"files": [ | ||
"dist/*" | ||
], | ||
"scripts": { | ||
"wasm-pack": "CARGO_TARGET_DIR=${PWD}/dist/target-rustc/ wasm-pack build src/main/rust/cactus-plugin-keychain-memory-wasm/ --release --scope=hyperledger --target=nodejs --out-dir=../../../../src/main/typescript/generated/wasm-pack/", | ||
"postwasm-pack": "run-s del-wasm-pack-project-files copy-wasm-bg", | ||
"del-wasm-pack-project-files": "del-cli src/main/typescript/generated/wasm-pack/{package.json,README.md,.gitignore}", | ||
"copy-wasm-bg": "cpy './main/typescript/generated/wasm-pack/cactus_plugin_keychain_memory_wasm_bg*' '../dist/lib/' --cwd=src --parents", | ||
"generate-sdk": "openapi-generator-cli generate -i ./src/main/json/openapi.json -g typescript-axios -o ./src/main/typescript/generated/openapi/typescript-axios/ --reserved-words-mappings protected=protected", | ||
"generate-rust-server": "openapi-generator-cli generate -i ./src/main/json/openapi.json -g rust-server -o ./src/main/rust/generated/openapi/rust-server", | ||
"codegen:openapi": "npm run generate-sdk", | ||
"codegen": "run-p 'codegen:*'", | ||
"watch": "npm-watch", | ||
"webpack": "npm-run-all webpack:dev", | ||
"webpack:dev": "npm-run-all webpack:dev:node webpack:dev:web", | ||
"webpack:dev:web": "webpack --env=dev --target=web --config ../../webpack.config.js", | ||
"webpack:dev:node": "webpack --env=dev --target=node --config ../../webpack.config.js" | ||
}, | ||
"watch": { | ||
"codegen:openapi": { | ||
"patterns": [ | ||
"./src/main/json/openapi.json" | ||
] | ||
} | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"engines": { | ||
"node": ">=10", | ||
"npm": ">=6" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/hyperledger/cactus.git" | ||
}, | ||
"keywords": [ | ||
"Hyperledger", | ||
"Cactus", | ||
"Integration", | ||
"Blockchain", | ||
"Distributed Ledger Technology" | ||
], | ||
"author": { | ||
"name": "Hyperledger Cactus Contributors", | ||
"email": "cactus@lists.hyperledger.org", | ||
"url": "https://www.hyperledger.org/use/cactus" | ||
}, | ||
"contributors": [ | ||
{ | ||
"name": "Please add yourself to the list of contributors", | ||
"email": "your.name@example.com", | ||
"url": "https://example.com" | ||
}, | ||
{ | ||
"name": "Peter Somogyvari", | ||
"email": "peter.somogyvari@accenture.com", | ||
"url": "https://accenture.com" | ||
} | ||
], | ||
"license": "Apache-2.0", | ||
"bugs": { | ||
"url": "https://github.com/hyperledger/cactus/issues" | ||
}, | ||
"homepage": "https://github.com/hyperledger/cactus#readme", | ||
"dependencies": { | ||
"@hyperledger/cactus-common": "0.10.0", | ||
"@hyperledger/cactus-core": "0.10.0", | ||
"@hyperledger/cactus-core-api": "0.10.0", | ||
"axios": "0.21.4", | ||
"express": "4.17.1", | ||
"prom-client": "13.2.0", | ||
"uuid": "8.3.2" | ||
}, | ||
"devDependencies": { | ||
"@types/express": "4.17.13", | ||
"cpy-cli": "3.1.1", | ||
"del-cli": "4.0.1" | ||
} | ||
} |
137 changes: 137 additions & 0 deletions
137
packages/cactus-plugin-keychain-memory-wasm/src/main/json/openapi.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
{ | ||
"openapi": "3.0.3", | ||
"info": { | ||
"title": "Hyperledger Cactus Plugin - Keychain Memory WASM", | ||
"description": "Contains/describes the Hyperledger Cactus Keychain Memory WASM plugin which is designed to help with testing and development and is implemented in Rust instead of Typescript.", | ||
"version": "1.0.0-rc.1", | ||
"license": { | ||
"name": "Apache 2.0", | ||
"url": "https://www.apache.org/licenses/LICENSE-2.0.html" | ||
} | ||
}, | ||
"paths": { | ||
"/api/v1/plugins/@hyperledger/cactus-plugin-keychain-memory-wasm/get-keychain-entry": { | ||
"post": { | ||
"x-hyperledger-cactus": { | ||
"http": { | ||
"path": "/api/v1/plugins/@hyperledger/cactus-plugin-keychain-memory-wasm/get-keychain-entry", | ||
"verbLowerCase": "post" | ||
} | ||
}, | ||
"operationId": "getKeychainEntryV1", | ||
"summary": "Retrieves the contents of a keychain entry from the backend.", | ||
"parameters": [], | ||
"requestBody": { | ||
"$ref": "https://raw.githubusercontent.com/hyperledger/cactus/v1.0.0-rc.1/packages/cactus-core-api/src/main/json/openapi.json#/components/requestBodies/keychain_get_entry_request_body" | ||
}, | ||
"responses": { | ||
"200": { | ||
"$ref": "https://raw.githubusercontent.com/hyperledger/cactus/v1.0.0-rc.1/packages/cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_get_entry_200" | ||
}, | ||
"400": { | ||
"$ref": "https://raw.githubusercontent.com/hyperledger/cactus/v1.0.0-rc.1/packages/cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_get_entry_400" | ||
}, | ||
"401": { | ||
"$ref": "https://raw.githubusercontent.com/hyperledger/cactus/v1.0.0-rc.1/packages/cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_get_entry_401" | ||
}, | ||
"404": { | ||
"$ref": "https://raw.githubusercontent.com/hyperledger/cactus/v1.0.0-rc.1/packages/cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_get_entry_404" | ||
}, | ||
"500": { | ||
"$ref": "https://raw.githubusercontent.com/hyperledger/cactus/v1.0.0-rc.1/packages/cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_get_entry_500" | ||
} | ||
} | ||
} | ||
}, | ||
"/api/v1/plugins/@hyperledger/cactus-plugin-keychain-memory-wasm/set-keychain-entry": { | ||
"post": { | ||
"x-hyperledger-cactus": { | ||
"http": { | ||
"path": "/api/v1/plugins/@hyperledger/cactus-plugin-keychain-memory-wasm/set-keychain-entry", | ||
"verbLowerCase": "post" | ||
} | ||
}, | ||
"operationId": "setKeychainEntryV1", | ||
"summary": "Sets a value under a key on the keychain backend.", | ||
"parameters": [], | ||
"requestBody": { | ||
"$ref": "https://raw.githubusercontent.com/hyperledger/cactus/v1.0.0-rc.1/packages/cactus-core-api/src/main/json/openapi.json#/components/requestBodies/keychain_set_entry_request_body" | ||
}, | ||
"responses": { | ||
"200": { | ||
"$ref": "https://raw.githubusercontent.com/hyperledger/cactus/v1.0.0-rc.1/packages/cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_set_entry_200" | ||
}, | ||
"400": { | ||
"$ref": "https://raw.githubusercontent.com/hyperledger/cactus/v1.0.0-rc.1/packages/cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_set_entry_400" | ||
}, | ||
"401": { | ||
"$ref": "https://raw.githubusercontent.com/hyperledger/cactus/v1.0.0-rc.1/packages/cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_set_entry_401" | ||
}, | ||
"500": { | ||
"$ref": "https://raw.githubusercontent.com/hyperledger/cactus/v1.0.0-rc.1/packages/cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_set_entry_500" | ||
} | ||
} | ||
} | ||
}, | ||
"/api/v1/plugins/@hyperledger/cactus-plugin-keychain-memory-wasm/delete-keychain-entry": { | ||
"post": { | ||
"x-hyperledger-cactus": { | ||
"http": { | ||
"path": "/api/v1/plugins/@hyperledger/cactus-plugin-keychain-memory-wasm/delete-keychain-entry", | ||
"verbLowerCase": "post" | ||
} | ||
}, | ||
"operationId": "deleteKeychainEntryV1", | ||
"summary": "Deletes an entry under a key on the keychain backend.", | ||
"parameters": [], | ||
"requestBody": { | ||
"$ref": "https://raw.githubusercontent.com/hyperledger/cactus/v1.0.0-rc.1/packages/cactus-core-api/src/main/json/openapi.json#/components/requestBodies/keychain_delete_entry_request_body" | ||
}, | ||
"responses": { | ||
"200": { | ||
"$ref": "https://raw.githubusercontent.com/hyperledger/cactus/v1.0.0-rc.1/packages/cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_delete_entry_200" | ||
}, | ||
"400": { | ||
"$ref": "https://raw.githubusercontent.com/hyperledger/cactus/v1.0.0-rc.1/packages/cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_delete_entry_400" | ||
}, | ||
"401": { | ||
"$ref": "https://raw.githubusercontent.com/hyperledger/cactus/v1.0.0-rc.1/packages/cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_delete_entry_401" | ||
}, | ||
"500": { | ||
"$ref": "https://raw.githubusercontent.com/hyperledger/cactus/v1.0.0-rc.1/packages/cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_delete_entry_500" | ||
} | ||
} | ||
} | ||
}, | ||
"/api/v1/plugins/@hyperledger/cactus-plugin-keychain-memory-wasm/has-keychain-entry": { | ||
"post": { | ||
"x-hyperledger-cactus": { | ||
"http": { | ||
"path": "/api/v1/plugins/@hyperledger/cactus-plugin-keychain-memory-wasm/has-keychain-entry", | ||
"verbLowerCase": "post" | ||
} | ||
}, | ||
"operationId": "hasKeychainEntryV1", | ||
"summary": "Checks that an entry exists under a key on the keychain backend", | ||
"parameters": [], | ||
"requestBody": { | ||
"$ref": "https://raw.githubusercontent.com/hyperledger/cactus/v1.0.0-rc.1/packages/cactus-core-api/src/main/json/openapi.json#/components/requestBodies/keychain_has_entry_request_body" | ||
}, | ||
"responses": { | ||
"200": { | ||
"$ref": "https://raw.githubusercontent.com/hyperledger/cactus/v1.0.0-rc.1/packages/cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_has_entry_200" | ||
}, | ||
"400": { | ||
"$ref": "https://raw.githubusercontent.com/hyperledger/cactus/v1.0.0-rc.1/packages/cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_has_entry_400" | ||
}, | ||
"401": { | ||
"$ref": "https://raw.githubusercontent.com/hyperledger/cactus/v1.0.0-rc.1/packages/cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_has_entry_401" | ||
}, | ||
"500": { | ||
"$ref": "https://raw.githubusercontent.com/hyperledger/cactus/v1.0.0-rc.1/packages/cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_has_entry_500" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
Empty file.
6 changes: 6 additions & 0 deletions
6
...s-plugin-keychain-memory-wasm/src/main/rust/cactus-plugin-keychain-memory-wasm/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/target | ||
**/*.rs.bk | ||
Cargo.lock | ||
bin/ | ||
pkg/ | ||
wasm-pack.log |
44 changes: 44 additions & 0 deletions
44
...s-plugin-keychain-memory-wasm/src/main/rust/cactus-plugin-keychain-memory-wasm/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
[package] | ||
name = "cactus-plugin-keychain-memory-wasm" | ||
version = "1.0.0-rc.1" | ||
authors = ["Peter Somogyvari <peter.somogyvari@accenture.com>"] | ||
edition = "2018" | ||
|
||
[build] | ||
target-dir = "../../../../dist/target-rustc/" | ||
|
||
[lib] | ||
crate-type = ["cdylib", "rlib"] | ||
|
||
[features] | ||
default = ["console_error_panic_hook"] | ||
|
||
[dependencies] | ||
wasm-bindgen = { version = "0.2.63", features = ["serde-serialize"] } | ||
wasm-bindgen-futures = "0.4.28" | ||
|
||
# The `console_error_panic_hook` crate provides better debugging of panics by | ||
# logging them with `console.error`. This is great for development, but requires | ||
# all the `std::fmt` and `std::panicking` infrastructure, so isn't great for | ||
# code size when deploying. | ||
console_error_panic_hook = { version = "0.1.6", optional = true } | ||
|
||
# `wee_alloc` is a tiny allocator for wasm that is only ~1K in code size | ||
# compared to the default allocator's ~10K. It is slower than the default | ||
# allocator, however. | ||
# | ||
# Unfortunately, `wee_alloc` requires nightly Rust when targeting wasm for now. | ||
wee_alloc = { version = "0.4.5", optional = true } | ||
|
||
js-sys = "0.3.55" | ||
serde = { version = "1.0.130", features = ["derive"] } | ||
serde_json = "1.0.68" | ||
# hashicorp_vault = { version = "2.1.0" } | ||
ureq = { version = "2.2.0", features = ["json", "charset"] } | ||
|
||
[dev-dependencies] | ||
wasm-bindgen-test = "0.3.13" | ||
|
||
[profile.release] | ||
# Tell `rustc` to optimize for small code size. | ||
opt-level = "s" |
Oops, something went wrong.