@transia/ripple-binary-codec 1.4.6-alpha.9 → 2.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/binary.d.ts +30 -16
- package/dist/binary.js +36 -16
- package/dist/binary.js.map +1 -1
- package/dist/enums/bytes.d.ts +1 -2
- package/dist/enums/bytes.js +3 -2
- package/dist/enums/bytes.js.map +1 -1
- package/dist/enums/constants.d.ts +1 -0
- package/dist/enums/constants.js +6 -5
- package/dist/enums/constants.js.map +1 -1
- package/dist/enums/definitions.json +1604 -969
- package/dist/enums/field.d.ts +1 -2
- package/dist/enums/field.js +1 -2
- package/dist/enums/field.js.map +1 -1
- package/dist/enums/index.d.ts +1 -2
- package/dist/enums/index.js +5 -27
- package/dist/enums/index.js.map +1 -1
- package/dist/enums/src/enums/definitions.json +1606 -971
- package/dist/enums/xrpl-definitions-base.d.ts +5 -3
- package/dist/enums/xrpl-definitions-base.js +26 -6
- package/dist/enums/xrpl-definitions-base.js.map +1 -1
- package/dist/enums/xrpl-definitions.d.ts +2 -1
- package/dist/enums/xrpl-definitions.js +2 -1
- package/dist/enums/xrpl-definitions.js.map +1 -1
- package/dist/hash-prefixes.d.ts +1 -2
- package/dist/hash-prefixes.js +8 -6
- package/dist/hash-prefixes.js.map +1 -1
- package/dist/hashes.d.ts +6 -7
- package/dist/hashes.js +6 -7
- package/dist/hashes.js.map +1 -1
- package/dist/index.d.ts +16 -11
- package/dist/index.js +53 -58
- package/dist/index.js.map +1 -1
- package/dist/ledger-hashes.d.ts +1 -2
- package/dist/ledger-hashes.js +11 -30
- package/dist/ledger-hashes.js.map +1 -1
- package/dist/quality.d.ts +3 -4
- package/dist/quality.js +10 -8
- package/dist/quality.js.map +1 -1
- package/dist/serdes/binary-parser.d.ts +2 -3
- package/dist/serdes/binary-parser.js +16 -32
- package/dist/serdes/binary-parser.js.map +1 -1
- package/dist/serdes/binary-serializer.d.ts +7 -8
- package/dist/serdes/binary-serializer.js +14 -37
- package/dist/serdes/binary-serializer.js.map +1 -1
- package/dist/shamap.d.ts +4 -5
- package/dist/shamap.js +5 -5
- package/dist/shamap.js.map +1 -1
- package/dist/src/binary.d.ts +106 -0
- package/dist/src/binary.js +154 -0
- package/dist/src/binary.js.map +1 -0
- package/dist/src/coretypes.d.ts +9 -0
- package/dist/src/coretypes.js +48 -0
- package/dist/src/coretypes.js.map +1 -0
- package/dist/src/enums/bytes.d.ts +25 -0
- package/dist/src/enums/bytes.js +65 -0
- package/dist/src/enums/bytes.js.map +1 -0
- package/dist/src/enums/constants.d.ts +5 -0
- package/dist/src/enums/constants.js +9 -0
- package/dist/src/enums/constants.js.map +1 -0
- package/dist/src/enums/definitions.json +3404 -0
- package/dist/src/enums/field.d.ts +28 -0
- package/dist/src/enums/field.js +58 -0
- package/dist/src/enums/field.js.map +1 -0
- package/dist/src/enums/index.d.ts +12 -0
- package/dist/src/enums/index.js +31 -0
- package/dist/src/enums/index.js.map +1 -0
- package/dist/src/enums/utils-renumber.d.ts +101 -0
- package/dist/src/enums/utils-renumber.js +127 -0
- package/dist/src/enums/utils-renumber.js.map +1 -0
- package/dist/src/enums/xrpl-definitions-base.d.ts +47 -0
- package/dist/src/enums/xrpl-definitions-base.js +83 -0
- package/dist/src/enums/xrpl-definitions-base.js.map +1 -0
- package/dist/src/enums/xrpl-definitions.d.ts +22 -0
- package/dist/src/enums/xrpl-definitions.js +30 -0
- package/dist/src/enums/xrpl-definitions.js.map +1 -0
- package/dist/src/hash-prefixes.d.ts +5 -0
- package/dist/src/hash-prefixes.js +43 -0
- package/dist/src/hash-prefixes.js.map +1 -0
- package/dist/src/hashes.d.ts +50 -0
- package/dist/src/hashes.js +76 -0
- package/dist/src/hashes.js.map +1 -0
- package/dist/src/index.d.ts +69 -0
- package/dist/src/index.js +134 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/ledger-hashes.d.ts +48 -0
- package/dist/src/ledger-hashes.js +141 -0
- package/dist/src/ledger-hashes.js.map +1 -0
- package/dist/src/quality.d.ts +21 -0
- package/dist/src/quality.js +42 -0
- package/dist/src/quality.js.map +1 -0
- package/dist/src/serdes/binary-parser.d.ts +100 -0
- package/dist/src/serdes/binary-parser.js +194 -0
- package/dist/src/serdes/binary-parser.js.map +1 -0
- package/dist/src/serdes/binary-serializer.d.ts +81 -0
- package/dist/src/serdes/binary-serializer.js +149 -0
- package/dist/src/serdes/binary-serializer.js.map +1 -0
- package/dist/src/shamap.d.ts +102 -0
- package/dist/src/shamap.js +172 -0
- package/dist/src/shamap.js.map +1 -0
- package/dist/src/types/account-id.d.ts +37 -0
- package/dist/src/types/account-id.js +73 -0
- package/dist/src/types/account-id.js.map +1 -0
- package/dist/src/types/amount.d.ts +92 -0
- package/dist/src/types/amount.js +292 -0
- package/dist/src/types/amount.js.map +1 -0
- package/dist/src/types/blob.d.ts +25 -0
- package/dist/src/types/blob.js +46 -0
- package/dist/src/types/blob.js.map +1 -0
- package/dist/src/types/currency.d.ts +30 -0
- package/dist/src/types/currency.js +131 -0
- package/dist/src/types/currency.js.map +1 -0
- package/dist/src/types/data.d.ts +104 -0
- package/dist/src/types/data.js +387 -0
- package/dist/src/types/data.js.map +1 -0
- package/dist/src/types/dataType.d.ts +94 -0
- package/dist/src/types/dataType.js +145 -0
- package/dist/src/types/dataType.js.map +1 -0
- package/dist/src/types/hash-128.d.ts +18 -0
- package/dist/src/types/hash-128.js +36 -0
- package/dist/src/types/hash-128.js.map +1 -0
- package/dist/src/types/hash-160.d.ts +12 -0
- package/dist/src/types/hash-160.js +23 -0
- package/dist/src/types/hash-160.js.map +1 -0
- package/dist/src/types/hash-192.d.ts +12 -0
- package/dist/src/types/hash-192.js +23 -0
- package/dist/src/types/hash-192.js.map +1 -0
- package/dist/src/types/hash-256.d.ts +12 -0
- package/dist/src/types/hash-256.js +20 -0
- package/dist/src/types/hash-256.js.map +1 -0
- package/dist/src/types/hash.d.ts +40 -0
- package/dist/src/types/hash.js +76 -0
- package/dist/src/types/hash.js.map +1 -0
- package/dist/src/types/index.d.ts +21 -0
- package/dist/src/types/index.js +72 -0
- package/dist/src/types/index.js.map +1 -0
- package/dist/src/types/issue.d.ts +49 -0
- package/dist/src/types/issue.js +107 -0
- package/dist/src/types/issue.js.map +1 -0
- package/dist/src/types/json.d.ts +169 -0
- package/dist/src/types/json.js +529 -0
- package/dist/src/types/json.js.map +1 -0
- package/dist/src/types/path-set.d.ts +37 -0
- package/dist/src/types/path-set.js +236 -0
- package/dist/src/types/path-set.js.map +1 -0
- package/dist/src/types/serialized-type.d.ts +117 -0
- package/dist/src/types/serialized-type.js +242 -0
- package/dist/src/types/serialized-type.js.map +1 -0
- package/dist/src/types/st-array.d.ts +32 -0
- package/dist/src/types/st-array.js +89 -0
- package/dist/src/types/st-array.js.map +1 -0
- package/dist/src/types/st-number.d.ts +55 -0
- package/dist/src/types/st-number.js +212 -0
- package/dist/src/types/st-number.js.map +1 -0
- package/dist/src/types/st-object.d.ts +33 -0
- package/dist/src/types/st-object.js +176 -0
- package/dist/src/types/st-object.js.map +1 -0
- package/dist/src/types/uint-16.d.ts +26 -0
- package/dist/src/types/uint-16.js +49 -0
- package/dist/src/types/uint-16.js.map +1 -0
- package/dist/src/types/uint-32.d.ts +26 -0
- package/dist/src/types/uint-32.js +54 -0
- package/dist/src/types/uint-32.js.map +1 -0
- package/dist/src/types/uint-64.d.ts +40 -0
- package/dist/src/types/uint-64.js +112 -0
- package/dist/src/types/uint-64.js.map +1 -0
- package/dist/src/types/uint-8.d.ts +26 -0
- package/dist/src/types/uint-8.js +50 -0
- package/dist/src/types/uint-8.js.map +1 -0
- package/dist/src/types/uint.d.ts +29 -0
- package/dist/src/types/uint.js +47 -0
- package/dist/src/types/uint.js.map +1 -0
- package/dist/src/types/vector-256.d.ts +31 -0
- package/dist/src/types/vector-256.js +76 -0
- package/dist/src/types/vector-256.js.map +1 -0
- package/dist/src/types/xchain-bridge.d.ts +45 -0
- package/dist/src/types/xchain-bridge.js +105 -0
- package/dist/src/types/xchain-bridge.js.map +1 -0
- package/dist/src/utils.d.ts +79 -0
- package/dist/src/utils.js +181 -0
- package/dist/src/utils.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types/account-id.d.ts +3 -2
- package/dist/types/account-id.js +8 -6
- package/dist/types/account-id.js.map +1 -1
- package/dist/types/amount.d.ts +33 -9
- package/dist/types/amount.js +128 -43
- package/dist/types/amount.js.map +1 -1
- package/dist/types/blob.d.ts +3 -3
- package/dist/types/blob.js +8 -2
- package/dist/types/blob.js.map +1 -1
- package/dist/types/currency.d.ts +3 -2
- package/dist/types/currency.js +17 -13
- package/dist/types/currency.js.map +1 -1
- package/dist/types/data.d.ts +104 -0
- package/dist/types/data.js +387 -0
- package/dist/types/data.js.map +1 -0
- package/dist/types/dataType.d.ts +94 -0
- package/dist/types/dataType.js +145 -0
- package/dist/types/dataType.js.map +1 -0
- package/dist/types/hash-128.d.ts +3 -2
- package/dist/types/hash-128.js +7 -3
- package/dist/types/hash-128.js.map +1 -1
- package/dist/types/hash-160.d.ts +3 -2
- package/dist/types/hash-160.js +5 -2
- package/dist/types/hash-160.js.map +1 -1
- package/dist/types/hash-192.d.ts +12 -0
- package/dist/types/hash-192.js +23 -0
- package/dist/types/hash-192.js.map +1 -0
- package/dist/types/hash-256.d.ts +3 -2
- package/dist/types/hash-256.js +5 -2
- package/dist/types/hash-256.js.map +1 -1
- package/dist/types/hash.d.ts +2 -3
- package/dist/types/hash.js +8 -4
- package/dist/types/hash.js.map +1 -1
- package/dist/types/index.d.ts +4 -1
- package/dist/types/index.js +17 -2
- package/dist/types/index.js.map +1 -1
- package/dist/types/issue.d.ts +49 -0
- package/dist/types/issue.js +107 -0
- package/dist/types/issue.js.map +1 -0
- package/dist/types/json.d.ts +169 -0
- package/dist/types/json.js +529 -0
- package/dist/types/json.js.map +1 -0
- package/dist/types/path-set.d.ts +2 -1
- package/dist/types/path-set.js +15 -12
- package/dist/types/path-set.js.map +1 -1
- package/dist/types/serialized-type.d.ts +70 -16
- package/dist/types/serialized-type.js +153 -8
- package/dist/types/serialized-type.js.map +1 -1
- package/dist/types/st-array.d.ts +7 -3
- package/dist/types/st-array.js +20 -11
- package/dist/types/st-array.js.map +1 -1
- package/dist/types/st-number.d.ts +55 -0
- package/dist/types/st-number.js +212 -0
- package/dist/types/st-number.js.map +1 -0
- package/dist/types/st-object.d.ts +2 -1
- package/dist/types/st-object.js +35 -8
- package/dist/types/st-object.js.map +1 -1
- package/dist/types/uint-16.d.ts +3 -2
- package/dist/types/uint-16.js +10 -5
- package/dist/types/uint-16.js.map +1 -1
- package/dist/types/uint-32.d.ts +3 -2
- package/dist/types/uint-32.js +11 -6
- package/dist/types/uint-32.js.map +1 -1
- package/dist/types/uint-64.d.ts +8 -7
- package/dist/types/uint-64.js +49 -24
- package/dist/types/uint-64.js.map +1 -1
- package/dist/types/uint-8.d.ts +3 -2
- package/dist/types/uint-8.js +11 -5
- package/dist/types/uint-8.js.map +1 -1
- package/dist/types/uint.d.ts +5 -6
- package/dist/types/uint.js +5 -0
- package/dist/types/uint.js.map +1 -1
- package/dist/types/vector-256.d.ts +3 -3
- package/dist/types/vector-256.js +5 -4
- package/dist/types/vector-256.js.map +1 -1
- package/dist/types/xchain-bridge.d.ts +45 -0
- package/dist/types/xchain-bridge.js +105 -0
- package/dist/types/xchain-bridge.js.map +1 -0
- package/dist/utils.d.ts +79 -0
- package/dist/utils.js +181 -0
- package/dist/utils.js.map +1 -0
- package/package.json +21 -17
- package/src/README.md +5 -0
- package/src/binary.ts +235 -0
- package/src/coretypes.ts +31 -0
- package/src/enums/README.md +144 -0
- package/src/enums/bytes.ts +80 -0
- package/src/enums/constants.ts +5 -0
- package/src/enums/definitions.json +3409 -0
- package/src/enums/field.ts +84 -0
- package/src/enums/index.ts +34 -0
- package/src/enums/utils-renumber.ts +134 -0
- package/src/enums/xrpl-definitions-base.ts +150 -0
- package/src/enums/xrpl-definitions.ts +33 -0
- package/src/hash-prefixes.ts +42 -0
- package/src/hashes.ts +75 -0
- package/src/index.ts +166 -0
- package/src/ledger-hashes.ts +191 -0
- package/src/quality.ts +38 -0
- package/src/serdes/binary-parser.ts +228 -0
- package/src/serdes/binary-serializer.ts +166 -0
- package/src/shamap.ts +189 -0
- package/src/types/account-id.ts +91 -0
- package/src/types/amount.ts +366 -0
- package/src/types/blob.ts +50 -0
- package/src/types/currency.ts +145 -0
- package/src/types/data.ts +496 -0
- package/src/types/dataType.ts +178 -0
- package/src/types/hash-128.ts +38 -0
- package/src/types/hash-160.ts +24 -0
- package/src/types/hash-192.ts +24 -0
- package/src/types/hash-256.ts +20 -0
- package/src/types/hash.ts +86 -0
- package/src/types/index.ts +74 -0
- package/src/types/issue.ts +140 -0
- package/src/types/json.ts +641 -0
- package/src/types/path-set.ts +294 -0
- package/src/types/serialized-type.ts +271 -0
- package/src/types/st-array.ts +117 -0
- package/src/types/st-number.ts +238 -0
- package/src/types/st-object.ts +219 -0
- package/src/types/uint-16.ts +58 -0
- package/src/types/uint-32.ts +64 -0
- package/src/types/uint-64.ts +141 -0
- package/src/types/uint-8.ts +57 -0
- package/src/types/uint.ts +60 -0
- package/src/types/vector-256.ts +83 -0
- package/src/types/xchain-bridge.ts +132 -0
- package/src/utils.ts +220 -0
- package/test/amount.test.js +0 -43
- package/test/binary-json.test.js +0 -45
- package/test/binary-parser.test.js +0 -396
- package/test/binary-serializer.test.js +0 -319
- package/test/definitions.test.js +0 -100
- package/test/fixtures/account-tx-transactions.db +0 -0
- package/test/fixtures/codec-fixtures.json +0 -4466
- package/test/fixtures/data-driven-tests.json +0 -2919
- package/test/fixtures/delivermin-tx-binary.json +0 -1
- package/test/fixtures/delivermin-tx.json +0 -98
- package/test/fixtures/deposit-preauth-tx-binary.json +0 -1
- package/test/fixtures/deposit-preauth-tx-meta-binary.json +0 -1
- package/test/fixtures/deposit-preauth-tx.json +0 -58
- package/test/fixtures/escrow-cancel-binary.json +0 -1
- package/test/fixtures/escrow-cancel-tx.json +0 -6
- package/test/fixtures/escrow-create-binary.json +0 -1
- package/test/fixtures/escrow-create-tx.json +0 -10
- package/test/fixtures/escrow-finish-binary.json +0 -1
- package/test/fixtures/escrow-finish-meta-binary.json +0 -1
- package/test/fixtures/escrow-finish-tx.json +0 -95
- package/test/fixtures/ledger-full-38129.json +0 -1
- package/test/fixtures/ledger-full-40000.json +0 -1
- package/test/fixtures/negative-unl.json +0 -12
- package/test/fixtures/nf-token.json +0 -547
- package/test/fixtures/payment-channel-claim-binary.json +0 -1
- package/test/fixtures/payment-channel-claim-tx.json +0 -8
- package/test/fixtures/payment-channel-create-binary.json +0 -1
- package/test/fixtures/payment-channel-create-tx.json +0 -11
- package/test/fixtures/payment-channel-fund-binary.json +0 -1
- package/test/fixtures/payment-channel-fund-tx.json +0 -7
- package/test/fixtures/remit-binary.json +0 -1
- package/test/fixtures/remit-tx.json +0 -39
- package/test/fixtures/signerlistset-tx-binary.json +0 -1
- package/test/fixtures/signerlistset-tx-meta-binary.json +0 -1
- package/test/fixtures/signerlistset-tx.json +0 -94
- package/test/fixtures/ticket-create-binary.json +0 -1
- package/test/fixtures/ticket-create-tx.json +0 -7
- package/test/fixtures/unl-report-binary.json +0 -1
- package/test/fixtures/unl-report-meta-binary.json +0 -1
- package/test/fixtures/unl-report.json +0 -89
- package/test/fixtures/x-codec-fixtures.json +0 -188
- package/test/hash.test.js +0 -135
- package/test/ledger.test.js +0 -29
- package/test/lower-case-hex.test.js +0 -46
- package/test/pseudo-transaction.test.js +0 -38
- package/test/quality.test.js +0 -15
- package/test/shamap.test.js +0 -89
- package/test/signing-data-encoding.test.js +0 -213
- package/test/tx-encode-decode.test.js +0 -119
- package/test/types.test.js +0 -34
- package/test/uint.test.js +0 -148
- package/test/utils.js +0 -30
- package/test/x-address.test.js +0 -181
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serialized-type.js","sourceRoot":"","sources":["../../../src/types/serialized-type.ts"],"names":[],"mappings":";;;AAAA,mEAAuD;AAGvD,q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C,CAAC,CAAA;IACnC,CAAC;IAED,GAAG,CAAC,KAAQ;QACV,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IAClC,CAAC;IAED;;;;;OAKG;IACH,SAAS,CAAC,KAAQ;QAChB,MAAM,IAAI,KAAK,CAAC,kBAAkB,IAAI,CAAC,QAAQ,EAAE,QAAQ,KAAK,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAA;IAC9E,CAAC;CACF;AAEwB,gCAAU"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { XrplDefinitionsBase } from '../enums';
|
|
2
|
+
import { SerializedType, JsonObject, SerializedTypeID } from './serialized-type';
|
|
3
|
+
import { BinaryParser } from '../serdes/binary-parser';
|
|
4
|
+
/**
|
|
5
|
+
* Class for serializing and deserializing Arrays of Objects
|
|
6
|
+
*/
|
|
7
|
+
declare class STArray extends SerializedType {
|
|
8
|
+
/**
|
|
9
|
+
* Construct an STArray from a BinaryParser
|
|
10
|
+
*
|
|
11
|
+
* @param parser BinaryParser to parse an STArray from
|
|
12
|
+
* @returns An STArray Object
|
|
13
|
+
*/
|
|
14
|
+
static fromParser(parser: BinaryParser): STArray;
|
|
15
|
+
/**
|
|
16
|
+
* Construct an STArray from an Array of JSON Objects
|
|
17
|
+
*
|
|
18
|
+
* @param value STArray or Array of Objects to parse into an STArray
|
|
19
|
+
* @param definitions optional, types and values to use to encode/decode a transaction
|
|
20
|
+
* @returns An STArray object
|
|
21
|
+
*/
|
|
22
|
+
static from<T extends STArray | Array<JsonObject>>(value: T, definitions?: XrplDefinitionsBase): STArray;
|
|
23
|
+
/**
|
|
24
|
+
* Return the JSON representation of this.bytes
|
|
25
|
+
*
|
|
26
|
+
* @param definitions optional, types and values to use to encode/decode a transaction
|
|
27
|
+
* @returns An Array of JSON objects
|
|
28
|
+
*/
|
|
29
|
+
toJSON(definitions?: XrplDefinitionsBase): Array<JsonObject>;
|
|
30
|
+
getSType(): SerializedTypeID;
|
|
31
|
+
}
|
|
32
|
+
export { STArray };
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.STArray = void 0;
|
|
4
|
+
const enums_1 = require("../enums");
|
|
5
|
+
const serialized_type_1 = require("./serialized-type");
|
|
6
|
+
const st_object_1 = require("./st-object");
|
|
7
|
+
const binary_parser_1 = require("../serdes/binary-parser");
|
|
8
|
+
const utils_1 = require("@transia/isomorphic/utils");
|
|
9
|
+
const ARRAY_END_MARKER = Uint8Array.from([0xf1]);
|
|
10
|
+
const ARRAY_END_MARKER_NAME = 'ArrayEndMarker';
|
|
11
|
+
const OBJECT_END_MARKER = Uint8Array.from([0xe1]);
|
|
12
|
+
/**
|
|
13
|
+
* TypeGuard for Array<JsonObject>
|
|
14
|
+
*/
|
|
15
|
+
function isObjects(args) {
|
|
16
|
+
return (Array.isArray(args) &&
|
|
17
|
+
args.every((arg) => typeof arg === 'object' &&
|
|
18
|
+
Object.keys(arg).length === 1 &&
|
|
19
|
+
typeof Object.values(arg)[0] === 'object'));
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Class for serializing and deserializing Arrays of Objects
|
|
23
|
+
*/
|
|
24
|
+
class STArray extends serialized_type_1.SerializedType {
|
|
25
|
+
/**
|
|
26
|
+
* Construct an STArray from a BinaryParser
|
|
27
|
+
*
|
|
28
|
+
* @param parser BinaryParser to parse an STArray from
|
|
29
|
+
* @returns An STArray Object
|
|
30
|
+
*/
|
|
31
|
+
static fromParser(parser) {
|
|
32
|
+
const bytes = [];
|
|
33
|
+
while (!parser.end()) {
|
|
34
|
+
const field = parser.readField();
|
|
35
|
+
if (field.name === ARRAY_END_MARKER_NAME) {
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
bytes.push(field.header, parser.readFieldValue(field).toBytes(), OBJECT_END_MARKER);
|
|
39
|
+
}
|
|
40
|
+
bytes.push(ARRAY_END_MARKER);
|
|
41
|
+
return new STArray((0, utils_1.concat)(bytes));
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Construct an STArray from an Array of JSON Objects
|
|
45
|
+
*
|
|
46
|
+
* @param value STArray or Array of Objects to parse into an STArray
|
|
47
|
+
* @param definitions optional, types and values to use to encode/decode a transaction
|
|
48
|
+
* @returns An STArray object
|
|
49
|
+
*/
|
|
50
|
+
static from(value, definitions = enums_1.DEFAULT_DEFINITIONS) {
|
|
51
|
+
if (value instanceof STArray) {
|
|
52
|
+
return value;
|
|
53
|
+
}
|
|
54
|
+
if (isObjects(value)) {
|
|
55
|
+
const bytes = [];
|
|
56
|
+
value.forEach((obj) => {
|
|
57
|
+
bytes.push(st_object_1.STObject.from(obj, undefined, definitions).toBytes());
|
|
58
|
+
});
|
|
59
|
+
bytes.push(ARRAY_END_MARKER);
|
|
60
|
+
return new STArray((0, utils_1.concat)(bytes));
|
|
61
|
+
}
|
|
62
|
+
throw new Error('Cannot construct STArray from value given');
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Return the JSON representation of this.bytes
|
|
66
|
+
*
|
|
67
|
+
* @param definitions optional, types and values to use to encode/decode a transaction
|
|
68
|
+
* @returns An Array of JSON objects
|
|
69
|
+
*/
|
|
70
|
+
toJSON(definitions = enums_1.DEFAULT_DEFINITIONS) {
|
|
71
|
+
const result = [];
|
|
72
|
+
const arrayParser = new binary_parser_1.BinaryParser(this.toString(), definitions);
|
|
73
|
+
while (!arrayParser.end()) {
|
|
74
|
+
const field = arrayParser.readField();
|
|
75
|
+
if (field.name === ARRAY_END_MARKER_NAME) {
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
const outer = {};
|
|
79
|
+
outer[field.name] = st_object_1.STObject.fromParser(arrayParser).toJSON(definitions);
|
|
80
|
+
result.push(outer);
|
|
81
|
+
}
|
|
82
|
+
return result;
|
|
83
|
+
}
|
|
84
|
+
getSType() {
|
|
85
|
+
return serialized_type_1.SerializedTypeID.STI_ARRAY;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
exports.STArray = STArray;
|
|
89
|
+
//# sourceMappingURL=st-array.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"st-array.js","sourceRoot":"","sources":["../../../src/types/st-array.ts"],"names":[],"mappings":";;;AAAA,oCAAmE;AACnE,uDAAgF;AAChF,2CAAsC;AACtC,2DAAsD;AACtD,qDAAkD;AAElD,MAAM,gBAAgB,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAA;AAChD,MAAM,qBAAqB,GAAG,gBAAgB,CAAA;AAE9C,MAAM,iBAAiB,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAA;AAEjD;;GAEG;AACH,SAAS,SAAS,CAAC,IAAI;IACrB,OAAO,CACL,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC;QACnB,IAAI,CAAC,KAAK,CACR,CAAC,GAAG,EAAE,EAAE,CACN,OAAO,GAAG,KAAK,QAAQ;YACvB,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,KAAK,CAAC;YAC7B,OAAO,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,QAAQ,CAC5C,CACF,CAAA;AACH,CAAC;AAED;;GAEG;AACH,MAAM,OAAQ,SAAQ,gCAAc;IAClC;;;;;OAKG;IACH,MAAM,CAAC,UAAU,CAAC,MAAoB;QACpC,MAAM,KAAK,GAAsB,EAAE,CAAA;QAEnC,OAAO,CAAC,MAAM,CAAC,GAAG,EAAE,EAAE;YACpB,MAAM,KAAK,GAAG,MAAM,CAAC,SAAS,EAAE,CAAA;YAChC,IAAI,KAAK,CAAC,IAAI,KAAK,qBAAqB,EAAE;gBACxC,MAAK;aACN;YAED,KAAK,CAAC,IAAI,CACR,KAAK,CAAC,MAAM,EACZ,MAAM,CAAC,cAAc,CAAC,KAAK,C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AG,oBAAQ,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,CAAA;YACxE,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;SACnB;QAED,OAAO,MAAM,CAAA;IACf,CAAC;IAED,QAAQ;QACN,OAAO,kCAAgB,CAAC,SAAS,CAAA;IACnC,CAAC;CACF;AAEQ,0BAAO"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { BinaryParser } from '../serdes/binary-parser';
|
|
2
|
+
import { SerializedType, SerializedTypeID } from './serialized-type';
|
|
3
|
+
/**
|
|
4
|
+
* STNumber: Encodes XRPL's "Number" type.
|
|
5
|
+
*
|
|
6
|
+
* - Always encoded as 12 bytes: 8-byte signed mantissa, 4-byte signed exponent, both big-endian.
|
|
7
|
+
* - Can only be constructed from a valid number string or another STNumber instance.
|
|
8
|
+
*
|
|
9
|
+
* Usage:
|
|
10
|
+
* STNumber.from("1.2345e5")
|
|
11
|
+
* STNumber.from("-123")
|
|
12
|
+
* STNumber.fromParser(parser)
|
|
13
|
+
*/
|
|
14
|
+
export declare class STNumber extends SerializedType {
|
|
15
|
+
/** 12 zero bytes, represents canonical zero. */
|
|
16
|
+
static defaultBytes: Uint8Array;
|
|
17
|
+
/**
|
|
18
|
+
* Construct a STNumber from 12 bytes (8 for mantissa, 4 for exponent).
|
|
19
|
+
* @param bytes - 12-byte Uint8Array
|
|
20
|
+
* @throws Error if input is not a Uint8Array of length 12.
|
|
21
|
+
*/
|
|
22
|
+
constructor(bytes?: Uint8Array);
|
|
23
|
+
/**
|
|
24
|
+
* Construct from a number string (or another STNumber).
|
|
25
|
+
*
|
|
26
|
+
* @param value - A string, or STNumber instance.
|
|
27
|
+
* @returns STNumber instance.
|
|
28
|
+
* @throws Error if not a string or STNumber.
|
|
29
|
+
*/
|
|
30
|
+
static from(value: unknown): STNumber;
|
|
31
|
+
/**
|
|
32
|
+
* Construct from a number string (integer, decimal, or scientific notation).
|
|
33
|
+
* Handles normalization to XRPL Number constraints.
|
|
34
|
+
*
|
|
35
|
+
* @param val - The number as a string (e.g. '1.23', '-123e5').
|
|
36
|
+
* @returns STNumber instance
|
|
37
|
+
* @throws Error if val is not a valid number string.
|
|
38
|
+
*/
|
|
39
|
+
static fromValue(val: string): STNumber;
|
|
40
|
+
/**
|
|
41
|
+
* Read a STNumber from a BinaryParser stream (12 bytes).
|
|
42
|
+
* @param parser - BinaryParser positioned at the start of a number
|
|
43
|
+
* @returns STNumber instance
|
|
44
|
+
*/
|
|
45
|
+
static fromParser(parser: BinaryParser): STNumber;
|
|
46
|
+
/**
|
|
47
|
+
* Convert this STNumber to a normalized string representation.
|
|
48
|
+
* The output is decimal or scientific notation, depending on exponent range.
|
|
49
|
+
* Follows XRPL convention: zero is "0", other values are normalized to a canonical string.
|
|
50
|
+
*
|
|
51
|
+
* @returns String representation of the value
|
|
52
|
+
*/
|
|
53
|
+
toJSON(): string;
|
|
54
|
+
getSType(): SerializedTypeID;
|
|
55
|
+
}
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.STNumber = void 0;
|
|
4
|
+
const serialized_type_1 = require("./serialized-type");
|
|
5
|
+
const utils_1 = require("../utils");
|
|
6
|
+
/**
|
|
7
|
+
* Constants for mantissa and exponent normalization per XRPL Number spec.
|
|
8
|
+
* These define allowed magnitude for mantissa and exponent after normalization.
|
|
9
|
+
*/
|
|
10
|
+
const MIN_MANTISSA = BigInt('1000000000000000');
|
|
11
|
+
const MAX_MANTISSA = BigInt('9999999999999999');
|
|
12
|
+
const MIN_EXPONENT = -32768;
|
|
13
|
+
const MAX_EXPONENT = 32768;
|
|
14
|
+
const DEFAULT_VALUE_EXPONENT = -2147483648;
|
|
15
|
+
/**
|
|
16
|
+
* Extract mantissa, exponent, and sign from a number string.
|
|
17
|
+
*
|
|
18
|
+
* @param val - The string representing the number (may be integer, decimal, or scientific notation).
|
|
19
|
+
* @returns Object containing mantissa (BigInt), exponent (number), and isNegative (boolean).
|
|
20
|
+
* @throws Error if the string cannot be parsed as a valid number.
|
|
21
|
+
*
|
|
22
|
+
* Examples:
|
|
23
|
+
* '123' -> { mantissa: 123n, exponent: 0, isNegative: false }
|
|
24
|
+
* '-00123.45' -> { mantissa: -12345n, exponent: -2, isNegative: true }
|
|
25
|
+
* '+7.1e2' -> { mantissa: 71n, exponent: -1 + 2 = 1, isNegative: false }
|
|
26
|
+
*/
|
|
27
|
+
function extractNumberPartsFromString(val) {
|
|
28
|
+
/**
|
|
29
|
+
* Regex for parsing decimal/float/scientific number strings with optional sign, integer, decimal, and exponent parts.
|
|
30
|
+
*
|
|
31
|
+
* Pattern: /^([-+]?)([0-9]+)(?:\.([0-9]+))?(?:[eE]([+-]?[0-9]+))?$/
|
|
32
|
+
*
|
|
33
|
+
* Breakdown:
|
|
34
|
+
* 1. ([-+]?) - Optional '+' or '-' sign at the start.
|
|
35
|
+
* 2. ([0-9]+) - Integer part: one or more digits (leading zeros allowed).
|
|
36
|
+
* 3. (?:\.([0-9]+))? - Optional decimal point followed by one or more digits.
|
|
37
|
+
* 4. (?:[eE]([+-]?[0-9]+))? - Optional exponent, starting with 'e' or 'E', optional sign, and digits.
|
|
38
|
+
*
|
|
39
|
+
* Notes:
|
|
40
|
+
* - Leading zeros are accepted and normalized by code after parsing.
|
|
41
|
+
* - Empty decimal ('123.') and missing integer ('.456') are NOT matched—must be fully specified.
|
|
42
|
+
*/
|
|
43
|
+
// eslint-disable-next-line prefer-named-capture-group
|
|
44
|
+
const regex = /^([-+]?)([0-9]+)(?:\.([0-9]+))?(?:[eE]([+-]?[0-9]+))?$/;
|
|
45
|
+
const match = regex.exec(val);
|
|
46
|
+
if (!match)
|
|
47
|
+
throw new Error(`Unable to parse number from string: ${val}`);
|
|
48
|
+
const [, sign, intPart, fracPart, expPart] = match;
|
|
49
|
+
// Remove leading zeros (unless the entire intPart is zeros)
|
|
50
|
+
const cleanIntPart = intPart.replace(/^0+(?=\d)/, '') || '0';
|
|
51
|
+
let mantissaStr = cleanIntPart;
|
|
52
|
+
let exponent = 0;
|
|
53
|
+
if (fracPart) {
|
|
54
|
+
mantissaStr += fracPart;
|
|
55
|
+
exponent -= fracPart.length;
|
|
56
|
+
}
|
|
57
|
+
if (expPart)
|
|
58
|
+
exponent += parseInt(expPart, 10);
|
|
59
|
+
let mantissa = BigInt(mantissaStr);
|
|
60
|
+
if (sign === '-')
|
|
61
|
+
mantissa = -mantissa;
|
|
62
|
+
const isNegative = mantissa < BigInt(0);
|
|
63
|
+
return { mantissa, exponent, isNegative };
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Normalize the mantissa and exponent to XRPL constraints.
|
|
67
|
+
*
|
|
68
|
+
* Ensures that after normalization, the mantissa is between MIN_MANTISSA and MAX_MANTISSA (unless zero).
|
|
69
|
+
* Adjusts the exponent as needed by shifting the mantissa left/right (multiplying/dividing by 10).
|
|
70
|
+
*
|
|
71
|
+
* @param mantissa - The unnormalized mantissa (BigInt).
|
|
72
|
+
* @param exponent - The unnormalized exponent (number).
|
|
73
|
+
* @returns An object with normalized mantissa and exponent.
|
|
74
|
+
* @throws Error if the number cannot be normalized within allowed exponent range.
|
|
75
|
+
*/
|
|
76
|
+
function normalize(mantissa, exponent) {
|
|
77
|
+
let m = mantissa < BigInt(0) ? -mantissa : mantissa;
|
|
78
|
+
const isNegative = mantissa < BigInt(0);
|
|
79
|
+
while (m !== BigInt(0) && m < MIN_MANTISSA && exponent > MIN_EXPONENT) {
|
|
80
|
+
exponent -= 1;
|
|
81
|
+
m *= BigInt(10);
|
|
82
|
+
}
|
|
83
|
+
while (m > MAX_MANTISSA) {
|
|
84
|
+
if (exponent >= MAX_EXPONENT)
|
|
85
|
+
throw new Error('Mantissa and exponent are too large');
|
|
86
|
+
exponent += 1;
|
|
87
|
+
m /= BigInt(10);
|
|
88
|
+
}
|
|
89
|
+
if (isNegative)
|
|
90
|
+
m = -m;
|
|
91
|
+
return { mantissa: m, exponent };
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* STNumber: Encodes XRPL's "Number" type.
|
|
95
|
+
*
|
|
96
|
+
* - Always encoded as 12 bytes: 8-byte signed mantissa, 4-byte signed exponent, both big-endian.
|
|
97
|
+
* - Can only be constructed from a valid number string or another STNumber instance.
|
|
98
|
+
*
|
|
99
|
+
* Usage:
|
|
100
|
+
* STNumber.from("1.2345e5")
|
|
101
|
+
* STNumber.from("-123")
|
|
102
|
+
* STNumber.fromParser(parser)
|
|
103
|
+
*/
|
|
104
|
+
class STNumber extends serialized_type_1.SerializedType {
|
|
105
|
+
/**
|
|
106
|
+
* Construct a STNumber from 12 bytes (8 for mantissa, 4 for exponent).
|
|
107
|
+
* @param bytes - 12-byte Uint8Array
|
|
108
|
+
* @throws Error if input is not a Uint8Array of length 12.
|
|
109
|
+
*/
|
|
110
|
+
constructor(bytes) {
|
|
111
|
+
const used = bytes !== null && bytes !== void 0 ? bytes : STNumber.defaultBytes;
|
|
112
|
+
if (!(used instanceof Uint8Array) || used.length !== 12) {
|
|
113
|
+
throw new Error(`STNumber must be constructed from a 12-byte Uint8Array, got ${used === null || used === void 0 ? void 0 : used.length}`);
|
|
114
|
+
}
|
|
115
|
+
super(used);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Construct from a number string (or another STNumber).
|
|
119
|
+
*
|
|
120
|
+
* @param value - A string, or STNumber instance.
|
|
121
|
+
* @returns STNumber instance.
|
|
122
|
+
* @throws Error if not a string or STNumber.
|
|
123
|
+
*/
|
|
124
|
+
static from(value) {
|
|
125
|
+
if (value instanceof STNumber) {
|
|
126
|
+
return value;
|
|
127
|
+
}
|
|
128
|
+
if (typeof value === 'string') {
|
|
129
|
+
return STNumber.fromValue(value);
|
|
130
|
+
}
|
|
131
|
+
throw new Error('STNumber.from: Only string or STNumber instance is supported');
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Construct from a number string (integer, decimal, or scientific notation).
|
|
135
|
+
* Handles normalization to XRPL Number constraints.
|
|
136
|
+
*
|
|
137
|
+
* @param val - The number as a string (e.g. '1.23', '-123e5').
|
|
138
|
+
* @returns STNumber instance
|
|
139
|
+
* @throws Error if val is not a valid number string.
|
|
140
|
+
*/
|
|
141
|
+
static fromValue(val) {
|
|
142
|
+
const { mantissa, exponent, isNegative } = extractNumberPartsFromString(val);
|
|
143
|
+
let normalizedMantissa;
|
|
144
|
+
let normalizedExponent;
|
|
145
|
+
if (mantissa === BigInt(0) && exponent === 0 && !isNegative) {
|
|
146
|
+
normalizedMantissa = BigInt(0);
|
|
147
|
+
normalizedExponent = DEFAULT_VALUE_EXPONENT;
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
;
|
|
151
|
+
({ mantissa: normalizedMantissa, exponent: normalizedExponent } =
|
|
152
|
+
normalize(mantissa, exponent));
|
|
153
|
+
}
|
|
154
|
+
const bytes = new Uint8Array(12);
|
|
155
|
+
(0, utils_1.writeInt64BE)(bytes, normalizedMantissa, 0);
|
|
156
|
+
(0, utils_1.writeInt32BE)(bytes, normalizedExponent, 8);
|
|
157
|
+
return new STNumber(bytes);
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Read a STNumber from a BinaryParser stream (12 bytes).
|
|
161
|
+
* @param parser - BinaryParser positioned at the start of a number
|
|
162
|
+
* @returns STNumber instance
|
|
163
|
+
*/
|
|
164
|
+
static fromParser(parser) {
|
|
165
|
+
return new STNumber(parser.read(12));
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Convert this STNumber to a normalized string representation.
|
|
169
|
+
* The output is decimal or scientific notation, depending on exponent range.
|
|
170
|
+
* Follows XRPL convention: zero is "0", other values are normalized to a canonical string.
|
|
171
|
+
*
|
|
172
|
+
* @returns String representation of the value
|
|
173
|
+
*/
|
|
174
|
+
// eslint-disable-next-line complexity -- required
|
|
175
|
+
toJSON() {
|
|
176
|
+
const b = this.bytes;
|
|
177
|
+
if (!b || b.length !== 12)
|
|
178
|
+
throw new Error('STNumber internal bytes not set or wrong length');
|
|
179
|
+
// Signed 64-bit mantissa
|
|
180
|
+
const mantissa = (0, utils_1.readInt64BE)(b, 0);
|
|
181
|
+
// Signed 32-bit exponent
|
|
182
|
+
const exponent = (0, utils_1.readInt32BE)(b, 8);
|
|
183
|
+
// Special zero: XRPL encodes canonical zero as mantissa=0, exponent=DEFAULT_VALUE_EXPONENT.
|
|
184
|
+
if (mantissa === BigInt(0) && exponent === DEFAULT_VALUE_EXPONENT) {
|
|
185
|
+
return '0';
|
|
186
|
+
}
|
|
187
|
+
if (exponent === 0)
|
|
188
|
+
return mantissa.toString();
|
|
189
|
+
// Use scientific notation for small/large exponents, decimal otherwise
|
|
190
|
+
if (exponent < -25 || exponent > -5) {
|
|
191
|
+
return `${mantissa}e${exponent}`;
|
|
192
|
+
}
|
|
193
|
+
// Decimal rendering for -25 <= exp <= -5
|
|
194
|
+
const isNegative = mantissa < BigInt(0);
|
|
195
|
+
const mantissaAbs = mantissa < BigInt(0) ? -mantissa : mantissa;
|
|
196
|
+
const padPrefix = 27;
|
|
197
|
+
const padSuffix = 23;
|
|
198
|
+
const mantissaStr = mantissaAbs.toString();
|
|
199
|
+
const rawValue = '0'.repeat(padPrefix) + mantissaStr + '0'.repeat(padSuffix);
|
|
200
|
+
const OFFSET = exponent + 43;
|
|
201
|
+
const integerPart = rawValue.slice(0, OFFSET).replace(/^0+/, '') || '0';
|
|
202
|
+
const fractionPart = rawValue.slice(OFFSET).replace(/0+$/, '');
|
|
203
|
+
return `${isNegative ? '-' : ''}${integerPart}${fractionPart ? '.' + fractionPart : ''}`;
|
|
204
|
+
}
|
|
205
|
+
getSType() {
|
|
206
|
+
return serialized_type_1.SerializedTypeID.STI_NUMBER;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
exports.STNumber = STNumber;
|
|
210
|
+
/** 12 zero bytes, represents canonical zero. */
|
|
211
|
+
STNumber.defaultBytes = new Uint8Array(12);
|
|
212
|
+
//# sourceMappingURL=st-number.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"st-number.js","sourceRoot":"","sources":["../../../src/types/st-number.ts"],"names":[],"mappings":";;;AACA,uDAAoE;AACpE,oCAA+E;AAE/E;;;GAGG;AACH,MAAM,YAAY,GAAG,MAAM,CAAC,kBAAkB,CAAC,CAAA;AAC/C,MAAM,YAAY,GAAG,MAAM,CAAC,kBAAkB,CAAC,CAAA;AAC/C,MAAM,YAAY,GAAG,CAAC,KAAK,CAAA;AAC3B,MAAM,YAAY,GAAG,KAAK,CAAA;AAC1B,MAAM,sBAAsB,GAAG,CAAC,UAAU,CAAA;AAE1C;;;;;;;;;;;GAWG;AACH,SAAS,4BAA4B,CAAC,GAAW;IAK/C;;;;;;;;;;;;;;OAcG;IACH,sDAAsD;IACtD,MAAM,KAAK,GAAG,wDAAwD,CAAA;IACtE,MAAM,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;IAC7B,IAAI,CAAC,KAAK;QAAE,MAAM,IAAI,KAAK,CAAC,uCAAuC,GAAG,EAAE,CAAC,CAAA;IAEzE,MAAM,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,CAAC,GAAG,KAAK,CAAA;IAClD,4DAA4D;IAC5D,MAAM,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC,IAAI,GAAG,CAAA;IAE5D,IAAI,WAAW,GAAG,YAAY,CAAA;IAC9B,IAAI,QAAQ,GAAG,CAAC,CAAA;IAEhB,IAAI,QAAQ,EAAE;QACZ,WAAW,IAAI,QAAQ,CAAA;QACvB,QAAQ,IAAI,QAAQ,CAAC,MAAM,CAAA;KAC5B;IACD,IAAI,OAAO;QAAE,QAAQ,IAAI,QAAQ,CAAC,OAAO,EAAE,EAAE,CAAC,CAAA;IAE9C,IAAI,QAAQ,GAAG,MAAM,CAA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,GAAG,WAAW,CAAC,QAAQ,EAAE,CAAA;QAC1C,MAAM,QAAQ,GAAG,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,WAAW,GAAG,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,CAAA;QAC5E,MAAM,MAAM,GAAG,QAAQ,GAAG,EAAE,CAAA;QAC5B,MAAM,WAAW,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,GAAG,CAAA;QACvE,MAAM,YAAY,GAAG,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAA;QAE9D,OAAO,GAAG,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,WAAW,GAC3C,YAAY,CAAC,CAAC,CAAC,GAAG,GAAG,YAAY,CAAC,CAAC,CAAC,EACtC,EAAE,CAAA;IACJ,CAAC;IAED,QAAQ;QACN,OAAO,kCAAgB,CAAC,UAAU,CAAA;IACpC,CAAC;;AA1HH,4BA2HC;AA1HC,gDAAgD;AACzC,qBAAY,GAAG,IAAI,UAAU,CAAC,EAAE,CAAC,CAAA"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { XrplDefinitionsBase } from '../enums';
|
|
2
|
+
import { SerializedType, JsonObject, SerializedTypeID } from './serialized-type';
|
|
3
|
+
import { BinaryParser } from '../serdes/binary-parser';
|
|
4
|
+
/**
|
|
5
|
+
* Class for Serializing/Deserializing objects
|
|
6
|
+
*/
|
|
7
|
+
declare class STObject extends SerializedType {
|
|
8
|
+
/**
|
|
9
|
+
* Construct a STObject from a BinaryParser
|
|
10
|
+
*
|
|
11
|
+
* @param parser BinaryParser to read STObject from
|
|
12
|
+
* @returns A STObject object
|
|
13
|
+
*/
|
|
14
|
+
static fromParser(parser: BinaryParser): STObject;
|
|
15
|
+
/**
|
|
16
|
+
* Construct a STObject from a JSON object
|
|
17
|
+
*
|
|
18
|
+
* @param value An object to include
|
|
19
|
+
* @param filter optional, denote which field to include in serialized object
|
|
20
|
+
* @param definitions optional, types and values to use to encode/decode a transaction
|
|
21
|
+
* @returns a STObject object
|
|
22
|
+
*/
|
|
23
|
+
static from<T extends STObject | JsonObject>(value: T, filter?: (...any: any[]) => boolean, definitions?: XrplDefinitionsBase): STObject;
|
|
24
|
+
/**
|
|
25
|
+
* Get the JSON interpretation of this.bytes
|
|
26
|
+
* @param definitions rippled definitions used to parse the values of transaction types and such.
|
|
27
|
+
* Can be customized for sidechains and amendments.
|
|
28
|
+
* @returns a JSON object
|
|
29
|
+
*/
|
|
30
|
+
toJSON(definitions?: XrplDefinitionsBase): JsonObject;
|
|
31
|
+
getSType(): SerializedTypeID;
|
|
32
|
+
}
|
|
33
|
+
export { STObject };
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.STObject = void 0;
|
|
4
|
+
const enums_1 = require("../enums");
|
|
5
|
+
const serialized_type_1 = require("./serialized-type");
|
|
6
|
+
const ripple_address_codec_1 = require("@transia/ripple-address-codec");
|
|
7
|
+
const binary_parser_1 = require("../serdes/binary-parser");
|
|
8
|
+
const binary_serializer_1 = require("../serdes/binary-serializer");
|
|
9
|
+
const st_array_1 = require("./st-array");
|
|
10
|
+
const uint_64_1 = require("./uint-64");
|
|
11
|
+
const OBJECT_END_MARKER_BYTE = Uint8Array.from([0xe1]);
|
|
12
|
+
const OBJECT_END_MARKER = 'ObjectEndMarker';
|
|
13
|
+
const ST_OBJECT = 'STObject';
|
|
14
|
+
const DESTINATION = 'Destination';
|
|
15
|
+
const ACCOUNT = 'Account';
|
|
16
|
+
const SOURCE_TAG = 'SourceTag';
|
|
17
|
+
const DEST_TAG = 'DestinationTag';
|
|
18
|
+
/**
|
|
19
|
+
* Break down an X-Address into an account and a tag
|
|
20
|
+
*
|
|
21
|
+
* @param field Name of field
|
|
22
|
+
* @param xAddress X-Address corresponding to the field
|
|
23
|
+
*/
|
|
24
|
+
function handleXAddress(field, xAddress) {
|
|
25
|
+
const decoded = (0, ripple_address_codec_1.xAddressToClassicAddress)(xAddress);
|
|
26
|
+
let tagName;
|
|
27
|
+
if (field === DESTINATION)
|
|
28
|
+
tagName = DEST_TAG;
|
|
29
|
+
else if (field === ACCOUNT)
|
|
30
|
+
tagName = SOURCE_TAG;
|
|
31
|
+
else if (decoded.tag !== false)
|
|
32
|
+
throw new Error(`${field} cannot have an associated tag`);
|
|
33
|
+
return decoded.tag !== false
|
|
34
|
+
? { [field]: decoded.classicAddress, [tagName]: decoded.tag }
|
|
35
|
+
: { [field]: decoded.classicAddress };
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Validate that two objects don't both have the same tag fields
|
|
39
|
+
*
|
|
40
|
+
* @param obj1 First object to check for tags
|
|
41
|
+
* @param obj2 Second object to check for tags
|
|
42
|
+
* @throws When both objects have SourceTag or DestinationTag
|
|
43
|
+
*/
|
|
44
|
+
function checkForDuplicateTags(obj1, obj2) {
|
|
45
|
+
if (!(obj1[SOURCE_TAG] === undefined || obj2[SOURCE_TAG] === undefined))
|
|
46
|
+
throw new Error('Cannot have Account X-Address and SourceTag');
|
|
47
|
+
if (!(obj1[DEST_TAG] === undefined || obj2[DEST_TAG] === undefined))
|
|
48
|
+
throw new Error('Cannot have Destination X-Address and DestinationTag');
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Class for Serializing/Deserializing objects
|
|
52
|
+
*/
|
|
53
|
+
class STObject extends serialized_type_1.SerializedType {
|
|
54
|
+
/**
|
|
55
|
+
* Construct a STObject from a BinaryParser
|
|
56
|
+
*
|
|
57
|
+
* @param parser BinaryParser to read STObject from
|
|
58
|
+
* @returns A STObject object
|
|
59
|
+
*/
|
|
60
|
+
static fromParser(parser) {
|
|
61
|
+
const list = new binary_serializer_1.BytesList();
|
|
62
|
+
const bytes = new binary_serializer_1.BinarySerializer(list);
|
|
63
|
+
while (!parser.end()) {
|
|
64
|
+
const field = parser.readField();
|
|
65
|
+
if (field.name === OBJECT_END_MARKER) {
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
const associatedValue = parser.readFieldValue(field);
|
|
69
|
+
bytes.writeFieldAndValue(field, associatedValue);
|
|
70
|
+
if (field.type.name === ST_OBJECT) {
|
|
71
|
+
bytes.put(OBJECT_END_MARKER_BYTE);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return new STObject(list.toBytes());
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Construct a STObject from a JSON object
|
|
78
|
+
*
|
|
79
|
+
* @param value An object to include
|
|
80
|
+
* @param filter optional, denote which field to include in serialized object
|
|
81
|
+
* @param definitions optional, types and values to use to encode/decode a transaction
|
|
82
|
+
* @returns a STObject object
|
|
83
|
+
*/
|
|
84
|
+
static from(value, filter, definitions = enums_1.DEFAULT_DEFINITIONS) {
|
|
85
|
+
if (value instanceof STObject) {
|
|
86
|
+
return value;
|
|
87
|
+
}
|
|
88
|
+
const list = new binary_serializer_1.BytesList();
|
|
89
|
+
const bytes = new binary_serializer_1.BinarySerializer(list);
|
|
90
|
+
let isUnlModify = false;
|
|
91
|
+
const xAddressDecoded = Object.entries(value).reduce((acc, [key, val]) => {
|
|
92
|
+
let handled = undefined;
|
|
93
|
+
if (val && (0, ripple_address_codec_1.isValidXAddress)(val.toString())) {
|
|
94
|
+
handled = handleXAddress(key, val.toString());
|
|
95
|
+
checkForDuplicateTags(handled, value);
|
|
96
|
+
}
|
|
97
|
+
return Object.assign(acc, handled !== null && handled !== void 0 ? handled : { [key]: val });
|
|
98
|
+
}, {});
|
|
99
|
+
function isValidFieldInstance(f) {
|
|
100
|
+
return (f !== undefined &&
|
|
101
|
+
xAddressDecoded[f.name] !== undefined &&
|
|
102
|
+
f.isSerialized);
|
|
103
|
+
}
|
|
104
|
+
let sorted = Object.keys(xAddressDecoded)
|
|
105
|
+
.map((f) => {
|
|
106
|
+
if (!(f in definitions.field)) {
|
|
107
|
+
if (f[0] === f[0].toLowerCase())
|
|
108
|
+
return undefined;
|
|
109
|
+
throw new Error(`Field ${f} is not defined in the definitions`);
|
|
110
|
+
}
|
|
111
|
+
return definitions.field[f];
|
|
112
|
+
})
|
|
113
|
+
.filter(isValidFieldInstance)
|
|
114
|
+
.sort((a, b) => {
|
|
115
|
+
return a.ordinal - b.ordinal;
|
|
116
|
+
});
|
|
117
|
+
if (filter !== undefined) {
|
|
118
|
+
sorted = sorted.filter(filter);
|
|
119
|
+
}
|
|
120
|
+
sorted.forEach((field) => {
|
|
121
|
+
var _a;
|
|
122
|
+
const associatedValue = field.type.name === ST_OBJECT
|
|
123
|
+
? this.from(xAddressDecoded[field.name], undefined, definitions)
|
|
124
|
+
: field.type.name === 'STArray'
|
|
125
|
+
? st_array_1.STArray.from(xAddressDecoded[field.name], definitions)
|
|
126
|
+
: field.type.name === 'UInt64'
|
|
127
|
+
? uint_64_1.UInt64.from(xAddressDecoded[field.name], field.name)
|
|
128
|
+
: ((_a = field.associatedType) === null || _a === void 0 ? void 0 : _a.from)
|
|
129
|
+
? field.associatedType.from(xAddressDecoded[field.name])
|
|
130
|
+
: (() => {
|
|
131
|
+
throw new Error(`Type ${field.type.name} for field ${field.name} is missing associatedType.from`);
|
|
132
|
+
})();
|
|
133
|
+
if (associatedValue == undefined) {
|
|
134
|
+
throw new TypeError(`Unable to interpret "${field.name}: ${xAddressDecoded[field.name]}".`);
|
|
135
|
+
}
|
|
136
|
+
if (associatedValue.name === 'UNLModify') {
|
|
137
|
+
// triggered when the TransactionType field has a value of 'UNLModify'
|
|
138
|
+
isUnlModify = true;
|
|
139
|
+
}
|
|
140
|
+
// true when in the UNLModify pseudotransaction (after the transaction type has been processed) and working with the
|
|
141
|
+
// Account field
|
|
142
|
+
// The Account field must not be a part of the UNLModify pseudotransaction encoding, due to a bug in rippled
|
|
143
|
+
const isUnlModifyWorkaround = field.name == 'Account' && isUnlModify;
|
|
144
|
+
bytes.writeFieldAndValue(field, associatedValue, isUnlModifyWorkaround);
|
|
145
|
+
if (field.type.name === ST_OBJECT) {
|
|
146
|
+
bytes.put(OBJECT_END_MARKER_BYTE);
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
return new STObject(list.toBytes());
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Get the JSON interpretation of this.bytes
|
|
153
|
+
* @param definitions rippled definitions used to parse the values of transaction types and such.
|
|
154
|
+
* Can be customized for sidechains and amendments.
|
|
155
|
+
* @returns a JSON object
|
|
156
|
+
*/
|
|
157
|
+
toJSON(definitions) {
|
|
158
|
+
const objectParser = new binary_parser_1.BinaryParser(this.toString(), definitions);
|
|
159
|
+
const accumulator = {};
|
|
160
|
+
while (!objectParser.end()) {
|
|
161
|
+
const field = objectParser.readField();
|
|
162
|
+
if (field.name === OBJECT_END_MARKER) {
|
|
163
|
+
break;
|
|
164
|
+
}
|
|
165
|
+
accumulator[field.name] = objectParser
|
|
166
|
+
.readFieldValue(field)
|
|
167
|
+
.toJSON(definitions, field.name);
|
|
168
|
+
}
|
|
169
|
+
return accumulator;
|
|
170
|
+
}
|
|
171
|
+
getSType() {
|
|
172
|
+
return serialized_type_1.SerializedTypeID.STI_OBJECT;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
exports.STObject = STObject;
|
|
176
|
+
//# sourceMappingURL=st-object.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"st-object.js","sourceRoot":"","sources":["../../../src/types/st-object.ts"],"names":[],"mappings":";;;AAAA,oCAKiB;AACjB,uDAAgF;AAChF,wEAGsC;AACtC,2DAAsD;AACtD,mEAAyE;AAEzE,yCAAoC;AACpC,uCAAkC;AAElC,MAAM,sBAAsB,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAA;AACtD,MAAM,iBAAi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