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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wowok",
3
- "version": "1.2.12",
3
+ "version": "1.3.4",
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/demand.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { type TransactionResult, Transaction as TransactionBlock } from '@mysten/sui/transactions';
2
- import { BCS } from '@mysten/bcs';
3
2
  import { FnCallType, Protocol, PassportObject, PermissionObject, GuardObject, DemandAddress, TxbObject, ResourceObject} from './protocol';
4
3
  import { IsValidDesription, IsValidUintLarge, IsValidAddress, IsValidArgType, } from './utils'
5
4
  import { Errors, ERROR} from './exception'
package/src/entity.ts CHANGED
@@ -1,4 +1,3 @@
1
- import { BCS, encodeStr, getSuiMoveConfig } from '@mysten/bcs';
2
1
  import { Protocol, FnCallType, TxbObject, ResourceAddress, PermissionObject, ResourceObject} from './protocol';
3
2
  import { IsValidDesription, IsValidAddress, IsValidName, isValidHttpUrl, Bcs, } from './utils';
4
3
  import { ERROR, Errors } from './exception';
package/src/exception.ts CHANGED
@@ -9,6 +9,7 @@ export enum Errors {
9
9
  IsValidTokenType = 'invalid token type',
10
10
  IsValidUint = 'invalid uint',
11
11
  IsValidInt = 'invalid int',
12
+ IsValidU64 = 'invalid u64',
12
13
  IsValidPercent = 'invalid percent',
13
14
  IsValidArray = 'invalid array',
14
15
  IsValidObjects = 'invalid objects',
package/src/guard.ts CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
- import { BCS } from '@mysten/bcs';
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
5
  import { IsValidDesription, Bcs, IsValidInt, IsValidAddress, FirstLetterUppercase } from './utils';
package/src/machine.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import { Transaction as TransactionBlock, TransactionObjectArgument, type TransactionResult } from '@mysten/sui/transactions';
2
- import { BCS } from '@mysten/bcs';
3
2
  import { Protocol, FnCallType, PermissionObject, RepositoryObject, PassportObject, MachineObject, MachineAddress, GuardObject, TxbObject} from './protocol';
4
3
  import { IsValidInt, Bcs, array_unique, IsValidArray, IsValidAddress, IsValidName, IsValidName_AllowEmpty,
5
4
  IsValidEndpoint, IsValidDesription,
6
- IsValidUintLarge} from './utils'
5
+ IsValidUintLarge,
6
+ IsValidU64} from './utils'
7
7
  import { Permission, PermissionIndexType } from './permission';
8
8
  import { Errors, ERROR} from './exception'
9
9
  import { ValueType } from './protocol';
@@ -26,6 +26,14 @@ export interface Machine_Node {
26
26
  pairs: Machine_Node_Pair[];
27
27
  }
28
28
 
29
+ export interface QueryGuardParam {
30
+ node: string;
31
+ prior_node: string;
32
+ forward: string;
33
+ txb: TransactionBlock;
34
+ guard: string | null;
35
+ }
36
+ export type OnQueryGuard = (param: QueryGuardParam) => void;
29
37
  export class Machine {
30
38
  protected txb;
31
39
  protected object : TxbObject;
@@ -83,7 +91,7 @@ export class Machine {
83
91
  if (!IsValidName_AllowEmpty(p.prior_node)) { bValid = false; }
84
92
  if (p?.threshold && !IsValidInt(p.threshold)) { bValid = false; }
85
93
  p.forwards.forEach((f) => {
86
- if (!Machine.isValidForward(f)) bValid = false;
94
+ if (Machine.checkValidForward(f) !== '') bValid = false;
87
95
  })
88
96
  })
89
97
  })
