@transia/ripple-binary-codec 1.4.4-alpha.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 (164) hide show
  1. package/LICENSE +13 -0
  2. package/README.md +107 -0
  3. package/dist/binary.d.ts +91 -0
  4. package/dist/binary.js +128 -0
  5. package/dist/binary.js.map +1 -0
  6. package/dist/coretypes.d.ts +9 -0
  7. package/dist/coretypes.js +48 -0
  8. package/dist/coretypes.js.map +1 -0
  9. package/dist/enums/bytes.d.ts +26 -0
  10. package/dist/enums/bytes.js +64 -0
  11. package/dist/enums/bytes.js.map +1 -0
  12. package/dist/enums/constants.d.ts +4 -0
  13. package/dist/enums/constants.js +8 -0
  14. package/dist/enums/constants.js.map +1 -0
  15. package/dist/enums/definitions.json +2476 -0
  16. package/dist/enums/field.d.ts +29 -0
  17. package/dist/enums/field.js +59 -0
  18. package/dist/enums/field.js.map +1 -0
  19. package/dist/enums/index.d.ts +13 -0
  20. package/dist/enums/index.js +53 -0
  21. package/dist/enums/index.js.map +1 -0
  22. package/dist/enums/src/enums/definitions.json +2481 -0
  23. package/dist/enums/utils-renumber.d.ts +101 -0
  24. package/dist/enums/utils-renumber.js +127 -0
  25. package/dist/enums/utils-renumber.js.map +1 -0
  26. package/dist/enums/xrpl-definitions-base.d.ts +45 -0
  27. package/dist/enums/xrpl-definitions-base.js +63 -0
  28. package/dist/enums/xrpl-definitions-base.js.map +1 -0
  29. package/dist/enums/xrpl-definitions.d.ts +21 -0
  30. package/dist/enums/xrpl-definitions.js +29 -0
  31. package/dist/enums/xrpl-definitions.js.map +1 -0
  32. package/dist/hash-prefixes.d.ts +6 -0
  33. package/dist/hash-prefixes.js +41 -0
  34. package/dist/hash-prefixes.js.map +1 -0
  35. package/dist/hashes.d.ts +51 -0
  36. package/dist/hashes.js +77 -0
  37. package/dist/hashes.js.map +1 -0
  38. package/dist/index.d.ts +64 -0
  39. package/dist/index.js +139 -0
  40. package/dist/index.js.map +1 -0
  41. package/dist/ledger-hashes.d.ts +49 -0
  42. package/dist/ledger-hashes.js +160 -0
  43. package/dist/ledger-hashes.js.map +1 -0
  44. package/dist/quality.d.ts +22 -0
  45. package/dist/quality.js +40 -0
  46. package/dist/quality.js.map +1 -0
  47. package/dist/serdes/binary-parser.d.ts +101 -0
  48. package/dist/serdes/binary-parser.js +210 -0
  49. package/dist/serdes/binary-parser.js.map +1 -0
  50. package/dist/serdes/binary-serializer.d.ts +82 -0
  51. package/dist/serdes/binary-serializer.js +172 -0
  52. package/dist/serdes/binary-serializer.js.map +1 -0
  53. package/dist/shamap.d.ts +103 -0
  54. package/dist/shamap.js +172 -0
  55. package/dist/shamap.js.map +1 -0
  56. package/dist/types/account-id.d.ts +36 -0
  57. package/dist/types/account-id.js +71 -0
  58. package/dist/types/account-id.js.map +1 -0
  59. package/dist/types/amount.d.ts +68 -0
  60. package/dist/types/amount.js +207 -0
  61. package/dist/types/amount.js.map +1 -0
  62. package/dist/types/blob.d.ts +25 -0
  63. package/dist/types/blob.js +40 -0
  64. package/dist/types/blob.js.map +1 -0
  65. package/dist/types/currency.d.ts +29 -0
  66. package/dist/types/currency.js +127 -0
  67. package/dist/types/currency.js.map +1 -0
  68. package/dist/types/hash-128.d.ts +17 -0
  69. package/dist/types/hash-128.js +32 -0
  70. package/dist/types/hash-128.js.map +1 -0
  71. package/dist/types/hash-160.d.ts +11 -0
  72. package/dist/types/hash-160.js +20 -0
  73. package/dist/types/hash-160.js.map +1 -0
  74. package/dist/types/hash-256.d.ts +11 -0
  75. package/dist/types/hash-256.js +17 -0
  76. package/dist/types/hash-256.js.map +1 -0
  77. package/dist/types/hash.d.ts +41 -0
  78. package/dist/types/hash.js +72 -0
  79. package/dist/types/hash.js.map +1 -0
  80. package/dist/types/index.d.ts +18 -0
  81. package/dist/types/index.js +57 -0
  82. package/dist/types/index.js.map +1 -0
  83. package/dist/types/issue.d.ts +39 -0
  84. package/dist/types/issue.js +81 -0
  85. package/dist/types/issue.js.map +1 -0
  86. package/dist/types/path-set.d.ts +36 -0
  87. package/dist/types/path-set.js +233 -0
  88. package/dist/types/path-set.js.map +1 -0
  89. package/dist/types/serialized-type.d.ts +63 -0
  90. package/dist/types/serialized-type.js +97 -0
  91. package/dist/types/serialized-type.js.map +1 -0
  92. package/dist/types/st-array.d.ts +28 -0
  93. package/dist/types/st-array.js +80 -0
  94. package/dist/types/st-array.js.map +1 -0
  95. package/dist/types/st-object.d.ts +32 -0
  96. package/dist/types/st-object.js +149 -0
  97. package/dist/types/st-object.js.map +1 -0
  98. package/dist/types/uint-16.d.ts +25 -0
  99. package/dist/types/uint-16.js +44 -0
  100. package/dist/types/uint-16.js.map +1 -0
  101. package/dist/types/uint-32.d.ts +25 -0
  102. package/dist/types/uint-32.js +49 -0
  103. package/dist/types/uint-32.js.map +1 -0
  104. package/dist/types/uint-64.d.ts +39 -0
  105. package/dist/types/uint-64.js +87 -0
  106. package/dist/types/uint-64.js.map +1 -0
  107. package/dist/types/uint-8.d.ts +25 -0
  108. package/dist/types/uint-8.js +44 -0
  109. package/dist/types/uint-8.js.map +1 -0
  110. package/dist/types/uint.d.ts +30 -0
  111. package/dist/types/uint.js +42 -0
  112. package/dist/types/uint.js.map +1 -0
  113. package/dist/types/vector-256.d.ts +31 -0
  114. package/dist/types/vector-256.js +75 -0
  115. package/dist/types/vector-256.js.map +1 -0
  116. package/package.json +47 -0
  117. package/test/amount.test.js +43 -0
  118. package/test/binary-json.test.js +45 -0
  119. package/test/binary-parser.test.js +396 -0
  120. package/test/binary-serializer.test.js +289 -0
  121. package/test/definitions.test.js +100 -0
  122. package/test/fixtures/account-tx-transactions.db +0 -0
  123. package/test/fixtures/codec-fixtures.json +4466 -0
  124. package/test/fixtures/data-driven-tests.json +2919 -0
  125. package/test/fixtures/delivermin-tx-binary.json +1 -0
  126. package/test/fixtures/delivermin-tx.json +98 -0
  127. package/test/fixtures/deposit-preauth-tx-binary.json +1 -0
  128. package/test/fixtures/deposit-preauth-tx-meta-binary.json +1 -0
  129. package/test/fixtures/deposit-preauth-tx.json +58 -0
  130. package/test/fixtures/escrow-cancel-binary.json +1 -0
  131. package/test/fixtures/escrow-cancel-tx.json +6 -0
  132. package/test/fixtures/escrow-create-binary.json +1 -0
  133. package/test/fixtures/escrow-create-tx.json +10 -0
  134. package/test/fixtures/escrow-finish-binary.json +1 -0
  135. package/test/fixtures/escrow-finish-meta-binary.json +1 -0
  136. package/test/fixtures/escrow-finish-tx.json +95 -0
  137. package/test/fixtures/ledger-full-38129.json +1 -0
  138. package/test/fixtures/ledger-full-40000.json +1 -0
  139. package/test/fixtures/negative-unl.json +12 -0
  140. package/test/fixtures/nf-token.json +547 -0
  141. package/test/fixtures/payment-channel-claim-binary.json +1 -0
  142. package/test/fixtures/payment-channel-claim-tx.json +8 -0
  143. package/test/fixtures/payment-channel-create-binary.json +1 -0
  144. package/test/fixtures/payment-channel-create-tx.json +11 -0
  145. package/test/fixtures/payment-channel-fund-binary.json +1 -0
  146. package/test/fixtures/payment-channel-fund-tx.json +7 -0
  147. package/test/fixtures/signerlistset-tx-binary.json +1 -0
  148. package/test/fixtures/signerlistset-tx-meta-binary.json +1 -0
  149. package/test/fixtures/signerlistset-tx.json +94 -0
  150. package/test/fixtures/ticket-create-binary.json +1 -0
  151. package/test/fixtures/ticket-create-tx.json +7 -0
  152. package/test/fixtures/x-codec-fixtures.json +188 -0
  153. package/test/hash.test.js +135 -0
  154. package/test/ledger.test.js +29 -0
  155. package/test/lower-case-hex.test.js +46 -0
  156. package/test/pseudo-transaction.test.js +38 -0
  157. package/test/quality.test.js +15 -0
  158. package/test/shamap.test.js +89 -0
  159. package/test/signing-data-encoding.test.js +242 -0
  160. package/test/tx-encode-decode.test.js +119 -0
  161. package/test/types.test.js +34 -0
  162. package/test/uint.test.js +148 -0
  163. package/test/utils.js +30 -0
  164. package/test/x-address.test.js +181 -0
