wowok 1.2.3 → 1.2.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/exception.d.ts +2 -1
- package/dist/exception.d.ts.map +1 -1
- package/dist/exception.js +1 -0
- package/dist/guard.d.ts.map +1 -1
- package/dist/guard.js +26 -25
- package/dist/machine.js +7 -6
- package/dist/passport.d.ts.map +1 -1
- package/dist/passport.js +30 -28
- package/dist/permission.js +2 -1
- package/dist/progress.d.ts.map +1 -1
- package/dist/progress.js +3 -12
- package/dist/protocol.d.ts +5 -2
- package/dist/protocol.d.ts.map +1 -1
- package/dist/protocol.js +9 -3
- package/dist/repository.d.ts.map +1 -1
- package/dist/repository.js +5 -15
- package/dist/service.js +25 -25
- package/dist/utils.d.ts +9 -21
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +114 -53
- package/dist/vote.js +8 -7
- package/package.json +1 -1
- package/src/exception.ts +1 -0
- package/src/guard.ts +26 -25
- package/src/machine.ts +7 -7
- package/src/passport.ts +30 -27
- package/src/permission.ts +2 -2
- package/src/progress.ts +4 -12
- package/src/protocol.ts +13 -6
- package/src/repository.ts +5 -14
- package/src/service.ts +25 -25
- package/src/utils.ts +116 -57
- package/src/vote.ts +8 -8
package/src/guard.ts
CHANGED
|
@@ -269,7 +269,8 @@ export class GuardConstantHelper {
|
|
|
269
269
|
let v = constants.get(identifier);
|
|
270
270
|
if (!v || v.type == ContextType.TYPE_WITNESS_ID) {
|
|
271
271
|
if (bNeedSerialize) {
|
|
272
|
-
constants.set(identifier, {type:ContextType.TYPE_WITNESS_ID, value:value ? Bcs.getInstance().
|
|
272
|
+
constants.set(identifier, {type:ContextType.TYPE_WITNESS_ID, value:value ? Bcs.getInstance().ser(ValueType.TYPE_ADDRESS, value) : undefined,
|
|
273
|
+
witness:witness ? Bcs.getInstance().ser(ValueType.TYPE_ADDRESS, witness) : undefined})
|
|
273
274
|
} else {
|
|
274
275
|
constants.set(identifier, {type:ContextType.TYPE_WITNESS_ID, value:value?value:undefined, witness:witness?witness:undefined});
|
|
275
276
|
}
|
|
@@ -301,12 +302,12 @@ export class GuardConstantHelper {
|
|
|
301
302
|
case ValueType.TYPE_VEC_U256:
|
|
302
303
|
let ser = SER_VALUE.find(s=>s.type==type);
|
|
303
304
|
if (!ser) ERROR(Errors.Fail, 'add_constant: invalid type');
|
|
304
|
-
bNeedSerialize ? constants.set(identifier, {type:type, value:Bcs.getInstance().ser(ser!.
|
|
305
|
+
bNeedSerialize ? constants.set(identifier, {type:type, value:Bcs.getInstance().ser(ser!.type, value)}) :
|
|
305
306
|
constants.set(identifier, {type:type, value:value})
|
|
306
307
|
return
|
|
307
308
|
case ValueType.TYPE_VEC_U8:
|
|
308
309
|
if (typeof(value) === 'string') {
|
|
309
|
-
constants.set(identifier, {type:type, value:Bcs.getInstance().
|
|
310
|
+
constants.set(identifier, {type:type, value:Bcs.getInstance().ser(ValueType.TYPE_STRING, value)})
|
|
310
311
|
} else {
|
|
311
312
|
constants.set(identifier, {type:type, value:value})
|
|
312
313
|
}
|
|
@@ -344,10 +345,10 @@ export class GuardMaker {
|
|
|
344
345
|
|
|
345
346
|
private serValueParam(type:ValueType, param?:any) {
|
|
346
347
|
if (!param) ERROR(Errors.InvalidParam, 'param');
|
|
347
|
-
this.data.push(Bcs.getInstance().
|
|
348
|
+
this.data.push(Bcs.getInstance().ser(ValueType.TYPE_U8, type));
|
|
348
349
|
let ser = SER_VALUE.find(s=>s.type==type);
|
|
349
350
|
if (!ser) ERROR(Errors.Fail, 'serValueParam: invalid type');
|
|
350
|
-
this.data.push(Bcs.getInstance().ser(ser!.
|
|
351
|
+
this.data.push(Bcs.getInstance().ser(ser!.type, param));
|
|
351
352
|
this.type_validator.push(type);
|
|
352
353
|
}
|
|
353
354
|
|
|
@@ -376,26 +377,26 @@ export class GuardMaker {
|
|
|
376
377
|
break;
|
|
377
378
|
case ValueType.TYPE_VEC_U8:
|
|
378
379
|
if (!param) ERROR(Errors.InvalidParam, 'param');
|
|
379
|
-
this.data.push(Bcs.getInstance().
|
|
380
|
+
this.data.push(Bcs.getInstance().ser(ValueType.TYPE_U8, type));
|
|
380
381
|
if (typeof(param) == 'string') {
|
|
381
|
-
this.data.push(Bcs.getInstance().
|
|
382
|
+
this.data.push(Bcs.getInstance().ser(ValueType.TYPE_STRING, param));
|
|
382
383
|
} else {
|
|
383
|
-
this.data.push(Bcs.getInstance().
|
|
384
|
+
this.data.push(Bcs.getInstance().ser(ValueType.TYPE_VEC_U8, param));
|
|
384
385
|
}
|
|
385
386
|
this.type_validator.push(type);
|
|
386
387
|
break;
|
|
387
388
|
case ContextType.TYPE_SIGNER:
|
|
388
|
-
this.data.push(Bcs.getInstance().
|
|
389
|
+
this.data.push(Bcs.getInstance().ser(ValueType.TYPE_U8, type));
|
|
389
390
|
this.type_validator.push(ValueType.TYPE_ADDRESS);
|
|
390
391
|
break;
|
|
391
392
|
case ContextType.TYPE_CLOCK:
|
|
392
|
-
this.data.push(Bcs.getInstance().
|
|
393
|
+
this.data.push(Bcs.getInstance().ser(ValueType.TYPE_U8, type));
|
|
393
394
|
this.type_validator.push(ValueType.TYPE_U64);
|
|
394
395
|
break;
|
|
395
396
|
case ContextType.TYPE_WITNESS_ID:
|
|
396
397
|
if (!param) ERROR(Errors.InvalidParam, 'param');
|
|
397
|
-
this.data.push(Bcs.getInstance().
|
|
398
|
-
this.data.push(Bcs.getInstance().
|
|
398
|
+
this.data.push(Bcs.getInstance().ser(ValueType.TYPE_U8, type));
|
|
399
|
+
this.data.push(Bcs.getInstance().ser(ValueType.TYPE_ADDRESS, param));
|
|
399
400
|
this.type_validator.push(ValueType.TYPE_ADDRESS);
|
|
400
401
|
break;
|
|
401
402
|
case ContextType.TYPE_CONSTANT:
|
|
@@ -409,8 +410,8 @@ export class GuardMaker {
|
|
|
409
410
|
var v = this.constant.get(param);
|
|
410
411
|
if (!v) ERROR(Errors.Fail, 'identifier not in constant');
|
|
411
412
|
this.type_validator.push(v!.type);
|
|
412
|
-
this.data.push(Bcs.getInstance().
|
|
413
|
-
this.data.push(Bcs.getInstance().
|
|
413
|
+
this.data.push(Bcs.getInstance().ser(ValueType.TYPE_U8, type));
|
|
414
|
+
this.data.push(Bcs.getInstance().ser(ValueType.TYPE_U8, param));
|
|
414
415
|
break;
|
|
415
416
|
default:
|
|
416
417
|
ERROR(Errors.InvalidParam, 'add_param type');
|
|
@@ -445,23 +446,23 @@ export class GuardMaker {
|
|
|
445
446
|
ERROR(Errors.Fail, 'array_equal');
|
|
446
447
|
}
|
|
447
448
|
|
|
448
|
-
this.data.push(Bcs.getInstance().
|
|
449
|
+
this.data.push(Bcs.getInstance().ser(ValueType.TYPE_U8, OperatorType.TYPE_QUERY)); // QUERY TYPE
|
|
449
450
|
if (typeof(object_address_from) == 'string') {
|
|
450
|
-
bWitness ? this.data.push(Bcs.getInstance().
|
|
451
|
-
this.data.push(Bcs.getInstance().
|
|
452
|
-
this.data.push(Bcs.getInstance().
|
|
451
|
+
bWitness ? this.data.push(Bcs.getInstance().ser(ValueType.TYPE_U8, ContextType.TYPE_WITNESS_ID)) :
|
|
452
|
+
this.data.push(Bcs.getInstance().ser(ValueType.TYPE_U8, ValueType.TYPE_ADDRESS));
|
|
453
|
+
this.data.push(Bcs.getInstance().ser(ValueType.TYPE_ADDRESS, object_address_from)); // object address
|
|
453
454
|
} else {
|
|
454
455
|
let v = this.constant.get(object_address_from);
|
|
455
456
|
if (!v) ERROR(Errors.Fail, 'object_address_from not in constant');
|
|
456
457
|
if ((bWitness && v?.type == ContextType.TYPE_WITNESS_ID) || (!bWitness && v?.type == ValueType.TYPE_ADDRESS)) {
|
|
457
|
-
this.data.push(Bcs.getInstance().
|
|
458
|
-
this.data.push(Bcs.getInstance().
|
|
458
|
+
this.data.push(Bcs.getInstance().ser(ValueType.TYPE_U8, ContextType.TYPE_CONSTANT));
|
|
459
|
+
this.data.push(Bcs.getInstance().ser(ValueType.TYPE_U8, object_address_from)); // object identifer in constants
|
|
459
460
|
} else {
|
|
460
461
|
ERROR(Errors.Fail, 'type bWitness not match')
|
|
461
462
|
}
|
|
462
463
|
}
|
|
463
464
|
|
|
464
|
-
this.data.push(Bcs.getInstance().
|
|
465
|
+
this.data.push(Bcs.getInstance().ser(ValueType.TYPE_U8, Guard.QUERIES[query_index][2])); // cmd
|
|
465
466
|
this.type_validator.splice(offset, Guard.QUERIES[query_index][3].length); // delete type stack
|
|
466
467
|
this.type_validator.push(Guard.QUERIES[query_index][4]); // add the return value type to type stack
|
|
467
468
|
return this;
|
|
@@ -499,7 +500,7 @@ export class GuardMaker {
|
|
|
499
500
|
default:
|
|
500
501
|
ERROR(Errors.InvalidParam, 'type')
|
|
501
502
|
}
|
|
502
|
-
this.data.push(Bcs.getInstance().
|
|
503
|
+
this.data.push(Bcs.getInstance().ser(ValueType.TYPE_U8, type)); // TYPE
|
|
503
504
|
this.type_validator.splice(this.type_validator.length - splice_len); // delete type stack
|
|
504
505
|
this.type_validator.push(ValueType.TYPE_BOOL); // add bool to type stack
|
|
505
506
|
return this;
|
|
@@ -536,7 +537,7 @@ export class GuardMaker {
|
|
|
536
537
|
maker.constant.set(k, {type:v.type, value:v.value, witness:v.witness});
|
|
537
538
|
})
|
|
538
539
|
let op = bAnd ? OperatorType.TYPE_LOGIC_AND : OperatorType.TYPE_LOGIC_OR;
|
|
539
|
-
maker.data.push(concatenate(Uint8Array, ...this.data, ...otherBuilt.data, Bcs.getInstance().
|
|
540
|
+
maker.data.push(concatenate(Uint8Array, ...this.data, ...otherBuilt.data, Bcs.getInstance().ser(ValueType.TYPE_U8, op)));
|
|
540
541
|
this.data.splice(0, this.data.length-1);
|
|
541
542
|
maker.type_validator = this.type_validator;
|
|
542
543
|
return maker
|
|
@@ -547,10 +548,10 @@ export class GuardMaker {
|
|
|
547
548
|
|
|
548
549
|
static input_combine(input1:Uint8Array, input2:Uint8Array, bAnd:boolean = true) : Uint8Array {
|
|
549
550
|
let op = bAnd ? OperatorType.TYPE_LOGIC_AND : OperatorType.TYPE_LOGIC_OR;
|
|
550
|
-
return concatenate(Uint8Array, input1, input2, Bcs.getInstance().
|
|
551
|
+
return concatenate(Uint8Array, input1, input2, Bcs.getInstance().ser(ValueType.TYPE_U8, op)) as Uint8Array;
|
|
551
552
|
}
|
|
552
553
|
static input_not(input:Uint8Array) : Uint8Array {
|
|
553
|
-
return concatenate(Uint8Array, input, Bcs.getInstance().
|
|
554
|
+
return concatenate(Uint8Array, input, Bcs.getInstance().ser(ValueType.TYPE_U8, OperatorType.TYPE_LOGIC_NOT)) as Uint8Array;
|
|
554
555
|
}
|
|
555
556
|
|
|
556
557
|
static match_u256(type:number) : boolean {
|
package/src/machine.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { IsValidInt, IsValidUint, Bcs, array_unique, IsValidArray, IsValidAddres
|
|
|
5
5
|
IsValidEndpoint, OptionNone, IsValidDesription} from './utils'
|
|
6
6
|
import { Permission, PermissionIndexType } from './permission';
|
|
7
7
|
import { Errors, ERROR} from './exception'
|
|
8
|
-
import {
|
|
8
|
+
import { ValueType } from './protocol';
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
export type MachineNodeObject = TransactionResult | String;
|
|
@@ -59,7 +59,7 @@ export class Machine {
|
|
|
59
59
|
|
|
60
60
|
let m = new Machine(protocol, permission);
|
|
61
61
|
let txb = protocol.CurrentSession();
|
|
62
|
-
let ep = endpoint? txb.pure(Bcs.getInstance().
|
|
62
|
+
let ep = endpoint? txb.pure(Bcs.getInstance().ser(ValueType.TYPE_OPTION_STRING, endpoint)) : OptionNone(txb);
|
|
63
63
|
|
|
64
64
|
if (passport) {
|
|
65
65
|
m.object = txb.moveCall({
|
|
@@ -104,11 +104,11 @@ export class Machine {
|
|
|
104
104
|
arguments:[txb.pure(node.name), txb.pure(node.description)]
|
|
105
105
|
});
|
|
106
106
|
node.pairs.forEach((pair) => {
|
|
107
|
-
let threshold = pair?.threshold ? txb.pure(Bcs.getInstance().
|
|
107
|
+
let threshold = pair?.threshold ? txb.pure(Bcs.getInstance().ser(ValueType.TYPE_OPTION_U64, pair.threshold)) : OptionNone(txb);
|
|
108
108
|
|
|
109
109
|
pair.forwards.forEach((forward) => {
|
|
110
110
|
let weight = forward?.weight ? forward.weight : 1;
|
|
111
|
-
let perm = forward?.permission ? txb.pure(Bcs.getInstance().
|
|
111
|
+
let perm = forward?.permission ? txb.pure(Bcs.getInstance().ser(ValueType.TYPE_OPTION_U64, forward.permission)) : OptionNone(txb);
|
|
112
112
|
let namedOperator = forward?.namedOperator ? txb.pure(forward.namedOperator) : txb.pure('');
|
|
113
113
|
let f;
|
|
114
114
|
|
|
@@ -169,13 +169,13 @@ export class Machine {
|
|
|
169
169
|
if (passport) {
|
|
170
170
|
txb.moveCall({
|
|
171
171
|
target:this.protocol.MachineFn('node_remove_with_passport') as FnCallType,
|
|
172
|
-
arguments:[passport, Protocol.TXB_OBJECT(txb, this.object), txb.pure(Bcs.getInstance().
|
|
172
|
+
arguments:[passport, Protocol.TXB_OBJECT(txb, this.object), txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, nodes_name)),
|
|
173
173
|
txb.pure(bTransferMyself, BCS.BOOL), Protocol.TXB_OBJECT(txb, this.permission)],
|
|
174
174
|
});
|
|
175
175
|
} else {
|
|
176
176
|
txb.moveCall({
|
|
177
177
|
target:this.protocol.MachineFn('node_remove') as FnCallType,
|
|
178
|
-
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(Bcs.getInstance().
|
|
178
|
+
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, nodes_name)), txb.pure(bTransferMyself, BCS.BOOL), Protocol.TXB_OBJECT(txb, this.permission)],
|
|
179
179
|
});
|
|
180
180
|
}
|
|
181
181
|
}
|
|
@@ -288,7 +288,7 @@ export class Machine {
|
|
|
288
288
|
}
|
|
289
289
|
|
|
290
290
|
let txb = this.protocol.CurrentSession();
|
|
291
|
-
let ep = endpoint? txb.pure(Bcs.getInstance().
|
|
291
|
+
let ep = endpoint? txb.pure(Bcs.getInstance().ser(ValueType.TYPE_OPTION_STRING, endpoint)) : OptionNone(txb);
|
|
292
292
|
|
|
293
293
|
if (passport) {
|
|
294
294
|
txb.moveCall({
|
package/src/passport.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type TransactionObjectInput, Inputs } from '@mysten/sui.js/transactions';
|
|
2
2
|
import { FnCallType, GuardObject, Protocol, ContextType, OperatorType, Data_Type,
|
|
3
3
|
ValueType, SER_VALUE, IsValidOperatorType } from './protocol';
|
|
4
|
-
import { parse_object_type, array_unique, Bcs, ulebDecode, IsValidAddress, IsValidArray, OPTION_NONE, readOption } from './utils';
|
|
4
|
+
import { parse_object_type, array_unique, Bcs, ulebDecode, IsValidAddress, IsValidArray, OPTION_NONE, readOption, readOptionString } from './utils';
|
|
5
5
|
import { BCS, BcsReader } from '@mysten/bcs';
|
|
6
6
|
import { ERROR, Errors } from './exception';
|
|
7
7
|
import { Guard } from './guard';
|
|
@@ -72,7 +72,7 @@ export class GuardParser {
|
|
|
72
72
|
switch (v.type) {
|
|
73
73
|
case ContextType.TYPE_WITNESS_ID:
|
|
74
74
|
case ValueType.TYPE_ADDRESS:
|
|
75
|
-
value = '0x' + Bcs.getInstance().de(
|
|
75
|
+
value = '0x' + Bcs.getInstance().de(ValueType.TYPE_ADDRESS, Uint8Array.from(v.value)).toString();
|
|
76
76
|
break;
|
|
77
77
|
case ValueType.TYPE_BOOL:
|
|
78
78
|
case ValueType.TYPE_U8:
|
|
@@ -94,7 +94,7 @@ export class GuardParser {
|
|
|
94
94
|
case ValueType.TYPE_VEC_U256:
|
|
95
95
|
let de = SER_VALUE.find(s=>s.type==v.type);
|
|
96
96
|
if (!de) ERROR(Errors.Fail, 'GuardObject de error')
|
|
97
|
-
value = Bcs.getInstance().de(de!.
|
|
97
|
+
value = Bcs.getInstance().de(de!.type, Uint8Array.from(v.value));
|
|
98
98
|
break;
|
|
99
99
|
|
|
100
100
|
default:
|
|
@@ -129,61 +129,60 @@ export class GuardParser {
|
|
|
129
129
|
break;
|
|
130
130
|
case ContextType.TYPE_WITNESS_ID: // add to constant
|
|
131
131
|
case ValueType.TYPE_ADDRESS:
|
|
132
|
-
value = '0x' + Bcs.getInstance().de(
|
|
132
|
+
value = '0x' + Bcs.getInstance().de(ValueType.TYPE_ADDRESS, Uint8Array.from(arr)).toString();
|
|
133
133
|
arr.splice(0, 32); // address
|
|
134
134
|
break;
|
|
135
135
|
case ValueType.TYPE_BOOL:
|
|
136
|
-
value = Bcs.getInstance().de(BCS.BOOL, Uint8Array.from(arr)) as boolean;
|
|
137
|
-
arr.shift();
|
|
138
|
-
break;
|
|
139
136
|
case ValueType.TYPE_U8:
|
|
140
|
-
value = Bcs.getInstance().de(
|
|
137
|
+
value = Bcs.getInstance().de(type as ValueType, Uint8Array.from(arr)) as number;
|
|
141
138
|
arr.shift();
|
|
142
139
|
break;
|
|
143
140
|
case ValueType.TYPE_U64:
|
|
144
|
-
value = Bcs.getInstance().de(
|
|
141
|
+
value = Bcs.getInstance().de(type as ValueType, Uint8Array.from(arr)) as number;
|
|
145
142
|
arr.splice(0, 8);
|
|
146
143
|
break;
|
|
147
144
|
case ValueType.TYPE_U128:
|
|
148
|
-
value = Bcs.getInstance().de(
|
|
145
|
+
value = Bcs.getInstance().de(type as ValueType, Uint8Array.from(arr)) as bigint;
|
|
149
146
|
arr.splice(0, 16);
|
|
150
147
|
break;
|
|
151
148
|
case ValueType.TYPE_U256:
|
|
152
|
-
value = Bcs.getInstance().de(
|
|
149
|
+
value = Bcs.getInstance().de(type as ValueType, Uint8Array.from(arr)) as bigint;
|
|
153
150
|
arr.splice(0, 32);
|
|
154
151
|
break;
|
|
155
152
|
case ValueType.TYPE_VEC_U8:
|
|
156
153
|
case ValueType.TYPE_VEC_BOOL:
|
|
154
|
+
case ValueType.TYPE_STRING:
|
|
157
155
|
let r = ulebDecode(Uint8Array.from(arr));
|
|
158
|
-
value = Bcs.getInstance().de(
|
|
156
|
+
value = Bcs.getInstance().de(type as ValueType, Uint8Array.from(arr));
|
|
159
157
|
arr.splice(0, r.value+r.length);
|
|
160
158
|
break;
|
|
161
159
|
case ValueType.TYPE_VEC_ADDRESS:
|
|
162
160
|
r = ulebDecode(Uint8Array.from(arr));
|
|
163
|
-
value = Bcs.getInstance().de(
|
|
161
|
+
value = Bcs.getInstance().de(type as ValueType, Uint8Array.from(arr));
|
|
164
162
|
arr.splice(0, r.value*32+r.length);
|
|
165
163
|
break;
|
|
166
164
|
case ValueType.TYPE_VEC_U128:
|
|
167
165
|
r = ulebDecode(Uint8Array.from(arr));
|
|
168
|
-
value = Bcs.getInstance().de(
|
|
166
|
+
value = Bcs.getInstance().de(type as ValueType, Uint8Array.from(arr));
|
|
169
167
|
arr.splice(0, r.value*16+r.length);
|
|
170
168
|
break;
|
|
171
169
|
case ValueType.TYPE_VEC_U256:
|
|
172
170
|
r = ulebDecode(Uint8Array.from(arr));
|
|
173
|
-
value = Bcs.getInstance().de(
|
|
171
|
+
value = Bcs.getInstance().de(type as ValueType, Uint8Array.from(arr));
|
|
174
172
|
arr.splice(0, r.value*32+r.length);
|
|
175
173
|
break;
|
|
176
174
|
case ValueType.TYPE_VEC_U64:
|
|
177
175
|
r = ulebDecode(Uint8Array.from(arr));
|
|
178
|
-
value = Bcs.getInstance().de(
|
|
176
|
+
value = Bcs.getInstance().de(type as ValueType, Uint8Array.from(arr));
|
|
179
177
|
arr.splice(0, r.value*8+r.length);
|
|
180
178
|
break;
|
|
181
179
|
case ValueType.TYPE_VEC_VEC_U8:
|
|
180
|
+
case ValueType.TYPE_VEC_STRING:
|
|
182
181
|
r = ulebDecode(Uint8Array.from(arr)); arr.splice(0, r.length);
|
|
183
182
|
let res = [];
|
|
184
183
|
for (let i = 0; i < r.value; i++) {
|
|
185
184
|
let r2 = ulebDecode(Uint8Array.from(arr));
|
|
186
|
-
res.push(Bcs.getInstance().de(
|
|
185
|
+
res.push(Bcs.getInstance().de(ValueType.TYPE_VEC_U8, Uint8Array.from(arr)));
|
|
187
186
|
arr.splice(0, r2.length+r2.value);
|
|
188
187
|
}
|
|
189
188
|
value = res;
|
|
@@ -191,7 +190,7 @@ export class GuardParser {
|
|
|
191
190
|
case OperatorType.TYPE_QUERY:
|
|
192
191
|
let t = arr.splice(0, 1); // data-type
|
|
193
192
|
if (t[0] == ValueType.TYPE_ADDRESS || t[0] == ContextType.TYPE_WITNESS_ID) {
|
|
194
|
-
let addr = '0x' + Bcs.getInstance().de(
|
|
193
|
+
let addr = '0x' + Bcs.getInstance().de(ValueType.TYPE_ADDRESS, Uint8Array.from(arr)).toString();
|
|
195
194
|
arr.splice(0, 32); // address
|
|
196
195
|
value = addr;
|
|
197
196
|
cmd = arr.shift()! as number; // cmd
|
|
@@ -208,35 +207,39 @@ export class GuardParser {
|
|
|
208
207
|
}
|
|
209
208
|
break;
|
|
210
209
|
case ValueType.TYPE_OPTION_ADDRESS:
|
|
211
|
-
let read = readOption(arr,
|
|
210
|
+
let read = readOption(arr, ValueType.TYPE_ADDRESS);
|
|
212
211
|
value = read.value;
|
|
213
212
|
if (!read.bNone) arr.splice(0, 32);
|
|
214
213
|
break;
|
|
215
214
|
case ValueType.TYPE_OPTION_BOOL:
|
|
216
|
-
read = readOption(arr,
|
|
215
|
+
read = readOption(arr, ValueType.TYPE_BOOL);
|
|
217
216
|
value = read.value;
|
|
218
217
|
if (!read.bNone) arr.splice(0, 1);
|
|
219
218
|
break;
|
|
220
219
|
case ValueType.TYPE_OPTION_U8:
|
|
221
|
-
read = readOption(arr,
|
|
220
|
+
read = readOption(arr, ValueType.TYPE_U8);
|
|
222
221
|
value = read.value;
|
|
223
222
|
if (!read.bNone) arr.splice(0, 1);
|
|
224
223
|
break;
|
|
225
224
|
case ValueType.TYPE_OPTION_U128:
|
|
226
|
-
read = readOption(arr,
|
|
225
|
+
read = readOption(arr, ValueType.TYPE_U128);
|
|
227
226
|
value = read.value;
|
|
228
227
|
if (!read.bNone) arr.splice(0, 16);
|
|
229
228
|
break;
|
|
230
229
|
case ValueType.TYPE_OPTION_U256:
|
|
231
|
-
read = readOption(arr,
|
|
230
|
+
read = readOption(arr, ValueType.TYPE_U256);
|
|
232
231
|
value = read.value;
|
|
233
232
|
if (!read.bNone) arr.splice(0, 32);
|
|
234
233
|
break;
|
|
235
234
|
case ValueType.TYPE_OPTION_U64:
|
|
236
|
-
read = readOption(arr,
|
|
235
|
+
read = readOption(arr, ValueType.TYPE_U64);
|
|
237
236
|
value = read.value;
|
|
238
237
|
if (!read.bNone) arr.splice(0, 8);
|
|
239
238
|
break;
|
|
239
|
+
case ValueType.TYPE_OPTION_STRING:
|
|
240
|
+
read = readOptionString(arr); // splice in it
|
|
241
|
+
value = read.value;
|
|
242
|
+
break;
|
|
240
243
|
default:
|
|
241
244
|
ERROR(Errors.Fail, 'GuardObject: parse_bcs types')
|
|
242
245
|
}
|
|
@@ -446,7 +449,7 @@ export class GuardParser {
|
|
|
446
449
|
// ValueType.TYPE_ADDRESS: Query_Cmd maybe used the address, so save it for using
|
|
447
450
|
if (v.fields.type == ContextType.TYPE_WITNESS_ID || v.fields.type == ValueType.TYPE_ADDRESS) {
|
|
448
451
|
info.constant.push({identifier:v.fields.identifier, index:this.get_index(), type:v.fields.type,
|
|
449
|
-
value_or_witness:'0x' + Bcs.getInstance().de(
|
|
452
|
+
value_or_witness:'0x' + Bcs.getInstance().de(ValueType.TYPE_ADDRESS, Uint8Array.from(v.fields.value))});
|
|
450
453
|
}
|
|
451
454
|
}
|
|
452
455
|
});
|
|
@@ -476,7 +479,7 @@ export class GuardParser {
|
|
|
476
479
|
arr.splice(0, 1); // identifier of constant
|
|
477
480
|
break;
|
|
478
481
|
case ContextType.TYPE_WITNESS_ID: // add to constant
|
|
479
|
-
let addr = '0x' + Bcs.getInstance().de(
|
|
482
|
+
let addr = '0x' + Bcs.getInstance().de(ValueType.TYPE_ADDRESS, Uint8Array.from(arr)).toString();
|
|
480
483
|
arr.splice(0, 32); // address
|
|
481
484
|
info.input_witness.push({index:this.get_index(), type:ContextType.TYPE_WITNESS_ID, value_or_witness:addr})
|
|
482
485
|
break;
|
|
@@ -503,7 +506,7 @@ export class GuardParser {
|
|
|
503
506
|
case OperatorType.TYPE_QUERY:
|
|
504
507
|
let type = arr.splice(0, 1);
|
|
505
508
|
if (type[0] == ValueType.TYPE_ADDRESS || type[0] == ContextType.TYPE_WITNESS_ID) {
|
|
506
|
-
let addr = '0x' + Bcs.getInstance().de(
|
|
509
|
+
let addr = '0x' + Bcs.getInstance().de(ValueType.TYPE_ADDRESS, Uint8Array.from(arr)).toString();
|
|
507
510
|
arr.splice(0, 33); // address + cmd
|
|
508
511
|
if (type[0] == ValueType.TYPE_ADDRESS) {
|
|
509
512
|
info.query_list.push(addr);
|
package/src/permission.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { BCS } from '@mysten/bcs';
|
|
|
2
2
|
import { FnCallType, TxbObject, PermissionObject, PermissionAddress, GuardObject, Protocol} from './protocol';
|
|
3
3
|
import { array_unique, IsValidAddress, IsValidArray, IsValidDesription, IsValidUint, Bcs} from './utils';
|
|
4
4
|
import { ERROR, Errors } from './exception';
|
|
5
|
-
import {
|
|
5
|
+
import { ValueType } from './protocol';
|
|
6
6
|
|
|
7
7
|
export enum PermissionIndex {
|
|
8
8
|
repository = 100,
|
|
@@ -236,7 +236,7 @@ export class Permission {
|
|
|
236
236
|
txb.moveCall({
|
|
237
237
|
target:this.protocol.PermissionFn('remove_index') as FnCallType,
|
|
238
238
|
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(entity_address, BCS.ADDRESS),
|
|
239
|
-
txb.pure(Bcs.getInstance().
|
|
239
|
+
txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_U64, array_unique(index)))]
|
|
240
240
|
})
|
|
241
241
|
}
|
|
242
242
|
remove_entity(entity_address:string[]) {
|
package/src/progress.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BCS } from '@mysten/bcs';
|
|
2
2
|
import { FnCallType, PermissionObject, RepositoryObject, PassportObject, MachineObject,
|
|
3
|
-
ProgressObject, ProgressAddress, Protocol,
|
|
3
|
+
ProgressObject, ProgressAddress, Protocol, ValueType,
|
|
4
4
|
TxbObject} from './protocol';
|
|
5
5
|
import { Bcs, array_unique,IsValidName, IsValidAddress, IsValidArray, OptionNone, IsValidInt } from './utils'
|
|
6
6
|
import { ERROR, Errors } from './exception';
|
|
@@ -86,15 +86,7 @@ export class Progress {
|
|
|
86
86
|
arguments: [Protocol.TXB_OBJECT(txb, this.object)],
|
|
87
87
|
})
|
|
88
88
|
}
|
|
89
|
-
|
|
90
|
-
mark(like:'like' | 'unlike', resource:Resource) {
|
|
91
|
-
let txb = this.protocol.CurrentSession();
|
|
92
|
-
txb.moveCall({
|
|
93
|
-
target:this.protocol.ProgressFn(like) as FnCallType,
|
|
94
|
-
arguments: [Protocol.TXB_OBJECT(txb, resource.get_object()), Protocol.TXB_OBJECT(txb, this.object)],
|
|
95
|
-
})
|
|
96
|
-
}
|
|
97
|
-
*/
|
|
89
|
+
|
|
98
90
|
set_namedOperator(name:string, addresses:string[], passport?:PassportObject) {
|
|
99
91
|
if (!IsValidName(name)) {
|
|
100
92
|
ERROR(Errors.IsValidName, 'name')
|
|
@@ -252,8 +244,8 @@ export class Progress {
|
|
|
252
244
|
}
|
|
253
245
|
|
|
254
246
|
let txb = this.protocol.CurrentSession();
|
|
255
|
-
let diliverable = deliverables_address? txb.pure(Bcs.getInstance().
|
|
256
|
-
let sub = sub_id? txb.pure(Bcs.getInstance().
|
|
247
|
+
let diliverable = deliverables_address? txb.pure(Bcs.getInstance().ser(ValueType.TYPE_OPTION_ADDRESS, deliverables_address)) : OptionNone(txb)
|
|
248
|
+
let sub = sub_id? txb.pure(Bcs.getInstance().ser(ValueType.TYPE_OPTION_ADDRESS, sub_id)) : OptionNone(txb)
|
|
257
249
|
|
|
258
250
|
if (passport) {
|
|
259
251
|
txb.moveCall({
|
package/src/protocol.ts
CHANGED
|
@@ -94,8 +94,12 @@ export enum ValueType {
|
|
|
94
94
|
TYPE_OPTION_U64 = 114,
|
|
95
95
|
TYPE_OPTION_U128 = 115,
|
|
96
96
|
TYPE_OPTION_U256 = 116,
|
|
97
|
-
|
|
98
|
-
|
|
97
|
+
TYPE_OPTION_STRING = 117,
|
|
98
|
+
TYPE_OPTION_VEC_U8 = 118,
|
|
99
|
+
TYPE_VEC_U256 = 119,
|
|
100
|
+
TYPE_STRING = 120,
|
|
101
|
+
TYPE_VEC_STRING = 121,
|
|
102
|
+
TYPE_U256 = 122,
|
|
99
103
|
}
|
|
100
104
|
|
|
101
105
|
export const OperatorTypeArray = (Object.values(OperatorType) as []).filter((v)=>typeof(v) === 'number') as number[];
|
|
@@ -114,7 +118,7 @@ export const SER_VALUE: ValueTypeString[] = [
|
|
|
114
118
|
{type: ValueType.TYPE_ADDRESS, name: 'address', description:'address or object-id. eg:0x6789af'},
|
|
115
119
|
{type: ValueType.TYPE_U64, name: 'number', description:'unsigned-64 number. eg:23870233'},
|
|
116
120
|
{type: ValueType.TYPE_U8, name: 'number', description:'unsigned-8 number. eg:255'},
|
|
117
|
-
{type: ValueType.TYPE_VEC_U8, name: '[number]', description:'unsigned-8 number array. eg:"
|
|
121
|
+
{type: ValueType.TYPE_VEC_U8, name: '[number]', description:'unsigned-8 number array. eg:"[1,2,3]"'},
|
|
118
122
|
{type: ValueType.TYPE_U128, name: 'number', description:'unsigned-8 number. eg:12348900999'},
|
|
119
123
|
{type: ValueType.TYPE_VEC_ADDRESS, name: '[address]', description:'address array. eg:[0x2277f2, 0x3344af]'},
|
|
120
124
|
{type: ValueType.TYPE_VEC_BOOL, name: '[bool]', description:'boolean array. eg:[true, false, true]'},
|
|
@@ -128,6 +132,9 @@ export const SER_VALUE: ValueTypeString[] = [
|
|
|
128
132
|
{type: ValueType.TYPE_OPTION_U128, name: 'option', description:'option of u128. eg:none or u128 value'},
|
|
129
133
|
{type: ValueType.TYPE_OPTION_U256, name: 'option', description:'option of u256. eg:none or u256 value'},
|
|
130
134
|
{type: ValueType.TYPE_VEC_U256, name: '[number]', description:'unsigned-256 number array. eg:[123, 778888, 42312]'},
|
|
135
|
+
{type: ValueType.TYPE_VEC_STRING, name: '[string]', description:'ascii string array. eg:["abc", "hi"]'},
|
|
136
|
+
{type: ValueType.TYPE_STRING, name: 'string', description:'ascii string. eg:"wowok"'},
|
|
137
|
+
{type: ValueType.TYPE_OPTION_STRING, name: 'option', description:'option of string. eg:none or string value'},
|
|
131
138
|
{type: ValueType.TYPE_U256, name: 'number', description:'unsigned-256 number. eg:12345678901233'},
|
|
132
139
|
]
|
|
133
140
|
|
|
@@ -177,9 +184,9 @@ export class Protocol {
|
|
|
177
184
|
case ENTRYPOINT.devnet:
|
|
178
185
|
break;
|
|
179
186
|
case ENTRYPOINT.testnet:
|
|
180
|
-
this.package = "
|
|
181
|
-
this.wowok_object = '
|
|
182
|
-
this.entity_object= '
|
|
187
|
+
this.package = "0x36cf5c284b715bfad79d281f040c225affe36be0e4c79646b946cfe4808243c8";
|
|
188
|
+
this.wowok_object = '0x1fb5abaf85afa41a4b7766c07b3894dd5f81938693bf7c19c354f97f28ea2791';
|
|
189
|
+
this.entity_object= '0xea38eaef3446eec1b131f21ca6a6f8b2b38bb16f5b660bafea5904b6a49128e9';
|
|
183
190
|
this.graphql = 'https://sui-testnet.mystenlabs.com/graphql';
|
|
184
191
|
break;
|
|
185
192
|
case ENTRYPOINT.mainnet:
|
package/src/repository.ts
CHANGED
|
@@ -82,16 +82,7 @@ export class Repository {
|
|
|
82
82
|
arguments: [Protocol.TXB_OBJECT(txb, this.object)],
|
|
83
83
|
})
|
|
84
84
|
}
|
|
85
|
-
|
|
86
|
-
mark(like:'like' | 'unlike', resource:Resource) {
|
|
87
|
-
if (!Protocol.IsValidObjects([this.object])) return false;
|
|
88
|
-
let txb = this.protocol.CurrentSession();
|
|
89
|
-
txb.moveCall({
|
|
90
|
-
target:this.protocol.RepositoryFn(like) as FnCallType,
|
|
91
|
-
arguments: [Protocol.TXB_OBJECT(txb, resource.get_object()), Protocol.TXB_OBJECT(txb, this.object)],
|
|
92
|
-
})
|
|
93
|
-
}
|
|
94
|
-
*/
|
|
85
|
+
|
|
95
86
|
add_data(data:Repository_Policy_Data) {
|
|
96
87
|
if (!Repository.IsValidName(data.key)) {
|
|
97
88
|
ERROR(Errors.IsValidName)
|
|
@@ -235,7 +226,7 @@ export class Repository {
|
|
|
235
226
|
|
|
236
227
|
let txb = this.protocol.CurrentSession();
|
|
237
228
|
policies.forEach((policy) => {
|
|
238
|
-
let permission_index = policy?.permission ? txb.pure(Bcs.getInstance().
|
|
229
|
+
let permission_index = policy?.permission ? txb.pure(Bcs.getInstance().ser(ValueType.TYPE_OPTION_U64, policy.permission)) : OptionNone(txb);
|
|
239
230
|
if (passport) {
|
|
240
231
|
txb.moveCall({
|
|
241
232
|
target:this.protocol.RepositoryFn('policy_add_with_passport') as FnCallType,
|
|
@@ -277,7 +268,7 @@ export class Repository {
|
|
|
277
268
|
txb.moveCall({
|
|
278
269
|
target:this.protocol.RepositoryFn('policy_remove_with_passport') as FnCallType,
|
|
279
270
|
arguments:[passport, Protocol.TXB_OBJECT(txb, this.object),
|
|
280
|
-
txb.pure(Bcs.getInstance().
|
|
271
|
+
txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, array_unique(policy_keys))),
|
|
281
272
|
Protocol.TXB_OBJECT(txb, this.permission)]
|
|
282
273
|
})
|
|
283
274
|
}
|
|
@@ -291,7 +282,7 @@ export class Repository {
|
|
|
291
282
|
txb.moveCall({
|
|
292
283
|
target:this.protocol.RepositoryFn('policy_remove') as FnCallType,
|
|
293
284
|
arguments:[Protocol.TXB_OBJECT(txb, this.object),
|
|
294
|
-
txb.pure(Bcs.getInstance().
|
|
285
|
+
txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, array_unique(policy_keys))),
|
|
295
286
|
Protocol.TXB_OBJECT(txb, this.permission)]
|
|
296
287
|
})
|
|
297
288
|
}
|
|
@@ -371,7 +362,7 @@ export class Repository {
|
|
|
371
362
|
if(!Permission.IsValidPermissionIndex(permission_index)) {
|
|
372
363
|
ERROR(Errors.IsValidPermissionIndex)
|
|
373
364
|
}
|
|
374
|
-
index = txb.pure(Bcs.getInstance().
|
|
365
|
+
index = txb.pure(Bcs.getInstance().ser(ValueType.TYPE_OPTION_U64, permission_index));
|
|
375
366
|
}
|
|
376
367
|
|
|
377
368
|
if (passport) {
|