@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,84 @@
|
|
|
1
|
+
// library lists {
|
|
2
|
+
// empty IS NIL.
|
|
3
|
+
// head IS 1.
|
|
4
|
+
// tail IS 2.
|
|
5
|
+
|
|
6
|
+
// cons IS fn (h, t) = ( head -> h, tail -> t ).
|
|
7
|
+
// make_list IS fn (array, start) {
|
|
8
|
+
// IF (array start) == NIL THEN { _return empty. }
|
|
9
|
+
// _return (cons (array start) (make_list array (start + 1) )).
|
|
10
|
+
// }
|
|
11
|
+
|
|
12
|
+
// print_list IS fn (l, f, sep) {
|
|
13
|
+
// IF (l == empty) THEN { _return "". }
|
|
14
|
+
|
|
15
|
+
// ret IS NEW().
|
|
16
|
+
// ret() -> (f (l head)).
|
|
17
|
+
// IF (l tail != empty) THEN { ret() -> ret() + sep. }
|
|
18
|
+
// ret() -> ret() + (print_list (l tail) f sep).
|
|
19
|
+
// }
|
|
20
|
+
// }
|
|
21
|
+
|
|
22
|
+
// library lists
|
|
23
|
+
// {
|
|
24
|
+
// empty = NIL.
|
|
25
|
+
|
|
26
|
+
// cons = fn (h, t
|
|
27
|
+
// }
|
|
28
|
+
library lists
|
|
29
|
+
{
|
|
30
|
+
generic module generic_lists takes _Type
|
|
31
|
+
{
|
|
32
|
+
metadef value_type: _Type.
|
|
33
|
+
metadef head_type: value_type.
|
|
34
|
+
metadef tail_type: ($head -> value_type, $tail -> any)+.
|
|
35
|
+
metadef list_type: tail_type.
|
|
36
|
+
|
|
37
|
+
empty = NIL.
|
|
38
|
+
cons = fn (h: value_type, t: tail_type) = ($head -> h, $tail -> t).
|
|
39
|
+
head = fn (l: list_type) -> head_type+ {
|
|
40
|
+
if l == NIL {
|
|
41
|
+
return empty.
|
|
42
|
+
}
|
|
43
|
+
return l? $head.
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
tail = fn (l: list_type) -> list_type {
|
|
47
|
+
if l == NIL {
|
|
48
|
+
return empty.
|
|
49
|
+
}
|
|
50
|
+
return (l? $tail) as list_type.
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
hidden
|
|
54
|
+
{
|
|
55
|
+
make_list_ex = fn (array: value_type[], idx: int) -> list_type {
|
|
56
|
+
if idx == (_count array|) {
|
|
57
|
+
return empty.
|
|
58
|
+
}
|
|
59
|
+
return cons (array idx|) (make_list_ex array (idx + 1)) as list_type.
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
make_list = fn (array: value_type[]) -> list_type {
|
|
64
|
+
return make_list_ex array 0.
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
print_list = fn (l: list_type, functor: (value_type->str), sep: str) -> str {
|
|
68
|
+
if (l == empty) {
|
|
69
|
+
return "".
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (tail l != empty) {
|
|
73
|
+
return (functor (head l|)) + sep + (print_list (tail l) functor sep) as str.
|
|
74
|
+
} else {
|
|
75
|
+
return functor (head l|).
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
module int_list instantiates generic_lists with int.
|
|
81
|
+
module str_list instantiates generic_lists with str.
|
|
82
|
+
module bool_list instantiates generic_lists with bool.
|
|
83
|
+
module any_list instantiates generic_lists with any.
|
|
84
|
+
}
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
library permissions
|
|
2
|
+
{
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
Motivation:
|
|
6
|
+
In the context of authorization service, we sometimes need to give external actors (services, users) permission to access certain parts of the code
|
|
7
|
+
This library manages these access rules.
|
|
8
|
+
|
|
9
|
+
When user grants some permissions to the external actors, safereference is generated and given to the actor.
|
|
10
|
+
This safereference serves as an identificator of the external actor in this context.
|
|
11
|
+
It is obvious, that the same actor might have several safereferences with different permission bundles.
|
|
12
|
+
For example, we authorize the service S to read our person information - name, surname and date of birth.
|
|
13
|
+
Then, later, we want to give access to this server to create a backup data in our secret storage, so we have to give this service a permission to access secret storage.
|
|
14
|
+
It is obvious, that these two permission bundles should be managed separately, which is why to distinct safe refs should be generated
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
Each permission should potentially have payload. For example, in the previous example, we don't want to give access to the entire secret storage. This access should be scoped.
|
|
18
|
+
This library have no information about internal structure of the secret storage, which is why this additional permission checks should be executed on the next level.
|
|
19
|
+
|
|
20
|
+
This library simply checks the general permission ignoring the particular payload.
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
Please note that this implementation allows for sharing safe references. Meaning that permissions could be shared with other parties by sharing the safe reference.
|
|
24
|
+
Any additional logic could be implemented on top of this module.
|
|
25
|
+
For example, if you want to make the permissions non sharable, you can associate each safe reference with packet id of the counterparty.
|
|
26
|
+
|
|
27
|
+
library custom_permission_manager loads library permissions
|
|
28
|
+
{
|
|
29
|
+
module my_permissions instantiates permissions::creator with <$a, $b, $c>.
|
|
30
|
+
|
|
31
|
+
users_by_saferefs is (saferef ->> global_id) = (,).
|
|
32
|
+
|
|
33
|
+
// implement API functions for permissions manager storing addionally the packet id of the party you are granting permission to
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
generic module creator takes P
|
|
39
|
+
{
|
|
40
|
+
// in case P type is enumerated set of strings, for the ease of use of this module, we have to allow strings values as argument types in functions
|
|
41
|
+
// because our type system does not know about the P type in the moment of a function call and treats the string arguments as str type
|
|
42
|
+
// permissions_id_t is equivalent to P
|
|
43
|
+
// permissions_id_extended_t is equivalent in case P is not enum, otherwise it is P || str
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
metablock
|
|
47
|
+
{
|
|
48
|
+
permissions_id_t = P.
|
|
49
|
+
permissions_id_extended_t = P.
|
|
50
|
+
if (P $is_enumerated_set)
|
|
51
|
+
{
|
|
52
|
+
permissions_id_extended_t -> meta::combinations::disjunction (P, meta::basics::string).
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
/*
|
|
59
|
+
module grant exposes API for granting permissions
|
|
60
|
+
it stores all the granted permissions to all the packets
|
|
61
|
+
*/
|
|
62
|
+
module grant
|
|
63
|
+
{
|
|
64
|
+
// actual permission type - includes the type of the permission and payload data
|
|
65
|
+
metadef permission_t: (
|
|
66
|
+
$type -> P,
|
|
67
|
+
$payload -> any
|
|
68
|
+
).
|
|
69
|
+
|
|
70
|
+
metadef permission_registration_t: permissions_id_extended_t || permission_t.
|
|
71
|
+
|
|
72
|
+
// bundle of permissions issues to some external party - indexed by the permission type
|
|
73
|
+
metadef permissions_bundle_t: P ->> permission_t.
|
|
74
|
+
|
|
75
|
+
hidden
|
|
76
|
+
{
|
|
77
|
+
metadef granted_permissions_t: (saferef ->> permissions_bundle_t).
|
|
78
|
+
|
|
79
|
+
granted_permissions is granted_permissions_t = (,).
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
fn get_permissions_bundle (sr: saferef) = (granted_permissions sr).
|
|
83
|
+
|
|
84
|
+
fn add_permissions (sr: saferef, permissions: permission_registration_t[])
|
|
85
|
+
{
|
|
86
|
+
abort "Unknown saferef passed to the permissions::grant::add_permissions" when granted_permissions sr == NIL.
|
|
87
|
+
sc permissions -- (-> permission)
|
|
88
|
+
{
|
|
89
|
+
if (_typeof permission == "IMMUTABLE_DICTIONARY" && (permission as any) $type != NIL)
|
|
90
|
+
{
|
|
91
|
+
granted_permissions sr (((permission as permission_t) $type) safe permissions_id_t) -> permission as permission_t.
|
|
92
|
+
}
|
|
93
|
+
else
|
|
94
|
+
{
|
|
95
|
+
granted_permissions sr (permission safe permissions_id_t) -> ($type -> permission safe permissions_id_t, $payload -> NIL).
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
fn revoke_permissions (sr: saferef, permissions: permissions_id_extended_t[])
|
|
101
|
+
{
|
|
102
|
+
sc permissions -- (-> permission)
|
|
103
|
+
{
|
|
104
|
+
delete granted_permissions sr (permission safe permissions_id_t).
|
|
105
|
+
// granted_permissions sr (permission safe permissions_id_t) -> NIL. // remove the permission from the bundle
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
fn register_permissions_bundle (permissions: permission_registration_t[]) -> saferef
|
|
110
|
+
{
|
|
111
|
+
sr = _new_safe_ref().
|
|
112
|
+
granted_permissions sr -> (,) as permissions_bundle_t.
|
|
113
|
+
add_permissions sr permissions.
|
|
114
|
+
return sr.
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/*
|
|
120
|
+
module check exposes API for permissions verification
|
|
121
|
+
*/
|
|
122
|
+
module check
|
|
123
|
+
{
|
|
124
|
+
|
|
125
|
+
metadef logical_t: ($type -> <$at_least_one, $all>, $permissions -> any). // we don't support recursive types, treat this any as check_permission_t
|
|
126
|
+
metadef check_permission_t: logical_t || permissions_id_extended_t.
|
|
127
|
+
|
|
128
|
+
fn at_least_one (permissions: check_permission_t || check_permission_t[]) -> logical_t
|
|
129
|
+
{
|
|
130
|
+
return ($type -> $at_least_one, $permissions -> permissions).
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
fn all (permissions: check_permission_t || check_permission_t[]) -> logical_t
|
|
134
|
+
{
|
|
135
|
+
return ($type -> $all, $permissions -> permissions).
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
hidden
|
|
140
|
+
{
|
|
141
|
+
|
|
142
|
+
fn check_single_permission (permissions_bundle: grant::permissions_bundle_t, permission: P) -> bool
|
|
143
|
+
{
|
|
144
|
+
return permissions_bundle permission != NIL.
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
fn check_ex (permissions_bundle: grant::permissions_bundle_t, required_permissions: check_permission_t || check_permission_t[]) -> bool
|
|
148
|
+
{
|
|
149
|
+
if (_count required_permissions == 0) // empty immutable dictionary is passed -> nothing to check
|
|
150
|
+
{
|
|
151
|
+
return TRUE.
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (_typeof required_permissions == "STRING")
|
|
155
|
+
{
|
|
156
|
+
single_permission = required_permissions safe permissions_id_t.
|
|
157
|
+
|
|
158
|
+
// check single permission
|
|
159
|
+
return check_single_permission permissions_bundle single_permission.
|
|
160
|
+
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
if ((required_permissions as any) 0 != NIL) // array is passed
|
|
164
|
+
{
|
|
165
|
+
// simple array is always treated as all logical operator.. this is a simple syntax sugar to enable omitting the all function call
|
|
166
|
+
return check_ex permissions_bundle (all required_permissions).
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// at this point required_permissions have to be logical operator
|
|
170
|
+
logical_op = required_permissions safe logical_t.
|
|
171
|
+
|
|
172
|
+
if (logical_op $type == $all)
|
|
173
|
+
{
|
|
174
|
+
sc logical_op $permissions -- (-> permission)
|
|
175
|
+
{
|
|
176
|
+
if (check_ex permissions_bundle (permission safe (check_permission_t || check_permission_t[])) != TRUE)
|
|
177
|
+
{
|
|
178
|
+
return FALSE.
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
return TRUE.
|
|
182
|
+
}
|
|
183
|
+
else // at least one
|
|
184
|
+
{
|
|
185
|
+
sc logical_op $permissions -- (-> permission)
|
|
186
|
+
{
|
|
187
|
+
if (check_ex permissions_bundle (permission safe (check_permission_t || check_permission_t[])) == TRUE)
|
|
188
|
+
{
|
|
189
|
+
return TRUE.
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
return FALSE.
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
/*
|
|
200
|
+
Please note that due to the implementation, if permissions to check are passed as array it should be indexed from 0
|
|
201
|
+
*/
|
|
202
|
+
fn check (sr: saferef, safe required_permissions: check_permission_t || check_permission_t[]) -> bool
|
|
203
|
+
{
|
|
204
|
+
granted_permissions_bundle = grant::get_permissions_bundle sr.
|
|
205
|
+
if (granted_permissions_bundle == NIL)
|
|
206
|
+
{
|
|
207
|
+
return FALSE.
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
return check_ex granted_permissions_bundle? required_permissions.
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
}
|
|
219
|
+
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
pragma langserver path="."
|
|
2
|
+
library platform_type_id loads library current_transaction_info uses transactions
|
|
3
|
+
{
|
|
4
|
+
trn readonly _get_platform_type_id _ {
|
|
5
|
+
current_transaction_info::validate_origin (transaction::envelope::origin::user,).
|
|
6
|
+
return _get_platform_type_id ().
|
|
7
|
+
}
|
|
8
|
+
trn readonly _get_nitro_platform_type_id _ {
|
|
9
|
+
current_transaction_info::validate_origin (transaction::envelope::origin::user,).
|
|
10
|
+
return _get_nitro_platform_type_id().
|
|
11
|
+
}
|
|
12
|
+
trn readonly _get_wasm_platform_type_id _ {
|
|
13
|
+
current_transaction_info::validate_origin (transaction::envelope::origin::user,).
|
|
14
|
+
return _get_wasm_platform_type_id().
|
|
15
|
+
}
|
|
16
|
+
trn readonly _get_native_platform_type_id _ {
|
|
17
|
+
current_transaction_info::validate_origin (transaction::envelope::origin::user,).
|
|
18
|
+
return _get_native_platform_type_id().
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
library random
|
|
2
|
+
{
|
|
3
|
+
|
|
4
|
+
hidden
|
|
5
|
+
{
|
|
6
|
+
|
|
7
|
+
fn construct_bytes_rec (l: int) -> bin
|
|
8
|
+
{
|
|
9
|
+
if (l == 0)
|
|
10
|
+
{
|
|
11
|
+
return 0x.
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
slice = _hex_string_to_binary << _new_id "".
|
|
15
|
+
if (_binlen slice >= l)
|
|
16
|
+
{
|
|
17
|
+
return slice @! (0 .. l - 1).
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return slice + (construct_bytes_rec (l - (_binlen slice))) as bin.
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
fn generate_random_bytes (len: int) -> bin
|
|
27
|
+
{
|
|
28
|
+
return construct_bytes_rec len.
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
fn generate_random_int (_) -> int
|
|
33
|
+
{
|
|
34
|
+
bytes = generate_random_bytes 4.
|
|
35
|
+
|
|
36
|
+
res = bytes 3.
|
|
37
|
+
|
|
38
|
+
res -> res + (bytes 2) * 10.
|
|
39
|
+
res -> res + (bytes 1) * 100.
|
|
40
|
+
res -> res + (bytes 0) * 1000.
|
|
41
|
+
|
|
42
|
+
return res.
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
fn generate_random_int_from_interval (min: int, max: int) -> int
|
|
46
|
+
{
|
|
47
|
+
return min + (generate_random_int() % (max - min)).
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
library rslt
|
|
2
|
+
{
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
generic module creator takes types
|
|
6
|
+
{
|
|
7
|
+
metablock {
|
|
8
|
+
ok_t = types $type_list 0.
|
|
9
|
+
err_t = types $type_list 1.
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
metadef rslt_t: (
|
|
13
|
+
$is_ok -> bool,
|
|
14
|
+
$err -> err_t+,
|
|
15
|
+
$ok -> ok_t+
|
|
16
|
+
).
|
|
17
|
+
|
|
18
|
+
fn get_ok(v: rslt_t) -> ok_t {
|
|
19
|
+
abort "Called 'get_ok' on Err result." when v $ok == NIL.
|
|
20
|
+
return (v $ok)?.
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
fn get_err(v: rslt_t) -> err_t {
|
|
24
|
+
abort "Called 'get_err' on Ok result." when v $err == NIL.
|
|
25
|
+
return (v $err)?.
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
fn ok(data: ok_t) -> rslt_t = ($is_ok -> TRUE, $err -> NIL, $ok -> data).
|
|
29
|
+
fn err(data: err_t) -> rslt_t = ($is_ok -> FALSE, $err -> data, $ok -> NIL).
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
library transaction_message_decoder loads library current_transaction_info uses transactions
|
|
2
|
+
{
|
|
3
|
+
trn readonly describe_message
|
|
4
|
+
message: transaction::type {
|
|
5
|
+
current_transaction_info::validate_origin (transaction::envelope::origin::user,).
|
|
6
|
+
|
|
7
|
+
raw_message is any = message.
|
|
8
|
+
message_decoded is any = NIL.
|
|
9
|
+
if raw_message $trn {
|
|
10
|
+
message_decoded -> raw_message $trn.
|
|
11
|
+
} elif raw_message $encrypted_message {
|
|
12
|
+
message_decoded -> ($name -> "::encrypted_message::", $targ -> NIL).
|
|
13
|
+
} else {
|
|
14
|
+
message_decoded -> raw_message.
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if !(_is_test_mode()) {
|
|
18
|
+
message_decoded $targ -> "Arguments are hidden.".
|
|
19
|
+
}
|
|
20
|
+
return message_decoded.
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
library transaction_queue loads library transaction {
|
|
2
|
+
/*
|
|
3
|
+
Assume, there is transaction 'trn2', result of which should be processed
|
|
4
|
+
after transaction 'trn2' is executed. For example, container sends some
|
|
5
|
+
data to the another container as a result of 'trn2', but this data is
|
|
6
|
+
depending on another transaction 'trn1'. In this case, we can add result of
|
|
7
|
+
the 'trn2' to the buffer and access this buffer in 'trn2'.
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
Pseudo code example:
|
|
11
|
+
trn trn2 ... {
|
|
12
|
+
buffered_transactions_cb = fn (_) { ...) =
|
|
13
|
+
[transaction::action::send ..., transactions::send ...] } // 1 buffer::add 'trn1'
|
|
14
|
+
buffered_transactions_cb. RETURN transaction::success [].
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
trn trn1 ... {
|
|
18
|
+
RETURN transaction::success []. // callback 1 is called here and
|
|
19
|
+
transactions returned from the callback are added to the result of this
|
|
20
|
+
transaction
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
For now transaction name is being used as transaction identifier, but
|
|
24
|
+
maybe it's better to use a hash of the transaction with arguments. But in
|
|
25
|
+
this case we don't always know arguments of the transaction. For example,
|
|
26
|
+
when we want to process result after we receive signature from authorizing
|
|
27
|
+
container, we cannot know signature before we recieved it...
|
|
28
|
+
*/
|
|
29
|
+
metadef t_actions_creator_func: (any->transaction::action::type[]).
|
|
30
|
+
|
|
31
|
+
hidden {
|
|
32
|
+
transactions_buffer IS (str->> t_actions_creator_func[]) = (,).
|
|
33
|
+
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
add = fn (trn_name: str, actions_creator: t_actions_creator_func) {
|
|
37
|
+
if transactions_buffer trn_name != NIL {
|
|
38
|
+
transactions_buffer trn_name (_count(transactions_buffer trn_name |)|) ->actions_creator.
|
|
39
|
+
} else {
|
|
40
|
+
transactions_buffer trn_name -> [actions_creator].
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
get = fn (trn_name : str) -> transaction::action::type[] {
|
|
45
|
+
res is transaction::action::type[] = [].
|
|
46
|
+
if transactions_buffer trn_name != NIL {
|
|
47
|
+
creators = (transactions_buffer trn_name |).
|
|
48
|
+
sc creators -- ( -> creator) {
|
|
49
|
+
actions = creator().
|
|
50
|
+
sc actions -- ( -> action) {
|
|
51
|
+
res (_count res|) -> action.
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
transactions_buffer -> transactions_buffer'(trn_name -> delete).
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return res.
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
library vector {
|
|
2
|
+
generic module vector takes value_type {
|
|
3
|
+
metadef type: (
|
|
4
|
+
$push_back -> (value_type -> any),
|
|
5
|
+
$at -> (int -> value_type),
|
|
6
|
+
$set -> (int -> value_type -> any),
|
|
7
|
+
$pop_back -> (any -> any),
|
|
8
|
+
$size -> (any -> int),
|
|
9
|
+
$for_each -> ((value_type -> any) -> nil),
|
|
10
|
+
$map -> ((value_type -> value_type) -> any),
|
|
11
|
+
$select_by_indices -> ((int*>int) -> any),
|
|
12
|
+
$merge -> ((int*>value_type) -> any),
|
|
13
|
+
$get -> (any -> value_type[])
|
|
14
|
+
).
|
|
15
|
+
|
|
16
|
+
construct = fn (init: int*>value_type) -> type
|
|
17
|
+
{
|
|
18
|
+
array is value_type[] = [].
|
|
19
|
+
sc init -- ( -> val) {
|
|
20
|
+
array (_count array|) -> val.
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
push_back = fn (old_vector: value_type[], value: value_type)
|
|
24
|
+
{
|
|
25
|
+
old_vector (_count old_vector|) -> value.
|
|
26
|
+
return construct old_vector.
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
get = fn (vec: value_type[], _) = vec.
|
|
30
|
+
|
|
31
|
+
pop_back = fn (old_vector: value_type[], _)
|
|
32
|
+
{
|
|
33
|
+
abort "Trying to pop from empty vector." when (_count old_vector|) == 0.
|
|
34
|
+
new_vector is value_type[] = [].
|
|
35
|
+
sc old_vector -- (i -> it) ?? i < ((_count old_vector|) - 1 ) {
|
|
36
|
+
new_vector (_count new_vector|) -> it.
|
|
37
|
+
}
|
|
38
|
+
return construct new_vector.
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
at = fn (vec: value_type[], idx: int) -> value_type
|
|
42
|
+
{
|
|
43
|
+
abort "Internal error. Trying to get uninitialized element of vector." when idx >= (_count vec|).
|
|
44
|
+
return (vec idx)?.
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
set = fn (old_vector: value_type[], idx: int, value: value_type) -> any
|
|
48
|
+
{
|
|
49
|
+
abort "Internal error. Trying to set uninitialized element of vector." when idx > (_count old_vector|).
|
|
50
|
+
old_vector idx -> value.
|
|
51
|
+
return construct old_vector.
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
size = fn (vec: value_type[], _) = (_count vec|).
|
|
55
|
+
|
|
56
|
+
for_each = fn (vec: value_type[], f: (value_type -> any)) -> nil
|
|
57
|
+
{
|
|
58
|
+
sc vec -- ( -> it) {
|
|
59
|
+
f it.
|
|
60
|
+
}
|
|
61
|
+
return NIL.
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
select_by_indices = fn (old_vector: value_type[], indices: int*>int) -> any
|
|
65
|
+
{
|
|
66
|
+
new_vector is value_type[] = [].
|
|
67
|
+
sc indices -- ( -> idx) {
|
|
68
|
+
abort "Index out of bounds." when idx >= (_count old_vector|).
|
|
69
|
+
new_vector (_count new_vector|) -> (old_vector idx)?.
|
|
70
|
+
}
|
|
71
|
+
return construct new_vector.
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
merge = fn (vec: value_type[], new_vals: int*>value_type) -> any
|
|
75
|
+
{
|
|
76
|
+
sc new_vals -- ( -> val) {
|
|
77
|
+
vec (_count vec|) -> val.
|
|
78
|
+
}
|
|
79
|
+
return construct vec.
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
map = fn (vec: value_type[], f: (value_type -> value_type)) -> any
|
|
83
|
+
{
|
|
84
|
+
new_vector is value_type[] = [].
|
|
85
|
+
sc vec -- (idx -> it) {
|
|
86
|
+
new_vector idx -> f it.
|
|
87
|
+
}
|
|
88
|
+
return construct new_vector.
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return (
|
|
92
|
+
$push_back -> push_back array,
|
|
93
|
+
$pop_back -> pop_back array,
|
|
94
|
+
$get -> get array,
|
|
95
|
+
$at -> at array,
|
|
96
|
+
$set -> set array,
|
|
97
|
+
$size -> size array,
|
|
98
|
+
$for_each -> for_each array,
|
|
99
|
+
$map -> map array,
|
|
100
|
+
$merge -> merge array,
|
|
101
|
+
$select_by_indices -> select_by_indices array
|
|
102
|
+
).
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
empty = fn (_) -> type
|
|
106
|
+
{
|
|
107
|
+
init is value_type[] = [].
|
|
108
|
+
return construct init.
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
identity = fn (v: any) = (v as type).
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
module int_vector instantiates vector with int.
|
|
115
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
library verification loads library current_transaction_info uses transactions
|
|
2
|
+
{
|
|
3
|
+
|
|
4
|
+
hidden
|
|
5
|
+
{
|
|
6
|
+
callbacks is global_id->>any = (,).
|
|
7
|
+
|
|
8
|
+
get_cb = fn (id: global_id)
|
|
9
|
+
{
|
|
10
|
+
res = callbacks id abort "Verification callback not found. ID: " + id when is NIL.
|
|
11
|
+
delete callbacks id.
|
|
12
|
+
return res?.
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
add_verification = fn (cb) -> global_id
|
|
19
|
+
{
|
|
20
|
+
id = _new_id "Verification id.".
|
|
21
|
+
|
|
22
|
+
abort "Internal error: Verification with generated id already exists." when callbacks id != NIL.
|
|
23
|
+
|
|
24
|
+
callbacks id -> cb.
|
|
25
|
+
return id.
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
trn accept
|
|
29
|
+
_:($id->id: global_id)
|
|
30
|
+
{
|
|
31
|
+
current_transaction_info::validate_origin (transaction::envelope::origin::user,).
|
|
32
|
+
return get_cb id NIL.
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@adapt-toolkit/mufl",
|
|
3
|
+
"version": "0.8.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"license": "SEE LICENSE IN LICENSE",
|
|
6
|
+
"description": "The MUFL toolchain: prebuilt `mufl` (REPL) and `mufl-compile` (compiler) engine binaries plus the MUFL stdlib, meta, and transactions trees they need at run time. Linux x64 only; the binaries are proprietary (AEFL) — see LICENSE and NOTICE.",
|
|
7
|
+
"bin": {
|
|
8
|
+
"mufl": "./bin/mufl.js",
|
|
9
|
+
"mufl-compile": "./bin/mufl-compile.js"
|
|
10
|
+
},
|
|
11
|
+
"exports": {
|
|
12
|
+
"./paths": "./lib/paths.js",
|
|
13
|
+
"./package.json": "./package.json"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"bin",
|
|
17
|
+
"lib",
|
|
18
|
+
"prebuilds",
|
|
19
|
+
"mufl_stdlib",
|
|
20
|
+
"meta",
|
|
21
|
+
"transactions",
|
|
22
|
+
"LICENSE",
|
|
23
|
+
"LICENSE.fsl",
|
|
24
|
+
"NOTICE",
|
|
25
|
+
"README.md"
|
|
26
|
+
],
|
|
27
|
+
"engines": {
|
|
28
|
+
"node": ">=20"
|
|
29
|
+
},
|
|
30
|
+
"scripts": {
|
|
31
|
+
"test": "node --test"
|
|
32
|
+
},
|
|
33
|
+
"repository": {
|
|
34
|
+
"type": "git",
|
|
35
|
+
"url": "git+https://github.com/adapt-toolkit/adapt.git",
|
|
36
|
+
"directory": "typescript/mufl"
|
|
37
|
+
},
|
|
38
|
+
"homepage": "https://github.com/adapt-toolkit/adapt/tree/main/typescript/mufl#readme",
|
|
39
|
+
"bugs": {
|
|
40
|
+
"url": "https://github.com/adapt-toolkit/adapt/issues"
|
|
41
|
+
},
|
|
42
|
+
"author": "Adapt Framework Solutions Ltd."
|
|
43
|
+
}
|
|
Binary file
|
|
Binary file
|