ripple-binary-codec 2.0.0-beta.0 → 2.0.0
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 +12 -13
- package/dist/binary.js +6 -5
- package/dist/binary.js.map +1 -1
- package/dist/enums/bytes.d.ts +1 -2
- package/dist/enums/bytes.js +1 -2
- package/dist/enums/bytes.js.map +1 -1
- package/dist/enums/definitions.json +36 -11
- package/dist/enums/field.d.ts +1 -2
- package/dist/enums/field.js +1 -2
- package/dist/enums/field.js.map +1 -1
- package/dist/enums/index.js +4 -24
- package/dist/enums/index.js.map +1 -1
- package/dist/enums/src/enums/definitions.json +36 -11
- package/dist/hash-prefixes.d.ts +1 -2
- package/dist/hash-prefixes.js +6 -6
- package/dist/hash-prefixes.js.map +1 -1
- package/dist/hashes.d.ts +5 -6
- package/dist/hashes.js +1 -2
- package/dist/hashes.js.map +1 -1
- package/dist/index.js +7 -14
- package/dist/index.js.map +1 -1
- package/dist/quality.d.ts +1 -2
- package/dist/quality.js +3 -3
- package/dist/quality.js.map +1 -1
- package/dist/serdes/binary-parser.d.ts +2 -3
- package/dist/serdes/binary-parser.js +2 -2
- package/dist/serdes/binary-parser.js.map +1 -1
- package/dist/serdes/binary-serializer.d.ts +6 -7
- package/dist/serdes/binary-serializer.js +9 -9
- package/dist/serdes/binary-serializer.js.map +1 -1
- package/dist/shamap.d.ts +4 -5
- package/dist/shamap.js +2 -3
- package/dist/shamap.js.map +1 -1
- package/dist/src/binary.d.ts +90 -0
- package/dist/src/binary.js +128 -0
- package/dist/src/binary.js.map +1 -0
- package/dist/src/coretypes.d.ts +9 -0
- package/dist/src/coretypes.js +48 -0
- package/dist/src/coretypes.js.map +1 -0
- package/dist/src/enums/bytes.d.ts +25 -0
- package/dist/src/enums/bytes.js +63 -0
- package/dist/src/enums/bytes.js.map +1 -0
- package/dist/src/enums/constants.d.ts +4 -0
- package/dist/src/enums/constants.js +8 -0
- package/dist/src/enums/constants.js.map +1 -0
- package/dist/src/enums/definitions.json +2866 -0
- package/dist/src/enums/field.d.ts +28 -0
- package/dist/src/enums/field.js +58 -0
- package/dist/src/enums/field.js.map +1 -0
- package/dist/src/enums/index.d.ts +12 -0
- package/dist/src/enums/index.js +31 -0
- package/dist/src/enums/index.js.map +1 -0
- package/dist/src/enums/utils-renumber.d.ts +101 -0
- package/dist/src/enums/utils-renumber.js +127 -0
- package/dist/src/enums/utils-renumber.js.map +1 -0
- package/dist/src/enums/xrpl-definitions-base.d.ts +44 -0
- package/dist/src/enums/xrpl-definitions-base.js +59 -0
- package/dist/src/enums/xrpl-definitions-base.js.map +1 -0
- package/dist/src/enums/xrpl-definitions.d.ts +21 -0
- package/dist/src/enums/xrpl-definitions.js +29 -0
- package/dist/src/enums/xrpl-definitions.js.map +1 -0
- package/dist/src/hash-prefixes.d.ts +5 -0
- package/dist/src/hash-prefixes.js +41 -0
- package/dist/src/hash-prefixes.js.map +1 -0
- package/dist/src/hashes.d.ts +50 -0
- package/dist/src/hashes.js +76 -0
- package/dist/src/hashes.js.map +1 -0
- package/dist/src/index.d.ts +64 -0
- package/dist/src/index.js +123 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/ledger-hashes.d.ts +48 -0
- package/dist/src/ledger-hashes.js +141 -0
- package/dist/src/ledger-hashes.js.map +1 -0
- package/dist/src/quality.d.ts +21 -0
- package/dist/src/quality.js +42 -0
- package/dist/src/quality.js.map +1 -0
- package/dist/src/serdes/binary-parser.d.ts +100 -0
- package/dist/src/serdes/binary-parser.js +194 -0
- package/dist/src/serdes/binary-parser.js.map +1 -0
- package/dist/src/serdes/binary-serializer.d.ts +81 -0
- package/dist/src/serdes/binary-serializer.js +149 -0
- package/dist/src/serdes/binary-serializer.js.map +1 -0
- package/dist/src/shamap.d.ts +102 -0
- package/dist/src/shamap.js +172 -0
- package/dist/src/shamap.js.map +1 -0
- package/dist/src/types/account-id.d.ts +35 -0
- package/dist/src/types/account-id.js +69 -0
- package/dist/src/types/account-id.js.map +1 -0
- package/dist/src/types/amount.d.ts +67 -0
- package/dist/src/types/amount.js +212 -0
- package/dist/src/types/amount.js.map +1 -0
- package/dist/src/types/blob.d.ts +24 -0
- package/dist/src/types/blob.js +40 -0
- package/dist/src/types/blob.js.map +1 -0
- package/dist/src/types/currency.d.ts +28 -0
- package/dist/src/types/currency.js +127 -0
- package/dist/src/types/currency.js.map +1 -0
- package/dist/src/types/hash-128.d.ts +16 -0
- package/dist/src/types/hash-128.js +32 -0
- package/dist/src/types/hash-128.js.map +1 -0
- package/dist/src/types/hash-160.d.ts +10 -0
- package/dist/src/types/hash-160.js +19 -0
- package/dist/src/types/hash-160.js.map +1 -0
- package/dist/src/types/hash-256.d.ts +10 -0
- package/dist/src/types/hash-256.js +16 -0
- package/dist/src/types/hash-256.js.map +1 -0
- package/dist/src/types/hash.d.ts +40 -0
- package/dist/src/types/hash.js +73 -0
- package/dist/src/types/hash.js.map +1 -0
- package/dist/src/types/index.d.ts +18 -0
- package/dist/src/types/index.js +61 -0
- package/dist/src/types/index.js.map +1 -0
- package/dist/src/types/issue.d.ts +38 -0
- package/dist/src/types/issue.js +81 -0
- package/dist/src/types/issue.js.map +1 -0
- package/dist/src/types/path-set.d.ts +36 -0
- package/dist/src/types/path-set.js +233 -0
- package/dist/src/types/path-set.js.map +1 -0
- package/dist/src/types/serialized-type.d.ts +70 -0
- package/dist/src/types/serialized-type.js +105 -0
- package/dist/src/types/serialized-type.js.map +1 -0
- package/dist/src/types/st-array.d.ts +31 -0
- package/dist/src/types/st-array.js +83 -0
- package/dist/src/types/st-array.js.map +1 -0
- package/dist/src/types/st-object.d.ts +32 -0
- package/dist/src/types/st-object.js +155 -0
- package/dist/src/types/st-object.js.map +1 -0
- package/dist/src/types/uint-16.d.ts +24 -0
- package/dist/src/types/uint-16.js +45 -0
- package/dist/src/types/uint-16.js.map +1 -0
- package/dist/src/types/uint-32.d.ts +24 -0
- package/dist/src/types/uint-32.js +50 -0
- package/dist/src/types/uint-32.js.map +1 -0
- package/dist/src/types/uint-64.d.ts +37 -0
- package/dist/src/types/uint-64.js +86 -0
- package/dist/src/types/uint-64.js.map +1 -0
- package/dist/src/types/uint-8.d.ts +24 -0
- package/dist/src/types/uint-8.js +46 -0
- package/dist/src/types/uint-8.js.map +1 -0
- package/dist/src/types/uint.d.ts +29 -0
- package/dist/src/types/uint.js +47 -0
- package/dist/src/types/uint.js.map +1 -0
- package/dist/src/types/vector-256.d.ts +30 -0
- package/dist/src/types/vector-256.js +73 -0
- package/dist/src/types/vector-256.js.map +1 -0
- package/dist/src/types/xchain-bridge.d.ts +44 -0
- package/dist/src/types/xchain-bridge.js +102 -0
- package/dist/src/types/xchain-bridge.js.map +1 -0
- package/dist/src/utils.d.ts +47 -0
- package/dist/src/utils.js +137 -0
- package/dist/src/utils.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types/account-id.d.ts +1 -2
- package/dist/types/account-id.js +4 -6
- package/dist/types/account-id.js.map +1 -1
- package/dist/types/amount.d.ts +1 -2
- package/dist/types/amount.js +16 -15
- package/dist/types/amount.js.map +1 -1
- package/dist/types/blob.d.ts +1 -2
- package/dist/types/blob.js +2 -2
- package/dist/types/blob.js.map +1 -1
- package/dist/types/currency.d.ts +1 -2
- package/dist/types/currency.js +10 -10
- package/dist/types/currency.js.map +1 -1
- package/dist/types/hash-128.d.ts +1 -2
- package/dist/types/hash-128.js +3 -3
- package/dist/types/hash-128.js.map +1 -1
- package/dist/types/hash-160.d.ts +1 -2
- package/dist/types/hash-160.js +1 -2
- package/dist/types/hash-160.js.map +1 -1
- package/dist/types/hash-256.d.ts +1 -2
- package/dist/types/hash-256.js +1 -2
- package/dist/types/hash-256.js.map +1 -1
- package/dist/types/hash.d.ts +2 -3
- package/dist/types/hash.js +5 -4
- package/dist/types/hash.js.map +1 -1
- package/dist/types/issue.d.ts +1 -2
- package/dist/types/issue.js +4 -4
- package/dist/types/issue.js.map +1 -1
- package/dist/types/path-set.js +12 -12
- package/dist/types/path-set.js.map +1 -1
- package/dist/types/serialized-type.d.ts +17 -13
- package/dist/types/serialized-type.js +11 -6
- package/dist/types/serialized-type.js.map +1 -1
- package/dist/types/st-array.js +5 -5
- package/dist/types/st-array.js.map +1 -1
- package/dist/types/st-object.js +1 -2
- package/dist/types/st-object.js.map +1 -1
- package/dist/types/uint-16.d.ts +1 -2
- package/dist/types/uint-16.js +6 -5
- package/dist/types/uint-16.js.map +1 -1
- package/dist/types/uint-32.d.ts +1 -2
- package/dist/types/uint-32.js +7 -6
- package/dist/types/uint-32.js.map +1 -1
- package/dist/types/uint-64.d.ts +2 -3
- package/dist/types/uint-64.js +16 -15
- package/dist/types/uint-64.js.map +1 -1
- package/dist/types/uint-8.d.ts +1 -2
- package/dist/types/uint-8.js +7 -5
- package/dist/types/uint-8.js.map +1 -1
- package/dist/types/uint.d.ts +4 -4
- package/dist/types/uint.js +5 -0
- package/dist/types/uint.js.map +1 -1
- package/dist/types/vector-256.d.ts +1 -2
- package/dist/types/vector-256.js +2 -4
- package/dist/types/vector-256.js.map +1 -1
- package/dist/types/xchain-bridge.d.ts +1 -2
- package/dist/types/xchain-bridge.js +20 -20
- package/dist/types/xchain-bridge.js.map +1 -1
- package/dist/utils.d.ts +47 -0
- package/dist/utils.js +137 -0
- package/dist/utils.js.map +1 -0
- package/package.json +8 -11
- package/src/README.md +3 -1
- package/src/binary.ts +21 -14
- package/src/enums/bytes.ts +2 -3
- package/src/enums/definitions.json +36 -11
- package/src/enums/field.ts +3 -4
- package/src/enums/index.ts +1 -1
- package/src/hash-prefixes.ts +8 -8
- package/src/hashes.ts +6 -7
- package/src/index.ts +12 -15
- package/src/quality.ts +4 -4
- package/src/serdes/binary-parser.ts +5 -5
- package/src/serdes/binary-serializer.ts +14 -14
- package/src/shamap.ts +5 -6
- package/src/types/account-id.ts +8 -8
- package/src/types/amount.ts +17 -18
- package/src/types/blob.ts +3 -3
- package/src/types/currency.ts +16 -16
- package/src/types/hash-128.ts +4 -4
- package/src/types/hash-160.ts +2 -3
- package/src/types/hash-256.ts +2 -3
- package/src/types/hash.ts +8 -6
- package/src/types/issue.ts +5 -5
- package/src/types/path-set.ts +16 -16
- package/src/types/serialized-type.ts +20 -15
- package/src/types/st-array.ts +7 -7
- package/src/types/st-object.ts +2 -2
- package/src/types/uint-16.ts +10 -6
- package/src/types/uint-32.ts +10 -7
- package/src/types/uint-64.ts +20 -17
- package/src/types/uint-8.ts +9 -6
- package/src/types/uint.ts +11 -4
- package/src/types/vector-256.ts +3 -8
- package/src/types/xchain-bridge.ts +22 -22
- package/src/utils.ts +152 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vector-256.js","sourceRoot":"","sources":["../../src/types/vector-256.ts"],"names":[],"mappings":";;;AAAA,uDAAkD;AAElD,yCAAoC;AACpC,mEAAuD;
|
|
1
|
+
{"version":3,"file":"vector-256.js","sourceRoot":"","sources":["../../src/types/vector-256.ts"],"names":[],"mappings":";;;AAAA,uDAAkD;AAElD,yCAAoC;AACpC,mEAAuD;AACvD,mDAAoD;AAEpD;;GAEG;AACH,SAAS,SAAS,CAAC,GAAG;IACpB,OAAO,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,KAAK,CAAC,IAAI,OAAO,GAAG,CAAC,CAAC,CAAC,KAAK,QAAQ,CAAC,CAAA;AAC/E,CAAC;AAED;;GAEG;AACH,MAAM,SAAU,SAAQ,gCAAc;IACpC,YAAY,KAAiB;QAC3B,KAAK,CAAC,KAAK,CAAC,CAAA;IACd,CAAC;IAED;;;;;;OAMG;IACH,MAAM,CAAC,UAAU,CAAC,MAAoB,EAAE,IAAa;QACnD,MAAM,SAAS,GAAG,IAAI,6BAAS,EAAE,CAAA;QACjC,MAAM,KAAK,GAAG,IAAI,aAAJ,IAAI,cAAJ,IAAI,GAAI,MAAM,CAAC,IAAI,EAAE,CAAA;QACnC,MAAM,MAAM,GAAG,KAAK,GAAG,EAAE,C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ACf,CAAC;CACF;AAEQ,8BAAS"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { BinaryParser } from '../serdes/binary-parser';
|
|
2
2
|
import { JsonObject, SerializedType } from './serialized-type';
|
|
3
|
-
import { Buffer } from 'buffer/';
|
|
4
3
|
import { IssueObject } from './issue';
|
|
5
4
|
/**
|
|
6
5
|
* Interface for JSON objects that represent cross-chain bridges
|
|
@@ -20,7 +19,7 @@ declare class XChainBridge extends SerializedType {
|
|
|
20
19
|
name: string;
|
|
21
20
|
type: typeof SerializedType;
|
|
22
21
|
}[];
|
|
23
|
-
constructor(bytes:
|
|
22
|
+
constructor(bytes: Uint8Array);
|
|
24
23
|
/**
|
|
25
24
|
* Construct a cross-chain bridge from a JSON
|
|
26
25
|
*
|
|
@@ -4,8 +4,8 @@ exports.XChainBridge = void 0;
|
|
|
4
4
|
const binary_parser_1 = require("../serdes/binary-parser");
|
|
5
5
|
const account_id_1 = require("./account-id");
|
|
6
6
|
const serialized_type_1 = require("./serialized-type");
|
|
7
|
-
const buffer_1 = require("buffer/");
|
|
8
7
|
const issue_1 = require("./issue");
|
|
8
|
+
const utils_1 = require("@xrplf/isomorphic/utils");
|
|
9
9
|
/**
|
|
10
10
|
* Type guard for XChainBridgeObject
|
|
11
11
|
*/
|
|
@@ -34,19 +34,19 @@ class XChainBridge extends serialized_type_1.SerializedType {
|
|
|
34
34
|
if (value instanceof XChainBridge) {
|
|
35
35
|
return value;
|
|
36
36
|
}
|
|
37
|
-
if (isXChainBridgeObject(value)) {
|
|
38
|
-
|
|
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));
|
|
37
|
+
if (!isXChainBridgeObject(value)) {
|
|
38
|
+
throw new Error('Invalid type to construct an XChainBridge');
|
|
48
39
|
}
|
|
49
|
-
|
|
40
|
+
const bytes = [];
|
|
41
|
+
this.TYPE_ORDER.forEach((item) => {
|
|
42
|
+
const { name, type } = item;
|
|
43
|
+
if (type === account_id_1.AccountID) {
|
|
44
|
+
bytes.push(Uint8Array.from([0x14]));
|
|
45
|
+
}
|
|
46
|
+
const object = type.from(value[name]);
|
|
47
|
+
bytes.push(object.toBytes());
|
|
48
|
+
});
|
|
49
|
+
return new XChainBridge((0, utils_1.concat)(bytes));
|
|
50
50
|
}
|
|
51
51
|
/**
|
|
52
52
|
* Read an XChainBridge from a BinaryParser
|
|
@@ -60,12 +60,12 @@ class XChainBridge extends serialized_type_1.SerializedType {
|
|
|
60
60
|
const { type } = item;
|
|
61
61
|
if (type === account_id_1.AccountID) {
|
|
62
62
|
parser.skip(1);
|
|
63
|
-
bytes.push(
|
|
63
|
+
bytes.push(Uint8Array.from([0x14]));
|
|
64
64
|
}
|
|
65
65
|
const object = type.fromParser(parser);
|
|
66
66
|
bytes.push(object.toBytes());
|
|
67
67
|
});
|
|
68
|
-
return new XChainBridge(
|
|
68
|
+
return new XChainBridge((0, utils_1.concat)(bytes));
|
|
69
69
|
}
|
|
70
70
|
/**
|
|
71
71
|
* Get the JSON representation of this XChainBridge
|
|
@@ -87,11 +87,11 @@ class XChainBridge extends serialized_type_1.SerializedType {
|
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
89
|
exports.XChainBridge = XChainBridge;
|
|
90
|
-
XChainBridge.ZERO_XCHAIN_BRIDGE = new XChainBridge(
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
90
|
+
XChainBridge.ZERO_XCHAIN_BRIDGE = new XChainBridge((0, utils_1.concat)([
|
|
91
|
+
Uint8Array.from([0x14]),
|
|
92
|
+
new Uint8Array(40),
|
|
93
|
+
Uint8Array.from([0x14]),
|
|
94
|
+
new Uint8Array(40),
|
|
95
95
|
]));
|
|
96
96
|
XChainBridge.TYPE_ORDER = [
|
|
97
97
|
{ name: 'LockingChainDoor', type: account_id_1.AccountID },
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"xchain-bridge.js","sourceRoot":"","sources":["../../src/types/xchain-bridge.ts"],"names":[],"mappings":";;;AAAA,2DAAsD;AAEtD,6CAAwC;AACxC,uDAA8D;AAC9D,
|
|
1
|
+
{"version":3,"file":"xchain-bridge.js","sourceRoot":"","sources":["../../src/types/xchain-bridge.ts"],"names":[],"mappings":";;;AAAA,2DAAsD;AAEtD,6CAAwC;AACxC,uDAA8D;AAC9D,mCAA4C;AAC5C,mDAAgD;AAYhD;;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,KAAiB;QAC3B,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,CAAC,oBAAoB,CAAC,KAAK,CAAC,EAAE;YAChC,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAA;SAC7D;QAED,MAAM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4BAAY,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAA;QAChD,MAAM,IAAI,GAAG,EAAE,CAAA;QACf,YAAY,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;YACvC,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,IAAI,CAAA;YAC3B,IAAI,IAAI,KAAK,sBAAS,EAAE;gBACtB,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;aACf;YACD,MAAM,MAAM,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,CAAA;YAC/C,IAAI,CAAC,IAAI,CAAC,GAAG,MAAM,CAAA;QACrB,CAAC,CAAC,CAAA;QACF,OAAO,IAA0B,CAAA;IACnC,CAAC;;AAGM,oCAAY;AA5FH,+BAAkB,GAAiB,IAAI,YAAY,CACjE,IAAA,cAAM,EAAC;IACL,UAAU,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC;IACvB,IAAI,UAAU,CAAC,EAAE,CAAC;IAClB,UAAU,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC;IACvB,IAAI,UAAU,CAAC,EAAE,CAAC;CACnB,CAAC,CACH,CAAA;AAEe,uBAAU,GACxB;IACE,EAAE,IAAI,EAAE,kBAAkB,EAAE,IAAI,EAAE,sBAAS,EAAE;IAC7C,EAAE,IAAI,EAAE,mBAAmB,EAAE,IAAI,EAAE,aAAK,EAAE;IAC1C,EAAE,IAAI,EAAE,kBAAkB,EAAE,IAAI,EAAE,sBAAS,EAAE;IAC7C,EAAE,IAAI,EAAE,mBAAmB,EAAE,IAAI,EAAE,aAAK,EAAE;CAC3C,CAAA"}
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import TypedArray = NodeJS.TypedArray;
|
|
3
|
+
/**
|
|
4
|
+
* Writes value to array at the specified offset. The value must be a valid unsigned 8-bit integer.
|
|
5
|
+
* @param array Uint8Array to be written to
|
|
6
|
+
* @param value Number to be written to array.
|
|
7
|
+
* @param offset plus the number of bytes written.
|
|
8
|
+
*/
|
|
9
|
+
export declare function writeUInt8(array: Uint8Array, value: number, offset: number): void;
|
|
10
|
+
/**
|
|
11
|
+
* Writes value to array at the specified offset as big-endian. The value must be a valid unsigned 16-bit integer.
|
|
12
|
+
* @param array Uint8Array to be written to
|
|
13
|
+
* @param value Number to be written to array.
|
|
14
|
+
* @param offset plus the number of bytes written.
|
|
15
|
+
*/
|
|
16
|
+
export declare function writeUInt16BE(array: Uint8Array, value: number, offset: number): void;
|
|
17
|
+
/**
|
|
18
|
+
* Writes value to array at the specified offset as big-endian. The value must be a valid unsigned 32-bit integer.
|
|
19
|
+
* @param array Uint8Array to be written to
|
|
20
|
+
* @param value Number to be written to array.
|
|
21
|
+
* @param offset plus the number of bytes written.
|
|
22
|
+
*/
|
|
23
|
+
export declare function writeUInt32BE(array: Uint8Array, value: number, offset: number): void;
|
|
24
|
+
/**
|
|
25
|
+
* Reads an unsigned, big-endian 16-bit integer from the array at the specified offset.
|
|
26
|
+
* @param array Uint8Array to read
|
|
27
|
+
* @param offset Number of bytes to skip before starting to read. Must satisfy 0 <= offset <= buf.length - 2
|
|
28
|
+
*/
|
|
29
|
+
export declare function readUInt16BE(array: Uint8Array, offset: number): string;
|
|
30
|
+
/**
|
|
31
|
+
* Reads an unsigned, big-endian 16-bit integer from the array at the specified offset.
|
|
32
|
+
* @param array Uint8Array to read
|
|
33
|
+
* @param offset Number of bytes to skip before starting to read. Must satisfy 0 <= offset <= buf.length - 4
|
|
34
|
+
*/
|
|
35
|
+
export declare function readUInt32BE(array: Uint8Array, offset: number): string;
|
|
36
|
+
/**
|
|
37
|
+
* Compares two Uint8Array or ArrayBuffers
|
|
38
|
+
* @param a first array to compare
|
|
39
|
+
* @param b second array to compare
|
|
40
|
+
*/
|
|
41
|
+
export declare function equal(a: Uint8Array | ArrayBuffer, b: Uint8Array | ArrayBuffer): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Compare two TypedArrays
|
|
44
|
+
* @param a first array to compare
|
|
45
|
+
* @param b second array to compare
|
|
46
|
+
*/
|
|
47
|
+
export declare function compare(a: TypedArray, b: TypedArray): 1 | -1 | 0;
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.compare = exports.equal = exports.readUInt32BE = exports.readUInt16BE = exports.writeUInt32BE = exports.writeUInt16BE = exports.writeUInt8 = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Writes value to array at the specified offset. The value must be a valid unsigned 8-bit integer.
|
|
6
|
+
* @param array Uint8Array to be written to
|
|
7
|
+
* @param value Number to be written to array.
|
|
8
|
+
* @param offset plus the number of bytes written.
|
|
9
|
+
*/
|
|
10
|
+
function writeUInt8(array, value, offset) {
|
|
11
|
+
value = Number(value);
|
|
12
|
+
array[offset] = value;
|
|
13
|
+
}
|
|
14
|
+
exports.writeUInt8 = writeUInt8;
|
|
15
|
+
/**
|
|
16
|
+
* Writes value to array at the specified offset as big-endian. The value must be a valid unsigned 16-bit integer.
|
|
17
|
+
* @param array Uint8Array to be written to
|
|
18
|
+
* @param value Number to be written to array.
|
|
19
|
+
* @param offset plus the number of bytes written.
|
|
20
|
+
*/
|
|
21
|
+
function writeUInt16BE(array, value, offset) {
|
|
22
|
+
value = Number(value);
|
|
23
|
+
array[offset] = value >>> 8;
|
|
24
|
+
array[offset + 1] = value;
|
|
25
|
+
}
|
|
26
|
+
exports.writeUInt16BE = writeUInt16BE;
|
|
27
|
+
/**
|
|
28
|
+
* Writes value to array at the specified offset as big-endian. The value must be a valid unsigned 32-bit integer.
|
|
29
|
+
* @param array Uint8Array to be written to
|
|
30
|
+
* @param value Number to be written to array.
|
|
31
|
+
* @param offset plus the number of bytes written.
|
|
32
|
+
*/
|
|
33
|
+
function writeUInt32BE(array, value, offset) {
|
|
34
|
+
array[offset] = (value >>> 24) & 0xff;
|
|
35
|
+
array[offset + 1] = (value >>> 16) & 0xff;
|
|
36
|
+
array[offset + 2] = (value >>> 8) & 0xff;
|
|
37
|
+
array[offset + 3] = value & 0xff;
|
|
38
|
+
}
|
|
39
|
+
exports.writeUInt32BE = writeUInt32BE;
|
|
40
|
+
/**
|
|
41
|
+
* Reads an unsigned, big-endian 16-bit integer from the array at the specified offset.
|
|
42
|
+
* @param array Uint8Array to read
|
|
43
|
+
* @param offset Number of bytes to skip before starting to read. Must satisfy 0 <= offset <= buf.length - 2
|
|
44
|
+
*/
|
|
45
|
+
function readUInt16BE(array, offset) {
|
|
46
|
+
return new DataView(array.buffer).getUint16(offset, false).toString(10);
|
|
47
|
+
}
|
|
48
|
+
exports.readUInt16BE = readUInt16BE;
|
|
49
|
+
/**
|
|
50
|
+
* Reads an unsigned, big-endian 16-bit integer from the array at the specified offset.
|
|
51
|
+
* @param array Uint8Array to read
|
|
52
|
+
* @param offset Number of bytes to skip before starting to read. Must satisfy 0 <= offset <= buf.length - 4
|
|
53
|
+
*/
|
|
54
|
+
function readUInt32BE(array, offset) {
|
|
55
|
+
return new DataView(array.buffer).getUint32(offset, false).toString(10);
|
|
56
|
+
}
|
|
57
|
+
exports.readUInt32BE = readUInt32BE;
|
|
58
|
+
/**
|
|
59
|
+
* Compares two Uint8Array or ArrayBuffers
|
|
60
|
+
* @param a first array to compare
|
|
61
|
+
* @param b second array to compare
|
|
62
|
+
*/
|
|
63
|
+
function equal(a, b) {
|
|
64
|
+
const aUInt = a instanceof ArrayBuffer ? new Uint8Array(a, 0) : a;
|
|
65
|
+
const bUInt = b instanceof ArrayBuffer ? new Uint8Array(b, 0) : b;
|
|
66
|
+
if (aUInt.byteLength != bUInt.byteLength)
|
|
67
|
+
return false;
|
|
68
|
+
if (aligned32(aUInt) && aligned32(bUInt))
|
|
69
|
+
return compare32(aUInt, bUInt) === 0;
|
|
70
|
+
if (aligned16(aUInt) && aligned16(bUInt))
|
|
71
|
+
return compare16(aUInt, bUInt) === 0;
|
|
72
|
+
return compare8(aUInt, bUInt) === 0;
|
|
73
|
+
}
|
|
74
|
+
exports.equal = equal;
|
|
75
|
+
/**
|
|
76
|
+
* Compares two 8 bit aligned arrays
|
|
77
|
+
* @param a first array to compare
|
|
78
|
+
* @param b second array to compare
|
|
79
|
+
*/
|
|
80
|
+
function compare8(a, b) {
|
|
81
|
+
const ua = new Uint8Array(a.buffer, a.byteOffset, a.byteLength);
|
|
82
|
+
const ub = new Uint8Array(b.buffer, b.byteOffset, b.byteLength);
|
|
83
|
+
return compare(ua, ub);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Compares two 16 bit aligned arrays
|
|
87
|
+
* @param a first array to compare
|
|
88
|
+
* @param b second array to compare
|
|
89
|
+
*/
|
|
90
|
+
function compare16(a, b) {
|
|
91
|
+
const ua = new Uint16Array(a.buffer, a.byteOffset, a.byteLength / 2);
|
|
92
|
+
const ub = new Uint16Array(b.buffer, b.byteOffset, b.byteLength / 2);
|
|
93
|
+
return compare(ua, ub);
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Compares two 32 bit aligned arrays
|
|
97
|
+
* @param a first array to compare
|
|
98
|
+
* @param b second array to compare
|
|
99
|
+
*/
|
|
100
|
+
function compare32(a, b) {
|
|
101
|
+
const ua = new Uint32Array(a.buffer, a.byteOffset, a.byteLength / 4);
|
|
102
|
+
const ub = new Uint32Array(b.buffer, b.byteOffset, b.byteLength / 4);
|
|
103
|
+
return compare(ua, ub);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Compare two TypedArrays
|
|
107
|
+
* @param a first array to compare
|
|
108
|
+
* @param b second array to compare
|
|
109
|
+
*/
|
|
110
|
+
function compare(a, b) {
|
|
111
|
+
if (a.byteLength !== b.byteLength) {
|
|
112
|
+
throw new Error('Cannot compare arrays of different length');
|
|
113
|
+
}
|
|
114
|
+
for (let i = 0; i < a.length - 1; i += 1) {
|
|
115
|
+
if (a[i] > b[i])
|
|
116
|
+
return 1;
|
|
117
|
+
if (a[i] < b[i])
|
|
118
|
+
return -1;
|
|
119
|
+
}
|
|
120
|
+
return 0;
|
|
121
|
+
}
|
|
122
|
+
exports.compare = compare;
|
|
123
|
+
/**
|
|
124
|
+
* Determine if TypedArray is 16 bit aligned
|
|
125
|
+
* @param array The array to check
|
|
126
|
+
*/
|
|
127
|
+
function aligned16(array) {
|
|
128
|
+
return array.byteOffset % 2 === 0 && array.byteLength % 2 === 0;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Determine if TypedArray is 32 bit aligned
|
|
132
|
+
* @param array The array to check
|
|
133
|
+
*/
|
|
134
|
+
function aligned32(array) {
|
|
135
|
+
return array.byteOffset % 4 === 0 && array.byteLength % 4 === 0;
|
|
136
|
+
}
|
|
137
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AAGA;;;;;GAKG;AACH,SAAgB,UAAU,CACxB,KAAiB,EACjB,KAAa,EACb,MAAc;IAEd,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,CAAA;IACrB,KAAK,CAAC,MAAM,CAAC,GAAG,KAAK,CAAA;AACvB,CAAC;AAPD,gCAOC;AAED;;;;;GAKG;AACH,SAAgB,aAAa,CAC3B,KAAiB,EACjB,KAAa,EACb,MAAc;IAEd,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,CAAA;IAErB,KAAK,CAAC,MAAM,CAAC,GAAG,KAAK,KAAK,CAAC,CAAA;IAC3B,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,KAAK,CAAA;AAC3B,CAAC;AATD,sCASC;AAED;;;;;GAKG;AACH,SAAgB,aAAa,CAC3B,KAAiB,EACjB,KAAa,EACb,MAAc;IAEd,KAAK,CAAC,MAAM,CAAC,GAAG,C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ary codec",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist/*",
|
|
@@ -11,19 +11,16 @@
|
|
|
11
11
|
"test": "test"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@xrplf/isomorphic": "^1.0.0
|
|
14
|
+
"@xrplf/isomorphic": "^1.0.0",
|
|
15
15
|
"bignumber.js": "^9.0.0",
|
|
16
|
-
"
|
|
17
|
-
"ripple-address-codec": "^5.0.0-beta.0"
|
|
18
|
-
},
|
|
19
|
-
"devDependencies": {
|
|
20
|
-
"assert": "^2.0.0"
|
|
16
|
+
"ripple-address-codec": "^5.0.0"
|
|
21
17
|
},
|
|
22
18
|
"scripts": {
|
|
23
|
-
"build": "tsc
|
|
24
|
-
"clean": "rm -rf ./dist ./coverage tsconfig.tsbuildinfo",
|
|
19
|
+
"build": "tsc --build tsconfig.build.json && copyfiles ./src/enums/definitions.json ./dist/enums/",
|
|
20
|
+
"clean": "rm -rf ./dist ./coverage ./test/testCompiledForWeb tsconfig.build.tsbuildinfo",
|
|
25
21
|
"prepublishOnly": "npm test",
|
|
26
|
-
"test": "npm run build && jest --verbose false --silent=false ./test/*.test.
|
|
22
|
+
"test": "npm run build && jest --verbose false --silent=false ./test/*.test.ts",
|
|
23
|
+
"test:browser": "npm run build && karma start ./karma.config.js",
|
|
27
24
|
"lint": "eslint . --ext .ts --ext .test.js"
|
|
28
25
|
},
|
|
29
26
|
"keywords": [
|
|
@@ -46,5 +43,5 @@
|
|
|
46
43
|
"engines": {
|
|
47
44
|
"node": ">= 16"
|
|
48
45
|
},
|
|
49
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "a09084289b2ba61eff2363773379573584e084d1"
|
|
50
47
|
}
|
package/src/README.md
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
# ripple-binary-codec
|
|
2
2
|
|
|
3
|
-
Serialize and deserialize transactions according to the XRP Ledger protocol.
|
|
3
|
+
Serialize and deserialize transactions according to the XRP Ledger protocol.
|
|
4
|
+
|
|
5
|
+
If you'd like to add a new transaction, data type, or generally modify this library, please read the [CONTRIBUTING.md](CONTRIBUTING.md)
|
package/src/binary.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/* eslint-disable func-style */
|
|
2
2
|
|
|
3
|
+
import { bytesToHex } from '@xrplf/isomorphic/utils'
|
|
3
4
|
import { coreTypes } from './types'
|
|
4
5
|
import { BinaryParser } from './serdes/binary-parser'
|
|
5
6
|
import { AccountID } from './types/account-id'
|
|
@@ -13,20 +14,23 @@ import {
|
|
|
13
14
|
} from './enums'
|
|
14
15
|
import { STObject } from './types/st-object'
|
|
15
16
|
import { JsonObject } from './types/serialized-type'
|
|
16
|
-
import { Buffer } from 'buffer/'
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
19
|
* Construct a BinaryParser
|
|
20
20
|
*
|
|
21
|
-
* @param bytes hex-string to construct BinaryParser from
|
|
21
|
+
* @param bytes hex-string or Uint8Array to construct BinaryParser from
|
|
22
22
|
* @param definitions rippled definitions used to parse the values of transaction types and such.
|
|
23
23
|
* Can be customized for sidechains and amendments.
|
|
24
|
-
* @returns
|
|
24
|
+
* @returns BinaryParser
|
|
25
25
|
*/
|
|
26
26
|
const makeParser = (
|
|
27
|
-
bytes: string,
|
|
27
|
+
bytes: string | Uint8Array,
|
|
28
28
|
definitions?: XrplDefinitionsBase,
|
|
29
|
-
): BinaryParser =>
|
|
29
|
+
): BinaryParser =>
|
|
30
|
+
new BinaryParser(
|
|
31
|
+
bytes instanceof Uint8Array ? bytesToHex(bytes) : bytes,
|
|
32
|
+
definitions,
|
|
33
|
+
)
|
|
30
34
|
|
|
31
35
|
/**
|
|
32
36
|
* Parse BinaryParser into JSON
|
|
@@ -61,8 +65,8 @@ const binaryToJSON = (
|
|
|
61
65
|
* @field set signingFieldOnly to true if you want to serialize only signing fields
|
|
62
66
|
*/
|
|
63
67
|
interface OptionObject {
|
|
64
|
-
prefix?:
|
|
65
|
-
suffix?:
|
|
68
|
+
prefix?: Uint8Array
|
|
69
|
+
suffix?: Uint8Array
|
|
66
70
|
signingFieldsOnly?: boolean
|
|
67
71
|
definitions?: XrplDefinitionsBase
|
|
68
72
|
}
|
|
@@ -72,9 +76,12 @@ interface OptionObject {
|
|
|
72
76
|
*
|
|
73
77
|
* @param object JSON object to serialize
|
|
74
78
|
* @param opts options for serializing, including optional prefix, suffix, signingFieldOnly, and definitions
|
|
75
|
-
* @returns A
|
|
79
|
+
* @returns A Uint8Array containing the serialized object
|
|
76
80
|
*/
|
|
77
|
-
function serializeObject(
|
|
81
|
+
function serializeObject(
|
|
82
|
+
object: JsonObject,
|
|
83
|
+
opts: OptionObject = {},
|
|
84
|
+
): Uint8Array {
|
|
78
85
|
const { prefix, suffix, signingFieldsOnly = false, definitions } = opts
|
|
79
86
|
const bytesList = new BytesList()
|
|
80
87
|
|
|
@@ -102,13 +109,13 @@ function serializeObject(object: JsonObject, opts: OptionObject = {}): Buffer {
|
|
|
102
109
|
* @param transaction Transaction to serialize
|
|
103
110
|
* @param prefix Prefix bytes to put before the serialized object
|
|
104
111
|
* @param opts.definitions Custom rippled types to use instead of the default. Used for sidechains and amendments.
|
|
105
|
-
* @returns A
|
|
112
|
+
* @returns A Uint8Array with the serialized object
|
|
106
113
|
*/
|
|
107
114
|
function signingData(
|
|
108
115
|
transaction: JsonObject,
|
|
109
|
-
prefix:
|
|
116
|
+
prefix: Uint8Array = HashPrefix.transactionSig,
|
|
110
117
|
opts: { definitions?: XrplDefinitionsBase } = {},
|
|
111
|
-
):
|
|
118
|
+
): Uint8Array {
|
|
112
119
|
return serializeObject(transaction, {
|
|
113
120
|
prefix,
|
|
114
121
|
signingFieldsOnly: true,
|
|
@@ -131,7 +138,7 @@ interface ClaimObject extends JsonObject {
|
|
|
131
138
|
* @param opts.definitions Custom rippled types to use instead of the default. Used for sidechains and amendments.
|
|
132
139
|
* @returns the serialized object with appropriate prefix
|
|
133
140
|
*/
|
|
134
|
-
function signingClaimData(claim: ClaimObject):
|
|
141
|
+
function signingClaimData(claim: ClaimObject): Uint8Array {
|
|
135
142
|
const num = BigInt(String(claim.amount))
|
|
136
143
|
const prefix = HashPrefix.paymentChannelClaim
|
|
137
144
|
const channel = coreTypes.Hash256.from(claim.channel).toBytes()
|
|
@@ -159,7 +166,7 @@ function multiSigningData(
|
|
|
159
166
|
opts: { definitions: XrplDefinitionsBase } = {
|
|
160
167
|
definitions: DEFAULT_DEFINITIONS,
|
|
161
168
|
},
|
|
162
|
-
):
|
|
169
|
+
): Uint8Array {
|
|
163
170
|
const prefix = HashPrefix.transactionMultiSig
|
|
164
171
|
const suffix = coreTypes.AccountID.from(signingAccount).toBytes()
|
|
165
172
|
return serializeObject(transaction, {
|
package/src/enums/bytes.ts
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
import { BytesList, BinaryParser } from '../binary'
|
|
2
|
-
import { Buffer } from 'buffer/'
|
|
3
2
|
|
|
4
3
|
/*
|
|
5
4
|
* @brief: Bytes, name, and ordinal representing one type, ledger_type, transaction type, or result
|
|
6
5
|
*/
|
|
7
6
|
export class Bytes {
|
|
8
|
-
readonly bytes:
|
|
7
|
+
readonly bytes: Uint8Array
|
|
9
8
|
|
|
10
9
|
constructor(
|
|
11
10
|
readonly name: string,
|
|
12
11
|
readonly ordinal: number,
|
|
13
12
|
readonly ordinalWidth: number,
|
|
14
13
|
) {
|
|
15
|
-
this.bytes =
|
|
14
|
+
this.bytes = new Uint8Array(ordinalWidth)
|
|
16
15
|
for (let i = 0; i < ordinalWidth; i++) {
|
|
17
16
|
this.bytes[ordinalWidth - i - 1] = (ordinal >>> (i * 8)) & 0xff
|
|
18
17
|
}
|
|
@@ -50,6 +50,7 @@
|
|
|
50
50
|
"NFTokenPage": 80,
|
|
51
51
|
"NFTokenOffer": 55,
|
|
52
52
|
"AMM": 121,
|
|
53
|
+
"DID": 73,
|
|
53
54
|
"Any": -3,
|
|
54
55
|
"Child": -2,
|
|
55
56
|
"Nickname": 110,
|
|
@@ -140,40 +141,40 @@
|
|
|
140
141
|
[
|
|
141
142
|
"LedgerEntry",
|
|
142
143
|
{
|
|
143
|
-
"nth":
|
|
144
|
+
"nth": 257,
|
|
144
145
|
"isVLEncoded": false,
|
|
145
146
|
"isSerialized": false,
|
|
146
|
-
"isSigningField":
|
|
147
|
+
"isSigningField": false,
|
|
147
148
|
"type": "LedgerEntry"
|
|
148
149
|
}
|
|
149
150
|
],
|
|
150
151
|
[
|
|
151
152
|
"Transaction",
|
|
152
153
|
{
|
|
153
|
-
"nth":
|
|
154
|
+
"nth": 257,
|
|
154
155
|
"isVLEncoded": false,
|
|
155
156
|
"isSerialized": false,
|
|
156
|
-
"isSigningField":
|
|
157
|
+
"isSigningField": false,
|
|
157
158
|
"type": "Transaction"
|
|
158
159
|
}
|
|
159
160
|
],
|
|
160
161
|
[
|
|
161
162
|
"Validation",
|
|
162
163
|
{
|
|
163
|
-
"nth":
|
|
164
|
+
"nth": 257,
|
|
164
165
|
"isVLEncoded": false,
|
|
165
166
|
"isSerialized": false,
|
|
166
|
-
"isSigningField":
|
|
167
|
+
"isSigningField": false,
|
|
167
168
|
"type": "Validation"
|
|
168
169
|
}
|
|
169
170
|
],
|
|
170
171
|
[
|
|
171
172
|
"Metadata",
|
|
172
173
|
{
|
|
173
|
-
"nth":
|
|
174
|
+
"nth": 257,
|
|
174
175
|
"isVLEncoded": false,
|
|
175
|
-
"isSerialized":
|
|
176
|
-
"isSigningField":
|
|
176
|
+
"isSerialized": false,
|
|
177
|
+
"isSigningField": false,
|
|
177
178
|
"type": "Metadata"
|
|
178
179
|
}
|
|
179
180
|
],
|
|
@@ -1897,6 +1898,26 @@
|
|
|
1897
1898
|
"type": "Blob"
|
|
1898
1899
|
}
|
|
1899
1900
|
],
|
|
1901
|
+
[
|
|
1902
|
+
"DIDDocument",
|
|
1903
|
+
{
|
|
1904
|
+
"nth": 26,
|
|
1905
|
+
"isVLEncoded": true,
|
|
1906
|
+
"isSerialized": true,
|
|
1907
|
+
"isSigningField": true,
|
|
1908
|
+
"type": "Blob"
|
|
1909
|
+
}
|
|
1910
|
+
],
|
|
1911
|
+
[
|
|
1912
|
+
"Data",
|
|
1913
|
+
{
|
|
1914
|
+
"nth": 27,
|
|
1915
|
+
"isVLEncoded": true,
|
|
1916
|
+
"isSerialized": true,
|
|
1917
|
+
"isSigningField": true,
|
|
1918
|
+
"type": "Blob"
|
|
1919
|
+
}
|
|
1920
|
+
],
|
|
1900
1921
|
[
|
|
1901
1922
|
"Account",
|
|
1902
1923
|
{
|
|
@@ -2681,6 +2702,7 @@
|
|
|
2681
2702
|
"temXCHAIN_BRIDGE_NONDOOR_OWNER": -257,
|
|
2682
2703
|
"temXCHAIN_BRIDGE_BAD_MIN_ACCOUNT_CREATE_AMOUNT": -256,
|
|
2683
2704
|
"temXCHAIN_BRIDGE_BAD_REWARD_AMOUNT": -255,
|
|
2705
|
+
"temEMPTY_DID": -254,
|
|
2684
2706
|
|
|
2685
2707
|
"tefFAILURE": -199,
|
|
2686
2708
|
"tefALREADY": -198,
|
|
@@ -2759,7 +2781,7 @@
|
|
|
2759
2781
|
"tecKILLED": 150,
|
|
2760
2782
|
"tecHAS_OBLIGATIONS": 151,
|
|
2761
2783
|
"tecTOO_SOON": 152,
|
|
2762
|
-
"
|
|
2784
|
+
"tecHOOK_REJECTED": 153,
|
|
2763
2785
|
"tecMAX_SEQUENCE_REACHED": 154,
|
|
2764
2786
|
"tecNO_SUITABLE_NFTOKEN_PAGE": 155,
|
|
2765
2787
|
"tecNFTOKEN_BUY_SELL_MISMATCH": 156,
|
|
@@ -2792,7 +2814,8 @@
|
|
|
2792
2814
|
"tecXCHAIN_PAYMENT_FAILED": 183,
|
|
2793
2815
|
"tecXCHAIN_SELF_COMMIT": 184,
|
|
2794
2816
|
"tecXCHAIN_BAD_PUBLIC_KEY_ACCOUNT_PAIR": 185,
|
|
2795
|
-
"tecXCHAIN_CREATE_ACCOUNT_DISABLED": 186
|
|
2817
|
+
"tecXCHAIN_CREATE_ACCOUNT_DISABLED": 186,
|
|
2818
|
+
"tecEMPTY_DID": 187
|
|
2796
2819
|
},
|
|
2797
2820
|
"TRANSACTION_TYPES": {
|
|
2798
2821
|
"Invalid": -1,
|
|
@@ -2839,6 +2862,8 @@
|
|
|
2839
2862
|
"XChainAddAccountCreateAttestation": 46,
|
|
2840
2863
|
"XChainModifyBridge": 47,
|
|
2841
2864
|
"XChainCreateBridge": 48,
|
|
2865
|
+
"DIDSet": 49,
|
|
2866
|
+
"DIDDelete": 50,
|
|
2842
2867
|
"EnableAmendment": 100,
|
|
2843
2868
|
"SetFee": 101,
|
|
2844
2869
|
"UNLModify": 102
|
package/src/enums/field.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Bytes } from './bytes'
|
|
2
2
|
import { SerializedType } from '../types/serialized-type'
|
|
3
3
|
import { TYPE_WIDTH } from './constants'
|
|
4
|
-
import { Buffer } from 'buffer/'
|
|
5
4
|
|
|
6
5
|
/**
|
|
7
6
|
* Encoding information for a rippled field, often used in transactions.
|
|
@@ -23,14 +22,14 @@ export interface FieldInstance {
|
|
|
23
22
|
readonly type: Bytes
|
|
24
23
|
readonly ordinal: number
|
|
25
24
|
readonly name: string
|
|
26
|
-
readonly header:
|
|
25
|
+
readonly header: Uint8Array
|
|
27
26
|
readonly associatedType: typeof SerializedType
|
|
28
27
|
}
|
|
29
28
|
|
|
30
29
|
/*
|
|
31
30
|
* @brief: Serialize a field based on type_code and Field.nth
|
|
32
31
|
*/
|
|
33
|
-
function fieldHeader(type: number, nth: number):
|
|
32
|
+
function fieldHeader(type: number, nth: number): Uint8Array {
|
|
34
33
|
const header: Array<number> = []
|
|
35
34
|
if (type < 16) {
|
|
36
35
|
if (nth < 16) {
|
|
@@ -43,7 +42,7 @@ function fieldHeader(type: number, nth: number): Buffer {
|
|
|
43
42
|
} else {
|
|
44
43
|
header.push(0, type, nth)
|
|
45
44
|
}
|
|
46
|
-
return
|
|
45
|
+
return Uint8Array.from(header)
|
|
47
46
|
}
|
|
48
47
|
|
|
49
48
|
function buildField(
|
package/src/enums/index.ts
CHANGED