wowok 1.3.13 → 1.4.16
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 +1 -1
- package/src/exception.ts +1 -1
- package/src/guard.ts +94 -79
- package/src/passport.ts +34 -31
- package/src/protocol.ts +5 -13
- package/src/repository.ts +2 -2
- package/src/utils.ts +18 -10
package/package.json
CHANGED
package/src/exception.ts
CHANGED
package/src/guard.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { Protocol, LogicsInfo, GuardAddress, FnCallType, Data_Type, MODULES, ContextType, ValueType, OperatorType, ConstantType, SER_VALUE} from './protocol';
|
|
4
4
|
import { concatenate, array_equal } from './utils';
|
|
5
|
-
import { IsValidDesription, Bcs, IsValidInt, IsValidAddress, FirstLetterUppercase } from './utils';
|
|
5
|
+
import { IsValidDesription, Bcs, IsValidInt, IsValidAddress, FirstLetterUppercase, insertAtHead } from './utils';
|
|
6
6
|
import { ERROR, Errors } from './exception';
|
|
7
7
|
import { Transaction as TransactionBlock } from '@mysten/sui/transactions';
|
|
8
8
|
|
|
@@ -59,19 +59,19 @@ export class Guard {
|
|
|
59
59
|
if (!v.witness) {
|
|
60
60
|
ERROR(Errors.InvalidParam, 'constants type')
|
|
61
61
|
}
|
|
62
|
-
|
|
62
|
+
const n = insertAtHead(v.witness!, v.type);
|
|
63
63
|
txb.moveCall({
|
|
64
64
|
target:Protocol.Instance().GuardFn("constant_add") as FnCallType,
|
|
65
|
-
arguments:[guard, txb.pure.u8(k), txb.pure.
|
|
65
|
+
arguments:[guard, txb.pure.u8(k), txb.pure.vector('u8', [].slice.call(n)), txb.pure.bool(true)]
|
|
66
66
|
})
|
|
67
67
|
} else {
|
|
68
68
|
if (!v.value) {
|
|
69
69
|
ERROR(Errors.InvalidParam, 'constants type')
|
|
70
70
|
}
|
|
71
|
-
|
|
71
|
+
const n = insertAtHead(v.value!, v.type);
|
|
72
72
|
txb.moveCall({
|
|
73
73
|
target:Protocol.Instance().GuardFn("constant_add") as FnCallType,
|
|
74
|
-
arguments:[guard, txb.pure.u8(k), txb.pure.
|
|
74
|
+
arguments:[guard, txb.pure.u8(k), txb.pure.vector('u8', [].slice.call(n)), txb.pure.bool(true)]
|
|
75
75
|
})
|
|
76
76
|
}
|
|
77
77
|
});
|
|
@@ -115,20 +115,29 @@ export class Guard {
|
|
|
115
115
|
[MODULES.repository, 'Value Type of Policy', 15, [ValueType.TYPE_STRING], ValueType.TYPE_U8, 'Data types defined by consensus policy.', 'Input:the policy name'],
|
|
116
116
|
[MODULES.repository, 'Contains Data for An Address', 16, [ValueType.TYPE_ADDRESS], ValueType.TYPE_BOOL, 'Whether data exists at a certain address?', 'Input:address'],
|
|
117
117
|
[MODULES.repository, 'Contains Data', 17, [ValueType.TYPE_ADDRESS, ValueType.TYPE_STRING], ValueType.TYPE_BOOL, 'Does it contain data for a certain field of an address?', 'Input 1:address, Input 2:the field name'],
|
|
118
|
-
[MODULES.repository, '
|
|
119
|
-
[MODULES.repository, '
|
|
118
|
+
[MODULES.repository, 'Raw data without Type', 18, [ValueType.TYPE_ADDRESS, ValueType.TYPE_STRING], ValueType.TYPE_VEC_U8, 'Data for a field at an address and does not contain data type information.', 'Input 1:address, Input 2:the field name'],
|
|
119
|
+
[MODULES.repository, 'Raw data', 19, [ValueType.TYPE_ADDRESS, ValueType.TYPE_STRING], ValueType.TYPE_VEC_U8, 'Data for a field at an address, and the first byte contains data type information.', 'Input 1:address, Input 2:the field name'],
|
|
120
120
|
[MODULES.repository, 'Type', 20, [], ValueType.TYPE_U8, 'The repository Type. 0: Normal; 1: Wowok greenee.'],
|
|
121
121
|
[MODULES.repository, 'Policy Mode', 21, [], ValueType.TYPE_U8, 'Policy Mode. 0: Free mode; 1: Strict mode.'],
|
|
122
122
|
[MODULES.repository, 'Reference Count', 22, [], ValueType.TYPE_U64, 'The number of times it is referenced by other objects.'],
|
|
123
123
|
[MODULES.repository, 'Is Referenced by An Object', 23, [ValueType.TYPE_ADDRESS], ValueType.TYPE_BOOL, 'Is it referenced by an object?', 'Input:address'],
|
|
124
|
+
[MODULES.repository, 'Data Number', 24, [ValueType.TYPE_ADDRESS, ValueType.TYPE_STRING], ValueType.TYPE_U256, 'Data for a field at an address and get unsigned integer type data.', 'Input 1:address, Input 2:the field name'],
|
|
125
|
+
[MODULES.repository, 'Data String', 25, [ValueType.TYPE_ADDRESS, ValueType.TYPE_STRING], ValueType.TYPE_STRING, 'Data for a field at an address and get string type data.', 'Input 1:address, Input 2:the field name'],
|
|
126
|
+
[MODULES.repository, 'Data Address', 26, [ValueType.TYPE_ADDRESS, ValueType.TYPE_STRING], ValueType.TYPE_ADDRESS, 'Data for a field at an address and get address type data.', 'Input 1:address, Input 2:the field name'],
|
|
127
|
+
[MODULES.repository, 'Data Bool', 27, [ValueType.TYPE_ADDRESS, ValueType.TYPE_STRING], ValueType.TYPE_BOOL, 'Data for a field at an address and get bool type data.', 'Input 1:address, Input 2:the field name'],
|
|
128
|
+
[MODULES.repository, 'Data Number Vector', 28, [ValueType.TYPE_ADDRESS, ValueType.TYPE_STRING], ValueType.TYPE_VEC_U256, 'Data for a field at an address and get unsigned integer vector type data.', 'Input 1:address, Input 2:the field name'],
|
|
129
|
+
[MODULES.repository, 'Data String Vector', 29, [ValueType.TYPE_ADDRESS, ValueType.TYPE_STRING], ValueType.TYPE_VEC_STRING, 'Data for a field at an address and get string vector type data.', 'Input 1:address, Input 2:the field name'],
|
|
130
|
+
[MODULES.repository, 'Data Address Vector', 30, [ValueType.TYPE_ADDRESS, ValueType.TYPE_STRING], ValueType.TYPE_VEC_ADDRESS, 'Data for a field at an address and get address vector type data.', 'Input 1:address, Input 2:the field name'],
|
|
131
|
+
[MODULES.repository, 'Data Bool Vector', 31, [ValueType.TYPE_ADDRESS, ValueType.TYPE_STRING], ValueType.TYPE_VEC_BOOL, 'Data for a field at an address and get bool vector type data.', 'Input 1:address, Input 2:the field name'],
|
|
132
|
+
|
|
124
133
|
// , means that data fields and data outside the consensus policy definition are allowed to be written
|
|
125
134
|
// , means that only data fields and data defined by the consensus policy are allowed to be written.
|
|
126
|
-
[MODULES.machine, 'Permission',
|
|
127
|
-
[MODULES.machine, 'Paused',
|
|
128
|
-
[MODULES.machine, 'Published',
|
|
129
|
-
[MODULES.machine, 'Is Consensus Repository',
|
|
130
|
-
[MODULES.machine, 'Has Endpoint',
|
|
131
|
-
[MODULES.machine, 'Endpoint',
|
|
135
|
+
[MODULES.machine, 'Permission', 41, [], ValueType.TYPE_ADDRESS, 'Permission object address.'],
|
|
136
|
+
[MODULES.machine, 'Paused', 42, [], ValueType.TYPE_BOOL, 'Pause the creation of new Progress?'],
|
|
137
|
+
[MODULES.machine, 'Published', 43, [], ValueType.TYPE_BOOL, 'Is it allowed to create Progress?'],
|
|
138
|
+
[MODULES.machine, 'Is Consensus Repository', 44, [ValueType.TYPE_ADDRESS], ValueType.TYPE_BOOL, 'Whether an address is a consensus repository?', 'Input:adddress'],
|
|
139
|
+
[MODULES.machine, 'Has Endpoint', 45, [], ValueType.TYPE_BOOL, 'Is the endpoint set?'],
|
|
140
|
+
[MODULES.machine, 'Endpoint', 46, [], ValueType.TYPE_STRING, 'Endpoint url/ipfs.'],
|
|
132
141
|
|
|
133
142
|
[MODULES.progress, 'Machine', 51, [], ValueType.TYPE_ADDRESS, 'The Machine object that created this Progress.'],
|
|
134
143
|
[MODULES.progress, 'Current Node', 52, [], ValueType.TYPE_STRING, 'The name of the currently running node.'],
|
|
@@ -295,7 +304,7 @@ export class Guard {
|
|
|
295
304
|
}
|
|
296
305
|
|
|
297
306
|
static StringOptions = () : Guard_Options[] => {
|
|
298
|
-
return [...Guard.CmdFilter(ValueType.
|
|
307
|
+
return [...Guard.CmdFilter(ValueType.TYPE_STRING)].map((v) => {
|
|
299
308
|
return {from:'query', name:v[1], value:v[2], group:FirstLetterUppercase(v[0])};
|
|
300
309
|
});
|
|
301
310
|
}
|
|
@@ -362,11 +371,12 @@ export class GuardConstantHelper {
|
|
|
362
371
|
}
|
|
363
372
|
}
|
|
364
373
|
|
|
365
|
-
static add_constant(constants:GuardConstant, identifier:number, type:ValueType
|
|
374
|
+
static add_constant(constants:GuardConstant, identifier:number, type:ValueType, value:any, bNeedSerialize=true) {
|
|
375
|
+
const e = SER_VALUE.find((v:any)=>v.type===type)?.name ?? '' + ' invalid';
|
|
366
376
|
if (!GuardConstantHelper.IsValidIndentifier(identifier)) {
|
|
367
377
|
ERROR(Errors.InvalidParam, 'add_constant identifier')
|
|
368
378
|
}
|
|
369
|
-
if (
|
|
379
|
+
if (value === undefined) {
|
|
370
380
|
ERROR(Errors.InvalidParam, 'add_constant value')
|
|
371
381
|
}
|
|
372
382
|
|
|
@@ -390,17 +400,20 @@ export class GuardConstantHelper {
|
|
|
390
400
|
case ValueType.TYPE_VEC_U128:
|
|
391
401
|
case ValueType.TYPE_VEC_U256:
|
|
392
402
|
case ValueType.TYPE_STRING:
|
|
393
|
-
case ValueType.TYPE_VEC_U8:
|
|
403
|
+
case ValueType.TYPE_VEC_U8:
|
|
404
|
+
case ValueType.TYPE_OPTION_STRING:
|
|
405
|
+
case ValueType.TYPE_OPTION_VEC_U8:
|
|
406
|
+
case ValueType.TYPE_VEC_STRING:
|
|
394
407
|
let ser = SER_VALUE.find(s=>s.type==type);
|
|
395
|
-
if (!ser) ERROR(Errors.Fail, 'add_constant: invalid type');
|
|
408
|
+
if (!ser) ERROR(Errors.Fail, 'add_constant: invalid type:'+e);
|
|
396
409
|
if (bNeedSerialize) {
|
|
397
|
-
constants.set(identifier, {type:type, value:Bcs.getInstance().ser(
|
|
410
|
+
constants.set(identifier, {type:type, value:Bcs.getInstance().ser(type, value)})
|
|
398
411
|
} else {
|
|
399
412
|
constants.set(identifier, {type:type, value:value})
|
|
400
413
|
}
|
|
401
414
|
return
|
|
402
415
|
default:
|
|
403
|
-
ERROR(Errors.Fail, 'add_constant serialize not impl yet')
|
|
416
|
+
ERROR(Errors.Fail, 'add_constant serialize not impl yet:'+e)
|
|
404
417
|
}
|
|
405
418
|
}
|
|
406
419
|
}
|
|
@@ -421,7 +434,7 @@ export class GuardMaker {
|
|
|
421
434
|
|
|
422
435
|
add_constant(type:ConstantType, value:any, identifier?:number, bNeedSerialize=true) : number {
|
|
423
436
|
if (identifier === undefined) identifier = GuardMaker.get_index();
|
|
424
|
-
if (type
|
|
437
|
+
if (type === ContextType.TYPE_WITNESS_ID) {
|
|
425
438
|
// add witness to constant
|
|
426
439
|
GuardConstantHelper.add_future_constant(this.constant, identifier, value, undefined, bNeedSerialize);
|
|
427
440
|
} else {
|
|
@@ -431,7 +444,7 @@ export class GuardMaker {
|
|
|
431
444
|
}
|
|
432
445
|
|
|
433
446
|
private serValueParam(type:ValueType, param?:any) {
|
|
434
|
-
if (
|
|
447
|
+
if (param === undefined) ERROR(Errors.InvalidParam, 'param');
|
|
435
448
|
this.data.push(Bcs.getInstance().ser(ValueType.TYPE_U8, type));
|
|
436
449
|
let ser = SER_VALUE.find(s=>s.type==type);
|
|
437
450
|
if (!ser) ERROR(Errors.Fail, 'serValueParam: invalid type');
|
|
@@ -441,6 +454,8 @@ export class GuardMaker {
|
|
|
441
454
|
|
|
442
455
|
// serialize const & data
|
|
443
456
|
add_param(type:ValueType | ContextType, param?:any) : GuardMaker {
|
|
457
|
+
const e = SER_VALUE.find((v:any)=>v.type===type)?.name ?? '' + ' invalid';
|
|
458
|
+
|
|
444
459
|
switch(type) {
|
|
445
460
|
case ValueType.TYPE_ADDRESS:
|
|
446
461
|
case ValueType.TYPE_BOOL:
|
|
@@ -464,7 +479,7 @@ export class GuardMaker {
|
|
|
464
479
|
break;
|
|
465
480
|
case ValueType.TYPE_STRING:
|
|
466
481
|
case ValueType.TYPE_VEC_U8:
|
|
467
|
-
if (!param) ERROR(Errors.InvalidParam, 'param');
|
|
482
|
+
if (!param) ERROR(Errors.InvalidParam, 'param:'+e);
|
|
468
483
|
this.data.push(Bcs.getInstance().ser(ValueType.TYPE_U8, type)); //@ USE VEC-U8
|
|
469
484
|
if (typeof(param) == 'string') {
|
|
470
485
|
this.data.push(Bcs.getInstance().ser(ValueType.TYPE_STRING, param));
|
|
@@ -482,56 +497,56 @@ export class GuardMaker {
|
|
|
482
497
|
this.type_validator.push(ValueType.TYPE_U64);
|
|
483
498
|
break;
|
|
484
499
|
case ContextType.TYPE_WITNESS_ID:
|
|
485
|
-
if (!param) ERROR(Errors.InvalidParam, 'param');
|
|
500
|
+
if (!param) ERROR(Errors.InvalidParam, 'param:'+e);
|
|
486
501
|
this.data.push(Bcs.getInstance().ser(ValueType.TYPE_U8, type));
|
|
487
502
|
this.data.push(Bcs.getInstance().ser(ValueType.TYPE_ADDRESS, param));
|
|
488
503
|
this.type_validator.push(ValueType.TYPE_ADDRESS);
|
|
489
504
|
break;
|
|
490
505
|
case ContextType.TYPE_CONSTANT:
|
|
491
506
|
if (!param) {
|
|
492
|
-
ERROR(Errors.InvalidParam, 'param invalid');
|
|
507
|
+
ERROR(Errors.InvalidParam, 'param invalid:'+e);
|
|
493
508
|
}
|
|
494
509
|
if (typeof(param) != 'number' || !IsValidInt(param) || param > 255) {
|
|
495
|
-
ERROR(Errors.InvalidParam, 'add_param param');
|
|
510
|
+
ERROR(Errors.InvalidParam, 'add_param param:'+type);
|
|
496
511
|
}
|
|
497
512
|
|
|
498
513
|
var v = this.constant.get(param);
|
|
499
|
-
if (!v) ERROR(Errors.Fail, 'identifier not in constant');
|
|
514
|
+
if (!v) ERROR(Errors.Fail, 'identifier not in constant:'+e);
|
|
500
515
|
this.type_validator.push(v!.type);
|
|
501
516
|
this.data.push(Bcs.getInstance().ser(ValueType.TYPE_U8, type));
|
|
502
517
|
this.data.push(Bcs.getInstance().ser(ValueType.TYPE_U8, param));
|
|
503
518
|
break;
|
|
504
519
|
default:
|
|
505
|
-
ERROR(Errors.InvalidParam, 'add_param type'
|
|
520
|
+
ERROR(Errors.InvalidParam, 'add_param type:'+e);
|
|
506
521
|
};
|
|
507
522
|
return this;
|
|
508
523
|
}
|
|
509
524
|
|
|
510
525
|
// object_address_from: string for static address; number as identifier inconstant
|
|
511
|
-
add_query(module:MODULES, query_name:string, object_address_from:string | number, bWitness:boolean=false) : GuardMaker {
|
|
526
|
+
add_query(module:MODULES, query_name:string, object_address_from:string | number, bWitness:boolean=false) : GuardMaker {
|
|
512
527
|
let query_index = Guard.QUERIES.findIndex((q) => { return q[0] == module && q[1] == query_name})
|
|
513
528
|
if (query_index == -1) {
|
|
514
|
-
ERROR(Errors.InvalidParam, 'query_name');
|
|
529
|
+
ERROR(Errors.InvalidParam, 'query_name:'+query_name);
|
|
515
530
|
}
|
|
516
531
|
|
|
517
532
|
if (typeof(object_address_from) == 'number' ) {
|
|
518
533
|
if (!GuardConstantHelper.IsValidIndentifier(object_address_from)) {
|
|
519
|
-
ERROR(Errors.InvalidParam, 'object_address_from');
|
|
534
|
+
ERROR(Errors.InvalidParam, 'object_address_from:'+query_name);
|
|
520
535
|
}
|
|
521
536
|
} else {
|
|
522
537
|
if (!IsValidAddress(object_address_from)) {
|
|
523
|
-
ERROR(Errors.InvalidParam, 'object_address_from');
|
|
538
|
+
ERROR(Errors.InvalidParam, 'object_address_from:'+query_name);
|
|
524
539
|
}
|
|
525
540
|
}
|
|
526
541
|
|
|
527
542
|
let offset = this.type_validator.length - Guard.QUERIES[query_index][3].length;
|
|
528
543
|
if (offset < 0) {
|
|
529
|
-
ERROR(Errors.InvalidParam, 'query_name');
|
|
544
|
+
ERROR(Errors.InvalidParam, 'query_name:'+query_name);
|
|
530
545
|
}
|
|
531
546
|
|
|
532
547
|
let types = this.type_validator.slice(offset);
|
|
533
548
|
if (!array_equal(types, Guard.QUERIES[query_index][3])) { // type validate
|
|
534
|
-
ERROR(Errors.Fail, 'array_equal');
|
|
549
|
+
ERROR(Errors.Fail, 'array_equal:'+query_name);
|
|
535
550
|
}
|
|
536
551
|
|
|
537
552
|
this.data.push(Bcs.getInstance().ser(ValueType.TYPE_U8, OperatorType.TYPE_QUERY)); // QUERY TYPE
|
|
@@ -541,12 +556,12 @@ export class GuardMaker {
|
|
|
541
556
|
this.data.push(Bcs.getInstance().ser(ValueType.TYPE_ADDRESS, object_address_from)); // object address
|
|
542
557
|
} else {
|
|
543
558
|
let v = this.constant.get(object_address_from);
|
|
544
|
-
if (!v) ERROR(Errors.Fail, 'object_address_from not in constant');
|
|
559
|
+
if (!v) ERROR(Errors.Fail, 'object_address_from not in constant:'+query_name);
|
|
545
560
|
if ((bWitness && v?.type == ContextType.TYPE_WITNESS_ID) || (!bWitness && v?.type == ValueType.TYPE_ADDRESS)) {
|
|
546
561
|
this.data.push(Bcs.getInstance().ser(ValueType.TYPE_U8, ContextType.TYPE_CONSTANT));
|
|
547
562
|
this.data.push(Bcs.getInstance().ser(ValueType.TYPE_U8, object_address_from)); // object identifer in constants
|
|
548
563
|
} else {
|
|
549
|
-
ERROR(Errors.Fail, 'type bWitness not match')
|
|
564
|
+
ERROR(Errors.Fail, 'type bWitness not match:'+query_name)
|
|
550
565
|
}
|
|
551
566
|
}
|
|
552
567
|
|
|
@@ -556,7 +571,10 @@ export class GuardMaker {
|
|
|
556
571
|
return this;
|
|
557
572
|
}
|
|
558
573
|
|
|
559
|
-
add_logic(type:OperatorType) : GuardMaker {
|
|
574
|
+
add_logic(type:OperatorType, param:number=2) : GuardMaker {
|
|
575
|
+
var e:any = LogicsInfo.find((v:any) => v[0] === type);
|
|
576
|
+
if (e) { e=e[1] }
|
|
577
|
+
|
|
560
578
|
let splice_len = 2;
|
|
561
579
|
let ret = ValueType.TYPE_BOOL;
|
|
562
580
|
switch (type) {
|
|
@@ -565,43 +583,41 @@ export class GuardMaker {
|
|
|
565
583
|
case OperatorType.TYPE_LOGIC_AS_U256_LESSER:
|
|
566
584
|
case OperatorType.TYPE_LOGIC_AS_U256_LESSER_EQUAL:
|
|
567
585
|
case OperatorType.TYPE_LOGIC_AS_U256_EQUAL:
|
|
568
|
-
if (this.type_validator.length < splice_len) { ERROR(Errors.Fail, 'type_validator.length') }
|
|
569
|
-
if (!GuardMaker.match_u256(this.type_validator[this.type_validator.length - 1])) { ERROR(Errors.Fail, 'type_validator check') }
|
|
570
|
-
if (!GuardMaker.match_u256(this.type_validator[this.type_validator.length - 2])) { ERROR(Errors.Fail, 'type_validator check') }
|
|
586
|
+
if (this.type_validator.length < splice_len) { ERROR(Errors.Fail, 'type_validator.length:' + e) }
|
|
587
|
+
if (!GuardMaker.match_u256(this.type_validator[this.type_validator.length - 1])) { ERROR(Errors.Fail, 'type_validator check:'+e) }
|
|
588
|
+
if (!GuardMaker.match_u256(this.type_validator[this.type_validator.length - 2])) { ERROR(Errors.Fail, 'type_validator check:'+e) }
|
|
571
589
|
break;
|
|
572
590
|
case OperatorType.TYPE_LOGIC_EQUAL:
|
|
573
|
-
if (this.type_validator.length < splice_len) { ERROR(Errors.Fail, 'type_validator.length') }
|
|
591
|
+
if (this.type_validator.length < splice_len) { ERROR(Errors.Fail, 'type_validator.length:' + e) }
|
|
592
|
+
if (GuardMaker.match_u256(this.type_validator[this.type_validator.length - 1]) &&
|
|
593
|
+
GuardMaker.match_u256(this.type_validator[this.type_validator.length - 2])) {
|
|
594
|
+
break;
|
|
595
|
+
} else if (this.type_validator[this.type_validator.length - 1] === this.type_validator[this.type_validator.length - 2]) {
|
|
596
|
+
break;
|
|
597
|
+
} else {
|
|
598
|
+
ERROR(Errors.Fail, 'type_validator check:' + e) ;
|
|
599
|
+
}
|
|
574
600
|
break;
|
|
575
601
|
case OperatorType.TYPE_LOGIC_HAS_SUBSTRING:
|
|
576
|
-
if (this.type_validator.length < splice_len) { ERROR(Errors.Fail, 'type_validator.length') }
|
|
602
|
+
if (this.type_validator.length < splice_len) { ERROR(Errors.Fail, 'type_validator.length:' + e) }
|
|
603
|
+
if (this.type_validator[this.type_validator.length - 1] !== ValueType.TYPE_STRING ||
|
|
604
|
+
this.type_validator[this.type_validator.length - 2] !== ValueType.TYPE_STRING) {
|
|
605
|
+
ERROR(Errors.Fail, 'type_validator check:' + e) ;
|
|
606
|
+
}
|
|
577
607
|
break;
|
|
578
608
|
case OperatorType.TYPE_LOGIC_NOT:
|
|
579
609
|
splice_len = 1;
|
|
580
|
-
if (this.type_validator.length < splice_len) { ERROR(Errors.Fail, 'type_validator.length') }
|
|
581
|
-
if (this.type_validator[this.type_validator.length -1] != ValueType.TYPE_BOOL) { ERROR(Errors.Fail, 'type_validator check') }
|
|
610
|
+
if (this.type_validator.length < splice_len) { ERROR(Errors.Fail, 'type_validator.length:'+e) }
|
|
611
|
+
if (this.type_validator[this.type_validator.length -1] != ValueType.TYPE_BOOL) { ERROR(Errors.Fail, 'type_validator check:'+e) }
|
|
582
612
|
break;
|
|
583
613
|
case OperatorType.TYPE_LOGIC_AND:
|
|
584
|
-
case OperatorType.TYPE_LOGIC_OR:
|
|
585
|
-
if (
|
|
586
|
-
|
|
587
|
-
if (this.type_validator
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
splice_len = 3;
|
|
592
|
-
if (this.type_validator.length < splice_len) { ERROR(Errors.Fail, 'type_validator.length') }
|
|
593
|
-
if (this.type_validator[this.type_validator.length -1] != ValueType.TYPE_BOOL) { ERROR(Errors.Fail, 'type_validator check') }
|
|
594
|
-
if (this.type_validator[this.type_validator.length -2] != ValueType.TYPE_BOOL) { ERROR(Errors.Fail, 'type_validator check') }
|
|
595
|
-
if (this.type_validator[this.type_validator.length -3] != ValueType.TYPE_BOOL) { ERROR(Errors.Fail, 'type_validator check') }
|
|
596
|
-
break;
|
|
597
|
-
case OperatorType.TYPE_LOGIC_AND4:
|
|
598
|
-
case OperatorType.TYPE_LOGIC_OR4:
|
|
599
|
-
splice_len = 4;
|
|
600
|
-
if (this.type_validator.length < splice_len) { ERROR(Errors.Fail, 'type_validator.length') }
|
|
601
|
-
if (this.type_validator[this.type_validator.length -1] != ValueType.TYPE_BOOL) { ERROR(Errors.Fail, 'type_validator check') }
|
|
602
|
-
if (this.type_validator[this.type_validator.length -2] != ValueType.TYPE_BOOL) { ERROR(Errors.Fail, 'type_validator check') }
|
|
603
|
-
if (this.type_validator[this.type_validator.length -3] != ValueType.TYPE_BOOL) { ERROR(Errors.Fail, 'type_validator check') }
|
|
604
|
-
if (this.type_validator[this.type_validator.length -4] != ValueType.TYPE_BOOL) { ERROR(Errors.Fail, 'type_validator check') }
|
|
614
|
+
case OperatorType.TYPE_LOGIC_OR: //@ logics count
|
|
615
|
+
if (!param || param < 2) ERROR(Errors.Fail, 'logic param invalid:'+e);
|
|
616
|
+
splice_len = param!;
|
|
617
|
+
if (this.type_validator.length < splice_len) { ERROR(Errors.Fail, 'type_validator.length:'+e) }
|
|
618
|
+
for (let i = 1; i <= splice_len; ++i) {
|
|
619
|
+
if (this.type_validator[this.type_validator.length -i] != ValueType.TYPE_BOOL) { ERROR(Errors.Fail, 'type_validator check:'+e) }
|
|
620
|
+
}
|
|
605
621
|
break;
|
|
606
622
|
case OperatorType.TYPE_LOGIC_ALWAYS_TRUE:
|
|
607
623
|
break;
|
|
@@ -610,15 +626,19 @@ export class GuardMaker {
|
|
|
610
626
|
case OperatorType.TYPE_NUMBER_MULTIPLY:
|
|
611
627
|
case OperatorType.TYPE_NUMBER_SUBTRACT:
|
|
612
628
|
case OperatorType.TYPE_NUMBER_MOD:
|
|
613
|
-
if (this.type_validator.length < splice_len) { ERROR(Errors.Fail, 'type_validator.length') }
|
|
614
|
-
if (!GuardMaker.IsNumberType(this.type_validator[this.type_validator.length -1])) { ERROR(Errors.Fail, 'type_validator check') }
|
|
615
|
-
if (!GuardMaker.IsNumberType(this.type_validator[this.type_validator.length -2])) { ERROR(Errors.Fail, 'type_validator check') }
|
|
629
|
+
if (this.type_validator.length < splice_len) { ERROR(Errors.Fail, 'type_validator.length:'+e) }
|
|
630
|
+
if (!GuardMaker.IsNumberType(this.type_validator[this.type_validator.length -1])) { ERROR(Errors.Fail, 'type_validator check:'+e) }
|
|
631
|
+
if (!GuardMaker.IsNumberType(this.type_validator[this.type_validator.length -2])) { ERROR(Errors.Fail, 'type_validator check:'+e) }
|
|
616
632
|
ret = ValueType.TYPE_U256;
|
|
617
633
|
break;
|
|
618
634
|
default:
|
|
619
|
-
ERROR(Errors.InvalidParam, 'add_logic type invalid' +
|
|
635
|
+
ERROR(Errors.InvalidParam, 'add_logic type invalid:' + e)
|
|
620
636
|
}
|
|
621
|
-
|
|
637
|
+
|
|
638
|
+
this.data.push(Bcs.getInstance().ser(ValueType.TYPE_U8, type)); // TYPE
|
|
639
|
+
if (type === OperatorType.TYPE_LOGIC_AND || type === OperatorType.TYPE_LOGIC_OR) {
|
|
640
|
+
this.data.push((Bcs.getInstance().ser(ValueType.TYPE_U8, param))); //@ logics
|
|
641
|
+
}
|
|
622
642
|
this.type_validator.splice(this.type_validator.length - splice_len); // delete type stack
|
|
623
643
|
this.type_validator.push(ret); // add bool to type stack
|
|
624
644
|
return this;
|
|
@@ -663,7 +683,7 @@ export class GuardMaker {
|
|
|
663
683
|
maker.constant.set(k, {type:v.type, value:v.value, witness:v.witness});
|
|
664
684
|
})
|
|
665
685
|
let op = bAnd ? OperatorType.TYPE_LOGIC_AND : OperatorType.TYPE_LOGIC_OR;
|
|
666
|
-
maker.data.push(concatenate(Uint8Array, ...this.data, ...otherBuilt.data, Bcs.getInstance().ser(ValueType.TYPE_U8, op)));
|
|
686
|
+
maker.data.push(concatenate(Uint8Array, ...this.data, ...otherBuilt.data, Bcs.getInstance().ser(ValueType.TYPE_U8, 2), Bcs.getInstance().ser(ValueType.TYPE_U8, op)));
|
|
667
687
|
this.data.splice(0, this.data.length-1);
|
|
668
688
|
maker.type_validator = this.type_validator;
|
|
669
689
|
return maker
|
|
@@ -672,22 +692,17 @@ export class GuardMaker {
|
|
|
672
692
|
get_constant() { return this.constant }
|
|
673
693
|
get_input() { return this.data }
|
|
674
694
|
|
|
695
|
+
// and/or + logics count
|
|
675
696
|
static input_combine(input1:Uint8Array, input2:Uint8Array, bAnd:boolean = true) : Uint8Array {
|
|
676
697
|
let op = bAnd ? OperatorType.TYPE_LOGIC_AND : OperatorType.TYPE_LOGIC_OR;
|
|
677
|
-
return concatenate(Uint8Array, input1, input2, Bcs.getInstance().ser(ValueType.TYPE_U8, op)) as Uint8Array;
|
|
698
|
+
return concatenate(Uint8Array, input1, input2, Bcs.getInstance().ser(ValueType.TYPE_U8, 2), Bcs.getInstance().ser(ValueType.TYPE_U8, op)) as Uint8Array;
|
|
678
699
|
}
|
|
679
700
|
static input_not(input:Uint8Array) : Uint8Array {
|
|
680
701
|
return concatenate(Uint8Array, input, Bcs.getInstance().ser(ValueType.TYPE_U8, OperatorType.TYPE_LOGIC_NOT)) as Uint8Array;
|
|
681
702
|
}
|
|
682
703
|
|
|
683
704
|
static match_u256(type:number) : boolean {
|
|
684
|
-
|
|
685
|
-
type == ValueType.TYPE_U64 ||
|
|
686
|
-
type == ValueType.TYPE_U128 ||
|
|
687
|
-
type == ValueType.TYPE_U256) {
|
|
688
|
-
return true;
|
|
689
|
-
}
|
|
690
|
-
return false;
|
|
705
|
+
return (type == ValueType.TYPE_U8 || type == ValueType.TYPE_U64 || type == ValueType.TYPE_U128 || type == ValueType.TYPE_U256);
|
|
691
706
|
}
|
|
692
707
|
}
|
|
693
708
|
|
package/src/passport.ts
CHANGED
|
@@ -71,12 +71,14 @@ export class GuardParser {
|
|
|
71
71
|
static DeGuardObject_FromData = (guard_constants:any, guard_input_bytes:any) : {object:DeGuardData, constant:DeGuardConstant[]} => {
|
|
72
72
|
let constants : DeGuardConstant[] = [];
|
|
73
73
|
guard_constants.forEach((c:any) => {
|
|
74
|
-
let value : any;
|
|
75
74
|
let v = c?.fields ?? c; // graphql dosnot 'fields', but rpcall has.
|
|
76
|
-
|
|
75
|
+
const data:Uint8Array = Uint8Array.from(v.value);
|
|
76
|
+
const type = data.slice(0, 1)[0];
|
|
77
|
+
var value : any = data.slice(1);
|
|
78
|
+
switch (type) {
|
|
77
79
|
case ContextType.TYPE_WITNESS_ID:
|
|
78
80
|
case ValueType.TYPE_ADDRESS:
|
|
79
|
-
value = '0x' + Bcs.getInstance().de(ValueType.TYPE_ADDRESS, Uint8Array.from(
|
|
81
|
+
value = '0x' + Bcs.getInstance().de(ValueType.TYPE_ADDRESS, Uint8Array.from(value)).toString();
|
|
80
82
|
break;
|
|
81
83
|
case ValueType.TYPE_BOOL:
|
|
82
84
|
case ValueType.TYPE_U8:
|
|
@@ -100,15 +102,15 @@ export class GuardParser {
|
|
|
100
102
|
case ValueType.TYPE_OPTION_STRING:
|
|
101
103
|
case ValueType.TYPE_OPTION_VEC_U8:
|
|
102
104
|
case ValueType.TYPE_VEC_STRING:
|
|
103
|
-
let de = SER_VALUE.find(s=>s.type==
|
|
105
|
+
let de = SER_VALUE.find(s=>s.type==type);
|
|
104
106
|
if (!de) ERROR(Errors.Fail, 'GuardObject de error')
|
|
105
|
-
value = Bcs.getInstance().de(
|
|
107
|
+
value = Bcs.getInstance().de(type as number, Uint8Array.from(value));
|
|
106
108
|
break;
|
|
107
109
|
|
|
108
110
|
default:
|
|
109
|
-
ERROR(Errors.Fail, 'GuardObject constant type invalid:' +
|
|
111
|
+
ERROR(Errors.Fail, 'GuardObject constant type invalid:' +type)
|
|
110
112
|
}
|
|
111
|
-
constants.push({identifier:v.identifier, type:
|
|
113
|
+
constants.push({identifier:v.identifier, type:type, value:value});
|
|
112
114
|
});
|
|
113
115
|
// console.log(constants)
|
|
114
116
|
let bytes = Uint8Array.from(guard_input_bytes);
|
|
@@ -116,7 +118,7 @@ export class GuardParser {
|
|
|
116
118
|
let data : DeGuardData[] = [];
|
|
117
119
|
while (arr.length > 0) {
|
|
118
120
|
let type : unknown = arr.shift() ;
|
|
119
|
-
let value:any; let cmd:any; let identifier:any;
|
|
121
|
+
let value:any; let cmd:any; let identifier:any;
|
|
120
122
|
switch (type as Data_Type) {
|
|
121
123
|
case ContextType.TYPE_SIGNER:
|
|
122
124
|
case ContextType.TYPE_CLOCK:
|
|
@@ -129,18 +131,16 @@ export class GuardParser {
|
|
|
129
131
|
case OperatorType.TYPE_LOGIC_HAS_SUBSTRING:
|
|
130
132
|
case OperatorType.TYPE_LOGIC_ALWAYS_TRUE:
|
|
131
133
|
case OperatorType.TYPE_LOGIC_NOT:
|
|
132
|
-
case OperatorType.TYPE_LOGIC_AND:
|
|
133
|
-
case OperatorType.TYPE_LOGIC_OR:
|
|
134
|
-
case OperatorType.TYPE_LOGIC_AND3:
|
|
135
|
-
case OperatorType.TYPE_LOGIC_OR3:
|
|
136
|
-
case OperatorType.TYPE_LOGIC_AND4:
|
|
137
|
-
case OperatorType.TYPE_LOGIC_OR4:
|
|
138
134
|
case OperatorType.TYPE_NUMBER_ADD:
|
|
139
135
|
case OperatorType.TYPE_NUMBER_DEVIDE:
|
|
140
136
|
case OperatorType.TYPE_NUMBER_MOD:
|
|
141
137
|
case OperatorType.TYPE_NUMBER_MULTIPLY:
|
|
142
138
|
case OperatorType.TYPE_NUMBER_SUBTRACT:
|
|
143
139
|
break;
|
|
140
|
+
case OperatorType.TYPE_LOGIC_AND: //@ with logics count
|
|
141
|
+
case OperatorType.TYPE_LOGIC_OR:
|
|
142
|
+
value = arr.shift()! as number;
|
|
143
|
+
break;
|
|
144
144
|
case ContextType.TYPE_CONSTANT:
|
|
145
145
|
identifier = arr.shift()! as number; // identifier
|
|
146
146
|
break;
|
|
@@ -348,7 +348,7 @@ export class GuardParser {
|
|
|
348
348
|
current.ret_type = ValueType.TYPE_BOOL;
|
|
349
349
|
if (stack.length < 2) ERROR(Errors.Fail, 'ResolveData: ' + current.type);
|
|
350
350
|
var p1 = stack.pop() as DeGuardData; var p2 = stack.pop() as DeGuardData;
|
|
351
|
-
console.log(p1); console.log(p2)
|
|
351
|
+
//console.log(p1); console.log(p2)
|
|
352
352
|
if (!p1.ret_type || !p2.ret_type) ERROR(Errors.Fail, 'ResolveData: ' + current.type + ' INVALID param type');
|
|
353
353
|
if (p1.ret_type != p2.ret_type) ERROR(Errors.Fail, 'ResolveData: ' + current.type + ' param type not match');
|
|
354
354
|
|
|
@@ -361,7 +361,7 @@ export class GuardParser {
|
|
|
361
361
|
if (stack.length < 2) ERROR(Errors.Fail, 'ResolveData: ' + current.type);
|
|
362
362
|
var p1 = stack.pop() as DeGuardData; var p2 = stack.pop() as DeGuardData;
|
|
363
363
|
if (!p1.ret_type || !p2.ret_type) ERROR(Errors.Fail, 'ResolveData: ' + current.type + ' INVALID param type');
|
|
364
|
-
if (p1.ret_type != ValueType.
|
|
364
|
+
if (p1.ret_type != ValueType.TYPE_STRING || p2.ret_type != ValueType.TYPE_STRING) {
|
|
365
365
|
ERROR(Errors.Fail, 'ResolveData: ' + current.type + ' param type not match');
|
|
366
366
|
}
|
|
367
367
|
|
|
@@ -372,15 +372,12 @@ export class GuardParser {
|
|
|
372
372
|
case OperatorType.TYPE_LOGIC_AND:
|
|
373
373
|
case OperatorType.TYPE_LOGIC_OR:
|
|
374
374
|
current.ret_type = ValueType.TYPE_BOOL;
|
|
375
|
-
if (stack.length < 2) ERROR(Errors.Fail, 'ResolveData: ' + current.type);
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
375
|
+
if (stack.length < current.value || current.value < 2) ERROR(Errors.Fail, 'ResolveData: ' + current.type);
|
|
376
|
+
for (let i = 0; i < current.value; ++i) {
|
|
377
|
+
var p = stack.pop() as DeGuardData;
|
|
378
|
+
if (!p.ret_type || (p.ret_type != ValueType.TYPE_BOOL)) ERROR(Errors.Fail, 'ResolveData: ' + current.type + ' INVALID param type');
|
|
379
|
+
current.child.push(p);
|
|
380
380
|
}
|
|
381
|
-
|
|
382
|
-
current.child.push(p1);
|
|
383
|
-
current.child.push(p2);
|
|
384
381
|
stack.push(current);
|
|
385
382
|
return
|
|
386
383
|
case OperatorType.TYPE_QUERY:
|
|
@@ -543,12 +540,16 @@ export class GuardParser {
|
|
|
543
540
|
constants.forEach((v:any) => {
|
|
544
541
|
if (v.type == (Protocol.Instance().Package() + '::guard::Constant')) {
|
|
545
542
|
// ValueType.TYPE_ADDRESS: Query_Cmd maybe used the address, so save it for querying
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
543
|
+
const data = Uint8Array.from(v.fields.value);
|
|
544
|
+
const type = data.slice(0, 1)[0];
|
|
545
|
+
const value = data.slice(1);
|
|
546
|
+
if (type == ContextType.TYPE_WITNESS_ID || type == ValueType.TYPE_ADDRESS) {
|
|
547
|
+
info.constant.push({identifier:v.fields.identifier, index:this.get_index(), type:type,
|
|
548
|
+
value_or_witness:'0x' + Bcs.getInstance().de(ValueType.TYPE_ADDRESS, Uint8Array.from(value))});
|
|
549
549
|
}
|
|
550
550
|
}
|
|
551
551
|
});
|
|
552
|
+
//console.log(info.constant)
|
|
552
553
|
}
|
|
553
554
|
|
|
554
555
|
parse_bcs = (info:GuardInfo, chain_bytes: Uint8Array) => {
|
|
@@ -568,14 +569,16 @@ export class GuardParser {
|
|
|
568
569
|
case OperatorType.TYPE_LOGIC_HAS_SUBSTRING:
|
|
569
570
|
case OperatorType.TYPE_LOGIC_ALWAYS_TRUE:
|
|
570
571
|
case OperatorType.TYPE_LOGIC_NOT:
|
|
571
|
-
case OperatorType.TYPE_LOGIC_AND:
|
|
572
|
-
case OperatorType.TYPE_LOGIC_OR:
|
|
573
572
|
case OperatorType.TYPE_NUMBER_ADD:
|
|
574
573
|
case OperatorType.TYPE_NUMBER_DEVIDE:
|
|
575
574
|
case OperatorType.TYPE_NUMBER_MOD:
|
|
576
575
|
case OperatorType.TYPE_NUMBER_MULTIPLY:
|
|
577
576
|
case OperatorType.TYPE_NUMBER_SUBTRACT:
|
|
578
577
|
break;
|
|
578
|
+
case OperatorType.TYPE_LOGIC_AND: //@ logics count
|
|
579
|
+
case OperatorType.TYPE_LOGIC_OR:
|
|
580
|
+
arr.splice(0, 1); // identifier of constant
|
|
581
|
+
break;
|
|
579
582
|
case ContextType.TYPE_CONSTANT:
|
|
580
583
|
arr.splice(0, 1); // identifier of constant
|
|
581
584
|
break;
|
|
@@ -774,13 +777,13 @@ export class Passport {
|
|
|
774
777
|
const clock = this.txb.sharedObjectRef(Protocol.CLOCK_OBJECT);
|
|
775
778
|
// rules: 'verify' & 'query' in turns; 'verify' at final end.
|
|
776
779
|
query?.query.forEach((q) => {
|
|
777
|
-
|
|
780
|
+
this.txb.moveCall({
|
|
778
781
|
target: Protocol.Instance().PassportFn('passport_verify') as FnCallType,
|
|
779
782
|
arguments: [ this.passport, this.txb.object(clock)]
|
|
780
783
|
});
|
|
781
784
|
this.txb.moveCall({
|
|
782
785
|
target: q.target as FnCallType,
|
|
783
|
-
arguments: [ bObject ? this.txb.object(q.object) : this.txb.object(q.id), this.passport
|
|
786
|
+
arguments: [ bObject ? this.txb.object(q.object) : this.txb.object(q.id), this.passport],
|
|
784
787
|
typeArguments: q.types,
|
|
785
788
|
})
|
|
786
789
|
})
|
package/src/protocol.ts
CHANGED
|
@@ -79,10 +79,6 @@ export enum OperatorType {
|
|
|
79
79
|
TYPE_LOGIC_NOT = 19, // NOT
|
|
80
80
|
TYPE_LOGIC_AND = 20, // AND
|
|
81
81
|
TYPE_LOGIC_OR = 21, // OR
|
|
82
|
-
TYPE_LOGIC_AND3 = 22, // and
|
|
83
|
-
TYPE_LOGIC_AND4 = 23, // and
|
|
84
|
-
TYPE_LOGIC_OR3 = 24, // or
|
|
85
|
-
TYPE_LOGIC_OR4 = 25, // or
|
|
86
82
|
}
|
|
87
83
|
|
|
88
84
|
export const LogicsInfo = [
|
|
@@ -91,16 +87,12 @@ export const LogicsInfo = [
|
|
|
91
87
|
[OperatorType.TYPE_LOGIC_AS_U256_LESSER, 'Unsigned Integer <'],
|
|
92
88
|
[OperatorType.TYPE_LOGIC_AS_U256_LESSER_EQUAL, 'Unsigned Integer <='],
|
|
93
89
|
[OperatorType.TYPE_LOGIC_AS_U256_EQUAL, 'Unsigned Integer ='],
|
|
94
|
-
[OperatorType.TYPE_LOGIC_EQUAL, '
|
|
90
|
+
[OperatorType.TYPE_LOGIC_EQUAL, 'Equal'],
|
|
95
91
|
[OperatorType.TYPE_LOGIC_HAS_SUBSTRING, 'Sub String'],
|
|
96
92
|
[OperatorType.TYPE_LOGIC_ALWAYS_TRUE, 'Always True'],
|
|
97
93
|
[OperatorType.TYPE_LOGIC_NOT, 'Not'],
|
|
98
94
|
[OperatorType.TYPE_LOGIC_AND, 'And'],
|
|
99
95
|
[OperatorType.TYPE_LOGIC_OR, 'Or'],
|
|
100
|
-
[OperatorType.TYPE_LOGIC_AND3, 'And 3'],
|
|
101
|
-
[OperatorType.TYPE_LOGIC_OR3, 'Or 3'],
|
|
102
|
-
[OperatorType.TYPE_LOGIC_AND4, 'And 4'],
|
|
103
|
-
[OperatorType.TYPE_LOGIC_OR4, 'Or 4'],
|
|
104
96
|
];
|
|
105
97
|
|
|
106
98
|
export enum ValueType {
|
|
@@ -216,10 +208,10 @@ const TESTNET = {
|
|
|
216
208
|
}
|
|
217
209
|
*/
|
|
218
210
|
const TESTNET = {
|
|
219
|
-
package: "
|
|
220
|
-
wowok_object: '
|
|
221
|
-
entity_object: '
|
|
222
|
-
treasury_cap:'
|
|
211
|
+
package: "0x4ce36e03ef9cd230f1158e48293ee01cb572cdcd2f9cab7ac7b2fd2251bfe51e",
|
|
212
|
+
wowok_object: '0xd3639daf1daa300bbf694b21e42cecac6be242ad038fe48a7a1212e93f3845f6',
|
|
213
|
+
entity_object: '0x8de1e01e6baca0990ca18de3ec51b57183512deaeb76076be9161ca38988c74f',
|
|
214
|
+
treasury_cap:'0x2e05eda6ee5b0773854be6eb48c6cee2b5ca8aaa13ee810434d66232005b40ef',
|
|
223
215
|
}
|
|
224
216
|
const MAINNET = {
|
|
225
217
|
package: "",
|
package/src/repository.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Protocol, FnCallType, ValueType, RepositoryValueType, RepositoryAddress, PermissionObject, PassportObject, TxbObject} from './protocol';
|
|
1
|
+
import { Protocol, FnCallType, ValueType, RepositoryValueType, RepositoryAddress, PermissionObject, PassportObject, TxbObject, } from './protocol';
|
|
2
2
|
import { PermissionIndexType, Permission } from './permission'
|
|
3
3
|
import { Bcs, array_unique, IsValidDesription, IsValidAddress, IsValidArray, IsValidName, ValueTypeConvert} from './utils';
|
|
4
4
|
import { ERROR, Errors } from './exception';
|
|
5
|
-
import { MAX_U8, MAX_U128, MAX_U256, MAX_U64 } from './utils';
|
|
5
|
+
import { MAX_U8, MAX_U128, MAX_U256, MAX_U64, stringToUint8Array } from './utils';
|
|
6
6
|
import { type TransactionResult, Transaction as TransactionBlock } from '@mysten/sui/transactions';
|
|
7
7
|
|
|
8
8
|
export enum Repository_Policy_Mode {
|
package/src/utils.ts
CHANGED
|
@@ -241,9 +241,10 @@ export class Bcs {
|
|
|
241
241
|
case ValueType.TYPE_U256:
|
|
242
242
|
return this.bcs.ser(BCS.U256, data).toBytes();
|
|
243
243
|
case ValueType.TYPE_STRING:
|
|
244
|
-
|
|
244
|
+
const d = new TextEncoder().encode(data);
|
|
245
|
+
return this.bcs.ser('vector<u8>', d).toBytes();
|
|
245
246
|
case ValueType.TYPE_VEC_STRING:
|
|
246
|
-
return this.bcs.ser('vector<
|
|
247
|
+
return this.bcs.ser('vector<vector<u8>>', data.map((v:string)=>{return new TextEncoder().encode(v)})).toBytes();
|
|
247
248
|
case ContextType.TYPE_WITNESS_ID:
|
|
248
249
|
return this.bcs.ser(BCS.ADDRESS, data).toBytes();
|
|
249
250
|
default:
|
|
@@ -297,7 +298,8 @@ export class Bcs {
|
|
|
297
298
|
case ValueType.TYPE_VEC_U256:
|
|
298
299
|
return this.bcs.de('vector<u256>', data);
|
|
299
300
|
case ValueType.TYPE_STRING:
|
|
300
|
-
|
|
301
|
+
const r = new TextDecoder().decode(Uint8Array.from(this.bcs.de('vector<u8>', data)));
|
|
302
|
+
return r
|
|
301
303
|
case ValueType.TYPE_VEC_STRING:
|
|
302
304
|
return this.bcs.de('vector<string>', data);
|
|
303
305
|
case ValueType.TYPE_U256:
|
|
@@ -329,13 +331,10 @@ export class Bcs {
|
|
|
329
331
|
}
|
|
330
332
|
}
|
|
331
333
|
|
|
332
|
-
export function stringToUint8Array(str:string)
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
}
|
|
337
|
-
var tmpUint8Array = new Uint8Array(arr);
|
|
338
|
-
return tmpUint8Array
|
|
334
|
+
export function stringToUint8Array(str:string) {
|
|
335
|
+
const encoder = new TextEncoder();
|
|
336
|
+
const view = encoder.encode(str);
|
|
337
|
+
return new Uint8Array(view.buffer);
|
|
339
338
|
}
|
|
340
339
|
|
|
341
340
|
export function numToUint8Array(num:number) : Uint8Array {
|
|
@@ -509,6 +508,15 @@ export const ParseType = (type:string) : ArgType => {
|
|
|
509
508
|
return {isCoin:false, coin:'', token:''}
|
|
510
509
|
}
|
|
511
510
|
|
|
511
|
+
|
|
512
|
+
export function insertAtHead(array:Uint8Array, value:number) {
|
|
513
|
+
const newLength = array.length + 1;
|
|
514
|
+
const newArray = new Uint8Array(newLength);
|
|
515
|
+
newArray.set([value], 0);
|
|
516
|
+
newArray.set(array, 1);
|
|
517
|
+
return newArray;
|
|
518
|
+
}
|
|
519
|
+
|
|
512
520
|
export function toFixed(x:number) {
|
|
513
521
|
let res = '';
|
|
514
522
|
if (Math.abs(x) < 1.0) {
|