ripple-binary-codec 1.2.0-beta.1 → 1.2.2

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/dist/binary.d.ts +6 -6
  2. package/dist/binary.js.map +1 -1
  3. package/dist/coretypes.d.ts +8 -8
  4. package/dist/coretypes.js.map +1 -1
  5. package/dist/enums/index.d.ts +6 -5
  6. package/dist/enums/index.js +3 -2
  7. package/dist/enums/index.js.map +1 -1
  8. package/dist/enums/utils-renumber.js +12 -12
  9. package/dist/enums/utils-renumber.js.map +1 -1
  10. package/dist/hash-prefixes.d.ts +1 -1
  11. package/dist/hash-prefixes.js.map +1 -1
  12. package/dist/hashes.d.ts +3 -3
  13. package/dist/hashes.js +5 -4
  14. package/dist/hashes.js.map +1 -1
  15. package/dist/index.d.ts +2 -2
  16. package/dist/index.js +13 -13
  17. package/dist/index.js.map +1 -1
  18. package/dist/ledger-hashes.d.ts +3 -3
  19. package/dist/ledger-hashes.js +5 -5
  20. package/dist/ledger-hashes.js.map +1 -1
  21. package/dist/quality.d.ts +2 -2
  22. package/dist/quality.js +4 -4
  23. package/dist/quality.js.map +1 -1
  24. package/dist/serdes/binary-parser.d.ts +3 -3
  25. package/dist/serdes/binary-parser.js +10 -10
  26. package/dist/serdes/binary-parser.js.map +1 -1
  27. package/dist/serdes/binary-serializer.d.ts +5 -5
  28. package/dist/serdes/binary-serializer.js +13 -8
  29. package/dist/serdes/binary-serializer.js.map +1 -1
  30. package/dist/shamap.d.ts +3 -3
  31. package/dist/shamap.js +5 -3
  32. package/dist/shamap.js.map +1 -1
  33. package/dist/types/account-id.d.ts +2 -2
  34. package/dist/types/account-id.js +12 -10
  35. package/dist/types/account-id.js.map +1 -1
  36. package/dist/types/amount.d.ts +3 -3
  37. package/dist/types/amount.js +23 -21
  38. package/dist/types/amount.js.map +1 -1
  39. package/dist/types/blob.d.ts +3 -3
  40. package/dist/types/blob.js +6 -4
  41. package/dist/types/blob.js.map +1 -1
  42. package/dist/types/currency.d.ts +2 -2
  43. package/dist/types/currency.js +14 -12
  44. package/dist/types/currency.js.map +1 -1
  45. package/dist/types/hash-128.d.ts +2 -2
  46. package/dist/types/hash-128.js +3 -1
  47. package/dist/types/hash-128.js.map +1 -1
  48. package/dist/types/hash-160.d.ts +2 -2
  49. package/dist/types/hash-160.js +3 -1
  50. package/dist/types/hash-160.js.map +1 -1
  51. package/dist/types/hash-256.d.ts +2 -2
  52. package/dist/types/hash-256.js +3 -1
  53. package/dist/types/hash-256.js.map +1 -1
  54. package/dist/types/hash.d.ts +3 -3
  55. package/dist/types/hash.js +7 -5
  56. package/dist/types/hash.js.map +1 -1
  57. package/dist/types/index.d.ts +15 -15
  58. package/dist/types/index.js +3 -3
  59. package/dist/types/index.js.map +1 -1
  60. package/dist/types/path-set.d.ts +2 -2
  61. package/dist/types/path-set.js +5 -3
  62. package/dist/types/path-set.js.map +1 -1
  63. package/dist/types/serialized-type.d.ts +4 -4
  64. package/dist/types/serialized-type.js +7 -5
  65. package/dist/types/serialized-type.js.map +1 -1
  66. package/dist/types/st-array.d.ts +2 -2
  67. package/dist/types/st-array.js +6 -4
  68. package/dist/types/st-array.js.map +1 -1
  69. package/dist/types/st-object.d.ts +2 -2
  70. package/dist/types/st-object.js +25 -14
  71. package/dist/types/st-object.js.map +1 -1
  72. package/dist/types/uint-16.d.ts +3 -3
  73. package/dist/types/uint-16.js +5 -3
  74. package/dist/types/uint-16.js.map +1 -1
  75. package/dist/types/uint-32.d.ts +3 -3
  76. package/dist/types/uint-32.js +6 -4
  77. package/dist/types/uint-32.js.map +1 -1
  78. package/dist/types/uint-64.d.ts +4 -4
  79. package/dist/types/uint-64.js +12 -10
  80. package/dist/types/uint-64.js.map +1 -1
  81. package/dist/types/uint-8.d.ts +3 -3
  82. package/dist/types/uint-8.js +5 -3
  83. package/dist/types/uint-8.js.map +1 -1
  84. package/dist/types/uint.d.ts +3 -3
  85. package/dist/types/uint.js +4 -2
  86. package/dist/types/uint.js.map +1 -1
  87. package/dist/types/vector-256.d.ts +3 -3
  88. package/dist/types/vector-256.js +7 -5
  89. package/dist/types/vector-256.js.map +1 -1
  90. package/package.json +14 -29
  91. package/test/amount.test.js +29 -29
  92. package/test/binary-json.test.js +24 -26
  93. package/test/binary-parser.test.js +225 -227
  94. package/test/binary-serializer.test.js +194 -169
  95. package/test/fixtures/negative-unl.json +4 -4
  96. package/test/fixtures/nf-token.json +547 -0
  97. package/test/hash.test.js +85 -78
  98. package/test/ledger.test.js +19 -19
  99. package/test/lower-case-hex.test.js +28 -28
  100. package/test/pseudo-transaction.test.js +26 -26
  101. package/test/quality.test.js +13 -13
  102. package/test/shamap.test.js +54 -54
  103. package/test/signing-data-encoding.test.js +79 -79
  104. package/test/tx-encode-decode.test.js +63 -63
  105. package/test/types.test.js +23 -23
  106. package/test/uint.test.js +107 -107
  107. package/test/x-address.test.js +106 -106
  108. package/dist/ShaMap/ShaMap.d.ts +0 -3
  109. package/dist/ShaMap/ShaMap.js +0 -25
  110. package/dist/ShaMap/ShaMap.js.map +0 -1
  111. package/dist/ShaMap/ShaMapInner.d.ts +0 -66
  112. package/dist/ShaMap/ShaMapInner.js +0 -145
  113. package/dist/ShaMap/ShaMapInner.js.map +0 -1
  114. package/dist/ShaMap/ShaMapLeaf.d.ts +0 -42
  115. package/dist/ShaMap/ShaMapLeaf.js +0 -84
  116. package/dist/ShaMap/ShaMapLeaf.js.map +0 -1
  117. package/dist/ShaMap/ShaMapNode.d.ts +0 -13
  118. package/dist/ShaMap/ShaMapNode.js +0 -12
  119. package/dist/ShaMap/ShaMapNode.js.map +0 -1
  120. package/dist/ShaMap/index.d.ts +0 -3
  121. package/dist/ShaMap/index.js +0 -9
  122. package/dist/ShaMap/index.js.map +0 -1
  123. package/dist/enums/Bytes.d.ts +0 -10
  124. package/dist/enums/Bytes.js +0 -30
  125. package/dist/enums/Bytes.js.map +0 -1
  126. package/dist/enums/BytesLookup.d.ts +0 -8
  127. package/dist/enums/BytesLookup.js +0 -29
  128. package/dist/enums/BytesLookup.js.map +0 -1
  129. package/dist/enums/Field.d.ts +0 -3
  130. package/dist/enums/Field.js +0 -9
  131. package/dist/enums/Field.js.map +0 -1
  132. package/dist/enums/FieldInfo.d.ts +0 -7
  133. package/dist/enums/FieldInfo.js +0 -3
  134. package/dist/enums/FieldInfo.js.map +0 -1
  135. package/dist/enums/FieldInstance.d.ts +0 -14
  136. package/dist/enums/FieldInstance.js +0 -3
  137. package/dist/enums/FieldInstance.js.map +0 -1
  138. package/dist/enums/FieldLookup.d.ts +0 -11
  139. package/dist/enums/FieldLookup.js +0 -102
  140. package/dist/enums/FieldLookup.js.map +0 -1
  141. package/dist/serdes/BinaryParser.d.ts +0 -100
  142. package/dist/serdes/BinaryParser.js +0 -200
  143. package/dist/serdes/BinaryParser.js.map +0 -1
  144. package/dist/serdes/BinarySerializer.d.ts +0 -50
  145. package/dist/serdes/BinarySerializer.js +0 -105
  146. package/dist/serdes/BinarySerializer.js.map +0 -1
  147. package/dist/serdes/BytesList.d.ts +0 -28
  148. package/dist/serdes/BytesList.js +0 -48
  149. package/dist/serdes/BytesList.js.map +0 -1
  150. package/dist/types/Comparable.d.ts +0 -18
  151. package/dist/types/Comparable.js +0 -43
  152. package/dist/types/Comparable.js.map +0 -1
  153. package/dist/types/PathSet/Hop.d.ts +0 -41
  154. package/dist/types/PathSet/Hop.js +0 -116
  155. package/dist/types/PathSet/Hop.js.map +0 -1
  156. package/dist/types/PathSet/Path.d.ts +0 -33
  157. package/dist/types/PathSet/Path.js +0 -83
  158. package/dist/types/PathSet/Path.js.map +0 -1
  159. package/dist/types/PathSet/index.d.ts +0 -29
  160. package/dist/types/PathSet/index.js +0 -98
  161. package/dist/types/PathSet/index.js.map +0 -1
  162. package/dist/types/SerializedType.d.ts +0 -47
  163. package/dist/types/SerializedType.js +0 -69
  164. package/dist/types/SerializedType.js.map +0 -1
