Skip to content
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
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## Unreleased

### Added

- Historical point query support has been added to JavaScript endpoints (#2285).

### Changed

- `"readonly"` has been replaced by `"mode"` in `app.json` in JavaScript apps (#2285).

Comment thread
letmaik marked this conversation as resolved.
## [0.19.0]

### Changed
Expand Down
10 changes: 7 additions & 3 deletions cmake/quickjs.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ if("sgx" IN_LIST COMPILE_TARGETS)
quickjs.enclave STATIC ${QUICKJS_SRC} ${CCF_DIR}/3rdparty/stub/time.c
)
target_compile_options(
quickjs.enclave PUBLIC -nostdinc -DCONFIG_VERSION="${QUICKJS_VERSION}"
-DEMSCRIPTEN -DCONFIG_STACK_CHECK
quickjs.enclave
PUBLIC -nostdinc -DCONFIG_VERSION="${QUICKJS_VERSION}" -DEMSCRIPTEN
-DCONFIG_STACK_CHECK
PRIVATE $<$<CONFIG:Debug>:-DDUMP_LEAKS>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to check, this is saying "when building this target in Debug, set DUMP_LEAKS", right?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah

)
target_link_libraries(quickjs.enclave PUBLIC ${OE_TARGET_LIBC})
set_property(TARGET quickjs.enclave PROPERTY POSITION_INDEPENDENT_CODE ON)
Expand All @@ -40,7 +42,9 @@ endif()

add_library(quickjs.host STATIC ${QUICKJS_SRC})
target_compile_options(
quickjs.host PUBLIC -DCONFIG_VERSION="${QUICKJS_VERSION}"
quickjs.host
PUBLIC -DCONFIG_VERSION="${QUICKJS_VERSION}"
PRIVATE $<$<CONFIG:Debug>:-DDUMP_LEAKS>
)
add_san(quickjs.host)
set_property(TARGET quickjs.host PROPERTY POSITION_INDEPENDENT_CODE ON)
Expand Down
24 changes: 12 additions & 12 deletions samples/apps/forum/app.tmpl.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@
"forwarding_required": "always",
"execute_outside_consensus": "never",
"authn_policies": [],
"readonly": false
"mode": "readwrite"
},
"put": {
"js_module": "build/PollControllerProxy.js",
"js_function": "submitOpinion",
"forwarding_required": "always",
"execute_outside_consensus": "never",
"authn_policies": [],
"readonly": false
"mode": "readwrite"
},
"get": {
"js_module": "build/PollControllerProxy.js",
"js_function": "getPoll",
"forwarding_required": "always",
"execute_outside_consensus": "never",
"authn_policies": [],
"readonly": true
"mode": "readonly"
}
},
"/polls": {
Expand All @@ -33,23 +33,23 @@
"forwarding_required": "always",
"execute_outside_consensus": "never",
"authn_policies": [],
"readonly": false
"mode": "readwrite"
},
"put": {
"js_module": "build/PollControllerProxy.js",
"js_function": "submitOpinions",
"forwarding_required": "always",
"execute_outside_consensus": "never",
"authn_policies": [],
"readonly": false
"mode": "readwrite"
},
"get": {
"js_module": "build/PollControllerProxy.js",
"js_function": "getPolls",
"forwarding_required": "always",
"execute_outside_consensus": "never",
"authn_policies": [],
"readonly": true
"mode": "readonly"
}
},
"/site": {
Expand All @@ -59,7 +59,7 @@
"forwarding_required": "always",
"execute_outside_consensus": "never",
"authn_policies": [],
"readonly": true
"mode": "readonly"
}
},
"/site/polls/create": {
Expand All @@ -69,7 +69,7 @@
"forwarding_required": "always",
"execute_outside_consensus": "never",
"authn_policies": [],
"readonly": true
"mode": "readonly"
}
},
"/site/opinions/submit": {
Expand All @@ -79,7 +79,7 @@
"forwarding_required": "always",
"execute_outside_consensus": "never",
"authn_policies": [],
"readonly": true
"mode": "readonly"
}
},
"/site/view": {
Expand All @@ -89,7 +89,7 @@
"forwarding_required": "always",
"execute_outside_consensus": "never",
"authn_policies": [],
"readonly": true
"mode": "readonly"
}
},
"/csv": {
Expand All @@ -99,7 +99,7 @@
"forwarding_required": "always",
"execute_outside_consensus": "never",
"authn_policies": [],
"readonly": true,
"mode": "readonly",
"openapi_merge_patch": {
"responses": {
"200": {
Expand All @@ -117,7 +117,7 @@
"forwarding_required": "always",
"execute_outside_consensus": "never",
"authn_policies": [],
"readonly": false,
"mode": "readwrite",
"openapi_merge_patch": {
"requestBody": {
"content": {
Expand Down
26 changes: 26 additions & 0 deletions samples/apps/forum/src/types/ccf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,26 @@ export interface KVMap {

export type KVMaps = { [key: string]: KVMap };

export interface ProofElement {
left?: string;
right?: string;
}

export type Proof = ProofElement[];

export interface Receipt {
signature: string;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add a jsdoc comments like /** base64-encoded signature of the root by the node identified by nodeId */, and if we did, would it get picked up by sphinx-js? Just wondering, not requesting :)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes and yes, see the CryptoKeyPair interface in #2313

root: string;
proof: Proof;
leaf: string;
nodeId: string;
}

export interface HistoricalState {
transactionId: string;
receipt: Receipt;
}

interface WrapAlgoParams {
name: string;
}
Expand All @@ -61,6 +81,11 @@ export interface AESKWPParams extends WrapAlgoParams {
name: "AES-KWP";
}

export interface RsaOaepAESKWPParams extends WrapAlgoParams {
Comment thread
letmaik marked this conversation as resolved.
name: "RSA-OAEP-AES-KWP";
label?: ArrayBuffer;
}

export interface CryptoKeyPair {
privateKey: string;
publicKey: string;
Expand All @@ -80,6 +105,7 @@ export interface CCF {
): ArrayBuffer;

kv: KVMaps;
historicalState?: HistoricalState;
}

export const ccf = globalThis.ccf as CCF;
Expand Down
8 changes: 4 additions & 4 deletions samples/apps/forum/tsoa-support/postprocess.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import SwaggerParser from "@apidevtools/swagger-parser";
import jsonmergepatch from "json-merge-patch";

// endpoint metadata defaults when first added to endpoints.json
const metadataDefaults = (readonly) => ({
const metadataDefaults = (mode) => ({
forwarding_required: "always",
execute_outside_consensus: "never",
authn_policies: ["user_cert"],
readonly: readonly,
mode: mode,
});

const distDir = "./dist";
Expand Down Expand Up @@ -116,8 +116,8 @@ const oldEndpoints = oldMetadata["endpoints"];
const newEndpoints = newMetadata["endpoints"];
for (const url in newEndpoints) {
for (const method in newEndpoints[url]) {
const readonly = method == "get";
Object.assign(newEndpoints[url][method], metadataDefaults(readonly));
const mode = method == "get" ? "readonly" : "readwrite";
Object.assign(newEndpoints[url][method], metadataDefaults(mode));
}
}
console.log(`Updating ${metadataPath} (if needed)`);
Expand Down
34 changes: 28 additions & 6 deletions samples/apps/logging/js/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"forwarding_required": "always",
"execute_outside_consensus": "never",
"authn_policies": ["jwt", "user_cert"],
"readonly": true,
"mode": "readonly",
"openapi": {}
},
"post": {
Expand All @@ -16,7 +16,7 @@
"forwarding_required": "always",
"execute_outside_consensus": "never",
"authn_policies": ["jwt", "user_cert"],
"readonly": false,
"mode": "readwrite",
"openapi": {}
},
"delete": {
Expand All @@ -25,7 +25,29 @@
"forwarding_required": "always",
"execute_outside_consensus": "never",
"authn_policies": ["jwt", "user_cert"],
"readonly": false,
"mode": "readwrite",
"openapi": {}
}
},
"/log/private/historical": {
"get": {
"js_module": "logging.js",
"js_function": "get_historical",
"forwarding_required": "never",
"execute_outside_consensus": "never",
"authn_policies": ["jwt", "user_cert"],
"mode": "historical",
"openapi": {}
}
},
"/log/private/historical_receipt": {
"get": {
"js_module": "logging.js",
"js_function": "get_historical_with_receipt",
"forwarding_required": "never",
"execute_outside_consensus": "never",
"authn_policies": ["jwt", "user_cert"],
"mode": "historical",
"openapi": {}
}
},
Expand All @@ -36,7 +58,7 @@
"forwarding_required": "always",
"execute_outside_consensus": "never",
"authn_policies": ["jwt", "user_cert"],
"readonly": true,
"mode": "readonly",
"openapi": {}
},
"post": {
Expand All @@ -45,7 +67,7 @@
"forwarding_required": "always",
"execute_outside_consensus": "never",
"authn_policies": ["jwt", "user_cert"],
"readonly": false,
"mode": "readwrite",
"openapi": {}
},
"delete": {
Expand All @@ -54,7 +76,7 @@
"forwarding_required": "always",
"execute_outside_consensus": "never",
"authn_policies": ["jwt", "user_cert"],
"readonly": false,
"mode": "readwrite",
"openapi": {}
}
}
Expand Down
10 changes: 10 additions & 0 deletions samples/apps/logging/js/src/logging.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ export function get_private(request) {
return get_record(ccf.kv["records"], id);
}

export function get_historical(request) {
return get_private(request);
}

export function get_historical_with_receipt(request) {
const result = get_private(request);
result.body.receipt = ccf.historicalState.receipt;
return result;
}

export function get_public(request) {
const id = get_id_from_request_query(request);
return get_record(ccf.kv["public:records"], id);
Expand Down
26 changes: 2 additions & 24 deletions samples/apps/logging/logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -546,30 +546,8 @@ namespace loggingapp
kv::Consensus::View view,
kv::Consensus::SeqNo seqno,
std::string& error_reason) {
if (consensus == nullptr)
{
error_reason = "Node is not fully configured";
return false;
}

const auto tx_view = consensus->get_view(seqno);
const auto committed_seqno = consensus->get_committed_seqno();
const auto committed_view = consensus->get_view(committed_seqno);

const auto tx_status = ccf::evaluate_tx_status(
view, seqno, tx_view, committed_view, committed_seqno);
if (tx_status != ccf::TxStatus::Committed)
{
error_reason = fmt::format(
"Only committed transactions can be queried. Transaction {}.{} is "
"{}",
view,
seqno,
ccf::tx_status_to_str(tx_status));
return false;
}

return true;
return ccf::historical::is_tx_committed(
consensus, view, seqno, error_reason);
};
make_endpoint(
"log/private/historical",
Expand Down
Loading