ripple-binary-codec 1.0.2 → 1.0.3-mpt-beta
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/README.md +3 -3
- package/dist/binary.d.ts +34 -20
- package/dist/binary.js +51 -34
- package/dist/binary.js.map +1 -1
- package/dist/coretypes.d.ts +9 -9
- package/dist/coretypes.js +33 -9
- package/dist/coretypes.js.map +1 -1
- package/dist/enums/bytes.d.ts +25 -0
- package/dist/enums/bytes.js +63 -0
- package/dist/enums/bytes.js.map +1 -0
- package/dist/enums/constants.d.ts +4 -0
- package/dist/enums/constants.js +8 -0
- package/dist/enums/constants.js.map +1 -0
- package/dist/enums/definitions.json +3066 -1760
- package/dist/enums/field.d.ts +28 -0
- package/dist/enums/field.js +58 -0
- package/dist/enums/field.js.map +1 -0
- package/dist/enums/index.d.ts +12 -46
- package/dist/enums/index.js +22 -110
- package/dist/enums/index.js.map +1 -1
- package/dist/enums/src/enums/definitions.json +3073 -0
- package/dist/enums/utils-renumber.js +20 -20
- package/dist/enums/utils-renumber.js.map +1 -1
- package/dist/enums/xrpl-definitions-base.d.ts +44 -0
- package/dist/enums/xrpl-definitions-base.js +59 -0
- package/dist/enums/xrpl-definitions-base.js.map +1 -0
- package/dist/enums/xrpl-definitions.d.ts +21 -0
- package/dist/enums/xrpl-definitions.js +29 -0
- package/dist/enums/xrpl-definitions.js.map +1 -0
- package/dist/hash-prefixes.d.ts +1 -2
- package/dist/hash-prefixes.js +7 -6
- package/dist/hash-prefixes.js.map +1 -1
- package/dist/hashes.d.ts +7 -8
- package/dist/hashes.js +23 -44
- package/dist/hashes.js.map +1 -1
- package/dist/index.d.ts +16 -17
- package/dist/index.js +65 -40
- package/dist/index.js.map +1 -1
- package/dist/ledger-hashes.d.ts +6 -3
- package/dist/ledger-hashes.js +40 -33
- package/dist/ledger-hashes.js.map +1 -1
- package/dist/quality.d.ts +3 -4
- package/dist/quality.js +20 -19
- package/dist/quality.js.map +1 -1
- package/dist/serdes/binary-parser.d.ts +8 -6
- package/dist/serdes/binary-parser.js +74 -64
- package/dist/serdes/binary-parser.js.map +1 -1
- package/dist/serdes/binary-serializer.d.ts +10 -11
- package/dist/serdes/binary-serializer.js +50 -48
- package/dist/serdes/binary-serializer.js.map +1 -1
- package/dist/shamap.d.ts +6 -7
- package/dist/shamap.js +74 -97
- package/dist/shamap.js.map +1 -1
- package/dist/src/binary.d.ts +90 -0
- package/dist/src/binary.js +128 -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 +63 -0
- package/dist/src/enums/bytes.js.map +1 -0
- package/dist/src/enums/constants.d.ts +4 -0
- package/dist/src/enums/constants.js +8 -0
- package/dist/src/enums/constants.js.map +1 -0
- package/dist/src/enums/definitions.json +3068 -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 +44 -0
- package/dist/src/enums/xrpl-definitions-base.js +59 -0
- package/dist/src/enums/xrpl-definitions-base.js.map +1 -0
- package/dist/src/enums/xrpl-definitions.d.ts +21 -0
- package/dist/src/enums/xrpl-definitions.js +29 -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 +41 -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 +64 -0
- package/dist/src/index.js +123 -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 +35 -0
- package/dist/src/types/account-id.js +69 -0
- package/dist/src/types/account-id.js.map +1 -0
- package/dist/src/types/amount.d.ts +91 -0
- package/dist/src/types/amount.js +289 -0
- package/dist/src/types/amount.js.map +1 -0
- package/dist/src/types/blob.d.ts +24 -0
- package/dist/src/types/blob.js +43 -0
- package/dist/src/types/blob.js.map +1 -0
- package/dist/src/types/currency.d.ts +28 -0
- package/dist/src/types/currency.js +127 -0
- package/dist/src/types/currency.js.map +1 -0
- package/dist/src/types/hash-128.d.ts +16 -0
- package/dist/src/types/hash-128.js +32 -0
- package/dist/src/types/hash-128.js.map +1 -0
- package/dist/src/types/hash-160.d.ts +10 -0
- package/dist/src/types/hash-160.js +19 -0
- package/dist/src/types/hash-160.js.map +1 -0
- package/dist/src/types/hash-192.d.ts +10 -0
- package/dist/src/types/hash-192.js +19 -0
- package/dist/src/types/hash-192.js.map +1 -0
- package/dist/src/types/hash-256.d.ts +10 -0
- package/dist/src/types/hash-256.js +16 -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 +73 -0
- package/dist/src/types/hash.js.map +1 -0
- package/dist/src/types/index.d.ts +19 -0
- package/dist/src/types/index.js +64 -0
- package/dist/src/types/index.js.map +1 -0
- package/dist/src/types/issue.d.ts +38 -0
- package/dist/src/types/issue.js +81 -0
- package/dist/src/types/issue.js.map +1 -0
- package/dist/src/types/path-set.d.ts +36 -0
- package/dist/src/types/path-set.js +233 -0
- package/dist/src/types/path-set.js.map +1 -0
- package/dist/src/types/serialized-type.d.ts +70 -0
- package/dist/src/types/serialized-type.js +105 -0
- package/dist/src/types/serialized-type.js.map +1 -0
- package/dist/src/types/st-array.d.ts +31 -0
- package/dist/src/types/st-array.js +86 -0
- package/dist/src/types/st-array.js.map +1 -0
- package/dist/src/types/st-object.d.ts +32 -0
- package/dist/src/types/st-object.js +155 -0
- package/dist/src/types/st-object.js.map +1 -0
- package/dist/src/types/uint-16.d.ts +24 -0
- package/dist/src/types/uint-16.js +45 -0
- package/dist/src/types/uint-16.js.map +1 -0
- package/dist/src/types/uint-32.d.ts +24 -0
- package/dist/src/types/uint-32.js +50 -0
- package/dist/src/types/uint-32.js.map +1 -0
- package/dist/src/types/uint-64.d.ts +37 -0
- package/dist/src/types/uint-64.js +86 -0
- package/dist/src/types/uint-64.js.map +1 -0
- package/dist/src/types/uint-8.d.ts +24 -0
- package/dist/src/types/uint-8.js +46 -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 +30 -0
- package/dist/src/types/vector-256.js +73 -0
- package/dist/src/types/vector-256.js.map +1 -0
- package/dist/src/types/xchain-bridge.d.ts +44 -0
- package/dist/src/types/xchain-bridge.js +102 -0
- package/dist/src/types/xchain-bridge.js.map +1 -0
- package/dist/src/utils.d.ts +47 -0
- package/dist/src/utils.js +137 -0
- package/dist/src/utils.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types/account-id.d.ts +2 -3
- package/dist/types/account-id.js +29 -37
- package/dist/types/account-id.js.map +1 -1
- package/dist/types/amount.d.ts +33 -10
- package/dist/types/amount.js +181 -101
- package/dist/types/amount.js.map +1 -1
- package/dist/types/blob.d.ts +3 -4
- package/dist/types/blob.js +16 -27
- package/dist/types/blob.js.map +1 -1
- package/dist/types/currency.d.ts +5 -13
- package/dist/types/currency.js +53 -66
- package/dist/types/currency.js.map +1 -1
- package/dist/types/hash-128.d.ts +8 -3
- package/dist/types/hash-128.js +23 -22
- package/dist/types/hash-128.js.map +1 -1
- package/dist/types/hash-160.d.ts +2 -3
- package/dist/types/hash-160.js +7 -24
- package/dist/types/hash-160.js.map +1 -1
- package/dist/types/hash-192.d.ts +10 -0
- package/dist/types/hash-192.js +19 -0
- package/dist/types/hash-192.js.map +1 -0
- package/dist/types/hash-256.d.ts +2 -3
- package/dist/types/hash-256.js +7 -22
- package/dist/types/hash-256.js.map +1 -1
- package/dist/types/hash.d.ts +4 -5
- package/dist/types/hash.js +25 -39
- package/dist/types/hash.js.map +1 -1
- package/dist/types/index.d.ts +19 -33
- package/dist/types/index.js +44 -24
- package/dist/types/index.js.map +1 -1
- package/dist/types/issue.d.ts +38 -0
- package/dist/types/issue.js +81 -0
- package/dist/types/issue.js.map +1 -0
- package/dist/types/path-set.d.ts +2 -2
- package/dist/types/path-set.js +73 -94
- package/dist/types/path-set.js.map +1 -1
- package/dist/types/serialized-type.d.ts +26 -18
- package/dist/types/serialized-type.js +50 -60
- package/dist/types/serialized-type.js.map +1 -1
- package/dist/types/st-array.d.ts +7 -4
- package/dist/types/st-array.js +36 -47
- package/dist/types/st-array.js.map +1 -1
- package/dist/types/st-object.d.ts +8 -5
- package/dist/types/st-object.js +73 -74
- package/dist/types/st-object.js.map +1 -1
- package/dist/types/uint-16.d.ts +3 -4
- package/dist/types/uint-16.js +20 -33
- package/dist/types/uint-16.js.map +1 -1
- package/dist/types/uint-32.d.ts +3 -4
- package/dist/types/uint-32.js +23 -36
- package/dist/types/uint-32.js.map +1 -1
- package/dist/types/uint-64.d.ts +5 -6
- package/dist/types/uint-64.js +44 -48
- package/dist/types/uint-64.js.map +1 -1
- package/dist/types/uint-8.d.ts +3 -4
- package/dist/types/uint-8.js +21 -33
- package/dist/types/uint-8.js.map +1 -1
- package/dist/types/uint.d.ts +5 -5
- package/dist/types/uint.js +17 -27
- package/dist/types/uint.js.map +1 -1
- package/dist/types/vector-256.d.ts +3 -4
- package/dist/types/vector-256.js +28 -45
- package/dist/types/vector-256.js.map +1 -1
- package/dist/types/xchain-bridge.d.ts +44 -0
- package/dist/types/xchain-bridge.js +102 -0
- package/dist/types/xchain-bridge.js.map +1 -0
- package/dist/utils.d.ts +47 -0
- package/dist/utils.js +137 -0
- package/dist/utils.js.map +1 -0
- package/package.json +23 -33
- package/src/README.md +5 -0
- package/src/binary.ts +194 -0
- package/src/coretypes.ts +31 -0
- package/src/enums/README.md +144 -0
- package/src/enums/bytes.ts +74 -0
- package/src/enums/constants.ts +4 -0
- package/src/enums/definitions.json +3073 -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 +111 -0
- package/src/enums/xrpl-definitions.ts +32 -0
- package/src/hash-prefixes.ts +40 -0
- package/src/hashes.ts +75 -0
- package/src/index.ts +153 -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 +186 -0
- package/src/types/account-id.ts +86 -0
- package/src/types/amount.ts +362 -0
- package/src/types/blob.ts +46 -0
- package/src/types/currency.ts +140 -0
- package/src/types/hash-128.ts +33 -0
- package/src/types/hash-160.ts +19 -0
- package/src/types/hash-192.ts +19 -0
- package/src/types/hash-256.ts +15 -0
- package/src/types/hash.ts +83 -0
- package/src/types/index.ts +66 -0
- package/src/types/issue.ts +96 -0
- package/src/types/path-set.ts +290 -0
- package/src/types/serialized-type.ts +122 -0
- package/src/types/st-array.ts +113 -0
- package/src/types/st-object.ts +192 -0
- package/src/types/uint-16.ts +53 -0
- package/src/types/uint-32.ts +59 -0
- package/src/types/uint-64.ts +104 -0
- package/src/types/uint-8.ts +52 -0
- package/src/types/uint.ts +60 -0
- package/src/types/vector-256.ts +79 -0
- package/src/types/xchain-bridge.ts +128 -0
- package/src/utils.ts +152 -0
- package/HISTORY.md +0 -74
- package/test/amount.test.js +0 -43
- package/test/binary-json.test.js +0 -47
- package/test/binary-parser.test.js +0 -397
- package/test/binary-serializer.test.js +0 -248
- 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 -3721
- 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/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/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/x-codec-fixtures.json +0 -188
- package/test/hash.test.js +0 -82
- package/test/ledger.test.js +0 -29
- package/test/lower-case-hex.test.js +0 -45
- package/test/pseudo-transaction.test.js +0 -38
- package/test/quality.test.js +0 -15
- package/test/shamap.test.js +0 -88
- package/test/signing-data-encoding.test.js +0 -129
- package/test/tx-encode-decode.test.js +0 -80
- package/test/types.test.js +0 -34
- package/test/uint.test.js +0 -40
- package/test/utils.js +0 -29
- package/test/x-address.test.js +0 -147
package/dist/index.js
CHANGED
|
@@ -1,70 +1,99 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
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;
|
|
4
|
+
const coretypes_1 = require("./coretypes");
|
|
5
|
+
const ledger_hashes_1 = require("./ledger-hashes");
|
|
6
|
+
Object.defineProperty(exports, "decodeLedgerData", { enumerable: true, get: function () { return ledger_hashes_1.decodeLedgerData; } });
|
|
7
|
+
const enums_1 = require("./enums");
|
|
8
|
+
Object.defineProperty(exports, "XrplDefinitionsBase", { enumerable: true, get: function () { return enums_1.XrplDefinitionsBase; } });
|
|
9
|
+
Object.defineProperty(exports, "TRANSACTION_TYPES", { enumerable: true, get: function () { return enums_1.TRANSACTION_TYPES; } });
|
|
10
|
+
Object.defineProperty(exports, "DEFAULT_DEFINITIONS", { enumerable: true, get: function () { return enums_1.DEFAULT_DEFINITIONS; } });
|
|
11
|
+
const xrpl_definitions_1 = require("./enums/xrpl-definitions");
|
|
12
|
+
Object.defineProperty(exports, "XrplDefinitions", { enumerable: true, get: function () { return xrpl_definitions_1.XrplDefinitions; } });
|
|
13
|
+
const types_1 = require("./types");
|
|
14
|
+
Object.defineProperty(exports, "coreTypes", { enumerable: true, get: function () { return types_1.coreTypes; } });
|
|
15
|
+
const utils_1 = require("@xrplf/isomorphic/utils");
|
|
16
|
+
const { signingData, signingClaimData, multiSigningData, binaryToJSON, serializeObject, } = coretypes_1.binary;
|
|
6
17
|
/**
|
|
7
18
|
* Decode a transaction
|
|
8
19
|
*
|
|
9
20
|
* @param binary hex-string of the encoded transaction
|
|
21
|
+
* @param definitions Custom rippled types to use instead of the default. Used for sidechains and amendments.
|
|
10
22
|
* @returns the JSON representation of the transaction
|
|
11
23
|
*/
|
|
12
|
-
function decode(binary) {
|
|
13
|
-
|
|
14
|
-
|
|
24
|
+
function decode(binary, definitions) {
|
|
25
|
+
if (typeof binary !== 'string') {
|
|
26
|
+
throw new Error('binary must be a hex string');
|
|
27
|
+
}
|
|
28
|
+
return binaryToJSON(binary, definitions);
|
|
15
29
|
}
|
|
30
|
+
exports.decode = decode;
|
|
16
31
|
/**
|
|
17
32
|
* Encode a transaction
|
|
18
33
|
*
|
|
19
34
|
* @param json The JSON representation of a transaction
|
|
35
|
+
* @param definitions Custom rippled types to use instead of the default. Used for sidechains and amendments.
|
|
36
|
+
*
|
|
20
37
|
* @returns A hex-string of the encoded transaction
|
|
21
38
|
*/
|
|
22
|
-
function encode(json) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
39
|
+
function encode(json, definitions) {
|
|
40
|
+
if (typeof json !== 'object') {
|
|
41
|
+
throw new Error();
|
|
42
|
+
}
|
|
43
|
+
return (0, utils_1.bytesToHex)(serializeObject(json, { definitions }));
|
|
27
44
|
}
|
|
45
|
+
exports.encode = encode;
|
|
28
46
|
/**
|
|
29
47
|
* Encode a transaction and prepare for signing
|
|
30
48
|
*
|
|
31
49
|
* @param json JSON object representing the transaction
|
|
32
50
|
* @param signer string representing the account to sign the transaction with
|
|
51
|
+
* @param definitions Custom rippled types to use instead of the default. Used for sidechains and amendments.
|
|
33
52
|
* @returns a hex string of the encoded transaction
|
|
34
53
|
*/
|
|
35
|
-
function encodeForSigning(json) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
54
|
+
function encodeForSigning(json, definitions) {
|
|
55
|
+
if (typeof json !== 'object') {
|
|
56
|
+
throw new Error();
|
|
57
|
+
}
|
|
58
|
+
return (0, utils_1.bytesToHex)(signingData(json, coretypes_1.HashPrefix.transactionSig, {
|
|
59
|
+
definitions,
|
|
60
|
+
}));
|
|
40
61
|
}
|
|
62
|
+
exports.encodeForSigning = encodeForSigning;
|
|
41
63
|
/**
|
|
42
64
|
* Encode a transaction and prepare for signing with a claim
|
|
43
65
|
*
|
|
44
66
|
* @param json JSON object representing the transaction
|
|
45
67
|
* @param signer string representing the account to sign the transaction with
|
|
68
|
+
* @param definitions Custom rippled types to use instead of the default. Used for sidechains and amendments.
|
|
46
69
|
* @returns a hex string of the encoded transaction
|
|
47
70
|
*/
|
|
48
71
|
function encodeForSigningClaim(json) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
72
|
+
if (typeof json !== 'object') {
|
|
73
|
+
throw new Error();
|
|
74
|
+
}
|
|
75
|
+
return (0, utils_1.bytesToHex)(signingClaimData(json));
|
|
53
76
|
}
|
|
77
|
+
exports.encodeForSigningClaim = encodeForSigningClaim;
|
|
54
78
|
/**
|
|
55
79
|
* Encode a transaction and prepare for multi-signing
|
|
56
80
|
*
|
|
57
81
|
* @param json JSON object representing the transaction
|
|
58
82
|
* @param signer string representing the account to sign the transaction with
|
|
83
|
+
* @param definitions Custom rippled types to use instead of the default. Used for sidechains and amendments.
|
|
59
84
|
* @returns a hex string of the encoded transaction
|
|
60
85
|
*/
|
|
61
|
-
function encodeForMultisigning(json, signer) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
86
|
+
function encodeForMultisigning(json, signer, definitions) {
|
|
87
|
+
if (typeof json !== 'object') {
|
|
88
|
+
throw new Error();
|
|
89
|
+
}
|
|
90
|
+
if (json['SigningPubKey'] !== '') {
|
|
91
|
+
throw new Error();
|
|
92
|
+
}
|
|
93
|
+
const definitionsOpt = definitions ? { definitions } : undefined;
|
|
94
|
+
return (0, utils_1.bytesToHex)(multiSigningData(json, signer, definitionsOpt));
|
|
67
95
|
}
|
|
96
|
+
exports.encodeForMultisigning = encodeForMultisigning;
|
|
68
97
|
/**
|
|
69
98
|
* Encode a quality value
|
|
70
99
|
*
|
|
@@ -72,9 +101,12 @@ function encodeForMultisigning(json, signer) {
|
|
|
72
101
|
* @returns a hex-string representing the quality
|
|
73
102
|
*/
|
|
74
103
|
function encodeQuality(value) {
|
|
75
|
-
|
|
76
|
-
|
|
104
|
+
if (typeof value !== 'string') {
|
|
105
|
+
throw new Error();
|
|
106
|
+
}
|
|
107
|
+
return (0, utils_1.bytesToHex)(coretypes_1.quality.encode(value));
|
|
77
108
|
}
|
|
109
|
+
exports.encodeQuality = encodeQuality;
|
|
78
110
|
/**
|
|
79
111
|
* Decode a quality value
|
|
80
112
|
*
|
|
@@ -82,17 +114,10 @@ function encodeQuality(value) {
|
|
|
82
114
|
* @returns a string representing the quality
|
|
83
115
|
*/
|
|
84
116
|
function decodeQuality(value) {
|
|
85
|
-
|
|
117
|
+
if (typeof value !== 'string') {
|
|
118
|
+
throw new Error();
|
|
119
|
+
}
|
|
86
120
|
return coretypes_1.quality.decode(value).toString();
|
|
87
121
|
}
|
|
88
|
-
|
|
89
|
-
decode: decode,
|
|
90
|
-
encode: encode,
|
|
91
|
-
encodeForSigning: encodeForSigning,
|
|
92
|
-
encodeForSigningClaim: encodeForSigningClaim,
|
|
93
|
-
encodeForMultisigning: encodeForMultisigning,
|
|
94
|
-
encodeQuality: encodeQuality,
|
|
95
|
-
decodeQuality: decodeQuality,
|
|
96
|
-
decodeLedgerData: ledger_hashes_1.decodeLedgerData,
|
|
97
|
-
};
|
|
122
|
+
exports.decodeQuality = decodeQuality;
|
|
98
123
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,2CAAyD;AACzD,mDAAkD;AAiJhD,iGAjJO,gCAAgB,OAiJP;AA9IlB,mCAIgB;AA6Id,oGAhJA,2BAAmB,OAgJA;AAFnB,kGA7IA,yBAAiB,OA6IA;AAGjB,oGA/IA,2BAAmB,OA+IA;AA7IrB,+DAA0D;AA2IxD,gGA3IO,kCAAe,OA2IP;AA1IjB,mCAAmC;AA6IjC,0FA7IO,iBAAS,OA6IP;AA5IX,mDAAoD;AAEpD,MAAM,EACJ,WAAW,EACX,gBAAgB,EAChB,gBAAgB,EAChB,YAAY,EACZ,eAAe,GAChB,GAAG,kBAAM,CAAA;AAEV;;;;;;GAMG;AACH,SAAS,MAAM,CAAC,MAAc,EAAE,WAAiC;IAC/D,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;QAC9B,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAA;KAC/C;IACD,OAAO,YAAY,CAAC,MAAM,EAAE,WAAW,CAAC,CAAA;AAC1C,CAAC;AA0GC,wBAAM;AAxGR;;;;;;;GAOG;AACH,SAAS,MAAM,CAAC,IAAY,EAAE,WAAiC;IAC7D,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;QAC5B,MAAM,IAAI,KAAK,EAAE,CAAA;KAClB;IACD,OAAO,IAAA,kBAAU,EAAC,eAAe,CAAC,IAAkB,EAAE,EAAE,WAAW,EAAE,CAAC,CAAC,CAAA;AACzE,CAAC;AA4FC,wBAAM;AA1FR;;;;;;;GAOG;AACH,SAAS,gBAAgB,CACvB,IAAY,EACZ,WAAiC;IAEjC,IAAI,OAAO,I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K,KAAK,QAAQ,EAAE;QAC7B,MAAM,IAAI,KAAK,EAAE,CAAA;KAClB;IACD,OAAO,mBAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,QAAQ,EAAE,CAAA;AACzC,CAAC;AASC,sCAAa"}
|
package/dist/ledger-hashes.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { Hash256 } from
|
|
2
|
-
import { JsonObject } from
|
|
1
|
+
import { Hash256 } from './types/hash-256';
|
|
2
|
+
import { JsonObject } from './types/serialized-type';
|
|
3
|
+
import { XrplDefinitionsBase } from './enums';
|
|
3
4
|
/**
|
|
4
5
|
* Function computing the hash of a transaction tree
|
|
5
6
|
*
|
|
@@ -39,7 +40,9 @@ declare function ledgerHash(header: ledgerObject): Hash256;
|
|
|
39
40
|
* Decodes a serialized ledger header
|
|
40
41
|
*
|
|
41
42
|
* @param binary A serialized ledger header
|
|
43
|
+
* @param definitions Type definitions to parse the ledger objects.
|
|
44
|
+
* Used if there are non-default ledger objects to decode.
|
|
42
45
|
* @returns A JSON object describing a ledger header
|
|
43
46
|
*/
|
|
44
|
-
declare function decodeLedgerData(binary: string): object;
|
|
47
|
+
declare function decodeLedgerData(binary: string, definitions?: XrplDefinitionsBase): object;
|
|
45
48
|
export { accountStateHash, transactionTreeHash, ledgerHash, decodeLedgerData };
|
package/dist/ledger-hashes.js
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.decodeLedgerData = exports.ledgerHash = exports.transactionTreeHash = exports.accountStateHash = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
var binary_parser_1 = require("./serdes/binary-parser");
|
|
4
|
+
const shamap_1 = require("./shamap");
|
|
5
|
+
const hash_prefixes_1 = require("./hash-prefixes");
|
|
6
|
+
const hashes_1 = require("./hashes");
|
|
7
|
+
const binary_1 = require("./binary");
|
|
8
|
+
const hash_256_1 = require("./types/hash-256");
|
|
9
|
+
const st_object_1 = require("./types/st-object");
|
|
10
|
+
const uint_64_1 = require("./types/uint-64");
|
|
11
|
+
const uint_32_1 = require("./types/uint-32");
|
|
12
|
+
const uint_8_1 = require("./types/uint-8");
|
|
13
|
+
const binary_parser_1 = require("./serdes/binary-parser");
|
|
15
14
|
/**
|
|
16
15
|
* Computes the hash of a list of objects
|
|
17
16
|
*
|
|
@@ -20,8 +19,8 @@ var binary_parser_1 = require("./serdes/binary-parser");
|
|
|
20
19
|
* @returns the hash of the SHAMap
|
|
21
20
|
*/
|
|
22
21
|
function computeHash(itemizer, itemsJson) {
|
|
23
|
-
|
|
24
|
-
itemsJson.forEach(
|
|
22
|
+
const map = new shamap_1.ShaMap();
|
|
23
|
+
itemsJson.forEach((item) => map.addItem(...itemizer(item)));
|
|
25
24
|
return map.hash();
|
|
26
25
|
}
|
|
27
26
|
/**
|
|
@@ -31,14 +30,16 @@ function computeHash(itemizer, itemsJson) {
|
|
|
31
30
|
* @returns a tuple of index and item to be added to SHAMap
|
|
32
31
|
*/
|
|
33
32
|
function transactionItemizer(json) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
33
|
+
if (!json.hash) {
|
|
34
|
+
throw new Error();
|
|
35
|
+
}
|
|
36
|
+
const index = hash_256_1.Hash256.from(json.hash);
|
|
37
|
+
const item = {
|
|
38
|
+
hashPrefix() {
|
|
38
39
|
return hash_prefixes_1.HashPrefix.transaction;
|
|
39
40
|
},
|
|
40
|
-
toBytesSink
|
|
41
|
-
|
|
41
|
+
toBytesSink(sink) {
|
|
42
|
+
const serializer = new binary_1.BinarySerializer(sink);
|
|
42
43
|
serializer.writeLengthEncoded(st_object_1.STObject.from(json));
|
|
43
44
|
serializer.writeLengthEncoded(st_object_1.STObject.from(json.metaData));
|
|
44
45
|
},
|
|
@@ -52,13 +53,13 @@ function transactionItemizer(json) {
|
|
|
52
53
|
* @returns a tuple of index and item to be added to SHAMap
|
|
53
54
|
*/
|
|
54
55
|
function entryItemizer(json) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
hashPrefix
|
|
56
|
+
const index = hash_256_1.Hash256.from(json.index);
|
|
57
|
+
const bytes = (0, binary_1.serializeObject)(json);
|
|
58
|
+
const item = {
|
|
59
|
+
hashPrefix() {
|
|
59
60
|
return hash_prefixes_1.HashPrefix.accountStateEntry;
|
|
60
61
|
},
|
|
61
|
-
toBytesSink
|
|
62
|
+
toBytesSink(sink) {
|
|
62
63
|
sink.put(bytes);
|
|
63
64
|
},
|
|
64
65
|
};
|
|
@@ -71,7 +72,7 @@ function entryItemizer(json) {
|
|
|
71
72
|
* @returns A Hash256 object
|
|
72
73
|
*/
|
|
73
74
|
function transactionTreeHash(param) {
|
|
74
|
-
|
|
75
|
+
const itemizer = transactionItemizer;
|
|
75
76
|
return computeHash(itemizer, param);
|
|
76
77
|
}
|
|
77
78
|
exports.transactionTreeHash = transactionTreeHash;
|
|
@@ -82,7 +83,7 @@ exports.transactionTreeHash = transactionTreeHash;
|
|
|
82
83
|
* @returns A Hash256 object
|
|
83
84
|
*/
|
|
84
85
|
function accountStateHash(param) {
|
|
85
|
-
|
|
86
|
+
const itemizer = entryItemizer;
|
|
86
87
|
return computeHash(itemizer, param);
|
|
87
88
|
}
|
|
88
89
|
exports.accountStateHash = accountStateHash;
|
|
@@ -93,12 +94,14 @@ exports.accountStateHash = accountStateHash;
|
|
|
93
94
|
* @returns the hash of header
|
|
94
95
|
*/
|
|
95
96
|
function ledgerHash(header) {
|
|
96
|
-
|
|
97
|
+
const hash = new hashes_1.Sha512Half();
|
|
97
98
|
hash.put(hash_prefixes_1.HashPrefix.ledgerHeader);
|
|
98
|
-
|
|
99
|
-
|
|
99
|
+
if (header.parent_close_time === undefined ||
|
|
100
|
+
header.close_flags === undefined) {
|
|
101
|
+
throw new Error();
|
|
102
|
+
}
|
|
100
103
|
uint_32_1.UInt32.from(header.ledger_index).toBytesSink(hash);
|
|
101
|
-
uint_64_1.UInt64.from(BigInt(header.total_coins)).toBytesSink(hash);
|
|
104
|
+
uint_64_1.UInt64.from(BigInt(String(header.total_coins))).toBytesSink(hash);
|
|
102
105
|
hash_256_1.Hash256.from(header.parent_hash).toBytesSink(hash);
|
|
103
106
|
hash_256_1.Hash256.from(header.transaction_hash).toBytesSink(hash);
|
|
104
107
|
hash_256_1.Hash256.from(header.account_hash).toBytesSink(hash);
|
|
@@ -113,11 +116,15 @@ exports.ledgerHash = ledgerHash;
|
|
|
113
116
|
* Decodes a serialized ledger header
|
|
114
117
|
*
|
|
115
118
|
* @param binary A serialized ledger header
|
|
119
|
+
* @param definitions Type definitions to parse the ledger objects.
|
|
120
|
+
* Used if there are non-default ledger objects to decode.
|
|
116
121
|
* @returns A JSON object describing a ledger header
|
|
117
122
|
*/
|
|
118
|
-
function decodeLedgerData(binary) {
|
|
119
|
-
|
|
120
|
-
|
|
123
|
+
function decodeLedgerData(binary, definitions) {
|
|
124
|
+
if (typeof binary !== 'string') {
|
|
125
|
+
throw new Error('binary must be a hex string');
|
|
126
|
+
}
|
|
127
|
+
const parser = new binary_parser_1.BinaryParser(binary, definitions);
|
|
121
128
|
return {
|
|
122
129
|
ledger_index: parser.readUInt32(),
|
|
123
130
|
total_coins: parser.readType(uint_64_1.UInt64).valueOf().toString(),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ledger-hashes.js","sourceRoot":"","sources":["../src/ledger-hashes.ts"],"names":[],"mappings":";;;AAAA
|
|
1
|
+
{"version":3,"file":"ledger-hashes.js","sourceRoot":"","sources":["../src/ledger-hashes.ts"],"names":[],"mappings":";;;AAAA,qCAAyD;AACzD,mDAA4C;AAC5C,qCAAqC;AACrC,qCAA4D;AAC5D,+CAA0C;AAC1C,iDAA4C;AAC5C,6CAAwC;AACxC,6CAA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AE;QAC/B,qBAAqB,EAAE,MAAM,CAAC,SAAS,EAAE;QACzC,WAAW,EAAE,MAAM,CAAC,SAAS,EAAE;KAChC,CAAA;AACH,CAAC;AAE2D,4CAAgB"}
|
package/dist/quality.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import { Decimal } from "decimal.js";
|
|
1
|
+
import BigNumber from 'bignumber.js';
|
|
3
2
|
/**
|
|
4
3
|
* class for encoding and decoding quality
|
|
5
4
|
*/
|
|
@@ -10,13 +9,13 @@ declare class quality {
|
|
|
10
9
|
* @param arg string representation of an amount
|
|
11
10
|
* @returns Serialized quality
|
|
12
11
|
*/
|
|
13
|
-
static encode(quality: string):
|
|
12
|
+
static encode(quality: string): Uint8Array;
|
|
14
13
|
/**
|
|
15
14
|
* Decode quality amount
|
|
16
15
|
*
|
|
17
16
|
* @param arg hex-string denoting serialized quality
|
|
18
17
|
* @returns deserialized quality
|
|
19
18
|
*/
|
|
20
|
-
static decode(quality: string):
|
|
19
|
+
static decode(quality: string): BigNumber;
|
|
21
20
|
}
|
|
22
21
|
export { quality };
|
package/dist/quality.js
CHANGED
|
@@ -1,41 +1,42 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.quality = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
7
|
+
const types_1 = require("./types");
|
|
8
|
+
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
9
|
+
const utils_1 = require("@xrplf/isomorphic/utils");
|
|
6
10
|
/**
|
|
7
11
|
* class for encoding and decoding quality
|
|
8
12
|
*/
|
|
9
|
-
|
|
10
|
-
function quality() {
|
|
11
|
-
}
|
|
13
|
+
class quality {
|
|
12
14
|
/**
|
|
13
15
|
* Encode quality amount
|
|
14
16
|
*
|
|
15
17
|
* @param arg string representation of an amount
|
|
16
18
|
* @returns Serialized quality
|
|
17
19
|
*/
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
static encode(quality) {
|
|
21
|
+
const decimal = (0, bignumber_js_1.default)(quality);
|
|
22
|
+
const exponent = ((decimal === null || decimal === void 0 ? void 0 : decimal.e) || 0) - 15;
|
|
23
|
+
const qualityString = decimal.times(`1e${-exponent}`).abs().toString();
|
|
24
|
+
const bytes = types_1.coreTypes.UInt64.from(BigInt(qualityString)).toBytes();
|
|
23
25
|
bytes[0] = exponent + 100;
|
|
24
26
|
return bytes;
|
|
25
|
-
}
|
|
27
|
+
}
|
|
26
28
|
/**
|
|
27
29
|
* Decode quality amount
|
|
28
30
|
*
|
|
29
31
|
* @param arg hex-string denoting serialized quality
|
|
30
32
|
* @returns deserialized quality
|
|
31
33
|
*/
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
return mantissa.times(
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
}());
|
|
34
|
+
static decode(quality) {
|
|
35
|
+
const bytes = (0, utils_1.hexToBytes)(quality).slice(-8);
|
|
36
|
+
const exponent = bytes[0] - 100;
|
|
37
|
+
const mantissa = new bignumber_js_1.default(`0x${(0, utils_1.bytesToHex)(bytes.slice(1))}`);
|
|
38
|
+
return mantissa.times(`1e${exponent}`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
40
41
|
exports.quality = quality;
|
|
41
42
|
//# sourceMappingURL=quality.js.map
|
package/dist/quality.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"quality.js","sourceRoot":"","sources":["../src/quality.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"quality.js","sourceRoot":"","sources":["../src/quality.ts"],"names":[],"mappings":";;;;;;AAAA,mCAAmC;AACnC,gEAAoC;AACpC,mDAAgE;AAEhE;;GAEG;AACH,MAAM,OAAO;IACX;;;;;OAKG;IACH,MAAM,CAAC,MAAM,CAAC,OAAe;QAC3B,MAAM,OAAO,GAAG,IAAA,sBAAS,EAAC,OAAO,CAAC,CAAA;QAClC,MAAM,QAAQ,GAAG,CAAC,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,CAAC,KAAI,CAAC,CAAC,GAAG,EAAE,CAAA;QACvC,MAAM,aAAa,GAAG,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAA;QACtE,MAAM,KAAK,GAAG,iBAAS,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC,OAAO,EAAE,CAAA;QACpE,KAAK,CAAC,CAAC,CAAC,GAAG,QAAQ,GAAG,GAAG,CAAA;QACzB,OAAO,KAAK,CAAA;IACd,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,MAAM,CAAC,OAAe;QAC3B,MAAM,KAAK,GAAG,IAAA,kBAAU,EAAC,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;QAC3C,MAAM,QAAQ,GAAG,KAAK,CAAC,CAAC,CAAC,GAAG,GAAG,CAAA;QAC/B,MAAM,QAAQ,GAAG,IAAI,sBAAS,CAAC,KAAK,IAAA,kBAAU,EAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAA;QACjE,OAAO,QAAQ,CAAC,KAAK,CAAC,KAAK,QAAQ,EAAE,CAAC,CAAA;IACxC,CAAC;CACF;AAEQ,0BAAO"}
|
|
@@ -1,17 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import { SerializedType } from "../types/serialized-type";
|
|
1
|
+
import { XrplDefinitionsBase, FieldInstance } from '../enums';
|
|
2
|
+
import { type SerializedType } from '../types/serialized-type';
|
|
4
3
|
/**
|
|
5
4
|
* BinaryParser is used to compute fields and values from a HexString
|
|
6
5
|
*/
|
|
7
6
|
declare class BinaryParser {
|
|
8
7
|
private bytes;
|
|
8
|
+
definitions: XrplDefinitionsBase;
|
|
9
9
|
/**
|
|
10
10
|
* Initialize bytes to a hex string
|
|
11
11
|
*
|
|
12
12
|
* @param hexBytes a hex string
|
|
13
|
+
* @param definitions Rippled definitions used to parse the values of transaction types and such.
|
|
14
|
+
* Can be customized for sidechains and amendments.
|
|
13
15
|
*/
|
|
14
|
-
constructor(hexBytes: string);
|
|
16
|
+
constructor(hexBytes: string, definitions?: XrplDefinitionsBase);
|
|
15
17
|
/**
|
|
16
18
|
* Peek the first byte of the BinaryParser
|
|
17
19
|
*
|
|
@@ -30,7 +32,7 @@ declare class BinaryParser {
|
|
|
30
32
|
* @param n The number of bytes to read
|
|
31
33
|
* @return The bytes
|
|
32
34
|
*/
|
|
33
|
-
read(n: number):
|
|
35
|
+
read(n: number): Uint8Array;
|
|
34
36
|
/**
|
|
35
37
|
* Read an integer of given size
|
|
36
38
|
*
|
|
@@ -48,7 +50,7 @@ declare class BinaryParser {
|
|
|
48
50
|
*
|
|
49
51
|
* @return The variable length bytes
|
|
50
52
|
*/
|
|
51
|
-
readVariableLength():
|
|
53
|
+
readVariableLength(): Uint8Array;
|
|
52
54
|
/**
|
|
53
55
|
* Reads the length of the variable length encoded bytes
|
|
54
56
|
*
|