You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

LeafNode.js 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. "use strict";
  2. var __importDefault = (this && this.__importDefault) || function (mod) {
  3. return (mod && mod.__esModule) ? mod : { "default": mod };
  4. };
  5. Object.defineProperty(exports, "__esModule", { value: true });
  6. const errors_1 = require("../../../errors");
  7. const HashPrefix_1 = __importDefault(require("../HashPrefix"));
  8. const sha512Half_1 = __importDefault(require("../sha512Half"));
  9. const node_1 = require("./node");
  10. const HEX = 16;
  11. class LeafNode extends node_1.Node {
  12. constructor(tag, data, type) {
  13. super();
  14. this.tag = tag;
  15. this.type = type;
  16. this.data = data;
  17. }
  18. get hash() {
  19. switch (this.type) {
  20. case node_1.NodeType.ACCOUNT_STATE: {
  21. const leafPrefix = HashPrefix_1.default.LEAF_NODE.toString(HEX);
  22. return (0, sha512Half_1.default)(leafPrefix + this.data + this.tag);
  23. }
  24. case node_1.NodeType.TRANSACTION_NO_METADATA: {
  25. const txIDPrefix = HashPrefix_1.default.TRANSACTION_ID.toString(HEX);
  26. return (0, sha512Half_1.default)(txIDPrefix + this.data);
  27. }
  28. case node_1.NodeType.TRANSACTION_METADATA: {
  29. const txNodePrefix = HashPrefix_1.default.TRANSACTION_NODE.toString(HEX);
  30. return (0, sha512Half_1.default)(txNodePrefix + this.data + this.tag);
  31. }
  32. default:
  33. throw new errors_1.XrplError('Tried to hash a SHAMap node of unknown type.');
  34. }
  35. }
  36. addItem(tag, node) {
  37. throw new errors_1.XrplError('Cannot call addItem on a LeafNode');
  38. this.addItem(tag, node);
  39. }
  40. }
  41. exports.default = LeafNode;
  42. //# sourceMappingURL=LeafNode.js.map