ripple-binary-codec 1.4.2 → 1.4.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.js +25 -29
- 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 +64 -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 +2330 -1971
- package/dist/enums/field.d.ts +29 -0
- package/dist/enums/field.js +59 -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 +2337 -0
- package/dist/enums/utils-renumber.js +14 -14
- package/dist/enums/utils-renumber.js.map +1 -1
- package/dist/enums/xrpl-definitions-base.d.ts +44 -0
- package/dist/enums/xrpl-definitions-base.js +64 -0
- package/dist/enums/xrpl-definitions-base.js.map +1 -0
- package/dist/enums/xrpl-definitions.d.ts +21 -0
- package/dist/enums/xrpl-definitions.js +28 -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/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.js +18 -18
- package/dist/types/index.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/package.json +6 -8
- 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/data-driven-tests.json +0 -14
- 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 +1 -1
- 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
|
@@ -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,IAAI,CAAC,KAAK,GAAG,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,eAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;IACvC,CAAC;IAED,MAAM,CAAC,UAAU,CAAC,MAAoB,EAAE,IAAa;QACnD,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAA;QAC7C,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;IACtC,CAAC;IAED,MAAM,CAAC,IAAI,CACT,KAAgD;QAEhD,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAA;QACvC,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IACzB,CAAC;IAED;;;;OAIG;IACH,WAAW,CAAC,IAAe;QACzB,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IACtB,CAAC;IAED;;;;OAIG;IACH,KAAK;QACH,OAAO,IAAI,CAAC,OAAO,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,WAAW,EAAE,CAAA;IACrD,CAAC;IAED;;;;OAIG;IACH,OAAO;QACL,IAAI,IAAI,CAAC,KAAK,EAAE;YACd,OAAO,IAAI,CAAC,KAAK,CAAA;SAClB;QACD,MAAM,KAAK,GAAG,IAAI,6BAAS,EAAE,CAAA;QAC7B,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAA;QACvB,OAAO,KAAK,CAAC,OAAO,EAAE,CAAA;IACxB,CAAC;IAED;;;;OAIG;IACH,MAAM;QACJ,OAAO,IAAI,CAAC,KAAK,EAAE,CAAA;IACrB,CAAC;IAED;;OAEG;IACH,QAAQ;QACN,OAAO,IAAI,CAAC,KAAK,EAAE,CAAA;IACrB,CAAC;CACF;AAqCQ,wCAAc;AAnCvB;;GAEG;AACH,MAAM,UAAW,SAAQ,cAAc;IACrC,EAAE,CAAC,KAAiB;QAClB,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,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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CAAA;YACrC,IAAI,KAAK,CAAC,IAAI,KAAK,qBAAqB,EAAE;gBACxC,MAAK;aACN;YAED,MAAM,KAAK,GAAG,EAAE,CAAA;YAChB,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,oBAAQ,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,MAAM,EAAE,CAAA;YAC7D,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;SACnB;QAED,OAAO,MAAM,CAAA;IACf,CAAC;CACF;AAEQ,0BAAO"}
|
package/dist/types/st-object.js
CHANGED
|
@@ -1,34 +1,19 @@
|
|
|
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.STObject = void 0;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
4
|
+
const enums_1 = require("../enums");
|
|
5
|
+
const serialized_type_1 = require("./serialized-type");
|
|
6
|
+
const ripple_address_codec_1 = require("ripple-address-codec");
|
|
7
|
+
const binary_parser_1 = require("../serdes/binary-parser");
|
|
8
|
+
const binary_serializer_1 = require("../serdes/binary-serializer");
|
|
9
|
+
const buffer_1 = require("buffer/");
|
|
10
|
+
const OBJECT_END_MARKER_BYTE = buffer_1.Buffer.from([0xe1]);
|
|
11
|
+
const OBJECT_END_MARKER = 'ObjectEndMarker';
|
|
12
|
+
const ST_OBJECT = 'STObject';
|
|
13
|
+
const DESTINATION = 'Destination';
|
|
14
|
+
const ACCOUNT = 'Account';
|
|
15
|
+
const SOURCE_TAG = 'SourceTag';
|
|
16
|
+
const DEST_TAG = 'DestinationTag';
|
|
32
17
|
/**
|
|
33
18
|
* Break down an X-Address into an account and a tag
|
|
34
19
|
*
|
|
@@ -36,17 +21,17 @@ var DEST_TAG = 'DestinationTag';
|
|
|
36
21
|
* @param xAddress X-Address corresponding to the field
|
|
37
22
|
*/
|
|
38
23
|
function handleXAddress(field, xAddress) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
var tagName;
|
|
24
|
+
const decoded = (0, ripple_address_codec_1.xAddressToClassicAddress)(xAddress);
|
|
25
|
+
let tagName;
|
|
42
26
|
if (field === DESTINATION)
|
|
43
27
|
tagName = DEST_TAG;
|
|
44
28
|
else if (field === ACCOUNT)
|
|
45
29
|
tagName = SOURCE_TAG;
|
|
46
30
|
else if (decoded.tag !== false)
|
|
47
|
-
throw new Error(
|
|
31
|
+
throw new Error(`${field} cannot have an associated tag`);
|
|
48
32
|
return decoded.tag !== false
|
|
49
|
-
?
|
|
33
|
+
? { [field]: decoded.classicAddress, [tagName]: decoded.tag }
|
|
34
|
+
: { [field]: decoded.classicAddress };
|
|
50
35
|
}
|
|
51
36
|
/**
|
|
52
37
|
* Validate that two objects don't both have the same tag fields
|
|
@@ -64,33 +49,29 @@ function checkForDuplicateTags(obj1, obj2) {
|
|
|
64
49
|
/**
|
|
65
50
|
* Class for Serializing/Deserializing objects
|
|
66
51
|
*/
|
|
67
|
-
|
|
68
|
-
__extends(STObject, _super);
|
|
69
|
-
function STObject() {
|
|
70
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
71
|
-
}
|
|
52
|
+
class STObject extends serialized_type_1.SerializedType {
|
|
72
53
|
/**
|
|
73
54
|
* Construct a STObject from a BinaryParser
|
|
74
55
|
*
|
|
75
56
|
* @param parser BinaryParser to read STObject from
|
|
76
57
|
* @returns A STObject object
|
|
77
58
|
*/
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
59
|
+
static fromParser(parser) {
|
|
60
|
+
const list = new binary_serializer_1.BytesList();
|
|
61
|
+
const bytes = new binary_serializer_1.BinarySerializer(list);
|
|
81
62
|
while (!parser.end()) {
|
|
82
|
-
|
|
63
|
+
const field = parser.readField();
|
|
83
64
|
if (field.name === OBJECT_END_MARKER) {
|
|
84
65
|
break;
|
|
85
66
|
}
|
|
86
|
-
|
|
67
|
+
const associatedValue = parser.readFieldValue(field);
|
|
87
68
|
bytes.writeFieldAndValue(field, associatedValue);
|
|
88
69
|
if (field.type.name === ST_OBJECT) {
|
|
89
70
|
bytes.put(OBJECT_END_MARKER_BYTE);
|
|
90
71
|
}
|
|
91
72
|
}
|
|
92
73
|
return new STObject(list.toBytes());
|
|
93
|
-
}
|
|
74
|
+
}
|
|
94
75
|
/**
|
|
95
76
|
* Construct a STObject from a JSON object
|
|
96
77
|
*
|
|
@@ -98,40 +79,36 @@ var STObject = /** @class */ (function (_super) {
|
|
|
98
79
|
* @param filter optional, denote which field to include in serialized object
|
|
99
80
|
* @returns a STObject object
|
|
100
81
|
*/
|
|
101
|
-
|
|
82
|
+
static from(value, filter) {
|
|
102
83
|
if (value instanceof STObject) {
|
|
103
84
|
return value;
|
|
104
85
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
var key = _a[0], val = _a[1];
|
|
111
|
-
var handled = undefined;
|
|
86
|
+
const list = new binary_serializer_1.BytesList();
|
|
87
|
+
const bytes = new binary_serializer_1.BinarySerializer(list);
|
|
88
|
+
let isUnlModify = false;
|
|
89
|
+
const xAddressDecoded = Object.entries(value).reduce((acc, [key, val]) => {
|
|
90
|
+
let handled = undefined;
|
|
112
91
|
if (val && (0, ripple_address_codec_1.isValidXAddress)(val.toString())) {
|
|
113
92
|
handled = handleXAddress(key, val.toString());
|
|
114
93
|
checkForDuplicateTags(handled, value);
|
|
115
94
|
}
|
|
116
|
-
return Object.assign(acc, handled !== null && handled !== void 0 ? handled :
|
|
95
|
+
return Object.assign(acc, handled !== null && handled !== void 0 ? handled : { [key]: val });
|
|
117
96
|
}, {});
|
|
118
|
-
|
|
119
|
-
.map(
|
|
120
|
-
.filter(
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
})
|
|
125
|
-
.sort(function (a, b) {
|
|
97
|
+
let sorted = Object.keys(xAddressDecoded)
|
|
98
|
+
.map((f) => enums_1.Field[f])
|
|
99
|
+
.filter((f) => f !== undefined &&
|
|
100
|
+
xAddressDecoded[f.name] !== undefined &&
|
|
101
|
+
f.isSerialized)
|
|
102
|
+
.sort((a, b) => {
|
|
126
103
|
return a.ordinal - b.ordinal;
|
|
127
104
|
});
|
|
128
105
|
if (filter !== undefined) {
|
|
129
106
|
sorted = sorted.filter(filter);
|
|
130
107
|
}
|
|
131
|
-
sorted.forEach(
|
|
132
|
-
|
|
108
|
+
sorted.forEach((field) => {
|
|
109
|
+
const associatedValue = field.associatedType.from(xAddressDecoded[field.name]);
|
|
133
110
|
if (associatedValue == undefined) {
|
|
134
|
-
throw new TypeError(
|
|
111
|
+
throw new TypeError(`Unable to interpret "${field.name}: ${xAddressDecoded[field.name]}".`);
|
|
135
112
|
}
|
|
136
113
|
if (associatedValue.name === 'UNLModify') {
|
|
137
114
|
// triggered when the TransactionType field has a value of 'UNLModify'
|
|
@@ -140,32 +117,31 @@ var STObject = /** @class */ (function (_super) {
|
|
|
140
117
|
// true when in the UNLModify pseudotransaction (after the transaction type has been processed) and working with the
|
|
141
118
|
// Account field
|
|
142
119
|
// The Account field must not be a part of the UNLModify pseudotransaction encoding, due to a bug in rippled
|
|
143
|
-
|
|
120
|
+
const isUnlModifyWorkaround = field.name == 'Account' && isUnlModify;
|
|
144
121
|
bytes.writeFieldAndValue(field, associatedValue, isUnlModifyWorkaround);
|
|
145
122
|
if (field.type.name === ST_OBJECT) {
|
|
146
123
|
bytes.put(OBJECT_END_MARKER_BYTE);
|
|
147
124
|
}
|
|
148
125
|
});
|
|
149
126
|
return new STObject(list.toBytes());
|
|
150
|
-
}
|
|
127
|
+
}
|
|
151
128
|
/**
|
|
152
129
|
* Get the JSON interpretation of this.bytes
|
|
153
130
|
*
|
|
154
131
|
* @returns a JSON object
|
|
155
132
|
*/
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
133
|
+
toJSON() {
|
|
134
|
+
const objectParser = new binary_parser_1.BinaryParser(this.toString());
|
|
135
|
+
const accumulator = {};
|
|
159
136
|
while (!objectParser.end()) {
|
|
160
|
-
|
|
137
|
+
const field = objectParser.readField();
|
|
161
138
|
if (field.name === OBJECT_END_MARKER) {
|
|
162
139
|
break;
|
|
163
140
|
}
|
|
164
141
|
accumulator[field.name] = objectParser.readFieldValue(field).toJSON();
|
|
165
142
|
}
|
|
166
143
|
return accumulator;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
}(serialized_type_1.SerializedType));
|
|
144
|
+
}
|
|
145
|
+
}
|
|
170
146
|
exports.STObject = STObject;
|
|
171
147
|
//# sourceMappingURL=st-object.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"st-object.js","sourceRoot":"","sources":["../../src/types/st-object.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"st-object.js","sourceRoot":"","sources":["../../src/types/st-object.ts"],"names":[],"mappings":";;;AAAA,oCAAsD;AACtD,uDAA8D;AAC9D,+DAAgF;AAChF,2DAAsD;AACtD,mEAAyE;AACzE,oCAAgC;AA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C,eAAe,CAAC,KAAK,CAAC,IAAI,CAC5B,IAAI,CACL,CAAA;aACF;YAED,IAAK,eAAoC,CAAC,IAAI,KAAK,WAAW,EAAE;gBAC9D,sEAAsE;gBACtE,WAAW,GAAG,IAAI,CAAA;aACnB;YACD,oHAAoH;YACpH,gBAAgB;YAChB,4GAA4G;YAC5G,MAAM,qBAAqB,GAAG,KAAK,CAAC,IAAI,IAAI,SAAS,IAAI,WAAW,CAAA;YACpE,KAAK,CAAC,kBAAkB,CAAC,KAAK,EAAE,eAAe,EAAE,qBAAqB,CAAC,CAAA;YACvE,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,KAAK,SAAS,EAAE;gBACjC,KAAK,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAA;aAClC;QACH,CAAC,CAAC,CAAA;QAEF,OAAO,IAAI,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAA;IACrC,CAAC;IAED;;;;OAIG;IACH,MAAM;QACJ,MAAM,YAAY,GAAG,IAAI,4BAAY,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAA;QACtD,MAAM,WAAW,GAAG,EAAE,CAAA;QAEtB,OAAO,CAAC,YAAY,CAAC,GAAG,EAAE,EAAE;YAC1B,MAAM,KAAK,GAAG,YAAY,CAAC,SAAS,EAAE,CAAA;YACtC,IAAI,KAAK,CAAC,IAAI,KAAK,iBAAiB,EAAE;gBACpC,MAAK;aACN;YACD,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,YAAY,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,CAAA;SACtE;QAED,OAAO,WAAW,CAAA;IACpB,CAAC;CACF;AAEQ,4BAAQ"}
|
package/dist/types/uint-16.js
CHANGED
|
@@ -1,61 +1,44 @@
|
|
|
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.UInt16 = void 0;
|
|
19
|
-
|
|
20
|
-
|
|
4
|
+
const uint_1 = require("./uint");
|
|
5
|
+
const buffer_1 = require("buffer/");
|
|
21
6
|
/**
|
|
22
7
|
* Derived UInt class for serializing/deserializing 16 bit UInt
|
|
23
8
|
*/
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
return _super.call(this, bytes !== null && bytes !== void 0 ? bytes : UInt16.defaultUInt16.bytes) || this;
|
|
9
|
+
class UInt16 extends uint_1.UInt {
|
|
10
|
+
constructor(bytes) {
|
|
11
|
+
super(bytes !== null && bytes !== void 0 ? bytes : UInt16.defaultUInt16.bytes);
|
|
28
12
|
}
|
|
29
|
-
|
|
13
|
+
static fromParser(parser) {
|
|
30
14
|
return new UInt16(parser.read(UInt16.width));
|
|
31
|
-
}
|
|
15
|
+
}
|
|
32
16
|
/**
|
|
33
17
|
* Construct a UInt16 object from a number
|
|
34
18
|
*
|
|
35
19
|
* @param val UInt16 object or number
|
|
36
20
|
*/
|
|
37
|
-
|
|
21
|
+
static from(val) {
|
|
38
22
|
if (val instanceof UInt16) {
|
|
39
23
|
return val;
|
|
40
24
|
}
|
|
41
25
|
if (typeof val === 'number') {
|
|
42
|
-
|
|
26
|
+
const buf = buffer_1.Buffer.alloc(UInt16.width);
|
|
43
27
|
buf.writeUInt16BE(val, 0);
|
|
44
28
|
return new UInt16(buf);
|
|
45
29
|
}
|
|
46
30
|
throw new Error('Can not construct UInt16 with given value');
|
|
47
|
-
}
|
|
31
|
+
}
|
|
48
32
|
/**
|
|
49
33
|
* get the value of a UInt16 object
|
|
50
34
|
*
|
|
51
35
|
* @returns the number represented by this.bytes
|
|
52
36
|
*/
|
|
53
|
-
|
|
37
|
+
valueOf() {
|
|
54
38
|
return this.bytes.readUInt16BE(0);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
UInt16.defaultUInt16 = new UInt16(buffer_1.Buffer.alloc(UInt16.width));
|
|
58
|
-
return UInt16;
|
|
59
|
-
}(uint_1.UInt));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
60
41
|
exports.UInt16 = UInt16;
|
|
42
|
+
UInt16.width = 16 / 8; // 2
|
|
43
|
+
UInt16.defaultUInt16 = new UInt16(buffer_1.Buffer.alloc(UInt16.width));
|
|
61
44
|
//# sourceMappingURL=uint-16.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uint-16.js","sourceRoot":"","sources":["../../src/types/uint-16.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"uint-16.js","sourceRoot":"","sources":["../../src/types/uint-16.ts"],"names":[],"mappings":";;;AAAA,iCAA6B;AAE7B,oCAAgC;AAEhC;;GAEG;AACH,MAAM,MAAO,SAAQ,WAAI;IAIvB,YAAY,KAAa;QACvB,KAAK,CAAC,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,CAAA;IAC5C,CAAC;IAED,MAAM,CAAC,UAAU,CAAC,MAAoB;QACpC,OAAO,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAA;IAC9C,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,IAAI,CAA4B,GAAM;QAC3C,IAAI,GAAG,YAAY,MAAM,EAAE;YACzB,OAAO,GAAG,CAAA;SACX;QAED,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE;YAC3B,MAAM,GAAG,GAAG,eAAM,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;YACtC,GAAG,CAAC,aAAa,CAAC,GAAG,EAAE,CAAC,CAAC,CAAA;YACzB,OAAO,IAAI,MAAM,CAAC,GAAG,CAAC,CAAA;SACvB;QAED,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAA;IAC9D,CAAC;IAED;;;;OAIG;IACH,OAAO;QACL,OAAO,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC,CAAA;IACnC,CAAC;;AAGM,wBAAM;AAxCa,YAAK,GAAW,EAAE,GAAG,CAAC,CAAA,CAAC,IAAI;AACrC,oBAAa,GAAW,IAAI,MAAM,CAAC,eAAM,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAA"}
|