UNPKG

5.25 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.coreTypes = exports.DEFAULT_DEFINITIONS = exports.XrplDefinitionsBase = exports.XrplDefinitions = exports.TRANSACTION_TYPES = exports.decodeLedgerData = exports.decodeQuality = exports.encodeQuality = exports.encodeForMultisigning = exports.encodeForSigningClaim = exports.encodeForSigning = exports.encode = exports.decode = void 0;
4const coretypes_1 = require("./coretypes");
5const ledger_hashes_1 = require("./ledger-hashes");
6Object.defineProperty(exports, "decodeLedgerData", { enumerable: true, get: function () { return ledger_hashes_1.decodeLedgerData; } });
7const enums_1 = require("./enums");
8Object.defineProperty(exports, "XrplDefinitionsBase", { enumerable: true, get: function () { return enums_1.XrplDefinitionsBase; } });
9Object.defineProperty(exports, "TRANSACTION_TYPES", { enumerable: true, get: function () { return enums_1.TRANSACTION_TYPES; } });
10Object.defineProperty(exports, "DEFAULT_DEFINITIONS", { enumerable: true, get: function () { return enums_1.DEFAULT_DEFINITIONS; } });
11const xrpl_definitions_1 = require("./enums/xrpl-definitions");
12Object.defineProperty(exports, "XrplDefinitions", { enumerable: true, get: function () { return xrpl_definitions_1.XrplDefinitions; } });
13const types_1 = require("./types");
14Object.defineProperty(exports, "coreTypes", { enumerable: true, get: function () { return types_1.coreTypes; } });
15const utils_1 = require("@xrplf/isomorphic/utils");
16const { signingData, signingClaimData, multiSigningData, binaryToJSON, serializeObject, } = coretypes_1.binary;
17/**
18 * Decode a transaction
19 *
20 * @param binary hex-string of the encoded transaction
21 * @param definitions Custom rippled types to use instead of the default. Used for sidechains and amendments.
22 * @returns the JSON representation of the transaction
23 */
24function decode(binary, definitions) {
25 if (typeof binary !== 'string') {
26 throw new Error('binary must be a hex string');
27 }
28 return binaryToJSON(binary, definitions);
29}
30exports.decode = decode;
31/**
32 * Encode a transaction
33 *
34 * @param json The JSON representation of a transaction
35 * @param definitions Custom rippled types to use instead of the default. Used for sidechains and amendments.
36 *
37 * @returns A hex-string of the encoded transaction
38 */
39function encode(json, definitions) {
40 if (typeof json !== 'object') {
41 throw new Error();
42 }
43 return (0, utils_1.bytesToHex)(serializeObject(json, { definitions }));
44}
45exports.encode = encode;
46/**
47 * Encode a transaction and prepare for signing
48 *
49 * @param json JSON object representing the transaction
50 * @param signer string representing the account to sign the transaction with
51 * @param definitions Custom rippled types to use instead of the default. Used for sidechains and amendments.
52 * @returns a hex string of the encoded transaction
53 */
54function encodeForSigning(json, definitions) {
55 if (typeof json !== 'object') {
56 throw new Error();
57 }
58 return (0, utils_1.bytesToHex)(signingData(json, coretypes_1.HashPrefix.transactionSig, {
59 definitions,
60 }));
61}
62exports.encodeForSigning = encodeForSigning;
63/**
64 * Encode a transaction and prepare for signing with a claim
65 *
66 * @param json JSON object representing the transaction
67 * @param signer string representing the account to sign the transaction with
68 * @param definitions Custom rippled types to use instead of the default. Used for sidechains and amendments.
69 * @returns a hex string of the encoded transaction
70 */
71function encodeForSigningClaim(json) {
72 if (typeof json !== 'object') {
73 throw new Error();
74 }
75 return (0, utils_1.bytesToHex)(signingClaimData(json));
76}
77exports.encodeForSigningClaim = encodeForSigningClaim;
78/**
79 * Encode a transaction and prepare for multi-signing
80 *
81 * @param json JSON object representing the transaction
82 * @param signer string representing the account to sign the transaction with
83 * @param definitions Custom rippled types to use instead of the default. Used for sidechains and amendments.
84 * @returns a hex string of the encoded transaction
85 */
86function encodeForMultisigning(json, signer, definitions) {
87 if (typeof json !== 'object') {
88 throw new Error();
89 }
90 if (json['SigningPubKey'] !== '') {
91 throw new Error();
92 }
93 const definitionsOpt = definitions ? { definitions } : undefined;
94 return (0, utils_1.bytesToHex)(multiSigningData(json, signer, definitionsOpt));
95}
96exports.encodeForMultisigning = encodeForMultisigning;
97/**
98 * Encode a quality value
99 *
100 * @param value string representation of a number
101 * @returns a hex-string representing the quality
102 */
103function encodeQuality(value) {
104 if (typeof value !== 'string') {
105 throw new Error();
106 }
107 return (0, utils_1.bytesToHex)(coretypes_1.quality.encode(value));
108}
109exports.encodeQuality = encodeQuality;
110/**
111 * Decode a quality value
112 *
113 * @param value hex-string of a quality
114 * @returns a string representing the quality
115 */
116function decodeQuality(value) {
117 if (typeof value !== 'string') {
118 throw new Error();
119 }
120 return coretypes_1.quality.decode(value).toString();
121}
122exports.decodeQuality = decodeQuality;
123//# sourceMappingURL=index.js.map
\No newline at end of file