ripple-binary-codec 1.1.3 → 1.2.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/ShaMap/ShaMap.d.ts +3 -0
- package/dist/ShaMap/ShaMap.js +25 -0
- package/dist/ShaMap/ShaMap.js.map +1 -0
- package/dist/ShaMap/ShaMapInner.d.ts +66 -0
- package/dist/ShaMap/ShaMapInner.js +145 -0
- package/dist/ShaMap/ShaMapInner.js.map +1 -0
- package/dist/ShaMap/ShaMapLeaf.d.ts +42 -0
- package/dist/ShaMap/ShaMapLeaf.js +84 -0
- package/dist/ShaMap/ShaMapLeaf.js.map +1 -0
- package/dist/ShaMap/ShaMapNode.d.ts +13 -0
- package/dist/ShaMap/ShaMapNode.js +12 -0
- package/dist/ShaMap/ShaMapNode.js.map +1 -0
- package/dist/ShaMap/index.d.ts +3 -0
- package/dist/ShaMap/index.js +9 -0
- package/dist/ShaMap/index.js.map +1 -0
- package/dist/enums/Bytes.d.ts +10 -0
- package/dist/enums/Bytes.js +30 -0
- package/dist/enums/Bytes.js.map +1 -0
- package/dist/enums/BytesLookup.d.ts +8 -0
- package/dist/enums/BytesLookup.js +29 -0
- package/dist/enums/BytesLookup.js.map +1 -0
- package/dist/enums/Field.d.ts +3 -0
- package/dist/enums/Field.js +9 -0
- package/dist/enums/Field.js.map +1 -0
- package/dist/enums/FieldInfo.d.ts +7 -0
- package/dist/enums/FieldInfo.js +3 -0
- package/dist/enums/FieldInfo.js.map +1 -0
- package/dist/enums/FieldInstance.d.ts +14 -0
- package/dist/enums/FieldInstance.js +3 -0
- package/dist/enums/FieldInstance.js.map +1 -0
- package/dist/enums/FieldLookup.d.ts +11 -0
- package/dist/enums/FieldLookup.js +102 -0
- package/dist/enums/FieldLookup.js.map +1 -0
- package/dist/enums/definitions.json +190 -4
- package/dist/hashes.js +2 -1
- package/dist/hashes.js.map +1 -1
- package/dist/serdes/BinaryParser.d.ts +100 -0
- package/dist/serdes/BinaryParser.js +200 -0
- package/dist/serdes/BinaryParser.js.map +1 -0
- package/dist/serdes/BinarySerializer.d.ts +50 -0
- package/dist/serdes/BinarySerializer.js +105 -0
- package/dist/serdes/BinarySerializer.js.map +1 -0
- package/dist/serdes/BytesList.d.ts +28 -0
- package/dist/serdes/BytesList.js +48 -0
- package/dist/serdes/BytesList.js.map +1 -0
- package/dist/types/Comparable.d.ts +18 -0
- package/dist/types/Comparable.js +43 -0
- package/dist/types/Comparable.js.map +1 -0
- package/dist/types/PathSet/Hop.d.ts +41 -0
- package/dist/types/PathSet/Hop.js +116 -0
- package/dist/types/PathSet/Hop.js.map +1 -0
- package/dist/types/PathSet/Path.d.ts +33 -0
- package/dist/types/PathSet/Path.js +83 -0
- package/dist/types/PathSet/Path.js.map +1 -0
- package/dist/types/PathSet/index.d.ts +29 -0
- package/dist/types/PathSet/index.js +98 -0
- package/dist/types/PathSet/index.js.map +1 -0
- package/dist/types/SerializedType.d.ts +47 -0
- package/dist/types/SerializedType.js +69 -0
- package/dist/types/SerializedType.js.map +1 -0
- package/dist/types/currency.d.ts +3 -10
- package/dist/types/currency.js +22 -23
- package/dist/types/currency.js.map +1 -1
- package/package.json +4 -3
- package/test/binary-parser.test.js +2 -2
- package/test/fixtures/data-driven-tests.json +2 -790
- package/test/hash.test.js +8 -4
- package/test/lower-case-hex.test.js +2 -1
- package/HISTORY.md +0 -90
package/README.md
CHANGED
|
@@ -98,10 +98,10 @@ Encode the transaction object for multi-signing.
|
|
|
98
98
|
|
|
99
99
|
Run unit tests with:
|
|
100
100
|
|
|
101
|
-
|
|
101
|
+
npm test
|
|
102
102
|
|
|
103
103
|
Use `--coverage` to generate and display code coverage information:
|
|
104
104
|
|
|
105
|
-
|
|
105
|
+
npm test --coverage
|
|
106
106
|
|
|
107
|
-
This tells jest to output code coverage info in the `./coverage` directory, in addition to showing it on the command line.
|
|
107
|
+
This tells jest to output code coverage info in the `./coverage` directory, in addition to showing it on the command line.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
extendStatics(d, b);
|
|
11
|
+
function __() { this.constructor = d; }
|
|
12
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
13
|
+
};
|
|
14
|
+
})();
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
var ShaMapInner_1 = require("./ShaMapInner");
|
|
17
|
+
var ShaMap = /** @class */ (function (_super) {
|
|
18
|
+
__extends(ShaMap, _super);
|
|
19
|
+
function ShaMap() {
|
|
20
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
21
|
+
}
|
|
22
|
+
return ShaMap;
|
|
23
|
+
}(ShaMapInner_1.default));
|
|
24
|
+
exports.default = ShaMap;
|
|
25
|
+
//# sourceMappingURL=ShaMap.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ShaMap.js","sourceRoot":"","sources":["../../src/ShaMap/ShaMap.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,6CAAuC;AAEvC;IAAoC,0BAAW;IAA/C;;IAAiD,CAAC;IAAD,aAAC;AAAD,CAAC,AAAlD,CAAoC,qBAAW,GAAG"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { Buffer } from 'buffer/';
|
|
2
|
+
import BytesList from '../serdes/BytesList';
|
|
3
|
+
import { Hash256 } from '../types';
|
|
4
|
+
import ShaMapLeaf from './ShaMapLeaf';
|
|
5
|
+
import ShaMapNode from './ShaMapNode';
|
|
6
|
+
/**
|
|
7
|
+
* Class defining an Inner Node of a SHAMap.
|
|
8
|
+
*/
|
|
9
|
+
export default class ShaMapInner extends ShaMapNode {
|
|
10
|
+
private _slotBits;
|
|
11
|
+
private _branches;
|
|
12
|
+
private readonly _depth;
|
|
13
|
+
constructor(depth?: number);
|
|
14
|
+
/**
|
|
15
|
+
* Returns `true` because ShaMapInners are always inner nodes.
|
|
16
|
+
*
|
|
17
|
+
* @returns `true`.
|
|
18
|
+
*/
|
|
19
|
+
isInner(): true;
|
|
20
|
+
/**
|
|
21
|
+
* Returns `false` because ShaMapInners are never leaves.
|
|
22
|
+
*
|
|
23
|
+
* @returns `false`.
|
|
24
|
+
*/
|
|
25
|
+
isLeaf(): false;
|
|
26
|
+
/**
|
|
27
|
+
* Get the hash prefix for this node.
|
|
28
|
+
*
|
|
29
|
+
* @returns Hash prefix describing an inner node.
|
|
30
|
+
*/
|
|
31
|
+
hashPrefix(): Buffer;
|
|
32
|
+
/**
|
|
33
|
+
* Set a branch of this node to be another node.
|
|
34
|
+
*
|
|
35
|
+
* @param slot - Slot to add branch to this._branches.
|
|
36
|
+
* @param branch - Branch to add.
|
|
37
|
+
*/
|
|
38
|
+
setBranch(slot: number, branch: ShaMapNode): void;
|
|
39
|
+
/**
|
|
40
|
+
* Returns `true` if node is empty.
|
|
41
|
+
*
|
|
42
|
+
* @returns `true` if node is empty.
|
|
43
|
+
*/
|
|
44
|
+
empty(): boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Compute the hash of this node.
|
|
47
|
+
*
|
|
48
|
+
* @returns The hash of this node.
|
|
49
|
+
*/
|
|
50
|
+
hash(): Hash256;
|
|
51
|
+
/**
|
|
52
|
+
* Writes the bytes representation of this node to a BytesList.
|
|
53
|
+
*
|
|
54
|
+
* @param list - BytesList to write bytes to.
|
|
55
|
+
*/
|
|
56
|
+
toBytesSink(list: BytesList): void;
|
|
57
|
+
/**
|
|
58
|
+
* Add item to the SHAMap.
|
|
59
|
+
*
|
|
60
|
+
* @param index - Hash of the index of the item being inserted.
|
|
61
|
+
* @param item - Item to insert in the map.
|
|
62
|
+
* @param leaf - Leaf node to insert when branch doesn't exist.
|
|
63
|
+
* @throws Error.
|
|
64
|
+
*/
|
|
65
|
+
addItem(index?: Hash256, item?: ShaMapNode, leaf?: ShaMapLeaf): void;
|
|
66
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
extendStatics(d, b);
|
|
11
|
+
function __() { this.constructor = d; }
|
|
12
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
13
|
+
};
|
|
14
|
+
})();
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
/* eslint-disable no-bitwise -- this file needs to use bitwise operations */
|
|
17
|
+
var assert = require("assert");
|
|
18
|
+
var hash_prefixes_1 = require("../hash-prefixes");
|
|
19
|
+
var hashes_1 = require("../hashes");
|
|
20
|
+
var types_1 = require("../types");
|
|
21
|
+
var ShaMapLeaf_1 = require("./ShaMapLeaf");
|
|
22
|
+
var ShaMapNode_1 = require("./ShaMapNode");
|
|
23
|
+
/**
|
|
24
|
+
* Class defining an Inner Node of a SHAMap.
|
|
25
|
+
*/
|
|
26
|
+
var ShaMapInner = /** @class */ (function (_super) {
|
|
27
|
+
__extends(ShaMapInner, _super);
|
|
28
|
+
function ShaMapInner(depth) {
|
|
29
|
+
if (depth === void 0) { depth = 0; }
|
|
30
|
+
var _this = _super.call(this) || this;
|
|
31
|
+
_this._slotBits = 0;
|
|
32
|
+
/* eslint-disable @typescript-eslint/consistent-type-assertions, @typescript-eslint/no-magic-numbers --
|
|
33
|
+
* TODO why, describe me */
|
|
34
|
+
_this._branches = Array(16);
|
|
35
|
+
_this._depth = depth;
|
|
36
|
+
return _this;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Returns `true` because ShaMapInners are always inner nodes.
|
|
40
|
+
*
|
|
41
|
+
* @returns `true`.
|
|
42
|
+
*/
|
|
43
|
+
/* eslint-disable class-methods-use-this --
|
|
44
|
+
* this method could be static, but its probably useful as is */
|
|
45
|
+
ShaMapInner.prototype.isInner = function () {
|
|
46
|
+
return true;
|
|
47
|
+
};
|
|
48
|
+
/* eslint-enable class-methods-use-this */
|
|
49
|
+
/**
|
|
50
|
+
* Returns `false` because ShaMapInners are never leaves.
|
|
51
|
+
*
|
|
52
|
+
* @returns `false`.
|
|
53
|
+
*/
|
|
54
|
+
/* eslint-disable class-methods-use-this --
|
|
55
|
+
* this method could be static, but its probably useful as is */
|
|
56
|
+
ShaMapInner.prototype.isLeaf = function () {
|
|
57
|
+
return false;
|
|
58
|
+
};
|
|
59
|
+
/* eslint-enable class-methods-use-this */
|
|
60
|
+
/**
|
|
61
|
+
* Get the hash prefix for this node.
|
|
62
|
+
*
|
|
63
|
+
* @returns Hash prefix describing an inner node.
|
|
64
|
+
*/
|
|
65
|
+
/* eslint-disable class-methods-use-this --
|
|
66
|
+
* this must be a method to fulfill the interface of ShaMapNode */
|
|
67
|
+
ShaMapInner.prototype.hashPrefix = function () {
|
|
68
|
+
return hash_prefixes_1.default.innerNode;
|
|
69
|
+
};
|
|
70
|
+
/* eslint-enable class-methods-use-this */
|
|
71
|
+
/**
|
|
72
|
+
* Set a branch of this node to be another node.
|
|
73
|
+
*
|
|
74
|
+
* @param slot - Slot to add branch to this._branches.
|
|
75
|
+
* @param branch - Branch to add.
|
|
76
|
+
*/
|
|
77
|
+
ShaMapInner.prototype.setBranch = function (slot, branch) {
|
|
78
|
+
this._slotBits |= 1 << slot;
|
|
79
|
+
this._branches[slot] = branch;
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* Returns `true` if node is empty.
|
|
83
|
+
*
|
|
84
|
+
* @returns `true` if node is empty.
|
|
85
|
+
*/
|
|
86
|
+
ShaMapInner.prototype.empty = function () {
|
|
87
|
+
return this._slotBits === 0;
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* Compute the hash of this node.
|
|
91
|
+
*
|
|
92
|
+
* @returns The hash of this node.
|
|
93
|
+
*/
|
|
94
|
+
ShaMapInner.prototype.hash = function () {
|
|
95
|
+
if (this.empty()) {
|
|
96
|
+
return types_1.Hash256.ZERO_256;
|
|
97
|
+
}
|
|
98
|
+
var hash = hashes_1.default.put(this.hashPrefix());
|
|
99
|
+
this.toBytesSink(hash);
|
|
100
|
+
return hash.finish();
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
* Writes the bytes representation of this node to a BytesList.
|
|
104
|
+
*
|
|
105
|
+
* @param list - BytesList to write bytes to.
|
|
106
|
+
*/
|
|
107
|
+
ShaMapInner.prototype.toBytesSink = function (list) {
|
|
108
|
+
for (var _i = 0, _a = this._branches; _i < _a.length; _i++) {
|
|
109
|
+
var branch = _a[_i];
|
|
110
|
+
var hash = branch ? branch.hash() : types_1.Hash256.ZERO_256;
|
|
111
|
+
hash.toBytesSink(list);
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
/**
|
|
115
|
+
* Add item to the SHAMap.
|
|
116
|
+
*
|
|
117
|
+
* @param index - Hash of the index of the item being inserted.
|
|
118
|
+
* @param item - Item to insert in the map.
|
|
119
|
+
* @param leaf - Leaf node to insert when branch doesn't exist.
|
|
120
|
+
* @throws Error.
|
|
121
|
+
*/
|
|
122
|
+
ShaMapInner.prototype.addItem = function (index, item, leaf) {
|
|
123
|
+
assert(index !== undefined);
|
|
124
|
+
var nibble = index.nibblet(this._depth);
|
|
125
|
+
var existing = this._branches[nibble];
|
|
126
|
+
if (existing === undefined) {
|
|
127
|
+
this.setBranch(nibble, leaf !== null && leaf !== void 0 ? leaf : new ShaMapLeaf_1.default(index, item));
|
|
128
|
+
}
|
|
129
|
+
else if (existing instanceof ShaMapLeaf_1.default) {
|
|
130
|
+
var newInner = new ShaMapInner(this._depth + 1);
|
|
131
|
+
newInner.addItem(existing.index, undefined, existing);
|
|
132
|
+
newInner.addItem(index, item, leaf);
|
|
133
|
+
this.setBranch(nibble, newInner);
|
|
134
|
+
}
|
|
135
|
+
else if (existing instanceof ShaMapInner) {
|
|
136
|
+
existing.addItem(index, item, leaf);
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
throw new Error('invalid ShaMap.addItem call');
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
return ShaMapInner;
|
|
143
|
+
}(ShaMapNode_1.default));
|
|
144
|
+
exports.default = ShaMapInner;
|
|
145
|
+
//# sourceMappingURL=ShaMapInner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ShaMapInner.js","sourceRoot":"","sources":["../../src/ShaMap/ShaMapInner.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Buffer } from 'buffer/';
|
|
2
|
+
import BytesList from '../serdes/BytesList';
|
|
3
|
+
import Hash256 from '../types/hash-256';
|
|
4
|
+
import ShaMapNode from './ShaMapNode';
|
|
5
|
+
/**
|
|
6
|
+
* Class describing a Leaf of SHAMap.
|
|
7
|
+
*/
|
|
8
|
+
export default class ShaMapLeaf extends ShaMapNode {
|
|
9
|
+
index: Hash256;
|
|
10
|
+
item?: ShaMapNode;
|
|
11
|
+
constructor(index: Hash256, item?: ShaMapNode);
|
|
12
|
+
/**
|
|
13
|
+
* Returns `true` because ShaMapLeafs are always leaf node.
|
|
14
|
+
*
|
|
15
|
+
* @returns True.
|
|
16
|
+
*/
|
|
17
|
+
isLeaf(): true;
|
|
18
|
+
/**
|
|
19
|
+
* Returns `false` because ShaMapLeafs are never inner nodes.
|
|
20
|
+
*
|
|
21
|
+
* @returns False.
|
|
22
|
+
*/
|
|
23
|
+
isInner(): false;
|
|
24
|
+
/**
|
|
25
|
+
* Get the prefix of the this.item.
|
|
26
|
+
*
|
|
27
|
+
* @returns The hash prefix, unless this.item is undefined, then it returns an empty Buffer.
|
|
28
|
+
*/
|
|
29
|
+
hashPrefix(): Buffer;
|
|
30
|
+
/**
|
|
31
|
+
* Hash the bytes representation of this.
|
|
32
|
+
*
|
|
33
|
+
* @returns Hash of this.item concatenated with this.index.
|
|
34
|
+
*/
|
|
35
|
+
hash(): Hash256;
|
|
36
|
+
/**
|
|
37
|
+
* Write the bytes representation of this to a BytesList.
|
|
38
|
+
*
|
|
39
|
+
* @param list - BytesList to write bytes to.
|
|
40
|
+
*/
|
|
41
|
+
toBytesSink(list: BytesList): void;
|
|
42
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
extendStatics(d, b);
|
|
11
|
+
function __() { this.constructor = d; }
|
|
12
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
13
|
+
};
|
|
14
|
+
})();
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
var buffer_1 = require("buffer/");
|
|
17
|
+
var hashes_1 = require("../hashes");
|
|
18
|
+
var ShaMapNode_1 = require("./ShaMapNode");
|
|
19
|
+
/**
|
|
20
|
+
* Class describing a Leaf of SHAMap.
|
|
21
|
+
*/
|
|
22
|
+
var ShaMapLeaf = /** @class */ (function (_super) {
|
|
23
|
+
__extends(ShaMapLeaf, _super);
|
|
24
|
+
function ShaMapLeaf(index, item) {
|
|
25
|
+
var _this = _super.call(this) || this;
|
|
26
|
+
_this.index = index;
|
|
27
|
+
_this.item = item;
|
|
28
|
+
return _this;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Returns `true` because ShaMapLeafs are always leaf node.
|
|
32
|
+
*
|
|
33
|
+
* @returns True.
|
|
34
|
+
*/
|
|
35
|
+
/* eslint-disable class-methods-use-this --
|
|
36
|
+
* this method could be static, but its probably useful as is */
|
|
37
|
+
ShaMapLeaf.prototype.isLeaf = function () {
|
|
38
|
+
return true;
|
|
39
|
+
};
|
|
40
|
+
/* eslint-enable class-methods-use-this */
|
|
41
|
+
/**
|
|
42
|
+
* Returns `false` because ShaMapLeafs are never inner nodes.
|
|
43
|
+
*
|
|
44
|
+
* @returns False.
|
|
45
|
+
*/
|
|
46
|
+
/* eslint-disable class-methods-use-this --
|
|
47
|
+
* this method could be static, but its probably useful as is */
|
|
48
|
+
ShaMapLeaf.prototype.isInner = function () {
|
|
49
|
+
return false;
|
|
50
|
+
};
|
|
51
|
+
/* eslint-enable class-methods-use-this */
|
|
52
|
+
/**
|
|
53
|
+
* Get the prefix of the this.item.
|
|
54
|
+
*
|
|
55
|
+
* @returns The hash prefix, unless this.item is undefined, then it returns an empty Buffer.
|
|
56
|
+
*/
|
|
57
|
+
ShaMapLeaf.prototype.hashPrefix = function () {
|
|
58
|
+
return this.item === undefined ? buffer_1.Buffer.alloc(0) : this.item.hashPrefix();
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Hash the bytes representation of this.
|
|
62
|
+
*
|
|
63
|
+
* @returns Hash of this.item concatenated with this.index.
|
|
64
|
+
*/
|
|
65
|
+
ShaMapLeaf.prototype.hash = function () {
|
|
66
|
+
var hash = hashes_1.default.put(this.hashPrefix());
|
|
67
|
+
this.toBytesSink(hash);
|
|
68
|
+
return hash.finish();
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Write the bytes representation of this to a BytesList.
|
|
72
|
+
*
|
|
73
|
+
* @param list - BytesList to write bytes to.
|
|
74
|
+
*/
|
|
75
|
+
ShaMapLeaf.prototype.toBytesSink = function (list) {
|
|
76
|
+
if (this.item !== undefined) {
|
|
77
|
+
this.item.toBytesSink(list);
|
|
78
|
+
}
|
|
79
|
+
this.index.toBytesSink(list);
|
|
80
|
+
};
|
|
81
|
+
return ShaMapLeaf;
|
|
82
|
+
}(ShaMapNode_1.default));
|
|
83
|
+
exports.default = ShaMapLeaf;
|
|
84
|
+
//# sourceMappingURL=ShaMapLeaf.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ShaMapLeaf.js","sourceRoot":"","sources":["../../src/ShaMap/ShaMapLeaf.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,kCAAgC;AAEhC,oCAAkC;AAIlC,2CAAqC;AAErC;;GAEG;AACH;IAAwC,8BAAU;IAIhD,oBAAmB,KAAc,EAAE,IAAiB;QAApD,YACE,iBAAO,SAGR;QAFC,KAAI,CAAC,KAAK,GAAG,KAAK,CAAA;QAClB,KAAI,CAAC,IAAI,GAAG,IAAI,CAAA;;IAClB,CAAC;IAED;;;;OAIG;IACH;oEACgE;IACzD,2BAAM,GAAb;QACE,OAAO,IAAI,CAAA;IACb,CAAC;IACD,0CAA0C;IAE1C;;;;OAIG;IACH;oEACgE;IACzD,4BAAO,GAAd;QACE,OAAO,KAAK,CAAA;IACd,CAAC;IACD,0CAA0C;IAE1C;;;;OAIG;IACI,+BAAU,GAAjB;QACE,OAAO,IAAI,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,eAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,CAAA;IAC3E,CAAC;IAED;;;;OAIG;IACI,yBAAI,GAAX;QACE,IAAM,IAAI,GAAG,gBAAU,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC,CAAA;QAC9C,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAA;QACtB,OAAO,IAAI,CAAC,MAAM,EAAE,CAAA;IACtB,CAAC;IAED;;;;OAIG;IACI,gCAAW,GAAlB,UAAmB,IAAe;QAChC,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS,EAAE;YAC3B,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAA;SAC5B;QACD,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC,CAAA;IAC9B,CAAC;IACH,iBAAC;AAAD,CAAC,AAjED,CAAwC,oBAAU,GAiEjD"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Buffer } from 'buffer/';
|
|
2
|
+
import BytesList from '../serdes/BytesList';
|
|
3
|
+
import Hash256 from '../types/hash-256';
|
|
4
|
+
/**
|
|
5
|
+
* Abstract class describing a SHAMapNode.
|
|
6
|
+
*/
|
|
7
|
+
export default abstract class ShaMapNode {
|
|
8
|
+
abstract hashPrefix(): Buffer;
|
|
9
|
+
abstract isLeaf(): boolean;
|
|
10
|
+
abstract isInner(): boolean;
|
|
11
|
+
abstract toBytesSink(list: BytesList): void;
|
|
12
|
+
abstract hash(): Hash256;
|
|
13
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/**
|
|
4
|
+
* Abstract class describing a SHAMapNode.
|
|
5
|
+
*/
|
|
6
|
+
var ShaMapNode = /** @class */ (function () {
|
|
7
|
+
function ShaMapNode() {
|
|
8
|
+
}
|
|
9
|
+
return ShaMapNode;
|
|
10
|
+
}());
|
|
11
|
+
exports.default = ShaMapNode;
|
|
12
|
+
//# sourceMappingURL=ShaMapNode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ShaMapNode.js","sourceRoot":"","sources":["../../src/ShaMap/ShaMapNode.ts"],"names":[],"mappings":";;AAKA;;GAEG;AACH;IAAA;IAMA,CAAC;IAAD,iBAAC;AAAD,CAAC,AAND,IAMC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var ShaMapNode_1 = require("./ShaMapNode");
|
|
4
|
+
Object.defineProperty(exports, "ShaMapNode", { enumerable: true, get: function () { return ShaMapNode_1.default; } });
|
|
5
|
+
var ShaMapLeaf_1 = require("./ShaMapLeaf");
|
|
6
|
+
Object.defineProperty(exports, "ShaMapLeaf", { enumerable: true, get: function () { return ShaMapLeaf_1.default; } });
|
|
7
|
+
var ShaMap_1 = require("./ShaMap");
|
|
8
|
+
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return ShaMap_1.default; } });
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ShaMap/index.ts"],"names":[],"mappings":";;AAAA,2CAAoD;AAA3C,wGAAA,OAAO,OAAc;AAC9B,2CAAoD;AAA3C,wGAAA,OAAO,OAAc;AAC9B,mCAAkC;AAAzB,iGAAA,OAAO,OAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type BytesList from '../serdes/BytesList';
|
|
2
|
+
export default class Bytes {
|
|
3
|
+
readonly ordinal: number;
|
|
4
|
+
readonly name: string;
|
|
5
|
+
private readonly _bytes;
|
|
6
|
+
constructor(name: string, ordinal: number, ordinalWidth: number);
|
|
7
|
+
toJSON(): string;
|
|
8
|
+
toBytesSink(sink: BytesList): void;
|
|
9
|
+
toBytes(): Uint8Array;
|
|
10
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/* eslint-disable no-bitwise -- this file needs to use bitwise operations */
|
|
4
|
+
var buffer_1 = require("buffer/");
|
|
5
|
+
// @brief: Bytes, name, and ordinal representing one type, ledger_type, transaction type, or result
|
|
6
|
+
var Bytes = /** @class */ (function () {
|
|
7
|
+
function Bytes(name, ordinal, ordinalWidth) {
|
|
8
|
+
this.ordinal = ordinal;
|
|
9
|
+
this.name = name;
|
|
10
|
+
this._bytes = buffer_1.Buffer.alloc(ordinalWidth);
|
|
11
|
+
for (var i = 0; i < ordinalWidth; i++) {
|
|
12
|
+
/* eslint-disable @typescript-eslint/no-magic-numbers --
|
|
13
|
+
* TODO describe better */
|
|
14
|
+
this._bytes[ordinalWidth - i - 1] = (this.ordinal >>> (i * 8)) & 0xff;
|
|
15
|
+
/* eslint-enable @typescript-eslint/no-magic-numbers */
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
Bytes.prototype.toJSON = function () {
|
|
19
|
+
return this.name;
|
|
20
|
+
};
|
|
21
|
+
Bytes.prototype.toBytesSink = function (sink) {
|
|
22
|
+
sink.put(this._bytes);
|
|
23
|
+
};
|
|
24
|
+
Bytes.prototype.toBytes = function () {
|
|
25
|
+
return this._bytes;
|
|
26
|
+
};
|
|
27
|
+
return Bytes;
|
|
28
|
+
}());
|
|
29
|
+
exports.default = Bytes;
|
|
30
|
+
//# sourceMappingURL=Bytes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Bytes.js","sourceRoot":"","sources":["../../src/enums/Bytes.ts"],"names":[],"mappings":";;AAAA,4EAA4E;AAC5E,kCAAgC;AAIhC,mGAAmG;AACnG;IAKE,eAAmB,IAAY,EAAE,OAAe,EAAE,YAAoB;QACpE,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,MAAM,GAAG,eAAM,CAAC,KAAK,CAAC,YAAY,CAAC,CAAA;QACxC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,YAAY,EAAE,CAAC,EAAE,EAAE;YACrC;sCAC0B;YAC1B,IAAI,CAAC,MAAM,CAAC,YAAY,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,IAAI,CAAA;YACrE,uDAAuD;SACxD;IACH,CAAC;IAEM,sBAAM,GAAb;QACE,OAAO,IAAI,CAAC,IAAI,CAAA;IAClB,CAAC;IAEM,2BAAW,GAAlB,UAAmB,IAAe;QAChC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IACvB,CAAC;IAEM,uBAAO,GAAd;QACE,OAAO,IAAI,CAAC,MAAM,CAAA;IACpB,CAAC;IACH,YAAC;AAAD,CAAC,AA5BD,IA4BC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type BinaryParser from '../serdes/BinaryParser';
|
|
2
|
+
import Bytes from './Bytes';
|
|
3
|
+
export default class BytesLookup {
|
|
4
|
+
private readonly _ordinalWidth;
|
|
5
|
+
constructor(types: Record<string, number>, ordinalWidth: number);
|
|
6
|
+
from(value: Bytes | string): Bytes;
|
|
7
|
+
fromParser(parser: BinaryParser): Bytes;
|
|
8
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var Bytes_1 = require("./Bytes");
|
|
4
|
+
// @brief: Collection of Bytes objects, mapping bidirectionally
|
|
5
|
+
var BytesLookup = /** @class */ (function () {
|
|
6
|
+
function BytesLookup(types, ordinalWidth) {
|
|
7
|
+
var _this = this;
|
|
8
|
+
this._ordinalWidth = ordinalWidth;
|
|
9
|
+
Object.entries(types).forEach(function (_a) {
|
|
10
|
+
var key = _a[0], value = _a[1];
|
|
11
|
+
var bytesValue = new Bytes_1.default(key, value, _this._ordinalWidth);
|
|
12
|
+
_this[key] = bytesValue;
|
|
13
|
+
_this[value.toString()] = bytesValue;
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
BytesLookup.prototype.from = function (value) {
|
|
17
|
+
/* eslint-disable @typescript-eslint/consistent-type-assertions --
|
|
18
|
+
* TODO we can fix this by storing the lookup as an object on this class,
|
|
19
|
+
* see FieldLookup */
|
|
20
|
+
return value instanceof Bytes_1.default ? value : this[value];
|
|
21
|
+
/* eslint-enable @typescript-eslint/consistent-type-assertions */
|
|
22
|
+
};
|
|
23
|
+
BytesLookup.prototype.fromParser = function (parser) {
|
|
24
|
+
return this.from(parser.readUIntN(this._ordinalWidth).toString());
|
|
25
|
+
};
|
|
26
|
+
return BytesLookup;
|
|
27
|
+
}());
|
|
28
|
+
exports.default = BytesLookup;
|
|
29
|
+
//# sourceMappingURL=BytesLookup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BytesLookup.js","sourceRoot":"","sources":["../../src/enums/BytesLookup.ts"],"names":[],"mappings":";;AAEA,iCAA2B;AAE3B,+DAA+D;AAC/D;IAGE,qBAAmB,KAA6B,EAAE,YAAoB;QAAtE,iBAOC;QANC,IAAI,CAAC,aAAa,GAAG,YAAY,CAAA;QACjC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,UAAC,EAAY;gBAAX,GAAG,QAAA,EAAE,KAAK,QAAA;YACxC,IAAM,UAAU,GAAG,IAAI,eAAK,CAAC,GAAG,EAAE,KAAK,EAAE,KAAI,CAAC,aAAa,CAAC,CAAA;YAC5D,KAAI,CAAC,GAAG,CAAC,GAAG,UAAU,CAAA;YACtB,KAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,GAAG,UAAU,CAAA;QACrC,CAAC,CAAC,CAAA;IACJ,CAAC;IAEM,0BAAI,GAAX,UAAY,KAAqB;QAC/B;;6BAEqB;QACrB,OAAO,KAAK,YAAY,eAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAE,IAAI,CAAC,KAAK,CAAW,CAAA;QAC9D,iEAAiE;IACnE,CAAC;IAEM,gCAAU,GAAjB,UAAkB,MAAoB;QACpC,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAA;IACnE,CAAC;IACH,kBAAC;AAAD,CAAC,AAvBD,IAuBC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var enums = require("./definitions.json");
|
|
4
|
+
var FieldLookup_1 = require("./FieldLookup");
|
|
5
|
+
/* eslint-disable @typescript-eslint/consistent-type-assertions --
|
|
6
|
+
* this is ok since we're parsing JSON and we know what's there */
|
|
7
|
+
exports.default = new FieldLookup_1.default(enums.FIELDS);
|
|
8
|
+
/* eslint-enable @typescript-eslint/consistent-type-assertions */
|
|
9
|
+
//# sourceMappingURL=Field.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Field.js","sourceRoot":"","sources":["../../src/enums/Field.ts"],"names":[],"mappings":";;AAAA,0CAA2C;AAE3C,6CAAuC;AAEvC;kEACkE;AAClE,kBAAe,IAAI,qBAAW,CAAC,KAAK,CAAC,MAAoC,CAAC,CAAA;AAC1E,iEAAiE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FieldInfo.js","sourceRoot":"","sources":["../../src/enums/FieldInfo.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Buffer } from 'buffer/';
|
|
2
|
+
import type SerializedType from '../types/SerializedType';
|
|
3
|
+
import type Bytes from './Bytes';
|
|
4
|
+
export default interface FieldInstance {
|
|
5
|
+
readonly nth: number;
|
|
6
|
+
readonly isVariableLengthEncoded: boolean;
|
|
7
|
+
readonly isSerialized: boolean;
|
|
8
|
+
readonly isSigningField: boolean;
|
|
9
|
+
readonly type: Bytes;
|
|
10
|
+
readonly ordinal: number;
|
|
11
|
+
readonly name: string;
|
|
12
|
+
readonly header: Buffer;
|
|
13
|
+
associatedType: typeof SerializedType;
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FieldInstance.js","sourceRoot":"","sources":["../../src/enums/FieldInstance.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import BytesLookup from './BytesLookup';
|
|
2
|
+
import FieldInfo from './FieldInfo';
|
|
3
|
+
import FieldInstance from './FieldInstance';
|
|
4
|
+
export declare const LedgerEntryType: BytesLookup;
|
|
5
|
+
export declare const TransactionType: BytesLookup;
|
|
6
|
+
export declare const TransactionResult: BytesLookup;
|
|
7
|
+
export default class FieldLookup {
|
|
8
|
+
private readonly _store;
|
|
9
|
+
constructor(fields: Array<[string, FieldInfo]>);
|
|
10
|
+
get(value: string): FieldInstance;
|
|
11
|
+
}
|