ripple-binary-codec 2.0.0-beta.0 → 2.0.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 (247) hide show
  1. package/dist/binary.d.ts +12 -13
  2. package/dist/binary.js +6 -5
  3. package/dist/binary.js.map +1 -1
  4. package/dist/enums/bytes.d.ts +1 -2
  5. package/dist/enums/bytes.js +1 -2
  6. package/dist/enums/bytes.js.map +1 -1
  7. package/dist/enums/definitions.json +36 -11
  8. package/dist/enums/field.d.ts +1 -2
  9. package/dist/enums/field.js +1 -2
  10. package/dist/enums/field.js.map +1 -1
  11. package/dist/enums/index.js +4 -24
  12. package/dist/enums/index.js.map +1 -1
  13. package/dist/enums/src/enums/definitions.json +36 -11
  14. package/dist/hash-prefixes.d.ts +1 -2
  15. package/dist/hash-prefixes.js +6 -6
  16. package/dist/hash-prefixes.js.map +1 -1
  17. package/dist/hashes.d.ts +5 -6
  18. package/dist/hashes.js +1 -2
  19. package/dist/hashes.js.map +1 -1
  20. package/dist/index.js +7 -14
  21. package/dist/index.js.map +1 -1
  22. package/dist/quality.d.ts +1 -2
  23. package/dist/quality.js +3 -3
  24. package/dist/quality.js.map +1 -1
  25. package/dist/serdes/binary-parser.d.ts +2 -3
  26. package/dist/serdes/binary-parser.js +2 -2
  27. package/dist/serdes/binary-parser.js.map +1 -1
  28. package/dist/serdes/binary-serializer.d.ts +6 -7
  29. package/dist/serdes/binary-serializer.js +9 -9
  30. package/dist/serdes/binary-serializer.js.map +1 -1
  31. package/dist/shamap.d.ts +4 -5
  32. package/dist/shamap.js +2 -3
  33. package/dist/shamap.js.map +1 -1
  34. package/dist/src/binary.d.ts +90 -0
  35. package/dist/src/binary.js +128 -0
  36. package/dist/src/binary.js.map +1 -0
  37. package/dist/src/coretypes.d.ts +9 -0
  38. package/dist/src/coretypes.js +48 -0
  39. package/dist/src/coretypes.js.map +1 -0
  40. package/dist/src/enums/bytes.d.ts +25 -0
  41. package/dist/src/enums/bytes.js +63 -0
  42. package/dist/src/enums/bytes.js.map +1 -0
  43. package/dist/src/enums/constants.d.ts +4 -0
  44. package/dist/src/enums/constants.js +8 -0
  45. package/dist/src/enums/constants.js.map +1 -0
  46. package/dist/src/enums/definitions.json +2866 -0
  47. package/dist/src/enums/field.d.ts +28 -0
  48. package/dist/src/enums/field.js +58 -0
  49. package/dist/src/enums/field.js.map +1 -0
  50. package/dist/src/enums/index.d.ts +12 -0
  51. package/dist/src/enums/index.js +31 -0
  52. package/dist/src/enums/index.js.map +1 -0
  53. package/dist/src/enums/utils-renumber.d.ts +101 -0
  54. package/dist/src/enums/utils-renumber.js +127 -0
  55. package/dist/src/enums/utils-renumber.js.map +1 -0
  56. package/dist/src/enums/xrpl-definitions-base.d.ts +44 -0
  57. package/dist/src/enums/xrpl-definitions-base.js +59 -0
  58. package/dist/src/enums/xrpl-definitions-base.js.map +1 -0
  59. package/dist/src/enums/xrpl-definitions.d.ts +21 -0
  60. package/dist/src/enums/xrpl-definitions.js +29 -0
  61. package/dist/src/enums/xrpl-definitions.js.map +1 -0
  62. package/dist/src/hash-prefixes.d.ts +5 -0
  63. package/dist/src/hash-prefixes.js +41 -0
  64. package/dist/src/hash-prefixes.js.map +1 -0
  65. package/dist/src/hashes.d.ts +50 -0
  66. package/dist/src/hashes.js +76 -0
  67. package/dist/src/hashes.js.map +1 -0
  68. package/dist/src/index.d.ts +64 -0
  69. package/dist/src/index.js +123 -0
  70. package/dist/src/index.js.map +1 -0
  71. package/dist/src/ledger-hashes.d.ts +48 -0
  72. package/dist/src/ledger-hashes.js +141 -0
  73. package/dist/src/ledger-hashes.js.map +1 -0
  74. package/dist/src/quality.d.ts +21 -0
  75. package/dist/src/quality.js +42 -0
  76. package/dist/src/quality.js.map +1 -0
  77. package/dist/src/serdes/binary-parser.d.ts +100 -0
  78. package/dist/src/serdes/binary-parser.js +194 -0
  79. package/dist/src/serdes/binary-parser.js.map +1 -0
  80. package/dist/src/serdes/binary-serializer.d.ts +81 -0
  81. package/dist/src/serdes/binary-serializer.js +149 -0
  82. package/dist/src/serdes/binary-serializer.js.map +1 -0
  83. package/dist/src/shamap.d.ts +102 -0
  84. package/dist/src/shamap.js +172 -0
  85. package/dist/src/shamap.js.map +1 -0
  86. package/dist/src/types/account-id.d.ts +35 -0
  87. package/dist/src/types/account-id.js +69 -0
  88. package/dist/src/types/account-id.js.map +1 -0
  89. package/dist/src/types/amount.d.ts +67 -0
  90. package/dist/src/types/amount.js +212 -0
  91. package/dist/src/types/amount.js.map +1 -0
  92. package/dist/src/types/blob.d.ts +24 -0
  93. package/dist/src/types/blob.js +40 -0
  94. package/dist/src/types/blob.js.map +1 -0
  95. package/dist/src/types/currency.d.ts +28 -0
  96. package/dist/src/types/currency.js +127 -0
  97. package/dist/src/types/currency.js.map +1 -0
  98. package/dist/src/types/hash-128.d.ts +16 -0
  99. package/dist/src/types/hash-128.js +32 -0
  100. package/dist/src/types/hash-128.js.map +1 -0
  101. package/dist/src/types/hash-160.d.ts +10 -0
  102. package/dist/src/types/hash-160.js +19 -0
  103. package/dist/src/types/hash-160.js.map +1 -0
  104. package/dist/src/types/hash-256.d.ts +10 -0
  105. package/dist/src/types/hash-256.js +16 -0
  106. package/dist/src/types/hash-256.js.map +1 -0
  107. package/dist/src/types/hash.d.ts +40 -0
  108. package/dist/src/types/hash.js +73 -0
  109. package/dist/src/types/hash.js.map +1 -0
  110. package/dist/src/types/index.d.ts +18 -0
  111. package/dist/src/types/index.js +61 -0
  112. package/dist/src/types/index.js.map +1 -0
  113. package/dist/src/types/issue.d.ts +38 -0
  114. package/dist/src/types/issue.js +81 -0
  115. package/dist/src/types/issue.js.map +1 -0
  116. package/dist/src/types/path-set.d.ts +36 -0
  117. package/dist/src/types/path-set.js +233 -0
  118. package/dist/src/types/path-set.js.map +1 -0
  119. package/dist/src/types/serialized-type.d.ts +70 -0
  120. package/dist/src/types/serialized-type.js +105 -0
  121. package/dist/src/types/serialized-type.js.map +1 -0
  122. package/dist/src/types/st-array.d.ts +31 -0
  123. package/dist/src/types/st-array.js +83 -0
  124. package/dist/src/types/st-array.js.map +1 -0
  125. package/dist/src/types/st-object.d.ts +32 -0
  126. package/dist/src/types/st-object.js +155 -0
  127. package/dist/src/types/st-object.js.map +1 -0
  128. package/dist/src/types/uint-16.d.ts +24 -0
  129. package/dist/src/types/uint-16.js +45 -0
  130. package/dist/src/types/uint-16.js.map +1 -0
  131. package/dist/src/types/uint-32.d.ts +24 -0
  132. package/dist/src/types/uint-32.js +50 -0
  133. package/dist/src/types/uint-32.js.map +1 -0
  134. package/dist/src/types/uint-64.d.ts +37 -0
  135. package/dist/src/types/uint-64.js +86 -0
  136. package/dist/src/types/uint-64.js.map +1 -0
  137. package/dist/src/types/uint-8.d.ts +24 -0
  138. package/dist/src/types/uint-8.js +46 -0
  139. package/dist/src/types/uint-8.js.map +1 -0
  140. package/dist/src/types/uint.d.ts +29 -0
  141. package/dist/src/types/uint.js +47 -0
  142. package/dist/src/types/uint.js.map +1 -0
  143. package/dist/src/types/vector-256.d.ts +30 -0
  144. package/dist/src/types/vector-256.js +73 -0
  145. package/dist/src/types/vector-256.js.map +1 -0
  146. package/dist/src/types/xchain-bridge.d.ts +44 -0
  147. package/dist/src/types/xchain-bridge.js +102 -0
  148. package/dist/src/types/xchain-bridge.js.map +1 -0
  149. package/dist/src/utils.d.ts +47 -0
  150. package/dist/src/utils.js +137 -0
  151. package/dist/src/utils.js.map +1 -0
  152. package/dist/tsconfig.tsbuildinfo +1 -0
  153. package/dist/types/account-id.d.ts +1 -2
  154. package/dist/types/account-id.js +4 -6
  155. package/dist/types/account-id.js.map +1 -1
  156. package/dist/types/amount.d.ts +1 -2
  157. package/dist/types/amount.js +16 -15
  158. package/dist/types/amount.js.map +1 -1
  159. package/dist/types/blob.d.ts +1 -2
  160. package/dist/types/blob.js +2 -2
  161. package/dist/types/blob.js.map +1 -1
  162. package/dist/types/currency.d.ts +1 -2
  163. package/dist/types/currency.js +10 -10
  164. package/dist/types/currency.js.map +1 -1
  165. package/dist/types/hash-128.d.ts +1 -2
  166. package/dist/types/hash-128.js +3 -3
  167. package/dist/types/hash-128.js.map +1 -1
  168. package/dist/types/hash-160.d.ts +1 -2
  169. package/dist/types/hash-160.js +1 -2
  170. package/dist/types/hash-160.js.map +1 -1
  171. package/dist/types/hash-256.d.ts +1 -2
  172. package/dist/types/hash-256.js +1 -2
  173. package/dist/types/hash-256.js.map +1 -1
  174. package/dist/types/hash.d.ts +2 -3
  175. package/dist/types/hash.js +5 -4
  176. package/dist/types/hash.js.map +1 -1
  177. package/dist/types/issue.d.ts +1 -2
  178. package/dist/types/issue.js +4 -4
  179. package/dist/types/issue.js.map +1 -1
  180. package/dist/types/path-set.js +12 -12
  181. package/dist/types/path-set.js.map +1 -1
  182. package/dist/types/serialized-type.d.ts +17 -13
  183. package/dist/types/serialized-type.js +11 -6
  184. package/dist/types/serialized-type.js.map +1 -1
  185. package/dist/types/st-array.js +5 -5
  186. package/dist/types/st-array.js.map +1 -1
  187. package/dist/types/st-object.js +1 -2
  188. package/dist/types/st-object.js.map +1 -1
  189. package/dist/types/uint-16.d.ts +1 -2
  190. package/dist/types/uint-16.js +6 -5
  191. package/dist/types/uint-16.js.map +1 -1
  192. package/dist/types/uint-32.d.ts +1 -2
  193. package/dist/types/uint-32.js +7 -6
  194. package/dist/types/uint-32.js.map +1 -1
  195. package/dist/types/uint-64.d.ts +2 -3
  196. package/dist/types/uint-64.js +16 -15
  197. package/dist/types/uint-64.js.map +1 -1
  198. package/dist/types/uint-8.d.ts +1 -2
  199. package/dist/types/uint-8.js +7 -5
  200. package/dist/types/uint-8.js.map +1 -1
  201. package/dist/types/uint.d.ts +4 -4
  202. package/dist/types/uint.js +5 -0
  203. package/dist/types/uint.js.map +1 -1
  204. package/dist/types/vector-256.d.ts +1 -2
  205. package/dist/types/vector-256.js +2 -4
  206. package/dist/types/vector-256.js.map +1 -1
  207. package/dist/types/xchain-bridge.d.ts +1 -2
  208. package/dist/types/xchain-bridge.js +20 -20
  209. package/dist/types/xchain-bridge.js.map +1 -1
  210. package/dist/utils.d.ts +47 -0
  211. package/dist/utils.js +137 -0
  212. package/dist/utils.js.map +1 -0
  213. package/package.json +8 -11
  214. package/src/README.md +3 -1
  215. package/src/binary.ts +21 -14
  216. package/src/enums/bytes.ts +2 -3
  217. package/src/enums/definitions.json +36 -11
  218. package/src/enums/field.ts +3 -4
  219. package/src/enums/index.ts +1 -1
  220. package/src/hash-prefixes.ts +8 -8
  221. package/src/hashes.ts +6 -7
  222. package/src/index.ts +12 -15
  223. package/src/quality.ts +4 -4
  224. package/src/serdes/binary-parser.ts +5 -5
  225. package/src/serdes/binary-serializer.ts +14 -14
  226. package/src/shamap.ts +5 -6
  227. package/src/types/account-id.ts +8 -8
  228. package/src/types/amount.ts +17 -18
  229. package/src/types/blob.ts +3 -3
  230. package/src/types/currency.ts +16 -16
  231. package/src/types/hash-128.ts +4 -4
  232. package/src/types/hash-160.ts +2 -3
  233. package/src/types/hash-256.ts +2 -3
  234. package/src/types/hash.ts +8 -6
  235. package/src/types/issue.ts +5 -5
  236. package/src/types/path-set.ts +16 -16
  237. package/src/types/serialized-type.ts +20 -15
  238. package/src/types/st-array.ts +7 -7
  239. package/src/types/st-object.ts +2 -2
  240. package/src/types/uint-16.ts +10 -6
  241. package/src/types/uint-32.ts +10 -7
  242. package/src/types/uint-64.ts +20 -17
  243. package/src/types/uint-8.ts +9 -6
  244. package/src/types/uint.ts +11 -4
  245. package/src/types/vector-256.ts +3 -8
  246. package/src/types/xchain-bridge.ts +22 -22
  247. package/src/utils.ts +152 -0
