index.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. "use strict";
  2. var assert = require("assert");
  3. var coretypes_1 = require("./coretypes");
  4. var ledger_hashes_1 = require("./ledger-hashes");
  5. var enums_1 = require("./enums");
  6. var signingData = coretypes_1.binary.signingData, signingClaimData = coretypes_1.binary.signingClaimData, multiSigningData = coretypes_1.binary.multiSigningData, binaryToJSON = coretypes_1.binary.binaryToJSON, serializeObject = coretypes_1.binary.serializeObject;
  7. /**
  8. * Decode a transaction
  9. *
  10. * @param binary hex-string of the encoded transaction
  11. * @returns the JSON representation of the transaction
  12. */
  13. function decode(binary) {
  14. assert.ok(typeof binary === 'string', 'binary must be a hex string');
  15. return binaryToJSON(binary);
  16. }
  17. /**
  18. * Encode a transaction
  19. *
  20. * @param json The JSON representation of a transaction
  21. * @returns A hex-string of the encoded transaction
  22. */
  23. function encode(json) {
  24. assert.ok(typeof json === 'object');
  25. return serializeObject(json)
  26. .toString('hex')
  27. .toUpperCase();
  28. }
  29. /**
  30. * Encode a transaction and prepare for signing
  31. *
  32. * @param json JSON object representing the transaction
  33. * @param signer string representing the account to sign the transaction with
  34. * @returns a hex string of the encoded transaction
  35. */
  36. function encodeForSigning(json) {
  37. assert.ok(typeof json === 'object');
  38. return signingData(json)
  39. .toString('hex')
  40. .toUpperCase();
  41. }
  42. /**
  43. * Encode a transaction and prepare for signing with a claim
  44. *
  45. * @param json JSON object representing the transaction
  46. * @param signer string representing the account to sign the transaction with
  47. * @returns a hex string of the encoded transaction
  48. */
  49. function encodeForSigningClaim(json) {
  50. assert.ok(typeof json === 'object');
  51. return signingClaimData(json)
  52. .toString('hex')
  53. .toUpperCase();
  54. }
  55. /**
  56. * Encode a transaction and prepare for multi-signing
  57. *
  58. * @param json JSON object representing the transaction
  59. * @param signer string representing the account to sign the transaction with
  60. * @returns a hex string of the encoded transaction
  61. */
  62. function encodeForMultisigning(json, signer) {
  63. assert.ok(typeof json === 'object');
  64. assert.equal(json['SigningPubKey'], '');
  65. return multiSigningData(json, signer)
  66. .toString('hex')
  67. .toUpperCase();
  68. }
  69. /**
  70. * Encode a quality value
  71. *
  72. * @param value string representation of a number
  73. * @returns a hex-string representing the quality
  74. */
  75. function encodeQuality(value) {
  76. assert.ok(typeof value === 'string');
  77. return coretypes_1.quality.encode(value).toString('hex').toUpperCase();
  78. }
  79. /**
  80. * Decode a quality value
  81. *
  82. * @param value hex-string of a quality
  83. * @returns a string representing the quality
  84. */
  85. function decodeQuality(value) {
  86. assert.ok(typeof value === 'string');
  87. return coretypes_1.quality.decode(value).toString();
  88. }
  89. module.exports = {
  90. decode: decode,
  91. encode: encode,
  92. encodeForSigning: encodeForSigning,
  93. encodeForSigningClaim: encodeForSigningClaim,
  94. encodeForMultisigning: encodeForMultisigning,
  95. encodeQuality: encodeQuality,
  96. decodeQuality: decodeQuality,
  97. decodeLedgerData: ledger_hashes_1.decodeLedgerData,
  98. TRANSACTION_TYPES: enums_1.TRANSACTION_TYPES,
  99. };
  100. //# sourceMappingURL=index.js.map