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,76 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.transactionID = exports.sha512Half = exports.Sha512Half = void 0;
4
+ const hash_prefixes_1 = require("./hash-prefixes");
5
+ const types_1 = require("./types");
6
+ const binary_serializer_1 = require("./serdes/binary-serializer");
7
+ const sha512_1 = require("@xrplf/isomorphic/sha512");
8
+ /**
9
+ * Class for hashing with SHA512
10
+ * @extends BytesList So SerializedTypes can write bytes to a Sha512Half
11
+ */
12
+ class Sha512Half extends binary_serializer_1.BytesList {
13
+ constructor() {
14
+ super(...arguments);
15
+ this.hash = sha512_1.sha512.create();
16
+ }
17
+ /**
18
+ * Construct a new Sha512Hash and write bytes this.hash
19
+ *
20
+ * @param bytes bytes to write to this.hash
21
+ * @returns the new Sha512Hash object
22
+ */
23
+ static put(bytes) {
24
+ return new Sha512Half().put(bytes);
25
+ }
26
+ /**
27
+ * Write bytes to an existing Sha512Hash
28
+ *
29
+ * @param bytes bytes to write to object
30
+ * @returns the Sha512 object
31
+ */
32
+ put(bytes) {
33
+ this.hash.update(bytes);
34
+ return this;
35
+ }
36
+ /**
37
+ * Compute SHA512 hash and slice in half
38
+ *
39
+ * @returns half of a SHA512 hash
40
+ */
41
+ finish256() {
42
+ return Uint8Array.from(this.hash.digest().slice(0, 32));
43
+ }
44
+ /**
45
+ * Constructs a Hash256 from the Sha512Half object
46
+ *
47
+ * @returns a Hash256 object
48
+ */
49
+ finish() {
50
+ return new types_1.Hash256(this.finish256());
51
+ }
52
+ }
53
+ exports.Sha512Half = Sha512Half;
54
+ /**
55
+ * compute SHA512 hash of a list of bytes
56
+ *
57
+ * @param args zero or more arguments to hash
58
+ * @returns the sha512half hash of the arguments.
59
+ */
60
+ function sha512Half(...args) {
61
+ const hash = new Sha512Half();
62
+ args.forEach((a) => hash.put(a));
63
+ return hash.finish256();
64
+ }
65
+ exports.sha512Half = sha512Half;
66
+ /**
67
+ * Construct a transactionID from a Serialized Transaction
68
+ *
69
+ * @param serialized bytes to hash
70
+ * @returns a Hash256 object
71
+ */
72
+ function transactionID(serialized) {
73
+ return new types_1.Hash256(sha512Half(hash_prefixes_1.HashPrefix.transactionID, serialized));
74
+ }
75
+ exports.transactionID = transactionID;
76
+ //# sourceMappingURL=hashes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hashes.js","sourceRoot":"","sources":["../../src/hashes.ts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erData } from './ledger-hashes';
2
+ import { JsonObject } from './types/serialized-type';
3
+ import { XrplDefinitionsBase, TRANSACTION_TYPES, DEFAULT_DEFINITIONS } from './enums';
4
+ import { XrplDefinitions } from './enums/xrpl-definitions';
5
+ import { coreTypes } from './types';
6
+ /**
7
+ * Decode a transaction
8
+ *
9
+ * @param binary hex-string of the encoded transaction
10
+ * @param definitions Custom rippled types to use instead of the default. Used for sidechains and amendments.
11
+ * @returns the JSON representation of the transaction
12
+ */
13
+ declare function decode(binary: string, definitions?: XrplDefinitionsBase): JsonObject;
14
+ /**
15
+ * Encode a transaction
16
+ *
17
+ * @param json The JSON representation of a transaction
18
+ * @param definitions Custom rippled types to use instead of the default. Used for sidechains and amendments.
19
+ *
20
+ * @returns A hex-string of the encoded transaction
21
+ */
22
+ declare function encode(json: object, definitions?: XrplDefinitionsBase): string;
23
+ /**
24
+ * Encode a transaction and prepare for signing
25
+ *
26
+ * @param json JSON object representing the transaction
27
+ * @param signer string representing the account to sign the transaction with
28
+ * @param definitions Custom rippled types to use instead of the default. Used for sidechains and amendments.
29
+ * @returns a hex string of the encoded transaction
30
+ */
31
+ declare function encodeForSigning(json: object, definitions?: XrplDefinitionsBase): string;
32
+ /**
33
+ * Encode a transaction and prepare for signing with a claim
34
+ *
35
+ * @param json JSON object representing the transaction
36
+ * @param signer string representing the account to sign the transaction with
37
+ * @param definitions Custom rippled types to use instead of the default. Used for sidechains and amendments.
38
+ * @returns a hex string of the encoded transaction
39
+ */
40
+ declare function encodeForSigningClaim(json: object): string;
41
+ /**
42
+ * Encode a transaction and prepare for multi-signing
43
+ *
44
+ * @param json JSON object representing the transaction
45
+ * @param signer string representing the account to sign the transaction with
46
+ * @param definitions Custom rippled types to use instead of the default. Used for sidechains and amendments.
47
+ * @returns a hex string of the encoded transaction
48
+ */
49
+ declare function encodeForMultisigning(json: object, signer: string, definitions?: XrplDefinitionsBase): string;
50
+ /**
51
+ * Encode a quality value
52
+ *
53
+ * @param value string representation of a number
54
+ * @returns a hex-string representing the quality
55
+ */
56
+ declare function encodeQuality(value: string): string;
57
+ /**
58
+ * Decode a quality value
59
+ *
60
+ * @param value hex-string of a quality
61
+ * @returns a string representing the quality
62
+ */
63
+ declare function decodeQuality(value: string): string;
64
+ export { decode, encode, encodeForSigning, encodeForSigningClaim, encodeForMultisigning, encodeQuality, decodeQuality, decodeLedgerData, TRANSACTION_TYPES, XrplDefinitions, XrplDefinitionsBase, DEFAULT_DEFINITIONS, coreTypes, };
@@ -0,0 +1,123 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.coreTypes = exports.DEFAULT_DEFINITIONS = exports.XrplDefinitionsBase = exports.XrplDefinitions = exports.TRANSACTION_TYPES = exports.decodeLedgerData = exports.decodeQuality = exports.encodeQuality = exports.encodeForMultisigning = exports.encodeForSigningClaim = exports.encodeForSigning = exports.encode = exports.decode = void 0;
4
+ const coretypes_1 = require("./coretypes");
5
+ const ledger_hashes_1 = require("./ledger-hashes");
6
+ Object.defineProperty(exports, "decodeLedgerData", { enumerable: true, get: function () { return ledger_hashes_1.decodeLedgerData; } });
7
+ const enums_1 = require("./enums");
8
+ Object.defineProperty(exports, "XrplDefinitionsBase", { enumerable: true, get: function () { return enums_1.XrplDefinitionsBase; } });
9
+ Object.defineProperty(exports, "TRANSACTION_TYPES", { enumerable: true, get: function () { return enums_1.TRANSACTION_TYPES; } });
10
+ Object.defineProperty(exports, "DEFAULT_DEFINITIONS", { enumerable: true, get: function () { return enums_1.DEFAULT_DEFINITIONS; } });
11
+ const xrpl_definitions_1 = require("./enums/xrpl-definitions");
12
+ Object.defineProperty(exports, "XrplDefinitions", { enumerable: true, get: function () { return xrpl_definitions_1.XrplDefinitions; } });
13
+ const types_1 = require("./types");
14
+ Object.defineProperty(exports, "coreTypes", { enumerable: true, get: function () { return types_1.coreTypes; } });
15
+ const utils_1 = require("@xrplf/isomorphic/utils");
16
+ const { signingData, signingClaimData, multiSigningData, binaryToJSON, serializeObject, } = coretypes_1.binary;
17
+ /**
18
+ * Decode a transaction
19
+ *
20
+ * @param binary hex-string of the encoded transaction
21
+ * @param definitions Custom rippled types to use instead of the default. Used for sidechains and amendments.
22
+ * @returns the JSON representation of the transaction
23
+ */
24
+ function decode(binary, definitions) {
25
+ if (typeof binary !== 'string') {
26
+ throw new Error('binary must be a hex string');
27
+ }
28
+ return binaryToJSON(binary, definitions);
29
+ }
30
+ exports.decode = decode;
31
+ /**
32
+ * Encode a transaction
33
+ *
34
+ * @param json The JSON representation of a transaction
35
+ * @param definitions Custom rippled types to use instead of the default. Used for sidechains and amendments.
36
+ *
37
+ * @returns A hex-string of the encoded transaction
38
+ */
39
+ function encode(json, definitions) {
40
+ if (typeof json !== 'object') {
41
+ throw new Error();
42
+ }
43
+ return (0, utils_1.bytesToHex)(serializeObject(json, { definitions }));
44
+ }
45
+ exports.encode = encode;
46
+ /**
47
+ * Encode a transaction and prepare for signing
48
+ *
49
+ * @param json JSON object representing the transaction
50
+ * @param signer string representing the account to sign the transaction with
51
+ * @param definitions Custom rippled types to use instead of the default. Used for sidechains and amendments.
52
+ * @returns a hex string of the encoded transaction
53
+ */
54
+ function encodeForSigning(json, definitions) {
55
+ if (typeof json !== 'object') {
56
+ throw new Error();
57
+ }
58
+ return (0, utils_1.bytesToHex)(signingData(json, coretypes_1.HashPrefix.transactionSig, {
59
+ definitions,
60
+ }));
61
+ }
62
+ exports.encodeForSigning = encodeForSigning;
63
+ /**
64
+ * Encode a transaction and prepare for signing with a claim
65
+ *
66
+ * @param json JSON object representing the transaction
67
+ * @param signer string representing the account to sign the transaction with
68
+ * @param definitions Custom rippled types to use instead of the default. Used for sidechains and amendments.
69
+ * @returns a hex string of the encoded transaction
70
+ */
71
+ function encodeForSigningClaim(json) {
72
+ if (typeof json !== 'object') {
73
+ throw new Error();
74
+ }
75
+ return (0, utils_1.bytesToHex)(signingClaimData(json));
76
+ }
77
+ exports.encodeForSigningClaim = encodeForSigningClaim;
78
+ /**
79
+ * Encode a transaction and prepare for multi-signing
80
+ *
81
+ * @param json JSON object representing the transaction
82
+ * @param signer string representing the account to sign the transaction with
83
+ * @param definitions Custom rippled types to use instead of the default. Used for sidechains and amendments.
84
+ * @returns a hex string of the encoded transaction
85
+ */
86
+ function encodeForMultisigning(json, signer, definitions) {
87
+ if (typeof json !== 'object') {
88
+ throw new Error();
89
+ }
90
+ if (json['SigningPubKey'] !== '') {
91
+ throw new Error();
92
+ }
93
+ const definitionsOpt = definitions ? { definitions } : undefined;
94
+ return (0, utils_1.bytesToHex)(multiSigningData(json, signer, definitionsOpt));
95
+ }
96
+ exports.encodeForMultisigning = encodeForMultisigning;
97
+ /**
98
+ * Encode a quality value
99
+ *
100
+ * @param value string representation of a number
101
+ * @returns a hex-string representing the quality
102
+ */
103
+ function encodeQuality(value) {
104
+ if (typeof value !== 'string') {
105
+ throw new Error();
106
+ }
107
+ return (0, utils_1.bytesToHex)(coretypes_1.quality.encode(value));
108
+ }
109
+ exports.encodeQuality = encodeQuality;
110
+ /**
111
+ * Decode a quality value
112
+ *
113
+ * @param value hex-string of a quality
114
+ * @returns a string representing the quality
115
+ */
116
+ function decodeQuality(value) {
117
+ if (typeof value !== 'string') {
118
+ throw new Error();
119
+ }
120
+ return coretypes_1.quality.decode(value).toString();
121
+ }
122
+ exports.decodeQuality = decodeQuality;
123
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,2CAAyD;AACzD,mDAAkD;AAiJhD,iGAjJO,gCAAgB,OAiJP;AA9IlB,mCAIgB;AA6Id,oGAhJA,2BAAmB,OAgJA;AAFnB,kGA7IA,yBAAiB,OA6IA;AAGjB,oGA/IA,2BAAmB,OA+IA;AA7IrB,+DAA0D;AA2IxD,gGA3IO,kCAAe,OA2IP;AA1IjB,mCAAmC;AA6IjC,0FA7IO,iBAAS,OA6IP;AA5IX,mDAAoD;AAEpD,MAAM,EACJ,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K,QAAQ,EAAE;QAC5B,MAAM,IAAI,KAAK,EAAE,CAAA;KAClB;IACD,IAAI,IAAI,CAAC,eAAe,CAAC,KAAK,EAAE,EAAE;QAChC,MAAM,IAAI,KAAK,EAAE,CAAA;KAClB;IACD,MAAM,cAAc,GAAG,WAAW,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC,SAAS,CAAA;IAChE,OAAO,IAAA,kBAAU,EACf,gBAAgB,CAAC,IAAkB,EAAE,MAAM,EAAE,cAAc,CAAC,CAC7D,CAAA;AACH,CAAC;AAiCC,sDAAqB;AA/BvB;;;;;GAKG;AACH,SAAS,aAAa,CAAC,KAAa;IAClC,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;QAC7B,MAAM,IAAI,KAAK,EAAE,CAAA;KAClB;IACD,OAAO,IAAA,kBAAU,EAAC,mBAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAA;AAC1C,CAAC;AAqBC,sCAAa;AAnBf;;;;;GAKG;AACH,SAAS,aAAa,CAAC,KAAa;IAClC,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;QAC7B,MAAM,IAAI,KAAK,EAAE,CAAA;KAClB;IACD,OAAO,mBAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,QAAQ,EAAE,CAAA;AACzC,CAAC;AASC,sCAAa"}
@@ -0,0 +1,48 @@
1
+ import { Hash256 } from './types/hash-256';
2
+ import { JsonObject } from './types/serialized-type';
3
+ import { XrplDefinitionsBase } from './enums';
4
+ /**
5
+ * Function computing the hash of a transaction tree
6
+ *
7
+ * @param param An array of transaction objects to hash
8
+ * @returns A Hash256 object
9
+ */
10
+ declare function transactionTreeHash(param: Array<JsonObject>): Hash256;
11
+ /**
12
+ * Function computing the hash of accountState
13
+ *
14
+ * @param param A list of accountStates hash
15
+ * @returns A Hash256 object
16
+ */
17
+ declare function accountStateHash(param: Array<JsonObject>): Hash256;
18
+ /**
19
+ * Interface describing a ledger header
20
+ */
21
+ interface ledgerObject {
22
+ ledger_index: number;
23
+ total_coins: string | number | bigint;
24
+ parent_hash: string;
25
+ transaction_hash: string;
26
+ account_hash: string;
27
+ parent_close_time: number;
28
+ close_time: number;
29
+ close_time_resolution: number;
30
+ close_flags: number;
31
+ }
32
+ /**
33
+ * Serialize and hash a ledger header
34
+ *
35
+ * @param header a ledger header
36
+ * @returns the hash of header
37
+ */
38
+ declare function ledgerHash(header: ledgerObject): Hash256;
39
+ /**
40
+ * Decodes a serialized ledger header
41
+ *
42
+ * @param binary A serialized ledger header
43
+ * @param definitions Type definitions to parse the ledger objects.
44
+ * Used if there are non-default ledger objects to decode.
45
+ * @returns A JSON object describing a ledger header
46
+ */
47
+ declare function decodeLedgerData(binary: string, definitions?: XrplDefinitionsBase): object;
48
+ export { accountStateHash, transactionTreeHash, ledgerHash, decodeLedgerData };
@@ -0,0 +1,141 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.decodeLedgerData = exports.ledgerHash = exports.transactionTreeHash = exports.accountStateHash = void 0;
4
+ const shamap_1 = require("./shamap");
5
+ const hash_prefixes_1 = require("./hash-prefixes");
6
+ const hashes_1 = require("./hashes");
7
+ const binary_1 = require("./binary");
8
+ const hash_256_1 = require("./types/hash-256");
9
+ const st_object_1 = require("./types/st-object");
10
+ const uint_64_1 = require("./types/uint-64");
11
+ const uint_32_1 = require("./types/uint-32");
12
+ const uint_8_1 = require("./types/uint-8");
13
+ const binary_parser_1 = require("./serdes/binary-parser");
14
+ /**
15
+ * Computes the hash of a list of objects
16
+ *
17
+ * @param itemizer Converts an item into a format that can be added to SHAMap
18
+ * @param itemsJson Array of items to add to a SHAMap
19
+ * @returns the hash of the SHAMap
20
+ */
21
+ function computeHash(itemizer, itemsJson) {
22
+ const map = new shamap_1.ShaMap();
23
+ itemsJson.forEach((item) => map.addItem(...itemizer(item)));
24
+ return map.hash();
25
+ }
26
+ /**
27
+ * Convert a transaction into an index and an item
28
+ *
29
+ * @param json transaction with metadata
30
+ * @returns a tuple of index and item to be added to SHAMap
31
+ */
32
+ function transactionItemizer(json) {
33
+ if (!json.hash) {
34
+ throw new Error();
35
+ }
36
+ const index = hash_256_1.Hash256.from(json.hash);
37
+ const item = {
38
+ hashPrefix() {
39
+ return hash_prefixes_1.HashPrefix.transaction;
40
+ },
41
+ toBytesSink(sink) {
42
+ const serializer = new binary_1.BinarySerializer(sink);
43
+ serializer.writeLengthEncoded(st_object_1.STObject.from(json));
44
+ serializer.writeLengthEncoded(st_object_1.STObject.from(json.metaData));
45
+ },
46
+ };
47
+ return [index, item, undefined];
48
+ }
49
+ /**
50
+ * Convert an entry to a pair Hash256 and ShaMapNode
51
+ *
52
+ * @param json JSON describing a ledger entry item
53
+ * @returns a tuple of index and item to be added to SHAMap
54
+ */
55
+ function entryItemizer(json) {
56
+ const index = hash_256_1.Hash256.from(json.index);
57
+ const bytes = (0, binary_1.serializeObject)(json);
58
+ const item = {
59
+ hashPrefix() {
60
+ return hash_prefixes_1.HashPrefix.accountStateEntry;
61
+ },
62
+ toBytesSink(sink) {
63
+ sink.put(bytes);
64
+ },
65
+ };
66
+ return [index, item, undefined];
67
+ }
68
+ /**
69
+ * Function computing the hash of a transaction tree
70
+ *
71
+ * @param param An array of transaction objects to hash
72
+ * @returns A Hash256 object
73
+ */
74
+ function transactionTreeHash(param) {
75
+ const itemizer = transactionItemizer;
76
+ return computeHash(itemizer, param);
77
+ }
78
+ exports.transactionTreeHash = transactionTreeHash;
79
+ /**
80
+ * Function computing the hash of accountState
81
+ *
82
+ * @param param A list of accountStates hash
83
+ * @returns A Hash256 object
84
+ */
85
+ function accountStateHash(param) {
86
+ const itemizer = entryItemizer;
87
+ return computeHash(itemizer, param);
88
+ }
89
+ exports.accountStateHash = accountStateHash;
90
+ /**
91
+ * Serialize and hash a ledger header
92
+ *
93
+ * @param header a ledger header
94
+ * @returns the hash of header
95
+ */
96
+ function ledgerHash(header) {
97
+ const hash = new hashes_1.Sha512Half();
98
+ hash.put(hash_prefixes_1.HashPrefix.ledgerHeader);
99
+ if (header.parent_close_time === undefined ||
100
+ header.close_flags === undefined) {
101
+ throw new Error();
102
+ }
103
+ uint_32_1.UInt32.from(header.ledger_index).toBytesSink(hash);
104
+ uint_64_1.UInt64.from(BigInt(String(header.total_coins))).toBytesSink(hash);
105
+ hash_256_1.Hash256.from(header.parent_hash).toBytesSink(hash);
106
+ hash_256_1.Hash256.from(header.transaction_hash).toBytesSink(hash);
107
+ hash_256_1.Hash256.from(header.account_hash).toBytesSink(hash);
108
+ uint_32_1.UInt32.from(header.parent_close_time).toBytesSink(hash);
109
+ uint_32_1.UInt32.from(header.close_time).toBytesSink(hash);
110
+ uint_8_1.UInt8.from(header.close_time_resolution).toBytesSink(hash);
111
+ uint_8_1.UInt8.from(header.close_flags).toBytesSink(hash);
112
+ return hash.finish();
113
+ }
114
+ exports.ledgerHash = ledgerHash;
115
+ /**
116
+ * Decodes a serialized ledger header
117
+ *
118
+ * @param binary A serialized ledger header
119
+ * @param definitions Type definitions to parse the ledger objects.
120
+ * Used if there are non-default ledger objects to decode.
121
+ * @returns A JSON object describing a ledger header
122
+ */
123
+ function decodeLedgerData(binary, definitions) {
124
+ if (typeof binary !== 'string') {
125
+ throw new Error('binary must be a hex string');
126
+ }
127
+ const parser = new binary_parser_1.BinaryParser(binary, definitions);
128
+ return {
129
+ ledger_index: parser.readUInt32(),
130
+ total_coins: parser.readType(uint_64_1.UInt64).valueOf().toString(),
131
+ parent_hash: parser.readType(hash_256_1.Hash256).toHex(),
132
+ transaction_hash: parser.readType(hash_256_1.Hash256).toHex(),
133
+ account_hash: parser.readType(hash_256_1.Hash256).toHex(),
134
+ parent_close_time: parser.readUInt32(),
135
+ close_time: parser.readUInt32(),
136
+ close_time_resolution: parser.readUInt8(),
137
+ close_flags: parser.readUInt8(),
138
+ };
139
+ }
140
+ exports.decodeLedgerData = decodeLedgerData;
141
+ //# sourceMappingURL=ledger-hashes.js.map
@@ -0,0 +1 @@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,CAAC,kBAAO,CAAC,CAAC,KAAK,EAAE;QAClD,YAAY,EAAE,MAAM,CAAC,QAAQ,CAAC,kBAAO,CAAC,CAAC,KAAK,EAAE;QAC9C,iBAAiB,EAAE,MAAM,CAAC,UAAU,EAAE;QACtC,UAAU,EAAE,MAAM,CAAC,UAAU,EAAE;QAC/B,qBAAqB,EAAE,MAAM,CAAC,SAAS,EAAE;QACzC,WAAW,EAAE,MAAM,CAAC,SAAS,EAAE;KAChC,CAAA;AACH,CAAC;AAE2D,4CAAgB"}
@@ -0,0 +1,21 @@
1
+ import BigNumber from 'bignumber.js';
2
+ /**
3
+ * class for encoding and decoding quality
4
+ */
5
+ declare class quality {
6
+ /**
7
+ * Encode quality amount
8
+ *
9
+ * @param arg string representation of an amount
10
+ * @returns Serialized quality
11
+ */
12
+ static encode(quality: string): Uint8Array;
13
+ /**
14
+ * Decode quality amount
15
+ *
16
+ * @param arg hex-string denoting serialized quality
17
+ * @returns deserialized quality
18
+ */
19
+ static decode(quality: string): BigNumber;
20
+ }
21
+ export { quality };
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.quality = void 0;
7
+ const types_1 = require("./types");
8
+ const bignumber_js_1 = __importDefault(require("bignumber.js"));
9
+ const utils_1 = require("@xrplf/isomorphic/utils");
10
+ /**
11
+ * class for encoding and decoding quality
12
+ */
13
+ class quality {
14
+ /**
15
+ * Encode quality amount
16
+ *
17
+ * @param arg string representation of an amount
18
+ * @returns Serialized quality
19
+ */
20
+ static encode(quality) {
21
+ const decimal = (0, bignumber_js_1.default)(quality);
22
+ const exponent = ((decimal === null || decimal === void 0 ? void 0 : decimal.e) || 0) - 15;
23
+ const qualityString = decimal.times(`1e${-exponent}`).abs().toString();
24
+ const bytes = types_1.coreTypes.UInt64.from(BigInt(qualityString)).toBytes();
25
+ bytes[0] = exponent + 100;
26
+ return bytes;
27
+ }
28
+ /**
29
+ * Decode quality amount
30
+ *
31
+ * @param arg hex-string denoting serialized quality
32
+ * @returns deserialized quality
33
+ */
34
+ static decode(quality) {
35
+ const bytes = (0, utils_1.hexToBytes)(quality).slice(-8);
36
+ const exponent = bytes[0] - 100;
37
+ const mantissa = new bignumber_js_1.default(`0x${(0, utils_1.bytesToHex)(bytes.slice(1))}`);
38
+ return mantissa.times(`1e${exponent}`);
39
+ }
40
+ }
41
+ exports.quality = quality;
42
+ //# sourceMappingURL=quality.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"quality.js","sourceRoot":"","sources":["../../src/quality.ts"],"names":[],"mappings":";;;;;;AAAA,mCAAmC;AACnC,gEAAoC;AACpC,mDAAgE;AAEhE;;GAEG;AACH,MAAM,OAAO;IACX;;;;;OAKG;IACH,MAAM,CAAC,MAAM,CAAC,OAAe;QAC3B,MAAM,OAAO,GAAG,IAAA,sBAAS,EAAC,OAAO,CAAC,CAAA;QAClC,MAAM,QAAQ,GAAG,CAAC,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,CAAC,KAAI,CAAC,CAAC,GAAG,EAAE,CAAA;QACvC,MAAM,aAAa,GAAG,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAA;QACtE,MAAM,KAAK,GAAG,iBAAS,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC,OAAO,EAAE,CAAA;QACpE,KAAK,CAAC,CAAC,CAAC,GAAG,QAAQ,GAAG,GAAG,CAAA;QACzB,OAAO,KAAK,CAAA;IACd,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,MAAM,CAAC,OAAe;QAC3B,MAAM,KAAK,GAAG,IAAA,kBAAU,EAAC,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;QAC3C,MAAM,QAAQ,GAAG,KAAK,CAAC,CAAC,CAAC,GAAG,GAAG,CAAA;QAC/B,MAAM,QAAQ,GAAG,IAAI,sBAAS,CAAC,KAAK,IAAA,kBAAU,EAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAA;QACjE,OAAO,QAAQ,CAAC,KAAK,CAAC,KAAK,QAAQ,EAAE,CAAC,CAAA;IACxC,CAAC;CACF;AAEQ,0BAAO"}
@@ -0,0 +1,100 @@
1
+ import { XrplDefinitionsBase, FieldInstance } from '../enums';
2
+ import { type SerializedType } from '../types/serialized-type';
3
+ /**
4
+ * BinaryParser is used to compute fields and values from a HexString
5
+ */
6
+ declare class BinaryParser {
7
+ private bytes;
8
+ definitions: XrplDefinitionsBase;
9
+ /**
10
+ * Initialize bytes to a hex string
11
+ *
12
+ * @param hexBytes a hex string
13
+ * @param definitions Rippled definitions used to parse the values of transaction types and such.
14
+ * Can be customized for sidechains and amendments.
15
+ */
16
+ constructor(hexBytes: string, definitions?: XrplDefinitionsBase);
17
+ /**
18
+ * Peek the first byte of the BinaryParser
19
+ *
20
+ * @returns The first byte of the BinaryParser
21
+ */
22
+ peek(): number;
23
+ /**
24
+ * Consume the first n bytes of the BinaryParser
25
+ *
26
+ * @param n the number of bytes to skip
27
+ */
28
+ skip(n: number): void;
29
+ /**
30
+ * read the first n bytes from the BinaryParser
31
+ *
32
+ * @param n The number of bytes to read
33
+ * @return The bytes
34
+ */
35
+ read(n: number): Uint8Array;
36
+ /**
37
+ * Read an integer of given size
38
+ *
39
+ * @param n The number of bytes to read
40
+ * @return The number represented by those bytes
41
+ */
42
+ readUIntN(n: number): number;
43
+ readUInt8(): number;
44
+ readUInt16(): number;
45
+ readUInt32(): number;
46
+ size(): number;
47
+ end(customEnd?: number): boolean;
48
+ /**
49
+ * Reads variable length encoded bytes
50
+ *
51
+ * @return The variable length bytes
52
+ */
53
+ readVariableLength(): Uint8Array;
54
+ /**
55
+ * Reads the length of the variable length encoded bytes
56
+ *
57
+ * @return The length of the variable length encoded bytes
58
+ */
59
+ readVariableLengthLength(): number;
60
+ /**
61
+ * Reads the field ordinal from the BinaryParser
62
+ *
63
+ * @return Field ordinal
64
+ */
65
+ readFieldOrdinal(): number;
66
+ /**
67
+ * Read the field from the BinaryParser
68
+ *
69
+ * @return The field represented by the bytes at the head of the BinaryParser
70
+ */
71
+ readField(): FieldInstance;
72
+ /**
73
+ * Read a given type from the BinaryParser
74
+ *
75
+ * @param type The type that you want to read from the BinaryParser
76
+ * @return The instance of that type read from the BinaryParser
77
+ */
78
+ readType(type: typeof SerializedType): SerializedType;
79
+ /**
80
+ * Get the type associated with a given field
81
+ *
82
+ * @param field The field that you wan to get the type of
83
+ * @return The type associated with the given field
84
+ */
85
+ typeForField(field: FieldInstance): typeof SerializedType;
86
+ /**
87
+ * Read value of the type specified by field from the BinaryParser
88
+ *
89
+ * @param field The field that you want to get the associated value for
90
+ * @return The value associated with the given field
91
+ */
92
+ readFieldValue(field: FieldInstance): SerializedType;
93
+ /**
94
+ * Get the next field and value from the BinaryParser
95
+ *
96
+ * @return The field and value
97
+ */
98
+ readFieldAndValue(): [FieldInstance, SerializedType];
99
+ }
100
+ export { BinaryParser };