package/test/uint.test.js CHANGED
@@ -1,148 +1,148 @@
1
- const { coreTypes } = require("../dist/types");
2
- const { UInt8, UInt64 } = coreTypes;
1
+ const { coreTypes } = require('../dist/types')
2
+ const { UInt8, UInt64 } = coreTypes
3
3
 
4
- const { encode } = require("../dist");
4
+ const { encode } = require('../dist')
5
5
 
6
6
  const binary =
7
- "11007222000300003700000000000000003800000000000000006280000000000000000000000000000000000000005553440000000000000000000000000000000000000000000000000166D5438D7EA4C680000000000000000000000000005553440000000000AE123A8556F3CF91154711376AFB0F894F832B3D67D5438D7EA4C680000000000000000000000000005553440000000000F51DFC2A09D62CBBA1DFBDD4691DAC96AD98B90F";
7
+ '11007222000300003700000000000000003800000000000000006280000000000000000000000000000000000000005553440000000000000000000000000000000000000000000000000166D5438D7EA4C680000000000000000000000000005553440000000000AE123A8556F3CF91154711376AFB0F894F832B3D67D5438D7EA4C680000000000000000000000000005553440000000000F51DFC2A09D62CBBA1DFBDD4691DAC96AD98B90F'
8
8
  const json = {
9
9
  Balance: {
10
- currency: "USD",
11
- issuer: "rrrrrrrrrrrrrrrrrrrrBZbvji",
12
- value: "0",
10
+ currency: 'USD',
11
+ issuer: 'rrrrrrrrrrrrrrrrrrrrBZbvji',
12
+ value: '0',
13
13
  },
14
14
  Flags: 196608,
15
15
  HighLimit: {
16
- currency: "USD",
17
- issuer: "rPMh7Pi9ct699iZUTWaytJUoHcJ7cgyziK",
18
- value: "1000",
16
+ currency: 'USD',
17
+ issuer: 'rPMh7Pi9ct699iZUTWaytJUoHcJ7cgyziK',
18
+ value: '1000',
19
19
  },
20
- HighNode: "0",
21
- LedgerEntryType: "RippleState",
20
+ HighNode: '0',
21
+ LedgerEntryType: 'RippleState',
22
22
  LowLimit: {
23
- currency: "USD",
24
- issuer: "rG1QQv2nh2gr7RCZ1P8YYcBUKCCN633jCn",
25
- value: "1000",
23
+ currency: 'USD',
24
+ issuer: 'rG1QQv2nh2gr7RCZ1P8YYcBUKCCN633jCn',
25
+ value: '1000',
26
26
  },
27
- LowNode: "0",
28
- };
27
+ LowNode: '0',
28
+ }
29
29
 
