wowok 1.3.13 → 1.4.18

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wowok",
3
- "version": "1.3.13",
3
+ "version": "1.4.18",
4
4
  "description": "Create, collaborate, and transact on your own terms with the AI-driven web3 collaboration protocol.",
5
5
  "main": "./src/index.ts",
6
6
  "types": "./src/index.ts",
package/src/exception.ts CHANGED
@@ -22,9 +22,10 @@ export enum Errors {
22
22
  isValidHttpUrl = 'invalid url',
23
23
  IsValidUserDefinedIndex = 'invalid user defined permission index',
24
24
  bcsTypeInvalid = 'invalid bcs type',
25
+ IsValidServiceItemName = 'invalid service item name',
25
26
  }
26
27
 
27
28
  export const ERROR = (error:Errors, info?:any) => {
28
- const e = error + info ? (': ' + info) : '';
29
+ const e = error + info ? (' ' + info) : '';
29
30
  throw e;
30
31
  }
package/src/guard.ts CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  import { Protocol, LogicsInfo, GuardAddress, FnCallType, Data_Type, MODULES, ContextType, ValueType, OperatorType, ConstantType, SER_VALUE} from './protocol';
4
4
  import { concatenate, array_equal } from './utils';
5
- import { IsValidDesription, Bcs, IsValidInt, IsValidAddress, FirstLetterUppercase } from './utils';
5
+ import { IsValidDesription, Bcs, IsValidInt, IsValidAddress, FirstLetterUppercase, insertAtHead } from './utils';
6
6
  import { ERROR, Errors } from './exception';
7
7
  import { Transaction as TransactionBlock } from '@mysten/sui/transactions';
8
8
 
@@ -59,19 +59,19 @@ export class Guard {
59
59
  if (!v.witness) {
60
60
  ERROR(Errors.InvalidParam, 'constants type')
61
61
  }
62
-
62
+ const n = insertAtHead(v.witness!, v.type);
63
63
  txb.moveCall({
64
64
  target:Protocol.Instance().GuardFn("constant_add") as FnCallType,
65
- arguments:[guard, txb.pure.u8(k), txb.pure.u8(v.type), txb.pure.vector('u8', [].slice.call(v.witness)), txb.pure.bool(true)]
65
+ arguments:[guard, txb.pure.u8(k), txb.pure.vector('u8', [].slice.call(n)), txb.pure.bool(true)]
66
66
  })
67
67
  } else {
68
68
  if (!v.value) {
69
69
  ERROR(Errors.InvalidParam, 'constants type')
70
70
  }
71
-
71
+ const n = insertAtHead(v.value!, v.type);
72
72
  txb.moveCall({
73
73
  target:Protocol.Instance().GuardFn("constant_add") as FnCallType,
74
- arguments:[guard, txb.pure.u8(k), txb.pure.u8(v.type), txb.pure.vector('u8', [].slice.call(v.value)), txb.pure.bool(true)]
74
+ arguments:[guard, txb.pure.u8(k), txb.pure.vector('u8', [].slice.call(n)), txb.pure.bool(true)]
75
75
  })
76
76
  }
77
77
  });
