@tari-project/tarijs-types 0.5.1 → 0.5.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/dist/helpers/cbor.d.ts +33 -0
- package/dist/helpers/cbor.js +105 -0
- package/dist/helpers/hexString.d.ts +2 -0
- package/dist/helpers/hexString.js +22 -0
- package/dist/helpers/index.d.ts +2 -0
- package/dist/helpers/index.js +2 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/network.d.ts +8 -0
- package/dist/network.js +9 -0
- package/package.json +1 -1
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export type CborValue = {
|
|
2
|
+
Map: Array<[CborValue, CborValue]>;
|
|
3
|
+
} | {
|
|
4
|
+
Array: CborValue[];
|
|
5
|
+
} | {
|
|
6
|
+
Tag: [BinaryTag, CborValue];
|
|
7
|
+
} | {
|
|
8
|
+
Bool: boolean;
|
|
9
|
+
} | {
|
|
10
|
+
Bytes: number[];
|
|
11
|
+
} | {
|
|
12
|
+
Text: string;
|
|
13
|
+
} | {
|
|
14
|
+
Float: number;
|
|
15
|
+
} | {
|
|
16
|
+
Integer: number;
|
|
17
|
+
} | "Null";
|
|
18
|
+
export declare function parseCbor(value: CborValue): unknown;
|
|
19
|
+
export declare function getCborValueByPath(cborRepr: CborValue | null, path: string): unknown;
|
|
20
|
+
export declare enum BinaryTag {
|
|
21
|
+
ComponentAddress = 128,
|
|
22
|
+
Metadata = 129,
|
|
23
|
+
NonFungibleAddress = 130,
|
|
24
|
+
ResourceAddress = 131,
|
|
25
|
+
VaultId = 132,
|
|
26
|
+
BucketId = 133,
|
|
27
|
+
TransactionReceipt = 134,
|
|
28
|
+
ProofId = 135,
|
|
29
|
+
UnclaimedConfidentialOutputAddress = 136,
|
|
30
|
+
TemplateAddress = 137,
|
|
31
|
+
ValidatorNodeFeePool = 138
|
|
32
|
+
}
|
|
33
|
+
export declare function convertTaggedValue(type: number, value: CborValue): string | unknown;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
export function parseCbor(value) {
|
|
2
|
+
if (typeof value === "string") {
|
|
3
|
+
if (value === "Null") {
|
|
4
|
+
return null;
|
|
5
|
+
}
|
|
6
|
+
throw new Error("Unknown CBOR value type");
|
|
7
|
+
}
|
|
8
|
+
if ("Map" in value) {
|
|
9
|
+
return Object.fromEntries(value.Map.map(([k, v]) => [parseCbor(k), parseCbor(v)]));
|
|
10
|
+
}
|
|
11
|
+
else if ("Array" in value) {
|
|
12
|
+
return value.Array.map(parseCbor);
|
|
13
|
+
}
|
|
14
|
+
else if ("Tag" in value) {
|
|
15
|
+
const [type, data] = value.Tag;
|
|
16
|
+
return convertTaggedValue(type, data);
|
|
17
|
+
}
|
|
18
|
+
else if ("Bool" in value) {
|
|
19
|
+
return value.Bool;
|
|
20
|
+
}
|
|
21
|
+
else if ("Bytes" in value) {
|
|
22
|
+
return new Uint8Array(value.Bytes);
|
|
23
|
+
}
|
|
24
|
+
else if ("Text" in value) {
|
|
25
|
+
return value.Text;
|
|
26
|
+
}
|
|
27
|
+
else if ("Float" in value) {
|
|
28
|
+
return value.Float;
|
|
29
|
+
}
|
|
30
|
+
else if ("Integer" in value) {
|
|
31
|
+
return value.Integer;
|
|
32
|
+
}
|
|
33
|
+
throw new Error("Unknown CBOR value type");
|
|
34
|
+
}
|
|
35
|
+
export function getCborValueByPath(cborRepr, path) {
|
|
36
|
+
if (!cborRepr) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
let value = cborRepr;
|
|
40
|
+
for (const part of path.split(".")) {
|
|
41
|
+
if (part == "$") {
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
if (typeof value !== "object") {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
if ("Map" in value) {
|
|
48
|
+
const mapEntry = value.Map.find((v) => parseCbor(v[0]) === part)?.[1];
|
|
49
|
+
if (mapEntry) {
|
|
50
|
+
value = mapEntry;
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if ("Array" in value) {
|
|
58
|
+
const arr = value.Array;
|
|
59
|
+
const index = parseInt(part);
|
|
60
|
+
if (!Number.isNaN(index) && Array.isArray(arr) && arr.length > index) {
|
|
61
|
+
value = arr[index];
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
return parseCbor(value);
|
|
68
|
+
}
|
|
69
|
+
function uint8ArrayToHex(bytes) {
|
|
70
|
+
return Array.from(bytes)
|
|
71
|
+
.map((byte) => byte.toString(16).padStart(2, "0"))
|
|
72
|
+
.join("");
|
|
73
|
+
}
|
|
74
|
+
export var BinaryTag;
|
|
75
|
+
(function (BinaryTag) {
|
|
76
|
+
BinaryTag[BinaryTag["ComponentAddress"] = 128] = "ComponentAddress";
|
|
77
|
+
BinaryTag[BinaryTag["Metadata"] = 129] = "Metadata";
|
|
78
|
+
BinaryTag[BinaryTag["NonFungibleAddress"] = 130] = "NonFungibleAddress";
|
|
79
|
+
BinaryTag[BinaryTag["ResourceAddress"] = 131] = "ResourceAddress";
|
|
80
|
+
BinaryTag[BinaryTag["VaultId"] = 132] = "VaultId";
|
|
81
|
+
BinaryTag[BinaryTag["BucketId"] = 133] = "BucketId";
|
|
82
|
+
BinaryTag[BinaryTag["TransactionReceipt"] = 134] = "TransactionReceipt";
|
|
83
|
+
BinaryTag[BinaryTag["ProofId"] = 135] = "ProofId";
|
|
84
|
+
BinaryTag[BinaryTag["UnclaimedConfidentialOutputAddress"] = 136] = "UnclaimedConfidentialOutputAddress";
|
|
85
|
+
BinaryTag[BinaryTag["TemplateAddress"] = 137] = "TemplateAddress";
|
|
86
|
+
BinaryTag[BinaryTag["ValidatorNodeFeePool"] = 138] = "ValidatorNodeFeePool";
|
|
87
|
+
})(BinaryTag || (BinaryTag = {}));
|
|
88
|
+
const BINARY_TAG_KEYS = new Map([
|
|
89
|
+
[BinaryTag.ComponentAddress, "component"],
|
|
90
|
+
[BinaryTag.Metadata, "metadata"],
|
|
91
|
+
[BinaryTag.NonFungibleAddress, "nft"],
|
|
92
|
+
[BinaryTag.ResourceAddress, "resource"],
|
|
93
|
+
[BinaryTag.VaultId, "vault"],
|
|
94
|
+
[BinaryTag.BucketId, "bucket"],
|
|
95
|
+
[BinaryTag.TransactionReceipt, "transaction-receipt"],
|
|
96
|
+
[BinaryTag.ProofId, "proof"],
|
|
97
|
+
[BinaryTag.UnclaimedConfidentialOutputAddress, "unclaimed-confidential-output-address"],
|
|
98
|
+
[BinaryTag.TemplateAddress, "template-address"],
|
|
99
|
+
[BinaryTag.ValidatorNodeFeePool, "validator-node-fee-pool"],
|
|
100
|
+
]);
|
|
101
|
+
export function convertTaggedValue(type, value) {
|
|
102
|
+
const tag = BINARY_TAG_KEYS.get(type) ?? "unknown";
|
|
103
|
+
const decoded = parseCbor(value);
|
|
104
|
+
return decoded instanceof Uint8Array ? `${tag}_${uint8ArrayToHex(decoded)}` : [tag, decoded];
|
|
105
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export function toHexString(byteArray) {
|
|
2
|
+
if (Array.isArray(byteArray)) {
|
|
3
|
+
return Array.from(byteArray, function (byte) {
|
|
4
|
+
return ('0' + (byte & 0xff).toString(16)).slice(-2);
|
|
5
|
+
}).join('');
|
|
6
|
+
}
|
|
7
|
+
if (byteArray === undefined) {
|
|
8
|
+
return 'undefined';
|
|
9
|
+
}
|
|
10
|
+
// object might be a tagged object
|
|
11
|
+
if (byteArray['@@TAGGED@@'] !== undefined) {
|
|
12
|
+
return toHexString(byteArray['@@TAGGED@@'][1]);
|
|
13
|
+
}
|
|
14
|
+
return 'Unsupported type';
|
|
15
|
+
}
|
|
16
|
+
export function fromHexString(hexString) {
|
|
17
|
+
let res = [];
|
|
18
|
+
for (let i = 0; i < hexString.length; i += 2) {
|
|
19
|
+
res.push(Number('0x' + hexString.substring(i, i + 2)));
|
|
20
|
+
}
|
|
21
|
+
return res;
|
|
22
|
+
}
|
package/dist/helpers/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { NonFungibleId, NonFungibleToken, ResourceAddress } from "@tari-project/typescript-bindings";
|
|
2
2
|
import { TransactionStatus } from "../TransactionStatus";
|
|
3
|
+
export { fromHexString, toHexString } from "./hexString";
|
|
4
|
+
export { BinaryTag, CborValue, convertTaggedValue, getCborValueByPath, parseCbor } from "./cbor";
|
|
3
5
|
export { substateIdToString, stringToSubstateId, shortenSubstateId, shortenString, rejectReasonToString, getSubstateDiffFromTransactionResult, getRejectReasonFromTransactionResult, jrpcPermissionToString, } from "@tari-project/typescript-bindings";
|
|
4
6
|
export declare function convertStringToTransactionStatus(status: string): TransactionStatus;
|
|
5
7
|
export declare function createNftAddressFromToken(token: NonFungibleToken): string;
|
package/dist/helpers/index.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { TransactionStatus } from "../TransactionStatus";
|
|
2
|
+
export { fromHexString, toHexString } from "./hexString";
|
|
3
|
+
export { BinaryTag, convertTaggedValue, getCborValueByPath, parseCbor } from "./cbor";
|
|
2
4
|
export { substateIdToString, stringToSubstateId, shortenSubstateId, shortenString, rejectReasonToString, getSubstateDiffFromTransactionResult, getRejectReasonFromTransactionResult, jrpcPermissionToString, } from "@tari-project/typescript-bindings";
|
|
3
5
|
export function convertStringToTransactionStatus(status) {
|
|
4
6
|
switch (status) {
|
package/dist/index.d.ts
CHANGED
|
@@ -17,5 +17,6 @@ export { UnsignedTransaction } from "./UnsignedTransaction";
|
|
|
17
17
|
export { VersionedSubstateId } from "./VersionedSubstateId";
|
|
18
18
|
export { WorkspaceArg } from "./Workspace";
|
|
19
19
|
export { ListAccountNftFromBalancesRequest } from "./ListAccountNftFromBalancesRequest";
|
|
20
|
+
export { Network } from "./network";
|
|
20
21
|
export { AccountData, ListSubstatesRequest, ListSubstatesResponse, SubmitTransactionRequest, Substate, SubstateMetadata, ReqSubstate, TemplateDefinition, VaultBalances, VaultData, GetSubstateRequest, } from "./signer";
|
|
21
|
-
export { convertHexStringToU256Array, convertStringToTransactionStatus, convertU256ToHexString, createNftAddressFromResource, createNftAddressFromToken, getRejectReasonFromTransactionResult, getSubstateDiffFromTransactionResult, jrpcPermissionToString, rejectReasonToString, shortenString, shortenSubstateId, stringToSubstateId, substateIdToString, } from "./helpers";
|
|
22
|
+
export { convertHexStringToU256Array, convertStringToTransactionStatus, convertU256ToHexString, createNftAddressFromResource, createNftAddressFromToken, getRejectReasonFromTransactionResult, getSubstateDiffFromTransactionResult, jrpcPermissionToString, rejectReasonToString, shortenString, shortenSubstateId, stringToSubstateId, substateIdToString, fromHexString, toHexString, convertTaggedValue, getCborValueByPath, parseCbor, BinaryTag, CborValue, } from "./helpers";
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export { Amount } from "./Amount";
|
|
2
2
|
export { TransactionStatus } from "./TransactionStatus";
|
|
3
|
-
export {
|
|
3
|
+
export { Network } from "./network";
|
|
4
|
+
export { convertHexStringToU256Array, convertStringToTransactionStatus, convertU256ToHexString, createNftAddressFromResource, createNftAddressFromToken, getRejectReasonFromTransactionResult, getSubstateDiffFromTransactionResult, jrpcPermissionToString, rejectReasonToString, shortenString, shortenSubstateId, stringToSubstateId, substateIdToString, fromHexString, toHexString, convertTaggedValue, getCborValueByPath, parseCbor, BinaryTag, } from "./helpers";
|
package/dist/network.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export var Network;
|
|
2
|
+
(function (Network) {
|
|
3
|
+
Network[Network["MainNet"] = 0] = "MainNet";
|
|
4
|
+
Network[Network["StageNet"] = 1] = "StageNet";
|
|
5
|
+
Network[Network["NextNet"] = 2] = "NextNet";
|
|
6
|
+
Network[Network["LocalNet"] = 16] = "LocalNet";
|
|
7
|
+
Network[Network["Igor"] = 36] = "Igor";
|
|
8
|
+
Network[Network["Esmeralda"] = 38] = "Esmeralda";
|
|
9
|
+
})(Network || (Network = {}));
|