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/src/index.ts CHANGED
@@ -10,3 +10,4 @@ export * from './protocol'
10
10
  export * from './passport'
11
11
  export * from './machine'
12
12
  export * from './service'
13
+ export * from './graphql'
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 type Machine_Forward = {
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 type Machine_Node_Pair = {
19
+ export interface Machine_Node_Pair {
20
20
  prior_node: string;
21
21
  forwards: Machine_Forward[];
22
22
  threshold?: number;
23
23
  }
24
- export type Machine_Node = {
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 { SuiObjectResponse, SuiObjectDataOptions } from '@mysten/sui.js/client';
2
- import { TransactionBlock, type TransactionObjectInput, Inputs } from '@mysten/sui.js/transactions';
3
- import { FnCallType, Query_Param, PassportObject, GuardObject, Protocol, ContextType, OperatorType, Data_Type,
4
- ValueType, MODULES,
5
- } from './protocol';
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
- export type GUARD_QUERIES_TYPE = {
19
- module:MODULES,
20
- name:string,
21
- cmd:number,
22
- params:Data_Type[],
23
- result:Data_Type
24
- };
25
-
26
- // de sense bsc => FutureValueRequest
27
- export type FutureValueRequest = {
28
- guardid: string;
29
- identifier: number;
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
- // from guards: get objects to fill FUTURE value by singer
37
- static guard_futures = async (protocol:Protocol, guards:string[]) : Promise<FutureValueRequest[]> => {
38
- let futrue_objects = guards.map((value) => {
39
- return {objectid:value, callback:GuardParser.rpc_sense_objects_fn, parser:GuardParser.parse_futures, data:[]} as Query_Param
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
- return future_objects_result
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
- // parse guard futures into result, WITH future variable READY.
55
- static parse_futures(result:FutureValueRequest[], guardid: string, chain_sense_bsc:Uint8Array, variable?:VariableType) : boolean {
56
- var arr = [].slice.call(chain_sense_bsc.reverse());
57
- while (arr.length > 0) {
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
- await protocol.Query(sense_objects); // objects need quering in guards
144
- let sense_objects_result:string[] = [];
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 queries = sense_objects_result.map((value) => {
151
- return {objectid:value, callback:GuardParser.rpc_query_cmd_fn, data:[]} as Query_Param;
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
- await protocol.Query(queries, {'showType':true}); // queries for passport verifing
155
- let res : Guard_Query_Object[] = [];
156
- sense_objects.forEach((guard) => { // DONT CHANGE objects sequence for passport verifying
157
- res = res.concat(guard.data.map((object:string) => {
158
- let data = queries.filter((v) => {
159
- return v.objectid == object
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
- return data[0].data
168
- }))
169
- })
170
- return res;
86
+ }
87
+ });
171
88
  }
172
89
 
173
- // parse guard senses input bytes of a guard, return [objectids] for 'query_cmd'
174
- static parse_sense_bsc(result:string[], guardid: string, chain_sense_bsc:Uint8Array, variable?:VariableType) : boolean {
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.TYPE_CONTEXT_SIGNER:
182
- case ContextType.TYPE_CONTEXT_CLOCK:
183
- case OperatorType.TYPE_LOGIC_OPERATOR_U128_GREATER:
184
- case OperatorType.TYPE_LOGIC_OPERATOR_U128_GREATER_EQUAL:
185
- case OperatorType.TYPE_LOGIC_OPERATOR_U128_LESSER:
186
- case OperatorType.TYPE_LOGIC_OPERATOR_U128_LESSER_EQUAL:
187
- case OperatorType.TYPE_LOGIC_OPERATOR_U128_EQUAL:
188
- case OperatorType.TYPE_LOGIC_OPERATOR_EQUAL:
189
- case OperatorType.TYPE_LOGIC_OPERATOR_HAS_SUBSTRING:
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.TYPE_CONTEXT_FUTURE_ID: // MACHINE-ID
193
- var v = arr.splice(0, 1);
194
- if (!variable || variable?.get(v[0])?.type != type) return false;
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 ContextType.TYPE_CONTEXT_address:
197
- case ContextType.TYPE_CONTEXT_bool:
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.TYPE_STATIC_address:
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.TYPE_STATIC_bool:
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.TYPE_STATIC_u128:
128
+ case ValueType.TYPE_U128:
215
129
  arr.splice(0, 16);
216
130
  break;
217
- case ValueType.TYPE_STATIC_vec_u8:
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
- result.push('0x' + Bcs.getInstance().de(BCS.ADDRESS, Uint8Array.from(arr)).toString());
223
- arr.splice(0, 33); // address + cmd
224
- break;
225
- case OperatorType.TYPE_QUERY_FROM_CONTEXT:
226
- case OperatorType.TYPE_FUTURE_QUERY:
227
- var identifer = arr.splice(0, 1);
228
- if (variable) {
229
- let v = Guard.get_variable_value(variable, identifer[0], type as OperatorType) ;
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
- }; return false
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
- console.error('parse_sense_bsc:undefined');
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
- // callback to parse guard's object-queries into Guard_Query_Object[]
248
- static rpc_sense_objects_fn = (protocol:Protocol, response:SuiObjectResponse, param:Query_Param, option:SuiObjectDataOptions) => {
249
- if (!response.error) {
250
- let c = response?.data?.content as any;
251
- let index = protocol.WOWOK_OBJECTS_TYPE().findIndex(v => v.includes('guard::Guard') && v == c.type);
252
- if (index >= 0 && c.fields.id.id == param.objectid) { // GUARD OBJECT
253
- if (!param?.variables) {
254
- let v = new Map<number, Guard_Vriable>();
255
- for (let i = 0; i < c.fields.variables.length; i ++) {
256
- let variable = c.fields.variables[i]; let bret ;
257
- if (variable.type == (protocol.WOWOK_OBJECTS_PREFIX_TYPE()[index] + 'Variable')) { // ...::guard::Variable
258
- if (variable.fields.type == OperatorType.TYPE_FUTURE_QUERY || variable.fields.type == ContextType.TYPE_CONTEXT_FUTURE_ID) {
259
- bret = Guard.add_future_variable(v, variable.fields.identifier, variable.fields.type,
260
- variable.fields?.value?Uint8Array.from(variable.fields.value):undefined, undefined, false);
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
- for (let i = 0; i < c.fields.senses.length; i ++) {
276
- let sense = c.fields.senses[i];
277
- if (sense.type == (protocol.WOWOK_OBJECTS_PREFIX_TYPE()[index] + 'Sense')) { // ...::guard::Sense
278
- let result : any[] = [];
279
- if (param?.parser && param.parser(result, param.objectid, Uint8Array.from(sense.fields.input.fields.bytes), param.variables)) {
280
- param.data = param.data.concat(result); // DONT array_unique senses
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
- // construct Guard_Query_Object of wowok objects for passport verify
289
- static rpc_query_cmd_fn = (protocol:Protocol, response:SuiObjectResponse, param:Query_Param, option:SuiObjectDataOptions) => {
290
- if (!response.error && response.data?.objectId == param.objectid && response.data?.type) {
291
- for (let k = 0; k < protocol.WOWOK_OBJECTS_TYPE().length; k++) {
292
- if (response?.data?.type.includes(protocol.WOWOK_OBJECTS_TYPE()[k]) ) { // type: pack::m::Object<...>
293
- param.data = { target:protocol.WOWOK_OBJECTS_PREFIX_TYPE()[k] + 'guard_query' as FnCallType,
294
- object:Inputs.SharedObjectRef({
295
- objectId: response.data.objectId,
296
- mutable: false,
297
- initialSharedVersion: response.data!.version,
298
- }) as TransactionObjectInput,
299
- types:parse_object_type(response?.data?.type as string),
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, guards:GuardObject[], guard_queries:Guard_Query_Object[], future_values?:FutureValueRequest[]) {
316
- if (!guards || guards.length > Passport.MAX_GUARD_COUNT) {
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(guards)) {
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
- guards.forEach((guard) => {
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, guard)]
274
+ arguments:[this.passport, Protocol.TXB_OBJECT(txb, g)]
335
275
  });
336
276
  })
337
-
338
- type futureResultItem = {
339
- identifier:number[],
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:protocol.PassportFn('futures_set') as FnCallType,
356
- arguments:[this.passport, txb.pure(Bcs.getInstance().ser_address(k)), txb.pure(Bcs.getInstance().ser_vector_u8(v.identifier)),
357
- txb.pure(v.real_address, 'vector<address>')]
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
- for (let i = 0; i < guard_queries.length; i++) {
363
- let res = txb.moveCall({
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: guard_queries[i].target as FnCallType,
369
- arguments: [ txb.object(guard_queries[i].object), this.passport, res ],
370
- typeArguments: guard_queries[i].types,
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,