UNPKG

6.35 kBJavaScriptView Raw
1"use strict";
2var __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}));
13var __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});
18var __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};
25Object.defineProperty(exports, "__esModule", { value: true });
26exports.nativeAsset = exports.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;
27const assert = __importStar(require("assert"));
28const coretypes_1 = require("./coretypes");
29const ledger_hashes_1 = require("./ledger-hashes");
30Object.defineProperty(exports, "decodeLedgerData", { enumerable: true, get: function () { return ledger_hashes_1.decodeLedgerData; } });
31const enums_1 = require("./enums");
32Object.defineProperty(exports, "XrplDefinitionsBase", { enumerable: true, get: function () { return enums_1.XrplDefinitionsBase; } });
33Object.defineProperty(exports, "TRANSACTION_TYPES", { enumerable: true, get: function () { return enums_1.TRANSACTION_TYPES; } });
34Object.defineProperty(exports, "DEFAULT_DEFINITIONS", { enumerable: true, get: function () { return enums_1.DEFAULT_DEFINITIONS; } });
35const xrpl_definitions_1 = require("./enums/xrpl-definitions");
36Object.defineProperty(exports, "XrplDefinitions", { enumerable: true, get: function () { return xrpl_definitions_1.XrplDefinitions; } });
37const types_1 = require("./types");
38Object.defineProperty(exports, "coreTypes", { enumerable: true, get: function () { return types_1.coreTypes; } });
39const nativeasset_1 = require("./nativeasset");
40Object.defineProperty(exports, "nativeAsset", { enumerable: true, get: function () { return nativeasset_1.nativeAsset; } });
41const { signingData, signingClaimData, multiSigningData, binaryToJSON, serializeObject, } = coretypes_1.binary;
42/**
43 * Decode a transaction
44 *
45 * @param binary hex-string of the encoded transaction
46 * @param definitions Custom rippled types to use instead of the default. Used for sidechains and amendments.
47 * @returns the JSON representation of the transaction
48 */
49function decode(binary, definitions) {
50 assert.ok(typeof binary === 'string', 'binary must be a hex string');
51 return binaryToJSON(binary, definitions);
52}
53exports.decode = decode;
54/**
55 * Encode a transaction
56 *
57 * @param json The JSON representation of a transaction
58 * @param definitions Custom rippled types to use instead of the default. Used for sidechains and amendments.
59 *
60 * @returns A hex-string of the encoded transaction
61 */
62function encode(json, definitions) {
63 assert.ok(typeof json === 'object');
64 return serializeObject(json, { definitions })
65 .toString('hex')
66 .toUpperCase();
67}
68exports.encode = encode;
69/**
70 * Encode a transaction and prepare for signing
71 *
72 * @param json JSON object representing the transaction
73 * @param signer string representing the account to sign the transaction with
74 * @param definitions Custom rippled types to use instead of the default. Used for sidechains and amendments.
75 * @returns a hex string of the encoded transaction
76 */
77function encodeForSigning(json, definitions) {
78 assert.ok(typeof json === 'object');
79 return signingData(json, coretypes_1.HashPrefix.transactionSig, {
80 definitions,
81 })
82 .toString('hex')
83 .toUpperCase();
84}
85exports.encodeForSigning = encodeForSigning;
86/**
87 * Encode a transaction and prepare for signing with a claim
88 *
89 * @param json JSON object representing the transaction
90 * @param signer string representing the account to sign the transaction with
91 * @param definitions Custom rippled types to use instead of the default. Used for sidechains and amendments.
92 * @returns a hex string of the encoded transaction
93 */
94function encodeForSigningClaim(json) {
95 assert.ok(typeof json === 'object');
96 return signingClaimData(json)
97 .toString('hex')
98 .toUpperCase();
99}
100exports.encodeForSigningClaim = encodeForSigningClaim;
101/**
102 * Encode a transaction and prepare for multi-signing
103 *
104 * @param json JSON object representing the transaction
105 * @param signer string representing the account to sign the transaction with
106 * @param definitions Custom rippled types to use instead of the default. Used for sidechains and amendments.
107 * @returns a hex string of the encoded transaction
108 */
109function encodeForMultisigning(json, signer, definitions) {
110 assert.ok(typeof json === 'object');
111 assert.equal(json['SigningPubKey'], '');
112 const definitionsOpt = definitions ? { definitions } : undefined;
113 return multiSigningData(json, signer, definitionsOpt)
114 .toString('hex')
115 .toUpperCase();
116}
117exports.encodeForMultisigning = encodeForMultisigning;
118/**
119 * Encode a quality value
120 *
121 * @param value string representation of a number
122 * @returns a hex-string representing the quality
123 */
124function encodeQuality(value) {
125 assert.ok(typeof value === 'string');
126 return coretypes_1.quality.encode(value).toString('hex').toUpperCase();
127}
128exports.encodeQuality = encodeQuality;
129/**
130 * Decode a quality value
131 *
132 * @param value hex-string of a quality
133 * @returns a string representing the quality
134 */
135function decodeQuality(value) {
136 assert.ok(typeof value === 'string');
137 return coretypes_1.quality.decode(value).toString();
138}
139exports.decodeQuality = decodeQuality;
140//# sourceMappingURL=index.js.map
\No newline at end of file