wowok_agent 0.1.12 → 0.1.14

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_agent",
3
- "version": "0.1.12",
3
+ "version": "0.1.14",
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/account.ts CHANGED
@@ -15,8 +15,8 @@ export interface AccountData_Show {
15
15
  address: string;
16
16
  }
17
17
 
18
- const Account_FileName = 'wowok.dat';
19
- const Account_Key = 'wowok-data-v1';
18
+ const Account_FileName = 'wowok.acc.dat';
19
+ const Account_Key = 'wowok-acc-v1';
20
20
 
21
21
  export class Account {
22
22
  constructor(storage: 'File' | 'Explorer' = 'File') {
@@ -32,64 +32,60 @@ export class Account {
32
32
 
33
33
  private storage: 'File' | 'Explorer' = 'File';
34
34
 
35
- private _add(buffer:string | null | undefined, name:string, bDefault?: boolean) : AccountData[] {
35
+ private _add(buffer:string | null | undefined, name:string, bDefault?: boolean) : AccountData[] | undefined {
36
36
  var data : AccountData[] | undefined;
37
37
  var key = '0x'+toHEX(decodeSuiPrivateKey(Ed25519Keypair.generate().getSecretKey()).secretKey);
38
38
 
39
39
  try {
40
40
  if (buffer) {
41
- data = JSON.parse(buffer) as AccountData[];
42
- }
43
- } catch(e) { console.log(e) }
44
-
45
- if (data) {
46
- const f = data.find(v => v.name === name);
47
- if (f) {
48
- f.default = bDefault;
49
- } else {
50
- if (bDefault) {
51
- data.forEach(v => v.default = false)
41
+ data = JSON.parse(buffer) as AccountData[];
42
+ if (data) {
43
+ const f = data.find(v => v.name === name);
44
+ if (f) {
45
+ f.default = bDefault;
46
+ } else {
47
+ if (bDefault) {
48
+ data.forEach(v => v.default = false)
49
+ }
50
+ data.push({name:name, key:key, default:bDefault})
51
+ }
52
+ return data
52
53
  }
53
- data.push({name:name, key:key, default:bDefault})
54
54
  }
55
- } else {
56
- data = [{name:name, key:key, default:bDefault}];
57
- }
58
- return data
55
+ } catch(e) { /*console.log(e)*/ }
56
+ return [{name:name, key:key, default:bDefault}]
59
57
  }
60
58
 
61
59
  private _default(buffer:string | null | undefined) : AccountData | undefined {
62
60
  var data : AccountData[] | undefined;
63
61
  try {
64
62
  if (buffer) {
65
- data = JSON.parse(buffer) as AccountData[];
63
+ data = JSON.parse(buffer) as AccountData[];
64
+ if (data) {
65
+ const f = data.find(v => v.default);
66
+ if (f) {
67
+ return f
68
+ }
69
+ }
66
70
  }
67
- } catch(e) { console.log(e) }
68
-
69
- if (data) {
70
- const f = data.find(v => v.default);
71
- if (f) {
72
- return f
73
- }
74
- }
71
+ } catch(e) { /*console.log(e)*/ }
75
72
  }
76
73
  private _get(buffer:string | null | undefined, name?:string, bNotFoundReturnDefault?:boolean) : AccountData | undefined {
77
74
  var data : AccountData[] | undefined;
78
75
  try {
79
76
  if (buffer) {
80
- data = JSON.parse(buffer) as AccountData[];
81
- }
82
- } catch(e) { console.log(e) }
83
-
84
- if (data) {
85
- const f = data.find(v => v.name === name);
86
- if (f) {
87
- return f
88
- }
89
- if (bNotFoundReturnDefault) {
90
- return data.find(v => v.default)
77
+ data = JSON.parse(buffer) as AccountData[];
78
+ if (data) {
79
+ const f = data.find(v => v.name === name);
80
+ if (f) {
81
+ return f
82
+ }
83
+ if (bNotFoundReturnDefault) {
84
+ return data.find(v => v.default)
85
+ }
86
+ }
91
87
  }
92
- }
88
+ } catch(e) { /*console.log(e)*/ }
93
89
  }
94
90
  private _rename(buffer:string | null | undefined, oldName:string, newName:string, bSwapIfExisted:boolean=true) : AccountData[] | undefined {
95
91
  var data : AccountData[] | undefined;
@@ -97,25 +93,24 @@ export class Account {
97
93
  if (buffer) {
98
94
  data = JSON.parse(buffer) as AccountData[];
99
95
  }
100
- } catch(e) { console.log(e) }
101
96
 
102
- if (data) {
103
- const f1 = data.find(v => v.name === oldName);
104
- if (!f1) return undefined;
105
-
106
- const f2 = data.find(v => v.name === newName);
107
- if (f2) {
108
- if (bSwapIfExisted) {
97
+ if (data) {
98
+ const f1 = data.find(v => v.name === oldName);
99
+ if (!f1) return undefined;
100
+
101
+ const f2 = data.find(v => v.name === newName);
102
+ if (f2) {
103
+ if (bSwapIfExisted) {
104
+ f1.name = newName;
105
+ f2.name = oldName;
106
+ return data
107
+ }
108
+ } else {
109
109
  f1.name = newName;
110
- f2.name = oldName;
111
- return data
112
- }
113
- } else {
114
- f1.name = newName;
115
- return data;
116
- }
117
- }
118
- return undefined
110
+ return data;
111
+ }
112
+ }
113
+ } catch(e) { /*console.log(e)*/ }
119
114
  }
120
115
 
121
116
  set_storage(storage: 'File' | 'Explorer' = 'File') {
@@ -134,7 +129,7 @@ export class Account {
134
129
  const data = this._add(localStorage.getItem(Account_Key), name, bDefault);
135
130
  localStorage.setItem(Account_Key, JSON.stringify(data))
136
131
  }
137
- } catch (e) { console.log(e) }
132
+ } catch (e) { /*console.log(e)*/ }
138
133
  }
139
134
  default() : AccountData | undefined {
140
135
  try {
@@ -144,7 +139,7 @@ export class Account {
144
139
  } else if (this.storage === 'Explorer') {
145
140
  return this._default(localStorage.getItem(Account_Key));
146
141
  }
147
- } catch (e) { console.log(e) }
142
+ } catch (e) { /*console.log(e)*/ }
148
143
  }
149
144
  get(name?: string, bNotFoundReturnDefault:boolean=true) : AccountData | undefined {
150
145
  try {
@@ -154,7 +149,7 @@ export class Account {
154
149
  } else if (this.storage === 'Explorer') {
155
150
  return this._get(localStorage.getItem(Account_Key), name, bNotFoundReturnDefault);
156
151
  }
157
- } catch (e) { console.log(e) }
152
+ } catch (e) { /*console.log(e)*/ }
158
153
  }
159
154
  rename(oldName:string, newName:string, bSwapIfExisted:boolean=true) : boolean {
160
155
  var res : AccountData[] | undefined;
@@ -167,7 +162,7 @@ export class Account {
167
162
  res = this._rename(localStorage.getItem(Account_Key), oldName, newName, bSwapIfExisted);
168
163
  if (res) localStorage.setItem(Account_Key, JSON.stringify(res));
169
164
  }
170
- } catch (e) { console.log(e) }
165
+ } catch (e) { /*console.log(e)*/ }
171
166
  return res ? true : false
