wowok 1.0.3 → 1.0.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/dist/machine.js CHANGED
@@ -1,172 +1,222 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.change_permission = exports.machine_publish = exports.machine_pause = exports.machine_set_endpoint = exports.machine_clone = exports.machine_remove_repository = exports.machine_add_repository = exports.machine_set_description = exports.launch = exports.destroy = exports.machine = exports.machine_remove_node = exports.machine_add_node2 = exports.machine_add_node = exports.is_valid_name = exports.INITIAL_NODE_NAME = void 0;
4
- const bcs_1 = require("@mysten/bcs");
3
+ exports.change_permission = exports.machine_publish = exports.machine_pause = exports.machine_set_endpoint = exports.machine_clone = exports.machine_remove_repository = exports.machine_add_repository = exports.machine_set_description = exports.launch = exports.destroy = exports.machine = exports.machine_remove_node = exports.machine_add_node2 = exports.machine_add_node = exports.INITIAL_NODE_NAME = void 0;
5
4
  const protocol_1 = require("./protocol");
6
5
  const util_1 = require("./util");
6
+ const permission_1 = require("./permission");
7
7
  exports.INITIAL_NODE_NAME = '';
8
- // node & forward & forward permission string length validation
9
- function is_valid_name(name) { return name.length > 0 && name.length < 33; }
10
- exports.is_valid_name = is_valid_name;
11
8
  // 创建新的node加入到machine
