ripple-binary-codec 1.5.0-beta.2 → 1.5.0-beta.3
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.
- package/dist/binary.d.ts +2 -1
- package/dist/binary.js +32 -30
- package/dist/binary.js.map +1 -1
- package/dist/coretypes.js +31 -8
- package/dist/coretypes.js.map +1 -1
- package/dist/enums/bytes.d.ts +26 -0
- package/dist/enums/bytes.js +68 -0
- package/dist/enums/bytes.js.map +1 -0
- package/dist/enums/constants.d.ts +4 -0
- package/dist/enums/constants.js +8 -0
- package/dist/enums/constants.js.map +1 -0
- package/dist/enums/definitions.json +44 -115
- package/dist/enums/field.d.ts +30 -0
- package/dist/enums/field.js +65 -0
- package/dist/enums/field.js.map +1 -0
- package/dist/enums/index.js +69 -60
- package/dist/enums/index.js.map +1 -1
- package/dist/enums/src/enums/definitions.json +44 -115
- package/dist/enums/utils-renumber.js +14 -14
- package/dist/enums/utils-renumber.js.map +1 -1
- package/dist/enums/xrpl-definitions.d.ts +44 -0
- package/dist/enums/xrpl-definitions.js +69 -0
- package/dist/enums/xrpl-definitions.js.map +1 -0
- package/dist/hash-prefixes.js +3 -3
- package/dist/hash-prefixes.js.map +1 -1
- package/dist/hashes.js +21 -43
- package/dist/hashes.js.map +1 -1
- package/dist/index.d.ts +2 -12
- package/dist/index.js +39 -16
- package/dist/index.js.map +1 -1
- package/dist/ledger-hashes.d.ts +1 -1
- package/dist/ledger-hashes.js +51 -28
- package/dist/ledger-hashes.js.map +1 -1
- package/dist/quality.js +18 -21
- package/dist/quality.js.map +1 -1
- package/dist/serdes/binary-parser.js +78 -56
- package/dist/serdes/binary-parser.js.map +1 -1
- package/dist/serdes/binary-serializer.js +59 -40
- package/dist/serdes/binary-serializer.js.map +1 -1
- package/dist/serdes/bytes-list.d.ts +29 -0
- package/dist/serdes/bytes-list.js +48 -0
- package/dist/serdes/bytes-list.js.map +1 -0
- package/dist/shamap.js +70 -98
- package/dist/shamap.js.map +1 -1
- package/dist/types/account-id.js +18 -35
- package/dist/types/account-id.js.map +1 -1
- package/dist/types/amount.js +71 -88
- package/dist/types/amount.js.map +1 -1
- package/dist/types/blob.js +10 -27
- package/dist/types/blob.js.map +1 -1
- package/dist/types/currency.js +26 -44
- package/dist/types/currency.js.map +1 -1
- package/dist/types/hash-128.d.ts +6 -0
- package/dist/types/hash-128.js +23 -25
- package/dist/types/hash-128.js.map +1 -1
- package/dist/types/hash-160.js +8 -25
- package/dist/types/hash-160.js.map +1 -1
- package/dist/types/hash-256.js +8 -25
- package/dist/types/hash-256.js.map +1 -1
- package/dist/types/hash.js +20 -38
- package/dist/types/hash.js.map +1 -1
- package/dist/types/index.d.ts +0 -2
- package/dist/types/index.js +20 -22
- package/dist/types/index.js.map +1 -1
- package/dist/types/issue.js +24 -41
- package/dist/types/issue.js.map +1 -1
- package/dist/types/path-set.js +57 -87
- package/dist/types/path-set.js.map +1 -1
- package/dist/types/serialized-type.d.ts +3 -3
- package/dist/types/serialized-type.js +35 -56
- package/dist/types/serialized-type.js.map +1 -1
- package/dist/types/st-array.js +26 -46
- package/dist/types/st-array.js.map +1 -1
- package/dist/types/st-object.js +49 -73
- package/dist/types/st-object.js.map +1 -1
- package/dist/types/uint-16.js +15 -32
- package/dist/types/uint-16.js.map +1 -1
- package/dist/types/uint-32.js +16 -33
- package/dist/types/uint-32.js.map +1 -1
- package/dist/types/uint-64.d.ts +1 -1
- package/dist/types/uint-64.js +30 -47
- package/dist/types/uint-64.js.map +1 -1
- package/dist/types/uint-8.js +15 -32
- package/dist/types/uint-8.js.map +1 -1
- package/dist/types/uint.d.ts +1 -1
- package/dist/types/uint.js +10 -27
- package/dist/types/uint.js.map +1 -1
- package/dist/types/vector-256.js +23 -40
- package/dist/types/vector-256.js.map +1 -1
- package/dist/types/xchain-attestation-batch.js +42 -59
- package/dist/types/xchain-attestation-batch.js.map +1 -1
- package/dist/types/xchain-bridge.js +44 -61
- package/dist/types/xchain-bridge.js.map +1 -1
- package/package.json +4 -5
- package/test/amount.test.js +1 -1
- package/test/binary-json.test.js +1 -1
- package/test/binary-parser.test.js +4 -4
- package/test/binary-serializer.test.js +3 -3
- package/test/fixtures/codec-fixtures.json +58 -118
- package/test/hash.test.js +28 -2
- package/test/ledger.test.js +1 -1
- package/test/lower-case-hex.test.js +1 -1
- package/test/pseudo-transaction.test.js +1 -1
- package/test/quality.test.js +1 -1
- package/test/shamap.test.js +3 -3
- package/test/signing-data-encoding.test.js +25 -2
- package/test/tx-encode-decode.test.js +1 -1
- package/test/types.test.js +2 -2
- package/test/uint.test.js +2 -2
- package/test/x-address.test.js +1 -1
package/dist/types/path-set.js
CHANGED
|
@@ -1,37 +1,22 @@
|
|
|
1
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 (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
3
|
exports.PathSet = void 0;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
4
|
+
const account_id_1 = require("./account-id");
|
|
5
|
+
const currency_1 = require("./currency");
|
|
6
|
+
const binary_parser_1 = require("../serdes/binary-parser");
|
|
7
|
+
const serialized_type_1 = require("./serialized-type");
|
|
8
|
+
const buffer_1 = require("buffer/");
|
|
24
9
|
/**
|
|
25
10
|
* Constants for separating Paths in a PathSet
|
|
26
11
|
*/
|
|
27
|
-
|
|
28
|
-
|
|
12
|
+
const PATHSET_END_BYTE = 0x00;
|
|
13
|
+
const PATH_SEPARATOR_BYTE = 0xff;
|
|
29
14
|
/**
|
|
30
15
|
* Constant for masking types of a Hop
|
|
31
16
|
*/
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
17
|
+
const TYPE_ACCOUNT = 0x01;
|
|
18
|
+
const TYPE_CURRENCY = 0x10;
|
|
19
|
+
const TYPE_ISSUER = 0x20;
|
|
35
20
|
/**
|
|
36
21
|
* TypeGuard for HopObject
|
|
37
22
|
*/
|
|
@@ -51,22 +36,18 @@ function isPathSet(arg) {
|
|
|
51
36
|
/**
|
|
52
37
|
* Serialize and Deserialize a Hop
|
|
53
38
|
*/
|
|
54
|
-
|
|
55
|
-
__extends(Hop, _super);
|
|
56
|
-
function Hop() {
|
|
57
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
58
|
-
}
|
|
39
|
+
class Hop extends serialized_type_1.SerializedType {
|
|
59
40
|
/**
|
|
60
41
|
* Create a Hop from a HopObject
|
|
61
42
|
*
|
|
62
43
|
* @param value Either a hop or HopObject to create a hop with
|
|
63
44
|
* @returns a Hop
|
|
64
45
|
*/
|
|
65
|
-
|
|
46
|
+
static from(value) {
|
|
66
47
|
if (value instanceof Hop) {
|
|
67
48
|
return value;
|
|
68
49
|
}
|
|
69
|
-
|
|
50
|
+
const bytes = [buffer_1.Buffer.from([0])];
|
|
70
51
|
if (value.account) {
|
|
71
52
|
bytes.push(account_id_1.AccountID.from(value.account).toBytes());
|
|
72
53
|
bytes[0][0] |= TYPE_ACCOUNT;
|
|
@@ -80,16 +61,16 @@ var Hop = /** @class */ (function (_super) {
|
|
|
80
61
|
bytes[0][0] |= TYPE_ISSUER;
|
|
81
62
|
}
|
|
82
63
|
return new Hop(buffer_1.Buffer.concat(bytes));
|
|
83
|
-
}
|
|
64
|
+
}
|
|
84
65
|
/**
|
|
85
66
|
* Construct a Hop from a BinaryParser
|
|
86
67
|
*
|
|
87
68
|
* @param parser BinaryParser to read the Hop from
|
|
88
69
|
* @returns a Hop
|
|
89
70
|
*/
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
71
|
+
static fromParser(parser) {
|
|
72
|
+
const type = parser.readUInt8();
|
|
73
|
+
const bytes = [buffer_1.Buffer.from([type])];
|
|
93
74
|
if (type & TYPE_ACCOUNT) {
|
|
94
75
|
bytes.push(parser.read(account_id_1.AccountID.width));
|
|
95
76
|
}
|
|
@@ -100,16 +81,16 @@ var Hop = /** @class */ (function (_super) {
|
|
|
100
81
|
bytes.push(parser.read(account_id_1.AccountID.width));
|
|
101
82
|
}
|
|
102
83
|
return new Hop(buffer_1.Buffer.concat(bytes));
|
|
103
|
-
}
|
|
84
|
+
}
|
|
104
85
|
/**
|
|
105
86
|
* Get the JSON interpretation of this hop
|
|
106
87
|
*
|
|
107
88
|
* @returns a HopObject, an JS object with optional account, issuer, and currency
|
|
108
89
|
*/
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
90
|
+
toJSON() {
|
|
91
|
+
const hopParser = new binary_parser_1.BinaryParser(this.bytes.toString('hex'));
|
|
92
|
+
const type = hopParser.readUInt8();
|
|
93
|
+
let account, currency, issuer;
|
|
113
94
|
if (type & TYPE_ACCOUNT) {
|
|
114
95
|
account = account_id_1.AccountID.fromParser(hopParser).toJSON();
|
|
115
96
|
}
|
|
@@ -119,7 +100,7 @@ var Hop = /** @class */ (function (_super) {
|
|
|
119
100
|
if (type & TYPE_ISSUER) {
|
|
120
101
|
issuer = account_id_1.AccountID.fromParser(hopParser).toJSON();
|
|
121
102
|
}
|
|
122
|
-
|
|
103
|
+
const result = {};
|
|
123
104
|
if (account) {
|
|
124
105
|
result.account = account;
|
|
125
106
|
}
|
|
@@ -130,49 +111,44 @@ var Hop = /** @class */ (function (_super) {
|
|
|
130
111
|
result.currency = currency;
|
|
131
112
|
}
|
|
132
113
|
return result;
|
|
133
|
-
}
|
|
114
|
+
}
|
|
134
115
|
/**
|
|
135
116
|
* get a number representing the type of this hop
|
|
136
117
|
*
|
|
137
118
|
* @returns a number to be bitwise and-ed with TYPE_ constants to describe the types in the hop
|
|
138
119
|
*/
|
|
139
|
-
|
|
120
|
+
type() {
|
|
140
121
|
return this.bytes[0];
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
}(serialized_type_1.SerializedType));
|
|
122
|
+
}
|
|
123
|
+
}
|
|
144
124
|
/**
|
|
145
125
|
* Class for serializing/deserializing Paths
|
|
146
126
|
*/
|
|
147
|
-
|
|
148
|
-
__extends(Path, _super);
|
|
149
|
-
function Path() {
|
|
150
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
151
|
-
}
|
|
127
|
+
class Path extends serialized_type_1.SerializedType {
|
|
152
128
|
/**
|
|
153
129
|
* construct a Path from an array of Hops
|
|
154
130
|
*
|
|
155
131
|
* @param value Path or array of HopObjects to construct a Path
|
|
156
132
|
* @returns the Path
|
|
157
133
|
*/
|
|
158
|
-
|
|
134
|
+
static from(value) {
|
|
159
135
|
if (value instanceof Path) {
|
|
160
136
|
return value;
|
|
161
137
|
}
|
|
162
|
-
|
|
163
|
-
value.forEach(
|
|
138
|
+
const bytes = [];
|
|
139
|
+
value.forEach((hop) => {
|
|
164
140
|
bytes.push(Hop.from(hop).toBytes());
|
|
165
141
|
});
|
|
166
142
|
return new Path(buffer_1.Buffer.concat(bytes));
|
|
167
|
-
}
|
|
143
|
+
}
|
|
168
144
|
/**
|
|
169
145
|
* Read a Path from a BinaryParser
|
|
170
146
|
*
|
|
171
147
|
* @param parser BinaryParser to read Path from
|
|
172
148
|
* @returns the Path represented by the bytes read from the BinaryParser
|
|
173
149
|
*/
|
|
174
|
-
|
|
175
|
-
|
|
150
|
+
static fromParser(parser) {
|
|
151
|
+
const bytes = [];
|
|
176
152
|
while (!parser.end()) {
|
|
177
153
|
bytes.push(Hop.fromParser(parser).toBytes());
|
|
178
154
|
if (parser.peek() === PATHSET_END_BYTE ||
|
|
@@ -181,59 +157,54 @@ var Path = /** @class */ (function (_super) {
|
|
|
181
157
|
}
|
|
182
158
|
}
|
|
183
159
|
return new Path(buffer_1.Buffer.concat(bytes));
|
|
184
|
-
}
|
|
160
|
+
}
|
|
185
161
|
/**
|
|
186
162
|
* Get the JSON representation of this Path
|
|
187
163
|
*
|
|
188
164
|
* @returns an Array of HopObject constructed from this.bytes
|
|
189
165
|
*/
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
166
|
+
toJSON() {
|
|
167
|
+
const json = [];
|
|
168
|
+
const pathParser = new binary_parser_1.BinaryParser(this.toString());
|
|
193
169
|
while (!pathParser.end()) {
|
|
194
170
|
json.push(Hop.fromParser(pathParser).toJSON());
|
|
195
171
|
}
|
|
196
172
|
return json;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
}(serialized_type_1.SerializedType));
|
|
173
|
+
}
|
|
174
|
+
}
|
|
200
175
|
/**
|
|
201
176
|
* Deserialize and Serialize the PathSet type
|
|
202
177
|
*/
|
|
203
|
-
|
|
204
|
-
__extends(PathSet, _super);
|
|
205
|
-
function PathSet() {
|
|
206
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
207
|
-
}
|
|
178
|
+
class PathSet extends serialized_type_1.SerializedType {
|
|
208
179
|
/**
|
|
209
180
|
* Construct a PathSet from an Array of Arrays representing paths
|
|
210
181
|
*
|
|
211
182
|
* @param value A PathSet or Array of Array of HopObjects
|
|
212
183
|
* @returns the PathSet constructed from value
|
|
213
184
|
*/
|
|
214
|
-
|
|
185
|
+
static from(value) {
|
|
215
186
|
if (value instanceof PathSet) {
|
|
216
187
|
return value;
|
|
217
188
|
}
|
|
218
189
|
if (isPathSet(value)) {
|
|
219
|
-
|
|
220
|
-
value.forEach(
|
|
221
|
-
|
|
222
|
-
|
|
190
|
+
const bytes = [];
|
|
191
|
+
value.forEach((path) => {
|
|
192
|
+
bytes.push(Path.from(path).toBytes());
|
|
193
|
+
bytes.push(buffer_1.Buffer.from([PATH_SEPARATOR_BYTE]));
|
|
223
194
|
});
|
|
224
|
-
|
|
225
|
-
return new PathSet(buffer_1.Buffer.concat(
|
|
195
|
+
bytes[bytes.length - 1] = buffer_1.Buffer.from([PATHSET_END_BYTE]);
|
|
196
|
+
return new PathSet(buffer_1.Buffer.concat(bytes));
|
|
226
197
|
}
|
|
227
198
|
throw new Error('Cannot construct PathSet from given value');
|
|
228
|
-
}
|
|
199
|
+
}
|
|
229
200
|
/**
|
|
230
201
|
* Construct a PathSet from a BinaryParser
|
|
231
202
|
*
|
|
232
203
|
* @param parser A BinaryParser to read PathSet from
|
|
233
204
|
* @returns the PathSet read from parser
|
|
234
205
|
*/
|
|
235
|
-
|
|
236
|
-
|
|
206
|
+
static fromParser(parser) {
|
|
207
|
+
const bytes = [];
|
|
237
208
|
while (!parser.end()) {
|
|
238
209
|
bytes.push(Path.fromParser(parser).toBytes());
|
|
239
210
|
bytes.push(parser.read(1));
|
|
@@ -242,22 +213,21 @@ var PathSet = /** @class */ (function (_super) {
|
|
|
242
213
|
}
|
|
243
214
|
}
|
|
244
215
|
return new PathSet(buffer_1.Buffer.concat(bytes));
|
|
245
|
-
}
|
|
216
|
+
}
|
|
246
217
|
/**
|
|
247
218
|
* Get the JSON representation of this PathSet
|
|
248
219
|
*
|
|
249
220
|
* @returns an Array of Array of HopObjects, representing this PathSet
|
|
250
221
|
*/
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
222
|
+
toJSON() {
|
|
223
|
+
const json = [];
|
|
224
|
+
const pathParser = new binary_parser_1.BinaryParser(this.toString());
|
|
254
225
|
while (!pathParser.end()) {
|
|
255
226
|
json.push(Path.fromParser(pathParser).toJSON());
|
|
256
227
|
pathParser.skip(1);
|
|
257
228
|
}
|
|
258
229
|
return json;
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
}(serialized_type_1.SerializedType));
|
|
230
|
+
}
|
|
231
|
+
}
|
|
262
232
|
exports.PathSet = PathSet;
|
|
263
233
|
//# sourceMappingURL=path-set.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"path-set.js","sourceRoot":"","sources":["../../src/types/path-set.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"path-set.js","sourceRoot":"","sources":["../../src/types/path-set.ts"],"names":[],"mappings":";;;AAAA,6CAAwC;AACxC,yCAAqC;AACrC,2DAAsD;AACtD,uDAA8D;AAC9D,oCAAgC;AAEhC;;GAEG;AACH,MAAM,gBAAgB,GAAG,IAAI,CAAA;AAC7B,MAAM,mBAAmB,GAAG,IAAI,CAAA;AAEhC;;GAEG;AACH,MAAM,YAAY,GAAG,IAAI,CAAA;AACzB,MAAM,aAAa,GAAG,IAAI,CAAA;AAC1B,MAAM,WAAW,GAAG,IAAI,CAAA;AAWxB;;GAEG;AACH,SAAS,WAAW,CAAC,GAAG;IACtB,OAAO,CACL,GAAG,CAAC,MAAM,KAAK,SAAS;QACxB,GAAG,CAAC,OAAO,KAAK,SAAS;QACzB,GAAG,CAAC,QAAQ,KAAK,SAAS,CAC3B,CAAA;AACH,CAAC;AAED;;GAEG;AACH,SAAS,SAAS,CAAC,GAAG;IACpB,OAAO,CACL,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC,CAAC;QACxC,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC;QACpE,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,WAAW,CAAC,GAAG,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AI,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,CAAC,CAAA;YAC7C,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAA;YAE1B,IAAI,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,gBAAgB,EAAE;gBAClD,MAAK;aACN;SACF;QAED,OAAO,IAAI,OAAO,CAAC,eAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAA;IAC1C,CAAC;IAED;;;;OAIG;IACH,MAAM;QACJ,MAAM,IAAI,GAA4B,EAAE,CAAA;QACxC,MAAM,UAAU,GAAG,IAAI,4BAAY,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAA;QAEpD,OAAO,CAAC,UAAU,CAAC,GAAG,EAAE,EAAE;YACxB,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC,MAAM,EAAE,CAAC,CAAA;YAC/C,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;SACnB;QAED,OAAO,IAAI,CAAA;IACb,CAAC;CACF;AAEQ,0BAAO"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { BytesList } from '../serdes/binary-serializer';
|
|
2
2
|
import { BinaryParser } from '../serdes/binary-parser';
|
|
3
|
-
import
|
|
3
|
+
import bigInt = require('big-integer');
|
|
4
4
|
import { Buffer } from 'buffer/';
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
type JSON = string | number | boolean | null | undefined | JSON[] | JsonObject;
|
|
6
|
+
type JsonObject = {
|
|
7
7
|
[key: string]: JSON;
|
|
8
8
|
};
|
|
9
9
|
/**
|
|
@@ -1,118 +1,97 @@
|
|
|
1
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 (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
3
|
exports.Comparable = exports.SerializedType = void 0;
|
|
19
|
-
|
|
20
|
-
|
|
4
|
+
const binary_serializer_1 = require("../serdes/binary-serializer");
|
|
5
|
+
const buffer_1 = require("buffer/");
|
|
21
6
|
/**
|
|
22
7
|
* The base class for all binary-codec types
|
|
23
8
|
*/
|
|
24
|
-
|
|
25
|
-
|
|
9
|
+
class SerializedType {
|
|
10
|
+
constructor(bytes) {
|
|
26
11
|
this.bytes = buffer_1.Buffer.alloc(0);
|
|
27
12
|
this.bytes = bytes !== null && bytes !== void 0 ? bytes : buffer_1.Buffer.alloc(0);
|
|
28
13
|
}
|
|
29
|
-
|
|
14
|
+
static fromParser(parser, hint) {
|
|
30
15
|
throw new Error('fromParser not implemented');
|
|
31
16
|
return this.fromParser(parser, hint);
|
|
32
|
-
}
|
|
33
|
-
|
|
17
|
+
}
|
|
18
|
+
static from(value) {
|
|
34
19
|
throw new Error('from not implemented');
|
|
35
20
|
return this.from(value);
|
|
36
|
-
}
|
|
21
|
+
}
|
|
37
22
|
/**
|
|
38
23
|
* Write the bytes representation of a SerializedType to a BytesList
|
|
39
24
|
*
|
|
40
25
|
* @param list The BytesList to write SerializedType bytes to
|
|
41
26
|
*/
|
|
42
|
-
|
|
27
|
+
toBytesSink(list) {
|
|
43
28
|
list.put(this.bytes);
|
|
44
|
-
}
|
|
29
|
+
}
|
|
45
30
|
/**
|
|
46
31
|
* Get the hex representation of a SerializedType's bytes
|
|
47
32
|
*
|
|
48
33
|
* @returns hex String of this.bytes
|
|
49
34
|
*/
|
|
50
|
-
|
|
35
|
+
toHex() {
|
|
51
36
|
return this.toBytes().toString('hex').toUpperCase();
|
|
52
|
-
}
|
|
37
|
+
}
|
|
53
38
|
/**
|
|
54
39
|
* Get the bytes representation of a SerializedType
|
|
55
40
|
*
|
|
56
41
|
* @returns A buffer of the bytes
|
|
57
42
|
*/
|
|
58
|
-
|
|
43
|
+
toBytes() {
|
|
59
44
|
if (this.bytes) {
|
|
60
45
|
return this.bytes;
|
|
61
46
|
}
|
|
62
|
-
|
|
47
|
+
const bytes = new binary_serializer_1.BytesList();
|
|
63
48
|
this.toBytesSink(bytes);
|
|
64
49
|
return bytes.toBytes();
|
|
65
|
-
}
|
|
50
|
+
}
|
|
66
51
|
/**
|
|
67
52
|
* Return the JSON representation of a SerializedType
|
|
68
53
|
*
|
|
69
54
|
* @returns any type, if not overloaded returns hexString representation of bytes
|
|
70
55
|
*/
|
|
71
|
-
|
|
56
|
+
toJSON() {
|
|
72
57
|
return this.toHex();
|
|
73
|
-
}
|
|
58
|
+
}
|
|
74
59
|
/**
|
|
75
60
|
* @returns hexString representation of this.bytes
|
|
76
61
|
*/
|
|
77
|
-
|
|
62
|
+
toString() {
|
|
78
63
|
return this.toHex();
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
}());
|
|
64
|
+
}
|
|
65
|
+
}
|
|
82
66
|
exports.SerializedType = SerializedType;
|
|
83
67
|
/**
|
|
84
68
|
* Base class for SerializedTypes that are comparable
|
|
85
69
|
*/
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
function Comparable() {
|
|
89
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
90
|
-
}
|
|
91
|
-
Comparable.prototype.lt = function (other) {
|
|
70
|
+
class Comparable extends SerializedType {
|
|
71
|
+
lt(other) {
|
|
92
72
|
return this.compareTo(other) < 0;
|
|
93
|
-
}
|
|
94
|
-
|
|
73
|
+
}
|
|
74
|
+
eq(other) {
|
|
95
75
|
return this.compareTo(other) === 0;
|
|
96
|
-
}
|
|
97
|
-
|
|
76
|
+
}
|
|
77
|
+
gt(other) {
|
|
98
78
|
return this.compareTo(other) > 0;
|
|
99
|
-
}
|
|
100
|
-
|
|
79
|
+
}
|
|
80
|
+
gte(other) {
|
|
101
81
|
return this.compareTo(other) > -1;
|
|
102
|
-
}
|
|
103
|
-
|
|
82
|
+
}
|
|
83
|
+
lte(other) {
|
|
104
84
|
return this.compareTo(other) < 1;
|
|
105
|
-
}
|
|
85
|
+
}
|
|
106
86
|
/**
|
|
107
87
|
* Overload this method to define how two Comparable SerializedTypes are compared
|
|
108
88
|
*
|
|
109
89
|
* @param other The comparable object to compare this to
|
|
110
90
|
* @returns A number denoting the relationship of this and other
|
|
111
91
|
*/
|
|
112
|
-
|
|
113
|
-
throw new Error(
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
}(SerializedType));
|
|
92
|
+
compareTo(other) {
|
|
93
|
+
throw new Error(`cannot compare ${this.toString()} and ${other.toString()}`);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
117
96
|
exports.Comparable = Comparable;
|
|
118
97
|
//# sourceMappingURL=serialized-type.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serialized-type.js","sourceRoot":"","sources":["../../src/types/serialized-type.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"serialized-type.js","sourceRoot":"","sources":["../../src/types/serialized-type.ts"],"names":[],"mappings":";;;AAAA,mEAAuD;AAGvD,oCAAgC;AAMhC;;GAEG;AACH,MAAM,cAAc;IAGlB,YAAY,KAAa;QAFN,UAAK,GAAW,eAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;QAGhD,IAA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,CAAC,CAAA;IAClC,CAAC;IAED,EAAE,CAAC,KAAiB;QAClB,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;IACpC,CAAC;IAED,EAAE,CAAC,KAAiB;QAClB,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IAClC,CAAC;IAED,GAAG,CAAC,KAAiB;QACnB,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAA;IACnC,CAAC;IAED,GAAG,CAAC,KAAiB;QACnB,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IAClC,CAAC;IAED;;;;;OAKG;IACH,SAAS,CAAC,KAAiB;QACzB,MAAM,IAAI,KAAK,CAAC,kBAAkB,IAAI,CAAC,QAAQ,EAAE,QAAQ,KAAK,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAA;IAC9E,CAAC;CACF;AAEwB,gCAAU"}
|
package/dist/types/st-array.js
CHANGED
|
@@ -1,28 +1,13 @@
|
|
|
1
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 (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
3
|
exports.STArray = void 0;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
4
|
+
const serialized_type_1 = require("./serialized-type");
|
|
5
|
+
const st_object_1 = require("./st-object");
|
|
6
|
+
const binary_parser_1 = require("../serdes/binary-parser");
|
|
7
|
+
const buffer_1 = require("buffer/");
|
|
8
|
+
const ARRAY_END_MARKER = buffer_1.Buffer.from([0xf1]);
|
|
9
|
+
const ARRAY_END_MARKER_NAME = 'ArrayEndMarker';
|
|
10
|
+
const OBJECT_END_MARKER = buffer_1.Buffer.from([0xe1]);
|
|
26
11
|
/**
|
|
27
12
|
* TypeGuard for Array<JsonObject>
|
|
28
13
|
*/
|
|
@@ -32,21 +17,17 @@ function isObjects(args) {
|
|
|
32
17
|
/**
|
|
33
18
|
* Class for serializing and deserializing Arrays of Objects
|
|
34
19
|
*/
|
|
35
|
-
|
|
36
|
-
__extends(STArray, _super);
|
|
37
|
-
function STArray() {
|
|
38
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
39
|
-
}
|
|
20
|
+
class STArray extends serialized_type_1.SerializedType {
|
|
40
21
|
/**
|
|
41
22
|
* Construct an STArray from a BinaryParser
|
|
42
23
|
*
|
|
43
24
|
* @param parser BinaryParser to parse an STArray from
|
|
44
25
|
* @returns An STArray Object
|
|
45
26
|
*/
|
|
46
|
-
|
|
47
|
-
|
|
27
|
+
static fromParser(parser) {
|
|
28
|
+
const bytes = [];
|
|
48
29
|
while (!parser.end()) {
|
|
49
|
-
|
|
30
|
+
const field = parser.readField();
|
|
50
31
|
if (field.name === ARRAY_END_MARKER_NAME) {
|
|
51
32
|
break;
|
|
52
33
|
}
|
|
@@ -54,47 +35,46 @@ var STArray = /** @class */ (function (_super) {
|
|
|
54
35
|
}
|
|
55
36
|
bytes.push(ARRAY_END_MARKER);
|
|
56
37
|
return new STArray(buffer_1.Buffer.concat(bytes));
|
|
57
|
-
}
|
|
38
|
+
}
|
|
58
39
|
/**
|
|
59
40
|
* Construct an STArray from an Array of JSON Objects
|
|
60
41
|
*
|
|
61
42
|
* @param value STArray or Array of Objects to parse into an STArray
|
|
62
43
|
* @returns An STArray object
|
|
63
44
|
*/
|
|
64
|
-
|
|
45
|
+
static from(value) {
|
|
65
46
|
if (value instanceof STArray) {
|
|
66
47
|
return value;
|
|
67
48
|
}
|
|
68
49
|
if (isObjects(value)) {
|
|
69
|
-
|
|
70
|
-
value.forEach(
|
|
71
|
-
|
|
50
|
+
const bytes = [];
|
|
51
|
+
value.forEach((obj) => {
|
|
52
|
+
bytes.push(st_object_1.STObject.from(obj).toBytes());
|
|
72
53
|
});
|
|
73
|
-
|
|
74
|
-
return new STArray(buffer_1.Buffer.concat(
|
|
54
|
+
bytes.push(ARRAY_END_MARKER);
|
|
55
|
+
return new STArray(buffer_1.Buffer.concat(bytes));
|
|
75
56
|
}
|
|
76
57
|
throw new Error('Cannot construct STArray from value given');
|
|
77
|
-
}
|
|
58
|
+
}
|
|
78
59
|
/**
|
|
79
60
|
* Return the JSON representation of this.bytes
|
|
80
61
|
*
|
|
81
62
|
* @returns An Array of JSON objects
|
|
82
63
|
*/
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
64
|
+
toJSON() {
|
|
65
|
+
const result = [];
|
|
66
|
+
const arrayParser = new binary_parser_1.BinaryParser(this.toString());
|
|
86
67
|
while (!arrayParser.end()) {
|
|
87
|
-
|
|
68
|
+
const field = arrayParser.readField();
|
|
88
69
|
if (field.name === ARRAY_END_MARKER_NAME) {
|
|
89
70
|
break;
|
|
90
71
|
}
|
|
91
|
-
|
|
72
|
+
const outer = {};
|
|
92
73
|
outer[field.name] = st_object_1.STObject.fromParser(arrayParser).toJSON();
|
|
93
74
|
result.push(outer);
|
|
94
75
|
}
|
|
95
76
|
return result;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
}(serialized_type_1.SerializedType));
|
|
77
|
+
}
|
|
78
|
+
}
|
|
99
79
|
exports.STArray = STArray;
|
|
100
80
|
//# sourceMappingURL=st-array.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"st-array.js","sourceRoot":"","sources":["../../src/types/st-array.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"st-array.js","sourceRoot":"","sources":["../../src/types/st-array.ts"],"names":[],"mappings":";;;AAAA,uDAA8D;AAC9D,2CAAsC;AACtC,2DAAsD;AACtD,oCAAgC;AAEhC,MAAM,gBAAgB,GAAG,eAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAA;AAC5C,MAAM,qBAAqB,GAAG,gBAAgB,CAAA;AAE9C,MAAM,iBAAiB,GAAG,eAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAA;AAE7C;;GAEG;AACH,SAAS,SAAS,CAAC,IAAI;IACrB,OAAO,CACL,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC,IAAI,OAAO,IAAI,CAAC,CAAC,CAAC,KAAK,QAAQ,CAAC,CAC1E,CAAA;AACH,CAAC;AAED;;GAEG;AACH,MAAM,OAAQ,SAAQ,gCAAc;IAClC;;;;;OAKG;IACH,MAAM,CAAC,UAAU,CAAC,MAAoB;QACpC,MAAM,KAAK,GAAkB,EAAE,CAAA;QAE/B,OAAO,CAAC,MAAM,CAAC,GAAG,EAAE,EAAE;YACpB,MAAM,KAAK,GAAG,MAAM,CAAC,SAAS,EAAE,CAAA;YAChC,IAAI,KAAK,CAAC,IAAI,KAAK,qBAAqB,EAAE;gBACxC,MAAK;aACN;YAED,KAAK,CAAC,IAAI,CACR,KAAK,CAAC,MAAM,EACZ,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,EACtC,iBAAiB,CAClB,CAAA;SACF;QAED,KAAK,CAAC,IAAI,CAAC,gBAAgB,CA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