30
30
  const binaryEntry0 =
31
- "11007222001100002501EC24873700000000000000003800000000000000A35506FC7DE374089D50F81AAE13E7BBF3D0E694769331E14F55351B38D0148018EA62D44BF89AC2A40B800000000000000000000000004A50590000000000000000000000000000000000000000000000000166D6C38D7EA4C680000000000000000000000000004A5059000000000047C1258B4B79774B28176324068F759EDE226F686780000000000000000000000000000000000000004A505900000000005BBC0F22F61D9224A110650CFE21CC0C4BE13098";
31
+ '11007222001100002501EC24873700000000000000003800000000000000A35506FC7DE374089D50F81AAE13E7BBF3D0E694769331E14F55351B38D0148018EA62D44BF89AC2A40B800000000000000000000000004A50590000000000000000000000000000000000000000000000000166D6C38D7EA4C680000000000000000000000000004A5059000000000047C1258B4B79774B28176324068F759EDE226F686780000000000000000000000000000000000000004A505900000000005BBC0F22F61D9224A110650CFE21CC0C4BE13098'
32
32
  const jsonEntry0 = {
33
33
  Balance: {
34
- currency: "JPY",
35
- issuer: "rrrrrrrrrrrrrrrrrrrrBZbvji",
36
- value: "0.3369568318",
34
+ currency: 'JPY',
35
+ issuer: 'rrrrrrrrrrrrrrrrrrrrBZbvji',
36
+ value: '0.3369568318',
37
37
  },
38
38
  Flags: 1114112,
39
39
  HighLimit: {
40
- currency: "JPY",
41
- issuer: "r94s8px6kSw1uZ1MV98dhSRTvc6VMPoPcN",
42
- value: "0",
40
+ currency: 'JPY',
41
+ issuer: 'r94s8px6kSw1uZ1MV98dhSRTvc6VMPoPcN',
42
+ value: '0',
43
43
  },
44
- HighNode: "a3",
45
- LedgerEntryType: "RippleState",
44
+ HighNode: 'a3',
45
+ LedgerEntryType: 'RippleState',
46
46
  LowLimit: {
47
- currency: "JPY",
48
- issuer: "rfYQMgj3g3Qp8VLoZNvvU35mEuuJC8nCmY",
49
- value: "1000000000",
47
+ currency: 'JPY',
48
+ issuer: 'rfYQMgj3g3Qp8VLoZNvvU35mEuuJC8nCmY',
49
+ value: '1000000000',
50
50
  },
51
- LowNode: "0",
51
+ LowNode: '0',
52
52
  PreviousTxnID:
53
- "06FC7DE374089D50F81AAE13E7BBF3D0E694769331E14F55351B38D0148018EA",
53
+ '06FC7DE374089D50F81AAE13E7BBF3D0E694769331E14F55351B38D0148018EA',
54
54
  PreviousTxnLgrSeq: 32253063,
55
- index: "000319BAE0A618A7D3BB492F17E98E5D92EA0C6458AFEBED44206B5B4798A840",
56
- };
55
+ index: '000319BAE0A618A7D3BB492F17E98E5D92EA0C6458AFEBED44206B5B4798A840',
56
+ }
57
57
 
