138 lines
6.0 KiB
JavaScript
Raw Permalink Normal View History

2025-06-21 23:30:33 +03:00
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
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;
const assert = __importStar(require("assert"));
const coretypes_1 = require("./coretypes");
const ledger_hashes_1 = require("./ledger-hashes");
Object.defineProperty(exports, "decodeLedgerData", { enumerable: true, get: function () { return ledger_hashes_1.decodeLedgerData; } });
const enums_1 = require("./enums");
Object.defineProperty(exports, "XrplDefinitionsBase", { enumerable: true, get: function () { return enums_1.XrplDefinitionsBase; } });
Object.defineProperty(exports, "TRANSACTION_TYPES", { enumerable: true, get: function () { return enums_1.TRANSACTION_TYPES; } });
Object.defineProperty(exports, "DEFAULT_DEFINITIONS", { enumerable: true, get: function () { return enums_1.DEFAULT_DEFINITIONS; } });
const xrpl_definitions_1 = require("./enums/xrpl-definitions");
Object.defineProperty(exports, "XrplDefinitions", { enumerable: true, get: function () { return xrpl_definitions_1.XrplDefinitions; } });
const types_1 = require("./types");
Object.defineProperty(exports, "coreTypes", { enumerable: true, get: function () { return types_1.coreTypes; } });
const { signingData, signingClaimData, multiSigningData, binaryToJSON, serializeObject, } = coretypes_1.binary;
/**
* Decode a transaction
*
* @param binary hex-string of the encoded transaction
* @param definitions Custom rippled types to use instead of the default. Used for sidechains and amendments.
* @returns the JSON representation of the transaction
*/
function decode(binary, definitions) {
assert.ok(typeof binary === 'string', 'binary must be a hex string');
return binaryToJSON(binary, definitions);
}
exports.decode = decode;
/**
* Encode a transaction
*
* @param json The JSON representation of a transaction
* @param definitions Custom rippled types to use instead of the default. Used for sidechains and amendments.
*
* @returns A hex-string of the encoded transaction
*/
function encode(json, definitions) {
assert.ok(typeof json === 'object');
return serializeObject(json, { definitions })
.toString('hex')
.toUpperCase();
}
exports.encode = encode;
/**
* Encode a transaction and prepare for signing
*
* @param json JSON object representing the transaction
* @param signer string representing the account to sign the transaction with
* @param definitions Custom rippled types to use instead of the default. Used for sidechains and amendments.
* @returns a hex string of the encoded transaction
*/
function encodeForSigning(json, definitions) {
assert.ok(typeof json === 'object');
return signingData(json, coretypes_1.HashPrefix.transactionSig, {
definitions,
})
.toString('hex')
.toUpperCase();
}
exports.encodeForSigning = encodeForSigning;
/**
* Encode a transaction and prepare for signing with a claim
*
* @param json JSON object representing the transaction
* @param signer string representing the account to sign the transaction with
* @param definitions Custom rippled types to use instead of the default. Used for sidechains and amendments.
* @returns a hex string of the encoded transaction
*/
function encodeForSigningClaim(json) {
assert.ok(typeof json === 'object');
return signingClaimData(json)
.toString('hex')
.toUpperCase();
}
exports.encodeForSigningClaim = encodeForSigningClaim;
/**
* Encode a transaction and prepare for multi-signing
*
* @param json JSON object representing the transaction
* @param signer string representing the account to sign the transaction with
* @param definitions Custom rippled types to use instead of the default. Used for sidechains and amendments.
* @returns a hex string of the encoded transaction
*/
function encodeForMultisigning(json, signer, definitions) {
assert.ok(typeof json === 'object');
assert.equal(json['SigningPubKey'], '');
const definitionsOpt = definitions ? { definitions } : undefined;
return multiSigningData(json, signer, definitionsOpt)
.toString('hex')
.toUpperCase();
}
exports.encodeForMultisigning = encodeForMultisigning;
/**
* Encode a quality value
*
* @param value string representation of a number
* @returns a hex-string representing the quality
*/
function encodeQuality(value) {
assert.ok(typeof value === 'string');
return coretypes_1.quality.encode(value).toString('hex').toUpperCase();
}
exports.encodeQuality = encodeQuality;
/**
* Decode a quality value
*
* @param value hex-string of a quality
* @returns a string representing the quality
*/
function decodeQuality(value) {
assert.ok(typeof value === 'string');
return coretypes_1.quality.decode(value).toString();
}
exports.decodeQuality = decodeQuality;
//# sourceMappingURL=index.js.map