@adapt-toolkit/mufl 0.8.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 +172 -0
- package/LICENSE.fsl +105 -0
- package/NOTICE +25 -0
- package/README.md +70 -0
- package/bin/mufl-compile.js +4 -0
- package/bin/mufl.js +4 -0
- package/lib/launcher.js +60 -0
- package/lib/paths.js +26 -0
- package/meta/meta.mm +2666 -0
- package/mufl_stdlib/config.mufl +86 -0
- package/mufl_stdlib/continuation.mm +51 -0
- package/mufl_stdlib/control_packet.mu +184 -0
- package/mufl_stdlib/cryptography/address_document.mm +333 -0
- package/mufl_stdlib/cryptography/address_document_types.mm +16 -0
- package/mufl_stdlib/cryptography/attestation/attestation_document.mm +68 -0
- package/mufl_stdlib/cryptography/attestation/config.mufl +12 -0
- package/mufl_stdlib/cryptography/attestation/container_associated_data.mm +12 -0
- package/mufl_stdlib/cryptography/attestation/control_packet_identity_proof_document.mm +36 -0
- package/mufl_stdlib/cryptography/attestation/identity_proof_document_impl.mm +57 -0
- package/mufl_stdlib/cryptography/attestation/identity_proof_document_types.mm +45 -0
- package/mufl_stdlib/cryptography/attestation/node_description.mm +9 -0
- package/mufl_stdlib/cryptography/attestation/platform_dependent_attestation_document/browser/browser_attestation_document.mm +25 -0
- package/mufl_stdlib/cryptography/attestation/platform_dependent_attestation_document/browser/config.mufl +12 -0
- package/mufl_stdlib/cryptography/attestation/platform_dependent_attestation_document/config.mufl +12 -0
- package/mufl_stdlib/cryptography/attestation/platform_dependent_attestation_document/native/config.mufl +12 -0
- package/mufl_stdlib/cryptography/attestation/platform_dependent_attestation_document/native/native_attestation_document.mm +25 -0
- package/mufl_stdlib/cryptography/attestation/platform_dependent_attestation_document/platform_dependent_attestation_document.mm +57 -0
- package/mufl_stdlib/cryptography/authorizing_container.mm +21 -0
- package/mufl_stdlib/cryptography/config.mufl +12 -0
- package/mufl_stdlib/cryptography/encrypted_channel.mm +95 -0
- package/mufl_stdlib/cryptography/key_storage.mm +391 -0
- package/mufl_stdlib/cryptography/key_storage_api.mm +17 -0
- package/mufl_stdlib/cryptography/key_utils.mm +20 -0
- package/mufl_stdlib/cryptography/peer_container.mu +17 -0
- package/mufl_stdlib/cryptography/registration_proof.mm +40 -0
- package/mufl_stdlib/current_transaction_info.mm +78 -0
- package/mufl_stdlib/identity_proof_document.mm +21 -0
- package/mufl_stdlib/integration_test_api.mm +39 -0
- package/mufl_stdlib/lists.mm +84 -0
- package/mufl_stdlib/permissions.mm +219 -0
- package/mufl_stdlib/platform_type_id.mm +20 -0
- package/mufl_stdlib/random.mm +50 -0
- package/mufl_stdlib/rslt.mm +32 -0
- package/mufl_stdlib/transaction_message_decoder.mm +22 -0
- package/mufl_stdlib/transaction_queue.mm +60 -0
- package/mufl_stdlib/vector.mm +115 -0
- package/mufl_stdlib/verification.mm +35 -0
- package/package.json +43 -0
- package/prebuilds/linux-x64/mufl +0 -0
- package/prebuilds/linux-x64/mufl-compile +0 -0
- package/transactions/__t_wrapper.mm +169 -0
- package/transactions/config.mufl +22 -0
- package/transactions/transaction.mm +200 -0
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// adapt generic attestation document
|
|
2
|
+
library attestation_document loads libraries node_description, identity_proof_document_types, current_transaction_info uses transactions {
|
|
3
|
+
metadef t_platform_dependent_attestation_document: identity_proof_document_types::t_platform_dependent_attestation_document.
|
|
4
|
+
|
|
5
|
+
metadef t_attestation_document: identity_proof_document_types::t_attestation_document.
|
|
6
|
+
|
|
7
|
+
metadef t_create: identity_proof_document_types::t_create.
|
|
8
|
+
|
|
9
|
+
metadef t_validate: identity_proof_document_types::t_validate.
|
|
10
|
+
|
|
11
|
+
metadef t_attestation_document_interface: identity_proof_document_types::t_attestation_document_interface.
|
|
12
|
+
|
|
13
|
+
module interface {
|
|
14
|
+
hidden {
|
|
15
|
+
interfaces IS t_attestation_document_interface[] = (,).
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
add_interface = fn (id: int, i: t_attestation_document_interface) {
|
|
19
|
+
abort provisional "Validation function for attestation document with given id(" + (_str id) + ") already defined." WHEN interfaces id != NIL.
|
|
20
|
+
interfaces id -> i.
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
get_interface = fn (id: int) -> t_attestation_document_interface {
|
|
24
|
+
RETURN (interfaces id|).
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
get_creator = fn (id: int) -> t_create {
|
|
28
|
+
RETURN (interfaces id|) $create.
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
get_validator = fn (id: int) -> t_validate {
|
|
32
|
+
RETURN (interfaces id|) $validate.
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
// aborts when validation is failed,) -> TRUE, when succeed
|
|
38
|
+
validate = fn (ad: t_attestation_document, node_dsc: node_description::t_node_description, timestamp: time) -> bool {
|
|
39
|
+
ad => ($platform_type_id -> platform_type_id, $platform_dependent_attestation_document -> platform_dependent_attestation_document).
|
|
40
|
+
abort provisional "Invalid attestation_document type" WHEN (interface::get_interface platform_type_id) == NIL.
|
|
41
|
+
|
|
42
|
+
RETURN (interface::get_validator platform_type_id) platform_dependent_attestation_document node_dsc timestamp.
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
create = fn (_) -> t_attestation_document {
|
|
46
|
+
id = _get_platform_type_id().
|
|
47
|
+
abort provisional "Invalid platform type id provided." WHEN (interface::get_interface id) == NIL.
|
|
48
|
+
node_dsc = node_description::create().
|
|
49
|
+
RETURN (interface::get_creator id) node_dsc.
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
trn readonly create _
|
|
53
|
+
{
|
|
54
|
+
current_transaction_info::validate_origin (transaction::envelope::origin::user,).
|
|
55
|
+
return create ().
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
trn readonly validate
|
|
59
|
+
_:(
|
|
60
|
+
$ad -> ad: t_attestation_document,
|
|
61
|
+
$node_dsc -> node_dsc: node_description::t_node_description,
|
|
62
|
+
$timestamp -> timestamp: time )
|
|
63
|
+
{
|
|
64
|
+
current_transaction_info::validate_origin (transaction::envelope::origin::user,).
|
|
65
|
+
return validate ad node_dsc timestamp.
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
library container_associated_data loads libraries control_packet_identity_proof_document, identity_proof_document_types {
|
|
2
|
+
metadef t_container_associated_data: identity_proof_document_types::t_container_associated_data.
|
|
3
|
+
|
|
4
|
+
create = fn (_) -> t_container_associated_data {
|
|
5
|
+
|
|
6
|
+
control_packet_ip_document_hash is hash_code+ = NIL.
|
|
7
|
+
if _get_platform_type_id() == _get_nitro_platform_type_id() {
|
|
8
|
+
control_packet_ip_document_hash -> control_packet_identity_proof_document::get_hash().
|
|
9
|
+
}
|
|
10
|
+
RETURN ($code_id -> _get_code_id(), $container_id -> _get_container_id(), $control_packet_ip_document_hash -> control_packet_ip_document_hash).
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
library control_packet_identity_proof_document loads libraries identity_proof_document_types, current_transaction_info uses transactions
|
|
2
|
+
{
|
|
3
|
+
is_control_packet is bool = NIL.
|
|
4
|
+
|
|
5
|
+
hidden
|
|
6
|
+
{
|
|
7
|
+
__ip_doc is identity_proof_document_types::t_identity_proof_document+ = NIL.
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
get_hash = fn (_) -> hash_code+
|
|
11
|
+
{
|
|
12
|
+
if (_get_platform_type_id() != _get_nitro_platform_type_id()) || is_control_packet {
|
|
13
|
+
return NIL.
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if _is_test_mode() && !__ip_doc {
|
|
17
|
+
return NIL.
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
abort "Control packet identity proof document wasn't set" when !__ip_doc.
|
|
21
|
+
|
|
22
|
+
return _value_id __ip_doc?.
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
trn set_identity_proof_document
|
|
26
|
+
ip_doc: ?(__ip_doc?)
|
|
27
|
+
{
|
|
28
|
+
current_transaction_info::validate_origin (transaction::envelope::origin::user,).
|
|
29
|
+
platform_type_id = ip_doc $attestation_document $platform_type_id.
|
|
30
|
+
abort "Invalid platform type id of control packet identity proof document." when (platform_type_id != _get_nitro_platform_type_id() && !(_is_test_mode())).
|
|
31
|
+
__ip_doc -> ip_doc.
|
|
32
|
+
return ::transaction::success [].
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
library identity_proof_document_impl loads libraries identity_proof_document_types, node_description, attestation_document,
|
|
2
|
+
key_storage, address_document, address_document_types, platform_dependent_attestation_document
|
|
3
|
+
{
|
|
4
|
+
metadef t_identity_proof_document: identity_proof_document_types::t_identity_proof_document.
|
|
5
|
+
|
|
6
|
+
validate_signature = fn (hash: hash_code, signature: crypto_signature) -> bool {
|
|
7
|
+
RETURN key_storage::check_signature hash signature.
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
hidden {
|
|
11
|
+
validate_signature_by_authorizing_container = fn (hash: hash_code, signature: crypto_signature) -> bool {
|
|
12
|
+
RETURN address_document::check_signature_by_authorizing_container hash signature.
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
validate = fn (ip_document: t_identity_proof_document, timestamp: time) -> bool {
|
|
17
|
+
ip_document => ($node_description -> node_dsc, $attestation_document -> ad).
|
|
18
|
+
identity = node_dsc $address_document $identity.
|
|
19
|
+
sign_key_id = identity $default_keys $SIGN.
|
|
20
|
+
sign_pub IS publickey_sign+ = NIL.
|
|
21
|
+
sc identity $key_list -- (k->) {
|
|
22
|
+
if _crypto_get_key_id k == sign_key_id {
|
|
23
|
+
sign_pub -> k SAFE(publickey_sign).
|
|
24
|
+
break.
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
abort "SIGN key not found in identity key_list" WHEN sign_pub == NIL.
|
|
28
|
+
abort "Identity proof: container id does not commit to signing key"
|
|
29
|
+
WHEN (key_storage::address_of_key sign_pub?) != (identity $container_id).
|
|
30
|
+
identity_hash = _value_id identity.
|
|
31
|
+
ad_self_sig_valid IS bool = FALSE.
|
|
32
|
+
sc (node_dsc $address_document $authorizations) -- (sig ->) {
|
|
33
|
+
if (_crypto_verify_hash_signature identity_hash sig sign_pub?) != NIL {
|
|
34
|
+
ad_self_sig_valid -> TRUE.
|
|
35
|
+
break.
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
abort "Identity proof: address document self-signature is invalid" WHEN !ad_self_sig_valid.
|
|
39
|
+
RETURN (attestation_document::validate ad node_dsc timestamp).
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
authorize_signature = fn (ad: address_document_types::t_address_document, signature: crypto_signature, no_check_for_authorizations: bool) {
|
|
44
|
+
// validate signature of the address document. It now could be signed by any container in the current network. Maybe should be accepted only signature from authorizing containers.
|
|
45
|
+
ad_hash = _value_id ad.
|
|
46
|
+
abort provisional "Invalid signature of address document." WHEN !(validate_signature ad_hash signature).
|
|
47
|
+
// register container in the current network
|
|
48
|
+
address_document::process_address_document ad no_check_for_authorizations. // TODO: how to pass no_check_for_authorizations parameter. Maybe is should not be accested as an argument.
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
create = fn (_) -> t_identity_proof_document {
|
|
52
|
+
node_dsc = node_description::create().
|
|
53
|
+
ad = platform_dependent_attestation_document::get_attestation_document (_get_platform_type_id()).
|
|
54
|
+
RETURN ($node_description -> node_dsc, $attestation_document -> ad).
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
library identity_proof_document_types loads library address_document_types {
|
|
2
|
+
metadef t_container_associated_data: (
|
|
3
|
+
$code_id -> hash_code,
|
|
4
|
+
$container_id -> global_id,
|
|
5
|
+
$control_packet_ip_document_hash -> hash_code+ // NILable, since a control packet is only available in the enclave environment
|
|
6
|
+
). // and other data in the future
|
|
7
|
+
|
|
8
|
+
metadef t_node_description: (
|
|
9
|
+
$address_document -> address_document_types::t_address_document,
|
|
10
|
+
$container_associated_data -> t_container_associated_data
|
|
11
|
+
).
|
|
12
|
+
|
|
13
|
+
metadef t_platform_dependent_attestation_document: any.
|
|
14
|
+
|
|
15
|
+
metadef t_attestation_document: ($platform_dependent_attestation_document -> t_platform_dependent_attestation_document,
|
|
16
|
+
$platform_type_id -> int).
|
|
17
|
+
|
|
18
|
+
metadef t_create: (t_node_description->t_attestation_document).
|
|
19
|
+
|
|
20
|
+
metadef t_validate: (t_platform_dependent_attestation_document->t_node_description->time->bool).
|
|
21
|
+
|
|
22
|
+
metadef t_attestation_document_interface: (
|
|
23
|
+
$create -> t_create,
|
|
24
|
+
$validate -> t_validate
|
|
25
|
+
).
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
metadef t_identity_proof_document: (
|
|
29
|
+
$node_description -> t_node_description,
|
|
30
|
+
$attestation_document -> t_attestation_document
|
|
31
|
+
).
|
|
32
|
+
|
|
33
|
+
hidden {
|
|
34
|
+
m_my_ipd IS t_identity_proof_document+ = NIL.
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
set_my_ipd = fn (ipd: t_identity_proof_document) -> nil {
|
|
38
|
+
m_my_ipd -> ipd.
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
get_my_ipd = fn (_) -> t_identity_proof_document+ {
|
|
42
|
+
RETURN m_my_ipd.
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
library node_description loads libraries address_document, container_associated_data, identity_proof_document_types {
|
|
2
|
+
metadef t_node_description: identity_proof_document_types::t_node_description.
|
|
3
|
+
|
|
4
|
+
create = fn (_) -> t_node_description {
|
|
5
|
+
ad = address_document::get_my_address_document().
|
|
6
|
+
associated_data = container_associated_data::create().
|
|
7
|
+
return ($address_document -> ad, $container_associated_data -> associated_data).
|
|
8
|
+
}
|
|
9
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
library browser_attestation_document loads libraries platform_dependent_attestation_document, node_description, attestation_document {
|
|
2
|
+
|
|
3
|
+
metadef type: ($user_data -> hash_code).
|
|
4
|
+
|
|
5
|
+
_create_browser_ad = fn (user_data: hash_code) -> type {
|
|
6
|
+
RETURN ($user_data -> user_data).
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
hidden {
|
|
10
|
+
type_id = platform_dependent_attestation_document::platform_type::wasm_browser.
|
|
11
|
+
create = fn (node_description: node_description::t_node_description) -> attestation_document::t_attestation_document{
|
|
12
|
+
ad = _create_browser_ad (_value_id node_description).
|
|
13
|
+
RETURN (
|
|
14
|
+
$platform_dependent_attestation_document -> ad,
|
|
15
|
+
$platform_type_id -> type_id
|
|
16
|
+
).
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
validate = fn (ad: any, node_dsc: node_description::t_node_description, timestamp: time) -> bool {
|
|
20
|
+
RETURN TRUE.
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
attestation_document::interface::add_interface type_id ($create -> create as(attestation_document::t_create), $validate -> validate as(attestation_document::t_validate)).
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
library native_attestation_document loads libraries platform_dependent_attestation_document, node_description, attestation_document {
|
|
2
|
+
|
|
3
|
+
metadef type: ($user_data -> hash_code).
|
|
4
|
+
|
|
5
|
+
_create_native_ad = fn (user_data: hash_code) -> type {
|
|
6
|
+
RETURN ($user_data -> user_data).
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
hidden {
|
|
10
|
+
type_id = platform_dependent_attestation_document::platform_type::node_js.
|
|
11
|
+
create = fn (node_description: node_description::t_node_description) -> attestation_document::t_attestation_document{
|
|
12
|
+
ad = _create_native_ad (_value_id node_description).
|
|
13
|
+
RETURN (
|
|
14
|
+
$platform_dependent_attestation_document -> ad,
|
|
15
|
+
$platform_type_id -> type_id
|
|
16
|
+
).
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
validate = fn (ad: any, node_dsc: node_description::t_node_description, timestamp: time) -> bool {
|
|
20
|
+
RETURN TRUE.
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
attestation_document::interface::add_interface type_id ($create -> create as(attestation_document::t_create), $validate -> validate as(attestation_document::t_validate)).
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
library platform_dependent_attestation_document loads libraries attestation_document, node_description, current_transaction_info uses transactions {
|
|
2
|
+
module platform_type {
|
|
3
|
+
hidden
|
|
4
|
+
{
|
|
5
|
+
platform_names is (int->>str) = (,).
|
|
6
|
+
add = fn (idx: int, name: str) -> int {
|
|
7
|
+
abort "Platform with given index already exists." when (_has platform_names idx).
|
|
8
|
+
platform_names idx -> name.
|
|
9
|
+
return idx.
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
enclave = add _get_nitro_platform_type_id() "enclave".
|
|
13
|
+
node_js = add _get_native_platform_type_id() "node js".
|
|
14
|
+
wasm_browser = add _get_wasm_platform_type_id() "wasm browser".
|
|
15
|
+
|
|
16
|
+
get_platform_name = fn (id: int) -> str {
|
|
17
|
+
abort provisional "Invalid platform type id." when !(_has platform_names id).
|
|
18
|
+
return (platform_names id|).
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
hidden {
|
|
23
|
+
current_platform is int = _get_platform_type_id().
|
|
24
|
+
attestation_document is attestation_document::t_attestation_document+ = NIL.
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
get_attestation_document = fn (platform_type_id: int) -> attestation_document::t_attestation_document {
|
|
28
|
+
abort provisional "Attestation document is not loaded. Consider executing transation ::platform_dependent_attestation_document::load_attestation_document." when attestation_document == NIL.
|
|
29
|
+
abort provisional
|
|
30
|
+
"Platform mismatch. Attestation document platform: " +
|
|
31
|
+
(platform_type::get_platform_name current_platform) +
|
|
32
|
+
", expected platform: " +
|
|
33
|
+
(platform_type::get_platform_name platform_type_id)
|
|
34
|
+
when platform_type_id != current_platform.
|
|
35
|
+
return attestation_document?.
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
trn load_attestation_document
|
|
39
|
+
ad: attestation_document::t_attestation_document {
|
|
40
|
+
current_transaction_info::validate_origin (transaction::envelope::origin::user,).
|
|
41
|
+
ad => ($platform_dependent_attestation_document -> _, $platform_type_id -> type_id).
|
|
42
|
+
abort
|
|
43
|
+
"Platform mismatch. Attestation document platform: " +
|
|
44
|
+
(platform_type::get_platform_name current_platform) +
|
|
45
|
+
", expected platform: " +
|
|
46
|
+
(platform_type::get_platform_name type_id)
|
|
47
|
+
when current_platform != type_id.
|
|
48
|
+
attestation_document -> ad.
|
|
49
|
+
|
|
50
|
+
return transaction::success [].
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
create = fn (_) {
|
|
54
|
+
ad = ::attestation_document::create ().
|
|
55
|
+
return ad.
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
library authorizing_container loads libraries address_document_types, key_storage uses transactions {
|
|
2
|
+
|
|
3
|
+
trn sign_ad
|
|
4
|
+
_: ($ad -> ad: address_document_types::t_address_document){
|
|
5
|
+
// TODO: check if container registered
|
|
6
|
+
signature = key_storage::default_sign (_value_id ad).
|
|
7
|
+
cid = ad $identity $container_id.
|
|
8
|
+
encrypted_trn = transaction::encrypt ($cid -> cid, $trn -> ($name -> "::address_document::save_ad_signature", $targ -> ($authorizing_container_id -> _get_container_id(), $signature -> signature)), $isemsignature -> TRUE).
|
|
9
|
+
RETURN transaction::success [
|
|
10
|
+
transaction::action::send cid encrypted_trn
|
|
11
|
+
].
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
trn resend_encrypted
|
|
15
|
+
_:($trn->tn:($name->str, $targ->any), $target_container_id->cid: global_id) {
|
|
16
|
+
encrypted_trn = transaction::encrypt ($cid->cid, $trn->tn, $isemsignature->TRUE).
|
|
17
|
+
RETURN transaction::success [
|
|
18
|
+
transaction::action::send cid encrypted_trn
|
|
19
|
+
].
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
library encrypted_channel
|
|
2
|
+
loads libraries
|
|
3
|
+
current_transaction_info,
|
|
4
|
+
identity_proof_document,
|
|
5
|
+
attestation_document,
|
|
6
|
+
browser_attestation_document,
|
|
7
|
+
address_document,
|
|
8
|
+
address_document_types,
|
|
9
|
+
continuation,
|
|
10
|
+
key_storage
|
|
11
|
+
uses transactions
|
|
12
|
+
{
|
|
13
|
+
using address_document.
|
|
14
|
+
|
|
15
|
+
hidden {
|
|
16
|
+
_read_or_abort is (bin->any) = fn (_: bin) { abort "_read_or_abort primitive is unset in this library." when TRUE. }
|
|
17
|
+
|
|
18
|
+
debug_mode is bool = FALSE.
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
init = fn (_:($_read_or_abort -> read: (bin->any)))
|
|
22
|
+
{
|
|
23
|
+
_read_or_abort -> read.
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
fn set_debug_mode (is_debug: bool) {
|
|
27
|
+
debug_mode -> is_debug.
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
metadef tx_body_t: (
|
|
31
|
+
$name -> str,
|
|
32
|
+
$targ -> any
|
|
33
|
+
).
|
|
34
|
+
|
|
35
|
+
fn send_encrypted_tx(receiver_id: global_id, tx_body: tx_body_t) -> transaction::action::type
|
|
36
|
+
{
|
|
37
|
+
if (debug_mode) {
|
|
38
|
+
return transaction::action::send receiver_id tx_body.
|
|
39
|
+
}
|
|
40
|
+
abort "Receiver is not authorized" when key_storage::is_container_registered(receiver_id) != TRUE.
|
|
41
|
+
encrypted_trn = transaction::encrypt (
|
|
42
|
+
$cid -> receiver_id,
|
|
43
|
+
$trn -> tx_body,
|
|
44
|
+
$isemsignature -> TRUE
|
|
45
|
+
).
|
|
46
|
+
return transaction::action::send receiver_id encrypted_trn.
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
fn check_encrypted_or_abort(_) {
|
|
50
|
+
if (debug_mode) {
|
|
51
|
+
return.
|
|
52
|
+
}
|
|
53
|
+
abort "Transaction is expected to be encrypted!" when not current_transaction_info::is_encrypted().
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
fn execute_transaction(
|
|
57
|
+
destination_packet_id: global_id,
|
|
58
|
+
transaction_producer: any -> transaction::results::type
|
|
59
|
+
) -> transaction::results::type
|
|
60
|
+
{
|
|
61
|
+
if (debug_mode || key_storage::is_container_registered(destination_packet_id)) {
|
|
62
|
+
return transaction_producer().
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return continuation::set_breakpoint
|
|
66
|
+
(fn(continuation_id: global_id) -> transaction::results::type {
|
|
67
|
+
return transaction::success [
|
|
68
|
+
transaction::action::send destination_packet_id (
|
|
69
|
+
$name -> "::encrypted_channel::request_identity",
|
|
70
|
+
$targ -> ($continuation_id -> continuation_id, $ad -> get_my_address_document()))
|
|
71
|
+
].
|
|
72
|
+
})
|
|
73
|
+
(fn(safe _:($peer_ad -> peer_ad: address_document_types::t_address_document)) -> transaction::results::type {
|
|
74
|
+
abort "encrypted_channel: identity reply from unexpected address"
|
|
75
|
+
when (peer_ad $identity $container_id) != destination_packet_id.
|
|
76
|
+
process_address_document peer_ad TRUE.
|
|
77
|
+
return transaction_producer().
|
|
78
|
+
}).
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
trn request_identity _:(
|
|
82
|
+
$continuation_id -> client_continuation_id: global_id,
|
|
83
|
+
$ad -> requester_ad: address_document_types::t_address_document)
|
|
84
|
+
{
|
|
85
|
+
sender_id = current_transaction_info::get_external_envelope_or_abort() $from.
|
|
86
|
+
abort "Identity request from unexpected address"
|
|
87
|
+
when (requester_ad $identity $container_id) != sender_id.
|
|
88
|
+
process_address_document requester_ad TRUE.
|
|
89
|
+
return transaction::success [
|
|
90
|
+
transaction::action::send sender_id (
|
|
91
|
+
$name -> "::continuation::continue_transaction",
|
|
92
|
+
$targ -> ($id -> client_continuation_id, $args -> ($peer_ad -> get_my_address_document())))
|
|
93
|
+
].
|
|
94
|
+
}
|
|
95
|
+
}
|