您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

index.js 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. "use strict";
  2. var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
  3. if (k2 === undefined) k2 = k;
  4. var desc = Object.getOwnPropertyDescriptor(m, k);
  5. if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
  6. desc = { enumerable: true, get: function() { return m[k]; } };
  7. }
  8. Object.defineProperty(o, k2, desc);
  9. }) : (function(o, m, k, k2) {
  10. if (k2 === undefined) k2 = k;
  11. o[k2] = m[k];
  12. }));
  13. var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
  14. Object.defineProperty(o, "default", { enumerable: true, value: v });
  15. }) : function(o, v) {
  16. o["default"] = v;
  17. });
  18. var __importStar = (this && this.__importStar) || function (mod) {
  19. if (mod && mod.__esModule) return mod;
  20. var result = {};
  21. if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
  22. __setModuleDefault(result, mod);
  23. return result;
  24. };
  25. Object.defineProperty(exports, "__esModule", { value: true });
  26. exports.TRANSACTION_TYPES = exports.decodeLedgerData = exports.decodeQuality = exports.encodeQuality = exports.encodeForMultisigning = exports.encodeForSigningClaim = exports.encodeForSigning = exports.encode = exports.decode = void 0;
  27. const assert = __importStar(require("assert"));
  28. const coretypes_1 = require("./coretypes");
  29. const ledger_hashes_1 = require("./ledger-hashes");
  30. Object.defineProperty(exports, "decodeLedgerData", { enumerable: true, get: function () { return ledger_hashes_1.decodeLedgerData; } });
  31. const enums_1 = require("./enums");
  32. Object.defineProperty(exports, "TRANSACTION_TYPES", { enumerable: true, get: function () { return enums_1.TRANSACTION_TYPES; } });
  33. const { signingData, signingClaimData, multiSigningData, binaryToJSON, serializeObject, } = coretypes_1.binary;
  34. /**
  35. * Decode a transaction
  36. *
  37. * @param binary hex-string of the encoded transaction
  38. * @returns the JSON representation of the transaction
  39. */
  40. function decode(binary) {
  41. assert.ok(typeof binary === 'string', 'binary must be a hex string');
  42. return binaryToJSON(binary);
  43. }
  44. exports.decode = decode;
  45. /**
  46. * Encode a transaction
  47. *
  48. * @param json The JSON representation of a transaction
  49. * @returns A hex-string of the encoded transaction
  50. */
  51. function encode(json) {
  52. assert.ok(typeof json === 'object');
  53. return serializeObject(json)
  54. .toString('hex')
  55. .toUpperCase();
  56. }
  57. exports.encode = encode;
  58. /**
  59. * Encode a transaction and prepare for signing
  60. *
  61. * @param json JSON object representing the transaction
  62. * @param signer string representing the account to sign the transaction with
  63. * @returns a hex string of the encoded transaction
  64. */
  65. function encodeForSigning(json) {
  66. assert.ok(typeof json === 'object');
  67. return signingData(json)
  68. .toString('hex')
  69. .toUpperCase();
  70. }
  71. exports.encodeForSigning = encodeForSigning;
  72. /**
  73. * Encode a transaction and prepare for signing with a claim
  74. *
  75. * @param json JSON object representing the transaction
  76. * @param signer string representing the account to sign the transaction with
  77. * @returns a hex string of the encoded transaction
  78. */
  79. function encodeForSigningClaim(json) {
  80. assert.ok(typeof json === 'object');
  81. return signingClaimData(json)
  82. .toString('hex')
  83. .toUpperCase();
  84. }
  85. exports.encodeForSigningClaim = encodeForSigningClaim;
  86. /**
  87. * Encode a transaction and prepare for multi-signing
  88. *
  89. * @param json JSON object representing the transaction
  90. * @param signer string representing the account to sign the transaction with
  91. * @returns a hex string of the encoded transaction
  92. */
  93. function encodeForMultisigning(json, signer) {
  94. assert.ok(typeof json === 'object');
  95. assert.equal(json['SigningPubKey'], '');
  96. return multiSigningData(json, signer)
  97. .toString('hex')
  98. .toUpperCase();
  99. }
  100. exports.encodeForMultisigning = encodeForMultisigning;
  101. /**
  102. * Encode a quality value
  103. *
  104. * @param value string representation of a number
  105. * @returns a hex-string representing the quality
  106. */
  107. function encodeQuality(value) {
  108. assert.ok(typeof value === 'string');
  109. return coretypes_1.quality.encode(value).toString('hex').toUpperCase();
  110. }
  111. exports.encodeQuality = encodeQuality;
  112. /**
  113. * Decode a quality value
  114. *
  115. * @param value hex-string of a quality
  116. * @returns a string representing the quality
  117. */
  118. function decodeQuality(value) {
  119. assert.ok(typeof value === 'string');
  120. return coretypes_1.quality.decode(value).toString();
  121. }
  122. exports.decodeQuality = decodeQuality;
  123. //# sourceMappingURL=index.js.map