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.
Files changed (49) hide show
  1. package/dist/binary.js +1 -2
  2. package/dist/binary.js.map +1 -1
  3. package/dist/enums/definitions.json +25 -18
  4. package/dist/enums/src/enums/definitions.json +25 -18
  5. package/dist/hashes.d.ts +1 -1
  6. package/dist/hashes.js +5 -5
  7. package/dist/hashes.js.map +1 -1
  8. package/dist/index.js +24 -32
  9. package/dist/index.js.map +1 -1
  10. package/dist/ledger-hashes.d.ts +1 -2
  11. package/dist/ledger-hashes.js +11 -30
  12. package/dist/ledger-hashes.js.map +1 -1
  13. package/dist/quality.d.ts +2 -2
  14. package/dist/quality.js +8 -6
  15. package/dist/quality.js.map +1 -1
  16. package/dist/serdes/binary-parser.js +12 -28
  17. package/dist/serdes/binary-parser.js.map +1 -1
  18. package/dist/serdes/binary-serializer.js +3 -26
  19. package/dist/serdes/binary-serializer.js.map +1 -1
  20. package/dist/shamap.js +3 -2
  21. package/dist/shamap.js.map +1 -1
  22. package/dist/types/amount.d.ts +1 -1
  23. package/dist/types/amount.js +31 -27
  24. package/dist/types/amount.js.map +1 -1
  25. package/dist/types/serialized-type.d.ts +1 -2
  26. package/dist/types/serialized-type.js.map +1 -1
  27. package/dist/types/uint-64.d.ts +2 -3
  28. package/dist/types/uint-64.js +10 -12
  29. package/dist/types/uint-64.js.map +1 -1
  30. package/dist/types/uint.d.ts +1 -2
  31. package/dist/types/uint.js.map +1 -1
  32. package/dist/types/xchain-bridge.d.ts +4 -4
  33. package/dist/types/xchain-bridge.js +5 -5
  34. package/dist/types/xchain-bridge.js.map +1 -1
  35. package/package.json +16 -9
  36. package/src/binary.ts +1 -2
  37. package/src/enums/definitions.json +25 -18
  38. package/src/hashes.ts +3 -3
  39. package/src/index.ts +24 -9
  40. package/src/ledger-hashes.ts +14 -10
  41. package/src/quality.ts +6 -7
  42. package/src/serdes/binary-parser.ts +12 -5
  43. package/src/serdes/binary-serializer.ts +3 -3
  44. package/src/shamap.ts +3 -2
  45. package/src/types/amount.ts +30 -30
  46. package/src/types/serialized-type.ts +1 -4
  47. package/src/types/uint-64.ts +12 -16
  48. package/src/types/uint.ts +2 -6
  49. 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
- "tecXCHAIN_BAD_TRANSFER_ISSUE": 166,
2774
- "tecXCHAIN_NO_CLAIM_ID": 167,
2775
- "tecXCHAIN_BAD_CLAIM_ID": 168,
2776
- "tecXCHAIN_CLAIM_NO_QUORUM": 169,
2777
- "tecXCHAIN_PROOF_UNKNOWN_KEY": 170,
2778
- "tecXCHAIN_CREATE_ACCOUNT_NONXRP_ISSUE": 171,
2779
- "tecXCHAIN_WRONG_CHAIN": 172,
2780
- "tecXCHAIN_REWARD_MISMATCH": 173,
2781
- "tecXCHAIN_NO_SIGNERS_LIST": 174,
2782
- "tecXCHAIN_SENDING_ACCOUNT_MISMATCH": 175,
2783
- "tecXCHAIN_INSUFF_CREATE_AMOUNT": 176,
2784
- "tecXCHAIN_ACCOUNT_CREATE_PAST": 177,
2785
- "tecXCHAIN_ACCOUNT_CREATE_TOO_MANY": 178,
2786
- "tecXCHAIN_PAYMENT_FAILED": 179,
2787
- "tecXCHAIN_SELF_COMMIT": 180,
2788
- "tecXCHAIN_BAD_PUBLIC_KEY_ACCOUNT_PAIR": 181,
2789
- "tecXCHAIN_CREATE_ACCOUNT_DISABLED": 182
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
- "XChainCreateBridge": 40,
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 createHash = require('create-hash')
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 = createHash('sha512')
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
- assert.ok(typeof binary === 'string', 'binary must be a hex string')
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
- assert.ok(typeof json === 'object')
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
- assert.ok(typeof json === 'object')
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
- assert.ok(typeof json === 'object')
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
- assert.ok(typeof json === 'object')
98
- assert.equal(json['SigningPubKey'], '')
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
- assert.ok(typeof value === 'string')
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
- assert.ok(typeof value === 'string')
136
+ if (typeof value !== 'string') {
137
+ throw new Error()
138
+ }
124
139
  return quality.decode(value).toString()