@@ -120,21 +128,30 @@ export class Machine {
120
128
 
121
129
  forward(forward:Machine_Forward) : TransactionResult {
122
130
  let weight = forward?.weight ? forward.weight : 1;
123
- let perm = this.txb.pure.option('u64', forward?.permission);
124
- let namedOperator = forward?.namedOperator ? this.txb.pure.string(forward.namedOperator) : this.txb.pure.string('');
125
131
  let f:any;
126
132
 
127
- if (forward?.guard) {
133
+ // namedOperator first.
134
+ if (forward?.namedOperator && IsValidName(forward.namedOperator)) {
135
+ if (forward?.guard) {
136
+ f = this.txb.moveCall({
137
+ target:Protocol.Instance().MachineFn('forward') as FnCallType,
138
+ arguments:[this.txb.pure.string(forward.namedOperator), this.txb.pure.u16(weight), this.txb.object(Protocol.TXB_OBJECT(this.txb, forward.guard))]
139
+ });
140
+ } else {
141
+ f = this.txb.moveCall({
142
+ target:Protocol.Instance().MachineFn('forward2') as FnCallType,
143
+ arguments:[this.txb.pure.string(forward.namedOperator), this.txb.pure.u16(weight)]
144
+ });
145
+ }
146
+ } else if (forward?.permission !== undefined && IsValidU64(forward.permission)) {
128
147
  f = this.txb.moveCall({
129
- target:Protocol.Instance().MachineFn('forward') as FnCallType,
130
- arguments:[namedOperator, this.txb.pure.u16(weight), this.txb.object(Protocol.TXB_OBJECT(this.txb, forward.guard)), perm]
131
- });
148
+ target:Protocol.Instance().MachineFn('forward3') as FnCallType,
149
+ arguments:[this.txb.pure.u64(forward.permission), this.txb.pure.u16(weight)]
150
+ });
132
151
  } else {
133
- f = this.txb.moveCall({
134
- target:Protocol.Instance().MachineFn('forward2') as FnCallType,
135
- arguments:[namedOperator, this.txb.pure.u16(weight), perm]
136
- });
152
+ ERROR(Errors.InvalidParam, 'forward')
137
153
  }
154
+
138
155
  return f
139
156
  }
140
157
 
@@ -206,13 +223,13 @@ export class Machine {
206
223
  if (passport) {
207
224
  this.txb.moveCall({
208
225
  target:Protocol.Instance().MachineFn('node_remove_with_passport') as FnCallType,
209
- arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, nodes_name)),
226
+ arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.vector('string', nodes_name),
210
227
  this.txb.pure.bool(bTransferMyself), Protocol.TXB_OBJECT(this.txb, this.permission)],
211
228
  });
212
229
  } else {
213
230
  this.txb.moveCall({
214
231
  target:Protocol.Instance().MachineFn('node_remove') as FnCallType,
215
- arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, nodes_name)),
232
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.vector('string', nodes_name),
216
233
  this.txb.pure.bool(bTransferMyself), Protocol.TXB_OBJECT(this.txb, this.permission)],
217
234
  });
218
235
  }
@@ -373,10 +390,10 @@ export class Machine {
373
390
  this.permission = new_permission;
374
391
  }
375
392
 
376
- add_forward(node_prior:string, node_name:string, foward: Machine_Forward, threshold?:number, passport?:PassportObject) {
393
+ add_forward(node_prior:string, node_name:string, foward: Machine_Forward, threshold?:number, old_forward_name?:string, passport?:PassportObject) {
377
394
  if (!IsValidName_AllowEmpty(node_prior)) ERROR(Errors.IsValidName_AllowEmpty, 'add_forward');
378
395
  if (!IsValidName(node_name)) ERROR(Errors.IsValidName, 'add_forward');
379
- if (!Machine.isValidForward(foward)) ERROR(Errors.InvalidParam, 'add_forward');
396
+ const err = Machine.checkValidForward(foward); if (err) ERROR(Errors.InvalidParam, err);
380
397
 
381
398
  let n : any;
382
399
  if (passport) {
@@ -397,6 +414,14 @@ export class Machine {
397
414
  target:Protocol.Instance().MachineFn('forward_add') as FnCallType,
398
415
  arguments:[n, this.txb.pure.string(node_prior), this.txb.pure.string(foward.name), t, f],
399
416
  })
417
+
418
+ if (old_forward_name && old_forward_name !== foward.name) {
419
+ this.txb.moveCall({
420
+ target:Protocol.Instance().MachineFn('forward_remove') as FnCallType,
421
+ arguments:[n, this.txb.pure.string(node_prior), this.txb.pure.string(old_forward_name)],
422
+ })
423
+ }
424
+ this.add_node2([n], passport);
400
425
  }
401
426
 
402
427
  remove_forward(node_prior:string, node_name:string, foward_name: string, passport?:PassportObject) {
@@ -420,6 +445,7 @@ export class Machine {
420
445
  target:Protocol.Instance().MachineFn('forward_remove') as FnCallType,
421
446
  arguments:[n, this.txb.pure.string(node_prior), this.txb.pure.string(foward_name)],
422
447
  })
448
+ this.add_node2([n], passport);
423
449
  }