58
58
  const binaryEntry1 =
59
- "1100642200000000320000000000000002580CB3C1AD2C371136AEA434246D971C5FCCD32CBF520667E131AB7B10D706E7528214BA53D10260FFCC968ACD16BA30F7CEABAD6E5D92011340A3454ACED87177146EABD5E4A256021D836D1E3617618B1EB362D10B0D1BAC6AE1ED9E8D280BBE0B6656748FD647231851C6C650794D5E6852DFA1E35E68630F";
59
+ '1100642200000000320000000000000002580CB3C1AD2C371136AEA434246D971C5FCCD32CBF520667E131AB7B10D706E7528214BA53D10260FFCC968ACD16BA30F7CEABAD6E5D92011340A3454ACED87177146EABD5E4A256021D836D1E3617618B1EB362D10B0D1BAC6AE1ED9E8D280BBE0B6656748FD647231851C6C650794D5E6852DFA1E35E68630F'
60
60
  const jsonEntry1 = {
61
61
  Flags: 0,
62
- IndexPrevious: "2",
62
+ IndexPrevious: '2',
63
63
  Indexes: [
64
- "A3454ACED87177146EABD5E4A256021D836D1E3617618B1EB362D10B0D1BAC6A",
65
- "E1ED9E8D280BBE0B6656748FD647231851C6C650794D5E6852DFA1E35E68630F",
64
+ 'A3454ACED87177146EABD5E4A256021D836D1E3617618B1EB362D10B0D1BAC6A',
65
+ 'E1ED9E8D280BBE0B6656748FD647231851C6C650794D5E6852DFA1E35E68630F',
66
66
  ],
67
- LedgerEntryType: "DirectoryNode",
68
- Owner: "rHzDaMNybxQppiE3uWyt2N265KvAKdiRdP",
69
- RootIndex: "0CB3C1AD2C371136AEA434246D971C5FCCD32CBF520667E131AB7B10D706E752",
70
- index: "0B4A2E68C111F7E42FAEEE405F7344560C8240840B151D9D04131EB79D080167",
71
- };
67
+ LedgerEntryType: 'DirectoryNode',
68
+ Owner: 'rHzDaMNybxQppiE3uWyt2N265KvAKdiRdP',
69
+ RootIndex: '0CB3C1AD2C371136AEA434246D971C5FCCD32CBF520667E131AB7B10D706E752',
70
+ index: '0B4A2E68C111F7E42FAEEE405F7344560C8240840B151D9D04131EB79D080167',
71
+ }
72
72
 
73
73
  const binaryEntry2 =
