postchain-client 2.0.0 → 2.0.2

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.
Files changed (74) hide show
  1. package/README.md +11 -0
  2. package/built/cjs/index.js +138 -1421
  3. package/built/cjs/index.js.map +1 -1
  4. package/built/esm/index.js +12400 -13410
  5. package/built/esm/index.js.map +1 -1
  6. package/built/index.d.ts +0 -1
  7. package/built/index.js +0 -2
  8. package/built/index.js.map +1 -1
  9. package/built/src/ICCF/IccfProofTxMaterialBuilder.d.ts +3 -2
  10. package/built/src/ICCF/IccfProofTxMaterialBuilder.js +23 -10
  11. package/built/src/ICCF/IccfProofTxMaterialBuilder.js.map +1 -1
  12. package/built/src/blockchainClient/blockchainClient.js +7 -3
  13. package/built/src/blockchainClient/blockchainClient.js.map +1 -1
  14. package/built/src/blockchainClient/failoverStrategies.js +2 -1
  15. package/built/src/blockchainClient/failoverStrategies.js.map +1 -1
  16. package/built/src/blockchainClient/nodeManager.d.ts +3 -0
  17. package/built/src/blockchainClient/nodeManager.js +7 -0
  18. package/built/src/blockchainClient/nodeManager.js.map +1 -1
  19. package/built/src/blockchainClient/types.d.ts +1 -0
  20. package/built/src/blockchainClient/utils.d.ts +11 -1
  21. package/built/src/blockchainClient/utils.js +14 -1
  22. package/built/src/blockchainClient/utils.js.map +1 -1
  23. package/built/src/gtv/index.d.ts +2 -2
  24. package/built/src/gtv/index.js +4 -6
  25. package/built/src/gtv/index.js.map +1 -1
  26. package/built/test/pcctf/getSuites.test.js +106 -0
  27. package/built/test/pcctf/getSuites.test.js.map +1 -0
  28. package/built/test/pcctf/helpers.d.ts +92 -0
  29. package/built/test/pcctf/helpers.js +239 -0
  30. package/built/test/pcctf/helpers.js.map +1 -0
  31. package/built/test/unit/blockchainClient/client.test.js +2 -0
  32. package/built/test/unit/blockchainClient/client.test.js.map +1 -1
  33. package/built/test/unit/failoverStrategies.test.js +1 -1
  34. package/built/test/unit/failoverStrategies.test.js.map +1 -1
  35. package/built/umd/index.js +14393 -13535
  36. package/built/umd/index.js.map +1 -1
  37. package/changelog.md +33 -1
  38. package/package.json +8 -4
  39. package/built/src/merkle/binarytree.d.ts +0 -131
  40. package/built/src/merkle/binarytree.js +0 -146
  41. package/built/src/merkle/binarytree.js.map +0 -1
  42. package/built/src/merkle/binarytreefactory.d.ts +0 -86
  43. package/built/src/merkle/binarytreefactory.js +0 -251
  44. package/built/src/merkle/binarytreefactory.js.map +0 -1
  45. package/built/src/merkle/merkleHelper.d.ts +0 -17
  46. package/built/src/merkle/merkleHelper.js +0 -109
  47. package/built/src/merkle/merkleHelper.js.map +0 -1
  48. package/built/src/merkle/merklehashcalculator.d.ts +0 -37
  49. package/built/src/merkle/merklehashcalculator.js +0 -73
  50. package/built/src/merkle/merklehashcalculator.js.map +0 -1
  51. package/built/src/merkle/path.d.ts +0 -151
  52. package/built/src/merkle/path.js +0 -306
  53. package/built/src/merkle/path.js.map +0 -1
  54. package/built/src/merkle/proof/merklehashcarrier.d.ts +0 -17
  55. package/built/src/merkle/proof/merklehashcarrier.js +0 -23
  56. package/built/src/merkle/proof/merklehashcarrier.js.map +0 -1
  57. package/built/src/merkle/proof/merklehashsummaryfactory.d.ts +0 -53
  58. package/built/src/merkle/proof/merklehashsummaryfactory.js +0 -82
  59. package/built/src/merkle/proof/merklehashsummaryfactory.js.map +0 -1
  60. package/built/src/merkle/proof/merkleproof.d.ts +0 -36
  61. package/built/src/merkle/proof/merkleproof.js +0 -61
  62. package/built/src/merkle/proof/merkleproof.js.map +0 -1
  63. package/built/src/merkle/proof/merkleprooftree.d.ts +0 -124
  64. package/built/src/merkle/proof/merkleprooftree.js +0 -117
  65. package/built/src/merkle/proof/merkleprooftree.js.map +0 -1
  66. package/built/src/merkle/proof/merkleprooftreefactory.d.ts +0 -47
  67. package/built/src/merkle/proof/merkleprooftreefactory.js +0 -123
  68. package/built/src/merkle/proof/merkleprooftreefactory.js.map +0 -1
  69. package/built/src/merkle/types.d.ts +0 -11
  70. package/built/src/merkle/types.js +0 -2
  71. package/built/src/merkle/types.js.map +0 -1
  72. package/built/test/unit/merkle/merkleHelper/merkleHelperTest.js +0 -85
  73. package/built/test/unit/merkle/merkleHelper/merkleHelperTest.js.map +0 -1
  74. /package/built/test/{unit/merkle/merkleHelper/merkleHelperTest.d.ts → pcctf/getSuites.test.d.ts} +0 -0
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var require$$0$1 = require('buffer');
3
+ var merklehashts = require('merklehashts');
4
4
  var bn_js = require('bn.js');
5
5
  var zod = require('zod');
6
6
  var crypto = require('crypto');
@@ -9,53 +9,25 @@ var cloneDeep = require('lodash/cloneDeep');
9
9
  var events = require('events');
10
10
 
11
11
  function _interopNamespaceDefault(e) {
12
- var n = Object.create(null);
13
- if (e) {
14
- Object.keys(e).forEach(function (k) {
15
- if (k !== 'default') {
16
- var d = Object.getOwnPropertyDescriptor(e, k);
17
- Object.defineProperty(n, k, d.get ? d : {
18
- enumerable: true,
19
- get: function () { return e[k]; }
20
- });
21
- }
22
- });
23
- }
24
- n.default = e;
25
- return Object.freeze(n);
12
+ var n = Object.create(null);
13
+ if (e) {
14
+ Object.keys(e).forEach(function (k) {
15
+ if (k !== 'default') {
16
+ var d = Object.getOwnPropertyDescriptor(e, k);
17
+ Object.defineProperty(n, k, d.get ? d : {
18
+ enumerable: true,
19
+ get: function () { return e[k]; }
20
+ });
21
+ }
22
+ });
23
+ }
24
+ n.default = e;
25
+ return Object.freeze(n);
26
26
  }
27
27
 
28
28
  var crypto__namespace = /*#__PURE__*/_interopNamespaceDefault(crypto);
29
29
  var secp256k1__namespace = /*#__PURE__*/_interopNamespaceDefault(secp256k1);
30
30
 
31
- function getAugmentedNamespace(n) {
32
- if (n.__esModule) return n;
33
- var f = n.default;
34
- if (typeof f == "function") {
35
- var a = function a () {
36
- if (this instanceof a) {
37
- var args = [null];
38
- args.push.apply(args, arguments);
39
- var Ctor = Function.bind.apply(f, args);
40
- return new Ctor();
41
- }
42
- return f.apply(this, arguments);
43
- };
44
- a.prototype = f.prototype;
45
- } else a = {};
46
- Object.defineProperty(a, '__esModule', {value: true});
47
- Object.keys(n).forEach(function (k) {
48
- var d = Object.getOwnPropertyDescriptor(n, k);
49
- Object.defineProperty(a, k, d.get ? d : {
50
- enumerable: true,
51
- get: function () {
52
- return n[k];
53
- }
54
- });
55
- });
56
- return a;
57
- }
58
-
59
31
  /* eslint-disable @typescript-eslint/ban-ts-comment */
60
32
  // @ts-nocheck
61
33
  // eslint-disable-next-line @typescript-eslint/no-var-requires
@@ -269,20 +241,20 @@ function matchRellErrorString(rellError) {
269
241
  }
270
242
 
271
243
  var formatter = /*#__PURE__*/Object.freeze({
272
- __proto__: null,
273
- PgBytesInputException: PgBytesInputException,
274
- checkGtvType: checkGtvType,
275
- checkGtxType: checkGtxType,
276
- ensureBuffer: ensureBuffer,
277
- ensureString: ensureString,
278
- matchRellErrorString: matchRellErrorString,
279
- pgBytes: pgBytes,
280
- rawGtxToGtx: rawGtxToGtx,
281
- rawGtxToRawGtxBody: rawGtxToRawGtxBody,
282
- removeDuplicateSigners: removeDuplicateSigners,
283
- toBuffer: toBuffer,
284
- toQueryObjectGTV: toQueryObjectGTV,
285
- toString: toString
244
+ __proto__: null,
245
+ PgBytesInputException: PgBytesInputException,
246
+ checkGtvType: checkGtvType,
247
+ checkGtxType: checkGtxType,
248
+ ensureBuffer: ensureBuffer,
249
+ ensureString: ensureString,
250
+ matchRellErrorString: matchRellErrorString,
251
+ pgBytes: pgBytes,
252
+ rawGtxToGtx: rawGtxToGtx,
253
+ rawGtxToRawGtxBody: rawGtxToRawGtxBody,
254
+ removeDuplicateSigners: removeDuplicateSigners,
255
+ toBuffer: toBuffer,
256
+ toQueryObjectGTV: toQueryObjectGTV,
257
+ toString: toString
286
258
  });
287
259
 
