1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", { value: true });
|
4 | exports.transactionID = exports.sha512Half = exports.binaryToJSON = exports.signingClaimData = exports.signingData = exports.multiSigningData = exports.readJSON = exports.serializeObject = exports.makeParser = exports.BytesList = exports.BinarySerializer = exports.BinaryParser = void 0;
|
5 | const utils_1 = require("@xrplf/isomorphic/utils");
|
6 | const types_1 = require("./types");
|
7 | const binary_parser_1 = require("./serdes/binary-parser");
|
8 | Object.defineProperty(exports, "BinaryParser", { enumerable: true, get: function () { return binary_parser_1.BinaryParser; } });
|
9 | const hash_prefixes_1 = require("./hash-prefixes");
|
10 | const binary_serializer_1 = require("./serdes/binary-serializer");
|
11 | Object.defineProperty(exports, "BinarySerializer", { enumerable: true, get: function () { return binary_serializer_1.BinarySerializer; } });
|
12 | Object.defineProperty(exports, "BytesList", { enumerable: true, get: function () { return binary_serializer_1.BytesList; } });
|
13 | const hashes_1 = require("./hashes");
|
14 | Object.defineProperty(exports, "sha512Half", { enumerable: true, get: function () { return hashes_1.sha512Half; } });
|
15 | Object.defineProperty(exports, "transactionID", { enumerable: true, get: function () { return hashes_1.transactionID; } });
|
16 | const enums_1 = require("./enums");
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 | const makeParser = (bytes, definitions) => new binary_parser_1.BinaryParser(bytes instanceof Uint8Array ? (0, utils_1.bytesToHex)(bytes) : bytes, definitions);
|
26 | exports.makeParser = makeParser;
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 | const readJSON = (parser, definitions = enums_1.DEFAULT_DEFINITIONS) => parser.readType(types_1.coreTypes.STObject).toJSON(definitions);
|
36 | exports.readJSON = readJSON;
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 | const binaryToJSON = (bytes, definitions) => readJSON(makeParser(bytes, definitions), definitions);
|
46 | exports.binaryToJSON = binaryToJSON;
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 | function serializeObject(object, opts = {}) {
|
55 | const { prefix, suffix, signingFieldsOnly = false, definitions } = opts;
|
56 | const bytesList = new binary_serializer_1.BytesList();
|
57 | if (prefix) {
|
58 | bytesList.put(prefix);
|
59 | }
|
60 | const filter = signingFieldsOnly
|
61 | ? (f) => f.isSigningField
|
62 | : undefined;
|
63 | types_1.coreTypes.STObject
|
64 | .from(object, filter, definitions)
|
65 | .toBytesSink(bytesList);
|
66 | if (suffix) {
|
67 | bytesList.put(suffix);
|
68 | }
|
69 | return bytesList.toBytes();
|
70 | }
|
71 | exports.serializeObject = serializeObject;
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 | function signingData(transaction, prefix = hash_prefixes_1.HashPrefix.transactionSig, opts = {}) {
|
81 | return serializeObject(transaction, {
|
82 | prefix,
|
83 | signingFieldsOnly: true,
|
84 | definitions: opts.definitions,
|
85 | });
|
86 | }
|
87 | exports.signingData = signingData;
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 | function signingClaimData(claim) {
|
96 | const num = BigInt(String(claim.amount));
|
97 | const prefix = hash_prefixes_1.HashPrefix.paymentChannelClaim;
|
98 | const channel = types_1.coreTypes.Hash256.from(claim.channel).toBytes();
|
99 | const amount = types_1.coreTypes.UInt64.from(num).toBytes();
|
100 | const bytesList = new binary_serializer_1.BytesList();
|
101 | bytesList.put(prefix);
|
102 | bytesList.put(channel);
|
103 | bytesList.put(amount);
|
104 | return bytesList.toBytes();
|
105 | }
|
106 | exports.signingClaimData = signingClaimData;
|
107 |
|
108 |
|
109 |
|
110 |
|
111 |
|
112 |
|
113 |
|
114 |
|
115 | function multiSigningData(transaction, signingAccount, opts = {
|
116 | definitions: enums_1.DEFAULT_DEFINITIONS,
|
117 | }) {
|
118 | const prefix = hash_prefixes_1.HashPrefix.transactionMultiSig;
|
119 | const suffix = types_1.coreTypes.AccountID.from(signingAccount).toBytes();
|
120 | return serializeObject(transaction, {
|
121 | prefix,
|
122 | suffix,
|
123 | signingFieldsOnly: true,
|
124 | definitions: opts.definitions,
|
125 | });
|
126 | }
|
127 | exports.multiSigningData = multiSigningData;
|
128 |
|
\ | No newline at end of file |