@transia/ripple-binary-codec 1.4.6-alpha.8 → 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 +1650 -964
- 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 +1652 -966
- 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 -307
- 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/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
package/src/index.ts
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { quality, binary, HashPrefix } from './coretypes'
|
|
2
|
+
import { decodeLedgerData } from './ledger-hashes'
|
|
3
|
+
import { ClaimObject, BatchObject } from './binary'
|
|
4
|
+
import { JsonObject } from './types/serialized-type'
|
|
5
|
+
import {
|
|
6
|
+
XrplDefinitionsBase,
|
|
7
|
+
TRANSACTION_TYPES,
|
|
8
|
+
DEFAULT_DEFINITIONS,
|
|
9
|
+
} from './enums'
|
|
10
|
+
import { XrplDefinitions } from './enums/xrpl-definitions'
|
|
11
|
+
import { coreTypes } from './types'
|
|
12
|
+
import { bytesToHex } from '@transia/isomorphic/utils'
|
|
13
|
+
|
|
14
|
+
const {
|
|
15
|
+
signingData,
|
|
16
|
+
signingClaimData,
|
|
17
|
+
multiSigningData,
|
|
18
|
+
signingBatchData,
|
|
19
|
+
binaryToJSON,
|
|
20
|
+
serializeObject,
|
|
21
|
+
} = binary
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Decode a transaction
|
|
25
|
+
*
|
|
26
|
+
* @param binary hex-string of the encoded transaction
|
|
27
|
+
* @param definitions Custom rippled types to use instead of the default. Used for sidechains and amendments.
|
|
28
|
+
* @returns the JSON representation of the transaction
|
|
29
|
+
*/
|
|
30
|
+
function decode(binary: string, definitions?: XrplDefinitionsBase): JsonObject {
|
|
31
|
+
if (typeof binary !== 'string') {
|
|
32
|
+
throw new Error('binary must be a hex string')
|
|
33
|
+
}
|
|
34
|
+
return binaryToJSON(binary, definitions)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Encode a transaction
|
|
39
|
+
*
|
|
40
|
+
* @param json The JSON representation of a transaction
|
|
41
|
+
* @param definitions Custom rippled types to use instead of the default. Used for sidechains and amendments.
|
|
42
|
+
*
|
|
43
|
+
* @returns A hex-string of the encoded transaction
|
|
44
|
+
*/
|
|
45
|
+
function encode(json: object, definitions?: XrplDefinitionsBase): string {
|
|
46
|
+
if (typeof json !== 'object') {
|
|
47
|
+
throw new Error()
|
|
48
|
+
}
|
|
49
|
+
return bytesToHex(serializeObject(json as JsonObject, { definitions }))
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Encode a transaction and prepare for signing
|
|
54
|
+
*
|
|
55
|
+
* @param json JSON object representing the transaction
|
|
56
|
+
* @param signer string representing the account to sign the transaction with
|
|
57
|
+
* @param definitions Custom rippled types to use instead of the default. Used for sidechains and amendments.
|
|
58
|
+
* @returns a hex string of the encoded transaction
|
|
59
|
+
*/
|
|
60
|
+
function encodeForSigning(
|
|
61
|
+
json: object,
|
|
62
|
+
definitions?: XrplDefinitionsBase,
|
|
63
|
+
): string {
|
|
64
|
+
if (typeof json !== 'object') {
|
|
65
|
+
throw new Error()
|
|
66
|
+
}
|
|
67
|
+
return bytesToHex(
|
|
68
|
+
signingData(json as JsonObject, HashPrefix.transactionSig, {
|
|
69
|
+
definitions,
|
|
70
|
+
}),
|
|
71
|
+
)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Encode a payment channel claim for signing.
|
|
76
|
+
*
|
|
77
|
+
* @param json JSON object representing the claim.
|
|
78
|
+
* @returns a hex string of the encoded claim.
|
|
79
|
+
*/
|
|
80
|
+
function encodeForSigningClaim(json: object): string {
|
|
81
|
+
if (typeof json !== 'object') {
|
|
82
|
+
throw new Error()
|
|
83
|
+
}
|
|
84
|
+
return bytesToHex(signingClaimData(json as ClaimObject))
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Encode a transaction and prepare for multi-signing.
|
|
89
|
+
*
|
|
90
|
+
* @param json JSON object representing the transaction.
|
|
91
|
+
* @param signer string representing the account to sign the transaction with.
|
|
92
|
+
* @param definitions Custom rippled types to use instead of the default. Used for sidechains and amendments.
|
|
93
|
+
* @returns a hex string of the encoded transaction.
|
|
94
|
+
*/
|
|
95
|
+
function encodeForMultisigning(
|
|
96
|
+
json: object,
|
|
97
|
+
signer: string,
|
|
98
|
+
definitions?: XrplDefinitionsBase,
|
|
99
|
+
): string {
|
|
100
|
+
if (typeof json !== 'object') {
|
|
101
|
+
throw new Error()
|
|
102
|
+
}
|
|
103
|
+
if (json['SigningPubKey'] !== '') {
|
|
104
|
+
throw new Error()
|
|
105
|
+
}
|
|
106
|
+
const definitionsOpt = definitions ? { definitions } : undefined
|
|
107
|
+
return bytesToHex(
|
|
108
|
+
multiSigningData(json as JsonObject, signer, definitionsOpt),
|
|
109
|
+
)
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Encode a Batch transaction for signing.
|
|
114
|
+
*
|
|
115
|
+
* @param json JSON object representing the transaction.
|
|
116
|
+
* @returns a hex string of the encoded transaction.
|
|
117
|
+
*/
|
|
118
|
+
function encodeForSigningBatch(json: object): string {
|
|
119
|
+
if (typeof json !== 'object') {
|
|
120
|
+
throw new Error('Need an object to encode a Batch transaction')
|
|
121
|
+
}
|
|
122
|
+
return bytesToHex(signingBatchData(json as BatchObject))
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Encode a quality value
|
|
127
|
+
*
|
|
128
|
+
* @param value string representation of a number
|
|
129
|
+
* @returns a hex-string representing the quality
|
|
130
|
+
*/
|
|
131
|
+
function encodeQuality(value: string): string {
|
|
132
|
+
if (typeof value !== 'string') {
|
|
133
|
+
throw new Error()
|
|
134
|
+
}
|
|
135
|
+
return bytesToHex(quality.encode(value))
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Decode a quality value
|
|
140
|
+
*
|
|
141
|
+
* @param value hex-string of a quality
|
|
142
|
+
* @returns a string representing the quality
|
|
143
|
+
*/
|
|
144
|
+
function decodeQuality(value: string): string {
|
|
145
|
+
if (typeof value !== 'string') {
|
|
146
|
+
throw new Error()
|
|
147
|
+
}
|
|
148
|
+
return quality.decode(value).toString()
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export {
|
|
152
|
+
decode,
|
|
153
|
+
encode,
|
|
154
|
+
encodeForSigning,
|
|
155
|
+
encodeForSigningClaim,
|
|
156
|
+
encodeForMultisigning,
|
|
157
|
+
encodeForSigningBatch,
|
|
158
|
+
encodeQuality,
|
|
159
|
+
decodeQuality,
|
|
160
|
+
decodeLedgerData,
|
|
161
|
+
TRANSACTION_TYPES,
|
|
162
|
+
XrplDefinitions,
|
|
163
|
+
XrplDefinitionsBase,
|
|
164
|
+
DEFAULT_DEFINITIONS,
|
|
165
|
+
coreTypes,
|
|
166
|
+
}
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import { ShaMap, ShaMapNode, ShaMapLeaf } from './shamap'
|
|
2
|
+
import { HashPrefix } from './hash-prefixes'
|
|
3
|
+
import { Sha512Half } from './hashes'
|
|
4
|
+
import { BinarySerializer, serializeObject } from './binary'
|
|
5
|
+
import { Hash256 } from './types/hash-256'
|
|
6
|
+
import { STObject } from './types/st-object'
|
|
7
|
+
import { UInt64 } from './types/uint-64'
|
|
8
|
+
import { UInt32 } from './types/uint-32'
|
|
9
|
+
import { UInt8 } from './types/uint-8'
|
|
10
|
+
import { BinaryParser } from './serdes/binary-parser'
|
|
11
|
+
import { JsonObject } from './types/serialized-type'
|
|
12
|
+
import { XrplDefinitionsBase } from './enums'
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Computes the hash of a list of objects
|
|
16
|
+
*
|
|
17
|
+
* @param itemizer Converts an item into a format that can be added to SHAMap
|
|
18
|
+
* @param itemsJson Array of items to add to a SHAMap
|
|
19
|
+
* @returns the hash of the SHAMap
|
|
20
|
+
*/
|
|
21
|
+
function computeHash(
|
|
22
|
+
itemizer: (item: JsonObject) => [Hash256?, ShaMapNode?, ShaMapLeaf?],
|
|
23
|
+
itemsJson: Array<JsonObject>,
|
|
24
|
+
): Hash256 {
|
|
25
|
+
const map = new ShaMap()
|
|
26
|
+
itemsJson.forEach((item) => map.addItem(...itemizer(item)))
|
|
27
|
+
return map.hash()
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Interface describing a transaction item
|
|
32
|
+
*/
|
|
33
|
+
interface transactionItemObject extends JsonObject {
|
|
34
|
+
hash: string
|
|
35
|
+
metaData: JsonObject
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Convert a transaction into an index and an item
|
|
40
|
+
*
|
|
41
|
+
* @param json transaction with metadata
|
|
42
|
+
* @returns a tuple of index and item to be added to SHAMap
|
|
43
|
+
*/
|
|
44
|
+
function transactionItemizer(
|
|
45
|
+
json: transactionItemObject,
|
|
46
|
+
): [Hash256, ShaMapNode, undefined] {
|
|
47
|
+
if (!json.hash) {
|
|
48
|
+
throw new Error()
|
|
49
|
+
}
|
|
50
|
+
const index = Hash256.from(json.hash)
|
|
51
|
+
const item = {
|
|
52
|
+
hashPrefix() {
|
|
53
|
+
return HashPrefix.transaction
|
|
54
|
+
},
|
|
55
|
+
toBytesSink(sink) {
|
|
56
|
+
const serializer = new BinarySerializer(sink)
|
|
57
|
+
serializer.writeLengthEncoded(STObject.from(json))
|
|
58
|
+
serializer.writeLengthEncoded(STObject.from(json.metaData))
|
|
59
|
+
},
|
|
60
|
+
} as ShaMapNode
|
|
61
|
+
return [index, item, undefined]
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Interface describing an entry item
|
|
66
|
+
*/
|
|
67
|
+
interface entryItemObject extends JsonObject {
|
|
68
|
+
index: string
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Convert an entry to a pair Hash256 and ShaMapNode
|
|
73
|
+
*
|
|
74
|
+
* @param json JSON describing a ledger entry item
|
|
75
|
+
* @returns a tuple of index and item to be added to SHAMap
|
|
76
|
+
*/
|
|
77
|
+
function entryItemizer(
|
|
78
|
+
json: entryItemObject,
|
|
79
|
+
): [Hash256, ShaMapNode, undefined] {
|
|
80
|
+
const index = Hash256.from(json.index)
|
|
81
|
+
const bytes = serializeObject(json)
|
|
82
|
+
const item = {
|
|
83
|
+
hashPrefix() {
|
|
84
|
+
return HashPrefix.accountStateEntry
|
|
85
|
+
},
|
|
86
|
+
toBytesSink(sink) {
|
|
87
|
+
sink.put(bytes)
|
|
88
|
+
},
|
|
89
|
+
} as ShaMapNode
|
|
90
|
+
return [index, item, undefined]
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Function computing the hash of a transaction tree
|
|
95
|
+
*
|
|
96
|
+
* @param param An array of transaction objects to hash
|
|
97
|
+
* @returns A Hash256 object
|
|
98
|
+
*/
|
|
99
|
+
function transactionTreeHash(param: Array<JsonObject>): Hash256 {
|
|
100
|
+
const itemizer = transactionItemizer as (
|
|
101
|
+
json: JsonObject,
|
|
102
|
+
) => [Hash256, ShaMapNode, undefined]
|
|
103
|
+
return computeHash(itemizer, param)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Function computing the hash of accountState
|
|
108
|
+
*
|
|
109
|
+
* @param param A list of accountStates hash
|
|
110
|
+
* @returns A Hash256 object
|
|
111
|
+
*/
|
|
112
|
+
function accountStateHash(param: Array<JsonObject>): Hash256 {
|
|
113
|
+
const itemizer = entryItemizer as (
|
|
114
|
+
json: JsonObject,
|
|
115
|
+
) => [Hash256, ShaMapNode, undefined]
|
|
116
|
+
return computeHash(itemizer, param)
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Interface describing a ledger header
|
|
121
|
+
*/
|
|
122
|
+
interface ledgerObject {
|
|
123
|
+
ledger_index: number
|
|
124
|
+
total_coins: string | number | bigint
|
|
125
|
+
parent_hash: string
|
|
126
|
+
transaction_hash: string
|
|
127
|
+
account_hash: string
|
|
128
|
+
parent_close_time: number
|
|
129
|
+
close_time: number
|
|
130
|
+
close_time_resolution: number
|
|
131
|
+
close_flags: number
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Serialize and hash a ledger header
|
|
136
|
+
*
|
|
137
|
+
* @param header a ledger header
|
|
138
|
+
* @returns the hash of header
|
|
139
|
+
*/
|
|
140
|
+
function ledgerHash(header: ledgerObject): Hash256 {
|
|
141
|
+
const hash = new Sha512Half()
|
|
142
|
+
hash.put(HashPrefix.ledgerHeader)
|
|
143
|
+
if (
|
|
144
|
+
header.parent_close_time === undefined ||
|
|
145
|
+
header.close_flags === undefined
|
|
146
|
+
) {
|
|
147
|
+
throw new Error()
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
UInt32.from<number>(header.ledger_index).toBytesSink(hash)
|
|
151
|
+
UInt64.from<bigint>(BigInt(String(header.total_coins))).toBytesSink(hash)
|
|
152
|
+
Hash256.from<string>(header.parent_hash).toBytesSink(hash)
|
|
153
|
+
Hash256.from<string>(header.transaction_hash).toBytesSink(hash)
|
|
154
|
+
Hash256.from<string>(header.account_hash).toBytesSink(hash)
|
|
155
|
+
UInt32.from<number>(header.parent_close_time).toBytesSink(hash)
|
|
156
|
+
UInt32.from<number>(header.close_time).toBytesSink(hash)
|
|
157
|
+
UInt8.from<number>(header.close_time_resolution).toBytesSink(hash)
|
|
158
|
+
UInt8.from<number>(header.close_flags).toBytesSink(hash)
|
|
159
|
+
return hash.finish()
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Decodes a serialized ledger header
|
|
164
|
+
*
|
|
165
|
+
* @param binary A serialized ledger header
|
|
166
|
+
* @param definitions Type definitions to parse the ledger objects.
|
|
167
|
+
* Used if there are non-default ledger objects to decode.
|
|
168
|
+
* @returns A JSON object describing a ledger header
|
|
169
|
+
*/
|
|
170
|
+
function decodeLedgerData(
|
|
171
|
+
binary: string,
|
|
172
|
+
definitions?: XrplDefinitionsBase,
|
|
173
|
+
): object {
|
|
174
|
+
if (typeof binary !== 'string') {
|
|
175
|
+
throw new Error('binary must be a hex string')
|
|
176
|
+
}
|
|
177
|
+
const parser = new BinaryParser(binary, definitions)
|
|
178
|
+
return {
|
|
179
|
+
ledger_index: parser.readUInt32(),
|
|
180
|
+
total_coins: parser.readType(UInt64).valueOf().toString(),
|
|
181
|
+
parent_hash: parser.readType(Hash256).toHex(),
|
|
182
|
+
transaction_hash: parser.readType(Hash256).toHex(),
|
|
183
|
+
account_hash: parser.readType(Hash256).toHex(),
|
|
184
|
+
parent_close_time: parser.readUInt32(),
|
|
185
|
+
close_time: parser.readUInt32(),
|
|
186
|
+
close_time_resolution: parser.readUInt8(),
|
|
187
|
+
close_flags: parser.readUInt8(),
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export { accountStateHash, transactionTreeHash, ledgerHash, decodeLedgerData }
|
package/src/quality.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { coreTypes } from './types'
|
|
2
|
+
import BigNumber from 'bignumber.js'
|
|
3
|
+
import { bytesToHex, hexToBytes } from '@transia/isomorphic/utils'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* class for encoding and decoding quality
|
|
7
|
+
*/
|
|
8
|
+
class quality {
|
|
9
|
+
/**
|
|
10
|
+
* Encode quality amount
|
|
11
|
+
*
|
|
12
|
+
* @param arg string representation of an amount
|
|
13
|
+
* @returns Serialized quality
|
|
14
|
+
*/
|
|
15
|
+
static encode(quality: string): Uint8Array {
|
|
16
|
+
const decimal = BigNumber(quality)
|
|
17
|
+
const exponent = (decimal?.e || 0) - 15
|
|
18
|
+
const qualityString = decimal.times(`1e${-exponent}`).abs().toString()
|
|
19
|
+
const bytes = coreTypes.UInt64.from(BigInt(qualityString)).toBytes()
|
|
20
|
+
bytes[0] = exponent + 100
|
|
21
|
+
return bytes
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Decode quality amount
|
|
26
|
+
*
|
|
27
|
+
* @param arg hex-string denoting serialized quality
|
|
28
|
+
* @returns deserialized quality
|
|
29
|
+
*/
|
|
30
|
+
static decode(quality: string): BigNumber {
|
|
31
|
+
const bytes = hexToBytes(quality).slice(-8)
|
|
32
|
+
const exponent = bytes[0] - 100
|
|
33
|
+
const mantissa = new BigNumber(`0x${bytesToHex(bytes.slice(1))}`)
|
|
34
|
+
return mantissa.times(`1e${exponent}`)
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export { quality }
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import {
|
|
2
|
+
XrplDefinitionsBase,
|
|
3
|
+
DEFAULT_DEFINITIONS,
|
|
4
|
+
FieldInstance,
|
|
5
|
+
} from '../enums'
|
|
6
|
+
import { type SerializedType } from '../types/serialized-type'
|
|
7
|
+
import { hexToBytes } from '@transia/isomorphic/utils'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* BinaryParser is used to compute fields and values from a HexString
|
|
11
|
+
*/
|
|
12
|
+
class BinaryParser {
|
|
13
|
+
private bytes: Uint8Array
|
|
14
|
+
definitions: XrplDefinitionsBase
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Initialize bytes to a hex string
|
|
18
|
+
*
|
|
19
|
+
* @param hexBytes a hex string
|
|
20
|
+
* @param definitions Rippled definitions used to parse the values of transaction types and such.
|
|
21
|
+
* Can be customized for sidechains and amendments.
|
|
22
|
+
*/
|
|
23
|
+
constructor(
|
|
24
|
+
hexBytes: string,
|
|
25
|
+
definitions: XrplDefinitionsBase = DEFAULT_DEFINITIONS,
|
|
26
|
+
) {
|
|
27
|
+
this.bytes = hexToBytes(hexBytes)
|
|
28
|
+
this.definitions = definitions
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Peek the first byte of the BinaryParser
|
|
33
|
+
*
|
|
34
|
+
* @returns The first byte of the BinaryParser
|
|
35
|
+
*/
|
|
36
|
+
peek(): number {
|
|
37
|
+
if (this.bytes.byteLength === 0) {
|
|
38
|
+
throw new Error()
|
|
39
|
+
}
|
|
40
|
+
return this.bytes[0]
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Consume the first n bytes of the BinaryParser
|
|
45
|
+
*
|
|
46
|
+
* @param n the number of bytes to skip
|
|
47
|
+
*/
|
|
48
|
+
skip(n: number): void {
|
|
49
|
+
if (n > this.bytes.byteLength) {
|
|
50
|
+
throw new Error()
|
|
51
|
+
}
|
|
52
|
+
this.bytes = this.bytes.slice(n)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* read the first n bytes from the BinaryParser
|
|
57
|
+
*
|
|
58
|
+
* @param n The number of bytes to read
|
|
59
|
+
* @return The bytes
|
|
60
|
+
*/
|
|
61
|
+
read(n: number): Uint8Array {
|
|
62
|
+
if (n > this.bytes.byteLength) {
|
|
63
|
+
throw new Error()
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const slice = this.bytes.slice(0, n)
|
|
67
|
+
this.skip(n)
|
|
68
|
+
return slice
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Read an integer of given size
|
|
73
|
+
*
|
|
74
|
+
* @param n The number of bytes to read
|
|
75
|
+
* @return The number represented by those bytes
|
|
76
|
+
*/
|
|
77
|
+
readUIntN(n: number): number {
|
|
78
|
+
if (0 >= n || n > 4) {
|
|
79
|
+
throw new Error('invalid n')
|
|
80
|
+
}
|
|
81
|
+
return this.read(n).reduce((a, b) => (a << 8) | b) >>> 0
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
readUInt8(): number {
|
|
85
|
+
return this.readUIntN(1)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
readUInt16(): number {
|
|
89
|
+
return this.readUIntN(2)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
readUInt32(): number {
|
|
93
|
+
return this.readUIntN(4)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
size(): number {
|
|
97
|
+
return this.bytes.byteLength
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
end(customEnd?: number): boolean {
|
|
101
|
+
const length = this.bytes.byteLength
|
|
102
|
+
return length === 0 || (customEnd !== undefined && length <= customEnd)
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Reads variable length encoded bytes
|
|
107
|
+
*
|
|
108
|
+
* @return The variable length bytes
|
|
109
|
+
*/
|
|
110
|
+
readVariableLength(): Uint8Array {
|
|
111
|
+
return this.read(this.readVariableLengthLength())
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Reads the length of the variable length encoded bytes
|
|
116
|
+
*
|
|
117
|
+
* @return The length of the variable length encoded bytes
|
|
118
|
+
*/
|
|
119
|
+
readVariableLengthLength(): number {
|
|
120
|
+
const b1 = this.readUInt8()
|
|
121
|
+
if (b1 <= 192) {
|
|
122
|
+
return b1
|
|
123
|
+
} else if (b1 <= 240) {
|
|
124
|
+
const b2 = this.readUInt8()
|
|
125
|
+
return 193 + (b1 - 193) * 256 + b2
|
|
126
|
+
} else if (b1 <= 254) {
|
|
127
|
+
const b2 = this.readUInt8()
|
|
128
|
+
const b3 = this.readUInt8()
|
|
129
|
+
return 12481 + (b1 - 241) * 65536 + b2 * 256 + b3
|
|
130
|
+
}
|
|
131
|
+
throw new Error('Invalid variable length indicator')
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Reads the field ordinal from the BinaryParser
|
|
136
|
+
*
|
|
137
|
+
* @return Field ordinal
|
|
138
|
+
*/
|
|
139
|
+
readFieldOrdinal(): number {
|
|
140
|
+
let type = this.readUInt8()
|
|
141
|
+
let nth = type & 15
|
|
142
|
+
type >>= 4
|
|
143
|
+
|
|
144
|
+
if (type === 0) {
|
|
145
|
+
type = this.readUInt8()
|
|
146
|
+
if (type === 0 || type < 16) {
|
|
147
|
+
throw new Error(
|
|
148
|
+
`Cannot read FieldOrdinal, type_code ${type} out of range`,
|
|
149
|
+
)
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (nth === 0) {
|
|
154
|
+
nth = this.readUInt8()
|
|
155
|
+
if (nth === 0 || nth < 16) {
|
|
156
|
+
throw new Error(
|
|
157
|
+
`Cannot read FieldOrdinal, field_code ${nth} out of range`,
|
|
158
|
+
)
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return (type << 16) | nth
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Read the field from the BinaryParser
|
|
167
|
+
*
|
|
168
|
+
* @return The field represented by the bytes at the head of the BinaryParser
|
|
169
|
+
*/
|
|
170
|
+
readField(): FieldInstance {
|
|
171
|
+
return this.definitions.field.fromString(this.readFieldOrdinal().toString())
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Read a given type from the BinaryParser
|
|
176
|
+
*
|
|
177
|
+
* @param type The type that you want to read from the BinaryParser
|
|
178
|
+
* @return The instance of that type read from the BinaryParser
|
|
179
|
+
*/
|
|
180
|
+
readType(type: typeof SerializedType): SerializedType {
|
|
181
|
+
return type.fromParser(this)
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Get the type associated with a given field
|
|
186
|
+
*
|
|
187
|
+
* @param field The field that you wan to get the type of
|
|
188
|
+
* @return The type associated with the given field
|
|
189
|
+
*/
|
|
190
|
+
typeForField(field: FieldInstance): typeof SerializedType {
|
|
191
|
+
return field.associatedType
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Read value of the type specified by field from the BinaryParser
|
|
196
|
+
*
|
|
197
|
+
* @param field The field that you want to get the associated value for
|
|
198
|
+
* @return The value associated with the given field
|
|
199
|
+
*/
|
|
200
|
+
readFieldValue(field: FieldInstance): SerializedType {
|
|
201
|
+
const type = this.typeForField(field)
|
|
202
|
+
if (!type) {
|
|
203
|
+
throw new Error(`unsupported: (${field.name}, ${field.type.name})`)
|
|
204
|
+
}
|
|
205
|
+
const sizeHint = field.isVariableLengthEncoded
|
|
206
|
+
? this.readVariableLengthLength()
|
|
207
|
+
: undefined
|
|
208
|
+
const value = type.fromParser(this, sizeHint)
|
|
209
|
+
if (value === undefined) {
|
|
210
|
+
throw new Error(
|
|
211
|
+
`fromParser for (${field.name}, ${field.type.name}) -> undefined `,
|
|
212
|
+
)
|
|
213
|
+
}
|
|
214
|
+
return value
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Get the next field and value from the BinaryParser
|
|
219
|
+
*
|
|
220
|
+
* @return The field and value
|
|
221
|
+
*/
|
|
222
|
+
readFieldAndValue(): [FieldInstance, SerializedType] {
|
|
223
|
+
const field = this.readField()
|
|
224
|
+
return [field, this.readFieldValue(field)]
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
export { BinaryParser }
|