74
- "1100722200210000250178D1CA37000000000000000038000000000000028355C0C37CE200B509E0A529880634F7841A9EF4CB65F03C12E6004CFAD9718D66946280000000000000000000000000000000000000004743420000000000000000000000000000000000000000000000000166D6071AFD498D000000000000000000000000000047434200000000002599D1D255BCA61189CA64C84528F2FCBE4BFC3867800000000000000000000000000000000000000047434200000000006EEBB1D1852CE667876A0B3630861FB6C6AB358E";
74
+ '1100722200210000250178D1CA37000000000000000038000000000000028355C0C37CE200B509E0A529880634F7841A9EF4CB65F03C12E6004CFAD9718D66946280000000000000000000000000000000000000004743420000000000000000000000000000000000000000000000000166D6071AFD498D000000000000000000000000000047434200000000002599D1D255BCA61189CA64C84528F2FCBE4BFC3867800000000000000000000000000000000000000047434200000000006EEBB1D1852CE667876A0B3630861FB6C6AB358E'
75
75
  const jsonEntry2 = {
76
76
  Balance: {
77
- currency: "GCB",
78
- issuer: "rrrrrrrrrrrrrrrrrrrrBZbvji",
79
- value: "0",
77
+ currency: 'GCB',
78
+ issuer: 'rrrrrrrrrrrrrrrrrrrrBZbvji',
79
+ value: '0',
80
80
  },
81
81
  Flags: 2162688,
82
82
  HighLimit: {
83
- currency: "GCB",
84
- issuer: "rBfVgTnsdh8ckC19RM8aVGNuMZnpwrMP6n",
85
- value: "0",
83
+ currency: 'GCB',
84
+ issuer: 'rBfVgTnsdh8ckC19RM8aVGNuMZnpwrMP6n',
85
+ value: '0',
86
86
  },
87
- HighNode: "283",
88
- LedgerEntryType: "RippleState",
87
+ HighNode: '283',
88
+ LedgerEntryType: 'RippleState',
89
89
  LowLimit: {
90
- currency: "GCB",
91
- issuer: "rhRFGCy2RJTA8oxkjjtYTvofPVGqcgvXWj",
92
- value: "2000000",
90
+ currency: 'GCB',
91
+ issuer: 'rhRFGCy2RJTA8oxkjjtYTvofPVGqcgvXWj',
92
+ value: '2000000',
93
93
  },
94
- LowNode: "0",
94
+ LowNode: '0',
95
95
  PreviousTxnID:
96
- "C0C37CE200B509E0A529880634F7841A9EF4CB65F03C12E6004CFAD9718D6694",
96
+ 'C0C37CE200B509E0A529880634F7841A9EF4CB65F03C12E6004CFAD9718D6694',
97
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
- });
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
+ })
@@ -1,181 +1,181 @@
1
- const { encode, decode } = require("./../dist/index");
2
- const fixtures = require("./fixtures/x-codec-fixtures.json");
1
+ const { encode, decode } = require('./../dist/index')
2
+ const fixtures = require('./fixtures/x-codec-fixtures.json')
3
3
 
4
4
  let json_x1 = {
5
5
  OwnerCount: 0,
6
- Account: "XVXdn5wEVm5G4UhEHWDPqjvdeH361P7BsapL4m2D2XnPSwT",
6
+ Account: 'XVXdn5wEVm5G4UhEHWDPqjvdeH361P7BsapL4m2D2XnPSwT',
7
7
  PreviousTxnLgrSeq: 7,
8
- LedgerEntryType: "AccountRoot",
8
+ LedgerEntryType: 'AccountRoot',
9
9
  PreviousTxnID:
10
- "DF530FB14C5304852F20080B0A8EEF3A6BDD044F41F4EBBD68B8B321145FE4FF",
10
+ 'DF530FB14C5304852F20080B0A8EEF3A6BDD044F41F4EBBD68B8B321145FE4FF',
11
11
  Flags: 0,
12
12
  Sequence: 1,
13
- Balance: "10000000000",
14
- };
13
+ Balance: '10000000000',
14
+ }
15
15
 
16
16
  let json_r1 = {
17
17
  OwnerCount: 0,
18
- Account: "rLs1MzkFWCxTbuAHgjeTZK4fcCDDnf2KRv",
18
+ Account: 'rLs1MzkFWCxTbuAHgjeTZK4fcCDDnf2KRv',
19
19
  PreviousTxnLgrSeq: 7,
20
- LedgerEntryType: "AccountRoot",
20
+ LedgerEntryType: 'AccountRoot',
21
21
  PreviousTxnID:
22
- "DF530FB14C5304852F20080B0A8EEF3A6BDD044F41F4EBBD68B8B321145FE4FF",
22
+ 'DF530FB14C5304852F20080B0A8EEF3A6BDD044F41F4EBBD68B8B321145FE4FF',
23
23
  Flags: 0,
24
24
  Sequence: 1,
25
- Balance: "10000000000",
25
+ Balance: '10000000000',
26
26
  SourceTag: 12345,
27
- };
27
+ }
28
28
 
29
29
  let json_null_x = {
30
30
  OwnerCount: 0,
31
- Account: "rLs1MzkFWCxTbuAHgjeTZK4fcCDDnf2KRv",
32
- Destination: "rLs1MzkFWCxTbuAHgjeTZK4fcCDDnf2KRv",
33
- Issuer: "XVXdn5wEVm5G4UhEHWDPqjvdeH361P4GETfNyyXGaoqBj71",
31
+ Account: 'rLs1MzkFWCxTbuAHgjeTZK4fcCDDnf2KRv',
32
+ Destination: 'rLs1MzkFWCxTbuAHgjeTZK4fcCDDnf2KRv',
33
+ Issuer: 'XVXdn5wEVm5G4UhEHWDPqjvdeH361P4GETfNyyXGaoqBj71',
34
34
  PreviousTxnLgrSeq: 7,
35
- LedgerEntryType: "AccountRoot",
35
+ LedgerEntryType: 'AccountRoot',
36
36
  PreviousTxnID:
37
- "DF530FB14C5304852F20080B0A8EEF3A6BDD044F41F4EBBD68B8B321145FE4FF",
37
+ 'DF530FB14C5304852F20080B0A8EEF3A6BDD044F41F4EBBD68B8B321145FE4FF',
38
38
  Flags: 0,
39
39
  Sequence: 1,
40
- Balance: "10000000000",
41
- };
40
+ Balance: '10000000000',
41
+ }
42
42
 