12
9
  function machine_add_node(txb, machine, permission, nodes, passport) {
10
+ if (!(0, protocol_1.IsValidObjects)([machine, permission]))
11
+ return false;
12
+ let bValid = true;
13
+ nodes.forEach((node) => {
14
+ if (!(0, protocol_1.IsValidDesription)(node.description) || !(0, protocol_1.IsValidName)(node.name)) {
15
+ bValid = false;
16
+ }
17
+ node.pairs.forEach((p) => {
18
+ if (!(0, protocol_1.IsValidName_AllowEmpty)(p.prior_node)) {
19
+ bValid = false;
20
+ }
21
+ if (p?.threshold && !(0, protocol_1.IsValidInt)(p.threshold)) {
22
+ bValid = false;
23
+ }
24
+ p.forwards.forEach((f) => {
25
+ if (!(0, protocol_1.IsValidName)(f.name)) {
26
+ bValid = false;
27
+ }
28
+ if (f?.namedOperator && !(0, protocol_1.IsValidName_AllowEmpty)(f?.namedOperator)) {
29
+ bValid = false;
30
+ }
31
+ if (f?.permission && !(0, permission_1.IsValidPermissionIndex)(f?.permission)) {
32
+ bValid = false;
33
+ }
34
+ if (!f?.permission && !f?.namedOperator) {
35
+ bValid = false;
36
+ }
37
+ if (f?.weight && !(0, protocol_1.IsValidUint)(f.weight)) {
38
+ bValid = false;
39
+ }
40
+ });
41
+ });
42
+ });
43
+ if (!bValid)
44
+ return false;
13
45
  let new_nodes = [];
14
46
  nodes.forEach((node) => {
15
47
  let n = txb.moveCall({
16
48
  target: protocol_1.PROTOCOL.NodeFn('new'),
17
- arguments: [txb.pure((0, protocol_1.name_data)(node.name)), txb.pure((0, protocol_1.description_data)(node.description))]
49
+ arguments: [txb.pure(node.name), txb.pure(node.description)]
18
50
  });
19
51
  node.pairs.forEach((pair) => {
52
+ let threshold = pair?.threshold ? txb.pure(util_1.BCS_CONVERT.ser_option_u64(pair.threshold)) : (0, protocol_1.OptionNone)(txb);
20
53
  pair.forwards.forEach((forward) => {
21
- if (!forward?.namedOperator && !forward?.permission) {
22
- return;
23
- }
24
- let weight = txb.pure(1);
25
- if (forward?.weight && forward.weight > 0) {
26
- weight = txb.pure(forward.weight);
27
- }
28
- let per = txb.pure([], bcs_1.BCS.U8);
29
- if (forward?.permission) {
30
- per = txb.pure(util_1.BCS_CONVERT.ser_option_u64(forward.permission));
31
- }
32
- ;
33
- let namedOperator = txb.pure('');
34
- if (forward?.namedOperator) {
35
- namedOperator = txb.pure(forward.namedOperator);
36
- }
37
- ;
54
+ let weight = forward?.weight ? forward.weight : 1;
55
+ let perm = forward?.permission ? txb.pure(util_1.BCS_CONVERT.ser_option_u64(forward.permission)) : (0, protocol_1.OptionNone)(txb);
56
+ let namedOperator = forward?.namedOperator ? txb.pure(forward.namedOperator) : txb.pure('');
38
57
  let f;
39
- if (forward?.guard_address) {
58
+ if (forward?.guard) {
40
59
  f = txb.moveCall({
41
60
  target: protocol_1.PROTOCOL.NodeFn('forward'),
42
- arguments: [namedOperator, weight, txb.object(forward.guard_address), per]
61
+ arguments: [namedOperator, txb.pure(weight), txb.object((0, protocol_1.TXB_OBJECT)(txb, forward.guard)), perm]
43
62
  });
44
63
  }
45
64
  else {
46
65
  f = txb.moveCall({
47
66
  target: protocol_1.PROTOCOL.NodeFn('forward2'),
48
- arguments: [namedOperator, weight, per]
67
+ arguments: [namedOperator, txb.pure(weight), perm]
49
68
  });
50
69
  }
51
70
  txb.moveCall({
52
71
  target: protocol_1.PROTOCOL.NodeFn('forward_add'),
53
- arguments: [n, txb.pure(pair.prior_node), txb.pure((0, protocol_1.name_data)(forward.name)),
54
- txb.pure(util_1.BCS_CONVERT.ser_option_u64(pair.threshold)), f]
72
+ arguments: [n, txb.pure(pair.prior_node), txb.pure(forward.name), threshold, f]
55
73
  });
56
74
  });
57
75
  });
58
76
  new_nodes.push(n);
59
77
  });
60
- machine_add_node2(txb, machine, permission, new_nodes, passport);
78
+ return machine_add_node2(txb, machine, permission, new_nodes, passport);
61
79
  }
62
80
  exports.machine_add_node = machine_add_node;
63
81
  // 把个人拥有的node加入到machine
64
82
  function machine_add_node2(txb, machine, permission, nodes, passport) {
83
+ if (!(0, protocol_1.IsValidObjects)([machine, permission]))
84
+ return false;
85
+ if (!nodes)
86
+ return false;
65
87
  if (passport) {
66
88
  txb.moveCall({
67
89
  target: protocol_1.PROTOCOL.MachineFn('node_add_with_passport'),
68
- arguments: [passport, machine, txb.makeMoveVec({ objects: nodes }), permission]
90
+ arguments: [passport, (0, protocol_1.TXB_OBJECT)(txb, machine), txb.makeMoveVec({ objects: nodes }), (0, protocol_1.TXB_OBJECT)(txb, permission)]
69
91
  });
70
92
  }
71
93
  else {
72
94
  txb.moveCall({
73
95
  target: protocol_1.PROTOCOL.MachineFn('node_add'),
74
- arguments: [machine, txb.makeMoveVec({ objects: nodes }), permission]
96
+ arguments: [(0, protocol_1.TXB_OBJECT)(txb, machine), txb.makeMoveVec({ objects: nodes }), (0, protocol_1.TXB_OBJECT)(txb, permission)]
75
97
  });
76
98
  }
99
+ return true;
77
100
  }
78
101
  exports.machine_add_node2 = machine_add_node2;
79
102
  // 从machine把node移动到个人地址
80
- function machine_remove_node(txb, machine, permission, nodes_name, receive_address, passport) {
103
+ function machine_remove_node(txb, machine, permission, nodes_name, passport) {
104
+ if (!(0, protocol_1.IsValidObjects)([machine, permission]))
105
+ return false;
106
+ if (!nodes_name || !(0, protocol_1.IsValidArray)(nodes_name, protocol_1.IsValidName))
107
+ return false;
81
108
  if (passport) {
82
109
  txb.moveCall({
83
110
  target: protocol_1.PROTOCOL.MachineFn('node_remove_with_passport'),
84
- arguments: [passport, machine, txb.pure(util_1.BCS_CONVERT.ser_vector_string(nodes_name)), permission],
111
+ arguments: [passport, (0, protocol_1.TXB_OBJECT)(txb, machine), txb.pure(util_1.BCS_CONVERT.ser_vector_string(nodes_name)), permission],
85
112
  });
86
113
  }
87
114
  else {
88
115
  txb.moveCall({
89
116
  target: protocol_1.PROTOCOL.MachineFn('node_remove'),
90
- arguments: [machine, txb.pure(util_1.BCS_CONVERT.ser_vector_string(nodes_name)), permission],
117
+ arguments: [(0, protocol_1.TXB_OBJECT)(txb, machine), txb.pure(util_1.BCS_CONVERT.ser_vector_string(nodes_name)), permission],
91
118
  });
92
119
  }
120
+ return true;
93
121
  }
94
122
  exports.machine_remove_node = machine_remove_node;
95
- function machine(txb, permission, description, endpoint_url, passport) {
96
- if (endpoint_url && endpoint_url.length > protocol_1.MAX_ENDPOINT_LENGTH)
97
- return undefined;
98
- let endpoint = endpoint_url ? txb.pure(util_1.BCS_CONVERT.ser_option_string(endpoint_url)) : txb.pure([], bcs_1.BCS.U8);
123
+ function machine(txb, permission, description, endpoint, passport) {
124
+ if (!(0, protocol_1.IsValidObjects)([permission]))
125
+ return false;
126
+ if ((0, protocol_1.IsValidDesription)(description))
127
+ return false;
128
+ if (endpoint && !(0, protocol_1.IsValidEndpoint)(endpoint))
129
+ return false;
130
+ let ep = endpoint ? txb.pure(util_1.BCS_CONVERT.ser_option_string(endpoint)) : (0, protocol_1.OptionNone)(txb);
99
131
  if (passport) {
100
132
  return txb.moveCall({
101
133
  target: protocol_1.PROTOCOL.MachineFn('new_with_passport'),
102
- arguments: [passport, txb.pure((0, protocol_1.description_data)(description)), endpoint, permission],
134
+ arguments: [passport, txb.pure(description), ep, (0, protocol_1.TXB_OBJECT)(txb, permission)],
103
135
  });
104
136
  }
105
137
  else {
106
- //console.log(endpoint)
107
138
  return txb.moveCall({
108
139
  target: protocol_1.PROTOCOL.MachineFn('new'),
109
- arguments: [txb.pure((0, protocol_1.description_data)(description)), endpoint, permission],
140
+ arguments: [txb.pure(description), ep, (0, protocol_1.TXB_OBJECT)(txb, permission)],
110
141
  });
111
142
  }
112
143
  }
113
144
  exports.machine = machine;
114
145
  function destroy(txb, machine) {
115
- return txb.moveCall({
146
+ if (!(0, protocol_1.IsValidObjects)([machine]))
147
+ return false;
148
+ txb.moveCall({
116
149
  target: protocol_1.PROTOCOL.MachineFn('destroy'),
117
- arguments: [machine],
150
+ arguments: [(0, protocol_1.TXB_OBJECT)(txb, machine)],
118
151
  });
152
+ return true;
119
153
  }
120
154
  exports.destroy = destroy;
121
155
  function launch(txb, machine) {
156
+ if (!(0, protocol_1.IsValidObjects)([machine]))
157
+ return false;
122
158
  return txb.moveCall({
123
159
  target: protocol_1.PROTOCOL.MachineFn('create'),
124
- arguments: [machine],
160
+ arguments: [(0, protocol_1.TXB_OBJECT)(txb, machine)],
125
161
  });
126
162
  }
127
163
  exports.launch = launch;
128
164
  function machine_set_description(txb, machine, permission, description, passport) {
165
+ if (!(0, protocol_1.IsValidObjects)([machine, permission]))
166
+ return false;
167
+ if (!(0, protocol_1.IsValidDesription)(description))
168
+ return false;
129
169
  if (passport) {
130
170
  txb.moveCall({
131
171
  target: protocol_1.PROTOCOL.MachineFn('description_set_with_passport'),
132
- arguments: [passport, machine, txb.pure((0, protocol_1.description_data)(description)), permission],
172
+ arguments: [passport, (0, protocol_1.TXB_OBJECT)(txb, machine), txb.pure(description), (0, protocol_1.TXB_OBJECT)(txb, permission)],
133
173
  });
134
174
  }
135
175
  else {
136
176
  txb.moveCall({
137
177
  target: protocol_1.PROTOCOL.MachineFn('description_set'),
138
- arguments: [machine, txb.pure((0, protocol_1.description_data)(description)), permission],
178
+ arguments: [(0, protocol_1.TXB_OBJECT)(txb, machine), txb.pure(description), (0, protocol_1.TXB_OBJECT)(txb, permission)],
139
179
  });
140
180
  }
181
+ return true;
141
182
  }
142
183
  exports.machine_set_description = machine_set_description;
143
184
  function machine_add_repository(txb, machine, permission, repository, passport) {
185
+ if (!(0, protocol_1.IsValidObjects)([machine, permission, repository]))
186
+ return false;
144
187
  if (passport) {
145
188
  txb.moveCall({
146
189
  target: protocol_1.PROTOCOL.MachineFn('repository_add_with_passport'),
147
- arguments: [passport, machine, repository, permission],
190
+ arguments: [passport, (0, protocol_1.TXB_OBJECT)(txb, machine), (0, protocol_1.TXB_OBJECT)(txb, repository), (0, protocol_1.TXB_OBJECT)(txb, permission)],
148
191
  });
149
192
  }
150
193
  else {
151
194
  txb.moveCall({
152
195
  target: protocol_1.PROTOCOL.MachineFn('repository_add'),
153
- arguments: [machine, repository, permission],
196
+ arguments: [(0, protocol_1.TXB_OBJECT)(txb, machine), (0, protocol_1.TXB_OBJECT)(txb, repository), (0, protocol_1.TXB_OBJECT)(txb, permission)],
154
197
  });
155
198
  }
199
+ return true;
156
200
  }
157
201
  exports.machine_add_repository = machine_add_repository;
158
202
  function machine_remove_repository(txb, machine, permission, repositories, removeall, passport) {
203
+ if (!(0, protocol_1.IsValidObjects)([machine, permission]))
204
+ return false;
205
+ if (!removeall && !repositories)
206
+ return false;
207
+ if (!(0, protocol_1.IsValidArray)(repositories, protocol_1.IsValidAddress))
208
+ return false;
159
209
  if (passport) {
160
210
  if (removeall) {
161
211
  txb.moveCall({
162
212
  target: protocol_1.PROTOCOL.MachineFn('repository_remove_all_with_passport'),
163
- arguments: [passport, machine, permission],
213
+ arguments: [passport, (0, protocol_1.TXB_OBJECT)(txb, machine), (0, protocol_1.TXB_OBJECT)(txb, machine)],
164
214
  });
165
215
  }
166
216
  else {
167
217
  txb.moveCall({
168
218
  target: protocol_1.PROTOCOL.MachineFn('repository_remove_with_passport'),
169
- arguments: [passport, machine, txb.pure(repositories, 'vector<address>'), permission],
219
+ arguments: [passport, (0, protocol_1.TXB_OBJECT)(txb, machine), txb.pure(repositories, 'vector<address>'), (0, protocol_1.TXB_OBJECT)(txb, permission)],
170
220
  });
171
221
  }
172
222
  }
@@ -174,86 +224,101 @@ function machine_remove_repository(txb, machine, permission, repositories, remov
174
224
  if (removeall) {
175
225
  txb.moveCall({
176
226
  target: protocol_1.PROTOCOL.MachineFn('repository_remove_all'),
177
- arguments: [machine, permission],
227
+ arguments: [(0, protocol_1.TXB_OBJECT)(txb, machine), (0, protocol_1.TXB_OBJECT)(txb, permission)],
178
228
  });
179
229
  }
180
230
  else {
181
231
  txb.moveCall({
182
232
  target: protocol_1.PROTOCOL.MachineFn('repository_remove'),
183
- arguments: [machine, txb.pure(repositories, 'vector<address>'), permission],
233
+ arguments: [(0, protocol_1.TXB_OBJECT)(txb, machine), txb.pure(repositories, 'vector<address>'), (0, protocol_1.TXB_OBJECT)(txb, permission)],
184
234
  });
185
235
  }
186
236
  }
237
+ return true;
187
238
  }
188
239
  exports.machine_remove_repository = machine_remove_repository;
189
240
  function machine_clone(txb, machine, permission, passport) {
241
+ if (!(0, protocol_1.IsValidObjects)([machine, permission]))
242
+ return false;
190
243
  if (passport) {
191
244
  return txb.moveCall({
192
245
  target: protocol_1.PROTOCOL.MachineFn('clone_with_passport'),
193
- arguments: [passport, machine, permission],
246
+ arguments: [passport, (0, protocol_1.TXB_OBJECT)(txb, machine), (0, protocol_1.TXB_OBJECT)(txb, permission)],
194
247
  });
195
248
  }
196
249
  else {
197
250
  return txb.moveCall({
198
251
  target: protocol_1.PROTOCOL.MachineFn('clone'),
199
- arguments: [machine, permission],
252
+ arguments: [(0, protocol_1.TXB_OBJECT)(txb, machine), (0, protocol_1.TXB_OBJECT)(txb, permission)],
200
253
  });
201
254
  }
202
255
  }
203
256
  exports.machine_clone = machine_clone;
204
- function machine_set_endpoint(txb, machine, permission, endpoint_url, passport) {
205
- if (endpoint_url && endpoint_url.length > protocol_1.MAX_ENDPOINT_LENGTH)
206
- return undefined;
207
- let endpoint = endpoint_url ? txb.pure(util_1.BCS_CONVERT.ser_option_string(endpoint_url)) : txb.pure([], bcs_1.BCS.U8);
257
+ function machine_set_endpoint(txb, machine, permission, endpoint, passport) {
258
+ if (!(0, protocol_1.IsValidObjects)([machine, permission]))
259
+ return false;
260
+ if (endpoint && !(0, protocol_1.IsValidEndpoint)(endpoint))
261
+ return false;
262
+ let ep = endpoint ? txb.pure(util_1.BCS_CONVERT.ser_option_string(endpoint)) : (0, protocol_1.OptionNone)(txb);
208
263
  if (passport) {
209
264
  txb.moveCall({
210
265
  target: protocol_1.PROTOCOL.MachineFn('endpoint_set_with_passport'),
211
- arguments: [passport, machine, endpoint, permission],
266
+ arguments: [passport, (0, protocol_1.TXB_OBJECT)(txb, machine), ep, (0, protocol_1.TXB_OBJECT)(txb, permission)],
212
267
  });
213
268
  }
214
269
  else {
215
270
  txb.moveCall({
216
271
  target: protocol_1.PROTOCOL.MachineFn('endpoint_set'),
217
- arguments: [machine, endpoint, permission],
272
+ arguments: [(0, protocol_1.TXB_OBJECT)(txb, machine), ep, (0, protocol_1.TXB_OBJECT)(txb, permission)],
218
273
  });
219
274
  }
275
+ return true;
220
276
  }
221
277
  exports.machine_set_endpoint = machine_set_endpoint;
222
278
  function machine_pause(txb, machine, permission, bPaused, passport) {
279
+ if (!(0, protocol_1.IsValidObjects)([machine, permission]))
280
+ return false;
223
281
  if (passport) {
224
282
  txb.moveCall({
225
283
  target: protocol_1.PROTOCOL.MachineFn('pause_with_passport'),
226
- arguments: [passport, machine, txb.pure(bPaused), permission],
284
+ arguments: [passport, (0, protocol_1.TXB_OBJECT)(txb, machine), txb.pure(bPaused), (0, protocol_1.TXB_OBJECT)(txb, permission)],
227
285
  });
228
286
  }
229
287
  else {
230
288
  txb.moveCall({
231
289
  target: protocol_1.PROTOCOL.MachineFn('pause'),
232
- arguments: [machine, txb.pure(bPaused), permission],
290
+ arguments: [(0, protocol_1.TXB_OBJECT)(txb, machine), txb.pure(bPaused), (0, protocol_1.TXB_OBJECT)(txb, permission)],
233
291
  });
234
292
  }
293
+ return true;
235
294
  }
236
295
  exports.machine_pause = machine_pause;
237
296
  function machine_publish(txb, machine, permission, passport) {
297
+ if (!(0, protocol_1.IsValidObjects)([machine, permission]))
298
+ return false;
238
299
  if (passport) {
239
300
  txb.moveCall({
240
301
  target: protocol_1.PROTOCOL.MachineFn('publish_with_passport'),
241
- arguments: [passport, machine, permission],
302
+ arguments: [passport, (0, protocol_1.TXB_OBJECT)(txb, machine), (0, protocol_1.TXB_OBJECT)(txb, permission)],
242
303
  });
243
304
  }
244
305
  else {
245
306
  txb.moveCall({
246
307
  target: protocol_1.PROTOCOL.MachineFn('publish'),
247
- arguments: [machine, permission],
308
+ arguments: [(0, protocol_1.TXB_OBJECT)(txb, machine), (0, protocol_1.TXB_OBJECT)(txb, permission)],
248
309
  });
249
310
  }
311
+ return true;
250
312
  }
251
313
  exports.machine_publish = machine_publish;
252
314
  function change_permission(txb, machine, old_permission, new_permission) {
315
+ if (!(0, protocol_1.IsValidObjects)([machine, old_permission, new_permission]))
316
+ return false;
253
317
  txb.moveCall({
254
318
  target: protocol_1.PROTOCOL.MachineFn('permission_set'),
255
- arguments: [machine, old_permission, new_permission],
319
+ arguments: [(0, protocol_1.TXB_OBJECT)(txb, machine), (0, protocol_1.TXB_OBJECT)(txb, old_permission), (0, protocol_1.TXB_OBJECT)(txb, new_permission)],
256
320
  typeArguments: []
257
321
  });
322
+ return true;
258
323
  }
259
324
  exports.change_permission = change_permission;
package/dist/passport.js CHANGED
@@ -1,12 +1,20 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.query_cmd_fn = exports.destroy = exports.verify = exports.passport_quries = exports.MAX_GUARD_COUNT = void 0;
3
+ exports.query_cmd_fn = exports.destroy = exports.verify = exports.passport_queries = exports.MAX_GUARD_COUNT = void 0;
4
4
  const transactions_1 = require("@mysten/sui.js/transactions");
5
5
  const protocol_1 = require("./protocol");
6
6
  const util_1 = require("./util");
7
7
  const guard_1 = require("./guard");
8
- exports.MAX_GUARD_COUNT = 4;
9
- const passport_quries = async (guards) => {
8
+ exports.MAX_GUARD_COUNT = 8;
9
+ // passport verify for some guards, MUST be in ONE pxb:
10
+ // 0. construct Guard_Query_Objects(passport_quries) from queries for guards of objects
11
+ // 1. create passport
12
+ // 2. add all guards
13
+ // 3. verify passport
14
+ // 4. ops using passport(guard set on object)
15
+ // 5. ops using passport(guard set on object)
16
+ // 6. destroy passport
17
+ const passport_queries = async (guards) => {
10
18
  let sense_objects = guards.map((value) => {
11
19
  return { objectid: value, callback: guard_1.sense_objects_fn, data: [] };
12
20
  });
@@ -25,11 +33,11 @@ const passport_quries = async (guards) => {
25
33
  return value.data;
26
34
  });
27
35
  };
28
- exports.passport_quries = passport_quries;
36
+ exports.passport_queries = passport_queries;
29
37
  // return passport object for using
30
38
  function verify(txb, passport_queries) {
31
39
  if (passport_queries.length == 0 || passport_queries.length > exports.MAX_GUARD_COUNT) {
32
- return undefined;
40
+ return false;
33
41
  }
34
42
  let guard_ids = passport_queries.map((value) => value.id);
35
43
  var passport = txb.moveCall({
@@ -67,6 +75,7 @@ function destroy(txb, passport) {
67
75
  target: protocol_1.PROTOCOL.PassportFn('destroy'),
68
76
  arguments: [passport]
69
77
  });
78
+ return true;
70
79
  }
71
80
  exports.destroy = destroy;
72
81
  // construct Guard_Query_Object of wowok objects for passport verify