125
140
  }
126
141
 
@@ -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
- assert.ok(json.hash)
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 | bigInt.BigInteger
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
- assert.ok(header.parent_close_time !== undefined)
144
- assert.ok(header.close_flags !== undefined)
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<bigInt.BigInteger>(
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
- assert.ok(typeof binary === 'string', 'binary must be a hex string')
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 = new Decimal(quality)
18
- const exponent = decimal.e - 15
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(bigInt(qualityString)).toBytes()
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): Decimal {
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 Decimal(`0x${bytes.slice(1).toString('hex')}`)
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
- assert.ok(this.bytes.byteLength !== 0)
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
- assert.ok(n <= this.bytes.byteLength)
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
- assert.ok(n <= this.bytes.byteLength)
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
- assert.ok(0 < n && n <= 4, 'invalid n')
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
- assert.ok(associatedValue.toBytesSink !== undefined)
136
- assert.ok(field.name !== undefined)
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
- assert.ok(index !== undefined)
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]
@@ -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 Decimal('1e17')
18
- const MIN_XRP = new Decimal('1e-6')
19
- const mask = bigInt(0x00000000ffffffff)
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
- * decimal.js configuration for Amount IOUs
20
+ * BigNumber configuration for Amount IOUs
23
21
  */
24
- Decimal.config({
25
- toExpPos: MAX_IOU_EXPONENT + MAX_IOU_PRECISION,
26
- toExpNeg: MIN_IOU_EXPONENT - MAX_IOU_PRECISION,
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 = bigInt(value)
79
+ const number = BigInt(value)
80
80
 
81
81
  const intBuf = [Buffer.alloc(4), Buffer.alloc(4)]
82
- intBuf[0].writeUInt32BE(Number(number.shiftRight(32)), 0)
83
- intBuf[1].writeUInt32BE(Number(number.and(mask)), 0)
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 Decimal(value.value)
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 = bigInt(integerNumberString)
104
+ const num = BigInt(integerNumberString)
105
105
  const intBuf = [Buffer.alloc(4), Buffer.alloc(4)]
106
- intBuf[0].writeUInt32BE(Number(num.shiftRight(32)), 0)
107
- intBuf[1].writeUInt32BE(Number(num.and(mask)), 0)
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 Decimal(0))) {
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 = bigInt(bytes.slice(0, 4).readUInt32BE(0))
156
- const lsb = bigInt(bytes.slice(4).readUInt32BE(0))
157
- const num = msb.shiftLeft(32).or(lsb)
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 Decimal(`${sign}0x${mantissa.toString('hex')}`).times(
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 Decimal(amount)
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 Decimal.js object representing IOU.value
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: Decimal): void {
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: Decimal): void {
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
  }
@@ -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 = bigInt(0x00000000ffffffff)
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 | bigInt.BigInteger | number>(
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 = bigInt(val)
41
+ const number = BigInt(val)
46
42
 
47
43
  const intBuf = [Buffer.alloc(4), Buffer.alloc(4)]
48
- intBuf[0].writeUInt32BE(Number(number.shiftRight(32)), 0)
49
- intBuf[1].writeUInt32BE(Number(number.and(mask)), 0)
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 (isInstance(val)) {
60
+ if (typeof val === 'bigint') {
65
61
  const intBuf = [Buffer.alloc(4), Buffer.alloc(4)]
66
- intBuf[0].writeUInt32BE(Number(val.shiftRight(bigInt(32))), 0)
67
- intBuf[1].writeUInt32BE(Number(val.and(mask)), 0)
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(): bigInt.BigInteger {
90
- const msb = bigInt(this.bytes.slice(0, 4).readUInt32BE(0))
91
- const lsb = bigInt(this.bytes.slice(4).readUInt32BE(0))
92
- return msb.shiftLeft(bigInt(32)).or(lsb)
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 | bigInt.BigInteger
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 a XChainBridge
61
- * @returns A XChainBridge object
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 a XChainBridge')
83
+ throw new Error('Invalid type to construct an XChainBridge')
84
84
  }
85
85
 
86
86
  /**
87
- * Read a XChainBridge from a BinaryParser
87
+ * Read an XChainBridge from a BinaryParser
88
88
  *
89
89
  * @param parser BinaryParser to read the XChainBridge from
90
- * @returns A XChainBridge object
90
+ * @returns An XChainBridge object
91
91
  */
92
92
  static fromParser(parser: BinaryParser): XChainBridge {
93
93
  const bytes: Array<Buffer> = []