@taquito/local-forging 23.0.2 → 23.1.0
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/lib/taquito-local-forging.js +7 -29
- package/dist/lib/version.js +2 -2
- package/dist/taquito-local-forging.es6.js +315 -1736
- package/dist/taquito-local-forging.es6.js.map +1 -1
- package/dist/taquito-local-forging.umd.js +389 -1810
- package/dist/taquito-local-forging.umd.js.map +1 -1
- package/dist/types/taquito-local-forging.d.ts +2 -3
- package/package.json +8 -7
- package/dist/lib/codec-proto022.js +0 -563
- package/dist/lib/constants-proto022.js +0 -286
- package/dist/lib/decoder-proto022.js +0 -63
- package/dist/lib/encoder-proto022.js +0 -62
- package/dist/lib/michelson/codec-proto022.js +0 -283
- package/dist/lib/schema/operation-proto022.js +0 -238
- package/dist/lib/validator-proto022.js +0 -56
- package/dist/types/codec-proto022.d.ts +0 -79
- package/dist/types/constants-proto022.d.ts +0 -74
- package/dist/types/decoder-proto022.d.ts +0 -5
- package/dist/types/encoder-proto022.d.ts +0 -4
- package/dist/types/michelson/codec-proto022.d.ts +0 -49
- package/dist/types/schema/operation-proto022.d.ts +0 -188
- package/dist/types/validator-proto022.d.ts +0 -13
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* Copyright (c) 2018 Andrew Kishino
|
|
15
15
|
*/
|
|
16
16
|
// See: https://tezos.gitlab.io/protocols/005_babylon.html#transactions-now-have-an-entrypoint
|
|
17
|
-
const ENTRYPOINT_MAX_LENGTH
|
|
17
|
+
const ENTRYPOINT_MAX_LENGTH = 31;
|
|
18
18
|
exports.CODEC = void 0;
|
|
19
19
|
(function (CODEC) {
|
|
20
20
|
CODEC["SECRET"] = "secret";
|
|
@@ -73,7 +73,7 @@
|
|
|
73
73
|
CODEC["SLOT_HEADER"] = "slot_header";
|
|
74
74
|
})(exports.CODEC || (exports.CODEC = {}));
|
|
75
75
|
// See https://tezos.gitlab.io/shell/p2p_api.html#alpha-michelson-v1-primitives-enumeration-unsigned-8-bit-integer
|
|
76
|
-
const opMapping
|
|
76
|
+
const opMapping = {
|
|
77
77
|
'00': 'parameter',
|
|
78
78
|
'01': 'storage',
|
|
79
79
|
'02': 'code',
|
|
@@ -234,15 +234,15 @@
|
|
|
234
234
|
'9d': 'Ticket',
|
|
235
235
|
'9e': 'IS_IMPLICIT_ACCOUNT',
|
|
236
236
|
};
|
|
237
|
-
const opMappingReverse
|
|
237
|
+
const opMappingReverse = (() => {
|
|
238
238
|
const result = {};
|
|
239
|
-
Object.keys(opMapping
|
|
240
|
-
result[opMapping
|
|
239
|
+
Object.keys(opMapping).forEach((key) => {
|
|
240
|
+
result[opMapping[key]] = key;
|
|
241
241
|
});
|
|
242
242
|
return result;
|
|
243
243
|
})();
|
|
244
244
|
// See https://tezos.gitlab.io/shell/p2p_api.html
|
|
245
|
-
const kindMapping
|
|
245
|
+
const kindMapping = {
|
|
246
246
|
0x04: 'activate_account',
|
|
247
247
|
0x6b: 'reveal',
|
|
248
248
|
0x6e: 'delegation',
|
|
@@ -266,16 +266,16 @@
|
|
|
266
266
|
0xe6: 'dal_publish_commitment',
|
|
267
267
|
0x11: 'failing_noop',
|
|
268
268
|
};
|
|
269
|
-
const kindMappingReverse
|
|
269
|
+
const kindMappingReverse = (() => {
|
|
270
270
|
const result = {};
|
|
271
|
-
Object.keys(kindMapping
|
|
271
|
+
Object.keys(kindMapping).forEach((key) => {
|
|
272
272
|
const keyNum = typeof key === 'string' ? parseInt(key, 10) : key;
|
|
273
|
-
result[kindMapping
|
|
273
|
+
result[kindMapping[keyNum]] = pad(keyNum, 2);
|
|
274
274
|
});
|
|
275
275
|
return result;
|
|
276
276
|
})();
|
|
277
277
|
// See https://tezos.gitlab.io/protocols/005_babylon.html#transactions-now-have-an-entrypoint
|
|
278
|
-
const entrypointMapping
|
|
278
|
+
const entrypointMapping = {
|
|
279
279
|
'00': 'default',
|
|
280
280
|
'01': 'root',
|
|
281
281
|
'02': 'do',
|
|
@@ -287,10 +287,10 @@
|
|
|
287
287
|
'08': 'finalize_unstake',
|
|
288
288
|
'09': 'set_delegate_parameters',
|
|
289
289
|
};
|
|
290
|
-
const entrypointMappingReverse
|
|
290
|
+
const entrypointMappingReverse = (() => {
|
|
291
291
|
const result = {};
|
|
292
|
-
Object.keys(entrypointMapping
|
|
293
|
-
result[entrypointMapping
|
|
292
|
+
Object.keys(entrypointMapping).forEach((key) => {
|
|
293
|
+
result[entrypointMapping[key]] = key;
|
|
294
294
|
});
|
|
295
295
|
return result;
|
|
296
296
|
})();
|
|
@@ -317,7 +317,7 @@
|
|
|
317
317
|
super();
|
|
318
318
|
this.entrypoint = entrypoint;
|
|
319
319
|
this.name = 'OversizedEntryPointError';
|
|
320
|
-
this.message = `Invalid entrypoint length "${entrypoint.length}", maximum length is "${ENTRYPOINT_MAX_LENGTH
|
|
320
|
+
this.message = `Invalid entrypoint length "${entrypoint.length}", maximum length is "${ENTRYPOINT_MAX_LENGTH}".`;
|
|
321
321
|
}
|
|
322
322
|
}
|
|
323
323
|
/**
|
|
@@ -488,73 +488,73 @@
|
|
|
488
488
|
}
|
|
489
489
|
}
|
|
490
490
|
|
|
491
|
-
const isPrim
|
|
491
|
+
const isPrim = (value) => {
|
|
492
492
|
return 'prim' in value;
|
|
493
493
|
};
|
|
494
|
-
const isBytes
|
|
494
|
+
const isBytes = (value) => {
|
|
495
495
|
return 'bytes' in value && typeof value.bytes === 'string';
|
|
496
496
|
};
|
|
497
|
-
const isString
|
|
497
|
+
const isString = (value) => {
|
|
498
498
|
return 'string' in value && typeof value.string === 'string';
|
|
499
499
|
};
|
|
500
|
-
const isInt
|
|
500
|
+
const isInt = (value) => {
|
|
501
501
|
return 'int' in value && typeof value.int === 'string';
|
|
502
502
|
};
|
|
503
|
-
const scriptEncoder
|
|
504
|
-
const code = valueEncoder
|
|
505
|
-
const storage = valueEncoder
|
|
503
|
+
const scriptEncoder = (script) => {
|
|
504
|
+
const code = valueEncoder(script.code);
|
|
505
|
+
const storage = valueEncoder(script.storage);
|
|
506
506
|
return `${pad(code.length / 2, 8)}${code}${pad(storage.length / 2, 8)}${storage}`;
|
|
507
507
|
};
|
|
508
|
-
const scriptDecoder
|
|
509
|
-
const code = extractRequiredLen
|
|
510
|
-
const storage = extractRequiredLen
|
|
508
|
+
const scriptDecoder = (value) => {
|
|
509
|
+
const code = extractRequiredLen(value);
|
|
510
|
+
const storage = extractRequiredLen(value);
|
|
511
511
|
return {
|
|
512
|
-
code: valueDecoder
|
|
513
|
-
storage: valueDecoder
|
|
512
|
+
code: valueDecoder(new Uint8ArrayConsumer(code)),
|
|
513
|
+
storage: valueDecoder(new Uint8ArrayConsumer(storage)),
|
|
514
514
|
};
|
|
515
515
|
};
|
|
516
|
-
const valueEncoder
|
|
516
|
+
const valueEncoder = (value) => {
|
|
517
517
|
if (Array.isArray(value)) {
|
|
518
|
-
const encoded = value.map((x) => valueEncoder
|
|
518
|
+
const encoded = value.map((x) => valueEncoder(x)).join('');
|
|
519
519
|
const len = encoded.length / 2;
|
|
520
520
|
return `02${pad(len)}${encoded}`;
|
|
521
521
|
}
|
|
522
|
-
else if (isPrim
|
|
523
|
-
return primEncoder
|
|
522
|
+
else if (isPrim(value)) {
|
|
523
|
+
return primEncoder(value);
|
|
524
524
|
}
|
|
525
|
-
else if (isBytes
|
|
526
|
-
return bytesEncoder
|
|
525
|
+
else if (isBytes(value)) {
|
|
526
|
+
return bytesEncoder(value);
|
|
527
527
|
}
|
|
528
|
-
else if (isString
|
|
529
|
-
return stringEncoder
|
|
528
|
+
else if (isString(value)) {
|
|
529
|
+
return stringEncoder(value);
|
|
530
530
|
}
|
|
531
|
-
else if (isInt
|
|
532
|
-
return intEncoder
|
|
531
|
+
else if (isInt(value)) {
|
|
532
|
+
return intEncoder(value);
|
|
533
533
|
}
|
|
534
534
|
throw new UnexpectedMichelsonValueError(JSON.stringify(value));
|
|
535
535
|
};
|
|
536
|
-
const valueDecoder
|
|
536
|
+
const valueDecoder = (value) => {
|
|
537
537
|
const preamble = value.consume(1);
|
|
538
538
|
switch (preamble[0]) {
|
|
539
539
|
case 0x0a:
|
|
540
|
-
return bytesDecoder
|
|
540
|
+
return bytesDecoder(value);
|
|
541
541
|
case 0x01:
|
|
542
|
-
return stringDecoder
|
|
542
|
+
return stringDecoder(value);
|
|
543
543
|
case 0x00:
|
|
544
|
-
return intDecoder
|
|
544
|
+
return intDecoder(value);
|
|
545
545
|
case 0x02: {
|
|
546
|
-
const val = new Uint8ArrayConsumer(extractRequiredLen
|
|
546
|
+
const val = new Uint8ArrayConsumer(extractRequiredLen(value));
|
|
547
547
|
const results = [];
|
|
548
548
|
while (val.length() > 0) {
|
|
549
|
-
results.push(valueDecoder
|
|
549
|
+
results.push(valueDecoder(val));
|
|
550
550
|
}
|
|
551
551
|
return results;
|
|
552
552
|
}
|
|
553
553
|
default:
|
|
554
|
-
return primDecoder
|
|
554
|
+
return primDecoder(value, preamble);
|
|
555
555
|
}
|
|
556
556
|
};
|
|
557
|
-
const extractRequiredLen
|
|
557
|
+
const extractRequiredLen = (value, bytesLength = 4) => {
|
|
558
558
|
const len = value.consume(bytesLength);
|
|
559
559
|
const valueLen = parseInt(Buffer.from(len).toString('hex'), 16);
|
|
560
560
|
return value.consume(valueLen);
|
|
@@ -565,7 +565,7 @@
|
|
|
565
565
|
* @param bytesLength default 4 bytes for length of variable bytes
|
|
566
566
|
* @returns array of Uint8Array values for each array item
|
|
567
567
|
*/
|
|
568
|
-
const stripLengthPrefixFromBytes
|
|
568
|
+
const stripLengthPrefixFromBytes = (value, bytesLength = 4) => {
|
|
569
569
|
const ret = [];
|
|
570
570
|
let values = value;
|
|
571
571
|
while (values.length()) {
|
|
@@ -576,31 +576,31 @@
|
|
|
576
576
|
}
|
|
577
577
|
return ret;
|
|
578
578
|
};
|
|
579
|
-
const bytesEncoder
|
|
579
|
+
const bytesEncoder = (value) => {
|
|
580
580
|
if (!/^([A-Fa-f0-9]{2})*$/.test(value.bytes)) {
|
|
581
581
|
throw new core.InvalidHexStringError(value.bytes);
|
|
582
582
|
}
|
|
583
583
|
const len = value.bytes.length / 2;
|
|
584
584
|
return `0a${pad(len)}${value.bytes}`;
|
|
585
585
|
};
|
|
586
|
-
const bytesDecoder
|
|
587
|
-
const bytes = extractRequiredLen
|
|
586
|
+
const bytesDecoder = (value) => {
|
|
587
|
+
const bytes = extractRequiredLen(value);
|
|
588
588
|
return {
|
|
589
589
|
bytes: Buffer.from(bytes).toString('hex'),
|
|
590
590
|
};
|
|
591
591
|
};
|
|
592
|
-
const stringEncoder
|
|
592
|
+
const stringEncoder = (value) => {
|
|
593
593
|
const str = Buffer.from(value.string, 'utf8').toString('hex');
|
|
594
594
|
const hexLength = str.length / 2;
|
|
595
595
|
return `01${pad(hexLength)}${str}`;
|
|
596
596
|
};
|
|
597
|
-
const stringDecoder
|
|
598
|
-
const str = extractRequiredLen
|
|
597
|
+
const stringDecoder = (value) => {
|
|
598
|
+
const str = extractRequiredLen(value);
|
|
599
599
|
return {
|
|
600
600
|
string: Buffer.from(str).toString('utf8'),
|
|
601
601
|
};
|
|
602
602
|
};
|
|
603
|
-
const intEncoder
|
|
603
|
+
const intEncoder = ({ int }) => {
|
|
604
604
|
const num = new BigNumber.BigNumber(int, 10);
|
|
605
605
|
const positiveMark = num.toString(2)[0] === '-' ? '1' : '0';
|
|
606
606
|
const binary = num.toString(2).replace(/-/g, '');
|
|
@@ -620,7 +620,7 @@
|
|
|
620
620
|
.padStart(2, '0'));
|
|
621
621
|
return `00${numHex.join('')}`;
|
|
622
622
|
};
|
|
623
|
-
const intDecoder
|
|
623
|
+
const intDecoder = (value) => {
|
|
624
624
|
let c = value.consume(1)[0];
|
|
625
625
|
const hexNumber = [];
|
|
626
626
|
const isNotLastChunkMask = 1 << 7;
|
|
@@ -645,14 +645,14 @@
|
|
|
645
645
|
int: num.toFixed(),
|
|
646
646
|
};
|
|
647
647
|
};
|
|
648
|
-
const primEncoder
|
|
648
|
+
const primEncoder = (value) => {
|
|
649
649
|
const hasAnnot = +Array.isArray(value.annots);
|
|
650
650
|
const argsCount = Array.isArray(value.args) ? value.args.length : 0;
|
|
651
651
|
// Specify the number of args max is 3 without annotation
|
|
652
652
|
const preamble = pad(Math.min(2 * argsCount + hasAnnot + 0x03, 9), 2);
|
|
653
|
-
const op = opMappingReverse
|
|
654
|
-
let encodedArgs = (value.args || []).map((arg) => valueEncoder
|
|
655
|
-
const encodedAnnots = Array.isArray(value.annots) ? encodeAnnots
|
|
653
|
+
const op = opMappingReverse[value.prim];
|
|
654
|
+
let encodedArgs = (value.args || []).map((arg) => valueEncoder(arg)).join('');
|
|
655
|
+
const encodedAnnots = Array.isArray(value.annots) ? encodeAnnots(value.annots) : '';
|
|
656
656
|
if ((value.prim === 'LAMBDA' || value.prim === 'LAMBDA_REC') && argsCount) {
|
|
657
657
|
encodedArgs = pad(encodedArgs.length / 2) + encodedArgs + pad(0);
|
|
658
658
|
}
|
|
@@ -667,19 +667,19 @@
|
|
|
667
667
|
}
|
|
668
668
|
return `${preamble}${op}${encodedArgs}${encodedAnnots}`;
|
|
669
669
|
};
|
|
670
|
-
const primDecoder
|
|
670
|
+
const primDecoder = (value, preamble) => {
|
|
671
671
|
const hasAnnot = (preamble[0] - 0x03) % 2 === 1;
|
|
672
672
|
let argsCount = Math.floor((preamble[0] - 0x03) / 2);
|
|
673
673
|
const op = value.consume(1)[0].toString(16).padStart(2, '0');
|
|
674
674
|
const result = {
|
|
675
|
-
prim: opMapping
|
|
675
|
+
prim: opMapping[op],
|
|
676
676
|
};
|
|
677
|
-
if (opMapping
|
|
677
|
+
if (opMapping[op] === 'LAMBDA' || opMapping[op] === 'LAMBDA_REC') {
|
|
678
678
|
value.consume(4);
|
|
679
679
|
}
|
|
680
|
-
if (opMapping
|
|
680
|
+
if (opMapping[op] === 'view') {
|
|
681
681
|
if (argsCount != 0) {
|
|
682
|
-
return primViewDecoder
|
|
682
|
+
return primViewDecoder(value, result);
|
|
683
683
|
}
|
|
684
684
|
else {
|
|
685
685
|
return result;
|
|
@@ -687,13 +687,13 @@
|
|
|
687
687
|
}
|
|
688
688
|
let combPairArgs;
|
|
689
689
|
let combPairAnnots;
|
|
690
|
-
if ((opMapping
|
|
691
|
-
combPairArgs = decodeCombPair
|
|
690
|
+
if ((opMapping[op] === 'pair' || opMapping[op] === 'Pair') && argsCount > 2) {
|
|
691
|
+
combPairArgs = decodeCombPair(value);
|
|
692
692
|
argsCount = 0;
|
|
693
|
-
combPairAnnots = decodeAnnots
|
|
693
|
+
combPairAnnots = decodeAnnots(value);
|
|
694
694
|
}
|
|
695
|
-
const args = new Array(argsCount).fill(0).map(() => valueDecoder
|
|
696
|
-
if (opMapping
|
|
695
|
+
const args = new Array(argsCount).fill(0).map(() => valueDecoder(value));
|
|
696
|
+
if (opMapping[op] === 'LAMBDA' || opMapping[op] === 'LAMBDA_REC') {
|
|
697
697
|
value.consume(4);
|
|
698
698
|
}
|
|
699
699
|
if (combPairArgs) {
|
|
@@ -706,25 +706,25 @@
|
|
|
706
706
|
result['annots'] = combPairAnnots;
|
|
707
707
|
}
|
|
708
708
|
else if (hasAnnot) {
|
|
709
|
-
result['annots'] = decodeAnnots
|
|
709
|
+
result['annots'] = decodeAnnots(value);
|
|
710
710
|
}
|
|
711
711
|
return result;
|
|
712
712
|
};
|
|
713
|
-
const primViewDecoder
|
|
713
|
+
const primViewDecoder = (value, result) => {
|
|
714
714
|
value.consume(4);
|
|
715
|
-
result['args'] = new Array(4).fill(0).map(() => valueDecoder
|
|
715
|
+
result['args'] = new Array(4).fill(0).map(() => valueDecoder(value));
|
|
716
716
|
value.consume(4);
|
|
717
717
|
return result;
|
|
718
718
|
};
|
|
719
|
-
const decodeCombPair
|
|
720
|
-
const array = new Uint8ArrayConsumer(extractRequiredLen
|
|
719
|
+
const decodeCombPair = (val) => {
|
|
720
|
+
const array = new Uint8ArrayConsumer(extractRequiredLen(val));
|
|
721
721
|
const args = [];
|
|
722
722
|
while (array.length() > 0) {
|
|
723
|
-
args.push(valueDecoder
|
|
723
|
+
args.push(valueDecoder(array));
|
|
724
724
|
}
|
|
725
725
|
return args;
|
|
726
726
|
};
|
|
727
|
-
const encodeAnnots
|
|
727
|
+
const encodeAnnots = (value) => {
|
|
728
728
|
const mergedAnnot = value
|
|
729
729
|
.map((x) => {
|
|
730
730
|
return Buffer.from(x, 'utf8').toString('hex');
|
|
@@ -733,7 +733,7 @@
|
|
|
733
733
|
const len = mergedAnnot.length / 2;
|
|
734
734
|
return `${pad(len)}${mergedAnnot}`;
|
|
735
735
|
};
|
|
736
|
-
const decodeAnnots
|
|
736
|
+
const decodeAnnots = (val) => {
|
|
737
737
|
const len = val.consume(4);
|
|
738
738
|
const annotLen = parseInt(Buffer.from(len).toString('hex'), 16);
|
|
739
739
|
const restOfAnnot = val.consume(annotLen);
|
|
@@ -742,63 +742,63 @@
|
|
|
742
742
|
};
|
|
743
743
|
|
|
744
744
|
// https://tezos.gitlab.io/shell/p2p_api.html specifies data types and structure for forging
|
|
745
|
-
const prefixEncoder
|
|
745
|
+
const prefixEncoder = (prefix) => (str) => {
|
|
746
746
|
const [pl] = utils.b58DecodeAndCheckPrefix(str, [prefix]);
|
|
747
747
|
return utils.buf2hex(pl);
|
|
748
748
|
};
|
|
749
|
-
const prefixDecoder
|
|
749
|
+
const prefixDecoder = (pre) => (str) => {
|
|
750
750
|
const val = str.consume(utils.payloadLength[pre]);
|
|
751
751
|
return utils.b58Encode(val, pre);
|
|
752
752
|
};
|
|
753
|
-
const tz1Decoder
|
|
754
|
-
const branchDecoder
|
|
755
|
-
const publicKeyHashDecoder
|
|
753
|
+
const tz1Decoder = prefixDecoder(utils.PrefixV2.Ed25519PublicKeyHash);
|
|
754
|
+
const branchDecoder = prefixDecoder(utils.PrefixV2.BlockHash);
|
|
755
|
+
const publicKeyHashDecoder = (val) => {
|
|
756
756
|
const prefix = val.consume(1);
|
|
757
757
|
if (prefix[0] === 0x00) {
|
|
758
|
-
return prefixDecoder
|
|
758
|
+
return prefixDecoder(utils.PrefixV2.Ed25519PublicKeyHash)(val);
|
|
759
759
|
}
|
|
760
760
|
else if (prefix[0] === 0x01) {
|
|
761
|
-
return prefixDecoder
|
|
761
|
+
return prefixDecoder(utils.PrefixV2.Secp256k1PublicKeyHash)(val);
|
|
762
762
|
}
|
|
763
763
|
else if (prefix[0] === 0x02) {
|
|
764
|
-
return prefixDecoder
|
|
764
|
+
return prefixDecoder(utils.PrefixV2.P256PublicKeyHash)(val);
|
|
765
765
|
}
|
|
766
766
|
else if (prefix[0] === 0x03) {
|
|
767
|
-
return prefixDecoder
|
|
767
|
+
return prefixDecoder(utils.PrefixV2.BLS12_381PublicKeyHash)(val);
|
|
768
768
|
}
|
|
769
769
|
};
|
|
770
|
-
const publicKeyHashesDecoder
|
|
771
|
-
if (!boolDecoder
|
|
770
|
+
const publicKeyHashesDecoder = (val) => {
|
|
771
|
+
if (!boolDecoder(val)) {
|
|
772
772
|
return;
|
|
773
773
|
}
|
|
774
774
|
const publicKeyHashes = [];
|
|
775
775
|
val.consume(4);
|
|
776
776
|
while (val.length() > 0) {
|
|
777
|
-
publicKeyHashes.push(publicKeyHashDecoder
|
|
777
|
+
publicKeyHashes.push(publicKeyHashDecoder(val));
|
|
778
778
|
}
|
|
779
779
|
return publicKeyHashes;
|
|
780
780
|
};
|
|
781
|
-
const branchEncoder
|
|
782
|
-
const tz1Encoder
|
|
783
|
-
const boolEncoder
|
|
784
|
-
const proposalEncoder
|
|
785
|
-
return prefixEncoder
|
|
781
|
+
const branchEncoder = prefixEncoder(utils.PrefixV2.BlockHash);
|
|
782
|
+
const tz1Encoder = prefixEncoder(utils.PrefixV2.Ed25519PublicKeyHash);
|
|
783
|
+
const boolEncoder = (bool) => (bool ? 'ff' : '00');
|
|
784
|
+
const proposalEncoder = (proposal) => {
|
|
785
|
+
return prefixEncoder(utils.PrefixV2.ProtocolHash)(proposal);
|
|
786
786
|
};
|
|
787
|
-
const proposalDecoder
|
|
788
|
-
return prefixDecoder
|
|
787
|
+
const proposalDecoder = (proposal) => {
|
|
788
|
+
return prefixDecoder(utils.PrefixV2.ProtocolHash)(proposal);
|
|
789
789
|
};
|
|
790
|
-
const proposalsDecoder
|
|
790
|
+
const proposalsDecoder = (proposal) => {
|
|
791
791
|
const proposals = [];
|
|
792
792
|
proposal.consume(4);
|
|
793
793
|
while (proposal.length() > 0) {
|
|
794
|
-
proposals.push(proposalDecoder
|
|
794
|
+
proposals.push(proposalDecoder(proposal));
|
|
795
795
|
}
|
|
796
796
|
return proposals;
|
|
797
797
|
};
|
|
798
|
-
const proposalsEncoder
|
|
799
|
-
return pad(32 * proposals.length) + proposals.map((x) => proposalEncoder
|
|
798
|
+
const proposalsEncoder = (proposals) => {
|
|
799
|
+
return pad(32 * proposals.length) + proposals.map((x) => proposalEncoder(x)).join('');
|
|
800
800
|
};
|
|
801
|
-
const ballotEncoder
|
|
801
|
+
const ballotEncoder = (ballot) => {
|
|
802
802
|
switch (ballot) {
|
|
803
803
|
case 'yay':
|
|
804
804
|
return '00';
|
|
@@ -810,7 +810,7 @@
|
|
|
810
810
|
throw new InvalidBallotValueError(ballot);
|
|
811
811
|
}
|
|
812
812
|
};
|
|
813
|
-
const ballotDecoder
|
|
813
|
+
const ballotDecoder = (ballot) => {
|
|
814
814
|
const value = ballot.consume(1);
|
|
815
815
|
switch (value[0]) {
|
|
816
816
|
case 0x00:
|
|
@@ -823,7 +823,7 @@
|
|
|
823
823
|
throw new DecodeBallotValueError(value[0].toString());
|
|
824
824
|
}
|
|
825
825
|
};
|
|
826
|
-
const pvmKindEncoder
|
|
826
|
+
const pvmKindEncoder = (pvm) => {
|
|
827
827
|
switch (pvm) {
|
|
828
828
|
case 'arith':
|
|
829
829
|
return '00';
|
|
@@ -835,7 +835,7 @@
|
|
|
835
835
|
throw new UnsupportedPvmKindError(pvm);
|
|
836
836
|
}
|
|
837
837
|
};
|
|
838
|
-
const pvmKindDecoder
|
|
838
|
+
const pvmKindDecoder = (pvm) => {
|
|
839
839
|
const value = pvm.consume(1);
|
|
840
840
|
switch (value[0]) {
|
|
841
841
|
case 0x00:
|
|
@@ -848,15 +848,15 @@
|
|
|
848
848
|
throw new DecodePvmKindError(value[0].toString());
|
|
849
849
|
}
|
|
850
850
|
};
|
|
851
|
-
const delegateEncoder
|
|
851
|
+
const delegateEncoder = (val) => {
|
|
852
852
|
if (val) {
|
|
853
|
-
return boolEncoder
|
|
853
|
+
return boolEncoder(true) + publicKeyHashEncoder(val);
|
|
854
854
|
}
|
|
855
855
|
else {
|
|
856
|
-
return boolEncoder
|
|
856
|
+
return boolEncoder(false);
|
|
857
857
|
}
|
|
858
858
|
};
|
|
859
|
-
const int32Encoder
|
|
859
|
+
const int32Encoder = (val) => {
|
|
860
860
|
const num = parseInt(String(val), 10);
|
|
861
861
|
const byte = [];
|
|
862
862
|
for (let i = 0; i < 4; i++) {
|
|
@@ -865,7 +865,7 @@
|
|
|
865
865
|
}
|
|
866
866
|
return Buffer.from(byte).toString('hex');
|
|
867
867
|
};
|
|
868
|
-
const int32Decoder
|
|
868
|
+
const int32Decoder = (val) => {
|
|
869
869
|
const num = val.consume(4);
|
|
870
870
|
let finalNum = 0;
|
|
871
871
|
for (let i = 0; i < num.length; i++) {
|
|
@@ -873,7 +873,7 @@
|
|
|
873
873
|
}
|
|
874
874
|
return finalNum;
|
|
875
875
|
};
|
|
876
|
-
const int16Encoder
|
|
876
|
+
const int16Encoder = (val) => {
|
|
877
877
|
const num = parseInt(String(val), 10);
|
|
878
878
|
const byte = [];
|
|
879
879
|
for (let i = 0; i < 2; i++) {
|
|
@@ -882,7 +882,7 @@
|
|
|
882
882
|
}
|
|
883
883
|
return Buffer.from(byte).toString('hex');
|
|
884
884
|
};
|
|
885
|
-
const int16Decoder
|
|
885
|
+
const int16Decoder = (val) => {
|
|
886
886
|
const num = val.consume(2);
|
|
887
887
|
let finalNum = 0;
|
|
888
888
|
for (let i = 0; i < num.length; i++) {
|
|
@@ -890,17 +890,17 @@
|
|
|
890
890
|
}
|
|
891
891
|
return finalNum;
|
|
892
892
|
};
|
|
893
|
-
const boolDecoder
|
|
893
|
+
const boolDecoder = (val) => {
|
|
894
894
|
const bool = val.consume(1);
|
|
895
895
|
return bool[0] === 0xff;
|
|
896
896
|
};
|
|
897
|
-
const delegateDecoder
|
|
898
|
-
const hasDelegate = boolDecoder
|
|
897
|
+
const delegateDecoder = (val) => {
|
|
898
|
+
const hasDelegate = boolDecoder(val);
|
|
899
899
|
if (hasDelegate) {
|
|
900
|
-
return publicKeyHashDecoder
|
|
900
|
+
return publicKeyHashDecoder(val);
|
|
901
901
|
}
|
|
902
902
|
};
|
|
903
|
-
const publicKeyHashEncoder
|
|
903
|
+
const publicKeyHashEncoder = (val) => {
|
|
904
904
|
try {
|
|
905
905
|
return utils.b58DecodePublicKeyHash(val);
|
|
906
906
|
}
|
|
@@ -908,19 +908,19 @@
|
|
|
908
908
|
throw new core.InvalidKeyHashError(val, err instanceof core.ParameterValidationError ? err.result : undefined);
|
|
909
909
|
}
|
|
910
910
|
};
|
|
911
|
-
const publicKeyHashesEncoder
|
|
911
|
+
const publicKeyHashesEncoder = (val) => {
|
|
912
912
|
if (!val) {
|
|
913
|
-
return boolEncoder
|
|
913
|
+
return boolEncoder(false);
|
|
914
914
|
}
|
|
915
915
|
if (val.length === 0) {
|
|
916
|
-
return boolEncoder
|
|
916
|
+
return boolEncoder(true) + pad(0);
|
|
917
917
|
}
|
|
918
918
|
const publicKeyHashes = val.reduce((prev, curr) => {
|
|
919
|
-
return prev + publicKeyHashEncoder
|
|
919
|
+
return prev + publicKeyHashEncoder(curr);
|
|
920
920
|
}, '');
|
|
921
|
-
return boolEncoder
|
|
921
|
+
return boolEncoder(true) + pad(publicKeyHashes.length / 2) + publicKeyHashes;
|
|
922
922
|
};
|
|
923
|
-
const publicKeyEncoder
|
|
923
|
+
const publicKeyEncoder = (val) => {
|
|
924
924
|
try {
|
|
925
925
|
return utils.b58DecodePublicKey(val);
|
|
926
926
|
}
|
|
@@ -928,12 +928,12 @@
|
|
|
928
928
|
throw new utils.InvalidPublicKeyError(val, err instanceof core.ParameterValidationError ? err.result : undefined);
|
|
929
929
|
}
|
|
930
930
|
};
|
|
931
|
-
const addressEncoder
|
|
931
|
+
const addressEncoder = (val) => {
|
|
932
932
|
return utils.b58DecodeAddress(val);
|
|
933
933
|
};
|
|
934
|
-
const smartRollupAddressEncoder
|
|
934
|
+
const smartRollupAddressEncoder = (val) => {
|
|
935
935
|
try {
|
|
936
|
-
return prefixEncoder
|
|
936
|
+
return prefixEncoder(utils.PrefixV2.SmartRollupHash)(val);
|
|
937
937
|
}
|
|
938
938
|
catch (err) {
|
|
939
939
|
if (err instanceof core.ParameterValidationError) {
|
|
@@ -944,25 +944,25 @@
|
|
|
944
944
|
}
|
|
945
945
|
}
|
|
946
946
|
};
|
|
947
|
-
const smartContractAddressEncoder
|
|
948
|
-
const publicKeyDecoder
|
|
947
|
+
const smartContractAddressEncoder = (val) => utils.b58DecodeAddress(val);
|
|
948
|
+
const publicKeyDecoder = (val) => {
|
|
949
949
|
const preamble = val.consume(1);
|
|
950
950
|
switch (preamble[0]) {
|
|
951
951
|
case 0x00:
|
|
952
|
-
return prefixDecoder
|
|
952
|
+
return prefixDecoder(utils.PrefixV2.Ed25519PublicKey)(val);
|
|
953
953
|
case 0x01:
|
|
954
|
-
return prefixDecoder
|
|
954
|
+
return prefixDecoder(utils.PrefixV2.Secp256k1PublicKey)(val);
|
|
955
955
|
case 0x02:
|
|
956
|
-
return prefixDecoder
|
|
956
|
+
return prefixDecoder(utils.PrefixV2.P256PublicKey)(val);
|
|
957
957
|
case 0x03:
|
|
958
|
-
return prefixDecoder
|
|
958
|
+
return prefixDecoder(utils.PrefixV2.BLS12_381PublicKey)(val);
|
|
959
959
|
default:
|
|
960
960
|
throw new utils.InvalidPublicKeyError(undefined, utils.ValidationResult.NO_PREFIX_MATCHED);
|
|
961
961
|
}
|
|
962
962
|
};
|
|
963
|
-
const smartRollupCommitmentHashEncoder
|
|
963
|
+
const smartRollupCommitmentHashEncoder = (val) => {
|
|
964
964
|
try {
|
|
965
|
-
return prefixEncoder
|
|
965
|
+
return prefixEncoder(utils.PrefixV2.SmartRollupCommitmentHash)(val);
|
|
966
966
|
}
|
|
967
967
|
catch (err) {
|
|
968
968
|
if (err instanceof core.ParameterValidationError) {
|
|
@@ -973,13 +973,13 @@
|
|
|
973
973
|
}
|
|
974
974
|
}
|
|
975
975
|
};
|
|
976
|
-
const addressDecoder
|
|
976
|
+
const addressDecoder = (val) => {
|
|
977
977
|
const preamble = val.consume(1);
|
|
978
978
|
switch (preamble[0]) {
|
|
979
979
|
case 0x00:
|
|
980
|
-
return publicKeyHashDecoder
|
|
980
|
+
return publicKeyHashDecoder(val);
|
|
981
981
|
case 0x01: {
|
|
982
|
-
const address = prefixDecoder
|
|
982
|
+
const address = prefixDecoder(utils.PrefixV2.ContractHash)(val);
|
|
983
983
|
val.consume(1);
|
|
984
984
|
return address;
|
|
985
985
|
}
|
|
@@ -987,22 +987,22 @@
|
|
|
987
987
|
throw new core.InvalidAddressError(val.toString(), ': Unable to decode.');
|
|
988
988
|
}
|
|
989
989
|
};
|
|
990
|
-
const smartRollupAddressDecoder
|
|
991
|
-
return prefixDecoder
|
|
990
|
+
const smartRollupAddressDecoder = (val) => {
|
|
991
|
+
return prefixDecoder(utils.PrefixV2.SmartRollupHash)(val);
|
|
992
992
|
};
|
|
993
|
-
const smartContractAddressDecoder
|
|
993
|
+
const smartContractAddressDecoder = (val) => {
|
|
994
994
|
const preamble = val.consume(1);
|
|
995
995
|
if (preamble[0] === 0x01) {
|
|
996
|
-
const scAddress = prefixDecoder
|
|
996
|
+
const scAddress = prefixDecoder(utils.PrefixV2.ContractHash)(val);
|
|
997
997
|
val.consume(1);
|
|
998
998
|
return scAddress;
|
|
999
999
|
}
|
|
1000
1000
|
throw new core.InvalidContractAddressError(val.toString(), utils.ValidationResult.NO_PREFIX_MATCHED);
|
|
1001
1001
|
};
|
|
1002
|
-
const smartRollupCommitmentHashDecoder
|
|
1003
|
-
return prefixDecoder
|
|
1002
|
+
const smartRollupCommitmentHashDecoder = (val) => {
|
|
1003
|
+
return prefixDecoder(utils.PrefixV2.SmartRollupCommitmentHash)(val);
|
|
1004
1004
|
};
|
|
1005
|
-
const zarithEncoder
|
|
1005
|
+
const zarithEncoder = (n) => {
|
|
1006
1006
|
const fn = [];
|
|
1007
1007
|
let nn = new BigNumber(n, 10);
|
|
1008
1008
|
if (nn.isNaN()) {
|
|
@@ -1026,7 +1026,7 @@
|
|
|
1026
1026
|
}
|
|
1027
1027
|
return fn.join('');
|
|
1028
1028
|
};
|
|
1029
|
-
const zarithDecoder
|
|
1029
|
+
const zarithDecoder = (n) => {
|
|
1030
1030
|
let mostSignificantByte = 0;
|
|
1031
1031
|
while (mostSignificantByte < n.length() && (n.get(mostSignificantByte) & 128) !== 0) {
|
|
1032
1032
|
mostSignificantByte += 1;
|
|
@@ -1040,97 +1040,97 @@
|
|
|
1040
1040
|
n.consume(mostSignificantByte + 1);
|
|
1041
1041
|
return new BigNumber(num).toString();
|
|
1042
1042
|
};
|
|
1043
|
-
const entrypointDecoder
|
|
1043
|
+
const entrypointDecoder = (value) => {
|
|
1044
1044
|
const preamble = pad(value.consume(1)[0], 2);
|
|
1045
|
-
if (preamble in entrypointMapping
|
|
1046
|
-
return entrypointMapping
|
|
1045
|
+
if (preamble in entrypointMapping) {
|
|
1046
|
+
return entrypointMapping[preamble];
|
|
1047
1047
|
}
|
|
1048
1048
|
else {
|
|
1049
|
-
const entry = extractRequiredLen
|
|
1049
|
+
const entry = extractRequiredLen(value, 1);
|
|
1050
1050
|
const entrypoint = Buffer.from(entry).toString('utf8');
|
|
1051
|
-
if (entrypoint.length > ENTRYPOINT_MAX_LENGTH
|
|
1051
|
+
if (entrypoint.length > ENTRYPOINT_MAX_LENGTH) {
|
|
1052
1052
|
throw new OversizedEntryPointError(entrypoint);
|
|
1053
1053
|
}
|
|
1054
1054
|
return entrypoint;
|
|
1055
1055
|
}
|
|
1056
1056
|
};
|
|
1057
|
-
const parametersDecoder
|
|
1057
|
+
const parametersDecoder = (val) => {
|
|
1058
1058
|
const preamble = val.consume(1);
|
|
1059
1059
|
if (preamble[0] === 0x00) {
|
|
1060
1060
|
return;
|
|
1061
1061
|
}
|
|
1062
1062
|
else {
|
|
1063
|
-
const encodedEntrypoint = entrypointDecoder
|
|
1064
|
-
const params = extractRequiredLen
|
|
1065
|
-
const parameters = valueDecoder
|
|
1063
|
+
const encodedEntrypoint = entrypointDecoder(val);
|
|
1064
|
+
const params = extractRequiredLen(val);
|
|
1065
|
+
const parameters = valueDecoder(new Uint8ArrayConsumer(params));
|
|
1066
1066
|
return {
|
|
1067
1067
|
entrypoint: encodedEntrypoint,
|
|
1068
1068
|
value: parameters,
|
|
1069
1069
|
};
|
|
1070
1070
|
}
|
|
1071
1071
|
};
|
|
1072
|
-
const entrypointEncoder
|
|
1073
|
-
if (entrypoint in entrypointMappingReverse
|
|
1074
|
-
return `${entrypointMappingReverse
|
|
1072
|
+
const entrypointEncoder = (entrypoint) => {
|
|
1073
|
+
if (entrypoint in entrypointMappingReverse) {
|
|
1074
|
+
return `${entrypointMappingReverse[entrypoint]}`;
|
|
1075
1075
|
}
|
|
1076
1076
|
else {
|
|
1077
|
-
if (entrypoint.length > ENTRYPOINT_MAX_LENGTH
|
|
1077
|
+
if (entrypoint.length > ENTRYPOINT_MAX_LENGTH) {
|
|
1078
1078
|
throw new OversizedEntryPointError(entrypoint);
|
|
1079
1079
|
}
|
|
1080
1080
|
const value = { string: entrypoint };
|
|
1081
|
-
return `ff${valueEncoder
|
|
1081
|
+
return `ff${valueEncoder(value).slice(8)}`;
|
|
1082
1082
|
}
|
|
1083
1083
|
};
|
|
1084
|
-
const parametersEncoder
|
|
1084
|
+
const parametersEncoder = (val) => {
|
|
1085
1085
|
if (!val || (val.entrypoint === 'default' && 'prim' in val.value && val.value.prim === 'Unit')) {
|
|
1086
1086
|
return '00';
|
|
1087
1087
|
}
|
|
1088
|
-
const encodedEntrypoint = entrypointEncoder
|
|
1089
|
-
const parameters = valueEncoder
|
|
1088
|
+
const encodedEntrypoint = entrypointEncoder(val.entrypoint);
|
|
1089
|
+
const parameters = valueEncoder(val.value);
|
|
1090
1090
|
const length = pad(parameters.length / 2);
|
|
1091
1091
|
return `ff${encodedEntrypoint}${length}${parameters}`;
|
|
1092
1092
|
};
|
|
1093
|
-
const valueParameterEncoder
|
|
1094
|
-
const valueEncoded = valueEncoder
|
|
1093
|
+
const valueParameterEncoder = (value) => {
|
|
1094
|
+
const valueEncoded = valueEncoder(value);
|
|
1095
1095
|
return `${pad(valueEncoded.length / 2)}${valueEncoded}`;
|
|
1096
1096
|
};
|
|
1097
|
-
const valueParameterDecoder
|
|
1098
|
-
const value = extractRequiredLen
|
|
1099
|
-
return valueDecoder
|
|
1097
|
+
const valueParameterDecoder = (val) => {
|
|
1098
|
+
const value = extractRequiredLen(val);
|
|
1099
|
+
return valueDecoder(new Uint8ArrayConsumer(value));
|
|
1100
1100
|
};
|
|
1101
|
-
const blockPayloadHashEncoder
|
|
1102
|
-
const blockPayloadHashDecoder
|
|
1103
|
-
const entrypointNameEncoder
|
|
1101
|
+
const blockPayloadHashEncoder = prefixEncoder(utils.PrefixV2.ValueHash);
|
|
1102
|
+
const blockPayloadHashDecoder = prefixDecoder(utils.PrefixV2.ValueHash);
|
|
1103
|
+
const entrypointNameEncoder = (entrypoint) => {
|
|
1104
1104
|
const value = { string: entrypoint };
|
|
1105
|
-
return `${valueEncoder
|
|
1105
|
+
return `${valueEncoder(value).slice(2)}`;
|
|
1106
1106
|
};
|
|
1107
|
-
const entrypointNameDecoder
|
|
1108
|
-
const entry = extractRequiredLen
|
|
1107
|
+
const entrypointNameDecoder = (val) => {
|
|
1108
|
+
const entry = extractRequiredLen(val);
|
|
1109
1109
|
return Buffer.from(entry).toString('utf8');
|
|
1110
1110
|
};
|
|
1111
|
-
const burnLimitEncoder
|
|
1112
|
-
return !val ? '00' : `ff${zarithEncoder
|
|
1111
|
+
const burnLimitEncoder = (val) => {
|
|
1112
|
+
return !val ? '00' : `ff${zarithEncoder(val)}`;
|
|
1113
1113
|
};
|
|
1114
|
-
const burnLimitDecoder
|
|
1114
|
+
const burnLimitDecoder = (value) => {
|
|
1115
1115
|
const prefix = value.consume(1);
|
|
1116
1116
|
if (Buffer.from(prefix).toString('hex') !== '00') {
|
|
1117
|
-
return zarithDecoder
|
|
1117
|
+
return zarithDecoder(value);
|
|
1118
1118
|
}
|
|
1119
1119
|
};
|
|
1120
|
-
const depositsLimitEncoder
|
|
1121
|
-
return !val ? '00' : `ff${zarithEncoder
|
|
1120
|
+
const depositsLimitEncoder = (val) => {
|
|
1121
|
+
return !val ? '00' : `ff${zarithEncoder(val)}`;
|
|
1122
1122
|
};
|
|
1123
|
-
const depositsLimitDecoder
|
|
1123
|
+
const depositsLimitDecoder = (value) => {
|
|
1124
1124
|
const prefix = value.consume(1);
|
|
1125
1125
|
if (Buffer.from(prefix).toString('hex') !== '00') {
|
|
1126
|
-
return zarithDecoder
|
|
1126
|
+
return zarithDecoder(value);
|
|
1127
1127
|
}
|
|
1128
1128
|
};
|
|
1129
|
-
const signatureV1Encoder
|
|
1129
|
+
const signatureV1Encoder = (val) => {
|
|
1130
1130
|
try {
|
|
1131
1131
|
const [data, pre] = utils.b58DecodeAndCheckPrefix(val, utils.signaturePrefixes);
|
|
1132
1132
|
if (pre === utils.PrefixV2.BLS12_381Signature) {
|
|
1133
|
-
return paddedBytesEncoder
|
|
1133
|
+
return paddedBytesEncoder(utils.buf2hex(data));
|
|
1134
1134
|
}
|
|
1135
1135
|
else {
|
|
1136
1136
|
throw new core.ProhibitedActionError('we only support encoding of BLSIG signatures from protocol Seoul');
|
|
@@ -1145,50 +1145,50 @@
|
|
|
1145
1145
|
}
|
|
1146
1146
|
}
|
|
1147
1147
|
};
|
|
1148
|
-
const signatureV1Decoder
|
|
1148
|
+
const signatureV1Decoder = (val) => {
|
|
1149
1149
|
val.consume(4);
|
|
1150
1150
|
if (val.length().toString() === '96') {
|
|
1151
|
-
return prefixDecoder
|
|
1151
|
+
return prefixDecoder(utils.PrefixV2.BLS12_381Signature)(val);
|
|
1152
1152
|
}
|
|
1153
1153
|
else {
|
|
1154
1154
|
throw new core.ProhibitedActionError('we only support decoding of BLSIG signatures');
|
|
1155
1155
|
}
|
|
1156
1156
|
};
|
|
1157
|
-
const signatureProofEncoder
|
|
1157
|
+
const signatureProofEncoder = (val) => {
|
|
1158
1158
|
if (val) {
|
|
1159
|
-
return boolEncoder
|
|
1159
|
+
return boolEncoder(true) + signatureV1Encoder(val);
|
|
1160
1160
|
}
|
|
1161
1161
|
else {
|
|
1162
|
-
return boolEncoder
|
|
1162
|
+
return boolEncoder(false);
|
|
1163
1163
|
}
|
|
1164
1164
|
};
|
|
1165
|
-
const signatureProofDecoder
|
|
1166
|
-
const hasProof = boolDecoder
|
|
1165
|
+
const signatureProofDecoder = (value) => {
|
|
1166
|
+
const hasProof = boolDecoder(value);
|
|
1167
1167
|
if (hasProof) {
|
|
1168
|
-
return signatureV1Decoder
|
|
1168
|
+
return signatureV1Decoder(value);
|
|
1169
1169
|
}
|
|
1170
1170
|
};
|
|
1171
|
-
const paddedBytesEncoder
|
|
1171
|
+
const paddedBytesEncoder = (val, paddingLength = 8) => {
|
|
1172
1172
|
return `${pad(val.length / 2, paddingLength)}${val}`;
|
|
1173
1173
|
};
|
|
1174
|
-
const paddedBytesDecoder
|
|
1175
|
-
const value = extractRequiredLen
|
|
1174
|
+
const paddedBytesDecoder = (val) => {
|
|
1175
|
+
const value = extractRequiredLen(val);
|
|
1176
1176
|
return Buffer.from(value).toString('hex');
|
|
1177
1177
|
};
|
|
1178
|
-
const smartRollupMessageEncoder
|
|
1178
|
+
const smartRollupMessageEncoder = (val) => {
|
|
1179
1179
|
const message = val.reduce((prev, curr) => {
|
|
1180
1180
|
return prev + `${pad(curr.length / 2)}${curr}`;
|
|
1181
1181
|
}, '');
|
|
1182
1182
|
return `${pad(message.length / 2)}${message}`;
|
|
1183
1183
|
};
|
|
1184
|
-
const smartRollupMessageDecoder
|
|
1185
|
-
const valueArray = extractRequiredLen
|
|
1186
|
-
const ret = stripLengthPrefixFromBytes
|
|
1184
|
+
const smartRollupMessageDecoder = (val) => {
|
|
1185
|
+
const valueArray = extractRequiredLen(val);
|
|
1186
|
+
const ret = stripLengthPrefixFromBytes(new Uint8ArrayConsumer(valueArray));
|
|
1187
1187
|
return ret.map((value) => Buffer.from(value).toString('hex'));
|
|
1188
1188
|
};
|
|
1189
|
-
const dalCommitmentEncoder
|
|
1189
|
+
const dalCommitmentEncoder = (val) => {
|
|
1190
1190
|
try {
|
|
1191
|
-
return prefixEncoder
|
|
1191
|
+
return prefixEncoder(utils.PrefixV2.SlotHeader)(val);
|
|
1192
1192
|
}
|
|
1193
1193
|
catch (err) {
|
|
1194
1194
|
if (err instanceof core.ParameterValidationError) {
|
|
@@ -1199,30 +1199,30 @@
|
|
|
1199
1199
|
}
|
|
1200
1200
|
}
|
|
1201
1201
|
};
|
|
1202
|
-
const dalCommitmentDecoder
|
|
1203
|
-
return prefixDecoder
|
|
1202
|
+
const dalCommitmentDecoder = (val) => {
|
|
1203
|
+
return prefixDecoder(utils.PrefixV2.SlotHeader)(val);
|
|
1204
1204
|
};
|
|
1205
|
-
const slotHeaderEncoder
|
|
1206
|
-
return pad(val.slot_index, 2) + dalCommitmentEncoder
|
|
1205
|
+
const slotHeaderEncoder = (val) => {
|
|
1206
|
+
return pad(val.slot_index, 2) + dalCommitmentEncoder(val.commitment) + val.commitment_proof;
|
|
1207
1207
|
};
|
|
1208
|
-
const slotHeaderDecoder
|
|
1208
|
+
const slotHeaderDecoder = (val) => {
|
|
1209
1209
|
const preamble = val.consume(1);
|
|
1210
1210
|
return {
|
|
1211
1211
|
slot_index: Number(preamble[0].toString(10)),
|
|
1212
|
-
commitment: dalCommitmentDecoder
|
|
1212
|
+
commitment: dalCommitmentDecoder(val),
|
|
1213
1213
|
commitment_proof: toHexString(val.consume(96)), // rpcForger expect commitment_proof bytes to be len 96
|
|
1214
1214
|
};
|
|
1215
1215
|
};
|
|
1216
1216
|
|
|
1217
|
-
const ManagerOperationSchema
|
|
1217
|
+
const ManagerOperationSchema = {
|
|
1218
1218
|
branch: exports.CODEC.BRANCH,
|
|
1219
1219
|
contents: [exports.CODEC.OPERATION],
|
|
1220
1220
|
};
|
|
1221
|
-
const ActivationSchema
|
|
1221
|
+
const ActivationSchema = {
|
|
1222
1222
|
pkh: exports.CODEC.TZ1,
|
|
1223
1223
|
secret: exports.CODEC.SECRET,
|
|
1224
1224
|
};
|
|
1225
|
-
const RevealSchema
|
|
1225
|
+
const RevealSchema = {
|
|
1226
1226
|
source: exports.CODEC.PKH,
|
|
1227
1227
|
fee: exports.CODEC.ZARITH,
|
|
1228
1228
|
counter: exports.CODEC.ZARITH,
|
|
@@ -1231,7 +1231,7 @@
|
|
|
1231
1231
|
public_key: exports.CODEC.PUBLIC_KEY,
|
|
1232
1232
|
proof: exports.CODEC.SIGNATURE_PROOF,
|
|
1233
1233
|
};
|
|
1234
|
-
const DelegationSchema
|
|
1234
|
+
const DelegationSchema = {
|
|
1235
1235
|
source: exports.CODEC.PKH,
|
|
1236
1236
|
fee: exports.CODEC.ZARITH,
|
|
1237
1237
|
counter: exports.CODEC.ZARITH,
|
|
@@ -1239,7 +1239,7 @@
|
|
|
1239
1239
|
storage_limit: exports.CODEC.ZARITH,
|
|
1240
1240
|
delegate: exports.CODEC.DELEGATE,
|
|
1241
1241
|
};
|
|
1242
|
-
const TransactionSchema
|
|
1242
|
+
const TransactionSchema = {
|
|
1243
1243
|
source: exports.CODEC.PKH,
|
|
1244
1244
|
fee: exports.CODEC.ZARITH,
|
|
1245
1245
|
counter: exports.CODEC.ZARITH,
|
|
@@ -1249,7 +1249,7 @@
|
|
|
1249
1249
|
destination: exports.CODEC.ADDRESS,
|
|
1250
1250
|
parameters: exports.CODEC.PARAMETERS,
|
|
1251
1251
|
};
|
|
1252
|
-
const OriginationSchema
|
|
1252
|
+
const OriginationSchema = {
|
|
1253
1253
|
source: exports.CODEC.PKH,
|
|
1254
1254
|
fee: exports.CODEC.ZARITH,
|
|
1255
1255
|
counter: exports.CODEC.ZARITH,
|
|
@@ -1259,35 +1259,35 @@
|
|
|
1259
1259
|
delegate: exports.CODEC.DELEGATE,
|
|
1260
1260
|
script: exports.CODEC.SCRIPT,
|
|
1261
1261
|
};
|
|
1262
|
-
const BallotSchema
|
|
1262
|
+
const BallotSchema = {
|
|
1263
1263
|
source: exports.CODEC.PKH,
|
|
1264
1264
|
period: exports.CODEC.INT32,
|
|
1265
1265
|
proposal: exports.CODEC.PROPOSAL,
|
|
1266
1266
|
ballot: exports.CODEC.BALLOT_STATEMENT,
|
|
1267
1267
|
};
|
|
1268
|
-
const AttestationSchema
|
|
1268
|
+
const AttestationSchema = {
|
|
1269
1269
|
slot: exports.CODEC.INT16,
|
|
1270
1270
|
level: exports.CODEC.INT32,
|
|
1271
1271
|
round: exports.CODEC.INT32,
|
|
1272
1272
|
block_payload_hash: exports.CODEC.BLOCK_PAYLOAD_HASH,
|
|
1273
1273
|
};
|
|
1274
|
-
const AttestationWithDalSchema
|
|
1274
|
+
const AttestationWithDalSchema = {
|
|
1275
1275
|
slot: exports.CODEC.INT16,
|
|
1276
1276
|
level: exports.CODEC.INT32,
|
|
1277
1277
|
round: exports.CODEC.INT32,
|
|
1278
1278
|
block_payload_hash: exports.CODEC.BLOCK_PAYLOAD_HASH,
|
|
1279
1279
|
dal_attestation: exports.CODEC.ZARITH,
|
|
1280
1280
|
};
|
|
1281
|
-
const SeedNonceRevelationSchema
|
|
1281
|
+
const SeedNonceRevelationSchema = {
|
|
1282
1282
|
level: exports.CODEC.INT32,
|
|
1283
1283
|
nonce: exports.CODEC.RAW,
|
|
1284
1284
|
};
|
|
1285
|
-
const ProposalsSchema
|
|
1285
|
+
const ProposalsSchema = {
|
|
1286
1286
|
source: exports.CODEC.PKH,
|
|
1287
1287
|
period: exports.CODEC.INT32,
|
|
1288
1288
|
proposals: exports.CODEC.PROPOSAL_ARR,
|
|
1289
1289
|
};
|
|
1290
|
-
const RegisterGlobalConstantSchema
|
|
1290
|
+
const RegisterGlobalConstantSchema = {
|
|
1291
1291
|
source: exports.CODEC.PKH,
|
|
1292
1292
|
fee: exports.CODEC.ZARITH,
|
|
1293
1293
|
counter: exports.CODEC.ZARITH,
|
|
@@ -1295,7 +1295,7 @@
|
|
|
1295
1295
|
storage_limit: exports.CODEC.ZARITH,
|
|
1296
1296
|
value: exports.CODEC.VALUE,
|
|
1297
1297
|
};
|
|
1298
|
-
const TransferTicketSchema
|
|
1298
|
+
const TransferTicketSchema = {
|
|
1299
1299
|
source: exports.CODEC.PKH,
|
|
1300
1300
|
fee: exports.CODEC.ZARITH,
|
|
1301
1301
|
counter: exports.CODEC.ZARITH,
|
|
@@ -1308,7 +1308,7 @@
|
|
|
1308
1308
|
destination: exports.CODEC.ADDRESS,
|
|
1309
1309
|
entrypoint: exports.CODEC.ENTRYPOINT,
|
|
1310
1310
|
};
|
|
1311
|
-
const IncreasePaidStorageSchema
|
|
1311
|
+
const IncreasePaidStorageSchema = {
|
|
1312
1312
|
source: exports.CODEC.PKH,
|
|
1313
1313
|
fee: exports.CODEC.ZARITH,
|
|
1314
1314
|
counter: exports.CODEC.ZARITH,
|
|
@@ -1317,7 +1317,7 @@
|
|
|
1317
1317
|
amount: exports.CODEC.ZARITH,
|
|
1318
1318
|
destination: exports.CODEC.SMART_CONTRACT_ADDRESS,
|
|
1319
1319
|
};
|
|
1320
|
-
const UpdateConsensusKeySchema
|
|
1320
|
+
const UpdateConsensusKeySchema = {
|
|
1321
1321
|
source: exports.CODEC.PKH,
|
|
1322
1322
|
fee: exports.CODEC.ZARITH,
|
|
1323
1323
|
counter: exports.CODEC.ZARITH,
|
|
@@ -1335,12 +1335,12 @@
|
|
|
1335
1335
|
pk: exports.CODEC.PUBLIC_KEY,
|
|
1336
1336
|
proof: exports.CODEC.SIGNATURE_PROOF,
|
|
1337
1337
|
};
|
|
1338
|
-
const DrainDelegateSchema
|
|
1338
|
+
const DrainDelegateSchema = {
|
|
1339
1339
|
consensus_key: exports.CODEC.PKH,
|
|
1340
1340
|
delegate: exports.CODEC.PKH,
|
|
1341
1341
|
destination: exports.CODEC.PKH,
|
|
1342
1342
|
};
|
|
1343
|
-
const SetDepositsLimitSchema
|
|
1343
|
+
const SetDepositsLimitSchema = {
|
|
1344
1344
|
source: exports.CODEC.PKH,
|
|
1345
1345
|
fee: exports.CODEC.ZARITH,
|
|
1346
1346
|
counter: exports.CODEC.ZARITH,
|
|
@@ -1348,7 +1348,7 @@
|
|
|
1348
1348
|
storage_limit: exports.CODEC.ZARITH,
|
|
1349
1349
|
limit: exports.CODEC.DEPOSITS_LIMIT,
|
|
1350
1350
|
};
|
|
1351
|
-
const SmartRollupOriginateSchema
|
|
1351
|
+
const SmartRollupOriginateSchema = {
|
|
1352
1352
|
source: exports.CODEC.PKH,
|
|
1353
1353
|
fee: exports.CODEC.ZARITH,
|
|
1354
1354
|
counter: exports.CODEC.ZARITH,
|
|
@@ -1359,7 +1359,7 @@
|
|
|
1359
1359
|
parameters_ty: exports.CODEC.VALUE,
|
|
1360
1360
|
whitelist: exports.CODEC.PKH_ARR,
|
|
1361
1361
|
};
|
|
1362
|
-
const SmartRollupAddMessagesSchema
|
|
1362
|
+
const SmartRollupAddMessagesSchema = {
|
|
1363
1363
|
source: exports.CODEC.PKH,
|
|
1364
1364
|
fee: exports.CODEC.ZARITH,
|
|
1365
1365
|
counter: exports.CODEC.ZARITH,
|
|
@@ -1367,7 +1367,7 @@
|
|
|
1367
1367
|
storage_limit: exports.CODEC.ZARITH,
|
|
1368
1368
|
message: exports.CODEC.SMART_ROLLUP_MESSAGE,
|
|
1369
1369
|
};
|
|
1370
|
-
const SmartRollupExecuteOutboxMessageSchema
|
|
1370
|
+
const SmartRollupExecuteOutboxMessageSchema = {
|
|
1371
1371
|
source: exports.CODEC.PKH,
|
|
1372
1372
|
fee: exports.CODEC.ZARITH,
|
|
1373
1373
|
counter: exports.CODEC.ZARITH,
|
|
@@ -1377,7 +1377,7 @@
|
|
|
1377
1377
|
cemented_commitment: exports.CODEC.SMART_ROLLUP_COMMITMENT_HASH,
|
|
1378
1378
|
output_proof: exports.CODEC.PADDED_BYTES,
|
|
1379
1379
|
};
|
|
1380
|
-
const DalPublishCommitmentSchema
|
|
1380
|
+
const DalPublishCommitmentSchema = {
|
|
1381
1381
|
source: exports.CODEC.PKH,
|
|
1382
1382
|
fee: exports.CODEC.ZARITH,
|
|
1383
1383
|
counter: exports.CODEC.ZARITH,
|
|
@@ -1385,18 +1385,18 @@
|
|
|
1385
1385
|
storage_limit: exports.CODEC.ZARITH,
|
|
1386
1386
|
slot_header: exports.CODEC.SLOT_HEADER,
|
|
1387
1387
|
};
|
|
1388
|
-
const FailingNoopSchema
|
|
1388
|
+
const FailingNoopSchema = {
|
|
1389
1389
|
arbitrary: exports.CODEC.PADDED_BYTES,
|
|
1390
1390
|
};
|
|
1391
|
-
const operationEncoder
|
|
1392
|
-
if (!(operation.kind in encoders) || !(operation.kind in kindMappingReverse
|
|
1391
|
+
const operationEncoder = (encoders) => (operation) => {
|
|
1392
|
+
if (!(operation.kind in encoders) || !(operation.kind in kindMappingReverse)) {
|
|
1393
1393
|
throw new core.InvalidOperationKindError(operation.kind);
|
|
1394
1394
|
}
|
|
1395
|
-
return kindMappingReverse
|
|
1395
|
+
return kindMappingReverse[operation.kind] + encoders[operation.kind](operation);
|
|
1396
1396
|
};
|
|
1397
|
-
const operationDecoder
|
|
1397
|
+
const operationDecoder = (decoders) => (value) => {
|
|
1398
1398
|
const op = value.consume(1);
|
|
1399
|
-
const operationName = kindMapping
|
|
1399
|
+
const operationName = kindMapping[op[0]];
|
|
1400
1400
|
if (operationName === undefined) {
|
|
1401
1401
|
throw new UnsupportedOperationError(op[0].toString());
|
|
1402
1402
|
}
|
|
@@ -1406,7 +1406,7 @@
|
|
|
1406
1406
|
}
|
|
1407
1407
|
return Object.assign({ kind: operationName }, decodedObj);
|
|
1408
1408
|
};
|
|
1409
|
-
const schemaEncoder
|
|
1409
|
+
const schemaEncoder = (encoders) => (schema) => (value) => {
|
|
1410
1410
|
const keys = Object.keys(schema);
|
|
1411
1411
|
return keys.reduce((prev, key) => {
|
|
1412
1412
|
const valueToEncode = schema[key];
|
|
@@ -1424,7 +1424,7 @@
|
|
|
1424
1424
|
}
|
|
1425
1425
|
}, '');
|
|
1426
1426
|
};
|
|
1427
|
-
const schemaDecoder
|
|
1427
|
+
const schemaDecoder = (decoders) => (schema) => (value) => {
|
|
1428
1428
|
const keys = Object.keys(schema);
|
|
1429
1429
|
return keys.reduce((prev, key) => {
|
|
1430
1430
|
const valueToEncode = schema[key];
|
|
@@ -1453,1526 +1453,153 @@
|
|
|
1453
1453
|
}, {});
|
|
1454
1454
|
};
|
|
1455
1455
|
|
|
1456
|
-
const decoders
|
|
1456
|
+
const decoders = {
|
|
1457
1457
|
[exports.CODEC.SECRET]: (val) => toHexString(val.consume(20)),
|
|
1458
1458
|
[exports.CODEC.RAW]: (val) => toHexString(val.consume(32)),
|
|
1459
|
-
[exports.CODEC.TZ1]: tz1Decoder
|
|
1460
|
-
[exports.CODEC.BRANCH]: branchDecoder
|
|
1461
|
-
[exports.CODEC.ZARITH]: zarithDecoder
|
|
1462
|
-
[exports.CODEC.PUBLIC_KEY]: publicKeyDecoder
|
|
1463
|
-
[exports.CODEC.PKH]: publicKeyHashDecoder
|
|
1464
|
-
[exports.CODEC.PKH_ARR]: publicKeyHashesDecoder
|
|
1465
|
-
[exports.CODEC.DELEGATE]: delegateDecoder
|
|
1466
|
-
[exports.CODEC.INT32]: int32Decoder
|
|
1467
|
-
[exports.CODEC.SCRIPT]: scriptDecoder
|
|
1468
|
-
[exports.CODEC.BALLOT_STATEMENT]: ballotDecoder
|
|
1469
|
-
[exports.CODEC.PROPOSAL]: proposalDecoder
|
|
1470
|
-
[exports.CODEC.PROPOSAL_ARR]: proposalsDecoder
|
|
1471
|
-
[exports.CODEC.PARAMETERS]: parametersDecoder
|
|
1472
|
-
[exports.CODEC.ADDRESS]: addressDecoder
|
|
1473
|
-
[exports.CODEC.SMART_ROLLUP_ADDRESS]: smartRollupAddressDecoder
|
|
1474
|
-
[exports.CODEC.SMART_CONTRACT_ADDRESS]: smartContractAddressDecoder
|
|
1475
|
-
[exports.CODEC.SMART_ROLLUP_COMMITMENT_HASH]: smartRollupCommitmentHashDecoder
|
|
1476
|
-
[exports.CODEC.VALUE]: valueParameterDecoder
|
|
1477
|
-
[exports.CODEC.INT16]: int16Decoder
|
|
1478
|
-
[exports.CODEC.BLOCK_PAYLOAD_HASH]: blockPayloadHashDecoder
|
|
1479
|
-
[exports.CODEC.ENTRYPOINT]: entrypointNameDecoder
|
|
1480
|
-
[exports.CODEC.BURN_LIMIT]: burnLimitDecoder
|
|
1481
|
-
[exports.CODEC.DEPOSITS_LIMIT]: depositsLimitDecoder
|
|
1482
|
-
[exports.CODEC.SIGNATURE_PROOF]: signatureProofDecoder
|
|
1483
|
-
[exports.CODEC.PVM_KIND]: pvmKindDecoder
|
|
1484
|
-
[exports.CODEC.PADDED_BYTES]: paddedBytesDecoder
|
|
1485
|
-
[exports.CODEC.SMART_ROLLUP_MESSAGE]: smartRollupMessageDecoder
|
|
1486
|
-
[exports.CODEC.SLOT_HEADER]: slotHeaderDecoder
|
|
1487
|
-
};
|
|
1488
|
-
decoders
|
|
1489
|
-
decoders
|
|
1490
|
-
decoders
|
|
1491
|
-
decoders
|
|
1492
|
-
decoders
|
|
1493
|
-
decoders
|
|
1494
|
-
decoders
|
|
1495
|
-
decoders
|
|
1496
|
-
decoders
|
|
1497
|
-
decoders
|
|
1498
|
-
decoders
|
|
1499
|
-
decoders
|
|
1500
|
-
decoders
|
|
1501
|
-
decoders
|
|
1502
|
-
decoders
|
|
1503
|
-
decoders
|
|
1504
|
-
decoders
|
|
1505
|
-
decoders
|
|
1506
|
-
decoders
|
|
1507
|
-
decoders
|
|
1508
|
-
decoders
|
|
1509
|
-
decoders
|
|
1510
|
-
decoders
|
|
1511
|
-
decoders
|
|
1459
|
+
[exports.CODEC.TZ1]: tz1Decoder,
|
|
1460
|
+
[exports.CODEC.BRANCH]: branchDecoder,
|
|
1461
|
+
[exports.CODEC.ZARITH]: zarithDecoder,
|
|
1462
|
+
[exports.CODEC.PUBLIC_KEY]: publicKeyDecoder,
|
|
1463
|
+
[exports.CODEC.PKH]: publicKeyHashDecoder,
|
|
1464
|
+
[exports.CODEC.PKH_ARR]: publicKeyHashesDecoder,
|
|
1465
|
+
[exports.CODEC.DELEGATE]: delegateDecoder,
|
|
1466
|
+
[exports.CODEC.INT32]: int32Decoder,
|
|
1467
|
+
[exports.CODEC.SCRIPT]: scriptDecoder,
|
|
1468
|
+
[exports.CODEC.BALLOT_STATEMENT]: ballotDecoder,
|
|
1469
|
+
[exports.CODEC.PROPOSAL]: proposalDecoder,
|
|
1470
|
+
[exports.CODEC.PROPOSAL_ARR]: proposalsDecoder,
|
|
1471
|
+
[exports.CODEC.PARAMETERS]: parametersDecoder,
|
|
1472
|
+
[exports.CODEC.ADDRESS]: addressDecoder,
|
|
1473
|
+
[exports.CODEC.SMART_ROLLUP_ADDRESS]: smartRollupAddressDecoder,
|
|
1474
|
+
[exports.CODEC.SMART_CONTRACT_ADDRESS]: smartContractAddressDecoder,
|
|
1475
|
+
[exports.CODEC.SMART_ROLLUP_COMMITMENT_HASH]: smartRollupCommitmentHashDecoder,
|
|
1476
|
+
[exports.CODEC.VALUE]: valueParameterDecoder,
|
|
1477
|
+
[exports.CODEC.INT16]: int16Decoder,
|
|
1478
|
+
[exports.CODEC.BLOCK_PAYLOAD_HASH]: blockPayloadHashDecoder,
|
|
1479
|
+
[exports.CODEC.ENTRYPOINT]: entrypointNameDecoder,
|
|
1480
|
+
[exports.CODEC.BURN_LIMIT]: burnLimitDecoder,
|
|
1481
|
+
[exports.CODEC.DEPOSITS_LIMIT]: depositsLimitDecoder,
|
|
1482
|
+
[exports.CODEC.SIGNATURE_PROOF]: signatureProofDecoder,
|
|
1483
|
+
[exports.CODEC.PVM_KIND]: pvmKindDecoder,
|
|
1484
|
+
[exports.CODEC.PADDED_BYTES]: paddedBytesDecoder,
|
|
1485
|
+
[exports.CODEC.SMART_ROLLUP_MESSAGE]: smartRollupMessageDecoder,
|
|
1486
|
+
[exports.CODEC.SLOT_HEADER]: slotHeaderDecoder,
|
|
1487
|
+
};
|
|
1488
|
+
decoders[exports.CODEC.OPERATION] = operationDecoder(decoders);
|
|
1489
|
+
decoders[exports.CODEC.OP_ACTIVATE_ACCOUNT] = (val) => schemaDecoder(decoders)(ActivationSchema)(val);
|
|
1490
|
+
decoders[exports.CODEC.OP_FAILING_NOOP] = (val) => schemaDecoder(decoders)(FailingNoopSchema)(val);
|
|
1491
|
+
decoders[exports.CODEC.OP_DELEGATION] = (val) => schemaDecoder(decoders)(DelegationSchema)(val);
|
|
1492
|
+
decoders[exports.CODEC.OP_TRANSACTION] = (val) => schemaDecoder(decoders)(TransactionSchema)(val);
|
|
1493
|
+
decoders[exports.CODEC.OP_ORIGINATION] = (val) => schemaDecoder(decoders)(OriginationSchema)(val);
|
|
1494
|
+
decoders[exports.CODEC.OP_BALLOT] = (val) => schemaDecoder(decoders)(BallotSchema)(val);
|
|
1495
|
+
decoders[exports.CODEC.OP_ATTESTATION] = (val) => schemaDecoder(decoders)(AttestationSchema)(val);
|
|
1496
|
+
decoders[exports.CODEC.OP_ATTESTATION_WITH_DAL] = (val) => schemaDecoder(decoders)(AttestationWithDalSchema)(val);
|
|
1497
|
+
decoders[exports.CODEC.OP_SEED_NONCE_REVELATION] = (val) => schemaDecoder(decoders)(SeedNonceRevelationSchema)(val);
|
|
1498
|
+
decoders[exports.CODEC.OP_PROPOSALS] = (val) => schemaDecoder(decoders)(ProposalsSchema)(val);
|
|
1499
|
+
decoders[exports.CODEC.OP_REVEAL] = (val) => schemaDecoder(decoders)(RevealSchema)(val);
|
|
1500
|
+
decoders[exports.CODEC.OP_REGISTER_GLOBAL_CONSTANT] = (val) => schemaDecoder(decoders)(RegisterGlobalConstantSchema)(val);
|
|
1501
|
+
decoders[exports.CODEC.OP_TRANSFER_TICKET] = (val) => schemaDecoder(decoders)(TransferTicketSchema)(val);
|
|
1502
|
+
decoders[exports.CODEC.OP_INCREASE_PAID_STORAGE] = (val) => schemaDecoder(decoders)(IncreasePaidStorageSchema)(val);
|
|
1503
|
+
decoders[exports.CODEC.OP_UPDATE_CONSENSUS_KEY] = (val) => schemaDecoder(decoders)(UpdateConsensusKeySchema)(val);
|
|
1504
|
+
decoders[exports.CODEC.OP_UPDATE_COMPANION_KEY] = (val) => schemaDecoder(decoders)(UpdateCompanionKeySchema)(val);
|
|
1505
|
+
decoders[exports.CODEC.OP_DRAIN_DELEGATE] = (val) => schemaDecoder(decoders)(DrainDelegateSchema)(val);
|
|
1506
|
+
decoders[exports.CODEC.OP_SMART_ROLLUP_ORIGINATE] = (val) => schemaDecoder(decoders)(SmartRollupOriginateSchema)(val);
|
|
1507
|
+
decoders[exports.CODEC.OP_SMART_ROLLUP_ADD_MESSAGES] = (val) => schemaDecoder(decoders)(SmartRollupAddMessagesSchema)(val);
|
|
1508
|
+
decoders[exports.CODEC.OP_SMART_ROLLUP_EXECUTE_OUTBOX_MESSAGE] = (val) => schemaDecoder(decoders)(SmartRollupExecuteOutboxMessageSchema)(val);
|
|
1509
|
+
decoders[exports.CODEC.OP_DAL_PUBLISH_COMMITMENT] = (val) => schemaDecoder(decoders)(DalPublishCommitmentSchema)(val);
|
|
1510
|
+
decoders[exports.CODEC.MANAGER] = schemaDecoder(decoders)(ManagerOperationSchema);
|
|
1511
|
+
decoders[exports.CODEC.OP_SET_DEPOSITS_LIMIT] = (val) => schemaDecoder(decoders)(SetDepositsLimitSchema)(val);
|
|
1512
1512
|
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
CODEC
|
|
1522
|
-
CODEC
|
|
1523
|
-
CODEC
|
|
1524
|
-
CODEC
|
|
1525
|
-
CODEC
|
|
1526
|
-
CODEC
|
|
1527
|
-
CODEC
|
|
1528
|
-
CODEC
|
|
1529
|
-
CODEC
|
|
1530
|
-
CODEC
|
|
1531
|
-
CODEC
|
|
1532
|
-
CODEC
|
|
1533
|
-
CODEC
|
|
1534
|
-
CODEC
|
|
1535
|
-
CODEC
|
|
1536
|
-
CODEC
|
|
1537
|
-
CODEC
|
|
1538
|
-
CODEC
|
|
1539
|
-
CODEC
|
|
1540
|
-
CODEC
|
|
1541
|
-
CODEC
|
|
1542
|
-
CODEC
|
|
1543
|
-
CODEC
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
'1a': 'CONCAT',
|
|
1604
|
-
'1b': 'CONS',
|
|
1605
|
-
'1c': 'CREATE_ACCOUNT', // Removed in Edo
|
|
1606
|
-
'1d': 'CREATE_CONTRACT', // Removed in Edo
|
|
1607
|
-
'1e': 'IMPLICIT_ACCOUNT',
|
|
1608
|
-
'1f': 'DIP',
|
|
1609
|
-
'20': 'DROP',
|
|
1610
|
-
'21': 'DUP',
|
|
1611
|
-
'22': 'EDIV',
|
|
1612
|
-
'23': 'EMPTY_MAP',
|
|
1613
|
-
'24': 'EMPTY_SET',
|
|
1614
|
-
'25': 'EQ',
|
|
1615
|
-
'26': 'EXEC',
|
|
1616
|
-
'27': 'FAILWITH',
|
|
1617
|
-
'28': 'GE',
|
|
1618
|
-
'29': 'GET',
|
|
1619
|
-
'2a': 'GT',
|
|
1620
|
-
'2b': 'HASH_KEY',
|
|
1621
|
-
'2c': 'IF',
|
|
1622
|
-
'2d': 'IF_CONS',
|
|
1623
|
-
'2e': 'IF_LEFT',
|
|
1624
|
-
'2f': 'IF_NONE',
|
|
1625
|
-
'30': 'INT',
|
|
1626
|
-
'31': 'LAMBDA',
|
|
1627
|
-
'32': 'LE',
|
|
1628
|
-
'33': 'LEFT',
|
|
1629
|
-
'34': 'LOOP',
|
|
1630
|
-
'35': 'LSL',
|
|
1631
|
-
'36': 'LSR',
|
|
1632
|
-
'37': 'LT',
|
|
1633
|
-
'38': 'MAP',
|
|
1634
|
-
'39': 'MEM',
|
|
1635
|
-
'3a': 'MUL',
|
|
1636
|
-
'3b': 'NEG',
|
|
1637
|
-
'3c': 'NEQ',
|
|
1638
|
-
'3d': 'NIL',
|
|
1639
|
-
'3e': 'NONE',
|
|
1640
|
-
'3f': 'NOT',
|
|
1641
|
-
'40': 'NOW',
|
|
1642
|
-
'41': 'OR',
|
|
1643
|
-
'42': 'PAIR',
|
|
1644
|
-
'43': 'PUSH',
|
|
1645
|
-
'44': 'RIGHT',
|
|
1646
|
-
'45': 'SIZE',
|
|
1647
|
-
'46': 'SOME',
|
|
1648
|
-
'47': 'SOURCE',
|
|
1649
|
-
'48': 'SENDER',
|
|
1650
|
-
'49': 'SELF',
|
|
1651
|
-
'4a': 'STEPS_TO_QUOTA', // Removed in Edo
|
|
1652
|
-
'4b': 'SUB',
|
|
1653
|
-
'4c': 'SWAP',
|
|
1654
|
-
'4d': 'TRANSFER_TOKENS',
|
|
1655
|
-
'4e': 'SET_DELEGATE',
|
|
1656
|
-
'4f': 'UNIT',
|
|
1657
|
-
'50': 'UPDATE',
|
|
1658
|
-
'51': 'XOR',
|
|
1659
|
-
'52': 'ITER',
|
|
1660
|
-
'53': 'LOOP_LEFT',
|
|
1661
|
-
'54': 'ADDRESS',
|
|
1662
|
-
'55': 'CONTRACT',
|
|
1663
|
-
'56': 'ISNAT',
|
|
1664
|
-
'57': 'CAST',
|
|
1665
|
-
'58': 'RENAME',
|
|
1666
|
-
'59': 'bool',
|
|
1667
|
-
'5a': 'contract',
|
|
1668
|
-
'5b': 'int',
|
|
1669
|
-
'5c': 'key',
|
|
1670
|
-
'5d': 'key_hash',
|
|
1671
|
-
'5e': 'lambda',
|
|
1672
|
-
'5f': 'list',
|
|
1673
|
-
'60': 'map',
|
|
1674
|
-
'61': 'big_map',
|
|
1675
|
-
'62': 'nat',
|
|
1676
|
-
'63': 'option',
|
|
1677
|
-
'64': 'or',
|
|
1678
|
-
'65': 'pair',
|
|
1679
|
-
'66': 'set',
|
|
1680
|
-
'67': 'signature',
|
|
1681
|
-
'68': 'string',
|
|
1682
|
-
'69': 'bytes',
|
|
1683
|
-
'6a': 'mutez',
|
|
1684
|
-
'6b': 'timestamp',
|
|
1685
|
-
'6c': 'unit',
|
|
1686
|
-
'6d': 'operation',
|
|
1687
|
-
'6e': 'address',
|
|
1688
|
-
'6f': 'SLICE',
|
|
1689
|
-
'70': 'DIG',
|
|
1690
|
-
'71': 'DUG',
|
|
1691
|
-
'72': 'EMPTY_BIG_MAP',
|
|
1692
|
-
'73': 'APPLY',
|
|
1693
|
-
'74': 'chain_id',
|
|
1694
|
-
'75': 'CHAIN_ID',
|
|
1695
|
-
'76': 'LEVEL',
|
|
1696
|
-
'77': 'SELF_ADDRESS',
|
|
1697
|
-
'78': 'never',
|
|
1698
|
-
'79': 'NEVER',
|
|
1699
|
-
'7a': 'UNPAIR',
|
|
1700
|
-
'7b': 'VOTING_POWER',
|
|
1701
|
-
'7c': 'TOTAL_VOTING_POWER',
|
|
1702
|
-
'7d': 'KECCAK',
|
|
1703
|
-
'7e': 'SHA3',
|
|
1704
|
-
'7f': 'PAIRING_CHECK',
|
|
1705
|
-
'80': 'bls12_381_g1',
|
|
1706
|
-
'81': 'bls12_381_g2',
|
|
1707
|
-
'82': 'bls12_381_fr',
|
|
1708
|
-
'83': 'sapling_state',
|
|
1709
|
-
'84': 'sapling_transaction_deprecated',
|
|
1710
|
-
'85': 'SAPLING_EMPTY_STATE',
|
|
1711
|
-
'86': 'SAPLING_VERIFY_UPDATE',
|
|
1712
|
-
'87': 'ticket',
|
|
1713
|
-
'88': 'TICKET_DEPRECATED',
|
|
1714
|
-
'89': 'READ_TICKET',
|
|
1715
|
-
'8a': 'SPLIT_TICKET',
|
|
1716
|
-
'8b': 'JOIN_TICKETS',
|
|
1717
|
-
'8c': 'GET_AND_UPDATE',
|
|
1718
|
-
'8d': 'chest',
|
|
1719
|
-
'8e': 'chest_key',
|
|
1720
|
-
'8f': 'OPEN_CHEST',
|
|
1721
|
-
'90': 'VIEW',
|
|
1722
|
-
'91': 'view',
|
|
1723
|
-
'92': 'constant',
|
|
1724
|
-
'93': 'SUB_MUTEZ',
|
|
1725
|
-
'94': 'tx_rollup_l2_address',
|
|
1726
|
-
'95': 'MIN_BLOCK_TIME',
|
|
1727
|
-
'96': 'sapling_transaction',
|
|
1728
|
-
'97': 'EMIT',
|
|
1729
|
-
'98': 'Lambda_rec',
|
|
1730
|
-
'99': 'LAMBDA_REC',
|
|
1731
|
-
'9a': 'TICKET',
|
|
1732
|
-
'9b': 'BYTES',
|
|
1733
|
-
'9c': 'NAT',
|
|
1734
|
-
'9d': 'Ticket',
|
|
1735
|
-
};
|
|
1736
|
-
const opMappingReverse = (() => {
|
|
1737
|
-
const result = {};
|
|
1738
|
-
Object.keys(opMapping).forEach((key) => {
|
|
1739
|
-
result[opMapping[key]] = key;
|
|
1740
|
-
});
|
|
1741
|
-
return result;
|
|
1742
|
-
})();
|
|
1743
|
-
// See https://tezos.gitlab.io/shell/p2p_api.html
|
|
1744
|
-
const kindMapping = {
|
|
1745
|
-
0x04: 'activate_account',
|
|
1746
|
-
0x6b: 'reveal',
|
|
1747
|
-
0x6e: 'delegation',
|
|
1748
|
-
0x6c: 'transaction',
|
|
1749
|
-
0x6d: 'origination',
|
|
1750
|
-
0x06: 'ballot',
|
|
1751
|
-
0x15: 'attestation',
|
|
1752
|
-
0x17: 'attestation_with_dal',
|
|
1753
|
-
0x01: 'seed_nonce_revelation',
|
|
1754
|
-
0x05: 'proposals',
|
|
1755
|
-
0x6f: 'register_global_constant',
|
|
1756
|
-
0x9e: 'transfer_ticket',
|
|
1757
|
-
0x70: 'set_deposits_limit',
|
|
1758
|
-
0x71: 'increase_paid_storage',
|
|
1759
|
-
0x72: 'update_consensus_key',
|
|
1760
|
-
0x09: 'drain_delegate',
|
|
1761
|
-
0xc8: 'smart_rollup_originate',
|
|
1762
|
-
0xc9: 'smart_rollup_add_messages',
|
|
1763
|
-
0xce: 'smart_rollup_execute_outbox_message',
|
|
1764
|
-
0xe6: 'dal_publish_commitment',
|
|
1765
|
-
0x11: 'failing_noop',
|
|
1766
|
-
};
|
|
1767
|
-
const kindMappingReverse = (() => {
|
|
1768
|
-
const result = {};
|
|
1769
|
-
Object.keys(kindMapping).forEach((key) => {
|
|
1770
|
-
const keyNum = typeof key === 'string' ? parseInt(key, 10) : key;
|
|
1771
|
-
result[kindMapping[keyNum]] = pad(keyNum, 2);
|
|
1772
|
-
});
|
|
1773
|
-
return result;
|
|
1774
|
-
})();
|
|
1775
|
-
// See https://tezos.gitlab.io/protocols/005_babylon.html#transactions-now-have-an-entrypoint
|
|
1776
|
-
const entrypointMapping = {
|
|
1777
|
-
'00': 'default',
|
|
1778
|
-
'01': 'root',
|
|
1779
|
-
'02': 'do',
|
|
1780
|
-
'03': 'set_delegate',
|
|
1781
|
-
'04': 'remove_delegate',
|
|
1782
|
-
'05': 'deposit',
|
|
1783
|
-
'06': 'stake',
|
|
1784
|
-
'07': 'unstake',
|
|
1785
|
-
'08': 'finalize_unstake',
|
|
1786
|
-
'09': 'set_delegate_parameters',
|
|
1787
|
-
};
|
|
1788
|
-
const entrypointMappingReverse = (() => {
|
|
1789
|
-
const result = {};
|
|
1790
|
-
Object.keys(entrypointMapping).forEach((key) => {
|
|
1791
|
-
result[entrypointMapping[key]] = key;
|
|
1792
|
-
});
|
|
1793
|
-
return result;
|
|
1794
|
-
})();
|
|
1795
|
-
|
|
1796
|
-
const isPrim = (value) => {
|
|
1797
|
-
return 'prim' in value;
|
|
1798
|
-
};
|
|
1799
|
-
const isBytes = (value) => {
|
|
1800
|
-
return 'bytes' in value && typeof value.bytes === 'string';
|
|
1801
|
-
};
|
|
1802
|
-
const isString = (value) => {
|
|
1803
|
-
return 'string' in value && typeof value.string === 'string';
|
|
1804
|
-
};
|
|
1805
|
-
const isInt = (value) => {
|
|
1806
|
-
return 'int' in value && typeof value.int === 'string';
|
|
1807
|
-
};
|
|
1808
|
-
const scriptEncoder = (script) => {
|
|
1809
|
-
const code = valueEncoder(script.code);
|
|
1810
|
-
const storage = valueEncoder(script.storage);
|
|
1811
|
-
return `${pad(code.length / 2, 8)}${code}${pad(storage.length / 2, 8)}${storage}`;
|
|
1812
|
-
};
|
|
1813
|
-
const scriptDecoder = (value) => {
|
|
1814
|
-
const code = extractRequiredLen(value);
|
|
1815
|
-
const storage = extractRequiredLen(value);
|
|
1816
|
-
return {
|
|
1817
|
-
code: valueDecoder(new Uint8ArrayConsumer(code)),
|
|
1818
|
-
storage: valueDecoder(new Uint8ArrayConsumer(storage)),
|
|
1819
|
-
};
|
|
1820
|
-
};
|
|
1821
|
-
const valueEncoder = (value) => {
|
|
1822
|
-
if (Array.isArray(value)) {
|
|
1823
|
-
const encoded = value.map((x) => valueEncoder(x)).join('');
|
|
1824
|
-
const len = encoded.length / 2;
|
|
1825
|
-
return `02${pad(len)}${encoded}`;
|
|
1826
|
-
}
|
|
1827
|
-
else if (isPrim(value)) {
|
|
1828
|
-
return primEncoder(value);
|
|
1829
|
-
}
|
|
1830
|
-
else if (isBytes(value)) {
|
|
1831
|
-
return bytesEncoder(value);
|
|
1832
|
-
}
|
|
1833
|
-
else if (isString(value)) {
|
|
1834
|
-
return stringEncoder(value);
|
|
1835
|
-
}
|
|
1836
|
-
else if (isInt(value)) {
|
|
1837
|
-
return intEncoder(value);
|
|
1838
|
-
}
|
|
1839
|
-
throw new UnexpectedMichelsonValueError(JSON.stringify(value));
|
|
1840
|
-
};
|
|
1841
|
-
const valueDecoder = (value) => {
|
|
1842
|
-
const preamble = value.consume(1);
|
|
1843
|
-
switch (preamble[0]) {
|
|
1844
|
-
case 0x0a:
|
|
1845
|
-
return bytesDecoder(value);
|
|
1846
|
-
case 0x01:
|
|
1847
|
-
return stringDecoder(value);
|
|
1848
|
-
case 0x00:
|
|
1849
|
-
return intDecoder(value);
|
|
1850
|
-
case 0x02: {
|
|
1851
|
-
const val = new Uint8ArrayConsumer(extractRequiredLen(value));
|
|
1852
|
-
const results = [];
|
|
1853
|
-
while (val.length() > 0) {
|
|
1854
|
-
results.push(valueDecoder(val));
|
|
1855
|
-
}
|
|
1856
|
-
return results;
|
|
1857
|
-
}
|
|
1858
|
-
default:
|
|
1859
|
-
return primDecoder(value, preamble);
|
|
1860
|
-
}
|
|
1861
|
-
};
|
|
1862
|
-
const extractRequiredLen = (value, bytesLength = 4) => {
|
|
1863
|
-
const len = value.consume(bytesLength);
|
|
1864
|
-
const valueLen = parseInt(Buffer.from(len).toString('hex'), 16);
|
|
1865
|
-
return value.consume(valueLen);
|
|
1866
|
-
};
|
|
1867
|
-
/**
|
|
1868
|
-
* @description parse bytes into multiple items of an array
|
|
1869
|
-
* @param value Uint8ArrayConsumer class of forged segment to parse
|
|
1870
|
-
* @param bytesLength default 4 bytes for length of variable bytes
|
|
1871
|
-
* @returns array of Uint8Array values for each array item
|
|
1872
|
-
*/
|
|
1873
|
-
const stripLengthPrefixFromBytes = (value, bytesLength = 4) => {
|
|
1874
|
-
const ret = [];
|
|
1875
|
-
let values = value;
|
|
1876
|
-
while (values.length()) {
|
|
1877
|
-
const len = values.consume(bytesLength);
|
|
1878
|
-
const valueLen = parseInt(Buffer.from(len).toString('hex'), 16);
|
|
1879
|
-
ret.push(values.consume(valueLen));
|
|
1880
|
-
values = values.slice(valueLen + bytesLength);
|
|
1881
|
-
}
|
|
1882
|
-
return ret;
|
|
1883
|
-
};
|
|
1884
|
-
const bytesEncoder = (value) => {
|
|
1885
|
-
if (!/^([A-Fa-f0-9]{2})*$/.test(value.bytes)) {
|
|
1886
|
-
throw new core.InvalidHexStringError(value.bytes);
|
|
1887
|
-
}
|
|
1888
|
-
const len = value.bytes.length / 2;
|
|
1889
|
-
return `0a${pad(len)}${value.bytes}`;
|
|
1890
|
-
};
|
|
1891
|
-
const bytesDecoder = (value) => {
|
|
1892
|
-
const bytes = extractRequiredLen(value);
|
|
1893
|
-
return {
|
|
1894
|
-
bytes: Buffer.from(bytes).toString('hex'),
|
|
1895
|
-
};
|
|
1896
|
-
};
|
|
1897
|
-
const stringEncoder = (value) => {
|
|
1898
|
-
const str = Buffer.from(value.string, 'utf8').toString('hex');
|
|
1899
|
-
const hexLength = str.length / 2;
|
|
1900
|
-
return `01${pad(hexLength)}${str}`;
|
|
1901
|
-
};
|
|
1902
|
-
const stringDecoder = (value) => {
|
|
1903
|
-
const str = extractRequiredLen(value);
|
|
1904
|
-
return {
|
|
1905
|
-
string: Buffer.from(str).toString('utf8'),
|
|
1906
|
-
};
|
|
1907
|
-
};
|
|
1908
|
-
const intEncoder = ({ int }) => {
|
|
1909
|
-
const num = new BigNumber.BigNumber(int, 10);
|
|
1910
|
-
const positiveMark = num.toString(2)[0] === '-' ? '1' : '0';
|
|
1911
|
-
const binary = num.toString(2).replace(/-/g, '');
|
|
1912
|
-
const pad = binary.length <= 6
|
|
1913
|
-
? 6
|
|
1914
|
-
: (binary.length - 6) % 7
|
|
1915
|
-
? binary.length + 7 - ((binary.length - 6) % 7)
|
|
1916
|
-
: binary.length;
|
|
1917
|
-
const splitted = binary.padStart(pad, '0').match(/\d{6,7}/g);
|
|
1918
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
1919
|
-
const reversed = splitted.reverse();
|
|
1920
|
-
reversed[0] = positiveMark + reversed[0];
|
|
1921
|
-
const numHex = reversed.map((x, i) =>
|
|
1922
|
-
// Add one to the last chunk
|
|
1923
|
-
parseInt((i === reversed.length - 1 ? '0' : '1') + x, 2)
|
|
1924
|
-
.toString(16)
|
|
1925
|
-
.padStart(2, '0'));
|
|
1926
|
-
return `00${numHex.join('')}`;
|
|
1927
|
-
};
|
|
1928
|
-
const intDecoder = (value) => {
|
|
1929
|
-
let c = value.consume(1)[0];
|
|
1930
|
-
const hexNumber = [];
|
|
1931
|
-
const isNotLastChunkMask = 1 << 7;
|
|
1932
|
-
while (c & isNotLastChunkMask) {
|
|
1933
|
-
hexNumber.push(c);
|
|
1934
|
-
c = value.consume(1)[0];
|
|
1935
|
-
}
|
|
1936
|
-
hexNumber.push(c);
|
|
1937
|
-
const isNegative = !!((1 << 6) & hexNumber[0]);
|
|
1938
|
-
hexNumber[0] = hexNumber[0] & 0b1111111;
|
|
1939
|
-
const numBin = hexNumber
|
|
1940
|
-
.map((x, i) => x
|
|
1941
|
-
.toString(2)
|
|
1942
|
-
.slice(i === 0 ? -6 : -7)
|
|
1943
|
-
.padStart(i === 0 ? 6 : 7, '0'))
|
|
1944
|
-
.reverse();
|
|
1945
|
-
let num = new BigNumber.BigNumber(numBin.join(''), 2);
|
|
1946
|
-
if (isNegative) {
|
|
1947
|
-
num = num.times(-1);
|
|
1948
|
-
}
|
|
1949
|
-
return {
|
|
1950
|
-
int: num.toFixed(),
|
|
1951
|
-
};
|
|
1952
|
-
};
|
|
1953
|
-
const primEncoder = (value) => {
|
|
1954
|
-
const hasAnnot = +Array.isArray(value.annots);
|
|
1955
|
-
const argsCount = Array.isArray(value.args) ? value.args.length : 0;
|
|
1956
|
-
// Specify the number of args max is 3 without annotation
|
|
1957
|
-
const preamble = pad(Math.min(2 * argsCount + hasAnnot + 0x03, 9), 2);
|
|
1958
|
-
const op = opMappingReverse[value.prim];
|
|
1959
|
-
let encodedArgs = (value.args || []).map((arg) => valueEncoder(arg)).join('');
|
|
1960
|
-
const encodedAnnots = Array.isArray(value.annots) ? encodeAnnots(value.annots) : '';
|
|
1961
|
-
if ((value.prim === 'LAMBDA' || value.prim === 'LAMBDA_REC') && argsCount) {
|
|
1962
|
-
encodedArgs = pad(encodedArgs.length / 2) + encodedArgs + pad(0);
|
|
1963
|
-
}
|
|
1964
|
-
if ((value.prim === 'pair' || value.prim === 'Pair') && argsCount > 2) {
|
|
1965
|
-
encodedArgs =
|
|
1966
|
-
encodedAnnots === ''
|
|
1967
|
-
? pad(encodedArgs.length / 2) + encodedArgs + pad(0)
|
|
1968
|
-
: pad(encodedArgs.length / 2) + encodedArgs;
|
|
1969
|
-
}
|
|
1970
|
-
if (value.prim === 'view' && value.args) {
|
|
1971
|
-
encodedArgs = pad(encodedArgs.length / 2) + encodedArgs + pad(0);
|
|
1972
|
-
}
|
|
1973
|
-
return `${preamble}${op}${encodedArgs}${encodedAnnots}`;
|
|
1974
|
-
};
|
|
1975
|
-
const primDecoder = (value, preamble) => {
|
|
1976
|
-
const hasAnnot = (preamble[0] - 0x03) % 2 === 1;
|
|
1977
|
-
let argsCount = Math.floor((preamble[0] - 0x03) / 2);
|
|
1978
|
-
const op = value.consume(1)[0].toString(16).padStart(2, '0');
|
|
1979
|
-
const result = {
|
|
1980
|
-
prim: opMapping[op],
|
|
1981
|
-
};
|
|
1982
|
-
if (opMapping[op] === 'LAMBDA' || opMapping[op] === 'LAMBDA_REC') {
|
|
1983
|
-
value.consume(4);
|
|
1984
|
-
}
|
|
1985
|
-
if (opMapping[op] === 'view') {
|
|
1986
|
-
if (argsCount != 0) {
|
|
1987
|
-
return primViewDecoder(value, result);
|
|
1988
|
-
}
|
|
1989
|
-
else {
|
|
1990
|
-
return result;
|
|
1991
|
-
}
|
|
1992
|
-
}
|
|
1993
|
-
let combPairArgs;
|
|
1994
|
-
let combPairAnnots;
|
|
1995
|
-
if ((opMapping[op] === 'pair' || opMapping[op] === 'Pair') && argsCount > 2) {
|
|
1996
|
-
combPairArgs = decodeCombPair(value);
|
|
1997
|
-
argsCount = 0;
|
|
1998
|
-
combPairAnnots = decodeAnnots(value);
|
|
1999
|
-
}
|
|
2000
|
-
const args = new Array(argsCount).fill(0).map(() => valueDecoder(value));
|
|
2001
|
-
if (opMapping[op] === 'LAMBDA' || opMapping[op] === 'LAMBDA_REC') {
|
|
2002
|
-
value.consume(4);
|
|
2003
|
-
}
|
|
2004
|
-
if (combPairArgs) {
|
|
2005
|
-
result['args'] = combPairArgs;
|
|
2006
|
-
}
|
|
2007
|
-
else if (args.length) {
|
|
2008
|
-
result['args'] = args;
|
|
2009
|
-
}
|
|
2010
|
-
if (combPairAnnots && combPairAnnots[0] !== '') {
|
|
2011
|
-
result['annots'] = combPairAnnots;
|
|
2012
|
-
}
|
|
2013
|
-
else if (hasAnnot) {
|
|
2014
|
-
result['annots'] = decodeAnnots(value);
|
|
2015
|
-
}
|
|
2016
|
-
return result;
|
|
2017
|
-
};
|
|
2018
|
-
const primViewDecoder = (value, result) => {
|
|
2019
|
-
value.consume(4);
|
|
2020
|
-
result['args'] = new Array(4).fill(0).map(() => valueDecoder(value));
|
|
2021
|
-
value.consume(4);
|
|
2022
|
-
return result;
|
|
2023
|
-
};
|
|
2024
|
-
const decodeCombPair = (val) => {
|
|
2025
|
-
const array = new Uint8ArrayConsumer(extractRequiredLen(val));
|
|
2026
|
-
const args = [];
|
|
2027
|
-
while (array.length() > 0) {
|
|
2028
|
-
args.push(valueDecoder(array));
|
|
2029
|
-
}
|
|
2030
|
-
return args;
|
|
2031
|
-
};
|
|
2032
|
-
const encodeAnnots = (value) => {
|
|
2033
|
-
const mergedAnnot = value
|
|
2034
|
-
.map((x) => {
|
|
2035
|
-
return Buffer.from(x, 'utf8').toString('hex');
|
|
2036
|
-
})
|
|
2037
|
-
.join('20');
|
|
2038
|
-
const len = mergedAnnot.length / 2;
|
|
2039
|
-
return `${pad(len)}${mergedAnnot}`;
|
|
2040
|
-
};
|
|
2041
|
-
const decodeAnnots = (val) => {
|
|
2042
|
-
const len = val.consume(4);
|
|
2043
|
-
const annotLen = parseInt(Buffer.from(len).toString('hex'), 16);
|
|
2044
|
-
const restOfAnnot = val.consume(annotLen);
|
|
2045
|
-
const restOfAnnotHex = Buffer.from(restOfAnnot).toString('hex');
|
|
2046
|
-
return restOfAnnotHex.split('20').map((x) => Buffer.from(x, 'hex').toString('utf8'));
|
|
2047
|
-
};
|
|
2048
|
-
|
|
2049
|
-
// https://tezos.gitlab.io/shell/p2p_api.html specifies data types and structure for forging
|
|
2050
|
-
const prefixEncoder = (prefix) => (str) => {
|
|
2051
|
-
return utils.buf2hex(Buffer.from(utils.b58cdecode(str, utils.prefix[prefix])));
|
|
2052
|
-
};
|
|
2053
|
-
const prefixDecoder = (pre) => (str) => {
|
|
2054
|
-
const val = str.consume(utils.prefixLength[pre]);
|
|
2055
|
-
return utils.b58cencode(val, utils.prefix[pre]);
|
|
2056
|
-
};
|
|
2057
|
-
const tz1Decoder = prefixDecoder(utils.Prefix.TZ1);
|
|
2058
|
-
const branchDecoder = prefixDecoder(utils.Prefix.B);
|
|
2059
|
-
const publicKeyHashDecoder = (val) => {
|
|
2060
|
-
const prefix = val.consume(1);
|
|
2061
|
-
if (prefix[0] === 0x00) {
|
|
2062
|
-
return prefixDecoder(utils.Prefix.TZ1)(val);
|
|
2063
|
-
}
|
|
2064
|
-
else if (prefix[0] === 0x01) {
|
|
2065
|
-
return prefixDecoder(utils.Prefix.TZ2)(val);
|
|
2066
|
-
}
|
|
2067
|
-
else if (prefix[0] === 0x02) {
|
|
2068
|
-
return prefixDecoder(utils.Prefix.TZ3)(val);
|
|
2069
|
-
}
|
|
2070
|
-
else if (prefix[0] === 0x03) {
|
|
2071
|
-
return prefixDecoder(utils.Prefix.TZ4)(val);
|
|
2072
|
-
}
|
|
2073
|
-
};
|
|
2074
|
-
const publicKeyHashesDecoder = (val) => {
|
|
2075
|
-
if (!boolDecoder(val)) {
|
|
2076
|
-
return;
|
|
2077
|
-
}
|
|
2078
|
-
const publicKeyHashes = [];
|
|
2079
|
-
val.consume(4);
|
|
2080
|
-
while (val.length() > 0) {
|
|
2081
|
-
publicKeyHashes.push(publicKeyHashDecoder(val));
|
|
2082
|
-
}
|
|
2083
|
-
return publicKeyHashes;
|
|
2084
|
-
};
|
|
2085
|
-
const branchEncoder = prefixEncoder(utils.Prefix.B);
|
|
2086
|
-
const tz1Encoder = prefixEncoder(utils.Prefix.TZ1);
|
|
2087
|
-
const boolEncoder = (bool) => (bool ? 'ff' : '00');
|
|
2088
|
-
const proposalEncoder = (proposal) => {
|
|
2089
|
-
return prefixEncoder(utils.Prefix.P)(proposal);
|
|
2090
|
-
};
|
|
2091
|
-
const proposalDecoder = (proposal) => {
|
|
2092
|
-
return prefixDecoder(utils.Prefix.P)(proposal);
|
|
2093
|
-
};
|
|
2094
|
-
const proposalsDecoder = (proposal) => {
|
|
2095
|
-
const proposals = [];
|
|
2096
|
-
proposal.consume(4);
|
|
2097
|
-
while (proposal.length() > 0) {
|
|
2098
|
-
proposals.push(proposalDecoder(proposal));
|
|
2099
|
-
}
|
|
2100
|
-
return proposals;
|
|
2101
|
-
};
|
|
2102
|
-
const proposalsEncoder = (proposals) => {
|
|
2103
|
-
return pad(32 * proposals.length) + proposals.map((x) => proposalEncoder(x)).join('');
|
|
2104
|
-
};
|
|
2105
|
-
const ballotEncoder = (ballot) => {
|
|
2106
|
-
switch (ballot) {
|
|
2107
|
-
case 'yay':
|
|
2108
|
-
return '00';
|
|
2109
|
-
case 'nay':
|
|
2110
|
-
return '01';
|
|
2111
|
-
case 'pass':
|
|
2112
|
-
return '02';
|
|
2113
|
-
default:
|
|
2114
|
-
throw new InvalidBallotValueError(ballot);
|
|
2115
|
-
}
|
|
2116
|
-
};
|
|
2117
|
-
const ballotDecoder = (ballot) => {
|
|
2118
|
-
const value = ballot.consume(1);
|
|
2119
|
-
switch (value[0]) {
|
|
2120
|
-
case 0x00:
|
|
2121
|
-
return 'yay';
|
|
2122
|
-
case 0x01:
|
|
2123
|
-
return 'nay';
|
|
2124
|
-
case 0x02:
|
|
2125
|
-
return 'pass';
|
|
2126
|
-
default:
|
|
2127
|
-
throw new DecodeBallotValueError(value[0].toString());
|
|
2128
|
-
}
|
|
2129
|
-
};
|
|
2130
|
-
const pvmKindEncoder = (pvm) => {
|
|
2131
|
-
switch (pvm) {
|
|
2132
|
-
case 'arith':
|
|
2133
|
-
return '00';
|
|
2134
|
-
case 'wasm_2_0_0':
|
|
2135
|
-
return '01';
|
|
2136
|
-
case 'riscv':
|
|
2137
|
-
return '02';
|
|
2138
|
-
default:
|
|
2139
|
-
throw new UnsupportedPvmKindError(pvm);
|
|
2140
|
-
}
|
|
2141
|
-
};
|
|
2142
|
-
const pvmKindDecoder = (pvm) => {
|
|
2143
|
-
const value = pvm.consume(1);
|
|
2144
|
-
switch (value[0]) {
|
|
2145
|
-
case 0x00:
|
|
2146
|
-
return 'arith';
|
|
2147
|
-
case 0x01:
|
|
2148
|
-
return 'wasm_2_0_0';
|
|
2149
|
-
case 0x02:
|
|
2150
|
-
return 'riscv';
|
|
2151
|
-
default:
|
|
2152
|
-
throw new DecodePvmKindError(value[0].toString());
|
|
2153
|
-
}
|
|
2154
|
-
};
|
|
2155
|
-
const delegateEncoder = (val) => {
|
|
2156
|
-
if (val) {
|
|
2157
|
-
return boolEncoder(true) + publicKeyHashEncoder(val);
|
|
2158
|
-
}
|
|
2159
|
-
else {
|
|
2160
|
-
return boolEncoder(false);
|
|
2161
|
-
}
|
|
2162
|
-
};
|
|
2163
|
-
const int32Encoder = (val) => {
|
|
2164
|
-
const num = parseInt(String(val), 10);
|
|
2165
|
-
const byte = [];
|
|
2166
|
-
for (let i = 0; i < 4; i++) {
|
|
2167
|
-
const shiftBy = (4 - (i + 1)) * 8;
|
|
2168
|
-
byte.push((num & (0xff << shiftBy)) >> shiftBy);
|
|
2169
|
-
}
|
|
2170
|
-
return Buffer.from(byte).toString('hex');
|
|
2171
|
-
};
|
|
2172
|
-
const int32Decoder = (val) => {
|
|
2173
|
-
const num = val.consume(4);
|
|
2174
|
-
let finalNum = 0;
|
|
2175
|
-
for (let i = 0; i < num.length; i++) {
|
|
2176
|
-
finalNum = finalNum | (num[i] << ((num.length - (i + 1)) * 8));
|
|
2177
|
-
}
|
|
2178
|
-
return finalNum;
|
|
2179
|
-
};
|
|
2180
|
-
const int16Encoder = (val) => {
|
|
2181
|
-
const num = parseInt(String(val), 10);
|
|
2182
|
-
const byte = [];
|
|
2183
|
-
for (let i = 0; i < 2; i++) {
|
|
2184
|
-
const shiftBy = (2 - (i + 1)) * 8;
|
|
2185
|
-
byte.push((num & (0xff << shiftBy)) >> shiftBy);
|
|
2186
|
-
}
|
|
2187
|
-
return Buffer.from(byte).toString('hex');
|
|
2188
|
-
};
|
|
2189
|
-
const int16Decoder = (val) => {
|
|
2190
|
-
const num = val.consume(2);
|
|
2191
|
-
let finalNum = 0;
|
|
2192
|
-
for (let i = 0; i < num.length; i++) {
|
|
2193
|
-
finalNum = finalNum | (num[i] << ((num.length - (i + 1)) * 8));
|
|
2194
|
-
}
|
|
2195
|
-
return finalNum;
|
|
2196
|
-
};
|
|
2197
|
-
const boolDecoder = (val) => {
|
|
2198
|
-
const bool = val.consume(1);
|
|
2199
|
-
return bool[0] === 0xff;
|
|
2200
|
-
};
|
|
2201
|
-
const delegateDecoder = (val) => {
|
|
2202
|
-
const hasDelegate = boolDecoder(val);
|
|
2203
|
-
if (hasDelegate) {
|
|
2204
|
-
return publicKeyHashDecoder(val);
|
|
2205
|
-
}
|
|
2206
|
-
};
|
|
2207
|
-
const publicKeyHashEncoder = (val) => {
|
|
2208
|
-
const pubkeyPrefix = val.substring(0, 3);
|
|
2209
|
-
switch (pubkeyPrefix) {
|
|
2210
|
-
case utils.Prefix.TZ1:
|
|
2211
|
-
return '00' + prefixEncoder(utils.Prefix.TZ1)(val);
|
|
2212
|
-
case utils.Prefix.TZ2:
|
|
2213
|
-
return '01' + prefixEncoder(utils.Prefix.TZ2)(val);
|
|
2214
|
-
case utils.Prefix.TZ3:
|
|
2215
|
-
return '02' + prefixEncoder(utils.Prefix.TZ3)(val);
|
|
2216
|
-
case utils.Prefix.TZ4:
|
|
2217
|
-
return '03' + prefixEncoder(utils.Prefix.TZ4)(val);
|
|
2218
|
-
default:
|
|
2219
|
-
throw new utils.InvalidKeyHashError(val, utils.invalidDetail(utils.ValidationResult.NO_PREFIX_MATCHED) +
|
|
2220
|
-
` expecting one for the following "${utils.Prefix.TZ1}", "${utils.Prefix.TZ2}", "${utils.Prefix.TZ3}" or "${utils.Prefix.TZ4}".`);
|
|
2221
|
-
}
|
|
2222
|
-
};
|
|
2223
|
-
const publicKeyHashesEncoder = (val) => {
|
|
2224
|
-
if (!val) {
|
|
2225
|
-
return boolEncoder(false);
|
|
2226
|
-
}
|
|
2227
|
-
if (val.length === 0) {
|
|
2228
|
-
return boolEncoder(true) + pad(0);
|
|
2229
|
-
}
|
|
2230
|
-
const publicKeyHashes = val.reduce((prev, curr) => {
|
|
2231
|
-
return prev + publicKeyHashEncoder(curr);
|
|
2232
|
-
}, '');
|
|
2233
|
-
return boolEncoder(true) + pad(publicKeyHashes.length / 2) + publicKeyHashes;
|
|
2234
|
-
};
|
|
2235
|
-
const publicKeyEncoder = (val) => {
|
|
2236
|
-
const pubkeyPrefix = val.substring(0, 4);
|
|
2237
|
-
switch (pubkeyPrefix) {
|
|
2238
|
-
case utils.Prefix.EDPK:
|
|
2239
|
-
return '00' + prefixEncoder(utils.Prefix.EDPK)(val);
|
|
2240
|
-
case utils.Prefix.SPPK:
|
|
2241
|
-
return '01' + prefixEncoder(utils.Prefix.SPPK)(val);
|
|
2242
|
-
case utils.Prefix.P2PK:
|
|
2243
|
-
return '02' + prefixEncoder(utils.Prefix.P2PK)(val);
|
|
2244
|
-
case utils.Prefix.BLPK:
|
|
2245
|
-
return '03' + prefixEncoder(utils.Prefix.BLPK)(val);
|
|
2246
|
-
default:
|
|
2247
|
-
throw new utils.InvalidPublicKeyError(val, utils.invalidDetail(utils.ValidationResult.NO_PREFIX_MATCHED) +
|
|
2248
|
-
` expecting one of the following '${utils.Prefix.EDPK}', '${utils.Prefix.SPPK}', '${utils.Prefix.P2PK}' or '${utils.Prefix.BLPK}'.`);
|
|
2249
|
-
}
|
|
2250
|
-
};
|
|
2251
|
-
const addressEncoder = (val) => {
|
|
2252
|
-
const pubkeyPrefix = val.substring(0, 3);
|
|
2253
|
-
switch (pubkeyPrefix) {
|
|
2254
|
-
case utils.Prefix.TZ1:
|
|
2255
|
-
case utils.Prefix.TZ2:
|
|
2256
|
-
case utils.Prefix.TZ3:
|
|
2257
|
-
case utils.Prefix.TZ4:
|
|
2258
|
-
return '00' + publicKeyHashEncoder(val);
|
|
2259
|
-
case utils.Prefix.KT1:
|
|
2260
|
-
return '01' + prefixEncoder(utils.Prefix.KT1)(val) + '00';
|
|
2261
|
-
default:
|
|
2262
|
-
throw new core.InvalidAddressError(val, utils.invalidDetail(utils.ValidationResult.NO_PREFIX_MATCHED) +
|
|
2263
|
-
` expecting one of the following prefix '${utils.Prefix.TZ1}', ${utils.Prefix.TZ2}', '${utils.Prefix.TZ3}', '${utils.Prefix.TZ4}' or '${utils.Prefix.KT1}'.`);
|
|
2264
|
-
}
|
|
2265
|
-
};
|
|
2266
|
-
const smartRollupAddressEncoder = (val) => {
|
|
2267
|
-
if (val.substring(0, 3) !== utils.Prefix.SR1) {
|
|
2268
|
-
throw new InvalidSmartRollupAddressError(val, utils.invalidDetail(utils.ValidationResult.NO_PREFIX_MATCHED) + ` expecting prefix '${utils.Prefix.SR1}'.`);
|
|
2269
|
-
}
|
|
2270
|
-
return prefixEncoder(utils.Prefix.SR1)(val);
|
|
2271
|
-
};
|
|
2272
|
-
const smartContractAddressEncoder = (val) => {
|
|
2273
|
-
const prefix = val.substring(0, 3);
|
|
2274
|
-
if (prefix === utils.Prefix.KT1) {
|
|
2275
|
-
return '01' + prefixEncoder(utils.Prefix.KT1)(val) + '00';
|
|
2276
|
-
}
|
|
2277
|
-
throw new core.InvalidContractAddressError(val, utils.invalidDetail(utils.ValidationResult.NO_PREFIX_MATCHED) + ` expecting prefix '${utils.Prefix.KT1}'.`);
|
|
2278
|
-
};
|
|
2279
|
-
const publicKeyDecoder = (val) => {
|
|
2280
|
-
const preamble = val.consume(1);
|
|
2281
|
-
switch (preamble[0]) {
|
|
2282
|
-
case 0x00:
|
|
2283
|
-
return prefixDecoder(utils.Prefix.EDPK)(val);
|
|
2284
|
-
case 0x01:
|
|
2285
|
-
return prefixDecoder(utils.Prefix.SPPK)(val);
|
|
2286
|
-
case 0x02:
|
|
2287
|
-
return prefixDecoder(utils.Prefix.P2PK)(val);
|
|
2288
|
-
case 0x03:
|
|
2289
|
-
return prefixDecoder(utils.Prefix.BLPK)(val);
|
|
2290
|
-
default:
|
|
2291
|
-
throw new utils.InvalidPublicKeyError(val.toString(), utils.invalidDetail(utils.ValidationResult.NO_PREFIX_MATCHED));
|
|
2292
|
-
}
|
|
2293
|
-
};
|
|
2294
|
-
const smartRollupCommitmentHashEncoder = (val) => {
|
|
2295
|
-
const prefix = val.substring(0, 4);
|
|
2296
|
-
if (prefix === utils.Prefix.SRC1) {
|
|
2297
|
-
return prefixEncoder(utils.Prefix.SRC1)(val);
|
|
2298
|
-
}
|
|
2299
|
-
throw new InvalidSmartRollupCommitmentHashError(val, utils.invalidDetail(utils.ValidationResult.NO_PREFIX_MATCHED) + ` expecting prefix '${utils.Prefix.SRC1}'`);
|
|
2300
|
-
};
|
|
2301
|
-
const addressDecoder = (val) => {
|
|
2302
|
-
const preamble = val.consume(1);
|
|
2303
|
-
switch (preamble[0]) {
|
|
2304
|
-
case 0x00:
|
|
2305
|
-
return publicKeyHashDecoder(val);
|
|
2306
|
-
case 0x01: {
|
|
2307
|
-
const address = prefixDecoder(utils.Prefix.KT1)(val);
|
|
2308
|
-
val.consume(1);
|
|
2309
|
-
return address;
|
|
2310
|
-
}
|
|
2311
|
-
default:
|
|
2312
|
-
throw new core.InvalidAddressError(val.toString(), ': Unable to decode.');
|
|
2313
|
-
}
|
|
2314
|
-
};
|
|
2315
|
-
const smartRollupAddressDecoder = (val) => {
|
|
2316
|
-
const address = prefixDecoder(utils.Prefix.SR1)(val);
|
|
2317
|
-
if (address.substring(0, 3) !== utils.Prefix.SR1) {
|
|
2318
|
-
throw new InvalidSmartRollupAddressError(address, utils.invalidDetail(utils.ValidationResult.NO_PREFIX_MATCHED) + ` expecting prefix '${utils.Prefix.SR1}'.`);
|
|
2319
|
-
}
|
|
2320
|
-
return address;
|
|
2321
|
-
};
|
|
2322
|
-
const smartContractAddressDecoder = (val) => {
|
|
2323
|
-
const preamble = val.consume(1);
|
|
2324
|
-
if (preamble[0] === 0x01) {
|
|
2325
|
-
const scAddress = prefixDecoder(utils.Prefix.KT1)(val);
|
|
2326
|
-
val.consume(1);
|
|
2327
|
-
return scAddress;
|
|
2328
|
-
}
|
|
2329
|
-
throw new core.InvalidContractAddressError(val.toString(), utils.invalidDetail(utils.ValidationResult.NO_PREFIX_MATCHED));
|
|
2330
|
-
};
|
|
2331
|
-
const smartRollupCommitmentHashDecoder = (val) => {
|
|
2332
|
-
const address = prefixDecoder(utils.Prefix.SRC1)(val);
|
|
2333
|
-
if (address.substring(0, 4) !== utils.Prefix.SRC1) {
|
|
2334
|
-
throw new InvalidSmartRollupCommitmentHashError(address, utils.invalidDetail(utils.ValidationResult.NO_PREFIX_MATCHED) + ` expecting prefix '${utils.Prefix.SRC1}'`);
|
|
2335
|
-
}
|
|
2336
|
-
return address;
|
|
2337
|
-
};
|
|
2338
|
-
const zarithEncoder = (n) => {
|
|
2339
|
-
const fn = [];
|
|
2340
|
-
let nn = new BigNumber(n, 10);
|
|
2341
|
-
if (nn.isNaN()) {
|
|
2342
|
-
throw new TypeError(`Invalid zarith number ${n}`);
|
|
2343
|
-
}
|
|
2344
|
-
// eslint-disable-next-line no-constant-condition
|
|
2345
|
-
while (true) {
|
|
2346
|
-
if (nn.lt(128)) {
|
|
2347
|
-
if (nn.lt(16))
|
|
2348
|
-
fn.push('0');
|
|
2349
|
-
fn.push(nn.toString(16));
|
|
2350
|
-
break;
|
|
2351
|
-
}
|
|
2352
|
-
else {
|
|
2353
|
-
let b = nn.mod(128);
|
|
2354
|
-
nn = nn.minus(b);
|
|
2355
|
-
nn = nn.dividedBy(128);
|
|
2356
|
-
b = b.plus(128);
|
|
2357
|
-
fn.push(b.toString(16));
|
|
2358
|
-
}
|
|
2359
|
-
}
|
|
2360
|
-
return fn.join('');
|
|
2361
|
-
};
|
|
2362
|
-
const zarithDecoder = (n) => {
|
|
2363
|
-
let mostSignificantByte = 0;
|
|
2364
|
-
while (mostSignificantByte < n.length() && (n.get(mostSignificantByte) & 128) !== 0) {
|
|
2365
|
-
mostSignificantByte += 1;
|
|
2366
|
-
}
|
|
2367
|
-
let num = new BigNumber(0);
|
|
2368
|
-
for (let i = mostSignificantByte; i >= 0; i -= 1) {
|
|
2369
|
-
const tmp = n.get(i) & 0x7f;
|
|
2370
|
-
num = num.multipliedBy(128);
|
|
2371
|
-
num = num.plus(tmp);
|
|
2372
|
-
}
|
|
2373
|
-
n.consume(mostSignificantByte + 1);
|
|
2374
|
-
return new BigNumber(num).toString();
|
|
2375
|
-
};
|
|
2376
|
-
const entrypointDecoder = (value) => {
|
|
2377
|
-
const preamble = pad(value.consume(1)[0], 2);
|
|
2378
|
-
if (preamble in entrypointMapping) {
|
|
2379
|
-
return entrypointMapping[preamble];
|
|
2380
|
-
}
|
|
2381
|
-
else {
|
|
2382
|
-
const entry = extractRequiredLen(value, 1);
|
|
2383
|
-
const entrypoint = Buffer.from(entry).toString('utf8');
|
|
2384
|
-
if (entrypoint.length > ENTRYPOINT_MAX_LENGTH) {
|
|
2385
|
-
throw new OversizedEntryPointError(entrypoint);
|
|
2386
|
-
}
|
|
2387
|
-
return entrypoint;
|
|
2388
|
-
}
|
|
2389
|
-
};
|
|
2390
|
-
const parametersDecoder = (val) => {
|
|
2391
|
-
const preamble = val.consume(1);
|
|
2392
|
-
if (preamble[0] === 0x00) {
|
|
2393
|
-
return;
|
|
2394
|
-
}
|
|
2395
|
-
else {
|
|
2396
|
-
const encodedEntrypoint = entrypointDecoder(val);
|
|
2397
|
-
const params = extractRequiredLen(val);
|
|
2398
|
-
const parameters = valueDecoder(new Uint8ArrayConsumer(params));
|
|
2399
|
-
return {
|
|
2400
|
-
entrypoint: encodedEntrypoint,
|
|
2401
|
-
value: parameters,
|
|
2402
|
-
};
|
|
2403
|
-
}
|
|
2404
|
-
};
|
|
2405
|
-
const entrypointEncoder = (entrypoint) => {
|
|
2406
|
-
if (entrypoint in entrypointMappingReverse) {
|
|
2407
|
-
return `${entrypointMappingReverse[entrypoint]}`;
|
|
2408
|
-
}
|
|
2409
|
-
else {
|
|
2410
|
-
if (entrypoint.length > ENTRYPOINT_MAX_LENGTH) {
|
|
2411
|
-
throw new OversizedEntryPointError(entrypoint);
|
|
2412
|
-
}
|
|
2413
|
-
const value = { string: entrypoint };
|
|
2414
|
-
return `ff${valueEncoder(value).slice(8)}`;
|
|
2415
|
-
}
|
|
2416
|
-
};
|
|
2417
|
-
const parametersEncoder = (val) => {
|
|
2418
|
-
if (!val || (val.entrypoint === 'default' && 'prim' in val.value && val.value.prim === 'Unit')) {
|
|
2419
|
-
return '00';
|
|
2420
|
-
}
|
|
2421
|
-
const encodedEntrypoint = entrypointEncoder(val.entrypoint);
|
|
2422
|
-
const parameters = valueEncoder(val.value);
|
|
2423
|
-
const length = pad(parameters.length / 2);
|
|
2424
|
-
return `ff${encodedEntrypoint}${length}${parameters}`;
|
|
2425
|
-
};
|
|
2426
|
-
const valueParameterEncoder = (value) => {
|
|
2427
|
-
const valueEncoded = valueEncoder(value);
|
|
2428
|
-
return `${pad(valueEncoded.length / 2)}${valueEncoded}`;
|
|
2429
|
-
};
|
|
2430
|
-
const valueParameterDecoder = (val) => {
|
|
2431
|
-
const value = extractRequiredLen(val);
|
|
2432
|
-
return valueDecoder(new Uint8ArrayConsumer(value));
|
|
2433
|
-
};
|
|
2434
|
-
const blockPayloadHashEncoder = prefixEncoder(utils.Prefix.VH);
|
|
2435
|
-
const blockPayloadHashDecoder = prefixDecoder(utils.Prefix.VH);
|
|
2436
|
-
const entrypointNameEncoder = (entrypoint) => {
|
|
2437
|
-
const value = { string: entrypoint };
|
|
2438
|
-
return `${valueEncoder(value).slice(2)}`;
|
|
2439
|
-
};
|
|
2440
|
-
const entrypointNameDecoder = (val) => {
|
|
2441
|
-
const entry = extractRequiredLen(val);
|
|
2442
|
-
return Buffer.from(entry).toString('utf8');
|
|
2443
|
-
};
|
|
2444
|
-
const burnLimitEncoder = (val) => {
|
|
2445
|
-
return !val ? '00' : `ff${zarithEncoder(val)}`;
|
|
2446
|
-
};
|
|
2447
|
-
const burnLimitDecoder = (value) => {
|
|
2448
|
-
const prefix = value.consume(1);
|
|
2449
|
-
if (Buffer.from(prefix).toString('hex') !== '00') {
|
|
2450
|
-
return zarithDecoder(value);
|
|
2451
|
-
}
|
|
2452
|
-
};
|
|
2453
|
-
const depositsLimitEncoder = (val) => {
|
|
2454
|
-
return !val ? '00' : `ff${zarithEncoder(val)}`;
|
|
2455
|
-
};
|
|
2456
|
-
const depositsLimitDecoder = (value) => {
|
|
2457
|
-
const prefix = value.consume(1);
|
|
2458
|
-
if (Buffer.from(prefix).toString('hex') !== '00') {
|
|
2459
|
-
return zarithDecoder(value);
|
|
2460
|
-
}
|
|
2461
|
-
};
|
|
2462
|
-
const signatureV1Encoder = (val) => {
|
|
2463
|
-
const signaturePrefix = val.substring(0, 5);
|
|
2464
|
-
switch (signaturePrefix) {
|
|
2465
|
-
case utils.Prefix.EDSIG:
|
|
2466
|
-
return paddedBytesEncoder(prefixEncoder(utils.Prefix.EDSIG)(val));
|
|
2467
|
-
case utils.Prefix.SPSIG:
|
|
2468
|
-
return paddedBytesEncoder(prefixEncoder(utils.Prefix.SPSIG)(val));
|
|
2469
|
-
case utils.Prefix.P2SIG:
|
|
2470
|
-
return paddedBytesEncoder(prefixEncoder(utils.Prefix.P2SIG)(val));
|
|
2471
|
-
case utils.Prefix.BLSIG:
|
|
2472
|
-
return paddedBytesEncoder(prefixEncoder(utils.Prefix.BLSIG)(val));
|
|
2473
|
-
default:
|
|
2474
|
-
throw new core.InvalidSignatureError(val, utils.invalidDetail(utils.ValidationResult.NO_PREFIX_MATCHED) +
|
|
2475
|
-
` expecting one of the following '${utils.Prefix.EDSIG}', '${utils.Prefix.SPSIG}', '${utils.Prefix.P2SIG}' or '${utils.Prefix.BLSIG}'.`);
|
|
2476
|
-
}
|
|
2477
|
-
};
|
|
2478
|
-
const signatureV1Decoder = (val) => {
|
|
2479
|
-
val.consume(4);
|
|
2480
|
-
if (val.length().toString() === '96') {
|
|
2481
|
-
return prefixDecoder(utils.Prefix.BLSIG)(val);
|
|
2482
|
-
}
|
|
2483
|
-
else {
|
|
2484
|
-
throw new core.ProhibitedActionError('currently we only support decoding of BLSIG signatures');
|
|
2485
|
-
}
|
|
2486
|
-
};
|
|
2487
|
-
const signatureProofEncoder = (val) => {
|
|
2488
|
-
if (val) {
|
|
2489
|
-
return boolEncoder(true) + signatureV1Encoder(val);
|
|
2490
|
-
}
|
|
2491
|
-
else {
|
|
2492
|
-
return boolEncoder(false);
|
|
2493
|
-
}
|
|
2494
|
-
};
|
|
2495
|
-
const signatureProofDecoder = (value) => {
|
|
2496
|
-
const hasProof = boolDecoder(value);
|
|
2497
|
-
if (hasProof) {
|
|
2498
|
-
return signatureV1Decoder(value);
|
|
2499
|
-
}
|
|
2500
|
-
};
|
|
2501
|
-
const paddedBytesEncoder = (val, paddingLength = 8) => {
|
|
2502
|
-
return `${pad(val.length / 2, paddingLength)}${val}`;
|
|
2503
|
-
};
|
|
2504
|
-
const paddedBytesDecoder = (val) => {
|
|
2505
|
-
const value = extractRequiredLen(val);
|
|
2506
|
-
return Buffer.from(value).toString('hex');
|
|
2507
|
-
};
|
|
2508
|
-
const smartRollupMessageEncoder = (val) => {
|
|
2509
|
-
const message = val.reduce((prev, curr) => {
|
|
2510
|
-
return prev + `${pad(curr.length / 2)}${curr}`;
|
|
2511
|
-
}, '');
|
|
2512
|
-
return `${pad(message.length / 2)}${message}`;
|
|
2513
|
-
};
|
|
2514
|
-
const smartRollupMessageDecoder = (val) => {
|
|
2515
|
-
const valueArray = extractRequiredLen(val);
|
|
2516
|
-
const ret = stripLengthPrefixFromBytes(new Uint8ArrayConsumer(valueArray));
|
|
2517
|
-
return ret.map((value) => Buffer.from(value).toString('hex'));
|
|
2518
|
-
};
|
|
2519
|
-
const dalCommitmentEncoder = (val) => {
|
|
2520
|
-
const prefix = val.substring(0, 2);
|
|
2521
|
-
if (prefix === utils.Prefix.SH) {
|
|
2522
|
-
return prefixEncoder(utils.Prefix.SH)(val);
|
|
2523
|
-
}
|
|
2524
|
-
throw new InvalidDalCommitmentError(val, utils.invalidDetail(utils.ValidationResult.NO_PREFIX_MATCHED) + ` expecting prefix '${utils.Prefix.SH}'`);
|
|
2525
|
-
};
|
|
2526
|
-
const dalCommitmentDecoder = (val) => {
|
|
2527
|
-
const commitment = prefixDecoder(utils.Prefix.SH)(val);
|
|
2528
|
-
if (commitment.substring(0, 2) !== utils.Prefix.SH) {
|
|
2529
|
-
throw new InvalidDalCommitmentError(commitment, utils.invalidDetail(utils.ValidationResult.NO_PREFIX_MATCHED) + ` expecting prefix '${utils.Prefix.SH}'`);
|
|
2530
|
-
}
|
|
2531
|
-
return commitment;
|
|
2532
|
-
};
|
|
2533
|
-
const slotHeaderEncoder = (val) => {
|
|
2534
|
-
return pad(val.slot_index, 2) + dalCommitmentEncoder(val.commitment) + val.commitment_proof;
|
|
2535
|
-
};
|
|
2536
|
-
const slotHeaderDecoder = (val) => {
|
|
2537
|
-
const preamble = val.consume(1);
|
|
2538
|
-
return {
|
|
2539
|
-
slot_index: Number(preamble[0].toString(10)),
|
|
2540
|
-
commitment: dalCommitmentDecoder(val),
|
|
2541
|
-
commitment_proof: toHexString(val.consume(96)), // rpcForger expect commitment_proof bytes to be len 96
|
|
2542
|
-
};
|
|
2543
|
-
};
|
|
2544
|
-
|
|
2545
|
-
const ManagerOperationSchema = {
|
|
2546
|
-
branch: CODEC.BRANCH,
|
|
2547
|
-
contents: [CODEC.OPERATION],
|
|
2548
|
-
};
|
|
2549
|
-
const ActivationSchema = {
|
|
2550
|
-
pkh: CODEC.TZ1,
|
|
2551
|
-
secret: CODEC.SECRET,
|
|
2552
|
-
};
|
|
2553
|
-
const RevealSchema = {
|
|
2554
|
-
source: CODEC.PKH,
|
|
2555
|
-
fee: CODEC.ZARITH,
|
|
2556
|
-
counter: CODEC.ZARITH,
|
|
2557
|
-
gas_limit: CODEC.ZARITH,
|
|
2558
|
-
storage_limit: CODEC.ZARITH,
|
|
2559
|
-
public_key: CODEC.PUBLIC_KEY,
|
|
2560
|
-
};
|
|
2561
|
-
const DelegationSchema = {
|
|
2562
|
-
source: CODEC.PKH,
|
|
2563
|
-
fee: CODEC.ZARITH,
|
|
2564
|
-
counter: CODEC.ZARITH,
|
|
2565
|
-
gas_limit: CODEC.ZARITH,
|
|
2566
|
-
storage_limit: CODEC.ZARITH,
|
|
2567
|
-
delegate: CODEC.DELEGATE,
|
|
2568
|
-
};
|
|
2569
|
-
const TransactionSchema = {
|
|
2570
|
-
source: CODEC.PKH,
|
|
2571
|
-
fee: CODEC.ZARITH,
|
|
2572
|
-
counter: CODEC.ZARITH,
|
|
2573
|
-
gas_limit: CODEC.ZARITH,
|
|
2574
|
-
storage_limit: CODEC.ZARITH,
|
|
2575
|
-
amount: CODEC.ZARITH,
|
|
2576
|
-
destination: CODEC.ADDRESS,
|
|
2577
|
-
parameters: CODEC.PARAMETERS,
|
|
2578
|
-
};
|
|
2579
|
-
const OriginationSchema = {
|
|
2580
|
-
source: CODEC.PKH,
|
|
2581
|
-
fee: CODEC.ZARITH,
|
|
2582
|
-
counter: CODEC.ZARITH,
|
|
2583
|
-
gas_limit: CODEC.ZARITH,
|
|
2584
|
-
storage_limit: CODEC.ZARITH,
|
|
2585
|
-
balance: CODEC.ZARITH,
|
|
2586
|
-
delegate: CODEC.DELEGATE,
|
|
2587
|
-
script: CODEC.SCRIPT,
|
|
2588
|
-
};
|
|
2589
|
-
const BallotSchema = {
|
|
2590
|
-
source: CODEC.PKH,
|
|
2591
|
-
period: CODEC.INT32,
|
|
2592
|
-
proposal: CODEC.PROPOSAL,
|
|
2593
|
-
ballot: CODEC.BALLOT_STATEMENT,
|
|
2594
|
-
};
|
|
2595
|
-
const AttestationSchema = {
|
|
2596
|
-
slot: CODEC.INT16,
|
|
2597
|
-
level: CODEC.INT32,
|
|
2598
|
-
round: CODEC.INT32,
|
|
2599
|
-
block_payload_hash: CODEC.BLOCK_PAYLOAD_HASH,
|
|
2600
|
-
};
|
|
2601
|
-
const AttestationWithDalSchema = {
|
|
2602
|
-
slot: CODEC.INT16,
|
|
2603
|
-
level: CODEC.INT32,
|
|
2604
|
-
round: CODEC.INT32,
|
|
2605
|
-
block_payload_hash: CODEC.BLOCK_PAYLOAD_HASH,
|
|
2606
|
-
dal_attestation: CODEC.ZARITH,
|
|
2607
|
-
};
|
|
2608
|
-
const SeedNonceRevelationSchema = {
|
|
2609
|
-
level: CODEC.INT32,
|
|
2610
|
-
nonce: CODEC.RAW,
|
|
2611
|
-
};
|
|
2612
|
-
const ProposalsSchema = {
|
|
2613
|
-
source: CODEC.PKH,
|
|
2614
|
-
period: CODEC.INT32,
|
|
2615
|
-
proposals: CODEC.PROPOSAL_ARR,
|
|
2616
|
-
};
|
|
2617
|
-
const RegisterGlobalConstantSchema = {
|
|
2618
|
-
source: CODEC.PKH,
|
|
2619
|
-
fee: CODEC.ZARITH,
|
|
2620
|
-
counter: CODEC.ZARITH,
|
|
2621
|
-
gas_limit: CODEC.ZARITH,
|
|
2622
|
-
storage_limit: CODEC.ZARITH,
|
|
2623
|
-
value: CODEC.VALUE,
|
|
2624
|
-
};
|
|
2625
|
-
const TransferTicketSchema = {
|
|
2626
|
-
source: CODEC.PKH,
|
|
2627
|
-
fee: CODEC.ZARITH,
|
|
2628
|
-
counter: CODEC.ZARITH,
|
|
2629
|
-
gas_limit: CODEC.ZARITH,
|
|
2630
|
-
storage_limit: CODEC.ZARITH,
|
|
2631
|
-
ticket_contents: CODEC.VALUE,
|
|
2632
|
-
ticket_ty: CODEC.VALUE,
|
|
2633
|
-
ticket_ticketer: CODEC.ADDRESS,
|
|
2634
|
-
ticket_amount: CODEC.ZARITH,
|
|
2635
|
-
destination: CODEC.ADDRESS,
|
|
2636
|
-
entrypoint: CODEC.ENTRYPOINT,
|
|
2637
|
-
};
|
|
2638
|
-
const IncreasePaidStorageSchema = {
|
|
2639
|
-
source: CODEC.PKH,
|
|
2640
|
-
fee: CODEC.ZARITH,
|
|
2641
|
-
counter: CODEC.ZARITH,
|
|
2642
|
-
gas_limit: CODEC.ZARITH,
|
|
2643
|
-
storage_limit: CODEC.ZARITH,
|
|
2644
|
-
amount: CODEC.ZARITH,
|
|
2645
|
-
destination: CODEC.SMART_CONTRACT_ADDRESS,
|
|
2646
|
-
};
|
|
2647
|
-
const UpdateConsensusKeySchema = {
|
|
2648
|
-
source: CODEC.PKH,
|
|
2649
|
-
fee: CODEC.ZARITH,
|
|
2650
|
-
counter: CODEC.ZARITH,
|
|
2651
|
-
gas_limit: CODEC.ZARITH,
|
|
2652
|
-
storage_limit: CODEC.ZARITH,
|
|
2653
|
-
pk: CODEC.PUBLIC_KEY,
|
|
2654
|
-
proof: CODEC.SIGNATURE_PROOF,
|
|
2655
|
-
};
|
|
2656
|
-
const DrainDelegateSchema = {
|
|
2657
|
-
consensus_key: CODEC.PKH,
|
|
2658
|
-
delegate: CODEC.PKH,
|
|
2659
|
-
destination: CODEC.PKH,
|
|
2660
|
-
};
|
|
2661
|
-
const SetDepositsLimitSchema = {
|
|
2662
|
-
source: CODEC.PKH,
|
|
2663
|
-
fee: CODEC.ZARITH,
|
|
2664
|
-
counter: CODEC.ZARITH,
|
|
2665
|
-
gas_limit: CODEC.ZARITH,
|
|
2666
|
-
storage_limit: CODEC.ZARITH,
|
|
2667
|
-
limit: CODEC.DEPOSITS_LIMIT,
|
|
2668
|
-
};
|
|
2669
|
-
const SmartRollupOriginateSchema = {
|
|
2670
|
-
source: CODEC.PKH,
|
|
2671
|
-
fee: CODEC.ZARITH,
|
|
2672
|
-
counter: CODEC.ZARITH,
|
|
2673
|
-
gas_limit: CODEC.ZARITH,
|
|
2674
|
-
storage_limit: CODEC.ZARITH,
|
|
2675
|
-
pvm_kind: CODEC.PVM_KIND,
|
|
2676
|
-
kernel: CODEC.PADDED_BYTES,
|
|
2677
|
-
parameters_ty: CODEC.VALUE,
|
|
2678
|
-
whitelist: CODEC.PKH_ARR,
|
|
2679
|
-
};
|
|
2680
|
-
const SmartRollupAddMessagesSchema = {
|
|
2681
|
-
source: CODEC.PKH,
|
|
2682
|
-
fee: CODEC.ZARITH,
|
|
2683
|
-
counter: CODEC.ZARITH,
|
|
2684
|
-
gas_limit: CODEC.ZARITH,
|
|
2685
|
-
storage_limit: CODEC.ZARITH,
|
|
2686
|
-
message: CODEC.SMART_ROLLUP_MESSAGE,
|
|
2687
|
-
};
|
|
2688
|
-
const SmartRollupExecuteOutboxMessageSchema = {
|
|
2689
|
-
source: CODEC.PKH,
|
|
2690
|
-
fee: CODEC.ZARITH,
|
|
2691
|
-
counter: CODEC.ZARITH,
|
|
2692
|
-
gas_limit: CODEC.ZARITH,
|
|
2693
|
-
storage_limit: CODEC.ZARITH,
|
|
2694
|
-
rollup: CODEC.SMART_ROLLUP_ADDRESS,
|
|
2695
|
-
cemented_commitment: CODEC.SMART_ROLLUP_COMMITMENT_HASH,
|
|
2696
|
-
output_proof: CODEC.PADDED_BYTES,
|
|
2697
|
-
};
|
|
2698
|
-
const DalPublishCommitmentSchema = {
|
|
2699
|
-
source: CODEC.PKH,
|
|
2700
|
-
fee: CODEC.ZARITH,
|
|
2701
|
-
counter: CODEC.ZARITH,
|
|
2702
|
-
gas_limit: CODEC.ZARITH,
|
|
2703
|
-
storage_limit: CODEC.ZARITH,
|
|
2704
|
-
slot_header: CODEC.SLOT_HEADER,
|
|
2705
|
-
};
|
|
2706
|
-
const FailingNoopSchema = {
|
|
2707
|
-
arbitrary: CODEC.PADDED_BYTES,
|
|
2708
|
-
};
|
|
2709
|
-
const operationEncoder = (encoders) => (operation) => {
|
|
2710
|
-
if (!(operation.kind in encoders) || !(operation.kind in kindMappingReverse)) {
|
|
2711
|
-
throw new core.InvalidOperationKindError(operation.kind);
|
|
2712
|
-
}
|
|
2713
|
-
return kindMappingReverse[operation.kind] + encoders[operation.kind](operation);
|
|
2714
|
-
};
|
|
2715
|
-
const operationDecoder = (decoders) => (value) => {
|
|
2716
|
-
const op = value.consume(1);
|
|
2717
|
-
const operationName = kindMapping[op[0]];
|
|
2718
|
-
if (operationName === undefined) {
|
|
2719
|
-
throw new UnsupportedOperationError(op[0].toString());
|
|
2720
|
-
}
|
|
2721
|
-
const decodedObj = decoders[operationName](value);
|
|
2722
|
-
if (typeof decodedObj !== 'object') {
|
|
2723
|
-
throw new OperationDecodingError('Invalid operation, cannot be decoded.');
|
|
2724
|
-
}
|
|
2725
|
-
return Object.assign({ kind: operationName }, decodedObj);
|
|
2726
|
-
};
|
|
2727
|
-
const schemaEncoder = (encoders) => (schema) => (value) => {
|
|
2728
|
-
const keys = Object.keys(schema);
|
|
2729
|
-
return keys.reduce((prev, key) => {
|
|
2730
|
-
const valueToEncode = schema[key];
|
|
2731
|
-
if (value && Array.isArray(valueToEncode)) {
|
|
2732
|
-
const encoder = encoders[valueToEncode[0]];
|
|
2733
|
-
const values = value[key];
|
|
2734
|
-
if (!Array.isArray(values)) {
|
|
2735
|
-
throw new OperationEncodingError(`Invalid operation value "${JSON.stringify(values)}" of key "${key}, expected value to be Array.`);
|
|
2736
|
-
}
|
|
2737
|
-
return (prev + values.reduce((prevBytes, current) => prevBytes + encoder(current), ''));
|
|
2738
|
-
}
|
|
2739
|
-
else {
|
|
2740
|
-
const encoder = encoders[valueToEncode];
|
|
2741
|
-
return prev + encoder(value[key]);
|
|
2742
|
-
}
|
|
2743
|
-
}, '');
|
|
2744
|
-
};
|
|
2745
|
-
const schemaDecoder = (decoders) => (schema) => (value) => {
|
|
2746
|
-
const keys = Object.keys(schema);
|
|
2747
|
-
return keys.reduce((prev, key) => {
|
|
2748
|
-
const valueToEncode = schema[key];
|
|
2749
|
-
if (Array.isArray(valueToEncode)) {
|
|
2750
|
-
const decoder = decoders[valueToEncode[0]];
|
|
2751
|
-
const decoded = [];
|
|
2752
|
-
const lastLength = value.length();
|
|
2753
|
-
while (value.length() > 0) {
|
|
2754
|
-
decoded.push(decoder(value));
|
|
2755
|
-
if (lastLength === value.length()) {
|
|
2756
|
-
throw new OperationDecodingError('Unable to decode value');
|
|
2757
|
-
}
|
|
2758
|
-
}
|
|
2759
|
-
return Object.assign(Object.assign({}, prev), { [key]: decoded });
|
|
2760
|
-
}
|
|
2761
|
-
else {
|
|
2762
|
-
const decoder = decoders[valueToEncode];
|
|
2763
|
-
const result = decoder(value);
|
|
2764
|
-
if (typeof result !== 'undefined') {
|
|
2765
|
-
return Object.assign(Object.assign({}, prev), { [key]: result });
|
|
2766
|
-
}
|
|
2767
|
-
else {
|
|
2768
|
-
return Object.assign({}, prev);
|
|
2769
|
-
}
|
|
2770
|
-
}
|
|
2771
|
-
}, {});
|
|
2772
|
-
};
|
|
2773
|
-
|
|
2774
|
-
const decoders = {
|
|
2775
|
-
[CODEC.SECRET]: (val) => toHexString(val.consume(20)),
|
|
2776
|
-
[CODEC.RAW]: (val) => toHexString(val.consume(32)),
|
|
2777
|
-
[CODEC.TZ1]: tz1Decoder,
|
|
2778
|
-
[CODEC.BRANCH]: branchDecoder,
|
|
2779
|
-
[CODEC.ZARITH]: zarithDecoder,
|
|
2780
|
-
[CODEC.PUBLIC_KEY]: publicKeyDecoder,
|
|
2781
|
-
[CODEC.PKH]: publicKeyHashDecoder,
|
|
2782
|
-
[CODEC.PKH_ARR]: publicKeyHashesDecoder,
|
|
2783
|
-
[CODEC.DELEGATE]: delegateDecoder,
|
|
2784
|
-
[CODEC.INT32]: int32Decoder,
|
|
2785
|
-
[CODEC.SCRIPT]: scriptDecoder,
|
|
2786
|
-
[CODEC.BALLOT_STATEMENT]: ballotDecoder,
|
|
2787
|
-
[CODEC.PROPOSAL]: proposalDecoder,
|
|
2788
|
-
[CODEC.PROPOSAL_ARR]: proposalsDecoder,
|
|
2789
|
-
[CODEC.PARAMETERS]: parametersDecoder,
|
|
2790
|
-
[CODEC.ADDRESS]: addressDecoder,
|
|
2791
|
-
[CODEC.SMART_ROLLUP_ADDRESS]: smartRollupAddressDecoder,
|
|
2792
|
-
[CODEC.SMART_CONTRACT_ADDRESS]: smartContractAddressDecoder,
|
|
2793
|
-
[CODEC.SMART_ROLLUP_COMMITMENT_HASH]: smartRollupCommitmentHashDecoder,
|
|
2794
|
-
[CODEC.VALUE]: valueParameterDecoder,
|
|
2795
|
-
[CODEC.INT16]: int16Decoder,
|
|
2796
|
-
[CODEC.BLOCK_PAYLOAD_HASH]: blockPayloadHashDecoder,
|
|
2797
|
-
[CODEC.ENTRYPOINT]: entrypointNameDecoder,
|
|
2798
|
-
[CODEC.BURN_LIMIT]: burnLimitDecoder,
|
|
2799
|
-
[CODEC.DEPOSITS_LIMIT]: depositsLimitDecoder,
|
|
2800
|
-
[CODEC.SIGNATURE_PROOF]: signatureProofDecoder,
|
|
2801
|
-
[CODEC.PVM_KIND]: pvmKindDecoder,
|
|
2802
|
-
[CODEC.PADDED_BYTES]: paddedBytesDecoder,
|
|
2803
|
-
[CODEC.SMART_ROLLUP_MESSAGE]: smartRollupMessageDecoder,
|
|
2804
|
-
[CODEC.SLOT_HEADER]: slotHeaderDecoder,
|
|
2805
|
-
};
|
|
2806
|
-
decoders[CODEC.OPERATION] = operationDecoder(decoders);
|
|
2807
|
-
decoders[CODEC.OP_ACTIVATE_ACCOUNT] = (val) => schemaDecoder(decoders)(ActivationSchema)(val);
|
|
2808
|
-
decoders[CODEC.OP_FAILING_NOOP] = (val) => schemaDecoder(decoders)(FailingNoopSchema)(val);
|
|
2809
|
-
decoders[CODEC.OP_DELEGATION] = (val) => schemaDecoder(decoders)(DelegationSchema)(val);
|
|
2810
|
-
decoders[CODEC.OP_TRANSACTION] = (val) => schemaDecoder(decoders)(TransactionSchema)(val);
|
|
2811
|
-
decoders[CODEC.OP_ORIGINATION] = (val) => schemaDecoder(decoders)(OriginationSchema)(val);
|
|
2812
|
-
decoders[CODEC.OP_BALLOT] = (val) => schemaDecoder(decoders)(BallotSchema)(val);
|
|
2813
|
-
decoders[CODEC.OP_ATTESTATION] = (val) => schemaDecoder(decoders)(AttestationSchema)(val);
|
|
2814
|
-
decoders[CODEC.OP_ATTESTATION_WITH_DAL] = (val) => schemaDecoder(decoders)(AttestationWithDalSchema)(val);
|
|
2815
|
-
decoders[CODEC.OP_SEED_NONCE_REVELATION] = (val) => schemaDecoder(decoders)(SeedNonceRevelationSchema)(val);
|
|
2816
|
-
decoders[CODEC.OP_PROPOSALS] = (val) => schemaDecoder(decoders)(ProposalsSchema)(val);
|
|
2817
|
-
decoders[CODEC.OP_REVEAL] = (val) => schemaDecoder(decoders)(RevealSchema)(val);
|
|
2818
|
-
decoders[CODEC.OP_REGISTER_GLOBAL_CONSTANT] = (val) => schemaDecoder(decoders)(RegisterGlobalConstantSchema)(val);
|
|
2819
|
-
decoders[CODEC.OP_TRANSFER_TICKET] = (val) => schemaDecoder(decoders)(TransferTicketSchema)(val);
|
|
2820
|
-
decoders[CODEC.OP_INCREASE_PAID_STORAGE] = (val) => schemaDecoder(decoders)(IncreasePaidStorageSchema)(val);
|
|
2821
|
-
decoders[CODEC.OP_UPDATE_CONSENSUS_KEY] = (val) => schemaDecoder(decoders)(UpdateConsensusKeySchema)(val);
|
|
2822
|
-
decoders[CODEC.OP_DRAIN_DELEGATE] = (val) => schemaDecoder(decoders)(DrainDelegateSchema)(val);
|
|
2823
|
-
decoders[CODEC.OP_SMART_ROLLUP_ORIGINATE] = (val) => schemaDecoder(decoders)(SmartRollupOriginateSchema)(val);
|
|
2824
|
-
decoders[CODEC.OP_SMART_ROLLUP_ADD_MESSAGES] = (val) => schemaDecoder(decoders)(SmartRollupAddMessagesSchema)(val);
|
|
2825
|
-
decoders[CODEC.OP_SMART_ROLLUP_EXECUTE_OUTBOX_MESSAGE] = (val) => schemaDecoder(decoders)(SmartRollupExecuteOutboxMessageSchema)(val);
|
|
2826
|
-
decoders[CODEC.OP_DAL_PUBLISH_COMMITMENT] = (val) => schemaDecoder(decoders)(DalPublishCommitmentSchema)(val);
|
|
2827
|
-
decoders[CODEC.MANAGER] = schemaDecoder(decoders)(ManagerOperationSchema);
|
|
2828
|
-
decoders[CODEC.OP_SET_DEPOSITS_LIMIT] = (val) => schemaDecoder(decoders)(SetDepositsLimitSchema)(val);
|
|
2829
|
-
|
|
2830
|
-
const encoders$1 = {
|
|
2831
|
-
[exports.CODEC.SECRET]: (val) => val,
|
|
2832
|
-
[exports.CODEC.RAW]: (val) => val,
|
|
2833
|
-
[exports.CODEC.TZ1]: tz1Encoder$1,
|
|
2834
|
-
[exports.CODEC.BRANCH]: branchEncoder$1,
|
|
2835
|
-
[exports.CODEC.ZARITH]: zarithEncoder$1,
|
|
2836
|
-
[exports.CODEC.PUBLIC_KEY]: publicKeyEncoder$1,
|
|
2837
|
-
[exports.CODEC.PKH]: publicKeyHashEncoder$1,
|
|
2838
|
-
[exports.CODEC.PKH_ARR]: publicKeyHashesEncoder$1,
|
|
2839
|
-
[exports.CODEC.DELEGATE]: delegateEncoder$1,
|
|
2840
|
-
[exports.CODEC.SCRIPT]: scriptEncoder$1,
|
|
2841
|
-
[exports.CODEC.BALLOT_STATEMENT]: ballotEncoder$1,
|
|
2842
|
-
[exports.CODEC.PROPOSAL]: proposalEncoder$1,
|
|
2843
|
-
[exports.CODEC.PROPOSAL_ARR]: proposalsEncoder$1,
|
|
2844
|
-
[exports.CODEC.INT32]: int32Encoder$1,
|
|
2845
|
-
[exports.CODEC.PARAMETERS]: parametersEncoder$1,
|
|
2846
|
-
[exports.CODEC.ADDRESS]: addressEncoder$1,
|
|
2847
|
-
[exports.CODEC.SMART_ROLLUP_ADDRESS]: smartRollupAddressEncoder$1,
|
|
2848
|
-
[exports.CODEC.SMART_CONTRACT_ADDRESS]: smartContractAddressEncoder$1,
|
|
2849
|
-
[exports.CODEC.SMART_ROLLUP_COMMITMENT_HASH]: smartRollupCommitmentHashEncoder$1,
|
|
2850
|
-
[exports.CODEC.VALUE]: valueParameterEncoder$1,
|
|
2851
|
-
[exports.CODEC.INT16]: int16Encoder$1,
|
|
2852
|
-
[exports.CODEC.BLOCK_PAYLOAD_HASH]: blockPayloadHashEncoder$1,
|
|
2853
|
-
[exports.CODEC.ENTRYPOINT]: entrypointNameEncoder$1,
|
|
2854
|
-
[exports.CODEC.BURN_LIMIT]: burnLimitEncoder$1,
|
|
2855
|
-
[exports.CODEC.DEPOSITS_LIMIT]: depositsLimitEncoder$1,
|
|
2856
|
-
[exports.CODEC.SIGNATURE_PROOF]: signatureProofEncoder$1,
|
|
2857
|
-
[exports.CODEC.PVM_KIND]: pvmKindEncoder$1,
|
|
2858
|
-
[exports.CODEC.PADDED_BYTES]: paddedBytesEncoder$1,
|
|
2859
|
-
[exports.CODEC.SMART_ROLLUP_MESSAGE]: smartRollupMessageEncoder$1,
|
|
2860
|
-
[exports.CODEC.SLOT_HEADER]: slotHeaderEncoder$1,
|
|
2861
|
-
};
|
|
2862
|
-
encoders$1[exports.CODEC.OPERATION] = operationEncoder$1(encoders$1);
|
|
2863
|
-
encoders$1[exports.CODEC.OP_ACTIVATE_ACCOUNT] = (val) => schemaEncoder$1(encoders$1)(ActivationSchema$1)(val);
|
|
2864
|
-
encoders$1[exports.CODEC.OP_DELEGATION] = (val) => schemaEncoder$1(encoders$1)(DelegationSchema$1)(val);
|
|
2865
|
-
encoders$1[exports.CODEC.OP_TRANSACTION] = (val) => schemaEncoder$1(encoders$1)(TransactionSchema$1)(val);
|
|
2866
|
-
encoders$1[exports.CODEC.OP_ORIGINATION] = (val) => schemaEncoder$1(encoders$1)(OriginationSchema$1)(val);
|
|
2867
|
-
encoders$1[exports.CODEC.OP_BALLOT] = (val) => schemaEncoder$1(encoders$1)(BallotSchema$1)(val);
|
|
2868
|
-
encoders$1[exports.CODEC.OP_ATTESTATION] = (val) => schemaEncoder$1(encoders$1)(AttestationSchema$1)(val);
|
|
2869
|
-
encoders$1[exports.CODEC.OP_ATTESTATION_WITH_DAL] = (val) => schemaEncoder$1(encoders$1)(AttestationWithDalSchema$1)(val);
|
|
2870
|
-
encoders$1[exports.CODEC.OP_SEED_NONCE_REVELATION] = (val) => schemaEncoder$1(encoders$1)(SeedNonceRevelationSchema$1)(val);
|
|
2871
|
-
encoders$1[exports.CODEC.OP_PROPOSALS] = (val) => schemaEncoder$1(encoders$1)(ProposalsSchema$1)(val);
|
|
2872
|
-
encoders$1[exports.CODEC.OP_REVEAL] = (val) => schemaEncoder$1(encoders$1)(RevealSchema$1)(val);
|
|
2873
|
-
encoders$1[exports.CODEC.OP_REGISTER_GLOBAL_CONSTANT] = (val) => schemaEncoder$1(encoders$1)(RegisterGlobalConstantSchema$1)(val);
|
|
2874
|
-
encoders$1[exports.CODEC.OP_TRANSFER_TICKET] = (val) => schemaEncoder$1(encoders$1)(TransferTicketSchema$1)(val);
|
|
2875
|
-
encoders$1[exports.CODEC.OP_INCREASE_PAID_STORAGE] = (val) => schemaEncoder$1(encoders$1)(IncreasePaidStorageSchema$1)(val);
|
|
2876
|
-
encoders$1[exports.CODEC.OP_UPDATE_CONSENSUS_KEY] = (val) => schemaEncoder$1(encoders$1)(UpdateConsensusKeySchema$1)(val);
|
|
2877
|
-
encoders$1[exports.CODEC.OP_UPDATE_COMPANION_KEY] = (val) => schemaEncoder$1(encoders$1)(UpdateCompanionKeySchema)(val);
|
|
2878
|
-
encoders$1[exports.CODEC.OP_DRAIN_DELEGATE] = (val) => schemaEncoder$1(encoders$1)(DrainDelegateSchema$1)(val);
|
|
2879
|
-
encoders$1[exports.CODEC.OP_SMART_ROLLUP_ORIGINATE] = (val) => schemaEncoder$1(encoders$1)(SmartRollupOriginateSchema$1)(val);
|
|
2880
|
-
encoders$1[exports.CODEC.OP_SMART_ROLLUP_ADD_MESSAGES] = (val) => schemaEncoder$1(encoders$1)(SmartRollupAddMessagesSchema$1)(val);
|
|
2881
|
-
encoders$1[exports.CODEC.OP_SMART_ROLLUP_EXECUTE_OUTBOX_MESSAGE] = (val) => schemaEncoder$1(encoders$1)(SmartRollupExecuteOutboxMessageSchema$1)(val);
|
|
2882
|
-
encoders$1[exports.CODEC.OP_DAL_PUBLISH_COMMITMENT] = (val) => schemaEncoder$1(encoders$1)(DalPublishCommitmentSchema$1)(val);
|
|
2883
|
-
encoders$1[exports.CODEC.MANAGER] = schemaEncoder$1(encoders$1)(ManagerOperationSchema$1);
|
|
2884
|
-
encoders$1[exports.CODEC.OP_SET_DEPOSITS_LIMIT] = (val) => schemaEncoder$1(encoders$1)(SetDepositsLimitSchema$1)(val);
|
|
2885
|
-
encoders$1[exports.CODEC.OP_FAILING_NOOP] = (val) => schemaEncoder$1(encoders$1)(FailingNoopSchema$1)(val);
|
|
2886
|
-
|
|
2887
|
-
const encoders = {
|
|
2888
|
-
[CODEC.SECRET]: (val) => val,
|
|
2889
|
-
[CODEC.RAW]: (val) => val,
|
|
2890
|
-
[CODEC.TZ1]: tz1Encoder,
|
|
2891
|
-
[CODEC.BRANCH]: branchEncoder,
|
|
2892
|
-
[CODEC.ZARITH]: zarithEncoder,
|
|
2893
|
-
[CODEC.PUBLIC_KEY]: publicKeyEncoder,
|
|
2894
|
-
[CODEC.PKH]: publicKeyHashEncoder,
|
|
2895
|
-
[CODEC.PKH_ARR]: publicKeyHashesEncoder,
|
|
2896
|
-
[CODEC.DELEGATE]: delegateEncoder,
|
|
2897
|
-
[CODEC.SCRIPT]: scriptEncoder,
|
|
2898
|
-
[CODEC.BALLOT_STATEMENT]: ballotEncoder,
|
|
2899
|
-
[CODEC.PROPOSAL]: proposalEncoder,
|
|
2900
|
-
[CODEC.PROPOSAL_ARR]: proposalsEncoder,
|
|
2901
|
-
[CODEC.INT32]: int32Encoder,
|
|
2902
|
-
[CODEC.PARAMETERS]: parametersEncoder,
|
|
2903
|
-
[CODEC.ADDRESS]: addressEncoder,
|
|
2904
|
-
[CODEC.SMART_ROLLUP_ADDRESS]: smartRollupAddressEncoder,
|
|
2905
|
-
[CODEC.SMART_CONTRACT_ADDRESS]: smartContractAddressEncoder,
|
|
2906
|
-
[CODEC.SMART_ROLLUP_COMMITMENT_HASH]: smartRollupCommitmentHashEncoder,
|
|
2907
|
-
[CODEC.VALUE]: valueParameterEncoder,
|
|
2908
|
-
[CODEC.INT16]: int16Encoder,
|
|
2909
|
-
[CODEC.BLOCK_PAYLOAD_HASH]: blockPayloadHashEncoder,
|
|
2910
|
-
[CODEC.ENTRYPOINT]: entrypointNameEncoder,
|
|
2911
|
-
[CODEC.BURN_LIMIT]: burnLimitEncoder,
|
|
2912
|
-
[CODEC.DEPOSITS_LIMIT]: depositsLimitEncoder,
|
|
2913
|
-
[CODEC.SIGNATURE_PROOF]: signatureProofEncoder,
|
|
2914
|
-
[CODEC.PVM_KIND]: pvmKindEncoder,
|
|
2915
|
-
[CODEC.PADDED_BYTES]: paddedBytesEncoder,
|
|
2916
|
-
[CODEC.SMART_ROLLUP_MESSAGE]: smartRollupMessageEncoder,
|
|
2917
|
-
[CODEC.SLOT_HEADER]: slotHeaderEncoder,
|
|
2918
|
-
};
|
|
2919
|
-
encoders[CODEC.OPERATION] = operationEncoder(encoders);
|
|
2920
|
-
encoders[CODEC.OP_ACTIVATE_ACCOUNT] = (val) => schemaEncoder(encoders)(ActivationSchema)(val);
|
|
2921
|
-
encoders[CODEC.OP_DELEGATION] = (val) => schemaEncoder(encoders)(DelegationSchema)(val);
|
|
2922
|
-
encoders[CODEC.OP_TRANSACTION] = (val) => schemaEncoder(encoders)(TransactionSchema)(val);
|
|
2923
|
-
encoders[CODEC.OP_ORIGINATION] = (val) => schemaEncoder(encoders)(OriginationSchema)(val);
|
|
2924
|
-
encoders[CODEC.OP_BALLOT] = (val) => schemaEncoder(encoders)(BallotSchema)(val);
|
|
2925
|
-
encoders[CODEC.OP_ATTESTATION] = (val) => schemaEncoder(encoders)(AttestationSchema)(val);
|
|
2926
|
-
encoders[CODEC.OP_ATTESTATION_WITH_DAL] = (val) => schemaEncoder(encoders)(AttestationWithDalSchema)(val);
|
|
2927
|
-
encoders[CODEC.OP_SEED_NONCE_REVELATION] = (val) => schemaEncoder(encoders)(SeedNonceRevelationSchema)(val);
|
|
2928
|
-
encoders[CODEC.OP_PROPOSALS] = (val) => schemaEncoder(encoders)(ProposalsSchema)(val);
|
|
2929
|
-
encoders[CODEC.OP_REVEAL] = (val) => schemaEncoder(encoders)(RevealSchema)(val);
|
|
2930
|
-
encoders[CODEC.OP_REGISTER_GLOBAL_CONSTANT] = (val) => schemaEncoder(encoders)(RegisterGlobalConstantSchema)(val);
|
|
2931
|
-
encoders[CODEC.OP_TRANSFER_TICKET] = (val) => schemaEncoder(encoders)(TransferTicketSchema)(val);
|
|
2932
|
-
encoders[CODEC.OP_INCREASE_PAID_STORAGE] = (val) => schemaEncoder(encoders)(IncreasePaidStorageSchema)(val);
|
|
2933
|
-
encoders[CODEC.OP_UPDATE_CONSENSUS_KEY] = (val) => schemaEncoder(encoders)(UpdateConsensusKeySchema)(val);
|
|
2934
|
-
encoders[CODEC.OP_DRAIN_DELEGATE] = (val) => schemaEncoder(encoders)(DrainDelegateSchema)(val);
|
|
2935
|
-
encoders[CODEC.OP_SMART_ROLLUP_ORIGINATE] = (val) => schemaEncoder(encoders)(SmartRollupOriginateSchema)(val);
|
|
2936
|
-
encoders[CODEC.OP_SMART_ROLLUP_ADD_MESSAGES] = (val) => schemaEncoder(encoders)(SmartRollupAddMessagesSchema)(val);
|
|
2937
|
-
encoders[CODEC.OP_SMART_ROLLUP_EXECUTE_OUTBOX_MESSAGE] = (val) => schemaEncoder(encoders)(SmartRollupExecuteOutboxMessageSchema)(val);
|
|
2938
|
-
encoders[CODEC.OP_DAL_PUBLISH_COMMITMENT] = (val) => schemaEncoder(encoders)(DalPublishCommitmentSchema)(val);
|
|
2939
|
-
encoders[CODEC.MANAGER] = schemaEncoder(encoders)(ManagerOperationSchema);
|
|
2940
|
-
encoders[CODEC.OP_SET_DEPOSITS_LIMIT] = (val) => schemaEncoder(encoders)(SetDepositsLimitSchema)(val);
|
|
2941
|
-
encoders[CODEC.OP_FAILING_NOOP] = (val) => schemaEncoder(encoders)(FailingNoopSchema)(val);
|
|
2942
|
-
|
|
2943
|
-
const OperationKindMapping = {
|
|
2944
|
-
activate_account: ActivationSchema$1,
|
|
2945
|
-
reveal: RevealSchema$1,
|
|
2946
|
-
delegation: DelegationSchema$1,
|
|
2947
|
-
transaction: TransactionSchema$1,
|
|
2948
|
-
origination: OriginationSchema$1,
|
|
2949
|
-
ballot: BallotSchema$1,
|
|
2950
|
-
attestation: AttestationSchema$1,
|
|
2951
|
-
attestation_with_dal: AttestationWithDalSchema$1,
|
|
2952
|
-
seed_nonce_revelation: SeedNonceRevelationSchema$1,
|
|
2953
|
-
proposals: ProposalsSchema$1,
|
|
2954
|
-
register_global_constant: RegisterGlobalConstantSchema$1,
|
|
2955
|
-
transfer_ticket: TransferTicketSchema$1,
|
|
2956
|
-
increase_paid_storage: IncreasePaidStorageSchema$1,
|
|
2957
|
-
update_consensus_key: UpdateConsensusKeySchema$1,
|
|
2958
|
-
update_companion_key: UpdateCompanionKeySchema,
|
|
2959
|
-
drain_delegate: DrainDelegateSchema$1,
|
|
2960
|
-
set_deposits_limit: SetDepositsLimitSchema$1,
|
|
2961
|
-
smart_rollup_originate: SmartRollupOriginateSchema$1,
|
|
2962
|
-
smart_rollup_add_messages: SmartRollupAddMessagesSchema$1,
|
|
2963
|
-
smart_rollup_execute_outbox_message: SmartRollupExecuteOutboxMessageSchema$1,
|
|
2964
|
-
dal_publish_commitment: DalPublishCommitmentSchema$1,
|
|
2965
|
-
failing_noop: FailingNoopSchema$1,
|
|
2966
|
-
};
|
|
2967
|
-
// Asymmetric difference: only account for things in arr2 that are not present in arr1, not vice versa
|
|
2968
|
-
const getArrayDifference = (arr1, arr2) => {
|
|
2969
|
-
return arr2.filter((x) => !arr1.includes(x));
|
|
2970
|
-
};
|
|
2971
|
-
const deleteArrayElementByValue = (array, item) => {
|
|
2972
|
-
return array.filter((e) => e !== item);
|
|
2973
|
-
};
|
|
2974
|
-
/**
|
|
2975
|
-
* @returns A boolean value to indicate whether the operation kind is valid or not
|
|
1513
|
+
const encoders = {
|
|
1514
|
+
[exports.CODEC.SECRET]: (val) => val,
|
|
1515
|
+
[exports.CODEC.RAW]: (val) => val,
|
|
1516
|
+
[exports.CODEC.TZ1]: tz1Encoder,
|
|
1517
|
+
[exports.CODEC.BRANCH]: branchEncoder,
|
|
1518
|
+
[exports.CODEC.ZARITH]: zarithEncoder,
|
|
1519
|
+
[exports.CODEC.PUBLIC_KEY]: publicKeyEncoder,
|
|
1520
|
+
[exports.CODEC.PKH]: publicKeyHashEncoder,
|
|
1521
|
+
[exports.CODEC.PKH_ARR]: publicKeyHashesEncoder,
|
|
1522
|
+
[exports.CODEC.DELEGATE]: delegateEncoder,
|
|
1523
|
+
[exports.CODEC.SCRIPT]: scriptEncoder,
|
|
1524
|
+
[exports.CODEC.BALLOT_STATEMENT]: ballotEncoder,
|
|
1525
|
+
[exports.CODEC.PROPOSAL]: proposalEncoder,
|
|
1526
|
+
[exports.CODEC.PROPOSAL_ARR]: proposalsEncoder,
|
|
1527
|
+
[exports.CODEC.INT32]: int32Encoder,
|
|
1528
|
+
[exports.CODEC.PARAMETERS]: parametersEncoder,
|
|
1529
|
+
[exports.CODEC.ADDRESS]: addressEncoder,
|
|
1530
|
+
[exports.CODEC.SMART_ROLLUP_ADDRESS]: smartRollupAddressEncoder,
|
|
1531
|
+
[exports.CODEC.SMART_CONTRACT_ADDRESS]: smartContractAddressEncoder,
|
|
1532
|
+
[exports.CODEC.SMART_ROLLUP_COMMITMENT_HASH]: smartRollupCommitmentHashEncoder,
|
|
1533
|
+
[exports.CODEC.VALUE]: valueParameterEncoder,
|
|
1534
|
+
[exports.CODEC.INT16]: int16Encoder,
|
|
1535
|
+
[exports.CODEC.BLOCK_PAYLOAD_HASH]: blockPayloadHashEncoder,
|
|
1536
|
+
[exports.CODEC.ENTRYPOINT]: entrypointNameEncoder,
|
|
1537
|
+
[exports.CODEC.BURN_LIMIT]: burnLimitEncoder,
|
|
1538
|
+
[exports.CODEC.DEPOSITS_LIMIT]: depositsLimitEncoder,
|
|
1539
|
+
[exports.CODEC.SIGNATURE_PROOF]: signatureProofEncoder,
|
|
1540
|
+
[exports.CODEC.PVM_KIND]: pvmKindEncoder,
|
|
1541
|
+
[exports.CODEC.PADDED_BYTES]: paddedBytesEncoder,
|
|
1542
|
+
[exports.CODEC.SMART_ROLLUP_MESSAGE]: smartRollupMessageEncoder,
|
|
1543
|
+
[exports.CODEC.SLOT_HEADER]: slotHeaderEncoder,
|
|
1544
|
+
};
|
|
1545
|
+
encoders[exports.CODEC.OPERATION] = operationEncoder(encoders);
|
|
1546
|
+
encoders[exports.CODEC.OP_ACTIVATE_ACCOUNT] = (val) => schemaEncoder(encoders)(ActivationSchema)(val);
|
|
1547
|
+
encoders[exports.CODEC.OP_DELEGATION] = (val) => schemaEncoder(encoders)(DelegationSchema)(val);
|
|
1548
|
+
encoders[exports.CODEC.OP_TRANSACTION] = (val) => schemaEncoder(encoders)(TransactionSchema)(val);
|
|
1549
|
+
encoders[exports.CODEC.OP_ORIGINATION] = (val) => schemaEncoder(encoders)(OriginationSchema)(val);
|
|
1550
|
+
encoders[exports.CODEC.OP_BALLOT] = (val) => schemaEncoder(encoders)(BallotSchema)(val);
|
|
1551
|
+
encoders[exports.CODEC.OP_ATTESTATION] = (val) => schemaEncoder(encoders)(AttestationSchema)(val);
|
|
1552
|
+
encoders[exports.CODEC.OP_ATTESTATION_WITH_DAL] = (val) => schemaEncoder(encoders)(AttestationWithDalSchema)(val);
|
|
1553
|
+
encoders[exports.CODEC.OP_SEED_NONCE_REVELATION] = (val) => schemaEncoder(encoders)(SeedNonceRevelationSchema)(val);
|
|
1554
|
+
encoders[exports.CODEC.OP_PROPOSALS] = (val) => schemaEncoder(encoders)(ProposalsSchema)(val);
|
|
1555
|
+
encoders[exports.CODEC.OP_REVEAL] = (val) => schemaEncoder(encoders)(RevealSchema)(val);
|
|
1556
|
+
encoders[exports.CODEC.OP_REGISTER_GLOBAL_CONSTANT] = (val) => schemaEncoder(encoders)(RegisterGlobalConstantSchema)(val);
|
|
1557
|
+
encoders[exports.CODEC.OP_TRANSFER_TICKET] = (val) => schemaEncoder(encoders)(TransferTicketSchema)(val);
|
|
1558
|
+
encoders[exports.CODEC.OP_INCREASE_PAID_STORAGE] = (val) => schemaEncoder(encoders)(IncreasePaidStorageSchema)(val);
|
|
1559
|
+
encoders[exports.CODEC.OP_UPDATE_CONSENSUS_KEY] = (val) => schemaEncoder(encoders)(UpdateConsensusKeySchema)(val);
|
|
1560
|
+
encoders[exports.CODEC.OP_UPDATE_COMPANION_KEY] = (val) => schemaEncoder(encoders)(UpdateCompanionKeySchema)(val);
|
|
1561
|
+
encoders[exports.CODEC.OP_DRAIN_DELEGATE] = (val) => schemaEncoder(encoders)(DrainDelegateSchema)(val);
|
|
1562
|
+
encoders[exports.CODEC.OP_SMART_ROLLUP_ORIGINATE] = (val) => schemaEncoder(encoders)(SmartRollupOriginateSchema)(val);
|
|
1563
|
+
encoders[exports.CODEC.OP_SMART_ROLLUP_ADD_MESSAGES] = (val) => schemaEncoder(encoders)(SmartRollupAddMessagesSchema)(val);
|
|
1564
|
+
encoders[exports.CODEC.OP_SMART_ROLLUP_EXECUTE_OUTBOX_MESSAGE] = (val) => schemaEncoder(encoders)(SmartRollupExecuteOutboxMessageSchema)(val);
|
|
1565
|
+
encoders[exports.CODEC.OP_DAL_PUBLISH_COMMITMENT] = (val) => schemaEncoder(encoders)(DalPublishCommitmentSchema)(val);
|
|
1566
|
+
encoders[exports.CODEC.MANAGER] = schemaEncoder(encoders)(ManagerOperationSchema);
|
|
1567
|
+
encoders[exports.CODEC.OP_SET_DEPOSITS_LIMIT] = (val) => schemaEncoder(encoders)(SetDepositsLimitSchema)(val);
|
|
1568
|
+
encoders[exports.CODEC.OP_FAILING_NOOP] = (val) => schemaEncoder(encoders)(FailingNoopSchema)(val);
|
|
1569
|
+
|
|
1570
|
+
const OperationKindMapping = {
|
|
1571
|
+
activate_account: ActivationSchema,
|
|
1572
|
+
reveal: RevealSchema,
|
|
1573
|
+
delegation: DelegationSchema,
|
|
1574
|
+
transaction: TransactionSchema,
|
|
1575
|
+
origination: OriginationSchema,
|
|
1576
|
+
ballot: BallotSchema,
|
|
1577
|
+
attestation: AttestationSchema,
|
|
1578
|
+
attestation_with_dal: AttestationWithDalSchema,
|
|
1579
|
+
seed_nonce_revelation: SeedNonceRevelationSchema,
|
|
1580
|
+
proposals: ProposalsSchema,
|
|
1581
|
+
register_global_constant: RegisterGlobalConstantSchema,
|
|
1582
|
+
transfer_ticket: TransferTicketSchema,
|
|
1583
|
+
increase_paid_storage: IncreasePaidStorageSchema,
|
|
1584
|
+
update_consensus_key: UpdateConsensusKeySchema,
|
|
1585
|
+
update_companion_key: UpdateCompanionKeySchema,
|
|
1586
|
+
drain_delegate: DrainDelegateSchema,
|
|
1587
|
+
set_deposits_limit: SetDepositsLimitSchema,
|
|
1588
|
+
smart_rollup_originate: SmartRollupOriginateSchema,
|
|
1589
|
+
smart_rollup_add_messages: SmartRollupAddMessagesSchema,
|
|
1590
|
+
smart_rollup_execute_outbox_message: SmartRollupExecuteOutboxMessageSchema,
|
|
1591
|
+
dal_publish_commitment: DalPublishCommitmentSchema,
|
|
1592
|
+
failing_noop: FailingNoopSchema,
|
|
1593
|
+
};
|
|
1594
|
+
// Asymmetric difference: only account for things in arr2 that are not present in arr1, not vice versa
|
|
1595
|
+
const getArrayDifference = (arr1, arr2) => {
|
|
1596
|
+
return arr2.filter((x) => !arr1.includes(x));
|
|
1597
|
+
};
|
|
1598
|
+
const deleteArrayElementByValue = (array, item) => {
|
|
1599
|
+
return array.filter((e) => e !== item);
|
|
1600
|
+
};
|
|
1601
|
+
/**
|
|
1602
|
+
* @returns A boolean value to indicate whether the operation kind is valid or not
|
|
2976
1603
|
*/
|
|
2977
1604
|
const validateOperationKind = (opKind) => {
|
|
2978
1605
|
const opKindList = Object.keys(OperationKindMapping);
|
|
@@ -3018,39 +1645,11 @@
|
|
|
3018
1645
|
ProtocolsHash["PtSeouLou"] = "PtSeouLouXkxhg39oWzjxDWaCydNfR3RxCUrNe4Q9Ro8BTehcbh";
|
|
3019
1646
|
ProtocolsHash["ProtoALpha"] = "ProtoALphaALphaALphaALphaALphaALphaALphaALphaDdp3zK";
|
|
3020
1647
|
})(exports.ProtocolsHash || (exports.ProtocolsHash = {}));
|
|
3021
|
-
const protoLevel = {
|
|
3022
|
-
Pt24m4xiPbLDhVgVfABUjirbmda3yohdN82Sp9FeuAXJ4eV9otd: 4,
|
|
3023
|
-
PsBABY5HQTSkA4297zNHfsZNKtxULfL18y95qb3m53QJiXGmrbU: 5,
|
|
3024
|
-
PsBabyM1eUXZseaJdmXFApDSBqj8YBfwELoxZHHW77EMcAbbwAS: 5,
|
|
3025
|
-
PsCARTHAGazKbHtnKfLzQg3kms52kSRpgnDY982a9oYsSXRLQEb: 6,
|
|
3026
|
-
PsDELPH1Kxsxt8f9eWbxQeRxkjfbxoqM52jvs5Y5fBxWWh4ifpo: 7,
|
|
3027
|
-
PtEdo2ZkT9oKpimTah6x2embF25oss54njMuPzkJTEi5RqfdZFA: 8,
|
|
3028
|
-
PsFLorenaUUuikDWvMDr6fGBRG8kt3e3D3fHoXK1j1BFRxeSH4i: 9,
|
|
3029
|
-
PtGRANADsDU8R9daYKAgWnQYAJ64omN1o3KMGVCykShA97vQbvV: 10,
|
|
3030
|
-
PtHangz2aRngywmSRGGvrcTyMbbdpWdpFKuS4uMWxg2RaH9i1qx: 11,
|
|
3031
|
-
Psithaca2MLRFYargivpo7YvUr7wUDqyxrdhC5CQq78mRvimz6A: 12,
|
|
3032
|
-
PtJakart2xVj7pYXJBXrqHgd82rdkLey5ZeeGwDgPp9rhQUbSqY: 13,
|
|
3033
|
-
PtKathmankSpLLDALzWw7CGD2j2MtyveTwboEYokqUCP4a1LxMg: 14,
|
|
3034
|
-
PtLimaPtLMwfNinJi9rCfDPWea8dFgTZ1MeJ9f1m2SRic6ayiwW: 15,
|
|
3035
|
-
PtMumbaiiFFEGbew1rRjzSPyzRbA51Tm3RVZL5suHPxSZYDhCEc: 16,
|
|
3036
|
-
PtMumbai2TmsJHNGRkD8v8YDbtao7BLUC3wjASn1inAKLFCjaH1: 16,
|
|
3037
|
-
PtNairobiyssHuh87hEhfVBGCVrK3WnS8Z2FT4ymB5tAa4r1nQf: 17,
|
|
3038
|
-
ProxfordYmVfjWnRcgjWH36fW6PArwqykTFzotUxRs6gmTcZDuH: 19,
|
|
3039
|
-
PtParisBxoLz5gzMmn3d9WBQNoPSZakgnkMC2VNuQ3KXfUtUQeZ: 20,
|
|
3040
|
-
PsParisCZo7KAh1Z1smVd9ZMZ1HHn5gkzbM94V3PLCpknFWhUAi: 20,
|
|
3041
|
-
PsQuebecnLByd3JwTiGadoG4nGWi3HYiLXUjkibeFV8dCFeVMUg: 21,
|
|
3042
|
-
PsRiotumaAMotcRoDWW1bysEhQy2n1M5fy8JgRp8jjRfHGmfeA7: 22,
|
|
3043
|
-
PtSeouLouXkxhg39oWzjxDWaCydNfR3RxCUrNe4Q9Ro8BTehcbh: 23,
|
|
3044
|
-
ProtoALphaALphaALphaALphaALphaALphaALphaALphaDdp3zK: 23,
|
|
3045
|
-
};
|
|
3046
|
-
function ProtoInferiorTo(a, b) {
|
|
3047
|
-
return protoLevel[a] < protoLevel[b];
|
|
3048
|
-
}
|
|
3049
1648
|
|
|
3050
1649
|
// IMPORTANT: THIS FILE IS AUTO GENERATED! DO NOT MANUALLY EDIT OR CHECKIN!
|
|
3051
1650
|
const VERSION = {
|
|
3052
|
-
"commitHash": "
|
|
3053
|
-
"version": "23.0
|
|
1651
|
+
"commitHash": "c77fe4b0989665d8b5cfd15a7cc977499021f6fd",
|
|
1652
|
+
"version": "23.1.0"
|
|
3054
1653
|
};
|
|
3055
1654
|
|
|
3056
1655
|
/**
|
|
@@ -3065,33 +1664,13 @@
|
|
|
3065
1664
|
}
|
|
3066
1665
|
const PROTOCOL_CURRENT = exports.ProtocolsHash.PtSeouLou;
|
|
3067
1666
|
function getCodec(codec, _proto) {
|
|
3068
|
-
|
|
3069
|
-
|
|
3070
|
-
|
|
3071
|
-
|
|
3072
|
-
|
|
3073
|
-
|
|
3074
|
-
|
|
3075
|
-
},
|
|
3076
|
-
};
|
|
3077
|
-
}
|
|
3078
|
-
else {
|
|
3079
|
-
return {
|
|
3080
|
-
encoder: encoders$1[codec],
|
|
3081
|
-
decoder: (hex) => {
|
|
3082
|
-
const consumer = Uint8ArrayConsumer.fromHexString(hex);
|
|
3083
|
-
return decoders$1[codec](consumer);
|
|
3084
|
-
},
|
|
3085
|
-
};
|
|
3086
|
-
}
|
|
3087
|
-
// TODO: Remove above if else once mainnet migrated into rio protocol and uncommon the return block below
|
|
3088
|
-
// return {
|
|
3089
|
-
// encoder: encoders[codec],
|
|
3090
|
-
// decoder: (hex: string) => {
|
|
3091
|
-
// const consumer = Uint8ArrayConsumer.fromHexString(hex);
|
|
3092
|
-
// return decoders[codec](consumer) as any;
|
|
3093
|
-
// },
|
|
3094
|
-
// };
|
|
1667
|
+
return {
|
|
1668
|
+
encoder: encoders[codec],
|
|
1669
|
+
decoder: (hex) => {
|
|
1670
|
+
const consumer = Uint8ArrayConsumer.fromHexString(hex);
|
|
1671
|
+
return decoders[codec](consumer);
|
|
1672
|
+
},
|
|
1673
|
+
};
|
|
3095
1674
|
}
|
|
3096
1675
|
class LocalForger {
|
|
3097
1676
|
constructor(protocolHash = PROTOCOL_CURRENT) {
|
|
@@ -3153,12 +1732,12 @@
|
|
|
3153
1732
|
exports.LocalForger = LocalForger;
|
|
3154
1733
|
exports.Uint8ArrayConsumer = Uint8ArrayConsumer;
|
|
3155
1734
|
exports.VERSION = VERSION;
|
|
3156
|
-
exports.decoders = decoders
|
|
3157
|
-
exports.encoders = encoders
|
|
1735
|
+
exports.decoders = decoders;
|
|
1736
|
+
exports.encoders = encoders;
|
|
3158
1737
|
exports.getCodec = getCodec;
|
|
3159
1738
|
exports.localForger = localForger;
|
|
3160
|
-
exports.opMapping = opMapping
|
|
3161
|
-
exports.opMappingReverse = opMappingReverse
|
|
1739
|
+
exports.opMapping = opMapping;
|
|
1740
|
+
exports.opMappingReverse = opMappingReverse;
|
|
3162
1741
|
|
|
3163
1742
|
}));
|
|
3164
1743
|
//# sourceMappingURL=taquito-local-forging.umd.js.map
|