172
167
  }
173
168
 
@@ -204,16 +199,15 @@ export class Account {
204
199
  return {name:v.name, default:v?.default, address:Ed25519Keypair.fromSecretKey(fromHEX(v.key)).getPublicKey().toSuiAddress()}
205
200
  })
206
201
  }
207
- } catch (e) { console.log(e) }
202
+ } catch (e) { /*console.log(e)*/ }
208
203
  return []
209
204
  }
210
205
 
211
- faucet(name?:string) {
206
+ async faucet(name?:string) {
212
207
  const address = this.get_address(name, true);
213
208
  if (address) {
214
- requestSuiFromFaucetV0({host:getFaucetHost('testnet'), recipient:address}).catch(e => {
215
- console.log(e)
216
- requestSuiFromFaucetV1({host:getFaucetHost('testnet'), recipient:address}).catch(e => console.log(e));
209
+ await requestSuiFromFaucetV0({host:getFaucetHost('testnet'), recipient:address}).catch(e => {
210
+ //console.log(e)
217
211
  })
218
212
  }
219
213
  }
@@ -1,27 +1,27 @@
1
- import { TransactionBlock, IsValidArgType, Resource, ResourceObject, } from 'wowok';
2
- import { PassportObject, IsValidAddress, Errors, ERROR, Permission, PermissionIndex, PermissionIndexType, Treasury,
3
- Arbitration, Dispute, Feedback, Vote, VotingGuard, WithdrawFee, WitnessFill
1
+ import { TransactionBlock, IsValidArgType, PassportObject, IsValidAddress, Errors, ERROR, Permission, PermissionIndex,
2
+ PermissionIndexType, Treasury, Arbitration, Dispute, Feedback, Vote, VotingGuard, WithdrawFee,
4
3
  } from 'wowok';
5
4
  import { query_objects, ObjectArbitration, } from '../objects';
6
- import { CallBase, CallResult, AddressMark, Namedbject} from "./base";
5
+ import { CallBase, CallResult, Namedbject} from "./base";
7
6
 
7
+ /// The execution priority is determined by the order in which the object attributes are arranged
8
8
  export interface CallArbitration_Data {
9
+ type_parameter: string;
9
10
  object?: {address:string} | {namedNew: Namedbject}; // undefined or {named_new...} for creating a new object
10
11
  permission?: {address:string} | {namedNew: Namedbject, description?:string};
11
- type_parameter: string;
12
- permission_new?: string;
13
12
  description?: string;
14
- bPaused?: boolean;
15
13
  endpoint?: string;
16
14
  fee?: string;
17
15
  fee_treasury?: {address:string} | {namedNew: Namedbject, description?:string};
18
- usage_guard?: string;
19
- voting_guard?: {op:'add' | 'set'; data:VotingGuard[]} | {op:'remove', guards:string[]} | {op:'removeall'};
20
16
  arb_new?: {data: Dispute; guard?:string | 'fetch'; namedNew?: Namedbject}; // dispute an order, and a new Arb launched.
21
17
  arb_withdraw_fee?: {arb:string; data:WithdrawFee};
22
18
  arb_vote?: Vote;
23
19
  arb_arbitration?: Feedback;
20
+ usage_guard?: string;
21
+ voting_guard?: {op:'add' | 'set'; data:VotingGuard[]} | {op:'remove', guards:string[]} | {op:'removeall'};
22
+ bPaused?: boolean;
24
23
  }
24
+
25
25
  export class CallArbitration extends CallBase {
26
26
  data: CallArbitration_Data;
27
27
  constructor (data: CallArbitration_Data) {
@@ -44,9 +44,6 @@ export class CallArbitration extends CallBase {
44
44
  if (!this.data?.object) {
45
45
  perms.push(PermissionIndex.arbitration)
46
46
  }
47
- if (this.data?.permission_new !== undefined) {
48
- checkOwner = true;
49
- }
50
47
  if (this.data?.description !== undefined && object_address) {
51
48
  perms.push(PermissionIndex.arbitration_description)
52
49
  }
@@ -155,9 +152,6 @@ export class CallArbitration extends CallBase {
155
152
  if (this.data?.arb_withdraw_fee !== undefined) {
156
153
  obj?.withdraw_fee(this.data.arb_withdraw_fee.arb, this.data.arb_withdraw_fee.data, passport)
157
154
  }
158
- if (this.data?.permission_new !== undefined) {
159
- obj?.change_permission(this.data.permission_new);
160
- }
161
155
  if (this.data?.voting_guard !== undefined) {
162
156
  switch (this.data.voting_guard.op) {
163
157
  case 'add':
package/src/call/base.ts CHANGED
@@ -71,7 +71,7 @@ export class CallBase {
71
71
  return await this.sign_and_commit(txb, param.account);
72
72
  }
73
73
  } else {
74
- ERROR(Errors.Fail, 'guard finish_passport')
74
+ ERROR(Errors.Fail, 'guard verify')
75
75
  }
76
76
  }
77
77
  }
@@ -5,18 +5,18 @@ import { query_objects, ObjectDemand } from '../objects';
5
5
  import { CallBase, CallResult, Namedbject } from "./base";
6
6
  import { Account } from '../account';
7
7
 
8
+ /// The execution priority is determined by the order in which the object attributes are arranged
8
9
  export interface CallDemand_Data {
10
+ type_parameter: string;
9
11
  object?: {address:string} | {namedNew: Namedbject}; // undefined or {named_new...} for creating a new object
10
12
  permission?: {address:string} | {namedNew: Namedbject, description?:string};
11
- type_parameter: string;
12
- guard?: {address:string; service_id_in_guard?:number};
13
13
  description?: string;
14
14
  time_expire?: {op: 'duration'; minutes:number} | {op:'set'; time:number};
15
- bounty?: {op:'add'; object:{address:string}|{balance:string|number}} | {op:'refund'} | {op:'reward'; service:string};
15
+ bounty?: {op:'add'; object:{address:string}|{balance:string|number}} | {op:'reward'; service:string} | {op:'refund'} ;
16
16
  present?: {service: string | number; recommend_words:string; service_pay_type:string, guard?:string | 'fetch'}; // guard is the present guard of Demand
17
- reward?: string; // rerward the service
18
- refund?: boolean;
17
+ guard?: {address:string; service_id_in_guard?:number};
19
18
  }
19
+
20
20
  export class CallDemand extends CallBase {
21
21
  data: CallDemand_Data;
22
22
  constructor(data: CallDemand_Data) {
@@ -46,10 +46,10 @@ export class CallDemand extends CallBase {
46
46
  if (this.data?.guard !== undefined) {
47
47
  perms.push(PermissionIndex.demand_guard)
48
48
  }
49
- if (this.data?.reward !== undefined) {
49
+ if (this.data?.bounty?.op === 'reward') {
50
50
  perms.push(PermissionIndex.demand_yes)
51
51
  }
52
- if (this.data?.refund) {
52
+ if (this.data?.bounty?.op === 'refund') {
53
53
  perms.push(PermissionIndex.demand_refund)
54
54
  }
55
55
  if (this.data?.present?.guard !== undefined) {
@@ -121,11 +121,11 @@ export class CallDemand extends CallBase {
121
121
  const r = await Account.Instance().get_coin_object(txb, (this.data.bounty.object as any)?.balance, account, this.data.type_parameter);
122
122
  if (r) obj.deposit(r)
123
123
  }
124
- } else if (this.data.bounty.op === 'refund') {
125
- obj?.refund(passport);
126
124
  } else if (this.data.bounty.op === 'reward') {
127
125
  obj?.yes(this.data.bounty.service, passport);
128
- }
126
+ } else if (this.data.bounty.op === 'refund') {
127
+ obj?.refund(passport);
128
+ }
129
129
  }
130
130
  if (this.data?.present !== undefined) {
131
131
  //@ demand guard and its passport, if set
package/src/call/guard.ts CHANGED
@@ -22,8 +22,7 @@ export type GuardNode = { identifier: number; } // Data from GuardConst
22
22
  | {logic: OperatorType.TYPE_LOGIC_AS_U256_GREATER | OperatorType.TYPE_LOGIC_AS_U256_GREATER_EQUAL
23
23
  | OperatorType.TYPE_LOGIC_AS_U256_LESSER | OperatorType.TYPE_LOGIC_AS_U256_LESSER_EQUAL
24
24
  | OperatorType.TYPE_LOGIC_AS_U256_EQUAL | OperatorType.TYPE_LOGIC_EQUAL | OperatorType.TYPE_LOGIC_HAS_SUBSTRING
25
- | OperatorType.TYPE_LOGIC_ALWAYS_TRUE | OperatorType.TYPE_LOGIC_NOT
26
- | OperatorType.TYPE_LOGIC_AND | OperatorType.TYPE_LOGIC_OR; parameters: GuardNode[];}
25
+ | OperatorType.TYPE_LOGIC_NOT | OperatorType.TYPE_LOGIC_AND | OperatorType.TYPE_LOGIC_OR; parameters: GuardNode[];}
27
26
  | {calc: OperatorType.TYPE_NUMBER_ADD | OperatorType.TYPE_NUMBER_DEVIDE | OperatorType.TYPE_NUMBER_MOD
28
27
  | OperatorType.TYPE_NUMBER_MULTIPLY | OperatorType.TYPE_NUMBER_SUBTRACT; parameters: GuardNode[];}
29
28
  | {value_type: ValueType; value:any; } // Data
@@ -149,10 +148,6 @@ const buildNode = (guard_node:GuardNode, type_required:ValueType | 'number' | 'v
149
148
  } else if (node?.logic !== undefined) {
150
149
  checkType(ValueType.TYPE_BOOL, type_required, node); // bool
151
150
  switch (node?.logic) {
152
- case OperatorType.TYPE_LOGIC_ALWAYS_TRUE:
153
- if (node.parameters.length !== 0) ERROR(Errors.InvalidParam, 'node logic parameters length must be 0'+ JSON.stringify(node));
154
- output.push(Bcs.getInstance().ser(ValueType.TYPE_U8, node.logic)); // TYPE
155
- break;
156
151
  case OperatorType.TYPE_LOGIC_AND:
157
152
  case OperatorType.TYPE_LOGIC_OR:
158
153
  if (node.parameters.length < 2) ERROR(Errors.InvalidParam, 'node logic parameters length must >= 2'+ JSON.stringify(node));
@@ -1,33 +1,31 @@
1
- import { PassportObject, IsValidAddress, Errors, ERROR, Permission, PermissionIndex, TransactionBlock,
1
+ import { PassportObject, IsValidAddress, Errors, ERROR, Permission, PermissionIndex, TransactionBlock, TxbAddress,
2
2
  PermissionIndexType, Machine, Machine_Forward, Machine_Node, Deliverable, ParentProgress, Progress, ProgressNext,
3
- TxbAddress,
4
- Resource,
5
- ResourceObject,
6
3
  } from 'wowok';
7
4
  import { CallBase, CallResult, Namedbject } from "./base";
8
5
  import { Account } from '../account';
9
6
 
7
+ /// The execution priority is determined by the order in which the object attributes are arranged
10
8
  export interface CallMachine_Data {
11
9
  object?: {address:string} | {namedNew: Namedbject}; // undefined or {named_new...} for creating a new object
12
10
  permission?: {address:string} | {namedNew: Namedbject, description?:string};
13
- bPaused?: boolean;
14
- bPublished?: boolean;
15
- consensus_repository?: {op:'set' | 'add' | 'remove' ; repositories:string[]} | {op:'removeall'};
16
11
  description?: string;
17
12
  endpoint?: string;
18
- clone_new?: {namedNew: Namedbject/*, description?:string*/};
13
+ consensus_repository?: {op:'set' | 'add' | 'remove' ; repositories:string[]} | {op:'removeall'};
19
14
  nodes?: {op: 'add'; data: Machine_Node[]} | {op: 'remove'; names: string[], bTransferMyself?:boolean}
20
- | {op:'rename node'; data:{old:string; new:string}[]} | {op:'add from myself'; addresses: string[]}
21
- | {op:'remove pair'; pairs: {prior_node_name:string; node_name:string}[]}
22
- | {op:'add forward'; data: {prior_node_name:string; node_name:string; forward:Machine_Forward; threshold?:number; old_need_remove?:string}[]}
23
- | {op:'remove forward'; data:{prior_node_name:string; node_name:string; forward_name:string}[]}
15
+ | {op:'rename node'; data:{old:string; new:string}[]} | {op:'add from myself'; addresses: string[]}
16
+ | {op:'remove pair'; pairs: {prior_node_name:string; node_name:string}[]}
17
+ | {op:'add forward'; data: {prior_node_name:string; node_name:string; forward:Machine_Forward; threshold?:number; old_need_remove?:string}[]}
18
+ | {op:'remove forward'; data:{prior_node_name:string; node_name:string; forward_name:string}[]}
19
+ bPublished?: boolean;
24
20
  progress_new?: {task_address?:string; namedNew?: Namedbject};
25
21
  progress_context_repository?: {progress:string; repository:string};
22
+ progress_namedOperator?: {progress:string; data:{name:string, operator:string[]}[]};
26
23
  progress_parent?: {progress:string, parent?:ParentProgress};
27
24
  progress_task?: {progress:string; task:string};
28
- progress_namedOperator?: {progress:string; data:{name:string, operator:string[]}[]};
29
25
  progress_hold?: {progress:string; data:ProgressNext; bHold:boolean; adminUnhold?:boolean};
30
26
  progress_next?: {progress:string; data:ProgressNext; deliverable:Deliverable; guard?:string | 'fetch'};
27
+ bPaused?: boolean;
28
+ clone_new?: {namedNew: Namedbject/*, description?:string*/};
31
29
  }
32
30
  export class CallMachine extends CallBase { //@ todo self-owned node operate
33
31
  data: CallMachine_Data;
@@ -48,24 +46,18 @@ export class CallMachine extends CallBase { //@ todo self-owned node operate
48
46
  if (this.data?.description !== undefined && object_address) {
49
47
  perms.push(PermissionIndex.machine_description)
50
48
  }
51
- if (this.data?.bPaused !== undefined) {
52
- perms.push(PermissionIndex.machine_pause)
53
- }
54
- if (this.data?.bPublished) { // publish is an irreversible one-time operation
55
- perms.push(PermissionIndex.machine_publish)
56
- }
57
49
  if (this.data?.endpoint !== undefined && object_address) {
58
50
  perms.push(PermissionIndex.machine_endpoint)
59
51
  }
60
52
  if (this.data?.consensus_repository !== undefined) {
61
53
  perms.push(PermissionIndex.machine_repository)
62
54
  }
63
- if (this.data?.clone_new !== undefined) {
64
- perms.push(PermissionIndex.machine_clone)
65
- }
66
55
  if (this.data?.nodes !== undefined) {
67
56
  perms.push(PermissionIndex.machine_node)
68
57
  }
58
+ if (this.data?.bPublished) { // publish is an irreversible one-time operation
59
+ perms.push(PermissionIndex.machine_publish)
60
+ }
69
61
  if (this.data?.progress_new !== undefined) {
70
62
  perms.push(PermissionIndex.progress)
71
63
  }
@@ -86,6 +78,9 @@ export class CallMachine extends CallBase { //@ todo self-owned node operate
86
78
  perms.push(PermissionIndex.progress_unhold)
87
79
  }
88
80
  }
81
+ if (this.data?.bPaused !== undefined) {
82
+ perms.push(PermissionIndex.machine_pause)
83
+ }
89
84
  if (this.data?.progress_next?.guard !== undefined) {
90
85
  if (IsValidAddress(this.data?.progress_next?.guard)) {
91
86
  guards.push(this.data?.progress_next?.guard)
@@ -170,6 +165,9 @@ export class CallMachine extends CallBase { //@ todo self-owned node operate
170
165
  break;
171
166
  }
172
167
  }
168
+ if (this.data?.bPublished ) {
169
+ obj?.publish(passport)
170
+ }
173
171
  if (this.data?.progress_new !== undefined) {
174
172
  const addr = Progress?.New(txb, obj?.get_object(), permission??this.data?.permission, this.data?.progress_new.task_address, passport).launch();
175
173
  if (addr) {
@@ -207,9 +205,6 @@ export class CallMachine extends CallBase { //@ todo self-owned node operate
207
205
  if (this.data?.bPaused !== undefined) {
208
206
  obj?.pause(this.data.bPaused, passport)
209
207
  }
210
- if (this.data?.bPublished ) {
211
- obj?.publish(passport)
212
- }
213
208
  if (this.data?.clone_new !== undefined && obj) {
214
209
  await this.new_with_mark(txb, obj?.clone(true, passport) as TxbAddress, (this.data?.clone_new as any)?.namedNew, account);
215
210
  }
@@ -3,15 +3,16 @@ import { PassportObject, IsValidAddress, Errors, ERROR, Permission, Permission_E
3
3
  PermissionIndexType, TransactionBlock
4
4
  } from 'wowok';
5
5
 
6
+ /// The execution priority is determined by the order in which the object attributes are arranged
6
7
  export interface CallPermission_Data {
7
8
  object?: {address:string} | {namedNew: Namedbject}; // undefined or {named_new...} for creating a new object
8
- builder?: string;
9
- admin?: {op:'add' | 'remove' | 'set', address:string[]};
10
9
  description?: string;
10
+ admin?: {op:'add' | 'remove' | 'set', address:string[]};
11
+ biz_permission?: {op:'add'; data: BizPermission[]} | {op:'remove'; permissions: PermissionIndexType[]};
11
12
  permission?: {op:'add entity'; entities:Permission_Entity[]} | {op:'add permission'; permissions:Permission_Index[]}
12
13
  | {op:'remove entity'; addresses:string[]} | {op:'remove permission'; address:string; index:PermissionIndexType[]}
13
14
  | {op:'transfer permission', from_address: string; to_address: string};
14
- biz_permission?: {op:'add'; data: BizPermission[]} | {op:'remove'; permissions: PermissionIndexType[]};
15
+ builder?: string;
15
16
  }
16
17
  export class CallPermission extends CallBase {
17
18
  data: CallPermission_Data;
@@ -49,6 +50,23 @@ export class CallPermission extends CallBase {
49
50
  }
50
51
 
51
52
  if (obj) {
53
+ if (this.data?.description !== undefined && this.data.object) {
54
+ obj?.set_description(this.data.description)
55
+ }
56
+ if (this.data?.admin !== undefined) {
57
+ switch(this.data.admin.op) {
58
+ case 'add':
59
+ obj?.add_admin(this.data.admin.address);
60
+ break;
61
+ case 'remove':
62
+ obj?.remove_admin(this.data.admin.address);
63
+ break;
64
+ case 'set':
65
+ obj?.remove_admin([], true);
66
+ obj?.add_admin(this.data.admin.address);
67
+ break
68
+ }
69
+ }
52
70
  if (this.data?.biz_permission !== undefined) { // High priority operate
53
71
  switch(this.data.biz_permission.op) {
54
72
  case 'add':
@@ -63,9 +81,6 @@ export class CallPermission extends CallBase {
63
81
  break;
64
82
  }
65
83
  }
66
- if (this.data?.description !== undefined && this.data.object) {
67
- obj?.set_description(this.data.description)
68
- }
69
84
  if (this.data?.permission !== undefined) {
70
85
  switch (this.data.permission.op) {
71
86
  case 'add entity':
@@ -85,20 +100,6 @@ export class CallPermission extends CallBase {
85
100
  break;
86
101
  }
87
102
  }
88
- if (this.data?.admin !== undefined) {
89
- switch(this.data.admin.op) {
90
- case 'add':
91
- obj?.add_admin(this.data.admin.address);
92
- break;
93
- case 'remove':
94
- obj?.remove_admin(this.data.admin.address);
95
- break;
96
- case 'set':
97
- obj?.remove_admin([], true);
98
- obj?.add_admin(this.data.admin.address);
99
- break
100
- }
101
- }
102
103
  if (this.data?.builder !== undefined ) {
103
104
  obj?.change_owner(this.data.builder);
104
105
  }
@@ -2,6 +2,7 @@ import { ResourceObject, TransactionBlock } from 'wowok';
2
2
  import { PassportObject, IsValidAddress, Errors, ERROR, Entity, Entity_Info, TagName, Resource} from 'wowok';
3
3
  import { CallBase, CallResult, Namedbject } from "./base";
4
4
 
5
+ /// The execution priority is determined by the order in which the object attributes are arranged
5
6
  export interface CallPersonal_Data {
6
7
  object?: {address:string} | {namedNew: Namedbject}; // undefined or {named_new...} for creating a new object
7
8
  information?: Entity_Info;
@@ -5,12 +5,13 @@ import { PassportObject, IsValidAddress, Errors, ERROR, Permission, PermissionIn
5
5
  } from 'wowok';
6
6
  import { CallBase, CallResult, Namedbject} from "./base";
7
7
 
8
+ /// The execution priority is determined by the order in which the object attributes are arranged
8
9
  export interface CallRepository_Data {
9
10
  object?: {address:string} | {namedNew: Namedbject}; // undefined or {named_new...} for creating a new object
10
11
  permission?: {address:string} | {namedNew: Namedbject, description?:string};
11
12
  description?: string;
12
- mode?: Repository_Policy_Mode; // default: 'Relax' (POLICY_MODE_FREE)
13
13
  reference?: {op:'set' | 'add' | 'remove' ; addresses:string[]} | {op:'removeall'};
14
+ mode?: Repository_Policy_Mode; // default: 'Relax' (POLICY_MODE_FREE)
14
15
  policy?: {op:'add' | 'set'; data:Repository_Policy[]} | {op:'remove'; data:string[]} | {op:'removeall'} | {op:'rename'; data:{old:string; new:string}[]};
15
16
  data?: {op:'add', data: Repository_Policy_Data | Repository_Policy_Data2} | {op:'remove'; data: Repository_Policy_Data_Remove};
16
17
  }
@@ -89,19 +90,8 @@ export class CallRepository extends CallBase {
89
90
  break;
90
91
  }
91
92
  }
92
- if (this.data?.data !== undefined) {
93
- switch(this.data.data.op) {
94
- case 'add':
95
- if ((this.data.data?.data as any)?.key !== undefined) {
96
- obj?.add_data(this.data.data.data as Repository_Policy_Data);
97
- } else if ((this.data.data?.data as any)?.address !== undefined) {
98
- obj?.add_data2(this.data.data.data as Repository_Policy_Data2);
99
- }
100
- break;
101
- case 'remove':
102
- obj?.remove(this.data.data.data.address, this.data.data.data.key);
103
- break;
104
- }
93
+ if (this.data?.mode !== undefined && object_address) { //@ priority??
94
+ obj?.set_policy_mode(this.data.mode, passport)
105
95
  }
106
96
  if (this.data?.policy !== undefined) {
107
97
  switch(this.data.policy.op) {
@@ -125,9 +115,21 @@ export class CallRepository extends CallBase {
125
115
  break;
126
116
  }
127
117
  }
128
- if (this.data?.mode !== undefined && object_address) { //@ priority??
129
- obj?.set_policy_mode(this.data.mode, passport)
118
+ if (this.data?.data !== undefined) {
119
+ switch(this.data.data.op) {
120
+ case 'add':
121
+ if ((this.data.data?.data as any)?.key !== undefined) {
122
+ obj?.add_data(this.data.data.data as Repository_Policy_Data);
123
+ } else if ((this.data.data?.data as any)?.address !== undefined) {
124
+ obj?.add_data2(this.data.data.data as Repository_Policy_Data2);
125
+ }
126
+ break;
127
+ case 'remove':
128
+ obj?.remove(this.data.data.data.address, this.data.data.data.key);
129
+ break;
130
+ }
130
131
  }
132
+
131
133
  if (permission) {
132
134
  await this.new_with_mark(txb, permission.launch(), (this.data?.permission as any)?.namedNew, account);
133
135
  }
@@ -1,43 +1,44 @@
1
- import { TransactionBlock, CallResponse, IsValidArgType, TxbAddress, TagName, Resource, ResourceObject} from 'wowok';
2
- import { PassportObject, IsValidAddress, Errors, ERROR, Permission, PermissionIndex,
3
- PermissionIndexType, BuyRequiredEnum, Customer_RequiredInfo, DicountDispatch, Service, Service_Buy,
4
- Service_Guard_Percent, Service_Sale, WithdrawPayee, Treasury, WitnessFill
1
+ import { TransactionBlock, IsValidArgType, TxbAddress, TagName, PassportObject, IsValidAddress, Errors, ERROR, Permission,
2
+ PermissionIndex, PermissionIndexType, BuyRequiredEnum, Customer_RequiredInfo, DicountDispatch, Service, Service_Buy,
3
+ Service_Guard_Percent, Service_Sale, WithdrawPayee, Treasury,
5
4
  } from 'wowok';
6
5
  import { query_objects, ObjectService } from '../objects';
7
6
  import { CallBase, CallResult, Namedbject } from "./base";
8
7
  import { Account } from '../account';
9
8
 
9
+ /// The execution priority is determined by the order in which the object attributes are arranged
10
10
  export interface CallService_Data {
11
+ type_parameter: string;
11
12
  object?: {address:string} | {namedNew: Namedbject}; // undefined or {named_new...} for creating a new object
12
13
  permission?: {address:string} | {namedNew: Namedbject, description?:string};
13
- type_parameter: string;
14
- bPaused?: boolean;
15
- bPublished?: boolean;
16
14
  description?: string;
17
- gen_discount?: DicountDispatch[];
18
- arbitration?: {op:'set' | 'add'; arbitrations:{address:string, type_parameter:string}[]}
19
- | {op:'removeall'} | {op:'remove', addresses:string[]};
20
- buy_guard?: string;
21
15
  endpoint?: string;
16
+ payee_treasury?:{address:string} | {namedNew: Namedbject, description?:string};
17
+ gen_discount?: DicountDispatch[];
18
+ repository?: {op:'set' | 'add' | 'remove' ; repositories:string[]} | {op:'removeall'};
22
19
  extern_withdraw_treasury?: {op:'set' | 'add'; treasuries:{address:string, token_type:string}[]}
23
20
  | {op:'removeall'} | {op:'remove', addresses:string[]};
24
21
  machine?: string;
25
- payee_treasury?:{address:string} | {namedNew: Namedbject, description?:string};
26
- clone_new?: {token_type_new?:string; namedNew?: Namedbject};
27
- repository?: {op:'set' | 'add' | 'remove' ; repositories:string[]} | {op:'removeall'};
22
+ arbitration?: {op:'set' | 'add'; arbitrations:{address:string, type_parameter:string}[]}
23
+ | {op:'removeall'} | {op:'remove', addresses:string[]};
24
+ customer_required_info?: {pubkey:string; required_info:(string | BuyRequiredEnum)[]};
25
+ sales?: {op:'add', sales:Service_Sale[]} | {op:'remove'; sales_name:string[]}
28
26
  withdraw_guard?: {op:'add' | 'set'; guards:Service_Guard_Percent[]}
29
27
  | {op:'removeall'} | {op:'remove', addresses:string[]};
30
28
  refund_guard?: {op:'add' | 'set'; guards:Service_Guard_Percent[]}
31
29
  | {op:'removeall'} | {op:'remove', addresses:string[]};
32
- customer_required_info?: {pubkey:string; required_info:(string | BuyRequiredEnum)[]};
33
- sales?: {op:'add', sales:Service_Sale[]} | {op:'remove'; sales_name:string[]}
30
+ bPublished?: boolean;
34
31
  order_new?: {buy_items:Service_Buy[], discount?:string, machine?:string, customer_info_crypto?: Customer_RequiredInfo, guard?:string | 'fetch', namedNew?: Namedbject}
32
+ order_agent?: {order:string; agents: string[]; progress?:string};
35
33
  order_required_info?: {order:string; info:Customer_RequiredInfo};
36
34
  order_refund?: {order:string; guard?:string;} | {order:string; arb:string; arb_token_type:string}; // guard address
37
35
  order_withdrawl?: {order:string; data:WithdrawPayee}; // guard address
38
36
  order_payer?: {order:string; payer_new: string}; // transfer the order payer permission to someaddress
39
- order_agent?: {order:string; agents: string[]; progress?:string};
37
+ buy_guard?: string;
38
+ bPaused?: boolean;
39
+ clone_new?: {token_type_new?:string; namedNew?: Namedbject};
40
40
  }
41
+
41
42
  export class CallService extends CallBase {
42
43
  data: CallService_Data;
43
44
  constructor(data: CallService_Data) {
@@ -175,14 +176,11 @@ export class CallService extends CallBase {
175
176
  if (this.data?.description !== undefined && object_address) {
176
177
  obj?.set_description(this.data.description, passport);
177
178
  }
178
- if (this.data?.payee_treasury !== undefined && object_address) {
179
- obj?.set_payee(treasury_address, passport);
180
- }
181
179
  if (this.data?.endpoint !== undefined) {
182
180
  obj?.set_endpoint(this.data.endpoint, passport)
183
181
  }
184
- if (this.data?.machine !== undefined) {
185
- obj?.set_machine(this.data.machine, passport)
182
+ if (this.data?.payee_treasury !== undefined && object_address) {
183
+ obj?.set_payee(treasury_address, passport);
186
184
  }
187
185
  if (this.data?.gen_discount !== undefined) {
188
186
  obj?.discount_transfer(this.data.gen_discount, passport)
@@ -221,6 +219,9 @@ export class CallService extends CallBase {
221
219
  break;
222
220
  }
223
221
  }
222
+ if (this.data?.machine !== undefined) {
223
+ obj?.set_machine(this.data.machine, passport)
224
+ }
224
225
  if (this.data?.arbitration !== undefined) {
225
226
  switch(this.data.arbitration.op) {
226
227
  case 'add':
@@ -238,6 +239,13 @@ export class CallService extends CallBase {
238
239
  break;
239
240
  }
240
241
  }
242
+ if (this.data?.customer_required_info !== undefined) {
243
+ if (this.data.customer_required_info.required_info && this.data.customer_required_info.pubkey) {
244
+ obj?.set_customer_required(this.data.customer_required_info.pubkey, this.data.customer_required_info.required_info, passport);
245
+ } else if (this.data.customer_required_info.pubkey) {
246
+ obj?.change_required_pubkey(this.data.customer_required_info.pubkey, passport);
247
+ }
248
+ }
241
249
  if (this.data?.sales !== undefined) {
242
250
  switch(this.data.sales.op) {
243
251
  case 'add':
@@ -248,47 +256,6 @@ export class CallService extends CallBase {
248
256
  break;
249
257
  }
250
258
  }
251
- if (this.data?.order_new !== undefined) {
252
- let b = BigInt(0); let coin : any;
253
- this.data.order_new.buy_items.forEach(v => {
254
- b += BigInt(v.max_price) * BigInt(v.count)
255
- })
256
- if (b > BigInt(0)) {
257
- const coin = await Account.Instance().get_coin_object(txb, b, account, this.data.type_parameter);
258
- if (coin) {
259
- //@ crypto tools support
260
- const addr = obj.buy(this.data.order_new.buy_items, coin, this.data.order_new.discount,
261
- this.data.order_new.machine, this.data.order_new.customer_info_crypto, passport) ;
262
- await this.new_with_mark(txb, addr, (this.data?.order_new as any)?.namedNew, account, [TagName.Launch, TagName.Order]);
263
- }
264
- }
265
- }
266
- if (this.data?.order_payer !== undefined && obj) {
267
- obj?.change_order_payer(this.data?.order_payer.order, this.data.order_payer.payer_new)
268
- }
269
- if (this.data?.order_agent !== undefined) {
270
- obj?.set_order_agent(this.data.order_agent.order, this.data.order_agent.agents, this.data.order_agent.progress)
271
- }
272
- if (this.data?.order_required_info !== undefined) {
273
- obj?.update_order_required_info(this.data.order_required_info.order, this.data.order_required_info.info)
274
- }
275
- if (this.data?.order_refund !== undefined) {
276
- if ((this.data?.order_refund as any)?.arb && (this.data?.order_refund as any)?.arb_token_type) {
277
- obj?.refund_withArb(this.data.order_refund.order, (this.data?.order_refund as any)?.arb, (this.data?.order_refund as any)?.arb_token_type)
278
- } else {
279
- obj?.refund(this.data.order_refund.order, (this.data?.order_refund as any)?.guard, passport)
280
- }
281
- }
282
- if (this.data?.order_withdrawl !== undefined && passport) { //@ need withdrawal passport
283
- obj?.withdraw(this.data.order_withdrawl.order, this.data.order_withdrawl.data, passport)
284
- }
285
- if (this.data?.customer_required_info !== undefined) {
286
- if (this.data.customer_required_info.required_info && this.data.customer_required_info.pubkey) {
287
- obj?.set_customer_required(this.data.customer_required_info.pubkey, this.data.customer_required_info.required_info, passport);
288
- } else if (this.data.customer_required_info.pubkey) {
289
- obj?.change_required_pubkey(this.data.customer_required_info.pubkey, passport);
290
- }
291
- }
292
259
  if (this.data?.withdraw_guard !== undefined) {
293
260
  switch(this.data.withdraw_guard.op) {
294
261
  case 'add':
@@ -323,15 +290,49 @@ export class CallService extends CallBase {
323
290
  break;
324
291
  }
325
292
  }
293
+ if (this.data?.bPublished) {
294
+ obj?.publish(passport)
295
+ }
296
+ if (this.data?.order_new !== undefined) {
297
+ let b = BigInt(0); let coin : any;
298
+ this.data.order_new.buy_items.forEach(v => {
299
+ b += BigInt(v.max_price) * BigInt(v.count)
300
+ })
301
+ if (b > BigInt(0)) {
302
+ const coin = await Account.Instance().get_coin_object(txb, b, account, this.data.type_parameter);
303
+ if (coin) {
304
+ //@ crypto tools support
305
+ const addr = obj.buy(this.data.order_new.buy_items, coin, this.data.order_new.discount,
306
+ this.data.order_new.machine, this.data.order_new.customer_info_crypto, passport) ;
307
+ await this.new_with_mark(txb, addr, (this.data?.order_new as any)?.namedNew, account, [TagName.Launch, TagName.Order]);
308
+ }
309
+ }
310
+ }
311
+ if (this.data?.order_agent !== undefined) {
312
+ obj?.set_order_agent(this.data.order_agent.order, this.data.order_agent.agents, this.data.order_agent.progress)
313
+ }
314
+ if (this.data?.order_required_info !== undefined) {
315
+ obj?.update_order_required_info(this.data.order_required_info.order, this.data.order_required_info.info)
316
+ }
317
+ if (this.data?.order_refund !== undefined) {
318
+ if ((this.data?.order_refund as any)?.arb && (this.data?.order_refund as any)?.arb_token_type) {
319
+ obj?.refund_withArb(this.data.order_refund.order, (this.data?.order_refund as any)?.arb, (this.data?.order_refund as any)?.arb_token_type)
320
+ } else {
321
+ obj?.refund(this.data.order_refund.order, (this.data?.order_refund as any)?.guard, passport)
322
+ }
323
+ }
324
+ if (this.data?.order_withdrawl !== undefined && passport) { //@ need withdrawal passport
325
+ obj?.withdraw(this.data.order_withdrawl.order, this.data.order_withdrawl.data, passport)
326
+ }
327
+ if (this.data?.order_payer !== undefined && obj) {
328
+ obj?.change_order_payer(this.data?.order_payer.order, this.data.order_payer.payer_new)
329
+ }
326
330
  if (this.data?.buy_guard !== undefined) {
327
331
  obj?.set_buy_guard(this.data.buy_guard, passport)
328
332
  }
329
333
  if (this.data?.bPaused !== undefined) {
330
334
  obj?.pause(this.data.bPaused, passport)
331
335
  }
332
- if (this.data?.bPublished) {
333
- obj?.publish(passport)
334
- }
335
336
  if (this.data?.clone_new !== undefined && obj) {
336
337
  await this.new_with_mark(txb, obj.clone(this.data.clone_new?.token_type_new, true, passport) as TxbAddress, (this.data?.clone_new as any)?.namedNew, account);
337
338
  }
@@ -1,22 +1,22 @@
1
- import { TransactionBlock, CallResponse, IsValidArgType, Resource, ResourceObject} from 'wowok';
2
- import { PassportObject, IsValidAddress, Errors, ERROR, Permission, PermissionIndex,
3
- PermissionIndexType, DepositParam, Treasury, Treasury_WithdrawMode, WithdrawParam, WitnessFill
1
+ import { TransactionBlock, IsValidArgType, PassportObject, IsValidAddress, Errors, ERROR, Permission, PermissionIndex,
2
+ PermissionIndexType, Treasury, Treasury_WithdrawMode, WithdrawParam,
4
3
  } from 'wowok';
5
4
  import { query_objects, ObjectTreasury } from '../objects';
6
5
  import { CallBase, CallResult, Namedbject } from "./base";
7
6
  import { Account } from '../account';
8
7
 
8
+ /// The execution priority is determined by the order in which the object attributes are arranged
9
9
  export interface CallTreasury_Data {
10
+ type_parameter: string;
10
11
  object?: {address:string} | {namedNew: Namedbject}; // undefined or {named_new...} for creating a new object
11
12
  permission?: {address:string} | {namedNew: Namedbject, description?:string};
12
- type_parameter: string;
13
13
  description?: string;
14
- withdraw_mode?: Treasury_WithdrawMode;
15
- withdraw_guard?: {op:'add' | 'set'; data:{guard:string, amount:string|number}[]} | {op:'remove', guards:string[]} | {op:'removeall'};
16
- deposit_guard?: string;
17
14
  deposit?: {data:{balance:string|number; index?:number; remark?:string; for_object?:string; for_guard?:string}; guard?:string | 'fetch'};
18
15
  receive?: {payment:string; received_object:string};
19
16
  withdraw?:WithdrawParam;
17
+ deposit_guard?: string;
18
+ withdraw_guard?: {op:'add' | 'set'; data:{guard:string, amount:string|number}[]} | {op:'remove', guards:string[]} | {op:'removeall'};
19
+ withdraw_mode?: Treasury_WithdrawMode;
20
20
  }
21
21
  export class CallTreasury extends CallBase {
22
22
  data: CallTreasury_Data;
@@ -120,6 +120,9 @@ export class CallTreasury extends CallBase {
120
120
  }
121
121
 
122
122
  if (obj) {
123
+ if (this.data?.description !== undefined && object_address) {
124
+ obj?.set_description(this.data.description, passport);
125
+ }
123
126
  if (this.data.deposit !== undefined) {
124
127
  const coin = await Account.Instance().get_coin_object(txb, this.data.deposit.data.balance, account, this.data.type_parameter);
125
128
  if (coin) {
@@ -130,15 +133,13 @@ export class CallTreasury extends CallBase {
130
133
  })
131
134
  }
132
135
  }
133
- if (this.data?.withdraw !== undefined) {
134
- obj?.withdraw(this.data.withdraw, passport)
135
- }
136
136
  if (this.data?.receive !== undefined) {
137
137
  obj?.receive(this.data.receive.payment, this.data.receive.received_object, passport);
138
138
  }
139
- if (this.data?.description !== undefined && object_address) {
140
- obj?.set_description(this.data.description, passport);
139
+ if (this.data?.withdraw !== undefined) {
140
+ obj?.withdraw(this.data.withdraw, passport)
141
141
  }
142
+
142
143
  if (this.data?.deposit_guard !== undefined) {
143
144
  obj?.set_deposit_guard(this.data.deposit_guard, passport);
144
145
  }
package/src/call.ts CHANGED
@@ -1,6 +1,6 @@
1
1
 
2
2
  /**
3
- * Provide a this interface for AI
3
+ * Provide an operate interface for AI
4
4
  * Restrictive prioritization, such as setting a deposit first and setting a deposit guard later (only subsequent deposits are affected).
5
5
  */
6
6
 
package/src/permission.ts CHANGED
@@ -3,9 +3,7 @@
3
3
  * not only the permission table, but also the administrator or Builder identity.
4
4
  */
5
5
 
6
- import { TransactionBlock, } from 'wowok';
7
- import { Protocol, Bcs, IsValidAddress, Errors, ERROR, Permission, PermissionAnswer, BCS} from 'wowok';
8
-
6
+ import { TransactionBlock, Protocol, Bcs, IsValidAddress, Errors, ERROR, Permission, PermissionAnswer, BCS} from 'wowok';
9
7
 
10
8
  export interface PermissionQuery {
11
9
  permission_object: string;
@@ -0,0 +1,217 @@
1
+ import * as fs from 'fs';
2
+ import * as path from 'path';
3
+ import * as os from 'os';
4
+ import { BuyRequiredEnum } from 'wowok';
5
+
6
+ const Private_FileName = 'wowok.sel.dat';
7
+ const Private_Key = 'wowok-sel-v1';
8
+
9
+ export interface PrivateInfo_Data {
10
+ name: string;
11
+ default?: boolean;
12
+ info: Map<BuyRequiredEnum | string, string>;
13
+ }
14
+
15
+ export class PrivateInfo {
16
+ constructor(storage: 'File' | 'Explorer' = 'File') {
17
+ this.storage = storage;
18
+ }
19
+ static _instance: any;
20
+
21
+ static Instance() : PrivateInfo {
22
+ if (!PrivateInfo._instance) {
23
+ PrivateInfo._instance = new PrivateInfo();
24
+ }; return PrivateInfo._instance
25
+ }
26
+
27
+ private storage: 'File' | 'Explorer' = 'File';
28
+
29
+ private _add(buffer:string | null | undefined, name:string, info:Map<BuyRequiredEnum | string, string>, bDefault?: boolean) : PrivateInfo_Data[] | undefined{
30
+ var data : PrivateInfo_Data[] | undefined;
31
+
32
+ try {
33
+ if (buffer) {
34
+ data = JSON.parse(buffer) as PrivateInfo_Data[];
35
+ if (data) {
36
+ const f = data.find(v => v.name === name);
37
+ if (f) {
38
+ f.default = bDefault;
39
+ f.info = info;
40
+ } else {
41
+ if (bDefault) {
42
+ data.forEach(v => v.default = false)
43
+ }
44
+ data.push({name:name, info:info, default:bDefault})
45
+ }
46
+ } else {
47
+ data = [{name:name, info:info, default:bDefault}];
48
+ }
49
+ return data
50
+ }
51
+ } catch(e) { console.log(e) }
52
+ }
53
+
54
+ private _remove(buffer:string | null | undefined, name:string) : PrivateInfo_Data[] | undefined{
55
+ var data : PrivateInfo_Data[] | undefined;
56
+
57
+ try {
58
+ if (buffer) {
59
+ data = JSON.parse(buffer) as PrivateInfo_Data[];
60
+ if (data) {
61
+ return data.filter(v => v.name !== name);
62
+ }
63
+ }
64
+ } catch(e) { console.log(e) }
65
+ }
66
+
67
+ private _default(buffer:string | null | undefined) : PrivateInfo_Data | undefined {
68
+ var data : PrivateInfo_Data[] | undefined;
69
+ try {
70
+ if (buffer) {
71
+ data = JSON.parse(buffer) as PrivateInfo_Data[];
72
+ if (data) {
73
+ const f = data.find(v => v.default);
74
+ if (f) {
75
+ return f
76
+ }
77
+ }
78
+ }
79
+ } catch(e) { console.log(e) }
80
+ }
81
+ private _get(buffer:string | null | undefined, name?:string, bNotFoundReturnDefault?:boolean) : PrivateInfo_Data | undefined {
82
+ var data : PrivateInfo_Data[] | undefined;
83
+ try {
84
+ if (buffer) {
85
+ data = JSON.parse(buffer) as PrivateInfo_Data[];
86
+ if (data) {
87
+ const f = data.find(v => v.name === name);
88
+ if (f) {
89
+ return f
90
+ }
91
+ if (bNotFoundReturnDefault) {
92
+ return data.find(v => v.default)
93
+ }
94
+ }
95
+ }
96
+ } catch(e) { console.log(e) }
97
+ }
98
+
99
+ private _rename(buffer:string | null | undefined, oldName:string, newName:string, bSwapIfExisted:boolean=true) : PrivateInfo_Data[] | undefined {
100
+ var data : PrivateInfo_Data[] | undefined;
101
+ try {
102
+ if (buffer) {
103
+ data = JSON.parse(buffer) as PrivateInfo_Data[];
104
+
105
+ if (data) {
106
+ const f1 = data.find(v => v.name === oldName);
107
+ if (!f1) return undefined;
108
+
109
+ const f2 = data.find(v => v.name === newName);
110
+ if (f2) {
111
+ if (bSwapIfExisted) {
112
+ f1.name = newName;
113
+ f2.name = oldName;
114
+ return data
115
+ }
116
+ } else {
117
+ f1.name = newName;
118
+ return data;
119
+ }
120
+ }
121
+ }
122
+ } catch(e) { console.log(e) }
123
+ }
124
+
125
+ set_storage(storage: 'File' | 'Explorer' = 'File') {
126
+ this.storage = storage
127
+ }
128
+
129
+ default() : PrivateInfo_Data | undefined {
130
+ try {
131
+ if (this.storage === 'File') {
132
+ const filePath = path.join(os.homedir(), Private_FileName);
133
+ return this._default(fs.readFileSync(filePath, 'utf-8'));
134
+ } else if (this.storage === 'Explorer') {
135
+ return this._default(localStorage.getItem(Private_Key));
136
+ }
137
+ } catch (e) { console.log(e) }
138
+ }
139
+ get(name?: string, bNotFoundReturnDefault:boolean=true) : PrivateInfo_Data | undefined {
140
+ try {
141
+ if (this.storage === 'File') {
142
+ const filePath = path.join(os.homedir(), Private_FileName);
143
+ return this._get(fs.readFileSync(filePath, 'utf-8'), name, bNotFoundReturnDefault);
144
+ } else if (this.storage === 'Explorer') {
145
+ return this._get(localStorage.getItem(Private_Key), name, bNotFoundReturnDefault);
146
+ }
147
+ } catch (e) { console.log(e) }
148
+ }
149
+ rename(oldName:string, newName:string, bSwapIfExisted:boolean=true) : boolean {
150
+ var res : PrivateInfo_Data[] | undefined;
151
+ try {
152
+ if (this.storage === 'File') {
153
+ const filePath = path.join(os.homedir(), Private_FileName);
154
+ res = this._rename(fs.readFileSync(filePath, 'utf-8'), oldName, newName, bSwapIfExisted);
155
+ if (res) {fs.writeFileSync(filePath, JSON.stringify(res), 'utf-8') }
156
+ } else if (this.storage === 'Explorer') {
157
+ res = this._rename(localStorage.getItem(Private_Key), oldName, newName, bSwapIfExisted);
158
+ if (res) localStorage.setItem(Private_Key, JSON.stringify(res));
159
+ }
160
+ } catch (e) { console.log(e) }
161
+ return res ? true : false
162
+ }
163
+
164
+ list() : PrivateInfo_Data[] {
165
+ try {
166
+ if (this.storage === 'File') {
167
+ const filePath = path.join(os.homedir(), Private_FileName);
168
+ return JSON.parse(fs.readFileSync(filePath, 'utf-8')) as PrivateInfo_Data[];
169
+ } else if (this.storage === 'Explorer') {
170
+ return JSON.parse(localStorage.getItem(Private_Key) ?? '') as PrivateInfo_Data[];
171
+ }
172
+ } catch (e) { console.log(e) }
173
+ return []
174
+ }
175
+
176
+ add(name:string, info:Map<BuyRequiredEnum | string, string>, bDefault?: boolean) {
177
+ try {
178
+ if (this.storage === 'File') {
179
+ const filePath = path.join(os.homedir(), Private_FileName);
180
+ fs.readFile(filePath, 'utf-8', (err, d) => {
181
+ const data = this._add(d, name, info, bDefault);
182
+ fs.writeFileSync(filePath, JSON.stringify(data), 'utf-8')
183
+ });
184
+ } else if (this.storage === 'Explorer') {
185
+ const data = this._add(localStorage.getItem(Private_Key), name, info, bDefault);
186
+ localStorage.setItem(Private_Key, JSON.stringify(data))
187
+ }
188
+ } catch (e) { console.log(e) }
189
+ }
190
+
191
+ remove(name:string) {
192
+ try {
193
+ if (this.storage === 'File') {
194
+ const filePath = path.join(os.homedir(), Private_FileName);
195
+ fs.readFile(filePath, 'utf-8', (err, d) => {
196
+ const data = this._remove(d, name);
197
+ fs.writeFileSync(filePath, JSON.stringify(data), 'utf-8')
198
+ });
199
+ } else if (this.storage === 'Explorer') {
200
+ const data = this._remove(localStorage.getItem(Private_Key), name);
201
+ localStorage.setItem(Private_Key, JSON.stringify(data))
202
+ }
203
+ } catch (e) { console.log(e) }
204
+ }
205
+
206
+ removeall() {
207
+ try {
208
+ if (this.storage === 'File') {
209
+ const filePath = path.join(os.homedir(), Private_FileName);
210
+ fs.unlink(filePath, (err) => {console.log(err)});
211
+ } else if (this.storage === 'Explorer') {
212
+ localStorage.removeItem(Private_Key)
213
+ }
214
+ } catch (e) { console.log(e) }
215
+ }
216
+ }
217
+