postchain-client 1.0.2 → 1.0.3
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 +0 -27
- package/built/cjs/index.js +2571 -0
- package/built/cjs/index.js.map +1 -0
- package/built/esm/index.js +29927 -0
- package/built/esm/index.js.map +1 -0
- package/built/index.js +21 -3
- package/built/index.js.map +1 -0
- package/built/src/chromia/chromiaClientProvider.js +35 -0
- package/built/src/chromia/chromiaClientProvider.js.map +1 -0
- package/built/src/chromia/errors.js +6 -0
- package/built/src/chromia/errors.js.map +1 -0
- package/built/src/chromia/interfaces.js +2 -0
- package/built/src/chromia/interfaces.js.map +1 -0
- package/built/src/encryption/encryption.js +105 -0
- package/built/src/encryption/encryption.js.map +1 -0
- package/built/src/encryption/errors.js +11 -0
- package/built/src/encryption/errors.js.map +1 -0
- package/built/src/encryption/types.js +2 -0
- package/built/src/encryption/types.js.map +1 -0
- package/built/src/formatter.d.ts +2 -0
- package/built/src/formatter.js +119 -0
- package/built/src/formatter.js.map +1 -0
- package/built/src/gtv/definition.js +20 -0
- package/built/src/gtv/definition.js.map +1 -0
- package/built/src/gtv/index.d.ts +1 -0
- package/built/src/gtv/index.js +11 -0
- package/built/src/gtv/index.js.map +1 -0
- package/built/src/gtv/types.d.ts +2 -3
- package/built/src/gtv/types.js +2 -0
- package/built/src/gtv/types.js.map +1 -0
- package/built/src/gtx/errors.js +26 -0
- package/built/src/gtx/errors.js.map +1 -0
- package/built/src/gtx/gtx.d.ts +1 -1
- package/built/src/gtx/gtx.js +115 -0
- package/built/src/gtx/gtx.js.map +1 -0
- package/built/src/gtx/gtxclient.js +77 -0
- package/built/src/gtx/gtxclient.js.map +1 -0
- package/built/src/gtx/index.js +5 -0
- package/built/src/gtx/index.js.map +1 -0
- package/built/src/gtx/interfaces.js +2 -0
- package/built/src/gtx/interfaces.js.map +1 -0
- package/built/src/gtx/serialization.d.ts +3 -2
- package/built/src/gtx/serialization.js +95 -0
- package/built/src/gtx/serialization.js.map +1 -0
- package/built/src/gtx/types.d.ts +10 -1
- package/built/src/gtx/types.js +2 -0
- package/built/src/gtx/types.js.map +1 -0
- package/built/src/logger.d.ts +2 -1
- package/built/src/logger.js +53 -0
- package/built/src/logger.js.map +1 -0
- package/built/src/merkle/binarytree.d.ts +137 -0
- package/built/src/merkle/binarytree.js +146 -0
- package/built/src/merkle/binarytree.js.map +1 -0
- package/built/src/merkle/binarytreefactory.d.ts +86 -0
- package/built/src/merkle/binarytreefactory.js +235 -0
- package/built/src/merkle/binarytreefactory.js.map +1 -0
- package/built/src/merkle/merkleHelper.js +109 -0
- package/built/src/merkle/merkleHelper.js.map +1 -0
- package/built/src/merkle/merklehashcalculator.d.ts +35 -0
- package/built/src/merkle/merklehashcalculator.js +71 -0
- package/built/src/merkle/merklehashcalculator.js.map +1 -0
- package/built/src/merkle/path.d.ts +155 -0
- package/built/src/merkle/path.js +306 -0
- package/built/src/merkle/path.js.map +1 -0
- package/built/src/merkle/proof/merklehashcarrier.d.ts +17 -0
- package/built/src/merkle/proof/merklehashcarrier.js +23 -0
- package/built/src/merkle/proof/merklehashcarrier.js.map +1 -0
- package/built/src/merkle/proof/merklehashsummaryfactory.d.ts +53 -0
- package/built/src/merkle/proof/merklehashsummaryfactory.js +81 -0
- package/built/src/merkle/proof/merklehashsummaryfactory.js.map +1 -0
- package/built/src/merkle/proof/merkleproof.d.ts +35 -0
- package/built/src/merkle/proof/merkleproof.js +59 -0
- package/built/src/merkle/proof/merkleproof.js.map +1 -0
- package/built/src/merkle/proof/merkleprooftree.d.ts +130 -0
- package/built/src/merkle/proof/merkleprooftree.js +116 -0
- package/built/src/merkle/proof/merkleprooftree.js.map +1 -0
- package/built/src/merkle/proof/merkleprooftreefactory.d.ts +47 -0
- package/built/src/merkle/proof/merkleprooftreefactory.js +121 -0
- package/built/src/merkle/proof/merkleprooftreefactory.js.map +1 -0
- package/built/src/merkle/types.js +2 -0
- package/built/src/merkle/types.js.map +1 -0
- package/built/src/restclient/errors.js +54 -0
- package/built/src/restclient/errors.js.map +1 -0
- package/built/src/restclient/interfaces.d.ts +2 -1
- package/built/src/restclient/interfaces.js +2 -0
- package/built/src/restclient/interfaces.js.map +1 -0
- package/built/src/restclient/restclient.js +309 -0
- package/built/src/restclient/restclient.js.map +1 -0
- package/built/src/restclient/restclientutil.d.ts +4 -0
- package/built/src/restclient/restclientutil.js +137 -0
- package/built/src/restclient/restclientutil.js.map +1 -0
- package/built/src/restclient/types.d.ts +4 -0
- package/built/src/restclient/types.js +13 -0
- package/built/src/restclient/types.js.map +1 -0
- package/built/umd/index.js +29931 -0
- package/built/umd/index.js.map +1 -0
- package/package.json +26 -16
- package/built/index.js.LICENSE.txt +0 -657
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gtxclient.js","sourceRoot":"","sources":["../../../src/gtx/gtxclient.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AACb,OAAO,KAAK,OAAO,MAAM,OAAO,CAAC;AACjC,8DAA8D;AAC9D,MAAM,SAAS,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;AAMvC,OAAO,KAAK,MAAM,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAEtD,MAAM,UAAU,YAAY,CAC1B,aAAyB,EACzB,aAAqB,EACrB,aAAuB;IAEvB,aAAa,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IAE9B,SAAS,WAAW,CAAC,GAAQ;QAC3B,OAAO;YACL,GAAG;YAEH,IAAI,EAAE,UAAU,OAAe,EAAE,MAAc;gBAC7C,IAAI,GAAG,GAAG,MAAM,CAAC;gBACjB,IAAI,CAAC,GAAG,EAAE;oBACR,MAAM,CAAC,KAAK,CACV,gEAAgE,CACjE,CAAC;oBACF,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,CAAC;iBACvD;gBACD,MAAM,CAA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oot":"","sources":["../../../src/gtx/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,aAAa,MAAM,iBAAiB,CAAC;AAEjD,MAAM,MAAM,GAAG,aAAa,CAAC,cAAc,CAAC;AAC5C,MAAM,MAAM,GAAG,aAAa,CAAC,cAAc,CAAC;AAE5C,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../src/gtx/interfaces.ts"],"names":[],"mappings":""}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { RawGtx } from "./types";
|
|
2
|
+
import { ASNValue, RawGtx } from "./types";
|
|
3
3
|
import { RawGtv } from "../gtv/types";
|
|
4
4
|
export declare function encodeValue(rawGtv: RawGtv): Buffer;
|
|
5
5
|
export declare function encodeValueGtx(rawGtx: RawGtx): Buffer;
|
|
6
6
|
export declare function decodeValue(bytes: Buffer): RawGtv;
|
|
7
7
|
export declare function decodeValueGtx(bytes: Buffer): RawGtx;
|
|
8
|
-
export declare function
|
|
8
|
+
export declare function parseValue(typedArg: ASNValue): RawGtv;
|
|
9
|
+
export declare function createTypedArg(value: RawGtv): ASNValue;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { rawGTV } from "../gtv/definition";
|
|
2
|
+
import { BN } from "bn.js";
|
|
3
|
+
import { UnexpectedArgumentTypeError } from "./errors";
|
|
4
|
+
import { checkGtxType } from "../formatter";
|
|
5
|
+
export function encodeValue(rawGtv) {
|
|
6
|
+
return rawGTV.encode(createTypedArg(rawGtv));
|
|
7
|
+
}
|
|
8
|
+
export function encodeValueGtx(rawGtx) {
|
|
9
|
+
return encodeValue(rawGtx);
|
|
10
|
+
}
|
|
11
|
+
export function decodeValue(bytes) {
|
|
12
|
+
const obj = rawGTV.decode(bytes);
|
|
13
|
+
return parseValue(obj);
|
|
14
|
+
}
|
|
15
|
+
export function decodeValueGtx(bytes) {
|
|
16
|
+
const decodedValue = decodeValue(bytes);
|
|
17
|
+
if (!checkGtxType(decodedValue)) {
|
|
18
|
+
throw new Error(`Unexpected type of value: ${decodedValue}, expected decoded value to be of type RawGtx`);
|
|
19
|
+
}
|
|
20
|
+
return decodedValue;
|
|
21
|
+
}
|
|
22
|
+
export function parseValue(typedArg) {
|
|
23
|
+
if (typedArg.type === "null") {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
else if (typedArg.type === "byteArray") {
|
|
27
|
+
return typedArg.value;
|
|
28
|
+
}
|
|
29
|
+
else if (typedArg.type === "string") {
|
|
30
|
+
return typedArg.value;
|
|
31
|
+
}
|
|
32
|
+
else if (typedArg.type === "integer") {
|
|
33
|
+
return Number(typedArg.value);
|
|
34
|
+
}
|
|
35
|
+
else if (typedArg.type === "array") {
|
|
36
|
+
const arrayValue = typedArg.value;
|
|
37
|
+
return arrayValue.map((item) => parseValue(item));
|
|
38
|
+
}
|
|
39
|
+
else if (typedArg.type === "bigInteger") {
|
|
40
|
+
return BigInt(typedArg.value);
|
|
41
|
+
}
|
|
42
|
+
else if (typedArg.type === "dict") {
|
|
43
|
+
const arrayValue = typedArg.value;
|
|
44
|
+
const result = {};
|
|
45
|
+
arrayValue.forEach((pair) => {
|
|
46
|
+
result[pair.name] = parseValue(pair.value);
|
|
47
|
+
});
|
|
48
|
+
return result;
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
throw new UnexpectedArgumentTypeError(typedArg);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
export function createTypedArg(value) {
|
|
55
|
+
try {
|
|
56
|
+
if (value == null) {
|
|
57
|
+
return { type: "null", value: null };
|
|
58
|
+
}
|
|
59
|
+
if (Buffer.isBuffer(value)) {
|
|
60
|
+
return { type: "byteArray", value: value };
|
|
61
|
+
}
|
|
62
|
+
if (typeof value === "boolean") {
|
|
63
|
+
return { type: "integer", value: value ? 1 : 0 };
|
|
64
|
+
}
|
|
65
|
+
if (typeof value === "string") {
|
|
66
|
+
return { type: "string", value: value };
|
|
67
|
+
}
|
|
68
|
+
if (typeof value === "number") {
|
|
69
|
+
if (!Number.isInteger(value)) {
|
|
70
|
+
throw Error("User error: Only integers are supported");
|
|
71
|
+
}
|
|
72
|
+
return { type: "integer", value: new BN(value) };
|
|
73
|
+
}
|
|
74
|
+
if (typeof value === "bigint") {
|
|
75
|
+
return { type: "bigInteger", value: new BN(Number(value)) };
|
|
76
|
+
}
|
|
77
|
+
if (value.constructor === Array) {
|
|
78
|
+
return {
|
|
79
|
+
type: "array",
|
|
80
|
+
value: value.map((item) => createTypedArg(item)),
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
if (typeof value === "object") {
|
|
84
|
+
const valueAsDictPair = value;
|
|
85
|
+
return { type: "dict", value: Object.keys(valueAsDictPair).map(function (key) {
|
|
86
|
+
return { name: key, value: createTypedArg(valueAsDictPair[key]) };
|
|
87
|
+
}) };
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
throw new Error(`Failed to encode ${value.toString()}: ${error}`);
|
|
92
|
+
}
|
|
93
|
+
throw new Error(`value ${value} have unsupported type: ${typeof value}`);
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=serialization.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serialization.js","sourceRoot":"","sources":["../../../src/gtx/serialization.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE3C,OAAO,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AAE3B,OAAO,EAAE,2BAA2B,EAAE,MAAM,UAAU,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C,MAAM,UAAU,WAAW,CAAC,MAAc;IACxC,OAAO,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC;AAC/C,C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AAE,CAAC;SAClD;QACD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;YAC7B,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;SAC7D;QACD,IAAI,KAAK,CAAC,WAAW,KAAK,KAAK,EAAE;YAC/B,OAAO;gBACL,IAAI,EAAE,OAAO;gBACb,KAAK,EAAG,KAAuB,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;aACpE,CAAC;SACH;QAED,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;YAC7B,MAAM,eAAe,GAAG,KAAiB,CAAA;YACvC,OAAO,EAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,GAAG,CAAC,UAAU,GAAG;oBACvE,OAAO,EAAC,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,cAAc,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC,EAAC,CAAA;gBACrE,CAAC,CAAC,EAAC,CAAA;SACN;KACA;IAAC,OAAO,KAAK,EAAE;QACd,MAAM,IAAI,KAAK,CAAC,oBAAoB,KAAK,CAAC,QAAQ,EAAE,KAAK,KAAK,EAAE,CAAC,CAAC;KACnE;IACD,MAAM,IAAI,KAAK,CAAC,SAAS,KAAK,2BAA2B,OAAO,KAAK,EAAE,CAAC,CAAC;AAC3E,CAAC"}
|
package/built/src/gtx/types.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
+
import BN from "bn.js";
|
|
2
3
|
import { RawGtv } from "../gtv/types";
|
|
3
4
|
export type RawGtxOp = [opName: string, args: RawGtv[]];
|
|
4
5
|
export type RawGtxBody = [
|
|
@@ -8,7 +9,7 @@ export type RawGtxBody = [
|
|
|
8
9
|
];
|
|
9
10
|
export type RawGtx = [transaction: RawGtxBody, signatures: Buffer[]];
|
|
10
11
|
export type GTX = {
|
|
11
|
-
[x: string]:
|
|
12
|
+
[x: string]: unknown;
|
|
12
13
|
blockchainRID: Buffer;
|
|
13
14
|
operations: RellOperation[];
|
|
14
15
|
signers: Buffer[];
|
|
@@ -26,3 +27,11 @@ export type BufferSignerPair = {
|
|
|
26
27
|
pubKey: Buffer;
|
|
27
28
|
signature: Buffer;
|
|
28
29
|
};
|
|
30
|
+
export type ASNValue = {
|
|
31
|
+
type: string;
|
|
32
|
+
value: BN | string | number | Buffer | ASNValue[] | ASNPair[] | null;
|
|
33
|
+
};
|
|
34
|
+
export type ASNPair = {
|
|
35
|
+
name: string;
|
|
36
|
+
value: ASNValue;
|
|
37
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/gtx/types.ts"],"names":[],"mappings":""}
|
package/built/src/logger.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
export { debug, info, error, warning, setLogLevel };
|
|
1
|
+
export { debug, info, error, warning, setLogLevel, getLogLevel };
|
|
2
2
|
declare function setLogLevel(level: number): void;
|
|
3
|
+
declare function getLogLevel(): number;
|
|
3
4
|
declare function debug(message: string): void;
|
|
4
5
|
declare function info(message: string): void;
|
|
5
6
|
declare function error(message: string): void;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export { debug, info, error, warning, setLogLevel, getLogLevel };
|
|
2
|
+
var MsgType;
|
|
3
|
+
(function (MsgType) {
|
|
4
|
+
MsgType["debug"] = "DEBUG";
|
|
5
|
+
MsgType["info"] = "INFO";
|
|
6
|
+
MsgType["error"] = "ERROR";
|
|
7
|
+
MsgType["warning"] = "WARNING";
|
|
8
|
+
})(MsgType || (MsgType = {}));
|
|
9
|
+
var LogColor;
|
|
10
|
+
(function (LogColor) {
|
|
11
|
+
LogColor["red"] = "\u001B[91m";
|
|
12
|
+
LogColor["green"] = "\u001B[92m";
|
|
13
|
+
LogColor["blue"] = "\u001B[36m";
|
|
14
|
+
LogColor["yellow"] = "\u001B[93m";
|
|
15
|
+
LogColor["stopColor"] = "\u001B[0m";
|
|
16
|
+
})(LogColor || (LogColor = {}));
|
|
17
|
+
let logLevel = 1;
|
|
18
|
+
function setLogLevel(level) {
|
|
19
|
+
logLevel = level;
|
|
20
|
+
}
|
|
21
|
+
function getLogLevel() {
|
|
22
|
+
return logLevel;
|
|
23
|
+
}
|
|
24
|
+
function debug(message) {
|
|
25
|
+
if (logLevel >= 3) {
|
|
26
|
+
emitLogMessage(MsgType.debug, message, LogColor.blue);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function info(message) {
|
|
30
|
+
if (logLevel >= 2) {
|
|
31
|
+
emitLogMessage(MsgType.info, message, LogColor.green);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function error(message) {
|
|
35
|
+
if (logLevel != -1) {
|
|
36
|
+
emitLogMessage(MsgType.error, message, LogColor.red);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function warning(message) {
|
|
40
|
+
if (logLevel >= 1) {
|
|
41
|
+
emitLogMessage(MsgType.warning, message, LogColor.yellow);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function emitLogMessage(msgType, message, color) {
|
|
45
|
+
const time = getTimestamp();
|
|
46
|
+
console.log(`[${time}] ${color}${msgType}:${LogColor.stopColor} ${message}`);
|
|
47
|
+
}
|
|
48
|
+
function getTimestamp() {
|
|
49
|
+
const pad = (n, s = 2) => `${new Array(s).fill(0)}${n}`.slice(-s);
|
|
50
|
+
const date = new Date();
|
|
51
|
+
return `${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}:${pad(date.getMilliseconds(), 3)}`;
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/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O,EAAE,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;KAC3D;AACH,CAAC;AAED,SAAS,cAAc,CAAC,OAAgB,EAAE,OAAe,EAAE,KAAe;IACxE,MAAM,IAAI,GAAG,YAAY,EAAE,CAAC;IAC5B,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,KAAK,KAAK,GAAG,OAAO,IAAI,QAAQ,CAAC,SAAS,IAAI,OAAO,EAAE,CAAC,CAAC;AAC/E,CAAC;AAED,SAAS,YAAY;IACnB,MAAM,GAAG,GAAG,CAAC,CAAS,EAAE,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,GAAG,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IAC1E,MAAM,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC;IACxB,OAAO,GAAG,GAAG,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,IAAI,GAAG,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC,IAAI,GAAG,CAC7D,IAAI,CAAC,UAAU,EAAE,CAClB,IAAI,GAAG,CAAC,IAAI,CAAC,eAAe,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC;AACxC,CAAC"}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
export const HASH_PREFIX_NODE: 0;
|
|
2
|
+
export const HASH_PREFIX_LEAF: 1;
|
|
3
|
+
export const HASH_PREFIX_NODE_ARRAY: 7;
|
|
4
|
+
export const HASH_PREFIX_NODE_DICT: 8;
|
|
5
|
+
/**
|
|
6
|
+
*
|
|
7
|
+
* @param {BinaryTreeElement} left
|
|
8
|
+
* @param {BinaryTreeElement} right
|
|
9
|
+
*/
|
|
10
|
+
export function Node(left: BinaryTreeElement, right: BinaryTreeElement): void;
|
|
11
|
+
export class Node {
|
|
12
|
+
/**
|
|
13
|
+
*
|
|
14
|
+
* @param {BinaryTreeElement} left
|
|
15
|
+
* @param {BinaryTreeElement} right
|
|
16
|
+
*/
|
|
17
|
+
constructor(left: BinaryTreeElement, right: BinaryTreeElement);
|
|
18
|
+
left: BinaryTreeElement;
|
|
19
|
+
right: BinaryTreeElement;
|
|
20
|
+
constructor: typeof Node;
|
|
21
|
+
getPrefixByte(): number;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
*
|
|
25
|
+
* @param {*} content
|
|
26
|
+
* @param {PathElement} pathElem
|
|
27
|
+
*/
|
|
28
|
+
export function Leaf(content: any, pathElem?: PathElement): void;
|
|
29
|
+
export class Leaf {
|
|
30
|
+
/**
|
|
31
|
+
*
|
|
32
|
+
* @param {*} content
|
|
33
|
+
* @param {PathElement} pathElem
|
|
34
|
+
*/
|
|
35
|
+
constructor(content: any, pathElem?: PathElement);
|
|
36
|
+
content: any;
|
|
37
|
+
constructor: typeof Leaf;
|
|
38
|
+
getPrefixByte(): number;
|
|
39
|
+
}
|
|
40
|
+
export function EmptyLeaf(): void;
|
|
41
|
+
export class EmptyLeaf {
|
|
42
|
+
constructor: typeof EmptyLeaf;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
*
|
|
46
|
+
* @param {BinaryTreeElement} left
|
|
47
|
+
* @param {BinaryTreeElement} right
|
|
48
|
+
* @param {*} content
|
|
49
|
+
* @param {PathSet} pathElem
|
|
50
|
+
*/
|
|
51
|
+
export function SubTreeRootNode(left: BinaryTreeElement, right: BinaryTreeElement, content: any, pathElem: PathSet): void;
|
|
52
|
+
export class SubTreeRootNode {
|
|
53
|
+
/**
|
|
54
|
+
*
|
|
55
|
+
* @param {BinaryTreeElement} left
|
|
56
|
+
* @param {BinaryTreeElement} right
|
|
57
|
+
* @param {*} content
|
|
58
|
+
* @param {PathSet} pathElem
|
|
59
|
+
*/
|
|
60
|
+
constructor(left: BinaryTreeElement, right: BinaryTreeElement, content: any, pathElem: PathSet);
|
|
61
|
+
content: any;
|
|
62
|
+
constructor: typeof SubTreeRootNode;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
*
|
|
66
|
+
*/
|
|
67
|
+
export function BinaryTreeElement(): void;
|
|
68
|
+
export class BinaryTreeElement {
|
|
69
|
+
pathElem: any;
|
|
70
|
+
isPath(): boolean;
|
|
71
|
+
isPathLeaf(): boolean;
|
|
72
|
+
setPathElement(pathElem: any): void;
|
|
73
|
+
getPrefixByte(): number;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Wrapper class for the root object.
|
|
77
|
+
* @param {BinaryTreeElement} root
|
|
78
|
+
*/
|
|
79
|
+
export function BinaryTree(root: BinaryTreeElement): void;
|
|
80
|
+
export class BinaryTree {
|
|
81
|
+
/**
|
|
82
|
+
* Wrapper class for the root object.
|
|
83
|
+
* @param {BinaryTreeElement} root
|
|
84
|
+
*/
|
|
85
|
+
constructor(root: BinaryTreeElement);
|
|
86
|
+
root: BinaryTreeElement;
|
|
87
|
+
maxLevel(): any;
|
|
88
|
+
maxLevelInternal(node: any): any;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Represents the top of a sub tree generated by a [Array]
|
|
92
|
+
*
|
|
93
|
+
* @param {*} left
|
|
94
|
+
* @param {*} right
|
|
95
|
+
* @param {*} content
|
|
96
|
+
* @param {*} size
|
|
97
|
+
* @param {PathElement} pathElem
|
|
98
|
+
*/
|
|
99
|
+
export function ArrayHeadNode(left: any, right: any, content: any, size: any, pathElem?: PathElement): void;
|
|
100
|
+
export class ArrayHeadNode {
|
|
101
|
+
/**
|
|
102
|
+
* Represents the top of a sub tree generated by a [Array]
|
|
103
|
+
*
|
|
104
|
+
* @param {*} left
|
|
105
|
+
* @param {*} right
|
|
106
|
+
* @param {*} content
|
|
107
|
+
* @param {*} size
|
|
108
|
+
* @param {PathElement} pathElem
|
|
109
|
+
*/
|
|
110
|
+
constructor(left: any, right: any, content: any, size: any, pathElem?: PathElement);
|
|
111
|
+
size: any;
|
|
112
|
+
constructor: typeof ArrayHeadNode;
|
|
113
|
+
getPrefixByte(): number;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Represents the top a sub tree generated by a [Dictionary]
|
|
117
|
+
* @param {*} left
|
|
118
|
+
* @param {*} right
|
|
119
|
+
* @param {*} content
|
|
120
|
+
* @param {*} size
|
|
121
|
+
* @param {PathElement} pathElem
|
|
122
|
+
*/
|
|
123
|
+
export function DictHeadNode(left: any, right: any, content: any, size: any, pathElem?: PathElement): void;
|
|
124
|
+
export class DictHeadNode {
|
|
125
|
+
/**
|
|
126
|
+
* Represents the top a sub tree generated by a [Dictionary]
|
|
127
|
+
* @param {*} left
|
|
128
|
+
* @param {*} right
|
|
129
|
+
* @param {*} content
|
|
130
|
+
* @param {*} size
|
|
131
|
+
* @param {PathElement} pathElem
|
|
132
|
+
*/
|
|
133
|
+
constructor(left: any, right: any, content: any, size: any, pathElem?: PathElement);
|
|
134
|
+
size: any;
|
|
135
|
+
constructor: typeof DictHeadNode;
|
|
136
|
+
getPrefixByte(): number;
|
|
137
|
+
}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var PathLeafElement = require('./path').PathLeafElement;
|
|
3
|
+
const HASH_PREFIX_NODE = 0;
|
|
4
|
+
const HASH_PREFIX_LEAF = 1;
|
|
5
|
+
const HASH_PREFIX_NODE_ARRAY = 7;
|
|
6
|
+
const HASH_PREFIX_NODE_DICT = 8;
|
|
7
|
+
/**
|
|
8
|
+
*
|
|
9
|
+
*/
|
|
10
|
+
function BinaryTreeElement() {
|
|
11
|
+
this.pathElem = null;
|
|
12
|
+
}
|
|
13
|
+
BinaryTreeElement.prototype.isPath = function () {
|
|
14
|
+
return this.pathElem != null;
|
|
15
|
+
};
|
|
16
|
+
BinaryTreeElement.prototype.isPathLeaf = function () {
|
|
17
|
+
if (this.pathElem == null) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
if (this.pathElem instanceof PathLeafElement) {
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
BinaryTreeElement.prototype.setPathElement = function (pathElem) {
|
|
28
|
+
this.pathElem = pathElem;
|
|
29
|
+
};
|
|
30
|
+
BinaryTreeElement.prototype.getPrefixByte = function () {
|
|
31
|
+
return HASH_PREFIX_NODE;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
*
|
|
35
|
+
* @param {BinaryTreeElement} left
|
|
36
|
+
* @param {BinaryTreeElement} right
|
|
37
|
+
*/
|
|
38
|
+
function Node(left, right) {
|
|
39
|
+
this.left = left;
|
|
40
|
+
this.right = right;
|
|
41
|
+
}
|
|
42
|
+
Node.prototype = Object.create(BinaryTreeElement.prototype);
|
|
43
|
+
Node.prototype.constructor = Node;
|
|
44
|
+
Node.prototype.getPrefixByte = function () {
|
|
45
|
+
return HASH_PREFIX_NODE;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
*
|
|
49
|
+
* @param {BinaryTreeElement} left
|
|
50
|
+
* @param {BinaryTreeElement} right
|
|
51
|
+
* @param {*} content
|
|
52
|
+
* @param {PathSet} pathElem
|
|
53
|
+
*/
|
|
54
|
+
function SubTreeRootNode(left, right, content, pathElem) {
|
|
55
|
+
Node.call(this, left, right);
|
|
56
|
+
this.content = content;
|
|
57
|
+
BinaryTreeElement.prototype.setPathElement.call(this, pathElem);
|
|
58
|
+
}
|
|
59
|
+
SubTreeRootNode.prototype = Object.create(Node.prototype);
|
|
60
|
+
SubTreeRootNode.prototype.constructor = SubTreeRootNode;
|
|
61
|
+
/**
|
|
62
|
+
*
|
|
63
|
+
* @param {*} content
|
|
64
|
+
* @param {PathElement} pathElem
|
|
65
|
+
*/
|
|
66
|
+
function Leaf(content, pathElem = null) {
|
|
67
|
+
this.content = content;
|
|
68
|
+
if (pathElem != null) {
|
|
69
|
+
if (pathElem instanceof PathLeafElement) {
|
|
70
|
+
BinaryTreeElement.prototype.setPathElement.call(this, pathElem);
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
throw new Error("The path and object structure does not match! We are at a leaf, but the path expects a sub structure.");
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
Leaf.prototype = Object.create(BinaryTreeElement.prototype);
|
|
78
|
+
Leaf.prototype.constructor = Leaf;
|
|
79
|
+
Leaf.prototype.getPrefixByte = function () {
|
|
80
|
+
return HASH_PREFIX_LEAF;
|
|
81
|
+
};
|
|
82
|
+
function EmptyLeaf() { }
|
|
83
|
+
EmptyLeaf.prototype = Object.create(BinaryTreeElement.prototype);
|
|
84
|
+
EmptyLeaf.prototype.constructor = EmptyLeaf;
|
|
85
|
+
/**
|
|
86
|
+
* Wrapper class for the root object.
|
|
87
|
+
* @param {BinaryTreeElement} root
|
|
88
|
+
*/
|
|
89
|
+
function BinaryTree(root) {
|
|
90
|
+
this.root = root;
|
|
91
|
+
}
|
|
92
|
+
BinaryTree.prototype.maxLevel = function () {
|
|
93
|
+
return this.maxLevelInternal(this.root);
|
|
94
|
+
};
|
|
95
|
+
BinaryTree.prototype.maxLevelInternal = function (node) {
|
|
96
|
+
if (node instanceof EmptyLeaf) {
|
|
97
|
+
return 0;
|
|
98
|
+
}
|
|
99
|
+
else if (node instanceof Leaf) {
|
|
100
|
+
return 1;
|
|
101
|
+
}
|
|
102
|
+
else if (node instanceof Node) {
|
|
103
|
+
return Math.max(this.maxLevelInternal(node.left), this.maxLevelInternal(node.right)) + 1;
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
throw new Error("What is this type? " + typeof node);
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
/**
|
|
110
|
+
* Represents the top of a sub tree generated by a [Array]
|
|
111
|
+
*
|
|
112
|
+
* @param {*} left
|
|
113
|
+
* @param {*} right
|
|
114
|
+
* @param {*} content
|
|
115
|
+
* @param {*} size
|
|
116
|
+
* @param {PathElement} pathElem
|
|
117
|
+
*/
|
|
118
|
+
function ArrayHeadNode(left, right, content, size, pathElem = null) {
|
|
119
|
+
SubTreeRootNode.call(this, left, right, content, pathElem);
|
|
120
|
+
this.size = size;
|
|
121
|
+
}
|
|
122
|
+
ArrayHeadNode.prototype = Object.create(SubTreeRootNode.prototype);
|
|
123
|
+
ArrayHeadNode.prototype.constructor = ArrayHeadNode;
|
|
124
|
+
ArrayHeadNode.prototype.getPrefixByte = function () {
|
|
125
|
+
return HASH_PREFIX_NODE_ARRAY;
|
|
126
|
+
};
|
|
127
|
+
/**
|
|
128
|
+
* Represents the top a sub tree generated by a [Dictionary]
|
|
129
|
+
* @param {*} left
|
|
130
|
+
* @param {*} right
|
|
131
|
+
* @param {*} content
|
|
132
|
+
* @param {*} size
|
|
133
|
+
* @param {PathElement} pathElem
|
|
134
|
+
*/
|
|
135
|
+
function DictHeadNode(left, right, content, size, pathElem = null) {
|
|
136
|
+
SubTreeRootNode.call(this, left, right, content, pathElem);
|
|
137
|
+
this.size = size;
|
|
138
|
+
}
|
|
139
|
+
DictHeadNode.prototype = Object.create(SubTreeRootNode.prototype);
|
|
140
|
+
DictHeadNode.prototype.constructor = DictHeadNode;
|
|
141
|
+
DictHeadNode.prototype.getPrefixByte = function () {
|
|
142
|
+
return HASH_PREFIX_NODE_DICT;
|
|
143
|
+
};
|
|
144
|
+
module.exports = { HASH_PREFIX_NODE, HASH_PREFIX_LEAF, HASH_PREFIX_NODE_ARRAY, HASH_PREFIX_NODE_DICT,
|
|
145
|
+
Node, Leaf, EmptyLeaf, SubTreeRootNode, BinaryTreeElement, BinaryTree, ArrayHeadNode, DictHeadNode };
|
|
146
|
+
//# sourceMappingURL=binarytree.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"binarytree.js","sourceRoot":"","sources":["../../../src/merkle/binarytree.js"],"names":[],"mappings":"AAAA,YAAY,CAAA;AAEZ,IAAI,eAAe,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC,eAAe,C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,EAAE,QAAQ,GAAC,IAAI;IAC7D,eAAe,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAA;IAC1D,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;AAClB,CAAC;AAED,YAAY,CAAC,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,eAAe,CAAC,SAAS,CAAC,CAAA;AACjE,YAAY,CAAC,SAAS,CAAC,WAAW,GAAG,YAAY,CAAA;AACjD,YAAY,CAAC,SAAS,CAAC,aAAa,GAAG;IACrC,OAAO,qBAAqB,CAAA;AAC9B,CAAC,CAAA;AAED,MAAM,CAAC,OAAO,GAAG,EAAC,gBAAgB,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,qBAAqB;IACjG,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,eAAe,EAAE,iBAAiB,EAAE,UAAU,EAAE,aAAa,EAAE,YAAY,EAAC,CAAA"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The factory does the conversion between list of elements and tree of elements.
|
|
3
|
+
*
|
|
4
|
+
* Note: The idea is that you should sub class for each type of element you want to build.
|
|
5
|
+
*/
|
|
6
|
+
export function BinaryTreeFactory(): void;
|
|
7
|
+
export class BinaryTreeFactory {
|
|
8
|
+
/**
|
|
9
|
+
* Transforms the incoming leaf into an [BinaryTreeElement]
|
|
10
|
+
* The idea with this function is that it can be recursive (if the leaf in turn is complex object with sub objects).
|
|
11
|
+
*
|
|
12
|
+
* Note: If we don't have a path here we can try to find the leaf in the cache.
|
|
13
|
+
*
|
|
14
|
+
* @param leaf the raw data we should wrap in a leaf
|
|
15
|
+
* @param paths a collection of proof paths that might point to this leaf
|
|
16
|
+
* @return the resulting [BinaryTreeElement] the leaf got converted to
|
|
17
|
+
*/
|
|
18
|
+
handleLeaf(leaf: any, paths: any, isRoot?: boolean): Leaf | ArrayHeadNode | DictHeadNode;
|
|
19
|
+
/**
|
|
20
|
+
*
|
|
21
|
+
*/
|
|
22
|
+
getEmptyPathSet(): PathSet;
|
|
23
|
+
/**
|
|
24
|
+
* At this point we should have looked in cache.
|
|
25
|
+
*
|
|
26
|
+
* @param leaf we should turn into a tree element
|
|
27
|
+
* @param {PathSet} paths
|
|
28
|
+
* @return the tree element we created.
|
|
29
|
+
*/
|
|
30
|
+
innerHandleLeaf(leaf: any, paths: PathSet): Leaf | ArrayHeadNode | DictHeadNode;
|
|
31
|
+
/**
|
|
32
|
+
* Just like [handleLeaf] but we know that this leaf should not be a complex type, but something we can
|
|
33
|
+
* immediately wrap
|
|
34
|
+
*
|
|
35
|
+
* @param leaf
|
|
36
|
+
* @param {PathSet} paths
|
|
37
|
+
*/
|
|
38
|
+
handlePrimitiveLeaf(leaf: any, paths: PathSet): Leaf;
|
|
39
|
+
/**
|
|
40
|
+
* Calls itself until the return value only holds 1 element
|
|
41
|
+
*
|
|
42
|
+
* Note: This method can only create standard [Node] that fills up the area between the "top" and the leaves.
|
|
43
|
+
* These "in-between" nodes cannot be "path leaf" or have any interesting properties.
|
|
44
|
+
*
|
|
45
|
+
* @param layer What layer we aim calculate
|
|
46
|
+
* @param inList The args of nodes we should build from
|
|
47
|
+
* @return All [BinaryTreeElement] nodes of the next layer
|
|
48
|
+
*/
|
|
49
|
+
buildHigherLayer(layer: any, inList: any): any;
|
|
50
|
+
build(data: any): BinaryTree;
|
|
51
|
+
/**
|
|
52
|
+
* @param {PathSet} paths
|
|
53
|
+
*/
|
|
54
|
+
buildWithPath(data: any, paths: PathSet): BinaryTree;
|
|
55
|
+
/**
|
|
56
|
+
* @param {Array} array
|
|
57
|
+
* @param {PathSet} paths
|
|
58
|
+
*/
|
|
59
|
+
buildFromArray(array: any[], paths: PathSet): ArrayHeadNode;
|
|
60
|
+
/**
|
|
61
|
+
*
|
|
62
|
+
*/
|
|
63
|
+
buildFromOneLeaf(array: any, orgRoot: any, pathElem: any): ArrayHeadNode;
|
|
64
|
+
/**
|
|
65
|
+
* @param {PathSet} paths
|
|
66
|
+
*/
|
|
67
|
+
buildLeafElements(leafList: any, paths: PathSet): any[];
|
|
68
|
+
/**
|
|
69
|
+
* @param {PathSet} paths
|
|
70
|
+
*/
|
|
71
|
+
buildFromDictionary(dict: any, paths: PathSet): DictHeadNode;
|
|
72
|
+
/**
|
|
73
|
+
* @param {PathSet} paths
|
|
74
|
+
*/
|
|
75
|
+
buildLeafElementFromDict(keys: any, dict: any, paths: PathSet): any[];
|
|
76
|
+
}
|
|
77
|
+
import Leaf_1 = require("./binarytree");
|
|
78
|
+
import Leaf = Leaf_1.Leaf;
|
|
79
|
+
import ArrayHeadNode_1 = require("./binarytree");
|
|
80
|
+
import ArrayHeadNode = ArrayHeadNode_1.ArrayHeadNode;
|
|
81
|
+
import DictHeadNode_1 = require("./binarytree");
|
|
82
|
+
import DictHeadNode = DictHeadNode_1.DictHeadNode;
|
|
83
|
+
import PathSet_1 = require("./path");
|
|
84
|
+
import PathSet = PathSet_1.PathSet;
|
|
85
|
+
import BinaryTree_1 = require("./binarytree");
|
|
86
|
+
import BinaryTree = BinaryTree_1.BinaryTree;
|