Socket
Socket
Sign inDemoInstall

ripple-binary-codec

Package Overview
Dependencies
Maintainers
9
Versions
86
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ripple-binary-codec - npm Package Compare versions

Comparing version 1.5.0-beta.3 to 1.5.0-beta.4

dist/enums/xrpl-definitions-base.d.ts

27

dist/binary.d.ts

@@ -5,2 +5,3 @@ import { BinaryParser } from './serdes/binary-parser';

import { sha512Half, transactionID } from './hashes';
import { type XrplDefinitionsBase } from './enums';
import { JsonObject } from './types/serialized-type';

@@ -13,5 +14,7 @@ import { Buffer } from 'buffer/';

* @param bytes hex-string to construct BinaryParser from
* @param definitions rippled definitions used to parse the values of transaction types and such.
* Can be customized for sidechains and amendments.
* @returns A BinaryParser
*/
declare const makeParser: (bytes: string) => BinaryParser;
declare const makeParser: (bytes: string, definitions?: XrplDefinitionsBase) => BinaryParser;
/**

@@ -21,5 +24,7 @@ * Parse BinaryParser into JSON

* @param parser BinaryParser object
* @param definitions rippled definitions used to parse the values of transaction types and such.
* Can be customized for sidechains and amendments.
* @returns JSON for the bytes in the BinaryParser
*/
declare const readJSON: (parser: BinaryParser) => JsonObject;
declare const readJSON: (parser: BinaryParser, definitions?: XrplDefinitionsBase) => JsonObject;
/**

@@ -29,5 +34,7 @@ * Parse a hex-string into its JSON interpretation

* @param bytes hex-string to parse into JSON
* @param definitions rippled definitions used to parse the values of transaction types and such.
* Can be customized for sidechains and amendments.
* @returns JSON
*/
declare const binaryToJSON: (bytes: string) => JsonObject;
declare const binaryToJSON: (bytes: string, definitions?: XrplDefinitionsBase) => JsonObject;
/**

@@ -42,2 +49,3 @@ * Interface for passing parameters to SerializeObject

signingFieldsOnly?: boolean;
definitions?: XrplDefinitionsBase;
}

@@ -48,3 +56,3 @@ /**

* @param object JSON object to serialize
* @param opts options for serializing, including optional prefix, suffix, and signingFieldOnly
* @param opts options for serializing, including optional prefix, suffix, signingFieldOnly, and definitions
* @returns A Buffer containing the serialized object

@@ -58,5 +66,8 @@ */

* @param prefix Prefix bytes to put before the serialized object
* @param opts.definitions Custom rippled types to use instead of the default. Used for sidechains and amendments.
* @returns A Buffer with the serialized object
*/
declare function signingData(transaction: JsonObject, prefix?: Buffer): Buffer;
declare function signingData(transaction: JsonObject, prefix?: Buffer, opts?: {
definitions?: XrplDefinitionsBase;
}): Buffer;
/**

@@ -73,2 +84,3 @@ * Interface describing fields required for a Claim

* @param claim A claim object to serialize
* @param opts.definitions Custom rippled types to use instead of the default. Used for sidechains and amendments.
* @returns the serialized object with appropriate prefix

@@ -82,5 +94,8 @@ */

* @param signingAccount Account to sign the transaction with
* @param opts.definitions Custom rippled types to use instead of the default. Used for sidechains and amendments.
* @returns serialized transaction with appropriate prefix and suffix
*/
declare function multiSigningData(transaction: JsonObject, signingAccount: string | AccountID): Buffer;
declare function multiSigningData(transaction: JsonObject, signingAccount: string | AccountID, opts?: {
definitions: XrplDefinitionsBase;
}): Buffer;
export { BinaryParser, BinarySerializer, BytesList, ClaimObject, makeParser, serializeObject, readJSON, multiSigningData, signingData, signingClaimData, binaryToJSON, sha512Half, transactionID, };

@@ -15,2 +15,3 @@ "use strict";

Object.defineProperty(exports, "transactionID", { enumerable: true, get: function () { return hashes_1.transactionID; } });
const enums_1 = require("./enums");
const bigInt = require("big-integer");

@@ -21,5 +22,7 @@ /**

* @param bytes hex-string to construct BinaryParser from
* @param definitions rippled definitions used to parse the values of transaction types and such.
* Can be customized for sidechains and amendments.
* @returns A BinaryParser
*/
const makeParser = (bytes) => new binary_parser_1.BinaryParser(bytes);
const makeParser = (bytes, definitions) => new binary_parser_1.BinaryParser(bytes, definitions);
exports.makeParser = makeParser;

@@ -30,5 +33,7 @@ /**

* @param parser BinaryParser object
* @param definitions rippled definitions used to parse the values of transaction types and such.
* Can be customized for sidechains and amendments.
* @returns JSON for the bytes in the BinaryParser
*/
const readJSON = (parser) => parser.readType(types_1.coreTypes.STObject).toJSON();
const readJSON = (parser, definitions = enums_1.DEFAULT_DEFINITIONS) => parser.readType(types_1.coreTypes.STObject).toJSON(definitions);
exports.readJSON = readJSON;

@@ -39,5 +44,7 @@ /**

* @param bytes hex-string to parse into JSON
* @param definitions rippled definitions used to parse the values of transaction types and such.
* Can be customized for sidechains and amendments.
* @returns JSON
*/
const binaryToJSON = (bytes) => readJSON(makeParser(bytes));
const binaryToJSON = (bytes, definitions) => readJSON(makeParser(bytes, definitions), definitions);
exports.binaryToJSON = binaryToJSON;

