ripple-binary-codec 1.10.0 → 2.0.0-beta.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.js +1 -2
- package/dist/binary.js.map +1 -1
- package/dist/hashes.d.ts +1 -1
- package/dist/hashes.js +5 -5
- package/dist/hashes.js.map +1 -1
- package/dist/index.js +24 -32
- 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 +2 -2
- package/dist/quality.js +8 -6
- package/dist/quality.js.map +1 -1
- package/dist/serdes/binary-parser.js +12 -28
- package/dist/serdes/binary-parser.js.map +1 -1
- package/dist/serdes/binary-serializer.js +3 -26
- package/dist/serdes/binary-serializer.js.map +1 -1
- package/dist/shamap.js +3 -2
- package/dist/shamap.js.map +1 -1
- package/dist/types/amount.d.ts +1 -1
- package/dist/types/amount.js +31 -27
- package/dist/types/amount.js.map +1 -1
- package/dist/types/serialized-type.d.ts +1 -2
- package/dist/types/serialized-type.js.map +1 -1
- package/dist/types/uint-64.d.ts +2 -3
- package/dist/types/uint-64.js +10 -12
- package/dist/types/uint-64.js.map +1 -1
- package/dist/types/uint.d.ts +1 -2
- package/dist/types/uint.js.map +1 -1
- package/package.json +17 -9
- package/src/binary.ts +1 -2
- package/src/hashes.ts +3 -3
- package/src/index.ts +24 -9
- package/src/ledger-hashes.ts +14 -10
- package/src/quality.ts +6 -7
- package/src/serdes/binary-parser.ts +12 -5
- package/src/serdes/binary-serializer.ts +3 -3
- package/src/shamap.ts +3 -2
- package/src/types/amount.ts +30 -30
- package/src/types/serialized-type.ts +1 -4
- package/src/types/uint-64.ts +12 -16
- package/src/types/uint.ts +2 -6
package/dist/types/amount.js
CHANGED
|
@@ -1,28 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.Amount = void 0;
|
|
4
|
-
const decimal_js_1 = require("decimal.js");
|
|
5
7
|
const binary_parser_1 = require("../serdes/binary-parser");
|
|
6
8
|
const account_id_1 = require("./account-id");
|
|
7
9
|
const currency_1 = require("./currency");
|
|
8
10
|
const serialized_type_1 = require("./serialized-type");
|
|
9
|
-
const bigInt = require("big-integer");
|
|
10
11
|
const buffer_1 = require("buffer/");
|
|
12
|
+
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
11
13
|
/**
|
|
12
14
|
* Constants for validating amounts
|
|
13
15
|
*/
|
|
14
16
|
const MIN_IOU_EXPONENT = -96;
|
|
15
17
|
const MAX_IOU_EXPONENT = 80;
|
|
16
18
|
const MAX_IOU_PRECISION = 16;
|
|
17
|
-
const MAX_DROPS = new
|
|
18
|
-
const MIN_XRP = new
|
|
19
|
-
const mask =
|
|
19
|
+
const MAX_DROPS = new bignumber_js_1.default('1e17');
|
|
20
|
+
const MIN_XRP = new bignumber_js_1.default('1e-6');
|
|
21
|
+
const mask = BigInt(0x00000000ffffffff);
|
|
20
22
|
/**
|
|
21
|
-
*
|
|
23
|
+
* BigNumber configuration for Amount IOUs
|
|
22
24
|
*/
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
25
|
+
bignumber_js_1.default.config({
|
|
26
|
+
EXPONENTIAL_AT: [
|
|
27
|
+
MIN_IOU_EXPONENT - MAX_IOU_PRECISION,
|
|
28
|
+
MAX_IOU_EXPONENT + MAX_IOU_PRECISION,
|
|
29
|
+
],
|
|
26
30
|
});
|
|
27
31
|
/**
|
|
28
32
|
* Type guard for AmountObject
|
|
@@ -55,35 +59,35 @@ class Amount extends serialized_type_1.SerializedType {
|
|
|
55
59
|
let amount = buffer_1.Buffer.alloc(8);
|
|
56
60
|
if (typeof value === 'string') {
|
|
57
61
|
Amount.assertXrpIsValid(value);
|
|
58
|
-
const number =
|
|
62
|
+
const number = BigInt(value);
|
|
59
63
|
const intBuf = [buffer_1.Buffer.alloc(4), buffer_1.Buffer.alloc(4)];
|
|
60
|
-
intBuf[0].writeUInt32BE(Number(number
|
|
61
|
-
intBuf[1].writeUInt32BE(Number(number
|
|
64
|
+
intBuf[0].writeUInt32BE(Number(number >> BigInt(32)), 0);
|
|
65
|
+
intBuf[1].writeUInt32BE(Number(number & BigInt(mask)), 0);
|
|
62
66
|
amount = buffer_1.Buffer.concat(intBuf);
|
|
63
67
|
amount[0] |= 0x40;
|
|
64
68
|
return new Amount(amount);
|
|
65
69
|
}
|
|
66
70
|
if (isAmountObject(value)) {
|
|
67
|
-
const number = new
|
|
71
|
+
const number = new bignumber_js_1.default(value.value);
|
|
68
72
|
Amount.assertIouIsValid(number);
|
|
69
73
|
if (number.isZero()) {
|
|
70
74
|
amount[0] |= 0x80;
|
|
71
75
|
}
|
|
72
76
|
else {
|
|
73
77
|
const integerNumberString = number
|
|
74
|
-
.times(`1e${-(number.e - 15)}`)
|
|
78
|
+
.times(`1e${-((number.e || 0) - 15)}`)
|
|
75
79
|
.abs()
|
|
76
80
|
.toString();
|
|
77
|
-
const num =
|
|
81
|
+
const num = BigInt(integerNumberString);
|
|
78
82
|
const intBuf = [buffer_1.Buffer.alloc(4), buffer_1.Buffer.alloc(4)];
|
|
79
|
-
intBuf[0].writeUInt32BE(Number(num
|
|
80
|
-
intBuf[1].writeUInt32BE(Number(num
|
|
83
|
+
intBuf[0].writeUInt32BE(Number(num >> BigInt(32)), 0);
|
|
84
|
+
intBuf[1].writeUInt32BE(Number(num & BigInt(mask)), 0);
|
|
81
85
|
amount = buffer_1.Buffer.concat(intBuf);
|
|
82
86
|
amount[0] |= 0x80;
|
|
83
|
-
if (number.gt(new
|
|
87
|
+
if (number.gt(new bignumber_js_1.default(0))) {
|
|
84
88
|
amount[0] |= 0x40;
|
|
85
89
|
}
|
|
86
|
-
const exponent = number.e - 15;
|
|
90
|
+
const exponent = (number.e || 0) - 15;
|
|
87
91
|
const exponentByte = 97 + exponent;
|
|
88
92
|
amount[0] |= exponentByte >>> 2;
|
|
89
93
|
amount[1] |= (exponentByte & 0x03) << 6;
|
|
@@ -116,9 +120,9 @@ class Amount extends serialized_type_1.SerializedType {
|
|
|
116
120
|
const isPositive = bytes[0] & 0x40;
|
|
117
121
|
const sign = isPositive ? '' : '-';
|
|
118
122
|
bytes[0] &= 0x3f;
|
|
119
|
-
const msb =
|
|
120
|
-
const lsb =
|
|
121
|
-
const num = msb
|
|
123
|
+
const msb = BigInt(bytes.slice(0, 4).readUInt32BE(0));
|
|
124
|
+
const lsb = BigInt(bytes.slice(4).readUInt32BE(0));
|
|
125
|
+
const num = (msb << BigInt(32)) | lsb;
|
|
122
126
|
return `${sign}${num.toString()}`;
|
|
123
127
|
}
|
|
124
128
|
else {
|
|
@@ -133,7 +137,7 @@ class Amount extends serialized_type_1.SerializedType {
|
|
|
133
137
|
const exponent = ((b1 & 0x3f) << 2) + ((b2 & 0xff) >> 6) - 97;
|
|
134
138
|
mantissa[0] = 0;
|
|
135
139
|
mantissa[1] &= 0x3f;
|
|
136
|
-
const value = new
|
|
140
|
+
const value = new bignumber_js_1.default(`${sign}0x${mantissa.toString('hex')}`).times(`1e${exponent}`);
|
|
137
141
|
Amount.assertIouIsValid(value);
|
|
138
142
|
return {
|
|
139
143
|
value: value.toString(),
|
|
@@ -152,7 +156,7 @@ class Amount extends serialized_type_1.SerializedType {
|
|
|
152
156
|
if (amount.indexOf('.') !== -1) {
|
|
153
157
|
throw new Error(`${amount.toString()} is an illegal amount`);
|
|
154
158
|
}
|
|
155
|
-
const decimal = new
|
|
159
|
+
const decimal = new bignumber_js_1.default(amount);
|
|
156
160
|
if (!decimal.isZero()) {
|
|
157
161
|
if (decimal.lt(MIN_XRP) || decimal.gt(MAX_DROPS)) {
|
|
158
162
|
throw new Error(`${amount.toString()} is an illegal amount`);
|
|
@@ -162,13 +166,13 @@ class Amount extends serialized_type_1.SerializedType {
|
|
|
162
166
|
/**
|
|
163
167
|
* Validate IOU.value amount
|
|
164
168
|
*
|
|
165
|
-
* @param decimal
|
|
169
|
+
* @param decimal BigNumber object representing IOU.value
|
|
166
170
|
* @returns void, but will throw if invalid amount
|
|
167
171
|
*/
|
|
168
172
|
static assertIouIsValid(decimal) {
|
|
169
173
|
if (!decimal.isZero()) {
|
|
170
174
|
const p = decimal.precision();
|
|
171
|
-
const e = decimal.e - 15;
|
|
175
|
+
const e = (decimal.e || 0) - 15;
|
|
172
176
|
if (p > MAX_IOU_PRECISION ||
|
|
173
177
|
e > MAX_IOU_EXPONENT ||
|
|
174
178
|
e < MIN_IOU_EXPONENT) {
|
|
@@ -186,7 +190,7 @@ class Amount extends serialized_type_1.SerializedType {
|
|
|
186
190
|
*/
|
|
187
191
|
static verifyNoDecimal(decimal) {
|
|
188
192
|
const integerNumberString = decimal
|
|
189
|
-
.times(`1e${-(decimal.e - 15)}`)
|
|
193
|
+
.times(`1e${-((decimal.e || 0) - 15)}`)
|
|
190
194
|
.abs()
|
|
191
195
|
.toString();
|
|
192
196
|
if (integerNumberString.indexOf('.') !== -1) {
|
package/dist/types/amount.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"amount.js","sourceRoot":"","sources":["../../src/types/amount.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"amount.js","sourceRoot":"","sources":["../../src/types/amount.ts"],"names":[],"mappings":";;;;;;AAAA,2DAAsD;AAEtD,6CAAwC;AACxC,yCAAqC;AACrC,uDAA8D;AAC9D,oCAAgC;AAChC,gEAAoC;AAEpC;;GAEG;AACH,MAAM,gBAAgB,GAAG,CAAC,EAAE,CAAA;AAC5B,MAAM,gBAAgB,GAAG,EAAE,CAAA;AAC3B,MAAM,iBAAiB,GAAG,EAAE,CAAA;AAC5B,MAAM,SAAS,GAAG,IAAI,sBAAS,CAAC,MAAM,CAAC,CAAA;AACvC,MAAM,OAAO,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;;;;OAKG;IACK,MAAM,CAAC,gBAAgB,CAAC,OAAkB;QAChD,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE;YACrB,MAAM,CAAC,GAAG,OAAO,CAAC,SAAS,EAAE,CAAA;YAC7B,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,CAAA;YAC/B,IACE,CAAC,GAAG,iBAAiB;gBACrB,CAAC,GAAG,gBAAgB;gBACpB,CAAC,GAAG,gBAAgB,EACpB;gBACA,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAA;aAClD;YACD,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,CAAA;SAC9B;IACH,CAAC;IAED;;;;;;OAMG;IACK,MAAM,CAAC,eAAe,CAAC,OAAkB;QAC/C,MAAM,mBAAmB,GAAG,OAAO;aAChC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC;aACtC,GAAG,EAAE;aACL,QAAQ,EAAE,CAAA;QAEb,IAAI,mBAAmB,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE;YAC3C,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAA;SAC9D;IACH,CAAC;IAED;;;;OAIG;IACK,QAAQ;QACd,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAA;IACrC,CAAC;;AAGM,wBAAM;AAzMN,oBAAa,GAAW,IAAI,MAAM,CACvC,eAAM,CAAC,IAAI,CAAC,kBAAkB,EAAE,KAAK,CAAC,CACvC,CAAA"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { BytesList } from '../serdes/binary-serializer';
|
|
2
2
|
import { BinaryParser } from '../serdes/binary-parser';
|
|
3
|
-
import bigInt = require('big-integer');
|
|
4
3
|
import { Buffer } from 'buffer/';
|
|
5
4
|
import { XrplDefinitionsBase } from '../enums';
|
|
6
5
|
type JSON = string | number | boolean | null | undefined | JSON[] | JsonObject;
|
|
@@ -14,7 +13,7 @@ declare class SerializedType {
|
|
|
14
13
|
protected readonly bytes: Buffer;
|
|
15
14
|
constructor(bytes: Buffer);
|
|
16
15
|
static fromParser(parser: BinaryParser, hint?: number): SerializedType;
|
|
17
|
-
static from(value: SerializedType | JSON |
|
|
16
|
+
static from(value: SerializedType | JSON | bigint): SerializedType;
|
|
18
17
|
/**
|
|
19
18
|
* Write the bytes representation of a SerializedType to a BytesList
|
|
20
19
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serialized-type.js","sourceRoot":"","sources":["../../src/types/serialized-type.ts"],"names":[],"mappings":";;;AAAA,mEAAuD;
|
|
1
|
+
{"version":3,"file":"serialized-type.js","sourceRoot":"","sources":["../../src/types/serialized-type.ts"],"names":[],"mappings":";;;AAAA,mEAAuD;AAEvD,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;IAED,MAAM,CAAC,IAAI,CAAC,KAAqC;QAC/C,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAA;QACvC,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IACzB,CAAC;IAED;;;;OAIG;IACH,WAAW,CAAC,IAAe;QACzB,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AAC,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/uint-64.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { UInt } from './uint';
|
|
2
2
|
import { BinaryParser } from '../serdes/binary-parser';
|
|
3
|
-
import bigInt = require('big-integer');
|
|
4
3
|
import { Buffer } from 'buffer/';
|
|
5
4
|
/**
|
|
6
5
|
* Derived UInt class for serializing/deserializing 64 bit UInt
|
|
@@ -16,7 +15,7 @@ declare class UInt64 extends UInt {
|
|
|
16
15
|
* @param val A UInt64, hex-string, bigInt, or number
|
|
17
16
|
* @returns A UInt64 object
|
|
18
17
|
*/
|
|
19
|
-
static from<T extends UInt64 | string |
|
|
18
|
+
static from<T extends UInt64 | string | bigint | number>(val: T): UInt64;
|
|
20
19
|
/**
|
|
21
20
|
* The JSON representation of a UInt64 object
|
|
22
21
|
*
|
|
@@ -28,7 +27,7 @@ declare class UInt64 extends UInt {
|
|
|
28
27
|
*
|
|
29
28
|
* @returns the number represented buy this.bytes
|
|
30
29
|
*/
|
|
31
|
-
valueOf():
|
|
30
|
+
valueOf(): bigint;
|
|
32
31
|
/**
|
|
33
32
|
* Get the bytes representation of the UInt64 object
|
|
34
33
|
*
|
package/dist/types/uint-64.js
CHANGED
|
@@ -2,11 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.UInt64 = void 0;
|
|
4
4
|
const uint_1 = require("./uint");
|
|
5
|
-
const bigInt = require("big-integer");
|
|
6
|
-
const big_integer_1 = require("big-integer");
|
|
7
5
|
const buffer_1 = require("buffer/");
|
|
8
6
|
const HEX_REGEX = /^[a-fA-F0-9]{1,16}$/;
|
|
9
|
-
const mask =
|
|
7
|
+
const mask = BigInt(0x00000000ffffffff);
|
|
10
8
|
/**
|
|
11
9
|
* Derived UInt class for serializing/deserializing 64 bit UInt
|
|
12
10
|
*/
|
|
@@ -32,10 +30,10 @@ class UInt64 extends uint_1.UInt {
|
|
|
32
30
|
if (val < 0) {
|
|
33
31
|
throw new Error('value must be an unsigned integer');
|
|
34
32
|
}
|
|
35
|
-
const number =
|
|
33
|
+
const number = BigInt(val);
|
|
36
34
|
const intBuf = [buffer_1.Buffer.alloc(4), buffer_1.Buffer.alloc(4)];
|
|
37
|
-
intBuf[0].writeUInt32BE(Number(number
|
|
38
|
-
intBuf[1].writeUInt32BE(Number(number
|
|
35
|
+
intBuf[0].writeUInt32BE(Number(number >> BigInt(32)), 0);
|
|
36
|
+
intBuf[1].writeUInt32BE(Number(number & BigInt(mask)), 0);
|
|
39
37
|
return new UInt64(buffer_1.Buffer.concat(intBuf));
|
|
40
38
|
}
|
|
41
39
|
if (typeof val === 'string') {
|
|
@@ -46,10 +44,10 @@ class UInt64 extends uint_1.UInt {
|
|
|
46
44
|
buf = buffer_1.Buffer.from(strBuf, 'hex');
|
|
47
45
|
return new UInt64(buf);
|
|
48
46
|
}
|
|
49
|
-
if (
|
|
47
|
+
if (typeof val === 'bigint') {
|
|
50
48
|
const intBuf = [buffer_1.Buffer.alloc(4), buffer_1.Buffer.alloc(4)];
|
|
51
|
-
intBuf[0].writeUInt32BE(Number(val
|
|
52
|
-
intBuf[1].writeUInt32BE(Number(val
|
|
49
|
+
intBuf[0].writeUInt32BE(Number(val >> BigInt(32)), 0);
|
|
50
|
+
intBuf[1].writeUInt32BE(Number(val & BigInt(mask)), 0);
|
|
53
51
|
return new UInt64(buffer_1.Buffer.concat(intBuf));
|
|
54
52
|
}
|
|
55
53
|
throw new Error('Cannot construct UInt64 from given value');
|
|
@@ -68,9 +66,9 @@ class UInt64 extends uint_1.UInt {
|
|
|
68
66
|
* @returns the number represented buy this.bytes
|
|
69
67
|
*/
|
|
70
68
|
valueOf() {
|
|
71
|
-
const msb =
|
|
72
|
-
const lsb =
|
|
73
|
-
return msb
|
|
69
|
+
const msb = BigInt(this.bytes.slice(0, 4).readUInt32BE(0));
|
|
70
|
+
const lsb = BigInt(this.bytes.slice(4).readUInt32BE(0));
|
|
71
|
+
return (msb << BigInt(32)) | lsb;
|
|
74
72
|
}
|
|
75
73
|
/**
|
|
76
74
|
* Get the bytes representation of the UInt64 object
|
|
@@ -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;AAE7B,oCAAgC;AAEhC,MAAM,SAAS,GAAG,qBAAqB,CAAA;AACvC,MAAM,IAAI,GAAG,MAAM,CAAC,kBAAkB,CAAC,CAAA;AAEvC;;GAEG;AACH,MAAM,MAAO,SAAQ,WAAI;IAIvB,YAAY,KAAa;QACvB,KAAK,CAAC,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,CAAA;IAC5C,CAAC;IAED,MAAM,CAAC,UAAU,CAAC,MAAoB;QACpC,OAAO,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAA;IAC9C,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,IAAI,CAA8C,GAAM;QAC7D,IAAI,GAAG,YAAY,MAAM,EAAE;YACzB,OAAO,GAAG,CAAA;SACX;QAED,IAAI,GAAG,GAAG,eAAM,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;QAEpC,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE;YAC3B,IAAI,GAAG,GAAG,CAAC,EAAE;gBACX,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAA;aACrD;YAED,MAAM,MAAM,GAAG,MAAM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AAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;YAEtD,OAAO,IAAI,MAAM,CAAC,eAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAA;SACzC;QAED,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAA;IAC7D,CAAC;IAED;;;;OAIG;IACH,MAAM;QACJ,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,WAAW,EAAE,CAAA;IACjD,CAAC;IAED;;;;OAIG;IACH,OAAO;QACL,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAA;QAC1D,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAA;QACvD,OAAO,CAAC,GAAG,IAAI,MAAM,CAAC,EAAE,CAAC,CAAC,GAAG,GAAG,CAAA;IAClC,CAAC;IAED;;;;OAIG;IACH,OAAO;QACL,OAAO,IAAI,CAAC,KAAK,CAAA;IACnB,CAAC;;AAGM,wBAAM;AAzFa,YAAK,GAAW,EAAE,GAAG,CAAC,CAAA,CAAC,IAAI;AACrC,oBAAa,GAAW,IAAI,MAAM,CAAC,eAAM,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAA"}
|
package/dist/types/uint.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import bigInt = require('big-integer');
|
|
2
1
|
import { Comparable } from './serialized-type';
|
|
3
2
|
import { Buffer } from 'buffer/';
|
|
4
3
|
/**
|
|
@@ -25,6 +24,6 @@ declare abstract class UInt extends Comparable {
|
|
|
25
24
|
*
|
|
26
25
|
* @returns the value
|
|
27
26
|
*/
|
|
28
|
-
abstract valueOf(): number |
|
|
27
|
+
abstract valueOf(): number | bigint;
|
|
29
28
|
}
|
|
30
29
|
export { UInt };
|
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;AAG9C;;;;;;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,4BAAU;IAGpC,YAAY,KAAa;QACvB,KAAK,CAAC,KAAK,CAAC,CAAA;IACd,CAAC;IAED;;;;;OAKG;IACH,SAAS,CAAC,KAAW;QACnB,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;CAQF;AAEQ,oBAAI"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ripple-binary-codec",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-beta.0",
|
|
4
4
|
"description": "XRP Ledger binary codec",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist/*",
|
|
@@ -11,20 +11,27 @@
|
|
|
11
11
|
"test": "test"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"
|
|
15
|
-
"
|
|
14
|
+
"@xrplf/isomorphic": "^1.0.0-beta.0",
|
|
15
|
+
"bignumber.js": "^9.0.0",
|
|
16
16
|
"buffer": "6.0.3",
|
|
17
|
-
"
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
"ripple-address-codec": "^5.0.0-beta.0"
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"assert": "^2.0.0"
|
|
20
21
|
},
|
|
21
22
|
"scripts": {
|
|
22
23
|
"build": "tsc -b && copyfiles ./src/enums/definitions.json ./dist/enums/",
|
|
23
|
-
"clean": "rm -rf ./dist
|
|
24
|
+
"clean": "rm -rf ./dist ./coverage tsconfig.tsbuildinfo",
|
|
24
25
|
"prepublishOnly": "npm test",
|
|
25
26
|
"test": "npm run build && jest --verbose false --silent=false ./test/*.test.js",
|
|
26
27
|
"lint": "eslint . --ext .ts --ext .test.js"
|
|
27
28
|
},
|
|
29
|
+
"keywords": [
|
|
30
|
+
"ripple",
|
|
31
|
+
"xrp",
|
|
32
|
+
"xrp ledger",
|
|
33
|
+
"xrpl"
|
|
34
|
+
],
|
|
28
35
|
"repository": {
|
|
29
36
|
"type": "git",
|
|
30
37
|
"url": "git@github.com:XRPLF/xrpl.js.git"
|
|
@@ -37,6 +44,7 @@
|
|
|
37
44
|
"readmeFilename": "README.md",
|
|
38
45
|
"prettier": "@xrplf/prettier-config",
|
|
39
46
|
"engines": {
|
|
40
|
-
"node": ">=
|
|
41
|
-
}
|
|
47
|
+
"node": ">= 16"
|
|
48
|
+
},
|
|
49
|
+
"gitHead": "9e30f1892c20a915c47593ffb8c336595804e4e7"
|
|
42
50
|
}
|
package/src/binary.ts
CHANGED
|
@@ -14,7 +14,6 @@ import {
|
|
|
14
14
|
import { STObject } from './types/st-object'
|
|
15
15
|
import { JsonObject } from './types/serialized-type'
|
|
16
16
|
import { Buffer } from 'buffer/'
|
|
17
|
-
import bigInt = require('big-integer')
|
|
18
17
|
|
|
19
18
|
/**
|
|
20
19
|
* Construct a BinaryParser
|
|
@@ -133,7 +132,7 @@ interface ClaimObject extends JsonObject {
|
|
|
133
132
|
* @returns the serialized object with appropriate prefix
|
|
134
133
|
*/
|
|
135
134
|
function signingClaimData(claim: ClaimObject): Buffer {
|
|
136
|
-
const num =
|
|
135
|
+
const num = BigInt(String(claim.amount))
|
|
137
136
|
const prefix = HashPrefix.paymentChannelClaim
|
|
138
137
|
const channel = coreTypes.Hash256.from(claim.channel).toBytes()
|
|
139
138
|
const amount = coreTypes.UInt64.from(num).toBytes()
|
package/src/hashes.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { HashPrefix } from './hash-prefixes'
|
|
2
|
-
import
|
|
3
|
-
import { Hash256 } from './types/hash-256'
|
|
2
|
+
import { Hash256 } from './types'
|
|
4
3
|
import { BytesList } from './serdes/binary-serializer'
|
|
5
4
|
import { Buffer } from 'buffer/'
|
|
5
|
+
import { sha512 } from '@xrplf/isomorphic/sha512'
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Class for hashing with SHA512
|
|
9
9
|
* @extends BytesList So SerializedTypes can write bytes to a Sha512Half
|
|
10
10
|
*/
|
|
11
11
|
class Sha512Half extends BytesList {
|
|
12
|
-
private hash =
|
|
12
|
+
private hash = sha512.create()
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* Construct a new Sha512Hash and write bytes this.hash
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import * as assert from 'assert'
|
|
2
1
|
import { quality, binary, HashPrefix } from './coretypes'
|
|
3
2
|
import { decodeLedgerData } from './ledger-hashes'
|
|
4
3
|
import { ClaimObject } from './binary'
|
|
@@ -27,7 +26,9 @@ const {
|
|
|
27
26
|
* @returns the JSON representation of the transaction
|
|
28
27
|
*/
|
|
29
28
|
function decode(binary: string, definitions?: XrplDefinitionsBase): JsonObject {
|
|
30
|
-
|
|
29
|
+
if (typeof binary !== 'string') {
|
|
30
|
+
throw new Error('binary must be a hex string')
|
|
31
|
+
}
|
|
31
32
|
return binaryToJSON(binary, definitions)
|
|
32
33
|
}
|
|
33
34
|
|
|
@@ -40,7 +41,9 @@ function decode(binary: string, definitions?: XrplDefinitionsBase): JsonObject {
|
|
|
40
41
|
* @returns A hex-string of the encoded transaction
|
|
41
42
|
*/
|
|
42
43
|
function encode(json: object, definitions?: XrplDefinitionsBase): string {
|
|
43
|
-
|
|
44
|
+
if (typeof json !== 'object') {
|
|
45
|
+
throw new Error()
|
|
46
|
+
}
|
|
44
47
|
return serializeObject(json as JsonObject, { definitions })
|
|
45
48
|
.toString('hex')
|
|
46
49
|
.toUpperCase()
|
|
@@ -58,7 +61,9 @@ function encodeForSigning(
|
|
|
58
61
|
json: object,
|
|
59
62
|
definitions?: XrplDefinitionsBase,
|
|
60
63
|
): string {
|
|
61
|
-
|
|
64
|
+
if (typeof json !== 'object') {
|
|
65
|
+
throw new Error()
|
|
66
|
+
}
|
|
62
67
|
return signingData(json as JsonObject, HashPrefix.transactionSig, {
|
|
63
68
|
definitions,
|
|
64
69
|
})
|
|
@@ -75,7 +80,9 @@ function encodeForSigning(
|
|
|
75
80
|
* @returns a hex string of the encoded transaction
|
|
76
81
|
*/
|
|
77
82
|
function encodeForSigningClaim(json: object): string {
|
|
78
|
-
|
|
83
|
+
if (typeof json !== 'object') {
|
|
84
|
+
throw new Error()
|
|
85
|
+
}
|
|
79
86
|
return signingClaimData(json as ClaimObject)
|
|
80
87
|
.toString('hex')
|
|
81
88
|
.toUpperCase()
|
|
@@ -94,8 +101,12 @@ function encodeForMultisigning(
|
|
|
94
101
|
signer: string,
|
|
95
102
|
definitions?: XrplDefinitionsBase,
|
|
96
103
|
): string {
|
|
97
|
-
|
|
98
|
-
|
|
104
|
+
if (typeof json !== 'object') {
|
|
105
|
+
throw new Error()
|
|
106
|
+
}
|
|
107
|
+
if (json['SigningPubKey'] !== '') {
|
|
108
|
+
throw new Error()
|
|
109
|
+
}
|
|
99
110
|
const definitionsOpt = definitions ? { definitions } : undefined
|
|
100
111
|
return multiSigningData(json as JsonObject, signer, definitionsOpt)
|
|
101
112
|
.toString('hex')
|
|
@@ -109,7 +120,9 @@ function encodeForMultisigning(
|
|
|
109
120
|
* @returns a hex-string representing the quality
|
|
110
121
|
*/
|
|
111
122
|
function encodeQuality(value: string): string {
|
|
112
|
-
|
|
123
|
+
if (typeof value !== 'string') {
|
|
124
|
+
throw new Error()
|
|
125
|
+
}
|
|
113
126
|
return quality.encode(value).toString('hex').toUpperCase()
|
|
114
127
|
}
|
|
115
128
|
|
|
@@ -120,7 +133,9 @@ function encodeQuality(value: string): string {
|
|
|
120
133
|
* @returns a string representing the quality
|
|
121
134
|
*/
|
|
122
135
|
function decodeQuality(value: string): string {
|
|
123
|
-
|
|
136
|
+
if (typeof value !== 'string') {
|
|
137
|
+
throw new Error()
|
|
138
|
+
}
|
|
124
139
|
return quality.decode(value).toString()
|
|
125
140
|
}
|
|
126
141
|
|
package/src/ledger-hashes.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import * as assert from 'assert'
|
|
2
1
|
import { ShaMap, ShaMapNode, ShaMapLeaf } from './shamap'
|
|
3
2
|
import { HashPrefix } from './hash-prefixes'
|
|
4
3
|
import { Sha512Half } from './hashes'
|
|
@@ -10,7 +9,6 @@ import { UInt32 } from './types/uint-32'
|
|
|
10
9
|
import { UInt8 } from './types/uint-8'
|
|
11
10
|
import { BinaryParser } from './serdes/binary-parser'
|
|
12
11
|
import { JsonObject } from './types/serialized-type'
|
|
13
|
-
import bigInt = require('big-integer')
|
|
14
12
|
import { XrplDefinitionsBase } from './enums'
|
|
15
13
|
|
|
16
14
|
/**
|
|
@@ -46,7 +44,9 @@ interface transactionItemObject extends JsonObject {
|
|
|
46
44
|
function transactionItemizer(
|
|
47
45
|
json: transactionItemObject,
|
|
48
46
|
): [Hash256, ShaMapNode, undefined] {
|
|
49
|
-
|
|
47
|
+
if (!json.hash) {
|
|
48
|
+
throw new Error()
|
|
49
|
+
}
|
|
50
50
|
const index = Hash256.from(json.hash)
|
|
51
51
|
const item = {
|
|
52
52
|
hashPrefix() {
|
|
@@ -121,7 +121,7 @@ function accountStateHash(param: Array<JsonObject>): Hash256 {
|
|
|
121
121
|
*/
|
|
122
122
|
interface ledgerObject {
|
|
123
123
|
ledger_index: number
|
|
124
|
-
total_coins: string | number |
|
|
124
|
+
total_coins: string | number | bigint
|
|
125
125
|
parent_hash: string
|
|
126
126
|
transaction_hash: string
|
|
127
127
|
account_hash: string
|
|
@@ -140,13 +140,15 @@ interface ledgerObject {
|
|
|
140
140
|
function ledgerHash(header: ledgerObject): Hash256 {
|
|
141
141
|
const hash = new Sha512Half()
|
|
142
142
|
hash.put(HashPrefix.ledgerHeader)
|
|
143
|
-
|
|
144
|
-
|
|
143
|
+
if (
|
|
144
|
+
header.parent_close_time === undefined ||
|
|
145
|
+
header.close_flags === undefined
|
|
146
|
+
) {
|
|
147
|
+
throw new Error()
|
|
148
|
+
}
|
|
145
149
|
|
|
146
150
|
UInt32.from<number>(header.ledger_index).toBytesSink(hash)
|
|
147
|
-
UInt64.from<
|
|
148
|
-
bigInt(String(header.total_coins)),
|
|
149
|
-
).toBytesSink(hash)
|
|
151
|
+
UInt64.from<bigint>(BigInt(String(header.total_coins))).toBytesSink(hash)
|
|
150
152
|
Hash256.from<string>(header.parent_hash).toBytesSink(hash)
|
|
151
153
|
Hash256.from<string>(header.transaction_hash).toBytesSink(hash)
|
|
152
154
|
Hash256.from<string>(header.account_hash).toBytesSink(hash)
|
|
@@ -169,7 +171,9 @@ function decodeLedgerData(
|
|
|
169
171
|
binary: string,
|
|
170
172
|
definitions?: XrplDefinitionsBase,
|
|
171
173
|
): object {
|
|
172
|
-
|
|
174
|
+
if (typeof binary !== 'string') {
|
|
175
|
+
throw new Error('binary must be a hex string')
|
|
176
|
+
}
|
|
173
177
|
const parser = new BinaryParser(binary, definitions)
|
|
174
178
|
return {
|
|
175
179
|
ledger_index: parser.readUInt32(),
|
package/src/quality.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { coreTypes } from './types'
|
|
2
|
-
import { Decimal } from 'decimal.js'
|
|
3
|
-
import bigInt = require('big-integer')
|
|
4
2
|
import { Buffer } from 'buffer/'
|
|
3
|
+
import BigNumber from 'bignumber.js'
|
|
5
4
|
|
|
6
5
|
/**
|
|
7
6
|
* class for encoding and decoding quality
|
|
@@ -14,10 +13,10 @@ class quality {
|
|
|
14
13
|
* @returns Serialized quality
|
|
15
14
|
*/
|
|
16
15
|
static encode(quality: string): Buffer {
|
|
17
|
-
const decimal =
|
|
18
|
-
const exponent = decimal
|
|
16
|
+
const decimal = BigNumber(quality)
|
|
17
|
+
const exponent = (decimal?.e || 0) - 15
|
|
19
18
|
const qualityString = decimal.times(`1e${-exponent}`).abs().toString()
|
|
20
|
-
const bytes = coreTypes.UInt64.from(
|
|
19
|
+
const bytes = coreTypes.UInt64.from(BigInt(qualityString)).toBytes()
|
|
21
20
|
bytes[0] = exponent + 100
|
|
22
21
|
return bytes
|
|
23
22
|
}
|
|
@@ -28,10 +27,10 @@ class quality {
|
|
|
28
27
|
* @param arg hex-string denoting serialized quality
|
|
29
28
|
* @returns deserialized quality
|
|
30
29
|
*/
|
|
31
|
-
static decode(quality: string):
|
|
30
|
+
static decode(quality: string): BigNumber {
|
|
32
31
|
const bytes = Buffer.from(quality, 'hex').slice(-8)
|
|
33
32
|
const exponent = bytes[0] - 100
|
|
34
|
-
const mantissa = new
|
|
33
|
+
const mantissa = new BigNumber(`0x${bytes.slice(1).toString('hex')}`)
|
|
35
34
|
return mantissa.times(`1e${exponent}`)
|
|
36
35
|
}
|
|
37
36
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import * as assert from 'assert'
|
|
2
1
|
import {
|
|
3
2
|
XrplDefinitionsBase,
|
|
4
3
|
DEFAULT_DEFINITIONS,
|
|
@@ -35,7 +34,9 @@ class BinaryParser {
|
|
|
35
34
|
* @returns The first byte of the BinaryParser
|
|
36
35
|
*/
|
|
37
36
|
peek(): number {
|
|
38
|
-
|
|
37
|
+
if (this.bytes.byteLength === 0) {
|
|
38
|
+
throw new Error()
|
|
39
|
+
}
|
|
39
40
|
return this.bytes[0]
|
|
40
41
|
}
|
|
41
42
|
|
|
@@ -45,7 +46,9 @@ class BinaryParser {
|
|
|
45
46
|
* @param n the number of bytes to skip
|
|
46
47
|
*/
|
|
47
48
|
skip(n: number): void {
|
|
48
|
-
|
|
49
|
+
if (n > this.bytes.byteLength) {
|
|
50
|
+
throw new Error()
|
|
51
|
+
}
|
|
49
52
|
this.bytes = this.bytes.slice(n)
|
|
50
53
|
}
|
|
51
54
|
|
|
@@ -56,7 +59,9 @@ class BinaryParser {
|
|
|
56
59
|
* @return The bytes
|
|
57
60
|
*/
|
|
58
61
|
read(n: number): Buffer {
|
|
59
|
-
|
|
62
|
+
if (n > this.bytes.byteLength) {
|
|
63
|
+
throw new Error()
|
|
64
|
+
}
|
|
60
65
|
|
|
61
66
|
const slice = this.bytes.slice(0, n)
|
|
62
67
|
this.skip(n)
|
|
@@ -70,7 +75,9 @@ class BinaryParser {
|
|
|
70
75
|
* @return The number represented by those bytes
|
|
71
76
|
*/
|
|
72
77
|
readUIntN(n: number): number {
|
|
73
|
-
|
|
78
|
+
if (0 >= n || n > 4) {
|
|
79
|
+
throw new Error('invalid n')
|
|
80
|
+
}
|
|
74
81
|
return this.read(n).reduce((a, b) => (a << 8) | b) >>> 0
|
|
75
82
|
}
|
|
76
83
|
|