ripple-binary-codec 1.6.0 → 1.7.1
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/enums/definitions.json +13 -0
- package/dist/enums/src/enums/definitions.json +13 -0
- package/dist/types/serialized-type.d.ts +5 -1
- package/dist/types/serialized-type.js +4 -1
- package/dist/types/serialized-type.js.map +1 -1
- package/dist/types/st-array.d.ts +5 -2
- package/dist/types/st-array.js +8 -5
- package/dist/types/st-array.js.map +1 -1
- package/dist/types/st-object.js +9 -2
- package/dist/types/st-object.js.map +1 -1
- package/package.json +2 -2
- package/test/definitions.test.js +60 -0
- package/dist/types/issue.d.ts +0 -39
- package/dist/types/issue.js +0 -81
- package/dist/types/issue.js.map +0 -1
- package/dist/types/xchain-bridge.d.ts +0 -45
- package/dist/types/xchain-bridge.js +0 -102
- package/dist/types/xchain-bridge.js.map +0 -1
|
@@ -321,6 +321,16 @@
|
|
|
321
321
|
"type": "UInt16"
|
|
322
322
|
}
|
|
323
323
|
],
|
|
324
|
+
[
|
|
325
|
+
"NetworkID",
|
|
326
|
+
{
|
|
327
|
+
"nth": 1,
|
|
328
|
+
"isVLEncoded": false,
|
|
329
|
+
"isSerialized": true,
|
|
330
|
+
"isSigningField": true,
|
|
331
|
+
"type": "UInt32"
|
|
332
|
+
}
|
|
333
|
+
],
|
|
324
334
|
[
|
|
325
335
|
"Flags",
|
|
326
336
|
{
|
|
@@ -2176,6 +2186,9 @@
|
|
|
2176
2186
|
"telCAN_NOT_QUEUE_BLOCKED": -389,
|
|
2177
2187
|
"telCAN_NOT_QUEUE_FEE": -388,
|
|
2178
2188
|
"telCAN_NOT_QUEUE_FULL": -387,
|
|
2189
|
+
"telWRONG_NETWORK": -386,
|
|
2190
|
+
"telREQUIRES_NETWORK_ID": -385,
|
|
2191
|
+
"telNETWORK_ID_MAKES_TX_NON_CANONICAL": -384,
|
|
2179
2192
|
"temMALFORMED": -299,
|
|
2180
2193
|
"temBAD_AMOUNT": -298,
|
|
2181
2194
|
"temBAD_CURRENCY": -297,
|
|
@@ -321,6 +321,16 @@
|
|
|
321
321
|
"type": "UInt16"
|
|
322
322
|
}
|
|
323
323
|
],
|
|
324
|
+
[
|
|
325
|
+
"NetworkID",
|
|
326
|
+
{
|
|
327
|
+
"nth": 1,
|
|
328
|
+
"isVLEncoded": false,
|
|
329
|
+
"isSerialized": true,
|
|
330
|
+
"isSigningField": true,
|
|
331
|
+
"type": "UInt32"
|
|
332
|
+
}
|
|
333
|
+
],
|
|
324
334
|
[
|
|
325
335
|
"Flags",
|
|
326
336
|
{
|
|
@@ -2176,6 +2186,9 @@
|
|
|
2176
2186
|
"telCAN_NOT_QUEUE_BLOCKED": -389,
|
|
2177
2187
|
"telCAN_NOT_QUEUE_FEE": -388,
|
|
2178
2188
|
"telCAN_NOT_QUEUE_FULL": -387,
|
|
2189
|
+
"telWRONG_NETWORK": -386,
|
|
2190
|
+
"telREQUIRES_NETWORK_ID": -385,
|
|
2191
|
+
"telNETWORK_ID_MAKES_TX_NON_CANONICAL": -384,
|
|
2179
2192
|
|
|
2180
2193
|
"temMALFORMED": -299,
|
|
2181
2194
|
"temBAD_AMOUNT": -298,
|
|
@@ -2,6 +2,7 @@ import { BytesList } from '../serdes/binary-serializer';
|
|
|
2
2
|
import { BinaryParser } from '../serdes/binary-parser';
|
|
3
3
|
import bigInt = require('big-integer');
|
|
4
4
|
import { Buffer } from 'buffer/';
|
|
5
|
+
import { XrplDefinitionsBase } from '../enums';
|
|
5
6
|
type JSON = string | number | boolean | null | undefined | JSON[] | JsonObject;
|
|
6
7
|
type JsonObject = {
|
|
7
8
|
[key: string]: JSON;
|
|
@@ -35,9 +36,12 @@ declare class SerializedType {
|
|
|
35
36
|
/**
|
|
36
37
|
* Return the JSON representation of a SerializedType
|
|
37
38
|
*
|
|
39
|
+
* @param _definitions rippled definitions used to parse the values of transaction types and such.
|
|
40
|
+
* Unused in default, but used in STObject, STArray
|
|
41
|
+
* Can be customized for sidechains and amendments.
|
|
38
42
|
* @returns any type, if not overloaded returns hexString representation of bytes
|
|
39
43
|
*/
|
|
40
|
-
toJSON(): JSON;
|
|
44
|
+
toJSON(_definitions?: XrplDefinitionsBase): JSON;
|
|
41
45
|
/**
|
|
42
46
|
* @returns hexString representation of this.bytes
|
|
43
47
|
*/
|
|
@@ -51,9 +51,12 @@ class SerializedType {
|
|
|
51
51
|
/**
|
|
52
52
|
* Return the JSON representation of a SerializedType
|
|
53
53
|
*
|
|
54
|
+
* @param _definitions rippled definitions used to parse the values of transaction types and such.
|
|
55
|
+
* Unused in default, but used in STObject, STArray
|
|
56
|
+
* Can be customized for sidechains and amendments.
|
|
54
57
|
* @returns any type, if not overloaded returns hexString representation of bytes
|
|
55
58
|
*/
|
|
56
|
-
toJSON() {
|
|
59
|
+
toJSON(_definitions) {
|
|
57
60
|
return this.toHex();
|
|
58
61
|
}
|
|
59
62
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serialized-type.js","sourceRoot":"","sources":["../../src/types/serialized-type.ts"],"names":[],"mappings":";;;AAAA,mEAAuD;AAGvD,oCAAgC;
|
|
1
|
+
{"version":3,"file":"serialized-type.js","sourceRoot":"","sources":["../../src/types/serialized-type.ts"],"names":[],"mappings":";;;AAAA,mEAAuD;AAGvD,oCAAgC;AAOhC;;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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,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.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { XrplDefinitionsBase } from '../enums';
|
|
1
2
|
import { SerializedType, JsonObject } from './serialized-type';
|
|
2
3
|
import { BinaryParser } from '../serdes/binary-parser';
|
|
3
4
|
/**
|
|
@@ -15,14 +16,16 @@ declare class STArray extends SerializedType {
|
|
|
15
16
|
* Construct an STArray from an Array of JSON Objects
|
|
16
17
|
*
|
|
17
18
|
* @param value STArray or Array of Objects to parse into an STArray
|
|
19
|
+
* @param definitions optional, types and values to use to encode/decode a transaction
|
|
18
20
|
* @returns An STArray object
|
|
19
21
|
*/
|
|
20
|
-
static from<T extends STArray | Array<JsonObject>>(value: T): STArray;
|
|
22
|
+
static from<T extends STArray | Array<JsonObject>>(value: T, definitions?: XrplDefinitionsBase): STArray;
|
|
21
23
|
/**
|
|
22
24
|
* Return the JSON representation of this.bytes
|
|
23
25
|
*
|
|
26
|
+
* @param definitions optional, types and values to use to encode/decode a transaction
|
|
24
27
|
* @returns An Array of JSON objects
|
|
25
28
|
*/
|
|
26
|
-
toJSON(): Array<JsonObject>;
|
|
29
|
+
toJSON(definitions?: XrplDefinitionsBase): Array<JsonObject>;
|
|
27
30
|
}
|
|
28
31
|
export { STArray };
|
package/dist/types/st-array.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.STArray = void 0;
|
|
4
|
+
const enums_1 = require("../enums");
|
|
4
5
|
const serialized_type_1 = require("./serialized-type");
|
|
5
6
|
const st_object_1 = require("./st-object");
|
|
6
7
|
const binary_parser_1 = require("../serdes/binary-parser");
|
|
@@ -40,16 +41,17 @@ class STArray extends serialized_type_1.SerializedType {
|
|
|
40
41
|
* Construct an STArray from an Array of JSON Objects
|
|
41
42
|
*
|
|
42
43
|
* @param value STArray or Array of Objects to parse into an STArray
|
|
44
|
+
* @param definitions optional, types and values to use to encode/decode a transaction
|
|
43
45
|
* @returns An STArray object
|
|
44
46
|
*/
|
|
45
|
-
static from(value) {
|
|
47
|
+
static from(value, definitions = enums_1.DEFAULT_DEFINITIONS) {
|
|
46
48
|
if (value instanceof STArray) {
|
|
47
49
|
return value;
|
|
48
50
|
}
|
|
49
51
|
if (isObjects(value)) {
|
|
50
52
|
const bytes = [];
|
|
51
53
|
value.forEach((obj) => {
|
|
52
|
-
bytes.push(st_object_1.STObject.from(obj).toBytes());
|
|
54
|
+
bytes.push(st_object_1.STObject.from(obj, undefined, definitions).toBytes());
|
|
53
55
|
});
|
|
54
56
|
bytes.push(ARRAY_END_MARKER);
|
|
55
57
|
return new STArray(buffer_1.Buffer.concat(bytes));
|
|
@@ -59,18 +61,19 @@ class STArray extends serialized_type_1.SerializedType {
|
|
|
59
61
|
/**
|
|
60
62
|
* Return the JSON representation of this.bytes
|
|
61
63
|
*
|
|
64
|
+
* @param definitions optional, types and values to use to encode/decode a transaction
|
|
62
65
|
* @returns An Array of JSON objects
|
|
63
66
|
*/
|
|
64
|
-
toJSON() {
|
|
67
|
+
toJSON(definitions = enums_1.DEFAULT_DEFINITIONS) {
|
|
65
68
|
const result = [];
|
|
66
|
-
const arrayParser = new binary_parser_1.BinaryParser(this.toString());
|
|
69
|
+
const arrayParser = new binary_parser_1.BinaryParser(this.toString(), definitions);
|
|
67
70
|
while (!arrayParser.end()) {
|
|
68
71
|
const field = arrayParser.readField();
|
|
69
72
|
if (field.name === ARRAY_END_MARKER_NAME) {
|
|
70
73
|
break;
|
|
71
74
|
}
|
|
72
75
|
const outer = {};
|
|
73
|
-
outer[field.name] = st_object_1.STObject.fromParser(arrayParser).toJSON();
|
|
76
|
+
outer[field.name] = st_object_1.STObject.fromParser(arrayParser).toJSON(definitions);
|
|
74
77
|
result.push(outer);
|
|
75
78
|
}
|
|
76
79
|
return result;
|
|
@@ -1 +1 @@
|
|
|
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,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AAW,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,CAAA;YACxE,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;SACnB;QAED,OAAO,MAAM,CAAA;IACf,CAAC;CACF;AAEQ,0BAAO"}
|
package/dist/types/st-object.js
CHANGED
|
@@ -7,6 +7,7 @@ const ripple_address_codec_1 = require("ripple-address-codec");
|
|
|
7
7
|
const binary_parser_1 = require("../serdes/binary-parser");
|
|
8
8
|
const binary_serializer_1 = require("../serdes/binary-serializer");
|
|
9
9
|
const buffer_1 = require("buffer/");
|
|
10
|
+
const st_array_1 = require("./st-array");
|
|
10
11
|
const OBJECT_END_MARKER_BYTE = buffer_1.Buffer.from([0xe1]);
|
|
11
12
|
const OBJECT_END_MARKER = 'ObjectEndMarker';
|
|
12
13
|
const ST_OBJECT = 'STObject';
|
|
@@ -107,7 +108,11 @@ class STObject extends serialized_type_1.SerializedType {
|
|
|
107
108
|
sorted = sorted.filter(filter);
|
|
108
109
|
}
|
|
109
110
|
sorted.forEach((field) => {
|
|
110
|
-
const associatedValue = field.
|
|
111
|
+
const associatedValue = field.type.name === ST_OBJECT
|
|
112
|
+
? this.from(xAddressDecoded[field.name], undefined, definitions)
|
|
113
|
+
: field.type.name === 'STArray'
|
|
114
|
+
? st_array_1.STArray.from(xAddressDecoded[field.name], definitions)
|
|
115
|
+
: field.associatedType.from(xAddressDecoded[field.name]);
|
|
111
116
|
if (associatedValue == undefined) {
|
|
112
117
|
throw new TypeError(`Unable to interpret "${field.name}: ${xAddressDecoded[field.name]}".`);
|
|
113
118
|
}
|
|
@@ -140,7 +145,9 @@ class STObject extends serialized_type_1.SerializedType {
|
|
|
140
145
|
if (field.name === OBJECT_END_MARKER) {
|
|
141
146
|
break;
|
|
142
147
|
}
|
|
143
|
-
accumulator[field.name] = objectParser
|
|
148
|
+
accumulator[field.name] = objectParser
|
|
149
|
+
.readFieldValue(field)
|
|
150
|
+
.toJSON(definitions);
|
|
144
151
|
}
|
|
145
152
|
return accumulator;
|
|
146
153
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"st-object.js","sourceRoot":"","sources":["../../src/types/st-object.ts"],"names":[],"mappings":";;;AAAA,oCAKiB;AACjB,uDAA8D;AAC9D,+DAAgF;AAChF,2DAAsD;AACtD,mEAAyE;AACzE,oCAAgC;
|
|
1
|
+
{"version":3,"file":"st-object.js","sourceRoot":"","sources":["../../src/types/st-object.ts"],"names":[],"mappings":";;;AAAA,oCAKiB;AACjB,uDAA8D;AAC9D,+DAAgF;AAChF,2DAAsD;AACtD,mEAAyE;AACzE,oCAAgC;AAChC,yCAAoC;AAEpC,MAAM,sBAAsB,GAAG,eAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAA;AAClD,MAAM,iBAAiB,GAAG,iBAAiB,CAAA;AAC3C,MAAM,SAAS,GAAG,UAAU,CAAA;AAC5B,MAAM,WAAW,GAAG,aAAa,CAAA;AACjC,MAAM,OAAO,GAAG,SAAS,CAAA;AACzB,MAAM,UAAU,GAAG,WAAW,CAAA;AAC9B,MAAM,QAAQ,GAAG,gBAAgB,CAAA;AAEjC;;;;;GAKG;AACH,SAAS,cAAc,CAAC,KAAa,EAAE,QAAgB;IACrD,MAAM,OAAO,GAAG,IAAA,+CAAwB,EAAC,QAAQ,CAAC,CAAA;IAElD,IAAI,OAAO,CAAA;IACX,IAAI,KAAK,KAAK,WAAW;QAAE,OAAO,GAAG,QAAQ,CAAA;SACxC,IAAI,KAAK,KAAK,OAAO;QAAE,OAAO,GAAG,UAAU,CAAA;SAC3C,IAAI,OAAO,CAAC,GAAG,KAAK,KAAK;QAC5B,MAAM,IAAI,KAAK,CAAC,GAAG,KAAK,gCAAgC,CAAC,CAAA;IAE3D,OAAO,OAAO,CAAC,GAAG,KAAK,KAAK;QAC1B,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC,cAAc,EAAE,CAAC,OAAO,CAAC,EAAE,OAAO,CAA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AAA;aAClC;QACH,CAAC,CAAC,CAAA;QAEF,OAAO,IAAI,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAA;IACrC,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,WAAiC;QACtC,MAAM,YAAY,GAAG,IAAI,4BAAY,CAAC,IAAI,CAAC,QAAQ,EAAE,EAAE,WAAW,CAAC,CAAA;QACnE,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;YAED,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,YAAY;iBACnC,cAAc,CAAC,KAAK,CAAC;iBACrB,MAAM,CAAC,WAAW,CAAC,CAAA;SACvB;QAED,OAAO,WAAW,CAAA;IACpB,CAAC;CACF;AAEQ,4BAAQ"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ripple-binary-codec",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.1",
|
|
4
4
|
"description": "XRP Ledger binary codec",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist/*",
|
|
@@ -40,5 +40,5 @@
|
|
|
40
40
|
"engines": {
|
|
41
41
|
"node": ">= 10"
|
|
42
42
|
},
|
|
43
|
-
"gitHead": "
|
|
43
|
+
"gitHead": "5ec6729c614f6f25328f939c9a039a9fdfb6e9b1"
|
|
44
44
|
}
|
package/test/definitions.test.js
CHANGED
|
@@ -60,6 +60,66 @@ describe('encode and decode using new types as a parameter', function () {
|
|
|
60
60
|
expect(decoded).toStrictEqual(tx)
|
|
61
61
|
})
|
|
62
62
|
|
|
63
|
+
test('can encode and decode a new Field nested in STObject in STArray in STObject', function () {
|
|
64
|
+
const tx = {
|
|
65
|
+
...txJson,
|
|
66
|
+
NewFieldArray: [
|
|
67
|
+
{
|
|
68
|
+
NewField: {
|
|
69
|
+
NewFieldValue: 10,
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
],
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Before updating the types, undefined fields will be ignored on encode
|
|
76
|
+
expect(decode(encode(tx))).not.toStrictEqual(tx)
|
|
77
|
+
|
|
78
|
+
// Normally this would be generated directly from rippled with something like `server_definitions`.
|
|
79
|
+
// Added here to make it easier to see what is actually changing in the definitions.json file.
|
|
80
|
+
const definitions = JSON.parse(JSON.stringify(normalDefinitionsJson))
|
|
81
|
+
|
|
82
|
+
definitions.FIELDS.push([
|
|
83
|
+
'NewFieldArray',
|
|
84
|
+
{
|
|
85
|
+
nth: 100,
|
|
86
|
+
isVLEncoded: false,
|
|
87
|
+
isSerialized: true,
|
|
88
|
+
isSigningField: true,
|
|
89
|
+
type: 'STArray',
|
|
90
|
+
},
|
|
91
|
+
])
|
|
92
|
+
|
|
93
|
+
definitions.FIELDS.push([
|
|
94
|
+
'NewField',
|
|
95
|
+
{
|
|
96
|
+
nth: 101,
|
|
97
|
+
isVLEncoded: false,
|
|
98
|
+
isSerialized: true,
|
|
99
|
+
isSigningField: true,
|
|
100
|
+
type: 'STObject',
|
|
101
|
+
},
|
|
102
|
+
])
|
|
103
|
+
|
|
104
|
+
definitions.FIELDS.push([
|
|
105
|
+
'NewFieldValue',
|
|
106
|
+
{
|
|
107
|
+
nth: 102,
|
|
108
|
+
isVLEncoded: false,
|
|
109
|
+
isSerialized: true,
|
|
110
|
+
isSigningField: true,
|
|
111
|
+
type: 'UInt32',
|
|
112
|
+
},
|
|
113
|
+
])
|
|
114
|
+
|
|
115
|
+
const newDefs = new XrplDefinitions(definitions)
|
|
116
|
+
|
|
117
|
+
const encoded = encode(tx, newDefs)
|
|
118
|
+
expect(() => decode(encoded)).toThrow()
|
|
119
|
+
const decoded = decode(encoded, newDefs)
|
|
120
|
+
expect(decoded).toStrictEqual(tx)
|
|
121
|
+
})
|
|
122
|
+
|
|
63
123
|
test('can encode and decode a new Type', function () {
|
|
64
124
|
const tx = {
|
|
65
125
|
...txJson,
|
package/dist/types/issue.d.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { BinaryParser } from '../serdes/binary-parser';
|
|
2
|
-
import { JsonObject, SerializedType } from './serialized-type';
|
|
3
|
-
import { Buffer } from 'buffer/';
|
|
4
|
-
/**
|
|
5
|
-
* Interface for JSON objects that represent amounts
|
|
6
|
-
*/
|
|
7
|
-
interface IssueObject extends JsonObject {
|
|
8
|
-
currency: string;
|
|
9
|
-
issuer?: string;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Class for serializing/Deserializing Amounts
|
|
13
|
-
*/
|
|
14
|
-
declare class Issue extends SerializedType {
|
|
15
|
-
static readonly ZERO_ISSUED_CURRENCY: Issue;
|
|
16
|
-
constructor(bytes: Buffer);
|
|
17
|
-
/**
|
|
18
|
-
* Construct an amount from an IOU or string amount
|
|
19
|
-
*
|
|
20
|
-
* @param value An Amount, object representing an IOU, or a string
|
|
21
|
-
* representing an integer amount
|
|
22
|
-
* @returns An Amount object
|
|
23
|
-
*/
|
|
24
|
-
static from<T extends Issue | IssueObject>(value: T): Issue;
|
|
25
|
-
/**
|
|
26
|
-
* Read an amount from a BinaryParser
|
|
27
|
-
*
|
|
28
|
-
* @param parser BinaryParser to read the Amount from
|
|
29
|
-
* @returns An Amount object
|
|
30
|
-
*/
|
|
31
|
-
static fromParser(parser: BinaryParser): Issue;
|
|
32
|
-
/**
|
|
33
|
-
* Get the JSON representation of this Amount
|
|
34
|
-
*
|
|
35
|
-
* @returns the JSON interpretation of this.bytes
|
|
36
|
-
*/
|
|
37
|
-
toJSON(): IssueObject;
|
|
38
|
-
}
|
|
39
|
-
export { Issue, IssueObject };
|
package/dist/types/issue.js
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Issue = void 0;
|
|
4
|
-
const binary_parser_1 = require("../serdes/binary-parser");
|
|
5
|
-
const account_id_1 = require("./account-id");
|
|
6
|
-
const currency_1 = require("./currency");
|
|
7
|
-
const serialized_type_1 = require("./serialized-type");
|
|
8
|
-
const buffer_1 = require("buffer/");
|
|
9
|
-
/**
|
|
10
|
-
* Type guard for AmountObject
|
|
11
|
-
*/
|
|
12
|
-
function isIssueObject(arg) {
|
|
13
|
-
const keys = Object.keys(arg).sort();
|
|
14
|
-
if (keys.length === 1) {
|
|
15
|
-
return keys[0] === 'currency';
|
|
16
|
-
}
|
|
17
|
-
return keys.length === 2 && keys[0] === 'currency' && keys[1] === 'issuer';
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Class for serializing/Deserializing Amounts
|
|
21
|
-
*/
|
|
22
|
-
class Issue extends serialized_type_1.SerializedType {
|
|
23
|
-
constructor(bytes) {
|
|
24
|
-
super(bytes !== null && bytes !== void 0 ? bytes : Issue.ZERO_ISSUED_CURRENCY.bytes);
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Construct an amount from an IOU or string amount
|
|
28
|
-
*
|
|
29
|
-
* @param value An Amount, object representing an IOU, or a string
|
|
30
|
-
* representing an integer amount
|
|
31
|
-
* @returns An Amount object
|
|
32
|
-
*/
|
|
33
|
-
static from(value) {
|
|
34
|
-
if (value instanceof Issue) {
|
|
35
|
-
return value;
|
|
36
|
-
}
|
|
37
|
-
if (isIssueObject(value)) {
|
|
38
|
-
const currency = currency_1.Currency.from(value.currency).toBytes();
|
|
39
|
-
if (value.issuer == null) {
|
|
40
|
-
return new Issue(currency);
|
|
41
|
-
}
|
|
42
|
-
const issuer = account_id_1.AccountID.from(value.issuer).toBytes();
|
|
43
|
-
return new Issue(buffer_1.Buffer.concat([currency, issuer]));
|
|
44
|
-
}
|
|
45
|
-
throw new Error('Invalid type to construct an Amount');
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Read an amount from a BinaryParser
|
|
49
|
-
*
|
|
50
|
-
* @param parser BinaryParser to read the Amount from
|
|
51
|
-
* @returns An Amount object
|
|
52
|
-
*/
|
|
53
|
-
static fromParser(parser) {
|
|
54
|
-
const currency = parser.read(20);
|
|
55
|
-
if (new currency_1.Currency(currency).toJSON() === 'XRP') {
|
|
56
|
-
return new Issue(currency);
|
|
57
|
-
}
|
|
58
|
-
const currencyAndIssuer = [currency, parser.read(20)];
|
|
59
|
-
return new Issue(buffer_1.Buffer.concat(currencyAndIssuer));
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Get the JSON representation of this Amount
|
|
63
|
-
*
|
|
64
|
-
* @returns the JSON interpretation of this.bytes
|
|
65
|
-
*/
|
|
66
|
-
toJSON() {
|
|
67
|
-
const parser = new binary_parser_1.BinaryParser(this.toString());
|
|
68
|
-
const currency = currency_1.Currency.fromParser(parser);
|
|
69
|
-
if (currency.toJSON() === 'XRP') {
|
|
70
|
-
return { currency: currency.toJSON() };
|
|
71
|
-
}
|
|
72
|
-
const issuer = account_id_1.AccountID.fromParser(parser);
|
|
73
|
-
return {
|
|
74
|
-
currency: currency.toJSON(),
|
|
75
|
-
issuer: issuer.toJSON(),
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
exports.Issue = Issue;
|
|
80
|
-
Issue.ZERO_ISSUED_CURRENCY = new Issue(buffer_1.Buffer.alloc(20));
|
|
81
|
-
//# sourceMappingURL=issue.js.map
|
package/dist/types/issue.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"issue.js","sourceRoot":"","sources":["../../src/types/issue.ts"],"names":[],"mappings":";;;AAAA,2DAAsD;AAEtD,6CAAwC;AACxC,yCAAqC;AACrC,uDAA8D;AAC9D,oCAAgC;AAUhC;;GAEG;AACH,SAAS,aAAa,CAAC,GAAG;IACxB,MAAM,IAAI,GAAG,MAAM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CAAA;QAChC,IAAI,IAAI,mBAAQ,CAAC,QAAQ,CAAC,CAAC,MAAM,EAAE,KAAK,KAAK,EAAE;YAC7C,OAAO,IAAI,KAAK,CAAC,QAAQ,CAAC,CAAA;SAC3B;QACD,MAAM,iBAAiB,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAA;QACrD,OAAO,IAAI,KAAK,CAAC,eAAM,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC,CAAA;IACpD,CAAC;IAED;;;;OAIG;IACH,MAAM;QACJ,MAAM,MAAM,GAAG,IAAI,4BAAY,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAA;QAChD,MAAM,QAAQ,GAAG,mBAAQ,CAAC,UAAU,CAAC,MAAM,CAAa,CAAA;QACxD,IAAI,QAAQ,CAAC,MAAM,EAAE,KAAK,KAAK,EAAE;YAC/B,OAAO,EAAE,QAAQ,EAAE,QAAQ,CAAC,MAAM,EAAE,EAAE,CAAA;SACvC;QACD,MAAM,MAAM,GAAG,sBAAS,CAAC,UAAU,CAAC,MAAM,CAAc,CAAA;QAExD,OAAO;YACL,QAAQ,EAAE,QAAQ,CAAC,MAAM,EAAE;YAC3B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE;SACxB,CAAA;IACH,CAAC;;AAGM,sBAAK;AAjEI,0BAAoB,GAAU,IAAI,KAAK,CAAC,eAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAA"}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { BinaryParser } from '../serdes/binary-parser';
|
|
2
|
-
import { JsonObject, SerializedType } from './serialized-type';
|
|
3
|
-
import { Buffer } from 'buffer/';
|
|
4
|
-
import { IssueObject } from './issue';
|
|
5
|
-
/**
|
|
6
|
-
* Interface for JSON objects that represent cross-chain bridges
|
|
7
|
-
*/
|
|
8
|
-
interface XChainBridgeObject extends JsonObject {
|
|
9
|
-
LockingChainDoor: string;
|
|
10
|
-
LockingChainIssue: IssueObject | string;
|
|
11
|
-
IssuingChainDoor: string;
|
|
12
|
-
IssuingChainIssue: IssueObject | string;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Class for serializing/deserializing XChainBridges
|
|
16
|
-
*/
|
|
17
|
-
declare class XChainBridge extends SerializedType {
|
|
18
|
-
static readonly ZERO_XCHAIN_BRIDGE: XChainBridge;
|
|
19
|
-
static readonly TYPE_ORDER: {
|
|
20
|
-
name: string;
|
|
21
|
-
type: typeof SerializedType;
|
|
22
|
-
}[];
|
|
23
|
-
constructor(bytes: Buffer);
|
|
24
|
-
/**
|
|
25
|
-
* Construct a cross-chain bridge from a JSON
|
|
26
|
-
*
|
|
27
|
-
* @param value XChainBridge or JSON to parse into a XChainBridge
|
|
28
|
-
* @returns A XChainBridge object
|
|
29
|
-
*/
|
|
30
|
-
static from<T extends XChainBridge | XChainBridgeObject>(value: T): XChainBridge;
|
|
31
|
-
/**
|
|
32
|
-
* Read a XChainBridge from a BinaryParser
|
|
33
|
-
*
|
|
34
|
-
* @param parser BinaryParser to read the XChainBridge from
|
|
35
|
-
* @returns A XChainBridge object
|
|
36
|
-
*/
|
|
37
|
-
static fromParser(parser: BinaryParser): XChainBridge;
|
|
38
|
-
/**
|
|
39
|
-
* Get the JSON representation of this XChainBridge
|
|
40
|
-
*
|
|
41
|
-
* @returns the JSON interpretation of this.bytes
|
|
42
|
-
*/
|
|
43
|
-
toJSON(): XChainBridgeObject;
|
|
44
|
-
}
|
|
45
|
-
export { XChainBridge, XChainBridgeObject };
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.XChainBridge = void 0;
|
|
4
|
-
const binary_parser_1 = require("../serdes/binary-parser");
|
|
5
|
-
const account_id_1 = require("./account-id");
|
|
6
|
-
const serialized_type_1 = require("./serialized-type");
|
|
7
|
-
const buffer_1 = require("buffer/");
|
|
8
|
-
const issue_1 = require("./issue");
|
|
9
|
-
/**
|
|
10
|
-
* Type guard for XChainBridgeObject
|
|
11
|
-
*/
|
|
12
|
-
function isXChainBridgeObject(arg) {
|
|
13
|
-
const keys = Object.keys(arg).sort();
|
|
14
|
-
return (keys.length === 4 &&
|
|
15
|
-
keys[0] === 'IssuingChainDoor' &&
|
|
16
|
-
keys[1] === 'IssuingChainIssue' &&
|
|
17
|
-
keys[2] === 'LockingChainDoor' &&
|
|
18
|
-
keys[3] === 'LockingChainIssue');
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Class for serializing/deserializing XChainBridges
|
|
22
|
-
*/
|
|
23
|
-
class XChainBridge extends serialized_type_1.SerializedType {
|
|
24
|
-
constructor(bytes) {
|
|
25
|
-
super(bytes !== null && bytes !== void 0 ? bytes : XChainBridge.ZERO_XCHAIN_BRIDGE.bytes);
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Construct a cross-chain bridge from a JSON
|
|
29
|
-
*
|
|
30
|
-
* @param value XChainBridge or JSON to parse into a XChainBridge
|
|
31
|
-
* @returns A XChainBridge object
|
|
32
|
-
*/
|
|
33
|
-
static from(value) {
|
|
34
|
-
if (value instanceof XChainBridge) {
|
|
35
|
-
return value;
|
|
36
|
-
}
|
|
37
|
-
if (isXChainBridgeObject(value)) {
|
|
38
|
-
const bytes = [];
|
|
39
|
-
this.TYPE_ORDER.forEach((item) => {
|
|
40
|
-
const { name, type } = item;
|
|
41
|
-
if (type === account_id_1.AccountID) {
|
|
42
|
-
bytes.push(buffer_1.Buffer.from([0x14]));
|
|
43
|
-
}
|
|
44
|
-
const object = type.from(value[name]);
|
|
45
|
-
bytes.push(object.toBytes());
|
|
46
|
-
});
|
|
47
|
-
return new XChainBridge(buffer_1.Buffer.concat(bytes));
|
|
48
|
-
}
|
|
49
|
-
throw new Error('Invalid type to construct a XChainBridge');
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Read a XChainBridge from a BinaryParser
|
|
53
|
-
*
|
|
54
|
-
* @param parser BinaryParser to read the XChainBridge from
|
|
55
|
-
* @returns A XChainBridge object
|
|
56
|
-
*/
|
|
57
|
-
static fromParser(parser) {
|
|
58
|
-
const bytes = [];
|
|
59
|
-
this.TYPE_ORDER.forEach((item) => {
|
|
60
|
-
const { type } = item;
|
|
61
|
-
if (type === account_id_1.AccountID) {
|
|
62
|
-
parser.skip(1);
|
|
63
|
-
bytes.push(buffer_1.Buffer.from([0x14]));
|
|
64
|
-
}
|
|
65
|
-
const object = type.fromParser(parser);
|
|
66
|
-
bytes.push(object.toBytes());
|
|
67
|
-
});
|
|
68
|
-
return new XChainBridge(buffer_1.Buffer.concat(bytes));
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Get the JSON representation of this XChainBridge
|
|
72
|
-
*
|
|
73
|
-
* @returns the JSON interpretation of this.bytes
|
|
74
|
-
*/
|
|
75
|
-
toJSON() {
|
|
76
|
-
const parser = new binary_parser_1.BinaryParser(this.toString());
|
|
77
|
-
const json = {};
|
|
78
|
-
XChainBridge.TYPE_ORDER.forEach((item) => {
|
|
79
|
-
const { name, type } = item;
|
|
80
|
-
if (type === account_id_1.AccountID) {
|
|
81
|
-
parser.skip(1);
|
|
82
|
-
}
|
|
83
|
-
const object = type.fromParser(parser).toJSON();
|
|
84
|
-
json[name] = object;
|
|
85
|
-
});
|
|
86
|
-
return json;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
exports.XChainBridge = XChainBridge;
|
|
90
|
-
XChainBridge.ZERO_XCHAIN_BRIDGE = new XChainBridge(buffer_1.Buffer.concat([
|
|
91
|
-
buffer_1.Buffer.from([0x14]),
|
|
92
|
-
buffer_1.Buffer.alloc(40),
|
|
93
|
-
buffer_1.Buffer.from([0x14]),
|
|
94
|
-
buffer_1.Buffer.alloc(40),
|
|
95
|
-
]));
|
|
96
|
-
XChainBridge.TYPE_ORDER = [
|
|
97
|
-
{ name: 'LockingChainDoor', type: account_id_1.AccountID },
|
|
98
|
-
{ name: 'LockingChainIssue', type: issue_1.Issue },
|
|
99
|
-
{ name: 'IssuingChainDoor', type: account_id_1.AccountID },
|
|
100
|
-
{ name: 'IssuingChainIssue', type: issue_1.Issue },
|
|
101
|
-
];
|
|
102
|
-
//# sourceMappingURL=xchain-bridge.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"xchain-bridge.js","sourceRoot":"","sources":["../../src/types/xchain-bridge.ts"],"names":[],"mappings":";;;AAAA,2DAAsD;AAEtD,6CAAwC;AACxC,uDAA8D;AAC9D,oCAAgC;AAChC,mCAA4C;AAY5C;;GAEG;AACH,SAAS,oBAAoB,CAAC,GAAG;IAC/B,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAA;IACpC,OAAO,CACL,IAAI,CAAC,MAAM,KAAK,CAAC;QACjB,IAAI,CAAC,CAAC,CAAC,KAAK,kBAAkB;QAC9B,IAAI,CAAC,CAAC,CAAC,KAAK,mBAAmB;QAC/B,IAAI,CAAC,CAAC,CAAC,KAAK,kBAAkB;QAC9B,IAAI,CAAC,CAAC,CAAC,KAAK,mBAAmB,CAChC,CAAA;AACH,CAAC;AAED;;GAEG;AACH,MAAM,YAAa,SAAQ,gCAAc;IAkBvC,YAAY,KAAa;QACvB,KAAK,CAAC,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,YAAY,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAA;IACvD,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,IAAI,CACT,KAAQ;QAER,IAAI,KAAK,YAAY,YAAY,EAAE;YACjC,OAAO,KAAK,CAAA;SACb;QAED,IAAI,oBAAoB,CAAC,KAAK,CAAC,EAAE;YAC/B,MAAM,KAAK,GAAkB,EAAE,CAAA;YAC/B,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;gBAC/B,MAAM,EAAE,I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