ripple-binary-codec 1.10.0-beta.0 → 2.0.0-beta.0
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.js +1 -2
- package/dist/binary.js.map +1 -1
- package/dist/enums/definitions.json +25 -18
- package/dist/enums/src/enums/definitions.json +25 -18
- package/dist/hashes.d.ts +1 -1
- package/dist/hashes.js +5 -5
- package/dist/hashes.js.map +1 -1
- package/dist/index.js +24 -32
- 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 +2 -2
- package/dist/quality.js +8 -6
- package/dist/quality.js.map +1 -1
- package/dist/serdes/binary-parser.js +12 -28
- package/dist/serdes/binary-parser.js.map +1 -1
- package/dist/serdes/binary-serializer.js +3 -26
- package/dist/serdes/binary-serializer.js.map +1 -1
- package/dist/shamap.js +3 -2
- package/dist/shamap.js.map +1 -1
- package/dist/types/amount.d.ts +1 -1
- package/dist/types/amount.js +31 -27
- package/dist/types/amount.js.map +1 -1
- package/dist/types/serialized-type.d.ts +1 -2
- package/dist/types/serialized-type.js.map +1 -1
- package/dist/types/uint-64.d.ts +2 -3
- package/dist/types/uint-64.js +10 -12
- package/dist/types/uint-64.js.map +1 -1
- package/dist/types/uint.d.ts +1 -2
- package/dist/types/uint.js.map +1 -1
- package/dist/types/xchain-bridge.d.ts +4 -4
- package/dist/types/xchain-bridge.js +5 -5
- package/dist/types/xchain-bridge.js.map +1 -1
- package/package.json +16 -9
- package/src/binary.ts +1 -2
- package/src/enums/definitions.json +25 -18
- package/src/hashes.ts +3 -3
- package/src/index.ts +24 -9
- package/src/ledger-hashes.ts +14 -10
- package/src/quality.ts +6 -7
- package/src/serdes/binary-parser.ts +12 -5
- package/src/serdes/binary-serializer.ts +3 -3
- package/src/shamap.ts +3 -2
- package/src/types/amount.ts +30 -30
- package/src/types/serialized-type.ts +1 -4
- package/src/types/uint-64.ts +12 -16
- package/src/types/uint.ts +2 -6
- package/src/types/xchain-bridge.ts +5 -5
|
@@ -2717,6 +2717,7 @@
|
|
|
2717
2717
|
"terQUEUED": -89,
|
|
2718
2718
|
"terPRE_TICKET": -88,
|
|
2719
2719
|
"terNO_AMM": -87,
|
|
2720
|
+
"terSUBMITTED": -86,
|
|
2720
2721
|
|
|
2721
2722
|
"tesSUCCESS": 0,
|
|
2722
2723
|
|
|
@@ -2758,6 +2759,7 @@
|
|
|
2758
2759
|
"tecKILLED": 150,
|
|
2759
2760
|
"tecHAS_OBLIGATIONS": 151,
|
|
2760
2761
|
"tecTOO_SOON": 152,
|
|
2762
|
+
"tecHOOK_ERROR": 153,
|
|
2761
2763
|
"tecMAX_SEQUENCE_REACHED": 154,
|
|
2762
2764
|
"tecNO_SUITABLE_NFTOKEN_PAGE": 155,
|
|
2763
2765
|
"tecNFTOKEN_BUY_SELL_MISMATCH": 156,
|
|
@@ -2770,23 +2772,27 @@
|
|
|
2770
2772
|
"tecAMM_BALANCE": 163,
|
|
2771
2773
|
"tecAMM_FAILED": 164,
|
|
2772
2774
|
"tecAMM_INVALID_TOKENS": 165,
|
|
2773
|
-
"
|
|
2774
|
-
"
|
|
2775
|
-
"
|
|
2776
|
-
"
|
|
2777
|
-
"
|
|
2778
|
-
"
|
|
2779
|
-
"
|
|
2780
|
-
"
|
|
2781
|
-
"
|
|
2782
|
-
"
|
|
2783
|
-
"
|
|
2784
|
-
"
|
|
2785
|
-
"
|
|
2786
|
-
"
|
|
2787
|
-
"
|
|
2788
|
-
"
|
|
2789
|
-
"
|
|
2775
|
+
"tecAMM_EMPTY": 166,
|
|
2776
|
+
"tecAMM_NOT_EMPTY": 167,
|
|
2777
|
+
"tecAMM_ACCOUNT": 168,
|
|
2778
|
+
"tecINCOMPLETE": 169,
|
|
2779
|
+
"tecXCHAIN_BAD_TRANSFER_ISSUE": 170,
|
|
2780
|
+
"tecXCHAIN_NO_CLAIM_ID": 171,
|
|
2781
|
+
"tecXCHAIN_BAD_CLAIM_ID": 172,
|
|
2782
|
+
"tecXCHAIN_CLAIM_NO_QUORUM": 173,
|
|
2783
|
+
"tecXCHAIN_PROOF_UNKNOWN_KEY": 174,
|
|
2784
|
+
"tecXCHAIN_CREATE_ACCOUNT_NONXRP_ISSUE": 175,
|
|
2785
|
+
"tecXCHAIN_WRONG_CHAIN": 176,
|
|
2786
|
+
"tecXCHAIN_REWARD_MISMATCH": 177,
|
|
2787
|
+
"tecXCHAIN_NO_SIGNERS_LIST": 178,
|
|
2788
|
+
"tecXCHAIN_SENDING_ACCOUNT_MISMATCH": 179,
|
|
2789
|
+
"tecXCHAIN_INSUFF_CREATE_AMOUNT": 180,
|
|
2790
|
+
"tecXCHAIN_ACCOUNT_CREATE_PAST": 181,
|
|
2791
|
+
"tecXCHAIN_ACCOUNT_CREATE_TOO_MANY": 182,
|
|
2792
|
+
"tecXCHAIN_PAYMENT_FAILED": 183,
|
|
2793
|
+
"tecXCHAIN_SELF_COMMIT": 184,
|
|
2794
|
+
"tecXCHAIN_BAD_PUBLIC_KEY_ACCOUNT_PAIR": 185,
|
|
2795
|
+
"tecXCHAIN_CREATE_ACCOUNT_DISABLED": 186
|
|
2790
2796
|
},
|
|
2791
2797
|
"TRANSACTION_TYPES": {
|
|
2792
2798
|
"Invalid": -1,
|
|
@@ -2824,7 +2830,7 @@
|
|
|
2824
2830
|
"AMMWithdraw": 37,
|
|
2825
2831
|
"AMMVote": 38,
|
|
2826
2832
|
"AMMBid": 39,
|
|
2827
|
-
"
|
|
2833
|
+
"AMMDelete": 40,
|
|
2828
2834
|
"XChainCreateClaimID": 41,
|
|
2829
2835
|
"XChainCommit": 42,
|
|
2830
2836
|
"XChainClaim": 43,
|
|
@@ -2832,6 +2838,7 @@
|
|
|
2832
2838
|
"XChainAddClaimAttestation": 45,
|
|
2833
2839
|
"XChainAddAccountCreateAttestation": 46,
|
|
2834
2840
|
"XChainModifyBridge": 47,
|
|
2841
|
+
"XChainCreateBridge": 48,
|
|
2835
2842
|
"EnableAmendment": 100,
|
|
2836
2843
|
"SetFee": 101,
|
|
2837
2844
|
"UNLModify": 102
|
package/src/hashes.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { HashPrefix } from './hash-prefixes'
|
|
2
|
-
import
|
|
3
|
-
import { Hash256 } from './types/hash-256'
|
|
2
|
+
import { Hash256 } from './types'
|
|
4
3
|
import { BytesList } from './serdes/binary-serializer'
|
|
5
4
|
import { Buffer } from 'buffer/'
|
|
5
|
+
import { sha512 } from '@xrplf/isomorphic/sha512'
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Class for hashing with SHA512
|
|
9
9
|
* @extends BytesList So SerializedTypes can write bytes to a Sha512Half
|
|
10
10
|
*/
|
|
11
11
|
class Sha512Half extends BytesList {
|
|
12
|
-
private hash =
|
|
12
|
+
private hash = sha512.create()
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* Construct a new Sha512Hash and write bytes this.hash
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import * as assert from 'assert'
|
|
2
1
|
import { quality, binary, HashPrefix } from './coretypes'
|
|
3
2
|
import { decodeLedgerData } from './ledger-hashes'
|
|
4
3
|
import { ClaimObject } from './binary'
|
|
@@ -27,7 +26,9 @@ const {
|
|
|
27
26
|
* @returns the JSON representation of the transaction
|
|
28
27
|
*/
|
|
29
28
|
function decode(binary: string, definitions?: XrplDefinitionsBase): JsonObject {
|
|
30
|
-
|
|
29
|
+
if (typeof binary !== 'string') {
|
|
30
|
+
throw new Error('binary must be a hex string')
|
|
31
|
+
}
|
|
31
32
|
return binaryToJSON(binary, definitions)
|
|
32
33
|
}
|
|
33
34
|
|
|
@@ -40,7 +41,9 @@ function decode(binary: string, definitions?: XrplDefinitionsBase): JsonObject {
|
|
|
40
41
|
* @returns A hex-string of the encoded transaction
|
|
41
42
|
*/
|
|
42
43
|
function encode(json: object, definitions?: XrplDefinitionsBase): string {
|
|
43
|
-
|
|
44
|
+
if (typeof json !== 'object') {
|
|
45
|
+
throw new Error()
|
|
46
|
+
}
|
|
44
47
|
return serializeObject(json as JsonObject, { definitions })
|
|
45
48
|
.toString('hex')
|
|
46
49
|
.toUpperCase()
|
|
@@ -58,7 +61,9 @@ function encodeForSigning(
|
|
|
58
61
|
json: object,
|
|
59
62
|
definitions?: XrplDefinitionsBase,
|
|
60
63
|
): string {
|
|
61
|
-
|
|
64
|
+
if (typeof json !== 'object') {
|
|
65
|
+
throw new Error()
|
|
66
|
+
}
|
|
62
67
|
return signingData(json as JsonObject, HashPrefix.transactionSig, {
|
|
63
68
|
definitions,
|
|
64
69
|
})
|
|
@@ -75,7 +80,9 @@ function encodeForSigning(
|
|
|
75
80
|
* @returns a hex string of the encoded transaction
|
|
76
81
|
*/
|
|
77
82
|
function encodeForSigningClaim(json: object): string {
|
|
78
|
-
|
|
83
|
+
if (typeof json !== 'object') {
|
|
84
|
+
throw new Error()
|
|
85
|
+
}
|
|
79
86
|
return signingClaimData(json as ClaimObject)
|
|
80
87
|
.toString('hex')
|
|
81
88
|
.toUpperCase()
|
|
@@ -94,8 +101,12 @@ function encodeForMultisigning(
|
|
|
94
101
|
signer: string,
|
|
95
102
|
definitions?: XrplDefinitionsBase,
|
|
96
103
|
): string {
|
|
97
|
-
|
|
98
|
-
|
|
104
|
+
if (typeof json !== 'object') {
|
|
105
|
+
throw new Error()
|
|
106
|
+
}
|
|
107
|
+
if (json['SigningPubKey'] !== '') {
|
|
108
|
+
throw new Error()
|
|
109
|
+
}
|
|
99
110
|
const definitionsOpt = definitions ? { definitions } : undefined
|
|
100
111
|
return multiSigningData(json as JsonObject, signer, definitionsOpt)
|
|
101
112
|
.toString('hex')
|
|
@@ -109,7 +120,9 @@ function encodeForMultisigning(
|
|
|
109
120
|
* @returns a hex-string representing the quality
|
|
110
121
|
*/
|
|
111
122
|
function encodeQuality(value: string): string {
|
|
112
|
-
|
|
123
|
+
if (typeof value !== 'string') {
|
|
124
|
+
throw new Error()
|
|
125
|
+
}
|
|
113
126
|
return quality.encode(value).toString('hex').toUpperCase()
|
|
114
127
|
}
|
|
115
128
|
|
|
@@ -120,7 +133,9 @@ function encodeQuality(value: string): string {
|
|
|
120
133
|
* @returns a string representing the quality
|
|
121
134
|
*/
|
|
122
135
|
function decodeQuality(value: string): string {
|
|
123
|
-
|
|
136
|
+
if (typeof value !== 'string') {
|
|
137
|
+
throw new Error()
|
|
138
|
+
}
|
|
124
139
|
return quality.decode(value).toString()
|
|
125
140
|
}
|
|
126
141
|
|
package/src/ledger-hashes.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import * as assert from 'assert'
|
|
2
1
|
import { ShaMap, ShaMapNode, ShaMapLeaf } from './shamap'
|
|
3
2
|
import { HashPrefix } from './hash-prefixes'
|
|
4
3
|
import { Sha512Half } from './hashes'
|
|
@@ -10,7 +9,6 @@ import { UInt32 } from './types/uint-32'
|
|
|
10
9
|
import { UInt8 } from './types/uint-8'
|
|
11
10
|
import { BinaryParser } from './serdes/binary-parser'
|
|
12
11
|
import { JsonObject } from './types/serialized-type'
|
|
13
|
-
import bigInt = require('big-integer')
|
|
14
12
|
import { XrplDefinitionsBase } from './enums'
|
|
15
13
|
|
|
16
14
|
/**
|
|
@@ -46,7 +44,9 @@ interface transactionItemObject extends JsonObject {
|
|
|
46
44
|
function transactionItemizer(
|
|
47
45
|
json: transactionItemObject,
|
|
48
46
|
): [Hash256, ShaMapNode, undefined] {
|
|
49
|
-
|
|
47
|
+
if (!json.hash) {
|
|
48
|
+
throw new Error()
|
|
49
|
+
}
|
|
50
50
|
const index = Hash256.from(json.hash)
|
|
51
51
|
const item = {
|
|
52
52
|
hashPrefix() {
|
|
@@ -121,7 +121,7 @@ function accountStateHash(param: Array<JsonObject>): Hash256 {
|
|
|
121
121
|
*/
|
|
122
122
|
interface ledgerObject {
|
|
123
123
|
ledger_index: number
|
|
124
|
-
total_coins: string | number |
|
|
124
|
+
total_coins: string | number | bigint
|
|
125
125
|
parent_hash: string
|
|
126
126
|
transaction_hash: string
|
|
127
127
|
account_hash: string
|
|
@@ -140,13 +140,15 @@ interface ledgerObject {
|
|
|
140
140
|
function ledgerHash(header: ledgerObject): Hash256 {
|
|
141
141
|
const hash = new Sha512Half()
|
|
142
142
|
hash.put(HashPrefix.ledgerHeader)
|
|
143
|
-
|
|
144
|
-
|
|
143
|
+
if (
|
|
144
|
+
header.parent_close_time === undefined ||
|
|
145
|
+
header.close_flags === undefined
|
|
146
|
+
) {
|
|
147
|
+
throw new Error()
|
|
148
|
+
}
|
|
145
149
|
|
|
146
150
|
UInt32.from<number>(header.ledger_index).toBytesSink(hash)
|
|
147
|
-
UInt64.from<
|
|
148
|
-
bigInt(String(header.total_coins)),
|
|
149
|
-
).toBytesSink(hash)
|
|
151
|
+
UInt64.from<bigint>(BigInt(String(header.total_coins))).toBytesSink(hash)
|
|
150
152
|
Hash256.from<string>(header.parent_hash).toBytesSink(hash)
|
|
151
153
|
Hash256.from<string>(header.transaction_hash).toBytesSink(hash)
|
|
152
154
|
Hash256.from<string>(header.account_hash).toBytesSink(hash)
|
|
@@ -169,7 +171,9 @@ function decodeLedgerData(
|
|
|
169
171
|
binary: string,
|
|
170
172
|
definitions?: XrplDefinitionsBase,
|
|
171
173
|
): object {
|
|
172
|
-
|
|
174
|
+
if (typeof binary !== 'string') {
|
|
175
|
+
throw new Error('binary must be a hex string')
|
|
176
|
+
}
|
|
173
177
|
const parser = new BinaryParser(binary, definitions)
|
|
174
178
|
return {
|
|
175
179
|
ledger_index: parser.readUInt32(),
|
package/src/quality.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { coreTypes } from './types'
|
|
2
|
-
import { Decimal } from 'decimal.js'
|
|
3
|
-
import bigInt = require('big-integer')
|
|
4
2
|
import { Buffer } from 'buffer/'
|
|
3
|
+
import BigNumber from 'bignumber.js'
|
|
5
4
|
|
|
6
5
|
/**
|
|
7
6
|
* class for encoding and decoding quality
|
|
@@ -14,10 +13,10 @@ class quality {
|
|
|
14
13
|
* @returns Serialized quality
|
|
15
14
|
*/
|
|
16
15
|
static encode(quality: string): Buffer {
|
|
17
|
-
const decimal =
|
|
18
|
-
const exponent = decimal
|
|
16
|
+
const decimal = BigNumber(quality)
|
|
17
|
+
const exponent = (decimal?.e || 0) - 15
|
|
19
18
|
const qualityString = decimal.times(`1e${-exponent}`).abs().toString()
|
|
20
|
-
const bytes = coreTypes.UInt64.from(
|
|
19
|
+
const bytes = coreTypes.UInt64.from(BigInt(qualityString)).toBytes()
|
|
21
20
|
bytes[0] = exponent + 100
|
|
22
21
|
return bytes
|
|
23
22
|
}
|
|
@@ -28,10 +27,10 @@ class quality {
|
|
|
28
27
|
* @param arg hex-string denoting serialized quality
|
|
29
28
|
* @returns deserialized quality
|
|
30
29
|
*/
|
|
31
|
-
static decode(quality: string):
|
|
30
|
+
static decode(quality: string): BigNumber {
|
|
32
31
|
const bytes = Buffer.from(quality, 'hex').slice(-8)
|
|
33
32
|
const exponent = bytes[0] - 100
|
|
34
|
-
const mantissa = new
|
|
33
|
+
const mantissa = new BigNumber(`0x${bytes.slice(1).toString('hex')}`)
|
|
35
34
|
return mantissa.times(`1e${exponent}`)
|
|
36
35
|
}
|
|
37
36
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import * as assert from 'assert'
|
|
2
1
|
import {
|
|
3
2
|
XrplDefinitionsBase,
|
|
4
3
|
DEFAULT_DEFINITIONS,
|
|
@@ -35,7 +34,9 @@ class BinaryParser {
|
|
|
35
34
|
* @returns The first byte of the BinaryParser
|
|
36
35
|
*/
|
|
37
36
|
peek(): number {
|
|
38
|
-
|
|
37
|
+
if (this.bytes.byteLength === 0) {
|
|
38
|
+
throw new Error()
|
|
39
|
+
}
|
|
39
40
|
return this.bytes[0]
|
|
40
41
|
}
|
|
41
42
|
|
|
@@ -45,7 +46,9 @@ class BinaryParser {
|
|
|
45
46
|
* @param n the number of bytes to skip
|
|
46
47
|
*/
|
|
47
48
|
skip(n: number): void {
|
|
48
|
-
|
|
49
|
+
if (n > this.bytes.byteLength) {
|
|
50
|
+
throw new Error()
|
|
51
|
+
}
|
|
49
52
|
this.bytes = this.bytes.slice(n)
|
|
50
53
|
}
|
|
51
54
|
|
|
@@ -56,7 +59,9 @@ class BinaryParser {
|
|
|
56
59
|
* @return The bytes
|
|
57
60
|
*/
|
|
58
61
|
read(n: number): Buffer {
|
|
59
|
-
|
|
62
|
+
if (n > this.bytes.byteLength) {
|
|
63
|
+
throw new Error()
|
|
64
|
+
}
|
|
60
65
|
|
|
61
66
|
const slice = this.bytes.slice(0, n)
|
|
62
67
|
this.skip(n)
|
|
@@ -70,7 +75,9 @@ class BinaryParser {
|
|
|
70
75
|
* @return The number represented by those bytes
|
|
71
76
|
*/
|
|
72
77
|
readUIntN(n: number): number {
|
|
73
|
-
|
|
78
|
+
if (0 >= n || n > 4) {
|
|
79
|
+
throw new Error('invalid n')
|
|
80
|
+
}
|
|
74
81
|
return this.read(n).reduce((a, b) => (a << 8) | b) >>> 0
|
|
75
82
|
}
|
|
76
83
|
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import * as assert from 'assert'
|
|
2
1
|
import { FieldInstance } from '../enums'
|
|
3
2
|
import { type SerializedType } from '../types/serialized-type'
|
|
4
3
|
import { Buffer } from 'buffer/'
|
|
@@ -132,8 +131,9 @@ class BinarySerializer {
|
|
|
132
131
|
isUnlModifyWorkaround = false,
|
|
133
132
|
): void {
|
|
134
133
|
const associatedValue = field.associatedType.from(value)
|
|
135
|
-
|
|
136
|
-
|
|
134
|
+
if (associatedValue.toBytesSink === undefined || field.name === undefined) {
|
|
135
|
+
throw new Error()
|
|
136
|
+
}
|
|
137
137
|
|
|
138
138
|
this.sink.put(field.header)
|
|
139
139
|
|
package/src/shamap.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { strict as assert } from 'assert'
|
|
2
1
|
import { coreTypes } from './types'
|
|
3
2
|
import { HashPrefix } from './hash-prefixes'
|
|
4
3
|
import { Sha512Half } from './hashes'
|
|
@@ -160,7 +159,9 @@ class ShaMapInner extends ShaMapNode {
|
|
|
160
159
|
* @param leaf Leaf node to insert when branch doesn't exist
|
|
161
160
|
*/
|
|
162
161
|
addItem(index?: Hash256, item?: ShaMapNode, leaf?: ShaMapLeaf): void {
|
|
163
|
-
|
|
162
|
+
if (index === undefined) {
|
|
163
|
+
throw new Error()
|
|
164
|
+
}
|
|
164
165
|
if (index !== undefined) {
|
|
165
166
|
const nibble = index.nibblet(this.depth)
|
|
166
167
|
const existing = this.branches[nibble]
|
package/src/types/amount.ts
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import { Decimal } from 'decimal.js'
|
|
2
|
-
|
|
3
1
|
import { BinaryParser } from '../serdes/binary-parser'
|
|
4
2
|
|
|
5
3
|
import { AccountID } from './account-id'
|
|
6
4
|
import { Currency } from './currency'
|
|
7
5
|
import { JsonObject, SerializedType } from './serialized-type'
|
|
8
|
-
import bigInt = require('big-integer')
|
|
9
6
|
import { Buffer } from 'buffer/'
|
|
7
|
+
import BigNumber from 'bignumber.js'
|
|
10
8
|
|
|
11
9
|
/**
|
|
12
10
|
* Constants for validating amounts
|
|
@@ -14,16 +12,18 @@ import { Buffer } from 'buffer/'
|
|
|
14
12
|
const MIN_IOU_EXPONENT = -96
|
|
15
13
|
const MAX_IOU_EXPONENT = 80
|
|
16
14
|
const MAX_IOU_PRECISION = 16
|
|
17
|
-
const MAX_DROPS = new
|
|
18
|
-
const MIN_XRP = new
|
|
19
|
-
const mask =
|
|
15
|
+
const MAX_DROPS = new BigNumber('1e17')
|
|
16
|
+
const MIN_XRP = new BigNumber('1e-6')
|
|
17
|
+
const mask = BigInt(0x00000000ffffffff)
|
|
20
18
|
|
|
21
19
|
/**
|
|
22
|
-
*
|
|
20
|
+
* BigNumber configuration for Amount IOUs
|
|
23
21
|
*/
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
BigNumber.config({
|
|
23
|
+
EXPONENTIAL_AT: [
|
|
24
|
+
MIN_IOU_EXPONENT - MAX_IOU_PRECISION,
|
|
25
|
+
MAX_IOU_EXPONENT + MAX_IOU_PRECISION,
|
|
26
|
+
],
|
|
27
27
|
})
|
|
28
28
|
|
|
29
29
|
/**
|
|
@@ -76,11 +76,11 @@ class Amount extends SerializedType {
|
|
|
76
76
|
if (typeof value === 'string') {
|
|
77
77
|
Amount.assertXrpIsValid(value)
|
|
78
78
|
|
|
79
|
-
const number =
|
|
79
|
+
const number = BigInt(value)
|
|
80
80
|
|
|
81
81
|
const intBuf = [Buffer.alloc(4), Buffer.alloc(4)]
|
|
82
|
-
intBuf[0].writeUInt32BE(Number(number
|
|
83
|
-
intBuf[1].writeUInt32BE(Number(number
|
|
82
|
+
intBuf[0].writeUInt32BE(Number(number >> BigInt(32)), 0)
|
|
83
|
+
intBuf[1].writeUInt32BE(Number(number & BigInt(mask)), 0)
|
|
84
84
|
|
|
85
85
|
amount = Buffer.concat(intBuf)
|
|
86
86
|
|
|
@@ -90,31 +90,31 @@ class Amount extends SerializedType {
|
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
if (isAmountObject(value)) {
|
|
93
|
-
const number = new
|
|
93
|
+
const number = new BigNumber(value.value)
|
|
94
94
|
Amount.assertIouIsValid(number)
|
|
95
95
|
|
|
96
96
|
if (number.isZero()) {
|
|
97
97
|
amount[0] |= 0x80
|
|
98
98
|
} else {
|
|
99
99
|
const integerNumberString = number
|
|
100
|
-
.times(`1e${-(number.e - 15)}`)
|
|
100
|
+
.times(`1e${-((number.e || 0) - 15)}`)
|
|
101
101
|
.abs()
|
|
102
102
|
.toString()
|
|
103
103
|
|
|
104
|
-
const num =
|
|
104
|
+
const num = BigInt(integerNumberString)
|
|
105
105
|
const intBuf = [Buffer.alloc(4), Buffer.alloc(4)]
|
|
106
|
-
intBuf[0].writeUInt32BE(Number(num
|
|
107
|
-
intBuf[1].writeUInt32BE(Number(num
|
|
106
|
+
intBuf[0].writeUInt32BE(Number(num >> BigInt(32)), 0)
|
|
107
|
+
intBuf[1].writeUInt32BE(Number(num & BigInt(mask)), 0)
|
|
108
108
|
|
|
109
109
|
amount = Buffer.concat(intBuf)
|
|
110
110
|
|
|
111
111
|
amount[0] |= 0x80
|
|
112
112
|
|
|
113
|
-
if (number.gt(new
|
|
113
|
+
if (number.gt(new BigNumber(0))) {
|
|
114
114
|
amount[0] |= 0x40
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
-
const exponent = number.e - 15
|
|
117
|
+
const exponent = (number.e || 0) - 15
|
|
118
118
|
const exponentByte = 97 + exponent
|
|
119
119
|
amount[0] |= exponentByte >>> 2
|
|
120
120
|
amount[1] |= (exponentByte & 0x03) << 6
|
|
@@ -152,9 +152,9 @@ class Amount extends SerializedType {
|
|
|
152
152
|
const sign = isPositive ? '' : '-'
|
|
153
153
|
bytes[0] &= 0x3f
|
|
154
154
|
|
|
155
|
-
const msb =
|
|
156
|
-
const lsb =
|
|
157
|
-
const num = msb
|
|
155
|
+
const msb = BigInt(bytes.slice(0, 4).readUInt32BE(0))
|
|
156
|
+
const lsb = BigInt(bytes.slice(4).readUInt32BE(0))
|
|
157
|
+
const num = (msb << BigInt(32)) | lsb
|
|
158
158
|
|
|
159
159
|
return `${sign}${num.toString()}`
|
|
160
160
|
} else {
|
|
@@ -172,7 +172,7 @@ class Amount extends SerializedType {
|
|
|
172
172
|
|
|
173
173
|
mantissa[0] = 0
|
|
174
174
|
mantissa[1] &= 0x3f
|
|
175
|
-
const value = new
|
|
175
|
+
const value = new BigNumber(`${sign}0x${mantissa.toString('hex')}`).times(
|
|
176
176
|
`1e${exponent}`,
|
|
177
177
|
)
|
|
178
178
|
Amount.assertIouIsValid(value)
|
|
@@ -196,7 +196,7 @@ class Amount extends SerializedType {
|
|
|
196
196
|
throw new Error(`${amount.toString()} is an illegal amount`)
|
|
197
197
|
}
|
|
198
198
|
|
|
199
|
-
const decimal = new
|
|
199
|
+
const decimal = new BigNumber(amount)
|
|
200
200
|
if (!decimal.isZero()) {
|
|
201
201
|
if (decimal.lt(MIN_XRP) || decimal.gt(MAX_DROPS)) {
|
|
202
202
|
throw new Error(`${amount.toString()} is an illegal amount`)
|
|
@@ -207,13 +207,13 @@ class Amount extends SerializedType {
|
|
|
207
207
|
/**
|
|
208
208
|
* Validate IOU.value amount
|
|
209
209
|
*
|
|
210
|
-
* @param decimal
|
|
210
|
+
* @param decimal BigNumber object representing IOU.value
|
|
211
211
|
* @returns void, but will throw if invalid amount
|
|
212
212
|
*/
|
|
213
|
-
private static assertIouIsValid(decimal:
|
|
213
|
+
private static assertIouIsValid(decimal: BigNumber): void {
|
|
214
214
|
if (!decimal.isZero()) {
|
|
215
215
|
const p = decimal.precision()
|
|
216
|
-
const e = decimal.e - 15
|
|
216
|
+
const e = (decimal.e || 0) - 15
|
|
217
217
|
if (
|
|
218
218
|
p > MAX_IOU_PRECISION ||
|
|
219
219
|
e > MAX_IOU_EXPONENT ||
|
|
@@ -232,9 +232,9 @@ class Amount extends SerializedType {
|
|
|
232
232
|
* @param decimal a Decimal object
|
|
233
233
|
* @returns a string of the object without a decimal
|
|
234
234
|
*/
|
|
235
|
-
private static verifyNoDecimal(decimal:
|
|
235
|
+
private static verifyNoDecimal(decimal: BigNumber): void {
|
|
236
236
|
const integerNumberString = decimal
|
|
237
|
-
.times(`1e${-(decimal.e - 15)}`)
|
|
237
|
+
.times(`1e${-((decimal.e || 0) - 15)}`)
|
|
238
238
|
.abs()
|
|
239
239
|
.toString()
|
|
240
240
|
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { BytesList } from '../serdes/binary-serializer'
|
|
2
2
|
import { BinaryParser } from '../serdes/binary-parser'
|
|
3
|
-
import bigInt = require('big-integer')
|
|
4
3
|
import { Buffer } from 'buffer/'
|
|
5
4
|
import { XrplDefinitionsBase } from '../enums'
|
|
6
5
|
|
|
@@ -23,9 +22,7 @@ class SerializedType {
|
|
|
23
22
|
return this.fromParser(parser, hint)
|
|
24
23
|
}
|
|
25
24
|
|
|
26
|
-
static from(
|
|
27
|
-
value: SerializedType | JSON | bigInt.BigInteger,
|
|
28
|
-
): SerializedType {
|
|
25
|
+
static from(value: SerializedType | JSON | bigint): SerializedType {
|
|
29
26
|
throw new Error('from not implemented')
|
|
30
27
|
return this.from(value)
|
|
31
28
|
}
|
package/src/types/uint-64.ts
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { UInt } from './uint'
|
|
2
2
|
import { BinaryParser } from '../serdes/binary-parser'
|
|
3
|
-
import bigInt = require('big-integer')
|
|
4
|
-
import { isInstance } from 'big-integer'
|
|
5
3
|
import { Buffer } from 'buffer/'
|
|
6
4
|
|
|
7
5
|
const HEX_REGEX = /^[a-fA-F0-9]{1,16}$/
|
|
8
|
-
const mask =
|
|
6
|
+
const mask = BigInt(0x00000000ffffffff)
|
|
9
7
|
|
|
10
8
|
/**
|
|
11
9
|
* Derived UInt class for serializing/deserializing 64 bit UInt
|
|
@@ -28,9 +26,7 @@ class UInt64 extends UInt {
|
|
|
28
26
|
* @param val A UInt64, hex-string, bigInt, or number
|
|
29
27
|
* @returns A UInt64 object
|
|
30
28
|
*/
|
|
31
|
-
static from<T extends UInt64 | string |
|
|
32
|
-
val: T,
|
|
33
|
-
): UInt64 {
|
|
29
|
+
static from<T extends UInt64 | string | bigint | number>(val: T): UInt64 {
|
|
34
30
|
if (val instanceof UInt64) {
|
|
35
31
|
return val
|
|
36
32
|
}
|
|
@@ -42,11 +38,11 @@ class UInt64 extends UInt {
|
|
|
42
38
|
throw new Error('value must be an unsigned integer')
|
|
43
39
|
}
|
|
44
40
|
|
|
45
|
-
const number =
|
|
41
|
+
const number = BigInt(val)
|
|
46
42
|
|
|
47
43
|
const intBuf = [Buffer.alloc(4), Buffer.alloc(4)]
|
|
48
|
-
intBuf[0].writeUInt32BE(Number(number
|
|
49
|
-
intBuf[1].writeUInt32BE(Number(number
|
|
44
|
+
intBuf[0].writeUInt32BE(Number(number >> BigInt(32)), 0)
|
|
45
|
+
intBuf[1].writeUInt32BE(Number(number & BigInt(mask)), 0)
|
|
50
46
|
|
|
51
47
|
return new UInt64(Buffer.concat(intBuf))
|
|
52
48
|
}
|
|
@@ -61,10 +57,10 @@ class UInt64 extends UInt {
|
|
|
61
57
|
return new UInt64(buf)
|
|
62
58
|
}
|
|
63
59
|
|
|
64
|
-
if (
|
|
60
|
+
if (typeof val === 'bigint') {
|
|
65
61
|
const intBuf = [Buffer.alloc(4), Buffer.alloc(4)]
|
|
66
|
-
intBuf[0].writeUInt32BE(Number(val
|
|
67
|
-
intBuf[1].writeUInt32BE(Number(val
|
|
62
|
+
intBuf[0].writeUInt32BE(Number(val >> BigInt(32)), 0)
|
|
63
|
+
intBuf[1].writeUInt32BE(Number(val & BigInt(mask)), 0)
|
|
68
64
|
|
|
69
65
|
return new UInt64(Buffer.concat(intBuf))
|
|
70
66
|
}
|
|
@@ -86,10 +82,10 @@ class UInt64 extends UInt {
|
|
|
86
82
|
*
|
|
87
83
|
* @returns the number represented buy this.bytes
|
|
88
84
|
*/
|
|
89
|
-
valueOf():
|
|
90
|
-
const msb =
|
|
91
|
-
const lsb =
|
|
92
|
-
return msb
|
|
85
|
+
valueOf(): bigint {
|
|
86
|
+
const msb = BigInt(this.bytes.slice(0, 4).readUInt32BE(0))
|
|
87
|
+
const lsb = BigInt(this.bytes.slice(4).readUInt32BE(0))
|
|
88
|
+
return (msb << BigInt(32)) | lsb
|
|
93
89
|
}
|
|
94
90
|
|
|
95
91
|
/**
|
package/src/types/uint.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import bigInt = require('big-integer')
|
|
2
1
|
import { Comparable } from './serialized-type'
|
|
3
2
|
import { Buffer } from 'buffer/'
|
|
4
3
|
|
|
@@ -9,10 +8,7 @@ import { Buffer } from 'buffer/'
|
|
|
9
8
|
* @param n2 Second object to compare
|
|
10
9
|
* @returns -1, 0, or 1, depending on how the two objects compare
|
|
11
10
|
*/
|
|
12
|
-
function compare(
|
|
13
|
-
n1: number | bigInt.BigInteger,
|
|
14
|
-
n2: number | bigInt.BigInteger,
|
|
15
|
-
): number {
|
|
11
|
+
function compare(n1: number | bigint, n2: number | bigint): number {
|
|
16
12
|
return n1 < n2 ? -1 : n1 == n2 ? 0 : 1
|
|
17
13
|
}
|
|
18
14
|
|
|
@@ -51,7 +47,7 @@ abstract class UInt extends Comparable {
|
|
|
51
47
|
*
|
|
52
48
|
* @returns the value
|
|
53
49
|
*/
|
|
54
|
-
abstract valueOf(): number |
|
|
50
|
+
abstract valueOf(): number | bigint
|
|
55
51
|
}
|
|
56
52
|
|
|
57
53
|
export { UInt }
|
|
@@ -57,8 +57,8 @@ class XChainBridge extends SerializedType {
|
|
|
57
57
|
/**
|
|
58
58
|
* Construct a cross-chain bridge from a JSON
|
|
59
59
|
*
|
|
60
|
-
* @param value XChainBridge or JSON to parse into
|
|
61
|
-
* @returns
|
|
60
|
+
* @param value XChainBridge or JSON to parse into an XChainBridge
|
|
61
|
+
* @returns An XChainBridge object
|
|
62
62
|
*/
|
|
63
63
|
static from<T extends XChainBridge | XChainBridgeObject>(
|
|
64
64
|
value: T,
|
|
@@ -80,14 +80,14 @@ class XChainBridge extends SerializedType {
|
|
|
80
80
|
return new XChainBridge(Buffer.concat(bytes))
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
throw new Error('Invalid type to construct
|
|
83
|
+
throw new Error('Invalid type to construct an XChainBridge')
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
/**
|
|
87
|
-
* Read
|
|
87
|
+
* Read an XChainBridge from a BinaryParser
|
|
88
88
|
*
|
|
89
89
|
* @param parser BinaryParser to read the XChainBridge from
|
|
90
|
-
* @returns
|
|
90
|
+
* @returns An XChainBridge object
|
|
91
91
|
*/
|
|
92
92
|
static fromParser(parser: BinaryParser): XChainBridge {
|
|
93
93
|
const bytes: Array<Buffer> = []
|