@transia/ripple-binary-codec 1.4.6-alpha.9 → 2.5.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/binary.d.ts +30 -16
- package/dist/binary.js +36 -16
- package/dist/binary.js.map +1 -1
- package/dist/enums/bytes.d.ts +1 -2
- package/dist/enums/bytes.js +3 -2
- package/dist/enums/bytes.js.map +1 -1
- package/dist/enums/constants.d.ts +1 -0
- package/dist/enums/constants.js +6 -5
- package/dist/enums/constants.js.map +1 -1
- package/dist/enums/definitions.json +1604 -969
- 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.d.ts +1 -2
- package/dist/enums/index.js +5 -27
- package/dist/enums/index.js.map +1 -1
- package/dist/enums/src/enums/definitions.json +1606 -971
- package/dist/enums/xrpl-definitions-base.d.ts +5 -3
- package/dist/enums/xrpl-definitions-base.js +26 -6
- package/dist/enums/xrpl-definitions-base.js.map +1 -1
- package/dist/enums/xrpl-definitions.d.ts +2 -1
- package/dist/enums/xrpl-definitions.js +2 -1
- package/dist/enums/xrpl-definitions.js.map +1 -1
- package/dist/hash-prefixes.d.ts +1 -2
- package/dist/hash-prefixes.js +8 -6
- package/dist/hash-prefixes.js.map +1 -1
- package/dist/hashes.d.ts +6 -7
- package/dist/hashes.js +6 -7
- package/dist/hashes.js.map +1 -1
- package/dist/index.d.ts +16 -11
- package/dist/index.js +53 -58
- package/dist/index.js.map +1 -1
- package/dist/ledger-hashes.d.ts +1 -2
- package/dist/ledger-hashes.js +11 -30
- package/dist/ledger-hashes.js.map +1 -1
- package/dist/quality.d.ts +3 -4
- package/dist/quality.js +10 -8
- package/dist/quality.js.map +1 -1
- package/dist/serdes/binary-parser.d.ts +2 -3
- package/dist/serdes/binary-parser.js +16 -32
- package/dist/serdes/binary-parser.js.map +1 -1
- package/dist/serdes/binary-serializer.d.ts +7 -8
- package/dist/serdes/binary-serializer.js +14 -37
- package/dist/serdes/binary-serializer.js.map +1 -1
- package/dist/shamap.d.ts +4 -5
- package/dist/shamap.js +5 -5
- package/dist/shamap.js.map +1 -1
- package/dist/src/binary.d.ts +106 -0
- package/dist/src/binary.js +154 -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 +65 -0
- package/dist/src/enums/bytes.js.map +1 -0
- package/dist/src/enums/constants.d.ts +5 -0
- package/dist/src/enums/constants.js +9 -0
- package/dist/src/enums/constants.js.map +1 -0
- package/dist/src/enums/definitions.json +3404 -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 +47 -0
- package/dist/src/enums/xrpl-definitions-base.js +83 -0
- package/dist/src/enums/xrpl-definitions-base.js.map +1 -0
- package/dist/src/enums/xrpl-definitions.d.ts +22 -0
- package/dist/src/enums/xrpl-definitions.js +30 -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 +43 -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 +69 -0
- package/dist/src/index.js +134 -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 +37 -0
- package/dist/src/types/account-id.js +73 -0
- package/dist/src/types/account-id.js.map +1 -0
- package/dist/src/types/amount.d.ts +92 -0
- package/dist/src/types/amount.js +292 -0
- package/dist/src/types/amount.js.map +1 -0
- package/dist/src/types/blob.d.ts +25 -0
- package/dist/src/types/blob.js +46 -0
- package/dist/src/types/blob.js.map +1 -0
- package/dist/src/types/currency.d.ts +30 -0
- package/dist/src/types/currency.js +131 -0
- package/dist/src/types/currency.js.map +1 -0
- package/dist/src/types/data.d.ts +104 -0
- package/dist/src/types/data.js +387 -0
- package/dist/src/types/data.js.map +1 -0
- package/dist/src/types/dataType.d.ts +94 -0
- package/dist/src/types/dataType.js +145 -0
- package/dist/src/types/dataType.js.map +1 -0
- package/dist/src/types/hash-128.d.ts +18 -0
- package/dist/src/types/hash-128.js +36 -0
- package/dist/src/types/hash-128.js.map +1 -0
- package/dist/src/types/hash-160.d.ts +12 -0
- package/dist/src/types/hash-160.js +23 -0
- package/dist/src/types/hash-160.js.map +1 -0
- package/dist/src/types/hash-192.d.ts +12 -0
- package/dist/src/types/hash-192.js +23 -0
- package/dist/src/types/hash-192.js.map +1 -0
- package/dist/src/types/hash-256.d.ts +12 -0
- package/dist/src/types/hash-256.js +20 -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 +76 -0
- package/dist/src/types/hash.js.map +1 -0
- package/dist/src/types/index.d.ts +21 -0
- package/dist/src/types/index.js +72 -0
- package/dist/src/types/index.js.map +1 -0
- package/dist/src/types/issue.d.ts +49 -0
- package/dist/src/types/issue.js +107 -0
- package/dist/src/types/issue.js.map +1 -0
- package/dist/src/types/json.d.ts +169 -0
- package/dist/src/types/json.js +529 -0
- package/dist/src/types/json.js.map +1 -0
- package/dist/src/types/path-set.d.ts +37 -0
- package/dist/src/types/path-set.js +236 -0
- package/dist/src/types/path-set.js.map +1 -0
- package/dist/src/types/serialized-type.d.ts +117 -0
- package/dist/src/types/serialized-type.js +242 -0
- package/dist/src/types/serialized-type.js.map +1 -0
- package/dist/src/types/st-array.d.ts +32 -0
- package/dist/src/types/st-array.js +89 -0
- package/dist/src/types/st-array.js.map +1 -0
- package/dist/src/types/st-number.d.ts +55 -0
- package/dist/src/types/st-number.js +212 -0
- package/dist/src/types/st-number.js.map +1 -0
- package/dist/src/types/st-object.d.ts +33 -0
- package/dist/src/types/st-object.js +176 -0
- package/dist/src/types/st-object.js.map +1 -0
- package/dist/src/types/uint-16.d.ts +26 -0
- package/dist/src/types/uint-16.js +49 -0
- package/dist/src/types/uint-16.js.map +1 -0
- package/dist/src/types/uint-32.d.ts +26 -0
- package/dist/src/types/uint-32.js +54 -0
- package/dist/src/types/uint-32.js.map +1 -0
- package/dist/src/types/uint-64.d.ts +40 -0
- package/dist/src/types/uint-64.js +112 -0
- package/dist/src/types/uint-64.js.map +1 -0
- package/dist/src/types/uint-8.d.ts +26 -0
- package/dist/src/types/uint-8.js +50 -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 +31 -0
- package/dist/src/types/vector-256.js +76 -0
- package/dist/src/types/vector-256.js.map +1 -0
- package/dist/src/types/xchain-bridge.d.ts +45 -0
- package/dist/src/types/xchain-bridge.js +105 -0
- package/dist/src/types/xchain-bridge.js.map +1 -0
- package/dist/src/utils.d.ts +79 -0
- package/dist/src/utils.js +181 -0
- package/dist/src/utils.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types/account-id.d.ts +3 -2
- package/dist/types/account-id.js +8 -6
- package/dist/types/account-id.js.map +1 -1
- package/dist/types/amount.d.ts +33 -9
- package/dist/types/amount.js +128 -43
- package/dist/types/amount.js.map +1 -1
- package/dist/types/blob.d.ts +3 -3
- package/dist/types/blob.js +8 -2
- package/dist/types/blob.js.map +1 -1
- package/dist/types/currency.d.ts +3 -2
- package/dist/types/currency.js +17 -13
- package/dist/types/currency.js.map +1 -1
- package/dist/types/data.d.ts +104 -0
- package/dist/types/data.js +387 -0
- package/dist/types/data.js.map +1 -0
- package/dist/types/dataType.d.ts +94 -0
- package/dist/types/dataType.js +145 -0
- package/dist/types/dataType.js.map +1 -0
- package/dist/types/hash-128.d.ts +3 -2
- package/dist/types/hash-128.js +7 -3
- package/dist/types/hash-128.js.map +1 -1
- package/dist/types/hash-160.d.ts +3 -2
- package/dist/types/hash-160.js +5 -2
- package/dist/types/hash-160.js.map +1 -1
- package/dist/types/hash-192.d.ts +12 -0
- package/dist/types/hash-192.js +23 -0
- package/dist/types/hash-192.js.map +1 -0
- package/dist/types/hash-256.d.ts +3 -2
- package/dist/types/hash-256.js +5 -2
- package/dist/types/hash-256.js.map +1 -1
- package/dist/types/hash.d.ts +2 -3
- package/dist/types/hash.js +8 -4
- package/dist/types/hash.js.map +1 -1
- package/dist/types/index.d.ts +4 -1
- package/dist/types/index.js +17 -2
- package/dist/types/index.js.map +1 -1
- package/dist/types/issue.d.ts +49 -0
- package/dist/types/issue.js +107 -0
- package/dist/types/issue.js.map +1 -0
- package/dist/types/json.d.ts +169 -0
- package/dist/types/json.js +529 -0
- package/dist/types/json.js.map +1 -0
- package/dist/types/path-set.d.ts +2 -1
- package/dist/types/path-set.js +15 -12
- package/dist/types/path-set.js.map +1 -1
- package/dist/types/serialized-type.d.ts +70 -16
- package/dist/types/serialized-type.js +153 -8
- package/dist/types/serialized-type.js.map +1 -1
- package/dist/types/st-array.d.ts +7 -3
- package/dist/types/st-array.js +20 -11
- package/dist/types/st-array.js.map +1 -1
- package/dist/types/st-number.d.ts +55 -0
- package/dist/types/st-number.js +212 -0
- package/dist/types/st-number.js.map +1 -0
- package/dist/types/st-object.d.ts +2 -1
- package/dist/types/st-object.js +35 -8
- package/dist/types/st-object.js.map +1 -1
- package/dist/types/uint-16.d.ts +3 -2
- package/dist/types/uint-16.js +10 -5
- package/dist/types/uint-16.js.map +1 -1
- package/dist/types/uint-32.d.ts +3 -2
- package/dist/types/uint-32.js +11 -6
- package/dist/types/uint-32.js.map +1 -1
- package/dist/types/uint-64.d.ts +8 -7
- package/dist/types/uint-64.js +49 -24
- package/dist/types/uint-64.js.map +1 -1
- package/dist/types/uint-8.d.ts +3 -2
- package/dist/types/uint-8.js +11 -5
- package/dist/types/uint-8.js.map +1 -1
- package/dist/types/uint.d.ts +5 -6
- package/dist/types/uint.js +5 -0
- package/dist/types/uint.js.map +1 -1
- package/dist/types/vector-256.d.ts +3 -3
- package/dist/types/vector-256.js +5 -4
- package/dist/types/vector-256.js.map +1 -1
- package/dist/types/xchain-bridge.d.ts +45 -0
- package/dist/types/xchain-bridge.js +105 -0
- package/dist/types/xchain-bridge.js.map +1 -0
- package/dist/utils.d.ts +79 -0
- package/dist/utils.js +181 -0
- package/dist/utils.js.map +1 -0
- package/package.json +21 -17
- package/src/README.md +5 -0
- package/src/binary.ts +235 -0
- package/src/coretypes.ts +31 -0
- package/src/enums/README.md +144 -0
- package/src/enums/bytes.ts +80 -0
- package/src/enums/constants.ts +5 -0
- package/src/enums/definitions.json +3409 -0
- package/src/enums/field.ts +84 -0
- package/src/enums/index.ts +34 -0
- package/src/enums/utils-renumber.ts +134 -0
- package/src/enums/xrpl-definitions-base.ts +150 -0
- package/src/enums/xrpl-definitions.ts +33 -0
- package/src/hash-prefixes.ts +42 -0
- package/src/hashes.ts +75 -0
- package/src/index.ts +166 -0
- package/src/ledger-hashes.ts +191 -0
- package/src/quality.ts +38 -0
- package/src/serdes/binary-parser.ts +228 -0
- package/src/serdes/binary-serializer.ts +166 -0
- package/src/shamap.ts +189 -0
- package/src/types/account-id.ts +91 -0
- package/src/types/amount.ts +366 -0
- package/src/types/blob.ts +50 -0
- package/src/types/currency.ts +145 -0
- package/src/types/data.ts +496 -0
- package/src/types/dataType.ts +178 -0
- package/src/types/hash-128.ts +38 -0
- package/src/types/hash-160.ts +24 -0
- package/src/types/hash-192.ts +24 -0
- package/src/types/hash-256.ts +20 -0
- package/src/types/hash.ts +86 -0
- package/src/types/index.ts +74 -0
- package/src/types/issue.ts +140 -0
- package/src/types/json.ts +641 -0
- package/src/types/path-set.ts +294 -0
- package/src/types/serialized-type.ts +271 -0
- package/src/types/st-array.ts +117 -0
- package/src/types/st-number.ts +238 -0
- package/src/types/st-object.ts +219 -0
- package/src/types/uint-16.ts +58 -0
- package/src/types/uint-32.ts +64 -0
- package/src/types/uint-64.ts +141 -0
- package/src/types/uint-8.ts +57 -0
- package/src/types/uint.ts +60 -0
- package/src/types/vector-256.ts +83 -0
- package/src/types/xchain-bridge.ts +132 -0
- package/src/utils.ts +220 -0
- package/test/amount.test.js +0 -43
- package/test/binary-json.test.js +0 -45
- package/test/binary-parser.test.js +0 -396
- package/test/binary-serializer.test.js +0 -319
- package/test/definitions.test.js +0 -100
- package/test/fixtures/account-tx-transactions.db +0 -0
- package/test/fixtures/codec-fixtures.json +0 -4466
- package/test/fixtures/data-driven-tests.json +0 -2919
- package/test/fixtures/delivermin-tx-binary.json +0 -1
- package/test/fixtures/delivermin-tx.json +0 -98
- package/test/fixtures/deposit-preauth-tx-binary.json +0 -1
- package/test/fixtures/deposit-preauth-tx-meta-binary.json +0 -1
- package/test/fixtures/deposit-preauth-tx.json +0 -58
- package/test/fixtures/escrow-cancel-binary.json +0 -1
- package/test/fixtures/escrow-cancel-tx.json +0 -6
- package/test/fixtures/escrow-create-binary.json +0 -1
- package/test/fixtures/escrow-create-tx.json +0 -10
- package/test/fixtures/escrow-finish-binary.json +0 -1
- package/test/fixtures/escrow-finish-meta-binary.json +0 -1
- package/test/fixtures/escrow-finish-tx.json +0 -95
- package/test/fixtures/ledger-full-38129.json +0 -1
- package/test/fixtures/ledger-full-40000.json +0 -1
- package/test/fixtures/negative-unl.json +0 -12
- package/test/fixtures/nf-token.json +0 -547
- package/test/fixtures/payment-channel-claim-binary.json +0 -1
- package/test/fixtures/payment-channel-claim-tx.json +0 -8
- package/test/fixtures/payment-channel-create-binary.json +0 -1
- package/test/fixtures/payment-channel-create-tx.json +0 -11
- package/test/fixtures/payment-channel-fund-binary.json +0 -1
- package/test/fixtures/payment-channel-fund-tx.json +0 -7
- package/test/fixtures/remit-binary.json +0 -1
- package/test/fixtures/remit-tx.json +0 -39
- package/test/fixtures/signerlistset-tx-binary.json +0 -1
- package/test/fixtures/signerlistset-tx-meta-binary.json +0 -1
- package/test/fixtures/signerlistset-tx.json +0 -94
- package/test/fixtures/ticket-create-binary.json +0 -1
- package/test/fixtures/ticket-create-tx.json +0 -7
- package/test/fixtures/unl-report-binary.json +0 -1
- package/test/fixtures/unl-report-meta-binary.json +0 -1
- package/test/fixtures/unl-report.json +0 -89
- package/test/fixtures/x-codec-fixtures.json +0 -188
- package/test/hash.test.js +0 -135
- package/test/ledger.test.js +0 -29
- package/test/lower-case-hex.test.js +0 -46
- package/test/pseudo-transaction.test.js +0 -38
- package/test/quality.test.js +0 -15
- package/test/shamap.test.js +0 -89
- package/test/signing-data-encoding.test.js +0 -213
- package/test/tx-encode-decode.test.js +0 -119
- package/test/types.test.js +0 -34
- package/test/uint.test.js +0 -148
- package/test/utils.js +0 -30
- package/test/x-address.test.js +0 -181
package/dist/types/uint-64.js
CHANGED
|
@@ -2,11 +2,22 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.UInt64 = void 0;
|
|
4
4
|
const uint_1 = require("./uint");
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
5
|
+
const utils_1 = require("@transia/isomorphic/utils");
|
|
6
|
+
const utils_2 = require("../utils");
|
|
7
|
+
const enums_1 = require("../enums");
|
|
8
|
+
const serialized_type_1 = require("./serialized-type");
|
|
8
9
|
const HEX_REGEX = /^[a-fA-F0-9]{1,16}$/;
|
|
9
|
-
const
|
|
10
|
+
const BASE10_REGEX = /^[0-9]{1,20}$/;
|
|
11
|
+
const mask = BigInt(0x00000000ffffffff);
|
|
12
|
+
const BASE10_AMOUNT_FIELDS = new Set([
|
|
13
|
+
'MaximumAmount',
|
|
14
|
+
'OutstandingAmount',
|
|
15
|
+
'MPTAmount',
|
|
16
|
+
'LockedAmount',
|
|
17
|
+
]);
|
|
18
|
+
function isBase10(fieldName) {
|
|
19
|
+
return BASE10_AMOUNT_FIELDS.has(fieldName);
|
|
20
|
+
}
|
|
10
21
|
/**
|
|
11
22
|
* Derived UInt class for serializing/deserializing 64 bit UInt
|
|
12
23
|
*/
|
|
@@ -23,34 +34,41 @@ class UInt64 extends uint_1.UInt {
|
|
|
23
34
|
* @param val A UInt64, hex-string, bigInt, or number
|
|
24
35
|
* @returns A UInt64 object
|
|
25
36
|
*/
|
|
26
|
-
|
|
37
|
+
// eslint-disable-next-line complexity
|
|
38
|
+
static from(val, fieldName = '') {
|
|
27
39
|
if (val instanceof UInt64) {
|
|
28
40
|
return val;
|
|
29
41
|
}
|
|
30
|
-
let buf =
|
|
42
|
+
let buf = new Uint8Array(UInt64.width);
|
|
31
43
|
if (typeof val === 'number') {
|
|
32
44
|
if (val < 0) {
|
|
33
45
|
throw new Error('value must be an unsigned integer');
|
|
34
46
|
}
|
|
35
|
-
const number =
|
|
36
|
-
const intBuf = [
|
|
37
|
-
intBuf[0]
|
|
38
|
-
intBuf[1]
|
|
39
|
-
return new UInt64(
|
|
47
|
+
const number = BigInt(val);
|
|
48
|
+
const intBuf = [new Uint8Array(4), new Uint8Array(4)];
|
|
49
|
+
(0, utils_2.writeUInt32BE)(intBuf[0], Number(number >> BigInt(32)), 0);
|
|
50
|
+
(0, utils_2.writeUInt32BE)(intBuf[1], Number(number & BigInt(mask)), 0);
|
|
51
|
+
return new UInt64((0, utils_1.concat)(intBuf));
|
|
40
52
|
}
|
|
41
53
|
if (typeof val === 'string') {
|
|
42
|
-
if (
|
|
54
|
+
if (isBase10(fieldName)) {
|
|
55
|
+
if (!BASE10_REGEX.test(val)) {
|
|
56
|
+
throw new Error(`${fieldName} ${val} is not a valid base 10 string`);
|
|
57
|
+
}
|
|
58
|
+
val = BigInt(val).toString(16);
|
|
59
|
+
}
|
|
60
|
+
if (typeof val === 'string' && !HEX_REGEX.test(val)) {
|
|
43
61
|
throw new Error(`${val} is not a valid hex-string`);
|
|
44
62
|
}
|
|
45
63
|
const strBuf = val.padStart(16, '0');
|
|
46
|
-
buf =
|
|
64
|
+
buf = (0, utils_1.hexToBytes)(strBuf);
|
|
47
65
|
return new UInt64(buf);
|
|
48
66
|
}
|
|
49
|
-
if (
|
|
50
|
-
const intBuf = [
|
|
51
|
-
intBuf[0]
|
|
52
|
-
intBuf[1]
|
|
53
|
-
return new UInt64(
|
|
67
|
+
if (typeof val === 'bigint') {
|
|
68
|
+
const intBuf = [new Uint8Array(4), new Uint8Array(4)];
|
|
69
|
+
(0, utils_2.writeUInt32BE)(intBuf[0], Number(Number(val >> BigInt(32))), 0);
|
|
70
|
+
(0, utils_2.writeUInt32BE)(intBuf[1], Number(val & BigInt(mask)), 0);
|
|
71
|
+
return new UInt64((0, utils_1.concat)(intBuf));
|
|
54
72
|
}
|
|
55
73
|
throw new Error('Cannot construct UInt64 from given value');
|
|
56
74
|
}
|
|
@@ -59,8 +77,12 @@ class UInt64 extends uint_1.UInt {
|
|
|
59
77
|
*
|
|
60
78
|
* @returns a hex-string
|
|
61
79
|
*/
|
|
62
|
-
toJSON() {
|
|
63
|
-
|
|
80
|
+
toJSON(_definitions = enums_1.DEFAULT_DEFINITIONS, fieldName = '') {
|
|
81
|
+
const hexString = (0, utils_1.bytesToHex)(this.bytes);
|
|
82
|
+
if (isBase10(fieldName)) {
|
|
83
|
+
return BigInt('0x' + hexString).toString(10);
|
|
84
|
+
}
|
|
85
|
+
return hexString;
|
|
64
86
|
}
|
|
65
87
|
/**
|
|
66
88
|
* Get the value of the UInt64
|
|
@@ -68,9 +90,9 @@ class UInt64 extends uint_1.UInt {
|
|
|
68
90
|
* @returns the number represented buy this.bytes
|
|
69
91
|
*/
|
|
70
92
|
valueOf() {
|
|
71
|
-
const msb =
|
|
72
|
-
const lsb =
|
|
73
|
-
return msb
|
|
93
|
+
const msb = BigInt((0, utils_2.readUInt32BE)(this.bytes.slice(0, 4), 0));
|
|
94
|
+
const lsb = BigInt((0, utils_2.readUInt32BE)(this.bytes.slice(4), 0));
|
|
95
|
+
return (msb << BigInt(32)) | lsb;
|
|
74
96
|
}
|
|
75
97
|
/**
|
|
76
98
|
* Get the bytes representation of the UInt64 object
|
|
@@ -80,8 +102,11 @@ class UInt64 extends uint_1.UInt {
|
|
|
80
102
|
toBytes() {
|
|
81
103
|
return this.bytes;
|
|
82
104
|
}
|
|
105
|
+
getSType() {
|
|
106
|
+
return serialized_type_1.SerializedTypeID.STI_UINT64;
|
|
107
|
+
}
|
|
83
108
|
}
|
|
84
109
|
exports.UInt64 = UInt64;
|
|
85
110
|
UInt64.width = 64 / 8; // 8
|
|
86
|
-
UInt64.defaultUInt64 = new UInt64(
|
|
111
|
+
UInt64.defaultUInt64 = new UInt64(new Uint8Array(UInt64.width));
|
|
87
112
|
//# sourceMappingURL=uint-64.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uint-64.js","sourceRoot":"","sources":["../../src/types/uint-64.ts"],"names":[],"mappings":";;;AAAA,iCAA6B;AAE7B,
|
|
1
|
+
{"version":3,"file":"uint-64.js","sourceRoot":"","sources":["../../src/types/uint-64.ts"],"names":[],"mappings":";;;AAAA,iCAA6B;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a,YAAK,GAAW,EAAE,GAAG,CAAC,CAAA,CAAC,IAAI;AACrC,oBAAa,GAAW,IAAI,MAAM,CAChD,IAAI,UAAU,CAAC,MAAM,CAAC,KAAK,CAAC,CAC7B,CAAA"}
|
package/dist/types/uint-8.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { UInt } from './uint';
|
|
2
2
|
import { BinaryParser } from '../serdes/binary-parser';
|
|
3
|
-
import {
|
|
3
|
+
import { SerializedTypeID } from './serialized-type';
|
|
4
4
|
/**
|
|
5
5
|
* Derived UInt class for serializing/deserializing 8 bit UInt
|
|
6
6
|
*/
|
|
7
7
|
declare class UInt8 extends UInt {
|
|
8
8
|
protected static readonly width: number;
|
|
9
9
|
static readonly defaultUInt8: UInt8;
|
|
10
|
-
constructor(bytes:
|
|
10
|
+
constructor(bytes: Uint8Array);
|
|
11
11
|
static fromParser(parser: BinaryParser): UInt;
|
|
12
12
|
/**
|
|
13
13
|
* Construct a UInt8 object from a number
|
|
@@ -21,5 +21,6 @@ declare class UInt8 extends UInt {
|
|
|
21
21
|
* @returns the number represented by this.bytes
|
|
22
22
|
*/
|
|
23
23
|
valueOf(): number;
|
|
24
|
+
getSType(): SerializedTypeID;
|
|
24
25
|
}
|
|
25
26
|
export { UInt8 };
|
package/dist/types/uint-8.js
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.UInt8 = void 0;
|
|
4
4
|
const uint_1 = require("./uint");
|
|
5
|
-
const
|
|
5
|
+
const utils_1 = require("@transia/isomorphic/utils");
|
|
6
|
+
const utils_2 = require("../utils");
|
|
7
|
+
const serialized_type_1 = require("./serialized-type");
|
|
6
8
|
/**
|
|
7
9
|
* Derived UInt class for serializing/deserializing 8 bit UInt
|
|
8
10
|
*/
|
|
@@ -23,8 +25,9 @@ class UInt8 extends uint_1.UInt {
|
|
|
23
25
|
return val;
|
|
24
26
|
}
|
|
25
27
|
if (typeof val === 'number') {
|
|
26
|
-
|
|
27
|
-
buf.
|
|
28
|
+
UInt8.checkUintRange(val, 0, 0xff);
|
|
29
|
+
const buf = new Uint8Array(UInt8.width);
|
|
30
|
+
(0, utils_2.writeUInt8)(buf, val, 0);
|
|
28
31
|
return new UInt8(buf);
|
|
29
32
|
}
|
|
30
33
|
throw new Error('Cannot construct UInt8 from given value');
|
|
@@ -35,10 +38,13 @@ class UInt8 extends uint_1.UInt {
|
|
|
35
38
|
* @returns the number represented by this.bytes
|
|
36
39
|
*/
|
|
37
40
|
valueOf() {
|
|
38
|
-
return this.bytes
|
|
41
|
+
return parseInt((0, utils_1.bytesToHex)(this.bytes), 16);
|
|
42
|
+
}
|
|
43
|
+
getSType() {
|
|
44
|
+
return serialized_type_1.SerializedTypeID.STI_UINT8;
|
|
39
45
|
}
|
|
40
46
|
}
|
|
41
47
|
exports.UInt8 = UInt8;
|
|
42
48
|
UInt8.width = 8 / 8; // 1
|
|
43
|
-
UInt8.defaultUInt8 = new UInt8(
|
|
49
|
+
UInt8.defaultUInt8 = new UInt8(new Uint8Array(UInt8.width));
|
|
44
50
|
//# sourceMappingURL=uint-8.js.map
|
package/dist/types/uint-8.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uint-8.js","sourceRoot":"","sources":["../../src/types/uint-8.ts"],"names":[],"mappings":";;;AAAA,iCAA6B;AAE7B,
|
|
1
|
+
{"version":3,"file":"uint-8.js","sourceRoot":"","sources":["../../src/types/uint-8.ts"],"names":[],"mappings":";;;AAAA,iCAA6B;AAE7B,qDAAsD;AACtD,oCAAqC;AACrC,uDAAoD;AAEpD;;GAEG;AACH,MAAM,KAAM,SAAQ,WAAI;IAItB,YAAY,KAAiB;QAC3B,KAAK,CAAC,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,KAAK,CAAC,YAAY,CAAC,KAAK,CAAC,CAAA;IAC1C,CAAC;IAED,MAAM,CAAC,UAAU,CAAC,MAAoB;QACpC,OAAO,IAAI,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAA;IAC5C,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,IAAI,CAA2B,GAAM;QAC1C,IAAI,GAAG,YAAY,KAAK,EAAE;YACxB,OAAO,GAAG,CAAA;SACX;QAED,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE;YAC3B,KAAK,CAAC,cAAc,CAAC,GAAG,EAAE,CAAC,EAAE,IAAI,CAAC,CAAA;YAElC,MAAM,GAAG,GAAG,IAAI,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;YACvC,IAAA,kBAAU,EAAC,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,CAAA;YACvB,OAAO,IAAI,KAAK,CAAC,GAAG,CAAC,CAAA;SACtB;QAED,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAA;IAC5D,CAAC;IAED;;;;OAIG;IACH,OAAO;QACL,OAAO,QAAQ,CAAC,IAAA,kBAAU,EAAC,IAAI,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC,CAAA;IAC7C,CAAC;IAED,QAAQ;QACN,OAAO,kCAAgB,CAAC,SAAS,CAAA;IACnC,CAAC;;AAGM,sBAAK;AA9Cc,WAAK,GAAW,CAAC,GAAG,CAAC,CAAA,CAAC,IAAI;AACpC,kBAAY,GAAU,IAAI,KAAK,CAAC,IAAI,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAA"}
|
package/dist/types/uint.d.ts
CHANGED
|
@@ -1,19 +1,17 @@
|
|
|
1
|
-
import bigInt = require('big-integer');
|
|
2
1
|
import { Comparable } from './serialized-type';
|
|
3
|
-
import { Buffer } from 'buffer/';
|
|
4
2
|
/**
|
|
5
3
|
* Base class for serializing and deserializing unsigned integers.
|
|
6
4
|
*/
|
|
7
|
-
declare abstract class UInt extends Comparable {
|
|
5
|
+
declare abstract class UInt extends Comparable<UInt | number> {
|
|
8
6
|
protected static width: number;
|
|
9
|
-
constructor(bytes:
|
|
7
|
+
constructor(bytes: Uint8Array);
|
|
10
8
|
/**
|
|
11
9
|
* Overload of compareTo for Comparable
|
|
12
10
|
*
|
|
13
11
|
* @param other other UInt to compare this to
|
|
14
12
|
* @returns -1, 0, or 1 depending on how the objects relate to each other
|
|
15
13
|
*/
|
|
16
|
-
compareTo(other: UInt): number;
|
|
14
|
+
compareTo(other: UInt | number): number;
|
|
17
15
|
/**
|
|
18
16
|
* Convert a UInt object to JSON
|
|
19
17
|
*
|
|
@@ -25,6 +23,7 @@ declare abstract class UInt extends Comparable {
|
|
|
25
23
|
*
|
|
26
24
|
* @returns the value
|
|
27
25
|
*/
|
|
28
|
-
abstract valueOf(): number |
|
|
26
|
+
abstract valueOf(): number | bigint;
|
|
27
|
+
static checkUintRange(val: number, min: number, max: number): void;
|
|
29
28
|
}
|
|
30
29
|
export { UInt };
|
package/dist/types/uint.js
CHANGED
|
@@ -37,6 +37,11 @@ class UInt extends serialized_type_1.Comparable {
|
|
|
37
37
|
const val = this.valueOf();
|
|
38
38
|
return typeof val === 'number' ? val : val.toString();
|
|
39
39
|
}
|
|
40
|
+
static checkUintRange(val, min, max) {
|
|
41
|
+
if (val < min || val > max) {
|
|
42
|
+
throw new Error(`Invalid ${this.constructor.name}: ${val} must be >= ${min} and <= ${max}`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
40
45
|
}
|
|
41
46
|
exports.UInt = UInt;
|
|
42
47
|
//# sourceMappingURL=uint.js.map
|
package/dist/types/uint.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uint.js","sourceRoot":"","sources":["../../src/types/uint.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"uint.js","sourceRoot":"","sources":["../../src/types/uint.ts"],"names":[],"mappings":";;;AAAA,uDAA8C;AAE9C;;;;;;GAMG;AACH,SAAS,OAAO,CAAC,EAAmB,EAAE,EAAmB;IACvD,OAAO,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;AACxC,CAAC;AAED;;GAEG;AACH,MAAe,IAAK,SAAQ,4BAAyB;IAGnD,YAAY,KAAiB;QAC3B,KAAK,CAAC,KAAK,CAAC,CAAA;IACd,CAAC;IAED;;;;;OAKG;IACH,SAAS,CAAC,KAAoB;QAC5B,OAAO,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC,CAAA;IACjD,CAAC;IAED;;;;OAIG;IACH,MAAM;QACJ,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,EAAE,CAAA;QAC1B,OAAO,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAA;IACvD,CAAC;IASD,MAAM,CAAC,cAAc,CAAC,GAAW,EAAE,GAAW,EAAE,GAAW;QACzD,IAAI,GAAG,GAAG,GAAG,IAAI,GAAG,GAAG,GAAG,EAAE;YAC1B,MAAM,IAAI,KAAK,CACb,WAAW,IAAI,CAAC,WAAW,CAAC,IAAI,KAAK,GAAG,eAAe,GAAG,WAAW,GAAG,EAAE,CAC3E,CAAA;SACF;IACH,CAAC;CACF;AAEQ,oBAAI"}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { SerializedType } from './serialized-type';
|
|
1
|
+
import { SerializedType, SerializedTypeID } from './serialized-type';
|
|
2
2
|
import { BinaryParser } from '../serdes/binary-parser';
|
|
3
|
-
import { Buffer } from 'buffer/';
|
|
4
3
|
/**
|
|
5
4
|
* Class for serializing and deserializing vectors of Hash256
|
|
6
5
|
*/
|
|
7
6
|
declare class Vector256 extends SerializedType {
|
|
8
|
-
constructor(bytes:
|
|
7
|
+
constructor(bytes: Uint8Array);
|
|
9
8
|
/**
|
|
10
9
|
* Construct a Vector256 from a BinaryParser
|
|
11
10
|
*
|
|
@@ -27,5 +26,6 @@ declare class Vector256 extends SerializedType {
|
|
|
27
26
|
* @returns An Array of strings representing the Hash256 objects
|
|
28
27
|
*/
|
|
29
28
|
toJSON(): Array<string>;
|
|
29
|
+
getSType(): SerializedTypeID;
|
|
30
30
|
}
|
|
31
31
|
export { Vector256 };
|
package/dist/types/vector-256.js
CHANGED
|
@@ -4,6 +4,7 @@ exports.Vector256 = void 0;
|
|
|
4
4
|
const serialized_type_1 = require("./serialized-type");
|
|
5
5
|
const hash_256_1 = require("./hash-256");
|
|
6
6
|
const binary_serializer_1 = require("../serdes/binary-serializer");
|
|
7
|
+
const utils_1 = require("@transia/isomorphic/utils");
|
|
7
8
|
/**
|
|
8
9
|
* TypeGuard for Array<string>
|
|
9
10
|
*/
|
|
@@ -63,13 +64,13 @@ class Vector256 extends serialized_type_1.SerializedType {
|
|
|
63
64
|
}
|
|
64
65
|
const result = [];
|
|
65
66
|
for (let i = 0; i < this.bytes.byteLength; i += 32) {
|
|
66
|
-
result.push(this.bytes
|
|
67
|
-
.slice(i, i + 32)
|
|
68
|
-
.toString('hex')
|
|
69
|
-
.toUpperCase());
|
|
67
|
+
result.push((0, utils_1.bytesToHex)(this.bytes.slice(i, i + 32)));
|
|
70
68
|
}
|
|
71
69
|
return result;
|
|
72
70
|
}
|
|
71
|
+
getSType() {
|
|
72
|
+
return serialized_type_1.SerializedTypeID.STI_VECTOR256;
|
|
73
|
+
}
|
|
73
74
|
}
|
|
74
75
|
exports.Vector256 = Vector256;
|
|
75
76
|
//# sourceMappingURL=vector-256.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vector-256.js","sourceRoot":"","sources":["../../src/types/vector-256.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"vector-256.js","sourceRoot":"","sources":["../../src/types/vector-256.ts"],"names":[],"mappings":";;;AAAA,uDAAoE;AAE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;YACF,OAAO,IAAI,SAAS,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC,CAAA;SAC1C;QAED,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAA;IAChE,CAAC;IAED;;;;OAIG;IACH,MAAM;QACJ,IAAI,IAAI,CAAC,KAAK,CAAC,UAAU,GAAG,EAAE,KAAK,CAAC,EAAE;YACpC,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAA;SAC/C;QAED,MAAM,MAAM,GAAkB,EAAE,CAAA;QAChC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,CAAC,IAAI,EAAE,EAAE;YAClD,MAAM,CAAC,IAAI,CAAC,IAAA,kBAAU,EAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAA;SACrD;QACD,OAAO,MAAM,CAAA;IACf,CAAC;IAED,QAAQ;QACN,OAAO,kCAAgB,CAAC,aAAa,CAAA;IACvC,CAAC;CACF;AAEQ,8BAAS"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { BinaryParser } from '../serdes/binary-parser';
|
|
2
|
+
import { JsonObject, SerializedType, SerializedTypeID } from './serialized-type';
|
|
3
|
+
import { IssueObject } from './issue';
|
|
4
|
+
/**
|
|
5
|
+
* Interface for JSON objects that represent cross-chain bridges
|
|
6
|
+
*/
|
|
7
|
+
interface XChainBridgeObject extends JsonObject {
|
|
8
|
+
LockingChainDoor: string;
|
|
9
|
+
LockingChainIssue: IssueObject | string;
|
|
10
|
+
IssuingChainDoor: string;
|
|
11
|
+
IssuingChainIssue: IssueObject | string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Class for serializing/deserializing XChainBridges
|
|
15
|
+
*/
|
|
16
|
+
declare class XChainBridge extends SerializedType {
|
|
17
|
+
static readonly ZERO_XCHAIN_BRIDGE: XChainBridge;
|
|
18
|
+
static readonly TYPE_ORDER: {
|
|
19
|
+
name: string;
|
|
20
|
+
type: typeof SerializedType;
|
|
21
|
+
}[];
|
|
22
|
+
constructor(bytes: Uint8Array);
|
|
23
|
+
/**
|
|
24
|
+
* Construct a cross-chain bridge from a JSON
|
|
25
|
+
*
|
|
26
|
+
* @param value XChainBridge or JSON to parse into an XChainBridge
|
|
27
|
+
* @returns An XChainBridge object
|
|
28
|
+
*/
|
|
29
|
+
static from<T extends XChainBridge | XChainBridgeObject>(value: T): XChainBridge;
|
|
30
|
+
/**
|
|
31
|
+
* Read an XChainBridge from a BinaryParser
|
|
32
|
+
*
|
|
33
|
+
* @param parser BinaryParser to read the XChainBridge from
|
|
34
|
+
* @returns An XChainBridge object
|
|
35
|
+
*/
|
|
36
|
+
static fromParser(parser: BinaryParser): XChainBridge;
|
|
37
|
+
/**
|
|
38
|
+
* Get the JSON representation of this XChainBridge
|
|
39
|
+
*
|
|
40
|
+
* @returns the JSON interpretation of this.bytes
|
|
41
|
+
*/
|
|
42
|
+
toJSON(): XChainBridgeObject;
|
|
43
|
+
getSType(): SerializedTypeID;
|
|
44
|
+
}
|
|
45
|
+
export { XChainBridge, XChainBridgeObject };
|
|
@@ -0,0 +1,105 @@
|
|
|
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 issue_1 = require("./issue");
|
|
8
|
+
const utils_1 = require("@transia/isomorphic/utils");
|
|
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 an XChainBridge
|
|
31
|
+
* @returns An XChainBridge object
|
|
32
|
+
*/
|
|
33
|
+
static from(value) {
|
|
34
|
+
if (value instanceof XChainBridge) {
|
|
35
|
+
return value;
|
|
36
|
+
}
|
|
37
|
+
if (!isXChainBridgeObject(value)) {
|
|
38
|
+
throw new Error('Invalid type to construct an XChainBridge');
|
|
39
|
+
}
|
|
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
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Read an XChainBridge from a BinaryParser
|
|
53
|
+
*
|
|
54
|
+
* @param parser BinaryParser to read the XChainBridge from
|
|
55
|
+
* @returns An 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(Uint8Array.from([0x14]));
|
|
64
|
+
}
|
|
65
|
+
const object = type.fromParser(parser);
|
|
66
|
+
bytes.push(object.toBytes());
|
|
67
|
+
});
|
|
68
|
+
return new XChainBridge((0, utils_1.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
|
+
getSType() {
|
|
89
|
+
return serialized_type_1.SerializedTypeID.STI_XCHAIN_BRIDGE;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
exports.XChainBridge = XChainBridge;
|
|
93
|
+
XChainBridge.ZERO_XCHAIN_BRIDGE = new XChainBridge((0, utils_1.concat)([
|
|
94
|
+
Uint8Array.from([0x14]),
|
|
95
|
+
new Uint8Array(40),
|
|
96
|
+
Uint8Array.from([0x14]),
|
|
97
|
+
new Uint8Array(40),
|
|
98
|
+
]));
|
|
99
|
+
XChainBridge.TYPE_ORDER = [
|
|
100
|
+
{ name: 'LockingChainDoor', type: account_id_1.AccountID },
|
|
101
|
+
{ name: 'LockingChainIssue', type: issue_1.Issue },
|
|
102
|
+
{ name: 'IssuingChainDoor', type: account_id_1.AccountID },
|
|
103
|
+
{ name: 'IssuingChainIssue', type: issue_1.Issue },
|
|
104
|
+
];
|
|
105
|
+
//# sourceMappingURL=xchain-bridge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"xchain-bridge.js","sourceRoot":"","sources":["../../src/types/xchain-bridge.ts"],"names":[],"mappings":";;;AAAA,2DAAsD;AAEtD,6CAAwC;AACxC,uDAAgF;AAChF,mCAA4C;AAC5C,qDAAkD;AAYlD;;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,KAAK,GAAsB,EAAE,CAAA;QACnC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;YAC/B,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,IAAI,CAAA;YAC3B,IAAI,IAAI,KAAK,sBAAS,EAAE;gBACtB,KAAK,CAAC,IAA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3B,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;IAED,QAAQ;QACN,OAAO,kCAAgB,CAAC,iBAAiB,CAAA;IAC3C,CAAC;;AAGM,oCAAY;AAhGH,+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,79 @@
|
|
|
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
|
+
* Writes a signed 32-bit integer to a Uint8Array at the specified offset (big-endian).
|
|
26
|
+
*
|
|
27
|
+
* @param array - The Uint8Array to write to.
|
|
28
|
+
* @param value - The signed 32-bit integer to write.
|
|
29
|
+
* @param offset - The offset at which to write.
|
|
30
|
+
*/
|
|
31
|
+
export declare function writeInt32BE(array: Uint8Array, value: number, offset: number): void;
|
|
32
|
+
/**
|
|
33
|
+
* Writes a signed 64-bit integer (BigInt) to a Uint8Array at the specified offset (big-endian).
|
|
34
|
+
*
|
|
35
|
+
* @param array - The Uint8Array to write to.
|
|
36
|
+
* @param value - The signed 64-bit integer (BigInt) to write.
|
|
37
|
+
* @param offset - The offset at which to write.
|
|
38
|
+
*/
|
|
39
|
+
export declare function writeInt64BE(array: Uint8Array, value: bigint, offset: number): void;
|
|
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
|
+
export declare function readUInt16BE(array: Uint8Array, offset: number): string;
|
|
46
|
+
/**
|
|
47
|
+
* Reads an unsigned, big-endian 16-bit integer from the array at the specified offset.
|
|
48
|
+
* @param array Uint8Array to read
|
|
49
|
+
* @param offset Number of bytes to skip before starting to read. Must satisfy 0 <= offset <= buf.length - 4
|
|
50
|
+
*/
|
|
51
|
+
export declare function readUInt32BE(array: Uint8Array, offset: number): string;
|
|
52
|
+
/**
|
|
53
|
+
* Reads a signed 32-bit integer from a Uint8Array at the specified offset (big-endian).
|
|
54
|
+
*
|
|
55
|
+
* @param array - The Uint8Array to read from.
|
|
56
|
+
* @param offset - The offset at which to start reading.
|
|
57
|
+
* @returns The signed 32-bit integer.
|
|
58
|
+
*/
|
|
59
|
+
export declare function readInt32BE(array: Uint8Array, offset: number): number;
|
|
60
|
+
/**
|
|
61
|
+
* Reads a signed 64-bit integer (BigInt) from a Uint8Array at the specified offset (big-endian).
|
|
62
|
+
*
|
|
63
|
+
* @param array - The Uint8Array to read from.
|
|
64
|
+
* @param offset - The offset at which to start reading.
|
|
65
|
+
* @returns The signed 64-bit integer (BigInt).
|
|
66
|
+
*/
|
|
67
|
+
export declare function readInt64BE(array: Uint8Array, offset: number): bigint;
|
|
68
|
+
/**
|
|
69
|
+
* Compares two Uint8Array or ArrayBuffers
|
|
70
|
+
* @param a first array to compare
|
|
71
|
+
* @param b second array to compare
|
|
72
|
+
*/
|
|
73
|
+
export declare function equal(a: Uint8Array | ArrayBuffer, b: Uint8Array | ArrayBuffer): boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Compare two TypedArrays
|
|
76
|
+
* @param a first array to compare
|
|
77
|
+
* @param b second array to compare
|
|
78
|
+
*/
|
|
79
|
+
export declare function compare(a: TypedArray, b: TypedArray): 1 | -1 | 0;
|