ripple-binary-codec 0.2.7 → 1.0.0-mpt-beta
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/README.md +104 -2
- package/dist/binary.d.ts +90 -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 +25 -0
- package/dist/enums/bytes.js +63 -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 +2956 -0
- package/dist/enums/field.d.ts +28 -0
- package/dist/enums/field.js +58 -0
- package/dist/enums/field.js.map +1 -0
- package/dist/enums/index.d.ts +12 -0
- package/dist/enums/index.js +31 -0
- package/dist/enums/index.js.map +1 -0
- package/{distrib/npm → dist/enums/src}/enums/definitions.json +1709 -438
- 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 +44 -0
- package/dist/enums/xrpl-definitions-base.js +59 -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 +5 -0
- package/dist/hash-prefixes.js +41 -0
- package/dist/hash-prefixes.js.map +1 -0
- package/dist/hashes.d.ts +50 -0
- package/dist/hashes.js +76 -0
- package/dist/hashes.js.map +1 -0
- package/dist/index.d.ts +64 -0
- package/dist/index.js +123 -0
- package/dist/index.js.map +1 -0
- package/dist/ledger-hashes.d.ts +48 -0
- package/dist/ledger-hashes.js +141 -0
- package/dist/ledger-hashes.js.map +1 -0
- package/dist/quality.d.ts +21 -0
- package/dist/quality.js +42 -0
- package/dist/quality.js.map +1 -0
- package/dist/serdes/binary-parser.d.ts +100 -0
- package/dist/serdes/binary-parser.js +194 -0
- package/dist/serdes/binary-parser.js.map +1 -0
- package/dist/serdes/binary-serializer.d.ts +81 -0
- package/dist/serdes/binary-serializer.js +149 -0
- package/dist/serdes/binary-serializer.js.map +1 -0
- package/dist/shamap.d.ts +102 -0
- package/dist/shamap.js +172 -0
- package/dist/shamap.js.map +1 -0
- package/dist/src/binary.d.ts +90 -0
- package/dist/src/binary.js +128 -0
- package/dist/src/binary.js.map +1 -0
- package/dist/src/coretypes.d.ts +9 -0
- package/dist/src/coretypes.js +48 -0
- package/dist/src/coretypes.js.map +1 -0
- package/dist/src/enums/bytes.d.ts +25 -0
- package/dist/src/enums/bytes.js +63 -0
- package/dist/src/enums/bytes.js.map +1 -0
- package/dist/src/enums/constants.d.ts +4 -0
- package/dist/src/enums/constants.js +8 -0
- package/dist/src/enums/constants.js.map +1 -0
- package/dist/src/enums/definitions.json +2956 -0
- package/dist/src/enums/field.d.ts +28 -0
- package/dist/src/enums/field.js +58 -0
- package/dist/src/enums/field.js.map +1 -0
- package/dist/src/enums/index.d.ts +12 -0
- package/dist/src/enums/index.js +31 -0
- package/dist/src/enums/index.js.map +1 -0
- package/dist/src/enums/utils-renumber.d.ts +101 -0
- package/dist/src/enums/utils-renumber.js +127 -0
- package/dist/src/enums/utils-renumber.js.map +1 -0
- package/dist/src/enums/xrpl-definitions-base.d.ts +44 -0
- package/dist/src/enums/xrpl-definitions-base.js +59 -0
- package/dist/src/enums/xrpl-definitions-base.js.map +1 -0
- package/dist/src/enums/xrpl-definitions.d.ts +21 -0
- package/dist/src/enums/xrpl-definitions.js +29 -0
- package/dist/src/enums/xrpl-definitions.js.map +1 -0
- package/dist/src/hash-prefixes.d.ts +5 -0
- package/dist/src/hash-prefixes.js +41 -0
- package/dist/src/hash-prefixes.js.map +1 -0
- package/dist/src/hashes.d.ts +50 -0
- package/dist/src/hashes.js +76 -0
- package/dist/src/hashes.js.map +1 -0
- package/dist/src/index.d.ts +64 -0
- package/dist/src/index.js +123 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/ledger-hashes.d.ts +48 -0
- package/dist/src/ledger-hashes.js +141 -0
- package/dist/src/ledger-hashes.js.map +1 -0
- package/dist/src/quality.d.ts +21 -0
- package/dist/src/quality.js +42 -0
- package/dist/src/quality.js.map +1 -0
- package/dist/src/serdes/binary-parser.d.ts +100 -0
- package/dist/src/serdes/binary-parser.js +194 -0
- package/dist/src/serdes/binary-parser.js.map +1 -0
- package/dist/src/serdes/binary-serializer.d.ts +81 -0
- package/dist/src/serdes/binary-serializer.js +149 -0
- package/dist/src/serdes/binary-serializer.js.map +1 -0
- package/dist/src/shamap.d.ts +102 -0
- package/dist/src/shamap.js +172 -0
- package/dist/src/shamap.js.map +1 -0
- package/dist/src/types/account-id.d.ts +35 -0
- package/dist/src/types/account-id.js +69 -0
- package/dist/src/types/account-id.js.map +1 -0
- package/dist/src/types/amount.d.ts +91 -0
- package/dist/src/types/amount.js +289 -0
- package/dist/src/types/amount.js.map +1 -0
- package/dist/src/types/blob.d.ts +24 -0
- package/dist/src/types/blob.js +40 -0
- package/dist/src/types/blob.js.map +1 -0
- package/dist/src/types/currency.d.ts +28 -0
- package/dist/src/types/currency.js +127 -0
- package/dist/src/types/currency.js.map +1 -0
- package/dist/src/types/hash-128.d.ts +16 -0
- package/dist/src/types/hash-128.js +32 -0
- package/dist/src/types/hash-128.js.map +1 -0
- package/dist/src/types/hash-160.d.ts +10 -0
- package/dist/src/types/hash-160.js +19 -0
- package/dist/src/types/hash-160.js.map +1 -0
- package/dist/src/types/hash-192.d.ts +10 -0
- package/dist/src/types/hash-192.js +19 -0
- package/dist/src/types/hash-192.js.map +1 -0
- package/dist/src/types/hash-256.d.ts +10 -0
- package/dist/src/types/hash-256.js +16 -0
- package/dist/src/types/hash-256.js.map +1 -0
- package/dist/src/types/hash.d.ts +40 -0
- package/dist/src/types/hash.js +73 -0
- package/dist/src/types/hash.js.map +1 -0
- package/dist/src/types/index.d.ts +19 -0
- package/dist/src/types/index.js +64 -0
- package/dist/src/types/index.js.map +1 -0
- package/dist/src/types/issue.d.ts +38 -0
- package/dist/src/types/issue.js +81 -0
- package/dist/src/types/issue.js.map +1 -0
- package/dist/src/types/path-set.d.ts +36 -0
- package/dist/src/types/path-set.js +233 -0
- package/dist/src/types/path-set.js.map +1 -0
- package/dist/src/types/serialized-type.d.ts +70 -0
- package/dist/src/types/serialized-type.js +105 -0
- package/dist/src/types/serialized-type.js.map +1 -0
- package/dist/src/types/st-array.d.ts +31 -0
- package/dist/src/types/st-array.js +83 -0
- package/dist/src/types/st-array.js.map +1 -0
- package/dist/src/types/st-object.d.ts +32 -0
- package/dist/src/types/st-object.js +155 -0
- package/dist/src/types/st-object.js.map +1 -0
- package/dist/src/types/uint-16.d.ts +24 -0
- package/dist/src/types/uint-16.js +45 -0
- package/dist/src/types/uint-16.js.map +1 -0
- package/dist/src/types/uint-32.d.ts +24 -0
- package/dist/src/types/uint-32.js +50 -0
- package/dist/src/types/uint-32.js.map +1 -0
- package/dist/src/types/uint-64.d.ts +37 -0
- package/dist/src/types/uint-64.js +86 -0
- package/dist/src/types/uint-64.js.map +1 -0
- package/dist/src/types/uint-8.d.ts +24 -0
- package/dist/src/types/uint-8.js +46 -0
- package/dist/src/types/uint-8.js.map +1 -0
- package/dist/src/types/uint.d.ts +29 -0
- package/dist/src/types/uint.js +47 -0
- package/dist/src/types/uint.js.map +1 -0
- package/dist/src/types/vector-256.d.ts +30 -0
- package/dist/src/types/vector-256.js +73 -0
- package/dist/src/types/vector-256.js.map +1 -0
- package/dist/src/types/xchain-bridge.d.ts +44 -0
- package/dist/src/types/xchain-bridge.js +102 -0
- package/dist/src/types/xchain-bridge.js.map +1 -0
- package/dist/src/utils.d.ts +47 -0
- package/dist/src/utils.js +137 -0
- package/dist/src/utils.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types/account-id.d.ts +35 -0
- package/dist/types/account-id.js +69 -0
- package/dist/types/account-id.js.map +1 -0
- package/dist/types/amount.d.ts +91 -0
- package/dist/types/amount.js +289 -0
- package/dist/types/amount.js.map +1 -0
- package/dist/types/blob.d.ts +24 -0
- package/dist/types/blob.js +40 -0
- package/dist/types/blob.js.map +1 -0
- package/dist/types/currency.d.ts +28 -0
- package/dist/types/currency.js +127 -0
- package/dist/types/currency.js.map +1 -0
- package/dist/types/hash-128.d.ts +16 -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 +10 -0
- package/dist/types/hash-160.js +19 -0
- package/dist/types/hash-160.js.map +1 -0
- package/dist/types/hash-192.d.ts +10 -0
- package/dist/types/hash-192.js +19 -0
- package/dist/types/hash-192.js.map +1 -0
- package/dist/types/hash-256.d.ts +10 -0
- package/dist/types/hash-256.js +16 -0
- package/dist/types/hash-256.js.map +1 -0
- package/dist/types/hash.d.ts +40 -0
- package/dist/types/hash.js +73 -0
- package/dist/types/hash.js.map +1 -0
- package/dist/types/index.d.ts +19 -0
- package/dist/types/index.js +64 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/issue.d.ts +38 -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 +70 -0
- package/dist/types/serialized-type.js +105 -0
- package/dist/types/serialized-type.js.map +1 -0
- package/dist/types/st-array.d.ts +31 -0
- package/dist/types/st-array.js +83 -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 +155 -0
- package/dist/types/st-object.js.map +1 -0
- package/dist/types/uint-16.d.ts +24 -0
- package/dist/types/uint-16.js +45 -0
- package/dist/types/uint-16.js.map +1 -0
- package/dist/types/uint-32.d.ts +24 -0
- package/dist/types/uint-32.js +50 -0
- package/dist/types/uint-32.js.map +1 -0
- package/dist/types/uint-64.d.ts +37 -0
- package/dist/types/uint-64.js +86 -0
- package/dist/types/uint-64.js.map +1 -0
- package/dist/types/uint-8.d.ts +24 -0
- package/dist/types/uint-8.js +46 -0
- package/dist/types/uint-8.js.map +1 -0
- package/dist/types/uint.d.ts +29 -0
- package/dist/types/uint.js +47 -0
- package/dist/types/uint.js.map +1 -0
- package/dist/types/vector-256.d.ts +30 -0
- package/dist/types/vector-256.js +73 -0
- package/dist/types/vector-256.js.map +1 -0
- package/dist/types/xchain-bridge.d.ts +44 -0
- package/dist/types/xchain-bridge.js +102 -0
- package/dist/types/xchain-bridge.js.map +1 -0
- package/dist/utils.d.ts +47 -0
- package/dist/utils.js +137 -0
- package/dist/utils.js.map +1 -0
- package/package.json +28 -33
- package/src/README.md +5 -0
- package/src/binary.ts +194 -0
- package/src/coretypes.ts +31 -0
- package/src/enums/README.md +144 -0
- package/src/enums/bytes.ts +74 -0
- package/src/enums/constants.ts +4 -0
- package/src/enums/definitions.json +2961 -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 +111 -0
- package/src/enums/xrpl-definitions.ts +32 -0
- package/src/hash-prefixes.ts +40 -0
- package/src/hashes.ts +75 -0
- package/src/index.ts +153 -0
- package/src/ledger-hashes.ts +191 -0
- package/src/quality.ts +38 -0
- package/src/serdes/binary-parser.ts +224 -0
- package/src/serdes/binary-serializer.ts +166 -0
- package/src/shamap.ts +186 -0
- package/src/types/account-id.ts +86 -0
- package/src/types/amount.ts +362 -0
- package/src/types/blob.ts +43 -0
- package/src/types/currency.ts +140 -0
- package/src/types/hash-128.ts +33 -0
- package/src/types/hash-160.ts +19 -0
- package/src/types/hash-192.ts +19 -0
- package/src/types/hash-256.ts +15 -0
- package/src/types/hash.ts +83 -0
- package/src/types/index.ts +66 -0
- package/src/types/issue.ts +96 -0
- package/src/types/path-set.ts +290 -0
- package/src/types/serialized-type.ts +122 -0
- package/src/types/st-array.ts +107 -0
- package/src/types/st-object.ts +192 -0
- package/src/types/uint-16.ts +53 -0
- package/src/types/uint-32.ts +59 -0
- package/src/types/uint-64.ts +104 -0
- package/src/types/uint-8.ts +52 -0
- package/src/types/uint.ts +60 -0
- package/src/types/vector-256.ts +79 -0
- package/src/types/xchain-bridge.ts +128 -0
- package/src/utils.ts +152 -0
- package/HISTORY.md +0 -66
- package/distrib/npm/binary.js +0 -68
- package/distrib/npm/coretypes.js +0 -22
- package/distrib/npm/enums/index.js +0 -125
- package/distrib/npm/enums/utils-renumber.js +0 -134
- package/distrib/npm/hash-prefixes.js +0 -30
- package/distrib/npm/hashes.js +0 -42
- package/distrib/npm/index.js +0 -72
- package/distrib/npm/ledger-hashes.js +0 -71
- package/distrib/npm/quality.js +0 -20
- package/distrib/npm/serdes/binary-parser.js +0 -98
- package/distrib/npm/serdes/binary-serializer.js +0 -106
- package/distrib/npm/shamap.js +0 -107
- package/distrib/npm/types/account-id.js +0 -41
- package/distrib/npm/types/amount.js +0 -215
- package/distrib/npm/types/blob.js +0 -28
- package/distrib/npm/types/currency.js +0 -91
- package/distrib/npm/types/hash-128.js +0 -10
- package/distrib/npm/types/hash-160.js +0 -10
- package/distrib/npm/types/hash-256.js +0 -15
- package/distrib/npm/types/hash.js +0 -45
- package/distrib/npm/types/index.js +0 -45
- package/distrib/npm/types/path-set.js +0 -112
- package/distrib/npm/types/serialized-type.js +0 -63
- package/distrib/npm/types/st-array.js +0 -37
- package/distrib/npm/types/st-object.js +0 -65
- package/distrib/npm/types/uint-16.js +0 -10
- package/distrib/npm/types/uint-32.js +0 -10
- package/distrib/npm/types/uint-64.js +0 -49
- package/distrib/npm/types/uint-8.js +0 -10
- package/distrib/npm/types/uint.js +0 -60
- package/distrib/npm/types/vector-256.js +0 -31
- package/distrib/npm/utils/bytes-utils.js +0 -112
- package/distrib/npm/utils/make-class.js +0 -83
- package/test/amount-test.js +0 -43
- package/test/binary-json-test.js +0 -43
- package/test/binary-parser-test.js +0 -341
- package/test/binary-serializer-test.js +0 -194
- package/test/bytes-utils-test.js +0 -72
- 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 -3721
- 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/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/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/hash-test.js +0 -58
- package/test/ledger-test.js +0 -26
- package/test/mocha.opts +0 -1
- package/test/quality-test.js +0 -16
- package/test/shamap-test.js +0 -88
- package/test/signing-data-encoding-test.js +0 -120
- package/test/tx-encode-decode-test.js +0 -124
- package/test/types-test.js +0 -38
- package/test/uint-test.js +0 -38
- package/test/utils.js +0 -93
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
'use strict';var assert = require('assert');
|
|
2
|
-
var makeClass = require('../utils/make-class');var _require =
|
|
3
|
-
require('../enums'),Field = _require.Field;var _require2 =
|
|
4
|
-
require('../utils/bytes-utils'),slice = _require2.slice,parseBytes = _require2.parseBytes;
|
|
5
|
-
|
|
6
|
-
var BinaryParser = makeClass({
|
|
7
|
-
BinaryParser: function BinaryParser(buf) {
|
|
8
|
-
this._buf = parseBytes(buf, Uint8Array);
|
|
9
|
-
this._length = this._buf.length;
|
|
10
|
-
this._cursor = 0;
|
|
11
|
-
},
|
|
12
|
-
skip: function skip(n) {
|
|
13
|
-
this._cursor += n;
|
|
14
|
-
},
|
|
15
|
-
read: function read(n) {var to = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Uint8Array;
|
|
16
|
-
var start = this._cursor;
|
|
17
|
-
var end = this._cursor + n;
|
|
18
|
-
assert(end <= this._buf.length);
|
|
19
|
-
this._cursor = end;
|
|
20
|
-
return slice(this._buf, start, end, to);
|
|
21
|
-
},
|
|
22
|
-
readUIntN: function readUIntN(n) {
|
|
23
|
-
return this.read(n, Array).reduce(function (a, b) {return a << 8 | b;}) >>> 0;
|
|
24
|
-
},
|
|
25
|
-
readUInt8: function readUInt8() {
|
|
26
|
-
return this._buf[this._cursor++];
|
|
27
|
-
},
|
|
28
|
-
readUInt16: function readUInt16() {
|
|
29
|
-
return this.readUIntN(2);
|
|
30
|
-
},
|
|
31
|
-
readUInt32: function readUInt32() {
|
|
32
|
-
return this.readUIntN(4);
|
|
33
|
-
},
|
|
34
|
-
pos: function pos() {
|
|
35
|
-
return this._cursor;
|
|
36
|
-
},
|
|
37
|
-
size: function size() {
|
|
38
|
-
return this._buf.length;
|
|
39
|
-
},
|
|
40
|
-
end: function end(customEnd) {
|
|
41
|
-
var cursor = this.pos();
|
|
42
|
-
return cursor >= this._length || customEnd !== null &&
|
|
43
|
-
cursor >= customEnd;
|
|
44
|
-
},
|
|
45
|
-
readVL: function readVL() {
|
|
46
|
-
return this.read(this.readVLLength());
|
|
47
|
-
},
|
|
48
|
-
readVLLength: function readVLLength() {
|
|
49
|
-
var b1 = this.readUInt8();
|
|
50
|
-
if (b1 <= 192) {
|
|
51
|
-
return b1;
|
|
52
|
-
} else if (b1 <= 240) {
|
|
53
|
-
var b2 = this.readUInt8();
|
|
54
|
-
return 193 + (b1 - 193) * 256 + b2;
|
|
55
|
-
} else if (b1 <= 254) {
|
|
56
|
-
var _b = this.readUInt8();
|
|
57
|
-
var b3 = this.readUInt8();
|
|
58
|
-
return 12481 + (b1 - 241) * 65536 + _b * 256 + b3;
|
|
59
|
-
}
|
|
60
|
-
throw new Error('Invalid varint length indicator');
|
|
61
|
-
},
|
|
62
|
-
readFieldOrdinal: function readFieldOrdinal() {
|
|
63
|
-
var tagByte = this.readUInt8();
|
|
64
|
-
var type = (tagByte & 0xF0) >>> 4 || this.readUInt8();
|
|
65
|
-
var nth = tagByte & 0x0F || this.readUInt8();
|
|
66
|
-
return type << 16 | nth;
|
|
67
|
-
},
|
|
68
|
-
readField: function readField() {
|
|
69
|
-
return Field.from(this.readFieldOrdinal());
|
|
70
|
-
},
|
|
71
|
-
readType: function readType(type) {
|
|
72
|
-
return type.fromParser(this);
|
|
73
|
-
},
|
|
74
|
-
typeForField: function typeForField(field) {
|
|
75
|
-
return field.associatedType;
|
|
76
|
-
},
|
|
77
|
-
readFieldValue: function readFieldValue(field) {
|
|
78
|
-
var kls = this.typeForField(field);
|
|
79
|
-
if (!kls) {
|
|
80
|
-
throw new Error('unsupported: (' + field.name + ', ' + field.type.name + ')');
|
|
81
|
-
}
|
|
82
|
-
var sizeHint = field.isVLEncoded ? this.readVLLength() : null;
|
|
83
|
-
var value = kls.fromParser(this, sizeHint);
|
|
84
|
-
if (value === undefined) {
|
|
85
|
-
throw new Error('fromParser for (' +
|
|
86
|
-
field.name + ', ' + field.type.name + ') -> undefined ');
|
|
87
|
-
}
|
|
88
|
-
return value;
|
|
89
|
-
},
|
|
90
|
-
readFieldAndValue: function readFieldAndValue() {
|
|
91
|
-
var field = this.readField();
|
|
92
|
-
return [field, this.readFieldValue(field)];
|
|
93
|
-
} });
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
module.exports = {
|
|
98
|
-
BinaryParser: BinaryParser };
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
'use strict';var assert = require('assert');var _require =
|
|
2
|
-
require('../utils/bytes-utils'),parseBytes = _require.parseBytes,bytesToHex = _require.bytesToHex;
|
|
3
|
-
var makeClass = require('../utils/make-class');var _require2 =
|
|
4
|
-
require('../enums'),Type = _require2.Type,Field = _require2.Field;
|
|
5
|
-
|
|
6
|
-
var BytesSink = {
|
|
7
|
-
put: function put() /* bytesSequence */{
|
|
8
|
-
// any hex string or any object with a `length` and where 0 <= [ix] <= 255
|
|
9
|
-
} };
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
var BytesList = makeClass({
|
|
13
|
-
implementing: BytesSink,
|
|
14
|
-
BytesList: function BytesList() {
|
|
15
|
-
this.arrays = [];
|
|
16
|
-
this.length = 0;
|
|
17
|
-
},
|
|
18
|
-
put: function put(bytesArg) {
|
|
19
|
-
var bytes = parseBytes(bytesArg, Uint8Array);
|
|
20
|
-
this.length += bytes.length;
|
|
21
|
-
this.arrays.push(bytes);
|
|
22
|
-
return this;
|
|
23
|
-
},
|
|
24
|
-
toBytesSink: function toBytesSink(sink) {
|
|
25
|
-
this.arrays.forEach(function (arr) {
|
|
26
|
-
sink.put(arr);
|
|
27
|
-
});
|
|
28
|
-
},
|
|
29
|
-
toBytes: function toBytes() {
|
|
30
|
-
var concatenated = new Uint8Array(this.length);
|
|
31
|
-
var pointer = 0;
|
|
32
|
-
this.arrays.forEach(function (arr) {
|
|
33
|
-
concatenated.set(arr, pointer);
|
|
34
|
-
pointer += arr.length;
|
|
35
|
-
});
|
|
36
|
-
return concatenated;
|
|
37
|
-
},
|
|
38
|
-
toHex: function toHex() {
|
|
39
|
-
return bytesToHex(this.toBytes());
|
|
40
|
-
} });
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
var BinarySerializer = makeClass({
|
|
44
|
-
BinarySerializer: function BinarySerializer(sink) {
|
|
45
|
-
this.sink = sink;
|
|
46
|
-
},
|
|
47
|
-
write: function write(value) {
|
|
48
|
-
value.toBytesSink(this.sink);
|
|
49
|
-
},
|
|
50
|
-
put: function put(bytes) {
|
|
51
|
-
this.sink.put(bytes);
|
|
52
|
-
},
|
|
53
|
-
writeType: function writeType(type, value) {
|
|
54
|
-
this.write(type.from(value));
|
|
55
|
-
},
|
|
56
|
-
writeBytesList: function writeBytesList(bl) {
|
|
57
|
-
bl.toBytesSink(this.sink);
|
|
58
|
-
},
|
|
59
|
-
encodeVL: function encodeVL(len) {
|
|
60
|
-
var length = len;
|
|
61
|
-
var lenBytes = new Uint8Array(4);
|
|
62
|
-
if (length <= 192) {
|
|
63
|
-
lenBytes[0] = length;
|
|
64
|
-
return lenBytes.subarray(0, 1);
|
|
65
|
-
} else if (length <= 12480) {
|
|
66
|
-
length -= 193;
|
|
67
|
-
lenBytes[0] = 193 + (length >>> 8);
|
|
68
|
-
lenBytes[1] = length & 0xff;
|
|
69
|
-
return lenBytes.subarray(0, 2);
|
|
70
|
-
} else if (length <= 918744) {
|
|
71
|
-
length -= 12481;
|
|
72
|
-
lenBytes[0] = 241 + (length >>> 16);
|
|
73
|
-
lenBytes[1] = length >> 8 & 0xff;
|
|
74
|
-
lenBytes[2] = length & 0xff;
|
|
75
|
-
return lenBytes.subarray(0, 3);
|
|
76
|
-
}
|
|
77
|
-
throw new Error('Overflow error');
|
|
78
|
-
},
|
|
79
|
-
writeFieldAndValue: function writeFieldAndValue(field, _value) {
|
|
80
|
-
var sink = this.sink;
|
|
81
|
-
var value = field.associatedType.from(_value);
|
|
82
|
-
assert(value.toBytesSink, field);
|
|
83
|
-
sink.put(field.bytes);
|
|
84
|
-
|
|
85
|
-
if (field.isVLEncoded) {
|
|
86
|
-
this.writeLengthEncoded(value);
|
|
87
|
-
} else {
|
|
88
|
-
value.toBytesSink(sink);
|
|
89
|
-
if (field.type === Type.STObject) {
|
|
90
|
-
sink.put(Field.ObjectEndMarker.bytes);
|
|
91
|
-
} else if (field.type === Type.STArray) {
|
|
92
|
-
sink.put(Field.ArrayEndMarker.bytes);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
},
|
|
96
|
-
writeLengthEncoded: function writeLengthEncoded(value) {
|
|
97
|
-
var bytes = new BytesList();
|
|
98
|
-
value.toBytesSink(bytes);
|
|
99
|
-
this.put(this.encodeVL(bytes.length));
|
|
100
|
-
this.writeBytesList(bytes);
|
|
101
|
-
} });
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
module.exports = {
|
|
105
|
-
BytesList: BytesList,
|
|
106
|
-
BinarySerializer: BinarySerializer };
|
package/distrib/npm/shamap.js
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
'use strict';var assert = require('assert');
|
|
2
|
-
var makeClass = require('./utils/make-class');var _require =
|
|
3
|
-
require('./types'),Hash256 = _require.Hash256;var _require2 =
|
|
4
|
-
require('./hash-prefixes'),HashPrefix = _require2.HashPrefix;var _require3 =
|
|
5
|
-
require('./hashes'),Hasher = _require3.Sha512Half;
|
|
6
|
-
|
|
7
|
-
var ShaMapNode = makeClass({
|
|
8
|
-
virtuals: {
|
|
9
|
-
hashPrefix: function hashPrefix() {},
|
|
10
|
-
isLeaf: function isLeaf() {},
|
|
11
|
-
isInner: function isInner() {} },
|
|
12
|
-
|
|
13
|
-
cached: {
|
|
14
|
-
hash: function hash() {
|
|
15
|
-
var hasher = Hasher.put(this.hashPrefix());
|
|
16
|
-
this.toBytesSink(hasher);
|
|
17
|
-
return hasher.finish();
|
|
18
|
-
} } });
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
var ShaMapLeaf = makeClass({
|
|
23
|
-
inherits: ShaMapNode,
|
|
24
|
-
ShaMapLeaf: function ShaMapLeaf(index, item) {
|
|
25
|
-
ShaMapNode.call(this);
|
|
26
|
-
this.index = index;
|
|
27
|
-
this.item = item;
|
|
28
|
-
},
|
|
29
|
-
isLeaf: function isLeaf() {
|
|
30
|
-
return true;
|
|
31
|
-
},
|
|
32
|
-
isInner: function isInner() {
|
|
33
|
-
return false;
|
|
34
|
-
},
|
|
35
|
-
hashPrefix: function hashPrefix() {
|
|
36
|
-
return this.item.hashPrefix();
|
|
37
|
-
},
|
|
38
|
-
toBytesSink: function toBytesSink(sink) {
|
|
39
|
-
this.item.toBytesSink(sink);
|
|
40
|
-
this.index.toBytesSink(sink);
|
|
41
|
-
} });
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
var $uper = ShaMapNode.prototype;
|
|
45
|
-
|
|
46
|
-
var ShaMapInner = makeClass({
|
|
47
|
-
inherits: ShaMapNode,
|
|
48
|
-
ShaMapInner: function ShaMapInner() {var depth = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
|
49
|
-
ShaMapNode.call(this);
|
|
50
|
-
this.depth = depth;
|
|
51
|
-
this.slotBits = 0;
|
|
52
|
-
this.branches = Array(16);
|
|
53
|
-
},
|
|
54
|
-
isInner: function isInner() {
|
|
55
|
-
return true;
|
|
56
|
-
},
|
|
57
|
-
isLeaf: function isLeaf() {
|
|
58
|
-
return false;
|
|
59
|
-
},
|
|
60
|
-
hashPrefix: function hashPrefix() {
|
|
61
|
-
return HashPrefix.innerNode;
|
|
62
|
-
},
|
|
63
|
-
setBranch: function setBranch(slot, branch) {
|
|
64
|
-
this.slotBits = this.slotBits | 1 << slot;
|
|
65
|
-
this.branches[slot] = branch;
|
|
66
|
-
},
|
|
67
|
-
empty: function empty() {
|
|
68
|
-
return this.slotBits === 0;
|
|
69
|
-
},
|
|
70
|
-
hash: function hash() {
|
|
71
|
-
if (this.empty()) {
|
|
72
|
-
return Hash256.ZERO_256;
|
|
73
|
-
}
|
|
74
|
-
return $uper.hash.call(this);
|
|
75
|
-
},
|
|
76
|
-
toBytesSink: function toBytesSink(sink) {
|
|
77
|
-
for (var i = 0; i < this.branches.length; i++) {
|
|
78
|
-
var branch = this.branches[i];
|
|
79
|
-
var hash = branch ? branch.hash() : Hash256.ZERO_256;
|
|
80
|
-
hash.toBytesSink(sink);
|
|
81
|
-
}
|
|
82
|
-
},
|
|
83
|
-
addItem: function addItem(index, item, leaf) {
|
|
84
|
-
assert(index instanceof Hash256);
|
|
85
|
-
var nibble = index.nibblet(this.depth);
|
|
86
|
-
var existing = this.branches[nibble];
|
|
87
|
-
if (!existing) {
|
|
88
|
-
this.setBranch(nibble, leaf || new ShaMapLeaf(index, item));
|
|
89
|
-
} else if (existing.isLeaf()) {
|
|
90
|
-
var newInner = new ShaMapInner(this.depth + 1);
|
|
91
|
-
newInner.addItem(existing.index, null, existing);
|
|
92
|
-
newInner.addItem(index, item, leaf);
|
|
93
|
-
this.setBranch(nibble, newInner);
|
|
94
|
-
} else if (existing.isInner()) {
|
|
95
|
-
existing.addItem(index, item, leaf);
|
|
96
|
-
} else {
|
|
97
|
-
assert(false);
|
|
98
|
-
}
|
|
99
|
-
} });
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
var ShaMap = makeClass({
|
|
103
|
-
inherits: ShaMapInner });
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
module.exports = {
|
|
107
|
-
ShaMap: ShaMap };
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
'use strict';var makeClass = require('../utils/make-class');var _require =
|
|
2
|
-
require('ripple-address-codec'),decodeAccountID = _require.decodeAccountID,encodeAccountID = _require.encodeAccountID;var _require2 =
|
|
3
|
-
require('./hash-160'),Hash160 = _require2.Hash160;
|
|
4
|
-
|
|
5
|
-
var AccountID = makeClass({
|
|
6
|
-
AccountID: function AccountID(bytes) {
|
|
7
|
-
Hash160.call(this, bytes);
|
|
8
|
-
},
|
|
9
|
-
inherits: Hash160,
|
|
10
|
-
statics: {
|
|
11
|
-
from: function from(value) {
|
|
12
|
-
return value instanceof this ? value :
|
|
13
|
-
/^r/.test(value) ? this.fromBase58(value) :
|
|
14
|
-
new this(value);
|
|
15
|
-
},
|
|
16
|
-
cache: {},
|
|
17
|
-
fromCache: function fromCache(base58) {
|
|
18
|
-
var cached = this.cache[base58];
|
|
19
|
-
if (!cached) {
|
|
20
|
-
cached = this.cache[base58] = this.fromBase58(base58);
|
|
21
|
-
}
|
|
22
|
-
return cached;
|
|
23
|
-
},
|
|
24
|
-
fromBase58: function fromBase58(value) {
|
|
25
|
-
var acc = new this(decodeAccountID(value));
|
|
26
|
-
acc._toBase58 = value;
|
|
27
|
-
return acc;
|
|
28
|
-
} },
|
|
29
|
-
|
|
30
|
-
toJSON: function toJSON() {
|
|
31
|
-
return this.toBase58();
|
|
32
|
-
},
|
|
33
|
-
cached: {
|
|
34
|
-
toBase58: function toBase58() {
|
|
35
|
-
return encodeAccountID(this._bytes);
|
|
36
|
-
} } });
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
module.exports = {
|
|
41
|
-
AccountID: AccountID };
|
|
@@ -1,215 +0,0 @@
|
|
|
1
|
-
'use strict';var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {return typeof obj;} : function (obj) {return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;};function _toConsumableArray(arr) {if (Array.isArray(arr)) {for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) {arr2[i] = arr[i];}return arr2;} else {return Array.from(arr);}}var _ = require('lodash');
|
|
2
|
-
var assert = require('assert');
|
|
3
|
-
var BN = require('bn.js');
|
|
4
|
-
var Decimal = require('decimal.js');
|
|
5
|
-
var makeClass = require('../utils/make-class');var _require =
|
|
6
|
-
require('./serialized-type'),SerializedType = _require.SerializedType;var _require2 =
|
|
7
|
-
require('../utils/bytes-utils'),bytesToHex = _require2.bytesToHex;var _require3 =
|
|
8
|
-
require('./currency'),Currency = _require3.Currency;var _require4 =
|
|
9
|
-
require('./account-id'),AccountID = _require4.AccountID;var _require5 =
|
|
10
|
-
require('./uint-64'),UInt64 = _require5.UInt64;
|
|
11
|
-
|
|
12
|
-
var MIN_IOU_EXPONENT = -96;
|
|
13
|
-
var MAX_IOU_EXPONENT = 80;
|
|
14
|
-
var MAX_IOU_PRECISION = 16;
|
|
15
|
-
var MIN_IOU_MANTISSA = '1000' + '0000' + '0000' + '0000'; // 16 digits
|
|
16
|
-
var MAX_IOU_MANTISSA = '9999' + '9999' + '9999' + '9999'; // ..
|
|
17
|
-
var MAX_IOU = new Decimal(MAX_IOU_MANTISSA + 'e' + MAX_IOU_EXPONENT);
|
|
18
|
-
var MIN_IOU = new Decimal(MIN_IOU_MANTISSA + 'e' + MIN_IOU_EXPONENT);
|
|
19
|
-
var DROPS_PER_XRP = new Decimal('1e6');
|
|
20
|
-
var MAX_NETWORK_DROPS = new Decimal('1e17');
|
|
21
|
-
var MIN_XRP = new Decimal('1e-6');
|
|
22
|
-
var MAX_XRP = MAX_NETWORK_DROPS.dividedBy(DROPS_PER_XRP);
|
|
23
|
-
|
|
24
|
-
// Never use exponential form
|
|
25
|
-
Decimal.config({
|
|
26
|
-
toExpPos: MAX_IOU_EXPONENT + MAX_IOU_PRECISION,
|
|
27
|
-
toExpNeg: MIN_IOU_EXPONENT - MAX_IOU_PRECISION });
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
var AMOUNT_PARAMETERS_DESCRIPTION = '\nNative values must be described in drops, a million of which equal one XRP.\nThis must be an integer number, with the absolute value not exceeding ' +
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
MAX_NETWORK_DROPS + '\n\nIOU values must have a maximum precision of ' +
|
|
34
|
-
|
|
35
|
-
MAX_IOU_PRECISION + ' significant digits. They are serialized as\na canonicalised mantissa and exponent.\n\nThe valid range for a mantissa is between ' +
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
MIN_IOU_MANTISSA + ' and ' +
|
|
39
|
-
MAX_IOU_MANTISSA + '\nThe exponent must be >= ' +
|
|
40
|
-
MIN_IOU_EXPONENT + ' and <= ' + MAX_IOU_EXPONENT + '\n\nThus the largest serializable IOU value is:\n' +
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
MAX_IOU.toString() + '\n\nAnd the smallest:\n' +
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
MIN_IOU.toString() + '\n';
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
function isDefined(val) {
|
|
50
|
-
return !_.isUndefined(val);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function raiseIllegalAmountError(value) {
|
|
54
|
-
throw new Error(value.toString() + ' is an illegal amount\n' +
|
|
55
|
-
AMOUNT_PARAMETERS_DESCRIPTION);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
var parsers = {
|
|
59
|
-
string: function string(str) {
|
|
60
|
-
// Using /^\d+$/ here fixes #31
|
|
61
|
-
if (!str.match(/^\d+$/)) {
|
|
62
|
-
raiseIllegalAmountError(str);
|
|
63
|
-
}
|
|
64
|
-
return [new Decimal(str).dividedBy(DROPS_PER_XRP), Currency.XRP];
|
|
65
|
-
},
|
|
66
|
-
object: function object(_object) {
|
|
67
|
-
assert(isDefined(_object.currency), 'currency must be defined');
|
|
68
|
-
assert(isDefined(_object.issuer), 'issuer must be defined');
|
|
69
|
-
return [new Decimal(_object.value),
|
|
70
|
-
Currency.from(_object.currency),
|
|
71
|
-
AccountID.from(_object.issuer)];
|
|
72
|
-
} };
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
var Amount = makeClass({
|
|
76
|
-
Amount: function Amount(value, currency, issuer) {var validate = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
|
|
77
|
-
this.value = value || new Decimal('0');
|
|
78
|
-
this.currency = currency || Currency.XRP;
|
|
79
|
-
this.issuer = issuer || null;
|
|
80
|
-
if (validate) {
|
|
81
|
-
this.assertValueIsValid();
|
|
82
|
-
}
|
|
83
|
-
},
|
|
84
|
-
mixins: SerializedType,
|
|
85
|
-
statics: {
|
|
86
|
-
from: function from(value) {
|
|
87
|
-
if (value instanceof this) {
|
|
88
|
-
return value;
|
|
89
|
-
}
|
|
90
|
-
var parser = parsers[typeof value === 'undefined' ? 'undefined' : _typeof(value)];
|
|
91
|
-
if (parser) {
|
|
92
|
-
return new (Function.prototype.bind.apply(this, [null].concat(_toConsumableArray(parser(value)))))();
|
|
93
|
-
}
|
|
94
|
-
throw new Error('unsupported value: ' + value);
|
|
95
|
-
},
|
|
96
|
-
fromParser: function fromParser(parser) {
|
|
97
|
-
var mantissa = parser.read(8);
|
|
98
|
-
var b1 = mantissa[0];
|
|
99
|
-
var b2 = mantissa[1];
|
|
100
|
-
|
|
101
|
-
var isIOU = b1 & 0x80;
|
|
102
|
-
var isPositive = b1 & 0x40;
|
|
103
|
-
var sign = isPositive ? '' : '-';
|
|
104
|
-
|
|
105
|
-
if (isIOU) {
|
|
106
|
-
mantissa[0] = 0;
|
|
107
|
-
var currency = parser.readType(Currency);
|
|
108
|
-
var issuer = parser.readType(AccountID);
|
|
109
|
-
var exponent = ((b1 & 0x3F) << 2) + ((b2 & 0xff) >> 6) - 97;
|
|
110
|
-
mantissa[1] &= 0x3F;
|
|
111
|
-
// decimal.js won't accept e notation with hex
|
|
112
|
-
var value = new Decimal(sign + '0x' + bytesToHex(mantissa)).
|
|
113
|
-
times('1e' + exponent);
|
|
114
|
-
return new this(value, currency, issuer, false);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
mantissa[0] &= 0x3F;
|
|
118
|
-
var drops = new Decimal(sign + '0x' + bytesToHex(mantissa));
|
|
119
|
-
var xrpValue = drops.dividedBy(DROPS_PER_XRP);
|
|
120
|
-
return new this(xrpValue, Currency.XRP, null, false);
|
|
121
|
-
} },
|
|
122
|
-
|
|
123
|
-
assertValueIsValid: function assertValueIsValid() {
|
|
124
|
-
// zero is always a valid amount value
|
|
125
|
-
if (!this.isZero()) {
|
|
126
|
-
if (this.isNative()) {
|
|
127
|
-
var abs = this.value.abs();
|
|
128
|
-
if (abs.lt(MIN_XRP) || abs.gt(MAX_XRP)) {
|
|
129
|
-
// value is in XRP scale, but show the value in canonical json form
|
|
130
|
-
raiseIllegalAmountError(this.value.times(DROPS_PER_XRP));
|
|
131
|
-
}
|
|
132
|
-
this.verifyNoDecimal(this.value); // This is a secondary fix for #31
|
|
133
|
-
} else {
|
|
134
|
-
var p = this.value.precision();
|
|
135
|
-
var e = this.exponent();
|
|
136
|
-
if (p > MAX_IOU_PRECISION ||
|
|
137
|
-
e > MAX_IOU_EXPONENT ||
|
|
138
|
-
e < MIN_IOU_EXPONENT) {
|
|
139
|
-
raiseIllegalAmountError(this.value);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
},
|
|
144
|
-
isNative: function isNative() {
|
|
145
|
-
return this.currency.isNative();
|
|
146
|
-
},
|
|
147
|
-
mantissa: function mantissa() {
|
|
148
|
-
// This is a tertiary fix for #31
|
|
149
|
-
var integerNumberString = this.verifyNoDecimal();
|
|
150
|
-
|
|
151
|
-
return new UInt64(
|
|
152
|
-
new BN(integerNumberString));
|
|
153
|
-
},
|
|
154
|
-
verifyNoDecimal: function verifyNoDecimal() {
|
|
155
|
-
var integerNumberString = this.value.
|
|
156
|
-
times('1e' + -this.exponent()).abs().toString();
|
|
157
|
-
// Ensure that the value (after being multiplied by the exponent)
|
|
158
|
-
// does not contain a decimal. From the bn.js README:
|
|
159
|
-
// "decimals are not supported in this library."
|
|
160
|
-
// eslint-disable-next-line max-len
|
|
161
|
-
// https://github.com/indutny/bn.js/blob/9cb459f044853b46615464eea1a3ddfc7006463b/README.md
|
|
162
|
-
if (integerNumberString.indexOf('.') !== -1) {
|
|
163
|
-
raiseIllegalAmountError(integerNumberString);
|
|
164
|
-
}
|
|
165
|
-
return integerNumberString;
|
|
166
|
-
},
|
|
167
|
-
isZero: function isZero() {
|
|
168
|
-
return this.value.isZero();
|
|
169
|
-
},
|
|
170
|
-
exponent: function exponent() {
|
|
171
|
-
return this.isNative() ? -6 : this.value.e - 15;
|
|
172
|
-
},
|
|
173
|
-
valueString: function valueString() {
|
|
174
|
-
return (this.isNative() ? this.value.times(DROPS_PER_XRP) : this.value).
|
|
175
|
-
toString();
|
|
176
|
-
},
|
|
177
|
-
toBytesSink: function toBytesSink(sink) {
|
|
178
|
-
var isNative = this.isNative();
|
|
179
|
-
var notNegative = !this.value.isNegative();
|
|
180
|
-
var mantissa = this.mantissa().toBytes();
|
|
181
|
-
|
|
182
|
-
if (isNative) {
|
|
183
|
-
mantissa[0] |= notNegative ? 0x40 : 0;
|
|
184
|
-
sink.put(mantissa);
|
|
185
|
-
} else {
|
|
186
|
-
mantissa[0] |= 0x80;
|
|
187
|
-
if (!this.isZero()) {
|
|
188
|
-
if (notNegative) {
|
|
189
|
-
mantissa[0] |= 0x40;
|
|
190
|
-
}
|
|
191
|
-
var exponent = this.value.e - 15;
|
|
192
|
-
var exponentByte = 97 + exponent;
|
|
193
|
-
mantissa[0] |= exponentByte >>> 2;
|
|
194
|
-
mantissa[1] |= (exponentByte & 0x03) << 6;
|
|
195
|
-
}
|
|
196
|
-
sink.put(mantissa);
|
|
197
|
-
this.currency.toBytesSink(sink);
|
|
198
|
-
this.issuer.toBytesSink(sink);
|
|
199
|
-
}
|
|
200
|
-
},
|
|
201
|
-
toJSON: function toJSON() {
|
|
202
|
-
var valueString = this.valueString();
|
|
203
|
-
if (this.isNative()) {
|
|
204
|
-
return valueString;
|
|
205
|
-
}
|
|
206
|
-
return {
|
|
207
|
-
value: valueString,
|
|
208
|
-
currency: this.currency.toJSON(),
|
|
209
|
-
issuer: this.issuer.toJSON() };
|
|
210
|
-
|
|
211
|
-
} });
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
module.exports = {
|
|
215
|
-
Amount: Amount };
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
'use strict';var makeClass = require('../utils/make-class');var _require =
|
|
2
|
-
require('../utils/bytes-utils'),parseBytes = _require.parseBytes;var _require2 =
|
|
3
|
-
require('./serialized-type'),SerializedType = _require2.SerializedType;
|
|
4
|
-
|
|
5
|
-
var Blob = makeClass({
|
|
6
|
-
mixins: SerializedType,
|
|
7
|
-
Blob: function Blob(bytes) {
|
|
8
|
-
if (bytes) {
|
|
9
|
-
this._bytes = parseBytes(bytes, Uint8Array);
|
|
10
|
-
} else {
|
|
11
|
-
this._bytes = new Uint8Array(0);
|
|
12
|
-
}
|
|
13
|
-
},
|
|
14
|
-
statics: {
|
|
15
|
-
fromParser: function fromParser(parser, hint) {
|
|
16
|
-
return new this(parser.read(hint));
|
|
17
|
-
},
|
|
18
|
-
from: function from(value) {
|
|
19
|
-
if (value instanceof this) {
|
|
20
|
-
return value;
|
|
21
|
-
}
|
|
22
|
-
return new this(value);
|
|
23
|
-
} } });
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
module.exports = {
|
|
28
|
-
Blob: Blob };
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
'use strict';var _ = require('lodash');
|
|
2
|
-
var makeClass = require('../utils/make-class');var _require =
|
|
3
|
-
require('../utils/bytes-utils'),slice = _require.slice;var _require2 =
|
|
4
|
-
require('./hash-160'),Hash160 = _require2.Hash160;
|
|
5
|
-
var ISO_REGEX = /^[A-Z0-9]{3}$/;
|
|
6
|
-
var HEX_REGEX = /^[A-F0-9]{40}$/;
|
|
7
|
-
|
|
8
|
-
function isoToBytes(iso) {
|
|
9
|
-
var bytes = new Uint8Array(20);
|
|
10
|
-
if (iso !== 'XRP') {
|
|
11
|
-
var isoBytes = iso.split('').map(function (c) {return c.charCodeAt(0);});
|
|
12
|
-
bytes.set(isoBytes, 12);
|
|
13
|
-
}
|
|
14
|
-
return bytes;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function isISOCode(val) {
|
|
18
|
-
return val.length === 3; // ISO_REGEX.test(val);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function isHex(val) {
|
|
22
|
-
return HEX_REGEX.test(val);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function isStringRepr(val) {
|
|
26
|
-
return _.isString(val) && (isISOCode(val) || isHex(val));
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function isBytesArray(val) {
|
|
30
|
-
return val.length === 20;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function isValidRepr(val) {
|
|
34
|
-
return isStringRepr(val) || isBytesArray(val);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function bytesFromRepr(val) {
|
|
38
|
-
if (isValidRepr(val)) {
|
|
39
|
-
// We assume at this point that we have an object with a length, either 3,
|
|
40
|
-
// 20 or 40.
|
|
41
|
-
return val.length === 3 ? isoToBytes(val) : val;
|
|
42
|
-
}
|
|
43
|
-
throw new Error('Unsupported Currency repr: ' + val);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
var $uper = Hash160.prototype;
|
|
47
|
-
var Currency = makeClass({
|
|
48
|
-
inherits: Hash160,
|
|
49
|
-
getters: ['isNative', 'iso'],
|
|
50
|
-
statics: {
|
|
51
|
-
init: function init() {
|
|
52
|
-
this.XRP = new this(new Uint8Array(20));
|
|
53
|
-
},
|
|
54
|
-
from: function from(val) {
|
|
55
|
-
return val instanceof this ? val : new this(bytesFromRepr(val));
|
|
56
|
-
} },
|
|
57
|
-
|
|
58
|
-
Currency: function Currency(bytes) {
|
|
59
|
-
Hash160.call(this, bytes);
|
|
60
|
-
this.classify();
|
|
61
|
-
},
|
|
62
|
-
classify: function classify() {
|
|
63
|
-
// We only have a non null iso() property available if the currency can be
|
|
64
|
-
// losslessly represented by the 3 letter iso code. If none is available a
|
|
65
|
-
// hex encoding of the full 20 bytes is the canonical representation.
|
|
66
|
-
var onlyISO = true;
|
|
67
|
-
|
|
68
|
-
var bytes = this._bytes;
|
|
69
|
-
var code = slice(this._bytes, 12, 15, Array);
|
|
70
|
-
var iso = code.map(function (c) {return String.fromCharCode(c);}).join('');
|
|
71
|
-
|
|
72
|
-
for (var i = bytes.length - 1; i >= 0; i--) {
|
|
73
|
-
if (bytes[i] !== 0 && !(i === 12 || i === 13 || i === 14)) {
|
|
74
|
-
onlyISO = false;
|
|
75
|
-
break;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
var lossLessISO = onlyISO && iso !== 'XRP' && ISO_REGEX.test(iso);
|
|
79
|
-
this._isNative = onlyISO && _.isEqual(code, [0, 0, 0]);
|
|
80
|
-
this._iso = this._isNative ? 'XRP' : lossLessISO ? iso : null;
|
|
81
|
-
},
|
|
82
|
-
toJSON: function toJSON() {
|
|
83
|
-
if (this.iso()) {
|
|
84
|
-
return this.iso();
|
|
85
|
-
}
|
|
86
|
-
return $uper.toJSON.call(this);
|
|
87
|
-
} });
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
module.exports = {
|
|
91
|
-
Currency: Currency };
|