43
43
  let json_invalid_x = {
44
44
  OwnerCount: 0,
45
- Account: "rLs1MzkFWCxTbuAHgjeTZK4fcCDDnf2KRv",
46
- Destination: "rLs1MzkFWCxTbuAHgjeTZK4fcCDDnf2KRv",
47
- Issuer: "XVXdn5wEVm5g4UhEHWDPqjvdeH361P4GETfNyyXGaoqBj71",
45
+ Account: 'rLs1MzkFWCxTbuAHgjeTZK4fcCDDnf2KRv',
46
+ Destination: 'rLs1MzkFWCxTbuAHgjeTZK4fcCDDnf2KRv',
47
+ Issuer: 'XVXdn5wEVm5g4UhEHWDPqjvdeH361P4GETfNyyXGaoqBj71',
48
48
  PreviousTxnLgrSeq: 7,
49
- LedgerEntryType: "AccountRoot",
49
+ LedgerEntryType: 'AccountRoot',
50
50
  PreviousTxnID:
51
- "DF530FB14C5304852F20080B0A8EEF3A6BDD044F41F4EBBD68B8B321145FE4FF",
51
+ 'DF530FB14C5304852F20080B0A8EEF3A6BDD044F41F4EBBD68B8B321145FE4FF',
52
52
  Flags: 0,
53
53
  Sequence: 1,
54
- Balance: "10000000000",
55
- };
54
+ Balance: '10000000000',
55
+ }
56
56
 
57
57
  let json_null_r = {
58
58
  OwnerCount: 0,
59
- Account: "rLs1MzkFWCxTbuAHgjeTZK4fcCDDnf2KRv",
60
- Destination: "rLs1MzkFWCxTbuAHgjeTZK4fcCDDnf2KRv",
61
- Issuer: "rLs1MzkFWCxTbuAHgjeTZK4fcCDDnf2KRv",
59
+ Account: 'rLs1MzkFWCxTbuAHgjeTZK4fcCDDnf2KRv',
60
+ Destination: 'rLs1MzkFWCxTbuAHgjeTZK4fcCDDnf2KRv',
61
+ Issuer: 'rLs1MzkFWCxTbuAHgjeTZK4fcCDDnf2KRv',
62
62
  PreviousTxnLgrSeq: 7,
63
- LedgerEntryType: "AccountRoot",
63
+ LedgerEntryType: 'AccountRoot',
64
64
  PreviousTxnID:
65
- "DF530FB14C5304852F20080B0A8EEF3A6BDD044F41F4EBBD68B8B321145FE4FF",
65
+ 'DF530FB14C5304852F20080B0A8EEF3A6BDD044F41F4EBBD68B8B321145FE4FF',
66
66
  Flags: 0,
67
67
  Sequence: 1,
68
- Balance: "10000000000",
69
- };
68
+ Balance: '10000000000',
69
+ }
70
70
 
71
71
  let invalid_json_issuer_tagged = {
72
72
  OwnerCount: 0,
73
- Account: "rLs1MzkFWCxTbuAHgjeTZK4fcCDDnf2KRv",
74
- Destination: "rLs1MzkFWCxTbuAHgjeTZK4fcCDDnf2KRv",
75
- Issuer: "XVXdn5wEVm5G4UhEHWDPqjvdeH361P7BsapL4m2D2XnPSwT",
73
+ Account: 'rLs1MzkFWCxTbuAHgjeTZK4fcCDDnf2KRv',
74
+ Destination: 'rLs1MzkFWCxTbuAHgjeTZK4fcCDDnf2KRv',
75
+ Issuer: 'XVXdn5wEVm5G4UhEHWDPqjvdeH361P7BsapL4m2D2XnPSwT',
76
76
  PreviousTxnLgrSeq: 7,
77
- LedgerEntryType: "AccountRoot",
77
+ LedgerEntryType: 'AccountRoot',
78
78
  PreviousTxnID:
79
- "DF530FB14C5304852F20080B0A8EEF3A6BDD044F41F4EBBD68B8B321145FE4FF",
79
+ 'DF530FB14C5304852F20080B0A8EEF3A6BDD044F41F4EBBD68B8B321145FE4FF',
80
80
  Flags: 0,
81
81
  Sequence: 1,
82
- Balance: "10000000000",
83
- };
82
+ Balance: '10000000000',
83
+ }
84
84
 
