wowok_agent 0.0.1 → 0.1.3

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
@@ -12,41 +12,40 @@ export interface PermissionQuery {
12
12
  address: string;
13
13
  }
14
14
 
15
- export namespace PERMISSION_QUERY {
16
- /*json: PermissionQuery; return PermissionAnswer */
17
- export const permission_json = async (json:string) : Promise<string> => {
18
- try {
19
- const q : PermissionQuery = JSON.parse(json);
20
- return JSON.stringify({data:await permission(q)});
21
- } catch (e) {
22
- return JSON.stringify({error:e});
23
- }
15
+ /*json: PermissionQuery; return PermissionAnswer */
16
+ export const query_permission_json = async (json:string) : Promise<string> => {
17
+ try {
18
+ const q : PermissionQuery = JSON.parse(json);
19
+ return JSON.stringify({data:await query_permission(q)});
20
+ } catch (e) {
21
+ return JSON.stringify({error:e});
24
22
  }
23
+ }
24
+
25
+ export const query_permission = async (query:PermissionQuery) : Promise<PermissionAnswer> => {
26
+ if (!IsValidAddress(query.permission_object)) {
27
+ ERROR(Errors.IsValidAddress, 'permission.permission_object');
28
+ }/*
29
+ if (!IsValidAddress(query.address)) {
30
+ ERROR(Errors.IsValidAddress, 'permission.address')
31
+ }*/
32
+ const txb = new TransactionBlock();
33
+ const object = Permission.From(txb, query.permission_object);
34
+ object.query_permissions_all(query.address);
25
35
 
26
- export const permission = async (query:PermissionQuery) : Promise<PermissionAnswer> => {
27
- if (!IsValidAddress(query.permission_object)) {
28
- ERROR(Errors.IsValidAddress, 'permission.permission_object');
29
- }/*
30
- if (!IsValidAddress(query.address)) {
31
- ERROR(Errors.IsValidAddress, 'permission.address')
32
- }*/
33
- const txb = new TransactionBlock();
34
- const object = Permission.From(txb, query.permission_object);
35
- object.query_permissions_all(query.address);
36
-
37
- const res = await Protocol.Client().devInspectTransactionBlock({sender:query.address, transactionBlock:txb});
38
- if (res.results && res.results[0].returnValues && res.results[0].returnValues.length !== 2 ) {
39
- ERROR(Errors.Fail, 'permission.retValues')
40
- }
41
-
42
- const perm = Bcs.getInstance().de(BCS.U8, Uint8Array.from((res.results as any)[0].returnValues[0][0]));
43
- if (perm === Permission.PERMISSION_ADMIN || perm === Permission.PERMISSION_OWNER_AND_ADMIN) {
44
- return {who:query.address, admin:true, owner:perm%2===1, items:[], object:query.permission_object}
45
- } else {
46
- const perms = Bcs.getInstance().de_perms(Uint8Array.from((res.results as any)[0].returnValues[1][0]));
47
- return {who:query.address, admin:false, owner:perm%2===1, items:perms.map((v:any)=>{
48
- return {query:v?.index, permission:true, guard:v?.guard}
49
- }), object:query.permission_object};
50
- }
36
+ const res = await Protocol.Client().devInspectTransactionBlock({sender:query.address, transactionBlock:txb});
37
+ if (res.results && res.results[0].returnValues && res.results[0].returnValues.length !== 2 ) {
38
+ ERROR(Errors.Fail, 'permission.retValues')
39
+ }
40
+
41
+ const perm = Bcs.getInstance().de(BCS.U8, Uint8Array.from((res.results as any)[0].returnValues[0][0]));
42
+ if (perm === Permission.PERMISSION_ADMIN || perm === Permission.PERMISSION_OWNER_AND_ADMIN) {
43
+ return {who:query.address, admin:true, owner:perm%2===1, items:[], object:query.permission_object}
44
+ } else {
45
+ const perms = Bcs.getInstance().de_perms(Uint8Array.from((res.results as any)[0].returnValues[1][0]));
46
+ return {who:query.address, admin:false, owner:perm%2===1, items:perms.map((v:any)=>{
47
+ return {query:v?.index, permission:true, guard:v?.guard}
48
+ }), object:query.permission_object};
51
49
  }
52
50
  }
51
+