wowok 1.1.1 → 1.1.3
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 +3 -2
- package/dist/exception.d.ts +3 -1
- package/dist/exception.d.ts.map +1 -1
- package/dist/exception.js +2 -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 +29 -34
- package/dist/guard.d.ts.map +1 -1
- package/dist/guard.js +401 -397
- 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/passport.d.ts +39 -24
- package/dist/passport.d.ts.map +1 -1
- package/dist/passport.js +186 -251
- package/dist/permission.d.ts +3 -0
- package/dist/permission.d.ts.map +1 -1
- package/dist/permission.js +3 -0
- package/dist/protocol.d.ts +40 -40
- package/dist/protocol.d.ts.map +1 -1
- package/dist/protocol.js +45 -51
- package/dist/repository.d.ts +2 -0
- package/dist/repository.d.ts.map +1 -1
- package/dist/repository.js +68 -0
- package/dist/utils.d.ts +9 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +37 -0
- package/package.json +3 -2
- package/src/exception.ts +2 -0
- package/src/graphql.ts +20 -0
- package/src/guard.ts +390 -394
- package/src/index.ts +1 -0
- package/src/machine.ts +3 -3
- package/src/passport.ts +209 -282
- package/src/permission.ts +3 -0
- package/src/protocol.ts +51 -56
- package/src/repository.ts +68 -0
- package/src/utils.ts +42 -0
- package/tsconfig.json +3 -2
package/src/index.ts
CHANGED
package/src/machine.ts
CHANGED
|
@@ -9,19 +9,19 @@ import { Errors, ERROR} from './exception'
|
|
|
9
9
|
|
|
10
10
|
export type MachineNodeObject = TransactionResult | String;
|
|
11
11
|
|
|
12
|
-
export
|
|
12
|
+
export interface Machine_Forward {
|
|
13
13
|
name: string; // foward name
|
|
14
14
|
namedOperator?: string; // dynamic operator
|
|
15
15
|
permission?: PermissionIndexType; // this.permission-index or named-operator MUST one defined.
|
|
16
16
|
weight?: number;
|
|
17
17
|
guard?: GuardObject;
|
|
18
18
|
}
|
|
19
|
-
export
|
|
19
|
+
export interface Machine_Node_Pair {
|
|
20
20
|
prior_node: string;
|
|
21
21
|
forwards: Machine_Forward[];
|
|
22
22
|
threshold?: number;
|
|
23
23
|
}
|
|
24
|
-
export
|
|
24
|
+
export interface Machine_Node {
|
|
25
25
|
name: string;
|
|
26
26
|
description: string;
|
|
27
27
|
pairs: Machine_Node_Pair[];
|
package/src/passport.ts
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
} from '
|
|
6
|
-
import { parse_object_type, array_unique, Bcs, ulebDecode } from './utils';
|
|
7
|
-
import { VariableType, Guard, Guard_Vriable} from './guard';
|
|
8
|
-
import { bcs, BCS, toHEX, fromHEX, getSuiMoveConfig, TypeName, StructTypeDefinition } from '@mysten/bcs';
|
|
1
|
+
import { type TransactionObjectInput, Inputs } from '@mysten/sui.js/transactions';
|
|
2
|
+
import { FnCallType, GuardObject, Protocol, ContextType, OperatorType, Data_Type,
|
|
3
|
+
ValueType, MODULES } from './protocol';
|
|
4
|
+
import { parse_object_type, array_unique, Bcs, ulebDecode, IsValidAddress, IsValidArray } from './utils';
|
|
5
|
+
import { BCS } from '@mysten/bcs';
|
|
9
6
|
import { ERROR, Errors } from './exception';
|
|
10
7
|
|
|
11
8
|
export type Guard_Query_Object = {
|
|
@@ -15,291 +12,234 @@ export type Guard_Query_Object = {
|
|
|
15
12
|
id: string, // object id
|
|
16
13
|
}
|
|
17
14
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
type: ContextType | OperatorType,
|
|
31
|
-
witness: string,
|
|
32
|
-
value: string, // future object address
|
|
15
|
+
interface QueryInfo {
|
|
16
|
+
identifier?: number;
|
|
17
|
+
index: number;
|
|
18
|
+
type: number;
|
|
19
|
+
value_or_witness: string;
|
|
20
|
+
future?: string;
|
|
21
|
+
}
|
|
22
|
+
interface GuardInfo {
|
|
23
|
+
id: string;
|
|
24
|
+
query_list: (string | QueryInfo)[]; // object or witness object query
|
|
25
|
+
variable: QueryInfo[]; // witness in variable & ValueType.TYPE_ADDRESS(for Query)
|
|
26
|
+
input_witness: QueryInfo[]; // witness in input
|
|
33
27
|
}
|
|
34
28
|
|
|
29
|
+
interface FutrueFill {
|
|
30
|
+
guard: string;
|
|
31
|
+
index: number;
|
|
32
|
+
future: string;
|
|
33
|
+
}
|
|
34
|
+
interface PassportQuery {
|
|
35
|
+
guard: GuardObject[];
|
|
36
|
+
query: Guard_Query_Object[];
|
|
37
|
+
witness: Guard_Query_Object[];
|
|
38
|
+
}
|
|
35
39
|
export class GuardParser {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
await protocol.Query(futrue_objects); // future objects
|
|
42
|
-
let future_objects_result:FutureValueRequest[] = [];
|
|
43
|
-
futrue_objects.forEach((futrue) => {
|
|
44
|
-
futrue.data.forEach((f:FutureValueRequest) => {
|
|
45
|
-
if (future_objects_result.findIndex((v)=>{ return v.guardid == f.guardid && v.identifier == f.identifier}) == -1) {
|
|
46
|
-
future_objects_result.push(f);
|
|
47
|
-
}
|
|
48
|
-
}) ;
|
|
49
|
-
});
|
|
40
|
+
protected guard_list: GuardInfo[] = [];
|
|
41
|
+
protected protocol: Protocol;
|
|
42
|
+
protected guards: GuardObject[];
|
|
43
|
+
private index:number = 0;
|
|
44
|
+
private get_index() { return this.index++ }
|
|
50
45
|
|
|
51
|
-
|
|
46
|
+
private constructor(protocol: Protocol, guards: string[]) {
|
|
47
|
+
this.protocol = protocol ;
|
|
48
|
+
this.guards = guards.map(g => protocol.CurrentSession().object(g) as GuardObject);
|
|
52
49
|
}
|
|
50
|
+
guardlist = () => { return this.guard_list }
|
|
53
51
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
var type : unknown = arr.shift() ;
|
|
59
|
-
// console.log(type);
|
|
60
|
-
switch (type as Data_Type) {
|
|
61
|
-
case ContextType.TYPE_CONTEXT_SIGNER:
|
|
62
|
-
case ContextType.TYPE_CONTEXT_CLOCK:
|
|
63
|
-
case OperatorType.TYPE_LOGIC_OPERATOR_U128_GREATER:
|
|
64
|
-
case OperatorType.TYPE_LOGIC_OPERATOR_U128_GREATER_EQUAL:
|
|
65
|
-
case OperatorType.TYPE_LOGIC_OPERATOR_U128_LESSER:
|
|
66
|
-
case OperatorType.TYPE_LOGIC_OPERATOR_U128_LESSER_EQUAL:
|
|
67
|
-
case OperatorType.TYPE_LOGIC_OPERATOR_U128_EQUAL:
|
|
68
|
-
case OperatorType.TYPE_LOGIC_OPERATOR_EQUAL:
|
|
69
|
-
case OperatorType.TYPE_LOGIC_OPERATOR_HAS_SUBSTRING:
|
|
70
|
-
case OperatorType.TYPE_LOGIC_ALWAYS_TRUE:
|
|
71
|
-
break;
|
|
72
|
-
case ContextType.TYPE_CONTEXT_FUTURE_ID: // MACHINE-ID
|
|
73
|
-
case OperatorType.TYPE_FUTURE_QUERY:
|
|
74
|
-
var identifer = arr.splice(0, 1);
|
|
75
|
-
if (type == OperatorType.TYPE_FUTURE_QUERY) {
|
|
76
|
-
arr.splice(0, 1); // cmd
|
|
77
|
-
}
|
|
78
|
-
if (!variable || variable?.get(identifer[0])?.type != type) return false;
|
|
79
|
-
|
|
80
|
-
let witness = Guard.get_variable_witness(variable, identifer[0], type as OperatorType) ;
|
|
81
|
-
if (!witness) return false;
|
|
82
|
-
result.push({guardid:guardid, identifier:identifer[0], type:type, value:'',
|
|
83
|
-
witness:'0x' + Bcs.getInstance().de(BCS.ADDRESS, Uint8Array.from(witness as Uint8Array))} as FutureValueRequest);
|
|
84
|
-
break;
|
|
85
|
-
case ContextType.TYPE_CONTEXT_address:
|
|
86
|
-
case ContextType.TYPE_CONTEXT_bool:
|
|
87
|
-
case ContextType.TYPE_CONTEXT_u8:
|
|
88
|
-
case ContextType.TYPE_CONTEXT_u64:
|
|
89
|
-
case ContextType.TYPE_CONTEXT_vec_u8:
|
|
90
|
-
case ValueType.TYPE_STATIC_bool:
|
|
91
|
-
case ValueType.TYPE_STATIC_u8:
|
|
92
|
-
arr.splice(0, 1); // identifier
|
|
93
|
-
break;
|
|
94
|
-
case OperatorType.TYPE_QUERY_FROM_CONTEXT:
|
|
95
|
-
arr.splice(0, 2); // identifer + cmd
|
|
96
|
-
break;
|
|
97
|
-
case ValueType.TYPE_STATIC_address:
|
|
98
|
-
arr.splice(0, 32);
|
|
99
|
-
break;
|
|
100
|
-
case ValueType.TYPE_STATIC_u64:
|
|
101
|
-
arr.splice(0, 8);
|
|
102
|
-
break;
|
|
103
|
-
case ValueType.TYPE_STATIC_u128:
|
|
104
|
-
arr.splice(0, 16);
|
|
105
|
-
break;
|
|
106
|
-
case ValueType.TYPE_STATIC_vec_u8:
|
|
107
|
-
let {value, length} = ulebDecode(Uint8Array.from(arr));
|
|
108
|
-
arr.splice(0, value+length);
|
|
109
|
-
break;
|
|
110
|
-
case OperatorType.TYPE_QUERY:
|
|
111
|
-
arr.splice(0, 33); // address + cmd
|
|
112
|
-
break;
|
|
113
|
-
default:
|
|
114
|
-
console.error('parse_sense_bsc:undefined');
|
|
115
|
-
console.log(type as number)
|
|
116
|
-
console.log(arr)
|
|
117
|
-
return false; // error
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
return true;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
// from guards: get objects to 'guard_query' on chain , with future variables had filled.
|
|
124
|
-
// passport verify for some guards, MUST be in ONE pxb:
|
|
125
|
-
// 0. construct Guard_Query_Objects(passport_quries) from queries for guards of objects
|
|
126
|
-
// 1. create passport
|
|
127
|
-
// 2. add all guards / guards future variables
|
|
128
|
-
// 3. verify passport
|
|
129
|
-
// 4. ops using passport(guard set on object)
|
|
130
|
-
// 5. ops using passport(guard set on object)
|
|
131
|
-
// 6. destroy passport
|
|
132
|
-
static guard_queries = async (protocol:Protocol, guards:string[], futures?:FutureValueRequest[]) : Promise<Guard_Query_Object[]> => {
|
|
133
|
-
let sense_objects = guards.map((value) => {
|
|
134
|
-
let v:VariableType = new Map();
|
|
135
|
-
futures?.forEach((f) => {
|
|
136
|
-
if (f.guardid == value) {
|
|
137
|
-
Guard.add_future_variable(v, f.identifier, f.type, f.witness.slice(0), f?.value?f.value.slice(0):undefined, true);
|
|
138
|
-
}
|
|
139
|
-
})
|
|
140
|
-
return {objectid:value, callback:GuardParser.rpc_sense_objects_fn, parser:GuardParser.parse_sense_bsc, data:[], variables:futures?v:undefined} as Query_Param
|
|
141
|
-
});
|
|
52
|
+
static CreateAsync = async (protocol: Protocol, guards: string[]) => {
|
|
53
|
+
if (!IsValidArray(guards, IsValidAddress)) {
|
|
54
|
+
ERROR(Errors.IsValidArray, 'guards');
|
|
55
|
+
}
|
|
142
56
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
sense_objects.forEach((value) => { // DONT CHANGE objects sequence
|
|
146
|
-
sense_objects_result = sense_objects_result.concat(value.data);
|
|
147
|
-
});
|
|
148
|
-
sense_objects_result = array_unique(sense_objects_result); // objects in guards
|
|
57
|
+
let guard_list = array_unique(guards);
|
|
58
|
+
const me = new GuardParser(protocol, guards);
|
|
149
59
|
|
|
150
|
-
let
|
|
151
|
-
|
|
60
|
+
let res = await protocol.Query_Raw(guard_list);
|
|
61
|
+
res.forEach((r) => {
|
|
62
|
+
let c = r.data?.content as any;
|
|
63
|
+
if (!c) return;
|
|
64
|
+
|
|
65
|
+
let index = protocol.WOWOK_OBJECTS_TYPE().findIndex(v => {return v.includes('guard::Guard') && v == c.type});
|
|
66
|
+
if (index == -1) return;
|
|
67
|
+
|
|
68
|
+
let info:GuardInfo = {id: c.fields.id.id, query_list:[], variable:[], input_witness:[]};
|
|
69
|
+
me.parse_variable(info, c.fields.variables);
|
|
70
|
+
if (c.fields.input.type == (protocol.Package() + '::bcs::BCS')) {
|
|
71
|
+
me.parse_bcs(info, Uint8Array.from(c.fields.input.fields.bytes));
|
|
72
|
+
}
|
|
73
|
+
me.guard_list.push(info);
|
|
152
74
|
})
|
|
75
|
+
return me
|
|
76
|
+
}
|
|
153
77
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
if (!data) {
|
|
162
|
-
console.error('error find data')
|
|
163
|
-
console.log(queries)
|
|
164
|
-
console.log(object)
|
|
165
|
-
return
|
|
78
|
+
parse_variable = (info:GuardInfo, variables:any) => {
|
|
79
|
+
variables.forEach((v:any) => {
|
|
80
|
+
if (v.type == (this.protocol.Package() + '::guard::Variable')) {
|
|
81
|
+
// ValueType.TYPE_ADDRESS: Query_Cmd maybe used the address, so save it for using
|
|
82
|
+
if (v.fields.type == ContextType.TYPE_WITNESS_ID || v.fields.type == ValueType.TYPE_ADDRESS) {
|
|
83
|
+
info.variable.push({identifier:v.fields.identifier, index:this.get_index(), type:v.fields.type,
|
|
84
|
+
value_or_witness:'0x' + Bcs.getInstance().de(BCS.ADDRESS, Uint8Array.from(v.fields.value))});
|
|
166
85
|
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
})
|
|
170
|
-
return res;
|
|
86
|
+
}
|
|
87
|
+
});
|
|
171
88
|
}
|
|
172
89
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
var arr = [].slice.call(chain_sense_bsc.reverse());
|
|
176
|
-
|
|
90
|
+
parse_bcs = (info:GuardInfo, chain_bytes: Uint8Array) => {
|
|
91
|
+
var arr = [].slice.call(chain_bytes.reverse());
|
|
177
92
|
while (arr.length > 0) {
|
|
178
93
|
var type : unknown = arr.shift() ;
|
|
179
94
|
// console.log(type);
|
|
180
95
|
switch (type as Data_Type) {
|
|
181
|
-
case ContextType.
|
|
182
|
-
case ContextType.
|
|
183
|
-
case OperatorType.
|
|
184
|
-
case OperatorType.
|
|
185
|
-
case OperatorType.
|
|
186
|
-
case OperatorType.
|
|
187
|
-
case OperatorType.
|
|
188
|
-
case OperatorType.
|
|
189
|
-
case OperatorType.
|
|
96
|
+
case ContextType.TYPE_SIGNER:
|
|
97
|
+
case ContextType.TYPE_CLOCK:
|
|
98
|
+
case OperatorType.TYPE_LOGIC_AS_U256_GREATER:
|
|
99
|
+
case OperatorType.TYPE_LOGIC_AS_U256_GREATER_EQUAL:
|
|
100
|
+
case OperatorType.TYPE_LOGIC_AS_U256_LESSER:
|
|
101
|
+
case OperatorType.TYPE_LOGIC_AS_U256_LESSER_EQUAL:
|
|
102
|
+
case OperatorType.TYPE_LOGIC_AS_U256_EQUAL:
|
|
103
|
+
case OperatorType.TYPE_LOGIC_EQUAL:
|
|
104
|
+
case OperatorType.TYPE_LOGIC_HAS_SUBSTRING:
|
|
190
105
|
case OperatorType.TYPE_LOGIC_ALWAYS_TRUE:
|
|
106
|
+
case OperatorType.TYPE_LOGIC_NOT:
|
|
107
|
+
case OperatorType.TYPE_LOGIC_AND:
|
|
108
|
+
case OperatorType.TYPE_LOGIC_OR:
|
|
191
109
|
break;
|
|
192
|
-
case ContextType.
|
|
193
|
-
|
|
194
|
-
|
|
110
|
+
case ContextType.TYPE_VARIABLE:
|
|
111
|
+
arr.splice(0, 1); // identifier of variable
|
|
112
|
+
break;
|
|
113
|
+
case ContextType.TYPE_WITNESS_ID: // add to variable
|
|
114
|
+
let addr = '0x' + Bcs.getInstance().de(BCS.ADDRESS, Uint8Array.from(arr)).toString();
|
|
115
|
+
arr.splice(0, 32); // address
|
|
116
|
+
info.input_witness.push({index:this.get_index(), type:ContextType.TYPE_WITNESS_ID, value_or_witness:addr})
|
|
195
117
|
break;
|
|
196
|
-
case
|
|
197
|
-
case
|
|
198
|
-
case ContextType.TYPE_CONTEXT_u8:
|
|
199
|
-
case ContextType.TYPE_CONTEXT_u64:
|
|
200
|
-
case ContextType.TYPE_CONTEXT_vec_u8:
|
|
118
|
+
case ValueType.TYPE_BOOL:
|
|
119
|
+
case ValueType.TYPE_U8:
|
|
201
120
|
arr.splice(0, 1); // identifier
|
|
202
121
|
break;
|
|
203
|
-
case ValueType.
|
|
204
|
-
//console.log('0x' + bcs.de(BCS.ADDRESS, Uint8Array.from(array)).toString());
|
|
122
|
+
case ValueType.TYPE_ADDRESS:
|
|
205
123
|
arr.splice(0, 32);
|
|
206
124
|
break;
|
|
207
|
-
case ValueType.
|
|
208
|
-
case ValueType.TYPE_STATIC_u8:
|
|
209
|
-
arr.splice(0, 1);
|
|
210
|
-
break;
|
|
211
|
-
case ValueType.TYPE_STATIC_u64:
|
|
125
|
+
case ValueType.TYPE_U64:
|
|
212
126
|
arr.splice(0, 8);
|
|
213
127
|
break;
|
|
214
|
-
case ValueType.
|
|
128
|
+
case ValueType.TYPE_U128:
|
|
215
129
|
arr.splice(0, 16);
|
|
216
130
|
break;
|
|
217
|
-
case ValueType.
|
|
131
|
+
case ValueType.TYPE_U256:
|
|
132
|
+
arr.splice(0, 32);
|
|
133
|
+
break;
|
|
134
|
+
case ValueType.TYPE_VEC_U8:
|
|
218
135
|
let {value, length} = ulebDecode(Uint8Array.from(arr));
|
|
219
136
|
arr.splice(0, value+length);
|
|
220
137
|
break;
|
|
221
138
|
case OperatorType.TYPE_QUERY:
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
if (v) {
|
|
231
|
-
result.push('0x' + Bcs.getInstance().de(BCS.ADDRESS, Uint8Array.from(v as Uint8Array)).toString());
|
|
232
|
-
arr.splice(0, 1); // splice cmd
|
|
233
|
-
break;
|
|
139
|
+
let type = arr.splice(0, 1);
|
|
140
|
+
if (type[0] == ValueType.TYPE_ADDRESS || type[0] == ContextType.TYPE_WITNESS_ID) {
|
|
141
|
+
let addr = '0x' + Bcs.getInstance().de(BCS.ADDRESS, Uint8Array.from(arr)).toString();
|
|
142
|
+
arr.splice(0, 33); // address + cmd
|
|
143
|
+
if (type[0] == ValueType.TYPE_ADDRESS) {
|
|
144
|
+
info.query_list.push(addr);
|
|
145
|
+
} else if (type[0] == ContextType.TYPE_WITNESS_ID){
|
|
146
|
+
info.query_list.push({index:this.get_index(), type:type[0], value_or_witness:addr});
|
|
234
147
|
}
|
|
235
|
-
}
|
|
148
|
+
} else if (type[0] == ContextType.TYPE_VARIABLE) {
|
|
149
|
+
let identifer = arr.splice(0, 2); // key + cmd
|
|
150
|
+
let variable = info.variable.find((v) =>
|
|
151
|
+
(v.identifier == identifer[0]) &&
|
|
152
|
+
((v.type == ValueType.TYPE_ADDRESS) || (v.type == ContextType.TYPE_WITNESS_ID)));
|
|
153
|
+
if (!variable) { ERROR(Errors.Fail, 'indentifier not in variable')}
|
|
154
|
+
if (variable?.type == ValueType.TYPE_ADDRESS) {
|
|
155
|
+
info.query_list.push(variable.value_or_witness);
|
|
156
|
+
} else if (variable?.type == ContextType.TYPE_WITNESS_ID) {
|
|
157
|
+
info.query_list.push({identifier:identifer[0], type:variable.type, value_or_witness:variable.value_or_witness, index:this.get_index()});
|
|
158
|
+
}
|
|
159
|
+
} else {
|
|
160
|
+
ERROR(Errors.Fail, 'variable type invalid');
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
break;
|
|
236
164
|
default:
|
|
237
|
-
|
|
238
|
-
console.log(type as number)
|
|
239
|
-
console.log(arr)
|
|
240
|
-
return false; // error
|
|
165
|
+
ERROR(Errors.Fail, 'parse_bcs types')
|
|
241
166
|
}
|
|
242
167
|
}
|
|
243
|
-
return true;
|
|
244
168
|
}
|
|
245
169
|
|
|
170
|
+
private get_object(guardid:string, info:QueryInfo, fill?:FutrueFill[]) : string {
|
|
171
|
+
let r = fill?.find(i => guardid == i.guard && i.index == info.index);
|
|
172
|
+
if (!r || !r.future) {
|
|
173
|
+
if (!info.future) {
|
|
174
|
+
ERROR(Errors.InvalidParam, 'index invalid for fill')
|
|
175
|
+
}
|
|
176
|
+
} else {
|
|
177
|
+
info.future = r!.future;
|
|
178
|
+
}
|
|
179
|
+
return info.future!
|
|
180
|
+
}
|
|
246
181
|
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
} else {
|
|
262
|
-
bret = Guard.add_variable(v, variable.fields.identifier, variable.fields.type,
|
|
263
|
-
variable.fields?.value?Uint8Array.from(variable.fields.value):undefined, false);
|
|
264
|
-
}
|
|
265
|
-
if (!bret) {
|
|
266
|
-
console.log('rpc_sense_objects_fn add_variable error');
|
|
267
|
-
console.log(variable);
|
|
268
|
-
return ;
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
param.variables = v;
|
|
182
|
+
done = async (fill?:FutrueFill[]) : Promise<PassportQuery>=> {
|
|
183
|
+
let objects: string[] = [];
|
|
184
|
+
this.guard_list.forEach((g) => {
|
|
185
|
+
g.variable.filter(v => v.type == ContextType.TYPE_WITNESS_ID).forEach((q) => {
|
|
186
|
+
objects.push(this.get_object(g.id, q, fill));
|
|
187
|
+
})
|
|
188
|
+
let list = g.query_list.map((q) => {
|
|
189
|
+
if (typeof(q) === "string") {
|
|
190
|
+
objects.push(q)
|
|
191
|
+
return q
|
|
192
|
+
} else {
|
|
193
|
+
let r = this.get_object(g.id, q, fill);
|
|
194
|
+
objects.push(r);
|
|
195
|
+
return r
|
|
273
196
|
}
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
197
|
+
})
|
|
198
|
+
g.query_list = list;
|
|
199
|
+
g.input_witness.forEach((q) => {
|
|
200
|
+
objects.push(this.get_object(g.id, q, fill));
|
|
201
|
+
})
|
|
202
|
+
})
|
|
203
|
+
|
|
204
|
+
// objects info
|
|
205
|
+
let res = await this.protocol.Query_Raw(array_unique(objects), {showType:true});
|
|
206
|
+
let query: Guard_Query_Object[] = [];
|
|
207
|
+
let witness: Guard_Query_Object[] = [];
|
|
208
|
+
this.guard_list.forEach(g => {
|
|
209
|
+
g.query_list.forEach(q => {
|
|
210
|
+
let r = res.find(r => r.data?.objectId == q as string);
|
|
211
|
+
if (!r) { ERROR(Errors.Fail, 'query object not match')}
|
|
212
|
+
let object = this.object_query(r!.data);
|
|
213
|
+
if (!object) { ERROR(Errors.Fail, 'query object fail')}
|
|
214
|
+
query.push(object!);
|
|
215
|
+
})
|
|
216
|
+
res.forEach(q => {
|
|
217
|
+
let r1 = g.variable.find(v => v.future == q.data?.objectId);
|
|
218
|
+
let r2 = g.input_witness.find(v => v.future == q.data?.objectId)
|
|
219
|
+
// not match r1 || r2 means query-cmd, not witness-cmd
|
|
220
|
+
if (r1 || r2) {
|
|
221
|
+
let object = this.object_query(q.data, 'witness');
|
|
222
|
+
if (!object) { ERROR(Errors.Fail, 'witness object fail') }
|
|
223
|
+
witness.push(object!);
|
|
283
224
|
}
|
|
284
|
-
}
|
|
285
|
-
}
|
|
225
|
+
})
|
|
226
|
+
})
|
|
227
|
+
|
|
228
|
+
return {guard:this.guards, query:query, witness:witness} as PassportQuery;
|
|
286
229
|
}
|
|
287
230
|
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
id: param.objectid,
|
|
301
|
-
} as Guard_Query_Object;
|
|
302
|
-
}
|
|
231
|
+
private object_query = (data: any, method:string='guard_query') : Guard_Query_Object | undefined=> {
|
|
232
|
+
for (let k = 0; k < this.protocol.WOWOK_OBJECTS_TYPE().length; k++) {
|
|
233
|
+
if (data.type.includes(this.protocol.WOWOK_OBJECTS_TYPE()[k]) ) { // type: pack::m::Object<...>
|
|
234
|
+
return { target:this.protocol.WOWOK_OBJECTS_PREFIX_TYPE()[k] + method as FnCallType,
|
|
235
|
+
object:Inputs.SharedObjectRef({
|
|
236
|
+
objectId: data.objectId,
|
|
237
|
+
mutable: false,
|
|
238
|
+
initialSharedVersion: data.version,
|
|
239
|
+
}) as TransactionObjectInput,
|
|
240
|
+
types:parse_object_type(data.type as string),
|
|
241
|
+
id: data.objectId,
|
|
242
|
+
} as Guard_Query_Object;
|
|
303
243
|
}
|
|
304
244
|
}
|
|
305
245
|
}
|
|
@@ -312,11 +252,11 @@ export class Passport {
|
|
|
312
252
|
|
|
313
253
|
get_object () { return this.passport }
|
|
314
254
|
// return passport object used
|
|
315
|
-
constructor (protocol:Protocol,
|
|
316
|
-
if (!
|
|
255
|
+
constructor (protocol:Protocol, query:PassportQuery) {
|
|
256
|
+
if (!query.guard || query.guard.length > Passport.MAX_GUARD_COUNT) {
|
|
317
257
|
ERROR(Errors.InvalidParam, 'guards' )
|
|
318
258
|
}
|
|
319
|
-
if (!Protocol.IsValidObjects(
|
|
259
|
+
if (!Protocol.IsValidObjects(query.guard)) {
|
|
320
260
|
ERROR(Errors.IsValidObjects, 'guards')
|
|
321
261
|
}
|
|
322
262
|
|
|
@@ -328,48 +268,35 @@ export class Passport {
|
|
|
328
268
|
});
|
|
329
269
|
|
|
330
270
|
// add others guards, if any
|
|
331
|
-
|
|
271
|
+
query.guard.forEach((g) => {
|
|
332
272
|
txb.moveCall({
|
|
333
273
|
target:protocol.PassportFn('guard_add') as FnCallType,
|
|
334
|
-
arguments:[this.passport, Protocol.TXB_OBJECT(txb,
|
|
274
|
+
arguments:[this.passport, Protocol.TXB_OBJECT(txb, g)]
|
|
335
275
|
});
|
|
336
276
|
})
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
real_address: string[],
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
let result = new Map<string, futureResultItem>();
|
|
344
|
-
future_values?.forEach((v) => {
|
|
345
|
-
if (result.has(v.guardid)) {
|
|
346
|
-
result.get(v.guardid)?.identifier.push(v.identifier);
|
|
347
|
-
result.get(v.guardid)?.real_address.push(v.value!);
|
|
348
|
-
} else {
|
|
349
|
-
result.set(v.guardid, {identifier:[v.identifier], real_address:[v.value!]})
|
|
350
|
-
}
|
|
351
|
-
})
|
|
352
|
-
|
|
353
|
-
result.forEach((v, k) => {
|
|
277
|
+
|
|
278
|
+
// witness
|
|
279
|
+
query?.witness.forEach((w) => {
|
|
354
280
|
txb.moveCall({
|
|
355
|
-
target:
|
|
356
|
-
arguments:[this.passport, txb.
|
|
357
|
-
|
|
281
|
+
target: w.target as FnCallType,
|
|
282
|
+
arguments: [this.passport, txb.object(w.object)],
|
|
283
|
+
typeArguments: w.types,
|
|
358
284
|
})
|
|
359
285
|
})
|
|
360
286
|
|
|
361
287
|
// rules: 'verify' & 'query' in turns;'verify' at final end.
|
|
362
|
-
|
|
363
|
-
let
|
|
288
|
+
query?.query.forEach((q) => {
|
|
289
|
+
let address = txb.moveCall({
|
|
364
290
|
target: protocol.PassportFn('passport_verify') as FnCallType,
|
|
365
|
-
arguments: [ this.passport, txb.object(Protocol.CLOCK_OBJECT)
|
|
291
|
+
arguments: [ this.passport, txb.object(Protocol.CLOCK_OBJECT)]
|
|
366
292
|
});
|
|
367
293
|
txb.moveCall({
|
|
368
|
-
target:
|
|
369
|
-
arguments: [ txb.object(
|
|
370
|
-
typeArguments:
|
|
294
|
+
target: q.target as FnCallType,
|
|
295
|
+
arguments: [ txb.object(q.object), this.passport, address ],
|
|
296
|
+
typeArguments: q.types,
|
|
371
297
|
})
|
|
372
|
-
}
|
|
298
|
+
})
|
|
299
|
+
|
|
373
300
|
txb.moveCall({
|
|
374
301
|
target: protocol.PassportFn('passport_verify') as FnCallType,
|
|
375
302
|
arguments: [ this.passport, txb.object(Protocol.CLOCK_OBJECT) ]
|
package/src/permission.ts
CHANGED
|
@@ -11,6 +11,9 @@ export enum PermissionIndex {
|
|
|
11
11
|
repository_remove_policies = 104,
|
|
12
12
|
repository_set_policy_description = 105,
|
|
13
13
|
repository_set_policy_permission = 106,
|
|
14
|
+
repository_reference_add = 107,
|
|
15
|
+
repository_reference_remove = 108,
|
|
16
|
+
repository_reference_removeall = 108,
|
|
14
17
|
vote = 150,
|
|
15
18
|
vote_set_description = 151,
|
|
16
19
|
vote_set_reference = 152,
|