85
85
  let invalid_json_x_and_tagged = {
86
86
  OwnerCount: 0,
87
- Account: "XVXdn5wEVm5G4UhEHWDPqjvdeH361P7BsapL4m2D2XnPSwT",
87
+ Account: 'XVXdn5wEVm5G4UhEHWDPqjvdeH361P7BsapL4m2D2XnPSwT',
88
88
  PreviousTxnLgrSeq: 7,
89
- LedgerEntryType: "AccountRoot",
89
+ LedgerEntryType: 'AccountRoot',
90
90
  PreviousTxnID:
91
- "DF530FB14C5304852F20080B0A8EEF3A6BDD044F41F4EBBD68B8B321145FE4FF",
91
+ 'DF530FB14C5304852F20080B0A8EEF3A6BDD044F41F4EBBD68B8B321145FE4FF',
92
92
  Flags: 0,
93
93
  Sequence: 1,
94
- Balance: "10000000000",
94
+ Balance: '10000000000',
95
95
  SourceTag: 12345,
96
- };
96
+ }
97
97
 
98
98
  let json_issued_x = {
99
99
  TakerPays: {
100
- currency: "USD",
101
- issuer: "X7WZKEeNVS2p9Tire9DtNFkzWBZbFtJHWxDjN9fCrBGqVA4",
102
- value: "7072.8",
100
+ currency: 'USD',
101
+ issuer: 'X7WZKEeNVS2p9Tire9DtNFkzWBZbFtJHWxDjN9fCrBGqVA4',
102
+ value: '7072.8',
103
103
  },
104
- };
104
+ }
105
105
 
106
106
  let json_issued_r = {
107
107
  TakerPays: {
108
- currency: "USD",
109
- issuer: "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B",
110
- value: "7072.8",
108
+ currency: 'USD',
109
+ issuer: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B',
110
+ value: '7072.8',
111
111
  },
112
- };
112
+ }
113
113
 
114
114
  let json_issued_with_tag = {
115
115
  TakerPays: {
116
- currency: "USD",
117
- issuer: "X7WZKEeNVS2p9Tire9DtNFkzWBZbFtSiS2eDBib7svZXuc2",
118
- value: "7072.8",
116
+ currency: 'USD',
117
+ issuer: 'X7WZKEeNVS2p9Tire9DtNFkzWBZbFtSiS2eDBib7svZXuc2',
118
+ value: '7072.8',
119
119
  },
120
- };
121
-
122
- describe("X-Address Account is equivalent to a classic address w/ SourceTag", () => {
123
- let encoded_x = encode(json_x1);
124
- let encoded_r = encode(json_r1);
125
- test("Can encode with x-Address", () => {
126
- expect(encoded_x).toEqual(encoded_r);
127
- });
128
-
129
- test("decoded X-address is object w/ source and tag", () => {
130
- let decoded_x = decode(encoded_x);
131
- expect(decoded_x).toEqual(json_r1);
132
- });
133
-
134
- test("Encoding issuer X-Address w/ undefined destination tag", () => {
135
- expect(encode(json_null_x)).toEqual(encode(json_null_r));
136
- });
137
-
138
- test("Throws when X-Address is invalid", () => {
139
- expect(() => encode(json_invalid_x)).toThrow("checksum_invalid");
140
- });
141
-
142
- test("Encodes issued currency w/ x-address", () => {
143
- expect(encode(json_issued_x)).toEqual(encode(json_issued_r));
144
- });
145
- });
146
-
147
- describe("Invalid X-Address behavior", () => {
148
- test("X-Address with tag throws value for invalid field", () => {
120
+ }
121
+
122
+ describe('X-Address Account is equivalent to a classic address w/ SourceTag', () => {
123
+ let encoded_x = encode(json_x1)
124
+ let encoded_r = encode(json_r1)
125
+ test('Can encode with x-Address', () => {
126
+ expect(encoded_x).toEqual(encoded_r)
127
+ })
128
+
129
+ test('decoded X-address is object w/ source and tag', () => {
130
+ let decoded_x = decode(encoded_x)
131
+ expect(decoded_x).toEqual(json_r1)
132
+ })
133
+
134
+ test('Encoding issuer X-Address w/ undefined destination tag', () => {
135
+ expect(encode(json_null_x)).toEqual(encode(json_null_r))
136
+ })
137
+
138
+ test('Throws when X-Address is invalid', () => {
139
+ expect(() => encode(json_invalid_x)).toThrow('checksum_invalid')
140
+ })
141
+
142
+ test('Encodes issued currency w/ x-address', () => {
143
+ expect(encode(json_issued_x)).toEqual(encode(json_issued_r))
144
+ })
145
+ })
146
+
147
+ describe('Invalid X-Address behavior', () => {
148
+ test('X-Address with tag throws value for invalid field', () => {
149
149
  expect(() => encode(invalid_json_issuer_tagged)).toThrow(
150
- new Error("Issuer cannot have an associated tag")
151
- );
152
- });
150
+ new Error('Issuer cannot have an associated tag'),
151
+ )
152
+ })
153
153
 
154
- test("Throws when Account has both X-Addr and Destination Tag", () => {
154
+ test('Throws when Account has both X-Addr and Destination Tag', () => {
155
155
  expect(() => encode(invalid_json_x_and_tagged)).toThrow(
156
- new Error("Cannot have Account X-Address and SourceTag")
157
- );
158
- });
156
+ new Error('Cannot have Account X-Address and SourceTag'),
157
+ )
158
+ })
159
159
 
160
- test("Throws when issued currency has tag", () => {
160
+ test('Throws when issued currency has tag', () => {
161
161
  expect(() => encode(json_issued_with_tag)).toThrow(
162
- "Only allowed to have tag on Account or Destination"
163
- );
164
- });
165
- });
162
+ 'Only allowed to have tag on Account or Destination',
163
+ )
164
+ })
165
+ })
166
166
 
