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 types_1 = require("./types");
|
6 | const binary_parser_1 = require("./serdes/binary-parser");
|
7 | Object.defineProperty(exports, "BinaryParser", { enumerable: true, get: function () { return binary_parser_1.BinaryParser; } });
|
8 | const hash_prefixes_1 = require("./hash-prefixes");
|
9 | const binary_serializer_1 = require("./serdes/binary-serializer");
|
10 | Object.defineProperty(exports, "BinarySerializer", { enumerable: true, get: function () { return binary_serializer_1.BinarySerializer; } });
|
11 | Object.defineProperty(exports, "BytesList", { enumerable: true, get: function () { return binary_serializer_1.BytesList; } });
|
12 | const hashes_1 = require("./hashes");
|
13 | Object.defineProperty(exports, "sha512Half", { enumerable: true, get: function () { return hashes_1.sha512Half; } });
|
14 | Object.defineProperty(exports, "transactionID", { enumerable: true, get: function () { return hashes_1.transactionID; } });
|
15 | const enums_1 = require("./enums");
|
16 | const bigInt = require("big-integer");
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 | const makeParser = (bytes, definitions) => new binary_parser_1.BinaryParser(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 |