@tari-project/tarijs-types 0.5.2 → 0.5.4
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/TransactionResult.d.ts +11 -0
- 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 +3 -0
- package/dist/helpers/index.js +3 -0
- package/dist/helpers/txResult.d.ts +29 -0
- package/dist/helpers/txResult.js +46 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.js +2 -1
- package/dist/network.d.ts +8 -0
- package/dist/network.js +9 -0
- package/package.json +2 -2
|
@@ -1,14 +1,25 @@
|
|
|
1
1
|
import { TransactionStatus } from "./TransactionStatus";
|
|
2
2
|
import { FinalizeResult } from "./FinalizeResult";
|
|
3
|
+
import { DownSubstates, UpSubstates } from "./SubstateDiff";
|
|
4
|
+
import { ComponentAddress } from "@tari-project/typescript-bindings";
|
|
3
5
|
export type SubmitTransactionResponse = {
|
|
4
6
|
transaction_id: string;
|
|
5
7
|
};
|
|
6
8
|
export interface SubmitTxResult {
|
|
7
9
|
response: SubmitTransactionResponse;
|
|
8
10
|
result: TransactionResult;
|
|
11
|
+
upSubstates: UpSubstates;
|
|
12
|
+
downSubstates: DownSubstates;
|
|
13
|
+
newComponents: UpSubstates;
|
|
14
|
+
getComponentForTemplate(templateAddress: string): ComponentAddress | null;
|
|
9
15
|
}
|
|
10
16
|
export type TransactionResult = {
|
|
11
17
|
transaction_id: string;
|
|
12
18
|
status: TransactionStatus;
|
|
13
19
|
result: FinalizeResult | null;
|
|
14
20
|
};
|
|
21
|
+
export type TransactionResultResponse = {
|
|
22
|
+
transaction_id: string;
|
|
23
|
+
status: TransactionStatus;
|
|
24
|
+
result: FinalizeResult | null;
|
|
25
|
+
};
|
|
@@ -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,8 @@
|
|
|
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 { txResultCheck, getSubstateValueFromUpSubstates, getComponentsForTemplate } from "./txResult";
|
|
5
|
+
export { BinaryTag, CborValue, convertTaggedValue, getCborValueByPath, parseCbor } from "./cbor";
|
|
3
6
|
export { substateIdToString, stringToSubstateId, shortenSubstateId, shortenString, rejectReasonToString, getSubstateDiffFromTransactionResult, getRejectReasonFromTransactionResult, jrpcPermissionToString, } from "@tari-project/typescript-bindings";
|
|
4
7
|
export declare function convertStringToTransactionStatus(status: string): TransactionStatus;
|
|
5
8
|
export declare function createNftAddressFromToken(token: NonFungibleToken): string;
|
package/dist/helpers/index.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { TransactionStatus } from "../TransactionStatus";
|
|
2
|
+
export { fromHexString, toHexString } from "./hexString";
|
|
3
|
+
export { txResultCheck, getSubstateValueFromUpSubstates, getComponentsForTemplate } from "./txResult";
|
|
4
|
+
export { BinaryTag, convertTaggedValue, getCborValueByPath, parseCbor } from "./cbor";
|
|
2
5
|
export { substateIdToString, stringToSubstateId, shortenSubstateId, shortenString, rejectReasonToString, getSubstateDiffFromTransactionResult, getRejectReasonFromTransactionResult, jrpcPermissionToString, } from "@tari-project/typescript-bindings";
|
|
3
6
|
export function convertStringToTransactionStatus(status) {
|
|
4
7
|
switch (status) {
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { SubstateDiff, VaultId, Vault, SubstateId, SubstateValue, ResourceContainer, ResourceAddress, Amount, RejectReason, ComponentAddress } from "@tari-project/typescript-bindings";
|
|
2
|
+
import { FinalizeResultStatus } from "../FinalizeResult";
|
|
3
|
+
import { UpSubstates } from "../SubstateDiff";
|
|
4
|
+
export declare const txResultCheck: {
|
|
5
|
+
isAccept: (result: FinalizeResultStatus) => result is {
|
|
6
|
+
Accept: SubstateDiff;
|
|
7
|
+
};
|
|
8
|
+
isVaultId: (substateId: SubstateId) => substateId is {
|
|
9
|
+
Vault: VaultId;
|
|
10
|
+
};
|
|
11
|
+
isVaultSubstate: (substate: SubstateValue) => substate is {
|
|
12
|
+
Vault: Vault;
|
|
13
|
+
};
|
|
14
|
+
isFungible: (resourceContainer: ResourceContainer) => resourceContainer is {
|
|
15
|
+
Fungible: {
|
|
16
|
+
address: ResourceAddress;
|
|
17
|
+
amount: Amount;
|
|
18
|
+
locked_amount: Amount;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
isReject: (result: FinalizeResultStatus) => result is {
|
|
22
|
+
Reject: RejectReason;
|
|
23
|
+
};
|
|
24
|
+
isAcceptFeeRejectRest: (result: FinalizeResultStatus) => result is {
|
|
25
|
+
AcceptFeeRejectRest: [SubstateDiff, RejectReason];
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
export declare function getSubstateValueFromUpSubstates(substateType: keyof SubstateValue | string, upSubstates: UpSubstates): UpSubstates;
|
|
29
|
+
export declare function getComponentsForTemplate(templateAddress: string, upSubstates: UpSubstates): ComponentAddress[] | null;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { substateIdToString, } from "@tari-project/typescript-bindings";
|
|
2
|
+
function isOfType(obj, key) {
|
|
3
|
+
return obj !== null && typeof obj === "object" && key in obj;
|
|
4
|
+
}
|
|
5
|
+
export const txResultCheck = {
|
|
6
|
+
isAccept: (result) => {
|
|
7
|
+
return "Accept" in result;
|
|
8
|
+
},
|
|
9
|
+
isVaultId: (substateId) => {
|
|
10
|
+
return isOfType(substateId, "Vault");
|
|
11
|
+
},
|
|
12
|
+
isVaultSubstate: (substate) => {
|
|
13
|
+
return "Vault" in substate;
|
|
14
|
+
},
|
|
15
|
+
isFungible: (resourceContainer) => {
|
|
16
|
+
return "Fungible" in resourceContainer;
|
|
17
|
+
},
|
|
18
|
+
isReject: (result) => {
|
|
19
|
+
return "Reject" in result;
|
|
20
|
+
},
|
|
21
|
+
isAcceptFeeRejectRest: (result) => {
|
|
22
|
+
return "AcceptFeeRejectRest" in result;
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
export function getSubstateValueFromUpSubstates(substateType, upSubstates) {
|
|
26
|
+
const components = [];
|
|
27
|
+
for (const [substateId, substate] of upSubstates) {
|
|
28
|
+
if (substateType in substate.substate) {
|
|
29
|
+
components.push([substateId, substate]);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return components;
|
|
33
|
+
}
|
|
34
|
+
export function getComponentsForTemplate(templateAddress, upSubstates) {
|
|
35
|
+
const components = [];
|
|
36
|
+
const templateAddressBytes = new TextEncoder().encode(templateAddress);
|
|
37
|
+
for (const [substateId, substate] of upSubstates) {
|
|
38
|
+
if ("Component" in substate.substate) {
|
|
39
|
+
const componentHeader = substate.substate.Component;
|
|
40
|
+
if (componentHeader.template_address === templateAddressBytes) {
|
|
41
|
+
components.push(substateIdToString(substateId));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return components;
|
|
46
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -10,12 +10,13 @@ export { Instruction } from "./Instruction";
|
|
|
10
10
|
export { Transaction } from "./Transaction";
|
|
11
11
|
export { SubstateDiff, DownSubstates, UpSubstates } from "./SubstateDiff";
|
|
12
12
|
export { SubstateRequirement } from "./SubstateRequirement";
|
|
13
|
-
export { TransactionResult, SubmitTxResult, SubmitTransactionResponse } from "./TransactionResult";
|
|
13
|
+
export { TransactionResult, SubmitTxResult, SubmitTransactionResponse, TransactionResultResponse, } from "./TransactionResult";
|
|
14
14
|
export { TransactionSignature } from "./TransactionSignature";
|
|
15
15
|
export { TransactionStatus } from "./TransactionStatus";
|
|
16
16
|
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, getSubstateValueFromUpSubstates, getComponentsForTemplate, txResultCheck, 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, getSubstateValueFromUpSubstates, getComponentsForTemplate, txResultCheck, 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 = {}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tari-project/tarijs-types",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.4",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"publishConfig": {
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"author": "",
|
|
11
11
|
"license": "ISC",
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@tari-project/typescript-bindings": "^1.5.
|
|
13
|
+
"@tari-project/typescript-bindings": "^1.5.2"
|
|
14
14
|
},
|
|
15
15
|
"devDependencies": {
|
|
16
16
|
"@types/node": "^22.13.1",
|