@@ -0,0 +1,242 @@
1
+ const { throws } = require('assert')
2
+ const {
3
+ encodeForSigning,
4
+ encodeForSigningClaim,
5
+ encodeForMultisigning,
6
+ } = require('../src')
7
+ const { XrplDefinitions } = require('../src/enums/xrpl-definitions')
8
+
9
+ const normalDefinitions = require('../src/enums/definitions.json')
10
+
11
+ const tx_json = {
12
+ Account: 'r9LqNeG6qHxjeUocjvVki2XR35weJ9mZgQ',
13
+ Amount: '1000',
14
+ Destination: 'rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh',
15
+ Fee: '10',
16
+ Flags: 2147483648,
17
+ Sequence: 1,
18
+ TransactionType: 'Payment',
19
+ TxnSignature:
20
+ '30440220718D264EF05CAED7C781FF6DE298DCAC68D002562C9BF3A07C1' +
21
+ 'E721B420C0DAB02203A5A4779EF4D2CCC7BC3EF886676D803A9981B928D3B8ACA483B80' +
22
+ 'ECA3CD7B9B',
23
+ Signature:
24
+ '30440220718D264EF05CAED7C781FF6DE298DCAC68D002562C9BF3A07C1E72' +
25
+ '1B420C0DAB02203A5A4779EF4D2CCC7BC3EF886676D803A9981B928D3B8ACA483B80ECA' +
26
+ '3CD7B9B',
27
+ SigningPubKey:
28
+ 'ED5F5AC8B98974A3CA843326D9B88CEBD0560177B973EE0B149F782CFAA06DC66A',
29
+ }
30
+
31
+ describe('Signing data', function () {
32
+ test('can create single signing blobs', function () {
33
+ const actual = encodeForSigning(tx_json)
34
+ expect(actual).toBe(
35
+ [
36
+ '53545800', // signingPrefix
37
+ // TransactionType
38
+ '12',
39
+ '0000',
40
+ // Flags
41
+ '22',
42
+ '80000000',
43
+ // Sequence
44
+ '24',
45
+ '00000001',
46
+ // Amount
47
+ '61',
48
+ // native amount
49
+ '40000000000003E8',
50
+ // Fee
51
+ '68',
52
+ // native amount
53
+ '400000000000000A',
54
+ // SigningPubKey
55
+ '73',
56
+ // VLLength
57
+ '21',
58
+ 'ED5F5AC8B98974A3CA843326D9B88CEBD0560177B973EE0B149F782CFAA06DC66A',
59
+ // Account
60
+ '81',
61
+ // VLLength
62
+ '14',
63
+ '5B812C9D57731E27A2DA8B1830195F88EF32A3B6',
64
+ // Destination
65
+ '83',
66
+ // VLLength
67
+ '14',
68
+ 'B5F762798A53D543A014CAF8B297CFF8F2F937E8',
69
+ ].join(''),
70
+ )
71
+ })
72
+
73
+ test('can create single signing blobs with modified type', function () {
74
+ const customPaymentDefinitions = JSON.parse(
75
+ JSON.stringify(normalDefinitions),
76
+ )
77
+ customPaymentDefinitions.TRANSACTION_TYPES.Payment = 31
78
+
79
+ const newDefs = new XrplDefinitions(customPaymentDefinitions)
80
+ const actual = encodeForSigning(tx_json, newDefs)
81
+ expect(actual).toBe(
82
+ [
83
+ '53545800', // signingPrefix
84
+ // TransactionType
85
+ '12',
86
+ '001F',
87
+ // Flags
88
+ '22',
89
+ '80000000',
90
+ // Sequence
91
+ '24',
92
+ '00000001',
93
+ // Amount
94
+ '61',
95
+ // native amount
96
+ '40000000000003E8',
97
+ // Fee
98
+ '68',
99
+ // native amount
100
+ '400000000000000A',
101
+ // SigningPubKey
102
+ '73',
103
+ // VLLength
104
+ '21',
105
+ 'ED5F5AC8B98974A3CA843326D9B88CEBD0560177B973EE0B149F782CFAA06DC66A',
106
+ // Account
107
+ '81',
108
+ // VLLength
109
+ '14',
110
+ '5B812C9D57731E27A2DA8B1830195F88EF32A3B6',
111
+ // Destination
112
+ '83',
113
+ // VLLength
114
+ '14',
115
+ 'B5F762798A53D543A014CAF8B297CFF8F2F937E8',
116
+ ].join(''),
117
+ )
118
+ })
119
+
120
+ test('can fail gracefully for invalid TransactionType', function () {
121
+ const invalidTransactionType = {
122
+ ...tx_json,
123
+ TransactionType: 'NotAPayment',
124
+ }
125
+
126
+ throws(() => encodeForSigning(invalidTransactionType), /NotAPayment/u)
127
+ })
128
+
129
+ test('can create multi signing blobs', function () {
130
+ const signingAccount = 'rJZdUusLDtY9NEsGea7ijqhVrXv98rYBYN'
131
+ const signingJson = { ...tx_json, SigningPubKey: '' }
132
+ const actual = encodeForMultisigning(signingJson, signingAccount)
133
+ expect(actual).toBe(
134
+ [
135
+ '534D5400', // signingPrefix
136
+ // TransactionType
137
+ '12',
138
+ '0000',
139
+ // Flags
140
+ '22',
141
+ '80000000',
142
+ // Sequence
143
+ '24',
144
+ '00000001',
145
+ // Amount
146
+ '61',
147
+ // native amount
148
+ '40000000000003E8',
149
+ // Fee
150
+ '68',
151
+ // native amount
152
+ '400000000000000A',
153
+ // SigningPubKey
154
+ '73',
155
+ // VLLength
156
+ '00',
157
+ // '',
158
+ // Account
159
+ '81',
160
+ // VLLength
161
+ '14',
162
+ '5B812C9D57731E27A2DA8B1830195F88EF32A3B6',
163
+ // Destination
164
+ '83',
165
+ // VLLength
166
+ '14',
167
+ 'B5F762798A53D543A014CAF8B297CFF8F2F937E8',
168
+ // signingAccount suffix
169
+ 'C0A5ABEF242802EFED4B041E8F2D4A8CC86AE3D1',
170
+ ].join(''),
171
+ )
172
+ })
173
+
174
+ test('can create multi signing blobs with custom definitions', function () {
175
+ const customPaymentDefinitions = JSON.parse(
176
+ JSON.stringify(normalDefinitions),
177
+ )
178
+ customPaymentDefinitions.TRANSACTION_TYPES.Payment = 31
179
+
180
+ const newDefs = new XrplDefinitions(customPaymentDefinitions)
181
+ const signingAccount = 'rJZdUusLDtY9NEsGea7ijqhVrXv98rYBYN'
182
+ const signingJson = { ...tx_json, SigningPubKey: '' }
183
+ const actual = encodeForMultisigning(signingJson, signingAccount, newDefs)
184
+ expect(actual).toBe(
185
+ [
186
+ '534D5400', // signingPrefix
187
+ // TransactionType
188
+ '12',
189
+ '001F',
190
+ // Flags
191
+ '22',
192
+ '80000000',
193
+ // Sequence
194
+ '24',
195
+ '00000001',
196
+ // Amount
197
+ '61',
198
+ // native amount
199
+ '40000000000003E8',
200
+ // Fee
201
+ '68',
202
+ // native amount
203
+ '400000000000000A',
204
+ // SigningPubKey
205
+ '73',
206
+ // VLLength
207
+ '00',
208
+ // '',
209
+ // Account
210
+ '81',
211
+ // VLLength
212
+ '14',
213
+ '5B812C9D57731E27A2DA8B1830195F88EF32A3B6',
214
+ // Destination
215
+ '83',
216
+ // VLLength
217
+ '14',
218
+ 'B5F762798A53D543A014CAF8B297CFF8F2F937E8',
219
+ // signingAccount suffix
220
+ 'C0A5ABEF242802EFED4B041E8F2D4A8CC86AE3D1',
221
+ ].join(''),
222
+ )
223
+ })
224
+
225
+ test('can create claim blob', function () {
226
+ const channel =
227
+ '43904CBFCDCEC530B4037871F86EE90BF799DF8D2E0EA564BC8A3F332E4F5FB1'
228
+ const amount = '1000'
229
+ const json = { channel, amount }
230
+ const actual = encodeForSigningClaim(json)
231
+ expect(actual).toBe(
232
+ [
233
+ // hash prefix
234
+ '434C4D00',
235
+ // channel ID
236
+ '43904CBFCDCEC530B4037871F86EE90BF799DF8D2E0EA564BC8A3F332E4F5FB1',
237
+ // amount as a uint64
238
+ '00000000000003E8',
239
+ ].join(''),
240
+ )
241
+ })
242
+ })
@@ -0,0 +1,119 @@
1
+ const { encode, decode } = require('../src')
2
+
3
+ // Notice: no Amount or Fee
4
+ const tx_json = {
5
+ Account: 'r9LqNeG6qHxjeUocjvVki2XR35weJ9mZgQ',
6
+ // Amount: '1000',
7
+ Destination: 'rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh',
8
+ // Fee: '10',
9
+
10
+ // JavaScript converts operands to 32-bit signed ints after doing bitwise
11
+ // operations. We need to convert it back to an unsigned int with >>> 0.
12
+ Flags: (1 << 31) >>> 0, // tfFullyCanonicalSig
13
+
14
+ Sequence: 1,
15
+ TransactionType: 'Payment',
16
+ // TxnSignature,
17
+ // Signature,
18
+ // SigningPubKey
19
+ }
20
+
21
+ describe('encoding and decoding tx_json', function () {
22
+ test('can encode tx_json without Amount or Fee', function () {
23
+ const encoded = encode(tx_json)
24
+ const decoded = decode(encoded)
25
+ expect(tx_json).toEqual(decoded)
26
+ })
27
+ test('can encode tx_json with Amount and Fee', function () {
28
+ const my_tx = Object.assign({}, tx_json, {
29
+ Amount: '1000',
30
+ Fee: '10',
31
+ })
32
+ const encoded = encode(my_tx)
33
+ const decoded = decode(encoded)
34
+ expect(my_tx).toEqual(decoded)
35
+ })
36
+ test('can encode tx_json with TicketCount', function () {
37
+ const my_tx = Object.assign({}, tx_json, {
38
+ TicketCount: 2,
39
+ })
40
+ const encoded = encode(my_tx)
41
+ const decoded = decode(encoded)
42
+ expect(my_tx).toEqual(decoded)
43
+ })
44
+ test('can encode tx_json with TicketSequence', function () {
45
+ const my_tx = Object.assign({}, tx_json, {
46
+ Sequence: 0,
47
+ TicketSequence: 2,
48
+ })
49
+ const encoded = encode(my_tx)
50
+ const decoded = decode(encoded)
51
+ expect(my_tx).toEqual(decoded)
52
+ })
53
+ test('can decode a transaction with an issued currency that evaluates to XRP', function () {
54
+ // Encoding is done prior, because this is disallowed during encoding with client libraries to avoid scam XRP tokens.
55
+ const expectedTx = {
56
+ TransactionType: 'TrustSet',
57
+ Flags: 0,
58
+ Sequence: 19,
59
+ LimitAmount: {
60
+ value: '200',
61
+ currency: '0000000000000000000000005852500000000000',
62
+ issuer: 'r9hEDb4xBGRfBCcX3E4FirDWQBAYtpxC8K',
63
+ },
64
+ Fee: '10',
65
+ SigningPubKey:
66
+ '023076CBB7A61837F1A23D4A3DD7CE810B694992EB0959AB9D6F4BB6FED6F8CC26',
67
+ TxnSignature:
68
+ '304502202D0CD77D8E765E3783C309CD663723B18406B7950A348A6F301492916A990FC70221008A76D586111205304F10ADEFDFDDAF804EF202D8CD1E492DC6E1AA8030EA1844',
69
+ Account: 'rPtfQWdcdhuL9eNeNv5YfmekSX3K7vJHbG',
70
+ }
71
+ const encoded = encode(expectedTx)
72
+ const decoded = decode(encoded)
73
+ expect(expectedTx).toEqual(decoded)
74
+ })
75
+ test('throws when Amount is invalid', function () {
76
+ const my_tx = Object.assign({}, tx_json, {
77
+ Amount: '1000.001',
78
+ Fee: '10',
79
+ })
80
+ expect(() => {
81
+ encode(my_tx)
82
+ }).toThrow()
83
+ })
84
+ test('throws when Fee is invalid', function () {
85
+ const my_tx = Object.assign({}, tx_json, {
86
+ Amount: '1000',
87
+ Fee: '10.123',
88
+ })
89
+ expect(() => {
90
+ encode(my_tx)
91
+ }).toThrow()
92
+ })
93
+ test('throws when Amount and Fee are invalid', function () {
94
+ const my_tx = Object.assign({}, tx_json, {
95
+ Amount: '1000.789',
96
+ Fee: '10.123',
97
+ })
98
+ expect(() => {
99
+ encode(my_tx)
100
+ }).toThrow()
101
+ })
102
+ test('throws when Amount is a number instead of a string-encoded integer', function () {
103
+ const my_tx = Object.assign({}, tx_json, {
104
+ Amount: 1000.789,
105
+ })
106
+ expect(() => {
107
+ encode(my_tx)
108
+ }).toThrow()
109
+ })
110
+
111
+ test('throws when Fee is a number instead of a string-encoded integer', function () {
112
+ const my_tx = Object.assign({}, tx_json, {
113
+ Amount: 1234.56,
114
+ })
115
+ expect(() => {
116
+ encode(my_tx)
117
+ }).toThrow()
118
+ })
119
+ })
@@ -0,0 +1,34 @@
1
+ const { coreTypes } = require('../src/types')
2
+ const { SerializedType } = require('../src/types/serialized-type')
3
+
4
+ describe('SerializedType interfaces', () => {
5
+ Object.entries(coreTypes).forEach(([name, Value]) => {
6
+ test(`${name} has a \`from\` static constructor`, () => {
7
+ expect(Value.from && Value.from !== Array.from).toBe(true)
8
+ })
9
+ test(`${name} has a default constructor`, () => {
10
+ expect(new Value()).not.toBe(undefined)
11
+ })
12
+ test(`${name}.from will return the same object`, () => {
13
+ const instance = new Value()
14
+ expect(Value.from(instance) === instance).toBe(true)
15
+ })
16
+ test(`${name} instances have toBytesSink`, () => {
17
+ expect(new Value().toBytesSink).not.toBe(undefined)
18
+ })
19
+ test(`${name} instances have toJSON`, () => {
20
+ expect(new Value().toJSON).not.toBe(undefined)
21
+ })
22
+ test(`${name}.from(json).toJSON() == json`, () => {
23
+ const newJSON = new Value().toJSON()
24
+ expect(Value.from(newJSON).toJSON()).toEqual(newJSON)
25
+ })
26
+ describe(`${name} supports all methods of the SerializedType mixin`, () => {
27
+ Object.keys(SerializedType.prototype).forEach((k) => {
28
+ test(`new ${name}.prototype.${k} !== undefined`, () => {
29
+ expect(Value.prototype[k]).not.toBe(undefined)
30
+ })
31
+ })
32
+ })
33
+ })
34
+ })
@@ -0,0 +1,148 @@
1
+ const { coreTypes } = require('../src/types')
2
+ const { UInt8, UInt64 } = coreTypes
3
+
4
+ const { encode } = require('../src')
5
+
6
+ const binary =
7
+ '11007222000300003700000000000000003800000000000000006280000000000000000000000000000000000000005553440000000000000000000000000000000000000000000000000166D5438D7EA4C680000000000000000000000000005553440000000000AE123A8556F3CF91154711376AFB0F894F832B3D67D5438D7EA4C680000000000000000000000000005553440000000000F51DFC2A09D62CBBA1DFBDD4691DAC96AD98B90F'
8
+ const json = {
9
+ Balance: {
10
+ currency: 'USD',
11
+ issuer: 'rrrrrrrrrrrrrrrrrrrrBZbvji',
12
+ value: '0',
13
+ },
14
+ Flags: 196608,
15
+ HighLimit: {
16
+ currency: 'USD',
17
+ issuer: 'rPMh7Pi9ct699iZUTWaytJUoHcJ7cgyziK',
18
+ value: '1000',
19
+ },
20
+ HighNode: '0',
21
+ LedgerEntryType: 'RippleState',
22
+ LowLimit: {
23
+ currency: 'USD',
24
+ issuer: 'rG1QQv2nh2gr7RCZ1P8YYcBUKCCN633jCn',
25
+ value: '1000',
26
+ },
27
+ LowNode: '0',
28
+ }
29
+
30
+ const binaryEntry0 =
31
+ '11007222001100002501EC24873700000000000000003800000000000000A35506FC7DE374089D50F81AAE13E7BBF3D0E694769331E14F55351B38D0148018EA62D44BF89AC2A40B800000000000000000000000004A50590000000000000000000000000000000000000000000000000166D6C38D7EA4C680000000000000000000000000004A5059000000000047C1258B4B79774B28176324068F759EDE226F686780000000000000000000000000000000000000004A505900000000005BBC0F22F61D9224A110650CFE21CC0C4BE13098'
32
+ const jsonEntry0 = {
33
+ Balance: {
34
+ currency: 'JPY',
35
+ issuer: 'rrrrrrrrrrrrrrrrrrrrBZbvji',
36
+ value: '0.3369568318',
37
+ },
38
+ Flags: 1114112,
39
+ HighLimit: {
40
+ currency: 'JPY',
41
+ issuer: 'r94s8px6kSw1uZ1MV98dhSRTvc6VMPoPcN',
42
+ value: '0',
43
+ },
44
+ HighNode: 'a3',
45
+ LedgerEntryType: 'RippleState',
46
+ LowLimit: {
47
+ currency: 'JPY',
48
+ issuer: 'rfYQMgj3g3Qp8VLoZNvvU35mEuuJC8nCmY',
49
+ value: '1000000000',
50
+ },
51
+ LowNode: '0',
52
+ PreviousTxnID:
53
+ '06FC7DE374089D50F81AAE13E7BBF3D0E694769331E14F55351B38D0148018EA',
54
+ PreviousTxnLgrSeq: 32253063,
55
+ index: '000319BAE0A618A7D3BB492F17E98E5D92EA0C6458AFEBED44206B5B4798A840',
56
+ }
57
+
58
+ const binaryEntry1 =
59
+ '1100642200000000320000000000000002580CB3C1AD2C371136AEA434246D971C5FCCD32CBF520667E131AB7B10D706E7528214BA53D10260FFCC968ACD16BA30F7CEABAD6E5D92011340A3454ACED87177146EABD5E4A256021D836D1E3617618B1EB362D10B0D1BAC6AE1ED9E8D280BBE0B6656748FD647231851C6C650794D5E6852DFA1E35E68630F'
60
+ const jsonEntry1 = {
61
+ Flags: 0,
62
+ IndexPrevious: '2',
63
+ Indexes: [
64
+ 'A3454ACED87177146EABD5E4A256021D836D1E3617618B1EB362D10B0D1BAC6A',
65
+ 'E1ED9E8D280BBE0B6656748FD647231851C6C650794D5E6852DFA1E35E68630F',
66
+ ],
67
+ LedgerEntryType: 'DirectoryNode',
68
+ Owner: 'rHzDaMNybxQppiE3uWyt2N265KvAKdiRdP',
69
+ RootIndex: '0CB3C1AD2C371136AEA434246D971C5FCCD32CBF520667E131AB7B10D706E752',
70
+ index: '0B4A2E68C111F7E42FAEEE405F7344560C8240840B151D9D04131EB79D080167',
71
+ }
72
+
73
+ const binaryEntry2 =
74
+ '1100722200210000250178D1CA37000000000000000038000000000000028355C0C37CE200B509E0A529880634F7841A9EF4CB65F03C12E6004CFAD9718D66946280000000000000000000000000000000000000004743420000000000000000000000000000000000000000000000000166D6071AFD498D000000000000000000000000000047434200000000002599D1D255BCA61189CA64C84528F2FCBE4BFC3867800000000000000000000000000000000000000047434200000000006EEBB1D1852CE667876A0B3630861FB6C6AB358E'
75
+ const jsonEntry2 = {
76
+ Balance: {
77
+ currency: 'GCB',
78
+ issuer: 'rrrrrrrrrrrrrrrrrrrrBZbvji',
79
+ value: '0',
80
+ },
81
+ Flags: 2162688,
82
+ HighLimit: {
83
+ currency: 'GCB',
84
+ issuer: 'rBfVgTnsdh8ckC19RM8aVGNuMZnpwrMP6n',
85
+ value: '0',
86
+ },
87
+ HighNode: '283',
88
+ LedgerEntryType: 'RippleState',
89
+ LowLimit: {
90
+ currency: 'GCB',
91
+ issuer: 'rhRFGCy2RJTA8oxkjjtYTvofPVGqcgvXWj',
92
+ value: '2000000',
93
+ },
94
+ LowNode: '0',
95
+ PreviousTxnID:
96
+ 'C0C37CE200B509E0A529880634F7841A9EF4CB65F03C12E6004CFAD9718D6694',
97
+ PreviousTxnLgrSeq: 24695242,
98
+ index: '0000041EFD027808D3F78C8352F97E324CB816318E00B977C74ECDDC7CD975B2',
99
+ }
100
+
101
+ test('compareToTests[0]', () => {
102
+ expect(UInt8.from(124).compareTo(UInt64.from(124))).toBe(0)
103
+ })
104
+
105
+ test('compareToTest[1]', () => {
106
+ expect(UInt64.from(124).compareTo(UInt8.from(124))).toBe(0)
107
+ })
108
+
109
+ test('compareToTest[2]', () => {
110
+ expect(UInt64.from(124).compareTo(UInt8.from(123))).toBe(1)
111
+ })
112
+
113
+ test('compareToTest[3]', () => {
114
+ expect(UInt8.from(124).compareTo(UInt8.from(13))).toBe(1)
115
+ })
116
+
117
+ test('compareToTest[4]', () => {
118
+ expect(UInt8.from(124).compareTo(124)).toBe(0)
119
+ })
120
+
121
+ test('compareToTest[5]', () => {
122
+ expect(UInt64.from(124).compareTo(124)).toBe(0)
123
+ })
124
+
125
+ test('compareToTest[6]', () => {
126
+ expect(UInt64.from(124).compareTo(123)).toBe(1)
127
+ })
128
+
129
+ test('compareToTest[7]', () => {
130
+ expect(UInt8.from(124).compareTo(13)).toBe(1)
131
+ })
132
+
133
+ test('UInt64 from string zero', () => {
134
+ expect(UInt64.from('0')).toEqual(UInt64.from(0))
135
+ expect(encode(json)).toEqual(binary)
136
+ })
137
+
138
+ test('UInt64 from non 16 length hex', () => {
139
+ expect(encode(jsonEntry0)).toEqual(binaryEntry0)
140
+ expect(encode(jsonEntry1)).toEqual(binaryEntry1)
141
+ expect(encode(jsonEntry2)).toEqual(binaryEntry2)
142
+ })
143
+
144
+ test('valueOfTests', () => {
145
+ let val = UInt8.from(1)
146
+ val |= 0x2
147
+ expect(val).toBe(3)
148
+ })
package/test/utils.js ADDED
@@ -0,0 +1,30 @@
1
+ const fs = require("fs");
2
+ const { Buffer } = require('buffer/')
3
+
4
+ function hexOnly(hex) {
5
+ return hex.replace(/[^a-fA-F0-9]/g, "");
6
+ }
7
+
8
+ function unused() {}
9
+
10
+ function parseHexOnly(hex) {
11
+ return Buffer.from(hexOnly(hex), "hex");
12
+ }
13
+
14
+ function loadFixture(relativePath) {
15
+ const fn = __dirname + "/fixtures/" + relativePath;
16
+ return require(fn);
17
+ }
18
+
19
+ function loadFixtureText(relativePath) {
20
+ const fn = __dirname + "/fixtures/" + relativePath;
21
+ return fs.readFileSync(fn).toString("utf8");
22
+ }
23
+
24
+ module.exports = {
25
+ hexOnly,
26
+ parseHexOnly,
27
+ loadFixture,
28
+ loadFixtureText,
29
+ unused,
30
+ };