Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move template to TypeScript #26

Merged
merged 2 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

Template repository for JavaScript and C++ CCF applications.

Note: For complete sample apps, see https://github.com/microsoft/ccf-app-samples.
Note: For complete sample apps, see https://github.com/microsoft/ccf-app-samples.

## Quickstart

The quickest way to build and run this sample CCF app is to checkout this repository locally in its development container by clicking:
The quickest way to build and run this sample CCF app is to checkout this repository locally in its development container by clicking:
[![Open in VSCode](https://img.shields.io/static/v1?label=Open+in&message=VSCode&logo=visualstudiocode&color=007ACC&logoColor=007ACC&labelColor=2C2C32)](https://vscode.dev/redirect?url=vscode://ms-vscode-remote.remote-containers/cloneInVolume?url=https://github.com/microsoft/ccf-app-template)

All dependencies will be automatically installed (takes ~2 mins on first checkout).
Expand Down Expand Up @@ -41,8 +41,8 @@ $ /opt/ccf_virtual/bin/sandbox.sh --js-app-bundle ./js/dist/
In another terminal:

```bash
$ curl -X POST https://127.0.0.1:8000/app/log?id=1 --cacert ./workspace/sandbox_common/service_cert.pem -H "Content-Type: application/json" --data '{"msg": "hello world"}'
$ curl https://127.0.0.1:8000/app/log?id=1 --cacert ./workspace/sandbox_common/service_cert.pem
$ curl -X POST "https://127.0.0.1:8000/app/log?id=1" --cacert ./workspace/sandbox_common/service_cert.pem -H "Content-Type: application/json" --data '{"msg": "hello world"}'
$ curl "https://127.0.0.1:8000/app/log?id=1" --cacert ./workspace/sandbox_common/service_cert.pem
hello world
```

Expand Down Expand Up @@ -96,18 +96,17 @@ To start a test CCF network on a Linux environment, it requires [CCF to be intal

The CCF network is started with one node and one member, please follow the [same governance steps as Docker](#network-governance) to initialize the network and check [CCF node config file documentation](https://microsoft.github.io/CCF/main/operations/configuration.html)


### Managed CCF

The application can be tested using [Azure Managed CCF](https://techcommunity.microsoft.com/t5/azure-confidential-computing/microsoft-introduces-preview-of-azure-managed-confidential/ba-p/3648986) ``(Pre-release phase)``, you can create Azure Managed CCF service on your subscription, that will give you a ready CCF network
The application can be tested using [Azure Managed CCF](https://techcommunity.microsoft.com/t5/azure-confidential-computing/microsoft-introduces-preview-of-azure-managed-confidential/ba-p/3648986) `(Pre-release phase)`, you can create Azure Managed CCF service on your subscription, that will give you a ready CCF network

- First, create the network's initial member certificate, please check [Certificates generation](https://microsoft.github.io/CCF/main/governance/adding_member.html)
- Create a new Azure Managed CCF service (the initial member certificate required as input)
- Build the application and [create a deployment proposal](https://microsoft.github.io/CCF/main/build_apps/js_app_bundle.html#deployment)
- Deploy the application proposal, [using governance calls](https://microsoft.github.io/CCF/main/governance/proposals.html#creating-a-proposal)
- Create and submit [an add users proposal](https://microsoft.github.io/CCF/main/governance/proposals.html#creating-a-proposal)

## <img src="https://user-images.githubusercontent.com/42961061/191275172-24269bf0-bb9c-402d-8900-2d589582a781.png" height=50px></img> C++
## <img src="https://user-images.githubusercontent.com/42961061/191275172-24269bf0-bb9c-402d-8900-2d589582a781.png" height=50px></img> C++

CCF apps can also be written in C++. This offers better performance than JavaScript apps but requires a compilation step and a restart of the CCF node for deployment.

Expand Down
5 changes: 4 additions & 1 deletion js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
"devDependencies": {
"@rollup/plugin-commonjs": "^17.1.0",
"@rollup/plugin-node-resolve": "^11.2.0",
"@rollup/plugin-typescript": "^11.1.6",
"del-cli": "^3.0.1",
"rollup": "^2.41.0"
"rollup": "^2.41.0",
"tslib": "^2.6.3",
"typescript": "^5.4.5"
}
}
9 changes: 7 additions & 2 deletions js/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import { nodeResolve } from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import typescript from "@rollup/plugin-typescript";

export default {
input: "src/app.js",
input: "src/app.ts",
output: {
dir: "dist/src",
format: "es",
preserveModules: true,
preserveModulesRoot: "src",
},
plugins: [nodeResolve(), commonjs()],
plugins: [
nodeResolve(),
typescript({ compilerOptions: { noEmitOnError: true } }),
commonjs(),
],
};
39 changes: 0 additions & 39 deletions js/src/app.js

This file was deleted.

41 changes: 41 additions & 0 deletions js/src/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import * as ccfapp from "@microsoft/ccf-app";

function parse_request_query(request: ccfapp.Request): {
[key: string]: string;
} {
const elements = request.query.split("&");
const obj = {};
for (const kv of elements) {
const [k, v] = kv.split("=");
obj[k] = v;
}
return obj;
}

const recordsMap = ccfapp.typedKv("records", ccfapp.string, ccfapp.string);

export function write(request: ccfapp.Request): ccfapp.Response {
const parsedQuery = parse_request_query(request);
if (parsedQuery.id === undefined) {
return { body: { error: "Missing query parameter 'id'" } };
}
const params = request.body.json();

recordsMap.set(parsedQuery.id, params.msg);
return {};
}

export function read(request: ccfapp.Request): ccfapp.Response {
const parsedQuery = parse_request_query(request);
if (parsedQuery.id === undefined) {
return { body: { error: "Missing query parameter 'id'" } };
}

const msg = recordsMap.get(parsedQuery.id);
if (msg === undefined) {
return {
body: { error: `Cannot find record for id \"${parsedQuery.id}\".` },
};
}
return { body: msg };
}
14 changes: 14 additions & 0 deletions js/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"compilerOptions": {
"lib": ["ES2020"],
"target": "ES2020",
"module": "ES2020",
"moduleResolution": "node",
"allowSyntheticDefaultImports": true,
"noImplicitAny": false,
"removeComments": true,
"preserveConstEnums": true,
"sourceMap": false
},
"include": ["src/**/*"]
}