wowok 1.5.40 → 1.5.41

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.5.40",
3
+ "version": "1.5.41",
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/guard.ts CHANGED
@@ -1,6 +1,6 @@
1
1
 
2
2
 
3
- import { Protocol, LogicsInfo, GuardAddress, FnCallType, Data_Type, MODULES, ContextType, ValueType, OperatorType, TxbObject, GuardObject} from './protocol';
3
+ import { Protocol, LogicsInfo, GuardAddress, FnCallType, Data_Type, MODULES, ContextType, ValueType, OperatorType, TxbObject, GuardObject, IsValidOperatorType} from './protocol';
4
4
  import { concatenate, array_equal, ValueTypeConvert } from './utils';
5
5
  import { IsValidDesription, Bcs, IsValidInt, IsValidAddress, FirstLetterUppercase, insertAtHead } from './utils';
6
6
  import { ERROR, Errors } from './exception';
@@ -587,11 +587,11 @@ export class GuardMaker {
587
587
  return this;
588
588
  }
589
589
 
590
- add_logic(type:OperatorType, logic_count:number=2) : GuardMaker {
590
+ add_logic(type:OperatorType, logic_count?:number) : GuardMaker {
591
591
  var e:any = LogicsInfo.find((v:any) => v[0] === type);
592
592
  if (e) { e=e[1] }
593
593
 
594
- let splice_len = 2;
594
+ let splice_len = 2; let cur:any;
595
595
  let ret = ValueType.TYPE_BOOL;
596
596
  switch (type) {
597
597
  case OperatorType.TYPE_LOGIC_AS_U256_GREATER:
@@ -599,26 +599,28 @@ export class GuardMaker {
599
599
  case OperatorType.TYPE_LOGIC_AS_U256_LESSER:
600
600
  case OperatorType.TYPE_LOGIC_AS_U256_LESSER_EQUAL:
601
601
  case OperatorType.TYPE_LOGIC_AS_U256_EQUAL:
602
- if (this.type_validator.length < splice_len) { ERROR(Errors.Fail, 'type_validator.length:' + e) }
603
- if (!GuardMaker.match_u256(this.type_validator[this.type_validator.length - 1])) { ERROR(Errors.Fail, 'type_validator check:'+e) }
604
- if (!GuardMaker.match_u256(this.type_validator[this.type_validator.length - 2])) { ERROR(Errors.Fail, 'type_validator check:'+e) }
602
+ if (!logic_count || logic_count < 2) ERROR(Errors.Fail, 'logic param invalid:'+e);
603
+ splice_len = logic_count!;
604
+ if (this.type_validator.length < splice_len) { ERROR(Errors.Fail, 'type_validator.length:'+e) }
605
+ for (let i = 1; i <= splice_len; ++i) {
606
+ if (!GuardMaker.match_u256(this.type_validator[this.type_validator.length - i])) { ERROR(Errors.Fail, 'type_validator check:'+e) }
607
+ }
605
608
  break;
606
609
  case OperatorType.TYPE_LOGIC_EQUAL:
607
- if (this.type_validator.length < splice_len) { ERROR(Errors.Fail, 'type_validator.length:' + e) }
608
- if (GuardMaker.match_u256(this.type_validator[this.type_validator.length - 1]) &&
609
- GuardMaker.match_u256(this.type_validator[this.type_validator.length - 2])) {
610
- break;
611
- } else if (this.type_validator[this.type_validator.length - 1] === this.type_validator[this.type_validator.length - 2]) {
612
- break;
613
- } else {
614
- ERROR(Errors.Fail, 'type_validator check:' + e) ;
610
+ if (!logic_count || logic_count < 2) ERROR(Errors.Fail, 'logic param invalid:'+e);
611
+ splice_len = logic_count!;
612
+ if (this.type_validator.length < splice_len) { ERROR(Errors.Fail, 'type_validator.length:'+e) }
613
+ cur = this.type_validator[this.type_validator.length - 1];
614
+ for (let i = 2; i <= splice_len; ++i) {
615
+ if (this.type_validator[this.type_validator.length - i] !== cur) ERROR(Errors.Fail, 'type_validator check:' + e) ;
615
616
  }
616
617
  break;
617
618
  case OperatorType.TYPE_LOGIC_HAS_SUBSTRING:
618
- if (this.type_validator.length < splice_len) { ERROR(Errors.Fail, 'type_validator.length:' + e) }
619
- if (this.type_validator[this.type_validator.length - 1] !== ValueType.TYPE_STRING ||
620
- this.type_validator[this.type_validator.length - 2] !== ValueType.TYPE_STRING) {
621
- ERROR(Errors.Fail, 'type_validator check:' + e) ;
619
+ if (!logic_count || logic_count < 2) ERROR(Errors.Fail, 'logic param invalid:'+e);
620
+ splice_len = logic_count!;
621
+ if (this.type_validator.length < splice_len) { ERROR(Errors.Fail, 'type_validator.length:'+e) }
622
+ for (let i = 1; i <= splice_len; ++i) {
623
+ if (this.type_validator[this.type_validator.length - i] !== ValueType.TYPE_STRING) ERROR(Errors.Fail, 'type_validator check:' + e) ;
622
624
  }
623
625
  break;
624
626
  case OperatorType.TYPE_LOGIC_NOT:
@@ -642,9 +644,12 @@ export class GuardMaker {
642
644
  case OperatorType.TYPE_NUMBER_MULTIPLY:
643
645
  case OperatorType.TYPE_NUMBER_SUBTRACT:
644
646
  case OperatorType.TYPE_NUMBER_MOD:
647
+ if (!logic_count || logic_count < 2) ERROR(Errors.Fail, 'logic param invalid:'+e);
648
+ splice_len = logic_count!;
645
649
  if (this.type_validator.length < splice_len) { ERROR(Errors.Fail, 'type_validator.length:'+e) }
646
- if (!GuardMaker.IsNumberType(this.type_validator[this.type_validator.length -1])) { ERROR(Errors.Fail, 'type_validator check:'+e) }
647
- if (!GuardMaker.IsNumberType(this.type_validator[this.type_validator.length -2])) { ERROR(Errors.Fail, 'type_validator check:'+e) }
650
+ for (let i = 1; i <= splice_len; ++i) {
651
+ if(!GuardMaker.match_u256(this.type_validator[this.type_validator.length -1])) { ERROR(Errors.Fail, 'type_validator check:'+e) }
652
+ }
648
653
  ret = ValueType.TYPE_U256;
649
654
  break;
650
655
  default:
@@ -652,7 +657,7 @@ export class GuardMaker {
652
657
  }
653
658
 
654
659
  this.data.push(Bcs.getInstance().ser(ValueType.TYPE_U8, type)); // TYPE
655
- if (type === OperatorType.TYPE_LOGIC_AND || type === OperatorType.TYPE_LOGIC_OR) {
660
+ if (GuardMaker.is_multi_input_op(type)) {
656
661
  this.data.push((Bcs.getInstance().ser(ValueType.TYPE_U8, logic_count))); //@ logics
657
662
  }
658
663
  this.type_validator.splice(this.type_validator.length - splice_len); // delete type stack
@@ -660,10 +665,6 @@ export class GuardMaker {
660
665
  return this;
661
666
  }
662
667
 
663
- static IsNumberType(type:Data_Type) : boolean {
664
- return (type === ValueType.TYPE_U8 || type === ValueType.TYPE_U64 || type === ValueType.TYPE_U128 || type === ValueType.TYPE_U256)
665
- }
666
-
667
668
  hasIdentifier(id:number) : boolean {
668
669
  return this.constant.has(id)
669
670
  }
@@ -720,6 +721,18 @@ export class GuardMaker {
720
721
  static match_u256(type:number) : boolean {
721
722
  return (type == ValueType.TYPE_U8 || type == ValueType.TYPE_U64 || type == ValueType.TYPE_U128 || type == ValueType.TYPE_U256);
722
723
  }
724
+ static is_multi_input_op(type:number) : boolean {
725
+ return (type === OperatorType.TYPE_LOGIC_AS_U256_GREATER ||
726
+ type === OperatorType.TYPE_LOGIC_AS_U256_GREATER_EQUAL ||
727
+ type === OperatorType.TYPE_LOGIC_AS_U256_LESSER ||
728
+ type === OperatorType.TYPE_LOGIC_AS_U256_LESSER ||
729
+ type === OperatorType.TYPE_LOGIC_AS_U256_LESSER_EQUAL ||
730
+ type === OperatorType.TYPE_LOGIC_AS_U256_EQUAL ||
731
+ type === OperatorType.TYPE_LOGIC_EQUAL ||
732
+ type === OperatorType.TYPE_LOGIC_HAS_SUBSTRING ||
733
+ type === OperatorType.TYPE_LOGIC_AND ||
734
+ type === OperatorType.TYPE_LOGIC_OR)
735
+ }
723
736
  }
724
737
 
725
738
 
package/src/passport.ts CHANGED
@@ -4,7 +4,7 @@ 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, insertAtHead, readOption, readOptionString } from './utils';
6
6
  import { ERROR, Errors } from './exception';
7
- import { Guard } from './guard';
7
+ import { Guard, GuardMaker } from './guard';
8
8
 
9
9
  export type Guard_Query_Object = {
10
10
  target: FnCallType, // object fnCall
@@ -137,41 +137,33 @@ export class GuardParser {
137
137
  current.ret_type = ValueType.TYPE_U256;
138
138
  }
139
139
 
140
- if (stack.length < 2) ERROR(Errors.Fail, 'ResolveData: ' + current.type);
141
- for (let i = 0; i < 2; ++i) {
142
- let p = stack.pop() as DeGuardData;
143
- if (!p.ret_type) ERROR(Errors.Fail, 'ResolveData: ' + current.type + ' INVALID param type');
144
- if (p.ret_type != ValueType.TYPE_U8 && p.ret_type != ValueType.TYPE_U64 &&
145
- p.ret_type != ValueType.TYPE_U128 && p.ret_type != ValueType.TYPE_U256) {
146
- ERROR(Errors.Fail, 'ResolveData: ' + current.type + ' INVALID param type');
147
- };
140
+ if (stack.length < current.value || current.value < 2) ERROR(Errors.Fail, 'ResolveData: ' + current.type);
141
+ for (let i = 0; i < current.value; ++i) {
142
+ var p = stack.pop() as DeGuardData;
143
+ if (!p.ret_type || !GuardMaker.match_u256(p.ret_type)) ERROR(Errors.Fail, 'ResolveData: ' + current.type + ' INVALID param type');
148
144
  current.child.push(p);
149
145
  }
150
146
  stack.push(current);
151
- return;
147
+ return
152
148
  case OperatorType.TYPE_LOGIC_EQUAL:
153
149
  current.ret_type = ValueType.TYPE_BOOL;
154
- if (stack.length < 2) ERROR(Errors.Fail, 'ResolveData: ' + current.type);
155
- var p1 = stack.pop() as DeGuardData; var p2 = stack.pop() as DeGuardData;
156
- //console.log(p1); console.log(p2)
157
- if (!p1.ret_type || !p2.ret_type) ERROR(Errors.Fail, 'ResolveData: ' + current.type + ' INVALID param type');
158
- if (p1.ret_type != p2.ret_type) ERROR(Errors.Fail, 'ResolveData: ' + current.type + ' param type not match');
159
-
160
- current.child.push(p1);
161
- current.child.push(p2);
150
+ if (stack.length < current.value || current.value < 2) ERROR(Errors.Fail, 'ResolveData: ' + current.type);
151
+ var p0 = stack.pop() as DeGuardData;
152
+ for (let i = 1; i < current.value; ++i) {
153
+ var p = stack.pop() as DeGuardData;
154
+ if (!p.ret_type || (p.ret_type != p0.ret_type)) ERROR(Errors.Fail, 'ResolveData: ' + current.type + ' INVALID param type');
155
+ current.child.push(p);
156
+ }
162
157
  stack.push(current);
163
- return;
158
+ return
164
159
  case OperatorType.TYPE_LOGIC_HAS_SUBSTRING:
165
160
  current.ret_type = ValueType.TYPE_BOOL;
166
- if (stack.length < 2) ERROR(Errors.Fail, 'ResolveData: ' + current.type);
167
- var p1 = stack.pop() as DeGuardData; var p2 = stack.pop() as DeGuardData;
168
- if (!p1.ret_type || !p2.ret_type) ERROR(Errors.Fail, 'ResolveData: ' + current.type + ' INVALID param type');
169
- if (p1.ret_type != ValueType.TYPE_STRING || p2.ret_type != ValueType.TYPE_STRING) {
170
- ERROR(Errors.Fail, 'ResolveData: ' + current.type + ' param type not match');
161
+ if (stack.length < current.value || current.value < 2) ERROR(Errors.Fail, 'ResolveData: ' + current.type);
162
+ for (let i = 0; i < current.value; ++i) {
163
+ var p = stack.pop() as DeGuardData;
164
+ if (!p.ret_type || (p.ret_type != ValueType.TYPE_STRING)) ERROR(Errors.Fail, 'ResolveData: ' + current.type + ' INVALID param type');
165
+ current.child.push(p);
171
166
  }
172
-
173
- current.child.push(p1);
174
- current.child.push(p2);
175
167
  stack.push(current);
176
168
  return
177
169
  case OperatorType.TYPE_LOGIC_AND:
@@ -370,6 +362,9 @@ export class GuardParser {
370
362
  case ContextType.TYPE_SIGNER:
371
363
  case ContextType.TYPE_CLOCK:
372
364
  case ContextType.TYPE_GUARD:
365
+ case OperatorType.TYPE_LOGIC_ALWAYS_TRUE:
366
+ case OperatorType.TYPE_LOGIC_NOT:
367
+ break;
373
368
  case OperatorType.TYPE_LOGIC_AS_U256_GREATER:
374
369
  case OperatorType.TYPE_LOGIC_AS_U256_GREATER_EQUAL:
375
370
  case OperatorType.TYPE_LOGIC_AS_U256_LESSER:
@@ -377,14 +372,11 @@ export class GuardParser {
377
372
  case OperatorType.TYPE_LOGIC_AS_U256_EQUAL:
378
373
  case OperatorType.TYPE_LOGIC_EQUAL:
379
374
  case OperatorType.TYPE_LOGIC_HAS_SUBSTRING:
380
- case OperatorType.TYPE_LOGIC_ALWAYS_TRUE:
381
- case OperatorType.TYPE_LOGIC_NOT:
382
375
  case OperatorType.TYPE_NUMBER_ADD:
383
376
  case OperatorType.TYPE_NUMBER_DEVIDE:
384
377
  case OperatorType.TYPE_NUMBER_MOD:
385
378
  case OperatorType.TYPE_NUMBER_MULTIPLY:
386
379
  case OperatorType.TYPE_NUMBER_SUBTRACT:
387
- break;
388
380
  case OperatorType.TYPE_LOGIC_AND: //@ with logics count
389
381
  case OperatorType.TYPE_LOGIC_OR:
390
382
  value = arr.shift()! as number;
package/src/protocol.ts CHANGED
@@ -94,17 +94,17 @@ export enum OperatorType {
94
94
  }
95
95
 
96
96
  export const LogicsInfo = [
97
- [OperatorType.TYPE_LOGIC_AS_U256_GREATER, 'Unsigned Integer >'],
98
- [OperatorType.TYPE_LOGIC_AS_U256_GREATER_EQUAL, 'Unsigned Integer >='],
99
- [OperatorType.TYPE_LOGIC_AS_U256_LESSER, 'Unsigned Integer <'],
100
- [OperatorType.TYPE_LOGIC_AS_U256_LESSER_EQUAL, 'Unsigned Integer <='],
101
- [OperatorType.TYPE_LOGIC_AS_U256_EQUAL, 'Unsigned Integer ='],
102
- [OperatorType.TYPE_LOGIC_EQUAL, 'Equal'],
103
- [OperatorType.TYPE_LOGIC_HAS_SUBSTRING, 'Sub String'],
104
- [OperatorType.TYPE_LOGIC_ALWAYS_TRUE, 'Always True'],
105
- [OperatorType.TYPE_LOGIC_NOT, 'Not'],
106
- [OperatorType.TYPE_LOGIC_AND, 'And'],
107
- [OperatorType.TYPE_LOGIC_OR, 'Or'],
97
+ [OperatorType.TYPE_LOGIC_AS_U256_GREATER, 'Unsigned Integer >', 'The first item > anything that follows'],
98
+ [OperatorType.TYPE_LOGIC_AS_U256_GREATER_EQUAL, 'Unsigned Integer >=', 'The first item >= anything that follows'],
99
+ [OperatorType.TYPE_LOGIC_AS_U256_LESSER, 'Unsigned Integer <', 'The first item < anything that follows'],
100
+ [OperatorType.TYPE_LOGIC_AS_U256_LESSER_EQUAL, 'Unsigned Integer <=', 'The first item <= anything that follows'],
101
+ [OperatorType.TYPE_LOGIC_AS_U256_EQUAL, 'Unsigned Integer =', 'The first item = anything that follows'],
102
+ [OperatorType.TYPE_LOGIC_EQUAL, 'Equal', 'Data and type are exactly equal for all items'],
103
+ [OperatorType.TYPE_LOGIC_HAS_SUBSTRING, 'Has Sub String', 'The first item contains anything that follows'],
104
+ [OperatorType.TYPE_LOGIC_ALWAYS_TRUE, 'Always True', 'Always True'],
105
+ [OperatorType.TYPE_LOGIC_NOT, 'Not', 'Not operation'],
106
+ [OperatorType.TYPE_LOGIC_AND, 'And', 'All Items And operations'],
107
+ [OperatorType.TYPE_LOGIC_OR, 'Or', 'All Items Or operations'],
108
108
  ];
109
109
 
110
110
  export enum ValueType {
@@ -165,6 +165,7 @@ export enum ContextType {
165
165
  TYPE_SIGNER = 60,
166
166
  TYPE_CLOCK = 61,
167
167
  TYPE_GUARD = 62, // current guard address
168
+ TYPE_STACK_ADDRESS = 63, // object queried from current stack top
168
169
  TYPE_CONSTANT = 80,
169
170
  }
170
171
  interface ValueTypeString {
@@ -220,13 +221,13 @@ const TESTNET = {
220
221
  }
221
222
  */
222
223
  const TESTNET = {
223
- wowok: "0xfa33358cf5f883038d124855567972241cd7036381fbc150a2208ab0e5939621",
224
- wowok_origin:'0xfa33358cf5f883038d124855567972241cd7036381fbc150a2208ab0e5939621' ,
224
+ wowok: "0x95541edbae1f167f8679df2bbee57eafaf09cf81230094ffc196e78a0df200e4",
225
+ wowok_origin:'0x95541edbae1f167f8679df2bbee57eafaf09cf81230094ffc196e78a0df200e4' ,
225
226
  base: '0x7efcdab72af2351e5915e34ad2ac8d4ea7f4f408e08138d3498af35a362db782',
226
227
  base_origin: '0x7efcdab72af2351e5915e34ad2ac8d4ea7f4f408e08138d3498af35a362db782',
227
228
 
228
- wowok_object: '0x459ed2fd2ad4aac9fd417d50584fae607ee557508dcb9b9f55722e0d18ed81ab',
229
- entity_object: '0xfeb95d277598ebb8a358bfda3c62a32d7622de9af7ec3219e67c5749e020f12b',
229
+ wowok_object: '0x33917cc62420ba654a0d4a0325e4d31778b12b4f736812d7427904e9911abad3',
230
+ entity_object: '0xf6f8ee1a3bc19288ac1067f77eae6e72bd1887b35a0c7996635eee975d758901',
230
231
  treasury_cap:'0x538cf8f32d59f58c0450a3a97c1eeed3096f4ce63e07e0bdf343a5cc1464887c',
231
232
  }
232
233
  const MAINNET = {