wowok 1.1.0 → 1.1.2
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/README.md +1 -1
- package/dist/demand.d.ts +2 -3
- package/dist/demand.d.ts.map +1 -1
- package/dist/demand.js +19 -11
- package/dist/exception.d.ts +2 -1
- package/dist/exception.d.ts.map +1 -1
- package/dist/exception.js +1 -0
- package/dist/graphql.d.ts +2 -0
- package/dist/graphql.d.ts.map +1 -1
- package/dist/graphql.js +19 -0
- package/dist/guard.d.ts +18 -23
- package/dist/guard.d.ts.map +1 -1
- package/dist/guard.js +220 -199
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/machine.d.ts +6 -6
- package/dist/machine.d.ts.map +1 -1
- package/dist/machine.js +7 -7
- package/dist/passport.d.ts +34 -22
- package/dist/passport.d.ts.map +1 -1
- package/dist/passport.js +124 -214
- package/dist/permission.d.ts +3 -0
- package/dist/permission.d.ts.map +1 -1
- package/dist/permission.js +5 -2
- package/dist/progress.js +3 -3
- package/dist/protocol.d.ts +11 -5
- package/dist/protocol.d.ts.map +1 -1
- package/dist/protocol.js +30 -6
- package/dist/repository.d.ts +2 -0
- package/dist/repository.d.ts.map +1 -1
- package/dist/repository.js +73 -5
- package/dist/service.d.ts +3 -3
- package/dist/service.d.ts.map +1 -1
- package/dist/service.js +115 -116
- package/dist/utils.d.ts +10 -2
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +39 -1
- package/dist/vote.js +8 -8
- package/package.json +1 -1
- package/src/exception.ts +1 -0
- package/src/graphql.ts +20 -0
- package/src/guard.ts +208 -192
- package/src/index.ts +1 -0
- package/src/machine.ts +10 -10
- package/src/passport.ts +139 -251
- package/src/permission.ts +5 -2
- package/src/progress.ts +3 -3
- package/src/protocol.ts +26 -5
- package/src/repository.ts +73 -5
- package/src/service.ts +25 -25
- package/src/utils.ts +44 -4
- package/src/vote.ts +8 -8
- package/tsconfig.json +3 -2
package/dist/guard.js
CHANGED
|
@@ -1,131 +1,22 @@
|
|
|
1
1
|
import { BCS } from '@mysten/bcs';
|
|
2
2
|
import { MODULES, ContextType, ValueType, OperatorType } from './protocol';
|
|
3
3
|
import { concatenate, array_equal } from './utils';
|
|
4
|
-
import { IsValidDesription,
|
|
4
|
+
import { IsValidDesription, Bcs, IsValidInt, IsValidAddress } from './utils';
|
|
5
5
|
import { ERROR, Errors } from './exception';
|
|
6
|
-
export var Guard_Sense_Binder;
|
|
7
|
-
(function (Guard_Sense_Binder) {
|
|
8
|
-
Guard_Sense_Binder[Guard_Sense_Binder["AND"] = 0] = "AND";
|
|
9
|
-
Guard_Sense_Binder[Guard_Sense_Binder["OR"] = 1] = "OR";
|
|
10
|
-
})(Guard_Sense_Binder || (Guard_Sense_Binder = {}));
|
|
11
6
|
export class Guard {
|
|
12
|
-
static
|
|
13
|
-
static IsValidGuardVirableType = (type) => {
|
|
14
|
-
if (type == OperatorType.TYPE_FUTURE_QUERY || type == ContextType.TYPE_CONTEXT_FUTURE_ID || type == OperatorType.TYPE_QUERY_FROM_CONTEXT ||
|
|
15
|
-
type == ContextType.TYPE_CONTEXT_bool || type == ContextType.TYPE_CONTEXT_address || type == ContextType.TYPE_CONTEXT_u64 ||
|
|
16
|
-
type == ContextType.TYPE_CONTEXT_u8 || type == ContextType.TYPE_CONTEXT_vec_u8) {
|
|
17
|
-
return true;
|
|
18
|
-
}
|
|
19
|
-
;
|
|
20
|
-
return false;
|
|
21
|
-
};
|
|
22
|
-
static IsValidIndentifier = (identifier) => {
|
|
23
|
-
if (!IsValidInt(identifier) || identifier > 255)
|
|
24
|
-
return false;
|
|
25
|
-
return true;
|
|
26
|
-
};
|
|
27
|
-
static get_variable_value(variables, identifier, type) {
|
|
28
|
-
if (variables.has(identifier)) {
|
|
29
|
-
let v = variables.get(identifier);
|
|
30
|
-
if (v?.value && v.type == type) {
|
|
31
|
-
return v.value;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
return false;
|
|
35
|
-
}
|
|
36
|
-
static get_variable_witness(variables, identifier, type) {
|
|
37
|
-
if (variables.has(identifier)) {
|
|
38
|
-
let v = variables.get(identifier);
|
|
39
|
-
if (v?.witness && v.type == type) {
|
|
40
|
-
return v.witness;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
return false;
|
|
44
|
-
}
|
|
45
|
-
static add_future_variable(variables, identifier, type, witness, value, bNeedSerialize = true) {
|
|
46
|
-
if (!Guard.IsValidIndentifier(identifier))
|
|
47
|
-
return false;
|
|
48
|
-
if (!Guard.IsValidGuardVirableType(type))
|
|
49
|
-
return false;
|
|
50
|
-
if (!witness && !value)
|
|
51
|
-
return false;
|
|
52
|
-
switch (type) {
|
|
53
|
-
case OperatorType.TYPE_FUTURE_QUERY:
|
|
54
|
-
case ContextType.TYPE_CONTEXT_FUTURE_ID:
|
|
55
|
-
if (variables.has(identifier)) {
|
|
56
|
-
let v = variables.get(identifier);
|
|
57
|
-
if (bNeedSerialize) {
|
|
58
|
-
v.value = value ? BCS_CONVERT.ser_address(value) : undefined;
|
|
59
|
-
v.witness = witness ? BCS_CONVERT.ser_address(witness) : undefined;
|
|
60
|
-
}
|
|
61
|
-
else {
|
|
62
|
-
v.value = value ? value : undefined;
|
|
63
|
-
v.witness = witness ? witness : undefined;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
if (bNeedSerialize) {
|
|
68
|
-
variables.set(identifier, { type: type, value: value ? BCS_CONVERT.ser_address(value) : undefined, witness: witness ? BCS_CONVERT.ser_address(witness) : undefined });
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
variables.set(identifier, { type: type, value: value ? value : undefined, witness: witness ? witness : undefined });
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
return true;
|
|
75
|
-
}
|
|
76
|
-
return false;
|
|
77
|
-
}
|
|
78
|
-
static add_variable(variables, identifier, type, value, bNeedSerialize = true) {
|
|
79
|
-
if (!Guard.IsValidIndentifier(identifier))
|
|
80
|
-
return false;
|
|
81
|
-
if (!Guard.IsValidGuardVirableType(type))
|
|
82
|
-
return false;
|
|
83
|
-
if (!value)
|
|
84
|
-
return false;
|
|
85
|
-
switch (type) {
|
|
86
|
-
case ContextType.TYPE_CONTEXT_bool:
|
|
87
|
-
bNeedSerialize ? variables.set(identifier, { type: type, value: BCS_CONVERT.ser_bool(value) }) :
|
|
88
|
-
variables.set(identifier, { type: type, value: value });
|
|
89
|
-
return true;
|
|
90
|
-
case ContextType.TYPE_CONTEXT_address:
|
|
91
|
-
case OperatorType.TYPE_QUERY_FROM_CONTEXT:
|
|
92
|
-
bNeedSerialize ? variables.set(identifier, { type: type, value: BCS_CONVERT.ser_address(value) }) :
|
|
93
|
-
variables.set(identifier, { type: type, value: value });
|
|
94
|
-
return true;
|
|
95
|
-
case ContextType.TYPE_CONTEXT_u64:
|
|
96
|
-
bNeedSerialize ? variables.set(identifier, { type: type, value: BCS_CONVERT.ser_u64(value) }) :
|
|
97
|
-
variables.set(identifier, { type: type, value: value });
|
|
98
|
-
return true;
|
|
99
|
-
case ContextType.TYPE_CONTEXT_u8:
|
|
100
|
-
bNeedSerialize ? variables.set(identifier, { type: type, value: BCS_CONVERT.ser_u8(value) }) :
|
|
101
|
-
variables.set(identifier, { type: type, value: value });
|
|
102
|
-
return true;
|
|
103
|
-
case ContextType.TYPE_CONTEXT_vec_u8:
|
|
104
|
-
bNeedSerialize ? variables.set(identifier, { type: type, value: BCS_CONVERT.ser_string(value) }) :
|
|
105
|
-
variables.set(identifier, { type: type, value: value });
|
|
106
|
-
return true;
|
|
107
|
-
}
|
|
108
|
-
return false;
|
|
109
|
-
}
|
|
7
|
+
static MAX_INPUT_LENGTH = 2048;
|
|
110
8
|
static launch(protocol, creation) {
|
|
111
9
|
if (!IsValidDesription(creation.description)) {
|
|
112
10
|
ERROR(Errors.IsValidDesription);
|
|
113
11
|
}
|
|
114
|
-
if (creation.
|
|
115
|
-
ERROR(Errors.InvalidParam, 'creation.
|
|
12
|
+
if (creation.input.length == 0 || creation.input.length > Guard.MAX_INPUT_LENGTH) {
|
|
13
|
+
ERROR(Errors.InvalidParam, 'creation.input');
|
|
116
14
|
}
|
|
117
15
|
let bValid = true;
|
|
118
|
-
creation.senses.forEach((v) => {
|
|
119
|
-
if (!v.input || v.input.length == 0)
|
|
120
|
-
bValid = false;
|
|
121
|
-
});
|
|
122
|
-
if (!bValid) {
|
|
123
|
-
ERROR(Errors.InvalidParam, 'creation.senses');
|
|
124
|
-
}
|
|
125
16
|
creation?.variables?.forEach((v, k) => {
|
|
126
|
-
if (!
|
|
17
|
+
if (!GuardVariableMaker.IsValidIndentifier(k))
|
|
127
18
|
bValid = false;
|
|
128
|
-
if (!
|
|
19
|
+
if (!GuardVariableMaker.IsValidGuardVirableType(v.type))
|
|
129
20
|
bValid = false;
|
|
130
21
|
if (!v.value && !v.witness)
|
|
131
22
|
bValid = false;
|
|
@@ -134,18 +25,11 @@ export class Guard {
|
|
|
134
25
|
ERROR(Errors.InvalidParam, 'creation.variables');
|
|
135
26
|
}
|
|
136
27
|
let txb = protocol.CurrentSession();
|
|
28
|
+
let input = new Uint8Array(creation.input); // copy new uint8array to reserve!
|
|
29
|
+
// reserve the bytes for guard
|
|
137
30
|
let guard = txb.moveCall({
|
|
138
31
|
target: protocol.GuardFn('new'),
|
|
139
|
-
arguments: [txb.pure(creation.description, BCS.STRING)],
|
|
140
|
-
});
|
|
141
|
-
creation.senses.forEach((sense) => {
|
|
142
|
-
txb.moveCall({
|
|
143
|
-
target: protocol.GuardFn('sense_add'),
|
|
144
|
-
arguments: [guard, txb.pure([].slice.call(sense.input)),
|
|
145
|
-
txb.pure(sense.notAfterSense, BCS.BOOL),
|
|
146
|
-
txb.pure(sense.binder, BCS.U8),
|
|
147
|
-
]
|
|
148
|
-
});
|
|
32
|
+
arguments: [txb.pure(creation.description, BCS.STRING), txb.pure([].slice.call(input.reverse()))],
|
|
149
33
|
});
|
|
150
34
|
creation?.variables?.forEach((v, k) => {
|
|
151
35
|
if (v.type == OperatorType.TYPE_FUTURE_QUERY || v.type == ContextType.TYPE_CONTEXT_FUTURE_ID) {
|
|
@@ -206,6 +90,8 @@ export class Guard {
|
|
|
206
90
|
[MODULES.repository, 'value', 9, [ValueType.TYPE_STATIC_address, ValueType.TYPE_STATIC_vec_u8], ValueType.TYPE_STATIC_vec_u8],
|
|
207
91
|
[MODULES.repository, 'type', 10, [], ValueType.TYPE_STATIC_u8],
|
|
208
92
|
[MODULES.repository, 'policy_mode', 11, [], ValueType.TYPE_STATIC_u8],
|
|
93
|
+
[MODULES.repository, 'reference_count', 12, [], ValueType.TYPE_STATIC_u64],
|
|
94
|
+
[MODULES.repository, 'has_reference', 13, [ValueType.TYPE_STATIC_address], ValueType.TYPE_STATIC_bool],
|
|
209
95
|
[MODULES.machine, 'permission', 1, [], ValueType.TYPE_STATIC_address],
|
|
210
96
|
[MODULES.machine, 'has_paused', 2, [], ValueType.TYPE_STATIC_bool],
|
|
211
97
|
[MODULES.machine, 'has_published', 3, [], ValueType.TYPE_STATIC_bool],
|
|
@@ -324,7 +210,106 @@ export const graphql_query_objects = (protocol: Protocol, nodes:any) : Guard_Que
|
|
|
324
210
|
})
|
|
325
211
|
return ret
|
|
326
212
|
} */
|
|
327
|
-
export class
|
|
213
|
+
export class GuardVariableMaker {
|
|
214
|
+
static IsValidGuardVirableType = (type) => {
|
|
215
|
+
if (type == OperatorType.TYPE_FUTURE_QUERY || type == ContextType.TYPE_CONTEXT_FUTURE_ID || type == OperatorType.TYPE_QUERY_FROM_CONTEXT ||
|
|
216
|
+
type == ContextType.TYPE_CONTEXT_bool || type == ContextType.TYPE_CONTEXT_address || type == ContextType.TYPE_CONTEXT_u64 ||
|
|
217
|
+
type == ContextType.TYPE_CONTEXT_u8 || type == ContextType.TYPE_CONTEXT_vec_u8) {
|
|
218
|
+
return true;
|
|
219
|
+
}
|
|
220
|
+
;
|
|
221
|
+
return false;
|
|
222
|
+
};
|
|
223
|
+
static IsValidIndentifier = (identifier) => {
|
|
224
|
+
if (!IsValidInt(identifier) || identifier > 255)
|
|
225
|
+
return false;
|
|
226
|
+
return true;
|
|
227
|
+
};
|
|
228
|
+
static get_variable_value(variables, identifier, type) {
|
|
229
|
+
if (variables.has(identifier)) {
|
|
230
|
+
let v = variables.get(identifier);
|
|
231
|
+
if (v?.value && v.type == type) {
|
|
232
|
+
return v.value;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
return false;
|
|
236
|
+
}
|
|
237
|
+
static get_variable_witness(variables, identifier, type) {
|
|
238
|
+
if (variables.has(identifier)) {
|
|
239
|
+
let v = variables.get(identifier);
|
|
240
|
+
if (v?.witness && v.type == type) {
|
|
241
|
+
return v.witness;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
return false;
|
|
245
|
+
}
|
|
246
|
+
static add_future_variable(variables, identifier, type, witness, value, bNeedSerialize = true) {
|
|
247
|
+
if (!GuardVariableMaker.IsValidIndentifier(identifier))
|
|
248
|
+
return false;
|
|
249
|
+
if (!GuardVariableMaker.IsValidGuardVirableType(type))
|
|
250
|
+
return false;
|
|
251
|
+
if (!witness && !value)
|
|
252
|
+
return false;
|
|
253
|
+
switch (type) {
|
|
254
|
+
case OperatorType.TYPE_FUTURE_QUERY:
|
|
255
|
+
case ContextType.TYPE_CONTEXT_FUTURE_ID:
|
|
256
|
+
if (variables.has(identifier)) {
|
|
257
|
+
let v = variables.get(identifier);
|
|
258
|
+
if (bNeedSerialize) {
|
|
259
|
+
v.value = value ? Bcs.getInstance().ser_address(value) : undefined;
|
|
260
|
+
v.witness = witness ? Bcs.getInstance().ser_address(witness) : undefined;
|
|
261
|
+
}
|
|
262
|
+
else {
|
|
263
|
+
v.value = value ? value : undefined;
|
|
264
|
+
v.witness = witness ? witness : undefined;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
else {
|
|
268
|
+
if (bNeedSerialize) {
|
|
269
|
+
variables.set(identifier, { type: type, value: value ? Bcs.getInstance().ser_address(value) : undefined, witness: witness ? Bcs.getInstance().ser_address(witness) : undefined });
|
|
270
|
+
}
|
|
271
|
+
else {
|
|
272
|
+
variables.set(identifier, { type: type, value: value ? value : undefined, witness: witness ? witness : undefined });
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
return true;
|
|
276
|
+
}
|
|
277
|
+
return false;
|
|
278
|
+
}
|
|
279
|
+
static add_variable(variables, identifier, type, value, bNeedSerialize = true) {
|
|
280
|
+
if (!GuardVariableMaker.IsValidIndentifier(identifier))
|
|
281
|
+
return false;
|
|
282
|
+
if (!GuardVariableMaker.IsValidGuardVirableType(type))
|
|
283
|
+
return false;
|
|
284
|
+
if (!value)
|
|
285
|
+
return false;
|
|
286
|
+
switch (type) {
|
|
287
|
+
case ContextType.TYPE_CONTEXT_bool:
|
|
288
|
+
bNeedSerialize ? variables.set(identifier, { type: type, value: Bcs.getInstance().ser_bool(value) }) :
|
|
289
|
+
variables.set(identifier, { type: type, value: value });
|
|
290
|
+
return true;
|
|
291
|
+
case ContextType.TYPE_CONTEXT_address:
|
|
292
|
+
case OperatorType.TYPE_QUERY_FROM_CONTEXT:
|
|
293
|
+
bNeedSerialize ? variables.set(identifier, { type: type, value: Bcs.getInstance().ser_address(value) }) :
|
|
294
|
+
variables.set(identifier, { type: type, value: value });
|
|
295
|
+
return true;
|
|
296
|
+
case ContextType.TYPE_CONTEXT_u64:
|
|
297
|
+
bNeedSerialize ? variables.set(identifier, { type: type, value: Bcs.getInstance().ser_u64(value) }) :
|
|
298
|
+
variables.set(identifier, { type: type, value: value });
|
|
299
|
+
return true;
|
|
300
|
+
case ContextType.TYPE_CONTEXT_u8:
|
|
301
|
+
bNeedSerialize ? variables.set(identifier, { type: type, value: Bcs.getInstance().ser_u8(value) }) :
|
|
302
|
+
variables.set(identifier, { type: type, value: value });
|
|
303
|
+
return true;
|
|
304
|
+
case ContextType.TYPE_CONTEXT_vec_u8:
|
|
305
|
+
bNeedSerialize ? variables.set(identifier, { type: type, value: Bcs.getInstance().ser_string(value) }) :
|
|
306
|
+
variables.set(identifier, { type: type, value: value });
|
|
307
|
+
return true;
|
|
308
|
+
}
|
|
309
|
+
return false;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
export class GuardInputMaker {
|
|
328
313
|
data = [];
|
|
329
314
|
type_validator = [];
|
|
330
315
|
constructor() { }
|
|
@@ -333,46 +318,46 @@ export class SenseMaker {
|
|
|
333
318
|
switch (type) {
|
|
334
319
|
case ValueType.TYPE_STATIC_address:
|
|
335
320
|
if (!param)
|
|
336
|
-
|
|
337
|
-
this.data.push(
|
|
338
|
-
this.data.push(
|
|
321
|
+
ERROR(Errors.InvalidParam, 'param');
|
|
322
|
+
this.data.push(Bcs.getInstance().ser_u8(type));
|
|
323
|
+
this.data.push(Bcs.getInstance().ser_address(param));
|
|
339
324
|
this.type_validator.push(type);
|
|
340
325
|
break;
|
|
341
326
|
case ValueType.TYPE_STATIC_bool:
|
|
342
327
|
if (!param)
|
|
343
|
-
|
|
344
|
-
this.data.push(
|
|
345
|
-
this.data.push(
|
|
328
|
+
ERROR(Errors.InvalidParam, 'param');
|
|
329
|
+
this.data.push(Bcs.getInstance().ser_u8(type));
|
|
330
|
+
this.data.push(Bcs.getInstance().ser_bool(param));
|
|
346
331
|
this.type_validator.push(type);
|
|
347
332
|
break;
|
|
348
333
|
case ValueType.TYPE_STATIC_u8:
|
|
349
334
|
if (!param)
|
|
350
|
-
|
|
351
|
-
this.data.push(
|
|
352
|
-
this.data.push(
|
|
335
|
+
ERROR(Errors.InvalidParam, 'param');
|
|
336
|
+
this.data.push(Bcs.getInstance().ser_u8(type));
|
|
337
|
+
this.data.push(Bcs.getInstance().ser_u8(param));
|
|
353
338
|
this.type_validator.push(type);
|
|
354
339
|
break;
|
|
355
340
|
case ValueType.TYPE_STATIC_u64:
|
|
356
341
|
if (!param)
|
|
357
|
-
|
|
358
|
-
this.data.push(
|
|
359
|
-
this.data.push(
|
|
342
|
+
ERROR(Errors.InvalidParam, 'param');
|
|
343
|
+
this.data.push(Bcs.getInstance().ser_u8(type));
|
|
344
|
+
this.data.push(Bcs.getInstance().ser_u64(param));
|
|
360
345
|
this.type_validator.push(type);
|
|
361
346
|
break;
|
|
362
347
|
case ValueType.TYPE_STATIC_vec_u8:
|
|
363
348
|
if (!param)
|
|
364
|
-
|
|
365
|
-
this.data.push(
|
|
366
|
-
this.data.push(
|
|
349
|
+
ERROR(Errors.InvalidParam, 'param');
|
|
350
|
+
this.data.push(Bcs.getInstance().ser_u8(type));
|
|
351
|
+
this.data.push(Bcs.getInstance().ser_string(param));
|
|
367
352
|
this.type_validator.push(type);
|
|
368
353
|
// this.data[this.data.length-1].forEach((item : number) => console.log(item))
|
|
369
354
|
break;
|
|
370
355
|
case ContextType.TYPE_CONTEXT_SIGNER:
|
|
371
|
-
this.data.push(
|
|
356
|
+
this.data.push(Bcs.getInstance().ser_u8(type));
|
|
372
357
|
this.type_validator.push(ValueType.TYPE_STATIC_address);
|
|
373
358
|
break;
|
|
374
359
|
case ContextType.TYPE_CONTEXT_CLOCK:
|
|
375
|
-
this.data.push(
|
|
360
|
+
this.data.push(Bcs.getInstance().ser_u8(type));
|
|
376
361
|
this.type_validator.push(ValueType.TYPE_STATIC_u64);
|
|
377
362
|
break;
|
|
378
363
|
case ContextType.TYPE_CONTEXT_bool:
|
|
@@ -381,16 +366,16 @@ export class SenseMaker {
|
|
|
381
366
|
case ContextType.TYPE_CONTEXT_vec_u8:
|
|
382
367
|
case ContextType.TYPE_CONTEXT_address:
|
|
383
368
|
case ContextType.TYPE_CONTEXT_FUTURE_ID:
|
|
384
|
-
if (!variable || !param)
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
369
|
+
if (!variable || !param) {
|
|
370
|
+
ERROR(Errors.InvalidParam, 'variable or param');
|
|
371
|
+
}
|
|
372
|
+
if (typeof (param) != 'number' || !IsValidInt(param) || param > 255) {
|
|
373
|
+
ERROR(Errors.InvalidParam, 'param');
|
|
374
|
+
}
|
|
390
375
|
var v = variable.get(param);
|
|
391
376
|
if (v?.type == type) {
|
|
392
|
-
this.data.push(
|
|
393
|
-
this.data.push(
|
|
377
|
+
this.data.push(Bcs.getInstance().ser_u8(type));
|
|
378
|
+
this.data.push(Bcs.getInstance().ser_u8(param));
|
|
394
379
|
if (type == ContextType.TYPE_CONTEXT_bool) {
|
|
395
380
|
this.type_validator.push(ValueType.TYPE_STATIC_bool);
|
|
396
381
|
}
|
|
@@ -412,12 +397,11 @@ export class SenseMaker {
|
|
|
412
397
|
break;
|
|
413
398
|
}
|
|
414
399
|
;
|
|
415
|
-
|
|
400
|
+
ERROR(Errors.InvalidParam, 'variable');
|
|
416
401
|
default:
|
|
417
|
-
|
|
402
|
+
ERROR(Errors.InvalidParam, 'type');
|
|
418
403
|
}
|
|
419
404
|
;
|
|
420
|
-
return true;
|
|
421
405
|
}
|
|
422
406
|
static query_index(module, query_name) {
|
|
423
407
|
for (let i = 0; i < Guard.QUERIES.length; i++) {
|
|
@@ -428,105 +412,142 @@ export class SenseMaker {
|
|
|
428
412
|
return -1;
|
|
429
413
|
}
|
|
430
414
|
add_future_query(identifier, module, query_name, variable) {
|
|
431
|
-
let query_index =
|
|
432
|
-
if (!
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
415
|
+
let query_index = GuardInputMaker.query_index(module, query_name);
|
|
416
|
+
if (!GuardVariableMaker.IsValidIndentifier(identifier) || query_index == -1) {
|
|
417
|
+
ERROR(Errors.InvalidParam, 'identifier or query_name');
|
|
418
|
+
}
|
|
419
|
+
if (module != MODULES.order && module != MODULES.progress) {
|
|
420
|
+
ERROR(Errors.InvalidParam, 'module');
|
|
421
|
+
}
|
|
422
|
+
if (!variable || variable.get(identifier)?.type != OperatorType.TYPE_FUTURE_QUERY) {
|
|
423
|
+
ERROR(Errors.InvalidParam, 'variable');
|
|
424
|
+
}
|
|
438
425
|
let offset = this.type_validator.length - Guard.QUERIES[query_index][3].length;
|
|
439
426
|
if (offset < 0) {
|
|
440
|
-
|
|
427
|
+
ERROR(Errors.InvalidParam, 'query_name');
|
|
441
428
|
}
|
|
442
429
|
let types = this.type_validator.slice(offset);
|
|
443
430
|
if (!array_equal(types, Guard.QUERIES[query_index][3])) { // type validate
|
|
444
|
-
|
|
431
|
+
ERROR(Errors.Fail, 'array_equal');
|
|
445
432
|
}
|
|
446
|
-
this.data.push(
|
|
447
|
-
this.data.push(
|
|
448
|
-
this.data.push(
|
|
433
|
+
this.data.push(Bcs.getInstance().ser_u8(OperatorType.TYPE_FUTURE_QUERY)); // TYPE
|
|
434
|
+
this.data.push(Bcs.getInstance().ser_u8(identifier)); // variable identifier
|
|
435
|
+
this.data.push(Bcs.getInstance().ser_u8(Guard.QUERIES[query_index][2])); // cmd
|
|
449
436
|
this.type_validator.splice(offset, Guard.QUERIES[query_index][3].length); // delete type stack
|
|
450
437
|
this.type_validator.push(Guard.QUERIES[query_index][4]); // add the return value type to type stack
|
|
451
438
|
// console.log(this.type_validator)
|
|
452
|
-
return true;
|
|
453
439
|
}
|
|
454
440
|
// object_address_from: string for static address; number as identifier for variable
|
|
455
441
|
add_query(module, query_name, object_address_from) {
|
|
456
|
-
let query_index =
|
|
457
|
-
if (query_index == -1)
|
|
458
|
-
|
|
442
|
+
let query_index = GuardInputMaker.query_index(module, query_name); // query_index: index(from 0) of array Guard.QUERIES
|
|
443
|
+
if (query_index == -1) {
|
|
444
|
+
ERROR(Errors.InvalidParam, 'query_name');
|
|
445
|
+
}
|
|
459
446
|
if (typeof (object_address_from) == 'number') {
|
|
460
|
-
if (!
|
|
461
|
-
|
|
447
|
+
if (!GuardVariableMaker.IsValidIndentifier(object_address_from)) {
|
|
448
|
+
ERROR(Errors.InvalidParam, 'object_address_from');
|
|
449
|
+
}
|
|
462
450
|
}
|
|
463
451
|
else {
|
|
464
|
-
if (!IsValidAddress(object_address_from))
|
|
465
|
-
|
|
452
|
+
if (!IsValidAddress(object_address_from)) {
|
|
453
|
+
ERROR(Errors.InvalidParam, 'object_address_from');
|
|
454
|
+
}
|
|
466
455
|
}
|
|
467
456
|
let offset = this.type_validator.length - Guard.QUERIES[query_index][3].length;
|
|
468
457
|
if (offset < 0) {
|
|
469
|
-
|
|
458
|
+
ERROR(Errors.InvalidParam, 'query_name');
|
|
470
459
|
}
|
|
471
460
|
let types = this.type_validator.slice(offset);
|
|
472
461
|
if (!array_equal(types, Guard.QUERIES[query_index][3])) { // type validate
|
|
473
|
-
|
|
462
|
+
ERROR(Errors.Fail, 'array_equal');
|
|
474
463
|
}
|
|
475
464
|
if (typeof (object_address_from) == 'string') {
|
|
476
|
-
this.data.push(
|
|
477
|
-
this.data.push(
|
|
465
|
+
this.data.push(Bcs.getInstance().ser_u8(OperatorType.TYPE_QUERY)); // TYPE
|
|
466
|
+
this.data.push(Bcs.getInstance().ser_address(object_address_from)); // object address
|
|
478
467
|
}
|
|
479
468
|
else {
|
|
480
|
-
this.data.push(
|
|
481
|
-
this.data.push(
|
|
469
|
+
this.data.push(Bcs.getInstance().ser_u8(OperatorType.TYPE_QUERY_FROM_CONTEXT)); // TYPE
|
|
470
|
+
this.data.push(Bcs.getInstance().ser_u8(object_address_from)); // object identifer in variables
|
|
482
471
|
}
|
|
483
|
-
this.data.push(
|
|
472
|
+
this.data.push(Bcs.getInstance().ser_u8(Guard.QUERIES[query_index][2])); // cmd
|
|
484
473
|
this.type_validator.splice(offset, Guard.QUERIES[query_index][3].length); // delete type stack
|
|
485
474
|
this.type_validator.push(Guard.QUERIES[query_index][4]); // add the return value type to type stack
|
|
486
475
|
// console.log(this.type_validator)
|
|
487
|
-
return true;
|
|
488
476
|
}
|
|
489
477
|
add_logic(type) {
|
|
478
|
+
let splice_len = 2;
|
|
490
479
|
switch (type) {
|
|
491
480
|
case OperatorType.TYPE_LOGIC_OPERATOR_U128_GREATER:
|
|
492
481
|
case OperatorType.TYPE_LOGIC_OPERATOR_U128_GREATER_EQUAL:
|
|
493
482
|
case OperatorType.TYPE_LOGIC_OPERATOR_U128_LESSER:
|
|
494
483
|
case OperatorType.TYPE_LOGIC_OPERATOR_U128_LESSER_EQUAL:
|
|
495
484
|
case OperatorType.TYPE_LOGIC_OPERATOR_U128_EQUAL:
|
|
496
|
-
if (this.type_validator.length <
|
|
497
|
-
|
|
485
|
+
if (this.type_validator.length < splice_len) {
|
|
486
|
+
ERROR(Errors.Fail, 'type_validator.length');
|
|
498
487
|
}
|
|
499
|
-
if (!
|
|
500
|
-
|
|
488
|
+
if (!GuardInputMaker.match_u128(this.type_validator[this.type_validator.length - 1])) {
|
|
489
|
+
ERROR(Errors.Fail, 'type_validator check');
|
|
501
490
|
}
|
|
502
|
-
if (!
|
|
503
|
-
|
|
491
|
+
if (!GuardInputMaker.match_u128(this.type_validator[this.type_validator.length - 2])) {
|
|
492
|
+
ERROR(Errors.Fail, 'type_validator check');
|
|
504
493
|
}
|
|
505
494
|
break;
|
|
506
495
|
case OperatorType.TYPE_LOGIC_OPERATOR_EQUAL:
|
|
496
|
+
if (this.type_validator.length < splice_len) {
|
|
497
|
+
ERROR(Errors.Fail, 'type_validator.length');
|
|
498
|
+
}
|
|
499
|
+
break;
|
|
507
500
|
case OperatorType.TYPE_LOGIC_OPERATOR_HAS_SUBSTRING:
|
|
508
|
-
if (this.type_validator.length <
|
|
509
|
-
|
|
501
|
+
if (this.type_validator.length < splice_len) {
|
|
502
|
+
ERROR(Errors.Fail, 'type_validator.length');
|
|
503
|
+
}
|
|
504
|
+
break;
|
|
505
|
+
case OperatorType.TYPE_LOGIC_NOT:
|
|
506
|
+
splice_len = 1;
|
|
507
|
+
if (this.type_validator.length < splice_len) {
|
|
508
|
+
ERROR(Errors.Fail, 'type_validator.length');
|
|
509
|
+
}
|
|
510
|
+
if (this.type_validator[this.type_validator.length - 1] != ValueType.TYPE_STATIC_bool) {
|
|
511
|
+
ERROR(Errors.Fail, 'type_validator check');
|
|
512
|
+
}
|
|
513
|
+
break;
|
|
514
|
+
case OperatorType.TYPE_LOGIC_AND:
|
|
515
|
+
case OperatorType.TYPE_LOGIC_OR:
|
|
516
|
+
if (this.type_validator.length < splice_len) {
|
|
517
|
+
ERROR(Errors.Fail, 'type_validator.length');
|
|
518
|
+
}
|
|
519
|
+
if (this.type_validator[this.type_validator.length - 1] != ValueType.TYPE_STATIC_bool) {
|
|
520
|
+
ERROR(Errors.Fail, 'type_validator check');
|
|
521
|
+
}
|
|
522
|
+
if (this.type_validator[this.type_validator.length - 2] != ValueType.TYPE_STATIC_bool) {
|
|
523
|
+
ERROR(Errors.Fail, 'type_validator check');
|
|
510
524
|
}
|
|
511
525
|
break;
|
|
512
526
|
default:
|
|
513
|
-
|
|
527
|
+
ERROR(Errors.InvalidParam, 'type');
|
|
514
528
|
}
|
|
515
|
-
this.data.push(
|
|
516
|
-
this.type_validator.splice(this.type_validator.length -
|
|
529
|
+
this.data.push(Bcs.getInstance().ser_u8(type)); // TYPE
|
|
530
|
+
this.type_validator.splice(this.type_validator.length - splice_len); // delete type stack
|
|
517
531
|
this.type_validator.push(ValueType.TYPE_STATIC_bool); // add bool to type stack
|
|
518
|
-
return true;
|
|
519
532
|
}
|
|
520
|
-
make(
|
|
533
|
+
make(bNot = false) {
|
|
521
534
|
//console.log(this.type_validator);
|
|
522
535
|
//this.data.forEach((value:Uint8Array) => console.log(value));
|
|
523
536
|
if (this.type_validator.length != 1 || this.type_validator[0] != ValueType.TYPE_STATIC_bool) {
|
|
524
537
|
console.log(this.type_validator);
|
|
525
|
-
|
|
538
|
+
ERROR(Errors.Fail, 'type_validator check');
|
|
526
539
|
} // ERROR
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
540
|
+
if (bNot) {
|
|
541
|
+
this.add_logic(OperatorType.TYPE_LOGIC_NOT);
|
|
542
|
+
}
|
|
543
|
+
return concatenate(Uint8Array, ...this.data);
|
|
544
|
+
}
|
|
545
|
+
static combine(input1, input2, bAnd = true) {
|
|
546
|
+
let op = bAnd ? OperatorType.TYPE_LOGIC_AND : OperatorType.TYPE_LOGIC_OR;
|
|
547
|
+
return concatenate(Uint8Array, input1, input2, Bcs.getInstance().ser_u8(op));
|
|
548
|
+
}
|
|
549
|
+
static not(input) {
|
|
550
|
+
return concatenate(Uint8Array, input, Bcs.getInstance().ser_u8(OperatorType.TYPE_LOGIC_NOT));
|
|
530
551
|
}
|
|
531
552
|
static match_u128(type) {
|
|
532
553
|
if (type == ValueType.TYPE_STATIC_u8 ||
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA;AACxB,cAAe,YAAY,CAAA;AAC3B,cAAe,UAAU,CAAA;AACzB,cAAe,SAAS,CAAA;AACxB,cAAe,cAAc,CAAA;AAC7B,cAAe,SAAS,CAAA;AACxB,cAAe,cAAc,CAAA;AAC7B,cAAe,QAAQ,CAAA;AACvB,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA;AAC1B,cAAc,WAAW,CAAA;AACzB,cAAc,WAAW,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA;AACxB,cAAe,YAAY,CAAA;AAC3B,cAAe,UAAU,CAAA;AACzB,cAAe,SAAS,CAAA;AACxB,cAAe,cAAc,CAAA;AAC7B,cAAe,SAAS,CAAA;AACxB,cAAe,cAAc,CAAA;AAC7B,cAAe,QAAQ,CAAA;AACvB,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA;AAC1B,cAAc,WAAW,CAAA;AACzB,cAAc,WAAW,CAAA;AACzB,cAAc,WAAW,CAAA"}
|
package/dist/index.js
CHANGED
package/dist/machine.d.ts
CHANGED
|
@@ -2,23 +2,23 @@ import { type TransactionResult } from '@mysten/sui.js/transactions';
|
|
|
2
2
|
import { Protocol, PermissionObject, RepositoryObject, PassportObject, MachineObject, MachineAddress, GuardObject, TxbObject } from './protocol';
|
|
3
3
|
import { PermissionIndexType } from './permission';
|
|
4
4
|
export type MachineNodeObject = TransactionResult | String;
|
|
5
|
-
export
|
|
5
|
+
export interface Machine_Forward {
|
|
6
6
|
name: string;
|
|
7
7
|
namedOperator?: string;
|
|
8
8
|
permission?: PermissionIndexType;
|
|
9
9
|
weight?: number;
|
|
10
10
|
guard?: GuardObject;
|
|
11
|
-
}
|
|
12
|
-
export
|
|
11
|
+
}
|
|
12
|
+
export interface Machine_Node_Pair {
|
|
13
13
|
prior_node: string;
|
|
14
14
|
forwards: Machine_Forward[];
|
|
15
15
|
threshold?: number;
|
|
16
|
-
}
|
|
17
|
-
export
|
|
16
|
+
}
|
|
17
|
+
export interface Machine_Node {
|
|
18
18
|
name: string;
|
|
19
19
|
description: string;
|
|
20
20
|
pairs: Machine_Node_Pair[];
|
|
21
|
-
}
|
|
21
|
+
}
|
|
22
22
|
export declare class Machine {
|
|
23
23
|
protected protocol: Protocol;
|
|
24
24
|
protected object: TxbObject;
|
package/dist/machine.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"machine.d.ts","sourceRoot":"","sources":["../src/machine.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4B,KAAK,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAE/F,OAAO,EAAE,QAAQ,EAAc,gBAAgB,EAAE,gBAAgB,EAAG,cAAc,EAAE,aAAa,EAAE,cAAc,EAAG,WAAW,EAAE,SAAS,EAAC,MAAM,YAAY,CAAC;AAG9J,OAAO,EAAc,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAI/D,MAAM,MAAM,iBAAiB,GAAG,iBAAiB,GAAG,MAAM,CAAC;AAE3D,MAAM,
|
|
1
|
+
{"version":3,"file":"machine.d.ts","sourceRoot":"","sources":["../src/machine.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4B,KAAK,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAE/F,OAAO,EAAE,QAAQ,EAAc,gBAAgB,EAAE,gBAAgB,EAAG,cAAc,EAAE,aAAa,EAAE,cAAc,EAAG,WAAW,EAAE,SAAS,EAAC,MAAM,YAAY,CAAC;AAG9J,OAAO,EAAc,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAI/D,MAAM,MAAM,iBAAiB,GAAG,iBAAiB,GAAG,MAAM,CAAC;AAE3D,MAAM,WAAW,eAAe;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,UAAU,CAAC,EAAE,mBAAmB,CAAC;IACjC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,WAAW,CAAC;CACvB;AACD,MAAM,WAAW,iBAAiB;IAC9B,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,eAAe,EAAE,CAAC;IAC5B,SAAS,CAAC,EAAE,MAAM,CAAC;CACtB;AACD,MAAM,WAAW,YAAY;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,iBAAiB,EAAE,CAAC;CAC9B;AAED,qBAAa,OAAO;IAChB,SAAS,CAAC,QAAQ,WAAC;IACnB,SAAS,CAAC,MAAM,EAAG,SAAS,CAAC;IAC7B,SAAS,CAAC,UAAU,mBAAC;IAErB,UAAU;IAEV,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAC,QAAQ,EAAE,UAAU,EAAC,gBAAgB,EAAE,MAAM,EAAC,SAAS,GAAI,OAAO;IAMvF,OAAO;IAKP,MAAM,CAAC,GAAG,CAAC,QAAQ,EAAC,QAAQ,EAAE,UAAU,EAAC,gBAAgB,EAAE,WAAW,EAAC,MAAM,EAAE,QAAQ,CAAC,EAAC,MAAM,EAAE,QAAQ,CAAC,EAAC,cAAc,GAAI,OAAO;IA8BpI,QAAQ,CAAC,KAAK,EAAC,YAAY,EAAE,EAAE,QAAQ,CAAC,EAAC,cAAc;IA2DvD,SAAS,CAAC,KAAK,EAAC,iBAAiB,EAAE,EAAE,QAAQ,CAAC,EAAC,cAAc;IAyB7D,WAAW,CAAC,UAAU,EAAC,MAAM,EAAE,EAAE,eAAe,GAAC,OAAe,EAAE,QAAQ,CAAC,EAAC,cAAc;IAoB1F,OAAO;IAQP,MAAM,IAAK,cAAc;IAQzB,eAAe,CAAC,WAAW,EAAC,MAAM,EAAE,QAAQ,CAAC,EAAC,cAAc;IAkB5D,cAAc,CAAC,UAAU,EAAC,gBAAgB,EAAE,QAAQ,CAAC,EAAC,cAAc;IAepE,iBAAiB,CAAC,YAAY,EAAC,MAAM,EAAE,EAAE,SAAS,CAAC,EAAC,OAAO,EAAE,QAAQ,CAAC,EAAC,cAAc;IAsCrF,KAAK,CAAC,QAAQ,CAAC,EAAC,cAAc,GAAI,aAAa;IAe/C,YAAY,CAAC,QAAQ,CAAC,EAAC,MAAM,EAAE,QAAQ,CAAC,EAAC,cAAc;IAoBvD,KAAK,CAAC,OAAO,EAAC,OAAO,EAAE,QAAQ,CAAC,EAAC,cAAc;IAc/C,OAAO,CAAC,QAAQ,CAAC,EAAC,cAAc;IAgBhC,iBAAiB,CAAC,cAAc,EAAC,gBAAgB;IAcjD,MAAM,CAAC,iBAAiB,SAAM;IAC9B,MAAM,CAAC,oBAAoB,SAAiB;CAC/C"}
|