@@ -0,0 +1,127 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Currency = void 0;
4
+ const hash_160_1 = require("./hash-160");
5
+ const utils_1 = require("@xrplf/isomorphic/utils");
6
+ const XRP_HEX_REGEX = /^0{40}$/;
7
+ const ISO_REGEX = /^[A-Z0-9a-z?!@#$%^&*(){}[\]|]{3}$/;
8
+ const HEX_REGEX = /^[A-F0-9]{40}$/;
9
+ // eslint-disable-next-line no-control-regex
10
+ const STANDARD_FORMAT_HEX_REGEX = /^0{24}[\x00-\x7F]{6}0{10}$/;
11
+ /**
12
+ * Convert an ISO code to a currency bytes representation
13
+ */
14
+ function isoToBytes(iso) {
15
+ const bytes = new Uint8Array(20);
16
+ if (iso !== 'XRP') {
17
+ const isoBytes = iso.split('').map((c) => c.charCodeAt(0));
18
+ bytes.set(isoBytes, 12);
19
+ }
20
+ return bytes;
21
+ }
22
+ /**
23
+ * Tests if ISO is a valid iso code
24
+ */
25
+ function isIsoCode(iso) {
26
+ return ISO_REGEX.test(iso);
27
+ }
28
+ function isoCodeFromHex(code) {
29
+ const iso = (0, utils_1.hexToString)((0, utils_1.bytesToHex)(code));
30
+ if (iso === 'XRP') {
31
+ return null;
32
+ }
33
+ if (isIsoCode(iso)) {
34
+ return iso;
35
+ }
36
+ return null;
37
+ }
38
+ /**
39
+ * Tests if hex is a valid hex-string
40
+ */
41
+ function isHex(hex) {
42
+ return HEX_REGEX.test(hex);
43
+ }
44
+ /**
45
+ * Tests if a string is a valid representation of a currency
46
+ */
47
+ function isStringRepresentation(input) {
48
+ return input.length === 3 || isHex(input);
49
+ }
50
+ /**
51
+ * Tests if a Uint8Array is a valid representation of a currency
52
+ */
53
+ function isBytesArray(bytes) {
54
+ return bytes.byteLength === 20;
55
+ }
56
+ /**
57
+ * Ensures that a value is a valid representation of a currency
58
+ */
59
+ function isValidRepresentation(input) {
60
+ return input instanceof Uint8Array
61
+ ? isBytesArray(input)
62
+ : isStringRepresentation(input);
63
+ }
64
+ /**
65
+ * Generate bytes from a string or UInt8Array representation of a currency
66
+ */
67
+ function bytesFromRepresentation(input) {
68
+ if (!isValidRepresentation(input)) {
69
+ throw new Error(`Unsupported Currency representation: ${input}`);
70
+ }
71
+ return input.length === 3 ? isoToBytes(input) : (0, utils_1.hexToBytes)(input);
72
+ }
73
+ /**
74
+ * Class defining how to encode and decode Currencies
75
+ */
76
+ class Currency extends hash_160_1.Hash160 {
77
+ constructor(byteBuf) {
78
+ super(byteBuf !== null && byteBuf !== void 0 ? byteBuf : Currency.XRP.bytes);
79
+ const hex = (0, utils_1.bytesToHex)(this.bytes);
80
+ if (XRP_HEX_REGEX.test(hex)) {
81
+ this._iso = 'XRP';
82
+ }
83
+ else if (STANDARD_FORMAT_HEX_REGEX.test(hex)) {
84
+ this._iso = isoCodeFromHex(this.bytes.slice(12, 15));
85
+ }
86
+ else {
87
+ this._iso = null;
88
+ }
89
+ }
90
+ /**
91
+ * Return the ISO code of this currency
92
+ *
93
+ * @returns ISO code if it exists, else null
94
+ */
95
+ iso() {
96
+ return this._iso;
97
+ }
98
+ /**
99
+ * Constructs a Currency object
100
+ *
101
+ * @param val Currency object or a string representation of a currency
102
+ */
103
+ static from(value) {
104
+ if (value instanceof Currency) {
105
+ return value;
106
+ }
107
+ if (typeof value === 'string') {
108
+ return new Currency(bytesFromRepresentation(value));
109
+ }
110
+ throw new Error('Cannot construct Currency from value given');
111
+ }
112
+ /**
113
+ * Gets the JSON representation of a currency
114
+ *
115
+ * @returns JSON representation
116
+ */
117
+ toJSON() {
118
+ const iso = this.iso();
119
+ if (iso !== null) {
120
+ return iso;
121
+ }
122
+ return (0, utils_1.bytesToHex)(this.bytes);
123
+ }
124
+ }
125
+ exports.Currency = Currency;
126
+ Currency.XRP = new Currency(new Uint8Array(20));
127
+ //# sourceMappingURL=currency.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"currency.js","sourceRoot":"","sources":["../../../src/types/currency.ts"],"names":[],"mappings":";;;AAAA,yCAAoC;AACpC,mDAA6E;AAE7E,MAAM,aAAa,GAAG,SAAS,CAAA;AAC/B,MAAM,SAAS,GAAG,mCAAmC,CAAA;AACrD,MAAM,SAAS,GAAG,gBAAgB,CAAA;AAClC,4CAA4C;AAC5C,MAAM,yBAAyB,GAAG,4BAA4B,CAAA;AAE9D;;GAEG;AACH,SAAS,UAAU,CAAC,GAAW;IAC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CAAC,CAAA;SACpD;QAED,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAA;IAC/D,CAAC;IAED;;;;OAIG;IACH,MAAM;QACJ,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;QACtB,IAAI,GAAG,KAAK,IAAI,EAAE;YAChB,OAAO,GAAG,CAAA;SACX;QACD,OAAO,IAAA,kBAAU,EAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IAC/B,CAAC;;AAGM,4BAAQ;AAxDC,YAAG,GAAG,IAAI,QAAQ,CAAC,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC,CAAA"}
@@ -0,0 +1,16 @@
1
+ import { Hash } from './hash';
2
+ /**
3
+ * Hash with a width of 128 bits
4
+ */
5
+ declare class Hash128 extends Hash {
6
+ static readonly width = 16;
7
+ static readonly ZERO_128: Hash128;
8
+ constructor(bytes: Uint8Array);
9
+ /**
10
+ * Get the hex representation of a hash-128 bytes, allowing unset
11
+ *
12
+ * @returns hex String of this.bytes
13
+ */
14
+ toHex(): string;
15
+ }
16
+ export { Hash128 };
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Hash128 = void 0;
4
+ const hash_1 = require("./hash");
5
+ const utils_1 = require("@xrplf/isomorphic/utils");
6
+ /**
7
+ * Hash with a width of 128 bits
8
+ */
9
+ class Hash128 extends hash_1.Hash {
10
+ constructor(bytes) {
11
+ if (bytes && bytes.byteLength === 0) {
12
+ bytes = Hash128.ZERO_128.bytes;
13
+ }
14
+ super(bytes !== null && bytes !== void 0 ? bytes : Hash128.ZERO_128.bytes);
15
+ }
16
+ /**
17
+ * Get the hex representation of a hash-128 bytes, allowing unset
18
+ *
19
+ * @returns hex String of this.bytes
20
+ */
21
+ toHex() {
22
+ const hex = (0, utils_1.bytesToHex)(this.toBytes());
23
+ if (/^0+$/.exec(hex)) {
24
+ return '';
25
+ }
26
+ return hex;
27
+ }
28
+ }
29
+ exports.Hash128 = Hash128;
30
+ Hash128.width = 16;
31
+ Hash128.ZERO_128 = new Hash128(new Uint8Array(Hash128.width));
32
+ //# sourceMappingURL=hash-128.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hash-128.js","sourceRoot":"","sources":["../../../src/types/hash-128.ts"],"names":[],"mappings":";;;AAAA,iCAA6B;AAC7B,mDAAoD;AAEpD;;GAEG;AACH,MAAM,OAAQ,SAAQ,WAAI;IAIxB,YAAY,KAAiB;QAC3B,IAAI,KAAK,IAAI,KAAK,CAAC,UAAU,KAAK,CAAC,EAAE;YACnC,KAAK,GAAG,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAA;SAC/B;QAED,KAAK,CAAC,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;IACxC,CAAC;IAED;;;;OAIG;IACH,KAAK;QACH,MAAM,GAAG,GAAG,IAAA,kBAAU,EAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAA;QACtC,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE;YACpB,OAAO,EAAE,CAAA;SACV;QACD,OAAO,GAAG,CAAA;IACZ,CAAC;;AAGM,0BAAO;AAzBE,aAAK,GAAG,EAAE,CAAA;AACV,gBAAQ,GAAY,IAAI,OAAO,CAAC,IAAI,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAA"}
@@ -0,0 +1,10 @@
1
+ import { Hash } from './hash';
2
+ /**
3
+ * Hash with a width of 160 bits
4
+ */
5
+ declare class Hash160 extends Hash {
6
+ static readonly width = 20;
7
+ static readonly ZERO_160: Hash160;
8
+ constructor(bytes?: Uint8Array);
9
+ }
10
+ export { Hash160 };
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Hash160 = void 0;
4
+ const hash_1 = require("./hash");
5
+ /**
6
+ * Hash with a width of 160 bits
7
+ */
8
+ class Hash160 extends hash_1.Hash {
9
+ constructor(bytes) {
10
+ if (bytes && bytes.byteLength === 0) {
11
+ bytes = Hash160.ZERO_160.bytes;
12
+ }
13
+ super(bytes !== null && bytes !== void 0 ? bytes : Hash160.ZERO_160.bytes);
14
+ }
15
+ }
16
+ exports.Hash160 = Hash160;
17
+ Hash160.width = 20;
18
+ Hash160.ZERO_160 = new Hash160(new Uint8Array(Hash160.width));
19
+ //# sourceMappingURL=hash-160.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hash-160.js","sourceRoot":"","sources":["../../../src/types/hash-160.ts"],"names":[],"mappings":";;;AAAA,iCAA6B;AAE7B;;GAEG;AACH,MAAM,OAAQ,SAAQ,WAAI;IAIxB,YAAY,KAAkB;QAC5B,IAAI,KAAK,IAAI,KAAK,CAAC,UAAU,KAAK,CAAC,EAAE;YACnC,KAAK,GAAG,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAA;SAC/B;QAED,KAAK,CAAC,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;IACxC,CAAC;;AAGM,0BAAO;AAZE,aAAK,GAAG,EAAE,CAAA;AACV,gBAAQ,GAAY,IAAI,OAAO,CAAC,IAAI,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAA"}
@@ -0,0 +1,10 @@
1
+ import { Hash } from './hash';
2
+ /**
3
+ * Hash with a width of 256 bits
4
+ */
5
+ declare class Hash256 extends Hash {
6
+ static readonly width = 32;
7
+ static readonly ZERO_256: Hash256;
8
+ constructor(bytes: Uint8Array);
9
+ }
10
+ export { Hash256 };
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Hash256 = void 0;
4
+ const hash_1 = require("./hash");
5
+ /**
6
+ * Hash with a width of 256 bits
7
+ */
8
+ class Hash256 extends hash_1.Hash {
9
+ constructor(bytes) {
10
+ super(bytes !== null && bytes !== void 0 ? bytes : Hash256.ZERO_256.bytes);
11
+ }
12
+ }
13
+ exports.Hash256 = Hash256;
14
+ Hash256.width = 32;
15
+ Hash256.ZERO_256 = new Hash256(new Uint8Array(Hash256.width));
16
+ //# sourceMappingURL=hash-256.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hash-256.js","sourceRoot":"","sources":["../../../src/types/hash-256.ts"],"names":[],"mappings":";;;AAAA,iCAA6B;AAE7B;;GAEG;AACH,MAAM,OAAQ,SAAQ,WAAI;IAIxB,YAAY,KAAiB;QAC3B,KAAK,CAAC,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;IACxC,CAAC;;AAGM,0BAAO;AARE,aAAK,GAAG,EAAE,CAAA;AACV,gBAAQ,GAAG,IAAI,OAAO,CAAC,IAAI,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAA"}
@@ -0,0 +1,40 @@
1
+ import { Comparable } from './serialized-type';
2
+ import { BinaryParser } from '../serdes/binary-parser';
3
+ /**
4
+ * Base class defining how to encode and decode hashes
5
+ */
6
+ declare class Hash extends Comparable<Hash | string> {
7
+ static readonly width: number;
8
+ constructor(bytes: Uint8Array);
9
+ /**
10
+ * Construct a Hash object from an existing Hash object or a hex-string
11
+ *
12
+ * @param value A hash object or hex-string of a hash
13
+ */
14
+ static from<T extends Hash | string>(value: T): Hash;
15
+ /**
16
+ * Read a Hash object from a BinaryParser
17
+ *
18
+ * @param parser BinaryParser to read the hash from
19
+ * @param hint length of the bytes to read, optional
20
+ */
21
+ static fromParser(parser: BinaryParser, hint?: number): Hash;
22
+ /**
23
+ * Overloaded operator for comparing two hash objects
24
+ *
25
+ * @param other The Hash to compare this to
26
+ */
27
+ compareTo(other: Hash): number;
28
+ /**
29
+ * @returns the hex-string representation of this Hash
30
+ */
31
+ toString(): string;
32
+ /**
33
+ * Returns four bits at the specified depth within a hash
34
+ *
35
+ * @param depth The depth of the four bits
36
+ * @returns The number represented by the four bits
37
+ */
38
+ nibblet(depth: number): number;
39
+ }
40
+ export { Hash };
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Hash = void 0;
4
+ const serialized_type_1 = require("./serialized-type");
5
+ const utils_1 = require("@xrplf/isomorphic/utils");
6
+ const utils_2 = require("../utils");
7
+ /**
8
+ * Base class defining how to encode and decode hashes
9
+ */
10
+ class Hash extends serialized_type_1.Comparable {
11
+ constructor(bytes) {
12
+ super(bytes);
13
+ if (this.bytes.length !== this.constructor.width) {
14
+ throw new Error(`Invalid Hash length ${this.bytes.byteLength}`);
15
+ }
16
+ }
17
+ /**
18
+ * Construct a Hash object from an existing Hash object or a hex-string
19
+ *
20
+ * @param value A hash object or hex-string of a hash
21
+ */
22
+ static from(value) {
23
+ if (value instanceof this) {
24
+ return value;
25
+ }
26
+ if (typeof value === 'string') {
27
+ return new this((0, utils_1.hexToBytes)(value));
28
+ }
29
+ throw new Error('Cannot construct Hash from given value');
30
+ }
31
+ /**
32
+ * Read a Hash object from a BinaryParser
33
+ *
34
+ * @param parser BinaryParser to read the hash from
35
+ * @param hint length of the bytes to read, optional
36
+ */
37
+ static fromParser(parser, hint) {
38
+ return new this(parser.read(hint !== null && hint !== void 0 ? hint : this.width));
39
+ }
40
+ /**
41
+ * Overloaded operator for comparing two hash objects
42
+ *
43
+ * @param other The Hash to compare this to
44
+ */
45
+ compareTo(other) {
46
+ return (0, utils_2.compare)(this.bytes, this.constructor.from(other).bytes);
47
+ }
48
+ /**
49
+ * @returns the hex-string representation of this Hash
50
+ */
51
+ toString() {
52
+ return this.toHex();
53
+ }
54
+ /**
55
+ * Returns four bits at the specified depth within a hash
56
+ *
57
+ * @param depth The depth of the four bits
58
+ * @returns The number represented by the four bits
59
+ */
60
+ nibblet(depth) {
61
+ const byteIx = depth > 0 ? (depth / 2) | 0 : 0;
62
+ let b = this.bytes[byteIx];
63
+ if (depth % 2 === 0) {
64
+ b = (b & 0xf0) >>> 4;
65
+ }
66
+ else {
67
+ b = b & 0x0f;
68
+ }
69
+ return b;
70
+ }
71
+ }
72
+ exports.Hash = Hash;
73
+ //# sourceMappingURL=hash.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hash.js","sourceRoot":"","sources":["../../../src/types/hash.ts"],"names":[],"mappings":";;;AAAA,uDAA8C;AAE9C,mDAAoD;AACpD,oCAAkC;AAElC;;GAEG;AACH,MAAM,IAAK,SAAQ,4BAAyB;IAG1C,YAAY,KAAiB;QAC3B,KAAK,CAAC,KAAK,CAAC,CAAA;QACZ,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,KAAM,IAAI,CAAC,WAA2B,CAAC,KAAK,EAAE;YACjE,MAAM,IAAI,KAAK,CAAC,uBAAuB,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,CAAC,CAAA;SAChE;IACH,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,IAAI,CAA0B,KAAQ;QAC3C,IAAI,KAAK,YAAY,IAAI,EAAE;YACzB,OAAO,KAAK,CAAA;SACb;QAED,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;YAC7B,OAAO,IAAI,IAAI,CAAC,IAAA,kBAAU,EAAC,KAAK,CAAC,CAAC,CAAA;SACnC;QAED,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAA;IAC3D,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,UAAU,CAAC,MAAoB,EAAE,IAAa;QACnD,OAAO,IAAI,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,aAAJ,IAAI,cAAJ,IAAI,GAAI,IAAI,CAAC,KAAK,CAAC,CAAC,CAAA;IAClD,CAAC;IAED;;;;OAIG;IACH,SAAS,CAAC,KAAW;QACnB,OAAO,IAAA,eAAO,EACZ,IAAI,CAAC,KAAK,EACT,IAAI,CAAC,WAA2B,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,KAAK,CACpD,CAAA;IACH,CAAC;IAED;;OAEG;IACH,QAAQ;QACN,OAAO,IAAI,CAAC,KAAK,EAAE,CAAA;IACrB,CAAC;IAED;;;;;OAKG;IACH,OAAO,CAAC,KAAa;QACnB,MAAM,MAAM,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;QAC9C,IAAI,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;QAC1B,IAAI,KAAK,GAAG,CAAC,KAAK,CAAC,EAAE;YACnB,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAA;SACrB;aAAM;YACL,CAAC,GAAG,CAAC,GAAG,IAAI,CAAA;SACb;QACD,OAAO,CAAC,CAAA;IACV,CAAC;CACF;AAEQ,oBAAI"}
@@ -0,0 +1,18 @@
1
+ import { AccountID } from './account-id';
2
+ import { Amount } from './amount';
3
+ import { Blob } from './blob';
4
+ import { Currency } from './currency';
5
+ import { Hash128 } from './hash-128';
6
+ import { Hash160 } from './hash-160';
7
+ import { Hash256 } from './hash-256';
8
+ import { PathSet } from './path-set';
9
+ import { STArray } from './st-array';
10
+ import { STObject } from './st-object';
11
+ import { UInt16 } from './uint-16';
12
+ import { UInt32 } from './uint-32';
13
+ import { UInt64 } from './uint-64';
14
+ import { UInt8 } from './uint-8';
15
+ import { Vector256 } from './vector-256';
16
+ import { type SerializedType } from './serialized-type';
17
+ declare const coreTypes: Record<string, typeof SerializedType>;
18
+ export { coreTypes, AccountID, Amount, Blob, Currency, Hash128, Hash160, Hash256, PathSet, STArray, STObject, UInt8, UInt16, UInt32, UInt64, Vector256, };
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Vector256 = exports.UInt64 = exports.UInt32 = exports.UInt16 = exports.UInt8 = exports.STObject = exports.STArray = exports.PathSet = exports.Hash256 = exports.Hash160 = exports.Hash128 = exports.Currency = exports.Blob = exports.Amount = exports.AccountID = exports.coreTypes = void 0;
4
+ const account_id_1 = require("./account-id");
5
+ Object.defineProperty(exports, "AccountID", { enumerable: true, get: function () { return account_id_1.AccountID; } });
6
+ const amount_1 = require("./amount");
7
+ Object.defineProperty(exports, "Amount", { enumerable: true, get: function () { return amount_1.Amount; } });
8
+ const blob_1 = require("./blob");
9
+ Object.defineProperty(exports, "Blob", { enumerable: true, get: function () { return blob_1.Blob; } });
10
+ const currency_1 = require("./currency");
11
+ Object.defineProperty(exports, "Currency", { enumerable: true, get: function () { return currency_1.Currency; } });
12
+ const hash_128_1 = require("./hash-128");
13
+ Object.defineProperty(exports, "Hash128", { enumerable: true, get: function () { return hash_128_1.Hash128; } });
14
+ const hash_160_1 = require("./hash-160");
15
+ Object.defineProperty(exports, "Hash160", { enumerable: true, get: function () { return hash_160_1.Hash160; } });
16
+ const hash_256_1 = require("./hash-256");
17
+ Object.defineProperty(exports, "Hash256", { enumerable: true, get: function () { return hash_256_1.Hash256; } });
18
+ const issue_1 = require("./issue");
19
+ const path_set_1 = require("./path-set");
20
+ Object.defineProperty(exports, "PathSet", { enumerable: true, get: function () { return path_set_1.PathSet; } });
21
+ const st_array_1 = require("./st-array");
22
+ Object.defineProperty(exports, "STArray", { enumerable: true, get: function () { return st_array_1.STArray; } });
23
+ const st_object_1 = require("./st-object");
24
+ Object.defineProperty(exports, "STObject", { enumerable: true, get: function () { return st_object_1.STObject; } });
25
+ const uint_16_1 = require("./uint-16");
26
+ Object.defineProperty(exports, "UInt16", { enumerable: true, get: function () { return uint_16_1.UInt16; } });
27
+ const uint_32_1 = require("./uint-32");
28
+ Object.defineProperty(exports, "UInt32", { enumerable: true, get: function () { return uint_32_1.UInt32; } });
29
+ const uint_64_1 = require("./uint-64");
30
+ Object.defineProperty(exports, "UInt64", { enumerable: true, get: function () { return uint_64_1.UInt64; } });
31
+ const uint_8_1 = require("./uint-8");
32
+ Object.defineProperty(exports, "UInt8", { enumerable: true, get: function () { return uint_8_1.UInt8; } });
33
+ const vector_256_1 = require("./vector-256");
34
+ Object.defineProperty(exports, "Vector256", { enumerable: true, get: function () { return vector_256_1.Vector256; } });
35
+ const xchain_bridge_1 = require("./xchain-bridge");
36
+ const enums_1 = require("../enums");
37
+ const coreTypes = {
38
+ AccountID: account_id_1.AccountID,
39
+ Amount: amount_1.Amount,
40
+ Blob: blob_1.Blob,
41
+ Currency: currency_1.Currency,
42
+ Hash128: hash_128_1.Hash128,
43
+ Hash160: hash_160_1.Hash160,
44
+ Hash256: hash_256_1.Hash256,
45
+ Issue: issue_1.Issue,
46
+ PathSet: path_set_1.PathSet,
47
+ STArray: st_array_1.STArray,
48
+ STObject: st_object_1.STObject,
49
+ UInt8: uint_8_1.UInt8,
50
+ UInt16: uint_16_1.UInt16,
51
+ UInt32: uint_32_1.UInt32,
52
+ UInt64: uint_64_1.UInt64,
53
+ Vector256: vector_256_1.Vector256,
54
+ XChainBridge: xchain_bridge_1.XChainBridge,
55
+ };
56
+ exports.coreTypes = coreTypes;
57
+ // Ensures that the DEFAULT_DEFINITIONS object connects these types to fields for serializing/deserializing
58
+ // This is done here instead of in enums/index.ts to avoid a circular dependency
59
+ // because some of the above types depend on BinarySerializer which depends on enums/index.ts.
60
+ enums_1.DEFAULT_DEFINITIONS.associateTypes(coreTypes);
61
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":";;;AAAA,6CAAwC;AA+CtC,0FA/CO,sBAAS,OA+CP;AA9CX,qCAAiC;AA+C/B,uFA/CO,eAAM,OA+CP;AA9CR,iCAA6B;AA+C3B,qFA/CO,WAAI,OA+CP;AA9CN,yCAAqC;AA+CnC,yFA/CO,mBAAQ,OA+CP;AA9CV,yCAAoC;AA+ClC,wFA/CO,kBAAO,OA+CP;AA9CT,yCAAoC;AA+ClC,wFA/CO,kBAAO,OA+CP;AA9CT,yCAAoC;AA+ClC,wFA/CO,kBAAO,OA+CP;AA9CT,mCAA+B;AAC/B,yCAAoC;AA8ClC,wFA9CO,kBAAO,OA8CP;AA7CT,yCAAoC;AA8ClC,wFA9CO,kBAAO,OA8CP;AA7CT,2CAAsC;AA8CpC,yFA9CO,oBAAQ,OA8CP;AA7CV,uCAAkC;AA+ChC,uFA/CO,gBAAM,OA+CP;AA9CR,uCAAkC;AA+ChC,uFA/CO,gBAAM,OA+CP;AA9CR,uCAAkC;AA+ChC,uFA/CO,gBAAM,OA+CP;AA9CR,qCAAgC;AA2C9B,sFA3CO,cAAK,OA2CP;AA1CP,6CAAwC;AA8CtC,0FA9CO,sBAAS,OA8CP;AA7CX,mDAA8C;AAE9C,oCAA8C;AAE9C,MAAM,SAAS,GAA0C;IACvD,SAAS,EAAT,sBAAS;IACT,MAAM,EAAN,eAAM;IACN,IAAI,EAAJ,WAAI;IACJ,QAAQ,EAAR,mBAAQ;IACR,OAAO,EAAP,kBAAO;IACP,OAAO,EAAP,kBAAO;IACP,OAAO,EAAP,kBAAO;IACP,KAAK,EAAL,aAAK;IACL,OAAO,EAAP,kBAAO;IACP,OAAO,EAAP,kBAAO;IACP,QAAQ,EAAR,oBAAQ;IACR,KAAK,EAAL,cAAK;IACL,MAAM,EAAN,gBAAM;IACN,MAAM,EAAN,gBAAM;IACN,MAAM,EAAN,gBAAM;IACN,SAAS,EAAT,sBAAS;IACT,YAAY,EAAZ,4BAAY;CACb,CAAA;AAQC,8BAAS;AANX,2GAA2G;AAC3G,gFAAgF;AAChF,8FAA8F;AAC9F,2BAAmB,CAAC,cAAc,CAAC,SAAS,CAAC,CAAA"}
@@ -0,0 +1,38 @@
1
+ import { BinaryParser } from '../serdes/binary-parser';
2
+ import { JsonObject, SerializedType } from './serialized-type';
3
+ /**
4
+ * Interface for JSON objects that represent amounts
5
+ */
6
+ interface IssueObject extends JsonObject {
7
+ currency: string;
8
+ issuer?: string;
9
+ }
10
+ /**
11
+ * Class for serializing/Deserializing Amounts
12
+ */
13
+ declare class Issue extends SerializedType {
14
+ static readonly ZERO_ISSUED_CURRENCY: Issue;
15
+ constructor(bytes: Uint8Array);
16
+ /**
17
+ * Construct an amount from an IOU or string amount
18
+ *
19
+ * @param value An Amount, object representing an IOU, or a string
20
+ * representing an integer amount
21
+ * @returns An Amount object
22
+ */
23
+ static from<T extends Issue | IssueObject>(value: T): Issue;
24
+ /**
25
+ * Read an amount from a BinaryParser
26
+ *
27
+ * @param parser BinaryParser to read the Amount from
28
+ * @returns An Amount object
29
+ */
30
+ static fromParser(parser: BinaryParser): Issue;
31
+ /**
32
+ * Get the JSON representation of this Amount
33
+ *
34
+ * @returns the JSON interpretation of this.bytes
35
+ */
36
+ toJSON(): IssueObject;
37
+ }
38
+ export { Issue, IssueObject };
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Issue = void 0;
4
+ const utils_1 = require("@xrplf/isomorphic/utils");
5
+ const binary_parser_1 = require("../serdes/binary-parser");
6
+ const account_id_1 = require("./account-id");
7
+ const currency_1 = require("./currency");
8
+ const serialized_type_1 = require("./serialized-type");
9
+ /**
10
+ * Type guard for AmountObject
11
+ */
12
+ function isIssueObject(arg) {
13
+ const keys = Object.keys(arg).sort();
14
+ if (keys.length === 1) {
15
+ return keys[0] === 'currency';
16
+ }
17
+ return keys.length === 2 && keys[0] === 'currency' && keys[1] === 'issuer';
18
+ }
19
+ /**
20
+ * Class for serializing/Deserializing Amounts
21
+ */
22
+ class Issue extends serialized_type_1.SerializedType {
23
+ constructor(bytes) {
24
+ super(bytes !== null && bytes !== void 0 ? bytes : Issue.ZERO_ISSUED_CURRENCY.bytes);
25
+ }
26
+ /**
27
+ * Construct an amount from an IOU or string amount
28
+ *
29
+ * @param value An Amount, object representing an IOU, or a string
30
+ * representing an integer amount
31
+ * @returns An Amount object
32
+ */
33
+ static from(value) {
34
+ if (value instanceof Issue) {
35
+ return value;
36
+ }
37
+ if (isIssueObject(value)) {
38
+ const currency = currency_1.Currency.from(value.currency).toBytes();
39
+ if (value.issuer == null) {
40
+ return new Issue(currency);
41
+ }
42
+ const issuer = account_id_1.AccountID.from(value.issuer).toBytes();
43
+ return new Issue((0, utils_1.concat)([currency, issuer]));
44
+ }
45
+ throw new Error('Invalid type to construct an Amount');
46
+ }
47
+ /**
48
+ * Read an amount from a BinaryParser
49
+ *
50
+ * @param parser BinaryParser to read the Amount from
51
+ * @returns An Amount object
52
+ */
53
+ static fromParser(parser) {
54
+ const currency = parser.read(20);
55
+ if (new currency_1.Currency(currency).toJSON() === 'XRP') {
56
+ return new Issue(currency);
57
+ }
58
+ const currencyAndIssuer = [currency, parser.read(20)];
59
+ return new Issue((0, utils_1.concat)(currencyAndIssuer));
60
+ }
61
+ /**
62
+ * Get the JSON representation of this Amount
63
+ *
64
+ * @returns the JSON interpretation of this.bytes
65
+ */
66
+ toJSON() {
67
+ const parser = new binary_parser_1.BinaryParser(this.toString());
68
+ const currency = currency_1.Currency.fromParser(parser);
69
+ if (currency.toJSON() === 'XRP') {
70
+ return { currency: currency.toJSON() };
71
+ }
72
+ const issuer = account_id_1.AccountID.fromParser(parser);
73
+ return {
74
+ currency: currency.toJSON(),
75
+ issuer: issuer.toJSON(),
76
+ };
77
+ }
78
+ }
79
+ exports.Issue = Issue;
80
+ Issue.ZERO_ISSUED_CURRENCY = new Issue(new Uint8Array(20));
81
+ //# sourceMappingURL=issue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"issue.js","sourceRoot":"","sources":["../../../src/types/issue.ts"],"names":[],"mappings":";;;AAAA,mDAAgD;AAChD,2DAAsD;AAEtD,6CAAwC;AACxC,yCAAqC;AACrC,uDAA8D;AAU9D;;GAEG;AACH,SAAS,aAAa,CAAC,GAAG;IACxB,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAA;IACpC,IAAI,IAAI,CAAC,MAAM,KA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C7C,OAAO,IAAI,KAAK,CAAC,QAAQ,CAAC,CAAA;SAC3B;QACD,MAAM,iBAAiB,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAA;QACrD,OAAO,IAAI,KAAK,CAAC,IAAA,cAAM,EAAC,iBAAiB,CAAC,CAAC,CAAA;IAC7C,CAAC;IAED;;;;OAIG;IACH,MAAM;QACJ,MAAM,MAAM,GAAG,IAAI,4BAAY,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAA;QAChD,MAAM,QAAQ,GAAG,mBAAQ,CAAC,UAAU,CAAC,MAAM,CAAa,CAAA;QACxD,IAAI,QAAQ,CAAC,MAAM,EAAE,KAAK,KAAK,EAAE;YAC/B,OAAO,EAAE,QAAQ,EAAE,QAAQ,CAAC,MAAM,EAAE,EAAE,CAAA;SACvC;QACD,MAAM,MAAM,GAAG,sBAAS,CAAC,UAAU,CAAC,MAAM,CAAc,CAAA;QAExD,OAAO;YACL,QAAQ,EAAE,QAAQ,CAAC,MAAM,EAAE;YAC3B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE;SACxB,CAAA;IACH,CAAC;;AAGM,sBAAK;AAjEI,0BAAoB,GAAU,IAAI,KAAK,CAAC,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC,CAAA"}
@@ -0,0 +1,36 @@
1
+ import { BinaryParser } from '../serdes/binary-parser';
2
+ import { SerializedType, JsonObject } from './serialized-type';
3
+ /**
4
+ * The object representation of a Hop, an issuer AccountID, an account AccountID, and a Currency
5
+ */
6
+ interface HopObject extends JsonObject {
7
+ issuer?: string;
8
+ account?: string;
9
+ currency?: string;
10
+ }
11
+ /**
12
+ * Deserialize and Serialize the PathSet type
13
+ */
14
+ declare class PathSet extends SerializedType {
15
+ /**
16
+ * Construct a PathSet from an Array of Arrays representing paths
17
+ *
18
+ * @param value A PathSet or Array of Array of HopObjects
19
+ * @returns the PathSet constructed from value
20
+ */
21
+ static from<T extends PathSet | Array<Array<HopObject>>>(value: T): PathSet;
22
+ /**
23
+ * Construct a PathSet from a BinaryParser
24
+ *
25
+ * @param parser A BinaryParser to read PathSet from
26
+ * @returns the PathSet read from parser
27
+ */
28
+ static fromParser(parser: BinaryParser): PathSet;
29
+ /**
30
+ * Get the JSON representation of this PathSet
31
+ *
32
+ * @returns an Array of Array of HopObjects, representing this PathSet
33
+ */
34
+ toJSON(): Array<Array<HopObject>>;
35
+ }
36
+ export { PathSet };