@@ -48,7 +55,7 @@ /**

* @param object JSON object to serialize
* @param opts options for serializing, including optional prefix, suffix, and signingFieldOnly
* @param opts options for serializing, including optional prefix, suffix, signingFieldOnly, and definitions
* @returns A Buffer containing the serialized object
*/
function serializeObject(object, opts = {}) {
const { prefix, suffix, signingFieldsOnly = false } = opts;
const { prefix, suffix, signingFieldsOnly = false, definitions } = opts;
const bytesList = new binary_serializer_1.BytesList();

@@ -61,3 +68,5 @@ if (prefix) {

: undefined;
types_1.coreTypes.STObject.from(object, filter).toBytesSink(bytesList);
types_1.coreTypes.STObject
.from(object, filter, definitions)
.toBytesSink(bytesList);
if (suffix) {

@@ -74,6 +83,11 @@ bytesList.put(suffix);

* @param prefix Prefix bytes to put before the serialized object
* @param opts.definitions Custom rippled types to use instead of the default. Used for sidechains and amendments.
* @returns A Buffer with the serialized object
*/
function signingData(transaction, prefix = hash_prefixes_1.HashPrefix.transactionSig) {
return serializeObject(transaction, { prefix, signingFieldsOnly: true });
function signingData(transaction, prefix = hash_prefixes_1.HashPrefix.transactionSig, opts = {}) {
return serializeObject(transaction, {
prefix,
signingFieldsOnly: true,
definitions: opts.definitions,
});
}

@@ -85,2 +99,3 @@ exports.signingData = signingData;

* @param claim A claim object to serialize
* @param opts.definitions Custom rippled types to use instead of the default. Used for sidechains and amendments.
* @returns the serialized object with appropriate prefix

@@ -111,5 +126,8 @@ */

* @param signingAccount Account to sign the transaction with
* @param opts.definitions Custom rippled types to use instead of the default. Used for sidechains and amendments.
* @returns serialized transaction with appropriate prefix and suffix
*/
function multiSigningData(transaction, signingAccount) {
function multiSigningData(transaction, signingAccount, opts = {
definitions: enums_1.DEFAULT_DEFINITIONS,
}) {
const prefix = hash_prefixes_1.HashPrefix.transactionMultiSig;

@@ -121,2 +139,3 @@ const suffix = types_1.coreTypes.AccountID.from(signingAccount).toBytes();

signingFieldsOnly: true,
definitions: opts.definitions,
});

@@ -123,0 +142,0 @@ }

@@ -1,2 +0,2 @@

import { Field, TransactionType, LedgerEntryType, Type, TransactionResult } from './enums';
import { DEFAULT_DEFINITIONS, Field, TransactionType, LedgerEntryType, Type, TransactionResult } from './enums';
import * as types from './types';

@@ -9,2 +9,2 @@ import * as binary from './binary';

import { HashPrefix } from './hash-prefixes';
export { hashes, binary, ledgerHashes, Field, TransactionType, LedgerEntryType, Type, TransactionResult, quality, HashPrefix, ShaMap, types, };
export { hashes, binary, ledgerHashes, DEFAULT_DEFINITIONS, Field, TransactionType, LedgerEntryType, Type, TransactionResult, quality, HashPrefix, ShaMap, types, };

@@ -26,4 +26,5 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.types = exports.ShaMap = exports.HashPrefix = exports.quality = exports.TransactionResult = exports.Type = exports.LedgerEntryType = exports.TransactionType = exports.Field = exports.ledgerHashes = exports.binary = exports.hashes = void 0;
exports.types = exports.ShaMap = exports.HashPrefix = exports.quality = exports.TransactionResult = exports.Type = exports.LedgerEntryType = exports.TransactionType = exports.Field = exports.DEFAULT_DEFINITIONS = exports.ledgerHashes = exports.binary = exports.hashes = void 0;
const enums_1 = require("./enums");
Object.defineProperty(exports, "DEFAULT_DEFINITIONS", { enumerable: true, get: function () { return enums_1.DEFAULT_DEFINITIONS; } });
Object.defineProperty(exports, "Field", { enumerable: true, get: function () { return enums_1.Field; } });

@@ -30,0 +31,0 @@ Object.defineProperty(exports, "TransactionType", { enumerable: true, get: function () { return enums_1.TransactionType; } });

@@ -1,2 +0,2 @@

import type { BytesList, BinaryParser } from '../binary';
import { BytesList, BinaryParser } from '../binary';
import { Buffer } from 'buffer/';

@@ -3,0 +3,0 @@ export declare class Bytes {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.BytesLookup = exports.Bytes = void 0;
var buffer_1 = require("buffer/");
const buffer_1 = require("buffer/");
/*
* @brief: Bytes, name, and ordinal representing one type, ledger_type, transaction type, or result
*/
var Bytes = /** @class */ (function () {
function Bytes(name, ordinal, ordinalWidth) {
class Bytes {
constructor(name, ordinal, ordinalWidth) {
this.name = name;

@@ -14,17 +14,16 @@ this.ordinal = ordinal;

this.bytes = buffer_1.Buffer.alloc(ordinalWidth);
for (var i = 0; i < ordinalWidth; i++) {
for (let i = 0; i < ordinalWidth; i++) {
this.bytes[ordinalWidth - i - 1] = (ordinal >>> (i * 8)) & 0xff;
}
}
Bytes.prototype.toJSON = function () {
toJSON() {
return this.name;
};
Bytes.prototype.toBytesSink = function (sink) {
}
toBytesSink(sink) {
sink.put(this.bytes);
};
Bytes.prototype.toBytes = function () {
}
toBytes() {
return this.bytes;
};
return Bytes;
}());
}
}
exports.Bytes = Bytes;

@@ -34,9 +33,7 @@ /*

*/
var BytesLookup = /** @class */ (function () {
function BytesLookup(types, ordinalWidth) {
var _this = this;
class BytesLookup {
constructor(types, ordinalWidth) {
this.ordinalWidth = ordinalWidth;
Object.entries(types).forEach(function (_a) {
var k = _a[0], v = _a[1];
_this.add(k, v);
Object.entries(types).forEach(([k, v]) => {
this.add(k, v);
});

@@ -51,21 +48,20 @@ }

*/
BytesLookup.prototype.add = function (name, value) {
add(name, value) {
if (this[name]) {
throw new SyntaxError("Attempted to add a value with a duplicate name \"".concat(name, "\". This is not allowed because it is unclear how to decode."));
throw new SyntaxError(`Attempted to add a value with a duplicate name "${name}". This is not allowed because it is unclear how to decode.`);
}
if (this[value.toString()]) {
throw new SyntaxError("Attempted to add a duplicate value under a different name (Given name: \"".concat(name, "\" and previous name: \"").concat(this[value.toString()], ". This is not allowed because it is unclear how to decode.\nGiven value: ").concat(value.toString()));
throw new SyntaxError(`Attempted to add a duplicate value under a different name (Given name: "${name}" and previous name: "${this[value.toString()]}. This is not allowed because it is unclear how to decode.\nGiven value: ${value.toString()}`);
}
this[name] = new Bytes(name, value, this.ordinalWidth);
this[value.toString()] = this[name];
};
BytesLookup.prototype.from = function (value) {
}
from(value) {
return value instanceof Bytes ? value : this[value];
};
BytesLookup.prototype.fromParser = function (parser) {
}
fromParser(parser) {
return this.from(parser.readUIntN(this.ordinalWidth).toString());
};
return BytesLookup;
}());
}
}
exports.BytesLookup = BytesLookup;
//# sourceMappingURL=bytes.js.map

@@ -28,4 +28,3 @@ import { Bytes } from './bytes';

constructor(fields: Array<[string, FieldInfo]>, types: Record<string, number>);
add(name: string, field_info: FieldInfo, typeOrdinal: number): void;
fromString(value: string): FieldInstance;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FieldLookup = void 0;
var bytes_1 = require("./bytes");
var serialized_type_1 = require("../types/serialized-type");
var constants_1 = require("./constants");
var buffer_1 = require("buffer/");
const bytes_1 = require("./bytes");
const serialized_type_1 = require("../types/serialized-type");
const constants_1 = require("./constants");
const buffer_1 = require("buffer/");
/*

@@ -12,3 +12,3 @@ * @brief: Serialize a field based on type_code and Field.nth

function fieldHeader(type, nth) {
var header = [];
const header = [];
if (type < 16) {

@@ -30,5 +30,4 @@ if (nth < 16) {

}
function buildField(_a, typeOrdinal) {
var name = _a[0], info = _a[1];
var field = fieldHeader(typeOrdinal, info.nth);
function buildField([name, info], typeOrdinal) {
const field = fieldHeader(typeOrdinal, info.nth);
return {

@@ -49,20 +48,15 @@ name: name,

*/
var FieldLookup = /** @class */ (function () {
function FieldLookup(fields, types) {
var _this = this;
fields.forEach(function (_a) {
var k = _a[0], v = _a[1];
_this.add(k, v, types[v.type]);
class FieldLookup {
constructor(fields, types) {
fields.forEach(([name, field_info]) => {
const typeOrdinal = types[field_info.type];
this[name] = buildField([name, field_info], typeOrdinal);
this[this[name].ordinal.toString()] = this[name];
});
}
FieldLookup.prototype.add = function (name, field_info, typeOrdinal) {
this[name] = buildField([name, field_info], typeOrdinal);
this[this[name].ordinal.toString()] = this[name];
};
FieldLookup.prototype.fromString = function (value) {
fromString(value) {
return this[value];
};
return FieldLookup;
}());
}
}
exports.FieldLookup = FieldLookup;
//# sourceMappingURL=field.js.map

@@ -1,48 +0,12 @@

import { SerializedType } from '../types/serialized-type';
import { Buffer } from 'buffer/';
import { BytesList } from '../binary';
export declare const TRANSACTION_TYPES: string[];
export declare class Bytes {
readonly name: string;
readonly ordinal: number;
readonly ordinalWidth: number;
readonly bytes: Buffer;
constructor(name: string, ordinal: number, ordinalWidth: number);
toJSON(): string;
toBytesSink(sink: BytesList): void;
toBytes(): Uint8Array;
}
declare class BytesLookup {
readonly ordinalWidth: number;
constructor(types: Record<string, number>, ordinalWidth: number);
from(value: Bytes | string): Bytes;
fromParser(parser: any): Bytes;
}
interface FieldInfo {
nth: number;
isVLEncoded: boolean;
isSerialized: boolean;
isSigningField: boolean;
type: string;
}
interface FieldInstance {
readonly nth: number;
readonly isVariableLengthEncoded: boolean;
readonly isSerialized: boolean;
readonly isSigningField: boolean;
readonly type: Bytes;
readonly ordinal: number;
readonly name: string;
readonly header: Buffer;
readonly associatedType: typeof SerializedType;
}
declare class FieldLookup {
constructor(fields: Array<[string, FieldInfo]>);
fromString(value: string): FieldInstance;
}
declare const Type: BytesLookup;
declare const LedgerEntryType: BytesLookup;
declare const TransactionType: BytesLookup;
declare const TransactionResult: BytesLookup;
declare const Field: FieldLookup;
export { Field, FieldInstance, Type, LedgerEntryType, TransactionResult, TransactionType, };
import { XrplDefinitionsBase, FieldInstance, Bytes } from './xrpl-definitions-base';
/**
* By default, coreTypes from the `types` folder is where known type definitions are initialized to avoid import cycles.
*/
declare const DEFAULT_DEFINITIONS: XrplDefinitionsBase;
declare const Type: import("./bytes").BytesLookup;
declare const LedgerEntryType: import("./bytes").BytesLookup;
declare const TransactionType: import("./bytes").BytesLookup;
declare const TransactionResult: import("./bytes").BytesLookup;
declare const Field: import("./field").FieldLookup;
declare const TRANSACTION_TYPES: string[];
export { Bytes, XrplDefinitionsBase, DEFAULT_DEFINITIONS, Field, FieldInstance, Type, LedgerEntryType, TransactionResult, TransactionType, TRANSACTION_TYPES, };

@@ -26,118 +26,27 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.TransactionType = exports.TransactionResult = exports.LedgerEntryType = exports.Type = exports.Field = exports.Bytes = exports.TRANSACTION_TYPES = void 0;
exports.TRANSACTION_TYPES = exports.TransactionType = exports.TransactionResult = exports.LedgerEntryType = exports.Type = exports.Field = exports.DEFAULT_DEFINITIONS = exports.XrplDefinitionsBase = exports.Bytes = void 0;
const enums = __importStar(require("./definitions.json"));
const serialized_type_1 = require("../types/serialized-type");
const buffer_1 = require("buffer/");
/*
* @brief: All valid transaction types
const xrpl_definitions_base_1 = require("./xrpl-definitions-base");
Object.defineProperty(exports, "XrplDefinitionsBase", { enumerable: true, get: function () { return xrpl_definitions_base_1.XrplDefinitionsBase; } });
Object.defineProperty(exports, "Bytes", { enumerable: true, get: function () { return xrpl_definitions_base_1.Bytes; } });
/**
* By default, coreTypes from the `types` folder is where known type definitions are initialized to avoid import cycles.
*/
exports.TRANSACTION_TYPES = Object.entries(enums.TRANSACTION_TYPES)
.filter(([_key, value]) => value >= 0)
.map(([key, _value]) => key);
const TYPE_WIDTH = 2;
const LEDGER_ENTRY_WIDTH = 2;
const TRANSACTION_TYPE_WIDTH = 2;
const TRANSACTION_RESULT_WIDTH = 1;
/*
* @brief: Serialize a field based on type_code and Field.nth
*/
function fieldHeader(type, nth) {
const header = [];
if (type < 16) {
if (nth < 16) {
header.push((type << 4) | nth);
}
else {
header.push(type << 4, nth);
}
}
else if (nth < 16) {
header.push(nth, type);
}
else {
header.push(0, type, nth);
}
return buffer_1.Buffer.from(header);
}
/*
* @brief: Bytes, name, and ordinal representing one type, ledger_type, transaction type, or result
*/
class Bytes {
constructor(name, ordinal, ordinalWidth) {
this.name = name;
this.ordinal = ordinal;
this.ordinalWidth = ordinalWidth;
this.bytes = buffer_1.Buffer.alloc(ordinalWidth);
for (let i = 0; i < ordinalWidth; i++) {
this.bytes[ordinalWidth - i - 1] = (ordinal >>> (i * 8)) & 0xff;
}
}
toJSON() {
return this.name;
}
toBytesSink(sink) {
sink.put(this.bytes);
}
toBytes() {
return this.bytes;
}
}
exports.Bytes = Bytes;
/*
* @brief: Collection of Bytes objects, mapping bidirectionally
*/
class BytesLookup {
constructor(types, ordinalWidth) {
this.ordinalWidth = ordinalWidth;
Object.entries(types).forEach(([k, v]) => {
this[k] = new Bytes(k, v, ordinalWidth);
this[v.toString()] = this[k];
});
}
from(value) {
return value instanceof Bytes ? value : this[value];
}
fromParser(parser) {
return this.from(parser.readUIntN(this.ordinalWidth).toString());
}
}
function buildField([name, info]) {
const typeOrdinal = enums.TYPES[info.type];
const field = fieldHeader(typeOrdinal, info.nth);
return {
name: name,
nth: info.nth,
isVariableLengthEncoded: info.isVLEncoded,
isSerialized: info.isSerialized,
isSigningField: info.isSigningField,
ordinal: (typeOrdinal << 16) | info.nth,
type: new Bytes(info.type, typeOrdinal, TYPE_WIDTH),
header: field,
associatedType: serialized_type_1.SerializedType, // For later assignment in ./types/index.js
};
}
/*
* @brief: The collection of all fields as defined in definitions.json
*/
class FieldLookup {
constructor(fields) {
fields.forEach(([k, v]) => {
this[k] = buildField([k, v]);
this[this[k].ordinal.toString()] = this[k];
});
}
fromString(value) {
return this[value];
}
}
const Type = new BytesLookup(enums.TYPES, TYPE_WIDTH);
const DEFAULT_DEFINITIONS = new xrpl_definitions_base_1.XrplDefinitionsBase(enums, {});
exports.DEFAULT_DEFINITIONS = DEFAULT_DEFINITIONS;
const Type = DEFAULT_DEFINITIONS.type;
exports.Type = Type;
const LedgerEntryType = new BytesLookup(enums.LEDGER_ENTRY_TYPES, LEDGER_ENTRY_WIDTH);
const LedgerEntryType = DEFAULT_DEFINITIONS.ledgerEntryType;
exports.LedgerEntryType = LedgerEntryType;
const TransactionType = new BytesLookup(enums.TRANSACTION_TYPES, TRANSACTION_TYPE_WIDTH);
const TransactionType = DEFAULT_DEFINITIONS.transactionType;
exports.TransactionType = TransactionType;
const TransactionResult = new BytesLookup(enums.TRANSACTION_RESULTS, TRANSACTION_RESULT_WIDTH);
const TransactionResult = DEFAULT_DEFINITIONS.transactionResult;
exports.TransactionResult = TransactionResult;
const Field = new FieldLookup(enums.FIELDS);
const Field = DEFAULT_DEFINITIONS.field;
exports.Field = Field;
/*
* @brief: All valid transaction types
*/
const TRANSACTION_TYPES = DEFAULT_DEFINITIONS.transactionNames;
exports.TRANSACTION_TYPES = TRANSACTION_TYPES;
//# sourceMappingURL=index.js.map

@@ -301,2 +301,12 @@ {

[
"DiscountedFee",
{
"nth": 6,
"isVLEncoded": false,
"isSerialized": true,
"isSigningField": true,
"type": "UInt16"
}
],
[
"Version",

@@ -352,2 +362,12 @@ {

[
"NetworkID",
{
"nth": 1,
"isVLEncoded": false,
"isSerialized": true,
"isSigningField": true,
"type": "UInt32"
}
],
[
"Flags",

@@ -793,3 +813,3 @@ {

[
"VoteWeight",
"LockCount",
{

@@ -804,3 +824,3 @@ "nth": 47,

[
"DiscountedFee",
"VoteWeight",
{

@@ -815,5 +835,5 @@ "nth": 48,

[
"LockCount",
"FirstNFTokenSequence",
{
"nth": 49,
"nth": 50,
"isVLEncoded": false,

@@ -1556,5 +1576,5 @@ "isSerialized": true,

[
"LPTokenOut",
"LockedBalance",
{
"nth": 20,
"nth": 21,
"isVLEncoded": false,

@@ -1567,5 +1587,5 @@ "isSerialized": true,

[
"LPTokenIn",
"BaseFeeDrops",
{
"nth": 21,
"nth": 22,
"isVLEncoded": false,

@@ -1578,5 +1598,5 @@ "isSerialized": true,

[
"EPrice",
"ReserveBaseDrops",
{
"nth": 22,
"nth": 23,
"isVLEncoded": false,

@@ -1589,5 +1609,5 @@ "isSerialized": true,

[
"Price",
"ReserveIncrementDrops",
{
"nth": 23,
"nth": 24,
"isVLEncoded": false,

@@ -1600,5 +1620,5 @@ "isSerialized": true,

[
"LPTokenBalance",
"LPTokenOut",
{
"nth": 24,
"nth": 25,
"isVLEncoded": false,

@@ -1611,2 +1631,32 @@ "isSerialized": true,

[
"LPTokenIn",
{
"nth": 26,
"isVLEncoded": false,
"isSerialized": true,
"isSigningField": true,
"type": "Amount"
}
],
[
"EPrice",
{
"nth": 27,
"isVLEncoded": false,
"isSerialized": true,
"isSigningField": true,
"type": "Amount"
}
],
[
"Price",
{
"nth": 28,
"isVLEncoded": false,
"isSerialized": true,
"isSigningField": true,
"type": "Amount"
}
],
[
"SignatureReward",

@@ -1632,3 +1682,3 @@ {

[
"LockedBalance",
"LPTokenBalance",
{

@@ -1973,12 +2023,2 @@ "nth": 31,

[
"AMMAccount",
{
"nth": 11,
"isVLEncoded": true,
"isSerialized": true,
"isSigningField": true,
"type": "AccountID"
}
],
[
"HookAccount",

@@ -2376,3 +2416,3 @@ {

{
"nth": 27,
"nth": 26,
"isVLEncoded": false,

@@ -2387,3 +2427,3 @@ "isSerialized": true,

{
"nth": 28,
"nth": 27,
"isVLEncoded": false,

@@ -2528,3 +2568,3 @@ "isSerialized": true,

{
"nth": 14,
"nth": 12,
"isVLEncoded": false,

@@ -2629,3 +2669,3 @@ "isSerialized": true,

{
"nth": 26,
"nth": 25,
"isVLEncoded": false,

@@ -2652,2 +2692,5 @@ "isSerialized": true,

"telCAN_NOT_QUEUE_FULL": -387,
"telWRONG_NETWORK": -386,
"telREQUIRES_NETWORK_ID": -385,
"telNETWORK_ID_MAKES_TX_NON_CANONICAL": -384,

@@ -2692,3 +2735,3 @@ "temMALFORMED": -299,

"temBAD_NFTOKEN_TRANSFER_FEE": -262,
"temAMM_BAD_TOKENS": -261,
"temBAD_AMM_TOKENS": -261,
"temEQUAL_DOOR_ACCOUNTS": -259,

@@ -2786,9 +2829,6 @@ "temBAD_XCHAIN_PROOF": -258,

"tecINSUFFICIENT_PAYMENT": 161,
"tecAMM_UNFUNDED": 162,
"tecUNFUNDED_AMM": 162,
"tecAMM_BALANCE": 163,
"tecAMM_FAILED_DEPOSIT": 164,
"tecAMM_FAILED_WITHDRAW": 165,
"tecAMM_INVALID_TOKENS": 166,
"tecAMM_FAILED_BID": 167,
"tecAMM_FAILED_VOTE": 168,
"tecAMM_FAILED": 164,
"tecAMM_INVALID_TOKENS": 165,
"tecBAD_XCHAIN_TRANSFER_ISSUE": 171,

@@ -2810,3 +2850,4 @@ "tecXCHAIN_NO_CLAIM_ID": 172,

"tecXCHAIN_BAD_PUBLIC_KEY_ACCOUNT_PAIR": 186,
"tecPRECISION_LOSS": 187
"tecREQUIRES_FLAG": 187,
"tecPRECISION_LOSS": 188
},

@@ -2813,0 +2854,0 @@ "TRANSACTION_TYPES": {

@@ -0,23 +1,9 @@

import { type DefinitionsData, XrplDefinitionsBase } from './xrpl-definitions-base';
import { SerializedType } from '../types/serialized-type';
import { Bytes, BytesLookup } from './bytes';
import { FieldInfo, FieldLookup, FieldInstance } from './field';
interface DefinitionsData {
TYPES: Record<string, number>;
LEDGER_ENTRY_TYPES: Record<string, number>;
FIELDS: (string | FieldInfo)[][];
TRANSACTION_RESULTS: Record<string, number>;
TRANSACTION_TYPES: Record<string, number>;
}
/**
* Stores the various types and fields for rippled to be used to encode/decode information later on.
*
* Should be used instead of XrplDefinitionsBase since this defines default `types` for serializing/deserializing
* ledger data.
*/
declare class XrplDefinitions {
field: FieldLookup;
ledgerEntryType: BytesLookup;
type: BytesLookup;
transactionResult: BytesLookup;
transactionType: BytesLookup;
transactionNames: string[];
dataTypes: Record<string, typeof SerializedType>;
export declare class XrplDefinitions extends XrplDefinitionsBase {
/**

@@ -31,15 +17,6 @@ * Present rippled types in a typed and updatable format.

* @param enums - A json encoding of the core types, transaction types, transaction results, transaction names, and fields.
* @param types - A list of type objects with the same name as the fields defined.
* You can use the coreTypes object if you are not adding new types.
* @param additionalTypes - A list of SerializedType objects with the same name as the fields defined.
* These types will be included in addition to the coreTypes used on mainnet.
*/
constructor(enums: DefinitionsData, types?: Record<string, typeof SerializedType>);
/**
* Associates each Field to a corresponding class that TypeScript can recognize.
*
* @param types a list of type objects with the same name as the fields defined.
* Defaults to xrpl.js's core type definitions.
*/
associateTypes(types: Record<string, typeof SerializedType>): void;
getAssociatedTypes(): Record<string, typeof SerializedType>;
constructor(enums: DefinitionsData, additionalTypes?: Record<string, typeof SerializedType>);
}
export { XrplDefinitions, FieldLookup, FieldInfo, FieldInstance, Bytes, BytesLookup, };
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.BytesLookup = exports.Bytes = exports.FieldLookup = exports.XrplDefinitions = void 0;
var bytes_1 = require("./bytes");
Object.defineProperty(exports, "Bytes", { enumerable: true, get: function () { return bytes_1.Bytes; } });
Object.defineProperty(exports, "BytesLookup", { enumerable: true, get: function () { return bytes_1.BytesLookup; } });
var field_1 = require("./field");
Object.defineProperty(exports, "FieldLookup", { enumerable: true, get: function () { return field_1.FieldLookup; } });
var constants_1 = require("./constants");
var types_1 = require("../types");
exports.XrplDefinitions = void 0;
const xrpl_definitions_base_1 = require("./xrpl-definitions-base");
const types_1 = require("../types");
/**
* Stores the various types and fields for rippled to be used to encode/decode information later on.
*
* Should be used instead of XrplDefinitionsBase since this defines default `types` for serializing/deserializing
* ledger data.
*/
var XrplDefinitions = /** @class */ (function () {
class XrplDefinitions extends xrpl_definitions_base_1.XrplDefinitionsBase {
/**

@@ -24,47 +20,11 @@ * Present rippled types in a typed and updatable format.

* @param enums - A json encoding of the core types, transaction types, transaction results, transaction names, and fields.
* @param types - A list of type objects with the same name as the fields defined.
* You can use the coreTypes object if you are not adding new types.
* @param additionalTypes - A list of SerializedType objects with the same name as the fields defined.
* These types will be included in addition to the coreTypes used on mainnet.
*/
function XrplDefinitions(enums, types) {
if (types === void 0) { types = types_1.coreTypes; }
this.type = new bytes_1.BytesLookup(enums.TYPES, constants_1.TYPE_WIDTH);
this.ledgerEntryType = new bytes_1.BytesLookup(enums.LEDGER_ENTRY_TYPES, constants_1.LEDGER_ENTRY_WIDTH);
this.transactionType = new bytes_1.BytesLookup(enums.TRANSACTION_TYPES, constants_1.TRANSACTION_TYPE_WIDTH);
this.transactionResult = new bytes_1.BytesLookup(enums.TRANSACTION_RESULTS, constants_1.TRANSACTION_RESULT_WIDTH);
this.field = new field_1.FieldLookup(enums.FIELDS, enums.TYPES);
this.transactionNames = Object.entries(enums.TRANSACTION_TYPES)
.filter(function (_a) {
var _key = _a[0], value = _a[1];
return value >= 0;
})
.map(function (_a) {
var key = _a[0], _value = _a[1];
return key;
});
this.dataTypes = {}; // Filled in via associateTypes
this.associateTypes(types);
constructor(enums, additionalTypes) {
const types = Object.assign({}, types_1.coreTypes, additionalTypes);
super(enums, types);
}
/**
* Associates each Field to a corresponding class that TypeScript can recognize.
*
* @param types a list of type objects with the same name as the fields defined.
* Defaults to xrpl.js's core type definitions.
*/
XrplDefinitions.prototype.associateTypes = function (types) {
var _this = this;
// Overwrite any existing type definitions with the given types
this.dataTypes = Object.assign({}, this.dataTypes, types);
Object.values(this.field).forEach(function (field) {
field.associatedType = _this.dataTypes[field.type.name];
});
this.field['TransactionType'].associatedType = this.transactionType;
this.field['TransactionResult'].associatedType = this.transactionResult;
this.field['LedgerEntryType'].associatedType = this.ledgerEntryType;
};
XrplDefinitions.prototype.getAssociatedTypes = function () {
return this.dataTypes;
};
return XrplDefinitions;
}());
}
exports.XrplDefinitions = XrplDefinitions;
//# sourceMappingURL=xrpl-definitions.js.map
import { decodeLedgerData } from './ledger-hashes';
import { JsonObject } from './types/serialized-type';
import { TRANSACTION_TYPES } from './enums';
import { XrplDefinitionsBase, TRANSACTION_TYPES, DEFAULT_DEFINITIONS } from './enums';
import { XrplDefinitions } from './enums/xrpl-definitions';
import { coreTypes } from './types';
/**

@@ -8,5 +10,6 @@ * 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
*/
declare function decode(binary: string): JsonObject;
declare function decode(binary: string, definitions?: XrplDefinitionsBase): JsonObject;
/**

@@ -16,5 +19,7 @@ * 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
*/
declare function encode(json: object): string;
declare function encode(json: object, definitions?: XrplDefinitionsBase): string;
/**

@@ -25,5 +30,6 @@ * Encode a transaction and prepare for signing

* @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
*/
declare function encodeForSigning(json: object): string;
declare function encodeForSigning(json: object, definitions?: XrplDefinitionsBase): string;
/**

@@ -34,2 +40,3 @@ * Encode a transaction and prepare for signing with a claim

* @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

@@ -43,5 +50,6 @@ */

* @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
*/
declare function encodeForMultisigning(json: object, signer: string): string;
declare function encodeForMultisigning(json: object, signer: string, definitions?: XrplDefinitionsBase): string;
/**

@@ -61,2 +69,2 @@ * Encode a quality value

declare function decodeQuality(value: string): string;
export { decode, encode, encodeForSigning, encodeForSigningClaim, encodeForMultisigning, encodeQuality, decodeQuality, decodeLedgerData, TRANSACTION_TYPES, };
export { decode, encode, encodeForSigning, encodeForSigningClaim, encodeForMultisigning, encodeQuality, decodeQuality, decodeLedgerData, TRANSACTION_TYPES, XrplDefinitions, XrplDefinitionsBase, DEFAULT_DEFINITIONS, coreTypes, };

@@ -26,3 +26,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.TRANSACTION_TYPES = exports.decodeLedgerData = exports.decodeQuality = exports.encodeQuality = exports.encodeForMultisigning = exports.encodeForSigningClaim = exports.encodeForSigning = exports.encode = exports.decode = void 0;
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"));

@@ -33,3 +33,9 @@ const coretypes_1 = require("./coretypes");

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;

@@ -40,7 +46,8 @@ /**

* @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) {
function decode(binary, definitions) {
assert.ok(typeof binary === 'string', 'binary must be a hex string');
return binaryToJSON(binary);
return binaryToJSON(binary, definitions);
}

@@ -52,7 +59,9 @@ exports.decode = decode;

* @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) {
function encode(json, definitions) {
assert.ok(typeof json === 'object');
return serializeObject(json)
return serializeObject(json, { definitions })
.toString('hex')

@@ -67,7 +76,10 @@ .toUpperCase();

* @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) {
function encodeForSigning(json, definitions) {
assert.ok(typeof json === 'object');
return signingData(json)
return signingData(json, coretypes_1.HashPrefix.transactionSig, {
definitions,
})
.toString('hex')

@@ -82,2 +94,3 @@ .toUpperCase();

* @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

@@ -97,8 +110,10 @@ */

* @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) {
function encodeForMultisigning(json, signer, definitions) {
assert.ok(typeof json === 'object');
assert.equal(json['SigningPubKey'], '');
return multiSigningData(json, signer)
const definitionsOpt = definitions ? { definitions } : undefined;
return multiSigningData(json, signer, definitionsOpt)
.toString('hex')

@@ -105,0 +120,0 @@ .toUpperCase();

import { Hash256 } from './types/hash-256';
import { JsonObject } from './types/serialized-type';
import bigInt = require('big-integer');
import { XrplDefinitionsBase } from './enums';
/**

@@ -43,5 +44,7 @@ * Function computing the hash of a transaction tree

* @param binary A serialized ledger header
* @param definitions Type definitions to parse the ledger objects.
* Used if there are non-default ledger objects to decode.
* @returns A JSON object describing a ledger header
*/
declare function decodeLedgerData(binary: string): object;
declare function decodeLedgerData(binary: string, definitions?: XrplDefinitionsBase): object;
export { accountStateHash, transactionTreeHash, ledgerHash, decodeLedgerData };

@@ -140,7 +140,9 @@ "use strict";

* @param binary A serialized ledger header
* @param definitions Type definitions to parse the ledger objects.
* Used if there are non-default ledger objects to decode.
* @returns A JSON object describing a ledger header
*/
function decodeLedgerData(binary) {
function decodeLedgerData(binary, definitions) {
assert.ok(typeof binary === 'string', 'binary must be a hex string');
const parser = new binary_parser_1.BinaryParser(binary);
const parser = new binary_parser_1.BinaryParser(binary, definitions);
return {

@@ -147,0 +149,0 @@ ledger_index: parser.readUInt32(),

@@ -1,3 +0,3 @@

import { FieldInstance } from '../enums';
import { SerializedType } from '../types/serialized-type';
import { XrplDefinitionsBase, FieldInstance } from '../enums';
import { type SerializedType } from '../types/serialized-type';
import { Buffer } from 'buffer/';

@@ -9,2 +9,3 @@ /**

private bytes;
definitions: XrplDefinitionsBase;
/**

@@ -14,4 +15,6 @@ * Initialize bytes to a hex string

* @param hexBytes a hex string
* @param definitions Rippled definitions used to parse the values of transaction types and such.
* Can be customized for sidechains and amendments.
*/
constructor(hexBytes: string);
constructor(hexBytes: string, definitions?: XrplDefinitionsBase);
/**

@@ -18,0 +21,0 @@ * Peek the first byte of the BinaryParser

@@ -38,5 +38,8 @@ "use strict";

* @param hexBytes a hex string
* @param definitions Rippled definitions used to parse the values of transaction types and such.
* Can be customized for sidechains and amendments.
*/
constructor(hexBytes) {
constructor(hexBytes, definitions = enums_1.DEFAULT_DEFINITIONS) {
this.bytes = buffer_1.Buffer.from(hexBytes, 'hex');
this.definitions = definitions;
}

@@ -157,3 +160,3 @@ /**

readField() {
return enums_1.Field.fromString(this.readFieldOrdinal().toString());
return this.definitions.field.fromString(this.readFieldOrdinal().toString());
}

@@ -160,0 +163,0 @@ /**

import { FieldInstance } from '../enums';
import { SerializedType } from '../types/serialized-type';
import { type SerializedType } from '../types/serialized-type';
import { Buffer } from 'buffer/';

@@ -4,0 +4,0 @@ /**

@@ -133,3 +133,5 @@ "use strict";

const branch = this.branches[i];
const hash = branch ? branch.hash() : types_1.coreTypes.Hash256.ZERO_256;
const hash = branch
? branch.hash()
: types_1.coreTypes.Hash256.ZERO_256;
hash.toBytesSink(list);

@@ -136,0 +138,0 @@ }

@@ -8,3 +8,2 @@ import { AccountID } from './account-id';

import { Hash256 } from './hash-256';
import { Issue } from './issue';
import { PathSet } from './path-set';

@@ -18,22 +17,4 @@ import { STArray } from './st-array';

import { Vector256 } from './vector-256';
import { XChainBridge } from './xchain-bridge';
declare const coreTypes: {
AccountID: typeof AccountID;
Amount: typeof Amount;
Blob: typeof Blob;
Currency: typeof Currency;
Hash128: typeof Hash128;
Hash160: typeof Hash160;
Hash256: typeof Hash256;
Issue: typeof Issue;
PathSet: typeof PathSet;
STArray: typeof STArray;
STObject: typeof STObject;
UInt8: typeof UInt8;
UInt16: typeof UInt16;
UInt32: typeof UInt32;
UInt64: typeof UInt64;
Vector256: typeof Vector256;
XChainBridge: typeof XChainBridge;
};
export { coreTypes };
import { type SerializedType } from './serialized-type';
declare const coreTypes: Record<string, typeof SerializedType>;
export { coreTypes, AccountID, Amount, Blob, Currency, Hash128, Hash160, Hash256, PathSet, STArray, STObject, UInt8, UInt16, UInt32, UInt64, Vector256, };
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.coreTypes = void 0;
const enums_1 = require("../enums");
exports.Vector256 = exports.UInt64 = exports.UInt32 = exports.UInt16 = exports.UInt8 = exports.STObject = exports.STArray = exports.PathSet = exports.Hash256 = exports.Hash160 = exports.Hash128 = exports.Currency = exports.Blob = exports.Amount = exports.AccountID = exports.coreTypes = void 0;
const account_id_1 = require("./account-id");
Object.defineProperty(exports, "AccountID", { enumerable: true, get: function () { return account_id_1.AccountID; } });
const amount_1 = require("./amount");
Object.defineProperty(exports, "Amount", { enumerable: true, get: function () { return amount_1.Amount; } });
const blob_1 = require("./blob");
Object.defineProperty(exports, "Blob", { enumerable: true, get: function () { return blob_1.Blob; } });
const currency_1 = require("./currency");
Object.defineProperty(exports, "Currency", { enumerable: true, get: function () { return currency_1.Currency; } });
const hash_128_1 = require("./hash-128");
Object.defineProperty(exports, "Hash128", { enumerable: true, get: function () { return hash_128_1.Hash128; } });
const hash_160_1 = require("./hash-160");
Object.defineProperty(exports, "Hash160", { enumerable: true, get: function () { return hash_160_1.Hash160; } });
const hash_256_1 = require("./hash-256");
Object.defineProperty(exports, "Hash256", { enumerable: true, get: function () { return hash_256_1.Hash256; } });
const issue_1 = require("./issue");
const path_set_1 = require("./path-set");
Object.defineProperty(exports, "PathSet", { enumerable: true, get: function () { return path_set_1.PathSet; } });
const st_array_1 = require("./st-array");
Object.defineProperty(exports, "STArray", { enumerable: true, get: function () { return st_array_1.STArray; } });
const st_object_1 = require("./st-object");
Object.defineProperty(exports, "STObject", { enumerable: true, get: function () { return st_object_1.STObject; } });
const uint_16_1 = require("./uint-16");
Object.defineProperty(exports, "UInt16", { enumerable: true, get: function () { return uint_16_1.UInt16; } });
const uint_32_1 = require("./uint-32");
Object.defineProperty(exports, "UInt32", { enumerable: true, get: function () { return uint_32_1.UInt32; } });
const uint_64_1 = require("./uint-64");
Object.defineProperty(exports, "UInt64", { enumerable: true, get: function () { return uint_64_1.UInt64; } });
const uint_8_1 = require("./uint-8");
Object.defineProperty(exports, "UInt8", { enumerable: true, get: function () { return uint_8_1.UInt8; } });
const vector_256_1 = require("./vector-256");
Object.defineProperty(exports, "Vector256", { enumerable: true, get: function () { return vector_256_1.Vector256; } });
const xchain_bridge_1 = require("./xchain-bridge");
const enums_1 = require("../enums");
const coreTypes = {

@@ -42,8 +57,6 @@ AccountID: account_id_1.AccountID,

exports.coreTypes = coreTypes;
Object.values(enums_1.Field).forEach((field) => {
field.associatedType = coreTypes[field.type.name];
});
enums_1.Field['TransactionType'].associatedType = enums_1.TransactionType;
enums_1.Field['TransactionResult'].associatedType = enums_1.TransactionResult;
enums_1.Field['LedgerEntryType'].associatedType = enums_1.LedgerEntryType;
// Ensures that the DEFAULT_DEFINITIONS object connects these types to fields for serializing/deserializing
// This is done here instead of in enums/index.ts to avoid a circular dependency
// because some of the above types depend on BinarySerializer which depends on enums/index.ts.
enums_1.DEFAULT_DEFINITIONS.associateTypes(coreTypes);
//# sourceMappingURL=index.js.map

@@ -0,1 +1,2 @@

import { XrplDefinitionsBase } from '../enums';
import { SerializedType, JsonObject } from './serialized-type';

@@ -19,12 +20,14 @@ import { BinaryParser } from '../serdes/binary-parser';

* @param filter optional, denote which field to include in serialized object
* @param definitions optional, types and values to use to encode/decode a transaction
* @returns a STObject object
*/
static from<T extends STObject | JsonObject>(value: T, filter?: (...any: any[]) => boolean): STObject;
static from<T extends STObject | JsonObject>(value: T, filter?: (...any: any[]) => boolean, definitions?: XrplDefinitionsBase): STObject;
/**
* Get the JSON interpretation of this.bytes
*
* @param definitions rippled definitions used to parse the values of transaction types and such.
* Can be customized for sidechains and amendments.
* @returns a JSON object
*/
toJSON(): JsonObject;
toJSON(definitions?: XrplDefinitionsBase): JsonObject;
}
export { STObject };

@@ -80,5 +80,6 @@ "use strict";

* @param filter optional, denote which field to include in serialized object
* @param definitions optional, types and values to use to encode/decode a transaction
* @returns a STObject object
*/
static from(value, filter) {
static from(value, filter, definitions = enums_1.DEFAULT_DEFINITIONS) {
if (value instanceof STObject) {

@@ -99,3 +100,3 @@ return value;

let sorted = Object.keys(xAddressDecoded)
.map((f) => enums_1.Field[f])
.map((f) => definitions.field[f])
.filter((f) => f !== undefined &&

@@ -132,7 +133,8 @@ xAddressDecoded[f.name] !== undefined &&

* Get the JSON interpretation of this.bytes
*
* @param definitions rippled definitions used to parse the values of transaction types and such.
* Can be customized for sidechains and amendments.
* @returns a JSON object
*/
toJSON() {
const objectParser = new binary_parser_1.BinaryParser(this.toString());
toJSON(definitions) {
const objectParser = new binary_parser_1.BinaryParser(this.toString(), definitions);
const accumulator = {};

@@ -139,0 +141,0 @@ while (!objectParser.end()) {

{
"name": "ripple-binary-codec",
"version": "1.5.0-beta.3",
"version": "1.5.0-beta.4",
"description": "XRP Ledger binary codec",

@@ -17,6 +17,6 @@ "files": [

"big-integer": "^1.6.48",
"buffer": "5.6.0",
"buffer": "6.0.3",
"create-hash": "^1.2.0",
"decimal.js": "^10.2.0",
"ripple-address-codec": "^4.2.4"
"ripple-address-codec": "^4.2.5"
},

@@ -26,3 +26,3 @@ "scripts": {

"clean": "rm -rf ./dist && rm -rf tsconfig.tsbuildinfo",
"prepare": "npm test",
"prepublishOnly": "npm test",
"test": "npm run build && jest --verbose false --silent=false ./test/*.test.js",

@@ -44,3 +44,4 @@ "lint": "eslint . --ext .ts --ext .test.js"

"node": ">= 10"
}
},
"gitHead": "4e03fbb78921c9e12562d65e3aa697849c290e9a"
}

@@ -7,3 +7,6 @@ const { throws } = require('assert')

} = require('../src')
const { XrplDefinitions } = require('../src/enums/xrpl-definitions')
const normalDefinitions = require('../src/enums/definitions.json')
const tx_json = {

@@ -71,2 +74,49 @@ Account: 'r9LqNeG6qHxjeUocjvVki2XR35weJ9mZgQ',

test('can create single signing blobs with modified type', function () {
const customPaymentDefinitions = JSON.parse(
JSON.stringify(normalDefinitions),
)
customPaymentDefinitions.TRANSACTION_TYPES.Payment = 31
const newDefs = new XrplDefinitions(customPaymentDefinitions)
const actual = encodeForSigning(tx_json, newDefs)
expect(actual).toBe(
[
'53545800', // signingPrefix
// TransactionType
'12',
'001F',
// Flags
'22',
'80000000',
// Sequence
'24',
'00000001',
// Amount
'61',
// native amount
'40000000000003E8',
// Fee
'68',
// native amount
'400000000000000A',
// SigningPubKey
'73',
// VLLength
'21',
'ED5F5AC8B98974A3CA843326D9B88CEBD0560177B973EE0B149F782CFAA06DC66A',
// Account
'81',
// VLLength
'14',
'5B812C9D57731E27A2DA8B1830195F88EF32A3B6',
// Destination
'83',
// VLLength
'14',
'B5F762798A53D543A014CAF8B297CFF8F2F937E8',
].join(''),
)
})
test('can fail gracefully for invalid TransactionType', function () {

@@ -83,3 +133,3 @@ const invalidTransactionType = {

const signingAccount = 'rJZdUusLDtY9NEsGea7ijqhVrXv98rYBYN'
const signingJson = Object.assign({}, tx_json, { SigningPubKey: '' })
const signingJson = { ...tx_json, SigningPubKey: '' }
const actual = encodeForMultisigning(signingJson, signingAccount)

@@ -126,2 +176,54 @@ expect(actual).toBe(

})
test('can create multi signing blobs with custom definitions', function () {
const customPaymentDefinitions = JSON.parse(
JSON.stringify(normalDefinitions),
)
customPaymentDefinitions.TRANSACTION_TYPES.Payment = 31
const newDefs = new XrplDefinitions(customPaymentDefinitions)
const signingAccount = 'rJZdUusLDtY9NEsGea7ijqhVrXv98rYBYN'
const signingJson = { ...tx_json, SigningPubKey: '' }
const actual = encodeForMultisigning(signingJson, signingAccount, newDefs)
expect(actual).toBe(
[
'534D5400', // signingPrefix
// TransactionType
'12',
'001F',
// Flags
'22',
'80000000',
// Sequence
'24',
'00000001',
// Amount
'61',
// native amount
'40000000000003E8',
// Fee
'68',
// native amount
'400000000000000A',
// SigningPubKey
'73',
// VLLength
'00',
// '',
// Account
'81',
// VLLength
'14',
'5B812C9D57731E27A2DA8B1830195F88EF32A3B6',
// Destination
'83',
// VLLength
'14',
'B5F762798A53D543A014CAF8B297CFF8F2F937E8',
// signingAccount suffix
'C0A5ABEF242802EFED4B041E8F2D4A8CC86AE3D1',
].join(''),
)
})
test('can create native claim blob', function () {

@@ -128,0 +230,0 @@ const channel =

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc