wowok 1.2.10 → 1.2.11

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.10",
3
+ "version": "1.2.11",
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/entity.ts CHANGED
@@ -97,7 +97,7 @@ export class Entity {
97
97
  }
98
98
 
99
99
  query_ent(address_queried:string) {
100
- if (!address_queried) {
100
+ if (!IsValidAddress(address_queried)) {
101
101
  ERROR(Errors.InvalidParam, 'query_ent');
102
102
  }
103
103
 
package/src/passport.ts CHANGED
@@ -751,7 +751,6 @@ export class Passport {
751
751
  typeArguments: q.types,
752
752
  })
753
753
  })
754
-
755
754
  txb.moveCall({
756
755
  target: protocol.PassportFn('passport_verify') as FnCallType,
757
756
  arguments: [ this.passport, txb.object(Protocol.CLOCK_OBJECT) ]
package/src/permission.ts CHANGED
@@ -3,6 +3,7 @@ import { FnCallType, TxbObject, PermissionObject, PermissionAddress, GuardObject
3
3
  import { array_unique, IsValidAddress, IsValidArray, IsValidDesription, IsValidUintLarge, Bcs, IsValidName} from './utils';
4
4
  import { ERROR, Errors } from './exception';
5
5
  import { ValueType } from './protocol';
6
+ import { Passport } from './passport';
6
7
 
7
8
  export enum PermissionIndex {
8
9
  repository = 100,
@@ -85,6 +86,19 @@ export interface PermissionInfoType {
85
86
  guard?: string;
86
87
  }
87
88
 
89
+ export interface PermissionAnswer {
90
+ who: string;
91
+ owner?: boolean;
92
+ admin?: boolean;
93
+ items?: PermissionAnswerItem[]; // items === undefined, while errors
94
+ }
95
+ export interface PermissionAnswerItem {
96
+ query: PermissionIndexType;
97
+ permission: boolean;
98
+ guard?: string;
99
+ }
100
+ export type OnPermissionAnswer = (answer: PermissionAnswer) => void;
101
+
88
102
  export const PermissionInfo : PermissionInfoType[] = [
89
103
  {index:PermissionIndex.repository, name:'Repository', description:'Launch new Repository', module: 'repository'},
90
104
  {index:PermissionIndex.repository_set_description_set, name:'Description', description:'Set Repository description', module: 'repository'},
@@ -436,11 +450,81 @@ export class Permission {
436
450
  arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(new_owner, BCS.ADDRESS)]
437
451
  });
438
452
  }
453
+ query_permissions(address_queried:string, permissions:PermissionIndexType[]) {
454
+ if (!IsValidAddress(address_queried)) {
455
+ ERROR(Errors.InvalidParam, 'query_permissions');
456
+ }
457
+
458
+ if (permissions.length === 0 || permissions.length > Permission.MAX_QUERY_COUNT) {
459
+ ERROR(Errors.InvalidParam, 'permissions count');
460
+ }
461
+
462
+ const txb = this.protocol.CurrentSession();
463
+ txb.moveCall({
464
+ target:this.protocol.PermissionFn('query_permissions') as FnCallType,
465
+ arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(address_queried, BCS.ADDRESS), txb.pure(permissions, 'vector<u64>')]
466
+ })
467
+ }
468
+
469
+ QueryPermissions(address_queried:string, permissions:PermissionIndexType[], onPermissionAnswer:OnPermissionAnswer, sender?:string) {
470
+ this.query_permissions(address_queried, permissions);
471
+ Protocol.Client().devInspectTransactionBlock({sender:sender ?? address_queried,
472
+ transactionBlock:this.protocol.CurrentSession()}).then((res) => {
473
+ if (res.results && res.results[0].returnValues && res.results[0].returnValues.length !== 3 ) {
474
+ onPermissionAnswer({who:address_queried});
475
+ return
476
+ }
477
+
478
+ const perm = Bcs.getInstance().de(BCS.U8, Uint8Array.from((res.results as any)[0].returnValues[0][0]));
479
+
480
+ if (perm === Permission.PERMISSION_ADMIN || perm === Permission.PERMISSION_OWNER_AND_ADMIN) {
481
+ onPermissionAnswer({who:address_queried, admin:true, owner:perm%2===1, items:[]})
482
+ } else {
483
+ const perms = Bcs.getInstance().de('vector<u8>', Uint8Array.from((res.results as any)[0].returnValues[1][0]));
484
+ const guards = Bcs.getInstance().de('vector<address>', Uint8Array.from((res.results as any)[0].returnValues[2][0]));
485
+ if (perms.length !== permissions.length) {
486
+ onPermissionAnswer({who:address_queried});
487
+ return
488
+ }
489
+
490
+ const items: PermissionAnswerItem[] = permissions.map((v, index) => {
491
+ const p = perms[index] === Permission.PERMISSION_QUERY_NONE ? false : true;
492
+ let g : any = undefined;
493
+ if (p && perms[index] < guards.length) {
494
+ g = '0x' + guards[perms[index] as number];
495
+ }
496
+ return {query:v, permission:p, guard:g}
497
+ })
498
+ onPermissionAnswer({who:address_queried, admin:false, owner:perm%2===1, items:items});
499
+ }
500
+ }).catch((e) => {
501
+ console.log(e);
502
+ onPermissionAnswer({who:address_queried});
503
+ })
504
+ }
505
+ static HasPermission(answer:PermissionAnswer|undefined, index:PermissionIndexType) : {has:boolean, guard?:string, owner?:boolean} {
506
+ if (answer) {
507
+ if (answer.admin) return {has:true, owner:answer.owner}; // admin
508
+ let i = answer.items?.find((v)=>v.query === index);
509
+ if (i) {
510
+ return {has:i.permission, guard:i.guard, owner:answer.owner};
511
+ }
512
+ }
513
+ return {has:false}
514
+ }
439
515
 
440
516
  static MAX_ADMIN_COUNT = 64;
441
517
  static MAX_ENTITY_COUNT = 2000;
442
518
  static MAX_PERMISSION_INDEX_COUNT = 200;
443
519
  static MAX_PERSONAL_PERMISSION_COUNT = 200;
520
+ static MAX_QUERY_COUNT = 250; //
521
+ static PERMISSION_QUERY_NONE = 255;
522
+ static PERMISSION_QUERY_HAS = 254;
523
+ static PERMISSION_NORMAL = 0;
524
+ static PERMISSION_OWNER = 1;
525
+ static PERMISSION_ADMIN = 2;
526
+ static PERMISSION_OWNER_AND_ADMIN = 3;
527
+
444
528
  static IsValidUserDefinedIndex = (index:number) => {
445
529
  return index >= PermissionIndex.user_defined_start && IsValidUintLarge(index)
446
530
  }
package/src/protocol.ts CHANGED
@@ -191,9 +191,9 @@ export enum ENTRYPOINT {
191
191
  }
192
192
 
193
193
  const TESTNET = {
194
- package: "0x8ba9f90c9a0e5f2199a92fdc5ea255ac9df5471289cfe40a87ac90f25d93dd5b",
195
- wowok_object: '0x9d33a57a09f3ff73ba51afe6ed2e671e7d78b771e34b0a1ba66e52264e34b3fd',
196
- entity_object: '0xb759e1e5569f1f8d5ae30efb6efec0a639c5ef70a7c7abcc012919cf5dae33af',
194
+ package: "0xc5bcb215cb4bc861203739b7378199969d4f60f5e8130fa1ebf87987bdee0b6a",
195
+ wowok_object: '0xe9fdb9c3ad7aa81ee32d3fc9618d6e69637111253445e864f898d29179d11a4d',
196
+ entity_object: '0xe1205f43507c943a82d5a67cb7d2b3b251ff4a80f3b38e815a78291ed53125ce',
197
197
  }
198
198
 
199
199
  const MAINNET = {
package/src/utils.ts CHANGED
@@ -241,7 +241,11 @@ export class Bcs {
241
241
  return new Uint8Array();
242
242
  }
243
243
 
244
- de(type:ValueType, data:Uint8Array | any) : any {
244
+ de(type:ValueType | string, data:Uint8Array | any) : any {
245
+ if (typeof(type) === 'string') {
246
+ return this.bcs.de(type, data);
247
+ }
248
+
245
249
  switch(type) {
246
250
  case ValueType.TYPE_BOOL:
247
251
  return this.bcs.de(BCS.BOOL, data);