-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement the encrypted storage plugin
Signed-off-by: Nam Hoang <hoangxuannam160493@gmail.com>
- Loading branch information
1 parent
a72918d
commit 7386859
Showing
21 changed files
with
823 additions
and
25 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
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
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,54 @@ | ||
import { IPluginMethodMap } from './IAgent'; | ||
|
||
/** | ||
* @public | ||
*/ | ||
export interface IEncryptAndStoreDataArgs { | ||
data: any; | ||
} | ||
|
||
/** | ||
* @public | ||
*/ | ||
export interface IEncrypteAndStoreDataResult { | ||
id: string; | ||
key: string; | ||
} | ||
|
||
/** | ||
* @public | ||
*/ | ||
export interface IFetchEncryptedDataArgs { | ||
id?: string; | ||
} | ||
|
||
/** | ||
* @public | ||
*/ | ||
export interface IFetchEncryptedDataByCredentialHashArgs { | ||
credentialHash: string; | ||
} | ||
|
||
/** | ||
* @public | ||
*/ | ||
export interface IFetchEncryptedDataByCredentialHashResult { | ||
encryptedData: string; | ||
encryptedDataId: string; | ||
decryptedKey: string; | ||
} | ||
|
||
/** | ||
* @public | ||
*/ | ||
export interface IEncryptedStorage extends IPluginMethodMap { | ||
encryptAndStoreData( | ||
args: IEncryptAndStoreDataArgs | ||
): Promise<IEncrypteAndStoreDataResult>; | ||
|
||
fetchEncryptedData(args: IFetchEncryptedDataArgs): Promise<string>; | ||
|
||
fetchEncryptedDataByCredentialHash( | ||
args: IFetchEncryptedDataByCredentialHashArgs | ||
): Promise<IFetchEncryptedDataByCredentialHashResult>; | ||
} |
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,87 @@ | ||
# Encrypted Storage | ||
|
||
The encrypted storage plugin provides a secure storage for the agent. It is used to store the verifiable credentials that issued when call the `createVerifiableCredential` method. | ||
|
||
## Usage | ||
|
||
### Configuration | ||
|
||
To use the encrypted storage plugin, you need to add the following configuration to the agent.yml. | ||
|
||
Fist, add the `dbConnectionEncrypted` to define the database connection for the encrypted storage. | ||
|
||
```yaml | ||
dbConnectionEncrypted: | ||
$require: typeorm#DataSource | ||
$args: | ||
- type: sqlite | ||
database: | ||
$ref: /constants/databaseFile | ||
synchronize: true | ||
migrationsRun: true | ||
migrations: | ||
$require: '@vckit/encrypted-storage?t=object#migrations' | ||
logging: false | ||
entities: | ||
$require: '@vckit/encrypted-storage?t=object#Entities' | ||
``` | ||
Second, add the `encryptedStorage` to define the encrypted storage plugin. | ||
|
||
```yaml | ||
# Encrypted Storage Plugin | ||
encryptedStorage: | ||
$require: '@vckit/encrypted-storage#EncryptedStorage' | ||
$args: | ||
- dbConnection: | ||
$ref: /dbConnectionEncrypted | ||
``` | ||
|
||
then require the encrypted storage plugin to the agent. | ||
|
||
```yaml | ||
# Agent | ||
agent: | ||
$require: '@vckit/core#Agent' | ||
$args: | ||
- schemaValidation: false | ||
plugins: | ||
# Plugins | ||
- $ref: /encryptedStorage | ||
``` | ||
|
||
After that, you need to configure the middleware to use the encrypted storage plugin to store the verifiable credentials when issue the verifiable credentials. You can configure the middleware in the `apiRoutes` section of the agent.yml. | ||
|
||
```yaml | ||
# API base path | ||
- - /agent | ||
- $require: '@vckit/remote-server?t=function#apiKeyAuth' | ||
$args: | ||
- apiKey: test123 | ||
# Configure the middleware before the AgentRouter function. The middleware only allow the apis in `apiRoutes` to use the encrypted storage plugin. | ||
- $require: '@vckit/encrypted-storage?t=function#encryptedStoreMiddleware' | ||
$args: | ||
- apiRoutes: | ||
- /createVerifiableCredential | ||
|
||
- $require: '@vckit/remote-server?t=function#AgentRouter' | ||
$args: | ||
- exposedMethods: | ||
$ref: /constants/methods | ||
``` | ||
Finally, you need to expose the endpoint that can be used to fetch the encrypted verifiable credential. You can configure the endpoint in the `apiRoutes` section of the agent.yml. | ||
|
||
```yaml | ||
# Encrypted storage API | ||
- - /encrypted-storage | ||
- $require: '@vckit/encrypted-storage?t=function#encryptedStoreRouter' | ||
``` | ||
|
||
### To use the encrypted storage plugin | ||
|
||
- To use the encrypted storage plugin, you need to call the `createVerifiableCredential` method with the parameter `save` to store the verifiable credential, then it will trigger the middleware to store the verifiable credential to the encrypted storage. | ||
|
||
- After that, it will response the decrypted key, id of encrypted verifiable credential, and the verifiable credential. | ||
|
||
- Use the decrypted key to decrypt the encrypted verifiable credential that fetched from the endpoint `/encrypted-storage/encrypted-data/:id`. |
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,18 @@ | ||
{ | ||
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json", | ||
"apiReport": { | ||
"enabled": true, | ||
"reportFolder": "./api", | ||
"reportTempFolder": "./api" | ||
}, | ||
|
||
"docModel": { | ||
"enabled": true, | ||
"apiJsonFilePath": "./api/<unscopedPackageName>.api.json" | ||
}, | ||
|
||
"dtsRollup": { | ||
"enabled": false | ||
}, | ||
"mainEntryPointFilePath": "<projectFolder>/build/index.d.ts" | ||
} |
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,46 @@ | ||
{ | ||
"name": "@vckit/encrypted-storage", | ||
"version": "1.0.0-beta.5", | ||
"description": "To encrypt the data and store to the database.", | ||
"author": "Nam Hoang <hoangxuannam160493@gmail.com>", | ||
"homepage": "https://github.com/uncefact/project-vckit#readme", | ||
"main": "build/index.js", | ||
"types": "build/index.d.ts", | ||
"exports": { | ||
".": "./build/index.js", | ||
"./build/plugin.schema.json": "./build/plugin.schema.json" | ||
}, | ||
"scripts": { | ||
"build": "tsc", | ||
"extract-api": "node ../cli/bin/vckit.js dev extract-api" | ||
}, | ||
"license": "Apache-2.0", | ||
"keywords": [], | ||
"type": "module", | ||
"moduleDirectories": [ | ||
"node_modules", | ||
"src" | ||
], | ||
"files": [ | ||
"build/**/*", | ||
"src/**/*", | ||
"README.md", | ||
"LICENSE" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/uncefact/project-vckit.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/uncefact/project-vckit/issues" | ||
}, | ||
"dependencies": { | ||
"@govtechsg/oa-encryption": "^1.3.5", | ||
"@vckit/core-types": "workspace:*", | ||
"@veramo/data-store": "^5.2.0", | ||
"@veramo/utils": "^5.2.0", | ||
"express-interceptor": "^1.2.0", | ||
"typeorm": "^0.3.10", | ||
"uuid": "^9.0.0" | ||
} | ||
} |
Oops, something went wrong.