wowok 1.2.12 → 1.3.4

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/permission.ts CHANGED
@@ -1,37 +1,36 @@
1
- import { BCS } from '@mysten/bcs';
2
1
  import { FnCallType, TxbObject, PermissionObject, PermissionAddress, GuardObject, Protocol} from './protocol';
3
2
  import { array_unique, IsValidAddress, IsValidArray, IsValidDesription, IsValidUintLarge, Bcs, IsValidName} from './utils';
4
3
  import { ERROR, Errors } from './exception';
5
4
  import { ValueType } from './protocol';
6
- import { Passport } from './passport';
5
+ import { BCS } from '@mysten/bcs';
7
6
  import { Transaction as TransactionBlock } from '@mysten/sui/transactions';
8
7
 
9
8
  export enum PermissionIndex {
10
9
  repository = 100,
11
- repository_set_description_set = 101,
12
- repository_set_policy_mode = 102,
13
- repository_add_remove_policies = 103,
14
- repository_set_policy_description = 105,
15
- repository_set_policy_permission = 106,
10
+ repository_description = 101,
11
+ repository_policy_mode = 102,
12
+ repository_policies = 103,
13
+ repository_policy_description = 105,
14
+ repository_policy_permission = 106,
16
15
  repository_reference = 107,
17
16
 
18
17
  vote = 150,
19
- vote_set_description = 151,
20
- vote_set_reference = 152,
18
+ vote_description = 151,
19
+ vote_reference = 152,
21
20
  vote_guard = 153,
22
21
  vote_option = 155,
23
- vote_set_max_choice_count = 157,
22
+ vote_max_choice_count = 157,
24
23
  vote_open_voting = 158,
25
24
  vote_lock_deadline = 159,
26
25
  vote_expand_deadline = 160,
27
26
  vote_lock_guard = 161,
28
27
 
29
28
  service = 200,
30
- service_set_description = 201,
31
- service_set_price = 202,
32
- service_set_add_reduce_stock = 203,
33
- service_set_sale_endpoint = 204,
34
- service_set_payee = 205,
29
+ service_description = 201,
30
+ service_price = 202,
31
+ service_stock = 203,
32
+ service_sale_endpoint = 204,
33
+ service_payee = 205,
35
34
  service_repository = 206,
36
35
  service_withdraw_guards = 208,
37
36
  service_refund_guards = 210,
@@ -39,9 +38,9 @@ export enum PermissionIndex {
39
38
  service_remove_sales = 213,
40
39
  service_discount_transfer = 214,
41
40
  service_withdraw = 216,
42
- service_set_buy_guard = 217,
43
- service_set_machine = 218,
44
- service_set_endpoint = 219,
41
+ service_buyer_guard = 217,
42
+ service_machine = 218,
43
+ service_endpoint = 219,
45
44
  service_publish = 220,
46
45
  service_clone = 221,
47
46
  service_customer_required = 222,
@@ -52,30 +51,33 @@ export enum PermissionIndex {
52
51
  reward_refund = 241,
53
52
  reward_expand_time = 242,
54
53
  reward_guard = 243,
55
- reward_set_description = 245,
54
+ reward_description = 245,
56
55
  reward_lock_guards = 246,
56
+ reward_claim_repeatably = 247,
57
+ reward_allow_claiming = 248,
57
58
 
58
59
  demand = 260,
59
60
  demand_refund = 261,
60
61
  demand_expand_time = 262,
61
- demand_set_guard = 263,
62
- demand_set_description = 264,
62
+ demand_guard = 263,
63
+ demand_description = 264,
63
64
  demand_yes = 265,
64
65
 
65
66
  machine = 600,
66
- machine_set_description = 601,
67
+ machine_description = 601,
67
68
  machine_repository = 602,
68
69
  machine_clone = 604,
69
70
  machine_node = 606,
70
- machine_set_endpoint = 608,
71
+ machine_endpoint = 608,
71
72
  machine_pause = 609,
72
73
  machine_publish = 610,
73
74
 
74
75
  progress = 650,
75
- progress_set_namedOperator = 651,
76
+ progress_namedOperator = 651,
76
77
  progress_bind_task = 652,
77
- progress_set_context_repository = 653,
78
+ progress_context_repository = 653,
78
79
  progress_unhold = 654,
80
+ progress_parent = 655,
79
81
  user_defined_start = 10000,
80
82
  }
81
83
 
@@ -92,6 +94,7 @@ export interface PermissionAnswer {
92
94
  owner?: boolean;
93
95
  admin?: boolean;
94
96
  items?: PermissionAnswerItem[]; // items === undefined, while errors
97
+ object: string; // permission object
95
98
  }
96
99
  export interface PermissionAnswerItem {
97
100
  query: PermissionIndexType;
@@ -102,29 +105,29 @@ export type OnPermissionAnswer = (answer: PermissionAnswer) => void;
102
105
 
103
106
  export const PermissionInfo : PermissionInfoType[] = [
104
107
  {index:PermissionIndex.repository, name:'Repository', description:'Launch new Repository', module: 'repository'},
105
- {index:PermissionIndex.repository_set_description_set, name:'Description', description:'Set Repository description', module: 'repository'},
106
- {index:PermissionIndex.repository_set_policy_mode, name:'Policy mode', description:'Set Repository policy mode', module: 'repository'},
107
- {index:PermissionIndex.repository_add_remove_policies, name:'Policy', description:'Add/Remove Repository policy', module: 'repository'},
108
- {index:PermissionIndex.repository_set_policy_description, name:'Policy Description', description:'Set Repository policy description', module: 'repository'},
109
- {index:PermissionIndex.repository_set_policy_permission, name:'Policy Permission', description:'Set Repository policy permission', module: 'repository'},
108
+ {index:PermissionIndex.repository_description, name:'Description', description:'Set Repository description', module: 'repository'},
109
+ {index:PermissionIndex.repository_policy_mode, name:'Policy mode', description:'Set Repository policy mode', module: 'repository'},
110
+ {index:PermissionIndex.repository_policies, name:'Policy', description:'Add/Remove/Edit Repository policy', module: 'repository'},
111
+ {index:PermissionIndex.repository_policy_description, name:'Policy Description', description:'Set Repository policy description', module: 'repository'},
112
+ {index:PermissionIndex.repository_policy_permission, name:'Policy Permission', description:'Set Repository policy permission', module: 'repository'},
110
113
  {index:PermissionIndex.repository_reference, name:'Reference', description:'Set Repository reference', module: 'repository'},
111
114
 
112
115
  {index:PermissionIndex.vote, name:'Vote', description:'Launch new Vote', module: 'vote'},
113
- {index:PermissionIndex.vote_set_description, name:'Description', description:'Set Vote description', module: 'vote'},
114
- {index:PermissionIndex.vote_set_reference, name:'Reference', description:'Set Vote reference', module: 'vote'},
116
+ {index:PermissionIndex.vote_description, name:'Description', description:'Set Vote description', module: 'vote'},
117
+ {index:PermissionIndex.vote_reference, name:'Reference', description:'Set Vote reference', module: 'vote'},
115
118
  {index:PermissionIndex.vote_guard, name:'Guard', description:'Set Vote guards', module: 'vote'},
116
119
  {index:PermissionIndex.vote_option, name:'Option', description:'Set Vote options', module: 'vote'},
117
- {index:PermissionIndex.vote_set_max_choice_count, name:'Choice count', description:'Set Vote max choice count', module: 'vote'},
120
+ {index:PermissionIndex.vote_max_choice_count, name:'Choice count', description:'Set Vote max choice count', module: 'vote'},
118
121
  {index:PermissionIndex.vote_open_voting, name:'Open voting', description:'Open voting', module: 'vote'},
119
122
  {index:PermissionIndex.vote_lock_deadline, name:'Lock deadline', description:'Set Vote deadline immutable', module: 'vote'},
120
123
  {index:PermissionIndex.vote_expand_deadline, name:'Expand deadline', description:'Expand Vote deadline', module: 'vote'},
121
124
  {index:PermissionIndex.vote_lock_guard, name:'Lock Guard', description:'Set Vote guards immutable', module: 'vote'},
122
125
 
123
126
  {index:PermissionIndex.service, name:'Service', description:'Launch new Service', module: 'service'},
124
- {index:PermissionIndex.service_set_description, name:'Description', description:'Set Service description', module: 'service'},
125
- {index:PermissionIndex.service_set_price, name:'Price', description:'Set Service item price', module: 'service'},
126
- {index:PermissionIndex.service_set_add_reduce_stock, name:'Inventory', description:'Set Service item inventory', module: 'service'},
127
- {index:PermissionIndex.service_set_payee, name:'Payee', description:'Set Service payee', module: 'service'},
127
+ {index:PermissionIndex.service_description, name:'Description', description:'Set Service description', module: 'service'},
128
+ {index:PermissionIndex.service_price, name:'Price', description:'Set Service item price', module: 'service'},
129
+ {index:PermissionIndex.service_stock, name:'Inventory', description:'Set Service item inventory', module: 'service'},
130
+ {index:PermissionIndex.service_payee, name:'Payee', description:'Set Service payee', module: 'service'},
128
131
  {index:PermissionIndex.service_repository, name:'Repository', description:'Set Service repositories', module: 'service'},
129
132
  {index:PermissionIndex.service_withdraw_guards, name:'Withdraw Guard', description:'Set Service withdraw guards', module: 'service'},
130
133
  {index:PermissionIndex.service_refund_guards, name:'Refund Guard', description:'Set Service refund guards', module: 'service'},
@@ -132,9 +135,9 @@ export const PermissionInfo : PermissionInfoType[] = [
132
135
  {index:PermissionIndex.service_remove_sales, name:'Remove sales', description:'Remove sale items for Service', module: 'service'},
133
136
  {index:PermissionIndex.service_discount_transfer, name:'Discount', description:'Launch discounts for Service', module: 'service'},
134
137
  {index:PermissionIndex.service_withdraw, name:'Withdraw', description:'Widthraw from Service orders', module: 'service'},
135
- {index:PermissionIndex.service_set_buy_guard, name:'Buyer Guard', description:'Set Guard of buying for Service', module: 'service'},
136
- {index:PermissionIndex.service_set_machine, name:'Machine', description:'Set Machine for Service', module: 'service'},
137
- {index:PermissionIndex.service_set_endpoint, name:'Endpoint', description:'Set Service endpoint', module: 'service'},
138
+ {index:PermissionIndex.service_buyer_guard, name:'Buyer Guard', description:'Set Guard of buying for Service', module: 'service'},
139
+ {index:PermissionIndex.service_machine, name:'Machine', description:'Set Machine for Service', module: 'service'},
140
+ {index:PermissionIndex.service_endpoint, name:'Endpoint', description:'Set Service endpoint', module: 'service'},
138
141
  {index:PermissionIndex.service_publish, name:'Publish', description:'Publish Service', module: 'service'},
139
142
  {index:PermissionIndex.service_clone, name:'Clone', description:'Clone Service', module: 'service'},
140
143
  {index:PermissionIndex.service_customer_required, name:'Buyer info', description:'Set Service buyer info required', module: 'service'},
@@ -144,31 +147,34 @@ export const PermissionInfo : PermissionInfoType[] = [
144
147
  {index:PermissionIndex.reward, name:'Reward', description:'Launch new Reward', module: 'reward'},
145
148
  {index:PermissionIndex.reward_refund, name:'Refund', description:'Refund from Reward', module: 'reward'},
146
149
  {index:PermissionIndex.reward_expand_time, name:'Expand deadline', description:'Expand Reward deadline', module: 'reward'},
147
- {index:PermissionIndex.reward_guard, name:'Guard', description:'build machine', module: 'Set Reward guard'},
148
- {index:PermissionIndex.reward_set_description, name:'Description', description:'Set Reward description', module: 'reward'},
150
+ {index:PermissionIndex.reward_guard, name:'Guard', description:'Set Reward guard', module: 'reward'},
151
+ {index:PermissionIndex.reward_description, name:'Description', description:'Set Reward description', module: 'reward'},
149
152
  {index:PermissionIndex.reward_lock_guards, name:'Lock Guard', description:'Set Reward guard immutable', module: 'reward'},
153
+ {index:PermissionIndex.reward_claim_repeatably, name:'Claim repeatably', description:'Allow claimming repeatably', module: 'reward'},
154
+ {index:PermissionIndex.reward_allow_claiming, name:'Allow claiming', description:'Allow claiming', module: 'reward'},
150
155
 
151
156
  {index:PermissionIndex.demand, name:'Demand', description:'Launch new Demand', module: 'demand'},
152
157
  {index:PermissionIndex.demand_refund, name:'Refund', description:'Refund from Demand', module: 'demand'},
153
158
  {index:PermissionIndex.demand_expand_time, name:'Expand deadline', description:'Expand Demand deadline', module: 'demand'},
154
- {index:PermissionIndex.demand_set_guard, name:'Guard', description:'Set Demand guard', module: 'demand'},
155
- {index:PermissionIndex.demand_set_description, name:'Description', description:'Set Demand description', module: 'demand'},
159
+ {index:PermissionIndex.demand_guard, name:'Guard', description:'Set Demand guard', module: 'demand'},
160
+ {index:PermissionIndex.demand_description, name:'Description', description:'Set Demand description', module: 'demand'},
156
161
  {index:PermissionIndex.demand_yes, name:'Yes', description:'Pick the Deamand serice', module: 'demand'},
157
162
 
158
163
  {index:PermissionIndex.machine, name: 'Machine', description:'Launch new Machine', module: 'machine'},
159
- {index:PermissionIndex.machine_set_description, name: 'Description', description:'Set Machine description', module: 'machine'},
164
+ {index:PermissionIndex.machine_description, name: 'Description', description:'Set Machine description', module: 'machine'},
160
165
  {index:PermissionIndex.machine_repository, name: 'Repository', description:'Set Machine repository', module: 'machine'},
161
166
  {index:PermissionIndex.machine_clone, name: 'Clone', description:'Clone Machine', module: 'machine'},
162
167
  {index:PermissionIndex.machine_node, name: 'Node', description:'Set Machine nodes', module: 'machine'},
163
- {index:PermissionIndex.machine_set_endpoint, name: 'Endpoint', description:'Set Machine endpoint', module: 'machine'},
168
+ {index:PermissionIndex.machine_endpoint, name: 'Endpoint', description:'Set Machine endpoint', module: 'machine'},
164
169
  {index:PermissionIndex.machine_pause, name: 'Pause', description:'Pause/Unpause Machine', module: 'machine'},
165
170
  {index:PermissionIndex.machine_publish, name: 'Publish', description:'Publish Machine', module: 'machine'},
166
171
 
167
172
  {index:PermissionIndex.progress, name: 'Progress', description:'Launch new Progress', module: 'progress'},
168
- {index:PermissionIndex.progress_set_namedOperator, name: 'Operator', description:'Set Progress operators', module: 'progress'},
173
+ {index:PermissionIndex.progress_namedOperator, name: 'Operator', description:'Set Progress operators', module: 'progress'},
169
174
  {index:PermissionIndex.progress_bind_task, name: 'Bind', description:'Set Progress task', module: 'progress'},
170
- {index:PermissionIndex.progress_set_context_repository, name: 'Repository', description:'Set Progress repository', module: 'progress'},
175
+ {index:PermissionIndex.progress_context_repository, name: 'Repository', description:'Set Progress repository', module: 'progress'},
171
176
  {index:PermissionIndex.progress_unhold, name: 'Unhold', description:'Release Progress holdings', module: 'progress'},
177
+ {index:PermissionIndex.progress_parent, name: 'Parent', description:'Set Progress parent', module: 'progress'},
172
178
  ]
173
179
 
174
180
  export type PermissionIndexType = PermissionIndex | number;
@@ -328,7 +334,7 @@ export class Permission {
328
334
  guards.forEach(({entity_address, index, guard}) => {
329
335
  this.txb.moveCall({
330
336
  target:Protocol.Instance().PermissionFn('guard_set') as FnCallType,
331
- arguments:[ Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure(entity_address, BCS.ADDRESS),
337
+ arguments:[ Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.address(entity_address),
332
338
  this.txb.pure.u64(index), Protocol.TXB_OBJECT(this.txb, guard)]
333
339
  })
334
340
  })
@@ -339,7 +345,7 @@ export class Permission {
339
345
  if (!IsValidAddress(entity_address)) {
340
346
  ERROR(Errors.IsValidAddress, 'entity_address')
341
347
  }
342
- if(!Permission.IsValidPermissionIndex(index)) {
348
+ if(!Permission.IsValidPermissionIndex(index) && !Permission.IsValidUserDefinedIndex(index)) {
343
349
  ERROR(Errors.IsValidPermissionIndex, 'index')
344
350
  }
345
351
 
@@ -369,7 +375,7 @@ export class Permission {
369
375
  this.txb.moveCall({
370
376
  target:Protocol.Instance().PermissionFn('remove_index') as FnCallType,
371
377
  arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.address(entity_address),
372
- this.txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_U64, array_unique(index)))]
378
+ this.txb.pure.vector('u64', array_unique(index))]
373
379
  })
374
380
  }
375
381
  remove_entity(entity_address:string[]) {
@@ -396,7 +402,9 @@ export class Permission {
396
402
  }
397
403
 
398
404
  add_admin(admin:string[]) {
399
- if (!admin || !IsValidArray(admin, IsValidAddress)) {
405
+ if (admin.length === 0) return ;
406
+
407
+ if (!IsValidArray(admin, IsValidAddress)) {
400
408
  ERROR(Errors.IsValidArray)
401
409
  }
402
410
 
@@ -407,7 +415,7 @@ export class Permission {
407
415
  }
408
416
 
409
417
  remove_admin(admin:string[], removeall?:boolean) {
410
- if (!removeall && admin.length === 0) return
418
+ if (!removeall && admin.length === 0) return;
411
419
  if (!IsValidArray(admin, IsValidAddress)) {
412
420
  ERROR(Errors.IsValidArray, 'admin')
413
421
  }
@@ -436,6 +444,8 @@ export class Permission {
436
444
  arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.address(new_owner)]
437
445
  });
438
446
  }
447
+
448
+ // query some permissions for address
439
449
  query_permissions(address_queried:string, permissions:PermissionIndexType[]) {
440
450
  if (!IsValidAddress(address_queried)) {
441
451
  ERROR(Errors.InvalidParam, 'query_permissions');
@@ -447,54 +457,84 @@ export class Permission {
447
457
 
448
458
  this.txb.moveCall({
449
459
  target:Protocol.Instance().PermissionFn('query_permissions') as FnCallType,
450
- arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.address(address_queried), this.txb.pure.vector('u64', permissions)]
460
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.address(address_queried),
461
+ this.txb.pure.vector('u64', permissions)]
462
+ })
463
+ }
464
+
465
+ // query all permissions for address
466
+ query_permissions_all(address_queried:string) {
467
+ if (!IsValidAddress(address_queried)) {
468
+ ERROR(Errors.InvalidParam, 'query_permissions');
469
+ }
470
+
471
+ this.txb.moveCall({
472
+ target:Protocol.Instance().PermissionFn('query_permissions_all') as FnCallType,
473
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.address(address_queried)]
451
474
  })
452
475
  }
453
476
 
454
- QueryPermissions(txb:TransactionBlock, address_queried:string, permissions:PermissionIndexType[], onPermissionAnswer:OnPermissionAnswer, sender?:string) {
455
- this.query_permissions(address_queried, permissions);
456
- Protocol.Client().devInspectTransactionBlock({sender:sender ?? address_queried, transactionBlock:txb}).then((res) => {
477
+ QueryPermissions(permission:string, address_queried:string, permissions:PermissionIndexType[]|'all', onPermissionAnswer:OnPermissionAnswer, sender?:string) {
478
+ //@ be the same txb
479
+ if (permissions === 'all') {
480
+ this.query_permissions_all(address_queried);
481
+ } else {
482
+ this.query_permissions(address_queried, permissions);
483
+ }
484
+
485
+ Protocol.Client().devInspectTransactionBlock({sender:sender ?? address_queried, transactionBlock:this.txb}).then((res) => {
457
486
  if (res.results && res.results[0].returnValues && res.results[0].returnValues.length !== 3 ) {
458
- onPermissionAnswer({who:address_queried});
487
+ onPermissionAnswer({who:address_queried, object:permission});
459
488
  return
460
489
  }
461
-
462
490
  const perm = Bcs.getInstance().de(BCS.U8, Uint8Array.from((res.results as any)[0].returnValues[0][0]));
463
-
464
491
  if (perm === Permission.PERMISSION_ADMIN || perm === Permission.PERMISSION_OWNER_AND_ADMIN) {
465
- onPermissionAnswer({who:address_queried, admin:true, owner:perm%2===1, items:[]})
492
+ onPermissionAnswer({who:address_queried, admin:true, owner:perm%2===1, items:[], object:permission})
466
493
  } else {
467
- const perms = Bcs.getInstance().de('vector<u8>', Uint8Array.from((res.results as any)[0].returnValues[1][0]));
468
- const guards = Bcs.getInstance().de('vector<address>', Uint8Array.from((res.results as any)[0].returnValues[2][0]));
469
- if (perms.length !== permissions.length) {
470
- onPermissionAnswer({who:address_queried});
471
- return
472
- }
473
-
474
- const items: PermissionAnswerItem[] = permissions.map((v, index) => {
475
- const p = perms[index] === Permission.PERMISSION_QUERY_NONE ? false : true;
476
- let g : any = undefined;
477
- if (p && perms[index] < guards.length) {
478
- g = '0x' + guards[perms[index] as number];
494
+ if (permissions === 'all') {
495
+ const perms = Bcs.getInstance().de('vector<u64>', Uint8Array.from((res.results as any)[0].returnValues[1][0]));
496
+ const guards = Bcs.getInstance().de_guards(Uint8Array.from((res.results as any)[0].returnValues[2][0]));
497
+ const items: PermissionAnswerItem[] = [];
498
+ for(let i = 0; i < perms.length; ++i) {
499
+ items.push({query:perms[i], permission:true, guard:guards[i] ? ('0x'+guards[i]) : undefined})
500
+ }
501
+ onPermissionAnswer({who:address_queried, admin:false, owner:perm%2===1, items:items, object:permission});
502
+ } else {
503
+ const perms = Bcs.getInstance().de('vector<u8>', Uint8Array.from((res.results as any)[0].returnValues[1][0]));
504
+ const guards = Bcs.getInstance().de('vector<address>', Uint8Array.from((res.results as any)[0].returnValues[2][0]));
505
+ if (perms.length !== permissions.length) {
506
+ onPermissionAnswer({who:address_queried, object:permission});
507
+ return
479
508
  }
480
- return {query:v, permission:p, guard:g}
481
- })
482
- onPermissionAnswer({who:address_queried, admin:false, owner:perm%2===1, items:items});
509
+
510
+ const items: PermissionAnswerItem[] = (permissions as PermissionIndexType[]).map((v, index) => {
511
+ const p = perms[index] === Permission.PERMISSION_QUERY_NONE ? false : true;
512
+ let g : any = undefined;
513
+ if (p && perms[index] < guards.length) {
514
+ g = '0x' + guards[perms[index] as number];
515
+ }
516
+ return {query:v, permission:p, guard:g}
517
+ })
518
+ onPermissionAnswer({who:address_queried, admin:false, owner:perm%2===1, items:items, object:permission});
519
+ }
483
520
  }
484
521
  }).catch((e) => {
485
522
  console.log(e);
486
- onPermissionAnswer({who:address_queried});
523
+ onPermissionAnswer({who:address_queried, object:permission});
487
524
  })
488
525
  }
489
- static HasPermission(answer:PermissionAnswer|undefined, index:PermissionIndexType) : {has:boolean, guard?:string, owner?:boolean} {
526
+ static HasPermission(answer:PermissionAnswer|undefined, index:PermissionIndexType, bStrict:boolean=false) : {has:boolean, guard?:string, owner?:boolean} | undefined {
490
527
  if (answer) {
491
528
  if (answer.admin) return {has:true, owner:answer.owner}; // admin
492
- let i = answer.items?.find((v)=>v.query === index);
529
+ let i = answer.items?.find((v)=>v.query == index); // index maybe string, so ==
493
530
  if (i) {
494
531
  return {has:i.permission, guard:i.guard, owner:answer.owner};
495
- }
532
+ }
496
533
  }
497
- return {has:false}
534
+ if (bStrict) {
535
+ return {has:false, guard:undefined, owner:answer?.owner}
536
+ }
537
+ return undefined
498
538
  }
499
539
 
500
540
  static MAX_ADMIN_COUNT = 64;
package/src/progress.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { BCS } from '@mysten/bcs';
1
+
2
2
  import { FnCallType, PermissionObject, RepositoryObject, PassportObject, MachineObject,
3
3
  ProgressObject, ProgressAddress, Protocol, ValueType,
4
4
  TxbObject} from './protocol';
@@ -158,7 +158,6 @@ export class Progress {
158
158
  ERROR(Errors.IsValidObjects, 'repository')
159
159
  }
160
160
 
161
-
162
161
  if (passport) {
163
162
  if (repository) {
164
163
  this.txb.moveCall({
@@ -189,8 +188,9 @@ export class Progress {
189
188
  }
190
189
  }
191
190
  unhold(next:ProgressNext, passport?:PassportObject) {
191
+ console.log(next)
192
192
  if (!Progress.IsValidProgressNext(next)) {
193
- ERROR(Errors.InvalidParam, 'next')
193
+ ERROR(Errors.InvalidParam, 'unhold')
194
194
  }
195
195
 
196
196
  if (passport) {
@@ -210,7 +210,6 @@ export class Progress {
210
210
  }
211
211
  }
212
212
  parent_none(passport?:PassportObject) {
213
-
214
213
  if (passport) {
215
214
  this.txb.moveCall({
216
215
  target:Protocol.Instance().ProgressFn('parent_none_with_passport') as FnCallType,
@@ -234,7 +233,6 @@ export class Progress {
234
233
  ERROR(Errors.InvalidParam, 'parent')
235
234
  }
236
235
 
237
-
238
236
  if (passport) {
239
237
  this.txb.moveCall({
240
238
  target:Protocol.Instance().ProgressFn('parent_set_with_passport') as FnCallType,
@@ -259,6 +257,7 @@ export class Progress {
259
257
  }
260
258
 
261
259
  next(next:ProgressNext, deliverables_address?:string, sub_id?:string, passport?:PassportObject) {
260
+ console.log(next)
262
261
  if (!Progress.IsValidProgressNext(next)) {
263
262
  ERROR(Errors.InvalidParam, 'next')
264
263
  }
@@ -268,7 +267,6 @@ export class Progress {
268
267
  if (sub_id && !IsValidAddress(sub_id)) {
269
268
  ERROR(Errors.IsValidAddress, 'sub_id');
270
269
  }
271
-
272
270
 
273
271
  let diliverable = this.txb.pure.option('address', deliverables_address ? deliverables_address : undefined);
274
272
  let sub = this.txb.pure.option('address', sub_id ? sub_id : undefined);
@@ -292,9 +290,8 @@ export class Progress {
292
290
 
293
291
  hold(next:ProgressNext, hold:boolean) {
294
292
  if (!Progress.IsValidProgressNext(next)) {
295
- ERROR(Errors.InvalidParam, 'next')
293
+ ERROR(Errors.InvalidParam, 'hold')
296
294
  }
297
-
298
295
 
299
296
  this.txb.moveCall({
300
297
  target:Protocol.Instance().ProgressFn('hold') as FnCallType,
@@ -302,6 +299,7 @@ export class Progress {
302
299
  this.txb.pure.string(next.forward), this.txb.pure.bool(hold), Protocol.TXB_OBJECT(this.txb, this.permission)],
303
300
  })
304
301
  }
302
+
305
303
  static rpc_de_sessions = (session: any) : Session[] => {
306
304
  let sessions : Session[] = [];
307
305
  session?.fields?.contents?.forEach((v:any) => {
package/src/protocol.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { SuiClient, SuiObjectResponse, SuiObjectDataOptions, SuiTransactionBlockResponseOptions,
2
2
  SuiTransactionBlockResponse, SuiObjectChange } from '@mysten/sui/client';
3
3
  import { Ed25519Keypair } from '@mysten/sui/keypairs/ed25519';
4
- import { BCS, getSuiMoveConfig, toHEX, fromHEX, BcsReader } from '@mysten/bcs';
4
+ import { toHEX, fromHEX, BcsReader } from '@mysten/bcs';
5
5
  import { Transaction as TransactionBlock, Inputs, TransactionResult, TransactionArgument } from '@mysten/sui/transactions';
6
6
  import { capitalize, IsValidAddress, IsValidArray, IsValidU128, IsValidU64, IsValidU8, IsValidUintLarge } from './utils'
7
7
  import { GuardConstant } from './guard';
@@ -191,9 +191,9 @@ export enum ENTRYPOINT {
191
191
  }
192
192
 
193
193
  const TESTNET = {
194
- package: "0xc5bcb215cb4bc861203739b7378199969d4f60f5e8130fa1ebf87987bdee0b6a",
195
- wowok_object: '0xe9fdb9c3ad7aa81ee32d3fc9618d6e69637111253445e864f898d29179d11a4d',
196
- entity_object: '0xe1205f43507c943a82d5a67cb7d2b3b251ff4a80f3b38e815a78291ed53125ce',
194
+ package: "0xdfead784f096e93d025e3e29c4fa48cf5585867e7bcc304c83d3f410f210e4c9",
195
+ wowok_object: '0xe386bb9e01b3528b75f3751ad8a1e418b207ad979fea364087deef5250a73d3f',
196
+ entity_object: '0xbc8be56e8924f7ddcce0ebbc8bd9a2bf1f00d1db9a12e36b9290f009ba305dd9',
197
197
  }
198
198
 
199
199
  const MAINNET = {
@@ -206,6 +206,7 @@ export interface CoinTypeInfo {
206
206
  symbol: string;
207
207
  type: string;
208
208
  decimals: number;
209
+ alias ?: boolean;
209
210
  }
210
211
  export class Protocol {
211
212
  protected network = '';
@@ -320,7 +321,6 @@ export class Protocol {
320
321
  transaction: this.CurrentSession(),
321
322
  signer: keypair,
322
323
  options,
323
-
324
324
  });
325
325
  this.txb = undefined; // reset the txb to undefine
326
326
  return response;
@@ -335,9 +335,9 @@ export class Protocol {
335
335
  COINS_TYPE = () => {
336
336
  switch(this.network) {
337
337
  case ENTRYPOINT.testnet:
338
- return this.CoinTypes_Testnet;
338
+ return this.CoinTypes_Testnet.filter((v)=>v.alias !== true);
339
339
  case ENTRYPOINT.mainnet:
340
- return this.CoinTypes_Mainnet;
340
+ return this.CoinTypes_Mainnet.filter((v)=>v.alias !== true);
341
341
  }; return [];
342
342
  }
343
343
  Update_CoinType = (token_type: string, decimals:number, symbol: string) => {
@@ -364,8 +364,14 @@ export class Protocol {
364
364
  }
365
365
 
366
366
  CoinTypes_Testnet:CoinTypeInfo[] = [
367
- {symbol:'SUI', type:'0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI', decimals:9},
368
- {symbol:'SUI', type:'0x2::sui::SUI', decimals:9},
367
+ {symbol:'SUI', type:'0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI', decimals:9, alias:true},
368
+ {symbol:'SUI', type:'0x2::sui::SUI', decimals:9, },
369
+ {symbol:'WOW', type:TESTNET.package + '::wowok::WOWOK', decimals:9},
370
+ ];
371
+
372
+ CoinTypes_Mainnet:CoinTypeInfo[] = [
373
+ {symbol:'SUI', type:'0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI', decimals:9, alias:true},
374
+ {symbol:'SUI', type:'0x2::sui::SUI', decimals:9, },
369
375
  {symbol:'WOW', type:TESTNET.package + '::wowok::WOWOK', decimals:9},
370
376
  {symbol:'USDT', type:'0xc060006111016b8a020ad5b33834984a437aaa7d3c74c18e09a95d48aceab08c::coin::COIN', decimals:6},
371
377
  {symbol:'USDC', type:'0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf::coin::COIN', decimals:6},
@@ -373,9 +379,6 @@ export class Protocol {
373
379
  {symbol:'WBNB', type:'0xb848cce11ef3a8f62eccea6eb5b35a12c4c2b1ee1af7755d02d7bd6218e8226f::coin::COIN', decimals:8},
374
380
  ];
375
381
 
376
- CoinTypes_Mainnet:CoinTypeInfo[] = [
377
- ];
378
-
379
382
  GetCoinTypeInfo = (token_type: string, handler:(info:CoinTypeInfo)=>void) : CoinTypeInfo | 'loading' => {
380
383
  let r = this.COINS_TYPE().find((v) => v?.type === token_type);
381
384
  if (!r) {
package/src/repository.ts CHANGED
@@ -1,4 +1,3 @@
1
- import { BCS } from '@mysten/bcs';
2
1
  import { Protocol, FnCallType, ValueType, RepositoryValueType, RepositoryAddress, PermissionObject, PassportObject, TxbObject} from './protocol';
3
2
  import { PermissionIndexType, Permission } from './permission'
4
3
  import { Bcs, array_unique, IsValidDesription, IsValidAddress, IsValidArray, IsValidName, ValueTypeConvert} from './utils';
@@ -222,7 +221,7 @@ export class Repository {
222
221
  }
223
222
 
224
223
  policies.forEach((policy) => {
225
- let permission_index = this.txb.pure.option('u64', policy?.permission);
224
+ let permission_index = this.txb.pure.option('u64', policy?.permission ? policy?.permission : undefined);
226
225
  if (passport) {
227
226
  this.txb.moveCall({
228
227
  target:Protocol.Instance().RepositoryFn('policy_add_with_passport') as FnCallType,
@@ -255,14 +254,14 @@ export class Repository {
255
254
  this.txb.moveCall({
256
255
  target:Protocol.Instance().RepositoryFn('policy_remove_with_passport') as FnCallType,
257
256
  arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object),
258
- this.txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, array_unique(policy_keys))),
257
+ this.txb.pure.vector('string', array_unique(policy_keys)),
259
258
  Protocol.TXB_OBJECT(this.txb, this.permission)]
260
259
  })
261
260
  } else {
262
261
  this.txb.moveCall({
263
262
  target:Protocol.Instance().RepositoryFn('policy_remove') as FnCallType,
264
263
  arguments:[Protocol.TXB_OBJECT(this.txb, this.object),
265
- this.txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, array_unique(policy_keys))),
264
+ this.txb.pure.vector('string', array_unique(policy_keys)),
266
265
  Protocol.TXB_OBJECT(this.txb, this.permission)]
267
266
  })
268
267
  }
package/src/resource.ts CHANGED
@@ -1,18 +1,17 @@
1
- import { BCS } from '@mysten/bcs';
2
1
  import { Protocol, FnCallType, TxbObject, ResourceAddress} from './protocol';
3
2
  import { IsValidDesription, IsValidAddress, IsValidName, IsValidArray, } from './utils';
4
3
  import { ERROR, Errors } from './exception';
5
4
  import { type TransactionResult, Transaction as TransactionBlock } from '@mysten/sui/transactions';
6
5
 
7
- export interface Tags {
8
- address: string;
9
- nick: string;
10
- tags: string[];
6
+ export interface Tags { // tag am address
7
+ address: string; // address to tag
8
+ nick: string; // named address
9
+ tags: string[]; // tags for address
11
10
  }
12
11
 
13
- export interface ResourceData {
14
- name: string;
15
- address: string[];
12
+ export interface ResourceData { // personal folder
13
+ name: string; // folder name
14
+ address: string[]; // objects in folder
16
15
  }
17
16
 
18
17
  export class Resource {
package/src/reward.ts CHANGED
@@ -1,9 +1,7 @@
1
1
  import { TransactionArgument, Transaction as TransactionBlock, type TransactionResult, } from '@mysten/sui/transactions';
2
- import { BCS} from '@mysten/bcs';
3
2
  import { FnCallType, GuardObject, PassportObject, PermissionObject, RewardAddress, Protocol, TxbObject, } from './protocol';
4
3
  import { array_unique, IsValidAddress, IsValidArgType, IsValidArray, IsValidDesription, IsValidUintLarge, } from './utils';
5
4
  import { ERROR, Errors } from './exception';
6
- import { Resource } from './resource';
7
5
 
8
6
  export type CoinReward = TransactionResult;
9
7
  export type RewardGuardPortions = {