424
450
 
425
451
  static rpc_de_nodes(fields: any) : Machine_Node[] {
@@ -458,15 +484,37 @@ export class Machine {
458
484
  return ret;
459
485
  }
460
486
 
461
- static isValidForward(forward:Machine_Forward) {
462
- if (!IsValidName(forward.name)) return false
463
- if (forward?.namedOperator && !IsValidName_AllowEmpty(forward?.namedOperator)) return false;
464
- if (forward?.permission && !Permission.IsValidPermissionIndex(forward?.permission)) return false;
465
- if (!forward?.permission && !forward?.namedOperator) return false;
466
- if (forward?.weight && !IsValidUintLarge(forward.weight)) return false;
467
- return true
487
+ static checkValidForward(forward:Machine_Forward) : string {
488
+ if (!IsValidName(forward.name)) return 'Forward name invalid'
489
+ if (forward?.namedOperator && !IsValidName_AllowEmpty(forward?.namedOperator)) return 'Progress Operator invalid';
490
+ if (forward?.permission && !Permission.IsValidPermissionIndex(forward?.permission)) return 'Permission index invalid';
491
+ if (!forward?.permission && !forward?.namedOperator) return 'Both Permission index and Progress Operator empty';
492
+ if (forward?.weight && !IsValidUintLarge(forward.weight)) return 'Weight invalid';
493
+ return ''
468
494
  }
469
495
 
496
+
497
+ QueryForwardGuard(sender:string, node:string, prior_node:string, forward:string, onGuard:OnQueryGuard) {
498
+ if (!node || !forward) { // prior_node maybe ''
499
+ ERROR(Errors.InvalidParam, 'QueryForwardGuard');
500
+ return ;
501
+ }
502
+
503
+ this.txb.moveCall({
504
+ target:Protocol.Instance().MachineFn('query_guard') as FnCallType,
505
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(node),
506
+ this.txb.pure.string(prior_node), this.txb.pure.string(forward)],
507
+ });
508
+
509
+ Protocol.Client().devInspectTransactionBlock({sender:sender, transactionBlock:this.txb}).then((res) => {
510
+ if (res.results?.length === 1 && res.results[0].returnValues?.length === 1) {
511
+ const guard = Bcs.getInstance().de('Option<address>', Uint8Array.from(res.results[0].returnValues[0][0]));
512
+ onGuard({node:node, prior_node:prior_node, forward:forward, guard:guard?.some?('0x'+guard?.some):'', txb:this.txb});
513
+ }
514
+ }).catch(e=>{
515
+ console.log(e);
516
+ })
517
+ }
470
518
  static INITIAL_NODE_NAME = '';
471
519
  /* static NODE_NAME_RESERVED = 'origin';
472
520
  static IsNodeNameReserved = (name:string) => {
package/src/passport.ts CHANGED
@@ -3,10 +3,8 @@ import { SuiObjectResponse } from '@mysten/sui/client';
3
3
  import { FnCallType, GuardObject, Protocol, ContextType, OperatorType, Data_Type,
4
4
  ValueType, SER_VALUE, IsValidOperatorType } from './protocol';
5
5
  import { parse_object_type, array_unique, Bcs, ulebDecode, IsValidAddress, IsValidArray, OPTION_NONE, readOption, readOptionString } from './utils';
6
- import { BCS, BcsReader } from '@mysten/bcs';
7
6
  import { ERROR, Errors } from './exception';
8
7
  import { Guard } from './guard';
9
- import { SUI_CLOCK_OBJECT_ID } from '@mysten/sui/utils';
10
8
 
11
9
  export type Guard_Query_Object = {
12
10
  target: FnCallType, // object fnCall
@@ -480,11 +478,15 @@ export class GuardParser {
480
478
 
481
479
  let guard_list = array_unique(guards);
482
480
  const protocol = Protocol.Instance();
483
-
481
+
484
482
  if (onGuardInfo) {
485
483
  protocol.Query_Raw(guard_list)
486
- .then((res) => { onGuardInfo(GuardParser.Parse_Guard_Helper(guards, res)); })
487
- .catch((e) => { onGuardInfo(undefined); })
484
+ .then((res) => {
485
+ onGuardInfo(GuardParser.Parse_Guard_Helper(guards, res));
486
+ }).catch((e) => {
487
+ console.log(e);
488
+ onGuardInfo(undefined);
489
+ })
488
490
  } else {
489
491
  const res = await protocol.Query_Raw(guard_list);
490
492
  return GuardParser.Parse_Guard_Helper(guards, res);
@@ -640,7 +642,6 @@ export class GuardParser {
640
642
  objects.push(this.get_object(g.id, q, fill));
641
643
  })
642
644
  })
643
-
644
645
  if (onPassportQueryReady) {
645
646
  Protocol.Instance().Query_Raw(array_unique(objects), {showType:true}).then((res) => {
646
647
  onPassportQueryReady(this.done_helper(res));
@@ -769,6 +770,51 @@ export class Passport {
769
770
  arguments: [ this.passport ]
770
771
  });
771
772
  }
773
+
774
+ query_result(sender:string, handleResult:OnQueryPassportResult) {
775
+ this.txb.moveCall({
776
+ target: Protocol.Instance().PassportFn('query_result') as FnCallType,
777
+ arguments: [ this.passport ]
778
+ });
779
+
780
+ Protocol.Client().devInspectTransactionBlock({sender:sender, transactionBlock:this.txb}).then((res) => {
781
+ const r = Passport.ResolveQueryRes(this.txb, res);
782
+ if (r) handleResult(r);
783
+ }).catch(e=>{
784
+ console.log(e);
785
+ })
786
+ }
787
+
788
+ query_result_async = async (sender:string) : Promise<QueryPassportResult | undefined> => {
789
+ this.txb.moveCall({
790
+ target: Protocol.Instance().PassportFn('query_result') as FnCallType,
791
+ arguments: [ this.passport ]
792
+ });
793
+
794
+ const res = await Protocol.Client().devInspectTransactionBlock({sender:sender, transactionBlock:this.txb});
795
+ return Passport.ResolveQueryRes(this.txb, res);
796
+ }
797
+
798
+ private static ResolveQueryRes(txb:TransactionBlock, res:any) : QueryPassportResult | undefined {
799
+ for (let i = 0; i < res.results?.length; ++ i) {
800
+ const v = res.results[i];
801
+ if (v?.returnValues && v.returnValues.length === 2 &&
802
+ v.returnValues[0][1] === 'bool' && v.returnValues[1][1] === 'vector<address>') { // (bool, vector<address>)
803
+ const result = Bcs.getInstance().de('bool', Uint8Array.from(v.returnValues[0][0]));
804
+ const guards = Bcs.getInstance().de('vector<address>', Uint8Array.from(v.returnValues[1][0])).map((v:string)=>'0x'+v);
805
+ return {txb:txb, result:result, guards:guards}
806
+ }
807
+ }
808
+ return undefined
809
+ }
772
810
  }
773
811
 
812
+ export interface QueryPassportResult {
813
+ txb: TransactionBlock;
814
+ result: boolean;
815
+ guards: string[];
816
+ }
817
+
818
+ export type OnQueryPassportResult = (result:QueryPassportResult) => void;
819
+
774
820