@@ -115,20 +115,29 @@ export class Guard {
115
115
  [MODULES.repository, 'Value Type of Policy', 15, [ValueType.TYPE_STRING], ValueType.TYPE_U8, 'Data types defined by consensus policy.', 'Input:the policy name'],
116
116
  [MODULES.repository, 'Contains Data for An Address', 16, [ValueType.TYPE_ADDRESS], ValueType.TYPE_BOOL, 'Whether data exists at a certain address?', 'Input:address'],
117
117
  [MODULES.repository, 'Contains Data', 17, [ValueType.TYPE_ADDRESS, ValueType.TYPE_STRING], ValueType.TYPE_BOOL, 'Does it contain data for a certain field of an address?', 'Input 1:address, Input 2:the field name'],
118
- [MODULES.repository, 'Data without Type', 18, [ValueType.TYPE_ADDRESS, ValueType.TYPE_STRING], ValueType.TYPE_VEC_U8, 'Data for a field at an address and does not contain data type information.', 'Input 1:address, Input 2:the field name'],
119
- [MODULES.repository, 'Value', 19, [ValueType.TYPE_ADDRESS, ValueType.TYPE_STRING], ValueType.TYPE_VEC_U8, 'Data for a field at an address, and the first byte contains data type information.', 'Input 1:address, Input 2:the field name'],
118
+ [MODULES.repository, 'Raw data without Type', 18, [ValueType.TYPE_ADDRESS, ValueType.TYPE_STRING], ValueType.TYPE_VEC_U8, 'Data for a field at an address and does not contain data type information.', 'Input 1:address, Input 2:the field name'],
119
+ [MODULES.repository, 'Raw data', 19, [ValueType.TYPE_ADDRESS, ValueType.TYPE_STRING], ValueType.TYPE_VEC_U8, 'Data for a field at an address, and the first byte contains data type information.', 'Input 1:address, Input 2:the field name'],
120
120
  [MODULES.repository, 'Type', 20, [], ValueType.TYPE_U8, 'The repository Type. 0: Normal; 1: Wowok greenee.'],
121
121
  [MODULES.repository, 'Policy Mode', 21, [], ValueType.TYPE_U8, 'Policy Mode. 0: Free mode; 1: Strict mode.'],
122
122
  [MODULES.repository, 'Reference Count', 22, [], ValueType.TYPE_U64, 'The number of times it is referenced by other objects.'],
123
123
  [MODULES.repository, 'Is Referenced by An Object', 23, [ValueType.TYPE_ADDRESS], ValueType.TYPE_BOOL, 'Is it referenced by an object?', 'Input:address'],
124
+ [MODULES.repository, 'Data Number', 24, [ValueType.TYPE_ADDRESS, ValueType.TYPE_STRING], ValueType.TYPE_U256, 'Data for a field at an address and get unsigned integer type data.', 'Input 1:address, Input 2:the field name'],
125
+ [MODULES.repository, 'Data String', 25, [ValueType.TYPE_ADDRESS, ValueType.TYPE_STRING], ValueType.TYPE_STRING, 'Data for a field at an address and get string type data.', 'Input 1:address, Input 2:the field name'],
126
+ [MODULES.repository, 'Data Address', 26, [ValueType.TYPE_ADDRESS, ValueType.TYPE_STRING], ValueType.TYPE_ADDRESS, 'Data for a field at an address and get address type data.', 'Input 1:address, Input 2:the field name'],
127
+ [MODULES.repository, 'Data Bool', 27, [ValueType.TYPE_ADDRESS, ValueType.TYPE_STRING], ValueType.TYPE_BOOL, 'Data for a field at an address and get bool type data.', 'Input 1:address, Input 2:the field name'],
128
+ [MODULES.repository, 'Data Number Vector', 28, [ValueType.TYPE_ADDRESS, ValueType.TYPE_STRING], ValueType.TYPE_VEC_U256, 'Data for a field at an address and get unsigned integer vector type data.', 'Input 1:address, Input 2:the field name'],
129
+ [MODULES.repository, 'Data String Vector', 29, [ValueType.TYPE_ADDRESS, ValueType.TYPE_STRING], ValueType.TYPE_VEC_STRING, 'Data for a field at an address and get string vector type data.', 'Input 1:address, Input 2:the field name'],
130
+ [MODULES.repository, 'Data Address Vector', 30, [ValueType.TYPE_ADDRESS, ValueType.TYPE_STRING], ValueType.TYPE_VEC_ADDRESS, 'Data for a field at an address and get address vector type data.', 'Input 1:address, Input 2:the field name'],
131
+ [MODULES.repository, 'Data Bool Vector', 31, [ValueType.TYPE_ADDRESS, ValueType.TYPE_STRING], ValueType.TYPE_VEC_BOOL, 'Data for a field at an address and get bool vector type data.', 'Input 1:address, Input 2:the field name'],
132
+
124
133
  // , means that data fields and data outside the consensus policy definition are allowed to be written
125
134
  // , means that only data fields and data defined by the consensus policy are allowed to be written.
126
- [MODULES.machine, 'Permission', 31, [], ValueType.TYPE_ADDRESS, 'Permission object address.'],
127
- [MODULES.machine, 'Paused', 32, [], ValueType.TYPE_BOOL, 'Pause the creation of new Progress?'],
128
- [MODULES.machine, 'Published', 33, [], ValueType.TYPE_BOOL, 'Is it allowed to create Progress?'],
129
- [MODULES.machine, 'Is Consensus Repository', 34, [ValueType.TYPE_ADDRESS], ValueType.TYPE_BOOL, 'Whether an address is a consensus repository?', 'Input:adddress'],
130
- [MODULES.machine, 'Has Endpoint', 35, [], ValueType.TYPE_BOOL, 'Is the endpoint set?'],
131
- [MODULES.machine, 'Endpoint', 36, [], ValueType.TYPE_STRING, 'Endpoint url/ipfs.'],
135
+ [MODULES.machine, 'Permission', 41, [], ValueType.TYPE_ADDRESS, 'Permission object address.'],
136
+ [MODULES.machine, 'Paused', 42, [], ValueType.TYPE_BOOL, 'Pause the creation of new Progress?'],
137
+ [MODULES.machine, 'Published', 43, [], ValueType.TYPE_BOOL, 'Is it allowed to create Progress?'],
138
+ [MODULES.machine, 'Is Consensus Repository', 44, [ValueType.TYPE_ADDRESS], ValueType.TYPE_BOOL, 'Whether an address is a consensus repository?', 'Input:adddress'],
139
+ [MODULES.machine, 'Has Endpoint', 45, [], ValueType.TYPE_BOOL, 'Is the endpoint set?'],
140
+ [MODULES.machine, 'Endpoint', 46, [], ValueType.TYPE_STRING, 'Endpoint url/ipfs.'],
132
141
 
133
142
  [MODULES.progress, 'Machine', 51, [], ValueType.TYPE_ADDRESS, 'The Machine object that created this Progress.'],
134
143
  [MODULES.progress, 'Current Node', 52, [], ValueType.TYPE_STRING, 'The name of the currently running node.'],
@@ -141,20 +150,24 @@ export class Guard {
141
150
  [MODULES.progress, 'Has Context Repository', 59, [], ValueType.TYPE_BOOL, 'Whether the repository reference for Progress is set?'],
142
151
  [MODULES.progress, 'Context Repository', 60, [], ValueType.TYPE_ADDRESS, 'Repository reference for Progress.'],
143
152
  [MODULES.progress, 'Last Session Time', 61, [], ValueType.TYPE_U64, 'Time when the previous session was completed.'],
144
- [MODULES.progress, 'Session Time', 62, [ValueType.TYPE_STRING], ValueType.TYPE_U64, 'Time a node completes its session.', 'Input:the node name'],
145
-
146
- [MODULES.demand, 'Permission', 71, [], ValueType.TYPE_ADDRESS, 'Permission object address.'],
147
- [MODULES.demand, 'Has Deadline', 72, [], ValueType.TYPE_BOOL, 'Whether to set the expiration time of presenting?'],
148
- [MODULES.demand, 'Deadline', 73, [], ValueType.TYPE_U64, 'The expiration time of presenting.'],
149
- [MODULES.demand, 'Bounty Count', 74, [], ValueType.TYPE_U64, 'Number of Bounties.'],
150
- [MODULES.demand, 'Has Guard', 75, [], ValueType.TYPE_BOOL, 'Whether the present guard is set?'],
151
- [MODULES.demand, 'Guard', 76, [], ValueType.TYPE_ADDRESS, 'The present guard address.'],
152
- [MODULES.demand, 'Has Service Picked', 77, [], ValueType.TYPE_BOOL, 'Whether a service has been picked and bounties given?'],
153
- [MODULES.demand, 'Service Picked', 78, [], ValueType.TYPE_ADDRESS, 'Service address that has been picked.'],
154
- [MODULES.demand, 'Presenter Count', 79, [], ValueType.TYPE_U64, 'Number of presenters.'],
155
- [MODULES.demand, 'Has Presenter', 80, [ValueType.TYPE_ADDRESS], ValueType.TYPE_BOOL, 'Is a certain address a presenter?', 'Input:address'],
156
- [MODULES.demand, 'Who Got Bounty', 81, [ValueType.TYPE_ADDRESS], ValueType.TYPE_ADDRESS, 'The address that bounties given.', 'Input:address'],
157
-
153
+ [MODULES.progress, 'Last Session Node', 62, [], ValueType.TYPE_STRING, 'The name of the last completed node.'],
154
+ [MODULES.progress, 'Current Session-id', 63, [], ValueType.TYPE_U64, 'The session id of ongoing node.'],
155
+ [MODULES.progress, 'Parent Session-id', 64, [], ValueType.TYPE_U64, 'The child process was started in the Session-id phase of the parent process.'],
156
+ [MODULES.progress, 'Parent Next Node', 65, [], ValueType.TYPE_STRING, 'The child process is started at the next node stage of the parent process.'],
157
+ [MODULES.progress, 'Parent Forward', 66, [], ValueType.TYPE_STRING, 'The child process is started in the Forward phase of the next node of the parent process.'],
158
+ [MODULES.progress, 'Parent Node', 67, [], ValueType.TYPE_STRING, 'The node name of the parent process where the child process is located.'],
159
+ [MODULES.progress, 'Forward Accomplished', 68, [ValueType.TYPE_U64, ValueType.TYPE_STRING, ValueType.TYPE_STRING], ValueType.TYPE_BOOL, 'Has a forward been accomplished?', 'Input 1:session-id; Input 2:next node name; Input 3:forward name'],
160
+ [MODULES.progress, 'Forward Operator', 69, [ValueType.TYPE_U64, ValueType.TYPE_STRING, ValueType.TYPE_STRING], ValueType.TYPE_ADDRESS, 'The forward operator.', 'Input 1:session-id; Input 2:next node name; Input 3:forward name'],
161
+ [MODULES.progress, 'Forward Sub-progress', 70, [ValueType.TYPE_U64, ValueType.TYPE_STRING, ValueType.TYPE_STRING], ValueType.TYPE_ADDRESS, 'The forward child process address(if set).', 'Input 1:session-id; Input 2:next node name; Input 3:forward name'],
162
+ [MODULES.progress, 'Forward Deliverables', 71, [ValueType.TYPE_U64, ValueType.TYPE_STRING, ValueType.TYPE_STRING], ValueType.TYPE_ADDRESS, 'The forward deliverable(if set).', 'Input 1:session-id; Input 2:next node name; Input 3:forward name'],
163
+ [MODULES.progress, 'Forward time', 72, [ValueType.TYPE_U64, ValueType.TYPE_STRING, ValueType.TYPE_STRING], ValueType.TYPE_U64, 'The time when the forward was last triggered.', 'Input 1:session-id; Input 2:next node name; Input 3:forward name'],
164
+ [MODULES.progress, 'Closest Session Time', 73, [ValueType.TYPE_STRING], ValueType.TYPE_U64, 'The time a node that closest time to the current node completes its session.', 'Input:the node name'],
165
+ [MODULES.progress, 'Closest Forward Accomplished', 74, [ValueType.TYPE_STRING, ValueType.TYPE_STRING, ValueType.TYPE_STRING], ValueType.TYPE_BOOL, 'Has a forward been accomplished?', 'Input 1:node name; Input 2:next node name; Input 3:forward name'],
166
+ [MODULES.progress, 'Closest Forward Operator', 75, [ValueType.TYPE_STRING, ValueType.TYPE_STRING, ValueType.TYPE_STRING], ValueType.TYPE_ADDRESS, 'The operator of the forward that closest time to the current node.', 'Input 1:node name; Input 2:next node name; Input 3:forward name'],
167
+ [MODULES.progress, 'Closest Forward Sub-progress', 76, [ValueType.TYPE_STRING, ValueType.TYPE_STRING, ValueType.TYPE_STRING], ValueType.TYPE_ADDRESS, 'The child process address(if set) of the forward that closest time to the current node.', 'Input 1:node name; Input 2:next node name; Input 3:forward name'],
168
+ [MODULES.progress, 'Closest Forward Deliverables', 77, [ValueType.TYPE_STRING, ValueType.TYPE_STRING, ValueType.TYPE_STRING], ValueType.TYPE_ADDRESS, 'The deliverable(if set) of the forward that closest time to the current node.', 'Input 1:node name; Input 2:next node name; Input 3:forward name'],
169
+ [MODULES.progress, 'Closest Forward time', 78, [ValueType.TYPE_STRING, ValueType.TYPE_STRING, ValueType.TYPE_STRING], ValueType.TYPE_U64, 'The time when the forward that closest time to the current node was last triggered.', 'Input 1:node name; Input 2:next node name; Input 3:forward name'],
170
+
158
171
  [MODULES.order, 'Amount', 91, [], ValueType.TYPE_U64, 'Order amount.'],
159
172
  [MODULES.order, 'Payer', 92, [], ValueType.TYPE_ADDRESS, 'Order payer.'],
160
173
  [MODULES.order, 'Service', 93, [], ValueType.TYPE_ADDRESS, 'Service for creating orders.'],
@@ -187,6 +200,18 @@ export class Guard {
187
200
  [MODULES.service, 'Required Info of Service-Pubkey', 128, [], ValueType.TYPE_STRING, 'The public key used to encrypt customer information, and only the service provider can decrypt and view customer information.'],
188
201
  [MODULES.service, 'Required Info', 129, [], ValueType.TYPE_VEC_STRING, 'Names of the required information item that needs to be provided by the customer.'],
189
202
 
203
+ [MODULES.demand, 'Permission', 135, [], ValueType.TYPE_ADDRESS, 'Permission object address.'],
204
+ [MODULES.demand, 'Has Deadline', 136, [], ValueType.TYPE_BOOL, 'Whether to set the expiration time of presenting?'],
205
+ [MODULES.demand, 'Deadline', 137, [], ValueType.TYPE_U64, 'The expiration time of presenting.'],
206
+ [MODULES.demand, 'Bounty Count', 138, [], ValueType.TYPE_U64, 'Number of Bounties.'],
207
+ [MODULES.demand, 'Has Guard', 139, [], ValueType.TYPE_BOOL, 'Whether the present guard is set?'],
208
+ [MODULES.demand, 'Guard', 140, [], ValueType.TYPE_ADDRESS, 'The present guard address.'],
209
+ [MODULES.demand, 'Has Service Picked', 141, [], ValueType.TYPE_BOOL, 'Whether a service has been picked and bounties given?'],
210
+ [MODULES.demand, 'Service Picked', 142, [], ValueType.TYPE_ADDRESS, 'Service address that has been picked.'],
211
+ [MODULES.demand, 'Presenter Count', 143, [], ValueType.TYPE_U64, 'Number of presenters.'],
212
+ [MODULES.demand, 'Has Presenter', 144, [ValueType.TYPE_ADDRESS], ValueType.TYPE_BOOL, 'Is a certain address a presenter?', 'Input:address'],
213
+ [MODULES.demand, 'Who Got Bounty', 145, [ValueType.TYPE_ADDRESS], ValueType.TYPE_ADDRESS, 'The address that bounties given.', 'Input:address'],
214
+
190
215
  [MODULES.reward, 'Permission', 151, [], ValueType.TYPE_ADDRESS, 'Permission object address.'],
191
216
  [MODULES.reward, 'Rewards Remaining', 152, [], ValueType.TYPE_U64, 'Number of rewards to be claimed.'],
192
217
  [MODULES.reward, 'Reward Count Supplied', 153, [], ValueType.TYPE_U64, 'Total rewards supplied.'],
@@ -295,7 +320,7 @@ export class Guard {
295
320
  }
296
321
 
297
322
  static StringOptions = () : Guard_Options[] => {
298
- return [...Guard.CmdFilter(ValueType.TYPE_VEC_U8), ...Guard.CmdFilter(ValueType.TYPE_STRING)].map((v) => {
323
+ return [...Guard.CmdFilter(ValueType.TYPE_STRING)].map((v) => {
299
324
  return {from:'query', name:v[1], value:v[2], group:FirstLetterUppercase(v[0])};
300
325
  });
301
326
  }
@@ -362,11 +387,12 @@ export class GuardConstantHelper {
362
387
  }
363
388
  }
364
389
 
365
- static add_constant(constants:GuardConstant, identifier:number, type:ValueType|ContextType, value:any, bNeedSerialize=true) {
390
+ static add_constant(constants:GuardConstant, identifier:number, type:ValueType, value:any, bNeedSerialize=true) {
391
+ const e = SER_VALUE.find((v:any)=>v.type===type)?.name ?? '' + ' invalid';
366
392
  if (!GuardConstantHelper.IsValidIndentifier(identifier)) {
367
393
  ERROR(Errors.InvalidParam, 'add_constant identifier')
368
394
  }
369
- if (!value) {
395
+ if (value === undefined) {
370
396
  ERROR(Errors.InvalidParam, 'add_constant value')
371
397
  }
372
398
 
@@ -390,17 +416,20 @@ export class GuardConstantHelper {
390
416
  case ValueType.TYPE_VEC_U128:
391
417
  case ValueType.TYPE_VEC_U256:
392
418
  case ValueType.TYPE_STRING:
393
- case ValueType.TYPE_VEC_U8:
419
+ case ValueType.TYPE_VEC_U8:
420
+ case ValueType.TYPE_OPTION_STRING:
421
+ case ValueType.TYPE_OPTION_VEC_U8:
422
+ case ValueType.TYPE_VEC_STRING:
394
423
  let ser = SER_VALUE.find(s=>s.type==type);
395
- if (!ser) ERROR(Errors.Fail, 'add_constant: invalid type');
424
+ if (!ser) ERROR(Errors.Fail, 'add_constant: invalid type:'+e);
396
425
  if (bNeedSerialize) {
397
- constants.set(identifier, {type:type, value:Bcs.getInstance().ser(ser!.type as number, value)})
426
+ constants.set(identifier, {type:type, value:Bcs.getInstance().ser(type, value)})
398
427
  } else {
399
428
  constants.set(identifier, {type:type, value:value})
400
429
  }
401
430
  return
402
431
  default:
403
- ERROR(Errors.Fail, 'add_constant serialize not impl yet')
432
+ ERROR(Errors.Fail, 'add_constant serialize not impl yet:'+e)
404
433
  }
405
434
  }
406
435
  }
@@ -421,7 +450,7 @@ export class GuardMaker {
421
450
 
422
451
  add_constant(type:ConstantType, value:any, identifier?:number, bNeedSerialize=true) : number {
423
452
  if (identifier === undefined) identifier = GuardMaker.get_index();
424
- if (type == ContextType.TYPE_WITNESS_ID) {
453
+ if (type === ContextType.TYPE_WITNESS_ID) {
425
454
  // add witness to constant
426
455
  GuardConstantHelper.add_future_constant(this.constant, identifier, value, undefined, bNeedSerialize);
427
456
  } else {
@@ -431,7 +460,7 @@ export class GuardMaker {
431
460
  }
432
461
 
433
462
  private serValueParam(type:ValueType, param?:any) {
434
- if (!param) ERROR(Errors.InvalidParam, 'param');
463
+ if (param === undefined) ERROR(Errors.InvalidParam, 'param');
435
464
  this.data.push(Bcs.getInstance().ser(ValueType.TYPE_U8, type));
436
465
  let ser = SER_VALUE.find(s=>s.type==type);
437
466
  if (!ser) ERROR(Errors.Fail, 'serValueParam: invalid type');
@@ -441,6 +470,7 @@ export class GuardMaker {
441
470
 
442
471
  // serialize const & data
443
472
  add_param(type:ValueType | ContextType, param?:any) : GuardMaker {
473
+ const e = SER_VALUE.find((v:any)=>v.type===type)?.name ?? '' + ' invalid';
444
474
  switch(type) {
445
475
  case ValueType.TYPE_ADDRESS:
446
476
  case ValueType.TYPE_BOOL:
@@ -464,7 +494,7 @@ export class GuardMaker {
464
494
  break;
465
495
  case ValueType.TYPE_STRING:
466
496
  case ValueType.TYPE_VEC_U8:
467
- if (!param) ERROR(Errors.InvalidParam, 'param');
497
+ if (!param) ERROR(Errors.InvalidParam, 'param:'+e);
468
498
  this.data.push(Bcs.getInstance().ser(ValueType.TYPE_U8, type)); //@ USE VEC-U8
469
499
  if (typeof(param) == 'string') {
470
500
  this.data.push(Bcs.getInstance().ser(ValueType.TYPE_STRING, param));
@@ -482,56 +512,60 @@ export class GuardMaker {
482
512
  this.type_validator.push(ValueType.TYPE_U64);
483
513
  break;
484
514
  case ContextType.TYPE_WITNESS_ID:
485
- if (!param) ERROR(Errors.InvalidParam, 'param');
515
+ if (!param) ERROR(Errors.InvalidParam, 'param:'+e);
486
516
  this.data.push(Bcs.getInstance().ser(ValueType.TYPE_U8, type));
487
517
  this.data.push(Bcs.getInstance().ser(ValueType.TYPE_ADDRESS, param));
488
518
  this.type_validator.push(ValueType.TYPE_ADDRESS);
489
519
  break;
490
- case ContextType.TYPE_CONSTANT:
520
+ case ContextType.TYPE_CONSTANT:
491
521
  if (!param) {
492
- ERROR(Errors.InvalidParam, 'param invalid');
522
+ ERROR(Errors.InvalidParam, 'param invalid:'+e);
493
523
  }
494
524
  if (typeof(param) != 'number' || !IsValidInt(param) || param > 255) {
495
- ERROR(Errors.InvalidParam, 'add_param param');
525
+ ERROR(Errors.InvalidParam, 'add_param param:'+type);
496
526
  }
497
527
 
498
528
  var v = this.constant.get(param);
499
- if (!v) ERROR(Errors.Fail, 'identifier not in constant');
500
- this.type_validator.push(v!.type);
501
- this.data.push(Bcs.getInstance().ser(ValueType.TYPE_U8, type));
502
- this.data.push(Bcs.getInstance().ser(ValueType.TYPE_U8, param));
529
+ if (!v) ERROR(Errors.Fail, 'identifier not in constant:'+e);
530
+ var t = v!.type;
531
+ if (v?.type === ContextType.TYPE_WITNESS_ID) {
532
+ t = ValueType.TYPE_ADDRESS;
533
+ }
534
+ this.type_validator.push(t); //@ type validator convert
535
+ this.data.push(Bcs.getInstance().ser(ValueType.TYPE_U8, type)); // constant flag
536
+ this.data.push(Bcs.getInstance().ser(ValueType.TYPE_U8, param)); // identifier
503
537
  break;
504
538
  default:
505
- ERROR(Errors.InvalidParam, 'add_param type' + type);
539
+ ERROR(Errors.InvalidParam, 'add_param type:'+e);
506
540
  };
507
541
  return this;
508
542
  }
509
543
 
510
544
  // object_address_from: string for static address; number as identifier inconstant
511
- add_query(module:MODULES, query_name:string, object_address_from:string | number, bWitness:boolean=false) : GuardMaker {
545
+ add_query(module:MODULES, query_name:string, object_address_from:string | number, bWitness:boolean=false) : GuardMaker {
512
546
  let query_index = Guard.QUERIES.findIndex((q) => { return q[0] == module && q[1] == query_name})
513
547
  if (query_index == -1) {
514
- ERROR(Errors.InvalidParam, 'query_name');
548
+ ERROR(Errors.InvalidParam, 'query_name:'+query_name);
515
549
  }
516
550
 
517
551
  if (typeof(object_address_from) == 'number' ) {
518
552
  if (!GuardConstantHelper.IsValidIndentifier(object_address_from)) {
519
- ERROR(Errors.InvalidParam, 'object_address_from');
553
+ ERROR(Errors.InvalidParam, 'object_address_from:'+query_name);
520
554
  }
521
555
  } else {
522
556
  if (!IsValidAddress(object_address_from)) {
523
- ERROR(Errors.InvalidParam, 'object_address_from');
557
+ ERROR(Errors.InvalidParam, 'object_address_from:'+query_name);
524
558
  }
525
559
  }
526
560
 
527
561
  let offset = this.type_validator.length - Guard.QUERIES[query_index][3].length;
528
562
  if (offset < 0) {
529
- ERROR(Errors.InvalidParam, 'query_name');
563
+ ERROR(Errors.InvalidParam, 'query_name:'+query_name);
530
564
  }
531
565
 
532
566
  let types = this.type_validator.slice(offset);
533
567
  if (!array_equal(types, Guard.QUERIES[query_index][3])) { // type validate
534
- ERROR(Errors.Fail, 'array_equal');
568
+ ERROR(Errors.Fail, 'array_equal:'+query_name);
535
569
  }
536
570
 
537
571
  this.data.push(Bcs.getInstance().ser(ValueType.TYPE_U8, OperatorType.TYPE_QUERY)); // QUERY TYPE
@@ -541,12 +575,12 @@ export class GuardMaker {
541
575
  this.data.push(Bcs.getInstance().ser(ValueType.TYPE_ADDRESS, object_address_from)); // object address
542
576
  } else {
543
577
  let v = this.constant.get(object_address_from);
544
- if (!v) ERROR(Errors.Fail, 'object_address_from not in constant');
578
+ if (!v) ERROR(Errors.Fail, 'object_address_from not in constant:'+query_name);
545
579
  if ((bWitness && v?.type == ContextType.TYPE_WITNESS_ID) || (!bWitness && v?.type == ValueType.TYPE_ADDRESS)) {
546
580
  this.data.push(Bcs.getInstance().ser(ValueType.TYPE_U8, ContextType.TYPE_CONSTANT));
547
581
  this.data.push(Bcs.getInstance().ser(ValueType.TYPE_U8, object_address_from)); // object identifer in constants
548
582
  } else {
549
- ERROR(Errors.Fail, 'type bWitness not match')
583
+ ERROR(Errors.Fail, 'type bWitness not match:'+query_name)
550
584
  }
551
585
  }
552
586
 
@@ -556,7 +590,10 @@ export class GuardMaker {
556
590
  return this;
557
591
  }
558
592
 
559
- add_logic(type:OperatorType) : GuardMaker {
593
+ add_logic(type:OperatorType, logic_count:number=2) : GuardMaker {
594
+ var e:any = LogicsInfo.find((v:any) => v[0] === type);
595
+ if (e) { e=e[1] }
596
+
560
597
  let splice_len = 2;
561
598
  let ret = ValueType.TYPE_BOOL;
562
599
  switch (type) {
@@ -565,43 +602,41 @@ export class GuardMaker {
565
602
  case OperatorType.TYPE_LOGIC_AS_U256_LESSER:
566
603
  case OperatorType.TYPE_LOGIC_AS_U256_LESSER_EQUAL:
567
604
  case OperatorType.TYPE_LOGIC_AS_U256_EQUAL:
568
- if (this.type_validator.length < splice_len) { ERROR(Errors.Fail, 'type_validator.length') }
569
- if (!GuardMaker.match_u256(this.type_validator[this.type_validator.length - 1])) { ERROR(Errors.Fail, 'type_validator check') }
570
- if (!GuardMaker.match_u256(this.type_validator[this.type_validator.length - 2])) { ERROR(Errors.Fail, 'type_validator check') }
605
+ if (this.type_validator.length < splice_len) { ERROR(Errors.Fail, 'type_validator.length:' + e) }
606
+ if (!GuardMaker.match_u256(this.type_validator[this.type_validator.length - 1])) { ERROR(Errors.Fail, 'type_validator check:'+e) }
607
+ if (!GuardMaker.match_u256(this.type_validator[this.type_validator.length - 2])) { ERROR(Errors.Fail, 'type_validator check:'+e) }
571
608
  break;
572
609
  case OperatorType.TYPE_LOGIC_EQUAL:
573
- if (this.type_validator.length < splice_len) { ERROR(Errors.Fail, 'type_validator.length') }
610
+ if (this.type_validator.length < splice_len) { ERROR(Errors.Fail, 'type_validator.length:' + e) }
611
+ if (GuardMaker.match_u256(this.type_validator[this.type_validator.length - 1]) &&
612
+ GuardMaker.match_u256(this.type_validator[this.type_validator.length - 2])) {
613
+ break;
614
+ } else if (this.type_validator[this.type_validator.length - 1] === this.type_validator[this.type_validator.length - 2]) {
615
+ break;
616
+ } else {
617
+ ERROR(Errors.Fail, 'type_validator check:' + e) ;
618
+ }
574
619
  break;
575
620
  case OperatorType.TYPE_LOGIC_HAS_SUBSTRING:
576
- if (this.type_validator.length < splice_len) { ERROR(Errors.Fail, 'type_validator.length') }
621
+ if (this.type_validator.length < splice_len) { ERROR(Errors.Fail, 'type_validator.length:' + e) }
622
+ if (this.type_validator[this.type_validator.length - 1] !== ValueType.TYPE_STRING ||
623
+ this.type_validator[this.type_validator.length - 2] !== ValueType.TYPE_STRING) {
624
+ ERROR(Errors.Fail, 'type_validator check:' + e) ;
625
+ }
577
626
  break;
578
627
  case OperatorType.TYPE_LOGIC_NOT:
579
628
  splice_len = 1;
580
- if (this.type_validator.length < splice_len) { ERROR(Errors.Fail, 'type_validator.length') }
581
- if (this.type_validator[this.type_validator.length -1] != ValueType.TYPE_BOOL) { ERROR(Errors.Fail, 'type_validator check') }
629
+ if (this.type_validator.length < splice_len) { ERROR(Errors.Fail, 'type_validator.length:'+e) }
630
+ if (this.type_validator[this.type_validator.length -1] != ValueType.TYPE_BOOL) { ERROR(Errors.Fail, 'type_validator check:'+e) }
582
631
  break;
583
632
  case OperatorType.TYPE_LOGIC_AND:
584
- case OperatorType.TYPE_LOGIC_OR:
585
- if (this.type_validator.length < splice_len) { ERROR(Errors.Fail, 'type_validator.length') }
586
- if (this.type_validator[this.type_validator.length -1] != ValueType.TYPE_BOOL) { ERROR(Errors.Fail, 'type_validator check') }
587
- if (this.type_validator[this.type_validator.length -2] != ValueType.TYPE_BOOL) { ERROR(Errors.Fail, 'type_validator check') }
588
- break;
589
- case OperatorType.TYPE_LOGIC_AND3:
590
- case OperatorType.TYPE_LOGIC_OR3:
591
- splice_len = 3;
592
- if (this.type_validator.length < splice_len) { ERROR(Errors.Fail, 'type_validator.length') }
593
- if (this.type_validator[this.type_validator.length -1] != ValueType.TYPE_BOOL) { ERROR(Errors.Fail, 'type_validator check') }
594
- if (this.type_validator[this.type_validator.length -2] != ValueType.TYPE_BOOL) { ERROR(Errors.Fail, 'type_validator check') }
595
- if (this.type_validator[this.type_validator.length -3] != ValueType.TYPE_BOOL) { ERROR(Errors.Fail, 'type_validator check') }
596
- break;
597
- case OperatorType.TYPE_LOGIC_AND4:
598
- case OperatorType.TYPE_LOGIC_OR4:
599
- splice_len = 4;
600
- if (this.type_validator.length < splice_len) { ERROR(Errors.Fail, 'type_validator.length') }
601
- if (this.type_validator[this.type_validator.length -1] != ValueType.TYPE_BOOL) { ERROR(Errors.Fail, 'type_validator check') }
602
- if (this.type_validator[this.type_validator.length -2] != ValueType.TYPE_BOOL) { ERROR(Errors.Fail, 'type_validator check') }
603
- if (this.type_validator[this.type_validator.length -3] != ValueType.TYPE_BOOL) { ERROR(Errors.Fail, 'type_validator check') }
604
- if (this.type_validator[this.type_validator.length -4] != ValueType.TYPE_BOOL) { ERROR(Errors.Fail, 'type_validator check') }
633
+ case OperatorType.TYPE_LOGIC_OR: //@ logics count
634
+ if (!logic_count || logic_count < 2) ERROR(Errors.Fail, 'logic param invalid:'+e);
635
+ splice_len = logic_count!;
636
+ if (this.type_validator.length < splice_len) { ERROR(Errors.Fail, 'type_validator.length:'+e) }
637
+ for (let i = 1; i <= splice_len; ++i) {
638
+ if (this.type_validator[this.type_validator.length -i] != ValueType.TYPE_BOOL) { ERROR(Errors.Fail, 'type_validator check:'+e) }
639
+ }
605
640
  break;
606
641
  case OperatorType.TYPE_LOGIC_ALWAYS_TRUE:
607
642
  break;
@@ -610,15 +645,19 @@ export class GuardMaker {
610
645
  case OperatorType.TYPE_NUMBER_MULTIPLY:
611
646
  case OperatorType.TYPE_NUMBER_SUBTRACT:
612
647
  case OperatorType.TYPE_NUMBER_MOD:
613
- if (this.type_validator.length < splice_len) { ERROR(Errors.Fail, 'type_validator.length') }
614
- if (!GuardMaker.IsNumberType(this.type_validator[this.type_validator.length -1])) { ERROR(Errors.Fail, 'type_validator check') }
615
- if (!GuardMaker.IsNumberType(this.type_validator[this.type_validator.length -2])) { ERROR(Errors.Fail, 'type_validator check') }
648
+ if (this.type_validator.length < splice_len) { ERROR(Errors.Fail, 'type_validator.length:'+e) }
649
+ if (!GuardMaker.IsNumberType(this.type_validator[this.type_validator.length -1])) { ERROR(Errors.Fail, 'type_validator check:'+e) }
650
+ if (!GuardMaker.IsNumberType(this.type_validator[this.type_validator.length -2])) { ERROR(Errors.Fail, 'type_validator check:'+e) }
616
651
  ret = ValueType.TYPE_U256;
617
652
  break;
618
653
  default:
619
- ERROR(Errors.InvalidParam, 'add_logic type invalid' + type)
654
+ ERROR(Errors.InvalidParam, 'add_logic type invalid:' + e)
620
655
  }
621
- this.data.push(Bcs.getInstance().ser(ValueType.TYPE_U8, type)); // TYPE
656
+
657
+ this.data.push(Bcs.getInstance().ser(ValueType.TYPE_U8, type)); // TYPE
658
+ if (type === OperatorType.TYPE_LOGIC_AND || type === OperatorType.TYPE_LOGIC_OR) {
659
+ this.data.push((Bcs.getInstance().ser(ValueType.TYPE_U8, logic_count))); //@ logics
660
+ }
622
661
  this.type_validator.splice(this.type_validator.length - splice_len); // delete type stack
623
662
  this.type_validator.push(ret); // add bool to type stack
624
663
  return this;
@@ -663,7 +702,7 @@ export class GuardMaker {
663
702
  maker.constant.set(k, {type:v.type, value:v.value, witness:v.witness});
664
703
  })
665
704
  let op = bAnd ? OperatorType.TYPE_LOGIC_AND : OperatorType.TYPE_LOGIC_OR;
666
- maker.data.push(concatenate(Uint8Array, ...this.data, ...otherBuilt.data, Bcs.getInstance().ser(ValueType.TYPE_U8, op)));
705
+ maker.data.push(concatenate(Uint8Array, ...this.data, ...otherBuilt.data, Bcs.getInstance().ser(ValueType.TYPE_U8, op), Bcs.getInstance().ser(ValueType.TYPE_U8, 2)));
667
706
  this.data.splice(0, this.data.length-1);
668
707
  maker.type_validator = this.type_validator;
669
708
  return maker
@@ -672,22 +711,17 @@ export class GuardMaker {
672
711
  get_constant() { return this.constant }
673
712
  get_input() { return this.data }
674
713
 
714
+ // and/or + logics count
675
715
  static input_combine(input1:Uint8Array, input2:Uint8Array, bAnd:boolean = true) : Uint8Array {
676
716
  let op = bAnd ? OperatorType.TYPE_LOGIC_AND : OperatorType.TYPE_LOGIC_OR;
677
- return concatenate(Uint8Array, input1, input2, Bcs.getInstance().ser(ValueType.TYPE_U8, op)) as Uint8Array;
717
+ return concatenate(Uint8Array, input1, input2, Bcs.getInstance().ser(ValueType.TYPE_U8, op), Bcs.getInstance().ser(ValueType.TYPE_U8, 2), ) as Uint8Array;
678
718
  }
679
719
  static input_not(input:Uint8Array) : Uint8Array {
680
720
  return concatenate(Uint8Array, input, Bcs.getInstance().ser(ValueType.TYPE_U8, OperatorType.TYPE_LOGIC_NOT)) as Uint8Array;
681
721
  }
682
722
 
683
723
  static match_u256(type:number) : boolean {
684
- if (type == ValueType.TYPE_U8 ||
685
- type == ValueType.TYPE_U64 ||
686
- type == ValueType.TYPE_U128 ||
687
- type == ValueType.TYPE_U256) {
688
- return true;
689
- }
690
- return false;
724
+ return (type == ValueType.TYPE_U8 || type == ValueType.TYPE_U64 || type == ValueType.TYPE_U128 || type == ValueType.TYPE_U256);
691
725
  }
692
726
  }
693
727
 
package/src/passport.ts CHANGED
@@ -71,12 +71,14 @@ export class GuardParser {
71
71
  static DeGuardObject_FromData = (guard_constants:any, guard_input_bytes:any) : {object:DeGuardData, constant:DeGuardConstant[]} => {
72
72
  let constants : DeGuardConstant[] = [];
73
73
  guard_constants.forEach((c:any) => {
74
- let value : any;
75
74
  let v = c?.fields ?? c; // graphql dosnot 'fields', but rpcall has.
76
- switch (v.type) {
75
+ const data:Uint8Array = Uint8Array.from(v.value);
76
+ const type = data.slice(0, 1)[0];
77
+ var value : any = data.slice(1);
78
+ switch (type) {
77
79
  case ContextType.TYPE_WITNESS_ID:
78
80
  case ValueType.TYPE_ADDRESS:
79
- value = '0x' + Bcs.getInstance().de(ValueType.TYPE_ADDRESS, Uint8Array.from(v.value)).toString();
81
+ value = '0x' + Bcs.getInstance().de(ValueType.TYPE_ADDRESS, Uint8Array.from(value)).toString();
80
82
  break;
81
83
  case ValueType.TYPE_BOOL:
82
84
  case ValueType.TYPE_U8:
@@ -100,15 +102,15 @@ export class GuardParser {
100
102
  case ValueType.TYPE_OPTION_STRING:
101
103
  case ValueType.TYPE_OPTION_VEC_U8:
102
104
  case ValueType.TYPE_VEC_STRING:
103
- let de = SER_VALUE.find(s=>s.type==v.type);
105
+ let de = SER_VALUE.find(s=>s.type==type);
104
106
  if (!de) ERROR(Errors.Fail, 'GuardObject de error')
105
- value = Bcs.getInstance().de(de!.type as number, Uint8Array.from(v.value));
107
+ value = Bcs.getInstance().de(type as number, Uint8Array.from(value));
106
108
  break;
107
109
 
108
110
  default:
109
- ERROR(Errors.Fail, 'GuardObject constant type invalid:' + v.type)
111
+ ERROR(Errors.Fail, 'GuardObject constant type invalid:' +type)
110
112
  }
111
- constants.push({identifier:v.identifier, type:v.type, value:value});
113
+ constants.push({identifier:v.identifier, type:type, value:value});
112
114
  });
113
115
  // console.log(constants)
114
116
  let bytes = Uint8Array.from(guard_input_bytes);
@@ -116,7 +118,7 @@ export class GuardParser {
116
118
  let data : DeGuardData[] = [];
117
119
  while (arr.length > 0) {
118
120
  let type : unknown = arr.shift() ;
119
- let value:any; let cmd:any; let identifier:any;
121
+ let value:any; let cmd:any; let identifier:any;
120
122
  switch (type as Data_Type) {
121
123
  case ContextType.TYPE_SIGNER:
122
124
  case ContextType.TYPE_CLOCK:
@@ -129,18 +131,16 @@ export class GuardParser {
129
131
  case OperatorType.TYPE_LOGIC_HAS_SUBSTRING:
130
132
  case OperatorType.TYPE_LOGIC_ALWAYS_TRUE:
131
133
  case OperatorType.TYPE_LOGIC_NOT:
132
- case OperatorType.TYPE_LOGIC_AND:
133
- case OperatorType.TYPE_LOGIC_OR:
134
- case OperatorType.TYPE_LOGIC_AND3:
135
- case OperatorType.TYPE_LOGIC_OR3:
136
- case OperatorType.TYPE_LOGIC_AND4:
137
- case OperatorType.TYPE_LOGIC_OR4:
138
134
  case OperatorType.TYPE_NUMBER_ADD:
139
135
  case OperatorType.TYPE_NUMBER_DEVIDE:
140
136
  case OperatorType.TYPE_NUMBER_MOD:
141
137
  case OperatorType.TYPE_NUMBER_MULTIPLY:
142
138
  case OperatorType.TYPE_NUMBER_SUBTRACT:
143
139
  break;
140
+ case OperatorType.TYPE_LOGIC_AND: //@ with logics count
141
+ case OperatorType.TYPE_LOGIC_OR:
142
+ value = arr.shift()! as number;
143
+ break;
144
144
  case ContextType.TYPE_CONSTANT:
145
145
  identifier = arr.shift()! as number; // identifier
146
146
  break;
@@ -348,7 +348,7 @@ export class GuardParser {
348
348
  current.ret_type = ValueType.TYPE_BOOL;
349
349
  if (stack.length < 2) ERROR(Errors.Fail, 'ResolveData: ' + current.type);
350
350
  var p1 = stack.pop() as DeGuardData; var p2 = stack.pop() as DeGuardData;
351
- console.log(p1); console.log(p2)
351
+ //console.log(p1); console.log(p2)
352
352
  if (!p1.ret_type || !p2.ret_type) ERROR(Errors.Fail, 'ResolveData: ' + current.type + ' INVALID param type');
353
353
  if (p1.ret_type != p2.ret_type) ERROR(Errors.Fail, 'ResolveData: ' + current.type + ' param type not match');
354
354
 
@@ -361,7 +361,7 @@ export class GuardParser {
361
361
  if (stack.length < 2) ERROR(Errors.Fail, 'ResolveData: ' + current.type);
362
362
  var p1 = stack.pop() as DeGuardData; var p2 = stack.pop() as DeGuardData;
363
363
  if (!p1.ret_type || !p2.ret_type) ERROR(Errors.Fail, 'ResolveData: ' + current.type + ' INVALID param type');
364
- if (p1.ret_type != ValueType.TYPE_VEC_U8 || p2.ret_type != ValueType.TYPE_VEC_U8) {
364
+ if (p1.ret_type != ValueType.TYPE_STRING || p2.ret_type != ValueType.TYPE_STRING) {
365
365
  ERROR(Errors.Fail, 'ResolveData: ' + current.type + ' param type not match');
366
366
  }
367
367
 
@@ -372,15 +372,12 @@ export class GuardParser {
372
372
  case OperatorType.TYPE_LOGIC_AND:
373
373
  case OperatorType.TYPE_LOGIC_OR:
374
374
  current.ret_type = ValueType.TYPE_BOOL;
375
- if (stack.length < 2) ERROR(Errors.Fail, 'ResolveData: ' + current.type);
376
- var p1 = stack.pop() as DeGuardData; var p2 = stack.pop() as DeGuardData;
377
- if (!p1.ret_type || !p2.ret_type) ERROR(Errors.Fail, 'ResolveData: ' + current.type + ' INVALID param type');
378
- if (p1.ret_type != ValueType.TYPE_BOOL || p2.ret_type != ValueType.TYPE_BOOL) {
379
- ERROR(Errors.Fail, 'ResolveData: ' + current.type + ' param type not match');
375
+ if (stack.length < current.value || current.value < 2) ERROR(Errors.Fail, 'ResolveData: ' + current.type);
376
+ for (let i = 0; i < current.value; ++i) {
377
+ var p = stack.pop() as DeGuardData;
378
+ if (!p.ret_type || (p.ret_type != ValueType.TYPE_BOOL)) ERROR(Errors.Fail, 'ResolveData: ' + current.type + ' INVALID param type');
379
+ current.child.push(p);
380
380
  }
381
-
382
- current.child.push(p1);
383
- current.child.push(p2);
384
381
  stack.push(current);
385
382
  return
386
383
  case OperatorType.TYPE_QUERY:
@@ -543,12 +540,16 @@ export class GuardParser {
543
540
  constants.forEach((v:any) => {
544
541
  if (v.type == (Protocol.Instance().Package() + '::guard::Constant')) {
545
542
  // ValueType.TYPE_ADDRESS: Query_Cmd maybe used the address, so save it for querying
546
- if (v.fields.type == ContextType.TYPE_WITNESS_ID || v.fields.type == ValueType.TYPE_ADDRESS) {
547
- info.constant.push({identifier:v.fields.identifier, index:this.get_index(), type:v.fields.type,
548
- value_or_witness:'0x' + Bcs.getInstance().de(ValueType.TYPE_ADDRESS, Uint8Array.from(v.fields.value))});
543
+ const data = Uint8Array.from(v.fields.value);
544
+ const type = data.slice(0, 1)[0];
545
+ const value = data.slice(1);
546
+ if (type == ContextType.TYPE_WITNESS_ID || type == ValueType.TYPE_ADDRESS) {
547
+ info.constant.push({identifier:v.fields.identifier, index:this.get_index(), type:type,
548
+ value_or_witness:'0x' + Bcs.getInstance().de(ValueType.TYPE_ADDRESS, Uint8Array.from(value))});
549
549
  }
550
550
  }
551
551
  });
552
+ //console.log(info.constant)
552
553
  }
553
554
 
554
555
  parse_bcs = (info:GuardInfo, chain_bytes: Uint8Array) => {
@@ -568,14 +569,16 @@ export class GuardParser {
568
569
  case OperatorType.TYPE_LOGIC_HAS_SUBSTRING:
569
570
  case OperatorType.TYPE_LOGIC_ALWAYS_TRUE:
570
571
  case OperatorType.TYPE_LOGIC_NOT:
571
- case OperatorType.TYPE_LOGIC_AND:
572
- case OperatorType.TYPE_LOGIC_OR:
573
572
  case OperatorType.TYPE_NUMBER_ADD:
574
573
  case OperatorType.TYPE_NUMBER_DEVIDE:
575
574
  case OperatorType.TYPE_NUMBER_MOD:
576
575
  case OperatorType.TYPE_NUMBER_MULTIPLY:
577
576
  case OperatorType.TYPE_NUMBER_SUBTRACT:
578
577
  break;
578
+ case OperatorType.TYPE_LOGIC_AND: //@ logics count
579
+ case OperatorType.TYPE_LOGIC_OR:
580
+ arr.splice(0, 1); // identifier of constant
581
+ break;
579
582
  case ContextType.TYPE_CONSTANT:
580
583
  arr.splice(0, 1); // identifier of constant
581
584
  break;
@@ -762,6 +765,7 @@ export class Passport {
762
765
  });
763
766
  })
764
767
 
768
+ console.log(query)
765
769
  // witness
766
770
  query?.witness.forEach((w) => {
767
771
  this.txb.moveCall({
@@ -774,13 +778,13 @@ export class Passport {
774
778
  const clock = this.txb.sharedObjectRef(Protocol.CLOCK_OBJECT);
775
779
  // rules: 'verify' & 'query' in turns; 'verify' at final end.
776
780
  query?.query.forEach((q) => {
777
- let address = this.txb.moveCall({
781
+ this.txb.moveCall({
778
782
  target: Protocol.Instance().PassportFn('passport_verify') as FnCallType,
779
783
  arguments: [ this.passport, this.txb.object(clock)]
780
784
  });
781
785
  this.txb.moveCall({
782
786
  target: q.target as FnCallType,
783
- arguments: [ bObject ? this.txb.object(q.object) : this.txb.object(q.id), this.passport, address ],
787
+ arguments: [ bObject ? this.txb.object(q.object) : this.txb.object(q.id), this.passport],
784
788
  typeArguments: q.types,
785
789
  })
786
790
  })
package/src/permission.ts CHANGED
@@ -273,7 +273,7 @@ export class Permission {
273
273
  ERROR(Errors.IsValidArray, 'add_entity2');
274
274
  }
275
275
 
276
- if (index) {
276
+ if (index !== undefined) {
277
277
  this.txb.moveCall({
278
278
  target:Protocol.Instance().PermissionFn('add_with_index') as FnCallType,
279
279
  arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.u64(index),
@@ -288,9 +288,7 @@ export class Permission {
288
288
  }
289
289
 
290
290
  add_entity(entities:Permission_Entity[]) {
291
- if (!entities) {
292
- ERROR(Errors.InvalidParam, 'add_entity');
293
- }
291
+ if (entities.length === 0) return
294
292
 
295
293
  let bValid = true;
296
294
  let e = entities.forEach((v) => {
@@ -322,13 +320,14 @@ export class Permission {
322
320
  }
323
321
  }
324
322
  }
325
- //if (indexes.length > 0) {
323
+
324
+ if (indexes.length > 0) {
326
325
  this.txb.moveCall({
327
326
  target:Protocol.Instance().PermissionFn('add_batch') as FnCallType,
328
327
  arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.address(entity.entity_address),
329
328
  this.txb.pure.vector('u64', indexes)]
330
329
  })
331
- //}
330
+ }
332
331
  }
333
332
  // set guards
334
333
  guards.forEach(({entity_address, index, guard}) => {
@@ -368,7 +367,8 @@ export class Permission {
368
367
  if (!IsValidAddress(entity_address)) {
369
368
  ERROR(Errors.IsValidAddress)
370
369
  }
371
- if (!index || !(IsValidArray(index, Permission.IsValidPermissionIndex))) {
370
+ if (index.length === 0) return ;
371
+ if (!(IsValidArray(index, Permission.IsValidPermissionIndex))) {
372
372
  ERROR(Errors.InvalidParam, 'index')
373
373
  }
374
374
 
@@ -379,7 +379,8 @@ export class Permission {
379
379
  })
380
380
  }
381
381
  remove_entity(entity_address:string[]) {
382
- if (!entity_address || !IsValidArray(entity_address, IsValidAddress)) {
382
+ if (entity_address.length === 0) return ;
383
+ if (!IsValidArray(entity_address, IsValidAddress)) {
383
384
  ERROR(Errors.IsValidArray)
384
385
  }
385
386
 
package/src/progress.ts CHANGED
@@ -188,24 +188,25 @@ export class Progress {
188
188
  }
189
189
  }
190
190
  unhold(next:ProgressNext, passport?:PassportObject) {
191
- console.log(next)
192
191
  if (!Progress.IsValidProgressNext(next)) {
193
192
  ERROR(Errors.InvalidParam, 'unhold')
194
193
  }
195
194
 
195
+ const clock = this.txb.sharedObjectRef(Protocol.CLOCK_OBJECT);
196
+
196
197
  if (passport) {
197
198
  this.txb.moveCall({
198
199
  target:Protocol.Instance().ProgressFn('unhold_with_passport') as FnCallType,
199
200
  arguments: [passport, Protocol.TXB_OBJECT(this.txb, this.object),
200
201
  Protocol.TXB_OBJECT(this.txb, this.machine), this.txb.pure.string(next.next_node_name),
201
- this.txb.pure.string(next.forward), Protocol.TXB_OBJECT(this.txb, this.permission)],
202
+ this.txb.pure.string(next.forward), Protocol.TXB_OBJECT(this.txb, this.permission), this.txb.object(clock)],
202
203
  })
203
204
  } else {
204
205
  this.txb.moveCall({
205
206
  target:Protocol.Instance().ProgressFn('unhold') as FnCallType,
206
207
  arguments: [Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, this.machine),
207
208
  this.txb.pure.string(next.next_node_name), this.txb.pure.string(next.forward),
208
- Protocol.TXB_OBJECT(this.txb, this.permission)],
209
+ Protocol.TXB_OBJECT(this.txb, this.permission), this.txb.object(clock)],
209
210
  })
210
211
  }
211
212
  }
@@ -293,11 +294,11 @@ export class Progress {
293
294
  if (!Progress.IsValidProgressNext(next)) {
294
295
  ERROR(Errors.InvalidParam, 'hold')
295
296
  }
296
-
297
+ const clock = this.txb.sharedObjectRef(Protocol.CLOCK_OBJECT);
297
298
  this.txb.moveCall({
298
299
  target:Protocol.Instance().ProgressFn('hold') as FnCallType,
299
300
  arguments: [Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, this.machine), this.txb.pure.string(next.next_node_name),
300
- this.txb.pure.string(next.forward), this.txb.pure.bool(hold), Protocol.TXB_OBJECT(this.txb, this.permission)],
301
+ this.txb.pure.string(next.forward), this.txb.pure.bool(hold), Protocol.TXB_OBJECT(this.txb, this.permission), this.txb.object(clock)],
301
302
  })
302
303
  }
303
304
 
package/src/protocol.ts CHANGED
@@ -79,10 +79,6 @@ export enum OperatorType {
79
79
  TYPE_LOGIC_NOT = 19, // NOT
80
80
  TYPE_LOGIC_AND = 20, // AND
81
81
  TYPE_LOGIC_OR = 21, // OR
82
- TYPE_LOGIC_AND3 = 22, // and
83
- TYPE_LOGIC_AND4 = 23, // and
84
- TYPE_LOGIC_OR3 = 24, // or
85
- TYPE_LOGIC_OR4 = 25, // or
86
82
  }
87
83
 
88
84
  export const LogicsInfo = [
@@ -91,16 +87,12 @@ export const LogicsInfo = [
91
87
  [OperatorType.TYPE_LOGIC_AS_U256_LESSER, 'Unsigned Integer <'],
92
88
  [OperatorType.TYPE_LOGIC_AS_U256_LESSER_EQUAL, 'Unsigned Integer <='],
93
89
  [OperatorType.TYPE_LOGIC_AS_U256_EQUAL, 'Unsigned Integer ='],
94
- [OperatorType.TYPE_LOGIC_EQUAL, 'Equals ='],
90
+ [OperatorType.TYPE_LOGIC_EQUAL, 'Equal'],
95
91
  [OperatorType.TYPE_LOGIC_HAS_SUBSTRING, 'Sub String'],
96
92
  [OperatorType.TYPE_LOGIC_ALWAYS_TRUE, 'Always True'],
97
93
  [OperatorType.TYPE_LOGIC_NOT, 'Not'],
98
94
  [OperatorType.TYPE_LOGIC_AND, 'And'],
99
95
  [OperatorType.TYPE_LOGIC_OR, 'Or'],
100
- [OperatorType.TYPE_LOGIC_AND3, 'And 3'],
101
- [OperatorType.TYPE_LOGIC_OR3, 'Or 3'],
102
- [OperatorType.TYPE_LOGIC_AND4, 'And 4'],
103
- [OperatorType.TYPE_LOGIC_OR4, 'Or 4'],
104
96
  ];
105
97
 
106
98
  export enum ValueType {
@@ -173,7 +165,7 @@ interface ValueTypeString {
173
165
  export const SER_VALUE: ValueTypeString[] = [
174
166
  {type: ValueType.TYPE_BOOL, name: 'bool', description:'boolean. eg:true or false', validator:(value:any) => { return (value === true || value === false)}},
175
167
  {type: ValueType.TYPE_ADDRESS, name: 'address', description:'address or object-id. eg:0x6789af', validator:IsValidAddress},
176
- {type: ContextType.TYPE_WITNESS_ID, name: 'future address', description:"eg: address of the Machine that will generate future Progress, address of the Service that will generate future Order", validator:IsValidAddress},
168
+ {type: ContextType.TYPE_WITNESS_ID, name: 'witness address', description:"For example, the address of the Machine object ensures that the Progress generated in the past or future is verified; the address of the Service object ensures that the Order generated in the past or future is verified.", validator:IsValidAddress},
177
169
  {type: ContextType.TYPE_SIGNER, name: 'txn signer', description:"signer address of the transaction, "},
178
170
  {type: ContextType.TYPE_CLOCK, name: 'txn time', description:"unsigned-64 number for the transaction time"},
179
171
  {type: ValueType.TYPE_U64, name: 'number', description:'unsigned-64 number. eg:23870233', validator:IsValidU64},
@@ -216,10 +208,10 @@ const TESTNET = {
216
208
  }
217
209
  */
218
210
  const TESTNET = {
219
- package: "0x72a2ee21e11ee0c0d8fd9212127b12be0cdf7722b1e91c85a15a79cff3f7d9b0",
220
- wowok_object: '0x3e69e10a8ab426c5e6d4392841bb6f6b9b45b7fa5feb9fcf23d7616a2effba0c',
221
- entity_object: '0x53606d845cdedf0b256d27b3c0b0764265b2c272f3ad743a018ea4e8e59f3c74',
222
- treasury_cap:'0xbbbc1fcab63e3373d53669507d7a6042282edef398273dcc04fe24db47c4881d',
211
+ package: "0x7a36d0cb4ac23770bd07b770997b5ceef57e8f7b22563eea945111a0bcf38e8d",
212
+ wowok_object: '0xa79bbf5d1b96a015da7b763bc9528a226c8dbf86e481947aa5cfd0d3949da33b',
213
+ entity_object: '0x524dcfb8d2fad580ccffb09cc3b3b1377213db040dad6cdad36ed5a99f1b0c00',
214
+ treasury_cap:'0x8e4dbb61e5cd2ca4812faa86e0e1d886903bd0c48c8bf8d5af0856cb8a8e5df1',
223
215
  }
224
216
  const MAINNET = {
225
217
  package: "",
package/src/repository.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { Protocol, FnCallType, ValueType, RepositoryValueType, RepositoryAddress, PermissionObject, PassportObject, TxbObject} from './protocol';
1
+ import { Protocol, FnCallType, ValueType, RepositoryValueType, RepositoryAddress, PermissionObject, PassportObject, TxbObject, } from './protocol';
2
2
  import { PermissionIndexType, Permission } from './permission'
3
3
  import { Bcs, array_unique, IsValidDesription, IsValidAddress, IsValidArray, IsValidName, ValueTypeConvert} from './utils';
4
4
  import { ERROR, Errors } from './exception';
5
- import { MAX_U8, MAX_U128, MAX_U256, MAX_U64 } from './utils';
5
+ import { MAX_U8, MAX_U128, MAX_U256, MAX_U64, stringToUint8Array } from './utils';
6
6
  import { type TransactionResult, Transaction as TransactionBlock } from '@mysten/sui/transactions';
7
7
 
8
8
  export enum Repository_Policy_Mode {
package/src/service.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { IsValidArray, IsValidPercent, IsValidName_AllowEmpty, Bcs, array_unique, IsValidTokenType, IsValidDesription,
2
- IsValidAddress, IsValidEndpoint, IsValidU64, IsValidName,} from './utils'
2
+ IsValidAddress, IsValidEndpoint, IsValidU64, } from './utils'
3
3
  import { FnCallType, GuardObject, PassportObject, PermissionObject, RepositoryObject, MachineObject, ServiceAddress,
4
4
  ServiceObject, DiscountObject, OrderObject, OrderAddress, CoinObject, Protocol, ValueType,
5
5
  TxbObject} from './protocol';
@@ -155,10 +155,11 @@ export class Service {
155
155
  }
156
156
  set_price(item:string, price:bigint, bNotFoundAssert:boolean=true, passport?:PassportObject) {
157
157
  if (!IsValidU64(price)) {
158
- ERROR(Errors.IsValidU64, 'price')
158
+ ERROR(Errors.IsValidU64, 'set_price price')
159
159
  }
160
- if (!IsValidName(item)) {
161
- ERROR(Errors.IsValidName, 'item')
160
+
161
+ if (!Service.IsValidItemName(item)) {
162
+ ERROR(Errors.IsValidServiceItemName, 'set_price item')
162
163
  }
163
164
 
164
165
  if (passport) {
@@ -180,8 +181,8 @@ export class Service {
180
181
  }
181
182
  }
182
183
  set_stock(item:string, stock:bigint, bNotFoundAssert:boolean=true, passport?:PassportObject) {
183
- if (!IsValidName(item)) {
184
- ERROR(Errors.IsValidName, 'item')
184
+ if (!Service.IsValidItemName(item)) {
185
+ ERROR(Errors.IsValidServiceItemName, 'item')
185
186
  }
186
187
  if (!IsValidU64(stock)) {
187
188
  ERROR(Errors.IsValidU64, 'stock')
@@ -206,11 +207,11 @@ export class Service {
206
207
  }
207
208
  }
208
209
  add_stock(item:string, stock_add:bigint, bNotFoundAssert:boolean=true, passport?:PassportObject) {
209
- if (!IsValidName(item)) {
210
- ERROR(Errors.IsValidName, 'item')
210
+ if (!Service.IsValidItemName(item)) {
211
+ ERROR(Errors.IsValidServiceItemName, 'add_stock item')
211
212
  }
212
213
  if (!IsValidU64(stock_add)) {
213
- ERROR(Errors.IsValidUint, 'stock_add')
214
+ ERROR(Errors.IsValidUint, 'add_stock stock_add')
214
215
  }
215
216
 
216
217
  if (passport) {
@@ -232,11 +233,11 @@ export class Service {
232
233
  }
233
234
  }
234
235
  reduce_stock(item:string, stock_reduce:bigint, bNotFoundAssert:boolean=true, passport?:PassportObject) {
235
- if (!IsValidName(item)) {
236
- ERROR(Errors.IsValidName, 'item')
236
+ if (!Service.IsValidItemName(item)) {
237
+ ERROR(Errors.IsValidServiceItemName, 'reduce_stock item')
237
238
  }
238
239
  if (!IsValidU64(stock_reduce)) {
239
- ERROR(Errors.IsValidUint, 'stock_reduce')
240
+ ERROR(Errors.IsValidUint, 'reduce_stock stock_reduce')
240
241
  }
241
242
 
242
243
  if (passport) {
@@ -259,11 +260,11 @@ export class Service {
259
260
  }
260
261
 
261
262
  set_sale_endpoint(item:string, endpoint?:string|null, bNotFoundAssert:boolean=true, passport?:PassportObject) {
262
- if (!IsValidName(item)) {
263
- ERROR(Errors.IsValidName, 'set_sale_endpoint')
263
+ if (!Service.IsValidItemName(item)) {
264
+ ERROR(Errors.IsValidServiceItemName, 'set_sale_endpoint item')
264
265
  }
265
266
  if (endpoint && !IsValidEndpoint(endpoint)) {
266
- ERROR(Errors.IsValidEndpoint, 'set_sale_endpoint')
267
+ ERROR(Errors.IsValidEndpoint, 'set_sale_endpoint endpoint')
267
268
  }
268
269
 
269
270
  let ep = this.txb.pure.option('string', endpoint ? endpoint : undefined);
@@ -505,7 +506,7 @@ export class Service {
505
506
  is_valid_sale(sales:Service_Sale[]) {
506
507
  let bValid = true; let names:string[] = [];
507
508
  sales.forEach((v) => {
508
- if (!IsValidName(v.item)) bValid = false;
509
+ if (!Service.IsValidItemName(v.item)) bValid = false;
509
510
  if (!IsValidU64(v.price)) bValid = false;
510
511
  if (!IsValidU64(v.stock)) bValid = false;
511
512
  if (names.includes(v.item)) bValid = false;
@@ -555,7 +556,7 @@ export class Service {
555
556
  remove_sales(sales:string[], passport?:PassportObject) {
556
557
  if (sales.length === 0) return;
557
558
 
558
- if (!IsValidArray(sales, IsValidName)) {
559
+ if (!IsValidArray(sales, Service.IsValidItemName)) {
559
560
  ERROR(Errors.IsValidArray, 'remove_sales')
560
561
  }
561
562
 
@@ -913,7 +914,7 @@ export class Service {
913
914
 
914
915
  let bValid = true; let names:string[] = [];
915
916
  buy_items.forEach((v) => {
916
- if (!IsValidName(v.item)) bValid = false;
917
+ if (!Service.IsValidItemName(v.item)) bValid = false;
917
918
  if (!IsValidU64(v.max_price)) bValid = false;
918
919
  if (!IsValidU64(v.count)) bValid = false;
919
920
  if (names.includes(v.item)) bValid = false;
@@ -1010,8 +1011,14 @@ export class Service {
1010
1011
  static MAX_DISCOUNT_COUNT_ONCE = 200;
1011
1012
  static MAX_DISCOUNT_RECEIVER_COUNT = 20;
1012
1013
  static MAX_GUARD_COUNT = 16;
1013
- static MAX_REPOSITORY_COUNT = 16;
1014
-
1014
+ static MAX_REPOSITORY_COUNT = 32;
1015
+ static MAX_ITEM_NAME_LENGTH = 256;
1016
+
1017
+ static IsValidItemName(name:string) : boolean {
1018
+ if (!name) return false;
1019
+ return new TextEncoder().encode(name).length <= Service.MAX_ITEM_NAME_LENGTH;
1020
+ }
1021
+
1015
1022
  static parseObjectType = (chain_type:string | undefined | null) : string => {
1016
1023
  if (chain_type) {
1017
1024
  const s = 'service::Service<'
package/src/utils.ts CHANGED
@@ -120,7 +120,6 @@ export const concatenate = (resultConstructor:any, ...arrays:any[]) => {
120
120
  }
121
121
 
122
122
  export const array_equal = (arr1: any[], arr2: any[]) => {
123
- // Array.some(): 有一项不满足,返回false
124
123
  if (arr1.length !== arr2.length) {
125
124
  return false;
126
125
  }
@@ -241,9 +240,10 @@ export class Bcs {
241
240
  case ValueType.TYPE_U256:
242
241
  return this.bcs.ser(BCS.U256, data).toBytes();
243
242
  case ValueType.TYPE_STRING:
244
- return this.bcs.ser(BCS.STRING, data).toBytes();
243
+ const d = new TextEncoder().encode(data);
244
+ return this.bcs.ser('vector<u8>', d).toBytes();
245
245
  case ValueType.TYPE_VEC_STRING:
246
- return this.bcs.ser('vector<string>', data).toBytes();
246
+ return this.bcs.ser('vector<vector<u8>>', data.map((v:string)=>{return new TextEncoder().encode(v)})).toBytes();
247
247
  case ContextType.TYPE_WITNESS_ID:
248
248
  return this.bcs.ser(BCS.ADDRESS, data).toBytes();
249
249
  default:
@@ -297,7 +297,8 @@ export class Bcs {
297
297
  case ValueType.TYPE_VEC_U256:
298
298
  return this.bcs.de('vector<u256>', data);
299
299
  case ValueType.TYPE_STRING:
300
- return this.bcs.de(BCS.STRING, data);
300
+ const r = new TextDecoder().decode(Uint8Array.from(this.bcs.de('vector<u8>', data)));
301
+ return r
301
302
  case ValueType.TYPE_VEC_STRING:
302
303
  return this.bcs.de('vector<string>', data);
303
304
  case ValueType.TYPE_U256:
@@ -329,13 +330,10 @@ export class Bcs {
329
330
  }
330
331
  }
331
332
 
332
- export function stringToUint8Array(str:string) : Uint8Array {
333
- var arr = [];
334
- for (var i = 0, j = str.length; i < j; ++i) {
335
- arr.push(str.charCodeAt(i));
336
- }
337
- var tmpUint8Array = new Uint8Array(arr);
338
- return tmpUint8Array
333
+ export function stringToUint8Array(str:string) {
334
+ const encoder = new TextEncoder();
335
+ const view = encoder.encode(str);
336
+ return new Uint8Array(view.buffer);
339
337
  }
340
338
 
341
339
  export function numToUint8Array(num:number) : Uint8Array {
@@ -509,6 +507,15 @@ export const ParseType = (type:string) : ArgType => {
509
507
  return {isCoin:false, coin:'', token:''}
510
508
  }
511
509
 
510
+
511
+ export function insertAtHead(array:Uint8Array, value:number) {
512
+ const newLength = array.length + 1;
513
+ const newArray = new Uint8Array(newLength);
514
+ newArray.set([value], 0);
515
+ newArray.set(array, 1);
516
+ return newArray;
517
+ }
518
+
512
519
  export function toFixed(x:number) {
513
520
  let res = '';
514
521
  if (Math.abs(x) < 1.0) {