@transia/ripple-binary-codec 1.4.4-alpha.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/LICENSE +13 -0
- package/README.md +107 -0
- package/dist/binary.d.ts +91 -0
- package/dist/binary.js +128 -0
- package/dist/binary.js.map +1 -0
- package/dist/coretypes.d.ts +9 -0
- package/dist/coretypes.js +48 -0
- package/dist/coretypes.js.map +1 -0
- package/dist/enums/bytes.d.ts +26 -0
- package/dist/enums/bytes.js +64 -0
- package/dist/enums/bytes.js.map +1 -0
- package/dist/enums/constants.d.ts +4 -0
- package/dist/enums/constants.js +8 -0
- package/dist/enums/constants.js.map +1 -0
- package/dist/enums/definitions.json +2476 -0
- package/dist/enums/field.d.ts +29 -0
- package/dist/enums/field.js +59 -0
- package/dist/enums/field.js.map +1 -0
- package/dist/enums/index.d.ts +13 -0
- package/dist/enums/index.js +53 -0
- package/dist/enums/index.js.map +1 -0
- package/dist/enums/src/enums/definitions.json +2481 -0
- package/dist/enums/utils-renumber.d.ts +101 -0
- package/dist/enums/utils-renumber.js +127 -0
- package/dist/enums/utils-renumber.js.map +1 -0
- package/dist/enums/xrpl-definitions-base.d.ts +45 -0
- package/dist/enums/xrpl-definitions-base.js +63 -0
- package/dist/enums/xrpl-definitions-base.js.map +1 -0
- package/dist/enums/xrpl-definitions.d.ts +21 -0
- package/dist/enums/xrpl-definitions.js +29 -0
- package/dist/enums/xrpl-definitions.js.map +1 -0
- package/dist/hash-prefixes.d.ts +6 -0
- package/dist/hash-prefixes.js +41 -0
- package/dist/hash-prefixes.js.map +1 -0
- package/dist/hashes.d.ts +51 -0
- package/dist/hashes.js +77 -0
- package/dist/hashes.js.map +1 -0
- package/dist/index.d.ts +64 -0
- package/dist/index.js +139 -0
- package/dist/index.js.map +1 -0
- package/dist/ledger-hashes.d.ts +49 -0
- package/dist/ledger-hashes.js +160 -0
- package/dist/ledger-hashes.js.map +1 -0
- package/dist/quality.d.ts +22 -0
- package/dist/quality.js +40 -0
- package/dist/quality.js.map +1 -0
- package/dist/serdes/binary-parser.d.ts +101 -0
- package/dist/serdes/binary-parser.js +210 -0
- package/dist/serdes/binary-parser.js.map +1 -0
- package/dist/serdes/binary-serializer.d.ts +82 -0
- package/dist/serdes/binary-serializer.js +172 -0
- package/dist/serdes/binary-serializer.js.map +1 -0
- package/dist/shamap.d.ts +103 -0
- package/dist/shamap.js +172 -0
- package/dist/shamap.js.map +1 -0
- package/dist/types/account-id.d.ts +36 -0
- package/dist/types/account-id.js +71 -0
- package/dist/types/account-id.js.map +1 -0
- package/dist/types/amount.d.ts +68 -0
- package/dist/types/amount.js +207 -0
- package/dist/types/amount.js.map +1 -0
- package/dist/types/blob.d.ts +25 -0
- package/dist/types/blob.js +40 -0
- package/dist/types/blob.js.map +1 -0
- package/dist/types/currency.d.ts +29 -0
- package/dist/types/currency.js +127 -0
- package/dist/types/currency.js.map +1 -0
- package/dist/types/hash-128.d.ts +17 -0
- package/dist/types/hash-128.js +32 -0
- package/dist/types/hash-128.js.map +1 -0
- package/dist/types/hash-160.d.ts +11 -0
- package/dist/types/hash-160.js +20 -0
- package/dist/types/hash-160.js.map +1 -0
- package/dist/types/hash-256.d.ts +11 -0
- package/dist/types/hash-256.js +17 -0
- package/dist/types/hash-256.js.map +1 -0
- package/dist/types/hash.d.ts +41 -0
- package/dist/types/hash.js +72 -0
- package/dist/types/hash.js.map +1 -0
- package/dist/types/index.d.ts +18 -0
- package/dist/types/index.js +57 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/issue.d.ts +39 -0
- package/dist/types/issue.js +81 -0
- package/dist/types/issue.js.map +1 -0
- package/dist/types/path-set.d.ts +36 -0
- package/dist/types/path-set.js +233 -0
- package/dist/types/path-set.js.map +1 -0
- package/dist/types/serialized-type.d.ts +63 -0
- package/dist/types/serialized-type.js +97 -0
- package/dist/types/serialized-type.js.map +1 -0
- package/dist/types/st-array.d.ts +28 -0
- package/dist/types/st-array.js +80 -0
- package/dist/types/st-array.js.map +1 -0
- package/dist/types/st-object.d.ts +32 -0
- package/dist/types/st-object.js +149 -0
- package/dist/types/st-object.js.map +1 -0
- package/dist/types/uint-16.d.ts +25 -0
- package/dist/types/uint-16.js +44 -0
- package/dist/types/uint-16.js.map +1 -0
- package/dist/types/uint-32.d.ts +25 -0
- package/dist/types/uint-32.js +49 -0
- package/dist/types/uint-32.js.map +1 -0
- package/dist/types/uint-64.d.ts +39 -0
- package/dist/types/uint-64.js +87 -0
- package/dist/types/uint-64.js.map +1 -0
- package/dist/types/uint-8.d.ts +25 -0
- package/dist/types/uint-8.js +44 -0
- package/dist/types/uint-8.js.map +1 -0
- package/dist/types/uint.d.ts +30 -0
- package/dist/types/uint.js +42 -0
- package/dist/types/uint.js.map +1 -0
- package/dist/types/vector-256.d.ts +31 -0
- package/dist/types/vector-256.js +75 -0
- package/dist/types/vector-256.js.map +1 -0
- package/package.json +47 -0
- package/test/amount.test.js +43 -0
- package/test/binary-json.test.js +45 -0
- package/test/binary-parser.test.js +396 -0
- package/test/binary-serializer.test.js +289 -0
- package/test/definitions.test.js +100 -0
- package/test/fixtures/account-tx-transactions.db +0 -0
- package/test/fixtures/codec-fixtures.json +4466 -0
- package/test/fixtures/data-driven-tests.json +2919 -0
- package/test/fixtures/delivermin-tx-binary.json +1 -0
- package/test/fixtures/delivermin-tx.json +98 -0
- package/test/fixtures/deposit-preauth-tx-binary.json +1 -0
- package/test/fixtures/deposit-preauth-tx-meta-binary.json +1 -0
- package/test/fixtures/deposit-preauth-tx.json +58 -0
- package/test/fixtures/escrow-cancel-binary.json +1 -0
- package/test/fixtures/escrow-cancel-tx.json +6 -0
- package/test/fixtures/escrow-create-binary.json +1 -0
- package/test/fixtures/escrow-create-tx.json +10 -0
- package/test/fixtures/escrow-finish-binary.json +1 -0
- package/test/fixtures/escrow-finish-meta-binary.json +1 -0
- package/test/fixtures/escrow-finish-tx.json +95 -0
- package/test/fixtures/ledger-full-38129.json +1 -0
- package/test/fixtures/ledger-full-40000.json +1 -0
- package/test/fixtures/negative-unl.json +12 -0
- package/test/fixtures/nf-token.json +547 -0
- package/test/fixtures/payment-channel-claim-binary.json +1 -0
- package/test/fixtures/payment-channel-claim-tx.json +8 -0
- package/test/fixtures/payment-channel-create-binary.json +1 -0
- package/test/fixtures/payment-channel-create-tx.json +11 -0
- package/test/fixtures/payment-channel-fund-binary.json +1 -0
- package/test/fixtures/payment-channel-fund-tx.json +7 -0
- package/test/fixtures/signerlistset-tx-binary.json +1 -0
- package/test/fixtures/signerlistset-tx-meta-binary.json +1 -0
- package/test/fixtures/signerlistset-tx.json +94 -0
- package/test/fixtures/ticket-create-binary.json +1 -0
- package/test/fixtures/ticket-create-tx.json +7 -0
- package/test/fixtures/x-codec-fixtures.json +188 -0
- package/test/hash.test.js +135 -0
- package/test/ledger.test.js +29 -0
- package/test/lower-case-hex.test.js +46 -0
- package/test/pseudo-transaction.test.js +38 -0
- package/test/quality.test.js +15 -0
- package/test/shamap.test.js +89 -0
- package/test/signing-data-encoding.test.js +242 -0
- package/test/tx-encode-decode.test.js +119 -0
- package/test/types.test.js +34 -0
- package/test/uint.test.js +148 -0
- package/test/utils.js +30 -0
- package/test/x-address.test.js +181 -0
package/dist/shamap.js
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ShaMapLeaf = exports.ShaMapNode = exports.ShaMap = void 0;
|
|
4
|
+
const assert_1 = require("assert");
|
|
5
|
+
const types_1 = require("./types");
|
|
6
|
+
const hash_prefixes_1 = require("./hash-prefixes");
|
|
7
|
+
const hashes_1 = require("./hashes");
|
|
8
|
+
const buffer_1 = require("buffer/");
|
|
9
|
+
/**
|
|
10
|
+
* Abstract class describing a SHAMapNode
|
|
11
|
+
*/
|
|
12
|
+
class ShaMapNode {
|
|
13
|
+
}
|
|
14
|
+
exports.ShaMapNode = ShaMapNode;
|
|
15
|
+
/**
|
|
16
|
+
* Class describing a Leaf of SHAMap
|
|
17
|
+
*/
|
|
18
|
+
class ShaMapLeaf extends ShaMapNode {
|
|
19
|
+
constructor(index, item) {
|
|
20
|
+
super();
|
|
21
|
+
this.index = index;
|
|
22
|
+
this.item = item;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* @returns true as ShaMapLeaf is a leaf node
|
|
26
|
+
*/
|
|
27
|
+
isLeaf() {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* @returns false as ShaMapLeaf is not an inner node
|
|
32
|
+
*/
|
|
33
|
+
isInner() {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Get the prefix of the this.item
|
|
38
|
+
*
|
|
39
|
+
* @returns The hash prefix, unless this.item is undefined, then it returns an empty Buffer
|
|
40
|
+
*/
|
|
41
|
+
hashPrefix() {
|
|
42
|
+
return this.item === undefined ? buffer_1.Buffer.alloc(0) : this.item.hashPrefix();
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Hash the bytes representation of this
|
|
46
|
+
*
|
|
47
|
+
* @returns hash of this.item concatenated with this.index
|
|
48
|
+
*/
|
|
49
|
+
hash() {
|
|
50
|
+
const hash = hashes_1.Sha512Half.put(this.hashPrefix());
|
|
51
|
+
this.toBytesSink(hash);
|
|
52
|
+
return hash.finish();
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Write the bytes representation of this to a BytesList
|
|
56
|
+
* @param list BytesList to write bytes to
|
|
57
|
+
*/
|
|
58
|
+
toBytesSink(list) {
|
|
59
|
+
if (this.item !== undefined) {
|
|
60
|
+
this.item.toBytesSink(list);
|
|
61
|
+
}
|
|
62
|
+
this.index.toBytesSink(list);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
exports.ShaMapLeaf = ShaMapLeaf;
|
|
66
|
+
/**
|
|
67
|
+
* Class defining an Inner Node of a SHAMap
|
|
68
|
+
*/
|
|
69
|
+
class ShaMapInner extends ShaMapNode {
|
|
70
|
+
constructor(depth = 0) {
|
|
71
|
+
super();
|
|
72
|
+
this.depth = depth;
|
|
73
|
+
this.slotBits = 0;
|
|
74
|
+
this.branches = Array(16);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* @returns true as ShaMapInner is an inner node
|
|
78
|
+
*/
|
|
79
|
+
isInner() {
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* @returns false as ShaMapInner is not a leaf node
|
|
84
|
+
*/
|
|
85
|
+
isLeaf() {
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Get the hash prefix for this node
|
|
90
|
+
*
|
|
91
|
+
* @returns hash prefix describing an inner node
|
|
92
|
+
*/
|
|
93
|
+
hashPrefix() {
|
|
94
|
+
return hash_prefixes_1.HashPrefix.innerNode;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Set a branch of this node to be another node
|
|
98
|
+
*
|
|
99
|
+
* @param slot Slot to add branch to this.branches
|
|
100
|
+
* @param branch Branch to add
|
|
101
|
+
*/
|
|
102
|
+
setBranch(slot, branch) {
|
|
103
|
+
this.slotBits = this.slotBits | (1 << slot);
|
|
104
|
+
this.branches[slot] = branch;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* @returns true if node is empty
|
|
108
|
+
*/
|
|
109
|
+
empty() {
|
|
110
|
+
return this.slotBits === 0;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Compute the hash of this node
|
|
114
|
+
*
|
|
115
|
+
* @returns The hash of this node
|
|
116
|
+
*/
|
|
117
|
+
hash() {
|
|
118
|
+
if (this.empty()) {
|
|
119
|
+
return types_1.coreTypes.Hash256.ZERO_256;
|
|
120
|
+
}
|
|
121
|
+
const hash = hashes_1.Sha512Half.put(this.hashPrefix());
|
|
122
|
+
this.toBytesSink(hash);
|
|
123
|
+
return hash.finish();
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Writes the bytes representation of this node to a BytesList
|
|
127
|
+
*
|
|
128
|
+
* @param list BytesList to write bytes to
|
|
129
|
+
*/
|
|
130
|
+
toBytesSink(list) {
|
|
131
|
+
for (let i = 0; i < this.branches.length; i++) {
|
|
132
|
+
const branch = this.branches[i];
|
|
133
|
+
const hash = branch
|
|
134
|
+
? branch.hash()
|
|
135
|
+
: types_1.coreTypes.Hash256.ZERO_256;
|
|
136
|
+
hash.toBytesSink(list);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Add item to the SHAMap
|
|
141
|
+
*
|
|
142
|
+
* @param index Hash of the index of the item being inserted
|
|
143
|
+
* @param item Item to insert in the map
|
|
144
|
+
* @param leaf Leaf node to insert when branch doesn't exist
|
|
145
|
+
*/
|
|
146
|
+
addItem(index, item, leaf) {
|
|
147
|
+
assert_1.strict.ok(index !== undefined);
|
|
148
|
+
if (index !== undefined) {
|
|
149
|
+
const nibble = index.nibblet(this.depth);
|
|
150
|
+
const existing = this.branches[nibble];
|
|
151
|
+
if (existing === undefined) {
|
|
152
|
+
this.setBranch(nibble, leaf || new ShaMapLeaf(index, item));
|
|
153
|
+
}
|
|
154
|
+
else if (existing instanceof ShaMapLeaf) {
|
|
155
|
+
const newInner = new ShaMapInner(this.depth + 1);
|
|
156
|
+
newInner.addItem(existing.index, undefined, existing);
|
|
157
|
+
newInner.addItem(index, item, leaf);
|
|
158
|
+
this.setBranch(nibble, newInner);
|
|
159
|
+
}
|
|
160
|
+
else if (existing instanceof ShaMapInner) {
|
|
161
|
+
existing.addItem(index, item, leaf);
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
throw new Error('invalid ShaMap.addItem call');
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
class ShaMap extends ShaMapInner {
|
|
170
|
+
}
|
|
171
|
+
exports.ShaMap = ShaM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O,SAAQ,WAAW;CAAG;AAE1B,wBAAM"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Hash160 } from './hash-160';
|
|
2
|
+
import { Buffer } from 'buffer/';
|
|
3
|
+
/**
|
|
4
|
+
* Class defining how to encode and decode an AccountID
|
|
5
|
+
*/
|
|
6
|
+
declare class AccountID extends Hash160 {
|
|
7
|
+
static readonly defaultAccountID: AccountID;
|
|
8
|
+
constructor(bytes?: Buffer);
|
|
9
|
+
/**
|
|
10
|
+
* Defines how to construct an AccountID
|
|
11
|
+
*
|
|
12
|
+
* @param value either an existing AccountID, a hex-string, or a base58 r-Address
|
|
13
|
+
* @returns an AccountID object
|
|
14
|
+
*/
|
|
15
|
+
static from<T extends Hash160 | string>(value: T): AccountID;
|
|
16
|
+
/**
|
|
17
|
+
* Defines how to build an AccountID from a base58 r-Address
|
|
18
|
+
*
|
|
19
|
+
* @param value a base58 r-Address
|
|
20
|
+
* @returns an AccountID object
|
|
21
|
+
*/
|
|
22
|
+
static fromBase58(value: string): AccountID;
|
|
23
|
+
/**
|
|
24
|
+
* Overload of toJSON
|
|
25
|
+
*
|
|
26
|
+
* @returns the base58 string for this AccountID
|
|
27
|
+
*/
|
|
28
|
+
toJSON(): string;
|
|
29
|
+
/**
|
|
30
|
+
* Defines how to encode AccountID into a base58 address
|
|
31
|
+
*
|
|
32
|
+
* @returns the base58 string defined by this.bytes
|
|
33
|
+
*/
|
|
34
|
+
toBase58(): string;
|
|
35
|
+
}
|
|
36
|
+
export { AccountID };
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AccountID = void 0;
|
|
4
|
+
const ripple_address_codec_1 = require("ripple-address-codec");
|
|
5
|
+
const hash_160_1 = require("./hash-160");
|
|
6
|
+
const buffer_1 = require("buffer/");
|
|
7
|
+
const HEX_REGEX = /^[A-F0-9]{40}$/;
|
|
8
|
+
/**
|
|
9
|
+
* Class defining how to encode and decode an AccountID
|
|
10
|
+
*/
|
|
11
|
+
class AccountID extends hash_160_1.Hash160 {
|
|
12
|
+
constructor(bytes) {
|
|
13
|
+
super(bytes !== null && bytes !== void 0 ? bytes : AccountID.defaultAccountID.bytes);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Defines how to construct an AccountID
|
|
17
|
+
*
|
|
18
|
+
* @param value either an existing AccountID, a hex-string, or a base58 r-Address
|
|
19
|
+
* @returns an AccountID object
|
|
20
|
+
*/
|
|
21
|
+
static from(value) {
|
|
22
|
+
if (value instanceof AccountID) {
|
|
23
|
+
return value;
|
|
24
|
+
}
|
|
25
|
+
if (typeof value === 'string') {
|
|
26
|
+
if (value === '') {
|
|
27
|
+
return new AccountID();
|
|
28
|
+
}
|
|
29
|
+
return HEX_REGEX.test(value)
|
|
30
|
+
? new AccountID(buffer_1.Buffer.from(value, 'hex'))
|
|
31
|
+
: this.fromBase58(value);
|
|
32
|
+
}
|
|
33
|
+
throw new Error('Cannot construct AccountID from value given');
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Defines how to build an AccountID from a base58 r-Address
|
|
37
|
+
*
|
|
38
|
+
* @param value a base58 r-Address
|
|
39
|
+
* @returns an AccountID object
|
|
40
|
+
*/
|
|
41
|
+
static fromBase58(value) {
|
|
42
|
+
if ((0, ripple_address_codec_1.isValidXAddress)(value)) {
|
|
43
|
+
const classic = (0, ripple_address_codec_1.xAddressToClassicAddress)(value);
|
|
44
|
+
if (classic.tag !== false)
|
|
45
|
+
throw new Error('Only allowed to have tag on Account or Destination');
|
|
46
|
+
value = classic.classicAddress;
|
|
47
|
+
}
|
|
48
|
+
return new AccountID(buffer_1.Buffer.from((0, ripple_address_codec_1.decodeAccountID)(value)));
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Overload of toJSON
|
|
52
|
+
*
|
|
53
|
+
* @returns the base58 string for this AccountID
|
|
54
|
+
*/
|
|
55
|
+
toJSON() {
|
|
56
|
+
return this.toBase58();
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Defines how to encode AccountID into a base58 address
|
|
60
|
+
*
|
|
61
|
+
* @returns the base58 string defined by this.bytes
|
|
62
|
+
*/
|
|
63
|
+
toBase58() {
|
|
64
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
65
|
+
return (0, ripple_address_codec_1.encodeAccountID)(this.bytes);
|
|
66
|
+
/* eslint-enable @typescript-eslint/no-explicit-any */
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
exports.AccountID = AccountID;
|
|
70
|
+
AccountID.defaultAccountID = new AccountID(buffer_1.Buffer.alloc(20));
|
|
71
|
+
//# sourceMappingURL=account-id.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account-id.js","sourceRoot":"","sources":["../../src/types/account-id.ts"],"names":[],"mappings":";;;AAAA,+DAK6B;AAC7B,yCAAoC;AACpC,oCAAgC;AAEhC,MAAM,SAAS,GAAG,gBAAgB,CAAA;AAElC;;GAEG;AACH,MAAM,SAAU,SAAQ,kBAAO;IAG7B,YAAY,KAAc;QACxB,KAAK,CAAC,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,SAAS,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAA;IAClD,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,IAAI,CAA6B,KAAQ;QAC9C,IAAI,KAAK,YAAY,SAAS,EAAE;YAC9B,OAAO,KAAK,CAAA;SACb;QAED,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;YAC7B,IAAI,KAAK,KAAK,EAAE,EAAE;gBAChB,OAAO,IAAI,SAAS,EAAE,CAAA;aACvB;YAED,OAAO,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC;gBAC1B,CAAC,CAAC,IAAI,SAAS,CAAC,eAAM,CAAC,IAAI,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;gBAC1C,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAA;SAC3B;QAED,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAA;IAChE,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,UAAU,CAAC,KAAa;QAC7B,IAAI,IAAA,sCAAe,EAAC,KAAK,CAAC,EAAE;YAC1B,MAAM,OAAO,GAAG,IAAA,+CAAwB,EAAC,KAAK,CAAC,CAAA;YAE/C,IAAI,OAAO,CAAC,GAAG,KAAK,KAAK;gBACvB,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAA;YAEvE,KAAK,GAAG,OAAO,CAAC,cAAc,CAAA;SAC/B;QAED,OAAO,IAAI,SAAS,CAAC,eAAM,CAAC,IAAI,CAAC,IAAA,sCAAe,EAAC,KAAK,CAAC,CAAC,CAAC,CAAA;IAC3D,CAAC;IAED;;;;OAIG;IACH,MAAM;QACJ,OAAO,IAAI,CAAC,QAAQ,EAAE,CAAA;IACxB,CAAC;IAED;;;;OAIG;IACH,QAAQ;QACN,uDAAuD;QACvD,OAAO,IAAA,sCAAe,EAAC,IAAI,CAAC,KAAY,CAAC,CAAA;QACzC,sDAAsD;IACxD,CAAC;;AAGM,8BAAS;AAtEA,0BAAgB,GAAc,IAAI,SAAS,CAAC,eAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { BinaryParser } from '../serdes/binary-parser';
|
|
2
|
+
import { JsonObject, SerializedType } from './serialized-type';
|
|
3
|
+
import { Buffer } from 'buffer/';
|
|
4
|
+
/**
|
|
5
|
+
* Interface for JSON objects that represent amounts
|
|
6
|
+
*/
|
|
7
|
+
interface AmountObject extends JsonObject {
|
|
8
|
+
value: string;
|
|
9
|
+
currency: string;
|
|
10
|
+
issuer: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Class for serializing/Deserializing Amounts
|
|
14
|
+
*/
|
|
15
|
+
declare class Amount extends SerializedType {
|
|
16
|
+
static defaultAmount: Amount;
|
|
17
|
+
constructor(bytes: Buffer);
|
|
18
|
+
/**
|
|
19
|
+
* Construct an amount from an IOU or string amount
|
|
20
|
+
*
|
|
21
|
+
* @param value An Amount, object representing an IOU, or a string
|
|
22
|
+
* representing an integer amount
|
|
23
|
+
* @returns An Amount object
|
|
24
|
+
*/
|
|
25
|
+
static from<T extends Amount | AmountObject | string>(value: T): Amount;
|
|
26
|
+
/**
|
|
27
|
+
* Read an amount from a BinaryParser
|
|
28
|
+
*
|
|
29
|
+
* @param parser BinaryParser to read the Amount from
|
|
30
|
+
* @returns An Amount object
|
|
31
|
+
*/
|
|
32
|
+
static fromParser(parser: BinaryParser): Amount;
|
|
33
|
+
/**
|
|
34
|
+
* Get the JSON representation of this Amount
|
|
35
|
+
*
|
|
36
|
+
* @returns the JSON interpretation of this.bytes
|
|
37
|
+
*/
|
|
38
|
+
toJSON(): AmountObject | string;
|
|
39
|
+
/**
|
|
40
|
+
* Validate XRP amount
|
|
41
|
+
*
|
|
42
|
+
* @param amount String representing XRP amount
|
|
43
|
+
* @returns void, but will throw if invalid amount
|
|
44
|
+
*/
|
|
45
|
+
private static assertXrpIsValid;
|
|
46
|
+
/**
|
|
47
|
+
* Validate IOU.value amount
|
|
48
|
+
*
|
|
49
|
+
* @param decimal Decimal.js object representing IOU.value
|
|
50
|
+
* @returns void, but will throw if invalid amount
|
|
51
|
+
*/
|
|
52
|
+
private static assertIouIsValid;
|
|
53
|
+
/**
|
|
54
|
+
* Ensure that the value after being multiplied by the exponent does not
|
|
55
|
+
* contain a decimal.
|
|
56
|
+
*
|
|
57
|
+
* @param decimal a Decimal object
|
|
58
|
+
* @returns a string of the object without a decimal
|
|
59
|
+
*/
|
|
60
|
+
private static verifyNoDecimal;
|
|
61
|
+
/**
|
|
62
|
+
* Test if this amount is in units of Native Currency(XRP)
|
|
63
|
+
*
|
|
64
|
+
* @returns true if Native (XRP)
|
|
65
|
+
*/
|
|
66
|
+
private isNative;
|
|
67
|
+
}
|
|
68
|
+
export { Amount, AmountObject };
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Amount = void 0;
|
|
4
|
+
const decimal_js_1 = require("decimal.js");
|
|
5
|
+
const binary_parser_1 = require("../serdes/binary-parser");
|
|
6
|
+
const account_id_1 = require("./account-id");
|
|
7
|
+
const currency_1 = require("./currency");
|
|
8
|
+
const serialized_type_1 = require("./serialized-type");
|
|
9
|
+
const bigInt = require("big-integer");
|
|
10
|
+
const buffer_1 = require("buffer/");
|
|
11
|
+
/**
|
|
12
|
+
* Constants for validating amounts
|
|
13
|
+
*/
|
|
14
|
+
const MIN_IOU_EXPONENT = -96;
|
|
15
|
+
const MAX_IOU_EXPONENT = 80;
|
|
16
|
+
const MAX_IOU_PRECISION = 16;
|
|
17
|
+
const MAX_DROPS = new decimal_js_1.Decimal('1e17');
|
|
18
|
+
const MIN_XRP = new decimal_js_1.Decimal('1e-6');
|
|
19
|
+
const mask = bigInt(0x00000000ffffffff);
|
|
20
|
+
/**
|
|
21
|
+
* decimal.js configuration for Amount IOUs
|
|
22
|
+
*/
|
|
23
|
+
decimal_js_1.Decimal.config({
|
|
24
|
+
toExpPos: MAX_IOU_EXPONENT + MAX_IOU_PRECISION,
|
|
25
|
+
toExpNeg: MIN_IOU_EXPONENT - MAX_IOU_PRECISION,
|
|
26
|
+
});
|
|
27
|
+
/**
|
|
28
|
+
* Type guard for AmountObject
|
|
29
|
+
*/
|
|
30
|
+
function isAmountObject(arg) {
|
|
31
|
+
const keys = Object.keys(arg).sort();
|
|
32
|
+
return (keys.length === 3 &&
|
|
33
|
+
keys[0] === 'currency' &&
|
|
34
|
+
keys[1] === 'issuer' &&
|
|
35
|
+
keys[2] === 'value');
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Class for serializing/Deserializing Amounts
|
|
39
|
+
*/
|
|
40
|
+
class Amount extends serialized_type_1.SerializedType {
|
|
41
|
+
constructor(bytes) {
|
|
42
|
+
super(bytes !== null && bytes !== void 0 ? bytes : Amount.defaultAmount.bytes);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Construct an amount from an IOU or string amount
|
|
46
|
+
*
|
|
47
|
+
* @param value An Amount, object representing an IOU, or a string
|
|
48
|
+
* representing an integer amount
|
|
49
|
+
* @returns An Amount object
|
|
50
|
+
*/
|
|
51
|
+
static from(value) {
|
|
52
|
+
if (value instanceof Amount) {
|
|
53
|
+
return value;
|
|
54
|
+
}
|
|
55
|
+
let amount = buffer_1.Buffer.alloc(8);
|
|
56
|
+
if (typeof value === 'string') {
|
|
57
|
+
Amount.assertXrpIsValid(value);
|
|
58
|
+
const number = bigInt(value);
|
|
59
|
+
const intBuf = [buffer_1.Buffer.alloc(4), buffer_1.Buffer.alloc(4)];
|
|
60
|
+
intBuf[0].writeUInt32BE(Number(number.shiftRight(32)), 0);
|
|
61
|
+
intBuf[1].writeUInt32BE(Number(number.and(mask)), 0);
|
|
62
|
+
amount = buffer_1.Buffer.concat(intBuf);
|
|
63
|
+
amount[0] |= 0x40;
|
|
64
|
+
return new Amount(amount);
|
|
65
|
+
}
|
|
66
|
+
if (isAmountObject(value)) {
|
|
67
|
+
const number = new decimal_js_1.Decimal(value.value);
|
|
68
|
+
Amount.assertIouIsValid(number);
|
|
69
|
+
if (number.isZero()) {
|
|
70
|
+
amount[0] |= 0x80;
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
const integerNumberString = number
|
|
74
|
+
.times(`1e${-(number.e - 15)}`)
|
|
75
|
+
.abs()
|
|
76
|
+
.toString();
|
|
77
|
+
const num = bigInt(integerNumberString);
|
|
78
|
+
const intBuf = [buffer_1.Buffer.alloc(4), buffer_1.Buffer.alloc(4)];
|
|
79
|
+
intBuf[0].writeUInt32BE(Number(num.shiftRight(32)), 0);
|
|
80
|
+
intBuf[1].writeUInt32BE(Number(num.and(mask)), 0);
|
|
81
|
+
amount = buffer_1.Buffer.concat(intBuf);
|
|
82
|
+
amount[0] |= 0x80;
|
|
83
|
+
if (number.gt(new decimal_js_1.Decimal(0))) {
|
|
84
|
+
amount[0] |= 0x40;
|
|
85
|
+
}
|
|
86
|
+
const exponent = number.e - 15;
|
|
87
|
+
const exponentByte = 97 + exponent;
|
|
88
|
+
amount[0] |= exponentByte >>> 2;
|
|
89
|
+
amount[1] |= (exponentByte & 0x03) << 6;
|
|
90
|
+
}
|
|
91
|
+
const currency = currency_1.Currency.from(value.currency).toBytes();
|
|
92
|
+
const issuer = account_id_1.AccountID.from(value.issuer).toBytes();
|
|
93
|
+
return new Amount(buffer_1.Buffer.concat([amount, currency, issuer]));
|
|
94
|
+
}
|
|
95
|
+
throw new Error('Invalid type to construct an Amount');
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Read an amount from a BinaryParser
|
|
99
|
+
*
|
|
100
|
+
* @param parser BinaryParser to read the Amount from
|
|
101
|
+
* @returns An Amount object
|
|
102
|
+
*/
|
|
103
|
+
static fromParser(parser) {
|
|
104
|
+
const isXRP = parser.peek() & 0x80;
|
|
105
|
+
const numBytes = isXRP ? 48 : 8;
|
|
106
|
+
return new Amount(parser.read(numBytes));
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Get the JSON representation of this Amount
|
|
110
|
+
*
|
|
111
|
+
* @returns the JSON interpretation of this.bytes
|
|
112
|
+
*/
|
|
113
|
+
toJSON() {
|
|
114
|
+
if (this.isNative()) {
|
|
115
|
+
const bytes = this.bytes;
|
|
116
|
+
const isPositive = bytes[0] & 0x40;
|
|
117
|
+
const sign = isPositive ? '' : '-';
|
|
118
|
+
bytes[0] &= 0x3f;
|
|
119
|
+
const msb = bigInt(bytes.slice(0, 4).readUInt32BE(0));
|
|
120
|
+
const lsb = bigInt(bytes.slice(4).readUInt32BE(0));
|
|
121
|
+
const num = msb.shiftLeft(32).or(lsb);
|
|
122
|
+
return `${sign}${num.toString()}`;
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
const parser = new binary_parser_1.BinaryParser(this.toString());
|
|
126
|
+
const mantissa = parser.read(8);
|
|
127
|
+
const currency = currency_1.Currency.fromParser(parser);
|
|
128
|
+
const issuer = account_id_1.AccountID.fromParser(parser);
|
|
129
|
+
const b1 = mantissa[0];
|
|
130
|
+
const b2 = mantissa[1];
|
|
131
|
+
const isPositive = b1 & 0x40;
|
|
132
|
+
const sign = isPositive ? '' : '-';
|
|
133
|
+
const exponent = ((b1 & 0x3f) << 2) + ((b2 & 0xff) >> 6) - 97;
|
|
134
|
+
mantissa[0] = 0;
|
|
135
|
+
mantissa[1] &= 0x3f;
|
|
136
|
+
const value = new decimal_js_1.Decimal(`${sign}0x${mantissa.toString('hex')}`).times(`1e${exponent}`);
|
|
137
|
+
Amount.assertIouIsValid(value);
|
|
138
|
+
return {
|
|
139
|
+
value: value.toString(),
|
|
140
|
+
currency: currency.toJSON(),
|
|
141
|
+
issuer: issuer.toJSON(),
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Validate XRP amount
|
|
147
|
+
*
|
|
148
|
+
* @param amount String representing XRP amount
|
|
149
|
+
* @returns void, but will throw if invalid amount
|
|
150
|
+
*/
|
|
151
|
+
static assertXrpIsValid(amount) {
|
|
152
|
+
if (amount.indexOf('.') !== -1) {
|
|
153
|
+
throw new Error(`${amount.toString()} is an illegal amount`);
|
|
154
|
+
}
|
|
155
|
+
const decimal = new decimal_js_1.Decimal(amount);
|
|
156
|
+
if (!decimal.isZero()) {
|
|
157
|
+
if (decimal.lt(MIN_XRP) || decimal.gt(MAX_DROPS)) {
|
|
158
|
+
throw new Error(`${amount.toString()} is an illegal amount`);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Validate IOU.value amount
|
|
164
|
+
*
|
|
165
|
+
* @param decimal Decimal.js object representing IOU.value
|
|
166
|
+
* @returns void, but will throw if invalid amount
|
|
167
|
+
*/
|
|
168
|
+
static assertIouIsValid(decimal) {
|
|
169
|
+
if (!decimal.isZero()) {
|
|
170
|
+
const p = decimal.precision();
|
|
171
|
+
const e = decimal.e - 15;
|
|
172
|
+
if (p > MAX_IOU_PRECISION ||
|
|
173
|
+
e > MAX_IOU_EXPONENT ||
|
|
174
|
+
e < MIN_IOU_EXPONENT) {
|
|
175
|
+
throw new Error('Decimal precision out of range');
|
|
176
|
+
}
|
|
177
|
+
this.verifyNoDecimal(decimal);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Ensure that the value after being multiplied by the exponent does not
|
|
182
|
+
* contain a decimal.
|
|
183
|
+
*
|
|
184
|
+
* @param decimal a Decimal object
|
|
185
|
+
* @returns a string of the object without a decimal
|
|
186
|
+
*/
|
|
187
|
+
static verifyNoDecimal(decimal) {
|
|
188
|
+
const integerNumberString = decimal
|
|
189
|
+
.times(`1e${-(decimal.e - 15)}`)
|
|
190
|
+
.abs()
|
|
191
|
+
.toString();
|
|
192
|
+
if (integerNumberString.indexOf('.') !== -1) {
|
|
193
|
+
throw new Error('Decimal place found in integerNumberString');
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Test if this amount is in units of Native Currency(XRP)
|
|
198
|
+
*
|
|
199
|
+
* @returns true if Native (XRP)
|
|
200
|
+
*/
|
|
201
|
+
isNative() {
|
|
202
|
+
return (this.bytes[0] & 0x80) === 0;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
exports.Amount = Amount;
|
|
206
|
+
Amount.defaultAmount = new Amount(buffer_1.Buffer.from('4000000000000000', 'hex'));
|
|
207
|
+
//# sourceMappingURL=amount.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"amount.js","sourceRoot":"","sources":["../../src/types/amount.ts"],"names":[],"mappings":";;;AAAA,2CAAoC;AAEpC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ACvC,eAAM,CAAC,IAAI,CAAC,kBAAkB,EAAE,KAAK,CAAC,CACvC,CAAA"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { SerializedType } from './serialized-type';
|
|
2
|
+
import { BinaryParser } from '../serdes/binary-parser';
|
|
3
|
+
import { Buffer } from 'buffer/';
|
|
4
|
+
/**
|
|
5
|
+
* Variable length encoded type
|
|
6
|
+
*/
|
|
7
|
+
declare class Blob extends SerializedType {
|
|
8
|
+
constructor(bytes: Buffer);
|
|
9
|
+
/**
|
|
10
|
+
* Defines how to read a Blob from a BinaryParser
|
|
11
|
+
*
|
|
12
|
+
* @param parser The binary parser to read the Blob from
|
|
13
|
+
* @param hint The length of the blob, computed by readVariableLengthLength() and passed in
|
|
14
|
+
* @returns A Blob object
|
|
15
|
+
*/
|
|
16
|
+
static fromParser(parser: BinaryParser, hint: number): Blob;
|
|
17
|
+
/**
|
|
18
|
+
* Create a Blob object from a hex-string
|
|
19
|
+
*
|
|
20
|
+
* @param value existing Blob object or a hex-string
|
|
21
|
+
* @returns A Blob object
|
|
22
|
+
*/
|
|
23
|
+
static from<T extends Blob | string>(value: T): Blob;
|
|
24
|
+
}
|
|
25
|
+
export { Blob };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Blob = void 0;
|
|
4
|
+
const serialized_type_1 = require("./serialized-type");
|
|
5
|
+
const buffer_1 = require("buffer/");
|
|
6
|
+
/**
|
|
7
|
+
* Variable length encoded type
|
|
8
|
+
*/
|
|
9
|
+
class Blob extends serialized_type_1.SerializedType {
|
|
10
|
+
constructor(bytes) {
|
|
11
|
+
super(bytes);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Defines how to read a Blob from a BinaryParser
|
|
15
|
+
*
|
|
16
|
+
* @param parser The binary parser to read the Blob from
|
|
17
|
+
* @param hint The length of the blob, computed by readVariableLengthLength() and passed in
|
|
18
|
+
* @returns A Blob object
|
|
19
|
+
*/
|
|
20
|
+
static fromParser(parser, hint) {
|
|
21
|
+
return new Blob(parser.read(hint));
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Create a Blob object from a hex-string
|
|
25
|
+
*
|
|
26
|
+
* @param value existing Blob object or a hex-string
|
|
27
|
+
* @returns A Blob object
|
|
28
|
+
*/
|
|
29
|
+
static from(value) {
|
|
30
|
+
if (value instanceof Blob) {
|
|
31
|
+
return value;
|
|
32
|
+
}
|
|
33
|
+
if (typeof value === 'string') {
|
|
34
|
+
return new Blob(buffer_1.Buffer.from(value, 'hex'));
|
|
35
|
+
}
|
|
36
|
+
throw new Error('Cannot construct Blob from value given');
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.Blob = Blob;
|
|
40
|
+
//# sourceMappingURL=blob.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"blob.js","sourceRoot":"","sources":["../../src/types/blob.ts"],"names":[],"mappings":";;;AAAA,uDAAkD;AAElD,oCAAgC;AAEhC;;GAEG;AACH,MAAM,IAAK,SAAQ,gCAAc;IAC/B,YAAY,KAAa;QACvB,KAAK,CAAC,KAAK,CAAC,CAAA;IACd,CAAC;IAED;;;;;;OAMG;IACH,MAAM,CAAC,UAAU,CAAC,MAAoB,EAAE,IAAY;QAClD,OAAO,IAAI,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAA;IACpC,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,IAAI,CAA0B,KAAQ;QAC3C,IAAI,KAAK,YAAY,IAAI,EAAE;YACzB,OAAO,KAAK,CAAA;SACb;QAED,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;YAC7B,OAAO,IAAI,IAAI,CAAC,eAAM,CAAC,IAAI,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAA;SAC3C;QAED,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAA;IAC3D,CAAC;CACF;AAEQ,oBAAI"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Hash160 } from './hash-160';
|
|
2
|
+
import { Buffer } from 'buffer/';
|
|
3
|
+
/**
|
|
4
|
+
* Class defining how to encode and decode Currencies
|
|
5
|
+
*/
|
|
6
|
+
declare class Currency extends Hash160 {
|
|
7
|
+
static readonly XRP: Currency;
|
|
8
|
+
private readonly _iso;
|
|
9
|
+
constructor(byteBuf: Buffer);
|
|
10
|
+
/**
|
|
11
|
+
* Return the ISO code of this currency
|
|
12
|
+
*
|
|
13
|
+
* @returns ISO code if it exists, else null
|
|
14
|
+
*/
|
|
15
|
+
iso(): string | null;
|
|
16
|
+
/**
|
|
17
|
+
* Constructs a Currency object
|
|
18
|
+
*
|
|
19
|
+
* @param val Currency object or a string representation of a currency
|
|
20
|
+
*/
|
|
21
|
+
static from<T extends Hash160 | string>(value: T): Currency;
|
|
22
|
+
/**
|
|
23
|
+
* Gets the JSON representation of a currency
|
|
24
|
+
*
|
|
25
|
+
* @returns JSON representation
|
|
26
|
+
*/
|
|
27
|
+
toJSON(): string;
|
|
28
|
+
}
|
|
29
|
+
export { Currency };
|