167
- describe("ripple-binary-codec x-address test", function () {
167
+ describe('ripple-binary-codec x-address test', function () {
168
168
  function makeSuite(name, entries) {
169
169
  describe(name, function () {
170
170
  entries.forEach((t, testN) => {
171
171
  test(`${name}[${testN}] encodes X-address json equivalent to classic address json`, () => {
172
- expect(encode(t.rjson)).toEqual(encode(t.xjson));
173
- });
172
+ expect(encode(t.rjson)).toEqual(encode(t.xjson))
173
+ })
174
174
  test(`${name}[${testN}] decodes X-address json equivalent to classic address json`, () => {
175
- expect(decode(encode(t.xjson))).toEqual(t.rjson);
176
- });
177
- });
178
- });
175
+ expect(decode(encode(t.xjson))).toEqual(t.rjson)
176
+ })
177
+ })
178
+ })
179
179
  }
180
- makeSuite("transactions", fixtures.transactions);
181
- });
180
+ makeSuite('transactions', fixtures.transactions)
181
+ })
@@ -1,3 +0,0 @@
1
- import ShaMapInner from './ShaMapInner';
2
- export default class ShaMap extends ShaMapInner {
3
- }
@@ -1,25 +0,0 @@
1
- "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- extendStatics(d, b);
11
- function __() { this.constructor = d; }
12
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
13
- };
14
- })();
15
- Object.defineProperty(exports, "__esModule", { value: true });
16
- var ShaMapInner_1 = require("./ShaMapInner");
17
- var ShaMap = /** @class */ (function (_super) {
18
- __extends(ShaMap, _super);
19
- function ShaMap() {
20
- return _super !== null && _super.apply(this, arguments) || this;
21
- }
22
- return ShaMap;
23
- }(ShaMapInner_1.default));
24
- exports.default = ShaMap;
25
- //# sourceMappingURL=ShaMap.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ShaMap.js","sourceRoot":"","sources":["../../src/ShaMap/ShaMap.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,6CAAuC;AAEvC;IAAoC,0BAAW;IAA/C;;IAAiD,CAAC;IAAD,aAAC;AAAD,CAAC,AAAlD,CAAoC,qBAAW,GAAG"}
@@ -1,66 +0,0 @@
1
- import { Buffer } from 'buffer/';
2
- import BytesList from '../serdes/BytesList';
3
- import { Hash256 } from '../types';
4
- import ShaMapLeaf from './ShaMapLeaf';
5
- import ShaMapNode from './ShaMapNode';
6
- /**
7
- * Class defining an Inner Node of a SHAMap.
8
- */
9
- export default class ShaMapInner extends ShaMapNode {
10
- private _slotBits;
11
- private _branches;
12
- private readonly _depth;
13
- constructor(depth?: number);
14
- /**
15
- * Returns `true` because ShaMapInners are always inner nodes.
16
- *
17
- * @returns `true`.
18
- */
19
- isInner(): true;
20
- /**
21
- * Returns `false` because ShaMapInners are never leaves.
22
- *
23
- * @returns `false`.
24
- */
25
- isLeaf(): false;
26
- /**
27
- * Get the hash prefix for this node.
28
- *
29
- * @returns Hash prefix describing an inner node.
30
- */
31
- hashPrefix(): Buffer;
32
- /**
33
- * Set a branch of this node to be another node.
34
- *
35
- * @param slot - Slot to add branch to this._branches.
36
- * @param branch - Branch to add.
37
- */
38
- setBranch(slot: number, branch: ShaMapNode): void;
39
- /**
40
- * Returns `true` if node is empty.
41
- *
42
- * @returns `true` if node is empty.
43
- */
44
- empty(): boolean;
45
- /**
46
- * Compute the hash of this node.
47
- *
48
- * @returns The hash of this node.
49
- */
50
- hash(): Hash256;
51
- /**
52
- * Writes the bytes representation of this node to a BytesList.
53
- *
54
- * @param list - BytesList to write bytes to.
55
- */
56
- toBytesSink(list: BytesList): void;
57
- /**
58
- * Add item to the SHAMap.
59
- *
60
- * @param index - Hash of the index of the item being inserted.
61
- * @param item - Item to insert in the map.
62
- * @param leaf - Leaf node to insert when branch doesn't exist.
63
- * @throws Error.
64
- */
65
- addItem(index?: Hash256, item?: ShaMapNode, leaf?: ShaMapLeaf): void;
66
- }