288
260
  function encodeValue(rawGtv) {
@@ -413,469 +385,18 @@ function sortDictPairByKey(dict) {
413
385
  return sortedDict;
414
386
  }
415
387
 
416
- var serialization$1 = /*#__PURE__*/Object.freeze({
417
- __proto__: null,
418
- createTypedArg: createTypedArg,
419
- decodeValue: decodeValue,
420
- decodeValueGtx: decodeValueGtx,
421
- encodeValue: encodeValue,
422
- encodeValueGtx: encodeValueGtx,
423
- parseValue: parseValue
424
- });
425
-
426
- var require$$1 = /*@__PURE__*/getAugmentedNamespace(serialization$1);
427
-
428
- var require$$0 = /*@__PURE__*/getAugmentedNamespace(formatter);
429
-
430
- var util$1 = require$$0;
431
- function PathElement(previous) {
432
- this.previous = previous;
433
- }
434
- PathElement.prototype.getSearchKey = function () { };
435
- function PathLeafElement$3(previous) {
436
- PathElement.call(this, previous);
437
- }
438
- PathLeafElement$3.prototype = Object.create(PathElement.prototype);
439
- PathLeafElement$3.prototype.constructor = PathLeafElement$3;
440
- PathLeafElement$3.prototype.equals = function (other) {
441
- if (this === other)
442
- return true;
443
- if (typeof this !== typeof other)
444
- return false;
445
- return true;
446
- };
447
- function SearchablePathElement(previous) {
448
- PathElement.call(this, previous);
449
- }
450
- SearchablePathElement.prototype = Object.create(PathElement.prototype);
451
- SearchablePathElement.prototype.constructor = SearchablePathElement;
452
- SearchablePathElement.prototype.getSearchKey = function () { };
453
- /**
454
- *
455
- * @param {SearchablePathElement} previous
456
- * @param {number} index
457
- */
458
- function ArrayPathElement(previous, index) {
459
- SearchablePathElement.call(this, previous);
460
- this.index = index;
461
- }
462
- ArrayPathElement.prototype = Object.create(SearchablePathElement.prototype);
463
- ArrayPathElement.prototype.constructor = ArrayPathElement;
464
- ArrayPathElement.prototype.getSearchKey = function () {
465
- return this.index;
466
- };
467
- /**
468
- * @param {ArrayPathElement} other
469
- */
470
- ArrayPathElement.prototype.equals = function (other) {
471
- if (this === other)
472
- return true;
473
- if (typeof this !== typeof other)
474
- return false;
475
- if (this.index != other.index)
476
- return false;
477
- return true;
478
- };
479
- /**
480
- *
481
- * @param {SearchablePathElement} previous
482
- * @param {string} key
483
- */
484
- function DictPathElement(previous, key) {
485
- SearchablePathElement.call(this, previous);
486
- this.key = key;
487
- }
488
- DictPathElement.prototype = Object.create(SearchablePathElement.prototype);
489
- DictPathElement.prototype.constructor = DictPathElement;
490
- DictPathElement.prototype.getSearchKey = function () {
491
- return this.key;
492
- };
493
- /**
494
- * @param {DictPathElement} other
495
- */
496
- DictPathElement.prototype.equals = function (other) {
497
- if (this === other)
498
- return true;
499
- if (typeof this !== typeof other)
500
- return false;
501
- if (this.key != other.key)
502
- return false;
503
- return true;
504
- };
505
- /**
506
- *
507
- * @param {Array} pathElements
508
- */
509
- function Path(pathElements) {
510
- this.pathElements = pathElements;
511
- }
512
- /**
513
- *
514
- */
515
- Path.prototype.getCurrentPathElement = function () {
516
- return this.pathElements[0];
517
- };
518
- /**
519
- *
520
- */
521
- Path.prototype.size = function () {
522
- return this.pathElements.length;
523
- };
524
- /**
525
- *
526
- */
527
- Path.prototype.tail = function () {
528
- if (this.pathElements.length == 0) {
529
- throw new Error("Impossible to tail this array");
530
- }
531
- else {
532
- var tail = this.pathElements.slice(1);
533
- return new Path(tail);
534
- }
535
- };
536
- Path.prototype.debugString = function () {
537
- var sb = "";
538
- this.pathElements.forEach(elem => {
539
- if (elem instanceof SearchablePathElement) {
540
- sb = sb + "-> " + elem.getSearchKey();
541
- }
542
- else if (elem instanceof PathLeafElement$3) {
543
- sb = sb + "-> Leaf";
544
- }
545
- });
546
- return sb;
547
- };
548
- /**
549
- * @param {Path} other
550
- */
551
- Path.prototype.equals = function (other) {
552
- if (this === other)
553
- return true;
554
- if (typeof this != typeof other)
555
- return false;
556
- return this.pathElements == other.pathElements;
557
- };
558
- /**
559
- * @param {number} index
560
- * @param {Path} path
561
- */
562
- var getTailIfFirstElementIsArrayOfThisIndex = function (index, path) {
563
- return getTail(index, path);
564
- };
565
- /**
566
- *
567
- * @param {string} key
568
- * @param {Path} path
569
- */
570
- var getTailIfFirstElementIsDictOfThisKey = function (key, path) {
571
- return getTail(key, path);
572
- };
573
- /**
574
- *
575
- * @param {string|number} searchKey
576
- * @param {Path} path
577
- */
578
- var getTail = function (searchKey, path) {
579
- if (searchKey === null) {
580
- throw new Error("Have to provide a search key");
581
- }
582
- try {
583
- var firstElement = path.pathElements[0];
584
- if (firstElement instanceof SearchablePathElement) {
585
- if (firstElement.getSearchKey() == searchKey) {
586
- return path.tail();
587
- }
588
- }
589
- }
590
- catch (err) {
591
- util$1.logError("Why are we dropping first element of an empty path? " + err);
592
- return null;
593
- }
594
- return null;
595
- };
596
- /**
597
- *
598
- * @param {Array} paths
599
- */
600
- function PathSet$1(paths) {
601
- this.paths = paths;
602
- }
603
- /**
604
- *
605
- */
606
- PathSet$1.prototype.isEmpty = function () {
607
- return this.paths.length == 0;
608
- };
609
- /**
610
- *
611
- */
612
- PathSet$1.prototype.getPathLeafOrElseAnyCurrentPathElement = function () {
613
- var leafElem = null;
614
- var currElem = null;
615
- var prev = {
616
- "path": null,
617
- "elem": null,
618
- };
619
- this.paths.forEach(path => {
620
- currElem = path.getCurrentPathElement();
621
- if (currElem instanceof PathLeafElement$3) {
622
- leafElem = currElem;
623
- }
624
- prev = this.errorCheckUnequalParent(path, currElem, prev.path, prev.elem);
625
- });
626
- if (leafElem != null) {
627
- return leafElem;
628
- }
629
- else {
630
- return currElem; // It doesn't matter which one we return (Next step we will get the "previous" from this one)
631
- }
632
- };
633
- /**
634
- * Yeah, this might be a completely un-needed check (but it MIGHT save us later on if we forget this rule).
635
- * What we are looking for here is an impossible state where two paths in the same set don't have the same parent.
636
- * (Since we usually only have one path in a path set, this check should be cheap)
637
- *
638
- * @param {Path} currPath
639
- * @param {PathElement} currElem
640
- * @param {Path} prevPath
641
- * @param {PathElement} prevElem
642
- */
643
- PathSet$1.prototype.errorCheckUnequalParent = function (currPath, currElem, prevPath, prevElem) {
644
- if (prevElem != null) {
645
- // weird: javascript cannot compare null == null then we have to compare each with null separately :(
646
- if (currElem.previous == null && prevElem.previous == null) {
647
- return {
648
- "path": currPath,
649
- "elem": currElem
650
- };
651
- }
652
- else if ((currElem.previous == null && prevElem.previous != null) || (currElem.previous != null && prevElem.previous == null)) {
653
- throw new Error("Something is wrong, these paths do not have the same parent. (" + currPath + ") (" + prevPath + ")");
654
- }
655
- else if (!currElem.previous.equals(prevElem.previous)) {
656
- throw new Error("Something is wrong, these paths do not have the same parent. (" + currPath + ") (" + prevPath + ")");
657
- }
658
- }
659
- return {
660
- "path": currPath,
661
- "elem": currElem
662
- };
663
- };
664
- /**
665
- *
666
- */
667
- PathSet$1.prototype.keepOnlyArrayPaths = function () {
668
- var filteredPaths = this.paths.filter(path => {
669
- return path.pathElements[0] instanceof ArrayPathElement;
670
- });
671
- return new PathSet$1(filteredPaths);
672
- };
673
- /**
674
- *
675
- */
676
- PathSet$1.prototype.keepOnlyDictPaths = function () {
677
- var filteredPaths = this.paths.filter(path => {
678
- return path.pathElements[0] instanceof DictPathElement;
679
- });
680
- return new PathSet$1(filteredPaths);
681
- };
682
- /**
683
- *
684
- */
685
- PathSet$1.prototype.getTailIfFirstElementIsArrayOfThisIndexFromList = function (index) {
686
- return this.getTailFromList(index, getTailIfFirstElementIsArrayOfThisIndex);
687
- };
688
- /**
689
- *
690
- */
691
- PathSet$1.prototype.getTailIfFirstElementIsDictOfThisKeyFromList = function (key) {
692
- return this.getTailFromList(key, getTailIfFirstElementIsDictOfThisKey);
693
- };
694
- /**
695
- *
696
- */
697
- PathSet$1.prototype.getTailFromList = function (searchKey, filterFunc) {
698
- var retPaths = new Array();
699
- this.paths.forEach(path => {
700
- var newPath = filterFunc(searchKey, path);
701
- if (newPath != null) {
702
- retPaths.push(newPath);
703
- }
704
- });
705
- return new PathSet$1(retPaths);
706
- };
707
- /**
708
- *
709
- * @param {Array} arr
710
- */
711
- var buildPathFromArray = function (arr) {
712
- var pathElements = new Array();
713
- var lastPathElem = null;
714
- arr.forEach(item => {
715
- var newElem = null;
716
- if (typeof item === 'number') {
717
- newElem = new ArrayPathElement(lastPathElem, item);
718
- }
719
- else if (typeof item === 'string') {
720
- newElem = new DictPathElement(lastPathElem, item);
721
- }
722
- else {
723
- throw new Error("A path structure must only consist of Ints and Strings, not " + item);
724
- }
725
- pathElements.push(newElem);
726
- lastPathElem = newElem;
727
- });
728
- var lastOne = lastPathElem;
729
- pathElements.push(new PathLeafElement$3(lastOne));
730
- return new Path(pathElements);
388
+ const gtvHash2 = (obj, merkleHashVersion) => {
389
+ return merklehashts.gtvHash(obj, merkleHashVersion);
731
390
  };
732
- var path = { Path, PathElement, PathLeafElement: PathLeafElement$3, ArrayPathElement, SearchablePathElement, DictPathElement, PathSet: PathSet$1,
733
- getTailIfFirstElementIsArrayOfThisIndex, buildPathFromArray };
391
+ const encode$1 = encodeValue;
392
+ const decode$1 = decodeValue;
734
393
 
735
- var PathLeafElement$2 = path.PathLeafElement;
736
- const HASH_PREFIX_NODE$1 = 0;
737
- const HASH_PREFIX_LEAF$1 = 1;
738
- const HASH_PREFIX_NODE_ARRAY$1 = 7;
739
- const HASH_PREFIX_NODE_DICT$1 = 8;
740
- /**
741
- *
742
- */
743
- function BinaryTreeElement() {
744
- this.pathElem = null;
745
- }
746
- BinaryTreeElement.prototype.isPath = function () {
747
- return this.pathElem != null;
748
- };
749
- BinaryTreeElement.prototype.isPathLeaf = function () {
750
- if (this.pathElem == null) {
751
- return false;
752
- }
753
- if (this.pathElem instanceof PathLeafElement$2) {
754
- return true;
755
- }
756
- else {
757
- return false;
758
- }
759
- };
760
- BinaryTreeElement.prototype.setPathElement = function (pathElem) {
761
- this.pathElem = pathElem;
762
- };
763
- BinaryTreeElement.prototype.getPrefixByte = function () {
764
- return HASH_PREFIX_NODE$1;
765
- };
766
- /**
767
- *
768
- * @param {BinaryTreeElement} left
769
- * @param {BinaryTreeElement} right
770
- */
771
- function Node$2(left, right) {
772
- this.left = left;
773
- this.right = right;
774
- }
775
- Node$2.prototype = Object.create(BinaryTreeElement.prototype);
776
- Node$2.prototype.constructor = Node$2;
777
- Node$2.prototype.getPrefixByte = function () {
778
- return HASH_PREFIX_NODE$1;
779
- };
780
- /**
781
- *
782
- * @param {BinaryTreeElement} left
783
- * @param {BinaryTreeElement} right
784
- * @param {*} content
785
- * @param {PathSet} pathElem
786
- */
787
- function SubTreeRootNode$1(left, right, content, pathElem) {
788
- Node$2.call(this, left, right);
789
- this.content = content;
790
- BinaryTreeElement.prototype.setPathElement.call(this, pathElem);
791
- }
792
- SubTreeRootNode$1.prototype = Object.create(Node$2.prototype);
793
- SubTreeRootNode$1.prototype.constructor = SubTreeRootNode$1;
794
- /**
795
- *
796
- * @param {*} content
797
- * @param {PathElement} pathElem
798
- */
799
- function Leaf$2(content, pathElem = null) {
800
- this.content = content;
801
- if (pathElem != null) {
802
- if (pathElem instanceof PathLeafElement$2) {
803
- BinaryTreeElement.prototype.setPathElement.call(this, pathElem);
804
- }
805
- else {
806
- throw new Error("The path and object structure does not match! We are at a leaf, but the path expects a sub structure.");
807
- }
808
- }
809
- }
810
- Leaf$2.prototype = Object.create(BinaryTreeElement.prototype);
811
- Leaf$2.prototype.constructor = Leaf$2;
812
- Leaf$2.prototype.getPrefixByte = function () {
813
- return HASH_PREFIX_LEAF$1;
814
- };
815
- function EmptyLeaf$2() { }
816
- EmptyLeaf$2.prototype = Object.create(BinaryTreeElement.prototype);
817
- EmptyLeaf$2.prototype.constructor = EmptyLeaf$2;
818
- /**
819
- * Wrapper class for the root object.
820
- * @param {BinaryTreeElement} root
821
- */
822
- function BinaryTree$1(root) {
823
- this.root = root;
824
- }
825
- BinaryTree$1.prototype.maxLevel = function () {
826
- return this.maxLevelInternal(this.root);
827
- };
828
- BinaryTree$1.prototype.maxLevelInternal = function (node) {
829
- if (node instanceof EmptyLeaf$2) {
830
- return 0;
831
- }
832
- else if (node instanceof Leaf$2) {
833
- return 1;
834
- }
835
- else if (node instanceof Node$2) {
836
- return Math.max(this.maxLevelInternal(node.left), this.maxLevelInternal(node.right)) + 1;
837
- }
838
- else {
839
- throw new Error("What is this type? " + typeof node);
840
- }
841
- };
842
- /**
843
- * Represents the top of a sub tree generated by a [Array]
844
- *
845
- * @param {*} left
846
- * @param {*} right
847
- * @param {*} content
848
- * @param {*} size
849
- * @param {PathElement} pathElem
850
- */
851
- function ArrayHeadNode$2(left, right, content, size, pathElem = null) {
852
- SubTreeRootNode$1.call(this, left, right, content, pathElem);
853
- this.size = size;
854
- }
855
- ArrayHeadNode$2.prototype = Object.create(SubTreeRootNode$1.prototype);
856
- ArrayHeadNode$2.prototype.constructor = ArrayHeadNode$2;
857
- ArrayHeadNode$2.prototype.getPrefixByte = function () {
858
- return HASH_PREFIX_NODE_ARRAY$1;
859
- };
860
- /**
861
- * Represents the top a sub tree generated by a [Dictionary]
862
- * @param {*} left
863
- * @param {*} right
864
- * @param {*} content
865
- * @param {*} size
866
- * @param {PathElement} pathElem
867
- */
868
- function DictHeadNode$2(left, right, content, size, pathElem = null) {
869
- SubTreeRootNode$1.call(this, left, right, content, pathElem);
870
- this.size = size;
871
- }
872
- DictHeadNode$2.prototype = Object.create(SubTreeRootNode$1.prototype);
873
- DictHeadNode$2.prototype.constructor = DictHeadNode$2;
874
- DictHeadNode$2.prototype.getPrefixByte = function () {
875
- return HASH_PREFIX_NODE_DICT$1;
876
- };
877
- var binarytree = { HASH_PREFIX_NODE: HASH_PREFIX_NODE$1, HASH_PREFIX_LEAF: HASH_PREFIX_LEAF$1, HASH_PREFIX_NODE_ARRAY: HASH_PREFIX_NODE_ARRAY$1, HASH_PREFIX_NODE_DICT: HASH_PREFIX_NODE_DICT$1,
878
- Node: Node$2, Leaf: Leaf$2, EmptyLeaf: EmptyLeaf$2, SubTreeRootNode: SubTreeRootNode$1, BinaryTreeElement, BinaryTree: BinaryTree$1, ArrayHeadNode: ArrayHeadNode$2, DictHeadNode: DictHeadNode$2 };
394
+ var index = /*#__PURE__*/Object.freeze({
395
+ __proto__: null,
396
+ decode: decode$1,
397
+ encode: encode$1,
398
+ gtvHash: gtvHash2
399
+ });
879
400
 
880
401
  class PrivKeyFormatException extends Error {
881
402
  constructor(privKey) {
@@ -988,747 +509,20 @@ function validatePrivKeyFormat(privKey) {
988
509
  }
989
510
  }
990
511
 
991
- var encryption$1 = /*#__PURE__*/Object.freeze({
992
- __proto__: null,
993
- checkDigestSignature: checkDigestSignature,
994
- checkSignature: checkSignature,
995
- createPublicKey: createPublicKey,
996
- hash256: hash256,
997
- hashConcat: hashConcat,
998
- makeKeyPair: makeKeyPair,
999
- makeTuid: makeTuid,
1000
- randomBytes: randomBytes,
1001
- sha256: sha256,
1002
- sign: sign$1,
1003
- signDigest: signDigest,
1004
- verifyKeyPair: verifyKeyPair
1005
- });
1006
-
1007
- var require$$3 = /*@__PURE__*/getAugmentedNamespace(encryption$1);
1008
-
1009
- const { Buffer: Buffer$3 } = require$$0$1;
1010
- var serialization = require$$1;
1011
- var HASH_PREFIX_LEAF = binarytree.HASH_PREFIX_LEAF;
1012
- var encryption = require$$3;
1013
- function CryptoSystem() { }
1014
- CryptoSystem.prototype.digest = function (buffer) {
1015
- return encryption.hash256(buffer);
1016
- };
1017
- /**
1018
- *
1019
- * @param {Buffer} buffer
1020
- * @param {CryptoSystem} cryptoSystem
1021
- */
1022
- function hashingFun(buffer, cryptoSystem) {
1023
- if (cryptoSystem === null) {
1024
- throw new Error("In this case we need the CryptoSystem to calculate the hash");
1025
- }
1026
- else {
1027
- return cryptoSystem.digest(buffer);
1028
- }
1029
- }
1030
- /**
1031
- *
1032
- * @param {CryptoSystem} cryptoSystem
1033
- */
1034
- function MerkleHashCalculator(cryptoSystem) {
1035
- this.cryptoSystem = cryptoSystem;
1036
- }
1037
- /**
1038
- * @param {number} prefix
1039
- * @param {Buffer} hashLeft
1040
- * @param {Buffer} hashRight
1041
- */
1042
- MerkleHashCalculator.prototype.calculateNodeHash = function (prefix, hashLeft, hashRight) {
1043
- return this.calculateNodeHashInternal(prefix, hashLeft, hashRight, hashingFun);
1044
- };
1045
- /**
1046
- * @param {*} value
1047
- */
1048
- MerkleHashCalculator.prototype.calculateLeafHash = function (value, merkleHashVersion) {
1049
- return this.calculateHashOfValueInternal(value, serialization.encodeValue, hashingFun, merkleHashVersion);
1050
- };
1051
- /**
1052
- * @param {number} prefix
1053
- * @param {Buffer} hashLeft
1054
- * @param {Buffer} hashRight
1055
- */
1056
- MerkleHashCalculator.prototype.calculateNodeHashInternal = function (prefix, hashLeft, hashRight, hashFunc) {
1057
- var buf = Buffer$3.alloc(1);
1058
- buf.writeInt8(prefix);
1059
- var bufferSum = Buffer$3.concat([buf, hashLeft, hashRight]);
1060
- return hashFunc(bufferSum, this.cryptoSystem);
1061
- };
1062
- MerkleHashCalculator.prototype.calculateHashOfValueInternal = function (valuetoHash, serializeFun, hashFunc, merkleHashVersion) {
1063
- var buf = Buffer$3.alloc(1);
1064
- buf.writeInt8(HASH_PREFIX_LEAF);
1065
- var bufferSum = Buffer$3.concat([buf, serializeFun(valuetoHash)]);
1066
- return hashFunc(bufferSum, this.cryptoSystem, merkleHashVersion);
1067
- };
1068
- MerkleHashCalculator.prototype.isContainerProofValueLeaf = function (value) {
1069
- if (value == null) {
1070
- return false;
1071
- }
1072
- if (value.constructor === Array || typeof value === 'object') {
1073
- return true;
1074
- }
1075
- else {
1076
- return false;
1077
- }
1078
- };
1079
- var merklehashcalculator = { MerkleHashCalculator, CryptoSystem };
1080
-
1081
- var util = require$$0;
1082
- const { Buffer: Buffer$2 } = require$$0$1;
1083
- var PathSet = path.PathSet;
1084
- var PathLeafElement$1 = path.PathLeafElement;
1085
- var EmptyLeaf$1 = binarytree.EmptyLeaf;
1086
- var Leaf$1 = binarytree.Leaf;
1087
- var Node$1 = binarytree.Node;
1088
- var BinaryTree = binarytree.BinaryTree;
1089
- var ArrayHeadNode$1 = binarytree.ArrayHeadNode;
1090
- var DictHeadNode$1 = binarytree.DictHeadNode;
1091
- const NO_PATHS = new PathSet([]);
1092
- /**
1093
- * The factory does the conversion between list of elements and tree of elements.
1094
- *
1095
- * Note: The idea is that you should sub class for each type of element you want to build.
1096
- */
1097
- function BinaryTreeFactory$1() { }
1098
- /**
1099
- * Transforms the incoming leaf into an [BinaryTreeElement]
1100
- * The idea with this function is that it can be recursive (if the leaf in turn is complex object with sub objects).
1101
- *
1102
- * Note: If we don't have a path here we can try to find the leaf in the cache.
1103
- *
1104
- * @param leaf the raw data we should wrap in a leaf
1105
- * @param paths a collection of proof paths that might point to this leaf
1106
- * @return the resulting [BinaryTreeElement] the leaf got converted to
1107
- */
1108
- BinaryTreeFactory$1.prototype.handleLeaf = function (leaf, paths, isRoot = false, merkleHashVersion) {
1109
- if (merkleHashVersion == undefined || merkleHashVersion == null) {
1110
- console.error("stack trace", new Error().stack);
1111
- throw new Error("Merkle hash version is undefined or null");
1112
- }
1113
- if (paths.length == 0 && !isRoot) {
1114
- return this.innerHandleLeaf(leaf, this.getEmptyPathSet(), merkleHashVersion);
1115
- }
1116
- else {
1117
- return this.innerHandleLeaf(leaf, paths, merkleHashVersion);
1118
- }
1119
- };
1120
- /**
1121
- *
1122
- */
1123
- BinaryTreeFactory$1.prototype.getEmptyPathSet = function () {
1124
- return NO_PATHS;
1125
- };
1126
- /**
1127
- * At this point we should have looked in cache.
1128
- *
1129
- * @param leaf we should turn into a tree element
1130
- * @param {PathSet} paths
1131
- * @return the tree element we created.
1132
- */
1133
- BinaryTreeFactory$1.prototype.innerHandleLeaf = function (leaf, paths, merkleHashVersion) {
1134
- if (leaf == null) {
1135
- return this.handlePrimitiveLeaf(leaf, paths);
1136
- }
1137
- if (Buffer$2.isBuffer(leaf)) {
1138
- return this.handlePrimitiveLeaf(leaf, paths);
1139
- }
1140
- if (typeof leaf === 'string') {
1141
- return this.handlePrimitiveLeaf(leaf, paths);
1142
- }
1143
- if (typeof leaf === 'number') {
1144
- return this.handlePrimitiveLeaf(leaf, paths);
1145
- }
1146
- if (typeof leaf === 'bigint') {
1147
- return this.handlePrimitiveLeaf(leaf, paths);
1148
- }
1149
- if (typeof leaf === 'boolean') {
1150
- return this.handlePrimitiveLeaf(leaf ? 1 : 0, paths);
1151
- }
1152
- if (leaf.constructor === Array) {
1153
- return this.buildFromArray(leaf, paths, merkleHashVersion);
1154
- }
1155
- if (typeof leaf === 'object') {
1156
- return this.buildFromDictionary(leaf, paths, merkleHashVersion);
1157
- }
1158
- else {
1159
- throw new Error("Unsupported data type");
1160
- }
1161
- };
1162
- /**
1163
- * Just like [handleLeaf] but we know that this leaf should not be a complex type, but something we can
1164
- * immediately wrap
1165
- *
1166
- * @param leaf
1167
- * @param {PathSet} paths
1168
- */
1169
- BinaryTreeFactory$1.prototype.handlePrimitiveLeaf = function (leaf, paths) {
1170
- var pathElem = paths.getPathLeafOrElseAnyCurrentPathElement();
1171
- if (pathElem != null && !(pathElem instanceof PathLeafElement$1)) {
1172
- throw new Error("Path does not match the tree structure. We are at a leaf " + leaf + " but found path element " + pathElem);
1173
- }
1174
- return new Leaf$1(leaf, pathElem);
1175
- };
1176
- /**
1177
- * Calls itself until the return value only holds 1 element
1178
- *
1179
- * Note: This method can only create standard [Node] that fills up the area between the "top" and the leaves.
1180
- * These "in-between" nodes cannot be "path leaf" or have any interesting properties.
1181
- *
1182
- * @param layer What layer we aim calculate
1183
- * @param inList The args of nodes we should build from
1184
- * @return All [BinaryTreeElement] nodes of the next layer
1185
- */
1186
- BinaryTreeFactory$1.prototype.buildHigherLayer = function (layer, inList) {
1187
- if (inList.length === 0) {
1188
- throw new Error("Cannot work on empty arrays. Layer: " + layer);
1189
- }
1190
- else if (inList.length === 1) {
1191
- return inList;
1192
- }
1193
- var returnArray = new Array();
1194
- var nrOfNodesToCreate = Math.floor(inList.length / 2);
1195
- var leftValue = null;
1196
- var isLeft = true;
1197
- for (var i = 0; i < inList.length; i++) {
1198
- if (isLeft) {
1199
- leftValue = inList[i];
1200
- isLeft = false;
1201
- }
1202
- else {
1203
- var tempNode = new Node$1(leftValue, inList[i]);
1204
- returnArray.push(tempNode);
1205
- nrOfNodesToCreate--;
1206
- isLeft = true;
1207
- leftValue = null;
1208
- }
1209
- }
1210
- if (!isLeft) {
1211
- // If there is odd number of nodes, then move the last node up one level
1212
- returnArray.push(leftValue);
1213
- }
1214
- // Extra check
1215
- if (nrOfNodesToCreate != 0) {
1216
- util.logDebug("Why didn't we build exactly the correct amount? Layer: " + layer + " , residue: " + nrOfNodesToCreate + " , input args size: " + inList.length + ".");
1217
- }
1218
- return this.buildHigherLayer((layer + 1), returnArray);
1219
- };
1220
- BinaryTreeFactory$1.prototype.build = function (data, merkleHashVersion) {
1221
- return this.buildWithPath(data, NO_PATHS, merkleHashVersion);
1222
- };
1223
- /**
1224
- * @param {PathSet} paths
1225
- */
1226
- BinaryTreeFactory$1.prototype.buildWithPath = function (data, paths, merkleHashVersion) {
1227
- var result = this.handleLeaf(data, paths, true, merkleHashVersion);
1228
- return new BinaryTree(result);
1229
- };
1230
- /**
1231
- * @param {Array} array
1232
- * @param {PathSet} paths
1233
- */
1234
- BinaryTreeFactory$1.prototype.buildFromArray = function (array, paths, merkleHashVersion) {
1235
- if (merkleHashVersion == undefined || merkleHashVersion == null) {
1236
- console.error("stack trace", new Error().stack);
1237
- throw new Error("Merkle hash version is undefined or null");
1238
- }
1239
- var pathElem = paths.getPathLeafOrElseAnyCurrentPathElement();
1240
- // 1. Build leaf layer
1241
- if (array.length == 0) {
1242
- return new ArrayHeadNode$1(new EmptyLeaf$1(), new EmptyLeaf$1(), array, 0, 0, pathElem);
1243
- }
1244
- var leafArray = this.buildLeafElements(array, paths, merkleHashVersion);
1245
- //Merkle hash version 2 and above - check
1246
- if (leafArray.length == 1 && leafArray[0] instanceof Node$1 && merkleHashVersion >= 2) {
1247
- return new ArrayHeadNode$1(leafArray[0], new EmptyLeaf$1(), array, array.length, pathElem);
1248
- }
1249
- // 2. Build all higher layers
1250
- var result = this.buildHigherLayer(1, leafArray);
1251
- // 3. Fix and return the root node
1252
- var orgRoot = result[0];
1253
- if (orgRoot instanceof Node$1) {
1254
- return new ArrayHeadNode$1(orgRoot.left, orgRoot.right, array, array.length, pathElem);
1255
- }
1256
- if (orgRoot instanceof Leaf$1) {
1257
- return this.buildFromOneLeaf(array, orgRoot, pathElem);
1258
- }
1259
- else {
1260
- throw new Error("Should not find element of this type here");
1261
- }
1262
- };
1263
- /**
1264
- *
1265
- */
1266
- BinaryTreeFactory$1.prototype.buildFromOneLeaf = function (array, orgRoot, pathElem) {
1267
- if (array.length > 1) {
1268
- throw new Error("How come we got a leaf returned when we had " + array.length + " elements is the args?");
1269
- }
1270
- else {
1271
- return new ArrayHeadNode$1(orgRoot, new EmptyLeaf$1(), array, array.length, pathElem);
1272
- }
1273
- };
1274
- /**
1275
- * @param {PathSet} paths
1276
- */
1277
- BinaryTreeFactory$1.prototype.buildLeafElements = function (leafList, paths, merkleHashVersion) {
1278
- var leafArray = new Array();
1279
- var onlyArrayPaths = paths.keepOnlyArrayPaths(); // For performance, since we will loop soon
1280
- for (var i = 0; i < leafList.length; i++) {
1281
- var pathsRelevantForThisLeaf = onlyArrayPaths.getTailIfFirstElementIsArrayOfThisIndexFromList(i);
1282
- var leaf = leafList[i];
1283
- var binaryTreeElement = this.handleLeaf(leaf, pathsRelevantForThisLeaf, false, merkleHashVersion);
1284
- leafArray.push(binaryTreeElement);
1285
- }
1286
- return leafArray;
1287
- };
1288
- /**
1289
- * @param {PathSet} paths
1290
- */
1291
- BinaryTreeFactory$1.prototype.buildFromDictionary = function (dict, paths, merkleHashVersion) {
1292
- var pathElem = paths.getPathLeafOrElseAnyCurrentPathElement();
1293
- // Needs to be sorted, or else the order is undefined
1294
- var keys = Object.keys(dict).sort();
1295
- if (keys.length == 0) {
1296
- return new DictHeadNode$1(new EmptyLeaf$1(), new EmptyLeaf$1(), dict, keys.length, 0, pathElem);
1297
- }
1298
- // 1. Build first (leaf) layer
1299
- var leafArray = this.buildLeafElementFromDict(keys, dict, paths, merkleHashVersion);
1300
- // 2. Build all higher layers
1301
- var result = this.buildHigherLayer(1, leafArray);
1302
- // 3. Fix and return the root node
1303
- var orgRoot = result[0];
1304
- if (orgRoot instanceof Node$1) {
1305
- return new DictHeadNode$1(orgRoot.left, orgRoot.right, dict, keys.length, pathElem);
1306
- }
1307
- else {
1308
- throw new Error("Should not find element of this type here: " + typeof orgRoot);
1309
- }
1310
- };
1311
- /**
1312
- * @param {PathSet} paths
1313
- */
1314
- BinaryTreeFactory$1.prototype.buildLeafElementFromDict = function (keys, dict, paths, merkleHashVersion) {
1315
- var leafArray = new Array();
1316
- var onlyDictPaths = paths.keepOnlyDictPaths(); // For performance, since we will loop soon
1317
- for (var i = 0; i < keys.length; i++) {
1318
- // The key cannot not be proved, so NO_PATHS
1319
- var key = keys[i];
1320
- var keyElement = this.handleLeaf(key, NO_PATHS, false, merkleHashVersion);
1321
- leafArray.push(keyElement);
1322
- var content = dict[key];
1323
- var pathsRelevantForThisLeaf = onlyDictPaths.getTailIfFirstElementIsDictOfThisKeyFromList(key);
1324
- var contentElement = this.handleLeaf(content, pathsRelevantForThisLeaf, false, merkleHashVersion);
1325
- leafArray.push(contentElement);
1326
- }
1327
- return leafArray;
1328
- };
1329
- var binarytreefactory = { BinaryTreeFactory: BinaryTreeFactory$1 };
1330
-
1331
- var HASH_PREFIX_NODE = binarytree.HASH_PREFIX_NODE;
1332
- var HASH_PREFIX_NODE_ARRAY = binarytree.HASH_PREFIX_NODE_ARRAY;
1333
- var HASH_PREFIX_NODE_DICT = binarytree.HASH_PREFIX_NODE_DICT;
1334
- /**
1335
- *
1336
- */
1337
- function MerkleProofElement() { }
1338
- /**
1339
- *
1340
- * @param {Buffer} prefix
1341
- * @param {MerkleProofElement} left
1342
- * @param {MerkleProofElement} right
1343
- */
1344
- function ProofNode$1(prefix, left, right) {
1345
- this.prefix = prefix;
1346
- this.left = left;
1347
- this.right = right;
1348
- }
1349
- ProofNode$1.prototype = Object.create(MerkleProofElement.prototype);
1350
- ProofNode$1.prototype.constructor = ProofNode$1;
1351
- /**
1352
- *
1353
- * @param {MerkleProofElement} left
1354
- * @param {MerkleProofElement} right
1355
- */
1356
- function ProofNodeSimple$1(left, right) {
1357
- ProofNode$1.call(this, HASH_PREFIX_NODE, left, right);
1358
- }
1359
- ProofNodeSimple$1.prototype = Object.create(ProofNode$1.prototype);
1360
- ProofNodeSimple$1.prototype.constructor = ProofNodeSimple$1;
1361
- /**
1362
- *
1363
- * @param {*} content
1364
- * @param {SearchablePathElement} pathElem
1365
- */
1366
- function ProofValueLeaf$2(content, pathElem) {
1367
- this.content = content;
1368
- this.pathElem = pathElem;
1369
- }
1370
- ProofValueLeaf$2.prototype = Object.create(MerkleProofElement.prototype);
1371
- ProofValueLeaf$2.prototype.constructor = ProofValueLeaf$2;
1372
- /**
1373
- *
1374
- * @param {Buffer} merkleHash
1375
- */
1376
- function ProofHashedLeaf$2(merkleHash) {
1377
- this.merkleHash = merkleHash;
1378
- }
1379
- ProofHashedLeaf$2.prototype = Object.create(MerkleProofElement.prototype);
1380
- ProofHashedLeaf$2.prototype.constructor = ProofHashedLeaf$2;
1381
- /**
1382
- * @param {ProofHashedLeaf} other
1383
- */
1384
- ProofHashedLeaf$2.prototype.equals = function (other) {
1385
- if (other instanceof ProofHashedLeaf$2) {
1386
- return this.merkleHash.equals(other.merkleHash);
1387
- }
1388
- else {
1389
- return false;
1390
- }
1391
- };
1392
- /**
1393
- *
1394
- * @param {MerkleProofElement} left
1395
- * @param {MerkleProofElement} right
1396
- * @param {SearchablePathElement} pathElem
1397
- */
1398
- function ProofNodeArrayHead$1(left, right, pathElem = null) {
1399
- ProofNode$1.call(this, HASH_PREFIX_NODE_ARRAY, left, right);
1400
- this.pathElem = pathElem;
1401
- }
1402
- ProofNodeArrayHead$1.prototype = Object.create(ProofNode$1.prototype);
1403
- ProofNodeArrayHead$1.prototype.constructor = ProofNodeArrayHead$1;
1404
- /**
1405
- *
1406
- * @param {MerkleProofElement} left
1407
- * @param {MerkleProofElement} right
1408
- * @param {SearchablePathElement} pathElem
1409
- */
1410
- function ProofNodeDictHead$1(left, right, pathElem = null) {
1411
- ProofNode$1.call(this, HASH_PREFIX_NODE_DICT, left, right);
1412
- this.pathElem = pathElem;
1413
- }
1414
- ProofNodeDictHead$1.prototype = Object.create(ProofNode$1.prototype);
1415
- ProofNodeDictHead$1.prototype.constructor = ProofNodeDictHead$1;
1416
- /**
1417
- *
1418
- * @param {MerkleProofElement} root
1419
- */
1420
- function MerkleProofTree$1(root) {
1421
- this.root = root;
1422
- }
1423
- MerkleProofTree$1.prototype.maxLevel = function () {
1424
- return this.maxLevelInternal(this.root);
1425
- };
1426
- /**
1427
- * @param {MerkleProofElement} node
1428
- */
1429
- MerkleProofTree$1.prototype.maxLevelInternal = function (node) {
1430
- if (node instanceof ProofValueLeaf$2) {
1431
- return 1;
1432
- }
1433
- else if (node instanceof ProofHashedLeaf$2) {
1434
- return 1;
1435
- }
1436
- else if (node instanceof ProofNode$1) {
1437
- return Math.max(this.maxLevelInternal(node.left), this.maxLevelInternal(node.right)) + 1;
1438
- }
1439
- else {
1440
- throw new Error("Should be able to handle node type: " + typeof node);
1441
- }
1442
- };
1443
- var merkleprooftree = { ProofNode: ProofNode$1, ProofNodeSimple: ProofNodeSimple$1, ProofHashedLeaf: ProofHashedLeaf$2, ProofValueLeaf: ProofValueLeaf$2,
1444
- ProofNodeArrayHead: ProofNodeArrayHead$1, ProofNodeDictHead: ProofNodeDictHead$1, MerkleProofElement, MerkleProofTree: MerkleProofTree$1 };
1445
-
1446
- const { Buffer: Buffer$1 } = require$$0$1;
1447
- var Node = binarytree.Node;
1448
- var Leaf = binarytree.Leaf;
1449
- var EmptyLeaf = binarytree.EmptyLeaf;
1450
- var ProofHashedLeaf$1 = merkleprooftree.ProofHashedLeaf;
1451
- var ProofValueLeaf$1 = merkleprooftree.ProofValueLeaf;
1452
- var MerkleProofTree = merkleprooftree.MerkleProofTree;
1453
- var ProofNodeArrayHead = merkleprooftree.ProofNodeArrayHead;
1454
- var ProofNodeDictHead = merkleprooftree.ProofNodeDictHead;
1455
- var PathLeafElement = path.PathLeafElement;
1456
- var SubTreeRootNode = binarytree.SubTreeRootNode;
1457
- var ArrayHeadNode = binarytree.ArrayHeadNode;
1458
- var DictHeadNode = binarytree.DictHeadNode;
1459
- var ProofNodeSimple = merkleprooftree.ProofNodeSimple;
1460
- const EMPTY_HASH = new Buffer$1.alloc(32);
1461
- /**
1462
- *
1463
- */
1464
- function MerkleProofTreeFactory$1() { }
1465
- /**
1466
- * @param {BinaryTree} originalTree
1467
- */
1468
- MerkleProofTreeFactory$1.prototype.buildFromBinaryTree = function (originalTree, calculator) {
1469
- var rootElem = this.buildFromBinaryTreeInternal(originalTree.root, calculator);
1470
- return new MerkleProofTree(rootElem);
1471
- };
1472
- /**
1473
- * @param {BinaryTreeElement} elem
1474
- * @param {*} calculator
1475
- */
1476
- MerkleProofTreeFactory$1.prototype.buildFromBinaryTreeInternal = function (elem, calculator) {
1477
- if (elem instanceof EmptyLeaf) {
1478
- return new ProofHashedLeaf$1(EMPTY_HASH);
1479
- }
1480
- else if (elem instanceof Leaf) {
1481
- var pathElem = elem.pathElem;
1482
- if (pathElem != null) {
1483
- if (pathElem instanceof PathLeafElement) {
1484
- return new ProofValueLeaf$1(elem.content, pathElem.previous);
1485
- }
1486
- else {
1487
- throw new Error("The path and structure don't match. We are at a leaf, but path elem is not a leaf: " + pathElem);
1488
- }
1489
- }
1490
- else {
1491
- // make a hash
1492
- var hash = calculator.calculateLeafHash(elem.content);
1493
- return new ProofHashedLeaf$1(hash);
1494
- }
1495
- }
1496
- else if (elem instanceof SubTreeRootNode) {
1497
- var pathElem = elem.pathElem;
1498
- if (pathElem != null) {
1499
- if (pathElem instanceof PathLeafElement) {
1500
- // Don't convert it
1501
- return new ProofValueLeaf$1(elem.content, pathElem.previous);
1502
- }
1503
- else {
1504
- return this.convertNode(elem, calculator);
1505
- }
1506
- }
1507
- else {
1508
- return this.convertNode(elem, calculator);
1509
- }
1510
- }
1511
- else if (elem instanceof Node) {
1512
- return this.convertNode(elem, calculator);
1513
- }
1514
- else {
1515
- throw new Error("Cannot handle " + elem);
1516
- }
1517
- };
1518
- /**
1519
- * @param {Node} node
1520
- */
1521
- MerkleProofTreeFactory$1.prototype.convertNode = function (node, calculator) {
1522
- var left = this.buildFromBinaryTreeInternal(node.left, calculator);
1523
- var right = this.buildFromBinaryTreeInternal(node.right, calculator);
1524
- if (left instanceof ProofHashedLeaf$1 && right instanceof ProofHashedLeaf$1) {
1525
- var addedHash = calculator.calculateNodeHash(node.getPrefixByte(), left.merkleHash, right.merkleHash);
1526
- return new ProofHashedLeaf$1(addedHash);
1527
- }
1528
- else {
1529
- return this.buildNodeOfCorrectType(node, left, right);
1530
- }
1531
- };
1532
- /**
1533
- * @param {ArrayHeadNode} node
1534
- */
1535
- MerkleProofTreeFactory$1.prototype.extractSearchablePathElement = function (node) {
1536
- var pathElem = node.pathElem;
1537
- if (pathElem != null) {
1538
- return pathElem.previous;
1539
- }
1540
- else {
1541
- return null;
1542
- }
1543
- };
1544
- /**
1545
- * @param {Node} node
1546
- * @param {MerkleProofElement} left
1547
- * @param {MerkleProofElement} right
1548
- */
1549
- MerkleProofTreeFactory$1.prototype.buildNodeOfCorrectType = function (node, left, right) {
1550
- if (node instanceof ArrayHeadNode) {
1551
- return new ProofNodeArrayHead(left, right, this.extractSearchablePathElement(node));
1552
- }
1553
- else if (node instanceof DictHeadNode) {
1554
- return new ProofNodeDictHead(left, right, this.extractSearchablePathElement(node));
1555
- }
1556
- else if (node instanceof Node) {
1557
- return new ProofNodeSimple(left, right);
1558
- }
1559
- else {
1560
- throw new Error("Should have taken care of this node type: " + node);
1561
- }
1562
- };
1563
- var merkleprooftreefactory = { MerkleProofTreeFactory: MerkleProofTreeFactory$1 };
1564
-
1565
- /**
1566
- *
1567
- * @param {Buffer} merkleHash
1568
- */
1569
- function MerkleHashSummary$1(merkleHash) {
1570
- this.merkleHash = merkleHash;
1571
- }
1572
- /**
1573
- * @param {MerkleHashSummary} other
1574
- */
1575
- MerkleHashSummary$1.prototype.equals = function (other) {
1576
- if (this === other)
1577
- return true;
1578
- if (typeof this != typeof other)
1579
- return false;
1580
- if (this.merkleHash.compare(other.merkleHash) === 0) {
1581
- return true;
1582
- }
1583
- return false;
1584
- };
1585
- var merklehashcarrier = { MerkleHashSummary: MerkleHashSummary$1 };
1586
-
1587
- var ProofHashedLeaf = merkleprooftree.ProofHashedLeaf;
1588
- var ProofValueLeaf = merkleprooftree.ProofValueLeaf;
1589
- var ProofNode = merkleprooftree.ProofNode;
1590
- var MerkleHashSummary = merklehashcarrier.MerkleHashSummary;
1591
- /**
1592
- *
1593
- * @param {BinaryTreeFactory} treeFactory
1594
- * @param {MerkleProofTreeFactory} proofFactory
1595
- */
1596
- function MerkleHashSummaryFactory$1(treeFactory, proofFactory) {
1597
- this.treeFactory = treeFactory;
1598
- this.proofFactory = proofFactory;
1599
- }
1600
- /**
1601
- * @param {any} value
1602
- * @param {MerkleHashCalculator} calculator
1603
- */
1604
- MerkleHashSummaryFactory$1.prototype.calculateMerkleRoot = function (value, calculator, merkleHashVersion) {
1605
- var binaryTree = this.treeFactory.build(value, merkleHashVersion);
1606
- var proofTree = this.proofFactory.buildFromBinaryTree(binaryTree, calculator);
1607
- return this.calculateMerkleRootOfTree(proofTree, calculator);
1608
- };
1609
- /**
1610
- * @param {MerkleProofTree} value
1611
- * @param {MerkleHashCalculator} calculator
1612
- */
1613
- MerkleHashSummaryFactory$1.prototype.calculateMerkleTreeRoot = function (tree, calculator, merkleHashVersion) {
1614
- return this.calculateMerkleRootOfTree(tree, calculator, merkleHashVersion);
1615
- };
1616
- /**
1617
- * @param {MerkleProofTree} proofTree
1618
- * @param {MerkleHashCalculator} calculator
1619
- */
1620
- MerkleHashSummaryFactory$1.prototype.calculateMerkleRootOfTree = function (proofTree, calculator, merkleHashVersion) {
1621
- var calculatedSummary = this.calculateMerkleRootInternal(proofTree.root, calculator, merkleHashVersion);
1622
- return new MerkleHashSummary(calculatedSummary);
1623
- };
1624
- /**
1625
- * @param {MerkleProofElement} currentElement
1626
- * @param {MerkleHashCalculator} calculator
1627
- */
1628
- MerkleHashSummaryFactory$1.prototype.calculateMerkleRootInternal = function (currentElement, calculator, merkleHashVersion) {
1629
- if (currentElement instanceof ProofHashedLeaf) {
1630
- return currentElement.merkleHash;
1631
- }
1632
- else if (currentElement instanceof ProofValueLeaf) {
1633
- var value = currentElement.content;
1634
- if (calculator.isContainerProofValueLeaf(value)) {
1635
- // We have a container value to prove, so need to convert the value to a binary tree, and THEN hash it
1636
- var merkleProofTree = this.buildProofTree(value, calculator, merkleHashVersion);
1637
- return this.calculateMerkleRootInternal(merkleProofTree.root, calculator, merkleHashVersion);
1638
- }
1639
- else {
1640
- // This is a primitive value, just hash it
1641
- return calculator.calculateLeafHash(value, merkleHashVersion);
1642
- }
1643
- }
1644
- else if (currentElement instanceof ProofNode) {
1645
- var left = this.calculateMerkleRootInternal(currentElement.left, calculator, merkleHashVersion);
1646
- var right = this.calculateMerkleRootInternal(currentElement.right, calculator, merkleHashVersion);
1647
- return calculator.calculateNodeHash(currentElement.prefix, left, right);
1648
- }
1649
- else {
1650
- throw new Error("Should have handled this type? " + typeof currentElement);
1651
- }
1652
- };
1653
- /**
1654
- * @param {any} value
1655
- * @param {MerkleHashCalculator} calculator
1656
- */
1657
- MerkleHashSummaryFactory$1.prototype.buildProofTree = function (value, calculator, merkleHashVersion) {
1658
- var root = this.treeFactory.build(value, merkleHashVersion);
1659
- return this.proofFactory.buildFromBinaryTree(root, calculator);
1660
- };
1661
- var merklehashsummaryfactory = { MerkleHashSummaryFactory: MerkleHashSummaryFactory$1 };
1662
-
1663
- var MerkleHashSummaryFactory = merklehashsummaryfactory.MerkleHashSummaryFactory;
1664
- var BinaryTreeFactory = binarytreefactory.BinaryTreeFactory;
1665
- var MerkleProofTreeFactory = merkleprooftreefactory.MerkleProofTreeFactory;
1666
- var treeFactory = new BinaryTreeFactory();
1667
- var proofFactory = new MerkleProofTreeFactory();
1668
- /**
1669
- * Calculates the merkle root hash of the structure.
1670
- *
1671
- * @param {any} value
1672
- * @param {MerkleHashCalculator} calculator describes the method we use for hashing and serialization
1673
- * @return the merkle root hash (32 bytes) of the data structure.
1674
- */
1675
- function merkleHash(value, calculator, merkleHashVersion) {
1676
- return merkleHashSummary(value, calculator, merkleHashVersion).merkleHash;
1677
- }
1678
- /**
1679
- *
1680
- * @param {MerkleProofTree} tree
1681
- * @param {MerkleHashCalculator} calculator
1682
- */
1683
- function merkleTreeHash(tree, calculator, merkleHashVersion) {
1684
- return merkleProofHashSummary(tree, calculator, merkleHashVersion).merkleHash;
1685
- }
1686
- /**
1687
- * Calculates the merkle root hash of the structure
1688
- *
1689
- * @param {any} value
1690
- * @param {MerkleHashCalculator} calculator describes the method we use for hashing and serialization
1691
- * @return the merkle root hash summary
1692
- */
1693
- function merkleHashSummary(value, calculator, merkleHashVersion) {
1694
- var summaryFactory = new MerkleHashSummaryFactory(treeFactory, proofFactory);
1695
- return summaryFactory.calculateMerkleRoot(value, calculator, merkleHashVersion);
1696
- }
1697
- /**
1698
- *
1699
- * @param {MerkleProofTree} tree
1700
- * @param {MerkleHashCalculator} calculator
1701
- * @param {number} merkleHashVersion
1702
- */
1703
- function merkleProofHashSummary(tree, calculator, merkleHashVersion) {
1704
- var summaryFactory = new MerkleHashSummaryFactory(treeFactory, proofFactory);
1705
- return summaryFactory.calculateMerkleTreeRoot(tree, calculator, merkleHashVersion);
1706
- }
1707
- /**
1708
- *
1709
- * @param {any} value
1710
- * @param {PathSet} pathSet
1711
- * @param {MerkleHashCalculator} calculator
1712
- * @param {number} merkleHashVersion
1713
- */
1714
- function generateProof(value, pathSet, calculator, merkleHashVersion) {
1715
- var binaryTree = treeFactory.buildWithPath(value, pathSet, merkleHashVersion);
1716
- return proofFactory.buildFromBinaryTree(binaryTree, calculator);
1717
- }
1718
- var merkleproof = { merkleHash, merkleTreeHash, merkleHashSummary, generateProof };
1719
-
1720
- const theMerkleHashCalculator = new merklehashcalculator.MerkleHashCalculator(new merklehashcalculator.CryptoSystem());
1721
- const gtvHash = (obj, merkleHashVersion) => {
1722
- return merkleproof.merkleHashSummary(obj, theMerkleHashCalculator, merkleHashVersion).merkleHash;
1723
- };
1724
- const encode$1 = encodeValue;
1725
- const decode$1 = decodeValue;
1726
-
1727
- var index = /*#__PURE__*/Object.freeze({
1728
- __proto__: null,
1729
- decode: decode$1,
1730
- encode: encode$1,
1731
- gtvHash: gtvHash
512
+ var encryption = /*#__PURE__*/Object.freeze({
513
+ __proto__: null,
514
+ checkDigestSignature: checkDigestSignature,
515
+ checkSignature: checkSignature,
516
+ createPublicKey: createPublicKey,
517
+ hash256: hash256,
518
+ hashConcat: hashConcat,
519
+ makeKeyPair: makeKeyPair,
520
+ makeTuid: makeTuid,
521
+ randomBytes: randomBytes,
522
+ sha256: sha256,
523
+ sign: sign$1,
524
+ signDigest: signDigest,
525
+ verifyKeyPair: verifyKeyPair
1732
526
  });
1733
527
 
1734
528
  const encode = encodeValueGtx;
@@ -1776,17 +570,17 @@ function addSignerToGtx(signer, gtx) {
1776
570
  * @param gtx the gtx to serialize
1777
571
  */
1778
572
  function getDigest(gtx, merkleHashVersion) {
1779
- return gtvHash(gtxToRawGtxBody(gtx), merkleHashVersion);
573
+ return gtvHash2(gtxToRawGtxBody(gtx), merkleHashVersion);
1780
574
  }
1781
575
  /**
1782
576
  * Serializes the gtx for signing
1783
577
  * @param gtx the gtx to serialize
1784
578
  */
1785
579
  function getDigestToSign(gtx, merkleHashVersion) {
1786
- return gtvHash(gtxToRawGtxBody(gtx), merkleHashVersion);
580
+ return gtvHash2(gtxToRawGtxBody(gtx), merkleHashVersion);
1787
581
  }
1788
582
  function getDigestToSignFromRawGtxBody(gtxBody, merkleHashVersion) {
1789
- return gtvHash(gtxBody, merkleHashVersion);
583
+ return gtvHash2(gtxBody, merkleHashVersion);
1790
584
  }
1791
585
  function gtxToRawGtxBody(gtx) {
1792
586
  return [
@@ -1962,23 +756,23 @@ function rawGtvToRellOp(gtv) {
1962
756
  }
1963
757
 
1964
758
  var gtx = /*#__PURE__*/Object.freeze({
1965
- __proto__: null,
1966
- addSignature: addSignature,
1967
- addSignerToGtx: addSignerToGtx,
1968
- addTransactionToGtx: addTransactionToGtx,
1969
- checkExistingGTXSignatures: checkExistingGTXSignatures,
1970
- checkGTXSignatures: checkGTXSignatures,
1971
- deserialize: deserialize,
1972
- emptyGtx: emptyGtx,
1973
- getDigest: getDigest,
1974
- getDigestToSign: getDigestToSign,
1975
- getDigestToSignFromRawGtxBody: getDigestToSignFromRawGtxBody,
1976
- gtxToRawGtx: gtxToRawGtx,
1977
- gtxToRawGtxBody: gtxToRawGtxBody,
1978
- newSignatureProvider: newSignatureProvider,
1979
- rawGtvToGtx: rawGtvToGtx,
1980
- serialize: serialize,
1981
- sign: sign
759
+ __proto__: null,
760
+ addSignature: addSignature,
761
+ addSignerToGtx: addSignerToGtx,
762
+ addTransactionToGtx: addTransactionToGtx,
763
+ checkExistingGTXSignatures: checkExistingGTXSignatures,
764
+ checkGTXSignatures: checkGTXSignatures,
765
+ deserialize: deserialize,
766
+ emptyGtx: emptyGtx,
767
+ getDigest: getDigest,
768
+ getDigestToSign: getDigestToSign,
769
+ getDigestToSignFromRawGtxBody: getDigestToSignFromRawGtxBody,
770
+ gtxToRawGtx: gtxToRawGtx,
771
+ gtxToRawGtxBody: gtxToRawGtxBody,
772
+ newSignatureProvider: newSignatureProvider,
773
+ rawGtvToGtx: rawGtvToGtx,
774
+ serialize: serialize,
775
+ sign: sign
1982
776
  });
1983
777
 
1984
778
  var _a$1;
@@ -2084,129 +878,15 @@ function logger(moduleName) {
2084
878
  }
2085
879
 
2086
880
  var logger$1 = /*#__PURE__*/Object.freeze({
2087
- __proto__: null,
2088
- get LogLevel () { return LogLevel; },
2089
- debug: debug,
2090
- error: error,
2091
- getLogLevel: getLogLevel,
2092
- info: info,
2093
- logger: logger,
2094
- setLogLevel: setLogLevel,
2095
- warning: warning
2096
- });
2097
-
2098
- var internalNodePrefix = Buffer.alloc(1, 0);
2099
- var leafPrefix = Buffer.alloc(1, 1);
2100
- var nonExistingNodeHash = Buffer.alloc(32);
2101
- function calculateRoot(hashes, depth, leafDepth) {
2102
- var numTransactions = hashes.length;
2103
- if (numTransactions === 0) {
2104
- return Buffer.alloc(32);
2105
- }
2106
- if (depth === undefined) {
2107
- depth = 0;
2108
- }
2109
- if (!leafDepth) {
2110
- leafDepth = Math.ceil(Math.log2(numTransactions));
2111
- }
2112
- if (depth === leafDepth) {
2113
- return hashes[0];
2114
- }
2115
- var maxLeavesPerChild = Math.pow(2, leafDepth - depth - 1);
2116
- var prefix = depth === leafDepth - 1 ? leafPrefix : internalNodePrefix;
2117
- if (numTransactions <= maxLeavesPerChild) {
2118
- var left = calculateRoot(hashes, depth + 1, leafDepth);
2119
- return hashConcat([prefix, left, nonExistingNodeHash]);
2120
- }
2121
- var left = calculateRoot(hashes.slice(0, maxLeavesPerChild), depth + 1, leafDepth);
2122
- var right = calculateRoot(hashes.slice(maxLeavesPerChild), depth + 1, leafDepth);
2123
- return hashConcat([prefix, left, prefix, right]);
2124
- }
2125
- function internalMerklePath(hashes, targetIndex, depth, leafDepth) {
2126
- var numTransactions = hashes.length;
2127
- if (depth === leafDepth) {
2128
- return [];
2129
- }
2130
- var maxLeavesPerChild = Math.pow(2, leafDepth - depth - 1);
2131
- if (numTransactions <= maxLeavesPerChild) {
2132
- var path = internalMerklePath(hashes, targetIndex, depth + 1, leafDepth);
2133
- path.push({ side: 1, hash: nonExistingNodeHash });
2134
- return path;
2135
- }
2136
- if (targetIndex < maxLeavesPerChild) {
2137
- var path = internalMerklePath(hashes.slice(0, maxLeavesPerChild), targetIndex, depth + 1, leafDepth);
2138
- var right = calculateRoot(hashes.slice(maxLeavesPerChild), depth + 1, leafDepth);
2139
- path.push({ side: 1, hash: right });
2140
- }
2141
- else {
2142
- var left = calculateRoot(hashes.slice(0, maxLeavesPerChild), depth + 1, leafDepth);
2143
- var path = internalMerklePath(hashes.slice(maxLeavesPerChild), targetIndex - maxLeavesPerChild, depth + 1, leafDepth);
2144
- path.push({ side: 0, hash: left });
2145
- }
2146
- return path;
2147
- }
2148
- /*
2149
- * a path looks like this:
2150
- * {merklePath: [{side: <0|1>, hash: <hash buffer depth n-1>},
2151
- * {side: <0|1>, hash: <hash buffer depth n-2>},
2152
- * ...
2153
- * {side: <0|1>, hash: <hash buffer depth 1>}]}
2154
- */
2155
- function merklePath(hashes, target) {
2156
- if (!hashes || hashes.length == 0) {
2157
- throw new Error("Cannot make merkle path from empty transaction set");
2158
- }
2159
- var index = -1;
2160
- for (var i = 0; i < hashes.length; i++) {
2161
- if (hashes[i].equals(target)) {
2162
- index = i;
2163
- break;
2164
- }
2165
- }
2166
- if (index === -1) {
2167
- throw new Error("Target is not in list of hashes");
2168
- }
2169
- var leafDepth = Math.ceil(Math.log2(hashes.length));
2170
- var path = internalMerklePath(hashes, index, 0, leafDepth);
2171
- return path;
2172
- }
2173
- /**
2174
- *
2175
- * @param path The merkle path to validate.
2176
- * Format [{side: <0|1>, hash: <hash buffer depth n-1>},
2177
- * {side: <0|1>, hash: <hash buffer depth n-2>},
2178
- * ...,
2179
- * {side: <0|1>, hash: <hash buffer depth 1>}]
2180
-
2181
- * @param target the leaf hash that the path proves belongs in the merkleRoot
2182
- * @param merkleRoot The merkle root that supposedly contains the target via the supplied path.
2183
- * The merkle root is typically taken from a block header.
2184
- */
2185
- function validateMerklePath(path, target, merkleRoot) {
2186
- let currentHash = target;
2187
- for (let i = 0; i < path.length; i++) {
2188
- const item = path[i];
2189
- const prefix = (i === 0) ? Buffer.from([1]) : Buffer.from([0]);
2190
- if (item.side === 0) {
2191
- currentHash = hashConcat([prefix, item.hash, prefix, currentHash]);
2192
- }
2193
- else {
2194
- if (item.hash.equals(nonExistingNodeHash)) {
2195
- currentHash = hashConcat([prefix, currentHash, nonExistingNodeHash]);
2196
- }
2197
- else {
2198
- currentHash = hashConcat([prefix, currentHash, prefix, item.hash]);
2199
- }
2200
- }
2201
- }
2202
- return merkleRoot.equals(currentHash);
2203
- }
2204
-
2205
- var merkleHelper = /*#__PURE__*/Object.freeze({
2206
- __proto__: null,
2207
- calculateRoot: calculateRoot,
2208
- merklePath: merklePath,
2209
- validateMerklePath: validateMerklePath
881
+ __proto__: null,
882
+ get LogLevel () { return LogLevel; },
883
+ debug: debug,
884
+ error: error,
885
+ getLogLevel: getLogLevel,
886
+ info: info,
887
+ logger: logger,
888
+ setLogLevel: setLogLevel,
889
+ warning: warning
2210
890
  });
2211
891
 
2212
892
  class MissingPubKeyError extends CustomError {
@@ -2347,6 +1027,8 @@ const createNodeManager = ({ nodeUrls, useStickyNode = false, unavailableDuratio
2347
1027
  return {
2348
1028
  nodes,
2349
1029
  stickedNode: null,
1030
+ useStickyNode: useStickyNode,
1031
+ lastUsedNode: null,
2350
1032
  getAvailableNodes() {
2351
1033
  const shuffledAvailableNodes = shuffleArray(this.nodes.filter((node) => node.isAvailable));
2352
1034
  // set sticky node as the first node, and then shuffle the rest
@@ -2359,6 +1041,9 @@ const createNodeManager = ({ nodeUrls, useStickyNode = false, unavailableDuratio
2359
1041
  setStickyNode(node) {
2360
1042
  this.stickedNode = node;
2361
1043
  },
1044
+ setUseStickyNode(useSticky) {
1045
+ this.useStickyNode = useSticky;
1046
+ },
2362
1047
  getNode() {
2363
1048
  const nodes = this.getAvailableNodes();
2364
1049
  if (nodes.length === 0) {
@@ -2366,6 +1051,7 @@ const createNodeManager = ({ nodeUrls, useStickyNode = false, unavailableDuratio
2366
1051
  }
2367
1052
  const index = Math.floor(Math.random() * nodes.length);
2368
1053
  const node = nodes[index];
1054
+ this.lastUsedNode = node;
2369
1055
  if (!useStickyNode) {
2370
1056
  return node;
2371
1057
  }
@@ -2373,6 +1059,7 @@ const createNodeManager = ({ nodeUrls, useStickyNode = false, unavailableDuratio
2373
1059
  this.setStickyNode(node);
2374
1060
  return node;
2375
1061
  }
1062
+ this.lastUsedNode = this.stickedNode;
2376
1063
  return this.stickedNode;
2377
1064
  },
2378
1065
  makeAllNodesAvailable() {
@@ -2913,7 +1600,8 @@ function retryRequest({ method, path, config, postObject, validateStatusCode, })
2913
1600
  return { error, statusCode, rspBody, transactionTimestamp };
2914
1601
  }
2915
1602
  if (isServerError) {
2916
- nodeManager.makeNodeUnavailable(endpoint.url);
1603
+ // nodeManager.makeNodeUnavailable(endpoint.url);
1604
+ info(`server error on ${endpoint.url}`);
2917
1605
  }
2918
1606
  info(`${method} request failed on ${endpoint.url}. Attempt: ${attempt + 1} / ${config.attemptsPerEndpoint}`);
2919
1607
  yield sleep(config.attemptInterval);
@@ -3390,12 +2078,14 @@ function awaitClusterAnchoringChainConfirmation(txRID, clusterAnchoringStatusPol
3390
2078
  return clusterAnchoringConfirmation;
3391
2079
  });
3392
2080
  }
3393
- function handleDappConfirmations(transactionRid, doStatusPolling, confirmationLevel, promiEvent, dappStatusPolling, getTransactionStatus) {
2081
+ function handleDappConfirmations(transactionRid, doStatusPolling, confirmationLevel, promiEvent, dappStatusPolling, getTransactionStatus, client) {
2082
+ var _a, _b;
3394
2083
  return __awaiter$5(this, void 0, void 0, function* () {
3395
2084
  const transactionReceipt = {
3396
2085
  status: exports.ResponseStatus.Pending,
3397
2086
  statusCode: null,
3398
2087
  transactionRid: transactionRid,
2088
+ node: (_a = client.config.nodeManager.lastUsedNode) === null || _a === void 0 ? void 0 : _a.url,
3399
2089
  };
3400
2090
  promiEvent.emit(exports.TransactionEvent.DappReceived, transactionReceipt);
3401
2091
  if (doStatusPolling === false || confirmationLevel === exports.ChainConfirmationLevel.None) {
@@ -3404,6 +2094,7 @@ function handleDappConfirmations(transactionRid, doStatusPolling, confirmationLe
3404
2094
  const dappConfirmationStatus = yield awaitDappConfirmation(transactionRid, dappStatusPolling, getTransactionStatus);
3405
2095
  transactionReceipt.statusCode = dappConfirmationStatus.statusCode;
3406
2096
  transactionReceipt.status = dappConfirmationStatus.status;
2097
+ transactionReceipt.node = (_b = client.config.nodeManager.lastUsedNode) === null || _b === void 0 ? void 0 : _b.url;
3407
2098
  promiEvent.emit(exports.TransactionEvent.DappConfirmed, transactionReceipt);
3408
2099
  if (confirmationLevel === exports.ChainConfirmationLevel.Dapp) {
3409
2100
  return transactionReceipt;
@@ -3457,6 +2148,16 @@ function getSystemAnchoringTransaction(dappClientEndpointPool, anchoredTxRid, an
3457
2148
  return systemAnchoringTransactionValidation.data;
3458
2149
  });
3459
2150
  }
2151
+ /**
2152
+ * Should be used to configure the `IClient` `ClientConfig` (config) properties
2153
+ * `dappStatusPolling`, `clusterAnchoringStatusPolling` and `systemAnchoringStatusPolling` with
2154
+ * the corresponding status polling configuration `interval` and `status`.
2155
+ * If the values are not provided, they do default to `500` for `interval` and `20` for `count`
2156
+ *
2157
+ * @param statusPolling - An optional partial configuration object, that can set the status polling interval and count properties
2158
+ * @returns - Returns a complete `StatusPolling` configuration object, with default values for any missing properties
2159
+ * of the provided partial configuration
2160
+ */
3460
2161
  function setStatusPolling(statusPolling) {
3461
2162
  var _a, _b;
3462
2163
  return {
@@ -3654,7 +2355,7 @@ function calculateBlockRID(decodedTxProof, merkleHashVersion) {
3654
2355
  throw new Error("Failed to get blockHeader from confirmation proof");
3655
2356
  }
3656
2357
  const decodeSourceBlockRid = decodeValue(sourceBlockHeader);
3657
- return gtvHash(decodeSourceBlockRid, merkleHashVersion);
2358
+ return gtvHash2(decodeSourceBlockRid, merkleHashVersion);
3658
2359
  }
3659
2360
  // fetch tx from txRID and verifies with secp256k1.ecdsaVerify that txRID and signer creates signatures that are on the blockchain transaction
3660
2361
  function fetchAndVerifyTransaction(sourceClient, txToProveRID, proofHash, txToProveSigners) {
@@ -3662,7 +2363,7 @@ function fetchAndVerifyTransaction(sourceClient, txToProveRID, proofHash, txToPr
3662
2363
  return __awaiter$4(this, void 0, void 0, function* () {
3663
2364
  const rawTx = yield sourceClient.getTransaction(txToProveRID);
3664
2365
  const txGtv = decodeValue(rawTx);
3665
- const fetchedTxHash = gtvHash(txGtv, sourceClient.config.merkleHashVersion);
2366
+ const fetchedTxHash = gtvHash2(txGtv, sourceClient.config.merkleHashVersion);
3666
2367
  if (Buffer.compare(fetchedTxHash, proofHash)) {
3667
2368
  // We received another hash for tx RID than what was included in proof
3668
2369
  // Possibly rouge or faulty node(s). Anyway, we need to give up.
@@ -3726,7 +2427,7 @@ var __awaiter$3 = (undefined && undefined.__awaiter) || function (thisArg, _argu
3726
2427
  * This function generates a proof that a specific transaction has occurred on the source blockchain
3727
2428
  * and constructs an ICCF proof transaction that can be posted to the target blockchain.
3728
2429
  *
3729
- * @param {IClient} client - The client configured to communicate with the management chain.
2430
+ * @param {IClient} directoryClient - The client configured to communicate with the management chain.
3730
2431
  * @param {BufferId} txToProveRid - The RID of the transaction to be proven.
3731
2432
  * @param {Buffer} txToProveHash - The hash of the transaction to be proven.
3732
2433
  * @param {PubKey[]} txToProveSigners - An array of public keys representing signers of the transaction to be proven.
@@ -3735,15 +2436,28 @@ var __awaiter$3 = (undefined && undefined.__awaiter) || function (thisArg, _argu
3735
2436
  * @param {PubKey[]} iccfTxSigners - An array of public keys representing signers of the ICCF proof transaction (optional, default: []).
3736
2437
  * @param {boolean} forceIntraNetworkIccfOperation - Whether to force the ICCF operation to be performed within the same network (optional, default: false).
3737
2438
  * @param {number} merkleHashVersion - The version of the merkle hash to use.
2439
+ * @param {string} nodeIdentifierURL - The URL of the node to use.
3738
2440
  * @returns {Promise<IccfProof>} A promise that resolves to an ICCF proof object containing the ICCF proof transaction.
3739
2441
  */
3740
- function createIccfProofTx(client, txToProveRid, txToProveHash, txToProveSigners, sourceBlockchainRid, targetBlockchainRid, iccfTxSigners = [], forceIntraNetworkIccfOperation = false, merkleHashVersion) {
2442
+ function createIccfProofTx(directoryClient, txToProveRid, txToProveHash, txToProveSigners, sourceBlockchainRid, targetBlockchainRid, iccfTxSigners = [], forceIntraNetworkIccfOperation = false, merkleHashVersion, nodeIdentifierURL) {
3741
2443
  return __awaiter$3(this, void 0, void 0, function* () {
3742
- const clientConfiguredToSource = yield createClient({
3743
- directoryNodeUrlPool: getUrlsFromEndpoints(client.config.endpointPool),
3744
- blockchainRid: ensureString(sourceBlockchainRid),
3745
- merkleHashVersion: merkleHashVersion,
3746
- });
2444
+ let clientConfiguredToSource;
2445
+ if (!nodeIdentifierURL) {
2446
+ clientConfiguredToSource = yield createClient({
2447
+ directoryNodeUrlPool: getUrlsFromEndpoints(directoryClient.config.endpointPool),
2448
+ blockchainRid: ensureString(sourceBlockchainRid),
2449
+ merkleHashVersion: merkleHashVersion,
2450
+ useStickyNode: true,
2451
+ });
2452
+ }
2453
+ else {
2454
+ clientConfiguredToSource = yield createClient({
2455
+ nodeUrlPool: nodeIdentifierURL,
2456
+ blockchainRid: ensureString(sourceBlockchainRid),
2457
+ merkleHashVersion: merkleHashVersion,
2458
+ useStickyNode: true,
2459
+ });
2460
+ }
3747
2461
  const txProof = yield clientConfiguredToSource.getConfirmationProof(txToProveRid);
3748
2462
  if (!txProof || !txProof.hash) {
3749
2463
  throw new ConfirmationProofException(txToProveRid);
@@ -3752,8 +2466,8 @@ function createIccfProofTx(client, txToProveRid, txToProveHash, txToProveSigners
3752
2466
  const { verifiedTx, verifiedTxHash } = !txToProveHash.equals(proofHash)
3753
2467
  ? yield fetchAndVerifyTransaction(clientConfiguredToSource, txToProveRid, proofHash, txToProveSigners)
3754
2468
  : { verifiedTx: null, verifiedTxHash: txToProveHash };
3755
- const sourceCluster = yield getClusterOfBlockchain(client, ensureBuffer(sourceBlockchainRid));
3756
- const targetCluster = yield getClusterOfBlockchain(client, ensureBuffer(targetBlockchainRid));
2469
+ const sourceCluster = yield getClusterOfBlockchain(directoryClient, ensureBuffer(sourceBlockchainRid));
2470
+ const targetCluster = yield getClusterOfBlockchain(directoryClient, ensureBuffer(targetBlockchainRid));
3757
2471
  if (!forceIntraNetworkIccfOperation && sourceCluster === targetCluster) {
3758
2472
  // intra-cluster
3759
2473
  const intraClusterProofTx = composeProofTransactionObject(sourceBlockchainRid, verifiedTxHash, txProof, iccfTxSigners, undefined, undefined, false);
@@ -3761,7 +2475,7 @@ function createIccfProofTx(client, txToProveRid, txToProveHash, txToProveSigners
3761
2475
  }
3762
2476
  else {
3763
2477
  // intra-network
3764
- const systemClientUsingStickyNode = Object.assign(Object.assign({}, client), { config: Object.assign(Object.assign({}, client.config), { failoverStrategy: exports.FailoverStrategy.SingleEndpoint }) });
2478
+ const systemClientUsingStickyNode = Object.assign(Object.assign({}, directoryClient), { config: Object.assign(Object.assign({}, directoryClient.config), { failoverStrategy: exports.FailoverStrategy.SingleEndpoint }) });
3765
2479
  const anchoringClient = yield getAnchoringClient(systemClientUsingStickyNode, sourceBlockchainRid, sourceCluster);
3766
2480
  const clusterAnchoredTx = yield getBlockAnchoringTransaction(clientConfiguredToSource, anchoringClient, undefined, txProof);
3767
2481
  if (!clusterAnchoredTx) {
@@ -4194,7 +2908,7 @@ function createClient(settings) {
4194
2908
  },
4195
2909
  sendTransaction(transaction, doStatusPolling = true, callback, confirmationLevel = exports.ChainConfirmationLevel.Dapp) {
4196
2910
  const promiEvent = new Web3PromiEvent((resolve, reject) => __awaiter$1(this, void 0, void 0, function* () {
4197
- var _a;
2911
+ var _a, _b;
4198
2912
  try {
4199
2913
  const gtx$1 = getGTXFromBufferOrTransactionOrOperation(transaction, config.blockchainRid);
4200
2914
  if (gtx$1.signers.length !== ((_a = gtx$1.signatures) === null || _a === void 0 ? void 0 : _a.length)) {
@@ -4210,6 +2924,7 @@ function createClient(settings) {
4210
2924
  status: exports.ResponseStatus.Waiting,
4211
2925
  statusCode,
4212
2926
  transactionRid: transactionRid,
2927
+ node: (_b = config.nodeManager.lastUsedNode) === null || _b === void 0 ? void 0 : _b.url,
4213
2928
  });
4214
2929
  }
4215
2930
  }
@@ -4225,7 +2940,7 @@ function createClient(settings) {
4225
2940
  clusterAnchoringStatusPolling: client.config.clusterAnchoringStatusPolling,
4226
2941
  systemAnchoringStatusPolling: client.config.systemAnchoringStatusPolling,
4227
2942
  };
4228
- let transactionReceipt = yield handleDappConfirmations(transactionRid, doStatusPolling, confirmationLevel, promiEvent, statusPollingConfig.dappStatusPolling, () => client.getTransactionStatus(transactionRid, callback));
2943
+ let transactionReceipt = yield handleDappConfirmations(transactionRid, doStatusPolling, confirmationLevel, promiEvent, statusPollingConfig.dappStatusPolling, () => client.getTransactionStatus(transactionRid, callback), client);
4229
2944
  if (confirmationLevel === exports.ChainConfirmationLevel.None ||
4230
2945
  confirmationLevel === exports.ChainConfirmationLevel.Dapp) {
4231
2946
  resolve(transactionReceipt);
@@ -4370,6 +3085,7 @@ function createClient(settings) {
4370
3085
  });
4371
3086
  },
4372
3087
  getTransactionConfirmationLevel(transactionRid, callback) {
3088
+ var _a;
4373
3089
  return __awaiter$1(this, void 0, void 0, function* () {
4374
3090
  try {
4375
3091
  const client = this;
@@ -4378,6 +3094,7 @@ function createClient(settings) {
4378
3094
  status: dappConfirmation.status,
4379
3095
  statusCode: dappConfirmation.statusCode,
4380
3096
  transactionRid: ensureBuffer(transactionRid),
3097
+ node: (_a = client.config.nodeManager.lastUsedNode) === null || _a === void 0 ? void 0 : _a.url,
4381
3098
  };
4382
3099
  if (dappConfirmation.status === exports.ResponseStatus.Waiting) {
4383
3100
  return response;
@@ -4456,7 +3173,7 @@ function createClient(settings) {
4456
3173
  });
4457
3174
  });
4458
3175
  },
4459
- getBlocks({ limit, beforeTime, afterTime, beforeHeight, afterHeight, txs, callback, } = {}) {
3176
+ getBlocks({ limit, beforeTime, afterTime, beforeHeight, afterHeight, excludeEmpty, txs, callback, } = {}) {
4460
3177
  return __awaiter$1(this, void 0, void 0, function* () {
4461
3178
  const searchValues = {
4462
3179
  limit,
@@ -4465,6 +3182,7 @@ function createClient(settings) {
4465
3182
  "after-time": afterTime,
4466
3183
  "before-height": beforeHeight,
4467
3184
  "after-height": afterHeight,
3185
+ "exclude-empty": excludeEmpty,
4468
3186
  };
4469
3187
  const searchParams = new URLSearchParams();
4470
3188
  for (const [key, value] of Object.entries(searchValues)) {
@@ -4879,7 +3597,7 @@ exports.decodeTransactionToGtx = decodeTransactionToGtx;
4879
3597
  exports.dumpGtv = dumpGtv;
4880
3598
  exports.dumpGtx = dumpGtx;
4881
3599
  exports.encodeTransaction = encodeTransaction;
4882
- exports.encryption = encryption$1;
3600
+ exports.encryption = encryption;
4883
3601
  exports.formatter = formatter;
4884
3602
  exports.getAnchoringClient = getAnchoringClient;
4885
3603
  exports.getAnchoringClientAndSystemChainRid = getAnchoringClientAndSystemChainRid;
@@ -4907,7 +3625,6 @@ exports.isTransactionInfoResponse = isTransactionInfoResponse;
4907
3625
  exports.isTransactionInfoResponseArray = isTransactionInfoResponseArray;
4908
3626
  exports.isTransactionsCount = isTransactionsCount;
4909
3627
  exports.logger = logger$1;
4910
- exports.merkle = merkleHelper;
4911
3628
  exports.newSignatureProvider = newSignatureProvider;
4912
3629
  exports.requestWithFailoverStrategy = requestWithFailoverStrategy;
4913
3630
  exports.setStatusPolling = setStatusPolling;