@adapt-toolkit/sdk 0.5.15 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +105 -0
- package/LICENSE.aefl +172 -0
- package/NOTICE +18 -0
- package/package.json +7 -4
- package/dist/common/index.d.ts +0 -7
- package/dist/common/index.d.ts.map +0 -1
- package/dist/common/index.js +0 -7
- package/dist/common/index.js.map +0 -1
- package/dist/common/interfaces/adapt_environment.d.ts +0 -21
- package/dist/common/interfaces/adapt_environment.d.ts.map +0 -1
- package/dist/common/interfaces/adapt_environment.js +0 -2
- package/dist/common/interfaces/adapt_environment.js.map +0 -1
- package/dist/common/interfaces/adapt_evaluation_unit.d.ts +0 -12
- package/dist/common/interfaces/adapt_evaluation_unit.d.ts.map +0 -1
- package/dist/common/interfaces/adapt_evaluation_unit.js +0 -2
- package/dist/common/interfaces/adapt_evaluation_unit.js.map +0 -1
- package/dist/common/interfaces/adapt_packet_context.d.ts +0 -29
- package/dist/common/interfaces/adapt_packet_context.d.ts.map +0 -1
- package/dist/common/interfaces/adapt_packet_context.js +0 -2
- package/dist/common/interfaces/adapt_packet_context.js.map +0 -1
- package/dist/common/interfaces/adapt_value.d.ts +0 -23
- package/dist/common/interfaces/adapt_value.d.ts.map +0 -1
- package/dist/common/interfaces/adapt_value.js +0 -2
- package/dist/common/interfaces/adapt_value.js.map +0 -1
- package/dist/common/interfaces/common.d.ts +0 -18
- package/dist/common/interfaces/common.d.ts.map +0 -1
- package/dist/common/interfaces/common.js +0 -4
- package/dist/common/interfaces/common.js.map +0 -1
- package/dist/common/memory_management/adapt_object_lifetime.d.ts +0 -121
- package/dist/common/memory_management/adapt_object_lifetime.d.ts.map +0 -1
- package/dist/common/memory_management/adapt_object_lifetime.js +0 -168
- package/dist/common/memory_management/adapt_object_lifetime.js.map +0 -1
- package/dist/index.d.ts +0 -3
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -2
- package/dist/index.js.map +0 -1
- package/dist/loaders/browser.d.ts +0 -5
- package/dist/loaders/browser.d.ts.map +0 -1
- package/dist/loaders/browser.js +0 -6
- package/dist/loaders/browser.js.map +0 -1
- package/dist/loaders/node.d.ts +0 -13
- package/dist/loaders/node.d.ts.map +0 -1
- package/dist/loaders/node.js +0 -33
- package/dist/loaders/node.js.map +0 -1
- package/dist/loaders/react-native.d.ts +0 -11
- package/dist/loaders/react-native.d.ts.map +0 -1
- package/dist/loaders/react-native.js +0 -19
- package/dist/loaders/react-native.js.map +0 -1
- package/dist/loaders/shared.d.ts +0 -17
- package/dist/loaders/shared.d.ts.map +0 -1
- package/dist/loaders/shared.js +0 -2
- package/dist/loaders/shared.js.map +0 -1
- package/dist/mufl_files/BF38C2D4E98F56F473F78121CF9EAAC3492364F1A11A3B0F1F04C12D24285596.muflo +0 -0
- package/dist/utilities/broker/broker.d.ts +0 -23
- package/dist/utilities/broker/broker.d.ts.map +0 -1
- package/dist/utilities/broker/broker.js +0 -599
- package/dist/utilities/broker/broker.js.map +0 -1
- package/dist/utilities/broker/broker_client.d.ts +0 -36
- package/dist/utilities/broker/broker_client.d.ts.map +0 -1
- package/dist/utilities/broker/broker_client.js +0 -121
- package/dist/utilities/broker/broker_client.js.map +0 -1
- package/dist/utilities/broker/broker_configurator.d.ts +0 -7
- package/dist/utilities/broker/broker_configurator.d.ts.map +0 -1
- package/dist/utilities/broker/broker_configurator.js +0 -16
- package/dist/utilities/broker/broker_configurator.js.map +0 -1
- package/dist/utilities/broker/index.d.ts +0 -5
- package/dist/utilities/broker/index.d.ts.map +0 -1
- package/dist/utilities/broker/index.js +0 -5
- package/dist/utilities/broker/index.js.map +0 -1
- package/dist/utilities/broker/pending_message_store.d.ts +0 -14
- package/dist/utilities/broker/pending_message_store.d.ts.map +0 -1
- package/dist/utilities/broker/pending_message_store.js +0 -58
- package/dist/utilities/broker/pending_message_store.js.map +0 -1
- package/dist/utilities/common/adapt_waitlist.d.ts +0 -5
- package/dist/utilities/common/adapt_waitlist.d.ts.map +0 -1
- package/dist/utilities/common/adapt_waitlist.js +0 -4
- package/dist/utilities/common/adapt_waitlist.js.map +0 -1
- package/dist/utilities/common/async_queue_adapter.d.ts +0 -40
- package/dist/utilities/common/async_queue_adapter.d.ts.map +0 -1
- package/dist/utilities/common/async_queue_adapter.js +0 -88
- package/dist/utilities/common/async_queue_adapter.js.map +0 -1
- package/dist/utilities/common/command_line_configurator.d.ts +0 -88
- package/dist/utilities/common/command_line_configurator.d.ts.map +0 -1
- package/dist/utilities/common/command_line_configurator.js +0 -217
- package/dist/utilities/common/command_line_configurator.js.map +0 -1
- package/dist/utilities/common/decorators.d.ts +0 -17
- package/dist/utilities/common/decorators.d.ts.map +0 -1
- package/dist/utilities/common/decorators.js +0 -84
- package/dist/utilities/common/decorators.js.map +0 -1
- package/dist/utilities/common/errors/adapt_initialization_error.d.ts +0 -4
- package/dist/utilities/common/errors/adapt_initialization_error.d.ts.map +0 -1
- package/dist/utilities/common/errors/adapt_initialization_error.js +0 -6
- package/dist/utilities/common/errors/adapt_initialization_error.js.map +0 -1
- package/dist/utilities/common/errors/adapt_network_error.d.ts +0 -8
- package/dist/utilities/common/errors/adapt_network_error.d.ts.map +0 -1
- package/dist/utilities/common/errors/adapt_network_error.js +0 -12
- package/dist/utilities/common/errors/adapt_network_error.js.map +0 -1
- package/dist/utilities/common/errors/adapt_protocol_error.d.ts +0 -12
- package/dist/utilities/common/errors/adapt_protocol_error.d.ts.map +0 -1
- package/dist/utilities/common/errors/adapt_protocol_error.js +0 -16
- package/dist/utilities/common/errors/adapt_protocol_error.js.map +0 -1
- package/dist/utilities/common/errors/adapt_test_mode_error.d.ts +0 -11
- package/dist/utilities/common/errors/adapt_test_mode_error.d.ts.map +0 -1
- package/dist/utilities/common/errors/adapt_test_mode_error.js +0 -22
- package/dist/utilities/common/errors/adapt_test_mode_error.js.map +0 -1
- package/dist/utilities/common/http_server.d.ts +0 -20
- package/dist/utilities/common/http_server.d.ts.map +0 -1
- package/dist/utilities/common/http_server.js +0 -44
- package/dist/utilities/common/http_server.js.map +0 -1
- package/dist/utilities/common/index.d.ts +0 -25
- package/dist/utilities/common/index.d.ts.map +0 -1
- package/dist/utilities/common/index.js +0 -36
- package/dist/utilities/common/index.js.map +0 -1
- package/dist/utilities/common/logger/logger.d.ts +0 -83
- package/dist/utilities/common/logger/logger.d.ts.map +0 -1
- package/dist/utilities/common/logger/logger.js +0 -272
- package/dist/utilities/common/logger/logger.js.map +0 -1
- package/dist/utilities/common/logger/logging_level.d.ts +0 -13
- package/dist/utilities/common/logger/logging_level.d.ts.map +0 -1
- package/dist/utilities/common/logger/logging_level.js +0 -36
- package/dist/utilities/common/logger/logging_level.js.map +0 -1
- package/dist/utilities/common/logger/message.d.ts +0 -65
- package/dist/utilities/common/logger/message.d.ts.map +0 -1
- package/dist/utilities/common/logger/message.js +0 -169
- package/dist/utilities/common/logger/message.js.map +0 -1
- package/dist/utilities/common/logger/network_component.d.ts +0 -3
- package/dist/utilities/common/logger/network_component.d.ts.map +0 -1
- package/dist/utilities/common/logger/network_component.js +0 -4
- package/dist/utilities/common/logger/network_component.js.map +0 -1
- package/dist/utilities/common/totp_qr_code_generator.d.ts +0 -12
- package/dist/utilities/common/totp_qr_code_generator.d.ts.map +0 -1
- package/dist/utilities/common/totp_qr_code_generator.js +0 -19
- package/dist/utilities/common/totp_qr_code_generator.js.map +0 -1
- package/dist/utilities/common/waitlist/waitlist.d.ts +0 -36
- package/dist/utilities/common/waitlist/waitlist.d.ts.map +0 -1
- package/dist/utilities/common/waitlist/waitlist.js +0 -116
- package/dist/utilities/common/waitlist/waitlist.js.map +0 -1
- package/dist/utilities/common/web_socket_client.d.ts +0 -67
- package/dist/utilities/common/web_socket_client.d.ts.map +0 -1
- package/dist/utilities/common/web_socket_client.js +0 -214
- package/dist/utilities/common/web_socket_client.js.map +0 -1
- package/dist/utilities/common/web_socket_connection.d.ts +0 -40
- package/dist/utilities/common/web_socket_connection.d.ts.map +0 -1
- package/dist/utilities/common/web_socket_connection.js +0 -174
- package/dist/utilities/common/web_socket_connection.js.map +0 -1
- package/dist/utilities/evaluator/common.d.ts +0 -10
- package/dist/utilities/evaluator/common.d.ts.map +0 -1
- package/dist/utilities/evaluator/common.js +0 -128
- package/dist/utilities/evaluator/common.js.map +0 -1
- package/dist/utilities/evaluator/evaluator.d.ts +0 -35
- package/dist/utilities/evaluator/evaluator.d.ts.map +0 -1
- package/dist/utilities/evaluator/evaluator.js +0 -141
- package/dist/utilities/evaluator/evaluator.js.map +0 -1
- package/dist/utilities/evaluator/index.d.ts +0 -3
- package/dist/utilities/evaluator/index.d.ts.map +0 -1
- package/dist/utilities/evaluator/index.js +0 -3
- package/dist/utilities/evaluator/index.js.map +0 -1
- package/dist/utilities/executables/adapt_wrapper.d.ts +0 -3
- package/dist/utilities/executables/adapt_wrapper.d.ts.map +0 -1
- package/dist/utilities/executables/adapt_wrapper.js +0 -25
- package/dist/utilities/executables/adapt_wrapper.js.map +0 -1
- package/dist/utilities/executables/adapt_wrapper_mobile.d.ts +0 -3
- package/dist/utilities/executables/adapt_wrapper_mobile.d.ts.map +0 -1
- package/dist/utilities/executables/adapt_wrapper_mobile.js +0 -20
- package/dist/utilities/executables/adapt_wrapper_mobile.js.map +0 -1
- package/dist/utilities/executables/adapt_wrapper_script.d.ts +0 -2
- package/dist/utilities/executables/adapt_wrapper_script.d.ts.map +0 -1
- package/dist/utilities/executables/adapt_wrapper_script.js +0 -6
- package/dist/utilities/executables/adapt_wrapper_script.js.map +0 -1
- package/dist/utilities/executables/broker.d.ts +0 -2
- package/dist/utilities/executables/broker.d.ts.map +0 -1
- package/dist/utilities/executables/broker.js +0 -28
- package/dist/utilities/executables/broker.js.map +0 -1
- package/dist/utilities/executables/index.d.ts +0 -2
- package/dist/utilities/executables/index.d.ts.map +0 -1
- package/dist/utilities/executables/index.js +0 -2
- package/dist/utilities/executables/index.js.map +0 -1
- package/dist/utilities/executables/local_data_storage.d.ts +0 -2
- package/dist/utilities/executables/local_data_storage.d.ts.map +0 -1
- package/dist/utilities/executables/local_data_storage.js +0 -20
- package/dist/utilities/executables/local_data_storage.js.map +0 -1
- package/dist/utilities/executables/local_data_storage_cmd_helper.d.ts +0 -2
- package/dist/utilities/executables/local_data_storage_cmd_helper.d.ts.map +0 -1
- package/dist/utilities/executables/local_data_storage_cmd_helper.js +0 -52
- package/dist/utilities/executables/local_data_storage_cmd_helper.js.map +0 -1
- package/dist/utilities/storage/data_storage.d.ts +0 -97
- package/dist/utilities/storage/data_storage.d.ts.map +0 -1
- package/dist/utilities/storage/data_storage.js +0 -440
- package/dist/utilities/storage/data_storage.js.map +0 -1
- package/dist/utilities/storage/index.d.ts +0 -6
- package/dist/utilities/storage/index.d.ts.map +0 -1
- package/dist/utilities/storage/index.js +0 -6
- package/dist/utilities/storage/index.js.map +0 -1
- package/dist/utilities/storage/local_data_storage.d.ts +0 -7
- package/dist/utilities/storage/local_data_storage.d.ts.map +0 -1
- package/dist/utilities/storage/local_data_storage.js +0 -18
- package/dist/utilities/storage/local_data_storage.js.map +0 -1
- package/dist/utilities/storage/local_data_storage_base.d.ts +0 -74
- package/dist/utilities/storage/local_data_storage_base.d.ts.map +0 -1
- package/dist/utilities/storage/local_data_storage_base.js +0 -163
- package/dist/utilities/storage/local_data_storage_base.js.map +0 -1
- package/dist/utilities/storage/local_data_storage_configurator.d.ts +0 -7
- package/dist/utilities/storage/local_data_storage_configurator.d.ts.map +0 -1
- package/dist/utilities/storage/local_data_storage_configurator.js +0 -13
- package/dist/utilities/storage/local_data_storage_configurator.js.map +0 -1
- package/dist/utilities/storage/storage_client.d.ts +0 -29
- package/dist/utilities/storage/storage_client.d.ts.map +0 -1
- package/dist/utilities/storage/storage_client.js +0 -100
- package/dist/utilities/storage/storage_client.js.map +0 -1
- package/dist/utilities/wrappers/configurators/adapt_wrapper_configurator.d.ts +0 -14
- package/dist/utilities/wrappers/configurators/adapt_wrapper_configurator.d.ts.map +0 -1
- package/dist/utilities/wrappers/configurators/adapt_wrapper_configurator.js +0 -57
- package/dist/utilities/wrappers/configurators/adapt_wrapper_configurator.js.map +0 -1
- package/dist/utilities/wrappers/configurators/control_packet_configurator.d.ts +0 -12
- package/dist/utilities/wrappers/configurators/control_packet_configurator.d.ts.map +0 -1
- package/dist/utilities/wrappers/configurators/control_packet_configurator.js +0 -52
- package/dist/utilities/wrappers/configurators/control_packet_configurator.js.map +0 -1
- package/dist/utilities/wrappers/configurators/packet_wrapper_configurator.d.ts +0 -32
- package/dist/utilities/wrappers/configurators/packet_wrapper_configurator.d.ts.map +0 -1
- package/dist/utilities/wrappers/configurators/packet_wrapper_configurator.js +0 -123
- package/dist/utilities/wrappers/configurators/packet_wrapper_configurator.js.map +0 -1
- package/dist/utilities/wrappers/enclave/control_packet.d.ts +0 -18
- package/dist/utilities/wrappers/enclave/control_packet.d.ts.map +0 -1
- package/dist/utilities/wrappers/enclave/control_packet.js +0 -213
- package/dist/utilities/wrappers/enclave/control_packet.js.map +0 -1
- package/dist/utilities/wrappers/index.d.ts +0 -5
- package/dist/utilities/wrappers/index.d.ts.map +0 -1
- package/dist/utilities/wrappers/index.js +0 -5
- package/dist/utilities/wrappers/index.js.map +0 -1
- package/dist/utilities/wrappers/wrappers/adapt_packet_wrapper.d.ts +0 -21
- package/dist/utilities/wrappers/wrappers/adapt_packet_wrapper.d.ts.map +0 -1
- package/dist/utilities/wrappers/wrappers/adapt_packet_wrapper.js +0 -67
- package/dist/utilities/wrappers/wrappers/adapt_packet_wrapper.js.map +0 -1
- package/dist/utilities/wrappers/wrappers/adapt_wrapper.d.ts +0 -136
- package/dist/utilities/wrappers/wrappers/adapt_wrapper.d.ts.map +0 -1
- package/dist/utilities/wrappers/wrappers/adapt_wrapper.js +0 -804
- package/dist/utilities/wrappers/wrappers/adapt_wrapper.js.map +0 -1
- package/dist/utilities/wrappers/wrappers/impl/adapt_packet_wrapper_impl.d.ts +0 -78
- package/dist/utilities/wrappers/wrappers/impl/adapt_packet_wrapper_impl.d.ts.map +0 -1
- package/dist/utilities/wrappers/wrappers/impl/adapt_packet_wrapper_impl.js +0 -611
- package/dist/utilities/wrappers/wrappers/impl/adapt_packet_wrapper_impl.js.map +0 -1
- package/dist/wasm/adapt.d.ts +0 -79
- package/dist/wasm/adapt.d.ts.map +0 -1
- package/dist/wasm/adapt.js +0 -450
- package/dist/wasm/adapt.js.map +0 -1
- package/dist/wasm/backend-node.d.ts +0 -9
- package/dist/wasm/backend-node.d.ts.map +0 -1
- package/dist/wasm/backend-node.js +0 -27
- package/dist/wasm/backend-node.js.map +0 -1
- package/dist/wasm/index.d.ts +0 -12
- package/dist/wasm/index.d.ts.map +0 -1
- package/dist/wasm/index.js +0 -15
- package/dist/wasm/index.js.map +0 -1
- package/dist/wasm/mufl-bindings.d.ts +0 -3
- package/dist/wasm/mufl-bindings.d.ts.map +0 -1
- package/dist/wasm/mufl-bindings.js +0 -3656
- package/dist/wasm/mufl-bindings.js.map +0 -1
- package/dist/wasm/mufl-bindings.wasm +0 -0
- package/dist/wasm/wasm_types.d.ts +0 -97
- package/dist/wasm/wasm_types.d.ts.map +0 -1
- package/dist/wasm/wasm_types.js +0 -2
- package/dist/wasm/wasm_types.js.map +0 -1
- package/dist/wrapper/conversion.d.ts +0 -9
- package/dist/wrapper/conversion.d.ts.map +0 -1
- package/dist/wrapper/conversion.js +0 -41
- package/dist/wrapper/conversion.js.map +0 -1
- package/dist/wrapper/index.d.ts +0 -11
- package/dist/wrapper/index.d.ts.map +0 -1
- package/dist/wrapper/index.js +0 -25
- package/dist/wrapper/index.js.map +0 -1
- package/dist/wrapper/memory_management/adapt_builder.d.ts +0 -36
- package/dist/wrapper/memory_management/adapt_builder.d.ts.map +0 -1
- package/dist/wrapper/memory_management/adapt_builder.js +0 -98
- package/dist/wrapper/memory_management/adapt_builder.js.map +0 -1
- package/dist/wrapper/memory_management/exit_handler_registrar.d.ts +0 -10
- package/dist/wrapper/memory_management/exit_handler_registrar.d.ts.map +0 -1
- package/dist/wrapper/memory_management/exit_handler_registrar.js +0 -38
- package/dist/wrapper/memory_management/exit_handler_registrar.js.map +0 -1
- package/dist/wrapper/protocol/message_handler_interfaces.d.ts +0 -32
- package/dist/wrapper/protocol/message_handler_interfaces.d.ts.map +0 -1
- package/dist/wrapper/protocol/message_handler_interfaces.js +0 -2
- package/dist/wrapper/protocol/message_handler_interfaces.js.map +0 -1
- package/dist/wrapper/protocol/protocol.d.ts +0 -174
- package/dist/wrapper/protocol/protocol.d.ts.map +0 -1
- package/dist/wrapper/protocol/protocol.js +0 -410
- package/dist/wrapper/protocol/protocol.js.map +0 -1
|
@@ -1,611 +0,0 @@
|
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
import { AdaptObjectBuilder, ExitHandlerRegistrar, object_to_adapt_value, Protocol } from '../../../../wrapper/index.js';
|
|
8
|
-
import { AdaptProtocolError, AdaptProtocolErrorType, AdaptWaitlist, AsyncQueueAdapter, Callback, LazyMessage, LoggerProxy, logging, log_fn_call, MessageDependency } from '../../../common/index.js';
|
|
9
|
-
import { AdaptEnvironment, AdaptObjectLifetime } from '@adapt-toolkit/sdk/backend';
|
|
10
|
-
import { ControlPacketConfigurator } from "../../configurators/control_packet_configurator.js";
|
|
11
|
-
import { ControlPacket } from "../../enclave/control_packet.js";
|
|
12
|
-
const adapt_packet_wrapper_impl_logger_proxy = new LoggerProxy("adapt packet wrapper impl");
|
|
13
|
-
export class AdaptPacketWrapperImpl {
|
|
14
|
-
adapt_wrapper;
|
|
15
|
-
builder = new AdaptObjectBuilder();
|
|
16
|
-
queue = new AsyncQueueAdapter(this.worker.bind(this));
|
|
17
|
-
worker_functions;
|
|
18
|
-
registration_accepted = false;
|
|
19
|
-
pending_messages = [];
|
|
20
|
-
waitlist;
|
|
21
|
-
pending_transactions;
|
|
22
|
-
first_messages;
|
|
23
|
-
prepared_to_execute_first_messages = false;
|
|
24
|
-
// web code sets this callback. Packet Wrapper calls this callback on every verify request from the packet
|
|
25
|
-
#on_verify_request;
|
|
26
|
-
// same here, setter is only availabe in browser
|
|
27
|
-
#on_return_data;
|
|
28
|
-
#on_transaction_failure;
|
|
29
|
-
container_id;
|
|
30
|
-
packet;
|
|
31
|
-
identity_proof_document;
|
|
32
|
-
control_packet;
|
|
33
|
-
create_create_packet_message() {
|
|
34
|
-
return AdaptObjectBuilder.execute_and_collect_garbage(builder => {
|
|
35
|
-
const args = builder.Attach(this.packet.CreateDictionary()
|
|
36
|
-
.Mutate(Protocol.FieldName.packet_info, builder.Attach(this.packet.CreateDictionary().Mutate(Protocol.FieldName.packet_id, this.packet.GetContainerID()).Mutate(Protocol.FieldName.state, this.packet.GetHash()))));
|
|
37
|
-
const create_packet = Protocol.CreateProtocolMessage(Protocol.MessageName.w2d_create_packet, { from: this.packet.GetContainerID(), body: args }).Detach();
|
|
38
|
-
return create_packet;
|
|
39
|
-
}, e => {
|
|
40
|
-
const message = e instanceof Error ? e.message : e;
|
|
41
|
-
throw new AdaptProtocolError(AdaptProtocolErrorType.INTERNAL_ERROR, "Internal error: while trying to create 'create_packet' message: " + message);
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
create_write_snapshot_message() {
|
|
45
|
-
return AdaptObjectBuilder.execute_and_collect_garbage(builder => {
|
|
46
|
-
// send snapshot data to the data storage
|
|
47
|
-
const packet_arg = builder.Attach(this.packet.CreateDictionary().Mutate(Protocol.FieldName.packet_data, this.packet.NewBinaryFromHex(Buffer.from(this.packet.Serialize()).toString('hex'))).Mutate(Protocol.FieldName.packet_info, builder.Attach(this.packet.CreateDictionary().Mutate(Protocol.FieldName.packet_id, this.packet.GetContainerID()).Mutate(Protocol.FieldName.state, this.packet.GetHash()))));
|
|
48
|
-
let write_snapshot_args = builder.Attach(this.packet.CreateDictionary().Mutate(Protocol.FieldName.packet, packet_arg));
|
|
49
|
-
const write_snapshot = Protocol.CreateProtocolMessage(Protocol.MessageName.w2d_write_snapshot, { from: builder.AdaptValue.New(this.packet.GetContainerID()), body: write_snapshot_args }).Detach();
|
|
50
|
-
return write_snapshot;
|
|
51
|
-
}, e => {
|
|
52
|
-
const message = e instanceof Error ? e.message : e;
|
|
53
|
-
throw new AdaptProtocolError(AdaptProtocolErrorType.INTERNAL_ERROR, "Internal error: while trying to create 'write snapshot' message:" + message);
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
load_attestation_document(is_control_packet = false) {
|
|
57
|
-
return AdaptObjectBuilder.execute_and_collect_garbage(builder => {
|
|
58
|
-
const execute_transaction = (trn_body) => {
|
|
59
|
-
builder.Attach(trn_body);
|
|
60
|
-
logging.info("Executing transaction in the packet: ", trn_body.Visualize());
|
|
61
|
-
const trn_result = builder.Attach(this.packet.ExecuteTransaction(trn_body));
|
|
62
|
-
const result_type = Protocol.GetTransactionResultKind(trn_result);
|
|
63
|
-
if (result_type !== 'SUC')
|
|
64
|
-
throw new Error("Internal error: transaction " + trn_body.Reduce(Protocol.FieldName.name).Visualize() + " failed.");
|
|
65
|
-
logging.info("Packet state updated. Previous state: ", builder.Attach(this.packet.GetHash()).Visualize().substring(2));
|
|
66
|
-
if (this.packet.lifetime == this.builder.lifetime || !this.packet.lifetime)
|
|
67
|
-
this.packet.Destroy();
|
|
68
|
-
this.packet = trn_result.GetPacket().Clone(this.builder.lifetime);
|
|
69
|
-
logging.info("New state: ", builder.Attach(this.packet.GetHash()).Visualize().substring(2));
|
|
70
|
-
};
|
|
71
|
-
if (!is_control_packet && this.adapt_wrapper.config.env === 'enclave') {
|
|
72
|
-
if (!this.adapt_wrapper.control_packet || !this.adapt_wrapper.control_packet.packet) {
|
|
73
|
-
throw new Error("Control packet in enclave was not set.");
|
|
74
|
-
}
|
|
75
|
-
const control_packet_ip_document = builder.Attach(this.adapt_wrapper.control_packet.packet.identity_proof_document);
|
|
76
|
-
execute_transaction(object_to_adapt_value({
|
|
77
|
-
name: "::control_packet_identity_proof_document::set_identity_proof_document",
|
|
78
|
-
targ: control_packet_ip_document
|
|
79
|
-
}));
|
|
80
|
-
}
|
|
81
|
-
execute_transaction(object_to_adapt_value({
|
|
82
|
-
name: "::platform_dependent_attestation_document::load_attestation_document",
|
|
83
|
-
targ: this.packet.ExecuteTransaction(builder.Attach(object_to_adapt_value({
|
|
84
|
-
name: "::attestation_document::create",
|
|
85
|
-
targ: false
|
|
86
|
-
})))
|
|
87
|
-
}));
|
|
88
|
-
}, e => {
|
|
89
|
-
const message = e instanceof Error ? e.message : e;
|
|
90
|
-
throw new AdaptProtocolError(AdaptProtocolErrorType.INTERNAL_ERROR, "Internal error while creating attestation document: " + message);
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
create_registration_message() {
|
|
94
|
-
return AdaptObjectBuilder.execute_and_collect_garbage(builder => {
|
|
95
|
-
const args = builder.Attach(Protocol.GetProtocolContainer().CreateDictionary().Mutate(Protocol.FieldName.ip_document, builder.Attach(Protocol.GetIdentityProofDocument(this.packet))));
|
|
96
|
-
const message = Protocol.CreateProtocolMessage(Protocol.MessageName.w2b_reg, { from: builder.AdaptValue.New(builder.Attach(this.packet.GetContainerID())), body: args }).Detach();
|
|
97
|
-
return message;
|
|
98
|
-
}, e => {
|
|
99
|
-
const message = e instanceof Error ? e.message : e;
|
|
100
|
-
throw new AdaptProtocolError(AdaptProtocolErrorType.INTERNAL_ERROR, "Internal error while creating registration message: " + message);
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
constructor(adapt_packet_wrapper, packet, config, adapt_wrapper, messages, is_backup) {
|
|
104
|
-
this.adapt_wrapper = adapt_wrapper;
|
|
105
|
-
this.packet = packet;
|
|
106
|
-
this.builder.Attach(this.packet);
|
|
107
|
-
// Finalize this wrapper's builder lifetime at process exit so the packet,
|
|
108
|
-
// identity-proof document, and anything scoped to it are freed (mirrors the
|
|
109
|
-
// protocol container's exit handler). Without this they outlive the process
|
|
110
|
-
// and the leak tracker reports them.
|
|
111
|
-
// Free this.packet explicitly (it may have drifted off builder.lifetime after a
|
|
112
|
-
// reassignment) then finalize the builder for everything else scoped to it.
|
|
113
|
-
ExitHandlerRegistrar.getInstance().registerOnExitHandler(() => { this.packet.Destroy(); this.builder.Destroy(); });
|
|
114
|
-
this.container_id = AdaptObjectBuilder.execute_and_collect_garbage(b => b.Attach(this.packet.GetContainerID()).Visualize());
|
|
115
|
-
this.control_packet = config instanceof ControlPacketConfigurator ? new ControlPacket(config, adapt_packet_wrapper, adapt_wrapper) : undefined;
|
|
116
|
-
this.waitlist = new AdaptWaitlist();
|
|
117
|
-
logging.debug("Creating adapt packet wrapper.");
|
|
118
|
-
this.worker_functions = new Map([
|
|
119
|
-
[Protocol.MessageName.b2w_reg_ok, this.b2w_reg_ok_v1_handler.bind(this)],
|
|
120
|
-
[Protocol.MessageName.b2w_exec_transaction, this.b2w_exec_transaction_v1_handler.bind(this)],
|
|
121
|
-
[Protocol.MessageName.d2w_write_transaction_confirm, this.d2w_write_transaction_confirm_v1_handler.bind(this)],
|
|
122
|
-
[Protocol.MessageName.d2w_write_snapshot_confirm, this.d2w_write_snapshot_confirm_v1_handler.bind(this)],
|
|
123
|
-
[Protocol.MessageName.d2w_create_packet_confirm, this.d2w_create_packet_confirm_v1_handler.bind(this)]
|
|
124
|
-
]);
|
|
125
|
-
this.queue.resume();
|
|
126
|
-
this.pending_transactions = new AsyncQueueAdapter(this.pending_transactions_worker.bind(this));
|
|
127
|
-
if (!is_backup)
|
|
128
|
-
this.load_attestation_document(config instanceof ControlPacketConfigurator);
|
|
129
|
-
this.identity_proof_document = this.builder.Attach(this.packet.ExecuteTransaction(this.builder.Attach(object_to_adapt_value({
|
|
130
|
-
name: "::identity_proof_document::create",
|
|
131
|
-
targ: undefined
|
|
132
|
-
}))));
|
|
133
|
-
this.first_messages = messages;
|
|
134
|
-
const first_message_cb = (() => {
|
|
135
|
-
logging.info(`Packet with id ${AdaptObjectBuilder.execute_and_collect_garbage(b => b.Attach(this.packet.GetContainerID()).Visualize())} created and prepared to execute first messages.`);
|
|
136
|
-
this.prepared_to_execute_first_messages = true;
|
|
137
|
-
this.first_messages.forEach(message => this.on_first_message(message));
|
|
138
|
-
}).bind(this);
|
|
139
|
-
const registration_message_callback = (() => {
|
|
140
|
-
const registration_message = this.create_registration_message();
|
|
141
|
-
this.send_to_adapt_wrappper_impl(registration_message, true);
|
|
142
|
-
}).bind(this);
|
|
143
|
-
if (is_backup) {
|
|
144
|
-
registration_message_callback();
|
|
145
|
-
first_message_cb();
|
|
146
|
-
}
|
|
147
|
-
else if (this.adapt_wrapper.storage_available) {
|
|
148
|
-
logging.debug("Creating packet wrapper with available data storage.");
|
|
149
|
-
const create_packet_message = this.create_create_packet_message();
|
|
150
|
-
const write_snapshot_message = this.create_write_snapshot_message();
|
|
151
|
-
logging.debug("Sending the registration message to the broker and create packet/write snapshot messages to the data storage.");
|
|
152
|
-
this.waitlist.add([
|
|
153
|
-
new MessageDependency(create_packet_message.GetHash().Visualize(), new Callback(this.send_to_adapt_wrapper.bind(this, write_snapshot_message))),
|
|
154
|
-
new MessageDependency(write_snapshot_message.GetHash().Visualize(), new Callback(registration_message_callback))
|
|
155
|
-
], first_message_cb);
|
|
156
|
-
this.send_to_adapt_wrapper(create_packet_message);
|
|
157
|
-
}
|
|
158
|
-
else {
|
|
159
|
-
logging.debug("Created packet without access to the data storage.");
|
|
160
|
-
logging.debug("Sending the registration message to the broker.");
|
|
161
|
-
registration_message_callback();
|
|
162
|
-
logging.debug("Executing first messages.");
|
|
163
|
-
first_message_cb();
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
add_client_message(message) {
|
|
167
|
-
let messages = [].concat(message);
|
|
168
|
-
if (this.prepared_to_execute_first_messages) {
|
|
169
|
-
messages.forEach(m => this.on_client_message(m));
|
|
170
|
-
}
|
|
171
|
-
else {
|
|
172
|
-
this.first_messages.push(...messages);
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
/**
|
|
176
|
-
* Message from the adapt wrapper
|
|
177
|
-
* @param message
|
|
178
|
-
*/
|
|
179
|
-
on_message(message) {
|
|
180
|
-
// message processing logic
|
|
181
|
-
logging.message_received('adapt_wrapper', 'packet_wrapper', message, this.packet);
|
|
182
|
-
this.queue.push({
|
|
183
|
-
kind: 'incoming_message',
|
|
184
|
-
data: message
|
|
185
|
-
});
|
|
186
|
-
}
|
|
187
|
-
send_to_adapt_wrapper(message) {
|
|
188
|
-
this.queue.push({
|
|
189
|
-
kind: 'outgoing_message',
|
|
190
|
-
data: message
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
|
-
transaction_destination(message) {
|
|
194
|
-
if (Protocol.GetTypeId(message) !== Protocol.MessageName.w2b_transaction)
|
|
195
|
-
return undefined;
|
|
196
|
-
return AdaptObjectBuilder.execute_and_collect_garbage(builder => builder.Attach(Protocol.GetTo(message)).Visualize());
|
|
197
|
-
}
|
|
198
|
-
is_local_transaction(message) {
|
|
199
|
-
const to = this.transaction_destination(message);
|
|
200
|
-
return to !== undefined && this.adapt_wrapper.packet_manager.packets.has(to);
|
|
201
|
-
}
|
|
202
|
-
flush_pending_messages_for(container_id) {
|
|
203
|
-
if (this.pending_messages.length === 0)
|
|
204
|
-
return;
|
|
205
|
-
const flushed = [];
|
|
206
|
-
this.pending_messages = this.pending_messages.filter(message => {
|
|
207
|
-
if (this.transaction_destination(message) !== container_id)
|
|
208
|
-
return true;
|
|
209
|
-
flushed.push(message);
|
|
210
|
-
return false;
|
|
211
|
-
});
|
|
212
|
-
flushed.forEach(message => this.send_to_adapt_wrapper(message));
|
|
213
|
-
}
|
|
214
|
-
send_to_adapt_wrappper_impl(message, registration_message = false) {
|
|
215
|
-
const type_id = Protocol.GetTypeId(message);
|
|
216
|
-
let to_storage = type_id.startsWith('w2d');
|
|
217
|
-
if (!to_storage && !this.registration_accepted && !registration_message && !this.is_local_transaction(message)) {
|
|
218
|
-
logging.debug("Message not forwarded to adapt wrapper. Registration wasn't accepted yet.");
|
|
219
|
-
logging.debug("Adding message to the list of pending messages:", new LazyMessage(() => message.Visualize()));
|
|
220
|
-
this.pending_messages.push(message);
|
|
221
|
-
return;
|
|
222
|
-
}
|
|
223
|
-
logging.message_sent('packet_wrapper', 'adapt_wrapper', message);
|
|
224
|
-
this.adapt_wrapper.receive_message(message);
|
|
225
|
-
}
|
|
226
|
-
on_first_message(message) {
|
|
227
|
-
logging.debug('Received first message:', new LazyMessage(() => new LazyMessage(() => message.Visualize())));
|
|
228
|
-
this.queue.push({
|
|
229
|
-
kind: 'first_or_client_message',
|
|
230
|
-
data: message
|
|
231
|
-
});
|
|
232
|
-
}
|
|
233
|
-
on_client_message(message) {
|
|
234
|
-
logging.debug("Received message from a client:", new LazyMessage(() => message.Visualize()));
|
|
235
|
-
this.queue.push({
|
|
236
|
-
kind: 'first_or_client_message',
|
|
237
|
-
data: message
|
|
238
|
-
});
|
|
239
|
-
}
|
|
240
|
-
worker(task, cb) {
|
|
241
|
-
try {
|
|
242
|
-
if (task.kind === 'incoming_message') {
|
|
243
|
-
this.incoming_message_handler(task);
|
|
244
|
-
}
|
|
245
|
-
else if (task.kind === 'first_or_client_message') {
|
|
246
|
-
this.first_or_client_message_handler(task);
|
|
247
|
-
}
|
|
248
|
-
else {
|
|
249
|
-
this.send_to_adapt_wrappper_impl(task.data);
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
catch (e) {
|
|
253
|
-
logging.error(e instanceof Error ? e.stack : e);
|
|
254
|
-
}
|
|
255
|
-
finally {
|
|
256
|
-
cb();
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
first_or_client_message_handler(task) {
|
|
260
|
-
this.b2w_exec_transaction_v1_handler(task.data, true);
|
|
261
|
-
}
|
|
262
|
-
incoming_message_handler(task) {
|
|
263
|
-
const message_type_id = Protocol.GetTypeId(task.data);
|
|
264
|
-
const func = this.worker_functions.get(message_type_id);
|
|
265
|
-
if (func)
|
|
266
|
-
func(task.data);
|
|
267
|
-
else
|
|
268
|
-
throw new AdaptProtocolError(AdaptProtocolErrorType.INVALID_MESSAGE, "Unrecognized message type id: " + message_type_id.toString());
|
|
269
|
-
}
|
|
270
|
-
b2w_reg_ok_v1_handler(message) {
|
|
271
|
-
message.Destroy();
|
|
272
|
-
if (this.registration_accepted) {
|
|
273
|
-
logging.debug("Ignoring duplicate registration confirmation from broker");
|
|
274
|
-
return;
|
|
275
|
-
}
|
|
276
|
-
logging.debug("Adapt wrapper received confirmation of registration from broker");
|
|
277
|
-
this.registration_accepted = true;
|
|
278
|
-
const pending = this.pending_messages;
|
|
279
|
-
this.pending_messages = [];
|
|
280
|
-
for (let i = pending.length - 1; i >= 0; i--) {
|
|
281
|
-
this.queue.unshift({
|
|
282
|
-
kind: 'outgoing_message',
|
|
283
|
-
data: pending[i]
|
|
284
|
-
});
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
d2w_write_transaction_confirm_v1_handler(message) {
|
|
288
|
-
this.process_confirmation_message(message);
|
|
289
|
-
}
|
|
290
|
-
d2w_write_snapshot_confirm_v1_handler(message) {
|
|
291
|
-
this.process_confirmation_message(message);
|
|
292
|
-
}
|
|
293
|
-
d2w_create_packet_confirm_v1_handler(message) {
|
|
294
|
-
this.process_confirmation_message(message);
|
|
295
|
-
}
|
|
296
|
-
process_confirmation_message(message) {
|
|
297
|
-
AdaptObjectBuilder.execute_and_collect_garbage(builder => {
|
|
298
|
-
builder.Attach(message);
|
|
299
|
-
const message_hash = builder.Attach(Protocol.GetMessageHash(message));
|
|
300
|
-
this.waitlist.satisfy(message_hash.Visualize(), message.Clone());
|
|
301
|
-
}, e => {
|
|
302
|
-
const message = e instanceof Error ? e.message : e;
|
|
303
|
-
throw new Error("Error while processing confirmation message: " + message);
|
|
304
|
-
});
|
|
305
|
-
}
|
|
306
|
-
/**
|
|
307
|
-
* Transactions processing workflow:
|
|
308
|
-
* When b2w_exec_transaction_v1 is received by adapt packet wrapper, the message is added to the queue of pending transactions.
|
|
309
|
-
* This queue process one transactions at time.
|
|
310
|
-
*/
|
|
311
|
-
b2w_exec_transaction_v1_handler(message, is_first_message = false) {
|
|
312
|
-
// Ensure, that container id in 'to' field is the same as the container id manages by the wrapper and validate attestation document of the issuer container
|
|
313
|
-
if (is_first_message) {
|
|
314
|
-
this.pending_transactions.push({ trn: message, is_user_transaction: true });
|
|
315
|
-
return;
|
|
316
|
-
}
|
|
317
|
-
AdaptObjectBuilder.execute_and_collect_garbage(builder => {
|
|
318
|
-
const to = builder.Attach(Protocol.GetTo(message));
|
|
319
|
-
if (!to.Equals(builder.Attach(this.packet.GetContainerID())))
|
|
320
|
-
throw new AdaptProtocolError(AdaptProtocolErrorType.LOGIC_ERROR, "Invalid container id of incoming transaction message." + "Expected: " + builder.Attach(this.packet.GetContainerID()).Visualize() + ", but received: " + to.Visualize());
|
|
321
|
-
const body = builder.Attach(Protocol.GetBody(message));
|
|
322
|
-
const ip_document = body.Reduce(Protocol.FieldName.ip_document);
|
|
323
|
-
// TODO: check if attestation document of the container is known to us, if not, attestation document in the message should not be NIL
|
|
324
|
-
// if (!is_first_message) {
|
|
325
|
-
// try {
|
|
326
|
-
// builder.Attach(Protocol.ValidateIdentityProofDocument(ip_document, builder.AdaptEnvironment.SystemTime()));
|
|
327
|
-
// } catch (e) {
|
|
328
|
-
// const message = e instanceof Error ? e.message : e;
|
|
329
|
-
// throw new AdaptProtocolError(AdaptProtocolErrorType.IP_DOCUMENT_VALIDATION_FAILURE, "Attestation document validation failed: " + message);
|
|
330
|
-
// }
|
|
331
|
-
// }
|
|
332
|
-
// logging.debug("Idenity proof document validated.");
|
|
333
|
-
});
|
|
334
|
-
// add transaction to the queue of pending transactions
|
|
335
|
-
this.pending_transactions.push({ trn: message, is_user_transaction: false });
|
|
336
|
-
}
|
|
337
|
-
// ========================= pending transactions worker and related methods ======================
|
|
338
|
-
pending_transactions_worker(event, cb) {
|
|
339
|
-
try {
|
|
340
|
-
this.execute_transaction(event);
|
|
341
|
-
}
|
|
342
|
-
catch (e) {
|
|
343
|
-
const message = e instanceof Error ? e.message : e;
|
|
344
|
-
logging.error("while executing transaction:", message);
|
|
345
|
-
if (this.#on_transaction_failure && e instanceof Error) {
|
|
346
|
-
this.#on_transaction_failure(e.message);
|
|
347
|
-
}
|
|
348
|
-
this.pending_transactions.resume(); // if transaction failed, next transactions can be processed
|
|
349
|
-
}
|
|
350
|
-
finally {
|
|
351
|
-
cb();
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
create_write_transaction_message(trn_result, transient_data_encrypted, request_data_encrypted) {
|
|
355
|
-
return AdaptObjectBuilder.execute_and_collect_garbage(builder => {
|
|
356
|
-
const args = builder.Attach(Protocol.GetProtocolContainer().CreateDictionary()
|
|
357
|
-
.Mutate(Protocol.FieldName.state_change, builder.Attach(Protocol.GetProtocolContainer().CreateDictionary())
|
|
358
|
-
.Mutate(Protocol.FieldName.final_state_id,
|
|
359
|
-
// trn_result is Detach()ed in execute_transaction, so its GetPacket()
|
|
360
|
-
// wrapper has no lifetime; scope it so it is freed with this builder.
|
|
361
|
-
builder.Attach(trn_result.GetPacket()).GetHash())
|
|
362
|
-
.Mutate(Protocol.FieldName.transaction, builder.Attach(Protocol.GetProtocolContainer().CreateDictionary().
|
|
363
|
-
Mutate(Protocol.FieldName.transient_data_encrypted, transient_data_encrypted).
|
|
364
|
-
Mutate(Protocol.FieldName.request_data_encrypted, request_data_encrypted))))
|
|
365
|
-
.Mutate(Protocol.FieldName.packet_info, builder.Attach(Protocol.CreatePacketInfo(this.packet))));
|
|
366
|
-
const write_transaction_message = Protocol.CreateProtocolMessage(Protocol.MessageName.w2d_write_transaction, { from: builder.AdaptValue.New(this.packet.GetContainerID()), body: args }).Detach();
|
|
367
|
-
return write_transaction_message;
|
|
368
|
-
});
|
|
369
|
-
}
|
|
370
|
-
execute_transaction({ trn, is_user_transaction }) {
|
|
371
|
-
this.pending_transactions.pause();
|
|
372
|
-
const builder = new AdaptObjectBuilder();
|
|
373
|
-
try {
|
|
374
|
-
// The incoming transaction message is consumed by this call; scope it so it
|
|
375
|
-
// is freed with the builder. This also frees locally-delivered envelopes
|
|
376
|
-
// (#deliver_locally builds them via CreateProtocolMessage and hands them in
|
|
377
|
-
// as `trn`), which otherwise leak once per local transaction.
|
|
378
|
-
builder.Attach(trn);
|
|
379
|
-
let envelope;
|
|
380
|
-
if (is_user_transaction) {
|
|
381
|
-
logging.debug("Executing user transaction in the packet: ", new LazyMessage(() => trn.Visualize()));
|
|
382
|
-
envelope = trn;
|
|
383
|
-
}
|
|
384
|
-
else {
|
|
385
|
-
logging.debug("Executing a transaction in the packet");
|
|
386
|
-
const body = builder.Attach(Protocol.GetBody(trn));
|
|
387
|
-
envelope = body.Reduce(Protocol.FieldName.envlp);
|
|
388
|
-
const trn_body = envelope.Reduce(Protocol.FieldName.body);
|
|
389
|
-
logging.debug("Executing transaction: ", new LazyMessage(() => builder.Attach(Protocol.DescribeTransaction(this.packet, trn_body)).Visualize()));
|
|
390
|
-
}
|
|
391
|
-
// generate and save entropy and timestamp
|
|
392
|
-
const entropy = builder.AdaptEnvironment.GetRandomBytes(256);
|
|
393
|
-
const time = builder.AdaptEnvironment.SystemTime();
|
|
394
|
-
// execute transaction
|
|
395
|
-
const trn_result = this.packet.ExecuteTransaction(envelope, entropy.Visualize().substring(2), time).Detach();
|
|
396
|
-
logging.info("Adapt transaction output: ", AdaptEnvironment.getStdoutContents(), AdaptEnvironment.getStderrContents());
|
|
397
|
-
// check, whether transaction succeeded. Otherwise, do not continue processing the transaction
|
|
398
|
-
const transaction_result_type = Protocol.GetTransactionResultKind(trn_result);
|
|
399
|
-
if (transaction_result_type === 'FAIL') {
|
|
400
|
-
throw new AdaptProtocolError(AdaptProtocolErrorType.TRANSACTION_FAILURE, "Transaction failed with message " + trn_result.Reduce(Protocol.FieldName.result).Visualize());
|
|
401
|
-
}
|
|
402
|
-
logging.debug("Container hash before transaction:", new LazyMessage(() => this.packet.GetHash().Visualize()));
|
|
403
|
-
logging.debug("Transaction result:", new LazyMessage(() => trn_result.Visualize()));
|
|
404
|
-
logging.debug("Container hash after transaction:", new LazyMessage(() => AdaptObjectBuilder.execute_and_collect_garbage(b => b.Attach(trn_result.GetPacket()).GetHash().Visualize())));
|
|
405
|
-
if (this.adapt_wrapper.storage_available) {
|
|
406
|
-
// encrypt transaction request and transient data with encryption key of this container
|
|
407
|
-
const transient_data = builder.Attach(this.packet.CreateDictionary().Mutate(Protocol.FieldName.timestamp, time).Mutate(Protocol.FieldName.entropy, entropy.Visualize().substring(2)));
|
|
408
|
-
const transient_data_encrypted = builder.Attach(this.packet.ExecuteTransaction(builder.Attach(object_to_adapt_value({
|
|
409
|
-
name: "::key_storage_api::default_encrypt",
|
|
410
|
-
targ: builder.Attach(object_to_adapt_value({
|
|
411
|
-
message: transient_data,
|
|
412
|
-
recipient_container_id: this.packet.GetContainerID()
|
|
413
|
-
}))
|
|
414
|
-
}))));
|
|
415
|
-
const request_data_encrypted = builder.Attach(this.packet.ExecuteTransaction(builder.Attach(object_to_adapt_value({
|
|
416
|
-
name: "::key_storage_api::default_encrypt",
|
|
417
|
-
targ: builder.Attach(object_to_adapt_value({
|
|
418
|
-
message: envelope,
|
|
419
|
-
recipient_container_id: this.packet.GetContainerID()
|
|
420
|
-
}))
|
|
421
|
-
}))));
|
|
422
|
-
const write_transaction_message = this.create_write_transaction_message(trn_result, transient_data_encrypted, request_data_encrypted);
|
|
423
|
-
const write_transaction_message_hash = write_transaction_message.GetHash().Visualize();
|
|
424
|
-
this.waitlist.add([new MessageDependency(write_transaction_message_hash)], this.process_transaction_result.bind(this, trn_result));
|
|
425
|
-
this.send_to_adapt_wrapper(write_transaction_message);
|
|
426
|
-
logging.debug("write transaction message:", new LazyMessage(() => write_transaction_message.Visualize()));
|
|
427
|
-
}
|
|
428
|
-
else {
|
|
429
|
-
this.process_transaction_result(trn_result);
|
|
430
|
-
}
|
|
431
|
-
}
|
|
432
|
-
finally {
|
|
433
|
-
// The local builder owns only this call's transients (entropy, time,
|
|
434
|
-
// envelope, transient data). trn_result and write_transaction_message
|
|
435
|
-
// are Detach()ed and outlive this scope, so finalizing here is safe.
|
|
436
|
-
builder.Destroy();
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
process_transaction_result(message) {
|
|
440
|
-
AdaptObjectBuilder.execute_and_collect_garbage(builder => {
|
|
441
|
-
logging.info("Processing transaction result:", message.Visualize());
|
|
442
|
-
logging.info("Container state before transaction:", builder.Attach(this.packet.GetHash()).Visualize());
|
|
443
|
-
builder.Attach(message);
|
|
444
|
-
const transaction_result = Protocol.GetTransactionResultKind(message);
|
|
445
|
-
const result = message.Reduce(Protocol.FieldName.result);
|
|
446
|
-
if (transaction_result === 'SUC') {
|
|
447
|
-
if (this.packet.lifetime == this.builder.lifetime || !this.packet.lifetime)
|
|
448
|
-
this.packet.Destroy();
|
|
449
|
-
this.packet = message.GetPacket().Clone(this.builder.lifetime);
|
|
450
|
-
logging.info("Packet state updated. New state: ", builder.Attach(this.packet.GetHash()).Visualize());
|
|
451
|
-
let idx = 0;
|
|
452
|
-
let value;
|
|
453
|
-
while (!(value = result.Reduce(idx)).IsNil()) {
|
|
454
|
-
idx++;
|
|
455
|
-
const action_kind = value.Reduce(Protocol.FieldName.action_kind).Visualize();
|
|
456
|
-
if (action_kind === "RET") {
|
|
457
|
-
if (this.packet.lifetime == this.builder.lifetime || !this.packet.lifetime)
|
|
458
|
-
this.packet.Destroy();
|
|
459
|
-
if (this.control_packet) {
|
|
460
|
-
const packet = message.GetPacket().Clone(this.builder.lifetime);
|
|
461
|
-
this.control_packet.on_message(value.Reduce(Protocol.FieldName.data).Detach(), cb => {
|
|
462
|
-
this.packet = packet;
|
|
463
|
-
logging.info("Packet state updated. New state: ", this.packet.GetHash().Visualize());
|
|
464
|
-
if (cb)
|
|
465
|
-
cb();
|
|
466
|
-
this.pending_transactions.resume();
|
|
467
|
-
});
|
|
468
|
-
return;
|
|
469
|
-
}
|
|
470
|
-
this.packet = message.GetPacket().Clone(this.builder.lifetime);
|
|
471
|
-
logging.info("Packet state updated. New state: ", builder.Attach(this.packet.GetHash()).Visualize());
|
|
472
|
-
// Give the callback a packet on a scratch lifetime we finalize right
|
|
473
|
-
// after it returns. If the handler ignores the 2nd arg, the scratch frees
|
|
474
|
-
// the clone; if it re-homes it (Attach to its own scope), the clone is
|
|
475
|
-
// detached from the scratch so Finalize is a no-op and the handler owns
|
|
476
|
-
// it. Either way no leak, and the wrapper's this.packet is never exposed.
|
|
477
|
-
if (this.#on_return_data) {
|
|
478
|
-
const ret_scope = new AdaptObjectLifetime();
|
|
479
|
-
this.#on_return_data(value.Reduce(Protocol.FieldName.data).Detach(), this.packet.Clone(ret_scope));
|
|
480
|
-
ret_scope.Finalize();
|
|
481
|
-
}
|
|
482
|
-
}
|
|
483
|
-
else if (action_kind === "SEND") {
|
|
484
|
-
this.send_to_adapt_wrapper(Protocol.CreateTransactionMessageFromEnvelope(value.Reduce(Protocol.FieldName.data)));
|
|
485
|
-
}
|
|
486
|
-
else if (action_kind === "VER") {
|
|
487
|
-
if (this.#on_verify_request)
|
|
488
|
-
this.#on_verify_request(value.Reduce(Protocol.FieldName.data).Detach());
|
|
489
|
-
}
|
|
490
|
-
else if (action_kind === "TIMEOUT") {
|
|
491
|
-
const data = value.Reduce(Protocol.FieldName.data);
|
|
492
|
-
const seconds = data.Reduce('seconds').GetNumber();
|
|
493
|
-
const continuation_id = data.Reduce('continuation_id').Visualize();
|
|
494
|
-
logging.debug("Recieved timeout request. Seconds: ", seconds, "continuation id: ", continuation_id);
|
|
495
|
-
const on_timeout = () => {
|
|
496
|
-
logging.debug("Calling timeout callback.");
|
|
497
|
-
this.pending_transactions.push({
|
|
498
|
-
trn: object_to_adapt_value({ name: "::continuation::continue_transaction", targ: { id: continuation_id, args: false } }).Detach(),
|
|
499
|
-
is_user_transaction: true
|
|
500
|
-
});
|
|
501
|
-
};
|
|
502
|
-
setTimeout(on_timeout.bind(this), seconds * 1000);
|
|
503
|
-
}
|
|
504
|
-
else {
|
|
505
|
-
logging.error("Received invalid transaction action: ", action_kind);
|
|
506
|
-
continue;
|
|
507
|
-
}
|
|
508
|
-
}
|
|
509
|
-
this.pending_transactions.resume();
|
|
510
|
-
}
|
|
511
|
-
else if (transaction_result === 'FAIL') {
|
|
512
|
-
throw new AdaptProtocolError(AdaptProtocolErrorType.INTERNAL_ERROR, "Invalid transaction result. Fail wasn't expected here. It should be handled before");
|
|
513
|
-
}
|
|
514
|
-
else {
|
|
515
|
-
throw new AdaptProtocolError(AdaptProtocolErrorType.INTERNAL_ERROR, "Unexpected transaction result: " + transaction_result + ". Transaction result should be checked before.");
|
|
516
|
-
}
|
|
517
|
-
});
|
|
518
|
-
}
|
|
519
|
-
//----------------------------- browser only methods ---------------------------------------
|
|
520
|
-
set on_verify_request(new_value) {
|
|
521
|
-
this.#on_verify_request = new_value;
|
|
522
|
-
}
|
|
523
|
-
set on_return_data(new_value) {
|
|
524
|
-
this.#on_return_data = new_value;
|
|
525
|
-
}
|
|
526
|
-
set on_transaction_failure(new_value) {
|
|
527
|
-
this.#on_transaction_failure = new_value;
|
|
528
|
-
}
|
|
529
|
-
acceptVerificationRequest(id) {
|
|
530
|
-
AdaptObjectBuilder.execute_and_collect_garbage(builder => {
|
|
531
|
-
const message = object_to_adapt_value({ name: "::verification::accept", targ: builder.Attach(object_to_adapt_value({ id: id })) });
|
|
532
|
-
this.add_client_message(message);
|
|
533
|
-
});
|
|
534
|
-
}
|
|
535
|
-
}
|
|
536
|
-
__decorate([
|
|
537
|
-
log_fn_call(adapt_packet_wrapper_impl_logger_proxy)
|
|
538
|
-
], AdaptPacketWrapperImpl.prototype, "create_create_packet_message", null);
|
|
539
|
-
__decorate([
|
|
540
|
-
log_fn_call(adapt_packet_wrapper_impl_logger_proxy)
|
|
541
|
-
], AdaptPacketWrapperImpl.prototype, "create_write_snapshot_message", null);
|
|
542
|
-
__decorate([
|
|
543
|
-
log_fn_call(adapt_packet_wrapper_impl_logger_proxy)
|
|
544
|
-
], AdaptPacketWrapperImpl.prototype, "load_attestation_document", null);
|
|
545
|
-
__decorate([
|
|
546
|
-
log_fn_call(adapt_packet_wrapper_impl_logger_proxy)
|
|
547
|
-
], AdaptPacketWrapperImpl.prototype, "create_registration_message", null);
|
|
548
|
-
__decorate([
|
|
549
|
-
log_fn_call(adapt_packet_wrapper_impl_logger_proxy)
|
|
550
|
-
], AdaptPacketWrapperImpl.prototype, "add_client_message", null);
|
|
551
|
-
__decorate([
|
|
552
|
-
log_fn_call(adapt_packet_wrapper_impl_logger_proxy)
|
|
553
|
-
], AdaptPacketWrapperImpl.prototype, "on_message", null);
|
|
554
|
-
__decorate([
|
|
555
|
-
log_fn_call(adapt_packet_wrapper_impl_logger_proxy)
|
|
556
|
-
], AdaptPacketWrapperImpl.prototype, "send_to_adapt_wrapper", null);
|
|
557
|
-
__decorate([
|
|
558
|
-
log_fn_call(adapt_packet_wrapper_impl_logger_proxy)
|
|
559
|
-
], AdaptPacketWrapperImpl.prototype, "flush_pending_messages_for", null);
|
|
560
|
-
__decorate([
|
|
561
|
-
log_fn_call(adapt_packet_wrapper_impl_logger_proxy)
|
|
562
|
-
], AdaptPacketWrapperImpl.prototype, "send_to_adapt_wrappper_impl", null);
|
|
563
|
-
__decorate([
|
|
564
|
-
log_fn_call(adapt_packet_wrapper_impl_logger_proxy)
|
|
565
|
-
], AdaptPacketWrapperImpl.prototype, "on_first_message", null);
|
|
566
|
-
__decorate([
|
|
567
|
-
log_fn_call(adapt_packet_wrapper_impl_logger_proxy)
|
|
568
|
-
], AdaptPacketWrapperImpl.prototype, "on_client_message", null);
|
|
569
|
-
__decorate([
|
|
570
|
-
log_fn_call(adapt_packet_wrapper_impl_logger_proxy)
|
|
571
|
-
], AdaptPacketWrapperImpl.prototype, "worker", null);
|
|
572
|
-
__decorate([
|
|
573
|
-
log_fn_call(adapt_packet_wrapper_impl_logger_proxy)
|
|
574
|
-
], AdaptPacketWrapperImpl.prototype, "first_or_client_message_handler", null);
|
|
575
|
-
__decorate([
|
|
576
|
-
log_fn_call(adapt_packet_wrapper_impl_logger_proxy)
|
|
577
|
-
], AdaptPacketWrapperImpl.prototype, "incoming_message_handler", null);
|
|
578
|
-
__decorate([
|
|
579
|
-
log_fn_call(adapt_packet_wrapper_impl_logger_proxy)
|
|
580
|
-
], AdaptPacketWrapperImpl.prototype, "b2w_reg_ok_v1_handler", null);
|
|
581
|
-
__decorate([
|
|
582
|
-
log_fn_call(adapt_packet_wrapper_impl_logger_proxy)
|
|
583
|
-
], AdaptPacketWrapperImpl.prototype, "d2w_write_transaction_confirm_v1_handler", null);
|
|
584
|
-
__decorate([
|
|
585
|
-
log_fn_call(adapt_packet_wrapper_impl_logger_proxy)
|
|
586
|
-
], AdaptPacketWrapperImpl.prototype, "d2w_write_snapshot_confirm_v1_handler", null);
|
|
587
|
-
__decorate([
|
|
588
|
-
log_fn_call(adapt_packet_wrapper_impl_logger_proxy)
|
|
589
|
-
], AdaptPacketWrapperImpl.prototype, "d2w_create_packet_confirm_v1_handler", null);
|
|
590
|
-
__decorate([
|
|
591
|
-
log_fn_call(adapt_packet_wrapper_impl_logger_proxy)
|
|
592
|
-
], AdaptPacketWrapperImpl.prototype, "process_confirmation_message", null);
|
|
593
|
-
__decorate([
|
|
594
|
-
log_fn_call(adapt_packet_wrapper_impl_logger_proxy)
|
|
595
|
-
], AdaptPacketWrapperImpl.prototype, "b2w_exec_transaction_v1_handler", null);
|
|
596
|
-
__decorate([
|
|
597
|
-
log_fn_call(adapt_packet_wrapper_impl_logger_proxy)
|
|
598
|
-
], AdaptPacketWrapperImpl.prototype, "pending_transactions_worker", null);
|
|
599
|
-
__decorate([
|
|
600
|
-
log_fn_call(adapt_packet_wrapper_impl_logger_proxy)
|
|
601
|
-
], AdaptPacketWrapperImpl.prototype, "create_write_transaction_message", null);
|
|
602
|
-
__decorate([
|
|
603
|
-
log_fn_call(adapt_packet_wrapper_impl_logger_proxy)
|
|
604
|
-
], AdaptPacketWrapperImpl.prototype, "execute_transaction", null);
|
|
605
|
-
__decorate([
|
|
606
|
-
log_fn_call(adapt_packet_wrapper_impl_logger_proxy)
|
|
607
|
-
], AdaptPacketWrapperImpl.prototype, "process_transaction_result", null);
|
|
608
|
-
__decorate([
|
|
609
|
-
log_fn_call(adapt_packet_wrapper_impl_logger_proxy)
|
|
610
|
-
], AdaptPacketWrapperImpl.prototype, "acceptVerificationRequest", null);
|
|
611
|
-
//# sourceMappingURL=adapt_packet_wrapper_impl.js.map
|